akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <string>
#include <numeric>
#include <functional>
using namespace std;

int main()
{
	int N;
	int res = 0;
	cin >> N;
	vector<int> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	while (N!=1) {
		sort(A.begin(), A.end(), greater<int>());
		int j = 0;
		for (j = 0;j < N;j++) {
			if (A[j] == 0) {
				A.pop_back();
			}
		}
		sort(A.begin(), A.end());
		N = A.size();
		if (N == 1) {
			break;
		}
		for (int i = 1;i<N;i++) {
			A[i] = A[i] % A[0];
		}
	}
	sort(A.begin(), A.end(), greater<int>());
	res = A[0];
	cout << res << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
ll f(ll i,ll j){
	ll x=2,p=1;
	while(1){
		if((i%x)!=(j%x))return p;
		x*=2;
		p++;
	}
}
int main(){
	ll N;
	cin >> N;
	FOR(i,1,N){
		FOR(j,i+1,N+1){
			cout << f(i,j) << " ";
		}
		cout << "\n";
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>

#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define endl "\n"
#define INF (ll)ll_MAX

typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;

const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;

using namespace std;

void solve()
{    
    int n ;
    cin>>n ; 
    int L[n]  ;
    rep(i, n )cin>>L[i] ;
    int count = 0 ;
    rep(i  , n ){
        repu(j , i+1 , n-1){
            repu(k , j+1 , n-1){
                if(L[i]!=L[j] && L[i]!=L[k] && L[j]!=L[k] && L[i]<L[j]+L[k] && L[k]<L[i]+L[j] && L[j]<L[k]+L[i]){
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    //cout<<"helo";
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    //  cin>>t;

    while(t--)
    {
        solve();    
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

}

Measured memory_bytes: 3808
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int X,Y;
 
 int main()
 {
	 cin >> X>>Y;
	 bool ans=false;
	 if (Y >= 2 * X && Y <= 4 * X && Y % 2 == 0) ans = true;
	 if (ans == true) cout << "Yes" << endl;
	 else cout << "No" << endl;
	return 0;
}



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

#define LL long long

LL arr[200009];
int n;

LL f(LL m){
	LL res=0;
	for(int i=1;i<=n;i++){
		res = res + abs(arr[i] - m);
	}
	return res;
}

int main(){
	

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;

	for(int i=1;i<=n;i++){
		cin>>arr[i];
		arr[i]-=i;
	//	arr[i] = abs(arr[i]);
	}

	sort(arr+1,arr+n+1);

	if(n%2 == 0){
		cout<<min(f(arr[n/2]) , f(arr[n/2 + 1]))<<endl;
	}else{
		cout<<f(arr[n/2 + 1])<<endl;
	}
}

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

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<long long> a;
  for(int i = 0; i < n; i++){
    long long k;
    cin >> k;
    a.push(k);
  }
  
  for(int i = 0; i < m; i++){
    long long k = a.top() / 2;
    a.pop();
    a.push(k);
  }
  long long ans = 0;
  for(int i = 0; i < n; i++){
    ans += a.top();
    a.pop();
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>

#define REP(i, n) for (int i=0;i<(n);i++)
#define FOR(i, a, b) for (int i=(a);i<(b);i++)

using namespace std;

int Q;
long long int A[101], B[101];

int main()
{
    scanf("%d", &Q);
    REP(i, Q)
        scanf(" %lld %lld", &A[i], &B[i]);

    REP(i, Q) {
        long long int prod = A[i] * B[i];
        long long int prod_sqrt = sqrt(static_cast<long double>(prod-1LL));
        long long int max_AB = max(A[i], B[i]);
        long long int min_AB = min(A[i], B[i]);
        if(prod_sqrt*(prod_sqrt+1)<prod) {
            if(min_AB<=prod_sqrt)
                printf("%lld\n", 2*prod_sqrt-1);
            else
                printf("%lld\n", 2*prod_sqrt);
        } else {
            if(min_AB<=prod_sqrt)
                printf("%lld\n", 2*prod_sqrt-2);
            else
                printf("%lld\n", 2*prod_sqrt-1);
        }
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ct = [[0] * 10 for _ in range(10)]
# print(ct)

for i in range(n + 1):
    i = str(i)
    ct[int(i[0])][int(i[-1])] += 1
# print(ct)
ans = 0
for i in range(1, 10):
    ans += ct[i][i] ** 2
for i in range(1, 10):
    for j in range(i + 1, 10):
        ans += ct[i][j] * ct[j][i] * 2
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

int main(){

ll S,W;

cin >> S >> W;

cout << (W >= S ? "unsafe" : "safe") << endl;

return 0;

}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()

int main(){
	string in;
	while(getline(cin,in)){
		rep(i,in.size()){
			if( islower(in[i]) )in[i] = toupper(in[i]);
		}
		cout << in << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int s;
    cin >> s;
    map<int, int> mp;
    bool g = true;
    int i = 2;
    int ans = 0;
    mp[s] = 1;
    while(g) {
        if(s % 2 == 0) {
            s /= 2;
        } else {
            s = 3 * s + 1;
        }
        if(mp.count(s)) {
            mp[s]++;
            if(mp[s] == 2) {
                g = false;
                ans = i;
            }
        } else {
            mp[s] = 1;
        }
        i++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,K,h[100000],n,i;
    scanf("%d%d",&N,&K);
    for(i=0,n=0;i<N;i++)
    {
    scanf("%d",&h[i]);
    if(h[i]>=K)
    {
        n=n+1;
    }
    }
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n,a[5];
    cin >> n;
    int mini = INF;
    rep(i,5){
        cin >> a[i];
        mini = min(mini,a[i]);
    }
    cout << 4+(n-1)/mini+1 << endl;

    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc123.contest.atcoder.jp/tasks/abc123_a

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    map<char,int>m;
    m['b']='d';
    m['d']='b';
    m['p']='q';
    m['q']='p';
    string S;cin>>S;
    rep(i,S.size()){
        if(m[S[i]]!=S[S.size()-1-i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 512
s = input()
min_A = len(s)
max_Z = 0
for i in range(len(s)):
    if s[i] == "A":
        if min_A>i:
            min_A = i
    if s[i] == "Z":
        if max_Z < i:
            max_Z = i
print(max_Z-min_A+1)

Measured memory_bytes: 3500
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;

// topological_sort
constexpr int MAX_N = 300003;
int used_topo[MAX_N];
vector<int> edg[MAX_N];

bool __rec_topo(vector<int> &topo, int pos) {
	if (used_topo[pos] == -1) return false;
	if (used_topo[pos] == 1) return true;
	used_topo[pos] = -1;
	for (int i : edg[pos]) {
		if (!__rec_topo(topo, i)) return false;
	}
	used_topo[pos] = 1;
	topo.push_back(pos);
	return true;
}

// Perform topological sort of the graph defined by edg.
// n: The number of vertices.
// The sorting result will be stored in the first argument topo.
// Returning false means the graph is not DAG.
bool topo_sort(vector<int> &topo, int n) {
	bool flag = true;
	for (int i = 1; i <= n; i++) {
		if (used_topo[i] == 0) flag &= __rec_topo(topo, i);
	}
	reverse(topo.begin(), topo.end());
	return flag;
}


int n, m;
int cnt[100003];
int rk[100003];
int ans[100003];

int main() {
	cin >> n >> m;
	for (int i = 0; i < n - 1 + m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		edg[a].push_back(b);
		cnt[b]++;
	}
	int rt;
	for (int i = 1; i <= n; i++) if (cnt[i] == 0) rt = i;
	vector<int> topo;
	topo_sort(topo, n);
	for (int idx : topo) {
		for (int to : edg[idx]) {
			rk[to] = max(rk[to], rk[idx] + 1);
		}
	}
	for (int idx : topo) {
		for (int to : edg[idx]) {
			if (rk[idx] + 1 != rk[to]) continue;
			ans[to] = idx;
		}
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
	return 0;
}

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

const int MAX = 3005;
const ll MOD = 998244353;

ll dp[MAX][MAX];

int main() {
  int n, s;
  cin >> n >> s;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  dp[1][0] = dp[1][A[0]] = 1;
  for (int i = 1; i < n; ++i) rep(j, MAX) {
    dp[i+1][j] += (dp[i][j] * 2 - dp[i-1][j]) % MOD;
    if (j == 0 || j == A[i]) dp[i+1][j] += 1;
    if (j+A[i] < MAX) {
      dp[i+1][j+A[i]] += (dp[i][j] - dp[i-1][j]) % MOD;
    }
  }
  ll ans = (dp[n][s] % MOD + MOD) % MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 73984
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 60;
const int MOD = (int) 1e9 + 7;

ll a[Maxn], p[Maxn];

ll rec(int l, ll x) {
    if (l == 0) {
        if (x >= 1) return 1;
        else return 0;
    }
    if (x <= a[l - 1] + 1) {
        return rec(l - 1, x - 1);
    } else {
        return p[l - 1] + 1 + rec(l - 1, x - a[l - 1] - 2);
    }
}

int n;
ll x;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x;
    a[0] = p[0] = 1;
    for (int i = 0; i < n; ++i) {
        a[i + 1] = 2 * a[i] + 3;
        p[i + 1] = 2 * p[i] + 1;
    }

    cout << rec(n, x) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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);
}

/*------------------------------------------------------------------*/
using Graph = vector<vector<int>>;

vector<bool> seen;
vector<int> depth;
vector<int> score;
vector<int> p, x;

void search_depth(const Graph &G, int v, int parent, int dep){
    depth[v] = dep;

    for(auto next_v : G[v]){
        if(next_v == parent) continue;
        search_depth(G, next_v, v, dep + 1);
    }
}
void dfs(const Graph &G, int v, int parent){
    seen[v] = true;
    score[v] += score[parent];

    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        dfs(G, next_v, v);
    }
}

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

    Graph G(n);
    depth.resize(n);
    seen.resize(n);
    p.resize(q);
    x.resize(q);
    score.resize(n);
    rep(i, n) score[i] = 0;

    rep(i, n - 1){
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, q){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    depth.assign(n, 0);
    search_depth(G, 0, -1, 0);

    rep(i, q) score[p[i]] += x[i];
    dfs(G, 0, -1);

    rep(i, n){
        if(i == n - 1){
            cout << score[i] << endl;
            return 0;
        }
        cout << score[i] << " ";
    }
}

Measured memory_bytes: 29848
#include<bits/stdc++.h>
#define  forn(i, n)  for(int i=0; i < (int)n; i++)
#define  vi          vector<int>
// #define  pb          push_back
// #define  ap          append
// #define  mii         map<int, int> 
using namespace std ;
// vector<string> splitstring(string str, string delimiter) {
//     vector<string> v;
//     string token;
//     istringstream parse(str);
//     while(getline(parse, token, delimiter)) {
//     v.push_back(token);
//     }
//     return v;
// }
// int gcd (int a, int b) {
//     if (b == 0) return a;
//     else return gcd (b, a % b);
// }
// int lcm(int a, int b){
//   return a / gcd(a,b) * b;
// }
void solve() {
  int n, m;
  cin >> n >> m;
  int a[m], sum = 0;
  for(int &i : a) {
    cin >> i;
    sum += i;
  }
  (n - sum >= 0) ? cout << n - sum : cout <<  -1 ; 

}
int main() {
  int t=1;
  //cin >> t ;
  while(t--) solve() ;
  return 0 ;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++)
    cin >> s.at(i);
  vector<vector<int>> dp(h+1,vector<int>(w+1,0));
  /*for(int i=0;i<h+1;i++){
    for(int j=0;j<w+1;j++)
      dp[i][j]=0;
  }*/
  dp[1][1]=1;
  for(int i=3;i<h+w+1;i++){
    for(int j=1;j<h+1;j++){
      if(i-j>0&&i-j<w+1){
        if(s.at(j-1).at(i-j-1)=='.')
       	  dp.at(j).at(i-j)=(dp[j-1][i-j]+dp[j][i-j-1])%1000000007;
      }
    }
  }
  cout << dp[h][w] << endl;
  /*for(int i=0;i<h+1;i++){
    for(int j=0;j<w+1;j++)
      cout << dp[i][j] << " ";
    cout << endl;
  }*/
}

Measured memory_bytes: 5248
def solve():
  a,b = (int(i) for i in input().split())
  ans = 1
  now = a
  if b == 1:
    print(0)
    exit()
  for i in range(10000):
    if now >= b:
      print(ans)
      exit()
    else:
      now += a-1
      ans +=1
    
solve()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M;
    cin >> N >> M;
    cout << min(N,M/2)+(M-min(N,M/2)*2)/4 << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;

int dp[1<<20][20];
int main(){
    int n;
    cin>>n;
    int a[n],b[n];
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    int m= 1<<n;
    rep(i,m)rep(j,n)dp[i][j]=inf;
    rep(i,n)dp[1<<i][i]=0;
    rep(i,m){
        int c=__builtin_popcount(i);
        int cnt=c;
        rep(j,n){
            if((1<<j)&i){
                --cnt;
                int pre = i^(1<<j);
                rep(k,n){
                    if((1<<k)&pre){
                        int cur = (c^k)%2?b[k]:a[k];
                        int nxt = (c^j)%2?a[j]:b[j];
                        if(cur<=nxt)dp[i][j]=min(dp[i][j],dp[pre][k]+cnt);
                    }
                }
            }
        }
    }
    int ans = inf;
    rep(i,n)ans=min(ans,dp[m-1][i]);
    if(ans==inf)cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 22784
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    while 1:
        n = int(readline())
        if not n:
            exit()

        data = sorted(int(readline()) for _ in range(n))
        print(sum(i * t for i, t in zip(range(n-1, 0, -1), data)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 5516
N,K,S=map(int,input().split())


if S<1000000000:
  x=[1000000000]*N
  for i in range(K):
    x[i]=S
else:
  x=[1]*N
  for i in range(K):
    x[i]=S
X=map(str,x)
print(' '.join(X))

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

int main(void)
{

   int r, g, b, n;
   cin >> r >> g >> b >> n;

   int cnt = 0;

   int R = (n + r - 1) / r;
   int G = (n + g - 1) / g;
   int B = (n + b - 1) / b;



   for (int i = 0; i <= R; i++)
   {
      for (int j = 0; j <= G; j++)
      {
         int sum = (n - i * r - j * g);
         if (sum % b == 0 && (sum / b) >= 0)
         {
            cnt++;
         }
      }
   }
   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var A = ReadLongs();
            long shojikin = 1000;
            long shojiKabu = 0;
            var hasKabu = false;
            for (var i = 0; i < N - 1; i++)
            {
                if (hasKabu)
                {
                    if (A[i] > A[i + 1])
                    {
                        hasKabu = false;
                        shojikin += shojiKabu * A[i];
                        shojiKabu = 0;
                    }
                }
                else
                {
                    if (A[i] < A[i + 1])
                    {
                        hasKabu = true;
                        shojiKabu = shojikin / A[i];
                        shojikin -= shojiKabu * A[i];
                    }
                }
            }
            if (hasKabu)
            {
                shojikin += shojiKabu * A[(int)N - 1];
            }
            return shojikin;
        }


        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

#define MOD 1000000007

long long fact(long long n){
    long long ret = n;
    n--;
    while(n>1){
        ret *= n;
        ret %= MOD;
        n--;
    }
    return ret;
}

int main(){
    long long N,M,res;
    
    scanf("%lld%lld",&N,&M);

    if(N-1>M || N<M-1){
        res = 0;
    }else if(N-1 == M || M-1 == N){
        res = fact(M);
        res %= MOD;
        res *= fact(N);
        res %= MOD;
    }else if(N == M){
        res = fact(M);
        res %= MOD;
        res *= fact(N);
        res %= MOD;
        res *= 2;
        res %= MOD;
    }

    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

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

  ll n;
  cin >> n;

  ll pwr2[n + 5];
  ll a[n + 5];
  ll limit = 1e18;
  for (ll i = 0; i <= n; i++) {
    cin >> a[i];
    if (i == 0)
      pwr2[i] = 1;
    else {
      pwr2[i] = min(limit, pwr2[i - 1] * 2);
    }
  }

  if (n == 0) {
    cout << ((a[0] == 1) ? 1 : -1) << en;
    return 0;
  }
  ll x[n + 5];
  x[n] = a[n];

  for (ll i = n - 1; i >= 0; i--) {
    x[i] = a[i] + min(pwr2[i] - a[i], x[i + 1]);
  }

  if (x[0] < a[0]) {
    cout << -1 << en;
    return 0;
  }

  if (x[0] != 1) {
    cout << -1 << en;
    return 0;
  }

  for (ll i = 1; i <= n; i++) {
    ll useful = x[i - 1] - a[i - 1];

    x[i] = min(x[i], useful * 2);

    if (x[i] < a[i]) {
      cout << -1 << en;
      return 0;
    }

    if (x[i] < useful) {
      cout << -1 << en;
      return 0;
    }

    if (i == n && x[i] != a[i]) {
      cout << -1 << en;
      return 0;
    }
  }

  for (ll i = n - 1; i >= 0; i--) {
    ll childs = x[i + 1];
    ll validNodes = x[i] - a[i];
    if (childs > (validNodes * 2)) {
      assert(false);
      return 0;
    }

    if (childs < validNodes) {
      assert(false);
      return 0;
    }
  }

  for (ll i = 0; i <= n; i++) {
    if (x[i] > pwr2[i]) {
      assert(false);
      return 0;
    }
    if (x[i] < a[i]) {
      assert(false);
      return 0;
    }
  }

  ll res = 0;
  for (ll i = 0; i <= n; i++) {
    res += x[i];
  }

  cout << res << en;

  return 0;
}

Measured memory_bytes: 5956
#include <stdio.h>

int a, b;

int main(void)
{
	scanf("%d %d", &a, &b);
	
	if((a + b) % 2 == 0)
	{
		printf("%d", (a + b) / 2);
	}
	
	else
	{
		printf("IMPOSSIBLE");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 100005, MAXM = 1003, Mod = 1000000007 , MAXLog = 20;



int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    int n, l;
    cin >> n >> l;
    long long sum = 0;
    for (int i = 1; i <= n; ++i) {
        sum += l + i - 1;
    }

    long long ans;
    long long diff = INT_MAX;
    for (int i = 1; i <= n; ++i) {
        long long tmp = abs(sum - (sum - (l + i - 1)));
        if (tmp < diff) {
            diff = tmp;
            ans = sum - (l + i - 1);
        }
    }

    cout << ans << '\n';

    return 0;
}

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

fun solve(a: Long, b: Long, c: Long){
    println(a + b + c - listOf(a,b,c).max()!!)
    return
}


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



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

void solve(int a0, int l) {
    vector<int> a = {a0};
    while(true) {
        int aa = a.back();
        string atmp = to_string(aa);
        sort(atmp.begin(), atmp.end());
        int mini = 0;
        for(char c : atmp) {
            mini *= 10;
            mini += c - '0';
        }
        reverse(atmp.begin(), atmp.end());
        int maxi = 0;
        for(int i = 0; i < l; ++i) {
            maxi *= 10;
            if(i < (int)atmp.size()) maxi += atmp[i] - '0';
        }
        a.push_back(maxi - mini);
        for(int i = 1; i < (int)a.size(); ++i) {
            for(int j = 0; j < i; ++j) {
                if(a[i] == a[j]) {
                    printf("%d %d %d\n", j, a[j], i - j);
                    return;
                }
            }
        }
    }
}

int main() {
    int a0, l;
    while(cin >> a0 >> l and l > 0) {
        solve(a0, l);
    }
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  int N, L;
  cin >> N >> L;
  int min = INF;
  int sum = 0;
  FOR(i, 1, N + 1) {
    int tmp = abs(L + i - 1);
    if (tmp < abs(min)) {
      min = L + i - 1;
    }
    sum += L + i - 1;
  }
  cout << sum - min;
  return 0;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("7 7");
            WillReturn.Add("1 3");
            WillReturn.Add("2 7");
            WillReturn.Add("3 4");
            WillReturn.Add("4 5");
            WillReturn.Add("4 6");
            WillReturn.Add("5 6");
            WillReturn.Add("6 7");
            //4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3 3");
            WillReturn.Add("1 2");
            WillReturn.Add("1 3");
            WillReturn.Add("2 3");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6 5");
            WillReturn.Add("1 2");
            WillReturn.Add("2 3");
            WillReturn.Add("3 4");
            WillReturn.Add("4 5");
            WillReturn.Add("5 6");
            //5
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct EdgeInfo
    {
        internal int A;
        internal int B;
    }

    static int N;
    static List<EdgeInfo> mEdgeList = new List<EdgeInfo>();

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        SplitAct(InputList[0]);
        N = wkArr[0];

        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            EdgeInfo WillAdd;
            WillAdd.A = wkArr[0];
            WillAdd.B = wkArr[1];
            mEdgeList.Add(WillAdd);
        }
        int HashiCnt = 0;
        for (int I = 0; I <= mEdgeList.Count - 1; I++) {
            if (IsHashi(I)) HashiCnt++;
        }
        Console.WriteLine(HashiCnt);
    }

    struct JyoutaiDef
    {
        internal int CurrPos;
    }

    //辺の添字を指定して、橋かを判定
    static bool IsHashi(int pSoeji)
    {
        var Stk = new Stack<JyoutaiDef>();
        JyoutaiDef WillPush;
        WillPush.CurrPos = 1;

        var VisitedSet = new HashSet<int>();
        VisitedSet.Add(1);
        Stk.Push(WillPush);

        while (Stk.Count > 0) {
            JyoutaiDef Popped = Stk.Pop();

            Action<int> PushSyori = pToInd =>
            {
                if (VisitedSet.Add(pToInd) == false) return;
                WillPush.CurrPos = pToInd;
                Stk.Push(WillPush);
            };

            for(int I=0;I<=mEdgeList.Count-1;I++){
                if (I == pSoeji) continue;
                EdgeInfo CurrEdge=mEdgeList[I];
                if (CurrEdge.A == Popped.CurrPos) PushSyori(CurrEdge.B);
                if (CurrEdge.B == Popped.CurrPos) PushSyori(CurrEdge.A);
            }
        }
        return VisitedSet.Count < N;
    }
}


Measured memory_bytes: 13532
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <string.h>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    char S[10];
	int ans,tmp=0;
	
	cin >> S;

	int str = strlen(S);
	
	rep(i,0,str){
		if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
			ans++;
		}
		else{
			if(tmp<ans){tmp = ans;}
			ans = 0;
		}
	}

	if(tmp<ans){tmp = ans;}

    cout << tmp << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n;
long long ans,p1,p2,k,p;
int a[4003],b[4003];
long long ksc(long long a,long long b)
{
    long long ans=0;
    while(b)
    {
        if(b%2)
        ans=(ans+a)%mod;
        a=(a+a)%mod;
        b/=2;
    }
    return ans;
}
void merge(int l,int mid,int r){
	int i=l,k=l,j=mid+1;
	while(i<=mid&&j<=r){
		if(a[i]<=a[j])b[k++]=a[i++];
		else b[k++]=a[j++],ans+=mid-i+1;
	}
	while(i<=mid)b[k++]=a[i++];
	while(j<=r)b[k++]=a[j++];
	for(int i=l;i<=r;i++)a[i]=b[i];
}
void mergesort(int l,int r){
	if(l<r){
		int mid=(l+r)/2;
		mergesort(l,mid);
		mergesort(mid+1,r);
		merge(l,mid,r);
	}
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		a[i+n]=a[i];
	}
	mergesort(1,n);
	p1=ans;
	mergesort(1,n*2);
	p2=ans;
	p2-=p1*2;
	if(k%2)p=ksc((k-1)/2,k);
	else p=ksc(k/2,k-1);
	p2=(p*p2)%mod;
	p2=(p2+p1*k)%mod;
	printf("%lld",p2);
	return 0;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

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

    int black = 0;
    ll ans = 0;
    string s; cin >> s;
    for (char c : s) {
        if (c == 'B') black++;
        else ans += black;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			int ta = in.nextInt();
			int ha = in.nextInt();
			if((ta|ha)==0)
				return;
			int a[]=new int[ta];
			int b[]=new int[ha];
			int ans1=-1;
			int ans2=-1;
			boolean  flag=false;
			for(int i=0; i<ta;i++)
				a[i]=in.nextInt();
			for(int j=0; j<ha;j++)
				b[j]=in.nextInt();
			int min=Integer.MAX_VALUE;
			for(int i=0;i<ta;i++)
			{			
				for(int j=0; j<ha;j++)
				{
					int sa=0;
					int sb=0;
					int tmp=a[i];
					a[i]=b[j];
					b[j]=tmp;
					for(int k=0; k<ta;k++)
						sa+=a[k];
					for(int m=0; m<ha;m++)
						sb+=b[m];
					if(sa==sb&&min>b[j]+a[i])
					{
						 ans1=b[j];
						 ans2=a[i];
						 min=a[i]+b[j];
						flag=true;
					}
					int tmp2=b[j];
					b[j]=a[i];
					a[i]=tmp2;
				}
			}
			
			if(!flag)
				System.out.println(-1);
			else
				System.out.println(ans1+" "+ans2);
		}
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <bitset>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int hdiff = h2 - h1;
    int mdiff = m2 - m1;
    int htom  = hdiff * 60;
    htom += mdiff;

    cout << htom - k << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

  while(1){
 //     cout<<S.size()<<endl;
 //     cout<<"start "<<S<<endl;
    if(S.size()>=5&&S.substr(S.size()-5,5)=="dream"){
      S.erase(S.size()-5,5);
    }else if(S.size()>=7&&S.substr(S.size()-7,7)=="dreamer"){
      S.erase(S.size()-7,7);
    }else if(S.size()>=5&&S.substr(S.size()-5,5)=="erase"){
      S.erase(S.size()-5,5);
    }else if(S.size()>=6&&S.substr(S.size()-6,6)=="eraser"){
      S.erase(S.size()-6,6);
    }else{
      cout<<"NO"<<endl;
      return 0;
    }
      //cout<<S<<endl;
    if(S.size()==0){
        cout<<"YES"<<endl;
        return 0;
    }
  }

      //cout<<S<<endl;
  //cout<<ans<<endl;

  return 0;
}
 


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

const int INF = 1e9+5;

void print(std::vector<std::vector<long long> > A){
	for(int i = 0; i<A.size(); i++){
		for(int j = 0; j<A[i].size(); j++){
			cout<<A[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
}

long long knapsack(std::vector<long long> V, std::vector<int> W, int w){
	std::vector<std::vector<long long> > k(V.size()+1, std::vector<long long> (w+1));

	for(int i = 0; i<=V.size(); i++){
		for(int j = 0; j<=w; j++){
			if(i==0 || j==0){
				k[i][j]=0;
				continue;
			}
			else if(j-W[i]>=0){
				k[i][j] = max(k[i-1][j], k[i-1][j-W[i-1]] + V[i-1]);
			}
			else
				k[i][j] = k[i-1][j];
		}
	}
	cout<<endl;
	print(k);
	return k[V.size()][w];
}
using ll = long long;
void max_self(ll& a, ll b) {
    a = max(a, b);
}
int main(){
	/*int n, w;
	cin>>n>>w;
	std::vector<long long> value;
	std::vector<int> weights;

	for(int i = 0; i<n; i++){
		long long v, W;
		cin>>W>>v;
		value.push_back(v);
		weights.push_back(W);
	}

	long long ans = knapsack(value, weights, w);
	cout<<ans<<endl;
	return 0;*/

	int n, W;
    scanf("%d%d", &n, &W);
    vector<ll> dp(W + 1); // 0 ... W
    // dp[i] - the maximum total value of items with total weight exactly i
    for(int item = 0; item < n; ++item) {
        int weight, value;
        scanf("%d%d", &weight, &value);
        // dp[0] -> dp[3] -> dp[6]
        for(int weight_already = W - weight; weight_already >= 0; --weight_already) {
        //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            max_self(dp[weight_already+weight], dp[weight_already] + value);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= W; ++i) {
        max_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}

Measured memory_bytes: 1024
module ABC139

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_A

  ! constants for this <module>
  integer(INT32), parameter, private :: len_data = 3_INT32

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_A

    ! variables for this <subroutine>
    character(len=len_data, kind=1) :: weather_estimated
    character(len=len_data, kind=1) :: weather_real
    integer(INT32)                  :: num_day

    ! support variables for this <subroutine>
    integer(INT32) :: itr

    ! STEP.01
    ! read out the given data
    read(unit=INPUT_UNIT, fmt='(A)') weather_estimated
    read(unit=INPUT_UNIT, fmt='(A)') weather_real

    ! STEP.02
    ! initialize the variables for this <subroutine>
    num_day = 0_INT32

    ! STEP.03
    ! calculate the answer of this task
    do itr = 1_INT32, len_data, 1_INT32
      if (weather_estimated(itr:itr) .eq. weather_real(itr:itr)) num_day = num_day + 1_INT32
    end do

    ! STEP.03
    ! output the answer of this task
    write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') num_day

    ! STEP.END
    return

  end subroutine task_A

end module ABC139

program main

  ! <module>s to import
  use, non_intrinsic :: ABC139

  ! require all variables to be explicitly declared
  implicit none

  call task_A

end program main

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

long long n, t, res = 0;
vector<string> v;
string x;
map<string, long long> mp;

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    string s;
    cin >> s >> t;
    v.push_back(s);
    mp[s] = t;
  }
  cin >> x;
  bool ch = 0;
  for(int i = 0; i < n; ++i) {
    if(ch) res += mp[v[i]];
    if(x == v[i]) ch = 1;
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while(true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using pii   = std::pair<int, int>;
using vi    = std::vector<int>;
using vd    = std::vector<double>;
using vc    = std::vector<char>;
using vb    = std::vector<bool>;
using vs    = std::vector<std::string>;
using vpii  = std::vector<pii>;
using vvi   = std::vector<vi>;
using vvb   = std::vector<vb>;
using vvpii = std::vector<vpii>;
template<typename A> using fn = std::function<A>;
constexpr int INF   = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD   = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
using namespace std;
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0)
    : src(s), dst(d), weight(w) {
  }
};

using Edges  = std::vector<Edge>;
using Array  = std::vector<Weight>;
using Matrix = std::vector<Array>;

class Graph {
  std::vector<Edges> g;

public:
  // clang-format off
  Graph(const int &size = 0) : g(size) { }

  void addArc(const int &src, const int &dst, const Weight &w = 1) {
    g[src].emplace_back(src, dst, w);
  }

  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }

  Graph toRootedTree(int r);
  std::vector<Weight> dijkstra(const int &src, const int &inf);
  Matrix warshallFloyd(const int &inf);
  std::pair<Weight, Edges> prim(const int &r);
  template<typename UnionFind> std::pair<Weight, Edges> kruskal();
  Weight solveTSP(const int &inf);
  // clang-format on
};

Weight Graph::solveTSP(const int &inf = std::numeric_limits<Weight>::max() / 8) {
  int n = g.size();
  Matrix dp(1 << n, Array(n, inf));
  dp[0][0] = 0;
  rep(s, 1 << n) {
    for (auto &es : g) {
      for (auto &e : es) {
        if (~s >> e.dst & 1) cmin(dp[s | 1 << e.dst][e.dst], dp[s][e.src] + e.weight);
      }
    }
  }
  return dp.back().front();
}

main {
  int v, e;
  cin >> v >> e;
  Graph g(v);
  while (e--) {
    int s, t, d;
    cin >> s >> t >> d;
    g.addArc(s, t, d);
  }
  Weight x = g.solveTSP(INF);
  cout << (x == INF ? -1 : x) << endl;
}

Measured memory_bytes: 7524
#include<stdio.h>
#include<map>
using namespace std;
int n, a;
map<int,int> mp;

int main(){
//	freopen("c.txt","r",stdin);
	scanf("%d", &n);
	while(n--){
		scanf("%d", &a);
		if(mp.count(a)){
			mp[a]++;
		}else{
			mp[a] = 1;
		}
	}
	int ans = 0;
	for(map<int,int>::iterator it = mp.begin();it!=mp.end();it++){
		if(it->second%2 != 0){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4864
using System;
using System.Collections.Generic;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            int sx = cin.nextInt();
            int sy = cin.nextInt();
            int tx = cin.nextInt();
            int ty = cin.nextInt();

            string ans = "";

            int x = tx - sx;
            int y = ty - sy;

            // 1回目
            for (int i = 0; i < x; i++)
            {
                ans += "R";
            }
            for (int i = 0; i < y; i++)
            {
                ans += "U";
            }
            for (int i = 0; i < x; i++)
            {
                ans += "L";
            }
            for (int i = 0; i < y; i++)
            {
                ans += "D";
            }

            // 1回目
            ans += "D";
            for (int i = 0; i < x + 1; i++)
            {
                ans += "R";
            }
            for (int i = 0; i < y + 1; i++)
            {
                ans += "U";
            }
            ans += "L";
            ans += "U";
            for (int i = 0; i < x + 1; i++)
            {
                ans += "L";
            }
            for (int i = 0; i < y + 1; i++)
            {
                ans += "D";
            }
            ans += "R";
            Console.WriteLine(ans);
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 34900
// English Sentence

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void)
{
        map<string, int> tango; // 単語とその登場回数を記録する
        string s, highfre_str, maxlen_str;
        int appear = 0;

        while (cin >> s) {
                ++tango[s];
        }

        for (map<string, int>::const_iterator it = tango.begin();
             it != tango.end(); ++it) {
                if (it->second > appear) {
                        highfre_str = it->first;
                        appear = it->second;
                }

                if (it->first.size() > maxlen_str.size()) {
                        maxlen_str = it->first;
                }
        }

        cout << highfre_str << " " << maxlen_str << endl;

        return 0;
}

Measured memory_bytes: 1196
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
nokori = a[-1]
ret = 0
for i in range(n-1,-1,-1):
    ret += min(b[i],a[i]+nokori)
    nokori = max(0,min(a[i],a[i]+nokori-b[i]))
print(ret)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int d;
    cin >> d;
    cout << "Christmas";
    rep(i, 0, 25 - d){
        cout << " Eve";
    }
    cout << endl;
}

Measured memory_bytes: 764