akhauriyash/Code-Regression huggingface dataset:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    result = N * M / gcd(N, M)
    cand = (result / N) * (result / M) / gcd(int((result / N)), int((result / M)))
    for i in range(0, int(result / cand)):
        if S[int((i * cand) / (result / N))] != T[int((i * cand) / (result / M))]:
            return '-1'
    return int(result)
print(main())

Measured memory_bytes: 3316
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] balls = new int[N];
        for(int i=0;i<N;i++){
        	balls[i]=sc.nextInt();
        }
        Arrays.sort(balls);
        ArrayList<Integer> kind = new ArrayList<>();
        int count=1;
        for(int i=1;i<N;i++){
        	if(balls[i]==balls[i-1]){
        		count++;
        	}else{
        		kind.add(count);
        		count=1;
        	}
        }
        kind.add(count);
        
        Integer[] array = new Integer[kind.size()];
        array = kind.toArray(array);
        Arrays.sort(array);
        
        
        
        if(array.length<=K) System.out.println(0);
        else{
        	int ans = 0;
        	for(int i=0;i<array.length-K;i++)ans+=array[i];
        	System.out.println(ans);
        }
    }
}

Measured memory_bytes: 65532
#include <bits/stdc++.h>
using namespace std ;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int main()
{
    ll flag = 0 ;
    string s, s1, s2 ;
    cin >> s ;
    for (int i = 0, j = s.size() - 1; i < j; i++, j--) {
        if (s[i] != s[j]) {
            flag = 1 ;
            break ;
        }
    }
    if (flag)   cout << "No" ;
    else {
        s1 = s.substr(0, (s.size() - 1) / 2) ;
        s2 = s.substr( ((s.size() + 3) / 2) - 1) ;

        for (int i = 0, j = s1.size() - 1; i < j; i++, j--) {
            if (s1[i] != s1[j]) {
                flag = 1 ;
                break ;
            }
        }
        if (flag)   cout << "No" ;
        else {
            for (int i = 0, j = s2.size() - 1; i < j; i++, j--) {
                if (s2[i] != s2[j]) {
                    flag = 1 ;
                    break ;
                }
            }
            if (flag)   cout << "No" ;
            else    cout << "Yes" ;
        }
    }


}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,r,x,sum=0;
	cin >> n;
	int* p = new int[n];

	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
		sum = sum + p[i];
	}
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> r >> x;
	cout<<	sum - p[r - 1] + x<<endl;


	}

    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  ll a, b, c;
  cin >> a >> b >> c;
  ll d = c - a - b;
  if (d < 0) {
    cout << "No" << endl;
  } else if (4LL * a * b < d * d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

ll h, w, n;
map<pair<int, int>, int> mp;
int a[100000 + 5], b[100000 + 5];
ll ans[10];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w >> n;
    rep(i, n) {
        cin >> a[i] >> b[i];
        mp[{a[i], b[i]}] = 1;
    }
    rep(o, n) {
        int y = a[o], x = b[o];
        rep2(i, y - 2, y - 2 + 3)rep2(j, x - 2, x - 2 + 3) {
            int cnt = 0;
            bool check = false;
            rep2(k, i, i + 3)rep2(l, j, j + 3) {
                if (k <= 0 || h < k || l <= 0 || w < l) {
                    check = true;
                    break;
                }
                if (mp[{k, l}]) cnt++;
            }
            if (!check) ans[cnt]++;
        }
    }
    ll sum = 0;
    rep2(i, 1, 10) {
        ans[i] /= i;
        sum += ans[i];
    }
    ans[0] = (h - 2) * (w - 2) - sum;
    rep(i, 10) cout << ans[i] << endl;
}


Measured memory_bytes: 157312
#include <iostream>
 #include <cstdio>
 using namespace std;

int gcd(int a, int b) {
    int r;
    do{
        r=a%b;
        a=b;
        b=r;
    }while(r != 0);
    
    return a;
 }

   int main(void){
    int a,b;
    while(cin >> a >> b) {
       int lcm = a/gcd(a,b)*b;
      cout << gcd(a,b) << " " << lcm << endl;
    }
    return 0;
 }


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100];
    int c=0;
    scanf("%s",s);
    if(s[0]==s[1]) c++;
    if(s[1]==s[2]) c++;
    if(s[2]==s[3]) c++;
    if(c!=0)
    {
        printf("Bad");
    }
    else
        printf("Good");
    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll dp[100005];

void Main() {
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i, N) cin >> H[i];
    rep(i, N + 10) dp[i] = INF;
    dp[0] = 0;
    rep(i, N) {
        if (i < N) dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]));
        if (i < N - 1) dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]));
    }
    cout << dp[N - 1] << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1408
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
struct _RLE{ char c; ll len; };
vector<_RLE> RLE(string S){
    ll N=S.size();
    vector<_RLE> v;
    char prev=S[0];
    if(S[0]=='>')v.push_back({'<',0});
    for(ll i=1,cnt=1;i<=N;i++){
        if(i==N){//最後
            v.push_back({prev,cnt});
            break;
        }
        while(S[i]==prev){cnt++;i++;}//数え上げ
        v.push_back({prev,cnt});
        cnt=1;prev=S[i];//初期化
    }
    if(S[S.size()-1]=='<')v.push_back({'>',0});
    return v;
}
typedef pair<ll,ll> P;
int main(void){
    string S;cin>>S;
    vector<_RLE> v=RLE(S);
    ll N=v.size();
    vector<P> v2;
    REP(i,N){
        ll c1=v[i].len,c2=v[++i].len;
        v2.push_back(make_pair(c1,c2));
    }
    ll ans=0;
    REP(i,v2.size()){
        ll l1=v2[i].first,l2=v2[i].second;
        ll m=min(l1,l2);
        ans+=l1*(1+l1)*1/2;ans+=l2*(1+l2)*1/2;ans-=m;
        //cout<<v2[i].first<<v2[i].second<<"\n";
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 8584
#include <bits/stdc++.h>
#define INF 1000000001
using namespace std;
typedef long long ll;

int main()
{
  ll N;
  cin >> N;
  vector<pair<ll, ll>> M(N);
  for (ll i = 0; i < N; ++i)
  {
    cin >> M.at(i).first >> M.at(i).second;
  }
  vector<vector<ll>> dp(N, vector<ll>(N, INF));
  for (ll i = 0; i < N; ++i)
  {
    dp.at(i).at(i) = 0;
  }
  for (ll i = 0; i < N - 1; ++i)
  {
    dp.at(i).at(i + 1) = M.at(i).first * M.at(i).second * M.at(i + 1).second;
  }

  for (ll width = 1; width < N; ++width)
  {
    for (ll l = 0; l < N - width; ++l)
    {
      ll r = l + width;
      for (ll m = l + 1; m < r + 1; ++m)
      {
        dp.at(l).at(r) = min(dp.at(l).at(r), dp.at(l).at(m - 1) + dp.at(m).at(r) + M.at(l).first * M.at(m - 1).second * M.at(r).second);
      }
    }
  }
  cout << dp.at(0).at(N - 1) << endl;
  // for (ll i = 0; i < N; ++i)
  // {
  //   for (ll j = 0; j < N; ++j)
  //   {
  //     cout << dp.at(i).at(j) << ' ';
  //   }
  //   cout << endl;
  // }
}



Measured memory_bytes: 3208
#include <iostream>
#include <vector>

using namespace std;

bool check_line(vector<int>& td, vector<int>& data) {
  for (size_t i = 0; i < td.size(); ++i) {
    if (td[i] != data[i]) {
      break;
    }
    else if (i == td.size()-1 && td[i] == data[i]) {
      return true;
    }
  }
  for (size_t i = 0; i < td.size(); ++i) {
    if (i%2 == 0) {
      if (td[i] != data[td.size()-i-1]) {
        break;
      }
      if (i == td.size()-1 && td[i] == data[td.size()-i-1]) {
        return true;
      }
    }
    else {
      if (td[i] != -data[td.size()-i-1]) {
        break;
      }
    }
  }
  return false;
}

int main(void) {
  int n;
  while (cin >> n,n) {
    vector< vector<int> > lsx(n+1),lsy(n+1);
    vector<bool> eq(n+1,true);
    int m,x,y,len;
    for (int i = 0; i < n+1; ++i) {
      cin >> m;
      if (i == 0) {
        len = m;
      }
      else if (len != m) {
        eq[i] = false;
      }
      for (int j = 0; j < m; ++j) {
        cin >> x >> y;
        lsx[i].push_back(x);
        lsy[i].push_back(y);
      }
    }
    
    vector< vector<int> > data(n+1);
    int dirx = 1;
    int diry = 1;
    for (int l = 0; l < n+1; ++l) {
			dirx = 1;
			diry = 1;
      for (int i = 0; i < len-1; ++i) {
        if (lsx[l][i] == lsx[l][i+1]) {
          if (lsy[l][i] > lsy[l][i+1]) {
            if (i > 0) {
              data[l].push_back(dirx);
            }
						diry = -1;
            data[l].push_back(lsy[l][i]-lsy[l][i+1]);
          }
          else {
            if (i > 0) {
              data[l].push_back(-dirx);
            }
						diry = 1;
            data[l].push_back(lsy[l][i+1]-lsy[l][i]);
          }
        }
        else {
          if (lsx[l][i] > lsx[l][i+1]) {
            if (i > 0) {
              data[l].push_back(-diry);
						}
						dirx = -1;
            data[l].push_back(lsx[l][i]-lsx[l][i+1]);
          }
          else {
            if (i > 0) {
              data[l].push_back(diry);
            }
						dirx = 1;
            data[l].push_back(lsx[l][i+1]-lsx[l][i]);
          }
        }
      }
    }
    
    for (int i = 1; i < n + 1; ++i) {
      if (eq[i]) {
        if (check_line(data[0],data[i])) {
          cout << i << endl;
        }
      }
    }
    cout << "+++++" << endl;
  }
  return 0;
}

Measured memory_bytes: 3036
import numpy as np

n, k, q = [int(v) for v in input().split()]
winners = [int(input()) - 1 for _ in range(q)]
points = np.array([k for _ in range(n)]) - q

for winner in winners:
    points[winner] += 1

for res in np.where(points <= 0, 'No', 'Yes'):
    print(res)
    

Measured memory_bytes: 20692
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <functional>
using namespace std;

int main()
{
	int a=0,b=0;
	cin >> a >> b;

	if((a+b)%3 == 0 || a%3 == 0 || b%3 == 0){
		puts("Possible");
	}else{
		puts("Impossible");
	}

	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    n = int(input().strip())
    edges = [[int(i) for i in input().strip().split()] for _ in range(n - 1)]
    g = defaultdict(list)
    for a, b in edges:
        g[a].append(b)

    # 1をルートとする
    que = deque([1])
    # 各頂点と親を結ぶ色を保存する
    # 1はルートのため 0 とする
    colors = [0] * (n + 1)

    # BFSで各ノードごとの子の色を決定する
    while que:
        parent = que.popleft()
        color = 0
        for child in g[parent]:
            color += 1
            if color == colors[parent]:
                color += 1
            colors[child] = color
            que.append(child)

    print(max(colors))

    for a, b in edges:
        print(colors[b])
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 100532
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int a, d,b;
    cin >> a >> d >> b;
    vector<int>mo;
    mo.push_back(b);
    rep(i, 10)mo.push_back((a * mo[i]) - d);
    mo.erase(mo.begin());
    for (auto s: mo)cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll h,w;
    cin>>h>>w;
    if( h== 1|| w==1)
        cout<<1;
    else {
        ll ans = (h * w + 1) / 2;
        cout<<ans;
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

ll INF=100000000000000;

int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(M,0);
    vector<ll> B(M,0);
    vector<ll> C(M,0);
    for(ll i=0;i<M;i++){
        cin>>A[i]>>B[i]>>C[i]
    ;}
    vector<ll> d(N+1,-INF);
    d[1]=0;
    ll counter=1;
    ll ans=-INF;
    ll an;
    while(true){
        for(ll i=0;i<M;i++){
            if(d[B[i]]<d[A[i]]+C[i]){
            d[B[i]]=d[A[i]]+C[i];}
        ;}
        if(counter==N){an=d[N];}
        else if(counter==2*N){
            if(d[N]!=an){
            cout<<"inf"<<endl;return 0;}
            else break;
        }
        counter++;
    }
    cout<<d[N]<<endl;
return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var input = sc.nextInt()
    var hour = input / 3600
    input %= 3600
    var minute = input / 60
    input %= 60
    val second = input

    println("$hour:$minute:$second")
}



Measured memory_bytes: 25636
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if(a >= b)
  {
    ans += a;
    --a;
  }
  else
  {
    ans += b;
    --b;
  }
  cout << ans + max(a, b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	for (int i = n; i < 1000; i++) {
		if (i % 111 == 0) {
			cout << i << endl;
			return 0;
		}
	}

}

Measured memory_bytes: 256
using System; 
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[][] TA = new int[N][].Select(_ => Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray()).ToArray();

        long T = TA[0][0];
        long A = TA[0][1];
        int t;
        int a;
        foreach (int[] ta in TA)
        {
            t = ta[0];
            a = ta[1];

            long n = Convert.ToInt64(Math.Max(A / a + (A % a != 0 ? 1 : 0), T / t + (T % t != 0 ? 1 : 0)));
            T = t * n;
            A = a * n;
        }
        Console.WriteLine(T + A);
    }
}

Measured memory_bytes: 11476
#include <bits/stdc++.h>
    using namespace std;
    	
    int main() {
      	int c; cin >> c;
    	string b; cin >> b;
      	if(b.size()>c){
        	cout << b.substr(0,c) << "...";
        } else {
        	cout << b;
        }
    	
    }

Measured memory_bytes: 3628
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

const int mod = 1e9 + 7;

ll f(vector<ll> &X) {
  int N = X.size();
  ll sum = 0;
  for (int k = 1; k <= N; k++) {
    sum += (k - 1) * X[k - 1] - (N - k) * X[k - 1];
    sum %= mod;
  }
  return sum;
}

int main() {
  // 考察1. xとyを独立にする！
  // \sum_i,j \sum_k,l (x_j - x_i) * (y_l - y_k)
  // = \sum_i,j (x_j - x_i) * \sum_k,l (y_l - y_k)
  // 考察2. \sum式は、足す順番を工夫してみる
  // x_k　は k - 1 回足され、 n - k 回引かれる
  // \sum_k ((k - 1)x_k - (n - k)x_k)

  int N, M;
  cin >> N >> M;
  vector<ll> X(N), Y(M);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> Y[i];
  }
  cout << (f(X) * f(Y)) % mod << endl;

  return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, M;
    cin >> N >> M;

    if (N == 1) {
        cout << M << endl;
        return 0;
    }

    ll ans = 1;
    for (ll i = 2; i * i <= M; i++) {
        if (M % i == 0) {
            if (i >= N) {
                ans = max(ans, M / i);
            } else if (M / i >= N) {
                ans = max(ans, i);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [ list(map(int, input().split())) for _ in range(m)]


# 最小値から順にCjより小さければ書き換えればよい　
# 毎回ソートしていたら間に合わなさそう
# Cを大きい順にソートして、カードの最小値をpop, キューの最後にCを加える
from collections import deque
import numpy as np
npbc = np.array(bc)
npbc = npbc[np.argsort(npbc[:, 1])[::-1]]
bc = npbc.tolist()
# print(bc)

que = deque(sorted(a))
for b, c in bc:
    for i in range(b):
        val = que.popleft()
        if val < c:
            que.append(c)
        else:
            que.appendleft(val)
            if i == 0:
                # print(que)
                print(sum(que))
                exit()
            else:
                break

# print(que)
print(sum(que))

Measured memory_bytes: 66324
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,d;
  cin>>n;
  string s,a;
  cin>>s;
  cin>>d;
  a=s;
  int t=0;
  if(d==0){
    cout<<s<<endl;
    return 0;
  }
  rep(i,n)
    if(s[i]=='0'){
      s[i]='1';
      t++;
      if(t==d){
	cout<<s<<endl;
	return 0;
      }
    }
  for(i=n-1;i>=0;i--)
    if(a[i]=='1'){
      s[i]='0';
      t++;
      if(t==d){
	cout<<s<<endl;
	return 0;
      }
    }
}

Measured memory_bytes: 3232
// Problem : N - Slimes
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_n?lang=en
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define Ma7moud_7amdy                                                                                                  \
    ios_base::sync_with_stdio(false);                                                                                  \
    cin.tie(NULL);                                                                                                     \
    cout.tie(NULL)
#define Open_Sesame Open()
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define watch(x) cout << #x << " = " << x << endl;
#define RT(x) return cout << (x), 0;
#define Accepted 0
typedef long long ll;
typedef vector<int> vi;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
const int mod = ll(1e9 + 7), N = 2000 + 5;
//“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
int n;
ll a[401], mem[403][403];
ll solve(int l = 1, int r = n)
{
    if (l == r)
        return 0;
    if (l + 1 == r)
        return a[r] - a[l - 1];

    ll &ret = mem[l][r];
    if (~ret)
        return ret;
    ret = 1e15;
    for (int i = l; i < r; i++)
    {
        ret = min(ret, solve(l, i) + solve(i + 1, r) + a[r] - a[l - 1]);
    }
    return ret;
}
int main()
{
    Ma7moud_7amdy;
    // Open_Sesame;
    clr(mem, -1);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i], a[i] += a[i - 1];
    cout << solve() << endl;
}


Measured memory_bytes: 4868
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,m) = get!(usize, usize);
    if n==m {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 8572
#include <iostream>
#include <iomanip>
using namespace std;

int GCD(int a, int b)
{
	if (b > 0) {
		return GCD(b, a%b);
	}else {
		return a;
	}
}

int LCM(int a, int b)
{
	return a / GCD(a, b) * b;
}

int main(int argc, char **argv)
{
	int a, b;
	while (cin >> a >> b)
		cout << GCD(a, b) << " " << LCM(a, b) << endl;
	
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;

long long dp[200][200];

long long N;
string S;

int main(){
	cin >> N >> S;

	long long mini = 0;
	long long left = 0;
	long long right = 0;
	long long addleft = 0;
	for(long long i = 0; i < S.length(); i++){
		if(S[i] == '('){
			left++;
		} else {
			right++;
			if(right > left){
				addleft++;
				left++;
			}
		}
	}

	for(int i = 0; i < addleft; i++){
		cout << "(";
	}

	if(right > left){
		for(int i = 0; i < right - left; i++){
			cout << "(";
		}
		cout << S << endl;
		return 0;
	} else {
		cout << S;
		for(int i = 0; i < left - right; i++){
			cout << ")";
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
int a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	if((abs(a-b)<=d&&abs(b-c)<=d)||(abs(a-c)<=d))
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, char> Pc;
typedef pair<int, string> Ps;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
const int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const string dir8[8] = {"U", "RU", "R", "RD", "D", "LD", "L", "LU"};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
struct Node { int data; Node *left, *right; Node(int data) : data(data), left(NULL), right(NULL) {} };
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  REP(i, M) cin >> A[i];

  ll sum = 0;
  REP(i, M) sum += A[i];
  if (sum > N) {
    cout << -1 << endl;
    return 0;
  }
  cout << N - sum << endl;
  return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int H,W;
    cin>>H>>W;
    int c[10][10];
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>c[i][j];
        }
    }
    int a[10]={};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int z;
            cin>>z;
            if(z!=-1) a[z]++;
        }
    }
    for(int k=0;k<10;k++){
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<10;i++){
        ans+=(c[i][1])*a[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def examB():
    St = S()
    ans = St[::2]
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 3700
//JSD
#include<iostream>
using namespace std;
int ans(int Num){
	int count=0;
	while(Num>0){
		Num/=10;
		count++;
	}
	return count%2;
}
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n-1;i++){
		if(i==0) a[i]--;
		else{
			if(a[i]-1>=a[i-1]){
				a[i]--;
			}
		}
	}
	bool res=1;
	for(int i=1;i<n;i++){
		if(a[i]<a[i-1])  res=0;
	}
	if(res) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
 
const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);
 
using namespace std;
 
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll ans = 0;
	int N,K;
    ll R,S,P;
    string T;
    char D[100005];
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    rep(i,K){
        if(T[i]=='r'){
            ans += P;
            D[i] = 'P';
        }else if(T[i]=='s'){
            ans += R;
            D[i] = 'R';
        }else{
            ans += S;
            D[i] = 'S';
        }
    }
    for(int i=K;i<N;i++){
        if(T[i]== 'r' && D[i-K]!='P'){
            ans += P;
            D[i] = 'P';
        }else if(T[i]=='s' && D[i-K]!='R'){
            ans += R;
            D[i] = 'R';
        }else if(T[i]=='p' && D[i-K]!='S'){
            ans += S;
            D[i] = 'S';
        }else D[i]='x';
    }
    cout << ans << endl;
}

Measured memory_bytes: 592
def solve(n, k):
    occurence = set()

    diff = n % k
    n = diff
    
    if diff == 0 or diff == 1:
        print(diff)
        return
    else:
        while n not in occurence:
            if k == 1:
                print(0)
                return

            occurence.add(n)

            n = abs(n - k)

            if n == 0:
                print(n)
                return

    min_value = min(occurence)
    print(min_value)


if __name__ == '__main__':
    nk = input().split()

    n = int(nk[0])
    k = int(nk[1])

    solve(n, k)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007

int main(){
    int N; cin >> N;
    vector<vector<int>> T(N, vector<int>(3));
    vector<int> smp(3);
    
    for(vector<int> &t:T){
        cin >> t[0] >> t[1] >> t[2];
        if(t[2]!=0)
            for(int i=0; i<3; i++)
                smp[i] = t[i];
    }

    vector<vector<int>> o;
    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            int H = smp[2] + abs(smp[0]-i) + abs(smp[1]-j);
            bool f = true;
            for(int k=0; k<N; k++){
                int h = max(H - abs(i-T[k][0]) - abs(j-T[k][1]), 0);
                if(h!=T[k][2]) f = false;
            }
            if(f){
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define endl "\n"

void hk()
{
    long long int n, x=0, y=0, ans=1;
    string s1, s2;
    cin>>s1>>s2;

    for(int i=0;i<s2.length();i++)
    {
        if(i == s2.length()-1)
            break;
        if(s1[i] != s2[i])
        {
            ans = 0;
            break;
        }
    }
    cout<<(ans ? "Yes" : "No")<<endl;

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t;
 	t = 1;

 	for(int i=1;i<=t;i++)
    {
        hk();
    }
 	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_set>
using namespace std;

vector<int> g[100000];
int n;

int dfs(int v, int p) {
	int currXor = 0;
	for (int to : g[v]) {
		if (to == p) continue;
		currXor ^= dfs(to, v) + 1;
	}
	return currXor;
}

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("game.in", "r", stdin);
	//freopen("game.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		b--;
		a--;
		g[b].push_back(a);
		g[a].push_back(b);
	}
	
	int currXor = dfs(0, -1);
	if (currXor == 0) {
		cout << "Bob";
	} else {
		cout << "Alice";
	}
	
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,c,ans;
int main(){
    scanf("%d %d %d",&a,&b,&c);
    if(c>a+b) ans=a+b+b+1;
    else ans=b+c;
    printf("%d",ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main(int argc, char* argv[]) {
  int N;
  cin >> N;
  vector<pair<int, int> > v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i].second >> v[i].first;
  }
  sort(v.begin(), v.end());
  int t = 0;
  for (int i = 0; i < N; i++) {
    t += v[i].second;
    if (t > v[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
	int i=0,j,d,x[3000],y[3000];
	while(1){
		scanf("%d %d",&x[i],&y[i]);
		if(x[i]==0&&y[i]==0){
			break;
		}
		i++;
	}
	for(j=0;i>=j;j++){
		if(x[j]==0&&y[j]==0){
			break;
		}
		if(x[j]>y[j]){
			d=x[j];
			x[j]=y[j];
			y[j]=d;
		}
		printf("%d %d\n",x[j],y[j]);
	}
	return 0;
}

Measured memory_bytes: 2700
n,m = map(int,input().split())
ab = []
for i in range(n):
	ab.append(list(map(int,input().split())))
    
sab = sorted(ab,key=lambda x:x[0])
cost = 0
for i in sab:
	if m - i[1] > 0:
		m -= i[1]
		cost += i[0] * i[1]
	else:
		for j in range(m):
			cost += i[0]
		break
print(cost)

Measured memory_bytes: 29792
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;
 
int main(){
	int n;cin>>n;
	int a[n];for(int i=0;i<n;i++)cin>>a[i];
	int over=0;
	bitset<8> c(0);
 
	for(int i=0;i<n;i++){
		if(		a[i]<400 )c.set(0);
		else if(a[i]<800 )c.set(1);
		else if(a[i]<1200)c.set(2);
		else if(a[i]<1600)c.set(3);
		else if(a[i]<2000)c.set(4);
		else if(a[i]<2400)c.set(5);
		else if(a[i]<2800)c.set(6);
		else if(a[i]<3200)c.set(7);
		else over++;
	}
 
	cout<<max(1,int(c.count()))<<" "<<int(c.count())+over<<endl;
 
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin
# -*- coding="utf-8" -*-
 
n = int(input())
a = input().split()
b = []
if n == 1:
  b.append(a[0])
else:
  for i in range(n-1, 0, -2):
    b.append(a[i])
  b.append(a[0])
  if n % 2 == 1:
    for i in range(1, n-1, 2):
      b.append(a[i])
  else:
    for i in range(2, n-1, 2):
      b.append(a[i])
print(' '.join(b))

Measured memory_bytes: 25544
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    cout << fixed << setprecision(6);
    int n;
    long double aux, cnt = 0, rta = 0;
    string s;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> aux >> s;
        if(s == "JPY") rta += aux;
        else cnt += aux;
    }
    rta += cnt*380000;
    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n,m,x,y;  cin>>n>>m; vector<int> v(n+1);
    for(int i=1;i<=n;i++) cin>>v[i];
    map<int,vector<int>> mp;
    for(int i=1;i<=n;i++) mp[i].push_back(-1);
    for(int i=0;i<m;i++){
        cin>>x>>y; 
        mp[x].push_back(v[y]); mp[y].push_back(v[x]);
    }
    int ans=0;
    map<int,vector<int>>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        vector<int> temp=it->second; int w=temp.size(); int c=0; int p=v[it->first];
        for(int i=0;i<w;i++){
            if(p>temp[i]) c++; 
        }
        //cout<<c<<" "<<w<<"\n";
        if(c==w) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 15344
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

char s[2001][2000];
int a[2001][2000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int h, w;
    cin >> h >> w;

    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    int t;
    for (int i = 0; i < h; i++) {
        t = 0;
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                t = 0;
            } else {
                t++;
                a[i][j] += t;
            }
        }
    }
    for (int i = 0; i < h; i++) {
        t = 0;
        for (int j = w - 1; j >= 0; j--) {
            if (s[i][j] == '#') {
                t = 0;
            } else {
                t++;
                a[i][j] += t;
            }
        }
    }
    for (int j = 0; j < w; j++) {
        t = 0;
        for (int i = 0; i < h; i++) {
            if (s[i][j] == '#') {
                t = 0;
            } else {
                t++;
                a[i][j] += t;
            }
        }
    }
    for (int j = 0; j < w; j++) {
        t = 0;
        for (int i = h - 1; i >= 0; i--) {
            if (s[i][j] == '#') {
                t = 0;
            } else {
                t++;
                a[i][j] += t;
            }
        }
    }

    int r = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            r = max(r, a[i][j]);
        }
    }

    cout << r - 3 << endl;

    return 0;
}

Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;

	priority_queue<pair<long long,int>> v;
	for(int i=0; i<n; ++i){
		int a;
		cin >> a;
		v.push(make_pair(a,1));
	}
	for(int i=0; i<m; ++i){
		int b, c;
		cin >> b >> c;
		v.push(make_pair(c,b));
	}
	
	long long ans=0;
	int cnt=0;
	for(int i=0; i<n+m && cnt<n; ++i){
		auto z=v.top();
		v.pop();
		if(cnt+z.second>=n){
			ans += z.first*(n-cnt);
			break;
		}
		ans += z.first*z.second;
		cnt += z.second;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6128
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
	
	int n;
	cin >> n;
	
	string btn[] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
	
	for(int k=0; k<n; ++k){
		
		string str, res="";
		cin >> str;
		int curr = 0;
		int ptr = -1, tmp;
		
		for(int i=0; i<str.size(); ++i){
			
			tmp = (int)(str[i]-'0');
			
			if(tmp==0){
				if(curr !=0)
					res += btn[curr][ptr];
				
				curr=0;
				ptr=-1;
				continue;
			}
			
			curr = tmp;
			ptr = (ptr+1)%btn[curr].size();
		}
		
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	int[] g = new int[4];
    	int maxOverlap = 0;
    	
    	Scanner in = new Scanner(System.in);
    	
    	for (int i = 0; i < 6; i++) {
    		int tmp = Integer.parseInt(in.next()) -1;
    		
    		g[tmp]++;
    		maxOverlap = Math.max(maxOverlap, g[tmp]);
    	}
    	
    	if (maxOverlap == 2) System.out.println("YES");
    	else System.out.println("NO");
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  string result;
  if (N<1200) result = "ABC";
  else if (N<2800) result = "ARC";
  else result = "AGC";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  int N;
  cin >> N;
  ll A[N+1];
  ll B[N];

  for(int i=0; i<N+1; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> B[i];
  
  ll ans = 0;
  for(int i=0; i<N; i++){
    if(B[i] <= A[i]){
      ans+=B[i];
//      cout << "1in: " << i << endl;
    }else if(A[i] < B[i] && B[i] < A[i]+A[i+1]){
      ans += B[i];
      A[i+1] = A[i+1] - B[i] + A[i];
//      cout << "2in: " << i << endl;      
    }else if(A[i]+A[i+1] <= B[i]){
      ans += (A[i] + A[i+1]);
      A[i+1] = 0;      
//      cout << "3in: " << i << endl;      
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

ll INF = (ll)(1e18)+1;

int main(int argc, char const* argv[])
{
  int n;
  ll k;
  cin>>n>>k;

  vector<ll> as(n);
  REP(i,n) cin>>as[i];
  sort(ALL(as));

  // REP(i,n) printf("%lld ", as[i]);
  // printf("\n");

  ll left = -INF;
  ll right = INF;

  while(left<right-1) {
    ll mid = left + (right-left)/2;
    ll count = 0;
    // printf("left:%lld, right:%lld, mid:%lld\n", left,right,mid);

    REP(i,n) {
      // ll l, r;
      // if(as[i]>=0) l=-1, r=n;
      // else l=-1, r=n;
      ll l=-1, r=n;
      // printf("l:%lld, r:%lld\n", l,r);
      while(l<r-1) {
        ll m = l+(r-l)/2;
        // printf("in while l:%lld, r:%lld, m:%lld\n", l,r,m);
        if(as[i]>=0) {
          if(as[i]*as[m]<mid) l=m;
          else r=m;
        } else {
          if(as[i]*as[m]<mid) r=m;
          else l=m;
        }
      }
      // printf("loop end. l:%lld, r:%lld\n", l,r);
      if(as[i]>=0) {
        if(l>=i) l--;
        count+=l+1;
      }
      else {
        if(r<=i) r++;
        count+=n-r;
      }
      // printf("current count: %lld\n", count);
    }
    count/=2;
    if(count<k) left = mid;
    else right = mid;
    // printf("count:%lld\n", count);
  }

  cout << left << endl;
  // cout << right << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<n; i++);
int main() {
long long X;
cin>>X;
ll answer=0;
answer+=X/500*1000;
answer+=X%500/5*5;
cout<<answer<<endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 2e2 + 7;
const int Inf = 1 << 30;
const LL INF = 1LL << 60;
int n, ans;
set <int> sst;
struct PP {
	int x, y;
	bool color;
	friend bool operator < (PP u, PP v) {
		return u.x < v.x;
	}
} p[maxx];

void Init() {
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> p[i].x >> p[i].y;
		p[i].color = 0;
	}
	for(int i = 1; i <= n; i++) {
		cin >> p[i + n].x >> p[i + n].y;
		p[i + n].color = 1;
	}
	sort(p + 1, p + 2 * n + 1);
}

void Scan() {
	set <int> ::iterator id;
	for(int i = 2 * n; i >= 1; i--) {
		if(p[i].color) sst.insert(p[i].y);
		else {
			id = sst.upper_bound(p[i].y);
			if(id != sst.end()) {
				ans++;
				sst.erase(id);
			}
		}
	}
	cout << ans << endl;
}

int main() {
	Init();
	Scan();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ll x,y,z;
	cin>>x;
        y=x/11;
        z=x%11;
	if(z!=0)
	{
		if(z<=6) z=1;
		else z=2;
	}
	cout<<y*2+z<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string s; cin >> s;
  bool flag = 1;
  if (s.at(0) != 'A') flag = 0;
  ll tmp = 0;
  for (ll i = 2; i < s.size()-1; i++) {
    if (s.at(i) == 'C') tmp++;
  }
  if (tmp != 1) flag = 0;
  tmp = 0;
  rep(i, s.size()) {
    ll num = s.at(i)-'a';
    if (0<=num && num<26) tmp++;
  }
  if (tmp != s.size()-2) flag = 0;
  if (flag) cout << "AC" << endl;
  else cout << "WA" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int main(){
 int n;
 cin>>n;
 int a[n];
 vi g;
 rep(i,n){
   cin>>a[i];
   g.push_back(a[i]);
   }
  sort(been(g),greater<int>());

  rep(i,n){
    if(a[i]==g[0]){
      cout<<g[1]<<endl;
    }
    else cout<<g[0]<<endl;
  }


}

Measured memory_bytes: 3316
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		char[]t=s.next().toCharArray();

		System.out.println(
				t[0]==t[1]||t[1]==t[2]||t[2]==t[3]
						?"Bad":"Good"
				);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define int long long
#include "string"

int32_t main(){
	boost;
	int n;
	cin>>n;
	string ans = "";
	int pw = 1;
	while(pw <= n)
		pw *=26;
	pw /= 26;

	while(n > 0){
		int tt =  n % 26;
		if(tt == 0){
			tt = 26;
			n -= 26;
		}
		n /= 26;
		//cout<<n<<" "<<tt<<endl;
		tt--;
		ans += char('a' + tt);
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a+b > c+d){
    cout << "Left" << endl;
  }
  else if (a+b < c+d){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256