akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <tuple>
#include <unordered_map>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

namespace std {
    template <>
    class hash<tuple<llong, llong, llong> > {
    public:
        size_t operator()(const tuple<llong, llong, llong> &x) const {
            return hash<llong>()(get<0>(x)) ^ hash<llong>()(get<1>(x)) ^ hash<llong>()(get<2>(x));
        }
    };
}

llong n;
string str;

llong base[3] = {101, 117, 107};
llong basep[3][100005];
llong hsh[3][100005];
const llong mod = (llong)(1e9) + 7;

void build() {
    basep[0][0] = basep[1][0] = basep[2][0] = 1;

    for (int i = 0; i < 100003; i++) {
        basep[0][i + 1] = basep[0][i] * base[0] % mod;
        basep[1][i + 1] = basep[1][i] * base[1] % mod;
        basep[2][i + 1] = basep[2][i] * base[2] % mod;
    }

    for (int i = 0; i < str.size(); i++) {
        hsh[0][i + 1] = hsh[1][i + 1] = hsh[2][i + 1] = str[i];
    }

    for (int k = 0; k < 3; k++) {
        for (int i = 1; i < str.size(); i++) {
            hsh[k][i + 1] += hsh[k][i] * base[k] % mod;
            hsh[k][i + 1] %= mod;
        }
    }
}

tuple<llong, llong, llong> geth(llong l, llong r) {
    llong v1 = ((hsh[0][r] - hsh[0][l]*basep[0][r - l])%mod+mod)%mod;
    llong v2 = ((hsh[1][r] - hsh[1][l]*basep[1][r - l])%mod+mod)%mod;
    llong v3 = ((hsh[2][r] - hsh[2][l]*basep[2][r - l])%mod+mod)%mod;

    return make_tuple(v1, v2, v3);
}

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

    build();
    
    for (llong len = n / 2; len >= 1; len--) {
        unordered_map<tuple<llong, llong, llong>, llong> cnt;
        for (llong s = 0; s + len <= n; s++) {
            tuple<llong, llong, llong> idx = geth(s, s + len);
            
            llong t = cnt[idx];
            if (t > 0) {
                if (s >= t) {
                    cout << len << endl;
                    return 0;
                }
            }
            else {
                cnt[idx] = s + len;
            }
        }
    }

    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 3512
use std::io;

fn abc(n:i32) -> i32 {
    if n % 2 ==0 {
        return n
    }
    else {
        return n*2
    }
}

fn main() {
    //test
    /*
    assert_eq!(abc(3), 6);
    assert_eq!(abc(10), 10);
    assert_eq!(abc(999999999), 1999999998);
    */
    let stdin = io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).ok();
    let txt:Vec<_> = line.trim().split(' ').collect();
    let n:i32 = txt[0].parse().unwrap();


    let result = abc(n);
    println!("{}", result);
}



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

using namespace std;

long long a[200010],b[200010];
long long N,K;
bool check(long long x)
{
	long long kk = 0;
	for (int i=1;i<=N;i++)
	{
		if (a[i]*b[N-i+1]<=x) continue;
		long long temp = x/b[N-i+1];
		kk+=a[i]-temp;
	}
	if (kk>K) return false;
	else return true;
}
int main(void)
{
//	freopen("aaa.in","r",stdin);
	scanf("%lld%lld",&N,&K); 
	for (int i=1;i<=N;i++)
	scanf("%lld",&a[i]);
	for (int i=1;i<=N;i++)
	scanf("%lld",&b[i]);
	sort(a+1,a+N+1);
	sort(b+1,b+N+1);
	long long l=0,r=10000000000005;
	long long ans = 0;
	while(l<=r)
	{
		long long mid = (l+r)>>1;
		if (check(mid))
			r =(ans=mid)-1;
		else
		    l = mid+1;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e11;
const long double PI = (acos(-1));


signed main() {
	int S, W;
	cin >> S >> W;
	if (W >= S)cout << "unsafe";
	else cout << "safe";
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define fi(n) for(int i=0;i<n;i++)
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	string str;
	cin>>str;
	if(str[1]=='B')
	cout<<"ARC";
	else
	cout<<"ABC";
	return 0;
}


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

int main(){
    // vector<vector<vector<int>>> status(4, vector<vector<int>>(3, vector<int>(10, 0)));
    int status[4][3][10] ={};
    int n, b, r, f, v;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> b >> r >> f >> v;
        status[b-1][r-1][f-1] += v;
    }
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                cout << " ";
                cout << status[i][j][k];
            }
            cout << endl;
        }
        if (i!=3) cout << "####################" << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if(x==1){
            System.out.println(0);
        }
        else {
            System.out.println(1);
        }
    }
}

Measured memory_bytes: 35628
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int w,h,x,y,r;
  cin>>w>>h>>x>>y>>r;
  if(x-r<0 || y-r<0 || x+r>w || y+r>h){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 1188
// Author: pankaj_m05 
// Problem: Multiplication
// Created: 04.06.2020 19:08:56

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) c.begin(), c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())  // Set and Maps
#define cpresent(c,x) (find(allc,x) != c.end()) // Vectors
using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef long long ll;

const int mod = 1e9 + 7;

int main(void) { 
	fast
	int a, b;
	cin >> a >> b;
	cout << a * b << '\n';
	return 0;
}                                          

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;
using db = long double;

 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 


signed main() {
  db a,b,x;
    cin>>a>>b>>x;
  db t=(2*a*a*b-2*x)/a/a;
  db ans=a/t;
  if(t>b){
    t=2*x/a/b;
    ans=t/b;
  }
  db pi=3.14159265;
  cout<<setprecision(9)<<90-atanl(ans)*180/pi<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  for(int i=1;i<20000;i++){
    int x=i;
    if((x*8/100==A)&&(x*10/100==B)){
      cout<<x<<endl;
      break;
    }
    else{
      if(i==19999){
        cout<<-1<<endl;
      }
    }
  }
}

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

int main() {
  int N, K, r = 1;
  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    if (r * 2 < r + K) {
      r *= 2;
    }
    else {
      r += K;
    }
  }
  
  cout << r << endl;
}

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

int a[12][12];

int main(){
  int n,m,x;
  cin >>n >>m >>x;
  vector<int> c(n);
  rep(i,n){
    cin >>c[i];
    rep(j,m){
      cin >>a[i][j];
    }
  }
  
  int ans = 1001001001;
  rep(s,1<<n){
    int cost = 0;
    vector<int> d(m);
    rep(i,n){
      if (s>>i&1){
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if(d[j]<x) ok = false;
    if(ok) ans = min(ans,cost);
  }
  if(ans == 1001001001) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
n,m,x = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ans = float('inf')

for i in range(2**n):
    sum = [0]*(m+1)
    # n桁について調査
    for j in range(n):
        # iのj桁目が1かどうかcheck
        if (i >> j) & 1:
            for k in range(m+1):
                sum[k] += l[j][k]
    if sum[0] < ans:
        for a in range(1,m+1):
            if sum[a] < x:
                break
        else:
            ans = sum[0]
if ans == float('inf'):
    print(-1)
else:
    print(ans)

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= b) {
		if (b <= c)cout << c - a << endl;
		else if (a <= c)cout << b - a << endl;
		else cout << b - c << endl;
	}
	else {
		if (a <= c)cout << c - b << endl;
		else if (b <= c)cout << a - b << endl;
		else cout << a - c << endl;
	}
    return 0;
}

Measured memory_bytes: 256
def main():
    n, a, b = map(int, input().split())
    s = input().rstrip()
    ans = [None]*n
    cnt_a, cnt_b = 0, 0
    for i in range(n):
        if s[i] == "a":
            if cnt_a + cnt_b < a + b:
                ans[i] = "Yes"
                cnt_a += 1
            else:
                ans[i] = "No"
        elif s[i] == "b":
            if cnt_a + cnt_b < a + b and cnt_b < b:
                ans[i] = "Yes"
                cnt_b += 1
            else:
                ans[i] = "No"
        else:
            ans[i] = "No"
    for q in ans:
        print(q)

if __name__ == "__main__":
    main()


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

#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
        
    const int M = 1e9 + 10;
    int n;
    cin >> n;
    vector<int> c(n, M), h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    c[0] = 0;
    for (int i = 1; i < n; i++) {
        if (i - 1 >= 0) {
            c[i] = min(c[i], c[i - 1] + abs(h[i - 1] - h[i]));
        }
        if (i - 2 >= 0) {
            c[i] = min(c[i], c[i - 2] + abs(h[i - 2] - h[i]));
        }
    }
    cout << c[n - 1] << endl;

}


Measured memory_bytes: 1024
/*
 * ID: adityaa
 * LANG: C++
 */
#include <bits/stdc++.h>
using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define PI 3.14159265359

/*-----------------------------------------------------------------------*/

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

/*-----------------------------------------------------------------------*/

// check base cases n = 0 , n = 1
// max / min questions - check for binary search
const int maxn = (int) 1e6 + 6;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int) 998244353;
int n , k , dp[maxn] , min_ele = INF;
vector<int> a;

int go(int k){
    if(k < min_ele) return dp[k] = 2;
    if(k == min_ele) return dp[k] = 1;
    if(dp[k] != -1){
        return dp[k];
    }
    for(int i = 0; i < n; i++){
        if(a[i] > k) continue;
        int winner = go(k - a[i]);
        if(winner == 2){
            return dp[k] = 1;
        }
    }
    return dp[k] = 2;
}

signed main() {
    
    fio;
    cin >> n >> k;
    a.resize(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        min_ele = min(min_ele , a[i]);
    }
    
    mem(dp , -1);
    int winner = go(k);
    cout << (winner == 1 ? "First" : "Second") << endl;
    
    
    
    
    return 0;
    
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

int main()
{	
	string s,t;
	cin >> s >> t;
	int sum = 0;
	for(int i = 0;i < s.size();i++){
		if(s[i] != t[i]) sum++;
	}
	cout << sum << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> c(n);
    for(int i = 0; i < n; i++) cin >> c[i];

    vector<int> backet(9, 0);
    for(int i = 0; i < n; i++){
        if(c[i] / 400 < 8) backet[c[i]/400]++;
        else backet[8]++;
    }
    int minans = 0;
    int maxans = 0;
    for(int i = 0; i < 8; i++){
        if(backet[i] > 0) minans++;
    }

    if(backet[8] > 0 && minans == 0){
        minans = 1;
        maxans = backet[8];
    }else if(backet[8] > 0){
        maxans = minans + backet[8];
    }else{
        maxans = minans;
    }
    cout << minans << " " << maxans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define SORT(c) sort((c).begin(), (c).end())

int main(void){
	int N;
	cin >> N;
	int s[N];
	int ans = 0;
	for(int i=0; i<N; i++){
		cin >> s[i];
		ans += s[i];
	}
	sort(s, s+N);

	if(ans%10==0){
		for(int i=0; i<N; i++){
			if(s[i]%10!=0){
				ans-=s[i];
				break;
			}else{
				if(i==N-1){
					ans=0;
				}
			}
		}
	}

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

Measured memory_bytes: 256
/*
ID: 5ak0
PROG:
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;

string s;
stack <int> v;

int main(){
    #ifndef SAKO
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    #endif // SAKO
    ios_base::sync_with_stdio(0);

    cin >> s;
    for (int i = 0; i < s.size(); ++i)
		if(v.size() && s[i] == 'T' && v.top() == 'S')
			v.pop();
		else
			v.push(s[i]);
    cout << v.size();

    return 0;
}


Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        vector<vi> d(2);
        REP(i, n) {
            int x;
            cin >> x;
            d[i % 2].push_back(x);
        }
        vector<pii> c[2];
        REP(i, 2) {
            map<int , int> mp;
            for (int x : d[i]) {
                mp[x] ++;
            }
            c[i].emplace_back(d[i].size(), -1);
            for (auto it : mp) {
                c[i].emplace_back(d[i].size() - it.second, it.first);
            }
            sort(ALL(c[i]));
        }
        int ans;
        if (c[0][0].second != c[1][0].second) {
            ans = c[0][0].first + c[1][0].first;
        } else {
            ans = min(c[0][0].first + c[1][1].first, c[0][1].first + c[1][0].first);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4344
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

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

    int A,B,C;
    cin >> A >> B >> C;
    for(int i = 1; i <= 100; i++){
      if(A * i % B == C){
        cout << "YES" << endl;
        return 0;
      }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
H, W, K = [int(_) for _ in input().split()]

pat = set()


def make_pat(v):
    if v in pat: return
    a = v
    while a > 0:
        if a & 1 and a & 2:
            return
        a = a >> 1

    pat.add(v)
    for i in range(W - 1):
        a = 1 << i
        if a & v: continue
        make_pat(a | v)


make_pat(0)
# print(pat)

dp = [[0] * (W + 5) for _ in range(H + 1)]

dp[0][0] = 1
MOD = 10 ** 9 + 7

for i in range(H):
    for line in pat:
        for j in range(W):
            # j 番目の棒を考える
            if line & (1 << j):  # 右側
                dp[i + 1][j + 1] += dp[i][j] % MOD
            elif j > 0 and line & (1 << (j - 1)):  # 左側
                dp[i + 1][j - 1] += dp[i][j] % MOD
            else:
                dp[i + 1][j] += dp[i][j] % MOD
print(dp[H][K - 1] % MOD)


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

int main(void)
{
    int H, W, h, w;
    scanf("%d%d%d%d", &H, &W, &h, &w);
    if (H % h == 0 && W % w == 0){
        printf("No");
        return 0;
    }
    printf("Yes\n");
    int m[H][W];
    for (int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++j){
            if ((i + 1) % h ==0 && (j + 1) % w == 0)
                m[i][j] = -1e9;
            else
                if (i % h == 0 && j % w == 0)
                    m[i][j] = 1e9 - 1;
                else
                    m[i][j] = 0;
            printf("%d ", m[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 305;

int n;
double dp[n_max][n_max][n_max];

double solve(int iti, int ni, int san){
    if(iti == 1 and ni == 0 and san == 0){
        return dp[1][0][0] = double(n);
    }
    if(dp[iti][ni][san] >= 0.0) return dp[iti][ni][san];

    double summ = 0.0;
    if(iti != 0) summ += iti * solve(iti-1,ni,san) / n;
    if(ni != 0) summ += ni * solve(iti+1, ni-1 , san) / n;
    if(san != 0) summ += san * solve(iti,ni+1, san-1) / n;
    return dp[iti][ni][san] = (summ + 1.0) * n / (iti + ni + san);
}

signed main(){
    cin >> n;
    int maisuu[4];
    REP(i,4) maisuu[i] = 0;
    REP(i,n){
        int tmp;
        cin >> tmp;
        maisuu[tmp] ++;
    }

    REP(i,n+1) REP(j,n+1) REP(k,n+1) dp[i][j][k] = - 1.0;

    cout << fixed << setprecision(10) << solve(maisuu[1],maisuu[2],maisuu[3]) << endl;
}

Measured memory_bytes: 219392
#include <iostream>
#include <stack>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

  stack<char> blacket;
  string pre;
  int start = 0;
  while (start < N && S[start] == ')') {
    pre += '(';
    start++;
  }

  string post;
  int end = N - 1;
  while (0 <= end && S[end] == '(') {
    post += '(';
    end--;
  }

  int count = 0;
  for (int i = start; i <= end; ++i) {
    if (S[i] == '(')
      count++;
    else {
      if (count == 0)
        pre += '(';
      else
        count--;
    }
  }
  rep(i, start) pre += ')';
  rep(i, count) post += ')';
  rep(i, N - end - 1) post += ')';

  cout << pre + S.substr(start, end - start + 1) + post << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
ll dp[N][15];
int main() {
    dp[0][0] = 1;
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++) {
        for(int j = 0; j < 13; j++) {
            int src = dp[i][j];
            if(src == -1) continue;
            if(s[i] == '?') {
                for(int k = 0; k < 10; k++) {
                    ll& dest = dp[i + 1][(j*10 + k) % 13];
                    dest += src;
                    dest %= MOD;
                }
            } else {
                ll& dest = dp[i + 1][(j*10 + s[i] - '0') % 13];
                dest += src;
                dest %= MOD;
            }
        }
    }
    cout << dp[s.length()][5] << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(c-(a-b), 0) << endl;
	return 0;
}



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

#include <algorithm>
#include <vector>
#include <cstdio>
#include <random>
#include <functional>



int main(){
  int N, count = 1, i;
  cin >> N;
  
  int v[N-1];
  
  for(i=0; i<N; i++){
    cin >> v[i];
  }
  
  for(i =1; i<N; i++){
    
    for(int t = 0; t<i; t++){
    if(v[i] == v[t]){
      break;
    }
      if(t+1==i){
        count++;
      }
    }
    
  }

  
 cout << count <<  endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
 
using namespace std;
 
int dx[4]={1,-1,4,-4};
map<string,int>res;

void solve(void){
  queue<string>que;
  que.push("01234567");
  while(!que.empty()){
    string v=que.front();
    que.pop();
    int pos=0;
    for(int i=0;i<8;i++)
      if(v[i]=='0')pos=i;
    for(int i=0;i<4;i++){
      if(0 <= pos+dx[i] && pos+dx[i]<8 && 
	 !(pos==3 && i==0) && !(pos==4 && i==1)){
	string u=v;
	swap(u[pos],u[pos+dx[i]]);
	if(res[u]==0){
	  que.push(u);
	  res[u]=res[v]+1;
	}
      }
    }
  }
}
 
int main(void){
  int in;
   
  res["01234567"]=1;
  solve();
 
  while(true){
    string s;
    for(int i=0;i<8;i++){
      if(!(cin >> in))return 0;
      s+=in+'0';
    }
 
    cout << res[s]-1 << endl;
  }
 
  return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    int k,x; cin >> k >> x;
    if(k==1){
        cout << x << endl;
        return 0;
    }
    vector<int>vec;
    for(int y=x;y>=x-k+1;y--){
        vec.pb(y);
    }
    for(int y=x+1;y<=k+x-1;y++){
        vec.pb(y);
    }
    sort(vec.begin(), vec.end());
    for(int i=0;i<vec.size();i++){
        cout << vec[i] << " ";
    }





    return 0;
}





Measured memory_bytes: 3640
#include <stdio.h>

using namespace std;

int main(){
	int n,m,tmp;
	scanf("%d %d",&n,&m);
	int** A = new int*[n];
	for(int i = 0; i < n; i++) A[i] = new int[m];
	int b[m];

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d",&tmp);
			A[i][j] = tmp;
		}
	}
	for(int i = 0; i < m; i++){
		scanf("%d",&tmp);
		b[i] = tmp;
	}
	long long int sum;
	for(int i = 0; i < n; i++){
		sum = 0;
		for(int j = 0; j < m; j++){
			sum += A[i][j] * b[j];
		}
		printf("%lld\n",sum);
	}



	for(int i = 0; i < n; i++){
		delete[] A[i];
	}
	delete A;
}



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

int main(){
  int n;
  cin >> n;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  int maxnum = 0;
  ll ans = 0;
  for(int i=0; i<n; ++i){
    if(maxnum < an[i]) maxnum = an[i];
    else ans += maxnum - an[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3952
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int main() {
    int S; cin >> S;
    int a=S/100, b=S%100;

    if(1<=a && a<=12 && 1<=b && b<=12){
        cout << "AMBIGUOUS" << endl;
    }else if(1<=a && a<=12 && (13<=b || b==0)){
        cout << "MMYY" << endl;
    }else if( (0==a || 13<=a) && 1<=b && b<=12){
        cout << "YYMM" << endl;
    }else {
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N,K,R,S,P,ans=0;
  string T;
  cin>>N>>K>>R>>S>>P>>T;
  map<char,ll> mp;
  mp['r']=P;
  mp['p']=S;
  mp['s']=R;
  REP(i,K){
    //あまりがiのところでの
    ll tmp=0;
    bool last_used=false;
    for(int j=i;j<N;j+=K){
      char t=T[j];
      if(last_used){
        if(t==T[j-K]){
          // ng
          last_used=false;
        }else{
          // ok
          last_used=true;
          tmp+=mp[t];
        }
      }else{
        // 問答無用でおｋ
        last_used=true;
        tmp+=mp[t];
      }
    }
    ans+=tmp;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[][] student =new int[n][2];
        int[][] checkPoint = new int[m][2];
        int[] indexArray = new int[n];
        for (int i = 0;i < n;i++){
        	student[i][0] = in.nextInt();
        	student[i][1] = in.nextInt();
        }
        for (int i=0;i<m;i++){
        	checkPoint[i][0] = in.nextInt();
        	checkPoint[i][1] = in.nextInt();	
        }
        for (int i=0;i<student.length;i++){
        	int min = 2147483647;
        	int index = -1;
        	for (int j=0;j<checkPoint.length;j++){
        		if(Math.abs(student[i][0]-checkPoint[j][0])+Math.abs(student[i][1]-checkPoint[j][1])<min){
        			min = Math.abs(student[i][0]-checkPoint[j][0])+Math.abs(student[i][1]-checkPoint[j][1]);
        			index = j+1;
        		}
        	}
        	//indexArray[i] = index;      	
        	System.out.println(index);
        }
	}
}


Measured memory_bytes: 23892
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
//    var pre = 2
//    var aaaaaa = 0
////    out.println("1:" +pre)
//    out.println(pre)
//    for (i in 1..12) {
//        aaaaaa += pre
//        val tmp = pre * pre % 1001
//
//
//        out.println("${i}:" + aaaaaa)
//        out.println(tmp)
//        pre = tmp
//    }
////    out.println(aaaaaa)
//    out.println()

    val (n, x, m) = readLongList()

    val set = mutableSetOf<Long>()
    var cur = x
    while (set.contains(cur) == false) {
        set.add(cur)
        cur = (cur % m) * (cur * m) % m
    }

    val a = set.max()!!
    var loopFrom = 1L
    val set2 = mutableSetOf<Long>()
    var cur2 = x
    while (set2.contains(cur2) == false) {
        set2.add(cur2)
        cur2 = (cur2 % m) * (cur2 % m) % m
        if (cur2 == a) break
        loopFrom++
    }
    loopFrom++

    var firstSum = 0L
    cur2 = x
    repeat(loopFrom.toInt()) {
        firstSum += cur2
        val tmp = (cur2 % m) * (cur2 % m) % m
        cur2 = tmp
    }


    var loopSum = 0L
    var loopCount = 0L
    set2.clear()
    val first = cur2
    while (set2.contains(cur2) == false) {
        loopCount++
        set2.add(cur2)
        val tmp = (cur2 % m)* (cur2 % m) % m
        loopSum += tmp
        cur2 = tmp
    }
//    out.println()
//    out.println(loopFrom)
//    out.println(firstSum)
//
//    out.println(loopCount)
//    out.println(loopSum)

    if (n <= loopFrom) {
        var ans = 0L
        var pre = x
        repeat(n.toInt()) {
            ans += pre
            pre = (pre % m) * (pre % m) % m
        }
        out.println(ans)
        return
    } else {
        var ans = firstSum

        val remain = max(0, n - loopFrom)
        val aaa = remain / loopCount
        val modRemain = remain % loopCount

        ans += aaa * loopSum

        var pre = first
        repeat(modRemain.toInt()) {
            ans += pre
            pre = (pre%m) * (pre%m) % m
        }
        out.println(ans)
        return
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 48884
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  vector<int> s2t(26, -1), t2s(26, -1);
  rep(i, s.size()){
    char sn = s.at(i) - 'a';
    char tn = t.at(i) - 'a';
    if(s2t.at(sn) == -1) s2t.at(sn) = tn;
    else{
      if(s2t.at(sn) != tn){
        cout << "No" << endl;
        return 0;
      }
    }
    if(t2s.at(tn) == -1) t2s.at(tn) = sn;
    else{
      if(t2s.at(tn) != sn){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main(){
  string s;
  cin>>s;
  if(s[0]==s[1] && s[1]==s[2]) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define M 1000000007
#define INF 999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
using namespace std;
 typedef  long long  int ll;
 typedef pair<int,int> ii;
 typedef vector<ii> vii;
 typedef vector <ll > vi;

ll arr[100005];

int main()
{
// freopen("input.txt","r",stdin);
 // freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,m,sum=0;
 cin>>n>>m;
 for(int i=0;i<n;i++)
  cin>>arr[i];
sort(arr,arr+n);
reverse(arr,arr+n);
for(int i=0;i<m;i++)
  sum+=arr[i];
cout<<sum<<endl;


return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int S,h,m,s;
    scanf("%d",&S);
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
using namespace std;

typedef long long ll;
const int N=1e5+5;
const ll p=1000000007;

int main()
{
    ll n;
    scanf("%lld",&n);
    ll a,b;
    cin>>a>>b;
    ll ans=min(a,n%(a+b))+n/(a+b)*a;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){
  int H, W, i, j;

  while (1){
    scanf("%d %d",&H, &W);
    if (H == 0 && W == 0) break;

    for ( i = 1; i <= H; i++){
      for (j = 1; j <= W; j++){

	if(i==1 ||  j==1 || i==H || j==W ){
	  printf ("#");
	}else{
	  printf(".");
	}

      }
      printf("\n");
    }

    printf("\n");
  }
  return 0;

}

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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = INF + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
	int a,b;
	cin >> a >> b;
	
	cout << (a*b)/__gcd(a,b);
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;
typedef long long ll;


int main(int argc, char *args[]) {
	int h, w;
	cin >> h >> w;
	string board[50];

	for (int i = 0; i < h; i++)cin >> board[i];

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

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (board[i][j] == '#')continue;

			int num = 0;
			for (int d = 0; d < 8; d++) {
				const int  ni = i + dy[d];
				const int  nj = j + dx[d];
				if (ni < 0 || h <= ni)continue;
				if (nj < 0 || w <= nj)continue;
				if (board[ni][nj] == '#')num++;
			}
			board[i][j] = char(num + '0');

		}
	}
		for (int i = 0; i < h; i++) cout << board[i] << endl;
		return 0;
}


Measured memory_bytes: 256
// Think twice, Code once
// 1SAC
#include<bits/stdc++.h>
using namespace std;
 
/*============================ DEBUGGING =============================*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
/*============================= DEFINES ==============================*/
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
/*============================== TYPEDEFS ============================*/
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;
/*============================ START FROM HERE =======================*/
 
int main(){
	FIO
	
	int n;cin >> n;
	pair<string,int> a[n];
	forn(i, n){
		string s;int x;cin >> s >>x;
		a[i] = {s,x};
		//sum += x;
	}
	string s;cin >> s;
	forn(i, n)if(a[i].fi == s){
		int sum = 0;
		for(int j= i+1 ;j<n;j++)sum+= a[j].se;
		cout << sum;
		return 0;
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int x = Integer.parseInt(tokenizer.nextToken());
        int y = Integer.parseInt(tokenizer.nextToken());
        char [][] image = new char[x][];

        for (int i = 0; i < x; i++) {
            image[i] = input.readLine().toCharArray();
        }
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < x * 2; i++) {
            for (int j = 0; j < y; j++) {
                out.append(image[(i/2)][j]);
            }
            System.out.println(out);
            out = new StringBuilder();
        }
    }
}


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

using P = pair<string,int>;


int main() {
	int n;
	cin >> n;
	string tmp;
	vector<string> s;
	rep(i,n) {
		cin >> tmp;
		s.push_back(tmp);
	}
	
	sort(s.begin(),s.end());
	
	
	int mNum,cnt;
	mNum=1;
	cnt=1;
	rep(i,n-1){
		if(s[i]==s[i+1]){ cnt++;
		}else{ 
			mNum=max(mNum,cnt);
			cnt=1;
		}
	}
	mNum=max(mNum,cnt);
	cnt=1;
	rep(i,n-1){
		if(s[i]==s[i+1]){ 
			cnt++;
		}else{ 
			if(mNum == cnt) printf("%s\n",s[i].c_str());
			cnt=1;
		}
	}
	
	if(mNum == cnt) printf("%s\n",s[n-1].c_str());
	
	
	return 0;
}

Measured memory_bytes: 14320
#include<stdio.h>
#include<cmath>
using namespace std;

int n, cnt;

bool isPrime(int p) {
    if (p<=1) return false;
    int sqrt_p = sqrt(p);
    for (int i=2; i<=sqrt_p; i++) {
        if (p%i==0) return false;
    }
    return true;
}

int main() {
    int p;
    cnt = 0;

    scanf("%d", &n);

    for (int i=0; i<n; i++) {
        scanf("%d", &p);
        if (isPrime(p)) cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}


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

int main() {
	string w; cin >> w;
	int P[30];
	for(int i=0; i<26; ++i) P[i]=0;
	for(int i=0; i<w.size(); ++i) ++P[w[i]-'a'];
	bool alleven=true;
	for(int i=0; i<26; ++i){
	    if(P[i]%2){
	        alleven=false;
	        break;
	    }
	}
	if(alleven) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int a = 0;
    int b = 0;
    
    // input
    std::cin >> a;
    std::cin >> b;
    
    // output
    if(a < b)
    {
        std::cout << "a < b" << std::endl;
    }
    else if(a > b)
    {
        std::cout << "a > b" << std::endl;
    }
    else
    {
        std::cout << "a == b" << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3072
x,a,b=input().split()
x=int(x)
a=int(a)
b=int(b)
if x<a:
	distance_xa=a-x
else:
    distance_xa=x-a
if x<b:
  distance_xb=b-x
else:
  distance_xb=x-b
if distance_xa<distance_xb:
  print("A")
else:
  print("B")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N;
    vec ans(N, 0);
    rep(i,N - 1){
        cin>>A;
        --A;
        ++ans[A];
    }
    rep(i,N) cout<<ans[i]<<endl;
}

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

long long gcd(long long a, long long b){
    if(a < b){
        swap(a, b);
    }

    long long r = a % b;

    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

long long lcm(long long a, long long b){
    return a * b / gcd(a, b);
}

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

    long long sum = 0;

    for (auto i = 0; i < n; i++)
    {
        sum += a[i] - 1;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 3e3 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

pi a[N];
int dp[N][2*N];
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n, t;
	cin >> n >> t;
	for(int i = 1; i <= n; i++)
		cin >> a[i].fi >> a[i].se;
	sort(a + 1, a + n + 1);
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 2*N; j++)
			dp[i][j] = -inf;
	}
	dp[0][0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < t; j++){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			dp[i+1][j+a[i+1].fi] = max(dp[i+1][j+a[i+1].fi], dp[i][j] + a[i+1].se);
		}
		for(int j = 1; j < 2*N; j++)
			dp[i+1][j] = max({dp[i+1][j], dp[i+1][j-1], dp[i][j]});
	}
	cout << dp[n][2*N-1];
	return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,m,ans=0,cnt=0;
vector<int>xx;
map<int ,int>mp;
int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        mp[a]++;
    }
    for(auto x:mp){
        cnt++;
        xx.push_back(x.second);
    }
    sort(xx.begin(),xx.end());
    reverse(xx.begin(),xx.end());
    for(int i=0;i<min(cnt,m);i++){
        ans+=xx[i];
    }
    cout<<n-ans<<endl;
}


Measured memory_bytes: 10748
#include<cstdio>
using namespace std;
int main(void)
{
	int i,a,b,c,d,e,f,s,s1,x,h,h1,m,ss;
	for(i=0;i<3;i++){
		scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
		s=a*3600;
		s+=b*60;
		s+=c;
		s1=d*3600;
		s1+=e*60;
		s1+=f;
		x=s1-s;
		h=x/3600;
		h1=x%3600;
		m=h1/60;
		ss=h1%60;
		printf("%d %d %d\n",h,m,ss);
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long i,n,d;
  cin >> n >> d;
  long long sum=0;
  for(i=0;i<n;i++){
    long long x,y;
    cin >> x >> y;
    if(x*x+y*y<=d*d){
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3568