akhauriyash/Code-Regression huggingface dataset:
def examA():
    ABC =LI(); ABC.sort()
    if ABC[0]==ABC[-1]:
        print("Yes")
    else:
        print("No")
    return

def examB():
    N = I()
    S = SI()
    red = S.count("R")
    if red>N//2:
        print("Yes")
    else:
        print("No")
    return

def examC():
    N,Q = LI()
    S = SI()
    T = [LSI()for _ in range(Q)]
    l = -1; r = N
    while(r-l>1):
        cur = (r+l)//2
        now = copy.deepcopy(cur)
        flag = False
        for t,d in T:
            if S[now]==t:
                if d=="R":
                    now += 1
                else:
                    now -= 1
            if now==N:
                flag = True
                break
            if now==-1:
                break
        if flag:
            r = cur
        else:
            l = cur
    R = r
    l = -1; r = N
    while(r-l>1):
        cur = (r+l)//2
        now = copy.deepcopy(cur)
        flag = False
        for t,d in T:
            if S[now]==t:
                if d=="R":
                    now += 1
                else:
                    now -= 1
            if now==-1:
                flag = True
                break
            if now==N:
                break
        if flag:
            l = cur
        else:
            r = cur
    L = l
    ans = max(0,R-L-1)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

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

ll n , L , R ;
ll a[100100];

int main(){



scanf("%lld",&n);
for(int i=1;i<=n;i++)scanf("%lld",a+i);

L=R=2ll;
for(int i=n;i;i--){
L = (L+a[i]-1)/a[i] *a[i];
R = (R/a[i])*a[i] + a[i]-1ll;

if(L>R){
    printf("-1\n");
    return 0;
}

}

printf("%lld %lld\n",L,R);
return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
int main() {
    int N; cin >> N;
    int ans = 0;
    for (int a = 1; a <= N; a++) {
        for (int b = 1; b <= N; b++) {
            if (a * b >= N) break;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
s=list(map(int,input().split()))
x=list(map(int,input().split()))
y=list(map(int,input().split()))
ma, mi = -10000, 10000
for i in x:
    ma = max(ma, i)
for j in y:
    mi = min(mi, j)
ma = max(ma, s[2])
mi = min(mi, s[3])
if (ma < mi):
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    // int n;
    // cin >> n;
    // vector<int> a(n);
    // rep(i, n)
    // {
    //     cin >> a[i];
    // }

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n - 1);
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, n)
    {
        cin >> b[i];
    }
    rep(i, n - 1)
    {
        cin >> c[i];
    }

    int ans = 0;
    int prev = 0;
    rep(i, n)
    {
        ans += b[a[i] - 1];
        if (a[i] == prev + 1)
        {
            ans += c[prev - 1];
        }
        prev = a[i];
    }

    cout << ans << endl;

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  int X,A,B;
  cin >> X >> A >> B;
  if(A >= B){
  	cout << "delicious" << endl;
  }else{
  	if(A+X >= B){
    	cout << "safe" << endl;
    }else{
    	cout << "dangerous" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int main() {
    int s;
    double w, h;
    char c;
    while(cin >> s) {
        cin >> c >> w >> c >> h;
        if (w/h/h >= 25) cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1, s2;
		int dp[][];
		int max;

		while (sc.hasNext()) {
			s1 = sc.next();
			s2 = sc.next();
			dp = new int[s1.length()][s2.length()];
			max = 0;

			for (int i = 0; i < s1.length(); i++) {
				for (int j = 0; j < s2.length(); j++) {
					if (s1.charAt(i) != s2.charAt(j)) {
						dp[i][j] = 0;
					} else {
						if (i != 0 && j != 0) {
							dp[i][j] = dp[i - 1][j - 1] + 1;
						} else {
							dp[i][j] = 1;
						}
					}
					max = Math.max(max, dp[i][j]);
				}
			}

			System.out.println(max);
		}
	}
}

Measured memory_bytes: 184356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll n,m,c,arr[105],cnt1=0,sum=0,v1;
     cin>>n>>m>>c;
     for(int i=0;i<m;i++)
     {
         cin>>arr[i];
     }
     for(int i=0;i<n;i++)
     {
         for(int j=0;j<m;j++)
         {
             cin>>v1;
             sum+=(v1*arr[j]);
         }
         if(sum+c>0)
            cnt1++;
         sum=0;
     }
     cout<<cnt1<<endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <stack>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define MOD ((ll)1000000007)

int main(int argc, char const *argv[])
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	string s;
	cin >> s;

	/*
	int A = (int)(s[0] - '0');
	int B = (int)(s[1] - '0');
	int C = (int)(s[2] - '0');
	int D = (int)(s[3] - '0');
	*/

	vector<int> v(4);
	for (size_t i = 0; i < 4; i++)
	{
		v[i] = (int)(s[i] - '0');
	}

	/*
	for (size_t op1 = 0; op1 < 2; op1++)
	{
		for (size_t op2 = 0; op2 < 2; op2++)
		{
			for (size_t op3 = 0; op3 < 2; op3++)
			{
				int res = A;
				res = (op1 == 0) ? (res + B) : (res - B);
				res = (op2 == 0) ? (res + C) : (res - C);
				res = (op3 == 0) ? (res + D) : (res - D);

				if (res == 7)
				{
					cout << A << ((op1 == 0) ? "+" : "-") << B << ((op2 == 0) ? "+" : "-") << C << ((op3 == 0) ? "+" : "-") << D << "=7" << endl;
					return 0;
				}
			}
		}
	}
	*/

	for (int i = 0; i < (1 << 3); i++)
	{
		int res = v[0];
		for (int j = 0; j < 3; j++)
		{
			if (i & (1 << j))
			{
				res += v[j + 1];
			}
			else
			{
				res -= v[j + 1];
			}
		}

		if (res == 7)
		{
			cout << v[0];
			for (int j = 0; j < 3; j++)
			{
				if (i & (1 << j))
				{
					cout << "+";
				}
				else
				{
					cout << "-";
				}
				cout << v[j + 1];
			}
			cout << "=7" << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	long long int sol=0;
	int n=(int)a.size();
	for(int i=0;i<n;i++)sol+=a[i]-'0';
	if(sol%9==0)cout<<"Yes";
	else cout<<"No";
}



Measured memory_bytes: 3752
#include<stdio.h>
int main()
{
	int n;
	double v,t,y;
	while(scanf("%lf",&v)!=EOF){
		t=v/9.8;
		y=t*t*4.9;
		n=((y+5)/5)+1;
		printf("%d\n",n);
	}
	return 0;
}

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

using namespace std;

int main()
{
    int a[26],i;
    memset(a,0,sizeof(a));
    string s;
    cin>>s;
    for(i=0;i<s.length();++i)
    {
        int d=(s[i]-97);
        //cout<<d<<endl;
        a[d]++;
    }
    for(i=0;i<26;++i)
    {
        if(a[i]==0)
        {
            char d=(i+97);
            cout<<d<<endl;
            break;
        }
    }
    if(i==26)
        cout<<"None"<<endl;
    return 0;
}


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

int gcd(int x, int y) {

    if (x % y == 0) {
        return(y);
    }
    else {
        return(gcd(y, x % y));
    }
}

int main() {
    int K;
    cin >> K;

    int ans = 0;

    for (int a = 1; a < K+1; a++) {
        for (int b = 1; b < K+1; b++) {
            for (int c = 1; c < K+1; c++) {
                ans = ans + gcd(gcd(a, b), c);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3620
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

Int N;
vector<string> S;
vector<Int> P;

vector<pair<pair<string,int>,int> > v;

void solve(){
	REP(i,N)v.push_back({{S[i],-P[i]},i});
	sort(ALL(v));
	REP(i,v.size()){
		cout<<v[i].second+1<<endl;
	}
}

//{{{ main fucnction
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> N;
    S.assign(N,string());
    P.assign(N,Int());
    for(int i = 0 ; i < N ; i++){
        cin >> S[i];
        cin >> P[i];
    }
	solve();
	return 0;
}

//}}}



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

using namespace std;

void solve(long N, vector<long> d) {
  sort(d.begin(), d.end());
  long max_abc = d[N / 2 - 1];
  long min_arc = d[N / 2];
  cout << min_arc - max_abc << endl;
}

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

  long N;
  cin >> N;
  vector<long> d(N);
  for(int i = 0 ; i < N ; i++){
    cin >> d[i];
  }
  solve(N, move(d));
  return 0;
}


Measured memory_bytes: 1024
from collections import deque
s=input()
d=deque()
for i in range(len(s)):
  if len(d)>0:
    if d[len(d)-1]!=s[i]:
      d.pop()
    else:
      d.append(s[i])
  else:
    d.append(s[i])
print(len(s)-len(d))

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int K;
    cin >> K;
    string S;
    cin >> S;
    if ((int)S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
}


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

using namespace std;

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

using ll = long long;

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
    cout << '[';
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len-1) s << ", ";
	}
    cout << ']';
	return s;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
	cin >> n;

	vector<int> h(n);
	rep(i, n) cin >> h[i];

	int m = h[0];
	int cnt = 0;
	rep(i, n){
	    if(m <= h[i]){
			++cnt;
			m = h[i];
		}
	}


	ppp(cnt);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    n = s.size();
    s = ";" + s;
    vector <int> dp(n + 2);
    vector <int> cur_las(26, n + 1);
    vector <vector <int> > las(n + 1);
    for(int i = n ; i >= 0 ; i--){
        las[i] = cur_las;
        dp[i] = 1e9;
        for(int j = 0 ; j < 26 ; j++){
            dp[i] = min(dp[i], dp[cur_las[j]] + 1);
        }
        if(i > 0){
            cur_las[s[i] - 'a'] = i;
        }
    }
    string ans;
    int len = dp[0];
    int cur = 0;
    while(cur <= n){
        for(int i = 0 ; i < 26 ; i++){
            if(dp[las[cur][i]] == len - 1){
                ans += i + 'a';
                cur = las[cur][i];
                len--;
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 30860
using System;

public class Hello
{
    public static void Main()
    {
        var x = int.Parse(Console.ReadLine().Trim());
        var t = Gcd(360, x);
        Console.WriteLine(360 / t);
    }
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}


Measured memory_bytes: 27488
import scala.io.StdIn._
import scala.math._
object Main{
	def main(args: Array[String]): Unit = {
		lazy val n = readInt
		var map = Array.ofDim[Int](n + 1, n + 1)
		for(i <- 1 to n){
			  var temp = readLine.split(" ").map(_.toInt)
		    for(j <- 1 to n)map(i)(j) = map(i)(j - 1) + map(i - 1)(j) -  map(i - 1)(j - 1) + temp(j - 1)
		}
		var max = map(1)(1)
		for(i <- 1 to n ;j <- 1 to n;k <- i to n;l <- j to n){
		  var temp = map(k)(l)
		  temp += map(i - 1)(j - 1)
      temp -= map(i - 1)(l) 
		  temp -= map(k)(j - 1)
			max = math.max(max, temp)	
		}
		println(max)
  }
}

Measured memory_bytes: 53424
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,ans=0;
	int sum1=0,sum2=0,sum3=0;
	char s[100];
	scanf("%d",&N);
 
	for(int i=0;i<N;i++){
		scanf("%s",s);
		int len=strlen(s);
		for(int j=1;j<len;j++){
			if(s[j-1]=='A'&&s[j]=='B')
				ans++;
		}
		if(s[0]=='B'&&s[len-1]=='A')
			sum3++;
		else if(s[0]=='B')
			sum1++;
		else if(s[len-1]=='A')
			sum2++;
	}
	ans+=min(sum1,sum2);
	if(sum1==0&&sum2==0&&sum3){
		sum3--;
	}
	ans+=sum3;
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
S=input()

ans1=0
for i in range(1,len(S)):
  if S[i-1]!=S[i]:
    ans1+=1
S=S[::-1]
ans2=0
for i in range(1,len(S)):
  if S[i-1]!=S[i]:
    ans2+=1
print(min(ans1,ans2))

Measured memory_bytes: 3188
#include<iostream>
#include<map>

using namespace std;
typedef long long ll;

map<ll, int> memo;
ll ruisekiwa[100001];
int N;
ll M;

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		ll tmp;
		cin >> tmp;
		ruisekiwa[i + 1] = ruisekiwa[i] + tmp; ruisekiwa[i + 1] %= M;
	}

	ll ans = 0;
	memo[0]++;
	for (int i = 0; i < N; i++) {
		ans += memo[ruisekiwa[i + 1]];
		memo[ruisekiwa[i + 1]]++;
	}

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

Measured memory_bytes: 4992
K,N = map(int,input().split())
A = list(map(int,input().split()))
A_max = K + A[0] - A[N-1]
for i in range(1,N):
    A_diff = A[i] - A[i-1]
    if A_diff >A_max:
        A_max = A_diff

print(K-A_max)



Measured memory_bytes: 25840
# frozen_string_literal: true

k, n = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
a.push k + a[0]
b = []
(1..n).each do |i|
  b.push a[i] - a[i - 1]
end

m = b.index(b.max)

b.delete_at(m)
puts b.reduce(:+)


Measured memory_bytes: 19076
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

void printvec(const std::vector<int>& vec) {
    for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << " "; } std::cout << std::endl;
}

const int MAX_N = 100;
int N;
int p[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;
    int cnt = 0;
    rep (i, 1, N) {
        std::cin >> p[i];
        if (p[i] != i) {
            cnt++;
        }
    }

    if (cnt <= 2) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}

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

using namespace std;

const int MAX_N = 2e3 + 5;
const int ZERO = 2e5 + 5e4;
const int MAX_B = 5e5 + 5;

int arr [MAX_N];

vector<char> _last;
char& last (int j) {
  return _last[j + ZERO];
}

vector<char> _dp;
char& dp (int j) {
  return _dp[j + ZERO];
}

int main () {
  int n;
  cin >> n;

  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  random_shuffle(arr, arr + n);

  _dp = vector<char> (MAX_B, 0);
  dp(0) = 1;
  for (int i = 0; i < n; i++) {
    _last = _dp;
    _dp = vector<char> (MAX_B, 0);
    for (int j = -ZERO; j <= ZERO; j++) {
      if (last(j)) {
        if (j - arr[i] >= -ZERO) {
          dp(j - arr[i]) = 1;
        }
        if (j + arr[i] <= ZERO) {
          dp(j + arr[i]) = 1;
        }
      }
    }
  }

  for (int i = 0; i <= ZERO; i++) {
    if (dp(i)) {
      cout << (sum + i) / 2 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 1704
class NormalInput{
  input: string[];
  pointer: number;
  constructor(raw:string){
    this.input=raw.split(/ |\n/);
    this.pointer=0;
  }
  int():number{
    const ret= parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  }
  str():string{
    const ret= this.input[this.pointer];
    this.pointer++;
    return ret;
  }
  strs(length:number):string[]{
    let ret:string[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.str());
    }
    return ret;
  }
  ints(length:number):number[]{
    let ret:number[]=[];
    for(let i=0;i<length;i++){
      ret.push(this.int());
    }
    return ret;
  }
}
function arrayOfEmptyArray(size:number){
  let arr=Array(size);
  for(let i=0;i<size;i++){
    arr[i]=[];
  }
  return arr;
}
class Tree{
  node:number;
  neighber:number[][];
  constructor(node:number, neighber:number[][]){
    this.node=node;
    this.neighber=neighber;
  }
  addEdge(a:number,b:number){
    this.neighber[a].push(b);
    this.neighber[b].push(a);
  }
  getNeighber(x:number){
    return this.neighber[x];
  }
  static fromEdges(node:number , edges:[number,number][]){
    let tree=new Tree(node, arrayOfEmptyArray(node));
    edges.forEach(([a,b])=>{
      tree.addEdge(a,b);
    })
    return tree;
  }
}
function Main(_: NormalInput) {
  const N=_.int();
  let edges:[number,number][]=[];
  for(let i=0;i<N-1;i++){
    edges.push([_.int()-1,_.int()-1]);
  }
  const c=_.ints(N);
  c.sort((a,b)=>a-b);
  let sum=c.reduce((a,b)=>a+b,0)-c[c.length-1];
  let ans=Array(N);
  const tree=Tree.fromEdges(N,edges);
  // const dfs=(x:number, visited?:number)=>{
  //   let nextC=c.pop();
  //   ans[x]=nextC;
  //   // console.log(x,nextC);
  //   tree.getNeighber(x).forEach(
  //     (next)=>{
  //       if(visited===next)return;
  //       dfs(next,x);
  //     }
  //   )
  // };
  // dfs(0);
  let stack=[[0,undefined]];
  while(true){
    if(stack.length==0)break;
    let [x,visited]=stack.pop();
    let nextC=c.pop();
    ans[x]=nextC;
    // console.log(x,nextC);
    tree.getNeighber(x).forEach(
      (next)=>{
        if(visited===next)return;
        stack.push([next,x]);
      }
    )
  }
  
  console.log(sum);
  console.log(ans.join(" "));
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 28060
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int H, W;
	cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	REP(i, H)REP(j, W) cin >> a[i][j];
	stack<P> st;
	st.push(P(0, 0));
	vector<vector<bool>> used(H, vector<bool>(W, false));
	used[0][0] = true;
	vector<vector<int>> res;
	vector<int> di = { 1,0,-1,0 };
	vector<int> dj = { 0,1,0,-1 };
	while (!st.empty()) {
		int i0 = st.top().first;
		int j0 = st.top().second;
		REP(k, 5) {
			if (k < 4) {
				int i = i0 + di[k];
				int j = j0 + dj[k];
				if (i >= 0 && i < H&&j >= 0 && j < W && !used[i][j]) {
					used[i][j] = true;
					st.push(P(i, j));
					if (a[i0][j0] % 2 == 1) {
						a[i][j]++;
						res.push_back({ i0,j0,i,j });
					}
					break;
				}
			}
			else st.pop();
		}
	}
	cout << res.size() << "\n";
	REP(i, res.size()) {
		REP(j, 4) {
			if (j < 3) cout << res[i][j] + 1 << " ";
			else cout << res[i][j] + 1 << "\n";
		}
	}

	return 0;
}

Measured memory_bytes: 12208
#include<iostream>
using namespace std;
int main()
{
	int r,g,b,n;
	int f=0;
	cin >>r>>g>>b>>n;
	for(int i=0;i<=n/r;i++) {
		for(int j=0;j<=n/g;j++){
//			for(int k=0;k<=n/b;k++)
//			if(i*r+j*g+k*b==n) f++;
			if((n-i*r-j*g)%b==0&&n-i*r-j*g>=0) {
				f++;
				//cout <<i <<" "<<j<<" "<<(n-i*r-j*g)/b<<endl;	
			}
		}
	}
	cout << f;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[200005];
ll b[200005];
int main(){
	//freopen("in.txt","r",stdin);
	ll n,m,k;
	cin>>n>>m>>k;
	a[0] = 0;
	b[0] = 0;
	for(ll i=1;i<=n;i++){
		ll tmp;
		cin>>tmp;
		a[i] = a[i-1] + tmp;
	}
	for(ll j=1;j<=m;j++){
		ll tmp;
		cin>>tmp;
		b[j] = b[j-1] + tmp;
	}
	ll ans = 0;
	ll j = m;
	ll i;
	for(i=0;i<=n;i++){
		while(a[i] + b[j] > k and j>=0){
			j--;
		}
		if(a[i] + b[j] <= k) {
			ans = max(ans , i+j);
			//cerr<<j<<endl;
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

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

int n, s[110];
int sum;
int mn = 1e9;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> s[i], sum += s[i];
		if (s[i] % 10) mn = min(mn, s[i]);
	}
	if (sum % 10 == 0) sum -= mn;
	cout << max(0, sum) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int w, h, x, y, r;
    cin>>w>>h>>x>>y>>r;
    if(w<(x+r)|h<(y+r)|0>(x-r)|0>(y-r))cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}



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

int main() {
	cin >> n;

	long long ans = LLONG_MAX;
	for (long long x = 1; x * x <= n; x++) {
		if (n % x) continue;
		long long can = x + n / x;
		ans = min(ans, can);
	}

	cout << ans - 2 << '\n';

	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v.at(i);
    }

    sort(v.begin(), v.end());
    double ans = v.at(0);

    for (int i = 1; i < N; i++) {
        ans = (ans + v.at(i)) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    ll H, N;
    cin >> H >> N;
    vector<ll> A;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    int all_atack = accumulate(A.begin(), A.end(), 0);
    // cout << all_atack << "\n";
    if (H - all_atack <= 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <iostream>
using namespace std;
int xx[110][110];
int main(){
    int h,w,n,x=0;
    cin>>h>>w>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            if((x/w)%2==0) xx[x/w][x%w]=i+1;
            else xx[x/w][w-(x%w)-1]=i+1;
            x++;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(j==w-1) printf("%d\n",xx[i][j]);
            else printf("%d ",xx[i][j]);
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint32 n;
	std::cin >> n;
	std::vector<uint32> a(n);
	rep(i, 0, n) {
		std::cin >> a[i];
		--a[i];
	}
	uint32 ans = 0;
	rep(i, 0, n) {
		if (a[a[i]] == i) {
			++ans;
		}
	}
	std::cout << (ans >> 1) << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			if (mod <= ans * x) ans = ans * x % mod;
			else ans *= x;
		}
		if (mod <= x * x) x = x * x % mod;
		else x *= x;
		n >>= 1;
	}
	return ans;
}

int fact_memo[114514];
int fact(int n) {
	int ans = 1;
	if (fact_memo[n]) return fact_memo[n];
	rep(i, n) {
		ans *= (i + 1);
		if (mod <= ans) ans %= mod;
	}
	fact_memo[n] = (ans + mod) % mod;
	return (ans + mod) % mod;
}

int comb(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) + mod) % mod;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	return (fact(n) * modpow(fact(n - r), mod - 2) % mod + mod) % mod;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}

bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int n, k;
signed main() {
	cin >> n >> k;
	for (int i = 1; i <= k; i++) {
		if (i == 1) {
			printf("%lld\n", n - k + 1);
		}
		else {
			int cnt = 0;
			rep(j, n - k) {
				int r = n - k - j;
				if (r < i - 1) break;
				cnt += (j + 1) * comb(r - 1, i - 2);
				if (mod <= cnt) cnt %= mod;
			}
			cnt *= comb(k - 1, i - 1);
			if (mod <= cnt) cnt %= mod;
			printf("%lld\n", cnt);
		}
	}
}

Measured memory_bytes: 256
const double = Float64
const int = Int64
const vint = Vector{int}
const vdouble = Vector{double}

int(x) = parse(int,x)

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))


function main()
  n,m = readint()
  
  flag = 1
  for i in 0:m-1
    if i%2==0
      println(1+ i÷2, " ", 1 + m - div(i,2))
    else
      println(m + 2 + div(i,2), " ", 2m + 1 - div(i,2) )
    end
  end 
end

main()

Measured memory_bytes: 222124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

  // 広義減少列問題に帰着させる。

  multiset<ll> st;
  st.insert(a[n-1]);
  int ans = 1;
  for (int i = n-2; i >= 0; --i) {
    auto it = st.upper_bound(a[i]);
    if (it == st.end()) {
      st.insert(a[i]);
      ans += 1;
    } else {
      st.erase(it);
      st.insert(a[i]);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
bool edge[51][51];
bool visited[51];
int n,m;

void dfs(int v){
  visited[v]=true;
  REP(v2, n){
    if(edge[v][v2]==false)continue;
    if(visited[v2]==true)continue;
    dfs(v2);
  }
}

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>n>>m;
  int a[51],b[51];
  REP(i,m){
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
    edge[a[i]][b[i]]=true;
    edge[b[i]][a[i]]=true;
  }
  int ans=0;
  REP(i,m){
    edge[a[i]][b[i]]=false;
    edge[b[i]][a[i]]=false;

    REP(j,51)visited[j]=false;
    dfs(0);
    bool flag=false;
    REP(j,n)if(visited[j]==false)flag=true;
    if(flag)ans++;

    edge[a[i]][b[i]]=true;
    edge[b[i]][a[i]]=true;
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;



ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a,ll b) {
	return a / gcd(a, b) * b;
}


int main() {
	int i, j, k;
	ll N, M, K;
	ll ans = 0;

	ll H;
	
	vector<int> A;
	cin >> H >> N;
	rep(i, 0, N) {
		int a;
		cin >> a;
		ans += a;
	}
	if (ans >= H)cout << "Yes";
	else cout << "No";

	return 0;


}


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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debp(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	int n, k;
	cin >> n >> k;
	map<int, int> m;
	for (int i = 0; i < k; i++) {
		int x; cin >> x;
		for (int i = 0; i < x; i++) {
			int a; cin >> a;
			m[a]++;
		}
	}
	cout << n - size(m) << endl;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

struct Node{
	int val;
	int wt;
	char type;
	i64 data;
	string name;
};
bool comp(Node& a, Node& b){
	if(a.val < b.val)return true;
	else if(a.val > b.val)return false;
	else {
		if(a.wt < b.wt)return true;
		else if(a.wt > b.wt)return false;
		else{
			if(a.type < b.type)return true;
			else if(a.type > b.type)return false;
			else {
				if(a.data < b.data)return true;
				else if(a.data > b.data)return false;
				else {
					return a.name < b.name;
				}
			}
		}
	}
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
  
	int n;
	cin >> n;
	vector<Node> a;
	for(int i = 0; i < n; i++){
		Node x;
		cin >> x.val >> x.wt >> x.type >> x.data >> x.name;
		a.push_back(x);
	}
	sort(a.begin(), a.end(), comp);
	for(auto i:a){
		cout << i.val << ' ' << i.wt << ' ' << i.type << ' ' << i.data << ' ' << i.name << '\n';
	}
    return 0;
}



Measured memory_bytes: 11152
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

//整数Tに対しenough(T)をT回以内の爆発ですべての魔物を消すことは可能か？という問いの答え
//とする。求めたい答えはenough(T)=YesであるようなTの最小値です。enoughは単調性を持つため
//この最小値を二分探索で求めることができる
//定められたTの値に対してenough(T)を判定するには爆発を起こすことを以下のようにとらえなおす
//すべての魔物の体力をBずつ減らし魔物を一体選んでその体力をさらにA-B減らす
//するとT回の爆発を起こすことはすべての魔物の体力をB*T減らしその上でT回にわたって
//一体の魔物の体力をA-B減らすことと同等すべての魔物を消すには体力がB*Tより高い魔物
//iにそれぞれに対して追加ダメージを[(hi-B*T)/(A-B)]回与える必要がありこの回数の合計が
//T以下であればenough(T)=Yes,合計がTを超える場合はenough(T)=Noと判定できます

ll N, A, B;
ll h[100100];
bool ok(ll k) {
	ll cnt = 0;
	ll sa = A - B;
	for (int i = 0; i < N; ++i) {
		if (h[i] > B*k) {
			cnt += (h[i] - B * k + (A - B) - 1)/ (A - B);
		}
	}
	return (cnt <= k);
}
int main() {
	cin >> N >> A >> B;
	REP(i, N)cin >> h[i];
	ll l = 0;
	ll r = 1e9+10;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (ok(mid)) {
			r = mid;
		}
		else {
			l = mid;
		}
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const int MOD = 1000000007;

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

    int N;
    cin >> N;
    vector<int> num(N, 0);
    Rep (i, N) {
        int a;
        cin >> a;
        num[a]++;
    }

    ll ans = 1;

    if (N % 2) {
        if (num[0] != 1) {
            cout << 0 << "\n";
            return 0;
        }
        for (int i = 2; i < N; i += 2) {
            if (num[i] != 2) {
                cout << 0 << "\n";
                return 0;
            } else {
                ans *= 2;
                ans %= MOD;
            }
        }
    } else {
        for (int i = 1; i < N; i += 2) {
            if (num[i] != 2) {
                cout << 0 << "\n";
                return 0;
            } else {
                ans *= 2;
                ans %= MOD;
            }
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 640
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, d[MAXN], trace[MAXN];
vector<int> a[MAXN];
queue<int> q;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) {
        int u, v;
        cin >> u >> v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    FOR(i,1,n) d[i] = 1000000000;
    d[1] = 0;
    q.push(1);
    while (SZ(q)) {
        int u = q.front(); q.pop();
        FOR(i,0,SZ(a[u])-1) {
            int v = a[u][i];
            if (d[v] > d[u] + 1) {
                d[v] = d[u] + 1;
                trace[v] = u;
                q.push(v);
            }
        }
    }
    cout << "Yes\n";
    FOR(i,2,n) cout << trace[i] << "\n";
    return 0;
}


Measured memory_bytes: 10924
#include<stdio.h>
#include<stdlib.h>

int main(void){

  int i, j, k=0, u=0, t=0, flag=0;
  char *s1, *s2, *p;

  s1 = (char *)malloc(sizeof(char)*101);
  p = (char *)malloc(sizeof(char)*101);
  s2 = (char *)malloc(sizeof(char)*202);


  scanf("%s", s1);
  scanf("%s", p);
//  sprintf(s2, "%s%s\n", s1, s1);

  i = 0;
  while(p[t] != '\0'){
    t++;
  }


  while(s1[i] != '\0'){
    s2[i] = s1[i];
    i++;
  }
  for(j=0;j<i;j++){
    s2[i+j] = s1[j];
  }


  while(u < i+j){

    if(flag == 1){
      break;
    }
    if(s2[u] == p[0]){
      for(k=0;k<t;k++){
        if(s2[u+k] != p[0+k]){
          break;
        }
      }
      if(k == t){
        flag = 1;
      }
    }
    u++;
  }

  free(s1);
  free(s2);
  free(p);

  if(flag == 1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}



Measured memory_bytes: 2100
// ワーシャル フロイド法
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

const int MAX_V = 100;
const int MAX_E = 9900;
const int INF = 0x7FFFFFFF;

int main(void)
{

    int V, E;
    int first, second, weight;
    bool b_negativeLoop = false;

    // 辺の重みを格納する配列
    int edgeWeight[MAX_V + 1][MAX_V + 1];

    for(int i = 0; i < MAX_V; i++)
    {
        for(int j = 0; j < MAX_V; j++)
        {
            if( i == j )
            {
                edgeWeight[i][j] = 0;
            }
            else
            {
                // 初期値として, 無効値を代入
                edgeWeight[i][j] = INF;
            }

        }
    }

    cin >> V >> E;

    for(int i = 0; i < E; i++)
    {
        cin >> first >> second >> weight;

        edgeWeight[first][second] = weight;
    }

    // ワーシャル フロイド法の実施
    for(int k = 0; k < V; k++)          // 経由する頂点
    {
        for(int i = 0; i < V; i++)      // 開始頂点
        {
            for(int j = 0; j < V; j++)  // 終了頂点
            {
                if( edgeWeight[i][k] != INF && edgeWeight[k][j] != INF )
                {
                    // 最短経路の探索
                    edgeWeight[i][j]
                        = min(edgeWeight[i][j], edgeWeight[i][k] + edgeWeight[k][j]);
                }
            }
        }
    }

    // 負の閉路の探索
    for(int p = 0; p < V; p++)
    {
        if( edgeWeight[p][p] < 0 )
        {
            // 負の閉路が存在する
            b_negativeLoop = true;
            printf("NEGATIVE CYCLE\n");
            break;
        }
    }

    if( b_negativeLoop == false )
    {
        // 結果の表示
        for(int i = 0; i < V; i++)
        {
            for(int j = 0; j < V; j++)
            {
                if( j != 0 )
                {
                    printf(" ");
                }

                if( edgeWeight[i][j] == INF )
                {
                    printf("INF");
                }
                else
                {
                    printf("%d", edgeWeight[i][j]);
                }
            }

            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 3256
N = int(input()) 
DP = [10000000]*(2*N+1)
DP[0] = 0
for i in range(0, N+1):
  DP[i+1] = min(DP[i+1],DP[i]+1)
  s = 6
  while s <= N:
    DP[i + s] = min(DP[i + s],DP[i]+1) 
    s = s*6
  n = 9
  while n <= N:
    DP[i + n] = min(DP[i + n],DP[i]+1)  
    n = n*9
print(DP[N])

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int cmd, index, val, dst;
  int num_query, num_list;

  cin >> num_list >> num_query;
  list<int> lst[num_list];

  for (int i = 0; i < num_query; i++) {
    cin >> cmd;
    switch (cmd) {
      case 0:
        cin >> index >> val;
        lst[index].push_back(val);
        break;

      case 1:
        cin >> index;
        if (lst[index].empty()) {
          cout << endl;
        } else {
          for (auto itr = lst[index].begin(); itr != prev(lst[index].end(), 1); itr++) {
            cout << *itr << " ";
          }
          cout << lst[index].back() << endl;
        }

        break;

      case 2:
        cin >> index >> dst;
        lst[dst].splice(lst[dst].end(), lst[index]);
        lst[index].clear();
        break;
    }
  }
}




Measured memory_bytes: 18764