akhauriyash/Code-Regression huggingface dataset:
import java.util.HashMap;
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
		
		for(int i=0;i<N;i++)
		{
			int tmp=sc.nextInt();
			if(map.containsKey(tmp))
			{
				map.put(tmp, map.get(tmp)+1);
			}
			else
			{
				map.put(tmp, 1);
			}

		}
				
		int M = sc.nextInt();
		int ti[]=new int[M];
		for(int i=0;i<M;i++)
		{
			ti[i]=sc.nextInt();
		}
		sc.close();
		
		/*判定*/
		boolean flg=true;
		for(int i=0;i<M;i++)
		{
			if(map.containsKey(ti[i]))
			{
				if(map.get(ti[i])>0)
				{
					map.put(ti[i], map.get(ti[i])-1);
				}
				else
				{
					flg=false;
					break;
				}
			}
			else
			{
				flg=false;
				break;
			}
		}
		
		String ans = flg? "YES":"NO"; 
		System.out.println(ans);

		
	}
	
	class D_i
	{
		int count =0;
	}


}



Measured memory_bytes: 143780
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int a[3*n];
    rep(i, 3*n) {
        cin >> a[i];
    }
    ll ans = 0;
    sort(a, a+3*n);

    for(int i = n; i < 3*n; i += 2) {
        ans += (ll)a[i];
    }

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
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;}

vector<int>g[100010];
vector<int> a;
int s ;
int flg = 0;

int dfs(int now,int par){
		int ret = 0;
		if(g[now].size()==1&&par!=-1)return a[now];
		int cnt = 0,ma = -1;
		for(auto e:g[now]){
			if(par == e)continue;
			int t = dfs(e,now);
			ret += t;
			CHMAX(ma,t);
			cnt++;
		}
		if(par == -1){
			return ret == a[now];
		}
		if(cnt == 1){
			if(ret != a[now]){
				flg = true;
				return 0;
			}
			else return a[now];
		}else{
			if(2 * a[now] - ret < 0)flg = true;
			if(a[now]>ret)flg = true;
			if(a[now]<ma)flg = true;
			return 2 * a[now] - ret;
		}
	};

signed main(){
	int N;
	cin>>N;
	a.resize(N);
	for(auto& e:a)cin >> e;
	vector<int>cnt(N,0);
	REP(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
		cnt[a]++;
		cnt[b]++;
	}
	
	REP(i,N){
		if(cnt[i] == 1)s = i;
	}
	if(dfs(s,-1)){
		if(flg){
			cout<<"NO"<<endl;
			return 0;
		}
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}

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

using namespace std;

int main(){
	long long int N;
	cin >> N;
	vector<long long int>A(N);
	long long int sum = 0;
	for( int i = 0; i < N; i++ ){
		cin >> A[i];
		A[i] -= i;
		sum += A[i];
	}
	auto B = A;
	sort(A.begin(), A.end());
	long long int ans = 0;
	for( size_t i = 0; i < N; i++ ){
		ans += abs(B[i] - A[N / 2]);
	}
	cout << ans << endl;
}

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

#define endl '\n'
using namespace std;
using ll = long long;

const int N = 16;
const ll INF = 1ll<<60;
int n;
ll arr[N][N];
ll points[(1<<N)];
ll dp[(1<<N)];

void init();
void process();

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    init();
    process();
    cout.flush();
    return 0;
}

void init()
{
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> arr[i][j];
    vector<int> ones;
    for(int mask = 0; mask < (1<<n); mask++)
    {
        ones.clear();
        for(int i = 0; i < n; i++)
            if((mask>>i)&1) ones.emplace_back(i);
        for(int i = 0; i < ones.size(); i++)
            for(int j = i+1; j < ones.size(); j++)
                points[mask] += arr[ones[i]][ones[j]];
    }
}

/*
ll f(int mask)
{
    if(dp[mask] != -INF) return dp[mask];
    // mask => group1 | group2
    // dp[mask] = max(dp[group1] + points[group2])
    vector<int> ones;
    for(int i = 0; i < n; i++)
        if((mask>>i)&1) ones.emplace_back(i);
    for(int m = 1; m < (1<<ones.size()); m++)
    {
        int group2 = 0;
        for(int i = 0; i < ones.size(); i++)
            if((m>>i)&1) group2 |= (1<<ones[i]);
        int group1 = mask ^ group2;
        dp[mask] = max(dp[mask], f(group1) + points[group2]);
    }
    return dp[mask];
}
*/

void process()
{
    vector<int> ones;
    for(int mask = 0; mask < (1<<n); mask++)
    {
        ones.clear();
        for(int i = 0; i < n; i++)
            if((mask>>i)&1) ones.emplace_back(i);
        for(int m = 1; m < (1<<ones.size()); m++)
        {
            int group2 = 0;
            for(int i = 0; i < ones.size(); i++)
                if((m>>i)&1) group2 |= (1<<ones[i]);
            int group1 = mask ^ group2;
            dp[mask] = max(dp[mask], dp[group1] + points[group2]);
        }
    }
    cout << dp[(1<<n)-1] << endl;
}



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;

    int ans = 0;
    int now = 0;
    for (auto c: S) {
        if (c == 'A' || c == 'C' || c == 'G' || c == 'T') now++;
        else now = 0;

        chmax(ans, now);
    }

    cout << ans << endl;
}


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

ans = 0
for i in range(len(s)):
    cnt = 0
    if i + len(t) - 1 >= len(s):
        break
    for j in range(len(t)):
        if s[i+j] == t[j]:
            cnt += 1
    ans = max(ans, cnt)
print(len(t) - ans)

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int MOD = (int)1e9 + 7, MAXN = (int)1e5 + 10;
int n;
VI A;

int mul(int a, int b) {
	return (1ll * a * b) % MOD;
}

int sub(int a, int b) {
	a -= b;
	return a < 0 ? a + MOD : a;
}


int fact[MAXN], finv[MAXN], inv[MAXN];
void precalc()
{
	fact[0] = fact[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(LL i = 2; i < MAXN; ++i) {
		inv[i] = sub(MOD, mul(inv[MOD % i], MOD / i));
		fact[i] = mul(fact[i - 1], i % MOD);
		finv[i] = mul(finv[i - 1], inv[i]);
	}
}

int comb(int n, int r)
{
	if(n < r) return 0;
	return mul(fact[n], mul(finv[r], finv[n - r]));
}

void solve()
{
	precalc();

	int dist;
	VI pos(MAXN + 1, -1);
	for(int i = 0; i < n + 1; ++i) {
		if(pos[A[i]] != -1) {
			dist = i - pos[A[i]];
			break;
		}
		pos[A[i]] = i;
	}
	
	for(int len = 1; len <= n + 1; ++len) {
		int whole = comb(n + 1, len), remain = comb(n - dist, len - 1);
		cout << sub(whole, remain) << '\n';
	}
	cout << flush;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    cin >> n;

	A = VI(n + 1, 0);
	REP(i, 0, n + 1) cin >> A[i];

	solve(); 

	return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

  string s;
  cin >> s;
  
  char c = s[0];
  int n = s.size();
  int k = n;
  REP(i,n-1){
    if(s[i+1] != c) k = min(k,max(i+1,n-i-1));
    c = s[i+1];
  }
  
  cout << k << endl;

 return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, K;
long long L[1 << 18];

long long solve(long long r) {
	if (r == 0) return (1LL << 60);

	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += (L[i] - 1LL) / r;
	}
	return ans;
}

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> L[i];

	int cl = 0, cr = (1 << 30), cm, minx = (1 << 30);
	for (int i = 0; i < 34; i++) {
		cm = (cl + cr) / 2;
		if (solve(cm) <= K) { minx = min(minx, cm); cr = cm; }
		else { cl = cm; }
	}
	cout << minx << endl;
	return 0;
}

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

int main()
{
    string ai,bi;
    cin>>ai>>bi;
    int len = ai.size();
    int flag = 0;
    for(int j=0;j<len;j++)
    {
        char d = ai[len-1];
        for(int i=len-1;i>=1;i--)
        {
            ai[i] = ai[i-1];
        }
        ai[0] = d;// cout<<ai<<endl;
        if(ai==bi){
            flag = 1;
            break;
        }

    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}
/*
4
128 4 340
*/


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

long long X,D,N,Y,ans,i,j,k;

int main()
{
  cin>>N>>D;
  ans=0;
  
  for(i=0;i<N;i++)
  {
    cin>>X>>Y;
    if(X*X+Y*Y<=D*D) ans++;
  }
  
  cout<<ans;
}



Measured memory_bytes: 3552
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int[] dis=new int[3];
    for(int i=0;i<3;i++){
      dis[i]=sc.nextInt();
    }
    int d=sc.nextInt();
    if(Math.abs(dis[2]-dis[0])<=d){
      System.out.println("Yes");
    }else if(Math.abs(dis[1]-dis[0])<=d && Math.abs(dis[2]-dis[1])<=d){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22868
import std.stdio, std.string, std.array, std.conv, std.algorithm.iteration, std.functional;

void main()
{
    auto abcd = readln.split.to!(long[]);
    auto ab = abcd[0] * abcd[1];
    auto cd = abcd[2] * abcd[3];

    writeln( ab > cd ? ab : cd );
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	long int result;
	char op;

	while (scanf("%d%*c%c%d", &a, &op, &b) != -1 && op != '?'){
		switch (op){
		case '+':
			result = a + b;
			break;
		case '-':
			result = a - b;
			break;
		case '*':
			result = a * b;
			break;
		case '/':
			result = a / b;
			break;
		default:
			puts("shit");
			result = 0;
			break;
		}
		printf("%ld\n", result);
	}
	return 0;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int n,h,w;
  cin>>n>>h>>w;
  cout<<(n-w+1)*(n-h+1)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef pair < int , int > Pi;
bool data[5001][5001];
bool isOK(int x,int y){
  return x >= 0 && x < 5001 && y >= 0 && y < 5001 && data[x][y];
}
int main(){
  int n;
  Pi p[3000];
  while(cin >> n , n){
    fill_n( *data, 5001 * 5001 , false);
    for(int i = 0 ; i < n ; i++ ){
      cin >> p[i].first >> p[i].second;
      data[p[i].first][p[i].second] = true;
    }
    int ret = 0;
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < i ; j++ ){
        int x = p[j].first - p[i].first;
        int y = p[j].second - p[i].second;
        if(isOK(p[i].first + y,p[i].second - x) & isOK(p[j].first + y,p[j].second - x))
          ret = max( ret, x * x + y * y);
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 25604
#![allow(unused_imports, unused_macros, dead_code, bare_trait_objects)]

macro_rules! get{
    ($t:ty) => {
        {
            let cin = stdin();
            let mut cin = cin.lock();
            
            let token =
                cin.by_ref().bytes().map(|c| c.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect::<String>();

            try!(token.parse::<$t>())
        }
    }
}

macro_rules! input{
    ($($id:ident: $t:ty),*) => {
        $(
            let $id = get!($t);
        )*;
    }
}

macro_rules! input_vec{
    ($id:ident: Vec<$t:ty>, $n:expr) => {
        let n = $n;
        let mut $id: Vec<$t> = Vec::with_capacity(n);
        for _ in 0..n {
            let temp = get!($t);
            $id.push(temp);
        }
    }
}

use std::io::{Read,stdin};
use std::str::*;
use std::error::Error;
use std::fmt::Debug;
use std::ops::*;
use std::cmp::*;


fn main(){
    while let Ok(_) = solve() {}
}

fn solve() -> Result<(),Box<std::error::Error>>{

    input!(n: usize);

    let mut a = vec![0; n];
    let mut b = vec![0; n];

    for i in 0..n {
        input!(x: u64, y: u64);

        a[i] = x;
        b[i] = y;
    }

    if a == b {
        println!("{}", 0);
    } else {
        let mut ans: u64 = a.iter().sum();

        let mut m = std::u64::MAX;
        
        for i in 0..n {
            if a[i] > b[i] {
                m = std::cmp::min(m, b[i]);
            }
        }

        ans -= m;
        
        println!("{}", ans);
    }

    Ok(())
}


Measured memory_bytes: 4352
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr, sort)
import Control.Monad
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS
import Data.Monoid

sub :: (Int, Int) -> (Int, Int) -> (Int, Int)
sub (x,y) (x',y') = (x-x',y-y')

main = do
  n <- readLn
  -- n <= 100 なのでリストの sort を使うのでも十分速い
  -- (x,y) == (0,0) の場合は atan2 はよくわからない値になるかもしれないが、エラーにさえならなければソート結果のどこに入っていても問題ない
  xs <- fmap (U.fromListN n . sort) $ replicateM n $ do
    [x,y] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (atan2 (fromIntegral y) (fromIntegral x) :: Double, x, y)
  let neg = U.takeWhile (\(a,_,_) -> a <= 0) xs -- x軸の下にある部分
  let xs' = xs <> U.map (\(a,x,y) -> (a + 2 * pi, x, y)) neg -- 1週半させる
  let ys = U.scanl' (\(!sx,!sy) (_,x,y) -> (sx+x,sy+y)) (0,0) xs'
  let zs = [ (ys U.! (j+1)) `sub` (ys U.! i) | i <- [0..n-1], j <- [i..min (i+n-1) (U.length xs' - 1)]]
  print $ maximum $ map (\(x,y) -> sqrt ((fromIntegral x)^2 + (fromIntegral y)^2)) zs


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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if ((x - r) < 0 || (x + r) > W || (y - r) < 0 || (y + r) > H) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  if(n == 3) {
    cout << "2 5 63" << endl;
    return 0;
  } else if(n == 4) {
    cout << "2 5 20 63" << endl;
    return 0;
  } else if(n == 5) {
    cout << "2 5 20 63 30" << endl;
    return 0;
  }
  vector<int> ans;
  bool odd = n%2 == 1;
  if(odd) n++;
  ans.push_back(2);
  ans.push_back(4);
  ans.push_back(3);
  ans.push_back(6);
  ans.push_back(9);
  ans.push_back(12);
  n -= 6;
  int now2 = 8, now3 = 15;
  int a = n / 8, b = n % 8;
  for(int i=0;i<a;++i) {
    for(int j=0;j<4;++j) {
      ans.push_back(now2);
      now2 += 2;
      if(now2 % 3 == 0) now2 += 2;
    }
    for(int j=0;j<4;++j) {
      ans.push_back(now3);
      now3 += 3;
    }
  }
  if(odd) ans.pop_back();
  switch(b) {
    case 0:
    break;
    case 2:
      ans.push_back(now2);
      if((now2 + 2) % 3) ans.push_back(now2 + 2);
      else ans.push_back(now2 + 4);
    break;
    case 4:
      ans.push_back(now3);
      ans.push_back(now3 + 3);
      ans.push_back(now3 + 6);
      ans.push_back(now3 + 9);
    break;
    case 6:
      ans.push_back(now2);
      if((now2 + 2) % 3) ans.push_back(now2 + 2);
      else ans.push_back(now2 + 4);
      ans.push_back(now3);
      ans.push_back(now3 + 3);
      ans.push_back(now3 + 6);
      ans.push_back(now3 + 9);
    break;
    default:
    assert(false);
    break;
  }
  printv(ans);
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,p="CODEFESTIVAL2016";
  cin>>s;long long i,m=0;
  for(i=0;i<16;i++){
      if(p[i]!=s[i])
      m++;
  }
cout<<m;
  return 0;
  
}


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

using namespace std;

typedef long long ll;

int main()
{
  int sec = 0;
  fscanf(stdin, "%d", &sec);
  int h = sec / 3600;
  sec %= 3600;
  int m = sec / 60;
  int s = sec % 60;
  fprintf(stdout, "%d:%d:%d", h, m, s);
  fprintf(stdout, "\n");
  return 0;
}

Measured memory_bytes: 1192
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <numeric>

using namespace std;

typedef long long int lo;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define inf (lo)1e9
#define N (lo)1e5 * 5
#define all(x) (x).begin(), (x).end()
#define ii pair<lo,lo>
#define iii pair<lo, pair<lo,lo> >
#define si pair<string,lo>
#define vi vector <lo> 
#define vii vector <ii> 

int main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0);
    lo a,b,n;
    cin >> a >> b >> n;
    if(n == b){
	n--;
	cout << (a * n / b) - a * (n / b) << endl;
	return 0;
    }
    if(n > b){
	n = b - 1;
	cout << (a * n / b) - a * (n / b) << endl;
    }
    else{
	cout << (a * n / b) - a * (n / b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
int main(void){
  int i,j,num,cnt,sum=0;
  scanf("%d",&num);
  for(i=1;i<=num;i+=2){
    cnt=0;
    for(j=i;j>0;j-=2){
      if(i%j==0){
        cnt++;
      }
    }
    if(cnt==8){
      sum++;
    }
  }
  printf("%d",sum);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

int main()
{
	int N;
	int X;
	int tmp;
	int total = 0;
	int min = 2147483647;
	int minP = 1;

	std::cin >> N;
	std::vector<int> arr;

	for (int i = 0; i < N; i++)
	{
		std::cin >> tmp;
		arr.push_back(tmp);
	}

	for (int P = 1; P <= 100; P++)
	{
		total = 0;
		for (auto n : arr)
		{
			total += (n - P) * (n - P);
		}
		if (total < min)
		{
			min = total;
			minP = P;
		}
	}
	
	std::cout << min;

	return 0;
}

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

int N;
vector<long long> A;
vector<long long> sum;

int main() {
    cin >> N; 
    A.resize(N); sum.resize(N+1); sum[0] = 0;
    for (int i = 0; i < N; ++i) cin >> A[i], sum[i+1] = sum[i] + A[i];

    long long res = 1LL<<60;
    for (int i = 0; i <= N; ++i) {
        // P < Q となる最大の切れ目を求める: 二分探索を終えた時の left_low
        int low = 0, high = i;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] >= sum[i] - sum[mid]) high = mid;
            else low = mid;
        }
        long long P = sum[low], Q = sum[i] - sum[low]; // 候補1
        long long P2 = sum[high], Q2 = sum[i] - sum[high]; // 候補2
        long long left_min = min(P, Q), left_max = max(P, Q);
        if (abs(P2-Q2) < abs(P-Q)) left_min = min(P2, Q2), left_max = max(P2, Q2);

        // R < S となる最大の切れ目を求める
        low = i, high = N;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (sum[mid] - sum[i] >= sum[N] - sum[mid]) high = mid;
            else low = mid;
        }
        long long R = sum[low] - sum[i], S = sum[N] - sum[low]; // 候補1
        long long R2 = sum[high] - sum[i], S2 = sum[N] - sum[high]; // 候補2
        long long right_min = min(R, S), right_max = max(R, S);
        if (abs(R2-S2) < abs(R-S)) right_min = min(R2, S2), right_max = max(R2, S2);

        // 真ん中の切れ目が i であるときの暫定解
        long long tmp = max(left_max, right_max) - min(left_min, right_min);
        res = min(res, tmp);
    }
    cout << res << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    int mat[11][11] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	cin >>mat[i][j];
      }
    }
    int k = 0;
    for(int i=0; i<n; i++){
      int s = 0, m = 0;
      for(int j=0; j<n; j++){
	s+=mat[i][j];
	m+=mat[j][i];
      }
      mat[i][n] = s;
      mat[n][i] = m;
      k+=s;
    }
    mat[n][n] = k;
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
	printf("%5d",mat[i][j]);
      }
      cout <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1192
#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>;

const ll mod = 1000000007;
const double eps = 1e-8;

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    vector<vector<int>> to(N);
    for (int i=0; i<N-1; ++i) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
        to[v].push_back(u);
    }

    vector<int> ans(N, 0);
    vector<int> lis;

    function<void(int,int)> dfs = [&](int u, int par) {
        auto it = lower_bound(lis.begin(), lis.end(), a[u]);

        // dump
        tuple<bool,int,int> dump; // pop, pos, val
        if (it == lis.end()) {
            dump = make_tuple(true, -1, -1);
            lis.push_back(a[u]);
        } else {
            dump = make_tuple(false, it-lis.begin(), *it);
            *it = a[u];
        }

        ans[u] = max(ans[u], (int)lis.size());
        for (int v: to[u]) {
            if (v == par) continue;
            dfs(v, u);
        }

        // revert
        bool pop; int pos, val;
        tie(pop, pos, val) = dump;
        if (pop) lis.pop_back();
        else lis[pos] = val;
    };
    dfs(0, -1);

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

    return 0;
}

Measured memory_bytes: 32996
import sys

n = input()

for i in range(1,n+1):
    x = i
    y = i
    flag = 0
    if(x % 3 == 0):
        flag = 1
        sys.stdout.write(" ")
        sys.stdout.write(str(x))
        if(i+1 > n):
            break

    while(1):
        if flag == 1:
            break
        if(y % 10 == 3):
            sys.stdout.write(" ")
            sys.stdout.write(str(x))
            break
            if(i+1 > n):
                break
        y = y/10
        if(y == 0):
            break
print

Measured memory_bytes: 4520
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		boolean ret = new Main().Akihabara(sc.next());
		if(ret) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
	public boolean Akihabara(String str) {
		Pattern ptn = Pattern.compile("^A?(KIH)A?(B)A?(R)A?$");
		Matcher mtc = ptn.matcher(str);
		return mtc.find();
	}

}


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


int main(){
    int n;
    cin >> n;
    
    vector<int> p(n), q(n), v(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 0; i < n; i++) cin >> q[i];
    for (int i = 0; i < n; i++) v[i] = i+1;
    
    map<vector<int>, int> mp;
    
    int i = 0;
    
    do{
        mp[v] = i;
        i++;
    }while(next_permutation(v.begin(), v.end()));
    
    int ans = abs(mp[p] - mp[q]);
    
    cout << ans << endl;
}

Measured memory_bytes: 5248
//Grouping2.java
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        
        int ans=0;
        if(n<3){
            System.out.println('0');
        }
        else{
            for(int i=0;i<n;i++){
                int sum=n-3*(i+1);
                ans++;
                if(sum<3){
                    break;
                }
            }
            System.out.println(ans);
        }      
        sc.close();
    }
}

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

using namespace std;

int main()
{
  int N;
  long T;
  cin >> N >> T;
  long total = T;
  long last = T;
  for (int i = 0; i < N; ++i) {
    long ti;
    cin >> ti;
    if (ti == 0) continue;
    long t = ti + T;
    if (ti < last) {
      if (t < last) continue;
      total += t - last;
    } else {
      total += T;
    }
    last = t;
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {

    ll a, b, c, d;
    cin >> a >> b >> c;
    d = c - a - b;

    if (d > 0 && d * d > 4 * a * b) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define mt make_tuple

int n;
ll d[303][303], sum=0;
bool ans;


int main(){
cin >> n;
rep(i, 1, n){
rep(j,1,n){
cin >> d[i][j];
sum+=d[i][j];
}
}

rep(k, 1, n){
rep(i, 1, n){
rep(j, 1, n){
if(d[i][j]>d[i][k]+d[k][j])ans=true;
}
}
}
if(ans)return 0*printf("%d", -1);


rep(i, 1, n){
rep(j, 1, n){
ans=false;
rep(k, 1, n){
if(d[i][k]+d[k][j]==d[i][j] && i!=k && j !=k)ans=true;
}
if(ans)sum-=d[i][j];
}
}



cout << sum/2 << endl;

return 0;}


Measured memory_bytes: 1024
//This is getting accepted!
#include<bits/stdc++.h>
#define ll long long
#define oo 1000000009
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define INARR(a,n) for (int i = 1; i <= (n); ++i) cin >> a[i];
#define ITE(x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define isset(x, i) (((x)>>(i))&1)
#define setbit(x, i) ((x)^(1ll<<(i)))
#define clearbit(x, i) ((x)&(~(1ll<<(i))))
#define twoexp(i) (1ll<<(i))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define FI first
#define SE second
#define son1 (id*2)
#define son2 (id*2+1)

using namespace std;

const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 1e6 + 6;

int n;
int a[MAXN];

void input() {
	int u, v, w, x, y, qtype;
	
	cin >> n;
	INARR(a, n);
	
}


void preprocess() {
	
	
	
}

void process(int itest) {
	int u, v, w, x, y, qtype;
	
	FOR(i, 1, n) {
		if (a[i] > a[i-1]) {
			a[i]--;
		}
		else if (a[i] == a[i-1]) {
			
		}
		else {
			cout << "No\n";
			return;
		}
	}
	
	cout << "Yes\n";
	
}

void oneTest() {
	
	input();
	preprocess();
	process(0);
	
}

void multiTest() {
	
	int t;
	cin >> t;
	
	for (int it = 1; it <= t; ++it) {
		input();
		preprocess();
		process(it);
	}
}

int main(){
    #ifndef ONLINE_JUDGE
//    freopen("../out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	oneTest();
//	multiTest();

    return 0;

}


Measured memory_bytes: 640
n = int(input())
l = list(map(int, input().split()))

ans = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if l[i] == l[j]:
            continue
        for k in range(j + 1, n):
            if l[i] == l[k] or l[j] == l[k]:
                continue
            max_l = max(l[i], l[j], l[k])
            judge = (l[i] + l[j] + l[k] - max_l) - max_l
            if judge > 0:
                ans += 1

print(ans)



Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int n,k;
	cin>>k>>n;
	vector<int> A(k);
	for(int i=0;i<k;i++)
	{
	    cin>>A[i];
	}
	vector<int> dp(n+1,0);
	for(int i=0;i<=n;i++)
	{
	    for(int j=0;j<k;j++)
	    {
	        if(A[j]<=i && !dp[i-A[j]])
	        {
	            dp[i]=1;
	        }
	    }
	}
// 	for(int i=0;i<=n;i++)
// 	{
// 	    cout<<dp[i]<<" ";
// 	}
	string sol=(dp[n]==1)?"First":"Second";
	cout<<sol;
}

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

int N;
string S;
int T[100001];

bool f(int a, int b) {
  T[0] = a, T[1] = b;
  for (int i=1; i<N; i++) {
    T[i+1] = T[i-1] ^ T[i] ^ (S[i] == 'x');
  }
  if (T[N] == T[0] && (T[0] ^ (S[0] == 'x')) == (T[N-1] ^ T[1])) {
    for (int i=0; i<N; i++) {
      if (T[i]) cout << 'W';
      else cout << 'S';
    }
    cout << "\n";
    return true;
  }
  return false;
}

int main() {
  cin >> N >> S;
  for (int a=0; a<=1; a++) {
    for (int b=0; b<=1; b++) {
      if (f(a, b)) return 0;
    }
  }
  cout << "-1\n";
  return 0;
}


Measured memory_bytes: 896
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-02-18 03:47:02
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

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

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  string s; cin >> s;
  int n = s.size();

  int64 ans = 0;

  int pos = 0;
  string t = "";
  while (pos < n) {
    if (s.substr(pos, 2) == "BC") {
      t += '$';
      pos += 2;
    } else {
      t += s[pos];
      ++pos;
    }
  }
  
  debug(t);

  int m = t.size();

  vector<int64> dp(m + 1, 0LL);

  for (int i = m - 2; i >= 0; --i) {
    if (t[i + 1] == '$') {
      dp[i] = dp[i + 1] + 1LL;
    } else if (t[i + 1] == 'A') {
      dp[i] = dp[i + 1];
    } else {
      dp[i] = 0LL;
    }
  }

  for (int i = 0; i < m; ++i) {
    if (t[i] == 'A') ans += dp[i];
  }

  debug(dp);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2452
n = gets.chomp.to_i
sp = {}
n.times do |i|
 s, p = gets.chomp.split(' ')
 sp[i+1] = [s, p.to_i]
end
sp = sp.to_a
sp.to_a.sort! do |a, b|
  (a[1][0] <=> b[1][0]).nonzero? || (b[1][1] <=> a[1][1])
end
sp.map{|e| puts e[0]}

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

int main(){
  int HP,AP;
  cin >> HP >> AP;
  int ans=0;
  for(int i=0; ; i++){
    HP = HP - AP;
    ans++; 
    if(HP <= 0)break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype = 'object')
mod = 10**9 + 7

sq_sum_a = sum(a)**2
sum_sq_a = sum(a**2)

sum_cross = (sq_sum_a - sum_sq_a) // 2
ans = sum_cross % mod
# xy = ((x + y)**2 - (x**2 + y**2)) // 2

print(ans)

Measured memory_bytes: 49684
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

s=input().rstrip()
q=int(input().rstrip())
qu=deque(s)
rev=0
for _ in range(q):
    que,*C=input().split()
    que=int(que)
    if que==2:
        f,c=C
        f=int(f)
        if f==1:
            if rev%2==0:
                qu.appendleft(c)
            else:
                qu.append(c)
        else:
            if rev%2==0:
                qu.append(c)
            else:
                qu.appendleft(c)
    else:
        rev+=1
print("".join(qu) if rev%2==0 else "".join(qu)[::-1])

Measured memory_bytes: 8564
#include<stdio.h>
int main(void)
{
	int a,b,n,i;
	for(i=0;i<4;i++){
		scanf("%d %d2",&a,&b);
		if(a==1)  n=b*6000;
		if(a==2)  n=b*4000;
		if(a==3)  n=b*3000;
		if(a==4)  n=b*2000;
		printf("%d\n",n);
	}
	return 0;
}

Measured memory_bytes: 2744
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

from collections import Counter

blue = Counter(S)
red = Counter(T)

point = []

for bkey in blue:
    if bkey in red:
        point.append(blue[bkey] - red[bkey])
    else:
        point.append(blue[bkey])
        
print(max(point) if max(point) > 0 else 0)

Measured memory_bytes: 3316
# coding: utf-8
from collections import deque 

class Node:
    def __init__(self):
        self.id = -1
        self.k = -1
        self.depth = -1
        self.parent = -1
        self.type = 'root'
        self.end = False
        self.children = []
        
def find_root_id(nodes):
    i = 0
    rootid = -1
    while nodes[i].parent != -1:
        nodes[i]
        i += 1
    else:
        rootid = nodes[i].id
        return rootid
        
def set_depth(rootid, nodes):
    que = deque()
    depth = 0
    node = nodes[rootid]
    que = deque(node.children)
    for i in que:
        nodes[i].depth = depth + 1
    depth += 1
    
    while que:
        for i in xrange(len(que)):
            for child in nodes[que.popleft()].children:
                que.append(child)
        for j in que:
            nodes[j].depth = depth + 1
        depth += 1

n = int(raw_input())
nodes = []
for i in xrange(n):
    node = Node()
    ls =  map(int, raw_input().split())
    node.id = ls[0]
    node.k = ls[1]
    if node.k == 0:
        pass
    else:
        node.children = ls[2:]
    nodes.append(node)
    
nodes = sorted(nodes, key=lambda node:node.id)
for node in nodes:
    for child in node.children:
        nodes[child].parent = node.id
        
for node in nodes:
    if node.children == []:
        if node.parent != -1:
            node.type = 'leaf'
    else:
        if node.parent != -1:
            node.type = 'internal node'

rootid = find_root_id(nodes)
nodes[rootid].depth = 0
set_depth(rootid, nodes)
for node in nodes:
    print 'node %s: parent = %s, depth = %s, %s, %s'%(node.id, node.parent, node.depth, node.type, node.children)

Measured memory_bytes: 137172
def main():
    N = int(input())
    p = []
    for i in range(N):
        a, b = map(int, input().split())
        p.append(a)
    else:
        p.append(b)

    m = [[1e10]*(N+1) for _ in range(N+1)]
    for i in range(N+1):
        m[i][i] = 0

    for l in range(2, N+1):
        for i in range(1, N-l+2):
            j = i + l - 1

            m[i][j] = 1e10
            for k in range(i, j):
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j])

    print(m[1][N])


if __name__ == '__main__':
    main()



Measured memory_bytes: 5728
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mod 1000000007
#define INF 1e9+100
#define pii pair<int,int>
#define ppi pair<pii,int>
#define ff first
#define ss second
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define urs(r...)          typename decay<decltype(r)>::type
#define fi(i,n)                for(urs(n) i=0;i<n;i++)
#define re(i,n)               for(urs(n) i=1;i<=n;i++)
#define pb push_back
#define gap ' '
#define mx 300005
int diff[mx];
main()
{
	int i,j,n,m,k;
	int t;
	cin>>n>>k;
	int a[k+2];
	fi(i,k) cin>>a[i];
	a[k]=n;
	sort(a,a+k+1);
	for(i=1;i<k;i++)
	{
		diff[i]=a[i]-a[i-1];
	}
	diff[i]=a[k]-a[k-1]+a[0];
	sort(diff+1,diff+k+1);
	int sum=0;
	for(i=1;i<k;i++)
	{
		sum+=diff[i];
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;

    int res = 0;
    int num = 1;

    while(num < b){
        num += (a - 1);
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string s;
    while (N) {
        if (N % -2) {
            s += "1";
            N--;
        } else {
            s += "0";
        }
        N /= -2;
    }
    reverse(s.begin(), s.end());
    if (s.empty()) s = "0";
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static int root(int[] root, int i) {
    int r = root[i];
    if (r == i) {
      return r;
    } else {
      int r2 = root(root, r);
      root[i] = r2;
      return r2;
    }
  }

  public static void main(String[] args) {

    var sc = new Scanner(System.in);

    var n = sc.nextInt();
    var m = sc.nextInt();
    var k = sc.nextInt();

    var ab = new int[2 * m];
    for (int i = 0; i < m; i++) {
      var a = sc.nextInt() - 1;
      var b = sc.nextInt() - 1;
      ab[2 * i    ] = a;
      ab[2 * i + 1] = b;
    }

    var cd = new int[2 * k];
    for (int i = 0; i < k; i++) {
      var c = sc.nextInt() - 1;
      var d = sc.nextInt() - 1;
      cd[2 * i    ] = c;
      cd[2 * i + 1] = d;
    }

    var count = new int[n];
    var root = new int[n];
    var abcount = new int[n];
    for (int i = 0; i < n; i++) {
      count[i] = 1;
      root[i] = i;
    }
    for (int i = 0; i < m; i++) {
      int a = ab[2 * i    ];
      int b = ab[2 * i + 1];
      int ra = root(root, a);
      int rb = root(root, b);
      if (ra != rb) {
        if (ra > rb) {
          int t = rb;
          rb = ra;
          ra = t;
        }
        root[rb] = ra;
        count[ra] += count[rb];
      }
      abcount[a]++;
      abcount[b]++;
    }

    for (int i = 0; i < k; i++) {
      int c = cd[2 * i    ];
      int d = cd[2 * i + 1];
      int rc = root(root, c);
      int rd = root(root, d);
      if (rc == rd) {
        abcount[c]++;
        abcount[d]++;
      }
    }

    var answer = new int[n];
    for (int i = 0; i < n; i++) {
      int r = root(root, i);
      answer[i] = count[r] - abcount[i] - 1;
    }

    for (int i = 0; i < n; i++) {
      if (i > 0) {
        System.out.print(" ");
      }
      System.out.print(answer[i]);
    }
    System.out.print("\n");

  }
}


Measured memory_bytes: 60384
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

vector<pair<LL, LL>> prime_factorization(LL x) {
	assert(x > 0);
	vector<pair<LL, LL>> f;
	for(LL i = 2; i <= x; i++) {
		if(i * i > x) { i = x; }
		if(x % i == 0) {
			f.EB(i, 0);
			while(x % i == 0) { f.back().SE++; x /= i; }
		}
	}
	return f;
}

LL a, b;

int main() {
	cin >> a >> b;
	auto f = prime_factorization(gcd(a, b));
	
	cout << SI(f) + 1 << endl;
	
	return 0;
}


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

class AtCoder
{
    static AtCoder atCoder;
    public static void Main()
    {
        atCoder = new AtCoder();
        atCoder.Run();
    }

    static void staticMethod()
    {
        atCoder.Run();
    }

    void Run()
    {
        var line = System.Console.ReadLine();
        string[] inputs = line.Split();
        int cityNum = int.Parse(inputs[0]);
        int roadNum = int.Parse(inputs[1]);

        int[] cities = new int[cityNum];

        int start=0;
        int end=0;
        for(int i = 0; i < roadNum; i++)
        {
            line = System.Console.ReadLine();
            inputs = line.Split();
            start = int.Parse(inputs[0]);
            end = int.Parse(inputs[1]);
            cities[start-1]++;
            cities[end-1]++;
        }

        for(int i = 0; i < cityNum; i++)
        {
            System.Console.WriteLine(cities[i].ToString());
        }
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.6lf", sqrt(d));
}

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

#define mp                  make_pair
#define pb                  push_back
#define f                   first
#define s                   second
#define F                   first
#define S                   second
#define clr(a, b)           memset(a, b, sizeof(a))
#define fore(i, b, e)       for(ll i = b; i < e; i++)
#define forr(i, b, e)       for(ll i = b; i < e; i++)
#define forg(i, b, e,au)    for(ll i = b; i < e; i+=au)
using namespace std;


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

int main()
{
    string txt;
    cin>>txt;
    ll n;
    cin>>n;
    char ant;ll c=0,ans=0;
    int posiz=txt.size(),posder=0;

    forr(i,0,txt.size()){
        if (txt[0]==txt[i])  
            c++;
        else {
            posiz=i;
            break;
        }
    }
    if (c==txt.size())
    {
        ans=(txt.size())*n;
        cout<<ans/2<<endl;
        return 0;
    }
    ans+=c/2;
    int c1=0;
    for(int i=txt.size()-1;i>=0;i--)
    {
        if (txt[0]==txt[i])
            c1++;
        else{ 
            posder=i;
            break;
        }
    }
    ans+=c1/2;
    c+=c1;
    ans+=ll(c/2)*(n-1);
    //cout<<ans<<endl;
    ant='$';
    c=1;ll resp=0;
    //cout<<posiz<<' '<<posder<<endl;
    forr(i,posiz,posder+1)
    {
        if (txt[i]==ant)
            c++;
        else
        {
            resp+=c/2;
            c=1;
        }
        ant=txt[i];
        //cout<<c<<" ";
    }
    resp+=c/2;
    ans+=resp*(n);
    cout<<ans<<endl;

}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  ll a[100009],b[100009];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  ll now=0;
  for(int i=n-1;i>=0;i--){
    a[i]+=now;
    ll temp=a[i]%b[i];
    if(temp!=0){
      now+=b[i]-a[i]%b[i];
    }
  }
  cout<<now<<endl;
  return(0);
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <climits>
using namespace std;

#define N 8 //メリーゴーランドの台数

int M[N] = {4, 1, 4, 1, 2, 1, 2, 1};
int check_M[N] = {41412121, 14121214, 41212141, 12121414, 21214141,12141412, 21414121, 14141212};

int main(void) {
	int p[N]; //客の人数
	int min; //乗り損ねた客の最小人数
	
	while(cin >> p[0]) {
		for(int i = 1; i < N; ++i) {
			cin >> p[i];
		}
		
		int ans; //p[0]の客が乗るメリーゴーランドの番号
		min = INT_MAX;
		
		for(int i = 0; i < N; ++i) { //p[0]の客が乗るメリーゴーランドをM[i]とする
		int n = 0;
			for(int j = 0; j < N; ++j) {
				if(M[(i + j) % N] < p[j % N]) {
					n += p[j % N] - M[(i + j) % N];
				}
			}
			if(n < min) {
				min = n;
				ans = i;
			} else if(n == min) {
				if(check_M[i] < check_M[ans]) ans = i;
			}
		}
		
		cout << M[ans % N];
		for(int i = 1; i < N; ++i) {
			cout << ' ' << M[(ans + i) % N];
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;

long li(long a, long b) {
    if (a > b) return li(b, a);
    if (b % a == 0) return a * (2 * b / a - 1);
    return b / a * 2 * a + li(b % a, a);
}

int main() {
    long n, x;
    cin >> n >> x;
    
    cout << n + li(n - x, x) << endl;
}


Measured memory_bytes: 256