akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

int main(void){
  int n;
  cin >> n;

  vector<int> a(n);

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

  sort(a.begin(), a.end(), greater<int>());

  int alice = 0;
  int bob = 0;

  rep(i, n) {
    if (i % 2 == 0) alice += a[i];
    else bob += a[i];
  }

  cout << alice - bob << endl;

  return 0;
}

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

using namespace std;

using ll = long long;

ll kth_lunlun_number(int k) {
  if (k <= 9) {
    return k;
  }

  queue<ll> q;
  for (int i = 1; i <= 9; i++) {
    q.push(i);
  }

  for (int i = 0; i < k - 1; i++) {
    ll n = q.front();
    q.pop();

    int d = n % 10;
    if (d != 0) {
      q.push(n * 10 + d - 1);
    }

    q.push(n * 10 + d);

    if (d != 9) {
      q.push(n * 10 + d + 1);
    }
  }

  return q.front();
}

int main(int argc, const char *argv[])
{
  int k;
  cin >> k;
  cout << kth_lunlun_number(k);
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define n 500000
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
void solve();
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int times = 1;
//	cin >> times;
	for(int i=0; i<times; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

int a, b, c, d, e, f, g, h;
int arr[n + 50], arr1[n + 50], arr2[n + 50];

//type here

void solve()
{
	cin >> a;
	for(int i=0; i<a; i++)
		cin >> arr[i];
	int des = 1, ans = 0;
	for(int i=0; i<a; i++)
	{
		if(arr[i] == des) des ++;
		else			  ans ++;
	}
	if(ans == a) cout << "-1";
	else		 cout << ans;
}

Measured memory_bytes: 2944
#include <stdio.h>
int main(void){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	int i;
	for(i=1;i<b;i++){
		int x=a*i,r=x%b;
		if(r==c){printf("YES");return 0;}
	}
	printf("NO");
	return 0;
}

Measured memory_bytes: 128
import sys
import queue
sys.setrecursionlimit(10**7)


def inpl():
    return list(map(int, input().split()))


N, M = inpl()

lines = [[] for _ in range(N)]
for _ in range(M):
    a, b = inpl()
    a -= 1
    b -= 1
    lines[a].append(b)
    lines[b].append(a)


ans = [-1] * N


q = queue.Queue()
q.put((0, 0))
while not q.empty():
    s, b = q.get()

    if ans[s] != -1:
        continue
    else:
        ans[s] = b
        for t in lines[s]:
            q.put((t, s))


print("Yes")
for a in ans[1:]:
    print(a + 1)


Measured memory_bytes: 115552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    int N, K;
    string S;
    cin >> N >> S >> K;
    for(int i=0; i<N; i++){
        if(S[i]!=S[K-1]){
            S[i] = '*';
        }
    }
    cout << S;
}

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

int N, T;
vector<int> P;

void input_init(void) {
	cin >> N >> T;
	for (int i = 0; i < N; ++i) {
		int c, t;
		cin >> c >> t;
		if (t <= T)
			P.push_back(c);
	}
}

int main(void) {
	input_init();
	if (P.size() == 0)
		cout << "TLE" << '\n';
	else {
		int ans = *min_element(P.begin(), P.end());
		cout << ans << '\n';
	}
	return 0;
}


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

int main()
{
   string a,b;
   cin>>a>>b;
   int as=a.size();int bs=b.size();
   int dp[as+1][bs+1];
   
   dp[0][0]=0;
   for(int i=1;i<=as;i++)
   {
    dp[i][0]=0;
   }
   for(int i=1;i<=bs;i++)
   {
    dp[0][i]=0;
   }

   for(int i=1;i<=as;i++)
   for(int j=1;j<=bs;j++)
   {
      dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      if(a[i-1]==b[j-1])
      dp[i][j]=max(1+dp[i-1][j-1],dp[i][j]);
   }
int i=as,j=bs;
string ans;
   while(i>0&&j>0&&dp[i][j])
   {
     if(a[i-1]==b[j-1])
     {
       ans+=a[i-1];
       i--;j--;  
     }
     else
     {
       if(dp[i][j]==dp[i-1][j])
       i--;
       else
       j--;
     }
     
   }
   reverse(ans.begin(),ans.end());
   cout<<ans<<endl;
}

Measured memory_bytes: 35456
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[][] gridD = new int[c+1][c+1];
		int[][] gridC = new int[n+1][n+1];
		for(int i = 1; i < c+1; i++){
		    for(int j = 1; j < c+1; j++){
		        gridD[i][j] = sc.nextInt();
		    }
		}
		for(int i = 1; i < n+1; i++){
		    for(int j = 1; j < n+1; j++){
		        gridC[i][j] = sc.nextInt();
		    }
		}
		
		// 計算
		int result = Integer.MAX_VALUE;
		int[][] d0 = new int[c+1][2];
		d0[0][1] = Integer.MAX_VALUE;
		d0[1][0] = c+1;
		int[][] d1 = new int[c+1][2];
		d1[0][1] = Integer.MAX_VALUE;
		d1[1][0] = c+2;
		int[][] d2 = new int[c+1][2];
		d2[0][1] = Integer.MAX_VALUE;
		d2[1][0] = c+3;
		for(int k = 1; k < c+1; k++){
		    for(int i = 1; i < n+1; i++){
		        for(int j = 1; j < n+1; j++){
		            if((i+j)%3 == 0){
		                d0[k][0] = k;
		                d0[k][1] += gridD[gridC[i][j]][k];
		            }else if((i+j)%3 == 1){
		                d1[k][0] = k;
		                d1[k][1] += gridD[gridC[i][j]][k];
		            }else{
		                d2[k][0] = k;
		                d2[k][1] += gridD[gridC[i][j]][k];
		            }
		        }
		    }
		}
		Arrays.sort(d0, (s, t) -> Integer.compare(s[1], t[1]));
		Arrays.sort(d1, (s, t) -> Integer.compare(s[1], t[1]));
		Arrays.sort(d2, (s, t) -> Integer.compare(s[1], t[1]));
		for(int i = 0; i < c; i++){
		    for(int j = 0; j < c; j++){
		        for(int k = 0; k < c; k++){
		            if(d0[i][0] == d1[j][0] || d1[j][0] == d2[k][0] || d2[k][0] == d0[i][0]) continue;
		            result = min(result, d0[i][1] + d1[j][1] + d2[k][1]);
		        }
		    }
		}
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 90496
#include <iostream>
#include <math.h>
using namespace std;
int main(){
	while(1){
		int n,a,b,c,x;
		int y[101]={0};
		cin >> n>>a>>b>>c>>x;
		if(n==0&&a==0&&b==0&&c==0&&x==0) break;
		for(int i=1;i<=n;i++){
			cin >> y[i];
		}
		int count=0;
		int slot = 1;
		while(count<=10000){
				
				if ( x ==y[slot] ){

					slot +=1;
				
				}
				if (slot > n) break;
				count +=1;
				x =(a*x+b)%c;
			}
		if(count==10001) cout <<-1 <<endl;
		else cout <<count <<endl;
		

	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    
    double ans = 0;
    for (int i = 1; i <= N; i++) {
        int tokuten = i;
        int cnt = 0;
        while(tokuten < K) {
            tokuten *= 2;
            cnt++;
        }
        double x = 1 / (N * pow(2, cnt));
        ans += x;
    }
    
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

def f(a, b):
    for i in range(9,0,-1):
        if a[i] == b[i]: continue
        elif a[i] > b[i]:
            return True
        else:
            return False
    return False

N, M = map(int, input().split())
se = set()
A = list(map(int, input().split()))
toNum = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [[] for i in range(N+1)]
done = [False for i in range(N+10)]
done[N] = True
dics = [defaultdict(int) for i in range(N+1)]
for i in range(N-1, -1, -1):
    for a in A:
        num = toNum[a]
        if not done[i+num]: continue
        l = len(dp[i+num])+1
        d = dics[i+num].copy()
        d[a] += 1
        if l > len(dp[i]) or (l == len(dp[i]) and f(d, dics[i])):
            dp[i] = dp[i+num] + [a]
            done[i] = True
            dics[i] = d
dp[0].sort(reverse=True)
print(*dp[0], sep='')


Measured memory_bytes: 264452
fun main(arg: Array<String>) {
    val (N, K) = listOfInt()
    val X = listOfInt()
    val dp = Array(N + 1) { LongArray(N * 50 + 1) }
    dp[0][0] = 1
    for (i in 0 until N) {
        for (j in (0 until N).reversed()) {
            for (k in 0 .. N * 50 - X[i]) {
                dp[j + 1][k + X[i]] += dp[j][k]
            }
        }
    }
    var ans = 0L
    for (j in 1 .. N) ans += dp[j][K * j]
    println(ans)

}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }



Measured memory_bytes: 42388
#include <bits/stdc++.h>
#define P pair<int, int>

using namespace std;
const int INF=1e5;
int dx[4]={-1, 0, 1, 0};
int dy[4]={0, -1, 0, 1};

int main(){
  long long h, w, cnt=0;
  string s[409];
  cin >>h >> w;
  for(int i=0;i<h;i++)cin >> s[i];
  bool check[409][409];
  memset(check, false, sizeof(check));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(check[i][j])continue;
      queue<P> q;
      long long b_cnt=0, w_cnt=0;
      q.push(P(i, j));
      check[i][j]=true;
      while(!q.empty()){
        P p=q.front();q.pop();
        int c_i=p.first;
        int c_j=p.second;
        if(s[c_i][c_j]=='.')w_cnt++;
        else b_cnt++;
        for(int k=0;k<4;k++){
          int n_i = c_i + dy[k];
          int n_j = c_j + dx[k];
          if(!(0<=n_i&&n_i<=h-1&&0<=n_j&&n_j<=w-1))continue;
          if(s[n_i][n_j]==s[c_i][c_j])continue;
          if(check[n_i][n_j])continue;
          check[n_i][n_j]=true;
          q.push(P(n_i, n_j));
        }
      }
      cnt+=b_cnt*w_cnt;
    }
  }
  cout << cnt << endl;
}



Measured memory_bytes: 640
#include<cstdio>
int main() {
	long long m, n, p=1000000007, d, ans=1;
	scanf("%lld%lld", &m, &n);
	for (d = 1 << 30; d >= 1; d >>= 1) {
		if (d&n) {
			ans = ((ans*ans)%p)*m%p;
		}
		else {
			ans = (ans*ans)%p;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2760
from itertools import starmap
(lambda *_: None)(
    *map(print,
         starmap(lambda h, w: ''.join(['#'*w + '\n'] +
                                      ['#' + '.'*(w-2) + '#\n'] * (h-2) +
                                      ['#'*w + '\n']),
                 map(lambda ss: map(int, ss),
                     map(str.split, iter(input, '0 0'))))))

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

int main() {
  int N,A,amari;
  cin >> N;
  cin >> A;
  amari = N % 500;
  if(A >= amari){
    cout << "Yes" << endl;
  }
  else if(A < amari){
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define S size()
#define E end()
#define B begin()
#define L length()
 
#define endl "\n"
#define cnt count
#define in insert
#define er erase
#define fi first
#define se second
#define fl float
#define ld long double
#define ll long long

#define gcd __gcd
#define mp make_pair
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define all(v) v.B,v.E
#define acc(v) accumulate(all(v), 0)
#define psum partial_sum
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define np next_permutation
#define maxe *max_element
#define mine *min_element
 
#define forl(i,n) for(ll i = 0; i < n; i++)
#define fore(i, m, n) for (ll i = m; i <= n; i++)
#define rforl(i,n) for (ll i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (ll i = n; i >= m; i--)    
#define iter(s) for(auto it:s)
 

#define prec(n) fixed<<setprecision(n)
#define popcnt(n) __builtin_popcountll(n)
#define parity(n) __builtin_parityll(n)
#define clz(n) __builtin_clzll(n)
#define ctz(n) __builtin_ctzll(n)

#define sll set<ll>
#define sc set<char>
#define mll map<ll,ll>
#define vll vector<ll>
#define vc vector<char>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define msll multiset<ll>
#define msc multiset<char>
#define vvll vector<vector<ll>>
#define rev reverse

#define pat ll n;cin>>n;
#define tc ll q;cin>>q;while(q--)
#define tak(s) string s;cin>>s;ll n=s.LEN;
#define nokay if(ok) cout<<"YES\n";else cout<<"NO\n";
#define pat1 vll a(n);forl(i,n)cin>>a[i];
#define pat2 ll n,k;cin>>n>>k;vll a;forl(i,n) cin>>a[i];

#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a,b) cout << a << " " << b << endl
#define p3(a,b,c) cout << a << " " << b << " " << c << endl
#define p4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl
 
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define mod1 1000000007
#define mod2 998244353
#define PI 3.1415926535897932384626433832

//**********************************
 
int main(){
    ll n=5;
    pat1
    forl(i,n){
        if(a[i]==0){
            cout<<i+1<<endl;
            break;
        }
    }
    
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

int main(){
  string S;
  cin >> S;
  
  int num;
  int min = 100000;
  
  rep(i, S.length()-2){
    num = abs(100*(int)(S[i]-48) + 10*(int)(S[i+1]-48) + (int)S[i+2]-48 - 753);
    if(min > num) min = num;
    //cout << 100*(int)(S[i]-48) + 10*(int)(S[i+1]-48) + (int)S[i+2]-48 << endl;
  }
  
  cout << min << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long x,k,d;
int main(){
  cin>>x>>k>>d;
  x=abs(x);
  if(x/d>=k) cout<<x-d*k<<endl;
  else cout<<abs(x%d-((x/d)%2==k%2?0:d))<<endl;
}


Measured memory_bytes: 3664
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine()
    var x = 0
    var max = 0

    for(z in kotlin)
    {
        if(z=='R')
        {
            x++
            max = Math.max(x,max)
        }
        else
            x= 0
    }
    println(max)
}


Measured memory_bytes: 36360
#include <iostream>

using namespace std;

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

  int B[20];
  for(int i = 0; i < M; i++) cin >> B[i];

  int A[N][M];
  for(int j = 0; j < N; j++){
    for(int k = 0; k < M; k++){
      cin >> A[j][k];
    }
  }

  int sum = 0;
  int correct = 0;
  for(int j = 0; j < N; j++){
    for(int k = 0; k < M; k++){
      sum += A[j][k] * B[k];
    }
    if(sum+C > 0) correct++;
    sum = 0;
  }

  cout << correct;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = k + 1; i <= n; i++) {
        cout << (a[i - k] < a[i] ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef pair<ll,ll> pll;
#define fi first
#define se second
#define pb push_back

const int N=1e6;
int main()
{
    ll n,cnt=0;
    cin>>n;
    string str;
    cin>>str;

    ll i=0,j=n-1;

    while(i<=j)
    {
        if(str[i]=='W'&&str[j]=='R')
        {
            swap(str[i],str[j]);
            cnt++;
        }
        if(str[i]=='R')
        {
            i++;

        }
         if(str[j]=='W')
        {
            j--;

        }

    }

    cout<<cnt<<endl;
}




Measured memory_bytes: 3752
/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;

#define mod 1000000007
#define pb push_back
#define ll long long int
#define ull unsigned ll
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

/*
const ll infinity = 9e18;

bool compare(ll a,ll b) {return a > b;}
bool compare1(ppl a,ppl b) {return a.ff > b.ff;}
bool compare2(ppl a,ppl b) {return a.ss < b.ss;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}

ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/




int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll n;
    cin>>n;

    if(n >= 30) cout<<"Yes";
    else cout<<"No";
        
        












    return 0;
}

Measured memory_bytes: 3648
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n;
int a[100000];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		--a[i];
	}
	int res = 0;
	REP(i, n - 1) if (a[i] == i) {
		++res;
		swap(a[i], a[i + 1]);
	}
	if (a[n - 1] == n - 1) ++res;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 

using namespace std;

int main()
{
	string s1,s2,tmp,ans;
	int n,m;

	while(1){
		s1.clear();s2.clear();ans.clear();
		cin>>n; if(n==0) return 0;
		for(int i=0;i<n;i++){
			cin>>tmp; s1+=tmp;
			cin>>tmp; s2+=tmp;
		}
		cin>>m;
		for(int i=0;i<m;i++){
			cin>>tmp; ans+=tmp;
			for(int j=0;j<n;j++){
				if(ans[i]==s1[j]){ans[i]=s2[j]; break;}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
long long wt[101],val[101],dp[100001][101],W=0;
long long knapsack(long long Weightremaining,int nthing )
{
	if(nthing<=0||Weightremaining<=0)
	return 0;
	if(Weightremaining>=wt[nthing])
	{
	if(dp[Weightremaining][nthing]!=-1)
		return dp[Weightremaining][nthing];
	dp[Weightremaining][nthing]=max(knapsack(Weightremaining,nthing-1),knapsack(Weightremaining-wt[nthing],nthing-1)+val[nthing]);
	}
	else
	dp[Weightremaining][nthing]=knapsack(Weightremaining,nthing-1);
	return dp[Weightremaining][nthing];
}
int main() {
	memset(dp,-1,sizeof(dp));
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	long long n,i,q;
	cin>>n>>W;
	for(i=1;i<=n;i++)
	cin>>wt[i]>>val[i];
	cout<<knapsack(W,n);
	return 0;
}

Measured memory_bytes: 79232
# include<iostream>
# include<algorithm>
# include<cstring>
using namespace std;
 
 
int main ()
{
	string s;
	string r;
	cin>>s;
	cin>>r;
   
    bool ok =false;
    
    for(int i=0;i<s.length();i++)
    {
    	  if(s[i]!=r[i])
    	  {
    	  	  ok = true;
		  }
	}
    
   if(ok)
   {
   	   cout<<"No"<<endl;
   }
   else
   {
   	   cout<<"Yes"<<endl;
   }
   
    
    return 0;
	
	
 } 

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, a; cin >> n >> a;
  n %= 500;
  cout << (n <= a ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [n, m] <- fmap read . words <$> getLine :: IO [Int]
    if m <= n * 2
        then print $ m `div` 2
        else do
            let r = m - n * 2
            print $ n + r `div` 4

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int r,d,x;
  cin>>r>>d>>x;
  rep(i,10){
    x=r*x-d;
   cout<<x<<endl; 
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    // int T;cin>>T;while(T--) 
    {
        int n;
        cin>>n;
        string s;
        map<string, int> m;
        ifr(i, 0, n) cin>>s,m[s]++;
        cout<<"AC x "<<m["AC"]<<endl;
        cout<<"WA x "<<m["WA"]<<endl;
        cout<<"TLE x "<<m["TLE"]<<endl;
        cout<<"RE x "<<m["RE"]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long h[n],MAX=0;
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  for(int i=0;i<n;i++){
    MAX=max(MAX, h[i]);
    if(MAX-h[i]>=2ll){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
using namespace std;
const int N = 5e2 + 5;
int n, m, d, ans[N][N + N];
int main() {
	cin >> n >> m >> d;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			int x = i + j;
			int y = i - j + m;
			x /= d; y /= d;
			x &= 1; y &= 1;
			ans[i][j] = x + (y << 1);
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (ans[i][j] == 0) printf("R");
			if (ans[i][j] == 1) printf("Y");
			if (ans[i][j] == 2) printf("G");
			if (ans[i][j] == 3) printf("B");
		}
		printf("\n");
	}
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, k, ans;
char a;

int main() {
    scanf(" %c", &a);
    if (a < 'a') printf("A");
    else printf("a");
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

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

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N, K, Q; cin >> N >> K >> Q;
    vec A(N); readv(A);
    int ans = INF;

    REP(i, N){
        int m = A[i];
        vec v(0), w(0);
        REP(j, N + 1){
            if(j == N || A[j] < m){
                if(v.size() >= K){
                    SORT(v);
                    REP(k, v.size() - K + 1) w.push_back(v[k]);
                }
                v = vec(0);
            }else v.push_back(A[j]);
        }
        if(w.size() >= Q){
            SORT(w);
            ans = min(ans, w[Q - 1] - m);
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

template <typename T>
void prime_factorization(T& result, int x)
{
  for (int i = 1; i*i <= x; i++) {
    if (x % i == 0) {
      result.insert(i);
      result.insert(x/i);
    }
  }
}

bool verify(const vector<int>& a, int k, int block_size, int block_num)
{
  priority_queue<int> pq;
  for (int x : a) {
    pq.push(x);
  }
  while (0 < block_num) {
    int x = pq.top();
    pq.pop();
    int block_use = min(block_num, max(1, x / block_size));
    pq.push(x - block_size * block_use);
    block_num -= block_use;
  }
  int diff = 0;
  while (!pq.empty()) {
    int x = pq.top();
    pq.pop();
    if (0 < x) {
      diff += x;
    }
  }
  return diff <= k;
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int sum = accumulate(a.begin(), a.end(), 0);
  set<int> s;
  prime_factorization(s, sum);
  int result = 0;
  for (int block_num : s) {
    int block_size = sum / block_num;
    if (verify(a, k, block_size, block_num)) {
      result = block_size;
      break;
    }
  }
  cout << result << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define ll long long 
#define f(i,l,n) for(int i=l;i<n;i++)
#define E "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAX 1e18
#define float long double
 
const int M=1e9+7;

#define pi 3.141592653590



int fun(int n,int k)
{
	int ans=0;
	int temp=(n+1-k)%M;
  	temp= ( temp *k)%M;
  	temp=(temp+1)%M;
  	ans=(ans+temp)%M;
  	return ans%M;
}


int32_t main()
{
 
  
  int n,k;
  cin >> n >> k;
  int ans=0;

  for(int i=k;i<=n+1;i++)
  {
  	ans=(ans+fun(n,i))%M;
  	
  }
  cout<<ans;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include<cstdio>
#include <cstring>
#include <algorithm>
#define ll long long int
using namespace std;

ll arr[100001];
ll dp[100001];
int n;

int call(int i)
{
    int ans1 = 0,ans2 = 0;
    if(i == n-1)
        return 0;
    if(dp[i] != -1)
            return dp[i];
    else if(i < n-2)
    {
        ans1 = abs(arr[i]-arr[i+1]) + call(i+1);
        ans2 = abs(arr[i]-arr[i+2]) + call(i+2);
        dp[i] = min(ans1,ans2);
        return dp[i];
    }
    else if(i == n-2)
    {
        ans1 = abs(arr[i]-arr[i+1]) + call(i+1);
        dp[i] = ans1;
        return dp[i];
    }

}

int main()
{

   cin>>n;

    for(int i=0;i<n;i++)
        cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<call(0);
}


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

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

  bool yymm = false;
  bool mmyy = false;
  int head = stoi(S.substr(0, 2));
  int tail = stoi(S.substr(2, 2));
  if (0 <= head && head <= 99 && 1 <= tail && tail <= 12) yymm = true;
  if (1 <= head && head <= 12 && 0 <= tail && tail <= 99) mmyy = true;
  if (yymm && mmyy)
    cout << "AMBIGUOUS" << endl;
  else if (yymm)
    cout << "YYMM" << endl;
  else if (mmyy)
    cout << "MMYY" << endl;
  else
    cout << "NA" << endl;
}


Measured memory_bytes: 256
INF = int(1e40)

from sys import stdin, stdout
from bisect import bisect_left as bl, bisect_right as br

def f(x, s, t):
    a = abs(x - s) + abs(s - t)
    a = min(a, abs(x - t) + abs(t - s))
    return a

a, b, q = map(int, raw_input().strip().split())
inp = stdin.readlines()
out = []

s = [0 for i in xrange(a)]
t = [0 for i in xrange(b)]

ctr = 0
for i in xrange(a):
    s[i] = int(inp[i + ctr].strip())

ctr = a
for i in xrange(b):
    t[i] = int(inp[i + ctr].strip())

ctr += b
for i in xrange(q):
    x = int(inp[i + ctr].strip())
    idx_s = bl(s, x)

    s1 = -INF
    s2 = INF
    if idx_s:
        s1 = s[idx_s - 1]
    try: s2 = s[idx_s]
    except: pass

    idx_t = bl(t, x)
    t1 = -INF
    t2 = INF
    if idx_t:
        t1 = t[idx_t - 1]
    try: t2 = t[idx_t]
    except: pass
    
    ans = f(x, s1, t1)
    ans = min(ans, f(x, s1, t2))
    ans = min(ans, f(x, s2, t2))
    ans = min(ans, f(x, s2, t1))

    out.append(str(ans))

stdout.write("\n".join(out))


Measured memory_bytes: 96988
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
    ll a,n,b,c,d;
    while(cin>>n>>a>>b>>c>>d)
    {
        ll k=0;
        for(ll i=0;i<n;i++)
        {
            if((c*(n-i-1)-i*d)<=(b-a)&&(b-a)<=(d*(n-i-1)-i*c))
            {
                puts("YES");
                goto eg;
            }
        }
        puts("NO");
        eg:;
    }
    return 0;
}

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

int main() {
    string S;
    cin>>S;
    int N=S.size();
    int count=(N+1)/4;
    int i=0;

    for(int n=0; n<(N+1)/2; n++){
        if(S.at(n) != S.at(N-n-1)){
            goto out;
        }
    }

    while(i<count){
        if(S.at(i) != S.at((N-1)/2-1-i)){
            goto out;
        }
        i++;
    }
    i=0;
    while(i<count){
        if(S.at(i+(N+3)/2-1) != S.at(N-1-i)){
            goto out;
        }
        i++;
    }

    cout<<"Yes"<<endl;    
    return 0;

    out:
        cout<<"No"<<endl;
        return 0;
}

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

#define INF 1 << 30

int D, G;

int search(vector<int> &p, vector<int> &c, int cmp, int sum, int score, int id) {
	if (id == D) {
		if (score >= G)
			return sum;
		for (int i = D - 1; i >= 0; i--) {
			if ((cmp & (1 << i)) == 0) {
				if ((p[i] - 1) * (i + 1) * 100 + score >= G) {
					sum += (G - score) / ((i + 1) * 100);
					if ((G - score) % ((i + 1) * 100) > 0)
						sum++;
					return sum;
				}
				break;
			}
		}
		return INF;
	}
	int ans = search(p, c, cmp, sum, score, id + 1);
	cmp = cmp | (1 << id);
	score += p.at(id) * (id + 1) * 100 + c.at(id);
	ans = min(ans, search(p, c, cmp, sum + p.at(id), score, id + 1));
	return ans;
}

int main(void) {
	cin >> D >> G;

	int cmp = 0;
	vector<int> p(D), c(D);

	for (int i=0; i < D; i++){
    cin >> p.at(i) >> c.at(i);
  }
	int ans = search(p, c, cmp, 0, 0, 0);
  cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#define fi first
#define se second
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int main() {
	int n;
	ll ans=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		ans*=i;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1156
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {  
		Scanner input = new Scanner(System.in);
		double W = input.nextDouble();
		double H = input.nextDouble();
		double x = input.nextDouble();
		double y = input.nextDouble();
		double A = W*H;
		A/=2; //It's always possible to split rectangle into 2 equal pieces
		//when divider can have any slope and start point
		int ways = 0;
		if (x==W/2&&y==H/2) ways++;
		System.out.println(A+" "+ways);
	}
}

Measured memory_bytes: 25300
def main():
    n = int(input())
    f = [0 for i in range(n+1)]
    Max = n**0.5
    Max = int(Max//1) 
    for x in range(1,Max):
        for y in range(1,Max):
            for z in range(1,Max):
                tmp = x**2+y**2+z**2+x*y+y*z+x*z
                if tmp<=n:
                    f[tmp] += 1
    for i in range(1,n+1):
        print(f[i])

main()

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

char pattern_3[4][4] = {"aa.", "..b", "..b"};
char pattern_4[5][5] = {"abcc", "abdd", "eegh", "ffgh"};
char pattern_5[6][6] = {"aabbc", "dee.c", "d..fg", "h..fg", "hiijj"};
char pattern_6[7][7] = {"aa.ccd", "..bf.d", "..bfee", "gghkk.", "j.h..l", "jii..l"};
char pattern_7[8][8] = {"a...ggh", "a...j.h", "b...jii", "bkkl...", "cn.l...", "cnmm...", ".ddeeff"};

const int N = 1010;

char ans[N][N];

int main(){
    int n;
    scanf("%d", &n);
    if (n <= 2){
        puts("-1");
        return 0;
    }
    if (n % 3 == 0){
        int offset = 0;
        for (int i = 0; i < n; i += 3){
            for (int j = 0; j < 3; ++ j){
                strcat(ans[i + j] + offset, pattern_3[j]);
            }
            offset += 3;
        }
    }
    else if (n == 7){
        for (int i = 0; i < n; ++ i){
            strcat(ans[i], pattern_7[i]);
        }
    }
    else if (n == 11){
        for (int i = 0; i < 6; ++ i){
            strcat(ans[i], pattern_6[i]);
        }
        for (int i = 0; i < 5; ++ i){
            strcat(ans[i + 6] + 6, pattern_5[i]);
        }
    }
    else{
        int num4 = 0, num5 = 0;
        for (int i = 0; ; ++ i){
            if ((n - i * 4) % 5 == 0){
                num4 = i, num5 = (n - i * 4) / 5;
                break;
            }
        }
        int offset = 0;
        for (int i = 0; i < num4; ++ i){
            for (int j = 0; j < 4; ++ j){
                strcat(ans[offset + j] + offset, pattern_4[j]);
            }
            offset += 4;
        }
        for (int i = 0; i < num5; ++ i){
            for (int j = 0; j < 5; ++ j){
                strcat(ans[offset + j] + offset, pattern_5[j]);
            }
            offset += 5;
        }
    }
    for (int i = 0; i < n; ++ i){
        for (int j = 0; j < n; ++ j){
            if (ans[i][j] == '\0'){
                ans[i][j] = '.';
            }
        }
    }
    for (int i = 0; i < n; ++ i){
        puts(ans[i]);
    }
    return 0;
}


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

#define read(a) cin >> a
#define out(a)  cout << a
#define ull unsigned long long
#define ll long long
#define FOR(i, l, r) for (ll i = l; i <= r; i++)
#define FOD(i, l, r) for (ll i = l; i >= r; i--)
#define fast ios_base::sync_with_stdio(0);

ll n;
ll tong = 0, kq = 0, x;
const ll mod = 1e9 + 7;

int main()
{
    fast;
    read(n);
    while(n--)
    {
        cin >> x;
        kq = (kq + (tong * x) % mod) % mod;
        tong =  (tong + x) % mod;
    }
    cout << (kq%mod + mod) % mod;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<string>
#include<queue>
using namespace std;
int main(){
  int w,h;
  string line;
  while(true){
    cin>>w>>h;
    if(!w&&!h)
      break;
    vector<string> castle;
    for(int i=0;i<h;i++){
      cin>>line;
      castle.push_back(line);
    }
    int count[w+2][h+2];
    int sx,sy;
    const int MAX = 100;
    for(int y=1;y<h+1;y++){
      for(int x=1;x<w+1;x++){
	count[x][y] = MAX;
	if (castle[y-1][x-1]=='&'){
	  sx = x;
	  sy = y;
	  castle[y-1][x-1]='.';
	}
      }
    }
    int min = MAX;
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    count[sx][sy] = 0;
    queue<int> st;
    st.push(sy*(w+2)+sx);
    while(!st.empty()){
      int x = st.front()%(w+2);
      int y = st.front()/(w+2);
      st.pop();
      char c = castle[y-1][x-1];
      int n;
      for(int d=0;d<4;d++){
	n = count[x][y];
	if(x+dx[d]>0&&y+dy[d]>0&&x+dx[d]<w+1&&y+dy[d]<h+1){
	  if(c=='.'&&castle[y+dy[d]-1][x+dx[d]-1]=='#')
	    n++;
	  if(n<count[x+dx[d]][y+dy[d]]){
	    count[x+dx[d]][y+dy[d]] = n;
	    st.push((y+dy[d])*(w+2)+x+dx[d]);
	  }
	}
	else{
	  if(n<min)
	    min = n;
	}
      }
    }
    cout<<min<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
const int mod = 1000000007;
typedef long long ll;
//------------------------------------------------------------------------

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

  int n; cin >> n;
  vector<pair<string,int>> m(n+2);
  int sum=0;
  vector<int> t(n+2);
  rep1(i,n){
    cin >> m[i].F >> m[i].S;
    sum+=m[i].S;
    t[i] = sum;
  }
  
  string x; cin >> x;
  
  rep1(i,n){
    if(x == m[i].F){
      cout << sum - t[i] << endl;
      return 0;
    }
  }

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
 	int n,m;
	cin>>n>>m;
  int arr[n];
	for(int i=0;i<n;i++)
	{
		arr[i]=-1;
	}
	int ans=0;
	for(int i=0;i<m;i++)
	{
		int t1, t2;
		cin>>t1>>t2;
		 if(t2==0&&t1==1&&n!=1)
		{
			ans=-1;
		}
		else if(t2==0&&t1==1&&n==1)
		{
			if(arr[t1-1]!=-1 &&arr[t1-1]!=0)
		{
			ans =-1;
		}
		else 
		{
			arr[0]=0;
		}


		}

		else if(arr[t1-1]==-1)
		{
			arr[t1-1]=t2;
		}
		else if(arr[t1-1]!=t2)
		{
			ans =-1;
		}
		
	}
	if(ans==-1)
	{
		
			cout<<-1;

	}
	  
	else
	{
		if(n==1)
		{
			if(arr[0]<=0)
		    cout<<0;
				else
				{
					cout<<arr[0];
				}
				
			return 0;  
		}
	
		for(int i=0;i<n;i++)
		{
      if(i==0&&arr[i]==-1)
			  cout<<1;
			else if(arr[i]==-1)
			  cout<<0;
				else
				{
					cout<<arr[i];
				}
				
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
 
class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int X = sc.nextInt();
        int m[] = new int[N];
        for(int i=0; i<N; i++){
            m[i] = sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int cnt = 0;

        for(int i=0; i<N;i++){
            if(min>m[i]) min = m[i];
            X -= m[i];
        }

        System.out.println(N + X/min);


    }
}

Measured memory_bytes: 21844
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xs = (0 until n).map {
        val a = readLine()!!.toInt()
        (0 until a).map {
            val (x, y) = readLine()!!.split(' ').map { it.toInt() }
            x - 1 to y
        }
    }

    var ans = 0

    fun dfs(array: IntArray) {
        if (array.size == n) {
            for (i in 0 until n) {
                if (array[i] == 0) continue
                if (!xs[i].all { it.second == array[it.first] }) {
                    return
                }
            }
            ans = Math.max(ans, array.sum())
            return
        }
        dfs(array.plus(0))
        dfs(array.plus(1))
    }

    dfs(IntArray(0))

    println(ans)
}


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

using namespace std;

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

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

signed main(void) {
    int n,t;
    cin >> n >> t;
    vp p(n);
    rep(i,n)cin >> p[i].first >> p[i].second;
    sort(all(p));
    vi dp(t, -INF);
    dp[0] = 0;
    int ans = 0;
    rep(i,n)for(int j = t-1; j >= 0; j--)if(dp[j] >= 0){
        ans = max(ans, dp[j] + p[i].second);
        if(j+p[i].first < t){
            dp[j+p[i].first] = max(dp[j+p[i].first], dp[j]+p[i].second);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
string str;
int alpha[26];
for(int i=0;i<26;i++)
  alpha[i]=0;
cin>>str;
for(int i=0;i<str.length();i++)
{
  alpha[int(str[i])-97]++;
}
int flag=-1;  
  for(int i=0;i<26;i++)
{
    if(alpha[i]%2!=0)
    {
      flag=0;
       break;
    }
}
  if(flag==-1)
    cout<<"Yes";
  else
    cout<<"No";
  
}

Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    if(n==0) {
        cout << "0\n";
        return 0;
    }
    vi ans;
    while(n!=0) {
        ans.pb((n%(-2)+2)%2);
        n=(n+(n<0?-1:+0))/(-2);
        // cout << n << endl;
    }
    rev(i,ans.size()) cout << ans[i];
    cout << endl;
    return 0;
}

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

const int MOD = 1000000007;

ll binary_pow(ll n, ll p)
{
    return p ? binary_pow(n * n % MOD, p >> 1) * (p & 1 ? n : 1) % MOD : 1;
}

ll factorial(ll n)
{
    ll ret = 1;
    for (int i = 1; i <= n; i++)
        ret = ret * i % MOD;
    return ret;
}

int main()
{
    int x, y;
    cin >> x >> y;

    int sum = (x + y) / 3;
    if ((x + y) % 3 || x - sum < 0 || y - sum < 0)
    {
        cout << 0 << endl;
        return 0;
    }

    x -= sum;
    y -= sum;
    ll ans = factorial(x + y) % MOD;
    ans = ans * binary_pow(factorial(x), MOD - 2) % MOD;
    ans = ans * binary_pow(factorial(y), MOD - 2) % MOD;

    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 3652