akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,M;
  cin>>N>>M;
  VI P(M);
  VS S(M);
  rep(i,M) cin>>P[i]>>S[i];
  VI F(N);
  VI cnt(N);
  int pen=0;
  int ac=0;
  rep(i,M){
    if(F[P[i]-1]) continue;
    if(S[i]=="WA"){
      cnt[P[i]-1]++;
    }else{
      F[P[i]-1]=1;
      ac++;
    }
  }
  rep(i,N) if(F[i]) pen+=cnt[i];
  cout<<ac<<" "<<pen<<endl;
}


Measured memory_bytes: 6912
#include <stdio.h>

int main(){
  int i,j,k,n,t;
  while (1){
    scanf("%d",&n);
    if (n==0) return 0;
    k=(n-1)/2;
    int ans[5000];
    int L[5000];
    int cnt=0;
    for (i=0;i<k+1;i++)
      ans[i]=0;

    for (i=1;i<n;i++){
      t=i*i%n;
      for (j=0;j<cnt;j++)
        if (L[j]==t) break;
      if (j==cnt){
        L[cnt]=t;
        cnt++;
      }
    }
    for (i=0;i<cnt;i++)
      for (j=i+1;j<cnt;j++){
        int t=L[i]-L[j];
        if (t<0) t+=n;
        if (t>k) t=n-t;
        ans[t]+=2;
      }
    for (i=1;i<=k;i++)
      printf("%d\n",ans[i]);
  }
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
main() {
	int a;
	cin>>a;
	if(a==1) cout<<"1";
	if(a>=2 and a<4) cout<<"2";
	if(a<8 and a>=4) cout<<"4";
	if(a<16 and a>=8) cout<<"8";
	if(a<32 and a>=16) cout<<"16";
	if(a<64 and a>=32) cout<<"32";
	if(a<128 and a>=64) cout<<"64";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m, p;
    cin >> n >> m >> p;

    vl a(m), b(m), c(m);
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;  b[i]--;
        c[i] = p - c[i];
    }

    vl dist(n, INF);  // dist[v] : 頂点0から頂点vへの最短距離
    dist[0] = 0;
    rep(loop, n-1) {
        rep(i, m) {
            if(dist[a[i]] == INF) {
                continue;
            }
            if(dist[b[i]] > dist[a[i]] + c[i]) {
                dist[b[i]] = dist[a[i]] + c[i];
            }
        }
    }

    vl negativeCycle(n);  // negativeCycle[v] : 頂点vを含む負閉路があるとき1
    rep(loop, n) {
        rep(i, m) {
            if(dist[a[i]] == INF) {
                continue;
            }
            if(dist[b[i]] > dist[a[i]] + c[i]) {
                dist[b[i]] = dist[a[i]] + c[i];
                negativeCycle[b[i]] = 1;
            }
            if(negativeCycle[a[i]]) {
                negativeCycle[b[i]] = 1;
            }
        }
    }

    if(negativeCycle[n-1]) {
        out(-1);
    }
    else {
        out(max(0LL, -dist[n-1]));
    }
    
    re0;
}

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

int main(){
    int N, t, dig, sum = 0, i;

    cin >> N;
    t = N;
    while(t > 0){
        dig = t % 10;
        sum += dig;
        t /= 10;
    }
    if(N % sum == 0){
        cout << "Yes" << endl;
    }
    else if (N % sum != 0) {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m;
bool used[52];
bool flag[52];
int a[52],b[52];
int ans;
void dfs(int t){
flag[t]=true;
for (int i=0;i<m;++i){
if(used[i]||(a[i]!=t&&b[i]!=t))continue;
used[i]=true;
dfs(t==a[i]?b[i]:a[i]);
}
}

int main(){
cin>>n>>m;
for(int i=0;i<m;++i){
cin>>a[i]>>b[i];
--a[i];--b[i];
}
for(int i=0;i<m;++i){
for(int j=0;j<m;++j)used[j]=false;
for(int j=0;j<n;++j)flag[j]=false;
used[i]=true;
dfs(0);
bool c=true;
for(int j=0;j<n;++j)c &= flag[j];
if(!c)++ans;
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {

	int a, b, c;
	cin >> a >> b >> c;
	cout << (c/a)*b<< endl;

}



Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var N, K, count int
  fmt.Scan(&N,&K)
  A := make([]int,N)
  d := make([]int,K)
  Aj := make([]int,N)
  
  for i:=0; i<K; i++ {
    fmt.Scan(&d[i])
    for j:=0; j<d[i]; j++ {
      fmt.Scan(&Aj[j])
      A[Aj[j]-1] = 1
    }
  }
  for i:= range A {
    count += A[i]
  }
  fmt.Println(N-count)
}


Measured memory_bytes: 2312
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;

int S(int a, int n, int d)
{
    return (2*a+(n-1)*d)*n/2;
}

int main()
{
    int n,l;
    cin >> n >> l;
    
    if(l > 0)
    {
        cout << S(l+1, n-1, 1) << '\n';
        return 0;
    }
    else if(l + n - 1 < 0)
    {
        cout << S(l, n-1, 1) << '\n';
        return 0;
    }
    cout << S(l, n, 1) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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;
}

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int n;
int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}

ll dig(ll n){
    ll d = 0;
    while(n != 0){
        n/=10;
        d++;
    }
    return d;
}
map<char,int> a;
void solve() {
   int n;
   cin >> n;
   cout << n*n*n << endl;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


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

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

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

    std::vector<int> A(N);
    for (int  i = 0; i < N; i++)
    {
        std::cin >> A[i];
    }

    int ans = A[0];
    for (int i = 1; i < N; i++)
    {
        ans = gcd(ans, A[i]);
    }


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

Measured memory_bytes: 640
#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());
  cout << A[N-1]-A[0] << endl;
}

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

namespace Contest
{
	class Program
	{
		static void Main()
		{
            int N = int.Parse(Console.ReadLine());
            var a = new int[N];
            var flag = new bool[N];
            flag[0] = true;
            for (int x = 0; x < N; x++)
            {
                a[x] = int.Parse(Console.ReadLine()) - 1;
            }
            int ans = 0, i = 0;
            for (; i != 1; ans++)
            {
                if (flag[a[i]])
                {
                    break;
                }
                else
                {
                    flag[a[i]] = true;
                }
                i = a[i];
            }
            Console.WriteLine(i == 1 ? ans : -1);
#if DEBUG
            Console.ReadKey();
#endif
		}
	}
}

Measured memory_bytes: 15200
#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;

int main(){

    int r,c;
    int sum_c=0,sum_r=0,sum=0;
    cin >> r >> c;
    int a[r+1][c+1];

    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin >> a[i][j];
            sum_c += a[i][j];
        }
        a[i][c] = sum_c;
        sum_c = 0;
    }

    for(int j=0;j<c;j++){
        for(int i=0;i<r;i++){
            sum_r += a[i][j];
        }
        a[r][j] = sum_r;
        sum_r = 0;
    }

    for(int i=0;i<r;i++){
        sum += a[i][c];
    }
    a[r][c] = sum;


    for(int i=0;i<r+1;i++){
        for(int j=0;j<c+1;j++){
            cout << a[i][j];
            if(j != c) cout << " ";
        }
        cout << endl;
    }
    
}


Measured memory_bytes: 3092
n=int(input())
s=input().strip()
a='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
aa = dict()
for i, c in enumerate(a):
    aa[c] = i
def f(c):
    return a[(aa[c] + n)%26]

r = ''
for c in s:
    r += f(c)
print(r)


Measured memory_bytes: 3060
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.range;
import std.typecons;

class Bit(Type){
	Type[] data;
	size_t size;
	this(int s){
		SetSize(s);
	}
	void SetSize(size_t s){
		data = new Type[s];
		size = s;
		data[] = 0;
	}
	void add(size_t idx,Type value){
		if(idx >= size)
			return;
		data[idx] += value;
		add(idx + ((idx+1) & (-idx-1)),value);
	}
	Type sum(size_t idx){
		if(idx == size_t.max)
			return 0;
		if(idx >= size)
			idx = size;
		return data[idx] + sum(idx - ((idx+1) & (-idx-1)));
	}
	Type sum(size_t from,size_t to){
		return sum(to) - sum(from-1);
	}
}

int[] rdi(){
	return readln.split.map!(to!int).array;
}

void main(){
	int n = rdi[0];
	int[] releasefoo;
	int[] allowfoo;
	int[] indices;
	foreach(i;0..n){
		auto ab = rdi;
		releasefoo ~= ab[0];
		allowfoo ~= -ab[1];
		indices ~= i;
	}
	sort(zip(releasefoo,allowfoo,indices));
	Bit!long releasebit = new Bit!long(n);
	int[] releasebitidx = new int[n];
	foreach(i;0..n){
		releasebitidx[indices[i]] = i; 
	}
	sort(zip(allowfoo,releasefoo,indices));
	Bit!int bugcountbit = new Bit!int(n);
	int res=0;
	foreach(i;0..n){
		releasebit.add(releasebitidx[indices[i]],releasefoo[i]);
		bugcountbit.add(releasebitidx[indices[i]],1);
/*
		writeln(-allowfoo[i]," ",releasefoo[i]);
		double[] tmprb;
		foreach(j;0..n)
			tmprb ~= cast(double)releasebit.sum(j) / bugcountbit.sum(j);
		tmprb.writeln;
		int[] tmpbc;
		foreach(j;0..n)
			tmpbc ~= bugcountbit.sum(j);
		tmpbc.writeln;
*/
		double minallow = -allowfoo[i];
		int base = -1;
		int s = n+1;
		while(s > 1){
			int p = s;
			s = s/2;
			double allowsum = 0;
			int bugc = bugcountbit.sum(base + s);
			if(bugc > 0)
				allowsum = cast(double)releasebit.sum(base + s) / bugc;
			if(allowsum <= minallow){
				base += s;
				s = p-s;
			}
		}
		int nbc = bugcountbit.sum(base);
		//(base).writeln;
		res = max(res,nbc);
	}
	res.writeln;
}

Measured memory_bytes: 13972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

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

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile(" ");
      int[] arrayS = delim
        .splitAsStream(line)
        .parallel()
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 200128
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1LL<<50;
const ld PI=abs(acos(-1));
int n,m,a[2010],b[2010],c[2010];
bool li[2010]={};
vector<P> g[1010];
vector<ll> dist(2010);

bool bellman_ford(){
	REP(i,0,n) dist[i]=LINF;
	dist[0]=0;
	
	REP(i,0,n){
		REP(j,0,m){
			if(dist[a[j]]!=LINF and dist[b[j]]>dist[a[j]]+c[j]){
				dist[b[j]]=dist[a[j]]+c[j];
				if(i==n-1) li[b[j]]=true;
			}
		}
	}
	
	return false ;
}

int main(){
	cin >> n >> m;
	REP(i,0,m) cin >> a[i] >> b[i] >> c[i],a[i]--,b[i]--,c[i]=-c[i];
	
	bellman_ford();
	if(li[n-1]) cout << "inf" << endl;
	else cout << -dist[n-1] << endl;
	return 0;
}



Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N, M;
	std::vector<std::string> A, B;
	std::cin >> N >> M;
	A.resize(N);
	B.resize(M);
	for (auto& a : A)
		std::cin >> a;
	for (auto& b : B)
		std::cin >> b;

	for (int yoff = 0; yoff <= N - M; ++yoff) {
		for (int xoff = 0; xoff <= N - M; ++xoff) {
			for (int y = 0; y < M; ++y) {
				if (A[yoff + y].compare(xoff, M, B[y]) != 0)
					goto bailout;
			}
			std::cout << "Yes\n";
			return 0;
		bailout:
			;
		}
	}
	std::cout << "No\n";
}


Measured memory_bytes: 384
# sの末尾x文字とtの先頭x文字ぶんかぶってるかどうかチェック
n = int(input())
s, t = input(), input()
a = -1
for i in range(n):
    if s[-i - 1 :] == t[: i + 1]:
        a = i
print(len(s) + len(t[a + 1 :]))



Measured memory_bytes: 2940
N, T = map(int, input().split())

A, B = zip(*[tuple(map(int, input().split())) for _ in range(N)])
dp1 = [[0]*(T) for _ in range(N+1)]
dp2 = [[0]*(T) for _ in range(N+2)]

for i in range(N):
    for j in range(T):
        dp1[i+1][j] = max(dp1[i][j], dp1[i][j-A[i]]+B[i]) if j-A[i]>=0 else dp1[i][j]

for i in range(N, 0, -1):
    for j in range(T):
        dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-A[i-1]]+B[i-1]) if j-A[i-1]>=0 else dp2[i+1][j]

ans = -1
for i in range(1, N+1):
    for j in range(T):
        ans = max(ans, dp1[i-1][j]+dp2[i+1][T-j-1]+B[i-1])

print(ans)

Measured memory_bytes: 179588
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define ull unsigned long long
#define pi (acos(-1))
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
int main()
{
    int n;
cin >>n;
vec<int> v(n);
rep(i,n){cin>>v[i];}
int cur=0;
rep(i,n){
if(v[i]==cur+1){++cur;}
}
#ifdef local 
dbg(n,cur);
#endif
if(cur==0){cout<<-1<<endl;return 0;}
cout<<n-cur<<endl;
    return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


Measured memory_bytes: 3976
#include <iostream>

using namespace std;

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

    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		 Scanner scan = new Scanner(System.in);
		 int a = scan.nextInt();
		 int b = scan.nextInt();
		 int c = scan.nextInt();
		 int tmp,i;
			for (i = 0; i <= 2; ++i){
		     if(a > b){
				 tmp = a;
				 a = b;
				 b = tmp;
			 }
			 else if(b > c){
				 tmp = b;
				 b = c;
				 c = tmp;
			 }
		}
		 System.out.println(""+a+" "+b+" "+c);
	}
}

Measured memory_bytes: 26192
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

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

    int n, m;
    cin >> n >> m;
    int ans[m];
    fill(ans, ans+m, 1);

    REP(i, n) {
        int k;
        cin >> k;
        int like[m];
        fill(like, like+m, 0);
        REP(j, k) {
            int temp;
            cin >> temp;
            like[temp-1] = 1;
        }
        REP(j, m) {
            ans[j] = min(ans[j], like[j]);
        }
    }

    int cnt = 0;
    REP(i, m) cnt += ans[i];
    P(cnt);

    return 0;
}


Measured memory_bytes: 256
'use strict';
    (function(stdin) {
      //declare function

      //declare variable
      var inputs = stdin.toString().trim().split('\n');
      var pi = Math.PI;
      var r = inputs[0];
      //main

      //display
      console.log((r * r * pi).toFixed(6), (2 * r * pi).toFixed(6));
    })(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 15452
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

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

    int ans = 0;
    rep(i, n)
    {
        if ((i + 1) % 2 == 1 && a[i] % 2 == 1)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(void)
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int left=a+b;
    int right=c+d;
    if(left>right)printf("Left");
    else if(left<right)printf("Right");
    else printf("Balanced");
}


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

//最大公約数を求める関数
int64_t gcd(int64_t a, int64_t b){
    return b ? gcd(b, a % b) : a;
}

int main(){
    int x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int N, M;
	while(cin >> N >> M, N) {
		vi p(N);
		REP(i, N) {
			cin >> p[i];
		}
		p.push_back(0);

		vi pts;
		REP(i, N+1) {
			REP(j, N+1) {
				pts.push_back(p[i]+p[j]);
			}
		}
		sort(ALL(pts));

		int size = pts.size(), l = 0, r = size-1, ans = 0;
		while(l < size) {
			if(r < 0) {
				break;
			}
			if(pts[l]+pts[r] > M) {
				r--;
			} else {
				ans = max(ans, pts[l]+pts[r]);
				l++;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 9196
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;

lli n,a,b;
lli t[1009];
int main(){
  scanf("%lld%lld%lld",&n,&a,&b);
  lli res=n;
  rep(i,n){
    scanf("%lld",&t[i]);
    if(t[i]>=a && t[i]<b) res--;
  }
  printf("%lld\n",res);



  return 0;

}


Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) a[n-1-i] = sc.nextInt();
		System.out.print(a[0]);
		for(int i = 1; i < n; i++) System.out.print(" " + a[i]);
		System.out.println();
	}
}


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

int main()
{
    int N;
    cin >> N;
    for(int k=0;k<N;k++)
    {
        int gx,gy,p;
        int x1[300],y1[300],x2[300],y2[300];
        cin >> gx >> gy;
        int vert[16][16],horiz[16][16];
        cin >> p;
        for(int i=0;i<=gx;i++)
           for(int j=0;j<=gy;j++)
           {
               vert[i][j]=1;
               horiz[i][j]=1;
           }
        for(int i=0;i<p;i++)
        {
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
            if(x1[i]==x2[i])
              vert[x2[i]][max(y1[i],y2[i])]=0;
            else if(y1[i]==y2[i])
              horiz[max(x1[i],x2[i])][y2[i]]=0;
        }
        for(int i=0;i<=gx;i++)
            vert[i][0]=0;
        for(int j=0;j<=gy;j++)
            horiz[0][j]=0;
        int T[16][16];
        for(int i=0;i<=gx;i++)
           for(int j=0;j<=gy;j++)
              T[i][j]=0;
        for(int i=0;i<=gx;i++)
           for(int j=0;j<=gy;j++)
           {
               if(i==0&&j==0)
                 T[i][j]=1;
               else if(vert[i][j]==0&&horiz[i][j]==0)
                 T[i][j]=0;
               else if(vert[i][j]==0&&horiz[i][j])
                 T[i][j]=T[i-1][j];
               else if(horiz[i][j]==0&&vert[i][j])
                 T[i][j]=T[i][j-1];
               else if(vert[i][j]&&horiz[i][j])
                 T[i][j]=T[i-1][j]+T[i][j-1];
           }
        if(!T[gx][gy])
          cout << "Miserable Hokusai!" << endl;
        else
         cout << T[gx][gy] << endl;
    }
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
#define int long long
using namespace std;
int ydir[] = {-1, -2, +1, +2};
int maxPoints(int x, int y, int grid[][3], int dp[][3], int n)
{
    if (y < 0 || y >= 3)
        return INT_MIN;
    if (x == n - 1)
        return grid[x][y];
    if (dp[x][y] != -1)
        return dp[x][y];

    int points = grid[x][y];
    points = points;
    int obtained = INT_MIN;
    for (int i = 0; i < 4; i++)
    {
        obtained = max(obtained, maxPoints(x + 1, y + ydir[i], grid, dp, n));
    }
    points += obtained;
    dp[x][y] = points;
    return points;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    int grid[n][3];
    for (int i = 0; i < n; i++)
    {
        cin >> grid[i][0] >> grid[i][1] >> grid[i][2];
    }
    int points = INT_MIN;
    int dp[n][3];
    memset(dp, -1, sizeof(dp));
    points = maxPoints(0, 0, grid, dp, n);
    points = max(points, maxPoints(0, 1, grid, dp, n));
    points = max(points, maxPoints(0, 2, grid, dp, n));
    cout << points;
    return 0;
}

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

int main(){
    double n;
    cin >> n;
    int x = n;
    if(x%2 == 0){
        printf("%lf\n",(n/2)/n);
    }
    else if(x == 1){
        printf("%lf\n",n);
    }
    else{
       printf("%lf\n",((n + 1)/2)/n);
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

cnt = 0

for i in range(10):
    x100 = S.find(str(i))
    if x100 == -1:
        continue
    for j in range(10):
        x10 = S.find(str(j), x100 + 1)
        if x10 == -1:
            continue
        for k in range(10):
            if S.find(str(k), x10 + 1) != -1:
                cnt += 1
print(cnt)


Measured memory_bytes: 9200
// #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;
using ll = long long int;
using int64 = long long int;
 
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;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll N; cin >> N;
    ll ans = 0;
    vector<ll> V(N);
    for(int i=0; i<N; i++) {
        cin >> V[i];
        ans += V[i] - (i + 1);
    }
    cout << ans << endl;
    return 0;
}




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

int main(){
  int N;
  cin >>N;
  int w;
  vector<int> wsum(N);
  int sum=0;
  int m=999999;
  cin >>wsum.at(0);
  sum+=wsum.at(0);
  for(int i=1;i<N;i++){
int n;
cin >>n;
wsum.at(i)=wsum.at(i-1)+n;
sum+=n;
}
for(int i=0;i<N;i++){
int c=max(wsum.at(i),sum-wsum.at(i))-min(wsum.at(i),sum-wsum.at(i));
m=min(c,m);
  }
  cout <<m<<endl;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int a, b, c; cin >> a >> b >> c;

    if(a - b == b - c) cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 256
// use proconio::input;
use std::io;

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

fn main() {
    let vec = read_vec::<i32>();
    let a = vec[0];
    let b = vec[1];
    let c = vec[2];

    let mut sum = 0;
    for num in a..(b+1) {
        if c % num == 0 { sum += 1; }
    }
    println!("{}", sum);
}


Measured memory_bytes: 5028
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Online Judge: Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define EMPP emplace_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
//		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			//aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		//printf("%d ", n);
	//	aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int d, n;
	cin >> d >> n;
	int ans = 1;
	for (int i = 0; i < d; i++)
		ans *= 100;
	if (n == 100)ans *= (n + 1);
	else ans *= n;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

if s==t:
    print('No')
    exit()

s, t = [c for c in s], [c for c in t]
s = sorted(s)
t = sorted(t, reverse=True)

s = ''.join(s)
t = ''.join(t)

if [s, t]==sorted([s, t]):
    print('Yes')
else:
    print('No')

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int H, A;
    cin >> H >> A;
    cout << (H+A-1)/A << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N;
  cin >> N;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 0;
  bool flg = true;
  while(flg){
    flg = false;

    ll sum = 0;
    vector<ll> cnt(N, 0);
    rep(i,N){    
      cnt[i] = v[i]/N;
      v[i] -= N * cnt[i];
      sum += cnt[i];
    }
    rep(i,N){
      v[i] += sum - cnt[i];
      if(v[i] >= N) flg = true;
    }
    ret += sum;
  }

  cout << ret << endl;
  
  return 0;
}


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

int main(){
    int n;
    int button[114514];
    int map[114514]={0};
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> button[i+1];
    }
    int now = 1;
    int count = 0;
    while(1){
        now = button[now];
        count++;
        if(now == 2){
            cout << count << endl;
            return 0;
        }
        if(map[now] == 1){
            cout << -1 << endl;
            return 0;
        }else{
            map[now] = 1;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define range(i, a, b, s) for (int i = (a), __##i = (b); i < __##i; i += (s))
#define down(i, a, b, s) for (int i = (a), __##i = (b); __##i < i; i += (s))

const int maxn = 1e5 + 2;

char c[maxn];
int n, x[maxn], y[maxn], dx[maxn], dy[maxn];

long double solve(long double t) {
  long double lx = +1e8, ly = +1e8;
  long double rx = -1e8, ry = -1e8;
  range(i, 0, n, 1) {
    long double xx = x[i] + dx[i] * t;
    long double yy = y[i] + dy[i] * t;
    lx = min(lx, xx);
    ly = min(ly, yy);
    rx = max(rx, xx);
    ry = max(ry, yy);
  }
  return (rx - lx) * (ry - ly);
}

int main(int argc, char const *argv[]) {
  // freopen("F.txt", "r", stdin);

  while (cin >> n) {
    range(i, 0, n, 1) {
      cin >> x[i] >> y[i] >> c[i];
      if (c[i] == 'R') dx[i] = +1, dy[i] = 0;
      if (c[i] == 'L') dx[i] = -1, dy[i] = 0;
      if (c[i] == 'U') dx[i] = 0, dy[i] = +1;
      if (c[i] == 'D') dx[i] = 0, dy[i] = -1;
    }
    long double l = 0, r = 1e8;
    range(_, 0, 300, 1) {
      if (solve((l + l + r) / 3) < solve((l + r + r) / 3))
        r = (l + r + r) / 3;
      else
        l = (l + l + r) / 3;
    }
    cout << fixed << setprecision(10) << solve(l) << endl;
  }
  return 0;
}

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

int	main()
{
	int	n, a, b, c, d;
	cin >> n;
	
	a = n % 10;
	b = n / 10 % 10;
	c = n / 100 % 10;
	d = n / 1000 % 10;
	if (a == b && b == c)
		cout << "Yes" << endl;
	else if (b == c && c == d)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

signed main() {
    int n;
    cin >> n;
    vector<vector<int>> graph(n), par(n, vector<int>(30));
    vector<int> d(n);
    REP(i, n) {
        int k;
        cin >> k;
        REP(j, k) {
            int c;
            cin >> c;
            graph[i].push_back(c);
            graph[c].push_back(i);
        }
    }
    function<void(int, int, int)> dfs = [&](int c, int p, int depth) {
        d[c] = depth;
        par[c][0] = p;
        for (auto ch : graph[c]) {
            if (ch != p) dfs(ch, c, depth + 1);
        }
    };
    dfs(0, 0, 0);
    int q;
    cin >> q;
    // cout << "skeleton barrel";
    /*calc par*/
    for (int j = 1; j < 30; j++) {
        REP(i, n) { par[i][j] = par[par[i][j - 1]][j - 1]; }
    }
    REP(j, q) {
        int u, v;
        cin >> u >> v;
        if (d[u] > d[v]) {
            swap(u, v);
        }
        for (int i = 29; 0 <= i; i--) {
            if (d[u] <= d[par[v][i]]) {
                v = par[v][i];
            }
        }
        /* LCA */
        for (int i = 29; 0 <= i; i--) {
            if (par[v][i] != par[u][i]) {
                v = par[v][i];
                u = par[u][i];
            }
        }
        if (u == v) {
            cout << u << endl;
        } else {
            cout << par[v][0] << endl;
        }
    }
}


Measured memory_bytes: 31140
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

    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 find(self, x):          #親を出力
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def same(self, x, y):       #xとyが同じグループかどうか
        return self.find(x) == self.find(y)

    def size(self, x):          #グループの要素数
        return -self.parents[self.find(x)]

    def members(self, x):       #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())

################

from collections import Counter

def main():
    N, K, L = map(int, input().split())
    ufK = UnionFind(N)
    ufL = UnionFind(N)
    for i in range(K):
        a,b = map(int,input().split())
        ufK.union(a-1, b-1)
    for i in range(L):
        a,b = map(int,input().split())
        ufL.union(a-1, b-1)

    ps=[(ufK.find(i),ufL.find(i)) for i in range(N)]
    cps = Counter(ps)
    ret = [0]*N
    for i in range(N):
        ret[i] =cps[ps[i]]
    print(*ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 44396
l=list(map(int,input().split()))
K=int(input())
from itertools import product
for i in range(K+1):
    for j in product([0,1,2], repeat=i):
        c=l.copy()
        for k in j:
            c[k]*=2
        if c[1]>c[0] and c[2]>c[1]:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <climits>
using namespace std;

#define rep(i,end)          rep2(i,0,(end))
#define rep2(i,beg,end)   for (int i=(beg);i<(end);i++)
#define all(cont)           begin(cont), end(cont)
#define INFMAX                   LLONG_MAX
#define INFMIN                   LLONG_MIN
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef list<ll> li;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int l, r;
    cin >> l >> r;
    if (r - l >= 2019) {
        cout << 0 << endl;
        return 0;
    }
    ll mods[2019] = {};
    rep2(i, l, r + 1)
    {
        mods[i % 2019]++;
    }
    ll minv = INFMAX;
    rep2(i, 0, 2019)
    {
        if (mods[i] == 0) continue;
        mods[i]--;
        rep2(j, i, 2019)
        {
            if (mods[j] == 0) continue;
            minv = min((i*j) % 2019LL, minv);
        }
    }
    cout << minv << endl;
    return 0;
}

string gets(bool skipToNextline)
{
    if (skipToNextline) gets(false);
    const int BUFF_MAX = 1024;
    char buf[BUFF_MAX];
    cin.getline(buf, sizeof(buf));
    return buf;
}

vi get_n_array(int n)
{
    vi v;
    while (n-- > 0) {
        int x;
        cin >> x;
        v.push_back(x);
    }
    return v;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;

int main(){

  int r,c,*v,*orig_v,c_sum,r_sum,all_sum;

  scanf("%d %d\n",&r,&c);

  orig_v = v=(int *)malloc(r*c*sizeof(int));

  for(int i=0;i<r;i++){
    c_sum=0;
    for(int j=0;j<c;j++){
      scanf("%d ",v);
      printf("%d ",*v);
      c_sum+=*v;
      v++;
    }
    printf("%d\n",c_sum);
  }

  all_sum=0;
  for(int i=0;i<c;i++){
    r_sum=0;
    for(int k=0;k<r;k++){
      r_sum += orig_v[c*k+i];
    }
    printf("%d ",r_sum);
    all_sum+=r_sum;
  }
  printf("%d\n",all_sum);
}


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


int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    
    sort(a.begin(), a.end());
    
    int cnt=0;
    cnt += a[2]-a[1];
    int b = a[2]-a[1];
    a[1] += b;
    a[0] += b;
    
    if((a[2]-a[0])%2==0){
        cnt += (a[2]-a[0])/2;
    }
    else {
        cnt++;
        a[1]++;
        a[2]++;
        cnt += (a[2]-a[0])/2;
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m = 1000;
    let mut cnt = vec![0u64; 2 * m + 1];
    for _ in 0..n {
        let l: usize = it.next().unwrap().parse().unwrap();
        cnt[l] += 1;
    }
    for i in 1..(2 * m + 1) {
        cnt[i] += cnt[i - 1];
    }
    let mut ans = 0u64;
    for a in 1..(m + 1) {
        for b in a..(m + 1) {
            if a == b {
                let x = cnt[a] - cnt[a - 1];
                ans += x * (x - 1) * (x - 2) / 6;
                ans += x * (x - 1) / 2 * (cnt[a + b - 1] - cnt[a]);
            } else {
                let x = cnt[a] - cnt[a - 1];
                let y = cnt[b] - cnt[b - 1];
                ans += x * y * (y - 1) / 2;
                ans += x * y * (cnt[a + b - 1] - cnt[b]);
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352