akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: Vec<usize> = (0..9)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    let n: usize = itr.next().unwrap().parse().unwrap();

    let mut c: Vec<bool> = vec![false; 9];
    for _ in 0..n {
        let q: usize = itr.next().unwrap().parse().unwrap();
        for j in 0..9 {
            if a[j] == q {
                c[j] = true;
            }
        }
    }
    if (c[0] && c[1] && c[2])
        || (c[3] && c[4] && c[5])
        || (c[6] && c[7] && c[8])
        || (c[0] && c[3] && c[6])
        || (c[1] && c[4] && c[7])
        || (c[2] && c[5] && c[8])
        || (c[0] && c[4] && c[8])
        || (c[2] && c[4] && c[6])
    {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
package main

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

func main() {
	fsc := NewFastScanner()
	S := fsc.Next()
	cnt := map[rune]bool{}
	for _, c := range S {
		cnt[c] = true
	}
	for i := 0; i < 26; i++ {
		c := rune('a' + i)
		if _, ok := cnt[c]; !ok {
			fmt.Println(string(rune('a' + i)))
			return
		}
	}
	fmt.Println("None")
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}

func (s *FastScanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
    int matrix[101][101];
    int transpose_matrix[101][101];
    int r,c;
    int i,j;
    for(i=0; i<101; i++){
        for(j=0; j<101; j++){
            matrix[i][j] = 0;
            transpose_matrix[i][j] = 0;
        }
    }
    cin>>r>>c;
    for(i=0; i<r; i++){
        getchar();
        for(j=0; j<c; j++){
            cin>>matrix[i][j];
        }
    }
    for(i=0; i<r; i++){
        int sum_of_row = 0;
        for(j=0; j<c; j++){
            printf("%d ", matrix[i][j]);
            sum_of_row += matrix[i][j];
        }
        printf("%d\n", sum_of_row);
    }
    for(i=0; i<r; i++){
        for(j=0; j<c; j++){
            transpose_matrix[j][i] = matrix[i][j];
        }
    }
    int sum_of_all = 0;
    for(i=0; i<c; i++){
        int sum_of_column = 0;
        for(j=0; j<r; j++){
            sum_of_column += transpose_matrix[i][j];
        }
        sum_of_all += sum_of_column;
        printf("%d ", sum_of_column);
    }
    printf("%d\n",sum_of_all);
}



Measured memory_bytes: 3216
#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;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextInt();
  int M = nextInt();
  vector<pair<int,int>> ans;

  if (N % 2 == 1) {
    int a = 0;
    int b = N-1;
    REP(_, N/2) {
      ans.push_back({a, b});
      a++;
      b--;
    }
  } else {
    int a = 0;
    int b = N-1;
    int m = N/2 - 1;
    REP(_, (m+1)/2) {
      ans.push_back({a, b});
      a++;
      b--;
    }
    b--;
    REP(_, m/2) {
      ans.push_back({a, b});
      a++;
      b--;
    }
  }
  for (int i = 0; i < M; i++) {
    printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 4328
use strict;
use warnings;
package SuffixArray;
sub sa_is(\@$);
sub sa_is(\@$){
	my@s=@{$_[0]};
	my$upper=$_[1];
	my$n=@s;
	if($n==0){
		return();
	}
	elsif($n==1){
		return(0);
	}
	elsif($n==2){
		if($s[0]<$s[1]){
			return(0,1);
		}
		else{
			return(1,0);
		}
	}
	my@sa;
	my@ls;
	for(my$i=$n-2;$i>=0;$i--){
		$ls[$i]=$s[$i]==$s[$i+1]?$ls[$i+1]:$s[$i]<$s[$i+1];
	}
	my@sum_l=(0)x($upper+1);
	my@sum_s=(0)x($upper+1);
	for(0..$n-1){
		if($ls[$_]){
			$sum_l[$s[$_]+1]++;
		}
		else{
			$sum_s[$s[$_]]++;
		}
	}
	for(0..$upper){
		$sum_s[$_]+=$sum_l[$_];
		$sum_l[$_+1]+=$sum_s[$_]if$_<$upper;
	}
	my$induce;
	$induce=sub{
		my@sa=(-1)x$n;
		my@buf=@sum_s;
		for(@_){
			next if$_==$n;
			$sa[$buf[$s[$_]]++]=$_;
		}
		@buf=@sum_l;
		$sa[$buf[$s[$n-1]]++]=$n-1;
		for(0..$n-1){
			my$v=$sa[$_];
			$sa[$buf[$s[$v-1]]++]=$v-1if$v>=1&&!$ls[$v-1];
		}
		@buf=@sum_l;
		for(my$i=$n-1;$i>=0;$i--){
			my$v=$sa[$i];
			$sa[--$buf[$s[$v-1]+1]]=$v-1if$v>=1&&$ls[$v-1];
		}
		return@sa;
	};
	my@lms_map=(-1)x($n+1);
	my$m=0;
	my@lms=();
	for(1..$n-1){
		if(!$ls[$_-1]&&$ls[$_]){
			$lms_map[$_]=$m++;
			push@lms,$_;
		}
	}
	@sa=$induce->(@lms);
	if($m>0){
		my@sorted_lms;
		for(@sa){
			push@sorted_lms,$_ if$lms_map[$_]!=-1;
		}
		my@rec_s=();
		my$rec_upper=0;
		$rec_s[$lms_map[$sorted_lms[0]]]=0;
		for(1..$m-1){
			my$l=$sorted_lms[$_-1];
			my$r=$sorted_lms[$_];
			my$end_l=$lms_map[$l]+1<$m?$lms[$lms_map[$l]+1]:$n;
			my$end_r=$lms_map[$r]+1<$m?$lms[$lms_map[$r]+1]:$n;
			my$same=1;
			if($end_l-$l!=$end_r-$r){
				$same=0;
			}
			else{
				$l++,$r++while$l<$end_l&&$s[$l]==$s[$r];
				$same=0if$l==$n||$s[$l]!=$s[$r];
			}
			$rec_upper++if!$same;
			$rec_s[$lms_map[$sorted_lms[$_]]]=$rec_upper;
		}
		my@rec_sa=SuffixArray::sa_is(@rec_s,$rec_upper);
		$sorted_lms[$_]=$lms[$rec_sa[$_]]for 0..$m-1;
		@sa=$induce->(@sorted_lms);
	}
	return@sa;
}
sub suffix_array(\$){
	my@s=map ord,split"",${$_[0]};
	return sa_is(@s,255);
}
package LcpArray;
sub lcp(\@\@){
	my@s=@{$_[0]};
	my$n=@s;
	my@sa=@{$_[1]};
	my@rnk;
	$rnk[$sa[$_]]=$_ for 0..$n-1;
	my@lcp;
	my$h=0;
	for(0..$n-1){
		$h--if$h>0;
		next if$rnk[$_]==0;
		my$j=$sa[$rnk[$_]-1];
		$h++while$j+$h<$n&&$_+$h<$n&&$s[$j+$h]==$s[$_+$h];
		$lcp[$rnk[$_]-1]=$h;
	}
	return@lcp;
}
sub lcp_array(\$\@){
	my@s=map ord,split"",${$_[0]};
	return lcp(@s,@{$_[1]});
}
package main;
my$s=<>;
chomp$s;
my@sa=SuffixArray::suffix_array($s);
my@lcp=LcpArray::lcp_array($s,@sa);
my$ans=@sa*(@sa+1)/2;
$ans-=$_ for@lcp;
print$ans,$/;


Measured memory_bytes: 252484
#!/usr/bin/python3
# -*- coding: utf-8 -*-

s = input()

if len(s) == 2:
    if s[0] == s[1]:
        print('1 2')
    else:
        print('-1 -1')
else:
    f = False
    for i in range(len(s) - 2):
        if len(set(s[i:i + 3])) < 3:
            f = True
            break
    if f:
        print('{0} {1}'.format(i + 1, i + 3))
    else:
        print('-1 -1')


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

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;

  for(int x = 0; x <= K; ++x) {
    for(int y = 0; y <= K; ++y) {
      int z = S - x - y;
      if(0 <= z and z <= K) {
        ans = ans + 1;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3576
from collections import Counter

N = int(input())

A = Counter(list(map(int,input().split())))

ans = []

for k,v in sorted(A.items(),key=lambda x:x[0],reverse=True):
    if v>=4:
        ans.append(k)
        ans.append(k)
    elif v>=2:
        ans.append(k)
    if len(ans)>=2:
        break
        
print(ans[0]*ans[1] if len(ans)>=2 else 0)

Measured memory_bytes: 21540
from itertools import accumulate
from collections import Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class BinaryIndexTree:  # 1-indexed
    def __init__(self, N):
        """
        INPUT
        N [int] -> 全部0で初期化
        N [list] -> そのまま初期化
        """
        if isinstance(N, int):
            self.N = N
            self.depth = N.bit_length()
            self.tree = [0] * (N + 1)
            self.elem = [0] * (N + 1)
        elif isinstance(N, list):
            self.N = len(N)
            self.depth = self.N.bit_length()
            self.tree = [0] + N
            self.elem = [0] + N
            self._init()
        else:
            raise "INVALID INPUT: input must be int or list"

    def _init(self):
        size = self.N + 1
        for i in range(1, self.N):
            if i + (i & -i) > size:
                continue
            self.tree[i + (i & -i)] += self.tree[i]

    def add(self, i, x):
        self.elem[i] += x
        while i <= self.N:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & -i
        return res

    def lower_bound(self, val):
        if val <= 0:
            return 0
        i = 0
        k = 1 << self.depth
        while k:
            if i + k <= self.N and self.tree[i + k] < val:
                val -= self.tree[i + k]
                i += k
            k >>= 1
        return i + 1


def coordinate_Compression_1D(A):
    #from collections import Counter
    B = sorted(list(set(A)))
    idx = {a: i for i, a in enumerate(B, start=1)}
    return [idx[a] for a in A]


if __name__ == "__main__":
    N, K = map(int, input().split())
    A = [int(input()) for _ in range(N)]
    Aacc = list(accumulate([0] + A))
    B = [a - K * i for i, a in enumerate(Aacc)]
    Bcmp = coordinate_Compression_1D(B)

    bit = BinaryIndexTree(N+10)
    ans = 0
    for i, b in enumerate(Bcmp):
        ans += bit.sum(b)
        bit.add(b, 1)
    print(ans)

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

typedef long long ll;


int main() {
    int N, M, K;
    cin >> N >> M >> K;
    for (int i=0;i<=N;i++){
        for (int j=0;j<=M;j++){
            if (K == i*M + j*N - i*j*2) {
                cout << "Yes" << "\n";
                return 0;
            }
        }
    }
    cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    w1 = 10**5
    w2 = 1
    try:
        for h in range(1,3501):
            for n in range(1,3501):
                if (4*h*n-N*(h+n))>0:
                    w1 = (N*h*n)//(4*h*n-N*(h+n))
                    w2 = (N*h*n)/(4*h*n-N*(h+n))
                if w1==w2 and w1>0:
                    raise(Exception)
    except Exception:
        print(h,n,w1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import sys

readline = sys.stdin.buffer.readline

N = int(readline())
XY = []
for i in range(N):
    a = int(readline())
    XY.append(tuple(tuple(map(int, readline().split())) for _ in range(a)))


# 正直者の人数を返す(矛盾　-> -1)
def honest():
    num = 0
    for i in range(N):
        if bit>>i & 1:
            for x, y in XY[i]:
                x -= 1
                if bit>>x & 1 != y:
                    return -1
            num += 1
    return num


max_honest = 0
for bit in range(2 ** N):
    max_honest = max(max_honest, honest())
print(max_honest)


Measured memory_bytes: 3064
n,m,v,p=map(int,input().split())
S=[int(i) for i in input().split()]
S.sort(reverse=True)

def binary_search(S,k,m,v,p):
  test=S[k]+m
  cnt=m*(p-1)
  l=0
  for i in range(p-1,n):
    if i==k:
      continue
    elif test<S[i]:
      l=1
      return False
      break
    elif test-S[i]>=m:
      cnt+=m
    else:
      cnt+=test-S[i]
      
  if l==0:
    if cnt>=m*(v-1):
      return True
    else:
      return False

l=p-1
r=n
while r-l>1:
  mid=(r+l)//2
  if binary_search(S,mid,m,v,p):
    l=mid
  else:
    r=mid
print(l+1)


Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;

ll cnt;

void print(vi A, int n){
    rep(i,n){
        if(i>0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(vi &A, int n, int g){
    rng(i,g,n){
        int v = A[i];
        int j = i-g;
        while(j>=0 && A[j] > v){
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(vi &A, int n, int m, vi G){
    cnt = 0;
    rep(i,m){
        insertionSort(A,n,G[i]);
    }
}

int main() {
    int N; cin >> N;
    vi a(N);
    rep(i,N) cin >> a[i];

    vi G;
    for(int i=1;;){
        G.pb(i);
        i = i*3+1;
        if(i>N) break;
    }
    int m = G.size();
    cout << m << endl;
    sort(RALL(G));
    print(G,m);

    shellSort(a,N,m,G);
    
    cout << cnt << endl;
    rep(i,N) cout << a[i] << endl;

    return 0;
}


Measured memory_bytes: 6672
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
int main() {
    int n;
    cin>>n;
    vector<int> ans(4,0);
    for(int i = 0;i < n;++i) {
        string s;
        cin>>s;
        if(s=="AC")++ans[0];
        if(s=="WA")++ans[1];
        if(s=="TLE")++ans[2];
        if(s=="RE")++ans[3];
    }
    cout<<"AC x "<<ans[0]<<endl;
    cout<<"WA x "<<ans[1]<<endl;
    cout<<"TLE x "<<ans[2]<<endl;
    cout<<"RE x "<<ans[3]<<endl;
    return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    void solve() throws IOException {
        int n = ni();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = ni();
            if (map.containsKey(a)) {
                map.put(a, map.get(a) + 1);
            } else {
                map.put(a, 1);
            }
        }

        int ans = map.size();

        int sum = 0;
        for (int x : map.values()) {
            sum += x - 1;
        }

        if (sum % 2 != 0) ans--;

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

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

  printf("%lld\n",
      N == 1 && M == 1 ? 1 :
      N == 1 || M == 1 ? N + M - 3 :
      1LL * (N - 2) * (M - 2));
  return 0;
}

Measured memory_bytes: 128
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

import numpy as np
a = list(np.cumsum(a))

ans = 100000000000000

for i in range(n-1):
    ans = min(ans, abs(a[-1]-a[i]*2))

print(ans)


Measured memory_bytes: 28676
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b,c;
  cin >> n;
  long long tmp[3];
  for(int i=0;i<n;i++){
    cin >> a >> b >> c;
    tmp[0]=a;tmp[1]=b;tmp[2]=c;
    sort(tmp,tmp+3);
    if(tmp[0]*tmp[0]+tmp[1]*tmp[1]==tmp[2]*tmp[2]){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3112
N, X = map(int, input().split())
def bisearch(n, l):
    if l <= 0:
        return 0
    half = (2**(n+2)-3) // 2
    if half < l:
        return 2**(n) + bisearch(n-1, min(l - 1 - half, half))
    else:
        return bisearch(n-1, l-1)

print(bisearch(N, X))


Measured memory_bytes: 3060
<?php
list($n) = ints();
$isAllNoun = true;
for ($i = 0; $i < $n; ++$i) {
    list($a) = ints();
    if ($a % 2) $isAllNoun = false;
}
echo $isAllNoun ? 'second' : 'first';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16068
#include <stdio.h>

main()
{
	long n;
	
	scanf("%ld",&n);
	
	char s[1000000];
	int i=0;
	int count=0;
	char temp;
	
	while(n*26/26>0)
	{
		if(n%26==1)
		{
			s[i]='a';
			i++;
		}
		else if(n%26==2)
		{
			s[i]='b';
			i++;
			n-=1;
		}
		else if(n%26==2)
		{
			s[i]='b';
			i++;
			n-=2;
		}
		else if(n%26==3)
		{
			s[i]='c';
			i++;
			n-=3;
		}
		else if(n%26==4)
		{
			s[i]='d';
			i++;
			n-=4;
		}
		else if(n%26==5)
		{
			s[i]='e';
			i++;
			n-=5;
		}
		else if(n%26==6)
		{
			s[i]='f';
			i++;
			n-=6;
		}
		else if(n%26==7)
		{
			s[i]='g';
			i++;
			n-=7;
		}
		else if(n%26==8)
		{
			s[i]='h';
			i++;
			n-=8;
		}
		else if(n%26==9)
		{
			s[i]='i';
			i++;
			n-=9;
		}
		else if(n%26==10)
		{
			s[i]='j';
			i++;
			n-=10;
		}
		else if(n%26==11)
		{
			s[i]='k';
			i++;
			n-=11;
		}
		else if(n%26==12)
		{
			s[i]='l';
			i++;
			n-=12;
		}
		else if(n%26==13)
		{
			s[i]='m';
			i++;
			n-=13;
		}
		else if(n%26==14)
		{
			s[i]='n';
			i++;
			n-=14;
		}
		else if(n%26==15)
		{
			s[i]='o';
			i++;
			n-=15;
		}
		else if(n%26==16)
		{
			s[i]='p';
			i++;
			n-=16;
		}
		else if(n%26==17)
		{
			s[i]='q';
			i++;
			n-=17;
		}
		else if(n%26==18)
		{
			s[i]='r';
			i++;
			n-=18;
		}
		else if(n%26==19)
		{
			s[i]='s';
			i++;
			n-=19;
		}
		else if(n%26==20)
		{
			s[i]='t';
			i++;
			n-=20;
		}
		else if(n%26==21)
		{
			s[i]='u';
			i++;
			n-=21;
		}
		else if(n%26==22)
		{
			s[i]='v';
			i++;
			n-=22;
		}
		else if(n%26==23)
		{
			s[i]='w';
			i++;
			n-=23;
		}
		else if(n%26==24)
		{
			s[i]='x';
			i++;
			n-=24;
		}
		else if(n%26==25)
		{
			s[i]='y';
			i++;
			n-=25;
		}
		else if(n%26==0)
		{
			s[i]='z';
			i++;
			n-=26;
		}
		
		n/=26;
		count++;
	}
	
	for(i=0;i<count/2;i++)
	{
		temp=s[i];
		s[i]=s[count-i-1];
		s[count-i-1]=temp;
	}
	
	for(i=0;i<count;i++)
	{
		printf("%c",s[i]);
	}
}

Measured memory_bytes: 1668
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
string s;
map<string,int>f;
map<string,int>g;
int F(string s);
int G(string s)
{
	if(g.find(s)!=g.end())
	return g[s];
	if(s.size()==1)
	return g[s]=s[0]-'0'+1;
	for(int i=1;i<s.size();++i)
	{
		if(s.size()%i==0)
		{
			string t;
			for(int j=0;j<i;++j)
			{
				int r=1;
				for(int k=0;k<s.size()/i;++k)
				if(s[i*k+j]=='0')
				r=0;
				t+=(char)(r+'0');
			}
			g[s]=(g[s]+F(t))%mod;
		}
	}
	return g[s];
}
int F(string s)
{
	if(f.find(s)!=f.end())
	return f[s];
	for(int i=1;i<=s.size();++i)
	f[s]=(f[s]+1ll*F(s.substr(0,s.size()-i))*G(s.substr(s.size()-i,i))%mod)%mod;
	return f[s];
}
int main()
{
	cin>>s;
	f[""]=1;
	cout<<F(s)<<endl;
	return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	int X;
	cin>>X;
	if(X>=30)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}
int main()
{
//	ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <bitset>
#include <climits>

using namespace std;
typedef long long ll;
constexpr ll INF = ((ll)INT_MAX) << 30;

int main(){

    ll V, E, A, B, C;
    ll K[128][128];

    cin>>V>>E;
    for(int i=0;i<V;++i){
        for(int j=0;j<V;++j){
            K[i][j]=INF;
        }
        K[i][i]=0;
    }
    for(int i=0;i<E;++i){
        cin>>A>>B>>C;
        K[A][B]=C;
    }
    for(int k=0;k<V;++k){
        for(int i=0;i<V;++i){
            for(int j=0;j<V;++j){
                if(K[i][k] != INF && K[k][j] != INF){
                    K[i][j] = min(K[i][j], K[i][k] + K[k][j]);
                }
            }
        }
    }
    for(int i=0;i<V;++i){
        if(K[i][i]<0){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }
    for(int i=0;i<V;++i){
        for(int j=0;j<V;++j){
            if(j!=0){
                cout << ' ';
            }
            if(K[i][j] != INF){
                cout << K[i][j];
            }else{
                cout << "INF";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;
typedef vector<ll> Vec;
typedef vector<pair<ll, ll>> Pair;
#define rep(i, n) for(ll i=0;i<n;i++)

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359

int main() {
    // input
    ll N, M;
    cin >> N >> M;
    Vec L(M), R(M);
    rep(i, M) {
        cin >> L[i] >> R[i];
    }

    // process
    ll min = *max_element(L.begin(), L.end());
    ll max = *min_element(R.begin(), R.end());

    ll ans = max - min + 1;
    if (ans < 0) {
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
N = int(input())
s_list = []
for i in range(N):
    s_list.append(input())

M = int(input())
t_list = []
for i in range(M):
    t_list.append(input())

X_list = []
for str in s_list:
    x = s_list.count(str) - t_list.count(str)
    X_list.append(x)

if max(X_list) < 0:
    print(0)
else:
    print(max(X_list))



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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	char a ,b ;
	cin >> a >>b ;
	int A = a - '1' ;

	int B = b - '1';
	A ++ ;
	B ++ ;
	string s ="";
	string t = "";
	rep(i,B){
		s.push_back(a);
	}
	rep(i,A){
		t.push_back(b);
	}
	if(s <= t){
		cout << s << endl;
	}else cout << t << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
int main() {
    int N; cin >> N;
    vector<int> A(N); for (auto &a : A) cin >> a;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 1 && i % 2 == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
X, Y, A, B, C = gets.chomp.split(" ").map(&:to_i)
P = gets.chomp.split(" ").map(&:to_i).sort[A-X, X]
Q = gets.chomp.split(" ").map(&:to_i).sort[B-Y, Y]
R = gets.chomp.split(" ").map(&:to_i).sort

ans = 0
w_p = P.bsearch_index{|x| x >= R[-1]}
ans += P[w_p..-1].inject(:+) if not w_p.nil?
w_q = Q.bsearch_index{|x| x >= R[-1]}
ans += Q[w_q..-1].inject(:+) if not w_q.nil?
rst = (w_p.nil? ? X : w_p) + (w_q.nil? ? Y : w_q)
wk = (R + (w_p.nil? ? P : P[0...w_p]) + (w_q.nil? ? Q : Q[0...w_q])).sort.reverse
ans += wk[0, rst].inject(:+) if rst > 0

puts ans


Measured memory_bytes: 34348
N=int(input())
la=list(map(int,input().split()))
da={}
for ll in la:
    if not ll in da:
        da[ll]=1
    elif da[ll]==1:
        da[ll]=2
    else:
        da[ll]=1
nev=0
for dd in da:
    if da[dd]==2:
        nev+=1
if nev%2==0:
    print(len(da))
else:
    print(len(da)-1)


Measured memory_bytes: 18272
#include <iostream>

using namespace std;

main(){
  int n, s, ans = 0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    bool f = true;
    for(int t=1;2*t*(t+1)<=s;t++){
      if((s - 2 * t * (t + 1)) % (2 * t + 1) == 0) f = false;
    }
    ans += f;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(void)
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];

  if (a[0] + a[1] == a[2]){
    cout << "Yes" << endl;
  }
  else if (a[0] + a[2] == a[1]){
    cout << "Yes" << endl;
  }
  else if (a[2] + a[1] == a[0]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from fractions import gcd

T = int(input())

for _ in range(T):
    a, b, c, d = map(int, input().split())

    if a < b or d < b:
        flag = False
    elif c >= b - 1:
        flag =  True
    else:
        g = gcd(b, d)
        flag = (b + a % g - g) <= c

    if flag:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 5472
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

// http://drken1215.hatenablog.com/entry/2018/06/26/125054
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long res = 0;
    int right = 0;
    int sum = 0;
    //[left,right)
    for(int left = 0; left < n; left++) {
        while(right < n and (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            right++;
        }
        res += right - left;
        if(left == right) {
            right++;
        } else {
            sum -= a[left];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
x = int(input())

dp = [True] + [False] * (x+110)

for i in range(len(dp)):
    if not dp[i]: continue
    for food in range(100, 106):
        if i+food >= len(dp): continue
        dp[i+food] = True

if dp[x]: print(1)
else: print(0)

Measured memory_bytes: 10220
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll Mod = 1000000007LL;
const int Maxn = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 21;

int sz[Maxn], p[Maxn], mk[Maxn];

int par(int u){
	if(p[u] == u) return u;
	return p[u] = par(p[u]);
}
ll ans = 0;
void merge(int u, int v, int w){
	u = par(u);
	v = par(v);
	if(u == v){
		if(mk[u]) return ;
		mk[u] = 1;
		ans += w;
		return ;
	}
	if(mk[u] & mk[v]) return ;
	p[u] = v;
	ans += w;
	mk[v] |= mk[u];
}
vector< pair<ll, pll> > A;
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	iota(p, p + Maxn, 0);
	ll n, h, W;
	cin >> n >> h >> W;
	ll r,c,w;
	for(int i = 0; i < n; i++){
		cin >> r >> c >> w;
		A.pb({w,{r,c}});
	}
	sort(all(A));
	reverse(all(A));
	for(auto x : A) merge(x.S.F, x.S.S + h, x.F);
	cout << ans;
	return 0;
}

/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/



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

int main()
{
  int n;
  cin >> n;
  n *= 2;
  int arr[n];
  for (int i = 0; i < n; i++)
  {
    cin >> arr[i];
  }
  int len = sizeof(arr)/sizeof(arr[0]); 
  sort(arr, arr + len);
  int sum = 0;
  for (int i = 0; i < n; i+=2)
  {
    sum += arr[i];
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

int N, K;
int D[15];
ll ans;

bool dislike(ll x) {
	while (x > 0) {
		ll m = x % 10;
		if (D[m]) {
			return true;
		}
		x /= 10;
	}
	return false;
}


void solve() {
	ans = N;
	while (dislike(ans)) {
		ans++;
	}
	cout << ans << endl;
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		int tmp;
		cin >> tmp;
		D[tmp] = 1;
	}
	solve();
	return 0;
}




Measured memory_bytes: 256
import java.io.IOException;

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

        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;

        StringBuilder builder = new StringBuilder();
        int buf;
        while ((buf = System.in.read()) != '\n') {}
        l: while (true) {
            builder.setLength(0);
            while ((buf = System.in.read()) != '\n') {
                if (buf == -1) break l;
                builder.appendCodePoint(buf);
            }

            switch (builder.toString()) {
                case "AC" :
                    ac++;
                    break;
                case "WA":
                    wa++;
                    break;
                case "TLE":
                    tle++;
                    break;
                case "RE":
                    re++;
                    break;
            }
        }

        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }
}


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

void dfs(int depth,int m,int *a){
    if(depth == n-1){
        for(int i=0; i<n; i++){
            char c = a[i]+'a';
            cout << c;
        }
        cout << endl;
    }
    else{
        for(int i=0; i<=m; i++){
            a[depth+1] = i;
            dfs(depth+1,m,a);
        }
        a[depth+1] = m+1;
        dfs(depth+1,m+1,a);
    }
}

int main(){
    cin >> n;
    int a[n];
    a[0] = 0;
    dfs(0,0,a);
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
ll n,m;
cin>>n>>m;
ll a[m];
for (ll i = 0; i <m ; ++i)
{
  cin>>a[i];
  /* code */
}
if(n>=m)
{
  c(0);
  return;
}
sort(a,a+m);
std::vector<ll> b;
for (ll i = 0; i < m-1; ++i)
{
  b.pb(a[i+1]-a[i]);
}
sort(b.begin(), b.end(),greater<ll>());
ll ans  = a[m-1] - a[0];
//c(ans);
for (ll i = 0; i < n-1; ++i)
{
  ans -=b[i];
}
cout<<ans;


}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 2168
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

import heapq as hp
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
uni = UnionFind(N-1)
for _ in range(M):
    a, b = map(int, input().split())
    uni.Unite(a, b)

root = {}
for i in range(N):
    r = uni.Find_Root(i)
    if not r in root.keys():
        root[r] = [A[i]]
    else:
        hp.heappush(root[r], A[i])
B = sorted(root.values(), reverse=True, key=lambda x:len(x))
q = []
ok = True
ans = 0
for i, L in enumerate(B):
    if i == 0:
        for a in L:
            hp.heappush(q, a)
    else:
        if not q:
            ok = False
            break
        a1 = hp.heappop(q)
        a2 = hp.heappop(L)
        ans += a1 + a2
        for a in L:
            hp.heappush(q, a)
if not ok:
    print("Impossible")
else:
    print(ans)

Measured memory_bytes: 29100
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, k; cin >> n >> k;
    map<int, int> m;
    rep(i, n) {
        int a; cin >> a;
        ++m[a];
    }
    vector<pair<int, int>> v;
    for (auto e: m) {
        v.push_back({e.second, e.first});
    }
    sort(v.begin(), v.end());
    int ans = 0;
    rep(i, v.size() - k) {
        ans += v[i].first;
    }
    cout << ans << endl;
}


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

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

void solve(void) {
  int N, M, X; cin >> N >> M >> X;

  vector<int> price(N, 0);
  vector<vector<int>> textbook(N, vector<int>(M, 0));
  for(int i = 0; i < N; ++i) {
    cin >> price[i];
    for(int j = 0; j < M; ++j) cin >> textbook[i][j];
  }

  int res = 10000000;
  for(int bit = 0; bit < (1 << N); ++bit) {

    int cost = 0;
    vector<int> exp(M, 0);
    int count = 0;
    for(int i = 0; i < N; ++i) {
      if(bit & (1 << i)) {
        cost += price[i];
        for(int j = 0; j < M; ++j) exp[j] += textbook[i][j];
      }
    } 
    for(int mi = 0; mi < M; ++mi) {
      if (exp[mi] >= X) count++;
    }
    if(count == M) res = min(res, cost); 
  }


  if (res != 10000000) cout << res << endl;
  else cout << "-1" << endl;
}

int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
int dp[100][200000];
signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int n,W;
   cin>>n>>W;
   vector<int>w,v;
   for(int i=0;i<n;i++)
   {
       int x,y;
       cin>>x>>y;
       w.emplace_back(x);
       v.emplace_back(y);
   }
   for(int i=0;i<n;i++)
    dp[i][0]=1;
   for(int j=w[0];j<=W;j++)
    dp[0][j]=v[0];
   for(int i=1;i<n;i++)
   {
      for(int x=0;x<=W;x++)
      {
           dp[i][x]=max(dp[i][x],dp[i-1][x]);
           if(x>=w[i])
            dp[i][x]=max(dp[i][x],dp[i-1][x-w[i]]+v[i]);
      }
   }
   cout<<dp[n-1][W]<<endl;
   return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m[a]++;
  }
  int ans = 0;
  for (auto [k, v] : m) {
    if (k < v) {
      ans += v - k;
    }
    if (k > v) {
      ans += v;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 110 A / Link: http://abc110.contest.atcoder.jp/tasks/abc110_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	int a, b, c; cin >> a >> b >> c;
	ans = a + b + c + 9*max({a,b,c});
	
	
	cout << ans << "\n";

	return 0;
}


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

////// Union Find https://atcoder.jp/contests/atc001/tasks/unionfind_a
// 引用資料：https://mickey24.hatenablog.com/entry/20090602/1243950241
// 経路圧縮のみ実装？ 深さ１の部分木を生成
class DisjointSet {
private:
    vector<int> p;              // 頂点 i の所属している木の root を記録する or 部分木の root には自分を含む頂点数が負の数で記録してある
    int count;                  // 分離している部分木の本数を記録(１となったとき孤立した部分木・頂点がなくなったことを示す)

    // 所属している部分木の root を調べる
    int root(int x) {         
        return p[x] < 0 ? x : p[x] = root(p[x]);
    }

public:
    // コンストラクタ　頂点数の提示が必要
    DisjointSet(int size) {
        p.resize(size, -1); 
        count = size;
    }
    // メインとなるメソッド 部分木同士の結合
    bool unite_set(int x, int y) {          
        int rootX = root(x);
        int rootY = root(y);

        if (rootX != rootY) {                       // 部分木におけるループの排除
            if (p[rootX] > p[rootY]) {              // 自分を含む頂点数が多い方を rootX とする  
                swap(rootX, rootY); 
            }
            p[rootX] += p[rootY];                   // 自分を含む頂点数を p[rootX] に渡す
            p[rootY] = rootX;                       // root を変更
            count--;                                // 部分木同士がつながったので、本数を一つ減らす
            return true;
        }
        else{
            return false;
        }
    }

    int number_of_sets() {                          // 分離している部分木の本数を出力
        return count;
    }
};

#define N 100000 

//////　クラスカル法 
// 参考資料：https://mickey24.hatenablog.com/entry/20090605/1244132474

////// 一見 O(n^2) 本だと思われる辺を 2(n-1) 本まで減らせる 
// x座標、y座標それぞれにおいて、隣接している２頂点間のコストさえ考えればよい
// 参考資料：https://img.atcoder.jp/arc076/editorial.pdf  dProblem

int main() {
    int nVertex;
    cin >> nVertex;
    priority_queue< pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > vertexInfoX, vertexInfoY;
    for (int i = 0; i < nVertex; i++){
        int x, y;
        cin >> x >> y;
        vertexInfoX.push(make_pair(x, i));
        vertexInfoY.push(make_pair(y, i));
    }

    pair<int, int> x0 = vertexInfoX.top(); vertexInfoX.pop();
    pair<int, int> y0 = vertexInfoY.top(); vertexInfoY.pop();
    priority_queue< tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>> > edgeInfo;
    for (int i = 0; i < nVertex - 1; i++){
        pair<int, int> x1 = vertexInfoX.top(); vertexInfoX.pop();
        pair<int, int> y1 = vertexInfoY.top(); vertexInfoY.pop();
        int dx = x1.first - x0.first, dy = y1.first - y0.first;
        edgeInfo.push(make_tuple(dx, x0.second, x1.second));
        edgeInfo.push(make_tuple(dy, y0.second, y1.second));
        x0 = x1, y0 = y1;
    }
    
    DisjointSet vJoint(nVertex);
    
    int sumEdgeWeightMin = 0; 
    while (true){
        tuple<int, int, int> tmp = edgeInfo.top(); edgeInfo.pop();
        bool isJoint = vJoint.unite_set(get<1>(tmp), get<2>(tmp));
        if (isJoint){
            sumEdgeWeightMin += get<0>(tmp);
        }
        if (vJoint.number_of_sets() == 1){
            break;
        }
    }

    cout << sumEdgeWeightMin << endl;
    
    return 0;
}


Measured memory_bytes: 8652
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; 
	cin >> N; 
	long long int A[10010] = {}; 
	long long int B[10010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	for(int i = 0; i < N; i++){
		cin >> B[i]; 
	}
	long long int kaisuu = 0; 
	for(int i = 0; i < N; i++){
		kaisuu += B[i] - A[i]; 
	}
	long long int necessary = 0; 
	for(int i = 0; i < N; i++){
		if(B[i] - A[i] > 0) necessary += (B[i] - A[i] + 1) / 2; 
	}
	if(kaisuu < necessary) cout << "No" << endl; 
	else cout << "Yes" << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
bool isPrime(ll n){
    if(n == 2)return true;
    if(n == 1 || n == 0)return false;
    ll sq = sqrt(n) + 1;
    ll tmp = n; 
    for(int i = 2; i <= sq; i++){
        sq = sqrt(tmp) + 1;
        while(tmp%i == 0)tmp/=i;
    }
    if(tmp == n)return  true;
    return false;
}

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

    while(!isPrime(x))x++;
    cout << x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
int n,k;
int main(){
    cin>>n>>k>>s;
    s+=string(s.rbegin(),s.rend());
    if(k>20)cout<<string(n,*min_element(s.begin(),s.end()))<<'\n';else{
        while(k--){
            string t(s,0,n);
            reverse(t.begin(),t.end());
            for(int i=1;i<=n;++i){
                string p(s,i,n);
                reverse(p.begin(),p.end());
                if(p<t)t=p;
            }
            s=string(t.rbegin(),t.rend())+t;
        }
        s.erase(0,n);
        cout<<s<<'\n';
    }
    return 0;
}

Measured memory_bytes: 256