akhauriyash/Code-Regression huggingface dataset:
<?php
while (1) {
    $input = explode(' ', trim(fgets(STDIN)));
    $a = $input[0];
    $b = $input[2];
    $op = $input[1];
    if ($op == '+')
        echo $a + $b.PHP_EOL;
    elseif ($op == '-')
        echo $a - $b.PHP_EOL; 
    elseif ($op == '/')
        echo floor($a / $b).PHP_EOL;
    elseif ($op == '*')
        echo $a * $b.PHP_EOL;
    else
    break;
}

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

int main()
{
    int n;
    int d[50];
    cin >> n;
    for( int i = 0; i < n; ++i ){
        cin >> d[i];
    }
    int sum = 0;
    for( int i = 0; i < n; i++ ){
        for( int j = 0; j < n; j++ ){
            if( i == j ){
                continue;
            }
            sum = sum + d[i] * d[j];
        }
    }
    cout << int(sum/2) << endl;
    return 0;
}



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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

ll gcd(ll p, ll q){ 
    while(q != 0){
        ll r=p%q;
        p=q;
        q=r;
    }
    return p;
}

ll lcm(ll a, ll b)
{
    if((ll)a * b / gcd(a, b)>inf){
        cout<<0<<endl;
        exit(0);
    }
    else return (ll)a * b / gcd(a, b);
}

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll>a(n),ca(n),ba(n);
    rep(i,0,n){
        cin>>a.at(i);
        ca.at(i)=a.at(i);
    }
    int cz=0;
    while(ca.at(0)%2==0){
        ca.at(0)/=2;
        cz++;
    }
    rep(i,1,n){
        int c=0;
        while(ca.at(i)%2==0){
            ca.at(i)/=2;
            c++;
        }
        if(cz!=c){
            cout<<0<<endl;
            return 0;
        }
    }
    rep(i,0,n){
        ba.at(i)=a.at(i)/2;
    }
    ll la=ba.at(0);
    rep(i,0,n){
        la=lcm(ba.at(i),la);
    }
    //cout<<la<<endl;
    if(m/la%2==0)cout<<m/la/2<<endl;
    else cout<<m/la/2+1<<endl;
return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main(){
    int a,b,C;
    double rad,S,L,h;
    double PI = acos(-1);
    
    cin >> a >> b >> C;
    rad = C * PI / 180;
    
    S = a*b*sin(rad)/2;
    L = a + b + sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(rad));
    h = b*sin(rad);
    
    cout << fixed << setprecision(5) << S << endl << L << endl << h << endl;
    return 0;
}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  string s;cin >> s;
  bool flag = false;
  int li = -1;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'){
      li = i;
      break;
    }
  }
  for(int i=s.size()-1;i>=0;i--){
    if(s[i]=='Z'){
      cout << i-li+1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) { return cost < e.cost; }
	bool operator > (const edge& e) { return cost > e.cost; }
};

int n;
vector<edge> es[100011];
int main()
{
	cin >> n;
	int masu[100011];
	REP(i, n)
	{
		int a;
		cin >> a;
		if (a == 0)
		{
			FOR(j, 1, 7)
			{
				edge e = { i, i + j, 1 };
				es[i].push_back(e);
			}
		}
		else
		{
			edge e = { i, i + a, 0 };
			es[i].push_back(e);
		}
	}
	int d[111111];
	fill(d, d + 111111, INF);
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, 0));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		REP(i, es[v].size())
		{
			edge e = es[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	cout << d[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 9744
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  
  for(int i=0; i<=n/4; ++i) for(int j=0; j<=n/7; ++j) if(i*4+j*7==n) return cout<<"Yes\n",0;
  cout<<"No\n";
  return 0;
}

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

const long long MOD=1e9+7;
int n,k,dp1[1000000];
vector<long long>cnt,dp2;

int main()
{
	cin>>n>>k;
	for(long long s=n;s>0;)
	{
		long long cur_s=n/(n/s+1);
		cnt.push_back(s-cur_s);
		s=cur_s;
	}
	reverse(cnt.begin(),cnt.end());
	int m=cnt.size();
	dp2=cnt;
	for(int i=1;i<k;i++)
	{
		for(int j=0;j<m;j++)
		{
			int t=m-1-j;
			dp1[t]=dp2[j]%MOD;
		}
		for(int j=m-1;j>=0;j--)
		{
			dp1[j]=(dp1[j]+(j+1<m?dp1[j+1]:0))%MOD;
			dp2[j]=(dp1[j]*cnt[j])%MOD;
		}
	}
	long long ans=0;
	for(int i=0;i<dp2.size();i++) 
		ans=(ans+dp2[i])%MOD;
	cout<<ans;
}


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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,lessl<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N = 1e5 + 5;
const int M = 1e9 + 7;

void solve()
{
	int n;
	cin>>n;
	int a[n];
	int pre[n]={0};
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		if(i==0)
			pre[i]=a[i];
		else
		pre[i]=pre[i-1]+a[i];
	}
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		int curr=pre[n-1]-pre[i];
		curr%=M;
		ans=(ans+(a[i]*curr)%M)%M;
	}
	cout<<ans<<endl;
}

signed main()
{
	FAST

#ifndef ONLINE_JUDGE
	freopen("input_sublime.txt", "r", stdin);
	freopen("output_sublime.txt", "w", stdout);
#endif

	int t = 1;
	// cin>>t;
	for (int tc = 1; tc <= t; tc++)
	{
		// cout<<"Case #"<<tc<<": ";
		solve();
	}

#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
}


Measured memory_bytes: 6716
n, k, l = map(int, input().split())
pq = [list(map(int, input().split())) for _ in range(k)]
rs = [list(map(int, input().split())) for _ in range(l)]

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

u1 = UnionFind(n)
for i in range(k):
    u1.union(pq[i][0], pq[i][1])

u2 = UnionFind(n)
for i in range(l):
    u2.union(rs[i][0], rs[i][1])

for i in range(n):
    a = u1.find(i + 1)
    b = u2.find(i + 1)

from collections import defaultdict
d = defaultdict(list)
for i in range(1, len(u1.par)):
    d[str(u1.par[i]) + ' ' + str(u2.par[i])].append(i)

ans = [0] * n
for k in d.keys():
    for v in d[k]:
        ans[v - 1] = len(d[k])

ans2 = ''
for i in range(len(ans)):
    ans2 += str(ans[i]) + ' '

print(ans2[:-1])


Measured memory_bytes: 112416
import numpy as np
n = int(input())
t, a = map(int, input().split())

h = list(map(int, input().split()))
results = []
for x in h:
    results.append(t - x * 0.006)

results = [abs(x - a) for x in results]
r = np.argsort(results)
print(r[0] + 1)


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

int main()
{
    int n; cin>>n;
    map<int, int> a;
    for(int i=0; i<n; ++i) { int t; cin>>t; ++a[t]; }

    int even=0;
    for(auto& e: a) even+=1-e.second%2;
    cout<<a.size()-even%2<<endl;
}


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

#define ii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair

typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
    string s;
    cin >> s;
    int c = 0;
    for(int  i = 0; i < s.length()/2; i++){
        if(s[i] != s[s.length()-1-i])
            c++;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  int sum=0,count=0;
  rep(i,n){
    cin >> vec.at(i);
    sum+=vec.at(i);
    if(vec.at(i)%10==0){
      count++;
    }
  }
  sort(vec.begin(),vec.end());
  int i=0;
  if(count==n){
    cout << 0;
    return 0;
  }
  while(sum%10==0 && i<n){
    if(vec.at(i)%10!=0){
    sum=sum-vec.at(i);
    }
    i++;
  }
  cout << sum;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))

AB = [tuple(map(int, input().split())) for i in range(M)]
G = [0]*N

for a, b in AB:
    a -= 1
    b -= 1
    if G[a] < H[b]:
        G[a] = H[b]
    if G[b] < H[a]:
        G[b] = H[a]
ans = 0
for i in range(N):
    if H[i] > G[i]:
        ans += 1
print(ans)


Measured memory_bytes: 27264
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    // a < b < cを作る
    int cnt = 0;
    while(b<=a){
        b*=2;
        cnt++;
    }
    while(c<=b){
        c*=2;
        cnt++;
    }
    if(cnt<=k)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3656
#include <math.h>
#include <string.h>
#include<stdio.h> 
#include<stdlib.h> 
#define re_ma 100000000 
#define n_max 1000000
#define c_max 2000000
typedef struct ko_t_s{ 
  int ko_p,ko_c; 
} ko_t_s; 
  
ko_t_s stuff[2000001]; 
int N=0;

void k_v_exc(ko_t_s* ,ko_t_s* );
void k_hep_mi(int );
ko_t_s k_hep_ex_min();
void k_hep_inc_ke(int ,ko_t_s );
void k_hep_ins_mi(ko_t_s );
void k_hep();
void ck();
  
   
int i_12_pa(int i){return i/2;} 
int i_12_lt(int i){return i*2;} 
int i_12_rt(int i){return i*2+1;} 
   

  
  
typedef struct s_t_e{ 
  int to,ko_c; 
} s_t_e; 
  
s_t_e* ggoo[10000]; 
int i_si_k[10000]; 
int n; 
int d[10000]; 
s_t_e e; 
ko_t_s s; 
int main(){ 
  int i,j,a,b,sh[n_max],ch[n_max]; 
  scanf("%d",&n);
  for(int i=0;i<n_max;i++){
  k_hep();
  ck();
  }
  for(i=0;i<n;i++){ 
    scanf("%d %d",&a,&b); 
    ggoo[a] = malloc( sizeof( s_t_e ) *b ); 
    i_si_k[a]=b; 
    for(j=0;j<b;j++){ 
      scanf("%d %d",&ggoo[a][j].to,&ggoo[a][j].ko_c); 
    } 
    d[i]=re_ma; 
  } 
  d[0]=0; 
  k_hep_ins_mi( (ko_t_s){0,0} ); 
  while(N!=0){ 
    s = k_hep_ex_min(); 
    if(s.ko_c>d[s.ko_p])continue; 
    for(i=0;i<i_si_k[s.ko_p];i++){ 
      e=ggoo[s.ko_p][i]; 
      if(d[e.to]<=d[s.ko_p]+e.ko_c)continue; 
      d[e.to]=d[s.ko_p]+e.ko_c; 
      k_hep_ins_mi((ko_t_s){e.to,d[e.to]}); 
   } 

  }
  for(i=0;i<n;i++) 
    printf("%d %d\n",i,d[i]); 
    
  return 0; 
}





void k_v_exc(ko_t_s* a,ko_t_s* b){ 
  ko_t_s s_t=*a; 
  *a=*b; 
  *b=s_t; 
} 
   
void k_hep_mi(int i){ 
  int l=i_12_lt(i); 
  int r=i_12_rt(i); 
  int k_i_m; 
    
  if( l<=N && stuff[l].ko_c<stuff[i].ko_c )k_i_m=l; 
  else k_i_m=i; 
    
  if( r<=N && stuff[r].ko_c<stuff[k_i_m].ko_c)k_i_m=r; 
    
  if(k_i_m!=i){ 
    k_v_exc(&stuff[i],&stuff[k_i_m]); 
    k_hep_mi(k_i_m); 
  } 
    
} 
   
ko_t_s k_hep_ex_min(){ 
  if(N<1)return (ko_t_s){0,0}; 
  ko_t_s min=stuff[1]; 
  stuff[1]=stuff[N]; 
  N--; 
  k_hep_mi(1); 
  return min; 
} 
  
   
void k_hep_inc_ke(int i,ko_t_s k_g_p_ke){ 
  if(k_g_p_ke.ko_c>stuff[i].ko_c)return; 
   
  stuff[i]=k_g_p_ke; 
  while(i>1&&stuff[i_12_pa(i)].ko_c>stuff[i].ko_c){ 
    k_v_exc(&stuff[i],&stuff[i_12_pa(i)]); 
    i=i_12_pa(i); 
  } 
} 
   
void k_hep_ins_mi(ko_t_s k_g_p_ke){ 
  N++; 
  stuff[N]=(ko_t_s){re_ma,re_ma}; 
  k_hep_inc_ke(N,k_g_p_ke); 
} 
void ck(){
  char gg[n_max],js[n_max];
  for(int i=0;i<n_max;i++){
    k_hep();
  }
}void k_hep(){
  int i=100;
  int size=1000*1000*100;
  char *chek;
  for(int j=0;j<n_max;j++){
    chek=(char *)malloc(sizeof(char)*size);
    chek[j]='y';
  }
  
}



Measured memory_bytes: 5720
from collections import defaultdict
mod = 998244353
def factrial(N):
    fc = [1, 1] + [None] * N
    inv = [0, 1] + [None] * N
    fcInv = [1, 1] + [None] * N
    for i in range(2, N+1):
        fc[i] = i*fc[i-1]%mod
        inv[i] = mod-(inv[mod%i]*(mod//i))%mod
        fcInv[i] = fcInv[i-1]*inv[i]%mod
    return fc, fcInv

def modCom(n, k):
    return 0 if n < k else fc[n] * fcInv[k] * fcInv[n-k] % mod

N, M, K = map(int, input().split())
fc, fcInv = factrial(N+1)
ans, C = 0, 0
for k in range(K+1):
    C = modCom(N-1, k)
    C %= mod
    ans += C * M * pow(M-1, N-k-1, mod)
    # print(ans)
    ans %= mod
print(ans)

Measured memory_bytes: 91860
#include<stdio.h>

void selectionSort(int *,int);

int main(){
  int a[100],n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  selectionSort(a,n);

  return 0;
}
void selectionSort(int *a,int n){
  int i,j,minj,x,kazu=0;

  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(a[j]<a[minj]){
	minj=j;
      }
    }
    if(a[i]!=a[minj]) kazu++;
    x=a[i];
    a[i]=a[minj];
    a[minj]=x;
  }
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n",kazu);
}



Measured memory_bytes: 2108
#include <iostream>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

ll powMod(ll a, ll p, ll mod){
        if(p==1) return a;
        if(p%2) return (a*powMod(a, p-1, mod))%mod;
        ll t = powMod(a, p/2, mod);
        return (t*t)%mod;
}

int main(){
        ll x,y,m,n,k,pre=1,cnt=1;
        cin >> x >> y;
        if((2*x-y)%3!=0||(2*y-x)%3!=0||2*x-y<0||2*y-x<0){
                cout << 0 << endl;
        }else{
                m = (2*x-y)/3;
                n = (2*y-x)/3;
                k = min(m,n);
                while(cnt!=m+n){
                        ++cnt;
                        pre = (pre*cnt)%MOD;
                }
                cnt = 1;
                while(cnt<k){
                        ++cnt;
                        pre = (pre*powMod(cnt,MOD-2,MOD))%MOD;
                }
                cnt = 1;
                while(cnt<m+n-k){
                        ++cnt;
                        pre = (pre*powMod(cnt,MOD-2,MOD))%MOD;
                }
                cout << pre << endl;
        }
        return 0;
}

Measured memory_bytes: 3644
s = input()

jug = True
for i in range(len(s)):
    if i % 2 == 0 and s[i] == 'L':
        print("No")
        jug = False
        break
    elif i % 2 == 1 and s[i] == 'R':
        print("No")
        jug = False
        break
    
if jug == True: print("Yes")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define INF 987654321

int main() {
  int n;
  cin >> n;
  long long ans = 0;

  for(int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;

    while(true){
      if(tmp % 2 == 1 || tmp < 2){
        break;
      }
      ans++;
      tmp /= 2;
    }
  }

  cout << ans << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int Q;
  cin>>Q;
  vector<pair<lint,lint> > ans;
  multiset<lint> s1,s2;
  int f;
  lint a,b;
  cin>>f>>a>>b;
  lint base=b;
  s1.insert(a);
  s2.insert(a);
  REP(i,Q-1){
    cin>>f;
    if(f==1){
      cin>>a>>b;
      base+=b;
      lint l=*(--s1.end());
      lint r=*(s2.begin());
      if(a>r){
        base+=a-r;
        s1.insert(r);
        s2.erase(s2.begin());
        s2.insert(a);
        s2.insert(a);
      }else if(a<l){
        base+=l-a;
        s2.insert(l);
        s1.erase(--s1.end());
        s1.insert(a);
        s1.insert(a);
      }else{
        s1.insert(a);
        s2.insert(a);
      }
    }
    else{
      ans.push_back(make_pair(*s1.rbegin(),base));
    }
  }
  for(auto e:ans){
    cout<<e.first<<" "<<e.second<<endl;
  }
  return 0;
}


Measured memory_bytes: 18944
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
	LL n,a[1000]={0},q;
	 string s;
	 cin>>n;
	 cin>>s;
	 cin>>q;
	 while(q--)
	 {LL DMnum=0,Dnum=0,Mnum=0,DMCnum=0,k;
	 cin>>k;
	 	  for(LL i=0;i<s.length();i++)
	  {if(i-k>=0&&s[i-k]=='D')
		   {
		   	Dnum--;
		   	DMnum-=Mnum;
		   }
		   if(i-k>=0&&s[i-k]=='M')
		   {
		   	Mnum--;
		   	
		   }
		   
	  	 if(s[i]=='D')Dnum++;
	  	 if(s[i]=='M')
	  	 {
	  	 	Mnum++;
	  	 	DMnum+=Dnum;
		   }
		   if(s[i]=='C')
		   {
		   	DMCnum+=DMnum;
		   }
		   
	  	 
	  }
	  cout<<DMCnum<<"\n";
	 }
	
}

Measured memory_bytes: 1412
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void) {
	int n;cin >> n;
	vector<ijt> a(n),c(n+1,0);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		c[i+1] = c[i] + a[i];
	}

	//真ん中の位置iにたいして切るべき適切な左と右の個所を決定する
	//まずは左。
	vector<int> left(n,0),right(n,0);
	//2番目からn-2番目まで
	int j = 1;
	int t = 3;
	for (int i = 2; i <= n - 2; i++) {
		//今j番目で区切っているとする
		//c[j]とc[i]-c[j]の差の絶対値はどこかで最小になる、それを見つける
		//ただし1 <= j <= i-1に注意
		//j = 1;
		while (j < i - 1) {
			if (abs(2 * c[j] - c[i]) > abs(2 * c[j + 1] - c[i])) {
				j++;
			}else break;
		}
		left[i] = j;

		//右側、今度はi+1 <= j <= n-1に注意する
		//t = i+1;
		while (t < n - 1) {
			if (abs((c[t] - c[i]) - (c[n] - c[t])) > abs((c[t + 1] - c[i]) - (c[n] - c[t + 1]))) {
				t++;
			}else break;
		}
		right[i] = t;
	}

	//2 <= i <= n-2で全探索
	ijt ans = INF;
	for (int i = 2; i <= n - 2; i++) {
		ijt p,q,r,s;
		p = c[left[i]];
		q = c[i] - c[left[i]];
		r = c[right[i]] - c[i];
		s = c[n] - c[right[i]];
		ijt d = max({p,q,r,s}) - min({p,q,r,s});
		mins(ans,d);
	}
	cout << ans << endl;

}

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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

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

    cout << n/2 - (n%2==0?1:0) << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
        solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll INF=10000000000000;
ll N;
int main(){
  cin>>N;
  vector<pair<ll,ll>>A(N);
  for(int i=0;i<N;i++){
  ll x,y;cin>>x>>y;ll Y=max(x,y);ll X=min(x,y);
    pair<ll,ll>p(Y,X);
    A[i]=p;
  }sort(A.begin(),A.end());
  ll rm=INF;ll rM=0;ll bm=INF;ll bM=0;
  for(int i=0;i<N;i++){
  ll y=A[i].first;
    ll x=A[i].second;
    if(x<rm)rm=x;
    if(rM<x)rM=x;
    if(y<bm)bm=y;
    if(bM<y)bM=y;
   }ll ans1=(bM-bm)*(rM-rm);
       ll m=A[0].first;ll ans2=INF;ll M=0;
       for(int i=N-1;0<=i;i--){
       ll a=max(M,A[i].first)-m;if(a<ans2)ans2=a;
       if(A[i].second<m)m=A[i].second;if(M<A[i].second)M=A[i].second;
       }ans2*=(bM-rm);
       ll ans=min(ans1,ans2);
       cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int a;
  cin >> a;
  if (a<1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x7fffffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define exist(s,e) (s.find(e)!=s.end())
#define ff first
#define ss second
#define EPS 1e-8
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
const ll MOD=1000000007;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string>) { cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis;
/////////////////// FUNCTIONS ////////////////////////////////////
template<class T>
T maxx(T a, T b) {return a>b?a:b;}
template<typename T, typename... Args>
T maxx(T a, T b, Args... args){return maxx(a>b?a:b, args...);}
ll mexp(ll x, ll n, ll m){
  ll res=1;  while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
  return res;
}
template<class T>
T minn(T a, T b) {return a<b?a:b;}
template<typename T, typename... Args>
T minn(T a, T b, Args... args){return minn(a>b?a:b, args...);}
bool ispow2(ll x){ return x && (!(x&(x-1))); }
ld pow(ld a, int n) {
  if(n == 0) return 1;if(n == 1) return a;
  double t = pow(a, n/2);return t * t * pow(a, n%2);
}
/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(0);  cin.tie(0);   cout<<fixed; cerr<<fixed;
  cout<<setprecision(14); cerr<<setprecision(3);
  #ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
  #endif

	ll n,m; cin>>n>>m; if(n>m) swap(n,m);
	if(n==1){
		if(m==1) cout<<"1\n";
		else cout<<m-2<<'\n';
	}
	else if(n==2) cout<<"0\n";
	else cout<<(n-2)*(m-2)<<'\n';

	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
	#endif
  return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;

	int i = 0;

	int answer = 0;
	int judge;
	int lastjudge = 0;

	while (i < m) {

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

		if (a < b) {

			judge = n - a;

			while (a < n){
				a++;
				answer++;
			}
			
				if (judge > lastjudge) {
					lastjudge = judge;
				}		
		}
		i++;
	}

	cout << answer - lastjudge << endl;
    return 0;
}


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long MOD = 1000000007;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint fib(int n) {
    mint a0 = 1, ans = 1;
    rep1(i, n-1) {
        mint t = a0;
        a0 = ans;
        ans = t + a0;
    }
    return ans;
}

int main(){
    int n, m;
    cin >> n >> m;
    vi a(m);
    rep(i, m) cin >> a[i];
    mint ans = 1;
    bool zero = false;
    int p = -1;
    rep(i, m) {
        int b = a[i] - p;
        if (b<=1) zero = true;
        ans *= fib(b-2);
        p = a[i];
    }
    ans *= fib(n-p-1);
    cout << (zero?0:ans) << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();	
		int a[] = new int[N];
        for(int i=0; i<N; i++){
          a[i] = sc.nextInt();}
        int cnt=0;
        int puyo=1;
        for(int i=0; i<N-1; i++){
          if(a[i] == a[i+1]){
            puyo++;
            continue;
           }
           cnt += puyo/2;
           puyo = 1;          
        }
           cnt += puyo/2;
		// 出力
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21716
n = int(input())
a = [int(x) for x in input().split()]
res = "APPROVED"
for i in range(n):
  if a[i] % 2 == 0:
    if a[i] % 3 != 0 and a[i] % 5 != 0:
      res = "DENIED"
print(res)

Measured memory_bytes: 9108
N = int(input())
if N <= 111:
    print(111)
elif N <= 222:
    print(222)
elif N <= 333:
    print(333)
elif N <= 444:
    print(444)
elif N <= 555:
    print(555)
elif N <= 666:
    print(666)
elif N <= 777:
    print(777)
elif N <= 888:
    print(888)
elif N <= 999:
    print(999)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,M;
  cin >> A >> B >> M;

  int a[A],b[B],x[M],y[M],c[M];

  for (int i = 0; i < A; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < B; i++) {
    cin >> b[i];
  }

  for (int i = 0; i < M; i++) {
    cin >> x[i] >> y[i] >> c[i];
  }
  
  int min,m[M+1];

    for (int i = 0; i < M; i++){
        m[i] = a[x[i]-1] + b[y[i]-1] - c[i];
    }

    sort(a,a+A);
    sort(b,b+B);
  
  m[M] = a[0] + b[0];
  sort(m,m+M+1);

  cout << m[0] <<endl;
}

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

int main() {
    int p, q, r;
    int ans = 99999;
    
    cin >> p >> q >> r;
    
    ans = min(ans, p + q);
    ans = min(ans, p + r);
    ans = min(ans, q + r);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def calc(K):
    if K % 2 == 0:
        print(-1)
        return
    elif 7 % K == 0:
        print(1)
        return

    a = [7 % K]
    for x in range(1, K):
        cur = (a[x-1]*10+7) % K
        if cur == 0:
            print(x + 1)
            return
        else:
            a.append(cur)

    print(-1)


K = int(input())

calc(K)

Measured memory_bytes: 48492
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    long ans = 0;
    for (long k : irange(1, n + 1)) {
        long m = n / k;
        ans += m * (m + 1) * k / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,i,c=0,k,o;
    double g;
    long long int u=0,l;
    scanf("%d%d",&N,&M);
    int a[N];
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
        u=u+a[i];
    }
    l=(u/(4*M));
    o=(u%(4*M));
    g=o/(4*M);
    if(o>=0.5)
        l++;
    for(i=0;i<N;i++)
    {
        if(a[i]>=l)
            c++;
    }
    if(c>=M)
    printf("Yes");
    else
        printf("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s[s.size()-1]=='2' || s[s.size()-1]=='4' || s[s.size()-1]=='5' ||s[s.size()-1]=='7' || s[s.size()-1]=='9'){
    cout<<"hon"<<endl;
  }
  else if(s[s.size()-1]=='0' || s[s.size()-1]=='1' || s[s.size()-1]=='6' || s[s.size()-1]=='8'){
    cout<<"pon"<<endl;
  }
  else{
    cout<<"bon"<<endl;
  }
}
  

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d)cout<<"Left\n";
    else if(a+b<c+d)cout<<"Right\n";
    else cout<<"Balanced\n";
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£????????????
		Scanner sc = new Scanner(System.in);
		//??\???????????????????????£?????????
		String word =sc.nextLine();
		//
		StringBuilder out = new StringBuilder();
		//??£?¨?
		 String w;
		 //
		 for(int i =0; i<word.length();i++){
			 w= word.substring(i,i+1);
			//?????£?????\?????????????°???????????????§???????????????
			 if(w.equals(w.toLowerCase())){
				 w = w.toUpperCase();
			//?????£?????\??????????????§?????????????°????????????????
			}else if(w.equals(w.toUpperCase())){
				w = w.toLowerCase();
			}
			 System.out.append(w);
		 }

		 //??¨???
		 System.out.println(out);
	}
}

Measured memory_bytes: 26908
/// @file

#include <iostream>
#include <map>
#include <string>

namespace {

bool run(std::istream& is, std::ostream& os);
}  // unnamed namespace

/// @brief エントリポイント
#ifdef _TEST
static int run()
#else
int main()
#endif
{
  try {
    if (run(std::cin, std::cout) == false) {
      std::cerr << "main funciton error.\n";
      return EXIT_FAILURE;
    }
  } catch (const std::exception& e) {
    std::cerr << "catch exception\n";
    std::cerr << e.what() << "\n";
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

namespace {

///
/// @brief 一回分の処理を行います。
/// @param[in] input 初期の枚数
/// @param[out] output 自分の変更後の枚数
/// @return 相手に渡す枚数
///
int oneStep_(const int input, int& output)
{
  int dst(input);
  if (dst % 2 == 1) --dst;
  output = dst / 2;
  return output;
}

/// @brief 実行処理
bool run(std::istream& is, std::ostream& os)
{
  int a;
  int b;
  int k;
  is >> a >> b >> k;

  int* target = &a;
  int* partner = &b;
  for (int i = 0; i < k; ++i) {
    *partner += oneStep_(*target, *target);
    std::swap(target, partner);
  }

  os << a << " " << b << "\n";

  return true;
}
}  // unnamed namespace


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  int e,f;
  int g=0;
  cin>>a>>b;
  for(int i=1;i<=a;i++){
    for(int j=1;j<=b;j++){
      f=j;
      c=f%10;
      d=f/10;
      if(c>=2&&d>=2&&c*d==i){
	  g++;
      }
    }
  }
  cout<<g<<"\n";
}
	


Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()
hap=0
if(n>1):
  for i in range(n):
    if(i==0):
      if(s[0]==s[1]=='R'):
        hap+=1
    elif(i==n-1):
      if(s[n-2]==s[n-1]=='L'):
        hap+=1
    else:
      if(s[i]==s[i+1]=='R' or s[i-1]==s[i]=='L'):
        hap+=1
print(min(hap+2*k,n-1))

Measured memory_bytes: 3316
// https://atcoder.jp/contests/abc071/tasks/abc071_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  string s, r = "None";
  char a[] = "abcdefghijklmnopqrstuvwxyz";

  cin >> s;

  REP(i, 26)
  {
    if (s.find(a[i]) == string::npos)
    {
      r = a[i];
      break;
    }
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long[] s = new long[1000000];
        for (long i = 0; i < n[0]; i++)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            s[(long)x[0] - (long)1] += (long)x[1];
        }
        long f = (long)n[(long)1];
        long j;
        for (j = 0; j < n[1] && f > 0; j++)
        {
            f -= (long)s[(long)j];
        }
        Console.WriteLine(j);Console.ReadLine();
    }
}



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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll A,B,C,X,Y;
    string S;
    cin >> A>>B>>C>>X>>Y;

    ll Z = 2*max(X,Y);
    ll cost, ans = LLINF;
    ll X_tmp, Y_tmp;
    for (ll i = 0; i <= Z; i++)
    {
        if(i%2==0){
            if(X-i/2>=0){
                X_tmp = X - i / 2;
            }
            else{
                X_tmp = 0;
            }

            if (Y - i / 2 >= 0)
            {
                Y_tmp = Y - i / 2;
            }
            else
            {
                Y_tmp = 0;
            }

           
            cost = C * i + A*X_tmp+B*Y_tmp;
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}


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

using namespace std;


int main()
{
    size_t n, m;
    cin >> n >> m;

    vector<vector<size_t>> s(m);

    vector<size_t> p;
    
    istream_iterator<size_t> iit(cin);

    for (auto i = 0; i < m; ++i) {
        size_t k = *iit++;
        for (auto j = 0; j < k; ++j) {
            s.at(i).emplace_back((*iit++) -1);
        }
    }

    for (auto i = 0; i < m; ++i) {
        p.emplace_back(*iit++);
    }

    size_t ret = 0;

    for (auto i = 0; i < (1 << n); ++i) {
        bitset<10> switches(i);
        //cout << "Case: " << switches.to_string() << endl;
        bool ok = true;
        for (auto j = 0; j < m; ++j) {
            //cout << "Sw: " << j << endl;
            size_t cnt = 0;
            for (auto sw : s.at(j)) {
                if (switches.test(sw)) {
                    ++cnt;
                    //cout << "Sw" << sw << " is on" << endl;
                }
            }
            if (cnt % 2 != p.at(j)) {
                ok = false;
                break;
            }
        }
        if (ok) ++ret;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
  if a < b:
    return gcd(b, a)
  if b == 0:
    return a
  return gcd(b, a%b)

K = int(input())

if gcd(K, 10) != 1:
  print(-1)
else:
  if K % 7 == 0:
    K//=7
  ans = 1
  cur = 1
  while cur % K != 0:
    cur += pow(10, ans, K)
    ans += 1
  print(ans)


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

int main() {
  string s;
  int w;
  cin>>s>>w;
  int e=s.size();
  for(int i=0;i<e;i+=w) {
    cout<<s.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map> 
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);

int z[200005];
int main()
{
	int a,b,c,d;
	memset(z,0,sizeof(z));
	scanf("%d",&a);
	for(int i=0;i<a-1;i++)
	{
		scanf("%d",&b);
		z[b]++;
	}
	for(int i=1;i<=a;i++)printf("%d\n",z[i]);

	
}



Measured memory_bytes: 2512
#include <iostream>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    while (!(h == 0 && w == 0)) {
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (i%2==1){
                    if(j%2==1){
                        cout<<"#";
                    }else{
                        cout<<".";
                    }
                }else{
                    if(j%2==1){
                        cout<<".";
                    }else{
                        cout<<"#";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> h >> w;
    }
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B;
    cin >> A >> B;
    if (A < 10 && B < 10)
        cout << A * B << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

ll gcd(ll s, ll t){
  if(s==0LL)return t;
  return gcd(t%s, s);
}

int main(){
  ll a, b;cin>>a>>b;
  if(a>b)swap(a, b);
  ll c = gcd(a, b);
  int ans=1;
  for(ll div=2LL;div*div<=c;div++){
    ll cnt=0LL;
    while(c%div==0LL){
      cnt++;c/=div;
    }
    if(cnt!=0LL)ans++;
  }
  if(c!=1LL)ans++;
  cout<<ans<<endl;
  system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 504
#include<iostream>
using namespace std;
char a[101];
int main()
{
    int n,max=0,s=0;
    cin>>n;
    for(int i=1;i<=n;++i)
    cin>>a[i];
    for(int i=1;i<=n;++i)
    {
    	if(a[i]=='I')
    	s++;
    	else
    	s--;
    	if(s>max)
    	max=s;
	}
	cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

bool CanGo(int y, int x, int R, int C) {
	return y >= 0 && y < R && x >= 0 && x < C;
}

int TraceMaze(queue<vector<int>>& Queue, int gy, int gx, vector<vector<bool>>& Map) {
	vector<int> nowstate = Queue.front();
	Queue.pop();
	int R = Map.size();
	int C = Map[0].size();
	int ny = nowstate[0];
	int nx = nowstate[1];
	int step = nowstate[2];
	if (ny == gy && nx == gx) return step;

	if (Map[ny][nx]) {
		Map[ny][nx] = false;
		if (CanGo(ny - 1, nx, R, C))Queue.push({ ny - 1, nx,step + 1 });
		if (CanGo(ny + 1, nx, R, C))Queue.push({ ny + 1, nx,step + 1 });
		if (CanGo(ny, nx - 1, R, C))Queue.push({ ny , nx - 1,step + 1 });
		if (CanGo(ny, nx + 1, R, C))Queue.push({ ny , nx + 1,step + 1 });
	}
	return -1;
}

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

	int White = 0;
	vector<vector<bool>> Map(H, vector<bool>(W, true));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char c;
			cin >> c;
			if (c == '#') Map[i][j] = false;
			else White++;
		}
	}
	int steps = -1;
	queue<vector<int>> Queue;
	Queue.push({ 0, 0, 1 });
	while (!Queue.empty() && steps < 0) steps = TraceMaze(Queue, H - 1, W - 1, Map);
	if (steps > 0) {
		cout << White - steps << endl;
	}
	else cout << -1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull usigned long long
#define two(n) 1<<n
#define l(v) (int)v.size()
#define p_b push_back
#define m_p make_pair
const int pi=acos(-1.0);
const int int_max=1e9;
const long long ll_max=1e18;
int n;
int a[25],b[25],c[25];
int ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<n;i++)
		cin>>c[i];
	for(int i=1;i<=n;i++)
	{
		ans+=b[a[i]];
		if(a[i]-1==a[i-1])
			ans+=c[a[i-1]];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string solve(vector<int>&v,int k){
	bool dp[k+1];
	memset(dp,0,sizeof dp);
	for (int i = 1; i <= k; ++i)
	{
		for(int move : v){
			if(move>i)
				continue;
			if(dp[i-move]==0)
				dp[i] = 1;
		}
	}

	return dp[k] ? "First" : "Second";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif


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

	cout<<solve(v,k)<<endl;




	return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 ll dp[100005];
 void dfs(vector<vector<ll>> &v,ll x){
     dp[x]=0;
     for(auto k:v[x]){
       if(dp[k]==-1)dfs(v,k);
       dp[x]=max(dp[x],1+dp[k]);
     }
     
 }
 int main(){
  ll m,i,n,k,a,b;
  cin>>n>>m;
  vector<vector<ll>> v(n+1);
  for(i=0;i<m;i++){
      cin>>a>>b;
      v[a].push_back(b);
    //   v[b].push_back(a);
  }
  memset(dp,-1,sizeof(dp));
  for(i=1;i<=n;i++)
   if(dp[i]==-1)dfs(v,i);
  ll ans=0;
  for(i=1;i<=n;i++)
   ans=max(ans,dp[i]);
  cout<<ans;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
	cin.sync_with_stdio(0);
	// cin.tie(0);

	ll a, b;
	cin >> a >> b;

	ll max = a + b;
	if (a - b > max) max = a-b;
	if (a*b > max) max = a*b;
	
	cout << max << '\n';
}


Measured memory_bytes: 256
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let s = read::<String>();
    let s = &s[0];

    let mut ans: i32 = 0;
    for c in s.chars() {
        if c == '+' {
            ans += 1;
        } else {
            ans -= 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
  int sum = 0, mx = 0;
  for (int i = 0; i < 5; ++i) {
    int a;
    cin >> a;
    sum += (a + 9) / 10;
    mx = max(mx, (10 - a % 10)%10);
  }
  cout<<sum*10-mx<<endl;
}


Measured memory_bytes: 256
S = input()
T = input()
ans = []
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        tmp = S[:i] + T + S[i+len(T):]
        ans.append(tmp.replace('?', 'a'))
if ans:
    print(ans[-1])
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3064