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

using namespace std;

int num_times_div(long long A, int d){
  int ret = 0;
  while(A % d == 0){
    A /= d;
    ret++;
  }
  return ret;
}

const int MAXN = 200100;

int st[4*MAXN][20][20];

int left(int p){
  return (p << 1);
}

int right(int p){
  return (p << 1) + 1;
}

void update(int p, int L, int R, int pos, long long A){
  if(L > pos or R < pos) return;

  if(L == R){
    for(int i = 0; i < 20; i++){
      for(int j = 0; j < 20; j++){
	st[p][i][j] = 0;
      }
    }
    int d2 = num_times_div(A, 2);
    int d5 = num_times_div(A, 5);
    st[p][min(18, d2)][min(18, d5)] = 1;
    return;
  }

  int mid = (L + R) >> 1;
  update(left(p), L, mid, pos, A);
  update(right(p), mid+1, R, pos, A);

  for(int i = 0; i < 20; i++){
    for(int j = 0; j < 20; j++){
      st[p][i][j] = st[left(p)][i][j] + st[right(p)][i][j];
    }
  }
}

void update(int pos, long long A){
  update(1, 0, MAXN-1, pos, A);
}

void query(int p, int L, int R, int i, int j, int cnt[][20]){
  if(L > j or R < i) return;

  if(L >= i and R <= j){
    for(int k = 0; k < 20; k++){
      for(int l = 0; l < 20; l++){
	cnt[k][l] += st[p][k][l];
      }
    }
    return;
  }

  int mid = (L + R) >> 1;
  query(left(p), L, mid, i, j, cnt);
  query(right(p), mid+1, R, i, j, cnt);
}

void query(int i, int j, int cnt[][20]){
  query(1, 0, MAXN-1, i, j, cnt);
}

char s[100];

long long read_value(){
  scanf("%s", s);

  int i = 0;
  while(s[i] and s[i] != '.') i++;
  int x = 9;
  
  if(!s[i]){
    s[i++] = '.';
    s[i] = 0;
  } else {
    i++;
  }

  while(s[i]){
    i++; x--;
  }

  while(x--){
    s[i++] = '0';
  }
  s[i] = 0;

  long long ret = 0;
  for(int i = 0; s[i]; i++){
    if(s[i] != '.') ret = ret*10 + s[i] - '0';
  }

  return ret;
}

int main(){
  int N;
  while(scanf("%d", &N) > 0){
    long long ans = 0;
    int cnt[20][20];
    memset(cnt, 0, sizeof cnt);

    for(int i = 0; i < N; i++){
      long long A = read_value();

      int d2 = num_times_div(A, 2);
      int d5 = num_times_div(A, 5);

      for(int k = 0; k < 20; k++){
	for(int l = 0; l < 20; l++){
	  if(min(k+d2, l+d5) >= 18){
	    ans += cnt[k][l];
	  }
	}
      }
      
      cnt[min(d2, 19)][min(d5, 19)]++;
    }

    printf("%lld\n", ans);
  }
}


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

int sx, sy, tx, ty;

string s;

int main() {
	cin >> sx >> sy >> tx >> ty;

	for( int y = sy; y < ty; y++ ) {
		s += "U";
	}
	for( int x = sx; x < tx; x++ ) {
		s += "R";
	}
	for( int y = sy; y < ty; y++ ) {
		s += "D";
	}
	for( int x = sx; x < tx; x++ ) {
		s += "L";
	}
	s += "L";
	for( int y = sy; y < ty + 1; y++ ) {
		s += "U";
	}
	for( int x = sx; x < tx + 1; x++ ) {
		s += "R";
	}
	s += "D";
	s += "R";
	for( int y = sy; y < ty + 1; y++ ) {
		s += "D";
	}
	for( int x = sx; x < tx + 1; x++ ) {
		s += "L";
	}
	s += "U";


	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.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 EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
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 psi = pair<string, int>;
// functions
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;
}
#endif 


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

    int N, K; cin >> N >> K;
    string S; cin >> S;
    S += '$';

    char c = S[0];
    queue<int> q;
    int len = 1;
    FOR(i,1,N+1) {
        if (S[i]!=S[i-1]) {
            q.push(len);
            len = 1;
        } else {
            len++;
        }
    }

    REP(i,K) {
        if (q.size()>2) {
            int head = q.front(); q.pop();
            int mid = q.front(); q.pop();
            int tail = q.front(); q.pop();            
            q.push(head + mid + tail);
        } else if (q.size()>1) {
            int head = q.front(); q.pop();
            int tail = q.front(); q.pop();
            q.push(head + tail);
        }
    }

    int ans = 0;
    while(!q.empty()) {
        int e = q.front(); q.pop();
        ans += e - 1;
    }

    cout << ans << endl;

    return 0;
}

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


int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n; cin >> n;
    for (int i = 0; i <= 100000; i++) {
        if ((int)((double)i * 1.08) == n) {
            cout << i << '\n';
            return 0;
        }
    }

    cout << ":(\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	string s;
	cin>>s;
	if ((s[0] == s[1] && s[1] == s[2])||(s[3] == s[1] && s[1] == s[2]))cout << "Yes"<<endl;
	else cout << "No" << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using ll = int64_t;

using namespace std;

struct Sieve{

    // MAX : 1e7
    int n,p = 0;
    vector<int> prime;
    vector<bool> is_prime;

    Sieve(int n):n(n),is_prime(n+1,true){
        is_prime[0] = is_prime[1] = false;
        for(int i = 2;i <= n;i++){
            if(is_prime[i]){
                prime.push_back(i);
                p++;
                for(int j = 2 * i;j <= n;j += i) is_prime[j] = false;
            }
        }
    }

    map<int,int> prime_factor(int n){
        map<int,int> res;

        for(int i : prime){
            if(i > n) break;
            if(n % i == 0){
                int cnt = 0;
                while(n % i == 0){
                    cnt++;
                    n /= i;
                }
                res[i] = cnt;
            }
        }

        if(n != 1) res[n] = 1;

        return res;
    }

};


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64_t n;cin >> n;
    int64_t ans = 0;
    for(int64_t i = 1;i <= n;i++){
        int64_t y = n / i;
        ans += i * (y*(y+1))/2;
    }
    cout << ans << '\n';
}


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

n = int(input())
*a, = map(int, input().split())
*b, = map(int, input().split())
*c, = map(int, input().split())

ans = 0
for i in range(len(a)-1):
    ans += b[a[i]-1]
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]
ans += b[a[-1]-1]
print(ans)

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int
#define P pair<int, int>

template<typename T>
struct BBIT {
	int n;
	vector<T> d, dd;
	BBIT(int n=0):n(n),d(n+1),dd(n+1) {}
	void add(int i, T x=1) {
		i++;
		for (int j=i; j <= n; j += j&-j) {
			d[j] += x;
			dd[j] += x*(j-i+1);
		}
	}
	T sum(int i) {
		i++;
		T x = 0;
		for (; i; i -= i&-i) {
			x += d[i];
		}
		return x;
	}
	T ssum(int i) {
		i++;
		T x = 0;
		for (int j=i; j; j -= j&-j) {
			x += dd[j] + d[j]*(i-j);
		}
		return x;
	}
};

int main(){
	int n;
	cin>>n;
	vector<int> e[200000];

	vector<P> uvs;
	rep(i, n-1){
		int u, v;
		cin>>u>>v; u--; v--;
		uvs.push_back(make_pair(u, v));
		uvs.push_back(make_pair(v, u));
	}
	sort(uvs.begin(), uvs.end());
	for(P p : uvs){
		e[p.first].push_back(p.second);
	}

	ll sum=0;
	BBIT<ll> dp(n);
	rep(r, n){
		int d=1;
		for(int u : e[r]){
			if(u>r) break;
			d--;
		}
		dp.add(0, d);
		int i=0;
		for(int u : e[r]){
			if(u>r) break;
			if(u+1<n) dp.add(u+1, 1);
			d++;
		}
		if(r+1<n) dp.add(r+1, -1);
		sum+=dp.ssum(n-1);
	}
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 21884
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1e9

// dp[i] player who moves at this wins or not
bool dp[(int)(1e5+1)];
bool vis[(int)(1e5+1)];
int a[100];
int n,k;
int top(int i){
	// cout<<i<<endl;
	// if(i==0) return 0;
	if(i<a[0]) return 0;
	if(vis[i]) return dp[i];
	for(int j=0;j<n;j++){
		if(a[j]>i) break;
		if(!top(i - a[j])) {vis[i]=1;return dp[i] = 1;}
	}
	vis[i]=1;
	return dp[i] = 0;
}

int main(){
	memset(dp,0,sizeof(dp));
	memset(vis,0,sizeof(dp));
	cin>>n;cin>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	// cout<<"continue::"<<endl;
	string ans = top(k)?"First":"Second";
	cout<<ans<<endl;
}

Measured memory_bytes: 6740
from functools import reduce
n, k = map(int, input().split())
p = list(map(int, input().split()))

cur = sum(map(lambda x: (x + 1) * 0.5, p[:k]))
max_value = cur
l, r = 1, k
while r < n:
    cur += (p[r] - p[l-1]) * 0.5
    max_value = max(max_value, cur)
    l += 1
    r += 1
print(max_value)


Measured memory_bytes: 25308
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        HashMap<String, Integer> wordCnt = new HashMap<String, Integer>();
        String longWord = "";
        String freqWord = "";
        wordCnt.put(freqWord, 0);
        
        while (scanner.hasNext()) {
            String input = scanner.nextLine();
            String[] strList = input.split(" ");
            
            for (int i = 0; i < strList.length; i++) {
                String tmpWord = strList[i];
                if (wordCnt.get(tmpWord) == null) {
                    wordCnt.put(tmpWord, 1);
                } else {
                    wordCnt.put(tmpWord, wordCnt.get(tmpWord)+1);
                }
                if (tmpWord.length() > longWord.length()) {
                    longWord = tmpWord;
                }
                if (wordCnt.get(tmpWord) > wordCnt.get(freqWord)) {
                    freqWord = tmpWord;
                }
            }
        }
        System.out.println(freqWord + " " + longWord);
    }
}

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

using namespace std;

const int N=2005;
const int P=1000000007;

int f[N][N][2],g[N<<1][N<<1],s[N<<1];
int n,m,K,ans;

inline void update(int &x,int y){(x+=y)%=P;}

int main()
{
	//freopen("average.in","r",stdin),freopen("average.out","w",stdout);
	scanf("%d%d%d",&n,&m,&K),--m;
	for (int i=1;i<K;++i) update(f[i][K-1-i][1],1);
	update(f[0][K-1][0],1);
	for (int i=0;i<=n;++i)
	{
		for (int j=0;j<m+K;++j) s[j]=s[j+1];
		s[m+K]=0;
		for (int j=0;j<=m+K;++j) update(s[j],g[i][j]);
		for (int j=0;j<=m;++j)
			for (int k=0;k<2;++k)
			{
				if (k) update(f[i][j][k],s[j]);
				if (f[i][j][k])
				{
					if (j+K-1<=m) update(f[i][j+K-1][0],f[i][j][k]);
					update(g[i+1][j+K-2],f[i][j][k]);
					if (j) update(g[i+K][j-1],P-f[i][j][k]);
				}
			}
	}
	for (int i=0;i<=n;++i)
		for (int j=0;j<=m;++j)
			if ((i%(K-1)==n%(K-1))&&(j%(K-1)==m%(K-1)))
				update(ans,f[i][j][1]);
	printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

Measured memory_bytes: 92928
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
 
int main(){
  string s;
  long long sum[4] = {1, 0, 0, 0};
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '?') for(int j = 3; j >= 0; j--)
      sum[j] = (sum[j]*3 + (j ? sum[j-1] : 0)) % MOD;
    else sum[s[i]-'A'+1] = (sum[s[i]-'A'+1] + sum[s[i]-'A']) % MOD;
  }
  printf("%lld\n", sum[3]);
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <ll> vll;
typedef vector <vector <int>> vvi;
typedef vector <vector <long long>> vvll;
typedef vector <long long> vll;
typedef pair <int, int> pii;
typedef pair<ll , ll> pll;
typedef vector <pair <int, int>> vpii;

vvi adj(1e5 + 1);
vb visited(1e5 + 1, 0);
vi sorted;

void dfs(int u)
{
    visited[u] = 1;
    for(auto v: adj[u])
        if(!visited[v])
            dfs(v);
    sorted.push_back(u);
}

void topsort(int n)
{
    for(int i =1; i < n +1; i++)
        if(!visited[i]) 
            dfs(i);
    reverse(sorted.begin(), sorted.end());
}

int main()
{
    int n, m; cin >> n >> m;
    int u, v;
    for(int i = 0; i < m; i++)
    {
        cin >> u >> v; 
        adj[u].push_back(v);
    }
    topsort(n);
    //--------------

    vi state(n, 0);
    for(auto u: sorted)
    {
        for(auto v: adj[u])
            state[v -1] = min(state[v -1], state[u -1] -1);
    }
    int ans = INT_MAX;
    for(auto i: state)
        ans = min(ans, i);
    cout << -ans <<endl;
}

Measured memory_bytes: 8696
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int pa[maxn],sz[maxn];
struct edge{
    int u,v;
    long long w;
    bool operator <(const edge &x){
        return w<x.w;
    }
    edge(int _u,int _v,long long _w):
        u(_u), v(_v), w(_w){}
};
int fi(int x){
    return x==pa[x]?x:pa[x]=fi(pa[x]);
}
void kruskal(vector<edge> &e){
    sort(e.begin(),e.end());
    long long sum=0;
    for(auto j:e){
        int u=fi(j.u),v=fi(j.v);
        if(u==v)continue;
        if(sz[u]<sz[v])swap(u,v);
        sz[u]+=sz[v];
        pa[v]=u;
        sum+=j.w;
    }
    printf("%lld\n",sum);
    exit(0);
}
int n,d,a[maxn];
vector<edge> e;
void dc(int l,int r){
    if(l==r)return;
    int mid=(l+r)>>1;
    dc(l,mid);dc(mid+1,r);
    long long ma=1e17;
    int idx=-1;
    for(int i=l;i<=mid;i++){
        long long c=a[i]-1LL*d*i;
        if(c<ma){
            ma=c;
            idx=i;
        }
    }
    int idx2=-1;
    ma=1e17;
    for(int i=mid+1;i<=r;i++){
        long long c=a[i]+1LL*d*i;
        if(c<ma){
            ma=c;
            idx2=i;
        }
    }
    for(int i=l;i<=mid;i++){
        e.push_back(edge(i,idx2,0LL+a[i]+a[idx2]+1LL*d*(idx2-i)));
    }
    for(int i=mid+1;i<=r;i++){
        e.push_back(edge(i,idx,0LL+a[i]+a[idx]+(1LL*d*(i-idx))));
    }
    return;
}

int main(){
    scanf("%d%d",&n,&d);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++){
        pa[i]=i;
        sz[i]=1;
    }
    dc(1,n);
    kruskal(e);
}


Measured memory_bytes: 70240
# AGC088 D - Grid Repainting
from collections import deque
def bfs(sy,sx,gy,gx):
    q = deque([[sy,sx]])
    visited[sy][sx]=0
    while q:
        y,x = q.popleft()
        if [y,x]==[gy,gx]:
            return visited[y][x]
        for j,k in ([1,0],[-1,0],[0,1],[0,-1]):
            ny,nx = y+j,x+k
            if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":
                continue
            if path[ny][nx]=="." and visited[ny][nx]==-1:
                visited[ny][nx]=visited[y][x]+1
                q.append([ny,nx])

h,w=map(int,input().split())
sy,sx=0,0
gy,gx=h-1,w-1
path=[input() for i in range(h)]
visited = [[-1]*w for i in range(h)]
bfs(sy,sx,gx,gy)

ans=0
black=0
for p in path:
    black+=p.count('#')
if visited[gy][gx]==-1:
    print(-1)
else:
    ans=h*w-(visited[gy][gx]+1)-black
    print(ans)


Measured memory_bytes: 3316
import sys

import numpy as np
def sieve_of_eratosthenes(n=5 * 10 ** 7):
  sieve = np.ones(n + 1); sieve[:2] = 0
  for i in range(2, int(np.sqrt(n)) + 1):
    if sieve[i]: sieve[i*2::i] = 0
  return sieve, np.flatnonzero(sieve)

is_prime, prime_numbers = sieve_of_eratosthenes()

def prime_factorize(n):
  res = dict()
  if n < 2: return res
  border = int(n ** 0.5)
  for p in prime_numbers:
    if p > border: break
    while n % p == 0: res[p] = res.get(p, 0) + 1; n //= p
    if n == 1: return res
  res[n] = 1
  return res

def prime_factorize_factorial(n):
  res = dict()
  for i in range(2, n + 1):
    for p, c in prime_factorize(i).items(): res[p] = res.get(p, 0) + c
  return res

x = int(sys.stdin.readline().rstrip())

def main():
    i = np.searchsorted(prime_numbers, x, side='left')
    print(prime_numbers[i])

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 426528
import scala.io.Source

object Main{
  def main(args: Array[String]){
    val line =
      for{
        in <-Source.stdin.getLines.toList
      } yield in.map(c => c.toLower)

    println(line.tail.mkString(" ").split(" ").filter(_ == line(0)).length)
  }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
const double PI=acos(-1.0);
const int INF=1e9;
const double EPS=1e-10;
const ll MOD=1e9+7;


int main(){
int p,q,r,mi;
cin>>p>>q>>r;
if(p>=q&&p>=r)mi=q+r;
else if(q>=p&&q>=r)mi=p+r;
else if(r>=p&&r>=q)mi=p+q;

cout<<mi<<endl;
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * 与えられた数(swap[])の各桁の和を計算するプログラムを作成する。
 * @author U633758
 *
 */
public class Main {

	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args){

		for(;scan.hasNext();){
			int sum=0;
			char[] swap = scan.nextLine().toCharArray();	//char型の配列に格納する


			for(int i=0;i<swap.length;i++){
				sum = sum + Character.getNumericValue(swap[i]);
			}
			if(sum != 0){
				System.out.println(sum);
			}else{
				break;
			}
		}
	}
}


Measured memory_bytes: 26756
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	int N, H;
	
	cin >> N >> H;
	vector<int> a(N), b(N);
	REP(i, N) {
		cin >> a[i] >> b[i];
	}

	sort(a.begin(), a.end(), greater<int>());
	sort(b.begin(), b.end(), greater<int>());

	int cnt = 0;
	
	REP(i, N) {
		if (H <= 0 || b[i] < a[0]) {
			break;
		}
		if (b[i] >= a[0]) {
			H -= b[i];
			cnt++;
		}

	}
	if (H > 0) {
		cnt += (H + a[0] - 1) / a[0];
	}
	cout << cnt << endl;




	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
連結かどうかを判定するのに探索してたら間に合わないかな
mapで間に合うか。
いや、連結なら、だったか・・・。unionか
*/
vector<vector<ll>> G;
vector<bool> seen;
struct UnionFind{
  vector<ll> par,siz;
  
  UnionFind(ll N):par(N+1),siz(N+1,1){
    for(int i=0; i<=N; i++)
      par[i]=i;
  }
  
  void mkpar(ll n, ll set){//親はset=根
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=set;
      mkpar(next_n, set);
    }
  }

  void mkpar2(ll n){//親は1個上、引数1個
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n] = true;
      par[next_n] = n;
      mkpar2(next_n);
    }
  }

  ll root(ll x){
    if(par[x]==x)
      return x;
    return par[x]=root(par[x]);
  }
  
  void unite(ll x, ll y){
    ll rx=root(x), ry=root(y);
    if(rx==ry)
      return;
    par[ry]=rx;
    siz[rx]+=siz[ry];    
  }
  
  bool issame(ll x, ll y){
    return root(x)==root(y);
  }
  
  ll size(ll x){
    return siz[root(x)];
  }
};

int main(){
  ll N, Q;
  cin >> N >> Q;
  G.assign(N+1, vector<ll>());
  seen.assign(N+1,false);
  UnionFind tree(N);
  for(int i = 0; i < Q; i++){
    ll t, u, v;
    cin >> t >> u >> v;
    if (t == 0){
      G[u].emplace_back(v);
      G[v].emplace_back(u);
      tree.unite(u, v);
    }
    else {
      if (tree.issame(u, v))
        cout << 1 << endl;
      else
        cout << 0 << endl;
    }
  }
}

Measured memory_bytes: 13324
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <math.h>
using namespace std;


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

	long double a;
	long double sum = 0;

	for(int i=0;i<N;i++){
		cin >> a;
		sum += 1.0/a;
	}
	cout << 1.0/sum << endl;

}


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


int main()
{
  int n, t;
  cin >> n >> t;
  vector<pair<int, int>> f(n);
  rep(i, n)
  {
    int a, b;
    cin >> a >> b;
    f[i].first = a;
    f[i].second = b;
  }
  sort(f.begin(), f.end());
  vector<vector<int>> dp(n + 1, vector<int>(t + 1, 0));
  rep(i, n)
  {
    dp[i+1][t] = max(dp[i][t], dp[i][t-1] + f[i].second);
    for (int j = 1; j < t; j++)
    {
      dp[i+1][j] = max(dp[i][j], dp[i+1][j-1]);
      if (f[i].first <= j)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j-f[i].first] + f[i].second);
    }
  }
  cout << dp[n][t] << endl;
  return 0;
}

Measured memory_bytes: 35584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		String s = sc.next();
		String t = sc.next();
		
		char[] schar = s.toCharArray();
		char[] tchar = t.toCharArray();
		
		for(int i = 0; i < s.length(); i++) {
			if(Arrays.equals(schar, tchar)) {
				System.out.println("Yes");
				return;
			}
			
			char[] n = new char[s.length()];
			
			n[0] = schar[s.length()-1];
			
			for(int j = 0; j < s.length()-1; j++) {
				n[j+1] = schar[j];
			}
			
			schar = n;
		}
		
		out.println("No");
		
		out.flush();
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	
	long long int x,a=100;
	cin>>x;
	int ans = 0;
	while(a<x){
		a = a*1.01;
		ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;

#define MXN 105
int N,K;
vector<int> G[MXN];
vector<pii> E;

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

    cin>>N>>K;
    if( K > (N-1)*(N-2)/2 )
    {
        cout<<-1<<'\n';
        return 0;
    }

    int now = (N-1)*(N-2)/2;
    FOR(i,2,N)E.pb(mkp(1,i));

    FOR(i,2,N-1)FOR(j,i+1,N)
        if( now>K )
        {
            E.pb( mkp(i,j) );
            now--;
        }

    cout<<SZ(E)<<'\n';
    for( pii Ei : E )cout<<Ei.f<<' '<<Ei.s<<'\n';

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int max=1;
	    int t=0;

	    for (int i=0; i<N;i++) {
	    	int a=gi();
	    	int b=gi();
	    	if (a>=max) {
	    		max=a;
	    		t=b;
	    	}
	    }
	    System.out.println(max+t);
	}

	public static double f(double r, double n, double m, double i) {
		double a = 0;
		double b=0;
		if(0<i&&i<n) {
			a=Math.abs(r-((2*r/n)*i));
			a= Math.sqrt(Math.pow(r, 2) - Math.pow(a, 2));
		}
		if(0<i-m&&i-m<n) {
			b=Math.abs(r-(2*r*(i-m)/n));
			b=Math.sqrt(Math.pow(r, 2) - Math.pow(b, 2));
		}
		return 2* Math.max(a, b);
	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 58772
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int n;
int a[101];
int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	reverse(a,a+n);
	int all=n;
	for(int i=n-1;i>=0;i--){
		if(a[i]==0)all--;
		else break;
	}
	int zero=all;
	for(int i=all-1;i>=0;i--){
		if(a[i]==1)all--;
		else break;
	}
	int sw=(n-all)-(zero-all);
	sort(a+all,a+n);
	if((n-zero)%2==1){
		if(zero-all>=1)swap(a[all+sw-1],a[all+sw]);
		else{
			for(int i=all-1;i+2<n;i+=2){
				swap(a[i],a[i+2]);
			}
			all--;
		}
	}
	if(all>=0)sort(a,a+all);
	if(all>=2 && a[all-2]==2 && a[all-1]==3)swap(a[all-2],a[all-1]);
	for(int i=0;i<n;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}

Measured memory_bytes: 1048
#include <iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	int ans=-1;
	ans=max(ans,a*10+b+c);
	ans=max(ans,a+b*10+c);
	ans=max(ans,a+b+c*10);
    printf("%d\n",ans);





    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define si( x ) scanf("%d", &x)
#define sll( x ) scanf("%lld", &x)
#define mp make_pair
#define pb push_back
using namespace std;

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

vector < int > v;
int n, res;

int main()
{
	cin >> n; v.resize(n+2);
	for(int i = 1 ; i <= n ; i++){
		cin >> v[i];
		res += abs(v[i-1]-v[i]);
	}
	res += abs(v[n]);
	
	for(int i = 1 ; i <= n ; i++){
		int now = res;
		now -= abs(v[i-1]-v[i]);
		now -= abs(v[i]-v[i+1]);
		now += abs(v[i-1]-v[i+1]);
		cout << now << endl;
	}
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const double INF = 1e+18;

struct edge{
    int from, to;
    double cost;
};

template <typename T>
bool bellmanFord(int s, vector<T>& d, vector<vector<edge>>& G){
    int V = G.size();

    d[s] = 0;
    REP(i, V){
        for(auto e: G[i]){
            if(e.from == INF) continue;
            if(d[e.to] > d[e.from]+e.cost){
                d[e.to] = d[e.from]+e.cost;
                if(i == V-1) return false;
            }
        }
        cout << i << " ";
        REP(i, V) cout << d[i] << " ";
        cout << endl;
    }
    return true;
}

template <typename T>
void dijkstra(int s, vector<T>& d, vector<vector<edge>>& G){
    d[s] = 0;

    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
    q.push({(T) 0, s});
    while(!q.empty()){
        auto tmp = q.top(); q.pop();
        T d_min = tmp.first;
        int v = tmp.second;
        if(d[v] < d_min) continue;
        for(auto e: G[v]){
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                q.push({d[e.to], e.to});
            }
        }
    }
}

int main()
{
    int xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    int N;
    cin >> N;
    vector<int> x(N+2), y(N+2), r(N+2);
    FOR(i, 1, N+1) cin >> x[i] >> y[i] >> r[i];

    x[0] = xs, y[0] = ys, r[0] = 0;
    x[N+1] = xt, y[N+1] = yt, r[N+1] = 0;

    vector<vector<edge>> G(N+2);
    REP(i, N+2){
        FOR(j, i+1, N+2){
            double d = max(0., sqrt(pow(x[i]-x[j], 2) + pow(y[i]-y[j], 2)) - (r[i]+r[j]));
            G[i].push_back({i, j, d});
            G[j].push_back({j, i, d});
        }
    }

    vector<double> d(N+2, INF);
    dijkstra<double>(0, d, G);
    cout << setprecision(10) << d[N+1] << endl;

    return 0;
}

Measured memory_bytes: 22256
N, M, C = map(int, raw_input().split())
B = map(int, raw_input().split())
A = [map(int, raw_input().split()) for _ in range(N)]

c = 0
for a in A:
  res = 0
  for _a, _b in zip(a, B):
    res += _a * _b
  res += C
  if res > 0:
    c += 1
print c

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n; scanf("%d", &n);
	ld k = (n+1)/2;
	printf("%.30Lf\n", k/n);
}


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

int main(){
	int n,m;
	cin>>n>>m;
	int d;
	set<int> s;
	for(int i=0;i<m;i++){
		cin>>d;
		for(int i =0;i<d;i++){
			int A;
			cin>>A;
			s.insert(A);
		}
	}

	cout<<n-s.size()<<endl;
}

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

int main(){
  string S;
  cin>>S;
  char c1 = S[0], c2;
  
  for (int i = 1; i < 4; i++)
    if (S[i] != c1) {
      c2 = S[i];
      break;
    }
  
  for (int i = 1; i < 4; i++)
    if (S[i] != c1 && S[i] != c2) {
      cout << "No\n";
      return 0;
    }
  
  int cnt1 = 1, cnt2 = 0;
  for (int i = 1; i < 4; i++)
    if (S[i] == c1) cnt1++;
    else cnt2++;
  
  cout << (cnt1 == cnt2 ? "Yes\n" : "No\n");
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
const int MOD=1e9+7;
const double eps=1e-8;
typedef long long ll;
//orz yht
using namespace std;
int n,m,edge[15][15],sco[32770];
int dp[15][32770];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out"，"w",stdout);
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		a--;
		b--;
		edge[a][b]=edge[b][a]=c;
	}
    for(int i=0;i<(1<<n);i++){
        sco[i]=0;
        for(int j=0;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(i&(1<<j) && i&(1<<k))
                sco[i]+=edge[j][k];
            }
        }
    }
    memset(dp,-INF,sizeof dp);
    for(int i=1;i<(1<<n);i+=2)
    dp[0][i]=sco[i];
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            if(dp[j][i]<0)
			continue;
            int msk=(1<<n)-1-i;
            for(int sub=msk;sub>0;sub=(sub-1)&msk){
                for(int k=0;k<n;k++){
                    if(edge[j][k] && (sub&(1<<k)))
                    dp[k][i+sub]=max(dp[k][i+sub],dp[j][i]+sco[sub]+edge[j][k]);
                }
            }
        }
    }
    ll cnt=0;
    for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
    cnt+=edge[i][j];
    cout<<cnt-dp[n-1][(1<<n)-1];
	return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#define M_P 10001

int prime[M_P];

void eratosthenes(void) {
    int i, j;
    prime[0] = 1;
    prime[1] = 1;
    for(i = 2; i < M_P; i++ ) {
       for(j = i; j * i < M_P; j++ ) {
           prime[i * j] = 1;
       }
    }
}

/*int prime_pick(int prime_only[]) {
    int i, j = 0;
    for(i = 2; i < M_P; i++ ) {
        if(!prime[i]) {
            prime_only[j] = prime[i];
            j++;
        }
    }
    return --j;
}*/

int main(void) {
    int i, n;
    eratosthenes();
    //p_max = prime_pick(primes);
    while(scanf("%d",&n), n != 0 ) {
        for(i = n; i > 0; i-- ) {
            if(!prime[i]) {
                if(!prime[i - 2]) {
                    printf("%d %d\n",i-2, i);
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 636
N,M=map(int,input().split())
if N%2==0:
    for i in range(1,(M+1)//2+1):
        print(i,N-i+1)
    for i in range(M-(M+1)//2):
        print(M-i,M+i+2)
else:
    for i in range(1,M+1):
        print(i,N-i)
        

Measured memory_bytes: 9240
data = []
n = int(input())
for i in range(n):
    data.append(list(map(int, input().split())))
    data[i] = sorted(data[i])[::-1]

for j in range(n):
    if data[j][0]**2 == data[j][1]**2 + data[j][2]**2:
        print('YES')
    else:
        print('NO')

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

using namespace std;

typedef long long ll;

long long test_cases;
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    /* cin >> test_cases; */
    test_cases = 1;

    int c = 0, t;
    while (test_cases > 0)
    {
        int x, y;
        
        cin >> x >> y;

        t = x;
        for (int i = 0; i <= x; i++)
        {
            
            if (y == 2*c + 4*t)
            {
                cout << "Yes\n";
                return 0;
            }
            c++;
            t--;
        }

        cout << "No\n";
        test_cases--;
    }

    
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int main() {
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
    for (int i = 0; i < tx - sx; ++i) {
        cout << "R";
    }
    for (int i = 0; i < ty - sy; ++i) {
        cout << "U";
    }
    for (int i = 0; i < tx - sx; ++i) {
        cout << "L";
    }
    for (int i = 0; i < ty - sy; ++i) {
        cout << "D";
    }
    cout << "D";
    for (int i = 0; i < tx + 1 - sx; ++i) {
        cout << "R";
    }
    for (int i = 0; i < ty + 1 - sy; ++i) {
        cout << "U";
    }
    cout << "L";
    cout << "U";
    for (int i = 0; i < tx + 1 - sx; ++i) {
        cout << "L";
    }
    for (int i = 0; i < ty + 1 - sy; ++i) {
        cout << "D";
    }
    cout << "R";
    cout << endl;
}


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

int x, n;
int p[100];
bool used[102];

int main() {
	int i;
	
	cin >> x >> n;
	for (i = 0; i < n; i++) {
		cin >> p[i];
		used[p[i]] = true;
	}
	
	int minScore = 114514;
	int ans = -1;
	for (i = 0; i < 102; i++) {
		if (!used[i]) {
			int score = abs(i - x);
			if (minScore > score) {
				minScore = score;
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
N, M = map(int, input().split())
S = input()
T = input()

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x % y == 0:
        return y
    else:
        return gcd(y,x%y)

def lcm(m,n):
    return int(m * n /gcd(m,n))

d = gcd(N,M)
l = lcm(N,M)

s = [0 for i in range(0,d)]
t = [0 for i in range(0,d)]

a = int(l/M)
b = int(l/N)

for i in range(0,d):
    s[i] = S[i*a]
    t[i] = T[i*b]

if s == t:
    print(l)
else:
    print(-1)

Measured memory_bytes: 41584
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll n, k;
vector<int> prime_factor(int n) {
  vector<int> res;
  for(int i=2; i*i<=n; i++) {
    res.push_back(i);
    while (n % i == 0) {
      n /= i;
    }
  }
  if(n != 1) res.push_back(n);
  return res;
}

ll mpow(ll x, ll p) {
  ll result = 1;
  for(; p>0; p >>= 1, x = x * x % mod) {
    if(p & 1) result = result * x % mod;
  }
  return result;
}

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

  cin >> n >> k;

  ll ans = 0;
  map<int, ll> mp;
  for(int i=k; i>0; i--) {
    ll nn = mpow((k / i), n);
    for(int j=i; j<=k; j+=i) {
      if(nn - mp[j] < 0) nn = nn - mp[j] + mod;
      else nn -= mp[j];
    }
    mp[i] = nn;

    ans = (ans + (i * nn % mod)) % mod;
  }

  cout << ans << endl;
}


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

int N;
vector<ll> a;

int main() {
    cin >> N;
    a.resize(N);
    map<int, int> cnt;

    rep(i, N) {
        cin >> a[i];
        cnt[a[i]] += 1;
    }

    if (cnt.count(0) == 1) {
        if (cnt[0] == N) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    if (N % 3 != 0) {
        cout << "No" << endl;
        return 0;
    }

    if (cnt.size() == 3) {
        int xor3 = 0;
        for (auto &e : cnt) {
            if (e.second != N / 3) {
                cout << "No" << endl;
                return 0;
            }
            xor3 = xor3 ^ e.first;
        }
        if (xor3 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }

    if (cnt.size() == 2) {
        if (cnt.count(0) == 0) {
            cout << "No" << endl;
            return 0;
        }

        for (auto &e : cnt) {
            if (e.first == 0) {
                if (e.second != N / 3) {
                    cout << "No" << endl;
                    return 0;
                }
            }
            else {
                if (e.second != 2 * N / 3) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int q;
	cin>>q;
	int t,f;
	string c;
	char k;
	int z;
	
	while(q!=0){
		cin>>t;
		if(t==1){
			z++;
		}
		else{
			cin>>f;
			cin>>c;
			k=c[0];
			
			if((f+z-1)%2==0){
				s.insert(0,c);
			}
			else{
				s.push_back(k);
			}
		}
		q--;
	}
	if(z%2==1){
		reverse(s.begin(),s.end());
	}
	cout<<s<<endl;
	return 0;

	
}

Measured memory_bytes: 900
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const int big=1e9+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
int main(void){
	int n,m,i,j;cin>>n>>m;
	multiset<tuple<int,int,int>>go;//出発地点,会社,行先
	for(i=0;i<m;i++){
		int p,q,c;cin>>p>>q>>c;p--;q--;
		go.ins(mt(p,c,q));
		go.ins(mt(q,c,p));
	}
	set<pair<int,int>>kita;
	deque<tuple<int,int,int>> tap;//地点,会社,コスト
	tap.pub(mt(0,0,0));
	while(!tap.empty()){
		int ti,ka,co;
		tie(ti,ka,co)=tap.front();
		if(ti==n-1){cout<<co<<endl;return 0;}
		tap.pof();
		if(kita.find(mp(ti,ka))!=kita.end()){continue;}
		kita.ins(mp(ti,ka));
		if(ka==0){
			for(auto itr=go.lower_bound(mt(ti,0,0));itr!=go.upper_bound(mt(ti,mod,mod));itr++){
				tap.pub(mt(ti,get<1>(*itr),co+1));
			}
		}else{
			for(auto itr=go.lower_bound(mt(ti,ka,0));itr!=go.upper_bound(mt(ti,ka,mod));itr++){
				tap.puf(mt(get<2>(*itr),ka,co));
			}
			tap.puf(mt(ti,0,co));
		}
	}
	cout<<-1<<endl;
	RE;
}

Measured memory_bytes: 44160
while (n = gets.chomp.to_i) != 0
  s,t,b = gets.chomp.split

  rooms = {
    [0,0] => {name: "A", value: 0.0}, 
    [0,1] => {name: "B", value: 0.0}, 
    [0,2] => {name: "C", value: 0.0}, 
    [1,0] => {name: "D", value: 0.0}, 
    [1,1] => {name: "E", value: 0.0}, 
    [1,2] => {name: "F", value: 0.0}, 
    [2,0] => {name: "G", value: 0.0}, 
    [2,1] => {name: "H", value: 0.0}, 
    [2,2] => {name: "I", value: 0.0}
  } 

  rooms.each_value{|room| room[:value] = 1 if room[:name] == s}
  rooms.delete_if{|k, v| v[:name] == b}

  n.times do |n|
    tmp = {
      [0,0] => 0.0, [0,1] => 0.0, [0,2] => 0.0,
      [1,0] => 0.0, [1,1] => 0.0, [1,2] => 0.0,
      [2,0] => 0.0, [2,1] => 0.0, [2,2] => 0.0
    }
    rooms.each do |k, v|
      if v[:value] != 0.0
        row = k[0]
        column = k[1]
        p = v[:value] / 4.0
        #up
        if rooms.has_key?([row-1, column])
          rooms[k][:value] -= p
          tmp[[row-1, column]] += p
        else
          tmp[[row, column]] += p
        end
        #down
        if rooms.has_key?([row+1, column])
          rooms[k][:value] -= p
          tmp[[row+1, column]] += p
        else
          tmp[[row, column]] += p
        end
        #left
        if rooms.has_key?([row, column-1])
          rooms[k][:value] -= p
          tmp[[row, column-1]] += p
        else
          tmp[[row, column]] += p
        end
        #right
        if rooms.has_key?([row, column+1])
          rooms[k][:value] -= p
          tmp[[row, column+1]] += p
        else
          tmp[[row, column]] += p
        end
      end
    end
    rooms.each_key do |k|
      rooms[k][:value] = tmp[k]
    end
  end
  rooms.each_value do |v|
    puts v[:value] if v[:name] == t
  end
end

Measured memory_bytes: 6176
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef unsigned long long ULL;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=1e9+7;
const int maxn =1e6+11;


int n;

int main(){

    int n;read(n);
    n%=1000;
    if(n) n=1000-n;
    cout<<n<<endl;

    return 0;
}

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

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int n, r;

	cin >> n >> r;

	if (n >= 10) {
		cout << r << endl;
	}
	else {
		cout << r + 100 * (10 - n) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	char O[50];
	char E[50];

	scanf("%s",O);
	scanf(" %s",E);

	for(int i=0;i<=100;i++){
		if(O[i] == 0) break;
		printf("%c",O[i]);
		if(E[i] == 0) break;
		printf("%c",E[i]);
	}
	printf("\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

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

const int MAX = 2000005;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

void solve() {
  COMinit();
  int n, k;
  cin >> n >> k;
  rep3(i, 1, k + 1) {
    ll ans = COM((k - i) + (i - 1), i - 1);
    (ans *= COM((n - k) - (i - 1) + i, i)) %= mod;
    cout << ans << '\n';
  }
}


Measured memory_bytes: 47104