akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <unordered_map>
#include <sstream>

using namespace std;

vector< std::string > split( const std::string &str, char delm )
{
	std::vector< std::string > v;
	std::stringstream ss( str );
	std::string buffer;
	while ( std::getline( ss, buffer, delm ) )
	{
		if ( buffer == "A" )
			buffer = "1";
		else if ( buffer == "J" )
			buffer = "11";
		else if ( buffer == "Q" )
			buffer = "12";
		else if ( buffer == "K" )
			buffer = "13";

		v.push_back( buffer );
	}

	return v;
}

std::string maxthree( std::unordered_map< std::string, int > ump )
{
	if ( ump.size() == 2 )
	{
		return "full house";
	}
	else 
	{
		return "three card";
	}
}

std::string maxone( std::unordered_map< std::string, int > ump )
{
	array< int, 5 > ar;
	int i = 0, tmp = 0;
	auto itr = ump.begin();
	const char * ch;

	for ( ; itr != ump.end() ; itr++ )
	{
		ch = itr->first.c_str();
		ar[i] = atoi( ch );
		i++;
	}

	for ( int j = 0 ; j < 5 ; j++ )
	{
		for ( int k = j+1 ; k < 5 ; k++ )
		{
			if ( ar[j] > ar[k] )
			{
				tmp = ar[j];
				ar[j] = ar[k];
				ar[k] = tmp;
			}
		}
	}

	if ( ar[0]+1 == ar[1] && ar[0]+2 == ar[2] && ar[0]+3 == ar[3] && ar[0]+4 == ar[4] )
	{
		return "straight";
	}
	else 
	{
		if ( ar[0] == 1 && ar[1] == 10 && ar[2] == 11 && ar[3] == 12 && ar[4] == 13 )
			return "straight";
		else 
			return "null";
	}
}

std::string maxtwo( std::unordered_map< std::string, int > ump )
{
	if ( ump.size() == 4 )
	{
		return "one pair";
	}
	else 
	{
		return "two pair";
	}
}

int main()
{
	int max = 0;
	vector< std::string > str_v;
	unordered_map< std::string, int > ump;
	string str;

	while ( cin >> str )
	{
		str_v = split( str, ',' );	
		for ( int i = 0 ; i < 5 ; i++ )
		{
			ump[str_v[i]]++;
		}

		auto itr = ump.begin();
		for ( ; itr != ump.end() ; itr++ )
		{
			if ( itr->second > max )
			{
				max = itr->second;
			}
		}

		if ( max == 1 )
			cout << maxone( ump ) << endl;
		else if ( max == 2 )
			cout << maxtwo( ump ) << endl;
		else if ( max == 3 )
			cout << maxthree( ump ) << endl;
		else if ( max == 4 )
			cout << "four card" << endl;

		max = 0;
		ump.clear();
	}

	return 0;
}

Measured memory_bytes: 3132
n,m=map(int,input().split())

import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[-1 for i in range(n+1)] #自分が親ならグループの人数のマイナス倍を、そうでないなら（元）親の番号を示す

def r(x):   #親は誰？
    if root[x]<0:
        return x
    else:
        
        return r(root[x])

def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    if root[x]>root[y]:
        x,y=y,x
    root[x]+=root[y]
    root[y]=x

for i in range(m):
    x,y,z=map(int,input().split())
    unite(x,y)


g=[0]*(n+1)
for i in range(1,n+1):
    g[r(i)]+=1
ans=0
for i in range(n+1):
    if g[i]>0:
        ans+=1
print(ans)



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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int A, B;
	cin >>A >>B;
	cout <<(A+B)%24 <<endl;
	return 0;
}



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

int main() {
  ll n, a;
  cin >> n;
  vector<ll> total(n + 1);
  rep(i, n) {
    cin >> a;
    total[i + 1] = total[i] + a;
  }

  ll ans = 1e16;
  for (int i = 1; i < n; i++) {
    ans = min(ans, abs(total[i] - (total[n] - total[i])));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>


using namespace std;
int a[200005];
int n,k;
bool check(int mid)
{
	int cnt=0;
	repD(i,n-1,0)
	{
		if(a[i]<=mid)continue;
		int temp=a[i];
		
		cnt+=temp/mid;
		if(cnt>k)return false;
	}	
	return cnt<=k;
}
void solve()
  {

	
	cin>>n>>k;
	int maxm=0;
	int ans;
	rep(i,n)cin>>a[i],maxm=max(maxm,a[i]);
	sort(a,a+n);
	int l=1,r=maxm;
	
	while(l<=r)
	{
		int mid=l+(r-l)/2;
		if(check(mid)){ans=mid;r=mid-1;}
		else l=mid+1;
	}
	cout<<ans;
	

  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


Measured memory_bytes: 5164
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

S = list(input())
d = deque(S)
Q = iin()
Query = [input().split() for _ in range(Q)]
isReversed = False

for i in range(Q):
    if Query[i][0] == '1':
        if isReversed:
            isReversed = False
        else:
            isReversed = True
    else:
        fl = 0

        if Query[i][1] == '1':
            fl = 0
            if isReversed:
                fl = 1
        else:
            fl = 1
            if isReversed:
                fl = 0
        if fl == 0:
            d.appendleft(Query[i][2])
        else:
            d.append(Query[i][2])
if isReversed:
    d.reverse()    
print(''.join(d))



Measured memory_bytes: 47148
n = gets.chomp.to_i
s = gets.chomp.to_s

a = s.scan(/.{1,#{1}}/)

i = 0

while a[i]
    if a[i] == a[i + 1]
        a.delete_at(i)
    else
        i += 1
    end
end

puts a.length

Measured memory_bytes: 8980
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int[] a = new int[2];
		for(int i = 0 ; i < 2 ; i++) a[i] = Integer.parseInt(sc.next());
		sc.close();
		int yono = 0;
		for(int i = 0 ; i < 2 ; i++){
			Arrays.sort(a);
			yono += a[1];
			a[1]--;
		}
		ou.println(yono);
		ou.flush();
	}
}

Measured memory_bytes: 35744
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    int a,b,k; cin >> a >> b >> k;
    cout<<max(a-k,0LL)<<' '<<max(b-(max(k-a,0LL)),0LL);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	ll n,c=0;
	// c is count of pairs before taking new input
	// map second value is occurence of that string previously
	cin>>n;
	unordered_map<string,ll> m;
	string s;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		sort(s.begin(),s.end());
		m[s]++;
		
	}
	for(auto x:m)
	c+=x.second*(x.second-1)/2;
	cout<<c<<endl;
	
	
}

Measured memory_bytes: 10660
N, X, M = map(int, input().split())

I = [-1] * M
A = []
total = 0
while (I[X] == -1):
    A.append(X)
    I[X] = len(A)
    total += X
    X = (X * X) % M

# print(f'{A=}')
# print(f'{I[:20]=}')
# print(f'{total=}')
# print(f'{X=}, {I[X]=}')

c = len(A) - I[X] + 1
s = sum(A[I[X] - 1:])
# print(f'{c=}, {s=}')
ans = 0
if N < len(A):
    ans += sum(A[:N])
else:
    ans += total
    N -= len(A)
    ans += s * (N // c)
    N %= c
    ans += sum(A[I[X] - 1:I[X] - 1 + N])
print(ans)


Measured memory_bytes: 13764
/// Author: Sarfaraz Alam
# include <bits/stdc++.h>
# define pb push_back
# define ll long long

# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG
typedef unsigned long long int ull;
using namespace std;
#include<string>
#include<cmath>
const int N = 1e5 + 7;
const int mod = 1e9 + 7;


int main()
{
    speed;
    #ifdef DEBUGfd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG

    //Code begins
    string str;
    cin>>str;


    int a[26];

    for(int i = 0; i<26; i++)
    a[i] = 0;

    int flag  = 0;

    for(int i = 0; i<str.size(); i++)
    {
      if(a[str[i] - 'a'] == 0)
      a[str[i]-'a'] = 1;
      else
      {
        flag = 1;
        break;
      }
    }

    if(!flag )
    cout<<"yes\n";
    else
    cout<<"no\n";





    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int R;
  cin >> R;
  if(R < 1200){
    cout << "ABC" << endl;
  }
  else if (R < 2800){
    cout << "ARC" << endl;
  }
  else{
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    int N = sc.nextInt();
    String ans = N == 0 ? "0" : "";
    while(N != 0){
      if(N%2 != 0){
        ans = "1"+ans;
        N--;
      }else{
        ans = "0"+ans;
      }
      N /= -2;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 2e3 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

ll fr[maxN];
int n;

void agre(int le, int ri) {
	fr[le]++, fr[ri]--;
}

int inve(int w) {
	return n - 1 - w;
}

void ranguito(int le, int ri, int strt) {
	int tama = ri - le + 1;
	int uno = tama / 2;
	int dos = tama - uno;
	agre(strt, strt + uno), agre(strt, strt + dos);
}

void consid(int w, int x, int y) {
	if(w * 2 == x + y) return agre(0, w + 1), agre(0, n - w);
	if(w * 2 > x + y) w = inve(w), x = inve(x), y = inve(y), swap(x, y);
	//LOG << w << ' ' << x << ' ' << y << '\n';
	int dst = abs(x - w), ini = y + 1;
	agre(dst + 2, dst + 2 + (n - ini)), agre(0, w + 1), agre(0, dst + 1);
	ranguito((w <= x? x + 1: w + dst + 1), y, dst + 1);
}

void prt() {
	for(ll i = 0, ct = 0; i < n; i++) {
		ct += fr[i];
		if(i) LOG << ct << ' ';
	}
	LOG << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	int x, y;
	cin >> n >> x >> y, x--, y--;
	//consid(3, x, y);
	//prt();exit(0);
	for(int i = 0; i < n; i++) {
		consid(i, x, y);
	}

	for(ll i = 0, ct = 0; i < n; i++) {
		ct += fr[i];
		if(i) cout << ct / 2 << '\n';
	}
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	static final Scanner s = new Scanner(System.in);
	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}
	public static void main(String[]__){
		long n=s.nextInt(),a=s.nextInt(),b=s.nextInt();
		long v=(a+b*(n-1))-(a*(n-1)+b);
		System.out.println(v<0?0:v+1);
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
using namespace std;
typedef long long ll;
 vector<pair<ll,ll>> P;

 int N,A,B,C; int l[1100]; int ans=10e7;

 void dfs(int a,int b,int c,int d,int n){
  if(n==N){
    if(a==0||b==0||c==0) return;
    int key = abs(a - A) + abs(b - B) + abs(c - C) + 10 * (d - 3);
		ans = min(ans, key);
		return;
	}
	dfs(a, b, c, d, n + 1);
	dfs(a + l[n], b, c, d + 1, n + 1);
	dfs(a, b + l[n], c, d + 1, n + 1);
	dfs(a, b, c + l[n], d + 1, n + 1);
 }

  
 int main(){
   cin >> N >> A >> B >> C;
    for(int i=0;i<N;i++) cin >> l[i];
   dfs(0,0,0,0,0);
   cout << ans << endl;
 }
   

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#define SIZE 1000005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int A[SIZE],B[SIZE];
int px[SIZE],py[SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++) scanf("%d",&A[i]),A[i]--;
	for(int i=0;i<m;i++) scanf("%d",&B[i]),B[i]--;
	memset(px,-1,sizeof(px));
	memset(py,-1,sizeof(py));
	ll ret=1;
	for(int i=0;i<n;i++)
	{
		if(px[A[i]]!=-1)
		{
			puts("0");
			return 0;
		}
		px[A[i]]=i;
	}
	for(int i=0;i<m;i++)
	{
		if(py[B[i]]!=-1)
		{
			puts("0");
			return 0;
		}
		py[B[i]]=i;
	}
	ll zx=0,zy=0;
	for(int i=n*m-1;i>=0;i--)
	{
		if(px[i]!=-1)
		{
			if(py[i]==-1)
			{
				ret=ret*zy%MOD;
				zx++;
			}
			else zx++,zy++;
		}
		else
		{
			if(py[i]!=-1)
			{
				ret=ret*zx%MOD;
				zy++;
			}
			else
			{
				ll zan=zx*zy-(n*m-i-1);
				ret=ret*zan%MOD;
			}
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 10368
function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var n = parseInt(input[0][0]);
    var S = input[1].map(e => parseInt(e, 10));
    var q = parseInt(input[2][0]);
    var T = input[3].map(e => parseInt(e, 10));
    const lowerBound = (arr, n) => {
        let first = 0, last = arr.length - 1, middle;
        while (first <= last) {
            middle = 0 | (first + last) / 2;
            if (arr[middle] < n) first = middle + 1;
            else last = middle - 1;
        }
        return first;
    }
    var tmp;
    var ans = 0;
    for (var i = 0; i < q; i++){
        tmp = lowerBound(S, T[i]);
        if (S[tmp] === T[i]) ans++;
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 


Measured memory_bytes: 32428
n = int(input())

l = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]

def dfs(res, i):
    if len(res) >= n:
        print(res)
        return
    for k in range(i):
        dfs(res+l[k], i)
    dfs(res+l[i], i+1)

dfs("", 0)

Measured memory_bytes: 4412
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

unsigned long ar[100000];

int main(void) {
	int n;
	unsigned long k;
	unsigned long a, b;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		ar[a - 1] += b;
	}
	a = 0;
	for (int i = 0; i < 100000; i++) {
		a += ar[i];
		if (a >= k) {
			cout << i + 1 << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

const ll limit = 3234566667;

void dfs(ll cur, vector<ll> &lunlun) {
    if (cur > limit) return;

    lunlun.push_back(cur);
    
    if (cur % 10 > 0) dfs(cur * 10 + (cur % 10 - 1), lunlun);
    dfs(cur * 10 + (cur % 10), lunlun);
    if (cur % 10 < 9) dfs(cur * 10 + (cur % 10 + 1), lunlun);
}

int main() {
    int K; cin >> K;
    vector<ll> lunlun;
    for (ll i = 1; i <= 9; i++) {
        dfs(i, lunlun);
    }
    sort(lunlun.begin(), lunlun.end());
    cout << lunlun[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=3005;
struct Node{
    int a,b;
}p[max_n];
int n,T;
int pre[max_n][max_n],suf[max_n][max_n];
int main(){
    scanf("%d%d",&n,&T);
    for(int i=1;i<=n;i++)scanf("%d%d",&p[i].a,&p[i].b);
    pre[0][0]=0;
    int sum=0;
    for(int i=1;i<=n;i++){
        sum+=p[i].a;
        for(int j=min(sum,T-1);j>=0;j--){
            pre[i][j]=pre[i-1][j];
            if(j>=p[i].a)pre[i][j]=max(pre[i][j],pre[i-1][j-p[i].a]+p[i].b);
        }
    }
    sum=0;
    suf[n+1][0]=0;
    for(int i=n;i>=1;i--){
        sum+=p[i].a;
        for(int j=min(sum,T-1);j>=0;j--){
            suf[i][j]=suf[i+1][j];
            if(j>=p[i].a)suf[i][j]=max(suf[i][j],suf[i+1][j-p[i].a]+p[i].b);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=T-1;j++)ans=max(ans,pre[i-1][j]+suf[i+1][T-1-j]+p[i].b);
    }
    printf("%d\n",ans);
    return 0;
}

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

int main(){
  int X, Y;
  cin >> X >> Y;
  for(int i = 0; i < 100000; i++){
    if(4 * i > Y){
      break;
    }
    if(i > X){
      break;
    }
    if((Y - 4 * i) / 2 == X - i && (Y - 4 * 1) % 2 == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int main()
{
	int n, x, t, a = 0;
	cin >> n >> x >> t;
	if((n % x) != 0){
		a = n / x;
		a += 1;
		cout << a * t;
		} 
	else{
		a = n / x;
		cout << a * t;
		}
return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#define rep(i,n)  for(int i=0;i!=(n);++i)

using namespace std;

typedef long long ll;

int main(){
    int N;
    scanf("%d",&N);
    ll H[N];

    rep(i,N)scanf("%lld",H+i);

    ll h=H[0]-1;
    bool flag=true;

    for(int i=0;i!=N-1;++i){
        if(h<=H[i+1]-1){
            h=H[i+1]-1;
        }else if(h<=H[i+1]){
            h=H[i+1];
        }else{
            flag=false;
            break;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    



}

Measured memory_bytes: 4468
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int n , count , que , max , min;
    long long sum;
    cin >> n;
    count = 0;
    sum = 0;
    min = 2000001;
    max = -2000001;
    while ( count < n ){
        cin >> que;
        sum = sum + que ;
        if ( que < min){
            min = que;
        }
        if ( que > max){
            max = que;
        }
        count++;
    }
    //printf("%d %d %ld\n", min, max, sum);
    cout << min << " " << max << " " << sum << endl;
}


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

class Program
{
    static void Main(string[] args)
    {
        var n = Console.ReadLine();

        if(n[n.Length - 1] == '3')
        {
            Console.WriteLine("bon");
        }
        else if (n[n.Length - 1] == '0' || n[n.Length - 1] == '1' || n[n.Length - 1] == '6' || n[n.Length - 1] == '8')
        {
            Console.WriteLine("pon");
        }
        else
        {
            Console.WriteLine("hon");
        }
    }
}

Measured memory_bytes: 25880
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, *X = list(map(int, read().split()))

X = np.array(X)
P = X.sum() // N

ans = 10**8 + 7

for i in range(-1, 2):
    acc = X - (P + i)
    acc = acc**2
    acc = acc.sum()

    ans = min(ans, acc)

print(ans)


Measured memory_bytes: 12424
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	//#ifndef ONLINE_JUDGE
	//#endif
	int s=0;
	string k;
	cin>>k;
	for(int i=0;i<k.size();i++)
		s+=k[i]-'0';
	cout<<(s%9?"No":"Yes");
	return 0;
}

Measured memory_bytes: 3744
N = gets.to_i
A = gets.split.map(&:to_i)
LIMIT = 10 ** 8

if A.first >= 2
  puts -1
  exit
end

up_sum = 1
down_sum = A.sum
ans = 0

A.each_with_index do |a, idx|
  if up_sum <= 0
    puts -1
    exit
  end

  ans += (up_sum <= down_sum) ? up_sum : down_sum

  if idx < N
    up_sum = 2 * (up_sum - a)
    up_sum = down_sum if up_sum > down_sum
    down_sum -= a
  end
end

if up_sum < A.last
  puts -1
  exit
end

puts ans


Measured memory_bytes: 20724
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b,s;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
        s=0;
        s=a*b;
        if(s%2==0)
        {
            cout<<"Even"<<endl;
        }
        else
            cout<<"Odd"<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>a>>b>>c>>x;
    rep(i,a+1){
        rep(j,b+1){
            rep(k,c+1){
                if(500*i+100*j+50*k==x)ans++;
            }
        }
    }
    Cout(ans);
    return 0;
}


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

#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct S {
    ll c0, c1, cinv;
};

S op(S l, S r) {
    return S{l.c0 + r.c0, l.c1 + r.c1, l.cinv + r.cinv + l.c1 * r.c0};
}

S e() { return S{0ll, 0ll, 0ll}; }

using F = bool;

S mapping(F l, S r) {
    if (l) {
        return S{r.c1, r.c0, r.c0 * r.c1 - r.cinv};
    } else {
        return r;
    }
}

F composition(F l, F r) { return l ^ r; }
F id() { return false; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    V<int> A(N);
    V<S> init_A(N);
    rep(i, N) {
        cin >> A[i];
        init_A[i] = S{!A[i], A[i], 0};
    }

    lazy_segtree<S, op, e, F, mapping, composition, id> seg(init_A);
    while (Q--) {
        int t, l, r;
        cin >> t >> l >> r;
        --l;
        if (t == 1) {
            seg.apply(l, r, true);
        } else {
            auto res = seg.prod(l, r);
            cout << res.cinv << '\n';
        }
    }

    return 0;
}

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

int main()
{
    string a, b;
    cin >> a >> b;
    string ans = "";
    int n = a.length(), m = b.length();

    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            // if (i == 0 || j == 0)
            //     dp[i][j] = 0;
            if (a[i - 1] == b[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    // cout << dp[n][m] << endl;
    int l = dp[n][m];
    int i = n, j = m;
    while (l > 0)
    {
        if (a[i - 1] == b[j - 1])
        {
            ans.push_back(a[i - 1]);
            l--, i--, j--;
        }
        else
        {
            if (dp[i][j - 1] > dp[i - 1][j])
            {
                j--;
            }
            else
            {
                i--;
            }
        }
    }
    reverse(ans.begin(), ans.end());

    cout << ans << endl;
    // cout << rec(val, weight, n, w);
    return 0;
}

Measured memory_bytes: 38188
# N本の竹、必要な3本の竹の長さはABC
N, A, B, C = map(int, input().split())
# 現在持っているそれぞれの竹の長さ（最大8本）
l = [int(input()) for i in range(N)]
INF = 10**9


def dfs(cur, a, b, c):
    # 全ての竹を使用している時だけ求める？
    if cur == N:
        # min(a, b, c) > 0 は最低でも竹を作るには1本以上の竹が必要なため
        if min(a, b, c) > 0:
            return abs(a-A)+abs(b-B)+abs(c-C)-30
        else:
            return INF

    ret0 = dfs(cur + 1, a, b, c)
    #print(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    #print(cur + 1, a + l[cur], b, c)
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    #print(cur + 1, a, b + l[cur], c)
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    #print(cur + 1, a, b, c + l[cur])
    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int maxint=100005;
vector < int > lian[maxint];
int ques;
int v[maxint],d[maxint],c[maxint];
void myinit(){
	cin >> n >> m;
	for (int i=1;i<=m;i++){
		int x,y;
		cin >> x >> y;
		lian[x].push_back(y);
		lian[y].push_back(x);
	}
	cin >> ques;
	for (int i=1;i<=ques;i++){
		int x,y,z;
		cin >> x >> y >> z;
		v[ques+1-i]=x;
		d[ques+1-i]=y;
		c[ques+1-i]=z;
	}
//	for (int i=1;i<=ques;i++){
//		cout << v[i] << ' ' << d[i] << ' ' << c[i] << endl;
//	}
//	for (int i=1;i<=n;i++){
//		cout << i << ':';
//		for (int j=0;j<lian[i].size();j++){
//			cout << lian[i][j] << ' ';
//		}
//		cout << endl;
//	}
}
queue < pair<int,int> > q;
int a[maxint];
bool used[maxint];
void CLEAR(){
	while (!q.empty()){
		q.pop();
	}
}
void go(int x){
//	cout << v[x] << ' ' << d[x] << ' ' << c[x] << endl;
	CLEAR();
	if (used[v[x]]) return;
	q.push(make_pair(v[x],0));
	used[v[x]]=true;
	a[v[x]]=c[x];
	while (!q.empty()){
		int ve=q.front().first;
		int bu=q.front().second;
		q.pop();
		if (bu==d[x]) break;
		for (int i=0;i<lian[ve].size();i++){
			int tmp=lian[ve][i];
			q.push(make_pair(tmp,bu+1));
//			cout << "push:" << tmp << ' ' << bu+1 << endl;
			if (!used[tmp]) a[tmp]=c[x];
			used[tmp]=true;
		}
	}
//	for (int i=1;i<=n;i++) cout << a[i] << ' ';
//	cout << endl;
}
void func1(){
	myinit();
	for (int i=1;i<=ques;i++) go(i);
	for (int i=1;i<=n;i++) cout << a[i] << endl;
}
int minDis[maxint];
void dfs(int x,int D,int Din,int Cin){
//	cout << x << ' ' << D << ' ' << Din << ' ' << Cin << ' ' << minDis[x] << endl;
	if (a[x]==0){
		a[x]=Cin;
	}
//	cout << "pass\n";
//	cout << "pass\n";
	if (Din-D<=minDis[x]) return;
	minDis[x]=Din-D;
	if (D==Din) return;
//	cout << "pass\n";
	for (int i=0;i<lian[x].size();i++){
		dfs(lian[x][i],D+1,Din,Cin);
	}
}
void func2(){
	myinit();
	memset(minDis,0,sizeof(minDis));
	for (int i=1;i<=ques;i++){
		dfs(v[i],0,d[i],c[i]);
	}
	for (int i=1;i<=n;i++) cout << a[i] << endl;
}
void open_file(){
//	freopen("Splatter_testdata1.in","r",stdin);
//	freopen("Splatter_testdata2.in","r",stdin);
}
int main(){
	open_file();
	func2();
	return 0;
}

Measured memory_bytes: 8440
#include <iostream>
using namespace std;
typedef long long int ll;
ll n, a[3001];
ll dp[3001][3001];
bool odd;
int main()
{
    scanf("%lld",&n);
    for(int i = 0; i < n; i++)scanf("%lld",&a[i]);
    odd = n%2;
    if(odd)
    {
        for(int i = 0 ; i<n;i++)
        {
            dp[i][i] = a[i];
        }
    }
    else
    {
        for(int i = 0 ; i<n;i++)
        {
            dp[i][i] = -a[i];
        }
    }
    //start dp
    for(int i = 1; i <= n-1; i++)
    {
        for(int l = 0; l+i<n; l++)
        {
            ll r = l+i;
            if((n-i)%2)
            {
                dp[l][r] = max(dp[l+1][r]+a[l],dp[l][r-1]+a[r]);
            }
            else
            {
                dp[l][r] = min(dp[l+1][r]-a[l],dp[l][r-1]-a[r]);
            }
        }
    }
    printf("%lld\n",dp[0][n-1]);
}


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

typedef long long int ll;

int main()
{
    ll n, k, r, s, p, ans = 0;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    for(ll i = 0;i < k;i++){
        char bt = 'a';
        for(ll j = i;j < t.size();j += k){
            if(t[j] != bt){
                if(t[j] == 'r'){
                    ans += p;
                }
                else if(t[j] == 's'){
                    ans += r;
                }
                else{
                    ans += s;
                }
                bt = t[j];
            }
            else{
                bt = 'a';
            }
        }
    }

    cout << ans;

    return 0;
}

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

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

	double sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}
	int ave = round(sum / n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(a[i] - ave)*abs(a[i] - ave);
	}
	cout << ans << endl;

	return 0;
}

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

typedef long long ll;

string s1;
string s2;
ll n1;
ll n2;
ll memo[3001][3001];
char mm[3001][3001];
int mm1[3001][3001];

ll func(ll i,ll j)
{
	if(i == n1-1 && j == n2-1)
	{
		if(s1[i] == s2[j])
			{
				mm[i][j]=s1[i];
				mm1[i][j]=0;
				return 1;
			}
		else
			return 0;
	}
	if(i == n1-1 || j==n2-1)
	{
		if(s1[i] == s2[j])
			{
				mm[i][j]=s1[i];
				mm1[i][j]=0;
				return 1;
			}
		else if(i == n1-1)
			return func(i,j+1);
		else
			return func(i+1,j);
	}

	if(memo[i][j]!=-1)
		return memo[i][j];
	
	if(s1[i] == s2[j])
	{
		memo[i][j]=1+func(i+1,j+1);
		mm[i][j]=s1[i];
		mm1[i][j]=0;
		return memo[i][j];
	}
	else
	{
		ll tt=func(i+1,j);
		ll t1=func(i,j+1);
		memo[i][j]=max(tt,t1);
		if(tt>t1)
			mm1[i][j]=1;
		else
			mm1[i][j]=2;
		return memo[i][j];
	}
 }


int main() 
{
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
     		//freopen("input.txt", "rt", stdin);
 	#endif
	cin >> s1;
	cin >> s2;
	s1+='a';
	s2+='z';
	n1=s1.length();
	n2=s2.length();

	for(int i=0;i<3001;i++)
	{
		for(int j=0;j<3001;j++)
		{
			memo[i][j]=-1;
			mm[i][j]='1';
			mm1[i][j]=-1;
		}
	}
	
	ll vv = func(0,0);
	int i=0;
	int j=0;
	int count=0;
	while(mm1[i][j]!=-1)
	{
		if(mm1[i][j]==0)
		cout<<mm[i][j];
		if(mm1[i][j]==0)
		{
			i++;
			j++;
		}
		else if(mm1[i][j]==1)
		{
			i++;
		}
		else
		{
			j++;
		}
	}
	cout<<"\n";
 	return 0;	
}


Measured memory_bytes: 114944
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N;
  cin>>N;
  string S,T;
  cin>>S>>T;
  
  string ans;
 for (int i =0; i < N; i++){
  char a,b;
  a = S[i];
  b = T[i];
  ans += a;
  ans += b;
 }
 cout<<ans<<endl;

}

Measured memory_bytes: 256
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long int dp[2020][2020], arr1[2020], arr2[2020];
int n,i,j,k,x,y,ans,curr,temp,m;
long long int rose;
long long int calc()
{
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            dp[i][j] = 0;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (arr1[i - 1] == arr2[j - 1])
                dp[i][j] = 1 + dp[i][j - 1] + dp[i - 1][j] % mod;
            else
            {
                dp[i][j] = ((dp[i][j - 1] + dp[i - 1][j]) % mod) - dp[i - 1][j - 1];
                if(dp[i][j] < 0)
                    dp[i][j] += mod;
            }
        }
    }

    return dp[n][m] % mod;
}
int main()
{
    cin >> n >> m;
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr1[i]);
    }
    for(i=0;i<m;i++)
    {
        scanf("%d",&arr2[i]);
    }
    rose = calc();
    cout << rose+1 << "\n";
    return 0;
}


Measured memory_bytes: 31872
n, k = map(int,input().split())
if n % k == 0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
    half = k//2
    while c > half:
        c = abs(c-k)
    l.append(c)
    print(min(l))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;


int main(void) {
    int a, b, m;
    cin >> a >> b >> m;
    
    vector<int> a_ary;
    vector<int> b_ary;
    
    int m_ary[m][3];
    
    int z = 0;
    for (int i = 0; i < a; i++) {
        cin >> z;
        a_ary.push_back(z);
    }
    
    for (int i = 0; i < b; i++) {
        cin >> z;
        b_ary.push_back(z);
    }
    
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> m_ary[i][j];
        }
    }
    
    vector<int> totals;
    
    totals.push_back(*min_element(a_ary.begin(), a_ary.end()) + *min_element(b_ary.begin(), b_ary.end()));
    
    for (int i = 0; i < m; i++) {
        totals.push_back(a_ary[m_ary[i][0] - 1] + b_ary[m_ary[i][1] - 1] - m_ary[i][2]);
    }
    
    cout << *min_element(totals.begin(), totals.end()) << endl;
    
    return 0;
}

Measured memory_bytes: 2936
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
     int N=int.Parse(str[0]);
     int L=int.Parse(str[1]);
     int[] apples=new int[N];
      int ans=0;
  
     for(int i=0;i<N;i++){
       apples[i]=L+i;
     }
    if(Array.IndexOf(apples,0)!=-1){
      ans=apples.Sum();
    }else if(L>0){
      ans=apples.Sum()-apples[0];
    }else{
      ans=apples.Sum()-apples[N-1];
    }
      Console.WriteLine(ans);
    }
    
  }

}

Measured memory_bytes: 27704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0xfff;
const int maxn = 100005;

int a[200] = {0};
int main()
{
    int x, n;
    cin >> x >> n;
    int b;
    for (int i = 1; i <= n;i++)
    {
        cin >> b;
        a[b]++;
    }
    int left=0, right=111;
    int i, j;
    for (i = x; i >= 1;i--)
    {
        if(!a[i]) {
            break;
        }
    }
    for ( j = x; j <= 100;j++)
    {
        if(!a[j]) {
            break;
        }
    }
    if(j-x < x-i)
        cout << j <<endl;
    else if(j-x == x-i)
        cout << i <<endl;
    else {
        cout << i<< endl;
    }
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
s = input()

west = [0]*n
east = [0]*n

count =0
for i in range(n):
  if s[i] == 'W':
    count += 1    
  west[i] = count  

count =0
for i in range(n):
  if s[-i-1] == 'E':
    count += 1    
  east[-i-1] = count  

change = [0]*n
for i in range(n):
  if i==0:
    change[i] = east[1]
  elif i== n-1:
    change[i] = west[-2]
  else:
    change[i]= (west[i-1] + east[i+1])

print(min(change))  

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

int s2i(string str){
  stringstream ss;
  int a;
  ss << str;
  ss >> a;
  return a;
}
int s2min(string str){
  int res = 0;
  res += s2i(str.substr(0, 2)) * 60;
  res += s2i(str.substr(2, 2));
  return res;
}

int main(void){
  int n;
  string p, q;
  while(cin >> n >> p >> q, n){
    vector<int> times(24*60, 0);

    for(int i=0; i < n; i++){
      int com; cin >> com;
      vector<int> tmp(24*60+100, 1);
      for(int j=0; j < com; j++){
	string a, b; cin >> a >> b;
	for(int k=s2min(a); k < s2min(b); k++){
	  tmp[k] = 0;
	}
	/*
	for(int k=0; k < s2min(a); k++){
	  tmes[k] = 1;
	}
	for(int k = s2min(b); k < (signed int)times.size(); k++){
	  times[k] = 1;
	}
	*/
      }
      for(int j = 0; j < (signed int)times.size(); j++){
	if(tmp[j] == 1){
	  times[j] = 1;
	}
      }
    }
    int ans = 0;
    int tmp = 0;
    for(int i=s2min(p); i < s2min(q); i++){
      if(times[i] != 0){
	tmp++;
      }else{
	ans = max(ans, tmp);
	tmp = 0;
      }
    }
    ans = max(ans, tmp);
    
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,a,b,c,d,cnt=0,pk;
     cin>>a>>b>>c>>d;
     for(int i=0;i<=a;i++)
     {
         for(int j=0;j<=b;j++)
         {
             for(int k=0;k<=c;k++)
             {
                 pk=i*500+j*100+k*50;
                 if(pk==d)
                    cnt++;
             }
         }
     }
     cout<<cnt<<endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void) {
  bool prime[1000000];
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= 1000000; i++) {
    if (prime[i]) {
      for (int j = 2 * i; j <= 1000000; j += i) {
        prime[j] = false;
      }
    }
  }

  while (true) {
    int n, p;
    cin >> n >> p;
    if (n == -1 && p == -1)
      break;

    int ii = 0;
    VI pp, ppp;
    pp.clear();
    ppp.clear();
    for (int i = n + 1; ii < p; i++) {
      if (prime[i]) {
        pp.push_back(i);
        ii++;
      }
    }

    REP(i, p) FOR(j, i, p) { ppp.push_back(pp[i] + pp[j]); }
    sort(ALL(ppp));

    /*REP(i, 100) {
      if(i != 0 && i % 10 == 0) cout << endl;
      cout << ppp[i] << " ";
    }*/

    cout << ppp[p - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 4184
#include <iostream>

using namespace std;

int main()
{
  int a,s,ans;
  cin >> a;
  int b[a];
  ans = -1;
  for(int i = 0;i<a+1;i++){
    cin >> b[i];
    b[i]--;
  }
  s = 0;
  for(int i=0;i<a;i++){
    if(b[s]==1){
      ans = i+1;
      break;
    }
    else s = b[s];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4024
#include <stdio.h>
#include <math.h>
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if(fabs(a+b)/2 != (int)fabs(a+b)/2)
        printf("IMPOSSIBLE\n");
    else
        printf("%d\n", (int)fabs(a+b)/2);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    i1, i2 = map(int, input().split())
    b.append(i1)
    c.append(i2)
d = [0]*(10**5 + 1)
for i in a:
    d[i] = d[i] + 1
s = sum(a)
for i in range(q):   
    s = s - d[b[i]]*b[i] + d[b[i]]*c[i] 
    d[c[i]] = d[c[i]] + d[b[i]]
    d[b[i]] = 0
    print(s)

Measured memory_bytes: 21848
from itertools import product
from heapq import heappop, heappush

x,y,z,k = map(int,input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)
if x * y * z <= 3000:
    lst = sorted([sum(i) for i in product(a,b,c)], reverse=True)
    [print(i) for i in lst[:k]]
    exit()

idx = [0,0,0]
heap = []
xxx = [x,y,z]

aaa = idx[0] if idx[0]+1 >= x else idx[0] + 1
bbb = idx[1] if idx[1]+1 >= y else idx[1] + 1
ccc = idx[2] if idx[2]+1 >= z else idx[2] + 1
heappush(heap, [-(a[aaa] + b[idx[1]] + c[idx[2]]), [1, 0, 0], 0])
heappush(heap, [-(a[idx[0]] + b[bbb] + c[idx[2]]), [0, 1, 0], 1])
heappush(heap, [-(a[idx[0]] + b[idx[1]] + c[ccc]), [0, 0, 1], 2])
print(a[idx[0]] + b[idx[1]] + c[idx[2]])
doc = {}
for _ in range(min(k-1, x*y*z)):
    score, ix, pos = heappop(heap)
    print(-score)
    for i in range(3):
        tmp = ix.copy()
        tmp[i] = ix[i] if ix[i] + 1 >= xxx[i] else ix[i] + 1
        if ','.join(map(str, tmp)) not in doc:
            doc[','.join(map(str, tmp))] = 1
            score = a[tmp[0]] + b[tmp[1]] + c[tmp[2]]
            # print(idx, ix, score, heap)
            heappush(heap, [-score, tmp, i])

# lst.sort(reverse=True)
# [print(i) for i in lst[:k]]


Measured memory_bytes: 5164
using System;
using System.Linq;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input, ball = "A";
            while((input = Console.ReadLine()) != null) {
                string[] split = input.Split(',');
                if(split.Contains(ball)) {
                    ball = split.First(q => q != ball);
                }
            }
            Console.WriteLine(ball);
        }
    }
}

Measured memory_bytes: 5532
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SIZE 100005
 
 
int main()
{
	string ch;
	cin >> ch;
	if(ch == "SUN") cout << 7 << endl;
	else if(ch == "SAT") cout << 1 << endl;
	else if(ch == "MON") cout << 6 << endl;
	else if(ch == "TUE") cout << 5 << endl;
	else if(ch == "WED") cout << 4 << endl;
	else if(ch == "THU") cout << 3 << endl;
	else if(ch == "FRI") cout << 2 << endl;
	
	
	
	return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif


int main(void)
{
	ll h, w, a, b; cin >> h >> w >> a >> b;

	vector<vector<char>> matrix(h, vector<char>(w, '0'));

	if (a == 1 && b == 1)
	{
		rep(i, 0, h)
			matrix[i][i] = '1';
	}
	else
	{
		rep(i, 0, b)
		{
			rep(j, 0, a)
				matrix[i][j] = '1';
		}
		rep(i, b, h)
		{
			rep(j, a, w)
				matrix[i][j] = '1';
		}
	}

	each(eh, matrix)
	{
		each(e, eh)
			cout << e;
		cout << endl;
	}

	return 0;
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    int n; cin >> n;
    V<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    int sum = pow(3, n);
    int sub = 1;
    for(int i = 0; i < n; i++){
        int cnt = 0;
        if((v[i] - 1) & 1) cnt++;
        if((v[i]) & 1) cnt++;
        if((v[i] + 1) & 1) cnt++;
        if(0 < cnt) sub *= cnt;
    }
    cout << sum - sub << endl;

    return 0;
}


Measured memory_bytes: 4088