akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int x,y;
	cin>>x>>y;
	for(int a=0; a<=100; a++) {
		for(int b=0; b<=100; b++ ) {
			if((a+b)==x) {
				if((4*a+2*b)==y) {
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}

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


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

using namespace std;

int main ()
{
	string str , ans;
	cin >> str;
	bool f = 0;
	for( auto x : str )
	{
		if( x == 'A' )
		{
			f = 1;
		} else if( f&&x == 'Z' )
		{
			ans += "AZ";
			f = 0;
		}
	}
	if( ans.size () == 0 )
	{
		ans = "-1";
	}
	cout << ans << endl;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int t1, t2, r1, r2;
    cin >> t1 >> t2 >> r1 >> r2;
    auto bob = []() {
        print("Bob");
        exit(0);
    };
    auto ali = []() {
        print("Alice");
        exit(0);
    };
    auto drw = []() {
        print("Draw");
        exit(0);
    };
    if (r1 != -1 && r1 < r2)
        bob();
    if (r2 != -1 && r2 < r1)
        ali();
    if (r1 != -1 && r1 == r2)
        drw();
    if (r1 == -1 || r2 == -1) {
        if (t1 < t2)
            ali();
        if (t2 < t1)
            bob();
        drw();
    }

    return 0;
}


Measured memory_bytes: 3212
N, K = list(map(int, input().split()))

snuke = [0]*N

for i in range(K):
  d = int(input())
  A = list(map(int, input().split()))
  
  for j in range(d):
    if snuke[A[j]-1] == 0:
      snuke[A[j]-1] = 1
      N = N-1
      
print(N)

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000001;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	ll n;
	ll a[100010];
	scanf("%lld",&n);
	rep(i,n)scanf("%lld",&a[i]);
	
	ll sum = 0;
	rep(i,n)sum += a[i];
	
	ll x = n*(n+1)/2;
	ll cnt = sum/x;
	
	if(sum%x != 0){
		puts("NO");
		return 0;
	}
	rep(i,n){
		if(a[i] < cnt){
			puts("NO");
			return 0;
		}
	}
	a[n] = a[0];
	rep(i,n){
		if((a[i]+cnt)%n != a[i+1]%n){
			puts("NO");
			return 0;
		}
		if(a[i]+cnt < a[i+1]){
			puts("NO");
			return 0;
		}
	}
	
	ll cnt_ = 0;
	rep1(i,n){
		cnt_ += (a[i-1]+cnt-a[i])/n;
	}
	if(cnt == cnt_)puts("YES");
	else puts("NO");
	
}
	



Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    V<ll> h(n);
    for(int i=0;i<n;i++)cin>>h[i];
    ll l=-1,r=1e9;
    ll cen=a-b;
    while(r-l>1){
        ll mid=(l+r)/2;
        ll cnt=0;
        for(int i=0;i<n;i++){
            if(h[i]<=b*mid)continue;
            cnt+=(h[i]-b*mid+cen-1)/cen;
        }
        if(cnt<=mid)r=mid;
        else l=mid;
    }
    cout<<r<<endl;
}

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

void solve() {
	long long n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	long long l = n / __gcd(n, m) * m;
	for (long long i = 0; i < n; i++) {
		long long ind = i * (l / n);
		if (ind % (l / m) == 0) {
			long long j = ind / (l / m);
			if (s[i] != t[j]) {
				cout << -1;
				return;
			}
		}
	}
	cout << l;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	solve();
}


Measured memory_bytes: 640
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	int w, h;
	while(cin >> w >> h){
		if(w == 0 && h == 0)break;
		char frame[w][h];
		memset(frame, '#', sizeof frame);
		for(int i = 1; i < w - 1; i++){
			for(int j = 1; j < h - 1; j++)frame[i][j] = '.';
		}
		for(int i = 0; i < w; i++){
			for(int j = 0; j < h; j++)cout << frame[i][j];
			cout << '\n';
		}
		cout << '\n';
	}
	return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    auto k = vector<int>(m);
    auto s = vector<vector<int>>(m);
    auto p = vector<int>(m);
    for(int i = 0; i < m; i++){
      cin >> k[i];
      for(int j = 0; j < k[i]; j++){
        int tmp;
        cin >> tmp;
        s[i].push_back(tmp);
      }
    }
    for(int i = 0; i < m; i++){
      cin >> p[i];
    }

    int ans = 0;
    int ok;

    for(int i = 0; i < (int)pow(2, n); i++){
      ok = 1;
      for(int j = 0; j < m; j++){
        int sum = 0;
        for(int l = 0; l < k[j]; l++){
          sum = (sum + ((i / (int)pow(2, s[j][l] - 1)) % 2)) % 2;
        }
        if(sum != p[j]){
          ok = 0;
          break;
        }
      }
      if(ok == 1) ans++;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int INF = (int)1 << 60;
int N;
vector<vector<int> > ed;
vector<int> X;
bool res = true;
vector<set<int> >st(2);
set<int> st2;
pair<int, int> dfs(int a) {
	
	vector<pair<int, int> > ps;
	pair<int, int> tmp;
	int sum = 0;
	for (int i = 0; i < ed[a].size(); i++) {
		tmp = dfs(ed[a][i]);
		ps.push_back(tmp);
		sum += tmp.first + tmp.second;
	}
	int b = 0;
	st[b].clear();
	st[b].insert(0);
	pair<int, int> ret;
	if (!res) {
		return ret;
	}
	ret.first = INF;
	ret.second = INF;
	for (int i = 0; i < ps.size(); i++) {
		st[1 - b].clear();
		for (auto s : st[b]) {
			st[1-b].insert(s + ps[i].first);
			st[1-b].insert(s + ps[i].second);
		}
		b = 1 - b;
	}
	bool f = false;
	if (st[b].size() > 0) {
		for (auto s : st[b]) {
			if (min(s, sum - s) > X[a]) {

			}
			else {
				f = true;
				if (max(s, sum - s) <= X[a]) {
					ret.first = X[a];
					ret.second = min(ret.second, min(s, sum - s));
				}
				else {
					ret.first = min(ret.first, max(s, sum - s));
					ret.second = min(ret.second, X[a]);
				}
			}
		}
	}
	else {
		f = true;
		ret.first = X[a];
		ret.second = 0;
	}
	if (!f) {
		res = false;
	}
	//cerr << a << " " << ret.first << " " << ret.second << endl;
	return ret;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N;
	ed.resize(N);
	
	int a;
	for (int i = 1; i < N; i++) {
		cin >> a;
		a--;
		ed[a].push_back(i);
	}
	X.resize(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i];
	}
	dfs(0);
	if (res) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 5372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

int main(void){ 
    int n;
    cin >> n;
    vector<ll> A;
    for(int i=0; i<n; i++){
        ll tmp_a;
        cin >> tmp_a;
        A.push_back(tmp_a);
    }

    vector<ll> ruiseki(n);
    ruiseki[0] = A[0];
    for(int i=1; i<n; i++){
        ruiseki[i] = ruiseki[i-1] + A[i];
    }

    ll ans = 0;

    vector<ll>::iterator l;
    l = lower_bound(ruiseki.begin(), ruiseki.end(), ruiseki[n-1]/2);

    ll usiro = (ruiseki[n-1] - *l);
    ll mae = *l;

    if(usiro - mae > 0LL){
        ans += (usiro - mae);
    }
    else{
        ans += (mae - usiro);
    }

    ll ans_1 = 0;
    advance(l,-1);

    usiro = (ruiseki[n-1] - *l);
    mae = *l;

    if(usiro - mae > 0LL){
        ans_1 += (usiro - mae);
    }
    else{
        ans_1 += (mae - usiro);
    }


    cout << min(ans,ans_1);
    return 0;
}

Measured memory_bytes: 3440
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int n;

int AUN(vector<int> mg) {
	int a = 0, un = 0;
	for (int i = 0; i < n; ++i) {
		if (mg[i] == 1) a++;
		else un++;
		if (un > a) return 0;
	}
	if (a == un) return 1;
	else return 0;
}

int main() {
	cin >> n;
	vector<int> mg(n);
	string aun;
	for (int i = 0; i < n; ++i) {
		cin >> aun;
		if (aun == "A") mg[i] = 1;
		else mg[i] = 0;
	}

	cout << (AUN(mg) ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x, n;
    cin >> x >> n;
    vector<pair<int, bool>> num(102, pair<int, bool>(make_pair(0, false)));
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        num.at(p).second=(true);
    }
    int ans = 0;
    int diff = numeric_limits<int>::max();
    for (int i = 0; i < 102; i++) {
        if (num.at(i).second) continue;
        if (abs(x - i) < diff) {
            ans = i;
            diff = abs(x - i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3572
def main():
    N, A = map(int, input().split())
    x = [0]
    x.extend(list(map(int, input().split())))

    dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]
    for i in range(N + 1):
        dp[i][0][0] = 1

    for i in range(1, N + 1):
        for j in range(1, i + 1):
            for k in range(1, N * A + 1):
                if k < x[i]:
                    dp[i][j][k] = dp[i - 1][j][k]
                else:
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]]

    ans = 0
    for j in range(1, N + 1):
        ans += dp[N][j][A * j]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 54088
// package app;

import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        final String a = sc.next();
        final String b = sc.next();

        // final int a = sc.nextInt();
        // final int b = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        String result = b;
        if(a.equals("D")){
            result = b.equals("H") ? "D" : "H";
        }

        System.out.println(result);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21716
#include <iostream>

using namespace std;

int N, M;
int G[55][55];
bool used[55];

void dfs(int v)
{
	used[v] = true;
	for(int i = 1; i <= N; i++){
		if(G[v][i] && !used[i]) dfs(i);
	}
}

bool check()
{
	bool ret = true;
	for(int i = 1; i <= N; i++) ret &= used[i];
	return ret;
}

int main(void)
{
	cin >> N >> M;
	
	int a, b;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		G[a][b] = G[b][a] = 1;
	}
	
	int ans = 0;
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= N; j++){
			if(i >= j) continue;
			if(G[i][j]){
				G[i][j] = G[j][i] = 0;
				for(int k = 1; k <= N; k++) used[k] = false;
				dfs(1);
				if(!check()){
					ans++;
					//cout << i << " " << j << endl;
				}
				G[i][j] = G[j][i] = 1;
			}
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#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 dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  priority_queue<ll> que;
  int N, M;
  ll A;
  ll B;
  cin >> N >> M;
  rep(i, N){
    cin >> A;
    que.push(A);
  }

  rep(i, M){
    B = que.top();
    que.pop();
    que.push(B/2);
  }

  ll ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }

  cout << ans << endl;

}


Measured memory_bytes: 1400
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,k;
char a[15];
bool num[15];

bool check(int a) {
    int cnt=0;
    while (a) {
        if (!num[a%10]) return false;
        a/=10;
    }
    return true;
}

int main() {
    memset(num,1,sizeof(num));
    scanf("%d%d",&n,&k);
    int tmp;
    for (int i=1;i<=k;i++) {
        scanf("%d",&tmp);
        num[tmp]=0;
    }
    int ans=n;
    while (!check(ans)) ans++;
    printf("%d\n", ans);
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll int, null_type,less<ll int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	cin>>n>>m;
    	map<ll,ll> ma;
    	map<ll,ll> wa;
    	for(i=0;i<m;i++)
    	{
    		ll x;
    		string s;
    		cin>>x>>s;
    		if(ma[x]==1)
    			continue;
    		if(s=="AC")
    			ma[x]=1;
    		else
    			wa[x]++;
    	}
    	ll ca=0,w=0;
    	for(auto i:ma)
    		ca+=i.S;
    	for(auto i:wa)
    	{
    		if(ma[i.F]==0) continue;
    		w+=i.S;
    	}
    	cout<<ca<<" "<<w;
    }
    return 0;
}


Measured memory_bytes: 8064
#include <cstdio>
#include <utility>
using namespace std;

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if (a > b) swap(a, b);
  if (b > c) swap(b, c);
  if (a > b) swap(a, b);
  printf("%d %d %d\n", a, b, c);
}


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

using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> grid(H, vector<char>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++) cin >> grid[i][j];
  }
  
  char c[4][4] = {{'6', '3', '1', '4'},
                  {'2', '0', '2', '0'},
                  {'1', '3', '6', '4'},
                  {'5', '0', '5', '0'}};
  
  
  vector<vector<bool>> reach(H, vector<bool>(W, false));
  reach[0][0] = true;
  queue<pair<int, int>> q;
  
  q.push({0, 0});
  while(!q.empty()){
    int i = q.front().first, j = q.front().second;
    q.pop();
    
    if(i - 1 >= 0 && grid[i - 1][j] == c[(i + 3) % 4][j % 4]){
      if(!reach[i - 1][j]){
        reach[i - 1][j] = true;
        q.push({i - 1, j});
      }
    }
    if(j - 1 >= 0 && grid[i][j - 1] == c[i % 4][(j + 3) % 4]){
      if(!reach[i][j - 1]){
        reach[i][j - 1] = true;
        q.push({i, j - 1});
      }
    }
    if(i + 1 < H && grid[i + 1][j] == c[(i + 1) % 4][j % 4]){
      if(!reach[i + 1][j]){
        reach[i + 1][j] = true;
        q.push({i + 1, j});
      }
    }
    if(j + 1 < W && grid[i][j + 1] == c[i % 4][(j + 1) % 4]){
      if(!reach[i][j + 1]){
        reach[i][j + 1] = true;
        q.push({i, j + 1});
      }
    }
  }
  
  puts(reach[H - 1][W - 1] ? "YES" : "NO");
  
  return 0;
}


Measured memory_bytes: 3192
import sys
a, b, c, d = map(int, input().split())

ss = a / d
ss1 = c / b

n = min(ss, ss1)

for _ in range(int(n) + 1):
  c -= b
  if c <= 0:
    print('Yes')
    sys.exit()
  a -= d
  if a <= 0:
    print('No')
    sys.exit()

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int MOD = 1e9+7;

map<pair<LL, LL>, LL> memo;

LL func(LL S, LL X) {
	if (S < 0 || X < 0) return 0;
	if (S == 0) return 1;
	if (S == 1) return (X > 0) * 2;
	if (memo.find(make_pair(S, X)) != memo.end()) return memo[make_pair(S, X)];
	return memo[make_pair(S, X)] = (func(S/2, X/2) + func((S-1)/2, (X-1)/2) + func((S-2)/2, X/2)) % MOD;
}

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

	LL N;
	cin >> N;
	cout << func(N, N) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<Integer> nums = Arrays.stream(br.readLine().split(" "))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
        int n = nums.get(0);
        int m = nums.get(1);
        int[][] a = new int[n][m];
        int[] b = new int[m];
        int[] c = new int[n];

        IntStream.range(0, n).forEach(i -> {
            try {
                List<Integer> ints = Arrays.stream(br.readLine().split(" "))
                        .map(Integer::parseInt)
                        .collect(Collectors.toList());
                IntStream.range(0, m).forEach(j -> {
                    a[i][j] = ints.get(j);
                });
            } catch (IOException e) {
            }
        });

        IntStream.range(0, m).forEach(i -> {
            try {
                int val = Integer.parseInt(br.readLine());
                b[i] = val;
            } catch (IOException e) {
            }
        });

        IntStream.range(0, n).forEach(i -> {
            IntStream.range(0, m).forEach(j -> {
                c[i] += a[i][j] * b[j];
            });
        });
        
        IntStream.range(0, n).forEach(i -> System.out.println(c[i]));
    }
}

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

int main(void) {
	int N;
	scanf("%d", &N);
	string S, T;
	cin >> S >> T;
	for (int i = 0; i < N; i++) {
		printf("%c%c", S[i], T[i]);
	}
	printf("\n");

	return 0;
}


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

int main(){
    int N;
    double x;
    char u[]="BTC";
    char v[]="JPY";
    char w[4];
    double y=0;
    double sum=0;
    cin>>N;
    for(int m=0;m<N;m++){
       cin>>x>>w;
       if(w[0]=='B'){
         y=x*380000.0;
       }
       else{
         y=x;
       }
       sum+=y;
    }
    
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
ll dp[100005][13]; // 1 - 桁数、2 - あまり。i桁目までで余りがjの個数
string S;

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

  cin >> S;

  dp[0][0] = 1; // 初期値

  rep (i, S.size()){ //　i桁目。昇順で考えていることに注意
    int trgt = -1;  
    if (S[i] != '?') trgt = S[i] - '0'; // i+1桁目の数
    if (trgt != -1) {
      // i桁目の余りは、i-1桁目までの余りkを10倍したものにi桁目の数jを加えて13で割った余りに等しい
      // kが0-12について考える
      rep(k, 13) dp[i+1][(k*10+trgt)%13] += dp[i][k];
    } else {
      //　i桁目が?のときはなんでも可能なのでi桁目を0-9で回して足し合わせることができる。
      rep(j, 10) {
        rep(k, 13) dp[i+1][(k*10+j)%13] += dp[i][k];
      }
    }
    rep(j, 13) dp[i+1][j] %= MOD;
  }

  cout << dp[S.size()][5] << endl;
  return 0;
}

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


int main(){
    int n,x;
    while(true){
        cin >> n >> x;
        if(n==0 && x==0){
            break;
        }
        int count=0;
        for(int i=1; i<=n; i++){
            for(int j=i+1; j<=n; j++){
                for(int k=j+1; k<=n; k++){
                    if(i+j+k==x && i!=j!=k){
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }



}
	
	


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vector<ll> h(n);
  rep(i,n) cin>>h[i];
  ///////
  ll dp[100000];
  rep(i,100000){
    dp[i]=inf;
  }
  dp[0]=0;
  for(int i=1;i<n;i++){
   chmin(dp[i],dp[i-1]+abs(h[i-1]-h[i]));
         if(i>1) chmin(dp[i],dp[i-2]+abs(h[i-2]-h[i]));
  }
  cout<<dp[n-1]<<endl;                     
}

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

d=[0 for i in range(40)]
for i in a:
  for j in range(40):
    d[j]+=1 if i&(2**j) else 0
s=[]
ss=0
for i in range(40):
  ss+=(2**i)*max(d[i],n-d[i])
  s.append(ss)
s.append(0)
mx=0
isum=0
for i in range(39,-1,-1):
  if k&(2**i):
    mx=max(mx,isum+(2**i)*d[i]+s[i-1])
    isum+=(2**i)*(n-d[i])
  else:
    isum+=(2**i)*d[i]
mx=max(mx,isum)
print(mx)

Measured memory_bytes: 87120
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

string S[3] = {"nobiro","tidime","karero"};

signed main(){

  int x,a,b; cin >> x >> a >> b;
  int n; cin >> n;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    if(s == "nobiro") x += a;
    if(s == "tidime") x += b;
    if(s == "karero") x = 0;
    x = max(0LL,x);
  }
  cout << x << endl;

  return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
int a[100000+1], b[100000+1], s[100000+1];
int main()
{
	int i, j;
	for(i=2;i<=100000;i++)
	{
		a[i]=1;
	}
	for(i=2;i<=int(sqrt(100000));i++)
	{
		if(a[i]==1)
		{
			for(j=i+i;j<=100000;j+=i)
			{
				a[j]=0;
			}
		}
	}
	b[1]=0; b[2]=0;
    for (i=3; i<=100000; i++)
    {
       if (a[i]==1 && a[(i+1)/2]==1)  
	   {
	   	 	b[i]=1;
	   }
    }
    s[1]=0; s[2]=0;
    for (i=3; i<=100000; i++)
    {
       s[i]= s[i-1] + b[i];
	}
    int q, L, r;
    cin >> q;
    for (i=1; i<=q; i++)
	{
    	cin >> L >> r;
    	cout << s[r] - s[L-1] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1792
n,x = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i).sort
j = 0
for i in 0..n-1
    if x >= a[i]
        x -= a[i]
    else
        puts i
        exit()
    end
end

puts x == 0 ? n : n-1

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

typedef long long ll;
#define rep(i,n) for( int (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#define co(n) cout << (n) << endl;
#define cn(n) cin >> n;
#define all(x) (x).begin(), (x).end()

int main(){
  string s; cin >> s;
  ll increase = 0;
  ll decrease = 0;
  ll ans = 0;
  rep(i,s.length()){
    if (s[i]=='<'){
      if (decrease){
        ans += decrease*(decrease-1)/2 + increase*(increase-1)/2 + max(increase,decrease);
        increase = 0;
        decrease = 0;
      }
      increase++;
    }else{decrease++;}
  }
  if (decrease){
    ans += decrease*(decrease-1)/2 + increase*(increase-1)/2 + max(increase,decrease);
  }else{
    ans += increase*(increase+1)/2;
  }
  co(ans);
}

Measured memory_bytes: 900
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int solve(int cnt, int x, int y, vint c, vint s, vint f) {
	if (cnt > cnt / f[x]*f[x]) {
		cnt = cnt / f[x] * f[x] + f[x];
	}
	else {
		cnt = cnt / f[x]*f[x];
	}
	if (cnt < s[x]) {
		cnt = s[x];
	}
	cnt += c[x];
	if (x + 1 == y) {
		return cnt;
	}
	else {
		return solve(cnt, x + 1, y, c, s, f);
	}
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	if (a % 2 == 0) {
		if (b % 2 == 0) {
			if (c % 2 == 1) {
				ans++;
				a++;
				b++;
			}
		}
		else {
			if (c % 2 == 0) {
				ans++;
				a++;
				c++;
			}
			else {
				ans++;
				b++;
				c++;
			}
		}
	}
	else {
		if (b % 2 == 0) {
			if (c % 2 == 1) {
				ans++;
				a++;
				c++;
			}
			else {
				ans++;
				b++;
				c++;
			}
		}
		else {
			if (c % 2 == 0) {
				ans++;
				a++;
				b++;
			}
		}
	}
	if (a > b)swap(a, b);
	if (b > c)swap(b, c);
	if (a > b)swap(a, b);
	ans += (c - b) / 2;
	ans += (c - a) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	ll N;
	cin >> N;
	ll x[N], y[N], h[N];
	for(int i = 0; i < N; i++) cin >> x[i] >> y[i] >> h[i];
	int start;
	for(int i = 0; i < N; i++)
		if(h[i]) start = i;
	for(ll X = 0; X < 101; X++) {
		for(ll Y = 0; Y < 101; Y++) {
			bool ok = true;
			ll H = abs(X - x[start]) + abs(Y - y[start]) + h[start];
			for(ll i = 0; i < N; i++) {
				if(max(H - abs(X - x[i]) - abs(Y - y[i]), 0LL) != h[i]) {
					ok = false;
					break;
				}
			}
			if(ok) {
				cout << X << " " << Y << " " << H << "\n";
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 384
N,x=map(int,input().split())
aList=sorted(list(map(int,input().split())))

remain = x
count = 0

if sum(aList)<x:
  count = N-1
elif sum(aList)==x:
  count = N
else:
  for i in range (N):
      if remain-aList[i] >= 0:
        remain-=(aList[i])
        count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ios()                \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)


signed main()
{
    ios();
    int n;
    cin >> n;
    int m = n;
    int sn = 0;
    while (m > 0) {
        sn += m % 10;
        m /= 10;
    }
    cout << (n % sn == 0 ? "Yes" : "No") << endl;
}


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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

ll x, k, d;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> x >> k >> d;
    x = abs(x);
    ll a = LLONG_MAX, b = LLONG_MAX;
    ll p = x / d;
    if(k < p)
    {
        cout << x - k * d << "\n";
        return 0;
    }
    if(k % 2 != p % 2)
        p--;
    a = x - p * d;
    if(p + 2 <= k)
        b = abs(a - 2 * d);
    cout << min(a, b) << "\n";
    return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SEGTREE_MAX 256

typedef struct {
	int max_num;
	int push_num;
} segtree_t;

segtree_t segtree[SEGTREE_MAX*2-1];

void segtree_push(int youso) {
	if(youso*2+1<SEGTREE_MAX*2-1) {
		segtree[youso*2+1].push_num+=segtree[youso].push_num;
		segtree[youso*2+2].push_num+=segtree[youso].push_num;
	}
	segtree[youso].max_num+=segtree[youso].push_num;
	segtree[youso].push_num=0;
}

void segtree_add_internal(
		int youso,int add,int start,int end,int kstart,int kend) {
	segtree_push(youso);
	if(end<=kstart || kend<=start)return;
	if(start<=kstart && kend<=end) {
		segtree[youso].push_num+=add;
		segtree_push(youso);
	} else {
		segtree_add_internal(youso*2+1,add,start,end,
			kstart,kstart+(kend-kstart)/2);
		segtree_add_internal(youso*2+2,add,start,end,
			kstart+(kend-kstart)/2,kend);
		segtree[youso].max_num=segtree[youso*2+1].max_num;
		if(segtree[youso].max_num<segtree[youso*2+2].max_num) {
			segtree[youso].max_num=segtree[youso*2+2].max_num;
		}
	}
}

int segtree_getmax_internal(
		int youso,int start,int end,int kstart,int kend) {
	int r1,r2;
	segtree_push(youso);
	if(end<=kstart || kend<=start)return 0;
	if(start<=kstart && kend<=end) {
		return segtree[youso].max_num;
	} else {
		r1=segtree_getmax_internal(youso*2+1,start,end,
			kstart,kstart+(kend-kstart)/2);
		r2=segtree_getmax_internal(youso*2+2,start,end,
			kstart+(kend-kstart)/2,kend);
		if(r1>r2)return r1; else return r2;
	}
}

void segtree_init(void) {
	memset(segtree,0,sizeof(segtree));
}

void segtree_add(int start,int end,int add) {
	segtree_add_internal(0,add,start,end,0,SEGTREE_MAX);
}

int segtree_getmax(int start,int end) {
	return segtree_getmax_internal(0,start,end,0,SEGTREE_MAX);
}

typedef struct {
	int weight;
	int start,end;
} people_t;

int people_num;
people_t people[100];
int zikoku_list_max;
int zikoku_list[200];

int qsort_comp(const void* x,const void* y) {
	int* a=(int*)x;
	int* b=(int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int zikoku_list_search(int zikoku) {
	int left,right,mid;
	left=0;right=zikoku_list_max;
	while(left<=right) {
		mid=(left+right)/2;
		if(zikoku_list[mid]==zikoku)return mid;
		else if(zikoku_list[mid]<zikoku)left=mid+1;
		else right=mid-1;
	}
	return 0;
}

void zikoku_list_make(int temp_max) {
	int i,j;
	zikoku_list_max=temp_max;
	qsort(zikoku_list,zikoku_list_max,sizeof(int),qsort_comp);
	for(i=zikoku_list_max-2;i>=0;i--) {
		if(zikoku_list[i]==zikoku_list[i+1]) {
			for(j=i+1;j<zikoku_list_max;j++) {
				zikoku_list[j-1]=zikoku_list[j];
			}
			zikoku_list_max--;
		}
	}
}

int main(void) {
	int i;
	while(1) {
		scanf("%d",&people_num);
		if(people_num==0)break;
		for(i=0;i<people_num;i++) {
			scanf("%d%d%d",&people[i].weight,
				&people[i].start,&people[i].end);
			zikoku_list[i*2]=people[i].start;
			zikoku_list[i*2+1]=people[i].end;
		}
		zikoku_list_make(people_num*2);
		segtree_init();
		for(i=0;i<people_num;i++) {
			segtree_add(
				zikoku_list_search(people[i].start),
				zikoku_list_search(people[i].end),
				people[i].weight
			);
		}
		puts(segtree_getmax(0,zikoku_list_max)>150?"NG":"OK");
	}
	return 0;
}

Measured memory_bytes: 0
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
    int A, B, C;
    cin>>A>>B>>C;
    int count1 = 0, count2 = 0;
    
    if (A == 5){
        count1 += 1;
    }else if(A == 7){
        count2 += 1;
    }
    
    if(B == 5){
        count1 += 1;
    }else if(B == 7){
        count2 += 1;
    }
    if(C == 5){
        count1 += 1;
    }else if(C == 7){
        count2 += 1;
    }
    
    if(count1 == 2 and count2 == 1){
        cout<<"YES"<<endl;
    }else{cout<<"NO"<<endl;}
    return 0;
}


Measured memory_bytes: 256
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
    N, M, X = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    ans = 10**9
    for p in product([0,1],repeat=N):
        cost = 0
        for i in range(N):
            if p[i]==1:
                cost += A[i][0]
        for j in range(1,M+1):
            und = 0
            for i in range(N):
                if p[i]==1:
                    und += A[i][j]
            if und<X:
                break
        else:
            ans = min(ans,cost)
    if ans == 10**9:
        return -1
    return ans
print(solve())

Measured memory_bytes: 68076
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

lint culc(lint h, lint w) {

  lint ret = INF;
  for (int i = 0; i < h - 1; i++) {
    lint A = w * (i + 1);

    lint d = h - (i + 1);
    {
      lint a = d / 2;
      lint b = d - a;
      lint B = a * w;
      lint C = b * w;

      ret = min(ret, max({A, B, C}) - min({A, B, C}));
    }
    {
      lint a = w / 2;
      lint b = w - a;
      lint B = a * d;
      lint C = b * d;

      ret = min(ret, max({A, B, C}) - min({A, B, C}));
    }
  }

  return ret;
}

int main() {
  
  lint h, w; cin >> h >> w;
  lint ans = min(culc(h, w), culc(w, h));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main(){
	var n1, n2, n3, n4, n5 int
    fmt.Scan(&n1, &n2, &n3, &n4, &n5)
    v := [5]int{n1,n2,n3,n4,n5}
	for i := 0; i < 5; i++ {

        if v[i] == 0 {
        	fmt.Println(i+1)
			break
        }
    }
}

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

const int MAX_N=1e5+3;
int N,K;
int H[MAX_N];
int dp[MAX_N];

void solve()
{
	memset(dp, 0x3f, sizeof(dp));
	dp[0]=0;
	for(int i=0; i<N; ++i){
		if(dp[i] < INF)for(int k=1; k<=K; ++k){
			if(i+k>=N) break;
			dp[i+k]=min(dp[i+k], dp[i]+abs(H[i+k]-H[i]));
			dp[i+k]=min(dp[i+k], dp[i]+abs(H[i+k]-H[i]));
		}
	}
	cout << dp[N-1] << endl;
}

int main()
{
	cin >> N >> K;
	for(int i=0;i<N;++i) cin >> H[i];
	solve();
	return 0;
}	

Measured memory_bytes: 1024
def read_input():
    n = int(input())
    alist = []

    for i in range(n):
        alist.append(int(input()))

    return n, alist


def submit():
    n, alist = read_input()

    paper = {a: -1 for a in alist}

    for a in alist:
        paper[a] *= -1

    paper_write = [t for t in paper.items() if t[1] == 1]
    print(len(paper_write))

if __name__ == '__main__':
    submit()

Measured memory_bytes: 63700
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[100005], b[100005];
int main(){
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%d%d", &a[i], &b[i]);
	}
	LL ans = 0;
	for(int i=n;i>=1;i--){
		LL val = (a[i]+ans+b[i]-1)/b[i];
		val *= b[i];
		ans += abs(a[i]+ans-val);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<set>
#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;

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

    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll ans;
    if (K % 2 == 0) ans = A - B;
    else ans = B - A;

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

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


int main() {
	UL X[5]; rep(i, 5) cin >> X[i];
	UL ans = 0;
	rep(i, 5) {
		if (X[i] == 0) ans = i + 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int N = 3000;
int n, k, a[N];
ll dp[N][N][2];

ll cal(int i, int j, bool p){
	if( i > j )
		return 0;
	if( dp[i][j][p] != -1 )
		return dp[i][j][p];
	if( p == 0 )
		return dp[i][j][p] = max( cal(i+1, j, !p) + a[i], cal(i, j-1, !p) + a[j] );
	else
		return dp[i][j][p] = min( cal(i+1, j, !p) - a[i], cal(i, j-1, !p) - a[j] );
}

int main()
{
	cin >> n;
	f(i, 0, n)
		cin >> a[i];
	memset(dp, -1, sizeof dp);
	cout << cal(0, n-1, 0);
}

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

using namespace std;
int main()
{
    long long int m,n,s=0;
    cin>>n>>m;
    long long int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<(n-m);i++){
        s=s+a[i];
    }
    cout<<s<<endl;

}


Measured memory_bytes: 1792
#include <stdio.h>

int paper[10][10];

void drop(int paper[][10], int x, int y, int size)
{
	if (x + size < 10){
		paper[x + size][y]++;
	}
	if (x - size >= 0){
		paper[x - size][y]++;
	}
	if (y + size < 10){
		paper[x][y + size]++;
	}
	if (y - size >= 0){
		paper[x][y - size]++;
	}
}

int main(void)
{
	int x, y, size;
	int i, j;
	int count = 0;
	int max = 0;
	
	while (scanf("%d,%d,%d", &x, &y, &size) != EOF){
		paper[x][y]++;
		drop(paper, x, y, 1);
		if (size > 1){
			if (x + 1 < 10 && y + 1 < 10){
				paper[x + 1][y + 1]++;
			}
			if (x - 1 >= 0 && y + 1 < 10){
				paper[x - 1][y + 1]++;
			}
			if (x + 1 < 10 && y - 1 >= 0){
				paper[x + 1][y - 1]++;
			}
			if (x - 1 >= 0 && y - 1 >= 0){
				paper[x - 1][y - 1]++;
			}
		}
		if (size > 2){
			drop(paper, x, y, 2);
		}
	}
	for (i = 0; i < 10; i++){
		for (j = 0; j < 10; j++){
			if (paper[i][j] == 0){
				count++;
			}
			if (max < paper[i][j]){
				max = paper[i][j];
			}
		}
	}
	printf("%d\n", count);
	printf("%d\n", max);
	
	return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18
ll gcd(ll a,ll b){
	ll r=0;
	do{
		r=a%b;
		a=b;
		b=r;
	}while(r!=0);
	return a;
}
int main(){
	ll k; cin>>k;
	ll memo[201][201]={0};
	FOR(i,1,201){
		FOR(j,1,201){
			memo[i][j]=gcd(i,j);
		}
	}
	ll sum=0;
	FOR(i,1,k+1){
		FOR(j,1,k+1){
			FOR(l,1,k+1){
				sum+=memo[i][memo[j][l]];
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3936
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];
int n;
int A,B,C;
int ans;
void dfs(int t,int aa,int bb,int cc,int cnt){
    //cout<<t<<" "<<aa<<" "<<bb<<" "<<cc<<" "<<a[t]<<endl;
    if(t==n){
        if(aa!=0&&bb!=0&&cc!=0)ans=min(ans,abs(A-aa)+abs(B-bb)+abs(C-cc)+cnt);
        return ;
    }
//    if(aa+a[t]>A&&bb+a[t]>B&&cc+a[t]>C){
//        ans=min(ans,A-aa+B-bb+C-cc+cnt);
//        return ;
//    }

    if(aa==0)
        dfs(t+1,aa+a[t],bb,cc,cnt);
    else
        dfs(t+1,aa+a[t],bb,cc,cnt+10);
    if(bb==0)
        dfs(t+1,aa,bb+a[t],cc,cnt);
    else
        dfs(t+1,aa,bb+a[t],cc,cnt+10);
    if(cc==0)
        dfs(t+1,aa,bb,cc+a[t],cnt);
    else
        dfs(t+1,aa,bb,cc+a[t],cnt+10);
    dfs(t+1,aa,bb,cc,cnt);
}
int main(){
    int m,T;
    cin>>n>>A>>B>>C;
    ans=1e9;
    rep(i,0,n) cin>>a[i];
    sort(a,a+n);
    dfs(0,0,0,0,0);
    cout<<ans<<endl;
    return 0;
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

int imos[111111];

int main(){
	
	int n, q;cin >> n >> q;
	string str;cin >> str;
	REP(i, n-1)if(str[i] == 'A' && str[i+1] == 'C')imos[i+2]++;
	REP(i, n)imos[i+1] += imos[i];
	
	REP(i, q){
		int l, r;cin >> l >> r;
		if(str[l-1] == 'C')l++;
		cout << imos[r] - imos[l-1] << endl;
	}
	
	return 0;
}


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

using namespace std;

const int N = 1e5 + 5;
bool vis[N];
vector<int> e[N];

void dfs(int n) {
    vis[n] = 1;
    for (auto i : e[n]) {
        if (!vis[i]) {
            dfs(i);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    while (m--) {
        int a, b;
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            res++;
            dfs(i);
        }
    }
    cout << res - 1 << endl;
    return 0;
}





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

int main(){
    int n;
    cin >> n;
    ll t[n],mx = 0;
    rep(i,n)cin >> t[i];
    
    sort(t,t+n,greater<ll>());
    mx = t[0];
    for(ll i = 1;i < n;i++){
        if(mx % t[i] == 0)continue;
        
        for(ll j = 1;j <= t[i];j++){
            if(j * mx % t[i] == 0){
                mx *= j;
                break;
            }
        }
    }
    
    cout << mx << endl;
}


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

#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << "["<< *it << " = " << a << "]"<< endl;
    err(++it, args...);
}
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    int N,K,R,S,P;
    string T;
    cin >> N >> K >> R >> S >> P;
    cin >> T;
    vector<int> C = {R,P,S};
    vector<int> M (N+1);
    for (int i =0 ; i<N; i++ ) {
        if (T[i] == 'r') {
            M[i+1] = 0;
        } else if (T[i] == 's') {
            M[i+1] = 2;
        } else {
            M[i+1] = 1;
        }
    }
    vector<vector<int>> dp(N+1, vector<int> (3));
    for (int i = 1; i <= K; i++ ) {
        int m = max({dp[i-1][0], dp[i-1][1], dp[i-1][2]});
        for (int j = 0; j <3; j++ ) {
            if (M[i] == ((j + 1) % 3)) {
                dp [i][j] = m ;//- C[j];
            } else if (M[i] == j) {
                dp [i][j] = m;
            } else {
                dp [i][j] = m + C[j];
            }
        }
    }
    for (int i = K+1; i <= N; i++) {
        int m1 = max({dp[i-1][0], dp[i-1][1], dp[i-1][2]});
        int mk = max({dp[i-K][0], dp[i-K][1], dp[i-K][2]});
        for (int j = 0; j<3; j++ ) {
            int dd = max(dp[i-K][(j+1) %3], dp[i-K][(j+2) %3]);
            if (M[i] == j) {
                dp[i][j] = m1 - (mk - dd);
            } else if (M[i] == ((j+1) % 3)) {
                dp[i][j] = m1 - (mk - dd) ;//-C[j]; 
            } else {
                dp[i][j] = m1 - (mk - dd) + C[j];
            }
        }
    }
    for (int j = 0; j<3; j++ ) {
        for (int i = 0; i<=N; i++) {
            cerr << dp[i][j] << " ";
        }
        cerr << "\n";
    }
    cout << max({dp[N][0], dp[N][1], dp[N][2] });
}


Measured memory_bytes: 6224
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back


int MOD=1000000007;
int N,M,P;
double A[105];
int ans=0;



signed main(){
    scanf("%lld",&N);
    double ans=0;
    rep(i,N){
        scanf("%lf",&A[i]);
        ans+=(double)(1/A[i]);
    }
    printf("%lf\n",(double)(1/ans));
}


Measured memory_bytes: 128
import math
import fractions
import copy
import numpy as np

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
n = ip()
s = input()
scut = [s[i] for i in range(len(s))]
scut.sort()
if n == 1:
	print(''.join(scut))
	exit(0)
for i in range(n-1):
	s = input()
	sncut = [s[i] for i in range(len(s))]
	sncut.sort()
	nextline = []
	while len(sncut) and len(scut):
	  if sncut[0] == scut[0]:
	  	nextline.append(sncut[0])
	  	scut.pop(0)
	  	sncut.pop(0)
	  elif sncut[0] > scut[0]:
	  	scut.pop(0)
	  else: sncut.pop(0)
	scut = copy.copy(nextline)
print(''.join(nextline))

Measured memory_bytes: 20264