akhauriyash/Code-Regression huggingface dataset:
#import<stdio.h>
#import<queue>
int main(){std::queue<int>q;int w,h,f[484],i,j,a,b,t,x,z;char p[15];for(;scanf("%d%d ",&h,&w),h;){for(i=0;i++<h;f[i*22]=f[i*22-~w]=-1,getchar())for(j=0;j++<w;z-35?z>65?b=x:z>64?a=x:1:--f[x])f[j]=f[j-~h*22]=-1,f[x=i*22+j]=-2,z=getchar();f[a]=t=0;q.push(0);for(q.push(a);a=q.front(),q.size()>1;q.pop())if(!a)++t,q.push(0);else for(i=4;i--;)if(f[x=a+" 57L"[i]-54]==-2)f[x]=t,q.push(x);q.pop();scanf("%s",p);for(a=t=0;!a;){x=b;z=0;for(i=0;!a&&p[i];f[b]>=0&&++z)++t,~f[j=b-54+"L65676 "[p[i++]-50]]?b=j:0,f[b]>=0&t>=f[b]?a=b:0;!z&!a&!p[i]&b==x&f[b]<0&&--a;}printf(~a?"%d %d %d\n":"impossible\n",t,a/22-1,a%22-1);}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long max=a*c;
  if(max<=a*d)
  max=a*d;
  if(max<=b*c)
  max=b*c;
  if(max<=b*d)
  max=b*d;
  cout<<max;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main(){
    int A[3][3], N;

    rep(i,3)
        rep(j,3)
            cin >> A[i][j];

    cin >> N;
    int* B = new int(N);
    rep(i, N)
        cin >> B[i];

    
    rep(i,N)
        rep(j, 3)
            rep(l, 3)
                if(B[i] == A[j][l]) A[j][l] = 0;

    bool bRet = false;
    if(
        (A[0][0] == 0 &&  A[0][1] == 0 && A[0][2] == 0) ||
        (A[1][0] == 0 &&  A[1][1] == 0 && A[1][2] == 0) ||
        (A[2][0] == 0 &&  A[2][1] == 0 && A[2][2] == 0) ||
        (A[0][0] == 0 &&  A[1][0] == 0 && A[2][0] == 0) ||
        (A[0][1] == 0 &&  A[1][1] == 0 && A[2][1] == 0) ||
        (A[0][2] == 0 &&  A[1][2] == 0 && A[2][2] == 0) ||
        (A[0][0] == 0 &&  A[1][1] == 0 && A[2][2] == 0) ||
        (A[0][2] == 0 &&  A[1][1] == 0 && A[2][0] == 0)
    ){
        bRet = true;
    }
    if(bRet){
         cout << "Yes" << endl;
    }else{
         cout << "No" << endl;
    }





   
}

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

int main() {
  string A, B;
  int K, N;
  int ten[11];
  int id[11];
  for(int i = 0; i < 11; ++i) id[i] = i;
  ten[0] = 1;
  for(int i = 1; i < 11; ++i) ten[i] = ten[i-1]*10;

  cin >> A >> B >> K;
  N = A.size();
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  while(A.size() != B.size()) B += "0";

  int ans = 0;
  for(int k = 0; k <= K; ++k) {
    do {
      int res = 0;
      for(int i = 0, borrow = 0; i < N; ++i) {
	int a, b;
	a = A[i]-'0', b = B[i]-'0';
	if(a-borrow >= b) {
	  res += ten[i]*(a-borrow-b);
	  borrow = 0;
	} else {
	  res += ten[i]*(a-borrow+10-b);
	  if(id[i] < k) borrow = 0;
	  else          borrow = 1;
	}
      }
      ans = max(ans,res);
    } while(next_permutation(id,id+N));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int C = sc.nextInt();
        final int X = sc.nextInt();
        final int Y = sc.nextInt();


        final int price = Math.min(C*2,A+B) * Math.min(X, Y);
        final int nokori = Math.max(X, Y) - Math.min(X, Y);
        if (X > Y) {
            System.out.println(price + Math.min(nokori*A, nokori*C*2));
        } else {
            System.out.println(price + Math.min(nokori*B, nokori*C*2));
        }
    }
}


Measured memory_bytes: 23764
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 15;
int d , g , p[N] , c[N];
int main() {
    abdelrahman010
    cin >> d >> g;
    for(int i = 0;i < d;i++)
        cin >> p[i] >> c[i];
    int ans = 1e9;
    for(int i = 0;i < (1 << d);i++) {
        int cnt = 0 , sum = 0;
        for(int j = 0;j < d;j++)
            if((1 << j) & i)
                cnt += p[j] , sum += (j + 1) * 100 * p[j] + c[j];
        if(sum >= g) {
            ans = min(ans , cnt);
            continue;
        }
        for(int j = d - 1;j >= 0;j--)
            if(!((1 << j) & i)) {
                int tmp = p[j];
                while(sum < g && tmp > 1) {
                    cnt++ , tmp--;
                    sum += (j + 1) * 100;
                }
            }
        if(sum >= g)
            ans = min(ans , cnt);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3656
N, x = list(map(lambda x: int(x), input().split(' ')))
a = list(map(lambda x: int(x), input().split(' ')))
before = sum(a)


for i in range(1, N):
    s = a[i-1] + a[i]
    if s > x:
        if (s - x) < a[i]:
            a[i] -= (s - x)
        else:
            a[i-1] -= (s - x) - a[i]
            a[i] = 0

print(before - sum(a))


Measured memory_bytes: 63452
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    string s;
    cin >> s;
    bool good=true;
    if(s.at(0) != 'A') good = false;
    int num=0;
    for(int i=2;i<s.size()-1;i++){
        if(s.at(i) == 'C') num++;
    }
    if(num != 1) good = false;
    for(int i=1;i<s.size();i++){
        if((0 > s.at(i) - 'a' || s.at(i) - 'a' > 25) && s.at(i) != 'C') good = false;
    }
    if(good) cout << "AC" << endl;
    else cout << "WA" << endl;
}

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


def solve(N: int, P: "List[int]", Q: "List[int]"):
    P = tuple(P)
    Q = tuple(Q)
    a = 0
    b = 0
    permutations = itertools.permutations(range(1, N + 1))
    for i, permutation in enumerate(permutations):

        if P == permutation:
            a = i
        if Q == permutation:
            b = i

    result = abs(a - b)
    print(result)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, P, Q)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main () {
 int n, x, ans = 0;
 int i, k, s;
 while (1){
     cin >> n >> x;
     ans = 0;
     if (n == 0 && x == 0) break;
     for ( i = 1; i <= n - 2; i++){
         for (k = i + 1; k <= n - 1; k++){
             for (s = 1 + k; s <= n; s++ ){
                 if (i + k + s == x) ans += 1;
              }
         }
     }
       cout << ans << endl; 
 }
      
 }



Measured memory_bytes: 3092
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl "\n"


int main() {
    #ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
    #endif
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s, t; cin >> s >> t;
    int ans = 0;
    for_(i, 0, s.size()) if (s[i] !=t[i]) ans ++;
    cout << ans << endl;

    return 0;
}

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

typedef unsigned long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

const double PI = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1000 * 1000 * 1000;
const int MAX = 2000 * 1000 + 5;
const int MAX2 = 1000 * 1000 + 2;
const int MAX20 = MAX2 * 10;
int n;
int d[205];
vector<vector<int> > g(205);
int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		for(int j = 0; j < n; j++)
			if(s[j] == '1')
			{
				//cout << i << " " << j << endl;
				g[i].PB(j);
			}
	}
	int ans = -1;
	for(int i = 0; i < n; i++)
	{
		memset(d , -1 , sizeof d);
		//cout << endl;
		d[i] = 1;
		queue<int> q;
		q.push(i);
		bool pzdc = false;
		while(!q.empty())
		{
			int u = q.front();
			q.pop();
			for(auto v : g[u])
			{
				if(d[v] == -1)
				{
					q.push(v);
					
					d[v] = d[u] + 1;
					//cout << d[v] << " " << v << endl;
					continue;
				}
				if(d[v] < d[u] || d[v] > d[u])
					continue;
				//cout << u << " " << v << " " << d[u] << " " << d[v] << endl;
				pzdc = true;
			}
		}
		if(pzdc)
			continue;
		int maxD = 0;
		for(int j = 0; j < n; j++)
		{
			
			maxD = max(maxD , d[j]);
		}
		ans = max(ans , maxD);
	}
	cout << ans;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>

using namespace std;

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if(S.size() % 2 == 0) {
        cout << NO << endl;
        return;
    }

    // 文字列を検索
    for(int i = 0; i < S.size(); i++) {
        if(S[i] != S[S.size()-1-i]) {
            cout << NO << endl;
            return;
        }
    }

    // N-1/2まで
    for(int i = 0; i < (S.size()-1)/2; i++) {
        if(S[i] != S[(S.size()-2)/2 -i]) {
            cout << NO << endl;
            return;
        }
    }

    // N+3 / ２からNまで
    for(int i = (S.size()+3)/2; i < S.size(); i++) {
        if(S[i] != S[S.size()-i-1]) {
            cout << NO << endl;
            return;
        }
    }

    cout << YES << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

using namespace std;

int n;
string S[55];

int c[30];

int main(void) {

	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> S[i];
	}

	for (int k = 0; k < 26; k++) {
		c[k] = 99;
		for (int i = 1; i <= n; i++) {
			int count = 0;
			for (int j = 0; j < (int)S[i].size(); j++) {
				if (S[i][j] - 'a' == k) { count++; }
			}
			c[k] = min(c[k], count);
		}
	}

	string ans="";

	for (int k = 0; k < 26; k++) {
		for (int i = 0; i < c[k]; i++) {
			char tmp = 'a' + k;
			
			ans += tmp;
		}
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
i,j,a[512];main(n){scanf("%d",&n);for(j=n;--j;)for(i=j&-j;i;++a[j])i/=2;for(i=n;--i;)for(j=i;j--;)printf("%d%c",a[i-j],j?32:10);}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int a[] = new int[n];
		int minus = 0;
		int zero = 0;
		int minAbs = Integer.MAX_VALUE;
		long absSum = 0;
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();

			if(a[i] < 0){
				minus++;
			}
			if(a[i] == 0){
				zero++;
			}
			minAbs = Math.min(Math.abs(a[i]), minAbs);

			absSum += Math.abs(a[i]);
		}

		if(minus % 2 == 0 || zero > 0){
			System.out.println(absSum);
		}
		else {
			System.out.println(absSum - minAbs*2);
		}

//		if(n == 2){
//			System.out.println(Math.max(a[0] + a[1], -a[0] - a[1]));
//		}
//		int dp[][] = new int[2][n - 1];
//		dp[0][0] = a[0] + a[1];
//		dp[1][0] = -a[0] - a[1];
//
//		for(int i = 1; i < n - 1; i++){
//			dp[0][i] = Math.max(dp[0][i - 1] + a[i + 1], dp[1][i - 1] + a[i]*2 + a[i + 1]);
//			dp[1][i] = Math.max(dp[0][i - 1] - a[i]*2 - a[i + 1], dp[1][i - 1] - a[i + 1]);
//		}

//		int dp[] = new int[n];
//
//		dp[0] = Math.max(a[0], -a[0]);
//		dp[1] = Math.max(a[0] + a[1], -a[0] - a[1]);
//
//		for(int i = 2; i < n; i++){
//			dp[i] = dp[i - 2] + Math.max(a[i], -a[i]);
//		}
//		for(int j = 0; j < 2; j++){
//			for(int i = 0; i < n - 1; i++){
////				System.out.print(dp[j][i]+ " ");
//			}
//			System.out.println();
//		}
//
//		System.out.println(dp[n - 1]);
	}

}

Measured memory_bytes: 50160
#include<stdio.h>
#define MAX 100000
int a[MAX];
int partition(int p,int r){
  int x,i,j,t;
  x = a[r];
  i = p - 1;
  for(j=p;j<r;j++){
    if(a[j] <= x){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }
    t = a[i+1];
    a[i+1] = a[r];
    a[r] = t;
    return i+1;
  
}
int main(){
  int i,q,datanum;
  scanf("%d",&datanum);
  for(i=0;i<datanum;i++){
    scanf("%d",&a[i]);
  }
  q = partition(0,datanum-1);
  for(i=0;i<datanum;i++){
    if(i)printf(" ");
    if(i == q)printf("[");
    printf("%d",a[i]);
    if(i == q)printf("]");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2172
n = int(input())
arr = input().split()
nq = int(input())

for i in range(nq):
    begin, end, tgt = map(int, input().split())
    length = end - begin
    if begin < tgt:
        arr = arr[:begin] + arr[tgt:tgt+length] + arr[end:tgt] + arr[begin:end] + arr[tgt+length:]
    else:
        arr = arr[:tgt] + arr[begin:end] + arr[tgt+length:begin] + arr[tgt:tgt+length] + arr[end:]

print(*arr)


Measured memory_bytes: 5820
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.Stream;
import java.util.Map;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            Map<Character, Integer> map = new HashMap<>();
            for (char c : S.toCharArray()) {
                map.put(c, map.getOrDefault(c, 0) + 1);
            }
            String ret = "No";
            if (map.entrySet().stream().filter(e -> e.getValue() == 2).count() == 2) {
                ret = "Yes";
            }
            out.println(ret);
        }

    }
}



Measured memory_bytes: 28500
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

long long gcd(long long a, long long b) {
    long long small = (a > b) ? b : a;
    long long big = (a > b) ? a : b;
    while (big%small > 0) {
        long long buf = small;
        small = big%small;
        big = buf;
    }
    return small;
}

int main() {
    long long a = 0, b = 0, c = 0, d = 0;
    cin >> a >> b >> c >> d;
    long long count = b - a + 1;
    long long pro = c * d / gcd(c, d);
    long long up = 0, down = 0;
    if (b/c != a/c || a%c == 0) {
        up = b / c;
        down = (a%c == 0) ? a/c : a/c+1;
        count -= (up - down + 1);
    }
    if (b/d != a/d || a%d == 0) {
        up = b / d;
        down = (a%d == 0) ? a/d : a/d+1;
        count -= (up - down + 1);
    }
    if (b/pro != a/pro || a%pro == 0) {
        up = b / pro;
        down = (a%pro == 0) ? a/pro : a/pro+1;
        count += (up - down + 1);
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
	int R[MAX], n;
	cin >> n;
	int j;
	for (int i = 0; i < n; i++)
		cin >> R[i];
	int key;
	for (int i = 0; i < n; i++){
                key=R[i];
		j = i - 1;
		while (j >= 0 && R[j] > key){
			R[j + 1] = R[j];
			j--;
		}
		R[j + 1] = key;
		for (int i = 0; i < n; i++){
                        if(i>0)
                          printf(" ");
			printf("%d", R[i]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3176
#pragma GCC optimize ("O3")
#define _CRT_DISABLE_PERFCRIT_LOCKS
#include <bits/stdc++.h>

using namespace std;
#define BOOST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define fileIn freopen("1.txt", "r", stdin)
#define fileOut freopen("output.txt", "w", stdout)
#define dbg(n) cout << n <<"\n"
#define dbg2(n) cout << n <<" "
#define all(a) a.begin(), a.end()
#define cinArr(arr) for(auto &v : arr) cin>>v
#define coutArr(arr) for(auto &v : arr) cout<<v<<" "
#define FOR(i, a, b) for(int i = a; i < b; i++)
typedef int64_t ll;
typedef uint64_t ull;
typedef vector<int> vi;
typedef vector<vi > vii;

int gcd (int a, int b) {
	while (b) {
		a %= b;
		swap (a, b);
	}
	return a;
}

int main()
{
    BOOST;
    int n;
    cin>>n;
    vi a(n), dpl(n), dpr(n);
    cinArr(a);
    dpl[0] = a[0];
    dpr[n - 1] = a[n - 1];
    FOR(i, 1, n) dpl[i] = gcd(dpl[i - 1], a[i]);
    for(int i = n - 2; i >= 0; --i) dpr[i] = gcd(dpr[i + 1], a[i]);


    int ans = max(dpr[1], dpl[n - 2]);

    FOR(i, 0, n){
        ans = max(ans, gcd(dpr[i + 1], dpl[i - 1]));
    }
    cout<<ans;

    return 0;
}





















Measured memory_bytes: 1408
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    double a, b, c, C, S, L, h;
    double PI = 3.14159265;
    cin >> a >> b >> C;
    S = a * b / 2 * sin(C * PI / 180);
    c = sqrt(a*a + b*b - 2*a*b*cos(C * PI / 180));
    L = a + b + c;
    h = 2 * S / a;
    cout << fixed;
    cout << setprecision(8) << S << endl;
    cout << L << endl;
    cout << h << endl;
    return 0;
}



Measured memory_bytes: 3452
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return(false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }

  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }

  int size(int k)
  {
    return(-data[find(k)]);
  }

  bool same(int x, int y)
  {
      return find(x) == find(y);
  }
};

string op(int sign)
{
    return sign == 0 ? "+" : "-";
}

static const string MARCH("MARCH");

bool IsMarch(char c)
{
  for (auto i : MARCH)
  {
    if (i == c) return true;
  }
  return false;
}

char ItoC(int i)
{
  return MARCH[i];
}

int main()
{
    int N;
    cin >> N;
    string S;
    map<char, int> m;
    REP(i, N)
    {
      cin >> S;
      if (IsMarch(S[0]))
      {
        ++m[S[0]];
      }
    }
    LL ans = 0;
    if (m.size() >= 3)
    {
      for (int bits = 0; bits < (1 << 5); ++bits)
      {
        bitset<5> bs(bits);
        if (bs.count() != 3) continue;

        LL num = 1;
        for (int i = 0; i < 5; ++i)
        {
          if (bs[i] != 0)
          {
              num *= m[ItoC(i)];
          }
        }

        ans += num;
      }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
x, y, t = 0, 0, 0
schd = []

for _ in range(n):
    schd.append(list(map(int, input().split())))

for k in range(n):
    t1, x1, y1 = schd[k][0], schd[k][1], schd[k][2]
    dist = abs(x1-x) + abs(y1-y)
    if dist <= t1-t and (t1-t-dist)%2 == 0:
        t, x, y = t1, x1, y1
    else:
        print("No")
        exit()
else:
    print("Yes")

Measured memory_bytes: 27380
#include<iostream>
#include<string>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)


int main(void){
  int al[27]={0};
  int num[11]={0};
  string s;

  cin>>s;
  int ori = s.size();
  for(int i = 0 ; i < s.size() ; i ++){
    if('a'<=s[i] && s[i]<='z')
      al[s[i]-'a']++;
    if('0'<=s[i] && s[i]<='9')
      num[s[i]-'0']++;
  }
  int cnt = 0;
  //rep(i,26)cout<<(char)('a'+i)<<" "<<al[i]<<endl;
  for(int i = 0 ; i < 26 ; i ++){
    if(al[i]){
      al[i]--;
      cnt ++;
      if(al[i+1]&&al[i+2]){
	cnt += 2;
	for(int j = i + 1 ; al[j] ; j ++){
	  al[j]--;
	  //cout<<'1'<<endl;
	}
      }
    }
    if(al[i])i--;
  }

  //cout<<cnt<<endl;
  //rep(i,10)cout<<(char)(i+'0')<<num[i]<<endl;
  for(int i = 0 ; i < 10 ; i ++){
    //cout<<i<<" "<<num[i]<<endl;
    if(num[i]){
      num[i]--;
      cnt ++;
      if(num[i+1]&&num[i+2]){
	cnt += 2;
	for(int j = i + 1 ; num[j] ; j ++){
	  num[j]--;
	}
      }
    }
    if(num[i])i--;
  }

  //rep(i,10)cout<<(char)(i+'0')<<num[i]<<endl;
  //if(al[25]&&num[0])cnt++;
  cout<<min(cnt,ori)<<endl;
}

Measured memory_bytes: 1184
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int n, d, x, a[102], sum = 0;

	cin >> n >> d >> x;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum++;
		for (int j = 1; j * a[i] + 1 <= d; j++)
			sum++;
	}

	sum += x;
	cout << sum << endl;


	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
using namespace std;

const int MAX_N = 3005, MOD = 1000000007;
typedef long long i64;
i64 f[2][MAX_N], C[MAX_N][MAX_N];
int L[MAX_N], R[MAX_N];
char s[MAX_N];

int main() {
  int N, M;
  
  scanf("%d%d", &N, &M);
  scanf("%s", s + 1);

  assert(strlen(s + 1) == N);
  
  for (int i = 1; i <= M; ++i) {
    scanf("%d%d", &L[i], &R[i]);
    assert(L[i] >= L[i - 1]);
    assert(L[i] < R[i]);
    assert(R[i] <= N);
    if (R[i] <= R[i - 1]) i--, M--;
  }
  
  for (int i = 0; i <= N; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
  }
  
  int o = 0, p;
  R[0] = L[1] - 1, f[0][0] = 1, L[M + 1] = N + 1;
  
  for (int i = 1; i <= M; ++i) {
    p = o, o ^= 1;
    memset(f[o], 0, sizeof f[o]);
    int num = 0;
    for (int j = R[i - 1] + 1; j <= R[i]; ++j)
      if (s[j] == '1') num++;
    
    int temp1 = R[i - 1] - L[i] + 1, temp2 = max(R[i] - L[i + 1] + 1, 0);
    
    for (int k1 = 0; k1 <= temp1; ++k1) {
      int num1 = num + k1, num0 = R[i] - L[i] + 1 - num1;
      for (int k2 = 0; k2 <= temp2; ++k2) {
	int rest1 = num1 - k2, rest0 = num0 - temp2 + k2;
	if (rest1 < 0 || rest0 < 0) continue;
	f[o][k2] = (f[o][k2] + C[rest1 + rest0][rest1] * f[p][k1] % MOD) % MOD;
      }
    }
    if (R[i] < L[i + 1] - 1) R[i] = L[i + 1] - 1;
  }

  printf("%lld\n", (f[o][0] + MOD) % MOD);
  
  return 0;
}


Measured memory_bytes: 69120
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		String str1=sc.nextLine();
		String str2=sc.nextLine();
		
		String[] line=str2.split("");
		
		int count=0;
		
		for(String str:line) {
			if(str.equals("R")) {
				count++;
			}
		}
		
		int point=0;
		
		for(int i=0;i<count;i++) {
			if(line[i].equals("R")) {
				point++;
			}
		}
		
		System.out.println(count-point);
		
		sc.close();
	}
}


Measured memory_bytes: 66120
#include <iostream>
#include <bitset>

using namespace std;
int main(){
	int i,n,a[2020],sum=0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	bitset <4000010> d,p;
	d.set(0);
	for(i=0;i<n;i++){
		p |= d;
		p |= d << a[i];
		swap(d,p);
	}
	
	for(i=(sum+1)/2;i<4000010;i++){
		if(d[i]){
		cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    getline(cin,s);
    int x=s.size();
    printf("%c",toupper(s[0]));
    for(int i=0;i<x;i++)
        if(s[i]==' ')
        printf("%c",toupper(s[i+1]));
    cout<<endl;
}


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

typedef long long ll;

int main() {
  int N; cin >> N;
  int F[101][11];
  int P[101][11];
  for ( int i = 1; i <= N; i++ ) {
    for ( int j =1; j <= 10; j++ ) {
      cin >> F[i][j];
    }
  }

  for ( int i = 1; i <= N; i++ ) {
    for ( int j = 0; j <= 10; j++ ) {
      cin >> P[i][j];
    }
  }
  ll ans = -1e18;
  for ( int bit = 0; bit < (1 << 10); bit++ ) {
    vector<int>S;
    for ( int j = 0; j < 10; j++ ) {
      if ( bit & (1<<j)) {
	S.push_back(j+1);
      }
    }
    int cnt;
    ll sum;
    if ( S.size() == 0 ) continue;
    int cnt2 = 0;
    sum = 0;    
    for ( int i = 1; i <= N; i++ ) {
      cnt = 0;

      for ( int k = 0; k < S.size(); k++ ) {
	if ( F[i][S[k]] == 1 ) {
	  cnt++;
	  cnt2++;
	}
      }
      sum += P[i][cnt];
      //cout <<cnt << " " <<  sum << endl;
    }
    if ( cnt2 != 0 ) ans = max(sum,ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int A[12] = {1,3,1,2,1,2,1,1,2,1,2,1}; 
int x, y; 
cin >> x >> y; 
if(A[x-1] == A[y-1]) cout << "Yes" << endl; 
else cout << "No" << endl; 
}

Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}

object Main extends App {
  val n = readInt
  for(i<- 0 until n) {
    var s = readLine
    for(j<-0 until s.length-6) {
      if(s.substring(j,j+7) == "Hoshino")
        s = s.updated(j+6,'a')
    }
    println(s)
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll n; cin >> n;
	ll ans = 100000;
	REP(i, n) {
		ans = ((ans * 105+99) / 100 + 999) / 1000 * 1000;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

namespace AtCoder_CSharp
{
    class AtCoder
    {
        static void Main(string[] args)
        {
            int N, K;

            string[] input = Console.ReadLine().Split(' ');

            N = int.Parse(input[0]);
            K = int.Parse(input[1]);

            if (K == 1)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(N - K);
            }
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef unsigned long long ll;
const int INF = 1e9;

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

int main(){
   int n; cin >> n;
   vector<ll> a(n);
   REP(i,n) cin >> a[i];
   if(n==1){
       cout << a[0] << endl;
       return 0;
   }
   ll lcm = a[0] / gcd(a[0],a[1]) * a[1];
   for(int i = 2; i < n; ++i){
       lcm = a[i] / gcd(a[i],lcm) * lcm;
   }
   cout << lcm << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int n;
    int ans;

    while (1){
        scanf("%d", &n);

        if (n == 0){
            break;
        }
        
        ans = 0;

        while (1){
            if (n == 1){
                break;
            }

            if ((n % 2) == 0){
                n /= 2;
                ans++;
            }
            else {
                n *= 3;
                n++;
                ans++;
            }
        }

        printf("%d\n", ans);
    
    }

    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    // pairは<>
    // Segmentation fault: 11
    // →squareの要素数を定義しないで使っていたため
    int n,n_i,d_i;
    vector<pair<int,int> > result;
    while (1)
    {
        cin >> n;
        if (n == 0)
        {
            break;
        }
        
        vector<pair<int,int> > square(n);
        square[0] = make_pair(0,0);
        int x,y;
        for(int i=1;i<n;i++){
            cin >> n_i >> d_i;
            pair<int,int> be_pair = square[n_i];
            // cout << be_pair.first << " " << be_pair.second << endl;
            if (d_i == 0){
                x = be_pair.first + 1;
                y = be_pair.second;
            } else if (d_i == 1){
                x = be_pair.first;
                y = be_pair.second + 1;
            } else if (d_i == 2){
                x = be_pair.first - 1;
                y = be_pair.second;
            } else if (d_i == 3){
                x = be_pair.first;
                y = be_pair.second - 1;
            }
            // cout << x << "," << y << endl;
            square[i] = make_pair(x,y);  
        }
        int max_height = 0, max_width = 0;
        int min_height=n, min_width=n;
        for(int i=0;i<n;i++){
            x = square[i].first;
            y = square[i].second;
            max_width = max(x, max_width);
            max_height = max(y, max_height);
            min_width = min(x, min_width);
            min_height = min(y,min_height);
            // cout << max_width << max_height << min_width << min_height<<endl;
        }
        result.push_back(make_pair(abs(max_width-min_width)+1,abs(max_height-min_height)+1));
        
    }
    for (int i = 0; i < result.size(); i++)
    {
        cout << result[i].first <<" "<< result[i].second << endl;
    }
}



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

signed main () {
    int n, k;
    cin >> n >> k;
    int64_t ans = 0;
    map < int, int64_t > mods;
    for (int i = 1; i <= n; ++i)
        ++mods[i % k];
    for (int i = 1; i <= n; ++i) {
        if ((i % k) == ((k - (i % k)) % k)) 
            ans += mods[i % k] * mods[(k - (i % k)) % k];
    }
    cout << ans << '\n';
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void init(int *par, int N){
    for(int i=0; i<N; i++){
        par[i] = i;
    }
}

int root(int *par, int x){
    if(par[x] == x) return x;
    else return par[x] = root(par, par[x]);
}

bool same(int *par, int x, int y){
    return root(par, x) == root(par, y);
}

void unite(int *par, int x, int y){
    x = root(par, x);
    y = root(par, y);
    if(x == y) return;
    par[x] = y;
}

int main(void){
    int N, M;
    cin >> N >> M;
    int par[N];
    init(par, N);
    rep(i, M){
        int x, y, z;
        cin >> x >> y >> z;
        unite(par, x-1, y-1);
    }
    rep(i, N) root(par, i);
    //rep(i, N) cout << par[i];
    //cout << endl;
    sort(par, par+N);
    int ans = 1;
    for(int i = 1; i < N; i++){
        if(par[i] != par[i-1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

bool sortbydec(const pair<int,int> &a , const pair<int,int> &b)
{
    return a.first>b.first;
}

int32_t main()
{
        int a;
        cin>>a ;
        cout<<a+a*a+a*a*a ;
    
       return 0;
}

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

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

using namespace std;





int main()
{
	int p,q;
	while(cin >>p >>q){
		string ans, ans2;
		map<int,int> mp;
		mp[p]=0;
		rep(k,81){
			p *=10;
			ans += p/q +'0';
			p=p%q;
			if(p==0) break;
			if(mp.count(p)) break;
			mp[p] = k+1;
			//printf("%s   %d\n", ans.c_str(),k);
		}
		printf("%s\n", ans.c_str());
		if(p){
			ans2=string(ans.size(), ' ');
			for(int j=mp[p];j<ans2.size();j++) ans2[j]='^';
			printf("%s\n", ans2.c_str());
		}
	}
	return 0;

}

Measured memory_bytes: 3012
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair
#define debug_vec(x, n) cout << (#x) << ": "; for(int i = 0; i < n; i++) cout << x[i] << (i == n - 1 ? "\n" : " ");

#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << "\n";
    err(++it, args...);
}

typedef long long ll;
typedef long double ld;

void solve(){
    int n, k;
    cin >> n >> k;
    set<int> s;
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int i = 0; i < d; i++){
            int x;
            cin >> x;
            s.insert(x);
        }
    }
    int res = 0;
    for(int i = 1; i <= n; i++){
        if(s.find(i) == s.end()){
            res++;
        }
    }
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
while(n,m=gets.split.map(&:to_i))!=[0,0]do
r,p,a=[],[],[]
n.times{r.unshift(gets.gsub("?",".").split)}
m.times{p<<gets.split}
p.each{|p|r.each{|r|if p[0]=~/#{r[1]}/&&p[1]=~/#{r[2]}/
a<<p*" "if r[0]=~/p/
break
end}}
puts a.size,a
end

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

int main() {
  string s;
  cin >> s;
  string flag="YES";
  // cout << s.length();
  for(int i=0;i<s.length();){
    if(s.substr(i,6)=="eraser" && (s.substr(i+6,1) == "e"|| s.substr(i+6,1) == "d" || i+6 == s.length())){
      // cout << s.substr(i,6) << " ";
      i=i+6;
    }  
    else if(s.substr(i,5)=="erase"){
      // cout << s.substr(i,5) << " ";
      i=i+5;
    }
    else if(s.substr(i,7)=="dreamer" && (s.substr(i+7,1) == "e"|| s.substr(i+7,1) == "d" || i+7 == s.length())){
      // cout << s.substr(i,7);           
      i=i+7;
    }
    else if(s.substr(i,5)=="dream"){
      // cout << s.substr(i,5) << " ";      
      i=i+5;
    }  
    else {
      flag="NO";
      break;
    }
  }
  cout << flag;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



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

        if (x <= 6) {
                cout << 1 << endl;
                return 0;
        } else if (6 < x and x <= 11) {
                cout << 2 << endl;
                return 0;
        }

        ll ans = x / 11;
        ll r = x % 11;
        ans *= 2;

        //cout << "r: " << r << endl;
        if (r > 6) ans += 2;
        else if (1 <= r and r <= 6) ans += 1;
        
        cout << ans << endl;
}

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

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans1 = 0;
	// 奇数 正  偶数 負
	vector<ll> accum1(n + 1, 0);
	for (ll i = 1; i <= n; i++) {
		accum1[i] += accum1[i - 1];
		accum1[i] += a[i - 1];
		if (i % 2 != 0) {
			if (0 < accum1[i]) {
			}
			else if (accum1[i] <= 0) {
				ans1 += abs(accum1[i]) + 1;
				accum1[i] += abs(accum1[i]) + 1;
			}			
		}
		else { // i % 2 == 0
			if (0 <= accum1[i]) {
				ans1 += abs(accum1[i]) + 1;
				accum1[i] -= abs(accum1[i]) + 1;
			}
			else if (accum1[i] < 0) {				
			}
		}
	}
	// 奇数 負  偶数 正
	ll ans2 = 0;
	vector<ll> accum2(n + 1, 0);
	for (ll i = 1; i <= n; i++) {
		accum2[i] += accum2[i - 1];
		accum2[i] += a[i - 1];
		if (i % 2 == 0) {
			if (0 < accum2[i]) {
			}
			else if (accum2[i] <= 0) {
				ans2 += abs(accum2[i]) + 1;
				accum2[i] += abs(accum2[i]) + 1;
			}
		}
		else { // i % 2 != 0
			if (0 <= accum2[i]) {
				ans2 += abs(accum2[i]) + 1;
				accum2[i] -= abs(accum2[i]) + 1;
			}
			else if (accum2[i] < 0) {
			}		
		}
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;



int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int s, w;
    cin >> s >> w;

    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;

    return 0;
%>

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

class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

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


n, k, l = map(int, input().split())
road = UnionFind(n)
for i in range(k):
    p, q = map(int, input().split())
    road.union(p, q)

rail = UnionFind(n)
for i in range(l):
    r, s = map(int, input().split())
    rail.union(r, s)

r = [(road.find(i + 1), rail.find(i + 1)) for i in range(n)]
c = Counter(r)
ans = []
for i in range(n):
    ans.append(c[r[i]])
print(' '.join(map(str, ans)))


Measured memory_bytes: 72444
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
const ll tl= 1'000'000'007;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(n);
    string A=""; 
    REP(i,n) A+= to_string(i+1);
    string p="",q="";
    REP(i,n){
        ins(x);
        p+=x;
    }
    REP(i,n){
        ins(x);
        q+=x;
    }
    int s=0,t=0;
    int i=0;
    do{
        i++;
        if(p==A) s= i;
        if(q==A) t= i;
    }while(next_permutation(all(A)));
    out(abs(s-t));
}

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

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

    vector<vector<int>> G(N), rG(N);
    for(int i=0;i<N + M - 1;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        rG[b].push_back(a);
    }

    vector<int> edge_cnt(N, 0);
    set<pair<int, int>> s;
    for(int i=0;i<N;i++){
        edge_cnt[i] = rG[i].size();
        s.emplace(edge_cnt[i], i);
    }

    vector<int> parent(N, -1);

    while(s.size()){
        auto p = *s.begin();
        s.erase(s.begin());
        int v = p.second;
        for(int to : G[v]){
            s.erase(make_pair(edge_cnt[to], to));
            edge_cnt[to]--;
            if(edge_cnt[to] == 0){
                assert(parent[to] == -1);
                parent[to] = v;
            }
            s.emplace(edge_cnt[to], to);
        }
    }

    for(int i=0;i<N;i++){
        cout << parent[i] + 1 << endl;
    }

    return 0;
}

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

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

def solve(c: "List[List[int]]"):

    L = []
    for i in range(3):
        L.append(c[i][0] - c[i][1])
    if len(set(L)) > 1:
        print(NO)
        return

    R = []
    for i in range(3):
        R.append(c[i][1] - c[i][2])
    if len(set(R)) > 1:
        print(NO)
        return

    print(YES)


    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
def msb(n)
  1 << (n.bit_length - 1)
end

def clear_highest_diff_bit(x, k)
  x ^ msb(((x ^ k) & x))
end

_n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
ary_x = []
m  = k.bit_length
0.upto(m - 1) do |bit|
  c = a.map { |e| (e >> bit) & 1 }
  ary_x[bit] = (c.count(1) > c.count(0)) ? 0 : 1
end
x = ary_x.reverse.join.to_i(2)
while x > k
  x = clear_highest_diff_bit(x, k)
end

puts a.map { |e| e ^ x }.inject(:+)


Measured memory_bytes: 25292
// https://atcoder.jp/contests/dp/tasks/dp_f

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define gcd __gcd
#define inf INT_MAX
#define minf INT_MIN
#define pb push_back
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<<" "; cout<<"\n";
#define printn(v) for(auto x:v) cout<<x<<"\n";
#define F first
#define S second
#define mp make_pair

const int N = 1e5 + 1;
vector<int>gr[N];
int dp[N]; //dp[i] = represents length of longest path starting at node i

int longest_path(int src) {
	if (dp[src] != -1) return dp[src];
	bool leaf_node = 1;
	int best_child = 0;
	for (auto child : gr[src]) {
		leaf_node = 0;
		best_child = max(best_child, longest_path(child));
	}
	return dp[src] = (leaf_node ? 0 : 1 + best_child);
}

int32_t main() {
	fastio;
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		gr[u].pb(v);
	}
	memset(dp, -1, sizeof dp);
	int ans = 0;
	for (int i = 1; i <= n; i++) ans = max(ans, longest_path(i));
	cout << ans << endl;
}

Measured memory_bytes: 11528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const lli MOD=1e9+7;

int main(){
	int W,a,b;
	cin>>W>>a>>b;
	if(a>b){
		int c=a;
		a=b;
		b=c;
	}
	int ans;
	if(a+W>=b)ans=0;
	else ans=b-a-W;
	cout<<ans<<endl;
}

Measured memory_bytes: 256