akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
        
            
    static StringBuilder out=new StringBuilder();
    static FastReader in=new FastReader();

    public static void reverse(int []a){
        int i=0,j=a.length-1;
        while(i<j){
            int temp=a[i];a[i]=a[j];a[j]=temp;
            i++;j--;
        }
    }
    public static void main(String args[]){
        int x=in.nextInt(),y=in.nextInt(),a=in.nextInt(),b=in.nextInt(),c=in.nextInt();
        int p[]=getIntArray(a);
        int q[]=getIntArray(b);
        int r[]=getIntArray(c);
        Arrays.sort(p);reverse(p);
        Arrays.sort(q);reverse(q);
        Arrays.sort(r);reverse(r);
        int []sel=new int[x+y+c];
        int k=0;
        for(int i=0;i<x;i++){
            sel[k++]=p[i];
        }
        for(int i=0;i<y;i++){
            sel[k++]=q[i];
        }
        for(int i=0;i<c;i++){
            sel[k++]=r[i];
        }
        Arrays.sort(sel);reverse(sel);
        long ans=0;
        for(int i=0;i<x+y;i++){
            ans+=sel[i];
        }
        System.out.println(ans);
    }
    public static int[] getIntArray(int n){
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=in.nextInt();
        }
        return arr;
    }   


    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 49836
#include<stdio.h>
#include<math.h>

int main(){
  int N;
  double K;

  scanf("%d %lf", &N, &K);

  int i;

  double sum = 0;
  double lo;

  for(i = 1; i <= N; i++){
    lo = log2(K/i);
    if(lo < 0) lo = 0;
    if(lo != (int)lo) lo++;
    sum += 1./pow(2, (int)lo);
  }
  sum /= N;

  printf("%.10lf\n", sum);

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const int MOD=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-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 same(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)];
	}
};

ll n,dp[101][10][10][10]={};
ll dfs(ll num,ll one,ll two,ll three){
	if(num==n)return 1;
	if(dp[num][one][two][three]!=0)return dp[num][one][two][three];

	ll ans=0;
	rep(f,0,4){
		if(one==1&&two==2&&f==3)continue;
		if(one==1&&three==2&&f==3)continue;
		if(two==1&&three==2&&f==3)continue;
		if(two==2&&three==1&&f==3)continue;
		if(two==1&&three==3&&f==2)continue;
		ans=(ans+dfs(num+1,two,three,f))%MOD;
	}
	return dp[num][one][two][three]=ans;
}


int main(){
	cin>>n;
	print(dfs(0,0,0,0));
	
}


Measured memory_bytes: 896
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;


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

	cin >> N;
	for (int i = 1; i <= 10; i++) {
		for (int j = 1; j < 10; j++) {
			vector<int>box(i, -1);
			while (box[0] == -1) {
				vector<int>bag(i);
				bag[0] = j;
				for (int k = 1; k < i; k++) {
					bag[k] = bag[k - 1] + box[k];
				}
				box.back()++;
				int cnt = box.size() - 1;
				while (box[cnt] == 2) {
					box[cnt--] = -1;
					box[cnt]++;
				}
				if (*min_element(bag.begin(), bag.end()) < 0 || *max_element(bag.begin(), bag.end()) > 9)continue;
				N--;
				if (N==0) {
					for (auto k : bag)cout << k;
					cout << endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = map(int,input().split())
h = [0]*(H+1)
w = [0]*(W+1)
c = [{-1,10**6} for i in range(H+1)]
for i in range(m):
    a,b = map(int,input().split())
    h[a] += 1
    w[b] += 1
    c[a].add(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in hkouho:
    # c[i] = set(c[i])
    for j in wkouho:
        # if c[i][bisect_left(c[i],j)] != j:
        if j not in c[i]:
            print(mh+mw)
            exit()
print(mh+mw-1)

Measured memory_bytes: 219860
#include<bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

int n;
long long s[200000 + 5];
int check[200000 + 5];



int main()
{
	file(1);
	scanf("%d", &n);
	for (int i = 0; i < n; i++)scanf("%lld", &s[i]);
	long long ans = 0;
	for (int c = 1; c < n; c++)
	{
		long long res = 0;
		for (int i = 0;; i++)
		{
			int l = i * c, r = n - 1 - i * c;
			if ((r%c == 0 && r <= l)||l>=n||r<0)break;
			res += s[l] + s[r];
			if (r > c)ans = max(ans, res);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
s = STDIN.gets.strip;

dict = [
  "dream",
  "dreamer",
  "erase",
  "eraser",
].map(&:reverse)
s = s.reverse()

i = 0
while i < s.length
  ok = false
  dict.each do |str|
    if s.slice(i, str.length) == str
      i = i + str.length
      ok = true
      break
    end
  end

  if !ok
    puts "NO"
    exit
  end
end
puts "YES"

Measured memory_bytes: 2044
def between(x, y, a):
    lrg = max(x, y)
    sml = min(x, y)
    if (sml <= a <= lrg):
        return True
    else:
        return False

while (True):
    pos = [10, 10]
    result = 'No'
    N = int(input()) # Total number of jewels
    if N == 0:
        break
    jewelPositions = list()
    for i in range(N):
        jewelPos = list(map(int, input().split()))
        jewelPositions.append(jewelPos)

    M = int(input()) # Number of instructions
    # instructions = list()
    for i in range(M):
        # print('==== Currently at ', pos)
        instruction = input().split()
        # print('instruction : ', i)
        if (result == 'Yes'):
            continue
        instruction[1] = int(instruction[1])
        if (instruction[0] == 'E'):
            move = ('x', instruction[1])
        elif (instruction[0] == 'W'):
            move = ('x', -1*instruction[1])
        elif (instruction[0] == 'N'):
            move = ('y', instruction[1])
        elif (instruction[0] == 'S'):
            move = ('y', -1*instruction[1])
        else:
            raise NotImplementedError

        # print('>>>>>>>>>>>>>>> pos: ', pos, ', move: ', move)
        jewelToRemove = []
        for jewel in jewelPositions:

            '''
            if ((move[0] == 'x') and (pos[1] == jewel[1]) and (pos[0] <= jewel[0] <= pos[0]+move[1])) \
                    or ((move[0] == 'y') and (pos[0] == jewel[0]) and (pos[1] <= jewel[1] <= pos[1]+move[1])):
            '''


            if ((move[0] == 'x') and (pos[1] == jewel[1]) and (between(0, move[1], jewel[0]-pos[0]))) \
                    or ((move[0] == 'y') and (pos[0] == jewel[0]) and (between(0, move[1], jewel[1]-pos[1]))):
                # print('---- Collecting a jewel at ', jewel)
                # jewelPositions.remove(jewel)
                jewelToRemove.append(jewel)
            else:
                # print('xxxx Jewel not collected at ', jewel)
                pass

        for jewel in jewelToRemove:
            jewelPositions.remove(jewel)

        if (move[0] == 'x'):
            pos[0] += move[1]
        elif (move[0] == 'y'):
            pos[1] += move[1]

        if not jewelPositions:
            """
            if empty,
            all jewels are collected
            """
            result = 'Yes'
        else:
            pass
        # print('jewels are left at ', jewelPositions)
    print(result)

"""
2
10 11
11 12
2
N 2
E 1
2
10 11
11 12
2
N 2
W 1
3
0 15
5 10
5 15
5
W 10
S 10
N 20
E 10
S 10
0
"""

Measured memory_bytes: 7840
n = int(input())
a = input().split()
b = []
ans = []
even = a[1::2]
odd = a[0::2]
b.append(even)#even number
b.append(odd)#odd number
# print(b)
if len(a) % 2 == 0:
    for i in range(1,len(even) + 1):
        ans.append(even[-i])
    ans = ans + odd
else:
    for i in range(1,len(odd) + 1):
        ans.append(odd[-i])
    ans = ans + even
for i in range(len(ans)):
    if i != len(ans) -1:
        print(ans[i],end=" ")
    else:
        print(ans[i])

Measured memory_bytes: 24128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int sosu[1150]={1,1,0};
	for(int i=2;i<1150;i++)if(sosu[i]==0)
	for(int j=i*2;j<1150;j+=i)sosu[j]=true;
	
	vi so;
	rep(i,1150)if(sosu[i]==0)so.pb(i);
	int dp[200][1150]={0};
	dp[0][0]=1;
	rep(i,so.size())for(int j=198;j>=0;j--)rep(k,1150)if(dp[j][k]){
		if(k+so[i]<1150)dp[j+1][k+so[i]]+=dp[j][k];
	}
	
	int n,k;
	while(cin>>n>>k,n+k){
		cout<<dp[k][n]<<endl;
	}
}

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

int main(){
  long result[1000];
  int length=0,temp;
  char input[10000];

  while(true){
    cin >> input;
    if(strlen(input) == 1 && (input[0] - '0') == 0) break;
    temp=0;
    for(int i=0; i<(int)strlen(input); i++){
      temp += input[i] - '0';
    }
    result[length] = temp;
    length++;
  }
  for(int i=0; i<length; i++){
    cout<<result[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3120
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# Nの素因数分解を辞書で返す
def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        while n % i == 0:
            cnt += 1
            n = n // i
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def combination_mod_initialize(n, MOD=10**9+7):
    fac = [1]*(n+1)
    inv = [1]*(n+1)
    for i in range(1, n+1):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = inv[i-1] * pow(i, -1, MOD) % MOD
    return fac, inv

# 二項係数　高速
def combination_mod(n, r, fac, inv, mod=10**9+7):
    return fac[n] * inv[r] * inv[n-r]


def main():
    N, M = NMI()
    PD = prime_fact(M)
    ans = 1
    fac, inv = combination_mod_initialize(10**6, MOD)

    for x in list(PD.values()):
        ans = ans * combination_mod(N+x-1, N-1, fac, inv) % MOD

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 88432
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   char a[2][3];
   for(int i=0;i<2;i++){
      for(int j=0;j<3;j++){
         cin >> a[i][j];
      }
   }

   if(a[0][0]==a[1][2] && a[0][1]==a[1][1] && a[0][2]==a[1][0]) cout << "YES" << endl;
   else cout << "NO" << endl;


   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define length(a) (sizeof(a)/sizeof(a[0]))

int printLargeNumber(int a[]){
	int i,flag=0,aLength;
	aLength=3;//length(a);
	for(i=aLength-1;i>=0;i--){
		if(a[i]!=0 || flag || i==0){
			if(flag==0){
				printf("%d",a[i]);
				flag=1;
			}else{
				printf("%08d",a[i]);
			}
		}
	}
	printf("\n");
	return 0;
}

int factorial(int num,int sum[]){
	int i,j,sumLength;
	int kuriagari=0;
	sumLength=3;//length(sum);
	sum[0]=1;
	for(i=1;i<=num;i++){
		kuriagari=0;
		for(j=0;j<sumLength;j++){
/*			printf("%d*%d+%d\n",sum[j],i,kuriagari);
*/			sum[j]*=i;
			sum[j]+=kuriagari;
			kuriagari=sum[j]/100000000;
			sum[j]%=100000000;
		}
		if(kuriagari)return kuriagari;
/*		printf("\t");
		printLargeNumber(sum);
*/	}
	
	return kuriagari;
}

int shokika(int a[]){
	int i;
	for(i=0;i<3;i++){
		a[i]=0;
	}
	return 0;
}

int main(){
	int num,sum[3]={1,0,0};
	int i;
	scanf("%d",&num);
	if(factorial(num,sum)){
		printf("over flow\n");
	}
	printLargeNumber(sum);
	return 0;
}

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

int main() {
  ll n,m; cin >>n >>m;
  ll ans;
  //2*2以上のものについて
  //角は4回裏返される。なし。
  //端は6回裏返される。なし。
  //中は9回裏返される。あり。
  if (n*m==1) ans = 1;
  else if ((n-1)*(m-1)==0) ans = m*n-2;
  else ans = n*m - 4 - (n-2)*2 - (m-2)*2;
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
def read():
    S = input().strip()
    return (S, )


def solve(S):
    isYYMM = False
    isMMYY = False
    if 1 <= int(S[0:2]) <= 12:
        isMMYY = True
    if 1 <= int(S[2:4]) <= 12:
        isYYMM = True
    if isMMYY and isYYMM:
        return 'AMBIGUOUS'
    elif isMMYY:
        return 'MMYY'
    elif isYYMM:
        return 'YYMM'
    else:
        return 'NA'


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

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

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int N; vi P; vi Q;
void input()
{
    cin>>N;
    rep(i,N){
        int a; cin>>a; P.emplace_back(a);
    }
    rep(i,N){
        int a; cin>>a; Q.emplace_back(a);
    }
    return;
}

void solve()
{
    vi R;
    rep(i,N) R.emplace_back(P[i]);
    SORT(R);
    int num=0,pnum=0,qnum=0;
    do{
        // rep(i,N) cout<<R[i]<<" ";
        // cout<<endl;
        int i=0;
        do{
            if(P[i]!=R[i]) break;
            ++i;
        }while(i<N);
        if(i==N) pnum=num;
        // cout<<"pnum: "<<pnum<<" i: "<<i<<" N: "<<N<<endl;
        i=0;
        do{
            if(Q[i]!=R[i]) break;
            ++i;
        }while(i<N);
        if(i==N) qnum=num;
        // cout<<"qnum: "<<qnum<<" i: "<<i<<" N: "<<N<<endl;
        ++num;
    }while(next_permutation(R.begin(),R.end()));
    // cout<<pnum<<" "<<qnum<<endl;
    cout<<abs(pnum-qnum)<<endl;
    return;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stacnice_task-protector")
//    #pragma GCC optimize("fast-math")

#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b emplace_back
////////////////////////////////???????????????CHECnice_task THIS OUT???????????????//////////////////////////////
#define ll long long
////////////////////////////////???????????????CHECnice_task THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
using namespace std;
//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
ll inf = 1e9, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={0,0,1,-1};
const ll ty[4]={1,-1,0,0};
const char rev_to[4]={'E','W','N','S'};
//const ll N
signed main(){
    fast_io;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll f=ceil((ld)c/b),s=ceil((ld)a/d);
    if(f<=s){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}
/*
    если WA , то чекер говно, поэтому почекай 18 строчку
    чекай для t>1 (выводишь ли ты  с endl))
*/


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
int main(void){
    int n, m, l;
    cin >> n >> m >> l;
    
    //??????A?????\???????????????
    int A[n][m];
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    
    //??????B?????\???????????????
    int B[m][l];
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> B[i][j];
        }
    }
    
    //A*B=C??¨?????????????????????C????¨????
    long C[n][l];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            C[i][j] = 0;
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            for (int k = 0; k < m; k++) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    
    //??????
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            if(j!=0) std::cout << " ";
            cout << C[i][j];
        }
        std::cout << std::endl;
    }
    
}

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

int main(){
    int N;
    cin >> N;
    int p[N], q[N];
    for(int i = 0; i < N; i++) cin >> p[i];
    for(int i = 0; i < N; i++) cin >> q[i];
    int a[N];
    for(int i = 0; i < N; i++) a[i] = i + 1;

    int x = -1, y = -1;
    int cnt = 0;
    do {
        cnt++;
        //cout << "hoge" << endl;
        //check
        bool check = true;
        for(int i = 0; i < N; i++){
            if(p[i] != a[i]) check = false;
        }
        if(check) x = cnt;

        check = true;
        for(int i = 0; i < N; i++){
            if(q[i] != a[i]) check = false;
        }
        if(check) y = cnt;
    } while(next_permutation(a, a + N));

    //cout << x << y << endl;
    cout << abs(x - y) << endl;
    return 0;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[105],n,k,i;
	while(scanf("%d%d",&n,&k)!=EOF)
	{
		memset(a,0,sizeof(a));
		for(i=1;i<=k;i++)
		{
			int t,x,j;
			cin>>t;
			for(j=1;j<=t;j++)
			{
				cin>>x;
				a[x]++;
			}
		}
		int num=0;
		for(i=1;i<=n;i++)
		{
			if(a[i]==0)num++;
		}
		cout<<num<<endl;
	}
}

Measured memory_bytes: 3728
#include <algorithm>
#include <cstdio>
char str[105];
int row_pre[105][105], col_pre[105][105], dp[105][105][105][105];
int main()
{
	// freopen("AGC004-E.in", "r", stdin);
	int n, m, x, y;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
	{
		scanf("%s", str);
		for (int j = 0; j < m; j++)
		{
			row_pre[i][j] = (j ? row_pre[i][j - 1] : 0) + (str[j] == 'o');
			col_pre[i][j] = (i ? col_pre[i - 1][j] : 0) + (str[j] == 'o');
			if (str[j] == 'E')
			{
				x = i;
				y = j;
			}
		}
	}
	auto calc_row = [&] (int idx, int l, int r)
	{
		int ll = std::max(l, r - y), rr = std::min(r, m - 1 - y + l);
		if (ll > rr)
			return 0;
		return row_pre[idx][rr] - (ll ? row_pre[idx][ll - 1] : 0);
	};
	auto calc_col = [&] (int idx, int l, int r)
	{
		int ll = std::max(l, r - x), rr = std::min(r, n - 1 - x + l);
		if (ll > rr)
			return 0;
		return col_pre[rr][idx] - (ll ? col_pre[ll - 1][idx] : 0);
	};
	auto upd = [&] (int &a, const int &b)
	{
		if (a < b)
			a = b;
	};
	for (int i = 0; i <= x; i++)
	{
		for (int j = n - 1; j >= x; j--)
		{
			for (int k = 0; k <= y; k++)
			{
				for (int t = m - 1; t >= y; t--)
				{
					if (i > j - x)
						upd(dp[i][j][k][t], dp[i - 1][j][k][t] + calc_row(i - 1, k, t));
					if (j < n - 1 - x + i)
						upd(dp[i][j][k][t], dp[i][j + 1][k][t] + calc_row(j + 1, k, t));
					if (k > t - y)
						upd(dp[i][j][k][t], dp[i][j][k - 1][t] + calc_col(k - 1, i, j));
					if (t < m - 1 - y + k)
						upd(dp[i][j][k][t], dp[i][j][k][t + 1] + calc_col(t + 1, i, j));
				}
			}
		}
	}
	printf("%d\n", dp[x][x][y][y]);
	return 0;
}


Measured memory_bytes: 235776
#include <bits/stdc++.h>
using namespace std;
int main(){
   int a,b;
   cin>>a>>b;
   if (a<b){
	   cout<<"a < b"<<endl;
   }
   else if (a>b){
	   cout<<"a > b"<<endl;
   }
   else {
	   cout<<"a == b"<<endl;
   }
   
}




Measured memory_bytes: 3064
#ifdef _WIN32
	#include <vector>
	#include<set>
	#include<map>
	#include<algorithm>
	#include<stdio.h>
	#include<iostream>
#else
	#include <bits/stdc++.h>
#endif
using namespace std;

int main() {
	double L;
	cin >> L;
	// a fix: mass M = ab(L-(a+b)) = abL - a^2b - ab^2
	// dM/db = aL - a^2 - 2ab = 0 -> b = (L - a)/2;
	// M = a * (L -a)/2 * (L-a)/2
	// dM/da = - -> 3a^2 - 4La + L^2 = 0
	// a = L/3, L
	double a = L / 3.0;
	cout << fixed << setprecision(6) << a * a * a << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(1000000000000000000<abs(a-b)) {
    cout<<"Unfair"<<endl;
  }
  else if(k%2) {
    cout<<b-a<<endl;
  }
  else {
    cout<<a-b<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    rep(i, 0, m) cin >> a[i];
    ll ans = 0;
    if (n >= m)
        ans = 0;
    else
    {
        sort(all(a));
        ll tmp = a[a.size() - 1] - a[0];
        priority_queue<ll> mp;
        rep(i, 0, m - 1) mp.push(a[i + 1] - a[i]);
        rep(i, 0, n - 1)
        {
            ll t = mp.top();
            mp.pop();
            tmp -= t;
        }
        ans = tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4944
from collections import deque
que=deque(input())
q=int(input())
rev=False
for i in range(q):
    t=input()
    if t=='1':
        rev=not rev
    else:
        tt,f,c=t.split()
        if (rev==False and f=='1')or(rev and f=='2'):
            que.appendleft(c)
        else:
            que.append(c)
if rev:
    que.reverse()
print(''.join(que))

Measured memory_bytes: 74072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {

		static int n;
		static int[] an;
		static boolean[][] memo;
		static boolean[][] isDone;

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			n = in.nextInt();
			an = in.nextIntArray(n);
			int q = in.nextInt();
			int[] qn = in.nextIntArray(q);

			memo = new boolean[n+1][40001];
			isDone = new boolean[n+1][40001];

			for (int i = 0; i < q; i++) {
			if (f(0, qn[i], 0)) {
				out.println("yes");
			} else {
				out.println("no");
			}
		}


		}
		boolean f(int i, int target, int sum) {
			if (target == sum) {
				return true;
			}
			if (i >= n) {
				return false;
			}
			return f(i+1, target, sum+an[i]) || f(i+1, target, sum);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}
}



Measured memory_bytes: 26096
#include <iostream>

using namespace std;

int binarySearch(int S[],int key, int n){
	int left = 0;
	int right = n;
	int mid = left+right/2;
	
	while( left < right ){
		mid = (left+right)/2;
		if ( key == S[mid] ) return 1;
		if( key > S[mid] ) left = mid+1;
		else if( key < S[mid] ) right = mid;
	}
	return 0;
}

int main(){
	int n,q,key,S[100000],cnt = 0;
	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> S[i];
	cin >> q;
	for(int i = 0; i < q; i++){
		cin >> key;
		if( binarySearch(S,key,n) ) cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}


Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1e9 + 7
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(), v.end(), greater<ll>()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
int main() {
    ll n;
    cin >> n;
    cout << ((n * (n - 1)) / 2) ;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// Manages Union-Find Forest.
class UnionFindForest {
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> size_;

 public:
  // Initialize forest.
  // parent_[i]=i, rank_[i]=0, size_[i]=1.
  UnionFindForest(const int &n);
  // Get the number of the root of the node q.
  int Root(const int &q);
  // Return true if the roots of x and y is same.
  bool IsSame(const int &x, const int &y);
  // Unite the tree x and tree y.
  void Unite(int x, int y);
  // Get the number of nodes which are the same group as node q.
  int Size(const int &q);
};
UnionFindForest::UnionFindForest(const int &n) {
  parent_.resize(n);
  rank_.resize(n);
  size_.resize(n);
  for (int i = 0; i < n; i++) {
    parent_[i] = i;
    rank_[i]   = 0;
    size_[i]   = 1;
  }
}
int UnionFindForest::Size(const int &q) {
  return size_[Root(q)];
}

int UnionFindForest::Root(const int &q) {
  if (parent_[q] == q) {
    return q;
  } else {
    return parent_[q] = Root(parent_[q]);
  }
}

bool UnionFindForest::IsSame(const int &x, const int &y) {
  return Root(x) == Root(y);
}

void UnionFindForest::Unite(int x, int y) {
  x = Root(x);
  y = Root(y);
  if (x == y) return;
  if (rank_[x] < rank_[y]) {
    parent_[x] = y;
    size_[y] += size_[x];
    size_[x] = 0;

  } else {
    parent_[y] = x;
    size_[x] += size_[y];
    size_[y] = 0;
    if (rank_[x] == rank_[y]) rank_[x]++;
  }
}

struct Queue {
  int a, b;
  Queue(int x, int y) {
    a = x;
    b = y;
  }
};

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t n, m;
  cin >> n >> m;
  UnionFindForest UFF(n + 1);
  std::vector<Queue> q;
  std::vector<int64_t> result;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    q.push_back(Queue(x, y));
  }
  int64_t answer = n * (n - 1) / 2;
  result.push_back(answer);
  for (int i = m - 1; i >= 0; i--) {
    int a = q[i].a;
    int b = q[i].b;
    // cout << a << " " << b << endl;
    if (UFF.IsSame(a, b)) {
      result.push_back(answer);
    } else {
      // cerr << UFF.Size(a) << "\t" << UFF.Size(b) << endl;
      answer -= UFF.Size(a) * UFF.Size(b);
      result.push_back(answer);
      UFF.Unite(a, b);
    }
  }

  for (int i = m - 1; i >= 0; i--) {
    cout << result[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }
};

//--global--//



//----------//

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    // int a = 114191;
    // rep(i, MAX){
    //     if(pow(i, 3) == a){
    //         cout << i << endl;
    //         return 0;
    //     }
    //     if(pow(i, 3) <= a){
    //         cout << pow(i, 3) << endl;
    //     }
    // }
    // return 0;

    ll n, k;
    cin >> n >> k;
    vector<ll> ki;
    vector<ll> gu;
    vector<ll> gu2;
    rep2(i, 1, n+1){
        if(i % k == 0){
            if(k % 2 == 0){
                gu.push_back(i);
            }
            else{
                ki.push_back(i);
            }
        }
        if(i % k == k / 2 && k % 2 == 0){
            gu2.push_back(i);
        }
    }

    // cout << ki.size() << endl;
    // cout << gu.size() << endl;
    // cout << gu2.size() << endl;

    if(k % 2 == 1)
        cout << ki.size() * ki.size() * ki.size() << endl;
    else 
        cout << gu.size() * gu.size() * gu.size() + gu2.size() * gu2.size() * gu2.size() << endl;
    
    
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

//used[j][i] : j分での最大値を達成するために，種類iの食べ物を使っているか？
// dp[i][j] : i種類目までの料理を見た時，j分以降での美味しさの最大値

int main() {
    int N, T; cin >> N >> T;
    P dish[N]; rep(i, N) cin >> dish[i].first >> dish[i].second;
    vector<vector<int>> dp0N(N + 10, vector<int>(T + 10, 0));
    rep(i, N) {
        rep(j, T) {
            dp0N[i + 1][j] = dp0N[i][j];
            if(dish[i].first <= j) {
                dp0N[i + 1][j] = max(dp0N[i][j], dp0N[i][j - dish[i].first] + dish[i].second);
            }
        }
    }
    vector<vector<int>> dpN0(N + 10, vector<int>(T + 10, 0));
    for(int i = N - 1; i >= 0; --i) {
        rep(j, T) {
            dpN0[i + 1][j] = dpN0[i + 2][j];
            if(dish[i].first <= j) {
                dpN0[i + 1][j] = max(dpN0[i + 2][j], dpN0[i + 2][j - dish[i].first] + dish[i].second);
            }
        }
    }
    int ans = max(dp0N[N][T - 1], dpN0[1][T - 1]);
    rep(i, N) {
        rep(j, T) {
            ans = max(ans, dp0N[i][j] + dpN0[i + 2][T - 1 - j] + dish[i].second);
            //dp0N[3][j] -> 0 -> 3までみたやつ
            //dpN0[3][j] -> N -> 3までみたやつ
        }
    }
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    string s1, s2;
    cin >> s1 >> s2;
    int n1 = s1.length(), n2 = s2.length();
    vector<vector<int>> sum1(n1, vector<int>(26, 0));
    vector<vector<int>> sum2(n2, vector<int>(26, 0));
    for (int i = 0; i < n1; i++)
    {
        if (i != 0)
        {
            for (int j = 0; j < 26; j++)
            {
                sum1[i][j] = sum1[i - 1][j];
            }
        }
        sum1[i][s1[i] - 'a']++;
    }
    for (int i = 0; i < n2; i++)
    {
        if (i != 0)
        {
            for (int j = 0; j < 26; j++)
            {
                sum2[i][j] = sum2[i - 1][j];
            }
        }
        sum2[i][s2[i] - 'a']++;
    }
    int res = 0;
    for (int len = min(n1, n2); len > 0; len--)
    {
        vector<ll> hash(n1 - len + 1);
        for (int i = 0; i < n1 - len + 1; i++)
        {
            ll tmp = 0;
            for (int k = 0; k < 26; k++)
            {
                tmp *= MOD;
                if (i == 0)
                {
                    tmp += sum1[i + len - 1][k];
                }
                else
                {
                    tmp += sum1[i + len - 1][k] - sum1[i - 1][k];
                }
            }
            hash[i] = tmp;
        }
        sort(hash.begin(), hash.end());
        for (int i = 0; i < n2 - len + 1; i++)
        {
            ll tmp = 0;
            for (int k = 0; k < 26; k++)
            {
                tmp *= MOD;
                if (i == 0)
                {
                    tmp += sum2[i + len - 1][k];
                }
                else
                {
                    tmp += sum2[i + len - 1][k] - sum2[i - 1][k];
                }
            }
            auto itr = lower_bound(hash.begin(), hash.end(), tmp);
            if (itr == hash.end())
                continue;
            if (*itr != tmp)
                continue;
            res = len;
            break;
        }
        if (res != 0)
            break;
    }
    cout << res << endl;
}



Measured memory_bytes: 3940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int r, d, x; cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		cout << r * x - d << endl;
		x = r * x - d;
	}
	cin >> x;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int unsigned long long int
signed main(){
    //int t;cin>>t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;cin>>s;
    int ans=0;
    for(char c:s){
        ans+=(c-'0');
    }
    if(ans%9==0)cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

ll n, m;

int main() {
  cin >> n >> m;
  vector<ll> a(n);
  rep (i, n) {
    cin >> a[i];
  }
  vector<P> bc(m);
  rep (i, m) {
    cin >> bc[i].second >> bc[i].first;
  }
  sort(a.begin(), a.end());
  sort(bc.rbegin(), bc.rend());
  ll bcind = 0;
  rep (i, n) {
    if (a[i] >= bc[bcind].first) break;
    a[i] = bc[bcind].first;
    bc[bcind].second--;
    if (bc[bcind].second == 0) bcind++;
    if (bcind == m) break;
  }
  ll ans = 0;
  rep (i, n) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n; cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	bool flag=1;
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			if(a[i]%3==0||a[i]%5==0){
				continue;
			}
			else{
				flag=0; 
				break;
			}
		}
	}
	if(flag) cout<<"APPROVED"<<'\n';
	else cout<<"DENIED"<<'\n';
	return 0;
}

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int a,b;
    cin>>b>>a;
    const int n = 100;
    string s[n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i<n/2) s[i] += ".";
            else s[i] += "#";
        }
    }
    a--,b--;
    cout << n << " " << n << "\n";
    for(int i=0;i<n/2;i+=2){
        for(int j=0;j<n;j+=2){
            if(a){
                s[i][j] = '#';
                a--;
            }
            if(b){
                s[n-i-1][j]='.';
                b--;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << s[i] <<"\n";
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;


int main(){
  int n,q,d[100000],x[1000];
  long long a[100000],t;
  scanf("%d %lld %d",&n,&t,&q);
  for(int i=0;i<n;i++) scanf("%lld %d",a+i,d+i);
  for(int i=0;i<q;i++){
    scanf("%d",x+i);
    x[i]--;
  }
  vector<long long> v;
  for(int i=0;i<n-1;i++){
    if(d[i]==1&&d[i+1]==2){
      v.push_back((a[i]+a[i+1])/2);
    }
  }
  for(int i=0;i<q;i++){
    int id = x[i];
    long long to;
    if(d[id]==1){
      if(upper_bound(v.begin(),v.end(),a[id])!=v.end()){
        to = *upper_bound(v.begin(),v.end(),a[id]);
        if(to-a[id]<t){
          printf("%lld\n",to);
          continue;
        }
      }
      to = a[id]+t;
    }else if(d[id]==2){
      if(lower_bound(v.begin(),v.end(),a[id])!=v.begin()){
        to = *(lower_bound(v.begin(),v.end(),a[id])-1);
        if(a[id]-to<t){
          printf("%lld\n",to);
          continue;
        }
      }
      to = a[id]-t;
    }
    printf("%lld\n",to);
  }
  return 0;
}

Measured memory_bytes: 3936
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            
            int w = sc.nextInt();
            int h = sc.nextInt();
            int[][] field = new int[h][w];
            
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                field[y-1][x-1] = 1;
            }
            
            int s = sc.nextInt();
            int t = sc.nextInt();
            
            int ans = 0;
            for (int i = 0; i <= h - t; i++) {
                for (int j = 0; j <= w - s; j++) {
                    int tmp = 0;
                    for (int k = 0; k < t; k++) {
                        for (int l = 0; l < s; l++) {
                            tmp += field[i+k][j+l];
                        }
                    }
                    ans = Math.max(ans, tmp);
                }
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 34132
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<stw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;

int main(void){
    string str;
    cin >> str;
    if(str[0]==str[1]&&str[1]==str[2]){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		if s == "Y" {
			fmt.Println("Four")
			return
		}
	}
	fmt.Println("Three")
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rt return
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n,k;
struct info
{
    int x,v;
}a[maxn];
bool cmp(info one,info two)
{
    return one.v>two.v;
}
int vis[maxn];
stack<int> s;
int main()
{
    scanf("%d %d",&n,&k);
    repd(i,1,n)
    {
        scanf("%d %d",&a[i].x,&a[i].v);
    }
    sort(a+1,a+1+n,cmp);
    ll cnt=0;
    ll tp=0;
    ll res=0;
    ll ans=0ll;
    repd(i,1,n)
    {
        if(cnt<k)
        {
                if(vis[a[i].x]==0)
                {
                    vis[a[i].x]=1;
                    tp++;
                }else
                {
                    s.push(a[i].v);
                }
                res+=a[i].v;
                cnt++;
                ans=max(ans,res+1ll*tp*tp);
        }
        else{
            if(s.empty())
                break;
            if(vis[a[i].x])
                continue;
            vis[a[i].x]=1;
            tp++;
            res-=s.top();
            res+=a[i].v;
            s.pop();
            ans=max(ans,res+tp*tp);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	ll A,B,C,K;
	cin>>A>>B>>C>>K;


	if(A >= K){
		cout<<K<<endl;
	}
	else if(A + B >= K){
		cout<<A<<endl;
	}
	else{
		ll nokori = K - A - B;
		cout<<A - nokori<<endl;
	}




	return 0;
}



Measured memory_bytes: 3596
#include <iostream>

using namespace std;

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

	if (D == 25) {
		cout << "Christmas" << endl;
	}
	else if (D == 24) {
		cout << "Christmas Eve" << endl;
	}
	else if (D == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (D == 22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}

	

}





Measured memory_bytes: 3628