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

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;

const int N = 100010;

int cnt[N][2];

void solve() {
    memset(cnt, 0, sizeof(cnt));
    ll ans = 0;
    int n;
    scanf("%d", &n);
    for (int rep = 0; rep < n * 2; ++rep) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (y < 1) {
            ans += 1 - y;
            y = 1;
        }
        if (y > 2) {
            ans += y - 2;
            y = 2;
        }
        if (x < 1) {
            ans += 1 - x;
            x = 1;
        }
        if (x > n) {
            ans += x - n;
            x = n;
        }
        ++cnt[x][y - 1];
    }
    for (int i = 1; i <= n; ++i) {
#define A cnt[i][0]
#define B cnt[i][1]
        --A;
        --B;
        if (A > 0 && B > 0) {
            ans += A + B;
            cnt[i + 1][0] += A;
            cnt[i + 1][1] += B;
        } else if (A <= 0 && B <= 0) {
            ans -= A + B;
            cnt[i + 1][0] += A;
            cnt[i + 1][1] += B;
        } else if (A <= 0 && B > 0) {
            if (-A > B) {
                ans += B;
                A += B;
                ans += abs(A);
                cnt[i + 1][0] += A;
            } else {
                ans += -A;
                B += A;
                ans += abs(B);
                cnt[i + 1][1] += B;
            }
        } else if (A > 0 && B <= 0) {
            if (A > -B) {
                ans += -B;
                A += B;
                ans += abs(A);
                cnt[i + 1][0] += A;
            } else {
                ans += A;
                B += A;
                ans += abs(B);
                cnt[i + 1][1] += B;
            }
        }
    }
    printf("%lld\n", ans);
}

int main() {
    solve();
}


Measured memory_bytes: 4004
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var cin = GetIntArray().OrderBy(s => s).ToArray();
            var ans = YESNO(cin[0] == 5 && cin[1] == 5 && cin[2] == 7);
            Console.WriteLine(ans);


            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

Measured memory_bytes: 11348
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
/*#define fast ios_base::sync_with_stdio(0); cin.tie(0)*/
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const double pi = acos(-1);
typedef long long ll;
int main()
{
	//fast;
	
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	a+=b;
	c+=d;
	if(a>c)cout<<"Left";
	else if(c>a)cout<<"Right";
	else cout<<"Balanced";
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 1;
  while(2 * ans <= n) {
    ans *= 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var N, A, B, C int
var l []int

func main() {
	fmt.Scan(&N, &A, &B, &C)
	l = make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&l[i])
	}
	fmt.Println(dfs(0, 0, 0, 0))

}
func dfs(i, a, b, c int) int {
	if i == N {
		if a == 0 || b == 0 || c == 0 {
			return math.MaxInt32
		}
		return Abs(a-A) + Abs(b-B) + Abs(c-C)
	}

	r := dfs(i+1, a, b, c)
	var wa, wb, wc int
	if a > 0 {
		wa = 10
	}
	if b > 0 {
		wb = 10
	}
	if c > 0 {
		wc = 10
	}
	r = Min(r, dfs(i+1, a+l[i], b, c)+wa)
	r = Min(r, dfs(i+1, a, b+l[i], c)+wb)
	r = Min(r, dfs(i+1, a, b, c+l[i])+wc)
	return r
}

func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


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


Measured memory_bytes: 512
#include <cstdio>
#include <vector>

using namespace std;

class Edge{
public:
	int from,to,cost;
	Edge(int f,int t,int c){
		from = f;
		to = t;
		cost = c;
	}
	void swap(){
		int a = from;
		from = to;
		to = a;
	}
};

vector<Edge> edge;

int n,k;
const int INF = 999999999;


int solve(int s,int g){
	int* d = new int[n + 1];
	for(int i=0;i<=n;i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	while(1){
		bool f = true;
		vector<Edge>::iterator it;
		for(it = edge.begin();it<edge.end();it++){
			if(d[it->from] != INF){
				if(d[it->to] > d[it->from] + it->cost){
					d[it->to] = d[it->from] + it->cost;
					f = false;
				} 
			}
		}
		if(f){
			break;
		}
	}
	int ans = d[g];
	if(ans == INF){ans = -1;}
	delete[] d;
	return ans;
}

int main(){
	int a,b,c,d;
	while(scanf("%d %d",&n,&k) && (n || k) ){
		edge.clear();
		for(int i=0;i<k;i++){
			scanf("%d",&a);
			if(a == 1){
				scanf("%d %d %d",&b,&c,&d);
				edge.push_back( Edge(b,c,d) );
				edge.push_back( Edge(c,b,d) );
			}else{
				scanf("%d %d",&b,&c);
				printf("%d\n",solve(b,c));
			}
		}
	}
}

Measured memory_bytes: 868
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e5+7;
ll dp[maxn][3];
int a[maxn];
string op[maxn];
int n;
ll dfs(int x,int cc)
{
	if(x==n+1) return 0;
	ll &ret=dp[x][cc];
	if(ret!=-1) return ret;
	ret=0;
	int sgn=(cc==1?-1:1);
	if(op[x-1][0]=='+')
	{
		ret=max(ret,dfs(x+1,cc)+sgn*a[x]);
		if(cc) ret=max(ret,dfs(x+1,cc-1)+sgn*a[x]);
	}
	else{
		sgn*=-1;
		ret=max(ret,dfs(x+1,cc)+sgn*a[x]);
		if(cc<2) ret=max(ret,dfs(x+1,cc+1)+sgn*a[x]);
	}
	return ret;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(i!=n) cin>>op[i];
	}
	op[0]="+";
	cout<<dfs(1,0)<<endl;
}

Measured memory_bytes: 14720
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

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

  if (n % (2 * d + 1) == 0) {
    cout << n / (2 * d + 1) << endl;
    return 0;
  } else {
    cout << n / (2 * d + 1) + 1 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 200001;
ll ans = 0;
int arr[mxN];
int n;
ll L;
int psum[mxN];
void solve() {
    arr[n] = L;
    ll curr = arr[n-1];
    ans = max(ans, curr);
    int lst = n;
    owo(i, 0, n-1) {
        int at = n-2-i;
        //cout<<curr<<" "<<arr[at]<<" "<<arr[lst]<<" "<<i<<"\n";
        if(i&1) {
            curr+=arr[at] + L - arr[lst];
            curr-= arr[lst-1] - arr[at];
        }else {
            lst--;
            curr+=arr[at] + L -arr[lst];
            curr-= arr[lst] - arr[at];
        }
        ans = max(ans, curr);
    }
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>L>>n;
    owo(i, 0, n) {
        cin>>arr[i];
    }
    n++;
    arr[n-1] = 0;
    sort(arr, arr+n);
    solve();
    owo(i, 0, n) {
        arr[i] = L-arr[i];
        if(arr[i]==L)arr[i] = 0;
    }
    //cout<<ans<<"\n";
    sort(arr, arr+n);
    solve();
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4396
n = gets.chomp.to_i
t_a = gets.chomp
a = t_a.split(' ').map{|v| v.to_i}

t_b = gets.chomp
b = t_b.split(' ').map{|v| v.to_i}

t_c = gets.chomp
c = t_c.split(' ').map{|v| v.to_i}

### a = [3, 1, 2]
### b = [2, 5, 4]
### c = [3, 6]

result = 0
prev = 99
a.each do |v|
  result += b[v-1]

  if prev+1 == v-1
    result += c[prev]
  end

  prev = v-1
end

p result

Measured memory_bytes: 1788
import java.util.*;
import java.lang.*;
  
public class Main{
  public static void main(String[] args){
    Scanner stdIn=new Scanner(System.in);
    int a=stdIn.nextInt(), b=stdIn.nextInt();
    int S=a*b, C=2*a+2*b;
    System.out.println(S+" "+C);
  }
}


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

int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int flag;
    int cnt = 0;
    map<int,int> mp;
    sort(l.begin(),l.end());
    for(int i=0; i<n-2; i++){
        for(int j =i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                flag = l[k] - l[j] - l[i];
                //cout << l[i] << " " << l[j] << " " << l[k] << " " << flag << endl;
                if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i]) continue;
                if(flag < 0){
                    cnt++;
                    
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  if (a == 000) {
    cout << 0 << endl;
  }
  else if (a == 001) {
    cout << 1 << endl;
  }
  else if (a == 10) {
    cout << 1 << endl;
  }
  else if (a == 100) {
    cout << 1 << endl;
  }
  else if (a == 11) {
    cout << 2 << endl;
  }
  else if (a == 101) {
    cout << 2 << endl;
  }
  else if (a == 110) {
    cout << 2 << endl;
  }
  else if (a == 111) {
    cout << 3 << endl;
  }
}

Measured memory_bytes: 256
from collections import deque
n =int(input())
takahashi = 0
aoki = 0
ab = []
a = []
for i in range(n):
 tmp1,tmp2 = (int(i) for i in input().split())
 a.append([tmp1,tmp2])
 ab.append(tmp1+tmp2)
 aoki += tmp2
#a2 = sorted(a, key=lambda x: x[0])
#a3 = sorted(a, key=lambda x: x[1])
ab = sorted(ab,reverse = True)
start = 0
for i in range(n):
  if i%2 == 0:
    takahashi += ab[i]
  else:
    continue


print(takahashi-aoki)

Measured memory_bytes: 25284
def 解():
    iN = int(input())

    #これも解法を見て作った

    iK = int((2 * iN) ** 0.5)
    if 2 * iN != iK * (iK +1 ) :
        print("No")
    else:
        print("Yes")
        print(iK+1)
        aD = [ [0] * iK for _ in range(iK)]
        iMaxCol = 0
        iRow = 0
        iCol = 0
        for i in range(1,iN+1):
            aD[iRow][iCol] = i
            if iCol == iMaxCol:
                iMaxCol += 1
                iRow += 1
                iCol = 0
            else:
                iCol += 1

        oAns = []
        iRC = 0
        iStartCol = 0
        iStartRow = 0
        for i in range(iK):
            aTmp = []
            aTmp.append(iK)
            for j in range(iK):
                if iRC == 0:
                    aTmp.append(aD[iStartRow][j])
                else:
                    aTmp.append(aD[j][iStartCol])
                if j == iStartCol:
                    iRC = 1
            oAns.append(" ".join([str(_) for _ in aTmp]))
            iStartCol += 1
            iStartRow += 1
            iRC = 0
        aTmp = []
        aTmp.append(iK)
        for i in range(iK):
            aTmp.append(aD[i][i])

        oAns.append(" ".join([str(_) for _ in aTmp]))
        print("\n".join(oAns))
解()


Measured memory_bytes: 12404
N,M=map(int,input().split())
#brr=[list(map(int,input().split())) for i in range(M)]
arr=[[] for i in range(N)]

check=[0]*N
ans=[]

for i in range(M):
    a,b=map(int,input().split())
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

q=[]
cnt=0
for i in range(N):
    if check[i]==0:
        cnt+=1
    q.append(i)
    #print(cnt,q)
    while q:
        x=q.pop()
        if check[x]==0:
            check[x]=1
            for j in arr[x]:
                q.append(j)
        
print(cnt-1)

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

void chmin(int &a, int b) {
    a = std::min(a, b);
}

int p[50], t[50];
int dp[50][5];
const int INF = 1 << 30;
int main() {
    int N;
    while(1) {
        scanf("%d", &N);
        if(N == 0) return 0;

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

        for(int i=0; i<=N; i++) {
            for(int k=0; k<=3; k++) {
                dp[i][k] = INF;
            }
        }

        dp[0][0] = 0;
        for(int i=0; i<N; i++) {
            bool ok = false;
            for(int k=0; k<=3; k++) {
                if(dp[i][k] == INF) continue;
                int diff_p = abs(p[i+1] - p[i]);
                int diff_t = t[i+1] - t[i];

                // テァツ崢エテヲツ篠・テァツァツサテ・ツ仰陛」ツ?凖」ツつ?
                if(k < 3 && diff_p * (k+1) <= diff_t) {
                    chmin(dp[i+1][k+1], dp[i][k] + diff_p);
                    ok = true;
                }

                // テ、ツクツ?ヲツ猟ヲテ・ツョツカテ」ツ?ォテ・ツクツーテ」ツつ?
                if(p[i+1] + p[i] * (k+1) <= diff_t) {
                    chmin(dp[i+1][1], dp[i][k] + p[i] + p[i+1]);
                    ok = true;
                }
            }
            if(!ok) {
                printf("NG %d\n", i+1);
                break;
            }
        }

        int ans = INF;
        for(int i=0; i<=3; i++) chmin(ans, dp[N][i] + p[N]);
        if(ans < INF) printf("OK %d\n", ans);
    }
}

Measured memory_bytes: 2612
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define dl double
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL)
#define cases ll t; cin>>t; while(t--)
#define rep1(qq,pp) for(ll i=qq;i<pp;i++)
#define rep2(qqq,ppp) for(ll i=qqq;i>=ppp;i--)
#define nl "\n"
#define Y cout<<"YES\n"
#define N cout<<"NO\n"
//cout<<fixed<<setprecision(13);

int main(){
	faster;

	ll n,d,x,y,cnt=0;
	double ans;

	cin>>n>>d;
	
	while(n--){
	    cin>>x>>y;
	    
	    ans=x*x+y*y;
	    
	    ans=sqrt((dl)ans);
	    
	    if(ans<=d) cnt++;
	}
	
	cout<<cnt<<nl;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define MAXN 400005
#define LL long long
using namespace std;

int N;
string s;

vector<int> adj[26];
int pos[MAXN];

//
int fw[MAXN];

int lbt(int x){
	return x & (-x);
} 

int getsum(int x){
	int ans = 0;
	for(;x;x -= lbt(x)){
		ans += fw[x];
	}
	return ans;
}

void change(int x, int dv){
	for(;x<=2*N;x += lbt(x)){
		fw[x] += dv;
	}
}

//

int main(){
	
	cin>>s;
	N = s.length();
	s = "%" + s;
	
	for(int i=1;i<=N;i++){
		adj[s[i]-'a'].push_back(i);
	}
	
	int n1 = 0;
	for(int i=0;i<26;i++){
		if(adj[i].size()%2) ++n1;
		if(adj[i].size()==0) continue;
		
		int l = 0, r = adj[i].size()-1;
		while(l <= r){
			pos[adj[i][l]] = adj[i][r];
			l++;
			r--;
		}
	}

	if(n1 > 1){
		cout<<"-1"<<endl;
		return 0;
	}
	
	for(int i=1;i<=N;i++){
		//cout<<i<<" "<<pos[i]<<endl;
		change(i, +1);
	}
	
	LL ans = 0;
	int p1 = 0;
	for(int i=1;i<=N;i++){
		if(pos[i]==0) continue;
		if(pos[i]==i){
			change(N+1, +1);
			continue;
		} 
		++p1;
		ans += getsum(N+1) - getsum(pos[i]);
		//cout<<i<<" "<<getsum(N)<<" "<<getsum(pos[i])<<" "<<ans<<endl;
		change(pos[i], -1);
	}
	cout<<ans<<endl;
	return 0;
}
/*
babaabbbaaa
*/

Measured memory_bytes: 2876
# -*- coding:utf8 -*-

s = [s for s in input()]
pk = ['R', 'U', 'D']
pg = ['L', 'U', 'D']

ans = 'Yes'
for i, n in enumerate(s):
    if i % 2 == 0:
        if n in pk:
            continue
        else:
            ans = 'No'
            break
    else:
        if n in pg:
            continue
        else:
            ans = 'No'
            break
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int MAXN = 2e5 + 19;
int minY[MAXN]; std::vector<int> peg[MAXN];
int fa[MAXN];
struct Node{
	int x;
	bool operator>(const Node &b)const{return minY[x] > minY[b.x];}
};
int n, ans[MAXN];
struct Point{
	int x, y, id;
	bool operator<(const Point &b)const{return x < b.x;}
}p[MAXN];
std::priority_queue<Node, std::vector<Node>, std::greater<Node> > q;
int main(){
	std::scanf("%d", &n);
	for(int i = 1; i <= n; ++i) std::scanf("%d%d", &p[i].x, &p[i].y), p[i].id = i;
	std::sort(p + 1, p + 1 + n);
	for(int i = 1; i <= n; ++i) fa[i] = i, minY[i] = p[i].y, peg[i] = {i};
	for(int i = 1; i <= n; ++i){
		std::vector<int> ink;
		while(!q.empty() && minY[q.top().x] < p[i].y)
			ink.push_back(q.top().x), q.pop();
		while(ink.size() > 1){
			int a = ink.back(); ink.pop_back();
			int b = ink.back(); ink.pop_back();
			if(peg[a].size() < peg[b].size()) std::swap(a, b);
			for(int j : peg[b]) peg[a].push_back(j);
			minY[a] = std::min(minY[a], minY[b]), std::vector<int>().swap(peg[b]);
			ink.push_back(a);
		}
		if(ink.size()){
			fa[i] = ink[0];
			peg[ink[0]].push_back(i);
			minY[ink[0]] = std::min(minY[ink[0]], minY[i]);
			q.push({ink[0]}); std::vector<int>().swap(peg[i]);
		}
		else q.push({i});
	}
	for(int i = 1; i <= n; ++i)
		for(int j : peg[i]) ans[p[j].id] = peg[i].size();
	for(int i = 1; i <= n; ++i) std::printf("%d\n", ans[i]);
	return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	string s,t;
	cin >> s >> t;
	int g = __gcd(n,m);
	for(int i=0;i<g;i++){
		int x=n/g*i;
		int y=m/g*i;
		if(s[x]!=t[y]){
			cout << -1 <<'\n';
			return 0;
		}
	}
	cout <<(long long) n*m/g <<'\n';
	return 0;

}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <sstream>
#include <stdlib.h>
#include <math.h>
using namespace std;
 
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
#define pb push_back
#define foreach(it,con) for(auto it=con.begin();it!=con.end();it++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;



string judge(int* nums){
	map<int,int> count;
	FOR(i,1,14){
		count[i] = 0;
	}
	rep(i,5){
		count[nums[i]]++;
	}
	
	bool is2 = false;
	bool is3 = false;
	int c=0;
	int mc=0;
	string ret="";
	foreach(it,count){
		if(it->second>0){
			c++; 
			mc=max(mc,c);
		}else{
			c=0;
		}
		if(it->second==4){
			ret = "four card";
			break;
		}else if(it->second==3){
			if(is2){
				ret = "full house";
				break;
			}else{
				is3 = true;
			}
		}else if(it->second==2){
			if(is3){
				ret = "full house";
				break;
			}else if(is2){
				ret = "two pair";
				break;
			}else{
				is2 = true;
			}
		}
	}
	if(count[1]==1&&count[13]==1&&count[12]==1&&count[11]==1&&count[10]==1){
		return "straight";
	}
	if(mc==5){
		return "straight";
	}else if(ret!=""){
		return ret;
	}else if(is3){
		return "three card";
	}else if(is2){
		return "one pair";
	}
	return "null";
}



int main(){
	int nums[5];
	while(scanf("%d,%d,%d,%d,%d",&nums[0],&nums[1],&nums[2],&nums[3],&nums[4])+1){
		cout << judge(nums) << endl;
	}
	return 0;	
}

Measured memory_bytes: 1216
N = int(input())
ac = 0
tle = 0
wa = 0
re = 0

for _ in range(N):
  s = input()
  if(s=="AC"):ac+=1
  if(s=="TLE"):tle+=1
  if(s=="WA"):wa+=1
  if(s=="RE"):re+=1

print("AC x %d" %(ac))
print("WA x %d" %(wa))
print("TLE x %d" %(tle))
print("RE x %d" %(re))

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

int main()
{
  string S;
  cin >> S;
  int cnt0 = 0, cnt1 = 0;
  string::iterator itr;
  for(itr=S.begin(); itr!=S.end(); itr++)
  {
    if(*itr=='0') cnt0++;
    else cnt1++;
  }
  cout << 2*min(cnt0,cnt1) << endl;
  return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    string s;
    cin >> s;
    int y = stoi(s.substr(0, 4));
    int m = stoi(s.substr(5, 2));

    if (y < 2019) {
        puts("Heisei");
        return;
    }
    else {
        if (y > 2019) {
            puts("TBD");
            return;
        }
        else {
            if (m <= 4) {
                puts("Heisei");
                return;
            }
            else {
                puts("TBD");
                return;
            }
        }
    }

}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;
int n;
int cnt[28];


int main(void){
	cin >> str;
	n=str.size();
	for(int i=0;i<n;i++){
		cnt[str[i]-'a']++;
	}
	int sum=0;
	for(int i=0;i<26;i++){
		if(cnt[i]%2==1){
			if(n%2==0)sum++;
			else n=0;
		}
	}
	sum-=sum/2;
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 3264
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int x,y,a,b;
    cin>>x>>y;
    if(x==1||x==3||x==5||x==7||x==8||x==10){
       if(y==3||y==5||y==7||y==8||y==10||y==12){
          cout<<"Yes"<<endl;
          return 0;
       } 
       else{
           cout<<"No"<<endl;
           return 0;
       }
    }
    else if(x==4||x==6||x==9){
       if(y==6||y==9||y==11){
           cout<<"Yes"<<endl;
           return 0;
       } 
       else{ cout<<"No"<<endl;
       return 0;
       }
    }
    else /*if(x==2)*/{
       cout<<"No"<<endl;
       return 0;
    }
}


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

int main(){
  int N;
  cin >> N;
  int A[N];
  int count = 0;
  int flag = 0;
  for(int i=0;i<N;i++) cin >> A[i];
  while(1){
  	for(int i=0;i<N;i++){
	  if(A[i]%2==1) flag=1;
	}
	for(int i=0;i<N;i++){
	  A[i] /= 2;
	}
	if(flag==1) break;
	count++;
  }
  cout << count << endl;
  return 0;
}


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

int main() {
  int n,a,i=0,x=0;
  cin >> n;
  for(; i < n; i += 1){
    cin >> a;
    if(a %2 == 0 && (!(a %3 == 0 || a %5 == 0))){
      x += 1;
    }
  }
  if(x == 0){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import itertools
import math

D, G = map(int, input().split())
p, c = [0]*D, [0]*D
for i in range(D):
    p[i], c[i] = map(int, input().split())

ls = []
for i in itertools.product([0, 1], repeat=D):
    sum = 0
    ans = 0
    for j, x in enumerate(i):
        if x == 1:
            sum += c[j] + (100*(j+1))*p[j]
            ans += p[j]
    if sum >= G:
        ls.append(ans)
    else:
        for j, x in enumerate(i[::-1]):
            if x != 1:
                if math.ceil((G-sum)/(100*(D-j))) <= p[D-1-j] - 1:
                    ans += math.ceil((G-sum)/(100*(D-j)))
                    ls.append(ans)
                    break
                else:
                    sum += (100*(D-j))*(p[D-1-j] - 1)
                    ans += p[D-1-j] - 1
print(min(ls))


Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    REP(i, n) cin >> a[i] >> b[i];

    vector<ll> pr(n);
    iota(ALL_OF(pr), 0LL);
    sort(ALL_OF(pr), [&](ll i, ll j) -> bool {
        return b[i] > b[j];
    });
    
    ll t = b[pr[0]];
    REP(i, n) {
        t = min(t, b[pr[i]]);
        t -= a[pr[i]];
    }
    cout << Yes(t >= 0) << endl;
    
}

Measured memory_bytes: 4992
#include<iostream>
#include<set>
#define ll long long
using namespace std;

ll check(ll k)
{
    set<ll> a;
    while(k != 0){
        ll l = k % 10;
        k /= 10;
        if(l == 3 || l == 5 || l == 7) a.insert(l);
        if(a.size() == 3) return 1;
    }
    return 0;
}

ll scgsn(ll k, ll n)
{
    if(k > n) return 0;
    return check(k) + scgsn(k*10 + 3, n) + scgsn(k*10 + 5, n) + scgsn(k*10 + 7, n);
}

int main()
{
    ll n;
    cin >> n;
    cout << scgsn(0, n) << endl;
    return 0;
}

Measured memory_bytes: 256
use strict;
use warnings;

main();

sub main{
	my $line1 = <STDIN>;
	chomp($line1);

	my @array;
	my %hash;

	for(my $i=0; $i<$line1;$i++){
	my $line2 = <STDIN>;
	chomp($line2);
	$array[$i] = $line2;
	}
	
	foreach(@array){
		$hash{$_} = 1;
	}
	
	my $count = keys(%hash);
	
	print $count;
	print "\n";
}
1;

Measured memory_bytes: 640
from fractions import gcd

N = int(input())
nums = [int(i) for i in input().split()]

fort = [nums[0], gcd(nums[0], nums[1])]
back = [nums[N-1], gcd(nums[N-1], nums[N-2])]
ans = []

for i in range(N-2):
    fort.append(gcd(fort[i+1], nums[i+2]))
                
for i in range(N-2):
    back.append(gcd(back[i+1], nums[N-(i+3)]))
    
for i in range(1, N-1):
    ans.append(gcd(fort[i-1], back[N-2-i]))

ans.append(fort[N-2])
ans.append(back[N-2])

print(max(ans))


Measured memory_bytes: 16156
from sys import exit

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if A1 > B1:
  A1, B1 = B1, A1
  A2, B2 = B2, A2

if A2 < B2:
  print(0)
  exit()

if A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2:
  print(0)
  exit()

if A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2:
  print('infinity')
  exit()

a = B1 * T1 - A1 * T1
b = (A1 * T1 + A2 * T2) - (B1 * T1 + B2 * T2)
t = a // b

if a % b == 0:
  print(t * 2)
else:
  print(t * 2 + 1)

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>


using namespace std;


int main(void){
  
  int N,K,count =1;
  
  cin >> N >> K;
  
 while(N>=K){
   count++;
   N /=K;
 }



  cout << count << endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a, b, sum, count;

  while(scanf("%d%d", &a, &b) != EOF){  
  
    sum = a + b;
    
    count = 0;
    
    while(sum != 0){
      
      sum = sum / 10;
      count++;
      
    }
    
    printf("%d\n", count);
    
  }
  return(0);
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
    int a, b, c, sum;
    int i, j, k, ans;
    scanf("%d%d%d%d", &a, &b, &c, &sum);

    for (i=0; i<a+1; i++)
    {
        for (j=0; j<b+1; j++)
        {
            for (k=0; k<c+1; k++)
            {
                if (500*i + 100*j + 50*k == sum) {
                    ans++;
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;

}


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

int main(int argc, char const *argv[]) {
  int n, i, j, temp;
  cin >> n;
  int li[n];
  for (i=0; i < n; i++) {
    cin >> li[i];
  }
  sort(li, li+n);
  cout << li[n/2]-li[n/2-1]<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,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;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    int n;
    cin >> n;
    vi l(n);
    int ans=0;
    rep(i,n) cin >> l[i];
    sort(l.begin(),l.end());
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int ab=l[i]+l[j];
            auto ite=lower_bound(l.begin()+j+1,l.end(),ab);
            int x=ite-(l.begin()+j+1);
            x=max(x,0);
            ans+=x;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> dx={1,0,-1,0};
vector<ll> dy={0,1,0,-1};


int main(){
    ll w,h;
    cin>>w>>h;
    vector<string> A(h);
    for(auto &I:A){cin>>I;}
    vector<vector<bool>> can(h,vector<bool>(w,false));
    pll G;
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            if(A[i][t]=='t'){G={i,t};}
        }
    }
    queue<pll> Q;
    Q.push({0,0});
    can[0][0]=true;
    while(!Q.empty()){
        pll W=Q.front(); Q.pop();
        for(int i=0;i<4;i++){
            ll X=W.F+dx[i];
            ll Y=W.S+dy[i];
            if(X<0 || Y<0 || X>=h || Y>=w || can[X][Y] || A[X][Y]=='#'){continue;}
            can[X][Y]=true;
            Q.push({X,Y});
        }
    }
    if(can[G.F][G.S]){cout<<0<<endl; return 0;}
    ll n;
    cin>>n;
    for(int T=1;T<=n;T++){
        ll x,y;
        cin>>x>>y;
        swap(x,y);
        if(A[x][y]=='#'){
            A[x][y]='.';
            for(int i=0;i<4;i++){
                ll X=x+dx[i];
                ll Y=y+dy[i];
                if(X<0 || Y<0 || X>=h || Y>=w || !can[X][Y] || A[X][Y]=='#'){continue;}
                Q.push({x,y});
                can[x][y]=true;
                break;
            }
            while(!Q.empty()){
                pll W=Q.front(); Q.pop();
                for(int i=0;i<4;i++){
                    ll X=W.F+dx[i];
                    ll Y=W.S+dy[i];
                    if(X<0 || Y<0 || X>=h || Y>=w || can[X][Y] || A[X][Y]=='#'){continue;}
                    can[X][Y]=true;
                    Q.push({X,Y});
                }
            }
        }
        if(can[G.F][G.S]){cout<<T<<endl; return 0;}
    }
    cout<<-1<<endl;
    
    
    return 0;
}



Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define endl "\n"
#define MAX 100005

void generate(vector<ll>& arr) {
    for (ll i = 1; i <= 9; i++) {
        arr[i] = i;
    }

    ll g = 1;
    ll i = 10;
    while (i < MAX-2) {
        ll gen = arr[g];
        ll gdig = gen%10;

        if (gdig > 0) {
            arr[i] = gen*10 + (gdig-1);
            i++;
        }

        arr[i] = gen*10 + gdig;
        i++;
        if (gdig < 9) {
            arr[i] = gen*10 + (gdig+1);
            i++;
        }
        g++;
    }
}

int main(void) {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    vector<ll> lun (MAX);
    generate(lun);
    ll k;
    cin >> k;
    cout << lun[k];
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, M;
	cin >> N >> M;

	int A[51], B[51], C[51], D[51];
	rep1(i, N) cin >> A[i] >> B[i];
	rep1(i, M) cin >> C[i] >> D[i];

	rep1(i, N) {
		int kyori = 1e9;
		int kotae;
		rep1(ii, M) {
			int kari = abs(A[i] - C[ii]) + abs(B[i] - D[ii]);
			if (kyori > kari) {
				kyori = kari;
				kotae = ii;
			}
		}
		co(kotae);
	}

	Would you please return 0;
}

Measured memory_bytes: 256
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;

template <typename T>
using priority_queue_lo = priority_queue<T, vector<T>, greater<T>>;
#define CLEAR(q) game_que = decltype(game_que)();

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


  int N, M; cin >> N >> M;
  vi A(N); REP(i, N) cin >> A[i];
  vi B(M), C(M); REP(i, M) cin >> B[i] >> C[i];

  priority_queue_lo<ll> pql;
  REP(i,N) pql.push(A[i]);

  vector<pii> CB;
  REP(i, M) CB.push_back(pii(C[i], B[i]));
  sort(CB.rbegin(), CB.rend());

  REP(i,M) {
    ll CI = CB[i].first;
    int BI = CB[i].second;
    REP(j, BI) {
      if (pql.top() < CI) {
        pql.pop();
        pql.push(CI);
      } else {
        break;
      }
    }
  }

  ll ans = 0;
  while (!pql.empty()) {
    ans += pql.top(); pql.pop();
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String a = s.next(), b = s.next(), c = s.next();
        if (a.charAt(a.length() - 1) == b.charAt(0) && b.charAt(b.length() - 1) == c.charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23764
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

int tx[] = {1,0};
int ty[] = {0,1};

ll GCD(ll a ,ll b){
	return b > 0 ? GCD(b,a%b) : a;
}

int main(){
	int a,b;
	while(~scanf("%d %d",&a,&b)){
		printf("%lld\n",GCD(a,b));
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;     // -INF: 0xc0   abs(-INF) = INF + 1
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9+7;     // when MOD = 1e9+7, inv2 = 500000004
const int N = 50007;
const int M = 328;
const int B = 203;

int main()
{
	int n;cin>>n;
	rep(i,1,10) {
		if(n % i == 0 && n / i <= 9) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int ans[100010];

int main(){
	string s;
	cin >> s;
	
	int r[100010],l[100010],cnt;
	cnt = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'R'){
			r[i] = 0;
			cnt = 0;
		}else{
			r[i] = cnt;
		}
		cnt++;
	}
	cnt = 0;
	for(int i = s.size()-1; i >= 0; i--){
		if(s[i] == 'L'){
			l[i] = 0;
			cnt = 0;
		}else{
			l[i] = cnt;
		}
		cnt++;
	}

	/*
	for(int i = 0; i < s.size(); i++) cout << r[i] << endl;
	cout << endl;
	for(int i = 0; i < s.size(); i++) cout << l[i] << endl;
	cout << endl;
	*/

	int num = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'R'){
			num = i+l[i];
			if(l[i]%2) num--;
		}else{
			num = i-r[i];
			if(r[i]%2) num++;
		}
		ans[num]++;
	}

	for(int i = 0; i < s.size(); i++){
		cout << ans[i];
		if(i != s.size()-1) cout << ' ';
		else cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if(a < b && b < c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
import numpy as np

class unionfind: #ノード数nを読み込む
    def __init__(self,n): #コンストラクタ
        self.parent = list(range(n))
    def find(self,a): #根を探す、そのつど根を更新
        if self.parent[a] == a: return a #自分が根だったら終了
        else:
            self.parent[a] = self.find(self.parent[a]) #経路圧縮
            return self.parent[a]
    def unite(self,a,b): #ランク度外視で根を合体する
        pa,pb = self.find(a),self.find(b)
        if pa == pb: return 0 #根が一緒なら何もせず終了
        else: self.parent[pa] = pb
    def same(self,a,b):
        pa,pb = self.find(a),self.find(b)
        return pa == pb

# クラスを使わない実装
def find(x):
    if node[x] == x: return x
    else: node[x] = find(node[x]) ; return node[x]
def unite(x,y):
    x,y = find(x),find(y)
    if x == y : return
    else: node[x] = y
def same(x,y): return find(x) == find(y)


n,m = map(int,input().split())
ab = np.array([list(map(int,input().split())) for i in range(m)])
a,b = ab.T[0] -1, ab.T[1] -1

ans = 0
for i in range(m): #除外する辺を決める
    connect = 0
    node = list(range(n))
    for j in range(m): #i以外の辺についてuniteしていく
        if i != j and  not same(a[j],b[j]): unite(a[j],b[j]) ; connect += 1
    ans += 0 if connect == n-1 else 1
print(ans)



Measured memory_bytes: 17568
#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	fasterthanlight;
	string s;
	cin >> s;
	int x = 0, ans = -1;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] != 'R')
		{
			ans = max(x, ans); x = 0;
		}
		else
			x++;
	}
	ans = max(x, ans);
	cout << ans << endl;


	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
 
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)  for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
typedef long long LL;
 
using namespace std;
 
LL mod=(LL)1000000007;
 
int main(void){
    int N,M;
    LL ans=0;
    cin>>N>>M;
    if(N>M)swap(N,M);
    if(N==M){
        ans=2;
    }else if(M-N==1){
        ans=1;
    }
    FOR(i,1,N+1){
        ans*=(LL)i;
        ans%=mod;
    }
    FOR(i,1,M+1){
        ans*=(LL)i;
        ans%=mod;
    }
    cout<<ans<<endl;
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  
  if(a > 9 || b > 9){
    cout << -1 << endl;
    return 0;
  }
  
  cout << a * b << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdio>
#include<cassert>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define inf (1<<29)
#define MOD 1000000009

using namespace std;
typedef long long ll;
typedef pair<ll,ll> Coor;

//
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef VVI matrix;

matrix identity(int n)
{
  matrix A(n,VI(n));
  for(int i=0;i<n;i++) A[i][i] = 1;
  return A;
}

VI multi(const matrix& A,const VI& B)
{
  VI ret(A.size());
  for(int i=0;i<A.size();++i)
    for(int j=0;j<A[0].size();++j)
      ret[i] = (ret[i]+(A[i][j]*B[j])%MOD)%MOD;
  return ret;
}

matrix multi(const matrix& A,const matrix& B)
{
  matrix C(A.size(),VI(B[0].size()));
  for(int i=0;i<C.size();++i)
    for(int j=0;j<C[i].size();++j)
      for(int k=0;k<A[i].size();++k)
	C[i][j] = (C[i][j]+(A[i][k]*B[k][j])%MOD)%MOD;
  return C;
}

matrix pow(const matrix& A,ll e)
{
  return !e?identity(A.size()):
    (e%2LL?multi(A,pow(A,e-1LL)):pow(multi(A,A),e/2LL));
}
//
ll W,H,N;
int dx[] = {-1,0,+1};
map<ll,vector<int> > obstruction;

matrix getMatrix(vector<int> vec)
{
  bool out[W];
  rep(i,W)out[i] = false;
  rep(i,vec.size())out[vec[i]] = true;
  matrix A = identity(W);
  rep(i,W)A[i][i] = 0;
  rep(x,W)
    {
      if(out[x])continue;
      rep(k,3)
	{
	  int nx = x + dx[k];
	  if(!(0 <= nx && nx < W))continue;
	  A[x][nx] = 1;
	}
    }
  return A;
}

void print(matrix A)
{
  rep(i,A.size())
    {
      rep(j,A[i].size())
	{
	  cout << A[i][j] << " ";
	}
      cout << endl;
    }
  cout << endl;
}

int main()
{
  int CNT = 1;
  while(scanf("%lld %lld %lld",&W,&H,&N),W|H|N)
    {
      obstruction.clear();
      vector<Coor> vec(N);
      vector<ll> b(W,0);
      b[0] = 1;
      bool out = false;
      rep(i,N)
	{
	  scanf("%lld %lld",&vec[i].first,&vec[i].second);
	  vec[i].first--,vec[i].second--;
	  if(vec[i].first == W-1 && vec[i].second == H-1)out = true;
	  if(vec[i].second == 0)continue;
	  if(vec[i].second == H-1)continue;
	  obstruction[vec[i].second].push_back(vec[i].first);
	}

      if(out)
	{
	  cout << "Case " << CNT++ << ": " << 0 << endl;
	  continue;
	}

      matrix A = getMatrix(vector<int>());
      matrix ans = identity(W);
      //cout << "A : "<< endl;
      //print(A);

      ll cur = 0;
      for(map<ll,vector<int> >::iterator it = obstruction.begin();it!=obstruction.end();it++)
	{
	  vector<int> obst = it->second;
	  matrix B = getMatrix(obst);
	  ll diff = (it->first) - cur - 1;

	  if(diff != 0)
	    {
	      matrix tmp = pow(A,diff);
	      ans = multi(tmp,ans);
	    }

	  ans = multi(B,ans);
	  cur = (it->first);

	}

      if((H-1) != cur)
	{
	  matrix tmp = pow(A,(H-1)-cur);
	  ans = multi(tmp,ans);
	}

      VI vans = multi(ans,b);
   
      cout << "Case " << CNT++ << ": " << vans[W-1]%MOD << endl;

    }
  return 0;
}

Measured memory_bytes: 4160