akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int[] a = new int[3];
			int[] b = new int[3];
			int h;
			int m;
			int min;
			int t = 0;
			for(int i = 0;i < n;i++){
				String[] str = scan.next().split(":");
				h = Integer.parseInt(str[0]);
				m = Integer.parseInt(str[1]);
				min = scan.nextInt();
				min = (min > m)?min-m:min-m+60;
				if(h >= 11 && h <= 14){
					t = 0;
				}else if(h >= 18 && h <= 20){
					t = 1;
				}else if(h >= 21 || h <= 1){
					t = 2;
				}else{
					continue;
				}
				if(min <= 8){
					b[t]++;
				}
				a[t]++;
			}
			System.out.println("lunch " + ((a[0] == 0)?"no guest":(int)(100*(double)b[0]/a[0])));
			System.out.println("dinner " + ((a[1] == 0)?"no guest":(int)(100*(double)b[1]/a[1])));
			System.out.println("midnight " + ((a[2] == 0)?"no guest":(int)(100*(double)b[2]/a[2])));
		}
	}
}

Measured memory_bytes: 24476
#include<bits/stdc++.h>
using namespace std;
int n,cnt[10005],a,v[10005],ans;
void fs(int x)
{
	if(x==13)
    {
        int rtn=24;
        for (int i=0;i<24;i++)
            for (int j=i+1;j<24;j++)
                if(v[i]&&v[j])
                    rtn=min(rtn,min(j-i,24-j+i));
        ans=max(ans,rtn);
        return ;
    }
    if (cnt[x]==2)
        v[x]=v[24-x]=1,fs(x+1);
    else if(cnt[x])
    {
        v[x]=1,fs(x+1),v[x]=0;
        if(x) v[24-x]=1,fs(x+1),v[24-x]=0;
    }
    else fs(x+1);
}
int main()
{
	scanf("%d",&n); for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);cnt[a]++;
	} cnt[0]++;
	for(int i=1;i<12;i++)
        if (cnt[i]>2)
            return puts("0"),0;
    if(cnt[12]>1||cnt[0]>1)
        return puts("0"),0;
    fs(0);
    return printf("%d\n",ans),0;
}

/*
AKIHABARA
*/

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

int main(){
    int N,K; cin >> N >> K;
    int p[N];
    for(int i=0;i<N;i++) cin >> p[i];
    set<int> s;
    for(int i=0;i<K;i++) s.insert(p[i]);
    int a[N]={};
    for(int i=1;i<N;i++){
        if(p[i]-p[i-1]>0) a[i]=1;
        a[i]+=a[i-1];
    }
    int ans=0;
    int res=N-K+1;
    bool check1[N]={};
    bool check2[N]={};
    for(int i=0;i<N-K;i++){
        int f=*s.begin();
        s.erase(p[i]);
        s.insert(p[i+K]);
        int l=*s.rbegin();
        //cout << f << l << endl;
        if(f==p[i]&&l==p[i+K]) check1[i]=true;
    }
    for(int i=0;i<N-K+1;i++){
        if(a[i+K-1]-a[i]==K-1) check2[i]=true;
    }
    int flag=0;
    for(int i=0;i<N;i++){
        if(check2[i]) flag++;
        if(check1[i]||check2[i]) ans++;
    }
    if(flag>=1) res++;
    cout << res-ans << endl;
}

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,ans[200005]={};
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>a;
		ans[a-1]++;
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}
  return(0);
}

Measured memory_bytes: 4412
def f(s):
  m,y = int(s[:2]), int(s[2:])
  return 0< m <= 12

def g(s):
  y,m = int(s[:2]), int(s[2:])
  return 0< m <= 12
    
s = raw_input()
p,q = f(s), g(s)

if p and q:
  print 'AMBIGUOUS'
elif p and not(q):
  print 'MMYY'
elif q and not(p):
  print 'YYMM'
else:
  print 'NA'

Measured memory_bytes: 27884
H, W = map(int, input().split())

dw = [[0]*W for _ in range(H)]
dh = [[0]*W for _ in range(H)]
maze = [[0]*W for _ in range(H)]

for h in range(H):
    s = input()
    c = 0
    for w, ss in enumerate(s):
        maze[h][w] = ss
        if ss == ".":
            c += 1
            dw[h][w] = c
        else:
            c = 0

for w in range(W):
    c = 0
    for h in range(H):
        ss = maze[h][w]
        if ss == ".":
            c += 1
            dh[h][w] = c
        else:
            c = 0

for h in range(H):
    m = 0
    for w in range(W)[::-1]:
        if dw[h][w] == 0:
            m = 0
        else:
            m = max(m, dw[h][w])
            dw[h][w] = m

for w in range(W):
    m = 0
    for h in range(H)[::-1]:
        if dh[h][w] == 0:
            m = 0
        else:
            m = max(m, dh[h][w])
            dh[h][w] = m

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, dh[h][w]+dw[h][w]-1)

print(ans)

Measured memory_bytes: 382600
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,S;
  cin >> s;
  S = "";
  for (int i = 0; i < s.size(); i++){
    if (s[i] == 'B'){
      if (S != ""){
        S = S.substr(0,S.size()-1);
      }
    } else {
      S = S + s[i];
    }
  }
  cout << S;
}

Measured memory_bytes: 256
from collections import defaultdict

tower = defaultdict(lambda: defaultdict(list))
for x in range(1, 5):
    for y in range(1, 4):
        for z in range(1, 11):
            tower[x][y].append(0)

count = int(input())

for x in range(count):
    b, f, r, v = map(int, input().split())
    if v > 0:
        tower[b][f][r-1] += v
    else:
        tower[b][f][r-1] -= -v


for key, value in tower.items():
    for layer, value in value.items():
        print(' ', end='')
        print(' '.join(map(str, value)))
    if key != 4:
        print('#' * 20)



Measured memory_bytes: 5996
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define N 100010
#define ll long long
using namespace std;
ll f[3];
void read(ll &x)
{
	x=0;
	int ch=0,flag=1;
	for(;!isdigit(ch);ch=getchar())
	if(ch=='-') flag=-flag;
	for(;isdigit(ch);ch=getchar())
	x=x*10+ch-'0';
	x*=flag;
}
int main()
{
	int n;
	scanf("%d",&n);
	f[0]=0,f[1]=f[2]=-10000000000000ll;
	for(int i=1;i<=n;i++)
	{
		ll x;
		read(x);
		f[0]+=x;
		f[1]-=x;
		f[2]+=x;
		if(x<0)
		{
			f[2]=max(f[2],f[1]);
			f[1]=max(f[1],f[0]);
		}
		f[0]=max(f[0],f[1]);
		f[1]=max(f[1],f[2]);
	}
	printf("%lld\n",f[0]);
	return 0;
}


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

int middleSquareMethod( int a )
{
    a *= a;
    a /= 100;

    int sum = 0, d = 1;
    for( int i = 0; i < 4; i++ )
    {
        sum += ( a % 10 ) * d;
        a /= 10;
        d *= 10;
    }

    return sum;
}

int main()
{
    int n, d;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> d;
        cout << "Case " << i + 1 << ":" << endl;

        int a = 10, b;
        while(a--)
        {
            b = middleSquareMethod(d);
            cout << b << endl;
            d = b;
        }
    }
    return 0;
}


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

Measured memory_bytes: 2760
#include <stdio.h>

int main (void) {

	int x, y;
	int i, j;

	while (1){
		if (x+y==0)
			break;
		scanf("%d %d", &x, &y);
		for (j=0; j<x; j++){
			for(i=0; i<y; i++){
				if( j==0 || j==x-1 || i==0 || i==y-1 ){
					printf("#");
				} else {
					printf(".");
				}
			}
		printf("\n");
		}
	if (x+y != 0)
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1000
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		// 計算
		int result = 0;
		result = a * b / 2;

		// 出力
		System.out.println(result);
        
	}
}


Measured memory_bytes: 23124
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int digsum(int N) {
  int res = 0;
  while (N > 0) {
    res += N % 10;
    N /= 10;
  }
  return res;
}

int main() {
  int N;
  while (cin >> N) {
    int res = 1 << 25;
    for (int A = 1; A < N; A++) {
      res = min(res, digsum(A) + digsum(N - A));
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{ long long int i,count=0,res,a,b,q,m,p,n,lcm;long int c,d;
  cin>>a>>b>>c>>d;lcm=(c*d)/__gcd(c,d);


 q=(b/c-a/c); p=(b/d-a/d); m=lcm;m=(b/m-a/m);
n=(q+p-m);res=b-a-n;
if(a%c!=0&&a%d!=0)
   cout<<(res+1);
   else cout<<res;}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{	int A[100],n,i=0,j,key,change=0,change_2;
	cin>>n;
	while(i<n)
		cin>>A[i++];
	for(i=0;i<n;i++)
	{	key=i;
		for(j=i;j<n;j++)
		{	if(A[j]<A[key])
				key=j;
		}
		if(i!=key)
		{	change_2=A[i],A[i]=A[key];
			A[key]=change_2,change++;
		}	
	}
	for(i=0;i<n;i++)
	{	cout<<A[i];	
		if(i!=n-1)
			cout<<" ";
	}
	cout<<endl;
	cout<<change<<endl;
		
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define ll long long
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
 
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;
		
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) {
  cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cout<<"{";
  __p(a.first);
  cout<<",";
  __p(a.second);
  cout<<"}";
}
template<typename T>
void __p(std::vector<T> a) {
  cout<<"{";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cout<<",}"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cout<<name<<" : ";
  __p(arg1);
  cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cout.write(names,comma-names)<<" : ";
  __p(arg1);
  cout<<" | ";
  __f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#define endl '\n'
#endif

struct edge{
	int a, b, weight;
};
		
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
		
long long modInverse(long long a, long long m) { 
    if(__gcd(a, m) != 1){
		throw "modular inverse does not exist.";
	}
	long long m0 = m;
    long long y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1) {  
        long long q = a / m; 
        long long t = m;  
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }  
    if (x < 0) 
       x += m0; 
    return x; 
} 
 
long long modExp(long long a, long long b, long long p) {
	long long res = 1;
	long long mult = a;
	while (b > 0) {
		if (b % 2 != 0) {
			res = (res * mult) % p;
		}
		mult = (mult * mult) % p;
		b >>= 1;
	}
	return res;
}
 
vector<int> sieveOfEratosthenes(int n) {
	vector<int> primes;
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int p = 2; p * p <= n; p++) {
		if (prime[p] == true) {
			for (int i = p * p; i <= n; i += p)
				prime[i] = false;
		}
	}
	for (int p = 2; p <= n; p++)
		if (prime[p])
			primes.push_back(p);
	return primes;
}
 
void solve() {
	ll a;
	double b;
	cin >> a >> b;
	ll c = (ll)round((b*100));
	
	trace(c);
	cout << (a*c)/100;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	for (int i = 0; i < t; i++) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3772
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<cmath>
#include<vector>
#include<map>
#include<random>
using namespace std;
#define ll long long 

ll gcd(ll a,ll b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}

int main(){
    int n;cin >> n;
    vector<ll>a(n);
    for(int i = 0;i < n;i++)cin >> a[i];
    ll ans = a[0];
    for(int i = 0;i < n;i++){
        ans = gcd(ans,a[i]);
    }
    cout << ans << endl;


}

Measured memory_bytes: 1024
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
cnt = 0
for i in range(K, N):
    if T[i] == T[i-K]:
        T[i] = "x"
for i in range(N):
    if T[i] == "r":
        cnt += P
    elif T[i] == "s":
        cnt += R
    elif T[i] == "p":
        cnt += S
print(cnt)


Measured memory_bytes: 4084
n,k=map(int,input().split())
l=[]
for i in range(n):
  x=int(input())
  l.append(x)
l.sort()
min=l[k-1]-l[0]
for i in range(1,n-k+1):
  x=l[k-1+i]-l[i]
  if x<min:
    min=x
print(min)

Measured memory_bytes: 7384
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  one = [0]*62
  zero = [0]*62
  for number in a:
    for i in range(62):
      if number >> i &1 == 1:
        one[i] +=1
      else:
        zero[i] += 1
  ans = 0
  mod = 10**9+7
  for i in range(62):
    ans += one[i]*zero[i]*int(2**i)
    ans %= mod
  print(ans)
        
solve()

Measured memory_bytes: 123260
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100000
using namespace std;
int rec[MAXN+5][4];
int seq[2][MAXN+5],len[2],tmp[MAXN+5];
int need[2];
int MergeSort(int l,int r,int id)
{
	if(l>=r)
		return 0;
	int ret=0;
	int mid=(l+r)/2;
	ret+=(MergeSort(l,mid,id)%2+MergeSort(mid+1,r,id)%2)%2;
	int i=l,j=mid+1,k=l;
	for(k=l;k<=r;k++)
	{
		if(j>r||(i<=mid&&seq[id][i]<seq[id][j]))
			tmp[k]=seq[id][i++];
		else
		{
			ret+=mid-i+1;
			ret%=2;
			tmp[k]=seq[id][j++];
		}
	}
	for(int i=l;i<=r;i++)
		seq[id][i]=tmp[i];
	return ret;
}
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=1;i<=3;i++)
		for(int j=1;j<=N;j++)
			scanf("%d",&rec[j][i]);
	bool legal=true;
	for(int j=1;j<=N;j++)
	{
		if(rec[j][1]+1==rec[j][2]&&rec[j][2]+1==rec[j][3])
		{
			if((rec[j][1]%6!=1&&j%2==1)||(rec[j][1]%6!=4&&j%2==0))
			{
				legal=false;
				break;
			}
			seq[j%2][++len[j%2]]=rec[j][1]/6+1;
		}
		else if(rec[j][1]-1==rec[j][2]&&rec[j][2]-1==rec[j][3])
		{
			if((rec[j][3]%6!=1&&j%2==1)||(rec[j][3]%6!=4&&j%2==0))
			{
				legal=false;
				break;
			}
			need[j%2]++;
			seq[j%2][++len[j%2]]=rec[j][3]/6+1;
		}
		else
		{
			legal=false;
			break;
		}
	}
	int cnt0=MergeSort(1,len[1],1);
	int cnt1=MergeSort(1,len[0],0);
	need[0]%=2,need[1]%=2;
	if(cnt0!=need[0]||cnt1!=need[1])
		legal=false;
	if(legal==false)
		printf("No\n");
	else
		printf("Yes\n");
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	int N;
	cin >> N;
	int ans = 0;
	for(int i=0; i<N; i++){
		int tmp;
		cin >> tmp;
		while(tmp%2 == 0){
			ans++;
			tmp /= 2;
		}
	}
	cout << ans << endl;

	return 0;
}



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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> good(N);
    for(int i = 0; i < N; i++) cin >> good.at(i);

    int sum = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i == j) continue;
            sum += good.at(i) * good.at(j);
        }
    }
    cout << sum / 2 << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
C=[-1]*N
ans=0
for i in range(M):
    s,c=map(int,input().split())
    if(s>N):
        ans=-1
    else:
        if(C[s-1]!=-1):
            if(C[s-1]!=c):
                ans=-1
        else:
            C[s-1]=c
if(C[0]==0):
    ans=-1

if(ans!=-1):
    for i in range(N):
        if(i==0):
            if(C[i]==-1):
                C[i]=1
        else:
            if(C[i]==-1):
                C[i]=0
    #print(C)
    for j in range(N):
        ans+=C[j]*(10**(N-1-j))
if(N==1 and C[0]==0):
    ans=0
if(N==1 and M==0):
    ans=0
print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

    return 0;
}


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

const int N = 200002;

int a[N], b[N];

int main() {
        ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
        multiset <int> st; int n; cin >> n;
        for(int i = 1; i <= n; i++) {
                int x; cin >> x;
                auto it = st.lower_bound(x);
                if(it == st.begin()) st.insert(x);
                else {
                        --it;
                        st.erase(it);
                        st.insert(x);
                }

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


}


Measured memory_bytes: 4992
#include<cstdio>
#include<vector>
using namespace std;

int insSort(vector<int> &arr, int g) {
	int	v, cnt;

	cnt = 0;
	for(int i=g; i<arr.size(); ++i) {
		int j;
		v = arr[i];
		for(j=i-g; j>=0 && arr[j]>v; j-=g) {
			arr[j+g] = arr[j];
			++cnt;
		}
		arr[j+g] = v;
	}
	return cnt;
}

int main() {
	int	n, tmp, m, cnt;
	vector<int>	arr, G;

	scanf("%d", &n);
	arr.reserve(n);

	for(int i=0; i<n; ++i) {
		scanf("%d", &tmp);
		arr.push_back(tmp);
	}

	tmp = 4;
	G.push_back(1);
	for(m=1; tmp<n; ++m) {
		G.push_back(tmp);
		tmp = 3 * tmp + 1;
	}

	cnt = 0;
	for(auto it=G.rbegin(); it!=G.rend(); ++it) {
		cnt += insSort(arr, *it);
	}

	printf("%d\n", m);
	for(auto it=G.rbegin(); it!=--(G.rend()); ++it) {
		printf("%d ", *it);
	}
	printf("%d\n", G[0]);
	printf("%d\n", cnt);
	for(auto it=arr.begin(); it!=arr.end(); ++it) {
		printf("%d\n", *it);
	}
}

Measured memory_bytes: 6264
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
    int a[10][10],n,d,i,j,k,c=0,x,b;
    scanf("%d %d",&n,&d);

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

    for(i=1; i<n; i++)
    {
        for(k=i+1; k<=n; k++)
        {
            x=0,b=0;
            for(j=1; j<=d; j++)
            {
                x= x+ (a[i][j]-a[k][j])*(a[i][j]-a[k][j]);
            }
            b=sqrt(x);
            if(b*b==x)
            {
                c++;
            }
        }
    }
    printf("%d\n",c);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> P(100010,0);
  rep(i,N) {
    int A; cin >> A;
    P[A]++;
  }
  ll sum = 0;
  rep(i,P.size()) {
    sum += i*P[i];
  }
  int Q; cin >> Q;
  vector<ll> S(Q);
  rep(i,Q) {
    int B, C; cin >> B >> C;
    sum += P[B]*(C-B);
    P[C] += P[B];
    P[B] = 0;
    S[i] = sum;
  }
  for(auto s:S) cout << s << endl;
}


Measured memory_bytes: 4496
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N;
	cin >> N;
	vector<int> a(N);
	rep(i, N) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int x = -1;
	int p = 0;
	rep(i, N) {
		if (x != a[i]) {
			p++;
			x = a[i];
		}
	}
	cout << p << endl;
}

Measured memory_bytes: 256
/**
 * author  : UshanGhosh
 * created : 2020-09-19 17:38:16
**/ 

#include<bits/stdc++.h>
using namespace std;

#define    ll      long long
#define    pii     pair<int,int>
#define    vii     vector<int>
#define    vcc     vector<char>
#define    pll     pair<long long, long long>
#define    mem     memset
#define    sof     sizeof
#define    co1     __builtin_popcountll
#define    PB      push_back
#define    UB      upper_bound
#define    LB      lower_bound
#define    MP      make_pair
#define    TS      to_string
#define    F       first
#define    S       second
#define    pi      acos(-1)
#define    mod     (int)1e9+7
#define    inf     (long long)1e18
#define    endl    '\n'

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,d,e,f,i,j,k,m,n,o,x,y;
    string s[3];
    for(i=0;i<3;i++) cin>>s[i];
    cout<<s[0][0]<<s[1][1]<<s[2][2]<<"\n";
}

Measured memory_bytes: 3584
def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 115408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

int main() {
  int N,M,K;
  cin >> N >> M >> K;
  vector<ll> a(N+1);
  vector<ll> data1(N);
  vector<ll> b(M+1);
  vector<ll> data2(M);
  a[0] = 0;
  b[0] = 0;

  rep (i,N) cin >> data1[i];
  rep (i,M) cin >> data2[i];

  for (int i = 1; i < N+1; i++) {
    a[i] = a[i-1] + data1[i-1];
  }

  for (int i = 1; i < M+1; i++) {
    b[i] = b[i-1] + data2[i-1];
  }

  ll ans = 0;

  for (int i = 0; i < N+1; i++) {
    ll nokori = K-a[i];
    if (nokori < 0) break;
    ll Iter = upper_bound(b.begin(), b.end(), nokori)-b.begin();
    Iter -= 1;
    Iter += i;
    ans = max(ans,Iter);
  }

  cout << ans << endl;

}


Measured memory_bytes: 9576
import java.util.Scanner;
import java.util.Stack;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("[\\s]+");
        while (sc.hasNext()) {
            double v = sc.nextDouble();
            for (int i = 0;; i++) {
                if (9.8 * Math.sqrt(5 * i / 4.9) >= v) {
                    System.out.println(i + 1);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 28112
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
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); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    string s;
    cin >> s;
    if (s[1] == 'B') s[1] = 'R';
    else s[1] = 'B';
    cout << s << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();

        int total = 700;
        total += s.charAt(0) == 'o' ? 100 : 0;
        total += s.charAt(1) == 'o' ? 100 : 0;
        total += s.charAt(2) == 'o' ? 100 : 0;
        System.out.println(total);
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ll n;
    cin>>n;
    ll arr[n][3];
    for(ll i=0;i<n;i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    ll dp[n][3];
    dp[0][0]=arr[0][0],dp[0][1]=arr[0][1],dp[0][2]=arr[0][2];
    for(ll i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+arr[i][2];
    }
    ll max1=0;
    for(ll i=0;i<3;i++){
        max1=max(dp[n-1][i],max1);
    }
    cout<<max1;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cmath>

using namespace std;

int main(void) {
  long long i, j, k, ans;
  long long N, rootN;
  // get input -----------------------------------------------
  cin >> N;
  // search (i, j) ------------------------------------------
  i = 1;
  j = 1;
  rootN = (long long)sqrt(N) + 1;
  for(k = 2; k <= rootN; k++) {
    if(N%k == 0) {
      i = k;
    }
  }
  // set answer --------------------------------------------
  j = N / i;
  ans = i + j - 2;
  // disp answer -------------------------------------------
  //cout << "(i, j)=(" << i << ", " << j << ")" << endl;
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
from math import *

N, M = map(int, input().split())
special_value = M//N
divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
divisor_set = divisor_set.union(M//j for j in divisor_set)
print(int(max(divisor_set, key=lambda x: x if special_value >= x else -1)))

Measured memory_bytes: 3316
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#define ull unsigned long long 
#define ll long long 
#define ld long double
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define MAXN 202000
#define INF 2000000000
const double weight = 4.292036732051034;
const double weight2 = 11.415926535897931;

const double pi=3.141592653589;
using namespace std;

int X1,Y1,X2,Y2,n;
vector<pii >G;
vector<int>lis; 

int ans[MAXN];

int main()
{
	cin>>X1>>Y1>>X2>>Y2;
	cin>>n;
	
	int maxx=max(X1,X2),minx=min(X1,X2),maxy=max(Y1,Y2),miny=min(Y1,Y2);
	int W=maxx-minx,H=maxy-miny;
	bool sx=X1>X2,sy=Y1>Y2;
	
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		x-=X1;
		y-=Y1;
		if(sx)x=-x;
		if(sy)y=-y;
		if(0<=x&&x<=W&&0<=y&&y<=H)
		{
			G.push_back(make_pair(x,y));
		}
			
	}
	
	sort(G.begin(),G.end());
	for(int i=0;i<G.size();i++)
		lis.push_back(G[i].second);
	
	
	
	for(int i=0;i<MAXN-3;i++)
		ans[i]=INF;
	
	
	for(int i=0;i<lis.size();i++)
			*lower_bound(ans,ans+(int)lis.size(),lis[i])=lis[i];
		
	int res;
	if(lis.empty())res=0;	
	else res=lower_bound(ans,ans+(int)lis.size(),INF)-ans;
	
	
	double realres=(W+H)*100.0;

	if(res<min(W,H)+1)
	{
		realres-=res*weight;
	}
	else {
			realres -= (res - 1) * weight;
		realres += weight2;		}

	
	printf("%.10f\n",realres);
	
	
		
	
	
	return 0;	
} 

Measured memory_bytes: 4464
n,c,k = map(int,input().split())
t = [int(input()) for i in range(n)]
t.sort()
cnt = 0
i = 0
while t != []:
    if len(t) == 1:
        cnt += 1
        break
    while t[i] - t[0] <= k:
        i += 1
        if i == len(t) :
            break
        if i == c:
            break
    del t[:i]
    cnt += 1
    i = 0
print(cnt)


Measured memory_bytes: 7384
// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    io;
    ll n,ans=0;
    cin>>n;
    FOR(j,1,n+1)
    {
    	ll y=n/j;
    	ans+=(y*(y+1)*j)/2;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3652
import bisect
from itertools import accumulate
n, *ABC = map(int, open(0).read().split())
A, B, C = ABC[:n], ABC[n:2*n], ABC[2*n:3*n]
A.sort()
B.sort()
C.sort()
D = [bisect.bisect_left(A, b) for b in B]
E = [bisect.bisect_left(B, c) for c in C]
F = list(accumulate(D))
s = 0
for e in E:
    if e != 0:
        s += F[e-1]
print(s)

Measured memory_bytes: 38620
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
vector<int> e[111];

bool f[111];
int solve(int m){
  int ret = 0;
  for(int i = 0; i < (int)e[m].size(); i++){
    if(f[e[m][i]]) continue;
    f[e[m][i]] = true;
    ret = max(ret,solve(e[m][i]));
    f[e[m][i]] = false;
  }
  return ret + 1;
}

int main(void){
  while(cin >> n && n){
    for(int i = 1; i <= 100; i++) e[i].clear();
    for(int i = 0; i < n; i++){
      int a,b;
      cin >> a >> b;
      e[a].push_back(b);
      e[b].push_back(a);
    }

    int res = 0;
    for(int i = 1; i <= 100; i++){
      memset(f,false,sizeof(f));
      f[i] = true;
      res = max(res,solve(i));
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e5+5;
const int mod = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    cout<<1.0*((n+1)/2)/n;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		s = s.replaceAll("0", "");
		System.out.println(s.length());
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
class UnionFindTree
{
    vector<int> parent;
    vector<int> depth;
    vector<int> cnt;

public:
    UnionFindTree(int n) : parent(n), depth(n), cnt(n)
    {
        for (int i = 0; i < n; i++)
        {
            parent[i] = i;
            depth[i] = 0;
            cnt[i] = 1;
        }
    }

    //木の根を求める
    int find(int x)
    {
        if (parent[x] == x)
        {
            return x;
        }
        else
        {
            return parent[x] = find(parent[x]);
        }
    }

    //xとyの属する集合を併合
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (depth[x] < depth[y])
        {
            parent[x] = y;
            cnt[y] += cnt[x];
        }
        else
        {
            parent[y] = x;
            cnt[x] += cnt[y];
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }

    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    int size(int x)
    {
        return cnt[find(x)];
    }
};
int main(){
    int n;
    cin >> n;
    vector<P> c(n);
    vector<P> d(n);
    int mx = 0;
    UnionFindTree utree(n+10);
    rep(i,n){
        int x;
        cin >> x;
        c[i] = P(x,i);
    }
    rep(i,n){
        int x;
        cin >> x;
        d[i] = P(x,i);
    }
    sort(c.begin(),c.end());
    sort(d.begin(),d.end());
    rep(i,n){
        if(c[i].first>d[i].first){
            cout << "No" << endl;
            return 0;
        }
        utree.unite(c[i].second,d[i].second);
        mx = max(mx,utree.size(c[i].second));
    }
    if(mx==n){
        // ソートの結果が巡回置換になっている
        rep(i,n-1){
            if(c[i+1].first<=d[i].first){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long ans = 0, bcnt = 0;
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] == 'B') ++bcnt;
    if(s[i] == 'W') ans += bcnt;
  } 
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef long long ll;
#define all(c) begin(c),end(c)

ll f(ll a, ll b) {
//    cerr << a << "," << b << endl;
    if (a == 0) return 0;
    if (b == 0)return 0;

    if (a == b)
        return a;

    if (a < b) {
        ll rem = b % a;
        ll d = b / a;
        if (rem == 0)
            return 2 * (d-1) * a + a;
        return 2 * d * a + f(a, rem);
    } else {
        ll rem = a % b;
        ll d = a / b;
        if (rem == 0)
            return 2 * (d-1) * b + b;
        return 2 * d * b + f(rem, b);
    }

}

auto solve() {
    ll N, X;
    cin >> N >> X;

    return N + f(N - X, X);
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;


int main() {
    ll n;
    cin >> n;
    cout << n*n*n << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
// #define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    ll n,t;
    ll a[110],b[110];
    cin>>n>>t;
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    ll ans=LLINF;
    rep(i,n){
        if(b[i]<=t)chmin(ans,a[i]);
    }
    if(ans==LLINF) cout<<"TLE"<<endl;
    else cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

// int main() {
//   int n;
//   cin >> n;
//   int a[n],b[n],c[n];
//   for(int i = 0; i < n; ++i){
//     cin >> a[i];
//   }
//   for(int i = 0; i < n; ++i){
//     cin >> b[i];
//   }
//   for(int i = 0; i < n-1; ++i){
//     cin >> c[i];
//   }
//   int res=0;
//   for(int i = 0; i < n; ++i){
//     res+=b[a[i]-1];
//     if(a[i]!=n){
//       if(b[a[i]-1] + 1 == b[a[i+1]]-1){
//         res+=c[a[i]-1];
//       }
//     }
//   }
//   cout << res << endl;
// }

int main() {
  int N; cin >> N;
  // input
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    --A[i];
  }
  vector<int> B(N);
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }
  vector<int> C(N-1);
  for (int i = 0; i < N; ++i) {
    cin >> C[i];
  }
  // calc
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += B[A[i]];
    if (i > 0 && A[i] == A[i-1]+1) {
      ans += C[A[i-1]];
    }
  }
  // output
  cout << ans << endl;
}

Measured memory_bytes: 3580
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	int N; scanf("%d", &N);
	printf("%d", (N - 1) / 2);

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int a,ans;
    
    while(cin >> a,a!=0){
        
        ans = 100010;
        for(int i=0;i*i*i<=a;i++){
            for(int j=0;j*j<=a-i*i*i;j++){
                ans = min(ans,i+j+(a-i*i*i-j*j) );
            }
        }
        
        cout << ans << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 3012
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include <iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {X=X;}
#define TF(f) {f=f;}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 1000000;
#define NMAX 50
#define MAX 10
    int N;
    int fir=0,en;
    vector<string> S,A,Z;
    string T;
int main(){
    cin>>N;
    REP(i,N){
        string s,a,z;
        cin>>s;
        a=s;
        z=s;
        REP(i,(signed)s.size()){
            if(s[i]=='?'){
                a[i]='a';
                z[i]='z';
            }
        }
        A.push_back(a);
        Z.push_back(z);
    }
    cin>>T;
    A.push_back(T);
    Z.push_back(T);
    sort(ALL(A));
    sort(ALL(Z));
    REP(i,(signed)Z.size()){
        if(Z[i]==T){
            fir=i+1;
            break;
        }
    }
    REP(i,(signed)A.size()){
        if(A[i]==T){
            en=i+1;
        }
    }
    FOR(i,fir,en+1){
        cout<<i;
        if(i!=en)cout<<" ";
    }
cout<<endl;
}


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

int main() {
	ll n,ans,a,b;
	cin >> n;
	ans=n-1;
	for(ll i=2;i*i<=n;i++){
		a=i;
		if(n%i==0){
			b=n/i;
			ans=min(ans,a+b-2);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define alpha_size 26


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
    
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k)
    cout << s << endl;
  else
  cout << s.substr(0, k) + "..." << endl; 
}
 

Measured memory_bytes: 3656
num = int(input())

S = [x for x in range(1,14)]
H = [x for x in range(1,14)]
C = [x for x in range(1,14)]
D = [x for x in range(1,14)]

for i in range(num):
    s = input().split()
    
    if s[0]=="S":        
        S.remove(int(s[1]))
    elif s[0]=="H":        
        H.remove(int(s[1]))
    elif s[0]=="C":        
        C.remove(int(s[1]))
    elif s[0]=="D":        
        D.remove(int(s[1]))
    
for i in range(len(S)):
    print("S",S[i])
for i in range(len(H)):
    print("H",H[i])
for i in range(len(C)):
    print("C",C[i])
for i in range(len(D)):
    print("D",D[i])



Measured memory_bytes: 5628
#include <bits/stdc++.h>
typedef long long ll;

int gcd(int a, int b){ return b == 0 ? a : gcd(b, a % b);};
ll lcm(ll a, ll b){ return a * (b / gcd(a, b)); }
using namespace std;


int main(){

    ll a = 0, b = 0;
    int n = 0;
    cin >> a >> b >> n;
    bool first = true;
    while(n > 0){
        if(first){
            if(a % 2 != 0){
                a--;
            }
            b += a / 2;
            a -= a / 2;
        }else{
            
            if(b % 2 != 0){
                b--;
            }
            a += b / 2;
            b -= b / 2;
        }
        first = !first;
        n--;
    }

    cout << a << " " << b << "\n";

    return 0;
}

Measured memory_bytes: 256
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
	i %= n
	a = que[i]
	if 0 < a[1] <= q:
		t += a[1]
		que.pop(i)
		n -= 1
		print a[0],t				
	elif q < a[1]:
		t += q
		que[i][1] = a[1] - q
		i += 1

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x,y;
    cin>>n>>x>>y;
    x--;
    y--;
    map<int,int> ma;
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<n;++j)
        {
            
            if(j<=x)
            {
                int temp=j-i;
                ma[temp]++;
            }
            else
            {
                int temp1=abs(x-i)+1+abs(y-j);
                int temp2=j-i;
                int temp=std::min(temp1,temp2);
                ma[temp]++;
            }
            
            
        }
    }

    for(int i=1;i<=n-1;++i)
    {
        cout<<ma[i]<<"\n";
    }


    
}


Measured memory_bytes: 384
let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ss = Array.init h @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let _ =
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      let f c (dy, dx) =
        let y, x = i + dy, j + dx in if 0 <= y && y < h && 0 <= x && x < w && ss.(y).[x] = '#' then c + 1 else c in
      if ss.(i).[j] = '.' then print_int @@ List.fold_left f 0 [-1, 0; -1, -1; 0, -1; 1, -1; 1, 0; 1, 1; 0, 1; -1, 1]
      else print_char ss.(i).[j] done; print_newline () done

Measured memory_bytes: 1024
package main

import "fmt"

func Traveling(t, x, y int) bool{
	if t < x + y || t % 2 != (x + y) % 2 {
		return false
	}else{
		return true
	}
}

func main() {
  	var N int
	fmt.Scan(&N)
	var t, x, y int
	ok := true
	for i := 0; i < N; i++ {
		fmt.Scanln(&t, &x, &y)
		traveling := Traveling(t, x, y)
		if traveling == false {
			ok = false
		}
	}
	if ok == false {
		fmt.Println("No")
	}else{
		fmt.Println("Yes")
	}
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,x,m,min=10000;cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>m;x-=m;
        if(m<min)min=m;
    }
    n+=x/min;
    cout<<n<<endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
 
  if (a +b > c + d) {
    cout << "Left" << endl;
  }
  else if (a +b == c + d) {
    cout << "Balanced" << endl;
  }
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256