akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll moddividing(ll x,ll y){
    vector<ll> vec(30);
    rep(i,30){
        vec[i] = y;
        y = y * y % 1000000007;
    }
    ll c = x;
    c = c * vec[0] % 1000000007;
    c = c * vec[2] % 1000000007;
    c = c * vec[9] % 1000000007;
    c = c * vec[11] % 1000000007;
    c = c * vec[14] % 1000000007;
    c = c * vec[15] % 1000000007;
    c = c * vec[17] % 1000000007;
    c = c * vec[19] % 1000000007;
    c = c * vec[20] % 1000000007;
    c = c * vec[23] % 1000000007;
    c = c * vec[24] % 1000000007;
    c = c * vec[25] % 1000000007;
    c = c * vec[27] % 1000000007;
    c = c * vec[28] % 1000000007;
    c = c * vec[29] % 1000000007;
    return c;
}

int main(){
    ll K;
    cin >> K;
    string S;
    cin >> S;
    ll len = S.size();
    vector<ll> exp_25(2000001);
    ll num = 1;
    for (ll i = 0; i < 2000001; i++){
        exp_25[i] = num;
        num = (num * 25) % 1000000007;
    }
    vector<ll> exp_26(2000001);
    num = 1;
    for (ll i = 0; i < 2000001; i++){
        exp_26[i] = num;
        num = (num * 26) % 1000000007;
    }
    vector<ll> fact(2000001);
    num = 1;
    for (ll i = 0; i < 2000001; i++){
        fact[i] = num;
        num = (num * (i + 1)) % 1000000007;
    }
    ll ans = 0;
    for (ll i = len; i <= len + K; i++){
        ll comb = moddividing(fact[i - 1], (fact[len - 1] * fact[i - len]) % 1000000007);
        comb = (comb * exp_25[i - len]) % 1000000007;
        comb = (comb * exp_26[len + K - i]) % 1000000007;
        ans = (ans + comb) % 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 51116
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int n = in.nextInt();
            int res = 0;
            while (n-- > 0) {
                res += in.nextInt() - 1;
            }
            out.println(res);
        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
int const nax = 1e6 + 10;

bool f[nax];
int n, a[nax];
int ct[nax];

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

    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d", a + i);
        ct[a[i]] ++;
    }

    for (int j = nax - 1 ; j >= 1 ; -- j) {
        if (!ct[j]) continue;
        if (ct[j] > 1) {
            f[j] = true;
        }
        for (int i = j + j ; i < nax ; i += j) {
            f[i] = true;
        }
    }

    int ans = 0;

    for (int i = 1 ; i <= n ; ++ i) {
        if (!f[a[i]]) ++ ans;
    }

    printf("%d\n", ans);
}


Measured memory_bytes: 9348
#include<iostream>
using namespace std;
int main(){
    int n;
    int a[210];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int res=0;
    while(true){
        bool exist_odd=false;
        for(int i=0;i<n;i++){
            if(a[i]&2 != 0)exist_odd=true;
        }
        if(exist_odd)break;
        for(int i=0;i<n;i++){
            a[i]/=2;
        }
        res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
n=int(input())
L=[int(input()) for i in range(n)]
#print(L)
sorted_L=sorted(L)
#print(sorted_L)

a=sorted_L[-1]
b=sorted_L[-2]

for i in range(n):
  if L[i]!=a:
    print(a)
  else:
    print(b)

Measured memory_bytes: 14112
import numpy as np
from numba import jit
@jit(cache=True)
def solve(n,k,A):
    l,r=0,0
    for ki in range(k):
        B=np.zeros(n+1,dtype=np.int64)
        for i,j in enumerate(A):
            l=max(0,i-j)
            r=min(n,i+j+1)
            B[l]+=1
            B[r]-=1
        A=np.cumsum(B[:-1])
        if A[A==n].size==n:
            break
    return A

n,k=map(int,input().split())
A=list(map(int,input().split()))
A=np.array(A)
x=solve(n,k,A)
print(*x)

Measured memory_bytes: 125660
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
忘文件操作，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),a[200005];
int sz[200005];
vector<int> g[200005];
map<int,int> dp[200005];
vector<int> res[200005];
inline void dfs(int x,int f){
	sz[x]=1;
	foreach(it,g[x]){
		int y=*it;
		if(y==f)	continue;
		dfs(y,x);
		sz[x]+=sz[y];
		int t=sz[y];
		if(dp[y].count(a[x]))	t-=dp[y][a[x]];
		res[a[x]].push_back(t);
//		cout<<"add "<<a[x]<<" "<<t<<endl;
		if(dp[x].size()<dp[y].size())	swap(dp[x],dp[y]);
		foreach(it2,dp[y])	dp[x][it2->first]+=it2->second;
	}
	dp[x][a[x]]=sz[x];
//	cout<<x<<"\t";
//	fz(i,1,n)	cout<<dp[x][i]<<" ";puts("");
}
signed main(){
	fz(i,1,n)	a[i]=read();
	fz(i,1,n-1){
		int u=read(),v=read();
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	fz(i,1,n)	res[i].push_back(n-dp[1][i]);
	fz(i,1,n){
		int sum=(n*(n+1))/2;
		foreach(it,res[i]){
//			cout<<*it<<" ";
			sum-=(*it)*((*it)+1)/2;
		}
//		puts("");
		cout<<sum<<endl;
	}
	return 0;
}

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

const ULL M = 1000000007;

ULL powm(ULL a, ULL i) {
    if (!i) return 1;
    if (i & 1) return powm(a * a % M, i >> 1) * a % M;
    return powm(a * a % M, i >> 1);
}

ULL F[10001], I[10001], iF[10001];

ULL C(ULL n, ULL r) { return F[n] * iF[r] % M * iF[n - r] % M; }
ULL P(ULL n, ULL r) { return F[n] * iF[n - r] % M; }
ULL H(ULL n, ULL r) { return C(r + n - 1, n - 1); }

struct Problem {

    void Solve() {
        F[0] = 1; for (UL i = 1; i <= 10000; i++) F[i] = F[i - 1] * i % M;
        I[1] = 1; for (UL i = 2; i <= 10000; i++) I[i] = M - M / i * I[M % i] % M;
        iF[0] = 1; for (UL i = 1; i <= 10000; i++) iF[i] = iF[i - 1] * I[i] % M;
        ULL N, K; cin >> N >> K;
        if (N < K) { cout << 0 << endl; return; }
        N -= K;
        ULL dp[1001] = {};
        dp[N] = 1;
        rep(i, K) {
            for (UL j = N; j >= K - i; j--) {
                dp[j - K + i] += dp[j];
                dp[j - K + i] %= M;
            }
        }
        cout << dp[0] << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



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

// --------------------------------------------------------------------------------
#define fastio	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------


void solve_main()
{
   	ll n,m;cin>>n>>m;
   	long long ans = 0;
   	if(n>=2)
   		ans+= (n*(n-1))/2;
   	if(m>=2)
   		ans+=(m*(m-1))/2;
   	cout<<ans<<"\n";
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve_main();
    }
    
}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
const int ZERO = 2 * 80 * 80 * 33;
std::bitset<2 * ZERO + 1> curr[80], next[80];
int a[80][80], b[80][80], nRows, nCols;
int main() {
    std::cin >> nRows >> nCols;
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            std::cin >> a[i][j];
        }
    }
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            std::cin >> b[i][j];
        }
    }
    curr[0][ZERO] = 1;
    for (int r = 0; r < nRows; r++) {
        std::fill(next,next+80,0);
        int d = std::abs(a[r][0] - b[r][0]);
        next[0] = (curr[0] << d) | (curr[0] >> d);
        for (int c = 1; c < nCols; c++) {
            d = std::abs(a[r][c] - b[r][c]);
            next[c] |= (next[c-1] << d) | (next[c-1] >> d);
            next[c] |= (curr[c] << d) | (curr[c] >> d);
        }
        std::copy(next,next+80,curr);
    }
    int answ = ZERO+1;
    for (int x = -ZERO; x <= ZERO; x++) {
        if (curr[nCols-1][x+ZERO]) {
            answ = std::min(answ,std::abs(x));
        }
    }
    assert(answ <= ZERO);
    std::cout << answ << std::endl;
    return 0;
}


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

int main() {


    while(true){

        int n,m;
        cin >> n >> m;
        if(n == 0){
            break;
        }

        vector<int> v1,v2;

        int sum1 = 0,sum2 = 0;

        for(int i=0; i<n; i++){
            int input;
            cin >> input;
            v1.push_back(input);
            sum1 += input;
        }

        for(int i=0; i<m; i++){
            int input;
            cin >> input;
            v2.push_back(input);
            sum2 += input;
        }

        pair<int,int> ans = {200,200};

        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(sum1 - v1[i] + v2[j] == sum2 - v2[j] + v1[i]){
                    if(ans.first + ans.second > v1[i] + v2[j]){
                        ans = make_pair(v1[i], v2[j]);
                    }
                }
            }
        }

        if(ans.first == 200){
            cout << -1 << endl;
            continue;
        }

        cout << ans.first << " " << ans.second << endl;


    }

    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

signed main() {
	bool res = true;
	int N;
	cin >> N;
	vector<int> a(N);
	vector<int> b(N,0);
	int maxi = -1;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		maxi = max(maxi, a[i]);
		b[a[i]]++;
	}
	for (int i = 0; i < N; i++) {
		if (a[i] < ((maxi+1) / 2)) {
			res = false;
		}
	}
	for (int i = ((maxi+1)/2); i <= maxi; i++) {
		if (b[i] == 0) {
			res = false;
		}
	}
	if (b[((maxi+1)/2)] != 1+(maxi%2)) {
		res = false;
	}
	
	if(res){
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
constexpr int ybit = 128 << 10;

auto connected_from = vector<vector<int>>(2 * ybit);
auto visited = vector<char>(2 * ybit);

void traverse(int v, int &nx, int &ny) {
    if (visited[v])
        return;
    visited[v] = true;
    (v & ybit ? ny : nx)++;

    for (auto u : connected_from[v])
        traverse(u, nx, ny);
}

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

    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;

        y |= ybit;

        connected_from[x].push_back(y);
        connected_from[y].push_back(x);
    }

    auto cnt = 0LL;
    for (auto v = 0; v < 2 * ybit; ++v) {
        if (visited[v])
            continue;
        int nx = 0, ny = 0;
        traverse(v, nx, ny);
        cnt += 1LL * nx * ny;
    }

    cout << (cnt - n) << "\n";
    return 0;
}


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

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

    bool found = true;
    // vSの先頭の文字は大文字の A である。
    if (S[0] != 'A')
    {
        found = false;
    }

    // S の先頭から 3 文字目と末尾から 2 文字目の間（両端含む）
    //に大文字の C がちょうど 1 個含まれる。
    // ex. 0123456789 -> from 2 to 8

    int end = S.size() - 1;
    int counter = 0;
    int location;
    for (int i = 2; i < end; i++)
    {
        if (S[i] == 'C')
        {
            location = i;
            counter++;
        }
    }
    // printf("counter = %d\n", counter);
    if (counter != 1)
    {
        found = false;
    }

    // 以上の A, C を除くSのすべての文字は小文字である。
    for (int i = 1; i < S.size(); i++)
    {
        if (i != location)
        {
            if (!(S[i] >= 'a' && S[i] <= 'z'))
            {
                found = false;
            }
        }
    }

    if (found == true)
    {
        cout << "AC" << endl;
    }
    else
    {
        cout << "WA" << endl;
    }

    return (0);
}

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

int main(void){
    ll x, y; cin >> x >> y;
    int res = 0;
    while(true){
        if((x<<res) <= y){
            res++;
        }else{
            break;
        }
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);
//ios::sync_with_stdio(false);

signed main()
{
    int W, B, t = 0, y = 0;
    cin >> W >> B;
    vector<vector<char>> ans(50, vector<char>(100, '.'));

    vector<vector<char>> ans2(50, vector<char>(100, '#'));
    B--;W--;


    while(B--){
        ans.at(t).at(y)='#';
        y+=2;
        if(y>99){
            y=0;
            t+=2;
        }
    }

    t=1,y=0;

    while(W--){
        ans2.at(t).at(y)='.';
        y+=2;
        if(y>99){
            y=0;
            t+=2;
        }
    }

    cout<<100<<" "<<100<<endl;
    rep(i,50)rep(j,100){
        cout<<ans[i][j];
        if(j==99)cout<<endl;
    }

    rep(i,50)rep(j,100){
        cout<<ans2[i][j];
        if(j==99)cout<<endl;
    }

}

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

const int MAX_N = 200009;
int N, T;
ll t[MAX_N];

void solve()
{
	ll ans = 0;
	ll b=0, e=T;
	for(int i=1;i<N;++i){
		if(t[i]<=e) e=max(e,t[i]+T);
		else{
			ans += e-b;
			b=t[i], e=t[i]+T;
		}
	}
	ans += e-b;
	cout << ans << '\n';
}

int main()
{
	cin >> N >> T;
	for(int i=0;i<N;++i) cin >> t[i];
	solve();
	return 0;
}

Measured memory_bytes: 1792
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


mod=1000000007
def combinations_count_mod(n, r):
    r = min(r, n - r)
    numer = reduce(lambda x,y: x*y%mod, range(n, n - r, -1), 1)
    denom = pow( reduce(lambda x,y: x*y%mod, range(1, r + 1), 1) , mod-2, mod)
    return numer * denom % mod


def main():
    S = input().strip()
    print( S.replace("?","D"))


if __name__ == '__main__':
    main()

Measured memory_bytes: 79040
#include<stdio.h>

int main(void) {
  int n;
  unsigned long ans=1, t, _tmp;
  scanf("%d", &n);
  int i;
  _Bool ov = 0;
  for(i=0; i<n; i++) {
    scanf("%lu", &t);
    if(t == 0) {
      printf("0\n");
      return 0;
    }
    _tmp = ans;
    ans = ans * t;
    if(_tmp > ans || ans > 1000000000000000000) {
      ov = 1;
    }
  }
  if (ans > 1000000000000000000 || ov == 1) {
    printf("-1\n");
  }
  else {
    printf("%lu\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1724
import math

a,b,h,m=map(int,input().split())

al=h*360/12+(m/60)*30

ss=(m/60)*360

ff=min(abs(ss-al),360-abs(ss-al))

fg=math.radians(ff)

x=pow(a,2)+pow(b,2)-2*a*b*math.cos(fg)
ans=math.sqrt(x)
print(ans)

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

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};


vector<int> to[100005];
int n;
vector<int> dist;
void dfs(int v, int d=0, int p=-1) {
    dist[v] = d;
    for (int u: to[v]) {
        if (u == p) continue;
        dfs(u, d+1, v);
    }
}

vector<int> calcDist(int s){
    dist = vector<int>(n);
    dfs(s);
    return dist;
}

ll g1(ll n, ll p) {
    if (n == 0) return 0;
    return n/p + g1(n/p,p);
}

ll g2(ll n, ll p) {
    if (n%2 == 1) {
        return 0;
//        return g1(n,p) - g2(n-1,p);
    }
    ll res = g1(n/2, p);
    if (p == 2) res += n/2;
    return res;
}
int main() {
    ll n; cin >> n;
    ll ans = min(g2(n,2), g2(n, 5));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b);i++)
#define repv(vec,v) for(v=(vec).begin(); v!=(vec).end();v++)
#define sz(vec) (int)(vec).size()
#define PB push_back
#define F first
#define S second

void solve(){
	
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin >> n >> m;
	int a;
	rep(i,1,m){
		cin >> a;
		n-=a;
	}
	cout << max(n,-1);
	
	return 0;
}


Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<int> c(5);
  while(scanf("%d,%d,%d,%d,%d",&c[0],&c[1],&c[2],&c[3],&c[4]) != EOF){
    int ans = 0;
    sort(c.begin(),c.end());
    for(int i=0; i<5; i++){
      if(i<2){
	if(c[i] == c[i+1] && c[i+1] == c[i+2] && c[i+2] == c[i+3]){
	  ans+=6;
	  i+=3;
	}
      }
      if(i<3){
	if(c[i] == c[i+1] && c[i+1] == c[i+2]){
	  ans+=3;
	  i+=2;
	}
      }
      if(i<4){
	if(c[i] == c[i+1]){
	  ans+=2;
	  i++;
	}
      }
    }
    if(ans == 6) cout <<"four card"<<endl;
    else if(ans == 5) cout <<"full house"<<endl;
    else if(ans == 4) cout <<"two pair"<<endl;
    else if(ans == 3) cout <<"three card"<<endl;
    else if(ans == 2) cout <<"one pair"<<endl;
    else if(c[0]+1 == c[1] && c[1]+1 == c[2] && c[2]+1 == c[3] && c[3]+1 == c[4]) cout <<"straight"<<endl;
    else if(c[0] == 1 && c[1] == 10 && c[2] == 11 && c[3] == 12 && c[4] == 13) cout <<"straight"<<endl;
    else cout <<"null"<<endl;
  }
  return 0;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  if (A - B*2 >= 0){
    cout << A - B*2 <<endl;
  }
  
  else if (A - B*2 < 0 ){
    cout << 0 << endl;
  }
}

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

using namespace std;

int main(){
    
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    bool ans=true;
    int count=0;
    while(ans){
        for(int i=0;i<n;i++){
            if(a[i]%2!=0){
                ans=false;
            }else{
                a[i]/=2;
            }
        }
        if(ans) count++; 
    }
    cout<<count<<endl;
}


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

using namespace std;

int main() {
    int n, m, x;
    cin>>n>>m>>x;
    
    vector<int> cost(n);
    int A[n][m];
    
    for(int i = 0;i<n;i++) {
        cin>>cost[i];
        for(int j = 0;j<m;j++) {
            cin>>A[i][j];
        }
    }
    
    int ret = INT_MAX;
    for(int mask = 0;mask<(1<<n);mask++) {
        vector<int> knowledge(m);
        int c = 0;
        for(int i = 0;i<n;i++) {
            if((mask & (1<<i))) {
                c += cost[i];
                for(int j = 0;j<m;j++) {
                    knowledge[j] += A[i][j];
                }
            }
        }
        
        
        
        bool ok = true;
        for(int i = 0;i<m;i++) {
            if(knowledge[i] < x) {
               ok = false;
            }
        }
        if(ok) ret = min(ret, c);
    }
    
    if(ret == INT_MAX) {
        cout<<-1<<endl;
    } else {
        cout<<ret<<endl;
    }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+5;
int n, a[N];
main() {
    cin >> n;
    for(int i=0; i<n; i++)  cin >> a[i];
    sort(a, a+n, greater<int>());
    int S = a[0];
    for(int i=1, j=2; i<n; i++) {
        if(j == n)  break;
        S += a[i]; 
        j++;
        if(j < n) {
            S += a[i];
            j++;
        }
    }
    cout << S;
}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
#define pw(x) (1LL << (x))
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl

using namespace std;
typedef long long ll;
typedef double dbl;
const int INF = 1.01e9;

const int MOD = 998244353;
const int N = (int)1.01e6;

int fct[N], ofct[N];

void add(int &a, ll b) {
    a = (a + b) % MOD;
}

int getC(int n, int k) {
    if (k < 0 || n < k || n < 0) return 0;
    return 1LL * fct[n] * ofct[k] % MOD * ofct[n - k] % MOD;
}

int bin(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        n >>= 1;
    }
    return res;
}

int inv(int x) {
    return bin(x, MOD - 2);
}

// slower, but works for non-prime modulo m
int rev(int x, int m) {
    if (x == 1) return 1;
    return (1 - rev(m % x, x) * (ll)m) / x + m;
}

void init() {
    fct[0] = 1;
    for (int i = 1; i < N; i++) fct[i] = 1LL * fct[i - 1] * i % MOD;
    ofct[N - 1] = inv(fct[N - 1]);
    for (int i = N - 2; i >= 0; i--) ofct[i] = 1LL * ofct[i + 1] * (i + 1) % MOD;
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif
    init();

    int n, a, b;
    ll k;
    while (cin >> n >> a >> b >> k) {
        int ans = 0;
        for (int i = 0; i <= n; i++ ){
            if (1LL * i * a <= k) {
                if ((k - 1LL * i * a) % b == 0) {
                    ll j = (k - 1LL * i * a) / b;
                    if (j <= n) {
                        add(ans, 1LL * getC(n, i) * getC(n, j));
                    }
                }
            }
        }
        cout << ans << endl;
    }

#ifdef HOME
    cerr << "time = " << (clock() * 1. / CLOCKS_PER_SEC) << "\n";
#endif
    return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>

int main(void) {
	int N;
	while(scanf("%d",&N)==1 && N>0) {
		char input[128];
		int i,j;
		int ba=0;
		int player[10]={};
		scanf("%s",input);
		for(i=0;i<100;i++) {
			switch(input[i]) {
				case 'M':
					player[i%N]++;
					break;
				case 'S':
					ba+=player[i%N]+1;
					player[i%N]=0;
					break;
				case 'L':
					player[i%N]+=ba+1;
					ba=0;
					break;
			}
		}
		for(i=N-1;i>0;i--) {
			for(j=0;j<i;j++) {
				if(player[j]>player[j+1]) {
					int temp=player[j];
					player[j]=player[j+1];
					player[j+1]=temp;
				}
			}
		}
		for(i=0;i<N;i++)printf("%d ",player[i]);
		printf("%d\n",ba);
	}
	return 0;
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  long long money = 1000, stock = 0;
  bool prev = false;
  for (int i = 0; i < N - 1; i++) {
    if (prev) {
      money += stock * A[i];
      stock = 0;
      prev = false;
    }
    if (A[i] < A[i + 1]) {
      long long num = money / A[i];
      money -= num * A[i];
      stock = num;
      prev = true;
    }
  }
  if (prev) {
    money += stock * A[N - 1];
    prev = false;
  }
  cout << money << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<stdio.h>
int main(void){
    int i, j, k, m, n, key, Key, waru, digit;
    char s[100000], S[100000], c[100000], C[100000];
    scanf("%d", &n);
    scanf("%s", s);
    while ( n-- ) {
        j = 0;
        key = 1;
        for ( i = 0; i < strlen(s); i++ ) {
            if ( s[i] == s[i + 1] ) key++;
            else {
                Key = key;
                digit = 0;
                waru = 1;
                while ( Key != 0 ){
                    Key /= 10;
                    digit++;
                }
                digit--;
                while ( digit-- ) waru *= 10;
                while (waru) {
                    Key = key;
                    Key /= waru;
                    if ( Key == 0 ) S[j] = '30';
                    if ( Key == 1 ) S[j] = '31';
                    if ( Key == 2 ) S[j] = '32';
                    if ( Key == 3 ) S[j] = '33';
                    if ( Key == 4 ) S[j] = '34';
                    if ( Key == 5 ) S[j] = '35';
                    if ( Key == 6 ) S[j] = '36';
                    if ( Key == 7 ) S[j] = '37';
                    if ( Key == 8 ) S[j] = '38';
                    if ( Key == 9 ) S[j] = '39';
                    key %= waru;
                    waru /= 10;
                    j++;
                }
                S[j] = s[i];
                j++;
                key = 1;
            }
        }
        memset( s , '\0' , strlen(s) );
        for ( i = 0; i < strlen(S); i++ ) s[i] = S[i];
        memset( S , '\0' , strlen(S) );
        if ( n == 0 ) {
            printf("%s\n", s);
            memset( s , '\0' , strlen(s) );
            scanf("%d", &n);
            if ( n == 0 ) break;
            scanf("%s", s);
        }
    }
    return 0;
}

Measured memory_bytes: 1816
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var l, r int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &l, &r)

	m := 2019
	for i := l; i <= r; i++ {
		for j := i + 1; j <= r; j++ {
			if m > (i*j)%2019 {
				m = (i * j) % 2019
			}
			if m == 0 {
				fmt.Println(0)
				return
			}
		}
	}
	fmt.Println(m)
}


Measured memory_bytes: 1840
package main

import "fmt"

func main() {
	var N, K int
	MOD := 1000000000 + 7
	fmt.Scan(&N, &K)
	// N+1=4, 4c2+4c3+4c4 = 6+4+1
	// MaxとMinの差っぽい（1ずつだとその間のやつの種類は作れるので）
	ans := 1
	for i := K; i < N+1; i++ {
		min_d := i * (i + 1) / 2
		// fmt.Printf("maxの初項は %d\n", N+2-i)
		max_d := i * (2*(N+2-i) + (i - 1)) / 2
		// fmt.Println(min_d, max_d)
		ans += max_d - min_d + 1
		ans %= MOD
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1752
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define MAXN ((ll)2e5+5)
#define MOD ((ll)1e9 + 7) 
#define ll long long
#define _ << " " <<
#define TRACE(x) cerr << #x << " = " << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"

ll n,m,t,k;
ll h[MAXN];
ll a[MAXN];

ll seg[4*MAXN];

void update(ll index, ll start, ll end, ll x, ll val)
{
	if(start > x or end < x) return;

	if(start == end && start == x){
		seg[index] = val;
		return;
	}

	ll mid = (start+end)/2;
	update(index*2, start, mid, x, val);
	update(index*2+1, mid+1, end, x, val);

	seg[index] = max(seg[index*2] , seg[index*2+1]);
}
ll find(ll index, ll start, ll end, ll l, ll r)
{
	if(start > r or end < l) return 0;

	if(start >= l and end <= r) return seg[index];

	ll mid = (start+end)/2;
	ll lv = find(index*2, start, mid, l, r);
	ll rv = find(index*2+1, mid+1, end, l, r);
	return max(lv,rv);
}

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

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

	for (ll i = 0; i < n; ++i)
	{
		ll res = find(1,1,n,1,h[i]);
		update(1,1,n,h[i],a[i]+res);
	}

	cout << seg[1] << endl;

	return 0;
}


Measured memory_bytes: 9600
#include <limits.h>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
	int a, b;
	cin >> a >> b;
  	long long c[a];
  	int ans = a;
   	long long m = LONG_MAX;
	for(int i = 0; i < a; ++i){
      cin >> c[i];
    }
  	for(int i = 0; i < a; ++i){
      b -= c[i];
      m = min(m, c[i]);
    }
	while(b > 0){
      b -= m;
      if(b >= 0) ans++;
    }
  	cout << ans << endl;
}

Measured memory_bytes: 256
a = [int(input()) for _ in range(5)]
k = int(input())
res = False
for i in range(len(a)):
  for j in range(i + 1, len(a)):
    if a[j] - a[i] > k:
      res = True
      break
  else:
    continue
if res:
  print(':(')
else:
  print('Yay!')
  

Measured memory_bytes: 3060
n, m=map(int, raw_input().split())
adj=[[] for i in range(n+1)]
for i in range(m):
	a, b=map(int, raw_input().split())
	adj[a].append(b)
	adj[b].append(a)
visited=[False]*(n+1)
def dfs(cur):
	result=[]
	while True:
		result.append(cur)
		found=False
		for to in adj[cur]:
			if not visited[to]:
				visited[to]=True
				cur=to
				found=True
				break
		if not found:
			break
	return result
for i in range(n+1):
	if adj[i]:
		to=adj[i][0]
		visited[i]=True
		visited[to]=True
		result=list(reversed(dfs(to)))+dfs(i)
		print len(result)
		for cur in result:
			print cur,
		print
		exit()


Measured memory_bytes: 26732
s = gets.chomp
array = s.chars.map(&:to_i)
count = 0

(1..array.size-1).each do |n|
  if array[n-1] == array[n]
    count += 1
    if array[n-1] == 0
      array[n] = 1
    else
      array[n] = 0
    end
  end
end

puts count

Measured memory_bytes: 20068
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#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
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

int dp[101][10010] = {};
int v[101];
int w[101];

/*----------------------------------------------------------------*/
signed main(){

    int N,W;
	cin >> N >> W;
	rep(i,N)cin >> v[i] >> w[i];
	rep(i,N){
		rep(j,W+1){
			dp[i+1][j] = dp[i][j];
			if(j-w[i] >= 0)dp[i+1][j] = max(dp[i+1][j],dp[i+1][j-w[i]] + v[i]);
		}
	}
	cout << dp[N][W] << endl;

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://abc088.contest.atcoder.jp/tasks/abc088_d


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

int main(void){
	int k;
	cin>>k;
	int a=k/2,b=(k+1)/2;
	cout<<a*b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX 100005
using namespace std;
using ll = long long;

bool ac[MAX];
int wa[MAX];

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

  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; ++i) {
    int p;
    string s;
    
    cin >> p >> s;

    if (ac[p]) continue;
  
    if (s == "AC") ac[p] = true;
    else ++wa[p];
  }

  int a = 0, w = 0;
  for (int i = 1; i <= n; ++i) {
    if (ac[i]) {
      ++a;
      w += wa[i];
    }
  }

  cout << a << " " << w << '\n';

  return (0);
}


Measured memory_bytes: 4048
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
	    List<Pair> pairList = new ArrayList<Pair>();

		for(int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();

			Pair pa = new Pair(x, y);

			pairList.add(pa);
		}

	    Comparator<Pair> comparator = Comparator.comparing(Pair::getX)
	    		.thenComparing(Pair::getY);

	    Collections.sort(pairList, comparator);

	    for(int i = 0; i < n; i++) {
	    		System.out.println(pairList.get(i).getX() + " " + pairList.get(i).getY());
	    }

	}
}

class Pair {
	private int x;
	private int y;

	Pair(int a, int b) {
		this.x = a;
		this.y = b;
	}

	public int getX() {
		return this.x;
	}

	public int getY() {
		return this.y;
	}
}



Measured memory_bytes: 118856
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string  s;
  cin >> s;
  int e =0;
  for (int i = 0 ; i <= n ;i++) {
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] =='C') {
      e++; }
  }
  cout << e ; }
      

Measured memory_bytes: 256
#include<iostream> 
#include<cmath>
#include<algorithm>
using namespace std;
int n;
long long int k;
long long a[200005],f[200005];
bool cmp(int a,int b)
{
	return a>b;
}
int check(long long mid)
{
	long long cnt=0;
	int i;
	for(i=1;i<=n;i++)
	{
		if(a[i]*f[i]>mid)
		{
			if((a[i]*f[i]-mid)%f[i]==0)cnt+=(a[i]*f[i]-mid)/f[i];
			else cnt+=(a[i]*f[i]-mid)/f[i]+1;
		}
	}
	return cnt<=k?1:0;
}
int main()
{
	cin>>n>>k;
	int i;
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&f[i]);
	}
	sort(a+1,a+n+1);
	sort(f+1,f+n+1,cmp);
	long long l=0,r=1e12,mid;
	while(l<r)
	{
		mid=(l+r)/2;
		if(check(mid))
		{
			r=mid;
		}
		else
		{
			l=mid+1;
		}
	}
	cout<<l;
	return 0; 
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
using namespace std;

long long gcd(long long a, long long b) {
	return b == 0 ? a : gcd(b, a%b);
}

int main() {
	long long N, h, n, w;
	scanf("%lld", &N);
	for(int h = 1; h <= 3500; ++h) {
		for(int n = 1; n <= 3500; ++n) {
			long long a = h * n, b = h + n;
			long long c = 4 * a - N * b, d = N * a;
			if(c <= 0 || d <= 0) {
				continue;
			}
			long long GCD = gcd(c, d);
			if(c == GCD) {
				printf("%lld %lld %lld\n", h, n, d / GCD);
				return 0;
			}
		}
	}
	return 0;
}

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



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    string s;
    while(cin>>s){
        if(s=="0")break;
        int dp[11][2]={};
        int x=0;
        int n = s.size();
        int ans = 0;
        for(int i=0;i<n;i++){
            dp[0][x]++;
            x^=1;
            for(int j=0;j<11;j++) dp[j][x]=0;
            for(int j=0;j<11;j++){
                int p = (j*10+s[i]-'0')%11;
                if(j==0 && s[i]=='0') dp[p][x]--;
                dp[p][x] += dp[j][x^1];
            }
            ans += dp[0][x];
            
        }
        cout << ans << "\n";
    }
    
}


Measured memory_bytes: 3300
N,C = map(int,input().split())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
A = [0]
B = [0]
k = 0
for i in range(N):
  k += L[i][1]
  p = max(A[i],k-L[i][0])
  A.append(p)
k = 0
for i in range(N):
  k += L[N-i-1][1]
  p = max(B[i],k-(C-L[N-i-1][0]))
  B.append(p)
ans = max(A[N],B[N])
t = 0
for i in range(N):
  b = L[N-i-1][0]
  t += L[N-i-1][1]
  if ans <= t-2*(C-b)+A[N-i-1]:
    ans = t-2*(C-b)+A[N-i-1]
t = 0
for i in range(N):
  a = L[i][0]
  t += L[i][1]
  if ans <= t-2*a+B[N-i-1]:
    ans = t-2*a+B[N-i-1]
print(ans)

Measured memory_bytes: 35348
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
int t[50],ans;
string s[50],x;
bool f;
int main(){
	cin>>n;
	rep(i,n){
		cin>>s[i]>>t[i];
	}
	cin>>x;
	rep(i,n){
		if(f){
			ans+=t[i];
			continue;
		}
		if(s[i]==x)
		f=true;
	}
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, M, K = tuple(map(int, input().split()))

list_ = [M*n for n in range(N+1)]
uni = set()

for n, l in enumerate(list_):
    uni.update([(l - n*m + (N-n)*m) for m in range(M+1)])

if K in uni:
    print("Yes")
else:
    print("No")

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


void solve(long long a, long long b){
  if((a <= 0) && (0 <= b)) {
    cout << "Zero" << endl;
  }
  else if((a > 0) || ((((a-1)-min(0ll,b)) % 2) == 0)) {
    cout << "Positive" << endl;
  }
  else {
    cout << "Negative" << endl;
  }

  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define debug(x) cout << '>' << #x << ':' << x << endl
using namespace std;
using ll = long long;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int &x: a) cin >> x;
    long sum = accumulate(a.begin(), a.end(), 0L);
    cout << max(-1L, (long)n - sum) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T;
    T = 1;
    // cin >> T;
    for (int t = 1; t <= T; t++){
        // cout << "Case #" << t << ": ";
        solve();
    }
	return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> vr[n+1];
    vector<int> out(n+1,0);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin >> a >> b;
        vr[b].push_back(a);
        out[a]++;
    }
    queue<int> q;
    for(int i=1;i<=n;i++) if(out[i]==0) q.push(i);
    vector<int> dp(n+1,0);
    while(!q.empty())
    {
        int a=q.front();
        q.pop();
        for(int to:vr[a])
        {
            dp[to]=max(dp[to],dp[a]+1);
            out[to]--;
            if(out[to]==0) q.push(to);
        }
    }
    int res=0;
    for(int i=1;i<=n;i++) res=max(res,dp[i]);
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 6528
# include <bits/stdc++.h>
using namespace std;
# define lli long long int
# define MOD 1000000007

void solve(){
    int n, k;
    cin >> n >> k;

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

    int dp[k + 1] = {0};
    for(int i = 1; i <= k; i++){
        for(int j = 0; j < n; j++){
            if(i - arr[j] >= 0 and dp[i - arr[j]] == 0){
                dp[i] = 1;
                break;
            }
        }
    }

    cout << (dp[k] == 1 ? "First" : "Second");

}



int main(){
    solve();
}

Measured memory_bytes: 4012
#include <iostream>

int main() {
    int N, M;
    std::cin >> N >> M;

    for (int gcd = M / N; gcd > 0; --gcd) {
        if (M % gcd == 0) {  // ≡ M % (gcd*N) % gcd
            std::cout << gcd << '\n';
            return 0;
        }
    }

    return 1;
}

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 < 4; i++ ){
    for( int j = i+1; j < 4; j++ ){
      if( S.at(i) == S.at(j) ){
        count++;
      }
    }
  }
  
  if( count == 2 ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

ll calc2(const vector<int>& t, int d1, int d2){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d1 && i!=d2){
      res += s[i][t[i]];
      lst[t[i]] = i;
    }
    else if(i==d1){
      res += s[i][d1];
      lst[t[d1]]=i;
    }
    else if(i==d2){
      res += s[i][d2];
      lst[t[d2]]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}

int main(){
  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(184);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);
  ll now = calc(t, -1, -1);
  rep(d,D){
    int k=-1;
    ll prenow=-1;
    rep(q,26){
      ll pre = calc(t,d,q);
      if(now < pre){
        if(mt()&1 || mt()&1 || mt()&1) {
          now = pre;
          t[d] = q;
        }
        if(k==-1) {k=q; prenow = pre;}
      }
      if(chmax(now,calc(t,d,q))){
        t[d]=q;
      }
      end = chrono::system_clock::now();
      double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
      if(ela>1900) break;
    }
    if(t[d]==-1) {
      t[d]=k;
      now = prenow;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  while(1){
    int d1=mt()%365, d2=mt()%365;
    if(d1==d2) continue;
    if(chmax(now,calc2(t,d1,d2))){
      int tmp = t[d1];
      t[d1]=t[d2];
      t[d2]=tmp;
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1970) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3688
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  set_bool_name("YES", "NO");
  int x;
  cin >> x;
  cout << (x == 3 || x == 5 || x == 7) << endl;
}



Measured memory_bytes: 256