akhauriyash/Code-Regression huggingface dataset:
let () =
  let n = read_int () in
  for _ = 0 to n - 1 do
    let s = read_line () in
    let t = read_line () in
    let l = String.length s in
    let m = String.length t in
    if l > 80 || m > 80 then print_endline "overflow"
    else if l < 10 && m < 10 then int_of_string s + int_of_string t |> Printf.printf "%d\n"
    else begin
      let x = Big_int.big_int_of_string s in
      let y = Big_int.big_int_of_string t in
      let p = Big_int.add_big_int x y |> Big_int.string_of_big_int in
      if String.length p > 80 then print_endline "overflow"
      else print_endline p
    end
  done

Measured memory_bytes: 2188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long LL;
using namespace std;
const LL INF=10000000000000000000000;


int main(){
  int N,K;
  cin >> N >> K;
  LL dp[N];
  rep(i,N) dp[i]=INF;
  int A[N];
  rep(i,N) cin >> A[i];
  dp[0]=0;
  rep(i,N){
    if(i-K<0){
      for(int j=1;j<=i;j++)
        chmin(dp[i],dp[i-j]+abs(A[i]-A[i-j]));
    }
    else{
      for(int j=1;j<=K;j++)
        chmin(dp[i],dp[i-j]+abs(A[i]-A[i-j]));
    }
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
int a,b;
  cin >> a >> b;
  cout << (a-1) * (b-1) << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import deque
import math


def inputIntList():
  return [int(s) for s in input().split()]


def inputInt():
  return int(input())


def main():
  H = inputInt()
  cnt = 0
  ans = 0
  while H:
    H = H >> 1
    ans += 2 ** cnt
    cnt += 1

  return ans


if __name__ == "__main__":
  print(main())


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long res[2001][2001];
int main()
{
	cin>>n>>k;
	for(int i=0;i<=max(k,n-k+1);i++)
	{
		res[i][0]=1;
		for(int j=1;j<=i;j++)
		{
			res[i][j]=(res[i-1][j-1]+res[i-1][j])%1000000007;
		}
	}
	for(int i=1;i<=k;i++)
	{
		cout<<(res[k-1][i-1]*res[n-k+1][i])%1000000007<<endl;
	}
	return 0;
}

Measured memory_bytes: 30080
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    op=str(op)
    
    if op=="+" :
        print(a+b)
    
    elif op=="-":
        print(a-b)
    
    elif op=="*":
        print(a*b)
        
    elif op=="/":
        print(int(a/b))
        
    else:
        break
    


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

int main(void){
  long long n,k;
  cin >> n >> k;
  long long ans=k;
  if(n==1){
    cout << ans << endl;
  }
  else{
  for(long long i=1;i<n;i++){
    ans*=k-1;
  }
  cout << ans << endl;
  }
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll a,b,c;
    Scll3(a,b,c);

    ll ans = 0;
    if( a%2 && b%2 && c%2 ){
        ans = min( a*b, b*c );
        ans = min( ans, c*a );
    }

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

    return 0;
}



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

typedef long long ll;

int main()
{
    ll n, a[5];
    while(cin>>n) {
        ll temp;
        for(int i=0;i<5;i++){
            cin>>a[i];
            if(i==0){
                temp = a[0];
            }
            else{
                temp = min(temp, a[i]);
            }
        }
        if(temp>=n){
            cout<<5<<endl;
        }
        else{
            ll ans = n/temp;
            if(n%temp != 0) {
                ans++;
            }
            cout<<ans+4<<endl;
        }

    }
    return 0;
}


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


long long countOrderedPairs(int N) 
{ 
	// Initialize count to 0 
	long long count_pairs = 0; 

	// count total pairs 
	for (long long i = 1; i <= sqrt(N - 1); ++i) { 
		for (long long j = i; j * i < N; ++j) 
			++count_pairs; 
	} 

	// multiply by 2 to get ordered_pairs 
	count_pairs *= 2; 

	// subtract redundant pairs (a, b) where a==b. 
	count_pairs -= (long long)(sqrt(N - 1)); 

	// return answer 
	return count_pairs; 
} 

// Driver code 
int main() 
{ 
	long long N ; 

	// function call to print required answer 
    cin>>N;
	cout << countOrderedPairs(N)<<endl;; 

	return 0; 
} 


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string A,B;
  cin >> A >> B;
  int a=A.size();
  int b=B.size();
  if(a>b){cout << "GREATER" << endl;}
  else if(a<b){cout << "LESS" << endl;}
  else{
    if(A==B){cout << "EQUAL" << endl;}
    else if(A>B){cout << "GREATER" << endl;}
    else{cout << "LESS" << endl;}
  }
}
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 10010
#define MAXY 2010
#define INF 0x3f3f3f
const int MOD=1e9+7;
const double eps=1e-8;
typedef long long ll;
//orz yht
using namespace std;
int n;
string s1,s2;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>s1>>s2;
	for(int i=0;i<n;i++)
	cout<<s1[i]<<s2[i];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define len(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define pb push_back

using namespace std;

int num(vector<int>& vec)
{
    int res = 0;
    int d = 1;
    rep(i,len(vec)){
        res += vec[i]*d;
        d *= 10;
    }
    return res;
}

int main()
{
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0 && m == 0){
            break;
        }
        int loop = 1;
        map<int,int> mp;
        mp[n] = 0;
        while(1){
            int id = 0;
            vector<int> vec;
            while(n){
                vec.pb(n%10);
                n /= 10;
                id++;
            }
            rep(i,m-id){
                vec.pb(0);
            }
            vector<int> a = vec, b = vec;
            sort(all(a)), sort(all(b),greater<int>());
            int res = num(a)-num(b);
            if(mp.find(res) == mp.end()){
                mp[res] = loop++;
                n = res;
            }else{
                cout << mp[res] << " " << res << " " << loop-mp[res] << "\n";
                break;
            }
        }
    }
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main() {
    // input
    int n;
    cin >> n;
 
    int a[n];
    int maximum = 0;
    int maximum2 = 0;
    bool isMaximums = false;
    REP(i,n){
        cin >> a[i];
        if(a[i] > maximum) maximum = a[i];
    }

    int max_cnt = 0;
    REP(i,n){
        if(a[i] == maximum){
            ++max_cnt;
            if(max_cnt > 1){
                isMaximums = true;
                break;
            }
        } else {
            if(a[i] > maximum2) maximum2 = a[i];
        }
    }

    // logic
    REP(i,n){
        if(maximum > a[i] || isMaximums) cout << maximum << endl;
        else cout << maximum2 << endl;
    }
}

Measured memory_bytes: 2432
using namespace std;

#include<iostream>



int main(){
    int A, B, C, D, x = 0;
    cin >> A >> B >> C >> D;

    if (A <= C && C <= B && B <= D) {
        x = B - C;
    }
    else if (A <= C && C <= B && D <= B) {
        x = D - C;
    }
    else if(C <= A && A <= D && B <= D){
        x = B - A;   
    }
    else if(C <= A && A <= D && D <= B){
        x = D - A;     
    }
    
    cout << x;
    return 0;
    

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int in,out,a,b,c,d;
	
	while(scanf("%d", &in) != EOF){
		out = 0;
		
		for(a = 0; a < 10; a++){
			for(b = 0; b < 10; b++){
				for(c = 0; c < 10; c++){
					for(d = 0; d < 10; d++){
						if((a+b+c+d) == in){
							out++;
						}
					}
				}
			}
		}
		
		printf("%d\n", out);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

int main()
{
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    a += b;
    c += d;

    if (a > c)
        cout << "Left" << endl;
    else if (a == c)
        cout << "Balanced" << endl;
    else
        cout << "Right" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout<< b <<endl;
        return 0;
    }
    if(a >= 6 && a <= 12){
        cout << b / 2 <<endl;
        return 0;
    }
    cout << 0 <<endl;
}


Measured memory_bytes: 256
#include <string.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>
#include<string.h>
#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)

using namespace std;

int main(void){
	char str[100001];
	char s[100001];
	bool flag = false;
	int cnt = 0;
	
	scanf("%s" ,str);
	int str_len = strlen(str);
	int s_len = 0;
	rep(i,str_len){
		if(str[i]=='x'){
			if(str_len%2 && i == str_len/2){}
			else {cnt++;}
		}
		else {
			s[s_len++] = str[i];
		}
	}
	rep(i,s_len/2){
		if(s[i] != s[s_len-i-1]){
			flag = true;
			break;
		}
	}
	int count = 0;
	if(!flag){
		int i= 0;
		int j = str_len - 1;
		while(i<j){
	//	cout << str_len << " " << i << " " << j << endl;
			if(str[i] != str[j]){
				if(str[i] == 'x') {
					i++;
					count++;
				}
				else {
					j--;
					count++;		
				}
			}
			else{
				i++;
				j--;
			}
		}
		cout << count << endl;
	}
	else cout << "-1" << endl;
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define reverse(s) reverse(s.begin(),s.end())

int main(){
    int n,m;
    cin >> n >> m;

    map<int,int> a;
    rep(i,m)    a[i];
    rep(i,n){
        int k;  cin >> k;
        rep(i,k){
            int A;  cin >> A;
            A--;
            a[A]++;
        }
    }

    int ans(0);
    rep(i,m){
        if(a[i]==n){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
s = list(input())
k = int(input())
cnt = 0
ans = ''
for i in range(len(s)):
    cnt = (ord('z') - ord(s[i]) + 1) % 26
    if cnt <= k:
        k -= cnt
        s[i] = 'a'
s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))
print(*s, sep='')


Measured memory_bytes: 6968
#include <bits/stdc++.h>
using namespace std;
#define maxn 55
#define maxm 125005
#define int long long
#define INF 1e9 + 10
int n, X, D, ans, cnt, dp[maxm];
int w[maxn], val[maxn], pos[maxn];
int tot, V[maxn * maxn], W[maxn * maxn];
     
int read()
{
    int x = 0, k = 1;
    char c; c = getchar();
    while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * k;
}
     
struct edge
{
    int cnp, to[maxn], last[maxn], head[maxn];
    edge() { cnp = 1; }
    void add(int u, int v) 
    { to[cnp] = v, last[cnp] = head[u], head[u] = cnp ++; }
}E1;
     
void dfs(int u)
{
    val[u] = 1;
    for(int i = E1.head[u]; i; i = E1.last[i])
    {
        int v = E1.to[i];
        dfs(v);
        w[u] += w[v]; val[u] += val[v];
    }
    cnt += val[u] * n; pos[u] = u;
}
     
bool cmp(int x, int y) { return val[x] * w[y] > val[y] * w[x]; }
void Get_min(int &x, int y) { x = x < y ? x : y; }
     
signed main()
{
    n = read(), X = read(), D = read();
    w[1] = read();
    for(int i = 2; i <= n; i ++)
    {
        w[i] = read(); int x = read();
        E1.add(x, i);
    }
    dfs(1);
    sort(pos + 1, pos + n + 1, cmp);
    int tmp = min(n, D);
    for(int i = 1; i <= cnt; i ++) dp[i] = INF;
    for(int i = 1; i <= n; i ++)
    {
        int len = 1, lim = tmp;
        while(lim >= len)
        {
            V[++ tot] = len * val[pos[i]];
            W[tot] = len * w[pos[i]];
            lim -= len, len <<= 1;
        }
        if(lim) V[++ tot] = lim * val[pos[i]], W[tot] = lim * w[pos[i]];
    }
    for(int i = 1; i <= tot; i ++)
        for(int j = cnt; j >= V[i]; j --)
                Get_min(dp[j], dp[j - V[i]] + W[i]); // k件物品 
    int ans = 0;
    for(int i = 0; i <= cnt; i ++)
       {
        if(dp[i] > X) continue;
        int ret = i, left = X - dp[i];
        for(int j = 1; j <= n; j ++)
        {
            int tem = pos[j], used = min(max(D - n, 0LL), left / w[tem]);
            if(tem == 1) used = left / w[tem];
            left -= w[tem] * used;
            ret += val[tem] * used;
        }
        ans = max(ans, ret);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;


public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	//static long INF = (Long.MAX_VALUE/2);
	static int mod = (int)(1e9+7);
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char mat[][] = new char[h][w];
        int dp[][] = new int[h][w];
        for(int i = 0; i < h; i++)
        {
        	mat[i] = sc.nextLine().toCharArray();
        }
        dp[h-1][w-1] = 1;
        for(int i = h-1; i >= 0; i--)
        {
        	for(int j = w-1; j >= 0; j--)
        	{
        		if(mat[i][j] == '#')
        			dp[i][j] = 0;
        		
        		else if(i < h-1 && j < w-1)
        			dp[i][j] = (dp[i+1][j]+dp[i][j+1])%(mod);
        		
        		else if(i == h-1 && j != w-1)
        			dp[i][j] = dp[i][j+1]%(mod);
        		
        		else if(i != h-1 && j == w-1)
        			dp[i][j] = dp[i+1][j]%(mod);
        		
        	}
        }
        
        out.println(dp[0][0]);
        out.close();
	}

}


Measured memory_bytes: 35256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll N;
  cin>>N;
  string s="";
  while(N>=1){
    ll a=N%26;
    N/=26;
    if(a==0){
      a=26;
      N--;
    }
    s+=(char)('a'+a-1);
    
  }
  reverse(s.begin(),s.end());
  cout<<s;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9e18
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define MAX_N 200000

#define M 1'000'000'007
int n, k;
ll g_arr[MAX_N + 2];
ll h_arr[MAX_N + 2];

void init() {
    rep(i, MAX_N + 2) {
        g_arr[i] = (i == 0) ? 1 : (g_arr[i - 1] + i) % M;
        h_arr[i] = (i == 0) ? 0 : (h_arr[i - 1] + i) % M;
    }
    rep(i, MAX_N + 2) { g_arr[i] = (i == 0) ? 1 : (g_arr[i] + g_arr[i - 1]) % M; }
}

int main() {
    cin >> n >> k;
    init();
    cout << (g_arr[n + 1 - k] + ((k - 1) * h_arr[n + 1 - k]) % M) % M << endl;
    return 0;
}

Measured memory_bytes: 6736
#include"iostream"
#include"algorithm"

using namespace std;
typedef long long int llint;
llint N;
llint A, B;

int main() {
	cin >> N;
	cin >> A >> B;
	llint ans = 0;
	ans += (N / (A + B)) * A;
	ans += min(A, N % (A + B));
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
sum = 0
A = [int(num) for num in input().split()]

counter_plus = 0
is_plus = True
sum = 0
for i in range(n):
  sum += A[i]
  if is_plus == True:
    if sum < 1:
      div = 1 - sum
      sum += div
      counter_plus += div
  else:
    if sum > -1:
      div = -1 -sum
      sum += div
      counter_plus -= div
  is_plus = not(is_plus)

counter_minus = 0
is_plus = False
sum = 0
for i in range(n):
  sum += A[i]
  if is_plus == True:
    if sum < 1:
      div = 1 - sum
      sum += div
      counter_minus += div
  else:
    if sum > -1:
      div = -1 -sum
      sum += div
      counter_minus -= div
  is_plus = not(is_plus)  
print(min(counter_plus, counter_minus))

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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 (b<a) { a=b; return 1; } return 0; }

int main() {
    vector<ll> v(3);
    rep(i, 3) cin >> v.at(i);

    ll odd = 0, even = 0;
    rep(i, 3) {
        if (v.at(i) % 2 == 0) even++;
        else odd++;
    }

    ll ans = 0;
    if (odd == 2) {
        ans++;
        rep(i, 3) {
            if (v.at(i) % 2 != 0) v.at(i)++;
        }
    } else if (even == 2) {
        ans++;
        rep(i, 3) {
            if (v.at(i) % 2 == 0) v.at(i)++;
        }
    }

    ll ma = max(v.at(0), max(v.at(1), v.at(2)));
    rep(i, 3) ans += (ma - v.at(i)) / 2;
    cout << ans << endl;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  int cnt = 0, ans = 0;
  for (int i = 1, t; i <= n; i++) {
    cin >> t;
    if (t == i) {
      cnt++;
    } else {
      ans += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  ans += (cnt + 1) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
N = int(input())
score_dic = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(N):
    sc = input()
    score_dic[sc] += 1
print('AC x ' + str(score_dic['AC']))
print('WA x ' + str(score_dic['WA']))
print('TLE x ' + str(score_dic['TLE']))
print('RE x ' + str(score_dic['RE']))


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    string S; cin >> S;
    vector<int> v(3);
    for(int i=0;i<S.size();i++)v[S[i]-'a']++;
    int MAX = *max_element(v.begin(), v.end());
    int MIN = *min_element(v.begin(), v.end());
    if(MAX-MIN <=1) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N; cin >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  // sort(rall(A));
  // A ...win
  //
  // AA ...lose
  //
  // AAA ...win
  //
  // A
  // B ...win
  //
  // AA
  // B    ...win
  //
  // AAA
  // B   ...win
  //
  // AAAA
  // B   ...win
  //
  // AA
  // B
  // C  ...win
  //
  // AA
  // B
  // C
  // D  ...win
  //
  // AA
  // BB ...lose
  //
  // AAA
  // BB  ...win
  //
  // AA
  // BB
  // C  ...win
  //
  // AA
  // BB
  // CC ...lose
  //
  // AAAA
  // BB   ...lose
  bool win = false;
  rep(i,N) if(A[i]%2==1) win = true;
  if(win) cout << "first" << endl;
  else cout << "second" << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;

priority_queue <pll> P, Q;
ll A[101010], B[101010], C[101010];
ll n, k, s, p, q;

ll gcd(ll a, ll b) { for(; b; swap(a, b)) a %= b; return a; }
void update(ll a, ll b) { if(p * b < a * q) p = a, q = b; }

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

	ll i, x;

	cin >> n;

	for(i = 0; i < n; i ++){
		cin >> A[i] >> B[i];
		if(A[i] < B[i]){
			s += B[i] - A[i];
			P.emplace(-B[i], i);
			C[i] = 1;
		}
		else Q.emplace(-A[i], i);
	}

	for(k = 0; ; k ++){
		if(!P.empty() && (Q.empty() || P.top() > Q.top())){
			tie(x, i) = P.top();
			if(s + x < 0) break;
			P.pop();
		}
		else if(!Q.empty()){
			tie(x, i) = Q.top();
			if(s + x < 0) break;
			Q.pop();
		}
		else break;
		s += x; C[i] = 2;
	}

	p = 0; q = 1;

	for(i = 0; i < n; i ++){
		if(C[i] == 0){
			if(s + B[i] - A[i] >= 0){
				update(s + B[i] - A[i], B[i]);
			}
		}
		else if(C[i] == 1) update(s, B[i]);
		else{
			if(!P.empty() && (Q.empty() || P.top() > Q.top())){
				x = P.top().first;
			}
			else if(!Q.empty()){
				x = Q.top().first;
			}
			else x = -1e18;
			if(s + B[i] + x >= 0){
				update(s + B[i] + x, B[i]);
			}
		}
	}

	p += q * k; q *= n;
	x = gcd(p, q);
	p /= x; q /= x;

	cout << p << " " << q << "\n";

	return 0;
}

Measured memory_bytes: 5236
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n,w;
	cin>>n>>w;
	vector<ll> we,v;
	for(ll i=0;i<n;i++)
	{
		ll weight,value;
		cin>>weight>>value;
		we.push_back(weight);
		v.push_back(value);
	}
	vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=w;j++)
		{
			if(j-we[i-1]>=0)
				dp[i][j]=max(v[i-1]+dp[i-1][j-we[i-1]],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][w];

}

Measured memory_bytes: 80256
#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>;


int main()
{
    int n; 
    string s;
    cin >> n >> s;

    rep(i,s.size()) {
        rep(j,n) {
            if(s[i] == 'Z') s[i] = 'A';
            else s[i]++;
        }
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> dist(n, vector<int>(n,INF));
  rep(i,n) dist[i][i] = 0;
  rep(i,m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    dist[a][b] = dist[b][a] = c;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(dist[i][j], dist[i][k]+dist[k][j]);
  vector<vector<int>> dist2(n, vector<int>(n,INF));
  rep(i,n)rep(j,n) {
    if (dist[i][j] <= l) dist2[i][j] = 1;
  }
  rep(k,n)rep(i,n)rep(j,n) chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
  int q;
  cin >> q;
  rep(qi,q) {
    int s, t;
    cin >> s >> t;
    --s; --t;
    int ans = dist2[s][t]-1;
    if (dist2[s][t] == INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){

    vector<int> d = {0, 1, 0, -1, 0};

    auto f = [d]{
        int h, w;
        cin >> h >> w;
        if(!h)
            return 0;
        vector<string> s(h);
        for(auto& x : s)
            cin >> x;
        vector<bitset<100>> bs(h);

        function<void(int, int)> g = [&](int x, int y){
            bs[x].set(y);
            for(int i = 0; i < 4; ++i){
                int ax = x + d[i], ay = y + d[i + 1];
                if(ax < 0 || ay < 0 || ax >= h || ay >= w || bs[ax][ay] || s[x][y] != s[ax][ay])
                    continue;
                g(ax, ay);
            }
        };

        int ans = 0;

        for(int i = 0; i < h; ++i)
            for(int j = 0; j < w; ++j)
                if(!bs[i][j])
                    ++ans, g(i, j);
        cout << ans << endl;
        return 1;
    };
    while(f());
}



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

int main(){
  int w,h;
  char map[100][100];
  int x,y;

  while(1){
    cin >> h >> w;
    if(!h && !w)break;

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

    x = 0;
    y = 0;
    int count = 0;
    int flag = 0;
    while(1){
      count++;
      if(map[y][x] == '^')y--;
      if(map[y][x] == '>')x++;
      if(map[y][x] == 'v')y++;
      if(map[y][x] == '<')x--;
      if(map[y][x] == '.')break;
      if(count>h*w){
	flag = 1;
	break;
      }
    }
    if(flag)cout << "LOOP" << endl;
    else cout << x << " " << y << endl;
  }
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a, b; cin >> a >> b;
  int ans = 0;
  REP(_, 2) {
    if (a > b) {
      ans += a;
      --a;
    } else {
      ans += b;
      --b;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
N,K,Q = map(int,input().split())

kq = K-Q
P = [0]*N
for i in range(Q):
    a = int(input())
    P[a-1] += 1
    
for i in range(N):
    p = P[i]
    if P[i]+kq > 0:
        print('Yes')
    else:
        print('No')


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  int t = m / n;

  RFOR (i, 1, t + 1) {
    if (m % i == 0) {
      printf("%d\n", i);
      exit(0);
    }
  }
}


Measured memory_bytes: 256
S = input()
count =0
if 'S' in S:
  if 'N' not in S:
    count = 1
if 'N' in S:
  if 'S' not in S:
    count = 1
if 'W' in S:
  if 'E' not in S:
    count = 1
if 'E' in S:
  if 'W' not in S:
    count = 1
if count ==1:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 9144
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main()
{
    long long n,d,c=0,x,y;
    cin>>n>>d;
     double  an;
    while(n--)
    {
        cin>>x>>y;
        an=sqrt(x*x+y*y);
        if(an<=d)
        {
            c++;
        }
    }

    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main(){
    int a[3];
    for (int i=0; i<3; i++) cin >> a[i];
    sort(a, a+3);
    cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
    return 0;
}


Measured memory_bytes: 3068
// AOJ 1056
#include<cstdio>
#include<vector>
#include<cmath>
#define repi(i,a,b) for(int i=(a);i<(b);++i)

const int MAX_N = 100001, ALPHA_N = 10;

void solve( double *exp )
{
	double prob[ALPHA_N], nprob[ALPHA_N];

	exp[0] = 0; exp[1] = 1; exp[2] = 1.5;

	prob[0] = 1;
	repi( i, 1, ALPHA_N )
	{
		double e2 = 1.0/((double)(1<<i));
		prob[i] = e2*prob[i-1];
		nprob[i] = (1-e2)*prob[i-1];
	}

	repi( n, 3, MAX_N )
	{
		exp[n] = 0;
		for( int j = 1; j < ALPHA_N && n-j-1 >= 0; ++j )
			exp[n] += nprob[j]*(j+exp[n-j-1]);
		if( n-1 < ALPHA_N )
			exp[n] += n*prob[n-1];
	}

	return;
}

int main()
{
	double ans[MAX_N];
	solve( ans );

	int n;
	while( scanf( "%d", &n ), n )
		printf( "%f\n", ans[n] );

	return 0;
}

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

int main(){
    int mod=1000000007;
    int n,k,ans,tmp=0;
    scanf("%d %d",&n,&k);
    vector<int> a(n);
    for (int i=0;i<n;i++) {
        scanf("%d",&a[i]);
        if (a[i]==k) {
            printf("POSSIBLE\n");
            return 0;
        }
        if (i>0) tmp=max(tmp,a[i-1]);
    }

    if (tmp<k) {
        printf("IMPOSSIBLE\n");
        return 0;
    }
    sort(a.begin(),a.end());
    tmp-=k;
    for (int i=1;i<n;i++) {
        int t=a[i]-a[i-1];
        if (t) tmp%=t;
    }

    printf("%s\n",tmp==0?"POSSIBLE":"IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 640
import sys

a,b = map(int,input().split())
low = int(min(a//0.08,b//0.1))
high = int(max((a+1)//0.08,(b+1)//0.1))
for i in range(low,high+1):
  if int(i*0.08)==a and int(i*0.1)==b:
    print(i)
    sys.exit()
print(-1)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
struct valt{
	long long p0, p1, sum1, mdiff;
	valt(){
		p0 = 0;
		p1 = 0;
		sum1 = 0;
		mdiff = 0;
	}
	valt(long long a, long long b){
		p0 = a; p1 = b;
		sum1 = p1;
		mdiff = p1 - p0;
	}
	valt operator + (valt other){
		valt ans;
		ans.sum1 = sum1 + other.sum1;
		ans.mdiff = max(mdiff, other.mdiff);
		return ans;
	}
};
struct tree{
	multiset<long long> values;
	long long sum1;
	void add(valt a){
		sum1 += a.sum1;
		values.insert(a.mdiff);
	}
	void rem(valt a){
		sum1 -= a.sum1;
		values.erase(values.find(a.mdiff));
	}
	valt getFull(){
		valt ans;
		ans.sum1 = sum1;
		if(!values.empty()) ans.mdiff = *(--values.end());
		return ans;
	}
};
const int maxn = 100100;
vector<int> tr[maxn];
tree mtree[maxn];
char s[maxn];
int ty[maxn], ms[maxn];
long long d[2][maxn];
void add(int cur, valt val){
	mtree[cur].add(val);
}
void rem(int cur, valt val){
	mtree[cur].rem(val);
}
void calc(int cur, int par, int sons){
	int ru = par != -1;
	int letdown = max(sons - 1, 0);
	valt incur = mtree[cur].getFull();
	d[0][cur] = sons + letdown + incur.sum1 - incur.mdiff + ((ty[cur] + letdown + ru)%2);
	d[1][cur] = 2 * sons + incur.sum1 + ((ty[cur] + sons + ru)%2);
}
void solve(int cur, int par){
	int sons = 0;
	for(int nxt : tr[cur]){
		if(nxt == par) {
			continue;
		}
		solve(nxt, cur);
		valt pnxt = valt(d[0][nxt], d[1][nxt]);
		add(cur, pnxt);
		sons++;
	}
	ms[cur] = sons;
	calc(cur, par, sons);
}
void fix(int cur, int par){
	if(par != -1){
		valt before = valt(d[0][cur], d[1][cur]);

		rem(par, before);
		calc(par, cur, tr[par].size() - 1);

		add(cur, valt(d[0][par], d[1][par]));
		calc(cur, -1, tr[cur].size());

		add(par, before);

		calc(par, -1, tr[par].size());
	}
	for(int nxt : tr[cur]){
		if(nxt == par) continue;
		fix(nxt, cur);
	}
}
int deg[maxn];
set<int> pk[maxn], stl;
int main(){
	int n;
	scanf("%d", &n);
	for(int e = 0; e < n - 1; e++){
		int x, y; scanf("%d %d", &x, &y); x--; y--;
		pk[x].insert(y);
		pk[y].insert(x);
		deg[x]++; deg[y]++;
	}
	scanf("%s", s);
	for(int e = 0; e < n; e++) ty[e] = s[e] == 'W';
	queue<int> q;
	for(int e = 0; e < n; e++) stl.insert(e);
	for(int e = 0; e < n; e++) if(deg[e] == 1 && ty[e] == 0) q.push(e);
	while(!q.empty()){
		int u = q.front(); q.pop();
		stl.erase(u);
		for(int v : pk[u]){
			deg[v]--;
			pk[v].erase(u);
			if(deg[v] == 1 && ty[v] == 0) q.push(v);
		}
		pk[u].clear();
	}
	if(stl.empty()){
		cout << 0 << endl;
		return 0;
	}
	int rt = *(stl.begin());
	for(int v : stl){
		for(int u : pk[v]){
			tr[v].push_back(u);
		}
	}
	solve(rt, -1);
	fix(rt, -1);
	long long ans = 1ll<<60;
	for(int v : stl) ans = min(ans, d[0][v]);
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 53248
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

prev = 0
ans = 0
for i in range(N):
  ans += min(A[i],B[i]+prev)
  if prev >= A[i]:
    prev = B[i]
  else:
    prev = max(0,B[i] + prev - A[i])

ans += min(prev,A[N])

print(ans)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;


int main() {

  string S;
  cin >> S;
  ll Q;
  cin >> Q;

  int siji;
  int flagS = 0;
  string matubi = "";
  string sento = "";
  REP(i, Q){
    cin >> siji;
    if(siji == 1){
      flagS = 1 - flagS;
      swap(sento, matubi);
    }else{
      int siji2;
      cin >> siji2;
      string c;
      cin >> c;
      if(siji2 == 1){
        if(flagS == 1){
          sento = sento + c;
        }else{
          sento = c + sento;
        }
      }else {
        if(flagS == 1){
          matubi = c + matubi;
        }else{
          matubi = matubi + c;
        }
      }
    }
  }

  if(flagS){
    reverse( sento.begin(), sento.end() );
    reverse( S.begin(), S.end() );
    reverse( matubi.begin(), matubi.end() );
  }
  S = sento + S + matubi;


  cout << S << endl;

    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 1512
def pow_r(x,n,p):
  if n == 0:
    return 1
  if n % 2 == 0:
    return pow_r(x**2 % p, n//2, p)
  else:
    return x * pow_r(x**2 % p, n//2, p) % p
    

N = int(input())
Ds = list(map(int, input().split()))
memo = [0]*N
P = 998244353

for d in Ds:
  memo[d] += 1
  
if Ds[0] != 0 or memo[0] != 1:
  print(0)
  exit()
  
rlt = 1
cnt = 1

for i in range(1,N):
  if memo[i] > 0:
    rlt *= pow_r(memo[i-1], memo[i], P)
    rlt %= P
    cnt += memo[i]
  else:
    if cnt == N:
      print(rlt)
      exit()
    else:
      print(0)
      exit()
      
print(rlt)


Measured memory_bytes: 85344
N, M = map(int, input().split())
shops = [None] * N
for i in range(N):
  shops[i] = list(map(int, input().split()))
shops.sort()
cnt = 0
ans = 0
for i in range(N):
  shop = shops[i]
  ans += shop[0] * shop[1]
  cnt += shop[1]
  if cnt > M:
    ans -= (cnt - M) * shop[0]
    break
print(ans)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 1;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll k,n;
    cin >> k >> n;
    vector<ll> a(n);
    rep0(i, n)cin >> a[i];
    sort(all(a));
    ll d,cnt;
    d = k - a[n - 1] + a[0];
    rep0(i, n - 1){
        cnt = a[i + 1] - a[i];
        d = max(d,cnt);
    }
    pf(k - d);
    return 0;
}



Measured memory_bytes: 1792
// Problem : C - Train Ticket
// Contest : AtCoder - AtCoder Beginner Contest 079
// URL : https://atcoder.jp/contests/abc079/tasks/abc079_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
bool check(string s,int i)
{
	int total=s[0]-'0';
	int ptr=1;
	for(int j=2;j>=0;j--)
	{
		if(i&(1<<j))
		{
			total+=(s[ptr++]-'0');
		}
		else
		total-=(s[ptr++]-'0');
	}
	return total==7;
}
string print(int x)
{
	if(x)
	return "+";
	return "-";
}
void solve()
{
	string s;cin>>s;
	for(int i=0;i<(1<<3);i++)
	{
		if(check(s,i))
		{
			cout<<s[0]<<print(i&(1<<2))<<s[1]<<print(i&(1<<1))<<s[2]<<print(i&(1<<0))<<s[3]<<"="<<7;
			break;
		}
	}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3656
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m=inf,ans=0; cin>>n;
    rep(i,n){
        int s; cin>>s;
        ans+=s;
        if(s%10) m=min(m,s);
    }
    if(ans%10) cout<<ans<<endl;
    else{
        if(m==inf) m=ans;
        cout<<ans-m<<endl;
    }
}


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

int main() {
    int N;
    vector<int> a;
    cin>>N;
    a = vector<int>(N);
    for(int i=0;i<N;i++) cin>>a[i];
    for(int i=0;i<N;i++) {
        int k=a[i];
        int j=i-1;
        for(;j>=0 && a[j]>k;j--) a[j+1]=a[j];
        a[j+1] = k;
        cout<<a[0];
        for(j=1;j<N;j++) cout<<" "<<a[j];
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <cctype>
#include <string>
using namespace std;

int main()
{
	int i;
	string word;
	int sum = 0;
	
	while(1)
	{
		getline(cin, word);
		
		if(word == "0")
			break;
		for(i = 0; i < word.size(); i++)
		{
			sum += word[i] - '0';
		}
		cout << sum << endl;
		sum = 0;
	}
}



Measured memory_bytes: 3176
void main() {
	auto ip = readln.split, A = ip[0].to!real, B = ip[1].to!real;
	writefln("%d", floor(A*B).to!ulong);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

long rl() {
	return readAs!long;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 2904
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,ans;
void f(ll n,ll m,ll a){
    if(N<n)return ;
    if(N>=n+a*3){
        if((m|1)==7)ans++;
        f(n+a*3,m|1,a*10);
    }
    if(N>=n+a*5){
        if((m|2)==7)ans++;
        f(n+a*5,m|2,a*10);
    }
    if(N>=n+a*7){
        if((m|4)==7)ans++;
        f(n+a*7,m|4,a*10);
    }
}
int main(void){
    cin>>N;
    f(0,0,1);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 2  # type: int


def solve(N: int, a: "List[int]"):

    box = [0]*N

    for x in range(N, 0, -1):
        ca = N // x
        t = 0
        for i in range(1,ca+1):
            t += box[i*x-1]
        
        if t%2 != a[x-1]:
            box[x-1] = 1

    print(sum(box))
    if sum(box) !=0:
        ans = [x for x in range(1, N+1) if box[x-1]==1]
        print(*ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265358979
#define MOD 998244353
const int MAX = 510000;

int main() {
  ll N,x;
  cin>>N>>x;
  vector<ll>a(2*N-1);
  if(x==1||x==(2*N-1)){cout<<"No";return 0;}
  if(N==2){cout<<"Yes"<<endl<<1<<endl<<2<<endl<<3;return 0;}
  if(x==2||x==(2*N-2)){
    a[N-2]=x-1;
    a[N-1]=x;
    a[N]=x+1;
    ll b=2*N-1;
    int p=1;
    if(x==2){p=4;}
    for(int i=0;i<b;i++){
      if(i==N-2||i==N-1||i==N){continue;}
      a[i]=p;
      p++;
    }
    cout<<"Yes"<<endl;
    rep(i,b){cout<<a[i]<<endl;} 
    return 0;
  }
    a[N-3]=x+2;
    a[N-2]=x-1;
    a[N-1]=x;
    a[N]=x+1;
    a[N+1]=x-2;
    ll b=2*N-1;
    int p=1;
    for(int i=0;i<b;i++){
      if(i==N-3||i==N-2||i==N-1||i==N||i==N+1){continue;}
      if(p==x-2){p=x+3;}
      a[i]=p;
      p++;
    }
    cout<<"Yes"<<endl;
    rep(i,b){cout<<a[i]<<endl;}
}

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

int main(){
  int a,b,k;cin >> a >> b >> k;
  int l = 0;
  for(int i=min(a,b);i>0;--i){
    if(a%i == 0&&b%i == 0)l += 1;
    if(l == k){cout << i << endl;return 0;}
  }
  return 0;
}

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

int main() {
  char alpha;
  cin >> alpha;
  if (alpha >= 'a' && alpha <= 'z') {
    cout << "a" << endl;
  } else {
    cout << "A" << endl;
  }
  return 0;
}

Measured memory_bytes: 3564
N, M = map(int, input().split())
S = []
for n in range(N):
    a, b = map(int, input().split())
    S.append((a, b))

S = sorted(S, key = lambda x:x[0])

price = 0
m = M
for a, b in S:
    if m <= b:
        price += m * a
        m = 0
    else:
        price += a * b
        m = m - b
    
    if m <= 0:
        break
    
print(price)

Measured memory_bytes: 18948