akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  constexpr ll mod = 1e9 + 7;
  int n, x; cin >> n >> x;
  vector<int> s(n);
  REP(i, n) cin >> s[i];

  sort(s.begin(), s.end(), greater<int>());

  auto dp = make_v(n+1, x+1, -1LL);
  function<ll(int, int)> rec = [&](int i, int j){
    if(i == n) return 1LL * j;

    if(dp[i][j] != -1) return dp[i][j];

    ll ret = 0LL;
    (ret += (n - i - 1) * rec(i+1, j)) %= mod;
    (ret += rec(i+1, j % s[i])) %= mod;
    
    return dp[i][j] = ret;
  };

  cout << rec(0, x) << endl;

  return 0;
}


Measured memory_bytes: 158592
'use strict'

const main = input => {
	const s = input.trim().split('\n')[1].split(' ')
	let cnt = 0

	for (let i = 0; i < s.length; i++) {
		if (s[i] === 'Y') cnt++
	}

	if (cnt > 0) console.log('Four')
	else console.log('Three')
}

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


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

using namespace std;
#define ll long long

ll INF = 1e18;

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

    int n;
    cin>>n;

    double ans = (double ((n+1)/2))/n;

    cout<<std::setprecision(15)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

long long dic_op(char str[][14])
{
   int j;
   long long f = 1;
   long long g = 0;
   for(j = 0;;j++) {
      if(str[1][j] == 'A')
         g += f * 1;
      else if(str[1][j] == 'C')
         g += f * 2;
      else if(str[1][j] == 'G')
         g += f * 3;
      else if(str[1][j] == 'T')
         g += f * 4;
      else break;
      f *= 5;
   }
   return g; 
}

int main()
{
   static long i,j,k,l;
   long n;
   long cnt = 0;
   int f,g;
   long left,right,mid;
   long ans = 0;
   static char e[1000000];
   static char dic[300000000];
   char str[2][14];
   cin >> n;
   for (i = 0; i < n; i++) {
      cin >> str[0] >> str[1];
      if(str[0][0] == 'i') {
         dic[dic_op(str)] = 1;
      }
      else if(str[0][0] == 'f') {
         if(dic[dic_op(str)] == 1)
            e[j] = 1;
         else 
            e[j] = 0;
         j++;
      }
   }
   for (i = 0; i < j; i++) {
      if(e[i] == 1)
         cout << "yes" << endl;
      else
         cout << "no" << endl;
   }
   return 0;
}

Measured memory_bytes: 11072
/*
ID: zhaowei10
TASK:
LANG: C++
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define pb push_back
#define MOD 1000000007
#define NDIG(x) floor(log10(x)) + 1
#define FOR(i, j, k, l) for (s32 i = j; i < k; i += l)
#define RFOR(i, j, k, l) for (s32 i = j; i >= k; i -= l)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(x) x.begin(), x.end()
#define MEAN(a, b) min(a, b) + (abs(b - a) >> 1)
#define FASTIO()    \
  cin.tie(nullptr); \
  ios::sync_with_stdio(false);

typedef long long ll;
typedef int64_t s64;
typedef uint64_t u64;
typedef int32_t s32;
typedef uint32_t u32;
typedef float f32;
typedef double f64;
typedef pair<s32, s32> II;
typedef pair<s64, s64> LL;
typedef vector<s32> VI;
typedef vector<II> VII;
typedef vector<char> VC;
typedef vector<VII> VVII;
typedef priority_queue<s32> PQI;
typedef priority_queue<s32, VI, greater<s32>> PQIA;
typedef priority_queue<s64> PQL;
typedef priority_queue<II> PQII;
typedef priority_queue<II, VII, greater<II>> PQIIA;
typedef priority_queue<LL> PQLL;
typedef unordered_set<s32> USI;
typedef unordered_set<s64> USL;
typedef set<II> SII;
typedef multiset<s32> MSI;

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

template <typename T>
inline s32 ndigits(T x, T b) {
  s32 r = 0;
  while (x) {
    x /= b;
    ++r;
  }
  return r;
}

int main() {
  FASTIO();

  int a, b;
  cin >> a >> b;
  int smaller = a < b ? a : b;
  int larger = a > b ? a : b;
  for (int i = 0; i < larger; ++i) {
    cout << smaller;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<queue>
#include<cstdio>
#include<cmath>
#include<sstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<ctime>
#include<cstdlib>
#include<map>
#include<utility>

#include<iomanip>
#include<set>
#include<stack>
#define lowbit(i) ((i)&(-i))
using namespace std;
typedef long long ll;typedef pair<int,int> pii;
typedef pair<ll,ll> pll;typedef vector<string> vss;
typedef vector<int> vii;typedef vector<pii> vpi;
typedef vector<ll> vll;typedef vector<pll> vpl;typedef long double ld;
typedef unsigned long long ul;typedef queue<int> qii;typedef queue<pii> qpi;
int x,y,p=1;
int main()
{
// 	freopen("","r",stdin);
// 	freopen("","w",stdout);
	cin>>x>>y;
	if(x%y==0){
		puts("-1");
		return 0;
	}
	while(true){
		++p;
		if(p*x%y!=0) {cout<<p*x<<'\n';break;}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=555555;
int n,m,ans[N],at[3];
int L[N],R[N],nL[N],nR[N];
int tmp[N],a[N];
char s[N];
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	m=strlen(s+1);
	ans[0]=0; ans[1]=1; ans[2]=2;
	L[0]=ans[0]; R[0]=ans[2];
	For(i,1,m){
		if (s[i]=='R'){
			int t=ans[2]; ans[2]=ans[1];
			ans[1]=ans[0]; ans[0]=t;
		}
		else swap(ans[1],ans[2]);
		L[i]=ans[0]; R[i]=ans[2];
	}
	int l=3;
	//For(i,0,2) cout<<ans[i]<<' '; cout<<endl;
	For(i,2,n){
		For(j,0,2) For(k,0,l-1) a[j*l+k]=j*l+k;
		For(j,0,2) at[j]=j;
		nL[0]=0; nR[0]=l*3-1;
		For(j,1,m){
			//cout<<R[j-1]<<' '<<L[j]<<endl;
			if (s[j]=='S') swap(at[1],at[2]);
			else{
				int v[3];
				For(k,0,2) v[k]=a[at[k]*l+R[j-1]];
				//For(k,0,2) cout<<v[k]<<' '; cout<<endl;
				For(k,0,2) a[at[k]*l+L[j]]=v[(k+2)%3];
			}
			nL[j]=a[at[0]*l+L[j]];
			nR[j]=a[at[2]*l+R[j]];
			//cout<<nL[j]<<' '<<nR[j]<<endl;
		}
		//For(j,0,2) cout<<a[j]<<endl;
		For(j,0,2) For(k,0,l-1) tmp[j*l+k]=a[at[j]*l+ans[k]];
		For(j,0,3*l-1) ans[j]=tmp[j];
		For(j,0,m) L[j]=nL[j],R[j]=nR[j];
		l*=3;
	}
	For(j,0,l-1) a[ans[j]]=j;
	For(j,0,l-1) printf("%d ",a[j]);
}
/*
2 SRSRR
*/
/*
0 1 2 3 4 5 6 7 8
0 2 1 6 8 7 3 5 4
4 0 2 1 6 8 7 3 5
4 2 0 7 5 3 1 8 6
*/

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

int main() {
  int N, M, from, to;
  vector<int> cities(N, 0);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> from >> to;
    cities.at(from-1) += 1;
    cities.at(to-1) += 1;
  }
  for (int i = 0; i < N; i++) {
    cout << cities.at(i) << endl;
  }
}


Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
typedef vector<ll> vl;
#define PB push_back
#define ios() ios::sync_with_stdio(false); cin.tie(0);
#define scan(a,n) for(ll i=0;i<n;i++)	cin>>a[i];
#define print(a,n) for(ll i=0;i<n;i++)	cout<<a[i]<<"\n";
#define test() ll t; cin>>t; while(t--) 
#define endl "\n"


int main()
{
	ios()
	ll n;
	cin>>n;
	float sum=0;
	ll ar[n+1];
	scan(ar,n)
	//cout<<n;
	REP(i,n)
	{
		sum+=(1.0/ar[i]);
	}
	sum=1/sum;
	printf("%.5f\n",sum);
	//cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

char a[2001];
char b[2001];
int l[2000];
int r[2000];

int calc(vector<pair<int, int> > &v) {
    int ans = 1e9, m = 0, i;
    
    if (v.size() == 0) return 0;
    
    for (i = 0; i < v.size(); i++) {
        ans = min(ans, v[i].first + m);
        m = max(m, v[i].second);
    }
    
    ans = min(ans, m);
    
    return ans * 2;
}

int main() {
    int n, ans = 1e9, i, j;
    
    scanf("%s", a);
    scanf("%s", b);
    
    n = strlen(a);
    
    for (i = 0; i < n; i++) {
        if (b[i] == '1') break;
    }
    
    if (i == n) {
        int ans = 0;
        
        for (i = 0; i < n; i++) {
            if (a[i] == '1') ans = -1;
        }
        
        printf("%d\n", ans);
        
        return 0;
    }
    
    for (i = 1; i < n; i++) {
        if (b[i] == '1') {
            l[i] = 0;
        } else {
            l[i] = l[i - 1] + 1;
        }
    }
    
    if (b[0] == '0') {
        l[0] = l[n - 1] + 1;
        
        for (i = 1; i < n; i++) {
            if (b[i] == '1') break;
            
            l[i] = l[i - 1] + 1;
        }
    }
    
    for (i = n - 2; i >= 0; i--) {
        if (b[i] == '1') {
            r[i] = 0;
        } else {
            r[i] = r[i + 1] + 1;
        }
    }
    
    if (b[n - 1] == '0') {
        r[n - 1] = r[0] + 1;
        
        for (i = n - 2; i >= 0; i--) {
            if (b[i] == '1') break;
            
            r[i] = r[i + 1] + 1;
        }
    }
    
    for (i = 0; i < n; i++) {
        int c = i;
        vector <pair<int, int> > v;
        
        for (j = 0; j < n; j++) {
            int x = (j + i) % n;
            
            if (b[j] != a[x]) {
                c++;
                
                if (b[j] == '0' && l[x] > i) v.push_back(make_pair(l[j], r[x]));
            }
        }
        
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        
        c += calc(v);
        
        ans = min(ans, c);
    }
    
    for (i = 0; i < n; i++) {
        int c = i;
        vector <pair<int, int> > v;
        
        for (j = 0; j < n; j++) {
            int x = (j - i + n) % n;
            
            if (b[j] != a[x]) {
                c++;
                
                if (b[j] == '0' && r[x] > i) v.push_back(make_pair(l[x], r[j]));
            }
        }
        
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        
        c += calc(v);
        
        ans = min(ans, c);
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define coyes cout << "Yes" << endl;
#define cono cout << "No" << endl;
#define coYes cout << "YES" << endl;
#define coNo cout << "NO" << endl;
using namespace std;
using ll = long long int;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  string al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int s_size = s.size();
  rep(i, s_size) {
    rep(j, 26) {
      if (s.at(i) == al.at(j)) {
        s.at(i) = al.at((j + n) % 26);
        break;
      }
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s,c;
int main()
{
	int n;
	cin >> n;
	cout << "0" << "\n";
	cout.flush();
	cin >> s;
	if(s=="Vacant")
    {
        return 0;
    }
    else
    {
        int l=1,r=n-1;
        while(l<r)
        {
            int mid=((l+r)>>1);
            cout << mid << "\n";
            cout.flush();
            cin >> c;
            if(c=="Vacant")
                return 0;
            string ans;
            if(mid%2==0)
            {
                ans=s;
            }
            else
            {
                if(s=="Female")
                    ans="Male";
                else
                    ans="Female";
            }
            if(c==ans)
            {
                l=mid+1;
            }
            else
            {
                r=mid;
            }
        }
        cout << l << "\n";
        cout.flush();
    }
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

int n, x;
int l[100];
int ans = 0;
int d = 0, i = 0;

int main(){
  cin >> n >> x;
  rep(i, n) cin >> l[i];
  while(i <= n+1 && d <= x){
    d = d + l[i];
    i++;
  }
  cout << i <<endl;
}

Measured memory_bytes: 256
a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
c=input()
for i in range(len(a)):
    if c is a[i]:
        print(a[i+1])
    else:
        continue

Measured memory_bytes: 3060
from math import *
def gcd2(array):
    temp = array[0]
    for a in array[1:]:
        temp = gcd(temp, a)
    return temp
N, X = map(int, input().split())
D = []
for x in map(int, input().split()):
    D.append(abs(x-X))
print(gcd2(D))



Measured memory_bytes: 85676
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

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

const int N = 110, K = 1e5+10;
int n, k, a[N], dp[K]; //dp[i] - 1 if player 1 wins when starting on a board of i stones, 0 if player 2 wins when starting on a board of i stones

int rec(int s) {
	int& memo = dp[s];
	if(memo != -1) return memo;
	bool cril = false; //can recurse into loss === win condition
	REP(i, n) if(a[i] <= s && !rec(s-a[i])) cril = true;
	return memo = cril;
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    cin >> n >> k;
    REP(i, n) cin >> a[i];
    sort(a, a+n);
    cout << (rec(k) ? "First" : "Second") << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    ll I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;
    ll ans = 0;
    ans += O;
    if (L % 2 + J % 2 + I % 2 >= 2 && L && J && I) {
        ans += 3;
        L--;
        J--;
        I--;
    }
    ans += L / 2 * 2;
    ans += J / 2 * 2;
    ans += I / 2 * 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int S;
    int h, m, s;
  
    do {  
        cin >> S;
    } while (S < 0 || S > 86400);

    h = S / 3600;
    m = (S - h * 3600) / 60;
    s = (S - h * 3600) - m * 60;

    cout << h << ":" << m << ":" << s << endl;

    return (0);
}

Measured memory_bytes: 1168
ans = []
while True:
    try:
        a = map(int,raw_input().split())
    except EOFError:
        break
    b = map(int,raw_input().split())

    n = 0
    m = 0

    for i in range(4):
        if a[i] == b[i]:
            n += 1

    for i in range(0,4):
        for j in range(0,4):
            if a[i] == b[j]:
                m += 1
    m -= n

    ans.append(str(n)+' '+str(m))

for i in ans:
    print i

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

int main() {
    int n,x,a;
    cin>>n>>x;
    int p;
    cin>>p;
    ll ans=0;
    for (int i=1;i<n;i++) {
        cin>>a;
        if (x<a+p) {
            ans+=a+p-x;
            a-=a+p-x;
            a=max(a,0);
        }
        p=a;
    }
    cout<<ans<<endl;
    return 0;
}

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

typedef complex<double> P;

#define EPS (1e-8)

double dot(P a,P b){
	return (a.real() * b.real() + a.imag() * b.imag());
}

int main(void){
	double d;

	while(cin>>d && d != 0){
		P p,v;
		cin>>p.real()>>p.imag()>>v.real()>>v.imag();

		P x = P(0,0) - p;
		double res = dot(x,v)/abs(x)/abs(v);
		double dist = -1;

		if(fabs(res-1) < EPS){
			dist = abs(p);
		}
		else if(fabs(res+1) < EPS){
			dist = 2 - abs(p);
		}

		if(0<dist+EPS && dist < d + EPS){
			printf("%.8lf\n",dist);
		}
		else{
			cout<<"impossible\n";
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

long long GCD(long long a, long long b){
    if(a==0) return b;
    return GCD(b%a, a);
}

int main(){
    int N;cin >>N;
    long long ans; cin >>ans;
    for(int i=1;i<N;i++){
        long long n; cin >> n;
        ans=ans/GCD(ans,n)*n;
    }
    cout << ans<< endl;
}


Measured memory_bytes: 256
use std::cmp;
use std::io;

fn main() {
    let input = input_number();
    let n = input[0] as usize;
    let his = input_number();
    let mut dp = vec![i64::max_value(); n];

    for (index, _) in his.iter().enumerate() {
        if index == 0 {
            dp[0] = 0;
            continue;
        }
        dp[index] = dp[index - 1] + (his[index] - his[index - 1]).abs();
        if index > 1 {
            dp[index] = cmp::min(
                dp[index],
                dp[index - 2] + (his[index] - his[index - 2]).abs(),
            );
        }
    }

    println!("{}", dp.last().unwrap());
}

#[allow(dead_code)]
fn input_number() -> Vec<i64> {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<i64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}

#[allow(dead_code)]
fn input() -> (char, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: char = iter.next().unwrap().chars().nth(0).unwrap();
    let n: usize = iter.next().unwrap().parse().unwrap();
    (c, n)
}


Measured memory_bytes: 6396
n = int(input())
a = list(map(int, input().split()))
p = [a[i] for i in range(0, n, 2)]
q = [a[i] for i in range(1, n, 2)]

if n % 2 == 0:
    print(" ".join(map(str, q[::-1] + p)))
else:
    print(" ".join(map(str, p[::-1] + q)))

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

#define ll long long
#define endl '\n'
const int N = 1e6 + 5;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll n, m;
        cin >> n >> m;
        if (n == 1 || m == 1) {
                cout << 1;
                return 0;
        }
        cout << (ll)(ceil(n * m * 1.0 / 2));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<n; i++)

int main(){
    string s; cin >> s;
    int q; cin >> q;
    string t;
    rep(i,q) {
        int ty;
        cin >> ty;
        if(ty==1){
            swap(s,t);
        }else{
            int f; char c;
            cin >> f >> c;
            if(f==1){
                t += c;
            }else{
                s += c;
            }
        }
    }
    reverse(t.begin(), t.end());
    t += s;
    cout << t;
}


Measured memory_bytes: 1160
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(repr(item))
        stderr.write(sep)
    stderr.write(end)


h, w = f()
grid = []
row = [False for _ in range(h)]
column = [False for _ in range(w)]

for i in range(h):
    ro = input()
    row[i] = (ro == '.' * w)
    grid.append(list(ro))

for j in range(w):
    column[j] = all([(grid[k][j] == '.') for k in range(h)])

for i in range(h):
    if row[i]:
        continue
    for j in range(w):
        if not column[j]:
            print(grid[i][j], end='')
    print()


Measured memory_bytes: 5220
n, k = [int(s) for s in input().split()]

e_list = [(int(s) + 1) / 2 for s in input().split()]

temp = sum(e_list[:k])
ans = temp

for i in range(k, n):
    temp = temp - e_list[i - k] + e_list[i]
    if temp > ans:
        ans = temp

print(ans)

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

string wd[7] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

int main() {
  string s;
  cin >> s;

  for (size_t i = 0; i < 7; i++)
  {
    if (wd[i] == s) {
      cout << (7-i) << endl;
    }
  }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 5;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    int n;cin >> n;
    vector<int>a(n);
    for(auto &c : a)cin >> c;
    sort(a.begin(),a.end());
    ll res =  1;
    for(int i = 0 ; i < n ; ++i)res *= __gcd(i , a[i]) , res %= 998244353;
    cout << res;
}


Measured memory_bytes: 640
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N;
int D[50];
int cnt[13];

int main() {
	cin >> N;
	REP(i, N) scanf("%d", D + i);
	
	REP(i, N) cnt[D[i]]++;
	
	bool ng = false;
	if (cnt[0] || cnt[12] > 1) ng = true;
	FOR(i, 1, 12) ng |= cnt[i] > 2;
	
	if (ng) {
		puts("0");
		return 0;
	}
	
	// N < 24
	int ans = 0;
	
	REP(s, 1<<N) {
		int state = 1;
		bool ok = true;
		REP(i, N) {
			if (s >> i & 1) {
				if (state >> (24-D[i]) & 1) ok = false;
				state |= 1 << (24-D[i]);
			}
			else {
				if (state >> D[i] & 1) ok = false;
				state |= 1 << D[i];
			}
		}
		
		if (!ok) continue;
		
		int cur = 100;
		REP(i, 24) if (state >> i & 1) {
			int cnt = 1;
			while (i + cnt < 48 && !(state >> ((i + cnt) % 24) & 1)) cnt++;
			chmin(cur, cnt);
			
			i = i + cnt - 1;
		}
		
		if (cur < 24) chmax(ans, cur);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    set<char> set;
    int t,ans=-1;
    for(int i=1;i<=n-1;i++){
        t=0;
        for(int j=0;j<i;j++){
            set.insert(s[j]);
        }
        for(int j=i;j<n;j++){
            if(set.find(s[j])!=set.end()){
                t++;
                set.erase(s[j]);
            }
        }
        ans=max(ans,t);
        set.clear();
    }
    cout<<ans<<endl;
}


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

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,p) scanf("%d %d %d %d",&n,&m,&o,&p)
#define SINT5(n,m,o,p,q) scanf("%d %d %d %d %d",&n,&m,&o,&p,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 0x2aaaaaaa; // 715,827,882
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second



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

	if ((b - a) % 2 == 0)  puts("Alice");
	else                  puts("Borys");


	//for (;;)getchar();

	return 0;
}

Measured memory_bytes: 256
A, V =gets.split.map(&:to_i)
B, W =gets.split.map(&:to_i)
T = gets.to_i

if V <= W
	puts "NO"
else
	dis = (A - B).abs * 1.0
	per = V - W
	ans = dis / per
	if ans <= T
		puts "YES"
	else
		puts "NO"
	end
end

Measured memory_bytes: 14328
#include<stdio.h>
#define N 100
#define swap(x,y) {x+=y;y=x-y;x-=y;}
int main(){
  int A[N],i=0,j ,a,flag,b=0,o;

  scanf("%d",&a);

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


  flag=1;
  while(flag){
    flag=0;
    for(j=a-1;j>=1;j--){
      if(A[j] < A[j-1]){
	swap(A[j] , A[j-1]);

	flag=1;
	b++;
      }
    }

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

  return 0;
}

Measured memory_bytes: 604
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

using namespace std;
typedef unsigned long long ll;
typedef pair<int,int>P;

int main()
{
	int N;
	string S;
	cin>>N>>S;
	for(;;)
	{
		int r=0,l=0;
		for(int i=0;i<S.length();i++)
		{
			if(S[i]=='(')l++;
			else r++;
			if(l<r)
			{
				S="("+S;
				goto LC;
			}
		}
		if(r==l)break;
		for(int i=0;i<(l-r);i++)
			S=S+")";
	LC:;
	}
	cout<<S<<endl;
}

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


struct Node{
  int key;
  struct Node *right,*parent,*left;
};

void insert(int);
struct Node inorder(struct Node *);
struct Node preorder(struct Node *);
struct Node * find(struct Node *,int);

struct Node *root, *NIL;


int main(){
  int n=0;
  int i=0;
  int number=0;
  char word[6];
  char space;
  int print_flag=0;
  struct Node *f;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%s",word);

    if(word[0]=='i')
      {
	scanf("%d%c",&number,&space);
	insert(number);
      }
    
    else if(word[0]=='p')
      {
	print_flag=1;
      }

    else if(word[0]=='f')
      {
	scanf("%d",&number);
	f=find(root,number);
	if(f != NIL) printf("yes\n");
	else if(f==NIL) printf("no\n");
	f=NIL;
      }

    if(print_flag==1){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      print_flag=0;
    }

    print_flag=0;
  }

  return 0;
}

void insert(int number){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;

  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=number;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if( z->key < x->key ) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if( z->key < y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}

struct Node inorder(struct Node *a){
  if(a==NIL)return;
  inorder(a->left);
  printf(" %d",a->key);
  inorder(a->right);
}

struct Node preorder(struct Node *a){
  if(a==NIL)return;
  printf(" %d",a->key);
  preorder(a->left);
  preorder(a->right);
}

struct Node * find(struct Node *a, int number){
  while( a != NIL && number != a->key)
    {
      if(number < a->key) a=a->left;
      else a=a->right;
    }
  return a;
}



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

p = 1

for i in range(n):
  if a[i] == 0:
    print(0)
    exit()

for j in range(n):
  p *= a[j]
  if p > 10**18:
    print(-1)
    exit()

print(p)

Measured memory_bytes: 21584
### main

3.times do
  h0, m0, s0, h1, m1, s1 = gets.strip.split(' ').map{|s| s.to_i}

  dt = (h1 - h0) * 3600 + (m1 - m0) * 60 + (s1 - s0)

  dh = dt / 3600
  dm = (dt % 3600) / 60
  ds = dt % 60

  puts [dh, dm ,ds].join(' ')
end

Measured memory_bytes: 6100
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	long double N, K;
	cin >> N >> K;

	long double ans = 0;
	for (int i = 1; i <= N; i++){

		if (i >= K) {
			ans += (N - K + 1) * 1.0 / N;
			break;
		}

		for (int j = 0; j <= 17; j++){
			if (((1 << j) < (K / i)) && ((K / i) <= (1 << (j + 1)))) { 
				ans += 1.0 / (1 << (j + 1)) * 1.0 / N;
				break;
			}
		}
	}

	cout.precision(15);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){

  int n[10000],nc,q[500],qc,i,j,count=0;
  scanf("%d",&nc);
  for(i=0 ; i<nc ; i++){
    scanf("%d",&n[i]);
  }
  scanf("%d",&qc);
  for(i=0;i<qc;i++){
    scanf("%d",&q[i]);
    for(j=0;j<nc;j++){
      if(n[j]==q[i]){
        count++;
        break;
      }
    }
  }

  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
#coding: UTF-8

from bisect import bisect_right

max_number = 1000000
prime_flag_list = [True] * max_number

prime_flag_list[0] = prime_flag_list[1] = False

prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])

for i in range(3, int(max_number**0.5) + 1, 2):
    prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])

prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]

while True:
    try:
        input = int(raw_input())
    except EOFError:
        break

    print bisect_right(prime_list, input)

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

void maxheap(int* A, int N, int i){
    int l, r, largest;
    l = 2*i;
    r = 2*i + 1;

    if( l <= N && A[l] > A[i] ){
        largest = l;
    }else{
        largest = i;
    }

    if( r <= N && A[r] > A[largest] ){
        largest = r;
    }

    if( largest != i ){
        swap(A[i], A[largest]);
        maxheap(A, N, largest);
    }
}

int main(){
    int N,M;
    cin >> N >> M;
    int A[N+1];

    for(int i=1; i<=N; i++){
        cin >> A[i];
    }

    for(int j=N/2; j>=1; j--){
        maxheap(A,N,j);
    }

    for(int i=0; i<M; i++){
        A[1]=A[1]/2;
        maxheap(A,N,1);
    }

    long sum;
    sum=0;
    for(int i=1; i<=N; i++){
        sum = sum + (long) A[i];
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775808;

ll m[2001][2001];

ll modminus(ll x, ll y) {
    return (x - y + mod) % mod;
}

int main() {
    ll N, x;
    cin >> N >> x;
    mod = N;
    for (int i = 0; i < N; i++) {
        cin >> m[0][i];
    }
    for (int n = 1; n < N; n++) {
        for (int i = 0; i < N; i++) {
            m[n][i] = min(m[n - 1][i], m[n - 1][modminus(i , 1)]);
        }
    }
    ll ans = llmax;
    for (int n = 0; n < N; n++) {
        ll num = accumulate(m[n], m[n] + N, 0ll) + x * n;
        ans = min(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=998244353;
const int MAX = 510000;
const int INF = 1e9;
const double pi=acos(-1);

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  vector<int>p(n);
  rep(i,n){
    cin >> p[i];
    p[i]--;
  }
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    tree.merge(x,y);
  }
  int sum=0;
  rep(i,n){
    if(tree.issame(p[i],i))sum++;
  }
  
  cout << sum<< endl;
  return 0;
  
}

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

using namespace std;

#define mod 1e9+7

int main()

{

    int n,k;

    cin>>n>>k;

    int a[n+1],b[n+1];

    for(int i=1; i<=n; i++)

    {

        cin>>a[i];

    }

    while(k--)

    {

        memset(b,0,sizeof(b));

       for(int i=1;i<=n;i++)

       {

         if(a[i]+i<n)

         {

             b[i]++;

             b[i+a[i]+1]--;

         }

         else

         {

             b[i]++;

         }

         if(i-a[i]>=1)

         {

             b[i-a[i]]++;

             b[i]--;

         }

         else

         {

             b[1]++;

             b[i]--;

         }

       }

       a[1]=b[1];

       for(int i=2;i<=n;i++)

       {

           a[i]=a[i-1]+b[i];

       }

       int flag=0;

       for(int i=1;i<=n;i++)

       {

           if(a[i]!=n)

           {

               flag++;

               break;

           }

       }

       if(!flag)

       {

           break;

       }

    }

    for(int i=1; i<=n; i++)

    {

        cout<<a[i]<<" ";

    }

    return 0;

}

Measured memory_bytes: 5188
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

int main()
{
    int N;
    cin >> N;
    vll A(N);
    cin >> A;
    vll l(N),r(N);
    l[0] = A[0];
    for(int i=1; i<N; i++){
        l[i] = l[i-1] + A[i];
    }
    r[N-1] = A[N-1];
    for(int i=N-2; i>=0; i--){
        r[i] = r[i+1] + A[i];
    }
    ll ans = 1LL << 60;
    REP(i,N-1){
        chmin(ans,abs(l[i]-r[i+1]));
    }
    cout << ans << endl;

}

Measured memory_bytes: 7996
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY
N,K=get_i
xy=array(N)
kind_x=Hash.new(0)
kind_y=Hash.new(0)
N.times do|i|
  xy[i]=get_i
  kind_x[xy[i][0]]=1
  kind_y[xy[i][1]]=1
end
kind_x=kind_x.sort{|x,y| x[0]<=>y[0]}
kind_y=kind_y.sort{|x,y| x[0]<=>y[0]}
to_i_x=Hash.new(-1)
to_i_y=Hash.new(-1)
to_x=array(kind_x.size)
to_y=array(kind_y.size)
kind_x.each_with_index do|arr,i|
  to_i_x[arr[0]]=i
  to_x[i]=arr[0]
end
kind_y.each_with_index do|arr,i|
  to_i_y[arr[0]]=i
  to_y[i]=arr[0]
end
w=to_x.size
h=to_y.size
accum=array(w+1,0,h+1)
a=array(w,0,h)
xy.each do|x,y|
    a[to_i_y[y]][to_i_x[x]]+=1
end
h.times do|i|
    w.times do|j|
        accum[i+1][j+1]=a[i][j]+accum[i+1][j]+accum[i][j+1]-accum[i][j]
    end
end
ans=INF
(h-1).times do|y1|
    (w-1).times do|x1|
        (y1+1).upto(h-1) do|y2|
            y2+=1
            (x1+1).upto(w-1) do|x2|
                x2+=1
                val=accum[y2][x2]-accum[y2][x1]-accum[y1][x2]+accum[y1][x1]
                if val>=K
                  s=(to_x[x2-1]-to_x[x1])*(to_y[y2-1]-to_y[y1])
                  ans=min(ans,s)
                end
            end
        end
    end
end
puts ans

Measured memory_bytes: 14348
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi //cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
//#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

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

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int a,b,q;
int MOD=INT_MAX;

main(){
	cin>>a>>b>>q;
	int s[a],t[b],x[q];
	rep(i,a)cin>>s[i];
	rep(i,b)cin>>t[i];
	rep(i,q)cin>>x[i];
	int ss=s[0],sl=s[a-1],ts=t[0],tl=t[b-1];
	rep(i,q){
		int p=x[i];
		int d1=0,d2=0,d3=0,d4=0;
		int is=(int)lower_bound(s,s+a,p)-(int)s;
		int it=(int)lower_bound(t,t+b,p)-(int)t;
		is/=8;
		it/=8;
		//debug(is,it,p);
		hi
		if(p<ss||p<ts)d1=MOD;
		else d1=max(p-s[is-1],p-t[it-1]);
		//debug(sl,tl,p);
		hi;

		if(p>sl||p>tl){
			d2=MOD;
			hi;
		}
		else{
			hi;
			//debug(is,it);
			d2=max(s[is]-p,t[it]-p);
		}
		hi;
		if(p<ss||p>tl)d3=MOD;
		else d3=2*(p-s[is-1])+(t[it]-p);
		hi
		if(p<ts||p>sl)d3=min(d3,MOD);
		else d3=min(d3,  2*(p-t[it-1])+(s[is]-p)  );
		hi
		if(p<ss||p>tl)d4=MOD;
		else d4=(p-s[is-1])+2*(t[it]-p);
		hi
		if(p<ts||p>sl)d4=min(d4,MOD);
		else d4=min(d4,  (p-t[it-1])+2*(s[is]-p)  );
		hi
		dump(min({d1,d2,d3,d4}));
	}
}






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

int main()
{
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r ;

  if(r>x||W-r<x)
    {
    cout<<"No"<<endl;}
  else if(r>y||H-r<y)
    {
    cout<<"No"<<endl;}
  else
    {
    cout<<"Yes"<<endl;}

  return 0;
}

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

using namespace std;

struct Node
{
    int key;
    Node *right, *left, *parent;
};

Node *root, *nullNode;

Node *createNode(const int key)
{
    Node *n = (Node *)malloc(sizeof(Node));
    n->key = key;
    n->left = nullNode;
    n->right = nullNode;
    return n;
}

void insert(const int k)
{
    Node *y = root, *z = createNode(k);
    for (Node *i = root; i != nullNode; z->key < i->key ? i = i->left : i = i->right)
    {
        y = i;
    }

    z->parent = y;
    if (y == nullNode)
        root = z;
    else if (z->key < y->key)
        y->left = z;
    else
        y->right = z;
}

bool find(Node *n, const int k)
{
    for (; n != nullNode; k < n->key ? n = n->left : n = n->right)
        if (k == n->key)
            return true;
    return false;
}

void inorder(const Node *n)
{
    if (n == nullNode)
        return;
    inorder(n->left);
    printf(" %d", n->key);
    inorder(n->right);
}

void preorder(const Node *n)
{
    if (n == nullNode)
        return;
    printf(" %d", n->key);
    preorder(n->left);
    preorder(n->right);
}

void deleteNode(Node *n)
{
    if (n == nullNode)
        return;
    deleteNode(n->left);
    deleteNode(n->right);
    free(n);
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        string ord;
        cin >> ord;
        if (ord == "insert")
        {
            int k;
            cin >> k;
            insert(k);
        }
        else if (ord == "find")
        {
            int k;
            cin >> k;
            printf("%s\n", find(root, k) ? "yes" : "no");
        }
        else
        {
            inorder(root);
            printf("\n");

            preorder(root);
            printf("\n");
        }
    }

    deleteNode(root);

    return 0;
}



Measured memory_bytes: 22088
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 105;
int n, b[N], a[N];

int main() {
    cin >> n;
    rep(i, 1, n - 1) cin >> b[i];
    a[1] = b[1], a[n] = b[n - 1];
    rep(i, 2, n - 1) {
        a[i] = min(b[i - 1], b[i]);
    }
    int ans = 0;
    rep(i, 1, n) ans += a[i];
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

using namespace std;

const ll N = 1e5 + 5;

ll n, W;
ll dp[N];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>W;
    for (int i = 1; i <= n; i++){
        ll a, b;
        cin>>a>>b;
        for (int j = W; j >= a; j--)
            dp[j] = max (dp[j], dp[j - a] + b);
    }
    ll ans = 0;
    for (int i = 1; i <= W; i++)
        ans = max (ans, dp[i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int A,B,C,X,Y;
	cin>>A>>B>>C>>X>>Y;
	int ans;
	if(A+B > C*2){
		int min_n = min(X, Y);
		ans = C*min_n*2;
		int rest_n = max(X, Y) - min_n;

		if(X > Y){//rest X -> A
			if(A > C*2){
				ans += C * rest_n * 2;
			}
			else{
				ans += A * rest_n;
			}
		}
		else if(X < Y){//rest Y -> B
			if(B > C*2){
				ans += C * rest_n * 2;
			}
			else{
				ans += B * rest_n;
			}
		}
		else{//rest  0
		}

	}
	else{
		ans = A*X + B*Y;
	}
	ote(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[]) {
	int N;
	std::cin >> N;
	int unl = 1;
	int temp;
	for (size_t i = 0; i < N; i++) {
		std::cin >> temp;
		if (temp%2 == 0) {
			unl *= 2;
		}
		else {
			unl *= 1;
		}
	}

	std::cout << pow(3,N) - unl << '\n';
	return 0;
}


Measured memory_bytes: 512