akhauriyash/Code-Regression huggingface dataset:
def zero_origin(s: str):
  return int(s) - 1


class UnionFindTree:
  """Union Find Tree for disjoint-set data structure.

  Args:
    n (int): number of the vertices.
  """
  def __init__(self, n: int):
    self.parent = list(range(n))
    self.rank = [0] * n
    self.size = [1] * n

  def find(self, i: int) -> int:
    if self.parent[i] != i:
      self.parent[i] = self.find(self.parent[i])
    return self.parent[i]

  def unite(self, i: int, j: int):
    ri = self.find(i)
    rj = self.find(j)
    if ri != rj:
      if self.rank[ri] < self.rank[rj]:
        self.parent[ri] = rj
        self.size[rj] += self.size[ri]
      else:
        self.parent[rj] = ri
        self.size[ri] += self.size[rj]
        if self.rank[ri] == self.rank[rj]:
          self.rank[ri] += 1

  def is_same(self, i: int, j: int) -> bool:
    return self.find(i) == self.find(j)


n, m = map(int, input().split())
uft = UnionFindTree(n)
for _ in range(m):
  a, b = map(zero_origin, input().split())
  uft.unite(a, b)
print(max(uft.size))

Measured memory_bytes: 20080
import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner inp = new Scanner(System.in);

while (true) {
int a = inp.nextInt();
String op = inp.next();
int b = inp.nextInt();

if (op.equals("?")) break;

switch (op) {

case "+" :
System.out.println(a+b);
break;

case "-" :
System.out.println(a-b);
break;

case "*" :
System.out.println(a*b);
break;

case "/" :
if (b!=0)
System.out.println(a/b);
break;

}
}
}
}


Measured memory_bytes: 26340
#include <stdio.h>

int main(){
  int n, s, f, t, i, sum;
  while(scanf("%d", &t) && t){
    sum = 0;
    scanf("%d", &n);
    while(n--){
      scanf("%d%d", &s, &f);
      sum += f - s;
    }
    t -= sum;
    printf(t <= 0 ? "OK\n" : "%d\n", t);
  }
  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a < b)
     printf("a < b\n");
    else if(a > b)
     printf("a > b\n");
    else if(a == b)
     printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int N,M; ll ans;
  std::cin >> N >> M;
  if(N == 1 && M == 1)
    ans = 1;
  else if(N == 1 || M == 1)
    ans = std::max(N,M) - 2;
  else
    ans = (ll)(N-2)*(M-2);
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int X,t; cin >>X >>t;
  int ans=X-t;
  if (ans<0) ans=0;
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
#define N 31000000
// #define M 19
 
// #define mod  11092019
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 2000000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}

inline ll mul(ll a, ll b, ll mod) { return (long long) a*b%mod;}
inline ll add(ll a, ll b, ll mod) { return a+b < mod? a+b: a+b-mod;}
inline void Mul(ll &a, ll b, ll mod) { a = (long long) a*b%mod;}
inline ll bp(ll a, ll p, ll mod){
	ll ret;
	for(ret = 1; p; p>>=1, Mul(a, a, mod)) (p & 1) && (Mul(ret, a, mod), 1);
	return ret;
}

static inline ll get_num() {
    ll num = 0;
    char c = getchar_unlocked();
    while(!((c>='0') & (c<='9')))  c=getchar_unlocked();
    while(c>='0' && c<='9'){
        num = (num<<1)+(num<<3)+c-'0';
        c=getchar_unlocked();
    }
    return num;
}

static inline void read(ll &x) { x = get_num();}

int main(){
	ll l, r, d; read(l), read(r), read(d);
	ll times = 0;
	FER(i, l, r+1){
		if(i%d == 0) times++;
	}
	cout<<times<<"\n";
	
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define pb push_back
#define N 1000003
#define SZ(a) (int)(a.size())
#define sorta(a) sort(a.begin(),a.end()) 
#define sortrev(a) sort(a.rbegin(),a.rend())
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define VI vector<int>
typedef long long LL;
using namespace std;
LL powmod(LL a, LL p, LL mod)
{
	LL ret = 1;while(p){if(p&1)ret = (ret*a)%mod;a=(a*a)%mod;p/=2;}return ret;
}
int pow(int a, int p)
{
	int ret = 1;while(p){if(p&1)ret = (ret*a);a=(a*a);p/=2;}return ret;
}
int n,x,t,y,a,b,i,j,k,p1[N],p2[N];
int main()
{
	cin.sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	if(t/10==9 || (t+1)%10==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

	 return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define mod 1000000007


struct ast{
    ll a1,b1,c1;
};


ll power(ll a,ll b)
{
    ll r=1;
    while(b!=0)
    {
        if(b%2!=0){r=r*a;}
        a=a*a; b=b/2;
    }
    return r;
}


int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n,a,b,c; cin>>n;
        struct ast anj[n+1];
        ll dp[n+1][3]; memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++){
            cin>>a>>b>>c;
            anj[i].a1=a; anj[i].b1=b; anj[i].c1=c;
        }
        dp[n][0]=anj[n].a1; dp[n][1]=anj[n].b1; dp[n][2]=anj[n].c1;
        for(int i=n-1;i>=1;i--){
            dp[i][0]= anj[i].a1+max(dp[i+1][1],dp[i+1][2]);
            dp[i][1]= anj[i].b1+max(dp[i+1][0],dp[i+1][2]);
            dp[i][2]= anj[i].c1+max(dp[i+1][1],dp[i+1][0]);
        }

        ll ans = max(dp[1][0],dp[1][1]);
        ans=max(ans,dp[1][2]); cout<<ans<<endl;
    }
}


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

int ctoi(const char c){
    if('0'<=c && c<='9') return (c-'0');
    else return -1;
}

int main(){
    string s;
    long long int k;
    cin>>s>>k;
    int ans=1;
    int count=0;
    rep(i,s.size()){
        if(s[i]!='1'){
            ans=ctoi(s[i]);
            break;
        }
        else count+=1;
    }
    if(count<k)cout<<ans<<endl;
    else cout<<1<<endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y-1);(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,pii> piii;
typedef pair<ll,ll> pll;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

ll d[512][512],INF=5e15,d2[512][512], dx[]={1,0,-1,0},dy[]={0,1,0,-1},dd[512][512];

main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  //  cout<<sizeof(ll)<<endl;
  int i,j,k,n,m,sx,sy,gx,gy;
  cin>>m>>n;
  vector<string> mp(n);
  rep(i,n)
    cin>>mp[i];
  fill(d[0],d[511]+512,INF);
  fill(d2[0],d2[511]+512,INF);
  queue<pii> que,que2;
  rep(i,n)rep(j,m){
    if(mp[i][j]=='s'){
      sx=j;
      sy=i;
    }else if(mp[i][j]=='g'){
      gx=j;
      gy=i;
      que.push(pii(j,i));
      d[i][j]=0;
    }else if(mp[i][j]=='*'){
      que2.push(pii(j,i));
      d2[i][j]=0;
    }
  }
  while(!que.empty()){
    pii p=que.front();que.pop();
    rep(i,4){
      int x=p.X+dx[i],y=p.Y+dy[i];
      if(mp[y][x]!='#' && mp[y][x]!='*' && d[y][x]>d[p.Y][p.X]+1){
	d[y][x]=d[p.Y][p.X]+1;
	que.push(pii(x,y));
      }
    }
  }
  while(!que2.empty()){
    pii p=que2.front();que2.pop();
    rep(i,4){
      int x=p.X+dx[i],y=p.Y+dy[i];
      if(mp[y][x]!='#' && d2[y][x]>d2[p.Y][p.X]+1){
	d2[y][x]=d2[p.Y][p.X]+1;
	que2.push(pii(x,y));
      }
    }
  }
  //  rep(i,n){rep(j,m)cout<<d[i][j]<<",";cout<<endl;}cout<<endl;
  //  rep(i,n){rep(j,m)cout<<d2[i][j]<<",";cout<<endl;}
  priority_queue<piii> q;
  ll a=0,b=0,nn=0;
  rep(i,n)rep(j,m){
    if(mp[i][j]!='#' && mp[i][j]!='*' && mp[i][j]!='g'){
      q.push(piii(d[i][j]-d2[i][j],pii(j,i)));
      b+=d[i][j];
      nn++;
    }
  }
  //    cout<<b<<","<<nn<<":"<<1.*b/(nn-a)<<endl;
  //cout<<d[sy][sx]*(1-dd[sy][sx])+(d2[sy][sx]+1.*b/(nn-a))*dd[sy][sx]<<endl;
  while(!q.empty()){
    piii tmp=q.top();q.pop();
    if(nn-a==1)break;
    if(tmp.X<1.*(b)/(nn-a))
      break;
    //cout<<tmp.Y<<tmp.X+d2[tmp.Y.Y][tmp.Y.X]<<"->";
    pii p=tmp.Y;
    b-=tmp.X;
    ++a;
    dd[p.Y][p.X]=1;
    //    cout<<1.*b/(nn-1)+d2[tmp.Y.Y][tmp.Y.X]<<endl;
    //cout<<a<<","<<b<<endl;
  }
  cout<<d[sy][sx]*(1-dd[sy][sx])+(d2[sy][sx]+1.*b/(nn-a))*dd[sy][sx]<<endl;
  return 0;
}

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

int main(){

    set<long long> s;
    vector<long long> cycle_order;
    long long N; cin >> N;
    long long X, M; cin >> X >> M;

    //cycleを見つける
    bool is_cycle = false;
    long long current_num = X;
    long long cycle_start_num = -1;

    //あと何回行動できるか
    long long rest = N;
    long long ans = 0;

    for(long long i=0; i<N; ++i){
        //ゼロなら以降ずっとゼロなのでブレイク
        if(current_num == 0){
            break;
        }
        //サイクルしたらブレイク
        if(s.count(current_num) > 0){
            is_cycle = true;
            cycle_start_num = current_num;
            break;
        }
        s.insert(current_num);
        cycle_order.push_back(current_num);
        //次の値
        current_num = current_num * current_num;
        current_num %= M;
    }


    //サイクルがない場合、またはゼロが来た場合10
    if(is_cycle == false){
        for(long long i=0; i<cycle_order.size(); ++i){
            ans += cycle_order[i];
        }
    }else{
        //サイクルの場所を復元する
        vector<long long> cycle;
        bool start = false;
        for(long long i=0; i<cycle_order.size(); ++i){
            if(start == false){
                if( cycle_order[i] != cycle_start_num ){
                    ans += cycle_order[i];
                    rest--;
                    continue;
                } 
                cycle.push_back(cycle_start_num);
                start = true;
            }else{

                if(cycle_order[i] == cycle_start_num){
                    break;
                }else{
                    cycle.push_back(cycle_order[i]);
                }
            }
        }

        //サイクルの長さ
        long long cycle_size= cycle.size();
        //何回サイクルできるか
        long long repeat = rest/cycle_size;
        //サイクルの和
        long long cycle_sum = 0;
        for(int s=0; s<cycle_size; ++s){
            cycle_sum += cycle[s];
        }
        //答えに加える
        ans += (cycle_sum * repeat);

        //サイクル後の残り回数
        rest %= cycle_size;

        int idx = 0;
        while(rest){
            ans += cycle[idx];
            idx++;
            rest--;
        }
    }

    cout << ans << endl;

}

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

using namespace std;

string str;

string dfs(int now, int score, string info) {
	if (now == 4) {
		if (score == 7) return info + "=7";
		else return "";
	}
	if (now == 0) {
		return dfs(now + 1, str[now] - '0', string(1, str[now]));
	}
	string res = dfs(now + 1, score + str[now] - '0', info + "+" + str[now]);
	if (res != "") return res;
	return dfs(now + 1, score - (str[now] - '0'), info + "-" + str[now]);
}

void hawawa()
{
	cin >> str;
	cout << dfs(0, 0, "") << "\n";
}

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


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a + b == c) {
		printf("Yes\n");
	}
	else if (a == b + c) {
		printf("Yes\n");
	}
	else if (a+c==b) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
}

Measured memory_bytes: 128
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
for i in range(n,1000):
    s = str(i)
    if s[0] == s[1] == s[2]:
        print(i)
        exit()


Measured memory_bytes: 10460
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<bitset>
#define ll long long
#define N 300003
#define reg register
#define inf 0x3f3f3f3f
#define p 1000000007
#define mid ((l+r)>>1)
#define ls (u<<1)
#define rs (u<<1|1)
using namespace std;

struct node{
    int id,rk;
    node(int id=0,int rk=0):id(id),rk(rk){}
    bool operator < (const node& nd) const{
        return rk < nd.rk;
    }
};

int n,m;
node a[N];

inline void read(int &x);
void print(int x);

signed main(){
    int t;
    read(n),read(m);
    for(int i=1;i<=n;++i) a[i] = node(i,i);
    for(int i=1;i<=m;++i){
        read(t);
        a[t].rk = 1-i;
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;++i){
        print(a[i].id);
        putchar('\n');
    }
    return 0;
}

inline void read(int &x){
    x = 0;
    char c = getchar();
    while(c<'0'||c>'9') c = getchar();
    while(c>='0'&&c<='9'){
        x = (x<<3)+(x<<1)+(c^48);
        c = getchar();
    }
}

void print(int x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}


Measured memory_bytes: 5440
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    print(-n % 1000)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 76652
import sys
def inputt():
    return sys.stdin.readline().strip()
def printt(n):
    sys.stdout.write(str(n)+'\n')
def listt():
    return [int(i) for i in inputt().split()]
D,T,S=map(int,input().split())
if (D/S)<=T:
    printt("Yes")
else:
    printt("No")

Measured memory_bytes: 9176
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let bs = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun b -> b)) in
  List.fold_left2 (fun (as_, bs) a b ->
    if a <= b then (as_, bs + (b - a) / 2)
    else (as_ + a - b, bs)) (0, 0) as_ bs
  |> (fun (as_, bs) -> as_ <= bs)
  |> (function true -> "Yes" | false -> "No")
  |> print_endline


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

#define ALL(a) (a).begin(), (a).end()
#define ll long long
#define INF (long long)1e15

using namespace std;

const ll Mval = 10001;


signed main(){
	ll N, W; cin >> N >> W;
	vector<ll> v(N), w(N);
	vector<ll> now(Mval, INF), prev(Mval, INF);

	for(int i = 0; i < N; i++){
		cin >> v[i] >> w[i];
	}
	prev[0] = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < Mval; j++){
			now[j] = min(prev[j], j-v[i] >= 0 && prev[j-v[i]] != INF ? prev[j-v[i]]+w[i] : INF);
		}
		swap(now, prev);
	}
	int idx = 0;
	for(int i = Mval-1; i >= 0; i--){
		if(prev[i] <= W){
			idx = i;
			break;
		}
	}
	cout << idx << endl;

	return 0;
}




Measured memory_bytes: 3200
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def factorization(n):
    factors = []

    if n < 2:
        return n

    while n % 2 == 0:
        factors.append(2)
        n //= 2

    for i in range(3, int(n ** 0.5) + 5, 2):
        while n % i == 0:
            factors.append(i)
            n //= i

    if n != 1:
        factors.append(n)

    return factors


def main():
    from collections import Counter

    n, m = list(map(int, readline().split()))

    if m == 1:
        print(1)
        sys.exit()

    factors = Counter(factorization(m))

    ans = 1

    for cnt in factors.values():
        for i in range(1, cnt + 1):
            ans *= (n + cnt - i)
            ans %= MOD
            ans *= pow(i, MOD - 2, MOD)
            ans %= MOD

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n,k;
  cin >> n>>k;
  vector<int> p(n);
  rep(i,n){
    cin >> p.at(i);
  }
  int sum=0;
  sort(p.begin(),p.end());
  rep(i,k){
    sum+=p.at(i);
  }
  cout << sum;
}

Measured memory_bytes: 3624
N = int(input().strip())
#P = map(int, input().strip().split())
#Q = map(int, input().strip().split())
P = int(input().strip().replace(" ", ""))
Q = int(input().strip().replace(" ", ""))

import itertools

seq = [str(i) for i in range(1,N+1)]
alllist = sorted([int("".join(l)) for l in list(itertools.permutations(seq))])
print(abs(alllist.index(P)-alllist.index(Q)))

Measured memory_bytes: 9588
#include<bits/stdc++.h>
#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b
#define rep(i,n) for(int (i)=0;(i)<n;(i)++)
#define read(n) scanf("%d",&n);
#define readll(n) scanf("%lld",&n);
#define readdb(n) scanf("%lf",&n);
#define readch(n) scanf("%c",&n);
#define readstr(n) scanf("%s",n);
#define test printf("test\n");
#define init(n) memset(n,0,sizeof(n));

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
typedef struct p1{
	int first,second;	
}p; 
bool cmp (p a , p b){
	return a.first>b.first;
}
int main(){
	int n;
	read(n);
	int c[100005];
	for(int i = 0 ; i < n ; i ++){
		read(c[i]);
	}
	int t1[100005];
	int t2[100005];
	init(t1);
	init(t2);
	int mmax = 0;
	int now = 0;
	for(int i = 0 ; i < n ; i +=2){
		t1[c[i]] ++;
	}
	for(int i = 1 ; i < n ; i += 2){
		t2[c[i]] ++;
	}
	vector<p> a ,b;
	for(int i = 0 ; i < 100005 ; i ++){
		if(t1[i] != 0){
			p x;
			x.first = t1[i];
			x.second = i;
			a.push_back(x);
		}
		if(t2[i] != 0){
			p x;
			x.first = t2[i];
			x.second = i;
			b.push_back(x);
		}
	}
	sort(a.begin(),a.end(),cmp);
	sort(b.begin(),b.end(),cmp);
	int ans = 0;
	if(a[0].second == b[0].second){
		ans += n - max(a[0].first+b[1].first,a[1].first+b[0].first);
	}else{
		ans += n - a[0].first - b[0].first;
	}
	printf("%d",ans);
	
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 return 0; 
}












Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,rd[N],a[N],f[N];
vector<int> g[N];
queue<int> q;
inline bool cmp(int x,int y){return f[x]<f[y];}
int main(){
	scanf("%d",&n);
	for (int i=2;i<=n;++i){
		scanf("%d",a+i);
		g[a[i]].push_back(i);
		++rd[a[i]];
	}
	for (int i=1;i<=n;++i) if (!rd[i]) q.push(i);
	while (!q.empty()){
		int u=q.front();q.pop();
		sort(g[u].begin(),g[u].end(),cmp);
		for (vector<int>::iterator it=g[u].begin();it!=g[u].end();++it) f[u]=max(f[u],f[*it])+1;
		if (--rd[a[u]]==0) q.push(a[u]);
	}
	printf("%d",f[1]);
	return 0;
}

Measured memory_bytes: 6912
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.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;
}

ll solve(const int pos, vector<int> &acc, const vector<ll> &cnts) {
    if (acc.size() == 3) {
        // printf("%d, %d, %d\n", acc[0], acc[1], acc[2]);
        return cnts[acc[0]] * cnts[acc[1]] * cnts[acc[2]];
    }

    if (pos >= 5) {
        return 0LL;
    }

    ll sum = 0LL;

    for (int i = pos; i < 5; i++) {
        acc.push_back(i);
        sum += solve(i + 1, acc, cnts);
        acc.pop_back();
    }

    return sum;
}

int main(void) {
    int N;
    cin >> N;

    ll cnt_m = 0;
    ll cnt_a = 0;
    ll cnt_r = 0;
    ll cnt_c = 0;
    ll cnt_h = 0;

    for (int i = 0; i < N; i++) {
        string name;
        cin >> name;
        switch (name[0]) {
            case 'M':
                cnt_m++;
                break;
            case 'A':
                cnt_a++;
                break;
            case 'R':
                cnt_r++;
                break;
            case 'C':
                cnt_c++;
                break;
            case 'H':
                cnt_h++;
                break;
            default:
                break;
        }
    }

    vector<ll> cnts = {cnt_m, cnt_a, cnt_r, cnt_c, cnt_h};
    vector<int> acc;
    cout << solve(0, acc, cnts) << endl;

    return 0;
}


Measured memory_bytes: 3628
#pragma optimize("", off)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define all(v) v.begin(),v.end()
#define pb push_back
#define sz(i) (int)(i.size())
#define setto(n) cout << fixed << setprecision(n)
#define fi first
#define se second
#define ld long double
#define inf LONG_MAX
#define pii pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int mod = 1000000007;
using namespace std;

#ifndef ONLINE_JUDGE
#define tr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}
template<class T> void smax(T& a, T val) {if (a < val) a = val;}
template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
//Check N size twiceeeeeeeeeeeeeeeeee, and verify it

#define int ll
const int N = 1e5 + 10;

int n, m;
string s, t;

int lcm(int a, int b){
	return (a/__gcd(a, b))*b;
}

int32_t main(){_

	cin>>n>>m;
	cin>>s;
	cin>>t;

	int length = lcm(n, m);

	int low = length, high = 1e15, ans = -1;

	std::unordered_map<int, char> tmp;
	while(low <= high){
		int mid = (low + high) >> 1;

		int i = ((mid)/length)*length;
		tmp.clear();

		for (int j = 0; j < n; ++j)
		{
			tmp[(j*(i/n)) + 1] = s[j];
		}
		int f = 0;
		for (int j = 0; j < m; ++j)
		{
			int place = (j*(i/m)) + 1;
			if(tmp.count(place) == 0){
				tmp[place] = t[j];
			}
			else{
				if(tmp[place] != t[j]){
					f = 1;
					break;
				}
			}
		}
		if(f == 0){
			ans = i;
			high = mid - 1;
		}
		else{
			low = mid + 1;
		}
	}

	cout<<ans;
	return 0;
}

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

using namespace std;

int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
constexpr const int INF=1<<30,MOD=1000000007;constexpr const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
#ifndef LOCAL
struct osd{template<class T>osd&operator<(const T&t){return*this;}template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;template<class...T>void _print(osd&a,T&&...t){}
#define cerr cer_
#endif
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}template<class T>istream&operator>(istream&i,T&t){return i>>t;}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<t<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}template<class...T>void dprint(T&&...t){_print(cerr,t...);}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<p.F<' '<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>p.F>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>queue<T>&operator<<(queue<T>&q,const T&t){q.push(t);return q;}template<class T>queue<T>&operator<<(T&t,queue<T>&q){t=q.front();q.pop();return q;}
template<class T>deque<T>&operator>>(const T&t,deque<T>&q){q.push_front(t);return q;}template<class T>deque<T>&operator<<(T&t,deque<T>&q){t=q.front();q.pop_front();return q;}
template<class T>deque<T>&operator<<(deque<T>&q,const T&t){q.push_back(t);return q;}template<class T>deque<T>&operator>>(deque<T>&q,T&t){t=q.back(t);q.pop_back();return q;}
template<class T>stack<T>&operator<<(stack<T>&s,const T&t){s.push(t);return s;}template<class T>stack<T>&operator>>(stack<T>&s,T&t){t=s.top();s.pop();return s;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>n;
    vi d(n);
    cin>d;
    sort(all(d));
    cout<(d[n/2]-d[n/2-1])<endl;
    return 0;
}


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

int main(){
    int n;cin>>n;
    vector<int> problems(n);for(int i=0;i<n;i++){cin>>problems[i];}

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

    int l_last = problems[n / 2 - 1];
    int r_first = problems[n / 2];
    cout << r_first - l_last << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
int m, k;
int main(){
    scanf("%d%d", &m, &k);
    if((1<<m) <= k || m == 1) return puts(k ? "-1" : "0 0 1 1")*0;
    for(int i = 0; i < (1<<m); i++) if(i != k) printf("%d ", i);
    printf("%d ", k);
    for(int i = (1<<m)-1; i >= 0; i--) if(i != k) printf("%d ", i);
    printf("%d\n", k);
}


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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for (int i=(a); i<(n); i++)

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

    map<string, int> count;
    rep(i, N) {
        string s;
        cin >> s;
        count[s] += 1;
    }
    
    cout << "AC x " << count["AC"] << endl;
    cout << "WA x " << count["WA"] << endl;
    cout << "TLE x " << count["TLE"] << endl;
    cout << "RE x " << count["RE"] << endl;
}


Measured memory_bytes: 3636
a = list(map(int,input().split()))
a.sort()
b = a[2] - a[1]
c = a[2] - a[0]
ans = 0
 
ans += b
 
if (c-b) % 2 == 0:
    ans += (c-b)//2
elif (c-b) % 2 == 1:
    ans += (c-b)//2 + 2
 
print(ans)

Measured memory_bytes: 3064
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap};
use std::io::{Write, BufWriter, stdout};
fn main() {
    input! {
        N: usize,
        C: usize,
        tv_pro: [(usize, usize, usize1); N],
    }
    tv_pro.sort_by_key(|p| p.0);
    let mut recorders: Vec<(usize, usize)> = Vec::new();
    let mut new_flag;
    for &(start, end, channel) in tv_pro.iter() {
        new_flag = true;
        for mut r in recorders.iter_mut() {
            if r.0 < start {
                r.0 = end;
                r.1 = channel;
                new_flag = false;
                break;
            } else if r.0 == start && r.1 == channel {
                r.0 = end;
                new_flag = false;
                break;
            }
        }
        if new_flag {
            recorders.push((end, channel));
        }
    }
    println!("{}", recorders.len());
}


Measured memory_bytes: 8444
import math
 
X = int(input())
if X <= 3:
    ans = 1
else:
    b=2
    ans = 4 # 2^2
    while(b <= math.sqrt(X)):
        p=2
        while(b ** p <= X):
            if b ** p > ans:
                ans = b ** p
            p += 1
        b += 1
print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 105;

int N;
int mn, mx;
int cnt[MAXN];

void load() {
	scanf("%d", &N);
	mn = N;
	while (N--) {
		int dist;
		scanf("%d", &dist);
		mn = min(mn, dist);
		mx = max(mx, dist);
		cnt[dist]++;
	}
}

bool solve() {
	if (cnt[mn] > 2) return false;
	if (mx != 2 * mn - cnt[mn] + 1) return false;
	for (int i = mx; i > mn; i--)
		if (cnt[i] < 2) return false;
	return true;
}

int main() {
	load();
	puts(solve() ? "Possible" : "Impossible");
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

int main() {
    int n, k;
    ll r = 0;
    cin >> n >> k;
    vector<int> h(n);

    rep(i, n) { cin >> h[i]; }
    sort(h.begin(), h.end(), std::greater<int>());

    if (n <= k) {
        r = 0;
    } else {
        for (int i = k; i < n; i++) {
            r += h[i];
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 1024
// Problem : 
// 			A - Connection and Disconnection
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Grand Contest 039
// URL : https://atcoder.jp/contests/agc039/tasks/agc039_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int t=1;
	while(t--)
	{
		string s;
 		ll k;
 		cin >> s >> k;
 		ll cnt = 1;
 		int n = sz(s);
 	 l00p(i,0,n-1) {
    if(s[i]==s[i+1])
      ++cnt;
    else
      break;
  }
  if(cnt==n) {
    cout<<cnt*k/2;
    return 0;
  }
 
  ll ans=0;
  l00p(i,0,n-1) {
    if(s[i]==s[i+1]){
      ans++;
      s[i+1]='.';
    }
  }
  ans*=k;
  if(s[0]==s[n-1] && cnt%2==1) ans+=k-1;
  cout<<ans;
  return 0;
	}
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

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

typedef long long ll;

int main(){
    ll n,i,j,k,l,r;
    string s;
    cin>>s;
    k=0;
    if(s[2]==s[3])
    k++;
    if(s[4]==s[5])
    k++;
    if(k==2)
    cout<<"Yes";
    else
    cout<<"No";
    
    
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N),B(N);
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> B[i];
    
    vec<unordered_map<int,int>> valid(30);
    auto prekmp = [&](string x,vector<int>& kmpnext){
        int m = x.size();
        int i = 0,j = kmpnext[0] = -1;
        while(i<m){
            while(j>-1 && x[i]!=x[j]) j = kmpnext[j];
            i++; j++;
            if(x[i]==x[j]) kmpnext[i] = kmpnext[j];
            else kmpnext[i] = j;
        }
    };
    auto KMP = [&](string x,string y,int bit,bool swapped){
        int m = x.size(),n = y.size();
        vector<int> kmpnext(m+1);
        int i = 0,j = 0;
        prekmp(x,kmpnext);
        while(j<n-1){
            while(i>-1 && x[i]!=y[j]) i = kmpnext[i];
            i++; j++;
            if(i>=m){
                valid[bit][j-m] = swapped;
                i = kmpnext[i];
            }
        }
    };


    auto check = [&](int bit){
        string S = "",T = "";
        for(int i=0;i<N;i++){
            char c;
            if(A[i]&(1<<bit)) S += '1';
            else S += '0';
            if(B[i]&(1<<bit)) T += '1';
            else T += '0';
        }
        S += S;
        KMP(T,S,bit,0);
        for(int i=0;i<2*N;i++) S[i] = (S[i]=='0'? '1':'0');
        KMP(T,S,bit,1);
    };

    for(int i=0;i<30;i++) check(i);
    vec<P<int,int>> ans;
    for(auto& x:valid[0]){
        bool ok = true;
        int res = (x.second? 1:0);
        for(int i=1;i<30;i++){
            if(!valid[i].count(x.first)){
                ok = false;
                break;
            }else if(valid[i][x.first]){
                res ^= (1<<i);
            }
        }
        if(ok) ans.push_back({x.first,res});
    }
    sort(ans.begin(),ans.end());
    for(auto& x:ans) cout << x.first << " " << x.second << endl;
}

Measured memory_bytes: 256316
N, K = map(int, input().split())
lst = list(map(int, input().split()))
ans = 10 ** 10
for i in range(N-K+1):
	left = lst[i]
	right = lst[i+K-1]
	if (abs(left) > abs(right)):
		dis = abs(left - right) + abs(right)
	else:
		dis = abs(left - right) + abs(left)
	if (dis < ans):
		ans = dis    
print(ans)


Measured memory_bytes: 14392
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<numeric>
#include<stdio.h>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

#define INF 999999999
#define MOD 1000000007

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

/*const int M = 10000;

class Matrix{
	public:
	int n;//行
	int m;//列
	vector<int> data;
	Matrix(int a, int b, const vector<int> &v){
		n = a;
		m = b;
		data.resize(n*m);
		for(int i = 0; i < n*m; i++){
			data[i] = v[i];
		}
	}

	int show(){
		cout << this->n << "x" << this->m << "Matrix\n"; 
		for(int i = 0; i < this->n; i++){
			for(int j = 0; j < this->m; j++){
				cout << data[i * this->m + j];
				if(j == this->m-1) cout << "\n";
				else cout << " ";
			}
		}
		return 0;
	}
	Matrix operator * (Matrix obj){
		vector<int> rt;
		int a=0;
		for(int i = 0; i < this->n; i++){
			for(int j = 0; j < obj.m; j++){

				for(int k = 0; k < this->m; k++){
					//a += this->data[i * this->m + k] * obj.data[k * obj.m + j];
					a = (a%M + ((this->data[i * this->m + k]%M)*(obj.data[k * obj.m + j]%M))%M)%M;
				}
				rt.push_back(a);
				a = 0;

			}
		}
		Matrix RT(this->n, obj.m, rt);
		return RT;
	}

	Matrix expt(long long int p){
		if(p == 0){
			vector<int> v{1, 0, 0, 1};
			Matrix RT(2, 2, v);
			return RT;
		}else if(p == 1) return *this;
		else if(p%2 == 1){
			Matrix T = this->expt(p-1);
			return *this * T;
		}else{
			Matrix T = this->expt(p/2);
			return T*T;
		}
	}
};*/


int n, q;

class UF{
	vector<int> oya;

	public:
	UF(int s){
		oya.resize(s);
		for(int i = 0; i < s; i++) oya[i] = i;
	}

	int root(int x){
		vector<int> path;
		while(oya[x] != x){
			path.push_back(x);
			x = oya[x];
		}
		for(int i = 0; i < path.size(); i++){
			oya[ path[i] ] = x;
		}
		return x;
	}

	void unite(int x, int y){
		//x <= s, y <= s が保証されているものとする
		int ox = root(x), oy = root(y);
		oya[oy] = ox;
	}

	bool same(int x, int y){
		root(x);root(y);
		return (oya[x] == oya[y]);
	}
};

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

	cin >> n >> q;
	UF uf(n);
	for(int i = 0; i < q; i++){
		int com, x, y;
		cin >> com >> x >> y;
		if(com == 0){
			uf.unite(x, y);
		}else if(com == 1){
			if(uf.same(x, y)){
				cout << 1 << "\n";
			}else{
				cout << 0 << "\n";
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3264
/*
?????§??§ 1000000 ??????????????§ 10000 ?????\?????????????????§?????????????????¨????¶??????????????????´?????????????????????1010 ????¨???????????????¨?????§?????????????????????????????????????????? 

int ??§????¶???????????????§???long long (??\?????¬??¬)????????¨??????
??¬??¬????????¬???????????????????????°?¢??????\??£????????????64bit????????§900????????§????????????
http://oshiete.goo.ne.jp/qa/56545.html
http://okwave.jp/qa/q2099363.html

printf?????????%lld??????????????§??¨???
*/

#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	int a[10000];
	int n;
	int max=-1000000,min=1000000;
	long long sum=0;
	
	cin >> n;
	if(n==0){
		printf("%d %d %d\n", 0, 0, 0);
		return 0;
	}
	
	for(int i=0; i<n; i++){
		cin >> a[i];

		sum+=a[i];
		if(max<a[i]) max = a[i];
		if(min>a[i]) min = a[i];
	}
	
	printf("%d %d %lld\n", min, max, sum);
		

	return 0;
}

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

using namespace std;

typedef long long LL;

const int N = 1e6 + 5;
const int mod = 1e9 + 7;

int n;
int dp[N][3][3];
char s[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
     T f = 1; x = 0;
     char c = getchar();
     for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
     x *= f;
}

inline void inc(int &x , int y) {
    x = x + y < mod ? x + y : x + y - mod;
}
int main() {
    
    scanf("%s" , s + 1); n = strlen(s + 1);
    dp[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
       	for (int j = 0; j < 3; ++j) {
       		for (int k = 0; k < 3; ++k) {
       		    if (s[i + 1] != '0') {
       		        if (k)
       		        	inc(dp[i + 1][j][k - 1] , dp[i][j][k]);
       		        else
       		        	inc(dp[i + 1][min(j + 1 , 2)][k] , dp[i][j][k]);
       		    }
       		    if (s[i + 1] != '1') {
       		    	if (k == 2)
       		    		inc(dp[i + 1][j][1] , dp[i][j][k]);
       		    	else 
       		    		inc(dp[i + 1][j][k + 1] , dp[i][j][k]);
       		    }
       		}
       	}
    }
    int ans = 0;
    for (int i = 0; i < 3; ++i)
    for (int j = 0; j <= i; ++j)
    	inc(ans , dp[n][i][j]);
    printf("%d\n" , ans);
    return 0;
}

Measured memory_bytes: 14608
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define ss(x) (int) x.size()
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl;
#define ios cin.tie(0); ios_base::sync_with_stdio(0)
 
using namespace std;
using namespace __gnu_pbds;
 
// order_of_key
// find_by_order
// tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ja;
const int nax = 2e5 + 111;
const ll INF = 1e18;

int n, x[nax], a, b, c;
vector <pair<int, int>> v[nax];
int p[nax];

int Find(int x) {
	if(x == p[x])
		return x;
	return p[x] = Find(p[x]);
}

int Com;
ll ans = 0;

void Onion(int x, int y, ll val) {
	x = Find(x);
	y = Find(y);
	if(x == y)
		return;
	//cout << x << " " << y << " " << val << endl;
	ans += val;
	Com -= 1;
	p[x] = y;
}

vector <pair<ll, int>> dp[nax][2], best[nax];
vector <pair<ll, pair<int, int>>> Merge;

void init() {
	Merge.clear();
	FOR(i, 0, n) {
		best[i].clear();
		dp[i][0].clear();
		dp[i][1].clear();
		FOR(j, 0, 1)
			FOR(g, 0, 1)
				dp[i][j].pb(mp(INF, -1));
	}
}
		
void reduce(vector <pair<ll, int>> &x, pair<ll, int> k) {
	if(x[0].se == k.se) {
		if(k.fi < x[0].fi)
			x[0] = k;
	}
	else if(x[1].se == k.se) {
		if(k.fi < x[1].fi)
			x[1] = k;
	}
	else if(k.fi < x[1].fi)
		x[1] = k;
	if(x[1].fi < x[0].fi)
		swap(x[0], x[1]);
}

void dfs1(int u, int p) {
	for(auto it: v[u]) {
		if(it.fi != p) {
			dfs1(it.fi, u);
			reduce(dp[u][0], mp(dp[it.fi][0][0].fi + it.se, dp[it.fi][0][0].se));
			reduce(dp[u][0], mp(dp[it.fi][0][1].fi + it.se, dp[it.fi][0][1].se));
			reduce(dp[u][0], mp(x[it.fi] + it.se, Find(it.fi)));
		}
	}
}

void dfs2(int u, int p, int C) {
	if(p != 0) {
		reduce(dp[u][1], mp(dp[p][1][0].fi + C, dp[p][1][0].se));
		reduce(dp[u][1], mp(dp[p][1][1].fi + C, dp[p][1][1].se));
		reduce(dp[u][1], mp(dp[p][0][0].fi + C, dp[p][0][0].se));
		reduce(dp[u][1], mp(dp[p][0][1].fi + C, dp[p][0][1].se));
		reduce(dp[u][1], mp(x[p] + C, Find(p)));
	}
	for(auto it: v[u])
		if(it.fi != p)
			dfs2(it.fi, u, it.se);
}

int main() {		
	ios;
	cin >> n;
	FOR(i, 1, n)
		cin >> x[i];
	
	FOR(i, 1, n - 1) {
		cin >> a >> b >> c;
		v[a].pb(mp(b, c));
		v[b].pb(mp(a, c));
	}
	
	Com = n;
	FOR(i, 1, n)
		p[i] = i;
	
	while(Com != 1) {
		init();
		
		dfs1(1, 0);
		dfs2(1, 0, 0);
		
		FOR(i, 1, n)
			FOR(j, 0, 1)
				FOR(g, 0, 1)
					dp[i][j][g].fi += x[i];
		
		FOR(i, 1, n) {
			int nr = Find(i);
			if(dp[i][0][0].se != nr)
				best[nr].pb(dp[i][0][0]);
			else
				best[nr].pb(dp[i][0][1]);
			if(dp[i][1][0].se != nr)
				best[nr].pb(dp[i][1][0]);
			else
				best[nr].pb(dp[i][1][1]);
		}
		
		FOR(i, 1, n) {
			sort(best[i].begin(), best[i].end());
			if(!ss(best[i]))
				continue;
			Merge.pb(mp(best[i][0].fi, mp(best[i][0].se, i)));
		}
		
		sort(Merge.begin(), Merge.end());
		
		for(auto it: Merge)
			Onion(it.se.fi, it.se.se, it.fi);
		
	}
	
	cout << ans;
		
		
		
		
	
	
	
	return 0;
}
		


Measured memory_bytes: 154352
#include<stdio.h>

int main (){
	int N,K,i,j,can;
	scanf("%d %d",&N,&K);
	int height[N];
	can = 0;
	for (i=0;i<N;i++){
		scanf("%d",&height[i]);
	}
	for (j=0;j<N;j++){
		if (height[j]>=K){
			can++;
		}
	}
	printf("%d\n",can);
	return 0;	
}


Measured memory_bytes: 512