akhauriyash/Code-Regression huggingface dataset:
def main():
    W, H, N = map(int, input().split())

    xl, xh = 0, W
    yl, yh = 0, H
    for _ in range(N):
        x, y, a = map(int, input().split())
        if a == 1:
            xl = max(xl, x)
        elif a == 2:
            xh = min(xh, x)
        elif a == 3:
            yl = max(yl, y)
        else:
            yh = min(yh, y)

    s = max(0, xh - xl) * max(0, yh - yl)

    print(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <limits>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int a,b,c,x;
    cin >> a >> b >> c >> x;

    int count = 0;
    for(int i = 0; i <= a; ++i)
        for(int j = 0; j <= b; ++j)
            for(int k = 0; k <= c; ++k)
                if(500*i + 100*j + 50*k == x) count++;
    cout << count << '\n';
    return 0;
}


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

int main() {
    string S;
    cin>>S;
    int cnt_even=0, cnt_odd=0;
    vi ans(S.size(),0);
    for (int i = 0; i < S.size(); i++){
        if(S[i]=='R'){
            if(i%2==0)cnt_even++;
            else cnt_odd++;
        }else{
            if(i%2==0){
                ans[i]+=cnt_even;
                ans[i-1]+=cnt_odd;
            }else{
                ans[i]+=cnt_odd;
                ans[i-1]+=cnt_even;
            }
            cnt_even=0;
            cnt_odd=0;
        }
    }
    for (int i = S.size()-1; i>=0; i--){
        if(S[i]=='L'){
            if(i%2==0)cnt_even++;
            else cnt_odd++;
        }else{
            if(i%2==0){
                ans[i]+=cnt_even;
                ans[i+1]+=cnt_odd;
            }else{
                ans[i]+=cnt_odd;
                ans[i+1]+=cnt_even;
            }
            cnt_even=0;
            cnt_odd=0;
        }
    }
    for(auto x:ans)cout<<x<<" ";
    cout<<endl;
}

Measured memory_bytes: 3820
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=n-1;i>0;i--){
        cout<<a[i]<<" ";
    }
    cout<<a[0]<<endl;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
  }

  ll ans = -1;
  ll total = accumulate(all(a), 0);

  if (total > n) {
    ans = -1;
  } else {
    ans = n - total;
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3700
city=int(input())
a=input().split(" ")
b=input().split(" ")
monster=[]
hero=[]
for p in a:
    monster.append(int(p))
for q in b:
    hero.append(int(q))
max=0
for s in range (0,city):
    if monster[s]-hero[s]>=0:
        max+=hero[s]
    elif monster[s+1]+monster[s]-hero[s]>0:
        max+=hero[s]
        monster[s+1]-=hero[s]-monster[s]
    else:
        max+=monster[s+1]+monster[s]
        monster[s+1]=0
print(max)

Measured memory_bytes: 25536
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<float.h>
using namespace std;


int main() {
    char a, b,c,d,e,f;
    cin >> a >> b ;
    if (a < b)cout << "<" << endl;
    else if (a > b)cout << ">" << endl;
    else cout << "=" << endl;
  
    return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()

ans = 0
for a, b in AB:
  if M == 0: break
  if M >= b:
    ans += a * b
    M -= b
  else:
    ans += a * M
    M = 0
    break
print(ans)

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

using ll = long long;
#define sz(x) ((int)x.size())
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int N=3e5;
int n;
ll a[N];

int main() {
	fastio();
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	multiset<pair<int, int>>P;
	P.insert({a[1],a[0]});
	ll ans=a[0];
	if(n==2){
		cout<<ans<<'\n';
		return 0;
	}
	ans+=a[1];
	P.insert({a[2],a[1]});
	P.insert({a[2],a[0]});
	for(int i=3;i<n;++i){
		auto it = prev(P.end());
		auto p = *it;
		ans += p.first;
		P.erase(it);
		P.insert({a[i],p.first});
		P.insert({a[i],p.second});
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 14552
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -MOD * MOD;
const long double pi = 3.141592653589793;
ll fac[1100000];
ll finv[1100000];
ll inv[1100000];
void modinv(int max) {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < max; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int r) {
	if (n < r) return 0;
	if (n < 0 || r < 0) return 0;
	return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}
int main() { // 問題文はしっかり読め!!!
	modinv(1001001);
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3) {
		cout << 0 << endl;
		return 0;
	}
	int Y = (x * 2 - y) / 3;
	int X = x - 2 * Y;
	cout << comb(X + Y, X) << endl;
	return 0;
}

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

typedef long long ll;
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % mod;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

int main() {
        int m, n; cin >> m >> n;
        
        ll ret;
        ret = mod_pow(m,n,1000000007);
        cout << ret << endl;
        return 0;
}

Measured memory_bytes: 1160
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            //var K = long.Parse(Console.ReadLine());
            //var c = Console.ReadLine();
            var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var P = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

            var ans = 0L;
            var N = NK[0];
            var K = NK[1];

            Sort(P);

            for (int i = 0; i < K; i++)
            {
                ans += P[i];
            }


                Console.WriteLine(ans);
            
            

        }
    }

}


Measured memory_bytes: 28584
#include<cstdio>
 
int main()
{
	int X;
	scanf("%d", &X);
    long pow5[240];
    for (int i = 0; i < 120; i++)
    {
        long x = i;
        pow5[120+i] = x * x * x * x * x;
        pow5[120-i] = -pow5[120+i];
    }
	for (int A = 0; A < 120; ++A) {
      	for (int B = -120; B < A; ++B) {
			if (pow5[120+A] - pow5[120+B] == X)
			{
				printf("%d %d", A, B);
				return 0;
            }
		}
    }
}


Measured memory_bytes: 1736
import java.util.*;


public class Main {
	
	private long calc(long num){
		String s = num + "";
		long n = num;
		long sum = 0;
		for(int i = 0; i < s.length(); i++){
			sum += n % 10;
			n /= 10;
		}
		return sum;
	}
	
	private long pow(long n){
		long sum = 1;
		for(int i = 0; i < n; i++){
			sum *= 10;
		}
		return sum;
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			long n = sc.nextLong();
			String s = n + "";
			long max = calc(n);
			for(int i = 0; i < s.length(); i++){
				long dif = n % pow(i+1) + 1;
				max = Math.max(max, calc(n - dif));
			}
			System.out.println(max);
			
			
			
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 21972
//chiragjn
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define gibe_de_fast_io_b0ss ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF/2;
int main(){
    gibe_de_fast_io_b0ss;
    int n, k;
    cin>>n>>k;
    if(n >= (k + k - 1)) {
        cout<<"YES";
    }
    else {
        cout<<"NO";
    }
    return 0;
}

Measured memory_bytes: 256
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using II = pair<int,int>;
using VII = vector<II>;
using VVII = vector<VII>;

int main(){
	int N; cin>>N;
	int x, y;

	//証言が"確実"か、"不確定"か。(正解100%か未満か)
	VVII A(N, VII());
	rp(i, 0, N){
		int a; cin>>a;
		while(a--){ cin>>x>>y; x--; A[i].emplace_back(x,y); }
	}

	// rp(i,0,N){cout<<i<<") ";for(auto e:A[i]){cout<<"("<<e.first<<" "<<e.second<<") ";}puts("");}puts("--");//

	int ans = 0;
	rp(bits, 1, 1<<N){//bits: 仮定のbit列: 0|1=不確実|確実
		bool ok = true;//true|false=仮定に矛盾なし|あり
		rp(i, 0, N){
			int assume_i = (bits>>i)&1;//i番目の仮定: 0|1
			if(!assume_i) continue;//不確実: 確認のしようがない
			rp(j, 0, A[i].size()){
				//y: i番目のx番に対する証言: 0|1=不確実|確実
				tie(x,y) = A[i][j];
				int assume_x = (bits>>x)&1;//x番目の仮定: 0|1
				if(assume_x ^ y) ok = false;//矛盾
			}
		}
		if(ok) ans = max(ans, (int)bitset<16>(bits).count());//矛盾なし: 仮定から最大数を得る
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
w_array = []
used_array = []
flag = true

N.times do |i|
  w_array << gets.chomp
end

w_array.each_with_index{|item, idx|
  unless idx == 0
    if used_array.include?(w_array[idx])
      flag = false
    end

    unless w_array[idx-1].split("")[-1] == w_array[idx].split("")[0]
      flag = false 
    end
  end

  used_array << item
}

if flag
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1916
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)

score = 0
keep = Float::INFINITY

A.each do |i|
  score += B[i - 1]
  if keep + 1 == i
    score += C[keep - 1]
  end
  keep = i
end

puts score

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++)
    cin >> a.at(i);
  int t=0;
  for(int i=0;i<N-1;i++){
    if(a.at(i)==a.at(i+1)){
      t++;
      a.at(i+1)=101;
    }
  }
  cout << t << endl;
       
}


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

int main()
{
    int s[3];
    for(int i=0;i<3;i++)
        scanf("%d",&s[i]);
    sort(s,s+3);
    int sum=s[0]+s[1];
    int k;
    scanf("%d",&k);
    while(k--)
    {
        s[2]*=2;
    }
    sum+=s[2];
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

//二項係数の計算前処理（KとNが10^7程度）
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
  COMinit();
  int N, K;
  cin >> N >> K;

  int ans = 0;
  for( int i = 1; i <= K; i++ ){
    int blue = COM(K-1, i-1);
    int red = COM(N-K+1, i);
    int A = (blue*red)%MOD;
    cout << A << endl;
  }

}


Measured memory_bytes: 12160
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  int n;
  ll y;
  cin>>n>>y;
  int a=-1,b=-1,c=-1;
  //n*10000<y -> no
  //n*1000>y -> no

  for(int i=n;i>=0;i--){
    for(int j=n-i;j>=0;j--){
      int k=n-i-j;
      ll sum = 1000*i+5000*j+10000*k;
      if(sum == y){
        c = i;
        b = j;
        a = k;
        break;
      }
    }
  }

  cout << a << " " << b <<" "<< c << endl;
}


Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

h,w=map(int,input().split())
s=[input() for i in range(h)]

d=deque([[0,0]])
itta=[[float('inf')]*w for i in range(h)]
if s[0][0]=="#":
    itta[0][0]=1
else:
    itta[0][0]=0

# print(itta)
ans=0
for i in range(h+w-2):
    # print(itta)
    for j in range(len(d)):
        now=d.popleft()
        nh,nw=now
        cnt=itta[nh][nw]
        if nh+1<h:
            tmp=cnt
            if s[nh][nw]=="." and s[nh+1][nw]=="#":
                tmp+=1
            if itta[nh+1][nw]==float('inf'):
                d.append([nh+1,nw])
            itta[nh+1][nw]=min(itta[nh+1][nw],tmp)
        if nw+1<w:
            tmp=cnt
            if s[nh][nw]=="." and s[nh][nw+1]=="#":
                tmp+=1
            if itta[nh][nw+1]==float('inf'):
                d.append([nh,nw+1])
            itta[nh][nw+1]=min(itta[nh][nw+1],tmp)

# print(itta)
# for i in range(len(d)):
print(itta[-1][-1])

Measured memory_bytes: 72296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(int i=0; i<(int)c; i++)
int main() {
	int n,l;
//	vector<string>s(n);
	vector<string>a;
	string ans,s1;

	cin >>n>>l;

	for(int i=0;i<n;i++){
		cin >> s1;
		a.push_back(s1);
	}
	sort(a.begin(),a.end());
	for (int j=0;j<n;j++){
		ans+=a[j];
	}
	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++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    ll n;
    cin >> n;
    ll nsqrt = ceil(sqrt(n));
    ll ans = 10e12;

    rem(i, 1, nsqrt + 1)
    {
        if (n % i == 0)
        {
            ans = min(ans, (i - 1) + (n / i - 1));
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  set<int> st;
  rep(i,n){
    int k;cin >> k;
    st.insert(k);
  }
  int ans = 0;
  for(auto&i:st) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  char a,b,c;str s;
  int mi=9999;
  cin>>s;
  int n=s.size();
  int cur=0;
  rep(i,n-2){
    a=s[i];b=s[i+1];c=s[i+2];
    a-=48;b-=48;c-=48;
    cur=100*a+10*b+c;cerr<<cur<<' ';
    mi=min(abs(cur-753),mi);
  }
  cout<<mi;
}

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

bool compareVector(pair<int, int> a, pair<int, int> b) {
  return a.second < b.second;
}

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

  int n;
  cin >> n;

  vector<pair<int, int>> a(n);

  for (int i = 0; i < n; i++) {
    pair<int, int> p;

    int ai;
    cin >> ai;

    p.first = i;
    p.second = ai;
    a.at(i) = p;
  }

  sort(a.begin(), a.end(), compareVector);

  for (int i = 0; i < n - 1; i++) {
    cout << a.at(i).first + 1 << " ";
  }
  cout << a.at(n - 1).first + 1 << endl;

  return 0;
}

Measured memory_bytes: 1664
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0
f = 10**9
for i in range(n):
    ans += b[a[i]-1]
    if a[i] - f == 1:
        ans += c[a[i-1]-1]
    f = a[i]
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

bool query(ll q) {
	cout << "? " << q << endl;
	string s;
	cin >> s;
	return s == "Y";
}

void FA(int ans) {
	cout << "! " << ans << endl;
	exit(0);
}

int main() {
	ll ans = 0;
	bool tenbeki = true;
	for (;;) {
		int left = -1;
		int right = 9;
		// (left, right]
		while (right - left > 1) {
			if (ans == 0 && right == 1) break;
	// pr(left);
	// pr(right);
			int mid = (right + left) / 2;
			ll temp = ans * 10 + mid;
			while (temp < MOD) temp = temp * 10 + 9;
			bool q = query(temp);
			if (q) right = mid;
			else left = mid;
		}
		if (right > 1 || ans > 0 && right != 0) tenbeki = false;
		if (right == 0) {
			if (query(ans * 10 - 1) ^ !tenbeki) {
				FA(ans);
			}
		}
		ans = ans * 10 + right;
	}
	return 0;
}


Measured memory_bytes: 596
#include <iostream>

using namespace std;

int main() {
  long h;
  cin >> h;

  long sum = 0;
  long cnt = 1;
  while(h != 0) {
  	h /= 2;
  	sum += cnt;
  	cnt *= 2;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX_A 20

int n;
int A[MAX_A];

int solve(int i, int m) {
  if (i >= n) {
    return m == 0;
  }
  if (solve(i+1, m)) {
    return 1;
  }
  if (solve(i+1, m-A[i])) {
    return 1;
  }
  return 0;
}
  


int main(void) {
  int i;
  int q;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    int M;
    scanf("%d", &M);
    if (solve(0, M)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int digits(ll n) {
	int count = 0;
	while (n > 0) {
		n /= 10;
		count++;
	}
	return count;
}
int main() {
	int n;
	cin >> n;
	vector<int>alpha(26);
	rep(i, n) {
		string s;
		cin >> s;
		vector<int>tmp(26);
		rep(j, s.size()) {
			int a = s[j];
			a -= 97;
			if (i == 0) {
				alpha[a]++;
			}
			tmp[a]++;
		}
		rep(j, 26) {
			alpha[j] = min(alpha[j], tmp[j]);
		}
	}
	rep(i, 26) {
		char a = 'a' + i;
		rep(j, alpha[i]) {
			cout << a ;
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;
use proconio::marker::Chars;
use std::collections::vec_deque::VecDeque;

fn main() {
    input! {
        h: usize,
        w: usize,
        ch: usize,
        cw: usize,
        dh: usize,
        dw: usize,
        c: [Chars; h],
    }
    let mut worp_num = vec![vec![std::u64::MAX; w]; h];
    let mut deque = VecDeque::new();
    worp_num[ch - 1][cw - 1] = 0;
    deque.push_back((ch - 1, cw - 1));
    while let Some(base_pt) = deque.pop_front() {
        // println!("base: {:?}", base_pt);
        for i in -1..2 {
            let h_updated = base_pt.0 as isize + i;
            if h_updated < 0 || h_updated >= h as isize {
                continue;
            }

            if c[h_updated as usize][base_pt.1] == '#' {
                continue;
            }

            if worp_num[base_pt.0][base_pt.1] < worp_num[h_updated as usize][base_pt.1] {
                worp_num[h_updated as usize][base_pt.1] = worp_num[base_pt.0][base_pt.1];
                deque.push_front((h_updated as usize, base_pt.1));
            }
        }
        for i in -1..2 {
            let w_updated = base_pt.1 as isize + i;
            if w_updated < 0 || w_updated >= w as isize {
                continue;
            }

            if c[base_pt.0][w_updated as usize] == '#' {
                continue;
            }

            if worp_num[base_pt.0][base_pt.1] < worp_num[base_pt.0][w_updated as usize] {
                worp_num[base_pt.0][w_updated as usize] = worp_num[base_pt.0][base_pt.1];
                deque.push_front((base_pt.0, w_updated as usize));
            }
        }

        for i in -2..3 {
            let h_updated = base_pt.0 as isize + i;
            if h_updated < 0 || h_updated >= h as isize {
                continue;
            }

            for j in -2..3 {
                let w_updated = base_pt.1 as isize + j;
                if w_updated < 0 || w_updated >= w as isize {
                    continue;
                }

                if c[h_updated as usize][w_updated as usize] == '#' {
                    continue;
                }

                if worp_num[base_pt.0][base_pt.1] + 1 < worp_num[h_updated as usize][w_updated as usize] {
                    worp_num[h_updated as usize][w_updated as usize] = worp_num[base_pt.0][base_pt.1] + 1;
                    deque.push_back((h_updated as usize, w_updated as usize));
                }
            }
        }
    }

    if worp_num[dh - 1][dw - 1] == std::u64::MAX {
        println!("-1");
    } else {
        println!("{}", worp_num[dh - 1][dw - 1]);
    }
}


Measured memory_bytes: 15056
import sys
input = sys.stdin.readline

n,m = map(int, input().split())
t = sorted([tuple(map(int, input().split())) for i in range(m)], key=lambda x:(x[0], -x[1]))
d=[0,0]+[1e18]*n
for l,r,c in t:
  for i in range(r,l,-1):
    if d[l]+c<d[i]:
      d[i]=d[l]+c
    else:
      break
print(d[-2]%10**18or-1)


Measured memory_bytes: 93660
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
int main()
{
	sync;
	//to be the king
	ll n,m;
	cin>>n>>m;
	string arr[n];
	input(arr,n);
	
	ll dp[n*m][n*m];
	for(ll i=0;i<n*m;i++)
		for(ll j=0;j<n*m;j++)
			if(i==j)
				dp[i][j]=0;
			else
				dp[i][j]=1e18;
				
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)
		{
			if(arr[i][j]=='#')
				continue;
				
			ll pt=i*m+j;
			if(i-1>=0&&arr[i-1][j]=='.')
				dp[pt][pt-m]=1,dp[pt-m][pt]=1;
			if(j-1>=0&&arr[i][j-1]=='.')
				dp[pt][pt-1]=1,dp[pt-1][pt]=1;
			if(i+1<n&&arr[i+1][j]=='.')
				dp[pt][pt+m]=1,dp[pt+m][pt]=1;
			if(j+1<m&&arr[i][j+1]=='.')
				dp[pt][pt+1]=1,dp[pt+1][pt]=1;
		}
	}
	
	for(ll i=0;i<n*m;i++)
		for(ll j=0;j<n*m;j++)
			for(ll k=0;k<n*m;k++)
				dp[j][k]=min(dp[j][k],dp[j][i]+dp[i][k]);
	
	ll ans=0;
	for(ll i=0;i<n*m;i++)
		for(ll j=0;j<n*m;j++)
			if(dp[i][j]!=1e18)
				ans=max(ans,dp[i][j]);

	cout<<ans;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int x, y; cin >> x >> y;
    if(4*x-y>=0 && (y-2*x)>=0){
        if((4*x-y)%2==0 && (y-2*x)%2==0){
            cout  << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int n, m, k;
int d[16], drev[105];
int v[105][105];
int dp[1 << 16];

const int INF = 0x3f3f3f3f;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	rep(i, 0, 1 << 16) dp[i] = INF;
	rep(i, 0, 105) drev[i] = -1;

	read(n, m, k);
	rep(i, 0, m) read(d[i]), drev[d[i]] = i;
	rep(i, 1, n + 1) rep(j, 0, k) read(v[i][j]);

	queue<int> Q;
	dp[(1 << m) - 1] = 0;
	Q.push((1 << m) - 1);
	
	while (!Q.empty()) {
		int st = Q.front(); Q.pop();
		rep(i, 0, k) {
			int nst = 0;
			vector<int> freq(m);
			rep(j, 0, m) if ((st & (1 << j)) && drev[v[d[j]][i]] != -1) {
				//write(i, d[j], "->", v[d[j]][i], "(", drev[v[d[j]][i]], ")");
				freq[drev[v[d[j]][i]]]++;
			}
			//for (auto p : freq)
			//	write(i, "F", p.first, p.second);
			rep(j, 0, m) if (freq[j]) nst |= 1 << j;
			//write(i, bitset<2>(st), "->", bitset<2>(nst));
			if (chmin(dp[nst], dp[st] + 1)) {
				Q.push(nst);
			}
		}
	}

	write(dp[0]);
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 200050
#define MAXM 4050
#define mod 1000000007
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define repd(i, x, y) for(ri i = x; i >= y; --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
	read(x), read(args...);
}
int n, a[MAXN], b[MAXN];
ll jc[MAXM*2], invj[MAXM*2];
int dp[MAXM][MAXM], g[MAXM][MAXM];
ll ans;
int M(int x) {
	return x >= mod ? x - mod : x;
}
ll fpow(ll x, ll y) {
	ll ret = 1;
	while(y) {
		if(y & 1) ret = ret * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ret;
} 
int C(int x, int y) {
	return jc[x] * invj[x-y] % mod * invj[y] % mod;
}
int main() {
	read(n);
	rep(i, 1, n) read(a[i], b[i]);
	jc[0] = 1;
	rep(i, 1, 8000) jc[i] = jc[i-1] * i % mod;
	invj[8000] = fpow(jc[8000], mod-2);
	repd(i, 8000, 1) invj[i-1] = invj[i] * i % mod;
	rep(i, 1, n) 
		dp[2000-a[i]][2000-b[i]]++, g[2000+a[i]][2000+b[i]]++;
	rep(i, 0, 4000) {
		rep(j, 0, 4000) {
			ans = (ans + 1ll * g[i][j] * dp[i][j]) % mod;
			dp[i+1][j] = M(dp[i+1][j] + dp[i][j]), dp[i][j+1] = M(dp[i][j+1] + dp[i][j]);
		}
	}
	rep(i, 1, n) ans = (ans - C(2 * a[i] + 2 * b[i], 2 * a[i]) + mod) % mod;
	cout << ans * (mod+1) / 2 % mod << endl;
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<char> s(N);
    for (int i=0; i<N; i++) {
        s.at(i) = S.at(i);
    }
    int count = 0;
    for (int i=0; i<N-2; i++) {
        if (s.at(i) == 'A' and s.at(i+1) == 'B' and s.at(i+2) == 'C') {
            count++;
        }
    }
    cout << count << endl;
}

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

int main(){
    int H, W, c[10][10];
    cin >> H >> W;
    rep(i, 10)rep(j, 10) cin >> c[i][j];
    rep(k, 10)rep(i, 10)rep(j, 10) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }
    int ans = 0;
    rep(i, H)rep(j, W) {
        int A;
        cin >> A;
        if (A == -1) continue;
        ans += c[A][1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

void printboard(vvi b) {
    for (int j = b.front().size() - 1; j >= 0; j--) {
        for (int i = 0; i < b.size(); i++) {
            cout << b[i][j] << '\t';
        }
        cout << endl;
    }
    cout << endl;
}

vvi fold_hor(vvi b, int x) {
    for (int j = 0; j < b.front().size(); j++) {
        for (int i = 0; i < x; i++) {
            b[x + i][j] += b[x - 1 - i][j];
        }
    }
    vvi ret(b.size() - x, vi(b.front().size()));
    for (int i = x; i < b.size(); i++) {
        for (int j = 0; j < b.front().size(); j++) {
            ret[i - x][j] = b[i][j];
        }
    }
    return ret;
}

vvi fold_ver(vvi b, int y) {
    for (int i = 0; i < b.size(); i++) {
        for (int j = 0; j < y; j++) {
            b[i][y + j] += b[i][y - 1 - j];
        }
    }
    vvi ret(b.size(), vi(b.front().size() - y));
    for (int i = 0; i < b.size(); i++) {
        for (int j = y; j < b.front().size(); j++) {
            ret[i][j - y] = b[i][j];
        }
    }
    return ret;
}

int main() {
    int n, m, t, p;
    while (1) {
        cin >> n >> m >> t >> p;
        if (n == 0) return 0;
        vvi board(500, vi(500, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                board[i][j] = 1;
            }
        }
        for (int i = 0; i < t; i++) {
            int d, c;
            cin >> d >> c;
            if (d == 2) {
                board = fold_ver(board, c);
            } else {
                board = fold_hor(board, c);
            }
            // printboard(board);
        }
        for (int i = 0; i < p; i++) {
            int x, y;
            cin >> x >> y;
            cout << board[x][y] << endl;
        }
    }
}


Measured memory_bytes: 8808
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        char[] inpt = Reader.ReadLine().ToArray();

        long cnt = long.Parse(Reader.ReadLine());


        for (int i = 0; i < inpt.Length; i++)
        {
            if (cnt == 0)
            {
                break;
            }
            if (inpt[i] == 'a')
            {
                continue;
            }
            int diff = 'z' - inpt[i];
            if (cnt > diff)
            {
                inpt[i] = 'a';
                cnt -= (diff + 1);
            }
        }
        if (cnt > 0)
        {
            cnt = cnt % 26;
            inpt[inpt.Length - 1] = (char)((int)inpt[inpt.Length - 1] + cnt);
        }
        Console.WriteLine(string.Join(string.Empty, inpt));

    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

a
1000000000


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 7000
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>

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


int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> a(N);

  rep(i, N){
    cin >> a[i];
  }

  ll ans = 0;
  priority_queue<ll> q;

  for (int i = 0; i < N; ++i) {
      q.push(a[i]);
  }
  while (M > 0) {
      ll b = q.top()/2;
      q.pop();
      q.push(b);
      M--;
  }
  rep(i, N){
    ans += q.top();
    q.pop();
  }

  cout << ans << endl;

}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    int x, y, a;
    vec v(N, 0);
    REP(i, N - 1){
        cin >> x >> y >> a;
        v[x] ^= a;
        v[y] ^= a;
    }
    vec cnt(16, 0);
    for(int i: v) cnt[i]++;
    int ans = 0;
    int X = 0;
    REP(i, 15){
        ans += cnt[i + 1] / 2;
        if(cnt[i + 1] % 2) X ^= bit(i);
    }

    vec dp(bit(15), INF);
    dp[0] = 0;
    FOR(n, 1, 15 + 1){
        int comb = bit(n) - 1;
        while(comb < bit(15)){
            int tmp = 0;
            REP(i, 15) if((comb >> i) & 1) tmp ^= (i + 1);
            if(tmp == 0){
                REP(i, 15) REP(j, 15) if(i != j && ((comb >> i) & 1) && ((comb >> j) & 1)){
                    int k = ((i + 1) ^ (j + 1)) - 1;
                    if((comb >> k) & 1) Min(dp[comb], dp[comb ^ bit(i) ^ bit(j) ^ bit(k)] + 2);
                    else Min(dp[comb], dp[comb ^ bit(i) ^ bit(j) ^ bit(k)] + 1);
                }
            }
            x = comb & -comb, y = comb + x;
            comb = ((comb & ~y) / x >> 1) | y;
        }
    }
    //vdebug(dp);
    ans += dp[X];

    cout << ans << endl;

    return 0;
}


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

int main(){
    while(1){
        ll m, f, r;
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        const ll total = m + f;
        if(m == -1 || f == -1){
            cout << 'F' << endl;
        }else if(total >= 80){
            cout << 'A' << endl;
        }else if(total >= 65){
            cout << 'B' << endl;
        }else if(total >= 50){
            cout << 'C' << endl;
        }else if(total >= 30){
            if(r >= 50){
                cout << 'C' << endl;
            }else{
                cout << 'D' << endl;
            }
        }else{
            cout << 'F' << endl;
        }
    }
    return 0;
}



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

#define mset(x, v) memset(x, v, sizeof(x));
#define fi first
#define se second
#define pb push_back
#define be begin()
#define en end()
#define mp make_pair

#define sd(x) scanf("%lld",&x);
#define sd2(x,y) scanf("%lld %lld",&x,&y);
#define sd3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z);

#define pf(x) printf("%lld\n", x);
#define pf2(x,y) printf("%lld %lld", x,y);
#define pf3(x,y,z) printf("%lld %lld %lld", x,y,z);

using namespace std;

typedef long long ll;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef set<ll> sll;
typedef queue<ll> qll;

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

template<class U, class V>
istream& operator>>(istream& in, pair<U, V>& p) {in >> p.first >> p.second;return in;}

int main ()
{
    ll n; sd (n);
    ll dp[n], h[n]; for (ll i = 0; i < n; i++)  sd (h[i]);
    mset (dp, 0);
    dp[1] = abs (h[1] - h[0]);
    for (ll i = 2; i < n; i++)
    {
        dp[i] = min (abs(h[i] - h[i-1]) + dp[i-1], dp[i-2] + abs (h[i] - h[i-2]));
    }
    pf (dp[n-1]);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>

using namespace std;

const int maxn=3e3+10;

int a[maxn];

long long int dp[maxn][maxn];

int main()
{
    int n;

    cin>>n;

    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=0;i<n;i++)
    {
        dp[i][i]=a[i];
     //   cout<<dp[i][i]<<" ";
    }
    for(int l=1;l<n;l++)
    {
        for(int r=l-1;r>=0;r--)
        {

            dp[r][l]=max(a[l]-dp[r][l-1],a[r]-dp[r+1][l]);
           // cout<<dp[r][l]<<" ";
        }
    }
    cout<<dp[0][n-1];
	return 0;
}



Measured memory_bytes: 70016
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m,Q;
  cin >> n >> m >> Q;
  vector<vector<int>> trains(n+1, vector<int>(n+1, 0));
  vector<vector<int>> S(n+1, vector<int>(n+1, 0));
  REP(i,m){
    int l,r;
    cin >> l >> r;
    trains[l-1][r-1]++;
  }
  REP(i,n){
    REP(j,n){
      S[i+1][j+1] = S[i+1][j] + S[i][j+1] - S[i][j] + trains[i][j];
    }
  }
  /*
  REP(i,n+1){
    REP(j,n+1) cout << S[i][j] << ' ';
    cout << '\n';
  }
  */
  REP(i,Q){
    int p,q;
    cin >> p >> q;
    p--;
    cout << S[q][q] - S[p][q] - S[q][p] + S[p][p] << '\n';
  }
  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    if (S == "AAA" || S == "BBB")
    {
        cout << "No" << endl;
        /* code */
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int x,y,z,tmp;
    
    scanf("%d %d %d",&x,&y,&z);
    tmp=x;
    x=y;
    y=tmp;
    
    tmp=x;
    x=z;
    z=tmp;
    
    printf("%d %d %d\n",x,y,z);
    return 0;
}


Measured memory_bytes: 1684
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> dist, skip_dist;
    skip_dist.pb(abs(a[1] - 0));
    dist.pb(abs(a[0] - 0));
    ll total = dist[0];
    reps(i, n, 1)
    {
        dist.pb(abs(a[i] - a[i - 1]));
        if (i < n - 1)
        {
            skip_dist.pb(abs(a[i + 1] - a[i - 1]));
        }
        else
        {
            skip_dist.pb(abs(0 - a[i - 1]));
        }
        total += dist[i];
    }
    dist.pb(abs(0 - a[n-1]));
    total+=dist[n];
    rep(i, n)
    {
        cout << total - (dist[i]+dist[i+1]) + skip_dist[i] << endl;
    }

    //system("pause");
    return 0;
}

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

accums = [0]
for i in range(n - 1):
    accums.append(accums[-1] + int(input()))

result = 0
k = 0
for i in range(m):
    a = int(input())
    result += abs(accums[k + a] - accums[k])
    k += a

print(result % 100000)

Measured memory_bytes: 11000
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
        n:usize,
        // mut a:[i64;n],
    }
    // a = a.iter_mut().map(|&mut x| x % 2).collect::<Vec<_>>();
    // dbg!(&a);
    let mut ans = 0;
    let mut angle = 0;
    for i in 1..33333 {
        angle += n;
        if angle % 360 == 0 {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define SZ(x) ((int)(x).size())
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
template <typename T>
inline void _read(T& x){
    cin>>x;
}
void R(){}
template <typename T,typename... U>
void R(T&head,U&... tail){
    _read(head);
    R(tail...);
}

template <typename T>
inline void _write(const T& x){
    cout<<x<<' ';
}
void W(){cout<<endl;}
template <typename T,typename... U>
void W(const T&head,const U&... tail){
    _write(head);
    W(tail...);
}

void go();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    go();
    return 0;
}
/****************ackun*********************/
bool check(int x){
    return 1<=x&&x<=12;
}
void go(){
    int x;
    R(x);
    int a=x/100;
    int b=x%100;
    int ans=0;
    if(check(a)&&check(b)){
        W("AMBIGUOUS");
    }else if(check(a)){
        W("MMYY");
    }else if(check(b)){
        W("YYMM");
    }else{
        W("NA");
    }
}


Measured memory_bytes: 256
/*痛みを受け取れ，痛みを知れ*/
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1000007;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 6e5 + 5;
pii a[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	ll n, d,x,y;
	while (cin >> n>>d)
	{
		int ans = 0;
		f(i, 1, n)
		{
			scanf("%lld%lld", &x, &y);
			ll now = ceil(sqrt(x*x*1.0 + y * y*1.0));
			if (now <= d)ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
char c[1100];
int a[11][1100],To[11];
inline int get(int w){
	To[1]=1;
	int num=1;
	for(register int i=1;i<n;i++){
		if(((1<<(i-1)) & w))num++;
		To[i+1]=num;
	}
	return num-1;
}

int sum[11];
int main(){
	n=read();m=read();k=read();
	for(register int i=1;i<=n;i++){
		scanf("%s",c+1);
		for(register int j=1;j<=m;j++){
			if(c[j]=='1')a[i][j]=1;
			else a[i][j]=0;
		}
	}
	int len=n-1,ans=1000000;
	for(register int w=0;w<(1<<len);w++){
		int anss=get(w);
		//cout<<anss<<" "<<w<<endl;
		for(register int i=1;i<=n;i++)sum[i]=0;
		for(register int i=1;i<=m;i++){
			int flag=0;
			for(register int j=1;j<=n;j++){
				if(a[j][i])sum[To[j]]++;
				if(sum[To[j]]>k){flag=1;}
				if(flag)break;
			}
			anss+=flag;
			if(flag){
				for(register int j=1;j<=n;j++)sum[j]=0;
				for(register int j=1;j<=n;j++){
					if(a[j][i])sum[To[j]]++;
					if(sum[To[j]]>k){anss=1000000;break;}
				}
			}
		}
		//cout<<anss<<endl;
		ans=min(ans,anss);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
bool dp[1000001];
bool isprime(int& x){
  if(x > 2 && x % 2 == 0) return true;
  for(int i = 3 ; i * i <= x ; i += 2 ) if( x % i == 0) return true;
  return x == 1;
}
int solve(int& i){
  while(true){
    if(dp[i] && !isprime(i)) return i;
    i--;
  }
}
int main(){
  int n,x,data,ans;
  dp[0] = true;
  while(scanf("%d %d",&n,&x) , n){
    for(int i = 1 ; i <= x ; i++ ) dp[i] = false;
    for(int i = 0 ; i < n ; i++ ){
      scanf("%d",&data);
      for(int i = data ; i <= x ; i++ ) if(dp[i-data]) dp[i] = true;
    }
    if(ans = solve(x)) printf("%d\n",ans);
    else printf("NA\n");
  }
}

Measured memory_bytes: 2016