├── .github └── workflows │ ├── CheckFileNames.yml │ └── UpdateReadmeOnPush.yml ├── 1011A.cpp ├── 1028A.cpp ├── 1030A.cpp ├── 1080B.cpp ├── 1097A.cpp ├── 110A.cpp ├── 112A.cpp ├── 1132B.cpp ├── 1169A.cpp ├── 116A.cpp ├── 1178A.cpp ├── 1183A.cpp ├── 1186A.cpp ├── 118A.cpp ├── 119A.cpp ├── 1206A.cpp ├── 122A.cpp ├── 1248B.cpp ├── 1272A.cpp ├── 1283A.cpp ├── 1294A.cpp ├── 1296A.cpp ├── 1311A.cpp ├── 131A.cpp ├── 1325A.cpp ├── 1325B.cpp ├── 1335B.cpp ├── 1337B.cpp ├── 1339A.cpp ├── 133A.cpp ├── 1342A.cpp ├── 1343A.cpp ├── 1343B.cpp ├── 1348A.cpp ├── 1353A.cpp ├── 1358A.cpp ├── 1360A.cpp ├── 1360B.cpp ├── 1367B.cpp ├── 1368A.cpp ├── 1369A.cpp ├── 136A.cpp ├── 1370A.cpp ├── 1371A.cpp ├── 1372A.cpp ├── 1374B.cpp ├── 1374C.cpp ├── 1385A.cpp ├── 1385B.cpp ├── 1389A.cpp ├── 1399B.cpp ├── 141A.cpp ├── 1426A.cpp ├── 1433A.cpp ├── 144A.cpp ├── 1454A.cpp ├── 1462A.cpp ├── 1472A.cpp ├── 1472B.cpp ├── 1473A.cpp ├── 1475A.cpp ├── 1475B.cpp ├── 1506A.cpp ├── 1512A.cpp ├── 151A.cpp ├── 1520A.cpp ├── 1520B.cpp ├── 1535A.cpp ├── 1538A.cpp ├── 1541A.cpp ├── 1542A.cpp ├── 1543A.cpp ├── 1549A.cpp ├── 1550A.cpp ├── 1551A.CPP ├── 1551B1.cpp ├── 1552A.cpp ├── 1553A.cpp ├── 1554A.cpp ├── 1555A.cpp ├── 1556A.cpp ├── 1559A.cpp ├── 1560A.cpp ├── 1560B.cpp ├── 1560C.cpp ├── 1562A.cpp ├── 1567B.cpp ├── 1569B.cpp ├── 1573A.cpp ├── 1574A.cpp ├── 1574B.cpp ├── 1579A.cpp ├── 1579B.cpp ├── 1579E1.cpp ├── 1581A.cpp ├── 1582A.cpp ├── 1582B.cpp ├── 158A.cpp ├── 1592A.cpp ├── 1593A.cpp ├── 1593B.cpp ├── 1593D1.cpp ├── 1594A.cpp ├── 1594B.cpp ├── 1602A.cpp ├── 1602B.cpp ├── 1604A.cpp ├── 1605A.cpp ├── 1605B.cpp ├── 1606A.cpp ├── 1607A.cpp ├── 1607B.cpp ├── 1607C.cpp ├── 160A.cpp ├── 1610A.cpp ├── 1619A.py ├── 1629A.cpp ├── 1680A.cpp ├── 1684A.cpp ├── 1684B.cpp ├── 1686B.cpp ├── 1691A.cpp ├── 1692A.cpp ├── 1692B.cpp ├── 1697A.cpp ├── 16B.cpp ├── 1703A.py ├── 1703B.cpp ├── 1714A.cpp ├── 1716A.cpp ├── 1721A.cpp ├── 1739A.cpp ├── 1739B.cpp ├── 1749A.cpp ├── 1760B.cpp ├── 1766A.py ├── 1766B.cpp ├── 1774A.py ├── 1774B.cpp ├── 1777A.cpp ├── 1777B.cpp ├── 1778A.cpp ├── 1778A.py ├── 1786A1.cpp ├── 1786A1.py ├── 1786A2.py ├── 1786B.py ├── 1786C.py ├── 1787A.py ├── 1788A.cpp ├── 1788A.py ├── 1788B.cpp ├── 1788B.py ├── 1788C.cpp ├── 1788C.py ├── 1790A.cpp ├── 1790A.py ├── 1790B.cpp ├── 1790B.py ├── 1790C.cpp ├── 1790C.py ├── 1790D.cpp ├── 1791A.cpp ├── 1791A.py ├── 1791B.cpp ├── 1791B.py ├── 1791C.cpp ├── 1791C.py ├── 1791D.cpp ├── 1791D.py ├── 1791E.cpp ├── 1791E.py ├── 1791G1.cpp ├── 1791G1.py ├── 1792B.cpp ├── 1933A.py ├── 1933B.py ├── 1933C.py ├── 1933D.py ├── 1948B.py ├── 1957A.cpp ├── 1957A.py ├── 1957B.py ├── 1966A.py ├── 1966B.py ├── 1966C.py ├── 1968A.py ├── 1968B.py ├── 1968C.py ├── 1969A.py ├── 1969B.py ├── 1972A.py ├── 1972B.py ├── 1972C.py ├── 1972D1.py ├── 1A.cpp ├── 200B.cpp ├── 208A.py ├── 230A.cpp ├── 231A.cpp ├── 233A.cpp ├── 236A.cpp ├── 252C.cpp ├── 263A.cpp ├── 266A.cpp ├── 26A.cpp ├── 271A.cpp ├── 281A.cpp ├── 282A.cpp ├── 306A.cpp ├── 318A.cpp ├── 32B.cpp ├── 32B.py ├── 337A.cpp ├── 339A.cpp ├── 339B.cpp ├── 343B.cpp ├── 344A.cpp ├── 34B.cpp ├── 379A.cpp ├── 381A.cpp ├── 3A.cpp ├── 405A.cpp ├── 41A.cpp ├── 431A.cpp ├── 43A.cpp ├── 443A.cpp ├── 443A.py ├── 451A.cpp ├── 460A.cpp ├── 467A.cpp ├── 474A.cpp ├── 479A.cpp ├── 486A.cpp ├── 492A.cpp ├── 4A.cpp ├── 509A.cpp ├── 50A.cpp ├── 540A.cpp ├── 545A.cpp ├── 546A.cpp ├── 556A.cpp ├── 579A.cpp ├── 580A.cpp ├── 580B.cpp ├── 584A.cpp ├── 58A.cpp ├── 59A.cpp ├── 611A.cpp ├── 617A.cpp ├── 61A.cpp ├── 630A.cpp ├── 651C.cpp ├── 669A.cpp ├── 676B.py ├── 677A.cpp ├── 69A.cpp ├── 702A.cpp ├── 703A.cpp ├── 706B.cpp ├── 707A.cpp ├── 71A.cpp ├── 727A.py ├── 731A.cpp ├── 734A.cpp ├── 749A.cpp ├── 785A.cpp ├── 791A.cpp ├── 80A.cpp ├── 81A.cpp ├── 855B.cpp ├── 873B.cpp ├── 903C.cpp ├── 935A.cpp ├── 939A.cpp ├── 954A.cpp ├── 959A.cpp ├── 96A.cpp ├── 976A.cpp ├── 977A.cpp ├── 991B.cpp ├── 9A.cpp ├── BalancedArray.cpp ├── Buy_a_Shovel.cpp ├── Candies_and_Two_Sisters.cpp ├── Chess_Tournament.cpp ├── ChoosingTeams.cpp ├── DesignTutorial_LearnfromMath.cpp ├── Divisibility_Problem.cpp ├── Fox_and_Snake.cpp ├── Games.cpp ├── Hit_the_Lottery.cpp ├── HolidayOfEquality.cpp ├── Hulk.cpp ├── I_Wanna_Be_The_Guy.cpp ├── I_love_saura.cpp ├── Insomnia_Cure.cpp ├── Is_your_horseshoe_on_the_other_hoof.cpp ├── LICENSE ├── MAX_MEX_Cut.cpp ├── MEXor_mixup.cpp ├── MIN_MEX_Cut.cpp ├── MakeAPower_ofTwo.cpp ├── Median_Maximization.cpp ├── New_Year_and_Hurry.cpp ├── Pangram.cpp ├── Police_Recruits.cpp ├── README.md ├── Remove_Smallest.cpp ├── RequiredRemainder.cpp ├── RestoringThreeNumbers.cpp ├── ShortSubstrings.cpp ├── Sum_of_Round_Numbers.cpp ├── TeamOlympiad.cpp ├── TheNewYearMeetingFriends.cpp ├── TwoArraysAndSwaps.cpp ├── Vasya_the_Hipster.cpp ├── Yet_Another_Two_Integers_Problem.cpp ├── between_two_sets.cpp ├── domino_disaster.cpp └── update_readme.py /.github/workflows/CheckFileNames.yml: -------------------------------------------------------------------------------- 1 | name: Check File name on Pull Request 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | checkFileName: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v3 15 | with: 16 | fetch-depth: 0 17 | 18 | - name: Check File Names 19 | run: | 20 | CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD) 21 | echo "$CHANGED_FILES" 22 | 23 | for file in $CHANGED_FILES; do 24 | if [[ ! ($file =~ ^[0-9]+[A-Z][0-9]*\.(cpp|py)$) ]]; then 25 | echo "Error: File '$file' does not match allowed pattern" 26 | exit 1 27 | fi 28 | done 29 | -------------------------------------------------------------------------------- /.github/workflows/UpdateReadmeOnPush.yml: -------------------------------------------------------------------------------- 1 | name: Update README on Push 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | update-readme: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v3 15 | with: 16 | fetch-depth: 0 17 | 18 | - name: Set up Python 19 | uses: actions/setup-python@v2 20 | with: 21 | python-version: '3.12' 22 | 23 | - name: Run Python script to update README 24 | run: | 25 | CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD) 26 | echo "$CHANGED_FILES" 27 | python update_readme.py $CHANGED_FILES 28 | 29 | - name: Commit changes 30 | run: | 31 | git config --local user.email "actions@github.com" 32 | git config --local user.name "GitHub Actions" 33 | git add README.md 34 | git commit -m "Update README" 35 | 36 | - name: Push changes 37 | uses: ad-m/github-push-action@master 38 | with: 39 | github_token: ${{ secrets.CODEFORCES_GITHUB_TOKEN }} 40 | -------------------------------------------------------------------------------- /1011A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int n, k; 9 | cin>>n>>k; 10 | string s; 11 | cin>>s; 12 | sort(s.begin(), s.end()); 13 | 14 | int sum = s[0] - 'a' + 1; 15 | k--; 16 | char prev = s[0]; 17 | for(int i = 1; i < n; i++){ 18 | if(!k){ 19 | break; 20 | } 21 | if(s[i] - prev >= 2){ 22 | prev = s[i]; 23 | sum += s[i] - 'a' + 1; 24 | k--; 25 | } 26 | } 27 | if(!k){ 28 | cout< 2 | using namespace std; 3 | 4 | void startPos(int *a, int *b, int n, int m, int arr[n][]){ 5 | for(int i = 0; i < n; i++){ 6 | for(int j = 0; j < m; j++){ 7 | if(arr[i][j] == 'B'){ 8 | *a = i; 9 | *b = j; 10 | return; 11 | } 12 | } 13 | } 14 | } 15 | 16 | int main(){ 17 | ios_base::sync_with_stdio(false); 18 | cin.tie(NULL); 19 | 20 | int n, m; 21 | cin>>n>>m; 22 | 23 | int arr[n][m]; 24 | 25 | for(int i = 0; i< n; i++){ 26 | for(int j = 0; j < m; j++){ 27 | cin>>arr[n][m]; 28 | } 29 | } 30 | int a, b; 31 | 32 | startPos(&a, &b, n, m, &arr); 33 | int a1, b1; 34 | int i = a; 35 | for(i = a; i < n; i++){ 36 | if(arr[i][b] == 'W'){ 37 | break; 38 | } 39 | } 40 | a1 = i+1; 41 | int j = b; 42 | for(j = b; j < m; j++){ 43 | if(arr[a][j] == 'W'){ 44 | break; 45 | } 46 | } 47 | b1 = j+1; 48 | a++; 49 | b++; 50 | cout<<((a + a1)/2)<<" "<<((b + b1)/2)< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, m, r = 0; 6 | cin>>n; 7 | for(int i = 0; i < n; i++){ 8 | cin>>m; 9 | r |= m; 10 | if(r == 1){ 11 | cout<<"HARD"; 12 | return 0; 13 | } 14 | } 15 | cout<<"EASY"; 16 | return 0; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /1080B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long 5 | #define endl '\n' 6 | #define debug(n) cout<<(n)<>t; 15 | long long l, r; 16 | while(t--){ 17 | 18 | cin>>l>>r; 19 | long long odd_l, odd_r; 20 | l--; 21 | if(l % 2 == 0){ 22 | odd_l = l/2 * l/2; 23 | } 24 | else{ 25 | odd_l = (l/2 + 1) * (l/2 + 1); 26 | } 27 | long long even_l = l/2 * (l/2 + 1); 28 | if(r % 2 == 0){ 29 | odd_r = r/2 * r/2; 30 | } 31 | else{ 32 | odd_r = (r/2 + 1) * (r/2 + 1); 33 | } 34 | long long even_r = r/2 * (r/2 + 1); 35 | 36 | long long even_s = even_r - even_l; 37 | long long odd_s = odd_r - odd_l; 38 | 39 | cout<<(even_s - odd_s)<<"\n"; 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /1097A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>a; 16 | string arr[5]; 17 | for(int i = 0; i < 5; i++){ 18 | cin>>arr[i]; 19 | } 20 | for(int i = 0; i < 5; i++){ 21 | if(a[0] == arr[i][0]){ 22 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | long long n; 6 | cin>>n; 7 | int check = 0; 8 | int rem; 9 | while(n != 0){ 10 | rem = n%10; 11 | n /= 10; 12 | if(rem == 7 || rem == 4){ 13 | check++; 14 | } 15 | 16 | } 17 | if(check != 4 && check != 7){ 18 | cout<<"NO"; 19 | } 20 | else{ 21 | cout<<"YES"; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /112A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | string s1, s2; 8 | cin>>s1; 9 | cin>>s2; 10 | transform(s1.begin(), s1.end(), s1.begin(), ::toupper); 11 | transform(s2.begin(), s2.end(), s2.begin(), ::toupper); 12 | if(s1 > s2){ 13 | cout<<"1"< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int n; 9 | cin>>n; 10 | int arr[n]; 11 | long long sum = 0; 12 | for(int i = 0; i < n; i++){ 13 | cin>>arr[i]; 14 | sum += arr[i]; 15 | } 16 | 17 | sort(arr, arr+n, greater()); 18 | 19 | int m; 20 | cin>>m; 21 | int q; 22 | for(int i = 0; i < m; i++){ 23 | cin>>q; 24 | cout<<(sum - arr[q - 1])<<'\n'; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /1169A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | //#define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>a>>x>>b>>y; 16 | 17 | while(a != x && b != y){ 18 | a++; 19 | b--; 20 | if(a == n+1){ 21 | a = 1; 22 | } 23 | if( b == 0){ 24 | b = n; 25 | } 26 | if(a == b){ 27 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int a, b, max = 0, tot = 0; 8 | for(int i = 0; i < n; i++){ 9 | cin>>a; 10 | cin>>b; 11 | tot -= a; 12 | tot += b; 13 | max = tot > max ? tot : max; 14 | } 15 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int n; 9 | cin>>n; 10 | int arr[n]; 11 | int seats = 0; 12 | for(auto i = 0; i < n; i++){ 13 | cin>>arr[i]; 14 | seats += arr[i]; 15 | } 16 | int party = arr[0]; 17 | int coalition = party, k = 0, i = 0; 18 | int arrn[n]; 19 | int cvheck = 0; 20 | while(i < n-1){ 21 | i++; 22 | if(arr[i] <= party/2){ 23 | coalition += arr[i]; 24 | arrn[k] = i; 25 | k++; 26 | } 27 | } 28 | if(coalition <= seats/2){ 29 | cout<<0< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>a; 16 | 17 | while(a % 4 != 0){ 18 | a++; 19 | } 20 | 21 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>m>>k; 16 | (n <= min(m, k)) ? cout<<"Yes"< 2 | using namespace std; 3 | 4 | #define ll long long 5 | #define endl '\n' 6 | #define debug(n) cout<<(n)<>s; 15 | transform(s.begin(), s.end(), s.begin(), ::tolower); 16 | for(auto i : s){ 17 | if( i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'y' || i == 'u'){ 18 | continue; 19 | } 20 | else{ 21 | r += "."; 22 | r += i; 23 | } 24 | } 25 | cout< 2 | using namespace std; 3 | int gcd(int a,int b){ 4 | return a?gcd(b%a,a):b; 5 | } 6 | int main() { 7 | int a,b,n; 8 | cin>>a>>b>>n; 9 | int flag1=0; 10 | int val; 11 | // cout<0){ 13 | if(flag1==0){ 14 | // this is for simon 15 | val=gcd(a,n); 16 | n-=val; 17 | flag1=1; 18 | }else{ 19 | // this is for the antisimon 20 | val=gcd(b,n); 21 | n-=val; 22 | flag1=0; 23 | } 24 | // cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, m, maxx = 0, maxy = 0; 6 | cin>>n; 7 | int x; 8 | for(int i = 0; i < n; i++){ 9 | cin>>x; 10 | maxx = x > maxx ? x : maxx; 11 | } 12 | cin>>m; 13 | for(int i = 0; i < m; i++){ 14 | cin>>x; 15 | maxy = x > maxy ? x : maxy; 16 | } 17 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 17 | for(auto i : arr){ 18 | if(n % i == 0){ 19 | cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | deque deck; 17 | ll x; 18 | for(int i = 0; i < n; i++){ 19 | cin>>x; 20 | deck.push_back(x); 21 | } 22 | sort(deck.begin(), deck.end(), greater()); 23 | 24 | ll hz = 0; 25 | ll vt = 0; 26 | bool check = false; 27 | for(int i = 0; i < n; i++){ 28 | check = !check; 29 | if(check){ 30 | hz += deck.front(); 31 | deck.pop_front(); 32 | } 33 | else{ 34 | vt += deck.back(); 35 | deck.pop_back(); 36 | } 37 | } 38 | ll dist = hz * hz + vt * vt; 39 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a[3]; 18 | cin>>a[0]>>a[1]>>a[2]; 19 | sort(a, a+3); 20 | if(a[0] == a[1] && a[2] != a[1]){ 21 | if(a[2] - a[1] > 1){ 22 | a[2] -= 1; 23 | } 24 | a[0] = a[0] + 1; 25 | a[1] = a[1] + 1; 26 | } 27 | else if(a[2] == a[1] && a[0] != a[1]){ 28 | if(a[1] - a[0] > 1){ 29 | a[0] += 1; 30 | } 31 | a[2] = a[2] - 1; 32 | a[1] = a[1] - 1; 33 | } 34 | else if(a[2] != a[1] && a[0] != a[1]){ 35 | a[0] += 1; 36 | a[2] -= 1; 37 | } 38 | int dista = (a[0] - a[1] >= 0) ? (a[0] - a[1]) : (a[1] - a[0]); 39 | int distb = (a[1] - a[2] >= 0) ? (a[1] - a[2]) : (a[2] - a[1]); 40 | int distc = (a[0] - a[2] >= 0) ? (a[0] - a[2]) : (a[2] - a[0]); 41 | cout<<(dista + distb + distc)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int h, m; 17 | while(t--){ 18 | cin>>h; 19 | cin>>m; 20 | cout<<(1440 - (h * 60) - m)< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int a, b, c, n; 8 | while(t--){ 9 | cin>>a>>b>>c>>n; 10 | int maxi = max(a, b); 11 | maxi = max(maxi, c); 12 | n -= 3*maxi - (a + b + c); 13 | if(n < 0){ 14 | cout<<"NO"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | int x; 20 | int odd = 0; 21 | for(int i = 0; i < n; i++){ 22 | cin>>x; 23 | (x & 1) ? odd++ : odd += 0; 24 | } 25 | (((odd == n) || (odd == 0) )&& !(odd & 1)) ? cout<<"NO"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int a, b; 9 | cin>>a>>b; 10 | if(a > b){ 11 | if((a%2 == 0 && b%2 == 0) || (a%2 != 0 && b%2 != 0)){ 12 | cout<<1< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>s; 16 | bool check = true; 17 | for(int i = 1; i < s.length(); i++){ 18 | if(s[i] >= 97){ 19 | check = false; 20 | break; 21 | } 22 | } 23 | if(s[0] <= 90 && check){ 24 | transform(s.begin(), s.end(), s.begin(), ::tolower); 25 | } 26 | else if(s[0] >= 97 && check){ 27 | s[0] = toupper(s[0]); 28 | for(int i = 1; i < s.length(); i++){ 29 | s[i] = tolower(s[i]); 30 | } 31 | } 32 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | cout<<1<<" "<<(n-1)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | set > s1; 20 | int x; 21 | for(int i = 0; i < n; i++){ 22 | cin>>x; 23 | s1.insert(x); 24 | } 25 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n, a, b; 18 | cin>>n>>a>>b; 19 | string s = ""; 20 | char c = 'a'; 21 | for(int i = 0; i < n; i++){ 22 | if(i % b == 0){ 23 | c = 'a'; 24 | } 25 | s += c; 26 | c = char(c + 1); 27 | } 28 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int n, x, m; 17 | while(t--){ 18 | cin>>n>>x>>m; 19 | while(n > 0 && m > 0){ 20 | if(n > 20 && x > 0){ 21 | n /= 2; 22 | n += 10; 23 | x--; 24 | } 25 | else{ 26 | n -= 10; 27 | m--; 28 | } 29 | } 30 | (n <= 0) ? cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | string s; 9 | cin>>s; 10 | for(auto i:s){ 11 | if(i == 'H' || i == 'Q' || i == '9'){ 12 | cout<<"YES\n"; 13 | return 0; 14 | } 15 | } 16 | cout<<"NO\n"; 17 | return 0; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /1342A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | ll x, y, a, b; 18 | cin>>x>>y>>a>>b; 19 | if(2* a < b){ 20 | cout<<(a * x + y * a)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 20 | while(t--){ 21 | ll n; 22 | cin>>n; 23 | for(int i = 1; i < 32; i++){ 24 | if(n % arr[i] == 0){ 25 | cout<<(n/arr[i])< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n; 9 | cin>>n; 10 | if((n/2)%2 != 0){ 11 | cout<<"NO"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | int arr[30]; 9 | int r = 2; 10 | for(int i = 0; i < 30; i++){ 11 | arr[i] = r; 12 | r *= 2; 13 | } 14 | while(t--){ 15 | cin>>n; 16 | int asum(0), bsum(0); 17 | for(int i = 0; i < n/2-1; i++){ 18 | asum += arr[i]; 19 | } 20 | asum += arr[n-1]; 21 | for(int i = n/2 - 1; i < n-1; i++){ 22 | bsum += arr[i]; 23 | } 24 | int diff = asum - bsum >= 0 ? (asum - bsum) : (bsum - asum); 25 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n, m; 8 | while (t--) { 9 | cin>>n>>m; 10 | if(n == 1){ 11 | cout<<0< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int n, m; 17 | while(t--){ 18 | cin>>n>>m; 19 | int lights; 20 | lights = (n*m)%2 == 0 ? ((n * m) / 2) : (((n * m) / 2) + 1); 21 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin >> t; 7 | int a, b, area; 8 | while(t--){ 9 | cin >> a >> b; 10 | if(b <= a){ 11 | if(2 * b < a){ 12 | area = a * a; 13 | } 14 | else{ 15 | area = 4 * b * b; 16 | } 17 | } 18 | else{ 19 | if(2 * a < b){ 20 | area = b * b; 21 | } 22 | else{ 23 | area = 4 * a * a; 24 | } 25 | } 26 | cout << area << endl; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /1360B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | while(t--){ 9 | cin>>n; 10 | int arr[n]; 11 | int mina = 0x3f3f3f3f; 12 | for(int i = 0; i < n; i++){ 13 | cin>>arr[i]; 14 | } 15 | sort(arr, arr+n); 16 | for(int i = 1; i < n; i++){ 17 | mina = min(mina, (arr[i] - arr[i-1])); 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n; 9 | cin>>n; 10 | int x; 11 | int evcnt = 0, oddcnt = 0; 12 | for(int i = 0; i < n; i++){ 13 | cin>>x; 14 | if(x%2 == 0 && i%2 != 0){ 15 | evcnt++; 16 | } 17 | if(x%2 != 0 && i % 2 == 0){ 18 | oddcnt++; 19 | } 20 | } 21 | if(evcnt == oddcnt){ 22 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a, b, n; 18 | cin>>a>>b>>n; 19 | if(b < a){ 20 | int temp = a; 21 | a = b; 22 | b = temp; 23 | } 24 | int count = 0; 25 | 26 | while(a <= n && b <= n){ 27 | if(a <= n){ 28 | a += b; 29 | count++; 30 | } 31 | if(a > n){ 32 | break; 33 | } 34 | 35 | if(b <= n){ 36 | b += a; 37 | count++; 38 | } 39 | if(b > n){ 40 | break; 41 | } 42 | 43 | } 44 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int n; 17 | while(t--){ 18 | cin>>n; 19 | (n % 4 == 0) ? cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int arr[n]; 8 | int parr[n]; 9 | for(int i = 0; i < n; i++){ 10 | cin>>arr[i]; 11 | parr[arr[i]-1] = i+1; 12 | } 13 | for(int i = 0; i < n; i++){ 14 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | while(t--){ 9 | cin>>n; 10 | if(n%2 != 0){ 11 | n--; 12 | cout<<(n/2)< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | while(t--){ 9 | cin>>n; 10 | cout<<((n-1)/2 + 1)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | for(int i = 0; i < n; i++){ 20 | cout<<1<<" "; 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int t; 9 | cin>>t; 10 | long long n; 11 | while(t--){ 12 | cin>>n; 13 | int cnt3 = 0, cnt2 = 0; 14 | int k = n; 15 | while(k % 3 == 0 && k > 1){ 16 | k /= 3; 17 | cnt3++; 18 | } 19 | while(k % 2 == 0 && k > 1){ 20 | k /= 2; 21 | cnt2++; 22 | } 23 | if(k != 1){ 24 | cout<<-1<1){ 34 | n /= 6; 35 | cnt6++; 36 | } 37 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | string s; 20 | cin>>s; 21 | stack st; 22 | int count = 0; 23 | for(auto i : s){ 24 | if(i == ')' && !st.empty()){ 25 | st.pop(); 26 | continue; 27 | } 28 | if(i == ')' && st.empty()){ 29 | count++; 30 | continue; 31 | } 32 | st.push(i); 33 | } 34 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a[3]; 18 | cin>>a[0]>>a[1]>>a[2]; 19 | 20 | sort(a, a + 3, greater()); 21 | 22 | if(a[0] == a[1]){ 23 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n; 9 | cin>>n; 10 | int arr[n]; 11 | map inp; 12 | int x, k = 0; 13 | for(int i = 0; i < 2*n; i++){ 14 | cin>>x; 15 | if(!inp[x]){ 16 | arr[k] = x; 17 | inp[x] = true; 18 | k++; 19 | } 20 | } 21 | for(int i = 0; i < n; i++){ 22 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int l, r; 18 | cin>>l>>r; 19 | if(r - l < l){ 20 | cout<<-1<<" "<<-1< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin >> t; 8 | while(t--) 9 | { 10 | int n; 11 | cin >> n; 12 | int a[n], b[n]; 13 | int mina = 0x3f3f3f3f, minb = 0x3f3f3f3f; 14 | long long ans = 0; 15 | for(int i = 1; i <= n; i++) 16 | { 17 | cin >> a[i]; 18 | mina = min(mina, a[i]); 19 | } 20 | for(int i = 1; i <= n; i++) 21 | { 22 | cin >> b[i]; 23 | minb = min(minb, b[i]); 24 | } 25 | for(int i = 1; i <= n; i++) 26 | { 27 | ans += 1ll * max(a[i] - mina, b[i] - minb); 28 | } 29 | cout << ans << endl; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /141A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | string s1, s2, s3, s4; 8 | cin>>s1>>s2>>s3; 9 | s4 = s1 + s2; 10 | if(s4.size() != s3.size()){ 11 | cout<<"NO"; 12 | return 0; 13 | } 14 | else{ 15 | sort(s3.begin(), s3.end()); 16 | sort(s4.begin(), s4.end()); 17 | if(s3 != s4){ 18 | cout<<"NO"; 19 | return 0; 20 | } 21 | else{ 22 | cout<<"YES"; 23 | return 0; 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /1426A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n, x; 18 | cin>>n>>x; 19 | if( n > 2){ 20 | n -= 2; 21 | if(n % x > 0){ 22 | cout<<(n / x + 2)< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | string n; 8 | int count = 0; 9 | while(t--){ 10 | cin>>n; 11 | count = 0; 12 | count += (stoi(n)%10 - 1) * 10; 13 | if(n.size() == 1){ 14 | count += 1; 15 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin>>n; 8 | int x, minindex, maxindex, maxi = 0, mini = 1000; 9 | for(int i = 0; i < n; i++){ 10 | cin>>x; 11 | if(x > maxi){ 12 | maxindex = i; 13 | maxi = x; 14 | } 15 | if(x <= mini){ 16 | minindex = i; 17 | mini = x; 18 | } 19 | } 20 | 21 | if(maxindex>minindex){ 22 | cout<<(maxindex-1)+(n-minindex)-1; 23 | } 24 | else{ 25 | cout<<(maxindex-1)+(n-minindex); 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /1454A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | while(t--){ 9 | cin>>n; 10 | for(int i = 2; i <= n; i++){ 11 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int n; 17 | while(t--){ 18 | cin>>n; 19 | deque drr; 20 | int x; 21 | for(int i = 0; i < n; i++){ 22 | cin>>x; 23 | drr.push_back(x); 24 | } 25 | bool check = false; 26 | for(int i = 0; i < n; i++){ 27 | check = !check; 28 | if(check){ 29 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int w, h, n; 8 | while(t--){ 9 | cin>>w>>h>>n; 10 | int steps = 0; 11 | while(w%2 == 0 && w > 1){ 12 | steps++; 13 | w /= 2; 14 | } 15 | while(h%2 == 0 && h > 1){ 16 | steps++; 17 | h /= 2; 18 | } 19 | if(n <= pow(2, steps)){ 20 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n, x; 8 | while(t--){ 9 | cin>>n; 10 | int count1 = 0, count2 = 0; 11 | for(int i = 0; i < n; i++){ 12 | cin>>x; 13 | if(x == 1){ 14 | count1++; 15 | continue; 16 | } 17 | count2++; 18 | } 19 | if(count2 % 2 == 0 && count1 % 2 == 0){ 20 | cout<<"YES"< 0){ 24 | cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n, d; 18 | cin>>n>>d; 19 | int arr[n]; 20 | for(int i = 0; i < n; i++){ 21 | cin>>arr[i]; 22 | } 23 | sort(arr, arr+n); 24 | if(arr[n-1] <= d){ 25 | cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | ll n; 18 | cin>>n; 19 | while(n != 1){ 20 | if(n % 2 == 0){ 21 | n /= 2; 22 | } 23 | else{ 24 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int t; 9 | cin>>t; 10 | int n; 11 | while(t--){ 12 | cin>>n; 13 | (n / 2020 >= n % 2020) ? cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<> t; 16 | while (t--){ 17 | long long int n, m, x; 18 | cin >> n >> m >> x; 19 | long long a = (x - 1) % n, b = (x - 1) / n; 20 | cout << a * m + b + 1 << "\n"; 21 | } 22 | return 0; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /1512A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | while(t--){ 9 | cin>>n; 10 | int arr[n]; 11 | for(int i = 0; i < n; i++){ 12 | cin>>arr[i]; 13 | } 14 | for(int i = 0; i < n; i++){ 15 | if(i == 0 && arr[i] != arr[i+1] && arr[i] != arr[i+2] ){ 16 | cout<<(i+1)< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, k, l, c, d, p, nl, np; 6 | cin>>n>>k>>l>>c>>d>>p>>nl>>np; 7 | int a = (k*l)/nl; 8 | int b = c * d; 9 | int s = p / np; 10 | if( a <= b && a <= s){ 11 | cout<<(a/n)< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin>>t; 8 | int n, check; 9 | string s; 10 | while(t--){ 11 | cin>>n; 12 | cin>>s; 13 | char s2[n], elem = s[0]; 14 | int k = 0; 15 | check = 0; 16 | for(int i = 0; i < n; i++){ 17 | if(s[i] != elem){ 18 | s2[k] = elem; 19 | elem = s[i]; 20 | k++; 21 | } 22 | for(int j = 0; j < k; j++){ 23 | if(s[i] == s2[j]){ 24 | cout<<"NO"< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | const int MAX = 10; 8 | int t; 9 | cin>>t; 10 | int n; 11 | while(t--){ 12 | cin>>n; 13 | int arr[MAX]; 14 | int r = log10(n); 15 | int tmp = 0; 16 | for (int i = 0; i < r+1; i++) { 17 | tmp = tmp * 10 + 1; 18 | } 19 | cout<<(r * 9 + n / tmp)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a, b, c, d; 18 | cin>>a>>b>>c>>d; 19 | if(max(a, b) > min(c, d) && max(c, d) > min(a, b)){ 20 | cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | cin>>n; 18 | int arr[n]; 19 | for(int i = 0; i < n; i++){ 20 | cin>>arr[i]; 21 | } 22 | int mx = distance(arr, max_element(arr, arr + n)) + 1; 23 | int mn = distance(arr, min_element(arr, arr + n)) + 1; 24 | int mx_b = abs(distance(arr + n, max_element(arr, arr + n))); 25 | int mn_b = abs(distance(arr + n, min_element(arr, arr + n))); 26 | 27 | int mrr[4] = {mx, mn, mx_b, mn_b}; 28 | int steps = 0; 29 | steps += *min_element(mrr, mrr + 4); 30 | if(*min_element(mrr, mrr+4) == mx || *min_element(mrr, mrr+4) == mx_b){ 31 | steps += min(min(abs(mn - mx), mn_b), min(mn, mn_b)); 32 | } 33 | else{ 34 | steps += min(min(abs(mx - mn), mx_b), min(mx, mx_b)); 35 | } 36 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int n; 17 | while(t--){ 18 | cin>>n; 19 | bool check = false; 20 | 21 | if(n & 1){ 22 | for(int i = 1; i <= n; i++){ 23 | check = !check; 24 | if(i == n-2){ 25 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | int od_sum = 0, ev_sum = 0; 20 | int x; 21 | for(int i = 0; i < 2*n; i++){ 22 | cin>>x; 23 | if(x & 1){ 24 | od_sum++; 25 | } 26 | else{ 27 | ev_sum++; 28 | } 29 | } 30 | if(od_sum == ev_sum){ 31 | cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | ll a, b; 18 | cin>>a>>b; 19 | ll diff = (a >= b) ? (a - b) : (b - a); 20 | if(a > b){ 21 | cout< a){ 24 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int n; 17 | while(t--){ 18 | cin>>n; 19 | n--; 20 | cout<<2<<" "< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | double n; 18 | cin>>n; 19 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | while(t--){ 9 | cin>>n; 10 | int c1 = 0, c2 = 0; 11 | if(n%3 == 0){ 12 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | string s; 17 | int cnt[26]; 18 | while(t--){ 19 | cin>>s; 20 | memset(cnt, 0, sizeof(cnt)); 21 | for(auto c : s) cnt[c - 'a']++; 22 | int cnt1 = 0; 23 | int cnt2 = 0; 24 | for(auto i : cnt){ 25 | if(i == 1) cnt1++; 26 | else if(i > 1) cnt2++; 27 | } 28 | cout<<(cnt2 + cnt1/2)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | string s, k; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | cin>>s; 21 | k = s; 22 | sort(s.begin(), s.end()); 23 | int count = 0; 24 | for(int i = 0; i < s.length(); i++){ 25 | if(s[i] != k[i]){ 26 | count++; 27 | } 28 | } 29 | 30 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int x; 8 | int n; 9 | for(int i = 0; i < t; i++){ 10 | cin>>n; 11 | n += 1; 12 | x = n / 10; 13 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | ll n; 17 | while(t--){ 18 | cin>>n; 19 | ll a, b, c, max = -1; 20 | cin>>a; 21 | for(ll i = 1; i < n; i++){ 22 | cin>>b; 23 | c = a * b; 24 | max = (c > max) ? c : max; 25 | a = b; 26 | } 27 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | ll n; 17 | while(t--){ 18 | cin>>n; 19 | 20 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, p, q, count; 6 | cin>>n; 7 | for(int i = 0; i < n; i++){ 8 | cin>>p; 9 | cin>>q; 10 | if((p+q)%2 != 0){ 11 | cout<<-1< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | ll n; 18 | cin>>n; 19 | ll arr[n]; 20 | for(ll i = 0; i < n; i++){ 21 | cin>>arr[i]; 22 | } 23 | ll res = arr[0]; 24 | 25 | for(ll i = 1; i < n; i++){ 26 | res &= arr[i]; 27 | } 28 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | while(t--){ 9 | cin>>n; 10 | int ans; 11 | int i = 0, j = 1; 12 | while(i != n){ 13 | if(j%3 != 0 && j % 10 != 3){ 14 | ans = j; 15 | j++; 16 | } 17 | else{ 18 | j++; 19 | continue; 20 | } 21 | i++; 22 | } 23 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a, b, c, a1, b1; 18 | cin>>a1>>b1>>c; 19 | 20 | a = max(a1, b1); 21 | b = min(a1, b1); 22 | 23 | if(a - b >= b && 2*(a - b) >= c){ 24 | if(c <= a - b){ 25 | c += (a - b); 26 | } 27 | else{ 28 | c -= (a - b); 29 | } 30 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int n; 17 | while(t--){ 18 | cin>>n; 19 | int i = 0; 20 | int dif; 21 | while(true){ 22 | i++; 23 | dif = n - (i * (i-1) + 1) ; 24 | dif *= dif > 0 ? 1 : -1; 25 | if(dif < i){ 26 | break; 27 | } 28 | } 29 | dif = n - (i * (i-1) + 1) ; 30 | if(dif > 0){ 31 | cout< 2 | using namespace std; 3 | 4 | #define endl '\n' 5 | 6 | int main(){ 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | 10 | int t; 11 | cin>>t; 12 | int l, r; 13 | 14 | while(t--){ 15 | cin>>l; 16 | cin>>r; 17 | 18 | if(r/2 < l){ 19 | cout<<(r%l)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a, b; 18 | cin>>a>>b; 19 | int res, n = a - 1; 20 | if(n % 4 == 0){ 21 | res = n; 22 | } 23 | else if(n % 4 == 1){ 24 | res = 1; 25 | } 26 | else if(n % 4 == 2){ 27 | res = n + 1; 28 | } 29 | else{ 30 | res = 0; 31 | } 32 | 33 | if(res == b){ 34 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | string a; 20 | cin>>a; 21 | int count = 0; 22 | for(int i = 0; i < n; i++){ 23 | if(a[i] == '2'){ 24 | count++; 25 | } 26 | } 27 | if(count == 1 || count == 2){ 28 | cout<<"NO"< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin>>t; 8 | int n, steps; 9 | string s; 10 | while(t--){ 11 | cin>>n; 12 | cin>>s; 13 | steps = 0; 14 | for(int i = 0; i < n-1; i++){ 15 | if(s[i] != '0'){ 16 | steps += (s[i] - '0') + 1; 17 | } 18 | } 19 | steps += (s[n-1] - '0'); 20 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | while(t--){ 9 | cin>>n; 10 | char arr[2*n]; 11 | for(int i = 0; i < 2*n; i++){ 12 | if(i % 2 == 0){ 13 | arr[i] = '('; 14 | continue; 15 | } 16 | arr[i] = ')'; 17 | } 18 | for(int i = 0; i < 2*n; i++){ 19 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a[3], m; 18 | cin>>a[0]>>a[1]>>a[2]>>m; 19 | sort(a, a + 3); 20 | int low = a[2] - 1 - (a[0] + a[1]); 21 | int high = a[2] + a[1] + a[0] - 3; 22 | (m <= high && m >= low) ? cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | int t; 8 | cin>>t; 9 | string s; 10 | while(t--){ 11 | cin>>s; 12 | int a = 0, b = 0, c = 0; 13 | for(auto i : s){ 14 | 15 | if(i == 'A'){ 16 | a++; 17 | continue; 18 | } 19 | if(i == 'B'){ 20 | b++; 21 | continue; 22 | } 23 | if(i == 'C'){ 24 | c++; 25 | continue; 26 | } 27 | } 28 | if(a + c == b){ 29 | cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | int arr[n]; 20 | for(int i = 0; i < n; i++){ 21 | cin>>arr[i]; 22 | } 23 | 24 | int brr[n][3]; 25 | int k = 0; 26 | for(int i = 1; i < n; i++){ 27 | int key = arr[i]; 28 | if(arr[i] < arr[i-1]){ 29 | int j = i - 1; 30 | int count = 0; 31 | while(arr[j] > key && j >= 0){ 32 | count++; 33 | arr[j + 1] = arr[j]; 34 | j--; 35 | } 36 | arr[j + 1] = key; 37 | brr[k][0] = i + 1; 38 | brr[k][1] = j + 2; 39 | brr[k][2] = count; 40 | k++; 41 | } 42 | 43 | } 44 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | 8 | int n; 9 | while(t--){ 10 | deque deqs; 11 | cin>>n; 12 | int x; 13 | for(int i = 0; i < n;i++){ 14 | cin>>x; 15 | if(x > deqs.front()){ 16 | deqs.push_back(x); 17 | continue; 18 | } 19 | deqs.push_front(x); 20 | } 21 | for(int i = 0; i < n; i++){ 22 | cout< 2 | using namespace std; 3 | 4 | 5 | 6 | int main(){ 7 | const unsigned int M = 1000000007; 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(NULL); 10 | int t; 11 | cin>>t; 12 | while(t--){ 13 | long long n; 14 | cin>>n; 15 | unsigned long long fact = 1; 16 | for(int i = 1; i <= n*2; i++){ 17 | fact = (fact * i)%M; 18 | fact = fact%M; 19 | } 20 | cout<<(fact*500000004)%M< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)< 12 | using namespace std; 13 | 14 | 15 | 16 | 17 | int main(){ 18 | ios_base::sync_with_stdio(false); 19 | cin.tie(NULL); 20 | 21 | int t; 22 | cin>>t; 23 | ll a, b, c; 24 | while(t--){ 25 | cin>>a>>b>>c; 26 | 27 | ll n = a + 2 * b + 3 * c; 28 | cout<<(n%2)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 26 | while(t--){ 27 | ll n; 28 | cin>>n; 29 | ll x = 0, y = 0, k; 30 | for(ll i = 0; i < n; i++){ 31 | cin>>k; 32 | if(k == 1){ 33 | x++; 34 | continue; 35 | } 36 | if(k == 0){ 37 | y++; 38 | continue; 39 | } 40 | 41 | } 42 | cout<<(x * powd(2,y))< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | int k; 7 | int count; 8 | cin>>n; 9 | cin>>k; 10 | int arr[n]; 11 | for(int i = 0; i < n; i++){ 12 | cout<<"i:"<>arr[i]; 14 | } 15 | int quali = 0, m; 16 | if(arr[k-1] == 0){ 17 | 18 | for(m = k-2; m >= 0; m--){ 19 | 20 | if(arr[m] > 0){ 21 | 22 | quali = arr[m]; 23 | count = m+1; 24 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int t; 9 | cin>>t; 10 | int n, h; 11 | while(t--){ 12 | cin>>n>>h; 13 | int arr[n]; 14 | for(int i = 0; i < n; i++){ 15 | cin>>arr[i]; 16 | } 17 | sort(arr, arr+n, greater()); 18 | int w1 = arr[0] + arr[1]; 19 | int move = 0; 20 | if(h % w1 == 0){ 21 | cout<<(h / w1 * 2)< arr[0]){ 25 | cout<<(h / w1 * 2 + 2)< 0){ 29 | cout<<(h / w1 * 2 + 1)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | int a, b, c; 17 | while(t--){ 18 | cin>>a>>b>>c; 19 | if(a > b && a > c){ 20 | cout<<(a - a)<<" "<<( a- b + 1)<<" "<<(a - c + 1)< a && b > c){ 24 | cout<<(b - a + 1)<<" "<<( b- b)<<" "<<(b - c + 1)< a && c > b){ 28 | cout<<(c - a + 1)<<" "<<( c- b + 1)<<" "<<(c - c)< c){ 32 | cout<<(a - a + 1)<<" "<<( a- b + 1)<<" "<<(a - c + 1)< a){ 36 | cout<<(b - a + 1)<<" "<<( b- b + 1)<<" "<<(b - c + 1)< b){ 40 | cout<<(c - a + 1)<<" "<<( c- b + 1)<<" "<<(c - c + 1)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)< 0 && t.length() > 0) { 14 | if(s.back() == t.back()) { 15 | t.pop_back(); 16 | } 17 | else { 18 | count++; 19 | } 20 | s.pop_back(); 21 | } 22 | if(t.length() == 0){ 23 | return count; 24 | } 25 | return l; 26 | } 27 | int main() { 28 | ios_base::sync_with_stdio(false); 29 | cin.tie(NULL); 30 | int t; 31 | cin>>t; 32 | while(t--) { 33 | string s; 34 | cin>>s; 35 | if(s.length() < 2) { 36 | cout << s.length()< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | ll n; 18 | cin>>n; 19 | ll arr[n]; 20 | for(ll i = 0; i < n; i++){ 21 | cin>>arr[i]; 22 | } 23 | 24 | sort(arr,arr+n); 25 | ll count = 0; 26 | 27 | for(ll i = 1; i < n; i++){ 28 | count = __gcd(count, arr[i] - arr[i-1]); 29 | } 30 | 31 | if(count == 0){ 32 | cout<<-1< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | 17 | ll n; 18 | while(t--){ 19 | cin>>n; 20 | cout<<(-1 * (n - 1))<<" "< 2 | #include 3 | using namespace std; 4 | 5 | long long MOD = 1e9 + 7; 6 | #define ll long long 7 | #define ull unsigned long long 8 | #define debug(n) cout<<(n)< 0) { 24 | arr[i] = n % 2; 25 | n = n / 2; 26 | i++; 27 | } 28 | return i; 29 | } 30 | 31 | int main(){ 32 | ios_base::sync_with_stdio(false); 33 | cin.tie(NULL); 34 | 35 | int t; 36 | cin>>t; 37 | ull n, k; 38 | while(t--){ 39 | cin>>n>>k; 40 | ull ans = 0; 41 | 42 | ull s[32]; 43 | ull bit = binary(s, k); 44 | for(ull i=0;i< bit;i++){ 45 | if(s[i]== 1){ 46 | ans = (ans + mypow(n,i)%MOD); 47 | } 48 | } 49 | cout<<(ans%MOD)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | string s; 18 | cin>>s; 19 | string k = s; 20 | sort(s.begin(), s.end()); 21 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | cin>>n; 18 | int arr[n]; 19 | 20 | int max = -1; 21 | for(int i = 0; i < n; i++){ 22 | cin>>arr[i]; 23 | if(arr[i] > max){ 24 | max = arr[i]; 25 | } 26 | 27 | } 28 | int brr[max][n]; 29 | 30 | for(int i = 0; i < n; i++){ 31 | brr[0][i] = arr[i]; 32 | } 33 | 34 | for(int j = 0; j < max; j++){ 35 | unordered_map mp; 36 | for (int i = 0; i < n; i++){ 37 | mp[brr[j][i]]++; 38 | } 39 | for(int i = 0; i < n; i++){ 40 | brr[j+1][i] = mp[brr[j][i]]; 41 | } 42 | 43 | } 44 | 45 | int q, a, b; 46 | cin>>q; 47 | while(q-- ){ 48 | cin>>a>>b; 49 | if(b < max){ 50 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | int maxel = 0; 20 | int x; 21 | for(int i = 1; i <= n; i++){ 22 | cin>>x; 23 | if(x - i > maxel){ 24 | maxel = x - i; 25 | } 26 | } 27 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a, b, c; 18 | cin>>a>>b>>c; 19 | int diff = 2 * b - (a + c); 20 | (diff % 3 == 0) ? cout<<0< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | string s, k; 20 | cin>>s; 21 | k = s; 22 | sort(s.begin(), s.end()); 23 | int arr[n]; 24 | int m = 0; 25 | for(int i = 0; i < s.length(); i++){ 26 | if(k[i] != s[i]){ 27 | arr[m] = i+1; 28 | m++; 29 | } 30 | } 31 | if(m != 0){ 32 | cout<<1< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | string s; 18 | cin>>s; 19 | if(s[0] == s[s.length() - 1]){ 20 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | string k, s; 18 | cin>>k>>s; 19 | int move = 0; 20 | for(int i = 0; i < s.length() - 1; i++){ 21 | char curr = s[i]; 22 | char nxt = s[i+1]; 23 | int curr_i = k.find(curr); 24 | int nxt_i = k.find(nxt); 25 | move += abs(nxt_i - curr_i); 26 | } 27 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | ll n, moves; 18 | cin>>n>>moves; 19 | if(n % 2 == 0){ 20 | if(moves % 4 == 0){ 21 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | int arr[n]; 20 | for(int i = 0; i < n; i++){ 21 | cin>>arr[i]; 22 | } 23 | sort(arr, arr + n); 24 | int brr[n]; 25 | brr[0] = arr[0]; 26 | for(int i = 1; i < n; i++){ 27 | brr[i] = arr[i] - arr[i - 1]; 28 | } 29 | sort(brr, brr+n, greater()); 30 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int n; 9 | cin>>n; 10 | int *arr; 11 | arr = new int[n]; 12 | for(int i = 0; i < n; i++){ 13 | cin>>*(arr+i); 14 | } 15 | sort(arr, arr+n); 16 | 17 | int sum1 = 0, sum2 = *(arr+n-1); 18 | for(int j = 0; j < n-1; j++){ 19 | sum1 += *(arr+j); 20 | } 21 | 22 | int i = 1; 23 | while(i <= n){ 24 | if(sum2 > sum1){ 25 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n, m; 18 | cin>>n>>m; 19 | if(n == 1 && m == 1){ 20 | cout<<0< 0): 4 | t -= 1 5 | s = input() 6 | n = len(s) 7 | if n % 2 != 0: 8 | print("NO") 9 | continue 10 | elif s[:n//2] == s[n//2:]: 11 | print("YES") 12 | else: 13 | print("NO") 14 | -------------------------------------------------------------------------------- /1629A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n, k; 18 | cin>>n>>k; 19 | vector > vect(n); 20 | for(int i = 0; i < n; i++){ 21 | cin>>vect[i].first; 22 | } 23 | for(int i = 0; i < n; i++){ 24 | cin>>vect[i].second; 25 | } 26 | sort(vect.begin(), vect.end()); 27 | for(int i = 0; i < n; i++){ 28 | if(vect[i].first > k){ 29 | break; 30 | } 31 | k += vect[i].second; 32 | } 33 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int l1, r1, l2, r2; 18 | cin>>l1>>r1>>l2>>r2; 19 | if(r1 >= max(l1, l2) && r2 >= max(l1, l2)){ 20 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n, k; 18 | cin>>n; 19 | int count = 0; 20 | int min = 10; 21 | k = n; 22 | while(k > 0){ 23 | count++; 24 | if(k % 10 < min){ 25 | min = k % 10; 26 | } 27 | k /= 10; 28 | } 29 | if(count == 2){ 30 | cout<<(n%10)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a, b, c; 18 | cin>>a>>b>>c; 19 | cout<<(a+b+c)<<" "<<(b+c)<<" "<<(c)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | 20 | int arr[n]; 21 | for(int i = 0; i < n; i++){ 22 | cin>>arr[i]; 23 | } 24 | if(n == 1){ 25 | cout<<0< arr[j]){ 33 | count++; 34 | i += 2; 35 | j += 2; 36 | } 37 | else{ 38 | i++; 39 | j++; 40 | } 41 | } 42 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | int eve = 0, odd = 0; 20 | int x; 21 | while(n--){ 22 | cin>>x; 23 | if(x % 2 == 0){ 24 | eve++; 25 | } 26 | else{ 27 | odd++; 28 | } 29 | } 30 | 31 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int a; 18 | cin>>a; 19 | int x, count = 0; 20 | for(int i = 0; i < 3; i++){ 21 | cin>>x; 22 | if(x > a){ 23 | count++; 24 | } 25 | } 26 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 15 | while(t--){ 16 | int n; 17 | cin>>n; 18 | int arr[n]; 19 | set st; 20 | for(int i = 0; i < n; i++){ 21 | cin>>arr[i]; 22 | st.insert(arr[i]); 23 | } 24 | int sub = n - st.size(); 25 | if(sub%2){ 26 | sub++; 27 | } 28 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n, k; 18 | cin>>n>>k; 19 | int x, sum = 0; 20 | for(int i = 0; i < n; i++){ 21 | cin>>x; 22 | sum += x; 23 | } 24 | if(sum - k <= 0){ 25 | cout<<0< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | int n, m; 8 | cin>>n>>m; 9 | 10 | multimap > marr; 11 | int x, y; 12 | for(int i = 0; i < m; i++){ 13 | cin>>x>>y; 14 | marr.insert(pair (y, x)); 15 | 16 | } 17 | 18 | multimap :: iterator itr; 19 | int count = 0, sum = 0; 20 | for (itr = marr.begin(); itr != marr.end(); ++itr) 21 | { 22 | count += itr->second; 23 | if(count >= n){ 24 | itr->second = itr->second - (count - n); 25 | sum += itr->first * itr->second; 26 | break; 27 | } 28 | sum += itr->first * itr->second; 29 | 30 | 31 | } 32 | cout < 0: 4 | t -= 1 5 | s = input() 6 | if s.upper() == 'YES': 7 | print("YES") 8 | else: 9 | print("NO") 10 | -------------------------------------------------------------------------------- /1703B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | string s; 20 | cin>>s; 21 | unordered_set uos; 22 | for(char c : s){ 23 | uos.insert(c); 24 | } 25 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | int H, M; 21 | cin>>H>>M; 22 | int h, m; 23 | int timeh, timem, mintimeh = 24, mintimem = 60; 24 | while(n--){ 25 | cin>>h>>m; 26 | timeh = h - H; 27 | timem = m - M; 28 | if(timem < 0){ 29 | timem += 60; 30 | timeh--; 31 | } 32 | if(timeh < 0){ 33 | timeh += 24; 34 | } 35 | if(timeh < mintimeh){ 36 | mintimeh = timeh; 37 | mintimem = timem; 38 | } 39 | else if(timeh == mintimeh && timem < mintimem){ 40 | mintimem = timem; 41 | } 42 | 43 | } 44 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | int ans; 20 | if(n == 1){ 21 | ans = 2; 22 | } 23 | else if(n % 3 != 0){ 24 | ans = n/3 + 1; 25 | } 26 | else{ 27 | ans = n/3; 28 | } 29 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | unordered_set uos; 18 | string s1, s2; 19 | cin>>s1>>s2; 20 | uos.insert(s1[0]); 21 | uos.insert(s1[1]); 22 | uos.insert(s2[0]); 23 | uos.insert(s2[1]); 24 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n, m; 18 | cin>>n>>m; 19 | int check = 0; 20 | for(int i = 1; i <= n; i++){ 21 | for(int j = 1; j <= m; j++){ 22 | if((i + 2 <= n && j+1 <= m)||(i + 2 <= n && j-1 >= 1)||(i-2 >= 1 && j +1 <= m)||(i-2 >= 1 && j -1 >= 1) 23 | ||(j+2 <= m && i+1 <= n) || (j+2 <= m && i-1 >= 1) ||(j-2 >= 1 && i +1 <= n)||(j-2 >= 1 && i -1 >= 1)){ 24 | continue; 25 | } 26 | else{ 27 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 15 | while(t--){ 16 | int n; 17 | cin>>n; 18 | int drr[n]; 19 | for(int i = 0; i < n; i++){ 20 | cin>>drr[i]; 21 | } 22 | int arr[n]; 23 | int check = 0; 24 | arr[0] = drr[0]; 25 | for(int i = 1; i < n; i++){ 26 | int a = arr[i-1] + drr[i]; 27 | int b = arr[i-1] - drr[i]; 28 | if((a > 0 && b > 0) && (a != b)){ 29 | cout<<-1< 0){ 35 | arr[i] = a; 36 | } 37 | else{ 38 | arr[i] = b; 39 | } 40 | } 41 | } 42 | if(check){ 43 | continue; 44 | } 45 | else{ 46 | for(int i = 0; i < n; i++){ 47 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | int m; 20 | cin>>m; 21 | int rooks[m][2]; 22 | for(int i = 0; i < m; i++){ 23 | cin>>rooks[i][0]>>rooks[i][1]; 24 | } 25 | if(m < n){ 26 | cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | string s; 20 | cin>>s; 21 | int ans = 0; 22 | for(int i = 0; i < n; i++){ 23 | ans = max(ans, s[i] - 'a' + 1); 24 | } 25 | cout< 0: 4 | n = input() 5 | l = len(n) 6 | ans = 0 7 | ans += int(n[0]) 8 | l -= 1 9 | ans += 9 * l 10 | print(ans) 11 | t -= 1 12 | -------------------------------------------------------------------------------- /1766B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | bool flag = false; 19 | int n; 20 | cin>>n; 21 | map mp; 22 | string s; 23 | cin>>s; 24 | string a; 25 | for(int i = 1; i < n; i++){ 26 | a = ""; 27 | a += s[i-1]; 28 | a += s[i]; 29 | if(mp.find(a) != mp.end() && mp[a] < i-1){ 30 | flag = true; 31 | break; 32 | } 33 | else if(mp.find(a) == mp.end()){ 34 | mp[a] = i; 35 | } 36 | 37 | } 38 | if(flag) cout<<"YES"< 0: 4 | n = int(input()) 5 | s = input() 6 | ans = "" 7 | ind = 0 8 | sign = '+' 9 | for i in range(n-1): 10 | if sign == '+': 11 | ind += int(s[i]) 12 | else: 13 | ind -= int(s[i]) 14 | 15 | if ind == 1: 16 | sign = '-' 17 | else: 18 | sign = '+' 19 | ans += sign 20 | 21 | print(ans) 22 | 23 | t -= 1 24 | -------------------------------------------------------------------------------- /1774B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n, m, k; 19 | cin>>n>>m>>k; 20 | int seg; 21 | if (n % k != 0){ 22 | seg = n/k + 1; 23 | } 24 | else{ 25 | seg = n /k; 26 | } 27 | int x, count = 0; 28 | bool check = true; 29 | for(int i = 0; i < m; i++){ 30 | cin>>x; 31 | if(x > seg){ 32 | check = false; 33 | } 34 | if(x == seg){ 35 | count++; 36 | } 37 | } 38 | if(n % k != 0 && count > n % k){ 39 | check = false; 40 | } 41 | if(check){ 42 | cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 18 | while(t--){ 19 | int n; 20 | cin>>n; 21 | int arr[n]; 22 | int x, ans = 0; 23 | for(int i = 0; i < n; i++){ 24 | cin>>arr[i]; 25 | } 26 | for(int i = 0; i < n-1; i++){ 27 | if(((arr[i] % 2) and (arr[i+1]%2)) or ((arr[i]%2 == 0) and (arr[i+1]%2 == 0))){ 28 | ans++; 29 | } 30 | } 31 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | ll n; 19 | cin>>n; 20 | ll res = (n-1)*n; 21 | for(ll i = 1; i <= n; i++){ 22 | res = ((res%1000000007)*i)%1000000007; 23 | } 24 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | int n; 18 | while(t--){ 19 | cin>>n; 20 | int arr[n]; 21 | int prev, curr; 22 | bool two1 = false, one1 = false; 23 | int ans = 0; 24 | cin>>prev; 25 | ans += prev; 26 | for(int i = 0; i < n-1; i++){ 27 | cin>>curr; 28 | ans += curr; 29 | if(prev == -1 && curr == -1){ 30 | two1 = true; 31 | } 32 | if(prev == 1 && curr == -1){ 33 | one1 = true; 34 | } 35 | if(prev == -1 && curr == 1){ 36 | one1 = true; 37 | } 38 | prev = curr; 39 | } 40 | if(two1){ 41 | ans += 4; 42 | } 43 | else if(!one1 && !two1){ 44 | ans -= 4; 45 | } 46 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | int count = 1; 21 | long long alice = 0, bob = 0; 22 | bool flag = true; 23 | while(n > 0){ 24 | if(flag){ 25 | if(n - count > 0){ 26 | alice += count; 27 | n -= count; 28 | count++; 29 | } 30 | else{ 31 | alice += n; 32 | n = 0; 33 | } 34 | if(n - count > 0){ 35 | bob += count; 36 | n -= count; 37 | count++; 38 | } 39 | else{ 40 | bob += n; 41 | n = 0; 42 | } 43 | flag = !flag; 44 | } 45 | else{ 46 | if(n - count > 0){ 47 | bob += count; 48 | n -= count; 49 | count++; 50 | } 51 | else{ 52 | bob += n; 53 | n = 0; 54 | } 55 | if(n - count > 0){ 56 | alice += count; 57 | n -= count; 58 | count++; 59 | } 60 | else{ 61 | alice += n; 62 | n = 0; 63 | } 64 | flag = !flag; 65 | } 66 | } 67 | cout< 0: 6 | if (rang >= n): 7 | alice += (n) 8 | break 9 | else: 10 | alice += rang 11 | n -= rang 12 | rang += 4 13 | if rang >= n: 14 | bob += (n) 15 | break 16 | else: 17 | bob += rang 18 | n -= rang 19 | rang += 4 20 | print(alice, bob) 21 | -------------------------------------------------------------------------------- /1786B.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n, w, h = map(int, input().split()) 3 | cakes = list(map(int, input().split())) 4 | dispenser = list(map(int, input().split())) 5 | 6 | status = True 7 | a, b = float('-inf'), float('inf') 8 | for i in range(n): 9 | a = max(a, cakes[i]-w+h-dispenser[i]) 10 | b = min(b, cakes[i]-dispenser[i]+w-h) 11 | # print(a, b) 12 | if a > b: 13 | print("NO") 14 | status = False 15 | break 16 | 17 | if status: 18 | print("YES") 19 | -------------------------------------------------------------------------------- /1786C.py: -------------------------------------------------------------------------------- 1 | for _ in range(int(input())): 2 | n = int(input()) 3 | elements = list(map(int, input().split())) 4 | elements.sort() 5 | res = 0 6 | cnt = 1 7 | prev = None 8 | for i in range(n): 9 | if cnt > elements[i]: 10 | continue 11 | res += (elements[i]-cnt) 12 | cnt += 1 13 | 14 | print(res) 15 | -------------------------------------------------------------------------------- /1787A.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | for _ in range(int(input())): 4 | n = int(input()) 5 | if n % 2 == 0: 6 | print(1, n//2) 7 | else: 8 | print(-1) 9 | -------------------------------------------------------------------------------- /1788A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | int arr[n]; 21 | for(int i = 0; i < n; i++){ 22 | cin>>arr[i]; 23 | } 24 | int prefix[n], suffix[n]; 25 | int count = 0; 26 | for(int i = 0; i < n; i++){ 27 | if(arr[i] == 2){ 28 | count++; 29 | } 30 | prefix[i] = count; 31 | } 32 | count = 0; 33 | for(int i = n-1; i >= 0; i--){ 34 | if(arr[i] == 2){ 35 | count++; 36 | } 37 | suffix[i] = count; 38 | } 39 | int ans = -1; 40 | for(int i = 0; i < n-1; i++){ 41 | if(prefix[i] == suffix[i+1]){ 42 | ans = i+1; 43 | break; 44 | } 45 | } 46 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 26 | while(t--){ 27 | int n; 28 | cin>>n; 29 | int i = 0; 30 | bool check = false; 31 | int ndigts[10]; 32 | while(n){ 33 | ndigts[i++] = n%10; 34 | n /= 10; 35 | } 36 | vector x(10); 37 | vector y(10); 38 | for(int j = 0;j < i;j++) { 39 | if(ndigts[j] & 1) { 40 | x[j] = ndigts[j]/2 + check; 41 | y[j] = ndigts[j]/2 + 1 - check; 42 | check = 1 - check; 43 | } 44 | else{ 45 | x[j] = ndigts[j] / 2; 46 | y[j] = ndigts[j] - x[j]; 47 | } 48 | } 49 | int l = 0, m = 0, u = 1; 50 | for(int j = 0; j < i; j++) { 51 | m += y[j]*u; 52 | l += x[j]*u; 53 | u *= 10; 54 | } 55 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | if(n % 2 == 1) { 21 | cout<<"yes"<= 0: 19 | for k in range((n//2)//2): 20 | print(arr[i], arr[j]) 21 | i -= 1 22 | j += 2 23 | j = n//2 24 | i = (n//2)-1 25 | # print(((n//2)//2)+1) 26 | 27 | for k in range(((n//2)//2)+1): 28 | print(arr[i], arr[j]) 29 | i -= 1 30 | j += 2 31 | -------------------------------------------------------------------------------- /1790A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 18 | while(t--){ 19 | string s; 20 | cin>>s; 21 | int i = 0; 22 | while(i < s.size() && i < p.size() && s[i] == p[i]) i++; 23 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n, s, r; 19 | cin>>n>>s>>r; 20 | int m = s - r; 21 | int arr[n]; 22 | for(int i = 0; i < n; i++){ 23 | arr[i] = 1; 24 | } 25 | s -= n; 26 | int i = 0; 27 | while(s > 0){ 28 | if(s >= m){ 29 | arr[i] = m; 30 | s -= (m-1); 31 | } 32 | else{ 33 | arr[i] += s; 34 | s = 0; 35 | } 36 | i++; 37 | } 38 | for(int i = 0; i < n; i++){ 39 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | vector freq(n+1, 0); 21 | int arr[n][n-1]; 22 | for(int i = 0; i < n; i++){ 23 | for(int j = 0; j < n-1; j++){ 24 | cin>>arr[i][j]; 25 | } 26 | freq[arr[i][0]]++; 27 | } 28 | int k = -1; 29 | for(int i = 1; i <=n; i++){ 30 | if(freq[i] == n-1) k = i; 31 | } 32 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | multiset st; 21 | int x; 22 | for(int i = 0; i < n; i++){ 23 | cin>>x; 24 | st.insert(x); 25 | } 26 | int ans = 0; 27 | while(!st.empty()){ 28 | int i = *st.begin(); 29 | ans++; 30 | for(int j = i; ; j++){ 31 | auto k = st.find(j); 32 | if(k == st.end()){ 33 | break; 34 | } 35 | else{ 36 | st.erase(k); 37 | } 38 | } 39 | } 40 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | string s = "codefrs"; 18 | while(t--){ 19 | char a; 20 | cin>>a; 21 | bool flag = false; 22 | for(auto i: s){ 23 | if(a == i){ 24 | flag = true; 25 | break; 26 | } 27 | } 28 | if(flag) cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | bool flag = false; 19 | int n; 20 | cin>>n; 21 | string s; 22 | cin>>s; 23 | int i = 0, j = 0; 24 | for(auto c: s){ 25 | if(c == 'U'){ 26 | j++; 27 | } 28 | else if(c == 'D'){ 29 | j--; 30 | } 31 | else if(c == 'L'){ 32 | i--; 33 | } 34 | else{ 35 | i++; 36 | } 37 | if(i == 1 && j == 1){ 38 | flag = true; 39 | break; 40 | } 41 | } 42 | if(flag) cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | string s; 21 | cin>>s; 22 | int i = 0, j = n-1; 23 | while(i <= j){ 24 | if(s[i] != s[j]){ 25 | i++; 26 | j--; 27 | } 28 | else{ 29 | break; 30 | } 31 | } 32 | cout<<(j-i)+1< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | unordered_set pre; 21 | unordered_set suff; 22 | vector prefix, suffix(n, 0); 23 | string s; 24 | cin>>s; 25 | for(auto i:s){ 26 | pre.insert(i); 27 | prefix.pb(pre.size()); 28 | 29 | } 30 | for(int i = n-1; i >=0; i--){ 31 | suff.insert(s[i]); 32 | suffix[i] = suff.size(); 33 | 34 | } 35 | int ans = 0; 36 | for(int i = 0; i < n-1; i++){ 37 | 38 | ans = max(prefix[i]+suffix[i+1], ans); 39 | } 40 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int n; 19 | cin>>n; 20 | vector arr(n), prefix(n, 0); 21 | ll ans = 0, count = 0; 22 | for(int i = 0; i < n; i++){ 23 | cin>>arr[i]; 24 | ans += abs(arr[i]); 25 | if(arr[i] < 0) count++; 26 | } 27 | for(int i= 0;i < n; i++){ 28 | if(arr[i] < 0){ 29 | arr[i] = abs(arr[i]); 30 | } 31 | } 32 | if(!(count % 2)){ 33 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | ll n, c; 19 | cin>>n>>c; 20 | vector arr; 21 | ll x; 22 | for(int i = 0; i < n; i++){ 23 | cin>>x; 24 | arr.pb(x+i+1); 25 | } 26 | sort(arr.begin(), arr.end()); 27 | ll ans = 0; 28 | for(int i = 0; i < n;i++){ 29 | if(c >= arr[i]){ 30 | c -= arr[i]; 31 | ans++; 32 | } 33 | else{ 34 | break; 35 | } 36 | } 37 | cout< c): 14 | break 15 | cnt += 1 16 | print(cnt) 17 | -------------------------------------------------------------------------------- /1792B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | while(t--){ 18 | int a, b, c, d; 19 | cin>>a>>b>>c>>d; 20 | ll ans = 1; 21 | if(a) ans = a + min(b, c) * 2 + min(a + 1, abs(b - c) + d); 22 | cout<0: 19 | out = 1 20 | else: 21 | out = 2 22 | else: 23 | out = 1 24 | 25 | outs.append(out) 26 | 27 | for out in outs: 28 | print(out) -------------------------------------------------------------------------------- /1933C.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | t = int(input()) 4 | outs = [] 5 | 6 | 7 | for tt in range(t): 8 | a, b, l = map(int, input().split()) 9 | 10 | x_m = math.ceil(math.log(l)/math.log(a)) 11 | y_m = math.ceil(math.log(l)/math.log(b)) 12 | 13 | ks = set() 14 | for x in range(x_m+1): 15 | for y in range(y_m+1): 16 | k = l/(a**x)/(b**y) 17 | if k>0 and math.floor(k)==math.ceil(k): 18 | ks.add(math.floor(k)) 19 | 20 | outs.append(len(ks)) 21 | 22 | for out in outs: 23 | print(out) -------------------------------------------------------------------------------- /1933D.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | for tt in range(t): 5 | n = int(input()) 6 | a = list(map(int, input().split())) 7 | 8 | a.sort() 9 | if a[0]!=a[1]: 10 | out = 'YES' 11 | else: 12 | if n==2: 13 | out = 'NO' 14 | else: 15 | out = False 16 | for aa in a[2:]: 17 | if aa%a[0]!=0: 18 | out = True 19 | break 20 | out = 'YES' if out else 'NO' 21 | outs.append(out) 22 | 23 | for out in outs: 24 | print(out) -------------------------------------------------------------------------------- /1948B.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n = int(input()) 7 | a = list(map(int, input().split())) 8 | 9 | last = a[-1] 10 | 11 | pos = True 12 | for aa in a[:-1][::-1]: 13 | 14 | if aa>last: 15 | if aa>=10 and aa//10<=aa%10 and aa%10<=last: 16 | last = aa//10 17 | else: 18 | pos = False 19 | break 20 | else: 21 | last = aa 22 | 23 | out = 'YES' if pos else 'NO' 24 | outs.append(out) 25 | 26 | 27 | for out in outs: 28 | print(out) -------------------------------------------------------------------------------- /1957A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>t; 17 | 18 | while(t--){ 19 | ll n; 20 | cin>>n; 21 | 22 | unordered_map mp; 23 | ll x; 24 | for(ll i = 0; i < n; i++){ 25 | cin>>x; 26 | mp[x]++; 27 | } 28 | 29 | unordered_map::iterator it = mp.begin(); 30 | ll count = 0; 31 | while (it != mp.end()) { 32 | count += it->second / 3; 33 | ++it; 34 | } 35 | cout<=k: 18 | pos=True 19 | 20 | out = k-1 if pos else n 21 | outs.append(out) 22 | 23 | 24 | for out in outs: 25 | print(out) -------------------------------------------------------------------------------- /1966B.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n, m = map(int, input().split()) 7 | a = [None]*n 8 | for i in range(n): 9 | r = input() 10 | a[i] = r 11 | 12 | b = {'x':{}, 'y':{}} 13 | w = {'x':{}, 'y':{}} 14 | 15 | b['x']['min'], b['x']['max'] = 550, -1 16 | b['y']['min'], b['y']['max'] = 550, -1 17 | w['x']['min'], w['x']['max'] = 550, -1 18 | w['y']['min'], w['y']['max'] = 550, -1 19 | 20 | pos = False 21 | for i in range(n): 22 | for j in range(m): 23 | if a[i][j]=='B': 24 | b['x']['min']=min(b['x']['min'], i) 25 | b['x']['max']=max(b['x']['max'], i) 26 | b['y']['min']=min(b['y']['min'], j) 27 | b['y']['max']=max(b['y']['max'], j) 28 | else: 29 | w['x']['min']=min(w['x']['min'], i) 30 | w['x']['max']=max(w['x']['max'], i) 31 | w['y']['min']=min(w['y']['min'], j) 32 | w['y']['max']=max(w['y']['max'], j) 33 | 34 | if b['x']['min']==0 and b['x']['max']==n-1 and b['y']['min']==0 and b['y']['max']==m-1: 35 | pos = True 36 | break 37 | elif w['x']['min']==0 and w['x']['max']==n-1 and w['y']['min']==0 and w['y']['max']==m-1: 38 | pos = True 39 | break 40 | 41 | out = 'YES' if pos else 'NO' 42 | outs.append(out) 43 | 44 | 45 | for out in outs: 46 | print(out) 47 | -------------------------------------------------------------------------------- /1966C.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n = int(input()) 7 | a = list(map(int, input().split())) 8 | 9 | a = [0] + sorted(list(set(a))) 10 | 11 | win = True 12 | for i in range(len(a)-3, -1, -1): 13 | if a[i+1]-a[i]==1: 14 | win = not win 15 | else: 16 | win = True 17 | 18 | out = 'Alice' if win else 'Bob' 19 | outs.append(out) 20 | 21 | 22 | for out in outs: 23 | print(out) -------------------------------------------------------------------------------- /1968A.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | x = int(input()) 7 | 8 | outs.append(x-1) 9 | 10 | for out in outs: 11 | print(out) 12 | -------------------------------------------------------------------------------- /1968B.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n, m = map(int, input().split()) 7 | a = input() 8 | b = input() 9 | 10 | i, j = 0, 0 11 | while ix[i-1] and x[i-1]!=1 and x[i-1]>x[i]: 14 | a[i]=x[i-1] 15 | else: 16 | mul = x[i]//a[i-1] 17 | if a[i-1]*mul + x[i-1]>x[i]: 18 | a[i] = mul*a[i-1]+x[i-1] 19 | else: 20 | a[i] = (mul+1)*a[i-1]+x[i-1] 21 | 22 | a[-1] = x[-1] 23 | 24 | outs.append(a) 25 | 26 | for out in outs: 27 | print(*out) 28 | -------------------------------------------------------------------------------- /1969A.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n = int(input()) 7 | p = list(map(int, input().split())) 8 | 9 | out = 3 10 | for i in range(1, n+1): 11 | if p[p[i-1]-1]==i: 12 | out=2 13 | break 14 | 15 | outs.append(out) 16 | 17 | 18 | for out in outs: 19 | print(out) -------------------------------------------------------------------------------- /1969B.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | s = input() 7 | n = len(s) 8 | 9 | lst = -1 10 | for i in range(n): 11 | if s[i]=='0': 12 | lst=i 13 | else: 14 | break 15 | 16 | tot = 0 17 | for i in range(lst+1, n): 18 | if s[i]=='0': 19 | tot+=i-lst 20 | lst+=1 21 | 22 | outs.append(tot) 23 | 24 | 25 | for out in outs: 26 | print(out) -------------------------------------------------------------------------------- /1972A.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n = int(input()) 7 | a = list(map(int, input().split())) 8 | b = list(map(int, input().split())) 9 | 10 | tot = 0 11 | a_i, b_i = 0, 0 12 | 13 | while b_ib[b_i]: 15 | tot+=1 16 | b_i+=1 17 | else: 18 | a_i+=1 19 | b_i+=1 20 | 21 | outs.append(tot) 22 | 23 | 24 | for out in outs: 25 | print(out) 26 | -------------------------------------------------------------------------------- /1972B.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n = int(input()) 7 | s = input() 8 | 9 | sum_=0 10 | for ss in s: 11 | sum_ = sum_ ^ (int(ss=='U')) 12 | 13 | out = 'YES' if sum_!=0 else 'NO' 14 | 15 | outs.append(out) 16 | 17 | 18 | for out in outs: 19 | print(out) 20 | -------------------------------------------------------------------------------- /1972C.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n, k = map(int, input().split()) 7 | a = list(map(int, input().split())) 8 | 9 | a.sort() 10 | min_, min_idx = a[0], 0 11 | 12 | for i in range(1, n): 13 | trg = i*(a[i]-min_) 14 | if k>=trg: 15 | k-=trg 16 | min_ = a[i] 17 | min_idx = i 18 | else: 19 | min_ += k//i 20 | min_idx = i-1 21 | k = k%i 22 | break 23 | 24 | if min_idx==n-1 and k>0: 25 | min_ += k//n 26 | k = k%n 27 | 28 | tot = min_ + (min_-1)*(n-1) + (n-1-min_idx) + k 29 | 30 | outs.append(tot) 31 | 32 | 33 | for out in outs: 34 | print(out) 35 | -------------------------------------------------------------------------------- /1972D1.py: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | outs = [] 3 | 4 | 5 | for tt in range(t): 6 | n, m = map(int, input().split()) 7 | 8 | tot = 0 9 | 10 | for b in range(1, m+1): 11 | tot+=(n+b)//b**2 12 | 13 | outs.append(tot-1) 14 | 15 | 16 | for out in outs: 17 | print(out) 18 | -------------------------------------------------------------------------------- /1A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>m>>a; 16 | ll c = (m % a == 0) ? (m / a) : (m / a + 1); 17 | ll d = (n % a == 0) ? (n / a) : (n / a + 1); 18 | cout<<(c * d)< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | float x, sum = 0; 8 | for(int i = 0; i < n; i++){ 9 | cin>>x; 10 | sum += x; 11 | } 12 | float aver = sum / n; 13 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>s>>n; 16 | multimap mp; 17 | int a, b; 18 | for(int i = 0; i < n; i++){ 19 | cin>>a>>b; 20 | mp.insert(pair (a, b)); 21 | } 22 | for(auto i = mp.begin(); i != mp.end(); i++){ 23 | if(s > i->first){ 24 | s += i->second; 25 | } 26 | else{ 27 | cout<<"NO"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int surity = 0, count = 0, sure; 8 | 9 | for(int i = 0; i < n; i++){ 10 | sure = 0; 11 | for(int j = 0; j < 3; j++){ 12 | cin>>surity; 13 | sure += surity; 14 | 15 | } 16 | if(sure >= 2){ 17 | count++; 18 | } 19 | } 20 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<> n; 16 | if (n % 2 == 1) 17 | { 18 | cout << -1 << endl; 19 | } 20 | else 21 | { 22 | cout << "2 1"; 23 | for (int i = 3; i < n; i += 2) 24 | { 25 | cout << " " << i + 1 << " " << i; 26 | } 27 | cout << endl; 28 | } 29 | return 0; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /236A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | string s; 8 | cin>>s; 9 | int count = 1; 10 | sort(s.begin(), s.end()); 11 | char elem = s[0]; 12 | for(int i = 0; i < s.size(); i++){ 13 | if(s[i] != elem){ 14 | elem = s[i]; 15 | count++; 16 | } 17 | } 18 | if(count % 2 == 0){ 19 | cout<<"CHAT WITH HER!"; 20 | } 21 | else{ 22 | cout<<"IGNORE HIM!"; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /252C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | // #define endl "\n" 7 | #define debug(n) cout<<(n)< target){ 14 | high = mid -1; 15 | } 16 | else{ 17 | if(mid == high){ 18 | return mid; 19 | } 20 | if(arr[mid+1] > target){ 21 | return mid; 22 | } 23 | low = mid +1; 24 | } 25 | } 26 | return low; 27 | } 28 | 29 | int main(){ 30 | ios_base::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | 33 | ll n, d; 34 | cin>>n>>d; 35 | ll arr[n]; 36 | for(int i = 0; i < n; i++){ 37 | cin>>arr[i]; 38 | } 39 | ll ans = 0; 40 | for(int i = 0; i < n; i++){ 41 | ll j = binary_search(arr, i, n-1, arr[i]+d); 42 | if(j - i > 1){ 43 | ll cnt = j - i + 1; 44 | ans += ((cnt-2)*(cnt-1))/2; 45 | } 46 | } 47 | cout< 2 | using namespace std; 3 | 4 | int absol(int m){ 5 | if(m >= 0){ 6 | return m; 7 | } 8 | return (m * -1); 9 | } 10 | 11 | int main(){ 12 | int arr[5][5]; 13 | int m, n; 14 | for(int i = 0; i < 5; i++){ 15 | for(int j = 0; j < 5; j++){ 16 | cin>>arr[i][j]; 17 | if(arr[i][j] == 1){ 18 | m = i; n = j; 19 | } 20 | } 21 | } 22 | int path = absol(m - 2) + absol(n - 2); 23 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, count = 0; 7 | cin>>n; 8 | string s; 9 | cin>>s; 10 | for(int i = 0; i < n-1; i++){ 11 | if(s[i] == s[i+1]){ 12 | count++; 13 | } 14 | } 15 | cout< 3 | 4 | int main() 5 | { 6 | int n, amount(0); 7 | scanf("%d", &n); 8 | 9 | bool b[3001] = {false}; 10 | int pfactors[3001] = {0}; 11 | for (int i = 2; i <= n; ++i) 12 | { 13 | if (!b[i]) 14 | { 15 | for (int j = i + i; j <= n; j += i) 16 | { 17 | b[j] = true; 18 | pfactors[j] += 1; 19 | } 20 | } 21 | 22 | if (pfactors[i] == 2) 23 | { 24 | amount += 1; 25 | } 26 | } 27 | printf("%d\n", amount); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /271A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int a, b, c, d; 8 | while(true){ 9 | n++; 10 | a = n/1000; 11 | b = n / 100 % 10; 12 | c = n/10 % 10; 13 | d = n%10; 14 | if(a != b && a != c && a != d && b != c && b != d && c != d){ 15 | break; 16 | } 17 | 18 | } 19 | 20 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | string s; 7 | cin>>s; 8 | if(s[0] >= 97){ 9 | 10 | s[0] = s[0] - 32; 11 | } 12 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin>>n; 8 | string s; 9 | int x = 0; 10 | for(int i = 0; i < n; i++){ 11 | cin>>s; 12 | if(s == "++X" || s == "X++"){ 13 | x++; 14 | } 15 | else{ 16 | x--; 17 | } 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | int m, n; 8 | cin>>m>>n; 9 | int rem = m % n; 10 | for(int i = 0; i < (n - rem); i++){ 11 | cout<<(m/n)<<" "; 12 | } 13 | for(int i = 0; i < rem; i++){ 14 | cout<<(m/n + 1)<<" "; 15 | } 16 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | unsigned long long n, m; 9 | cin>>n>>m; 10 | if(n & 1){ 11 | (m <= (n/2 + 1)) ? cout<<(2 * m - 1)< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>s; 16 | for(int i = 0; i < s.length(); i++){ 17 | if(s[i] == '.'){ 18 | res += '0'; 19 | } 20 | else if(s[i] == '-'){ 21 | i++; 22 | if(s[i] == '.'){ 23 | res += '1'; 24 | } 25 | else{ 26 | res += '2'; 27 | } 28 | } 29 | } 30 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>m; 16 | int arr[m]; 17 | for(int i = 0; i < m; i++){ 18 | cin>>arr[i]; 19 | } 20 | sort(arr, arr+m); 21 | int res = 1000000; 22 | for(int i = 0; i <= m - n; i++){ 23 | if((arr[n + i - 1] - arr[i]) < res){ 24 | res = (arr[i+n-1] - arr[i]); 25 | } 26 | } 27 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | string s1; 8 | cin>>s1; 9 | char arr[s1.size()-1]; 10 | int j = 0; 11 | for(int i = 0; i < s1.size(); i += 2){ 12 | arr[j]= s1[i]; 13 | j++; 14 | } 15 | sort(arr, arr+j); 16 | for(int k = 0; k < j; k++){ 17 | if(k == j-1){ 18 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>m; 16 | 17 | ll p1 = 1, p2, steps = 0; 18 | while(m--){ 19 | cin>>p2; 20 | if(p2 < p1){ 21 | steps += (n - p1 + p2); 22 | } 23 | else{ 24 | steps += (p2 - p1); 25 | } 26 | p1 = p2; 27 | } 28 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)< st; 16 | string s; 17 | cin>>s; 18 | 19 | for(int i = 0; i < s.size(); i++){ 20 | if(!st.empty() && st.top() == s[i]){ 21 | st.pop(); 22 | } 23 | else{ 24 | st.push(s[i]); 25 | } 26 | } 27 | if(st.empty()){ 28 | cout<<"Yes"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, count = 1; 6 | cin>>n; 7 | int arr[n]; 8 | for(int i = 0; i < n; i++){ 9 | cin>>arr[i]; 10 | } 11 | for(int i = 0; i < n-1; i++){ 12 | if(arr[i] != arr[i+1]){ 13 | count++; 14 | } 15 | } 16 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>m; 16 | int arr[n]; 17 | for(int i = 0; i < n; i++){ 18 | cin>>arr[i]; 19 | } 20 | sort(arr, arr+n); 21 | int count = 0; 22 | for(int i = 0; i < m; i++){ 23 | if(arr[i] < 0){ 24 | count -= arr[i]; 25 | } 26 | } 27 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>a>>b; 16 | ll c = a; 17 | while(a/b != 0){ 18 | ll temp = a; 19 | c += a/b; 20 | a /= b; 21 | a += temp % b; 22 | } 23 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | list listn; 8 | int x; 9 | for(int i = 0; i < n; i++){ 10 | cin>>x; 11 | listn.push_back(x); 12 | } 13 | int sereja = 0, dima = 0; 14 | bool turn = true; 15 | while(n--){ 16 | turn = !turn; 17 | if(turn){ 18 | if(listn.front() >= listn.back()){ 19 | dima += listn.front(); 20 | listn.pop_front(); 21 | continue; 22 | } 23 | dima += listn.back(); 24 | listn.pop_back(); 25 | continue; 26 | } 27 | if(listn.front() >= listn.back()){ 28 | sereja += listn.front(); 29 | listn.pop_front(); 30 | continue; 31 | } 32 | sereja += listn.back(); 33 | listn.pop_back(); 34 | continue; 35 | } 36 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>s>>t; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /405A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | ll arr[n]; 17 | for(ll i = 0; i < n; i++){ 18 | cin>>arr[i]; 19 | } 20 | 21 | sort(arr, arr+n); 22 | for(auto i : arr){ 23 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | string s, t; 7 | cin>>s; 8 | cin>>t; 9 | int check = 0; 10 | for(int i = 0; i < s.size(); i++){ 11 | if(s[i] != t[t.size() - i -1]){ 12 | check = -1; 13 | } 14 | } 15 | if(check == 0){ 16 | cout<<"YES"; 17 | } 18 | else{ 19 | cout<<"NO"; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /431A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int a, b, c, d; 6 | cin>>a>>b>>c>>d; 7 | string s; 8 | cin>>s; 9 | int clry = 0; 10 | for(int i = 0; i < s.size(); i++){ 11 | if(s[i] == '1'){ 12 | clry += a; 13 | continue; 14 | } 15 | if(s[i] == '2'){ 16 | clry += b; 17 | continue; 18 | } 19 | if(s[i] == '3'){ 20 | clry += c; 21 | continue; 22 | } 23 | if(s[i] == '4'){ 24 | clry += d; 25 | continue; 26 | } 27 | } 28 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | map mp; 17 | while(n--){ 18 | string s; 19 | cin>>s; 20 | mp[s]++; 21 | } 22 | int max = -1; 23 | string maxchar; 24 | map::iterator i; 25 | for(i = mp.begin(); i != mp.end(); i++){ 26 | if(max < i->second){ 27 | max = i->second; 28 | maxchar = i->first; 29 | } 30 | } 31 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | const int MAX = 1000; 8 | char d, c[MAX]; 9 | int i = 0; 10 | while(d != '}'){ 11 | cin>>d; 12 | if(d >= 97 && d <= 122){ 13 | c[i] = d; 14 | i++; 15 | } 16 | } 17 | c[i] = '\0'; 18 | sort(c, c+i); 19 | char h = 'A'; 20 | int count = 0; 21 | for(int j = 0; j < i; j++){ 22 | if(c[j] != h){ 23 | count++; 24 | h = c[j]; 25 | } 26 | } 27 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>m>>n; 16 | int a = min(m, n); 17 | if(a %2 == 0){ 18 | cout<<"Malvika"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>m; 16 | int count = 0; 17 | while(n != 0){ 18 | count++; 19 | n--; 20 | if(count % m == 0){ 21 | n++; 22 | } 23 | } 24 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, p, q, count = 0; 6 | cin>>n; 7 | for(int i = 0; i < n; i++){ 8 | cin>>p; 9 | cin>>q; 10 | if(q - p >= 2){ 11 | count++; 12 | } 13 | } 14 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>o; 17 | string s; 18 | cin>>s; 19 | if(o == 'R'){ 20 | for(int i = 0; i < s.length(); i++){ 21 | s[i] = k[k.find(s[i]) - 1]; 22 | } 23 | } 24 | else{ 25 | for(int i = 0; i < s.length(); i++){ 26 | s[i] = k[k.find(s[i]) + 1]; 27 | } 28 | } 29 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>a>>b>>c; 16 | ll max = -1; 17 | ll arr[] = {(a*b*c), (a + b + c), (a + b * c), (a * b + c), ((a +b)*c), (a*(b + c))}; 18 | for(auto i : arr){ 19 | max = (i > max) ? i : max; 20 | } 21 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | long long n; 6 | cin>>n; 7 | long long evn = n/2; 8 | long long oddn = n%2 == 0 ? n/2 : (n/2 + 1); 9 | long long sumevn = evn * (evn + 1); 10 | long long sumoddn = oddn * oddn; 11 | long long sum = sumevn - sumoddn; 12 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | 17 | int count = 0; 18 | int pre = 0; 19 | int i = 1; 20 | while(n >= pre + i){ 21 | count++; 22 | n -= pre + i; 23 | pre = pre + i; 24 | i++; 25 | } 26 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int w; 6 | cin>>w; 7 | if(w%2 == 0 && w>2){ 8 | cout<<"YES"; 9 | } 10 | else{ 11 | cout<<"NO"; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /509A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | 17 | int a[n][n]; 18 | 19 | for(int i = 0; i < n; i++){ 20 | for(int j = 0; j < n; j++){ 21 | if(i == 0 || j == 0){ 22 | a[i][j] = 1; 23 | } 24 | else{ 25 | a[i][j] = a[i-1][j] + a[i][j-1]; 26 | } 27 | } 28 | } 29 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int m, n; 6 | cin>>m; 7 | cin>>n; 8 | int sqrAr = 2; 9 | cout<<((m*n)/sqrAr); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /540A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | string s, t; 17 | cin>>s>>t; 18 | int count = 0; 19 | for(int i = 0; i < n; i++){ 20 | int a = s[i] - '0'; 21 | int b = t[i] - '0'; 22 | int g = min(a, b); 23 | int h = max(a, b); 24 | int c = min(h - g, (g + 10 - h)); 25 | count += c; 26 | } 27 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int n; 9 | cin>>n; 10 | 11 | int arr[n][n]; 12 | 13 | map mp; 14 | 15 | for(int i = 0; i< n; i++){ 16 | for(int j = 0; j< n; j++){ 17 | cin>>arr[i][j]; 18 | } 19 | } 20 | 21 | for(int i = 0; i < n; i++){ 22 | for(int j = i+1; j < n; j++){ 23 | if(arr[i][j] == 1){ 24 | mp[i] = true; 25 | continue; 26 | } 27 | if(arr[i][j] == 2){ 28 | mp[j] = true; 29 | continue; 30 | } 31 | if(arr[i][j] == 3){ 32 | mp[i] = mp[j] = true; 33 | } 34 | 35 | } 36 | } 37 | 38 | int arrb[n], k = 0; 39 | for(int i = 0; i < n; i++){ 40 | if(!mp[i]){ 41 | arrb[k] = i + 1; 42 | k++; 43 | } 44 | } 45 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int k, n, w; 6 | cin>>k; 7 | cin>>n; 8 | cin>>w; 9 | 10 | int sum = 0; 11 | for(int i = 1; i <= w; i++){ 12 | sum += i*k; 13 | } 14 | int b = (sum - n) > 0 ? (sum - n) : 0; 15 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | string s; 17 | cin>>s; 18 | int count1 = 0, count0 = 0; 19 | for(auto i : s){ 20 | (i == '1') ? count1++ : count0++; 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | int res = __builtin_popcount(n); 17 | cout< 2 | #include 3 | using namespace std; 4 | 5 | 6 | #define ll long long 7 | #define endl '\n' 8 | #define debug(n) cout<<(n)<>n; 17 | 18 | int arr[n+1]; 19 | for(int i = 0; i < n; i++){ 20 | cin>>arr[i]; 21 | } 22 | arr[n] = std::numeric_limits::max(); 23 | int max= 0, count = 0; 24 | for(int i = 0; i < n; i++){ 25 | count++; 26 | max = count > max ? count : max; 27 | if(arr[i] > arr[i+1]){ 28 | count = 0; 29 | } 30 | } 31 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define pb push_back 7 | #define endl "\n" 8 | #define debug(n) cout<<(n)<& a, pair& b){ 12 | return a.first < b.first; 13 | } 14 | 15 | int binary_search(vector>& arr, int low, int high, ll target){ 16 | while(low <= high){ 17 | int mid = (low + high)/2; 18 | if(arr[mid].first < target){ 19 | if(mid == high){ 20 | return high + 1; 21 | } 22 | low = mid + 1; 23 | } 24 | else{ 25 | if(mid == low){ 26 | return mid; 27 | } 28 | if(arr[mid-1].first < target){ 29 | return mid; 30 | } 31 | high = mid -1; 32 | } 33 | } 34 | } 35 | 36 | int main(){ 37 | ios_base::sync_with_stdio(false); 38 | cin.tie(NULL); 39 | 40 | ll n, d; 41 | cin>>n>>d; 42 | 43 | vector> friends; 44 | ll a, b, s = 0; 45 | vector suff; 46 | 47 | for(int i = 0; i < n; i++){ 48 | cin>>a>>b; 49 | friends.push_back(make_pair(a, b)); 50 | s += b; 51 | } 52 | sort(friends.begin(), friends.end(), comp); 53 | for(int i = 0; i < n; i++){ 54 | suff.pb(s); 55 | // cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>t; 16 | if(n == 1 && t == 10){ 17 | cout<<-1< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>s; 16 | 17 | for(auto i : s){ 18 | if(i == 'h' && r == ""){ 19 | r += i; 20 | } 21 | else if(i == 'e' && r[r.length() - 1] == 'h'){ 22 | r += i; 23 | } 24 | else if(i == 'l' && r[r.length() - 1] == 'e'){ 25 | r += i; 26 | } 27 | else if(i == 'l' && r[r.length() - 2] == 'e' && r[r.length() - 1] == 'l'){ 28 | r += i; 29 | } 30 | else if(i == 'o' && r[r.length() - 1] == 'l' && r[r.length() - 2] == 'l' && r[r.length() - 3] == 'e'){ 31 | r += i; 32 | } 33 | } 34 | (r == "hello") ? cout<<"YES"< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | string s; 8 | cin>>s; 9 | int low = 0, up = 0; 10 | for(int i = 0; i < s.size(); i++){ 11 | if(s[i] >= 97){ 12 | low++; 13 | } 14 | else{ 15 | up++; 16 | } 17 | } 18 | if(low >= up){ 19 | transform(s.begin() , s.end(), s.begin(), ::tolower); 20 | } 21 | else{ 22 | transform(s.begin(), s.end(), s.begin(), ::toupper); 23 | } 24 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>b>>s; 18 | if(s[0] == 'm'){ 19 | if(n == 31){ 20 | cout<<7< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | 8 | int steps = n % 5 == 0 ? n / 5 :(n / 5) + 1; 9 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | const int MAX = 100; 6 | char *a = new char[MAX];char *b = new char[MAX];char *r = new char[MAX]; 7 | cin>>a; 8 | cin>>b; 9 | int i = 0; 10 | while(a[i] != '\0'){ 11 | r[i] = ((a[i] - '0') ^ (b[i] - '0')) + '0'; 12 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | cout<<25; 17 | } 18 | -------------------------------------------------------------------------------- /651C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>n; 21 | unordered_map mpx; 22 | unordered_map mpy; 23 | map, ll> mpxy; 24 | int x, y; 25 | for(int i = 0; i < n; i++){ 26 | cin>>x>>y; 27 | mpx[x]++; 28 | mpy[y]++; 29 | mpxy[make_pair(x, y)]++; 30 | } 31 | long long ans = 0; 32 | 33 | for(auto i : mpx){ 34 | ans += npairs(i.second); 35 | } 36 | for(auto i : mpy){ 37 | ans += npairs(i.second); 38 | } 39 | for(auto i : mpxy){ 40 | ans -= npairs(i.second); 41 | } 42 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int n; 9 | cin>>n; 10 | 11 | (n%3 == 0) ? cout<<(n/3 * 2)<= 1: 11 | count += 1 12 | extra = (frontier[i] - 1)/2 13 | nxt[i] += extra 14 | nxt[i+1] += extra 15 | frontier = nxt 16 | r += 1 17 | for i in frontier: 18 | if i >= 1: 19 | count += 1 20 | 21 | 22 | return count 23 | 24 | 25 | print(solve(1, t, n)) 26 | -------------------------------------------------------------------------------- /677A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, h, m, width = 0; 6 | cin>>n; 7 | cin>>h; 8 | for(int i = 0; i < n; i++){ 9 | cin>>m; 10 | if(m > h){ 11 | width += 2; 12 | } 13 | else{ 14 | width++; 15 | } 16 | } 17 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | int arr[n][3]; 17 | for(int i = 0; i < n; i++){ 18 | cin>>arr[i][0]>>arr[i][1]>>arr[i][2]; 19 | } 20 | 21 | int sum = 0; 22 | for(int i = 0; i < 3; i++){ 23 | sum = 0; 24 | for(int j = 0; j < n; j++){ 25 | sum += arr[j][i]; 26 | } 27 | if(sum){ 28 | cout<<"NO"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | 8 | #define debug(n) cout<<(n)<>n; 17 | int prev, current; 18 | cin>>prev; 19 | int maxlen = 1, count = 1; 20 | for(int i = 0; i < n-1; i++){ 21 | cin>>current; 22 | if(current <= prev){ 23 | count = 1; 24 | prev = current; 25 | continue; 26 | } 27 | count++; 28 | if(maxlen < count){ 29 | maxlen = count; 30 | } 31 | prev = current; 32 | } 33 | 34 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, a, b, asum = 0, bsum = 0; 6 | cin>>n; 7 | while(n--){ 8 | cin >> a >> b; 9 | if(a > b){ 10 | asum++; 11 | continue; 12 | } 13 | if(b > a){ 14 | bsum++; 15 | continue; 16 | } 17 | } 18 | if(asum > bsum){ 19 | cout<<"Mishka"< asum){ 23 | cout<<"Chris"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 17 | int arr[n]; 18 | for(int i = 0; i < n; i++){ 19 | cin>>arr[i]; 20 | } 21 | int m; 22 | cin>>m; 23 | sort(arr, arr+n); 24 | while(m--){ 25 | int t; 26 | cin>>t; 27 | int a; 28 | a = upper_bound(arr, arr+n, t) - arr; 29 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, m; 6 | cin>>n>>m; 7 | char x; 8 | for(int i = 0; i < (n*m); i++){ 9 | cin>>x; 10 | if(x != 'B' && x != 'W' && x != 'G'){ 11 | cout<<"#Color"< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin>>t; 8 | string s[t]; 9 | 10 | for(int i = 0; i < t; i++){ 11 | 12 | cin>>s[i]; 13 | 14 | } 15 | 16 | for(int i = 0; i < t; i++){ 17 | if(s[i].size() > 10){ 18 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>s; 16 | int count = 0; 17 | char prev = 'a'; 18 | for(auto i : s){ 19 | int a = abs(i - prev); 20 | int b = 26 - a; 21 | 22 | count += min(a, b); 23 | prev = i; 24 | } 25 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int n, a = 0, d = 0; 7 | cin>>n; 8 | string s; 9 | cin>>s; 10 | for(int i = 0; i < n; i++){ 11 | if(s[i] == 'A'){ 12 | a++; 13 | } 14 | else{ 15 | d++; 16 | } 17 | } 18 | if(a > d){ 19 | cout<<"Anton"; 20 | } 21 | else if(a < d){ 22 | cout<<"Danik"; 23 | } 24 | else{ 25 | cout<<"Friendship"; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /749A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | if(n%2 == 0){ 8 | cout<<(n/2)< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int n; 7 | cin>>n; 8 | string s; 9 | int count = 0; 10 | for(int i = 0; i < n; i++){ 11 | cin>>s; 12 | if(s == "Tetrahedron"){ 13 | count += 4; 14 | continue; 15 | } 16 | else if(s == "Cube"){ 17 | count += 6; 18 | continue; 19 | } 20 | else if(s == "Octahedron"){ 21 | count += 8; 22 | continue; 23 | } 24 | else if(s == "Dodecahedron"){ 25 | count += 12; 26 | continue; 27 | } 28 | else{ 29 | count += 20; 30 | continue; 31 | } 32 | } 33 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a, b; 6 | cin>>a; 7 | cin>>b; 8 | int year = 0; 9 | 10 | while(b >= a){ 11 | a *= 3; 12 | b *= 2; 13 | year++; 14 | } 15 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n>>m; 31 | 32 | int real_m; 33 | for(int i = n+1; i <= m; i++){ 34 | if(prime_check(i)){ 35 | real_m = i; 36 | break; 37 | } 38 | } 39 | 40 | (real_m == m) ? cout<<"YES"< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)< st; 15 | 16 | string s; 17 | cin>>s; 18 | 19 | for(int i = s.size() - 1; i >= 0; i--){ 20 | if(!st.empty() && st.top() == s[i]){ 21 | st.pop(); 22 | } 23 | else{ 24 | st.push(s[i]); 25 | } 26 | } 27 | 28 | string ans = ""; 29 | while(!st.empty()){ 30 | ans.push_back(st.top()); 31 | st.pop(); 32 | } 33 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>n>>p>>q>>r; 16 | 17 | ll x, maxpx, maxpqx, maxpqrx, px, qx, rx; 18 | cin>>x; 19 | maxpx = p * x; 20 | maxpqx = maxpx + q * x; 21 | maxpqrx = maxpqx + r * x; 22 | for(int i = 1; i < n; i++){ 23 | cin>>x; 24 | px = p * x; 25 | qx = q * x; 26 | rx = r * x; 27 | maxpx = max(maxpx, px); 28 | maxpqx = max(maxpqx, maxpx + qx); 29 | maxpqrx = max(maxpqrx, maxpqx + rx); 30 | } 31 | 32 | cout<<(maxpqrx)< 2 | #include 3 | using namespace std; 4 | 5 | int fun(string s, int n){ 6 | int a = 0, b = 0; 7 | if(n==1){ 8 | cout<<-1<<" "; 9 | cout<<-1< 0; r--){ 13 | for(int l = 0; l < r; l++){ 14 | for(int i = l; i <= r; i++){ 15 | if(s[i] == 'a'){ 16 | a++; 17 | } 18 | else{ 19 | b++; 20 | } 21 | } 22 | if(a == b){ 23 | cout<<(l+1)<<" "; 24 | cout<<(r+1)<>t; 38 | string s; 39 | for(int j = 0; j < t; j++){ 40 | cin>>n; 41 | 42 | cin>>s; 43 | 44 | fun(s, n); 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /903C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl "\n" 7 | #define debug(n) cout<<(n)<>n; 16 | unordered_map mp; 17 | ll x; 18 | ll ans = -1; 19 | while(n--){ 20 | cin>>x; 21 | mp[x]++; 22 | ans = max(ans, mp[x]); 23 | } 24 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | int count = 0; 17 | for(int i = 1; i < n; i++){ 18 | (n % i == 0) ? count++ : count+=0; 19 | } 20 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int n; 9 | cin>>n; 10 | 11 | char a[n]; 12 | cin>>a; 13 | 14 | int seq = 0; 15 | 16 | for(int i = 0; i < n - 1; i++){ 17 | 18 | if(a[i] != a[i+1]){ 19 | seq++; 20 | i++; 21 | continue; 22 | } 23 | 24 | } 25 | cout<<(n - seq); 26 | } 27 | -------------------------------------------------------------------------------- /959A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>n; 16 | 17 | if(n & 1){ 18 | cout<<"Ehab"< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | string s; 8 | cin>>s; 9 | char elem = '2'; 10 | int maxi = 0, count = 0; 11 | for(auto i:s){ 12 | if(i != elem){ 13 | elem = i; 14 | count = 1; 15 | continue; 16 | } 17 | count++; 18 | maxi = count > maxi ? count : maxi; 19 | if(maxi == 7){ 20 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | int n; 8 | cin>>n; 9 | string s; 10 | cin>>s; 11 | if(s == "0"){ 12 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, k; 6 | cin>>n; 7 | cin>>k; 8 | 9 | for(int i = 0; i < k; i++){ 10 | if(n%10 == 0){ 11 | n /= 10; 12 | } 13 | else{ 14 | n--; 15 | } 16 | } 17 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int n; 9 | cin>>n; 10 | int arr[n], score = 0; 11 | for(int i = 0; i < n; i++){ 12 | cin>>arr[i]; 13 | score += arr[i]; 14 | } 15 | int req_score = ceil(4.5 * n) - score; 16 | sort(arr, arr+n); 17 | int i = 0; 18 | while(req_score > 0){ 19 | req_score -= 5 - arr[i]; 20 | i++; 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | 5 | #define ll long long 6 | #define endl '\n' 7 | #define debug(n) cout<<(n)<>a>>b; 16 | if(max(a, b) == 1){ 17 | cout<<"1/1"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n; 9 | cin>>n; 10 | if((n/2)%2 != 0){ 11 | cout<<"NO"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, k, i = 1; 6 | cin>>n>>k; 7 | int r = n; 8 | while(true){ 9 | n = r * i; 10 | if(n%10 == 0 || n%10 == k){ 11 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int n; 8 | for(int i = 0; i < t; i++){ 9 | cin>>n; 10 | if(n % 2 == 0){ 11 | cout<<((n-1)/2)< 2 | #include 3 | using namespace std; 4 | 5 | int fun(string s, int n){ 6 | int *all_win, *one_win; 7 | *all_win = new int; 8 | *one_win = new int; 9 | int l = 0, k = 0; 10 | for(int i = 0; i < n;i++){ 11 | if(s[i] == 1){ 12 | *(all_win + k) = i; 13 | k++; 14 | } 15 | else{ 16 | *(one_win + l) = i; 17 | l++; 18 | } 19 | } 20 | int arr[n][n]; 21 | for(int i = 0; i < k; i++){ 22 | for(int j = 0; j < n; j++){ 23 | arr[all_win[i]][j] = 1; 24 | arr[j][all_win[i]] = -1; 25 | } 26 | } 27 | } 28 | 29 | int main(){ 30 | int t, n; 31 | string s; 32 | cin>>t; 33 | for(int i = 0; i < t; i++){ 34 | cin>>n; 35 | cin>>s; 36 | fun(s, n); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /ChoosingTeams.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, k; 6 | cin>>n>>k; 7 | int x, count = 0, team; 8 | for(int i = 0; i < n; i++){ 9 | cin>>x; 10 | count += x <= (5-k) ? 1 : 0; 11 | } 12 | team = count/3; 13 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | 8 | if(n%2 == 0){ 9 | cout<<(n-4)<<" "<<4; 10 | } 11 | else{ 12 | cout<<(n-9)<<" "<<9; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Divisibility_Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t, a, b; 6 | cin>>t; 7 | for(int j = 0; j < t; j++){ 8 | cin>>a; 9 | cin>>b; 10 | if(a % b == 0){ 11 | cout<<0< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, m; 6 | cin>>n; 7 | cin>>m; 8 | for(int i = 0; i < n; i++){ 9 | if(i % 2 == 0){ 10 | for(int j = 0; j < m; j++){ 11 | cout<<"#"; 12 | } 13 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int arr[n][2], count = 0; 8 | for(int i = 0; i < n; i++){ 9 | cin>>arr[i][0]>>arr[i][1]; 10 | } 11 | for(int i = 0; i < n; i++){ 12 | for(int j = 0; j < n; j++){ 13 | if(arr[i][1] == arr[j][0]){ 14 | count++; 15 | } 16 | } 17 | } 18 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int count = 0; 8 | while(n != 0){ 9 | if(n >= 100){ 10 | count += (n / 100); 11 | n %= 100; 12 | continue; 13 | } 14 | else if(n >= 20){ 15 | count += (n / 20); 16 | n %= 20; 17 | continue; 18 | } 19 | else if(n >= 10){ 20 | count += (n / 10); 21 | n %= 10; 22 | continue; 23 | } 24 | else if(n >= 5){ 25 | count += (n / 5); 26 | n %= 5; 27 | continue; 28 | } 29 | else{ 30 | count += (n / 1); 31 | break; 32 | } 33 | } 34 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int arr[n]; 8 | int max = -1; 9 | for(int i = 0; i < n; i++){ 10 | cin>>arr[i]; 11 | if(arr[i] > max){ 12 | max = arr[i]; 13 | } 14 | } 15 | int count = 0; 16 | for(int i = 0; i < n; i++){ 17 | count += max - arr[i]; 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | for(int i = 1; i <= n; i++){ 8 | if(i % 2 != 0){ 9 | cout<<"I hate "; 10 | } 11 | else{ 12 | cout<<"I love "; 13 | } 14 | if(i == n){ 15 | cout<<"it"; 16 | continue; 17 | } 18 | cout<<"that "; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /I_Wanna_Be_The_Guy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int n, p, q; 8 | cin>>n; 9 | cin>>p; 10 | int x; 11 | set > s; 12 | for(int i = 0; i < p; i++){ 13 | cin>>x; 14 | s.insert(x); 15 | } 16 | cin>>q; 17 | for(int i = 0; i < q; i++){ 18 | cin>>x; 19 | s.insert(x); 20 | } 21 | 22 | int check = s.size() == n ? 1 : 0; 23 | if(check == 1){ 24 | cout<<"I become the guy."; 25 | } 26 | else{ 27 | cout<<"Oh, my keyboard!"; 28 | } 29 | return 0; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /I_love_saura.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, x, count = 0; 6 | cin>>n; 7 | int min, max, y; 8 | cin>>y; 9 | min = y; 10 | max = y; 11 | for(int i = 0; i < n-1; i++){ 12 | cin>>x; 13 | if(x < min){ 14 | min = x; 15 | count++; 16 | } 17 | if(x > max){ 18 | max = x; 19 | count++; 20 | } 21 | } 22 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int k, l, m, n, d; 6 | cin>>k>>l>>m>>n>>d; 7 | int i = 0, j = 1; 8 | while(j <= d){ 9 | if(j % k == 0 || j % l == 0 || j % m == 0 || j % n == 0){ 10 | i++; 11 | } 12 | j++; 13 | } 14 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int arr[4], rs = 0; 7 | for(int i = 0; i < 4; i++){ 8 | cin>>arr[i]; 9 | } 10 | sort(arr, arr+4); 11 | for(int i = 0; i < 3; i++){ 12 | if(arr[i] == arr[i+1]){ 13 | rs++; 14 | } 15 | } 16 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin>>t; 8 | string s1, s2; 9 | int n, j, count; 10 | for(int i = 0; i < t; i++){ 11 | cin>>n; 12 | cin>>s1; 13 | cin>>s2; 14 | j = 0; 15 | count = 0; 16 | while(j < n){ 17 | if((s1[j] == '0' && s2[j] == '1') || (s2[j] == '0' && s1[j] == '1')){ 18 | count += 2; 19 | j++; 20 | continue; 21 | } 22 | else if(s1[j] == '0' && s2[j] == '0'){ 23 | if(s1[j+1] == '1' && s2[j+1] == '1' && j != n-1){ 24 | count += 2; 25 | j += 2; 26 | continue; 27 | } 28 | else{ 29 | count += 1; 30 | j++; 31 | continue; 32 | } 33 | } 34 | else{ 35 | if(s1[j+1] == '0' && s2[j+1] == '0' && j != n-1){ 36 | count += 2; 37 | j += 2; 38 | continue; 39 | } 40 | else{ 41 | j++; 42 | continue; 43 | } 44 | } 45 | } 46 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | int a; 7 | int b; 8 | cin>>t; 9 | for(int i = 0; i < t; i++){ 10 | cin>>a; 11 | cin>>b; 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /MIN_MEX_Cut.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin>>t; 8 | string s; 9 | char elem; 10 | for(int i = 0; i < t; i++){ 11 | cin>>s; 12 | elem = '4'; 13 | int count = 0; 14 | for(int j = 0; j < s.size(); j++){ 15 | if(s[j] != elem){ 16 | elem = s[j]; 17 | if(elem == '0'){ 18 | count++; 19 | if(count == 2){ 20 | break; 21 | } 22 | continue; 23 | } 24 | } 25 | } 26 | cout< 2 | 3 | using namespace std; 4 | 5 | typedef long long ll; 6 | 7 | const ll P2LIM = (ll)2e18; 8 | 9 | int solve(string s, string t) 10 | { 11 | int tp = 0; 12 | int sp = 0; 13 | int taken = 0; 14 | 15 | while (sp < s.length() && tp < t.length()) 16 | { 17 | if(s[sp] == t[tp]) 18 | { 19 | taken++; 20 | tp++; 21 | } 22 | sp++; 23 | } 24 | 25 | return (int)s.length() - taken + (int)t.length() - taken; 26 | } 27 | 28 | vector ts; 29 | 30 | int main() 31 | { 32 | for (ll p2 = 1; p2 <= P2LIM; p2 *= 2) 33 | ts.push_back(to_string(p2)); 34 | 35 | int t; 36 | cin >> t; 37 | 38 | while (t--) 39 | { 40 | string n; 41 | cin >> n; 42 | 43 | int ans = n.length() + 1; 44 | for (auto p2 : ts) 45 | ans = min(ans, solve(n, p2)); 46 | cout << ans << '\n'; 47 | } 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Median_Maximization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | int x, s, n; 8 | for(int i = 0; i < t; i++){ 9 | cin>>n>>s; 10 | if(n%2 == 0){ 11 | x = s/((n/2) + 1); 12 | } 13 | else{ 14 | x = s/((n+1)/2); 15 | } 16 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n, k; 6 | cin>>n; 7 | cin>>k; 8 | int sum = 0; 9 | int i; 10 | for(i = 1; i <= n; i++){ 11 | if(sum + (5 * i) > (240 -k)){ 12 | break; 13 | } 14 | sum += (5 * i); 15 | } 16 | i--; 17 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | string su; 10 | cin>>su; 11 | transform(su.begin(), su.end(), su.begin(), ::tolower); 12 | int check = 0; 13 | char apl[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; 14 | for(int i = 0; i < 26; i++){ 15 | check = 0; 16 | for(int j = 0; j < su.size(); j++){ 17 | if(apl[i] == su[j]){ 18 | check = 1; 19 | break; 20 | } 21 | } 22 | if(check == 0){ 23 | cout<<"NO"; 24 | return 0; 25 | } 26 | } 27 | cout<<"YES"; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Police_Recruits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int x, pcnt = 0, ccnt = 0; 8 | while(n--){ 9 | cin>>x; 10 | if(x == -1 && pcnt == 0){ 11 | ccnt++; 12 | continue; 13 | } 14 | else if(x == -1 && pcnt > 0){ 15 | pcnt--; 16 | continue; 17 | } 18 | else{ 19 | pcnt += x; 20 | } 21 | } 22 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n; 10 | cin>>n; 11 | int arr[n]; 12 | for(int i = 0; i < n; i++){ 13 | cin>>arr[i]; 14 | } 15 | sort(arr, arr+n); 16 | int count = n; 17 | for(int i = 0; i < n-1; i++){ 18 | if(arr[i] == arr[i+1] || arr[i+1] - arr[i] == 1){ 19 | count--; 20 | } 21 | } 22 | if(count != 1){ 23 | cout<<"NO"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int x, y, n; 9 | cin>>x>>y>>n; 10 | int k = (n % x) - y >= 0 ? (n - (((n % x) - y))) : (n - (x + ((n % x) - y))); 11 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int arr[4]; 7 | for(int i = 0; i < 4; i++){ 8 | cin>>arr[i]; 9 | } 10 | sort(arr, arr+4); 11 | for(int i = 0; i < 3; i++){ 12 | cout<<(arr[3] - arr[i])<<" "; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /ShortSubstrings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin>>t; 8 | string s; 9 | while(t--){ 10 | cin>>s; 11 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | cin>>t; 8 | int n; 9 | while(t--){ 10 | cin>>n; 11 | int count = 0; 12 | int arr[n], i = 0; 13 | while(n){ 14 | arr[i] = n%10; 15 | n /= 10; 16 | count += arr[i] == 0 ? 0 : 1; 17 | i++; 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | int arr[n]; 8 | int count1 = 0, count2 = 0, count3 = 0, min, one[n], two[n], three[n]; 9 | for(int i = 0; i < n; i++){ 10 | cin>>arr[i]; 11 | if(arr[i] == 1){ 12 | one[count1] = i + 1; 13 | count1++; 14 | } 15 | else if(arr[i] == 2){ 16 | two[count2] = i + 1; 17 | count2++; 18 | } 19 | else{ 20 | three[count3] = i + 1; 21 | count3++; 22 | } 23 | min = 10000; 24 | if(min > count1){ 25 | min = count1; 26 | } 27 | if(min > count2){ 28 | min = count2; 29 | } 30 | if(min > count3){ 31 | min = count3; 32 | } 33 | } 34 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int arr[3]; 6 | cin>>arr[0]>>arr[1]>>arr[2]; 7 | sort(arr, arr+3); 8 | cout<<(arr[2] - arr[0]); 9 | } 10 | -------------------------------------------------------------------------------- /TwoArraysAndSwaps.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | int t, n, k; 6 | cin>>t; 7 | while(t--){ 8 | cin>>n>>k; 9 | int arr1[n], arr2[n]; 10 | int temp; 11 | for(int i = 0; i < n; i++){ 12 | cin>>arr1[i]; 13 | } 14 | for(int i = 0; i < n; i++){ 15 | cin>>arr2[i]; 16 | } 17 | sort(arr1, arr1+n); 18 | sort(arr2, arr2+n, greater()); 19 | for(int i = 0; i < k; i++){ 20 | if(arr1[i] < arr2[i]){ 21 | arr1[i] = arr2[i]; 22 | continue; 23 | } 24 | else{ 25 | break; 26 | } 27 | } 28 | int sum = 0; 29 | for(int i = 0; i < n; i++){ 30 | sum += arr1[i]; 31 | } 32 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int a, b; 6 | cin>>a; 7 | cin>>b; 8 | int hip, sip; 9 | hip = a <= b ? a : b; 10 | sip = ((a <= b ? b : a) - hip)/2; 11 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int a, b; 9 | cin>>a; 10 | cin>>b; 11 | int x = a >= b ? (a - b) : (b - a); 12 | int steps = x % 10 == 0 ? x/10 : (x/10 + 1); 13 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | int t; 7 | int n; 8 | string s; 9 | 10 | cin>>t; 11 | for(int i = 0; i < t; i++){ 12 | cin>>n; 13 | cin>>s; 14 | for(int j = 0; j < n; j++){ 15 | if(s[j] == 'D'){ 16 | 17 | s[j] = 'U'; 18 | continue; 19 | } 20 | else if(s[j] == 'U'){ 21 | 22 | s[j] = 'D'; 23 | continue; 24 | 25 | } 26 | else{ 27 | continue; 28 | } 29 | } 30 | cout<