akhauriyash/Code-Regression huggingface dataset:
# Union Find
class UnionFind():
    # parents:親要素の番号，要素が根なら-グループの要素数
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # xが所属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # xとyのグループを併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

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

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

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

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

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

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

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

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


n, m = map(int, input().split())

UF = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    UF.union(a, b)

print(len(UF.roots()) - 1)


Measured memory_bytes: 12956
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int m = Integer.parseInt(in.next());
            int lr[][] = new int[m][2];
            int min = 1;
            int max = n;
            for (int i = 0; i < m; i++) {
                lr[i][0] = Integer.parseInt(in.next());
                lr[i][1] = Integer.parseInt(in.next());
                min = Math.max(min, lr[i][0]);
                max = Math.min(max, lr[i][1]);
            }
            // 出力
            out.println(Math.max(0, max - min + 1));

        }

    }
}



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

int main(){
    int a,b;
    cin >> a >> b;
    string s;
    cin >> s;

	for(int i; i < a+b+1; i++){
    	if(i == a){
        	if(s.at(i) != '-'){
              cout << "No" << endl;
          	  return 0;
            }
        }
        else{
            if(s.at(i) >= '0' && s.at(i) <= '9')
              continue;
            else{
              cout << "No" << endl;
              return 0;
            }
        }        
    }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
	int a,b,h;
	cin >> a >> b >> h;
	cout << (a+b)*h/2 << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cassert>
#include <deque>
#include <map>
#include <queue>
#include <climits>
#include <set>
#include <stack>

using namespace std;

#define ll long long
#define MAX 100000
#define MAX1 10000
#define MAX2 100000
#define inf 1000000000
#define eps 1e-12
#define MOD 1000000007

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    int n, a;
    cin >> n;
    a = n / 1000;
    a += (n % 1000 != 0);
    n = 1000 * a - n;
    cout << n;

    return 0;
}


Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(Q)]

cup = list(range(N+1)) + [0]
se = set([0,1,2])
ball = 1
for a,b in AB:
    cup[a],cup[b] = cup[b],cup[a]
    for x in [a,b]:
        if cup[x] == 1:
            ball = x
    se.add(cup[ball-1])
    se.add(cup[ball+1])

se.remove(0)
answer = len(se)
print(answer)



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

            if(T[j] == 'r') {
                ans += P;
            }
            else if(T[j] == 's') {
                ans += R;
            }
            else if(T[j] == 'p') {
                ans += S;
            }

            if(j+K <= n-1 && T[j] == T[j+K]) {
                j += K;
            }
        }
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string str;
string ans;
int d[4];

void dfs(int v,int sum){
	if(v==3){
		if(sum==7){
			string tmp="";
			for(int i=0;i<4;i++){
				tmp+=str[i];
				if(i<3){
					if(d[i]==1){
						tmp+='+';
					}else{
						tmp+='-';
					}
				}
			}
			tmp+="=7";
			ans=tmp;
		}
	}else{
		d[v]=1;
		dfs(v+1,sum+(str[v+1]-'0'));
		d[v]=0;
		dfs(v+1,sum-(str[v+1]-'0'));
	}
}

int main(void){
	cin >> str;
	dfs(0,(str[0]-'0'));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>

double getd(double x, double y){
	double r = atan2(y, x) * 180 / M_PI;
	return r;
}

int main(){
	double x1,y1,x2,y2,x3,y3,xp,yp,d1,d2,d3;
	double h;
	while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp) + 1){
		x1 -= xp;
		x2 -= xp;
		x3 -= xp;
		y1 -= yp;
		y2 -= yp;
		y3 -= yp;
		d1 = getd(x1,y1);
		d2 = getd(x2,y2);
		d3 = getd(x3,y3);
		if(d1 > d2){
			h = d1;
			d1 = d2;
			d2 = h;
		}
		if(d2 > d3){
			h = d2;
			d2 = d3;
			d3 = h;
			if(d1 > d2){
				h = d1;
				d1 = d2;
				d2 = h;
			}
		}
		d2 -= d1;
		d3 -= d1;
		if(180 > d2){
			if(180 < d3 && d3 < d2 + 180){
				printf("YES\n");
			}else{
				printf("NO\n");
			}
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1100
#include <stdio.h>

int main() {
  int x[3000][2], i, j, a;

  for(i=0;i<3000;i++) {
    scanf("%d %d",&x[i][0], &x[i][1]);
    if(x[i][0]==0 && x[i][1]==0) break;
  }

  for(i=0;i<3000;i++) {
    if(x[i][0]==0 && x[i][1]==0) break;
    if(x[i][0]>x[i][1]){
      a = x[i][0];
      x[i][0] = x[i][1];
      x[i][1] = a;
    }
    printf("%d %d\n", x[i][0], x[i][1]);
  }

  return 0;
}



Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
LL n;

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

	cin >> n;
	cout << (1000-(n%1000) == 1000 ? 0 : 1000-(n%1000)) << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 5e3 + 7, MOD = 1e9 + 7;
void inc(int &a, int b) { if ((a += b) >= MOD) a -= MOD; }
int add(int a, int b) { if ((a += b) >= MOD) a -= MOD; return a; }
int mul(int a, int b) { return ll(a) * b % MOD; }
int n, m, dp[N][N], g[N][N], pw[N];
int main() {
  pw[0] = 1; rep(i, 1, N) pw[i] = mul(pw[i - 1], 2);
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
  cin >> n;
  string s; cin >> s; m = sz(s);
	dp[0][0] = g[0][0] = 1;
	rep(i, 0, n + 1)
		rep(j, 0, i + 1) {
			inc(dp[i + 1][j + 1], dp[i][j]);
			if (j)
				inc(dp[i + 1][j - 1], dp[i][j]);
			inc(g[i + 1][j + 1], mul(2, g[i][j]));
			inc(g[i + 1][max(0, j - 1)], g[i][j]);		
		}
	int ans = 0;
	rep(pre, 0, n + 1) if (n - pre >= m && (n - pre - m) % 2 == 0)
		inc(ans, mul(g[pre][0], mul(dp[n - pre - 1][m - 1], pw[(n - pre - m) / 2])));
	cout << ans;
	return 0;
}

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

int main() {
  int N,i,j,k;
  cin>>N;

  string s;
  int w = 0;
  for(i=0;i<N;i++){

  	cin >> s;
 // 	cout << i << ":" << s << endl;

  		if(s=="Y"){
		cout<<"Four"<<endl;
  			break;
		}
  		
  	}

	if(s!="Y"){
		cout<<"Three"<<endl;
	}

}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		Dxy[] ab = new Dxy[n];
		Dxy[] cd = new Dxy[n];
		for (int i = 0; i < n; i++) {
			ab[i] = new Dxy(in.nextInt(), in.nextInt());
		}
		for (int i = 0; i < n; i++) {
			cd[i] = new Dxy(in.nextInt(), in.nextInt());
		}
		System.out.println(solve(ab, cd));
		in.close();
	}

	private static int solve(Dxy[] ab, Dxy[] cd) {
		int r = 0;
		Arrays.sort(cd, new CompCD());
		Arrays.sort(ab, new CompAB());
		boolean[] fab = new boolean[ab.length];
		for (int i = 0; i < cd.length; i++)
			for (int j = 0; j < ab.length; j++)
				if (ab[j].x < cd[i].x && ab[j].y < cd[i].y && !fab[j]) {
					r++;
					fab[j] = true;
					break;
				}
		return r;
	}
}

class CompAB implements Comparator<Dxy> {
	public int compare(Dxy a, Dxy b) {
		if (a.y == b.y)
			return b.x - a.x;
		else
			return b.y - a.y;
	}
}

class CompCD implements Comparator<Dxy> {
	public int compare(Dxy a, Dxy b) {
		if (a.x == b.x)
			return a.y - b.y;
		else
			return a.x - b.x;
	}
}

class Dxy {
	public Dxy(int a, int b) {
		x = a;
		y = b;
	}

	int x;
	int y;
}


Measured memory_bytes: 23892
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, q, a[MAXN], cnt[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll res = 0;
    FOR(i,1,n) res += a[i];
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        res -= (ll) cnt[u] * u;
        res += (ll) cnt[u] * v;
        cnt[v] += cnt[u];
        cnt[u] = 0;
        cout << res << "\n";
    }
    return 0;
}


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

int main()
{
	int N, d[1000];
	while(cin >> N, N)
	{
		for(int i=0; i<N; i++)
			cin >> d[i];

		sort(d,d+N);
		int ret=0;
		for(int i=1; i<N-1; i++)
			ret+=d[i];

		cout << ret/(N-2) << endl;
	}
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(114514)


def dfs(g, n):
    if not g[n]:
        return 0
    a = []
    for node in g[n]:
        a.append(dfs(g, node))
    a.sort()
    res = 0
    for i, x in enumerate(a):
        res = max(res, x - i)
    return res + len(a)


n = int(input())
a = [int(input()) for _ in range(n - 1)]
g = [[] for _ in range(n)]
for i in range(n - 1):
    g[a[i] - 1].append(i + 1)
print(dfs(g, 0))


Measured memory_bytes: 122904
l = sorted(list(map(int, input().split())))
aq = (l[2] - l[0]) // 2
ar = (l[2] - l[0]) % 2
bq = (l[2] - l[1]) // 2
br = (l[2] - l[1]) % 2
cnt = aq + bq

if ar == 1 and br == 1:
    print(cnt + 1)
elif ar == 1 or br == 1:
    print(cnt+2)
else:
    print(cnt)

Measured memory_bytes: 3064
import fractions

N, K = map(int, input().split())
As = list(map(int, input().split()))

def solve(N, K, As):
    if N == 1:
        if K == As[0]:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")
        return
    g = As[-1]
    for a in As[:-1]:
        g = fractions.gcd(g, a)
    maxA = max(As)
    if (maxA >= K) and ((maxA - K)%g) == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

solve(N, K, As)


Measured memory_bytes: 16276
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
typedef long long ll;

using namespace std;


int main(){
    string S;
    cin >> S;
    int l=0;
    int r=S.size()-1;
    int sum=0;
    while(l<r){
        if(S[l] != S[r]){
            sum ++;
        }
        l++;
        r--;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
n,Y = map(int,input().split())
for i in range(Y//10000 + 1):
    x = i
    for j in range((Y-10000*x)//5000 + 1):
        y = j
        z = n - x - y
        if x*10000 + y*5000 + z*1000 == Y:
                print(x,y,z)
                exit(0)
else:
    print('-1 -1 -1')

Measured memory_bytes: 3060
class String
  def to_ia
    split(/\s/).map {|s| s.to_i}
  end
end
  
class Array
  def binary_search(val)
    left = 0
    right = size
    while left < right
      mid = (left + right) / 2
      if self[mid] == val
        return val
        #return mid
      elsif val < self[mid]
        right = mid
      else
        left = mid + 1
      end
    end
    nil
  end

  def binary_search_rec(val, left, right)
    return nil unless left < right
    mid = (left + right) / 2
    return mid if self[mid] == val
    if val < self[mid]
      binary_search_rec(val, left, mid)
    else
      binary_search_rec(val, mid+1, right)
    end
  end
end

STDIN.readline
subject = STDIN.readline.to_ia
STDIN.readline
search = STDIN.readline.to_ia

ans = 0
search.each do |v|
  #ans += 1 unless subject.binary_search(v).nil?
  ans += 1 unless subject.binary_search_rec(v, 0 , subject.size).nil?
end
puts ans

Measured memory_bytes: 17260
#[allow(unused)]
use std::io::{stdin, stdout, Write};    
use std::iter::Iterator;
#[allow(unused)]
macro_rules! read {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty), *) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            read!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(non_snake_case)]
fn main() {
    let n = read![i32];
    let mut c = String::new();
    stdin().read_line(&mut c).unwrap();
    let c = c.as_bytes().to_vec();
    let mut rRCount = c.iter().filter(|&item| *item == b'R').count();
    let mut lWCount = 0;
    let mut min = rRCount;
    for i in 0..c.len() {
        if c[i] == b'R' {
            rRCount -= 1;
        } else {
            lWCount += 1;
        }
        min = std::cmp::min(min, std::cmp::max(rRCount, lWCount));
    }
    println!("{}", min);
}

Measured memory_bytes: 2408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <cstdio>
#include <bitset>


using namespace std;
using ll = long long;

#define rep(i, n)  for (ll i = 0; i < (n); i++)
#define INF 100000000

ll H, W, K;
vector<string> S;

bool sat(const vector<ll> &whites, const bitset<16> &divs) {
  ll cnt = 0;

  rep(i, H) { // 切れ目の数なので
    cnt += whites[i];

    if (cnt > K) {
      return false;
    }

    if (divs[i] > 0)  {
      cnt = 0;
    }
  }

  return true;
}

ll check(bitset<16> divs) {
  ll cut = 0;
  bool ate = false;

  vector<ll> whites(10, 0);

  for (ll w = 0; w < W; w++) {
    rep(h, H) {
      if (S[h][w] == '1') {
        whites[h]++;
      }
    }

    if (sat(whites, divs)) {
      ate = true;
    } else { //  unsat
      if (ate == false) {
        return INF; // impossible
      }

//      printf("cut at %lld\n", w);

      // cut and start from last bite
      cut++;
      w -= 1;
      ate = false;

      fill(whites.begin(), whites.end(), 0);
    }
  }
  return cut;
}

ll search() {
  ll mn = INF;

  rep(h, 1 << (H - 1)) {
    bitset<16> divs(h);
    ll c = check(divs);
    ll a = divs.count();

    mn = min(c + a, mn);
  }

  return mn;
}


int main() {
  cin >> H >> W >> K;

  rep(i, H) {
    string tmp; cin >> tmp;
    S.emplace_back(tmp);
  }

  ll result = search();

  cout << result << endl;
  return 0;
}

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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 300001;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    fast_io();
    cout.precision(9);
    cout << fixed;
    auto start = chrono::steady_clock::now();
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t;
    cin >> t;
    if (s.size() + t.size() < n) {
        cout << s << string(n - t.size() - s.size(), 'a') << t << "\n";
        return 0;
    }
    int mx_inter = 0;
    for (int inter = 1; inter <= s.size() + t.size() - n && inter <= s.size() && inter <= t.size(); ++inter) {

        if (s.substr(s.size() - inter) == t.substr(0, inter)) {
            mx_inter = inter;
        }
    }
    cout << s.size() + t.size() - mx_inter << "\n";
    auto end = chrono::steady_clock::now();

    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);

}



Measured memory_bytes: 256
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
# 条件を満たす状態における 連続する 4 つの値に関して考えると
# a_i = a_(i+3) を満たす事がわかる
# 満たす条件は
# a1 ^ a2 ^ a3 = 0
# a_i = a_(i+3) -> 値が 3 種類以内
c = Counter(a)
n_uniq = len(c)
# 値が 3 種類以上であれば No
if n_uniq > 3:
    print('No')
#  a1, a2, a3 の場合分けを考える
# 3 種類の異なる値の場合 : a1, a2, a3 が n 枚のうちちょうど同じ数ずつある必要がある (-> n / 3 が 3 の倍数)
elif n_uniq == 3:
    a_1, a_2, a_3 = c.keys()
    if a_1 ^ a_2 ^ a_3 == 0 and c[a_1] == c[a_2] == c[a_3]:
        print('Yes')
    else:
        print('No')
# 2 種類の異なる値の場合 : ある 1 つの値が必ず 0 -> 0 が n / 3 枚、 等しい数となる a_x は 2n / 3 枚
elif n_uniq == 2:
    a_1, a_2 = sorted(set(a))
    if a_1 == 0 and 3 * c[a_1] == n:
        print('Yes')
    else:
        print('No')
# 全て同じ値の場合 : 全て 0
else:
    if sum(a) == 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 20988
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int c[50][50];
void dfs(int i, int j, int w, int h) {
  c[i][j] = 0;
  rep(k, 3) {
    int di = i - 1 + k;
    if (di < 0 || h <= di) continue;
    rep(l, 3) {
      int dj = j - 1 + l;
      if (dj < 0 || w <= dj) continue;
      if (di == i && dj == j) continue;
      if (c[di][dj]) dfs(di, dj, w, h);
    }
  }
}

int main() {
  vector<int> ans;
  while (1) {
    int w, h;
    cin >> w >> h;
    if (w + h == 0) break;
    // vector<vector<int> > c(w, vector<int>(h));
    rep(i, h) rep(j, w) cin >> c[i][j];
    // cout << endl;
    // rep(i, h) {
    //   rep(j, w) printf("%d ", c[i][j]);
    //   cout << endl;
    // }
    int cnt = 0;
    rep(i, h) rep(j, w) {
      if (c[i][j] == 0) continue;
      cnt++;
      dfs(i, j, w, h);
      // rep(i, h) {
      //   rep(j, w) printf("%d ", c[i][j]);
      //   cout << endl;
      // }
    }
    ans.push_back(cnt);
  }
  for (int a : ans) cout << a << endl;
  return 0;
}


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

int pcnt(int x) {
    return __builtin_popcount(x);
}

int f(int x) {
    if (x == 0) return 0;
    return f(x%pcnt(x)) + 1;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        x[i] = s[i] - '0';
    }
    int pc = 0;
    for (int i = 0; i < n; i++) {
        pc += x[i];
    }
    vector<int> ans(n);
    for (int b = 0; b < 2; b++) {
        int npc = pc;
        if (b == 0) npc++; else npc--;
        if (npc <= 0) continue;
        int r0 = 0;
        for (int i = 0; i < n; i++) {
            r0 = (r0*2)%npc;
            r0 += x[i];
        }
        int k = 1;
        for (int i = n-1; i >= 0; i--) {
            if (x[i] == b) {
                int r = r0;
                if (b == 0) r = (r+k)%npc;
                else r = (r-k+npc)%npc;
                ans[i] = f(r) + 1;
            }
            k = (k*2)%npc;
        }
    }

    for (int i = 0; i < n; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 5220
from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]

count = 0
color = S[0][0]
Q1 = deque()
Q2 = deque()
if color == '#':
  count += 1
done = set((0, 0))

Q1.append((0, 0))

while True:
  while Q1:
    x, y = Q1.popleft()
    if x == W-1 and y == H-1:
      break
    for dx, dy in [(1, 0), (0, 1)]:
      if x+dx >= W or y+dy >= H:
        continue
      if (x+dx, y+dy) in done:
        continue
      done.add((x+dx, y+dy))
      if S[y+dy][x+dx] == color:
        Q1.append((x+dx, y+dy))
      else:
        Q2.append((x+dx, y+dy))
    else:
      continue
    break
  else:
    Q1, Q2 = Q2, Q1
    if color == '#':
      color = '.'
    else:
      color = '#'
      count += 1
    continue
  break

print(count)

Measured memory_bytes: 4456
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const arr = input.split(/\n/);
const numbers = arr[1].split(" ").map(Number);
let min = numbers[0];
let max = numbers[0];
let sum = 0;

numbers.forEach(number => {
  if(min > number) min = number;
  if(max < number) max = number;
  sum += number;
})

console.log(min + " " + max + " " + sum);




Measured memory_bytes: 18760
n, y = map(int, input().split())

q_10000, mod_10000 = divmod(y, 10000)
for i in range(q_10000, -1, -1):
    remaining_5000 = 10000 * (q_10000 - i) + mod_10000
    q_5000, mod_5000 = divmod(remaining_5000, 5000)
    for j in range(q_5000, -1, -1):
        remaining_1000 = 5000 * (q_5000 - j) + mod_5000
        q_1000 = remaining_1000 // 1000
        if i + j + q_1000 == n:
            print("{} {} {}".format(i, j, q_1000))
            exit()

print("-1 -1 -1")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
using namespace std;

int main(){
  int64_t n,m;
  cin >> n >> m;
  vector<bool> solved(n);
  vector<int64_t> penalty(n);
  rep(i,m){
    int64_t hoge;
    string judge;
    cin >> hoge >> judge;
    if(judge == "AC"){
      solved.at(hoge-1) = true;
    }else{
      if(!solved.at(hoge-1)){
        penalty.at(hoge-1)++;
      }
    } 
  }
  int64_t ACcount = 0;
  int64_t penaltysum = 0;
  rep(i,n){
    if(solved.at(i)){
      ACcount++;
      penaltysum += penalty.at(i);
    }
  }
  cout << ACcount << " " << penaltysum << endl;
    
      
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

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

    int n, k, c;
    cin >> n >> k >> c;
    bool s[n];
    for (int i = 0; i < n; i++) {
        char t;
        cin >> t;
        s[i] = t == 'o';
    }

    int dp1[n+1], dpma = 0;
    dp1[0] = -(c + 1);
    for (int i = 0; i < n; i++) {
        if (s[i] && i > dp1[dpma] + c) {
            dp1[++dpma] = i;
        }
    }

    int dp2[n+1];
    dpma = 0;
    dp2[0] = n + c;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] && i < dp2[dpma] - c) {
            dp2[++dpma] = i;
        }
    }

    for (int i = 1; i <= k; i++) {
        if (dp1[i] == dp2[k+1-i]) {
            cout << dp1[i] + 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3328
N,T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
ret = 0
# for ind in range (1, N):
#     ret += min(T,ts[ind]-ts[ind-1])
for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
    ret += T if T<diff else diff
print(ret+T)


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

#define MAXN 405
#define MAXK 1000000
#define int long long
#define LL long long
#define pii pair<long, long>
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;

int N;
int mod = 1e9+7;
int a[MAXN];
int sum[MAXN];
int dp[MAXN][MAXN];

signed main() {
    fastio;
    cin >> N;
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 1; i <= N; i++) cin >> a[i], dp[i][i] = 0, sum[i] = sum[i-1] + a[i];
    for (int len = 2; len <= N; len++) {
        for (int i = 1; i+len-1 <= N; i++) {
            int j = i+len-1;
            for (int k = i; k < j; k++) 
                dp[i][j] = min(dp[i][k] + dp[k+1][j] + sum[j] - sum[i-1], dp[i][j]);
        }
    }
    cout << dp[1][N] << endl;
    return 0;
}

Measured memory_bytes: 1536
package main

import (
	"fmt"
	"math"
)

var a, b string

func main() {
	fmt.Scan(&a, &b)
	if a == "H" {
		if b == "H" {
			fmt.Println("H")
		} else {
			fmt.Println("D")
		}
	} else {
		if b == "H" {
			fmt.Println("D")
		} else {
			fmt.Println("H")
		}
	}
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }
func ceil(x int) int      { return int(math.Ceil(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy []si

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].s < a[j].s }


Measured memory_bytes: 512
#include <stdio.h>

int main(){
	int x,y,d,tmp;

	scanf("%d %d",&x,&y);

	if(x<y){
		tmp=x;
		x=y;
		y=tmp;
	}

	while(y>0){
		d=x%y;
		x=y;
		y=d;
	}
	printf("%d\n",x);

	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
signed main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> d(m, vector<int>(m));
  vector<vector<int>> c(n, vector<int>(n));
  vector<vector<int>> a(3, vector<int>(m));
  vector<vector<int>> b(3, vector<int>(m));

  for (auto &&i : d)
    for (auto &&j : i) {
      cin >> j;
    }
  for (auto &&i : c)
    for (auto &&j : i) {
      cin >> j;
      j--;
    }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x = c[i][j];
      a[(i + j) % 3][x]++;
    }
  }
  int ans = inf, tmp;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m; k++) {
        if (i == j || j == k || k == i) continue;
        tmp = 0;
        for (int y = 0; y < m; y++) {
          tmp += a[0][y] * d[y][i];
          tmp += a[1][y] * d[y][j];
          tmp += a[2][y] * d[y][k];
        }
        ans = min(ans, tmp);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll A_max=0;
  ll A_max_i=0;
  rep(i, 0, N){
    cin >> A[i];
    if(A_max < A[i]){
      A_max = A[i];
      A_max_i = i;
    }
  }

  A[A_max_i] = A[N-1];
  A.pop_back();

  ll A_middle=0;
  ll A_middle_num=A_max;
  rep(i, 0, N){
    if(A_middle_num > abs((A_max/2)-A[i])){
      A_middle_num = abs((A_max/2)-A[i]);
      A_middle = A[i];
    }
  }

  cout << A_max << " " << A_middle << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, a, b;
    cin >> n >> a >> b;

    cout << min(b, a * n) << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

class Card
{
public:
	char c;
	int v;
};

int main()
{
	int n;
	Card origin[36];
	Card a[36],b[36];

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		origin[i].c = s[0];
		stringstream ss;
		ss << s[1];
		ss >> origin[i].v;
		a[i] = origin[i];
		b[i] = origin[i];
	}

	for (int i = 0; i < (n - 1); i++)
	{
		for (int j = n - 1; j != i; j--)
		{
			if (a[j].v < a[j - 1].v)
			{
				Card t = a[j];
				a[j] = a[j - 1];
				a[j - 1] = t;
			}
		}
	}

	for (int i = 0; i < (n - 1); i++)
	{
		int mini = i;
		for (int j = i + 1; j < n; j++)
		{
			if (b[j].v < b[mini].v)
			{
				mini = j;
			}
		}
		if (mini != i)
		{
			Card t = b[i];
			b[i] = b[mini];
			b[mini] = t;
		}
	}

	for (int i = 0; i < n; i++)
	{
		cout << a[i].c << a[i].v;
		if (i < (n - 1))
		{
			cout << " ";
		}
	}
	cout << endl;

	cout << "Stable" << endl;

	for (int i = 0; i < n; i++)
	{
		cout << b[i].c << b[i].v;
		if (i < (n - 1))
		{
			cout << " ";
		}
	}
	cout << endl;

	for (int i = 0; i < n; i++)
	{
		if (a[i].c != b[i].c)
		{
			cout << "Not stable" << endl;
			return 0;
		}
	}
	cout << "Stable" << endl;
}

Measured memory_bytes: 3144
{-# LANGUAGE BangPatterns #-}

import Data.Array (Array, listArray, accumArray, (!))
import Data.List (sortOn, sortBy)

solv xs = go xs [] 0 where
  go [] _ !n = n
  go !(x:xs) [] !n = go xs [x] n
  go !(x:xs) !(s:ss) !n
    | x==s = go xs (x:s:ss) n
    | x/=s = go xs ss (n+2)

main = do
  s <- getLine
  print $! solv s


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector <int> a(n),pre(n),suf(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i){
            pre[i]=__gcd(pre[i-1],a[i]);
        }
        else{
            pre[i]=a[i];
        }
    }
    suf[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        suf[i]=__gcd(suf[i+1],a[i]);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        int val=0;
        if(i){
            val=__gcd(val,pre[i-1]);
        }
        if(i<n-1){
            val=__gcd(val,suf[i+1]);
        }
        ans=max(ans,val);
    }
    cout << ans << endl;
    return 0;
}

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

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
*/

using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
const ll INF = 1e18;
const int mod = 1e9 + 7;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_NOde_update> 

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
	#ifdef LOCAL_TEST
	freopen("in.txt","r",stdin);
	//freopen("out.txt", "w", stdout);
	#else
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	#endif

	ll n,m;
	cin>>n>>m;
	vector<vector<int> > v(15);
	int p[15] = {0};
	for(int i=1;i<=m;i++)
	{
		int k;
		cin>>k;

		for(int j=1;j<=k;j++)
		{
			int q;
			cin>>q;
			v[i].pb(q);
		}
	}

	for(int i=1;i<=m;i++)
	{
		cin>>p[i];
	}
	int ans = 0;
	for(int i=0;i<(1<<n);i++)
	{
		int flag = 1;
		for(int j=1;j<=m;j++)
		{
			int count = 0;
			for(int w=0;w<v[j].size();w++)
			{
				int val = v[j][w] - 1;


				if((1<<val)&i)count++;
			}

			if(count%2 != p[j])
			{
				flag = 0;
			}
		}

		if(flag)ans++;
	}
	cout << ans << "\n";
	return 0;
}

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

void main()
{
  auto n = readln.chomp.to!ptrdiff_t;
  auto ai = readln.split.map!(to!int).array;

  writeln(ai.map!(to!string).join(" "));

  foreach (i; 1..n) {
    auto v = ai[i];
    auto j = i - 1;
    for (; j >= 0 && ai[j] > v; --j)
      ai[j + 1] = ai[j];
    ai[j + 1] = v;
    writeln(ai.map!(to!string).join(" "));
  }
}

Measured memory_bytes: 2572
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#n = int(input())
n, k = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

x = 0
y = 0
for i in range(1, k):
    x += i-1
    y += n-i+1

ans = 0
for i in range(k, n+2):
    x += (i-1)
    y += (n-i+1)
    ans += (y-x+1)
    ans = ans % (10**9+7)


print(ans)

    


Measured memory_bytes: 9420
<?php 
  $s = trim(fgets(STDIN));
  $t = trim(fgets(STDIN));
  $cnt = 0;
  $strlen = strlen($s);
  $a_s = str_split($s);
  $a_t =str_split($t);

  for($i = 0; $i < $strlen; $i++){
    if($a_s[$i] !== $a_t[$i])
        $cnt += 1;
  }

  echo $cnt;
  

Measured memory_bytes: 41416
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 500009
#define M6 2000009
#define M 1000000007
#define inf LLONG_MAX
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll fac[M6],not_prime[M6],ar[M6];
ll power(ll x,ll n)
{   if(n==0) return 1;
    else if(n%2 == 0) return power((x*x),n/2);
    else return (x*power((x*x),(n-1)/2));
}
void fact(){
    fac[0]=1;
    for(ll i=1;i<21;i++) fac[i]=(i*fac[i-1]);
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<M6;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=M6;i+=p) not_prime[i]=1;
        }
    }
}
ll modi(ll a, ll m){
    ll m0 = m, t, q; ll x0 = 0, x1 = 1;
    if (m == 1) return 0;
    while (a > 1){  q = a / m; t = m; m = a % m, a = t;t = x0;x0 = x1 - q * x0; x1 = t;}
    if (x1 < 0) x1 += m0;return x1;
}
int main(){
    buf; 
    //sieve(); 
    fact();
    ll i,j,k,test,flag,ans,n,p,m,t,a,b,c; string s1;
    //cin>>test;
    test=1;
    while(test--){
        cin>>n;
        ll p=1;
        for(i=1;i<=n;i++){
            cin>>ar[i];
            if(!(ar[i]&1)) p*=2;
        }
        cout<<power(3,n)-p;
    }
    return 0;
} 

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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = 1e6 + 7;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 5e1 + 5;

int A[N];
ll DP[N][N][N * N];

int main() {
 
	sync;

	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> A[i];

	for (int i = 1; i <= n; i++) {
		DP[i][1][A[i]] = 1;
		for (int j = 1; j <= i; j++) for (int k = 1; k < N * N; k++) 
			DP[i][j][k] += DP[i - 1][j][k] + (k >= A[i] ? DP[i - 1][j - 1][k - A[i]] : 0);
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) ans += DP[n][i][i * m];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 65792
MOD = 10 ** 9 + 7
N, M = gets.split.map(&:to_i)
L = N * M
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

counterA = Hash.new(0)
counterB = Hash.new(0)

A.each do |a|
  counterA[a] += 1
end

B.each do |b|
  counterB[b] += 1
end

if counterA.values.max > 1 || counterB.values.max > 1
  puts 0
else
  ans = 1
  cntB = 0
  cntA = 0

  L.downto(1) do |l|
    if counterA[l] > 0 && counterB[l] == 0
      ans *= cntB
    elsif counterA[l] == 0 && counterB[l] > 0
      ans *= cntA
    elsif counterA[l] == 0 && counterB[l] == 0
      ans *= cntA * cntB - (L - l)
    end

    cntA += 1 if counterA[l] > 0
    cntB += 1 if counterB[l] > 0
    ans %= MOD
  end

  puts ans
end


Measured memory_bytes: 3836
n = tonumber(io.read())
s = io.read()

t = {{}, {}, {}}

cnt = 0

for i = n, 1, -1 do
    cur = s:sub(i, i)
    for v in pairs(t[2]) do
        if not t[3][cur .. v] then cnt = cnt + 1 end
        t[3][cur .. v] = true
    end
    for v in pairs(t[1]) do
        t[2][cur .. v] = true
    end
    t[1][cur] = true
end

print(cnt)

Measured memory_bytes: 760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net.Mail;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }


    class Program
    {
        private int N;
        private int[] P;
        public void Solve()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            P = new int[N];
            for (int i = 0; i < N; i++)
            {
                P[i] = sc.NextInt() - 1;
            }
            var index = new int[N];
            for (int i = 0; i < N; i++)
            {
                index[P[i]] = i;
            }
            var dp = new int[N];
            for (int i = 0; i < N; i++)
            {
                if (P[i] == 0)
                {
                    dp[i] = 1;
                    continue;
                }
                dp[i] = dp[index[P[i] - 1]] + 1;
            }
            Console.WriteLine(N - dp.Max());
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 17472
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b;
    cin >> a >> b;
    bool f = a > 9 || b > 9;
    cout << (f ? -1 : a * b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ

int64_t func(int64_t num, int64_t x) {
  if (num == -1) return 0;
  return num / x + 1;
}
 
int main(){
    int64_t a,b,x;
    cin>>a>>b>>x;
    int64_t ans=(b-a)/x;
    if(a%x==0||b%x==0){
        ans++;
    }
    //cout<<ans<<endl;
    cout<<func(b,x)-func(a-1,x)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;
bool ans[3][3];

int main() {
    int num, N;
    map<int, pair<int, int> > m;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> num;
            m.insert(make_pair(num, make_pair(i, j)));
        }
    }
    int b;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> b;
        if (m.count(b)) {
            ans[m[b].first][m[b].second] = 1;
        }
    }
    for (int i = 0; i < 3; i++) {
        int sum = ans[i][0] && ans[i][1] && ans[i][2];
        if (sum) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 3; i++) {
        int sum = ans[0][i] && ans[1][i] && ans[2][i];
        if (sum) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    int sum = ans[0][0] && ans[1][1] && ans[2][2];
    if (sum) {
        cout << "Yes" << endl;
        return 0;
    }
    sum = ans[0][2] && ans[1][1] && ans[2][0];
    if (sum) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = [int(_) for _ in input().split()]

MOD = 10**9+7

def primes(n):
    from math import sqrt
    mn = int(sqrt(n)) + 2
    p = [1] * mn
    for x in range(2, mn):
        if p[x]:
            y = x * x
            while y < mn:
                p[y] = 0
                y += x
    return (i for i in range(2, mn) if p[i])

def calc(M):
    result = {}
    for n in primes(M):
        if M % n == 0:
            result[n] = 1
            M //= n
        while M % n == 0:
            result[n] += 1
            M //= n
    if M > 1:
        result[M] = 1
    return result

def C(x, y):
    n = min(y, x - y)
    r = 1
    for i in range(n):
        r = r * (x - i)
    for i in range(n):
        r = r // (i + 1)
    return r

cs = calc(M)

result = 1

for x in cs.values():
    result = result * C(N+x-1, N-1) % MOD

print(result)


Measured memory_bytes: 3316
s = input()
ue = int(s[:2])
sita = int(s[2:4])
if ue < 1 or ue > 12:
    if 1 <= sita <= 12:
        print('YYMM')
    if sita < 1 or sita > 12:
        print('NA')
elif sita < 1 or sita > 12:
    print('MMYY')
else:
    print('AMBIGUOUS')


Measured memory_bytes: 3060