akhauriyash/Code-Regression huggingface dataset:
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####

from collections import defaultdict as ddic

def solve(N, K, A):
    A.sort()
    ans = 0
    for i in range(K):
        ans += A[i]
    return ans
N, K=rrm()
A= rrm()
print solve(N,K,A)


Measured memory_bytes: 67044
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
const int SIZE=5+2*1e5;
const LL INF=1<<30;
int maps[10][10];
bool solve(){

	int H,W;
	int co=0;
	cin >> H >> W;
	REP(i,H){
		string s;
		cin >> s;
		REP(j,W){
			maps[i][j]=s[j]=='#';
			co+=maps[i][j];
		}

	}
	maps[0][0]=2;
	REP(i,H) REP(j,W){
		if(maps[i][j]==2){
			if(maps[i+1][j]==1) maps[i+1][j]=2;
			else if(maps[i][j+1]==1) maps[i][j+1]=2;
			co--;
		}
		else if(maps[i][j]==1){
			return false;
		}
	}
	return co==0;
}
int main(){
	cout << (solve()?"Possible":"Impossible") << endl;
	
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.TreeSet;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	public static void main(String[] __){
		cases:
		for(int q=getInt();q>0;q--) {
			int t=getInt();
			final int bufd=t;
			int digit=IntStream.iterate(1,i->i*10).limit(8).filter(i->i<=bufd).max().orElse(0);
			
			TreeSet<Integer>log=new TreeSet<>();
			int c=0;
			for(;t>9;c++) {
				int l=0,r=t,max=Integer.MIN_VALUE,d=digit;
				while(d!=1) {
					l*=10;
					l+=r/d;
					r%=d;
					d/=10;
					max=Math.max(l*r,max);
				}
				if(!log.add(t=max)) {
					System.out.println(-1);
					continue cases;
				}
			}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 32780
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
  lint X, Y;
  cin >> X >> Y;

  for(lint a=0; a<=X; a++) {
    lint b = X - a;
    if(a*2 + b*4 == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3592
import sys

n = int(input())
s = list(input())

if n == 1:
    print(1)
    sys.exit()

a = []

for i in range(n-1):
    if s[i] != s[i+1]:
        a.append(s[i])

if len(a) == 0:
    print(1)
else:
    if a[-1] != s[-1]:
        a.append(s[-1])

    print(len(a))


Measured memory_bytes: 10476
#include <iostream>
#include <cstdio>
#include <vector>
#define N 3010
using namespace std;
vector<int> e[N];
int sg[N],a[N],n;
void dfs(int p,int fa)
{
	sg[p] = 0;
	for (int i = 0;i < e[p].size();i++)
	{
		int x = e[p][i];
		if (x != fa&&a[p] > a[x])
		{
			dfs(x,p);
			if (!sg[x]) sg[p] = 1;
		}
	}
}
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	for (int i = 2;i <= n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	for (int i = 1;i <= n;i++)
	{
		dfs(i,0);
		if (sg[i]) printf("%d ",i);
	}
	return 0;
}


Measured memory_bytes: 512
// AOJ Volume 0 Problem 0028

#include <stdio.h>

int freq[101];

int main(void)
{
	int num;
	int max;
	int i;
	
    while (scanf("%d", &num) != EOF){
		freq[num]++;
	}
	
	max = 0;
	for (i = 1; i <= 100; i++){
		if (max < freq[i]){
			max = freq[i];
		}
	}
	
	for (i = 1; i <= 100; i++){
		if (max == freq[i]){
			printf("%d\n", i);
		}
	}
	
    return (0);
}

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

using namespace std;
const int Max_Num=85;
const int Max_Dif=7000;

int main(){
  int H, W;
  cin >> H >> W;
  int A[Max_Num][Max_Num];
  int B[Max_Num][Max_Num];
  rep(i,H){
    rep(j,W) cin >> A[i+1][j+1];
  }
  rep(i,H){
    rep(j,W) cin >> B[i+1][j+1];
  }
  int dif[Max_Num][Max_Num];
  rep(i,H){
    rep(j,W) dif[i+1][j+1]=abs(A[i+1][j+1]-B[i+1][j+1]);
  }
  bool dp[Max_Num][Max_Num][Max_Dif*4];
  rep(i,H+1){
    rep(j,W+1){
      rep(k,Max_Dif*4) dp[i][j][k]=false;
    }
  }
  dp[1][0][Max_Dif*2]=true;
  dp[0][1][Max_Dif*2]=true;
  rep(i,H){
    rep(j,W){
      int d=dif[i+1][j+1];
      for(int k=Max_Dif; k<Max_Dif*3; k++){
        if(dp[i+1][j][k]) dp[i+1][j+1][k+d]=true, dp[i+1][j+1][k-d]=true;
        if(dp[i][j+1][k]) dp[i+1][j+1][k+d]=true, dp[i+1][j+1][k-d]=true;
      }
    }
  }
  rep(i,Max_Dif){
    if(dp[H][W][Max_Dif*2+i]||dp[H][W][Max_Dif*2-i]){
      cout << i << endl;
      break;
    }
  }

  return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int a[maxn];

int main() {
    int n, minn = inf, cnt = 0;
    ll sum = 0, res = 0, tmp = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (a[i] >= 0) sum += a[i];
        else tmp += a[i], cnt++;
        minn = min(minn, abs(a[i]));
    }
    if (cnt & 1) res = sum - tmp - minn - minn;
    else res = sum - tmp;
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 640
n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(j) for j in input().split()]

ans = 0


for i in range(q):
    key = T[i]
    for j in range(n):
        if key == S[j]:
            ans += 1
            break
        else:
            continue

print(ans)


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

template <class T>
struct RangeSum {
  vector<T> vec;
  RangeSum() {}
  RangeSum(vector<T> elems) : vec(elems) {
    for (int i = 1; i < vec.size(); i++) { vec[i] += vec[i - 1]; }
  }
  T sum(int l, int r) {
    if (l > r) return T(0);
    if (l == 0)
      return vec[r];
    else
      return vec[r] - vec[l - 1];
  }
};

void solve() {
  ll n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 1 << endl;
    return;
  }
  if (n == 1) {
    cout << m - 2 << endl;
    return;
  }
  if (m == 1) {
    cout << n - 2 << endl;
    return;
  }
  cout << n * m - (n - 1 + m - 1) * 2 << endl;
  return;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();
  return 0;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    // "sort"
)

func main() {
    // var n int
    // fmt.Scan(&n, &x)
    // nums := make([]int,n);
    // m := make(map[int]int)

    var s string
    fmt.Scan(&s)
    a := make([]int ,26)

    for i := 0; i < len(s); i++ {
    	a[s[i]-'a']=i+1
    }
    b := "abcdefghijklmnopqrstuvwxyz"

    for i := 0; i < len(a); i++ {
    	if a[i]==0 {
			fmt.Println(s+b[i:i+1])
			return
    	}
	}

    for i := 0; i < len(s); i++ {
    	a[i]=0
    }
	a[s[25]-'a'] = 1
    for i := 24; 0 <= i; i-- {
    	if s[i]<s[i+1] {
    		for t := int(s[i]-'a'); t < len(s); t++ {
    			if  a[t]>0 {
					fmt.Println(s[0:i]+b[t:t+1])    				
					return
    			}
    		}
    	} else {
    		a[s[i]-'a'] = 1
    	}    	
	}
	

	fmt.Println(-1)
}

Measured memory_bytes: 512
class Dice      
    @face = nil         
                        
    def initialize ary   
        @face = ary        
    end                     

    def top
        @face[0]
    end

    def rotate news     
        f = @face.dup
        case news
        when "N"
            @face = [f[1],f[5],f[2],f[3],f[0],f[4]]
        when "E"
            @face = [f[3],f[1],f[0],f[5],f[4],f[2]]
        when "W"
            @face = [f[2],f[1],f[5],f[0],f[4],f[3]]
        when "S"
            @face = [f[4],f[0],f[2],f[3],f[5],f[1]]
        end
    end

    def right top,front
        "SWSWS".each_char do |c|
            break if @face[0] == top
            rotate c
        end
        rotate "N"
        "WWW".each_char do |c|
            break if @face[0] == front
            rotate c
        end
    @face[2]
    end
end

numbers = gets.chomp.split
dice = Dice.new numbers
gets.to_i.times do 
    top,front = gets.chomp.split
    puts dice.right top,front
end


Measured memory_bytes: 8872
/*
	Failure is not the reason for you to stop trying 
	   it is actually a remainder that you should 
			KEEP GOING 
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n ,a;
		cin>>n>>a;
		cout << (n<a ? "0" : "10");
	
	
	}
	
	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int h,w,i,j,k,c=0,x[]={-1,0,1,-1,1,-1,0,1},y[]={-1,-1,-1,0,0,1,1,1};
	char a[55][55];

	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++)	
		scanf("%s",a[i]);

	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(a[i][j]=='.'){
				for(k=0;k<8;k++)
					if(a[i+y[k]][j+x[k]]=='#')
						c++;
				printf("%d",c);
				c=0;
			}
			else
				printf("#");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
N=gets.to_i
s=Array.new
t=Array.new
N.times do |i|
    a,b=gets.chomp.split
    b=b.to_i
    s.push(a)
    t.push(b)
end
X=gets.chomp
res=0
f=false
N.times do |i|
    res+=t[i] if f
    f=true if s[i]==X
end
puts res


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

int main(){
 int n,W;
 cin>>n>>W;

 int v[n];
 int w[n];

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

 int DP[n+1][W+1];

 for(int j=0;j<=W;j++){
	DP[0][j]=0;
 }

 for(int i=1;i<=n;i++){
	for(int j=0;j<=W;j++){
		if(j<w[i-1]){
			DP[i][j]=DP[i-1][j];
		}else{
			if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1]){
				DP[i][j]=DP[i-1][j];
			}else{
				DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];
			}
		}
	}
 }
 cout<<DP[n][W]<<endl;
return 0;
}

Measured memory_bytes: 7004
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

long fact[101010];
long factinv[101010];

long mpow(long a, long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long d = mpow(a, n / 2);
        return d * d % MOD;
    }
    return a * mpow(a, n - 1) % MOD;
}

void make() {
    fact[0] = 1;
    REPI(i,1,101010) {
        fact[i] = fact[i-1] * i % MOD;
    }
    REP(i,101010) {
        factinv[i] = mpow(fact[i], MOD - 2);
    }
}

void check() {
    REP(i,101010) {
        if (fact[i] * factinv[i] % MOD != 1) {
            cout << "ERROR" << endl;
            exit(1);
        }
    }
}

long comb(long n, long k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return fact[n] * factinv[k] % MOD * factinv[n - k] % MOD;
}

int main() {
    make();
    check();
    long n;
    cin >> n;
    VI v;
    long sum = 0;
    REP(i,n+1) {
        long a;
        cin >> a;
        v.push_back(a);
        sum += a;
    }
    long dbl = sum - n * (n + 1) / 2;
    long l = -1, r, p = 0;
    while (p < n + 1) {
        if (v[p] == dbl && l == -1) l = p;
        else if (v[p] == dbl) {
            r = p;
            break;
        }
        p++;
    }
    REP(i,n+1) {
        long ans = (comb(n+1,i+1) - comb(l+n-r,i) + MOD) % MOD;
        cout << ans << endl;
    }
}


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

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

    vector<vector<int>> v(n);
    int a, b;
    for(int i = 0; i < n-1; i++){
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    int disto[n], distn[n];
    stack<pair<pair<int,int>, int>> s;
    
    s.push({{-1, 0}, 0});
    while(!s.empty()){
        pair<pair<int,int>,int> x = s.top();    s.pop();
        int parent = x.first.first;
        int now = x.first.second;
        int depth = x.second;
        disto[now] = depth;
        for(int next : v[now]){
            if(next != parent)  s.push({{now, next}, depth+1});
        }
    }
    
    s.push({{-1, n-1}, 0});
    while(!s.empty()){
        pair<pair<int,int>,int> x = s.top();    s.pop();
        int parent = x.first.first;
        int now = x.first.second;
        int depth = x.second;
        distn[now] = depth;
        for(int next : v[now]){
            if(next != parent)  s.push({{now, next}, depth+1});
        }
    }

    int fen = 0, snu = 0;
    for(int i = 0; i < n; i++){
        if(distn[i] >= disto[i])    fen++;
        else                        snu++;
    }

    if(fen <= snu)  cout << "Snuke" << endl;
    else                cout << "Fennec" << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	double r, S, A;

	cin >> r;

	S = M_PI * r*r;
	A = 2 * M_PI*r;

	cout <<fixed << setprecision(6)<< S << " " <<fixed<<setprecision(6)<< A << "\n";

    return 0;
}




Measured memory_bytes: 3284
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, X; cin >> N >> X;
    vector< tuple<int, int, int> > tups;
    for(int i=0; i<N; i++) {
        int b, l, u; cin >> b >> l >> u;
        tups.emplace_back(b, l, u);
    }
    sort(tups.begin(), tups.end(), [&](auto x, auto y) {
            int xb, xl, xu, yb, yl, yu;
            tie(xb, xl, xu) = x;
            tie(yb, yl, yu) = y;

            int vl = xl * xb + xu * (X - xb);
            int vr = yl * yb + yu * (X - yb);
            return vl > vr;
        });

    int D = 0;
    vector<int> acc(N+1), val(N);
    for(int i=0; i<N; i++) {
        int b, l, u; tie(b, l, u) = tups[i];
        D -= b * l;
        val[i  ] = l * b + u * (X - b);
        acc[i+1] = acc[i] + val[i];
    }

    int ub = X*N, lb = -1;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;

        bool ok = false;
        // 中途半端に選ぶものが i 番目の要素
        int q = mid / X, R = mid % X;
        for(int i=0; i<N; i++) {
            int d = D, r = R;
            int b, l, u; tie(b, l, u) = tups[i];
            d += l * min(r, b);
            r -= min(r, b);
            d += u * r;

            if(i < q) {
                d += acc[q+1] - val[i];
            }
            else {
                d += acc[q];
            }
            ok |= (d >= 0);
        }

        if(ok) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
    return 0;
}


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

int main() {

  int64_t h, w, s, result;

  cin >> h >> w;
  s = h * w;

  if (h == 1 || w == 1) {
    result = 1;
  } else if (s % 2 == 1) {
    result = s / 2 + 1;
  } else {
    result = s / 2;
  }

  cout << result << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

void solve() {
    int n; scanf("%d", &n); if (n == 0) exit(0);
    vector<int> p(n), t(n); for (int i = 0; i < n; i++) scanf("%d %d", &p[i], &t[i]);
    vector<vector<int>> dp(n + 1, vector<int>(4, inf));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            if (dp[i][j] == inf) continue;
            int len = p[i];
            if (i) len -= p[i - 1];
            len = abs(len);
            int tt = t[i];
            if (i) tt -= t[i - 1];
            if (len * (j + 1) <= tt) {
                chmin(dp[i + 1][j + 1], dp[i][j] + len);
            }
        }
        for (int j = 1; j < 4; j++) {
            if (dp[i][j] == inf) continue;
            int lt = p[i];
            if (i) lt += p[i - 1] * (j + 1);
            int len = p[i];
            if (i) len += p[i - 1];
            int tt = t[i];
            if (i) tt -= t[i - 1];
            if (lt <= tt) {
                chmin(dp[i + 1][1], dp[i][j] + len);
            }
        }
        if (*min_element(dp[i + 1].begin(), dp[i + 1].end()) == inf) {
            printf("NG %d\n", i + 1);
            return;
        }
    }
    printf("OK %d\n", *min_element(dp[n].begin(), dp[n].end()) + p.back());
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
    int kkt = 89;
    while (kkt) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3224
#include<iostream>

using namespace std;

int main(){
    long N, T, a;
    cin >> N >> T >> a;
    int surplus[N], max_a[N], min_a, count=0, flag=0, count2=0;
    max_a[0] = a;
    min_a = a;
    surplus[0] = max_a[0] - min_a;
    for (int i=1; i<N; i++){
        cin >> a;

        if (a > max_a[count]){
            max_a[count] = a;
            surplus[count] = max_a[count] - min_a;
            count2 = 0;
        }else if (a < min_a){
            for(int j=1; j <= count2; j++){
                count ++;
                surplus[count] = surplus[count-1];    
            }
            count ++; 
            flag = 0;
            min_a = a;  
            max_a[count] = a;
            surplus[count] = max_a[count] - min_a;

        }
    }

    int cost=1, max_surplus;
    max_surplus = surplus[0];
    for (int i=1; i <= count; i++){
        //cout << surplus[i] << endl;
        if (surplus[i] > max_surplus){
            cost = 1;
            max_surplus = surplus[i];
        }else if(surplus[i] == max_surplus){
            cost++;
        }
    }
    cout << cost << endl;
    return 0;
}

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

int main() {
	int a, b, c, d;
  	cin >> a >> b >> c >> d;
  	int L = a+b, R = c+d;
    if (L>R) cout << "Left" <<endl;
    if (L==R) cout << "Balanced" << endl;
    if (L<R) cout << " Right" << endl;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  if(s == "RSR"){
    cout<<1<<endl;
    return 0;
  }
  for(int i=0;i<3;i++){
    if(s[i] == 'R')ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
"""
    dp[h][w]: h番目のrow(h: 0~H(終着))で棒w(w: 0~W-1)にいる状態になるための横線(0~h)の組合せ数
    dp[h][w] = A*dp[h-1][w-1] + B*dp[h-1][w] + C*dp[h-1][w+1] O(100*8)
    A, B, Cはなんかうまいこと決めれそう。(全探索でもO(7*7*7))
    """
def main():
    import sys
    input = sys.stdin.readline
    H, W, K = map(int, input().split())
    dp = [[0]*W for _ in range(H+1)]
    dp[0][0] = 1
    for h in range(1, H+1):
        for w in range(W):
            A, B, C = 0, 0, 0
            for i in range(2 ** (W-1)):
                lines = []
                for j in range(W-1):
                    if ((i >> j) & 1):
                        if lines and lines[-1]:
                            break
                        lines.append(True)
                    else:
                        lines.append(False)
                else:
                    if w-1 >= 0 and lines[w-1]:
                        A += 1
                    elif w <= W-2 and lines[w]:
                        C += 1
                    else:
                        B += 1
            if w-1 >= 0:
                dp[h][w] += dp[h-1][w-1] * A
            dp[h][w] += dp[h-1][w] * B
            if w+1 <= W-1:
                dp[h][w] += dp[h-1][w+1] * C
    print(dp[H][K-1] % (10**9+7))
    

if __name__ == '__main__':
    main()

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

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

char s[1000000];

int main() {
    scanf(" %s", s);
    int l = strlen(s);
    int x = 0;
    int y = 0;
    FO(i,0,l) {
        if (s[i] == 'T') y--;
        if (y < 0) {
            y = 0; x++;
        }
        if (s[i] == 'S') y++;
    }
    printf("%d\n", x*2);
}



Measured memory_bytes: 384
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = max(0, -a[0] + 1)
sm = 1
if a[0] >= 1:
  res = 0
  sm = a[0]
#print(res, sm)
for i in range(1, N):
  if sm > 0:
    res += max(-1, a[i] + sm) + 1
    sm = min(-1, sm + a[i])
  else:
    res += -min(1, sm + a[i]) + 1
    sm = max(1, sm + a[i])
  #print(res, sm)
res2 = max(0, a[0] + 1)
sm = -1
if a[0] <= -1:
  res2 = 0
  sm = a[0]
for i in range(1, N):
  if sm > 0:
    res2 += max(-1, a[i] + sm) + 1
    sm = min(-1, sm + a[i])
  else:
    res2 += -min(1, sm + a[i]) + 1
    sm = max(1, sm + a[i])
  #print(res2, sm)
#print(res, res2)
print(min(res, res2))

Measured memory_bytes: 59120
#include<stdio.h>
#define MAX 1000

int main(){
  int n,H,i,A[MAX];
  scanf("%d",&H);
  for(i=1;i<=H;i++) scanf("%d",&A[i]);
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i!=1) printf("parent key = %d, ",A[i/2]);
    if(2*i<=H) printf("left key = %d, ",A[i*2]);
    if(2*i+1<=H) printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2048
#include <vector>
#include <iostream>
#include <climits>

using namespace std;

const int kSize = 200000;

int main() {
    int A[kSize];
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    int ans = INT_MIN;
    int min_v = A[0];

    for (int i = 1; i < n; ++i) {
        ans = max(ans, A[i] - min_v);
        min_v = min(min_v, A[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define MOD 1000000007
 
int main(){
    string S; cin >> S;
    long long int sum = stol(S);
    for(int bit = 1; bit < (1<<(S.length()-1)); bit++){
        vector<int> v;
        for(int i = 0; i < (S.length()-1); i++){
            if(bit & (1<<i)) v.push_back(i);
        }

        int l = 0; int n = S.length() - 1;
        for(int i = v.size() - 1; i >= 0; i--){
            sum += stol(S.substr(l, n - v[i]));
          	l = l + n - v[i]; n = v[i];
        }
      	sum += stol(S.substr(l));
    }
    cout << sum;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;
ll dx[] = { 1,1,0,-1,-1,-1,0,1 };
ll dy[] = { 0,1,1,1,0,-1,-1,-1 };
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}

ll MOD = 1000000007;
int main() {
	ll H, W;
	cin >> H >> W;
	ll cnt = 0;
	char c[10][10];
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> c[i][j];
			if (c[i][j] == '#')
				cnt++;
		}
	}
	if (H + W - 1 == cnt)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

bool judge_one(long long N, vector<long long> &A){
    for(long long i=0; i<N-1; i++)
        if(A[i] >= A[i+1])
            return false;
    return true;
}

bool judge(long long N, vector<long long> &A, long long M){
    map<long long, int> mp;
    for(long long i=1; i<N; i++){

        if(A[i-1] >= A[i]){
            vector<int> v;
            for(auto itr=mp.rbegin(); itr!=mp.rend(); itr++){
                if(itr->first >= A[i]) v.push_back(itr->first);
                   // itr->second = 0;
                else break;
            }
            for(auto k : v)
                mp.erase(k);

            int pos = A[i]-1;
            while(true){
                if(mp[pos] == M-1){
                    if(pos == 0) return false;
                    mp.erase(pos);
                    //mp[pos] = 0;
                    pos--;
                }else{
                    mp[pos]++;
                    break;
                }
            }
        }

        //for(auto x : mp)
        //    cerr << x.first << ":" << x.second << " ";
        //cerr << endl;
    }
    return true;
}

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

    if(judge_one(N, A)){
        cout << 1 << endl;
        return 0;
    }

    long long lb = 1;
    long long ub = N;
    while(ub - lb > 1){
        long long mid = (lb+ub)/2;
        if(judge(N, A, mid)) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
#define N 100010
ll dp[N],w[N],v[N];
int main(){
	ll n,m;
	cin>>n>>m;
	ll sum=0;
	for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++)sum+=v[i];
	for(int i=0;i<=sum;i++)dp[i]=bql;
	dp[0]=0;
	for(int i=1;i<=n;i++)
		for(int j=sum;j>=v[i];j--)
			dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
	for(int i=sum;i>=0;i--)if(dp[i]<=m)return cout<<i<<endl,0;
}

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

int main(){
  double  n, t, a;
  cin >> n >> t >> a;
  vector<double>height(n);
  vector<double>ther(n);
  for (double i = 0; i < n; i++){
    cin >> height.at(i);
    ther.at(i) = t - height.at(i)*0.006;
    ther.at(i) = abs(ther.at(i) - a);
  
  }
  int ans = 1;
  double min = ther.at(0);
  for (double i = 1; i < n; i++){
    if (ther.at(i) < min){
      ans = i+1;
      min = ther.at(i);
    }
    else
      continue;
  }
  cout << ans << endl;
}
  

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

using namespace std;
typedef long long ll;
#define int ll

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; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int N, K;
    cin >> N >> K;
    vector<bool> cnt(N, false);
    REP(i, K) {
        int d;
        cin >> d;
        REP(j, d) {
            int a;
            cin >> a;
            a--;
            cnt[a] = true;
        }
    }
    int ans = 0;
    REP(i, N) {
        if(cnt[i] == false) { ans++; }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 3744
#include <stdio.h>

#define HOUR    (3600) //sec
#define MINUTE  (60)   //sec
int main()
{
  int inp_sec;
  int hour,minite;
  scanf("%d",&inp_sec);

  hour = inp_sec / HOUR;
  inp_sec -= hour * HOUR;

  minite = inp_sec / MINUTE;
  inp_sec -= minite * MINUTE;

  printf("%d:%d:%d\n",hour,minite,inp_sec);
  return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	int n, ans=0;
	cin >> n;
	string s;
	cin >> s;
	for(int i = 1; i < n-1; i++){
		int pre = 0;
		bool son[30][2]={false};
		for(int j = 0; j < i; j++)son[s[j]-'a'][0]=true;
		for(int j = i; j < n; j++)son[s[j]-'a'][1]=true;
		for(int j = 0; j < 30; j++)if(son[j][0] && son[j][1])pre++;
		ans = max(ans, pre);
	}
	cout << ans << endl;
    return 0;
}

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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int w, h, n; cin >> w >> h >> n;
    int x1 = 0, x2 = w, y1 = 0, y2 = h;
    REPI(i, n){
        int a, b, c; cin >> a >> b >> c;
        if(c == 1) x1 = max(x1, a);
        if(c == 2) x2 = min(x2, a);
        if(c == 3) y1 = max(y1, b);
        if(c == 4) y2 = min(y2, b);
    }cout << (x1 < x2 && y1 < y2 ? (x2 - x1) * (y2 - y1) : 0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 2000005
#define mod 998244353
ll tree[MAX] = {0}; 
ll lazy[MAX] = {0}; 
void updateRangeUtil(ll si, ll ss, ll se, ll us, 
					ll ue, ll diff) 
{ 
	if (lazy[si] != 0) 
	{ 
		tree[si] += (se-ss+1)*lazy[si]; 
		tree[si] %= mod;
		if (ss != se) 
		{ 
			lazy[si*2 + 1] += lazy[si]; 
			lazy[si*2 + 1] %= mod;
			lazy[si*2 + 2] += lazy[si]; 
			lazy[si*2 + 2] %= mod;
		} 
		lazy[si] = 0; 
	} 
	if (ss>se || ss>ue || se<us) 
		return ; 
	if (ss>=us && se<=ue) 
	{ 
		tree[si] += (se-ss+1)*diff; 
		tree[si] %= mod;
		if (ss != se) 
		{ 
			lazy[si*2 + 1] += diff; 
			lazy[si*2 + 1] %=mod; 
			lazy[si*2 + 2] += diff; 
			lazy[si*2 + 2] %= mod;
		} 
		return; 
	} 
	ll mid = (ss+se)/2; 
	updateRangeUtil(si*2+1, ss, mid, us, ue, diff); 
	updateRangeUtil(si*2+2, mid+1, se, us, ue, diff); 
	tree[si] = tree[si*2+1] + tree[si*2+2]; 
	tree[si] %= mod;
} 
void updateRange(ll n, ll us, ll ue, ll diff) 
{ 
updateRangeUtil(0, 0, n-1, us, ue, diff); 
} 
ll getSumUtil(ll ss, ll se, ll qs, ll qe, ll si) 
{ 
	if (lazy[si] != 0) 
	{ 
		tree[si] += (se-ss+1)*lazy[si]; 
		tree[si] %= mod;
		if (ss != se) 
		{ 
			lazy[si*2+1] += lazy[si]; 
			lazy[si*2+1] %= mod; 
			lazy[si*2+2] += lazy[si]; 
			lazy[si*2+2] %= mod; 
		} 
		lazy[si] = 0; 
	} 
	if (ss>se || ss>qe || se<qs) 
		return 0; 
	if (ss>=qs && se<=qe) 
		return tree[si]; 
	ll mid = (ss + se)/2; 
	ll mkp =  getSumUtil(ss, mid, qs, qe, 2*si+1) + 
		getSumUtil(mid+1, se, qs, qe, 2*si+2); 
	mkp %= mod;
	return mkp;
} 
ll getSum(ll n, ll qs, ll qe) 
{ 
	if (qs < 0 || qe > n-1 || qs > qe) 
	{ 
		exit(78); 
	} 
	return getSumUtil(0, n-1, qs, qe, 0); 
} 
void constructSTUtil(ll arr[], ll ss, ll se, ll si) 
{ 
	if (ss > se) 
		return ; 
	if (ss == se) 
	{ 
		tree[si] = arr[ss]; 
		return; 
	} 
	ll mid = (ss + se)/2; 
	constructSTUtil(arr, ss, mid, si*2+1); 
	constructSTUtil(arr, mid+1, se, si*2+2); 
	tree[si] = tree[si*2 + 1] + tree[si*2 + 2]; 
} 
void constructST(ll arr[], ll n) 
{ 
	constructSTUtil(arr, 0, n-1, 0); 
} 
int main() 
{ 
	//freopen("in", "r", stdin);
	ll n, k;
    cin >>n >>k;
    ll arr[n+10];
    for(int i = 0; i < n+5; i++) arr[i] = 0;
    arr[0] = 1;
    constructST(arr, n); 
    vector<pair<ll,ll>>ami(k);
    for(auto &a: ami) {
        cin >> a.first; cin >> a.second;
    }
    for(int i = 0; i < n; i++){
        for(auto a: ami){
			if(i+a.first >= n) continue;
            updateRange(n, i+a.first, min(i+a.second, n-1), getSum(n, i, i));
        }
    }
    cout << getSum(n, n-1, n-1) << endl;
} 


Measured memory_bytes: 13376
N = int(input())
t,x,y = 0,0,0

for i in range(N):
	T,X,Y = map(int,input().split())
	t_res = (T-t)
	xy_res = abs(X-x)+abs(Y-y)
	if (t_res - xy_res) % 2 == 0 and t_res >= xy_res:
		ans = 'Yes'
		t,x,y = T,X,Y
	else:
		ans = 'No'
		for j in range(N-(i+1)):
			input()
		break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int n;
  cin >> n;
  if(n%2 == 0) cout << n << endl;
  else cout << n*2 << endl;
}

Measured memory_bytes: 256
N = int(input())
S = [i for i in input()]
A = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(len(S)):
  S[i] = A[A.index(S[i])+N]
print(''.join(S))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, answer;
    int sum = 0;
    int temp_a = 0;
    int temp_b = 0;
    number_n = Integer.parseInt(sc.next());
    int[] weight = new int[number_n];
    for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    }
    for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    }
    temp_a = sum - 2 * temp_a;
    temp_b = sum - 2 * temp_b;
    temp_a = Math.abs(temp_a);
    temp_b = Math.abs(temp_b);
    if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    }
    System.out.println(answer);
  }
}


Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner (System.in);
        int a = sc.nextInt();
        if(a==25)
        {
            System.out.println("Christmas");
        }
        else if (a==24)
        {
            System.out.println("Christmas Eve");
        }
        else if (a==23)
        {
            System.out.println("Christmas Eve Eve");
        }
        else if (a==22)
        {
            System.out.println("Christmas Eve Eve Eve");
        }
        
        
        
    }

}

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N, Q;
	cin >> N >> Q;
	while (Q--) {
		int u, v;
		cin >> u >> v;
		if (N == 1) {
			cout << min(u, v) << endl;
			continue;
		}
		vector<int> x, y;
		while (u > 0) {
			x.push_back(u);
			u = (u + N - 2) / N;
		}
		while (v > 0) {
			y.push_back(v);
			v = (v + N - 2) / N;
		}
		reverse(y.begin(), y.end());
		for (auto val : x) {
			if (binary_search(y.begin(), y.end(), val)) {
				printf("%d\n", val);
				break;
			}
		}
	}
	return 0;
}


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

int main(void) {
  int i, n, j, k;
  double x1, y1, x2, y2, x3, y3;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
    double xt1 = (x1 + x2) / 2, xt2 = (x3 + x2) / 2, yt1 = (y1 + y2) / 2, yt2 = (y3 + y2) / 2;
    double t1 = y1 - y2, t2 = y2 - y3;
    double x, y, k1, k2;
    if(!t1) {
      x = xt1;
      k2 = -(x2 - x3) / (y2 - y3);
      y = k2 * (x - xt2) + yt2;
    } else if(!t2) {
      x = xt2;
      k1 = -(x1 - x2) / (y1 - y2);
      y = k1 * (x - xt1) + yt1;
    } else {
      k1 = -(x1 - x2) / (y1 - y2), k2 = -(x2 - x3) / (y2 - y3);
      x = ((k1 * xt1 - k2 * xt2) - (yt1 - yt2)) / (k1 - k2);
      y = k1 * (x - xt1) + yt1;
      //printf("%f %f ", k1, k2);
    }
    double r = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
    //printf("%f %f %f %f\n", xt1, yt1, xt2, yt2);
    printf("%.3f %.3f %.3f\n", x, y, r);
  }
  return 0;
}


Measured memory_bytes: 2608
#include <iostream>
#include <math.h>

using namespace std;
//
//int compare_int(const void *a, const void *b)
//{
//	return *(int*)a - *(int*)b;
//}
//
//int main() {
//	int n[3];
//	for (int i = 0; i < 3; i++) {
//		cin >> n[i];
//	}
//
//	qsort(n, 3, sizeof(int), compare_int);
//
//	if (n[0] == n[1] && n[1] != n[2] && n[0] != n[2]) {
//		cout << "Yes";
//	}
//	else {
//		cout << "No";
//	}
//	
//
//	return 0;
//}

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

	int* a = new int[n];

	bool flag = true;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			if (a[i] % 3 != 0 && a[i] % 5 != 0) {
				flag = false;
				break;
			}
		}
	}

	if (flag) {
		cout << "APPROVED";
	}
	else {
		cout << "DENIED";
	}


	return 0;
}

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

typedef long long ll;

int main()
{
  ll H, W;
  std::cin >> H >> W;

  std::string str(W, 'X');
  std::vector< std::string > vs(H, str);

  ll cnt = 0;
  for (ll y = 0; y < H; y++) {
    std::string base(W, '.');
    std::string in;
    std::cin >> in;
    if (in != base) {
      vs[cnt] = in;
      cnt++;
    }
  }

  H = cnt;

  std::vector< std::string > vans(H, str);
  cnt = 0;
  for (ll x = 0; x < W; x++) {
    bool judge = true;
    for (ll y = 0; y < H; y++) {
      if (vs[y][x] != '.') {
	judge = false;
      }
    }
    if (!judge) {
      for (ll y = 0; y < H; y++) {
	vans[y][cnt] = vs[y][x];
      }
      cnt++;
    }
  }

  W = cnt;

  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      std::cout << vans[y][x];
    }
    std::cout << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  char x,y;
  cin >> x >> y;
  if(x < y)
    cout << "<" << endl;
  else if(x > y)
    cout << ">" << endl;
  else
    cout << "=" << endl;
  return 0;
}


Measured memory_bytes: 256
while line = gets
  a, op, b = line.split
  case op
  when "*" then
    puts a.to_i * b.to_i
  when "/" then
    puts a.to_i / b.to_i
  when "+" then
    puts a.to_i + b.to_i
  when "-" then
    puts a.to_i - b.to_i
  else
    break
  end
end

Measured memory_bytes: 8740
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	long long N,x,sum,temp;
	long long a[100001]={};
	long long minus=0;
	cin>>N>>x;
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	sum=a[0]+a[1];
	if(sum>x && (sum-x)>a[1]){
		temp=((sum-x)-a[1]);
		minus+=temp;
		a[0]-=temp;
		sum-=temp;
	}
	for(int i=1;i<N;i++){
		if(a[i]+a[i-1]>x){
			temp=(a[i]+a[i-1]-x);
			minus+=temp;
			a[i]-=temp;
		}
	}
	cout<<minus<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const int Nmax = 100000;
const int Mmax = 100000;
int N,M,K[Mmax];
vector<int> L[Nmax];
int rnk[Nmax], par[Nmax];
vector<int> c[Mmax];

void init(){
	for(int i=0; i<N; i++){
		rnk[i] = 0;
		par[i] = i;
	}
}

int root(int i){
	if(par[i]==i) return i;
	else return par[i]=root(par[i]);
}

void unite(int i, int j){
	int ri = root(i);
	int rj = root(j);
	if(i==j || ri == rj) return;
	if(rnk[ri]==rnk[rj]){
		par[ri] = rj;
		rnk[rj]++;
	}
	else if(rnk[ri]<rnk[rj]){
		par[ri] = rj;
	}
	else{
		par[rj] = ri;
	}
}

int main(){
	cin >> N >> M;
	for(int i=0; i<N; i++){
		cin >> K[i];
		for(int j=0; j<K[i]; j++){
			int l;
			cin >> l;
			l--;
			L[i].push_back(l);
			c[l].push_back(i);
		}
	}

	init();

	for(int i=0; i<M; i++){
		for(int j=1; j<c[i].size(); j++){
			unite(c[i][0],c[i][j]);
			//cout << c[i][0] << " " << c[i][j] << endl;
		}
	}
	/*
	for(int i=0; i<N; i++){
		cout << root(i) << endl;
	}
	*/

	int r = root(0);
	for(int i=1; i<N; i++){
		if(root(i)!=r){
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265358979323846264338327950L
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " = " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " || ";
        __f(comma+1, args...);
    }
#else
#define debug(...)
#endif
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	string s;
 	cin >> s;
 	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << endl;
 	else if (s[0] == 'R' && s[1] == 'R') cout << 2 << endl;   
 	else if (s[2] == 'R' && s[1] == 'R') cout << 2 << endl;   
 	else {
 		ll f = 0;
 		for (ll i = 0; i < 3; i++) {
 			if (s[i] == 'R') {
 				cout << 1 << endl;
 				f = 1;
 				break;
 			}
 		}
 		if (f == 0) cout << 0 << endl;
 	}
	return 0;
}

Measured memory_bytes: 3612