akhauriyash/Code-Regression huggingface dataset:
N=gets.to_i
s1=gets.chomp
s2=gets.chomp
MOD=10**9+7

i = 0
arr = []
while i < N
    if s1[i] == s2[i]
        arr << 1
        i += 1
    else
        arr << 2
        i += 2
    end
end

ret = (arr[0] == 1 ? 3 : 6)
arr.each_cons(2) do |ab|
    case ab
    in [1,1]
        ret *= 2
    in [1,2]
        ret *= 2
    in [2,1]
        ret *= 1
    in [2,2]
        ret *= 3
    end
end

p ret%MOD

Measured memory_bytes: 14352
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define maxv 58
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
vector<int> gr[maxv],rgr[maxv];
vector<int> vs;
bool sumi[maxv];
int cmp[maxv];
void dfs(int v){
	sumi[v]=true;
	rep(i,gr[v].size()){
		if(!sumi[gr[v][i]]) dfs(gr[v][i]);
	}
	vs.pb(v);
}
void rdfs(int v,int k){
	sumi[v]=true;cmp[v]=k;
	rep(i,rgr[v].size()){
		if(!sumi[rgr[v][i]]) rdfs(rgr[v][i],k);
	}
}
int scc(int v)
{
	memset(sumi,false,sizeof(sumi));
	vs.clear();
	rep(i,v){
		if(!sumi[i]) dfs(i);
	}
	memset(sumi,false,sizeof(sumi));
	int k=0;
	for(int i=vs.size()-1;i>=0;i--){
		if(!sumi[vs[i]]) rdfs(vs[i],k++);
	}
	return k;
}
void aedge(int v,int w){
	gr[v].pb(w);rgr[w].pb(v);
}

int st=-1,ko;
vector<int> ed[58][2];
void rec(int v,int u,int d){
	//cout<<v<<u<<d<<endl;
	if(d==0 && v==st) return;
	if(d<0){
		ko++;
		int it=0,i2=0,n=ed[v][0].size()-1,m=ed[v][1].size()-1;
		while(it<n || i2<m){
			int x=ed[v][0][it],y=ed[v][1][i2];
			assert(x!=58 || y!=58);
			if(x==u){
				it++;
			}
			else if(y==u){
				i2++;
			}
			else if(x==st){
				//rec(st,v,0);
				it++;
			}
			else if(x<y){
				rec(x,v,0);it++;
			}
			else if(x>y){
				rec(y,v,1);i2++;
			}
			else{
				assert(x==y);
				rec(x,v,-1);it++;i2++;
			}
		}
	}
	else{
		rep(i,ed[v][d].size()-1){
			int w=ed[v][d][i];
			if(u==w) continue;
			if(d==0) aedge(w,v);else aedge(v,w);
			rec(w,v,d);
		}
	}
}
int cal2(int i,int n){
	//cout<<i<<' '<<st<<endl;
	rep(j,58) gr[j].clear(),rgr[j].clear();
	ko=0;
	rec(i,-1,-1);
	if(scc(n)==n) return n-ko;return 58;
}
int cal(){
	int n,a,b;
	rep(i,55) rep(j,2) ed[i][j].clear();
	cin>>n;
	rep(j,2) rep(i,n-1){
		cin>>a>>b;a--;b--;
		ed[a][j].pb(b);ed[b][j].pb(a);
	}
	int ret=58;st=-1;
	rep(i,n){
		sort(All(ed[i][0]));sort(All(ed[i][1]));
		ed[i][0].pb(58);
		ed[i][1].pb(58);
	}
	rep(i,n){
		ret=min(ret,cal2(i,n));
	}
	int nowret=ret;
	//cout<<"a"<<endl;
	rep(i,n){
		if(ed[i][0].size()>2) continue;
		int ori=ed[i][0][0];
		st=i;
		rep(j,n){
			if(j==i || j==ori) continue;
			ed[i][0][0]=j;
			ret=min(ret,cal2(i,n)+1);
		}
		ed[i][0][0]=ori;
	}
	assert(nowret!=n);
	assert(nowret<n || ret>=n);
	if(ret>50) return -1;
	return ret;
}
int main()
{
	int t;
	cin>>t;
	rep(i,t) cout<<cal()<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            // input //
            decimal A;
            decimal B;
            args = Console.ReadLine().Split();

            A = decimal.Parse(args[0]);
            B = decimal.Parse(args[1]);

            Console.Write((ulong)(A * B));
            Console.Read();
        }
    }
}


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

using namespace std;

int n;
vector<int> v(100009);
vector<int> w(100009);

int main(){
    int a,b;
    cin >> n;
    for(int i=0;i<100009;i++) v[i] = w[i] = 0;
    for(int i=0;i<n/2;i++){
        cin >> a >> b;
        v[a]++,w[b]++;
    }
    int vv = max_element(v.begin(), v.end()) - v.begin();
    int ww = max_element(w.begin(), w.end()) - w.begin();
    if(vv != ww){
        cout << n-v[vv]-w[ww] << endl;
        return 0;
    }
    int v_max = v[vv];
    int w_max = w[ww];
    v[vv] = w[ww] = 0;
    vv = max_element(v.begin(), v.end()) - v.begin();
    ww = max_element(w.begin(), w.end()) - w.begin();
    cout << n-max(v[vv]+w_max,w[ww]+v_max) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n,x;
  cin>>n>>x;
  ll a[n+1]={};
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }

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


Measured memory_bytes: 1024
#include <stdio.h>
#define M 1000000

typedef struct{
  int pa,le,ri;
}data;
void pre(int);
void ino(int);
void pos(int);

data Da[M];
int num;

int main(){
  int i;
  int id,le,ri,ro;

  scanf("%d",&num);
  
  for(i=0;i<num;i++) Da[i].pa=Da[i].le=Da[i].le=-1;
    
  for(i=0;i<num;i++){
    scanf("%d%d%d",&id,&le,&ri);
    Da[id].le=le;
    Da[id].ri=ri;
    if(le>=0)Da[le].pa=id;
    if(ri>=0)Da[ri].pa=id;
  }
  for(i=0;i<num;i++){
    if(Da[i].pa==-1){
      ro=i;
      break;
    }
  }

  printf("Preorder\n");
  pre(ro);
  printf("\n");
  printf("Inorder\n");
  ino(ro);
  printf("\n");
  printf("Postorder\n");
  pos(ro);
  printf("\n");
  
  return 0;
}

void pre(int ro){
  if(ro==-1)return;
  printf(" %d",ro);
  pre(Da[ro].le);
  pre(Da[ro].ri);
}

void ino(int ro){
  if(ro==-1) return ;
  ino(Da[ro].le);
  printf(" %d",ro);
  ino(Da[ro].ri);
}

void pos(int ro){
  if(ro==-1)return ;
  pos(Da[ro].le);
  pos(Da[ro].ri);
  printf(" %d",ro);
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int MAXN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    int arr[n], odd = 0, ans = 0;
    for(int i = 0; i < n; ++i){
        cin >> arr[i];
        if(arr[i] & 1) odd++;
        else{
            int temp = arr[i];
            while(temp % 2 == 0){
                ans++;
                temp /= 2;
            }
        }
    }
    if(odd == n) cout << 0;
    else cout << ans ;
}

Measured memory_bytes: 3720
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli dp[MaxN][3];										//dp[día][A]=max(dp[día-1][C]+A[soy],dp[día-1][C]+A[soy];
	lli A[MaxN],B[MaxN],C[MaxN];
	void solve(){
		lli N,K,i,j,p,q;
		cin>>N;
		for(i=1;i<=N;i++){
			cin>>A[i]>>B[i]>>C[i];
		}
		for(i=1;i<=N;i++){
			dp[i][1]=max(dp[i-1][2],dp[i-1][3])+A[i];
			dp[i][2]=max(dp[i-1][1],dp[i-1][3])+B[i];
			dp[i][3]=max(dp[i-1][1],dp[i-1][2])+C[i];
		}
		lli res=dp[N][1];
		res=max(res,max(dp[N][2],dp[N][3]));
		cout<<res<<"\n";
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,j,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
	
}


Measured memory_bytes: 8288
#include <bits/stdc++.h>
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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main() {
  int n, k;
  cin >> n >> k;
  vector<bool>b(n,true);
  vector<int>cost(n);
  vector<ll>dp(n, inf);
  rep(i, 0, n){
      cin >> cost[i];
  }
  dp[0]=0;
  rep(i, 1, n){
      rep(j, 1, k+1){
          if(i-j<0)continue;
          chmin(dp[i], dp[i-j]+abs(cost[i]-cost[i-j]));
          //cout << dp[i] << " " << abs(cost[i]-cost[i-j]) << endl;
      }
  }
  //rep(i, 0, n)cout << dp[i] << endl;
  cout << dp[n-1] << endl;
}

Measured memory_bytes: 1408
//#include "stdafx.h"
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <iterator>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
ll N;
pair<ll, ll> P[500000];
int main() {
    cin >> N;
    FOR(i, 0, N) {
        cin >> P[i].FI >> P[i].SE;
    }
    sort(P, P + N);
    ll ans = P[0].SE;
    ll sum = P[0].SE;
    ll now = P[0].FI;
    FOR(i, 1, N) {
        ll num = sum + P[i].SE - (P[i].FI - now);
        ans = max(ans, num);
        ans = max(ans, P[i].SE);
        if (P[i].SE > num) {
            now = P[i].FI;
            sum = P[i].SE;
        }
        else {
            sum += P[i].SE;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 10904
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
using namespace std;

int main(){
	int a,b,c,d;
	cin >> a >> b >> c;
	d = min(a + b,a + c);
	d = min(d,b + c);
	cout << d;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int counter = 0;
        for (int i = 0; i < S.length(); i++) {
            if (S.charAt(i) != T.charAt(i)) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
}

Measured memory_bytes: 41052
#include <cstdio>
#include <cctype>
#include <utility>
#include <unordered_map>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	unordered_map<int, bool> m;
	auto o = [&m](int i) {
		bool r = m[i];
		m.erase(i);
		return r;
	};
	for (int a, b;;)
		if (scan(a, b))
			if (a)
				m[a] ^= 1, m[b] ^= 1;
			else {
				outl(o(1) && o(2)
					 && none_of(m.begin(), m.end(), [](auto x) {return x.second;})
					 ? "OK" : "NG");
				m.clear();
			}
		else
			break;
}


Measured memory_bytes: 2528
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS()ios_base::sync_with_stdio(0);cin.tie(0)

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

template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************


signed main()
{
	//IOS();
	int N;
	cin>>N;
	int sum = 0,ma = INF,t,flag = 1;
	rep(i,0,N){
		int a,b;
		cin>>a>>b;
		if(a>b)chmin(ma,b);
		if(a!=b)flag = 0;
		sum+=a;
	}
	if(flag){
		cout<<0<<endl;
		return 0;
	}
	cout<<sum-ma<<endl;
}


Measured memory_bytes: 256
/*
https://abc053.contest.atcoder.jp/tasks/arc068_a
*/

// 桁が足りてない場合だった。
// 代入する場合、すべての変数の桁をそろえておこう。

#include <stdio.h>

int main() {
  long long x;
  scanf("%lld" , &x);

  long long num = 0;
  long long count = 0;
  long long i;

  count += 2*(x / 11);
  if((x%11) != 0){
    if((x%11 > 6)) count += 2;
    else if((x%11 <= 6)) count += 1;

  }

  // count++;
  // count = 40 /11;
  printf("%lld", count);
  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	// http://abc092.contest.atcoder.jp/tasks/abc092_b
	public class Abc092_b
	{
#if !Development
		public static void Main(string[] args)
		{
			Abc092_b.Solve(args);
		}
#endif

		public static void Solve(string[] args)
		{
			var playerNum = ReadLineInt();
			var temp = ReadLineInts();
			var day = temp[0];
			var 残ったChocolateの数 = temp[1];

			var Chocolateを食べる間隔 = Enumerable.Range(0, playerNum).Select(_ => ReadLineInt()).ToList();

			var 食べたChocolateの数 = Chocolateを食べる間隔.Select(間隔 =>
			{
				return (int)Math.Ceiling(day / (float)間隔);
			}).Sum();

			var 最初にあったChocolateの数 = 食べたChocolateの数 + 残ったChocolateの数;

			Console.WriteLine(最初にあったChocolateの数);
		}

		public static List<string> ReadLineString() { return Console.ReadLine().Split(' ').ToList(); }
		public static List<int> ReadLineInts() { return Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToList(); }
		public static int ReadLineInt() { return Console.ReadLine().Split(' ').Select(str => int.Parse(str)).First(); }
	}
}



Measured memory_bytes: 13396
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int num = Integer.parseInt(a + b);
		String result = "No";
		for(int i = 1; i*i <= num; i++) {
			if(i * i == num) {
				result = "Yes";
				break;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 26944
#include <iostream>

using namespace std;

int main(void) {
    char b;
    cin>>b;
    if(b=='A'){
        cout<<'T'<<endl;
    }else if(b=='C'){
        cout<<'G'<<endl;
    }else if(b=='G'){
        cout<<'C'<<endl;
    }else if(b=='T'){
        cout<<'A'<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((x, y, i))
    Y.append((y, x, i))
X.sort()
Y.sort()
Edges = list([] for _ in range(N))
for k in range(N-1):
    xk, yk, ik = X[k]
    xk_, yk_, ik_ = X[k+1]
    Edges[ik].append((ik_, min(abs(xk-xk_), abs(yk-yk_))))
    Edges[ik_].append((ik, min(abs(xk-xk_), abs(yk-yk_))))
    yk, xk, ik = Y[k]
    yk_, xk_, ik_ = Y[k+1]
    Edges[ik].append((ik_, min(abs(xk-xk_), abs(yk-yk_))))
    Edges[ik_].append((ik, min(abs(xk-xk_), abs(yk-yk_))))
    
import heapq
def prim(Edges, V):
    mst = []
    included = [False]*V
    heap = []
    included[0] = True
    for v, d in Edges[0]:
        heapq.heappush(heap, (d, 0, v)) #(dist, pre_v, cur_v)
    while heap:
        d, pre_v, cur_v = heapq.heappop(heap)
        if included[cur_v]:
            continue
        included[cur_v] = True
        mst.append((pre_v, cur_v, d))
        for next_v, dist in Edges[cur_v]:
            if not included[next_v]:
                heapq.heappush(heap, (dist, cur_v, next_v))
    return mst

mst = prim(Edges, N)
ans = 0
for v1, v2, d in mst:
    ans += d
    
print(ans)

Measured memory_bytes: 158368
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int R,G,B,N;
  cin>>R>>G>>B>>N;
  int ANS = 0;
  for (int r = 0; r < 3001; r++)
  {
    for (int g = 0; g < 3001; g++)
    {
      int b = N - r*R - g*G;

      if(b%B == 0&& b >= 0)ANS++;
    }
    
  }
  cout<<ANS<<endl;
  

  return;
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795


typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector< pii >   vpii;

#define MAXN 100500

int n;
int f[MAXN];
int h[MAXN];


int main() {
    scanf("%i", &n);
    for(int i = 0; i < n; ++i) scanf("%i", &h[i]);
    fill(f + 1, f + n, 2000000000);


    for(int i = 0; i < n; ++i) {
        f[i + 1] = min(f[i + 1], f[i] + abs(h[i] - h[i + 1]));
        f[i + 2] = min(f[i + 2], f[i] + abs(h[i] - h[i + 2]));
    }

    printf("%i\n", f[n - 1]);

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main()
{
    int n;
    cin >> n;
    bool ok = false;
    for (int i = 0; i <= n / 4; i++)
    {
        for (int j = 0; j <= n / 7; j++)
        {
            if (4 * i + 7 * j == n)
            {
                ok = true;
            }
        }
    }
    if (ok)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long a[100000], b[100000], cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = n - 1; i > -1; i--) {
    cnt += (b[i] - (a[i] + cnt) % b[i]) % b[i];
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <iostream>
#define FOR(k,m,n) for(int(k)=(m);(k)<(n);(k)++)
#define REP(k,n) FOR((k),0,(n))
#define ALL(a) begin(a),end(a)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef unsigned long long ull;
typedef unsigned long ul;
typedef unsigned int  ui;
const int INF=numeric_limits<int>::infinity();
const int MOD=1000000007;
const double EPS=1e-9;

int main(int argc,char**argv)
{
int A, B, K;

cin >> A >> B >> K;

REP(i, K){

	if(i%2){
		if(B%2)B--;
		B/=2;A += B;
	}else{
		if(A%2)A--;
		A/=2;B += A;
	}

}


cout << A << " " << B << "\n";

}





Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int h, w, k;
vector<string> a;
vector<vector<Int>> v;
Int dx[4] = {0, 0, 1, -1};
Int dy[4] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> h >> w >> k;
	a.resize(h);
	for(auto &i:a) cin >> i;
	v.resize(h, vector<Int>(w, -1));
	using P = pair<Int, Int>;
	queue<P> q;
	for(Int i=0; i<h; ++i)
		for(Int j=0; j<w; ++j)
			if(a[i][j] == 'S'){
				v[i][j] = k;
				q.push(P(i, j));
			}
	while(!q.empty()){
		P p = q.front();
		q.pop();
		Int x = p.first;
		Int y = p.second;
		for(Int i=0; i<4; ++i){
			Int nx = x + dx[i];
			Int ny = y + dy[i];
			if(0 <= nx && nx < h && 0 <= ny && ny < w && a[nx][ny] == '.' && v[x][y] - 1 > v[nx][ny]){
				v[nx][ny] = v[x][y] - 1;
				if(v[nx][ny] > 0) q.push(P(nx, ny));
			}
		}
	}
	Int ans = 1e9;
	for(Int i=0; i<h; ++i)
		for(Int j=0; j<w; ++j)
			if(v[i][j] != -1){
				if(i == 0 || j == 0 || i == h-1 || j == w-1) ans = 1;
				else ans = min({ans, 1+(i+k-1)/k, 1+(j+k-1)/k, 1+(h-1-i+k-1)/k, 1+(w-1-j+k-1)/k});
			}
	cout << ans << "\n";
//	for(Int i=0; i<h; ++i)
//		for(Int j=0; j<w; ++j)
//			cout << v[i][j] << (" \n"[j+1==w]);
}

Measured memory_bytes: 6016
{-# LANGUAGE BangPatterns #-}

import qualified Data.Vector.Unboxed as U
-- import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
-- import Control.Monad
import Control.Arrow
--import Data.Foldable
--import Data.Char
import qualified Data.IntMap.Strict as IM
--import qualified Data.IntSet as IS
-- import Data.Sequence as Sq

-- r :: Int -> IO (U.Vector Int)
-- r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine




main = do
    [a,b,n] <- r'
    print $ if b-1 < n then f a b (b-1) else f a b n




f :: Int -> Int -> Int -> Int
f a b x = floor (fromIntegral (a*x)/fromIntegral b) - a*(floor(fromIntegral x/fromIntegral b))




Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,time,total=0;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>time;
    total+=time;
  }
  if(n<total)
    cout<<-1<<endl;
  else
    cout<<n-total<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int dislike[11] = {0};
int solve(int test)
{
    int tt;
    while (test) {
        if (dislike[test % 10]) {
            return false;
        }
        test /= 10;
    }
    return true;
}
int main()
{
    int N, K;
    cin >> N  >> K;
    for (int i = 1; i <= K; i++) {
        int t;
        cin >> t;
        dislike[t]++;
    }
    for (int i = N; ;i++) {
        if (solve(i)) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
def selectionSort(A, N):
    count = 0
    for i in range(N-1):
        minj = i
        for j in range(i + 1, N):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        if A[i] != A[minj]:
            count += 1
    return count


n = int(input())
a = [int(i) for i in input().split()]
count = selectionSort(a, n)
print(" ".join(map(str, a)))
print(count)



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

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

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





int main(void){
int n;
scanf("%d",&n);
int p[n];
int i,j;
int ans=0;
long long int min=1000000;


for(i=0;i<n;i++){
  scanf("%d",&p[i]);
}

for(i=0;i<n;i++){
  if(min>p[i]){
    ans++;
  }

  if(min>p[i]){
    min=p[i];
  }
}
printf("%d",ans);


  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int X, Y;
  cin>>X>>Y;
  int ans = X +	Y/2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

bool kansu(const pair<int, int>a, const pair<int, int>b)
{
	return a.first*a.second < b.first*b.second;
}

int main()
{
	int n, w, d;
	while (cin >> n >> w >> d, w)
	{
		vector<pair<int, int> >data;
		data.push_back(pair < int, int > {w, d});
		int a, b;
		for (size_t i = 0; i < n; i++)
		{
			cin >> a >> b;
			a--;
			b %= (data[a].first + data[a].second);
			if (b>data[a].first)
			{
				b -= data[a].first;
				if (b < data[a].second - b)
				{
					data.push_back(pair < int, int > {data[a].first, b});
					data.push_back(pair < int, int > {data[a].first, data[a].second - b});
				} else
				{
					data.push_back(pair < int, int > {data[a].first, data[a].second - b});
					data.push_back(pair < int, int > {data[a].first, b});
				}
			} else
			{
				if (b < data[a].first-b)
				{
					data.push_back(pair < int, int > {b, data[a].second});
					data.push_back(pair < int, int > {data[a].first - b, data[a].second});
				} else
				{
					data.push_back(pair < int, int > {data[a].first - b, data[a].second});
					data.push_back(pair < int, int > {b, data[a].second});
				}
			}
			data.erase(data.begin() + a);
		}
		sort(data.begin(), data.end(), [](const pair<int, int>a, const pair<int, int>b)->bool {return a.first*a.second < b.first*b.second; });
		auto ite = data.begin();
		for (; ite != data.end() - 1; ite++)
		{
			cout << ((*ite).first)*((*ite).second) << " ";
		}
		cout << ((*ite).first)*((*ite).second) << endl;
	}
}

Measured memory_bytes: 1200
n = int(input())
la, lb = [], []
for _ in range(n):
    a, b = map(int, input().split())
    la.append(a)
    lb.append(b)

la.sort()
lb.sort(reverse=True)

if n % 2 == 1:
    i = n // 2 + 1
    md = la[i - 1]
    mu = lb[i - 1]
    answer = mu - md + 1
else:
    i = n // 2
    md2 = la[i - 1] + la[i]
    mu2 = lb[i - 1] + lb[i]
    answer = (mu2 - md2) + 1

print(answer)


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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> p(N), excluded_p;
  for (int i = 0; i < N; i++) cin >> p.at(i);
  sort(p.begin(), p.end());
  for (int i = 0; i <= 101; i++) {
    if (!binary_search(p.begin(), p.end(), i)) excluded_p.push_back(i);
  }
  // for (auto x : excluded_p) cout << "E" << x << endl;

  int minimum = 0xff;
  int chosen = 0xff;
  for (auto x : excluded_p) {
    int y = abs(X - x);
    if (minimum > y) minimum = y, chosen = x;
  }

  cout << chosen << endl;

  // bitset<100> hai;
  // for(int j=0;j<N;j++){
  //   hai.set(hairetu.at(j)-1,1);
  // }
  // 
  // int kekka = 1000;
  // int count1=0;
  // int count2=0;
  // 
  // for(int k=X;k<101;k++){
  //   if(hai.test(k-1) == 0){
  //     kekka = k;
  //     break;
  //   }
  //   count1++;
  // }
  // 
  // for(int l=X;l>0;l--){
  //   if(hai.test(l-1) == 0){
  //     if(count1<count2){
  //       break;
  //     }
  //     else if(count1>=count2){
  //       kekka = l;
  //       break;
  //     }
  //   }
  //   count2++;
  // }
  // 
  // if(kekka==1000){
  //   if(X>=51){
  //     cout << 101 <<endl;
  //   }
  //   else{
  //     cout << 0 <<endl;
  //   }
  // }
  // else{
  //   cout << kekka <<endl;
  // }
  // 
}



Measured memory_bytes: 3600
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int w, h;
constexpr int dx[] = {1, -1, 0, 0};
constexpr int dy[] = {0, 0, 1, -1};

inline bool out(int x, int y) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

int count_panel(const vector<vector<int>> &field) {
	int res = 0;

	queue<pair<int, int>> que;
	que.push({0, 0});

	vector<vector<bool>> visited(h, vector<bool>(w, false));
	visited[0][0] = true;

	while(!que.empty()) {
		const int x = que.front().first;
		const int y = que.front().second;
		que.pop();

		++res;

		for(int d = 0; d < 4; ++d) {
			const int nx = x + dx[d];
			const int ny = y + dy[d];

			if(out(nx, ny)) continue;
			if(field[y][x] != field[ny][nx]) continue;
			if(visited[ny][nx]) continue;

			que.push({nx, ny});
			visited[ny][nx] = true;
		}
	}

	return res;
}

void change(vector<vector<int>> &field, int to, int x = 0, int y = 0) {
	const int from = field[y][x];
	field[y][x] = to;

	for(int d = 0; d < 4; ++d) {
		const int nx = x + dx[d];
		const int ny = y + dy[d];

		if(out(nx, ny) || field[ny][nx] != from) continue;
		change(field, to, nx, ny);
	}
}

bool dfs(int rest, int cnt, const vector<vector<int>> &field) {
	if(rest == 0) return false;

	for(int color = 0; color < 3; ++color) {
		if(color == field[0][0]) continue;
		auto next_field = field;
		change(next_field, color);
		const int next_cnt = count_panel(next_field);
		if(next_cnt == w * h) return true;
		if(next_cnt == cnt) continue;
		if(dfs(rest - 1, next_cnt, next_field)) return true;
	}
	return false;
}

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

	int convert[256];
	convert['R'] = 0;
	convert['G'] = 1;
	convert['B'] = 2;

	while(cin >> w >> h && w) {
		vector<vector<int>> field(h, vector<int>(w));

		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				char c;
				cin >> c;
				field[i][j] = convert[c];
			}
		}

		const int cnt = count_panel(field);
		if(cnt == h * w) {
			cout << 0 << endl;
			continue;
		}

		for(int ans = 1;; ++ans) {
			if(dfs(ans, cnt, field)) {
				cout << ans << endl;
				break;
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1236
object Main extends App {
    val N = readInt
    def calc(i:Int):String =  {
        if(i == 0 ) {
            "No"
        } else if((N / i < 10 && N % i == 0)) {
            "Yes"
        } else {
            calc(i - 1)
        }
    }
    
    println(calc(9))        

}

Measured memory_bytes: 25536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin >> str;
    int n = str.size();
    for(int i = 0; i < n; i++)
    {
        if(str[i] == '?')
        {
            str[i] = 'D';
        }
    }
    cout << str << endl;
    return 0;
}


Measured memory_bytes: 3728
#include "stdio.h"

#include "string.h"

int main() {

    int n,m,i,j;

    char a[100],b[100];

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

    for(i=0;i<n;i++)

    a[i]=48+m;

    a[i]=0;

    for(i=0;i<m;i++)

    b[i]=48+n;

    b[i]=0;

  if (strcmp(a,b)>0)printf("%s",b);

else printf("%s",a);

    return 0;

}

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

#define REP(i, from, to) for(int i=(from); i<(int)(to); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N;

int main(void) {
    cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    vector<int> order(N);
    for(int i = 0; i < N; ++i) {
        order[i] = i + 1;
    }

    int pnum = -1;
    int qnum = -1;
    int c = 0;
    do {
        c++;
        bool pfound = true;
        bool qfound = true;
        for (int i = 0; i < N; ++i) {
            if (P[i] != order[i]) {
                pfound = false;
            }

            if (Q[i] != order[i]) {
                qfound = false;
            }
        }

        if (pfound) {
            pnum = c;
        }
        if (qfound) {
            qnum = c;
        }
    } while(next_permutation(ALLOF(order)));

    cout << (int)abs(pnum - qnum) << endl;
    
    return 0;
}

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

int main(void) {
	int p, q, r;
	std::cin >> p >> q >> r;

	int t_min = std::min(p+q, std::min(q+r, r+p));
	
	std::cout << t_min << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}
class llm{
public:
llm(ll value){this->value = (ll)value;}
ll value;
llm operator + (llm obj){return llm((this->value + (ll)(obj.value))%MOD);}
llm operator + (ll obj){return llm((this->value + obj)%MOD);}
llm operator - (llm obj){return llm(((this->value + MOD - (ll)(obj.value)))%MOD);}
llm operator - (ll obj){return llm(((this->value + MOD - obj))%MOD);}
llm operator * (llm obj){return llm((this->value * (ll)(obj.value))%MOD);}
llm operator * (ll obj){return llm((this->value * obj)%MOD);}
llm operator / (llm obj){return llm(this->value / (ll)(obj.value));}
llm operator / (ll obj){return llm(this->value / obj);}
llm operator % (llm obj){return llm(this->value % (ll)(obj.value));}
llm operator % (ll obj){return llm(this->value % obj);}};
ostream& operator<<(ostream& os, llm l){os << l.value;return os;} 
llm operator+(ll a,llm l){return llm((a + l.value)%MOD);} 
llm operator*(ll a,llm l){return llm((a * l.value)%MOD);}
 


 
int main(void){
	int sx,sy,tx,ty,x,y;
	cin>>sx>>sy>>tx>>ty;
	x = tx-sx;
	y = ty-sy;
	for(int i=0;i<x;i++){
		cout<<"R";
	}
	for(int i=0;i<-x;i++){
		cout<<"L";
	}
	rep(i,y){
		cout<<"U";
	}
	rep(i,-y){
		cout<<"D";
	}

	x = -x;
	y = -y;
	for(int i=0;i<x;i++){
		cout<<"R";
	}
	for(int i=0;i<-x;i++){
		cout<<"L";
	}
	rep(i,y){
		cout<<"U";
	}
	rep(i,-y){
		cout<<"D";
	}

	x*=-1;
	y*=-1;
	if(y>0){
		cout<<"D";
	}else{
		cout<<"U";
	}
	rep(i,x+1){
		cout<<"R";
	}
	
	for(int i=0;i<-x+1;i++){
		cout<<"L";
	}
	rep(i,y+1){
		cout<<"U";
	}
	rep(i,-y+1){
		cout<<"D";
	}

	if(x>0){
		cout<<"L";
	}else{
		cout<<"R";
	}

	x*=-1;
	y*=-1;
	if(y>0){
		cout<<"D";
	}else{
		cout<<"U";
	}
	rep(i,x+1){
		cout<<"R";
	}
	
	for(int i=0;i<-x+1;i++){
		cout<<"L";
	}
	rep(i,y+1){
		cout<<"U";
	}
	rep(i,-y+1){
		cout<<"D";
	}

	if(x>0){
		cout<<"L";
	}else{
		cout<<"R";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void init(char*);

int main(){
    int n, m, i;
    char a, b, convert[128];
    while(cin >> n){
        if(n == 0){
            break;
        }
        init(convert);
        for(i = 0; i < n; ++i){
            cin >> a >> b;
            convert[a] = b;
        }
        cin >> m;
        for(i = 0; i < m; ++i){
            cin >> a;
            if(convert[a] != 0){
                cout << convert[a];
            }else{
                cout << a;
            }
        }
        cout << endl;
    }
}

void init(char* ary){
    int i;
    for(i = 0; i < 128; ++i){
        ary[i] = 0;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  int N;
  cin >> N;
  ll sum[N+1], a, result = 0, add = 0;
  sum[0] = 0;
  rep(i, N){
    cin >> a;
    sum[i+1] = sum[i]+a;
  }
  sort(sum, sum+N+1);
  rep(i, N){
    if (sum[i] == sum[i+1]) {
      add += 1;
      result += add;
    }else{
      add = 0;
    }
  }
  puts(result)
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const lli inf = 1e18;

struct info{
    int p;
    lli v;
    lli d;
    info(int p, lli v, lli d):p(p),v(v),d(d){}
    info(){}
    bool operator <(const info &a) const{
        return d > a.d;
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<pll>> adj(n);
    for(int i=0; i<m; i++){
        lli x,y,t;
        cin >> x >> y >> t;
        x--; y--;
        adj[x].emplace_back(y, t);
        adj[y].emplace_back(x, t);
    }
    lli v_init,a,b,c;
    cin >> v_init >> a >> b >> c;

    priority_queue<info> wait;
    wait.push(info(0, v_init, 0));
    vector<vector<lli>> mincost(n, vector<lli>(c, inf));
    mincost[0][v_init] = 0;
    while(!wait.empty()){
        int p = wait.top().p;
        lli v = wait.top().v;
        lli d = wait.top().d;
        wait.pop();
        if(d > mincost[p][v]) continue;
        for(auto next: adj[p]){
            int np = next.first;
            lli t = next.second;
            lli nd = d + v*t;
            lli nv = (a*v +b) %c;
            if(nd < mincost[np][nv]){
                mincost[np][nv] = nd;
                wait.push(info(np, nv, nd));
            }
        }
    }

    lli ans = inf;
    for(int i=0; i<c; i++){
        wait.push(info(n-1, i, 0));
        vector<vector<lli>> mincost_back(n, vector<lli>(c, inf));
        mincost_back[n-1][i] = 0;
        while(!wait.empty()){
            int p = wait.top().p;
            lli v = wait.top().v;
            lli d = wait.top().d;
            wait.pop();
            if(d > mincost_back[p][v]) continue;
            for(auto next: adj[p]){
                int np = next.first;
                lli t = next.second;
                lli nd = d + v*t;
                lli nv = (a*v +b) %c;
                if(nd < mincost_back[np][nv]){
                    mincost_back[np][nv] = nd;
                    wait.push(info(np, nv, nd));
                }
            }
        }
        ans = min(ans, mincost[n-1][i] + *min_element(mincost_back[0].begin(), mincost_back[0].end()));
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6220
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 510000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a)
int main(){
  lli A=INF,B=INF,C=INF,D=INF,E,F,N,M,K,sum=0,num=0,cnt=1,next=0;
  cin >> N >> K;
  if(N<0){
    if(0<=K)Out("Zero");
    else{
      A=-N-K;
      if(A%2==0)Out("Negative");
      else Out("Positive");
    }
  }else{
    if(N==0)Out("Zero");
    else Out("Positive");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define mod 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define ss second
#define pb push_back
#define mp make_pair


vector<int> adj[101010];
int dist[101010], n, k, a[101010], ans=0;
bool vis[101010], ck[101010];

void dfs(int s){
if(vis[s])return ;
vis[s]=true;
for(auto u: adj[s]){
    dist[u]= min(dist[u], dist[s]+1);
    dfs(u);
}
}

void dfs2(int s, int p){

if(ck[s])return ;
ck[s]=true;
for(auto u: adj[s]){
   if(u!=p) dfs2(u, s);
}

}

int main(){

rep(i, 1, 101010)dist[i]=mod;

cin >> n >> k;
rep(i, 1, n){
cin >> a[i];
if(a[1]!=1)a[1]=1, ans++;
adj[a[i]].pb(i);
}
dist[1]=0;
dfs(1);

priority_queue<pi> q;
//vector<pi>  v;
rep(i,1, n){
q.push({dist[i], i});
}

//sort(v.begin(), v.end());

//reverse(v.begin(), v.end());
while(!q.empty()){
int u = q.top().ss;
int d = q.top().f;
q.pop();
if(d<=k)continue;
if(ck[u])continue;
rep(i, 1, k-1){
u = a[u];
}

dfs2(u, a[u]);
ans++;

}

cout << ans << endl;

return 0;}


Measured memory_bytes: 12276
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    long double L;
    cin >> L;
    cout << fixed << setprecision(10) << (L / 3.0) * (L / 3.0) * (L / 3.0)
         << endl;
    return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#include<math.h>
//#include "Ants.h"
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef pair < int, int> P;
/****Union-Ford-Tree***/
int par[int(0x7ffffff)];//Parent
int Rank[int(0x7ffffff)];//Deep_of_the_Tree

//int a[100] = { 4,2,3,1,5 }, m[100] ={3,2,2};
//int n = 0;
//const ll mod = 1000000007;


//n要素で初期化
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		Rank[i] = 0;
	}
}
//木の根探し
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;

	if (Rank[x] < Rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}
/************************************************************************************/
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
/**************/

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int ans = INF;
	
	for (int i = 0; i < n - 2; i++) {
		char res[3] = { s[i],s[i + 1],s[i + 2] };
		int num = (res[0]-'0') * 100;
		num += 10 * (res[1]-'0');
		num += res[2]-'0';
		ans = min(ans, abs(753-num));

	}
	cout << ans << endl;

}

Measured memory_bytes: 256