akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		String s = fs.next();
		long k = fs.nextLong();
		
		for(int i = 0; i < k; i++) {
			int charAt = s.charAt(i) - '0';
			
			if(charAt == 1) {
				if(i == k-1) {
					System.out.println(charAt);
					return;
				}
			}else {
				System.out.println(charAt);
				return;
			}
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     long long int a,b,c,k,s=0;
     cin>>a>>b>>c>>k;
      if(a<=k)
      {
          s+=a;
          k-=a;
      }
      else
      {
          s+=k;
          k=0;
      }
      if(b<=k)
        k-=b;
      else
        k=0;
      if(c<=k)
        s-=c;
      else
        s-=k;
      cout<<s<<endl;
 }


Measured memory_bytes: 3632
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)
function bsearch(a,x);l,r=0,length(a)+1;while r-l>1;m=(r+l)>>1;if a[m]<x;l=m;else;r=m;end;end;r;end
function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	d = Dict{Int,Int}()
	for i in 1:n
		if haskey(d,a[i])
			d[a[i]] += 1
		else
			d[a[i]] = 1
		end
	end
	e = Dict{Int,Int}()
	for i in keys(d)
		if haskey(e,d[i])
			e[d[i]] += 1
		else
			e[d[i]] = 1
		end
	end
	f = zeros(Int,n)
	for i in keys(e)
		f[i] = e[i]
	end
	ans = zeros(Int,n)
	kd = zeros(Int,n+1)
	xd = zeros(Int,n+1)
	for i in 1:n
		kd[i+1] = kd[i]+i*f[i]
		xd[i+1] = xd[i]+f[i]
	end
	for i in 1:n
		ans[n-i+1] = div(kd[i+1]+i*(xd[n+1]-xd[i+1]),i)
	end
	for i in 1:n
		println(n-bsearch(ans,i)+1)
	end
end

main()

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

int main(){
  int N, K;
  vector<int> l;
  cin >> N >> K;
  for(int i=0; i<N; i++){
    int x; cin >> x;
    l.push_back(x);
  }
  sort(l.begin(), l.end(), greater<int>());
  int len=0;
  for(int i=0; i<K; i++){
    len += l[i];
  }
  cout << len << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
  ll q;
  cin>>q;
  for(int i=0;i<q;i++){
    ll c,a,n;
    cin>>c>>a>>n;
    ll t1=min({c,a,n});
    c-=t1;
    a-=t1;
    ll t2=min({c/2,a});
    c-=t2*2;
    ll t3=c/3;
    cout<<t1+t2+t3<<endl;
  }
}



Measured memory_bytes: 3096
# Acceptance of input

import sys

file_input = sys.stdin

v_num, e_num, r = map(int, file_input.readline().split())

G = [[] for i in range(v_num)]

import heapq

for line in file_input:
    s, t, w = map(int, line.split())
    if t != r:
        heapq.heappush(G[t], [w, s, t])

# Edmonds' algorithm

def find_cycle(incoming_edges, root):
    in_tree = [False] * v_num
    in_tree[root] = True
    for e in incoming_edges:
        if e:
            S = []
            S.append(e[2])
            while True:
                p = incoming_edges[S[-1]][1]
                if in_tree[p]:
                    while S:
                        in_tree[S.pop()] = True
                    break
                elif p in S:
                    return S[S.index(p):] # return nodes in a cycle
                else:
                    S.append(p)
    return None

def contract_cycle(digraph, cycle_node, root):
    super_node = cycle_node[0]
    for edges in digraph:
        if edges:
            min_weight = edges[0][0]
            for e in edges:
                e[0] -= min_weight
                if e[1] in cycle_node:
                    e[1] = super_node
                if e[2] in cycle_node:
                    e[2] = super_node
    contracted_edges = []
    for n in cycle_node: 
        for e in digraph[n]:
            if e[1] != super_node:
                heapq.heappush(contracted_edges, e)
        digraph[n].clear()
    digraph[super_node] = contracted_edges

def edmonds_branching(digraph, root, weight):
    min_incoming_edges = [None] * v_num
    for edges in digraph:
        if edges:
            min_edge = edges[0]
            min_incoming_edges[min_edge[2]] = min_edge
            weight += min_edge[0]
    C = find_cycle(min_incoming_edges, root)
    if not C:
        return weight
    else:
        contract_cycle(digraph, C, r)
        return edmonds_branching(digraph, root, weight)

# output
print(edmonds_branching(G, r, 0))

Measured memory_bytes: 7940
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <queue>
#include <climits>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

template<class T> T getAs(){ T v; std::cin >> v; return v; }
inline int getInt(){ return getAs<int>(); }

using namespace std;

int main(){
  while(true){
    int m = getInt();
    int c = getInt();
    int n = getInt();

    if(m + c + n == 0) break;

    vector<vector<int> > b(n);

    REP(i,n){
      int k = getInt();
      b[i] = vector<int>(k);
      REP(j,k) b[i][j] = getInt();
    }

    vector<set<int> > D(m);
    vector<int> idx(n);
    int ans = 0;
    int end = 0;
    int id  = 0;
    map<int, int> lru;

    while(end != n){
      REP(i,n) if(idx[i] != b[i].size()){
        int book = b[i][idx[i]++];

        if(idx[i] == b[i].size()) end++;

        // search book
        bool ok = false;
        REP(j,m) if(D[j].count(book)){
          ans += j + 1;
          D[j].erase(book);
          ok = true;
          break;
        }

        if(!ok) ans += m + 1;

        // return book
        if(D[0].size() == c){
          // put on first D
          int tmp = -1;
          REP(j,m) if(D[j].size() != c){
            tmp = j;
            D[j].insert(book);
            tmp = j;
            ans += j + 1;
            break;
          }
          if(tmp == -1){
            ans += m + 1;
          }

          // select lru book
          int lruidx = -1;
          int lruid  = INT_MAX;

          FOR(it, D[0]){
            if(lruid > lru[*it]){
              lruidx = *it;
              lruid  = lru[*it];
            }
          }

          ans += 1;
          D[0].erase(lruidx);

          // put on first D
          ok = false;
          for(int j = 1; j < m; j++) if(D[j].size() != c){
              D[j].insert(lruidx);
              ans += j + 1;
              ok = true;
              break;
          }
          if(!ok) ans += m + 1;

          // take book
          if(tmp == -1) ans += m + 1;
          else{
            ans += tmp + 1;
            D[tmp].erase(book);
          }

          // put book on D1
          ans += 1;
          D[0].insert(book);
        }else{
          D[0].insert(book);
          ans += 1;
        }

        lru[book] = id++;
      }
    }

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

  return 0;
}

Measured memory_bytes: 940
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++)
		cin >> A.at(i);

	bool flg = true;
	for(int i = 0; i < N; i++)
		if(A.at(i)%2 == 0)
			if(A.at(i)%3 && A.at(i)%5){
				flg = false;
				break;
			}
	cout << (flg?"APPROVED":"DENIED") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
	return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
	return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
	return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
	return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
	return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
	return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
	if (exp == 0) {
		return 1;
	}

	if (exp == 1) {
		return base;
	}

	if (exp % 2 == 0) {
		return powSz(base * base, exp / 2);
	}
	else {
		return base * powSz(base, exp - 1);
	}
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static size_t gcdZu(size_t m, size_t n) {
	size_t temp;

	while (m % n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m % n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t L, R;

	scanf("%zu %zu", &L, &R);

	if (2019 <= R - L + 1) {
		puts("0");
	}
	else {
		uint64_t min = (uint64_t)2019;
		for (uint64_t i = L; i <= R - 1; i++) {
			for (uint64_t j = i + 1; j <= R; j++) {
				uint64_t res = i * j % 2019;

				if (res < min) {
					min = res;
				}
			}
		}

		printf("%zu\n", min);
	}

	return 0;
}


Measured memory_bytes: 128
N, M = [int(i) for i in input().split()]
G_ls = []
d = [-float("inf") for i in range(N)]
for i in range(M):
    a, b, c = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    G_ls.append([a,b,c])

def update(x, y, is_updated):
    if x < y:
        is_updated = True
        x = y
    return x, is_updated
d[0] = 0
G_ls.sort(key=lambda x:x[0])
for i in range(N):
    for j in range(M):
        is_updated = False
        a, b, c = G_ls[j]
        d[b], is_updated = update(d[b], d[a] + c, is_updated)
if is_updated:
    print("inf")
else:
    print(d[-1])

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long A;
    std::cin >> A;
    long long B;
    std::cin >> B;
    long long C;
    std::cin >> C;
    long long D;
    std::cin >> D;

    if (A + B > C + D)
        cout << "Left" << endl;
    else if (A + B < C + D)
        cout << "Right" << endl;
    else
        cout << "Balanced" << endl;

    return 0;
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int a;
    rep(i,5){
        cin >> a;
        if(a==0)
            c(i+1);
    }
    return 0;
}


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

int main(){
	int *a,*b,c,d,w,n,*number,*data;
	scanf("%d",&w);
	scanf("%d",&n);
	a=(int*)malloc(sizeof(int)*(n+1));
	b=(int*)malloc(sizeof(int)*(n+1));
	number=(int*)malloc(sizeof(int)*(w+1));
	data=(int*)malloc(sizeof(int)*(w+1));
	for(c=1;c<=w;c++){
		number[c]=c;
		data[c]=c;
	}
	for(c=0;c<n;c++){
		scanf("%d,%d",&a[c],&b[c]);
	}
	for(c=1;c<=w;c++){
		for(d=0;d<n;d++){
			if(number[c]==a[d])number[c]=b[d];else if(number[c]==b[d])number[c]=a[d];
		}
	}
	for(c=1;c<=w;c++){
		for(d=1;d<=w;d++){
			if(number[d]==c)printf("%d\n",d);
		}
	}
	
	return 0;
} 

Measured memory_bytes: 0
# cook your dish here
import sys,math
try:sys.stdin,sys.stdout=open('input.txt','r'),open('out.txt','w')
except:pass
from sys import stdin,stdout;mod=int(1e9 + 7);from statistics import mode
from collections import *;from math import ceil,floor,inf,factorial,gcd,log2,sqrt,log
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
# print('{:.3f}'.format(1),round(1.123456789,4))
# sys.setrecursionlimit(500000)
def lcm(a,b): return (a*b)//gcd(a,b)
def setbits(n):return bin(n).count('1')
def resetbits(n):return bin(n).count('0')
def modinv(n,p):return pow(n,p-2,p)
def ncr(n,r):
    num,den=1,1;r=min(n,n-r)
    for i in range(r):num*=(n-i);den*=(i+1)
    return num//den
def ncr_p(n, r, p):
    num,den=1,1;r=min(r,n-r)
    for i in range(r):num = (num * (n - i)) % p ;den = (den * (i + 1)) % p
    return (num * modinv(den,p)) % p
def isPrime(num) :
    if num<=1:return False
    if num==2 or n==3:return True
    if (num % 2 == 0 or num % 3 == 0) :return False
    m = int(num**0.5)+1
    for i in range(5,m,6):
        if (num % i == 0 or num % (i + 2) == 0) :return False
    return True
def bin_search(s, low, high, val):
    while low <= high:
        mid = low + (high - low) // 2;
        if s[mid] == val:return mid
        elif s[mid] < val:low = mid + 1
        else:high = mid - 1
    return -1
def sumofdigit(num):
    count=0;
    while num : count+=num % 10;num //= 10;
    return count;
def inputmatrix():
    r,c=iia();mat=[0]*r;
    for i in range(r):mat[i]=iia();
    return r,c,mat;
def prefix_sum(n,s):
    for i in range(1,n):s[i]+=s[i-1]
    return s;
def binomial(n, k):
    if 0 <= k <= n:
        ntok = 1;ktok = 1
        for t in range(1, min(k, n - k) + 1):ntok *= n;ktok *= t;n -= 1
        return ntok // ktok
    else:return 0
def divisors(n):
    res = [];
    for i in range(1,ceil(sqrt(n))+1):
        if n%i == 0:
            if i==n//i:res.append(i)
            else:res.append(i);res.append(n//i)
    return res;
#code here
n = ii1()
if n==1:print(0)
else:
    print(1)


Measured memory_bytes: 72628
n=gets.to_i
a=gets.split.map &:to_i
c=0
n.times{|i|
m=i
i.upto(n-1){|j|a[j]<a[m]&&m=j}
t=a[i];a[i]=a[m];a[m]=t
i!=m&&c+=1
}
puts a*" "
p c


Measured memory_bytes: 6876
n = int(input())
a = list(map(int, input().split()))

mode = 0
ans = 0
for i in range(1, n):
    if a[i]-a[i-1] == 0:
        continue
    if a[i]-a[i-1] > 0:
        if mode == 0:
            mode = 1
        if mode == -1:
            ans += 1
            mode = 0
    if a[i]-a[i-1] < 0:
        if mode == 0:
            mode = -1
        if mode == 1:
            ans += 1
            mode = 0
print(ans+1)


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

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

  int ans = 0;

  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ans += min(x * 2, (K - x) * 2);
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 

bool check(int n,int i)
{
  while( n || i )
  {
    if((n&1) < (i&1)) return false;
    n >>= 1;
    i >>= 1;
  }
  return true;
}

int main()
{
  __;
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> v;
  for(int i=0;i<n;i++)
  {
    if(check(n-1,i)) 
    {
      v.pu(i);
      continue;
    }
  }

  set<char> se;
  bool zero = false;
  for(int i=0;i<s.size();i++) 
  {
    if(s[i] == '1') zero = true;
    s[i]--;
    se.insert(s[i]);
  }

  int x = 0;
  if(se.size() == 3)
  {
    for(int i=0;i<v.size();i++)
    {
      if(s[v[i]] == '1') x ^= 1;
      // t(s[v[i]],v[i],x);
    }
  }
  else if(se.size() == 2)
  {
    for(int i=0;i<v.size();i++)
    {
      if(s[v[i]] != '0') x ^= s[v[i]]-'0';
    }
    if(!zero) 
    {
      x = 0;
      for(int i=0;i<v.size();i++)
      {
        if(s[v[i]] != '2') x ^= s[v[i]]-'0';
      }
    }
  }
  else 
  {
    if(s.size() == 1) cout << (char)(s[0]+1) << endl;
    else cout << 0 << endl;
    return 0;
  }

  cout << x << endl;
  return 0;
}


Measured memory_bytes: 3352
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make([]int, n)
	bb := make([]int, n)

	var ans, sum int64
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
		bb[i] = getNextInt(scanner)
		if k != k|aa[i] {
			continue
		}
		sum += int64(bb[i])
	}
	if ans < sum {
		ans = sum
	}

	for b := 0; b < 30; b++ {
		if k>>uint(b)&1 == 0 {
			continue
		}
		// bビット目が1
		u := (k >> uint(b+1)) << uint(b+1)
		sum = 0
		for i := 0; i < n; i++ {
			v := (aa[i] >> uint(b)) << uint(b)
			if u != u|v {
				continue
			}
			sum += int64(bb[i])
		}
		if ans < sum {
			ans = sum
		}
	}
	fmt.Fprintln(writer, ans)

}


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

int dp[51][1<<18];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++) cin>>b[i];
    int INF = 1e9;
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<=50;j++){
            dp[j][i] = INF;
        }
    }
    dp[0][0] = 0;
    for(int bit=0;bit<(1<<n);bit++){
        int cnt = 0;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)) cnt++;
        }
        int mae = 0;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                cnt--;
                for(int ma=50;ma>=0;ma--){
                    int ret = mae+cnt;
                    // same color
                    int pre = bit ^ (1<<i);
                    if(ret %2 == 0 && a[i]>=ma){
                        dp[a[i]][bit] = min(dp[a[i]][bit],dp[ma][pre] + mae);
                    }
                    else if(ret %2 == 1 && b[i] >= ma){
                        dp[b[i]][bit] = min(dp[b[i]][bit], dp[ma][pre] + mae);
                    }
                    // if(bit == ((1<<n)-1) && a[i]==38){
                    //     cerr << ma << " " << dp[ma][pre] <<" "<<dp[38][bit] << endl;
                    // }
                }
            }
            else mae++;
        }
    }
    int ans = 1e9;
    for(int i=0;i<=50;i++){
        int bit = (1<<n)-1;
        ans = min(ans, dp[i][bit]);
        //cerr << i << " " << dp[i][bit] << endl;
    }
    if(ans == 1e9){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;

}


Measured memory_bytes: 52480
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int[] ban = new int[N];
		for(int i = 0; i < N; i++) ban[i] = s.nextInt();
		Arrays.sort(ban);
		System.out.println((ban[N - 1] - ban[0] + 1) / 2);
	}
}


Measured memory_bytes: 30052
#include <stdio.h>
int main()
{
	int num,hr,min,sec,temp;
	scanf("%d",&num);
	hr=num/3600;
	temp=num%3600;
	min=temp/60;
	sec=temp%60;
	printf("%d:%d:%d\n",hr,min,sec);
	return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    string ans = "NO";
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if(a < b) {
        if((a + t * v) >= (b + t * w)){
            ans = "YES";
        }
    } else {
        if((b - t * w) >= (a - t * v)){
            ans = "YES";
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
//abc123_d.cpp
//Sat Jun 15 15:00:55 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int x,y,z,n;
	cin >> x >> y >> z >> n;

	ll a[x],b[y],c[z];
	for (int i=0;i<x;i++){
		cin >> a[i];
	}
	for (int i=0;i<y;i++){
		cin >> b[i];
	}
	for (int i=0;i<z;i++){
		cin >> c[i];
	}

	sort(a,a+x,greater<>());
	sort(b,b+y,greater<>());
	sort(c,c+z,greater<>());

	vector<ll> ans;
	for (int i=0;i<x;i++){
		for (int j=0;j<y;j++){
			for (int k=0;k<z;k++){
				if (i*j*k<n){
					ans.push_back(a[i]+b[j]+c[k]);
				}
			}
		}
	}

	sort(ans.begin(),ans.end(),greater<ll>());

	for (int i=0;i<n;i++){
		cout << ans[i] << endl;
	}

//	printf("%.4f\n",ans);
}

Measured memory_bytes: 35172
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()

	aImg := make([]string, n)
	for i := range aImg {
		sc.Scan()
		aImg[i] = sc.Text()
	}
	bImg := make([]string, m)
	for j := range bImg {
		sc.Scan()
		bImg[j] = sc.Text()
	}

	for dRow := 0; dRow <= n-m; dRow++ {
		for dColumn := 0; dColumn <= n-m; dColumn++ {
			flg := true
			for j := 0; j < m; j++ {
				if aImg[j+dRow][dColumn:dColumn+m] != bImg[j][0:m] {
					flg = false
					break
				}
			}
			if flg {
				fmt.Println("Yes")
				return
			}
		}
	}

	fmt.Println("No")
}


Measured memory_bytes: 640
#include <cmath>
#include <iostream>
using namespace std;
int main()
{
int N,M,a[M],i,sum=0;
cin>>N>>M;
for(i=1;i<=M;i++)
{
    cin>>a[i];
    sum+=a[i];
}
if(sum>N)
cout<<"-1";
else
cout<<N-sum;
    return 0;
}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		void swap(ref long x, ref long y)
		{
			long temp = y;
			y = x;
			x = temp;
		}

		public void Exec()
		{
			long x = -1;
			long y = -1;
			List<long[]> list = new List<long[]>();
			while (x != 0 || y != 0) {
				var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
				x = array[0];
				y = array[1];
				if (x == 0 && y == 0) {
					break;
				}

				if (x > y) {
					swap(ref x, ref y);
				}
				list.Add(new[] { x, y });
			}

			foreach (var item in list) {
				Console.WriteLine($"{item[0]} {item[1]}");
			}

			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 16364
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod= 1e9+7;
long double PI = acosl(-1);
const ll inf = 1e18;
//const int inf = 2e9+100;
const int nmax = 3e5+10;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ost;

bool korajay(int idx, vector<ll>&arr, int bhot, ll bhoter, int nibo){
    int n = arr.size();
    bhot -= n-idx+nibo-1;
    ll cur = arr[idx] + bhoter;
    vector<ll>baal(arr.begin()+nibo-1, arr.begin()+idx);
    if(baal.empty()) return true;
    if(cur>=baal[0] and bhot<=0) return true;
    if(cur<baal[0]) return false;
    if(baal.size()<bhot) return false;
    ll bakivot = bhot * bhoter;
    while(baal.size()){
        ll dif = cur - baal.back();
        baal.pop_back();
        bakivot -= min(dif, bhoter);
    }
    if(bakivot>0) return false;
    return true;
}

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

    int n,m,v,p;
    cin>>n>>m>>v>>p;
    v++;
    vector<ll>arr(n);
    for(auto &x : arr) cin>>x;
    sort(arr.rbegin(), arr.rend());
    arr.push_back(-inf);

    int lo = p, hi = n;
    while(lo < hi){
        int mid = (lo+hi)/2;
//        cout<<" mid = "<<mid<<endl;
        if(korajay(mid, arr, v, m, p)){
            lo = mid+1;
//            cout<<" hoisee "<<endl;
        }
        else {
            hi = mid;
//            cout<<"hoynai "<<endl;
        }
    }
    cout<<lo<<"\n";
}


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

int main() {
  int N, D, X;
  cin >> N >> D >> X;

  vector<int> A(N);
  rep(i, N) cin >> A[i];

  int ans = X;
  rep(i, N) {
    int a = A[i];
    int d = 1, n = 1;
    while (d <= D) {
      d = n * a + 1;
      ans++;
      n++;
    }
  }

  cout << ans << endl;
}

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

#define ll long long
const int MOD = 1e9 + 7;

int add(int x, int y){
	int res = (x + y) % MOD;
	if(res < 0)	res += MOD;
	return res;
}

int mult(int x, int y){
	ll res = (x * 1LL * y) % MOD;
	if(res < 0)	res += MOD;
	return res;
}

int main(){
	int n[2];
	ll ans = 1, tmp, prefix, totX;
	cin>>n[0]>>n[1];
	for(int big = 0; big <= 1; big++){
		prefix = totX = 0;
		for(int i = 1; i <= n[big]; i++){
			cin>>tmp;
			totX = add(totX, add(mult(i - 1, tmp), -prefix));
			prefix = add(prefix, tmp);
		}
		ans = mult(ans, totX);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

class modInt{
    ll value;
    static const ll mod = 1000000007;

public:
    modInt(ll x=0): value{x % mod}{}

    inline modInt& operator+=(modInt x){
        value = (value + x.value) % mod;
        return *this;
    }

    inline modInt& operator-=(modInt x){
        value = (value + mod - x.value) % mod;
        return *this;
    }

    inline modInt& operator*=(modInt x){
        value = (value * x.value) % mod;
        return *this;
    }


    inline modInt operator/=(modInt x){
        *this *= x.inv();
        return *this;
    }

    inline modInt pow(ll n){
        modInt res = modInt(1LL);
        modInt x{value};
        while(n > 0){
            if(n & 1)   res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }

    inline modInt inv(){
        modInt res = pow(mod-2);
        return res;
    }

    inline ll get(){
        return value;
    }
};

modInt operator+(modInt x, modInt y){
    return x += y;
}

modInt operator-(modInt x, modInt y){
    return x -= y;
}

modInt operator*(modInt x, modInt y){
    return x *= y;
}

modInt operator/(modInt x, modInt y){
    return x /= y;
}

ostream& operator<<(ostream& os, modInt x){
    return os << x.get();
}


class modIntCombinations{
    vector<modInt> factArray;

    void make_fact(ll x){
        for(auto i = factArray.size(); i <= x+1; i++){
            modInt y = factArray[i-1] * i;
            factArray.push_back(y);
        }
    }

public:
    modIntCombinations(){
        factArray.emplace_back(1);
    }

    modInt fact(ll x){
        if(factArray.size() < x+1){
            make_fact(x);
        }
        return factArray[x];
    }

    modInt comb(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k) / fact(n - k);
        }
    }

    modInt perm(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k);
        }
    }
};


int main(){
    ll n;  cin >> n;
    vector<ll> x(n+1, 0);
    for(int i = 1; i <= n; i++){
        cin >> x[i];
    }

    vector<modInt> s(n+1, modInt{0});
    modIntCombinations mic{};
    for(ll i = 2; i <= n; i++){
        s[i] += s[i-1] + mic.fact(n-1) / (i-1);
    }

    modInt res = 0;
    for(int i = 2; i <= n; i++){
        ll dif = x[i] - x[i-1];
        res += s[i] * dif;
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 2936
import sys
n, m = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(m)]
ln1 = []
ln2 = []
for i in p:
    if i[0] == 1:
        ln1.append(i[1])
for j in p:
    if j[1] == n:
        ln2.append(j[0])

if len(set(ln1) & set(ln2)) == 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 54428
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j;
string s;
char ch;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    cin>>s;
    for(i=0; i<s.size(); i++){
        c=s[i]-'A';
        d=(c+a)%26;
        ch='A'+d;
        cout<<ch;
    }
    return 0;
}

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

int main() {
	int n;
	vector<int> x(200);
	cin >> n;
	for (int i = 0; i < n; i++)cin >> x.at(i);
	int count = 0;
	int i = 0;
	while (1) {
		if (i == n)i = 0, count++;
		if (x.at(i) % 2 == 0) {
			x.at(i) = x.at(i) / 2;
		}
		else
		{
			break;
		}
		i++;
	}
		cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void)
{
    int g,i;
    while(scanf("%d",&g)!=EOF){
        int ans[10]={0},cu=512,n=0;
        for(i=0;i<10;i++){
            if(g-cu>=0){
                g=g-cu;
                ans[i]=cu;
            }
            cu=cu/2;
        }
        for(i=9;i>=0;i--){
            if(ans[i]!=0&&n==0){
                printf("%d",ans[i]);
                n++;
            }
            else if(ans[i]!=0){
                printf(" %d",ans[i]);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 596
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			u = scanner.nextInt();
			if ((n | u) == 0)
				break;
			need = new int[n];
			int all = 0;
			unit = new int[n];
			for (int i = 0; i < n; i++) {
				unit[i] = scanner.nextInt();
				all += unit[i];
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					int x = scanner.nextInt();
					need[i] |= (1 << x);
				}
			}
			if (all == u) {
				System.out.println(n);
				continue;
			}
			v = new boolean[1 << n];
			Deque<Point> deque = new ArrayDeque<Point>();
			deque.offer(new Point(0, 0, 0));

			while (!deque.isEmpty()) {
				Point p = deque.poll();
				if (p.have >= u) {
					System.out.println(p.one);
					break;
				}
				for (int i = 0; i < n; i++) {
					int a = p.bit | (1 << i);
					if (v[a] || (a | need[i]) != a)
						continue;
					v[a] = true;
					deque.offer(new Point(a, p.one + 1, p.have + unit[i]));
				}
			}
		}
	}

	class Point {
		int bit, one, have;

		public Point(int bit, int one, int have) {
			super();
			this.bit = bit;
			this.one = one;
			this.have = have;
		}

		@Override
		public String toString() {
			return "Point [bit=" + bit + ", one=" + one + ", have=" + have
					+ "]";
		}

	}

	int n, u;
	int[] need, unit;
	int ans;
	boolean[] v;
}

Measured memory_bytes: 102068
#include <bits/stdc++.h>
#define ll long long int
#define N 500500
#define M 1000000007
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define mp make_pair
#define bs binary_search
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
  * @author :: Rishabh
  *
  */
int main()
{
	ibs;
	cti;
	int n,k;
	cin>>n>>k;
	int *a=new int[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	ll dp[k+2]={0};
	dp[0]=0;
	//dp[1]=0;
	for(int i=1;i<=k;i++)
	{
		for(int j=0;j<n;j++)
		{
			if((i-a[j])>=0)
			{
				if(dp[i-a[j]]==0)
				{
					dp[i]=1;
					break;
				}
			}
			else
			continue;
		}
	}
	// for(int i=0;i<=k;i++)
	// cout<<dp[i]<<" ";
	// cout<<"\n";
	if(dp[k]==1)
	cout<<"First\n";
	else
	cout<<"Second\n";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(){

string S,messg;
int C=0,indexOfC;

cin >> S;

  for (int i=0;i<S.length();i++){
    if (S[i]=='C'){C+=1;
    if(C==1&&(i!=0))indexOfC=i;
    }}
    if (C==1 &&(indexOfC==(S.length()-1)||S[1]=='C')){cout << "WA";return 0;}

if (S[0]=='A'&&C==1){
   for(int i=0; i<S.length();i++){
     if (i==0||i==indexOfC)continue;
   else if (S[i]>=97 && S[i]<=122){
        messg= "AC";}
    else {messg="WA";break;}
  }}
else messg ="WA";
cout << messg;

return 0;}

Measured memory_bytes: 256
h,w,m = map(int, input().split())
bomb=[list(map(int,input().split())) for i in range(m)]
cnt_h=[0]*h
cnt_w=[0]*w

for h,w in bomb:
    cnt_h[h-1]+=1
    cnt_w[w-1]+=1

mx_h=max(cnt_h)
mx_w=max(cnt_w)
mxh_ind=cnt_h.count(mx_h)
mxw_ind=cnt_w.count(mx_w)

hit=0
for h,w in bomb:
    if cnt_h[h-1]==mx_h and cnt_w[w-1]==mx_w:
        hit+=1

if hit==mxh_ind*mxw_ind:
    print(mx_h+mx_w-1)
else:
    print(mx_h+mx_w)

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

int main(){
    int N; cin >> N;
    long A[100010], B[100010];
    long beat[100010]; for(int i = 0; i < 100010; i++) beat[i] = 0;
    for(int i = 0; i < N + 1; i++){
        cin >> A[i];
    } 
    for(int i = 0; i < N; i++){
        cin >> B[i];
    } 
    ll sum = 0;

    for(int i = 0; i < N; i++){
        // i退治
        ll _min = min(A[i], B[i]);
        sum += _min;
        B[i] -= _min;
        // i + 1退治
        _min = min(A[i + 1], B[i]);
        sum += _min;
        A[i + 1] -= _min;
    }
    cout << sum << endl;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll N, K;
ll A[200005];
vector<ll> B[200005];
bool U[200005];

vector<ll> solve(ll n)
{
    stack<ll> s;
    memset(U, 0, sizeof(U));
    FOR(i, N, n)
    {
        ll m = A[i];
        if (!U[m])
        {
            s.push(m);
            U[m] = true;
            continue;
        }

        while (!s.empty())
        {
            ll t = s.top();
            s.pop();
            U[t] = false;
            if (t == m)
                break;
        }
    }

    vector<ll> v;
    while (!s.empty())
    {
        ll t = s.top();
        s.pop();
        v.push_back(t);
    }
    return v;
}

int main()
{
    cin >> N >> K;
    REP(i, N)
    {
        cin >> A[i];
        B[A[i]].push_back(i);
    }

    ll loop = 1;
    ll index = 0;
    while (true)
    {
        ll t = A[index];
        ll i = lower_bound(B[t].begin(), B[t].end(), index) - B[t].begin();
        i = (i + 1) % B[t].size();
        ll nxt = (B[t][i] + 1) % N;

        if (index >= nxt - 1)
        {
            if (nxt != 0 || index == N - 1)
                loop++;
        }
        //cout << index << "->" << nxt << " " << loop << endl;
        index = nxt;
        if (index == 0)
            break;
    }

    ll n = K % loop;
    index = 0;
    loop = 1;
    while (true)
    {
        if (loop >= n)
            break;
        ll t = A[index];
        ll i = lower_bound(B[t].begin(), B[t].end(), index) - B[t].begin();
        i = (i + 1) % B[t].size();
        ll nxt = (B[t][i] + 1) % N;

        if (index >= nxt - 1)
            loop++;
        index = nxt;
    }

    auto v = solve(index);

    if (n > 0)
    {
        REP(i, v.size())
        {
            cout << v[v.size() - 1 - i] << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 17044
//................ DON'T WISH IT WERE EASIER, WISH YOU WERE BETTER........................
//............ WHEN LIFE PUTS YOU IN TOUGH SITUATIONS, DONT SAY "WHY ME" SAY "TRY ME".......

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define pb emplace_back
#define endl "\n"
#define f first
#define mp make_pair
#define s second
// #define int long long
#define delrep(v)  (v).erase(unique((v).begin(),(v).end()),(v).end());
#define all(a)  (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define sz(x)   (int)x.size()
#define lll __int64
const int N=1e6+10; const int M=1e6+20;
const int mod=1e9+7;
using namespace std;
typedef long long ll;
const long long MAX_SIZE = 3000003;
vector<pair<int,int>>v[N]; map<int,int>hashx;
vector<int>a(N); vector<int>b(N); int pref[N]; int suff[N]; int sum[N];
// vector<ll>dp(N);
ll n,k;
ll dp[1005][1005];
int32_t main()
{
    int n,k; cin>>n>>k;  int ans=0,count=0;
    string s; cin>>s; char c='$';
    for(int i=0;i<s.size();i++) { if(s[i]==c) ans++; else { count++; c=s[i]; } }
    if(count>2*k) ans+=2*k; else ans=n-1;
    cout<<ans; return 0; 
}
 



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

int main(){
  int a,m,k=0;
  cin>>a>>m;
  vector<int>b(a);
  for(int i=0;i<a;i++){
    cin>>b.at(i);
    k=k+b.at(i);
  }
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  double j=(double)k/(4*(double)m);
  if(b.at(m-1)>=j){
    cout <<"Yes";
  }
  else if(b.at(m-1)<j){
    cout <<"No";
  }
}

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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpl;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1.0);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#ifdef TESTING
#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG
#define VALUE(x)
#define debug(...)
#endif
#define rep0(a,c) for (ll(a) = 0; (a) < (c); ++(a))
#define rep1(a,c) for (ll(a) = 1; (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define sqr(x) ((ll)(x) * (x))
#define rst(a,b) memset(a, b, sizeof(a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define len(v) (ll)v.size()
#define srt(v) sort( v.begin(), v.end())
#define rsrt(v) sort( v.rbegin(), v.rend())
#define rvrs(v) reverse( v.begin(), v.end())
#define PERMUTE next_permutation
#define tc(t) while (t--)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define scs(a) scanf("%s",&a)
#define yes printf("YES\n")
#define no printf("NO\n")
#define minus1  printf("-1\n")
#define space printf(" ")
#define pf1(a) printf("%lld",a)
#define pf2(a,b) printf("%lld %lld",a,b)
#define case(a) printf("Case %lld: ",a)
#define ses printf("\n")

ll power(ll x, ll y,ll M){ll res=1;while(y>0){ if(y&1)res=(res*x)%M;y=(y>>1)%M;x=(x*x)%M;}return res;}

int main()
{
    ll t;
    sc1(t);
    t%=10;
    if(t==0 || t==1 || t==6 || t==8)cout<<"pon"<<endl;
    else if(t==3)cout<<"bon"<<endl;
    else cout<<"hon"<<endl;
    return 0;

}



Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	unordered_map<int, int> um1;
	unordered_map<int, unordered_map<int, int>> um2;
	vector<pair<int, int>> vp;
	for (int i = 0; i < m; i++) {
		int p, y;
		cin >> p >> y;
		vp.push_back(make_pair(p, y));
	}
	vector<pair<int, int>> vp_ = vp;
	sort(vp_.begin(), vp_.end());
	for (auto p : vp_) {
		um1[p.first]++;
		um2[p.first][p.second] = um1[p.first];
	}
	for (int i = 0; i < m; i++) {
		string s1 = to_string(vp[i].first);
		string s2 = to_string(um2[vp[i].first][vp[i].second]);
		s1 = string(6 - s1.size(), '0') + s1;
		s2 = string(6 - s2.size(), '0') + s2;
		cout << s1 << s2 << endl;
	}
}


Measured memory_bytes: 23980
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
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; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;

    vector<bool> is_prime(55556, true);
    vector<ll> primes; primes.reserve(50000);
    REP(i, 55556) {
        if (i < 2) {
            is_prime[i] = false;
            continue;
        }
        if (is_prime[i]) {
            primes.push_back(i);
            for (ll j = i*2; j <= 55555; j += i) {
                is_prime[j] = false;
            }
        }
    }
    
    vector<ll> x;
    copy_if(ALL_OF(primes), back_inserter(x), [](ll i) { return i % 10 == 9; });
    REP(i, n) cout << x[i] << " \n"[i==i_len-1];

}

Measured memory_bytes: 384