akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	int n,g=0,k=0,t=0;
	cin>>n;
	long long a[n];
	for(int i=0;i<n;i++) a[i]=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%4==0) g++;
		else if(a[i]%2==0) t++;
		else k++;
	}
	if(g>=k-1&&t==0) cout<<"Yes"<<endl;
	else if(k<=g&&t>0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

#define N 4005

int n,m,p,ans[N],tp,stk[N];

int main(){
	scanf("%d%d",&n,&m); p=n+m;
	if (m>=n){puts("Impossible"); fflush(stdout); return 0;}
	for (int i=0;i<p;++i){
		if (!tp) stk[++tp]=i;
		else{
			printf("? %d %d\n",stk[tp],i); fflush(stdout);
			char ch; for (ch=getchar();ch!='N'&&ch!='Y';ch=getchar());
			if (ch=='N') --tp;
			else stk[++tp]=i;
		}
	}
	for (int x=stk[tp],i=0;i<p;++i){
		printf("? %d %d\n",x,i); fflush(stdout);
		char ch; for (ch=getchar();ch!='N'&&ch!='Y';ch=getchar());
		ans[i]=ch=='Y';
	}
	putchar('!'); putchar(' ');
	for (int i=0;i<p;++i) putchar(ans[i]+'0'); puts(""); fflush(stdout);
	
	return 0;
}
			

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

int main() {
  int a, b;
  while(cin >> a >> b) {
    int sum = a + b;
    int count = 1;
    while(sum >= 10) {
      count++;
      sum /= 10;
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 2956
from scipy import optimize

X = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

divisors = make_divisors(X)
divisors = divisors + [-x for x in divisors]
for p in divisors:
    def f(x):
        return (x+p)**5 - x**5 - X 
    sol = optimize.fsolve(f, X**(1./5.))
    B = int(round(sol[0]))
    A = B + p
    if A**5 - B**5 == X:
        print(A, B)
        break

Measured memory_bytes: 49704
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
x = max(a,b,c,d,e) - min(a,b,c,d,e)

if k >= x:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 3064
my $N = <STDIN>;
my $S;
my @arr = ("M","A","R","C","H");
foreach (@arr) {
        $S->{$_} = 0;
}
while (my $l = <STDIN>) {
        chomp $l;
        if ($l =~ /^([MARCH])/) {
                $S->{$1}++;
        }
}
my $num = 0;
foreach my $i (0..$N-1) {
        my $ival = $S->{$arr[$i]};
        next if ($ival == 0);
        foreach my $j ($i+1..$N-1) {
                my $jval = $S->{$arr[$j]};
                next if ($jval == 0);
                my $ijv = $ival * $jval;
                my $ktot = 0;
                foreach my $k ($j+1..$N-1) {
                        my $kval = $S->{$arr[$k]};
                        next if ($kval == 0);
                        $ktot += $kval;
                }
                $num += $ijv * $ktot;
        }
}
print $num;

Measured memory_bytes: 512
def encode(s):
    val = 0
    min_val = 0
    for c in s:
        if c == '(':
            val += 1
        else:
            val -= 1
            min_val = min(min_val, val)
    return [min_val, val]

def check(s):
    h = 0
    for p in s:
        b = h + p[0]
        if b < 0:
            return False
        h += p[1]
    return True


n = int(input())
ls = []
rs = []
l_total = 0
r_total = 0
for _ in range(n):
    si = encode(input())
    if si[1] > 0:
        ls.append(si)
        l_total += si[1]
    else:
        si[0] -= si[1]
        si[1] *= -1
        rs.append(si)
        r_total += si[1]
list.sort(ls, reverse=True)
list.sort(rs, reverse=True)
if check(ls) and check(rs) and l_total == r_total:
    print("Yes")
else:
    print("No")


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

int gcd(int a, int b) {
  int tmp;
  while (b != 0) {
    tmp = a;
    a = b;
    b = tmp%b;
  }
  return a;
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}



Measured memory_bytes: 3088
a, b, ab, x, y = map(int, input().split())
if a + b > ab*2:
  ab1 = True
else:
  ab1 = False

if a > ab*2:
  a1 = True
else:
  a1 = False

if b > ab*2:
  b1 = True
else:
  b1 = False

price = 0
if x > y:
  if ab1 is True:
    price += ab*2*y
    if a1 is True:
  	  price += ab*2*(x-y)
    else:
      price += a*(x-y)
  else:
    price += a*x + b*y
else:
  if ab1 is True:
    price += ab*2*x
    if b1 is True:
      price += ab*2*(y-x)
    else:
      price += b*(y-x)
  else:
    price += a*x + b*y
    
print(price)

Measured memory_bytes: 3064
def main():
    N = int(input())
    restrants = [None] * N
    for i in range(N):
        S, P = input().split()
        restrants[i] = (S, -int(P), i)
    restrants.sort()
    for i in range(N):
        _, _, i = restrants[i]
        print(i+1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
using System;

namespace ALDS_1_9_C
{
    class Program
    {
        static int H;
        static int[] A;
        static int parent(int i) { return i / 2; }
        static int left(int i) { return 2 * i; }
        static int right(int i) { return 2 * i + 1; }
        static void Main(string[] args)
        {
            A = new int[2000001];
            while (true)
            {
                var a = Console.ReadLine().Split(' ');
                if (a[0][0] == 'i') insert(int.Parse(a[1]));
                else if (a[0] == "extract")
                    Console.WriteLine(extract());
                else break;
            }
        }
        static int extract()
        {
            int maxv;
            if (H < 1) return int.MinValue;
            maxv = A[1];
            A[1] = A[H--];
            maxheapify(1);
            return  maxv;

        }
        static void increasekey(int i,int key)
        {
            if (key < A[i]) return;
            A[i] = key;
            while (i>1 && A[i/2]<A[i])
            {
                int temp = A[i];
                A[i] = A[i / 2];
                A[i / 2] = temp;
                i /= 2;
            }
        }
        static void insert(int key)
        {
            H++;
            A[H] = int.MinValue;
            increasekey(H, key);
        }
        static void maxheapify(int i)
        {
            int l = left(i);
            int r = right(i);
            //????????????????????????????????§?????§????????????
            int largest;
            if (l <= H && A[l] > A[i]) largest = l;
            else largest = i;
            if (r <= H && A[r] > A[largest]) largest = r;

            if (largest != i)
            {
                int tmp = A[i];
                A[i] = A[largest];
                A[largest] = tmp;
                maxheapify(largest);
            }
        }
    }
}

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

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

int main(int argc, char** argv){
  int n, x;
  
  while(cin >> n >> x) {
    int tmp;
    
    cin >> tmp;
    int g = abs(tmp - x);
       
    for (int i = 0; i < n - 1; i++) {      
      cin >> tmp;
      g = gcd(abs(x - tmp), g);
    }

    cout << g << endl;    
  }

  return 0;
}


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

#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

    ll n ;
    cin >> n ; 

    ll ans = n*(n-1)/2 ; 
    cout << ans << endl ;


    return 0 ;

}

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

int solve(){
  string s, t;  cin >> s >> t;
  map<string, int> mp;
  cin >> mp[s] >> mp[t];
  string u; cin >>u;
  mp[u]--;

  cout << mp[s] << " " << mp[t] << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String s = "";
        for (int i = 0; i < 3; i++) {
        	s += sc.next();
        }
        
        System.out.println(Integer.parseInt(s) % 4 == 0 ? "YES" : "NO");
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int n, T; cin >> n >> T;
    bool flg = false;
    int minv = 100000;

    for(int i=0; i<n; i++){
        int c, t; cin >> c >> t;
        if(t <= T){
            minv = min(minv, c);
            flg = true;
        }
    }

    if(flg == false) cout << "TLE" << endl;
    else cout << minv << endl;
}

Measured memory_bytes: 256
n,h=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
amax=max(A)
for i in range(n):
    if amax<=B[i]:
        C.append(B[i])
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt=0
ans=0
i=0
for i in range(len(C)):
    if ans<h:
        ans+=C[i]
    else:
        break
    cnt+=1
if ans<h:
    if ((h-ans)//amax)*amax>=h-ans:
        cnt+=(h-ans)//amax
    else:
        cnt+=(h-ans)//amax+1
        
print(cnt)

Measured memory_bytes: 12064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

void mebiusu_henkan(int N,ll*dp){
	//積集合で条件が与えられたとき、和集合の条件を返す
	dp[0]=0;
	rep(k,0,N)rep(j,0,1<<N)if(bit(j,k))dp[j]-=dp[j^(1<<k)];
	rep(j,0,1<<N)if(!__builtin_parity(j))dp[j]*=-1;
}

int n,k,and,or;
int aa[99];
int a[99];
ll dp[1<<18];
ll choose[60][60];
ll coe[60];
#define N 18

int main(){
	scanf("%d%d%d%d",&n,&k,&and,&or);
	rep(i,0,n)scanf("%d",aa+i);

	//10
	rep(k,0,N){
		if(bit(and,k)==1&&bit(or,k)==0){
			puts("0");
			return 0;
		}
	}
	
	//00,11
	{
		int cnt=0;
		rep(i,0,n){
			int mask=~(and^or);
			if((mask&and)==(mask&aa[i]))a[cnt++]=aa[i];
		}
		n=cnt;
	}

	choose[0][0]=1;
	rep(i,1,55){
		choose[i][0]=1;
		rep(j,1,i+1)choose[i][j]=choose[i-1][j-1]+choose[i-1][j];
		rep(j,1,k+1)coe[i]+=choose[i][j];
	}
	
	//01
	rep(mask,1,1<<N){
		int hoge=mask&(and^or);
		//hogeのところが全部ダメ
		if(hoge!=mask)continue;
		ll aaaaa[99];
		rep(i,0,n)aaaaa[i]=a[i]&hoge;
		sortup(aaaaa,n);
		//rep(i,0,n)printf("%d ",aaaaa[i]);puts("");
		aaaaa[n]=-1;
		int cnt=0;
		rep(i,0,n){
			cnt++;
			if(aaaaa[i]!=aaaaa[i+1]){
				dp[mask]+=coe[cnt];
				cnt=0;
			}
		}
	}	
	//rep(i,0,1<<N)printf("%lld ",dp[i]);puts("");
	mebiusu_henkan(N,dp);
	//rep(i,0,1<<N)printf("%lld ",dp[i]);puts("");

	printf("%lld\n",coe[n]-dp[(1<<N)-1]);
}

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

int n;
vector<int> et[100010];
vector<int> ec[100010];
int q,r,x,y;
int dist[100010];

void dfs(int v,int p = -1,int d = 0){
	dist[v] = d;
	for(int i = 0; i < et[v].size(); i++){
		if(et[v][i] == p )	continue;
		dfs(et[v][i] , v ,d + ec[v][i]);
	}
}
signed main()
{
	cin>>n;
	for(int i=0;i < n-1; i++){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		et[a].push_back(b);
		et[b].push_back(a);
		ec[a].push_back(c);
		ec[b].push_back(c);
	}
	cin>> q >> r;
	r--;
	dfs(r);
	for(int i = 0; i < q; i++){
		cin >> x >> y ;
		x--; y--;
		cout<<dist[x] + dist[y]<<'\n'; 
	}
	return 0;
}

Measured memory_bytes: 21376
NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
heightlst = list(map(int, input().split()))
roadlst = list()
for _ in range(M):
	roadlst.append(list(map(int, input().split())))
allroad = [[] for _ in range(N)]

for v in roadlst:
	allroad[v[0] - 1].append(v[1] - 1)
	allroad[v[1] - 1].append(v[0] - 1)

ans = 0
for i in range(N):
	flag = 0
	for v in allroad[i]:
		if heightlst[v] < heightlst[i]:
			flag += 1
	if flag == len(allroad[i]):
		ans += 1
print(ans)


Measured memory_bytes: 47556
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

  int n;
  cin>>n;

  cout<<n/2-(n%2==0)<<endl;


}

Measured memory_bytes: 764
N, M = map(int, input().split())
shops_n_limit = [list(map(int, input().split())) for _ in range(N)]

shop_list = sorted(shops_n_limit, key=lambda x: x[0])
cost = 0
num = 0
num_shop = 0
for i, shop in enumerate(shop_list):
    if num >= M:
        break
    cost += shop[0] * shop[1]
    num += shop[1]
    num_shop = i

if num != M:
    cost -= shop_list[num_shop][0] * shop_list[num_shop][1]
    num -= shop_list[num_shop][1]
    while num != M:
        cost += shop_list[num_shop][0]
        num += 1

print(cost)


Measured memory_bytes: 29800
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K,C;
    string str;
    cin >> N >> K >> C >> str;
    int L[K],R[K];
    int n=0;

    for(int i=0; i<K; i++){
        while(str[n]=='x'){
            n++;
        }
        L[i]=n;
        n+=C+1;
    }
    n=N-1;
    for(int i=K-1; i>=0; i--){
        while(str[n]=='x'){
            n--;
        }
        R[i]=n;
        n-=C+1;
    }
    for(int i=0; i<K; i++){
        if(L[i]==R[i]){
            cout << L[i]+1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3332
#include <stdio.h>

int main(void)
{
int a,b;
scanf("%d %d",&a,&b);
if(a<b){
	printf("a < b\n");
}
else if(a>b){
	printf("a > b\n");
}
else{
	printf("a == b\n");
}
return 0;
}


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

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
	ll cnt = N/(A+B);
    ll amari = N%(A+B);
	cout << cnt*A + min(A,amari) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(void) {

	int s;

	cin >> s;

	if (s < 1200) {
		cout << "ABC" << endl;
	}
	else if (1200 <= s && s < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}

	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll N;
  cin>>N;
  ll A;
  A=N%10;
  if(A==2 || A==4 || A==5 || A==7 || A==9) {
    cout<<"hon"<<endl;
  }
  if(A==0 || A==1 || A==6 || A==8) {
    cout<<"pon"<<endl;
  }
  if(A==3) cout<<"bon"<<endl;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  int prev;
  cin>>prev;
  prev--;
  for(int i=1;i<n;i++){
    int t;cin>>t;
    if(prev==t)continue;
    if(prev>t){
      puts("No");
      return 0;
    }
    prev=t-1;
  }
  puts("Yes");

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
const int N=107;
int n,m,k,P,f[N][N][N],C[N][N],pw[N][N];
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
int sub(int a,int b){return a-=b,a+(a>>31&P);}
int mul(int a,int b){return 1ll*a*b%P;}
int main()
{
    scanf("%d%d%d%d",&n,&m,&k,&P),f[0][0][0]=1;
    for(int i=0;i<=100;++i) for(int j=C[i][0]=1;j<=i;++j) inc(C[i][j]=C[i-1][j],C[i-1][j-1]);
    for(int i=0;i<=100;++i) for(int j=pw[i][0]=1;j<=100;++j) pw[i][j]=mul(pw[i][j-1],i);
    for(int h=1;h<=k;++h)
    {
	for(int i=0;i<=n;++i)
	    for(int j=0;j<=m;++j)
		for(int t=mul(pw[k-h+1][j],sub(pw[h][m-j],pw[h-1][m-j])),s=1,l=i;l<=n;++l)
		    inc(f[h][l][j],mul(mul(s,C[n-i][l-i]),f[h-1][i][j])),s=mul(s,t);
	for(int i=0;i<=n;++i)
	    for(int j=m;~j;--j)
		for(int t=mul(pw[h][n-i],sub(pw[k-h+1][i],pw[k-h][i])),s=1,l=j+1;l<=m;++l)
		    s=mul(s,t),inc(f[h][i][l],mul(mul(s,C[m-j][l-j]),f[h][i][j]));
    }
    printf("%d",f[k][n][m]);
}


Measured memory_bytes: 5368
#include<cstdio>

using namespace std;

signed main(){
    int ret = 0, d;
    while( scanf( "%d", &d ) != EOF ){
        int m = 600 / d;
        ret = m * ( m - 1 ) * ( 2 * m - 1 ) / 6 * d * d * d;
        printf( "%d\n", ret );
    }
    return 0;
}


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

int n;
int a[100010];
int b[100010];

int main()
{
	long long ans = 0;
	cin >> n;
	for (int i = 1; i <= n + 1; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}

	for (int i = 1; i <= n+1; i++) {
		if (b[i - 1] > 0) {
			if (a[i] >= b[i - 1]) {
				a[i] -= b[i - 1];
				ans += b[i - 1];
				b[i - 1] = 0;
			}
			else {
				ans += a[i];
				b[i - 1] -= a[i];
				a[i] = 0;
			}
		}
		if (a[i] > 0) {
			if (a[i] >= b[i]) {
				a[i] -= b[i];
				ans += b[i];
				b[i] = 0;
			}
			else {
				ans += a[i];
				b[i] -= a[i];
				a[i] = 0;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func small(N, X, M int) {
	a := X
	ans := X
	for i := 2; i <= N; i++ {
		a *= a
		a %= M
		ans += a
	}
	out(ans)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, X, M := getInt(), getInt(), getInt()

	// if N < 1000000000 {
	// 	small(N, X, M)
	// 	// return
	// }

	m := make([]int, M)
	b := make([]int, 0)
	last := -1
	a := X
	b = append(b, a)
	tot := a
	m[a]++
	for i := 2; i <= N; i++ {
		a *= a
		a %= M
		if m[a] != 0 {
			last = a
			break
		}
		if a == 0 {
			out(tot)
			return
		}
		tot += a
		m[a]++
		b = append(b, a)
	}
	// out(b, last, tot)
	if last == -1 {
		out(tot)
		return
	}
	start := 0
	ans := 0
	for i := 0; i < len(b); i++ {
		if b[i] == last {
			start = i
			break
		}
		ans += b[i]
		tot -= b[i]
	}
	N -= start
	loop := len(b) - start
	// out(N, loop, tot)
	n := N / loop
	ans += n * tot
	rest := N % loop
	for i := 0; i < rest; i++ {
		ans += b[start+i]
	}
	// out(n*loop + rest)
	out(ans)
}


Measured memory_bytes: 4944
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 100000000007
#define pi acos(-1.0)
ll n,m,j,k,l,t,arr[sz],brr[sz],crr[sz],drr[sz];
int main()
{
 scanf("%lld",&n);
 for(int i=1;i<n;i++)
 {
    scanf("%lld",&l);
    arr[l]++;
 }
 for(int i=1;i<=n;i++)
 printf("%lld\n",arr[i]);
}


Measured memory_bytes: 5276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,a[1000],count=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i%2==1&&a[i]%2==1)
        {
            count++;
        }
    }
    cout<<count<<'\n';
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	vector<int> a(s.size(), 0);
	s.push_back('R');
	int pv = 0;
	char c = 'R';
	rep(i, s.size()){
		char now = s[i];
		if(now == c) continue;
		int co = i - pv;
		if(now == 'L'){
			a.at(i-1) += (co+1) / 2;
			a.at(i) += co / 2;
		}else{
			a.at(pv-1) += co / 2;
			a.at(pv) += (co+1) / 2;
		}
		pv = i;
		c = now;
	}
	rep(i, a.size()){
		if(i != 0) cout << " ";
		cout << a.at(i);
	}
	cout << endl;
	return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const ll mod = 1000000007;
ll dp[55][2];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	for (;;) {
		string a, b, c;
		cin >> a; if (a == "0") break;
		cin >> b >> c;

		reverse(all(a));
		reverse(all(b));
		reverse(all(c));

		int n = a.size();

		// reset
		rep(i, 0, 55) rep(j, 0, 2) dp[i][j] = 0;
		dp[0][0] = 1;

		rep(i, 0, n) {
			rep(na, a[i] == '?' ? (i == n - 1 ? 1 : 0) : a[i] - '0', a[i] == '?' ? 10 : a[i] - '0' + 1)
			rep(nb, b[i] == '?' ? (i == n - 1 ? 1 : 0) : b[i] - '0', b[i] == '?' ? 10 : b[i] - '0' + 1)
			rep(carry, 0, 2) if (dp[i][carry]) {
				if (c[i] == '?' || (na + nb + carry) % 10 == c[i] - '0') {
					dp[i + 1][(na + nb + carry) / 10] += dp[i][carry];
					dp[i + 1][(na + nb + carry) / 10] %= mod;
				}
			}
		}

		cout << dp[n][0] << endl;
	}
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

pii A[MAXN];
int ans[MAXN];

vector<int> city[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    scanf("%d%d",&n,&m);

    for(int i=0;i<m;i++){
        scanf("%d%d",&A[i].f,&A[i].s);
        city[A[i].f].push_back(A[i].s);
    }

    for(int i=1;i<=100000;i++)
        sort(city[i].begin(),city[i].end());

    for(int i=0;i<m;i++){
        idx = lower_bound(city[A[i].f].begin(),city[A[i].f].end(),A[i].s)-city[A[i].f].begin();
        idx++;
        ans[i] = idx;
    }

    for(int i=0;i<m;i++){
        printf("%06d%06d\n",A[i].f,ans[i]);
    }

    return 0;
}


Measured memory_bytes: 10880
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A1 = new int[N];
        int[] A2 = new int[N];
        int[] count = new int[N];
        for (int i = 0; i < N ; i++) {
            A1[i] = sc.nextInt();
            if(i >=1){
                A1[i] += A1[i-1];
            }
        }

        for (int j = 0; j < N ; j++) {
            A2[j] = sc.nextInt();
        }

        for (int j = N-2; j >=0 ; j--) {
            A2[j]+=A2[j+1];
        }

        for (int i = 0; i < N ; i++) {
            count[i] = A1[i] + A2[i];
        }
        System.out.println( IntStream.of(count).max().getAsInt());
    }
}

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

#define LEN 100000

typedef struct {
	char name[100];
	int time;
} process;

void enqueue( process );
process dequeue();

int head, tail, n;
process q[LEN];

int main( void ){
	int i, queue, tmp;
	int progress = 0;
	
	scanf("%d %d", &n, &queue);
	
	for( i = 1; i <= n; i++ ){
		scanf("%s", q[i].name );
		scanf("%d", &q[i].time );
	}
	head = 1;
	tail = n+1;
	
	process u;
	while( head != tail ){
		u = dequeue();
		
		if( queue < u.time ){
			tmp = queue;
		}
		else{
			tmp = u.time;
		}
		
		u.time = u.time - tmp;
		progress = progress + tmp;
		
		if( u.time > 0 ){
			enqueue(u);
		}
		else{
			printf("%s %d\n", u.name, progress );
		}
	}
	
	return 0;
}

void enqueue( process a ){
	q[tail] = a;
	tail = (tail+1) % LEN;
}

process dequeue(){
	process a = q[head];
	head = (head+1) % LEN;
	
	return a;
}


Measured memory_bytes: 11852
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,ans=0,X=-1,Y=-1,plus;
  cin>>n;
  vector<int> x(n),y(n),h(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>h[i];
    if(h[i]>0) plus=i;
  }
  for(int i=0;i<101;i++){
    for(int j=0;j<101;j++){
      int height=abs(x[plus]-i)+abs(y[plus]-j)+h[plus];
      for(int k=0;k<n;k++){
        if(h[k]==0){
          if(height>abs(x[k]-i)+abs(y[k]-j)) goto next;
        }
        else{
          if(height!=abs(x[k]-i)+abs(y[k]-j)+h[k]) goto next;
        }
      }
      ans=height;
      X=i;
      Y=j;
      goto end;
      next:;
    }
  }
  end:;
  cout<<X<<" "<<Y<<" "<<ans<<endl;
}

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

int main() {
    string S;
    string sub = "";
    char C;
    cin >> S;
    int Q, T, F;
    int mode = 0;
    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        cin >> T;
        if(T == 1){
            mode++;
        }else{
            cin >> F >> C;
            if(mode%2){
                if(F == 2){
                    sub.push_back(C);
                }else{
                    S.push_back(C);
                }
            }else{
                if(F == 1){
                    sub.push_back(C);
                }else{
                    S.push_back(C);
                }
            }
        }
    }
    if(mode%2){
      reverse(S.begin(), S.end());
      cout << S + sub << endl;
    }else{
      reverse(sub.begin(), sub.end());
      cout << sub + S << endl;
    }
}

Measured memory_bytes: 1248
/*
                                               
 ____                 ______           _____   
|    |            ___|\     \      ___|\    \  
|    |           |    |\     \    |    |\    \ 
|    |           |    |/____/|    |    | |    |
|    |        ___|    \|   | |    |    |/____/|
|    |       |    \    \___|/     |    ||    ||
|    |       |    |\     \        |    ||____|/
|____|  ___  |\ ___\|_____|  ___  |____|       
|    | |   | | |    |     | |   | |    |       
|____| |___|  \|____|_____| |___| |____|       
  \(             \(    )/           \(         
   '              '    '             '      
   				template v.1.4   
                                           
*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(s) (int)s.size()
#define OPTIMIZE ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "#" << x << ": " << x << '\n';
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i--)
#define FORL(i, a, b) for (LL i = a; i <= b; i++)
#define FORDL(i, a, b) for (LL i = b; i >= a; i--)

using namespace std;

typedef long long LL;
typedef pair<int,int> ii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<ii> vii;
typedef vector<pll> vll;

const LL MODPRIME = 1e9 + 7;
const double EPS  = 1e-12;
const LL MAXL = 4e18;
const LL MINL = -4e18;
const int MAXI = 2e9;
const int MINI = -2e9;

int N;
int arr[105], ans;

int main(){
	// #ifndef ONLINE_JUDGE
	// 	freopen("in.txt", "r", stdin);
	// #endif
	OPTIMIZE
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> arr[i];
	ans = 1e9;
	for (int t = 1; t < N; t++){
		int s1 = 0;
		int s2 = 0;
		for (int j = 1; j <= N; j++){
			if (j <= t) s1+=arr[j];
			else s2 += arr[j];
		}
		ans = min(ans, abs(s1-s2));
		// if (ans == 0) cout << t << '\n';
	}
	cout << ans << '\n';
	return 0;
}

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

int main() {
  ll x, y;
  cin >> x >> y;
  if (x % y == 0) cout << -1 << endl;
  else cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
n, m, s = map(int, input().split())
rail = [[] for _ in range(n)]
fare = [[] for _ in range(n)]
time = [[] for _ in range(n)]
rate = []
TIME = []
for _ in range(m):
    i, j, k, l = map(int, input().split())
    i -= 1
    j -= 1
    rail[i].append(j)
    rail[j].append(i)
    fare[i].append(k)
    fare[j].append(k)
    time[i].append(l)
    time[j].append(l)
for _ in range(n):
    i, j = map(int, input().split())
    rate.append(i)
    TIME.append(j)
    
# Dijkstra's algorithm
# 銀貨の枚数がlimit以上になったら捨てる
limit = [max(i) for i in fare]
limit = max(limit) * n
if s >= limit:
    s = limit - 1

# dp[i][j] = 都市iで銀貨j枚を持っているための必要最小時間
dp = [[float('inf')] * limit for _ in range(n)]

# candidateに(必要時間, 都市番号, 銀貨の枚数)を追加していく
import heapq
candidate = [(0, 0, s)]
heapq.heapify(candidate)

ans = [-1] * n
todo = n

while todo > 0:
    i, j, k = heapq.heappop(candidate)
    if dp[j][k] != float('inf'):
        continue
    dp[j][k] = i
    if ans[j] == -1:
        ans[j] = i
        todo -= 1

    # 鉄道移動をcandidateに追加
    for l in range(len(rail[j])):
        if fare[j][l] <= k and dp[rail[j][l]][k - fare[j][l]] == float('inf'):
            heapq.heappush(candidate, (i + time[j][l], rail[j][l], k - fare[j][l]))
    
    # 両替をcandidateに追加
    if k < limit - 1:
        heapq.heappush(candidate, (i + TIME[j], j, min([k + rate[j], limit - 1])))

for i in range(1, n):
    print(ans[i])

Measured memory_bytes: 131104
#!/usr/bin/env python3

n = int(input())
ans = 0
for i in range(n):
    ans += (1 + (n - i)) * (n - i) // 2
for _ in range(n-1):
    u, v = map(int, input().split())
    if u > v:
        u, v = v, u
    ans -= u * (n - v + 1)

print(ans)

Measured memory_bytes: 9208
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll n;
    cin>>n;
    if(n > 999)cout<<"ABD"<<endl;
    else cout<<"ABC"<<endl;
}


Measured memory_bytes: 256
s=input()
t=input()
n=len(s)-len(t)-1
ans=len(t)
if n==-1:
    cnt=0
    for i in range(len(s)):
        if s[i]!=t[i]:
            cnt+=1
    ans=cnt
else:
    for i in range(n):
        cnt=0
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                cnt+=1
        ans=min(ans,cnt)
print(ans)


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

int main(void){
	int r, c, a[101][101], sum_r=0, sum_c=0, sum_all=0;
	cin >>r >>c;
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin >>a[i][j];
			cout <<a[i][j] <<" ";
			sum_r+=a[i][j];
			sum_all+=a[i][j];
		}
		cout <<sum_r <<endl;
		sum_r=0;
	}
	for(int j=0; j<c; j++){
		for(int i=0; i<r; i++){
			sum_c+=a[i][j];
		}
		cout <<sum_c <<" ";
		sum_c=0;
	}
	cout <<sum_all <<endl;
    return 0;
}

Measured memory_bytes: 1196
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit()
a = sorted(a, reverse=True)
res = a[0]
for ai in a[1:]:
    res *= ai
    if res > 10**18:
        print(-1)
        exit()
print(res)

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

using namespace std;

class Dice{
private:
  void roll(int a,int b,int c,int d){
    swap(x[a],x[b]);
    swap(x[b],x[d]);
    swap(x[c],x[d]);
  }
public:
  char x[6];
  void roll_N(){ roll(0,1,4,5); }
  void roll_E(){ roll(0,3,2,5); }
  void roll_S(){ roll(0,4,1,5); }
  void roll_W(){ roll(0,2,3,5); }
  void rotation(){ roll(1,2,3,4); }
};

Dice d[8],e[2][2][2];

int diff(char a,char b){
  return abs(a-b) == 32;
}

bool check(int idx){
  bool res = true;
  if(idx == 0){ return res; }
  if(idx == 1){
    return diff(e[0][0][0].x[1],e[1][0][0].x[4]);
  }
  if(idx == 2){
    return diff(e[0][0][0].x[2],e[0][1][0].x[3]);
  }
  if(idx == 3){
    res &= diff(e[1][0][0].x[2],e[1][1][0].x[3]);
    res &= diff(e[0][1][0].x[1],e[1][1][0].x[4]);
  }
  if(idx == 4){
    return diff(e[0][0][0].x[5],e[0][0][1].x[0]);
  }
  if(idx == 5){
    res &= diff(e[1][0][0].x[5],e[1][0][1].x[0]);
    res &= diff(e[0][0][1].x[1],e[1][0][1].x[4]);
  }
  if(idx == 6){
    res &= diff(e[0][0][1].x[2],e[0][1][1].x[3]);
    res &= diff(e[0][1][0].x[5],e[0][1][1].x[0]);
  }
  if(idx == 7){
    res &= diff(e[1][0][1].x[2],e[1][1][1].x[3]);
    res &= diff(e[0][1][1].x[1],e[1][1][1].x[4]);
    res &= diff(e[1][1][0].x[5],e[1][1][1].x[0]);
  }
  return res;
}

bool rec(int idx,int S){
  if(S == (1<<8)-1){ return true; }
  for(int i = 0 ; i < 8 ; i++){
    if((S >> i) & 1){ continue; }
    for(int j = 0 ; j < 4 ; j++){
      for(int k = 0 ; k < 4 ; k++){
        d[i].roll_N();
        e[idx%2][(idx%4)>1][idx>3] = d[i];
        if(check(idx) && rec(idx+1,S|(1<<i))){
          return true;
        }
      }
      for(int k = 0 ; k < 4 ; k++){
        d[i].roll_E();
        e[idx%2][(idx%4)>1][idx>3] = d[i];
        if(check(idx) && rec(idx+1,S|(1<<i))){
          return true;
        }
      }
      d[i].rotation();
    }
  }
  return false;
}

int main(){
  while(cin >> d[0].x[0],d[0].x[0] != '0'){
    for(int i = 0 ; i < 8 ; i++){
      for(int j = (i == 0) ; j < 6 ; j++){
        cin >> d[i].x[j];
      }
    }
    cout << (rec(0,0) ? "YES" : "NO") << endl;
  }
  return 0;
}

Measured memory_bytes: 1132
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    v = set()
    while n not in v:
        v.add(n)
        n = min(abs(n-k), n % k)

    return min(v)


print(main())





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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }			//最小公倍数(Least Common Multiple)

long long comb(long long m) {
	return (m * (m - 1)) / 2;
}


int main() {
	char x;
	cin >> x ;
	
	if ((int)x >= 65 && (int)x <= 90)
		cout << 'A' << endl;
	else
		cout << 'a' << endl;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>a>>b;
    if(a>0)  cout<<"Positive"<<endl;
    else  if(b>=0)  cout<<"Zero"<<endl;
    else  if((a&1)^(b&1))  cout<<"Positive"<<endl;
    else  cout<<"Negative"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int, int>;
const int INF = 1 << 30;

enum { START, END };

int N, Q;

void solve() {
    vector<Pair> A;
    map<int, string> mp;
    for(int i = 0; i < N; ++i) {
        string s;
        int e, w;
        cin >> s >> e >> w;
        int start = w - e + 1;
        A.emplace_back(start, START);
        A.emplace_back(w, END);
        mp[start] = s;
    }
    A.emplace_back(INF, START);
    sort(A.begin(), A.end());
    while(Q--) {
        int y; cin >> y;
        auto end = upper_bound(A.begin(), A.end(), make_pair(y, 0));
        if(end->second == 0) {
            cout << "Unknown" << '\n';
        } else {
            auto start = prev(end);
            cout << mp[start->first] << " " << y - start->first + 1 << '\n';
        }
    }
}

int main() {
    while(cin >> N >> Q) {
        if(!N) break;
        solve();
    }
    return 0;
}



Measured memory_bytes: 3308
#include <iostream>
#include <map>
#include <string>
#include <cstdlib>
#include <utility>

using namespace std;

map<string, int> table;
int main() {
    string word, frequent, longest;
    size_t N = 0;
    
    while (cin >> word) {
        table[word] += 1;
        if(table[word] > N){
            N = table[word];
            frequent = word;
        }
        if(word.size() > longest.size()){
            longest = word;
        }
    }
    cout << frequent << " " << longest << endl;
    
    return 0;
}

Measured memory_bytes: 3168
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
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 rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
vector<pair<ll,ll>> vec[100000];
int main(){
  ll n,d;
  cin >> n >> d;
  ll tmp=0;
  if(n%(2*d+1)!=0){
    tmp=1;
  }
  cout << n / (2*d+1) + tmp;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>
#include<stack>
#include<vector>
#include<numeric>

using namespace std;

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


Measured memory_bytes: 256
//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
using namespace std;
typedef long long ll;
#define int long long
#define SZ(x) ((int)(x).size())m
#define all(x)  x.begin(),x.end()
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//bool cmp(pair<string,int>p1,pair<string,int>p2) {
////    return p1.ss > p2.ss;
////}
////if (s1.find(s2) != std::string::npos) {
////   std::cout << "found!" << '\n';
////}
set<int>s;
void rec(int x) {
    if(x > 4e9)
        return;
    s.insert(x);
    int last = x % 10;
    if(last - 1 >= 0)
        rec(x*10 + last - 1);
    rec(x * 10 + last);
    if(last + 1 <= 9)
        rec(x * 10 + last + 1);
}
int32_t main() {
        fio
        int1(k)
    for (int i = 1; i <= 9; ++i) {
        rec(i);
    }
    vector<int> v;
    for(auto &i : s) {
        v.push_back(i);
    }
    cout << v[k-1];

    return 0;

        return 0;
}

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x = x2-x1;
  int y = y2-y1;
  cout << x2-y << " " << y2+x << " " << x2-y-x << " " << y2+x-y << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, D;
  cin >> N >> D;
  long ans = 0, a;
  vector<vector<long>> data(N, vector<long>(D));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < D; j++){
      cin >> data.at(i).at(j);
    }
  }
  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      a = 0;
      for(int k = 0; k < D; k++){
        a += pow(data.at(i).at(k) - data.at(j).at(k),2);
      }
      if(a == pow((long)sqrt(a),2))ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int Displayed(int grade)
{
    return (grade % 10 == 0 ? 0 : grade);
}

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

    vector<int> vec(n);
    auto sum = 0;

    for (auto &num : vec) {
        cin >> num;
        sum += num;
    }

    auto res = Displayed(sum);
    for (const auto &num : vec) {
        res = max(res, Displayed(sum - num));
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for(long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for(long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                                                            \
    (upper_bound((V).begin(), (V).end(), X) -                                  \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                                                               \
    {                                                                          \
        cerr << #v << ':';                                                     \
        for(auto xv : v) cerr << xv << ' ';                                    \
        cerr << endl;                                                          \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
    if(a > b) a = b;
    return a > b;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
    if(a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    ll N, M;
    cin >> N >> M;
    vl A(N);
    FOR(i, 0, N) cin >> A[i];
    sort(ALL(A));
    vector<pl> v;
    FOR(i, 0, M) {
        ll b, c;
        cin >> b >> c;
        v.push_back(make_pair(c, b));
    }
    sort(ALL(v), greater<pair<ll, ll>>());
    ll index = 0;
    FOR(i, 0, N) {
        if(index < v.size()) {
            if(A[i] < v[index].first) {
                A[i] = v[index].first;
                v[index].second--;
                if(v[index].second == 0) index += 1;
            }
        }
    }
    ll ans = 0;
    FOR(i, 0, N) {
        ans += A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3188