akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mo 1000000007
#define mems(a,x) memset(a,x,sizeof(a))
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}

ll size[100005];
ll parent[100005];


int find_set(int v) {
    if (v == parent[v])
        return v;
    return find_set(parent[v]);
}

void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}


int main() 
{ 
	ll n,m;
	cin>>n>>m;
	vector<pair<ll,ll>>v;
	for(int i=1;i<=n;i++)
		make_set(i);
	for(int i=0;i<m;i++)
	{
		ll a,b;
		cin>>a>>b;
		v.push_back(make_pair(a,b));
	}
	ll ans=n*(n-1)/2;
	//cout<<ans<<endl;
	ll as[m+1];
	as[m]=ans;
	for(int i=m-1;i>0;i--)
	{
		ll a,b;

		a=v[i].fi;
		b=v[i].se;
		ll p1,p2;
		if(find_set(a)!=find_set(b))
		{
			p1=find_set(a);
			p2=find_set(b);
			p1=size[p1];
			p2=size[p2];
			ll t=p1+p2;
			ans=ans+(p1*(p1-1)/2)+(p2*(p2-1)/2)-(t*(t-1)/2);
			union_sets(a,b);
		}
		as[i]=ans;



	}
	for(int i=1;i<=m;i++)
		cout<<as[i]<<endl;

} 

Measured memory_bytes: 5360
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>

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

Node *root = nullptr, *NIL = nullptr;

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

    //z = (Node*)malloc(sizeof(Node));
    z = new Node();
    z->key = k;
    z->left = NIL;
    z->right = NIL;

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

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

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

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

int main() {
    int n,i,x;
    std::string com;

    scanf("%d", &n);
    for (int i=0; i <n; i++) {
        std::cin >> com;
        if (com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 26732
#include<stdio.h>

int main(){
  int i;
  int m[]={6000,4000,3000,2000};
  int ans[4]={};
  int num;
  int n;

  for(i=0;i<4;i++){
    scanf("%d %d",&num,&n);
    ans[i]=m[num-1]*n;
  }

  for(i=0;i<4;i++)
    printf("%d\n",ans[i]);

  return 0;
}

Measured memory_bytes: 600
// can i beat Mod Love?
#include<bits/stdc++.h>

using namespace std;
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define eps 1e-8
typedef long long ll;
const double PI = acos(-1.0);
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
constexpr int maxn = 1e6+100;
int main(){
    close;
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0, tp = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            tp++;
        }else {
            ans = max(ans , tp);
            tp = 0;
        }
    }
    ans = max(ans , tp);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3584
#! /usr/bin/env python
import sys

CHECK_STRING = 'keyence'

def main():
  line = sys.stdin.readline().strip()

  CheckKeys = list(CHECK_STRING)
  checkChar = CheckKeys.pop(0)

  missIndex = 0
  for i in list(line):
    if i == checkChar:
      if len(CheckKeys) != 0:
        checkChar = CheckKeys.pop(0)
      else:
        print('YES')
        return
    else:
      break
    missIndex += 1

  restString = CHECK_STRING[missIndex:]
  checkRestString = line[missIndex:]

  index = -1
  completed = True
  while len(restString) >= abs(index):
    r = restString[index]
    c = checkRestString[index]
    if r != c:
      completed = False
      break
    index -= 1

  if completed:
    print('YES')
  else:
    print('NO')


main()



Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int H,W,word_num,loc[128];
char map[50][51],word_table[8];
bool isOK;


void recursive(int work[8],int count){

	if(isOK)return;

	if(count == word_num){

		bool FLG = true;
		int most_left,most_right,most_top,most_bottom,rank;
		char ch;

		for(int i = 0; i < word_num; i++){
			ch = word_table[i];
			rank = work[i];

			most_left = 51,most_right = -1,most_top = 51,most_bottom = -1;

			for(int row = 0; row < H; row++){
				for(int col = 0; col < W; col++){
					if(map[row][col] == ch){
						most_left = min(most_left,col);
						most_right = max(most_right,col);
						most_top = min(most_top,row);
						most_bottom = max(most_bottom,row);
					}
				}
			}

			for(int row = most_top; row <= most_bottom; row++){
				for(int col = most_left; col <= most_right; col++){
					if(map[row][col] != ch){
						if(rank > work[loc[map[row][col]-'0']]){
							FLG = false;
							break;
						}
					}
				}
				if(!FLG)break;
			}
		}

		if(FLG)isOK = true;

		return;
	}

	for(int i = 0; i < word_num; i++){
		if(work[i] == -1){
			int next_work[8];
			for(int k = 0; k < 8; k++)next_work[k] = work[k];
			next_work[i] = count;

			recursive(next_work,count+1);
		}
	}
}



void func(){

	for(int i = 0; i < 128; i++)loc[i] = -1;
	word_num = 0;

	scanf("%d %d",&H,&W);
	for(int i = 0; i < H; i++){
		scanf("%s",map[i]);
		for(int k = 0; k < W; k++){
			if(map[i][k] != '.'){
				if(loc[map[i][k]-'0'] == -1){ //????????´?????´???
					loc[map[i][k]-'0'] = word_num;
					word_table[word_num] = map[i][k];
					word_num++;
				}
			}
		}
	}

	bool FLG = true;
	int most_left,most_right,most_top,most_bottom;
	char ch;

	for(int i = 0; i < word_num; i++){
		ch = word_table[i];

		most_left = 51,most_right = -1,most_top = 51,most_bottom = -1;

		for(int row = 0; row < H; row++){
			for(int col = 0; col < W; col++){
				if(map[row][col] == ch){
					most_left = min(most_left,col);
					most_right = max(most_right,col);
					most_top = min(most_top,row);
					most_bottom = max(most_bottom,row);
				}
			}
		}

		for(int row = most_top; row <= most_bottom; row++){
			for(int col = most_left; col <= most_right; col++){
				if(map[row][col] == '.'){
					FLG = false;
					break;
				}
			}
			if(!FLG)break;
		}
	}

	if(!FLG){
		printf("SUSPICIOUS\n");
		return;
	}

	isOK = false;
	int work[8];

	for(int i = 0; i < word_num; i++)work[i] = -1;

	recursive(work,0);

	if(isOK){
		printf("SAFE\n");
	}else{
		printf("SUSPICIOUS\n");
	}
}


int main(){

	int num;
	scanf("%d",&num);

	for(int i = 0; i < num; i++)func();

	return 0;
}

Measured memory_bytes: 3080
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
MOD = 10 ** 9 + 7
corrct = []
t = N - 1
for i in range(N):
    corrct.append(t)
    if i % 2 == 1:
        t -= 2

if all(corrct[i] == A[i] for i in range(N)):
    print(pow(2, N//2, MOD))
else:
    print(0)


Measured memory_bytes: 56044
N, M = map(int, input().split())
tmp = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
L = []
ans = 0
for i in tmp:
    c = 0
    for j in range(1, i[0] + 1):
        c += 2 ** (i[j] - 1)
    L.append(c)

for i in range(2 ** N):
    for j in range(M):
        if not p[j] == bin(L[j] & i).count("1") % 2:
            break
    else:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

	//累積和[0, i)
	vector<ll> sum;

	CumulativeSum(vector<ll>& A)
	{
		sum.resize(A.size() + 1);

		rep(i, A.size())
		{
			sum[i + 1] = sum[i] + A[i];
		}
	};

	ll getvalue(int l, int r)
	{
		//[l, r)
		return sum[r] - sum[l];
	}
};

map<ll, int> cnt;

int main() {

	int N;
	cin >> N;

	vector<ll> A(N);

	rep(i, N) cin >> A[i];

	//累積和を使用して連続部分列をカウント。
	//ただし、左端・右端両方を動かすと問題全体でO(N^2)となる。
	//
	//よって、左端を0に固定して、右端のみを動かして計算する。
	//
	//[0, i)の累積和をS(i)としたとき、[l, r)の累積和S(l, r)は
	//
	//S(l, r) := S(r) - S(l)
	//
	//と表すことができる。右端rを固定したとき、題意を満たすlは
	//
	//0 = S(l, r) = S(r) - S(l)
	//
	//S(l) = S(r)・・・(1)
	//
	//となる。よって、右端rを0からNまで動かしながら、
	//(1)を満たすlの個数を合計していけばよい。
	//
	//rを動かすごとに[0, r)の値がわかるので、その個数を毎回mapに保存しておけば、
	//lの検索をO(logN)程度で計算できて、問題全体はO(NlogN)となる。

	CumulativeSum cs(A);

	ll ans = 0;

	rep(i, N + 1)
	{
		ans += cnt[cs.getvalue(0, i)];
		cnt[cs.getvalue(0, i)]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>

 int main(void) {
 int k, a, b;
 scanf("%d", &k);
 scanf("%d%d", &a, &b);

 int largest = (b / k) * k;
 if (a <= largest) {
 	puts("OK");
 } 
   else {
 puts("NG");
}

 return 0;
 }


Measured memory_bytes: 1640
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>
#include <vector>
#include<cstdio>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const ll mod = 1000000007;
const double eps = 1e-10;
const int MAX = 200000;

int main() {
	int n;
  double a;
	cin >> n;
  if(n % 2) {
    a =  (double) ((n / 2) + 1) / (double)n;
  } else {
    a = 1.0 / 2.0;
  }

	cout << setprecision(7) << a << endl;
  return 0;
}

Measured memory_bytes: 256
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
][int(input())-1])

Measured memory_bytes: 38384
import math

def primes(x):
    if x<2: return []
    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes[:int(math.sqrt(x))+1]:
        if prime > 0:
            for not_prime in range( 2*prime, x, prime ): primes[not_prime] = 0

    return [prime for prime in primes if prime != 0]



while True:
    n = input()

    if n <= 0: break

    primelist = primes(n)

    print (len([prime for prime in primelist if (n-prime in primelist)])+1)/2

Measured memory_bytes: 7844
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    string s;
    cin>>s;
    if(s[sz(s)-1]=='s')cout<<s<<"es";
    else cout<<s<<"s";
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

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

using ll=long long;
using P=pair<int, int>;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

int main(){
    int N; cin >> N;
    vector<int> x(N), y(N);
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
    }
    vector<vector<double>> dist(N, vector<double>(N));
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            dist[i][j]=sqrt(pow(x[i]-x[j], 2)+pow(y[i]-y[j], 2));
        }
    }
    vector<int> order(N);
    for(int i=0; i<N; i++) order[i]=i;
    double mean=0;
    int num=1;
    for(int i=1; i<=N; i++) num*=i;
    do{
        double total=0;
        for(int i=0; i<N-1; i++){
            total+=dist[order[i]][order[i+1]];
        }
        mean+=total/num;
    }while(next_permutation(order.begin(), order.end()));
    printf("%.7f\n",mean);
    return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/agc035/tasks/agc035_a
    //A - XOR Circle
    //a,b,a^b でならぶので、a,b,a^bの3種
    #include <bits/stdc++.h>
    using namespace std;
    using ll=int64_t;
    #define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
    #define REP(i,n)  FOR(i,0,n)
    int main() {
        ll N; cin>>N;
        vector<ll> an(N);
        unordered_map<ll,ll> vnum;
        for(auto&& a:an){
            cin>>a;
            ++vnum[a];
        }
        bool ret=false;
        //全0
        if(vnum.size()==1&&vnum.begin()->first==0){
            ret=true;
        }
        //0一つ、x,x,0
        if(N%3==0&&vnum.size()==2&&vnum.count(0)&&vnum[0]==N/3){
            ret=true;
        }
        //3つ違う a,b,c
        if(N%3==0&&vnum.size()==3){
            ll x=0;
            bool ret3=true;
            for(auto& d:vnum){
                x^=d.first;
                if(d.second!=N/3){
                    ret3=false;
                }
            }
            if(x!=0) ret3=false;
            ret|=ret3;
        }
#if 0
        ll tmp=an[i]
        ll ans=an[0];
        FOR(i,1,N){
            ans ^= an[i];
        }
#endif
        cout<<(ret?"Yes":"No")<<endl;
        return 0;
    }

Measured memory_bytes: 4260
#include<bits/stdc++.h>
#define N 500005
using namespace std;
int head[N],s[N],a[N],n,x,kk;
struct Tree{int nxt,to;}e[N];
inline void link(int x,int y){e[++kk].nxt=head[x];e[kk].to=y;head[x]=kk;}
void dfs(int u){
    int top=0;if (!head[u]) return; 
    for (int i=head[u];i;i=e[i].nxt){
        int v=e[i].to;
        dfs(v); 
    }
    for (int i=head[u];i;i=e[i].nxt){
    	int v=e[i].to;
    	s[++top]=a[v];
	}
    sort(s+1,s+top+1);
    for (int i=2;i<=top;i++)
        if (s[i]<=s[i-1]) s[i]=s[i-1]+1;
    a[u]=s[top]+1;
}
int main(){
    scanf("%d",&n);
    for (int i=2;i<=n;i++) scanf("%d",&x),link(x,i);
    dfs(1);printf("%d\n",a[1]);
    return 0;
}

Measured memory_bytes: 12032
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}


int main() {
	int n;
	cin >> n;
	vector<int> a;
	REP(i, n) {
		int x;
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	bool p = true;
	ll sum0 = 0, sum1 = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (p) {
			sum0 += a[i];
			p = false;
		}
		else {
			sum1 += a[i];
			p = true;
		}
	}
	cout << sum0 - sum1 << endl;
}



Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = 0;
        int x = 0;
        int y = 0;

        for(int i=0; i<n; i++){
            int memo_t = sc.nextInt();
            int memo_x = sc.nextInt();
            int memo_y = sc.nextInt();

            int d = memo_t - t;
            int dist = Math.abs(memo_x - x) + Math.abs(memo_y -y);
            if((d < dist) || ((dist - d)%2 != 0)){
                System.out.println("No");
                return;
            }
            t = memo_t;
            x = memo_x;
            y = memo_y;
        }
        System.out.println("Yes");
    }
}


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

int main(){
  int num_total = 0;
  int num_1yen = 0;
  char buf[16] = { 0 };
  char buf2[16] = { 0 };
  fgets(buf, sizeof(buf), stdin);
  fgets(buf2, sizeof(buf2), stdin);
  
  num_total = atoi(buf);
  num_1yen = atoi(buf2);
  
  int amari = num_total % 500;
  if(amari <= num_1yen) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

loop = [0]
town = 0
visited = defaultdict(lambda: None)
visited[town] = 0

period = 0
for i in range(1, k+1):
    town = a[town]
    if visited[town] != None:
        offset = visited[town]
        period = i - offset 
        break
    else:
        loop.append(town)
        visited[town] = i

if period == 0:
    print(town+1)
else:
    print(loop[offset+((k-offset)%period)]+1)

Measured memory_bytes: 32704
import bisect

A, B, Q = map(int, input().split())  # 複数数値入力
S = [0] * A
T = [0] * B
X = [0] * Q
for i in range(A):
    S[i] = int(input())
for i in range(B):
    T[i] = int(input())
for i in range(Q):
    X[i] = int(input())

S.insert(0, -float("inf"))
S.append(float("inf"))
T.insert(0, -float("inf"))
T.append(float("inf"))

for i in range(Q):
    b = bisect.bisect_right(S, X[i])
    d = bisect.bisect_right(T, X[i])
    res = float("inf")
    for s in [S[b - 1], S[b]]:
        for t in [T[d - 1], T[d]]:
            d1 = abs(s - X[i]) + abs(t - s)  # 先に神社
            d2 = abs(t - X[i]) + abs(t - s)  # 先に寺
            res = min(res, d1, d2)

    print(res)


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

using namespace std;
#define ll long long

bool get(ll n, ll i) {
    if (i == 1) return 0;
    while (n % i == 0)n /= i;
    if (n == 1) return 1;
    return (n - 1) % i == 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    int ans = 0;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i)continue;
        ans += get(n, i);
        if (i * i != n) ans += get(n, n / i);
    }
    for (ll i = 1; i * i <= (n - 1); i++) {
        if ((n - 1) % i == 0 && n % i != 0) ans++;
        if (i * i == (n - 1)) continue;
        if ((n % ((n - 1) / i)) != 0 && ((n - 1) % ((n - 1) / i)) == 0)ans++;
    }
    cout << ans << endl;
    return 0;
}

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

char s[101010];

int a[101010];

int main()
{
	scanf("%s", s);
	int k;
	scanf("%d", &k);
	int len = strlen(s);
	
	int n = 0;
	for(int i = 0; i < len; i++)
	{
		if(i == 0 || s[i] != s[i-1])
		{
			n++;
			a[n] = 1;
		}
		else
			a[n]++;
	}
	if(n == 1)
	{
		printf("%lld\n", 1ll * len * k / 2);
		return 0; 
	}
	int sum = 0;
	for(int i = 2; i < n; i++)
		sum += a[i]/2;
	if(s[0] != s[len - 1])
		sum += a[1]/2 + a[n]/2;
	else
		sum += (a[1] + a[n])/2;
	printf("%lld\n", 1ll * sum * k - (s[0] == s[len - 1]) * ((a[1] + a[n])/2 - a[1]/2 - a[n]/2));
	return 0;
}

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  int p[a], q[b], r[c];
  for (int i = 0; i < a; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> q[i];
  }
  for (int i = 0; i < c; i++) {
    cin >> r[i];
  }
  sort(p, p + a);
  reverse(p, p + a);
  sort(q, q + b);
  reverse(q, q + b);
  sort(r, r + c);
  reverse(r, r + c);
  vector <int> pp;
  for (int i = 0; i < x; i++) {
    pp.emplace_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    pp.emplace_back(q[i]);
  }
  sort(pp.begin(), pp.end());
  for (int i = 0; i < c; i++) {
    if (r[i] > pp[i]) {
      pp[i] = r[i];
    } else {
      break;
    }
  }
  ll ans = 0;
  for (int i = 0; i < x + y; i++) {
    ans += pp[i];
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
char a[1005][1005];
int h,w;
typedef struct point{
	int x,y;
	int d;
}p;
int main(){
	scanf("%d%d",&h,&w);
	getchar();
	queue<p> q;
	for(int i = 0; i < h;i++){
		for(int j = 0; j < w; j++){
			scanf("%c",&a[i][j]);
			if(a[i][j] == '#'){
				p s;
				s.d = 0;
				s.x = i;
				s.y = j;
				q.push(s);
			}
		}
		getchar();
	}
	int maxn = 0;
	while(!q.empty()){
		p t;
		int tx,ty;
		t = q.front();
		q.pop();
		if(t.x>0){
			tx = t.x-1;
			ty = t.y;
			if(a[tx][ty] == '.'){
				p s;
				s.x = tx;
				s.y = ty;
				s.d = t.d+1;
				maxn = max(maxn,s.d);
				q.push(s);
				a[tx][ty] = '#';
			}
		}
		if(t.y>0){
			tx = t.x;
			ty = t.y-1;
			if(a[tx][ty] == '.'){
				p s;
				s.x = tx;
				s.y = ty;
				s.d = t.d+1;
				maxn = max(maxn,s.d);
				q.push(s);
				a[tx][ty] = '#';
			}
		}
		if(t.x<h-1){
			tx = t.x+1;
			ty = t.y;
			if(a[tx][ty] == '.'){
				p s;
				s.x = tx;
				s.y = ty;
				s.d = t.d+1;
				maxn = max(maxn,s.d);
				q.push(s);
				a[tx][ty] = '#';
			}
		}
		if(t.y<w-1){
			tx = t.x;
			ty = t.y+1;
			if(a[tx][ty] == '.'){
				p s;
				s.x = tx;
				s.y = ty;
				s.d = t.d+1;
				maxn = max(maxn,s.d);
				q.push(s);
				a[tx][ty] = '#';
			}
		}
	}
	printf("%d\n",maxn);
	return 0;
}

Measured memory_bytes: 13328
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

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

int X, Y, A, B, C;
vector<PI> V;
int main(void){
    cin >> X >> Y >> A >> B >> C;
    int val;
    REP(i,A) {
        cin >> val;
        V.push_back(PI(val, 0));
    }
    REP(i,B) {
        cin >> val;
        V.push_back(PI(val, 1));
    }
    REP(i,C) {
        cin >> val;
        V.push_back(PI(val, 2));
    }
    sort(V.begin(), V.end(), greater<PI>());

    int count=0;
    ll res = 0;
    int i=0;
    int R = 0;
    int G = 0;
    while(count < X+Y){
        PI p = V[i++];
        if(p.second==0){
            if(R >= X) continue;
            R++;
        }
        if(p.second==1){
            if(G >= Y) continue;
            G++;
        }
        //cout << p.first << " " << p.second << endl;
        res += p.first;
        count++;
    }
    cout << res << endl;
    return 0;
}



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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

void solve(std::string S, std::string T) {
  int ans = 0;
  for(int i = 0 ; i < 3 ; i++){
    ans += S[i] == T[i];
  }
  cout << ans << endl;

}

int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
  return 0;
}


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

using namespace std;

typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
    ll a,b,c,k; cin >> a >> b >> c >> k;
    ll diff = a - b;
    if(k%2==0) cout << diff;
    else cout << -diff;
    return 0;
}







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

int main (){
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;

  if ((x - r) >= 0 && (x + r) <= w && (y - r) >= 0 && (y + r) <= h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}



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

using namespace std;

void solve() {
    int N, X, T;
    cin >> N >> X >> T;
    if (N%X == 0)
    {
        cout << T * N / X << endl;
    }
    else
    {
        cout << T * (N / X + 1) << endl;
    }
    
    
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a); (i)<=(b); (i)++)
#define REP(i,N) FOR((i), 0, (N)-1)
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}

int f(int n){
    return (n % 2 == 0) ? (n/2) : (3*n+1) ;
}

int main(){
    int s , cnt = 1;
    cin >> s;
    while(true){
        if(s == 4 || s == 2 || s == 1) break;
        s = f(s);
        cnt++;
    }
    cout << cnt+3 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
a = sorted(list(set(a)))
from fractions import gcd
lc = a[0]
if n != 1:
  for num,i in enumerate(a[1:]):
    if lc == 0:
      break
    lc = lc * i // gcd(lc, i)
    if gcd(lc, i) == min(i,lc):
      for j in a[:num+1]:
        if (i/j)%2 == 0:
          lc = 0
          break 
if lc == 0:
  print(0)
else:
  print((m+lc//2)//lc)


Measured memory_bytes: 15012
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	char c;
	cin >> c;
	c++;
	cout << c;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int A[100];
int main()
{
	int N,i;
	cin >> N;
	for(i=0;i<N;i++)
		cin >> A[i];
	int flag=1,j,t,count=0;
	while(flag)
	{
		flag=0;
		for(j=1;j<N;j++)
		{
			if(A[j]<A[j-1])
			{
				t=A[j];
				A[j]=A[j-1];
				A[j-1]=t;
				flag=1;
				count++;
			}
		}
	}
	for(i=0;i<N;i++)
	{
		if(i>0)
			cout <<" ";
		cout << A[i];
	} 
	cout<<endl;
	cout<<count<<endl;
	return 0;
} 


Measured memory_bytes: 3100
#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];
  
  int cur = 1;
  int broken_block = 0;
  for(int i = 0; i < N; i++){
    if(a[i] == cur) cur++;
    else broken_block++;
  }
  
  if(cur == 1) cout << -1 << endl;
  else cout << broken_block << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>
#include <string>

using namespace std;

const double PI = 3.14159265358979;

int dp[1001][1001];

void lcs(string x, string y) {

	for (int i = 0; i < x.length(); i++) {
		dp[i][0] = 0;
	}
	for (int i = 0; i < y.length(); i++) {
		dp[0][i] = 0;
	}

	for (int i = 1; i <= x.length(); i++) {
		for (int j = 1; j <= y.length(); j++) {

			if (x[i-1] == y[j-1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
				dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
		}
	}
}


int main() {

	int n; cin >> n;

	for (int i = 0; i < n; i++)	{
		string big, small;
		cin >> big >> small;
		
		lcs(big, small);
		int res = dp[big.length()][small.length()];
		cout << res << endl;
	}
	

	return 0;
}



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

int main() {
    string s;
    cin >> s;
    int i = 0;
    for (char x: s){
        if (x == '+'){
            i++;
        } else {
            i--;
        }
    }
	cout << i << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
int main() {
	int ans=0;
	llong min_num, max_num;
	cin >> min_num >> max_num;
	while (min_num <= max_num) {
		ans++;
		min_num *= 2;
	}
	cout << ans << endl;
	return 0;
}

	

Measured memory_bytes: 256
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].fe << " " << v[i].se << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void PP(int n) { cout << n << " ";}
inline void PP(int n, int m) { cout << n << " " << m << endl;}
inline void PP(int n, int m, int q) {  cout << n << " " << m << " " << q << endl;}
inline void PP(int n, int m, int q, int u) {  cout << n << " " << m << " " << q << " " << u << endl;}
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <=================================================================================================================================
// <=================================================================================================================================




signed  main() {
    //op();
    lets_go
    int i, j, x, y, u, l;
    //int t; cin >> t; while (t--)
    {
        i = j = x = y = u = l = 0;

        string a, b;
        cin >> a >> b;
        for(i = 0; i < a.size(); i++){
            if(a[i] != b[i])
                x++;
        }
        PT(x);


        /* */

    }
    return 0;

}


Measured memory_bytes: 3820
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

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

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};

const double EPS = 1e-9;

double dot(point a,point b){
    return real(conj(a)*b);
}

double cross(point a,point b){
    return imag(conj(a)*b);
}

// 直線と点との距離
// みけんしょう
double dist_line_and_point(point a1,point a2,point b){
    return abs(cross(a2-a1,b-a1)) / abs(a2-a1);
}

// 線分と点との距離
// みけんしょう
double dist_linesegment_and_point(point a1,point a2,point b){
    if(dot(a2-a1,b-a1) < EPS) return abs(b-a1);
    if(dot(a1-a2,b-a2) < EPS) return abs(b-a2);
    return dist_line_and_point(a1,a2,b);
}


// 円と線分の交差判定
bool is_cross_linesegment_and_circle(point c,double r,point a1,point a2){
    return (dist_linesegment_and_point(a1,a2,c) < r+EPS and
             (r < abs(c-a1) + EPS or r < abs(c-a2) + EPS));
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<pair<point,double> > cs;
        for(int i=0;i<n;i++){
            point p;double c;
            cin >> p.real() >> p.imag() >> c;
            cs.push_back(make_pair(p,c));
        }
        int m;
        cin >> m;
        for(int i=0;i<m;i++){
            point a,b;
            cin >> a.real() >> a.imag() >> b.real() >> b.imag();
            bool safe = false;
            for(int j=0;j<n;j++){
                if(is_cross_linesegment_and_circle(cs[j].first,cs[j].second,a,b)){
                    safe = true;
                }
            }
            if(safe){
                cout << "Safe" << endl;
            }else{
                cout << "Danger" << endl;
            }
        }
    }
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	int cnt = 0;
	rep(i,n)if(a[i]%2==1)cnt ++ ;
	if(cnt%2==1)
	{
		cout<<"NO"<<endl;
	}
	else
	{
		cout<<"YES"<<endl;
	}

	
	return 0;
}

Measured memory_bytes: 640
#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.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(i%2) ans -= a.at(i);
    else ans += a.at(i);
  }
  
  cout << ans << endl;
}

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

int main()
{
    char str[1000];  scanf("%s",str);
    int q,cnt=0;          scanf("%d",&q);
    
    while(cnt<q){
        char order[1000];
        scanf("%s",order);
        if(strcmp(order,"replace")==0){
            int a,b,i;    scanf("%d%d",&a,&b);
            char x[100];  scanf("%s",x);
            for(i=a;i<=b;i++)
                str[i]=x[i-a];
        }
        if(strcmp(order,"reverse")==0){
            int a,b,i;    scanf("%d%d",&a,&b);
            char cpy[1000];
            strcpy(cpy,str);
            for(i=a;i<=b;i++)
                str[i]=cpy[a+b-i];
        }
        
        if(strcmp(order,"print")==0){
            int a,b,i;    scanf("%d%d",&a,&b);
            for(i=a;i<=b;i++){
                printf("%c",str[i]);
            }
            printf("\n");
        }
        cnt++;
    }
    return 0;
}



Measured memory_bytes: 2140
N = int(input())
h = list(map(int,input().split()))

def c(a,b): # b exclusive
  
  if b-a==1:
    return h[a]
  if b==a:
    return 0
  
  try:
    s = h.index(0,a,b)
  except ValueError:
    s = -1
  if s>=0:
    return c(a,s) + c(s+1,b)
  # no zeros
  m = min(h[a:b])
  for i in range(a,b):
    if h[i] == m:
      index = i
    h[i] -= m
  
  return m + c(a,index) + c(index+1,b)

print(c(0,N))

Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())

ans = 10 ** 9
i = 1
while i * i <= n:
    if n % i == 0:
        ans = min(ans, max(len(str(i)), len(str(n // i))))
    i += 1
print(ans)

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

int main(){
	int K;cin >> K;
	int N,M;cin >> N >> M;

	for(int i=N;i<=M;i++){
		if(i%K==0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout<< "NG" << endl;	
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
//Angle*M_PI/180
int a,b,h,m;
int main(){
	cin>>a>>b>>h>>m;
	int ms=h*60+m;
	double ha=360.0/12/60*ms;//时钟当前所在的角度 
	double ma=360.0/60*m;//分钟当前所在的角度
	double x=abs(ha-ma);
	if(x>180) x=360-x;
	double ans=sqrt(a*a+b*b-2.0*a*b*cos(x*1.0*M_PI/180));
	cout<<fixed<<setprecision(20)<<ans; 
	return 0;
}


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

int main(){
    ll n, t;
    cin >> n >> t;
    vector<ll> osu(n);
    for(int i = 0; i < n; i++){
        cin >> osu[i];
    }
    ll ans = 0;
    for(int i = 0; i < n - 1; i++){
        ans += min(t, osu[i + 1] - osu[i]);
    }
    cout << ans + t << endl;
}

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

using namespace std;

int main() {
    // Input
    int N;
    vector<int> A;
    
    cin >> N;
    A = vector<int>(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    // Process
    bool ans = true;
    for (int n : A){
        if (n % 2 == 0){
            if ((n % 3 > 0) && (n % 5 > 0)){
                ans = false;
                break;
            }
        }
    }

    // Output
    cout << (ans ? "APPROVED" : "DENIED") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

int main() {
    string S;
    cin >> S;
    ll ans = S.size() + 1;
    for(ll init = 0; init <= 1; init++) {
        ll tmp = 0;
        for(ll i = 0; i < S.size(); i++) {
            char c = '0' + (i + init) % 2;
            tmp += (c != S[i]);
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  vint check(s.size()+1,-1);
  rep(i,s.size()){
    if(i == 0){
      if(s[i] == '<') check[i] = 0;
    }
    else if(i == s.size()-1){
      if(s[i] == '>') check[i+1] = 0;
    }
    if(s[i] == '>' && s[i+1] == '<'){
      check[i+1] = 0;
    }
  }
  rep(i,check.size()){
    if(check[i] == 0){
      int left = 1;
      int right = 0;
      while(i-left >= 0){
        if(s[i-left] == '>'){
          if(check[i-left] == -1)
            check[i-left] = check[i] + left;
          else if(check[i-left] != 0 && check[i-left] < check[i] + left)
            check[i-left] = check[i] + left;
        }
        else break;
        left++;
      }
      while(i+right < check.size()){
        if(s[i+right] == '<'){
          if(check[i+right] == -1)
            check[i+right+1] = check[i] + right + 1;
          else if(check[i+right+1] != 0 && check[i+right] < check[i] + right + 1)
            check[i+right + 1] = check[i] + right + 1;
        }
        else break;
        right++;
      }
    }
  }
  ll ans = 0;
  rep(i,check.size()){
    ans += check[i];
    //cout << check[i];
  }
  //cout << endl;
  if(s != ">")
    cout << ans << endl;
  else
    cout << 1 << endl;
}


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

#define int long long
#define MOD ((int)1e9+7)

signed  main(){
  stack<int> sta, sta2;
  string s;
  int a = 0, b = 0, r;

  cin>>s>>r;

  //sta.push(s[0] - '0');
  
  for(int i = 0; i < s.size(); i++){//cout<<i<<endl;
    if(s[i] == '+'){//cout<<"+"<<endl;
      sta.push(-1);
    } else if(s[i] == '*'){//cout<<"-"<<endl;
      sta.push(-2);
    } else{
         int temp3 = s[i] - '0';
      if(sta.size() == 0){
	sta.push(temp3);
      } else {
      int temp = sta.top(), temp2;//sta.pop();
      if(temp == -1) {
	sta.pop();
	temp2 = sta.top();sta.pop();
	sta.push(temp2 + temp3);
      } else if(temp == -2){
	sta.pop();
	temp2 = sta.top(); sta.pop();
	sta.push(temp2*temp3);
      } else {
	sta.push(temp3);
	
      }
      }
      //  cout<<sta.top()<<endl;
    }
  }
  
  for(int i = 1; sta.size(); i++){
    b += sta.top(); sta.pop();
  }
  
    
  for(int i = 0; i < s.size(); i++){//cout<<i<<" <-i "<<endl;
    if(s[i] == '+'){//cout<<"+"<<endl;
      // sta.push(-1);
    } else if(s[i] == '*'){//cout<<"-"<<endl;
       sta2.push(-2);
    } else{
      // cout<<"<><><><><><><   "<<endl;
      if(sta2.size() == 0){
	//cout<<"fhdsjklfhdsjlkfhsjflkdshf SIZE -->"<<sta2.size()<<" "<<s[i]-'0'<<endl; 
	sta2.push(s[i] - '0');
      }else {
	//cout<<"[][][][][][][][][][][][][][][][]["<<" "<<sta2.size()<<endl;
		int temp = sta2.top();
	if(temp == -2){
	  sta2.pop();
	  int temp2 = sta2.top(); sta2.pop();
	  //cout<<temp2<<" *  "<<s[i]-'0'<<endl;
	  sta2.push((s[i]-'0')*temp2);
	} else {
	  // cout<<s[i]-'0'<<endl;
	  sta2.push(s[i] - '0');
	}
      }
    }
    
  }
  //cout<<"stack siza ---> "<<sta2.size()<<endl;
 for(; sta2.size();){
    a += sta2.top(); sta2.pop();
  }
    

 //cout<<a<<" "<<b<<endl;

    if(a == r && b == r){
      cout<<'U'<<endl;
    } else if(a == r){
      cout<<'M'<<endl;
    } else if(b == r){
      cout<<'L'<<endl;
    } else {
      cout<<'I'<<endl;
    }
  return 0;
}



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

int main(){
    ll N;
    cin >> N;
    vector<pair<ll, ll>> res;
    ll sum;
    if(N % 2 == 1) sum = N-1;
    else sum = N;
    rep(i, 1, N+1){
        rep(j, 1, N+1){
            if(j <= i || j == sum - i + 1) continue;
            res.push_back({i, j});
        }
    }
    cout << res.size() << endl;
    for(auto p : res){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}

Measured memory_bytes: 512
main = interact solve
solve = f 0 <$>(map read).words
f::Int->[Int]->String
f i (a:b:k:[])
    | i==k  = show a ++ " " ++ show b ++ "\n"
    | mod i 2 == 0 = f (i+1)$(div a 2):(b+div a 2):k:[]
    | otherwise = f (i+1)$(a+div b 2):(div b 2):k:[]

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=100005,mod=1e9+7;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int dad[max_n];
int deep[max_n];
int people[max_n];
int find(int x)
{
    if(dad[x]==x)return x;
    return dad[x]=find(dad[x]);
}
void link(int x,int y)
{
    x=find(x);
    y=find(y);
    if(x==y)
    {
        return;
    }
    else if(deep[x]<deep[y])
    {
        dad[x]=y;people[y]+=people[x];
    }
    else if(deep[x]>deep[y])
    {
        dad[y]=x;people[x]+=people[y];
    }
    else if(deep[x]==deep[y])
    {
        dad[x]=y;
        deep[y]++;
        people[y]+=people[x];
    }
}
struct Edge
{
    int from,to;
}e[100005];
int V,E,q;
int cnt;
int x;
int tt;
vector<int>v1;
long long ans;
int peng[100005];
int feng[100005];
int main()
{
	int V,m,k;cin>>V>>m>>k;int a,b;
    for(int i=0;i<V;i++)
    {
        dad[i]=i;people[i]=1;
    }
    for(int i=1;i<=m;i++)
    {
    	cin>>a>>b;
    	peng[a-1]++;
    	peng[b-1]++;
    	link(a-1,b-1);
	}
	for(int i=1;i<=k;i++)
	{
		cin>>a>>b;
		if(find(a-1)==find(b-1))
		{
			feng[a-1]++;
			feng[b-1]++;
		}

	}
    for(int i=0;i<V;i++)
    {
        if(dad[i]==i)
        {
            cnt++;
            v1.push_back(people[find(i)]);
        }
	}
    for(int i=0;i<V;i++)
    {
    	cout<<people[find(i)]-peng[i]-feng[i]-1<<' ';
	}
}

Measured memory_bytes: 2816
_=`dd`.split.map &:to_i
if _[0]<1000
	puts _[0]<=_[1]? 'Yes' : 'No'
else
	_[0]=_[0].to_s[-3..-1].to_i
  	_[0]-=500 if _[0]>500
	puts _[0]<=_[1]? 'Yes' : 'No'
end

Measured memory_bytes: 2044