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

#define rep(i,n) for (int i = 0; i < (n); ++i)

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

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

struct LCA{
    vector<vector<int>> parent;
    vector<int> depth;
    int n;
    int max_k;
    vector<vector<int>> graph;

    LCA(vector<vector<int>>& _graph, int v=0): graph(_graph), n(_graph.size()), max_k(int(log2(n)) + 1) {
        parent.assign(max_k+1, vector<int>(n, -1));
        depth.assign(n, 0);
        dfs(v);
        doubling();
    }

    void dfs(int v, int p=-1) {
        for (int nv: graph[v]) {
            if (nv == p) continue;
            depth[nv] = depth[v] + 1;
            parent[0][nv] = v;
            dfs(nv, v);
        }
    }

    void doubling() {
        for (int k = 0; k < max_k; ++k) {
            for (int i = 0; i < n; ++i) {
                if (parent[k][i] == -1) {
                    parent[k+1][i] = -1;
                } else {
                    parent[k+1][i] = parent[k][parent[k][i]];
                }
            }
        }
    }

    int get_lca(int u, int v) {
        if (depth[u] < depth[v]) swap(u, v);
        for (int k = max_k; k >= 0; --k) {
            if (((depth[u] - depth[v]) >> k) & 1) {
                u = parent[k][u];
            }
        }
        if (u == v) return u;
        for (int k = max_k; k >= 0; --k) {
            if (parent[k][u] != parent[k][v]) {
                u = parent[k][u];
                v = parent[k][v];
            }
        }
        return parent[0][u];
    }

    int get_path_length(int u, int v) {
        int lca = get_lca(u, v);
        return (depth[u] - depth[lca]) + (depth[v] - depth[lca]);
    }
};


int main() {
    int n; cin >> n;
    vector<vector<int>> graph(n);
    rep(i, n) {
        int k; cin >> k;
        rep(j, k) {
            int v; cin >> v;
            graph[i].push_back(v);
        }
    }

    LCA lca(graph);

    int q; cin >> q;
    rep(i, q) {
        int u, v; cin >> u >> v;
        cout << lca.get_lca(u, v) << endl;
    }
    

    return 0;
}


    



Measured memory_bytes: 24852
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back

int n,k,s;
ll ans;

//9 3 23
void dfs(int sum,int floor,int bef){
    if(floor==k-1){
        if(0<s-sum && bef<s-sum && s-sum<=n){ans++;}
        return ;
    }
    for(int i=bef+1;i<=n;i++){
        dfs(sum+i,floor+1,i);
    }
}


int main(){
    
    while(cin>>n>>k>>s){
        ans=0;
        if(n==0 && k==0 && s==0)break;
        dfs(0,0,0);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
const int Max = 100000 + 5;
int n, a[Max];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = n - 1; i >= 1; i--) {
        if(a[i] > a[i + 1])
            a[i]--;
    }
    for (int i = 2; i <= n; i++) {
        if(a[i] < a[i - 1]) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,x[200000],y[200000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
        y[i]=x[i];
    }
    sort(y,y+n);
    for(int i=0;i<n;i++){
        if(x[i]<=y[n/2-1]){
            cout<<y[n/2]<<endl;
        }else{
            cout<<y[n/2-1]<<endl;
        }
    }
    
}


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

int main() {
  int K, S ;
cin >> K >> S ;
  int c,d,e;
  int f =0;
   for(int c =0; c<=K; c++){
     for(int d = 0; d<=K; d++){
      
      if((S -(c+d) >= 0) &&(S-(c+d) <= K))
           f++;
         
       }
     }
   
  cout << f << endl;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
link = [[] for i in range(n)]
for _ in range(m):
    a,b = map(int, input().split())
    link[a-1].append(b-1)
    link[b-1].append(a-1)

used = [0 for i in range(n)]
ans = 0
#print(link)
def dfs(now, prev):
    global ans

    if sum(used) == n:
        #print('+1')
        ans += 1

    for i in link[now]:
        #print(now,i,used)
        if i != now and used[i] == 0:
            used[i] = 1
            #print('a')
            dfs(i, now)
            #print('b')
            used[i] = 0
            #print('c')

used[0] = 1
dfs(0,-1)
print(ans)



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

string s;
int a, b;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s;
	a = stoi(s.substr(0, 2));
	b = stoi(s.substr(2, 2));
	if(1 <= a && a <= 12){
		if(1 <= b && b <= 12) cout << "AMBIGUOUS\n";
		else cout << "MMYY\n";
	}else{
		if(1 <= b && b <= 12) cout << "YYMM\n";
		else cout << "NA\n";
	}
}

Measured memory_bytes: 256
/*input
2
100
200
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w, n; cin >> h >> w >> n;
    cout << min(n/h + (n % h != 0), n/w + (n % w != 0));

    return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	static int[] ans;
	static Map<Integer, Integer> map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int Q = Integer.parseInt(sc.next());
		ans = new int[N];

		map = new HashMap<>();
		for (int i = 0; i < N - 1; i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			if (map.get(b) == null) {
				map.put(b, a);
			}
		}

		for (int i = 0; i < Q; i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			ans[a - 1] += b;
		}

		for (int i = 2; i <= N; i++) {
			int p = map.get(i);
			ans[i - 1] += ans[p - 1];
		}
		for (int i = 0; i < N; i++) {
			if (i < N - 1) {
				System.out.print(ans[i]);
				System.out.print(" ");
			} else {
				System.out.println(ans[i]);
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 125236
#include <stdio.h>


#define MAX_PRIME	(300100)

int prime[MAX_PRIME + 1];

void make_prime(void)
{
    int i;
    int j;
    int n;
    int c;
    
    for (i = 1; i <= MAX_PRIME / 7; i++){
        if (prime[i * 7 - 1] == 0){
            for (j = (i * 7 - 1) * 2; j <= MAX_PRIME; j += (i * 7 - 1)){
				prime[j] = 1;
//printf("<%d>", j);
            }
        }
        if (prime[i * 7 + 1] == 0){
            for (j = (i * 7 + 1) * 2; j <= MAX_PRIME; j += (i * 7 + 1)){
				prime[j] = 1;
//printf("[%d]", j);
            }
        }
    }
}


int main(void)
{
    int n;
    int i;
    
    make_prime();
#if 0
for (i = 7; i <= 300100; i += 7){
    if (prime[i - 1] == 0){
        printf(" %d", i - 1);
    }
    if (prime[i + 1] == 0){
        printf(" %d", i + 1);
    }
}
#endif
    while (1){
        scanf("%d", &n);
        if (n == 1){
            break;
        }
        
        printf("%d:", n);
        
        i = 7;
        while (n >= i - 1){
            if (prime[i - 1] == 0){
                if (n % (i - 1) == 0){
                    printf(" %d", i - 1);
                }
            }
            if (prime[i + 1] == 0){
                if (n % (i + 1) == 0){
                    printf(" %d", i + 1);
                }
            }
            i += 7;
        }
        printf("\n");
    }
    return (0);
}

Measured memory_bytes: 1768
/*C - Replacing Integer*/

#include <bits/stdc++.h>

using namespace std;
using Long = long long;

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	Long N, K;
	Long aux;

	cin >> N >> K;

	cout << min(N % K, K - (N % K));

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    ll n;
    cin >> n;
    vector<ll> a;
    rep(i, n){ ll tmp; cin >> tmp; a.push_back(tmp);}
    sort(a.begin(), a.end(), greater<ll>());

    vector<ll> l;
    ll cnt = 0;
    rep1(i, n-1){
        if (a[i] == a[i-1]){
            l.push_back(a[i]);
            i++;            
        } 
    }
    ll ans = 0;
    if (l.size()!=0) ans = l[0]*l[1]; 
    cout << ans << endl;
}



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

using namespace std;

int main(){
	int N;
	cin >> N;
	
	vector<int> h(N+1);
	for (int i=1; i<=N; ++i) {
		cin >> h.at(i);
	}
	
	vector<int> dp(N+1);
	
	for (int i=2; i<=N; ++i) {
		if (i == 2) {
			dp.at(2) = abs(h.at(2) - h.at(1));
		} else if (i == 3) {
			dp.at(3) = min(dp.at(2) + abs(h.at(3) - dp.at(2)), abs(h.at(3) - h.at(1)));
		} else {
			dp.at(i) = min(dp.at(i-1) + abs(h.at(i) - h.at(i-1)), dp.at(i-2) + abs(h.at(i) - h.at(i-2)));
		}
	}
	cout << dp.at(N) << endl;
	
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

import itertools
import numpy as np
import math

p = list(itertools.permutations(range(N)))

Sum_N = 0

for i in range(len(p)):

    Sum = 0

    for j in range(N - 1):
        Sum += math.sqrt((x[p[i][j]] - x[p[i][j + 1]]) ** 2 + (y[p[i][j]] - y[p[i][j + 1]]) ** 2)

    Sum_N += Sum

print(Sum_N / len(p))



Measured memory_bytes: 23216
#include <iostream>

using namespace std;

int main(){
	int R, C;
	static int s[10][10000];
	while(cin >> R >> C){
		if(R == 0 && C == 0) break;
		for(int i=0;i<R;i++){
			for(int j=0;j<C;j++) cin >> s[i][j];
		}
		int res = 0;
		for(int b=0;b<(1<<R);b++){
			int sum = 0;
			for(int j=0;j<C;j++){
				int cnt = 0;
				for(int i=0;i<R;i++){
					if(b&(1<<i)){
						if(s[i][j] == 1) cnt++;
					} else {
						if(s[i][j] == 0) cnt++;
					}
				}
				sum += max(cnt, R-cnt);
			}
			res = max(sum, res);
		}
		cout << res << endl;
	}
}

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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a)
        cout << k << endl;
    else if (k <= a + b)
        cout << a << endl;
    else
        cout << a - (k - a - b) << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=700,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c;
	if(a+b>=c){cout<<"Yes";}
	else{cout<<"No";}


	cout<<endl;
} 


Measured memory_bytes: 256
# 2020/02/09
# AtCoder Beginner Contest 154 - D

# Input
n, k = map(int,input().split())
p = list(map(int,input().split()))

acm = [0] * n

# Calc
for i in range(n):
    if i-k < 0:
        minu = 0
    else:
        minu = p[i-k]
    acm[i] = acm[i-1] + p[i] - minu

ans = (max(acm) + k) / 2

# Output
print(ans)


Measured memory_bytes: 25060
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
	int n;
	cin >> n;
	vector<int> dp(n+1);
	dp[0]=0;
	for(int i=1; i<=n; i++){
		dp[i] = 1+dp[i-1];
		int pow6=1;
		while(pow6*6<=i){
			pow6*=6;
			dp[i] = min(dp[i], 1+dp[i-pow6]);
		}
		int pow9=1;
		while(pow9*9<=i){
			pow9*=9;
			dp[i] = min(dp[i], 1+dp[i-pow9]);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 640
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(arr, brr):  # fix inputs here
    console(arr)
    console(brr)
    console("----- solving ------")
    c1 = Counter(arr)
    c2 = Counter(brr)

    for k,v in c1.items():
        if k in c2:
            if v + c2[k] > len(arr):
                print("No")
                return

    anew = sorted(arr)
    bnew = sorted(brr)[::-1]

    idxs = set([i for i,(a,b) in enumerate(zip(anew,bnew)) if a == b])
    swaps = []

    if idxs:
        same_num = bnew[list(idxs)[0]]
        for i in range(len(arr)):
            if i in idxs:
                continue
            if bnew[i] == same_num:
                continue
            if anew[i] == same_num:
                continue
            swaps.append(i)
            if len(swaps) == len(idxs):
                break
    
    assert len(swaps) == len(idxs)
    
    console()
    console(anew)
    console(bnew)
    console(idxs)
    console(swaps)
    console()

    for x,y in zip(swaps, idxs):
        bnew[x], bnew[y] = bnew[y], bnew[x]

    d = defaultdict(list)
    for a,b in zip(anew, bnew):
        d[a].append(b)
    
    
    res = []
    for a in arr:
        b = d[a].pop()
        assert b != a
        res.append(b)

    # assert(sorted(res) == sorted(brr))

    console()
    console(anew)
    console(bnew)
    console(idxs)
    console(swaps)
    console()

    print("Yes")
    print(" ".join([str(a) for a in res]))

    return





def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
# sys.stdin.readlines()

for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
    k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    arr = list(map(int,input().split()))
    brr = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(list(map(int,input().split())))

    res = solve(arr, brr)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
    # print(res)


Measured memory_bytes: 214936
import scala.io.Source

object Main{
  def main(args: Array[String]){
    val list =
      for{
        in <- Source.stdin.getLines.toList
      } yield in

    list.map(_.split(" ").toList).filter{_.length > 2}.map{list =>
      val l = list.head.toInt
      val r = list.last.toInt

      list.tail.head match {
        case "+" => println(l + r)
        case "-" => println(l - r)
        case "*" => println(l * r)
        case "/" => println(l / r)
        case "?" =>
      }
    }
  }
}

Measured memory_bytes: 44040
import sys
from itertools import product
input = sys.stdin.readline


def inpl():
    return list(map(int, input().split()))


def solve(N, M):
    C = [int(input()) for _ in range(M)]
    X = [int(input()) for _ in range(N)]

    ret = [float('inf')] * 256
    ret[128] = 0
    cor = set((max(min(i + c, 255), 0), i) for c, i in product(C, list(range(256))))
    xt = tuple(tuple((x - t)**2 for x in range(256)) for t in range(256))
    for x in X:
        tmp = [float('inf')] * 256
        xt_now = xt[x]
        for t, i in cor:
            v = ret[i]
            if v + xt_now[t] < tmp[t]:
                tmp[t] = v + xt_now[t]
        ret = tmp[:]

    return min(ret)


def main():
    ans = []
    while True:
        N, M = inpl()
        if N == M == 0:
            break
        ans.append(solve(N, M))
    for a in ans:
        print(a)
    return

main()



Measured memory_bytes: 8472
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<iomanip>
#include <bitset>
#include<set>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 ll n;
 cin >> n;
 set<int> d;
 for(int i=0;i<n;i++){
   int a;
   cin >> a;
   d.insert(a);
 }
 cout << d.size();
 return 0;
}

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

int main(){
	int K;
	cin >> K;
	string S;
	cin >> S;

	string ans;
	if(S.size() <= K){
		ans = S;
	}else{
		ans = S.substr(0, K) + "...";
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    int A[n];
    int B[n];
    int C[n - 1];
    for (int i = 0; i < n; ++i)
    {
        cin >> A[i];
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> B[i];
    }
    for (int i = 0; i < n - 1; ++i)
    {
        cin >> C[i];
    }
    int ans = 0;
    int befo = -100;
    for (int i = 0; i < n; ++i)
    {
        ans += B[A[i] - 1];
        if (A[i] - befo == 1)
        {
            ans += C[A[i] - 2];
        }
        befo = A[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int h,w;cin>>h>>w;
    string s[h];
    rep(i,0,h)cin>>s[i];
    char a[h][w];
    char b[h][w];
    rep(i,0,h){
        rep(j,0,w){
            a[i][j]=s[i][j];
            b[i][j]=s[i][j];
        }
    }
    for(int i=0;i<h;i+=2){
        rep(j,1,w)a[i][j]='#';
    }
    rep(i,0,h)a[i][w-1]='#';
    for(int i=1;i<h;i+=2){
        rep(j,0,w-1)b[i][j]='#';
    }
    rep(i,0,h)b[i][0]='#';
    rep(i,0,h){
        rep(j,0,w)cout<<a[i][j];
        cout<<endl;
    }
    cout<<endl;
    rep(i,0,h){
        rep(j,0,w)cout<<b[i][j];
        cout<<endl;
    }
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
inline int read(){
	int num=0,f=1;
	char rd=getchar();
	while(!isdigit(rd)){
		if(rd=='-') f=-1;
		rd=getchar();
	}
	while(isdigit(rd)){
		num=num*10+rd-48;
		rd=getchar();
	}
	return f*num;
}
int main()
{
	string s;
	cin>>s;
	int len=s.length(),tot=0;
	char t[3]={'C','F','$'};
	for(int i=0;i<len;i++) if(s[i]==t[tot]) tot++;
	tot==2?printf("Yes\n"):printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    ll Ans;
    int a, b;

    cin >> N;
    int count = 0;
    bool flag = false;

    rep(i, N)
    {

        cin >> a >> b;
        if (a == b)
        {
            count++;
        }
        else
        {
            count = 0;
        }
        if (count == 3)
            flag = true;
    }
    if (flag )
    {

        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3644
#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++)

int main(){
  string S; cin >> S;
  
  char temp1 = S[0], temp2;
  int count1 = 1, count2 = 0;
  
  for(int i = 1; i < 4; i++){
    if(S[i] == temp1) count1++;
    else if(count2 == 0){
      count2++;
      temp2 = S[i];
    }
    else if(S[i] == temp2) count2++;
  }
  
  if(count1 == 2 && count2 == 2){
    cout << "Yes";
  }
  else cout << "No";
  
  return 0;
}

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

int main(){
  string order;
  int height,wide,x,y,num;
  while(1){
    x = 1; y = 1;
    cin >> wide >> height;
    if( wide == 0 && height == 0 ) break;
    int angle = 1;
    while(1){

      cin >> order;
      if( order == "STOP" ) break;

      if( order == "FORWARD" ){
	cin >> num;
	if( angle == 1 ){
	  y+=num;
	}
	else if( angle == 2 ){
	  x+=num;
	}
	else if( angle == 3 ){
	  y-=num;
	}
	else if( angle == 4 ){
	  x-=num;
	}
      }
      
      if( order == "BACKWARD" ){
	cin >> num;
	if( angle == 1 ){
	  y-=num;
	
	}
	else if( angle == 2 ){
	  x-=num;
	
	}
	else if( angle == 3 ){
	  y+=num;
	
	}
	else if( angle == 4 ){
	  x+=num;
	
	}
      }

      if( x < 1 ){
	x = 1;
      }else if( x > wide ){
	x = wide;
      }
	

      if( y < 1 ){
	y = 1;
      }else if( y > height ){
	y = height;
      }

      if( order == "RIGHT" ){
	angle++;
	if( angle == 5 ) angle = 1;
      }

      if( order == "LEFT" ){
	angle--;
	if( angle == 0 ) angle = 4;
      }
      
    }
    cout << x << " " << y << endl;
   
  }

  return 0;
}

Measured memory_bytes: 1208
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n)
    {
		string str;

		set < string > st;

		while(n--) cin >> str, st.insert(str);

		cout << st.size() << '\n';
    }


}






Measured memory_bytes: 19112
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vll = vector<long long>;
using vpi = vector<pair<int, int>>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;

#define F first
#define S second
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define F0R(i, a) for (int i = 0; i < (a); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)

const char nl = '\n';
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    int n, k; cin >> n >> k;
    vi a(n);
    F0R (i, n) cin >> a[i];
    vb win(k + 1, false);
    win[a[0]] = true;
    FOR (i, a[0] + 1, k) {
        bool good = false;
        F0R (j, n) {
            if (a[j] > i) break;
            if (!win[i - a[j]]) {
                good = true;
            }
        }
        win[i] = good;
    }
    cout << (win[k] ? "First" : "Second") << endl;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int c, d;
  c = a % 2;
  d = b % 2;
  
  if (c == 0 || d == 0){
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 3500
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>

#define DEBUG false

#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);

/*************Global variable  **************/
int N,D ;
char str[26];
std::map<char,int> M ;
/*******************************/
int times100(int x ){
  if(x%100 != 0)
    return 0 ;
  return times100(x/100) + 1;
}
int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  cin >> D >> N ;
  int cnt = 0 ;
  int ans;
  for(int x=1 ;; x++){
    if(times100(x) == D)
      cnt++;
    if(cnt == N)
    {
      ans = x;
      cout << ans << endl;
      return 0;
    }
  }

  return 0 ;
}

//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, int> Pll;
int main()
{
  int T, P, R;
  while(cin >> T >> P >> R, T || P || R) {
    ll point[T+1], miss[T+1][P+1], pena[T+1];
    CLR(pena), CLR(miss), CLR(point);
    FOR(i,0,R) {
      int in[3]; FOR(j,0,3) cin >> in[j];
      string mes; cin >> mes;
      if(mes[0] == 'C') {
        point[in[0]]++;
        pena[in[0]] += miss[in[0]][in[1]] * 1200 + in[2];
      } else {
        miss[in[0]][in[1]]++;
      }
    }
    vector<Pll> sum_point(T);
    FOR(i,0,T) {
      ll p = point[i+1] * 100000000 - pena[i+1] * 100 - i;
      sum_point[i] = Pll(p, i + 1);
    }
    sort(sum_point.rbegin(), sum_point.rend());
    FOR(i,0,T) {
      int j = sum_point[i].second;
      cout << j << " " << point[j] << " " << pena[j] << endl;
    }
  }
  return 0;
}

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

int main() {
  int W, A, B;
  cin >> W >> A >> B;
  
  int AA = A+W;
  int BB = B+W;
  
  if(A<=B) {
    if (AA<B) {
      cout << B-AA;
    }
    else {
      cout << 0;
    }
  }
  
  else {
    if (BB<A) {
      cout << A-BB;
    }
    else {
      cout << 0;
    }
  }
  return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

string s;
void compute() {

}

string arr[] = { "dreamer", "dream","eraser","erase" };

int main() {
  cin >> s;
  //cout << s.substr(0,(int)s.size()-3) << endl;
  bool update = true;
  while( update ) {
    update = false;
    rep(i,4) {
      int n = s.size();
      int m = arr[i].size();
      if( n >= m ) {
	if( s.substr(n-m) == arr[i] ) {
	  s = s.substr(0,n-m);
	  update = true;
	  break;
	}
      }
    }
  }
  if( s.size() ) puts("NO");
  else puts("YES");
  compute();
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, A;
  cin >> N >> A;
  if (N % 500 <= A) {
    print("Yes");
  } else {
    print("No");
  }
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

void solve(int x, int y, int s){
    int ans = 0;
    for(int i = 1; i < s; i++){
        int ni = i * (100 + x) / 100;
        for(int j = 1; j <= s - ni; j++){
            int nj = j * (100 + x) / 100;

            if(ni + nj == s){
                int mi = i * (100 + y) / 100;
                int mj = j * (100 + y) / 100;

                if(mi + mj > ans){
                    ans = mi + mj;
                }
            }
        }
    }
    cout << ans << endl;
}

signed main(){
    while(true){
        int x, y, s;
        cin >> x >> y >> s;

        if(x == 0 && y == 0 && s == 0){
            break;
        }

        solve(x, y, s);
    }

    return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> prefix_function(string s) {
    int n = (int)s.length();
    vector<int> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i - 1];
        while (j > 0 && s[i] != s[j])
            j = pi[j - 1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    string x;
    cin >> n >> x;
    int mx = 0;
    for (int i = 0; i < n-  1; i++) {
        vector<int> pi = prefix_function(x.substr(i));
        for (int j = 0; j < pi.size(); j++) mx = max(mx, min(pi[j], (j + 1) / 2));
    }
    cout << mx;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes() {
  cout << "Yes" << endl;
  exit(0);
}

void no() {
  cout << "No" << endl;
  exit(0);
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  REP(i, n) { cin >> a[i] >> b[i]; }
  vector<ll> ord(n);
  iota(ALL(ord), 0);
  sort(ALL(ord), [&](ll i, ll j) { return b[i] < b[j]; });
  ll now = 0;
  REP(i, n) {
    ll j = ord[i];
    if (now + a[j] > b[j]) {
      no();
    }
    now = now + a[j];
  }
  yes();
}

Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
struct edge {int to,cost;};
#define VMAX 51
//typedef std::pair<int,int> P;

    ll ans;
    string s,t;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>t>>s>>t;
    cout<<"A"<<s[0]<<"C";
    return 0;
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy

ans = dx*'R'+dy*'U'+dx*'L'+dy*'D'+'L'+(dy+1)*'U'+(dx+1)*'R'+'D'+'R'+(dy+1)*'D'+(dx+1)*'L'+'U'
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
    int N; cin >> N;
    vector<ll> A(N), B(N); rep(i, N) cin >> A[i] >> B[i];
    sort(range(A));
    sort(range(B));
    if (N % 2 == 0) {
        cout << (B[N / 2] + B[(N - 1) / 2]) - (A[N / 2] + A[(N - 1) / 2]) + 1 << endl;
    } else {
        cout << B[N / 2] - A[N / 2] + 1 << endl;
    }
}

struct boot {
    boot() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} boot_;


Measured memory_bytes: 6352
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let mut a = read![[i64]];

    let mut total = 0_usize;
    for i in 0..N {
        while a[i] > 0 && a[i] % 2 == 0 {
            a[i] /= 2;
            total += 1;
        }
    }

    println!("{}", total)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
typedef long long LL;
const LL P = 1e9+7;
const int N = 4e6+10;
const double pi = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
char s[N],t[N];
int a,b,nxt[N],ans,g[N],i,j;
 
int main(){
	scanf("%s%s",s+1,t+1),a=strlen(s+1),b=strlen(t+1);
	for(;a<b*2;a*=2)
		rep(i,1,a) s[i+a]=s[i];
	rep(i,1,a) s[i+a]=s[i];
	a*=2;
	rep(i,1,b){
		for (j=i; j>1 && t[nxt[j-1]]!=t[i]; j=nxt[j-1]-1);
		nxt[i]=nxt[j-1]+1;
	}
	for(i=1,j=1;i<=a;i++){
		while(j>1 && s[i]!=t[j]) j=nxt[j-1];
		if(s[i]==t[j]) j++;
		if(j==b+1) ans=max(ans,g[i]=g[i-b]+1);
	}
	printf("%d",ans>=a/b-1?-1:ans);
	return 0;
}

Measured memory_bytes: 23040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

ll mod = 1e9 + 7;

int main(){
	int a,b;

	cin >> a >> b;

	if(a<b){
		for(int i=0;i<b;i++){
			cout << a;
		}
	}else{
		for(int i=0;i<a;i++){
			cout << b;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int id,g,validl=-1,validr=1000000000;
  cin>>id>>g;
  for(int i=0;i<id;++i)
  { int a,b;
    cin>>a>>b;
   if(a>=validl)
     validl=a;
   if(b<=validr)
     validr=b;
  }
  
    cout<<max(0,validr-validl+1);
  return 0;
}
  
  

Measured memory_bytes: 256
import heapq
import sys

input = sys.stdin.readline

def dijkstra_heap(s,N,edge):
    d = [float('inf')] * N
    used = [True] * N
    d[s] = 0
    used[s] = False
    edgelist = []
    for a, b in edge[s]:
        heapq.heappush(edgelist, a * (10 ** 6) + b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge%(10**6)]:
            continue
        v = minedge % (10 ** 6)
        d[v] = minedge // (10 ** 6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def main():
    N, M = map(int, input().split())
    edge = [[] for i in range(N)]
    for i in range(N-1):
        edge[i+1].append([0,i])
    for i in range(M):
        L, R, C = map(int, input().split())
        L -= 1
        R -= 1
        edge[L].append([C,R])
        edge[R].append([C,L])
    d = dijkstra_heap(0,N,edge)
    if d[N-1] == float('inf'):
        print(-1)
    else:
        print(d[N-1])
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 92468
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    def f(n):
        d = {}
        for _ in range(n):
            c,a,b = LS()
            s = set()
            for i in range(int(a),int(b)+1):
                s.add(i)
            d[c] = s
        m = I()
        aa = LS()
        st = []
        for c in aa:
            if re.match(r'^\d+$', c):
                st.append(set([int(c)]))
            elif c in d:
                st.append(d[c])
            else:
                a,b = st[-2:]
                st = st[:-2]
                t = set()
                if c == '/':
                    if 0 in b:
                        return 'error'
                    for ai in a:
                        for bi in b:
                            t.add((ai//bi) % 256)
                elif c == '+':
                    for ai in a:
                        for bi in b:
                            t.add((ai+bi) % 256)
                elif c == '-':
                    for ai in a:
                        for bi in b:
                            t.add((ai-bi) % 256)
                else:
                    for ai in a:
                        for bi in b:
                            t.add((ai*bi) % 256)
                st.append(t)
        return 'correct'



    while True:
        n = I()
        rr.append(f(n))
        break

    return '\n'.join(map(str,rr))


print(main())



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

            

int main(){
	//freopen("in.txt","r",stdin);
	
	
	int n;
	cin>>n;
	int i=1000;
	while(i<n){
		i+=1000;
	}
	cout<<i-n;
	
	return 0;
}






Measured memory_bytes: 3628
#include <string>
#include <iostream>
#include <vector>
#include <algorithm> 
#include <bits/stdc++.h>

#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
using namespace std;
typedef unsigned long long int ull;
int main()
{
	int n;
	cin>>n;
	float s=0;
	float* a = new float[n];
	REP(i,0,n-1)
		cin>>*(a+i);
	
	std::sort(a,a+n);
	s=(a[0]+a[1])/2.0;
	REP(i,2,n-1)
	{
		s=(s+(a[i]))/2.0;
	}
	
	cout<<s;
	
	return 0;
}

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

using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int> v(N);

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

    int cnt=0;
    for(int i=0;i<N;i++){
        int tmp=v[i];
        while(tmp%2==0){
            tmp/=2;
            cnt++;
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define repeat(i,n) repeat_from(i,0,n)
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= (m); --(i))
#define repeat_reverse(i,n) repeat_from_reverse(i,0,n)
typedef long long ll;
using namespace std;
vector<int> primes(int n) {
    vector<bool> is_prime(n+1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i * i <= n; ++ i) {
        if (is_prime[i]) {
            for (int j = 2*i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    vector<int> result;
    for (int i = 0; i <= n; ++ i) {
        if (is_prime[i]) {
            result.push_back(i);
        }
    }
    return result;
}
constexpr int max_n = 1120;
constexpr int max_k = 14;
int main() {
    vector<int> ps = primes(max_n);
    array<array<ll,max_k+1>,max_n+1> dp = {};
    dp[0][0] = 1;
    for (int p : ps) {
        repeat_reverse (k, max_k+1) {
            repeat (n, max_n+1) {
                if (n-p >= 0 and k-1 >= 0) {
                    dp[n][k] += dp[n-p][k-1];
                }
            }
        }
    }
    while (true) {
        int n, k; cin >> n >> k;
        if (n == 0 and k == 0) break;
        cout << dp[n][k] << endl;
    }
    return 0;
}

Measured memory_bytes: 1348
S = input()
T = input()
ans = len(T)
for i in range(len(S)-len(T)+1):
  count = 0
  #print(S[i:i+len(T)], T)
  for s, t in zip(S[i:i+len(T)], T):
    if s != t:
      count += 1
  ans = min(count, ans)
print(ans)

Measured memory_bytes: 73452
def outxs(head)
  return [] if !head
    [head[:v]] + outxs(head[:next])
end

def r(xs, m)
  n = xs.size

  llist = xs.map.with_index{ |v,i| { v:v, i:i } }


  sorted_list = llist.sort_by{ |e| e[:v] }.each_with_index{ |e,s| e[:s] = s }

  (1...xs.size).each{ |i|
    sorted_list[i][:prev] = sorted_list[i-1]
    sorted_list[i-1][:next] = sorted_list[i]
  }


  cumm = sorted_list[0,m].map{ |e| e[:v] }.inject(:+)

  on_border = sorted_list[m-1]
  head = sorted_list[0]


  ans = [cumm]
  llist[0,n-m].each { |e|

    if e[:s] <= on_border[:s]
      on_border = on_border[:next]
      cumm += on_border[:v] - e[:v]
    end

    pv, nx = e[:prev], e[:next]
    (pv[:next] = nx) if pv
    (nx[:prev] = pv) if nx
    e[:prev] = nil
    e[:next] = nil

    (head = nx) if head == e

    ans << cumm
  }
  ans
end

N = $stdin.gets.chomp.to_i
A = $stdin.gets.chomp.split(" ").map(&:to_i)

A1 = r(A[0,2*N].reverse.map{ |v| -v }, N).reverse.map{ |v| -v }
A2 = r(A[N,2*N], N)
puts A1.zip(A2).map{ |t| t[0]-t[1] }.max


Measured memory_bytes: 127284
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int cnt = 0;
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        if(tmp >= k)
        {
            cnt++;
        }
    }
    cout << cnt;

    return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	cout << N / 3 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int d, t, s; cin >> d >> t >> s;
	if (s * t >= d) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

bool prime(ll N) {
    if (N == 1) return false;
    for (ll i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main() {
    vector<ll>data(1e5+10,0);
    for(ll i=1;i<1e5+10;i+=2){
        if(prime(i)&&prime((i+1)/2)){
            data[i]++;
        }
    }
    for(ll i=1;i<1e5+10;i++){
        data[i]+=data[i-1];
    }
    ll q;
    cin >> q;
    for(ll i=0;i<q;i++){
        ll l,r;
        cin >> l >> r;
        ll ans=data[r]-data[l-1];
        cout << ans << endl;
    }
}

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

int main()
{
  int n;
  float a,sum,b;
  cin>>n;
  for(int i = 0;i<n;i++)
  {
    cin>>a;
    b = 1.0/a;
    sum+=b;
  }
  float ans = 1.0/sum;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256