akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define NIL -1
#define MAX 100005

typedef struct node{
  int p,l,r;
}Node;
Node T[MAX];
int D[MAX],H[MAX];
int n;

void depth(int,int);
int height(int);
int sibling(int);

void print(int);

int main(){
  int i,j,v,l,r,root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL)T[l].p=v;
    if(r!=NIL)T[r].p=v;
}
  for(i=0;i<n;i++){
    if(T[i].p==NIL)root=i;
}
  depth(root,0);
  height(root);
  for(i=0;i<n;i++)print(i);
  return 0;
}

void depth(int u,int d){
  if(u==NIL)return ;//                                                                             
  D[u]=d;
  depth(T[u].l,d+1);
  depth(T[u].r,d+1);
}
int height(int u){
  int h1=0,h2=0;
  if(T[u].l!=NIL)h1=height(T[u].l)+1;
  if(T[u].r!=NIL)h2=height(T[u].r)+1;
  return H[u]=(h1>h2 ? h1:h2);//                                                                   
}

int sibling(int u){
  if(T[u].p==NIL)return NIL;
  if(T[T[u].p].l!=u && T[T[u].p].l!=NIL)return T[T[u].p].l;
  if(T[T[u].p].r!=u && T[T[u].p].r !=NIL)return T[T[u].p].r;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",sibling(u));
  int deg = 0;
  if(T[u].l!=NIL)deg++;
  if(T[u].r!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].p==NIL){
    printf("root\n");
  }else if(T[u].l==NIL && T[u].r==NIL){
    printf("leaf\n");
  }else {
    printf("internal node\n");
}


}



Measured memory_bytes: 2132
#include <iostream>
using namespace std;
 
   int main()
   {
       int N;
       cin >> N;
       int a[N];
       bool visited[N];
       for (int i=0; i<N; i++) {
           cin >> a[i];
       }
       for (int i=0; i<N; i++) {
           visited[i] = false;
       }
       visited[0] = true;
       int next = a[0];
       if (next == 2) {
           cout << 1 << endl;
           return 0;
       }
       int cnt = 1;
       for (int i=0; i<N-1; i++) {
           if (!visited[next-1]) {
               next = a[next-1];
               cnt += 1;
               if (next == 2) {
                   cout << cnt << endl;
                   return 0;
               }
           }
       }
       cout << -1 << endl;
    }

Measured memory_bytes: 4088
N,C = map(int,input().split())
D = [list(map(int,input().split())) for i in range(C)]
L = [list(map(int,input().split())) for i in range(N)]

d0 = {}
d1 = {}
d2 = {}

for i in range(N) :
    for j in range(N) :
        before = L[i][j] - 1
        
        if (i+j) % 3 == 0 :
            if before not in d0 :
                d0[before] = 1
            else :
                d0[before] += 1

        elif (i+j) % 3 == 1 :
            if before not in d1 :
                d1[before] = 1
            else :
                d1[before] += 1

        else :
            if before not in d2 :
                d2[before] = 1
            else :
                d2[before] += 1


B = []

for d in [d0,d1,d2] :
    A = []
    for after in range(C) :
        calc = 0
        for before in d :
            calc += D[before][after] * d[before]
        A.append([calc,after])

    A = sorted(A,key=lambda x:x[0],reverse=False)[:3]
    B.append(A)
    
    

ans = float("inf")

for i in range(3) :
    for j in range(3) :
        for k in range(3) :
            if (B[0][i][1] - B[1][j][1]) * (B[1][j][1] - B[2][k][1]) * (B[2][k][1] - B[0][i][1]) == 0 :
                continue
            
            ans = min(ans, B[0][i][0] + B[1][j][0] + B[2][k][0])

print(ans)


Measured memory_bytes: 5620
n,c,k = tuple(map(int,input().split()))
t = []

for i in range(n):
  t.append(int(input()))
t = sorted(t)
t_0 = t[0]
p = 1
ans = 0
for t_i in t[1:]:
  if p<c and t_i-t_0<=k:
    p+=1
  else:
    p = 1
    t_0 = t_i
    ans+=1
    
print(ans+1)

Measured memory_bytes: 51928
#include <bits/stdc++.h>
using namespace std;
long long  N,A,B;
long long value[51];
bool comp(long long a,long long b)
{
    return a>b?true:false;
}

long long dp[51][51];

void init()
{
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=1; i<=50; i++)
    {
        dp[i][0]=1;
        for(int j=1; j<=i; j++)
            dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
    }
}
int main(void)
{
    cout.tie(0);
    cin>>N>>A>>B;
    init();
    for(int i=0; i<N; i++)
    {
        cin>>value[i];
    }
    sort(value,value+N,comp);
    double sum=0.0;
    for(int i=0; i<=A-1; i++)
    {
        sum+=value[i];
    }
    long long  num=0,k=0;
    for(int i=0; i<N; i++)
    {
        if(value[i]==value[A-1])
        {
            num++;
            if(i<A)
                k++;
        }
    }
    long long ans=0;
    if(k==A)//前A个相同,可以增加个数
    {
        for(int i=A; i<=B; i++)
            ans+=dp[num][i];
    }
    else
        ans+=dp[num][k];

    printf("%.15f\n",sum/A);
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 256
// AOJ 0576
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int l, a, b, c, d;
	cin >> l >> a >> b >> c >> d;
	cout << l - max((a + c - 1) / c, (b + d - 1) / d) << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	bool f[10] = {};
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;
		f[d] = true;
	}

	vector<int> l;
	queue<int> q;
	for (int i = 0; i < 10; i++) {
		if (!f[i]) {
			l.emplace_back(i);
			if (i != 0) {
				q.push(i);
			}
		}
	}

	while (!q.empty()) {
		int top = q.front();
		q.pop();

		if (top >= n) {
			cout << top << endl;
			return 0;
		}

		top *= 10;
		for (int i = 0; i < l.size(); i++) {
			q.push(top + l[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i,n) for (int i=0; i < int(n); i++)
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	cout << '\n';
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	cout << '\n';
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	cout << '\n';
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) * b;
	//a*bは64bit integer overflow
}

bool integer(double num) {
	return floor(num) == num;
}

Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	IOS;
	int a,b,c;
	cin >> a >> b >> c;
	int left=a-b;
	if (c-left>0)
		cout << c - left;
	else cout<<0;



	cout << endl;
	return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
using namespace std;
typedef pair < int , int > Pi;
typedef pair < int , Pi > Pii;
#define fr first
#define sc second
const int dy[] = { -1, -1, 0, 1, 1, 0 }, dx[] = { -1, 0, 1, 1, 0, -1 };
bool mas[256][256], used[256][256];

int main(){
  int n, t;
  while(cin >> t >> n , t || n){
    fill_n( *mas, 256 * 256, false);
    fill_n( *used, 256 * 256, false);
    for(int i = 0 ; i < n ; i++ ){
      int y, x;
      cin >> x >> y;
      mas[100 + y][100 + x] = true;
    }
    int sy, sx;
    cin >> sx >> sy;
    int ret = 0;
    queue< Pii > que;
    que.push(Pii( t, Pi(sy + 100, sx + 100)));
    while(!que.empty()){
      Pii p = que.front();
      que.pop();
      if(p.fr < 0 || used[p.sc.fr][p.sc.sc]++) continue;
      ret++;
      for(int i = 0 ; i < 6 ; i++ ){
        int ny = p.sc.fr + dy[i], nx = p.sc.sc + dx[i];
        if(!mas[ny][nx]) que.push(Pii( p.fr - 1, Pi( ny, nx)));
      }
    }
    cout << ret << endl;
  }
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

ll n;
vector<string> ans;

void dfs(string s, char mc) {
  if (s.length() == n) {
    ans.push_back(s);
    return;
  }
  for (char c = 'a'; c <= char(mc + 1); c++) {
    char nmc = max(mc, c);
    dfs(s + c, nmc);
  }
}

int main() {
  cin >> n;
  dfs("a", 'a');
  sort(ALL(ans));
  REP(i, ans.size()) { cout << ans[i] << endl; }
  return 0;
}

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define lpx(i,x,n) for(int i=x; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 500000;
int mx = -1e9 , mn = 1e9 ;
int arr[N] ;

int dcmp(double x, double y)
{
    return fabs(x - y) <= eps ? 0 : x > y ? -1 : 1;
}



int main()
{
    int k, x; cin>> k>> x;
    for(int i = 1 ; i < k ; ++i)
        cout << x - k + i << ' ';
    cout << x << ' ';
    for(int i = 1 ; i < k ; ++i)
        cout << x + i << ' ';
    cout << endl;

    return 0;
}
























Measured memory_bytes: 256
class NextTrip
  def solve
    while true
      target_price = gets.to_i
      break if target_price <= 0
      calc(target_price)
    end
  end

  private
  def calc(target_price)
    answer = 'NA'
    1.upto(12) do |month|
      m, n = gets.split.map(&:to_i)
      target_price -= (m - n)
      if target_price <= 0 && answer == 'NA'
        answer = month
      end
    end
    puts answer
  end
end

next_trip = NextTrip.new
next_trip.solve

Measured memory_bytes: 8780
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a;
        int n = sc.nextInt();
        a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }        
        for(int j=n-1;j>0;j--){
            System.out.print(a[j] + " ");
        }
        System.out.println(a[0]);
        sc.close();
    }
}


Measured memory_bytes: 26276
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count=0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      total = 500 * i + 100 * j + 50 * k
      if total == x:
        count += 1
print(count)

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

using namespace std;

#define watch(x) cout << (#x) << " is " << (x) << endl

typedef unsigned long long int ll;
typedef long double ld;
typedef long int li;
const int inf=1e9+5;

int main()
{
    // clock_t tStart = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    vector<int> dp(n,inf);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<i+3;j++)
        {
            if(j<n)
            {
                dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
    // prllf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0, cnt = 0;
    rep(i,3){
        if(s[i] == 'R') ++cnt;
        else cnt = 0;
        chmax(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int dp[50];
int fib(int);
int main(){
    int i,k;
    for(k=0;k<50;k++) dp[k]=-1;
    scanf("%d",&i);
    printf("%d\n",fib(i));
    return 0; 
}
int fib(int i){
    if(i==0 || i==1) return dp[i]=1;
    if(dp[i]!=-1) return dp[i];
    else return dp[i]=fib(i-1)+fib(i-2);
}


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

int main()
{
    string S;
    cin >> S;
    if (S.at(0) == S.at(1))
    {
        if (S.at(2) == S.at(3) && S.at(2)!=S.at(0))
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else if (S.at(0) == S.at(2))
    {
        if (S.at(1) == S.at(3) && S.at(3)!=S.at(0))
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else if (S.at(0) == S.at(3))
    {
        if (S.at(1) == S.at(2) && S.at(2)!=S.at(0))
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }

        int ls = -1;
        int rs = n;
        boolean ez = false;
        for (int i = 0; i < n; i++) {
            if (x[i] == 0)
                ez = true;
            if (x[i] < 0)
                ls = i;
        }

        for (int i = n - 1; i >= 0; i--) {
            if (x[i] > 0)
                rs = i;
        }

        int nl = ls + 1;
        int nr = n - rs;
        if (ez) {
            k--;
        }

        int ans = -1;

        for (int i = 0; i <= nl; i++) {
            int toL = 0;
            if (i != 0) {
                toL = x[ls - i + 1];
            }

            int needR = k - i;
            if (needR > nr)
                continue;
            int toR = 0;
            if (needR != 0) {
                toR = x[rs + needR - 1];
            }

            int a1 = Math.abs(2 * toL) + Math.abs(toR);
            int a2 = Math.abs(2 * toR) + Math.abs(toL);
            // System.out.println(a1 + " " + a2 + " " + toR + " " + toL);
            if (ans == -1) {
                ans = Math.min(a1, a2);
            } else {
                ans = Math.min(Math.min(a1, a2), ans);
            }

        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 49660
A = list(map(int, input().split()))
ans = 0
while A[0] % 2 == 0 and A[1] % 2 == 0 and A[2] % 2 == 0:
    if A[0] == A[1] and A[0] == A[2]:
        ans = -1
        break
    A[0], A[1], A[2] = ( A[1] + A[2] ) / 2, ( A[2] + A[0] ) / 2, ( A[0] + A[1] ) / 2
    ans += 1
print(ans)


Measured memory_bytes: 61748
#line 1 "main.cpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
lint modpow(lint a,unsigned int b,unsigned int mod){
	lint res(1),now(a%mod);
	while(b){
		if(b&1){
			res*=now;
			res%=mod;
		}
		b>>=1;
		now*=now;
		now%=mod;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int n,m;
std::vector<int> vec[100010];
bool used[100010];
void dfs(int node){
	used[node]=true;
	for(int i:vec[node]){
		if(!used[i])dfs(i);
	}
}
int main(){
	std::cin>>n>>m;
	rep(i,m){
		int a,b;
		std::cin>>a>>b;
		vec[a].emplace_back(b);
		vec[b].emplace_back(a);
	}
	int ans=0;
	REP(i,n){
		if(!used[i]){
			dfs(i);
			ans++;
		}
	}
	std::cout<<ans-1<<std::endl;
	return 0;
}

Measured memory_bytes: 9716
h,w=map(int,input().split())
l=[]
for _ in range(h):
    l.append(list(input()))
P=[["#"]*w for _ in range(h)]
x=[[1,0],[1,-1],[1,1],[0,-1],[0,1],[-1,0],[-1,-1],[-1,1]]
for i in range(h):
    for j in range(w):
        s=0
        if l[i][j]!="#":
            for k in range(8):
                if 0<=i+x[k][0]<h and 0<=j+x[k][1]<w:
                    if l[i+x[k][0]][j+x[k][1]]=="#":
                        s+=1
            P[i][j]=str(s)
for c in range(h):
    print("".join(P[c]))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define PI 3.141592653589793238462643383279
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	double a,b,ho,mi;
	cin>>a>>b>>ho>>mi;
	double h= (ho*360)/12 + (mi*360)/(12*60);
	double m= (mi*360)/60;
	double angle = abs(h-m);
	if(angle>180)
	{
		angle=360-angle;
	}
	double c = a*a + b*b - 2*b*a*cos(angle*PI/180);
	cout<<fixed<<setprecision(30)<<sqrt(c)<<endl;
	return 0;
}

Measured memory_bytes: 4164
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
sa = [abs(a[i]-a[i+1]) for i in range(n+1)]
sum_sa = sum(sa)

for i in range(n):
    yen = sum_sa + abs(a[i+2]-a[i]) - sa[i] - sa[i+1]
    print(yen)

Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    int count;
    cin>>a>>b;
    if(b==1)
    cout<<"0"<<endl;
    else if(a>=b)
    cout<<"1"<<endl;
    else if(a<b)
    {   count=1;
    if((b-a)%(a-1)>0)
    count++;
        count+=(b-a)/(a-1);
        cout<<count<<endl;
    }
    

}

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

int main(){
    int n; cin >> n;
    int x[n];
    int L = INT_MAX, R = INT_MIN;
    for(int i = 0; i < n; i++){
        cin >> x[i];
        L = min(L,x[i]);
        R = max(R, x[i]);
    }

    int ans = INT_MAX;
    for(int i = L; i <= R; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, sum);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n; cin >> n;
   int ac=0, wa=0, tle=0, re=0;
   rep(i,n){
      string s; cin >> s;
      if (s[0]=='A')ac++;
      else if (s[0]=='W')wa++;
      else if (s[0]=='T')tle++;
      else re++;
   }
   cout << "AC x " << ac << endl;
   cout << "WA x " << wa << endl;
   cout << "TLE x " << tle << endl;
   cout << "RE x " << re << endl;
}

Measured memory_bytes: 3652
program minorchange;
var
    s, t : ansistring;
    i, mismatch : longint;
begin
    readln(s);
    readln(t);
    mismatch := 0;
    for i := 1 to length(s) do begin
        if s[i] <> t[i] then
            mismatch += 1;
    end;
    writeln(mismatch);
end.

Measured memory_bytes: 1384
//54
#include<iostream>
#include<complex>
#include<cmath>
#include<algorithm>

using namespace std;

typedef complex<double> P;

double cr(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

bool in(double a,double b,double c,double d){
  return !(max(a,b)<min(c,d)||max(c,d)<min(a,b));
}

bool is(P *a,P *b){
  return in(a[0].real(),a[1].real(),b[0].real(),b[1].real())
    &&in(a[0].imag(),a[1].imag(),b[0].imag(),b[1].imag())
    &&cr(a[1]-a[0],b[1]-a[0])*cr(a[1]-a[0],b[0]-a[0])<=0
    &&cr(b[1]-b[0],a[1]-b[0])*cr(b[1]-b[0],a[0]-b[0])<=0;
}

int main(){
  for(;;){
    P l[3][2];
    for(int i=0;i<3;i++){
      int x,y,xx,yy;
      cin>>x>>y>>xx>>yy;
      if(i==0&&(x|y|xx|yy)==0)return 0;
      l[i][0]=P(x,y);
      l[i][1]=P(xx,yy);
    }
    double a=0;
    if(is(l[0],l[1])&&is(l[1],l[2])&&is(l[2],l[0])){
      P cp[3];
      for(int i=0;i<3;i++){
	P a,b,c,d;
	a=l[i][0];
	b=l[i][1];
	c=l[(i+1)%3][0];
	d=l[(i+1)%3][1];
	double d1=fabs(cr(a-b,c-b)),d2=fabs(cr(a-b,d-b));
	cp[i]=(d-c)*d1/(d1+d2)+c;
      }
      a=fabs(cr(cp[1]-cp[0],cp[2]-cp[0])/2);
    }
    double as[]={0,.1,100000,1000000,1900000};
    const char *ls[]={"kyo","syo-kichi","kichi","chu-kichi","dai-kichi"};
    cout<<ls[upper_bound(as,as+5,a)-as-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N, M = map(int, input().split())
AB = [0] * N
for i in range(N):
    AB[i] = tuple(map(int, input().split()))

AB.sort(key=lambda x: x[0])
s = 0
m = 0
for a, b in AB:
    r = min(M - m, b)
    m += r
    s += r * a
    if m == M:
        break
print(s)


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

int main() {
  vector<vector<int>> bingo(3, vector<int>(3));
  vector<vector<bool>> judge(3, vector<bool>(3, false));
  vector<bool> judge1(3, true);

  for (int i = 0; i < 3; i++){
    for (int j = 0; j < 3; j++) cin >> bingo[i][j];
  }
  int n, b;
  cin >> n;

  for (int i = 0; i < n; i++){
    cin >> b; 
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(bingo[j][k] == b) judge[j][k] = true;
      }
    }
  }

  if(judge[0] == judge1 || judge[1] == judge1 || judge[2] == judge1) cout << "Yes";
  else if(judge[0][0] && judge[1][1] && judge[2][2]) cout << "Yes";
  else if(judge[0][2] && judge[1][1] && judge[2][0]) cout << "Yes";
  else if(judge[0][0] && judge[1][0] && judge[2][0]) cout << "Yes";
  else if(judge[0][1] && judge[1][1] && judge[2][1]) cout << "Yes";
  else if(judge[0][2] && judge[1][2] && judge[2][2]) cout << "Yes";
  else cout << "No";

}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define OUT(a) cout<<(a)<<endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    int d[101]={};
    REP(i,n){
        cin >> a[i];
        d[a[i]]++;
    }

    sort(a.begin(),a.end());
    if(d[a[0]]>2){
        cout << "Impossible" <<endl;
        return 0;
    }
    if(d[a[0]]==1){
        if(a[0]*2<a[n-1]){
        cout << "Impossible" <<endl;
        return 0;
        }
        d[a[0]]--;
        FOR(i,a[0]+1,a[n-1]+1){
            d[i]-=2;
            if(d[i]<0){
                cout << "Impossible" <<endl;
                return 0;
            }
        }
    }else{
        if(a[0]*2-1<a[n-1]){
        cout << "Impossible" <<endl;
        return 0;
        }
        d[a[0]]=0;
        FOR(i,a[0]+1,a[n-1]+1){
            d[i]-=2;
            if(d[i]<0){
                cout << "Impossible" <<endl;
                return 0;
            }
        }
    }
    cout << "Possible" <<endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string s;
    ll k;
    cin >> s >> k;
    ll n = s.size();
    set<string> a;
    ll c = 0;
    rep(i, 0, n){
        rep(j, 1, min(k+1, n-i+1)){
            a.insert(s.substr(i, j));
        }
    }
    ll cnt = 1;
    for(auto e : a){
        if(cnt == k){
            cout << e << endl;
            break;
        }
        cnt++;
    }
    return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    set<string> s;
    while (N--) {
        var(string, str);
        s.insert(str);
    }

    print(s.size());

    return 0;
}


Measured memory_bytes: 19136
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

struct Point {
	ll x, y;
	Point() {};
	Point(ll xx, ll yy):x(xx), y(yy){}
};
void initializeDis(vector<vector<ll>>& dis, ll& h, ll& w) {
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			dis[i][j] = -1;
		}
	}
}

ll bfs(Point st, Point go, vector<vector<ll>>& dis, vector<vector<bool>>& grid, ll& h, ll& w) {
	queue<Point> Q;
	Q.push(st);
	dis[st.x][st.y] = 0;
	while (!Q.empty()) {
		Point now = Q.front();
		Q.pop();
		ll disnow = dis[now.x][now.y];
		Point tmp[4];
		for (ll i = 0; i < 4; i++) {
			tmp[i] = now;
		}
		tmp[0].x++;
		tmp[1].x--;
		tmp[2].y++;
		tmp[3].y--;
		for (ll i = 0; i < 4; i++) {
			if (0 <= tmp[i].x && tmp[i].x < h && 0 <= tmp[i].y && tmp[i].y < w && dis[tmp[i].x][tmp[i].y] == -1 && grid[tmp[i].x][tmp[i].y] == true) {
				dis[tmp[i].x][tmp[i].y] = disnow + 1;
				Q.push(tmp[i]);
			}
		}

	}
	/*for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			cout << dis[i][j];
		}
		cout << endl;
	}*/
	return dis[go.x][go.y];
}

int main() {
	ll h, w, numCheese;
	cin >> h >> w >> numCheese;
	vector<vector<bool>> grid;
	grid.resize(h);
	vector<vector<ll>> dis;
	dis.resize(h);
	vector<Point> destinations;
	destinations.resize(numCheese + 1);
	for (ll i = 0; i < h; i++) {
		string str;
		cin >> str;
		grid[i].resize(w);
		dis[i].resize(w);
		for (ll j = 0; j < w; j++) {
			if (str[j] != 'X') {
				grid[i][j] = true;
				if (str[j] != '.') {
					if (str[j] == 'S') {
						destinations[0] = Point(i, j);
					}
					else {
						destinations[str[j] - '0'] = Point(i, j);
					}
				}
			}
			

		}
	}
	ll ans = 0;
	for (ll q = 0; q < numCheese; q++) {
		initializeDis(dis, h, w);
		Point st = destinations[q];
		Point go = destinations[q + 1];
		ans += bfs(st, go, dis, grid, h, w);
	}
	cout << ans << endl;
}



Measured memory_bytes: 10980
N,K=map(int, input().split())
A=list(map(int, input().split()))
D=[]
for i in range(N):
  for j in range(i,N):
    D.append(sum(A[i:j+1]))
ans=0
k=42
for i in range(1,k+1):
  cnt=0
  DD=[]
  for j in D:
    if (j>>(k-i))&1==1:
      cnt+=1
      DD.append(j)
  if cnt>=K:
    ans+=2**(k-i)
    D=DD
  elif cnt>=K:
    ans+=2**(k-i)
print(ans)


Measured memory_bytes: 23856
N = int(input())

d = {}
x = [0] * N
y = [0] * N
from collections import defaultdict
for i in range(N):
    x[i], y[i] = map(int, input().split())

d = defaultdict(int)
for i in range(N):
    for j in range(N):
        dx = x[i] - x[j]
        dy = y[i] - y[j]
        if i == j:
            continue
        d[(dx, dy)] += 1
        
if N == 1:
    print(1)
else:
    print(N - max(d.values()))

Measured memory_bytes: 3828
#include<stdio.h>

int main(void){
    int N,K;
    scanf("%d %d", &N,&K);
    if((N%2==1 && (N+1)/2 >= K) || (N%2==0 && N/2 >= K))
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
import math

A,B,H,M = map(int,input().split())


if M == 0 and H == 6:

    print(A+B)

elif M == 0 and H == 0:

    print(abs(A-B))

else:
    angulo = abs(11 * M - 60 * H)/2

    angulo = math.radians(angulo)

    print(abs(math.sqrt((A**2 + B ** 2) -  (2 * A * B * math.cos(angulo)))))


Measured memory_bytes: 9452
//CF handle :dineshg
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back



int main()
{
	fastio
	//ll t;
	//cin >> t;
	//while(t--)
	//{
	ll n;
	cin >> n;
	ll arr[n+1];
	for(ll i=1;i<=n;i++)
		cin >> arr[i];
	sort(arr+1,arr+1+n);
	ll ans = __gcd(arr[1],arr[2]);
	for(ll i =3;i<=n;i++)
	{
		ans = __gcd(ans,arr[i]);
	}

	cout << ans << endl;
//	}
	return 0;	
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <iomanip>
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long  ll;
const int mod = 1e9 + 7;
const int MAXN = 3333;
double dp[MAXN][MAXN];
double p[MAXN];

int main(){
    faster
    int n; cin >> n;
    for(int i = 1;i <= n;i++) cin >> p[i];
    dp[0][0] = 1;
    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= n;j++){
            dp[i][j] += dp[i - 1][j] * (1 - p[i]);
            if(j > 0) dp[i][j] += dp[i - 1][j - 1] * p[i];
        }
    }
    double ans = 0;
    for(int i = n / 2 + 1;i <= n;i++){
        ans += dp[n][i];
    }
    cout << setprecision(15) << ans << endl;
    return 0;
}

    



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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  while(1){
    c -= b;
    if(c <= 0){
      cout << "Yes" << endl;
      break;
    }
    
    a -= d;
    if(a <= 0){
      cout << "No" << endl;
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005],b[100005],c[100005];
vector<ll> p;
int main(){
    ll x,y,n,m,k,sum=0;
    cin>>x>>y>>n>>m>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=m;i++){
        cin>>b[i];
    }
    for(int i=1;i<=k;i++){
        cin>>c[i];
    }
    sort(a+1,a+1+n);reverse(a+1,a+1+n);
    sort(b+1,b+1+m);reverse(b+1,b+1+m);
    sort(c+1,c+1+k);reverse(c+1,c+1+k);
    p.push_back(0);
    for(int i=1;i<=x;i++) p.push_back(a[i]);
    for(int i=1;i<=y;i++) p.push_back(b[i]);
    sort(p.begin(),p.end());
    for(int i=1;i<=x+y;i++){
        sum+=p[i];
    }
    ll ans=sum,num=sum;
    for(ll i=1;i<=min(k,x+y);i++){
        num-=p[i];
        num+=c[i];
        ans=max(ans,num);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 4724
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 
#define OUTPUT1(n, a) cout << "---count---" << endl << n << endl << "---content---" << endl; for(const auto b : a){cout << b << endl; }
#define INPUT2(x, y, field) for(int i##x = 0; i##x < y; i##x++) { for(int j##x = 0; j##x < x; j##x++) { cin >> field[i##x][j##x]; } }
#define OUTPUT2(x, y, field) cout << "---count---" << endl << x << " " << y << endl <<"---content---" << endl; for(int i##x = 0; i##x < y; i##x++) { cout << i##x << "   "; for(int j##x = 0; j##x < x; j##x++) { cout << field[i##x][j##x] << " "; } cout << endl; }

using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
    // Your code here!
    vector<int> v(9);
    vector<bool> bingo(9);
    rep(i, 9){
        cin>>v[i];
        bingo[i]=false;
    }
    int n(0);
    cin>>n;
    
    bool is_bingo(false);
    int input(0);
    
    rep(i, n){
        cin>>input;
        
        
        rep(j, 9){
            if(v[j]==input)bingo[j]=true;
        }
        
        if((bingo[0] && bingo[1] && bingo[2])||
            (bingo[3]&&bingo[4]&&bingo[5])||
            (bingo[6]&&bingo[7]&&bingo[8])||
            (bingo[0]&&bingo[3]&&bingo[6])||
            (bingo[1]&&bingo[4]&&bingo[7])||
            (bingo[2]&&bingo[5]&&bingo[8])||
            (bingo[0]&&bingo[4]&&bingo[8])||
            (bingo[2]&&bingo[4]&&bingo[6])){
                is_bingo=true;
                cout<<"Yes"<<endl;
                break;
            }
    }
    
    if(!(is_bingo))cout<<"No"<<endl;
}


Measured memory_bytes: 256
string = input()
ans_01 = 0
ans_10 = 0

tile = 0
for s in string:
    if s != str(tile % 2):
        ans_01 += 1
    tile += 1

tile = 1
for s in string:
    if s != str(tile % 2):
        ans_10 += 1
    tile += 1

if ans_01 >= ans_10:
    print(ans_10)
else:
    print(ans_01)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

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

    int N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) cin >> S[i];

    vector<int> A(5);
    // 頭文字の数を数える
    REP(i, N) {
        if (S[i][0] == 'M') {
            A[0]++;
        }
        if (S[i][0] == 'A') {
            A[1]++;
        }
        if (S[i][0] == 'R') {
            A[2]++;
        }
        if (S[i][0] == 'C') {
            A[3]++;
        }
        if (S[i][0] == 'H') {
            A[4]++;
        }
    }
    ll ans = 0;
    // bit全探索
    REP(bit, (1 << 5)) {
        int a  = 0; // 選んだ個数を数える
        ll sum = 1;
        REP(i, 5) {
            if (bit & (1 << i)) {
                a++;
                sum *= (ll)A[i];
            }
        }
        // 選んだ個数が 3 つのとき答えに加える
        if (a == 3)
            ans += sum;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
// 2016-12-06
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

struct section { int d, p; };

int main() {
	int n, m, d, p;
	vector<section> v;
	while (cin >> n >> m, n) {
		v.clear();
		for (int i = 0; i < n; i++) {
			cin >> d >> p;
			section s = {d, p};
			v.push_back(s);
		}
		sort(begin(v), end(v), [](const section& x, const section& y) { return x.p > y.p; });
		p = 0;
		for (auto s : v) {
			d = min(m, s.d);
			m -= d;
			p += (s.d - d) * s.p;
		}
		cout << p << endl;
	}
	return 0;
}

Measured memory_bytes: 3224
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<ldouble, ldouble> pdd;

int N, A[2020];
bitset <4000040> B;

void solve() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++) scanf("%d", A+i);
	int sum = 0;
	for(int i=1;i<=N;i++) sum += A[i];
	int v = (sum + 1) / 2;
	B[0] = 1;
	for(int i=1;i<=N;i++) {
		B = (B | B << A[i]);
	}
	for(int i=v;i<=sum;i++) if(B.test(i)) {
		printf("%d\n", i);
		return;
	}
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<complex>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI (3.1415926535897932384626433832795028)
typedef long long Int;
typedef pair<Int, Int> P;
Int n ,l, t[6600];

class Complex{
public:
    double real, imag;
    Complex(double real = 0, double imag = 0):real(real),imag(imag){}
    Complex operator*(Complex other){
        return Complex(real * other.real - imag * other.imag,
                       real * other.imag + imag * other.real);
    }
    Complex operator+(Complex other){
        return Complex(real + other.real, imag + other.imag);
    }
};
typedef Complex C;
C point(double theta){
    return C(cos(theta), sin(theta));
}

C operator*(C a, double b){
    return C(a.real * b, a.imag * b);
}

C operator*(double b, C a){
   return  C(a.real * b, a.imag * b);
}

C transpose(C a){
    return C(a.imag, a.real);
}



C ans;
C z[6600];
void view(C x){
    cout << x.real << " " << x.imag << endl;
}

int main(){
    cin >> n >> l;
    Int all = n * (n-1) / 2 * (n-2) / 3;
    for(int i = 0;i < n;i++){
        cin >> t[i];
        t[i + n] = t[i] + l;
        z[i + n] = z[i] = point(t[i] * PI / l);
    }
    for(int i = 0;i < n;i++){
        for(int j = i + 1;j < i + n;j++){
            double gamma = (t[i] + t[j]) * PI / l;
            ans = ans + point(gamma) * (j - i - 1);
//            zsum = zsum + t[j];
//            view(ans);
        }
    }
    printf("%.15lf %.15lf\n", -ans.real / all, -ans.imag/all);
    return 0;
}

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

main()
{
    int n; cin>>n;
    int ma=-1e9;
    int mi=1e9;
    vector<int> a(n);

    for(int i=n; i--; )
    {
        cin>>a[i];
    }
    sort(begin(a),end(a));
    a.erase(unique(begin(a),end(a)),end(a));
    if(a.size()==n)
    {
        cout << "YES" << "\n";
    }
    else
    {
        cout << "NO" << "\n";
    }
    return 0;

    // int k,n; cin>>n>>k;
    // vector<int> acc(n+1);
    // int ans{};
    // for(int i=1; i<=n; ++i)
    // {
    //     int p; cin>>p;
    //     acc[i]=acc[i-1]+p;
    //     if(i<k) continue;
    //     int tmp=acc[i]-acc[i-k];
    //     if(tmp>ans) ans=tmp;
    // }
    // cout << double(ans+k)/2 << "\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<memory>
#include<string>
typedef long long ll;
int main() {
	int a = 0;
	int n;
	char s[4000];
	std::cin >> n >> s;
	ll r = 0;
	ll g = 0;
	ll b = 0;
	ll k = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r++;
		}
		if (s[i] == 'G') {
			g++;
		}
		if (s[i] == 'B') {
			b++;
		}
	}
	for (int i = 0; i < n - 2; i++) {
		for (int j = 1; j <= (n-i-1) / 2; j++) {
			if (s[i] != s[i + j] && s[i] != s[i + 2 * j] && s[i + j] != s[i + 2 * j]) {
				k++;
			}
		}
	}
	std::cout << r*g*b-k << std::endl;
	return 0;
}

Measured memory_bytes: 3580
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let n: usize = sc.get();
    let mut rem = n;
    let mut div = Vec::new();
    for i in (2..).take_while(|i| i * i <= n) {
        if rem % i == 0 {
            div.push(i);
            while rem % i == 0 { rem /= i; }
        }
    }
    if rem != 1 {
        div.push(rem);
    }
    let mut extra = 0;
    let m = div.len();
    for bit in 1..1<<m {
        let mut mul = 1;
        for i in 0..m {
            if (bit>>i) & 1 != 0 {
                mul *= div[i];
            }
        }
        let size = usize::count_ones(bit);
        if size % 2 == 0 {
            extra -= n as i64 / mul as i64;
        } else {
            extra += n as i64 / mul as i64;
        }
    }
    let ans = n as i64 - extra;
    println!("{}", ans);
}



Measured memory_bytes: 5032
#include<bits/stdc++.h>
 
using namespace std;
 
template<typename T> class BIT {
private:
    int n,m; vector<vector<T> > bit;
public:
    void add(int i, int j, T val){
        for(int i_ = i+1; i_ < n; i_ += i_ & -i_)
            for(int j_ = j+1; j_ < m; j_ += j_ & -j_)
                bit[i_][j_] += val;
    }
    T sum(int i, int j){
        T s = 0;
            for(int i_ = i+1; i_ > 0; i_ -= i_ & -i_)
                for(int j_ = j+1; j_ > 0; j_ -= j_ & -j_)
                    s += bit[i_][j_];
            return s;
    }
    T sum(int lx, int uy, int rx, int dy){
        return sum(rx, dy) - sum(lx-1, dy) - sum(rx, uy-1) + sum(lx-1, uy-1);   
    }
    BIT(int sz1, int sz2){
        n = sz1 + 1, m = sz2 + 1;
        bit.resize(n, vector<T>(m, 0));
    }
    BIT(vector<vector<T> >& v){
        n = (int)v.size()+1, m = (int)v[0].size()+1;
        bit.resize(n, vector<T>(m, 0));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                add(i, j, v[i][j]);
    }
    void print_sum(){
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++)
                cout<< sum(i-1, j-1) << " ";
        cout << "\n";
    }
};

 
int main()
{
    int m, n, K;
    cin >> m >> n >> K;
    vector<BIT<int> > bt(3, BIT<int>(m, n));
    vector<string> s(m);
    for(int i = 0; i < m; i++){
        cin >> s[i];
        for(int j = 0; j < n; j++){
            if(s[i][j] == 'J'){
                bt[0].add(i, j, 1);
            }else if(s[i][j] == 'O'){
                bt[1].add(i, j, 1);
            }else{
                bt[2].add(i, j, 1);
            }
        }
    }
    for(int i = 0; i < K; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a, --b, --c, --d;
        cout << bt[0].sum(a, b, c, d) << " " << bt[1].sum(a, b, c, d) << " " << bt[2].sum(a, b, c, d) << "\n";
    }
    return 0;
}


Measured memory_bytes: 18432