akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/python

import sys,itertools
if sys.version_info[0]>=3: raw_input=input

def dfs(a):
	if len(a)<2: yield (a[0],str(a[0]))
	for i in range(len(a)-1):
		for l in dfs(a[:i+1]):
			for r in dfs(a[i+1:]):
				yield (l[0]+r[0],'(%s + %s)'%(l[1],r[1]))
				yield (l[0]-r[0],'(%s - %s)'%(l[1],r[1]))
				yield (l[0]*r[0],'(%s * %s)'%(l[1],r[1]))

def solve(a):
	for e in itertools.permutations(a):
		for n,s in dfs(e):
			if n==10:
				print(s)
				return True

try:
	while True:
		a=[int(e) for e in raw_input().split()]
		if a==[0,0,0,0]: break
		if not solve(a): print(0)
except EOFError:
	pass

Measured memory_bytes: 4408
#include<stdio.h>
#define SM 10000
#define TM 500
main()
{

  int i;
  int j;
  int c = 0;
  int q;
  int n;
  int s[SM];
  int t[TM];

  scanf("%d",&n);

  for(i = 0;i < n;i++)
    {
      scanf("%d",&s[i]);
    }


  scanf("%d",&q);

  for(i = 0;i < q;i++)
    {
      scanf("%d",&t[i]);
    }


  for(i = 0;i < q;i++)
    { 
      for(j = 0;j < n;j++)
	{
	  if(t[i] == s[j])
	    {
	      c++;
	      break;
	    }
	}
    }

  printf("%d\n",c);

  return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int x, t;
    cin >> x >> t;
    cout << float(x)/float(t) << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
"""AtCoder nomura 2020: B - Postdocs - 
https://atcoder.jp/contests/nomura2020/tasks/nomura2020_b
"""

__author__ = 'bugttle <bugttle@gmail.com>'

def main():
    T = input()

    # S = T.replace('??', 'DD').replace('?D', 'DD').replace('D?', 'DD').replace('P?', 'PD').replace('?P', 'DP')
    S = T.replace('?', 'D')
    print(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N, K;
    cin >> N >> K;
    ll MaxK = (N-1)*(N-2)/2;
    if(K > MaxK){
        cout << -1 << endl;
        return 0;
    }
    vector<Pll> v;
    rep(i,N-1){
        v.push_back(Pll(1,i+2));
    }
    ll cnt = MaxK - K;
    REP(i,2,N+1){
        REP(j,i+1,N+1){
            if(cnt == 0) goto gt;
            v.push_back(Pll(i,j));
            cnt--;
        }
    }
    gt:
    cout << v.size() << endl;
    for(auto& p:v){
        cout << p.fi << " " << p.se << endl;
    }
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		

		if(a/10%111==0)
			System.out.println("Yes");
		else if((a-a/1000*1000)%111==0)
			System.out.println("Yes");
		else
			System.out.println("No");


	}
}


Measured memory_bytes: 23508
#include <stdio.h>

int main (){
	int L, R, d, ctr = 0;
	
	scanf ("%d %d %d", &L, &R, &d);
		for (L; L <= R; L++){
			if (L % d == 0){
				ctr += 1;
			}
		}
	printf ("%d", ctr);

	return 0;
}

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

int main(){
  while(true){
    int N,X,count=0;
    cin >> N >> X;
    if(N==0 && X==0){
      break;
    }
    for(int i=0;i<N-2;i++){
      for(int j=i+1;j<N-1;j++){
        for(int k=j+1;k<N;k++){
          if(i+j+k+3==X){
            count++;
          }
        }
      }
    }
    cout << count << endl;
  }
}


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


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    ll ans = 0;
    for (int i = 1; i < n; i++) {
        if (a.at(i) < a.at(i-1)) {
            ans += abs(a.at(i) - a.at(i-1));
            a.at(i) = a.at(i-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4852
import numpy as np
N=int(input())

H=list(map(int, input().split()))
H=np.array(H)
MAX=H.max()

ans=0
for i in range(MAX):
    nowzero=True
    count=0
    for j in range(N):
        if nowzero:
            if H[j]>0:
                nowzero=False
                count+=1
        else:
            if H[j]<=0:
                nowzero=True
    ans+=count
    #print(H)
    H-=1

#print(H)
print(ans)

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

using namespace std;

int main()
{
    int N;
    cin >>N;
    int K;
    cin >>K;
    int t;
    int count = 0; 
    for(int i=0;i<N;i++)
    {
        cin >>t;
        if(t>=K)
        {
            count++; 
        }
    }
    cout<<count<<endl; 
    return 0; 
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[]  h= new int[n];
		int count = 1; boolean flag = true;

		for(int i = 0; i < n; i++)
			h[i] = Integer.parseInt(sc.next());

		for(int i = 1; i < n; i++) {
			flag = true;
			for(int j = 0; j < i; j++) {
				if(h[j] > h[i]) flag = false;
			}
			if(flag) count++;
		}
		System.out.println(count);
		sc.close();
	}
}

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int S, W;
    cin >> S >> W;
    if(S <= W) { printf("unsafe\n"); }
    else { printf("safe\n"); }

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
typedef long long ll;
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
long long modpow(long long a,long long n,long long p)
{
    if(n==1)
    {
        return a%p;
    }
    if(n%2==1)
    {
        return a*modpow(a,n-1,p)%p;
    }
    long long t = modpow(a,n/2,p);
    return t*t%p;
}


int main()
{
    /*A
    int a,b;
    cin>>a>>b;

    if(a<=5)
    {
        cout<<0<<endl;
    }
    else if(a>=13)
    {
        cout<<b<<endl;
    }
    else
    {
        cout<<b/2<<endl;
    }
    */
    
    int r,d,a;
    cin>>r>>d>>a;
    int b[11];
    for(int i=1;i<=10;i++)
    {
        if(i==1)
        {
            b[i]=r*a-d;
        }
        else
        {
            b[i]=r*b[i-1]-d;
        }
    }

    for(int i=1;i<=10;i++)
    {
        cout<<b[i]<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b,c,d,x,s,p;
    bool flag;
    cin>>n>>a>>b>>c>>d;
    flag=false;
    for(int i=0;i<=n-1;i++)
    {
        p=a+i*c-(n-1-i)*c;
        x=-(n-i-1)*(d-c);s=i*(d-c);
        if (p+x<=b && b<=p+s) flag=true;
    }
    if (flag) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  int k;cin>>k;
  map<int,int>ma;
  rep(i,n){int a;cin>>a;ma[a]++;};
  vector<int>v;
  for(auto t:ma)v.push_back(t.second);
  sort(all(v));
  int l=v.size();
  if(l<=k)
  {
    cout<<0<<endl;
  }
  else
  {
    int res=0;
    rep(i,l-k)res+=v[i];
    cout<<res<<endl;
  }

  return 0;

}


Measured memory_bytes: 10744
#include<stdio.h>

int a[200010];
int c[200010];
int main(){
	int n;
	scanf("%d",&n);
	long long ans=0;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		ans+=c[a[i]]++;
	}
	for(int i=0;i<n;i++)printf("%lld\n",ans-c[a[i]]+1);
}

Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{
    public class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ');
            var n = int.Parse(nk[0]);
            var k = int.Parse(nk[1]);
            var h = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var x = h.OrderByDescending(tmp => tmp).Skip(k).Sum(); ;
            Console.WriteLine(x);

        }
    }
}


Measured memory_bytes: 38912
#include<cstdio>
#include<algorithm>

using namespace std;

long long a[300000],b[300000];

int main()
{
	int n=0;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lld%lld",&a[i],&b[i]);
	sort(a+1,a+n+1),sort(b+1,b+n+1);
	if(n&1){printf("%lld",b[n/2+1]-a[n/2+1]+1);}
	else printf("%lld",b[n/2]-a[n/2]+b[n/2+1]-a[n/2+1]+1);
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ull i=0;i<(ull)n;++i)
const ull INF = 999999999999999;
double pi = 3.141592653589793238;

int main(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double x,y;
  x = (30*h+0.5*m);
  y = (6*m);
  while( x >= 360 ){
    x -= 360;
  }
  while( y >= 360 ){
    y -= 360;
  }
  double ang = (double)max(x,y) - (double)min(x,y);
  ang = (double)min(ang,360-ang);
  ang = ang*pi/180.0;
  double ans = (double)(a*a) + (double)(b*b) - 2.0*(double)a*(double)b*cos(ang);
  ans = sqrt(ans);
  printf("%.9lf\n",ans);

  return 0;
}

Measured memory_bytes: 4220
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        double sum = 0;
        int indexMax = 0;
        int j = 1;
        while (j < k) {
            j = j * 2;
            indexMax++;
        }
        
        for (int i = 1; i <= n; i++) {
            if (i >= k) {
                sum += Math.pow(2, indexMax);
                continue;
            }

            int index = 0;
            int i2 = i;
            while (i2 < k) {
                index++;
                i2 = i2 * 2;
            }

            sum += Math.pow(2, indexMax - index);
        }


        System.out.println(sum / (n * Math.pow(2, indexMax)));
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 20052
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while ( left < right ) {
    mid = (left + right) / 2;
    if ( key == A[mid] ) return 1;
    if ( key > A[mid] ) left = mid + 1;
    else if ( key < A[mid] ) right = mid;
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ )
    scanf("%d", &A[i]);

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &k);
    if ( binarySearch( k ) ) sum++;
  }
  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 2104
import sys
import copy
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    D = list(map(int, input().split())) + [0]
    c = Counter(D)
    times = []
    undecided = []
    for k, v in c.items():
        if k == 0 or k == 12:
            if v > 1:
                print(0)
                return
            else:
                times.append(k)
                continue

        if v > 2:
            print(0)
            return
        elif v == 2:
            times.append(k)
            times.append(24 - k)
        else:
            undecided.append(k)

    ans = 0
    n = len(undecided)
    for pattern in range(2 ** n):
        tmp = copy.deepcopy(times)
        for i in range(n):
            if pattern & (1 << i):
                tmp.append(undecided[i])
            else:
                tmp.append(24 - undecided[i])

        L = len(tmp)
        diff = INF
        for i in range(L):
            for j in range(i + 1, L):
                d = abs(tmp[i] - tmp[j])
                d = min(d, 24 - d)

                if d < diff:
                    diff = d

        if diff > ans:
            ans = diff

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let A: i32 = read();
    let B: i32 = read();
    let _C: i32 = read();
    let K: i32 = read();
    if A >= K {
        println!("{}", K);
        return;
    }
    if A + B >= K {
        println!("{}", A);
        return;
    }
    println!("{}", A - (K - A - B));
}


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

int main() {
	int a,b;
    cin>>a>>b;
  if(a>=13)
    cout<<b<<endl;
  else
    if(a>=6&&a<=12)
      cout<<b/2<<endl;
  	else
      cout<<0<<endl;
  
     
    
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 1000000

int G[N], A[N], gsize;
int cnt;

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

void shellSort(int A[N], int n){
	
	int h;
	for(h = 1, gsize = 0;;gsize++){
		if( h > n ) break;
		G[gsize] = h;
		h = 3*h+1;
	}
	for(int j = gsize-1; j >= 0; j--){
		insertionSort(A,n,G[j]);
	}
	
	
}

int main(void){
	
	int n;
	cnt = 0;
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++){
		scanf("%d", &A[i]);
	}
	
	shellSort(A, n);
	
	printf("%d\n", gsize);
	for(int i = gsize-1; i >= 0; i--){
		printf("%d", G[i]);
		if( i == 0 ) printf("\n");
		else printf(" ");
	}
	printf("%d\n", cnt);
	for(int i = 0; i < n; i++){
		printf("%d\n", A[i]);
	}
	
}


Measured memory_bytes: 5600
#include<stdio.h>

int main(void){
    int n,i=0,dig=1,sum=0;
    scanf("%d",&n);
    int temp = n;
    while(dig<n){
        dig *=10;
        i++;
    }
    dig/=10;
    //printf("%d %d\n",dig,i);
    for(i=i;i>0;i--){
        sum+=temp/dig;
        temp = n%dig;
        dig/=10;
    }
    //printf("%d\n",sum);
    if(n%sum==0){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}


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

typedef long long ll;
int main()
{
  string s;
  cin >>s;
  char temp;
  int flag=0;
  for(int i=0;i<4;i++){
    if(i>0){
      if(s.at(i)==temp){
        flag=1;
      }
    }
    temp=s.at(i);
  }
  if(flag==1){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=100005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T> inline void read(T &x){
	x=0;char ch=getchar();
	while(ch>'9'||ch<'0') ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
}
template<class T> inline void print(T x){
	if(!x){puts("0");return;}
	int a[20],m=0;
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');puts("");
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
	srand(time(0));
#endif
	ios::sync_with_stdio(0);
//	debug(exp(2,mod-2));
	int ans=0,n,mn=inf,tmp=0,zero=0;read(n);
	for(int i=1;i<=n;i++){
		int x;read(x);
		if(x%10) tmp+=x,gmin(mn,x); else zero+=x;
	}
	if(!tmp){puts("0");return 0;}
	if(tmp%10){printf("%d\n",tmp+zero);return 0;}
	printf("%d\n",tmp+max(0,zero-mn));
#ifdef rqgao2014
	time_tester(1);
#endif
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
 
int toindex(char);
char tosuit(int);
 
int main(void) {
    int n, idx, num, tbl[4][13] = {};
    char buf[2];
    for(scanf("%d", &n); n--; tbl[toindex(buf[0])][~-num]++) {
        scanf("%1s %d", buf, &num);
    }
    for(n = 0; n < 52; n++) {
        idx = n / 13, num = n % 13;
        tbl[idx][num] || printf("%c %d\n", tosuit(idx), -~num);
    }
    return 0;
}
 
int toindex(char suit) {
    int rslt;
    switch(suit) {
      case 'S':
        rslt = 0;
        break;
      case 'H':
        rslt = 1;
        break;
      case 'C':
        rslt = 2;
        break;
      case 'D':
        rslt = 3;
        break;
    }
    return rslt;
}
 
char tosuit(int index) {
    return index-- ? index-- ? index-- ? 'D' : 'C' : 'H' : 'S';
}



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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

struct edge {
    int to, cost;
};

vector<vector<edge>> g;
vector<int> dist;
vector<int> pre;

//ダイクストラ法
void dijkstra(int n, int s) {
    dist.resize(n, INF);
    pre.resize(n, -1);

    //最小値を取り出す優先度付きキュー
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;

    dist[s] = 0;
    que.push(make_pair(0, s)); //距離を最初にして、優先度付きキューで最小値を出せるようにする

    while (!que.empty()) {
        pair<int, int> p = que.top(); que.pop();
        int v = p.second;

        //記録してある最短距離よりも取り出した要素に入っている距離情報が大きい場合は打ち切り
        if (dist[v] < p.first) continue;

        for (int i = 0; i < (int)g[v].size(); ++i) {
            edge e = g[v][i];

            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                pre[e.to] = v; //頂点vを通って、e.toにたどり着いた
                que.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main() {

    int n, m;
    cin >> n >> m;

    g.resize(n);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;

        g[a].push_back(edge({b, 1}));
        g[b].push_back(edge({a, 1}));
    }

    dijkstra(n, 0);

    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i) {
        if (i == 0) continue;

        cout << pre[i] + 1 << endl;
    }
}

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

int main(int argc, char *argv[]){
  int x, base, lim_base, over, used;
  cin >> x >> base >> lim_base >> over >> used;
  int over_lit = max(0, used - lim_base);
  int ans = min(x*used, base + over_lit*over);
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1160
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
# https://atcoder.jp/contests/abc042/tasks/abc042_b

N, L = read_ints()
print(''.join(sorted([input() for _ in range(N)])))


Measured memory_bytes: 3316
#include <stdio.h>
 int main(int argc, const char * argv[])
 {
 char ch;
 int x=0,y=97;
 char z;
 int w[25]={0};
 while( scanf("%c", &ch) != EOF )
{
 if('A'<=ch && ch<='Z')
{
 ch=ch+32;
 }
 if('a'<=ch && ch<='z')
{
 w[ch-97]++;
 }
 x++;
 }
 for(y=97;
y<=122;y++)
{
 z=y;
 printf("%c : %d\n",z,w[y-97]);
 }
 return 0;
 } 


Measured memory_bytes: 2104
N = int(input())
honest = [[] for _ in range(N)]
unkind = [[] for _ in range(N)]
MAX = 0
for i in range(0,N):
    A = int(input())
    for _ in range(A):
        x, y =map(int,input().split(' '))
        if y == 0:
            unkind[i].append(x-1)
        else:
            honest[i].append(x-1)

for i in range(2**N):
    flg = 1
    for j in range(N):
        if ((i>>j) & 1):
            bool1 = all([(i>>k) & 1 for k in honest[j]])
            bool2 = all([~(i>>k) & 1 for k in unkind[j]])
            if not all([(i>>k) & 1 for k in honest[j]]) or not all([~(i>>k) & 1 for k in unkind[j]]):
                flg =0

    if flg:
        cnt = 0
        num = i
        while num:
            num &= num -1
            cnt += 1
        MAX = max(cnt,MAX) 

print(MAX)

Measured memory_bytes: 3064
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn main() {
    let s = read_line();
    let t = "CODEFESTIVAL2016";

    let mut ans = 0;
    for (c, d) in s.chars().zip(t.chars()) {
        if c != d {
            ans += 1
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	map<int, int> mp;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		mp[a]++;
	}
	
	int ans = 0;
	for(auto &x : mp) {
		if( x.second % 2 != 0 ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

const int MOD = 1e9 + 7;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    vector<vector<bool>> grid(h, vector<bool> (w));
    for (int i = 0; i < h; i++) {
        string row;
        cin >> row;
        for (int j = 0; j < w; j++) {
            grid[i][j] = row[j] == '.';
        }
    }
    
    vector<vector<int>> paths(h, vector<int> (w));
    paths[0][0] = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!grid[i][j]) continue;
            if (j+1 < w && grid[i][j+1]) {
                paths[i][j+1] += paths[i][j];
            }
            if (paths[i][j+1] >= MOD) paths[i][j+1] -= MOD;
            if (i+1 < h && grid[i+1][j]) {
                paths[i+1][j] += paths[i][j];
            }
            if (paths[i][j+1] >= MOD) paths[i][j+1] -= MOD;
        }
    }
    cout << paths[h-1][w-1] % MOD << endl;
}

Measured memory_bytes: 4352
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
import copy
k = int(input())
#n, d = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

m = 7
for i in range(1, 10 ** 6):
    if m % k == 0:
        print(i)
        sys.exit()

    m *= 10
    m += 7
    if m > k:
        m %= k

print(-1)



Measured memory_bytes: 9916
#include<iostream>
#include<memory.h>
#include<algorithm>
using namespace std;
int n, k;
int card[100001];
int ans = 0;
int main()
{
	cin >> n >> k;
	while (n!=0&&k!=0){
		memset(card, 0, sizeof(card));
		for (int i = 0; i < k; i++){
			int t;
			cin >> t;
			card[t] = 1;
		}
		int st = 1;
		int count = 0;
		for (int i = 1; i <= n + 1; i++){
			if (card[i] == 0){
				for (int i2 = st; i2 < i; i2++){
					card[i2] = count;
				}
				ans = max(ans, count);
				st = i + 1;
				count = 0;
			}
			else{
				count++;
			}
		}
		if (card[0] == 0){
			cout << ans << endl;
		}
		else{
			for (int i = 1; i <= n; i++){
				if (card[i] == 0){
					ans = max(ans, (card[i - 1] + card[i + 1]) + 1);
				}
			}
			cout << ans << endl;
		}
		cin >> n >> k;
	}
}

Measured memory_bytes: 3488
import java.util.Scanner;
public class Main {
	public static void main(String args[]){
		run();
	}
	static void run(){
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		String tmptmp[] = new String[h];
		String a[][] = new String[h][w];
		for(int i = 0; i < h; i++){
			String tmp = scan.next();
			tmptmp = tmp.split("");
			for(int j = 0; j < w; j++){
				a[i][j] = tmptmp[j];
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				System.out.print(a[i][j]);
			}
			System.out.println();
			for(int j = 0; j < w; j++){
				System.out.print(a[i][j]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 15928
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 1000010;

string conv(int n){
        string s;
        if(n/1000>0){
                if(n/1000>1) s+='0'+n/1000;
                s+='m';
        }
        n%=1000;
        if(n/100>0){
                if(n/100>1) s+='0'+n/100;
                s+='c';
        }
        n%=100;
        if(n/10>0){
                if(n/10>1) s+='0'+n/10;
                s+='x';
        }
        n%=10;
        if(n>0){
                if(n>1) s+='0'+n;
                s+='i';
        }
        return s;
}

int main(){
        map<string, int> mp;
        For(i, 1, 10000) mp[conv(i)]=i;
        int n;
        scanf("%d", &n);
        rep(i, n){
                string s, t;
                cin>>s>>t;
                cout << conv(mp[s]+mp[t]) << "\n";
        }
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
 
using namespace std;
 
struct Bipartite_Matching
{
  vector< vector< int > > graph;
  vector< int > match, alive, used;
  int timestamp;
 
  Bipartite_Matching(int n)
  {
    timestamp = 0;
    graph.resize(n);
    alive.assign(n, 0);
    used.assign(n, 0);
    match.assign(n, -1);
  }
 
  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
 
  bool dfs(int v)
  {
    used[v] = timestamp;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(alive[u] == 0) continue;
      if(w == -1 || (used[w] != timestamp && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return (true);
      }
    }
    return (false);
  }
 
  int bipartite_matching()
  {
    int ret = 0;
    for(int i = 0; i < graph.size(); i++) {
      if(alive[i] == 0) continue;
      if(match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return (ret);
  }
 
  int add(int k)
  {
    alive[k] = 1;
    ++timestamp;
    return (dfs(k));
  }
 
};
 
int main()
{
  int N, A[150000], idx[150000];
  vector< int > g[150000];
 
  cin >> N;
  ++N;
  for(int i = 1; i < N; i++) {
    cin >> idx[i];
    g[idx[i]].push_back(i);
  }
 
  Bipartite_Matching flow(N);

  for(int i = 1; i < N; i++) {
    flow.add_edge(i, idx[i]);
  }
  flow.alive[0] = true;
 
  flow.bipartite_matching();
  int ret = 0;
  for(int i = 1; i < N; i++) {
    ret += flow.add(i);
    cout << ret << endl;
  }
 
}

Measured memory_bytes: 6892
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
typedef long long ll;

using namespace std;

struct xyz {
    int x;
    int y;
};

bool fin(vector<bool> &check, int index, int lim) {
    if(index == lim) {
        return false;
    }
    
    if(check[index] == true) {
        check[index] = false;
        return true;
    }
    else {
        check[index] = true;;
        return fin(check, index + 1, lim);
    }
}

int main() {
    int n; cin >> n;
    
    vector<int> a(n);
    vector<vector<xyz>> v = vector<vector<xyz>>(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        v[i] = vector<xyz>(a[i]);
        for(int j = 0; j < a[i]; j++) {
            cin >> v[i][j].x >> v[i][j].y;
        }
    }
    
    int ans = 0;
    vector<bool> check(n, true);
    do {
        bool flag = true;
        for(int i = 0; i < n; i++) {
            if(check[i] == true && !v[i].empty()) {
                for(int j = 0; j < v[i].size(); j++) {
                    int who = v[i][j].x - 1;
                    bool isTrue = v[i][j].y == 1 ? true : false;
                    if(check[who] != isTrue) {
                        flag = false;
                    }
                }
            }
        }
        
        // cout << check[0] << " " << check[1] << " " << check[2] << endl;
        
        if(flag) {
            int tmp = 0;
            for(int i = 0; i < n; i++) {
                if(check[i]) {
                    tmp++;
                }
            }
            ans = max(ans, tmp);
        }
    } while(fin(check, 0, n));
    cout << ans << endl;
    return 0;
}


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

len_a=len(str(bin(max(a))))-2
len_k=len(str(bin(k)))-2

if len_a >= len_k:
  length =len_a
  for i in range(n):
    a[i] = ("0"*length+str(bin(a[i]))[2:])[-len_a:] 
elif len_a < len_k:
  length =len_k
  for i in range(n):
    a[i] = ("0"*length+str(bin(a[i]))[2:])[-len_k:]
    
k = ("0"*length+str(bin(k))[2:])[-length:]

flag = False
for i in range(length):
  count_0 =0
  count_1 =0
  for j in range(n):
    if a[j][i]=="0":
      count_0 += 1
    else:
      count_1 += 1
  #print(count_0,count_1)
  if count_0 <= count_1 and k[i]=="1":
    if i==0:   
      k="0"+k[1:length]
    elif i == length - 1:
      k= k[0:i]+"0"
    else:
      k= k[0:i]+"0"+k[i+1:]
    flag = True
  elif count_0 > count_1 and k[i]=="0" and flag:
    if i==0:   
      k="1"+k[1:length]
    elif i == length - 1:
      k= k[0:i]+"1"
    else:
      k=k[0:i]+"1"+k[i+1:]
      
ans = 0
for i in range(n):
  for j in range(length):
    if a[i][j]!=k[j]:
      ans +=2**(length-1-j)
print(ans)



Measured memory_bytes: 93144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 200005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
string s;

int main(void){
  
  IN(N);
  vl A(N);
  REP(i, N+1) {
    IN(A[i]);
  }
  map<ll, ll> B;
  map<ll, ll> C;
  REP(i, N) {
    B[A[i]+i+1];
    B[A[i]+i+1]++;
    C[i+1-A[i]];
    C[i+1-A[i]]++;
  }

  for (pair<ll, ll> p : B) {
    ret += p.second * C[p.first];
  }

  PRINT(ret);

}


Measured memory_bytes: 38932
while(s=gets.gsub(/\d+/){|k|?1*k.to_i})!~/#/
n=s.reverse.index ?/
a,b,c,d=gets.split.map &:to_i
s[n*a-n+b-1]=?1
s[n*c-n+d-1]=?b
$><<s.gsub(/1+/,&:size)
end

Measured memory_bytes: 8724
n = int(input())
L = list(map(int, input().split()))

trips = []

for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                trips.append([L[i], L[j], L[k]])

ans = 0

for i in trips:
    if max(i) < sum(i) - max(i):
        ans += 1

print(ans)


Measured memory_bytes: 25380
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int[] nab = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine((nab[2] - nab[1]) % 2 == 0 ? "Alice" : "Borys");
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    stack<ll> s;
    string x;
    while(cin >> x){
        if(x == "+"){
            ll y1 = s.top(); s.pop();
            ll y2 = s.top(); s.pop();
            s.push(y1 + y2);
        }else if(x == "-"){
            ll y1 = s.top(); s.pop();
            ll y2 = s.top(); s.pop();
            s.push(y2 - y1);
        }else if(x == "*"){
            ll y1 = s.top(); s.pop();
            ll y2 = s.top(); s.pop();
            s.push(y1 * y2);
        }else{
            ll y = stoll(x);
            s.push(y);
        }
    }
    cout << s.top() << endl;
    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
using namespace std;
typedef pair<int,int> P;

int N, M;

// t[i] := 部屋 i を守れる教授の数.
int t[101] = {0};	

// 解が存在しないかどうか
bool impossible(vector<P>& v){
	for(int i=0 ; i < v.size() ; i++ ){
		int a = v[i].first;
		int b = v[i].second;
		for(int j = a ; j <= b ; j++ ){
			t[j]++;
		}
	}
	int cnt=0;
	for(int i=0 ; i < N ; i++ ){
		if( t[i] ) cnt++;
	}
	return (cnt != N);
}

// 前から貪欲に選んでいく. 
// 部屋 id を守れる教授のなかで区間[a,b]について b が最大の教授を選んでいく.
int solve(vector<P>& v, int id, int cnt){
	if( N <= id ) return cnt;
	
	int m = -1;
	for(int i=0 ; i < v.size() ; i++ ){
		int a = v[i].first;
		int b = v[i].second;
		if( a <= id ){
			m = max( m , b );
		}
	}
	int res=0;
	for(int i=0 ; i < v.size() ; i++ ){
		int a = v[i].first;
		int b = v[i].second;
		if( a <= id && m == b ){
			res = solve(v,b+1,cnt+1);
			break;
		}
	}
	return res;
}

int main(){	
	cin >> N >> M;
	vector<P> v(M);
	for(int i=0 ; i < M ; i++ ){
		int a,b;
		cin >> a >> b;
		a--; b--;
		v[i] = P(a,b);
	}
	
	// 解が存在しないかどうか.
	if( impossible(v) ){
		cout << "Impossible" << endl;
		return 0;
	}
	sort( v.begin() , v.end() );
	int ans = solve(v,0,0);
	cout << ans << endl;
}

Measured memory_bytes: 0
import math
while True :
    n = int(input())
    if n == -1 :
        break
    
    x = 1
    y = 0
    for i in range(n-1) :
        a = y / (math.sqrt(x**2 + y**2))
        b = x / (math.sqrt(x**2 + y**2))
        x = x - a
        y = y + b
    print('{:.2f}'.format(x))
    print('{:.2f}'.format(y))


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


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

int main2() {
  double L = nextInt();

  double ans = pow(L/3.0, 3);
  printf("%.10f\n", ans);

  return 0;
}

int main() {

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using intl = long long;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)((n) - 1); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF = 1e9;
#define debug(x) cout << #x << ":" << x << endl
using namespace std;
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    string w;
    cin >> w;
    intl a[26];
    rep(i,26){
        a[i] = 0;
    }
    rep(i,w.length()){
        a[w[i] - 'a']++;
    }
    bool flag = true;
    rep(i,26){
        if(a[i]%2 != 0)flag = false;
    }
    fp(flag);
    return 0;
}

Measured memory_bytes: 256
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const l1 = r.nn()
    const l2 = r.nn()
    const l3 = r.nn()
    const l = [l1, l2, l3]
    const [N] = r.nn()

    for (let i = 0; i < N; i++) {
      const [b] = r.nn()

      for (let i = 0; i < 3; i++) {
        for (let j = 0; j < 3; j++) {
          if (l[i][j] === b) {
            l[i][j] = -1
          }
        }
      }
    }
    // console.log(l.map(v => v.join(',')).join('\n'))

    let hit = false

    for (let i = 0; i < 3; i++) {
      hit = hit || l[i][0] + l[i][1] + l[i][2] === -3
      hit = hit || l[0][i] + l[1][i] + l[2][i] === -3
    }
    hit = hit || l[0][0] + l[1][1] + l[2][2] === -3
    hit = hit || l[2][0] + l[1][1] + l[0][2] === -3
    return hit ? 'Yes' : 'No'
  }

  const _io = (i = 0) => {
    const str = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map(line => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}


Measured memory_bytes: 9420
#include<bits/stdc++.h>
 
using namespace std;
 
inline int read(){
	char ch=getchar();int x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}
 
bitset<2010*2010> bt; 
 
int main(){
	int n=read();
	int sum=0;
	bt[0]=1;
	for(int i=1;i<=n;i++){
		int d=read();
		sum+=d;
		bt=bt | (bt<<d);
	} 
	int ans=(sum+1)/2;
	while(bt[ans]==0) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a == b) {
            System.out.println(a + b);
            return;
        }
        int ans = Math.max(a, b);
        System.out.println(ans + ans - 1);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


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

const long long INF = 1LL << 60;

template <class T> bool chmin(T& a, T b)
{
  if (a > b) {
    a = b; return true;
  } else return false;
}

template <class T> bool chmax(T& a, T b)
{
  if (a < b) {
    a = b; return true;
  } else return false;
}

int main() 
{
  int N, W;
  cin >> N >> W;
  vector<int> w(N + 10);
  vector<long long> v(N + 10);
  for (int i = 0; i < N; i++) cin >> w.at(i) >> v.at(i);
  
  vector<vector<long long>> dp(N + 10, vector<long long>(W + 10, 0));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j <= W; j++)
    {
      if (j - w.at(i) >= 0) chmax(dp.at(i + 1).at(j), dp.at(i).at(j - w.at(i)) + v.at(i));
      chmax(dp.at(i + 1).at(j), dp.at(i).at(j));
      //cout << dp.at(i + 1).at(j) << " ";
    }
    //cout << endl;
  }
  
  long long ans = dp.at(N).at(W);
  cout << ans << endl;
}

Measured memory_bytes: 87296
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

struct UnionFind {
    data: Vec<usize>,
    size: Vec<usize>,
    inconv: usize,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut data = vec![0; n];
        for i in 0..data.len() {
            data[i] = i;
        }
        let mut size = vec![1; n];
        UnionFind {
            data: data,
            size: size,
            inconv: n * (n - 1) / 2,
        }
    }

    fn inconv(&self) -> usize {
        self.inconv
    }

    fn unite(&mut self, a: usize, b: usize) {
        let mut a = self.find(a);
        let mut b = self.find(b);
        if a == b {
            return;
        }

        if self.size[a] < self.size[b] {
            std::mem::swap(&mut a, &mut b);
        }

        self.inconv -= self.size[a] * self.size[b];
        self.size[a] += self.size[b];
        self.data[b] = a;
    }

    fn find(&mut self, x: usize) -> usize {
        let t = self.data[x];
        if t != x {
            let p = self.find(t);
            self.data[x] = p;
        }
        self.data[x]
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1); m]
    }

    let mut uf = UnionFind::new(n);
    let mut ans = vec![0; m];
    for i in (0..ans.len()).rev() {
        ans[i] = uf.inconv();
        uf.unite(e[i].0, e[i].1);
    }

    for x in ans {
        println!("{}", x);
    }
}


Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<int> an(n);
  int minuscnt = 0;
  for(int i=0; i<n; ++i){
    cin >> an[i];
    if(an[i] < 0) ++minuscnt;
  }
  ll ans = 0;
  int m = INF;
  for(int i=0; i<n; ++i){
    ans += abs(an[i]);
    if(minuscnt%2){
      m = min(m, abs(an[i]));
    }
  }
  if(minuscnt%2) ans -= m*2;
  cout << ans << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define MAX 100010

int n,q;
char s[MAX];
int t[MAX];
int l,r;

void put(){
    for(int i=1;i<n;i++){
        if(s[i]=='C'&&s[i-1]=='A') t[i]=t[i-1]+1;
        else t[i]=t[i-1];
    }
}

int main(){
    cin>>n>>q;
    cin>>s;
    put();
    for(int i=0;i<q;i++){
        cin>>l>>r;
        cout<<t[r-1]-t[l-1]<<endl;
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int64_t N;
  cin >> N;
  int64_t sum = 0;
  for (int i=1;i<=N;i++){
    if ((i % 3 != 0) && (i % 5 != 0)){
      sum += i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3580