akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
struct RAQ {
  int n,k;
  vector<int> data;
  vector<int> delay; // 遅延
  RAQ(int n): n(n) {
    k = sqrt(n) + 1;
    data.resize(k * k, 0);
    delay.resize(k, 0);
  }

  // [s,t)
  void add(int s, int t, int x) {
    for(int i = 0; i < k; i++) {
      int l = i * k, r = (i + 1) * k;
      if(r <= s || t <= l) continue;
      // 全て含まれる
      if(s <= l && r <= t) {
        delay[i] += x;
      } else {
        for(int j = l; j < r; j++) {
          data[j] += delay[i];
        }
        delay[i] = 0;
        for(int j = max(s, l); j < min(t, r); j++) {
          data[j] += x;
        }
      }
    }
  }

  int get(int i) {
    int j = i / k;
    return data[i] + delay[j];
  }
  
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  RAQ raq(n);
  FOR(i,0,q) {
    int f; cin >> f;
    if(f) {
      int i; cin >> i;
      cout << raq.get(i) << endl;
    } else {
      int s,t,x;
      cin >> s >> t >> x;
      raq.add(s, t + 1, x);
    }
  }
  
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, cnt = 0, w, h;
string s;
vector<ll> v;
vector<ll> v1;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
set<ll> st;
map<char, ll> mp;

/*--------------------template--------------------*/

int main()
{
	cin >> n >> k;
	ans = n + k;
	if (ans > 23)
	{
		ans -= 24;
	}
	cout << ans << endl;
}

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

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

       return 0;
   }

    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt = 0, k[11],p[11],s[11][11],sw[11];

int main(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j];
            sw[s[i][j]] |= 1 << i;
        }
    }
    int target = 0;
    for(int i = 1; i <= m; i++) {
        cin >> p[i];
        target |= p[i] << i;
    }
    for(int i = 0; i < (1 << n+1); i+=2){
        int now = 0;
        for(int j = 1; j <= n; j++){
            if(i >> j & 1) {
                now ^= sw[j];
            }
        }
        if(now == target) cnt++;
    } 
    cout << cnt << endl;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int S;
int did[1010101];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	did[S]=1;
	for(int i=2;;i++) {
		if(S%2==0) {
			S/=2;
		}
		else {
			S=S*3+1;
		}
		if(did[S]) return _P("%d\n",i);
		did[S]=1;
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
      List<string> youso = new List<string>();
      string line = "";
      while((line=Console.ReadLine()) != null)
      {
        youso.Add(line.ToString());
      }
      /////////////////////////////////////////
      
      string answer;

      string Today = youso[0].ToString();

      Dictionary<string, string> Weather = new Dictionary<string, string>()
      {
        {"Sunny","Cloudy" },
        {"Cloudy","Rainy" },
        {"Rainy","Sunny" }
      };

      answer = Weather[Today];
      Console.WriteLine(answer);        
	}
  
  
  
}


Measured memory_bytes: 13408
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <iterator>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
 
typedef long long LL;
typedef pair<double, double> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<LL, LL> PLL;
 
const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF * INF;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = INF + 7;

const int maxn = 3*100010;
VI g[maxn];
int d[maxn];
int q[maxn];
int main()
{
//  freopen("input.txt","r",stdin);
    int n,m;
    cin >> n >> m;
    FOR(i,0,m)
    {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[3*a].PB(3*b+1);
        g[3*a+1].PB(3*b+2);
        g[3*a+2].PB(3*b);
    }
    int s,t;
    cin >> s >> t;
    s--; t--;
    FOR(i,0,maxn)
        d[i] = INF;
    d[3*s] = 0;
    int qh = 0,qt = 0;
    q[qh++] = 3*s;
    while(qh!=qt)
    {
        int v = q[qt++];
        FOR(i,0,SZ(g[v]))
        {
            if(d[g[v][i]]!=INF) continue;
            q[qh++] = g[v][i];
            d[g[v][i]] = d[v] + 1;    
        }
    }


    if(d[3*t]==INF)
    {
        cout << -1;
    }
    else
    {
        cout << d[3*t]/3;
    }
    
    return 0;
}

Measured memory_bytes: 18944
def nod(a, b):
    if a == 0:
        return b
    elif a > b:
        return nod(a % b, b)
    return nod(b % a, a)


a, b, c, d = map(int, input().split())
ac = a + (c - a % c) % c
ad = a + (d - a % d) % d
bc = b - b % c
bd = b - b % d
dc = c*d//nod(c,d)
acd=a + (dc - a % dc) % dc
bcd = b - b % dc
print(b-a+1-(max(0,(bc-ac)//c+1)+max(0,(bd-ad)//d+1)-max(0,(bcd-acd)//dc+1)))

Measured memory_bytes: 3064
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)
import numpy as np


def main():
    N, K = map(int, input().split())
    H = np.array(list(map(int, input().split())), dtype=np.int64)
    dp = np.zeros(N, dtype=np.int64)
    for i in range(1, N):
        L = max(0, i - K)
        dp[i] = np.min(np.abs(H[i] - H[L:i]) + dp[L:i])

    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 22816
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const ll mod = 1'000'000'007;
const ll mod1= 998244353;
const int N = 5e5, M = N;
//=======================

vi g[N];
int a[N];
int f[1000000];


void solve() {
   int n;
   cin>>n;
   fo(i,n)
   {
       cin>>a[i];
   }
   int best=a[0];
   ll ans=0;
   Fo(i,1,n)
   {
       if(a[i]<best)
       {
           ans+=abs(a[i]-best);
       }
       else
        best=a[i];
   }
   cout<<ans<<"\n";
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
      solve();
    }
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}


void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}


Measured memory_bytes: 16128
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 

int main(){
  string s;cin>>s;
  string ans="No";
  if(s.size()%2==1){
  }
  else{
    for(int i=1;i<s.size();i=i+2){
      if(s.at(i-1)=='h' && s.at(i)=='i')
        ans="Yes";
    }
  }
  cout<<ans;
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
		ios::sync_with_stdio(false);
		cin.tie(0);
		ll n;
		cin>>n;
		ll ans=0;
		if(n>=195)ans = 5;
		else if(n>=189)ans = 4;
		else if(n>=165)ans = 3;
		else if(n>=135)ans = 2;
		else if(n>=105)ans = 1;
		cout<<ans<<endl;
}

Measured memory_bytes: 256
S=input()
T=input()
t=len(T)
s=len(S)
if s<t:
  print("UNRESTORABLE")
  exit()
L=list()
for i in range(s-t+1):
  "S[i]からs[i+t-1]までの文字列"
  for j in range(t):
    if S[i+j]!="?" and S[i+j]!=T[j]:
      break
    if j==t-1:
      k=S[:i]+T+S[i+t:]
      k=k.replace("?","a")
      L.append(k)
if len(L)==0:
  print("UNRESTORABLE")
else:
  L=sorted(L)
  print(L[0])

Measured memory_bytes: 61908
#include <bits/stdc++.h>
#define REP(i, a, b) for(long long i = (a); (i) < (b); (i)++)
using namespace std;
using ll = long long;
using vecll = vector<ll>;

int main() {
    string S;
    cin >> S;
    ll n = S.size();
    reverse(S.begin(), S.end());

    vecll powmod(n,1);
    REP(i, 1, n) powmod[i] = powmod[i - 1] * 10 % 2019;
    vecll cnt(2019,0);

    ll sum = 0, ans = 0;
    cnt[sum] = 1;

    REP(i, 0, n){
        sum += (S[i] - '0') * powmod[i];
        sum %= 2019;
        ans += cnt[sum];
        cnt[sum]++;
    }
    cout << ans << endl;
}

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

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int> b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    ll t = 0;
    rep(i, m) t += b[i];

    int j = m;
    int ans = 0;

    rep(i, n+1){
        while(j > 0 && t > k){
            --j;
            t -= b[j];
        }
        if (t > k) break;
        ans = max(ans, i + j);
        if (i == n) break;
        t += a[i];
    }
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 4820
n = int(input())
AL = list(map(int,input().split()))
BL = list(map(int,input().split()))
CL = list(map(int,input().split()))
ans = 0
tmp = AL[0]-1
for i in AL:
    i = i-1
    ans += BL[i]
    if tmp == i-1:
        ans += CL[tmp]
    tmp = i
print(ans)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		String message = "No";
		if(a <= c && c <= b) {
			message = "Yes";
		}
		System.out.println(message);
	}
}

Measured memory_bytes: 21844
import sys
import random
from copy import copy
from math import floor, e

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def write_output(out):
    with open("my_sample3.out", mode="w") as f:
        for x in out:
            f.write(str(x + 1) + "\n")


def main():
    d = int(readline())
    c = list(map(int, readline().split()))
    s = [list(map(int, readline().split())) for _ in range(d)]

    sat_cur = 0
    last = [1] * 26
    out = [-1] * d

    for day in range(d):
        estimate = [0.0] * 26
        for cid in range(26):
            if s[day][cid] > 16000:
                estimate[cid] = last[cid] * c[cid] + c[cid] ** 1
        cur = estimate.index(max(estimate))
        out[day] = cur
        sat_cur += s[day][cur]
        last[cur] = 1
        for cid in range(26):
            if cid != cur:
                last[cid] += 1
                sat_cur -= last[cid] * c[cid]

    # print(sat_cur)
    out_best = copy(out)
    sat_best = sat_cur
    num_of_try = 3000
    for i in range(1, num_of_try + 1):
        te = 0
        change_num = floor((num_of_try - i) / 500)
        out_temp = copy(out)
        for j in range(change_num):
            c_day = int(random.triangular(0, 365 - 0.01, 50))
            c_cid = random.randint(0, 25)
            out_temp[c_day] = c_cid

        last = [1] * 26
        sat_temp = 0
        for day in range(d):
            cur = out_temp[day]
            sat_temp += s[day][cur]
            last[cur] = 1
            for cid in range(26):
                if cid != cur:
                    last[cid] += 1
                    sat_temp -= last[cid] * c[cid]
        # print(change_day, change_cid, sat_temp)
        # print(sat_temp)
        if sat_temp > sat_cur:
            out_best = out_temp
            sat_cur = sat_temp

    for x in out_best:
        print(x + 1)

    #write_output(out_best)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81556
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
        final Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final List<Integer> list = new ArrayList<>();
        int count = 0;

    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }

    for(int i = 0; i < n - 1 ; i++){
        if(list.get(i) < list.get(i+1)){
            list.set(i+1, list.get(i+1)-1);
        }
    }

    for(int i = 0; i < n - 1 ; i++){
        if(list.get(i) > list.get(i+1)){
            count++;
        }
    }

    if(count == 0){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }



    
  

    


    


    

    
    
    



    





}
}

Measured memory_bytes: 59788
#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////







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

ll a[n+1];
rep(i, n){
	a[i]=0;
}
rep(i,k){
ll u;
cin>>u;
for(int j=1;j<=u;j++){
	ll s;
	cin>>s;
	a[s]++;
}

}
ll cnt=0;

rep(i, n){
	if(a[i]==0)cnt++;
}

cout<<cnt<<endl;


}






Measured memory_bytes: 3640
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int N = sc.nextInt();
		int[] W = new int[N];
		int sum = 0;
		for(int i = 0; i < N; i++) {
			W[i] = sc.nextInt();
			sum += W[i];
		}
		int min = Integer.MAX_VALUE;
		for(int i = 1; i < N; i++) {
			int S1 = 0;
			for(int j = 0; j < i; j++) {
				S1 += W[j];
			}
			min = Math.min(min, Math.abs(S1 - (sum - S1)));
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;
using ll = long long ;
const int INF = 1001001001;

int main() {

ll n ;
cin >> n ;


cout << n+n*n+n*n*n << endl ;
    
        return 0; 
}

Measured memory_bytes: 3596
F =-> {gets.split.map &:to_i}
N,W = F[]
D = Hash.new 0
D[0] = 0
N.times {
	w,v = F[]
	D.keys.sort.reverse_each {|i| W >= j=i+w and D[j] < x=D[i]+v and D[j]=x}
}
p D.values.max

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

using namespace std;

const int N = 303, mod = 998244353;

int a[N][N];

int main() {
  int r, c;
  scanf("%d %d", &r, &c);
  for (int i = 0; i < r; ++i) {
    for (int j = 0; j < c; ++j)
      scanf("%d", a[i]+j);
  }
  int cnt = 0;
  for (int k = 0; k < c; ++k) {
    int idx = -1;
    for (int i = cnt; i < r; ++i) {
      if (a[i][k])
        idx = i;
    }
    if (idx == -1) continue;
    for (int i = 0; i < c; ++i)
      swap(a[cnt][i], a[idx][i]);
    for (int i = cnt+1; i < r; ++i) {
      if (a[i][k] == 0) continue;
      for (int j = 0; j < c; ++j) {
        a[i][j] ^= a[cnt][j];
      }
    }
    ++cnt;
  }
  long long ans = 1;
  for (int i = 0; i < cnt; ++i)
    ans = ans * 2 % mod;
  --ans;
  for (int i = 0; i < c-1 + r - cnt; ++i) {
    ans = ans * 2 % mod;
  }
  if (ans < 0)
    ans += mod;
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007


using namespace std;

int main(void){
    int E,Y,ans[5]={0,1867,1911,1925,1988};
    cin>>E>>Y;
    if(E==0){
        if(Y<1912)cout<<"M"<<Y-1867<<endl;
        else if(Y<1926)cout<<"T"<<Y-1911<<endl;
        else if(Y<1989)cout<<"S"<<Y-1925<<endl;
        else cout<<"H"<<Y-1988<<endl;
    }else{
        cout<<ans[E]+Y<<endl;
    }
}




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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}



int g3(int X, int K) {
  // cout << X << " " << K << endl;
  int res = 0;
  if (X < K) {
    res = 0;
  } else if (X % K == 0) {
    res = X / K;
  } else {
    int j = X/K + 1;
    res = g3(X - j * max(1, (X - (j-1)*K) / j), K);
  }
  return res;
}


int main2() {
  int N = nextInt();
  ll ans = 0;
  REP(i, N) {
    int A = nextInt();
    int K = nextInt();
    ans ^= g3(A, K);
  }
  cout << (ans ? "Takahashi":"Aoki") << endl;
  return 0;
}


int memo[100][100];
int memo2[100][100];

int g(int X, int K) {
  if (memo[X][K] != -1) { return memo[X][K]; }

  set<int> s;
  for (int i = 1; i <= X / K; i++) {
    int nxt = g(X - i, K);
    s.insert(nxt);
  }
  int res = 0;
  while (s.count(res) > 0) res++;
  return memo[X][K] = res;
}

int g2(int X, int K) {
  if (memo2[X][K] != -1) { return memo2[X][K]; }
  int res = 0;
  res = (X % K == 0 ? X / K : g2(X - X/K - 1, K));
  return memo2[X][K] = res;
}
int main() {
  // CLR(memo, -1);
  // CLR(memo2, -1);
  // for (int i = 0; i <= 30; i++) cout << g(i, 1) << " "; cout << endl;
  // for (int i = 0; i <= 30; i++) cout << g2(i, 1) << " "; cout << endl;
  
  // for (int i = 0; i <= 30; i++) cout << g(i, 2) << " "; cout << endl;
  // for (int i = 0; i <= 30; i++) cout << g2(i, 2) << " "; cout << endl;
  // for (int i = 0; i <= 30; i++) cout << g(i, 3) << " "; cout << endl;
  // for (int i = 0; i <= 30; i++) cout << g2(i, 3) << " "; cout << endl;

  // for (int i = 0; i < 100; i++) {
  //   for (int k = 1; k < 100; k++) {
  //     if (g(i, k) != g3(i, k)) {
  //       cout << i << " " << k << " " << g(i,k) << " " << g3(i,k) << endl;
  //     }
  //   }
  // }
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;

int main()
{
    int s,w ; cin >> s >> w;
    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second

/* STL */
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxi(v) distance(v.begin(),max_element(v.begin(),v.end()))
#define mxa(a) *max_element(a, a.size())
#define r(a)   reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n) i=1;i<=(n);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(something)  cerr<<#something<<" - "<<something<<"\n";

int main()
{

   Ezio
   ll t,m,n,x,a(0),b;
   string s;

   cin>>n;

   vector<ll>v(2*n);

   fr(i,2*n)cin>>v[i];

   sort(all(v));

   for (ll i= 0;i<2*n;i+=2){
       a+=v[i];
   }
   cout<<a<<endl;
   return 0;
}


Measured memory_bytes: 3544
#include <iostream>

using namespace std;

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


Measured memory_bytes: 764
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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


int main()
{
	int a, b; cin >> a >> b;

	if (1 > a || a > 9) {
		cout << -1;
		return 0;
	} else if (1 > b || b > 9) {
		cout << -1;
		return 0;
	}

	cout << (a * b);

	return 0;

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
#define db double long
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	int n = s.size();
	vector<int>dp(n + 1, 0);
	dp[n] = 1;
	string have;
	for (int i = n - 1; i >= 0; i--) {
		if (i <= n - 5) {
			have = s.substr(i, 5);
			if (have == "dream" || have == "erase")
				dp[i] = dp[i] | dp[i + 5];
		}
		if (i <= n - 6) {
			have = s.substr(i, 6);
			if (have == "eraser")
				dp[i] = dp[i] | dp[i + 6];

		}
		if (i <= n - 7) {
			have = s.substr(i, 7);
			if (have == "dreamer")
				dp[i] = dp[i] | dp[i + 7];
		}
	}
	if (dp[0] == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 3872
n = int(input())
s = input()
d1 = [0] * 10
d2 = [0] * 100
d3 = [0] * 1000
for i in s:
    seq = int(i)
    for j in range(100):
        if d2[j] == 1:
            d3[j * 10 + seq] = 1
    for k in range(10):
        if d1[k] == 1:
            d2[k * 10 + seq] = 1
    d1[seq] = 1
print(sum(d3))

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>

using namespace std;
int a[110];
int n,m,sum,m2;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    m2=m;
    sort(a,a+n);
    for(int i=n-1;i>=0;i--){
        if(a[i]>=(sum*1.0/(4*m2))) m--;
        if(m==0){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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; }

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
int main(){
    char b;
    cin >> b;
    switch (b) {
        case 'A': cout << 'T';
        break;
        case 'C': cout << 'G';
            break;
        case 'G': cout << 'C';
            break;
        case 'T': cout <<'A';
            break;
    }

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//pow(x,n)
//cout << fixed << setprecision(桁数);

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

    vector<int> btn(n+1);
    rep(i,n) cin >> btn.at(i+1);
    int newbtn;
    int oldbtn=1;
    bool flag=0;
    rep(i,n){
        newbtn=btn.at(oldbtn);
        if(newbtn==2){
            cout << i+1 << endl;
            return 0;
        }
        oldbtn=newbtn;
    }
    cout << -1 << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>  // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
#define PAI 3.14159265358979
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(14);
  int h,w;
  cin >> h >> w;
  string memo;
  int y,t;
  rep(i,0,h){
    rep(j,0,w){
      cin >> memo;
      if(memo=="snuke"){
        y=j;
        t=i;
      }
    }
  }
  char c='A'+y;
  cout << c << t+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>

/********
*   ?????¢??¢?´¢ Linear Search
*********/ 

/*
int linearSearch(int strS int strT, int n )
{
	int key;
	
	for(int i =0 ; i < n; i++){
		if(strS[i] == key){
			return i;
		}
	}
	return NOT_FOUND;
}
*/

int main(void)
{
	vector<int> strS;
    vector<int> strT;
	int n, q;
	
	cin >> n;	
	strS.resize(n);
	
	for(int i = 0; i<n; i++){
		cin >> strS[i];
	}
	
	cin >> q;
	strT.resize(q);
	for(int i = 0; i<n; i++){
		cin >> strT[i];
	}
	
	int count = 0 ;
	for(int j = 0; j<q ; j++){
		for(int i =0; i < n; i++){
			if(strT[j] == strS[i]){
				count++;
				break;
			}
		}
	}
	cout << count << endl;
	
    return 0;
}

Measured memory_bytes: 1232
import sys
from collections import Counter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
a.sort()
cnt = Counter(a)
elem = [True]*(a[-1]+1)

for i in a:
  for j in range(i*2,a[-1]+1,i):
    elem[j] = False
ans = 0
for v in a:
  if elem[v] == True and cnt[v] == 1:
    ans += 1
    
print(ans)

Measured memory_bytes: 120472
import math
N = int(input())

ans = [0 for _ in range(10050)]


for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            a = x**2+y**2+z**2+x*y+y*z+z*x
            if  a < 10050:
                ans[a] +=1

for i in range(N):
    print(ans[i+1])



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

int main(int argc, char** argv) {
  unsigned long long H;
  std::cin >> H;
  // 2^(N) <= H < 2^(N+1)
  int N {};
  for (unsigned long long i = 1;i < H;++i, ++N) {
    i <<= 1;
  }
  std::vector<unsigned long long> dp(1000000, 0); // random 100
  dp[0] = 1;
  for (auto i = 1;i <= N;++i) {
    dp[i] = 2*dp[i-1]+1;
  }
  std::cout << dp[N] << '\n';
}


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

vector<int> split(const string &str, char sep) {
  vector<int> v;
  stringstream ss(str);
  string buffer;
  while( getline(ss, buffer, sep) ) {
    v.push_back(stoi(buffer));
  }
  return v;
}

int main() {
  int W;
  int cnt = 0;
  while (cin >> W, W) {
    int N; cin >> N;
    cout << "Case " << ++cnt << ":" << endl;
    auto v = vector<int>(N);
    auto w = vector<int>(N);
    for (int i = 0; i < N; ++i) {
      string s; cin >> s;
      auto tmp = split(s, ',');
      v[i] = tmp[0];
      w[i] = tmp[1];
    }
    auto dp = vector<vector<int>>(N + 1, vector<int>(W + 1, -1));
    auto dp2 = vector<vector<int>>(N + 1, vector<int>(W + 1, 0));
    for (int j = 0; j < W + 1; ++j) dp[0][j] = 0;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < W + 1; ++j) {
        if (j < w[i]) {
          dp[i + 1][j] = dp[i][j];
          dp2[i + 1][j] = dp2[i][j];
        } else {
          if (dp[i][j] < dp[i][j - w[i]] + v[i]) {
            dp2[i + 1][j] = dp2[i][j - w[i]] + w[i];
          } else {
            dp2[i + 1][j] = dp2[i][j];
          }
          dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
        }
      }
    }
    int m = dp2[N][W];
    for (int j = W - 1; j >= 0; --j) {
      if (dp[N][j] < dp[N][W]) break;
      m = min(m, dp2[N][j]);
    }
    cout << dp[N][W] << endl;
    cout << m << endl;
  }
  return 0;
}



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

    ll n, k, a[200020], f[200020];

    ll check(ll x){
        ll cnt = 0;
        for(ll i = 0; i < n; i++){
            if(a[i]*f[i] <= x) continue;
            ll ki = floor(x*1.0/f[i]);
            //cout << " [ "<<a[i] << " , " << f[i] << " ] "<< (a[i] - ki) << " : " << i <<"    " ;
            cnt += (a[i] - ki);
        }
     //   cout << endl << x << "  " << cnt << endl;
        return (cnt <= k ? 1 : 0);
    }

    void solve() {
        cin >> n >> k;
        for(ll i = 0; i < n; i++) cin >> a[i];
        for(ll i = 0; i < n; i++) cin >> f[i];
        sort(a, a + n);
        sort(f, f + n, greater<ll>());
        ll lo = 0, hi = 1e18, m;
        while(lo <= hi){
                //cout << lo << " :: " << hi << endl;
            m = (lo + hi)/2;
            if(check(m)) hi = m-1;
            else lo = m+1;
        }
        cout << max(0ll, (check(hi) ? hi : lo)) << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    }


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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 UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int n;
	cin>>n;
	int cnt[200010],a[200010];
	rep(i,n){
		cin>>a[i];
		cnt[a[i]-1]++;
		a[i]--;
	}
	int ans=0;
	rep(i,n){
		if(cnt[i]>=2)ans+=cnt[i]*(cnt[i]-1)/2;
	}
	rep(i,n){
		if(cnt[a[i]]>=2)
		cout<<ans-((cnt[a[i]]*(cnt[a[i]]-1)/2-(cnt[a[i]]-1)*(cnt[a[i]]-2)/2))<<endl;
		else 
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 5376
N = int(input())
G = [[] for _ in range(N)]
que_f = [0]
que_s = [N-1]
dis_f = [-1]*N
dis_s = [-1]*N
for i in range(N-1):
  a, b = map(int,input().split())
  a -= 1
  b -= 1
  G[a].append(b)
  G[b].append(a)

visited_f = [False]*N
dis_f[0] = 0
while que_f:
  pos = que_f.pop(0)
  for next_pos in G[pos]:
    if visited_f[next_pos] == True:
      continue
    que_f.append(next_pos)
    visited_f[pos] = True
    dis_f[next_pos] = dis_f[pos] + 1

visited_s = [False]*N
dis_s[N-1] = 0
while que_s:
  pos = que_s.pop(0)
  for next_pos in G[pos]:
    if visited_s[next_pos] == True:
      continue
    que_s.append(next_pos)
    visited_s[pos] = True
    dis_s[next_pos] = dis_s[pos] + 1
    
f = 0
s = 0
for i in range(N):
  if dis_f[i] <= dis_s[i]:
    f += 1
  else:
    s += 1

if f >s:
  print('Fennec')
else:
  print('Snuke')

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

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

    vector<pair<int, bool>> data(N, make_pair(1, false));
    data.at(0).second = true;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        if (data.at(x - 1).second) {
            data.at(y - 1).second = true;
        }
        data.at(x - 1).first--;
        data.at(y - 1).first++;
        if (data.at(x - 1).first == 0) {
            data.at(x - 1).second = false;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (data.at(i).second) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define MOD 1000000007
#define EPS (1e-10)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	string s; cin >> s;
	bool C = false, f = false;
	for (char c : s) {
		if (c == 'C')C = true;
		if (c == 'F'&&C)f = true;
	}
	puts(C&&f ? "Yes" : "No");
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
	int w, h;
	char seat[10][20];
	map<string, int> mp;

	int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
	int dy[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
	
	while( cin >> h >> w, (h||w))
	{
		mp.clear();
		
		for( int j = 0; j < h; j++)
			for( int i = 0; i < w; i++)
			{
				cin >> seat[j][i];
			}
		
		
		for( int j = 0; j < h; j++)
			for( int i = 0; i < w; i++)
				for( int d = 0; d < 8 ; d++ )
				{ 
					string str = "";
					int x = i, y = j;
					
					do
					{
						str += seat[y][x];

						x = (x + w + dx[d]) % w;
						y = (y + h + dy[d]) % h;

						mp[str] += 1;

					}
					while( x != i || y != j );
					
				}
	
		string out = "";
		map<string, int>::iterator it; 

		for( it = mp.begin() ; it != mp.end(); it++ )
		{
			if( (*it).second >= 2 )
				if( (*it).first.length() > out.length() )
				{
					out = (*it).first;
				}
				else if( (*it).first.length() == out.length() )
				{
					if( out > (*it).first )
						out = (*it).first;
				}
		}

		if( out.length() >= 2 )
			cout << out << endl;
		else
			cout << '0' << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int w,h,i,j;
    while(1)
    {
        scanf("%d%d",&h,&w);
        if(h==0&&w==0)
        {
            break;
        }
        for(i=0;i<h;i++)
        {
            if(i%2==0)
            {
               for(j=0;j<w;j++)
            {
                if(j%2==0)
                {
                    printf("#");
                }
                else
                {
                    printf(".");
                }
            }
            printf("\n");
            }
            else
            {
                for(j=0;j<w;j++)
            {
                if(j%2==0)
                {
                    printf(".");
                }
                else
                {
                    printf("#");
                }
            }
            printf("\n");
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
#include<cstdio>
#include<algorithm>
using namespace std;

#define INF (1<<28)
#define REP(i,n) for(int i=0;i<n;i++)

int a[110][110],wf[30][110][110],p[30],q[100],r[100],sum[100];
int n,m,c,s,g,x,y,d,id,tmp;

int main(){
  while(scanf("%d%d%d%d%d",&n,&m,&c,&s,&g),n){
    REP(i,n)REP(j,n){
      a[i][j] = INF;
      REP(k,c)wf[k][i][j] = INF;
    }
    
    REP(i,m){
      scanf("%d%d%d%d",&x,&y,&d,&id);
      x--; y--; id--;
      wf[id][x][y] = min(wf[id][x][y],d);
      wf[id][y][x] = min(wf[id][y][x],d);
    }
    
    REP(l,c){
      scanf("%d",&p[l]);
      REP(k,n)REP(i,n)for(int j=i;j<n;j++){
	wf[l][i][j] = wf[l][j][i] = min(wf[l][i][j],wf[l][i][k] + wf[l][k][j]);
      }
    }

    REP(k,c){
      q[0] = 0;
      REP(i,p[k]-1)scanf("%d",&q[i+1]);
      q[p[k]] = INF;
      REP(i,p[k])scanf("%d",&r[i]);
      sum[0] = 0;
      REP(i,p[k])sum[i+1] = sum[i] + r[i]*(q[i+1]-q[i]);

      REP(i,n)for(int j=i;j<n;j++){
	if(wf[k][i][j] < INF){
	  tmp = upper_bound(q,q+p[k]+1,wf[k][i][j])-q-1;
	  a[i][j] = a[j][i] = min(a[i][j],sum[tmp] + r[tmp]*(wf[k][i][j]-q[tmp]));
	}
      }
    }

    REP(k,n)REP(i,n)for(int j=i;j<n;j++)a[i][j] = a[j][i] = min(a[i][j],a[i][k] + a[k][j]);

    if(a[s-1][g-1]>=INF)printf("-1\n");
    else printf("%d\n",a[s-1][g-1]);
  }
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

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

    ll sum = 0;
    for (ll i = 1; i * i <= N; ++i)
    {
        {
            ll a = N / i;
            ll b = N % i;
            if (a == b)
                sum += i;
        }
        {
            ll a = (N - i) / i;
            if (a != 0)
            {
                if (N / a == N % a)
                    sum += a;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

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


return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
using ll = long long;
using ld = long double;
long double pi = 2*acos(0.0);

void solve() {
    ll a, b, h, m;
    cin >> a >> b >> h >> m;
    h %= 12; m %= 60;
    ld am = m * 6, ah = h * 30 + (ld)m / 2, diff = am - ah;
    if(diff < 0) diff = -diff;
    if(diff > 180) diff = 360 - diff;
    cout << setprecision(15) << sqrtl(a * a + b * b - (2 * a * b * cos((pi * diff) / 180)));
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    ll n, x, tmp, ans = 0; sc(n), sc(x);
    vector<ll> a(n);
    rep(i, 0, n) sc(a[i]);
    rep(i, 1, n){
        tmp = a[i]+a[i-1];
        if (tmp > x) a[i] -= tmp-x, ans += tmp-x;
        a[i] = max(a[i], 0ll);
    }
    cout << ans << endl;
    return 0;
}

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

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

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


int main()
{
    /*A
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    if(s[0]==s[1]&&s[2]==s[3])
    {
        if(s[1]==s[2])
        {
            cout<<"No"<<endl;
        }
        else
        {
            cout<<"Yes"<<endl;
        }
        return 0;
    }
    else
    {
        cout<<"No"<<endl;
    }
    */
    /*B
    int n;
    cin>>n;
    vector <int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    } 
    int count=0;
    for(int i=1;i<n-1;i++)
    {
        if(a[i]>a[i-1] && a[i]<a[i+1])
        {
            count++;
        }
        else if(a[i]>a[i+1]&&a[i]<a[i-1])
        {
            count++;
        }
    }
    cout<<count<<endl;
    */

    int n;
    cin>>n;
    vector <int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());

    
    int count = a[n/2]-a[n/2-1];
    
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 640
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	graph := make([][]int, N+1)
	for i := 0; i < N+M-1; i++ {
		a, b := ReadInt(), ReadInt()
		graph[a] = append(graph[a], b)
	}
	used := make(map[int]bool)
	sortedNode := []int{}
	for i := 1; i <= N; i++ {
		dfs(graph, used, i, &sortedNode)
	}
	ans := make([]int, N)
	for i := 0; i < N; i++ {
		v := sortedNode[i]
		for _, u := range graph[v] {
			if ans[u-1] == 0 {
				ans[u-1] = v
			}
		}
	}
	for _, a := range ans {
		fmt.Println(a)
	}
}

func dfs(graph [][]int, used map[int]bool, v int, ans *[]int) {
	if used[v] {
		return
	}
	used[v] = true
	for _, uu := range graph[v] {
		dfs(graph, used, uu, ans)
	}
	*ans = append(*ans, v)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 25296
#include <bits/stdc++.h>
using namespace std;
int main(){
  int W,H,N; cin>>W>>H>>N;
  int A=0,B=W,C=0,D=H;
  for(int i=0;i<N;i++){
    int a,b,c; cin>>a>>b>>c;
    if(c==1)A=max(A,a);
    else if(c==2)B=min(B,a);
    else if(c==3)C=max(C,b);
    else D=min(D,b);
  }
  cout<<max(B-A,0)*max(D-C,0)<<endl;
}

Measured memory_bytes: 3636