akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

using namespace std;

const int V_MAX=50*50+2;
const int CAPA_INF=1<<29;
const int COST_INF=1<<29;

template<class capa_t,class cost_t>
struct edge{
	int v,rev;
	capa_t capa;
	cost_t cost;
	capa_t flow;
};

template<class capa_t,class cost_t>
void add_directed_edge(vector< edge<capa_t,cost_t> > *G,int u,int v,capa_t capa,cost_t cost){
	G[u].push_back((edge<capa_t,cost_t>){v,G[v].size()  ,capa, cost,0});
	G[v].push_back((edge<capa_t,cost_t>){u,G[u].size()-1,   0,-cost,0});
}

template<class T,class U>
pair<T,U> augment(int n,vector< edge<T,U> > *G,int s,int t,U *pot,bool fir){
	static int pre[V_MAX];
	static U d[V_MAX];
	rep(u,n) d[u]=(u==s?0:COST_INF);

	bool ok;
	if(fir){
		// Bellman-Ford
		while(1){
			bool end=true;
			rep(u,n) rep(i,G[u].size()) {
				edge<T,U> &e=G[u][i];
				if(e.capa-e.flow>0 && d[u]<COST_INF && d[u]+e.cost<d[e.v]){
					d[e.v]=d[u]+e.cost;
					pre[e.v]=e.rev;
					end=false;
				}
			}
			if(end) break;
		}
		ok=(d[t]<COST_INF);
	}
	else{
		// Dijkstra
		ok=false;
		priority_queue< pair<U,int> > Q; Q.push(make_pair(0,s));
		while(!Q.empty()){
			int u=Q.top().second;
			U cost=-Q.top().first; Q.pop();

			if(cost<d[u]) continue;
			if(u==t) ok=true;

			rep(i,G[u].size()){
				edge<T,U> &e=G[u][i];
				U cost2=cost+e.cost+pot[u]-pot[e.v];
				if(e.capa-e.flow>0 && cost2<d[e.v]){
					d[e.v]=cost2;
					pre[e.v]=e.rev;
					Q.push(make_pair(-cost2,e.v));
				}
			}
		}
	}

	if(!ok) return make_pair(0,0);

	T water=CAPA_INF;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		water=min(water,e2.capa-e2.flow);
		v=e1.v;
	}

	U cost=0;
	for(int v=t;v!=s;){
		edge<T,U> &e1=G[v][pre[v]];
		edge<T,U> &e2=G[e1.v][e1.rev];
		e1.flow-=water;
		e2.flow+=water;
		cost+=water*e2.cost;
		v=e1.v;
	}

	rep(u,n) pot[u]+=d[u];

	return make_pair(water,cost);
}

template<class T,class U>
pair<T,U> primal_dual(int n,vector< edge<T,U> > *G,int s,int t){
	static U pot[V_MAX];
	rep(u,n) pot[u]=0;

	T ans1=0;
	U ans2=0;
	for(bool fir=true;;fir=false){
		pair<T,U> tmp=augment(n,G,s,t,pot,fir);
		if(tmp.first==0) break;
		ans1+=tmp.first;
		ans2+=tmp.second;
	}
	return make_pair(ans1,ans2);
}

int main(){
	int h,w; cin>>h>>w;
	vector<string> B(h);
	rep(i,h) cin>>B[i];

	vector<edge<int,int>> G[50*50+2];
	int s=h*w,t=h*w+1;

	rep(i,h) rep(j,w) {
		if(B[i][j]=='o'){
			add_directed_edge(G,s,i*w+j,1,0);
		}
		if(B[i][j]!='#'){
			add_directed_edge(G,i*w+j,t,1,0);
		}
		if(i<h-1 && B[i][j]!='#' && B[i+1][j]!='#'){
			add_directed_edge(G,i*w+j,(i+1)*w+j,h*w,-1);
		}
		if(j<w-1 && B[i][j]!='#' && B[i][j+1]!='#'){
			add_directed_edge(G,i*w+j,i*w+(j+1),h*w,-1);
		}
	}

	printf("%d\n",-primal_dual(h*w+2,G,s,t).second);

	return 0;
}


Measured memory_bytes: 4268
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define INF 2140000000
#define MOD 1000000007

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

    return gcd(b % a, a); 
} 

int main() {
	int n;

	cin >> n;

	if (n == 1) {
		cin >> n;
		cout << 1000000000 << endl;
		return 0;
	}

	vector<int> a(n);

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	vector<int> gcd1(n);
	vector<int> gcd2(n);

	gcd1[0] = a[0];

	for (int i = 1; i < n; ++i) {
		gcd1[i] = gcd(a[i], gcd1[i - 1]);
	}

	gcd2[n - 1] = a[n - 1];

	for (int i = n - 2; i >= 0; --i) {
		gcd2[i] = gcd(a[i], gcd2[i + 1]);
	}

	int ans = -1;

	for (int i = 0; i < n; ++i) {
		if (i == 0) {
			ans = max(ans, gcd2[i + 1]);
		}
		else if (i == n - 1) {
			ans = max(ans, gcd1[i - 1]);	
		}
		else {
			ans = max(ans, gcd(gcd1[i - 1], gcd2[i + 1]));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main()
{
    long long n,a,b;//这题范围到了三个10^9,合起来可能有10^18,一定要开long long
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)//本题精华之特判,n=1的时候最大数和最小数必须一致,因为只有一个数,其他的时候就只要满足a>=b即可
        cout<<(n-2)*(b-a)+1<<endl;//按照(n-2)*(a-b)+1的思路打的代码,其实我也想到了(笑)
    else
        cout<<0<<endl; 
 } 

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

ptA = 0
ptB = 0

for i in range(N):
    if i % 2 == 0:
        temp = max(a)
        ptA += temp
        a.remove(temp)
    else:
        temp = max(a)
        ptB += temp
        a.remove(temp)

print(ptA-ptB)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

#define vi vector<int>

int main(){
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vi s(n),p(n),q(n),r(n);
    for(i=0;i<n;i++)cin>>s[i]>>p[i]>>q[i]>>r[i];
    int pp,qq,rr,cc;
    cin>>pp>>qq>>rr>>cc;
    vi ans;
    for(i=0;i<n;i++)
      if(p[i]<=pp&&q[i]<=qq&&r[i]<=rr){
        int tmp=p[i]*4+q[i]*9+r[i]*4;
        if(tmp<=cc)ans.push_back(s[i]);
      }
    if(ans.size()){
      for(i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
}

Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    long long unit = 1LL * n * (n + 1) / 2;
    long long sum = accumulate(begin(a), end(a), 0LL);
    if (sum % unit) return !(cout << "NO" << endl);
    long long k = sum / unit;
    auto check = [&]() {
        long long cnt = 0;
        for (int i = 0; i < n; i++) {
            int d = a[(i + 1) % n] - a[i];
            if (k - d < 0 || (k - d) % n) return false;
            cnt += (k - d) / n;
        }
        return cnt == k;
    };
    cout << (check() ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N;
	cin >> N;
	vector<LL> A(N);
	LL ans = 0;
	LL base = N * N + N;
	
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		LL cnt = A[i] / base;
		ans += base * cnt;
		A[i] %= base;
	}
	
	int LOOP = 0;
	int ter = 0;
	while (LOOP != N) {
		if (A[ter] >= N) {
			LOOP = 0;
			int asd = A[ter] / N;
			ans += asd;
			A[ter] %= N;
			for (int i = 0; i < N; ++i) {
				if (i == ter)continue;
				A[i] += asd;
			}
		}
		else {
			LOOP++;
		}
		ter = (ter + 1) % N;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
    var s string
    fmt.Scan(&s)

    if len(s) == 2 {
        fmt.Println(s)
    } else {
        for i := 0; i < len(s); i++ {
            fmt.Print(string(s[len(s)-i-1]))
        }
        fmt.Println()
    }
}

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

using namespace std;

int A[100002];
int F[100002];

int main() {
    int n;
    cin >> n;
    for (int i=1;i<=n;++i) {
        cin>>A[i];
    }
    F[1] = 0;
    F[2] = (int) abs (A[2]-A[1]);
    for (int i=3;i<=n;++i) {
        F[i] = (int) min ( F[i-1] + abs (A[i]-A[i-1]) , F[i-2] + abs (A[i] - A[i-2]) );
    }
    cout<<F[n];
    return 0;
}

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

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

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

int n;
std::vector<int> dat[26];
std::set<int> pl[26], mn[26];

int getL(const std::set<int> &s, int x, int y)
{

    auto be = s.lower_bound(x), en = s.upper_bound(y);

    int cnt = 0;

    while (be != en)
    {
        ++be;
        ++cnt;
    }
    return cnt;
}

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

    std::string s;
    std::cin >> s;

    rep(i, 26)
        dat[i]
            .resize(n + 1);

    rep(i, s.size())
    {
        ++dat[s[i] - 'a'][i + 1];
    }

    rep(i, 26) rep(j, n)
    {
        dat[i][j + 1] += dat[i][j];
    }

    int q;

    std::cin >> q;

    rep(i, q)
    {
        int type, x;

        std::cin >> type >> x;
        if (type == 1)
        {
            char y;
            std::cin >> y;
            bool f = 0;
            rep(i, 26)
            {
                if (pl[i].count(x))
                {
                    f = 1;
                    pl[i].erase(x);
                    break;
                }
            }
            if (!f)
                mn[s[x - 1] - 'a'].insert(x);
            pl[y - 'a'].insert(x);
        }
        else
        {
            int z;
            std::cin >> z;
            int ans = 0;

            rep(j, 26)
            {
                int xxx = dat[j][z] - dat[j][x - 1] + getL(pl[j], x, z) - getL(mn[j], x, z);
                /*if (xxx > 0)
                    std::cerr << char('a' + j) << ' ' << xxx << std::endl;*/
                ans += (xxx > 0);
            }

            std::cout << ans << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 56452
# coding: utf-8
# Your code here!

s=input()
t=input()
b=[]

if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)+1):
        ans=s
        for j in range(len(t)):
            flg=True
            if s[i+j]=='?' or s[i+j]==t[j]:
                #print(ans)
                ans=ans[:i+j]+t[j]+('' if i+j+1>len(s) else ans[i+j+1:])
            else:
                flg=False
                break
        if flg==True:
            b.append(ans.replace('?','a'))
#print(b)
b.sort()

print(b[0] if len(b)>0 else 'UNRESTORABLE')

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

int d[13];
int da[13],db[13];

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

    bool three=false;

    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        int id;cin>>id;
        d[id]++;
        if(d[id]>=3)three=true;
    }

    if(three||d[0]>0||d[12]==2){cout<<0<<"\n";return 0;}

    int ans=24;
    da[0]=1;db[0]=1;
    int am=0,bm=0;
    for(int i=1;i<=11;i++)
    {
        if(d[i]==2)
        {
            da[i]=1;db[i]=1;
            ans=min(ans,min(i,24-i*2));
        }
        else if(d[i]==1)
        {
            for(int j=i-1;j>=0;j--)
            {
                if(db[j]==1)
                {
                    da[i]=1;
                    for(;j>=0;j--)if(da[j]==1){ans=min(ans,i-j);break;}
                    am=i;
                    break;
                }
                if(da[j]==1)
                {
                    db[i]=1;
                    for(;j>=0;j--)if(db[j]==1){ans=min(ans,i-j);break;}
                    bm=i;
                    break;
                }
            }
        }
    }
    if(d[12]==1)
    {
        da[12]=1;db[12]=1;
        ans=min(ans,12-max(am,bm));
    }
    else ans=min(ans,24-am-bm);

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3612
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
div = int(1e+9+7)
n,k = map(int,input().split())
for i in range(1,k+1):
    if i > n-k+1:
        print(0)
    else:
        print((cmb(n-k+1,i)*cmb(k-1,i-1))%div)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

long long int f[100001];
int Mod = 1e9 + 7;

void init()
{
	f[0] = 1;
	for (int i = 1; i <= 100000; i++)
	{
		f[i] = i*f[i - 1];
		f[i] %= Mod;
	}
}

int main(void)
{
	int n;

	init();

	cin >> n;

	cout << f[n] << '\n';

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
    char ch;x=0;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
    for(x=numb;isdigit(ch=getchar());x=x*10+numb);(fl==true)&&(x=-x);}
template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');}
template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Modulo{
const int mod=998244353;
il int ad(int x,int y){return x+y>=mod?x+y-mod:x+y;}
il int sub(int x,int y){return ad(x,mod-y);}
il int mul(int x,int y){return (ll)x*y%mod;}
il void inc(int &x,int y){x=ad(x,y);}
il void inc2(int &x,int y){x=mul(x,y);}
il int qm(int x,int y=mod-2){int ret=1;while(y){if(y&1) ret=mul(x,ret);x=mul(x,x);y>>=1;}return ret;}
template<class ...Args>il int ad(const int a,const int b,const Args &...args) {return ad(ad(a,b),args...);}
template<class ...Args>il int mul(const int a,const int b,const Args &...args) {return mul(mul(a,b),args...);}
}
using namespace Modulo;
namespace Miracle{
const int N=1e6+5;
int n,m; 
int jie[N],inv[N];
int C(int n,int m){
	return mul(jie[n],inv[m],inv[n-m]);
}
int main(){
    rd(n);rd(m);
    jie[0]=1;
    int lim=2*max(n,m);
    for(reg i=1;i<=lim;++i) jie[i]=mul(jie[i-1],i);
	inv[lim]=qm(jie[lim]);
	for(reg i=lim-1;i>=0;--i) inv[i]=mul(inv[i+1],i+1);
	int d=min(n,m);
	int sum=0;
	for(reg i=1;i<=d;++i){
		inc(sum,mul(C(2*i,i),C(n+m-2*i,n-i)));
	}
	inc2(sum,qm(2));
	inc(sum,mul(max(n,m),C(n+m,n)));
	int ans=mul(sum,qm(C(n+m,n)));
	cout<<ans;
	return 0;
}

}
signed main(){
    Miracle::main();
    return 0;
}

/*
   Author: *Miracle*
*/

Measured memory_bytes: 8064
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a, b;
  cin >> a >> b;

  int ans = 0;
  if(a < b){
    ans += b;
    --b;
  }
  else{
    ans += a;
    --a;
  }
  ans += max(a, b);

  cout << ans << endl;

  return 0;
}


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

int main()
{
  string s;
  cin >> s;
  for (ll i = 0; i < (ll)s.length(); i++)
  {
    cout << "x";
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		UL A, B; cin >> A >> B;
		vector<UL> P(N); rep(i, N) cin >> P[i];
		UL S[3] = {};
		rep(i, N) {
			if (P[i] <= A) S[0]++;
			else if (P[i] > B) S[2]++;
			else S[1]++;
		}
		UL ans = min(S[0], min(S[1], S[2]));
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll n, c = 0;
    cin >> n;
    vector<int> a;
    ll b = 2;
    while (n) {
    	if (n % b) {
    		a.push_back(1);
    		if (c % 2 != 0) n += b / 2;
    		else n -= b / 2;
		}
    	else a.push_back(0);
    	b *= 2;
    	c++;
	}
	reverse(a.begin(), a.end());
	if (a.size() == 0) cout << 0; 
    for (int i = 0 ; i < a.size() ; i++) cout << a[i];
}
/*
*/


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;
ll mypow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return mypow(x*x%m, n / 2, m);
	}
	else {
		return x * mypow(x, n - 1, m) % m;
	}
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
///////////////////////////////////////
int ans[2010];
int d[2010];
int main() {
	int N, X, Y; cin >> N >> X >> Y;
	X--, Y--;
	vector<int>G[2010];
	for (int i = 0; i < N - 1; ++i) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);
	}
	G[X].push_back(Y);
	G[Y].push_back(X);
	REP(i, 2010)ans[i] = 0;
	REP(i, N) {
		REP(j, N) {
			d[j] = INF;
		}
		d[i] = 0;
		priority_queue<pii, vector<pii>, greater<pii>>que;
		que.push({ 0,i });
		while (!que.empty()) {
			pii p = que.top(); que.pop();
			int v = p.second;
			if (d[v] < p.first)continue;
			for (int j = 0; j < G[v].size(); ++j) {
				if (d[G[v][j]] > d[v] + 1) {
					d[G[v][j]] = d[v] + 1;
					que.push({ d[G[v][j]],G[v][j] });
				}
			}
		}
		for (int j = 0; j < N ; ++j) {
			if (i == j)continue;
			ans[d[j]]++;
		}
	}
	for (int i = 1; i < N; ++i) {
		cout << ans[i]/2 << endl;
	}
	return 0;
}


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

int main(){
    int n,d,x,a[100];
    cin >> n;
    cin >> d >> x;
    for(int i=0; i<n; i++)
    cin >> a[i];
    int ans=x+n;
    for(int i=0; i<n; i++){
        int ate=(d-1)/a[i];
        ans+=ate;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	int[] dx = { 1, 0, -1, 0 };
	int[] dy = { 0, 1, 0, -1 };
	int H, W, C;
	int[][] map;
	int[][] field;
	boolean visit[][];
	int max, cnt;

	void run() {
		for (;;) {
			H = sc.nextInt();
			W = sc.nextInt();
			C = sc.nextInt();
			if ((H | W | C) == 0) {
				return;
			}
			map = new int[H][W];
			field = new int[H][W];
			max = 0;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					map[i][j] = sc.nextInt();
				}
			}
			int[] parm = new int[5];
			makePerm(0, parm);
			System.out.println(max);
		}
	}

	void makePerm(int n, int[] parm) {
		if (n == 4) {
			parm[n] = C;
			solve(parm);
			return;
		}
		for (int i = 1; i <= 6; i++) {
			if (n == 3 && i == C) {
				continue;
			}
			parm[n] = i;
			makePerm(n + 1, parm);
		}
	}

	void solve(int parm[]) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				field[i][j] = map[i][j];
			}
		}
		for (int i = 0; i < 5; i++) {
			visit = new boolean[H][W];
			int first = field[0][0];
			dfs(parm[i], first, visit, 0, 0);
		}
		visit = new boolean[H][W];
		if (field[0][0] == C && !visit[0][0]) {
			cnt = 1;
			cntMap(field, visit, 0, 0);
			max = Math.max(max, cnt);
		}
	}

	void dfs(int num, int first, boolean[][] visit, int h, int w) {
		field[h][w] = num;
		visit[h][w] = true;
		for (int i = 0; i < 4; i++) {
			int nh = h + dy[i];
			int nw = w + dx[i];
			if (nh >= 0 && nh < H && nw >= 0 && nw < W && !visit[nh][nw]
					&& field[nh][nw] == first) {
				dfs(num, first, visit, nh, nw);
			}
		}
	}

	void cntMap(int[][] field, boolean[][] visitf, int h, int w) {
		visit[h][w] = true;
		for (int i = 0; i < 4; i++) {
			int nh = h + dy[i];
			int nw = w + dx[i];
			if (nh >= 0 && nh < H && nw >= 0 && nw < W && !visit[nh][nw]
					&& field[nh][nw] == C) {
				cnt++;
				cntMap(field, visit, nh, nw);
			}
		}
	}

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

Measured memory_bytes: 158140
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 200010;

typedef long long ll;

char s[maxn];
int n, cnt;
ll ans = 0;

int main() {
	scanf("%s", s+1);
	n = int (strlen(s+1));
	for (int i = 1; i <= n; i++) {
		if (s[i] == 'A') {
			++ cnt;
		} else if (s[i] == 'B') {
			if (i+1 <= n && s[i+1] == 'C') {
				ans += cnt;
				++ i;
			} else cnt = 0;
		} else cnt = 0;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
N = int(input())

cnt=0
if N<4:
    print('No')
    cnt=1
else:
    t=int(N/7)
    for i in range(0,t+1):
        if (N-(7*i))%4==0:
            print('Yes')
            cnt=1
            break
        else:
            pass
    if cnt==0:
        print('No')

Measured memory_bytes: 38384
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

fn main() {
    input!{
        d: usize,
        g: u64,
        pc_a: [[u64; 2]; d],
    }

    let mut answer = 1000000;
    'a: for flag in 0..(1 << d) {
        let mut score = 0;
        let mut count = 0;

        for i in 0..d {
            if flag & (1 << i) != 0 {
                let p = pc_a[i][0];
                let c = pc_a[i][1];
                score += 100 * (i as u64 + 1) * p + c;
                count += p;
            }
        }


        if count >= answer {
            continue;
        } else if score >= g {
            answer = count;
            continue;
        }


        'b: for i in (0..d).rev() {
            if flag & (1 << i) == 0 {

                let p = pc_a[i][0];
                let max_additional_score = 100 * (i as u64 + 1) * (p - 1);
                if max_additional_score + score < g {
                    continue 'a;
                }

                let need_score = g - score;
                count += if need_score % (100 * (i as u64 + 1)) == 0 {
                    need_score / (100 * (i as u64 + 1))
                } else {
                    need_score / (100 * (i as u64 + 1)) + 1
                };

                break 'b;
            }
        }

        if count < answer {
            answer = count;
            continue;
        }
    }

    println!("{}", answer);
}


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

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int total = 0;
    rep(i, n-1) {
        if (s[i] == s[i+1]) total++;
    }
    cout << min(n-1, total+(2*k)) << endl;
    return 0;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val ss = (0 until m).map { readLine()!!.split(' ').map { it.toInt() }.drop(1) }
    val ps = readLine()!!.split(' ').map { it.toInt() }

    var ans = 0

    for (i in 0 until Math.pow(2.0, n.toDouble()).toInt()) {
        ss.indices
                .all { j -> ss[j].count { i shr (it - 1) and 1 == 1 } % 2 == ps[j] }
                .let { if (it) ans++ }
    }

    println(ans)
}


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

#define ll long long 

int main()
{
    ll n,w;
    cin>>n>>w;
    vector< pair<ll,ll> > v;
    for(int i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());
    ll dp[n][w+1];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=w;j++)
         dp[i][j]=0;
    }
    for(ll i=0;i<n;i++)
    {
        ll x=v[i].first;
        for(ll j=0;j<=w;j++)
        {
            if(i==0)
            {
                if((j>=x))
                 dp[i][j]=v[i].second;
                 else
                  dp[i][j]=0;
            }
            else if(j<x)
             dp[i][j]=dp[i-1][j];
             else
             {
                 dp[i][j]=max(dp[i-1][j],(v[i].second+dp[i-1][j-x]));
             }
        }
    }
    /*for(ll i=0;i<=w;i++)
     cout<<dp[n-1][i]<<" ";
     cout<<"\n";*/
    cout<<dp[n-1][w]<<"\n";
    return 0;
}

Measured memory_bytes: 78336
#include<stdio.h>
#include<string.h>
 
int main(void){
  int n;
  int i,j;
  scanf("%d",&n);
  char s[n+1][11];
  int p[n+1];
  int num[n+1];
  for(i=0;i<n;i++){
    scanf("%s",s[i]);
    scanf("%d",&p[i]);
    num[i]=i;
  }
  int it;
  char st[11];
  for(i=n-1;i>0;i--){
    for(j=0;j<i;j++){
      if( (strcmp(s[i],s[j])<0) || ( (strcmp(s[i],s[j])==0) && (p[i]>p[j] )) ){
        strcpy(st,s[i]);
        strcpy(s[i],s[j]);
        strcpy(s[j],st);
        it = p[i];
        p[i] = p[j];
        p[j] = it;
        it = num[i];
        num[i] = num[j];
        num[j] = it;
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d\n",num[i]+1);
  }
}

Measured memory_bytes: 128
from itertools import *
g=lambda a,x,b:a+b if x=='+'else a-b if x=='-'else a*b
def f(s):
 for a,b,c,d in permutations(s):
  for x,y,z in product('+-*',repeat=3):
   if g(g(a,x,b),y,g(c,z,d))==10:return f"(({a} {x} {b}) {y} ({c} {z} {d}))"
   if g(g(a,x,g(b,y,c)),z,d)==10:return f"(({a} {x} ({b} {y} {c})) {z} {d})"
 else:return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))


Measured memory_bytes: 5656
#include<stdio.h>
struct change{
	char c;
	char newC;
};
struct change c[1000];
int main(){
	int n,i,j,k,m,count;
	char str,tc;
	while(1){
		scanf("%d",&m);
		if(!m)break;
		for(i=0;i<m;i++){
			count=0;
			while(1){
				scanf("%c",&str);
				if(('a'<= str && str <='z') || ('A'<= str && str <='Z')||('0'<= str && str <='9')){
					if(count==0){
						c[i].c=str;count++;
					}
					else{
						c[i].newC=str;
						break;
					}
				}
			}
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			while(1){
				scanf("%c",&str);
				if(('a'<= str && str <='z') || ('A'<= str && str <='Z')||('0'<= str && str <='9')){
					tc=str;
					break;
				}
			}
			for(j=0;j<m;j++)
				if(c[j].c==tc){tc=c[j].newC;break;}
			printf("%c",tc);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 384
from collections import deque
h, w =  map(int, input().split())
s = [[i for i in list(str(input()))] for i in range(h)]
INF = 10**9
dp = [[INF for _ in range(w)] for _ in range(h)]


if s[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0
que = deque()
que.append((0, 0))
is_checked = [[False for _ in range(w)] for _ in range(h)]
while len(que) > 0:
    y, x = que.popleft()
    if y + 1 < h:
        if s[y][x] != s[y+1][x]:
            dp[y+1][x] = min(dp[y+1][x], dp[y][x]+1)
        else:
            dp[y+1][x] = min(dp[y+1][x], dp[y][x])
        if not is_checked[y+1][x]:
            que.append((y+1, x))
            is_checked[y+1][x] = True
    if x + 1 < w:
        if s[y][x] != s[y][x+1]:
            dp[y][x+1] = min(dp[y][x+1], dp[y][x]+1)
        else:
            dp[y][x+1] = min(dp[y][x+1], dp[y][x])
        if not is_checked[y][x+1]:
            que.append((y, x+1))
            is_checked[y][x+1] = True
if s[h-1][w-1] == "#":
    dp[h-1][w-1]+=1
print(dp[h-1][w-1]//2)

Measured memory_bytes: 45804
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(string S) {
    ll n = S.size(), len_sub;
    int ans = 0;
    string sub;
    rep(i, n) {
        for (int j = 1; j <= n - i; j++) {
            sub = S.substr(i, j);
            len_sub = sub.size();
            for (int k = 0; k < len_sub; k++) {
                if (sub[k] == 'A' || sub[k] == 'C' || sub[k] == 'G' || sub[k] == 'T') {
                    if (ans < k+1) {ans = k+1;}
                } else  {
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 3604
def crane_and_turtle():
    condition = input()
    num_str = condition.split()
    X = int(num_str[0])
    Y = int(num_str[1])
    
    a = 0
    b = X
    
    for i in range(X+1):
        if 2*a + 4*b == Y:
            print('Yes')
            return
        a += 1
        b -= 1
    
    print('No')
    return

crane_and_turtle()

Measured memory_bytes: 9192
a, b = map(int, input().split())

eight_min = a / 0.08
eight_max = (a+1) / 0.08
ten_min = b / 0.1
ten_max = (b + 1) / 0.1

ans = False
for p in range(int(eight_min), int(eight_max)):
    if eight_min <= p < eight_max and ten_min <= p < ten_max:
        ans = p
        break


if ans:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 38384
#include <stdio.h>

int main()
{
  int a,b,ab,x,y,ans;

  scanf("%d%d%d%d%d",&a,&b,&ab,&x,&y);

  if(x < y)
  {
    int tmp = x; x=y; y=tmp;
        tmp = a; a=b; b=tmp;
  }

  if( a > ab*2 )
    ans = ab*x*2;
  else  if(a+b>ab*2)
    ans = a*(x-y) + ab*y*2;
  else
    ans = a*x + b*y;

  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long int a,b;
    cin>>a>>b;
    if(a<b){
        if(a*b>=0){
            cout<<abs(b-a)<<endl;
        }else{
            cout<<1+abs(a+b)<<endl;
        }
    }else{
        if(a*b>0){
            cout<<2+abs(a-b)<<endl;
        }else{
            cout<<1+abs(a+b)<<endl;
        }
    }
}


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

int main(){
  int n,m;
  cin>>n>>m;
  string a(n,'0');

vector<int>s(m);
vector<char>c(m);
  
for(int i=0;i<m;i++){
  cin>>s.at(i)>>c.at(i);
}
 
bool b=true;
bool d=true;
  
for(int i=0;i<m;i++){
  for(int j=i;j<m;j++){
    if((s.at(i)==s.at(j))&&(c.at(i)!=c.at(j)))b=false;
    if((s.at(i)==1)&&(c.at(i)=='0'))d=false;
  }
}
if(b&&d&&(n!=1)){
  for(int i=0;i<m;i++){
    a.at(s.at(i)-1)=c.at(i);
  }
	if(a.at(0)=='0')a.at(0)='1';
  cout<<a<<endl;
}
else if(b&&(n==1)){
  if(m!=0){
  a.at(0)=c.at(0);
  cout<<a<<endl;
  }else cout<<0<<endl;
}
else cout<<"-1"<<endl;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    int x, a, b;
	cin >> x >> a >> b;

	if(b - a >= x + 1)
		cout << "dangerous" << endl;
	else if(b <= a)
		cout << "delicious" << endl;
	else
		cout << "safe" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int m[16][8],i,j,l,p,s,r;
	while(scanf("%d",&l) , l != 0){
		s = 0;
		for(i = 0;i <= 15;i++){
			for(j = 0;j <= 7;j++){
				m[i][j] = 0;
			}
		}
		for(i = l;i >= 1;i--){
			scanf("%d%d%d%d%d",&m[i][1],&m[i][2],&m[i][3],&m[i][4],&m[i][5]);
		}
		p = 1;
		while(p != 0){
			p = 0;
			for(i = 1;i <= l;i++){
				if(m[i][1] != 0 && m[i][1] == m[i][2] && m[i][2] == m[i][3] && m[i][3] == m[i][4] && m[i][4] == m[i][5]){
					p = 1;
					s+=((m[i][1]) * 5);
					m[i][1] = 0;m[i][2] = 0;m[i][3] = 0;m[i][4] = 0;m[i][5] = 0;
				}
				else if(m[i][1] != 0 && m[i][1] == m[i][2] && m[i][2] == m[i][3] && m[i][3] == m[i][4]){
					p = 1;
					s+=((m[i][1]) * 4);
					m[i][1] = 0;m[i][2] = 0;m[i][3] = 0;m[i][4] = 0;
				}
				else if(m[i][2] != 0 && m[i][2] == m[i][3] && m[i][3] == m[i][4] && m[i][4] == m[i][5]){
					p = 1;
					s+=((m[i][2]) * 4);
					m[i][2] = 0;m[i][3] = 0;m[i][4] = 0;m[i][5] = 0;
				}
				else if(m[i][1] != 0 && m[i][1] == m[i][2] && m[i][2] == m[i][3]){
					p = 1;
					s+=((m[i][1]) * 3);
					m[i][1] = 0;m[i][2] = 0;m[i][3] = 0;
				}
				else if(m[i][2] != 0 && m[i][2] == m[i][3] && m[i][3] == m[i][4]){
					p = 1;
					s+=((m[i][2]) * 3);
					m[i][2] = 0;m[i][3] = 0;m[i][4] = 0;
				}
				else if(m[i][3] != 0 && m[i][3] == m[i][4] && m[i][4] == m[i][5]){
					p = 1;
					s+=((m[i][3]) * 3);
					m[i][3] = 0;m[i][4] = 0;m[i][5] = 0;
				}
			}
			
			for(j = 1;j <= 5;j++){
				r = 1;
				for(i = 1;i <= 10;i++){
					if(m[i][j] != 0){
						m[r][j] = m[i][j];
						r++;
					}
				}
				for(i = r;i <= 10;i++){
					m[i][j] = 0;
				}
			}
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define rep1(i,N) for(int i=1;i<=(int)N;i++)
#define pb push_back
#define all(c) c.begin(),c.end()
#define show(x) cout<<#x<<" "<<x<<endl
using namespace std;
typedef unsigned long long ll;
typedef pair<ll,ll> P;
ll rs[2][26];
set<P> st;
int main(){
	srand(unsigned(time(NULL)));
	rep(t,2) rep(i,26) rs[t][i]=rand();
	string a,b;
	cin>>a>>b;
	int A=a.size(),B=b.size();
	for(int l=min(A,B);l>0;l--){
		st.clear();
		ll v[2]={};
		rep(t,2) rep(i,l) v[t]+=rs[t][a[i]-'a'];
		st.insert(P(v[0],v[1]));
		rep(i,A-l){
			rep(t,2){
				v[t]-=rs[t][a[i]-'a'];
				v[t]+=rs[t][a[i+l]-'a'];
			}
			st.insert(P(v[0],v[1]));
		}

		bool found=0;
		v[0]=v[1]=0;
		rep(t,2) rep(i,l) v[t]+=rs[t][b[i]-'a'];
		if(st.find(P(v[0],v[1]))!=st.end()) found=1;
		rep(i,B-l){
			rep(t,2){
				v[t]-=rs[t][b[i]-'a'];
				v[t]+=rs[t][b[i+l]-'a'];
			}
			if(st.find(P(v[0],v[1]))!=st.end()) found=1;
		}
		if(found){
			cout<<l<<endl;
			return 0;
		}
	}
	puts("0");
}

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

int main(){
  lld a;
  lld b;
  cin>>a>>b;
  // scanf("%ll %lld",&a,&b);
  ll z=a*b;
  cout<<z<<endl;
  // z=a*z;
  // cout<<z<<endl;
  // z=z/100;
  // cout<<z<<endl;
  
  
  return 0;
    
}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 100002;

int n, m, indegree[maxn];
vector<vector<int> > g;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;

	g = vector<vector<int> >(n+1);
	for (int i = 1; i < n + m; ++i) {
		int u, v;
		cin >> u >> v;

		g[u].push_back(v);
		++indegree[v];
	}
	
	vector<int> p(n+1, -1);
	queue<int> qu;

	for (int i = 1; i <= n; ++i)
		if (indegree[i] == 0) {
			// indegree[i] = -1;

			p[i] = 0;
			qu.push(i);
			break;
		}

	while (!qu.empty()) {
		int u = qu.front();
		qu.pop();

		for (int i = 0; i < g[u].size(); ++i) {
			int v = g[u][i];
			--indegree[v];
			if (indegree[v] == 0) {
				p[v] = u;
				qu.push(v);
			}
		}
	}

	for (int i = 1; i <= n; ++i)
		cout << p[i] << endl;

	return 0;
}

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

int main() {
    string a, b, c; cin >> a >> b >> c;
    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
use std::cmp::min;
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<usize>();
    let s = read::<String>();
    let s1: Vec<char> = s.chars().collect();

    let answer = solve(n, s, &s1);
    println!("{}", answer);
}

fn solve(n: usize, s: String, s1: &[char]) -> usize {
    let mut v_max = 0;
    for i in 0..n {
        let s2 = &s1[i..n];
        let z = z_algo(s2.len(), s2);
        //println!("z: {:?}", z);
        let tmp = get_max(z.len(), &z);
        //println!("tmp: {}", tmp);
        if tmp > v_max {
            v_max = tmp;
        }
        if v_max > (n - i - 1) / 2 {
            break;
        }
    }
    return v_max;
}

fn z_algo(n: usize, s: &[char]) -> Vec<usize> {
    //println!("*** {}, {:?}", n, s);
    let mut z: Vec<usize> = vec![0; n];
    let mut l: usize = 0;
    let mut r: usize = 0;
    for i in 1..n {
        //println!("{}", i);
        if i >= r {
            //println!("   A");
            l = i;
            r = i;
            while r < n && s[r] == s[r - l] {
                r += 1;
            }
            z[i] = r - l;
        //r -= 1;
        } else {
            let k = i - l;
            if z[k] < r - i {
                //println!("   B1");
                z[i] = z[k];
            } else {
                //println!("   B2");
                l = i;
                while r < n && s[r] == s[r - l] {
                    r += 1;
                }
                z[i] = r - l;
            }
        }
    }
    // println!("{:?}", z);
    return z;
}

/**
 * l1 + len <= l2
 *  --> z[i] <= l1
 */
fn get_max(n: usize, z: &[usize]) -> usize {
    let mut v_max: usize = 0;
    for i in 1..n {
        let tmp = min(z[i], i);
        if tmp > v_max {
            v_max = tmp;
        }
    }
    return v_max;
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, t;
	cin >> x >> t;
	int ans = max(x-t, 0);
	cout << ans << endl;
	return 0;
}

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

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

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:

const int limit = 100010;
vector<int> graph[limit];

void add_edge(int from, int to) {
	graph[from].push_back(to);
	graph[to].push_back(from);
}

ll a[limit];
bool visited[limit];
vector<ll> comp[limit];

void dfs(int v, int p, int s) {
	visited[v] = true;
	comp[s].push_back(a[v]);
	for (auto &v2 : graph[v]) {
		if (v2 == p) continue;
		dfs(v2, v, s);
	}
}


int main(void) {
	int n, m;
	cin >> n >> m;
	rep(i, n) cin >> a[i];

	rep(i, m) {
		int s, t;
		cin >> s >> t;
		add_edge(s , t);
	}

	int all = 0;
	rep(v, n) {
		if (visited[v]) continue;
		dfs(v, -1, v);
		all++;
	}

	if (all == 1) {
		puts("0");
		return 0;
	}

	if (2 * all - 2 > n) {
		puts("Impossible");
		return 0;
	}

	ll ans = 0LL;
	vector<ll> rest;
	rep(v, n) {
		if (comp[v].size() == 0) continue;
		sort(begin(comp[v]), end(comp[v]));
		const int sz = comp[v].size();
		rep(i, sz) {
			if (i == 0)
				ans += comp[v][i];
			else
				rest.push_back(comp[v][i]);
		}
	}

	sort(begin(rest), end(rest));
	rep(i, all - 2) ans += rest[i];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 11256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
K = 0
for i in range(N):
    A = list(map(int, input().split()))
    x = 0
    for j in range(M):
        x += B[j]*A[j]
    if x > -1*C:
        K += 1

print(K)

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, M, C[16], X[int(2e4 + 5)];
ll DP[int(2e4 + 5)][256];

int Solve(){
  fill((ll*)DP, (ll*)(DP + N + 1), 1e18);
  DP[0][128] = 0;

  for (int i = 0; i < M; i++) cin >> C[i];
  for (int i = 1; i <= N; i++) cin >> X[i];

  for (int i = 1; i <= N; i++){
    for (int j = 0; j < 256; j++){
      for (int k = 0; k < M; k++){
        int Y = j + C[k];
        if (Y < 0) Y = 0;
        if (Y > 255) Y = 255;
        DP[i][Y] = min(DP[i][Y], DP[i - 1][j] + (X[i] - Y) * (X[i] - Y));
      }
    }
  }
  
  ll ans = 1e18;
  for (int j = 0; j < 256; j++) ans = min(ans, DP[N][j]);
  cout << ans << endl;
  
  return 0;
}

int main(){
  while (cin >> N >> M){
    if (N == 0 && M == 0) return 0;
    Solve();
  }
  return 0;
}



Measured memory_bytes: 43176
#include<stdio.h>
int main(){
int m[11],i,j,work;
for(i=0;i<10;i++){
 scanf("%d",&m[i]);
}
for(i=0;i<10;i++){
 for(j=0;j<10;j++){
  if(m[i]>m[j]){
   work=m[i]; m[i]=m[j]; m[j]=work;
   }
  }
 }
for(i=0;i<3;i++){
 printf("%d\n",m[i]);
}
return 0; }

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	cout << (n / 2)*min(8 * q, min(h * 4, min(s * 2, d))) + (n % 2)*min(4 * q, min(2 * h, s)) << endl;
	getchar(); getchar();
}

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

int main() {
  int N;
  cin >> N;
  set<string> se;
  
  int i = 0;
  while(i < N) {
    string S;
    cin >> S;
    se.insert(S);
    i++;
  }
  
  cout << se.size() << endl;
}

Measured memory_bytes: 19136
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let ws = reads int
    let s12 = List.sum ws
    let s1s = List.scan (+) 0 ws |> List.tail
    let ss = List.map (fun s1 -> let s2 = s12 - s1 in abs (s1 - s2)) s1s
    printfn "%i" (List.min ss)
    0

Measured memory_bytes: 14172