akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int N=1e6+8;
int n,mx;
char s[N],t[N];
vector<int>pos[26];
queue<int>q;
int main(){
	scanf("%d%s%s",&n,s+1,t+1);
	if(!strcmp(1+s,1+t))return puts("0"),0;
	if(s[1]!=t[1])return puts("-1"),0;
	for(int i=1;i<=n;++i)
	pos[s[i]-'a'].push_back(i);
	int mx=0,l=n;
	for(int i=n;i;--i)if(t[i]!=t[i-1]){
		const int c=t[i]-'a';
		l=min(l,i);
		while(pos[c].size()&&pos[c].back()>l)pos[c].pop_back();
		if(pos[c].empty())return puts("-1"),0;
		l=pos[c].back();
		while(!q.empty()&&q.front()-q.size()>=i)q.pop();
		q.push(l);
		if(l!=i)mx=max(mx,(int)q.size());
		pos[c].pop_back();
	}
	printf("%d\n",mx+1);
	return 0;
}

Measured memory_bytes: 10632
s=list(input())
n=len(s)
if s==s[::-1]:
  t=s[:(n-1)//2]
  u=s[(n+3)//2-1:]
  if t==t[::-1] and u==u[::-1]:
    print('Yes')
    
  else:
    print('No')
    
else:
  print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    long double A,B;
    cin>>A>>B;
    ll ans=floor(A*B);
    cout<<ans<<endl;
}

Measured memory_bytes: 3732
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws ClassNotFoundException, IOException {
		FastScanner sc = new FastScanner();
		long W = sc.nextLong();
		long H = sc.nextLong();
		long x = sc.nextLong();
		long y = sc.nextLong();

		double centerW = W / 2.0;
		double centerH = H / 2.0;
		int flagNum = 0;
		double S = 0.0;
		if(centerW == x && centerH == y) {
			flagNum = 1;
			S = H * centerW;
		}else if(centerW == x) {
			S = H * centerW;
		}else if(centerH == y) {
			S = W * centerH;
		}else {
			S = H * W / 2.0;
		}


		System.out.println(S+ " " + flagNum);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

ll GCD(ll a, ll b){
    if(b==0) return a;
    else return GCD(b,a%b);
}

int main(){
    ll n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    ll g = a[0];
    REP(i,1,n){
        g = GCD(g,a[i]);
    }
    ll ans = 0;
    while(g%2==0){
        ans++;
        g /= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;
int n;
int cnt;
int main(){
	while(cin>>n&&n){
		int A[n];
		for (int i = 0; i < n; ++i) {
			cin>>A[i];
		}
		cnt=0;
		for (int i = n-1; i > 0; --i) {
			for (int j = 0; j < i; ++j) {
				if (A[j]>A[j+1]) {
					swap(A[j],A[j+1]);
					cnt++;
				}
			}
		}
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for(int i=a;i<b;i++)
#define repds(i,a,b) for(int i=a+1;i<=b;i++)
#define rep(i,N) repd(i,0,N)
#define reps(i,N) repds(i,0,N)
#define debug(x) cout<<#x<<"="<<x<<endl
#define debugarr(arr,N,M){rep(i,N+1){rep(j,M+1){if(arr[i][j]==INF)printf(" INF");\
	else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define cint(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};
//--------------------------------------//

int main(){
	int n,k;
	cin>>n>>k;
	if(n%k==0) cout<<"0"<<endl;
	else cout<<"1"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100000+10;
vector<int> edge[MAXN];
int n,cnt[3];
int tree[MAXN];
void bfs()
{
    queue<int> q;
    q.push(1),q.push(n);
    while(!q.empty())
    {
        int temp=q.front();
        q.pop();
        cnt[tree[temp]]++;
        for(int i=0;i<edge[temp].size();++i)
        {
            int v=edge[temp][i];
            if(tree[v])continue;
            else tree[v]=tree[temp];
            q.push(v);
        }
    }
}

int main()
{
    memset(tree,0,sizeof(tree));
    cin>>n;
    for(int i=1;i<n;++i)
    {
        int x,y;
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    tree[1]=1,tree[n]=2;
    bfs();
    if(cnt[2]>=cnt[1])
        cout<<"Snuke"<<endl;
    else
        cout<<"Fennec"<<endl;
    return 0;
}

Measured memory_bytes: 6272
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+1];
        int R[] = new int[N+1];
        for(int i=2; i<=N; i++) {
            A[i] = sc.nextInt();
            R[A[i]]++;
        }
        for(int i=1; i<=N; i++) {
            System.out.println(R[i]);
        }
    }
}


Measured memory_bytes: 61944
# 01-BFS
# 参考: White_Pie_46
# https://atcoder.jp/contests/abc176/submissions/16168825
# 01-BFSのちょっと丁寧な解説 - ARMERIA
# https://betrue12.hateblo.jp/entry/2018/12/08/000020

from collections import deque


def main():
    height, width = [int(x) for x in input().split()]
    init_h, init_w = [int(x) - 1 for x in input().split()]
    dest_h, dest_w = [int(x) - 1 for x in input().split()]
    grid = [list(input()) for _ in range(height)]

    can_walk = (
        (1, 0),
        (0, 1),
        (-1, 0),
        (0, -1)
    )

    def gen_warp_can_reach():
        for h in range(-2, 3):
            for w in range(-2, 3):
                if h == 0 == w:
                    continue
                yield (h, w, (h, w) in can_walk)
    warp_can_reach = tuple(gen_warp_can_reach())  # 移動先，徒歩で行けるか
    qu = deque()
    qu.append((init_h, init_w, 0))  # 座標とワープ回数を保持

    while qu:
        h, w, warps = qu.popleft()
        if h == dest_h and w == dest_w:
            return warps
        if grid[h][w] == 'R':
            # 同じマスを複数回キューに追加しているかもしれない。
            continue
        grid[h][w] = 'R'  # reached

        for h_delta, w_delta, walking in warp_can_reach:
            new_h, new_w = h + h_delta, w + w_delta
            if 0 <= new_h < height and 0 <= new_w < width:
                if grid[new_h][new_w] == '.':
                    if walking:
                        qu.appendleft((new_h, new_w, warps))
                    else:
                        qu.append((new_h, new_w, warps + 1))
    return -1


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 189936
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

int main()
{
     int n,k;
     cin>>n>>k;
     int a[n];
     for(int i=0;i<n;i++)
          cin>>a[i];
     int dp[n];
     for(int i=0;i<n;i++)
          dp[i]=INT_MAX;
     dp[0]=0;
     for(int i=0;i<n;i++)
     {
          for(int j=1;j<=k;j++)
          {
              if(i+j<n)
               dp[i+j]=min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));
          }
     }
     cout<<dp[n-1]<<'\n';
}


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef int ss;
#define int long long

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

ll a,b,c;


ss main()
{
    cin>>a>>b;
    b += a * 3;
    cout<< b/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll a[100010],b[100010];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	for(ll i=0;i<n;i++){
		cin>>b[i];
	}
	ll A=0,B=0;
	for(ll i=0;i<n;i++){
		if(a[i]>b[i]){
			B+=a[i]-b[i];
		}
		else{
			A+=(b[i]-a[i])/2;
		}
	}
	cout << (B<=A?"Yes":"No");
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
import math
# from itertools import product, accumulate, combinations, product
import bisect
# import numpy as np
# from copy import deepcopy
#from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())



def run():
    S, T = input(), input()
    dic = defaultdict(lambda : [])
    for i, s in enumerate(S):
        dic[s].append(i)

    k = -1
    ans = 1
    for t in T:
        if t in dic.keys():
            i = bisect.bisect_right(dic[t], k)
            if i >= len(dic[t]):
                k = dic[t][0]
                ans += 1
            else:
                k = dic[t][i]

        else:
            print(-1)
            return

    print((ans-1) * len(S) + k +1)


if __name__ == "__main__":
    #print(math.gcd(0, 10))
    run()


Measured memory_bytes: 13768
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
const int INF = 2 * 1e9;

int main(){
    int n;
    cin >> n;
    vector<P> d;
    rep(i, 0, n){
        int h, p;
        cin >> h >> p;
        d.push_back(P(h + p, p));
    } 
    sort(all(d));
    int dp[5010] = {};
    rep(i, 0, 5010) dp[i] = INF;
    dp[0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = i; j >= 0; j--){
            if(dp[j] != INF && dp[j] <= d[i].first - d[i].second){
                dp[j + 1] = min(dp[j + 1], dp[j] + d[i].second);
            }
        }
    }
    int ans = 0;
    rep(i, 0, n + 1){
        if(dp[i] != INF) ans = i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;

signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << a + b + c - max({ a,b,c });
}

Measured memory_bytes: 256
// 27
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) \
  for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) \
  for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef LOCAL
#define debug(e)                             \
  cerr << "\033[48;5;196m\033[38;5;15m" << e \
       << "\033[0m";
#else
#define debug(e)
#endif
// 4
template <class A, class B>
ostream &operator<<(ostream &o, const pair<A, B> &p) {
  return o << "(" << p.fi << " " << p.se << ")";
}
// 8
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  rep(i, (int)v.size()) o << setw(7) << left << v[i];
  return o << endl;
}
// 5
template <class A, class B>
ostream &operator<<(ostream &o, const map<A, B> &m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 3
void _main(int tc) {
  char c;
  cin >> c;
  if (c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

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

int main()
{
	int n;
    scanf("%d", &n);
    if(n % 2 == 0){
        printf("%d\n", (n/2) * (n/2));
    }
    else
        printf("%d\n", (n/2) * ((n/2) + 1));
}






Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, steps=0;
  cin >> N;
  vector<int> a(N);
  vector<int> count(100, 0);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
    count.at(a.at(i)-1)=a.at(i);
  }
  for(int i=0; i<100; i++){
    if(!(count.at(i)==0)) steps++;
  }
  cout << steps << endl;
}

Measured memory_bytes: 256
s = list(input())
t = list(input())

len_s = len(s)
len_t = len(t)

A = []

for i in range(len_s - len_t + 1):
    total = 0
    for j in range(len_t):
        if t[j] != s[i + j]:
            total += 1
    A.append(total)

print(min(A))

Measured memory_bytes: 65232
import java.util.Scanner;

public class Main{
  static int A,B,Q;
  static Long[] S,T,X;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    A = sc.nextInt();
    B = sc.nextInt();
    Q = sc.nextInt();
    S = new Long[A+2];
    T = new Long[B+2];
    X = new Long[Q];
    for(int i=1;i<=A;i++){
      S[i]=sc.nextLong();
    }
    S[0]=-100000000000000000L;
    S[A + 1]=100000000000000000L;
    for(int i=1;i<=B;i++){
      T[i]=sc.nextLong();
    }
    T[0]=-100000000000000000L;
    T[B + 1]=100000000000000000L;
    for(int i=0;i<Q;i++){
      X[i]=sc.nextLong();
    }
    for(int i=0;i<Q;i++){
      System.out.println(Qanswer(i));
    }
  }

  static int binary_search(Long[] a, Long x, int lb, int ub) {
    if (ub  - lb <= 1) {
      return lb;
    } else {
      int mid = (lb + ub) / 2;
      if (a[mid] <= x) return binary_search(a, x, mid, ub);
      else return binary_search(a, x, lb, mid);
    }
  }

  static Long Qanswer(int i){
    int Snear = binary_search(S,X[i],0,S.length-1);
    int Tnear = binary_search(T,X[i],0,T.length-1);

    /* ======== DEBUG ======== */
    //System.out.println("[" + S[Snear] + ", " + X[i] + ", " + S[Snear + 1] + "]");
    //System.out.println("[" + T[Tnear] + ", " + X[i] + ", " + T[Tnear + 1] + "]");
    /* ======== /DEBUG ======== */

    return minimum(caliculate(i,Snear,Tnear),caliculate(i,Snear,Tnear+1),caliculate(i,Snear+1,Tnear),caliculate(i,Snear+1,Tnear+1));
    /*if((Snear<=X[i] && Tnear<=X[i]) || (Snear>=X[i] && Tnear>=X[i])){
      return Math.max(Math.abs(X[i]-Snear),Math.abs(X[i]-Tnear));
    }
    else{
    return Math.max(Math.abs(X[i]-Snear),Math.abs(X[i]-Tnear))+2*Math.min(Math.abs(X[i]-Snear),Math.abs(X[i]-Tnear));
    }
    */
  }

  static Long caliculate(int i,int r,int l){
    return Math.min(Math.abs(X[i]-S[r]) + Math.abs(T[l]-S[r]), Math.abs(X[i]-T[l]) + Math.abs(S[r]-T[l]));
    //if((S[r]<=X[i] && T[l]<=X[i]) || (S[r]>=X[i] && T[l]>=X[i])){
    //  /* ======== DEBUG ======== */
    //  //System.out.println("1: " + Math.abs(X[i] - S[r]) + ", " + Math.abs(X[i] - T[l]));
    //  /* ======== /DEBUG ======== */
    //  return Math.max(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l]));
    //}
    //else{
    //  /* ======== DEBUG ======== */
    //  //Long t = Math.max(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l])) + 2*Math.min(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l]));
    //  //System.out.println("2: " + t);
    //  /* ======== /DEBUG ======== */
    //  return Math.max(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l]))+2*Math.min(Math.abs(X[i]-S[r]),Math.abs(X[i]-T[l]));
    //}
  }

  static Long minimum(Long a,Long b,Long c,Long d){
    Long ans = 100000000000000000L;
    Long[] Arra= new Long[4];
    Arra[0] = a;
    Arra[1] = b;
    Arra[2] = c;
    Arra[3] = d;
    for(int i=0;i<4;i++){
      if(ans>=Arra[i]){
        ans = Arra[i];
      }
    }
    return ans;
  }

}

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

int f(int c){
	int d = 1;
	
	while(c >= 10){
		c = c/10;
		d++;
	}
	
	cout << d << endl;
	return 0;
}

int main() {
	int a;
	while(cin>>a){
		int b;
		cin >> b;
		
		int c = a + b;
		f(c);
	}
	
	return 0;
}

Measured memory_bytes: 2956
n, m, l = (int(x) for x in input().split())

A =  []
B = []
for r in range(n):
    line = input().split()
    row = [int(x) for x in line]
    A.append(row)

for r in range(m):
    line = input().split()
    row = [int(x) for x in line]
    B.append(row)

# print(A)
# print(B)

C = []
for r in range(n):
    row = []
    for c in range(l):
        s = 0
        for j in range(m):
            s += A[r][j] * B[j][c]
#             print(r, c, j, A[r][j], B[j][c])
        row.append(s)
    C.append(row)

for r in range(n):
    line = ""
    for c in range(l):
        line += str(C[r][c]) + " "
    print(line.strip())


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n;
  cin >> n;
  if(n==1) cout << "Hello World" << endl;
  else {
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
	char s[10];

	scanf("%s",s);
	
	if(s[0]==s[1]&&s[0]==s[2]&&s[0]==s[3]){
		printf("No\n");
	}
	else if(s[0]==s[1]){
		if(s[2]==s[3]){
			printf("Yes\n");
		}else {
			printf("No\n");
		}
	}else if(s[0]==s[2]){
		if(s[1]==s[3]){
			printf("Yes\n");
		}else {
			printf("No\n");
		}
	}else if(s[0]==s[3]){
		if(s[1]==s[2]){
			printf("Yes\n");
		}else {
			printf("No\n");
		}
	}else {
		printf("No\n");
	}
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdbool.h>


int findTown(int V, long K, int adj[])
{
    bool cycle = 0;
    int s = 1, path[V+1], in_path[V+1] = {0}, len = 0;
    long K_cpy = K;
    
    while(K_cpy-- && !cycle)
    {
        if(in_path[s])
            cycle = 1;
        else
        {
            path[++len] = s;
            in_path[s] = len;
            s = adj[s];   
        }
    }
    
    if(cycle)
    {
        int cyc_start = in_path[s];
        K -= (cyc_start - 1);
        int cyc_len = len - cyc_start + 1;
        int node_in_cyc = K % cyc_len;
        return path[cyc_start + node_in_cyc];    
    }
    else
        return s;
}
int main()
{
    int n, ans;
    long k;
    scanf("%d %ld", &n, &k);
    
    int edges[n + 1];
    for(int i = 1 ; i <= n ; i++)
        scanf("%d",&edges[i]);
    
    ans = findTown(n, k, edges);
    
    printf("%d",ans);
}

Measured memory_bytes: 3920
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}
map<ll,ll> prime_factor(ll x){
    map<ll,ll> m;
    ll sq=(ll)sqrt(x) + 1;
    vector<ll> v_prime=vectorprime(sq);
    
    ll tmp=x;
    rep(i,sz(v_prime)){
        ll count=0;
        while(tmp % v_prime[i] == 0){
            tmp /= v_prime[i];
            count++;
        }
        if(count != 0) m[v_prime[i]]=count;
        if(tmp==1) break;
    }
    
    if(tmp != 1) m[tmp]=1;
    return m;
}
ll fac[500001],finv[500001],inv[500001];
 
void table() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(ll i=2;i<500001;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;
    }
}

ll dev(long long a,long long b){
    return (a*inv[b])%MOD;
}

ll comb(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;
}

int main(){
    table();
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M; cin>>N>>M;
    map<ll,ll> m=prime_factor(M);
    
    ll tmp=1;
    for(auto x:m){
        tmp*=comb(x.b+N-1,N-1);
        tmp%=MOD;
    }
    tmp%=MOD;
    
    cout<<tmp<<endl;
}



Measured memory_bytes: 15420
#include <iostream>
using namespace std;
 
int main(void){
    int N;
    int il;
    int rl;
    int all;
    cin >> N;
    for(int i = 0; i < N; i += 1){
    	cin >> il >> rl;
    	all += rl - il + 1;
    }
    cout << all << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    double t = Double.parseDouble(sc.next());
    double a = Double.parseDouble(sc.next());
    sc.nextLine();
    int ans = 0;
    String h = sc.nextLine();
    String[] ha = h.split(" ");
    double[] hd = new double[n];
    for (int i = 0; i < n; i++) {
      hd[i] = t - Double.parseDouble(ha[i]) * 0.006;
      if (Math.abs(a - hd[i]) < Math.abs(a - hd[ans]))
        ans = i;  
    }
    System.out.println(ans+1);
  }
}

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

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

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   int a, b , c;
   cin >> a >> b >> c;
   for(int i = 1; i < 1000000; i++)
   {
      if(i*a % b == c)
      {
         cout << "YES" << nl;
         return 0;
      }
   }
   cout << "NO" <<nl;
   return 0;

}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while(cin >> n) {
    vector<int> A(n + 1), B(n + 1), C(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 - 1; ++i) cin >> C[i];
    long long sum = 0;
    for(int i = 1; i <= n; ++i) sum += B[i];
    for(int i = 2; i <= n; ++i) {
      if(A[i - 1] == A[i] - 1) sum += C[A[i - 1]];
    }
    cout << sum << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

int gcd(int a,int b){
    while(b!=0){
        a %= b;
        if(a==0) return b;
        b %= a;
    }
    return a;
}
signed main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> mp(1001001,0);
    bool ok=1;
    int G;
    rep(i,n){
        cin >> a[i];
        int mx=a[i];
        if(i==0) G=a[i];
        else G=gcd(G,a[i]);
        if(ok){
            for(int j=2;j*j<=mx;j++){
                if(mx%j==0){
                    if(mp[j]>0) ok=0;
                    mp[j]++;
                    while(mx%j==0){
                        mx/=j;
                    }
                }
            }
            if(mx!=1){
                if(mp[mx]>0) ok=0;
                mp[mx]++;
            }
        }
    }
    if(ok) cout << "pairwise coprime" << endl;
    else if(G==1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}




Measured memory_bytes: 11168
#include <stdio.h>
#include <string.h>
#define LEN 100001

typedef struct process {
    char name[11];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    if (tail == n)
        tail = 0;
    else
        tail += 1;
}

P dequeue() {
    P tp = Q[head];
    if (head == n)
        head = 0;
    else
        head += 1;
    return tp;
}

int main() {
    int q;
    scanf("%d %d", &n, &q);

    int i;
    for (i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }

    head = 1;
    tail = 0;
    P p;
    int elaps = 0;

    while (head != tail) {
        p = dequeue();
        if (p.t > q) {
            p.t -= q;
            elaps += q;
            enqueue(p);
        } else {
            elaps += p.t;
            printf("%s %d\n", p.name, elaps);
        }
    }

    return 0;
}

Measured memory_bytes: 2576
#include<iostream>

using namespace std;

int main()
{
	
	int a,b,c;
	
	cin>>a>>b>>c;
	
	if(0==(100*a+10*b+c)%4)
	{
		
		cout<<"YES"<<endl;
		
	}
	
	else cout<<"NO"<<endl;
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int_;
inline int readint() {
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0' or c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c and c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}
void writeint(int_ x){
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) writeint(x/10);
	putchar((x%10)^48);
}
# define MB template < typename T >
MB void getMax(T &a,const T &b){ if(a < b) a = b; }
MB void getMin(T &a,const T &b){ if(b < a) a = b; }
# define FOR(i,n) for(int i=0; i<(n); ++i)

int ans, x[11], n, m, q;
int a[51], b[51], c[51], d[51];
void check(){
	int now = 0;
	for(int i=1; i<=q; ++i)
		if(x[b[i]]-x[a[i]] == c[i])
			now += d[i];
	getMax(ans,now);
}
void dfs(int t){
	if(t > n) return check();
	for(int i=x[t-1]; i<=m; ++i)
		x[t] = i, dfs(t+1);
}

int main(){
	int_ a, b, n;
	scanf("%lld %lld %lld",&a,&b,&n);
	printf("%lld\n",min(b-1,n)*a/b);
	return 0;
}

Measured memory_bytes: 3824
class SegmentTree():
    def segfunc(self, x, y):
        return max(x, y)
    
    def __init__(self, a): #a:リスト
        n = len(a)
        self.ide_ele = 0 #単位元
        self.num = 2**((n-1).bit_length()) #num:n以上の最小の2のべき乗
        self.seg = [self.ide_ele]*2*self.num
        
        #set_val
        for i in range(n):
            self.seg[i+self.num-1] = a[i]
        #built
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])
        
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
            
    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q - p > 1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

N = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))
dp = [0] * N
S = SegmentTree(dp)
for i in range(N):
    tmp = S.query(0,h[i]-1)
    S.update(h[i]-1, tmp+a[i])
print(S.query(0,N))

Measured memory_bytes: 121724
#include <stdio.h>
int main()
{
	char num[4];
  	int count2 = 0;
  	scanf("%s", num);
  	for (int i = 0; i < 4; i++){
    	if (num[i] == '2'){
        	count2++;
        }
    }
  	printf("%d", count2);
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

char s[] = "AKIHABARA";

int pos[] = {0, 4, 6, 8};

int main()
{
    string ss;
    cin >> ss;
    for (int mask = 0; mask < (1 << 4); mask++)
    {
        string sss(s);
        for (int i = 3; i >= 0; i--) if (mask & (1 << i)) sss.erase(sss.begin() + pos[i]);
        if (ss == sss)
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int h,n,a[100000],sum=0;
    cin>>h>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=h)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int A,B,C;cin >> A >> B >> C;
    int K;cin >> K;
    int ct = 0;
    while(A >= B){
        B *= 2;
        ct++;
    }
    while(B >= C){
        C *= 2;
        ct++;
    }
    if(ct <= K)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    ll N;cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }

    ll ans = 0;
    while(1){
        ll tar = -1;   //2で割られる数のインデックス
        rep(i,N){
            if(A[i]%2 == 0){
                if(tar == -1)tar = i;
                else if(A[i]%4 == 0){
                    A[i] /= 2;
                    ans++;
                    break;
                }
            }
        }
        if(tar != -1){
            A[tar] /= 2;
            ans++;
        }
        else break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
typedef pair<ll,ll> P;
P a[200010];
int main(){
    ll h,w,x;cin>>w>>h;
    lol(i,w){cin>>x;a[i]=make_pair(x,0);}
    lol(i,h){cin>>x;a[i+w]=make_pair(x,1);}
    sort(a,a+h+w);
    ll ans=0,cnt[2]={0};
    lol(i,h+w){
	int t=a[i].second;
	cnt[t]++;
	if(t==0){
	   ans+=(h-cnt[1]+1)*a[i].first;
	}
	if(t==1){
	   ans+=(w-cnt[0]+1)*a[i].first;
	}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3328
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 全国統一プログラミング王決定戦予選：A - Subscribers


def main():
    N, A, B = [int(i) for i in raw_input().strip().split(' ')]

    x = min(A, B)
    y = A + B - N
    if y < 0:
        y = 0
    print x, y


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
num = int(input())
data = input().split()

int_data = [int(i) for i in data]

cnt= 0

judge = True

while judge == True:
    
    for i in range(num):
        if int_data[i] % 2 == 0:
            int_data[i] = int_data[i] / 2
        else:
            judge = False
            break

    cnt += 1
    
print(cnt - 1)

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

bool prime(int x)
{ if(x==1)
   return 0;
   for(int i=2;i*i<=x;i++)
    if(x%i==0)
    return 0;
    return 1;
}
void find(int x)
{  int i; for( i=x;;i++)
       if(prime(i))
         break;
    cout<<i;   }  
int main()
{ ll x;
   cin>>x;
   find(x);
   return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long LL;

int main(){
  LL A,B,C,K;
  cin >> A >> B >> C >> K;

  if(A-B < -1e18 || 1e18 < A-B){
    cout << "Unfair" << endl;
    return 0;
  }

  if(K%2==0){
    cout << A - B << endl;
  }else{
    cout << B - A << endl;
  }

  return 0;
}


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

int main(){
	int n;
	cin >> n;
	int ac = 0,wa = 0,tle = 0,re = 0;
	string result;
	for(int i=0;i<n;i++){
		cin >> result;
		if(result == "AC"){
			ac++;
		}else if(result == "WA"){
			wa++;
		}else if(result == "TLE"){
			tle++;
		}else{
			re++;
		}
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
int main() {
    int m, f, r;
    for(;;) {
        cin >> m >> f >> r;
        int sum = m + f;
        if(m == -1 && f == -1 && r == -1) break;
        if(m == -1 || f == -1) cout << "F" << endl;
        else if(sum >= 80) cout << "A" << endl;
        else if(sum >= 65) cout << "B" << endl;
        else if(sum >= 50) cout << "C" << endl;
        else if(sum >= 30) {
            if(r >= 50) cout << "C" << endl;
            else cout << "D" << endl;
        }
        else cout << "F" << endl;
        
    }
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	bool itd=true;
	for(int i=0;i<s.size();i++)
	{
		if((i+1)%2==1)
		{
			if(s[i]!='R'&&s[i]!='U'&&s[i]!='D')
			{
				itd=false;
				break;
			}
		}
		else
		{
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D')
			{
				itd=false;
				break;
			}
		}
	}
	if(itd)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
    return 0;	
} 	

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

template<class T, class U> inline int divCount(T &num, U divisor) {
    int count = 0;
    while (num % divisor == 0) {
        num /= divisor;
        count++;
    }
    return count;
}

void solve(long long N, std::vector<long long> A){
    int ans = 1001001001;
    REP(i, N)
        chmin(ans, divCount(A[i], 2));
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s)
    ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

unordered_set<ll> enum_div(ll n)  // nの約数を列挙
{
  std::unordered_set<ll> ret;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ret.insert(i);
      if (i * i != n) {
        ret.insert(n / i);
      }
    }
  }
  return ret;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> dp(1 << N, 1 << 29);
  dp[0] = 0;
  FOR(i, M) {
    int b;
    cin >> a[i] >> b;
    int add = 0;
    FOR(j, b) {
      int c;
      cin >> c;
      add |= 1 << (c - 1);
    }
    FOR(j, 1 << N) { dp[j | add] = min(dp[j | add], dp[j] + a[i]); }
  }
  print(dp[(1 << N) - 1] == 1 << 29 ? -1 : dp[(1 << N) - 1]);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<int> a(n);
    map<int, ll> acnt;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        acnt[a[i]]++;
    }

    ll ans = 0;
    for (P<int, ll> aaa: acnt) {
        ans += aaa.second * (aaa.second - 1) / 2;
    }

    for (int i = 0; i < n; i++) {
        if (acnt[a[i]] == 1) cout << ans << '\n';
        else {
            cout << ans - acnt[a[i]] * (acnt[a[i]] - 1) / 2 + (acnt[a[i]] - 1) * (acnt[a[i]] - 2) / 2 << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 10368
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var n2 = (n - 1) / 2;
            var w1 = new List<int>();
            for (int i = 1; i < n; i++) w1.Add(i * i  % n);
            var w2 = w1.Distinct().ToArray();
            var w2L = w2.Length;
            var ret = new int[n2];
            for (int i = 0; i < w2L; i++)
                for (int j = 0; j < w2L; j++)
                    if (i != j)
                    {
                        var z = w2[i] - w2[j];
                        if (z < 0) z += n;
                        if (z > n2) z = n - z;
                        ret[z-1]++; 
                    }
            foreach (var x in ret)
                Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 10592
#include <stdio.h>
int main(void){
  int a,b,c,d,s,e;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  s=(a>c)? a:c;
  e=(b<d)? b:d;
  printf("%d\n",(s<e)? e-s:0);
  return 0;
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;

int main() {
    ios::sync_with_stdio (false), cin.tie (0);
    int n;
    cin >> n;
    string a;
    cin >> a;
    int ans = 0;
    for(int i =0; i < n; i++){
        if(a[i] != a[i + 1]){
            ans++;
        }
    }
    cout << ans << '\n';



    return 0;
}














Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    cin >> N;
    if(N < 1000){
        cout << "ABC" << endl;
    }else{
        cout << "ABD" << endl;
    }

    return 0;
}

Measured memory_bytes: 3604
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
	mod            = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type Edge struct {
	to, cost int
}

// 辺のリストで表現されるグラフ
type Graph struct {
	Edges [][]Edge // Edge[i][j]: 頂点iのj番目の辺
}

// 頂点数nのリスト型グラフを返す
func NewGraph(n int) *Graph {
	g := &Graph{
		Edges: make([][]Edge, n),
	}
	for i := 0; i < n; i++ {
		g.Edges[i] = make([]Edge, 0)
	}
	return g
}

// 辺の追加
func (g *Graph) AddEdge(from, to, cost int) {
	g.Edges[from] = append(g.Edges[from], Edge{to, cost})
}

func P(n, k int) int {
	res := 1
	for ; k >= 1; k-- {
		res *= n
		res %= mod
		n--
	}
	return res
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func dfs(g *Graph, k, cur, prev int, ans *int) {
	if prev >= 0 {
		*ans *= P(max(0, k-2), len(g.Edges[cur])-1)
	} else {
		*ans *= P(k-1, len(g.Edges[cur]))
	}
	*ans %= mod
	for _, e := range g.Edges[cur] {
		if e.to != prev {
			dfs(g, k, e.to, cur, ans)
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, k := nextInt(), nextInt()
	g := NewGraph(n)
	for i := 0; i < n-1; i++ {
		a, b := nextInt()-1, nextInt()-1
		g.AddEdge(a, b, 1)
		g.AddEdge(b, a, 1)
	}

	ans := k
	dfs(g, k, 0, -1, &ans)

	puts(ans)
}


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

typedef long long ll;


ll f(ll b, ll n){
  ll ret = 0;
  while(n>=b){
    ret += n%b;
    n = n/b;
  }
  return ret+n;
}

int main(){
  ll n,s;
  cin>>n>>s;
  if(s==n){
    cout<<n+1<<endl;
    return 0;
  }

  ll b=2;
  while(b*b<=n){
    if(f(b,n)==s){
      cout<<b<<endl;
      return 0;
    }
    b += 1;
  }

  ll p = ll(sqrt(n))+2;
  while(p>0){
    ll q = s - p;
    ll b = (n-q)/p;
    if(b>1 && f(b,n)==s){
      cout<<b<<endl;
      return 0;
    }
    p--;
  }

  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 256