akhauriyash/Code-Regression huggingface dataset:
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
const int N = 2e5+10;
const double eps = 0.00000001;
const ll mod = 1e9 + 7 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
deque<char> dt;
int main(){
	string s;
	cin >> s;
	int l = s.size();
	rep(i,0,l-1){
		dt.push_back(s[i]);
	}
	int q = read();
	int cnt = 0;
	while(q--){
		int t = read();
		if(t==1) cnt ++;
		else{
			int op = read();
			char c;
			cin >> c;
			if(op == 1){
				if(cnt&1) dt.push_back(c);
				else dt.push_front(c);
			}
			else {
				if(!(cnt&1)) dt.push_back(c);
				else dt.push_front(c);
			}
		}
	}
	if(cnt&1){
		while(dt.size()) cout<<dt.back(),dt.pop_back();
	}
	else {
		while(dt.size()) cout<<dt.front(),dt.pop_front();
	}
}


Measured memory_bytes: 896
# include <bits/stdc++.h>
# define ll long long
# define pb push_back
# define mk make_pair
# define fr first
# define sc second

using namespace std;
int n,z;
string s;
int res[100009];
int main(){
	cin>>s;
	n=s.size();
	while(z<n)
	{
		int i=0,odd=0,even=0,t,k,q=0;
		while(1)
		{
			i++;
			
			if(z==n || s[z]=='R' && q==1)
			break;

			if(s[z]=='L' && q==0)
			q=1,t=z,k=i;
			
			if(i%2)odd++;
			else even++;
			
			z++;
		}
		if(k%2)
		res[t]=odd,res[t-1]=even;
		else
		res[t]=even,res[t-1]=odd;
	}
	
	for(int i=0;i<n;i++)
	cout<<res[i]<<" ";
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>

using namespace std;

#define MAX 10000000
#define LMT 3163
int sieve();
int calculation();

unsigned flag[MAX>>6];
int primes[5761455];

#define ifc(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define isc(n) (flag[n>>6]|=(1<<((n>>1)&31)))

int main()
{
    sieve();
    return 0;
}


int sieve()
{
    unsigned i, j, k;
    for(i=3; i<LMT; i+=2)
        if(!ifc(i))
            for(j=i*i, k=i<<1; j<MAX; j+=k)
                isc(j);
    calculation();
    return 0;
}

int calculation()
{
    int Rang, count;
    unsigned int i;
    int k = 1;
    primes[0] = 2;
    for( i=3; i<MAX; i+=2)
    {
        if(ifc(i)==0)
            primes[k++] = i;
    }
    while(scanf("%d",&Rang)==1)
    {
        count = 0;
        for(i=0; i<Rang; i++)
        {
            if(primes[i]<=Rang)
            {
                count++;
            }
            else if(primes[i]>Rang)
                break;
        }
        cout << count << "\n";
    }
    return 0;
}

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

using namespace std;

template<class T> inline T updmax(T &a, T b){return a = max(a,b);}
template<class T> inline T updmin(T &a, T b){return a = min(a,b);}

template <unsigned long long mod> class modint {
public:
    unsigned long long v;
    modint(const long long x = 0) : v(x % mod) {}
    modint operator+(const modint rhs) { return modint(*this) += rhs; }
    modint operator-(const modint rhs) { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) { return modint(*this) *= rhs; }
    modint operator/(const modint rhs) { return modint(*this) /= rhs; }
    modint operator-() { return modint(mod-this->v); }
    modint &operator+=(const modint rhs) {
        v += rhs.v;
        if (v >= mod)v -= mod;
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if (v < rhs.v)v += mod;
        v -= rhs.v;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        v = v * rhs.v % mod;
        return *this;
    }
    modint inverse(modint a) {
        unsigned long long exp = mod - 2;
        modint ret(1ULL);
        while (exp) {
            if (exp % 2) {
                ret *= a;
            }
            a *= a;
            exp >>= 1;
        }
        return ret;
    }
    modint &operator/=(modint rhs) {
        (*this) *= inverse(rhs);
        return *this;
    }
};
using mint = modint<1000000007>;

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(1, 0);
    for(int i=1; i*i<=n; i++){
        a.emplace_back(i);
        if(n/i != i)a.emplace_back(n/i);
    }
    sort(a.begin(), a.end());
    int m = a.size();
    vector<vector<mint>> dp(k+1, vector<mint>(m));
    dp[0][1] = 1;
    for(int i=0; i <= k; i++){
        for(int j=1; j < m; j++){
            dp[i][j] += dp[i][j-1];
        }
        if(i == k)break;
        for(int j=1; j < m; j++){
            auto id = distance(a.begin(), lower_bound(a.begin(), a.end(), n/a[j]));
            dp[i+1][j] += dp[i][id] * (a[j] - a[j-1]);
        }
    }
    printf("%lld", dp[k][m-1]);
    return 0;
}

Measured memory_bytes: 51196
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }


signed main()
{
    string s,t; cin>>s>>t;
    int N=s.size();
    int M=t.size();

    vector<vector<int> > dp(N+1,vector<int>(M+1));
    vector<vector<int> > dp2(N+1,vector<int>(M+1));
    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
                dp2[i+1][j+1]=0;
            }
            else if(dp[i][j+1]>dp[i+1][j]){
                dp[i+1][j+1]=dp[i][j+1];
                dp2[i+1][j+1]=1;
            }
            else{
                dp[i+1][j+1]=dp[i+1][j];
                dp2[i+1][j+1]=-1;
            }
        }
    }
    
    string ans="";
    int i=N,j=M;
    while(i>0 and j>0){
        if(dp2[i][j]>0){
            i--;
        }
        else if(dp2[i][j]<0){
            j--;
        }
        else{
            ans=s[i-1]+ans;
            i--; j--;
        }
    }
    cout<<ans<<endl;
}


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) (x).begin() , (x).end()
#define mod 1000000009

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

void solve()
{
	int n;
	cin >> n;
	vi v(4 , 0);
	for (int i = 0 ; i < n ; ++i)
	{
		string s;
		cin >> s;

		if (s == "AC") v[0]++;
		if (s == "WA") v[1]++;
		if (s == "TLE") v[2]++;
		if (s == "RE") v[3]++;
	}

	cout << "AC x " << v[0] << "\n";
	cout << "WA x " << v[1] << "\n";
	cout << "TLE x " << v[2] << "\n";
	cout << "RE x " << v[3] << "\n";
}

int main() {

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

	int t = 1;
	//cin>>t;

	while (t--)
	{
		solve();
	}


	return 0;
}





Measured memory_bytes: 3660
import bisect

A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = INF
  for S in [s[b - 1], s[b]]:
    for T in [t[d - 1], t[d]]:
      d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
      res = min(res, d1, d2)
  print(res)

Measured memory_bytes: 12812
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
H=list(map(int,input().split()))
INF=float('inf')
DP=[INF]*n
DP[0]=0
for i in range(n-1):
    for j in range(1,k+1):
        if i+j>=n:
            break
        else:
            DP[i+j]=min(DP[i+j],DP[i]+abs(H[i+j]-H[i]))
print(DP[-1])

Measured memory_bytes: 55004
def main():
    A1, A2, A3 = sorted(map(int, raw_input().split()))

    if A1 == A2 and A2 == A3:
        print 0
    elif A2-A1 < A3-A2:
        print (A2-A1) + (A3-A2)
    elif A3-A2 < A2-A1:
        print (A2-A1) + (A3-A2)
    else:
        print 0


main()


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    ll X;
    cin>>X;
    ll ans = 0;
    ans += (X/500)*1000;
    X -=(X/500)*500;
    ans += (X/5)*5;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
bool vis[N];
void dfs(vector<vector<int> >&v,int u){
	vis[u]=1;
	for(int i=0;i<v[u].size();i++){
		int ch=v[u][i];
		if(!vis[ch])dfs(v,ch);
	}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int n,m;
cin>>n>>m;
vector<vector<int> >adj(n+1);
for(int i=0;i<m;i++){
	int a,b;
	cin>>a>>b;
	adj[a].pb(b);
	adj[b].pb(a);
}
int c=0;
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++){
	if(!vis[i]){
		dfs(adj,i);
        c++;
	}
}
cout<<max(c-1,0)<<endl;
return 0;
}

Measured memory_bytes: 9800
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,m,t[100005],a[100005],ans;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)a[i]=1;
    t[1]=2;
    for(int i=1;i<=m;++i){
        int x,y;
        scanf("%d%d",&x,&y);
        if(t[x]==2&&a[x]==1)t[y]=2,t[x]=0;
        else if(t[x])t[y]=1;
        --a[x],++a[y];
        if(!a[x])t[x]=0;
    }
    for(int i=1;i<=n;++i)if(t[i])++ans;
    printf("%d\n",ans);            
    //system("pause");
    return 0;
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::collections::HashSet;

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 abc = read_vec::<u32>();
    

    let answer = solve(&abc);
    println!("{}", answer);
}

fn solve(abc: &[u32]) -> u32 {
    if abc[0] <= abc[1] {
        if abc[1] <= abc[2] {
            return abc[0] + abc[1];
        } 
        return abc[0] + abc[2];
    } else {
        if abc[0] <= abc[2] {
            return abc[0] + abc[1];
        }
        return abc[1] + abc[2];
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define max 1000000007
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair<int,int> P;
typedef pair<P,P> PP;
int main(void)
{
	int n,m,s,g,v,p;
	int pp,kou,min;
	int i,j,k;
	int ri[21][21],leng[21],flg[21];
	
	PP d[100];
	
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++) scanf("%d,%d,%d,%d",&d[i].ff,&d[i].fs,&d[i].sf,&d[i].ss);
	scanf("%d,%d,%d,%d",&s,&g,&v,&p);
	
	for(i=0;i<=n;i++) fill(ri[i]+1,ri[i]+n+1,max);
	for(i=0;i<m;i++) ri[d[i].ff][d[i].fs]=d[i].sf,
					 ri[d[i].fs][d[i].ff]=d[i].ss;
					 
	for(i=1;i<=n;i++) leng[i]=max,flg[i]=0;
	leng[s]=0;
	
	kou=0;
	for(i=1;i<=n;i++){
		min=max;
		
		for(j=1;j<=n;j++) if(flg[j]==0&&leng[j]<min) pp=j,min=leng[j];
		flg[pp]=1;
		
		for(k=1;k<=n;k++){
			if(leng[pp]+ri[pp][k]<leng[k]) leng[k]=leng[pp]+ri[pp][k];
		}	
	}
	kou+=leng[g];
	
	for(i=1;i<=n;i++) leng[i]=max,flg[i]=0;
	leng[g]=0;
	
	for(i=1;i<=n;i++){
		min=max;
		
		for(j=1;j<=n;j++) if(flg[j]==0&&leng[j]<min) pp=j,min=leng[j];
		flg[pp]=1;
		
		for(k=1;k<=n;k++){
			if(leng[pp]+ri[pp][k]<leng[k]) leng[k]=leng[pp]+ri[pp][k];
		}	
	}
	kou+=leng[s];

	printf("%d\n",v-p-kou);
}	
	


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#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()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
double dist(pair<double, double> a, pair<double, double> b) {
    double ax, ay, bx, by;
    tie(ax, ay) = a;
    tie(bx, by) = b;
    return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}
int main() {
    int n;
    cin >> n;
    vector<pair<double, double>> v(n);
    rep(i, n) {
        double x, y;
        cin >> x >> y;
        v[i] = make_pair(x, y);
    }
    vector<int> p(n);
    rep(i, n) p[i] = i;

    double ans = 0;
    do {
        rep(i, n - 1) {
            ans += dist(v[p[i]], v[p[i + 1]]);
        }
    } while (next_permutation(all(p)));
    rep(i, n) ans /= (double)(i + 1);
    cout << fixed << setprecision(20) << ans << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a=1;
    int n;cin>>n;
    for(int i=1;i<=n;i++)a=a*i%1000000007;
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const float pi = 3.1415926535;
unsigned GetDigit(unsigned num){
    return to_string(num).length();
}

int main() {
  float a,b;
  int x;
  cin >> a >> b >> x;
  cout << fixed << setprecision(8);
  if (x >= a*a*b/2) {
    float k = (2*a*a*b-2*x)/(a*a*a);
    cout << (float)atan(k)*360/2/pi << endl;
  }
  else {
    float k = a*b*b/(2*x);
    cout << (float)atan(k)*360/2/pi << endl;
  }
}

Measured memory_bytes: 3912
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
if N == 0:
    if A[0] == 1:
        print(1)
        exit()
    else:
        print(-1)
        exit()
if A[0] != 0:
    print(-1)
    exit()
cum = [0] * (N+2)
for i in range(N+1)[::-1]:
    cum[i] = cum[i+1] + A[i]
ans = 1
cur = 1
for i in range(1, N+1):
    cur = min(cur * 2, cum[i+1] + A[i])
    ans += cur
    cur -= A[i]
    if cur < 0:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 82852
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int A, B;
	string S, T, U;
	cin >> S >> T >> A >> B >> U;
	if (U == S) cout << A - 1 << " " << B;
	else cout << A << " " << B - 1;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int i, j, n, u, k, v;
    scanf("%d",&n);
    int A[n][n];
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            A[i][j]=0;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d",&v);
            A[u-1][v-1] = 1;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            printf("%d",A[i][j]);
            if(j<n-1)printf(" ");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2752
import math
N, K = map(int, input().split())

ans = 0

for n in range(1, N+1):
    tmp = n
    need = 0
    while True:
        if tmp >= K:
            break
        tmp *= 2
        need += 1
    probability = 1 / 2**need
    ans += probability

print(ans / N)

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

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < (int)s.length(); i++)
    {
        if (s[i] != t[i])
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3896
//Author: AnandRaj anand873
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 2e9+7,MAX = 1e5+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
    		MinDiv[i]=i;
        	for (j = i * i; j <= MAX; j += i)
            {
				is_prime[j] = false;
				MinDiv[j]=i;
    		}
    	}
	}
}
//////////////////Sieve////////////////////

int main()
{
	ld a,b;
	cin>>a>>b;
	cout<<(ll)(a*b)<<endl;
}		

Measured memory_bytes: 3780
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""


input:
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0

output:
0
0
1
1
1
0
1
1

"""

import sys


class UnionFind(object):
    __slots__ = ('size', 'tree_height_rank_list', 'ancestor_list')

    def __init__(self, size):
        self.size = int(size)
        self.tree_height_rank_list = [0] * self.size
        self.ancestor_list = [i for i in range(self.size)]

    def _find(self, x):
        if x != self.ancestor_list[x]:
            self.ancestor_list[x] = self._find(self.ancestor_list[x])
        return self.ancestor_list[x]

    def same(self, x, y):
        return self._find(x) == self._find(y)

    def link(self, x, y):
        if self.tree_height_rank_list[x] > self.tree_height_rank_list[y]:
            self.ancestor_list[y] = x
        else:
            self.ancestor_list[x] = y
            if self.tree_height_rank_list[x] == self.tree_height_rank_list[y]:
                self.tree_height_rank_list[y] += 1

    def union(self, x, y):
        self.link(self._find(x), self._find(y))


def action(cmd):
    for _, each in enumerate(cmd):
        cmd, ele_1, ele_2 = map(int, each)
        if cmd == 0:
            case.union(ele_1, ele_2)
        elif cmd == 1:
            if case.same(ele_1, ele_2):
                print('1')
            else:
                print('0')
    return case


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    ele_num, cmd_num = map(int, _input[0].split())
    cmd_list = map(lambda x: x.split(), _input[1:])

    case = UnionFind(size=ele_num)

    ans = action(cmd_list)

Measured memory_bytes: 16588
def convert_binary(n):
    if n == 0:
        return '0'
    s = []
    while True:
        s.append(str(n % 2))
        n = int(n / 2)
        if n == 0:
            break
    return ''.join(s)[::-1]
   
def calc_xor(b1, b2):
    maxlen = max(len(b1), len(b2))
    b1 = '0' * (maxlen - len(b1)) + b1
    b2 = '0' * (maxlen - len(b2)) + b2
    s = ''
    for i in range(maxlen):
        if (int(b1[i]) + int(b2[i])) % 2 == 1:
            s += '1'
        else:
            s += '0'
    return s
   
def convert_decimal(binary):
    n = 0
    i = 0
    for b in binary[::-1]:
        n += (2 ** i) * int(b)
        i += 1
    return n
 
def calc_xor_from_zero(n):
    if (n+1) % 2 == 0:
        count_pair = int((n+1) / 2)
        if count_pair % 2 == 0:
            return '0'
        else:
            return '1'
    else:
        count_pair = int((n+1) / 2)
        if count_pair % 2 == 0:
            return calc_xor('0', convert_binary(n))
        else:
            return calc_xor('1', convert_binary(n))
    
A, B = list(map(int, input().split(' ')))
 
print(convert_decimal(calc_xor(calc_xor_from_zero(A-1), calc_xor_from_zero(B))))

Measured memory_bytes: 3064
// ALDS1_3_B: Queue

use std::collections::VecDeque;

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let a = s.split_whitespace().collect::<Vec<&str>>();
    let n = a[0].parse::<usize>().unwrap();
    let q = a[1].parse::<i64>().unwrap();

    let mut queue: VecDeque<(String, i64)> = VecDeque::new();

    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let a = s.split_whitespace().collect::<Vec<&str>>();
        let name = a[0].to_string().clone();
        let t = a[1].parse::<i64>().unwrap();
        queue.push_back((name, t));
    }

    let mut elaps = 0;
    while !queue.is_empty() {
        let mut u = queue.pop_front().unwrap();
        let a = if u.1 < q { u.1 } else { q };
        u.1 -= a;
        elaps += a;
        if u.1 > 0 {
            queue.push_back((u.0, u.1));
        } else {
            println!("{} {}", u.0, elaps);
        }
    }
}


Measured memory_bytes: 7060
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

template<typename T>
string join(const vector<T>& vec, string sep = " "){
    stringstream ss;
    for(int i = 0; i < vec.size(); i++){
        ss << vec[i] << (i + 1 == vec.size() ? "" : sep);
    }
    return ss.str();
}

vector<bool> solve(int a, int b, int c, int d){
    bool op1[] = {true, false, true, false, true, false, true, false};
    bool op2[] = {true, true, false, false, true, true, false, false};
    bool op3[] = {true, true, true, true, false, false, false, false};
    for(int i = 0; i < 8; i++){
        int s = a;
        s += b * (op1[i] ? 1 : -1);
        s += c * (op2[i] ? 1 : -1);
        s += d * (op3[i] ? 1 : -1);
        if(s == 7){
            return {op1[i], op2[i], op3[i]};
        }
    }
}

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

    vector<char> ns(4);
    cin >> ns;
    const vector<bool>& ops = solve(ns[0] - '0', ns[1] - '0', ns[2] - '0', ns[3] - '0');
    for(int i = 0; i < 3; i++){
        cout << ns[i] << (ops[i] ? '+' : '-');
    }
    cout << ns[3] << "=7" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	-- a, -- b;
	puts("100 100");
	for (int i = 0; i < 50; ++ i){
		for (int j = 0; j < 100; ++ j)
			if ((i & 1) && (j & 1) && a){
				putchar('.');
				-- a;
			}
			else
				putchar('#');
		putchar('\n');
	}
	for (int i = 50; i < 100; ++ i){
		for (int j = 0; j < 100; ++ j)
			if ((i & 1) && (j & 1) && b){
				putchar('#');
				-- b;
			}
			else
				putchar('.');
		putchar('\n');
	}
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define int long long
using namespace std;

const int mod=1e9+7;

int n,m;
char g[1005][1005];
int dp[1005][1005];

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> g[i][j];
        }
    }
    dp[1][1]=1;
    for(int i=2;i<=m;i++){
        if(g[1][i]!='#') dp[1][i]=dp[1][i-1];
    }
    for(int i=2;i<=n;i++){
        if(g[i][1]!='#') dp[i][1]=dp[i-1][1];
    }
    for(int i=2;i<=n;i++){
        for(int j=2;j<=m;j++){
                if(g[i][j]!='#'){
            dp[i][j]=dp[i-1][j]+dp[i][j-1];
            dp[i][j]=dp[i][j]%mod;}
        }
    }
 /**   for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++) cout<<dp[i][j];
        cout<<endl;
    } */
    cout<<dp[n][m];
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for( int i = 0; i < H; i++ ) cin >> S.at(i);

  vector<vector<int>> L(H, vector<int>(W));
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ){
      if( S[i][j] == '#' ) L[i][j] = 0;
      else{
        if( j == 0 ) L[i][j] = 1;
        else L[i][j] = L[i][j-1] + 1;
      }
    }
  }

  vector<vector<int>> R(H, vector<int>(W));
  for( int i = 0; i < H; i++ ){
    for( int j = W-1; j >= 0; j-- ){
      if( S[i][j] == '#' ) R[i][j] = 0;
      else{
        if( j == W-1 ) R[i][j] = 1;
        else R[i][j] = R[i][j+1] + 1;
      }
    }
  }

  vector<vector<int>> D(H, vector<int>(W));
  for( int i = 0; i < W; i++ ){
    for( int j = 0; j < H; j++ ){
      if( S[j][i] == '#' ) D[j][i] = 0;
      else{
        if( j == 0 ) D[j][i] = 1;
        else D[j][i] = D[j-1][i] + 1;
      }
    }
  }

  vector<vector<int>> U(H, vector<int>(W));
  for( int i = 0; i < W; i++ ){
    for( int j = H-1; j >= 0; j-- ){
      if( S[j][i] == '#' ) U[j][i] = 0;
      else{
        if( j == H-1 ) U[j][i] = 1;
        else U[j][i] = U[j+1][i] + 1;
      }
    }
  }

  int ans = 0;
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ){
      ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 129664
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	bool ans;
	cin >>s;
	map<char, int> dis;
	dis['N'] = 0;
	dis['S'] = 0;
	dis['W'] = 0;
	dis['E'] = 0;
	for (char i:s){
		dis[i]++;
	}
	 
	cout << solve(!(dis['N']==0 xor dis['S']==0) and !(dis['E']==0 xor dis['W']==0)) << endl;
}

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

int main() {
  int N,K,x,a;
  cin >> N >>K;
  a=0;

  for (int i=0; i<N; i++){
    cin >> x;
      if (x>K-x)
        a+=(K-x)*2;
      else
        a+=x*2;
    if  (i==N-1)
      cout << a << endl;
  }
}


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

using namespace std;

int main(void) {
	int N,X;
	cin >> N >> X;
	int sum = 0;
	int minm = (1 << 28);
	for (int i = 0; i < N; ++i) {
		int m;
		cin >> m;
		sum += m;
		minm = min(minm,m);
	}
	int res = N + (X-sum)/minm;
	cout << res << endl;

	return 0;
}



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

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var s = new int[M][];
        for (int i = 0; i < M; i++)
            s[i] = ReadLine().Split(' ').Skip(1).Select(s => int.Parse(s)).ToArray();
        var p = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var ans = 0;

        for (int pattern = 0; pattern < (1 << N); pattern++)
        {
            var ok = true;

            for (int i = 0; i < M; i++)
            {
                var count = 0;

                for (int j = 0; j < s[i].Length; j++)
                {
                    static int isOn(int p, int n) => (p & (1 << n)) != 0 ? 1 : 0;
                    count += isOn(pattern, s[i][j] - 1);
                }

                if (count % 2 != p[i])
                    ok = false;
            }

            if (ok)
                ans++;
        }

        WriteLine(ans);
    }
}


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

using namespace std;

vector<int> IntegerToVector(int bit,int N){
  vector<int> S;
  for(int i = 0; i < N; i++) {
    if(bit & (1 << i)) {
      S.push_back(i);
    }
  }
  return S;
}



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

  vector<double> x(N);
  vector<double> y(N);
  vector<int> z(N);
  for(int i = 0; i < N; i++){
    z[i] = i;
  }


  for(int i = 0; i < N; i++) cin >> x[i] >> y[i];
  double sum = 0;
  do{
    for(int i = 0; i < N - 1; i++){
      sum += sqrt((x[z[i + 1]] - x[z[i]]) * (x[z[i + 1]] - x[z[i]]) + (y[z[i + 1]] - y[z[i]])* (y[z[i + 1]] - y[z[i]]));
    }

  }while(next_permutation(z.begin(),z.end()));

  int num = 1;
  for(int i = 1; i < N + 1; i++) num *= i;

  cout << setprecision(10) << sum / num << endl;
  return 0;
}





Measured memory_bytes: 256
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

X = int(input())

while True:
    if is_prime(X):
        break
    else:
        X += 1

print(X)

Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String line1 = sc.nextLine();
        String line2 = sc.nextLine();
        
        String[] array = line2.split(" ");
        int n = Integer.parseInt(line1);
        
        int min = Integer.parseInt(array[0]);
        int count = 1;
        for(int i = 1; i < n; i++)
        {
            int buf = Integer.parseInt(array[i]);
            if(buf < min)
            {
                min = buf;
                count++;
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 57176
# D - Make Them Even

H, W = map(int, input().split())
A = [[0] * W for _ in range(H)]
for i in range(H):
    A[i] = list(int(x) for x in input().split())

path = []
for i in range(H):
    for j in range(W):
        if i%2 == 1:
            path.append((i, W-1-j))
        else:
            path.append((i, j))

cnt = 0
arr = []
for idx in range(len(path)-1):
    if A[path[idx][0]][path[idx][1]]%2 == 1:
        A[path[idx][0]][path[idx][1]] -= 1
        A[path[idx+1][0]][path[idx+1][1]] += 1
        cnt += 1
        arr.append((path[idx][0]+1, path[idx][1]+1, path[idx+1][0]+1, path[idx+1][1]+1))

print(cnt)
for a in arr:
    print(' '.join(map(str, a)))

Measured memory_bytes: 47872
#include <bits/stdc++.h>
using namespace std;
bool checkstr(int p,string a,string b){
    int i;
    for(i=0;i<b.size();i++){
        if(!(a[p+i]==b[i] or a[p+i]=='?'))
            break;
    }
    return i==b.size();
}

int main(void){
    string s,t;
    cin>>s>>t;
    int i;
    for(i=s.size()-1;i>=0;i--){
        if(checkstr(i,s,t)){
            for(int j=0;j<t.size();j++){
                s[j+i]=t[j];
            }
            break;
        }
    }
    if(i<0){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    replace(s.begin(),s.end(),'?','a');
    cout<<s<<endl;
}


Measured memory_bytes: 256
def resolve():
  N = int(input())
  X = [int(x) for x in input().split(" ")]
  min_X = min(X)
  max_X = max(X)
  # sigma(Xi-P) = X**2 - 2*Xi*P + P**2
  sum_of_x = sum(X)

  sum_of_squared = 0
  for x in X:
    sum_of_squared += x**2

  temp_sum_of_cost = sum_of_squared - 2 * min_X * sum_of_x + N * min_X**2
  for p in range(min_X, max_X+1):
    sum_of_cost = sum_of_squared - 2 * p * sum_of_x + N * p**2
    if sum_of_cost < temp_sum_of_cost:
      temp_sum_of_cost = sum_of_cost

  print(temp_sum_of_cost)

if __name__ == "__main__":
  resolve()

Measured memory_bytes: 62020
H, W = map(int, input().split())
res = []

for i in range(H+2):
    if i == 0 or i == H+1:
        l = '#'*(W+2)
        res.append(l)
    else:
        a = input()
        a = '#' + a + '#'
        res.append(a)

for i in res:
    print(i)


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

int main() {
    string S[200];
    for (int i = 0; i < 200; ++i) cin >> S[i];

    for (int i = 0; i < 200; ++i) {
        if (S[i] == "+") {
            int t = 0, tmp;
            for (int j = i - 1; j >= 0; --j) {
                if (S[j] != "+" && S[j] != "-" && S[j] != "*" && S[j] != "emp") {
                    t += stoi(S[j]);
                    tmp = j;
                    break;
                }
            }
            for (int j = tmp - 1; j >= 0; --j) {
                if (S[j] != "+" && S[j] != "-" && S[j] != "*" && S[j] != "emp") {
                    t += stoi(S[j]);
                    tmp = j;
                    break;
                }
            }
            S[i] = to_string(t);
            for (int j = tmp; j < i; ++j) {
                S[j] = "emp";
            }

        }
        if (S[i] == "-") {
            int t = 0, tmp;
            for (int j = i - 1; j >= 0; --j) {
                if (S[j] != "+" && S[j] != "-" && S[j] != "*" && S[j] != "emp") {
                    t -= stoi(S[j]);
                    tmp = j;
                    break;
                }
            }
            for (int j = tmp - 1; j >= 0; --j) {
                if (S[j] != "+" && S[j] != "-" && S[j] != "*" && S[j] != "emp") {
                    t += stoi(S[j]);
                    tmp = j;
                    break;
                }
            }
            S[i] = to_string(t);
            for (int j = tmp; j < i; ++j) {
                S[j] = "emp";
            }
        }
        if (S[i] == "*") {
            int t = 1, tmp;
            for (int j = i - 1; j >= 0; --j) {
                if (S[j] != "+" && S[j] != "-" && S[j] != "*" && S[j] != "emp") {
                    t *= stoi(S[j]);
                    tmp = j;
                    break;
                }
            }
            for (int j = tmp - 1; j >= 0; --j) {
                if (S[j] != "+" && S[j] != "-" && S[j] != "*" && S[j] != "emp") {
                    t *= stoi(S[j]);
                    tmp = j;
                    break;
                }
            }
            S[i] = to_string(t);
            for (int j = tmp; j < i; ++j) {
                S[j] = "emp";
            }

        }
    }

    for (int i = 0; i < 200; ++i) {
        if (S[i] != "emp") {
            cout << S[i] << endl;
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, x;
	cin >> n >> x;
	for (int i = 1; i <= n; i++) cin >> a[i];
	LL ans = 0;
	for (int i = 1; i <= n; i++)
	{
		int o = max(0, a[i] + a[i - 1] - x);
		ans += o;
		a[i] -= o;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;

int main(){
	string s ;
	cin >> s;
	string tmp = "";
	for(int i=0;i<s.size();++i){
		if(s[i] != 'x'){
			tmp += s[i];
		}
	}
	
	string tmptmp = tmp; 
	reverse(tmp.begin(),tmp.end());
	if(tmptmp == tmp){
		int res = 0;
		for(int i=0,j=s.size()-1;i <= j ;){
			if(s[i] != s[j]){
				res++;
				if(s[i] == 'x') i++;
				else if(s[j] == 'x') j--;
			}else{
				i++;
				j--;
			}
		}
		cout << res <<endl;
	}else{
		cout << -1 <<endl;
	}
	
	return 0;

}



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

int BubbleSort(int A[],int N){
	int count=0;
	bool flag=1;
	while(flag){
		flag=0;
		for(int j=N-1;j>=1;j--){
			if(A[j]<A[j-1]){
				swap(A[j],A[j-1]);
				count++;
				flag=1;
			}
		}
	}
	return count;
}

int main(){
	int num=0;
	cin >> num;
	int array[num];
	for(int i=0;i<num;i++){
		cin >> array[i];
	}
	int count = BubbleSort(array,num);
	for(int i=0;i<num-1;i++){
		cout << array[i] << " ";
	}
	cout << array[num-1] << endl << count << endl;
	return 0;
	
}

Measured memory_bytes: 3100
N=int(input())
matrix=[[0 for i in range(N)] for j in range(N)]
for i in range(N):
    a,b,*c=input().split()
    a=int(a)
    for k in c:

        matrix[a-1][int(k)-1]=1
for i in range(len(matrix)):
    print(*matrix[i])


Measured memory_bytes: 6384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            int score = Integer.parseInt(br.readLine());

            if (score >= 1200) {
                System.out.println("ARC");
            } else {
                System.out.println("ABC");
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21076
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        txy: [(i64, i64, i64)],
    }
    let n = txy.len();
    let mut txy = txy;
    txy.insert(0, (0, 0, 0));
    let ok = (0..n).all(|i| {
        let (t1, x1, y1) = txy[i];
        let (t2, x2, y2) = txy[i + 1];
        let t = t2 - t1;
        let d = (x2 - x1).abs() + (y2 - y1).abs();
        t >= d && (t + d) % 2 == 0
    });
    puts!("{}\n", if ok { "Yes" } else { "No" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 16636
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    

    long double n;
    long double k;
    cin >> n >> k;
    long double ans = 0;
    for (ll i=1;i<=n;i++){
//        cout << ans << endl;
        if(k < i){
            ans++;
        }else {
            ans += pow(1 / 2.0, ceil(log2(k / i)));
        }
    }
    cout << setprecision(20) << ans / n << endl;


}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [[int(j) for j in input().split()] for _ in range(N)]

AB = sorted(AB)

count = 0
result = 0
i = 0
while M != count:
    if 0 < AB[i][1]:
        result += AB[i][0]
        count += 1
        AB[i][1] -= 1
    else:
        i += 1
print(result)


Measured memory_bytes: 22372
#include <stdio.h>

int main(){
    int x = 1;
    int y = 1;
    while (x != 0 || y != 0){
        scanf("%d %d", &x, &y);
        if (x == 0 && y == 0){
            exit(0);
        }
        for (int i = 1; i <= x; i++){
            for (int j = 1; j <= y; j++){
                if ((i == 1 || i == x) || (j == 1 || j == y)){
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}



Measured memory_bytes: 2048
n,m = map(int, input().split())
h = list(map(int, input().split()))
#a = [list(map(int, input().split())) for _ in range(m)]
ans = [1]*n
for i in range(m):
    x,y = map(int, input().split())
    if (h[x-1] > h[y-1]):
        ans[y-1] = 0
    elif (h[x-1] < h[y-1]):
        ans[x-1] = 0
    else:
        ans[x-1] = 0
        ans[y-1] = 0
print(sum(ans))

Measured memory_bytes: 20140
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;

int n, a[maxn];

int main() {	
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    ll ans = 0, ph = 0;
    for(int i = 1; i <= n; ++i) {
        ll tmp = max(0ll, ph - a[i]);
        ans += tmp;
        ph = a[i] + tmp;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4364
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	count := 0
	for i := a; i <= b; i++ {
		str := strconv.Itoa(i)
		if str[0] == str[len(str)-1] && str[1] == str[len(str)-2] {
			count++
			// fmt.Println(str)
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
#define N 50
#define T 3000
int y[T]={0};
int num=0;
void LeapYear(void);
void Answer(int n,int m);

int main(void){
	int n,m,i;
	char str[N];

	LeapYear();
	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		sscanf(str,"%d %d",&n,&m);
		if(n==0 && m==0)
			break;
		if(num>0) printf("\n");
		Answer(n,m);
	}
	return 0;
}

void LeapYear(void){
	int i,j;
	for(i=1;i<T;i++){
		if((i%4==0 && i%100!=0) || (i%4==0 && i%400==0))
			y[i]=1;			
	}
}

void Answer(int n,int m){
	int i,cnt=0;
	for(i=n;i<=m;i++){
		if(y[i]==1){
			printf("%d\n",i);
			cnt+=1;
		}
	}
	if(cnt==0) printf("NA\n");
	num+=1;
}		

Measured memory_bytes: 636
ary = readlines.map(&:chomp)
ary.delete_at(0)

tmp = []
ary.each_with_index do |v, k|
  a, b = v.split(" ")
  tmp << [a.to_s, b.to_i, k+1]
end

tmp.sort! do |a, b|
  a[0] == b[0] ? b[1] <=> a[1] : a[0] <=> b[0]
#  (a[0] <=> b[0]) || (b[1] <=> a[1])
end
tmp.each do |v|
  puts v[2]
end

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

int main() {
  int X,A,B;
  cin >> X >> A >> B;
  X -= A;
  for(int i=0;i<10000;i++){
   if(X-B<0){
     break;
   }
   X -= B;
  }
  cout << X << endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    string s[3];
    rep(i,3)cin>>s[i];
    int a = s[0].length(),b = s[1].length();
    if(s[0][a-1]==s[1][0]&&s[1][b-1]==s[2][0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256