akhauriyash/Code-Regression huggingface dataset:
// Problem : A - Table Tennis Training
// Contest : AtCoder - AtCoder Grand Contest 041
// URL : https://atcoder.jp/contests/agc041/tasks/agc041_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int n,a,b;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>a>>b;
    if((b-a)%2 == 0) cout<<(b-a)/2;
    else cout<<min(a-1,n-b)+1+(b-a-1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;



int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> l(n), r(n);
  l[0] = a[0];
  r[n-1] = a[n-1];
  for (int i = 1; i < n; i++){
    l[i] = l[i-1] + a[i];
  }
  for (int i = n-2; i >= 0; i--){
    r[i] = r[i+1] + a[i];
  }
  ll ans = INF;
  rep(i, n-1){
    ll tmp = abs(l[i] - r[i+1]);
    if (tmp < ans) ans = tmp;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int32_t main() {
	string s;
	int ans=mod,i;
	cin>>s;
	int n=s.length();
	for(i=0;i+2<n;i++)
	{
		int k=stoi(s.substr(i,3));
		//cout<<"k is "<<k<<"\n";
		ans=min(ans,abs(k-753));
	}
	cout<<ans<<"\n";
}

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

int A[MAX], n;

int partition(int p, int r)
{
  int x, i, j, t;
  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 q;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &A[i]);
  }

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

  return 0;
}


Measured memory_bytes: 3108
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りの計算方法で実装
 */
public class Main {

	/** 平均気温の係数 */
	private static final int D = 6;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), t = scanner.nextInt() * 1000, a = scanner.nextInt() * 1000;
			Queue<Data> queue = new PriorityQueue<>();
			IntStream.range(0, n).forEach(i -> {
				int h = scanner.nextInt();
				queue.add(new Data(i + 1, Math.abs(t - h * D - a)));
			});
			System.out.println(queue.peek().index);
		}
	}

	/**
	 * 番号と平均気温を表すクラス
	 */
	private static class Data implements Comparable<Data> {
		/** 番号 */
		int index;
		/** 平均気温 */
		double t;

		Data(int index, double t) {
			super();
			this.index = index;
			this.t = t;
		}

		@Override
		public int compareTo(Data data) {
			return Double.compare(t, data.t);
		}
	}
}


Measured memory_bytes: 39096
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int get() { int r; cin >> r; return r; }
int h, n, ans = mod;
int k[123456];
signed main() {
	cin >> h >> n;
	for1(i, 20000)k[i] = mod;
	for1(i, n) {
		int a, b; cin >> a >> b;
		k[a] = min(k[a], b);
	}
	for1(i, h) {
		for0(j, i)k[i] = min(k[i], k[j] + k[i - j]);
		for1(j, i)k[j] = min(k[j], k[i]);
	}
	for (int i = 15000; i >= h; i--)k[i] = min(k[i], k[i + 1]);
	cout << k[h] << endl;
}

Measured memory_bytes: 512
s = input()
flag = True
while flag:
    if s=='':
        flag==False
    if s[-7:]=='dreamer':
        s = s[:-7]

    elif s[-6:]=='eraser':
        s = s[:-6]

    elif s[-5:]=='dream' or s[-5:]=='erase':
        s = s[:-5]

    else:
        break


if s=='':
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define ret return
#define all(vl) vl.begin(),vl.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;
bool zhi[1000001];
int main()
{
	zhi[0] = zhi[1] = 1;
	vector<ll> vl;
	ll n;cin>>n;
	for(ll i = 2;i<1000001;i++)
	{
		if(!zhi[i])
			vl.pb(i);
		for(ll j = i*i;j<1000001;j+=i)
			zhi[j] = 1;
	}
	ll cnt = 0;
	ll cop = n;
	bool isok = false;
	int sz = vl.size();
	for(int i=0;i<sz;i++)
	{
		ll cc = 0;
		while(cop%vl[i] == 0)
		{
			cc++;
			cop/=vl[i];
		}
		ll cn,ccn;
		cn = 1,ccn = 0;
		while(cc>=cn)
		{
			cc-=cn;
			ccn++;
			cn++;
		}
		cnt+=ccn;
	}
	if(cop>1)
		cnt++;
	cout<<cnt<<endl;
	return 0;
}

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

int n; ll l,t;
vector<ll> x;
vector<int> w;

int main() {
  cin >> n >> l >> t;
  x.resize(n); w.resize(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> w[i];
  vector<ll> tmp(n);
  for (int i = 0; i < n; i++) {
    if (w[i] == 1) tmp[i] = (x[i] + t) % l;
    else tmp[i] = ((x[i] - t) % l + l) % l;
  }
  sort(tmp.begin(), tmp.end());
  ll count = 0;
  for (int i = 0; i < n; i++) {
    if (w[i] == 1) count -= (t - (l - x[i]) + l) / l;
    else count += (t - (x[i] + 1) + l) / l;
  }
  count = (count % n + n) % n;
  vector<ll> res(n);
  for (int i = 0; i < n; i++) res[(i+count)%n] = tmp[i];
  for (int i = 0; i < n; i++) cout << res[i] << endl;

  return 0;
}

Measured memory_bytes: 5788
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    long long N, K; cin >> N >> K;

    vector<vector<int> > doubling(60, vector<int>(N));
    for (int i = 0; i < N; i++) {
        cin >> doubling[0][i];
        doubling[0][i]--;
    }

    for (int i = 1; i < 60; i++) {
        for (int j = 0; j < N; j++) {
            doubling[i][j] = doubling[i-1][doubling[i-1][j]];
        }
    }

    int ans = 0;
    for (int i = 0; i < 60; i++) {
        if (K & (1LL<<i)) ans = doubling[i][ans];
    }
    ans++;

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 50920
#include <iostream>
#include <string>

using namespace std;

int main()
{
  int x, k;

  cin >> k >> x;

  if (k * 500 >= x)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <boost/range/combine.hpp>

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

template <typename... T>
auto zip(T&&... containers) -> boost::iterator_range<boost::zip_iterator<decltype(boost::make_tuple(begin(containers)...))>>
{
    auto zip_begin = boost::make_zip_iterator(boost::make_tuple(begin(containers)...));
    auto zip_end = boost::make_zip_iterator(boost::make_tuple(end(containers)...));
    return boost::make_iterator_range(zip_begin, zip_end);
}

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for (auto v : zip(S, T)) {
        char s, t;
        boost::tie(s, t) = v;
        if (s != t) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if((a*b)%2==0){
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int n;
const int maxn=2e5+10;
int a[maxn],b[maxn],na[maxn],nb[maxn];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    int ans=0;
    for(int i=0;i<=28;i++)
    {
        for(int j=1;j<=n;j++)
            na[j]=a[j]&((1<<(i+1))-1),nb[j]=b[j]&((1<<(i+1))-1);
        sort(nb+1,nb+1+n);
        int t1=1<<i,t2=2*t1,t3=3*t1,t4=4*t1;
        int now=0;
        for(int j=1;j<=n;j++)
        {
            now^=(lower_bound(nb+1,nb+1+n,t2-na[j])-lower_bound(nb+1,nb+1+n,t1-na[j]))&1;
            now^=(lower_bound(nb+1,nb+1+n,t4-na[j])-lower_bound(nb+1,nb+1+n,t3-na[j]))&1;
        }
        ans+=now<<i;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
	int a,b[10],x=0,y=0;
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> b[i];
		x += b[i];
		if (y < b[i])y = b[i];
	}
	cout << x - y / 2 << endl;
	return 0;

}

	
	

	

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

int main(){
  char s[3];
  int i;
  int num=0;
  scanf("%s", s);
  
  for(i=0;i<3;i++){
    if(s[i]=='1')num++;
  }
  
  printf("%d\n", num);
}


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

int main(){
    int k, n, x, ans = 0;

    cin >> n >> k;

    if(k != n){
        for(int i=0; i<n; ++i){
            cin >> x;
            if(x == 1){
                if(i !=  0) ans += (i + (k-2)) / (k-1);
                i = ans * (k-1);
                if(i != n-1)ans += ((n-i-1) + (k-2)) / (k-1);
                cout << ans << endl;
                return 0;
            }
        }
    }

    cout << 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{   
   long long  int r,g,b,k,c=0;
   cin>>r>>g>>b>>k;
   while(g<=r)
   {
       c++;
       g=g*2;
   }
   while(b<=g)
   {
       c++;
       b=b*2;
   }
  // printf("%lld %lld %lld\n",r,g,b);
   if(c<=k)
   {
       printf("Yes\n");
   }
   else
   {
       printf("No\n");
   }
}

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

int main() {
  int x,y,z,K; cin>>x>>y>>z>>K;
  vector<ll> a(x),b(y),c(z);
  rep(i, x) cin>>a[i];
  rep(i, y) cin>>b[i];
  rep(i, z) cin>>c[i];

  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());
  vector<ll> ans;
  rep(i, x) {
    rep(j, y) {
      rep(k, z) {
        if ((i+1)*(j+1)*(k+1)<=K) {
          ans.push_back(a[i]+b[j]+c[k]);
        }
        else break;
      }
    }
  }
  sort(ans.begin(), ans.end(), greater<ll>());
  rep(i, K) cout<<ans[i]<<endl;
  return 0;
}


Measured memory_bytes: 1404
from collections import deque

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

b = deque()

for i in range(len(a)):
    if i % 2 == 0:
        b.append(str(a[i]))
    else:
        b.appendleft(str(a[i]))
    last = i

if last % 2 == 0:
    b.reverse()

print(' '.join(b))


Measured memory_bytes: 33164
#include<cstdio>
#include <algorithm>
using namespace std;

struct node
{
	long long p;
	long long d;//p shuliang
};
bool cmp(node a,node b)
{
	if(a.d!=b.d)return a.d<b.d;
	
	return a.p>b.p;
}
int main()
{
	int n,m,i,j;
	scanf("%d%d",&n,&m);
	node a[n];
	for(i=0;i<n;i++)
	scanf("%lld%lld",&a[i].d,&a[i].p);
	
	sort(a,a+n,cmp);
	long long max=0;
	i=0;
	while(m>0)
	{
		max+=a[i].d*(a[i].p<m?a[i].p:m);
		
		m-=a[i].p;
		i++;
	}
	printf("%lld",max);
	return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
   
int main(void){
   
int i, j;
int k;
int marble;
int queue[25]={0};
int ani, oto;
   
while(1){
   
   
scanf("%d", &i);
   
if(i==0)
break;
   
for(j=0; j<i; j++)
scanf("%d", &queue[j]);
 
marble=32;
k=0;
   
while(marble!=0){
   
ani=(marble-1)%5;
   
if(queue[k]!=0)
oto=queue[k];
else{
k=0;
oto=queue[k];
}
   
marble=marble-ani;
   
if(marble>0)
printf("%d\n", marble);
else
marble=0;
    
marble=marble-oto;
   
if(marble>0)
printf("%d\n", marble);
else
marble=0;
   
k++;
   
  }
   
printf("%d\n", 0);
   
 }
   
return 0;
   
}

Measured memory_bytes: 600
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	const A = args[1].map(arg => parseInt(arg, 10))
	const B = args[2].map(arg => parseInt(arg, 10))
	const C = args[3].map(arg => parseInt(arg, 10))
	let ans = 0
	let prev = -1

	for (let i = 0; i < N; i++) {
		const a = A[i] - 1
		ans += B[a]
		if (prev !== -1 && a === prev + 1) ans += C[prev]
		prev = a
	}

	console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
*/

//=================================================
int N;
//=================================================
void input()
{
    cin>>N;
}

//=================================================
void solve()
{
    stack<char> s;
    int v=1, w=1;
    while (N) {
        if (N & 1) {
            s.push('1');
        }
        else {
            s.push('0');
        }

        N = (N>0) ? (-N/2) : -(N-1)/2;
    }

    if (s.empty()) {
        cout<<0<<endl;
    }
    else {
        while (!s.empty()) {
            cout<<s.top();
            s.pop();
        }
        cout<<endl;
    }

}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int inf = 2147483647;
  int N , K;
  cin >> N >> K;
  
  vector<int> height(N);
  vector<vector<int>> steps(N,vector<int>(K));
  
  for(int i = 0; i < N; i++){
    cin >> height.at(i);
  } 
  /*
  for(int i = 0; i < N; i++){
    cout << height.at(i) << " ";
  }
  cout << endl;
  */
  
  //i番目からj段飛ばし
  for(int i = 0; i < N-1; i++){
    for(int j = 0; j < K ; j++){
//    if(i == 0){
//      steps.at(i).at(0) = 0;
//    }
//    else{
        if(i + j >= N - 1){
          steps.at(i).at(j) = inf;
        }
        else{
          steps.at(i).at(j) = abs( height.at(i + j + 1) - height.at(i) );
        }
//    }  
    }
  }
/*
  for(int i = 0; i < N-1; i++){
    for(int j = 0; j < K; j++){
      cout << steps.at(i).at(j) << " ";
    }
    cout << endl;
  }
  
  cout << "begin" << endl;
*/  
  //DPのはじまり
  vector<int> DP(N);
  DP.at(0) = 0;
  
  for(int i = 1; i < N; i++){
    int a = inf;
    for(int j = 0; j < min(i,K); j++){
      if(i > j){
        int p = DP.at(i-j-1) + steps.at(i-j-1).at(j);
        a = min(a, p);
      }
    }
    DP.at(i) = a;
  }
/*
  for(int i = 0; i < N; i++){
    cout << DP.at(i) << " ";
  }
  cout << endl;
*/
  cout << DP.at(N-1) << endl;
}

Measured memory_bytes: 44032
def turukame(a, b, num, remain)
  y = (remain - a * num) / (b - a)
  x = num - y

  return [-1, -1] if remain != a * x + b * y
  return [-1, -1] if y < 0 || x < 0

  [x, y]
end

X, Y = gets.split.map(&:to_i)

a, b = turukame(2, 4, X, Y)

if a < 0 || b < 0
  puts 'No'
else
  puts 'Yes'
end


Measured memory_bytes: 14372
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5,M=2*N,inf=1e8;
int n,i,et,he[N],l[N],r[N];bool flag;
struct edge{int l,to;}e[M];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
void put(int x){if (x>9) put(x/10);putchar(x%10+48);}
void write(int x){
	if (x<0) putchar('-'),x=-x;
	put(x);putchar('\n');
}
void dfs1(int x,int fa){
	for (int i=he[x];i;i=e[i].l){
		int y=e[i].to;if (y==fa) continue;
		dfs1(y,x);
		l[x]=max(l[x],l[y]-1);
		r[x]=min(r[x],r[y]+1);
	}
}
void dfs2(int x,int fa){
	for (int i=he[x];i;i=e[i].l){
		int y=e[i].to;if (y==fa) continue;
		l[y]=max(l[y],l[x]-1);
		r[y]=min(r[y],r[x]+1);
		if (!((l[x]^l[y])&1)) flag=0;
		dfs2(y,x);
	}
}
int main(){
	for (n=read(),i=1;i<n;i++){
		int x=read(),y=read();
		e[++et].l=he[x];he[x]=et;e[et].to=y;
		e[++et].l=he[y];he[y]=et;e[et].to=x;
	}
	for (i=1;i<=n;i++) l[i]=-inf,r[i]=inf;
	for (i=read();i--;){
		int x=read();l[x]=r[x]=read();
	}
	dfs1(1,0);flag=1;dfs2(1,0);
	for (i=1;i<=n;i++) if (l[i]>r[i]) flag=0;
	if (!flag){puts("No");return 0;}
	for (puts("Yes"),i=1;i<=n;i++) put(r[i]),putchar('\n');
}

Measured memory_bytes: 8320
#!/usr/bin/env ruby
# opt(i) = min(opt(i-2)+|c(i, i-2)|, opt(i-1)+|c(i, i-1)|)

n = STDIN.readline.strip.to_i
h = STDIN.readline.strip.split(' ').map(&:to_i)

def opt(h)
  m = []
  m[0] = 0
  m[1] = (h[1] - h[0]).abs 
  for i in 2..h.size-1 do
    c_1 = m[i-1] + (h[i] - h[i-1]).abs
    c_2 = m[i-2] + (h[i] - h[i-2]).abs
    m[i] = [c_1, c_2].min
  end
  m[-1]
end

puts opt(h)


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 2e3 + 5;

int n, k, q;
int a[MAXN];

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

    cin >> n >> k >> q;
    REP(i, n){
        cin >> a[i];
    }

    int sol = 2e9;
    REP(i, n){

        vector <point> v;
        int left = -1;
        int bounds = a[i];

        REP(j, n){
            if(a[j] < bounds){
                if(left != -1 && j - left >= k){
                    v.push_back(point(left, j - 1));

                }
                left = -1;
            }
            else if (left == -1)
                left = j;
        }
        if(left != -1 && a[n - 1] >= bounds && n - left >= k)
            v.push_back(point(left, n - 1));

        vector <int> num;

        REP(curr, sz(v)){
            vector <int> mini;

            FOR(j, v[curr].first, v[curr].second + 1){
                mini.push_back(a[j]);
            }
            sort(mini.begin(), mini.end());
            //cout << sz(mini) << "\n";
            REP(j, mini.size() - k + 1)
                num.push_back(mini[j]);
        }
        //cout << sz(num) << "\n";
        sort(num.begin(), num.end());

        if(num.size() < q) continue;
        //cout << bounds;
        int x = num[0];
        int y = num[q - 1];

        sol = min(sol, y - x);
    }

    cout << sol;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef pair<ll,const char*> parsed;

parsed expr(const char*);
parsed term(const char*);
parsed fact(const char*);

parsed expr(const char* s)
{
	//cout<<"expr(\""<<s<<"\")"<<endl;
	parsed now=term(s);
	while(*now.second=='+' || *now.second=='-'){
		char op=*now.second;
		parsed next=term(now.second+1);
		if(op=='+')
			now=parsed(now.first+next.first,next.second);
		else
			now=parsed(now.first-next.first,next.second);
	}
	//cout<<"expr(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

parsed term(const char* s)
{
	//cout<<"term(\""<<s<<"\")"<<endl;
	parsed now=fact(s);
	while(*now.second=='*' || *now.second=='/'){
		char op=*now.second;
		parsed next=fact(now.second+1);
		if(op=='*')
			now=parsed(now.first*next.first,next.second);
		else
			now=parsed(now.first/next.first,next.second);
	}
	//cout<<"term(\""<<s<<"\")="<<now.first<<endl;
	return now;
}

//parsed fact(const char* s)
//{
//	//cout<<"fact(\""<<s<<"\")"<<endl;
//	if(s[0]=='('){
//		parsed res=expr(s+1);
//		res.second++;
//		return res;
//	}
//	else{
//		const char* p=s;
//		if(*p=='-')
//			p++;
//		ll n=0;
//		while(isdigit(*p)){
//			n=n*10+*p-'0';
//			p++;
//		}
//		return parsed(n,p);
//	}
//}

parsed fact(const char *p)
{
  if (isdigit(*p)){
    //int t=*(p++)-'0';
    int t=0;
    while(isdigit(*p)) t=t*10+*(p++)-'0';
    return parsed(t,p);
  }
  else if (*p=='('){
    parsed r=expr(p+1);
    if (*r.second!=')') exit(0); // invalid input
    return parsed(r.first,r.second+1);
  }
  else
    exit(0); // invalid input
}

int main()
{
	string s;
	getline(cin,s);
	while(getline(cin,s))
		cout<<expr(s.c_str()).first<<endl;
	
	return 0;
}

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

#define N 100000

int n;
long long m;
long long a[N];
long long acc[N] = {0};

int main()
{
	long long ans = 0;
	map<long, long> t;

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

	t[ 0 ]++;
	acc[0] = a[0] % m;
	t[ acc[0] ]++;
	for( int i = 1; i < n; i++ ) {
		acc[i] += ( acc[i - 1] + a[i] ) % m;
		t[ acc[i] ]++;
	}

	for( auto it = t.begin(); it != t.end(); it++ ) {
		long long v = it->second;
		if( v > 1 ) {
			ans += v * ( v - 1 ) / 2;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5760
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String[] str = br.readLine().split(" ");
      int x = Integer.parseInt( str[0] );
      int y = Integer.parseInt( str[1] );

      System.out.println( gcd(x,y) );
    }
  }

  static int gcd(int x, int y) {
    if( x<y ){
      int tmp = x; x = y; y = tmp;
    }

    int r;
    while( y>0 ) {
      r = x%y;
      x = y; y = r;
    }

    return x;
  }
}


Measured memory_bytes: 24376
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double[] v = new double[n];
        for (int i = 0; i < n; i++) {
            v[i] = sc.nextDouble();
        }
        Arrays.sort(v);
        for (int i = 0; i < n -1; i++) {
            v[i+1] = (v[i]+v[i+1])/2;
        }
        System.out.println(v[n-1]);
    }
}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll max1 = 0, max2 = 0;
    for(int i = 0; i < N;i++) {
        cin >> A[i];
        if(A[i] > max1) max1 = A[i];
        else if(A[i] > max2) max2 = A[i];
    }
    for(int i = 0; i < N; i++){
        if(A[i] == max1) cout << max2 << endl;
        else cout << max1 << endl;
    }
    return 0;
}

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

typedef long long ll;
ll N;

int main(){
    cin >> N;
    for(ll h = 1;h <= 3500;++h){
        for(ll n = 1;n <= 3500;++n){
            ll fz = 4*h*n-N*n-N*h;
            ll fm = N*h*n;
            if(fz <= 0) continue;
            if(fm % fz == 0){
                cout << h << ' ' << n << ' ' << fm / fz << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

typedef long long ll;
ll INF = 1LL << 60;
ll MAX = 100010;

ll
gcd(ll c, ll d)
{
  return d ? gcd(d, c % d) : c;
}

int
main() 
{

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  a -= 1;

  ll GCD = gcd(c, d);
  ll mul = c / GCD * d;
  ll ans_a = a - (a / c) - (a / d) + a / mul;
  ll ans_b = b - (b / c) - (b / d) + b / mul;

  cout << ans_b - ans_a << endl;


}



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

int main(){
	char area[8][8];
	char c;
	while(cin >> c){
		while(!isalnum(c)) cin >> c;
		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++){
				area[i][j] = c;
				if(i ==  7 && j == 7) break;
				cin >> c;
			}
		}
		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++){
				if(area[i][j] == '1'){
					if(i+1 < 8 && area[i+1][j] == '1'){
						if(i+2 < 8 && area[i+2][j] == '1'){
							if(i+3 < 8 && area[i+3][j] == '1'){
								cout << "B";
							}
						}
						if(j+1 < 8 && area[i+1][j+1] == '1'){
							if(i+2 < 8 && area[i+2][j+1] == '1'){
								cout << "F";
							}
							if(area[i][j+1] == '1'){
								cout << "A";
							}
						}
						if(j+1 < 8 && area[i][j+1] == '1'){
							if(j-1 >= 0 && area[i+1][j-1] == '1'){
								cout << "G";
							}
						}
						if(j+1 < 8 && area[i][j+1] == '1'){
							if(i-1 >= 0 && area[i-1][j+1] == '1'){
								cout << "D";
							}
						}
					}else if(j+1 < 8 && area[i][j+1] == '1'){
						if(j+2 < 8 && area[i][j+2] == '1'){
							if(j+3 < 8 && area[i][j+3] == '1'){
								cout <<"C";
							}
						}
						if(i+1 < 8 && area[i+1][j+1] == '1'){
							if(j+2 < 8 && area[i+1][j+2] == '1'){
								cout << "E";
							}
						}
					}
				}
			}
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010
#define NO_COLOR    0
#define BLACK       1
#define WHITE       2

ll N, M;
int color[MAX_N];   // 各頂点の色
vector<int> edge[MAX_N];

// 各頂点に色を塗る
// 隣接する点は違う色を塗る
// もしうまく塗れない場合は奇ループがある return 1 する
int dfs(int id) {
    int paint;
    if(color[id] == BLACK) { paint = WHITE; }
    else { paint = BLACK; }
    for(auto e : edge[id]) {
        if(color[e] == NO_COLOR) {
            color[e] = paint;
            int ret = dfs(e);
            if(ret == 1) { return 1; }
        }
        else if(color[e] != NO_COLOR && color[e] != paint) { return 1; }
    }
    return 0;
}

int main()
{
    ZERO(color);
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        scanf("%d %d", &a, &b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    color[1] = WHITE;
    if(dfs(1) == 1) {
        ll ans = N * (N - 1) / 2;
        printf("%lld\n", ans - M);
    } else {
        ll white_num = 0, black_num = 0;
        for(int i = 1; i <= N; ++i) {
            if(color[i] == WHITE) { white_num++; }
            else { black_num++; }
        }
        ll ans = white_num * black_num - M;
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 6400
#include <iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;



int main() {
    string S;
    cin>>S;
    sort(rng(S));
    if(S[0]==S[1]&&S[1]!=S[2]&& S[2]==S[3])puts("Yes");
    else(puts("No"));

    return 0;
}

Measured memory_bytes: 3656
using System;

namespace AtCoder{
  class Program{
    static void Main(string[] args){
      int n = int.Parse(Console.ReadLine());
      string[] input = Console.ReadLine().Split(' ');
      Int64[] dp = new Int64[n];
      dp[0] = 0;
      dp[1] = Math.Abs(int.Parse(input[0]) - int.Parse(input[1]));
      for(int i = 2; i < n; i++){
        int a = int.Parse(input[i]);
        int b = int.Parse(input[i-1]);
        int c = int.Parse(input[i-2]);
        if(dp[i-1] + Math.Abs(a-b) < dp[i-2] + Math.Abs(a-c)) dp[i] = dp[i-1] + Math.Abs(a-b);
        else dp[i] = dp[i-2] + Math.Abs(a-c);
      }
      Console.WriteLine(dp[n-1]);
    }
  }
}


Measured memory_bytes: 34840
def transform(s):
    s = s[::-1]
    s = s.replace('b', '0').replace('d', 'b').replace('0', 'd')
    s = s.replace('p', '0').replace('q', 'p').replace('0', 'q')
    return s

s = input()
if s == transform(s):
    print('Yes')
else:
    print('No')   

Measured memory_bytes: 3316
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#define N 100002
using namespace std;
typedef long long LL;
LL n,a[N * 3],ans;
int main()
{
	scanf("%lld",&n);
	for (int i = 1;i <= n * 3; ++i) scanf("%lld",&a[i]);
	sort(a + 1,a + n * 3 + 1);
	ans = 0;
	for (int i = 1,j = n * 3 - 1;i <= n;++i,j -= 2)
		ans += a[j];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2560
//If you are trying to hack me I wish you can get it, Good Luck :D.
#include <bits/stdc++.h>
using namespace std;

#define debug(args...) fprintf (stderr,args)
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX = 112;
const int INF = 0x3f3f3f3f;
const ll  MOD = 1000000007;

int n, a[MAX];


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

    int cost = INF;
    for (int K = -100; K <= 100; K++) {
        int cur = 0;
        for (int j = 0; j < n; j++) {
            cur += (K - a[j]) * (K - a[j]);
        }
        cost = min(cost, cur);
    }

    cout << cost << endl;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  int a = 0, b = 0, c = 0;
  REP(i,s.length()){
    if(s[i] == 'a') a++;
    else if(s[i] == 'b') b++;
    else c++;
  }
  int n = min(a, min(b, c));
  a -= n; b -= n; c -= n;
  if(a <=1 && b<=1 && c <= 1){
    cout << "YES\n";
  }else{
    cout << "NO\n";
  }
  return 0;
}



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

int main() {
  int n;
  cin >> n;
  int a, cnt2 = 0, cnt4 = 0;
  for (int i=0; i<n; i++) {
    cin >> a;
    if (a%4 == 0)
      cnt4++;
    else if (a%2 == 0)
      cnt2++;
  }
  if (n-cnt4-cnt2 <= cnt4)
    cout << "Yes\n";
  else if (cnt2 == 0 && n-cnt4 == cnt4+1)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
    fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll N,M;
        cin>>N>>M;
        ll ar[N];
        cn(ar,N);
        map<ll,ll> ma;
        for(ll i=0;i<M;i++)
        {
            ll a,b;
            cin>>a>>b;
            if(ar[a-1]>=ar[b-1])
                ma[b]++;
            if(ar[b-1]>=ar[a-1])
                ma[a]++;
        }
        ll ans=0;
        for(ll i=1;i<=N;i++)
        {
            if(ma[i]==0)
                ans++;
        }
        cout<<ans<<endl;
    }
}

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

int main(){
  int N, K, x; 
  cin >> N >> K ;
  
  int sum=0;
  for (int i=0; i<N; i++){
    cin >> x;
    
    if((K - x) <= x)
      sum += 2 * (K - x);
    if((K - x) >  x)
      sum += 2 * x;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3556
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
String s[]=line.split("",0);
String a=sc.nextLine();
int i=Integer.parseInt(a);
for(int j=0;j<s.length;j+=i)
        System.out.print(s[j]);
    }
}

Measured memory_bytes: 22228
#include <iostream>

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

  uint32_t A, B, C;
  int64_t X, Y;
  std::cin >> A >> B >> C >> X >> Y;

  int64_t M = std::max(X, Y);
  int64_t ret = 0;

  if (C * 2 < (A + B)) {
    ret = (C * 2) * (M - std::abs(X - Y));
    
    if (X > Y) {
      if (C * 2 > A) {
        ret += A * (X - Y);
      } else {
        ret += (C * 2) * (X - Y);
      }
    } else if (Y > X) {
      if (C * 2 > B) {
        ret += B * (Y - X);
      } else {
        ret += (C * 2) * (Y - X);
      }
    }
  } else {
    ret = (A * X) + (B * Y);
  }

  std::cout << ret << std::endl;

  return 0;
}


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

int main() {
  int n, result = 0;
  cin >> n;
  int s[n];
  for (int i = 0; i < n; i++)
  {
    cin >> s[i];
  }

  sort(s, s+n);

  // for (int i = 0; i < n; i++)
  // {
  //   cout << s[i];
  // }


  for (int i = 1; i < n; i++) {
    if(s[i] == s[i-1]) result++;
  }

  cout << n - result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    long long cnt = 0;
    for (int i = 0; i < n - 1;i++){
        if(a[i]>x){
            cnt += a[i] - x;
            a[i] = x;
        }
        if(a[i]+a[i+1]>x){
            cnt += a[i + 1] - (x - a[i]);
            a[i + 1] = (x - a[i]);
        }
    }
    cout << cnt << endl;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    ll N;
    cin >> N;
    ll N_ = N;
    int L = 0;
    ll p = 1;
    while (N > 0) {
        p *= 26;
        N -= p;
        ++L;
    }
    vector<int> res(L);
    N = N_;
    p = 1;
    REP(_, L - 1) {
        p *= 26;
        N -= p;
    }
    --N;
    RREP(i, L) {
        res[i] = N % 26;
        N /= 26;
    }
    REP(i, L) {
        cout << char('a' + res[i]);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3616
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

max_first, max_second = 0, 0

max_v = -float("inf")
for p in range(1, 1 << 10):
	v = 0
	for n in range(N):
		c = 0
		for m in range(10):
			c += (p & 1 << m != 0) & (F[n][m])
		v += P[n][c]
	max_v = max(max_v, v)

print(max_v)


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;

int N;
struct Task {
public:
  Task() {

  }
  int a, b;
  void input() {
    cin >> a >> b;
  }

  bool operator < (const Task& t) const {
    if(b != t.b) return b < t.b;
    else return a < t.a;
  }

};

Task tasks[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N) {
    tasks[n].input();
  }

  sort(tasks, tasks+N);

  int pos = 0;
  REP(n,N) {
    pos += tasks[n].a;
    if(pos > tasks[n].b) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int h = ri();
	int w = ri();
	int max = ri();
	std::string s[h];
	for (auto &i : s) std::cin >> i;
	int res = 1000000000;
	for (int i = 0; i < 1 << (h - 1); i++) {
		int head = 0;
		int map[h];
		int cur_res = 0;
		for (int j = 0; j < h; j++) {
			map[j] = head;
			if (j + 1 < h && (i >> j & 1)) head++, cur_res++;
		}
		head++;
		int all[head];
		memset(all, 0, sizeof(all));
		for (int j = 0; j < w; j++) {
			int add[head];
			memset(add, 0, sizeof(add));
			for (int k = 0; k < h; k++) {
				add[map[k]] += s[k][j] == '1';
			}
			for (int k = 0; k < head; k++) if (add[k] > max) {
				cur_res = 1000000000;
				break;
			}
			bool flush = false;
			for (int k = 0; k < head; k++) if (all[k] + add[k] > max) flush = true;
			if (flush) {
				cur_res++;
				for (int k = 0; k < head; k++) all[k] = add[k];
			} else for (int k = 0; k < head; k++) all[k] += add[k];
		}
		res = std::min(res, cur_res);
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1050
#define INF 100000000
using namespace std;
int n,m,a,b,sum,mp[N][N];
inline int rd() {int r;scanf("%d",&r);return r;}
int main() {
	n = rd(), m = rd(), a = rd(), b = rd();
	int p1 = INF / (n*m), p2 = -((a*b-1)*p1 + 1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) if (i%a == 0 && j%b == 0)
			mp[i][j] = p2; else mp[i][j] = p1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			sum += mp[i][j];
	if (sum <= 0) puts("No"); else {
		puts("Yes");
		for (int i=1;i<=n;i++)
			for (int j=1;j<=m;j++) printf("%d%c",mp[i][j],j==m?'\n':' ');
	}

	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int n;
	while ( cin >> n, n ) {
		vector<int> h(n), r(n);
		for (int i = 0; i < n; ++i) {
			cin >> h[i] >> r[i];
		}
		int M; cin >> M;
		h.resize(n+M);
		r.resize(n+M);
		for (int i = 0; i < M; ++i) {
			cin >> h[n+i] >> r[n+i];
		}
		n += M;

		int m[200][200] = {0};
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (h[i] < h[j] && r[i] < r[j]) {
					m[i][j] = -1;
				}
			}
		}
		int ans = 0;
		for (int k = 0; k < n; ++k) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
			if (m[i][k] && m[k][j]) {
				m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
			}
			ans = min(ans, m[i][j]);
		}
		cout << (-ans + 1) << endl;
	}
}

Measured memory_bytes: 1376
import java.util.*;
import java.io.*;

public class Main {

    FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(System.out);
    int N = (int)5e5+5, mod = (int)1e9+7; 
    

    void solve(){
        int n = in.ni(), w = in.ni();
        int[] val = new int[n+1], wei = new int[n+1];
        long[] dp = new long[w+1];
        for(int i=1;i<=n;i++){
            wei[i] = in.ni();
            val[i] = in.ni();
        }
        for(int i=1;i<=n;i++)
            for(int j=w;j>=1;j--)
                if(j>=wei[i])
                    dp[j] = Math.max(dp[j],val[i]+dp[j-wei[i]]); 
        out.println(dp[w]);
    }



    void run(){
        solve();
        // out.flush();
        out.close();
    }
    public static void main(String[] args) {
        new Main().run();
    }
    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{   
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }  
            return str;
        }
        int nextInt(){return Integer.parseInt(in.next());}
        long nextLong(){return Long.parseLong(in.next());}
        double nextDouble(){return Double.parseDouble(in.next());}
        int ni(){return Integer.parseInt(in.next());}
        long nl(){return Long.parseLong(in.next());}
        double nd(){return Double.parseDouble(in.next());}
    }
    class Edges{
        int u,v,w;
        public Edges(int u,int v,int w){
            this.u = u;
            this.v = v;
            this.w = w;
        }
    }
    void pn(Object o){out.println(o);out.flush();}
    long inv(long a, long b){return 1<a ? b - inv(b%a,a)*b/a : 1;}//a^(-1)%b
    long fe(long a,long b){
        long ans = 1L;
        while(b>0){
            if((b&1)>0)ans=ans*a%mod;
            a = a%mod*a%mod;
            b>>=1;
        }
        // pn("ans = "+ans);
        return ans;
    }
    long gcd(long a,long b){
        if(a==0)return b;
        return gcd(b%a,a);
    }
    class pair{
        int f,s;
        public pair(int f,int s){
            this.f = f;
            this.s = s;
        }
    }
    class triple{
        int i,l,r;
        public triple(int i,int l,int r){
            this.i = i;
            this.l = l;
            this.r = r;
        }
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(void)
{
  int column;
  int row;
  int i,j;
 
  scanf("%d %d",&column,&row);
 
  int a[column][row];
  int b[row];
  int c[column];
 
  //c????????????
  for(i=0;i<column;i++){
    c[i] = 0;
  }
 
 
  //a
  for(i=0;i<column;i++){
    for(j=0;j<row;j++){
      scanf("%d",&a[i][j]);
    }
  }
 
  //b
  for(i=0;i<row;i++){
    scanf("%d",&b[i]);
  }
 
  //c
  for(i=0;i<column;i++){
    for(j=0;j<row;j++){
      c[i] += a[i][j]*b[j];
    }
    printf("%d\n",c[i]);
  }
  return 0;
}

Measured memory_bytes: 636