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

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int two = 1;
        while (two * 2<= n) {
            two *= 2;
        }
        System.out.println(two);
    }
}

Measured memory_bytes: 23124
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        a = self.parents[x]
        b = self.parents[y]
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return(a*b)
N,M = (int(x) for x in input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
uf = UnionFind(N)
init = N*(N-1)//2
ans = []
temp = init
for i in range(1, M+1):
    temp -= uf.union((AB[-i][0]-1), (AB[-i][1]-1))
    ans.append(temp)
for i in range(1, M):
    print(ans[-i-1])
print(init)

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

int main()
{ 
  int n, ans = 0, c;
  vector<int> v(20);

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  for (int i = 0; i < n; i++)
  {
    cin >> c;
    if (c < v[i])
      ans += v[i] - c;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*; 
 
class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a=n%1000;
        int ans=0;
        if(a==0){
        ans=0;
        }else{
  		ans=1000-a;
        }
  		
 
    	System.out.println(ans);
    }
}


Measured memory_bytes: 35660
#include<iostream>
#include<cstring>
using namespace std;
char s[100005];
int ans;
int main(){
	cin>>s;
	int len=strlen(s);
	ans=len;
	for(int i=0;i<len;i++){
		if(s[i]!=s[i-1]){
			ans=min(ans,max(i,len-i));
		}
	}
	cout<<ans;
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

vector<int> a;

// 約数列挙
vector<int> divisor(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
            }
    }
    sort(begin(ret), end(ret));
    sort(ret.begin(), ret.end());
    ret.pop_back();

    return (ret);
}

int main(){
    int n;
    cin >> n;
    map<int,int> mp;
    rep(i, n) {
        int  b;
        cin >> b;
        a.push_back(b);
        mp[b]++;
    }

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

    int ans = 0;

    rep(i, n){
        vector<int> vec = divisor(a[i]);
        bool flag = 1;
        rep(j, vec.size()){
            if (binary_search(a.begin(), a.end(), vec[j])) flag = 0;
        }
        if (mp[a[i]] >= 2) flag = 0;
        if (flag) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13476
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  string s;cin>>s;
  string t;cin>>t;
  int i,j,k,l;
  string sp=s;
  string ans;
  ans="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
  i=0;
  bool reach=false;
  while(i<s.size()-t.size()+1){
    bool reached = false;
    s=sp;
    for(j=i;j<i+t.size();j++){
      if(s[j]!=t[j-i] and s[j]!='?') break;
      if(j==i+t.size()-1) reach=reached=true;
    }
    if(reached){
      for(j=i;j<i+t.size();j++){
        s[j]=t[j-i];
      }
      for(j=0;j<s.size();j++){
        if(s[j]=='?') s[j]='a';
      }
    }
    if(reached) ans=min(ans,s);
    i++;
    //cout<<i<<endl;
  }
  if(reach) cout<<ans<<endl;
  else cout<<"UNRESTORABLE"<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)


def solve(N, S):
    d = Counter([s[0] for s in S if s[0] in "MARCH"])
    ans = 0
    for comb in combinations("MARCH", 3):
        a = 1
        for c in comb:
            a *= d[c]
        ans += a
    return ans


def main():
    N = int(input())
    S = []
    for i in range(0, N):
        S.append(input())
    print(solve(N, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12028
package main

import (
	"fmt"
)

var (
	finv, inv, fac [MAX]int
)

func COM(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func init() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

const (
	MOD = 998244353
	MAX = 510000
)

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	value int
	index int
	A, B  int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int64) int64 {
	return a * b / GCD(a, b)
}

func main() {
	var N, X int
	fmt.Scanf("%d %d\n", &N, &X)
	L := make([]int, N)
	for i := 0; i < N; i++ {
		var l int
		fmt.Scan(&l)
		L[i] = l
	}
	cnt := 0
	if X >= 0 {
		cnt++
	}
	var last int
	for i := 0; i < N; i++ {
		last = last + L[i]
		if last <= X {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  int n;
  cin>>n;
  vi a, b;
  rep(i,n) {
    int x,y;
    cin>>x>>y;
    a.pb(x+y);
    b.pb(x-y);
  }
  sort(all(a));
  sort(all(b));
  ll ans = max(a[n-1]-a[0], b[n-1]-b[0]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5088
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,A,x;
    cin >> N >> A;
    ll dp[N+1][6000];
    ll i,j;
    for(j=0;j<6000;j++){
        dp[0][j]=0;
    }
    dp[0][3000]=1;
    for(i=1;i<=N;i++){
        cin >> x;
        for(j=0;j<6000;j++){
            dp[i][j]=dp[i-1][j];
            if(j-x+A>=0&&j-x+A<6000)dp[i][j]+=dp[i-1][j-x+A];
        }
    }
    cout << dp[N][3000]-1 <<endl;
    return 0;
}


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

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int sum = 700;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'o') {
            sum += 100;
        }
    }
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define ld long double
#define F first
#define S second
//
#define int long long
#define ll long long
#define db(x)                cerr<<#x<<": "<<x<<endl
#define db2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define db3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define db4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define db5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define db6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
//
#define mem(x,y) memset(x,y,sizeof(x))
#define bitcount    __builtin_popcount
//
#define pii pair<int, int>
#define all(v) v.begin(),v.end()
//
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define vi vector<int>
#define vvi vector< vector<int> >
#define si set<int>
#define pb push_back
#define lp(i,a,b) for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define mk make_pair
const int N=50;
const int mod=1e9+7;
const int mod1=998244353;
const int inf=1e16+7;
using namespace std;

void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    set<int> adj[3];
    for(int i=0;i<n;i++){
        if(s[i]=='R')
        adj[0].insert(i);
        else if(s[i]=='G')
              adj[1].insert(i);
        else
              adj[2].insert(i);
    }
    int ans=0;
    for(int i:adj[0]){
        for(int j:adj[1]){
          //  if(i>j) continue;
            int diff=j-i;
            int c=0;
            if(diff%2==0){
                if(adj[2].count((i+j)/2)) c++;
            }
            if(adj[2].count(j+diff)) c++;
            if(adj[2].count(i-diff)) c++;
            
            ans+=adj[2].size()-c;
        }
    }
    cout<<ans;
}


int32_t main() {
    IOS;
    int t;
//    cin>>t;
    t=1;
    for(int i=1;i<=t;i++){
        solve();
       // cout<<endl;
    }
   
}

















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

int main()
{
    rep(i, 3)
    {
        string s;
        cin >> s;
        cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
 
vector<int> g[26];
int par[26],dep[26],sib[26],deg[26],h[26];
bool nroot[26];
int dfs(int v,int p,int d){
    par[v]=p,dep[v]=d;
    int ret=0;
    rep(i,g[v].size()){
        ret=max(ret,dfs(g[v][i],v,d+1)+1);
    }
    return h[v]=ret;
}
int main(){
    int n;
    cin>>n;
    int id,c1,c2;
    memset(sib,-1,sizeof(sib));
    rep(i,n){
        cin>>id;
        int cnt=0;
        cin>>c1>>c2;
        if(c1!=-1)g[id].pb(c1),sib[c1]=c2,nroot[c1]=true,++cnt;
        if(c2!=-1)g[id].pb(c2),sib[c2]=c1,nroot[c2]=true,++cnt; 
        deg[id]=cnt;
    }
    int root;
    rep(i,n)if(!nroot[i]) root=i;
    dfs(root,-1,0);
    rep(i,n){
        cout<<"node "<<i<<": parent = "<<par[i]<<", sibling = "<<sib[i];
        cout<<", degree = "<<deg[i];
        cout<<", depth = "<<dep[i];
        cout<<", height = "<<h[i]<<", ";
        if(root==i) cout<<"root";
        else if(g[i].size()>0) cout<<"internal node";
        else cout<<"leaf";
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	string s, ans = "Yes";
	in(s);

	rep(i, 0, s.size()) {
		if (i % 2 == 1) {
			if (s[i] == 'R') {
				ans = "No";
			}
		}
		else {
			if (s[i] == 'L') {
				ans = "No";
			}
		}
	}
	outn(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) for (int i=0; i<n; i++)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
    ll n, k; cin >> n >> k;
    if(k%2 == 1){
        ll i = n/k;
        ll ans = i*i*i;
        cout << ans << endl;
    }
    else{
        ll i = n/(k/2);
        ll j = n/k;
        ll k = i-j;
        ll ans = j*j*j;
        ans += k*k*k;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3608
#include<stdio.h>
#include<limits.h>


int main(void){
    int w, h, x, y;
    int s=0;
    scanf("%d %d %d %d", &w, &h, &x, &y);
    if(w==2*x&&h==2*y){
        s=1;
    }
    printf("%f %d", ((double)w*h)/2, s);
    return 0;
}

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

int n;
int a[100000];
int b[100001];
int c[100001];

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

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  
  b[0] = 0;
  c[n] = 0;
  for (int i = 0; i < n; ++i) {
    b[i + 1] = gcd(b[i], a[i]);
  }
  for (int i = n; i > 0; --i) {
    c[i - 1] = gcd(c[i], a[i - 1]);
  }
  
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    mx = max(mx, gcd(b[i], c[i + 1]));
  }
  cout << mx << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void)
{
	char a, b, c;
	scanf("%c%c%c", &a, &b, &c);
	if(a == '9')
	a = '1';
	else if(a == '1')
	a = '9';
	if(b == '9')
	b = '1';
	else if(b == '1')
	b = '9';
	if(c == '9')
	c = '1';
	else if(c == '1')
	c = '9';
	printf("%C%C%c", a, b, c);
	return 0;
}

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

using namespace std;

#define int long long
const int mod=(int)1e9+7;

void test_case(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='7'){
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        test_case();
    }
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    int N, K; cin >> N >> K;
    vll H(N);
    for (auto &v : H) cin >> v;
    sort(rbegin(H), rend(H));
    ll sum = 0;
    for (int i = K; i < N; i++) {
        sum += H[i];
    }
    cout << sum << endl;
    return (0);
}


Measured memory_bytes: 1792
#!/usr/bin/python3
#coding: utf-8

import sys

N = int(input())

zoromes = 0
for i in range(N):
    D1, D2 = (int(x) for x in input().split())
    if D1 == D2:
        zoromes += 1
        if zoromes >= 3:
            print("Yes")
            sys.exit(0)
    else:
        zoromes = 0
print("No")


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int N; cin >> N;
  string s[3];
  rep(i, 0, 3) cin >> s[i];
  int ans = 0;
  rep(i, 0, N) {
    int cnt = 0;
    if(s[0][i] == s[1][i]) {
      if(s[0][i] != s[2][i]) ans++;
    } else {
      if(s[0][i] != s[2][i] && s[1][i] != s[2][i]) ans += 2;
      else ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=105,M=1e9+7;
int n,m,a[N],dp[N][N][N];
int main(){
	scanf("%d",&n);
	m=(n<<1)-1;
	for (int i=1;i<=m;i++)scanf("%d",&a[i]);
	sort(a+1,a+m+1);
	dp[1][1][1]=1;
	for (int i=1;i<n;i++)
		for (int j=1;j<=m;j++)
			for (int k=1;k<=j;k++){
				int x=j,y=k;
				if (a[n-i]!=a[n-i+1])x++,y++;
				if (a[n+i]!=a[n+i-1])x++;
				for (int l=1;l<y;l++)(dp[i+1][x-(y-l-1)][l]+=dp[i][j][k])%=M;
				(dp[i+1][x][y]+=dp[i][j][k])%=M;
				for (int l=y+1;l<=x;l++)(dp[i+1][x-(l-y-1)][y+1]+=dp[i][j][k])%=M;
			}
	int ans=0;
	for (int i=1;i<=m;i++)
		for (int j=1;j<=i;j++)(ans+=dp[n][i][j])%=M;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

bool dp[30010][11][11][11];

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

  int N; string S; cin >> N >> S;
  REP(i, N+1) dp[i][10][10][10] = 1;
  REP(i, N){
    int now = S[i]-'0';
    REP(j, 11) REP(k, 11) REP(l, 11){
      dp[i+1][j][k][l] |= dp[i][j][k][l];
    }
    REP(j, 10) REP(k, 10) REP(l, 10){
      dp[i+1][j][k][now] |= dp[i][10][j][k];
      dp[i+1][10][j][now] |= dp[i][10][10][j];
    }
    dp[i+1][10][10][now] |= 1;
  }
  int ans = 0;
  REP(i, 10) REP(j, 10) REP(k, 10){
    // if(dp[N][i][j][k]) cerr << i << ' ' << j << ' ' << k << endl;
    ans += dp[N][i][j][k];
  }
  cout << ans << endl;
}

Measured memory_bytes: 39296
#include <stdio.h>
#include <math.h>
 
int main(void){
  int h, n;
  scanf("%d", &h);
  scanf("%d", &n);
  int a[n], sum=0;
  for(int i=0;i<n;i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }
  if(sum < h){
    printf("No");
  }else{
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
  int n;
  cin >> n;
  int ans = 0;
  int count=15;
  for(int i=0;i<n;i++){
    ans += 800;
  }
  ans -= 200*(n/15);
  cout << ans << endl;
}

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

int	main()
{
	int		A[200000];
	int64_t cnt[200000];
	int	N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cnt[i] = 0;
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A[i] = A[i] - 1;
		cnt[A[i]] += 1;
	}
	int64_t	total_combi = 0;
	for (int i = 0; i < N; ++i) {
		total_combi += cnt[i] * (cnt[i] - 1) / 2;
	}
	for (int i = 0; i < N; ++i) {
		cout << total_combi - cnt[A[i]] + 1 << endl;
	}
}


Measured memory_bytes: 4992
#include<stdio.h>
int main(){
  int f=0,i;
  char s[1000010];
  scanf("%s",s);
  for(i=0;s[i];i++){
    if(s[i]=='C'&&f==0)f=1;
    if(s[i]=='F'&&f==1)f=2;
  }
  printf("%s\n",f==2?"Yes":"No");
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;

int main(){
    int n;
    cin>>n;
    priority_queue<tuple<string,int,int>,vector<tuple<string,int,int>>,greater<tuple<string,int,int>>> sp;
    string s;
    int i,p;
    for(i=0;i<n;i++){
        cin >> s >> p;
        sp.push(make_tuple(s,-p,i+1));
    }
    while(!sp.empty()){
        cout<<get<2>(sp.top())<<endl;
        sp.pop();
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    int ans = 0;
    int sum = 1;
    rep(i,n){
        if(a[i] == a[i+1]){
            sum++;
        }else{
            if(sum % 2 == 1) ans++;
            sum = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
H,W = map(int,input().split())
g = [list(input()) for i in range(H)]

c = [[0 for w in range(W)] for h in range(H)]

hs = [0 for i in range(W)]

for h in range(H):
    ws = 0
    for w in range(W):
        if g[h][w] == '#':
            for i in range(ws,w):
                c[h][i] += w-ws-1
            ws = w+1
            for j in range(hs[w],h):
                c[j][w] += h-hs[w]
            hs[w] = h+1
    w2 = w+1
    for i in range(ws,w2):
        c[h][i] += w2-ws-1
h2 = h+1
for w in range(W):
    for j in range(hs[w],h2):
        c[j][w] += h2-hs[w]

#print(c)

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans,c[h][w])

print(ans)
'''
横方向と縦方向に分けてプログラムを作成してまとめた
横方向
for h in range(H):
    ws = 0
    for w in range(W):
        if g[h][w] == '#':
            for i in range(ws,w):
                c[h][i] += w-ws-1
            ws = w+1
    w2 = w+1
    for i in range(ws,w2):
        c[h][i] += w2-ws-1

縦方向
hs = [0 for i in range(W)]
for h in range(H):
    for w in range(W):
        if g[h][w] == '#':
            for j in range(hs[w],h):
                c[j][w] += h-hs[w]
            hs[w] = h+1
h2 = h+1
for w in range(W):
    for j in range(hs[w],h2):
        c[j][w] += h2-hs[w]
'''


Measured memory_bytes: 221704
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cassert>
using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define DEC(i, k) for (int i = (k); i >= 0; --i)
#define FORIT(i, c) for (__tyoeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define SZ(v) (int)((v).size())
#define MEMSET(v, h) memset((v), (h), sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())
#define ALL(c) (c).begin(), (c).end()

int w, h, n;
char iniField[40][40];
char field[40][40];
bool erase[40][40];
const int dx[2] = { 1, 0 };
const int dy[2] = { 0, 1 };

void printField() {
  REP(y, h) {
    puts(field[y]);
  }
}

void fall() {
  REP(iter, h) {
    for (int y = h - 1; y > 0; y--) {
      REP(x, w) {
        if (field[y][x] == '.') {
          swap(field[y][x], field[y - 1][x]);
        }
      }
    }
  }
}

void doit(int x, int y, int dir) {
  int suc = 0;
  char prev = '.';
  while (true) {
    suc++;
    if (prev != field[y][x]) { suc = 1; }
    if (field[y][x] == '.') { suc = 0; }
    if (suc == n) {
      int nx = x;
      int ny = y;
      REP(i, n) {
        erase[ny][nx] = true;
        nx -= dx[dir];
        ny -= dy[dir];
      }
    } else if (suc > n) {
      erase[y][x] = true;
    }
    prev = field[y][x];
    x += dx[dir];
    y += dy[dir];
    if (x < 0 || x >= w || y < 0 || y >= h) { break; }
  }
}

bool calc() {
  while (true) {
    fall();
    MEMSET(erase, false);
    REP(y, h) {
      doit(0, y, 0);
    }
    REP(x, w) {
      doit(x, 0, 1);
    }
    bool end = true;
    REP(y, h) REP(x, w) {
      if (erase[y][x]) {
        end = false;
        field[y][x] = '.';
      }
    }
    if (end) {
      REP(x, w) {
        if (field[h - 1][x] != '.') { return false; }
      }
      return true;
    }
  }
}

int main() {
  scanf("%d %d %d", &h, &w, &n);
  REP(y, h) {
    scanf("%s", iniField[y]);
  }
  REP(y, h) REP(x, w) {
    memcpy(field, iniField, sizeof(field));
    REP(dir, 2) {
      int nx = x + dx[dir];
      int ny = y + dy[dir];
      if (nx < 0 || nx >= w || ny < 0 || ny >= h) { continue; }
      swap(field[y][x], field[ny][nx]);
      if (calc()) {
        puts("YES");
        return 0;
      }
    }
  }
  puts("NO");
}

Measured memory_bytes: 844
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a)  (a).begin(),(a).end()

int under(int v,int m){
	int ret=0;
	while(ret+v<=m)ret+=v;
	return ret;
}

int main(){
	int n,m;
	while(cin>>n>>m&&(n||m)){
		vector<pair<pii,int>> vec;	//????????? ????\??????????????????£??????????????\???????????????
		vector<int> v(n);
		rep(i,n)cin>>v[i];
		
		rep(i,n){
			int time=under(v[i],m);	//i???????????????????????????????\???????
			int diffi=v[i];			//i??????????????????????????????????????£??????
			vec.push_back( make_pair(pii(time,diffi),i) );
		}
		sort(all(vec));
		if(vec[0].first==vec[1].first)cout<<n<<endl;	//time,difficult???????°???????????????°?±??????´???
		else cout<<vec[0].second+1<<endl;				//time,difficult???????°????????????????????±?????????´???
	}
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;

int main()
{
    int N, M;
    std::cin >> N >> M;
    std::vector<int> xs(M);
    for (int i = 0; i < M; i++) {
        std::cin >> xs.at(i);
    }
    if (N >= M) {
        std::cout << 0 << std::endl;
        return 0;
    }
    std::sort(xs.begin(), xs.end());
    std::vector<int> diffs(M - 1);
    for (int i = 0; i < M - 1; i++) {
        diffs.at(i) = (xs.at(i + 1) - xs.at(i));
    }
    std::sort(diffs.begin(), diffs.end());

    bint sum = std::accumulate(diffs.begin(), diffs.begin() + M - N, bint(0));
    std::cout << sum << std::endl;

    return 0;
}

Measured memory_bytes: 1024
def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a


def main():
    N, x = map(int, input().split())
    y = list(map(int, input().split()))
    y = [abs(i - x) for i in y]
    ans = y[0]
    for i in y[1:]:
        ans = gcd(i, ans)

    print(ans)

main()

Measured memory_bytes: 14224
n = int(input())
b = {}
ans = 0
for i in input().split():
    i = int(i)
    if(i in b):
        b[i] += 1
    else:
        b[i] = 1
for c in b:
    if(c < b[c]):
        ans += b[c] - c
    elif(c > b[c]):
        ans += b[c]
print(ans)

Measured memory_bytes: 23288
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int a,b;
  cin>>a>>b;
  long long int k;
  cin>>k;
  long long int count=0;
  long long int now=1;
  vector<long long int> hoge;
  for(long long int i=1; i<=100; i++){
    if(a%i==0&&b%i==0){
      hoge.push_back(i);
    }
  }
  cout<<hoge.at(hoge.size()-k)<<endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,x,y,n;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	if(a<0){
		y=c*a*(-1);
		n=e*b;
		x=y+d+n;
		printf("%d\n",x);
	}
	else{
		x=e*(b-a);
		printf("%d\n",x);
	}
	
	return 0;
}



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

using namespace std;

struct cmp {
   bool operator()(const string &v, const string &u) const {
      return v.size() > u.size();
   }
};

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   auto query = [&](string S) {
      cout << "? " << S << endl;
      int ans; cin >> ans;
      return ans;
   };
   int tot = 0;
   priority_queue<string, vector<string>, cmp> kek;
   auto deal = [&](char c) {
      int freq = 128 - query(string(128, c));
      tot += freq;
      kek.emplace(freq, c);
   };
   for (char c = 'a'; c <= 'z'; ++c) deal(c);
   for (char c = 'A'; c <= 'Z'; ++c) deal(c);
   for (char c = '0'; c <= '9'; ++c) deal(c);
   auto ok = [&](string S) {
      return S.size() + query(S) == tot;
   };
   while (kek.size() >= 2) {
      string x = kek.top(); kek.pop();
      string y = kek.top(); kek.pop();
      string z;
      int xptr = 0, yptr = 0;
      while (xptr < int(x.size()) && yptr < int(y.size())) {
         if (ok(z + x[xptr] + y.substr(yptr))) {
            z += x[xptr++];
         } else {
            z += y[yptr++];
         }
      }
      while (xptr < x.size()) z += x[xptr++];
      while (yptr < y.size()) z += y[yptr++];
      kek.push(z);
   }
   cout << "! " << kek.top() << endl;
   return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    int n,d;
    cin>>n>>d;
    int s=0;
    int x[n][d];
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x[i][j];
        }
    }
    double sum=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            sum=0;
            for(int k=0;k<d;k++){
                sum+=pow(x[i][k]-x[j][k], 2);
            }
            if (ceil(sqrt(sum)) == floor(sqrt(sum))) {
                s++;
            }
        }
    }
    cout<<s;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; 
  cin >> n;
  vector<string> s(10);
    s[1]="pon";
    s[2]="hon";
  s[3]="bon";
  s[4]="hon";
  s[5]="hon";
  s[6]="pon";
  s[7]="hon";
  s[8]="pon";
  s[9]="hon";
  s[0]="pon";
  cout << s[n%10] << endl;
  return 0;
 }

Measured memory_bytes: 3588
#include<bits/stdc++.h>
  
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed<<setprecision(14)
using namespace std;
using pii=pair<int,int>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol inf=(1LL<<60);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k,r;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n;
  if(360%n==0){
    cout <<360/n<<'\n';
  }else{
    cout <<lcm(360LL,n)/n<<'\n';
  }
  return (0);
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int aList[n], bList[n], cList[n];
    vector<int> plusVector, minusVector;
    long totalPlus = 0 , totalMinus = 0;
    for(int i = 0; i < n; i++) {
        cin >> aList[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> bList[i];
    }
    for(int i = 0; i < n; i++) {
        cList[i] = aList[i] - bList[i];
    }
    for(int i = 0; i < n; i++) {
        if(cList[i] >= 0) {
            plusVector.push_back(cList[i]);
        } else {
            minusVector.push_back(cList[i]);
        }
    }
    for(int i = 0; i < plusVector.size(); i++) {
        totalPlus += plusVector[i];
    }
    int changeCount = 0;
    for(int i = 0; i < minusVector.size(); i++) {
        totalMinus += minusVector[i];
        changeCount++;
    }
    if(totalPlus + totalMinus < 0) {
        cout << "-1" << endl;
        return 0;
    }
    sort(plusVector.begin(), plusVector.end(), greater<int>());
    for (int i = 0; i < plusVector.size(); i++) {
        if (totalMinus >= 0) {
            cout << changeCount << endl;
            return 0;
        }
        totalMinus += plusVector[i];
        changeCount++;
    }

    cout << changeCount << endl;
    return 0;
}


Measured memory_bytes: 2044
//B - Bishop

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long long h,w;

    cin >> h >> w;

    long long m = h * w;

    if ((h == 1) || (w == 1)) {
        cout << 1 << endl;
    }else{
        cout << m/2 + m%2 << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vi h(n);
  rep(i, n) cin >> h[i];
  vector<vi> g(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ans = 0;
  rep(i, n) {
    bool ok = true;
    for(auto v : g[i])
      if(h[v] >= h[i]) ok = false;
    if(ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 8804
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  int A[N+1]={0};
  for(int i=0;i<N;i++){
    if(S[i]=='I') A[i+1]=A[i]+1;
    else A[i+1]=A[i]-1;
  }
  sort(A,A+N+1);
  cout<<A[N]<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] array = new long[n + 1];
    for(int i = 0; i <= n; i++){
      array[i] = sc.nextLong();
    }
    System.out.println(solve(array));
  }
  static long solve(long[] a){
    long[] nodeCount = new long[a.length];
    long prev = 0;
    for(int i = a.length - 1; i > 0; i--){
      nodeCount[i] = prev + a[i];
      prev = nodeCount[i];
    }
    nodeCount[0] = 1;

    for(int i = 1; i < a.length; i++){
      long tmp = nodeCount[i - 1] - a[i - 1];
      if(tmp <= 0){
        return -1;
      } else {
        nodeCount[i] = Math.min(nodeCount[i], tmp * 2);
      }
    }
    if(nodeCount[nodeCount.length - 1] != a[a.length - 1]){
      return -1;
    }
    return Arrays.stream(nodeCount).sum();
  }
}


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

struct Node{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
};

struct Node *root,*NIL;

void insert(int k);
void inorder(struct Node *n);
void preorder(struct Node *n);


int main(){

  int i,n,s;
  char code[10];


  scanf("%d",&n);

  for(i = 0; i < n; i++){

    scanf("%s",code);

    if(strcmp(code,"insert") == 0){
      scanf("%d",&s);
      insert(s);
    
    }

    else if(strcmp(code,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      
    }
  }

  return 0;
}
      
    
void insert(int k){
  struct Node *b=NIL, *a = root, *c;

  c = malloc(sizeof(struct Node));
  c->key = k;
  c->right = NIL;
  c->left = NIL;

  while(a != NIL){

    b = a;
    
    if(c->key < a->key) a = a->left;

    else a = a->right;
  }

  c->parent = b;

  if(b == NIL)root = c;

  else{
    if(c->key < b->key) b->left = c;
    
    else b->right = c;
  }
  
}


void inorder(struct Node *n){
  if(n == NIL)return;

  inorder(n->left);

  printf(" %d",n->key);

  inorder(n->right);
}


void preorder(struct Node *n){

  if(n == NIL)return;

  printf(" %d",n->key);

  preorder(n->left);
  preorder(n->right);

}



Measured memory_bytes: 25164
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

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

    if(a[0] != 0){
        cout << -1 << endl;
        return 0;
    }

    for(int i=0; i+1<n; i++){
        if(a[i+1] - a[i] > 1){
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = 0;
    for(int i=0; i<n; i++){
        int cur = a[i];
        while(i + 1 < n && cur + 1 == a[i+1]){
            cur = a[++i];
        }

        ans += cur;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    unordered_map<int, bool> mp;
    ll cur = 0; int i = 0;
    while (1) { 
        // cout << i << endl;  
        cur = (cur * 10 + 7) % K;
        // cout << "--> " << cur << endl;
        if (mp[cur]) {
            break;
        }
        if (cur == 0) {
            cout << i + 1 << endl;
            return 0;
        }
        mp[cur] = true;
        i++;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 42612
#include <cmath>
#include <queue>
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 100010
#define ll long long
using namespace std;
inline ll read() 
{ 
    ll x=0,f=1;char ch=getchar(); 
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 
    return x*f; 
}
ll k;
ll h[51];
int main()
{
	k=read();
	ll tmp=k/50;
	ll tmp2=k%50;
	for(int i=1;i<=50;i++)
	h[i]=50+tmp-1;
	for(int i=1;i<=tmp2;i++)
	{
		h[i]+=50;
		for(int j=1;j<=50;j++)
		{
			if(j!=i)h[j]--;
		}
	}
	puts("50");
	for(int i=1;i<=50;i++)
	printf("%lld ",h[i]);
}

Measured memory_bytes: 256
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_058_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 i      PIC 9(2).
    01 O      PIC X(50).
    01 E      PIC X(50).
    01 ans    PIC X(100).
    01 len    PIC 9(2).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT O.
    ACCEPT E.

    COMPUTE len = FUNCTION STORED-CHAR-LENGTH(O).

    PERFORM VARYING i FROM 1 BY 1 UNTIL len < i
        STRING
            ans(1:FUNCTION STORED-CHAR-LENGTH(ans))
            O(i:1)
            E(i:1)
            INTO ans
        END-STRING
    END-PERFORM.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.


Measured memory_bytes: 636
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    a,b,c=parseMap(split(readline()))
    ans="NO"
    for i in 1:100000
        if (a*i)%b==c
            ans="YES"
            break
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 111148
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();
            final int N = Integer.parseInt(s);

            int sn = 0;

            for (int i = 0; i < s.length(); i++) {
                sn += Character.getNumericValue(s.charAt(i));
            }

            System.out.println(N % sn == 0 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 22484
INF = 10**9

def as_bit(ls):
    # 開けられる宝箱をbitで示す
    ret = 0
    for l in ls:
        ret |= 1 << (l - 1)
    return ret

def main():
    
    N, M = map(int, input().split())
    C, A = [], []
    for _ in range(M):
        a, b = map(int, input().split())
        A.append(a)
        c = list(map(int, input().split()))
        C.append(as_bit(c))

    dp = [[INF] * (2**N) for _ in range(M+1)]

    for i in range(M+1):
        dp[i][0] = 0

    for i in range(M):
        for bit in range(2**N):
            dp[i+1][bit|C[i]] = min(dp[i+1][bit|C[i]], dp[i][bit] + A[i])
            dp[i+1][bit] = min(dp[i+1][bit], dp[i][bit])

    ans = dp[-1][-1]
    print(ans if ans != INF else -1)

if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

// 600点, 27min

ll N;
map<ll, bool> meta; // 数, 奇数番目にいるべき数なら true
vector<ll> A;
vector<ll> ansA;

int main()
{
    cin >> N;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
        ansA.push_back(tmp);
    }
    SORT(ansA);
    REP(i, N) {
        meta[ansA[i]] = (i % 2 == 0) ? false : true;
    }
    ll ans = 0;
    REP(i, N) {
        if( (i % 2 == 0 && meta[A[i]] == true) ||
            (i % 2 != 0 && meta[A[i]] == false) ) { ans++; }
    }
    printf("%lld\n",ans / 2);

    return 0;
}


Measured memory_bytes: 8044
from collections import deque

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

b = deque()

for i in range(n):
    if i % 2 == n % 2:
        b.append(a[i])
    else:
        b.appendleft(a[i])

b = [str(x) for x in b]
print(" ".join(b))


Measured memory_bytes: 38156
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < int(n); ++i)
typedef long long i64;
 
int gcd(int x, int y) {
	return y ? gcd(y, x % y) : x;
}
 
int a[1000];
 
int main() {
	// your code goes here
	int n, m;
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
	}
	// Pick nm/gcd(n, m) = lcm(n, m) times.
	i64 tot = 0;
	int g = gcd(n, m);
	rep(i, n / g) {
		vector<int> t;
		rep(j, m) {
			// (i * m + j) % n -th is taken
			t.push_back(a[(i * m + j) % n]);
		}
		sort(t.begin(), t.end());
		tot += t[t.size() - 1] - t[0];
	}
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include<string.h>
#include<vector>
using namespace std;

#define rpt(i, n) for(i = 0; i < (n); i++)
typedef long long ll;

int main(void) {
	int n, d;
	cin >> n >> d;
	if (n % (2 * d + 1) != 0) {
		cout << n / (2 * d + 1) + 1;
	}
	else {
		cout << n / (2 * d + 1);
	}
	return 0;
}

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

using namespace std;

#define fore(i, s, e) for(ll i = s; i < (ll)e; i++)
#define pb push_back

typedef long long ll;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, z, K; cin >> x >> y >> z >> K;
    ll a[x], b[y], c[z];
    fore(i, 0, x) cin >> a[i]; 
    fore(i, 0, y) cin >> b[i]; 
    fore(i, 0, z) cin >> c[i];
    sort(a, a + x);
    sort(b, b + y);
    sort(c, c + z);
    reverse(a, a + x);
    reverse(b, b + y);
    reverse(c, c + z);
    vector<ll> res;
    fore(i, 0, x) {
        fore(j, 0, y) {
            fore(k, 0, z) {
                if((i + 1) * (j + 1) * (k + 1) <= K) res.pb(a[i] + b[j] + c[k]);
            }
        }
    }
    sort(res.begin(), res.end(), greater<ll>());
    fore(i, 0, K) {
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1400