akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
 
  int d[6],i,blank;
  char ENSW[100];
 
  for(i = 0; i < 6; i++){
 
    scanf("%d",&d[i]);
 
  }
 
  scanf("%s",ENSW);
   
  for(i = 0; ENSW[i] != '\0'; i++){
 
    if(ENSW[i] == 'N'){
 
      blank=d[0];
      d[0]=d[1];
      d[1]=d[5];
      d[5]=d[4];
      d[4]=blank;
 
    }
 
    if(ENSW[i] == 'E'){
 
      blank=d[0];
      d[0]=d[3];
      d[3]=d[5];
      d[5]=d[2];
      d[2]=blank;
 
    }
 
    if(ENSW[i] == 'S'){
 
      blank=d[0];
      d[0]=d[4];
      d[4]=d[5];
      d[5]=d[1];
      d[1]=blank;
 
    }
 
    if(ENSW[i] == 'W'){
 
      blank=d[0];
      d[0]=d[2];
      d[2]=d[5];
      d[5]=d[3];
      d[3]=blank;
 
    }
 
  }
   
  printf("%d\n",d[0]);
 
  return 0;
 
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
const ll INFL = 1e18;
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int X, Y, a, b, c;
    cin >> X >> Y >> a >> b >> c;
    vvl pqr(3, vl(a+b+c, 0));
    rep(i,a) cin >> pqr[0][i];
    rep(i,b) cin >> pqr[1][i];
    rep(i,c) cin >> pqr[2][i];
    pqr[0].push_back(INFL);
    pqr[1].push_back(INFL);
    rep(i,3) sort(pqr[i].rbegin(),pqr[i].rend());
    vl xy({X, Y});
    rep(z,c) {
        int mxi = (pqr[0][xy[0]] < pqr[1][xy[1]] ? 0 : 1);
        int mni = 1 - mxi;
        ll cmp = pqr[2][z];
        if (pqr[mxi][xy[mxi]] < cmp) {
            pqr[mxi][xy[mxi]] = cmp;
            xy[mxi]--;
        } else if (pqr[mni][xy[mni]] < cmp) {
            pqr[mni][xy[mni]] = cmp;
            xy[mni]--;
        }
    }
    ll ans = 0;
    rep(i,X) ans += pqr[0][i+1];
    rep(i,Y) ans += pqr[1][i+1];
    cout << ans << endl;
    return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

vi PS;
vi HS;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	PS.resize(N);
	HS.resize(N);
	F0R(i, N) {
		int h, p; cin >> h >> p;
		HS[i] = h;
		PS[i] = p;
	}

	vi perm (N);
	F0R(i, N) perm[i] = i;
	sort(perm.begin(), perm.end(), [] (const auto& lhs, const auto& rhs) {
		return HS[lhs] + PS[lhs] < HS[rhs] + PS[rhs];
	});

	vll dp (N+1, INF); // smallest height using N people 
	dp[0] = 0;
	for (int p = 0; p < N; ++p) {
		int i = perm[p];
		for (int s = N; s >= 0; --s) {
			if (dp[s] <= HS[i]) dp[s+1] = min(dp[s+1], dp[s] + PS[i]);
		}
	}
	int ans = 0;
	while (ans <= N && dp[ans] != INF) ++ans;
	print(ans-1);
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    vector<vector<ll>> pi(A, vector<ll>(2, 0));
    ll pena = 0, ans = 0;
    int x;
    string s;
    REP(i, B)
    {
        cin >> x >> s;
        if (pi[x - 1][0] == false && s == "WA")
        {
            pi[x - 1][1]++;
        }
        else if (pi[x - 1][0] == false && s == "AC")
        {
            ans++;
            pi[x - 1][0] = true;
        }
        else
            continue;
    }

    REP(j, A)
    {
        if (pi[j][0] == true)
            pena += pi[j][1];
    }
    printf("%lld %lld\n", ans, pena);
    return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a>b*2) {
			System.out.println(a-2*b);
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 23636
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
gi = lambda : list(map(int,input().strip().split()))
n, = gi()
l = gi()
ll = sorted(l)
diff = sum([1 if l[k] != ll[k] else 0 for k in range(n)])
if diff <= 2:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 3064
n,m,x,y = map(int, input().split())
lix = list(map(int, input().split()))
liy = list(map(int, input().split()))
lix.sort()
liy.sort()
flag = 0
for i in range(x+1,y+1):
    if lix[-1] < i and i <= liy[0]:
        flag = 1
        break

if flag == 1:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3060
a = gets.to_i 
x = gets.split.map(&:to_i)
b = gets.to_i 
y = b.times.map{gets.split}

y.each do |n|
 val = x[n[0].to_i - 1]
 x[n[0].to_i - 1] = n[1].to_i
 puts x.inject(:+) 
 x[n[0].to_i - 1] = val
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
ll n, k;
std::vector<ll> v;
//-------------------関数----------------------//

int main() {
  cin >> n >> k;
  REP(i, n) {
    ll a;
    cin >> a;
    v.pb(a);
  }
  ll mini = INF;
  REP(i, 1 << n) {
    ll mae = 0;
    ll cnt = 0;
    if (bitcnt(i) < k)
      continue;
    REP(j, v.size()) {
      if ((i >> j) & 1) {
        if (v[j] <= mae) {
          cnt += mae - v[j] + 1;
          mae++;
        } else {
          mae = v[j];
        }
      }
      mae = max(mae, v[j]);
    }
    mini = min(cnt, mini);
  }
  cout << mini << endl;
}


Measured memory_bytes: 256
n,p = map(int,input().split())
s = list(map(int,list(input())))
ans = 0
cnt = [0]*p
cnt[0] = 1

if p == 2:
  for i in range(n):
    if s[i] in [0,2,4,6,8] :
      ans += i + 1
elif p == 5:
  for i in range(n):
    if s[i] in [0,5]:
      ans += i + 1
else:
  sum = 0
  for i in range(n):
    sum = (sum+s[n-i-1]*pow(10,i,p))%p
    cnt[sum] += 1
  for j in range(p):
    cj = cnt[j]
    ans += cj * (cj-1)//2
print(ans)


Measured memory_bytes: 6560
#include<iostream>
using namespace std;
int main() {
	int a;
	cin >> a;

	int array[100];
	for (int i = 0; i < a; i++) {
		cin >> array[i];
	}

	int sa[100][100];

	for (int x = 0; x < a; x++) {
		for (int y = 0; y < a; y++) {
			sa[x][y] = array[x] - array[y];
		}
	}

	for (int z = 0; z < a; z++) {
		for (int p = 0; p < a; p++) {
			if (sa[z][p] < 0) {
				sa[z][p] = -sa[z][p];
			}
			else {
				sa[z][p] = sa[z][p];
			}
		}
	}

	int answer = 0;

	for (int n = 0; n < a; n++) {
		for (int m = 0; m < a; m++) {
			if (answer < sa[n][m]) {
				answer = sa[n][m];
			}
			else {
				answer = answer;
			}
		}
	}
	cout << answer;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,j,k;
    int N,X,L[100],answer = 1,D = 0;
    
    scanf("%d %d",&N,&X);
    
    for(i = 0;i < N-1;i++){
        scanf("%d\n",&L[i]);
    }
    scanf("%d",&L[i]);
    
    for(i = 0;i < N;i++){
        D += L[i];
        if(D <= X) answer++;
    }
    
    printf("%d\n",answer);
    
    return 0;
}



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


int main(){
    
    string s, t;
    
    cin >> s;
    cin >> t;
    
    int ans = 10000;
    
    for(int i=0; i<s.length(); i++){
        int cnt=0;
        for(int j=0; j<t.length(); j++){
            if(i+j>=s.length()){
                cnt=10000;
                break;
            }
            if(s[i+j]!=t[j])cnt++;
        }
        ans = cnt<ans? cnt: ans;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
long long n,m;
long long a[3][110];
int main()
{
    cin>>n;
    memset(a,0,sizeof(a));
    for(long long i=1;i<=2;i++)
        for(long long j=1;j<=n;j++)
        cin>>a[i][j];
    for(long long i=2;i<=n;i++)
        a[1][i]+=a[1][i-1];
    for(long long i=n;i>=1;i--)
        a[2][i]+=a[2][i+1];
    long long max1=0;
    for(long long i=1;i<=n;i++)
        max1=max(max1,a[1][i]+a[2][i]);
    cout<<max1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int M = 100010;
int x,cnt,ans,p,k,t,l;
char s[M];
int main()
{
	scanf("%s",s);
	l = strlen(s);
	for (int i = 0; i < l; i++)
		if((i+1) % 2 != 0 )
			printf("%c",s[i]);
	printf("\n"); 
	return 0;
}

Measured memory_bytes: 384
import math

def sieve(n):
    ass = []
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(math.sqrt(n))+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    for i in range(n+1):
        if is_prime[i]:
            ass.append(i)
    return(ass)

x = int(input())
ass = sieve(10**5+4)
s = set(ass)
import bisect
if x in s:
    print(x)
else:
    i = bisect.bisect_right(ass, x)
    print(ass[i])

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

#define int long long

signed main(void){
    int n; cin >> n;
    vector<int>p(n);
    for(int i=0;i<n;i++) cin >> p[i];
    int min_p = 1e10,ans=0;
    for(int i=0;i<n;i++){
        if(p[i] < min_p){
            min_p = p[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int digits(long long n)
{
  if(n == 0)
    return 0;
  else
    return 1 + digits(n / 10);
}
int main()
{
  int n;
  scanf("%d", &n);
  int v[n];
  for(int i = 0; i < n; i++)
    scanf("%d", &v[i]);
  sort(v, v + n);
  int best = INT_MAX;
  for(int i = v[0]; i <= v[n - 1]; i++)
  {
    int sum = 0;
    for(int j = 0; j < n; j++)
      sum += pow(v[j] - i, 2);
    best = min(best, sum);
  }
  printf("%d\n", best);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

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

    for(int i = a; i <= a*b; i += a){
        if(i % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
def count_rewrite(v):
    ct = {}
    for x in v:
        if x in ct:
            ct[x] += 1
        else:
            ct[x] = 1
    total = 0
    for x in ct:
        total += ct[x]
    best = 0
    for x in ct:
        if ct[x] > best:
            best = ct[x]
            maxv = x
    del ct[maxv]
    second = 0
    for x in ct:
        if ct[x] > second:
            second = ct[x]
    return maxv, total - best, total - second


n = int(input())
v = list(map(int, input().split()))

r1 = count_rewrite(v[::2])
r2 = count_rewrite(v[1::2])
if r1[0] != r2[0]:
    print(r1[1] + r2[1])
else:
    if r1[2] >= r2[2]:
        print(r1[1] + r2[2])
    else:
        print(r1[2] + r2[1])


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

using namespace std;

typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,k,q,t,a[100005];
    cin>>n>>k>>q;
    memset(a,0,sizeof a);
    for(int i=1;i<=q;i++)
    {
        cin>>t;
        a[t]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]+k>q)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


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

long long N, K, Q, A[1 << 18], cnt[1 << 18];

int main() {
	cin >> N >> K >> Q;
	for (int i = 1; i <= Q; i++) {
		cin >> A[i];
		cnt[A[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		if (cnt[i] > Q - K) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

int main()
{
  int N,A ;
  cin>>N>>A ;
  for(int i=0;i<=A;i++){
    if(((N-i)%500)==0){
      cout<<"Yes"<<endl ;
      return 0 ;
    }
  }
  cout<<"No"<<endl ;
  return 0 ;
}

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

int main(){
  int N,result;
  cin >> N;
  string S;

  map<string,int> mp;
  for(int i=0;i<N;i++){
    cin >> S;
    if(mp[S]==0){
      mp[S] = 1;
    }else{
      mp[S] += 1;
    }
  }
  cout << mp.size() << endl;
}

Measured memory_bytes: 19180
#include "bits/stdc++.h"

using namespace std;

#define ll  long long
#define vi  vector<int>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

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

int main(){

  int a,b,c,x,y;
  ll ans = 0;
  cin >> a >> b >> c >> x >> y;

  if(x == 0)ans = min(b,2*c)*y;
  else if(y == 0) ans = min(a,2*c)*x;
  else {
    if(a+b < 2*c)ans = a*x + b*y;
    else{
      ans = 2*c*min(x,y);
      if(x > y){
        x -= y;
        if(a > 2*c)ans += 2*c*x;
        else ans+= a*x;
      }
      else{
        y -= x;
        if(b > 2*c)ans += 2*c*y;
        else ans += b*y;
      }
    }
  }

  pr(ans);

  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;

const int MAXN=100000+10;
bool check[MAXN+10];
int prime[MAXN+10];
int mu[MAXN+10];

void Moblus()
{
    memset(check,false,sizeof(check));
    mu[1] = 1;
    int tot = 0;
    for(int i = 2; i <= MAXN; i++)
    {
        if( !check[i] ){
            prime[tot++] = i;
            mu[i] = -1;
        }
        for(int j = 0; j < tot; j++)
        {
            if(i * prime[j] > MAXN) break;
            check[i * prime[j]] = true;
            if( i % prime[j] == 0){
                mu[i * prime[j]] = 0;
                break;
            }else{
                mu[i * prime[j]] = -mu[i];
            }
        }
    }
}

int main()
{
    Moblus();
    int n,l,r,sz[MAXN];
    memset(sz,0,sizeof(sz));
    int _max=0;
    for(int i=2;i<=100000;i++){
        if(i%2==1){
            if(!check[i]&&!check[(i+1)/2]) {sz[i]=_max+1;_max++;}
            else sz[i]=_max;
        }
        else sz[i]=_max;

    }
    while(~scanf("%d",&n)){
        for(int i=0;i<n;i++){
            scanf("%d%d",&l,&r);
            printf("%d\n",sz[r]-sz[l-1]);
        }
    }



    return 0;
}



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

int main() {
  int n, a[51];

  cin >> n;
  int amax = 0, amin = 0, x, imax, imin;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[i] = x;
    if (x > amax) {
      amax = x;
      imax = i;
    }
    if (x < amin) {
      amin = x;
      imin = i;
    }
  }

  if (amax == 0 && amin == 0) {
    cout << 0 << endl;
    return 0;
  }

  int cnt = 0;
  if (amax >= abs(amin)) {
    for (int i = 1; i <= n; i++) {
      if (i != imax) {
        //a[i] += amax;
        //cout << imax << " " << i << endl;
        cnt++;
      }
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (i != imin) {
        //a[i] += amin;
        //cout << imin << " " << i << endl;
        cnt++;
      }
    }
  }

  if (amax >= abs(amin)) {
    for (int i = 2; i <= n; i++) {
      //a[i] += a[i-1];
      //cout << i-1 << " " << i << endl;
      cnt++;
    }
  } else {
    for (int i = n-1; i >= 1; i--) {
      //a[i] -= a[i+1];
      //cout << i << " " << i+1 << endl;
      cnt++;
    }
  }

  cout << cnt << endl;
  if (amax >= abs(amin)) {
    for (int i = 1; i <= n; i++) {
      if (i != imax) {
        cout << imax << " " << i << endl;
      }
    }
  } else {
    for (int i = 1; i <= n; i++) {
      if (i != imin) {
        cout << imin << " " << i << endl;
      }
    }
  }

  if (amax >= abs(amin)) {
    for (int i = 2; i <= n; i++) {
      cout << i-1 << " " << i << endl;
    }
  } else {
    for (int i = n-1; i >= 1; i--) {
      cout << i+1 << " " << i << endl;
    }
  }
  
  return 0;

}


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

using namespace std;

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

  int v[n];
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }

  sort(v, v + n);

  double ans = v[0];
  for (int i = 1; i < n; ++i) {
    ans = (ans + v[i]) / 2;
  }

  cout << fixed << setprecision(6) << ans << endl;
}


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

int dp_compute(int a[],int n,int k){
	int dp[100009]={};
	dp[0]=0;

	int best=INT_MAX;
	for(int i=1;i<n;i++){
		best=INT_MAX;
		for(int j=1;j<=k;j++){
			if(i-j>=0){
				best=min(best,abs(a[i]-a[i-j])+dp[i-j]);
			}
		}
		dp[i]=best;
	}
	return dp[n-1];
}
int main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ans=dp_compute(a,n,k);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
# input
N = int(input())
A = list(map(int, input().split()))

# check
res = 0
Alice_Turn = True
while A:
    max_a = max(A)
    if Alice_Turn:
        res += max_a
        Alice_Turn = False
    else:
        res -= max_a
        Alice_Turn = True
    A.remove(max_a)

print(res)

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int A[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}
	bool filled[3][3];
	memset(filled, 0, sizeof(filled));

	int N; cin >> N;
	while (N--) {
		int v; cin >> v;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (A[i][j] == v) filled[i][j] = true;
			}
		}
	}
	if (
			(filled[0][0] && filled[1][1] && filled[2][2]) ||
			(filled[0][0] && filled[0][1] && filled[0][2]) ||
			(filled[1][0] && filled[1][1] && filled[1][2]) ||
			(filled[2][0] && filled[2][1] && filled[2][2]) ||
			(filled[0][0] && filled[1][0] && filled[2][0]) ||
			(filled[0][1] && filled[1][1] && filled[2][1]) ||
			(filled[0][2] && filled[1][2] && filled[2][2]) ||
			(filled[0][2] && filled[1][1] && filled[2][0])
	   ) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
from itertools import product

from operator import add, sub

numbers = tuple(int(c) for c in input())

operators = product((add, sub), repeat=3)


def opstr(op):
    if op == add:
        return '+'
    elif op == sub:
        return '-'


for op1, op2, op3 in operators:
    result = numbers[0]
    result = op1(result, numbers[1])
    result = op2(result, numbers[2])
    result = op3(result, numbers[3])

    if result == 7:
        print(str(numbers[0]) + opstr(op1) + str(numbers[1]) + opstr(op2) + str(numbers[2]) + opstr(op3) + str(numbers[3]) + '=7')
        break


Measured memory_bytes: 3188
gets
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

total = 0
prev = 0
a.each_with_index do |x, i|
  if (b[i].to_i + prev) - x >= 0
    total += x
    if prev - x < 0
      prev = prev + b[i].to_i - x
    else
      prev = b[i].to_i
    end
  else
    total += (b[i].to_i + prev)
    prev = 0
  end
end

puts total


Measured memory_bytes: 17564
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n,k;
  cin >> n >> k;
  vector<vector<int>> x(1+k,vector<int>(1+k,0));
  vector<vector<int>> y(k+1,vector<int>(k+1,0));
  rep(i,n){
    int a,b;
    char c;
    cin >> a >> b >> c;
    int o=(a/k)+(b/k);
    if((o%2==0&&c=='B')||(o%2==1&&c=='W'))x[1+a%k][1+b%k]++;
    else y[a%k+1][b%k+1]++;
  }
  rep(i,k){
    rep(j,k){
      x[i+1][j+1]=x[i+1][j+1]+x[i+1][j]+x[i][j+1]-x[i][j];
      y[i+1][j+1]=y[i+1][j+1]+y[i+1][j]+y[i][j+1]-y[i][j];
      
    }
  }
  int ans=0;
  rep(i,k+1)rep(j,k+1)ans=max(ans,x[i][j]*2+x[k][k]-x[i][k]-x[k][j]+y[i][k]+y[k][j]-2*y[i][j]);
  rep(i,k+1)rep(j,k+1){
    ans=max(ans,y[i][j]*2+y[k][k]-y[i][k]-y[k][j]+x[i][k]+x[k][j]-2*x[i][j]);
    //if(ans==5)cout << i << " " << j << " " << y[i][j] << " " << y[k][k] << " " << y[i][k] << " " << y[k][
  }
  cout << ans << endl;
}


Measured memory_bytes: 11544
#include<stdio.h>

int main(void) {
	int N, X;
	int L[120], D[120];
	int i, answer = 0;
	
	scanf("%d %d", &N, &X);
	
	for(i = 0;i < N;i++) {
		scanf("%d", &L[i]);
	}
	
	D[0] = 0;
	
	for(i = 1;i <= N;i++) {
		D[i] = D[i - 1] + L[i - 1];
	}
	
	for(i = 0;i <= N;i++) {
		if(D[i] <= X) {
			answer = answer + 1;
		}
	}
	
	printf("%d", answer);
	
	return 0;
}		

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

int main() {
  int N, L;
  cin >> N >> L;
  int ajimin = 1000;
  int imin;
  for (int i = 1; i <= N; i++) {
    if (ajimin > abs(L+i-1)) {
      ajimin = abs(L+i-1);
      imin = i;
    }
  }
  cout << N*(L-1) + N*(N+1)/2 - (L+imin-1) << endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



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

    int a[n];
    inrep(n,a);
    sort(a,a+n);

    int ans = 0;
    rep(i,0,k)ans += a[i];
    P(ans);
    
    return  0;
}


Measured memory_bytes: 3544
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



signed main() {
	int n, ans = 0;
	cin >> n;
	map<string, int>mp;
	rep(i, n) {
		char a[15];
		rep(j, 10) {
			cin >> a[j];
		}
		sort(a, a + 10);
		string s;
		rep(j, 10) {
			s += a[j];
		}
		mp[s]++;
	}
	for (auto i = mp.begin(); i != mp.end(); i++) {
		int x = i->second;
		ans += x * (x - 1) / 2;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	int l;
	cin >> l;
	long double n = (long double)l / 3;
	long double ans = n * n * n;

	cout << fixed << setprecision(10);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := scanInt()
	m := scanInt()
	sum := 0
	for i := 0; i < m; i++ {
		sum += scanInt()
	}
	if n-sum < 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(n - sum)
	}

	return
}

var sc = bufio.NewScanner(os.Stdin)

func scanString() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}
func Permute(nums []int) [][]int {
	n := factorial(len(nums))
	ret := make([][]int, 0, n)
	permute(nums, &ret)
	return ret
}

func permute(nums []int, ret *[][]int) {
	*ret = append(*ret, makeCopy(nums))

	n := len(nums)
	p := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		p[i] = i
	}
	for i := 1; i < n; {
		p[i]--
		j := 0
		if i%2 == 1 {
			j = p[i]
		}

		nums[i], nums[j] = nums[j], nums[i]
		*ret = append(*ret, makeCopy(nums))
		for i = 1; p[i] == 0; i++ {
			p[i] = i
		}
	}
}

func factorial(n int) int {
	ret := 1
	for i := 2; i <= n; i++ {
		ret *= i
	}
	return ret
}
func makeCopy(nums []int) []int {
	return append([]int{}, nums...)
}
func gcd(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func main() {
	sc.Split(bufio.ScanWords)
	solve()
}


Measured memory_bytes: 1804
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    int ans;
    int diff = abs(a[n-1] - a[0] * 2);
    rep(i, n) {
        int diff2 = abs(a[n-1] -a[i]*2);
        if ( diff > diff2 ) {
            diff = diff2;
            ans = a[i];
        }
    }
    cout << a[n-1] << " " << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
vector<int> v;

const int maxn = 5e5+400;
typedef long long ll;

int main(){
    ll n;
    cin>>n;
    ll ans=0x3f3f3f3f3f3f3f3f;
    for(int i=1;i<=sqrt(n)+1;i++){
        if(n%i==0){
            ll tmp=n/i;
            ans=min(ans,tmp+i-2);
        }
    }
    cout<<ans<<endl;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)    cin >> a[i];
    if(n==1)    cout << "0";
    else
    {
        int c=0,s=0,e=a[n-1];
        for(int i=(n-2);i>=0;i--)
        {
            if(e<=a[i])
            {
                s++;
                c=max(c,s);
            }    
            else    s=0;
            e=a[i];
        }
        cout << c;
    }    
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <array>
#include <bitset>
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'
using namespace std;

signed main() {
    fastio;
    long double d, t, s;
    cin >> d >> t >> s;
    if (d / s <= t) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
using namespace std; 
int main() { 
  string s;  
  cin >> s; 
  for(int i=0; i<s.size(); i++) {
    if(s[i]<'D') s[i] = s[i]+('Z'-'C'); 
    else s[i]-=3; 
  }  
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 1180
#include <stdio.h>
#include <vector>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
using vi = vector<int>;

string str;
string stra;
int id = 0;

void pt(vector<int> v){
  for(int r=0;r<v.size();r++){
    cout << v[r];
  }
  cout << endl;
}

vi number(){
  vi res;
  for (;'0'<=stra[id]&&stra[id]<='9'; id++) {
    res.push_back(stra[id] - '0');
  }
  reverse(res.begin(),res.end());
  return res;
}
int solve(){
  stra = str;
  for (int i = 9; i >= 0; i--) {
    id = 0;
    for (int j = 0; j <(int)str.size(); j++) {
      if (str[j] == 'X') {
        stra[j] = i + '0';
      }
    }
    vi a = number();
    if (stra[id] == '+' ) {
      id++;
    }
    vi b = number();

    a.resize(max(b.size() + 1,a.size()+1),0);
    // 
    // a.push_back(0);
    // while(a.size()<=b.size()){
    //   a.push_back(0);
    // }
    for (int j = 0; j < (int)b.size(); j++) {
      a[j] += b[j];
      // if (a[j]>=10) {
      //   a[j] -= 10;
      //   a[j+1]++;
      // }
    }
    // for (int j = b.size(); j < (int)(a.size()-1); j++) {
    //   if (a[j] >= 10) {
    //     a[j] -= 10;
    //     a[j+1]++;
    //   }
    // }
    for(int j=0;j<(int)a.size()-1;j++){
      if(a[j]>=10){
        a[j]-=10;
        a[j+1]++;
      }
    }

    if(a[a.size()-1]==0){
      a.pop_back();
    }

    //pt(a);
    // int j;
    // int k=0;
    // int l=0;
    // vi ab;
    // for(j=0;j<int(a.size())&&j<int(b.size());j++){
    //   k=0;
    //   if(a[j]+b[j]+l>=10){
    //     k++;
    //     ab.push_back(a[j]+b[j]+l-10);
    //   }
    //   else{
    //     ab.push_back(a[j]+b[j]+l);
    //   }
    //   l=k;
    // }
    // for(;j<int(a.size());j++){
    //   k=0;
    //   if(a[j]+l>=10){
    //     k++;
    //     ab.push_back(a[j]+l-10);
    //   }
    //   else{
    //     ab.push_back(a[j]+l);
    //   }
    //   l=k;
    // }
    // for(;j<int(b.size());j++){
    //   k=0;
    //   if(b[j]+l>=10){
    //     k++;
    //     ab.push_back(b[j]+l-10);
    //   }
    //   else{
    //     ab.push_back(b[j]+l);
    //   }
    //   l=k;
    // }
    // if(l>0){
    //   ab.push_back(l);
    // }
    // a=ab;
    /////////
    if (stra[id] == '=') {
      id++;
    }

    vi c = number();
    if (a.size() != c.size()) {
      continue;
    }
    int flag = 0;
    for (int j = 0; j < (int)a.size(); j++) {
      if (a[j] == c[j]) {
        flag++;
      }
    }
    if (flag ==(int)a.size()) {
      return i;
    }

  }
  return -1;
}
int main(){
  cin >> str;
  while(str.size()){
  int ans = solve();
  if (ans >= 0) {
    cout << ans << endl;
  } else {
    cout << "NA" << endl;
  }
  str="";
  cin >> str;
}
  return 0;
}



Measured memory_bytes: 3148
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) x.begin(),x.end()
#define endl '\n'

#ifndef ONLINE_JUDGE       
template<typename T>    
void __p(T a) {
  cerr<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cerr<<"[";
  __p(a.first);
  cerr<<",";
  __p(a.second);
  cerr<<"]";
}
template<typename T>
void __p(std::vector<T> a) {
  cerr<<"[";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cerr<<",]"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr<<name<<" : ";
  __p(arg1);
  cerr<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cerr.write(names,comma-names)<<" : ";
  __p(arg1);
  cerr<<" | ";
  __f(comma+1,args...);
}
#define trace(...) cerr<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#endif

void test_case(){
	double d,t,s;
	cin>>d>>t>>s;
	double tm=d/s;
	if(tm<=t){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 
    int T=1;
    //cin>>T;
    for(int TT=1; TT<=T; TT++){
        test_case();
    }

    cerr<<endl<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

    return 0;
}


Measured memory_bytes: 3764
n=int(input())
li=[]
for i in range (0,n):
  a,b=map(int,input().split())
  li.append([b,a])
li.sort()
t=0
j=0
for i in range (0,n):
  t=t+li[i][1]
  if t>li[i][0]:
    j=j+1
if j==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 35608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define FOR(i, i0, n) for(int i = (i0); i < (n); i ++)
#define COUT(val) cout << (val) << "\n";
using namespace std;
using ll = long long int;

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    FOR(i, 0, n) cin >> a[i];
    
    //vector<vector<int>> a(n, vector<int>(k+1));
    vector<bool> dp(k+1);
    dp[0] = false;
    
    FOR(i, 1, k+1){
        FOR(j, 0, n){
            if(i-a[j] >= 0 && !dp[i-a[j]]){
                dp[i] = true;
                break;
            }
        }
    }
    
    COUT(dp[k] ? "First" : "Second");
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int a, b;
  cin >> a >> b;
  if ((a + b) % 2)
    cout << "IMPOSSIBLE" << endl;
  else
    cout << (a + b) / 2 << endl;
}


Measured memory_bytes: 384
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n,k;
    R(n,k);
    string s;
    R(s);
    VPII AA;
    for(int i=0,j;i<SZ(s);i=j){
        for(j=i+1;j<SZ(s)&&s[j]==s[i];j++);
        AA.PB({s[i]-'0',j-i});
    }
    int ll=0;
    int now=0,an=0;
    REP(i,SZ(AA)){
        now+=AA[i].S;
        if(AA[i].F==0)k--;
        while(k<0){
            if(AA[ll].F==0)k++;
            now-=AA[ll].S;
            ll++;
        }
        an=max(an,now);
    }
    W(an);
    return 0;
}


Measured memory_bytes: 1528
a = list(map(int,input().split()))
a.sort()
if (a[1]-a[0]) % 2 == 0:
    print((a[1]-a[0])//2 + (a[2]-a[1]))
else:
    print((a[2]-a[1])//2 + (a[2]-a[1])%2 + (a[2]-a[0]+1)//2 + 1)    

Measured memory_bytes: 9032
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

ll mod = 1e9+7;

ll fpow(ll a, ll b, ll md){
	ll res = 1;
	a = (a%md);
	while(b>0){
		if(b%2==1){
			res = (res*a)%md;
		}
		b = b/2;
		a = (a*a)%md;
	}
	return res%md;
}

void solve(){
	int n;
	cin>>n;
	map<int,int> cnt;
	int r = n-1;
	for(int i=0;i<n;i++){
		cnt[abs(r-i)] += 1;
		r--;
		int u;
		cin>>u;
		cnt[u] -= 1;
	}
	for(auto x:cnt){
		if(x.Y != 0){
			cout<<0<<endl;
			return;
		}
	}
	int s = cnt.size();
	if(n%2) s-=1;

	
	cout<<fpow(2,s,mod)<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	String O = scan.next();
	String E = scan.next();

	StringBuilder str = new StringBuilder();
	for (int i = 0; i < E.length(); i++) {
	    str.append(O.charAt(i));
	    str.append(E.charAt(i));
	}
	if(O.length()-E.length() == 1) str.append(O.charAt(O.length()-1));

	System.out.println(str.toString());
	scan.close();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
using ll = long long;

int main(void)
{
    double l;
    cin >> l;
    // 1/3 L * 1/3L * 1/3L
    // L * L * L / 27
    printf("%.16lf\n", l * l * l / 27.0);
}

Measured memory_bytes: 256
import sys
import heapq
input=sys.stdin.readline
def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d
n,m,s,t=map(int,input().split())
ey=[[] for _ in range(n)]
es=[[] for _ in range(n)]
for i in range(m):
  u,v,a,b=map(int,input().split())
  ey[u-1].append([a,v-1])
  ey[v-1].append([a,u-1])
  es[u-1].append([b,v-1])
  es[v-1].append([b,u-1])
dy=dijkstra_heap(s-1,ey)
ds=dijkstra_heap(t-1,es)
accumb=[10*10]*n
accumb[n-1]=int(dy[n-1]+ds[n-1])
for i in range(1,n):
  accumb[n-i-1]=int(min(dy[n-i-1]+ds[n-i-1],accumb[n-i]))
money=10**15
for i in range(n):
  print(money-accumb[i])

Measured memory_bytes: 128620
import sys
readline = sys.stdin.readline
INF = 10 ** 9

def main():
    N, K, S = map(int, readline().rstrip().split())
    if S < INF:
        res = [S] * K  + [INF] * (N - K)
    else:
        res = [S] * K + [1] * (N - K) 

    print(*res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 6780
#include<stdio.h>
#define MAX 100000

int partition(int A[], int p, int r)
{
	int i, j, t;
	int x = A[r];
	i = p - 1;
	for(j = p; j < r; j++) {
		if(A[j] <= x) {
			i++;
			t = A[i];
			A[i] = A[j];
			A[j] = t;
		}
	}
	t = A[i+1];
	A[i+1] = A[r];
	A[r] = t;

	return i+1;
}
int main()
{	
	int i, n, idx;
	int A[MAX];
	scanf("%d", &n);

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

	idx = partition(A, 0, n-1);

	for(i = 0; i < n; i++) {
		if(i)
			printf(" ");
		if(i == n-1) {
			printf("%d\n", A[i]);
		}
		else {
			if(i == idx)
				printf("[");
			printf("%d", A[i]);
			if( i == idx)
				printf("]");
		}
	}

    return 0;
}

Measured memory_bytes: 996
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//







int main(void) {

    int N; cin >> N;
    int a[N]; rep(i,N) cin >> a[i];
    int sum = 0;
    rep(i,N) sum += a[i];
    int c = sum / N;
    ll E_1, E_2;
    E_1 = E_2 = 0;
    rep(i,N) {
        E_1 += pow(a[i] - c, 2);
        E_2 += pow(a[i] - (c + 1), 2);
    }
    out(min(E_1, E_2));
    

    return 0;
}











Measured memory_bytes: 256
import numpy as np

n, m, x = map(int, input().split())
ca_list = [list(map(int, input().split())) for _ in range(n)]

ans = 10**7
for i in range(2**n):
    select_list = list(map(int, format(i, '0'+str(n)+'b')))
    tmp = []
    r = np.array([x] * m)
    money = 0
    c = True
    for i, ca in enumerate(ca_list):
        if select_list[i]:
            r -= np.array(ca[1:])
            money += ca[0]
    for i in r:
        if i > 0: c = False
    if c:
        ans = min(ans, money)
if ans == 10**7:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 27136