akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(ll i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(arg),key)-begin(arg)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

using namespace std;

using R=long double;
const R EPS = 1E-11;
const R INF = 1E40;
constexpr R PI = acos(R(-1));
inline int sgn(const R& r){ return (r > EPS) - (r < -EPS);}

using P=complex<R>;
constexpr P O = P(0,0);
#define X real()
#define Y imag()

istream& operator >> (istream& is,P& p){ R x,y; is >> x >> y; p=P(x,y); return is;}
ostream& operator << (ostream& os,P& p){ os << p.X << " " << p.Y; return os;}

//?????? dot ?????? det
inline R dot(P o,P a,P b){a-=o,b-=o; return real(conj(a)*b);}
inline R det(P o,P a,P b){a-=o,b-=o; return imag(conj(a)*b);}

using L=struct{P s,t;};

// ?°???± verify AOJ CGL_1_A
P proj(P o,P a,P b){ a-=o,b-=o; return a*(b/a).X;}
P proj(L l,P p){ return l.s+proj(l.s,l.t,p);}
// ????°? verify AOJ CGL_1_B
P refl(L l,P p){ return R(2.0)*proj(l,p)-p;}
// CCW verify AOJ CGL_1_C
enum CCW{ LEFT = 1,RIGHT = 2,BACK = 4,FRONT = 8,ON = 16};
inline int ccw(P o,P a, P b) {//???a??¨???b???????????????????????????
	if (sgn(det(o,a,b)) > 0) return LEFT;    // counter clockwise
	if (sgn(det(o,a,b)) < 0) return RIGHT;   // clockwise
	if (sgn(dot(o,a,b)) < 0) return BACK;    // b--base--a on line
	if (sgn(norm(a)-norm(b)) < 0) return FRONT;   // base--a--b on line
	return ON;// base--b--a on line  a??¨b????????????????????????
}

int main(void){
	P a,b,p;
	int n;
	cin >> a >> b >> n;
	L l={a,b};
	cout.precision(20);
	rep(i,n){
		cin >> p;
		P ans=proj(l,p);
		cout << fixed << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, k;
ll v[51];
int main() {
    cin>>n>>k;
    REP(i, 0, n) cin>>v[i];

    ll mx=0;
    REP(l, 0, k+1){
        REP(r, 0, k-l+1){
            if(l+r>n) break;

            ll sum=0, res=k-l-r;
            vector<ll> gem;
            REP(i, 0, l){
                gem.emplace_back(v[i]);
                sum+=v[i];
            }
            REP(i, n-r, n){
                gem.emplace_back(v[i]);
                sum+=v[i];
            }

            if(gem.empty()) continue;

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

            REP(i, 0, res){
                if(i>=gem.size()) break;
                if(gem[i]>0) break;

                sum-=gem[i];
            }
            mx=max(mx, sum);
        }
    }

    cout<<mx<<endl;
    return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n;
	while (cin >> n, n) {
		int a(0), b(0);
		rep(i, 0, n) {
			int x, y; cin >> x >> y;
			if (x == y) {
				a += x;
				b += y;
			}
			else if (x < y)b += x + y;
			else a += x + y;
		}
		cout << a << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 3036
#include <cstdio>
#include <algorithm>
using namespace std;
int N, h[100001], dp[100001];
int main() {
  scanf("%d", &N);
  for(int i = 1; i <= N; i++) scanf("%d", &h[i]);
  dp[0] = 1e9, dp[1] = 0;
  for(int i = 2; i <= N; i++) {
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
  }
  printf("%d", dp[N]);
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using namespace std;


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

    int now = 1;

    for(int i = 0; i < N; i++){
        int m = now*2;
        int a = now + K;
        if(m > a){
            now = a;
        }else{
            now = m;
        }
    }

    cout << now << endl;

    return 0;
}


Measured memory_bytes: 256
F =-> {gets.split.map &:to_i}
N,M = F[]
A = [nil] * N
E = A.map {[]}
M.times { a,b = F[]; E[a-1] << b-1; E[b-1] << a-1 }
X = [[0,0]]
until X.empty?
  X.pop(X.size).each {|(i,a)|
    next  if A[i]
    A[i] = a+1
    E[i].each {|j| X << [j,i] }
  }
end
A.all?{_1} ? A[0]=:Yes : A.replace([:No])
puts A 

Measured memory_bytes: 53208
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    h,w,a,b=map(int,input().split())
    s='1'*a+'0'*(w-a)
    t='0'*a+'1'*(w-a)
    for i in range(b):
        print(s)
    for i in range(h-b):
        print(t)
resolve()

Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
int main(){
    int aiueo;
    string ans="No";
    vector<vector<int>>board(3,vector<int>(3));
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin>>board.at(i).at(j);
        }
    }
    int n;
    cin>>n;
    vector<int>bingo(n);
    for(int i=0; i<n; i++){
        cin>>bingo.at(i);
    }

for(int i=0; i<n; i++){
    for(int j=0; j<3; j++){
        for(int k=0; k<3; k++){
            if(bingo.at(i)==board.at(j).at(k)){
                board.at(j).at(k)=0;
            }
        }
    }
}
    int yoko1 = 0;
    int yoko2 = 0;
    int yoko3 = 0;
    int tate1 =0;
    int tate2 =0;
    int tate3 =0;
    int naname1 = 0;
    int naname2 = 0;
for(int i=0; i<3; i++){
    yoko1 += board.at(0).at(i);
    yoko2 += board.at(1).at(i);
    yoko3 += board.at(2).at(i);
    tate1 += board.at(i).at(0);
    tate2 += board.at(i).at(1);
    tate3 += board.at(i).at(2);
    naname1 += board.at(i).at(i);
    naname2 += board.at(i).at(2-i);
}
    if(yoko1==0 or yoko2==0 or yoko3==0 or
       tate1==0 or tate2==0 or tate3==0 or
       naname1==0 or naname2==0) ans="Yes";

cout<<ans<<endl;

}



Measured memory_bytes: 256
import itertools
N = int(input())
S = [input() for _ in range(N)]
caps = ['M', 'A', 'R', 'C', 'H']
a = [0] * 5
ans = 0
for s in S:
    if s[0] in caps:
        a[caps.index(s[0])] += 1
c = list(itertools.combinations((0, 1, 2, 3, 4), 3))
for i in range(len(c)):
    ans += a[c[i][0]] * a[c[i][1]] * a[c[i][2]]
print(ans)

Measured memory_bytes: 9776
#include <bits/stdc++.h>
#define int long long
#define dl long double
#define ff first
#define ss second
#define pb push_back
#define MAXN 20
#define inf 1000000007
#define INI 12332112
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef pair<int,int> pii;

int pre[(1<<16)+10];
int a[MAXN][MAXN];
int dp[(1<<16)+10];
int full=0;

int solve(int bitmask){
	if(dp[bitmask]!=-INI)return dp[bitmask];
	if(bitmask==full)return 0;
	
	int best=-inf;
	best=best*100LL;
	int gap = full^bitmask;
	for(int x = gap;x>0;x=(x-1)&gap){
		best = max(best,pre[x]+solve(bitmask|x));
	}
	return dp[bitmask]=best;
}


int32_t main(){
	fastio;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<n;i++){
		full+=(1<<i);
	}
	dp[0]=-INI;
	for(int x=1;x<=full;x++){
		dp[x]=-INI;
		int atual=0;
		for(int b1=0;b1<n;b1++){
			for(int b2=b1+1;b2<n;b2++){
				if(((x&(1<<b1))!=0) && ((x&(1<<b2))!=0)){
					atual+=a[b1][b2];
				}
			}
		}
		pre[x]=atual;
	}

	cout<<solve(0)<<endl;
		
}

Measured memory_bytes: 1280
#include<iostream>

using namespace std;

bool checkOddOrEven(int num){
    int counter = 0;

    for(; num > 0; counter++){
        num /= 10;
    }
    if(counter % 2 == 1){ return true; } else { return false; }
}

int getResult(int num){
    int count = 0;
    for(int i = 0; i <= num; i++){
        if(checkOddOrEven(i)){
            count++;
        }
    }
    return count;
}

int main(){
    int n;
    int count = 0;

    cin >> n;

    int result = getResult(n);

    cout << result;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

bool f[200010],l[200010];

int main(){
  int n,m;
  cin>>n>>m;
  int a,b;
  
  REP(i,m){
    cin>>a>>b;
    if(a==1 || b==1){
      f[max(a,b)]=true;
    }else if(a==n || b==n){
      l[min(a,b)]=true;
    }else{
      continue;
    }
  }
  REP(i,n){
    if(f[i] && l[i]){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}

Measured memory_bytes: 640
import math
def firstprime(n):
  p = 2
  while(p <= math.sqrt(n)):
    if(n % p == 0):
      return p
    p += 1
  return n

N = int(input())
prime = [0] * 101
for i in range(2, N+1):
  n = i
  while(n > 1):
    p = firstprime(n)
    prime[p] += 1
    n = n // p
    
p2 = 0
p4 = 0
p14 = 0
p24 = 0
p74 = 0
for i in range(101):
  if(prime[i] >= 74):
    p74 += 1
  if(prime[i] >= 24):
    p24 += 1
  if(prime[i] >= 14):
    p14 += 1
  if(prime[i] >= 4):
    p4 += 1
  if(prime[i] >= 2):
    p2 += 1
p3_5_5 = p4*(p4-1)*(p2-2)//2
p5_15 = p14*(p4-1)
p3_25 = p24*(p2-1)
p75 = p74
print(p3_5_5+p5_15+p3_25+p75)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int INF=10000007;
vector<ll>adj[INF];
vector<ll>path;
vector<ll>visited;
vector<ll>sorted;
void toposort(ll b)
{
    ll i;
    for(i=0;i<adj[b].size();i++)
    {
        if(visited[adj[b][i]]==1)continue;
        visited[adj[b][i]]=1;
        toposort(adj[b][i]);
    }
    sorted.push_back(b);
}
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n,m,i,j,x,y;
  cin>>n>>m;
  char arr[n][m];
  for(i=0;i<n;i++)
  {
      for(j=0;j<m;j++)
      {
        cin>>arr[i][j];
      }
  }
  ll h=0,mod=1000000007;
  visited.assign(n*m,0);
  path.assign(n*m,0);
  for(i=0;i<n;i++)
  {
      for(j=0;j<m;j++)
      {
            if(j==m-1 && i!=n-1)
            {
                if(arr[i+1][j]=='.' && arr[i][j]=='.')
                {
                    adj[h].push_back(h+m);
                }
                
            }
            else if(i==n-1 && j!=m-1)
            {
                if(arr[i][j+1]=='.' && arr[i][j]=='.')
                {
                    adj[h].push_back(h+1);
                }
            }
            else if(i!=n-1 && j!=m-1)
            {
                if(arr[i+1][j]=='.' && arr[i][j]=='.')
                {
                    adj[h].push_back(h+m);
                }
                if(arr[i][j+1]=='.' && arr[i][j]=='.')
                {
                    adj[h].push_back(h+1);
                }
            }
            h++;
      }
  }
  
if(visited[0]!=1)
{visited[0]=1;toposort(0);}   
  for(i=sorted.size()-1;i>=0;i--)
  {
    for(j=0;j<adj[sorted[i]].size();j++)  
    {
        if(sorted[i]!=0)
        {path[adj[sorted[i]][j]]=(((path[adj[sorted[i]][j]])%mod)+path[sorted[i]])%mod;}
        else
        {
           path[adj[sorted[i]][j]]=(((path[adj[sorted[i]][j]])%mod)+1)%mod;
        }
        
        // cout<<adj[sorted[i]][j]<<" "<< path[adj[sorted[i]][j]]<<endl;
    }
  }
    cout<<path[(n*m)-1]<<endl;


}

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

typedef long long ll;


using namespace std;

int main() {
    ll n;
    cin >> n;

    ll* A = new ll[n];

    ll* count = new ll[n + 1];
    for (ll i = 0; i < n + 1; i++) {
        count[i] = 0;
    }

    for (ll i = 0; i < n; i++) {
        cin >> A[i];
        count[A[i]]++;
    }

    ll result = 0;
    for (ll i = 0; i < n; i++) {
        if (count[i + 1]) {
            result += count[i + 1] * (count[i + 1] - 1) / 2;
        }
    }
    
    for (ll i = 0; i < n; i++) {
        cout << result - count[A[i]] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 5760
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import heapq

N, K = map(int, input().split())
P = list(map(int, input().split()))

Z = [0 for i in range(N)]
tmp = P[0]
count = 1
order = [0 for i in range(N)]
for i in range(1, N):
    if tmp < P[i]:
        count += 1
        if count >= K:
            order[i] = 1
    else:
        count = 1
    tmp = P[i]

hp = []
hm = []
heapq.heapify(hp)
heapq.heapify(hm)
used = [0 for i in range(N)]

for i in range(K):
    heapq.heappush(hp, P[i]) # 最小
    heapq.heappush(hm, -P[i]) # 最大

ans = 1
kaburi = [0 for i in range(N)]

for i in range(K, N):
    while used[hp[0]-1] == 1:
        heapq.heappop(hp)
    while used[-hm[0]-1] == 1:
        heapq.heappop(hm)

    if hp[0] == P[i-K] and -hm[0] < P[i]:
        kaburi[i] = 1
        pass
    else:
        ans += 1
    
    used[P[i-K]-1] = 1

    heapq.heappush(hp, P[i])
    heapq.heappush(hm, -P[i])

order_count = 0
for i in range(N):
    if kaburi[i] == 0 and order[i] == 1:
        order_count += 1

ans = N-K+1 - (sum(kaburi)+max(order_count-1, 0))
print(ans)

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

H, W, K = map(int, input().split())
mA = [input().rstrip() for _ in [0,]*H]

mR = []
num = 0
head = 0
for i,vA in enumerate(mA):
    if "#" not in vA:
        # header ...
        if not num:
            head += 1
        mR.append(mR[-1] if mR else [num or 1,] * W)
        continue
    vR = []
    cnt = 0
    for j,a in enumerate(vA):
        if a=="#":
            num += 1
            cnt += 1
        if cnt:
            vR.append(num)
        else:
            vR.append(num+1)
    mR.append(vR)

for k in range(head):
    mR[k] = mR[head]


for vR in mR:
    print(*vR)


Measured memory_bytes: 7568
import time
import random

def check(j,l,r):
    global point
    last=[0]*26
    sum_=0
    t=ans.copy()
    t[l],t[r]=t[r],t[l]
    for i in range(D):
        d=i+1
        sum_+=s[i][t[i]]
        for k in range(26):
            if t[i]==k:
                continue
            sum_-=c[k]*(d-last[k])
        last[t[i]]=d
    if sum_>point:
        point=sum_
        return True
    else:
        return False

start=time.time()
INF=10**30
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
last=[0]*26
ans=[]
point=0
for i in range(D):
    d=i+1
    res=-INF
    z=-1
    for j in range(26):
        p=s[i][j]
        for k in range(26):
            if k==j:
                continue
            p-=c[k]*(d-last[k])
        res=max(res,p)
        if res==p:
            z=j
    ans.append(z)
    last[z]=i+1
    point+=res

while True:
    if time.time()-start>1.80:
        break
    for i in range(D):
        if time.time()-start>1.80:
            break
        l=random.randrange(D)
        r=random.randrange(D)
        if check(i,l,r):
            ans[l],ans[r]=ans[r],ans[l]
for i in range(D):
    print(ans[i]+1)

Measured memory_bytes: 80724
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<ll,ll>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,W;cin >> n >> W;
    vi w(n), v(n);
    rep(i,n) cin >> w[i] >> v[i];

    vector<vl> dp(n+10, vl(2*W+10, 0));

    rep(i,n){
        for(int j=0;j<=W;++j){
            if(j-w[i]>=0) dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]] + v[i]);
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[n][W] << endl;
}

Measured memory_bytes: 173824
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] nums = new int[n];
    int[] dp = new int[n];
    for (int i = 0; i < n; i++) {
      nums[i] = sc.nextInt();
    }
    sc.close();
    Arrays.fill(dp, Integer.MAX_VALUE);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= k && i + j < n; j++) {
          dp[i + j] = Math.min(dp[i + j], dp[i] + Math.abs(nums[i] - nums[i + j]));
      }
    }
    System.out.println(dp[n - 1]);
  }
}

Measured memory_bytes: 60772
h, n = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
a, b = x[0]
dp = [-(-i // a) * b for i in range(h + 1)]
for j in range(1, n):
    a, b = x[j]
    for i in range(min(h + 1, a)):
        dp[i] = min(dp[i], b)
    for i in range(a, h + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
print(dp[-1])


Measured memory_bytes: 45148
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7, mod = 1e9 + 7;
typedef long long ll;
int n, m;
int f[maxn], siz[maxn];
int find(int x) {
    return f[x] == x ? x : f[x] = find(f[x]);
}
set<int> sp;
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) f[i] = i, siz[i] = 1;
    for (int i = 1, x, y; i <= m; i++) {
        scanf("%d%d", &x, &y);
        int fx = find(x), fy = find(y);
        if(fx != fy) {
            f[fy] = fx;
            siz[fx] += siz[fy];
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = find(i);
        if(!sp.count(x)) {
            ans = max(ans, siz[x]);
            sp.insert(x);
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 14568
Scanf.scanf "%d" (fun n ->
    let module S = Set.Make (struct type t = char let compare = compare end) in
    let rec loop i set =
        if i = n then S.cardinal set else
            let set = Scanf.scanf " %c" (fun c -> S.add c set) in
            loop (i + 1) set
    in
    let ans = loop 0 S.empty in
    print_endline @@ if ans = 3 then "Three" else "Four"
)

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int d[n];
    rep(i, n) cin >> d[i];
    sort(d, d + n);
    if (n % 2 == 1 || d[n / 2 - 1] == d[n / 2]) {
        cout << 0 << endl;
        return 0;
    }

    cout << d[n / 2] - d[n / 2 - 1] << endl;

    return 0;
}



Measured memory_bytes: 640
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string a, b, c;
    cin >> a >> b >> c;
    int ans = a.size() + b.size() + c.size();
    auto calc = [&ans](string& a, string& b, string& c, vector<int>& ab, vector<int>& ac, vector<int>& bc){ 
        for(int i = 0; i <= (int)a.size(); i++){
            if(ab[i]){ continue; }
            for(int j = 0; j <= (int)max(a.size(), b.size()); j++){
                if(ac[i + j] || bc[j]){ continue; }
                ans = min(ans, max({i + j + (int)c.size(), i + (int)b.size(), (int)a.size()}));
            }
        }
    };
    auto proc = [](string& a, string& b, vector<int>& ab){
        for(int i = 0; i < (int)a.size(); i++){
            for(int j = i; j < (int)a.size() && j - i < (int)b.size(); j++){
                if(a[j] != b[j - i] && a[j] != '?' && b[j - i] != '?'){
                    ab[i] = true;
                    break;
                }
            }
        }
    };
    vector<int> ab(4001), bc(4001), ca(4001);
    vector<int> ba(4001), cb(4001), ac(4001);
    proc(a, b, ab);
    proc(a, c, ac);
    proc(b, a, ba);
    proc(b, c, bc);
    proc(c, a, ca);
    proc(c, b, cb);
    calc(a, b, c, ab, ac, bc);
    calc(a, c, b, ac, ab, cb);
    calc(b, a, c, ba, bc, ac);
    calc(b, c, a, bc, ba, ca);
    calc(c, a, b, ca, cb, ab);
    calc(c, b, a, cb, ca, ba);
    cout << ans << '\n';
}


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

using namespace std;

using i64 = long long;

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

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n, m;
    cin >> n >> m;
    if(!n)
        return false;
    vector<bitset<500>> bs(n);
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        for(int j = 0; j < m; ++j)
            bs[i].set(j, s[j] == '1');
    }
    if(n < 25){
        int ans = 0;
        for(int i = 0; i < (1 << n); ++i){
            bitset<500> fl;
            for(int j = 0; j < n; ++j)
                if(i & (1 << j))
                    fl ^= bs[j];
            if(!fl.any()){
                chmax(ans, __builtin_popcount(i));
            }
        }
        cout << ans << endl;
        return true;
    }
    vector<vector<int>> dp(n + 1, vector<int>(1 << m, -MOD));
    dp[0][0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < (1 << m); ++j){
            if(dp[i][j] == -MOD)
                continue;
            chmax(dp[i + 1][j ^ bs[i].to_ulong()], dp[i][j] + 1);
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp.back().front() << endl;
    return true;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 114084
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <map>
using namespace std;
const int N=200010;
int fa[N][18],mx[N][18];
int e[N*2],nex[N*2],head[N],ed=0;
int T[N],ans[N],siz[N],dep[N];
vector<int> a[N];
map<int,int> pr[N];
int findr(int x){
	if(T[x]==-1) return x;
	else{
		int tmp=findr(T[x]);
		return T[x]=tmp;
	}
}
void adde(int x,int y){e[++ed]=y;nex[ed]=head[x];head[x]=ed;}
void dfs(int x,int f){
	fa[x][0]=f;mx[x][0]=x;
	int i;
	for(i=1;i<=17;i++){
		fa[x][i]=fa[fa[x][i-1]][i-1];
		mx[x][i]=max(mx[x][i-1],mx[fa[x][i-1]][i-1]);
	}
	for(i=head[x];i;i=nex[i])
		if(e[i]!=f) dep[e[i]]=dep[x]+1,dfs(e[i],x);
}
int getmx(int x){
	int i,tmp=1;
	for(i=17;i>=0;i--)
		if(fa[x][i]){
			tmp=max(tmp,mx[x][i]);
			x=fa[x][i];
		}
	return tmp;
}
int getf(int x,int y){
	int i;
	for(i=17;i>=0;i--)
		if(dep[fa[x][i]]>dep[y]) x=fa[x][i];
	return x;
}
int used[N];
int main(){
	int n,i,k,x,y,j,tmp;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d %d",&x,&y);
		adde(x,y);adde(y,x);
	}
	for(i=1;i<=n;i++) siz[i]=1;
	memset(T,-1,sizeof(T));
	dep[1]=1;dfs(1,0);
	for(i=2;i<=n;i++)
		a[getmx(fa[i][0])].push_back(i);
	for(i=1;i<=n;i++){
		for(j=0;j<a[i].size();j++){
			x=a[i][j];
			//if(x==2) printf("hsuda %d %d %d\n",fa[x][0],i,get2(fa[x][0],i));
			for(k=head[x];k;k=nex[k])
				if(e[k]<i){
					tmp=findr(e[k]);
					pr[x][e[k]]=siz[tmp];
					if(used[tmp]!=x){
						ans[x]+=siz[tmp];
						if(findr(x)==tmp) ans[x]--;
						used[tmp]=x;
					}
				}
			//if(x==8) printf("%d %d %d %d\n",i,ans[x],ans[getmx(fa[x][0])],pr[i][getf(x,i)]);
			ans[x]+=ans[getmx(fa[x][0])]+1-pr[i][getf(x,i)];
		}
		for(j=head[i];j;j=nex[j])
			if(e[j]<i){
				x=findr(e[j]);y=findr(i);
				if(x!=y) T[x]=y,siz[y]+=siz[x];
			}
	}
	for(i=2;i<=n;i++) printf("%d ",ans[i]);
	return 0;
}


Measured memory_bytes: 79732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1000000007;
 
int main(void){
    int N; cin >> N;
    vector<ll> div(N+5, 0);

    for(int i=2; i<=N; i++){
        int d = i;
        for(int j=2; j*j<=d; j++){
            if(d%j == 0){
                while(d%j == 0){
                    div[j]++;
                    d /= j;
                }
            }
        }
        if(d > 1) div[d]++;
    }

    ll res = 1;
    for(int i=2; i<=N; i++) res = res*(div[i]+1)%mod;
    cout << res << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
colors=[]
for i in range(n):
    for _ in range(a[i]):
        colors.append(i+1)
ans=[[0 for _ in range(w)] for _ in range(h)]
temp=0
for i in range(h):
    for j in range(w):
        if i%2!=0:
            j = w-j-1
        ans[i][j]=colors[temp]
        temp+=1

for i in range(h):
    for j in range(w):
        print(ans[i][j], end=" ")
    print()

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  typedef function<E(E,E)> H;
  typedef function<E(E,int)> P;
  int n;
  F f;
  G g;
  H h;
  P p;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T d1,E d0,
	      vector<T> v=vector<T>(),P p=[](E a,int b){return a;}):
    f(f),g(g),h(h),d1(d1),d0(d0),p(p){
    init(n_);
    if(n_==(int)v.size()) build(n_,v);
  }
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,d1);
    laz.clear();
    laz.resize(2*n-1,d0);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(int len,int k){
    if(laz[k]==d0) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=d0;
  }
  T update(int a,int b,E x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(int a,int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return d1;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(int a,int b){
    return query(a,b,0,0,n);
  }
};
//END CUT HERE
signed main(){
  int n,q;
  cin>>n>>q;
  SegmentTree<Int,Int> ch(n,
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  [](Int a,Int b){return a+b;},
			  0,0,vector<Int>(n,0),
			  [](Int a,int b){return a*b;});
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<ch.query(s-1,t)<<endl;
    }else{
      cin>>s>>t>>x;
      ch.update(s-1,t,x);
    }
  }
}

/*
verified on 2017/12/01
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G
*/

Measured memory_bytes: 8428
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using P = pair<int, int>;

bool check(const vec<int, 2>& A, const vec<int, 2>& B, int L) {
  int N = A.size(), M = A[0].size();
  vector<set<P>> top(A.size());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) top[i].insert(P(j, A[i][j]));
  }
  int rem = M;
  while (rem > 0) {
    vector<int> cnt(M, 0);
    for (int i = 0; i < N; i++) {
      auto p = *top[i].begin();
      ++cnt[p.snd];
    }
    bool cont = false;
    for (int k = 0; k < M; k++) {
      if (cnt[k] > L) {
        cont = true;
        --rem;
        for (int i = 0; i < N; i++) top[i].erase(P(B[i][k], k));
      }
    }
    if (!cont) {
      return true;
    }
  }
  return false;
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N, M;
  while (cin >> N >> M) {
    vec<int, 2> A = make_v(N, M, -1);
    vec<int, 2> B = make_v(N, M, -1);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        cin >> A[i][j];
        --A[i][j];
        B[i][A[i][j]] = j;
      }
    }
    int fail = 0, pass = N;
    while (pass - fail > 1) {
      int L = (fail + pass) / 2;
      if (check(A, B, L)) {
        pass = L;
      } else {
        fail = L;
      }
    }
    cout << pass << endl;
  }
  return 0;
}


Measured memory_bytes: 7296
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int priority;
    double value;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N,C;
    scanf("%d%d",&N,&C);

    int D[C+1][C+1];
    for(int i=1;i<=C;i++){
        for(int j=1;j<=C;j++) scanf("%d",&D[i][j]);
    }

    int map[N+1][N+1];
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++) scanf("%d",&map[i][j]);
    }

    //(i+j)%3の値ごとにそれぞれ、何色のますがいくつあるのか格納
    int R[3][C+1];
    for(int i=0;i<3;i++){
        for(int j=1;j<=C;j++) R[i][j]=0;
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++) R[(i+j)%3][map[i][j]]++;
    }

    //何色で塗ればいいか全探索
    int ans=1000000000;
    for(int a=1;a<=C;a++){
        for(int b=1;b<=C;b++){
            if(a==b) continue;
            for(int c=1;c<=C;c++){
                if(a==c || b==c) continue;
                int tmp=0;
                for(int l=1;l<=C;l++){
                    tmp+=R[0][l]*D[l][a];
                    tmp+=R[1][l]*D[l][b];
                    tmp+=R[2][l]*D[l][c];
                }
                ans=MIN(ans,tmp);
            }
        }
    }

    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define pair <int, int> P;
#define first fi
#define second se
typedef long long ll;

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

    cout << a + a * a + a * a * a << "\n";
}

Measured memory_bytes: 3588
n = int(input())
c_s_f = []
for i in range(n - 1):
    line = list(map(int, input().split()))
    c_s_f.append(line)

for i in range(n - 1):
    t = c_s_f[i][0] + c_s_f[i][1]
    for j in range(i + 1, n - 1):
        if t <= c_s_f[j][1]:
            t = c_s_f[j][1] + c_s_f[j][0]
        else:
            t = (t + c_s_f[j][2] - 1) // c_s_f[j][2] * \
                c_s_f[j][2] + c_s_f[j][0]
    print(t)
print(0)


Measured memory_bytes: 9188
# https://atcoder.jp/contests/abc052/tasks/arc067_a
# N!の約数の個数
# N, N-1, N-2 について素因数分解を個々に行い、素因数とその個数をカウントしていく
# 各素因数の出現回数について (a1+1)(a2+1)...が答え。


def factorization(n: int):
    if n == 1:
        return []  # 1は素数ではない
    # 素因数分解
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 1):  # ここにバグがないか心配
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append((i, cnt))

    if temp != 1:
        arr.append((temp, 1))

    if arr == []:
        arr.append((n, 1))

    return arr


MOD = 10**9 + 7
from collections import defaultdict
N = int(input())
factor_num = defaultdict(lambda: 0)
for n in range(1, N + 1):
    tmp = factorization(n)
    for k, v in tmp:
        factor_num[k] += v

# 約数の個数
ans = 1
for v in factor_num.values():
    ans *= (v + 1)
    if ans >= MOD:
        ans %= MOD
print(ans)


Measured memory_bytes: 41328
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

ll h;

ll f(ll x){
  if(x==1) return 1;
  return f(x/2)*2+1;
}

void solve(){
  cin >> h;
  ll ans=f(h);
  cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 256
class BinaryIndexedTree:
    def __init__(self, size):
        self.data = [0] * (size+1)
        self.size = size+1
        self.msb = 1 << (size.bit_length()-1)
    
    def _add(self, i, w):
        i += 1
        while i < self.size:
            self.data[i] += w
            i += i & -i
    
    def _get_sum(self, i):
        res = 0
        while i > 0:
            res += self.data[i]
            i -= i & -i
        return res

    def __getitem__(self, i):
        """
        [0,i)
        """
        if isinstance(i, slice):
            if i.start is None:
                return self._get_sum(i.stop)
            else:
                return self._get_sum(i.stop) - self._get_sum(i.start)
        else:
            return 0 # fake value
    
    __setitem__ = _add
    
    def bisect_left(self, v):
        """
        return smallest i s.t v <= sum[:i]
        """
        i = 0
        k = self.msb
        while k > 0:
            i += k
            if i < len(self.data) and self.data[i] < v:
                v -= self.data[i]
            else:
                i -= k
            k >>= 1
        return i
    
    def bisect_right(self, v):
        """
        return smallest i s.t v < sum[:i]
        """
        i = 0
        k = self.msb
        while k > 0:
            i += k
            if i < len(self.data) and self.data[i] <= v:
                v -= self.data[i]
            else:
                i -= k
            k >>= 1
        return i
    
    bisect = bisect_right



def solve(C, queries):
    N = len(C)
    Q = len(queries)
    bit = BinaryIndexedTree(N)

    last_ind = [None]*(N + 1)
    sorted_qi = sorted(range(Q), key=lambda i:queries[i][1])

    res = [None]*Q
    pr = 0
    temp = 0
    for qi in sorted_qi:
        l,r = queries[qi]
        for j,c in enumerate(C[pr:r],start=pr):
            c = C[j]
            if last_ind[c] is not None:
                bit._add(last_ind[c], -1)
            else:
                temp += 1
            last_ind[c] = j
            bit._add(j, 1)

        pr = r
        res[qi] = temp - bit._get_sum(l-1)

    return res

# from random import randrange, seed
# from time import perf_counter

# def test():
#     seed(1234)
#     N = 5*10**5
#     C = [randrange(N) for _ in range(N)]
#     queries = [tuple(sorted((randrange(1,N+1),randrange(1,N+1)))) for _ in range(N)]
#     start = perf_counter()
#     solve(C,queries)
#     stop = perf_counter()
#     print(stop-start)

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

if __name__ == '__main__':
    N,Q = map(int,readline().split())
    C = list(map(int,readline().split()))

    m = map(int,read().split())
    queries = list(zip(m,m))

    print(*solve(C,queries), sep='\n')
    # test()


Measured memory_bytes: 242060
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

multiset<ll> num;
priority_queue<pair<ll, ll>> task, waiting;

int main(int argc, char const *argv[]) {
  ll N, a;
  std::cin >> N;
  for(int i=0;i<(1<<N);i++) {
    std::cin >> a;
    num.insert(a);
  }
  auto itr = num.end();
  itr--;
  task.push(make_pair(*itr, N));
  //std::cout << *itr << " " << N<< '\n';
  num.erase(itr);
  while(!num.empty()){
    while(!task.empty()){
      ll now = task.top().first, c=task.top().second;
      task.pop();
      itr = num.lower_bound(now);
      if(itr==num.begin()){
        std::cout << "No" << '\n';
        return 0;
      }
      itr--;
      //std::cout << *itr << " " << c - 1 << '\n';
      if(c!=1) waiting.push(make_pair(*itr, c-1)),waiting.push(make_pair(now, c-1));
      num.erase(itr);
    }
    while(!waiting.empty()){
      task.push(make_pair(waiting.top().first, waiting.top().second));
      waiting.pop();
    }
  }
  std::cout << "Yes" << '\n';
  return 0;
}


Measured memory_bytes: 16872
# include <stdio.h>
# include <stdlib.h>
long long int min (long long int a,long long int b){
	if (a<b) return a;
	else return b;
}
int abs(int n){
	if(n<=0) return (-1*n);
	else return n;
}
int main(){
	int n,k,i,j;
	scanf ("%d %d",&n,&k);
	int *cost;
	cost=(int*)malloc(n*sizeof(int));
	for(i=0;i<n;i++) scanf ("%d",&cost[i]);
	long long int *res;
	res=(long long int*)malloc(n*sizeof(long long int));
	for(i=0;i<n;i++) res[i]=-1;
	res[0]=0;
	for(i=0;i<n;i++){
		for(j=i+1;j<min(n,i+k+1);j++){
			if(res[j]==-1) res[j]=res[i]+abs(cost[i]-cost[j]);
			else res[j]=min(res[j],res[i]+abs(cost[i]-cost[j]));
		}
	}
	printf ("%lld\n",res[n-1]);
	return 0;
}

Measured memory_bytes: 2880
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;

constexpr ll mod=1e9+7;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

int n;
vector<int> g[200200];
ll p[200200];
ll d[202020];

ll q[202020];
ll qq[202020];

void dfs(int s,int pp){
	d[s]=1;
	for(int t:g[s]){
		if(t==pp)continue;
		p[t]=s;
		dfs(t,s);
		d[s]+=d[t];
		(q[s]*=q[t])%=mod;
	}
	(q[s]*=mod_pow(d[s],mod-2))%=mod;
}

void dfs2(int s,int p){
	ll re=1;
	for(int t:g[s]){
		if(t==p)continue;
		(re*=q[t])%=mod;
	}
	for(int t:g[s]){
		if(t==p)continue;
		(qq[t]*=qq[s]*re%mod*mod_pow(q[t],mod-2)%mod*mod_pow((n-d[t]),mod-2)%mod)%=mod;
		dfs2(t,s);
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=1;i<n;i++){
		int a,b; cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i=0;i<n;i++){
		q[i]=1;
		qq[i]=1;
	}
	p[0]=-1;
	dfs(0,-1);
	dfs2(0,-1);
	ll res=1;
	for(int i=1;i<n;i++){
		(res*=i)%=mod;
	}
	for(int i=0;i<n;i++){
		ll ans=res;
		for(int t:g[i]){
			if(p[t]==i){
				(ans*=q[t])%=mod;
			}else{
				(ans*=mod_pow(n-d[i],mod-2))%=mod;
				ll re=q[t];
				(re*=d[t])%=mod;
				(re*=mod_pow(q[i],mod-2))%=mod;
				(ans*=re)%=mod;
				(ans*=qq[t])%=mod;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 20480
#include<bits/stdc++.h>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int N = 3e3 + 10 , Max = 50 + 10;
const ll  MOD = 998244353 , OO = 1e14 + 2;
int dp[N][N];
string a , b;
vector<char> sol;
int solve(int i,int j) {
    if(i == a.size() || j == b.size())
        return 0;
    int &ret = dp[i][j];
    if(ret!=-1)
        return ret;
    int c1 = solve(i + 1,j);
    int c2 = solve(i,j + 1);
    int c3 = 0;
    if(a[i] == b[j]) {
        c3 = 1 + solve(i + 1,j + 1);
    }
    return ret = max(c1,max(c2,c3));
}
void path(int i ,int j) {
     if(i == a.size() || j == b.size())
        return ;
    int optimal = solve(i,j);
    int c1 = solve(i + 1,j);
    int c2 = solve(i,j + 1);
    int c3 = 0;
    if(a[i] == b[i]) {
        c3 = 1 + solve(i + 1,j + 1);
    }
    if(optimal == c1) {
        path(i + 1,j);
    } else if(optimal == c2) {
        path(i,j + 1);
    }
    else {
        sol.pb(a[i]);
        path(i + 1,j + 1);
    }
}
int main() {
    memset(dp,-1,sizeof(dp));
    cin >> a >> b;
    path(0,0);
    for(int i =0;i < sol.size();++i) cout << sol[i] ;
    cout << endl;
}



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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	long long d,a;
	cin >> d >> a;
	
	vector<pair<long long,long long>> b(n);
	for(int i=0;i<n;i++){
		cin >> b[i].first >> b[i].second;
	}
	sort(b.begin(),b.end());
	
	
	long long res=0;
	vector<long long> imos(n+2);
	long long cur=0;
	for(int i=0;i<n;i++){
		cur+=imos[i];
		long long da=cur*a;
		if(da<b[i].second){
			long long rem=b[i].second-da;
			long long kai=(rem+a-1)/a;
			res+=kai;
			
			pair<long long,long long> key=make_pair(b[i].first+2*d,1LL<<55);
			int ind=lower_bound(b.begin(),b.end(),key)-b.begin();
			imos[ind]-=kai;
			cur+=kai;
		}
	}
	cout << res << "\n";
	return 0;
}

Measured memory_bytes: 4992
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

A=one_int()
B=one_int()

temp = set([1,2,3])

print(list(temp-set([A])-set([B]))[0])

Measured memory_bytes: 38384
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if ( T[u].left != NIL ) h1 = setHeight(T[u].left) + 1;
    if ( T[u].right != NIL ) h2 = setHeight(T[u].right) + 1;
    return H[u] = ( h1 > h2 ? h1 : h2 );
}

int getSibling( int u ) {
    if ( T[u].parent == NIL ) return NIL;
    if ( T[ T[u].parent ].left != u && T[ T[u].parent ].left != NIL) {
        return T[ T[u].parent ].left;
    }
    if ( T[ T[u].parent ].right != u && T[ T[u].parent ].right != NIL) {
        return T[ T[u].parent ].right;
    }
    return NIL;
}

void print( int u ) {
    printf("node %d: parent = %d, sibling = %d, ",u ,T[u].parent, getSibling(u));
    int deg = 0;
    if ( T[u].left != NIL ) deg ++;
    if ( T[u].right != NIL ) deg ++;
    printf("degree = %d, depth = %d, height = %d, ",deg, D[u], H[u]);

    if ( T[u].parent == NIL ) {
        printf("root\n");
    } else if ( T[u].left == NIL && T[u].right == NIL ) { 
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int main(void) {
    int i, n, v,l,r, root = 0;
    scanf("%d", &n);
//    printf("test\n");
    for (i = 0 ; i < n ; i ++ ) T[i].parent = NIL;

//   printf("test\n");
    for ( i = 0 ; i < n ; i++ ) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }

//    printf("test\n");
    for ( i = 0 ; i < n ; i++) if ( T[i].parent == NIL ) root = i;

 //   printf("test\n");
    setDepth(root , 0);
    setHeight(root);

  //  printf("test\n");
    for ( i = 0 ; i < n ; i ++ ) print(i);

    return 0;
}

Measured memory_bytes: 2720
#include <stdio.h>

int main(void) {
    char c_new, c_prev = '\0';
    int sum = 0;
    while (1) {
        scanf("%c", &c_new);
        if (c_new != 'B' && c_new!= 'W') {
            break;
        }
        if (c_new == c_prev) {
            continue;
        }
        if (c_new != c_prev) {
            ++sum;
            c_prev = c_new;
        }
    }
    printf("%d\n", sum - 1);
    return 0;
}


Measured memory_bytes: 128