akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main(){
    int n;
    string s;
    cin>>n>>s;
    
    
    
    int cnt=0;
    
    // for (int i=0;i<n+3;i++){
    //     cin>>s.at(i);
    // }
    for (int i=0;i<n-2;i++){
        if(s.at(i)=='A'&& s.at(i+1)=='B' && s.at(i+2)=='C'){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 256
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=405;
int n;
class Tiles{
public:
	int c[4];
	Tiles(){}
	Tiles(int c0,int c1,int c2,int c3){c[0]=c0;c[1]=c1;c[2]=c2;c[3]=c3;}
	bool operator < (const Tiles &o)const{
		rep(i,4)if(c[i]!=o.c[i])return c[i]<o.c[i];
		return false;
	}
	bool operator == (const Tiles &o)const{
		rep(i,4)if(c[i]!=o.c[i])return false;
		return true;
	}
	Tiles rotate(){
		Tiles res;
		rep(i,4)res.c[(i+1)%4]=c[i];
		return res;
	}
	Tiles change(){
		Tiles cur=*this,res=*this;
		rep(i,3){
			cur=cur.rotate();
			if(cur<res)res=cur;
		}
		return res;
	}
	int countway(){
		Tiles cur=*this;
		int res=0;
		rep(i,4){
			cur=cur.rotate();
			if(cur==*this)res++;
		}
		return res;
	}
	ll gethash(){
		ll h=0;
		rep(i,4)h=1000LL*h+c[i];
		return h;
	}
};
set<Tiles>s;
map<ll,int>cnt,way;
int fac[maxn];

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	fac[0]=1;
	REP(i,4)fac[i]=fac[i-1]*i;
	rep(i,n){
		Tiles tmp;
		rep(j,4)scanf("%d",&tmp.c[j]);
		tmp=tmp.change();
		way[tmp.gethash()]=tmp.countway();
		cnt[tmp.gethash()]++;
		s.insert(tmp);
	}
	ll ans=0;
	map<ll,int>used;
	for(set<Tiles>::iterator it=s.begin();it!=s.end();it++){
		Tiles cur1=*it;
		ll h1=cur1.gethash();
		ll coef=cnt[h1];
		cnt[h1]--;
		for(set<Tiles>::iterator it2=s.begin();it2!=s.end();it2++){
			Tiles cur2=*it2;
			ll h2=cur2.gethash();
			ll coef2=coef;
			if(cnt[h2]!=0)coef2*=cnt[h2],cnt[h2]--;
			else continue;
			rep(i,4){
				ll now=coef2;
				vector<ll>v;
				bool ok=true;
				rep(j,4){
					Tiles cur3=Tiles(cur1.c[j],cur2.c[(4-j)%4],cur2.c[(4-(j+1)%4)%4],cur1.c[(j+1)%4]);
					cur3=cur3.change();
					ll h3=cur3.gethash();
					if(!cnt.count(h3)||!cnt[h3]){
						ok=false;
						break;
					}
					now*=cnt[h3]*way[h3];					
					cnt[h3]--;
					v.pb(h3);
				}
				if(ok){
					ans+=now;
				}
				rep(j,v.size())cnt[v[j]]++;
				cur2=cur2.rotate();
			}
			cnt[h2]++;
		}
		cnt[h1]++;
	}
	printf("%lld\n",ans/6);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INT long long int
using namespace std;
INT a, b, t, ans;
set<INT> x, y;
vector<INT> c, chk;
int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b;
    for(INT i = 1 ; i*i <= a ; i++ )
        if( a%i == 0 ) x.insert(i), x.insert(a/i);
    for(INT i = 1 ; i*i <= b ; i++ )
        if( b%i == 0 )
        {
            if( x.find(i) != x.end() ) y.insert(i);
            if( x.find(b/i) != x.end() ) y.insert(b/i);
        }
    for(INT v : y ) c.push_back(v);
    ans = 1;
    chk.resize(c.size(), 0);
    for(INT i = 1 ; i < c.size() ; i++ )
    {
        if( chk[i] ) continue;
        ans++;
        for(int j = i+1 ; j < c.size() ; j++ )
            if( c[j]%c[i] == 0 ) chk[j] = 1;
    }
    cout<<ans<<endl;
}


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

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    int tmp;
    for(int i = 0; i < n; i++){
        cin >> tmp;
        while(tmp % 2 == 0){
            tmp /= 2;
            cnt++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

vector<int> to[100005];
vector<bool> d(100005);
vector<bool> visited(100005,0);
bool flag = 1;
void dfs(int v, int p=-1) {
  for (auto u : to[v]) {
    if (u == p) continue;
    if(visited[u]){
      if(d[u]==d[v])flag=0;
      continue;
    }
    visited[u]=1;
    d[u] = 1-d[v];
    dfs(u,v);
  }
}

int main() {
  ll n,m;
  cin >> n >> m;
  rep(i,m) {
    int u,v;
    cin >> u >> v;
    --u; --v;
    to[u].push_back(v);
    to[v].push_back(u);
  }
  d[0]=0;
  //flag=1;
  visited[0]=1;
  dfs(0);
  if(flag){
    ll c0 =0,c1=0;
    rep(i,n){
      if(d[i]==0)c0++;
      else c1++;
    }
    ll ans = c0*c1-m;
    cout << ans << endl;
  }else{
    ll ans= n*(n-1)/2LL - m;
    cout << ans << endl;
  }
  return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint a,b,c,k;
    cin >> a>>b>>c>>k;
    lint ans;

    if(k%2==0){
        ans = a - b;
    }else{
        ans = b-a;
    }

    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef std::pair<int, int>p;

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

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

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
struct edge { int to, cost; };
std::vector<edge>v[100];
bool used[210];

int main() {
	int n, c, k, t[100000], ans = 0;
	std::cin >> n >> c >> k;
	for (int i = 0;i < n;i++) {
		std::cin >> t[i];
	}
	std::sort(t, t + n);
	int i = 0;
	while (i < n) {
		int sum = 1;
		t[i] += k;
		if (c == 1) {
			ans++, i++;
			continue;
		}
		for (int j = i + 1;j < n;j++) {
			if (t[i] < t[j])break;
			sum++;
			if (sum == c)break;
		}
		ans++;
		i += sum;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=1e5+50,P=1e9+7;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }

vector<int> cir[N];
int fail,len[N],vis[N],f[N];
int n,to[N],deg[N],blg[N],m,cnt[N]; 

void dfs(int v){
	vis[v]=2; 
	if(vis[to[v]]==2){
		++m;
		for(int x=to[v];;x=to[x]){
			blg[x]=m;
			cir[m].pb(x);
			if(x==v)break;
		}
	}else if(!vis[to[v]]){
		dfs(to[v]); 
	}
	vis[v]=1;
}

int process(vector<int> &c){
	vector<int> b;
	lop(i,0,(int)c.size()){
		if(len[c[i]])b.pb(i); 
		if(len[c[i]])Pr("len[%d]=%d\n",c[i],len[c[i]]); 
	}
	int res=1,nb=b.size(),nc=c.size();
	if(b.empty()){
		++cnt[c.size()];
		return res;
	}
	Pr("process : "); for(int x:c)Pr("%d ",x); Pr("\n"); 

	lop(i,0,(int)b.size()){
		int p=(i-1+nb)%nb,d=(b[i]-b[p]+nc)%nc,l=len[c[b[i]]];
		if(d==0)d=nc;
		Pr("i=%d,b[i]=%d,c[b[i]]=%d,d=%d,l=%d\n",i,b[i],c[b[i]],d,l); 
		res=mul(res,(d>=l)+(d>l));
	}
	return res;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	read(n); 
	rep(i,1,n){
		read(to[i]); 
		++deg[to[i]];
		Pr("to[%d]=%d\n",i,to[i]); 
	}	
	rep(i,1,n){
		if(!vis[i]){
			dfs(i); 
		}
	}
	rep(i,1,n){
		if(blg[i]&&deg[i]>2)fail=true;
		if(!blg[i]&&deg[i]>1)fail=true;
	}
	rep(i,1,n){
		if(deg[i])continue;
		int x,c=0; 
		for(x=i;!blg[x];x=to[x])++c;
		len[x]=c;
	}
	int ans=1;
	rep(k,1,m){
		ans=mul(ans,process(cir[k])); 
	}
	if(!ans)fail=true;
	Pr("ans=%d\n",ans); 
	rep(l,1,n){
		Pr("f[%d]=%d\n",l,f[l]); 
		int w=(l&1)+(l>1); 
		f[0]=1;
		rep(i,1,cnt[l]){
			f[i]=mul(f[i-1],w); 	
			if(i>1)f[i]=add(f[i],mul(f[i-2],mul(i-1,l)));
		}
		ans=mul(ans,f[cnt[l]]); 
	}
	Pr("fail=%d\n",(int)fail); 
	printf("%d\n", fail?0:ans);
	return 0;
}


Measured memory_bytes: 9852
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
sumd = sum([k*v for k, v in d.items()])

q = int(input())
t = []
for _ in range(q):
   b, c = map(int, input().split())
   t.append([b, c])

for b, c in t:
   sum_minus = b * d[b]
   tmp = d.pop(b, None)
   if tmp:
      if d[c] > 0:
         d[c] += tmp
      else:
         d[c] = tmp
      sumd = sumd - sum_minus + c * tmp
   print(sumd)


Measured memory_bytes: 33844
#include<iostream>

using namespace std;

int main(){
    int n, p[30],cnt=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    for(int i=1;i<=n-2;i++){
        if(p[i]==max(p[i-1],p[i]) ^ p[i]==max(p[i], p[i+1])){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);

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


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

int main(void){
	int N;
	cin >> N;
	int	mul2[3] = {0};
	for(int i = 0; i < N; ++i){
		long long int a;
		cin >> a;
		if(a % 4 == 0){
			mul2[2]++;
		} else if(a % 2 == 0){
			mul2[1]++;
		} else {
			mul2[0]++;
		}
	}
	//for(int i = 0; i < 3; ++i){
	//	cout << mul2[i] << endl;
	//}
	// 2の倍数があると後ろに並べなければいけないと思う
	if(mul2[1] >= 1){
		if(mul2[2] >= mul2[0]){
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	} else {
		if(mul2[0]-1 == mul2[2] || mul2[2] >= mul2[0]){
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#define N 60
#define M 2510
#define ls x << 1
#define rs x << 1 | 1
#define inf 0x3f3f3f3f
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
// #define int long long
#define debug() puts("XRZ TXDY");
#define Next(i, u) for(int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
using namespace std;
int ans; string s;
signed main() {
	cin >> s;
	int len = s.size();
	Rep(i, 0, len / 2 - 1) if(s[i] != s[len - i - 1]) inc(ans);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[1005],b,c,s=0;
int main()
{
    cin>>n>>b>>c;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    	if(a[i]<b || a[i]>=c) s++;
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){

		Scanner sr = new Scanner(System.in);
		String s = sr.next();
		int sum = 0;
		int a = 0;
		int b = 0;
		int c = 0;
		for(int i = 0; i < s.length(); i++){
			String ch = s.substring(i, i + 1);
			if(ch.indexOf("a") != -1){
				a++;
			}else if(ch.indexOf("b") != -1){
				b++;
			}else if(ch.indexOf("c") != -1){
				c++;
			}
		}
		if(a < 2 && b < 2 && c < 2 && (a + b + c) == 3){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996
/*
縦横を別々にやる
DPで...?
i回目の移動の後に座標jにいられるか? をbitsetで書けば速そう

*/

#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;long x,y;cin>>x>>y;x+=20000;y+=20000;
  long c=0;vector<long>H,V;int d=0;bool o=0;
  for(long i=0;i<s.length();i++){
    if(s[i]=='T' || i==s.length()-1){
      if(i==s.length()-1 && s[i]=='F')c++;
      
      if(!o){x-=c;o=1;}
      else{
        if(d==0)H.push_back(c);
        else V.push_back(c);
      }
      c=0;d=1-d;
    }
    else c++; 
  }
  bitset<20000*2> BH;BH.set(20000);
  for(auto h:H){
    bitset<20000*2> tmp;
    tmp|=(BH<<h)|(BH>>h);BH=tmp;
  }
  bitset<20000*2> BV;BV.set(20000);
  for(auto v:V){
    bitset<20000*2> tmp;
    tmp|=(BV<<v)|(BV>>v);BV=tmp;
  }
  cout<<(BH.test(x)&&BV.test(y)?"Yes":"No");
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen("C.in","r",stdin);
	int A,B,C,X,Y;
	scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);
	if(A+B<=C*2){
		printf("%d\n",X*A+Y*B);
		return 0;
	}
	int V=min(X,Y);
	int ans=V*C*2;
	X-=V,Y-=V;
	if(X>0)
		ans+=min(C*X*2,A*X);
	if(Y>0)
		ans+=min(C*Y*2,B*Y);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,n,s) for(int i=s;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  int a,b;
  cin >> a >> b;
  if(a >= 13) {
    cout << b << endl;
  } else if(a >= 6) {
    cout << b/2 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
class Dice:
    """サイコロを操作するクラス"""
    def __init__(self, num):
        self.num = num
    def roll_north(self):
        tmp = self.num[:]
        self.num[0] = tmp[1]
        self.num[1] = tmp[5]
        self.num[4] = tmp[0]
        self.num[5] = tmp[4]
    def roll_east(self):
        tmp = self.num[:]
        self.num[0] = tmp[3]
        self.num[2] = tmp[0]
        self.num[3] = tmp[5]
        self.num[5] = tmp[2]
    def roll_right(self):
        tmp = self.num[:]
        self.num[1] = tmp[3]
        self.num[2] = tmp[1]
        self.num[3] = tmp[4]
        self.num[4] = tmp[2]
    def print_dice(self):
        print(self.num)

dice1 = Dice(list(map(int, input().split())))
dice2 = Dice(list(map(int, input().split())))
flg = False
for i in range(20):
    if flg == True:
        break
    dice2.roll_north()
    for k in range(20):
        if flg == True:
            break
        dice2.roll_east()
        for l in range(20):
            dice2.roll_right()
            if dice1.num == dice2.num:
                flg = True
                break
if flg:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5612
#include <algorithm>
#include <iostream>
#include <limits>
#include <queue>
#include <utility>
#include <vector>

int main(int argc, char const* argv[])
{
    uint64_t n, m;
    std::cin >> n >> m;

    auto cards = std::vector<uint64_t>(n);
    for (auto& c : cards) {
        std::cin >> c;
    }

    std::sort(cards.begin(), cards.end());

    auto rewrites = std::vector<std::pair<int, uint64_t>>(m);

    for (uint64_t i = 0; i < m; ++i) {
        uint64_t b, c;
        std::cin >> b >> c;

        rewrites[i] = std::make_pair(b, c);
    }

    std::sort(rewrites.begin(), rewrites.end(), [](std::pair<int, uint64_t>& a, std::pair<int, uint64_t>& b) -> bool {
            return a.second > b.second;
            });

    int card_index = 0;
    for(int i=0; i<rewrites.size(); ++i)
    {
        uint64_t num = rewrites[i].second;
        for(int j=0; j<rewrites[i].first; ++j)
        {
            if(cards[card_index] < num)
            {
                cards[card_index] = num;
                card_index++;
            }
            else
            {
                goto done;
            }
        }
    }
done:

    uint64_t result = 0;
    for(int i=0; i<n;++i)
    {
        result += cards[i];
    }

    std::cout << result << std::endl;
}

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

using namespace std;

#define int long long 
#define INF 1001000100010001000
#define rep(i, n) for (int i = 0; i < n; i++) 
#define pb emplace_back

signed main(void)
{
    int n; cin >> n;
    vector<string> input(n);
    rep(i, n) {
        cin >> input[i];
    }

    vector<int> alp(30, INF);
    int ans = 0;
    rep(i, n) {
        ans = min(ans + 1, alp[input[i][0]-'a']);
        alp[input[i][0]-'a'] = ans;
//        cout << ans << endl;
    }

    cout << ans << endl;


    return 0;
}




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

struct edge {
    int to;
    int distance;
};

int N;
vector<vector<edge> > gragh(N);
vector<int> color(N, -1);

void dfs(int ver) {
    if (color.at(ver - 1) != -1) {
        return;
    }

    bool seen = false;
    for (int i = 0; i < gragh.at(ver - 1).size(); i++) {
        if (color.at(gragh.at(ver - 1).at(i).to - 1) != -1) {
            seen = true;
            if (gragh.at(ver - 1).at(i).distance % 2 == 0) {
                color.at(ver - 1) = color.at(gragh.at(ver - 1).at(i).to - 1);
            }
            else {
                color.at(ver - 1) = 1 - color.at(gragh.at(ver - 1).at(i).to - 1);
            }
            break;
        }
    }
    if (!seen) {
        color.at(ver - 1) = 0;
    }
    for (int i = 0; i < gragh.at(ver - 1).size(); i++) {
        dfs(gragh.at(ver - 1).at(i).to);
    }
}

int main() {
    cin >> N;
    gragh.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        edge e;
        cin >> u >> v >> w;
        e.to = v;
        e.distance = w;
        gragh.at(u - 1).push_back(e);
        e.to = u;
        gragh.at(v - 1).push_back(e);
    }

    color.resize(N, -1);
    dfs(1);
    
    for (int i = 0; i < N; i++) {
        cout << color.at(i) << endl;
    }
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
    lint n;cin >> n;
    string ans;
    if((n%10)==3){
        ans = "bon";
    }
    else if ((n % 10) == 0 || (n % 10) ==1 || (n % 10) == 6 || (n % 10) == 8){
        ans = "pon";
    }else{
        ans = "hon";
    }

        cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
int x, n, a, m, t;
int p[102];
int main() {
	scanf("%d%d", &x, &n);
	m = x;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		p[a] = 1;
	}
	a = 0;
	for (int i = 0; i < 102; i++) {
		if (p[i] == 0) {
			t = x - i;
			if (t < 0)t = -t;
			if (m > t) {
				m = t;
				a = i;
			}
		}
	}
	printf("%d\n", a);
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#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(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> H >> W >> K;
  Vec(G,string,H,"");
  rep(i,0,H)cin >> G[i];
  rep(i,0,H)rep(j,0,W)if(G[i][j]=='#')flag++;
  for(int h=0; h < (1<<H); h++){
    for(int w=0; w < (1<<W); w++){
      num=0;
      rep(i,0,H)if(h&(1<<i))rep(j,0,W)if(G[i][j]=='#')num++;
      rep(i,0,W)if(w&(1<<i))rep(j,0,H)if(G[j][i]=='#')num++;
      rep(i,0,H)rep(j,0,W)if((h&(1<<i))&&(w&(1<<j))&&G[i][j]=='#')num--;
      if(flag-K==num)sum++;
    }
  }
  Out(sum);
}

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

int memo[1111];

int solve(int n){
  
  if(!n) return 0;
  if(n<0) return 1<<28;
  if(memo[n]) return memo[n];
  
  int ans = 1<<28;
  ans = min(solve(n-500), min(solve(n-100), min(solve(n-50), min(solve(n-10), min(solve(n-5), solve(n-1))))))+1;
  
  return memo[n] = ans;
}

int main(){
  
  for(int i=0;i<1111;i++) solve(i);

  int n;
  while(cin >> n, n) cout << solve(1000-n) << endl;
  
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;

int main() {
	ll N,M;

	vector<ll>A;
	ll c;
	ll sum=0;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {

		cin >> c;
		sum += c;
	}
	N - sum >= 0 ? cout << N - sum : cout << -1;

}

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

typedef long long ll;

#define debug(args...)do{cerr<< #args << " : ";shaon(args);}while(0)
void shaon () { cerr << endl; }
template <typename T, typename ... north>
void shaon(T arg, const north &... rest){cerr << arg << ' ';shaon(rest...);}

const ll N=1e5+5;
ll dp[N], n, a[N], k;


int main()
{
    scanf("%lld %lld",&n,&k);

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

    dp[2]=abs(a[1]-a[2]);

    for(ll i=3; i<=n; i++){
        dp[i]=dp[i-1]+abs(a[i-1]-a[i]);
        for(ll w=i-2, y=k-1; y>0 && w>=1; w--,y--){
            dp[i]=min(dp[i],dp[w]+abs(a[w]-a[i]));
        }
    }

    printf("%lld",dp[n]);

    return 0;
}


















Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main {

  static int n;
  static int[] h;
  static int[] memo;

  public static int dp(int i) {
    if (i == n - 1) {
      return 0;
    }
    if (memo[i] != -1) {
      return memo[i];
    }
    if (i == n - 2) {
      return memo[i] = Math.abs(h[i] - h[i + 1]) + dp(i + 1);
    } else {
      return memo[i] = Math.min(Math.abs(h[i] - h[i + 1]) + dp(i + 1), Math.abs(h[i] - h[i + 2]) + dp(i + 2));
    }

  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    h = new int[n];
    for (int i = 0; i < n; i++)
      h[i] = sc.nextInt();
    memo = new int[n];
    Arrays.fill(memo, -1);
    System.out.println(dp(0));
  }
}

Measured memory_bytes: 64480
import collections
N = int(input())
D = list(map(int, input().split()))
D.append(0)
ans = 0  
    
x = collections.Counter(D)
y = x.most_common(1)
#print(x,y,y[0][1])

if y[0][1] >= 3:
  print(ans)
  quit()
         
if y[0][1] == 2:
  if (y[0][0] == 0) or (y[0][0] == 12):
    print(ans)
    quit()
 
day = [0] * 24 
ilist = [0] * 13
for i in range(13):
  if (i == 0) or (i == 12):
    if i in D:
      day[i] = 1
      ilist[i] = 1
  else:# i = 1 ~ 11
    if D.count(i) == 2:
      day[i] = 1
      day[24 - i] = 1
      ilist[i] = 2
    elif D.count(i) == 1:
      #print(i)
      p = 0
      l = 1
      while p == 0:
        p = ilist[i - l]
        if p == 0:
          l += 1
        if (p == 0) and (l == i):
          p = 3
      #print(i,p,ilist)
      if p == 3:
        day[i] = 1
      if p == 2:
        day[i] = 1
      if p == 1:
        #print(i, l, day)
        if day[i - l] == 1:
          day[24-i] = 1
        else:
          day[i] = 1
      ilist[i] = 1
      

day2 = day * 2
ans = 25
ans2 = 1
xp = 1
#print(day2)
for i in range(len(day2)):
  if day2[i] == 0:
    ans2 += 1
    xp = 0
  elif (day2[i] == 1) and (xp == 0):
    #print(ans, ans2)
    ans = min(ans, ans2)
    ans2 = 1

if ans > 24:
  ans = ans - 24
print(ans)
 




Measured memory_bytes: 39024
x,y,z,K=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()

res1=[]
for i in range(x):
    for j in range(y):
        res1.append(a[i]+b[j])
res1.sort()
res2=[]
for i in range(min(K,x*y)):
    for k in range(z):
        res2.append(res1[-i-1]+c[k])
res2.sort()
for i in range(K):
    print(res2[-1-i])

Measured memory_bytes: 148332
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int n;
	scanf("%d",&n);
	int x,y,z,count=0;
	for(int i=1;i<=n;i++){
		count=0;
		for(x=1;x<10000;x++){
			for(y=1;y<10000-x;y++){
				for(z=1;z<10000-x-y;z++){
					if((x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x) == i){
						count++;
					}
					if(((x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x))>=i)break;
				}
				if(((x*x)+(y*y)+(x*y))>=i)break;
			}
			if((x*x)>=i)break;
		}
		printf("%d\n",count);
	}
}


Measured memory_bytes: 1676
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

ans = 0
for i in 1..N do
  if i % 2 == 1 and lines[1][i-1] % 2 == 1 then
    ans += 1
  end
end
  
puts ans

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<vector<ll>> A(N, vector<ll>(N));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> A[i][j];
        }
    }

    const ll Amax = 1e+9;
    mcf_graph<ll, ll> graph(2 * N + 2);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            graph.add_edge(i, N+j, 1, Amax - A[i][j]);
        }
    }
    graph.add_edge(2*N, 2*N+1, N*K, Amax);
    for(int i=0;i<N;i++){
        graph.add_edge(2*N, i, K, 0);
        graph.add_edge(N+i, 2*N+1, K, 0);
    }

    auto ret = graph.flow(2*N, 2*N+1, N*K);
    cout << (Amax * N * K - ret.second) << endl;;

    vector<string> res(N, string(N, '.'));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            auto e = graph.get_edge(i*N+j);
            if(e.flow > 0) res[i][j] = 'X';
        }
    }
    for(auto v : res) cout<<v<<endl;

    return 0;
}

Measured memory_bytes: 3936
#include <stdio.h>

int main(void)
{
	int time;
	int sum = 0;
	int i;
	
	for (i = 0; i < 4; i++){
		scanf("%d", &time);
		sum += time;
	}
	printf("%d\n", sum / 60);
	printf("%d\n", sum % 60);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 1000005;
const ll MOD = 1e9+7;
ll mypow10[MAX_N],mypow9[MAX_N],mypow8[MAX_N];

void init()
{
	mypow10[0] = 1;
	mypow9[0] = 1;
	mypow8[0] = 1;
	rep(i,MAX_N-1)
	{
		mypow10[i+1] = mypow10[i] * 10 % MOD;
		mypow9[i+1] = mypow9[i] * 9 % MOD;
		mypow8[i+1] = mypow8[i] * 8 % MOD;
	}
	return;
}

int main()
{
	init();
	int N;
	cin >> N;
	ll temp = (mypow10[N] - mypow9[N] + MOD) % MOD;
	cout << (temp * 2 % MOD - (mypow10[N] - mypow8[N] + MOD) % MOD + MOD) % MOD << endl;
	return 0;
}

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

const long long MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> t(n), a(n);
    for (int i = 0; i < n; i++) {
        cin >> t.at(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    if (n == 1) {
        if (t.at(0) != a.at(0)) {
            cout << 0 << endl;
            return 0;
        }
    }

    vector<int> h(n);
    h.at(0) = t.at(0);
    h.at(n - 1) = a.at(n - 1);
    for (int i = 1; i < n; i++) {
        if (t.at(i - 1) < t.at(i)) {
            if (h.at(i) != 0 && h.at(i) != t.at(i)) {
                cout << 0 << endl;
                return 0;
            }
            h.at(i) = t.at(i); 
        }
    }
    for (int i = 1; i < n; i++) {
        if (a.at(i - 1) > a.at(i)) {
            if (h.at(i - 1) != 0 && h.at(i - 1) != a.at(i - 1)) {
                cout << 0 << endl;
                return 0;
            }
            h.at(i - 1) = a.at(i - 1);
        }
        if (h.at(i - 1) != 0 && h.at(i - 1) > a.at(i - 1)) {
            cout << 0 << endl;
            return 0;
        } 
    }
    
    long long ans = 1;
    for (int i = 0; i < n; i++) {
        if (h.at(i) == 0) {
            ans *= (long long)min(t.at(i), a.at(i));
            ans %= MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
i = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_cost=min(a)+min(b)
for j in range(i[2]):
    x = list(map(int, input().split()))
    if (a[x[0]-1]+b[x[1]-1]-x[2])<min_cost:
        min_cost=(a[x[0]-1]+b[x[1]-1]-x[2])
print(min_cost)

Measured memory_bytes: 18612
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int n;
    int sum = 0;
    vector<int> vec;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        vec.push_back(v);
        sum += v;
    }
    int p = sum / n;
    
    int sum2 = sum = 0;
    for (int i = 0; i < n; i++) {
        sum  += (vec[i] - p) * (vec[i] - p);
        sum2 += (vec[i] - p - 1) * (vec[i] - p - 1);
    }
    int ans = (sum > sum2) ? sum2 : sum;
    cout << ans << endl;
    
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------
ll N, P;

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

int main() {
  cin >> N >> P;
  auto mp = prime_factor(P);

  ll ans = 1;
  for (auto e : mp) {
    ll k = e.first;
    ll v = e.second;
    ans *= pow(k, v / N);
  }
  cout << ans << endl;
}


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

using namespace std;

int gcd(int m, int n) {
  if (m%n==0) return n;
  else return gcd(n, m%n);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;
  cout<<360/gcd(360, n)<<"\n";
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int N, A, B, C;
int l[8], group[8];
int ans = 1 << 30;
void solve(int k) {
	if (k == N) {
		int sum[4] = {};
		int cnt[4] = {};
		for (int i = 0; i < N; i++) {
			sum[group[i]] += l[i];
			cnt[group[i]]++;
		}
		if (cnt[1] == 0 || cnt[2] == 0 || cnt[3] == 0) return;
		int ret = abs(A - sum[1]) + abs(B - sum[2]) + abs(C - sum[3]) + (cnt[1] + cnt[2] + cnt[3] - 3) * 10;
		ans = min(ans, ret);
		return;
	}
	for (int i = 0; i < 4; i++) {
		group[k] = i;
		solve(k + 1);
	}
}
int main() {
	cin >> N >> A >> B >> C;
	for (int i = 0; i < N; i++) {
		cin >> l[i];
	}
	solve(0);
	cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const ll M = 998244353;

ll n, s;
ll a[3005];
ll d[3005];

int main()
{
    scanf("%lld%lld", &n, &s);
    d[0] = 1;
    for(ll i = 0; i < n; i++)
    {
        ll t;
        scanf("%lld", &t);
        for(ll j = s; j >= 0; j--)
        {
            d[j] *= 2;
            if(j >= t) d[j] += d[j - t];
            d[j] %= M;
        }
    }
    printf("%lld\n", d[s]);
    return 0;
}


Measured memory_bytes: 3852
from collections import defaultdict
import math
def factorize(n):
    i = 2
    factors = defaultdict(int)
    while i**2 <= n:
        if n % i != 0:
            i += 1
            continue

        while n % i == 0:
            n //= i
            factors[i] += 1
        i += 1

    if n != 1:
        factors[n] += 1

    return factors

def C(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

N, M = map(int, input().split())
factors = factorize(M)
# print(factors)

ans = 1
for key, val in factors.items():
    ans *= C(N + val - 1, val)

MOD = 10**9 + 7
print(ans % MOD)


Measured memory_bytes: 134772
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float("inf")] * N
goal_index = N - 1
dp[0] = 0
for i in range(N):
	for k in range(1, K + 1):
		if i + k <= goal_index:
			dp[i + k] = min(dp[i + k], dp[i] + abs(H[i + k] - H[i]))
		else:
			break
			
print(dp[-1])

Measured memory_bytes: 55008
use std::io;
use std::cmp;


fn main() {
    let n = read_one::<usize>();
    let mut cnt = vec![::std::usize::MAX; 26];

    for _ in 0..n {
        let s_ni = read_one::<String>().chars()
            .collect::<Vec<char>>();
        let mut _cnt = vec![0; 26];
        for s in s_ni {
            _cnt[(s as u8 - 'a' as u8) as usize] += 1;
        }

        for c in 0..26 {
            cnt[c] = cmp::min(cnt[c], _cnt[c]);
        }
    }

    for c in 0..26 {
        for _ in 0..cnt[c] {
            print!("{}", (c + 'a' as usize) as u8 as char);
        }
    }
    println!();
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int main(){
    string s,t;
    cin>>s>>t;
    int m=s.size(), n=t.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(t[i-1]==s[j-1]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
//    cout<<dp[n][m]<<endl; // 最長共通部分列長さ

// dp配列を逆からたどってLCSを作成する
	// LCSの長さが更新されたときの文字を追加していく
 
	string ans;
	int x = n;
	int y = m;
	while(x > 0 && y > 0){
		if(dp[x][y] == dp[x-1][y]){
			x--;
		}else if(dp[x][y] == dp[x][y-1]){
			y--;
		}else{
			x--;
			y--;
			ans.push_back(t[x]);
		}
	}
 
	reverse(ans.begin(), ans.end());
    cout << ans << endl; // 長共通部分文字列
    return 0;
}

Measured memory_bytes: 35584
# -*- coding: utf-8 -*-
"""
Jogging
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0211

"""
import sys
from math import gcd
from functools import reduce

def solve(n, data):
    res = []
    for i in range(n):
        t = 1
        for j in range(n):
            t *= (data[j][0], data[j][1])[i==j]
        res.append(t)
    g = reduce(gcd, res)
    return [r//g for r in res]


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        data = [[int(i) for i in input().split()] for _ in range(n)]
        ans = solve(n, data)
        print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 6352
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    string s;
    in>>s;
    int n=s.length(),ans=n;
    Fr(i,n-1) if(s[i-1]!=s[i]) ans=min(ans,max(i,n-i));
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	int i, N, A[2001], sum = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(A[i]));
		sum += A[i];
	}
	
	int j, k, r, half = sum / 2, halff = half / 64;
	const unsigned long long sup = 18446744073709551615;
	unsigned long long flag[32000] = {1}, tmp[32000];
	for (i = 1; i <= N; i++) {
		k = A[i] / 64;
		r = A[i] % 64;
		for (j = 0; j <= halff; j++) tmp[j] = 0;
		for (j = 0; j <= halff - k; j++) {
			tmp[j+k] |= (flag[j] & (sup >> r)) << r;
			if (r != 0) tmp[j+k+1] |= flag[j] >> (64 - r);
		}
		for (j = 0; j <= halff; j++) flag[j] |= tmp[j];
	}
	
	flag[halff] &= (sup >> (63 - half % 64));
	for (i = halff; i >= 0; i--) if (flag[i] != 0) break;
	for (j = -1; flag[i] != 0; j++, flag[i] >>= 1);
	printf("%d\n", sum - i * 64 - j);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2240
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define MAXN 1000001
void solve(){
	ll n,k;
	cin>>n>>k;
	ll freq[n+1]={0};
	while(k--)
	{
		ll d;
		cin>>d;
		while(d--)
		{
			int x;
			cin>>x;
			++freq[x];
		}
		
	}
	ll count=0;
	for(int i=1;i<=n;i++)
	{
		if(freq[i]==0)
		{
			count++;
		}
	}
	cout<<count<<endl;
}
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int t=1;
  //  cin>>t;
    while(t--){
        solve();
    }
} 

Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int[][] A=new int[n][m];
		int[] b=new int[m];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				A[i][j]=scan.nextInt();
			}
		}
		for(int i=0;i<m;i++){
			b[i]=scan.nextInt();
		}
		int sum;
		for(int i=0;i<n;i++){
			sum=0;
			for(int j=0;j<m;j++){
				sum+=A[i][j]*b[j];
			}
			System.out.println(sum);
		}
		scan.close();
	}
}

Measured memory_bytes: 31876
#!/usr/bin/env ruby

numbers = gets.split.map(&:to_f)
puts numbers[0] * numbers[1] * Math.sin(numbers[2]*(Math::PI/180)) /2.0
puts (numbers[0]**2 + numbers[1]**2 - 2 * numbers[0] * numbers[1] * Math.cos(numbers[2]*(Math::PI/180))) ** 0.5 + numbers[0] + numbers[1]
puts numbers[1] * Math.sin(numbers[2]*(Math::PI/180))


Measured memory_bytes: 6964
import math
from functools import reduce
from collections import deque
import heapq
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

h,w = get_nums_l()
grid = [ input() for _ in range(h) ]
dp = [ [99999999999999999999] * w for _ in range(h)]

def bfs(cost, x, y):
    log(cost, y, x)
    if dp[y][x] <= cost:
        return

    dp[y][x] = cost

    if x < w-1:
        if grid[y][x] == "." and grid[y][x+1] == "#":
            heapq.heappush(heap, (cost+1, x+1, y))
        else:
            heapq.heappush(heap, (cost, x+1, y))

    if y < h-1:
        if grid[y][x] =="." and grid[y+1][x] == "#":
            heapq.heappush(heap, (cost+1, x, y+1))
        else:
            heapq.heappush(heap, (cost, x, y+1))

heap = []

if grid[0][0] == ".":
    heapq.heappush(heap, (0,0,0))
else:
    heapq.heappush(heap, (1,0,0))

while heap:
    cost, x, y = heapq.heappop(heap)
    bfs(cost, x, y)

print(dp[h-1][w-1])

Measured memory_bytes: 69208
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
using ull = unsigned long long;
using mp = map<ull,ull>;

void PrimeFactor(ull N, mp& pri){
  while(N%2==0){
    pri[2]++;
    N /=2;
  }
  for(ull i = 3; i < sqrt(N)+1;){
    if( N%i == 0 ){
      pri[i]++;
      N /= i;
      i = 3;
    }else{
      i+=2;
    }
  }
  pri[N]++;
}
ull Pow(ull n, ull p){
  ull ret = 1;
  for(ull i = 0; i < p; i++)
    ret *= n;
  return ret;
}
int main(){
  ull n, p, ans=1;
  cin >> n >> p;
  mp tes;
  PrimeFactor(p,tes);

  if(n==1) cout << p <<"\n";
  else{
    for(auto& x : tes){
      if(x.second >= n)
        ans *= Pow( x.first, (x.second/n) );
      //cout<<x.first<<':'<<x.second<<"\n";
    }
    cout<<ans<<"\n";
  }
  return 0;
}


Measured memory_bytes: 384
#ifdef INPUT
#include <sstream>
stringstream input(R"(
2
80 70
)");
#define cin input
#endif

#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

int main()
{
    string s;
	int k;
	cin >> s >> k;

    set<string> m;
    FOR (i, 1, min((int)s.size() + 1, k + 1))
        REP (j, (int)s.size() - i + 1)
            m.insert(s.substr(j, i));

    auto it = m.begin();
    advance(it, k - 1);
	cout << *it << endl;

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

ll mygcd(ll x,ll y){
    if(x <= y){
        if(x == 0)
            return y;
        else
            return mygcd(y%x,x);      
    }else{
        if(y == 0)
            return x;
        else
        {
            return mygcd(y,x%y);
        }
        
    }
}


int main(){
    ll N,X;
    cin >> N >> X;
    vector<ll> A(N);

    for(int i = 0;i < N;i++)
        cin >> A.at(i);

    sort(A.begin(),A.end());

    ll min = INF;

    vector<ll>sa(N);
    for(int i = 0;i < N;i++){
        sa.at(i) = abs(X - A.at(i));
    }

    ll gcmax=-1,ans=sa.at(0);
    for(int i = 1;i < N;i++){
        ans = mygcd(ans,sa.at(i));
        if(ans > gcmax)
            gcmax=ans;
    }

    cout << ans << endl;

}

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

using namespace std;

string removeDuplication(string s) {
  sort(s.begin(), s.end());
  string ret;
  for (int i = s.size() - 1; i >= 0; --i) {
    if (s[i+1] != s[i]) ret.push_back(s[i]);
  }
  return ret;
}

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

  int ans = 0;
  for (int i = 1; i < N; ++i) {
    string x = S.substr(0, i);
    string y = S.substr(i, N-i);

    x = removeDuplication(x);

    int sum = 0;
    for (int j = x.size()-1; j >= 0; --j) {
      if (y.find(x[j]) != string::npos) {
        sum++;
      }
    }

    ans = max(sum, ans);
  }

  cout << ans;
}

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

int main(void)
{
  int n,m;
  scanf("%d",&n);
  char a[n][11];
  for(int i=0; i<n; i++){
      scanf("%s",a[i]);
  }

  scanf("%d",&m);
  char b[m][11];
  for(int i=0; i<m; i++){
      scanf("%s",b[i]);
  }

 // qsort(a,n,11,strcmp);
 // qsort(b,m,11,strcmp);

  int count = 0;
  int max = 0;

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(strcmp(a[i],a[j])==0) count++;
    }
    
    for(int k=0; k<m; k++){
      if(strcmp(a[i],b[k])==0) count--;
    }
    if(max<count) max=count;
    count = 0;
  }

  printf("%d",max);

    return 0;

}



Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int partition(int,int);
int *A;
int main(){
  int n,i,r,a;
  scanf("%d",&n);

  A=(int *)malloc(sizeof(int)*n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
 
  }

  r=partition(0,n-1);


  for(i=0;i<r;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf(" [%d]",A[r]);

  for(i=r+1;i<n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  
  free(A);
  return 0; 
}

int partition(int p,int r){
  int x,j,a,b,i;

  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
  
    if(A[j]<=x){
      i=i+1;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  b=A[i+1];
  A[i+1]=A[r];
  A[r]=b;
  
  return i+1;
}

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

const long long inf=1000000000000000000ll;
int n,a[510][510],x,y;
long long f[2][510][510],ans,sum[510][510],Sum[510][510];

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++) if (j!=i) scanf("%d",&a[i][j]);
	for (int i=1; i<=n; i++)
	{
		sum[i][0]=Sum[i][0]=0;
		for (int j=1; j<=n; j++)
			sum[i][j]=sum[i][j-1]+a[i][j],Sum[i][j]=Sum[i][j-1]+a[j][i];
	}
	for (int i=0; i<=n; i++)
		for (int j=0; j<=n; j++)
			f[0][i][j]=f[1][i][j]=inf;
	x=1,y=0,f[0][1][1]=0;
	for (int i=2; i<=n; i++) 
	{
		x^=1,y^=1;
		for (int j=1; j<=n; j++)
			for (int k=1; k<=n; k++) f[y][j][k]=inf;
		for (int j=1; j<i; j++)
			for (int k=j; k<i; k++)
				f[y][j][k]=min(f[y][j][k],f[x][j][k]+sum[i][j-1]+Sum[i][i]-Sum[i][k-1]),
				f[y][k][i]=min(f[y][k][i],f[x][j][k]+sum[i][k-1]);
	}
	ans=inf;
	for (int i=1; i<=n; i++) 
		for (int j=1; j<=n; j++) ans=min(ans,f[y][i][j]);
	return printf("%lld\n",ans),0;
}

Measured memory_bytes: 9344