akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<set>
#include<stack>
#include<queue>

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}

class node{
	public:
		int val;
		vector<node> l, r;
		string to_s(){
			string sl = "", sr = "";
			if(l.size() != 0) sl = l[0].to_s();
			if(r.size() != 0) sr = r[0].to_s();
			return "(" + sl + ")[" + to_string(val) + "](" + sr + ")";
		}
};

int to_i(int &pos, string &s){// str[pos-1] = '['
	int n = 0;
	while(s[pos] != ']'){
		n = n * 10 + s[pos] - '0';
		pos++;
	}
	return n; //str[pos] = ']'
}

node eval(int &pos, string &s){// str[pos] = '('
	pos++;
	node n;
	if(s[pos] != ')'){
		n.l.pb(eval(pos, s));
	}
	pos+=2;
	int v = to_i(pos, s);
	n.val = v;
	pos+=2;
	if(s[pos] != ')'){
		n.r.pb(eval(pos, s));
	}
	pos++;
	return n;
}

node add(node t1, node t2){
	int n = t1.val + t2.val;
	node v;
	v.val = n;
	if(!t1.l.empty() && !t2.l.empty()) v.l.pb(add(t1.l[0], t2.l[0]));
	if(!t1.r.empty() && !t2.r.empty()) v.r.pb(add(t1.r[0], t2.r[0]));
	return v;
}

int main(){
	string s;
	node a[3];
	cin >> s;
	int n=0;
	a[0] = eval(n, s);
	n = 0;
	cin >> s;
	a[1] = eval(n, s);
	n = 0;
	a[2] = add(a[0], a[1]);
	cout << a[2].to_s() << endl;

	return 0;
}

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

//#define n_size 100000

typedef struct node_
{
    int kosu;
    int *hyo;
    int parent;
//    int depth;
} Node;

int main()
{
    int n,node,ko,dep,tmp=0;
    Node *N;
    scanf("%d",&n);
    N = malloc(sizeof(Node)*n);
    for(int i=0;i<n;i++) N[i].parent = -1; 
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&node,&ko);
        N[node].kosu = ko;
        if(ko != 0)  N[node].hyo = malloc(sizeof(int)*ko);
        //parent探し
        for(int j=0;j<ko;j++)
        {
            scanf("%d",&tmp);
            N[node].hyo[j] = tmp;
            N[tmp].parent = node;
            //fprintf(stderr,"%dのhyo=%d,",i,N[node].hyo[j]);
        }
        //fprintf(stderr,"\n");
    }
    //階層探し
    for(int i=0;i<n;i++)
    {
        dep = 0;
        for(int j=i;N[j].parent != -1;j=N[j].parent)
        {
            dep +=1;
        }
//        N[i].depth = dep;
        printf("node %d: parent = %d, depth = %d, ",i,N[i].parent,dep);
        if(dep == 0){
            printf("root, ");
        }else if(N[i].kosu != 0){
            printf("internal node, ");
        }else {
            printf("leaf, ");
        }
        
        //fprintf(stderr,"N[%d].hyo=%p\n", i, N[i].hyo);
        printf("[");
        for(int j=0;j<N[i].kosu;j++){
            if(j == 0)     printf("%d",N[i].hyo[j]);
            else printf(", %d",N[i].hyo[j]);
        }
        printf("]\n");
        //free(N[i].hyo);
    }
    //free(N);
}


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

using namespace std;

int n;
int c[200010];
int last[200010], sz[200010];
vector<int> adj[200010], ch[200010], cnt[200010], root[200010];
long long ans[200010], tmp;

void dfs(int u, int p){
    sz[u] = 1;

    int pr = last[c[u]];

    if(pr != -1) ch[pr].emplace_back(u);
    else root[c[u]].emplace_back(u);

    last[c[u]] = u;

    for(auto &v : adj[u]){
        if(v == p) continue;

        cnt[u].emplace_back(0);
        dfs(v, u);

        cnt[u].back() += sz[v];

        sz[u] += sz[v];
    }

    last[c[u]] = pr;

    if(pr != -1) cnt[pr].back() -= sz[u];
}

void dfs0(int u){
    for(auto &v : ch[u])
        dfs0(v);

    for(auto &k : cnt[u])
        tmp -= 1LL * k * (k - 1) / 2 + k;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> n;

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

    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;

        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }

    memset(last, -1, sizeof(last));
    dfs(1, 1);

    for(int i = 1; i <= n; i++){
        tmp = 0;
        if(!root[i].empty()){
            tmp += 1LL * n * (n - 1) / 2 + n;

            int k = sz[1];

            for(auto &v : root[i]){
                dfs0(v);
                
                k -= sz[v];
            }

            tmp -= 1LL * k * (k - 1) / 2 + k;
        }
        ans[i] = tmp;
    }

    for(int i = 1; i <= n; i++) cout << ans[i] << "\n";

    return 0;
}

Measured memory_bytes: 63820
#include<iostream>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y)
 {
   while(x!=y)
   {
 
       if(x>y) x=x-y;
        else
        y=y-x;
   }
   return x;
   //辗转相除法
 }

 int main(int argc,char *argv[]){
 	ll x, y; cin >> x >> y;
 	cout << x * y /gcd(x, y) << endl;
    return 0;
 }
 


Measured memory_bytes: 256
import java.util.*;

public class Main{
  	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int n = Integer.parseInt(sc.next());
      	int start = 400;
      	int rank = 8;
      	while(true){
          if(n >= start && start + 199 >= n){
          	System.out.println(rank);
            break;
          }else{
           	start += 200;
            rank--;
          }
        }
    }
}

Measured memory_bytes: 35616
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;

int main(){
	fast_io();
	int x;
	map<int,int> cnt;
	int n;
	cin >> n;
	while(n--){
		cin >> x;
		++cnt[x];
	}
	int ans = 0;
	int even = 0;
	for(pii p:cnt){
		if(p.S&1)++ans;
		else ++even;
	}
	ans += even/2 * 2;
	cout << ans << '\n';
}



Measured memory_bytes: 4992
list = [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]
k = int(input())
print(list[k-1])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i <= n; ++i)
#define int long long
static const int LL_INF = 1ll << 60;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int n,m;
int s[1000100];
int a,b;
int dfs1(int p){
    if(s[p+1]<s[p]&&s[p-1]<s[p]){
        return m-s[p];
    }
    else {
        if(p<n)a=dfs1(p+1)+(m-s[p]);
    }
    return a;
}

int dfs2(int p){
    if(s[p+1]<s[p]&&s[p-1]<s[p]){
        return m-s[p];
    }
    else {
        if(p>1)b = dfs2(p-1)+(m-s[p]);
    }
    return b;
}

signed main(){
    cin>>n>>m;
    FOR(i,1,n){
        cin>>s[i];
    }
    int res=0;
    FOR(i,1,n){
        int temp;
        a=0,b=0;
        if(i==1&&s[i]<s[i+1])temp=dfs1(i);
        if(i==n&&s[i]<s[i-1])temp=dfs2(i);
        else if(s[i]<s[i+1]&&s[i]<s[i-1]){
           temp=max(dfs1(i),dfs2(i));
        }
        if(res<temp)res=temp;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2328
#include <iostream>
#include <cmath>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){
  const double pi = 3.141592653589793;
  double a,b,h,m,ans,kaku;
  cin >> a >> b >> h >> m;
  
  kaku = (m/60)*360 - ((h*60+m)/720)*360;
  kaku = kaku / 180 * pi;
  
  ans = a*a + b*b - 2*a*b*cos(kaku);
  ans = sqrt(ans);
  
  printf("%0.20f", ans);
  
  return 0;
}


Measured memory_bytes: 4116
from itertools import combinations
N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
flug = True
for j in range(1, M + 1):
    sum_test = 0
    for i in range(N):
        sum_test += A[i][j]
    if sum_test < X:
        flug = False
        break
N_idx = [n for n in range(N)]
rec_tes = 0
for i in range(N):
    rec_tes += A[i][0] 
for i in range(N):
    for j in combinations(N_idx, r = i + 1):
        for k in range(1, M + 1):
            sum_und = 0
            sum_tes = 0
            for h in j:
                sum_und += A[h][k]
                sum_tes += A[h][0]
            if sum_und < X:
                break
        if sum_und >= X and sum_tes < rec_tes:
            rec_tes = sum_tes
if flug:
    print(rec_tes)
else:
    print(-1)

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

#define ll long long
#define mod 1000000007

ll n;
double prob[3003], dp[3003][3003];

double solve (int i, int heads) {
	if (heads <= 0) {
		return 1;
	}
	if (i == 0) {
		return 0;
	}
	if (dp[i][heads] > -0.9) {
		return dp[i][heads];
	}

	dp[i][heads] = prob[i] * solve (i - 1, heads - 1) +  (1 - prob[i]) * solve (i - 1, heads);
	return dp[i][heads];
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> prob[i];
	}
	memset (dp, -1, sizeof dp);
	double ans = solve (n, (n + 1) / 2);
	cout << setprecision(10) << ans << "\n";
	return 0;
}

Measured memory_bytes: 70912
package main

import (
   "fmt"
)

func calc(a, b float32) int {
  var ans = (a + b) / 2
 
  if float32(int(ans)) < ans {
    return int(ans) + 1
  } else {
    return int(ans)
  }   
}


func main() {
 var a float32
 var b float32
 fmt.Scan(&a)
 fmt.Scan(&b)

 fmt.Println(calc(a, b))
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
const int MAX = 1000000+5;
int n,a[MAX];
void Print(){
	for(int i = 0;i < n-1;i++)
		cout << a[i] << " ";
	cout << a[n-1] << endl;
}
void InsertionSort(){
	Print();
	for(int i = 1;i < n;i++){
		int t = a[i];
		int j = i-1;
		while(j >= 0 && a[j] > t){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = t;
		Print();
	}
}
int main(int argc, char const *argv[])
{
	cin >> n;
	for(int i = 0;i < n;i++)
		cin >> a[i];
	InsertionSort();
	return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  for (int i = B*10; i < (B+1)*10; i++) {
    if (i * 2 / 25 == A) {
      cout << i << endl;
      return 0;
    }
  }
  
  cout << -1 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

x, n = list(map(int, input().split()))
p = list(map(int, input().split()))


l = x
h = x

while True:
    if l not in p:
        break
    else:
        l -= 1

while True:
    if h not in p:
        break
    else:
        h += 1

if (x - l) <= (h - x):
    print(l)
else:
    print(h)

Measured memory_bytes: 9200
import sys
sys.setrecursionlimit(10**7)
n=int(input())
t=[[] for i in range(n)]
for i in range(n-1):
    a,b,l=map(int,input().split())
    t[a-1].append([b-1,l % 2])
    t[b-1].append([a-1,l % 2])

flag = [(-1) for _ in range(n)]

def dfs(s,l,c):
    global flag
    global t
    if l == 1:
        if c == 0:c = 1
        else:c = 0
    flag[s] = c
    for g in t[s]:
        if flag[g[0]] == -1:
            dfs(g[0],g[1],c)

dfs(0,0,0)

print("\n".join(map(str,flag)))

Measured memory_bytes: 82348
n = int(input())
brick = list(map(int, input().split()))
cnt = 0
i = 0
j = 1
while i < n:
    if brick[i] == j:
        cnt += 1
        j += 1
    i += 1
if cnt == 0:
    print(-1)
else:
    print(n - cnt)


Measured memory_bytes: 26268
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL div(LL a,LL b){
  return mul(a,power(b,mod-2));
}


int invfact[100005];
int fact[100005];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

int main(){
	int n,m;
	cin>>n>>m;
	int f=fabs(n-m);
	if(f>=2)cout<<0;
	else{
		factset(max(n,m));
		int ans=mul(fact[n],fact[m]);
		if(f==0)ans=ans*2%mod;
		cout<<ans;
	}
	cout<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int[][] g;
	static int[] p, dp;

	static int[][] directedGraph(int n, ArrayList<Integer> from, ArrayList<Integer> to) {
		int[] cnt = new int[n];
		for (int i : from) cnt[i]++;

		int[][] g = new int[n][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]];
		for (int i=0; i<from.size(); i++) {
			int s = from.get(i);
			int t = to.get(i);
			g[s][--cnt[s]] = t;
		}

		return g;
	}

	static int rec(int cur) {
		if (dp[cur] != -1) return dp[cur];
		if (g[cur].length == 0) {
			return dp[cur] = p[cur];
		}
		int sum = 0;
		for (int to : g[cur]) {
			sum += rec(to);
		}
		return dp[cur] = Math.min(p[cur], sum);
	}

	static boolean solve() {
		int n = in.nextInt();
		if (n == 0) return false;

		String[] s = new String[n];
		p = new int[n];

		HashMap<String,Integer> map = new HashMap<>();

		for (int i=0; i<n; i++) {
			s[i] = in.next();
			p[i] = in.nextInt();
			map.put(s[i], i);
		}

		ArrayList<Integer> from = new ArrayList<>();
		ArrayList<Integer> to = new ArrayList<>();
		int m = in.nextInt();

		for (int i=0; i<m; i++) {
			String name = in.next();
			int idx = map.get(name);
			int k = in.nextInt();
			for (int j=0; j<k; j++) {
				from.add(idx);
				to.add(map.get(in.next()));
			}
		}

		g = directedGraph(n, from, to);
		dp = new int[n];
		Arrays.fill(dp, -1);

		out.println(rec(map.get(in.next())));

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 34660
//q5.cpp
//Sat Aug  8 09:48:45 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

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

int main(){
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;

	if (c*2>=a+b){
		cout << a*x + b*y << endl;
	}else {
		int ans = min(x,y)*2*c;
		if (x>y && a<=2*c){
			ans += (x-y)*a;
		}else if (x>y){
			ans += (x-y)*c*2;
		}else if (x<y && b<=2*c){
			ans += (y-x)*b;
		}else if (x<y){
			ans += (y-x)*c*2;
		}
		cout << ans << endl;
	}

//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3612
import sys

input = sys.stdin.readline

S = input().strip()

# a = [0]*30
a = [0]*(5*10**5)

i = 0
while i<=len(S)-1:
	si = S[i]
	if si=='<':
		a[i+1] = a[i]+1 
		i += 1
	else:
		dec_num = 0
		j = i
		while S[j]=='>':
			dec_num += 1
			j += 1
			if j==len(S): break

		for n in range(dec_num):
			a[i+n] = max(dec_num,a[i+n])
			dec_num -= 1

		i = j

ans = sum(a)

print(ans)

Measured memory_bytes: 49644
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a,b;
    cin >> a >> b;
    cout << a * b << endl;
}

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

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long INF = 1000000000000000;
long long d(long long P, long long Q, long long R, long long S){
	return max({P, Q, R, S}) - min({P, Q, R, S});
}
int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
	}
	vector<long long> S(N + 1, 0);
	for (int i = 0; i < N; i++){
		S[i + 1] = S[i] + A[i];
	}
	long long ans = INF;
	for (int i = 2; i <= N - 2; i++){
		long long PQ = S[i];
		long long RS = S[N] - S[i];
		int p1 = lower_bound(S.begin(), S.end(), PQ / 2) - S.begin();
		long long P1 = S[p1];
		long long Q1 = PQ - P1;
		long long P2;
		long long Q2;
		if (p1 > 0){
			P2 = S[p1 - 1];
			Q2 = PQ - P2;
		}
		int p2 = lower_bound(S.begin(), S.end(), PQ + RS / 2) - S.begin();
		long long R1 = S[p2] - PQ;
		long long S1 = RS - R1;
		long long R2;
		long long S2;
		if (p2 > i){
			R2 = S[p2 - 1] - PQ;
			S2 = RS - R2;
		}
		ans = min(ans, d(P1, Q1, R1, S1));
		if (p1 > 0){
			ans = min(ans, d(P2, Q2, R1, S1));
		}
		if (p2 > i){
			ans = min(ans, d(P1, Q1, R2, S2));
			if (p1 > 0){
				ans = min(ans, d(P2, Q2, R2, S2));
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5640
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <cassert>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>

#include <atcoder/segtree>

int max(int a, int b) { return std::max(a, b); }
int zero() { return 0; }
int main() {
	constexpr int max_value = 300000;
	int n, k; std::cin >> n >> k;
	std::vector<int> nums(n);
	for (auto& a : nums) std::cin >> a;
	atcoder::segtree<int, max, zero> tree(max_value + 1);
	for (const auto a : nums) {
		const auto max_length = tree.prod(std::max(a - k, 0), std::min(a + k, max_value) + 1);
		tree.set(a, max_length + 1);
	}
	std::cout << tree.all_prod() << '\n';
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int n,counter;
bool flag=true;
cin>>n;
vector<int> vec(n);
  
for(int i=0;i<n;i++){
	cin>>vec[i];
}

while(flag){
	flag=false;
	for(int j=n-1;0<j;j--){
		if(vec[j]<vec[j-1]){
			int temp = vec[j];
			vec[j] =vec[j-1];
			vec[j-1] = temp;
			flag = true;
          	counter ++;
		}
	}

}

for(int i=0;i<n;i++){
	if(i==n-1){
      cout<<vec[i]<<endl;
    }else{
      cout<<vec[i]<<" ";
    }
}
cout<<counter<<endl;

}


Measured memory_bytes: 3104
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T, std::size_t N>
struct make_vector_type {
	using type =
		typename std::vector<typename make_vector_type<T, (N - 1)>::type>;
};

template <typename T>
struct make_vector_type<T, 0> {
	using type = typename std::vector<T>;
};

template <typename T, size_t N>
auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) {
	if constexpr(N == 0) {
		return std::vector<T>(ls[N], init_value);
	} else {
		return typename make_vector_type<T, N>::type(
			ls[N], make_vector_impl<T, (N - 1)>(ls, init_value));
	}
}

template <typename T, std::size_t N>
auto make_vector(const std::size_t (&ls)[N], T init_value) {
	std::vector<std::size_t> dimensions(N);
	for(int i = 0; i < N; i++) {
		dimensions[N - i - 1] = ls[i];
	}
	return make_vector_impl<T, N - 1>(dimensions, init_value);
}

template <typename T>
std::vector<T> make_vector(std::size_t size, T init_value) {
	return std::vector<T>(size, init_value);
}

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max<T>(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min<T>(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	VLL a(n);
	REP(i, n) { cin >> a[i]; }

	ll abs_sum = 0;
	ll abs_min = INF;
	ll neg_count = 0;
	REP(i, n) {
		abs_sum += abs(a[i]);
		chmin(abs_min, abs(a[i]));
		neg_count += a[i] < 0 ? 1 : 0;
	}

	cout << abs_sum - (neg_count % 2 == 0 ? 0 : abs_min * 2) << endl;
	return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  double r;
  cin >> r;

  cout << r * 2 * 3.14 << endl;
}

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

Measured memory_bytes: 3788
d,n = map(int,input().split())
if d == 0:
	if n == 100:
		print('101')
	else:
		print(n)
elif d == 1:
	if n == 100:
		print('10100')
	else:
	    print(n * 100)
elif d == 2:
	if n == 100:
		print('1010000')
	else:
	    print(n * 10000)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
bool isPalindromic(int n){
    vi digits(5);
    rep(i, 0, 5){
        digits[i]=n%10;
        n/=10;
    }
    if(digits[0]==digits[4] and digits[1]==digits[3]){
        return true;
    }
    return false;
}
int main( ) {
    //freopen("B.01.in","r",stdin);
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    vi digits(5);
    int a,b,all=0;
    // cin >> a >> b;
    scanf("%d %d",&a,&b);
    rep(i, a, b+1){
        if(isPalindromic(i)){
            all++;
        }
    }
    // cout << all << endl;
    printf("%d\n",all);
    return 0;
}

Measured memory_bytes: 3752
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Distance(int n, List<int>[] parents, int?[] memo)
        {
            if (!memo[n].HasValue)
            {
                memo[n] = 0;
                foreach (var parent in parents[n])
                {
                    int distance = Distance(parent, parents, memo);
                    if (distance + 1 > memo[n])
                    {
                        memo[n] = distance + 1;
                    }
                }
            }
            return memo[n].Value;
        }

        static int[] Solve(int N, int M, Tuple<int, int>[] tuples)
        {
            var parents = new List<int>[N];
            for (int i = 0; i < N; ++i)
            {
                parents[i] = new List<int>();
            }
            foreach (var tuple in tuples)
            {
                parents[tuple.Item2].Add(tuple.Item1);
            }
            var memo = new int?[N];
            var answers = Enumerable.Repeat(-1, N).ToArray();
            for (int i = 0; i < N; ++i)
            {
                int min = -1;
                foreach (var parent in parents[i])
                {
                    var distance = Distance(parent, parents, memo);
                    if (distance > min)
                    {
                        answers[i] = parent;
                        min = distance;
                    }
                }
            }
            return answers.Select(a => a + 1).ToArray();
        }

        static void Main(string[] args)
        {
            var V1 = ReadInts();
            int N = V1[0], M = V1[1];
            var tuples = new Tuple<int, int>[N + M - 1];
            for (int i = 0; i < N + M - 1; ++i)
            {
                var V2 = ReadInts();
                tuples[i] = new Tuple<int, int>(V2[0] - 1, V2[1] - 1);
            }
            foreach (var a in Solve(N, M, tuples))
            {
                Console.WriteLine(a);
            }
        }
    }
}


Measured memory_bytes: 42240
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  if (n == 0){
    cout << 1 << endl;
  } else if (n == 1){
    cout << 2 << endl;
  } else if (n == 2){
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}


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

int main(){
  int n,m;
  cin>>n>>m;
  vector<ll> x(m);
  for(int i=0;i<m;i++) cin>>x[i];
  sort(x.begin(),x.end());
  vector<ll> d;
  for(int i=0;i<m-1;i++) d.push_back(x[i+1]-x[i]);
  sort(d.begin(),d.end());
  ll ans=0;
  for(int i=0;i<m-n;i++) ans+=d[i];
  cout << ans << endl;
}

Measured memory_bytes: 4912
#include <iostream>

using namespace std;

int main (void) {
    string  a, b, c;

    cin >> a >> b >> c;

    if (a[a.length()-1] == b[0] && b[b.length() -1] == c[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

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

int main() {
  int n,x,t;
  cin >> n >> x >> t;
  cerr << n << x << t << endl;
  int ans = 0;
  while(n > 0) {
    n-=x;
    ans +=t;
  }
  cout << ans << endl;
}


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

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main()
{
    ll A, B;
    cin >> A >> B;
    cout << LCM(A, B) << endl;
}

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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

#ifdef LOCALCODE
signed solve()
#else
signed main()
#endif
{
	auto N = IN();
	vector<i64> X(N);
	for (auto& v : X)
	{
		cin >> v;
	}

	vector<i64> x(X);
	ALL(sort, x);
	i64 l = x[N / 2 - 1];
	i64 r = x[N / 2];

	REP(i, N)
	{
		if (X[i] <= l)
			print(r);
		else
			print(l);
	}
	return 0;
}


Measured memory_bytes: 5376
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input! {
        a: i32, b: i32, c: i32, d: i32,
    }

    println!("{}", cmp::max(a*b, c*d));
}


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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

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

    string s = next<string>();
    for(char c : s) {
        cout << (char)((c - 'A' + 23) % 26 + 'A');
    }
    cout ln;

    return 0;
}

Measured memory_bytes: 1168
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> ss(n);
  FOR(s,ss) {
    cin >> s;
  }
  VI minimum(26, INT_MAX);
  FOR(s,ss) {
    VI count(26, 0);
    FOR(c,s) {
      count[c-'a']++;
    }
    REP(i,0,26) {
      minimum[i] = min(minimum[i], count[i]);
    }
  }
  string ans = "";
  REP(i,0,26) {
    REP(j,0,minimum[i]) {
      ans.push_back(i + 'a');
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define f first
#define s second
#define tr(a,i) for(auto (i)=(a).begin();(i)!=(a).end();++(i))
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define spresent(a,val) ((a).find(val)!=(a).end())
#define present(a,val) (find(all(a),val)!=(a).end()) 


typedef long long int ll;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<int,pi > pii;
typedef pair<ll,pl > pll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int M = 998244353;


int pow_mod(ll num, int pow){
	if(pow==0)
		return 1;
	if(pow==1)
		return num;
	ll temp = pow_mod(num,pow>>1);
	temp = (temp*temp)%M;
	if(pow&1)
		temp = (temp*num)%M;
	return temp;
}

int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(c<=b+a){
		cout<<b+c;
	}
	else{
		cout<<2*b+a+1;
	}











	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}





void _main() {
        int n; cin >> n;
        map<int, int> freq;
        while (n--) {
                int a; cin >> a;
                freq[a]++;
        }

        vector<int> candidates;
        for (const auto it: freq) {
                if (it.second >= 2) candidates.emplace_back(it.first);
                if (it.second >= 4) candidates.emplace_back(it.first);
        }



        sort(all(candidates), greater<>());
        if (candidates.size() < 2) cout << 0;
        else cout << (ll) candidates[0] * candidates[1];
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


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

using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int costTrain = n * a;
  int costTaxi = b;

  if(costTrain < costTaxi) cout << costTrain << endl;
  else cout << costTaxi << endl;


  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toStr(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	vi s(3);
	while(cin >> s[0] >> s[1] >> s[2], s[0]) {
		sort(ALL(s));
		double lim = sqrt(s[0]*s[0]+s[1]*s[1]);

		int n, r;
		cin >> n;
		REP(_, n) {
			cin >> r;
			if(lim < 2*r) {
				cout << "OK" << endl;
			} else {
				cout << "NA" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#pragma GCC target("avx2")
using namespace std;

const int maxh = 101, maxw = 9;
const int mod = 1000000007;
 
int h, w, k;
int dp[maxh][maxw];
 
int rec (int r, int c) {
    if (r == h)
        return int(c == k - 1);
    if (dp[r][c] != -1)
        return dp[r][c];
    else {
        int res = 0;
        for (int mask = 0; mask < (1 << (w - 1)); ++mask) {
            bool ok = 1;
            for (int i = 1; i < w - 1; ++i) {
                if ((mask & (1 << (i - 1))) && (mask & (1 << i))) {
                    ok = 0;
                    break;
                }
            }
            if (ok) {
                int nc = c;
                if (c + 1 < w && (mask & (1 << c)))
                    nc = c + 1;
                else if (c - 1 >= 0 && (mask & (1 << (c - 1))))
                    nc = c - 1;
                (res += rec(r + 1, nc)) %= mod;
            }
        }
        return dp[r][c] = res;
    }
}
 
signed main () {
	cin >> h >> w >> k;
	memset(dp, -1, sizeof(dp));
	cout << rec(0, 0) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)  
#define REP(i,n) for(int i=0;i<(n);i++)      
#define RREP(i,n) for (int i=(n)-1;i>=0;i--) 
           
#define pb push_back              
#define PII pair<int,int>         
           
#define VS vector<string>         
#define VI vector<int>            
#define ll long long int          
#define debug(x) cout << x << " :" <<#x << endl   
int main(void) {
    int n; 
    vector<bool> p;               
    int count = 0;
    while(1) {
        count = 0;
        cin >> n;
        if(n == 0) break;
        if(n<4) {                                                                                                                           
            cout << 0 << endl;
            continue;
        }  
        p = vector<bool>(n,true);
        p[0] = false;
        int i = 3;
        while(i <= n) {
            p[i] = false;
            i += 2;
        }  
           
        i = 2;
        while(i <= n) {
            if(p[i]) {
                int j=2*(i+1) - 1;
                while(j<=n) {
                    p[j] = false;
                    j += i+1;
                }
            }
            i += 2;
        }  
           
        if(p[1] && p[n-3]) count++;
        i = 2;
        while(i < n/2) {
            if(p[i] && p[n-i-2]) {
                count++;
            }
            i += 2;               
        }  
        cout << count << endl;    
        p.clear();
    }      
}

Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	int a, b, c, x, y;

	std::cin >> a >> b >> c >> x >> y;

	if (a + b < 2 * c) {
		std::cout << a * x + b * y;
	}
	else {
		int ans = std::min(x, y) * c * 2;
		if (x < y) {
			if (b < 2 * c) {
				ans += (y - x) * b;
			}
			else {
				ans += (y - x) * c * 2;
			}
		}
		else {
			if (a < 2 * c) {
				ans += (x - y) * a;
			}
			else {
				ans += (x - y) * c * 2;
			}
		}
		std::cout << ans;
	}

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define all(a) (a).begin(), (a).end()
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 

using namespace std;

void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
}                         

void solve() {                                                                                         
	int n;
	cin >> n;
	vector<int> b(n - 1);
	for (int i = 0; i < n - 1; ++i) {
	    cin >> b[i];
	}	
	
	vector<int> a(n, 0);
	a[0] = b[0];
	for (int i = 0; i < n - 1; ++i) {
		a[i] = min(a[i], b[i]);
		a[i + 1] = b[i]; 	
    }

    cout << accumulate(a.begin(), a.end(), 0) << endl;
}	


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

using namespace std;


int main(){

	string str1,str2,p;
	char x;
	int q,a,b;

	getline(cin, str1);
	cin >> q;

	for (int i = 0; i < q; i++){
	
		cin >> str2;
		if (str2 == "replace"){
		//replace?????????
			cin >> a >> b >> p;
			for (int j = 0; j < p.length(); j++)
				str1[j + a] = p[j];
		}
	    else if(str2 == "reverse"){
			//reverse?????????
			cin >> a >> b;
			//a???????????????b???????????????????????????

			for (int j = a; j < ((b - a) / 2)+a+1; j++){
			
				swap(str1[j],str1[b-(j-a)]);

			}



		}
		 else if(str2=="print"){
		//print?????????
			cin >> a >> b;
			for (int j = a; j < b+1; j++){
				cout << str1[j];
			}cout << endl;
		 }
	}//??????????????????






	return 0;
}

Measured memory_bytes: 1212
#include <iostream>

#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : vec) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }

ostream& operator<<(ostream& os, const ii& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

const int MAX { 1000010 };
const ll oo { (1LL << 62) };
const int MOD { 1000000007 };

ll as[MAX], sum[MAX];

ll RSQ(ll a, ll b)
{
    return sum[b] - sum[a - 1];
}

ll solve(int N)
{
    // Prefix sum
    for (int i = 1; i <= N; ++i)
        sum[i] = sum[i - 1] + as[i];

    ll min_diff = oo, x = 1, z = 3;

    for (ll y = 2; y <= N - 2; ++y)
    {
        auto a = RSQ(1, x), b = RSQ(x + 1, y), c = RSQ(y + 1, z), d = RSQ(z + 1, N);
        auto L = abs(b - a), R = abs(d - c);

//LOG(a, ' '); LOG(b, ' '); LOG(c, ' '); LOG(d, '\n');
//LOG(x, ' '); LOG(y, ' '); LOG(z, ' '); LOG(L, ' '); LOG(R, '\n');

        while (x < y - 1)
        {
            auto D = abs(RSQ(1, x + 1) - RSQ(x + 2, y));

            if (D <= L)
            {
                L = D;
                a = RSQ(1, x + 1);
                b = RSQ(x + 2, y);
                ++x;
            } else
                break;
        }

        while (z < N - 1)
        {
            auto D = abs(RSQ(y + 1, z + 1) - RSQ(z + 2, N));

            if (D <= R)
            {
                R = D;
                c = RSQ(y + 1, z + 1);
                d = RSQ(z + 2, N);
                ++z;
            } else
                break;
        }

        auto m = min({a, b, c, d});
        auto M = max({a, b, c, d});

//LOGM("==> "); LOG(m, ' '); LOG(M, '\n');
//LOG(a, ' '); LOG(b, ' '); LOG(c, ' '); LOG(d, '\n');
//LOG(x, ' '); LOG(y, ' '); LOG(z, ' '); LOG(L, ' '); LOG(R, "\n\n");
        min_diff = min(min_diff, M - m);
    }

    cout << min_diff << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    for (int i = 1; i <= N; ++i)
        cin >> as[i];

    solve(N);

    return 0;
}


Measured memory_bytes: 5888