akhauriyash/Code-Regression huggingface dataset:
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

const long long MOD = 1000000007;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

const ll d = 1000000007;

void solve(ll N, std::vector<ll> A, std::vector<ll> B) {
  map<pair<ll, ll>, pair<ll, ll>> mp;
  vector<ll> p2(201010);
  ll z = 0;

  p2.at(0) = 1;
  rep(i, 201009) { p2.at(i + 1) = p2.at(i) * 2 % d; }

  rep(i, N) {
    ll x = A.at(i);
    ll y = B.at(i);
    if (x == 0 && y == 0) {
      z++;
    } else if (x == 0) {
      mp[{0, 0}].first++;
    } else if (y == 0) {
      mp[{0, 0}].second++;
    } else {
      if (y < 0) x = -x, y = -y;
      ll g = __gcd(abs(x), abs(y));
      x /= g;
      y /= g;
      if (x < 0)
        mp[{y, -x}].first++;
      else
        mp[{x, y}].second++;
    }
  }

  ll c = 1;
  for (auto v : mp) {
    ll a = p2.at(v.second.first) + p2.at(v.second.second) - 1;
    c = (c * a) % d;
  }

  cout << (c + z + d - 1) % d << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  std::vector<ll> A(N);
  std::vector<ll> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 23520
fun main(args: Array<String>) {
    val width = readLine()!!.trim().toInt()

    val row1 = readLine()!!.trim().split(' ').map {it.toInt()}
    val row2 = readLine()!!.trim().split(' ').map {it.toInt()}

    val row1Ruisekiwa = Array<Int>(width + 1) {0}
    val row2Ruisekiwa = Array<Int>(width + 1) {0}

    (0..(width - 1)).forEach { x ->
        row1Ruisekiwa[x + 1] = row1Ruisekiwa[x] + row1[x]
        row2Ruisekiwa[x + 1] = row2Ruisekiwa[x] + row2[x]
    }

    var maxTotal: Int = 0

    (1..width).forEach { row1Right ->
        val row1Total = row1Ruisekiwa[row1Right]
        val row2Total = row2Ruisekiwa[width] - row2Ruisekiwa[row1Right - 1]

        val total = row1Total + row2Total
        if (maxTotal < total) {
            maxTotal = total
        }
    }

    println(maxTotal)
}


Measured memory_bytes: 36388
#include<iostream>
#include<string>
#include<vector>

using namespace std;
int main(){

	int N, X;
	cin >> N >> X;
	vector<int>L(N+1);
	for (int i = 0; i < N; i++){
		int tmp; cin >> tmp;
		L[i + 1] = L[i] + tmp;
	}

	int ans = 0;
	for (int i = 0; i < N+1; i++){
		if (L[i] <= X)
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    r = stdin.readline()[:-1]
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #n = int(r)
    #a = r.split()
    #a,b,c = r.split()
    a = list(map(int, r.split()))
    #a,b,c,d = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #res = 0

    print(len(set(a)))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
N = input()
p_list = [int(i) for i in input().split(' ')]
P_up = sorted(p_list)
count = 0
for i in range(len(p_list)):
    if p_list[i]!=P_up[i]:
        count+=1
        
if count==2 or count==0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    printf("%s", ((x >= r && x <= W-r) && (y >= r && y <= H-r))? "Yes\n" : "No\n");
}


Measured memory_bytes: 2104
N,Wmax=map(int,input().split(' '))
W=[]
V=[]
for _ in range(N):
	w,v = map(int,input().split(' '))
	W.append(w)
	V.append(v)

Vmax=sum(V)

# dp[i][v]=i番目の品物までだけを選び価値の合計をvとしたときの必要な重量の最小値
# ただしそのような価値の合計が実現不可能なときはNoneを格納

dp = []
for _ in range(N):
	dp.append([None]*(Vmax+1))

dp[0][0] = 0
dp[0][V[0]] = W[0]

for i in range(1,N):
	# 新しく積めるようになる荷物の価値をV[i]とする
	# このとき価値の合計をvにするのに必要な重量の最小値は
	#	  dp[i-1][v-V[i]]+W[i] と
	#   dp[i-1][v] のうち小さいほう
	for v in range(Vmax+1):
		if v-V[i]<0:
			dp[i][v] = dp[i-1][v]
		else:
			if dp[i-1][v] is not None:
				if dp[i-1][v-V[i]] is not None:
					dp[i][v] = min(dp[i-1][v],dp[i-1][v-V[i]]+W[i])
				else:
					dp[i][v] = dp[i-1][v]
			else:
				if dp[i-1][v-V[i]] is not None:
					dp[i][v] = dp[i-1][v-V[i]]+W[i]

ans = 0
for v in range(Vmax+1):
	try:
		ans = v if dp[-1][v]<=Wmax else ans
	except TypeError:
		pass

print(ans)

Measured memory_bytes: 130824
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<utility>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int n,a,b,c,d;
signed main(){
  cin>>n>>a>>b>>c>>d;
  bool ans=false;
  if(a>b){
    swap(a,b);
  }
  int dist=b-a;
  int res=d-c;
  int m=0;
  rep(i,n){
    if((dist<=(d*(n-1-i)-c*i))&&dist>=(c*(n-1-i)-d*i)){
      ans=true;
      break;
    }
  }
  if(ans){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    int n = s.size();
    int m = t.size();
    bool ans = true;
    if(n < m){
        for(int i = 0; i < n; i++){
            if(s[i] != t[i]){
                ans = false;
                break;
            }
        }
        if(ans){
            cout << "Yes\n";
            return 0;
        }
    }
    ans = false;
    for(int i = 0; i < min(n, m); i++){
        if(s[i] == t[i]) continue;
        else if(s[i] < t[i]){
            ans = true;
            break;
        } else {
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 3628
n, m = map(int, input().split())
a_l = [ int(input()) for _ in range(m) ]

dp = [1] * (n+1)
dp[0] = 1
if 1 not in a_l:
    dp[1] = 1
else:
    dp[1] = 0
if n > 1:
    for i in a_l:
        dp[i] = 0
    if 2 not in a_l:
        dp[2] = dp[0] + dp[1]
    else:
        dp[2] = 0
    for i in range(2,n+1):
        if dp[i] != 0:
            dp[i] = (dp[i-1] + dp[i-2])%1000000007
print(dp[-1])

Measured memory_bytes: 13624
import math
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())

def ceil(s, t):
    if s%t == 0:
        return s//t
    else:
        return s//t + 1


x = max(a)
b_list= []
for i in range(N):
    if b[i] > x :
        b_list.append(b[i])

y = sum(b_list)

b_list.sort(reverse=True)

ans = 0

for i in b_list:
    H -= i
    ans += 1
    if H > 0:
        pass
    elif H  == 0:
        break
    elif H < 0:
        break

if H > 0:
    ans += ceil(H, x)

print(ans) 

Measured memory_bytes: 12140
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int N,M,Q,B[200010],C,D;
int A[200010];
std::string S;

int main(){
	int n,a[110];
	cin>>n;
	REP(i,n){
		cin>>a[i];
	}
	cout<<*max_element(a,a+n)-*min_element(a,a+n)<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

const STAND = "0"
const HANDSTAND = "1"

type POS struct {
	num                  int
	before_handstand_num int
	after_handstand_num  int
}

type POSs []POS

func main() {

	var n, k int
	var s string
	handstand := 0

	pos := make(POSs, 1)

	tmpPos := POS{}
	index := 0

	fmt.Scan(&n, &k)
	fmt.Scan(&s)
	people := make([]string, len(s))
	runes := []rune(s)
	for i := 0; i < len(runes); i++ {
		people[i] = string(runes[i])
		if string(runes[i]) == STAND {
			if tmpPos.num == 0 {
				if index != 0 {
					pos[index-1].after_handstand_num += handstand
					tmpPos.before_handstand_num += handstand
				} else {
					tmpPos.before_handstand_num += handstand
				}
				handstand = 0
				tmpPos.num++
			} else {
				tmpPos.num++
			}
		} else {
			if tmpPos.num == 0 {
				handstand++
				continue
			}
			if index == 0 {
				pos[0] = tmpPos
			} else {
				pos = append(pos, tmpPos)
			}
			tmpPos = POS{}
			index++
			handstand++
		}
	}
	if tmpPos.num == 0 && handstand != 0 && index == 0 {
		fmt.Println(n)
		os.Exit(0)
	}
	if tmpPos.num != 0 {
		pos = append(pos, tmpPos)
	} else {
		pos[index-1].after_handstand_num += handstand
	}

	if k > index {
		fmt.Println(n)
		os.Exit(0)
	}
	/*
		for _, v := range pos {
			fmt.Println(v)
		}
	*/
	changeMaxNum := 0
	changeTmpNum := 0
	for i := 0; i+k <= len(pos); i++ {
		changeTmpNum = 0
		for j := 0; j < k; j++ {
			changeTmpNum += pos[i+j].before_handstand_num + pos[i+j].num
			if j == k-1 {
				changeTmpNum += pos[i+j].after_handstand_num
			}
		}
		//		fmt.Println(changeTmpNum)
		if changeMaxNum < changeTmpNum {
			changeMaxNum = changeTmpNum
		}
	}
	fmt.Println(changeMaxNum)
}


Measured memory_bytes: 8960
import math

def main():
    k=int(input())
    #gcds=[[[0]*(k+1) for i in range(k+1)]for j in range(k+1)]
    ans=0
    gcd2=[]
    for i in range(1,k+1):
        for j in range(1,k+1):
           gcd2.append(math.gcd(i,j))
    for i in range(1,k+1):
        for j in gcd2:
            ans+=math.gcd(i,j)
    '''
    for i in range(1,k+1):
        for j in range(1,k+1):
            for k in range(1,k+1):
                a,b,c=map(int,sorted([i,j,k]))
                print(a,b,c)
                if gcds[a][b][c]==0:
                    gcds[a][b][c]=gcd(a,b,c)
                ans+=gcds[a][b][c]
    '''
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 9312
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	IOS;
	 
    long double a; long double b; cin>>a>>b;
    long double h = (a*b*100.0)/100.0;
	ll g = h; cout<<g;
	return 0;
}


Measured memory_bytes: 3748
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	string S;
	cin >> S;
	string D[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	int a;
	rep(i, 7) if (D[i] == S) a = 7 - i;

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <ctime>
#include <math.h> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <utility>
#include <functional>
#include <set>

using namespace std;

int main() {
        string n;
        int temp;
        long long int sum = 0;
        cin >> n;
        for(int i = 0 ; i < n.size() ; i ++){
                temp = n[i] - 48;
                sum += temp;
        }

        if (sum % 9 == 0){
                cout << "Yes";
        }
        else{
                cout << "No";
        }

}

Measured memory_bytes: 3700
x = int(input())
if x <600:
  print(8)
elif x <800:
  print(7)
elif x<1000:
  print(6)
elif x<1200:
  print(5)
elif x<1400:
  print(4)
elif x<1600:
  print(3)
elif x<1800:
  print(2)
else:
  print(1)

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>


using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long ll;

int main() {

    ll N,D;
    cin >> N >> D;

    ll res;

    res = (N -1) / (2*D+1) + 1;

    cout << res << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIND(c, e) ((c).find(e) != (c).end())
#define NFIND(c, e) ((c).find(e) == (c).end())
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair
template<class T> inline T max(T a,T b,T c){return max(max(a,b),c);}
template<class T> inline T min(T a,T b,T c){return min(min(a,b),c);}
const int  MOD = int( 1e9 ) + 7;
const int    N = int( 1e5 ) + 69;
const int LOGN = ceil(log(N) / log(2));
const double EPS = 1e-6;

int a[N];
void __answer()
{
    int n, k, p;
    cin >> n >> k;
    if(n <= k) {
        cout << 1;
        return;
    }
    cout << (int)ceil((double)(n - 1) / (k - 1));
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cout << setprecision(11) << fixed;
    #ifdef LOCAL
        freopen("TEST.txt", "r", stdin);
    #endif
    __answer();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    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: 2104
import java.util.Scanner;


public class Main
{
	public static void main(String[] args) 
	{
		int m,n,p;
		Scanner scanner=new Scanner(System.in);		
		while(true)
		{
			n=scanner.nextInt();
			m=scanner.nextInt();
			p=scanner.nextInt();
			if ((n | m | p) == 0)
				break;
			int [] x=new int[n];
			double money=0.0;
			for(int i=0;i<n;i++)
			{
				x[i]=scanner.nextInt();
				money+=100*x[i];
			}
			money-=money*p/100;
			if(x[m-1]==0)
				System.out.println(0);
			else
				System.out.println((int)(money/x[m-1]));
		}
	}
}

Measured memory_bytes: 27868
#include <iostream>
using namespace std;
const int M = 1000000007;

class ModComb {
    long long *fact, *facti;
    const int mod;
public:
    explicit ModComb(int n, int m) : mod(m) {
        fact = new long long[n+1];
        facti = new long long[n+1];
        fact[0] = 1; facti[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % m;
        // calc 1/n!
        long long &inv = facti[n], pw = fact[n];
        inv = 1;
        for (int e = mod-2; e > 0; e /= 2) {
            if (e&1) inv = inv * pw % mod;
            pw = pw * pw % mod;
        }
        for (int i = n-1; i > 0; i--) facti[i] = (facti[i+1] * (i+1)) % m;
    }

    ~ModComb() {
        if (fact) delete[] fact;
        if (facti) delete[] facti;
    }

    long long get(int n, int k) const {
        if (n < 0 || k < 0 || k > n) return 0;
        return fact[n] * facti[k] % mod * facti[n-k] % mod;
    }

    long long getPerm(int n, int k) const {
        if (n < 0 || k < 0 || k > n) return 0;
        return fact[n] * facti[n-k] % mod;
    }
} mc(2001001, M);

long long g(int r, int c) {
    long long ret = 0;
    for (int a = 0; a <= r; a++) ret += mc.get(a+c+1, a+1);
    return ret % M;
}

int main() {
    int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
    long long ans = g(r2, c2) - g(r2, c1-1) - g(r1-1, c2) + g(r1-1, c1-1);
    cout << (ans % M + M) % M << endl;
}


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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  int i=1;
  int x=a[0];
  int ans=0;
  int sum=1;
  while(i<n){
    if(a[i]==x){
      sum++;
      if(i==n-1){
        if(sum%2==1) ans++;
      }
    }
    else{
      if(sum%2==1) ans++;
      sum=1;
      x=a[i];
      if(i==n-1) ans++;
    }
    i++;
  }
  cout<<ans<<endl;
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

map<ll,ll> dp;
int solve(int h)
{
	if(h==1)
		return 1;
	if(dp.find(h)!=dp.end())
	{
		return dp[h];
	}
	
	dp[h]=solve(h/2)+solve(h/2)+1;
	return dp[h];
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif

    int h;
    cin>>h;

    cout<<solve(h);

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
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 d = sc.nextInt();
      
      if(a+b>c+d){
        System.out.print("Left");
      }else if(a+b<c+d){
        System.out.print("Right");
      }else{
        System.out.print("Balanced");
      }
       
       
      
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
	int  n, k; string s;
        cin >> n >> k >> s;
	vector<ll> lr;
        if(s[0]!='L'){lr.push_back(0);}
	for(int l = 0; l < n; ++l){
		int r = l;
		for(; r < n; ++r){
			if(s[l]!=s[r]){break;}
        }
        lr.push_back(r-l);
       l = r-1;
    }
    
    int N = lr.size();
    vector<ll> sum(N+1);
    for(int i = 0; i < N; ++i){
        sum[i+1]=sum[i] + lr[i];
    }
    ll tmp = 0;
    P idx {};
    for(int i = 0; i < N+1; ++i){
    	int r = min(2*k+1+i, N);
        if(tmp<sum[r]-sum[i]){
            tmp = sum[r]-sum[i];
            idx = {i, r};
        }
    }
    
    vector<ll> a;
    for(int i = 0; i < N; ++i){
    	if(i == idx.first){
    	    a.push_back(tmp);
            i = idx.second-1;
        }
        else{
        	a.push_back(lr[i]);
        }
    }

    ll ans = 0;
    for(int i = 0; i < a.size(); ++i){
        ans+= max(0LL, a[i]-1LL);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3444
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#define endl "\n"
#define SRK ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EPS 1e-6
typedef long long ll;
using namespace std;


    int main()
{
    SRK;
    string s;
    cin >> s;
    if (s[0] == 'R')
    {
        if (s[1] == 'R')
        {
            if (s[2] == 'R')
            {
                cout << "3\n";
            }
            else
            {
                cout << "2\n";
            }
        }
        else
        {
            cout << "1\n";
        }
    }
    else if (s[1] == 'R')
    {
        if (s[2] == 'R')
        {
            cout << "2\n";
        }
        else
        {
            cout << "1\n";
        }
    }
    else if (s[2] == 'R')
    {
        cout << "1\n";
    }
    else
    {
        cout << "0\n";
    }

}



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

int main(){
  int a, b;
  char op;
  while(1){
    cin >> a >> op >> b;
    if(op=='?')break;
    
    if(op=='+')cout << a+b <<endl;
    else if(op=='-')cout << a-b <<endl;
    else if(op=='*')cout << a*b <<endl;
    else if(op=='/')cout << a/b <<endl;
  }
  return 0;
}

Measured memory_bytes: 2996
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d){
		cout<<"Yes";
	}
	else if(abs(a-b)<=d&&abs(b-c)<=d){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

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

using namespace std;

typedef long long ll;

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

  ll n;cin>>n;
  ll sum=0;
  ll a[n];
  for(int i=0;i<n;i++){
      cin>>a[i];
      sum+=a[i];
  }
  ll tmp=n*(n+1)/2;
  if(sum%tmp!=0){
      cout<<"NO"<<endl;
      return 0;
  }
  sum/=tmp;
  ll k=0;
  bool ret=true;
  for(int i=0;i<n;i++){
      ll dif=-(a[(i+1)%n]-a[i]-sum);
      k+=dif/n;
      if(dif%n!=0||dif<0) ret=false;
  }
  if(ret&&(k==sum)) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>

#define ll long long
using namespace std;

const int N = 4e5;
int A[N], B[N];

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);

    if(((ll)a*(ll)b<(ll)n) || (a+b>n+1)){
        puts("-1");
        return 0;
    }
    
    int i, j;
    for(i=1; i<=n; i++)
        A[i] = i;
    
    if(b!=1){
        int t = (n-a);
        for(i=0; i<t/(b-1); i++){
            for(j=1; 2*j<=b; j++){
                int temp = A[b*i+j];
                A[b*i+j] = A[b*i+b-j+1];
                A[b*i+b-j+1] = temp;
            }
        }

        int l = t%(b-1)+1;
        for(j=1; 2*j<=l; j++){
            int temp = A[b*i+j];
            A[b*i+j] = A[b*i+l-j+1];
            A[b*i+l-j+1] = temp;
        }
    }

    for(i=1; i<=n; i++)
        printf("%d ", A[i]);      

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int dp[1000][5][2];
signed main(){
	string n;
	cin>>n;
	int k;
	cin>>k;
	int s = n.size();
	dp[0][1][0] = n[0] - '0' - 1;
	dp[0][0][0] = 1;
	dp[0][1][1] = 1;
	for(int i=0;i<s-1;i++){
		for(int j=0;j<=3;j++){
			dp[i+1][j][0] += dp[i][j][0]; // next is 0
			dp[i+1][j+1][0] += dp[i][j][0] * 9; // next is 1-9
			if( n[i+1] == '0' ){
				dp[i+1][j][1] += dp[i][j][1]; // next is 0
			}
			else{
				dp[i+1][j][0] += dp[i][j][1];
				dp[i+1][j+1][0] += dp[i][j][1] * ( n[i+1] - '0' - 1);
				dp[i+1][j+1][1] += dp[i][j][1];
			}
		}
	}
	cout<<dp[s-1][k][0] + dp[s-1][k][1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
    int a, b;
    cin >> a >> b;
    if (b == a) { cout << 2 * a ; }
    else if(b>a) { cout << 2*b -1; }
    else { cout << 2*a-1; }
    system("pause");
    return 0;
}

Measured memory_bytes: 504
N=int(input())
z=[]
for i in range(N):
    z.append(list(map(int,input().split())))
h=max(zz[2] for zz in z)
while(1):
    flag=1
    for x in range(101):
        for y in range(101):
            for zz in z:
                if max(h-abs(zz[0]-x)-abs(zz[1]-y),0) != zz[2]:
                    break
            else:
                print(x,y,h)
                exit()
    h+=1

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

int main() {
    int n; cin >>n;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >>h.at(i);
    string ret = "Yes";
    for (int i = n-1; i > 0; i--) {
        if (h.at(i)>=h.at(i-1)) {
            //ok
        }
        else if (h.at(i)>=h.at(i-1)-1) {
            h.at(i-1)--;
        }
        else {
            ret = "No";
            break;
        }
    }
    cout << ret << endl;
    return 0;
}

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

int main(){
    long double PI = acos(-1);
    long double a, b, c;
    cin >> a >> b >> c ;
    cout << fixed << setprecision(8);
    cout << a * b * sin(c * PI / 180) / 2 << endl;
    cout << a + b + sqrt(a*a + b*b - 2 * a * b * cos(c * PI / 180)) << endl;
    cout << b * sin(c * PI / 180) << endl;
    return 0;
}


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

int main() {
  string input;
  cin >> input;
  
  int smart_flg_g = 1;
  int smart_flg_k = 1;
  for(int i = 0; i < (int)input.size(); ++i){
    if ( i % 2 == 0 && input[i] == 'L' )  {      
      smart_flg_g = 0;
    }
    if (i % 2 == 1 && input[i] == 'R' )  {
      smart_flg_k = 0;
    }
  }
  if (smart_flg_g == 1 && smart_flg_k == 1) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import math
a, b, x = map(int, input().split())
def pta(a, b, sita):
    return  a * b - ((a ** 2) * math.tan(math.radians(sita)) / 2)
def ptb(a, b, sita):
    return (b ** 2 * math.tan(math.radians(90-sita)) / 2)
max = 90
min = 0
for i in range(60):
    sen = (max + min) / 2

    if (a ** 2) * b / 2 >= x:
        #print("ptb", ptb(a, b, sen))
        if ptb(a, b, sen) >= x / a:
            min = sen
        else:
            max = sen
    else:
        #print("pta", pta(a, b, sen))
        if pta(a, b, sen) >= x / a:
            min = sen
        else:
            max = sen

print(sen)

Measured memory_bytes: 3188
n = gets.to_i
words = []
n.times do
  words << gets.chomp
end

last_c = nil
used = []
words.each do |w|
  if used.include?(w)
    puts "No"
    exit
  elsif last_c && last_c != w[0]
    puts "No"
    exit
  else
    used << w
    last_c = w[-1]
  end
end

puts "Yes"

Measured memory_bytes: 1788
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

	private void run() throws NumberFormatException, IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			nodes[i] = new Node();
		}
		for (int i = 0; i < n; i++) {
			int v = scanner.nextInt();
			int l = scanner.nextInt();
			int r = scanner.nextInt();
			nodes[v].left = l;
			nodes[v].right = r;
			if (l != -1)
				nodes[l].parent = v;
			if (r != -1)
				nodes[r].parent = v;
		}
		int root = 0;
		for (int i = 0; i < n; i++) {
			if (nodes[i].parent == -1) {
				root = i;
				break;
			}
		}
		setDepth(root, 0, nodes);
		setHeight(root, nodes);
		for (int i = 0; i < n; i++) {
			print(i, nodes);
		}
	}

	private void print(int u, Node[] nodes) {
		System.out.printf("node %d: parent = %d, sibling = %d, ", u,
				nodes[u].parent, getSibling(u, nodes));
		int deg = 0;
		if (nodes[u].left != -1)
			deg++;
		if (nodes[u].right != -1)
			deg++;
		System.out.printf("degree = %d, depth = %d, height = %d, ", deg,
				nodes[u].d, nodes[u].h);
		if (nodes[u].parent == -1)
			System.out.println("root");
		else if (nodes[u].left == -1 && nodes[u].right == -1)
			System.out.println("leaf");
		else
			System.out.println("internal node");
	}

	private Object getSibling(int u, Node[] nodes) {
		int p = nodes[u].parent;
		if (nodes[u].parent == -1)
			return -1;
		if (nodes[p].left != u && nodes[p].left != -1)
			return nodes[p].left;
		if (nodes[p].right != u && nodes[p].right != -1)
			return nodes[p].right;
		return -1;
	}

	private int setHeight(int u, Node[] nodes) {
		int h1 = 0;
		int h2 = 0;
		if (nodes[u].left != -1)
			h1 = setHeight(nodes[u].left, nodes) + 1;
		if (nodes[u].right != -1)
			h2 = setHeight(nodes[u].right, nodes) + 1;
		return nodes[u].h = (h1 > h2 ? h1 : h2);
	}

	private void setDepth(int u, int d, Node[] nodes) {
		if (u == -1)
			return;
		nodes[u].d = d;
		setDepth(nodes[u].left, d + 1, nodes);
		setDepth(nodes[u].right, d + 1, nodes);

	}

	class Node {
		int parent = -1;
		int left = -1;
		int right = -1;
		int d;
		int h;
	}
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




int main() {

	int n, k, q;
	cin >> n >> k >> q;
	VI a(n, 0);
	REP(i, q) {
		int b;
		cin >> b;
		b--;
		a[b]++;
	}
	REP(i, n) {
		a[i] = k - q + a[i];
	}
	
	REP(i, n) {
		if (a[i] > 0)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;

	vector<int>order(n);
	for (int i = 0; i < n; i++) {
		order[a[i]-1] = i + 1;
	}
	for (int i = 0; i < n; i++) {
		cout << order[i] << ' ';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1536
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<lint> zyo,rz,z3;
lint mo=1000000007;
lint dp[810893];
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint cal(int a,int b){
	return ((zyo[a+b]*rz[a])%mo*rz[b])%mo;
}
int main()
{
	int n,m,k;lint out=0;
	cin>>n>>m>>k;
	zyo.pb(1);rep(i,931931) zyo.pb((zyo[i]*(i+1))%mo);
	rep(i,931931) rz.pb(invMod(zyo[i],mo));
	z3.pb(1);rep(i,810893) z3.pb((z3[i]*3)%mo);
	dp[0]=1;
	rep(i,m+k){
		dp[i+1]=dp[i]*2;
		if(i>=m) dp[i+1]-=cal(m,i-m);
		if(i>=k) dp[i+1]-=cal(k,i-k);
		dp[i+1]%=mo;if(dp[i+1]<0) dp[i+1]+=mo;
	}
	rep(i,m+k+1){
		//cout<<i<<' '<<dp[i]<<' '<<cal(i,n-1)<<' '<<z3[m+k-i]<<endl;
		out+=(dp[i]*cal(i,n-1))%mo*z3[m+k-i];
		out%=mo;
	}
	cout<<out%mo<<endl;
}


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

N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        H = xyh[0][2] + abs(xyh[0][0]-cx) + abs(xyh[0][1]-cy)
        Flag = True
        for i in range(1,N):
            tmp = xyh[i][2] + abs(xyh[i][0]-cx) + abs(xyh[i][1]-cy)
            if (xyh[i][2] == 0 and H > tmp) or (xyh[i][2] != 0 and H != tmp):
                Flag = False
                break
        if Flag:
            print(cx,cy,H)
            sys.exit()

Measured memory_bytes: 3064
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

bool win[2020][2020];
bool dp[2][2020][2020];
signed main() {
    int N; scanf("%d", &N);
    
    for(int i=0; i<N; i++) {
        for(int j=0; j<i; j++) {
            char c; scanf(" %c", &c);
            bool p = c - '0';
            win[i][j] = p;
            win[j][i] = !p;
        }
    }

    for(int i=0; i<N; i++) dp[0][i][i] = dp[1][i][i] = true;
    for(int d=1; d<N; d++) {
        for(int i=0; i<N-d; i++) {
            int j = i + d;
            bool f1 = false, f2 = false;
            for(int k=i; k<j; k++) {
                f2 |= dp[1][i][k] & dp[0][j-1][k] & win[j][k];
            }
            for(int k=i+1; k<=j; k++) {
                f1 |= dp[0][j][k] & dp[1][i+1][k] & win[i][k];
            }
            dp[0][j][i] = f1, dp[1][i][j] = f2;
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++) ans += (dp[0][N-1][i] & dp[1][0][i]);
    printf("%d\n", ans);
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<long long> Subsum(N);
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		Subsum[i] = A + (i > 0 ? Subsum[i - 1] : 0);
	}
	sort(Subsum.begin(), Subsum.end());
	long long ans = 0;
	for (auto itr = Subsum.begin(); itr != Subsum.end(); itr++) {
		if (*itr == 0) ans++;
		ans += distance(lower_bound(itr + 1, Subsum.end(), *itr),
			upper_bound(itr + 1, Subsum.end(), *itr));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
A, B = list(map(int, input().split()))

def sum_tap_num(tap_num, A, B):
	tap_sum = (tap_num-1)*(A-1)+A
	if tap_sum >= B:
		return tap_num
  	
	return sum_tap_num(tap_num+1, A, B)
if B==1:
	print(0)
else:
	print(sum_tap_num(1, A, B))



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

int main() {
  string s;
  cin >> s;
  int res = 700;
  for(int i = 0; i < 3; ++i) if(s[i] == 'o') {
    res += 100;
  }
  cout << res << endl;
  return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  int count = 0;
  rep(i, N)
  {
    cin >> a[i];
    if ((i + 1) % 2 != 0 && a[i] % 2 != 0)
      count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3592
N = int(input())
A = sorted(list(map(int, input().split())))

max_A = A[-1]
# df[i]...数字iが条件満たす:1、条件満たさない:0
df = [True for _ in range(max_A + 1)]

for i, a in enumerate(A):
    if i > 0:
        if A[i] == A[i - 1]:
            df[a] = False
            continue
    if df[a]:
        for num in range(2*a, max_A+1, a):
            df[num] = False
count = 0
for a in A:
    if df[a]:
        count += 1
print(count)

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

namespace B._754
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] arr = Console.ReadLine().ToCharArray();

            int min = int.MaxValue;
            int res;

            for (int i = 0; i < arr.Length - 3 + 1; i++)
            {
                res = Math.Abs(753 - int.Parse(new string(arr.Skip(i).Take(3).ToArray())));
                min = min > res ? res : min;
            }

            Console.WriteLine(min);
        }
    }
}

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

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

    if (n[1] == n[2] && (n[0] == n[1] || n[2] == n[3])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  int a[2*N];
  for (int i = 0; i < 2 * N; i++) cin >> a[i];

  sort(a, a + 2 * N);
  int ans = 0;
  for (int i = 0; i < 2 * N; i += 2) {
    ans += min(a[i], a[i+1]);
  }

  // 解答
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import Counter

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, K, L = map(int, readline().rstrip().split())
    uf_road = UnionFind(N)
    uf_train = UnionFind(N)
    
    for _ in range(K):
        p, q = map(int, readline().rstrip().split())
        uf_road.union(p-1, q-1)
    
    for _ in range(L):
        r, s = map(int, readline().rstrip().split())
        uf_train.union(r-1, s-1)
    
    pairs = []
    for i in range(N):
        pairs.append((uf_road.find(i), uf_train.find(i)))
    
    cnt = Counter(pairs)
    res = [cnt[pair] for pair in pairs]
    print(*res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 46912
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
using namespace std;

typedef long long ll;

ll calc(vector<ll> &a,vector<ll> &b, ll x) {
  //  vector<ll>a,b;
  ll ans = 1e18;
  ll d;
  //  for ( int i = 0; i < 2; i++ ) {
  //    if ( i == 0 ) a = s,b = t;
  //    else a = t,b = s;
    for ( int j = 0; j < 2; j++ ) {
      int apos = lower_bound(a.begin(),a.end(),x)-a.begin();
      ll ax=a[apos-j];
      for ( int k = 0; k < 2; k++ ) {
	int bpos = lower_bound(b.begin(),b.end(),ax)-b.begin();
	ll bx = b[bpos-k];
	d = abs(x-ax)+abs(ax-bx);
	ans = min(ans,d);	
      }

    }
    //  }
  return ans;
}


int main() {
  int A,B,Q; cin >> A >> B >> Q;
  vector<ll> s(A+2),t(B+2);

  ll x[100010];
  s[0] = t[0] = -1e18;
  for ( int i = 1; i <= A; i++ ) cin >> s[i];
  for ( int i = 1; i <= B; i++ ) cin >> t[i];
  for ( int i = 0; i < Q; i++ ) cin >> x[i];
  s[A+1] = 1e18;
  t[B+1] = 1e18;
  for ( int i = 0; i < Q; i++ ) {
    cout << min(calc(s,t,x[i]),calc(t,s,x[i])) << endl;
  }
  return 0;
}


Measured memory_bytes: 3712
n,m = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(n)]
CD = [list(map(int, input().split())) for _ in range(m)]

for ab in AB:
  ind = 1
  ans = 1
  dist = float('inf')
  for cd in CD:
    temp_dist = abs(ab[0]-cd[0])+abs(ab[1]-cd[1])
    if temp_dist<dist:
      ans = ind
      dist = temp_dist
    ind += 1
  print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<string>
using namespace std;
int main(){
	
	string s;
	cin>>s;
	int a=s.size();
	int ok=0;
	if(s[0]=='A'){
		ok=ok+1;
	}
	int fl=0;
	int j=0;
	int u=0;
	for(int i=2;i<a-1;i++){
		if(s[i]=='C'){
			fl=fl+1;
			j=i;
			}
	}
	if(fl==1){
		ok=ok+1;
		u=j;
	}
	for(int i=1;i<a;i++){
		if(i!=u){
			if(s[i]>='A'&&s[i]<='Z'){
				break;
			}else if(i==a-1){
				ok=ok+1;
		}
	}
	}
		if(ok==3){
			cout<<"AC"<<endl;
		}else{cout<<"WA"<<endl;}
	
	
return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

long[10^^5] AS, BS;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (i; 0..N) {
        AS[i] = readln.chomp.to!long;
    }
    sort(AS[0..N]);

    if (N == 2) {
        writeln(AS[1] - AS[0]);
        return;
    }

    BS[N/2] = AS[0];
    int i = 0, j = N, a = N/2-1, b = N/2+1, x = 1;
    for (;;) {
        if (x++ % 2) {
            --j;
            if (i == j) break;
            BS[a--] = AS[j];
            --j;
            if (i == j) break;
            BS[b++] = AS[j];
        } else {
            ++i;
            if (i == j) break;
            BS[a--] = AS[i];
            ++i;
            if (i == j) break;
            BS[b++] = AS[i];
        }
    }
    long r1;
    i = 0;
    j = 1;
    while (j != N) {
        r1 += abs(BS[i++] - BS[j++]);
    }

    BS[N/2] = AS[N-1];
    i = -1;
    j = N-1;
    a = N/2-1;
    b = N/2+1;
    x = 0;
    for (;;) {
        if (x++ % 2) {
            --j;
            if (i == j) break;
            BS[a--] = AS[j];
            --j;
            if (i == j) break;
            BS[b++] = AS[j];
        } else {
            ++i;
            if (i == j) break;
            BS[a--] = AS[i];
            ++i;
            if (i == j) break;
            BS[b++] = AS[i];
        }
    }
    long r2;
    i = 0;
    j = 1;
    while (j != N) {
        r2 += abs(BS[i++] - BS[j++]);
    }

    writeln(max(r1, r2));
}

Measured memory_bytes: 2812
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include <initializer_list>
#include<unordered_set>
#include<map>
#include<cmath>
#include <iterator>
#include<stack>
#include<queue>
#include <iomanip>
#include<math.h>
#include <limits.h>
#include <numeric>
#include <functional>
#include<fstream>
using namespace std;

#define mod 300002
#define ll  long long
#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int x;
	string s;
	cin >> x;
	cin >> s;
	cout << (x >= 3200 ? s : "red") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <climits>
using namespace std;
/*------- Constants---- */

#define LL                      long long
#define Ulong                   unsigned long long
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-14
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl
#define nl                      cout<<endl
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("/home/matrixcode/Desktop/in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
  register char c = getchar();x = 0;
  int neg = 0;
  for(; ((c<48 || c>57) && c != '-'); c = getchar());
  if(c=='-'){neg = 1;c = getchar();}
  for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
  if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
  long long ret = 1;
  for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 405;
int n;
int a[22][22];
LL dp[22][1<<21];
int mod = 1e9+7;

LL solve(int i, int mask) {
  if(i == n) return 1;
  if(dp[i][mask] != -1) return dp[i][mask];

  LL ret = 0;
  for(int j = 0; j < n; j ++) {
    if(a[i][j] && (mask & (1 << j))) {
     ret += solve(i + 1, mask ^ (1 << j));
    }
  }
  ret = ret % mod;
  return dp[i][mask] = ret;

}
int main()
{
  in(n);
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j ++) {
      in(a[i][j]);
    }
  }
  memset(dp,-1,sizeof dp);
  cout << solve(0, (1<<n) - 1) << endl;
}


Measured memory_bytes: 360832
#include<iostream>

using namespace std;

int main()
{
  int n;
  cin>>n;
  int a=0, b = 0, c =0, d =0;
  while(n--){
    string s;
    cin>>s;
    if(s=="AC")a++;
    else if(s=="TLE")c++;
    else if(s=="WA")b++;
    else d++;
    s.clear();
  }
  cout<<"AC x "<<a<<endl<<"WA x "<<b<<endl<<"TLE x "<<c<<endl<<"RE x "<<d<<endl;
  return 0;
}


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

using namespace std;

int main(){
  	int n,k;
  	cin>>n>>k;
  	string s;
  	cin>>s;
    for(int i = 0;i<n;i++){
     	if(i == k-1){
         cout<< (char)tolower(s[i]); 
          
        }else{
         cout<< s[i]; 
        }
    }
	return 0;
}

Measured memory_bytes: 256