akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

  long double a, b, h, m;
	cin >> a >> b >> h >> m;

  // cout << hth << "\n";
  long double mth = 6 * m;
  long double hth = 0.5 * (h*60+m);
  // cout << mth << "\n";
  long double sath;
  if (abs(mth-hth)>=180) {
    sath = 360 - abs(mth-hth);
  } else {
    sath = abs(mth-hth);
  }
  long double sar = abs(b-a);

  if (sath==90) {
    cout << sqrt(pow(a, 2)+pow(b, 2)) << "\n";
  } else if (sath==0) {
    cout << sar << "\n";
  } else {
    static const double pi = 3.141592653589793238462643383279;

    // long double hko = 2*a*sin(pi*sath/360);
    // long double mko = 2*b*sin(pi*sath/360);
    //
    // long double sako2 = abs(mko-hko)/2;
    // long double lar;
    // if (mko > hko) {
    //   lar = mko;
    // } else {
    //   lar = hko;
    // }
    // long double ans = sqrt(pow(lar-sako2, 2)+pow(sar,2)-pow(sako2, 2));
    long double ans = sqrt(pow(a, 2)+pow(b, 2)-2*a*b*cos(pi*sath/180));

  	cout << fixed << setprecision(20) << ans << "\n";
  }


}


Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main (void)
{
	int a[4];
	for (int i = 0; i < 4; i++)
	{
		cin >> a[i];
	}
	
	sort (a,a + 4);
	if (a[0] == a[1] && a[2] == a[3])
	{
		cout << "yes" << endl;
	}
	else
	{
		cout << "no" << endl;
	}
}


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

using namespace std;
using ll = long long;

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

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

  int mx = 0;
  rep(i, n) mx = max(mx, a[i]);
  int k = 0;
  while (mx > 0) {
    mx /= 2;
    ++k;
  }

  int ans[n][k];

  rep(i, k) {
    vector<int> same(n);
    int z = a[0] >> i & 1;
    // cout << z << endl;
    rep(j, n) {
      same[j] = z == (a[j] >> i & 1);
      // cout << (a[j] >> i & 1);
    }
    // cout << endl;
    // rep(j, n) cout << same[j];
    // cout << endl;
    int sum = 0;
    for (int j = 1; j < n; ++j) sum += same[j];
    int x = (sum % 2 == z % 2);
    rep(j, n) {
      if (same[j])
        ans[j][i] = x;
      else
        ans[j][i] = (x + 1) % 2;
    }
  }

  rep(i, n) {
    int b = 0;
    rep(j, k) {
      int res = 1;
      rep(r, j) res *= 2;
      b += res * ans[i][j];
    }
    cout << b;
    if (i == n - 1)
      cout << endl;
    else
      cout << " ";
  }
  return 0;
}


Measured memory_bytes: 28492
N = int(input())
X = list(map(int, input().split()))
Xcopy = X[::]
X.sort()
left = X[N//2 - 1]
right = X[N//2]

for i in range(N):
    if Xcopy[i] <= left:
        print(right)
    elif Xcopy[i] >= right:
        print(left)

Measured memory_bytes: 26772
#include <iostream>
#define MAX 100
#define INF (1<<21)
#define WHITE 0
#define GRAY  1
#define BLACK 2 
using namespace std;

int n, adj_M[MAX][MAX];

void Dijkstra()
{
    int next, min_cost;
    int min_dist[n+1], color[n+1], parent[n+1];

    for (int i = 0; i < n; ++i) 
    {
        color[i]  = WHITE;
        parent[i] = -1;
        min_dist[i] = INF;
    }

    min_dist[0] = 0;

    while (true) 
    {
        min_cost = INF;
        next = -1;
        for (int i = 0; i < n; ++i) 
        {
            if (color[i] != BLACK && min_dist[i] < min_cost) 
            {
                min_cost = min_dist[i];
                next = i;
            }
        }
        if (next == -1) break;
        color[next] = BLACK;

        for (int i = 0; i < n; ++i) 
        {
            if (color[i] != BLACK && adj_M[next][i] != INF)
            {
                if (min_dist[next] + adj_M[next][i] < min_dist[i])
                {
                    color[i] = GRAY;
                    min_dist[i] = min_dist[next] + adj_M[next][i];
                    parent[i] = next;
                }
            }
        }
    }

    for (int i = 0; i < n; ++i) 
    {
        cout << i << ' ' << min_dist[i] << endl;
    }
}

int main() 
{
    int id, deg, n_id, n_w;
    cin >> n; 

    for (int i = 0; i < n; ++i) 
    {
        for (int j = 0; j < n; ++j) 
        {
            adj_M[i][j] = INF;
        }
    }

    for (int i = 0; i < n; ++i) 
    {
        cin >> id >> deg;
        for (int j = 0; j < deg; ++j) 
        {
            cin >> n_id >> n_w;
            adj_M[id][n_id] = n_w;
        }
    }

    Dijkstra();
}


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

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

int main(void){
  	int n,k; 
  	cin >>n >>k;
  	int r,s,p; 
  	cin >>s >>p >>r;
  	string str; 
  	cin >>str;
  	int ans=0;
  	REP(i,n){
   		int hand;
    	if(str[i]=='r') hand=r;
    	if(str[i]=='p') hand=p;
    	if(str[i]=='s') hand=s;
    	if(i>=k && str.at(i)==str.at(i-k)){
      		hand=0;
      		str[i]='x';
    	}
    	ans+=hand;
  	}
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 512
from itertools import combinations

n,k = map(int,input().split())
Px = sorted([list(map(int,input().split())) for i in range(n)])
Py = sorted(Px,key=lambda p:p[1])

area = float('inf')

for x1 in range(n-1):
    for x2 in range(x1+1,n):
        for y1 in range(n-1):

            point = 0
            for y in range(y1,n):
                if Px[x1][0]<=Py[y][0]<=Px[x2][0]:
                    point += 1
                    if point == k:
                        area = min(area,(Px[x2][0]-Px[x1][0])*(Py[y][1]-Py[y1][1]))
                        break

print(area)

Measured memory_bytes: 44268
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}



void printtree(int nn, int k){
  int n = nn - nn % 2;

  REP(i, n / 2){
    int a = 1 + (i + k) % n;
    int b = 1 + (n - i + k - 1) % n;
    printf("%d %d\n", a, b);
  }

  REP(i, n / 2 - 1){
    int a = 1 + (n - i - 1 + k) % n;
    int b = 1 + (i + k + 1) % n;
    printf("%d %d\n", a, b);
  }

  if(nn % 2) printf("%d %d\n", k + 1, nn);
}

int main(){
  int n = getInt();
  int k = getInt();

  if(n / 2 < k){ puts("-1"); }
  else{
    REP(i,k){
      printtree(n, i);
      puts("");
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <ctype.h>

int main(void){
  char ch;
  for (;;) {
    scanf("%c", &ch);
    if (ch == '\n')
      break;
    else if ('A' <= ch && ch <= 'Z')
      printf("%c", tolower(ch));
    else if ('a' <= ch && ch <= 'z')
      printf("%c", toupper(ch));
    else
      printf("%c", ch);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		char[][] a = new char[n][];
		char[][] b = new char[m][];
		for (int i = 0; i < n; i++) {
			a[i] = sc.next().toCharArray();
		}
		for (int i = 0; i < m; i++) {
			b[i] = sc.next().toCharArray();
		}
		for (int i = 0; i < n - m + 1; i++) {
			L: for (int j = 0; j < n - m + 1; j++) {
				for (int ii = 0; ii < m; ii++) {
					for (int jj = 0; jj < m; jj++) {
						if (a[i + ii][j + jj] != b[ii][jj]) {
							continue L;
						}
					}
				}
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

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


Measured memory_bytes: 20820
N = int(input())
A = list([0]*N)
A = list(map(int, input().split()))

cnt = 0
flag = False
while 1:
    for i in range(N):
        if A[i] % 2 != 0:
            flag = True
            break
        A[i] = A[i] /2
    if flag:
        break
    cnt += 1
print(cnt)

Measured memory_bytes: 9188
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		ArrayList<Integer> al=new ArrayList<>();
		HashSet<Integer> set =new HashSet<>();
		int []arr=new int[n+1];
		for(int i=1;i<=n;i++) {
			int x=scn.nextInt();
			arr[i]=x;
			if(i>=n/2+1&&arr[i]==1) {
				set.add(i);
			}
		}
		for(int j=n/2;j>=2;j--) {
			int sum=0;
			for(int i=2;i<=n/2;i++) {
				//System.out.println(i+" "+j);
				if(i*j<=n) {
					if(set.contains(i*j))
					sum+=1;
				}else {
					break;
				}
			}
			if((sum%2==0&&arr[j]==1)||(sum%2==1&&arr[j]==0)) {
				//System.out.println(sum+" sum");
				set.add(j);
			}
		}
		if((set.size()%2==0&&arr[1]==1)||(set.size()%2!=0&&arr[1]==0)) {
			set.add(1);
		}
		System.out.println(set.size());
		Iterator<Integer> itr=set.iterator();
		while(itr.hasNext()) {
			System.out.print(itr.next()+" ");
		}
	}

}


Measured memory_bytes: 98576
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		
		String s = "";
		for(int i = 0; i < S.length()/2; i++) {
			s += "hi";
		}
		if(S.equals(s)) System.out.println("Yes");
		else System.out.println("No");

	}

}

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

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

    int d[3] = { 3,5,7 };
    int ans = 0;
    int i = 0;
    while (true) {
        vector<int> X;
        int p = i++;
        int c[3] = {};
        while (p >= 3) {
            X.push_back(d[p % 3]);
            c[p % 3]++;
            p /= 3;
        }
        if (p != 1) continue;
        if (c[0] * c[1] * c[2] == 0) continue;
        LL tmp = 0;
        reverse(X.begin(), X.end());
        for (int x : X) tmp = tmp * 10 + x;
        if (tmp > N) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;

int main(int argc, char **argv)
{
	ll n; cin >> n;
	vector<ll> a(n+10);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	vector<ll> com(n+1, 0);
	for (int i = 0;i < n; ++i)
		com[i+1] = a[i] + com[i];

	map<ll, ll> m;
	for (int i = 0; i < n+1; ++i)
		++m[com[i]];

	ll ans = 0;
	for (auto &e : m)
	{
		ll num = e.second;
		ll tmp = num * (num - 1)  / 2;
		ans += tmp;
	}
	std::cout << ans << std::endl;
}

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

int main() {
  int N; cin >> N;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  ll ans = 0, sum = 0;
  int r = 0;
  rep(l, 0, N) {
    while(r < N && sum + A[r] == (sum ^ A[r])) {
      sum += A[r];
      ans += r - l + 1;
      r++;
    }
    if(l == r) r++;
    else sum -= A[l];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import sys

n = int(input())
a = [int(input()) for i in range(n)]

flag = False
button = 0
cnt = 0
for i in range(1, n+1):
    if a[button] == 2:
        cnt = i
        flag = True
        break
    else:
        button = a[button] - 1

print(cnt) if flag else print(-1)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int a, b, c;
  cin >> a >> b >> c;

  int res = (a == b || a == c || b == c) && !(a == b && a == c);
  cout << (res ? "Yes": "No") << endl;
}


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

using namespace std;

int n;
char s[maxn];

int a[maxn];

int cal(int x){
	if(!x) return 0;
	if(a[x]) return a[x];
	int y = x, cnt = 0;
	while(y){
		if(y & 1) cnt++;
		y >>= 1;
	}
	return a[x] = cal(x % cnt) + 1;
}

int cnt; 
int b[maxn];

inline int fpow(int x, int y, int p){
	int ans = 1;
	while(y){
		if(y & 1) ans = 1ll * ans * x % p;
		y >>= 1, x = 1ll * x * x % p;
	}
	return ans % p;
}

int main(){
	scanf("%d%s", &n, s + 1);
	//n = 2e5;
	//for(int i = 1;i <= n;i++) s[i] = (i & 1) + '0';
	for(int i = 1;i <= n;i++) cnt += s[i] - '0';
	for(int i = 1;i <= n;i++){
		if(s[i] == '1'){
			if(cnt - 1 > 0) b[0] = (b[0] + fpow(2, n - i, cnt - 1)) % (cnt - 1);
			b[1] = (b[1] + fpow(2, n - i, cnt + 1)) % (cnt + 1);
		}
	}
	//printf("%d %d %d--\n", b[0], b[1], cnt);
	for(int i = 1;i <= n;i++){
		if(s[i] == '1'){
			if(cnt - 1 > 0) printf("%d\n", cal(((b[0] - fpow(2, n - i, cnt - 1)) % (cnt - 1) + cnt - 1) % (cnt - 1)) + 1);
			else puts("0");
		}else{
			//printf("%d--\n", fpow(2, n - i, cnt + 1));
			printf("%d\n", cal((b[1] + fpow(2, n - i, cnt + 1)) % (cnt + 1)) + 1);
		}
	}
}

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

int main(){
  string s;
  cin >> s;
  int a=s.size();
  int b=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      a=min(a,i);
    }else if(s[i]=='Z'){
      b=max(b,i);
    }
  }
    cout << b-a+1 << endl;
}

Measured memory_bytes: 640
n = int(input())
a = [int(_) for _ in input().split()]

done = {}
for i in range(n):
    done[a[i]] = 0
# print(done)

direct = {}
a_sorted = sorted(a)
for i in range(n):
    direct[a_sorted[i]] = i
# print(direct)

group_list = []
for i in range(n):
    if done[a[i]] == 1:
        continue
    else:
        f = a[i]
        done[f] = 1
        group = [f]
        n = f
        while a[direct[n]] != f:
            n = a[direct[n]]
            done[n] = 1
            group.append(n)
        group_list.append(group)
# print(group_list)

m = a_sorted[0]
cost = 0
while len(group_list) > 0:
    group = group_list.pop()
    if len(group) == 1:
        continue
    else:
        cost += min(sum(group) + (len(group) - 2) * min(group), sum(group) + min(group) + (len(group) + 1) * m)
print(cost)


Measured memory_bytes: 5848
N, K = gets.split.map(&:to_i)
S = gets.chomp

L = S.split('R').select { |s| s.size > 0 }
R = S.split('L').select { |s| s.size > 0 }

str = ''

if S[0] == 'R'
  K.times do
    break if R.empty? || L.empty?

    str << R.shift
    str << 'R' * L.shift.size
  end

  str += R.zip(L).join
else
  K.times do
    break if R.empty? || L.empty?

    str << L.shift
    str << 'L' * R.shift.size
  end

  str += L.zip(R).join
end

puts str.chars.each_cons(2).count { |a, b| a == b }


Measured memory_bytes: 16160
#include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
 
 
int main(){
    long H,W;
    cin>>H>>W;
    char a[H][W];
    int b=0,d=0;
    bool f[H],g[W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>a[i][j];
            if(a[i][j]=='.')b++;
        }
        if(b==W)f[i]=0;
        else f[i]=1;
        b=0;
    }

    for(int i=0;i<W;i++){
        for(int j=0;j<H;j++){
            if(a[j][i]=='.')d++;
        }
        if(d==H)g[i]=0;
        else g[i]=1;
        d=0;
    }
    for(int i=0;i<H;i++){
        if(f[i]){
            for(int j=0;j<W;j++){
                if(g[j])cout<<a[i][j];
            }
            cout<<endl;
        }
    }

}

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

int main() {
  ll x;
  cin >> x;
  ll ans = 0;

  ll amount = 100;
  while(true) {
    ans++;
    amount *= 1.01;
    if (x <= amount) break;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

//サイズが1のときだけ値を持っておくといいね．典型だねうれしいね
int dp[301][301];
int v[301][301];
bool check[301][301];
int n;
int w[301];

int DP(int l,int r){
    if(check[l][r]){
        return dp[l][r];
    }
    check[l][r]=true;
    if(l==r){
        v[l][r]=w[l];
        return dp[l][r]=1;
    }
    
    for(int i=l;i<r;i++){
        auto x=DP(l,i),y=DP(i+1,r);
        if(x==0 and y==1){
            if(chmin(dp[l][r],x+y)) v[l][r]=v[i+1][r];
        }
        else if(x==1 and y==0){
            if(chmin(dp[l][r],x+y)) v[l][r]=v[l][i];
        }
        else if(x==1 and y==1){
            if(abs(v[l][i]-v[i+1][r])<2) dp[l][r]=0;
            else chmin(dp[l][r],x+y);
        }
        else chmin(dp[l][r],x+y);
    }
    return dp[l][r];
}


void solve(){
    rep(i,n) cin>>w[i];
    rep(i,n)rep(j,n)check[i][j]=false,dp[i][j]=INF;
    cout<<n-DP(0,n-1)<<endl;
}

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

    while(cin>>n,n){
        solve();
    }
    return 0;
}



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

  int main(void){
  int n,A[100];
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  for(int i=n-1;i>=0;i--){
    if(i!=n-1)cout<<" ";
    cout<<A[i];
  }cout<<endl;
}


Measured memory_bytes: 3084
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	string s, t;
	cin >> s >> t;
	if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int m, n, d, field[110][110];

void judge() {
	int ans = 0;
	/////////////////////////////////////?¨????????????????????????´???
	for (int i = 0; i <= n - d; i++) {//(????????°????¨??????????????¨???????????????????????????????????????´??????5-2+1=4???)
		for (int j = 0; j < m; j++) {//j???????????????
			bool flag = true;
			for (int k = 0; k < d; k++) {
				if (field[i + k][j] == 1) flag = false;
			}
			if (flag == true) ans += 1;
		}
	}
	/////////////////////////////////////??????????????????????????´???
	for (int i = 0; i < n; i++) {//i???????????????
		for (int j = 0; j <= m - d; j++) {//?¨???¨????§?
			bool flag = true;
			for (int k = 0; k < d; k++) {
				if (field[i][j + k] == 1) flag = false;
			}
			if (flag == true) ans += 1;
		}
	}

	//??????
	cout << ans << endl;
}

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

	char place;

	for (int i = 0; i < n; i++) {//????????????
		for (int j = 0; j < m; j++) {//??±?\???????
			cin >> place;
			if (place == '#') field[i][j] = 1;//?¨????i??????????????????j??????????????????
			else field[i][j] = 0;
		}
	}

	judge();

	return 0;
}

Measured memory_bytes: 3120
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    ll L, R;
    cin >> L >> R;
    //vector<vector<int>> data(3, vector<int>(4));
    if (R-L>=2019) {
        cout << 0 << endl;
    } else {
        ll res = 2018;
        for (ll i = L; i < R; ++i) {
            for (ll j = i+1; j <= R; ++j) {
                res = min(res, (i*j) % 2019);
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



H,W = map(int,input().split())

table = [[0]*(W+1) for i in range(H+1)]

for row in range(H):
    work = list(map(int,input().split())) #★★直にtableに代入すると、列数が変わってしまう!!!★★★
    for col in range(W):
        table[row][col] = work[col]


for row in range(H):
    for col in range(0,W):
        table[row][W] += table[row][col]


for col in range(0,W+1):
    for row in range(0,H):
        table[H][col] += table[row][col]


for row in range(0,H+1):
    print("%d"%(table[row][0]),end="")
    for col in range(1,W+1):
        print(" %d"%(table[row][col]),end = "")
    print()



Measured memory_bytes: 6220
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	if(0 >= b - a) cout << "delicious" << endl;
	else if(x >= b - a) cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include<cmath>
#include<limits>
#include<iostream>
#include<numeric>
using namespace std;

long long int gcd(long long int a, long long int b){

    long long int r, tmp;

    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
 
    /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

long long int lcm(long long int a, long long int b, long long int c){
    return c * (a/c) * (b/c);
}

int main(void){
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int f = lcm(c,d, gcd(c, d));
    //cout<<f<<endl;

    long long int X = b/c - (a-1)/c;
    long long int Y = b/d - (a-1)/d;
    long long int Z = b/f - (a-1)/f;

    //cout<<X<<Y<<Z<<endl;

    cout<<(b-a+1)-X-Y+Z<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, N: int, A: "List[int]"):
    A.sort()
    for i in range(N):
        H-=A[-1]
        del A[-1]
        if H<=0:
            print(YES)
            break
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(H, N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <utility>
#include <string>

#define loop(n) for(ll i=0;i<n;i++)

using namespace std;

typedef long long int ll;

int main() {
    int n,t[50];
    while(1) {
        cin >> n;
        if(n == 0) break;
        for(char i = 'A';i <= 'Z';i++) t[i-'A'] = 0;
        char c;
        bool f = false;
        for(int i = 0;i < n;i++) {
            cin >> c;
            if(f) continue;
            t[c-'A']++;
            int m[2] = {0,1};
            for(char j = 'A';j <= 'Z';j++) if(t[m[0]] < t[j-'A']) m[0] = j-'A';
            m[1] = m[0]+1%(1+'Z'-'A');
            for(char j = 'A';j <= 'Z';j++) if(t[m[1]] < t[j-'A'] && j-'A' != m[0]) m[1] = j-'A';
            if(i == n-1) {
                if (t[m[0]] - t[m[1]] > 0) cout << (char) (m[0] + 'A') << " " << n << "\n";
                else cout << "TIE" << endl;
            } else if(t[m[0]]-t[m[1]] > n-i-1) {
                cout << (char)(m[0]+'A') << " " << i+1 << "\n";
                f = true;
            }
        }
    }
}


Measured memory_bytes: 3076
n,k=map(int,input().split())

ans=0
for i in range(1,n+1):
  num=i
  p=1/n
  if num>=k:
    ans+=p
    continue
  while num<k:
    num=num*2
    p=p*(1/2)
  ans+=p
  
print(ans)


Measured memory_bytes: 9092
//#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>

#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e15;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}

const int MAX_N=200005;
bool isPrime[MAX_N];
void eratos(){
  for(int i=0;i<MAX_N;i++)isPrime[i]=true;
  isPrime[0]=isPrime[1]=false;
  for(int i=0;i<MAX_N;i++){
    if(isPrime[i]){
      for(int j=i+i;j<MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
}

signed main(){
  eratos();
  int n,p;
  while(cin>>n>>p){
    if(n==-1&&p==-1)break;
    vector<int> ans;
    int tmpp=101;
    int s=n+1;
    while(tmpp){
      if(isPrime[s]){
        int tmpq=101;
        int t=s;
        while(tmpq){
          if(isPrime[t]){
            ans.push_back(s+t);
            tmpq--;
          }
          t++;
        }
        tmpp--;
      }
      s++;
    }
    sort(all(ans));

    cout<<ans[p-1]<<endl;
  }


 return 0;
}


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

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

    ll ans = 0;
    for(int i=0; i<n-1; i++){
        string a, b;
        for(int j=0; j<=i; j++){
            a.push_back(s.at(j));
        }
        for(int j=i+1; j<n; j++){
            b.push_back(s.at(j));
        }

        sort(a.begin(), a.end());
        sort(b.begin(), b.end());

        for(int j=0; j<a.size(); j++){
            for(int k=j+1; k<a.size(); k++){
                if(a.at(j)==a.at(k)) a.at(k) = '!';
            }
        }

        for(int j=0; j<b.size(); j++){
            for(int k=j+1; k<b.size(); k++){
                if(b.at(j)==b.at(k)) b.at(k) = '!';
            }
        }

        ll cnt = 0;
        for(int j=0; j<a.size(); j++){
            if(a.at(j)=='!') continue;
            for(int k=0; k<b.size(); k++){
                if(a.at(j)==b.at(k)) {
                    cnt++;
                    break;
                }
            }
        }

        ans = max(cnt, ans);
    }

    cout << ans << endl;
}


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

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] pow = new int[n];
		int total = 0;
		int amari =0;
		int ans = 0;

			for(int i=0; i<n; i++) {
				pow[i]=sc.nextInt();
				total+=pow[i];
			}
			Arrays.sort(pow);
			amari = x-total;
				if(amari == 0) {
					ans =n;
				}else {
					ans=(amari/pow[0])+n;
				}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21716
import java.util.Scanner;

/** dp[n][v]: n番目の荷物までで価値がv以上の時の重さの最小値 */
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = Integer.parseInt(scanner.next());
    int w = Integer.parseInt(scanner.next());
    int[][] wv = new int[n][2];
    int wi, vi;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 2; j++) {
        wv[i][j] = Integer.parseInt(scanner.next());
      }
    }
    int v = 100000;
    long[][] dp = new long[n + 1][v + 1];
    for (int i = 0; i < n + 1; i++) {
      for (int j = 0; j < v + 1; j++) {
        dp[i][j] = 100000000000L;
      }
    }
    dp[0][0] = 0;
    for (int i = 1; i < n + 1; i++) {
      wi = wv[i - 1][0];
      vi = wv[i - 1][1];
      for (int j = 0; j < v + 1; j++) {
        dp[i][j] = Math.min(dp[i][j], dp[i - 1][j]);
        if (j - vi >= 0) {
          dp[i][j] = Math.min(dp[i][j], dp[i - 1][j - vi] + wi);
        }
      }
    }
    for (int j = v; j >= 0; j--) {
      if (dp[n][j] > w) {
        continue;
      }
      System.out.println(j);
      break;
    }
  }
}


Measured memory_bytes: 125524
s = input()
ans = []
for i in range(1 << (len(s)-1)):
    a = ''
    for j in range(len(s)):
        a += s[j]
        if j == 3:
            break
        if 1 & (i >> j) == 1:
            a += '+'
        if 1 & (i >>j) == 0:
            a += '-'
    if eval(a) == 7:
        a += '=7'
        ans.append(a)
print(ans[0])

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  string s;cin >> s;
  cout << s.substr(0,4) <<" "<< s.substr(4,8) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 40;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vi>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

itn N, K;

void solve() {
    vvi s(N);
    FOR(N) {
        itn t, d;
        cin >> t >> d;
        t--;
        s[t].eb(d);
    }
    for (auto& v : s) {
        sort(all(v), greater<int>());
        if (v.empty())
            v.eb(-INF);
    }
    sort(all(s), [&](vi a, vi b) { return a[0] > b[0]; });

    int cur = 0;
    priority_queue<int> que;
    FOR(K) {
        cur += s[i][0];
        for (int j = 1; j < s[i].size(); j++)
            que.push(s[i][j]);
    }
    FOR(i, K, N) {
        for (auto x : s[i])
            que.push(x);
    }

    int ans = cur + K * K;

    for (itn i = K - 1; i >= 1; i--) {
        int v = s[i][0];
        int w = que.top();
        if (v < w) {
            cur -= v;
            cur += w;
            que.pop();
        }
        chmax(ans, cur + i * i);
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> K;


    solve();
    return 0;
}


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

int main() {
  int N;cin >> N;
  vector<int> A(N);
  for (int i=0;i<N;i++) A.at(i) = i+1;
  vector<vector<int>> B(0,vector<int>(N));
  do{
    B.push_back(A);
  }while(next_permutation(A.begin(),A.end()));
  sort(B.begin(),B.end());
  vector<int> P(N),Q(N);
  for (int i=0;i<N;i++) cin >> P.at(i);
  for (int i=0;i<N;i++) cin >> Q.at(i);
  auto ir_p=B.begin();
  auto ir_q=B.begin();
  for (auto ir=B.begin();ir<B.end();ir++) {
    if (*ir==P) ir_p=ir;
    if (*ir==Q) ir_q=ir;
  }
  cout << abs(distance(ir_p,ir_q)) << endl;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll a[3030], b[3030];
ll dp[3030][7000]; // i個までからトータルj分選んだ時の満足度の最大値
vector<P> vp;

int main(){
    int n, t;
    cin >> n >> t;
    rep(i, n){
        ll p, q;
        cin >> p >> q;
        vp.push_back(make_pair(p, q));
    }
    sort(vp.begin(), vp.end());
    
    rep(i, n) a[i] = vp[i].first, b[i] = vp[i].second;

    rep(i, n){
        rep(j, t){          
            if (0 <= j - a[i]){
                dp[i+1][j] = max(dp[i][j], dp[i][j-a[i]] + b[i]);
            }
            else dp[i+1][j] = dp[i][j];
        }
    }
    ll ans = 0;
    rep(i, n) rep(j, t) ans = max(dp[i+1][j] + b[i+1], ans);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 85940
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] a = new int[n];
		for(int i=0; i<a.length; i++){
			a[i] = scn.nextInt();
		}
      	int check = 1;
      	for(int i=0; i<a.length; i++){
			if(a[i]%2==0) check*=2;
		}
      	int ans = (int)Math.pow(3,n) - check;
      	System.out.println(ans);
	}
}


Measured memory_bytes: 35560
fun main(args: Array<String>) {
    val (H, W) = readInputLine().split(" ").map { it.toInt() }
    readInputLine()
    val aList = readInputLine().split(" ").map { it.toInt() }
    
    val ans = Array(H, { IntArray(W) } )
    var nowH = 0
    var nowW = 0
    
    for ((index, a) in aList.withIndex()) {
        for (j in 1..a) {
            ans[nowH][nowW] = index + 1
            if (nowH % 2 == 0) {
                nowW++
                if (nowW >= W) {
                    nowW--
                    nowH++
                }
            } else {
                nowW--
                if (nowW < 0) {
                    nowW++
                    nowH++
                }
            }
        }
    }
    
    for (a in ans) {
        println(a.joinToString(" "))
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 41128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e18
#define mod pow(10,9)+7
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
// void c_p_c()
// {
// 	ios_base::sync_with_stdio(0);
// 	cin.tie(0);
// 	cout.tie(0);
// // #ifndef  ONLINE_JUDGE
// // 	freopen("input.txt", "r", stdin);
// // 	freopen("output.txt", "w", stdout);
// // #endif
// }
int32_t main()
{
	//c_p_c();
	string s;
	cin>>s;
	set<char>se;
	int i;
	for(i=0;i<s.length();i++)
	{
		se.insert(s[i]);
	}
	if(se.size()==2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int h,a[200][3],i,j,l,b,c;
	scanf("%d",&h);
	for(i=0;i<h;i++){
		for(j=0;j<3;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<3;i++){
		for(j=0;j<h;j++){
			b=a[j][i];
			for(l=j+1;l<=h;l++){
				if(b==a[l][i]){
					a[j][i]=0;
					a[l][i]=0;
				}
			}
		}
	}
	for(i=0;i<h;i++){
		c=a[i][0]+a[i][1]+a[i][2];
		printf("%d\n",c);
	}
	return 0;
}


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

int main() {

	int N;
	cin >> N;

	double sum = 0.0;
	int A;
	for (int i = 0; i < N; i++) {
		cin >> A;
		sum += 1.0 / (double)A;
	}

	double ans = 1.0 / sum;

	cout << fixed;
	cout << setprecision(10) << ans << endl;

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>)
{
    val (n, d) = readNInts()

    val q = n / (2 * d + 1)
    val r = n % (2 * d + 1)

    println(if (r == 0) q else q + 1)
}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!


Measured memory_bytes: 36012
#include<iostream>

int main(){
 	int N;
 	int A[100];
	int tmp;
  	std::cin>>N;
  	for(int i=0;i<N;i++){
    	std::cin>>A[i];
  	}
	for(int i=1;i<N;i++){
		for(int k=0;k<N-1;k++){
			std::cout<<A[k]<<" ";
		}
		std::cout<<A[N-1]<<"\n";
		int v=A[i];
    	int j=i-1;
    	while(j>=0&&A[j]>v){
    		A[j+1]=A[j];
    		j--;
    	}
		A[j+1]=v;
  	}
	for(int k=0;k<N-1;k++){
		std::cout<<A[k]<<" ";
	}
	std::cout<<A[N-1]<<"\n";
	return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 29;
int hs[100100];
int dp[100100];
int N;

int rec(int i) {
    if (dp[i] < INF) return dp[i];
    if (i == 1) return abs(hs[1] - hs[0]);
    if (i == 2) return abs(hs[2] - hs[0]);
    dp[i] = min(rec(i - 1) + abs(hs[i] - hs[i-1]), rec(i - 2) + abs(hs[i] - hs[i - 2]));
    return dp[i];
}

void solve() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> hs[i];
    for (int i = 0; i < N; ++i) dp[i] = INF;
    dp[0] = 0;
    cout << rec(N - 1) << endl;
}

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


Measured memory_bytes: 2560
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var par []int
var rank []int

func main() {
	n, q := scanInt(), scanInt()
	par = make([]int, n)
	for i := 0; i < n; i++ {
		par[i] = i
	}
	rank = make([]int, n)
	executeQueries(q)
}

func debug(a ...interface{}) {
	// fmt.Println(a...)
}

func executeQueries(q int) {
	for i := 0; i < q; i++ {
		com, x, y := scanInt(), scanInt(), scanInt()
		switch com {
		case 0: // unite
			unite(x, y)
		case 1:
			if same(x, y) {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}
	}
}

func unite(x, y int) {
	minRank, other := -1, -1
	xRoot, yRoot := findRoot(x), findRoot(y)
	if rank[xRoot] < rank[yRoot] {
		minRank = xRoot
		other = yRoot
	} else {
		minRank = yRoot
		other = xRoot
	}

	debug(xRoot, yRoot, minRank, other, par)

	par[other] = par[minRank]
	rank[other] = rank[minRank]
}

func same(x, y int) bool {
	debug("findRoot ", x, y)
	xRoot, yRoot := findRoot(x), findRoot(y)
	return xRoot == yRoot
}

func findRoot(x int) int {
	tmp := x
	for {
		if tmp == par[tmp] {
			return tmp
		}
		tmp = par[tmp]
	}
}



Measured memory_bytes: 2408
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int f = 0;
        int n1 = n;
        while (n1 > 0){
            f += n1 % 10;
            n1 = n1/10;
        }
        System.out.println(n % f == 0?"Yes":"No");
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdlib>

using namespace std;

int main() {
  int n;
  cin >> n;
  while (n > 0) {
    int score_a = 0, score_b = 0;
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      if (a > b) {
        score_a += (a+b);
      } else if (a < b) {
        score_b += (a+b);
      } else {
        score_a += a;
        score_b += b;
      }
    }
    cout << score_a << " " << score_b << endl;
    cin >> n;
  }

  
  return 0;
}

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

auto kuku = [](auto x, auto y){ return x*y;};

int main(){
    int x;
    int y;
    cin >> x >> y;
    if(x < 0 || y < 0){ cout << -1 << endl; return 0;}
    auto ans = kuku(x,y);
    if(x > 0 && x < 10 && y > 0 && y < 10) cout << ans << "\n";
    else cout << -1 << endl;
}

Measured memory_bytes: 256
import Data.List

sumup [] = []
sumup x@(a:[]) = x

sumup x@(a:xs) =
  let l = length $ takeWhile (== a) x
      l'= l `div` 2
      y = dropWhile (== a) x
  in
    if (l `mod` 2) == 0
    then   sumup ( (replicate l' (a+1)) ++ y )
    else a:sumup ( (replicate l' (a+1)) ++ y )

ans i =
  let s = sort $ map (\ (a:b:_) -> a+b) i
      r = sumup s
  in
    r

main = do
  _ <- getLine
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ putStrLn $ map (\ x -> (show x) ++ " 0") o
  

Measured memory_bytes: 20504
def main():
    N, M = map(int, input().split())
    s = [list(map(int, input().split()[1:])) for _ in range(M)]
    p = list(map(int, input().split()))
    ans = 0
    
    for i in range(2**N):
        state = [0] * N
        flag = True
        for j in range(N):
            if (i >> j) & 1:
                state[j] = 1
        for k in range(M):
            cnt = 0
            for l in s[k]:
                cnt += state[l-1]
            if cnt%2 == p[k]:
                continue
            else:
                flag = False
                break
        if flag:
            ans += 1
    print(ans)
                
if __name__  == '__main__':
    main()

Measured memory_bytes: 9228
import math

n = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))

p1 = 0
for i in range(n):
    p1 += abs(x[i] - y[i])

p2 = 0
for i in range(n):
    p2 += (x[i] - y[i]) ** 2

p2 = math.sqrt(p2)

p3 = 0
for i in range(n):
    p3 += abs((x[i] - y[i])) ** 3

p3 = math.pow(p3, 1.0/3.0)

px = 0
l = list()
for i in range(n):
    l.append(abs(x[i] - y[i]))
    px = max(l)

print(f'{p1:.6f}')
print(f'{p2:.6f}')
print(f'{p3:.6f}')
print(f'{px:.6f}')


Measured memory_bytes: 5744
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b;
    scanf("%d %d" ,&a,&b);
    if(a<b)
    printf("a < b\n");
    else if(a>b)
    printf("a > b\n");
    else 
    printf("a == b\n");
    
    return 0;
}


Measured memory_bytes: 2052
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#解説みた
N, K = na()
ans = 0
for b in range(1, N+1):
    p = N // b
    r = N % b
    ans += p * max(0, b - K)
    ans += max(0, r - K + 1)

if K == 0:
    ans -= N
print(ans)



Measured memory_bytes: 83592
def main():
    K = int(input())
    MAX = 20
    dp = [[0] * 10 for _ in range(MAX)]
    dp[1] = [1] * 10
    for i in range(2, MAX):
        for j in range(10):
            dp[i][j] = dp[i-1][j]
            if j >= 1:
                dp[i][j] += dp[i-1][j-1]
            if j < 9:
                dp[i][j] += dp[i-1][j+1]
    total = 0
    idx = 0
    for i in range(MAX):
        tmp = sum(dp[i][1:])
        if total + tmp < K:
            total += tmp
            continue
        idx = i
        break
    K -= total
    ans = [""] * idx
    rng = range(1, 10)
    while idx > 0:
        for i in rng:
            if K <= dp[idx][i]:
                ans[idx-1] = str(i)
                rng = range(max(0, i-1), min(9, i+1)+1)
                break
            K -= dp[idx][i]
        idx -= 1
    print("".join(ans[::-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
//
// Created by Hideaki Imamura on 2019-07-10.
//

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

int main() {
    ll n;
    cin >> n;

    vector<int> s;
    while (n != 0) {
        s.push_back(abs(n % 2));
        n = (n - abs(n%2)) / (-2);
    }

    for(auto it = s.rbegin(); it != s.rend(); ++it) {
        cout << *it;
    }
    if (s.empty()) cout << 0;
    cout << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18, MOD = 1e15 + 37;
const ld PI = acos(-1);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    string s, t;
    cin >> s >> t;

    int n = s.size(), m = t.size();
    int res = m;

    for (int i = 0; i + m - 1 < n; ++i) {
        int ctr = 0;
        for (int j = 0; j < m; ++j) {
            ctr += s[i + j] != t[j];
        }
        res = min(res, ctr);
    }

    cout << res << "\n";
}


Measured memory_bytes: 3640