akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<map>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1e9 + 7)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int n = in();

	bool flag = false;

	REP(i, 26) {
		REP(j, 15) {
			if (4 * i + 7 * j == n) {
				flag = true;
			}
		}
	}

	Yes(flag);

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
    int a[1010];
    memset(a,0,sizeof(a));
    for(int i=1;i<=31;i++)
        {
            int t=i;
            for(int j=2;j<10;j++ )
        {
            if(t*i>1000)
                break;
            a[t*i]=1;
            t*=i;
        }
        }
    int x;
    while(scanf("%d",&x)!=EOF)
    {
        for(int i=0;i<=x;i++)
        {
            if(a[x-i]==1)
            {
                printf("%d\n",x-i);
                break;
            }
        }
    }    
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<map>
#include<queue>
using namespace std;
int co=0;
queue<int> q;
map<int,int> m;
int visited[100001],pos=0;
int main()
{
    int n,tmp;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&tmp);
        if(m.count(tmp)==0)
        {
            m[tmp]=pos;
            q.push(tmp);
            visited[pos++]=1;
        }
        else
            visited[m[tmp]]++;
    }
    while(!q.empty())
    {
        tmp=q.front();
        q.pop();
        if(visited[m[tmp]]>tmp)
            co+=visited[m[tmp]]-tmp;
        else if(visited[m[tmp]]<tmp)
            co+=visited[m[tmp]];
    }
    printf("%d",co);
}


Measured memory_bytes: 5504
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 1
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
s = X()

count = list(Counter(s).most_common())

for i in count:
    ans *= i[1]+1

ans -= 1
print(ans%mod)

Measured memory_bytes: 11132
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	double in;
	while(cin>>in,abs(in-0)>EPS){
		int a=1,b=1;
		while(abs((double)a/b-PI)>in){
			if((double)a/b<PI)a++;
			else b++;
		}
		cout<<a<<"/"<<b<<endl;
	}
}

Measured memory_bytes: 1224
s = input()
a_iter=0
z_iter=0
for i in range(len(s)):
  if s[i]=="A":
    a_iter=i+1
    break
for i in range(1,len(s)+1):
  if s[-i]=="Z":
    z_iter=(len(s)-1)-(i-1)
    break
print(z_iter-a_iter+2)
      
    

Measured memory_bytes: 3516
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
 
	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int len, rem;
		long n, k, q,index,ai,count;
		String s,t,answer;
		Map <Long,Long> mapA= new HashMap<Long,Long>();
		
			// 整数の入力
		
		n = sc.nextInt();
		k = sc.nextLong();
		q = sc.nextInt();
		LoopA: for(index=0;index<q;index++) {
			ai = sc.nextLong();
			if(mapA.containsKey(ai)) {
				count=mapA.get(ai);
				mapA.put(ai,count+1);
			}
			else{
				mapA.put(ai,1L);
			}
		}
		sc.close();

		 for(index=1;index<=n;index++) {
			if(mapA.containsKey(index)) {
				count=mapA.get(index);
			}
			else {
				count=0;
			}
			if(count+k-q>0) {
				System.out.println("Yes");
			}	
			else {
				System.out.println("No");
				}
				
			}
 
	}
}	

Measured memory_bytes: 81516
import numpy as np
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n = ni()
if n==1:
    print('Hello World')
else:
    a = ni()
    b = ni()
    print(a+b)


Measured memory_bytes: 20508
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define rrep(i, n) for(int i=((int)(n));i>0;i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)	
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
const long long MOD = 1000000007;
typedef long long ll;

int main(){
	double W, H;
	ll x, y;
	cin >> W >> H >> x >> y;
	int ans = 0;
	if(x == W / 2 && y == H / 2)ans = 1;
	cout << W * H / 2 << " " << ans << endl;
}

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

 using namespace std;

  
int main(){
  int N,count=0;
  string s;
  cin>>N>>s;
  for(int i=0;i<N-2;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
      count++;
  }
  cout<<count<<endl;
    
      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
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 main() {
    int x; cin >> x;
    int ans = 0;
    if(x >= 1800) ans = 1;
    else if(x >= 1600) ans = 2;
    else if(x >= 1400) ans = 3;
    else if(x >= 1200) ans = 4;
    else if(x >= 1000) ans = 5;
    else if(x >= 800) ans = 6;
    else if(x >= 600) ans = 7;
    else if(x >= 400) ans = 8;
    cout << ans << endl;
}

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

int main(){
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  rep(i, n) cin >> x[i] >> y[i] >> a[i];

  int lx = 0, ly = 0;
  int ux = w, uy = h;
  rep(i, n){
    if (a[i] == 1){
      if (lx < x[i]) lx = x[i];
    } else if (a[i] == 2){
      if (ux > x[i]) ux = x[i];
    } else if (a[i] == 3){
      if (ly < y[i]) ly = y[i];
    } else if (a[i] == 4){
      if (uy > y[i]) uy = y[i];
    }
  }

  int ansx = ux - lx;
  int ansy = uy - ly;
  if ((ansx > 0) && (ansy > 0)){
    cout << ansx * ansy << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 5005
#define P 998244353
#define G 3
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
#define fuck printf("FUCK!!\n");
using namespace std;

int n, a, b, num[MAXN];
LL ans=1e18, f[MAXN][MAXN];

int main()
{
    scanf("%d%d%d", &n, &a, &b);
    for(rint i=1; i<=n; ++i) scanf("%d", &num[i]);
    memset(f, 0x3f, sizeof(f));
    for(rint i=1; i<=n; ++i) f[0][i]=0;
    for(rint i=1; i<=n; ++i)
        for(rint j=1; j<=n; ++j)
        {
            if(num[i]>=j)
            {
                f[i][num[i]]=min(f[i][num[i]], f[i-1][j]);
                f[i][j]=min(f[i][j], f[i-1][j]+a);
            }
            else f[i][j]=min(f[i][j], f[i-1][j]+b);
        }
    for(rint i=1; i<=n; ++i) ans=min(ans, f[n][i]);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 195840
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
int main()
{
	long long n, m;
	
	scanf("%lld%lld", &n, &m);
	long long ans = n * m;
	for (int i = 1; i <= n; i++) {
		long long x = n - i;
		long long y = m;
		ans = min(ans, max(abs(m * i - x / 2 * m), max(abs(m * i - (x + 1) / 2 * m), abs(x / 2 * m - (x + 1) / 2 * m))));
		ans = min(ans, max(abs(m * i - y / 2 * x), max(abs(m * i - (y + 1) / 2 * x), abs(x / 2 * m - (y + 1) / 2 * x))));
	} 
	swap(n, m);
	for (int i = 1; i <= n; i++) {
		long long x = n - i;
		long long y = m;
		ans = min(ans, max(abs(m * i - x / 2 * m), max(abs(m * i - (x + 1) / 2 * m), abs(x / 2 * m - (x + 1) / 2 * m))));
		ans = min(ans, max(abs(m * i - y / 2 * x), max(abs(m * i - (y + 1) / 2 * x), abs(x / 2 * m - (y + 1) / 2 * x))));
	} 
	printf("%lld\n", ans);
} 

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

int main() {
    long long x[4], n;
    for (int i = 0; i < 4; i++) {
        cin >> x[i];
    }
    cin >> n;
    const double a[3] = {4, 2, 1};
    double minimum = 1000000000.0;
    int index = 0;
    for (int i = 0; i < 3; i++) {
        if (x[i] * a[i] < minimum) {
            minimum = x[i] * a[i];
            index = i;
        }
    }

    long long ans;
    if (minimum < (double)x[3] / 2 || n < 2) {
        ans = n * a[index] * x[index];
        if (n * (x[0] * 2 + x[1]) < ans) ans = n * (x[0] * 2 + x[1]);
    }
    else {
        ans = n / 2 * x[3];
        ans += (n % 2) * min(x[index] * (long long)a[index], x[0] * 2 + x[1]);
    }
    cout << ans << endl;
}   

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())

ji = (360/12*h) + (360/12/60*m)
hun = 360/60*m
cosC = math.cos(math.radians(abs(ji-hun)))

ans = math.sqrt(a**2 + b**2 - 2*a*b*cosC)
print(ans)

Measured memory_bytes: 9508
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
map<int, int> mp;
int main()
{
	int h, w;
	cin >> h >> w;
	vector<vector<int>> dist(10, vector<int>(10, iINF));
	rep(i, 10) rep(j, 10) cin >> dist[i][j];
	rep(k, 10) {
		rep(i, 10) {
			rep(j, 10) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	int ans = 0;
	int tmp;
	rep(i, h) {
		rep(j, w) {
			cin >> tmp;
			if (tmp == -1)	continue;
			ans += dist[tmp][1];
		}
	}
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <queue>

std::vector<int> a[100000], b[100000];
int n, m, k, x, y, tmp, cnt;

void solve() {
	std::cin >> n >> m >> k;

    for (int i=0; i<m; ++i) {
		std::cin >> x >> y;
		a[x].push_back(y);
		a[y].push_back(x);
	}

	cnt = 0;
	std::vector<bool> done(n + 1, 0);
	std::vector<int> ans(n + 1, 0);
	std::vector<int> groupnum(n + 1);
	std::queue<int> que;
    for (int i=1; i<n+1; ++i) {
		std::vector<int> group;
		if (done[i] == true)
            continue;
		done[i] = true;
		group.push_back(i);
		for (auto nx : a[i]) {
			que.push(nx);
			done[nx] = true;
			group.push_back(nx);
		}
		while (!que.empty()) {
			tmp = que.front();
			que.pop();
			for (auto nx : a[tmp]) {
				if (done[nx] == true)
                    continue;
				que.push(nx);
				done[nx] = true;
				group.push_back(nx);
			}
		}
		for (auto s : group) {
			ans[s] = group.size();
			groupnum[s] = cnt;
		}
		cnt++;
	}

    for (int i=0; i<k; ++i) {
		std::cin >> x >> y;
		if (groupnum[x] == groupnum[y]) {
			b[x].push_back(y);
			b[y].push_back(x);
		}
	}

    for (int i=1; i<n+1; ++i)
		std::cout << ans[i] - a[i].size() - b[i].size() - 1 << " ";
    std::cout << std::endl;
}

int main() {
    std::ios_base::sync_with_stdio(0);
    solve();
    return 0;
}


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


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

    long long A[N];
    int cou = 0;
    int zero = 0;
    int min = 1000000000;
    int num = 0;
    for(int i = 0; i < N; i++){
        int re = 0;
        cin >> A[i];
        if(A[i] == 0){
            zero = 1;
            re = 0;
        }else if(A[i] < 0){
            cou++;
            re = -A[i];
        }else{
            re = A[i];
        }

        if(min > re){
            min = re;   
            num = i;     
        }
    }

    long long ans = 0;
    int ki = 0;
    ki = cou % 2;

    if(zero != 0 || ki == 0){
        for(int i = 0; i < N; i++){
            if(A[i] < 0){
                ans -= A[i];
            }else{
                ans += A[i];
            }
        }
    }else{
        for(int i = 0; i < N; i++){
            if(i == num){
                if(A[i] < 0){
                    ans += A[i];
                }else{
                    ans -= A[i];
                }
            }else{
                if(A[i] < 0){
                    ans -= A[i];
                }else{
                    ans += A[i];
                }
            }
        }
    }

    cout << ans <<endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(int i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 1e3 + 5;
const ll OO = 1e9 + 7;
using namespace std;

int main() {
    IO;
   ll n,k; cin>>n>>k;
   cout<<min(n%k,abs((n%k)-k));

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) prllf("%d",n)
#define pl(n) prllf("%d",n)
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  int ans=a-1;
  if(b>=a)
    ans+=1;
  cout << ans << endl;
}


Measured memory_bytes: 256
func readUInts() -> [UInt] {
    return readLine()!.split(separator: " ").map { UInt($0)! }
}

func main() {
    let _ = readLine()!
    let a_tachi = readUInts().sorted(by: <)
    
    if a_tachi[0] == 0 {
        print(0)
        return
    }
    
    var mul: UInt = 1
    for a in a_tachi {
        if 1000000000000000000 / mul < a {
            print(-1)
            return
        }
        mul *= a
        if mul > 1000000000000000000 {
            print(-1)
            return
        }
    }
    
    print(mul)
}

main()


Measured memory_bytes: 15140
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> points(N);

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

    long long int sum = 0;

    for (int i = 0; i < N; i++)
        for (int j = i+1; j < N; j++) {
            sum += points[i]*points[j];
        }

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long A, B;
  cin >> A >> B;
  if ((A + B) & 1)
    cout << "IMPOSSIBLE\n";
  else
    cout << (A + B) / 2 << '\n';
  return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int n;
int a[10005],b[10005];
int main(){
	scanf("%d",&n);
	long long sum1=0,sum2=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum1=sum1+a[i];
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
		sum2=sum2+b[i];
	}
	if(sum1>sum2){
		printf("No\n");
		return 0;
	}
	long long del = sum2-sum1;//理论上最多的次数
	long long tot = 0;
	for(int i=1;i<=n;i++)
		if(b[i]>a[i])
			tot+=(b[i]-a[i]+1)/2;
	if(tot<=del)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
} 

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
long long euler_phi(long long n){
  if(n == 0 || n == 1) return 0;
  long long res = n;
  for(long long i=2;i*i<=n;i++){
    if(n%i == 0){
      res -= res / i;
      while(n%i == 0) n /= i;
    }
  }
  if(n > 1) res -= res / n;
  return res;
}
//-----------------------------------------

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

  ll n;
  cin >> n;
  cout << euler_phi(n) <<endl;




  return 0;
}



Measured memory_bytes: 3232
import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
import static java.lang.System.out;

// AOJ4
public class Main {
	final Scanner sc=new Scanner(System.in);
	final int[] vx={0,1,0,-1,-1,1,1,-1}, vy={-1,0,1,0,-1,-1,1,1};
	final int INF=1<<26;
	final double EPS=1.0e-08;
	static class Point{
		int x, y;
		Point(int x, int y){	this.x=x;	this.y=y;}
		Point(){	this.x=0; this.y=0;}
		@Override public String toString(){	return "("+this.x+","+this.y+")";}
		static boolean ok(int x,int y,int X,int Y,int min){	return (min<=x&&x<X)&&(min<=y&&y<Y);}
		static boolean ok(int x,int y,int X,int Y){	return ok(x,y,X,Y,0);}
	}
	public static void main(String[] args) {
		//long s=System.currentTimeMillis();
		new Main().AOJ1165();
		//out.println((System.currentTimeMillis()-s)+"msec");
	}
	void AOJ1165(){
		final int[] vx2={-1,0,1,0}, vy2={0,-1,0,1};
		while(true){
			int N=sc.nextInt();
			if(N==0)	break;
			int[] x=new int[N],y=new int[N];
			for(int i=1; i<N; i++){
				int n=sc.nextInt(),d=sc.nextInt();
				x[i]=x[n]+vx2[d];	y[i]=y[n]+vy2[d];
			}
			Arrays.sort(x);	Arrays.sort(y);
			System.out.println((x[N-1]-x[0]+1)+" "+(y[N-1]-y[0]+1));
		}

		
	}
}

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

int main(void) {
  int A, B, C, D, E, F, G;
  cin >> A >> B >> C >> D >> E >> F >> G;
  vector<long long> waters;
  vector<long long> sugers;
  for (int i = 0; i <= F; i++) {
    for (int j = 0; j <= F; j++) {
      long long water = 100LL * A * i + 100LL * B * j;
      long long suger = C * i + D * j;
      if (0 < water && water <= F) {
        waters.push_back(water);
      }
      if (suger <= F) {
        sugers.push_back(suger);
      }
    }
  }

  double ma = -1;
  int ans_w, ans_s;
  for (auto water : waters) {
    for (auto suger : sugers) {
      if (water + suger <= F && suger <= E * (water / 100)) {
        double per = (100 * suger) / (double)(water + suger);
        if (ma < per) {
          ans_w = water + suger;
          ans_s = suger;
          ma = per;
        }
      }
    }
  }

  cout << ans_w << " " << ans_s << endl;
  return 0;
}

Measured memory_bytes: 2420
#include <iostream>
using namespace std;
int main(){
  int N, T;
  cin >> N >> T;
  long long int ans = 0;
  int t, u = 0;
  for(int i = 0; i < N; ++i){
    cin >> t;
    u = max(u, t);
    ans += max(0, t + T - u);
    u = max(u, t + T);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(var, start, end) for(int var = start; var < end; ++var)
#define all(container) begin(container), end(container)
#define eb(x)  emplace_back(x);
#define err(x) cout << #x << " : " << x << "\n";
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
const ll MOD = 1000000;

int main() {
	fast;
	int n; cin >> n; if(n & 1) {cout << "No"; return 0;}
	string s;
	cin >> s;
	int l = n / 2;
	if(s.substr(0, l) == s.substr(l)) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
} 



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using namespace std;

// int gcd(int a, int b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

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

int main(){
    long long n,count=0;
    cin >> n;
    vector<long long> a(n);
    rep(i,n){
        cin >> a.at(i);
    }
    
    reverse(a.begin(),a.end());
    for(long long i=1;i<n;i++){
        if(a.size() < 1){
            break;
        }
        if(a[(long long)a.size()-1] == i){
            a.pop_back();
        }else{
            a.pop_back();
            count++;
            i--;
        }
    }
    if(count == n){
        cout << "-1" << endl;
    }else{
        cout << count << endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{   
ios::sync_with_stdio(false);
  cin.tie(0);
    //SieveOfEratosthenes(900000);
	int t,k,i,cost;
	cin>>t;
	int a[t][3],b[t][3];
	i=0;
	while(i<t)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		i++;
	}
	b[0][0]=a[0][0];
	b[0][1]=a[0][1];
	b[0][2]=a[0][2];
	for(i=1;i<t;i++)
	{
		if(b[i-1][2]>b[i-1][1])
			b[i][0]=b[i-1][2]+a[i][0];
		else
			b[i][0]=b[i-1][1]+a[i][0];
		if(b[i-1][1]>b[i-1][0])
			b[i][2]=b[i-1][1]+a[i][2];
		else
			b[i][2]=b[i-1][0]+a[i][2];
		if(b[i-1][2]>b[i-1][0])
			b[i][1]=b[i-1][2]+a[i][1];
		else
			b[i][1]=b[i-1][0]+a[i][1];
	}
	if(b[t-1][0]>b[t-1][1]&&b[t-1][0]>b[t-1][2])
	cost=b[i-1][0];
else if(b[t-1][2]>b[t-1][1])
	cost=b[i-1][2];
else
	cost = b[t-1][1];
	cout<<cost<<endl;
    return 0; 
} 

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)(v).size())
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1);

template <class T>
inline bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    vector<int> dp(n, 1e9);
    dp.at(0) = 0;
    for (int i = 1; i < n; i++) {
        for (int ii = i - 1; ii >= 0; ii--) {
            if (ii < i - k) break;
            chmin(dp.at(i), dp.at(ii) + abs(h.at(ii) - h.at(i)));
        }
    }
    cout << dp.at(n - 1) << endl;
    return 0;
}

Measured memory_bytes: 4000
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        checked {
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
        }
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var a = decimal.Parse(spl[0]);
        var b = decimal.Parse(spl[1]);

        return (long)(a * b);
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 27468
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int a=in.nextInt();
		int b=in.nextInt();
		int x=0;
		if(b>9){
		x=2;
		if(b==100)
		x=3;
		}
		else x=1;
		int num=a*(int)(Math.pow(10,x))+b;
		int y=(int)Math.pow(num,0.5);
		int z=(int)Math.pow(y,2);
		if(z==num)
		System.out.println("Yes");
		else System.out.println("No");
		
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    int A[N],B[N];
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N) cin >> B[i];
    long long def[N];
    rep(i,N) def[i]=A[i]-B[i];
    sort(def,def+N);
    int ans=0;
    long long sum=0;

    rep(i,N){
        if(def[i]<0){
            sum+=def[i];
            ans++;
        }else break;
    }
    int i=N;
    while(sum<0){
        i--;
        if(def[i]>0){
            sum+=def[i];
            ans++;
        }else{
            ans=-1;
            break;
        }
    }
    cout << ans << endl;



}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/********** TEMPLATE ENDS HERE ***********/

bool isPalindrom(int n)
{
	int m = n;
	
	int x = 0;
	
	while(m)
	{
		x = x * 10 + m % 10;
		m /= 10;
	}
	
	return (x == n);
	
}

main()
{
	IOS
	
	int nr = 0;
	
	int a, b;
	cin >> a >> b;
	
	for(int i = a; i <= b; i++)
		if(isPalindrom(i))
			nr++;
	
	cout << nr;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#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 print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c)
{
	if (c >= '0' && c <= '9')
	{
		return c - '0';
	}
	return 0;
}

char upper(char c)
{
	return c - 0x20;
}

char lower(char c)
{
	return c + 0x20;
}

void unique_vector(vector<int> &v)
{
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	std::fill((T *)array, (T *)(array + N), val);
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y)
{
	if (y == 0)
		return x;
	return gcd(y, x % y);
}

//最小公倍数
ll lcm(ll x, ll y)
{
	ll g = gcd(x, y);
	return x / g * y;
}

ll myPow(ll x, ll n, ll m)
{
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

//素因数分解
map<ll, ll> prime_factor(ll n)
{
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++)
	{
		while (n % i == 0)
		{
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1)
		ret[n] = 1;
	return ret;
}

int main()
{
	int n;
	cin >> n;
	vector<int> x(n), y(n), v(n);
	double ans = 0;
	int t = 1;
	double g[n][n];
	rep(i, n)
	{
		cin >> x[i] >> y[i];
		t *= i + 1;
		v[i] = i;
	}
	rep(i, n)
	{
		for (int k = i + 1; k < n;k++){
			g[i][k] = sqrt(pow(x[i] - x[k], 2) + pow(y[i] - y[k], 2));
			g[k][i] = g[i][k];
		}
	}
	do {
		rep(i,n-1){
			ans += g[v[i]][v[i + 1]];
		}
	} while (next_permutation(v.begin(), v.end()));

	printf("%.8f\n", 1.0 * ans / t);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using ull = unsigned long long;

using namespace std;

int main(int argc, char const *argv[]) {
	ull a,b,k;
	std::cin >> a >> b >> k;
	for (int i = 0; i < k; i++) {
		if (i % 2 == 0) {
			a /= 2;
			b += a;
		}
		else {
			b /= 2;
			a += b;
		}
	}

	std::cout << a  << ' ' << b << '\n';
	return 0;
}


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

using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using ull = unsigned long long;


const int mn = 2e5 + 5;

int n;

struct node {
    int x, y;
    int id;

    bool operator<(const node &p) const {
        return x < p.x;
    }

    bool operator!=(const node &p) const {
        return x != p.x || y != p.y || id != p.id;
    }
} p[mn];

int f[mn];

int sf(int x) { return f[x] == x ? x : f[x] = sf(f[x]); }

int c[mn];

bool cmp(const node &a, const node &b) {
    return a.x < b.x && a.y < b.y;
}

int main() {
    //cin.sync_with_stdio(0);
#ifdef trote
    freopen("../1.txt", "r", stdin);
    //freopen("../2.txt", "w", stdout);
    auto bg = clock();
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        f[i] = p[i].id = i;
        c[i] = 1;
        scanf("%d%d", &p[i].x, &p[i].y);
    }
    sort(p + 1, p + n + 1);
    vector<node> v;
    for (int i = 1; i <= n; i++) {
        if (v.empty()) {
            v.push_back(p[i]);
            continue;
        }
        node yminp = v.back();
        while (!v.empty() && cmp(v.back(), p[i])) {
            node pr = v.back();
            c[p[i].id] += c[sf(pr.id)];
            c[sf(pr.id)] = 0;
            f[sf(pr.id)] = sf(p[i].id);
            v.pop_back();
        }
        if (v.empty() || v.back() != yminp) {
            v.push_back(yminp);
        }
        if (p[i].y < yminp.y) {
            v.push_back(p[i]);
        }
    }

    for (int i = 1; i <= n; i++) {
        printf("%d\n", c[sf(i)]);
    }


}

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

using namespace std;

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

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define sum(v) accumulate(ALL(v),0)

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    double rev = 0;
    rep(i,n){
        double tmp;
        cin>>tmp;
        tmp = 1/tmp;
        rev += tmp;
    }
    cout<<std::setprecision(10) << 1/rev <<endl;
    return  0;
}


Measured memory_bytes: 256
n = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
count = 0
for i in range(n):
    for j in range(2):
        if b_list[i] >= a_list[i+j]:
            b_list[i] -= a_list[i+j]
            count += a_list[i+j]
            a_list[i+j] = 0
            
        else:
            a_list[i+j] -= b_list[i]
            count += b_list[i]
            b_list[i] = 0
print(count)

Measured memory_bytes: 19156
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
 
Node root;
Node find(Node root,int key){
  if(root==NIL||root->key==key)
    return root;
  if(root->key > key)
    return find(root->left,key);
  else
    return find(root->right,key);
}

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;
}
Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y = x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return 0;
}

Node treeDelete(Node z){
  Node y;
  Node x;

  if(z->left==NIL || z->right==NIL) y=z;
  else y = treeSuccessor(z);
  
  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
    root=x;
  }else{
    if(y==y->parent->left){
      y->parent->left=x;
    }else{
      y->parent->right=x;
    }
  }
  if(y!=z) z->key=y->key;
  free(y);
  return 0;
}
  

void insert(int key){
   Node y = NIL;
   Node x = root;
   Node z;
    
   z =malloc(sizeof(struct node));
   z->key = key;
   z->left = NIL;
   z->right = NIL;
   while(x!=NIL){
     y=x;
     if(z->key < x->key)x=x->left;
     else x=x->right;
   }
   z->parent=y;
   if(y==NIL)root=z;
   else if(z->key <y->key)
   y->left=z;
   else
     y->right=z;
}
 
void inorder(Node root){
  if(root->left!=NIL)
    inorder(root->left);
  printf(" %d",root->key);
  if(root->right!=NIL)
    inorder(root->right);
}
 
void preorder(Node root){
  if(root!=NIL)
    printf(" %d",root->key);
  if(root->left!=NIL)
    preorder(root->left);
  if(root->right!=NIL)
    preorder(root->right);
}
 
int main(){
  int n, i, x;
  char com[10];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
     Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(com[0] == 'd'){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}

Measured memory_bytes: 19364
import math

k,n = map(int,input().split())
li = list(map(int,input().split()))
cnt=k+li[0]-li[-1]

for i in range(len(li)-1):
    if li[i+1]-li[i]>=cnt:
        cnt=li[i+1]-li[i]
print(k-cnt)
    

Measured memory_bytes: 26444
#include <iostream>

using namespace std;

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

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

	while (k--) {
		int x, y, ans;
		cin >> x >> y;
		--x; --y;

		if (n & 2) {
			if (x > n / 2) x = n - x - 1;
			if (y > n / 2) y = n - y - 1;
		} else {
			if (x >= n / 2) x = n - x - 1;
			if (y >= n / 2) y = n - y - 1;
		}
		
		if (x <= y) ans = x % 3 + 1;
		else ans = y % 3 + 1;

		cout << ans << endl;


	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <set>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    string s;
    cin>>n>>k;
    cin>>s;
    k--;
    s[k]=s[k]+32;
    cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
typedef vector<vector<int > > vec2int;
typedef vector<vector<bool > > vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int n, m;
  cin >> n >> m;
  vecbool ac(n + 1,false);
  vecint pena(n + 1,0);
  int tmp;
  string s;
  REP(i,m){
    cin >> tmp >> s;
    if(!ac[tmp]){
      if(s == "AC"){
	ac[tmp] = true;
      }else{
	pena[tmp]++;
      }
    }
  }
  int numac = 0;
  int numwa = 0;
  REP(i, n + 1){
    if(ac[i]){
      numac ++;
      numwa += pena[i];
    }
  }
  cout << numac << " " << numwa << endl;
}


Measured memory_bytes: 640
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S=get_int

sstr = S.to_s

amaris = {}
cur = 0
multi = 1
1.step(sstr.length) do |i|
  cur += sstr[-i].to_i * multi
  amari = cur % 2019
  amaris[amari] = 0 if amaris[amari].nil?
  amaris[amari] += 1

  multi = multi * 10 % 2019
end

sum = 0
amaris.values.filter { |x| x > 1 }.each do |x|
  sum += x * (x - 1) / 2
end

sum += amaris[0] if amaris[0]

puts sum


Measured memory_bytes: 15784
n=int(input())
s,t=[],[]
#s:曲名
#t:再生時間
for i in range(n):
    S,T=input().split()
    s.append(S)
    t.append(int(T))
x=input()
#print(s,t,sep='\n')

wake=0
for a,b in zip(s,t):
    wake+=b
    if a==x:
        print(sum(t)-wake)
        exit()


Measured memory_bytes: 3060
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: usize = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let S = sc.chars();
    let T = sc.chars();
    let mut ans = INF;
    for i in 0..S.len()-T.len()+1 {
        dbg!(i);
        let mut cnt = 0;
        for j in 0..T.len() {
            if S[i+j] != T[j] {
                cnt += 1;
            }
        }
        ans = min(ans, cnt);
    }
    println!("{}", ans);
}


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

int main()
{
	int n, i;
	char suits[4] = { 'S', 'H', 'C', 'D' };
	int d[4][13] = {
		{ 1,2,3,4,5,6,7,8,9,10,11,12,13 },
		{ 1,2,3,4,5,6,7,8,9,10,11,12,13 },
		{ 1,2,3,4,5,6,7,8,9,10,11,12,13 },
		{ 1,2,3,4,5,6,7,8,9,10,11,12,13 }
	};

	cin >> n;

	for (i = 0; i < n; i++)
	{
		char mark;
		int A;

		cin >> mark >> A;

		if (mark == suits[0]) d[0][A - 1] = 0;
		else if (mark == suits[1]) d[1][A - 1] = 0;
		else if (mark == suits[2]) d[2][A - 1] = 0;
		else if (mark == suits[3]) d[3][A - 1] = 0;

	}

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			if (d[i][j] != 0) cout << suits[i] << " " << d[i][j] << "\n";
		}
	}


	return 0;
}

Measured memory_bytes: 3088
/*
 * aoj/dpl_1_d/main.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


#include <set>
void solve() {
  int n;
  vector<int> A;
  multiset<int> S;
  cin >> n;
  A.resize(n);
  loop(i,0,n) cin >> A[i];

  for(auto&&a: A) {
    auto iter = S.lower_bound(a);
    if (iter != S.end()) S.erase(iter);
    S.insert(a);
  }

  cout << S.size() << endl;
}



Measured memory_bytes: 7752
q = int(input())

def solve(a,b):
    if a == b:
        return 2*a-2
    if b < a:
        return solve(b, a)

    lb, ub, ab = a, 2*b, a*b
    while ub-lb > 1:
        mid = (lb+ub)//2
        maxp = (mid)//2*(mid-(mid)//2)
        if maxp < ab:
            lb = mid
        else:
            ub = mid
    return lb-2

for _ in range(q):
    a, b = map(int, input().split())
    t = solve(a,b)
    print(t)


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

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

    bool ok = false;
    rep(m, 50000) {
        if (m * 108 / 100 == N) {
            ok = true;
            cout << m << endl;
            break;
        }
    }

    if (!ok) cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
void W(int line[],int temp[]){
    line[0]=temp[2];
    line[3]=temp[0];
    line[5]=temp[3];
    line[2]=temp[5];
}
void S(int line[],int temp[]){
    line[1]=temp[0];
    line[5]=temp[1];
    line[4]=temp[5];
    line[0]=temp[4];
}
void E(int line[],int temp[]){
    line[2]=temp[0];
    line[5]=temp[2];
    line[3]=temp[5];
    line[0]=temp[3];
}
void N(int line[],int temp[]){
    line[1]=temp[5];
    line[0]=temp[1];
    line[4]=temp[0];
    line[5]=temp[4];
}
int main(void){
    int line[6],i,t,temp[6];
    char ope[101];
    for(i=0;i<6;i++)
        scanf("%d",&line[i]);
    scanf("%s",ope);
    t=0;
    while(ope[t]){
        for(i=0;i<6;i++)
            temp[i]=line[i];
        if(ope[t]=='W')
            W(line,temp);
        else if(ope[t]=='S')
            S(line,temp);
        else if(ope[t]=='E')
            E(line,temp);
        else
            N(line,temp);
        t++;
    }
    printf("%d\n",line[0]);
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>

using namespace std;

int main(){
	long long N;
	long long tmp = 0;
	cin >> N;
	while (N >= 10) {
		if (N % 10 != 9) {
			N -= 10;
		}
		tmp += 9;
		N /= 10;
	}
	tmp += N;
	cout << tmp << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
    fast;
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll sum=0;
    if(k<=a) cout<<k;
    else{
        sum+=a;
        k-=a;
        if(k<=b) cout<<a;
        else{
            k-=b;
            sum-=k;
            cout<<sum;
        }
    }
}

Measured memory_bytes: 3652
from itertools import accumulate

h,w,k = map(int,input().split())
s = [list(map(int,"".join(input()))) for _ in range(h)]

min_split = 10**10

for i in range(2**(h-1)):
    li = []

    for j in range(h-1):
        if (i >> j)&1:
            li.append(j)
    li.append(h-1)
    lin = [0]*w
    total = []

    over = False

    for l in range(h):
        for m in range(w):
            lin[m] += s[l][m]
            if lin[m] > k:
                over = True
        if l in li:
            total.append(lin)
            lin = [0]*w

    if over:
        continue

    now = 0
    t = len(total)
    count = t-1

    for n in range(t):
        total[n] = [0]+list(accumulate(total[n]))
    for o in range(1,w+1):
        for p in range(t):
            if total[p][o]-total[p][now] > k:
                now = o-1
                count += 1
                break

    min_split = min(min_split,count)

print(min_split)

Measured memory_bytes: 9436
<?php
 
$n = trim(fgets(STDIN));
$a = explode(" ", trim(fgets(STDIN)));
 
if ($n === 2)
{
	echo abs($a[0] - $a[1]);
}
else
{
	$total = array_sum($a);
	$ans = abs($total - 2 * $a[0]);
	$x = 0;
	for ($i = 0; $i < $n-1; $i++)
	{
                $x += $a[$i];
		$ans = min($ans, abs($total - 2 * $x));
	}
	echo $ans;
}

Measured memory_bytes: 20980