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

const int N = 1e5 + 5;
vector< pair< int, int> > conn[N];
int dist[N];
bitset< N> seen;

void dfs(int u, int d) {
    dist[u] = d;
    seen[u] = true;
    for (auto it : conn[u]) if (!seen[it.first]) {
            dfs(it.first, d + it.second);
        }
}

signed main() {
    int n;
    scanf("%lld", &n);
    for (int i = 0; i < n - 1; i++) {
        int a, b, c;
        scanf("%lld %lld %lld", &a, &b, &c);
        conn[a].emplace_back(b, c);
        conn[b].emplace_back(a, c);
    }

    int q, k;
    scanf("%lld %lld", &q, &k);
    dfs(k, 0);
    while (q--) {
        int a, b;
        scanf("%lld %lld", &a, &b);
        printf("%lld\n", dist[a] + dist[b]);
    }
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char> > S(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) cin >> S[i][j];
    }
    vector<vector<int> > L(H, vector<int>(W)), R(H, vector<int>(W)),
        U(H, vector<int>(W)), D(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        if (S[i][0] == '.') L[i][0] = 1;
        for (int j = 1; j < W; j++) {
            if (S[i][j] == '.') L[i][j] = L[i][j - 1] + 1;
        }
    }
    for (int i = 0; i < H; i++) {
        if (S[i][W - 1] == '.') R[i][W - 1] = 1;
        for (int j = W - 2; j >= 0; j--) {
            if (S[i][j] == '.') R[i][j] = R[i][j + 1] + 1;
        }
    }
    for (int i = 0; i < W; i++) {
        if (S[0][i] == '.') U[0][i] = 1;
        for (int j = 1; j < H; j++) {
            if (S[j][i] == '.') U[j][i] = U[j - 1][i] + 1;
        }
    }
    for (int i = 0; i < W; i++) {
        if (S[H - 1][i] == '.') D[H - 1][i] = 1;
        for (int j = H - 2; j >= 0; j--) {
            if (S[j][i] == '.') D[j][i] = D[j + 1][i] + 1;
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 67072
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
/*long long fu(long long x)
{
    if(x==0||x==1)
        return x;
    if(x%4==0)
    return x;
   if(x%2==0)
    return x+1;
    return fu(x-1)^x;
}*/
int main()
{
   long long a,b,sum;
    cin>>a>>b;
    if(a%2==0)
    {
        sum=b-a+1;
        if(sum%2==0)
           {
               sum/=2;
               if(sum%2==0)
                cout<<0<<endl;
               else
                cout<<1<<endl;
           }
        else
        {   sum/=2;
               if(sum%2==0)
                cout<<(0^b)<<endl;
               else
             cout<<(1^b)<<endl;

        }
    }
    else
    {
         sum=b-(a+1)+1;
        if(sum%2==0)
        {
              sum/=2;
              if(sum%2==0)
                cout<<(a^0)<<endl;
              else
                cout<<(a^1)<<endl;
        }
        else
        {
             sum/=2;
             if(sum%2==0)
                cout<<(a^0^b)<<endl;
             else
                cout<<(a^1^b)<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int k, s, x, y, z, a;
int main() {
	cin>>k>>s;
	for(x=0; x<=k; x++) for(y=0; y<=k; y++) {
		z = s - x - y;
		a += (z>=0 && z<=k);
	}
	cout<<a;
	return 0;
}

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

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

using namespace std;

typedef long double ld; 
const ld INF = 1e+12;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<ld> p(n),p2(1,1);
    REP(i,n) cin>>p[i];
    int l = 0;
    vector<int> len;
    REP(i,n) {
      if (p[i] != 1) {
        len.push_back(l);
        p2.push_back(p[i]);
        l = 0;
      }
      ++l;
    }
    len.push_back(l);
    n = p2.size();
    vector<ld> dp(n+1,INF);
    dp[0] = 0;
    REP(i,n) {
      ld e = 0.0;
      REP(j,100) {
        if(i+j>=n)break;
        e = e + len[i+j] + (e+1) * (1-p2[i+j]) / p2[i+j];
        dp[i+j+1] = min(dp[i+j+1], dp[i] + e + 1);
      }
    }
    cout << setprecision(10) << fixed << dp[n] - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 8408
def task_c():
    """
    https://atcoder.jp/contests/abc042/tasks/abc042_c
    """
    n, k = map(int, input().split())
    dd = input().split()

    while True:
        if any(d in dd for d in str(n)):
            n += 1
        else:
            break
    print(n)

    
task_c()

Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
#define INF 1000000000

int n;

double Distance(double v1[], double v2[], int p) 
{
	if (p != INF) {
		double sgm = 0;
		for (int i = 0; i < n; i++) {
			sgm += pow(abs(v1[i] - v2[i]), p);
		}
		return (pow(sgm, 1.0 / p));
	}
	else
	{
		double max = 0;
		for (int i = 0; i < n; i++) {
			if (max < abs(v1[i] - v2[i])) {
				max = abs(v1[i] - v2[i]);
			}
		}
		return max;
	}
}

int main()
{
	cin >> n;
	double x[100] = { 0 }, y[100] = { 0 };
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> y[i];
	}

	printf("%.8lf\n", Distance(x, y, 1));
	printf("%.8lf\n", Distance(x, y, 2));
	printf("%.8lf\n", Distance(x, y, 3));
	printf("%.8lf\n", Distance(x, y, INF));

	return 0;
}


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

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

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

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

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  ll X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
  int n;
  cin >> n;
  vector<P> red(n),blue(n);
  rep(i,n){
    int x,y;
    cin >> x >> y;
    red[i].first=y;
    red[i].second=x;
  }
  rep(i,n){
    int x,y;
    cin >> x >> y;
    blue[i].first=x;
    blue[i].second=y;
  }
  vector<bool> used(n,false);
  sort(red.begin(),red.end());
  reverse(red.begin(),red.end());
  sort(blue.begin(),blue.end());
  int i=0;
  int res=0;
  bool X=false;
  rep(i,n){
    rep(j,n){
      if(blue[i].first>red[j].second && blue[i].second>red[j].first && used[j] ==false){
        used[j] =true;
        /*cout << red[j].second << "  " <<red[j].first << " " <<
          blue[i].first <<"  " << blue[i].second << endl;*/
        res++;
        break;
      }
    }
  }
  cout << res << endl;
    
  return 0;
}

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

struct StackOfInt {
	int *value;
	int max;
	int count;
	StackOfInt() {
		clear();
	}
	void clear() {
		max = 100;
		count = 0;
		value = new int[max];
	}
	void push(int x) {
		if (count > 0.9 * max) {
			int *temp = value;
			value = new int[max * 2];
			for (int i = 0; i < count; i++) 
				value[i] = temp[i];
			max = max * 2;
			delete[] temp;
		}
		value[count] = x;
		count++;
	}
	int top() {
		return value[count - 1];
	}
	void pop() {
		if (max != 100 && count < 0.2 * max) {
			int *temp = value;
			value = new int[max / 2];
			for (int i = 0; i < count; i++)
				value[i] = temp[i];
			max = max / 2;
			delete[] temp;
		}
		count--;
	}
	bool empty() {
		return count == 0;
	}
};

struct ArrayOfStack {
	int n;
	StackOfInt *value;
	ArrayOfStack(int x) {
		n = x;
		value = new StackOfInt[x];
	}
	void push(int t, int x) {
		value[t].push(x);
	}
	int top(int t) {
		return value[t].top();
	}
	void pop(int t) {
		value[t].pop();
	}
	bool empty(int t) {
		return value[t].empty();
	}
};

int main(void) {
	int n, q, com, t, x;
	cin >> n >> q;
	ArrayOfStack ar(n);
	while (q--) {
		cin >> com >> t;
		if (com == 0) {
			cin >> x;
			ar.push(t, x);
		} else if (com == 1) {
			if (!ar.empty(t))
				cout << ar.top(t) << endl;
		} else {
			if (!ar.empty(t))
				ar.pop(t);
		}
	}
}


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

const int N=1e5+50,mod=1e9+7;
int n,A[N];
int fac[N],inv[N];
int cnt[N];

inline int read(){
    int x=0,f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+ch-'0';
    return x*f;
}
inline void Add(int &x,int y){
	x+=y;if(x>=mod)x-=mod;
}
inline void Sub(int &x,int y){
	x-=y;if(x<0)x+=mod;
}
int Pow(int x,int k){
	if(k==0)return 1;
	int Res=Pow(x,k>>1);Res=1LL*Res*Res%mod;
	if(k&1)Res=1LL*Res*x%mod;
	return Res;
}
void Prework(){
	fac[0]=1;
	for(int i=1;i<=n;++i)fac[i]=1LL*fac[i-1]*i%mod;
	inv[n]=Pow(fac[n],mod-2);
	for(int i=n-1;i>=0;--i)inv[i]=1LL*inv[i+1]*(i+1)%mod;
}
void Chafen(){
	for(int i=1;i<=n;++i)Add(cnt[i],cnt[i-1]);
}
int C(int x,int y){
	return 1LL*fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int main(){
	n=read();
	for(int i=1;i<=n;++i)A[i]=read();
	if(n==1)return printf("%d\n",A[1])*0;
	Prework();
	for(int i=1;i<=n-2;++i){
		int qwq=2LL*fac[i]*fac[n-i-2]%mod*C(n,i+2)%mod;
		Add(cnt[2],qwq);Sub(cnt[i+2],qwq);
		Sub(cnt[n-i+1],qwq);
	}
	Chafen();
	for(int i=1;i<n;++i){
		int qwq=1LL*fac[i]*fac[n-i-1]%mod*C(n,i+1)%mod;
		Add(cnt[1],qwq);Sub(cnt[i+1],qwq);
		Add(cnt[n-i+1],qwq);
	}
	Add(cnt[1],fac[n]);
	Chafen();
	int ans=0;
	for(int i=1;i<=n;++i)Add(ans,1LL*cnt[i]*A[i]%mod);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

int gcd(int a, int b)
{
    if (b == 0) return a;
    else if (a < b) return gcd(b, a);
    else return gcd(b, a % b);
}

int main()
{
    while (true) {
        int a, b;
        std::cin >> a >> b;
        if (std::cin.eof()) break;
        int g = gcd(a, b);
        std::cout << g << " " << a / g * b << std::endl;
    }
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeSet;

import javax.swing.*;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;
import static java.util.Arrays.sort;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    private static int mod = 998244353;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long x = in.nextLong();
        // n * log 1.01 >= log x / 100
        out.println(cal(x));
    }

    private int cal(long x) {
        long a = 100;
        for (int i = 1;; i++) {
            a = (long) (a * 1.01);
            if (a >= x) {
                return i;
            }
        }
    }

}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


Measured memory_bytes: 25584
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,k;
  cin >> n >> k;
  n--;
  vi a(n);
  rep(i,n){
    cin >> a[i];
  }
  int cnt = 0;
  while(n>0){
    cnt++;
    n-=k-1;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 640
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
bigmod = 10 ** 9 + 7
sum = arr[0] + arr[1]
mod = arr[0] * arr[1] 
mod %= bigmod
2.upto(arr.length-1) do |i|
	mod += sum * arr[i]
	mod %= bigmod
	sum += arr[i]
end

puts mod


Measured memory_bytes: 35900
S=input()
t=len(S)
w=int((t-1)/2)
l=int(len(S)/2)
n=int((t+3)/2)

Two=list(S)[0:w]
Three=list(S)[n-1:t+1]
m=int(len(Two)/2)
o=int(len(Three)/2)

count=0
counts=0
countss=0


#回文条件分岐
for i  in range(l):
    if S[i]==S[len(S)-(i+1)]:
        count +=1

#二個目の条件分岐
for i  in range(m):
    if Two[i]==Two[len(Two)-(i+1)]:
        counts +=1

#三個目の条件分岐
for i  in range(o):
    if Three[i]==Three[len(Three)-(i+1)]:
        countss +=1

if count==l and counts==m and countss==o:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    A = []
    B = [''] * m
    for i in range(m):
        p, y = map(int, input().split())
        A.append((p, y, i))
    A.sort()
    count = 0
    i, x = 1, 1
    for a in A:
        if a[0] == i:
            B[a[2]] = '{:06}{:06}'.format(a[0], x)
        else:
            i = a[0]
            x = 1
            B[a[2]] = '{:06}{:06}'.format(a[0], x)
        x += 1
    print('\n'.join(B))


if __name__ == '__main__':
    main()

Measured memory_bytes: 31496
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String mid = "";
        if (s.length() >= 2) {
            mid = s.substring(1, s.length() - 1);
        }
        int q = sc.nextInt();
        StringBuffer sbHead = new StringBuffer();
        sbHead.append(s.charAt(0));
        StringBuffer sbLast = new StringBuffer();
        if (s.length() != 1) {
            sbLast.append(s.charAt(s.length() - 1));
        }
//        debug(sbHead, sbLast);
        boolean isHead = true;
        for (int i = 0; i < q; i++) {
//            debug(sbHead, sbLast);
            int t = sc.nextInt();
            if (t == 1) {
                isHead = !isHead;
                continue;
            }
            int f = sc.nextInt();
            char c = sc.next().charAt(0);
            if ((f == 1 && isHead) || (f == 2 && !isHead)) {
                sbHead.append(c);
            } else {
                sbLast.append(c);
            }
        }


        StringBuffer ans = sbHead.reverse().append(mid).append(sbLast);
        if (isHead) {
            System.out.println(ans.toString());
        } else {
            System.out.println(ans.reverse().toString());
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 153200
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()

int main()
{   SPEED;
	ll n,c=1;
	cin>>n;
	string a;
	cin>>a;
	
	
for(ll i=1;i<n;i++)
{  if(a[i]!=a[i-1])
	{
		c++;
	}
}

cout<<c<<endl;
	
    
return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
VII dp(401,vector<ll>(401,INF));
int main()
{
	owo
	int n;
	cin>>n;
	vector<ll>a(n+1);
	vector<ll>pref(n+1,0);
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){pref[i] = pref[i-1]+a[i];dp[i][i] = 0;}
	for(int j=1;j<n;j++)
	{
		for(int i=1;i+j<=n;i++){
			ll cost = pref[i+j]-pref[i-1];
			for(int k=i+1;k<=i+j;k++)
			{
				dp[i][i+j] = min(dp[i][i+j],dp[k][i+j]+dp[i][k-1]+cost);
				
			}
			
		}
		
		
	}
	cout<<dp[1][n];
	
}


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

using namespace std;
using ll = long long;

int main(void) {
  string s;
  cin >> s;
  long long n = s.length();

  long long ans = 0;
  long long cnt = 0;
  for (auto &p : s) {
    if (p == 'B') {
      cnt++;
    } else {
      ans += cnt;
    }
  }
  cout << ans << endl;
}

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

int main() {
            int N,i,count=1;
            cin>>N;
            vector<int> moti(N);
            for(i=0;i<N;i++){
            	cin>>moti.at(i);
            }
            sort(moti.begin(),moti.end());
            
            for(i=1;i<N;i++){
            	if(moti.at(i)!=moti.at(i-1)){
            		count++;
            	}
            }
            cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) //  fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def mod_(a_list, m):
    sum_ = 0
    for a in a_list:
        sum_ += m % a

    return sum_


n = int(input())
a = list(map(int, input().split(" ")))

lcm_ = lcm_list(a)

print(mod_(a, lcm_-1))


Measured memory_bytes: 5588
#include<bits/stdc++.h>
#define mo 1000000007
#define ny 499122177
#define maxn 1000000000000000000LL
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1; 
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,i,j,nex[8][2]={3,1,5,2,2,2,4,7,3,3,6,1,5,5,3,1},f[300005][8];
char s[300005];
int main(){
//	freopen("number.in","r",stdin);
//	freopen("number.out","w",stdout);
	scanf("%s",s+1);
	n=strlen(s+1);
	f[n][1]=1;
	f[n][2]=1;
	for(i=n-1;i>=0;i--)
		for(j=0;j<=7;j++)
			f[i][j]=(f[i+1][nex[j][1]]*(s[i+1]!='0')+f[i+1][nex[j][0]]*(s[i+1]!='1'))%mo;
	pus(f[0][0],2);
  	return 0;
}

Measured memory_bytes: 19328
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

signed main(){
	double w, h, x, y;
	cin >> w >> h >> x >> y;

	cout << w * h / 2 << ' ';
	if(w == x * 2 and h == y * 2){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}
}


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

int gcd(int a, int b)
{
  int r;
  if(a < b)
  {
    a += b;
    b -= a;
    a += b;
    b *= -1;
  }
  r = a%b;
  while(r!=0)
  {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  int ans;
  for(i = 0; i < n-1; i++)
  {
    if(i == 0)
    {
      ans = gcd(a.at(0), a.at(1));
    }
    else
    {
      ans = gcd(ans, a.at(i+1));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
n,x,y=map(int,input().split())
#array=[0 for i in range(n)]
array=[None]*n
for i in range(n):
    array[i]=0
for i in range(1,n):
    for j in range(i+1,n+1):
        res=min(abs(j-i),abs(x-j)+1+abs(y-i),abs(y-j)+1+abs(x-i))
        array[res]+=1
for i in range(1,n):
    print(array[i])


Measured memory_bytes: 47324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int n,a[111111];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	int cnt=0;
	rep(i,n)if(a[i]<0)cnt++;
	int ans=0;
	rep(i,n){
		a[i]=abs(a[i]);
		ans+=a[i];
	}
	sort(a,a+n);
	if(cnt%2)ans-=a[0]*2;
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  string S;
  cin >> S;
  int N = S.length(), k=0;
  vector<int> n={0};
  char prev='R';
  for(int i=0; i<N; i++){
    if(prev==S[i]){
      n[k]+=1;
    }
    else{
      n.push_back(1);
      prev=S[i];
      k+=1;
    }
  }
  for(int i=0; i<n.size(); i++){
    for(int k=1; k<n[i]; k++){
      cout << 0 << ' ';
    }
    if((n[i]+n[i+1])%2==0){
	  cout << (n[i]+n[i+1])/2 << ' ' << (n[i]+n[i+1])/2 << ' ';
    }else{
      if(n[i]%2==0){
        cout << (n[i]+n[i+1])/2 << ' ' << (n[i]+n[i+1])/2 + 1 << ' ';
      }else{
        cout << (n[i]+n[i+1])/2 + 1 << ' ' << (n[i]+n[i+1])/2 << ' ';
      }
    }
    i+=1;
    for(int k=1; k<n[i]; k++){
      cout << 0 << ' ';
    }
  }
  return 0;
}

Measured memory_bytes: 1144
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in=new Scanner (System.in);
        PrintWriter out=new PrintWriter(System.out);
        TreeSet<Integer> set=new TreeSet<>();
        int q=Integer.parseInt(in.next());
        for(int i=0;i<q;i++) {
            int odr=Integer.parseInt(in.next());

            switch(odr) {
            case 0:
            	int x0=Integer.parseInt(in.next());
            	if(!set.contains(x0)) set.add(x0);
            	out.println(set.size());
            	break;

            case 1:
            	int x1=Integer.parseInt(in.next());
            	out.println(set.contains(x1)? 1:0);
            	break;
            }

        }
        out.flush();
    }

}


Measured memory_bytes: 113348
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
#define MOD 1000000007
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
double ax,ay,bx,by,cx,cy;
double triangle=0.0;
vector<int> videos(105);
double now=0;
string s;
string forans;
int ans=0;
bool change=false;
int main(int argc,char const* argv[])
{
  cin >> s;
  forans=s;
  int n=s.size();
  for(int i=n-1;i>=0;i--)
    {
      if(i!=0)
	{
	  if(s[i]!='9')
	    {
	      forans[i]='9';
	      change=true;
	    }
	}
    }
  if(!change)
    {
      for(int i=0;i<n;i++)
	{
	  ans+=forans[i]-'0';
	}
    }
  else
    {
      for(int i=0;i<n;i++)
	{
	  if(i==0) ans+=forans[i]-'1';
	  else ans+=forans[i]-'0';
	}
    }
  cout << ans << endl;

      
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();
		int m = in.nextInt();
		int l = in.nextInt();
		int[][] a = new int[n][m];
		int[][] b = new int[m][l];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				a[i][j] = in.nextInt();
			}
		}
		for(int i = 0; i < m; i++){
			for(int j = 0; j < l; j++){
				b[i][j] = in.nextInt();
			}
		}
		for(int i = 0; i < n; i++){
			String ret = "";
			for(int j = 0; j < l; j++){
				long sum = 0;
				for(int k = 0; k < m; k++){
					sum += a[i][k] * b[k][j];
				}
				ret += " " + sum;
			}
			out.println(ret.trim());
		}
	}
}

Measured memory_bytes: 63200
use std::ops::Index;
use std::ptr::read_volatile;

fn main() {
    // トランプ一覧作成
    let s = "SHCD";
    let cards: Vec<_>= s
        .chars()
        .flat_map(|s|(1..14)
        .map(move|x|(s.to_string(), x.to_string())))
        .collect();

    // 除外カードリスト作成
    let n: Vec<i64>=r();
    let mut v :Vec<(String, String)>= vec!();
    for _ in 0..n[0]{
        let w: Vec<String>=r();
        v.push((w[0].clone(), w[1].clone()))
    }

    for c in cards{
        let d = c.clone();
        if !v.contains(&(d.0, d.1)){
            println!("{} {}", c.0, c.1);
        }
    }
}
fn r<T:std::str::FromStr>()->Vec<T> {
    let mut b = String::new();
    let s = std::io::stdin();
    s.read_line(&mut b).unwrap();
    b.split_whitespace().flat_map(str::parse).collect()
}



Measured memory_bytes: 5048
#include <stdio.h>

int main(){
  int j=0, flag=0, Ans[100];
  char fx;
  while(1){
    scanf("%c",&fx);
    if(fx == '\n') break;
    if(fx >= '0' && fx <= '9'){
      if(flag)
	Ans[j] = Ans[j] * 10 + (fx-48);
      else Ans[j] = fx - 48;
      flag = 1;
    }
    else if(fx == '+'){
      Ans[j-2] += Ans[j-1];
      flag = 0;
      j--;
    }
    else if(fx == '-'){
      Ans[j-2] -= Ans[j-1];
      flag = 0;
      j--;
    }
    else if(fx == '*'){
      Ans[j-2] *= Ans[j-1];
      flag = 0;
      j--;
    }
    else if(fx == ' ' && flag){
      j++;
      flag = 0;
    }
    else continue;
  }
    printf("%d\n",Ans[0]);
    return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int inf=0x3f3f3f3f;
int a[100024];
int main()
{

    int n;
    scanf("%d",&n);
    int n4=0,n2=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%4==0) n4++;
        else if(a[i]%2==0) n2++;
    }
    if(n4+n2/2>=n/2) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<ll> &v) {
    std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    set<int> s1;
    set<pair<int, int>> s2;
    set<tuple<int, int, int>> s3;
    REP(i, N) {
        if(i >= 2) {
            for(auto p : s2) {
                s3.insert(make_tuple(p.first, p.second, S[i]));
                if(s3.size() == 1000) {
                    cout << 1000 << endl;
                    return 0;
                }
            }
        }
        if(i >= 1) {
            for(auto p : s1) {
                s2.insert(make_pair(p, S[i]));
            }
        }
        s1.insert(S[i]);
    }
    cout << s3.size() << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int h,w;
  cin >> h>>w;
  vector<string> a(h);
  rep(i,0,h)cin>>a[i];

  vector<bool> r(h,false),c(w,false);

  rep(i,0,h){
    int count = 0;
    rep(j,0,w){
      if(a[i][j]=='.')count++;
    }
    if(count==w)r[i]=true;
  }
  rep(i,0,w){
    int count = 0;
    rep(j,0,h){
      if(a[j][i]=='.')count++;
    }
    if(count==h)c[i]=true;
  }

  rep(i,0,h){
    if(r[i]) continue;
    rep(j,0,w){
      if(c[j]) continue;
      cout<<a[i][j];
    }
    cout<<endl;
  }
}


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

int main(){
    int n, d[55];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> d[i];
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if (i == j)continue;

            ans += d[i] * d[j];
        }
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
const ll MOD = 1e9+7;

vector<vector<int>> g(100001);
vector<int> d_ta(100001, -1), d_ao(100001, -1);

void dfs1(int now, int depth){
    d_ta[now] = depth;
    rep(i, g[now].size()){
        int next = g[now][i];
        if(d_ta[next] == -1) dfs1(next,depth+1);
    }
}

void dfs2(int now, int depth){
    d_ao[now] = depth;
    rep(i, g[now].size()){
        int next = g[now][i];
        if(d_ao[next] == -1) dfs2(next,depth+1);
    }
}

int main(){
    int n, ta, ao; cin >> n >> ta >> ao;
    ta--; ao--;
    int a,b;
    rep(i,n-1){
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs1(ta,0);
    dfs2(ao,0);
    int max=-1, max_node;
    rep(i,n){
        if(d_ta[i] < d_ao[i] && d_ao[i] > max){
            max_node = i;
            max = d_ao[i];
        }
    }
    int dis = d_ta[ao];
    cout << d_ao[max_node]-1 << "\n";
}

Measured memory_bytes: 9088
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_D() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;  cin >> N;
    string S; cin >> S;

    stack<char> op;
    deque<char> dq;

    REP(i,N) {
        if (S[i] == '(') {
            op.push('(');
            dq.push_back('(');
        } else {
            if (!op.empty()) {
                op.pop();
            } else {
                dq.push_front('(');
            }
            dq.push_back(')');
        }
    }
    while(!op.empty()) {
        op.pop();
        dq.push_back(')');
    }

    string ans = "";
    while(!dq.empty()) {
        ans += dq.front(); dq.pop_front();
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    ship = [[] for _ in range(n)]
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        ship[a].append(b)
        ship[b].append(a)
    for i in range(1, n - 1):
        if 0 in ship[i] and n - 1 in ship[i]:
            print("POSSIBLE")
            break
    else:
        print("IMPOSSIBLE")


if __name__ == '__main__':
    main()



Measured memory_bytes: 38320
dic, link = (dict() for i in range(2))
n = int(input())
se = set(int(x) for x in range(n))

for i in range(n):
    a, b, c = map(int, input().split())
    link[a] = list()
    for bc in [b, c]:
        link[a].append(bc)
        se.discard(bc)

rt = se.pop()
pre_odr, in_odr, pst_odr = ([] for i in range(3))


def dfs_pr(u):
    pre_odr.append(u)
    for e in link[u]:
        if e >= 0: dfs_pr(e)


def dfs_in(u):
    for i in range(2):
        if i < len(link[u]):
            if i != 0 and u not in used:
                in_odr.append(u)
                used.add(u)
            e = link[u][i]
            if e < 0: continue
            dfs_in(e)
            if e not in used:
                in_odr.append(e)
                used.add(e)


def dfs_ps(u):
    for e in link[u]:
        if e >= 0: dfs_ps(e)
    pst_odr.append(u)


print("Preorder")
dfs_pr(rt)
print("", *pre_odr)

print("Inorder")
used = set()
dfs_in(rt)
if len(in_odr) == 0: in_odr.append(0)
print("", *in_odr)

print("Postorder")
dfs_ps(rt)
print("", *pst_odr)



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

int main(){
  vector<int> s(101);
  int N;
  vector<int> rel(101,0);
  
  cin>>N;
  for(int i=0;i<N;i++) s[i]=0;
  
  for(int i=0;i<N*(N-1)/2;i++){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(C>D) s[A-1]+=3;
    else if(C<D) s[B-1]+=3;
    else {
      s[A-1]++;
      s[B-1]++;
    }
  }

  int count=0,b=-1,p;
  while(1){
    int m=0,ans;
    if(count==N) break;
    count++;
    for(int i=0;i<N;i++){
      m=max(m,s[i]);
      if(m==s[i]) ans=i;
    }
    if(b!=s[ans])rel[ans]=count;
    else rel[ans]=rel[p];
    b=s[ans];
    p=ans;
    s[ans]=-1;
  }

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

Measured memory_bytes: 1196
n, a, b = map(int, input().split())
s = input()
plus = a+b
for i in range(n):
    if s[i] == "a" and 0 < plus:
        print("Yes")
        plus -= 1
    elif s[i] == "b" and 0 < b and 0 < plus:
        print("Yes")
        b -= 1
        plus -= 1
    else:
        print("No")

Measured memory_bytes: 4016
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = br.readLine()) != null) {
			String[] arr = line.split(" ");
			int h = Integer.parseInt(arr[0]);
			int w = Integer.parseInt(arr[1]);
			if (h == 0 && w == 0)
				break;

			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if ((i + j) % 2 == 0)
						System.out.print("#");
					else
						System.out.print(".");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 25952
#include <algorithm>
#include <cstdio>
#include <vector>

static const size_t n_max = 25;
static size_t parents[n_max];
static int depths[n_max], heights[n_max];
static size_t siblings[n_max];
static std::pair<size_t, size_t> children[n_max];

int rec(size_t i, int d) {
  depths[i] = d;
  int h = 0;
  if (children[i].first != size_t(-1))
    h = std::max(h, 1 + rec(children[i].first, d + 1));
  if (children[i].second != size_t(-1))
    h = std::max(h, 1 + rec(children[i].second, d + 1));
  return heights[i] = h;
}

int main() {
  size_t n;
  scanf("%zu\n", &n);
  std::fill(parents, parents + n, size_t(-1));
  std::fill(siblings, siblings + n, size_t(-1));
  for (size_t i = 0; i < n; i++) {
    size_t j;
    int l, r;
    scanf("%zu%d%d", &j, &l, &r);
    children[j].first = size_t(l);
    children[j].second = size_t(r);
    siblings[l] = size_t(r);
    siblings[r] = size_t(l);
    if (l >= 0)
      parents[l] = j;
    if (r >= 0)
      parents[r] = j;
  }
  rec(std::find(parents, parents + n, size_t(-1)) - parents, 0);
  for (size_t i = 0; i < n; i++) {
    int d = 0;
    if (children[i].first != size_t(-1))
      d++;
    if (children[i].second != size_t(-1))
      d++;
    printf("node %zu: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
           i, int(parents[i]), int(siblings[i]), d, depths[i], heights[i],
           parents[i] == size_t(-1) ? "root" : d ? "internal node" : "leaf");
  }
  return 0;
}

Measured memory_bytes: 2676
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

int lucas(int n, int r) {
	for(int i = 0; i < 20; i++) {
		if(!(n & (1 << i)) && (r & (1 << i)))
			return 0;
	}
	return 1;
}

int odd_ans(vector<int> v) {
	int n = v.size(), ans = 0;
	for(int i = 0; i < n; i++) {
		if(v[i] % 2 && lucas(n - 1, i)) {
			ans ^= 1;
		}
	}
	return ans;
}

// https://atcoder.jp/contests/agc043/tasks/agc043_b
signed main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	//int t = 1; cin >> t; while(t--)
	{
		int n;
		string s;
		cin >> n >> s;

		vector<int> a(n);
		for(int i = 0; i < n; i++)
			a[i] = s[i] - '0';

		vector<int> b;
		for(int i = 0; i < (int)a.size() - 1; i++) {
			b.push_back(abs(a[i] - a[i + 1]));
		}
		a = b;
		n--;

		if(n == 1)
			return cout << a[0], 0;

		int ans = 0;
		if(odd_ans(b)) 
			return cout << "1\n", 0;
		
		for(auto& x : b) {
			if(x == 1)
				return cout << "0\n", 0;
			x /= 2;
		}

		if(odd_ans(b))
			cout << "2\n";
		else
			cout << "0\n";
	}
	
	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}



Measured memory_bytes: 26000
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, int num=0){
  if(num == 0) num = (int)v.size();
  if(is_reverse) for(int i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";}
  else for(int i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, int num=0){
  if(num == 0) num = (int)v.size();
  for(int i=0; i<num; i++){ cout << v[i].first << v[i].second; if(i!=num-1) cout << " ";}
  cout << endl;
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<ll> w(n);
  for(int i=0; i<n; i++) cin >> w[i];

  ll left = 0, right = 1e9 + 1;
  while(right - left > 1){
    ll mid = (left + right) /2;
    vector<ll> track(k, 0);
    int id = 0;
    bool is_can = true;
    for(int i=0; i<n; i++){
      while(track[id]+w[i] > mid){
        id++;
        if(id>=k){
          is_can = false;
          break;
        }
      }      
      if(is_can == false) break;
      track[id] += w[i];
    }
    if(track.back() > mid) is_can = false;
    
    if(is_can) right = mid;
    else left = mid;
  }
  cout << right << endl;


  // 以下問題勘違いして トラックの順番を毎回変えられるものだと
  // sort(w.rbegin(), w.rend());
  // priority_queue<ll, vector<ll>, greater<ll>> _pri_qu;
  // for(int i=0; i<k; i++) _pri_qu.push(0);
  // ll left = 0, right = 1e9+1;
  // while(right - left > 1){
  //   ll mid = (left + right) /2;
  //   bool is_can = true;
  //   priority_queue<ll, vector<ll>, greater<ll>> pri_qu = _pri_qu;
  //   for(int i=0; i<n; i++){
  //     ll track = pri_qu.top();
  //     pri_qu.pop();
  //     if(track + w[i] > mid) is_can = false;
  //     pri_qu.push(track+w[i]);
  //   }

  //   if(is_can) right = mid;
  //   else left = mid;
  // }
  // cout << right << endl;
}




Measured memory_bytes: 4428
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			for k := 0; k <= n-i-j; k++ {
				if y == (i*10000+j*5000+k*1000) && n == i+j+k {
					fmt.Println(i, j, k)
					return
				}
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
    int n, x, ans;
    while(true){
        std::cin >> n >> x;
        ans = 0;
        if (n == 0 && x == 0){
            break;
        }
        else if (x < 6){
            std::cout << "0" << endl;
        }
        else {
            for (int i=1; i<=n; ++i){
                for (int j=i+1; j<=n; ++j){
                    if (x-i-j > j && x-i-j <= n && x-i-j != i && x-i-j != j){
                        ans++;
                        // std::cout << i << "+" << j << "+" << x-i-j << endl;
                    }
                }
            }
            std::cout << ans << endl;
        }
    }
    return 0;
}



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

map<long long, long long> memo;


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

	for(long long i = 0; i < N; i++) {
		long long a;
		cin >> a;
		memo[a]++;
	}
	long long ans = 0;
	for( auto i = memo.begin(); i != memo.end() ; ++i ) {
		ans += i->second * i->first;
	}

	long long Q;
	cin >> Q;
	for(long long i = 0; i < Q; i++) {
		long long b, c;
		cin >> b >> c;
		ans -= memo[b] * b;
		ans += memo[b] * c;
		memo[c] += memo[b];
		memo[b] = 0;
		cout << ans << endl;
	}


}

Measured memory_bytes: 9404
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	vector<long double> v;
	
	cin>>N;
	
	v.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>v[i];
	}
	
	sort(v.begin(), v.end());
	// sort(v.begin(), v.end(), greater<long double>());
	
	for(int i = 1; i < N; i++){
		v[i] = (v[i] + v[i-1])/2;
	}
	
	cout<<v.back()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

int barg[60];
int meet[60];

int N, X;

int calc(int x, int l) {
    if (x == 0) {
        return 0;
    }

    if (x == barg[l]) {
        return meet[l];
    }

    if (x >= barg[l-1] + 2 ) {
        return meet[l-1] + 1 + calc(x - barg[l-1] - 2, l - 1);
    } else {
        return calc(x - 1, l - 1);
    }
}

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

    cin >> N >> X;

    barg[0] = 1;
    meet[0] = 1;
    for (int i = 1; i <= N; i++) {
        barg[i] = 2 * barg[i-1] + 3;
        meet[i] = 2 * meet[i-1] + 1;
    }
    cout << endl;

    cout << calc(X, N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
//sort(all(x))とするとソートできるよ

int main(){
    double W,H,x,y;cin >> W >> H >> x >>y ;
    int ans;
    if(W/2 == x && H/2 == y){
        ans = 1;
    }
    else{
        ans = 0;
    }
    cout << H*W/2.0 << ' ' << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	string s[] = {"MON","TUE","WED","THU","FRI","SAT","SUN","MON","TUE","WED","THU","FRI","SAT","SUN"};
	int n = 14;
	string t;
	cin >> t;
	
	for(int i = 0; i < n; i++){
		if(s[i] == t){
			int cnt = 0;
			for(int j = i+1; j < 14; j++){
				cnt++;
				if(s[j] == "SUN"){
					cout << cnt << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}



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

Measured memory_bytes: 3596