akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  vector<int> w(N+2);
  rep(i,N){
    cin >> v[i];
    w[v[i]] = i+1;
  }
  set<int> stl;
  set<int> str;
  ll ans = 0;
  perr(x,1,N+1){
    auto itl = stl.upper_bound(-w[x]);
    auto itr = str.upper_bound(w[x]);
    ll l1=0,l2=0,r1=N+1,r2=N+1;
    //自分より大きい一番近く
    if(itl == stl.end()) l1 = 0;
    else l1 = *itl;
    if(itr == str.end()) r1 = N+1;
    else r1 = *itr;

    //自分より大きい二番目に近く
    if(l1!=0){
      stl.erase(itl);
      itl = stl.upper_bound(-w[x]);
      if(itl != stl.end()) l2 = *itl;
      stl.insert(l1);
    }
    if(r1!=N+1){
      str.erase(itr);
      itr = str.upper_bound(w[x]);
      if(itr != str.end()) r2 = *itr;
      str.insert(r1);
    }
    stl.insert(-w[x]);
    str.insert(w[x]);

    l1=-l1;
    l2=-l2;
    ans += x*(l1-l2)*(r1-w[x]); 
    ans += x*(r2-r1)*(w[x]-l1);
    //if(l1 != 0) ans += x*(l1-l2)*(r1-w[x]);
    //if(r1 != N+1) ans += x*(r2-r1)*(w[x]-l1);
    //cout << x SP l2 SP l1 SP r1 SP r2 SP ans << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10368
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;
string s, p;
int sum, f, add;
int main() {
	getline(cin, s);
	getline(cin, p);
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == p[0]) {
			add = i;
			int j = 0;
			for (; j < p.length(); j++) {
				
				if (s[add++] != p[j])
					break;
				if (add >= s.length())
					add = 0;
			}
			if (j >= p.length())
				f++;
		}
	}
	if (f == 0)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;
constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

#define A 0
#define G 1
#define C 2
#define T 3

int main(void){
    Cin(int, n);
    ll dp[4][4][4];
    For(i, 4) For(j, 4) For(k, 4) dp[i][j][k] = 1; // AGC, GAC, ACG, A*GC, AG*C
    dp[A][G][C] = dp[G][A][C] = dp[A][C][G] = 0;
    
    Rep(n-3){
    ll dpn[4][4][4] = {{{0}}};
        For(i, 4) For(j, 4) For(k, 4) For(l, 4){
            dpn[j][k][l] += dp[i][j][k];
        }
        dpn[A][G][C] = dpn[G][A][C] = dpn[A][C][G] = 0;
        dpn[G][G][C] -= dp[A][G][G];
        dpn[T][G][C] -= dp[A][T][G];
        dpn[G][T][C] -= dp[A][G][T];
        For(i, 4) For(j, 4) For(k, 4) dp[i][j][k] = dpn[i][j][k] % MOD;
    }
    
    ll ans = 0;
    For(i, 4) For(j, 4) For(k, 4) ans = (ans + dp[i][j][k]) % MOD;
    Cout(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main () {
  vector<int> numbers;
  int input;
  bool status = false;

  for (size_t i = 0; i < 2; i++) {
    cin >> input;
    numbers.push_back(input);
  }

  for (size_t i = 1; i <= 3; i++) {
    if(numbers[0] * numbers[1] * i % 2 != 0) {
      status = true;
      break;
    }
  }
  
  cout << (status ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
    static int[][] c;
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n], b = new int[n];
        int[] dif = new int[n];
        long suma = 0, sumb = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            suma += a[i];
        } 
        long D = 0;
        int cnt1 = 0;
        int cnt2 = 0;
        for(int i = 0; i < n; i++){
            b[i] = sc.nextInt();
            sumb += b[i];
            dif[i] = a[i] - b[i];
            if(dif[i] >= 0) cnt1++;
            else D -= dif[i];
        }
        if(suma < sumb){
            System.out.println(-1);
            return;
        }
        Arrays.sort(dif);
        long x = 0;
        int k = n-1;
        while(x < D){
            x += dif[k];
            cnt2++;
            k--;
        }
        System.out.println((n - cnt1 + cnt2));
    }
}   

Measured memory_bytes: 85088
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
double s[1001],t,a,n,x,minn=99999999,maxi;
int main()
{
	cin>>n;
	cin>>t>>a;
	for(int i=1;i<=n;i++)
	  {
	  	cin>>x;
	  	s[i]=abs(a-(t-x*0.006));
	  	if(minn>s[i])
	  	  maxi=i,minn=min(minn,s[i]);
	  }
	cout<<maxi;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N,M,i,j,n;
	int k;
	int temp;
	int mate[100];
	cin>>N>>M;
	for(i=1;i<=N;i++){
		cin>>k;
		mate[i]=k;
	}
	for(j=2;j<=M;j++){
		for(i=1;i<=N-1;i++){
			k=mate[i]%j;
			if(k>mate[i+1]%j){
				temp=mate[i];
				mate[i]=mate[i+1];
				mate[i+1]=temp;
			}
		}
	}
	for(i=1;i<=N;i++){
		cout<<mate[i]<<endl;
	}
	return 0;
}

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

int main() {
    int k, s;
    cin >> k >> s;
    int count = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (0 <= z && z <= k) count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

using Graph = vector<vector<int>>;
int main()
{
  int h, w;
  cin >> h >> w;
  Graph g(h*w);
  char c[21][21];
  int a[21][21];


  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      cin >> c[i][j];
      if(c[i][j] == '.'){
        a[i][j] = 0;
      }else{
        a[i][j] = 1;
      }
    }
  }
  for (int i = 0; i<h; i++){
    for (int j = 0; j<w; j++){
      if (a[i][j] == 1)
        continue;
      if(a[i][j] == 0 && j<w -1 && a[i][j+1] == 0 ){
        g[i * w + j].push_back(i * w + j + 1);
        g[i * w + j + 1].push_back(i * w + j);
      }
      if(a[i][j] == 0 && i<h -1 && a[i+1][j] == 0){
        g[i * w + j].push_back((i+1) * w + j);
        g[(i+1) * w + j].push_back(i * w + j);
      }
    }
  }
  int max = 0;
  for (int i = 0; i < h * w; i++)
  {
    if(a[i/w][i%w] == 1){
      continue;
    }
    queue<int> que;
    vector<int> dist(h * w, -1);
    dist[i] = 0;
    que.push(i);
    while(!que.empty()){
      int b = que.front();
      que.pop();
      for ( int j : g[b])
      {
        if(dist[j]!=-1){
          continue;
        }
        que.push(j);
        dist[j] = dist[b] + 1;
        if(max<dist[j]){
          max = dist[j];
        }
      }
    }
  }
  cout << max << "\n";
  return 0;
}

Measured memory_bytes: 256
#pragma region Macros
// ===========
// include
// ===========
#include <bits/stdc++.h>

using namespace std;

// ===========
// typedef
// ===========
typedef int64_t int64;
typedef vector<int64> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;

// ===========
// conversion
// ===========
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

// ===========
// math
// ===========
template<class T> inline T sqr( T x ){ return x * x; }
inline int64 Factorial( int64 n ){ return n == 0 ? 0 : ( n == 1 ? 1 : Factorial( n - 1) * n  ); }

// ===========
// repetition
// ===========
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a), __length = int(b); i < __length; ++i)

void input(vector<int64> *vec, const int size){ vec->resize(size); rep(i, size) { cin >> vec->at(i); } }
void input(vector<string> *vec, const int size){ vec->resize(size); rep(i, size) { cin >> vec->at(i); } }

#pragma endregion //Macros

int main()
{
    int N;
    cin >> N;
    VI a;
    input(&a, N);

    int count = 0;
    for( int i = 0; i < N; i+=2)
    {
        if( a.at(i) % 2 == 1 )
        {
            ++count;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3596
H,W=map(int,input().split())
grid=[None]*10
for i in range(10):
  grid[i]=list(map(int,input().split()))

for k in range(10):
  for i in range(10):
    for j in range(10):
      if grid[i][k]+grid[k][j]<grid[i][j]:
        grid[i][j]=grid[i][k]+grid[k][j]
        
ans=0
for i in range(H):
  A=list(map(int,input().split()))
  for a in A:
    if a==-1:
      continue
    ans+=grid[a][1]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;

int main(){
    int H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<(H*W)-(h*W+w*H-(h*w))<<endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        h: usize, w: usize,
        s: [Chars; h],
    }

    let mut map = s
        .iter()
        .map(|row| {
            row.iter()
                .map(|c| if *c == '.' { 0 } else { -1 })
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();
    for i in 0..h {
        for j in 0..w {
            if map[i][j] < 0 {
                let i = i as isize;
                let j = j as isize;
                for k in -1..=1 {
                    if i + k < 0 || i + k >= h as isize {
                        continue;
                    }
                    for l in -1..=1 {
                        if j + l < 0 || j + l >= w as isize {
                            continue;
                        }
                        if map[(i + k) as usize][(j + l) as usize] >= 0 {
                            map[(i + k) as usize][(j + l) as usize] += 1;
                        }
                    }
                }
            }
        }
    }
    println!(
        "{}",
        map.iter()
            .map(|row| row
                .iter()
                .map(|c| if *c < 0 {
                    '#'
                } else {
                    std::char::from_digit(*c as u32, 10).unwrap()
                })
                .collect::<String>())
            .join("\n")
    );
}


Measured memory_bytes: 2160
#include <iostream>

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  long long a = 0, b = 0;
  long long maxa = 0, minb = 1e10; 
  for (int i=0; i<n; i++) {
    cin >> a >> b;
    if (a > maxa) {
      maxa = a;
      minb = b;
    }
  }
  cout << maxa + minb << endl;
  return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<int> A(N+1), B(N);
	rep(i, N+1) cin >> A[i];
	rep(i, N) cin >> B[i];
	
	int64_t ans = 0;
	rep(i, N){
		if(B[i] <= A[i]){
			ans += B[i];
		}
		else{
			ans += A[i];
			B[i] -= A[i];
			if(B[i] <= A[i+1]){
				ans += B[i];
				A[i+1] -= B[i];
			}
			else{
				ans += A[i+1];
				A[i+1] = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
from collections import deque

n = int(input())
a = list(map(int,input().split()))
b = deque([a[0]])

for i in range(1,n):
    if i%2==(n-1)%2:
        b.appendleft(a[i])
    else:
        b.append(a[i])
    
print(' '.join(map(str,b)))



Measured memory_bytes: 29248
#include<stdio.h>
int main()
{
	int n,i,f=0;
	scanf("%d",&n);
	char a[n];
	for(i=0;i<n;i++)
	{
	scanf(" %c",&a[i]);
	if(n%2==0&&i>=n/2)
	{
		if(a[i]!=a[i-n/2])
		f=1;
	}	
	}
	if(n%2==1||f==1)
	printf("No\n");
	else
	printf("Yes\n");	
	return 0;
}

Measured memory_bytes: 1644
/*
   Push yourself, because no one else is going to do it for you.
*/
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long int
#define PI 2 * acos(0.0)
#define MAX 10000000000000000
#define in(a) scanf("%d",&a);
#define out(a) printf("%d",a);
#define INF 1000000 
#define M 1000000007
using namespace std;
int main(){ 
   fast_io
   ll a,b,n; 
   cin>>a>>b>>n;
   if(n >= b){
      ll x = b-1;
      ll ans = (a*x)/b;
      cout<<ans<<endl;
   }
   else{
      ll x = n;
      ll ans = (a*n)/b;
      cout<<ans<<endl;
   }
   return 0; 
}  

Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;
	static int[] par, dep, ch;

	static void solve() {
		int[] a=ir.nextIntArray(3);
		out.println((a[0]-a[2])/(a[1]+a[2]));
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


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

int grid[30][30];

inline bool isAtObstacle(int x, int y) {
  return grid[y][x] == 1;
}

inline bool isAtSkiJump(int x, int y) {
  return grid[y][x] == 2;
}

int main() {
  int n, m;
  
  while(cin >> m >> n && n) {
    fill(grid[0], grid[0]+900, 0);
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
	cin >> grid[i][j];
      }
    }
    
    int dp[30][30][2] = {{{}}};
    
    for(int j=0; j<m; j++) {
      if(grid[0][j]==0) { dp[0][j][0] = 1; }
    }
    
    int extra = 0;
    for(int i=0; i<n-1; i++) {
      for(int j=0; j<m; j++) {
	
	// there is no case such that skier is at obstacle.
	if(isAtObstacle(j, i)) continue;
	
	// A skier is at a ski jump.
	if(isAtSkiJump(j, i)) {
	  if(i+2 > n-1) extra += dp[i][j][0];
	  else {
	    if(isAtObstacle(j, i+2)) continue;
	    dp[i+2][j][0] += dp[i][j][0];
	  }
	}
	
	// skiing without jump.
	else {
	  // from the upper left
	  if( j-1 >= 0
	      && !isAtObstacle(j-1, i+1)
	      && !isAtSkiJump (j-1, i+1) ) {
	    dp[i+1][j-1][1] += dp[i][j][0] + dp[i][j][1];
	  }
	  
	  // from the above
	  if( !isAtObstacle(j, i+1) ) {
	    dp[i+1][j][0] += dp[i][j][0] + dp[i][j][1];
	  }
	  
	  // from the upper right
	  if( j+1 < m
	      && !isAtObstacle(j+1, i+1)
	      && !isAtSkiJump (j+1, i+1) ) {
	    dp[i+1][j+1][1] += dp[i][j][0] + dp[i][j][1];
	  }
	}
	
      }
    }
    
    int ans = 0;
    for(int i=0; i<m; i++) {
      ans += dp[n-1][i][0] + dp[n-1][i][1];
    }
    
    cout << ans + extra << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1168
(let ((S (read-line)))
  (labels ((f (str)
             (if (string-equal (subseq str (ash (length str) -1))
                               (subseq str 0 (ash (length str) -1)))
                 (length str)
                 (f (subseq str 0 (- (length str) 2))))))
    (format t "~A~%" (f (if (zerop (mod (length S) 2))
                            (subseq S 0 (- (length S) 2))
                            (subseq S 0 (- (length S) 1)))))))

Measured memory_bytes: 9056
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        int n=ni();
        int[]A=new int[n+1];
        int[]B=new int[n+1];
        int[]C=new int[n+1];
        
        for (int x=1;x<=n;x++) {
            int a=ni();
            A[x]=a+Math.max(B[x-1],C[x-1]);
            a=ni();
            B[x]=a+Math.max(A[x-1],C[x-1]);
            a=ni();
            C[x]=a+Math.max(A[x-1],B[x-1]);
        }
        
        int ans=A[n];
        ans=Math.max(ans,B[n]);
        ans=Math.max(ans,C[n]);
        System.out.println(ans);
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int x,n;
  cin >> x >> n;
  vector<int> p(n);
  int i;
  rep(i,n) cin >> p[i];
  vector<bool> num(2001,false);
  rep(i,n)
  {
    num[p[i]+1000] = true;
  }
  int ans=-1000;
  int dis=1000;
  rep(i,2001)
  {
    if(!num[i])
    {
      int kdis = abs(x-(i-1000));
      if(kdis < dis)
      {
        ans = i-1000;
        dis = kdis;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
/*
___ is a raging sadist.
*/
//Destroy all WA at test 2
// Stay cool
// Pass the 4th wall..

#include "bits/stdc++.h"
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define siz(a) int((a).size())
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define pi 3.14159265
const ll mod = 1000 * 1000 * 1000 + 7;
const ll mod1 = 998244353;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
using namespace std;

ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  

        y = y>>1; 

        if (x<=100000000)
        x = (long long)(x*x);

        //cout<<x<<'\n'; 
    } 
    return res; 
} 






int main()
{

#ifndef ONLINE_JUDGE    
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

fastio();

    string s;
    cin>>s;

    ll sum=0;

    For(i,0,s.length())
    {
        sum+=s[i]-'0';
    }

    if (sum%9==0)
        cout<<"Yes";
    else
        cout<<"No";

return 0;
}

// check all product based operations for integer overflow

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


Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

int main()
{
    string S;
    cin >> S;
    S[4] = S[7] = ' ';
    istringstream ss(S);
    int y, m, d;
    ss >> y >> m >> d;
    assert(y == 2019);
    if (m < 4 || (m == 4 && d <= 30))
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;

    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll X, Y;
    cin >> X >> Y;
    ll ans = 0;
    if (4 - X > 0) ans += (4-X) * 100000;
    if (4 - Y > 0) ans += (4-Y) * 100000;
    if (X == 1 && Y == 1) ans += 400000;
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    ll S, C;
    cin >> S >> C;

    ll ans = 0;
    if (C > S * 2)
    {
        ans += S;
        C -= S * 2;
        ans += C / 4;
    }
    else
    {
        ans = C / 2;
    }
    // printf("%lld %lld\n", S, C);
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
ll N;
int main(){
  cin>>N;ll a=0;ll b=0;vector<P>A;
  for(int i=0;i<N;i++){
  ll x,y;cin>>x>>y;
    a+=x;b+=y;P p(x,i);P q(y,i);
    A.push_back(p);
    A.push_back(q);
  }sort(A.begin(),A.end());
  set<ll>S;ll ans=0;
  for(int i=0;i<N;i++){
  ans+=A[i].first;
    S.insert(A[i].second);
  }ll M=S.size();
  if(M==N){
  if(A[N].second!=A[N-1].second)
    ans+=(A[N].first-A[N-1].first);
    else{
      ans+=min(A[N].first-A[N-2].first,A[N+1].first-A[N-1].first);
    }
   }a=min(a,b);ans=min(a,ans);
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(){
	int N,a,b;
	ll counter,K,numbers[100001]={};
	cin>>N>>K;
	REP(i,N){
	cin>>a>>b;
	numbers[a]+=b;
	}

	FOR(i,1,100001){
		if(numbers[i]!=0){
			counter+=numbers[i];
			if(counter>=K){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 1024
n = int(input())
numbers = list(map(int, input().split()))

def main() :
    x = numbers[n - 1]
    i = 0
    for j in range(n) :
        if numbers[j] <= x :
            numbers[i], numbers[j] = numbers[j], numbers[i]
            i += 1

    [print(numbers[j] if j != i - 1 else '['+str(numbers[j])+']', end = ' ' if j != n - 1 else '\n') for j in range(n)]

if __name__ == '__main__':
    main()



Measured memory_bytes: 16392
#include<bits/stdc++.h>
using namespace std;
int solve(vector<int>v,int n)
{
	vector<int>dp(n+1);
	dp[1] = 0;
	for(int i=2;i<=n;i++)
	{
		int option1 = abs(v[i] - v[i-1]) + dp[i-1];
		int option2 = (i==2) ? INT_MAX : abs(v[i] - v[i-2]) + dp[i-2];
		dp[i] = min(option1,option2);
	}
	return dp[n];
}
int main()
{
	int n;
	cin>>n;
	vector<int>v(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}
	cout<<solve(v,n);
}

Measured memory_bytes: 4252
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
c = [list(map(int, input().split())) for _ in range(m)]

for i in range(n):
    dist = abs(a[i][0]-c[0][0])+abs(a[i][1]-c[0][1])
    ans = 1
    for j in range(m):
        if(dist > (abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1]))):
            dist = abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
            ans = j+1
        if(j == m-1):
            print(ans)
    

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

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

using namespace std;

int main(){
	string s; cin>>s;
	int i0=-1,i1;
	rep(i,s.length()){
		if(s[i]=='A' && i0==-1) i0=i;
		if(s[i]=='Z') i1=i;
	}
	cout<<i1-i0+1<<'\n';
	return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	int n, p;
	cin >>n >>p >>s;
	ll ans = 0;
	
	if(p==2 ||p==5){
		rep(i, sz(s)){
			if((s[i]-'0')%p==0) ans += i +1;
		}
		cout <<ans <<"\n";
		return 0;
	}
	
	
	VL dt(n);
	ll su = 0, kt =1;
	repr(i, n-1, 0){
		su = (( s[i]-'0') * kt + su ) % p;
		dt[i] = su; (kt *=10)%=p;
	}
	
	map<ll, ll> mp= {{0,1}};
	rep(i, n) mp[dt[i]]++;
	for(auto& x: mp){
		if(x.second<2) continue;
		ans += x.second * (x.second-1) /2;
	}
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 2580
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    int n;
    cin>>n;
    int a[n+1],b[n+1];
    b[0]=0;
    memset(a,0,sizeof(a));
    for(int i=1;i<=n;i++)
        cin>>b[i];
    int c=0;
    int k=1;
    for(int i=1;i<=n;i++)
    {
        if(b[i]==k){
            c++;
            k++;
        }
    }
    if(c >0 && c<=n)
    cout<<n-c;
    else
        cout<<"-1";
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define JS(q,w) ((d[q][0]*d[q][1]+d[w][0]*d[w][1])/(d[q][0]+d[w][0]))
#define SM(q) (d[q][0]*d[q][1])
using namespace std;
typedef double db;
const int N=500500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n;
db ans;
db d[N][2];//v t
int main()
{
	int q,w;
	read(n),read(m);
	int l=1,r=0,all=0;
	fo(i,1,n)
	{
		read(q),read(w);
		d[++r][0]=w,d[r][1]=q;ans+=SM(r);
		all+=w;
		for(;l<r&&d[r-1][1]>=d[r][1];--r)
			if(d[r-1][0]+d[r][0]<=m)
			{
				ans-=SM(r)+SM(r-1);
				d[r-1][1]=JS(r-1,r),d[r-1][0]+=d[r][0];
				ans+=SM(r-1);
			}
			else 
			{
				l=--r;
				d[r][0]=m-d[r+1][0];
				d[r][1]=JS(r,r+1);
				d[r][0]=m;all=m;
				ans=SM(r);
				break;
			}
		for(;all>m;++l)if(all-d[l][0]>=m)ans-=SM(l),all-=d[l][0];
		else
		{
			ans-=SM(l);
			d[l][0]-=(all-m);
			ans+=SM(l);all=m;
			break;
		}	
		printf("%.10lf\n",ans/m);
	}
	return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  cin >> n >> m;
  vl c(m + 1, 0);
  rep(i, n) {
    ll k;
    cin >> k;
    rep(j, k) {
      ll a;
      cin >> a;
      c[a]++;
    }
  }
  ll ans = 0;
  rep(i, m + 1) if(c[i] == n) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3628
import sys
from collections import defaultdict
import heapq
readline = sys.stdin.readline


class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False


def main():
    N, M = map(int, readline().split())
    a = list(map(int, readline().split()))
    uf = UnionFind(N)
    for _ in range(M):
        x, y = map(int, readline().split())
        uf.union(x, y)
    mins = defaultdict(list)
    for i in range(N):
        mins[uf.find(i)].append(a[i])
    if len(mins) == 1:
        return 0
    ans = 0
    others = []
    for v in mins.values():
        v.sort(reverse=True)
        ans += v.pop()
        others += v
    others.sort()
    return 'Impossible' if len(others) < len(mins) - 2 else ans + sum(others[:len(mins) - 2])

print(main())


Measured memory_bytes: 85816
K, S = list(map(int, input().split()))

num = 0
for x in range(K + 1):
	rest = S - x
	if 0 <= rest and rest <= K:
		num += rest + 1
	elif K < rest and rest <=2*K:
		num += 2*K + 1 - rest
print(num)

Measured memory_bytes: 38768
#include <math.h>
#include <stdio.h>
#include <string.h>
long long n, ans = 0;
int main(void) {
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) {
        if (i % 5 != 0) {
            if (i % 3 != 0) {
                ans = ans + i;
            }
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 1728
using System;

namespace DayOfTakahashi {
    class Program {
        static void Main(string[] args) {

            var split = Console.ReadLine().Split(' ');
            int a = int.Parse(split[0]);
            int b = int.Parse(split[1]);

            int ans = 0;

            if (b >= a) ans = a;
            else ans = a - 1;

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
def main():
    s = input()
    ans = 0
    seq = 0
    for c in s:
        if c == 'A' or c == 'C' or c == 'T' or c == 'G':
            seq+=1
        else:
            ans = max(ans,seq)
            seq=0
    else:
        ans = max(ans,seq)
    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
    int b, f, r, v;
    vector<vector<vector<int>>> d(4, vector<vector<int>>(3, vector<int>(10)));

    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> b >> f >> r >> v;
        d.at(b-1).at(f-1).at(r-1) += v;
    }
    
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 10; k++)
            {
                cout << " " << d.at(i).at(j).at(k);
            }
            cout << endl;
        }
        if(i != 3)
            cout << "####################" << endl;
    }
    
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define cmax(a,b) a=max(a,b)
using namespace std;
int qry(string s)
{
	int ret;
	printf("? %s\n",s.c_str());
	fflush(stdout);
	scanf("%d",&ret);
	return ret;
}
struct Node
{
	string w;
	int c;
	bool operator <(const Node &a)const
	{
		return c>a.c;
	}
};
priority_queue<Node> prq;
int main()
{
	int i,j,num,t1,t2,len=0;
	string s,t;
	Node a,b;
	char cw;
	for(i=0;i<62;i++)
	{
		s="";
		if(i<26) cw='a'+i;
		else if(i<52) cw='A'+(i-26);
		else cw='0'+(i-52);
		for(j=0;j<128;j++) s+=cw;
		num=128-qry(s);
		len+=num;
		if(num==0) continue;
		s="";
		for(j=0;j<num;j++) s+=cw;
		prq.push((Node){s,num});
	}
	while(prq.size()>=2)
	{
		a=prq.top();prq.pop();
		b=prq.top();prq.pop();
		s="";
		t1=t2=0;
		for(i=1;i<=a.c+b.c;i++)
		{
			if(t1<a.c&&t2<b.c)
			{
				t=s+a.w[t1];
				for(j=t2;j<b.c;j++) t+=b.w[j];
				if(len-qry(t)==i+(b.c-t2)) s+=a.w[t1++];
				else s+=b.w[t2++];
			}
			else
			{
				if(t1==a.c) s+=b.w[t2++];
				else s+=a.w[t1++];
			}
		}
		prq.push((Node){s,a.c+b.c});
	}
	a=prq.top();
	printf("! %s\n",a.w.c_str());
	fflush(stdout);
	return 0;
}

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

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for ( i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1;
    tail = n + 1;

    while (head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0){
            enqueue(u);
        }else{
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}



Measured memory_bytes: 13364
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int a[100],n,p;
  int mn,mx;
  while(cin>>n&&n){
    for(i=0;i<n;i++)
      cin>>a[i];
    cin>>p;
    mn=0;
    mx=n-1;
    for(i=1;;i++){
      if(0){
      }else if(a[(mn+mx)/2]==p){
	break;
      }else if(a[(mn+mx)/2]<p){
	if(mn==mx)
	  break;
	mn=(mn+mx)/2+1;
      }else if(a[(mn+mx)/2]>p){
	if(mn==mx||mn==(mn+mx)/2)
	  break;
	mx=(mn+mx)/2-1;
      }
    }
    cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
// AOJ 2252 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2252)
#include<iostream>
#include<string>
#define rep(i,a) for(int i=0;i<(a);++i)
#define notFound(c) (lhs.find(c)==std::string::npos)

const std::string lhs = "qwertasdfgzxcvb";

int main()
{
	std::string s;
	while( std::cin >> s, s != "#" )
	{
		int ans = 0;

		rep( i, s.size()-1 )
			ans += notFound(s[i+1])!=notFound(s[i]);
	
		std::cout << ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long LL;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
#include<bitset>
bitset<4000005> s;
int n,a[2005],t;
int main(){
	n=read(); 
	for(int i=1;i<=n;i++)t+=(a[i]=read());
	s[0]=1;
	for(int i=1;i<=n;i++){
		s|=s<<a[i];
	}
	for(int i=(t+1)/2;i<=t;i++)if(s[i]){
		cout<<i<<endl; return 0;
	}
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt(),b=s.nextInt();
        int arr1[] = {1,3,5,7,8,10,12};
        int arr2[] = {4,6,9,11};
        int arr3[] = {2};
        if((Arrays.binarySearch(arr1,a)>=0&&Arrays.binarySearch(arr1,b)>=0)||(Arrays.binarySearch(arr2,a)>=0&&Arrays.binarySearch(arr2,b)>=0)||(Arrays.binarySearch(arr3,a)>=0&&Arrays.binarySearch(arr3,b)>=0))
            System.out.println("Yes");
        else System.out.println("No");
    }


}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25352
import           Control.Applicative
import           Control.Monad

gcd' :: Int -> Int -> Int
gcd' x 0 = x
gcd' x y
    | x >= y    = gcd' y (x `mod` y)
    | otherwise = gcd' x (y `mod` x)

main :: IO ()
main = do
    [x,y] <- fmap read . words <$> getLine :: IO [Int]
    print $ gcd' x y



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;string s;
    cin >> n >> s;
    int cnt = 0;
    rep(i,1000){
        int c[3] = {i/100,(i/10)%10,i%10};
        int f = 0;
        for(int j=0;j<n;j++){
            if(s[j]=='0'+c[f]) f++;
            if(f==3) break;
        }
        if(f==3) cnt++;
    }
    cout << cnt << endl;
}

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

s = []
t = []

sum = 0

for i in range(n):
    a,b = input().split()
    s.append(a)
    t.append(b)
x = input()

for i in range(n):
    if x == s[i]:
        for j in range(i+1,n):
            sum += int(t[j])
        break

print(sum)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

//#include <set>
//#include <unordered_map>
//#include <stack>

using namespace std;

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

#define max_n 100

string S;


int main() {
	
	cin >> S;

	int ans = 0;
	if (S == "SUN")ans = 7;
	if (S == "MON")ans = 6;
	if (S == "TUE")ans = 5;
	if (S == "WED")ans = 4;
	if (S == "THU")ans = 3;
	if (S == "FRI")ans = 2;
	if (S == "SAT")ans = 1;


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++) 
#define forj(s,n) for(int j=s;j<n;j++) 
#define vii vector<int>
int theMax;
int maxi = 1e18 + 200;
int max_val = 1e5 + 1;
int t = 1, n,W;
vii v, w;
int dp[101][100001];
int solve(int i, int rest_val) {
	if (!rest_val) return 0;
	if (i == n) return maxi;
	int& ret = dp[i][rest_val];
	if (ret != theMax) return ret;
	int r1 = maxi;
	if(rest_val>=v[i])
	 r1 = w[i] + solve(i+1,rest_val - v[i]);
	int r2 = solve(i + 1, rest_val);
	return ret = min(r1, r2);
}
signed main()
{
	fast;
	
	//cin>>t;
	while (t--)
	{
		int ans = 0;
		cin >> n >> W;
		v = vii(n); w = vii(n);
		fori(0, n) cin >> w[i] >> v[i];
		memset(dp, '?', sizeof dp);
		theMax = dp[0][0];
		fori(1, max_val) {
			//cout << i << endl;
			//cout << solve(0, i) << endl;
			if (solve(0, i) <= W) ans = i;
		}
		cout << ans << endl;
	}
}

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

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N), B(N);
	rep(i, N) cin >> A.at(i) >> B.at(i);
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	ll answer;
	if (N % 2 == 0) {
		ll P = N / 2;
		ll X = A.at(P - 1) + A.at(P);
		ll Y = B.at(P - 1) + B.at(P);
		answer = Y - X + 1;
	} else {
		ll P = N / 2;
		ll X = A.at(P);
		ll Y = B.at(P);
		answer = Y - X + 1;
	}
	cout << answer << endl;
}

Measured memory_bytes: 6424
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const LL MOD = 1e9 + 7;
const int N = 5000;
LL dp[N + 5][N + 5];
int n, pressed;

LL solve(int idx,int mv) {
	if(mv == pressed) return idx == n; //when all moves already used, check whether the string is same or not
	LL &res = dp[idx][mv];
	if(res != -1) return res;
	res = solve(idx + 1, mv + 1); //pressed (maybe) the right character
	if(idx != 0) res += 2 * solve(idx - 1, mv + 1); //remove one character (either is true or not)
	else res += solve(idx, mv + 1); //when there are no characters left
	return res %= MOD;
}

void hora(int tc) {
	string s;
	cin>>pressed;
	cin>>s;
	n = s.size();
	memset(dp, -1, sizeof dp);
	cout<<solve(0, 0)<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}




Measured memory_bytes: 196224
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	string s;
	cin>>s;
	cout<<s.substr(0,4)+' '+s.substr(4)<<endl;
	return 0;
}

Measured memory_bytes: 256