akhauriyash/Code-Regression huggingface dataset:
n=int(input())
sum=0

if n%2==0:
    flag=int(n/2)
    for i in range(flag):
        sum=sum+(n+1)
else:
    flag=int((n-1)/2)
    for i in range(flag):
        sum=sum+(n+1)
    sum=sum+((n+1)/2)

print(int(sum))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
int n,a,dp[15][2]={};
	
int main(){
	cin >> n;
	dp[0][1]=1;
	REP(i,0,n){
		cin >> a;
		if(a%2){
			dp[i+1][0]=dp[i][0]*3+dp[i][1]*2;
			dp[i+1][1]=dp[i][1];
		}else{
			dp[i+1][0]=dp[i][0]*3+dp[i][1]*1;
			dp[i+1][1]=dp[i][1]*2;
		}
	}
	
	cout << dp[n][0] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define debug(s, param) std::cerr << s << param << std::endl;

using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  int sum = 0;
  rep (i, (int)s.size()) {
    if (s[i] == '0') continue;
    sum += (stoi(to_string(s[i])) - 48);
  }
  cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3804
# -*- coding: utf-8 -*-

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

'''
方針
N/3から2N/3まで動かして、その時の差分の最大値を返す
前半では、要素を追加して、最小値を取り出す
後半では、要素を
'''


import heapq
q = [] # プライオリティキュー minヒープ
heapq.heappush(q, 1) # 1をpush
#q
#[1]
heapq.heappush(q, 2) # 2をpush
#q
#[1, 2] # 1より2の方が優先度が低いので先頭以外に追加される
heapq.heappush(q, 0) # 0をpush

q1 = []
sum_q1 = 0
sum_q1s = []

for i in range(0,N,1):
    heapq.heappush(q1, As[i])
    sum_q1 += As[i]
sum_q1s.append(sum_q1)
for i in range(N,2*N,1):
    heapq.heappush(q1, As[i])
    pop_q1 = heapq.heappop(q1)
    sum_q1 = sum_q1 - pop_q1 + As[i]
    sum_q1s.append(sum_q1)

q2 = []
sum_q2 = 0
sum_q2s = []

for i in range(2*N,3*N,1):
    heapq.heappush(q2, -As[i])
    sum_q2 += -As[i]
sum_q2s.append(sum_q2)
for i in range(2*N-1,N-1,-1):
    heapq.heappush(q2, -As[i])
    pop_q2 = heapq.heappop(q2)
    sum_q2 = sum_q2 - pop_q2 - As[i]
    sum_q2s.append(sum_q2)

max_value = -float('inf')
for i in range(0,N+1,1):
    max_value = max(max_value, sum_q1s[i] + sum_q2s[N-i])

print(max_value)

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

int main(){
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N,greater<int>());
    int A=0;
    int B=0;

    for(int k=0;k<N;k++){
        if(k%2==0){
            A+=a[k];
        }
        else{
            B+=a[k];
        }
    }
    cout<<A-B<<endl;
    return 0;
}

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

int a[200010];
int main()
{
    int n; scanf("%d", &n);
    priority_queue<int> q;
    for(int i=0; i<n; ++i) {
        scanf("%d", a+i);
        q.push(a[i]);
    }
    for(int i=0; i<n; ++i) {
        if (q.top()>a[i]) {
            printf("%d\n", q.top());
        }
        else {
            int p=q.top();
            q.pop();
            printf("%d\n", q.top());
            q.push(p);
        }
    }
}


Measured memory_bytes: 3316
N, K = map(int, input().split())
sushi = []
for i in range(N):
    s = list(map(int, input().split()))
    sushi.append(s)


sushi.sort(key=lambda x: x[1], reverse=True)

# pick from first
point = 0
neta_set = set()
removable_idx = list()
for i in range(K):
    s = sushi[i]
    point += s[1]
    if s[0] not in neta_set:
        neta_set.add(s[0])
    else:
        removable_idx.append(i)
point += len(neta_set) **2
max_point = point

# pick latest
for s in sushi[K:]:
    if len(removable_idx) == 0:
        break
    if s[0] in neta_set:
        continue
    idx = removable_idx[-1]
    count = len(neta_set)
    point += s[1] - sushi[idx][1]
    point += (count + 1) ** 2 - count ** 2
    neta_set.add(s[0])
    removable_idx = removable_idx[:-1]

    if point > max_point:
        max_point = point
print(max_point)

Measured memory_bytes: 31164
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int K;
int A[200000];
long long s[200001];
map<int,int> mp;
int main(){
  int i;
  long long res = 0;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
    }
  }
  for(i=(0);i<(N);i++){
    s[i+1] = (s[i] + A[i]) % K;
  }
  for(i=(0);i<(N+1);i++){
    if(i>=K){
      mp[s[i-K]]--;
    }
    res += mp[s[i]]++;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N, K, A[2d5];
// ll s[200001];
// map<int,int> mp;
// {
//   ll res = 0;
//   rd(N,K,(A--)(N));
// 
//   rep(i,N) s[i+1] = (s[i] + A[i]) % K;
//   rep(i,N+1){
//     if(i>=K) mp[s[i-K]]--;
//     res += mp[s[i]]++;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 11904
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <complex>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
 
typedef long long ll;
#define X real()
#define Y imag()
 
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> Pol;
 
const D INF = 1e40;
const D EPS = 1e-5;
const D PI = acos(-1);
 
int sign(D r){ return (r < -EPS) ? -1 : (r > EPS) ? 1 : 0; }
bool eq(D a, D b){ return abs(b - a) < EPS; }
bool near(P a, P b){ return abs(b - a) < EPS; }
 
D dot(P a, P b){ return a.X * b.X + a.Y * b.Y; }
D cross(P a, P b){ return a.X * b.Y - a.Y * b.X; }
P vec(L a){ return a.second - a.first; }
 
P pLL(L a, L b){ return a.first + vec(a) * (cross(vec(b), b.first - a.first) / cross(vec(b), vec(a))); }
int main(){
  int N;
  while(cin>>N && N){
    vector<L> l;
    REP(i, N){
      double a, b, c, d;
      cin>>a>>b>>c>>d;
      l.push_back(L(P(a, b), P(c, d)));
    }
    int ans = 1;
    for(int i = 0; i < N; i++){
      int cnt = 1;
      vector<P> crs;
      for(int j = 0; j < i; j++){
        if(!sign(cross(vec(l[i]), vec(l[j])))) continue;
        P p = pLL(l[i], l[j]);
        if(!(abs(p.X) < 100 - EPS && abs(p.Y) < 100 - EPS)) continue;
        bool ok = true;
        for(int k = 0; k < crs.size(); k++){
          if(eq(crs[k].X, p.X) && eq(crs[k].Y, p.Y)){
            ok = false;
            break;
          }
        }
        if(ok){
          crs.push_back(p);
          cnt++;
        }
      }
      ans += cnt;
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second
#define all(x) (x).begin() , (x).end()
#define mod 1000000009

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

void solve()
{
	int n;
	cin >> n;

	if (n % 1000 == 0)
	{
		cout << "0\n";
		return;
	}

	int x = n % 1000 , y = n / 1000;

	cout << 1000 - (n % 1000) << "\n";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin>>t;

	while (t--)
	{
		solve();
	}


	return 0;
}





Measured memory_bytes: 3648
import numpy
N, K = map(int, input().split())
p = numpy.array(list(map(int, input().split())))
max = 0
nowsum = 0
for i in range(N-K+1):
    if i == 0:
        nowsum = numpy.sum(p[i:i+K])
    else:
        nowsum = nowsum - p[i-1] + p[i+K-1]
    if max < nowsum:
        max = nowsum
        maxno = i

exsum = 0

for i in range(K):
    temp = p[i+maxno]
    exsum += (0.5*temp*(temp+1))/temp
print(exsum)

Measured memory_bytes: 33976
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const plan = arg.slice(1, N + 1);
    
    let x  = 0;
    let y  = 0;
    let lt = 0;
    
    for(let i in plan) {
        let t  = parseInt(plan[i].split(" ")[0]);
        let dx = parseInt(plan[i].split(" ")[1]);
        let dy = parseInt(plan[i].split(" ")[2]);
        
        let distance = Math.abs(dx - x) + Math.abs(dy - y);
        
        if(distance > t - lt || distance % 2 !== (t - lt) % 2) {
            console.log("No");
            return;
        }
        
        x  = dx;
        y  = dy;
        lt = t;
    }
    
    console.log("Yes");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 34284
from numba import njit

N = int(input())


@njit
def f():
    for h in range(1, 3501):
        for n in range(1, 3501):
            x = 4 * h * n - N * n - N * h
            if x != 0 and N * h * n % x == 0:
                w = N * h * n // x
                if w >= 1:
                    return h, n, w


print(*f())


Measured memory_bytes: 109352
#include <iostream>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    string s,s1,s2;
    cin>>s;
    s1=s.substr(0,4);
    s2=s.substr(4,8);
    cout<<s1<<' '<<s2<<endl;
    return 0;
}


Measured memory_bytes: 256
N,Ma,Mb = map(int,input().split())
ABC = [list(map(int,input().split())) for i in range(N)]

dp = [[[float("inf")]*(10*N+1) for i in range(10*N+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0][0] = 0

for i in range(1,N+1):
    for A in range(10*N+1):
        for B in range(10*N+1):
            a,b,c = ABC[i-1]
            dp[i][A][B] = min(dp[i][A][B], dp[i-1][A][B], c+dp[i-1][A-a][B-b])
            
i = 1
ans = float("inf")
while i*Ma <= 10*N and i*Mb <= 10*N:
    ans = min(ans, dp[N][i*Ma][i*Mb])
    i += 1
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 125660
ans = [0] * 10000
for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      k = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
      if k > 10000:
        break
      ans[k - 1] += 1

n = int(input())
for i in range(n):
  print(ans[i])

Measured memory_bytes: 9160
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)

int main() {
  long long int n,m;
  cin>>n>>m;
  
  rep(i,0,m){
    long long int a;
    cin>>a;
    n-=a;
  }

  if(n>=0){cout<<n<<endl;}
  else{cout<<-1<<endl;}
  
  return 0;
}


Measured memory_bytes: 3632
// Written by newbiechd
#include <cstdio>
#include <cctype>
#include <cstring>
using namespace std;

const int BUF = 1000003;
inline char getChar() {
  static char buf[BUF], *bufS, *bufT;
  if (bufS == bufT) {
    bufT = (bufS = buf) + fread(buf, 1, BUF, stdin);
    if (bufS == bufT)
      return EOF;
  }
  return *bufS++;
}
inline int read() {
  int f = 0;
  char ch;
  while (!isdigit(ch = getChar())) {}
  do f = f * 10 + (ch ^ 48);
  while (isdigit(ch = getChar()));
  return f;
}

const int maxN = 403, mod = 998244353;
int a[maxN], b[maxN], dp[maxN][maxN][maxN], inv[maxN];

int main() {
  int n = read(), i, j, k, d, temp, A, B, ans = 0;
  for (i = 1; i <= n; ++i)
    a[i] = read(), b[i] = read();
  inv[1] = 1;
  for (i = 2; i < maxN; ++i)
    inv[i] = -1ll * (mod / i) * inv[mod % i] % mod;
  
  dp[0][0][0] = -1, A = 0, B = 0;
  for (i = 1; i <= n; ++i) {
    temp = 1;
    for (j = 0; j <= A; ++j)
      memcpy(dp[i][j], dp[i - 1][j], sizeof(int) * (B + 1));
    A += a[i], B += b[i] - 1;
    for (d = 0; d < b[i]; ++d, temp = 1ll * temp * a[i] % mod * inv[d] % mod)
      for (j = a[i]; j <= A; ++j)
        for (k = d; k <= B; ++k)
          dp[i][j][k] = (-1ll * dp[i - 1][j - a[i]][k - d] * temp
                         + dp[i][j][k]) % mod;
  }
  
  for (j = 1; j <= A; ++j) {
    temp = 1ll * A * inv[j] % mod;
    for (k = 0; k <= B; ++k, temp = 1ll * temp * k % mod * inv[j] % mod)
      ans = (1ll * dp[n][j][k] * temp + ans) % mod;
  }
  printf("%d\n", (ans + mod) % mod);
  return 0;
}


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

int N, M;
vector<int> s, c;

bool ok(string str) {
    if (str.size() != N) return false;
    for (int i = 0; i < M; ++i) if (str[s[i]] != (char)(c[i] + '0')) return false;
    return true;
}

string solve() {
    for (int i = 0; i <= 999; ++i) {
        stringstream iss; iss << i;
        string str = iss.str();
        if (ok(str)) return str;
    }
    return "-1";
}

int main() {
    cin >> N >> M;
    s.resize(M); c.resize(M);
    for (int i = 0; i < M; ++i) cin >> s[i] >> c[i], --s[i];
    cout << solve() << endl;
}

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

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

    long long ans = 1;
    long long m = 100;
    while (1)
    {
        m = double(m) * 1.01;
        if(m >= x)break;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int n = sc.nextInt();
        final int d = sc.nextInt();
        sc.close();
        int yono = n / (d * 2 + 1);
        if(n % (2 * d + 1) != 0) yono++;
        System.out.println(yono);
    }
}

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

int main() {
  stack<int> S1;
  stack<pair<int, int> > S2;
  char ch;
  int sum = 0;
  for (int i = 0; cin >> ch; i++) {
    if (ch == '\\')
      S1.push(i);
    else if (ch == '/' && S1.size() > 0) {
      int j = S1.top();
      S1.pop();
      sum += i - j;
      int a = i - j;
      while (S2.size() > 0 && S2.top().first > j) {
        a += S2.top().second;
        S2.pop();
      }
      S2.push(make_pair(j, a));
    }
  }

  vector<int> ans;
  while (S2.size() > 0) {
    ans.push_back(S2.top().second);
    S2.pop();
  }
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size();
  for (int i = 0; i < ans.size(); i++) {
    cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


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

int main() {

  /*
  int dx[4] = {  0,  1,  0, -1 };
  int dy[4] = { -1,  0,  1,  0 };
  */
  
  long long int r[7][7];
  r[1][2] = 3;
  r[1][3] = 5;
  r[1][4] = 2;
  r[1][5] = 4;
  r[2][1] = 4;
  r[2][3] = 1;
  r[2][4] = 6;
  r[2][6] = 3;
  r[3][1] = 2;
  r[3][2] = 6;
  r[3][5] = 1;
  r[3][6] = 5;
  r[4][1] = 5;
  r[4][2] = 1;
  r[4][5] = 6;
  r[4][6] = 2;
  r[5][1] = 3;
  r[5][3] = 6;
  r[5][4] = 1;
  r[5][6] = 4;
  r[6][2] = 4;
  r[6][3] = 2;
  r[6][4] = 5;
  r[6][5] = 3;
  
  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    long long int h[300][300] = {};
    long long int c[300][300] = {};
    
    for ( long long int i = 0; i < n; i++ ) {

      long long int t, f;
      cin >> t >> f;

      long long int x = 150;
      long long int y = 150;

      while( true ) {

	long long int l, b, d;
	l = 7 - r[t][f];
	b = 7 - f;
	d = 7 - t;

	long long int dd[3] = {};
	long long int dn[3] = {};
	long long int k = 0;
	
	if ( f >= 4 && h[x][y] > h[x][y-1] ) {
	  dd[k] = 1;
	  dn[k] = f;
	  k++;
	}
	if ( r[t][f] >= 4 && h[x][y] > h[x+1][y] ) {
	  dd[k] = 2;
	  dn[k] = r[t][f];
	  k++;
	}
	if ( b >= 4 && h[x][y] > h[x][y+1] ) {
	  dd[k] = 3;
	  dn[k] = b;
	  k++;
	}
	if ( l >= 4 && h[x][y] > h[x-1][y] ) {
	  dd[k] = 4;
	  dn[k] = l;
	  k++;
	}
	long long int m = 0;
	if ( dd[1] == 0 ) {
	  m = dd[0];
	}else {
	  if ( dn[0] > dn[1] ) {
	    m = dd[0];
	  }else {
	    m = dd[1];
	  }
	}
	if ( m == 0 ) break;
	if ( m == 1 ) {
	  y--;
	  f = t;
	  t = b;
	}else if ( m == 2 ) {
	  x++;
	  t = 7 - r[t][f];
	}else if ( m == 3 ) {
	  y++;
	  t = f;
	  f = d;
	}else if ( m == 4 ) {
	  x--;
	  t = r[t][f];
	}
	
      }

      h[x][y]++;
      c[x][y] = t;
      
    }

    long long int ans[7] = {};
    for ( long long int i = 0; i < 300; i++ ) {
      for ( long long int j = 0; j < 300; j++ ) {
	ans[ c[i][j] ]++;
      }
    }

    for ( long long int i = 1; i <= 6; i++ ) {
      cout << ans[i];
      if ( i == 6 ) {
	cout << endl;
      }else {
	cout << " ";
      }
    }
    
  }
  
  return 0;
  
}

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

int main( ){
  int E,Y;
  cin>>E>>Y;

  if(E==0 && 1868 <= Y && Y <= 1911){
    cout<<"M"<<Y-1867<<endl;
  }else if(E==0 && 1912 <= Y&&Y <= 1925){
    cout<<"T"<<Y-1911<<endl;
  }else if(E==0 && 1926 <= Y&&Y <= 1988){
    cout<<"S"<<Y-1925<<endl;
  }else if(E==0 && 1989 <= Y&&Y <= 2016){
    cout<<"H"<<Y-1988<<endl;
  }else if(E==1){
    cout<<Y+1867<<endl;
  }else if(E==2){
    cout<<Y+1911<<endl;
  }else if(E==3){
    cout<<Y+1925<<endl;
  }else if(E==4){
    cout<<Y+1988<<endl;
  }
  return 0;
}



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

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n, INT_MAX);
	for(int i=0; i<n-1; i++) {
		int t;
		cin >> t;
		a[i] = min(a[i], t);
		a[i+1] = min(a[i+1], t);
	}
	cout << accumulate(a.begin(), a.end(), 0);
}

Measured memory_bytes: 256
A, B, C = gets.split.map(&:to_i)

a, b, c = A, B, C
ans = 0

100000.times do
  if a.odd? || b.odd? || c.odd?
    puts ans
    exit
  end

  a, b, c = (b + c) / 2, (a + c) / 2, (b + a) / 2
  ans += 1
end

puts '-1'


Measured memory_bytes: 1788
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, l;
	scanf("%d%d", &n, &l);
	vector<int> a(n);
	rep(i, n)a[i] = l + i;
	int tmp = INF;
	rep(i, n)if(abs(a[i]) < abs(tmp))tmp = a[i];
	printf("%lld\n", accumulate(all(a), 0LL) - (ll)tmp);
	
	Please AC;
}


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

void Watch(int &S) {
    int hour = S / 3600;
    int minite = (S % 3600) / 60;
    int second = S % 60;
    cout << hour << ":" << minite << ":" << second << endl;
}

int main() {
    int S = 0;
    cin >> S;
    Watch(S);
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
   if(n%2==1) {
     cout << "No" << endl;
     return 0;
   }
   if(s.substr(0,n/2) == s.substr(n/2,n/2)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
	int N;	cin >> N;
	vector<int> a;
	int inputA;
	int answer = 0;
	for (int i = 0; i < N; ++i) {
		cin >> inputA;
		a.push_back(inputA);
	}
	for (int i = 0; i < N; ++i) {
		answer += a[i] - 1;
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
 
 
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn main(){
 
    
    let v:Vec<i64>=read_vec();
 
   	
    if (v[0]*100+v[1]*10+v[2])%4==0 {
        println!("YES");
    }else{
    
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include<list>
#include<cstring>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LP lower_bound
#define UP upper_bound
#define MP make_pair
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define UMP unordered_map
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;
    /*
    **  author : mahiman12
    **  created : 2020-05-06 15:14 
    */
    cin>>n;
    ll arr[n][3];
    ll dp[n][3];
    rep(i,0,n){
        rep(j,0,3){
            cin>>arr[i][j];
            dp[i][j]=arr[i][j];
        }
    }
    // dp[0][0]=arr[0][0];
    // dp[0][1]=arr[0][1];
    // dp[0][2]=arr[0][2];
    rep(i,1,n){
        dp[i][0] = max(dp[i][0] + dp[i-1][1], dp[i][0] +  dp[i-1][2]);
        dp[i][1] = max(dp[i][1] + dp[i-1][0], dp[i][1] +  dp[i-1][2]);
        dp[i][2] = max(dp[i][2] + dp[i-1][1], dp[i][2] +  dp[i-1][0]);
    }
    cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}


Measured memory_bytes: 4992
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main()
{
  string N;
  cin >> N;
  rep(i,3){
    if(N.at(i) == '7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n, q;
    cin >> n >> q;
    vector<tuple<int, int, int>> xst(n);
    rep(i, n) {
        int s, t, x;
        cin >> s >> t >> x;
        xst[i] = make_tuple(x, s-x, t-x);
    }
    sort(all(xst));
    set<P> st;
    rep(i, q) {
        int d;
        cin >> d;
        st.emplace(d, i);
    }
    vector<int> ans(q, -1);

    rep(i, n) {
        int s, t, x;
        tie(x, s, t) = xst[i];
        auto it = st.lower_bound(P(s, 0));
        while (it != st.end()) {
            if (it->first >= t) break;
            ans[it->second] = x;
            st.erase(it++);
        }
    }
    rep(i, q) cout << ans[i] << endl;
}


Measured memory_bytes: 15580
#[allow(unused_imports)]
use std::cmp::{min,max};

fn main() {
    let (a,b) = {
        let xs = read_vec_i64();
        (xs[0],xs[1])
    };
    println!("{} {}", (a-1)/50*2+2 + (b-1)/50*2+2, 100);
    let (n,m) = ((a-1)/50, (a-1)%50);
    for _ in 0..n {
        for _ in 0..50 {
            print!(".#");
        }
        println!("");
        for _ in 0..50 {
            print!("##");
        }
        println!("");
    }
    for _ in 0..m {
        print!(".#");
    }
    for _ in m..50 {
        print!("##");
    }
    println!("");
    for _ in 0..50 {
        print!("##");
    }
    println!("");
    let (n,m) = ((b-1)/50, (b-1)%50);
    for _ in 0..n {
        for _ in 0..50 {
            print!("..");
        }
        println!("");
        for _ in 0..50 {
            print!("#.");
        }
        println!("");
    }
    for _ in 0..50 {
        print!("..");
    }
    println!("");
    for _ in m..50 {
        print!("..");
    }
    for _ in 0..m {
        print!("#.");
    }
    println!("");
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}


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

namespace abc147_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string N = string.Concat(S.Reverse());
            int H = 0;

            for (int i = 0; i < S.Length / 2; i++)
            {
                if (S[i] == N[i])
                {
                    ;
                }
                else
                {
                    H++;
                }
            }

            Console.WriteLine(H);
            Console.Read();

        }
    }
}


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

typedef struct node_t
{
	node_t *pre, *next;
	int value;
}node;

node *nil;

void list_init(){
	nil = (node *)malloc(sizeof(node));
	nil->pre = nil->next = nil;
}

void insert(int key){
	node *x = (node *)malloc(sizeof(node));
	x->value = key;
	x->next = nil->next;
	nil->next->pre = x;
	x->pre = nil;
	nil->next = x;
}

node* search(int key){
	node *start = nil->next;
	while(start != nil){
		if(start->value == key) {
			//printf("i find\n");
			break;
		}
		start = start->next;
	}
	return start;
}

void deleteNode(node *n){
    if(n==nil) return;
	n->pre->next = n->next;
	n->next->pre = n->pre;
	free(n);
}

void deleteKey(int key){
	node *n = search(key);
	deleteNode(n);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->pre);
}

void printList(){
	node *n = nil->next;
	while(1){
		printf("%d",n->value);
		n = n->next;
		if(n == nil) break;
		printf(" ");
	}
	printf("\n");
}

int main(int argc, char const *argv[])
{
	list_init();
	int num_operation, key;
	scanf("%d",&num_operation);
	string operation;
	for(int i=0;i<num_operation;++i){
		cin>>operation;
		if(operation=="deleteFirst"){
			deleteFirst();
			continue;
		}
		if(operation=="deleteLast"){
			deleteLast();
			continue;
		}
		scanf("%d",&key);
//		printf("len of operation %d\n",(int)strlen(operation));
		if(operation[0]=='i') insert(key);
		else if(operation[0]=='d'){
//            if(strlen(operation)>6){
//                if(operation[6]=='F') deleteFirst();
//                else if(operation[6]=='L') deleteLast();
//            }
//			else 
			deleteKey(key);
		}
	}
	printList();
	return 0;
}


Measured memory_bytes: 34576
#include<stdio.h>
int main(void)
{
	int n;
	int i,j;
	int a[1000],b[1000],c[1000];
	int a1[1000],b1[1000],c1[1000];
	int sum[1000];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		a1[i]=a[i];
		b1[i]=b[i];
		c1[i]=c[i];
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(a[i]==a[j] && i!=j){
				a1[i]=0;
			}
			if(b[i]==b[j] && i!=j){
				b1[i]=0;
			}
			if(c[i]==c[j] && i!=j){
				c1[i]=0;
			}
		}
	}
	for(i=0;i<n;i++) {
		sum[i]=(a1[i]+b1[i]+c1[i]);
		printf ("%d\n",sum[i]);
	}
	
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    
    int dp[n+1];
    dp[0] = dp[1] = 1;
    for(int i = 2;i <= n;i++){
        dp[i] = dp[i-1] + dp[i-2];
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define rpt(n) for(register int ttxyc=0;ttxyc<n;++ttxyc)
using namespace std;
int n,a,ans;map<int,int>m;
main()
{
    scanf("%d",&n);
    rpt(n)scanf("%d",&a),++m[a];
    for(map<int,int>::iterator i=m.begin();i!=m.end();++i)
    {
        pair<int,int>now=*i;
        if(now.first>now.second)ans+=now.second;
        else ans+=now.second-now.first;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 4736
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	int n;
	vector<ll> a;
	a.push_back(0);
	cin >> n;
	for (int i = 0;i < n;i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	a.push_back(0);

	ll total = 0;
	for (int i = 0;i < a.size()-1;i++) {
		total += abs(a[i + 1] - a[i]);
	}

	for (int i = 1;i <= n;i++) {
		ll tmp = total - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]);
		cout << tmp << endl;
	}

	return 0;
}




Measured memory_bytes: 2164
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	100005

int		N, D, st[n], Num[n];

struct	Lin{
		int v, next;
}E[n << 1];

void	Link(int u, int v)	{
		E[++ D]= (Lin){v, st[u]};	st[u]= D;
		E[++ D]= (Lin){u, st[v]};	st[v]= D;
}

set<int>	G[n];

void	Merge(int u, set<int>&a, set<int>&b)	{
		if	(a.size() > b.size())	swap(a, b);
		for (set<int>::iterator it= b.begin(); it != b.end(); it++)	{
			if	(a.find(*it) != a.end())	Num[u]= max(Num[u], (*it) + 1);
				else	a.insert(*it);
		}
}

void	DFS(int u, int f)	{
		Num[u]= 0;
		
		for (int i= st[u], v; i; i= E[i].next)
			if	((v= E[i].v) != f)	DFS(v, u);
		
		for (int i= st[u], v; i; i= E[i].next)
			if	((v= E[i].v) != f)	Merge(u, G[u], G[v]);
		
		for (; G[u].size() && *(G[u].begin()) < Num[u]; )	G[u].erase(G[u].begin());
		for (; G[u].find(Num[u]) != G[u].end(); )	G[u].erase(Num[u]), Num[u]++;
		G[u].insert(Num[u]);
		
	//	printf("# %d %d\n", u, Num[u]);
}

int		main(int argc, char* argv[]){
		N= IN();
		For(i, 2, N)	Link(IN(), IN());
		
		DFS(1, 0);
		
		int	Ans= 0;
		For(i, 1, N)	Ans= max(Ans, Num[i]);
		
		cout << Ans << endl;
		
		return	0;
}

Measured memory_bytes: 49152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a[3];
  rep(i, 3) cin >> a[i];
  sort(a, a+3);
  cout << a[2]*10+a[1]+a[0] << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt
    val s = in.readLine()

    val cs = s.toCharArray.map(_.toInt - '0')

    val thirdChars = new Array[Set[Int]](n)
    val thirdCharsCount = new Array[Int](n)

    thirdChars(n - 1) = Set(cs(n - 1))
    thirdCharsCount(n - 1) = 1
    for {
      i <- (n - 2) to 2 by -1
    } {
      thirdChars(i) = thirdChars(i + 1) + cs(i)
      thirdCharsCount(i) = thirdChars(i).size
    }

    var count = 0
    val firstMemo = Array.ofDim[Boolean](10)
    val secondMemo = Array.ofDim[Boolean](n - 1, 10)

    for (
      i <- 0 until (n - 2)
      if !firstMemo(cs(i))
    ) {
      for (
        j <- i + 1 until (n - 1)
        if !secondMemo(i)(cs(j))
      ) {
        count += thirdCharsCount(j + 1)
        secondMemo(i)(cs(j)) = true
      }
      firstMemo(cs(i)) = true
    }

    System.out.println(
      count
    )
  }
}


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

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

    int n;
    cin >> n;
    int p[static_cast<int>(2 * 1e5 + 1)] = {};
    int tmp;
    int max_seq = 0;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        p[tmp] = p[tmp - 1] + 1;
        max_seq = max(max_seq, p[tmp]);
        p[tmp - 1] = 0;
    }
    // for (int i = 1; i <= n; ++i) {
    //     max_seq = max(max_seq, p[i]);
    // }
    // sort(p + 1, p + n + 1);

    // cout << n - p[n] << '\n';
    cout << n - max_seq << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#define il inline
#define ri register
#define ll long long
#define Size 200050
using namespace std;
namespace{
	template<class free>
		il void read(free&x){
		x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
		while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
	}
	template<class f1,class...f2>
		il void read(f1&x,f2&...y){
		read(x),read(y...);
	}
}
template<class free>
struct heap{
	free a[Size];int n;
	il void down(int p){
		int s(p<<1);
		while(s<=n){
			if(s<n&&a[s+1]<a[s])++s;
			if(a[s]<a[p])
				swap(a[s],a[p]),
					p=s,s<<=1;
			else break;
		}
	}
	il void up(int p){
		while(p)
			if(a[p]<a[p>>1])
				swap(a[p],a[p>>1]),
					p>>=1;
			else break;
	}
	il void push(const free&x){
		a[++n]=x,up(n);
	}
	il void pop(){
		a[1]=a[n--],down(1);
	}
	il void build(){
		for(int i(n);i;--i)down(i);
	}
};
struct san{
	int x,y,z;
	il bool operator<(const san&A)const{
		return y*1ll*A.x<A.y*1ll*x;
	}
};
ll ans;
heap<san>H;
int fa[Size],a[Size];
int fa1[Size],a1[Size],a2[Size];
il int find(int);
il void Union(int,int);
int main(){
	int n;read(n);
	for(int i(2);i<=n;++i)read(fa[i]);
	for(int i(1);i<=n;++i)
		read(a[i]),fa1[i]=i,a1[i]=!a[i],a2[i]=a[i];
	for(int i(2);i<=n;++i)
		H.a[i-1]={a1[i],a2[i],i};
	H.n=n-1,H.build();while(H.n){
		san top(H.a[1]);H.pop();
		if(top.x==a1[top.z]&&top.y==a2[top.z])
			Union(top.z,fa[top.z]);
	}return printf("%lld",ans),0;
}
il int find(int x){
	return x^fa1[x]?fa1[x]=find(fa1[x]):x;
}
il void Union(int u,int v){
	u=find(u),v=find(v);
	if(u==v)return;fa1[u]=v;
	ans+=a2[v]*1ll*a1[u];
	a1[v]+=a1[u],a2[v]+=a2[u];
	if(v^1)H.push({a1[v],a2[v],v});
}


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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

int gcd(int a, int b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (a < b) swap(a,b);
    if (b == 0) return a;
    return a%b == 0 ? b : gcd(b, a%b);
}
int lcm(int a, int b) { return a*b/gcd(a,b);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    int g = A[0];
    int mx = A[0];
    for (int i=1;i<N;i++) {
        g = gcd(g,A[i]);
        mx = max(mx, A[i]);
    }
    if (K%g==0 && K <= mx) cout << "POSSIBLE" << "\n";
    else cout << "IMPOSSIBLE" << "\n";
}

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

template<class T>
T gcd(T a, T b)
{
    while (a > 0)
    {
        T t = a;
        a = b%a;
        b = t;
    }
    return b;
}

int main()
{
    int N;
    cin>>N;
    vector<long long> x(N), y(N);
    for (int i=0; i<N; i++)
        cin>>x[i]>>y[i];

    set<pair<long long, long long>> xy;
    for (int i=0; i<N; i++)
        xy.insert(make_pair(x[i], y[i]));
    long long ans = N;

    for (int a=0; a<N; a++)
    for (int b=0; b<a; b++)
    {
        long long p = x[a] - x[b];
        long long q = y[a] - y[b];
        long long c = 0;
        for (int i=0; i<N; i++)
            if (xy.count(make_pair(x[i]-p, y[i]-q))==0)
                c++;
        ans = min(ans, c);
    }
    cout<<ans<<endl;


    /*
    long long ans = min(
        set<long long>(x.begin(), x.end()).size(), 
        set<long long>(y.begin(), y.end()).size());
    set<pair<long long, long long>> S;
    for (int a=0; a<N; a++)
    for (int b=0; b<N; b++)
    {
        long long p = x[a] - x[b];
        long long q = y[a] - y[b];
        if (p!=0 && q!=0)
        {
            //long long g = gcd(abs(p), abs(q));
            //p /= g;
            //q /= g;
            S.clear();
            if (p<0)
            {
                p = -p;
                q = -q;
            }
            for (int i=0; i<N; i++)
            {
                long long c = x[i]/p;
                while (x[i]-c*p<0)
                {
                    if (c*p>0)
                        c++;
                    else
                        c--;
                }
                while (x[i]-c*p>=p)
                {
                    if (c*p>0)
                        c--;
                    else
                        c++;
                }
                S.insert(make_pair(x[i]-c*p, y[i]-c*q));
            }
            ans = min(ans, (long long)S.size());
        }
    }
    cout<<ans<<endl;
        */
}


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

int main(void){
  int A, B, C;
  bool can = false;
  cin >> A >> B >> C;
  for(int i = 1; i <= B; i++){
    if(A*i % B == C){
      can = true;
      break;
    }
  }
  if(can){cout << "YES" << endl;}
  else{cout << "NO" << endl;}
  return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

int main() {
  int n;
  cin >> n;
  int s[n];
  rep(i, n) cin >> s[i];
  ll dp[n + 1][10010];
  rep(j, n + 1) rep(i, 10010) dp[j][i] = 0;
  dp[0][0] = 1;
  rep(i, n) {
    rep(j, 10010) {
      if (dp[i][j] == 1) dp[i + 1][j] = 1;
      if (j - s[i] < 0 || dp[i][j - s[i]] == 0) continue;
      dp[i + 1][j] = 1;
    }
  }
  ll mx_val = 0;
  rep(i, 10005) {
    ll val = dp[n][i];
    if (val == 0 || i % 10 == 0) continue;
    mx_val = MAX(mx_val, i);
  }
  cout << mx_val << endl;
  return 0;
}

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

int main(){
  string S;
  cin>>S;
  
  int l=S.size()-1;
  int num=1<<l;
  rep(tmp, num){
    bitset<10> bits(tmp);
    
    int this_sum=(S[0]-'0');
    rep(i, l){
      // cout<<this_sum<<endl;
      if(bits.test(i)){
        this_sum += (S[i+1]-'0');
      }
      else{
        this_sum -= (S[i+1]-'0');
      }
    }
    // cout<<this_sum<<endl;
    if(this_sum==7){
      cout<<S[0];
      rep(i, l){
        if(bits.test(i)){
          cout<<'+';
        }
        else{
          cout<<'-';
        }
        cout<<S[i+1];
      }
      cout<<"=7"<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3616
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    N = I()
    print((pow(10, N, MOD) - (pow(9, N, MOD) + pow(9, N, MOD) - pow(8, N, MOD))) % MOD)


if __name__ == '__main__':
    main()

Measured memory_bytes: 72532
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int a[4];
bool f =false;

void solve(int i , int num , string s){
  if(f)
    ret;
  if(i == 4){
    if(num == 7){
      P(s+"=7");
      f = true;
      ret;
    }
  }
  else{
    solve(i+1,num+a[i],s+"+"+to_string(a[i]));
    solve(i+1,num-a[i],s+"-"+to_string(a[i]));
  }
  
  ret;
}

int main(){
  string s;
  cin >> s;
  rep(i,0,s.size()){
    a[i] = s[i] - '0';
  }
  
  s = to_string(a[0]);
  solve(1,a[0],s);
  ret 0;
}

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

int main(void)
{
  int X,Y;

  int money=0;
  cin>>X>>Y;
  
  
  if(X<4)
  {
	money +=100000*(4-X);
  }
  		
    if(Y<4)
  	{
  		money +=100000*(4-Y);
	} 
  
  if(X==1&&Y==1) money += 400000;
  cout<<money<<endl;
}  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>  // abs() for integer
using namespace std;

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;

    int mt[N+1][N+1];

    int i, j;

    int count[N];

    for(int i = 0; i < N; i++){
        count[i] = 0;
    }

    int minv;
    
    for(i = 1; i <= N; i++){
        for(j = i; j <= N; j++){
            //printf("%d\n",min(j - i, abs(X- i) + 1 + abs(Y - j)));
            minv = min(j - i, abs(X- i) + 1 + abs(Y - j));
            count[minv]++;
            //printf("count %d\n", count[minv]);

        }
    }

    //printf("aaa\n");

    for(i = 1; i < N; i++){
        printf("%d\n", count[i]);
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int N, x;
vector<int> a;

int main() {
  scanf("%d%d", &N, &x);
  a = vector<int>(N);

  REP(i, N) {
    scanf("%d", &a[i]);
  }

  sort(a.begin(), a.end());

  int cnt = 0, last = -1;
  for (int i = 0; i < N; ++i) {
    if (x < a[i]) {
      last = i;
      break;
    }
    x -= a[i];
    cnt += 1;
  }

  // お菓子が余った場合
  if (x > 0 && cnt != 0) {
    if (last == -1) cnt -= 1;
  }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

long int Compare(const void *a, const void *b) {
	return *(long int*)a - *(long int*)b;
}

int main(void)
{
	int n,i,check,count = 0;
	long int nums[100000] = {0};
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%ld", &nums[i]);
	}
	qsort(nums, n, sizeof(long int), Compare);

	for (i = 0; i < n ;) {
		int dub = 0;
		check = nums[i];
		while (i < n && check == nums[i]) i++, dub++;
		count += dub % 2;
	}
	printf("%d\n", count);

	return 0;
}


Measured memory_bytes: 1788