akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll unsighned long int

int ans = 0;



void solve(int n,vector<vector<int> > v,vector<int> dist,int pos = 1,int k = 1){
    //cout << ans << endl;
    if(k == n){
        ans++;
        return ;
    }
    for(int i = 0; i < v[pos - 1].size(); ++i){
        if(dist[v[pos - 1][i] - 1] != 1){
            dist[v[pos - 1][i] - 1] = 1;
            solve(n,v,dist,v[pos - 1][i],k + 1);
            dist[v[pos - 1][i] - 1] = -1;
        }
    }
}


int main(){
    int n,m;
    cin >> n >> m;
    //cout << n << " " << m << endl;

    vector<vector<int> > v(n);

    vector<int> dist(n,-1);


    dist[0] = 1;

    for(int i = 0; i < m; ++i){
        int a,b;
        cin >> a >> b;
        v[a - 1].push_back(b);
        v[b - 1].push_back(a);
    }
    solve(n,v,dist);
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve(s):
	if len(s) == 0:
		return 0, 1
	l = len(s)
	ans = 0
	cnt = 0
	for i in range(1, l+1):
		left = s[:i]
		right = s[i:]
		a, b = solve(right)
		ans += int(left) * b + a
		cnt += b
	return ans, cnt

s = input().strip()
ans, _ = solve(s)
print(ans)


Measured memory_bytes: 3188
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		boolean[] arr = new boolean[n];
		int[] count = new int[n];
		for(int i = 0; i < n; i++) {
			int p = scan.nextInt()-1;
			arr[p] = true;
			if(p>0 && arr[p-1]) count[p] = count[p-1]+1;
		}
		//System.out.println(Arrays.toString(count));
		int max = 0;
		for(int num : count) max = Math.max(max,num);
		System.out.println(n-max-1);
	}
}


Measured memory_bytes: 84040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		String[] data = input.split(" ");
		int a = Integer.parseInt(data[0]);
		int b = Integer.parseInt(data[1]);

		if (a >= -1000 && b <= 1000) {
			if (a > b) {
				System.out.println("a > b");
			} else if (a < b) {
				System.out.println("a < b");
			} else {
				System.out.println("a == b");
			}
		}

	}

}



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

int main(){
  int n;
  cin>>n;
  vector<int>h(n);
  int ans=0,active=0;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  for(int i=0;i<n;i++){
    if(active>=h[i]){
      active=h[i];
    }
    else{
      ans+=h[i]-active;
      active=h[i];
    }
  }
  cout<<ans<<endl;
}

  


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

int main() {
    int A,B,H,M;
    cin>>A>>B>>H>>M;
    double A2=A*A;
    double B2=B*B;
    const double PI = acos(-1);
    double angle=(60*H-11*M)*PI/360;

    double c=sqrt(A2+B2-2*double(A)*double(B)*cos(angle));
    cout << std::fixed << std::setprecision(20) << c << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a % 2 == 1) && (b % 2 == 1)) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[ input() for _ in range(h)]
#print(s)
for i in range(h):
    for j in range(w):
        def valid(a,b):
            if a>=0 and a<h and b>=0 and b<w:
                return True
            return False
        if s[i][j]=='#':
            flag=False
            if valid(i+1,j):
                if s[i+1][j]=='#':
                    flag=True
            if valid(i-1,j):
                if s[i-1][j]=='#':
                    flag=True
            if valid(i,j-1):
                if s[i][j-1]=='#':
                    flag=True
            if valid(i,j+1):
                if s[i][j+1]=='#':
                    flag=True
            if not flag:
                print('No')
                import sys
                sys.exit()
print('Yes')


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    a = list(map(int,input().split()))
    num = 0
    for i in a:
        if i%2 == 1:
            num += 1
    print("YES") if num%2 == 0 else print("NO")

if __name__ == "__main__":
    main()

Measured memory_bytes: 14048
/*
Writer: SPD_9X2
https://atcoder.jp/contests/abc149/tasks/abc149_f

全方位木dpか？
→保持する値は、小部分木の頂点の数

頂点数a,b,c,dの4つの部分木が付いてる時の確率は

1/2 * (1-黒を持つ成分が1つ以下の確率)

黒を持つ成分が1つ以下の確率 = all白の確率+aのみall白+bのみall白+c+d
all白の確率 = aが白*b*c*d = 1/2**(n-1)
aのみ黒 = (1-a)*b*c*d

aが白の確率 = (1/2) ** a

all白の確率は, 累計O(N)で構築可能
aのみ白・・etc は、あらかじめ(1-a)*(1-b)…を計算しておき、差分計算する
そうすれば全体O(N)で構築可能
結果としてO(N)で解ける。

全方位木dpでは、結局接続する小部分木の頂点の数の集合が分ければ解ける
→親部分木の大きさは分かるので全方位感がないね？

pyだとTLE…
*/

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

#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 1000000007;
const ll half = 500000004;

ll dfs(ll v,ll p,ll& ans,vector<vector<ll>>& lis,vector<ll>& hxx,ll N){

    vector<ll> vns(0);
    ll ret = 1;

    rep(i,0,lis[v].size()){

        ll nex = lis[v][i];

        if (nex != p){
            ll cvn = dfs(nex,v,ans,lis,hxx,N);
            ret += cvn;
            vns.push_back(cvn);
        }
    }

    if ((N-ret) != 0) vns.push_back(N-ret);

    ll Bzo = hxx[N-1];

    rep(j,0,vns.size()){
        ll i = vns[j];
        Bzo += hxx[N-1-i] * (1-hxx[i]);
      	Bzo %= mod;
    }

    ans += half * (1-Bzo);
    //cout << v << " " << half * (1-Bzo) << endl;
    ans %= mod;

    return ret;
}

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

    vector<vector<ll>> lis(N,vector<ll>(0,0));

    rep(i,0,N-1){

        ll A,B;
        cin >> A >> B;
        A -= 1;
        B -= 1;

        lis[A].push_back(B);
        lis[B].push_back(A);

    }

    vector<ll> hxx(1,1);
    rep(i,0,N+10){
        hxx.push_back((hxx[hxx.size()-1] * half) % mod);
    }

    ll ans = 0;

    dfs(0,0,ans,lis,hxx,N);
    while (ans < 0){
      ans += mod;
    }
    cout << ans << endl;
}



Measured memory_bytes: 33264
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        int[] a = new int[str.length()];
        char[] ans = {'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'};
        
        for(int i=0; i<str.length(); i++){
            a[i] = c[i]-65;
            //System.out.print(a[i]+">");
            a[i] += N;
            a[i] %= 26;
            //System.out.println(a[i]);
        }
        for(int i=0; i<str.length(); i++){
            System.out.print(ans[a[i]]);
        }
        System.out.println("");
    }
}

Measured memory_bytes: 39056
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef pair<int,int>P;
const int INF=1<<20;
int main(){
  int h,w;
  char maps[100][100];
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>maps[i][j];
    }
  }
  
  int maxim=0;
  int dx[4]={0,1,0,-1};
  int dy[4]={-1,0,1,0};
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(maps[i][j]=='#')continue;
      int sx=j,sy=i;
      int dist[100][100];
      for(int k=0;k<h;k++){
	for(int l=0;l<w;l++){
	  dist[k][l]=INF;
	}
      }
      
      queue<P>que;
      que.push(P(sx,sy));
      dist[sy][sx]=0;
      while(!que.empty()){
	P now=que.front();que.pop();
	int x=now.first;
	int y=now.second;
	for(int k=0;k<4;k++){
	  int nx=x+dx[k];
	  int ny=y+dy[k];
	  if(0<=nx&&nx<w&&0<=ny&&ny<h&&maps[ny][nx]!='#'&&dist[ny][nx]>dist[y][x]+1){
	    dist[ny][nx]=dist[y][x]+1;
	    que.push(P(nx,ny));
	  }
	}
      }
      
      for(int k=0;k<h;k++){
	for(int l=0;l<w;l++){
	  if(maps[k][l]!='#'&&dist[k][l]!=INF){
	    maxim=max(dist[k][l],maxim);
	  }
	}
      }
    }
  }
  cout<<maxim<<endl;
  return(0);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    while N:
        lines = []
        for _ in range(N+1):
            tmp = []
            M = int(input())
            x0, y0 = map(int, input().split())
            x1, y1 = map(int, input().split())
            x2, y2 = map(int, input().split())
    
            L1 = abs(x0 + y0 - x1 - y1)
            L2 = abs(x1 + y1 - x2 - y2)
    
            v1 = [(x1-x0)//L1, (y1-y0)//L1]
            v2 = [(x2-x1)//L2, (y2-y1)//L2]
    
            tmp.append(str(L1))
            if [-v1[1], v1[0]] == v2:
                tmp.append("L")
            else:
                tmp.append("R")
            tmp.append(str(L2))
    
            for _ in range(M-3):
                x0, y0 = x1, y1
                x1, y1 = x2, y2
                x2, y2 = map(int, input().split())
    
                L1 = L2
                L2 = abs(x1 + y1 - x2 - y2)
    
                v1 = v2
                v2 = [(x2-x1)//L2, (y2-y1)//L2]
    
                if [-v1[1], v1[0]] == v2:
                    tmp.append("L")
                else:
                    tmp.append("R")
                tmp.append(str(L2))
            lines.append(tmp)
    
        base1 = "".join(lines[0])
    
        base2 = ""
        for l in lines[0][::-1]:
            if l == "L":
                base2 += "R"
            elif l == "R":
                base2 += "L"
            else:
                base2 += l
    
        for i, line in enumerate(lines[1:], start=1):
            l = "".join(line)
            if l == base1 or l == base2:
                print(i)
        print("+++++")
        N = int(input())

if __name__ == "__main__":
    main()


Measured memory_bytes: 5632
n = int(input())
s = input()

ans = 0
for a in range(10):
    ai = 0
    while ai < n:
        if s[ai] == str(a):
            break
        else:
            ai += 1
    if ai == n:
        continue
    for b in range(10):
        bi = ai + 1
        while bi < n:
            if s[bi] == str(b):
                break
            else:
                bi += 1
        if bi == n:
            continue
        for c in range(10):
            ci = bi + 1
            while ci < n:
                if s[ci] == str(c):
                    break
                else:
                    ci += 1
            if ci == n:
                continue
            else:
                ans += 1

print(ans)
exit(0)


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

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)

typedef long long ll;
typedef long long int lli;

int main() {
    int D;   
    cin >> D;
    if (D == 25) {
        cout << "Christmas" << endl;
    } else if (D == 24) {
        cout << "Christmas Eve" << endl;
    } else if (D == 23) {
        cout << "Christmas Eve Eve" << endl;
    } else {
        cout << "Christmas Eve Eve Eve" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a,b,c,x,y,z,i,t,n;
  long k;
  scanf("%d %d %d %ld",&a,&b,&c,&k);
  
  y=1;
  
  if(k%2==1)
  {
    for(i=0;i<(k-1)/2;i++)
      y=y*4-1;
    x=y-1;
    z=y;
  }
  
  else if(k%2==0)
  {
    for(i=0;i<(k-2)/2;i++)
      y=y*4+1;
    x=y+1;
    z=y;
  }
  
  t=x*a+y*b+z*c;
  n=z*a+x*b+y*c;
  
  if(t-n<-1000000000000000000)
    printf("Unfair");
  
  else if(t-n>1000000000000000000)
    printf("Unfair");
  
  else 
    printf("%d",t-n);
}

Measured memory_bytes: 128
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[2][55];
vector <int> Vin;

int u[55];
ll dp[55];
int main() {
	int N, i, j;
	scanf("%d %s %s", &N, in[0], in[1]);

	for (i = 0; i < N;) {
		if (i + 1 == N || in[0][i] == in[1][i]) {
			Vin.push_back(1);
			i++;
		}
		else {
			Vin.push_back(2);
			i += 2;
		}
	}

	dp[0] = 6;
	if (Vin[0] == 1) dp[0] = 3;
	for (i = 1; i < Vin.size(); i++) {
		if (Vin[i] == 1 && Vin[i-1] == 1) dp[i] = dp[i - 1] * 2 % MOD;
		if (Vin[i] == 1 && Vin[i - 1] == 2) dp[i] = dp[i - 1];
		if (Vin[i] == 2 && Vin[i - 1] == 1) dp[i] = dp[i - 1] * 2 % MOD;
		if (Vin[i] == 2 && Vin[i - 1] == 2) dp[i] = dp[i - 1] * 3 % MOD;
	}
	return !printf("%lld\n", dp[Vin.size() - 1]);
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   ll n,N,kt=0;
   cin>>n; N=n;
   while(n!=0)
   {
      kt+=(n%10);
      n/=10;
   }
 (N%kt==0)? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

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

#define INF 1000000007
#define ll long long
#define F first
#define S second
#define pii pair<ll int,ll int>
#define pb push_back
#define ppb pop_back
#define vi vector<ll int>


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--){
		string str;
		cin >> str;
		if(str[0] == str[1] && str[0] == str[2]) cout << "No";
		else cout << "Yes";
	}
	return 0;
}


Measured memory_bytes: 256
S = input()
ans = "WA"
if S[0] == "A":
    tmp = S[2:len(S)-1]
    if tmp.count("C") == 1:
        c = tmp.index("C")
        count = 0
        for i in range(1,len(S)):
            tmp2 = S[i]
            if tmp2.islower():
                count += 1
        if count == len(S) - 2:
            ans = "AC"
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
//repマクロ定義
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
//allマクロ定義
#define all(v) v.begin(),v.end()
using namespace std;

#define M 2000000000

int N,cont;

void remainder(vector<int>& vec){
  for(int i=1;vec.at(i)!=M;i++){
    vec.at(i)%=vec.at(0);
    if(vec.at(i)==0){
      vec.at(i)=M;
      cont--;
    }
  }
}

int main(){
  cin >> N;
  cont = N;
  vector<int> a(N+1);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  a.at(N)=M;



  while(cont!=1){
    sort(a.begin(),a.end());
    remainder(a);
  }

  cout << a.at(0);


}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	int N;
	string s, t;
	cin >> N >> s >> t;

	for (int i = 0; i < N; i++) {
		bool ok = true;
		for (int j = 0; j < N - i; j++) {
			if (s[i + j] != t[j]) {
				ok = false;
				break;
			}
		}

		if (ok) {
			//cout << s.substr(0, i) << t << endl;
			cout << i + N << endl;
			return 0;
		}
	}

	//cout << s << t << endl;
	cout << 2 * N << endl;

	return 0;
}

Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, A, B = getlist()
	if (B - A) % 2 == 0:
		ans = int((B - A) // 2)
		print(ans)
	else:
		ans = min(int((2 * N + 1 - A - B) // 2), int((A + B - 1) // 2))
		print(ans)
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;

const int MAXN = 3010;
int dp[MAXN][MAXN];
char path[MAXN][MAXN];
void update(int i, int j, int val, char op) {
	if (dp[i][j] > val) {
		dp[i][j] = val;
		path[i][j] = op;
	}
}
string s, t;
int main() {
	cin>>s>>t;
	s = "$" + s;
	t = "$" + t;
	memset(dp, 127, sizeof(dp));
	dp[0][0] = 0;
	for (int i=0; i<s.size(); i++)
		for (int j=0; j<t.size(); j++) {
			if (s[i] == t[j] && i && j)
				update(i, j, dp[i-1][j-1], 'a');

			//delete s[i];
			if (i)
				update(i, j, dp[i-1][j] +1, 's');
			
			//delete t[i];
			if (j)
				update(i, j, dp[i][j-1] +1, 't');
		}

	string ans;
	for (int i=s.size()-1, j=t.size()-1; i&&j; ) {
		if (path[i][j] == 'a')
			ans += s[i], i--, j--;
		if (path[i][j] == 's')
			i--;
		if (path[i][j] == 't')
			j--;
	}
	reverse(ans.begin(), ans.end());
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 44544
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int in[100005];
int out[100005];
int dp[100005];
int par[100005];
using graph = VVI;

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	graph g(n);
	REP(i, n+m-1) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--, y--;
		g[x].PB(y);
		out[x]++;
		in[y]++;
	}
	stack<int> st;
	VI nodes;
	REP(i, n) {
		if (!in[i]) {
			st.push(i);
		}
	}
	while (!st.empty()) {
		auto i = st.top();
		nodes.PB(i);
		st.pop();
		for (auto j : g[i]) {
			in[j]--;
			if (!in[j])st.push(j);
		}
	}
	int ret = 0;
	par[nodes[0]] = -1;
	for (auto i : nodes) {
		for (auto j : g[i]) {
			if (dp[j] < dp[i] + 1) {
				par[j] = i;
				dp[j] = dp[i] + 1;
			}
		}
	}
	REP(i,n)printf("%d\n", par[i]+1);
	return 0;
}

Measured memory_bytes: 8312
#include <iostream>
#include <string>
#include <array>

#define ALPHA 26

#define INPUT_LEN 12
#define INPUT_SIZE 2
#define DATA_SIZE (1 << (INPUT_LEN * INPUT_SIZE))

bool cache[INPUT_LEN][DATA_SIZE];

int encode(const std::string& dna, const std::array<int, ALPHA>& dna_map){
	const int length = dna.length();
	
	int code = 0;
	for(int i = length - 1; i >= 0; i--){
		code <<= INPUT_SIZE;
		code |= dna_map[dna[i] - 'A'];
	}
	
	return code;
}

int main(int argc, char* argv[]){
	std::array<int, ALPHA> dna_map;
	dna_map.fill(-1);
	dna_map['A' - 'A'] = 0;
	dna_map['C' - 'A'] = 1;
	dna_map['G' - 'A'] = 2;
	dna_map['T' - 'A'] = 3;

	int n;
	std::cin >> n;

	for(int i = 0; i < n; i++){
		std::string ops, dna;
		std::cin >> ops >> dna;

		const int code = encode(dna, dna_map);
		const int length = dna.length() - 1;

		if(ops == "insert"){ cache[length][code] = true; }
		else{ std::cout << (cache[length][code] ? "yes" : "no") << std::endl; }
	}
	
	return 0;
}

Measured memory_bytes: 11444
#include <iostream>
#include <algorithm>

using namespace std;

const int w[] = {2, 3, 5, 10, 12, 15};
const int v[] = {380, 550, 850, 1520, 1870, 2244};
const int num = 6;
int dp[55];

int main()
{
    int m;

    for (int i = 0; i <= 50; i++) 
        dp[i] = 50000;

    dp[0] = 0;
    for (int i = 0; i < num; i++)
        for (int j = 0; j + w[i] <= 50; j++)
            dp[j + w[i]] = min(dp[j + w[i]], dp[j] + v[i]);

    while (cin >> m, m) {
        m = m / 100;
        cout << dp[m] << endl;;
    }

    return 0;
}

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

int main()
{
	int n; cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 2 != 0) {
			int cnt = 0;
			for (int j = 1; j <= i; j++) {
				if (i % j == 0) cnt++;
			}
			if (cnt == 8) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
using namespace std;
int a[102];
int b[102];
int main()
{
	long long n;
	int p1 = 0, p2 = 0, m = 100;
	scanf("%lld", &n);
	n++;
	while (n > 1)
	{
		if (n & 1)
		{
			a[++p1] = m--;
			n--;
		}
		else
		{
			b[++p2] = m--;
			n >>= 1;
		}
	}
	printf("%d\n", p1 + p2 << 1);
	for (int i = 1; i <= p1; i++)
		printf("%d ", a[i]);
	for (int i = p2; i >= 1; i--)
		printf("%d ", b[i]);
	for (int i = 101 - p1 - p2; i <= 100; ++i)
		printf("%d ", i);
	return 0;
}


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

bool cmp(int a,int b){
    return a>b;
}

int n,a[200010];
priority_queue<int> q;
int ans;

signed main(){
    cin>>n;
    
    for(int i=1;i<=n;i++)
        cin>>a[i];
        
    sort(a+1,a+n+1,cmp);
    
    q.push(a[1]);
    
    for(int i=2;i<=n;i++){
        ans+=q.top();
        q.pop();
        q.push(a[i]);
        q.push(a[i]);
    }
    
    cout<<ans<<"\n";
    
    return 0;
}

Measured memory_bytes: 6888
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[10],m,n;
  while(cin>>n&&n){
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++){
      cin>>m;
      a[m]++;
    }
    for(i=0;i<10;i++){
      if(a[i]){
	for(j=0;j<a[i];j++)
	  cout<<"*";
	cout<<endl;
      }else
	cout<<"-"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
"""
~~ Author : Bhaskar
~~ Dated : 10~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")
input = lambda : sys.stdin.readline()

def solve():
    s = sys.stdin.readline().replace("\n","")
    if s.isupper():
        print("A")
    else:
        print("a")


if __name__ == "__main__":
    try:
        sys.stdin = open('input.txt','r')
        sys.stdout = open('output.txt','w')
    except:
       pass
    solve()



Measured memory_bytes: 9412
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N, K;
  cin >> N >> K;

  string S;
  cin >> S;

  ll score = 0;

  rep(i, N - 1) {
    if (S[i] == S[i + 1]) {
      score++;
    }
  }
  ll ans = min(score + 2 * K, N - 1);
  COUT(ans);

  return 0;
}

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

int main()
{
	long N,K;

	cin >> N >> K;

	vector<long> HP;

	for (int a = 0; a < N; a++) {
		long H;
		cin >> H;
		HP.push_back(H);
	}
	sort(HP.begin(),HP.end());

	long long result = 0;
	for (int a = 0; a < N; a++) {
		if (a >= K)result += HP[N-a-1];
	}



	cout << result<<endl;
}



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

using namespace std;
#define ll long long
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;

int main (){
    int n;
    cin >> n;
    vector<ll> vec(n);
    REP(i,n){
        cin >> vec.at(i);
    }
    ll count = 0;
    sort(vec.begin(), vec.end());
    for(int i = 0;i < n;){
        ll wo = vec.at(i);
        int ff = 0;
        while(i < n && vec.at(i) == wo){
            ff++;
            i++;
        }
        count += ff % 2;
    }
    
    cout << count << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_             \
  template <typename T> \
  inline
#define TTF_                        \
  template <typename T, typename F> \
  inline
TT_ T sq(T x) { return x * x; }
TT_ T In() {
  T x;
  cin >> x;
  return x;
}
TT_ void Out(T& x) { cout << x; }
TT_ void sort(T& v) { sort(begin(v), end(v)); }
TT_ void revs(T& v) { reverse(begin(v), end(v)); }
TT_ void uniq(T& v) {
  sort(v);
  v.erase(unique(begin(v), end(v)), end(v));
}
TT_ int ubnd(T& v, typename T::value_type& x) {
  return upper_bound(begin(v), end(v), x) - begin(v);
}
TT_ int lbnd(T& v, typename T::value_type& x) {
  return lower_bound(begin(v), end(v), x) - begin(v);
}
TTF_ void inpt(T& v, int n, F f) {
  for (v.reserve(n); n--; v.emplace_back(f()))
    ;
}
TTF_ void show(T& v, F f, string d = " ", string e = "\n") {
  int i = 0;
  for (auto& x : v) i++&&(cout << d), f(x);
  cout << e;
}
TT_ typename T::iterator minel(T& v) { return min_element(begin(v), end(v)); }
TT_ typename T::iterator maxel(T& v) { return max_element(begin(v), end(v)); }

inline void fast_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
inline ll pow_mod(ll a, ll k, ll m) {
  ll r = 1;
  for (; k > 0; a = a * a % m, k >>= 1)
    if (k & 1) r = r * a % m;
  return r;
}
inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); }
//}}} priority_queue queue deque front stringstream max_element min_element
//insert count make_tuple

bool valid(const vector<duo>& a, const vector<duo>& b) {
  int it = 0;
  for (const auto& ai : a) {
    while (it < b.size() && b[it] != ai) it++;
    if (it == b.size()) return false;
    it++;
  }
  return true;
}

int main() {
  int m;
  while (m = in()) {
    vector<duo> ms;
    inpt(ms, m, []() {
      int a, b;
      cin >> a >> b;
      return duo(a, b);
    });
    int n = in();
    vector<duo> ns;
    inpt(ns, n, []() {
      int a, b;
      cin >> a >> b;
      return duo(a, b);
    });
    vector<duo> dm;
    for (int i = 1; i < m; i++)
      dm.emplace_back(get<0>(ms[0]) - get<0>(ms[i]),
                      get<1>(ms[0]) - get<1>(ms[i]));
    sort(dm);
    for (int i = 0; i < n; i++) {
      vector<duo> dn;
      for (int j = 0; j < n; j++) {
        if (i == j) continue;
        dn.emplace_back(get<0>(ns[i]) - get<0>(ns[j]),
                        get<1>(ns[i]) - get<1>(ns[j]));
      }
      sort(dn);
      if (valid(dm, dn)) {
        cout << get<0>(ns[i]) - get<0>(ms[0]) << " "
             << get<1>(ns[i]) - get<1>(ms[0]) << endl;
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 5e5 + 5, M = 1e9 + 7;

ll qpow(ll x, ll n) {
  ll res = 1;
  for (; n; n >>= 1, x = x * x % M) if (n & 1) res = res * x % M;
  return res;
}

ll fac[N];
ll comb(ll n, ll m) {
  if (n < m) return 0;
  return fac[n] * qpow(fac[m] * fac[n - m] % M, M - 2) % M;
}

int main() {
  ll h, w, a, b;
  cin >> h >> w >> a >> b;
  fac[0] = 1;
  for (int i = 1; i <= 2 * max(h, w); i++) {
    fac[i] = fac[i-1] * i % M;
  }
  ll ans = 0;
  for (int i = b; i < w; i++) {
    ans = (ans + comb(h - a - 1 + i, i) * comb(a + w - i - 2, a - 1) % M) % M;
  }
  cout << ans;
}


Measured memory_bytes: 5136
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define pai 3.1415926535


int main(void) {
	int A, B, C;
	scanf("%d%d%d", &A, &B, &C);
	if (A == B && B == C) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;


}

Measured memory_bytes: 128
from collections import deque
def main():
    N = int(input())
    # 辺の集合を隣接リストとして入力
    E = [[] for i in range(N+1)]
    edge_order = []
    for i in range(N-1):
        a,b = map(int, input().split())
        E[a].append(b)
        edge_order.append(b)
    
    # 頂点1から幅優先探索
    queue = deque([1])
    color = [0] * (N+1) 
    while queue:
        V = queue.popleft()
        c = 1
        for i in E[V]:
            if c == color[V]:
                c += 1
            color[i] = c
            c += 1
            queue.append(i)

    print(max(color))
    for i in edge_order:
        print(color[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 18608
#include<cstdio>
#include<algorithm>
using namespace std;

int f[100100][3];

inline int readint(){
	int x;
	scanf("%d",&x);
	return x;
}

int main(){
	int N;
	scanf("%d\n",&N);
	
	for(int i=1;i<=N;i++)
		for(int j=0;j<=2;j++){
			for(int k=0;k<=2;k++)
				if(j-k) f[i][j]=max(f[i][j],f[i-1][k]);
			f[i][j]+=readint();
		}
	return printf("%d\n",max(max(f[N][0],f[N][1]),f[N][2]))&0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,a,b,c;long t;
int s[50];
int E[50][50];
int A[50][50];
main()
{
	while(cin>>n>>m>>a>>b>>c>>t,n)
	{
		for(int i=0;i<n;i++)
		{
			cin>>s[i];
			for(int j=0;j<n;j++)E[i][j]=A[i][j]=0;
			E[i][i]=1;
			A[i][i]=b;
			if(i>0)A[i][i-1]=a;
			if(i<n-1)A[i][i+1]=c;
		}
		for(long i=1;i<=t;i<<=1)
		{
			if(t&i)
			{
				int F[50][50]={};
				for(int j=0;j<n;j++)for(int k=0;k<n;k++)
				{
					for(int l=0;l<n;l++)F[j][k]+=E[j][l]*A[l][k];
				}
				for(int j=0;j<n;j++)for(int k=0;k<n;k++)E[j][k]=F[j][k]%m;
			}
			int F[50][50]={};
			for(int j=0;j<n;j++)for(int k=0;k<n;k++)
			{
				for(int l=0;l<n;l++)F[j][k]+=A[j][l]*A[l][k];
			}
			for(int j=0;j<n;j++)for(int k=0;k<n;k++)A[j][k]=F[j][k]%m;
		}
		for(int i=0;i<n;i++)
		{
			int ans=0;
			for(int j=0;j<n;j++)ans=(ans+s[j]*E[i][j])%m;
			cout<<ans<<(i==n-1?"\n":" ");
		}
	}
}



Measured memory_bytes: 3128
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define RSORT(A) std::sort((A).rbegin(), (A).rend())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){if(a < b) a = b;}
template <class T> inline void chmin(T &a, T b){if(a > b) a = b;}
template <class T> inline void reverseSORT(Vec<T> &Array){
  std::sort(Array.begin(), Array.end(), std::greater<T>());
}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1LL << k;}
inline void putsDouble(double d){printf("%.16lf\n", d);}
inline int toInt(const string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res;
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



using data_ = pair<string, pii>;


int main(void){
    int n; cin >> n;
    Vec<data_> A(n);
    REP(i, n){
        string s; int a; cin >> s >> a;
        A[i] = make_pair(s, make_pair(-a, i + 1));
    }
    SORT(A);
    REP(i, n){
        cout << A[i].second.second << BR;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;
int main(){
    int n, i;
    double m, u, c, r, t, sum;
    cin >> n;
    sum = 0;
    c = 0;
    
    int xl[101] = {};
    int yl[101] = {};
    
    for(i = 0; i < n; i++){
        cin >> xl[i];
    } 
    
    for(i = 0; i < n; i++){
        cin >> yl[i];
    }
    
    for(i = 0; i < n; i++){
        r = fabs(xl[i] - yl[i]);
        sum = sum + r;
    }
    
    m = sum;
    sum = 0;
    
    for(i = 0; i < n; i++){
        r = pow(xl[i] - yl[i], 2);
        sum = sum + r;
    }
    
    u = sqrt(sum);
    sum = 0;
    
    for(i = 0; i < n; i++){
        r = fabs(pow(xl[i] - yl[i], 3));
        sum = sum + r;
    }
    
    t = cbrt(sum);
    
    for(i = 0; i < n; i++){
        r = fabs(xl[i] - yl[i]);
        if(c < r) c = r;
    }
    
    cout << fixed;
    cout << setprecision(7) << m << endl;
    cout << setprecision(7) << u << endl;
    cout << setprecision(7) << t << endl;
    cout << setprecision(7) << c << endl;

}


Measured memory_bytes: 3500
/**
 * @brief 素集合森構造体
 * @date  2016/04/16
 */



//****************************************
// 必要なヘッダファイルのインクルード
//****************************************

#include <iostream>
#include <vector>
#include <cstdint>



//****************************************
// 構造体の定義
//****************************************

/**< @brief 素集合森 */
struct disjointset {
    using index_t = std::int32_t;
    using rank_t  = std::int32_t;
    
    std::vector<index_t> p;
    std::vector<rank_t> rank;

    explicit disjointset(std::size_t size) : p(size, -1), rank(size, -1) {}
    
    /**
     * @brief xを唯一の要素(従って、代表元)としてもつ新しい集合を生成する.
     * @note  集合は互いに素であるから、xがすでに別の集合に出現していることはない. 
     *
     * @param int x 節点x
     */
    void makeset(index_t x) {
        p[x]    = x;
        rank[x] = 0;
    }

    /**
     * @brief     xを含む動的集合Sxとyを含む動的集合Syを合併(統合)し、
     *            これらの和集合である新しい集合を生成する.
     * @attention SxとSyはこの操作を実行する前は互いに素であると仮定する.
     *
     * @param int x   動的集合Sxの元x
     * @param int y   動的集合Syの元y
     */
    void merge(index_t x, index_t y) {
        link(findset(x), findset(y));
    }


    /**
     * @brief 手続きmergeの補助関数
     *
     * @param int x 動的集合Sxの代表元x(Sxの根)
     * @param int y 動的集合Syの代表元y(Syの根)
     */
    void link(index_t x, index_t y) {
        // xのランク > yのランクかどうか判定
        if (rank[x] > rank[y]) {  // x.rank > y.rankならば、
            p[y] = x;             // yの親はxを指す
        }
        else {                    // x.rank <= y.rankならば、 
            p[x] = y;             // xの親はyを指す
            
            if (rank[x] == rank[y]) {   // x.rank == y.rankならば、
                rank[y] = rank[y] + 1;  // y.rankをひとつ増やす
            }
        }
    }

    /**
     * @brief  xを含む(唯一の)集合の代表元へのポインタを返す.
     *         手続きfindsetは2パス法に基づく.再帰が進行するのに従って、
     *         find経路を根に向かって上向きに走査して根を発見し、つぎに、
     *         再帰が巻き戻されるにつれて、辿ってきたfind経路を下る2度目の走査を行って、
     *         find経路上の各節点のポインタを直接根を指すように更新する.
     *
     * @param  int x   集合Sxの元x
     * @return int y   集合Sxの代表元(根)
     */
    index_t findset(index_t x) {
        // find経路を根に向かって上向きに走査
        if (x != p[x]) {
            p[x] = findset(p[x]);  // 再帰を進行させる
        }
        return p[x];  // 再帰が底をついてから、根を返す
    }
};



//****************************************
// 関数の定義
//****************************************

int main()
{
    using namespace std;
    
    int a, b, q, n, t;

    cin >> n >> q;

    disjointset ds(n);
    for (int i = 0; i < n; i++) { ds.makeset(i); }

    for (int i = 0; i < q; i++) {
        cin >> t >> a >> b;

        if (t == 0) { ds.merge(a, b); }
        else if (t == 1) {
            if (ds.findset(a) == ds.findset(b)) cout << 1 << endl;
            else                                cout << 0 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast 
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535

int main(){
  int n;
  cin >> n;
  long long sum=0;
  for(int i=1;i<=n;i++){
      if(i%3!=0 && i%5!=0)
          sum += i;
  }
  
  cout << sum <<endl;
  return 0;
  
}






Measured memory_bytes: 3624
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#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++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;

int main(void) {

	string s;
	cin >> s;
	
	string str;
	REP(i, s.length()) {
		if (str.length() == 0 && s[i] == 'B') continue;

		if (s[i] == 'B') str.pop_back();
		else if(s[i] == '1') str.push_back('1');
		else if (s[i] == '0') str.push_back('0');
	}
	cout << str << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N = int(readline())
A = sorted(list(map(int,readline().split())))
B = list(map(int,readline().split()))
C = sorted(list(map(int,readline().split())))

ans = 0
import bisect
for i in range(len(B)):
  ind_a = bisect.bisect_left(A, B[i])
  ind_c = bisect.bisect_right(C, B[i])
  ans += ind_a * (len(C) - ind_c)
  
print(ans)

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

using namespace std;

int main(void){
	string s;
	cin >> s;
	int a=0, b=0, c=0;
	for(int i = 0;i < 3;++i){
		if(s[i] == 'a') a = 1;
		if(s[i] == 'b') b = 1;
		if(s[i] == 'c') c = 1;
	}
	puts((a == 1 && b == 1 && c == 1) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  val Array(n, m, l) = StdIn.readLine().split(' ').map(_.toInt)
  val a = Array.fill(n, m)(0) 
  val b = Array.fill(m, l)(0)
  //http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2415390#1
  // val result = Array.fill(n, l)(0L)
  val result: Array[Array[Long]] = Array.ofDim[Long](n, l)
  
  (0 until n).foreach{ i =>
    a(i) = StdIn.readLine().split(' ').map(_.toInt)
  }
  (0 until m).foreach{ i =>
    b(i) = StdIn.readLine().split(' ').map(_.toInt)
  }

  (0 until n).foreach{ i =>
    (0 until l).foreach{ j =>
      result(i)(j) = (0 until m).foldLeft(0L){ (acc, k) =>
        acc + a(i)(k)*b(k)(j)
      }
    }
  }

  (0 until n).foreach { i =>
    println(result(i).mkString(" "))
  }
}


Measured memory_bytes: 78864
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c;
    scanf("%c",&c);
    if(c=='A')
    {
        cout<<"T"<<endl;
    }
    else if(c=='T')
    {
        cout<<"A"<<endl;
    }
    else if(c=='C')
    {
        cout<<"G"<<endl;
    }
    else if(c=='G')
    {
        printf("C\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;
const long long INF = 1LL<<60; // 仮想的な無限大の値
vector<bool> seen;

Graph G;


int main() {
    string odd;
    string even;

    cin >> odd >> even;
    //string ans[odd.length() + even.length()];
    vector<char> ans;
    int k=0,j=0;
    for(int i=0;i < odd.length() + even.length();i++){
        
        if(i % 2 == 0){
            ans.push_back(odd[k]);
            k++;
        }else{
            ans.push_back(even[j]);
            j++;
        }
    }

    for(int i=0;i < ans.size();i++){
        cout << ans[i];
    }
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    sort(A,A+3);
    cout << A[0]+A[1] << endl;
}

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

int main()
{
  string s;
  cin >> s;
  int len = s.size();
  int b = 0;
  uint64_t ans = 0;
  for (auto i = 0; i < len; i++) {
    if (s[i] == 'B') {
      b++;
    } else {
      ans += b;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 832
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define sort(v) sort(v.begin(),v.end()) 
#define pb push_back
/*
ll ar[1000000+9]={0}; 
void seiv() { 
ll n=1000000,i,j; 
ar[1]=1; 
for(i=4;i<=n;i+=2)ar[i]=1; 
for(i=3;i<=n;i+=2) 
{ if(ar[i]==0) 
{ for(j=i*i;j<=n;j+=i*2)ar[j]=1; }
 } 
}*/
int main()
{double a,b,c,d,f;
cin>>a>>d>>c;
if(a/c<=d)cout<<"Yes\n";
else cout<<"No\n";
}

Measured memory_bytes: 3720