akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
LL facctorialMethod(int k);
int main(){
    LL n,a,sum;
    LL len_a,len_sum;
    cin >> n ;
    vector<LL> array_a(n);

    for(int i = 0; i < n; i++) {
        cin >> a;
        array_a[i] =  a;
        if(a == 0) {
            cout << "0" << endl;
            return 0;
        }
    }
//    sort(array_a.begin(),array_a.end());

/*
    for(int i = 0; i < n; i++) {
        cout << "array_a[i] :[" << i << "] :" << array_a[i] << endl;
    }
*/

    sum = 1;
    for(int i = 0; i < n; i++) {
/*
        len_a = to_string(array_a[i]).length();
        len_sum = to_string(sum).length();1
        if((len_a + len_sum) > 20){
            cout << -1 << endl;
            return 0;            
        }
*/
        if(((LL)1e18 / array_a[i]) < sum ) {
            cout << -1 << endl;
            return 0;            
        } 
        sum *= array_a[i];
        if(sum > (LL)1e18) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << sum << endl;
    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3984
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var A, B, C int
	fmt.Sscanf(scanner.Text(), "%d %d %d", &A, &B, &C)

	ans := 0
	if B > C {
		ans += B + C
	} else {
		ans += 2 * B
		C = C - B
		if A < C {
			ans += A + 1
		} else {
			ans += C
		}
	}
	fmt.Println(ans)

}

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


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define F first
#define S second
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};
int in()
{
	int x;
	cin >> x;
	return x;
}

/*
(char)'1' - (int)48 = (int)1;
　1111181
*/
////////////////////////////////////////////////////




int main()
{
	int n;
	cin >> n;
	rep(EEE, n)
	{
		string a, b;
		cin >> a >> b;
		int ans = 0;
		int now = 0;
		for (int i = a.size() - 1; i >= 0; i--)
		{
			if (a[i] == 'i')
			{
				if (now != 0)ans += now;
				now = 1;
			}
			else if (a[i] == 'x')
			{
				if (now != 0)ans += now;
				now = 10;
			}
			else if (a[i] == 'c')
			{
				if (now != 0)ans += now;
				now = 100;
			}
			else if (a[i] == 'm')
			{
				if (now != 0)ans += now;
				now = 1000;
			}
			else
			{
				ans += now*(a[i] - 48);
				now = 0;
			}
		}
		if (now != 0)ans += now;
		now = 0; a = b;
		for (int i = a.size() - 1; i >= 0; i--)
		{
			if (a[i] == 'i')
			{
				if (now != 0)ans += now;
				now = 1;
			}
			else if (a[i] == 'x')
			{
				if (now != 0)ans += now;
				now = 10;
			}
			else if (a[i] == 'c')
			{
				if (now != 0)ans += now;
				now = 100;
			}
			else if (a[i] == 'm')
			{
				if (now != 0)ans += now;
				now = 1000;
			}
			else
			{
				ans += now*(a[i] - 48);
				now = 0;
			}
		}
		if (now != 0)ans += now;
		if (ans / 1000)
		{
			if (ans / 1000 == 1)cout << "m";
			else cout << ans / 1000 << "m";
			ans -= ans/1000*1000;
		}
		
		if (ans / 100)
		{
			if (ans / 100 == 1)cout << "c";
			else cout << ans / 100 << "c";
			ans -= ans/100*100;
		}
		
		if (ans / 10)
		{
			if (ans / 10 == 1)cout << "x";
			else cout << ans / 10 << "x";
			ans -= ans/10*10;
		}
		
		if (ans / 1)
		{
			if (ans / 1 == 1)cout << "i";
			else cout << ans / 1 << "i";
		}
		cout << endl;


	}
}

Measured memory_bytes: 1212
#include <stdio.h>

int solve(int i,int m);

int A[2000];
int n;

int main(){
  int q,Q;
  int i;
  int S;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }


  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&Q);
    S=solve(0,Q);
    if(S==1)printf("yes\n");
    else printf("no\n");
  }

  return 0;
}


int solve(i,m){
  int res;
  if(m==0)return 1;
  if(i>=n)return 0;
  res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

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

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

using namespace std;

int main(){
	int a,b,c,k; scanf("%d%d%d%d",&a,&b,&c,&k);
	if(k<a) printf("%d\n",k);
	else if(k<a+b) printf("%d\n",a);
	else           printf("%d\n",a-(k-a-b));
	return 0;
}


Measured memory_bytes: 3724
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll ur = 0, ul = 1000000001, dr = -1000000001, dl = 2000000001;
    pair<ll, ll> urP, ulP, drP, dlP;
    ll x, y;
    rep(i, N){
        cin >> x >> y;
        if(x + y > ur){
            ur = x + y;
            urP = make_pair(x, y);
        }
        if(x + y < dl){
            dl = x + y;
            dlP = make_pair(x, y);
        }
        if(x - y < ul){
            ul = x - y;
            ulP = make_pair(x, y);
        }
        if(x - y > dr){
            dr = x - y;
            drP = make_pair(x, y);
        }
    }

    ll ans = 0;
    ans = max(ans, abs(urP.first - ulP.first) + abs(urP.second - ulP.second));
    ans = max(ans, abs(urP.first - drP.first) + abs(urP.second - drP.second));
    ans = max(ans, abs(urP.first - dlP.first) + abs(urP.second - dlP.second));
    ans = max(ans, abs(ulP.first - drP.first) + abs(ulP.second - drP.second));
    ans = max(ans, abs(ulP.first - dlP.first) + abs(ulP.second - dlP.second));
    ans = max(ans, abs(drP.first - dlP.first) + abs(drP.second - dlP.second));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#define N 1000000
using namespace std;
int main(){
  vector<int> m,mn;
  int n[N]={},s,t,st;
  n[0]=1,n[1]=1;
  for(int i=2;i<=1000;i++)
    for(int j=2;i*j<N;j++)if(n[j*i]==0) n[i*j]=1;
  for(int i=0;i<N;i++) if(n[i]==0) m.push_back(i);
  while(1){
    cin>>s>>t;
    if(s+t==-2) break;
    for(int i=0;i<m.size();i++) if(m[i]>s){
	st=i;
	break;
      }
    for(int i=st;i<t+st;i++)
      for(int j=i;j<t+st;j++) mn.push_back(m[i]+m[j]);
    sort(mn.begin(),mn.end());
    cout<<mn[t-1]<<endl;
    mn.clear();
  }    
  return 0;
}

Measured memory_bytes: 5500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i; i < N; i++) {
    cin >> vec.at(i);
  }
  vector<int> num(N);
  for (int i; i < N; i++) {
    while ( (vec.at(i) % 2) == 0) {
      vec.at(i) /= 2;
      num.at(i)++;
    }
  }
  sort(num.begin(),num.end());
  cout << num.at(0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n;cin>>n;
    ll a[n];
    ll diff[n];
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    if(sum%(n*(n+1)/2)!=0LL){
        DEBUG{printf("out1\n");}
        cout << "NO" << endl;
        return 0;
    }
    ll val = sum/(n*(n+1)/2);
    DEBUG{cout << "val : "<< val << endl;}
    rep(i,n){
        diff[i] = a[(i+1)%n] - a[i] - val;
    }
    ll cnt=0;
    rep(i,n){
        if(diff[i]>0||diff[i]%n){
            DEBUG{printf("out2 i : %d reminder : %lld\n",i,diff[i]%n);}
            cout << "NO" << endl;
            return 0;
        }
        // cnt += -diff[i]/n;
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int N, M, eq;
char buf[1010];
bool alloc[12];

bool OR[2][2] = {
  {false, true},
  {true, true}
};
bool AND[2][2] = {
  {false, false},
  {false, true}
};
bool IMP[2][2] = {
  {true, true},
  {false, true}
};

int p;

bool formula() {
  if (buf[p] == '-') {
    ++p; return !formula();
  }
  if (buf[p] == 'T') {
    p++; return true;
  }
  if (buf[p] == 'F') {
    p++; return false;
  }
  if ('a' <= buf[p] && buf[p] <= 'k') {
    return alloc[buf[p++] - 'a'];
  }
  if (buf[p] == '(') {
    p++;
    bool lhs = formula(), rhs, ret;
    if (buf[p] == '+') {
      ++p;
      rhs = formula();
      ret = OR[lhs][rhs];
    } else if (buf[p] == '*') {
      ++p; rhs = formula();
      ret = AND[lhs][rhs];
    } else if (buf[p] == '^') {
      p+=2;
      rhs = formula();
      ret = IMP[lhs][rhs];
    }
    p++;
    return ret;
  }
}

int main() {
  while (scanf("%s", buf), buf[0] != '#') {
    N = strlen(buf);
    set<char> sc;
    rep(i,N) if ('a' <= buf[i] && buf[i] <= 'k') {
      sc.insert(buf[i]);
    }

    M = sc.size();
    vector<char> vc;
    foreach(sc,i) vc.push_back(*i);

    rep(i,N) {
      if (buf[i] == '=') eq = i;
      if (buf[i] == '>') buf[i-1] = '^';
    }

    bool ans = true;
    for (int S = 0; S < (1 << M); ++S) {
      fill(alloc, alloc + 12, false);
      for (int i = 0; i < M; ++i) {
        if (S >> i & 1) alloc[vc[i] - 'a'] = true;
      }
      // lhs
      p = 0;
      bool lhs = formula();
      // rhs
      p = eq+1;
      bool rhs = formula();
      if (lhs != rhs) { ans = false; break; }
    }
    printf("%s\n", ans ? "YES": "NO");
  }
  return 0;
}

Measured memory_bytes: 0
from operator import mul
from itertools import product

n, m = map(int, input().split())
arr = []
for i in range(n):
    ##[[x, y, z], ..., [x, y, z]]
    arr.append(list(map(int, input().split())))

ans = 0
for opList in list(product(list((1, -1)), repeat=3)):
    bufArr = []
    for xyz in arr:
        bufArr.append(sum(map(mul, opList, xyz)))
    ans = max(ans, sum(sorted(bufArr, reverse = True)[:m]))

print(ans)


Measured memory_bytes: 3432
n = int(input())


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


if n == 1:
    print("0")
    exit()

a = factorization(n)
cnt = 0

for i in range(len(a)):
    b = a[i]
    c = b[1]
    for j in range(1, 100):
        c = c - j
        cnt += 1
        if c <= j:
            break

print(cnt)


Measured memory_bytes: 9496
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;
 
int main()
{
    Khela
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    //string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n>>m)
    {
        string str[n];
        for(i=0;i<n;i++)  cin>>str[i];
        int sum[5][n][m];
        memset(sum,0,sizeof sum);
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
               if(j==0) {
                   if(str[i][j]=='.') sum[1][i][j]=1;
                   if(i>0 && str[i][j]=='.') sum[2][i][j]=sum[2][i-1][j]+1;
                   else if(i==0 && str[i][j]=='.') sum[2][i][j]=1;
                }
                else if(i==0) {
                    if(str[i][j]=='.') sum[2][i][j]=1;
                    if(str[i][j]=='.') sum[1][i][j]=sum[1][i][j-1]+1;
                }
                else{
                    if(str[i][j]=='.') sum[1][i][j]=sum[1][i][j-1]+1,sum[2][i][j]=sum[2][i-1][j]+1;
                }
            }
        }
 
        for(i=n-1;i>=0;i--){
            for(j=m-1;j>=0;j--){
                    if(j==m-1) {
                        if(str[i][j]=='.') sum[3][i][j]=1;
                        if(i<n-1 && str[i][j]=='.') sum[4][i][j]=sum[4][i+1][j]+1;
                        else if(i==n-1 && str[i][j]=='.') sum[4][i][j]=1;
                    }
                    else if(i==n-1) {
                        if(str[i][j]=='.')  sum[4][i][j]=1;
                        if(str[i][j]=='.') sum[3][i][j]=sum[3][i][j+1]+1;
                    }
                else{
                    if(str[i][j]=='.') sum[3][i][j]=sum[3][i][j+1]+1,sum[4][i][j]=sum[4][i+1][j]+1;
                }
            }
        }
 
 
        mx=0;
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                if(str[i][j]=='.') p=sum[1][i][j]+sum[2][i][j]+sum[3][i][j]+sum[4][i][j];
                mx=max(mx,p-3);
            }
        }
 
        cout<<mx<<endl;
    }
 
 
 
 
 
}

Measured memory_bytes: 82688
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max

local function getxor(x, y)
  local ret = 0
  local mul = 1
  while(0 < x or 0 < y) do
    if((x % 2) + (y % 2) == 1) then
      ret = ret + mul
    end
    x, y, mul = mfl(x / 2), mfl(y / 2), mul * 2
  end
  return ret
end

local n = io.read("*n")
local tot = 0
local cutpos = {}
for i = 1, 32 do cutpos[i] = false end
for i = 1, n do
  local a = io.read("*n")
  tot = getxor(tot, a)
  local pos = 1
  while a % 2 == 0 do
    pos = pos + 1
    a = mfl(a / 2)
  end
  cutpos[pos] = true
end
local tgt = {}
local isok = true
while 0 < tot do
  table.insert(tgt, tot % 2 == 1)
  tot = mfl(tot / 2)
end
local cnt = 0
for i = #tgt, 1, -1 do
  if tgt[i] then
    if cutpos[i] then
      cnt = cnt + 1
      for j = 1, i - 1 do
        tgt[j] = not tgt[j]
      end
    else
      isok = false
      break
    end
  end
end
print(isok and cnt or -1)


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char a;
  
  scanf("%c",&a);
  
  switch(a){
    case 'A':
      printf("T");
      break;
    case 'T':
      printf("A");
      break;
    case 'C':
      printf("G");
      break;
    case 'G':
      printf("C");
      break;
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, X;
	cin >> N >> X;

	int tmp, m = INF;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		X -= tmp;
		m = min(m, tmp);
	}

	cout << N + X / m << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N =2e5+10;
const double pi=acos(-1.0);
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
const ll mod=1e9+7;
int f[N],sz[N];
int findfa(int x){
    if(f[x]==x)return f[x];
    else return f[x]=findfa(f[x]);
}
int mergefa(int a,int b){
    int fa=findfa(a),fb=findfa(b);
    if(fa==fb)return 0;
    if(sz[fb]>sz[fa])swap(fa,fb);
    sz[fa]+=sz[fb];
    f[fb]=fa;
    return 1;
}
signed main(){
    int n;
    si(n);
    for (int i = 0; i <=n ; ++i) {
        f[i]=i;
        sz[i]=1;
    }
    int m;
    si(m);
    while(m--){
        int a,b;
        si(a);
        si(b);
        mergefa(a,b);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        int fa=findfa(i);
        ans=max(ans,sz[fa]);
    }
    pi(ans);
    return 0;
}

Measured memory_bytes: 5364
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
using namespace std;

int S;
signed main() {
	vector<int>x, y;
	int n; cin >> n; int m = n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (i & 1) {
			y.push_back(a);
		}
		else {
			x.push_back(a);
		}
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	int MAX = 0;
	for (int i = 0; i < x.size(); i++) {
		for (int j = i; j < x.size(); j++) {
			if (j + 1 == x.size() || x[j + 1] != x[i]) {
				if (j - i + 1 > MAX) {
					S = x[i];
					MAX = j - i + 1;
				}
				i = j;
				break;
			}
		}
	}
	n -= MAX;
	MAX = 0;
	for (int i = 0; i < y.size(); i++) {
		for (int j = i; j < y.size(); j++) {
			if (j + 1 == y.size() || y[j + 1] != y[i]) {
				if (y[i] != S)MAX = max(MAX, j - i + 1);
				i = j;
				break;
			}
		}
	}
	n -= MAX;

	MAX = 0;
	for (int i = 0; i < y.size(); i++) {
		for (int j = i; j < y.size(); j++) {
			if (j + 1 == y.size() || y[j + 1] != y[i]) {
				if (j - i + 1 > MAX) {
					S = y[i];
					MAX = j - i + 1;
				}
				i = j;
				break;
			}
		}
	}
	m -= MAX;
	MAX = 0;
	for (int i = 0; i < x.size(); i++) {
		for (int j = i; j < x.size(); j++) {
			if (j + 1 == x.size() || x[j + 1] != x[i]) {
				if (x[i] != S)MAX = max(MAX, j - i + 1);
				i = j;
				break;
			}
		}
	}
	m -= MAX;
	cout << min(n, m) << endl;
}


Measured memory_bytes: 892
n = gets.to_i
h,idealAverT = gets.chomp.split(" ").map(&:to_f)
averT = -1
index = -1
diffValue = 0.0
heightArrays = gets.split(" ").map(&:to_f)
heightArrays.each_with_index do |value, count|
  tempH = value
  tempAverT = h -  tempH * 0.006
  tempdiffValue = (idealAverT + tempAverT * -1.0).abs
  if count == 0 || diffValue > tempdiffValue
    index = count + 1
    diffValue = tempdiffValue
  end
end
puts index


Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n, m;
int a[55], b[55], c[55], d[55];
/**********************************************/

int main(){
    cin >> n >> m;
    REP(i, n){
        cin >> a[i] >> b[i];
    }
    REP(i, m){
        cin >> c[i] >> d[i];
    }

    REP(i, n){
        int point = 0; 
        REP(j, m){
           if(abs(a[i]-c[j])+abs(b[i]-d[j]) < abs(a[i]-c[point])+abs(b[i]-d[point])){
               point = j;
           } 
        }
        cout << point+1 << endl;
    }
}


Measured memory_bytes: 256
// ITP1_11_A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}
vector<int> di(6);
tuple<int,int,int,int> c_sn(){
    return forward_as_tuple(di[0],di[1],di[4],di[5]);
}
tuple<int,int,int,int> c_we(){
    return forward_as_tuple(di[0],di[2],di[3],di[5]);
}

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

    string order;
    for(int i=0;i<6;i++){
        int s;
        cin>>s;
        di[i]=s;
    }
    cin>>order;
    for(int i=0;i<order.size();i++){
        int a,b,c,d;
        if(order[i]=='S'){
            tie(a,b,c,d)=c_sn();
            //cout<<a<<b<<c<<d<<endl;
            di[0]=c;
            di[1]=a;
            di[4]=d;
            di[5]=b;
        }else if(order[i]=='N'){
            tie(a,b,c,d)=c_sn();
            di[0]=b;
            di[1]=d;
            di[4]=a;
            di[5]=c;
        }else if(order[i]=='W'){
            tie(a,b,c,d)=c_we();
            di[0]=b;
            di[2]=d;
            di[3]=a;
            di[5]=c;
        }else{
            tie(a,b,c,d)=c_we();
            di[0]=c;
            di[2]=a;
            di[3]=d;
            di[5]=b;
        }
    }
    cout<<di[0]<<endl;
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	string s; cin >> s;
	map<string, int> ways[20];
	for(int i = 0; i < 1<<n; i++){
		string in0, in1;
		for(int j = 0; j < n; j++){
			if(i&(1<<j)) in1.push_back(s[j]);
			else in0.push_back(s[j]);
		}
		reverse(in1.begin(), in1.end());
		ways[in0.size()][in0 + in1]++;
	}
	long long ans = 0;
	for(int i = 0; i < 1<<n; i++){
		string in0, in1;
		for(int j = 0; j < n; j++){
			if(i&(1<<j)) in1.push_back(s[j + n]);
			else in0.push_back(s[j + n]);
		}
		reverse(in1.begin(), in1.end());
		ans += ways[n - in0.size()][in1 + in0];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 68224
while True:
    height, width = [int(x) for x in input().split(" ")]
    if height == width == 0:
        break
    col1 = "#." * 150
    col2 = ".#" * 150
    col_set = col1[:width] + "\n" + col2[:width] + "\n"
    print(col_set * (height // 2) + (col1[:width] + "\n") * (height % 2))



Measured memory_bytes: 5640
import math

def parse(line, i):
    [s, p] = line.split()
    
    return [s, int(p), i]

input_n = int(input())
input_S = [parse(input(), i) for i in range(input_n)]

for line in sorted(input_S, key=lambda x: (x[0], -x[1])):
    print(line[2] + 1)

Measured memory_bytes: 3060
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    nums = np.array(read().split(), np.int64)
    a = nums[:9]

    for x in nums[10:]:
        a[a == x] = 0
    pos = ((0,1,2), (3,4,5), (6,7,8), (0,3,6), (1,4,7), (2,5,8), (0,4,8), (2,4,6))
    for pose in pos:
        if a[pose[0]] == a[pose[1]] == a[pose[2]] == 0:
            print('Yes')
            sys.exit()
    print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 26676
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,a,b,k = list(map(int, input().split()))

### 素数の逆元とCombination

M = 998244353 # 出力の制限
N = n+10 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M


def gcd2(a, b):
    """a*x + b*y = gcd(a,b)なるx,yも求める
    """
    l = []
    while b:
        l.append(divmod(a,b))
        a, b = b, a%b
    x, y = 1, 0
    for aa,bb in l[::-1]:
        x, y = y, x - aa*y
    return a, x, y
g,xa,xb = gcd2(a,b)
# xa*a + xb*b = g
if k%g!=0:
    ans = 0
else:
    va, vb = xa*(k//g), xb*(k//g)
    l = a*b//g
    if vb<0:
        tmp = abs(vb)//(l//b) + int(abs(vb)//(l//b)!=0)
        vb += tmp*(l//b)
        va -= tmp*(l//a)
    elif vb>0:
        tmp = abs(vb)//(l//b)
        vb -= tmp*(l//b)
        va += tmp*(l//a)
    init = (va,vb)
    ans = 0
    while va>=0:
#         print(va,vb,va*a + vb*b)
        assert va*a + vb*b == k
        ans += cmb(n, va, M) * cmb(n, vb,M)
        ans %= M
        va -= l//a
        vb += l//b
print(ans)

Measured memory_bytes: 104772
/*
	Author: Hamza Hasbi
	Copyrights: "h.hamza" ==> "www.hamzahasbi.me"
	Date: 10/06/2017 12:58:47
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define uld unsigned long double
#define ui unsigned int
#define ud unsigned double
#define uf unsigned float
#define pi 2*acos(0.0)
#define module cin.ignore()
#define rep(i,l,r) for(auto i=l;i<=r;i++)
#define range(x,y) for(auto x:y)
//inline lcm(int a,int b) {return a*b/__gcd(a,b);}
//inline gcd(ll a,ll b) {return 1LL*b == 0 ? a : gcd(1LL*b, a*1LL % b*1LL);}
using namespace std;

main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	scanf("%d",&n);
	int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,other=0;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(x>=1 && x<=399) a=1;
		if(x>=400 && x<=799) b=1;
		if(x>=800 && x<=1199) c=1;
		if(x>=1200 && x<=1599) d=1;
		if(x>=1600 && x<=1999) e=1;
		if(x>=2000 && x<=2399) f=1;
		if(x>=2400 && x<=2799) g=1;
		if(x>=2800 && x<=3199) h=1;
		if(x>=3200) other++;
	}
	cout<<max(1,a+b+c+d+e+f+g+h)<<" "<<max(1,a+b+c+d+e+f+g+h+other)<<endl;
	return 0;
}


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

int main() {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n - 2; i++) {
        if (s.substr(i, 3) == "ABC") {
            ans++;
            i += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int ans = 0;
		for (int i=0;i<=a;i++) {
			for (int j=0;j<=b;j++) {
				for (int k=0;k<=c;k++) {
					if ((i*500)+(j*100)+(k*50) == x) {
            ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
 
}

Measured memory_bytes: 35740
using System;
class torikainoakaunntonanndakke
{
    static void Main()
    {
        int[] a = new int[10000];
        a[0] = 2;
        int z = 1;
        int g = 2;
        for(;; )
        {
            for(int m = 0; m < z; m++)
            {
                if (g % a[m] == 0)
                    goto stop;
            }
            a[z] = g;
            z++;
            stop:;
            if (g % 2 == 0)
                g++;
            else
                g += 2;
            if (z == 10000)
                break;
        }
        ulong[] k = new ulong[50];
        int j = 0;
        while (true)
        {
            int b = int.Parse(Console.ReadLine());
            if (b == 0) break;
            ulong c = 0;
            for(int i = 0; i < b; i++)
                c += (ulong)a[i];
            k[j] = c;
            j++;
        }
        for(int i = 0; i < j; i++)
        {
            Console.WriteLine(k[i]);
        }
    }
}

Measured memory_bytes: 9144
#include<iostream>
#include<math.h>
#include<strings.h>
using namespace std;

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

Measured memory_bytes: 3596
#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() {
    int n;
    cin >> n;
    
    int res = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = i; j <= n; ++j){
            for(int k = j; k <= n; ++k){
                int x = __gcd(__gcd(i, j), k);
                if(i == j){
                    if(i == k){
                        res += x;
                    }else{
                        res += (3 * x);
                    }
                }else{
                    if(j == k){
                        res += (3 * x); 
                    }else{
                        res += (6 * x);
                    }
                }
            }
        }
    }
    
    cout << res << endl;
    return 0;
}


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

int main(){
  int n,d,tmp;
  long long int dist=0, intDist=0, cnt=0;
  cin>>n>>d;
  vector<vector<int> > points;
  
  for(int i=0;i<n;i++){
      vector<int> point;
      for(int j=0;j<d;j++){
          cin>>tmp;
          point.push_back(tmp);
      }
      points.push_back(point);
  }
  
  for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
          dist=0;
          for(int k=0;k<d;k++){
              dist+=(int)pow((points[i][k]-points[j][k]),2);
          }
          intDist=sqrt(dist);
          if((intDist*intDist)==dist) cnt++;
        //   cout<<(intDist*intDist)<<" "<<dist<<endl;
      }
  }
  cout<<cnt;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
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; }
int Inf = (1<<30);
ll inf = (1LL<<60);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n;
	cin >> n;
	int sum = 0;
	int i;
	for (i = 1; i <= 500000; i++) {
		sum += i;
		if (sum >= n) break;
	}
	cout << i;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
if n==1:
    print("Yes")
    exit()
for i in range(1,n):
    if h[i]-h[i-1]<=-1:
        print("No")
        exit()
    elif h[i]-h[i-1]==0:
        pass
    elif h[i]-h[i-1]>=1:
        h[i]-=1
print("Yes")


Measured memory_bytes: 84916
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    ll H[N+10];
    bool ans=true;
    for(ll i=0; i<N; i++) cin >> H[i];
    H[0]--;
    for(ll i=1; i<N; i++){
        if(H[i] > H[i-1]){
            H[i]--;
        }
        if(H[i] < H[i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 1024
inputs = [s.strip() for s in open(0).readlines()]
import numpy as np
class Grid():
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, rows in zip(range(h), grid):
            for j, val in zip(range(w), rows):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, rows)) for rows in self.grid])
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val

h, w = map(int, inputs[0].split())
grid = Grid([s.strip() for s in inputs[1:]]).grid
grid = grid[:, ~np.all(grid == '.', axis=0)]
grid = grid[~np.all(grid == '.', axis=1), :]
print(*[''.join(map(str, row)) for row in grid], sep='\n')

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ld a,b,h,m;cin>>a>>b>>h>>m;
    if(a<b)swap(a,b);
    ld k=min(abs(30*h+0.5*m-6*m),abs(360-abs(30*h+0.5*m-6*m)));
    ld A,B;
    if(k>90&&k<180){k=acos(-1)-k*2*acos(-1)/360;B=a+b*cos(k);A=b*sin(k);}
    else if(k<90&&k>0){k=k*2*acos(-1)/360;A=a*sin(k);B=a*cos(k)-b;}
    else if(k==180){cout<<fixed<<setprecision(15)<<a+b<<endl;return 0;}
    else if(k==90){cout<<fixed<<setprecision(15)<<sqrt(a*a+b*b)<<endl;return 0;}
    else if(k==0){cout<<fixed<<setprecision(15)<<a-b<<endl;return 0;}
    cout<<fixed<<setprecision(15)<<sqrt(A*A+B*B)<<endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) ((x)*(x))

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

const int mn=105;

int n;
int a[mn];

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif

    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);

    int ans=0;
    for(int i=2;i<=n;i++){
        if (a[i]==a[i-1]) a[i]=100000,ans++;
    }
    printf("%d\n",ans);

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn(1e5+10);
int n,a[maxn];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	cout<<a[n/2+1]-a[n/2]<<endl;
	return 0;
}

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

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

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

  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

  int maxi;
  int maxcount = 0;
  int nextmax = 0;

  rep(i,n) maxi = max(maxi, a.at(i));
  rep(i,n) if(a.at(i)==maxi) maxcount++;
  rep(i,n){
    if(a.at(i)==maxi) continue;
    nextmax = max(nextmax, a.at(i));
  }

  if(maxcount>=2){
    rep(i,n) cout << maxi << endl;
    return 0;
  }

  rep(i,n){
    if(a.at(i)==maxi) cout << nextmax << endl;
    else cout << maxi << endl;
  }
}


Measured memory_bytes: 3984
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> Q;

int n, ans, l, r, p;
string s[10010];

int main()
{
	int n, k;
	ll ans = 1;
	cin >> n >> k;
	cout << n - k + 1 << endl;
	cin >> n;
}

Measured memory_bytes: 384
S = input()

elements = ["maerd", "remaerd", "esare", "resare"]
reverseS = S[::-1]

ans = "NO"
i = 0
while True:
    flg = 0
    for element in elements:
        l = len(element)
        if element == reverseS[i:i+l]:
            i += l
            flg = 1
            break
    if flg == 0:
        break
    elif i == len(reverseS):
        ans = "YES"
        break

print(ans)

Measured memory_bytes: 3188
def is_prime(x):
    if x == 2:
        return True
    if x < 2 or x%2==0:
        return False
    i = 3
    while i <= x**(0.5):
        if x%i==0:
            return False
        i+=2
    return True

if __name__=='__main__':
    N=int(input())
    cnt=0
    for _ in range(N):
        if is_prime(int(input())): cnt+=1
    print(cnt)

Measured memory_bytes: 7792
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N   200005
#define MAX 300005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcount
#define PI acos(-1)
//#define endl "\n"
 
const int inf = (int)1e18 + 10;
vec v[N];
int ans[N] = {0} , val[N] = {0};
void dfs(int x , int p ){
  ans[x] =  val[x];
      for(int i = 0 ; i < v[x].size() ; i++ ){
           int y = v[x][i];
           if(y == p) continue;
           val[y] += val[x];
           dfs(y , x);
      }


}
signed main(){
  fast;
  
  int n , q , x , y;
  cin >> n >> q;
  for(int i = 1 ; i <n ; i++){
        cin >>x >> y;
        v[x].pb(y);
        v[y].pb(x);
  }

  while(q--){
        cin >> x >> y;
        val[x] += y;
  }
  dfs(1 , 0);
  for(int i = 1 ; i <= n ; i++)
    cout << ans[i] << " ";




 
}

Measured memory_bytes: 25856
import java.util.Scanner;

public class Main {

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

		int H = scan.nextInt();
		int W = scan.nextInt();

		char C[][] = new char[H][W];
		for (int i = 0; i < H; i++) {
			C[i] = scan.next().toCharArray();
		}
		for (int i = 0; i < 2 * H; i++) {
			for (int j = 0; j < W; j++) {
				System.out.print(C[i / 2][j]);
			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 26556
#include<stdio.h>

int main(void)
{
    char num[1000];
    int sum = 0, i = 0;
    
    while(1){
        scanf("%s", num);
        if(num[0] == '0'){
            break;
        }
        sum = 0;
        for(i=0;num[i] != '\0';i++){
            sum += num[i] - '0';
        }
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 536
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) cout << "Left" << endl;
	else if (a + b == c + d) cout << "Balanced" << endl;
	else cout << "Right" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 300 + 7;
const int inf = 2e9 + 7;
const ll infl = 1e18 + 7;
const long double eps = 1e-9;
const ll mod = 1e9 + 7;

ll dp[(1 << 21) + 7];
int go[21][21];

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // _DEBUG

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	dp[0] = 1;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> go[i][j];
		}
	}
	
	for (int i = 0; i < (1 << n); i++) {
		int cnt = 0;
		for (int j = 0; j < n; j++) {
			if ((i & (1 << j)) != 0) cnt++;
		}
		for (int j = 0; j < n; j++) {
			if ((i & (1 << j)) == 0 && go[cnt][j]) {
				dp[i | (1 << j)] = (dp[i | (1 << j)] + dp[i]) % mod;
			}
		}
	}

	cout << dp[(1 << n) - 1];
	return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define MAX 10000
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL) {
        return;
    }
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL) {
        h1 = setHeight(T[u].left) + 1;
    }
    if (T[u].right != NIL) {
        h2 = setHeight(T[u].right) + 1;
    }
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if (T[u].parent == NIL) {
        return NIL;
    }
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) {
        return T[T[u].parent].left;
    }
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) {
        return T[T[u].parent].right;
    }
    return NIL;
}

void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].left != NIL) {
        deg++;
    }
    if (T[u].right != NIL) {
        deg++;
    }
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);
    if (T[u].parent == NIL) {
        printf("root\n");
    }
    else if (T[u].left == NIL && T[u].right == NIL) {
        printf("leaf\n");
    }
    else {
        printf("internal node\n");
    }
}

int main() {
    int v, l, r, root = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        T[i].parent = NIL;
    }
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) {
            T[l].parent = v;
        }
        if (r != NIL) {
            T[r].parent = v;
        }
    }
    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) {
            root = i;
        }
    }
    setDepth(root, 0);
    setHeight(root);
    for (int i = 0; i < n; i++) {
        print(i);
    }
    return 0;
}


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

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

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

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

using namespace std;

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

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

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  char c='a';
  int offset;
  vector<string> S(n);
  string ans="";
  for(int i = 0; i < n; ++i) {
    cin >> S[i];
  }
  for(int i = 0; i < 26; ++i) {
    int a=0;
    int minC=(int)1e9;
    for(int j = 0; j < n; ++j) {
      a = count(S[j].begin(), S[j].end(), c+i);
      minC = min(minC, a);
    }
    ans += string(minC, c+i);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        n: usize,
        m: usize,
        heights: [usize; n],
        bridges: [(usize, usize); m],
    }

    let mut viewers: HashMap<&usize, Vec<usize>> = HashMap::new();
    let mut count = 0;

    for bridge in &bridges {
        if let Some(vec) = viewers.get_mut(&bridge.0) {
            vec.push(bridge.1);
        } else {
            viewers.insert(&bridge.0, vec![bridge.1]);
        }
        if let Some(vec) = viewers.get_mut(&bridge.1) {
            vec.push(bridge.0);
        } else {
            viewers.insert(&bridge.1, vec![bridge.0]);
        }
    }

    for (key, values) in &viewers {
        if !values.iter().all(|x| heights[**key-1] > heights[*x-1]) {
            count += 1;
        }
    }

    println!("{}", n - count);

}


Measured memory_bytes: 15016
s = str(input())
t = str(input())

ans = len(t)
for i in range(len(s) - len(t) + 1):
    tmp_ans = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            tmp_ans += 1
    ans = min(ans, tmp_ans)
print(ans)

Measured memory_bytes: 9036
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int lhs = scanner.nextInt();
    int rhs = scanner.nextInt();
    int k = scanner.nextInt();

    int sqrt = (int)Math.sqrt(rhs);
    TreeSet<Integer> set = new TreeSet<Integer>();
    for (int ix = 1; ix <= Math.min(lhs, rhs); ix++) {
      if (lhs % ix == 0 && rhs % ix == 0) {
        set.add(ix);
      }
    }

    Iterator<Integer> it = set.descendingIterator();
    while (--k > 0) {
      it.next();
    }

    System.out.println(it.next());
  }
}

Measured memory_bytes: 23636
#include <iostream>
#include <iomanip>


int main()
{
	double r,a,b;
	std::cin >> r;
	a = r*r*3.141592653589;
	b = 2 * r*3.141592653589;

	std::cout << std::fixed << std::setprecision(5) << a;
	std::cout << " ";
	std::cout << std::fixed << std::setprecision(5) << b << std::endl;

    return 0;
}

Measured memory_bytes: 3292
#include<stdio.h>
#include<math.h>
#define PI 3.1415926535
double kkkk(double h,double m) {
	double a, b,c;
	b = m / 60.0;
	if (b == 1)
		b = 0;
	a = (h * 60 + m) / (60.0 * 12);
	if (a == 1)
		a = 0;
	c = a - b;
	if (c < 0) {
		c = -c;
	}
	if (c > 0.5) {
		c = 1 - c;
	}
	return 2 * PI * c;
}

int main() {

	double a,b,h,m;
	double rad;
	double c2;
	double ans;
	scanf("%lf %lf %lf %lf", &a, &b, &h, &m);
	
	rad= kkkk(h,m);
	c2 = (a * a) + (b * b)- (2 * a * b * cos(rad));
	
	ans = sqrt(c2);

	printf("%.10f\n", ans);

	return 0;
}

Measured memory_bytes: 2580
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	int ans=0;
	cin>>a>>b>>c;
	for(int i=a;i<=b;i++){
		if(c%i==0){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int a;
  cin >> a;
  if(a / 100 == 7) {
    cout << "Yes" << endl;
    return 0;
  }
  a = a % 100;
  if(a / 10 == 7) {
    cout << "Yes" << endl;
    return 0;
  }
  if(a % 10 == 7) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3624