akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec));
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	int n;
	cin>>n;
	int d[n];
	map<int,int>mp;
	rep(i,120) mp[i]=0;
	rep(i,n) {
		cin>>d[i];
		mp[d[i]]++;
	}
	int cnt=0;
	rep(i,120) if(mp[i]) cnt++;
	cout<<cnt<<endl;
}


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

int main(void){
	int a,b;
	char op;
	while(1){
		cin >> a >> op >> b;
		if(op == '?') break;
		switch(op){
			case '+':
			cout << a + b << endl;
			break; 
			
			case '-':
			cout << a - b << endl;
			break ;

			case '*':
			cout << a * b << endl;
			break ;

			case '/':
			cout << a / b << endl;
			break ;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
<?php

fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%d', $k);
fscanf(STDIN, '%d', $x);
fscanf(STDIN, '%d', $y);

$ans = 0;
for ($i=0; $i < $n; $i++) {
    if ($i > $k - 1) {
        $ans += $y;
    } else {
        $ans += $x;
    }
}

echo $ans;

echo PHP_EOL;


Measured memory_bytes: 16240
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll a,b,c,t;
	cin>>a>>b>>c;
	t=a;
	a=b;
	b=t;
	t=a;
	a=c;
	c=t;
	cout<<a<<" "<<b<<" "<<c<<"\n";
}

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

using namespace std;

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a[i];
  ll cnt = 0;
  ll sum = 0;
  for (int i = 0; i < N; ++i) {
    ll t = sum + a[i];
    if (i % 2 == 0 && t <= 0) cnt += 1 - t, t = 1;
    if (i % 2 == 1 && t >= 0) cnt += t + 1, t = -1;
    sum = t;
  }
  ll ans = cnt;
  cnt = sum = 0;
  for (int i = 0; i < N; ++i) {
    ll t = sum + a[i];
    if (i % 2 == 1 && t <= 0) cnt += 1 - t, t = 1;
    if (i % 2 == 0 && t >= 0) cnt += t + 1, t = -1;
    sum = t;
  }
  ans = min(ans, cnt);
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int i;
	int count = 0;
	int hug = 0;
	char s[101];

	scanf("%s", s);

	for (i = 0; s[i] != '\0'; i++) //文字数を数える
	{
		count++;
	}

	for (i = 0; i < count; i++) 
	{
		if (s[i] != s[count - 1 - i]) //文字が異なる場合hugを+1する
		{
			hug++;
		}
	}

	printf("%d", hug / 2);

	return 0;
}

Measured memory_bytes: 128
n=int(input())
st=[]

for i in range(n):
	st.append(input().split())

x=input()

for j in range(n):
	if st[j][0]==x:
		k=j+1
		break
ans=0
while k < n:
	ans+=int(st[k][1])
	k+=1

print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

N = int(input())
A = inpl()
s = sum(A)

x, y = A[0], sum(A[1:])
res = abs(x-y)

for a in A[1:-1]:
    x += a
    y -= a
    if abs(x-y) < res:
        res = abs(x-y)
print(res)

Measured memory_bytes: 24960
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

bool fl(int k,int N,int Q,string s,vector<char> t,vector<char> d){
    int now = k;
    bool ok = false;
    rep(i,Q){
        if(t[i] == s[now]){
            if(d[i] == 'R') now++;
            else now--;
        }
        if(now == -1) ok = true;
    }
    return ok;
}

bool fr(int k,int N,int Q,string s,vector<char> t,vector<char> d){
    int now = k;
    bool ok = false;
    rep(i,Q){
        if(t[i] == s[now]){
            if(d[i] == 'R') now++;
            else now--;
        }
        if(now == N) ok = true;
    }
    return ok;
}

int main(){
    int N,Q; cin >> N >> Q;
    string s; cin >> s;
    vector<char> t(Q),d(Q);
    rep(i,Q) cin >> t[i] >> d[i];
    int ok = -1,ng = N;
    while(ng-ok > 1){
        int mid = (ng+ok)/2;
        if(fl(mid,N,Q,s,t,d)) ok = mid;
        else ng = mid;
    }
    int ok2 = N,ng2 = -1;
    while(ok2-ng2 > 1){
        int mid2 = (ng2+ok2)/2;
        if(fr(mid2,N,Q,s,t,d)) ok2 = mid2;
        else ng2 = mid2;
    }
    int ans = N-(ok+1)-(N-ok2);
    cout << ans << endl;
}

Measured memory_bytes: 1540
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << " ";
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

int n, k, a[MAXN];
bool dp[MAXN];

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

	cin >> n >> k;

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

	dp[0] = false;

	for (int i = 0 ;  i <= k ; ++i) {
		if (dp[i] == false) {
			for (int j = 0 ; j < n ; ++j) {
				if(i + a[j] <= k) dp[i + a[j]] = true;
			}
		}
	}

	string ans = "First";

	if (!dp[k]) ans = "Second";

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
/*
[abc150] F - Xor Shift
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 2e5;
const int MAX_B = 30;

const int MAX_PAT = MAX_N;
const int MAX_TXT = MAX_N * 2;

typedef bitset<MAX_B> BS;

int N;
BS a[MAX_N], b[MAX_N];

int table[MAX_PAT + 1];
bool matched[MAX_TXT];

void kmp(const vector<BS> &txt, const vector<BS> &pat) {
    int n = txt.size(), m = pat.size();

    table[0] = -1;
    for (int i = 0, j = -1; i < m; i++) {
        while (j >= 0 && pat[i] != pat[j]) {
            j = table[j];
        }
        table[i + 1] = ++j;
    }

    for (int i = 0, j = 0; i < n; i++) {
        while (j >= 0 && txt[i] != pat[j]) {
            j = table[j];
        }
        if (++j >= m) {
            matched[i - m + 1] = true;
            j = table[j];
        }
    }
}

void solve() {
    vector<BS> c(2 * N), d(N);
    for (int i = 0; i < 2 * N; i++) {
        c[i] = a[i % N] ^ a[(i + 1) % N];
    }
    for (int i = 0; i < N; i++) {
        d[i] = b[i % N] ^ b[(i + 1) % N];
    }

    kmp(c, d);

    for (int i = 0; i < N; i++) {
        if (!matched[i]) {
            continue;
        }
        int x = (a[i] ^ b[0]).to_ulong();
        cout << i << " " << x << endl;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int ai;
        cin >> ai;
        a[i] = BS(ai);
    }
    for (int i = 0; i < N; i++) {
        int bi;
        cin >> bi;
        b[i] = BS(bi);
    }

    solve();

    return 0;
}


Measured memory_bytes: 12288
#include<iostream>
    using namespace std;
    int main(){
      			int a;
      			char s[10];
      			cin>>a;
      			cin>>s;
      			if(a>=3200){
                  			cout<<s;
                			}
      			else{
        			 cout<<"red";
      					}
      			return 0;
    }

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

int main() {
	int A, B, C, ans = 0, sum = 0;
	cin >> A >> B >> C;
	while (C > sum) {
		++ans;
		sum += A;
		if (ans % 7 == 0) sum += B;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner stdin =new Scanner(System.in);
		int a=stdin.nextInt();
		int b=stdin.nextInt();
		int c=stdin.nextInt();
		int d=stdin.nextInt();
		int train=a;
		int bus=c;
		if(a>b)
			train=b;
		if(c>d)
			bus=d;
		System.out.println(train+bus);

	}
}

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

using namespace std;
typedef long long ll;

int n, curr, past;
ll k;
int pos[200005], dist[200005];

int main()
{

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

    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> pos[i];

    curr = 1;
    while(k && !dist[curr]){
        dist[curr] = dist[past] + 1;

        past = curr;
        curr = pos[curr];
        --k;
    }

    past = dist[past] + 1 - dist[curr];

    k -= k / past * past;

    while(k){
        curr = pos[curr];
        --k;
    }

    cout << curr;

    return 0;
}


Measured memory_bytes: 5216
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        String T = scanner.next();
        String T2 = new StringBuilder(T).deleteCharAt(T.length()-1).toString();
        if (S.equals(T2)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35612
from collections import Counter, deque, OrderedDict, defaultdict
# from copy import copy, deepcopy # pythonのみ．copyは1次元，deepcopyは多次元．
# from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
# from functools import reduce
# from heapq import heapify, heappop, heappush
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    A=list(input())
    AA=Counter(A)

    ans=1
    alpha=list(chr(ord('a')+i) for i in range(26))
    
    for i, j in product(alpha,repeat=2):
        if i<j:
            ans+=AA[i]*AA[j]


    print(ans)


    
resolve()

Measured memory_bytes: 82636
A, B, C, D, E, F = map(int, input().split())
ans1 = A
ans2 = 0
for i in range(A, F // 100 + 1):
  if any((i - A * j) % B == 0 for j in range(i // A + 1)):
    x = min(E * i, F - i * 100)
    e = max([C * j + (x - C * j) // D * D for j in range(x // C + 1)])
    if e * ans1 > ans2 * i:
      ans1 = i
      ans2 = e
print(ans1 * 100 + ans2, ans2)


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
// 取り出しまくってから詰めるのが最適
// i 回右から取り出して、j回左から取り出したとき,,,

using PQ = priority_queue<int64_t, vector<int64_t>, greater<int64_t>>;

int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, K;
    cin >> N >> K;
    vector<int64_t> V(N);
    for(int i = 0; i < N; i++) {
        cin >> V[i];
    }
    int64_t ans = -1e12;
    int64_t sum_left = 0;
    PQ p_left;
    for(int i = 0; i <= min(K, N); i++) {
        PQ p = p_left;
        int64_t sum = sum_left;
        for(int j = 0; j <= min(K, N) - i; j++) {
            PQ tmp = p;
            int64_t cand_ans = sum;
            for(int k = 0; k < K - i - j && !tmp.empty(); k++) {
                int x = tmp.top();
                if(x >= 0) break;
                tmp.pop();
                cand_ans -= x;
            }
            ans = max(ans, cand_ans);
            p.push(V[N - 1 - j]);
            sum += V[N - 1 - j];
        }
        p_left.push(V[i]);
        sum_left += V[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int count = 0;
    int v[100], c[100];
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        cin >> c[i];
    }
    for(int i=0; i<n; i++){
        if(v[i]-c[i]>0){
            count += (v[i]-c[i]);
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
//import javafx.util.Pair;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int A[][]=new int[3][3];		
		boolean flag=false;
		for(int i=0;i<3;i++)
		{
			String []s=br.readLine().split(" ");
			A[i][0]=Integer.parseInt(s[0]);
			A[i][1]=Integer.parseInt(s[1]);
			A[i][2]=Integer.parseInt(s[2]);
		}
		
		int N = Integer.parseInt(br.readLine());
		
		for(int k=0;k<N;k++)
		{
			int x=Integer.parseInt(br.readLine());
			
			//check in the matrix
			outer: 
			{
			
				for(int i=0;i<3;i++)
				{
					for(int j=0;j<3;j++)
					{
						if(A[i][j] == x)
						{
							A[i][j]=-1;
							break outer;
						}
					}
				}
			}
		}
		
		//check if bingo
		//row, col, diagonal
		for(int i=0;i<3;i++) //row
			if((A[i][0]==A[i][1]) && (A[i][1]==A[i][2])) //success
				flag=true;

		for(int i=0;i<3;i++) //column
			if((A[0][i]==A[1][i]) && (A[1][i]==A[2][i])) //success
				flag=true;
		
		if(((A[0][0]==A[1][1]) && (A[1][1]==A[2][2])) || ((A[0][2]==A[1][1]) && (A[1][1]==A[2][0]))) //diagonal
			flag=true;
			
		if(flag==true)
			out.println("Yes");
		else
			out.println("No");

	}
	
	
}




Measured memory_bytes: 21332
import java.lang.Math;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int D = sc.nextInt();

        int[][] vectors = new int[N][D];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < D; j++) {
                vectors[i][j] = sc.nextInt();
            }
        }

        int answer = 0;

        for (int i = 0; i < N-1; i++) {
            for (int j = i+1; j < N; j++) {
                // calculate distance
                int dist = 0;
                for (int d = 0; d < D; d++) {
                    int x = (vectors[i][d] - vectors[j][d]);
                    dist += (x * x);
                }

                // is dist a perfect square?
                double sq = Math.sqrt(dist);
                answer += (Math.abs(sq - Math.floor(sq)) < 0.001 ? 1 : 0);
            }
        }

        System.out.println(answer);
    }
}


Measured memory_bytes: 23124
#include <cstdio>

int main(){
  int a, b, d, r;
  double f;
  scanf("%d %d", &a, &b);
  d = a/b;
  r = a%b;
  f = a/(double)b;
  printf("%d %d %f\n", d, r, f);
  return 0;
}

Measured memory_bytes: 2756
#include <iostream>

int main(){
   std::string c1, c2;
   std::cin >> c1;
   std::cin >> c2;

   if(c1[0]==c2[2] && c1[1]==c2[1] && c1[2]==c2[0]) std::cout << "YES" << std::endl;
   else std::cout << "NO" << std::endl;
   return 0;
}


Measured memory_bytes: 256
fun main() {
    val s = read()
    if (s.contains("7")) {
        println("Yes")
    } else {
        println("No")
    }

}

private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 35596
n = gets.to_i
a = [0, *gets.split.map(&:to_i), 0]

sum = (0..n).inject(0) do |r, i|
  r + (a[i + 1] - a[i]).abs
end

(1..n).each do |i|
  d1 = (a[i] - a[i - 1]).abs + (a[i + 1] - a[i]).abs
  d2 = (a[i + 1] - a[i - 1]).abs

  puts sum - d1 + d2
end


Measured memory_bytes: 12548
N = input()
K = int(input())
m = len(N)
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)]
dp[0][0][0] = 1

for i in range(1, m + 1):
    l = int(N[i - 1])
    for k in range(K + 1):
        dp[i][1][k] += dp[i - 1][1][k]
        if l != 0:
            dp[i][1][k] += dp[i - 1][0][k]
        else:
            dp[i][0][k] += dp[i - 1][0][k]
        if k - 1 >= 0:
            dp[i][1][k] += 9 * dp[i - 1][1][k - 1]
            if l != 0:
                dp[i][0][k] += dp[i - 1][0][k - 1]
                dp[i][1][k] += (l - 1) * dp[i - 1][0][k - 1]

print(dp[m][0][K] + dp[m][1][K])


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

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

    ll dp[n+1][n+1];
    fill(dp[0], dp[n+1], 0);
    for (int i = n-1; i >= 0; i--) {
        for (int j = i+1; j <= n; j++) {
            if (n % 2 == (j - i) % 2) { // taro
                dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j-1]);
            } else { // jiro
                dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j-1]);
            }
        }
    }

    cout << dp[0][n] << "\n";
    return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];
 
ll n,i,j=1;
ll a,b;
bool flag = false;
long long int x[55];
int d;
long long int k;

int main(){
	cin>>k;
	cout<<50<<endl;
	a=k/50;
	b=k%50;
	a += 49;
	for(i=0;i<50;i++){
		x[i]=a;
	}
	for(i=0;i<50;i++){
		if(i<b){
			x[i] += 51-b;
		}else{
			x[i] -= b;
		}
	}
	for(i=0;i<50;i++){
		cout<<x[i]<<" ";
	}
	cout<<endl;
	return 0;
}

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

int main() {
	// your code goes here
	cin.tie(NULL);
	cout.tie(NULL);
	
	unsigned long long n,w;
	while(cin>>n && cin>>w)
	{
		vector<unsigned long long>weight(n),value(n);
		
		for(int i=0;i<n;i++)
		{
			cin>>weight[i]>>value[i];
		}
		
		vector<vector<unsigned long long>>dp(n+1,vector<unsigned long long>(w+1,0));
		
		for(int i=0;i<n+1;i++)
		{
			dp[i][0] = 0;
		}
		
		for(int i=0;i<=w;i++)
		dp[0][i] = 0;
		
		for(int i=1;i<=n;i++)
		{
			for(unsigned long long j=1;j<=w;j++)
			{
				if(j>=weight[i-1])
				dp[i][j] = max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
				
				else dp[i][j] = dp[i-1][j];
			}
		}
		
		cout<<dp[n][w]<<endl;
	}

	
	return 0;
}

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

int main() {
  vector<int64_t> Lucas(90);
  int N;
  cin >> N;
  
  Lucas.at(0)=2LL;
  Lucas.at(1)=1LL;
  for (int i=2; i<=N; i++) {
    Lucas.at(i) = Lucas.at(i-1) + Lucas.at(i-2);
  }
  
  cout << Lucas.at(N) << endl;
}


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

 using namespace std;

 int main() {
   int A, B;
   cin >> A >> B;
   int tap = 1;
   if (B == 1) cout << 0 << endl;
   else {
     for (int i = 2;; i++) {
       tap = (i - 1) * A - i + 2;
       if (tap >= B) {
         cout << i - 1 << endl;
         break;
       }
     }
   }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int gcd(int,int);
void swap(int,int);
  
  main()
{
  int a,b,c;
  
  scanf("%d%d",&a,&b);
  c = gcd(a,b);
  printf("%d\n",c);

  return 0;
}

int gcd(int x,int y)
{
  int r;

  if(x<y) swap(x,y);
  while(y>0){
    r = x%y;
    x = y;
    y = r;
  }
  return x;
}

void swap(int x,int y)
{
  int temp;

  temp = x;
  x = y;
  y = temp;
}

Measured memory_bytes: 592
#include <stdio.h>
#include <math.h>
int main(void) {
    int m,w[10],temp,i,j;
    while (scanf("%d",&m)!=EOF) {
        for (i=0;i<10;i++) w[i]=0;
        for (i=0;i<10;i++){
            w[i]=m%2;
            m/=2;
            if (m==0) break;
        }
        for (j=0;j<=i;j++) {
            if (w[j]!=0) {
            	temp = pow(2,j);
            	printf("%d",temp);
            	if (j!=i) {
            		printf(" ");
            	}
            }
        }
		printf("\n");
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int n = Integer.parseInt(sc.nextLine());
            int[] a = Stream.of(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray();
            int q = Integer.parseInt(sc.nextLine());
            int[] ms = Stream.of(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray();
            if (n != a.length || q != ms.length) {
                System.out.println("Conditions is invalid.");
                return;
            }
            for (int m : ms) {
                if (hasCombination(m, a, 0,0)) {
                    System.out.println("yes");
                } else {
                    System.out.println("no");
                }
            }
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static boolean hasCombination(int target, int[] elements, int i, int s) {
        if (target == s) {
            return true;
        }
        if (elements.length <= i) {
            return false;
        }
        return hasCombination(target, elements, i + 1, s + elements[i])
                || hasCombination(target, elements, i + 1, s);
    }
}



Measured memory_bytes: 32140
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
const ll B=1e6+7;
const ll mod=1e9+7,mod2=998244353;
ll t_mod(ll x,ll m){
  if(x>=0) return x%m;
  else{
    ll x2=x*(-1);
    x2/=m;
    x2+=2;
    return (x+m*x2)%m;
  }
}
bool contain(string b,string a){
  if(a.length()==0) return true;
  int al=a.length(),bl=b.length();

  ll t=1,t2=1,t3=1;
  for(int i=0;i<al;i++) {
    t*=B;
    t%=mod;
    t2*=B;
    t2%=mod2;
//    t3*=B;
//    t3%=mod3;
  }

  ll ah=0,bh=0,ah2=0,bh2=0,ah3=0,bh3=0;
  for(int i=0;i<al;i++) {
    ah=(ah*B)%mod+a[i];
    ah%=mod;
    ah2=(ah2*B)%mod2+a[i];
    ah2%=mod2;
//    ah3=(ah3*B)%mod3+a[i];
//    ah3%=mod3;
  }
  for(int i=0;i<al;i++) {
    bh=(bh*B)%mod+b[i];
    bh%=mod;
    bh2=(bh2*B)%mod2+b[i];
    bh2%=mod2;
//    bh3=(bh3*B)%mod3+b[i];
//    bh3%=mod3;
  }

  vector<int> ret;
  for(int i=0;i+al<=bl;i++){
    if(ah==bh&&ah2==bh2/*&&ah3==bh3*/) {
      return true;
    }
    if(i+al<bl){
      bh=(bh*B)%mod+b[i+al]-b[i]*t;
      bh=t_mod(bh,mod);
      bh2=(bh2*B)%mod2+b[i+al]-b[i]*t2;
      bh2=t_mod(bh2,mod2);
//      bh3=(bh3*B)%mod3+b[i+al]-b[i]*t3;
//      bh3=t_mod(bh3,mod3);
    }
  }
  return false;
}
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<n-1;i++){
    int lb=0,rb=(n-i)/2+1;
    while(rb-lb>1){
      int mid=(lb+rb)/2;
      string l=s.substr(i,mid),r=s.substr(i+mid,n-(i+mid));
      //cout<<i<<" "<<mid<<" "<<l<<" "<<r
      if(contain(r,l)) lb=mid;
      else rb=mid;
    }
    ans=max(ans,lb);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
object Main extends App {
  println(scala.io.StdIn.readChar match {
    case 'a' => "vowel"
    case 'e' => "vowel"
    case 'i' => "vowel"
    case 'o' => "vowel"
    case 'u' => "vowel"
    case _ => "consonant"
  })
}

Measured memory_bytes: 21412
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_5-B: Merge Sort

#include <cstdio>
#include <cstring>

static void print_ints(const int as[], const unsigned int n, const char* sep = " ")
{
  const char* out_sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::printf("%s%d", out_sep, as[i]);
    out_sep = sep;
  }
  std::printf("\n");
}

static void print_int(const unsigned int n)
{
  std::printf("%d\n", n);
}

static unsigned int comparison_count = 0u;

static void merge(int* const ss, const unsigned int n)
{
  auto n1 = n/2, n2 = n-n1;
  int tmp[n1];
  std::memcpy(tmp, ss, sizeof(tmp));
  auto ss1 = tmp, ss2 = ss+n1;
  auto i = 0u, i1 = 0u, i2 = 0u;
  while (i1 < n1 && i2 < n2) {
    ++comparison_count;
    if (ss1[i1] < ss2[i2]) {
      ss[i++] = ss1[i1++];
    } else {
      ss[i++] = ss2[i2++];
    }
  }
  while (i1 < n1) {
    ++comparison_count;
    ss[i++] = ss1[i1++];
  }
  while (i2 < n2) {
    ++comparison_count;
    ss[i++] = ss2[i2++];
  }
}

static void merge_sort(int* const ss, const unsigned int n)
{
  if (n > 1) {
    auto n1 = n/2, n2 = n-n1;
    auto ss1 = ss, ss2 = ss+n1;
    merge_sort(ss1, n1); // ss[0..n/2-1] is sorted
    merge_sort(ss2, n2); // ss[n/2..n-1] is sorted
    merge(ss, n);
  }
}

int main()
{
  unsigned int n;
  std::scanf("%d", &n);
  int ss[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  merge_sort(ss, n);
  print_ints(ss, n);
  print_int(comparison_count);
}

// eof

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll A, B, C, D, E;
    cin >> A >> B >>C >> D >> E;
    ll T1 = 60*A + B;
    ll T2 = 60*C + D;
    ll res = max(0ll, T2-T1-E);
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mxn 1000005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using  namespace std;
int main(void){
	fast;
	ll n,k,i,ma=-inf;
	cin>>n>>k;
	ll a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
		ma=max(ma,a[i]);
	}
	ll lo=1,hi=ma;
	while(lo<hi){
		ll mid=(lo+hi)/2;
		ll c=0;
		for(i=0;i<n;i++)
			c+=(a[i]-1)/mid;
		if(c>k)
		lo=mid+1;
		else
		hi=mid;
	}
	cout<<lo;
}


Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n, m;
        in >> n >> m;
        out << (n - 1)*(m - 1) << endl;
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a);i < (b);++i)
#define FORR(i, b, a) for (int i = (b) - 1;i >= 0;--i)
#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = (n) - 1;i >= 0;--i)
#define ITER(itr, v) for(auto itr = v.begin();itr != v.end();++itr)
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
#define SIZE(v) int(v.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N, K;
	cin >> N >> K;
	vector<pair<ll, int>> dt(N);
	REP(i, N) cin >> dt[i].second >> dt[i].first;
	sort(dt.begin(), dt.end(), greater<pair<ll, int>>());
	vector<int> num(N + 1);
	ll sum = 0;
	ll x = 0;
	REP(i, K) {
		sum += dt[i].first;
		if (num[dt[i].second]++ == 0) ++x;
	}
	ll res = 0;
	int i = K - 1, j = K;
	while (true) {
		res = max(res, sum + x * x);
		if (x == K) break;
		while (i >= 0 && num[dt[i].second] == 1) --i;
		if (i < 0) break;
		while (j < N && num[dt[j].second] > 0) ++j;
		if (j == N) break;
		num[dt[i].second]--;
		num[dt[j].second]++;
		++x;
		sum = sum - dt[i].first + dt[j].first;
		--i;
		++j;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
int main(){
    char S[3];
    int pr = 700;
    int i;
    /*printf("注文メモを入力してください\n");*/
    scanf("%s", S);
    for(i = 0; i <3; i++){
        if(S[i] == 'o') pr+= 100;
    }
    printf("%d\n",pr);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int N,M;
main(){
  cin>>N>>M;
  vector<pair<int,int>>ms(M);
  for(int i=0;i<M;++i){
    int a,b;
    cin>>a>>b;
    --a;
    --b;
    ms[i]={b,a};
  }
  sort(ms.begin(),ms.end());
  int last=-1;
  int n_count=0;
  for(int i=0;i<M;++i){
    const int left=ms[i].second;
    const int right=ms[i].first;
    // printf("left, right = %d, %d\n",left,right);
    if(left<=last)continue;
    last=right-1;
    ++n_count;
  }
  cout<<n_count<<endl;
}


Measured memory_bytes: 1024
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    long[3] cnt;
    foreach (c; S)
        cnt[c - 'a']++;
    long m = max(abs(cnt[0] - cnt[1]), abs(cnt[1] - cnt[2]), abs(cnt[0] - cnt[2]));
    writeln((m < 2) ? "YES" : "NO");
}


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
     while(t--){
        int n,k;
        cin>>n;
        vector<int> arr(n);
        long long int sum=0;
        map<int,int> mp;
        for(int i=0;i<n;i++){
        	cin>>arr[i];
        	mp[arr[i]]++;
        	sum+=arr[i];
		}
	    int q;
	    cin>>q;
	    while(q--){
	    	int a,b;
	    	cin>>a>>b;
	    	sum=sum+mp[a]*(b-a);
	    	mp[b]+=mp[a];
	    	mp[a]=0;
	    	cout<<sum<<"\n";
		}
    }
}

Measured memory_bytes: 7976
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
const ll mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll N=1e5+8;
const ll INF=1e18;
int prime[N]={0};
ll a[300000]={0};
int main(){
  IOS;
  ll n,k;
  cin>>n>>k;
  for(ll i=1;i<=n;i++){
    cin>>a[i];
  }
  for(ll i=1;i<=n;i++){
   ll x=i;
   ll y=i+k;
   if(y>n)
   break;
   if(a[y]>a[x])
   cout<<"Yes"<<endl;
   else 
   cout<<"No"<<endl;
  }
}

Measured memory_bytes: 5196
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b && b==c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n);
    bool exist_0 = false;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if(a[i] == 0)exist_0 = true;
    }

    if(exist_0)
    {
        cout << 0 << endl;
    }
    else
    {
        long long ans = 1;
        for (long long i = 0; i < n; i++)
        {
            if((long double)1e18 / a[i] < ans)
            {
                ans = -1;
                break;
            }
            else
            {
                ans *= a[i];
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 4052
N, K = map(int, input().split())

S = list(input())

newS=' '
for i in range(N):
    if i == K-1:
        if S[i]=="A":
            newS+="a"
        elif S[i]=="B":
            newS+="b"
        elif S[i]=="C":
            newS+="c"
        else:
            newS+=S[i]
    else:
        newS+=S[i]
print(newS)

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

int main() {
	int charge[7] = {600,800,1000,1200
	,1400,1600,0 };

	int n;
	int a, b, c, d;
	while (cin >> n, n) {
		int sum = 0;

		for (int i = 0; i < n; i++) {
			int flga, flgb;
			cin >> a >> b >> c >> d;
			int e = a + b + c;

			if (e <= 60) { flga = 0; }
			else if (e <= 80) { flga = 1; }
			else if (e <= 100) { flga = 2; }
			else if (e <= 120) { flga = 3; }
			else if (e <= 140) { flga = 4; }
			else if (e <= 160) { flga = 5; }
			else { flga = 6; }

			if (d <= 2) { flgb = 0; }
			else if (d <= 5) { flgb = 1; }
			else if (d <= 10) { flgb = 2; }
			else if (d <= 15) { flgb = 3; }
			else if (d <= 20) { flgb = 4; }
			else if (d <= 25) { flgb = 5; }
			else { flgb = 6; }
			
			int flgc = max(flga, flgb);
			sum += charge[flgc];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 2976
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  cin >>A;
  vector<int> a(A-1);
  vector<int> b(A);
  for(int i=0; i<A-1; i++){
    cin >>a.at(i);
  }
  for(int i=0; i<A-1; i++){
    int k = a.at(i)-1;
    b.at(k)++;
  }
  for(int i=0; i<A; i++){
    cout <<b.at(i) <<endl;
  }
}

Measured memory_bytes: 4800
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
using namespace std;

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

class CToInfinity {
public:
	void solve(std::istream& in, std::ostream& out) {
		string s; in >> s;
		int k; in >> k;
		f(i, s.length()){
			if(s[i]!='1'){
				out << s[i];
				break;
			}
			if(i+1 == k){
				out << s[i];
				return;
			}
		}
	}
};


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CToInfinity solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

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

  int X,Y;
  cin >> X >> Y;
  
  int x[N] = {0};
  int y[M] = {0};

  for(int i = 0; i < N; ++i){
    cin >> x[i];
  }
  for(int i = 0; i < M; ++i){
    cin >> y[i];
  }

  sort(x, x + N, greater<int>());
  sort(y, y + M);

  if(y[0] - x[0] <= 0){
    cout << "War" << endl;
  } else if(x[0] >= Y|| y[0] <= X){
    cout << "War" << endl;
  } else if(Y - X <= y[0] - x[0]) {
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int n; cin>>n;
    map<int,int> m_odd,m_even;
    REP(i,n) {
        int v;
        cin>>v;
        if (i%2) {
            m_even[v]++;
        } else {
            m_odd[v]++;
        }
    }
    Pi c1_odd = {0,0}, c2_odd = {0,0}, c1_even = {0,0}, c2_even = {0,0};
    for (auto itr = m_odd.begin(); itr != m_odd.end(); ++itr) {
        if (c1_odd.second<=itr->second) {
            c2_odd = c1_odd;
            c1_odd.first = itr->first;
            c1_odd.second = itr->second;
        } else if (c2_odd.second<itr->second && itr->second<c1_odd.second) {
            c2_odd.first = itr->first;
            c2_odd.second = itr->second;
        }
    }
    for (auto itr = m_even.begin(); itr != m_even.end(); ++itr) {
        if (c1_even.second<=itr->second) {
            c2_even = c1_even;
            c1_even.first = itr->first;
            c1_even.second = itr->second;
        } else if (c2_even.second<itr->second && itr->second<c1_even.second) {
            c2_even.first = itr->first;
            c2_even.second = itr->second;
        }
    }
    int ans;
    if (c1_odd.first==c1_even.first) {
        ans = n - max(c1_even.second+c2_odd.second,c1_odd.second+c2_even.second);
    } else {
        ans = n - c1_odd.second - c1_even.second;
    }
    cout<<ans<<endl;
}


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

#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TC int tc; cin >> tc; while(tc--)

using namespace std;

const int INF = 1e9 + 7;


int main(void)
{
	FAST
	int n; cin >> n;
	string s; cin >> s;
	int p1 = 0, p2 = n-1;

	int ans = 0;

	while(p1 < p2){
		if(s[p1] == 'R') p1++;
		else if(s[p2] == 'W') p2--;
		else {
			s[p1] = 'R';
			s[p2] = 'W';
			ans++;
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define ins				insert
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull				unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>
#define usi 			unordered_set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}

void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
bool cmp(Node A,Node B)
{
	return A.a<B.a;
}
const int Max=1e5+1;

int32_t main()
{
	c_p_p();
	int ac=0,wa=0,tl=0,re=0;
	w(t)
	{
		string str;
		cin>>str;
		if(str=="AC")++ac;
		else if(str=="WA")++wa;
		else if(str=="TLE")++tl;
		else ++re;
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tl<<endl;
	cout<<"RE x "<<re<<endl;
	return 0;
}
	

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int n,s,t,ans,bl;
vector<int> v[100005],path;
bool dfs(int x,int fa){
    path.pb(x);
    if(x==t) return 1;
    rap(i,0,v[x].size()){
        int to=v[x][i];
        if(to!=fa) {
            if(dfs(to,x)) return 1;
        }
    }
    path.pop_back();
    return 0;
}
int run(int x,int fa){
    int ret=0;
    rap(i,0,v[x].size()){
        int to=v[x][i];
        if(to==bl||to==fa) continue;
        ret=max(ret,run(to,x)+1);
    }
    return ret;
}
int main()
{
    scanf("%d%d%d",&n,&s,&t);
    rap(i,1,n){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        v[t1].pb(t2);v[t2].pb(t1);
    }
    dfs(s,0);
    int len=path.size();
    //bl=path[len/2];
    int ans=0;bool flg=1;
    rap(i,0,v[s].size()) if(v[s][i]!=t) flg=0;
    rap(i,0,len/2){
        int x=path[i];
        if(i) bl=path[i-1];
        int p=(i+1==len?0:path[i+1]);
        ans=max(ans,run(path[i],p)+len-i-1);
    }
    printf("%d\n",flg?0:ans-1);
    return 0;
}

Measured memory_bytes: 11256
# -*- coding UTF-8 -*-
import sys

N = int(input())
F = int(N/7)
F *= 7

if N % 7 == 0:
    print('Yes')
    sys.exit()
if N % 4 == 0:
    print('Yes')
    sys.exit()

while F-7 >= 0:
    if (N-F) % 4 == 0:
        print('Yes')
        sys.exit()
    else:
        F -= 7
print('No')


Measured memory_bytes: 3060
N, M, X = map(int, input().split())
C = []
A = []
for i in range(N):
    line = list(map(int, input().split()))
    C.append(line[0])
    A.append(line[1:])

limit = 2 ** N
ans = (10 ** 5) * 13
for p in range(limit):
    t = 1
    U = [0] * M
    cost = 0
    for i in range(N):
        if p & t > 0:
            cost += C[i]
            for j in range(M):
                U[j] += A[i][j]
        t <<= 1
    if all([su >= X for su in U]):
        ans = min(cost, ans)

if ans == (10 ** 5) * 13:
    print('-1')
else:
    print(ans)


Measured memory_bytes: 68876
#include <stdio.h>
 
int main(void) {
    int i,j,k,n,b,f,r,v,p[4][3][10]={0};
    char fence[]="####################";
    scanf("%d",&n);
    while (n--){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        p[b-1][f-1][r-1]+=v;
    }
    for (i=0;i<4;i++){
        for (j=0;j<3;j++){
            for (k=0;k<10;k++){
                printf(" %d",p[i][j][k]);
            }
            printf("%c",'\n');
        }
        if (i!=3) printf("%s\n",fence);
    }
    return 0;
}


Measured memory_bytes: 2044
N = int(input())
X,Y = [],[]
for _ in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
inf = 10**10

d = {}
for i in range(N):
    for j in range(i+1,N):
        if X[i] > X[j]:
            r,l = i,j
        elif X[i] == X[j]:
            if Y[i] > Y[j]:
                r,l = i,j
            else:
                r,l = j,i
        else:
            r,l = j,i
        k = (X[r]-X[l],Y[r]-Y[l])
        if k in d.keys():
            d[k] += 1
        else:
            d[k] = 1

if N == 1:
    print(1)
else:
    print(N-(max(d.values())))

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int a,b,c;
int ans;
int flag;
int main()
{
	cin>>a>>b;
	for(int i=1;i<=3;i++)
		if((a*i*b)%2==1)
		{
			flag=1;
			break;
		}
	if(flag==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()

	answer := getAnswer(n)
	if answer {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

func getAnswer(n int) bool {
	if n > 81 {
		return false
	}
	for i := 9; i >= 1; i-- {
		if n%i == 0 && n/i <= 9 {
			return true
		}
	}
	return false
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define pqueue priority_queue
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

signed main(){
    typedef pair<int,int> P;
    int N,K;
    cin>>N>>K;
    string S;
    while(N>0){
        S.push_back('0'+(N%K));
        N/=K;
    }
    // rep(0,S.size()){
    //     cout<<S.at(S.size()-i-1);
    // }
    // cout<<endl;
    cout<<S.size()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;


int main(){
    int week;
    cin >> week;
    double money =100;

    for(int i=0; i<week; i++){
        money=money * 1.05;
        money+=0.999;
        money=int(money);
    }
    printf("%d\n",int(money)*1000);
}

Measured memory_bytes: 1144