akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
typedef vector<P> vec;
typedef vector<vec> mat;

int main() {
    int N;
    while (cin >> N, N) {
        mat m(10);
        vector<vector<int> > dp(10, vector<int>(10, 1 << 28));
        for (int i = 0; i < N; i++) {
            int a, b, c;
            cin >> a >> b >> c;
            dp[a][b] = dp[b][a] = c;

            dp[a][a] = 0;
            dp[b][b] = 0;
        }

        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
                }
            }
        }

        int ans = 999999999;
        int p;
        for (int i = 0; i < 10; i++) {
            if (dp[i][i] == 1 << 28) continue;

            int sum = 0;

            for (int j = 0; j < 10; j++) {
                if (dp[i][j] != 1 << 28) sum += dp[i][j];
            }

            if (ans > sum) {
                ans = sum;
                p = i;
            }
        }

        cout << p << " " << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3076
// B - Roller Coaster

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	int N, K;
	cin >> N >> K;

	int ans = 0;
	int h;
	for (int i=0; i<N; i++) {
		cin >> h;
		if (h >= K) ans++;
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
INF = float('inf')
N, K = [int(x) for x in input().split()]
P = [0] + [int(x) for x in input().split()]
C = [0] + [int(x) for x in input().split()]

max_score = -INF
for init in range(1, N + 1):   # 初めの場所をiとする
    score = defaultdict(int)  # int/bool/list....
    # visited = defaultdict(init)  # int/bool/list....
    visited = [-1] * (N + 1)
    visited[init] = 0  # 何回移動後に着いたか？
    i = init
    max_init = -INF
    for k in range(1, K + 1):
        prev = i
        i = P[i]    # k回移動後に着くところ



        # if not visited[i]:
        if visited[i] < 0:  # まだ訪れてなかった
            visited[i] = k
            score[i] = score[prev] + C[i]
            max_init = max(max_init, score[i])
            continue

        loop_score = (score[prev] + C[i]) - score[i]
        loop_len = k - visited[i]

        score[i] = score[prev] + C[i]
        max_init = max(max_init, score[i])

        if k == K:
            break # これ以上移動できない

        start = i   # ループを開始するノード
        loop_num = (K - k) // loop_len # ループをあと何回回れるか
        loop_rem = (K - k) % loop_len

        if loop_rem == 0:
            loop_num -= 1
            loop_rem = loop_len

        jj = start
        temp = 0
        temp_max = 0
        for l in range(loop_rem):
            jj = P[jj]
            temp += C[jj]
            temp_max = max(temp_max, temp)

        # loop_max = temp_max + max(loop_num * loop_score, 0)
        loop_max = temp_max + loop_num * loop_score
        max_init = max(max_init, score[start] + loop_max)
        break

    max_score = max(max_score, max_init)

if max_score == -INF:
    max_score = max(C[1:])

print(max_score)

Measured memory_bytes: 169404
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;

int main()
{
    int N, S1, S2, min = 1000000;
    cin >> N;
    vector<int> W(N);
    rep(i, N)
    {
        cin >> W[i];
    }
    rep(i, N)
    {
        int x = i, S1 = 0, S2 = 0;
        for (int j = 0; j <= x; j++)
        {
            S1 += W[j];
        }
        for (int k = x + 1; k < N; k++)
        {
            S2 += W[k];
        }
        if (abs(S1 - S2) < min)
        {
            min = abs(S1 - S2);
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int func(string name,string s,int h);
int main ()
{
    int n,ans=0;
    string board,old;
    cin>>n>>board;
    for(int i=0;i<n;i++){
        cin>>old;
        for(int j=0;j<old.size();j++){
            if(func(board,old,j)==1){
                ans++;
                break;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}
int func (string name,string s,int h)
{
    int cnt=0;
    for(int i=0;i<=s.size()-name.size();i++){
        if(name[0]!=s[i])continue;
        cnt=0;
        for(int j=i;j<s.size();j+=h){
            if(name[cnt]!=s[j])break;
            if(name[cnt+1]=='\0')return 1;
            cnt++;
        }
    }
    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>ostream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(c,b/a)<<endl;
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	long long prev[2] = {2, 1};
	long long cur = 1;
	for (int i = 2; i <= n; ++i) {
		cur = prev[0] + prev[1];
		prev[0] = prev[1];
		prev[1] = cur;
	}
	cout << cur << endl;
	return 0;
}

Measured memory_bytes: 256
//All Pairs Shortest Path
#include <iostream>
#include <climits>

using namespace std;

static const int MAX = 100;
int V, E;
long long A[MAX][MAX];

void warshallFloyd() {
    for(int k = 0; k < V; k++) {
        for(int i = 0; i < V; i++) {
            if(A[i][k] == LONG_LONG_MAX) continue;
            for(int j = 0; j < V; j++) {
                if(A[k][j] == LONG_LONG_MAX) continue;
                A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
            }
        }
    }
}

int main() {
    int s, t;
    long long d;
    cin >> V >> E;

    for (int i = 0; i < MAX; i++) {
        for (int j = 0; j < MAX; j++) A[i][j] = (i == j ? 0 : LONG_LONG_MAX);
    }
    for (int i = 0; i < E; i++) {
        cin >> s >> t >> d;
        A[s][t] = d;
    }

    warshallFloyd();

    bool negative = false;
    for (int i = 0; i < V; i++) {
        if(A[i][i] < 0) negative = true;
    }

    if(negative) cout << "NEGATIVE CYCLE" << endl;
    else {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                if(j != 0) cout << " ";
                if(A[i][j] == LONG_LONG_MAX) cout << "INF";
                else cout << A[i][j];
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3216
#include <iostream>
#include <cstring>

using namespace std;

int main(void){
    int i,j,k,l;
    int count=0;
    bool flag;
    char str[101];
    
    while(cin>>str){
        flag=true;
        i=0;
        l=strlen(str)-1;
        while(i<l){
            if(str[i]!=str[l]){
                flag=false;
                break;
            }
            i++;
            l--;
        }
        if(flag)count++;
    }
    cout<<count<<endl;
    return (0);
}

Measured memory_bytes: 1140
#include<iostream>
using namespace std;
int main(){
  int a,b,r,G,R,L,tmp;
  while(cin >> a >> b){
    R = a; L = b;
    if(b > a){
      tmp = a; a = b; b = tmp;
    }
    while(1){
      r = a % b;
      if(r == 0)
        break;
      a = b;
      b = r;
       }
    G = b;
    R = R / G;
    L = L / G;
    cout << G <<" "<< R*L*G << endl;
  }
}

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

int main() {

  string s;
  cin >> s;

  int K;
  cin >> K;

  set<string> st;

  for (int i = 0; i < s.size(); i++) {
    string s_ = "";
    for (int j = i; j < s.size(); j++) {
      s_ += s[j];
      st.insert(s_);
      if (K < s_.size()) {
        break;
      }
    }
  }

  int count = 1;
  for (auto item:st) {
    if (count == K) {
      cout << item << endl;
      break;
    }
    count++;
  }

  return 0;

}

Measured memory_bytes: 2176
def grading(mid, final, re_exam):   
    if mid == -1 or final == -1:
        return 'F'

    reg_score = mid + final

    if reg_score >= 80:
        return 'A'
    elif reg_score >= 65 and reg_score < 80:
        return 'B'
    elif reg_score >= 50 and reg_score < 65:
        return 'C'
    elif reg_score >= 30 and reg_score < 50:
        if re_exam >= 50:
            return 'C'
        else :
            return 'D'
    else :
        return 'F'
    

while True :
    test_results = [int(i) for i in input().split()]
    mid = test_results[0]
    final = test_results[1]
    re_exam = test_results[2]
    sentinel = mid + final + re_exam
    
    if sentinel == -3:
        break 
    else :
        grade = grading(mid, final, re_exam)
        print(grade)


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

int i;
 
int main()
{
  cin >> i;
  if(i < 10)
  {
    cout << "ABC" << 00 << i << endl;
  }
  else if(i < 100)
  {
    cout << "ABC" << 0 << i << endl;
  }
  else
  {
    cout << "ABC" << i << endl;
  }
  return 0;
}


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

int main(){
  int A, B, C, N;
  cin >> A >> B >> C >> N;
  
  int focus = 0;
  focus = max(A,B);
  focus = max(focus,C);
  int focus_a = 0;
  focus_a = focus;
  
  for(int i=0; i<N; i++){
    focus = focus * 2;
  }
  cout << focus + A + B + C - focus_a << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll mo=1000000007;
int N,K;
ll memo[101][10101];
ll pk[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	pk[0]=1;
	FOR(i,N+1) pk[i+1]=pk[i]*(K+1)%mo;
	
	memo[N+1][0]=1;
	ll ret=0;
	for(int cur=N;cur>=1;cur--) {
		ll tot=0;
		for(i=0;i<=10100;i++) {
			if(memo[cur+1][i]==0) break;
			tot+=memo[cur+1][i];
			FOR(j,K+1) {
				if(j>cur) {
					(memo[cur][i]+=memo[cur+1][i])%=mo;
					(ret+=(j+i)*pk[cur-1]%mo*memo[cur+1][i])%=mo;
				}
				else {
					(memo[cur][i+(j+i)/cur]+=memo[cur+1][i])%=mo;
					(ret+=(j+i)%cur*pk[cur-1]%mo*memo[cur+1][i])%=mo;
				}
			}
		}
	}
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#pragma once
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main() {
    int d,n;
    cin>>d>>n;
    int ans =0;
    if(n==100) {
        ans=pow(100,d)*(n+1);
    }else{
         ans =pow(100,d)*n;
    }
   
    cout<<ans<<endl;



}

Measured memory_bytes: 640
#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
a,b = LS()
c = int(a+b)
for i in range(1,1000):
    if i * i == c:
        print("Yes")
        quit()
print("No")
"""

#B
"""
a,b = LI()
if a*b <= 0:
    print("Zero")
else:
    if b < 0:
        if (a-b) %2 == 1:
            print("Positive")
        else:
            print("Negative")
    else:
        print("Positive")
"""

#C
n = II()
s = SR(n)
march = [[] for i in range(5)]
ch = list("MARCH")
for i in s:
    for j in range(5):
        if i[0] == ch[j]:
            march[j].append(i)
ans = 0
for i in range(5):
    for j in range(i):
        for k in range(j):
            if len(march[i])*len(march[j])*len(march[k]) == 0:
                break
            ans += len(march[i])*len(march[j])*len(march[k])
print(ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 59480
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll A, B, M;
  cin >> A >> B >> M;
  vector<ll> a(A);
  rep (i, A) cin >> a[i];
  vector<ll> b(B);
  rep (i, B) cin >> b[i];

  ll mina = a[0];
  rep (i, A) mina = min(mina, a[i]);

  ll minb = b[0];
  rep (i, B) minb = min(minb, b[i]);

  ll ans = mina + minb;

  rep (i, M) {
    ll x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ll tmp = a[x] + b[y] - c;
    ans = min(ans, tmp);
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

constexpr int N = 200005;
int n, k, a[N];

inline int mod(int x) {
  if(x >= 0 && x < k) return x;
  x %= k;
  if(x < 0) return x + k;
  else return x;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> n >> k;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] = mod(a[i] + a[i - 1]);
  }
  map<int, vector<int>> mp;
  for(int i = 0; i <= n; ++i) {
    mp[mod(a[i] - i)].push_back(i); 
  }
  long long ans = 0;
  for(auto& e : mp) {
    vector<int>& v = e.second;
    int c = 1; 
    for(int i : v) {
      ans += lower_bound(v.begin(), v.end(), k + i) - v.begin() - c;
      ++c;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 22912
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main(void){
  int j,k,N,sum,ans[2],t[2],n,i,M;
    int a[100000]={};
  int b[1000000]={};
  int d[1000000];
  char S[1000000][2],Q[2];
  char w[2]="AC";
  char r[2];
    
  if(scanf("%d %d",&N,&M)>2){
    exit(0);
  }
  if(M==0){
    printf("%d %d",0,0);
     return 0;
  }
 for(i=0;i<M;i++){
   if(scanf("%d %s",&d[i],&S[i])>2){
     exit(0);
   }
 }
 
 /*/
     //printf("%c\n",Q[0]);
     // printf("%c\n",Q[1]);
 //printf("%d\n",d[0]);
 printf("%c\n",S[0][0]);
 printf("%c\n",S[0][1]);
 printf("%c\n",S[1][0]);
 printf("%c\n",S[1][1]);
 /*/
 t[0]=0;
 t[1]=0;
 ans[0]=0;
 ans[1]=0;
 //printf("%c\n",S[0]);
 //printf("%c\n",w[0]);
 //printf("%c\n",w[1]);
 //printf("%s\n",w);
 for(i=0;i<M;i++){
   r[0]=S[i][0];
   r[1]=S[i][1];
   //printf("%c\n",r[0]);
   //printf("%c\n",r[1]);
   //printf("%s\n",r);
   if(r[0]=='A' && r[1]=='C' && b[d[i]]<0.5){
     ans[0]++;
   ans[1]+=a[d[i]];
   b[d[i]]=1;
 }
   if(r[0]=='W' && r[1]=='A' && b[d[i]]<0.5){
   a[d[i]]+=1;
 }
  }
 printf("%d %d",ans[0],ans[1]);
  return 0;
}




Measured memory_bytes: 8704
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    array = sc.intarr()

    for i in array:
        if i == array[-1]:
            print(i, end='')
        else:
            print(i, end=' ')
    print("")

    for i in range(1, n):
        v = array[i]
        j = i - 1

        while j >= 0 and array[j] > v:
            array[j+1] = array[j]
            j = j - 1
        array[j+1] = v
        for i in array:
            if i == array[-1]:
                print(i, end='')
            else:
                print(i, end=' ')
        print("")


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()



Measured memory_bytes: 6076
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e16
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
signed main()
{
	int n = in(), q = in();
	queue<pair<string, int>>que;
	REP(i, n)
	{
		string name = in<string>();
		int time = in();
		que.push(make_pair(name, time));
	}
	for (int time_sum = 0; que.size() > 0;)
	{
		auto top = que.front(); que.pop();
		if (top.second <= q)
		{
			cout << top.first << ' ' << time_sum + top.second << endl;
			time_sum += top.second;
		}
		else
		{
			que.push(make_pair(top.first, top.second - q));
			time_sum += q;
		}
	}
}


Measured memory_bytes: 6300
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define SIZ 1000005
#define SIZE 200005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair<string,ll>&a,const pair<string,ll>&b){
	return (a.first < b.first || (a.first == b.first && a.second > b.second));
}

signed main(){ 
    IOS
    //io_set();
    ll n, p;
    string s;
    cin >> n;
    ll tt = n;
    vector < pair < string , ll > > a, b;
    while(tt--){
    	cin >> s >> p;
    	a.pb(mp(s,p));
    	b.pb(mp(s,p));
    }
    sort(all(b),comp);
    map < pair<string , ll >,ll > mpp;
    ll j=1;
    for(auto it : a){
    	mpp[{it.first,it.second}] = j;
    	j++;
    }
    for(auto it : b){
    	cout << mpp[{it.first,it.second}] << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const int mod = 2019;
static const int INF = 3000;
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	int minv=numeric_limits<int>::max();
	for(int i=-100;i<=100;++i){
		int cul=0;
		rep(j,n){
			cul+=(int)pow(a[j]-i,2);
		}
		minv=min(minv,cul);
	}
	cout<<minv<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define vi   vector<int>
#define vvi  vector<vi >
#define vvvi vector<vvi >
#define pii  pair<int,int>
#define INF  (int)1e9
#define MOD  (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	string s;
	int k;
	cin>>s>>k;
	
	int n=min((int)s.size(),k);
	set<string> ss;
	for(int i=1;i<=n;++i){
		for(int j=0;j<=s.size()-i;++j){
			ss.insert(s.substr(j,i));
		}
	}
	
	auto itr=ss.begin();
	REP(i,k-1){
		itr=ss.erase(ss.begin());
	}
	
	cout<<*itr<<endl;
}//解説参考.

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<double,ll> P;


int main(){
	int a,b,c;cin >> a >> b >> c;cout << a * b / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> num(n + 2);
	num[n + 1] = 1;
	for (int i = n; i > 0; i--) {
		num[i] = num[i + 1] - n + (ll)i * 2;
	}
	ll ans = 0;
	for (int i = k; i < n + 2; i++) {
		ans += num[i] % mod;
	}
	ans = (ans + mod) % mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4820
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

//(int)'a'=97 (int)'A'=65 (int)'1'=49
//おまじない

const int maxn = 300000;

int main(){
    
    ll n;
    ll mod = INF;
    ll ans=0;
    ll a[maxn];
    cin >> n;
    
    rep(i,n)cin >> a[i];
    
    ll b = 1;
    rep(i,60){
        ll c = b;
        b=b*2;
        ll A=0,B=0;
        rep(j,n){
            if(c<=a[j]%b)A++;
        }
        B = n-A;
        ans += (((A*B)%mod)*(c%mod))%mod;
        ans %=mod;
    }
    
    cout << ans <<endl;
    
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
const long long mod = 1000000007;


int main() {
	int N;
	scanf("%d", &N);
	for (int i = 0; i <= N; i++) {
		if (100 * i <= N && N <= 105 * i) {
			printf("1");
			return 0;
		}
	}
	printf("0");
	return 0;
}

Measured memory_bytes: 128
def isSeparater c
  c == ' ' || c == ',' || c == '.'
end

def solve str
  first = true
  result = ""
  out = ""
  str.chars do |c|
    if isSeparater c
      if 2 < out.size && out.size < 7
        result.concat(" ") unless first
        first = false
        result.concat(out)
      end
      out = ""
    else
      out.concat c
    end
  end
  result
end

printf "%s\n", solve($stdin.gets.chomp)

Measured memory_bytes: 6088
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: usize,
        b: usize
    }
    if a == b {
        println!("Draw");
    } else if a == 1 {
        println!("Alice");
    } else if b == 1 {
        println!("Bob");
    } else if a > b {
        println!("Alice");
    } else {
        println!("Bob");
    }
}


Measured memory_bytes: 4352
package main
 
import (
	"fmt"
)

var graph [8][8]bool

func dfs (v, n int, visited [8]bool) int{
  all_visited := true;
  for i := 0; i < n; i++{
    if visited[i] == false{
      all_visited = false;
    }
  }
  if all_visited == true{
    return 1;
  }
  
  ret := 0
  for i := 0; i < n; i++{
    if graph[v][i] == false {
      continue
    }
    if visited[i] == true {
      continue
    }
    
    visited[i] = true
    ret += dfs(i, n ,visited)
    visited[i] = false;
  }
  return ret
}

func main() {
  var n, m, a ,b int
  fmt.Scanf("%d %d", &n, &m)
  
  for i := 0; i < m; i++{
    fmt.Scanf("%d %d", &a, &b)
    graph[a-1][b-1] = true
    graph[b-1][a-1] = true
  }
  
  var visited [8]bool
  for i := 0; i < n; i++{
    visited[i] = false
  }
  
  visited[0] = true
  ans := dfs(0, n, visited)
  
  fmt.Printf("%d", ans)
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

string rot(string s) {
  string r = "";
  rep (i, s.size()) {
    char c = s[i] < 'a' ? s[i]
           : s[i] == 'z' ? 'a' : char(s[i]+1);
    r += c;
  }
  return r;
}

bool ok(string s) {
  int a = s.find("the");
  int b = s.find("this");
  int c = s.find("that");
  return a != string::npos || b != string::npos || c != string::npos;
}

int main() {

  vi xs;
  int x;
  while (cin >> x, cin) xs.push_back(x);
  sort(all(xs)); reverse(all(xs));
  cout << xs << endl;

  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int a, b;
	cin >> a >> b;
	if (a*b*(a + b) % 3 == 0)print("Possible"); else print("Impossible");






	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        m: usize,
        aabb: [(isize, isize); n],
        ccdd: [(isize, isize); m],
    };
    for (x1, y1) in aabb {
        let mut min_len = std::isize::MAX;
        let mut pos = 0usize;
        for (index, (x2, y2)) in ccdd.iter().enumerate() {
            let len = (x1 - x2).abs() + (y1 - y2).abs();
            if len < min_len {
                min_len = len;
                pos = index;
            }
        }
        println!("{}", pos + 1);
    }
}


Measured memory_bytes: 2164
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if (i,j) not in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)

Measured memory_bytes: 176764
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	string s;
	cin>>s;
	for(int i = 0; i<s.length()-1; i++){
		if(s[i] == s[i+1]){
			cout<<"Bad\n";
			return 0;
		}
	}
	cout<<"Good\n";
	return 0;
}

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

int main(){
  int n,i;
  cin>>n;
  int v[n],c[n],p[n];
  for(i=0;i<n;i++)cin>>v[i];
  for(i=0;i<n;i++)cin>>c[i];
  for(i=0;i<n;i++)p[i]=v[i]-c[i];
  int sum=0;
  for(i=0;i<n;i++){
    if(p[i]>0)sum+=p[i];
  }
  cout<<sum;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
a=N//2
b=a+1
print(a,b)
if M==1:
  exit(0)
c=1
d=N-1
print(c,d)
for i in range(M-2):
  if i%2==0:
    a,b=a-1,b+1
    print(a,b)
  else:
    c,d=c+1,d-1
    print(c,d)


Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    double v[1000];
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    sort(v, v+n);
    double ans = 0;
    for(int i=0; i<2; i++){
        ans += v[i];
    }
    ans /= 2;
    for(int i=2; i<n; i++){
        ans += v[i];
        ans/=2;
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cassert>
#include<vector>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<fstream>
#include<typeinfo>
#include<locale>
#include<iterator>
#include<valarray>
#include<complex>
#include<climits>
using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

int maximum69Number (int num) {

           vector<int>d;
           while(num>0){
             d.pb(num%10);
             num/=10;
           }

          reverse(d.begin(),d.end());

          for(int i = 0; i<d.size(); i++){
            if(d[i]==6){
                d[i] = 9;break;
            }
          }
          int res = 0;
          for(int i = 0; i<d.size(); i++){
            res = res*10+d[i];
          }
          return res;
}


int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("out.txt","w",stdout);
     int n,m;
     cin >> n >> m;

     if(n==m){
        cout << "Yes" << endl;
     }
     else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys


def selection_sort(a, n):
    swap_count = 0
    for i in range(0, n):
        minj = min(range(i, n), key=a.__getitem__)
        if i != minj:
            a[i], a[minj] = a[minj], a[i]
            swap_count += 1
    return swap_count


n = int(sys.stdin.readline())
a = [int(v) for v in sys.stdin.readline().strip().split()]
count = selection_sort(a, n)

print(' '.join(map(str, a)))
print(count)


Measured memory_bytes: 5608
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

numbers = input_numbers()

numbers.sort()
if(numbers[0] == 1):
    if(numbers[1] == 1):
        print(1)
    else:
        print(numbers[1] - 2)

else:
    ans = numbers[0] * numbers[1] - (numbers[0] + numbers[1] - 2) * 2

    print(ans)

Measured memory_bytes: 20392
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
// 省略
#define ll long long
#define ld long double
#define Vi vector<int>
#define Vl vector<ll>
// for
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Repp(i, a, b) for (int i = a; i <= (int)(b); i++)
#define Repm(i, a, b) for (int i = a; i <= (int)(b); i—-)
// 入力
#define ini(x) int x; cin >> x;
#define inl(x) ll x; cin >> x;
#define ind(x) double x; cin >> x;
#define inc(x) char x; cin >> x;
#define ins(x) string x; cin >> x;
// 出力
#define co(x) cout << x;
#define ce cout << endl;
#define cs cout << “ “;
#define keta(x) cout << fixed << setprecision(x);
// 配列
#define Sort(x) sort(x.begin(), x.end()); // 小順
#define Rev(x) reverse(x.begin(), x.end());

int main() {
  ini(N)
  Vl As(100100, 0);
  rep(i, N){
    ini(A) As[A]++; 
  }
  
  ll ans = 0;
  rep(i, 100100){
    ans += i*As[i];
  }
    
  ini(Q) 
  rep(i, Q){
    inl(B) inl(C)
    ll keep;
    keep = As[B]; As[B] = 0;
    ans -= keep*B;
    As[C] += keep;
    ans += keep*C;
    co(ans) ce
  }
}

Measured memory_bytes: 4052
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
      
N,M = map(int,input().split())
Edge = []
for i in range(M):
  a,b = map(int,input().split())
  Edge.append([a-1,b-1])

ans = 0
for i in range(M):
 graph = UnionFind(N)
 for j in range(M):
   if(i != j): 
    graph.Unite(Edge[j][0],Edge[j][1])
 if(graph.Count(0) != N): ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_map>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 2000000000
typedef long long ll;

ll bisect(ll l,ll r,ll N,ll K,vector<ll> A){
    if(r-l==1) return r;
    ll k = 0;
    ll m = (l+r)/2;
    REP(i,N){
        if (A.at(i)%m==0) k+=A.at(i)/m-1;
        else k+=A.at(i)/m;
    }
    if(k<=K){
        return bisect(l,m,N,K,A);
    } else{
        return bisect(m,r,N,K,A);
    }
}

void solve(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,N) cin >> A.at(i);
    cout << bisect(0,1000000000,N,K,A) << endl;
}

int main(){
    solve();
}

Measured memory_bytes: 52852
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long max = 1000000000000000000l;
    long now = 1l;
    long[] a = new long[n];
    for(int i = 0;i<n;i++){
      a[i] = sc.nextLong();
      if(a[i] == 0){
        System.out.println(0);
        return;
      }
    }
    for(int i = 0;i<n;i++){
      max /= a[i];
      // if(max % long != 0)koe = true;
      if(max == 0){
        System.out.println(-1);
        return;
      }
      now *= a[i];
    }
    System.out.println(now);
  }
}


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

using namespace std;

int main(){
    int N,lastN;
    cin>>N;
    lastN=N%10;
    if(lastN==2 || lastN==4 || lastN==5 || lastN==7 || lastN==9){
        cout<<"hon";
    }
    if(lastN==0 || lastN==1 || lastN==6 || lastN==8){
        cout<<"pon";
    }
    if (lastN==3){
            cout<<"bon";
    }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    ll n;
    multimap< ll, ll> m;
    cin>>n;
    int i;
    ll a[n+5], b[n+5];
    FOR0(i, n)
    {
        cin>>a[i]>>b[i];
        m.insert(mp(-1*(a[i]+b[i]), i));
    }
    multimap<ll, ll>::iterator it;
    it = m.begin();
    int cur = 0;
    ll ans = 0;
    while(it!=m.end())
    {
        if(!cur) ans += a[it->ss];
        else ans -= b[it->ss];
        cur = 1-cur;
        it++;
    }
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  
  for(int i = 1; i <= 10; i++){
    if(n <= i * 1000){
      cout << i * 1000 - n << endl;
      break;
    }
  }  
}

Measured memory_bytes: 3572
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
    // String[] nyu=sc.nextLine().split(" ");

     String nyu=sc.nextLine();
//int A=Integer.parseInt(nyu[0]);
//int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);
//int D=Integer.parseInt(nyu[3]);


StringBuffer sb = new StringBuffer(nyu);
String line_r_1 = sb.reverse().toString();
     String nyu2=sc.nextLine();
sb = new StringBuffer(nyu2);
String line_r_2 = sb.reverse().toString();



//double A=Double.parseDouble(nyu[0]);
//double B=Double.parseDouble(nyu[1]);
/*
switch(C){
case 7:
case 5:
case 3:
System.out.println("YES") ;
break;
default:
System.out.println("NO") ;

break;
}
*/

//int res=Math.min((A*B),C);

//for(String tem:nyu){
//if(tem.equals("1"))res++;
//}

//char[] c = nyu.toCharArray();


//System.out.println(nyu+"-"+line_r_2+"-"+nyu2+"-"+line_r_1);


if(nyu.equals(line_r_2) && nyu2.equals(line_r_1)){
//double res=Math.ceil((AB)/2);

System.out.println("YES");
//}else if((int)c[0]>(int)c[2]){
//System.out.println(">");

}else{
System.out.println("NO");

}




	}
}

Measured memory_bytes: 23124
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


main() {
	int n, i;
	scanf("%d", &n);

	if (n<1200) {
		printf("ABC");
	}
	else if(n<2800){
		printf("ARC");
	}
	else { printf("AGC"); }
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#define mod 998244353
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
using namespace std;
typedef long long ll;
const double PI=3.14159265358979;
const double eps=1e-15;
const int INF=2147483647;
const int maxn=310;
const int maxm=20;

int n;
ll cost,g[maxn][maxn],h[maxn][maxn];
bool vis[maxn][maxn];

void floyd(){
    memset(vis,0,sizeof(vis));
    for(int k=0;k<n;++k)
        for(int i=0;i<n;++i)
            for(int j=0;j<n;++j)
                if(h[i][j]>=h[i][k]+h[k][j]){
                    h[i][j]=h[i][k]+h[k][j];
                    if(k!=i && k!=j)
                        vis[i][j]=vis[j][i]=true; 
                }                   
}

int main(){  
    while(~scanf("%d", &n)){
        for(int i=0;i<n;++i)
            for(int j=0;j<n;++j){
                scanf("%lld", &g[i][j]);
                h[i][j]=g[i][j];
            }
        floyd();
        bool isok=true;
        cost=0;
        for(int i=1;i<n;++i){
            for(int j=0;j<i;++j){
                if(h[i][j]!=g[i][j]){
                    isok=false;
                    break;
                }        
                if(!vis[i][j])   cost+=h[i][j];                     
            }  
            if(!isok)   break;
        }
        printf("%lld\n",isok?cost:-1);
    }
    return 0;  
}  

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100

int main(){
  int x[N];
  char s[N];
  int top=0;

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x[top-2]=x[top-2] + x[top-1];
      top--;
    } 
    else if ( s[0] == '-' ){
      x[top-2] = x[top-2] - x[top-1];
      top--;
    } 
    else if ( s[0] == '*' ){
       x[top-2] = x[top-2] * x[top-1];
      top--;
    }
    else {
      x[top] = atoi(s);
      top++;
    }
  }
  printf("%d\n",x[top-1]);
  return 0;
}

Measured memory_bytes: 548
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	int jiro[100];
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			cin>>jiro[i];
		}
		int r=32;
		i=0;
		while(r>0){
			cout<<(r-1)/5*5+1<<endl;
			r=(r-1)/5*5+1;
			if(jiro[i]>r)cout<<0<<endl;
			else cout<<r-jiro[i]<<endl;
			r-=jiro[i];
			i=(i+1)%n;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;

int main(){
    int x; cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int x,y,z;

int main() {
	cin >> x >> y;
	for (int a = 0; a < y; a++) {
		cin >> z;
		x -= z;
	}
	if (x < 0) printf("-1\n"); else cout << x << "\n";
}

Measured memory_bytes: 3676