akhauriyash/Code-Regression huggingface dataset:
import math
import sys

X=int(input())
i=0
y= 100

if X==y:
	print(i)
	sys.exit()

while X > y:
	i=i+1
	y=y*1.01
	y=math.floor(y)
	if X==y:
		print(i)
		sys.exit()

print(i)

Measured memory_bytes: 9172
n = int(input())
di = [[0]*123 for _ in range(n)]
new = [0]*123
al = []
for i in range(n):
    s = str(input())
    for j in range(len(s)):
        p = ord(s[j])
        di[i][p] += 1
for k in range(97,123):
    a = float("inf")
    for l in range(n):
        if a > di[l][k]:
            a = di[l][k]
    new[k] = a
for m in range(97,123):
    if new[m] != 0:
        st = chr(m)
        al += [st]*(new[m])
if al != []:
    print("".join(al))
else:
    print("")

Measured memory_bytes: 3064
N,M = (int(i) for i in input().split())
ban=[False]*(N+1)
for i in range(M):
    a=int(input())
    ban[a]='True'
    
dp=[0]*(N+1)
dp[0]=1
if ban[1]=='True':
    dp[1]=0
else:
    dp[1]=1

for i in range(2,N+1):
    if(ban[i]):
        dp[i]=0
    else:
        dp[i]=dp[i-2]+dp[i-1]
print(dp[N]%1000000007)
        


    
    


Measured memory_bytes: 460788
//Attack Survival
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

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

    vector<int> vec(N,(K-Q));
    for (int i = 0; i < Q; i++) {
        int tmp;
        cin >> tmp;
        vec[tmp-1]++;
    }

    for (int i = 0; i < N; i++) {
        //cout << vec[i];
        if (vec[i] > 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int T;
	cin >> T;
	forn(tc, T)
	{
		int N, K , L, R;
		cin >> N;
		vector<tuple<int, int, int>> vL, vR;
		uint64_t res = 0;
		forn(i, N)
		{
			cin >> K >> L >> R;
			if(L > R)
				vL.push_back(make_tuple(K, L, R));
			else
				vR.push_back(make_tuple(K, L, R));
		}
		sort(vL.begin(), vL.end());
		sort(vR.begin(), vR.end());
		reverse(vR.begin(), vR.end());
		multiset<int> ms;
		forn(i, vL.size())
		{
			auto tmp = vL[i];
			K = get<0>(tmp);
			L = get<1>(tmp);
			R = get<2>(tmp);
			while (ms.size() >= K && *ms.begin() < L-R)
			{
				res -= *ms.begin();
				ms.erase(ms.begin());
			}
			if (ms.size() >= K)
			{
				res += R;
			}
			else
			{
				res += L;
				ms.insert(L - R);
			}
		}
		multiset<int> mR;
		forn(i, vR.size())
		{
			auto tmp = vR[i];
			K = get<0>(tmp);
			L = get<1>(tmp);
			R = get<2>(tmp);
			if (K == N)
			{
				res += L;
				continue;
			}
			int ul = N - K ;
			while (mR.size() >= ul && *mR.begin() < R - L)
			{
				res -= *mR.begin();
				mR.erase(mR.begin());
			}
			if (mR.size() >= ul)
			{
				res += L;
			}
			else
			{
				res += R;
				mR.insert(R - L);
			}
		}
		cout << res << endl;
	}
	return 0;
}


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

struct UnionFind{
  int n;
  vector<int> p,r;
  UnionFind(int sz):n(sz),p(sz,0),r(sz,1){iota(p.begin(),p.end(),0);}
  int find(int x){
    if(p[x]==x)return x;
    else return p[x]=find(p[x]);
  }
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(p[x]<p[y])p[y]=x;
    else p[x]=y;
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
};

int main(){
  int n;
  cin>>n;
  vector<pair<int,string> > p(n);
  for(int i=0;i<n;i++)cin>>p[i].second>>p[i].first;
  sort(p.begin(),p.end());
  map<string,int> stoi;
  for(int i=0;i<n;i++){
    stoi[p[i].second]=i;
  }
  UnionFind uf(n);
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    string s,t;
    cin>>s>>t;
    uf.unite(stoi[s],stoi[t]);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=p[uf.find(i)].first;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3756
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    lines = ["".join(sorted(line.rstrip())) for line in sys.stdin.readlines()]

    ret = 0
    sortedlines = {}
    for n in range(N):
        item = lines[n]
        if item in sortedlines:
            sortedlines[item] += 1
            ret += sortedlines[item]
        else:
            sortedlines[item] = 0

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21040
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 45

int MDT[N2][N2];
const int dx[4] { -1, 0, 1, 0 };
const int dy[4] { 0, -1, 0, 1 };
const char dir[4] { 'u', 'l', 'd', 'r' };

struct Puzzle {
	int f[N2], space, MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMd(Puzzle p) {
	int sum = 0;
	for (int i = 0; i < N2; ++i) {
		if (p.f[i] == N2)
			continue;
		sum += MDT[i][p.f[i] - 1];
	}
	return sum;
}

bool dfs(int depth, int prev) {
	if (state.MD == 0) {
		return true;
	}
	if (depth + state.MD > limit)
		return false;

	int sx = state.space / N;
	int sy = state.space % N;
	Puzzle tmp;

	for (int r = 0; r < 4; ++r) {
		int tx = sx + dx[r];
		int ty = sy + dy[r];
		if (tx < 0 || ty < 0 || tx >= N || ty >= N)
			continue;
		//??????????????????
		if (max(prev, r) - min(prev, r) == 2)
			continue;
		tmp = state;
		//????????????????????£?????????
		state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
		state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];

		swap(state.f[tx * N + ty], state.f[sx * N + sy]);
		state.space = tx * N + ty;

		if (dfs(depth + 1, r)) {
			path[depth] = r;
			return true;
		}
		//???????????£????????????
		state = tmp;
	}
	return false;
}

//??????
string iterate_deeping(Puzzle p) {

	p.MD = getAllMd(p);

	for (limit = p.MD; limit <= LIMIT; ++limit) {
		state = p;
		if (dfs(0, -100)) {
			string ans = "";
			for (int i = 0; i < limit; ++i) {
				ans += dir[path[i]];
			}
			return ans;
		}
	}
	return "";
}

int main() {

	for (int i = 0; i < N2; ++i) {
		for (int j = 0; j < N2; ++j) {
			MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
		}
	}
	Puzzle p;
	for (int i = 0; i < N2; ++i) {
		scanf("%d", &p.f[i]);
		if (p.f[i] == 0) {
			p.f[i] = N2;
			p.space = i;
		}
	}
	string ans = iterate_deeping(p);
	cout << ans.size() << endl;
	return 0;
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  reverse(ALL(s));
  vector<string> t = {"dream", "dreamer", "erase", "eraser"};
  REP(i, 4) reverse(ALL(t[i]));
  int i = 0;
  while(i < n){
    bool ok = false;
    REP(j, 4){
      int m = t[j].size();
      if(s.substr(i, m) == t[j]){
        ok = true;
        i += m;
      }
    }
    if(!ok){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 512
N = int(input())
As = list(map(int, input().split()))
r = 1
n, m, l = 0, 0, 0
for A in As:
  if n == m == l == A:
    r = r*3%1000000007
    l += 1
  elif n < m == l == A:
    r = r*2%1000000007
    l += 1
  elif m < l == A:
    r = r*1%1000000007
    l += 1
  elif n == m == A < l:
    r = r*2%1000000007
    m += 1
  elif n < m == A < l:
    r = r*1%1000000007
    m += 1
  elif n == A < m:
    r = r*1%1000000007
    n += 1
  else:
    r = 0
print(r)


Measured memory_bytes: 14396
N, M = list(map(int,input().split()))

students = [list(map(int,input().split())) for i in range(N)]
checkpoints = [list(map(int,input().split())) for i in range(M)]

def checkdist(student,checkpoint):
    a, b = student
    c, d = checkpoint
    
    distance = abs(a-c) + abs(b-d)
    return distance

result = {}

for i in range(len(students)):
    result[i] = 0
    
for i, student in enumerate(students):
    lowest_dist = checkdist(student, checkpoints[0])
    for j, checkpoint in enumerate(checkpoints):
        distance = checkdist(student,checkpoint)
        if distance < lowest_dist:
            result[i] = j
            lowest_dist = distance

for i in range(len(students)):
    print(result[i] + 1)    

Measured memory_bytes: 3064
x=int(input())
p=0
q=0
flag=True
for a in range(1000):
    if flag:
        B=abs(a**5-x)
        for i in range(int(B**(0.2))+1):
            if i**5==B:
                q=i
                p=a
                flag=False
                break
for a,b in [(p,q),(-p,q),(p,-q),(-p,-q),(q,p),(-q,p),(q,-p),(-q,-p)]:
    if a**5-b**5==x:
        print(a,b)
        break

Measured memory_bytes: 9412
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n); for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
typedef pair<int, int> P;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  int N;string S;cin>>N>>S;
  int cnt=0;
  rep(i,10){
    rep(j,10){
      rep(k,10){
        vi a={i,j,k};
        
        bool a0=false,a1=false,a2=false;
        rep(l,N){
          if(S[l]==i+'0'&&!a0)a0=true;
          else if(S[l]==j+'0' &&a0&&!a1)a1=true;
          else if(S[l]==k+'0' &&a1)a2=true;
        }
        if(a0&&a1&&a2)cnt++;
      }
    }
  }
  cout<<cnt<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
int const INF=1000000000;
int DP[100001];
vector<int>H(100000);
int rec(int n){
    if(n==0)return 0;
    if(DP[n]!=INF)return DP[n];

    int res=INF;
    if(n-2>=0)res=min(res,rec(n-2)+abs(H[n-2]-H[n]));
    if(n-1>=0)res=min(res,rec(n-1)+abs(H[n-1]-H[n]));
    return DP[n]=res;
}
typedef long long ll;
int main(){
    int N;
    cin>>N;
    for(int i=0;i<=100001;i++){
        DP[i]=INF;
    }
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    DP[0]=0;
    cout<<rec(N-1)<<endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		int k[100];
		for(int i=0;i<n;i++)cin>>k[i];
		string s;cin>>s;
		for(int i=0;i<s.size();i++)
		{
			int now=k[i%n];
			if(now>=26)
			{
				now-=26;
				s[i]^=32;
			}
			if(s[i]<'a')
			{
				if(s[i]-'A'<now)
				{
					now-=s[i]-'A'+1;
					s[i]='z'-now;
				}
				else s[i]-=now;
			}
			else
			{
				if(s[i]-'a'<now)
				{
					now-=s[i]-'a'+1;
					s[i]='Z'-now;
				}
				else s[i]-=now;
			}
		}
		cout<<s<<endl;
	}
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 s,w;
    cin >> s >> w;
    if(w >= s){
        ANS("unsafe");
    }else{
        ANS("safe");
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;


int main() {
    int A1, A2, A3;
    cin >> A1>>A2>>A3;
    if(A1+A2+A3>=22)
        cout<< "bust" <<endl;
    else
        cout << "win" <<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a == 1) a+=13;
    if(b == 1) b+=13;
    if(a<b) cout << "Bob" << endl;
    else if(a>b) cout << "Alice" << endl;
    else cout << "Draw" << endl;
}

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

using ll = long long;

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

    const int MAXN = 200000;
    static ll a[MAXN * 3];

    for (int i = 0; i < 3 * N; i++) {
        cin >> a[i];
    }

    static ll sum1[MAXN * 3],   // 前半部分 [0, i]
              sum2[MAXN * 3];   // 後半部分 [i, 3N - 1]
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    priority_queue<ll> que2;

    for (int i = 0; i < 3 * N - 1; i++) {
        sum1[i] = (i > 0 ? sum1[i - 1] : 0) + a[i];
        que1.push(a[i]);

        if (que1.size() <= N) continue;

        sum1[i] -= que1.top();
        que1.pop();
    }

    for (int i = 3 * N - 1; i >= 0; i--) {
        sum2[i] = sum2[i + 1] + a[i];
        que2.push(a[i]);

        if (que2.size() <= N) continue;

        sum2[i] -= que2.top();
        que2.pop();
    }

    ll ans = -(1LL << 50);
    for (int i = N - 1; i < 2 * N; i++) {
        ans = max(ans, sum1[i] - sum2[i + 1]);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 14196
#include <iostream>
#include <queue>

using namespace std;

typedef pair<long, int> P;
priority_queue<P, vector<P>, greater<P>> que_pos;
priority_queue<P, vector<P>> que_neg;

int main(){
    long N, Q;
    long a[200000], b[200000];
    cin >> N >> Q;
    for(int i = 0; i < 2*N ; i++){
        cin >> a[i];
    }
    for(int i = 0; i < 2*N ; i++){
        cin >> b[i];
    }
    long sum_a = a[0] + a[2*N-1];
    long sum_b = 0;
    int cnt_pos = 0;
    for(int i = 1; i <= 2*N-2; i++){
        if(a[i] < b[i]){
            cnt_pos++;
            que_pos.push(P(b[i]-a[i], i));
            sum_b += b[i];
        }else{
            que_neg.push(P(b[i]-a[i], i));
            sum_a += a[i];
        }
    }
    //cout << cnt_pos << endl;
    //cout << sum_a << ' ' << sum_b << endl;
    for(int i = 0; i < Q; i++){
        int p, x, y;
        cin >> p >> x >> y;
        p--;
        if(b[p] > a[p]) {
            if(p != 0 && p != 2*N-1){
                cnt_pos--;
                sum_b -= b[p];
            }else{
                sum_a -= a[p];
            }
        }else{
            sum_a -= a[p];
        }
        a[p] = x;
        b[p] = y;
        if(b[p] > a[p]) {
            if(p != 0 && p != 2*N-1){
                cnt_pos++;
                sum_b += b[p];
                que_pos.push(P(b[p]-a[p], p));
            }else{
                sum_a += a[p];
            }
        }else{
            if(p != 0 && p != 2*N-1){
                sum_a += a[p];
                que_neg.push(P(b[p]-a[p], p));
            }else{
                sum_a += a[p];
            }
        }
        //cout << sum_a << ' ' << sum_b << endl;        
        if(cnt_pos%2 == 0){
            //cout << 'H' << endl;
            cout << sum_a+sum_b << endl;
        }else{
            while(!que_pos.empty()){
                P top = que_pos.top();
                int idx = top.second;
                if(top.first != (b[idx]-a[idx])) que_pos.pop();
                else break;
            }
            while(!que_neg.empty()){
                P top = que_neg.top();
                int idx = top.second;
                if(top.first != (b[idx]-a[idx])) que_neg.pop();
                else break;
            }
            //if(que_neg.empty()) cout << "neg empty\n";
            //if(que_pos.empty()) cout << "pos empty\n";
            if(que_neg.top().first+que_pos.top().first >= 0){
                cout  << sum_a + sum_b + que_neg.top().first << endl;
            }else{
                cout  << sum_a + sum_b - que_pos.top().first << endl; 
            }
        }
    }
}

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

#define endl "\n"
#define INF 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cout << #x << " => " << x << "\n"
#define deba(x) cout << #x << "\n"; for (auto a : x) cout << a << " "; cout << "\n";
#define debm(x) cout << #x << "\n"; for (auto a : x){for(auto b : a) cout << b << " "; cout << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int32_t main() { fastio;
    int n; cin >> n;
    map<string, int> mp;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto m : mp) {
        mx = max(mx, m.second);
    }
    for (auto m : mp) {
        if (m.second == mx) {
            cout << m.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 23808
n, m = gets.split.map(&:to_i)

k = Array.new(m)
s = Array.new(m)
m.times do |i|
  k[i],*s[i] = gets.split.map(&:to_i)
  s[i].map!{|t| t-=1}
end

pp = gets.split.map(&:to_i)

ans = 0
(1 << n).times do |bit|
  # p ["bit", bit]
  ok = true
  m.times do |i|
    cnt = 0
    s[i].each do |t|
      cnt += 1 if bit & (1 << t) == 0
      # p [bit, 1 << t, bit & (1 << t)]
    end
    if cnt %2 != pp[i]
      ok = false
      break
    end
  end
  ans += 1 if ok 
end

puts ans

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

int main()
{
    int n, a = 0, b = 0, c = 0, d = 0;
    string s;
    cin >> n;
    while (n--)
    {
        cin >> s;
        if (s == "AC") a++;
        else if (s == "RE") d++;
        else if (s == "WA") b++;
        else c++;
    }
    cout << "AC x " << a << '\n';
    cout << "WA x " << b << '\n';
    cout << "TLE x " << c << '\n';
    cout << "RE x " << d << '\n';
}

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

b = [0]*n 
c = 0
d = 0

for j in range(m):
    c = a[j][0] - 1
    if n>=2 and c==0 and a[j][1]==0:
        b[c] = -1
    elif  b[c]==0 or b[c]==a[j][1]:
        b[c] = a[j][1]
    else:
        b[c] = -1

if n>=2 and b[0]==0:
    b[0] = 1

if b.count(-1)>0:
    print(-1)
else:
    for k in range(n):
        d = d + b[k]*(10**(n-k-1))
    print(d)

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

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    bool ok = true;
    for(int i = 0; i < n; i++) {
        if(a[i] % 2 == 0) {
            if(a[i] % 3 != 0 && a[i] % 5 != 0) {
                ok = false;
            }
        }
    }
    if(ok) {
        puts("APPROVED");
    } else {
        puts("DENIED");
    }
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>

using namespace std;

#define TRACE(x) cerr << #x <<  " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

#define X first
#define Y second

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

const int MAX = 1<<18;

char ss[MAX];
int p[2*MAX];
int n;
int cnt[26];

int main()
{
  scanf("%s", ss);
  n = (int) strlen(ss);

  REP(i, n) cnt[ss[i]-'a']++;
  ll rje = (ll) n * (n - 1) / 2 + 1;
  REP(i, 26)
    rje -= (ll) cnt[i] * (cnt[i] - 1) / 2;

  printf("%lld\n", rje);

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
  int x, a, b;
  cin >> x >> a >> b;

  int disA = 0, disB = 0;
  disA = abs(x - a);
  disB = abs(x - b);
  if(disA < disB) cout << "A" << endl;
  else cout << "B" << endl;
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> key;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j, b) {
      int c;
      cin >> c;
      --c;
      s |= 1 << c;
    }
    key.emplace_back(s, a);
  }

  vector<int> dp(1 << n, INF);
  dp[0] = 0;
  rep(s, 1 << n) {
    rep(i, m) {
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      dp[t] = min(dp[t], cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	int ans = 0;
	int c = 0;
	for (int i = 0;i < n - 1;i++) {
		if (h[i] >= h[i + 1]) {
			c++;
		}
		else {
			ans = max(ans, c);
			c = 0;
		}
	}
	ans = max(ans, c);
	cout << ans << endl;
}

Measured memory_bytes: 640
local w, h, n = io.read("*n", "*n", "*n")
local l, r, t, b = 0, w, 0, h
for i = 1, n do
  local x, y, a = io.read("*n", "*n", "*n")
  if a == 1 then
    l = math.max(l, x)
  elseif a == 2 then
    r = math.min(r, x)
  elseif a == 3 then
    t = math.max(t, y)
  else
    b = math.min(b, y)
  end
end
r = math.max(l, r)
b = math.max(t, b)
print((r - l) * (b - t))


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// stringToInt はstring型のスライスをint型のスライスにキャストする関数
func stringToInt(tSlice []string) (rSlice []int) {
	for _, str := range tSlice {
		num, _ := strconv.Atoi(str)
		rSlice = append(rSlice, num)
	}
	return
}

// sliceSum はint型のスライスの要素全体の和を求める関数
func sliceSum(tSlice []int) int {
	var sumNum int = 0
	for _, num := range tSlice {
		sumNum += num
	}
	return sumNum
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	var daysString string = scanner.Text()
	var days int = stringToInt(strings.Split(daysString, " "))[0]

	scanner.Scan()
	var hwList []int = stringToInt(strings.Split(scanner.Text(), " "))

	if days >= sliceSum(hwList) {
		fmt.Println(days - sliceSum(hwList))
	} else {
		fmt.Println("-1")
	}
}


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

struct Unionfind {
  // tree number
  vector<int> par;
  // tree rank
  vector<int> treerank;
  // constructor
  Unionfind(int n = 1) { stree(n + 1); }
  // make and initialization
  void stree(int n = 1) {
    par.assign(n, -1);
    treerank.assign(n, 0);
  }
  // search root
  int root(int x) {
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return 0;
    if(treerank[x] > treerank[y]) swap(x, y);
    if(treerank[x] == treerank[y]) ++treerank[y];
    par[y] -= size(x);
    par[x] = y;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

struct data {
  int from, to;
};

bool operator<(const data &l, const data &r) {
  if(l.from != r.from) return l.from < r.from;
  return l.to < r.to;
}

int n, m;
set<int> edge[100005];
vector<bool> num;
vector<data> ans;
queue<int> qu;
Unionfind uf;

void solve();
bool bfs();

int main() {
  cin >> n >> m;
  num.assign(n, 0);
  uf = Unionfind(n);
  for(int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if(!uf.issame(--a, --b)) {
      uf.uni(a, b);
      edge[a].insert(b);
      edge[b].insert(a);
    }
    else {
      ans.push_back({a, b});
      num[a] = !num[a];
    }
  }
  if(m % 2)
    cout << -1 << endl;
  else {
    solve();
    for(int i = 0; i < m; ++i)
      cout << ans[i].from + 1 << " " << ans[i].to + 1
           << endl;
  }
  return 0;
}

void solve() {
  for(int i = 0; i < n; ++i)
    if(edge[i].size() == 1) qu.push(i);
  bfs();
}

bool bfs() {
  while(!qu.empty()) {
    int now = qu.front();
    qu.pop();
    if(edge[now].size() == 0) {
      if(num[now]) {
        ans.erase(ans.begin(), ans.end());
        return 0;
      }
      continue;
    }
    vector<int> tmp;
    for(auto to : edge[now]) tmp.push_back(to);
    int tsize = tmp.size();
    for(int j = 0; j < tsize; ++j) {
      int to = tmp[j];
      if(num[now]) {
        ans.push_back({now, to});
        num[now] = 0;
      }
      else {
        ans.push_back({to, now});
        num[to] = !num[to];
      }
      edge[now].erase(to);
      edge[to].erase(now);
      if(edge[to].size() == 1) qu.push(to);
    }
  }
  return 1;
}

Measured memory_bytes: 17400
def cin():  return list(map(int,input().split()))

def gcd_(a, b):
    if a < b:  a, b = b, a
    if b == 0:  return a
    return gcd_(b, a % b)

def gcd(l):
    ans = 0
    for i in l:  ans = gcd_(ans, i)
    return ans

def lcm_(x,y):
    return (x * y) // gcd_(x, y)

def lcm(l):
    ans = l[0]
    for i in l:  ans = lcm_(ans, i)
    return ans

N = cin()[0]
v = cin()
lc = lcm(v)
ans = 0
INF = 10 ** 9 + 7
lc %= INF
for i in range(N):
    ans += lc * pow(v[i], INF - 2, INF)
    ans %= INF
print(int(ans))

Measured memory_bytes: 75072
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    ll n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);


    ll ans = 0;

    if(a==b){
        ans=1;
        cout << ans << endl;
        return 0;
    }
    if(a>b){
        cout << ans << endl;
        return 0;
    }
    if(n==1){
        cout << ans << endl;
        return 0;
    }

    

    ans = (n-2)*b - (n-2)*a + 1;
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int mod=998244353;
const int MAXN=305;
const int MAXM=305*305*2;
const int zero=90005;
//const int zero=5;
int f[MAXN][MAXM][3];
int n,a[MAXN],g[MAXN][MAXM];
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int main()
{
	n=read();
	int sum=0;
	for(int i=1;i<=n;i++)a[i]=read(),sum+=a[i];
	int ans=1;
	for(int i=1;i<=n;i++)ans=1LL*ans*3%mod;
	f[0][zero][0]=f[0][zero][1]=f[0][zero][2]=1;
	g[0][zero]=1;
	int mx=zero+sum,mn=zero-sum;
	
	for(int i=1;i<=n;i++)
		for(int j=mx;j>=mn;j--)
			{
				if(j+a[i]<=mx)ad(g[i][j],g[i-1][j+a[i]]%mod);
				if(j-a[i]>=mn)ad(g[i][j],g[i-1][j-a[i]]%mod);
			}
	for(int i=1;i<=n;i++)
		for(int j=mx;j>=mn;j--)
			for(int k=0;k<=2;k++)
			{
				if(j+a[i]<=mx)ad(f[i][j][k],f[i-1][j+a[i]][k]%mod);
				if(j-a[i]>=mn)ad(f[i][j][k],f[i-1][j-a[i]][k]*2%mod);
			}
	sum=0;
	for(int i=mn;i<=zero;i++)
		for(int k=0;k<=2;k++)ad(sum,f[n][i][k]);
	dl(sum,1LL*g[n][zero]*3%mod);
	dl(ans,sum);
	pr2(ans);
	return 0;
}



Measured memory_bytes: 875904
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

// DPを使う方法
//  DP[i][j] : S[i:] と S[j:] の最長共通連続文字列

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector< vector<int> > DP(N+2, vector<int>(N+2,0));

  int cmax = 0;
  for( int i= N-1; i>=0; --i ) {
    for( int j= N-1; j>i; --j ) {
      if ( S[i] == S[j] ) DP[i][j] = max( DP[i][j], DP[i+1][j+1] + 1);
      else DP[i][j] = 0;
      cmax = max( cmax, min(DP[i][j],j-i) );
//  for( int i=0; i<N; ++i ) {
//    for( int j=i+1 ; j<N; ++j ) {
//      if ( S[i] == S[j] ) DP[i+1][j+1] = max( DP[i+1][j+1], DP[i][j] + 1);
//      else DP[i+1][j+1] = 0;
//      cmax = max( cmax, min(DP[i+1][j+1],j-i) );
    }
  }
  cout << cmax << endl;
}


Measured memory_bytes: 100224
#include<stdio.h>
int main()
{
	int x[25556], cnt = 0;
	while (1)
	{
		cnt++;
		scanf("%d", &x[cnt]);
		if (x[cnt] == 0) break;
	}
	cnt = 0;
	while (1)
	{
		cnt++;
		if (x[cnt] == 0) break;
		else printf("Case %d: %d\n", cnt, x[cnt]);
	}
		
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = n / (a + b) * a;
    ans += min(n % (a + b), a);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>
#include<stdio.h>

using namespace std;

using ll = long long;

#define rep(i, n) for (ll i = 0; i < n; i++)

const ll INF = 1LL << 60;

typedef pair<ll, double> P;

bool pairCompare(const P & firstElof, const P & secondElof)
{
	return firstElof.second < secondElof.second;
}

ll b[61] = {0};
signed main() {
	ll m = pow(10, 9) + 7;
	ll n;
	cin >> n;
	vector<ll>a(n + 1);
	ll ans = 0;
	rep(i, n) {
		cin >> a[i];
	}
		rep(j, 61) {
	rep(i, n) {
			if ((a[i] >> j) & 1LL != 0) {
				b[j]++;
			}
		}
	}
	rep(i, 61) {
		ll c = b[i];
		ans += (c * (n - c)) % m * ((1LL << i) % m);
		ans %= m;
	}

	cout << ans;
}


Measured memory_bytes: 2560
import sys
readline = sys.stdin.readline
class Node:
    def __init__(self, sigma, depth):
        self.end = False
        self.child = [None] * sigma
        self.depth = depth
        self.count = 0
    def __setitem__(self, i, x):
        self.child[i] = x
    def __getitem__(self, i):
        return self.child[i]

class Trie():
    def __init__(self, sigma):
        self.sigma = sigma
        self.root = Node(sigma, 0)
    
    def add(self, S):
        vn = self.root
        vn.count += 1
        for cs in S:
            if vn[cs] is None:
                vn[cs] = Node(self.sigma, vn.depth + 1)
            vn = vn[cs]
            vn.count += 1
        vn.end = True

T = Trie(26)
N = int(readline())
Di = [None]*N

for i in range(N):
    S = list(map(lambda x: ord(x)-97, readline().strip()))
    Di[i] = S
    T.add(S)

Q = int(readline())
Ans = [None]*Q
Query = [[] for _ in range(N)]
for qu in range(Q):
    k, p = readline().strip().split()
    k = int(k)-1
    p = list(map(lambda x:ord(x)-97, p))
    pinv = [None]*26
    for i in range(26):
        pinv[p[i]] = i
    Query[k].append((qu, pinv))

for k in range(N):
    if not Query[k]:
        continue
    cost = [[0]*26 for _ in range(26)]
    geta = 0
    vn = T.root
    for si in Di[k]:        
        for ti in range(26):
            if si != ti and vn[ti] is not None:
                cost[si][ti] += vn[ti].count
        vn = vn[si]
        if vn.end:
            geta += 1
    L, P = map(list, zip(*Query[k]))
    M = len(P)
    for idx in range(M):
        res = 0
        invp = P[idx]
        for i in range(26):
            for j in range(26):
                if invp[i] > invp[j]:
                    res += cost[i][j]
        Ans[L[idx]] = res+geta
        
print('\n'.join(map(str, Ans)))     


Measured memory_bytes: 302824
#include<bits/stdc++.h>
#define mod 1000000007
#define ll  long long int
using namespace std;
int ans[3000][3000];
ll foo(ll a[],int i,int j)
{
	cout<<i<<" "<<j<<endl;
	if(j==(i+1)) return max(a[i],a[j]);
	if(i==j) return a[i];
	if(ans[i][j] !=(-1)) return ans[i][j];

	ans[i][j] = max(a[i]+ min(foo(a,i+1,j-1),foo(a,i+2,j)) , a[j] + min(foo(a,i,j-2),foo(a,i+1,j-1)));
	//cout<<i<<" "<<j<<" "<<ans[i][j]<<endl;
	return ans[i][j];
}
ll prevs[100001],curr[100001];
int  main()
{
	memset(prevs,0,sizeof(ll));
	memset(curr,0,sizeof(ll));

	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);

	for(ll i=0;i<=k;i++) prevs[i] = 1;
	for(ll i=0;i<n;i++)
	{
		curr[0] = 1;
		for(ll j=1;j<=a[i];j++) curr[j] = (prevs[j]+curr[j-1])%mod;

		for(ll p=a[i]+1;p<=k;p++)
		{
			ll x = p-a[i]-1;
			x = ((prevs[p] - prevs[x])+mod)%mod;
			curr[p] = curr[p-1] + x;
		}
		for(ll j=0;j<=k;j++) { prevs[j] = curr[j];}
		//cout<<endl;
	}
	cout<<(prevs[k]-prevs[k-1])%mod<<endl;
}


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

// using mint = modint1000000007;
// using mint = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int n, m;
    cin >> n >> m;
    vector<Int> a(m), b(m);
    dsu uf(n);
    for (Int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        uf.merge(a[i] - 1, b[i] - 1);        
    }
    print((Int)uf.groups().size() - 1);
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 9104
import java.io.*
import java.util.*

const val ROCK = 0
const val SCISSOR = 1
const val PAPER = 2
val HANDS = listOf(ROCK, SCISSOR, PAPER)
fun solve(N: Int, K: Int, R: Int, S: Int, P: Int, T: String) {
    fun score(index: Int, rsp: Int) = when {
        (T[index] == 'r' && rsp == PAPER) -> P
        (T[index] == 's' && rsp == ROCK) -> R
        (T[index] == 'p' && rsp == SCISSOR) -> S
        else -> 0
    }
    // Kで割ったあまりごとに配列を分ける -> それぞれの最大値のsumを求める
    fun maximum(remainder: Int): Int{
        // dp[i][j] = remainder + j * K回目にiを出して出せる最高得点
        // remainder + size * K <= N - 1
        val size = (N - remainder - 1) / K + 1
        val dp = Array(3) { IntArray(size) }
        for (hand in HANDS) dp[hand][0] = score(remainder, hand)
        for (i in 1 until size) {
            for (hand in HANDS) {
                dp[hand][i] = Math.max(
                        dp[(hand + 1) % 3][i-1] + score(remainder + i*K , hand),
                        dp[(hand + 2) % 3][i-1] + score(remainder + i *K, hand)
                    )
            }
        }
        // println(dp.contentDeepToString())
        return HANDS.map{ hand -> dp[hand].last() }.max()!!
    }
    val ans = (0..K-1).map{ maximum(it) }.sum()
    println(ans)
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val K = sc.next().toInt()
    val R = sc.next().toInt()
    val S = sc.next().toInt()
    val P = sc.next().toInt()
    val T = sc.next()
    solve(N, K, R, S, P, T)
}


Measured memory_bytes: 46204
/*/ Author: arl17 /*/
#include<bits/stdc++.h>
using namespace std;

/*/---------------------------Defines----------------------/*/
 
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(v) (v).begin(),(v).end()

typedef pair<ll,ll> pi;
/*/-----------------------Modular Arithmetic---------------/*/
 
const int mod=1e9+7;
inline int add(int x,int y){
    x+=y;
    if (x>=mod) return x-mod;
    return x;
}
inline int sub(int x,int y){
    x-=y;
    if (x<0) return x+mod;
    return x;
}
inline int mul(int x,int y){
    return (x*1ll*y)%mod;
}
inline int power(int x,int y){
    int ans=1;
    while(y){
        if (y&1) ans=mul(ans,x);
        x=mul(x,x);
        y>>=1;
    }
    return ans;
}
inline int inv(int x){
    return power(x,mod-2);
}
/*/-----------------------------Code begins----------------------------------/*/


void solve()
{
	ll n,m,i,j,k,x,y,z,l,r;
	cin>>n;
	if(n%1000)
	{
	
		cout<<1000-n%1000<<endl;
	
		}
		else
		{
			cout<<"0"<<endl;
			}	
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}



Measured memory_bytes: 3664
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    const MOD: i64 = 1000000007;
    let (n, k): (usize, usize) = (sc.read(), sc.read());

    let mut cnt = vec![0i64; k + 1];
    cnt[k] = 1;

    for x in (1..k).rev() {
        cnt[x] = pow(k / x, n, MOD as usize) as i64;

        for i in 2.. {
            if x * i > k {
                break;
            }
            cnt[x] = (cnt[x] - cnt[x * i] + MOD) % MOD;
        }
    }

    let mut ans = 0;
    for x in 1..=k as i64 {
        ans = (ans + x * cnt[x as usize] % MOD) % MOD;
    }
    println!("{}", ans);
}

fn pow(x: usize, n: usize, m: usize) -> usize {
    let mut res = 1;
    let mut n = n;
    let mut pow = x;
    while n > 0 {
        if n & 1 != 0 {
            res = res * pow % m;
        }
        pow = pow * pow % m;
        n >>= 1;
    }
    res
}


Measured memory_bytes: 2824
object Main extends App {
	val Array(a, b, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	if(a > x){
		println("NO")
	}else if(a < x){
		if(a + b >= x){
			println("YES")
		}else{
			println("NO")
		}
	}else{
		println("YES")
	}
}

Measured memory_bytes: 25524
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    // int N = 200000, K = 200000;
    int N, K; cin >> N >> K;
    vector<int> A(N+1);
    for(int i=0; i<N; i++) cin >> A[i];
    
    auto solve_naive = [&]() {
        int cnt = 0;
        while(K--) {
            cnt++;
            vector<int> B(N+1);
            for(int i=0; i<N; i++) {
                int mi = max(0, i-A[i]);
                int ma = min(N, i+A[i]+1);
                B[mi]++;
                B[ma]--;
            }
            for(int i=1; i<=N; i++) B[i] += B[i-1];

            swap(A, B);
            if(count(A.begin(), A.end(), N) == N) {
                fprintf(stderr, "full in %d\n", cnt);
                break;
            }
        }
        for(int i=0; i<N; i++) printf("%d%c", A[i], " \n"[i + 1 == N]);
    };

    solve_naive();
    return 0;
    
    vector<int> B(N+1);
    for(int i=0; i<N; i++) {
        int l = max(0, i - A[i] - (K - 1));
        int r = min(N, i + A[i] + (K - 1) + 1);
        B[l]++, B[r]--;
        fprintf(stderr, "l = %d, r = %d\n", l, r);
    }
    for(int i=1; i<=N; i++) B[i] += B[i-1];

    for(int i=0; i<N; i++) printf("%d%c", B[i], " \n"[i + 1 == N]);
    return 0;
}


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

const string NO = "IMPOSSIBLE";

void solve(long long A, long long B){
    if ((A + B) % 2 == 0) {
        cout << (A + B) / 2 << '\n';
    } else {
        cout << NO << '\n';
    }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256