akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(0LL,min(b,d)-max(a,c))<<endl;
}


Measured memory_bytes: 256
n=int(input())
s=input()
ans=10**9
w=[0]*n
b=[0]*n
cw,cb=0,0
for i in range(n):
  if s[i]==".":
    cw+=1
  else:
    cb+=1
  w[i]=cw
  b[i]=cb

for i in range(n):
  ans=min(ans,b[i]+w[-1]-w[i])
ans=min(ans,b[-1],w[-1])
print(ans)


Measured memory_bytes: 12904
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=1e9+7;
    const int N=1e6+5; 
    const ll inf=1e18+5;
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
        }
       
        
     
        int main()
    {
        FAST;
        ll n;
        cin>>n;
        vll a(n);
        for(ll i=0;i<n;i++)
        cin>>a[i];
       ll dp[n+1][n+1];
       for(ll L=n-1;L>=0;L--)
       {
           for(ll R=L;R<n;R++)
           {
               if(L==R)
               dp[L][R]=0;
               else
               {
                  dp[L][R]=inf;
                  ll s=0;
                  for(ll i=L;i<=R;i++)
                  s+=a[i];
                  for(ll i=L;i<R;i++)
                  dp[L][R]=min(dp[L][R],dp[L][i]+dp[i+1][R]+s);
                  
               }
           }
       }
       cout<<dp[0][n-1];
        return 0;
    }

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<ll> a(n);
    ll suma=0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        suma+=a[i];
    }
    ll sums=a[0];
    suma-=a[0];

    ll ans=abs(suma-sums);
    for(int i = 1; i < n-1; i++) {
        sums+=a[i];
        suma-=a[i];
        ll tans=abs(suma-sums);
        ans=min(ans,tans);
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    ll x,y;
    cin >> x >> y;
    int ans = 0;
    
    while(x<=y){
        ans++;
        x *= 2;
    }
    
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	int n, m, x, y;
	int i, j;
	int xz = -INF;
	int yz = INF;
	cin >> n >> m >> x >> y;

	rep(i, n) {
		int xx;
		cin >> xx;
		xz = max(xz, xx);
	}
	rep(j, m) {
		int yy;
		cin >> yy;
		yz = min(yz, yy);
	}
	if (xz >= yz || xz >= y || yz <= x) 
		cout << "War" << endl;
	else
		cout << "No War" << endl;
	return 0;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

int main() {
	ll K, S; cin >> K >> S;
	ll cnt = 0;
	for (int x = 0; x <= K; x++) {
		for (int y = 0; y <= K; y++) {
			if (S - x - y >= 0 && S - x - y <= K)cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
//ABC136 B - Uneven Numbers
//20190905

using System;
using System.Linq;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            // Console.WriteLine("Hello World!");
            int N = int.Parse(Console.ReadLine());
            double OUTPUT = 0;

            if (N < 10)
            {
                OUTPUT = N;
            }
            else if (N < 100)
            {
                OUTPUT = 9;
            }
            else if (N < 1000)
            {
                OUTPUT = 9 + N - 99;
            }
            else if (N < 10000)
            {
                OUTPUT = 9 + 900;
            }
            else if (N < 100000)
            {
                OUTPUT = 9 + 900 + N - 9999;
            }
            else
            {
                OUTPUT = 9 + 900 + 90000 ;
            }

            Console.WriteLine(OUTPUT);

        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>

int main(){
  int H,A[251],i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i != 1)printf("parent key = %d, ",A[i/2]);
    if(i*2 <= H)printf("left key = %d, ",A[2*i]);
    if(i*2+1 <= H)printf("right key = %d, ",A[2*i+1]);
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
using namespace std;
 
int main() {
	int a,b;
	cin >> a;
	b=0;
	for(int i = a;i>0;i--){
		if(0<i&&i<10){b++;}
		else if(99<i&&i<1000){b++;}
		else if(9999<i&&i<100000){b++;}
	}
	cout << b << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
	int N, A, i, j, d;
	scanf("%d", &N);
	A = 0;
	for(i = 1; i <= N; i+=2){
		d = 2;
		for(j = 2; j < i-1; j++) if(i % j == 0) d++;
		if(d == 8) A++;
	}
	printf("%d", A);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

class SegmentTree {
  private:
    ll n;
    vector<ll> dat;

  public:
    SegmentTree() {}
    SegmentTree(ll n) { init(n); }
    ~SegmentTree() {}
    void init(int n_) {
        n = 1;
        while (n < n_) {
            n *= 2;
        }
        dat.resize(2 * n - 1);
        for (ll i = 0; i < 2 * n - 1; i++) {
            dat[i] = 0;
        }
    }
    void update_inc(ll k) {
        k += n - 1;
        dat[k]++;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
        }
    }
    void update_dec(ll k) {
        k += n - 1;
        dat[k]--;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
        }
    }
    ll query(ll a, ll b) { return query(a, b, 0, 0, n); }
    ll query(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a || b <= l) {
            return 0;
        }
        if (a <= l && r <= b) {
            return dat[k];
        } else {
            ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return vl + vr;
        }
    }
};

int main() {
source:
    ll n, q;
    string s;
    cin >> n >> s >> q;
    vector<char> s_char(n);
    vector<SegmentTree> st(26, SegmentTree(n));
    rep(i, n) {
        s_char[i] = s[i];
        st[s[i] - 'a'].update_inc(i);
    }
    vector<ll> ans;

    rep(l0, q) {
        ll num;
        cin >> num;
        if (num == 1) {
            ll i;
            char c;
            cin >> i >> c;
            char c_old = s_char[i - 1];
            s_char[i - 1] = c;
            st[c_old - 'a'].update_dec(i - 1);
            st[c - 'a'].update_inc(i - 1);
        } else {
            ll l, r;
            cin >> l >> r;
            ll counter = 0;
            rep(i, 26) {
                if (st[i].query(l - 1, r) > 0) {
                    counter++;
                }
            }
            ans.push_back(counter);
        }
    }

    rep(i, ans.size()) { cout << ans[i] << endl; }

    return 0;
}



Measured memory_bytes: 222724
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

def inpl_strl(): return list(sys.stdin.readline())

a, b = inpl()
for i in range(10000):
    if int(i * 0.08) == a and int(i * 0.1) == b:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 3944
import sys

N=int(input())
A = list(map(int,input().split()))
 
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

if gcd_list(A) > 1:
    print("not coprime")
    sys.exit()

D = [i for i in range(max(A)+1)] #iを割り切る最小の素数を格納
p = 2
 
while(p*p<=max(A)):
    if D[p]==p:
        for i in range(p*p,max(A)+1,p):
            if D[i]==i:
                D[i]=p
 
    p+=1
    
prime = set()
for a in A:
    tmp=D[a]
    L=set()
    while(a>1):
        a=a//tmp
        L.add(tmp)
        tmp=D[a]

    for l in L:
        if l in prime:
            print("setwise coprime")
            sys.exit()
        else:
            prime.add(l)

print("pairwise coprime")

Measured memory_bytes: 217920
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef pair<int,int> state;

int N,M,x,y;
P t[100];
int f[100][100];
int d[100][100];

int solve(){
  int si=0,ti,ans=0;
  double mini=1e9;
  for(int i=0;i<N;i++)
    if(t[i].real()<t[si].real())si=i;
  deque<state> Q;    
  for(int i=0;i<N;i++)
    if(f[si][i] && arg(t[i]-t[si])< mini)
      ti=i,mini=arg(t[i]-t[si]);
  Q.push_back(state(si,ti));
  d[si][ti]=0;
   
  while(!Q.empty()){
    state p=Q.front();
    Q.pop_front();
    int from=p.first;
    int to=p.second;
    ans=max(ans,d[from][to]);
    
    if(d[from][to]+1<d[to][from]){
      d[to][from]=d[from][to]+1;
      Q.push_back(state(to,from));
    }
    int id=-1;
    double mini=1e9;
    for(int i=0;i<N;i++){
      if(f[to][i]&&i!=from){
        if( arg( (t[i]-t[to])*conj(t[to]-t[from]) ) < mini){
          id=i;
          mini=arg( (t[i]-t[to])*conj(t[to]-t[from]) );
        }
      }
    }
    if(id!=-1&&d[to][id]>d[from][to]){
      d[to][id]=d[from][to];
      Q.push_front(state(to,id));
    }
  }
  return ans;
}

int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    memset(f,0,sizeof(f));
    memset(d,1,sizeof(d));
    for(int i=0;i<N;i++){
      cin>>x>>y;
      t[i]=P(x,y);
    }
    for(int i=0;i<M;i++){
      cin>>x>>y;
      x--,y--;
      f[x][y]=f[y][x]=true;
    }
    cout<<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1360
import heapq
x,y,z,k= map(int,input().split())
alist = sorted(list(map(int,input().split())),reverse=True)
blist = sorted(list(map(int,input().split())),reverse=True)
clist = sorted(list(map(int,input().split())),reverse=True)
l = [(-(alist[0]+blist[0]+clist[0]),0,0,0)]
heapq.heapify(l)
count=0
ai=bi=ci=0
selected = set()
selected.add((0,0,0))
while len(l)!=0:
    temp = heapq.heappop(l)
    (tempa,tempb,tempc)=temp[1:]
    print(-temp[0])
    count += 1
    if count==k:break
    if tempa+1<=x-1:
        if not (tempa+1,tempb,tempc) in selected:
            heapq.heappush(l,(-(alist[tempa+1]+blist[tempb]+clist[tempc]),tempa+1,tempb,tempc))
            selected.add((tempa+1,tempb,tempc))    
    if tempb+1<=y-1:
        if not (tempa,tempb+1,tempc) in selected:
            heapq.heappush(l,(-(alist[tempa]+blist[tempb+1]+clist[tempc]),tempa,tempb+1,tempc))
            selected.add((tempa,tempb+1,tempc))
    if tempc+1<=z-1:
        if not (tempa,tempb,tempc+1) in selected:
            heapq.heappush(l,(-(alist[tempa]+blist[tempb]+clist[tempc+1]),tempa,tempb,tempc+1))
            selected.add((tempa,tempb,tempc+1))

Measured memory_bytes: 4964
#include<bits/stdc++.h>
using namespace std;
const int Max_N=3*1e2;
int N,M,L,Q,Num=0;
long long A[Max_N+10][Max_N+10]={},f[Max_N+10][Max_N+10]={};
int main(){
	memset(A,30,sizeof(A));
	scanf("%d%d%d",&N,&M,&L);
	for(int i=1;i<=M;i++){
		int a,b,l; scanf("%d%d%d",&a,&b,&l);
		A[a][b]=A[b][a]=l;
	}
	for(int i=1;i<=N;i++) A[i][i]=0;
	for(int k=1;k<=N;k++)
	 for(int i=1;i<=N;i++)
	  for(int j=1;j<=N;j++)
	   if(A[i][k]+A[k][j]<A[i][j])
	    A[i][j]=A[i][k]+A[k][j];
//	for(int i=1;i<=N;i++)
//	 for(int j=1;j<=N;j++)
//	  cout<<"Map:"<<i<<' '<<j<<' '<<A[i][j]<<endl;
	memset(f,30,sizeof(f));
	for(int i=1;i<=N;i++) f[i][i]=0;
	for(int T=50;T;T--)
	for(int k=1;k<=N;k++)
	 for(int i=1;i<=N;i++)
	  for(int j=1;j<=N;j++)
	   if(A[k][j]<=L&&f[i][k]+1<=f[i][j])
	    f[i][j]=f[i][k]+1,f[j][i]=f[i][j];
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++){
		int a,b; scanf("%d%d",&a,&b);
		if(f[a][b]>=f[0][0]) puts("-1");
		else printf("%lld\n",max(f[a][b]-1,0LL));
	}
	return 0;
}

Measured memory_bytes: 2048
// Nurbakyt Madibek
// Look at my code! IT'S AWESOME

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)1e5 + 5;
const int mod = (int)1e9 + 7;

int n;
int a[MAX_N], cnt[MAX_N];

void out(bool tp) {
    if (!tp)
        puts("No");
    else
        puts("Yes");
    exit(0);
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    scanf("%d", &n);
    set < int > q;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        q.insert(a[i]);
        cnt[a[i]]++;
    }
    if (sz(q) > 2)
        out(0);
    int val = *q.rbegin();
    if (val == n - 1 && cnt[val] == n)
        out(1);
    if (val < 1 || val - *q.begin() > 1)
        out(0);
    if (val < cnt[val - 1])
        out(0);
    int have = val - cnt[val - 1];
    if (have == 0 && cnt[val] > 0)
        out(0);
    if (cnt[val] >= have * 2)
        out(1);
    out(0);
    return 0;
}

Measured memory_bytes: 5760
using System;

class main
{
    public static int n = 1000001;
    static void Main()
    {
        string s;
        int[] p = new int[n];
        for (int i = 2; i < 1001; ++i)
            for (int j = i * 2; j < n; j += i)
                p[j] = 1;
        while ((s = Console.ReadLine()) != null)
        {
            int c = int.Parse(s);
            int q = 0;
            for (int i = 2; i <= c; ++i)
                if (p[i] != 1) ++q;
            Console.WriteLine("{0}", q);
        }
    }
}

Measured memory_bytes: 9532
M = 10**9 + 7
n, a, b = map(int, input().split())
r = pow(2, n, M) - 1
f = c = 1
l = iter((a,b))
for i in range(b):
  f = f * (i + 1) % M
  c = c * (n - i) % M
  if i + 1 == a:
    a = b
    r -= c * pow(f, M - 2, M)
print(r % M)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long int
#include<list>
#include<algorithm>
#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 UMP unordered_map
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#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; 
}
ll arr1[101];
ll cost[101][101];
ll n, m, x;
ll mini = MAX;
void printArray(vector<ll> arr, ll n1) 
{ 
    ll i,j,k;
    ll cost1 = 0;
    rep(i,0,n1)
    {
        cost1+=arr1[arr[i]];
    }
    rep(i,0,m)
    {
        ll xd = 0;
        rep(j,0,n1)
        {
            xd += cost[arr[j]][i];
        }
        if(xd<x)
            return;
    }
    mini = min(mini, cost1);
} 
void printSubsequences(ll arr[], ll index, vector<ll> subarr) 
{ 
    if (index == n) 
    { 
        ll l = subarr.size(); 
  
        if (l != 0) 
            printArray(subarr, l); 
    } 
    else
    { 
        printSubsequences(arr, index + 1, subarr); 
  
        subarr.push_back(index); 
  
        printSubsequences(arr, index + 1, subarr); 
    } 
    return; 
} 
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-10 18:10 
    */
    cin>>n>>m>>x;
    rep(i,0,n)
    {
        cin>>arr1[i];
        rep(j,0,m)
        {
            cin>>cost[i][j];
        }
    }
    vector<ll>subarr;
    printSubsequences(arr1, 0, subarr);
    if(mini==MAX)
        cout<<-1;
    else
        cout<<mini;
}




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

 using namespace std;

 int main() {
   int mina, maxz, i;
   string S;
   cin >> S;

   mina = S.length();
   maxz = 0;
   for (i = 0; i < S.length(); i++) {
     if (S.at(i) == 'A') mina = min(mina, i);
     else if (S.at(i) == 'Z') maxz = max(maxz, i);
   }

   cout << maxz - mina + 1 << endl;
 }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"

const int N =  2e5 + 5;
int xx[4]={0,0,1,-1};
int yy[4] ={1,-1,0,0};

int32_t main(){
   boost;
   int n,m,k;
   cin>>n>>m>>k;
   int x1,y1,x2,y2;
   cin>>x1>>y1>>x2>>y2;
   char c[n+1][m+1];
   for(int i=1;i<=n;i++){
      for(int j=1;j<=m;j++)
         cin>>c[i][j];
   }
   int dp[n+1][m+1];
   memset(dp,1,sizeof dp);
   dp[x1][y1] = 0;
   queue<array<int,2>>q;
   q.push({x1,y1});
   while(!q.empty()) {
      array<int,2> p = q.front();
      q.pop();
      if(p[0]==x2 && p[1]==y2)
         break;
      for(int i=0;i<4;i++){
         for(int j=1;j<=k;j++){
            int x = p[0] + xx[i]*j;
            int y = p[1] + yy[i]*j;
            if(x<1 or x>n or y<1 or y>m or c[x][y]=='@')
               break;
            if(dp[x][y]<dp[p[0]][p[1]]+1)
               break;
            if(dp[x][y] > dp[p[0]][p[1]]+1){
               dp[x][y] = dp[p[0]][p[1]]+1;
               q.push({x,y});
            }
         }
      }
   }
   if(dp[x2][y2] == dp[0][0])
      cout<<-1<<endl;
   else
      cout<<dp[x2][y2]<<endl;
}



Measured memory_bytes: 12452
//---------- Begin IO utilities ----------
// Thanks to https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:tt : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! p {
    ($v:ident) => {
        println!("{}", $v);
    };
    ($v:ident, $($t:ident),*) => {
        print!("{}", $v);
        ($(print!(" {}", $t)),*);
        println!();
    }
}
#[allow(unused_macros)]
macro_rules! ps {
    ($v:ident) => {
        println!("{}", $v.iter().collect::<String>());
    };
    ($v:ident, $($t:ident),*) => {
        print!("{}", $v.iter().collect::<String>());
        ($(print!(" {}", $t.iter().collect::<String>())),*);
        println!();
    }
}
#[allow(dead_code)]
fn pv<T: std::string::ToString>(v: &[T], sep: &str) {
    let s = v.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep);
    println!("{}", s);
}
#[allow(dead_code)]
fn pvs(v: &[Vec<char>], sep:&str) {
    let s = v.iter().map(|e| e.iter().collect::<String>()).collect::<Vec<String>>().join(sep);
    println!("{}", s);
}
//---------- End IO utilities ----------

fn main() {
    input!{
        s: i32,
        w: i32,
    }
    if s <= w {
        println!("unsafe");
    } else {
        println!("safe");
    }
}


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

int main(void) {
    int a[60], b[60], i, j, M, N, R[60]={0};
    scanf("%d%d", &N, &M);
    for (i=0;i<M;i++) scanf("%d%d", &a[i], &b[i]);

    for (i=0;i<M;i++) {
        R[a[i]]++; R[b[i]]++;
    }
    for (j=1;j<=N;j++) {
        printf("%d\n", R[j]);
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int w,h,n;
   cin >> w >> h >> n;
   int x[110] = {0};
   int y[110] = {0};
   int a[110] = {0};
   rep(i,n) cin >> x[i] >> y[i] >> a[i];

   int rect[w][h] = {0};
   rep(i,n){
         for(int j=0;j<w;j++){
            for(int k=0;k<h;k++){
               if(a[i] == 1){
                  if(j<x[i]) rect[j][k] = 1;
               }else if(a[i] == 2){
                  if(j>=x[i]) rect[j][k] = 1;
               }else if(a[i] == 3){
                  if(k<y[i]) rect[j][k] = 1;
               }else if(a[i] == 4){
                  if(k>=y[i]) rect[j][k] = 1;
               }
               }        
            }
         }       

   int cnt = 0;
   for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
         if(rect[i][j] == 0 ) cnt++;
      }
   }

   cout << cnt << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>

using namespace std;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;

    int result = (int)ceil((double)n / (double)x) * t;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0index
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1index
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //?index
#define all(x) (x).begin(),(x).end()
#define put(x) cout << x << endl;
const int INF = 1000000007;  //MOD
typedef long long ll;
using namespace std;
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; }

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }  //GCD

int N;
long long W, weight[110], value[110]; 

long long dp[110][100100] = {0};
int main(){
     cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

           
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    
    cout << dp[N][W] << endl;
    return 0;
} 

Measured memory_bytes: 79360
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 998244353, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> key;

ll dp[1001][(1 << 12)];
key keys[1000];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> M;
	rep(i, M + 1) {
		rep(j, (1 << N)) {
			dp[i][j] = MAX;
		}
	}
	dp[0][0] = 0;
	rep(i, M) {
		cin >> A >> B;
		ll sum = 0;
		rep(j, B) {
			cin >> C; C--;
			sum += (1 << C);
		}
		keys[i] = key(A, sum);
	}
	rep(i, M) {
		rep(j, (1 << N)) {
			dp[i + 1][j | keys[i].second] = min(dp[i + 1][j | keys[i].second], dp[i][j] + keys[i].first);
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	if (dp[M][(1 << N) - 1] == MAX) cout << -1;
	else cout << dp[M][(1 << N) - 1];
}

Measured memory_bytes: 35672
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int n;
    cin >> n;
    vector<int> c(n);
    vector<modint> CumulativeSum(n + 1);
    for(int i = 0; i < n; ++i)  cin >> c[i];
    sort(c.begin(), c.end());
    for(int i = 0; i < n; ++i){
        CumulativeSum[i + 1] = CumulativeSum[i] + c[i];
    }

    modint ans = 0;
    modint x1 = modint(2).pow(n - 1);
    modint x2 = modint(2).pow(max(n - 2, 0));
    for(int i = 0; i < n; ++i){
        ans += x1 * c[i];
        ans += x2 * CumulativeSum[i];
    }
    ans *= modint(2).pow(n);
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll solve(string s, ll k)
{
    ll d = 0, c = 0, m = 0, mc = 0;
    for(ll i = 0; i < k; i++)
    {
        if(s[i] == 'D')
            d++;
        else if(s[i] == 'M')
            m += d, mc++;
        else if(s[i] == 'C')
            c += m;
    }
    for(ll i = k; i < s.size(); i++)
    {
        if(s[i - k] == 'D')
        {
            m -= mc;
            d--;
        }
        else if(s[i - k] == 'M')
            mc--;
        if(s[i] == 'D')
            d++;
        else if(s[i] == 'M')
            m += d, mc++;
        else if(s[i] == 'C')
            c += m;
    }
    return c;
}
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    string s;
    ll n, q, i;
    cin >> n >> s >> q;
    vll k(q);
    for(i = 0; i < q; i++)  
        cin >> k[i];
    for(auto x : k)
        cout << solve(s, x) << endl;
    return 0;
}

Measured memory_bytes: 2460
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
using namespace std;
using ll = long long;
const int INF = 999999999;

int gcd(int x, int y) {
    if(x < y) swap(x, y);
    if(y == 0) return x;
    return gcd(x%y, y);
}

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

    vector<int> csl(N+1, 0), csr(N+1, 0);
    csl[1] = A[0];
    csr[N-1] = A[N-1];

    for(int i = 2; i <= N; i++) {
        csl[i] = gcd(csl[i-1], A[i-1]);
    }

    for(int i = N-2; i >= 0; i--) {
        csr[i] = gcd(csr[i+1], A[i]);
    }

    int ans = (-1) * INF;
    for(int i = 0; i < N; i++) {
        ans = max(ans, gcd(csl[i], csr[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
unittest
{
	assert( [ "600", "300", "220", "420" ].parse.expand.solve == 520 );
	assert( [ "555", "555", "400", "200" ].parse.expand.solve == 755 );
	assert( [ "549", "817", "715", "603" ].parse.expand.solve == 1152 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto a = input.front.strip.to!( long );
	input.popFront;
	auto b = input.front.strip.to!( long );
	input.popFront;
	auto c = input.front.strip.to!( long );
	input.popFront;
	auto d = input.front.strip.to!( long );
	return tuple( a, b, c, d );
}

auto solve( long a, long b, long c, long d )
{
	return min( a, b ) + min( c, d );
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 2000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  string s;
  cin>>s;
  cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
  return 0;
}


Measured memory_bytes: 764
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 配列数の決定
		int number = sc.nextInt();
		
		//LeftNumberの決定
		int LeftNumber[] = new int[number];
		for(int i = 0; i < number; i++) {
			 LeftNumber[i] = sc.nextInt();
		}
		
		//RightNumberの決定
		int RightNumber[] = new int[number];
		for(int i = 0; i < number; i++) {
			 RightNumber[i] = sc.nextInt();
		}
		
		
		//引き算の結果を受けて加算していく
		int Sum = 0;
		int sa = 0;
		for(int i = 0; i < number; i++) {
			sa =  LeftNumber[i] -  RightNumber[i];
			if(sa > 0){
				Sum = Sum + sa;
			}
		}
		
		// 出力
		System.out.println(Sum);
	}
}

Measured memory_bytes: 23632
#include "bits/stdc++.h"
using namespace std;

const int N=2e5+20;

int n;
long long ans;
map <int,int> m;

int main()
{
    
	scanf("%d",&n);
    int a[n+1];
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		ans+=m[a[i]-i];
		m[-a[i]-i]++;
	}

	cout<<ans;
}


Measured memory_bytes: 21532
#include <cmath>
#include <iostream>

using namespace std;
int main()
{
    long long a, b;
    cin >> a >> b;
    if ((a - b) % 2 != 0)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << (a + b) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int v[50];

void sort(int n,int x[]){
    int m,i,temp;
    for(m=n;m>0;m--){
        for(i=0;i<m-1;i++){
            if(x[i]>x[i+1]) temp=x[i],x[i]=x[i+1],x[i+1]=temp;
        }
    }
}

double function(int n){
    if(n==2) return (v[0]+v[1])/2.0;
    return (function(n-1)+v[n-1])/2.0;
}

int main(){
    int n,i;
    double S=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&v[i]);
    }
    sort(n,v);
    S=function(n);
    printf("%lf\n",S);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define mod (ll)1000000007
#define MAX 100005
using namespace std;
int dp[MAX][3];
int n;
vector<vector<int> > a(MAX,vector<int>(3));

int rec(int pos, int prevch)
{
	if(pos == n)
		return 0;

	if(dp[pos][prevch] != -1)
		return dp[pos][prevch];


	dp[pos][prevch] = INT_MIN;

	for(int i = 0; i < 3; i++)
	{
		if(i!=prevch)
			dp[pos][prevch] = max(dp[pos][prevch], rec(pos+1,i)+a[pos][i]);	
	}

	return dp[pos][prevch];
}


int main()
{
	cin>>n;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < 3; j++)
			cin>>a[i][j];

	memset(dp,-1,sizeof(dp));

	int ans = INT_MIN;
	for(int i = 0; i < 3; i++)
		ans = max(ans,rec(1,i)+a[0][i]);

	cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 14720
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <climits>
struct Taxi {
	int cost, distance;
};
struct Town {
	std::vector<int> route{};
};

int main() {
	int n, k;
	std::cin >> n >> k;
	std::vector<Taxi> taxis(n);
	for (auto &taxi : taxis) std::cin >> taxi.cost >> taxi.distance;
	std::vector<Town> towns(n);
	for (auto i = 0; i < k; ++i) {
		int from, to;
		std::cin >> from >> to;
		towns[from - 1].route.push_back(to - 1);
		towns[to - 1].route.push_back(from - 1);
	}
	std::vector<int> memo(n, INT_MAX);
	memo[0] = 0;
	std::vector<int> is_on_pass(n, -1);
	std::queue<int> next;
	std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::function<bool(const std::pair<int, int>&, const std::pair<int, int>&)>> priority_queue([](const std::pair<int, int> &a, const std::pair<int, int> &b) {return a.second > b.second; });
	priority_queue.push(std::make_pair(0, 0));
	while (!priority_queue.empty() && priority_queue.top().first != n - 1) {
		auto top = priority_queue.top();
		priority_queue.pop();
		if (memo[top.first] == top.second) {
			for (const auto &to : towns[top.first].route) next.push(to);
			for (auto i = 1; i <= taxis[top.first].distance; ++i) {
				for (auto j = next.size(); j > 0; --j) {
					if (memo[next.front()] > top.second + taxis[top.first].cost) {
						memo[next.front()] = top.second + taxis[top.first].cost;
						priority_queue.push(std::make_pair(next.front(), memo[next.front()]));
					}
					if (is_on_pass[next.front()] != top.first && i != taxis[top.first].distance) {
						is_on_pass[next.front()] = top.first;
						for (const auto &n : towns[next.front()].route) next.push(n);
					}
					next.pop();
				}
			}
		}
	}
	std::cout << memo[n - 1] << std::endl;
}


Measured memory_bytes: 3476
import * as fs from 'fs';

namespace AtCoder.abc114 {
    export class Program {
        static main(inp: string): void {

            const x: number = parseInt(inp);
            if (x === 3 || x === 5 || x === 7) {
                console.log('YES');
            } else {
                console.log('NO');
            }
        }
    }
}

AtCoder.abc114.Program.main(fs.readFileSync('/dev/stdin', 'utf8').trim());

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int two_table[2200000];
bool pascal_mod2(int n, int r) {
    return two_table[n] == two_table[r] + two_table[n - r];
}
int N;
string S;
signed main() {
    for (int i = 1; i < 2200000; i++) {
        int cur = i;
        while (cur % 2 == 0) { two_table[i]++, cur /= 2; }
        two_table[i] += two_table[i - 1];
    }
    cin >> N >> S;
    vint v(N - 1);
    rep(i, N - 1) {
        v[i] = abs((S[i] - '0') - (S[i + 1] - '0'));
    }
    bool flag = false;
    rep(i, N - 1) { if (v[i] == 1) { flag = true; }}
    if (flag) {
        bool is_one = false;
        rep(i, N - 1) {
            is_one ^= pascal_mod2(N - 2, i) && (v[i] == 1);
        }
        if (is_one) { cout << 1 << endl; }
        else { cout << 0 << endl; }
    } else {
        bool is_two = false;
        rep(i, N - 1) {
            is_two ^= pascal_mod2(N - 2, i) && (v[i] == 2);
        }
        if (is_two) { cout << 2 << endl; }
        else { cout << 0 << endl; }
    }
}


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

ll attack(ll n){
  if(n==0) return 0;
  else return 2*attack(n/2)+1;
}

int main() {
  ll n;
  cin>>n;
  cout<<attack(n)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#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

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////

ll a,b,c,d[100005] = {},n,m;
string s,t;


int main(){

    /*   cin >> a >> b;
    if(a < 10 && b < 10)P(a*b);
    else P(-1);

    ret 0;*/
    cin >> n;

    rep(i,1,10){
	if(n == (n/i) * i && n/i < 10){
	    Yes;
	    ret 0;
	}
    }
    No;
    
    return  0;
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

ll N,A,B,C,D;
map<ll,ll> memo;

ll dfs(ll n) {
    if (n==1) return D;
    else if (n==0) return 0;
    else if (memo.count(n)) return memo[n];
    ll ans = 1e19;
    if (D < ans/n) ans = D*n;
    if (n/5!=n) ans = min(ans,abs(n-n/5*5)*D+C+dfs(n/5));
    if (n/5+1!=n) ans = min(ans,abs(n-(n/5+1)*5)*D+C+dfs(n/5+1));
    if (n/3!=n) ans = min(ans,abs(n-n/3*3)*D+B+dfs(n/3));
    if (n/3+1!=n) ans = min(ans,abs(n-(n/3+1)*3)*D+B+dfs(n/3+1));
    if (n/2!=n) ans = min(ans,abs(n-n/2*2)*D+A+dfs(n/2));
    if (n/2+1!=n) ans = min(ans,abs(n-(n/2+1)*2)*D+A+dfs(n/2+1));
    memo[n] = ans;
    return ans;
}



int main(){
    int T;
    cin >> T;

    rep(t,T) {
        cin >> N >> A >> B >> C >> D;
        memo.clear();
        ll ans = dfs(N);
        cout << ans << endl;
    }
}


Measured memory_bytes: 4816