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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

string s;
int a[500005];
int n;

int main() {
//    freopen("input.txt", "w", stdout);
//    mt19937 mt(123);
//    forn(i, 500000) {
//        int val = mt() % 10;
//        if (i == 0 && val == 0) {
//            ++val;
//        }
//        cout << val;
//    }
//    cout << endl;
//    return 0;
//    freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin >> s;
    n = int(s.size());
    forn(i, n) {
        a[i] = int(s[n - 1 - i] - '0');
    }
    int ans = 0;
    int pre = n - 1;
    for (int i = n - 1; i >= 0; ) {
        ++ans;
        int cur = -1;
        int acti = i - 1;
        if (pre < i - 5) {
            i = pre;
            cur = a[i + 1];
        }
        while (i >= 0 && a[i] >= cur) {
            if (a[i] > cur) {
                acti = i - 1;
            }
            cur = a[i];
            --i;
        }
        if (i < 0) {
            break;
        }
        pre = i;
        i = acti;
        int j = 0;
        while (a[j] == 9) {
            a[j] = 0;
            ++j;
        }
        ++a[j];
        assert(j <= i);
        pre = max(pre, j + 1);
        while (i >= 0 && a[i] == 0) {
            --i;
        }
//        for (int k = i; k >= 0; --k) {
//            cerr << a[k];
//        }
//        cerr << endl;
    }
    cout << ans << endl;
    return 0;
}


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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

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

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

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

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  string S;
  cin >> S;
  int n = S.size();
  string ans = "WA";
  if (S[0] == 'A') {
    int cnt = 0;
    for (int i = 2; i < n - 1; i++) {
      if (S[i] == 'C')
        cnt++;
    }
    if (cnt == 1) {
      for (char c = 'A'; c <= 'Z'; c++) {
        cnt = count(S.begin(), S.end(), c);
        if ((c == 'A' || c == 'C') && cnt == 1)
          ans = "AC";
        else if (cnt == 0)
          ans = "AC";
        else {
          ans = "WA";
          break;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

s, t = map(str, input().split())
a, b = inm()
u = ins()
if u == s:
    print(a-1, b)
else:
    print(a, b-1)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
long long n,x,a[1000005],ans=0;
int main()
{
    cin>>n>>x;
    for(int i=1;i<=n;i++) 
    {
       cin>>a[i+1];
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i+1]+a[i]>x) 
        {
            ans+=a[i+1]+a[i]-x;
            a[i+1]=x-a[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
 
int main(){
  int h, w;  scanf("%d %d", &h, &w);
  char field[103][103];
  for(int i=0; i<h; i++)
    scanf("%s", field[i]);
  for(int i=0; i<w+2; i++)  printf("#");  puts("");
  for(int i=0; i<h; i++)
    printf("#%s#\n", field[i]);
  for(int i=0; i<w+2; i++)  printf("#");  puts("");
 
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int num[110]={};
    int i,j;
    int n;
    num[0]=0;
    num[1]=1;
    for (i=2,j=2;i<110;i++)
    {
        if(i<2*j)
            num[i]=j;
        else
        {
            j*=2;
            num[i]=j;
        }
    }
    while (cin>>n)
    {
        cout<<num[n]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
    string S;
    cin>>S;

    if(S.size()==2){
        cout<<S<<endl;
    }
    else{
        cout<<S[2]<<S[1]<<S[0]<<endl;
    }
}

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> x(n);
	vector<int> mod(m);
	map<int,int> mp;
	rep(i,n){
		cin >> x[i];
		mod[x[i]%m]++;
		mp[x[i]]++;
	}
	vector<int> d(m);
	for (auto v: mp) {
		d[v.first%m] += v.second/2;
	}
	
	ll ans = 0;
	
	for (int i = 0; i+i <= m ; ++i) {
		if (i == 0) {
			ans += mod[i] / 2;
		} else if (i + i == m) {
			ans += mod[i] / 2;
		} else {
			int temp = min(mod[i], mod[m-i]);
			ans += temp;
			mod[i] -= temp;
			mod[m-i] -= temp;
		}
	}
	
	rep(i,m){
		if(i==0 || i+i==m) continue;
		int a = min(d[i], mod[i]/2);
		ans += a;
	}
	
	cout << ans << endl;
	
    return 0;
}

Measured memory_bytes: 6144
import math
#import numpy as np
#import numba
#from numba import njit, b1, i4, i8, f8
#from numba import jit
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
import time

dx = [1,0,-1,0]
dy = [0,1,0,-1]

def main():
    H,W = map(int,input().split())
    Ch,Cw = map(int,input().split())
    Ch+=-1
    Cw+=-1
    Dh,Dw = map(int,input().split())
    Dh+=-1
    Dw+=-1
    S = [None for i in range(H)]
    
    for i in range(H):
        S[i] = input()
        
    ans=0
    visited = [[False for i in range(W)] for j in range(H)]
    walk_deque = deque()
    walk_deque.append((Ch,Cw))
    visited[Ch][Cw]=True
    while(1):
        new_visited = []
        while(len(walk_deque) != 0):
            Ph,Pw = walk_deque.popleft()
            new_visited.append([Ph,Pw])
            #print(Ph,Pw)
            if Ph==Dh and Pw==Dw:
                print(ans)
                return
            for i in range(4):
                tmph = Ph+dy[i]
                tmpw = Pw+dx[i]
                if tmph >= 0 and tmph <=H-1 and tmpw >= 0 and tmpw <=W-1:
                    if S[tmph][tmpw]=='.' and not visited[tmph][tmpw]:
                        walk_deque.append((tmph,tmpw))
                        visited[tmph][tmpw]=True

        #print("warp")
        for h,w in new_visited:
            for x in [-2,-1,0,1,2]:
                for y in [-2,-1,0,1,2]:
                    tmph = h+y
                    tmpw = w+x
                    if tmph >= 0 and tmph <=H-1 and tmpw >= 0 and tmpw <=W-1:
                        if S[tmph][tmpw]=='.' and not visited[tmph][tmpw]:
                            walk_deque.append((h+y,w+x))
                            visited[h+y][w+x]=True
        ans+=1
        if len(walk_deque)==0:
            print(-1)
            return
        
if __name__ == '__main__':
    main()

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

using namespace std;

template <typename T>std::string NumberToString ( T Number ){std::ostringstream ss; ss << Number;return ss.str(); } // Usages NumberToString(3)
template <typename T>T StringToNumber ( const string &Text ){istringstream ss(Text);T result;return ss >> result ? result : 0;} // StringToNumber<int>("3")


int vec[900006];

int main(){

   ios::sync_with_stdio(0);
   cin.tie(0);

   set<string>mymap;
   int countN[10009];
   string name;
   int N;

   cin >> N;
   for(int i=0; i<N; i++){
   cin >> name;
   mymap.insert(name);
   }
   cout << mymap.size() <<endl;




    return 0;
}

Measured memory_bytes: 19156
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
const int INF = 1000000007;
string S;

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

  cin >> S;
  S[3] = '8';
  cout << S << "\n";
  return 0;
}

Measured memory_bytes: 256
from scipy.sparse import*
from itertools import permutations as pm

n,m,h = map(int,input().split())
r = [int(i) for i in input().split()]

u,v,l = zip(*[map(int,input().split()) for i in range(m)])

A=csgraph.dijkstra(csr_matrix((l,(u,v)),(n+1,n+1)),0)

s=min(sum(A[i][j] for i,j in zip(a[:-1],a[1:])) for a in pm(r))
print(int(s))


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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    for(int i=0; i<n/2; i++){
        if(s[i] != s[n-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=0; i<(n-1)/2-1; i++){
        if(s[i] != s[(n-1)/2-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=(n+3)/2-1; i<n; i++){
        if(s[i] != s[n-1-i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

struct unionfind {
  vector<long long> par;
  vector<long long> _size;

  // コンストラクタ
  unionfind(long n) : par(n+1), _size(n+1,1) {
    for(long long i=1; i<=n; i++) par[i]=i;
  }

  void init(long long n) {
    par = vector<long long>(n+1);
    _size = vector<long long>(n+1);
    for(long long i=1; i<=n; i++) par[i]=i;
  }

  long long root(long long x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x==y) return false;

    if(_size[x]<_size[y]) swap(x,y);

    _size[x] += _size[y];
    par[y] = x;
    return true;
  }

  bool issame(long long x, long long y) {
    return root(x) == root(y);
  }

  long long size(long long x) {
    return _size[root(x)];
  }
};

int main() {
  int n,m;
  cin >> n >> m;
  unionfind uni(n);
  vector<pair<long,long>> to;
  for (int i=0; i<m; i++) {
    int a,b;
    cin >> a >> b;
    to.push_back(make_pair(a,b));
  }
  reverse(to.begin(), to.end());

  vector<long long> ans;
  ans.push_back((long long)n*(n-1)/2);
  for (auto e : to) {
    // cerr << e.first << "->" << e.second << endl;
    long long a,b;
    a = uni.size(e.first);
    b = uni.size(e.second);
    if(uni.merge(e.first, e.second)) {
      ans.push_back(max(0LL, ans.back()-(long long)a*b));
    } else {
      ans.push_back(ans.back());
    }
  }
  ans.pop_back();

  for_each(ans.rbegin(), ans.rend(), [](const auto &i) {cout << i << endl;});
}


Measured memory_bytes: 6256
def II(): return int(input())
def LI(): return list(map(int, input().split()))

N=II()
A=LI()
cnt=[0]*((10**6)+1)
for a in A:
  cnt[a]+=1
  
unique=[]
for i in range((10**6)+1):
  if cnt[i]==1:
    unique.append(i)
    
ans=0
cnt=[0]*((10**6)+1)
A=list(set(A))
for elem in A:
  for i in range(elem*2,(10**6)+1,elem):
    cnt[i]=1
for i in unique:
  if cnt[i]==0:
    ans+=1
print(ans)

Measured memory_bytes: 47320
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

AB.sort(key= lambda x:(-x[1],-x[0]))
memo = [0]*(10**5+1)#請け負うと決めた仕事の日
work = [float('inf')]*(10**5+1)

noMore = float('inf') #これ以上の日数が振り込みにかかる仕事は受けれない
ans = 0
for a,b in AB:
    if a< noMore:
        flag = 1
        for idx in range(min(M-a,work[a]),-1,-1):
            if memo[idx] == 0:#仕事が請けられる
                ans += b
                memo[idx]=1
                flag = 0
                work[a] = idx
                break
        if flag ==1:
            noMore = a
    
print(ans)
    


Measured memory_bytes: 97524
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <time.h>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
using namespace std;
inline int lowb(int x) {
	return x & -x;
}
int n, m/* , a[], b[], p[], ans */;
struct EDGE {
	int to, dis;
};
int main() {
	cin >> n;
	cout << n / 2 - (n + 1) % 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef unsigned long long ll;

int N, n, M, K;

int main(){
    cin >> N >> K;
    if(N >= 13) cout << K;
    else if(N >= 6) cout << K/2;
    else cout << 0;
    return 0; 
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        Set<Integer> set = new HashSet<>();
        boolean yes = true;
        for(int i = 0; i < n; i++){
            int a = Integer.parseInt(sc.next());
            if(set.contains(a)) yes = false;
            set.add(a);
        }
        if(yes){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

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


int main() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N), C(N), cntA(N), cntB(N);
    rep(i,N) cin >> A.at(i);
    rep(i,N) cin >> B.at(i);
    rep(i,N) cin >> C.at(i);
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    rep(i,N) {
        auto it = upper_bound(C.begin(), C.end(), B.at(i));
        cntB.at(i) = C.end() - it;
    }
    ll sum = 0;
    rep(i,N) {
        sum += cntB.at(N - 1 - i);
        cntB.at(N - 1 - i) = sum;
    }
    rep(i,N) {
        auto it = upper_bound(B.begin(), B.end(), A.at(i));
        int index = it - B.begin();
        if (index != N) cntA.at(i) = cntB.at(index);
    }
    ll ans = 0;
    rep(i,N) ans += cntA.at(i);
    cout << ans << endl;
}



Measured memory_bytes: 7224
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HGrid1 solver = new HGrid1();
        solver.solve(1, in, out);
        out.close();
    }

    static class HGrid1 {
        NumberTheory.Mod107 mod = new NumberTheory.Mod107();

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt(), w = in.nextInt();
            char[][] grid = new char[h][];
            for (int i = 0; i < h; i++) {
                grid[i] = in.next().toCharArray();
            }

            long[][] dp = new long[h + 1][w + 1];
            dp[0][0] = 1;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (grid[i][j] == '#')
                        continue;
                    dp[i][j + 1] = mod.add(dp[i][j + 1], dp[i][j]);
                    dp[i + 1][j] = mod.add(dp[i + 1][j], dp[i][j]);
                }
            }

            out.println(dp[h - 1][w - 1]);
        }

    }

    static class NumberTheory {
        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            ArrayList<Long> factorial = new ArrayList<>();
            ArrayList<Long> invFactorial = new ArrayList<>();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.add(1L);
                invFactorial.add(1L);
            }

            public long add(long a, long b) {
                long v = a + b;
                return v < modulus() ? v : v - modulus();
            }

        }

        public static class Mod107 extends NumberTheory.Modulus<NumberTheory.Mod107> {
            public long modulus() {
                return 1_000_000_007L;
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 40192
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if(a==b){
        System.out.println("0");    
    }else if(a<b){
    if(b-(a+w)>0){
        System.out.println(b-(a+w));
    }else{
        System.out.println("0");
}
    }else{
    if(a-(b+w)>0){
        System.out.println(a-(b+w));
    }else{
        System.out.println("0");
    }    
    }
}
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

ll n,a,b;
int p[5005];
ll d[10005],s[10005];

int main(){
	n=readint(); a=readint(); b=readint();
	for(int i=1;i<=n;i++) p[readint()]=i;
	memset(d,0x3f,sizeof(d));
	d[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=2*n;j++){
			if(j&1) d[j]=s[j-1]+(p[i]==(j+1)/2?0:p[i]<(j+1)/2?a:b);
			else d[j]=s[j]+(p[i]>=(j+1)/2?b:a);
		}
		s[0]=d[0];
		for(int j=1;j<=2*n;j++) s[j]=min(s[j-1],d[j]);
	}
	printf("%lld\n",s[2*n]);
	return 0;
}

Measured memory_bytes: 512
<?php
/**
 * ABC131
 * D - Megalomania
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%d %d", $works[$i]['cost'], $works[$i]['limit']);
    $sort[$i] = $works[$i]['limit'];
}

array_multisort($sort, SORT_ASC, $works);

$time = 0;
foreach ($works as $work) {
    $time += $work['cost'];
    if ($work['limit'] < $time) {
        echo 'No', PHP_EOL;
        exit;
    }
}
echo 'Yes', PHP_EOL;


Measured memory_bytes: 123756
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from itertools import product

def resolve():
    n=int(input())
    G=[input() for _ in range(n)]
    ans=0
    for i in range(n):
        now=G[i:]+G[:i]
        ans+=all(now[i][j]==now[j][i] for i,j in product(range(n),repeat=2))

    print(n*ans)
resolve()

Measured memory_bytes: 42620
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;

template<typename T>
class hashmap64 {
	std::vector<std::pair<uint64, T>> map;
	uint64 mask, count, temp;
	uint64 hash64(uint64 key) {
		key = ~key;
		key ^= key << 13;
		key ^= key >> 19;
		return key ^ (key << 17);
	}
public:
	hashmap64() :map(8192, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
		mask = 8191; count = 0;
	}
	hashmap64(size_t s) {
		s |= s << 1;
		s |= s >> 2;
		s |= s >> 4;
		s |= s >> 8;
		s |= s >> 16;
		s |= s >> 32;
		mask = s;
		count = 0;
		map.resize(s + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
	}
	T &operator[](uint64 suf) {
		temp = mask&hash64(suf);
		while (map[temp].first != suf) {
			temp = mask&(temp + 1);
		}
		return map[temp].second;
	}
	void insert(uint64 key, const T &value) {
		temp = mask&hash64(key);
		while (~map[temp].first) {
			if (map[temp].first == key) {
				map[temp].second = value;
				return;
			}
			temp = mask&(temp + 1);
		}
		map[temp] = std::make_pair(key, value);
		++count;
		if ((count << 1) > mask) {
			std::pair<uint64, T> mkey;
			mask = mask << 1 | 1;
			map.resize(mask + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
			for (uint64 t = 0;t <= mask >> 1;++t) {
				if (~map[t].first) {
					mkey = map[t];
					map[t].first = ~static_cast<std::uint_fast64_t>(0);
					temp = mask&hash64(mkey.first);
					while (~map[temp].first) {
						temp = mask&(temp + 1);
					}
					map[temp] = mkey;
				}
			}
		}
		return;
	}
	bool find(uint64 key) {
		temp = mask&hash64(key);
		while (~map[temp].first) {
			if (map[temp].first == key) {
				return true;
			}
			temp = mask&(temp + 1);
		}
		return false;
	}
	bool empty(void) {
		return !count;
	}
	size_t size(void) {
		return count;
	}
};

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	hashmap64<uint32> map(60);
	uint32 n;
	std::cin >> n;
	int64 a, sum = 1e15;
	uint32 ans = 0;
	map.insert(sum, 0);
	rep(i, 0, n) {
		std::cin >> a;
		sum += a;
		if (map.find(sum)) {
			ans = std::max(ans, i + 1 - map[sum]);
		}
		else {
			map.insert(sum, i + 1);
		}
	}
	std::cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 15380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    ll n,k;
    cin>>n>>k;
    ll ans=1;
    for(int i=0;i<n;i++){
        if(ans<=k){
            ans=ans*2;
        }else{
            ans+=k;
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	static int mod=0;
	static List<int>[] li;
	static Dictionary<int,int>[] hs2;
	static int[] m,c;
	static long[][] dat;
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		int n=s[0];
		mod=s[1];
		long[] ans=new long[n];
		li=new List<int>[n+1];
		hs2=new Dictionary<int,int>[n+1];
		m=new int[n+1];
		c=new int[n+1];
		dat=new long[n+1][];
		for(int i=1;i<=n;i++){
			li[i]=new List<int>();
			hs2[i]=new Dictionary<int,int>();
		}
		for(int i=0;i<n-1;i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			li[q[0]].Add(q[1]);
			li[q[1]].Add(q[0]);
		}
		for(int i=1;i<=n;i++){
			int z=li[i].Count;
			m[i]=1;
			while(m[i]<=z){m[i]*=2;}
			dat[i]=new long[z+m[i]-1];
		}
		if(n==1){Console.WriteLine(1);}
		else{
			for(int i=1;i<=n;i++){ans[i-1]=Fu(i,0);}
			Console.WriteLine(String.Join("\n",ans));
		}
	}
	static long Fu(int a,int p){
		if(c[a]==-1){
			if(p==0){return dat[a][0];}
			return (fdg(0,hs2[a][p]-1,0,0,m[a]-1,a)*fdg(hs2[a][p]+1,li[a].Count-1,0,0,m[a]-1,a))%mod;
		}
		else if(c[a]==0){
			if(p==0){c[a]=-1;}
			else{c[a]=p;}
			for(int i=0;i<dat[a].Length;i++){dat[a][i]=1;}
			for(int i=0;i<li[a].Count;i++){
				hs2[a].Add(li[a][i],i);
				if(li[a][i]!=p){fdu(a,i,(Fu(li[a][i],a)+1)%mod);}
			}
			return dat[a][0];
		}
		else if(c[a]==p){return dat[a][0];}
		else{
			fdu(a,hs2[a][c[a]],(Fu(c[a],a)+1)%mod);
			c[a]=-1;
			if(p==0){return dat[a][0];}
			return (fdg(0,hs2[a][p]-1,0,0,m[a]-1,a)*fdg(hs2[a][p]+1,li[a].Count-1,0,0,m[a]-1,a))%mod;
		}
	}
	static void fdu(int c,int q,long b){
		q+=m[c]-1;
		dat[c][q]=b;
		while(q>0){
			dat[c][(q-1)/2]=(dat[c][(q-1)/2]*b)%mod;
			q=(q-1)/2;
		}
	}
	static long fdg(int a,int b,int k,int l,int r,int c){
		if(r<a||b<l){return 1;}
		if(a<=l&&r<=b){return dat[c][k];}
		else{return (fdg(a,b,k*2+1,l,(l+r)/2,c)*fdg(a,b,k*2+2,(l+r+1)/2,r,c))%mod;}
	}
}

Measured memory_bytes: 72784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll x,y;cin>>x>>y;
    if(abs(x-y)>1)cout<<"Alice"<<endl;
    else cout<<"Brown"<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<ll> div(n + 1);
	for (int i = 1; i <= n; ++i) {
		for (int j = i; j <= n; j += i) {
			++div[j];
		}
	}
	ll answer = 0;
	for (int i = 1; i <= n; ++i) {
		answer += 1ll * div[i] * i;
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 81320
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  vector<int> vec(n);
  for(int i=0; i<n; i++) {
    cin >> vec.at(i);
  }
  for(int i=0; i<n; i++) {
    if(vec.at(i) != i+1) {
      cnt++;
    }
  }
  if(cnt == 2 || cnt == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>
#include<unordered_set>
#include<algorithm>
#include<cmath>
#include<cassert>
#include<thread>
#include<future>
using namespace std;

#define INF 1e15+7
typedef long long ll;



int main(){
    int N;
    cin>>N;
    vector<ll>X(N);
    vector<ll>vec(N);
    for(int i=0;i<N;i++){
        cin>>X[i];
        vec[i]=X[i];
    }
    sort(vec.begin(),vec.end());
    vector<ll>B(N);
    ll l = vec[N/2-1];
    ll r = vec[N/2];
    for(int i=0;i<N;i++){
        if(X[i]<=l){
            B[i]=r;
        } else if(X[i]>=r){
            B[i]=l;
        }
        cout<<B[i]<<endl;
    }
    
}


Measured memory_bytes: 7168
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
import numpy as np

INF = float('inf')
NIL = - 1
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
k = np.arange(K, N + 2, dtype=np.int64)

low = k * (k - 1) // 2
high = N * k - low
cnt = high - low + 1
print(sum(cnt) % MOD)


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V)   \
    for (auto v : (V)) \
        cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main()
{
    /* code */
    int K;
    string S;
    cin >> K >> S;
    if (S.length() <= K)
    {
        cout << S << endl;
    }
    else
    {
        cout << S.substr(0, K) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define MOD 1000000007
ll check(ll x,ll l,ll r)
{
	if(x>=l && x<=r)
	{
		return 1;
	}
	else
	return 0;
}
ll mod(ll x,ll h)
{
	return (x+h)%h;
}
int main()
{
 string s;
 cin>>s;
 ll n=s.size();
 ll check=1;
 for(ll i=0;i<n;i++)
 {
 	if(s[i]!=s[n-1-i])
 	{
 		check=0;
 		break;
	}
 }
 if(check==0)
 cout<<"No"<<endl;
 else
 {  ll r= (n-3)/2;
 	for(ll i=0;i<(n-1)/2;i++)
 	{
 	  if(s[i]!=s[r-i])
	   {
	    check=0;	
	    break;
	   }	
	}
	if(check==0)
	cout<<"No"<<endl;
	else
	{
		ll l=(n+1)/2;
		for(ll i=l;i<n;i++)
		{
			if(s[i]!=s[n-1-i])
			{
				check=0;
				break;
			}
		}
		if(check==0)
		cout<<"No"<<endl;
		else
		{
			cout<<"Yes"<<endl;
		}
	}
 }
}


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

using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    int city[N+1] = {0};
    for(int i = 0; i < M; i++){
        int a,b;
        cin>>a>>b;
        city[a]++;
        city[b]++;
    }
    for(int i = 1; i < N+1; i++){
        cout<<city[i]<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

#include <tuple>

using std::cin;
using std::cout;
using std::endl;

using std::get;
using std::make_tuple;
using std::tuple;

static auto
solve(int A, int B, int C, int D, int E, int F)
{
  double e = double(E) / (100 + E);
  double best_concent = -1;
  int best_water = 0;
  int best_sugar = 0;
  for (int a = 0;; a++)
  {
    int water_a = A * a * 100;
    if (F < water_a)
    {
      break;
    }
    for (int b = 0;; b++)
    {
      int water = water_a + B * b * 100;
      if (F < water)
      {
        break;
      }
      if (0 < water)
      {
        for (int c = 0;; c++)
        {
          int sugar_c = C * c;
          int total_c = water + sugar_c;
          if (F < total_c)
          {
            break;
          }
          if (e < double(sugar_c) / total_c)
          {
            break;
          }
          for (int d = 0;; d++)
          {
            int sugar = sugar_c + D * d;
            int total = water + sugar;
            if (F < total)
            {
              break;
            }
            double concent = double(sugar) / total;
            if (e < concent)
            {
              break;
            }
            if (best_concent < concent)
            {
              best_concent = concent;
              best_water = water;
              best_sugar = sugar;
            }
          }
        }
      }
    }
  }
  return make_tuple(best_water + best_sugar, best_sugar);
}

int
main()
{
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  auto ret = solve(A, B, C, D, E, F);
  cout << get<0>(ret) << ' ' << get<1>(ret) << endl;
  return 0;
}


Measured memory_bytes: 256
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
k = [0]*(n+1)
for i in range(m):
    a = INT()
    k[a] = -1

for i in range(n+1):
    if k[i] == -1:
        continue
    elif i <= 1:
        k[i] = 1
    else:
        k[i] = ( (k[i-1] if k[i-1] != -1 else 0) + (k[i-2] if k[i-2] != -1 else 0) ) % (10**9+7)

print(k[n]%(10**9+7))

Measured memory_bytes: 13780
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as BS

stripR :: BS.ByteString -> BS.ByteString
stripR s = case BS.uncons s of
             Just ('r', s') -> s'
             _ -> s

solve :: BS.ByteString -> Bool
solve s | BS.null s = True
        | "dreamerase" `BS.isPrefixOf` s = solve $ stripR $ BS.drop 10 s
        | "dreamer" `BS.isPrefixOf` s = solve $ BS.drop 7 s
        | "dream" `BS.isPrefixOf` s = solve $ BS.drop 5 s
        | "erase" `BS.isPrefixOf` s = solve $ stripR $ BS.drop 5 s
        | otherwise = False
-- stripPrefix :: ByteString -> ByteString -> Maybe ByteString is not available

main = do
  s <- BS.getLine
  putStrLn $ if solve s then "YES" else "NO"


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int i,j;
#define fi(o,n) for(i=o;i<n;i++)
#define fj(o,n) for(i=o;j<n;j++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define double long double
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define WW 100000
#define INF 1000000000000000000 //1e18
#define EPS 0.000000001 //1e-9
//for(auto &x: a) cout<<x; to traverse along array if size is KNOWN.
//max({_,......,_}) can give maximum of any number of elements. Similarly min also.
//reverse(all(v)) would reverse a vector
//count_if(lower_bound, upper_bound, function)
int32_t main()
{   IOS
    int t,a=0;cin>>t;
    while(t>0)
    {
        int r;
        r=t%10;
        if(r==7)
        {
            a++;
        }
        t/=10;
    }
    if(a>0) cout<<"Yes";
    else cout<<"No";

}


Measured memory_bytes: 3652
#[allow(unused_macros)]
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 ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
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" ) } ; }

fn main() {
    input! {
        n: usize,
        a: [i64;n]
    }

    let mut ret = i64::min_value() >> 2;
    for i in 0..n {
        for j in i+1..n {
            ret = std::cmp::max(ret, (a[i] - a[j]).abs());
        }
    }
    println!("{}", ret);
}

Measured memory_bytes: 4352
import sys
readline = sys.stdin.readline


def main():
    N = int(readline())  # 偶数
    A = list(map(int, readline().rstrip().split()))  # [自分以外の全ての整数のxor, ...]
    
    xor = 0
    for a in A:
        xor ^= a
    
    res = [a ^ xor for a in A]
    print(*res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 31584
while true
    a,op,b = gets.split
    break if op == "?"
    puts a.to_i + b.to_i if op == "+"
    puts a.to_i - b.to_i if op == "-"
    puts a.to_i * b.to_i if op == "*"
    puts a.to_i / b.to_i if op == "/"
end

Measured memory_bytes: 6096
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
const int N = 200010; 
struct node{
	int pre, to;
}edge[N];
int head[N], tot;
int n;
int a[N];
ll k;
void add(int u, int v) {
	edge[++tot] = node{head[u], v};
	head[u] = tot;
}
int dep[N];
void get_ans(int x, int now, int dis) {
	if (now == dis) {
		cout << x;
		exit(0);
	}
	for (int i = head[x]; i; i = edge[i].pre) {
		int y = edge[i].to;
		get_ans(y, now + 1, dis);
	}
}
void dfs(int x) {
	if (dep[x] == k) {
		cout << x;
		exit(0);
	}
	for (int i = head[x]; i; i = edge[i].pre) {
		int y = edge[i].to;
		if (!dep[y]) {
			dep[y] = dep[x] + 1;
			dfs(y);
		} else {
			if (dep[x] + 1 == k) {
				cout << y;
				exit(0);
			}
			int d = dep[x] + 1 - dep[y];
			k = k - dep[x] - 1;
			k = k % d;
			get_ans(y, 0, k);
			exit(0);
		}
	}
}
int main() {
	scanf("%d", &n);
	scanf("%lld", &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		add(i, a[i]);
	}
	
	dfs(1);
	return 0;
}

Measured memory_bytes: 15440
N = int(input())
A = list(map(int, input().split()))
b = [x[1] - x[0] for x in enumerate(A,1)]
b.sort()
if N % 2 == 1:
    median = b[N//2]
else:
    median = (b[(N//2)-1]+b[N//2]) // 2
c = [abs(x-median) for x in b]
print(sum(c))

Measured memory_bytes: 26820
import heapq

N,M = [int(i) for i in input().split()]
NM = [[int(i) for i in input().split()] for _ in range(N)]
NM.sort(key=lambda x: x[0])
day, i = 1,0
heapL = []
total = 0
heapq.heapify(heapL)

while day <= M:
    while i != N and day == NM[i][0]:
        heapq.heappush(heapL, -NM[i][1])
        i += 1
        
        if i == N:
            break
    
    if heapL:
        total += (-1)*heapq.heappop(heapL)
    
    day += 1
    
print(total)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

struct State {
  int a, b, c;
  ll val;

  bool operator<(const State& o) const {
    if (val != o.val) return val > o.val;
    if (a != o.a) return a > o.a;
    if (b != o.b) return b > o.b;
    if (c != o.c) return c > o.c;
    return false;
  }

};

int main2() {
  int X, Y, Z, K; cin >> X >> Y >> Z >> K;
  vector<ll> A(X), B(Y), C(Z);
  REP(i, X) cin >> A[i];
  REP(i, Y) cin >> B[i];
  REP(i, Z) cin >> C[i];
  sort(ALL(A)); reverse(ALL(A));
  sort(ALL(B)); reverse(ALL(B));
  sort(ALL(C)); reverse(ALL(C));

  auto get = [&](const int a, const int b, const int c) {
    return (State){a, b, c, A[a] + B[b] + C[c]};
  };

  set<State> S, T;
  S.insert(get(0, 0, 0));
  T.insert(get(0, 0, 0));
  REP(_, K) {
    State cur = *S.begin();
    cout << cur.val << endl;
    S.erase(S.begin());
    if (cur.a + 1 < (int)A.size() && T.count(get(cur.a + 1, cur.b, cur.c)) == 0) { S.insert(get(cur.a + 1, cur.b, cur.c)); T.insert(get(cur.a + 1, cur.b, cur.c)); }
    if (cur.b + 1 < (int)B.size() && T.count(get(cur.a, cur.b + 1, cur.c)) == 0) { S.insert(get(cur.a, cur.b + 1, cur.c)); T.insert(get(cur.a, cur.b + 1, cur.c)); }
    if (cur.c + 1 < (int)C.size() && T.count(get(cur.a, cur.b, cur.c + 1)) == 0) { S.insert(get(cur.a, cur.b, cur.c + 1)); T.insert(get(cur.a, cur.b, cur.c + 1)); }
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int k, n;
int h[100003];
int ans = 10000000000;

int main(){

	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> h[i];

	sort(h, h + n);

	for (int i = 0; i < n - k + 1; i++){
		ans = min(ans, h[i + k - 1] - h[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
package main

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

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	sc := bufio.NewScanner(os.Stdin)
	s := make([]string, h)
	ls := make([][]int, h)
	rs := make([][]int, h)
	for i := range s {
		sc.Scan()
		s[i] = sc.Text()

		ls[i] = make([]int, w)
		for j := 0; j < w; j++ {
			if s[i][j] == '#' {
				ls[i][j] = 0
				continue
			}
			if j == 0 {
				ls[i][j] = 1
				continue
			}
			ls[i][j] = ls[i][j-1] + 1
		}

		rs[i] = make([]int, w)
		for j := w - 1; j >= 0; j-- {
			if s[i][j] == '#' {
				rs[i][j] = 0
				continue
			}
			if j == w-1 {
				rs[i][j] = 1
				continue
			}
			rs[i][j] = rs[i][j+1] + 1
		}
	}

	ts := make([][]int, h)
	ds := make([][]int, h)
	for i := range ts {
		ts[i] = make([]int, w)
		ds[i] = make([]int, w)
	}
	ans := 0
	for j := 0; j < w; j++ {
		for i := 0; i < h; i++ {
			if s[i][j] == '#' {
				ts[i][j] = 0
				continue
			}
			if i == 0 {
				ts[i][j] = 1
				continue
			}
			ts[i][j] = ts[i-1][j] + 1
		}

		for i := h - 1; i >= 0; i-- {
			if s[i][j] == '#' {
				ds[i][j] = 0
				continue
			}
			if i == h-1 {
				ds[i][j] = 1
				continue
			}
			ds[i][j] = ds[i+1][j] + 1
		}

		for i := 0; i < h; i++ {
			if v := ls[i][j] + rs[i][j] + ts[i][j] + ds[i][j] - 3; v > ans {
				ans = v
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 138260
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin >> s;
  bool r = true;
  vector<ll> ans(s.size(),0);
  ll pos = 0;
  ll odd=0;
  ll eve = 0;
  rep(i,s.size()){
      if(s[i]=='L')r=false;
      else r = true;

      if(r){
        if(i%2==0)eve++;
        else odd++;
      }


      if(i!=0&&s[i]=='L'&&s[i-1]=='R'){
          pos = i;
          if(pos%2==0){
              ans[pos]+=eve;
              ans[pos-1]+=odd;
          }else{
              ans[pos-1]+=eve;
              ans[pos]+=odd;
          }
          eve = 0;
          odd = 0;
      }
      if(!r){
          if((i-pos)%2==0){
              ans[pos]++;
          }else{
              ans[pos-1]++;
          }
      }
  }
  rep(i,s.size()){
      cout << ans[i] << " "  ;
  }
  cout << endl;
}

Measured memory_bytes: 1488
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
typedef long long LL;
char s[maxn];
char tmp[maxn];
void solve()
{
    //ios::sync_with_stdio(false);
    scanf("%s",tmp);
    int len = strlen(tmp);
    int n;
    int k,p;
    char c;
    int l = 2e5+100,r = 2e5+100;
    for(int i = 0; i<len; ++i)
    {
        s[i+l] = tmp[i];
        ++r;
    }
    --r;
    int op = 0;
    scanf("%d",&n);
    for(int i = 0; i<n; ++i)
    {
        scanf("%d",&k);
        if(k==1)
            op++;
        else
        {
            scanf("%d %c",&p,&c);
            if(op==1)
            {
                if(p==2)
                    p = 1;
                else
                    p = 2;
            }
            if(p==1)
            {
                --l;
                s[l] = c;
            }
            else
            {
                ++r;
                s[r] = c;
            }
        }
        // cout << s << "\n";
        op%=2;
    }
    if(op==1)
    {
        for(int i = r; i>=l; --i)
        {
            printf("%c",s[i]);
        }
    }
    else
    {
        for(int i = l; i<=r; ++i)
        {
            printf("%c",s[i]);
        }
    }
    printf("\n");
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define MAX_N (110)

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

	int factors[MAX_N][MAX_N];
	memset(factors, 0, sizeof(factors));
	for (int i = 2; i <= 100; i++) {
		for (int j = 2; j <= 100; j++) {
			factors[i][j] = factors[i - 1][j];
		}

		int num = i;
		for (int j = 2; j <= 100; j++) {
			while (num % j == 0) {
				factors[i][j]++;
				num /= j;
			}
		}
	}

	int cnt_74 = 0;
	int cnt_24 = 0;
	int cnt_14 = 0;
	int cnt_4 = 0;
	int cnt_2 = 0;
	for (int j = 2; j <= N; j++) {
		if (factors[N][j] >= 74)
			cnt_74++;
		if (factors[N][j] >= 24)
			cnt_24++;
		if (factors[N][j] >= 14)
			cnt_14++;
		if (factors[N][j] >= 4)
			cnt_4++;
		if (factors[N][j] >= 2)
			cnt_2++;
	}

	int res = 0;
	// p0^74
	res += cnt_74;
	// p0^24 * p1^2
	if (cnt_2 - 1 > 0)
		res += cnt_24 * (cnt_2 - 1);

	// p0^14 * p1^4
	if (cnt_4 - 1 > 0)
		res += cnt_14 * (cnt_4 - 1);

	// p0^4 * p1^4 * p2^2
	if (cnt_4 - 1 > 0 && cnt_2 - 2 > 0)
		res += cnt_4 * (cnt_4 - 1) * (cnt_2 - 2) / 2;

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

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#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 all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct Job {
	string name;
	int time;
	Job(){}
	Job(string name, int time) :name(name), time(time) {}
};
template<typename T>
struct Queue {
	T a[100000];
	int l, r,len;
	Queue():l(0),r(0),len(100000){}
	void enqueue(T x) {
		a[r++] = x;
		r %= len;
	}
	T dequeue() {
		T ret = a[l++];
		l %= len;
		return ret;
	}
	bool empty() {
		return l == r;
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	static Queue<Job>qu;
	rep(i, 0, n) {
		string s; int t;
		cin >> s >> t;
		qu.enqueue(Job(s, t));
	}
	int now(0);
	while (!qu.empty()) {
		Job j = qu.dequeue();
		int x = min(q, j.time);
		now += x;
		j.time -= x;
		if (j.time <= 0) {
			cout << j.name << " " << now << endl;
		}
		else qu.enqueue(j);
	}
	return 0;
}

Measured memory_bytes: 7020