akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define rep(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define repr(i, n) for(int i = n;i >= 0;--i)
#define reparr(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl

int count_yakusuu(int n){
	map<int,int> primes;
	// 素因数分解
	int p=2;
	while(n!=1){
		if(n%p){
			p++;
		}else{
			n/=p;
			primes[p]++;
		}
	}
	int ans=1;
	for(P p:primes){
		ans*=(p.second+1);
	}
	return ans;
}


int main(){
	int n;
	int ans=0;
	cin>>n;
	for(int i=1;i<=n;i+=2){
		if(count_yakusuu(i)==8)ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main
{
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int K=sc.nextInt();
        sc.nextLine();
        List<Integer> list=new ArrayList<Integer>();
        for(int i=0;i<n;i++)
          list.add(sc.nextInt());
        List<Integer> dyn=new ArrayList<Integer>();
        dyn.add(0);
        dyn.add((int)(Math.abs(list.get(1)-list.get(0))));
        for(int i=2;i<n;i++)
        {
            int min=Integer.MAX_VALUE;
            for(int j=1;j<=K;j++)
              {
                  if(i-j>=0)
                   {
                          min=(int)Math.min(min,Math.abs(list.get(i)-list.get(i-j))+dyn.get(i-j));
                   }
                   if(i-j<0)
                    break;
              }
            dyn.add(min);
        }
        System.out.println(dyn.get(n-1));
        sc.close();
    }
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double n,m,a=0,cnt=0;;
	cin>>n>>m;
	vector<double>v(n);
	for(ll i=0;i<n;i++) {
		cin>>v.at(i);
		a+=v.at(i);
	}
	for(ll i=0;i<n;i++){
		if(v.at(i)>=a/(4*m)){
			cnt++;
		}
	}
	if(cnt>=m){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
/*****Enigma_27*****/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<ll,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,k,l,t=1,ans=0,m,flag=0;
vll v;
int main()
{   ios
    cin>>n>>m;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            v.pb(i*m+j*n-(2LL*(i*j)));
        }
    }
    sort(all(v));
    cin>>k;
    if(bs(all(v),k)) cout<<"Yes\n";
    else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 10476
n,m = map(int,input().split())
info = [[] for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    info[a].append(b)
    info[b].append(a)

import collections

seen = [-1]*(n+1)
todo = collections.deque()

for i in info[1]:
    todo.append(i)
    seen[i] = 1

while len(todo) != 0:
    now = todo.popleft()
    for i in info[now]:
        if seen[i] == -1:
            todo.append(i)
            seen[i] = now

seen = seen[2:]
if -1 in seen:
    print("No")
else:
    print("Yes")
    for i in seen:
        print(i)
    

Measured memory_bytes: 96088
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

#define lset(h, n) memset(h, n, sizeof(h));
    

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    int n;
    cin >> n;
    int b[n];
    rep(i,n-1){
        cin >> b[i];
    }
    int ans = 0;
    int kari = b[0];
    rep1(i,n-1){
        if(kari > b[i]){
            kari = b[i];
        }
        ans+= kari;
        kari = b[i];
    }
    ans = ans + b[0] + b[n-2];
    pri(ans);
}











Measured memory_bytes: 256
N, K, Q = [int(n) for n in input().split()]
c = {}
ans = [K]*N
for i in range(Q):
    a = int(input())
    if a not in c:
        c.setdefault(a, 1)
    else:
        c[a] += 1
for j in range(N):
    print('Yes' if ans[j] - (Q-c.get(j+1, 0)) > 0 else 'No')

Measured memory_bytes: 9824
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		HashMap<Long, Integer> map = new HashMap<Long, Integer>();
		long ans = 0;
		for (int i = 0; i < (Math.pow(2, S.length() - 1)); i++) {
			int pre = 0;
			long num = 0;
			for (int j = 0; j < S.length() - 1; j++) {
				if ((1&i>>j) == 1) {
					num += Long.parseLong(S.substring(pre, j + 1));
					pre = j + 1;
				}
			}
			num += Long.parseLong(S.substring(pre, S.length()));
			ans += num;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int a[3];

bool allsame() {
    bool ret = true;
    rep(i,2) if (a[i] != a[i+1]) ret = false;
    return ret;
}

int main() {
    rep(i,3) cin >> a[i];
    int ans = 0;
    while (!allsame()) {
        sort(a, a+3);
        a[0]++;
        sort(a, a+3);
        a[0]++;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
void call(int n, int c){
  static int i, x;
  bool end = false;
 
  if(c != 2){
    if(!c) i = 1;
    x = i;
    if(x % 3 == 0){
      cout << " " << i;
      end = true;
    }
  }
  if(x % 10 == 3 && !end){
    cout << " " << i;
    end = true;
  }
  if(!end){
    x /= 10;
    if(x){ 
      call(n, 2); 
    }
  }
 
  if(++i <= n){ 
    call(n, 1); 
  }
}
 
int main(){
  int n;
  cin >> n; call(n, 0);
  cout << endl;
 
  return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    int r, c, k;
    cin >> r >> c >> k;


    vector<string> g(r);
    for(int i = 0; i < r; i++) cin >> g[i];

    int cnt = 0;

    for(int i = 0; i < (1 << r); i++) {
        for(int j = 0; j < (1 << c); j++) {
            vector<string> cpy = g;
            for(int row = 0; row < r; row++) {
                if((i & (1 << row))) {
                    for(int k = 0; k < c; k++) {
                        cpy[row][k] = 'R';
                    }
                }
            }
            for(int col = 0; col < c; col++) {
                if((j & (1 << col))) {
                    for(int k = 0; k < r; k++) {
                        cpy[k][col] = 'R';
                    }
                }
            }
            int count = 0;
            for(int k = 0; k < r; k++) {
                for(int x = 0; x < c; x++) {
                    if(cpy[k][x] == '#') count++;
                }
            }
            if(count == k) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A[i] -= (i + 1);
	}
	sort(A.begin(), A.end());
	int b = A[N / 2];
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		ans += abs(A[i] - b);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    vector<lint> c(m+1, LINF);
    FOR(i, 1, m+1){
        cin >> c[i];
    }
    lint dp[m+1][n+1]; // i 枚目のコインで j 円支払う
    REP(i, m+1){
        REP(j, n+1){
            dp[i][j] = (i == 0 && j == 0) ? 0 : INF;
        }
    }
    FOR(i, 1, m+1){
        FOR(j, 0, n+1){
            if(j - c[i] >= 0){
                dp[i][j] = min(dp[i-1][j], min(dp[i-1][j - c[i]] + 1, dp[i][j-c[i]] + 1));
            }
            else {
                dp[i][j] = dp[i-1][j];
            }
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    cout << dp[m][n] << endl;
    return 0;
}


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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<Int> fact(Int x) {
    vector<Int> ans;
    for(Int i = 2;i*i <= x;i++) {
        if(x % i == 0) {
            ans.push_back(i);
            if(i*i != x) {
                ans.push_back(x/i);
            }
        }
    }

    return ans;
}

int main(void) {
    Int X;
    cin>>X;

    if(X == 1) {
        cout<<1<<" "<<0<<endl;

        return 0;
    }

    for(Int i = -120;i < 120;i++) {
        for(Int j = -120;j < 120;j++) {
            if(pow(i,5)-pow(j,5) == X) {
                cout<<i<<" "<<j<<endl;

                return 0;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3592
import math
A ,B, H, M = map(int, input().split())

a = 360 * (H * 60 + M) / (12 * 60)
b = 360 * M / 60

f = lambda a, b, c: math.sqrt(a ** 2 + b ** 2 -2 * a * b * math.cos(math.radians(c)))

print(f(A, B, min(abs(a - b), 360 - abs(a - b))))

Measured memory_bytes: 9516
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	 int a,b,c;
	 cin>>a>>b>>c;
	 if((b/a)>c){
		 cout<<c<<endl;
	 }else {
		 cout<<b/a<<endl;
	 }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>

using namespace std;

inline int ctoi(const char c)
{
	return c >= '0'&&c <= '9' ? c - '0' : -1;
}

int main()
{
	int a, b;
	cin >> a >> b;
	
	int tower_height = 0;
	for (int i = 1; i <= 999; i++) {
		tower_height += i;
		if (i == (b - a)) {
			cout << tower_height - b << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 1003
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int n,t,m[M],l[M],k[M],add[M];
bool used[M];
bool ch(int x){
  memset(add,0,sizeof(add));
  memset(used,0,sizeof(used));
  int cnt=0;
  r(i,t+1){
    x+=add[i];
    r(j,n)if(!used[j]&&x){
      int p=l[j]+k[j];
      if((i%p<=l[j])&&m[j]+i<=t){
        add[i+m[j]]++;
	used[j]=1;
	x--;
	cnt++;
      }
    }
  }
  return cnt==n;
}
int main(){
  while(cin>>n>>t,t){
    r(i,n)cin>>m[i]>>l[i]>>k[i];
    r(i,M){
      if(ch(i)){
	cout<<i<<endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 3024
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	h,w=map(int,input().split())
	A=[list(map(int,input().split())) for _ in range(h)]
	B=[list(map(int,input().split())) for _ in range(h)]
	C=[[0]*w for _ in range(h)]
	for i in range(h):
		for j in range(w):
			C[i][j]=abs(A[i][j]-B[i][j])
	D=[[0]*w for _ in range(h)]
	D[0][0]=(1<<C[0][0]+5000)|(1>>C[0][0]+5000)
	for i in range(h):
		for j in range(w):
			if i>0:
				D[i][j]=D[i][j]|(D[i-1][j]<<C[i][j])|(D[i-1][j]>>C[i][j])
			if j>0:
				D[i][j] = D[i][j]|(D[i][j-1] << C[i][j]) | (D[i][j-1] >> C[i][j])

	val=D[-1][-1]
	ans=5000

	for i in range(10000):
		if val>>i&1:
			ans=min(ans,abs(i-5000))
	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 51932
# AGC002C - Knot Puzzle
def main():
    N, L, *A = map(int, open(0).read().split())
    B = [i + j for i, j in zip(A, A[1:])]
    x = max(B)
    if x < L:  # corner case
        print("Impossible")
        return
    idx = B.index(x) + 1
    # keep the biggest one until the end
    ans = [i for i in range(1, idx)] + [i for i in range(N - 1, idx, -1)] + [idx]
    print("Possible")
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	int n; cin >> n;
	vi a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];
	sort(all(a)); sort(all(b)); sort(all(c));
	ll ans = 0;
	rep(i,n){
		int eval = b[i];
		ll a_pos = lower_bound(all(a), eval) - a.begin();
		ll c_pos = c.end() - upper_bound(all(c), eval);
		ans += a_pos * c_pos;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
<?php
fscanf(STDIN, "%d", $n);
$d = explode(' ', fgets(STDIN));
$count = 0;
for($i=0; $i<$n; $i++){
	for($j=$i+1; $j<$n; $j++){
		$count += $d[$i]*$d[$j];
	}
}
echo $count;

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int l[15],r[15],c[15],cc[15],tot;
char s[15][1005];
int n,m,k;
int cal(int st,int ed,int j){//st-ed行第j列
    int ans=0;
    for(int i=st;i<=ed;i++){
        if(s[i][j]=='1')ans++;
    }
    return ans;
}
int check(){
    for(int i=1;i<=tot;i++)c[i]=cc[i]=0;
    int ans=0;
    for(int j=1;j<=m;j++){//列
        int ok=1;
        for(int e=1;e<=tot;e++){
            cc[e]=cal(l[e],r[e],j);
            if(cc[e]>k)return -1;//无解
            if(c[e]+cc[e]>k){
                ok=0;
            }
        }
        if(ok){
            for(int e=1;e<=tot;e++)c[e]+=cc[e];
        }else{
            ans++;
            for(int e=1;e<=tot;e++)c[e]=cc[e];
        }
    }
    return ans;
}
signed main(){
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        scanf("%s",s[i]+1);
    }
    int ans=1e9;
    for(int i=0;i<(1<<(n-1));i++){
        int temp=0;
        for(int j=0;j<(n-1);j++)if(i>>j&1)temp++;
        tot=0;
        int last=1;
        for(int j=0;j<(n-1);j++){
            if(i>>j&1)tot++,l[tot]=last,r[tot]=j+1,last=j+2;
        }
        if(last<=n)tot++,l[tot]=last,r[tot]=n;
        int t=check();
        if(t==-1)continue;
        else temp+=t;
        ans=min(ans,temp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.*;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Deque a = new Deque();
        
        int n = Integer.parseInt(br.readLine());
        
        String l;
        char query, d;
        int p;
        long x;
        for (int i = 0; i < n; i++) {
            l = br.readLine();
            query = l.charAt(0);
            switch (query) {
                case '0':
                    d = l.charAt(2);
                    x = Long.valueOf(l.substring(4));
                    if (d == '0') {
                        a.addFirst(x);
                    } else {
                        a.addLast(x);
                    }
                    break;
                case '1':
                    p = Integer.parseInt(l.substring(2));
                    System.out.println(a.getElementAt(p));
                    break;
                case '2':
                    d = l.charAt(2);
                    if (d == '0') {
                        a.removeFirst();
                    } else {
                        a.removeLast();
                    }
                    break;
            }
        }
    }
}

class Deque {
    int l = 499999, r = 500000;
    long[] a;
    
    Deque() {
        a = new long[1000000];
    }
    
    void addFirst(long x) {
        a[l] = x;
        l--;
    }
    void addLast(long x) {
        a[r] = x;
        r++;
    }
    long getElementAt(int index) {
        return a[index + l + 1];
    }
    void removeFirst() {
        l++;
    }
    void removeLast() {
        r--;
    }
}
    



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

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  bool isAllEven = true;
  for(int i=0;i<N;i++){
    if(A[i] % 2 != 0){
      isAllEven = false;
    }
  }
  int counter = 0;
  while(isAllEven){
    counter ++;
    for(int i=0;i<N;i++){
      A[i] = A[i]/2;
    }
    for(int i=0;i<N;i++){
      if(A[i] % 2 != 0){
        isAllEven = false;
      }
    }
  }
  cout << counter;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, wm);
    ll w0;
    vector<vector<int>> b(4);
    For(i, n){
        Cin(int, w, v);
        if(i == 0) w0 = w;
        b[w - w0].push_back(v);
    }
    For(i, 4){
        auto &bi = b[i];
        DeSort(bi);
        bi.insert(bi.begin(), 0);
        for(int j = 1; j < (int)bi.size(); j ++) bi[j] += bi[j-1];
    }
    ll ans = 0;
    For(i0, (int)b[0].size()) For(i1, (int)b[1].size()) For(i2, (int)b[2].size()) For(i3, (int)b[3].size()){
        if((w0+0)*i0 + (w0+1)*i1 + (w0+2)*i2 + (w0+3)*i3 <= wm) ans = max(ans, (ll)b[0][i0] + b[1][i1] + b[2][i2] + b[3][i3]);
    }
    Cout(ans);
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
typedef pair<int, int> P; typedef long long int ll; typedef vector <int> vecint; typedef vector <vecint> dvecint; typedef vector <dvecint> vecdvecint; typedef vector <vector <dvecint> > dvecdvecint;
const int INF = 100000000;
struct edge {
	int to, cap, rev;
};
int level[202]; vector <edge> G[202];
vecint to[102];
void addedge(int from, int to, int cap) {
	edge e1 = { to, cap, G[to].size() };
	edge e2 = { from, 0, G[from].size()};
	G[from].push_back(e1);
	G[to].push_back(e2);
}
void bfs(int s) {
	fill(level, level + 202, -1);
	queue<int> q;
	q.push(s);
	level[s] = 0;
	while (!q.empty()) {
		int f = q.front(); q.pop();
		for (int i = 0; i < G[f].size(); i++) {
			edge e = G[f][i];
			if (level[e.to] < 0 && e.cap > 0) {
				level[e.to] = level[f] + 1;
				q.push(e.to);
			}
		}
	}
}
int dfs(int s, int t, int f) {
	if (s == t) return f;
	for (int i = 0; i < G[s].size(); i++) {
		edge &e = G[s][i];
		if (level[e.to] > level[s] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
int main() {
	int nx, ny, ne;
	cin >> nx >> ny >> ne;
	for (int i = 0; i < ne; i++) {
		int x, y; cin >> x >> y;
		to[x + 1].push_back(y + nx + 1);
	}
	for (int i = 1; i <= nx; i++)
		for (int j = 0; j < to[i].size(); j++)
			addedge(i, to[i][j], 1);
	int t = 1 + nx + ny;
	for (int i = 1; i <= nx; i++)
		addedge(0, i, 1);
	for (int i = nx + 1; i <= nx + ny; i++)
		addedge(i, t, 1);
	int flow = 0;
	while (true) {
		bfs(0);
		if (level[t] < 0) break;
		int f;
		while ((f = dfs(0, t, INF)) > 0) {
			flow += f;
		}
	}
	cout << flow << endl;
	return 0;
}

Measured memory_bytes: 3296
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

#include<bits/stdc++.h>
using namespace std;

#define f(i,k,n) for(i=k;i<n;i++)
#define fd(i,k,n) for(i=k;i>n;i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define gi greater<int>
#define rev reverse
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define imp cout << "IMPOSSIBLE" << endl;
#define nl cout << endl
#define hello cout << "hello" << endl;
#define sp(x) fixed << setprecision(x)
#define re return

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s) 
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n) 
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}
void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LONG_MIN,minl = LONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int k,n;
	R(n,k);
	vi a(n);
	rv(a);
	sort(all(a));
	for(i=0;i<k;i++)
		sum += a[i];
	W(sum);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define N 100002
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;

int main(){
  ll w,h;
  cin>>w>>h;
  vector <PP> path;

  ll p[N],q[N];
  for(int i=0;i<w;i++) cin>>p[i],path.push_back(PP(P(p[i],i+1),0));
  for(int i=0;i<h;i++) cin>>q[i],path.push_back(PP(P(q[i],i+1),1));
  sort(path.begin(),path.end());
  
  ll sum=0,cnt[2]={},wh[]={w+1,h+1};
  for(int i=0;i<path.size();i++){
    ll cost=path[i].first.first;
    ll k=path[i].first.second;
    ll f=path[i].second;
    cnt[f]++;
    sum+=cost*(wh[!f]-cnt[!f]);
  }
  cout <<sum<<endl;  

  return 0;
}


Measured memory_bytes: 7536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(),K = in();
    vector<int> h(N);
    REP(i,N)h[i] = in();
    sort(ALL(h));
    int minimum = mod;
    REP(i,N-K+1){
        minimum = min(minimum,h[i+K-1]-h[i]);
    }
    cout << minimum << "\n";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,X,Y; cin>>N>>X>>Y; X--; Y--;
	vector<int> ret(N-1);
	for (int i=0; i<N-1; i++)
		for (int j=i+1; j<N; j++)
			ret[min({j-i,abs(X-i)+1+abs(Y-j),abs(Y-i)+1+abs(X-j)})-1]++;
	for (int i=0; i<N-1; i++)
		cout<<ret[i]<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cassert>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

const double g=10.0,eps=1e-4;
const int N=200000+10,maxn=500+100,inf=0x3f3f3f;

vector<int>v[N],p;
bool vis[N];
int pre[N],n,res;
int color[N];
void bfs(int x)
{
    memset(vis,0,sizeof vis);
    memset(pre,-1,sizeof pre);
    queue<int>q;
    q.push(x);
    vis[x]=1;
    while(!q.empty()){
        int s=q.front();
        q.pop();
        for(int i=0;i<v[s].size();i++)
        {
            if(!vis[v[s][i]])
            {
                vis[v[s][i]]=1;
                pre[v[s][i]]=s;
                q.push(v[s][i]);
                if(v[s][i]==n)return ;
            }
        }
    }
}
int bfs1(int x)
{
    memset(vis,0,sizeof vis);
    queue<int>q;
    q.push(x);
    vis[1]=1;
    int ans=0;
    while(!q.empty()){
        int s=q.front();
     //   cout<<s<<endl;
        ans++;
        q.pop();
        for(int i=0;i<v[s].size();i++)
        {
            if(color[v[s][i]]==2||vis[v[s][i]])continue;
            q.push(v[s][i]);
            vis[v[s][i]]=1;
        }
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    bfs(1);
    int ans=0;
    for(int i=pre[n];i!=1;i=pre[i])ans++;
    ans/=2;
    memset(color,0,sizeof color);
    color[1]=1,color[n]=2;
    for(int i=pre[n];i!=1;i=pre[i])
    {
        if(ans>0)ans--,color[i]=2;
        else color[i]=1;
    }
  //  for(int i=1;i<=n;i++)cout<<color[i]<<endl;
    int res=bfs1(1);
    if(res>n-res)cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
    return 0;
}

Measured memory_bytes: 9984
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
//#include <immintrin.h>
//#include <emmintrin.h>

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=998244353;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}

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

void Solve(){
  int n;
  cin>>n;
  n%=1000;
  cout<<(1000-n)%1000<<endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long 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;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int n;
	cin >> n;
	hei(llint) a(n);
	llint sum = 0;
	rep(i, 0, n) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	int ans = 1;
	sum -= a[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		if (sum * 2 < a[i + 1])break;
		sum -= a[i];
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
dlist = sorted(list(map(int, input().split())))

st = dlist[N//2 -1]
ed = dlist[N//2]
if st == ed:
    print(0)
    exit()
cnt = 0
for i in range(st+1, ed+1):
    cnt = cnt + 1

print(cnt)

Measured memory_bytes: 14556
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c, d, e, f = map(int, readline().split())
A = 100 * a
B = 100 * b
E = 100 * e / (100 + e)
ans = [0, 0]
check = 0
for i in range(f // A + 2):
    for j in range(f // B + 2):
        w = A * i + B * j
        for k in range(int((w * E / 100) // c) + 2):
            for l in range(int((w * E / 100) // d) + 2):
                if k == 0 and l == 0:
                    continue
                s = c * k + d * l
                n = 100 * s / (w + s)
                if w + s > f or n > E:
                    break
                if n > check:
                    ans = w + s, s
                    check = n
if ans[0] == 0:
    print(100 * a, ans[1])
else:
    print(*ans)


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

int main(void){
    int n;
    cin >> n;
    vector<int> arr = vector<int>(n + 1);

    for(int i = 1; i <= n; i++) cin >> arr[i];


    vector<int> xors = vector<int>(n + 1, 0);
    vector<int> sum = vector<int>(n + 1, 0);

    for(int i = 1; i <= n; i++){
        sum[i] = sum[i - 1] + arr[i];
        xors[i] = xors[i - 1] ^ arr[i];
    }

    long long result = 0;
    int j = 1;
    for(int i = 1; i <= n; i++){
        while((sum[i] - sum[j - 1]) != (xors[i] ^ xors[j - 1])) j++;

        //cout << i << "::" << j << endl;
        int q = i - j + 1;
        result += q;
        //j = last_success;
    }

    /*
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 21; j++){
            cout << cnt[i][j] << ' ';
        }
        cout << endl;
    }
    */

    cout << result << endl;
}



Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int MOD=1e9+7;
  long long ans=1,n,cnt[1005];
int main() {
  int i,j,k;
  cin >> n;
  for(i=2; i<=n; i++) {
    for(j=i,k=2; j>1;) {
      if(j%k==0) {
        j/=k,cnt[k]++;
      }
      else {
        k++;
      }
    }
  }
  for(i=2; i<=n; i++) {
    ans=ans*(cnt[i]+1)%MOD;
  }
  cout << ans << endl;
}

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

int main(void){
    int N;
    cin >> N;
    string S;
    cin >> S;
    if(N % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i < N/2; i++){
        if(S[i] != S[N/2+i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

signed main(){
  int x,y,a,b,c;cin>>x>>y>>a>>b>>c;
  vector<int> r(a),g(b),w(c);
  for(int i=0;i<a;i++)cin>>r[i];
  for(int i=0;i<b;i++)cin>>g[i];
  for(int i=0;i<c;i++)cin>>w[i];
  sort(r.rbegin(),r.rend());
  sort(g.rbegin(),g.rend());
  for(int i=0;i<x;i++)w.push_back(r[i]);
  for(int i=0;i<y;i++)w.push_back(g[i]);
  sort(w.rbegin(),w.rend());
  long long ans=0;
  for(int i=0;i<x+y;i++)ans+=w[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 2552
package main

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

func main() {
        var n int
        fmt.Scan(&n)
        sc := bufio.NewScanner(os.Stdin)
        var s string
        if sc.Scan() {
                s = sc.Text()
        }
        var count int
        for _, v := range strings.Split(s, " ") {
                t, _ := strconv.Atoi(v)
                if t%2 == 0 {
                        if t%3 == 0 || t%5 == 0 {
                                count++
                        } else {
                                fmt.Println("DENIED")
                                return
                        }
                }
        }
        fmt.Println("APPROVED")
}


Measured memory_bytes: 640
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = getLine >> getLine >>= main'
    where
        main' s = readLn >>= putStrLn . solve s

solve :: String -> Int -> String
solve s k = map mf s
    where
        c = s !! (k - 1)
        mf x
            | x == c = x
            | otherwise = '*'

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 508
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	p := strings.Split(scanner.Text(), " ")
	N, _ := strconv.Atoi(p[0])
	T, _ := strconv.Atoi(p[1])

	ret := 1001
	for i := 0; i < N; i++ {
		scanner.Scan()
		p = strings.Split(scanner.Text(), " ")
		c, _ := strconv.Atoi(p[0])
		t, _ := strconv.Atoi(p[1])
		if t <= T && c < ret {
			ret = c
		}
	}
	if ret == 1001 {
		fmt.Println("TLE")
	} else {
		fmt.Println(ret)
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

struct counter{ll d; ll m; ll dm;};

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int Q;
    cin >> Q;

    for(int i=0; i<Q; i++){
        ll ans=0;
        counter cnt={0,0,0};
        int k;
        cin >> k;
        for(int j=0; j<N; j++){
            if(j>=k){
                if(S[j-k]=='D'){
                    cnt.d--;
                    cnt.dm-=cnt.m;
                }else if(S[j-k]=='M'){
                    cnt.m--;
                }
            }

            if(S[j]=='D'){
                cnt.d++;
            }else if(S[j]=='M'){
                cnt.m++;
                cnt.dm+=cnt.d;
            }else if(S[j]=='C'){
                ans+=cnt.dm;
            }
        }

        cout << ans << endl;
    }
}

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

int main()
{
  string s;
  cin>>s;
  map<char,int> mp;
  for(int i=0;i<s.length();i++)
     mp[s[i]]++;
  for(auto t=mp.begin();t!=mp.end();t++)
  {
    if(t->second%2!=0){
      cout<<"No";
     return 0;
    }
  }
  cout<<"Yes";
  return 0;
}
    
    

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

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int H, W, N, sr, sc, i, j;
	scanf("%d%d%d", &H, &W, &N);
	scanf("%d%d", &sr, &sc);
	char *S = (char *)malloc(sizeof(char) * (N + 1));
	scanf("%s", S);
	char *T = (char *)malloc(sizeof(char) * (N + 1));
	scanf("%s", T);
	int now, mU = 0;
	for(i = 0, now = 0; i < N; i++){
		if(S[i] == 'U'){
			now++;
		}
		mU = max(mU, now);
		if(T[i] == 'D' && now > sr - H){
			now--;
		}
		mU = max(mU, now);
	}
	if(mU >= sr){
		printf("NO\n");
		return 0;
	}
	mU = 0;
	for(i = 0, now = 0; i < N; i++){
		if(S[i] == 'D'){
			now++;
		}
		mU = max(mU, now);
		if(T[i] == 'U' && now > -sr + 1){
			now--;
		}
		mU = max(mU, now);
	}
	if(mU > H - sr){
		printf("NO\n");
		return 0;
	}
	mU = 0;
	for(i = 0, now = 0; i < N; i++){
		if(S[i] == 'L'){
			now++;
		}
		mU = max(mU, now);
		if(T[i] == 'R' && now > sc - W){
			now--;
		}
		mU = max(mU, now);
	}
	if(mU >= sc){
		printf("NO\n");
		return 0;
	}
	mU = 0;
	for(i = 0, now = 0; i < N; i++){
		if(S[i] == 'R'){
			now++;
		}
		mU = max(mU, now);
		if(T[i] == 'L' && now > -sc + 1){
			now--;
		}
		mU = max(mU, now);
	}
	if(mU > W - sc){
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 512
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    A_list = list(sorted([(int(input()), i) for i in range(N)]))
    a_list = [i for a, i in A_list]
    ans = 0
    for i, a in enumerate(a_list):
        ans += (i % 2 != a % 2)
    print(ceil(ans, 2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 18108
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long A, long long B) { cout << A * B << endl; }

signed main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3728
#include<stdio.h>
#include<string.h>

int main(void){
  char s[11] , t[11];
  scanf("%s  %s",s , t);
  
  int n = strlen(s) , flag = 0;
  
  for(int i = 0;i < n;i ++){
    if(s[i] != t[i]){
      flag = 1;
    }
  }
  
  if(flag == 0){
    printf("Yes\n");
  }
  else{
     printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 1660