akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int a;
  cin >> a;
  if(a==7||a==5||a==3) cout << "YES" <<endl;
  else cout<<"NO" <<endl;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int count=0;
  int num = 1;
  for(int i=0; i < n; i++){
    while (num < n+1){
      num = k*num;
      count = count+1;
      break;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
while True:
    a, l = map(int, input().split())
    if a == l == 0:
        break

    nums = [a]
    cnt = 0

    while True:
        cnt += 1
        li = list()

        for i in reversed(range(l)):
            li.append(a // (10 ** i))
            a %= 10 ** i

        amin = int(''.join(map(str, sorted(li))))
        amax = int(''.join(map(str, sorted(li, reverse = True))))
        a = amax - amin

        if a in nums:
            print(nums.index(a), a, cnt - nums.index(a))
            break
        else:
            if cnt <= 20:
                nums.append(a)
            else:
                break


Measured memory_bytes: 5604
#pragma GCC optimize("Ofast", "unroll-loops")

// #define TEST

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

const ll mod = 1000000007LL;

// aのb乗を求める.
ll modpow(ll a, ll b) {
	if (a > mod) a %= mod;
	if (b == 0LL) return 1LL;
	ll tmp = modpow(a, b / 2);
	if (b & 1LL)
		return tmp * tmp % mod * a % mod;
	return tmp * tmp % mod;
}

// aの逆元を求める.
ll inverse(ll a) {
	return modpow(a, mod - 2);
}

// kの階乗を計算する.(sgnを0以外に設定すると逆元を返す)
ll fact(ll k, int sgn = 0) {
	static vector<ll> fac(2, 1LL);
	static vector<ll> inv(2, 1LL);
	static vector<ll> finv(2, 1LL);
	static ll nx = 2LL;
	while (nx <= k) {
		fac.push_back(fac[nx - 1] * nx % mod);
		inv.push_back(mod - inv[mod % nx] * (mod / nx) % mod);
		finv.push_back(finv[nx - 1] * inv[nx] % mod);
		++nx;
	}
	if (sgn == 0)
		return fac[k];
	return finv[k];
}

// aCbを計算する.
ll comb(ll a, ll b) {
	if (b < 0 || b > a) return 0;
	return fact(a) * fact(b, 1) % mod * fact(a - b, 1) % mod;
}

int n;
vector<vector<int>> g;

vector<int> c;
vector<ll> a;
void dfs(int s = 0, int p = -1) {
	int _c = 1;
	for (int nx : g[s]) {
		if (nx != p) {
			dfs(nx, s);
			_c += c[nx];
		}
	}
	c[s] = _c;
	ll _a = fact(_c - 1LL);
	for (int nx : g[s]) {
		if (nx != p) {
			_a *= a[nx];
			_a %= mod;
			_a *= fact(c[nx], 1);
			_a %= mod;
		}
	}
	a[s] = _a;
}

vector<ll> res;
void solve(int s = 0, int p = -1) {
	if (s == 0) res[0] = a[0];
	else {
		ll tmp = res[p];
		tmp *= c[s];
		tmp %= mod;
		// tmp *= inverse((ll)n - c[s]);
		tmp *= fact((ll)n - c[s], 1) * fact((ll)n - c[s] - 1) % mod;
		tmp %= mod;
		res[s] = tmp;
	}
	for (int nx : g[s]) {
		if (nx != p) {
			solve(nx, s);
		}
	}
}

int main() {
	cin >> n;
	g.resize(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	c.resize(n);
	a.resize(n);
	dfs();
#ifdef TEST
	cout << "----c----" << endl;
	for (auto ci : c) cout << ci << " ";
	cout << endl;
	cout << "----a----" << endl;
	for (auto ai : a) cout << ai << " ";
	cout << endl;
#endif
	res.resize(n);
	solve();
	for (auto resi : res)
		cout << resi << endl;
	return 0;
}

Measured memory_bytes: 22632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace codeFes2016 {
    class Program {
        static int[] ai;
        static void Main(string[] args) {
            int pair = 0;
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            ai = new int[str.Length];
            for(int i = 0; i < str.Length; i++) {
                ai[i] = int.Parse(str[i]);
            }
            for(int i = 0; i < ai.Length; i++) {
                if (ai[ai[i] - 1] == (i + 1)) {
                    pair++;
                }
            }
            Console.WriteLine(pair/2);
        }
        static void rab() { }
    }
}


Measured memory_bytes: 9688
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	cout<<((H-h)*(W-w));
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int n;cin>>n;
  int a[4],b[4];
  rep(i,3)cin>>a[i];
  rep(i,3)cin>>b[i];
  a[3]=b[3]=1;
  ll dp[n+1];
  dp[0]=0;
  rep(i,1,n+1){
    dp[i]=dp[i-1];
    rep(j,4){
      if(n>=a[j]&&i>=a[j]){
        chmax(dp[i],dp[i-a[j]]+b[j]);
      }
    }
  }
  ll newn=dp[n];
  ll dp2[newn+1];
  auto dp3=n;
  dp2[0]=0;
  rep(i,1,newn+1){
    dp2[i]=dp2[i-1];
    rep(j,4){
      if(newn>=b[j]&&i>=b[j]){
        chmax(dp2[i],dp2[i-b[j]]+a[j]);
      }
    }
  }
  cout<<dp2[newn]<<endl;
}
  
  

Measured memory_bytes: 195584
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(20)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int K, A, B; cin >> K >> A >> B;
  if(A-B<=0 and A < K) cout << -1 << endl;
  else if(A-B<=0 and A>=K) cout << 1 << endl;
  else {
    int plus = A-B;
    int ans = 1;
    K -= A; ans += (K+plus-1)/plus * 2;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int i,n,k,x,y;
  int total = 0;
  
  scanf("%d",&n);
  scanf("%d",&k);
  scanf("%d",&x);
  scanf("%d",&y);
  
  for( i = 1; i <= n; i++ ){
    if( i <= k ){
      total += x;
    } else {
      total += y;
    }    
  }
  
  printf( "%d\n", total );
  
  return 0;
}


Measured memory_bytes: 2152
from itertools import combinations_with_replacement as c
N, M, Q = map(int,input().split())
l1 = list(list(map(int,input().split())) for _ in range(Q))

ans = 0

for l2 in c(range(1, M + 1), N):
  total = 0
  for i in range(Q):
    if l2[l1[i][1] - 1] - l2[l1[i][0] - 1] == l1[i][2]:
      total += l1[i][3]
  ans = max(ans, total)

print(ans)

Measured memory_bytes: 9196
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
 
using namespace std;
 
typedef long long ll;
 
const int MAXN = 200005;
 
int n;
int a[MAXN];
 
ll ans;
ll sum[MAXN];
 
int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n;i++)
	{
		scanf("%d",&a[i]);
		sum[i] = sum[i - 1] + a[i];
	}
	sort(sum,sum + n + 1);
	int cnt = 0;
	for (int i = 0;i <= n;i++)
		if (i > 0 && sum[i] != sum[i - 1])
			ans += (ll)cnt * (cnt - 1) / 2,cnt = 1;
		else
			cnt++;
	ans += (ll)cnt * (cnt - 1) / 2;
	printf("%lld\n",ans);
	return 0;
}

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

#define MN 2001000
#define MOD 1000000007

using namespace std;
typedef long long ll;

ll n, ans, a[MN], txor, ac[MN], dp[MN], adp[MN];
vector<int> occ[MN];

ll zs(int l, int r) {
    int L = lower_bound(occ[0].begin(), occ[0].end(), l) - occ[0].begin();
    int R = lower_bound(occ[0].begin(), occ[0].end(), r) - occ[0].begin();
    return R - L;
}

ll p[MN][2];
ll solve(int pos, int empt) {
    if(pos > n) return !empt;

    ll &x = p[pos][empt];
    if(x != -1) return x;
    x = 0;

    ll xo = a[pos], j = pos;
    while(xo != 0) {
        xo ^= a[++j];
    }

    x = (solve(j + 1, 0) + solve(j + 1, 1)) % MOD;
    return x;
}

int main() {
    scanf("%lld", &n);
    memset(p, -1, sizeof p);

    for(int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        txor ^= a[i];
    }

    a[0] = ac[0] = txor;
    occ[txor].push_back(0);
    for(int i = 1; i <= n; i++) {
        txor ^= a[i];
        ac[i] = txor;
        occ[txor].push_back(i);
    }
    txor = ac[0];

    dp[n+1] = 0;
    for(int i = n; i > 0; i--) {
        int ai = ac[i-1];
        int l = lower_bound(occ[ai].begin(), occ[ai].end(), i-1) - occ[ai].begin();
        int r = l + 1;

        assert(l < occ[ai].size() && occ[ai][l] == i - 1);

        if(r == occ[ai].size()) dp[i] = 1, adp[i] = 1;
        else {
            ll z = zs(i, occ[ai][r]);
            dp[i] = (dp[occ[ai][r]+1] + z * adp[occ[ai][r]+1]) % MOD;
            adp[i] = (adp[occ[ai][r]+1] + dp[i]) % MOD;
        }
    }

    if(txor == 0) {
        for(int i = 1; i + 1 <= n; i++) {
            if(ac[i]) ans += dp[i+1];
            if(ans >= MOD) ans -= MOD;
        }
        ans += solve(1, 0);
        if(ans >= MOD) ans -= MOD;
    }
    else ans = dp[1];

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


Measured memory_bytes: 126064
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int A[100];
    for(int i = 0;i < N;++i) cin >> A[i];
    int flag = 1, count = 0;
    while(flag){
        flag = 0;
        for(int i = N - 1;i > 0;--i){
            if(A[i] < A [i-1]){
                int k = A[i];
                A[i] = A[i-1];
                A[i-1] = k;
                ++count;
                flag = 1;
            }
        }
    }
    cout << A[0];
    for(int i = 1;i < N;++i) cout << ' ' << A[i];
    cout << endl; 
    cout << count << endl;
}


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

#define BUF_SIZE 8
#define MOD_NUM (1000000000+7)
int main(void) {
  char line[BUF_SIZE];
  FILE *fp = stdin;
  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int num;
  sscanf(line, "%d", &num);

  int i;
  long power = 1;
  for(i = 2; i <= num; i++) {
    power *= i;
    power %= MOD_NUM;
  }

  printf("%ld\n", power);
  return 0;
}

Measured memory_bytes: 384
n = int(input())
a = [int(input()) for i in range(n)]

if 2 in a:
    k = 1
    while True:
        t = a[k-1]
        a[k-1] = -1
        k = t
#        print(t)
#        print(a)
        if k == -1:
            break
        elif k == 2:
            break
        
    if k == -1:
        print(-1)
    else:
        print(a.count(-1))
else:
    print(-1)

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

using namespace std;

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx, dy = ty - sy;
	for (int i = 0; i < dy; i++)
		cout << "U";
	for (int i = 0; i < dx; i++)
		cout << "R";
	for (int i = 0; i < dy; i++)
		cout << "D";
	for (int i = 0; i < dx; i++)
		cout << "L";
	cout << "L";
	for (int i = 0; i < dy + 1; i++)
		cout << "U";
	for (int i = 0; i < dx + 1; i++)
		cout << "R";
	cout << "D";
	cout << "R";
	for (int i = 0; i < dy + 1; i++)
		cout << "D";
	for (int i = 0; i < dx + 1; i++)
		cout << "L";
	cout << "U"<< endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int N = (1 << 18) + 3, C = 1 << 9, M = 1e5 + 3;

ll a[N], w[N];
ll dp[C][M];

void solve() {
    int n, q;
    cin >> n;
    
    for (int i = 1; i <= n; ++i)
        cin >> a[i] >> w[i];
    
    for (int i = 1; i < min(C, n + 1); ++i) {
        for (int j = w[i]; j < M; ++j)
            dp[i][j] = max({dp[i / 2][j], dp[i / 2][j - w[i]] + a[i], dp[i][j - 1]});
        for (int j = 1; j < w[i]; ++j)
            dp[i][j] = max(dp[i][j - 1], dp[i / 2][j]);
    }
//    for (int i = 0; i < min(C, n + 1); ++i)
//        for (int j = 0; j < 10; ++j)
//            cout << dp[i][j] << " \n"[j == 10- 1];
    
    cin >> q;
    while (q--) {
        int v, l;
        cin >> v >> l;
        
        ll res = 0;
        vector<int> scope;
        for (int i = v; ; i /= 2) {
            scope.push_back(i);
            if (i < C) break;
        }
        assert(!scope.empty());
        
        int m = (int)scope.size() - 1;
        for (int msk = 0; msk < (1 << m); ++msk) {
            ll ww = 0, p = 0;
            for (int i = 0; i < m; ++i)
                if ((msk >> i) & 1)
                    ww += w[scope[i]], p += a[scope[i]];
            if (ww <= l) {
                strain(res, dp[scope[m]][l - ww] + p);
            }
        }
        strain(res, dp[scope[m]][l]);
        
        cout << res << '\n';
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}



Measured memory_bytes: 406864
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int h, w;
char map[60][60];
int f(int a, int b) {
	int cnt = 0;
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			if (i == 0 && j == 0)continue;
			else if (map[a+i][b+j] == '#')cnt++;
		}
	}return cnt;
}
int main() {
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> map[i][j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (map[i][j] == '#')cout << '#';
			else cout << f(i, j);
		}cout << endl;
	}
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll n;



    vector<pair<ll,ll>>p;
void fs(ll a){
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        p.emplace_back(i,cnt);
    }
    return;
}


int main()
{
ll n,k;
cin>>n>>k;
ll cnt=0;
vector<ll>t(1000000);
vector<ll>town(n);
rep(i,n)cin>>town[i];
rep(i,n)town[i]--;
ll now=0;
while(0<k){  
    t[now]=cnt;
    now=town[now];
    k--;
    cnt++;
    if(t[now]!=0){
        ll a=cnt-t[now];
        k%=a;
        while(0<k){
            now=town[now];
            k--;
        }
    }
}
cout<<now+1<<endl;
}



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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

int main() {
    ios_base::sync_with_stdio(false);
    vector<int> v;

    for(int i = 0; i < 3; i++) {
        int x; cin >> x;
        v.pb(x);
    }

    sort(v.begin(), v.end());

    cout << ((v[0] == v[1] and v[0] != v[2]) or (v[1] == v[2] and v[0] != v[2])? "Yes" : "No") << endl;



    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H+1);
    for(int i = 0; i < H; ++i){
        cin >> S[i];
    }
    int sx = H-1;
    int sy = 0;
    const int dx[4] = { 1, 0, -1, 0 };
    const int dy[4] = { 0, 1, 0, -1 };
    int ans = -1;
    for(int sxi = 0; sxi < H; ++sxi){
        for(int syi = 0; syi < W; ++syi){
            sx = sxi;
            sy = syi;
            if(S[sx][sy] == '#') continue;
            int maxdist = -1;

            vector<vector<int>> dist(H+1, vector<int>(W+1, -1));
            dist[sx][sy] = 0;
            vector<vector<int> > prev_x(H+1, vector<int>(W+1, -1));
            vector<vector<int> > prev_y(H+1, vector<int>(W+1, -1));
            queue<pair<int, int>> que;
            que.push(make_pair(sx, sy));
            while(!que.empty()){
                pair<int, int> cur = que.front();
                int x = cur.first;
                int y = cur.second;
                que.pop();
                for(int dir = 0; dir < 4; ++dir){
                    int next_x = x + dx[dir];
                    int next_y = y + dy[dir];
                    if(next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) continue;
                    if(S[next_x][next_y] == '#') continue;
                    if(dist[next_x][next_y] == -1){
                        que.push(make_pair(next_x, next_y));
                        dist[next_x][next_y] = dist[x][y] + 1;
                        prev_x[next_x][next_y] = x;
                        prev_y[next_x][next_y] = y;
                    }
                }
            }
            for(int i = 0; i < H; ++i){
                for(int j = 0; j < W; ++j){
                    maxdist = max(maxdist, dist[i][j]);
                }
            }
            ans = max(ans, maxdist);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    long ans = 0;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += d[i] * d[j]; 
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>

template <typename T> void in(T &_){
	char c=getchar(); _=0; int fl=1;
	while(c<'0'||c>'9') fl=c=='-'?-1:fl, c=getchar();
	while(c>='0'&&c<='9') _=_*10+c-'0', c=getchar(); _*=fl;
}
template <typename T, typename... A> void in(T &_, A &...a){in(_); in(a...);}

#define MOD 1000000007

int N, M, bit[1<<15], f[16][1<<15], g[16][1<<15], h[1<<15];
bool map[16][16];

int ksm(int x, int y){
	int z=1;
	for(; y; y>>=1, x=1LL*x*x%MOD) if(y&1) z=1LL*z*x%MOD;
	return z;
}

void print(int x){
	for(int i=0; i<N; i++)
		putchar('0'+((x>>i)&1)); 
}

int lowbit(int x){return (x&(-x));}

int main(){
	for(int i=0; i<15; i++) bit[1<<i]=i+1;
	in(N, M);
	for(int x, y, i=1; i<=M; i++){
		in(x); in(y);
		map[x][y]=true;
	}
	for(int i=1; i<=N; i++)
		for(int j=0; j<(1<<N); j++)
			f[i][j]=f[i][j-lowbit(j)]+map[i][bit[lowbit(j)]];
	for(int i=1; i<=N; i++)
		for(int j=0; j<(1<<N); j++)
			g[i][j]=ksm(2, f[i][j])-1;	
//			if(map[i][bit[lowbit(j)]]) g[i][j]=(g[i][j-lowbit(j)]<<1|1)%MOD;
//			else g[i][j]=g[i][j-lowbit(j)];
	for(int i=0; i<(1<<N); i++){
		h[i]=1;
		for(int j=i&(i-1); j; j=i&(j-1))
			if(((j&1)^((j&2)>>1))==0 && (((i^j)&1)^(((i^j)&2)>>1))==0){
				int tmp=h[i^j];
				for(int k=j; k; k-=lowbit(k)) 
					tmp=1LL*tmp*ksm(2, f[bit[lowbit(k)]][i^j])%MOD;
				for(int k=i^j; k; k-=lowbit(k))
					tmp=1LL*tmp*g[bit[lowbit(k)]][j]%MOD;
				h[i]=(h[i]+tmp)%MOD;
			}
	}
	printf("%d\n", (ksm(2, M)-h[(1<<N)-1]+MOD)%MOD);
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string A, B, C;
	cin >> A >> B >> C;
	transform(A.begin(), A.begin()+1, A.begin(), ::toupper);
	transform(B.begin(), B.begin()+1, B.begin(), ::toupper);
	transform(C.begin(), C.begin()+1, C.begin(), ::toupper);

	cout << A[0] << B[0] << C[0] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

#define	BUFFER_LENGTH	(256)
#define	MAX_STRING_LENGTH	(100)

int
main(int argc, const char *argv[])
{
	char buffer[BUFFER_LENGTH];
	int n;
	char a[MAX_STRING_LENGTH + 1];
	char b[MAX_STRING_LENGTH + 1];
	char c[MAX_STRING_LENGTH + 1];
	int i;
	int nc;

	(void)fgets(buffer, sizeof(buffer), stdin);
	(void)sscanf(buffer, "%d\n", &n);

	(void)fgets(buffer, sizeof(buffer), stdin);
	(void)sscanf(buffer, "%s\n", a);

	(void)fgets(buffer, sizeof(buffer), stdin);
	(void)sscanf(buffer, "%s\n", b);

	(void)fgets(buffer, sizeof(buffer), stdin);
	(void)sscanf(buffer, "%s\n", c);

	nc = 0;
	for (i = 0; i < n; i++) {
		if ((a[i] != b[i]) || (b[i] != c[i])) {
			if ((a[i] != b[i]) && (b[i] != c[i]) && (a[i] != c[i])) {
				nc += 2;
			} else {
				nc += 1;
			}
		}
	}

	(void)printf("%d\n", nc);

	return 0;
}


Measured memory_bytes: 128
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, M = LI()
uv = LIR(M)
S, T = LI()
S, T = S-1, T-1

utov = [[] for i in range(N)]

for u, v in uv:
    utov[u-1].append(v-1)


ken1 = deque()
ken2 = deque()
pa = deque()

ken1_used = [False]*N
ken2_used = [False]*N
pa_used = [False]*N

pa.append(S)
pa_used[S] = True

ans = -1

while ken1 or ken2 or pa:
    ans += 1

    while ken1:
        u = ken1.popleft()
        for v in utov[u]:
            if (not ken2_used[v]):
                ken2_used[v] = True
                ken2.append(v)

    while ken2:
        u = ken2.popleft()
        for v in utov[u]:
            if (not pa_used[v]):
                if (v==T):
                    print(ans)
                    quit()
                pa_used[v] = True
                pa.append(v)    

    while pa:
        u = pa.popleft()
        for v in utov[u]:
            if (not ken1_used[v]):
                ken1_used[v] = True
                ken1.append(v)

print(-1)




"""
kenken = []

def bfs(s):
    ret = []
    bfs_map = [-1]*N
    q = deque()
    q.append(s)
    bfs_map[s] = 0
    while q:
        u = q.popleft()
        for v in utov[u]:
            if (edge[u][v] > 0) and (bfs_map[u] > bfs_map[v]):
                bfs_map[v] = bfs_map[u] + 1
                if (bfs_map[v] == 3):
                    ret.append(v)
                else:
                    q.append(v)
    return ret

for i in range(N):
    ret = bfs(i)
    kenken.append(ret)

kenkenedge = [[0]*N for i in range(N)]
for u, vs in enumerate(kenken):
    for v in vs:
        kenkenedge[u][v] = 1

def bfs_dist(S, T):
    bfs_map = [-1]*N
    q = deque()
    q.append(S)
    bfs_map[S] = 0
    while q:
        u = q.popleft()
        for v in kenken[u]:
            if (kenkenedge[u][v] > 0) and (bfs_map[u] > bfs_map[v]):
                bfs_map[v] = bfs_map[u] + 1
                if (v==T):
                    return bfs_map[T]
                else:
                    q.append(v)
    return -1

print(bfs_dist(S, T))
"""

Measured memory_bytes: 69552
#include <iostream>

int main(int argc, char* argv[])
{
    int H1, H2, M1, M2, K, res=0;
    std::cin >> H1 >> M1 >> H2 >> M2 >> K;

    while(K > 0)
    {
        if(K >= 60)
        {
            K -= 60;
            M2 -= 60;
        }

        else
        {
            M2 -= K;
            K = 0;
        }

        if(M2 < 0)
        {
            M2 += 60;
            H2 -= 1;

            if(H2 < 0)
                H2 = 23;
        }
    }

    if(H2 > H1)
    {
        res += (H2-H1)*60;
        if(M2 > M1)
            std::cout << res+(M2-M1) << std::endl;

        else
            std::cout << res+(M2-M1) << std::endl;
    }

    else if(H2 == H1 && M2 >= M1)
    {
        std::cout << M2-M1 << std::endl;
    }

    else
        std::cout << 0 << std::endl;
    return 0;
}

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

int main(){
    double W, H, x, y;
    cin >> W >> H >> x >> y;

    double res = 0;

    
    if((int)W%2 == 0 && W/2 == x && (int)H%2 == 0 && H/2 == y){
        res = (H*W)/2;
        cout << fixed << setprecision(10) << res << " " << 1 << endl;
        return 0;
    }
    
    /*
    if((int)W%2 == 0 && W/2 == x){
        res = (H*W)/2;
        cout << fixed << setprecision(10) << res << " " << 0 << endl;
        return 0;
    }
    if((int)H%2 == 0 && H/2 == y){
        res = (H*W)/2;
        cout << fixed << setprecision(10) << res << " " << 0 << endl;
        return 0;
    }
    */
    res = (H*W)/2;
    cout << fixed << setprecision(10) << res << " " << 0 << endl;
    




}

Measured memory_bytes: 256
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  vi cnt(3);
  rep(i,s.size()){
    cnt[int(s[i]-'a')]++;
  }
  if(abs(cnt[0]-cnt[1])<=1 && abs(cnt[1]-cnt[2])<=1 && abs(cnt[2]-cnt[0])<=1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

typedef std::pair<int, int> ipair;
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k;i--)
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define mp make_pair

const int mod = 1000000007;
const ld pi = acos(-1);
const int maxn = 200006;

template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}
#define IOS  std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int32_t main(){
  int i,A,B;
int temp;
cin >> A >> B;

if (B == 1) {
  cout << 0;
}
else if(A >= B){
  cout << 1;
}else{
  for(i=2;i<=40;i++){
     temp = (A-1)*(i-1) + A;
     if (temp >= B) break;
  }
  cout << i;
}
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a[4],b[4],i,j,flag0,flag1;
  while(scanf("%d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]) != EOF){
    flag0=0;
    flag1=0;
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
	if(a[i] == b[j]){
	  if(i == j){
	    flag1++;
	  }
	  else{
	    flag0++;
	  }
	}
      }
    }
    printf("%d %d\n",flag1,flag0);
  }
  return(0);
}

Measured memory_bytes: 596
import java.io.BufferedReader;
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream("./ALDS1_4_B-in1.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] s = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		int q = Integer.parseInt(br.readLine());
		int[] t = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
		
		//long start = System.nanoTime();
		int cnt = 0;
		for(int i = 0; i < q; ++i) {
			if(binarySearch(t[i], s)){
				cnt += 1;
			}
		}
		System.out.println(cnt);
		//System.out.println("Time:" + (System.nanoTime() - start) / 1000000f + " ms");

	}
	public static boolean binarySearch(int t, int[] s){
		int l = 0;
		int r = s.length;
		while(l <= r) {
			int mid = (l + r) / 2;
			if(s[mid] == t) {
				return true;
			}else if(s[mid] < t){
				l = mid + 1;
			}else{
				r = mid - 1;
			}
		}
		return false;
	}

}

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

int n;
string s;

int main()
{
    cin >> n >> s;
    int res = 0;
    for(int i = 0; i < 1000; i++)
    {
        string t = to_string(i);
        while(t.size() < 3) t.insert(t.begin(), '0');
        int pos = 0;
        rep(j, 3)
        {
            while(pos < n && s[pos] != t[j])
            {
                pos++;
            }
            pos++;
        }
        if(pos <= n)
        {
            res++;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
	int n, k;
	cin >> n >> k;
	if((n+1)/k >= 2) YOUT;
	else NOUT;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main()
{
	int n; cin >> n;
	n %= 26;
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++) {
		s[i] += n;
		if (int(s[i]) > 90) {
			s[i] = 'A' + (int)s[i] - 91;
		}
	}
	cout << s;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L[] = new int[N];
        int max = 0;
        int sum = 0;
        for(int i = 0; i < N; i++){
            L[i] = sc.nextInt();
        }
        for(int i = 0; i < N; i++){
            max = Math.max(max, L[i]);
            sum += L[i];
        }
        if(max < sum-max){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 36204
#include<stdio.h>
#include<string.h>



int main(void){
    int a,b,x=0;
    scanf("%d%d",&a,&b);
    if(a>=b){
        x=x+a;
        a--;
    }else{
        x=x+b;
        b--;
    }

    if(a>=b){
        x=x+a;
        a--;
    }else{
        x=x+b;
        b--;
    }
    printf("%d",x);



    return 0;
}

Measured memory_bytes: 128
import numpy as N
p=print
n=int(input())
c=int(N.sqrt(n*2))
if c**2+c-n*2:p('No');exit()
a=N.zeros((c+1,c))
t=N.triu_indices(c)
a[t]=a[1:].T[t]=N.arange(n)+1
p('Yes')
p(c+1)
for r in a:p(c,*map(int,r))

Measured memory_bytes: 22232
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<fstream>
#include<map>
#include<bitset>
#include<unordered_map>
#include<cstring>
#include<cctype>
using namespace std;
#define  ll long long
#define  ull unsigned long long
#define  ul unsigned long
#define all(v) v.begin(),v.end()
#define sz(n) (int)n.size()
#define pb(s) push_back(s);
#define format(n) fixed<<setprecision(n)
#define finl "\n"
#define Mohammed_Atef_Hassan fast();
#define mod 1000000007
#define INF LLONG_MAX
#define PI acos(-1)
#define clr(dp,n) memset(dp,n,sizeof dp)
#define ex(n) return cout<<n<<finl,0;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
ll fix_mod(ll x, ll y)
{
	return (y + x % y) % y;
}
void fast() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);


}
int n;
vector<vector<ll>>v;
ll mem[(int)1e5 + 10][5];
ll solve(int i, int c)
{
	if (i == n)return 0;
	ll& ret = mem[i][c];
	if (~ret)return ret;
	for (int k = 0; k < 3; k++)
	{
		if (k == c)continue;
		ret = max(ret, solve(i+1, k) + v[i][k]);
	}
	return ret;
}
int main()
{
	Mohammed_Atef_Hassan
		cin >> n;
	v = vector<vector<ll>>(n + 1, vector<ll>(3));
	for (int i = 0; i < n; i++)
		cin >> v[i][0] >> v[i][1] >> v[i][2];
	clr(mem, -1);
	ex(solve(0, 4));
}

Measured memory_bytes: 17408
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
int main() {
	int X;
	cin >> X;
	int Y = X / 100;
	int Z = X % 100;
	int sum = 0;
	for (int i = 5; i >= 1; i--) {
		sum += Z / i;
		Z %= i;
	}
	if (sum <= Y) cout << 1 << endl;
	else cout << 0 << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<string> s(n);
    vector<ll> t(n);
    string x;
    for(ll i=0; i<n; i++) {
        cin>>s[i]>>t[i];
    }
    cin>>x;
    ll ans=0;
    for(ll i=0; i<n; i++) {
        if(s[i] == x) {
            for(ll j=i+1; j<n; j++) {
                ans += t[j];
            }
            break;
        }
    }

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


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int z = sc.nextInt();
		int w = sc.nextInt();
		int[] a = new int[n + 2];
		for (int i = 0; i < n; ++i) {
			a[i + 2] = sc.nextInt();
		}
		a[0] = z;
		a[1] = w;
		// 初手：最大化
		// 後手：最小化
		System.out.println(f(1, 1, a));
	}

	long[] max = new long[2002];
	long[] min = new long[2002];
	{
		for (int i = 0; i < max.length; ++i) {
			max[i] = -Long.MAX_VALUE / 3;
			min[i] = Long.MAX_VALUE / 3;
		}
	}

	// b=0:最小化したい
	// b=1:最大化したい
	long f(int pre, int b, int[] a) {
		if (b == 0 && min[pre] < Integer.MAX_VALUE / 3) {
			return min[pre];
		}
		if (b == 1 && max[pre] > 0) {
			return max[pre];
		}
		long ret = b == 0 ? Long.MAX_VALUE / 3 : -Long.MAX_VALUE / 3;
		for (int i = pre + 1; i < a.length; ++i) {
			boolean f = i == a.length - 1;
			if (b == 0) {
				if (f) {
					ret = Math.min(ret, Math.abs(a[pre] - a[a.length - 1]));
				} else
					ret = Math.min(ret, f(i, b ^ 1, a));
			} else {
				if (f) {
					ret = Math.max(ret, Math.abs(a[pre] - a[a.length - 1]));
				} else
					ret = Math.max(ret, f(i, b ^ 1, a));
			}
		}
		if (b == 0)
			min[pre] = ret;
		else
			max[pre] = ret;
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 28128
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 2e5 + 5;
const double eps = 1e-9;
int a[MAXN], nx[MAXN];
ll dp[MAXN];

int main() {
	int n; ni(n); nai(a, n);
	a[n] = 0;
	ll ans = 0;
	for (int i = n-1; ~i; i--) {
		nx[i] = i+1;
		while (nx[i] != n && a[nx[i]] > a[i])
			nx[i] = nx[nx[i]];
		dp[i] = dp[nx[i]] + (ll)a[i] * (ll)(nx[i] - i);
		ans += dp[i];
	}
	prl(ans);
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll         	long long int
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,n)   	for(ll i =0;i<n;i++)
#define inf 		INT_MAX
#define pll 		pair<ll, pair<ll,ll>>
const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
void solve(){
	
	ll N;
	cin>>N;
	vector<ll> A(N) , B(N);
	for(ll i = 0;i<N;i++){
		cin>>A[i]>>B[i];
	}

	sort(A.begin() , A.end());
	sort(B.begin() , B.end());

	ll x,y;
	if(N & 1){
		x = A[N/2];
		y = B[N/2];
	}
	else{
		x = A[N/2 - 1] + A[N/2];
		y = B[N/2 - 1] + B[N/2];
	}
	//cout<<x<<" "<<y<<endl;
	cout<<y-x+1<<endl;
	
}
int main(){
	init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


Measured memory_bytes: 6340
#include <bits/stdc++.h>
    #include<string.h>
    using namespace std;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define endl "\n"
    #define Max(x,y,z) max(x,max(y,z))
    #define Min(x,y,z) min(x,min(y,z))
    #define fr(i,s,e) for(i=s;i<e;i++)
    #define rf(i,s,e) for(i=s-1;i>=e;i--)
    #define pb push_back
    #define eb emblace_back
    #define mp make_pair
    #define ff first
    #define ss second
    #define ll long long
    #define trace1(x)                cerr<<#x<<": "<<x<<endl
    #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
    #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
    #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
    #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
    #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
    #define vl vector<long long>
     
    #define vi vector<int> 
    #define vii vector< vector<int> >
    #define vll vector< vector<long long> >
    #define vpi vector< pair<int,int> >   
    #define vpl vector< pair<ll,ll> >   
    typedef pair<pair<int, int>,int> P;
     #define mod %1000000007
     
    bool less_vectors(const vector<int>& a,const vector<int>& b) 
    {
       return a.size() > b.size();
    }
     
    int gcd(int a,int b)
    {
    	if(a%b==0)
    		return b;
    		else
    			return gcd(b,a%b);
    }
     
    bool cmp(pair<int,pair<int,int> >  p1,pair<int,pair<int,int> > p2)
    {
    		return p1.ff>p2.ff;
    }
    
    int main()
    {
    	IOS;
    	int n,k;
		cin>>n>>k;
		vl v(n);
		for(int i=0;i<n;i++)
		{
			cin>>v[i];
		}
		ll ans=0;
		sort(v.rbegin(),v.rend());
		for(int i=0;i<k;i++)
			ans+=v[i];
			cout<<ans;
    	return 0;
    		
    } 

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

int main(){
  string s; cin>>s;
  int count=0;
  for(int i=0;i<s.size();i++){
    if(s[i] == 'o'){
    count++;
    }
  }
  if(15-s.size()+count >= 8){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=61
#define rep(i,n) for(int i=0;i<n;i++)
#define vecs(a)  sort(a.begin(),a.end());
#define vecr(a)  reverse(a.begin(),a.end());
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n;
  
  cin>>n;
  veci v(n);
  rep(i,n)cin>>v[i];cerr<<1;
  vecs(v);
  vecr(v);
  int a=0,b=0;
  rep(j,n){
    if(j==0)goto x;
    if(j%2)b+=v[j];
    else 
   x:   a+=v[j];
  }
  cout<<a-b<<endl;
}

Measured memory_bytes: 256
n = int(input())
g = [[] for _ in range(n)]
inv = [0] * n
for i in range(n - 1):
    a, b = map(int, input().split())
    g[a - 1].append((b - 1, i))
    inv[a - 1] += 1
    g[b - 1].append((a - 1, i))
    inv[b - 1] += 1
k = max(inv)
print(k)
s = [0]
d = [-1] * n
d[0] = [-2]
ans = [0] * (n - 1)
while s:
    p = s.pop()
    c = 1
    for node, idx in g[p]:
        if d[node] == -1:
            if c == d[p]:
                c += 1
            d[node] = c
            ans[idx] = c
            c += 1
            s.append(node)
for x in ans:
    print(x)


Measured memory_bytes: 40376
# -*- coding: utf-8 -*-
"""
https://abc059.contest.atcoder.jp/tasks/abc059_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s1, s2, s3):
    ans = s1[0] + s2[0] + s3[0]
    return ans.upper()


def main(args):
    s1, s2, s3 = input().split()
    ans = solve(s1, s2, s3)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060