akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
#define ll long long 
#define mod 1000000007
#define MOD 99824435300000000
inline ll mul(ll a,ll b){
  a=(a+MOD)%MOD;
  b=(b+MOD)%MOD;
  ll c=a*b;
  c=(c+MOD)%MOD;
  return c;
}
inline ll add(ll a,ll b){
  a=(a+MOD)%MOD;
  b=(b+MOD)%MOD;
  ll ans=(a+b);
  ans=(ans+MOD)%MOD;
  return ans;
}

ll power(ll a,ll b,ll c){
  ll ans=1;
  while(b){
    if(b&1){
      ans=mul(ans,a);
    }
    a=mul(a,a);
    b=b/2;
  }
  return ans;
}
inline ll max(ll a,ll b){return a>b?a:b;}
inline ll min(ll a,ll b){return a<b?a:b;}
int f(vector<vector<int> >&v,int i,int j,string &s,string &t){
  if(i==s.length()||j==t.length())return 0;
  if(v[i][j]!=-1)return v[i][j];
  if(s[i]==t[j])return v[i][j]=1+f(v,i+1,j+1,s,t);
  else return v[i][j]=max(f(v,i,j+1,s,t),f(v,i+1,j,s,t));
}
void find(vector<vector<int> > &dp,string &s,int i,int j,int ans,string &ss,string &tt){
  if(ans==0)return;
  if(ss[i]==tt[j])
  {
    s.push_back(ss[i]);
    find(dp,s,i+1,j+1,ans-1,ss,tt);
  }
  else{
    if(dp[i+1][j]==ans)find(dp,s,i+1,j,ans,ss,tt);
    else find(dp,s,i,j+1,ans,ss,tt);
  }
}
int main()
{
  string s,t; cin>>s>>t;
  int m=s.length();
  int n=t.length();
  vector<vector<int> > dp(m+1,vector<int>(n+1,-1));
  int ans=f(dp,0,0,s,t);
  string ss="";
  find(dp,ss,0,0,ans,s,t);
  cout<<ss;
  return 0;
}

Measured memory_bytes: 35968
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Set;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            Set<Integer> set = new TreeSet<>();
            set.add(1);
            int tmp = 6;
            while (tmp <= n) {
                set.add(tmp);
                tmp *= 6;
            }
            tmp = 9;
            while (tmp <= n) {
                set.add(tmp);
                tmp *= 9;
            }

            int[] dp = new int[n + 1];
            Arrays.fill(dp, Integer.MAX_VALUE / 2);
            dp[0] = 0;

            for (int i = 0; i <= n; i++) {
                for (int x : set) {
                    if (i + x <= n) {
                        dp[i + x] = Math.min(dp[i + x], dp[i] + 1);
                    }
                }
            }

            out.println(dp[n]);
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

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

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

    }
}



Measured memory_bytes: 27984
def main():
    N=int(input())
    A=list(map(int, input().split()))
    B=list(map(int, input().split()))

    count = 0
    prev_count = -1
    while count!=prev_count:
        prev_count = count
        for i in range(N):
            d = B[i-1 if i>=1 else N-1] + B[i+1 if i<N-1 else 0]
            c = (B[i]-A[i]) // d
            B[i] -= d * c
            count += c

    if A == B:
        print(count)
    else:
        print(-1)

if __name__ == '__main__':
    main()

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


int main(){
  int N, M;
  cin >> N >> M;
  
  int a[N];
  pair<int, int> cb[M];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < M; i++) {
    int b, c;
    cin >> b >> c;
    cb[i] = {c, b};
  }
  
  sort(a, a+N);
  sort(cb, cb+M, greater<pair<int, int>>());
  
  int aI = 0;
  for (int i = 0; i < M; i++) {
    while (cb[i].second>0 && aI<N) {
      if(cb[i].first>a[aI]) {
        a[aI] = cb[i].first;
        aI++;
        cb[i].second--;
      } else {
        break;
      }
    }
  }
  
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += (long long) a[i];
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <functional>
#include <tuple>
#include <string>
#include <iomanip>
using namespace std;

template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

struct S {
    string x;
    int y;
	int index;

    S(const string& x, const int& y, const int& index)
        : x(x), y(y), index(index) {}
};

bool operator<(const S& a, const S& b)
{
    return tie(a.x, b.y, a.index) < tie(b.x, a.y, b.index);
}

int main()
{
	int n;
	vector<S> v;

	std::cin >> n;

	for (int i = 0; i < n; i++) {
		string tmp1; int tmp2;
		
		cin >> tmp1 >> tmp2;

		S s = {tmp1,tmp2,i+1};
		v.push_back(s);
	}

	std::sort(v.begin(), v.end());

	for (int i = 0; i < v.size(); i++)
	{
		cout << /* v[i].x << " " << v[i].y << " " << */ v[i].index << endl;
	}
	

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
struct P{
	int x,y,cost;
	P(int a,int b,int c){x = a, y = b , cost = c;}
	P(){}
};
#define INF (1<<25)
#define rep(i,n) for(int i=0; i<n ;i++)

int dist(P a,P b){
	return abs(a.x-b.x) + abs(a.y-b.y);
}
int main(){
	int w,h;
	
	while(cin >> w >> h , w) {
		vector<P> data[5];
		P start , goal ;
		
		start.cost = 0 , goal.cost = 0;
		
		rep(i,h)rep(j,w){
			char c;	cin >> c;
			if(c != '.'){
				if(c == 'S')start.x = j , start.y = i;	
				else if(c == 'G')goal.x = j , goal.y = i;
				else {P t(j,i,0) ; data[c-'1'].push_back(t);}
			}
		}
		int ret = INF , num ;
		
		P dp[5][1000];
		
		rep(lp,5){ // start
			rep(i,5)rep(j,1000){dp[i][j].cost = INF;}
			
			int so = (lp+1)%5;
			rep(i,data[so].size()){
				dp[so][i] = data[so][i];
				dp[so][i].cost = dist(data[so][i],start);
			}
			
			rep(Z,3){ // remain 
				int z = (lp+Z+2)%5;
				int prev = (z+4)%5;
				rep(i,data[prev].size()){ // prev
					rep(j,data[z].size()){ //cur
						int cost = dp[prev][i].cost + dist(dp[prev][i],data[z][j]);
						if(dp[z][j].cost > cost){
							dp[z][j] = data[z][j] , dp[z][j].cost = cost;
						}
					}
				}
			}
			rep(i,data[(lp+4)%5].size() ){
				int kCost = dp[(lp+4)%5][i].cost + dist(dp[(lp+4)%5][i],goal);
				if( kCost < ret){
					ret = kCost , num = lp+1; 
				}
			}
		}
		
		if(ret == INF)cout << "NA" << endl; 
		else cout << num << " " << ret << endl; 
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{int a,b,c;
cin>>a>>b>>c;
if (a>b){swap(a,b);}
if (b>c){swap(b,c);}
if (a>b){swap(a,b);}

    cout << a<<" "<<b<<" "<<c << endl;
    return 0;
}



Measured memory_bytes: 3084
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        c:[[i64; 3]; 3]
    }

    let mut a = vec![0i64;3];
    let mut b = vec![0i64;3];
    for x in 0..3 {
        b[x] = c[0][x];
    }
    a[1] = c[1][0] - b[0];
    a[2] = c[2][0] - b[0];

    let mut ok = true;
    for y in 0..3 {
        for x in 0..3 {
            if c[y][x] != a[y] + b[x] {
                ok = false;
            }
        }
    }
    println!("{}", if ok {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
multiset<int> h1, h2;
long long sh1, sh2;
void push(int x) {
  if(!h1.empty() && x <= *h1.rbegin()) {
    h1.insert(x);
    sh1 += x;
  }
  else {
    h2.insert(x);
    sh2 += x;
  }
  while(h1.size() > h2.size()) {
    const int cur = *h1.rbegin();
    h2.insert(cur);
    auto it = h1.end(); it--;
    h1.erase(it);
    sh2 += cur;
    sh1 -= cur;
  }
  while(h2.size() > h1.size()) {
    const int cur = *h2.begin();
    h1.insert(cur);
    h2.erase(h2.begin());
    sh1 += cur;
    sh2 -= cur;
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int q; cin >> q;
  long long sb = 0;
  while(q--) {
    int op; cin >> op;
    if(op == 1) {
      int a, b; cin >> a >> b;
      sb += b;
      push(a);
    } else if(op == 2) {
      const int x = *h1.rbegin();
      cout << x << " " << (1ll * x * int(h1.size()) - sh1) + (sh2 - 1ll * x * int(h2.size())) + sb << "\n";
    }
  }
}

Measured memory_bytes: 9600
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s; cin >> s;
    int x, y; cin >> x >> y;
    
    uint i=0;
    
    int cnt=0;
    bool isLR = true;
    vector<int> vLR, vTB;
    for(; i<s.size(); ++i){
        if(s[i]=='F'){ ++cnt; continue; }
        if(s[i]=='T'){
            if( isLR && cnt!=0){ vLR.push_back(cnt); }
            if(!isLR && cnt!=0){ vTB.push_back(cnt); }
            isLR = !isLR;
            cnt = 0;
        }
    }
    if(s[s.size()-1]=='F'){
        if( isLR && cnt!=0){ vLR.push_back(cnt); }
        if(!isLR && cnt!=0){ vTB.push_back(cnt); }
    }
    if(s[0]!='T'){
        x -= vLR[0]; vLR.erase(vLR.begin());
    }
    
    sort(vLR.begin(), vLR.end(), greater<int>());
    sort(vTB.begin(), vTB.end(), greater<int>());
    
    int sumLR=0, sumTB=0;
    for(uint i=0; i<vLR.size(); ++i){
        sumLR -= (sumLR>x ? 1:-1) * vLR[i];
    }
    for(uint i=0; i<vTB.size(); ++i){
        sumTB -= (sumTB>y ? 1:-1) * vTB[i];
    }
    
    cout << (sumLR==x && sumTB==y ? "Yes":"No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main {


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

    	
    	int n = scan.nextInt(); int k = scan.nextInt();
    	
    	int [] price = new int[n];
    	
    	for(int i=0; i<n; i++) {
    		int line = scan.nextInt();
    		price[i] = line;
    	}
    	
    	Arrays.sort(price);
    	int sum = 0;
    	
    	for(int i=0; i<k; i++) {
    		sum+= price[i];
    	}
    	
    	System.out.println(sum);
    	
    } 	
}


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

namespace Lsk {
#define _auto_ template <typename T>

// fast io
#define writesp(x) (write(x), putchar(' '))
#define writeln(x) (write(x), putchar('\n'))
_auto_ inline void read(T &x) {
	x = 0; bool sgn = false; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (sgn = true), ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	if(sgn) x = -x;
}
_auto_ inline void write(T x) {
	if(x < 0) putchar('-'), x = -x;
	static char buf[40]; int o = 0;
	for(x; x > 9; x /= 10, ++o) buf[o] = x % 10 + '0'; buf[o] = x + '0';
	for(o; ~o; --o) putchar(buf[o]);
	return;
}

// cmin / cmax / swap
_auto_ inline void cmin(T &u, const T v) { if(u > v) u = v; }
_auto_ inline void cmax(T &u, const T v) { if(u < v) u = v; }
_auto_ inline T min(const T u, const T v) { return u < v ? u : v; }
_auto_ inline T max(const T u, const T v) { return u > v ? u : v; }
_auto_ inline void swap(T &u, T &v) { T tmp(u); u = v, v = tmp; }

// math
const int mod = 998244353, mod_2 = 1996488706;
//const int mod = 1000000007, mod_2 = 2000000014;
//const int mod = 1000000009, mod_2 = 2000000018;
_auto_ inline T abs(T x) { return x > 0 ? x : -x; }
_auto_ inline T gcd(T u, T v) {	return v ? gcd(v, u % v) : u; }
_auto_ inline T Mod(T u) { return u >= mod_2 ? u % mod : (u > mod ? u - mod : u); }
_auto_ inline T inmod(T u) { return u >= mod ? u - mod : (u < 0 ? u + mod : u); }
inline long long fpm(long long base, long long mi) {
	long long res = 1;
	while(mi) {
		if(mi & 1) res = Mod(res * base);
		base = Mod(base * base), mi >>= 1;
	}
	return res;
}

} using namespace Lsk;
#define N 200005
using std :: sort;

int n;
int a[N], f[N];
long long K;

inline bool check(long long mid) {
	long long res = 0;
	for(int i = 1; i <= n; ++i) {
		long long to = mid / f[i];
		if(to < a[i]) res += a[i] - to;	
	}
	return res <= K;
}

int main() {
	read(n), read(K);
	for(int i = 1; i <= n; ++i) read(a[i]);
	for(int i = 1; i <= n; ++i) read(f[i]);
	
	sort(a + 1, a + 1 + n);
	sort(f + 1, f + 1 + n, std :: greater<long long>());
	
	long long l = 0, r = 1e12, mid, minp = 1e18;
	while(l <= r) {
		mid = l + r >> 1;
		//writesp(l), writeln(r);
		if(check(mid)) {
			cmin(minp, mid);
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	
	writeln(minp);
	return 0;
}

Measured memory_bytes: 1920
def resolve():
    n = int(input())
    a = list(map(int, input().split()))

    ll = [0] * 9
    for aa in a:
        if 3200 <= aa:
            ll[0] += 1
            continue
        for i in range(1,9):
            if aa < 400 * i:
                ll[i] += 1
                break
    mn = sum([i > 0 for i in ll[1:]])
    mx = mn + ll[0]
    mn = max(int(ll[0] > 0), mn)

    print(mn, mx)


if __name__ == "__main__":
    resolve()


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

int main(){
    int a, b;
    cin >> a >> b;
    double priceA = a / 0.08;
    double priceB = b / 0.1;
    int price = priceA > priceB ? (int) priceA : (int) priceB;
    while(true){
        if((int) (price * 0.08) == a && (int) (price * 0.1) == b){
            break;
        } else if((int) (price * 0.08) != a && (int) (price * 0.1) != b){
            price = -1;
            break;
        } else {
            price++;
        }
    }
    cout << price << endl;
    return 0;
}

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

int main()
{
	string s;
	int64_t k;
	cin >> s >> k;
	if (k == 1)
	{
		cout << s[0] << endl;
		return 0;
	}
	for (int i = 0; i < k; i++)
	{
		if ('1' < s[i])
		{
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << '1' << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
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;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int k, n;
	string s;
	int ans = 0;
	cin >> n >> s >> k;
	rep(i, n) { cout << ((s[i] == s[k - 1]) ? s[i] : '*'); }
	cout << endl;
}

Measured memory_bytes: 3644
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc065/tasks/abc065_b

N = int(input())
a = [int(input())-1 for _ in range(N)]
ans = 0
cur = 0

visit = [-1] * N
while True:
    # print(cur, visit)
    cur = a[cur]
    ans += 1
    if visit[cur] == -1:
        visit[cur] = ans
    else:
        print(-1)
        exit()
    if cur == 1:
        print(ans)
        exit()


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

using namespace std;

struct Operation {
    int x;
    int y;
    int nx;
    int ny;
};

int main (void) {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> a(H+1, vector<int>(W+1, 0));
    for ( int i = 1; i <= H; i++ ) {
        for ( int j = 1; j <= W; j++ )
            cin >> a.at(i).at(j);
    }

    int n_ope = 0;
    vector<Operation> ope;
    for ( int i = 1; i <= H; i++ ) {
        for ( int j = 1; j <= W; j++ ) {
            /* すでに偶数なら操作しない */
            if ( a.at(i).at(j) % 2 == 0 ) {
                continue;
            }

            /* 奇数の場合は偶数にする
             *   最終的に最終行右端列以外は偶数にできる */
            if ( j != W ) {
                /* 右端列以外なら右のマスに渡す */
                n_ope++;
                ope.push_back({j, i, j+1, i});
                a.at(i).at(j)--;
                a.at(i).at(j+1)++;
            }
            else if ( i != H ) {
                /* 最終行以外なら下のマスに渡す */
                n_ope++;
                ope.push_back({j, i, j, i+1});
                a.at(i).at(j)--;
                a.at(i+1).at(j)++;
            }
        }
    }

    cout << n_ope << endl;
    for ( int i = 0; i < n_ope; i++ ) {
        printf("%d %d %d %d\n",
               ope.at(i).y, ope.at(i).x,
               ope.at(i).ny, ope.at(i).nx);
    }
    return 0;
}


Measured memory_bytes: 6272
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 1e7 + 1;

int f[maxn];
lli g[maxn];

int n;

void prep()
{
    for(int i = 2; i < maxn; ++i)
        if(f[i] == 0)
        {
            for(int j = i; j < maxn; j += i)
                f[j] = i;
        }
    g[1] = 1;
    for(int i = 2; i < maxn; ++i)
    {
        vector<pii> v;
        int x = i;
        while(x > 1)
        {
            int p = f[x];
            if(sz(v) == 0 || p != v.back().fi) v.push_back(pii(p, 1));
            else ++v.back().se;
            x /= p;
        }
        g[i] = 1;
        for(auto&to: v) g[i] *= 1LL * (to.se + 1);
    }
}

void read_input()
{
    cin >> n;
}

void solve()
{
    lli ans = 0;
    for(int i = 1; i <= n; ++i)
        ans += i * 1LL * g[i];
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    prep();
    read_input();
    solve();
}



Measured memory_bytes: 120828
#include <iostream>

using namespace std;

int main(void)
{
  long long r, D, x2000, i;
  
  cin >> r >> D >> x2000;
  
  for(i=1; i<=10; i++){
    cout << r*x2000-D << endl;
    
    x2000 = r*x2000-D;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, k;
    cin >> n >> k;
    vector<pair<int, int>> num;
    for(int i = 0; i<n; i++){
        int a, b;
        cin >> a >> b;
        num.push_back(make_pair(a, b));
    }
    sort(num.begin(), num.end());
    int ans;
    for(int i = 0; i<num.size(); i++){
        if(num[i].second>=k){
            ans = num[i].first;
            break;
        }else{
            k -= num[i].second;
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 1400
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int n;
bool isPallindrome(string s){
	for(int i = 0 ;i  < n/2; i++){
		if(s[i] != s[s.length()-1-i])return false;
	}
 
	return true;
}
int main(){
 
      string s;
      cin >> s;
      n = s.length();
      if(isPallindrome(s) && n%2 == 1){
          string str = "";
          for(int i =1; i <= (n-1)/2;i++){
          	str+=s[i-1];
          }
          string str1 ="";
          for(int i = (n+3)/2; i<=n ;i++){
          	str1 += s[i-1];
          }
          if(isPallindrome(str) && isPallindrome(str1))cout<<"Yes\n";
          else cout<<"No\n";
      }
      else cout<<"No\n";
 
}


Measured memory_bytes: 256
# operator.add(a, b)
# operator.mul(a, b)


class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 0:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)
    

# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
def AOJ_DSL_2_A():
    n, q = map(int, input().split())
    e = (1 << 31) - 1
    A = [e] * n
    seg = SegmentTree(A, min, e)

    for i in range(q):
        t, x, y = map(int, input().split())
        if t == 0:
            seg.update(x, y)
        else:
            print(seg.get(x, y + 1))


# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B
def AOJ_DSL_2_B():
    from operator import add
    import sys
    n, q = map(int, input().split())
    e = 0
    A = [e] * n
    seg = SegmentTree(A, add, e)
    
    query = sys.stdin.readlines()
    for i in range(q):
        t, x, y = map(int, query[i].split())
        x -= 1
        if t == 0:
            A[x] += y
            seg.update(x, A[x])
        else:
            y -= 1
            print(seg.get(x, y + 1))


def ABC125_C():
    from fractions import gcd
    N = int(input())
    A = list(map(int, input().split()))
    
    seg = SegmentTree(A, gcd, 0)
    ans = 0
    for i in range(N):
        ans = max(ans, gcd(seg.get(0, i), seg.get(i + 1, N)))
    print(ans)


# AOJ_DSL_2_A()
# AOJ_DSL_2_B()
ABC125_C()


Measured memory_bytes: 16128
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int[] A = nextIntArray(N);
		double res = 0.0;
		for(int i=0;i<N;i++) {
			res += 1.0 / A[i];
		}
		res = 1.0 / res;
		out.println(res);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
void read(int &x){
	char ch=getchar();x=0;
	for (;ch==' '||ch=='\n';ch=getchar());
	for (;ch!=' '&&ch!='\n';x=x*10+ch-'0',ch=getchar());
}
void write(int x){
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,a[100003];
int t[100003];
bool cmp(int a,int b){
	return t[a]<t[b];
}
int main(){
	read(n);
	for (int i=1;i<=n;i++) a[i]=i;
	for (int i=1;i<=n;i++) cin>>t[i];
	sort (a+1,a+1+n,cmp);
	for (int i=1;i<=n;i++) write(a[i]),putchar(' ');
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,sum=1000;
  cin >> n;
  int64_t a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n-1;i++){
    int64_t cnt=0;
    if(a[i]<a[i+1])cnt=sum/a[i];
    sum+=(a[i+1]-a[i])*cnt;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3644
import java.io.*;
import java.util.*;

// Replace with public class Main
public class Main {
    public static void main(String[] args) throws IOException {
        lunlunSequence();
    }

    static void lunlunSequence() throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(in.readLine());
        ArrayList<String> oneDigits = new ArrayList<>();
        TreeSet<Long> ordered = new TreeSet<>();
        for (long number = 0; number < 10; number++) {
            String sNumber = number+"";
            oneDigits.add(sNumber);
            ordered.add(Long.parseLong(sNumber));
        }
        HashMap<Integer, ArrayList<String>> suffixs = new HashMap<>();
        suffixs.put(1, oneDigits);
        int iter = 10;
        int row = 2;
        while (row <= iter) {
            if (ordered.size() > 100000) break;
            ArrayList<String> numbers = new ArrayList<>();
            for(String suffix : suffixs.get(row-1)) {
                for(String d : nextNumbers(suffix)) {
                    numbers.add(d);
                    long lNumber = Long.parseLong(d);
                    if (lNumber == 0) continue;
                    ordered.add(lNumber);
                }
            };
            suffixs.put(row, numbers);
            row++;
        }
        int j = 0;
        while (!ordered.isEmpty()) {
            long kth = ordered.pollFirst();
            if (N == j) {
                System.out.println(kth);
                break;
            }
            ++j;
        }
    }

    static String[] nextNumbers(String suffix) {
        char leading = suffix.charAt(0);
        int c = leading-'0';
        if (leading == '0') {
            return new String[] { "1" + suffix, "0" + suffix};
        } if (leading < '2') {
            return new String[] { (c-1)+suffix, (c)+suffix, (c+1)+suffix };
        } else if (leading < '9')  {
            return new String[] { (c-1)+suffix, (c)+suffix, (c+1)+suffix };
        } else {
            return new String[] { (c-1)+suffix, (c)+suffix };
        }
    }

}


Measured memory_bytes: 64784
def main():
    N, K = map(int, input().split())

    ans = editorial(N, K)
    print(ans)


def editorial(N, K):
    """
    一番左の塗り方: K通り
    残りN-1個
        上記隣: 上記以外のK-1通り
        上記隣: 上記以外のK-1通り(一番左に塗った色復帰)
    """
    return K * (K-1) ** (N-1)


def WA(N, K):
    if N == 1:
        return K


if __name__ == '__main__':
    main()


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

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

}	



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;

//最大公約数
ll gcd(ll a, ll b){
    if(a % b == 0)return b;
    else return gcd(b, a % b);
}

int main(){
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    sort(ALL(a));
    ll res = abs(a[0] - x);
    rep(i, n)res = gcd(res, abs(a[i] - x));
    cout << res << endl;
}





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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int X, N;
    cin >> X >> N;

    set<int> se;
    rep(i, N) {
        int p;
        cin >> p;
        se.insert(p);
    }

    int dist = 0;
    while(true) {
        if(se.find(X - dist) == se.end()) {
            cout << X - dist << endl;
            return 0;
        }

        if(se.find(X + dist) == se.end()) {
            cout << X + dist << endl;
            return 0;
        }
        dist++;
    }
}


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

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

  int count = 0;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == 'R'){
      count++;
    }
  }
  if(count == 0){
    cout << count << endl;
  }else if(count == 3){
    cout << count << endl;
  }else if(count == 2 && S.at(1) == 'R'){
    cout << 2 << endl;
  }else{
    cout << 1 << endl;
  }
  
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, m;
    cin >> n >> m;

    ll a[m], b[m];
    rep(i, m) { cin >> a[i] >> b[i]; }

    vector<vector<ll>> g(n);
    rep(i, m) {
        g[a[i] - 1].push_back(b[i] - 1);
        g[b[i] - 1].push_back(a[i] - 1);
    }

    vector<ll> from(n, -1);
    queue<ll> q;
    q.push(0);

    while (!q.empty()) {
        ll now = q.front();
        q.pop();
        for (auto next : g[now]) {
            if (from[next] == -1) {
                from[next] = now;
                q.push(next);
            }
        }
    }

    cout << "Yes" << endl;
    repd(i, 1, n) { cout << from[i] + 1 << endl; }

    return 0;
}



Measured memory_bytes: 15888
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000



int main(){

	int X,Y,Z;
	cin>>X>>Y>>Z;
	int N = X+Y+Z;
	vector<vector<long long>> C(X+Y+Z);
	long long ans = 0LL;
	for(int i=0;i<X+Y+Z;i++){
		long long a,b,c;
		cin>>a>>b>>c;
		C[i] = {b-a,a,b,c};
		ans += a;
	}
	
	sort(C.begin(),C.end());
	vector<long long> Acnt(N);
	
	{
		priority_queue<long long> Q;
		long long S = 0;
		for(int i=0;i<N;i++){
			long long t = C[i][3]-C[i][1];
			Q.push(t);
			if(Q.size()>X){
				S += Q.top();
				Q.pop();
			}
			Acnt[i] = S;
		}
	}
	
	long long Maxi = -Inf;
	long long t = 0LL;
	priority_queue<long long> Q;
	for(int i=N-1;i>=0;i--){
		t += C[i][0];
		Q.push(C[i][3]-C[i][2]);
		if(Q.size()>Y){
			t += Q.top();
			Q.pop();
		}
		if(i<X)break;
		if(Q.size()==Y){
			Maxi = max(Maxi,t+Acnt[i-1]);
		}
	}
	
	cout<<ans+Maxi<<endl;
	
	return 0;
}

Measured memory_bytes: 12124
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var (
		_                = ReadLineInt()
		Eats             = ReadLineInt()
		Points           = ReadLineInt()
		AdditionalPoints = ReadLineInt()
		Result           = 0
		Previous         = -1
	)

	for _, v := range Eats {
		Result += Points[v-1]
		if Previous == v-1 {
			Result += AdditionalPoints[v-2]
		}
		Previous = v
	}

	fmt.Println(Result)
}

/////////////////////////////////////////

func fln(format string, elements ...interface{}) {
	fmt.Printf(format+"\n", elements...)
}

var BufReader = bufio.NewReaderSize(os.Stdin, 1e6)

func ReadLine() string {
	a, _, _ := BufReader.ReadLine()
	return string(a)
}

func ReadLineInt() (result []int) {
	in := strings.Split(ReadLine(), " ")
	result = make([]int, 0, 2)
	for _, v := range in {
		t, _ := strconv.Atoi(v)
		result = append(result, t)
	}
	return
}


Measured memory_bytes: 640
#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>P;

int main() {
  int n,k;
  cin >> n >> k;
  int cnt = 0;
  while(n){
    n/=k;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

int main()
{
    string s;
    cin >> s;

    bool flag = false;
    for (int i = 0; i < s.size(); i++)
    {
        if(flag && s[i] == 'F'){
            cout << "Yes" << endl;
            return 0;
        }

        if(s[i] == 'C'){
            flag = true;
        }
    }
    cout << "No" << endl;
    
    return 0;
}


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


Measured memory_bytes: 3088
#include <stdio.h>
#include <cmath>
#include <stdlib.h>
#include <algorithm>

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

    int aCount = 0, middleCount = 0, bCount = 0;
    for (int i = 0; i < n; i++)
    {
        int p;
        scanf("%d", &p);
        if (p <= a)
            aCount++;
        else if (p <= b)
            middleCount++;
        else
            bCount++;
    }

    printf("%d", std::min(std::min(aCount, middleCount), bCount));
    return 0;
}


Measured memory_bytes: 128
n, t = map(int, input().split())
lst = []
for i in range(n):
  tp = tuple(map(int, input().split()))
  if tp[1] <= t:
    lst.append(tp)
if lst == []:
  print('TLE')
  exit()
print(min(lst, key=lambda x: x[0])[0])

Measured memory_bytes: 8988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	rep(i,s.size()-1){
		if(s.substr(i,2)=="AC"){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-11
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007
const int N = 501031;

int n;
char board[100][100];
int fe[100];
vector<pair<int,int> > order;

int get_id(char c)
{
	if (c>='a'&&c<='z')
		return c-'a';
	return c-'A'+26;
}

bool outside(int a,int b)
{
	return (a<0||a>1||b<0||b>=n);
}

long long dp[70][81];

int adj[200][200];
int clr[200];

bool can_put(int ps,int c)
{
	for (int i=0;i<4;i++)
	{
		int v=ps-4+i;
		if (v>=0&&adj[order[ps].second][order[v].second]==1&&clr[i]==c)
			return false;
	}
	return true;
}

int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios_base::sync_with_stdio(0);
	//cin.tie(0);

	cin>>n;
	for (int i=0;i<2;i++)
	{
		string st;
		cin>>st;
		for (int j=0;j<st.size();j++)
		{
			board[i][j]=st[j];
		}
	}

	for (int i=0;i<60;i++)
	{
		fe[i]=1e9;
	}

	for (int i=0;i<2;i++)
	{
		for (int j=0;j<n;j++)
		{
			int id=get_id(board[i][j]);
			fe[id]=min(fe[id],j);
		}
	}

	for (int i=0;i<2;i++)
	{
		for (int j=0;j<n;j++)
		{
			for (int dx=-1;dx<=1;dx++)
			{
				for (int dy=-1;dy<=1;dy++)
				{
					if (abs(dx)+abs(dy)!=1)
						continue;
					if (outside(i+dx,j+dy))
						continue;
					int id1=get_id(board[i][j]);
					int id2=get_id(board[i+dx][j+dy]);
					adj[id1][id2]=1;
					adj[id2][id1]=1;
					//cout<<id1<<" "<<id2<<endl;
				}
			}
		}
	}
	for (int i=0;i<52;i++)
	{
		if (fe[i]<1e6)
			order.push_back(make_pair(fe[i],i));
	}

	sort(order.begin(),order.end());

	dp[0][0]=1;
	for (int i=0;i<order.size();i++)
	{
		for (int mask=0;mask<81;mask++)
		{
			dp[i][mask]%=bs;
			if (dp[i][mask]==0)
				continue;
			int here=mask;
			for (int q=0;q<4;q++)
			{
				clr[q]=here%3;
				here/=3;
			}
			for (int new_clr=0;new_clr<3;new_clr++)
			{
				if (can_put(i,new_clr))
				{
					int new_mask=new_clr;
					for (int j=3;j>0;--j)
					{
						new_mask=new_mask*3+clr[j];
					}
					dp[i+1][new_mask]+=dp[i][mask];
					//cout<<i<<" "<<new_clr<<" "<<new_mask<<endl;
				}
			}
		}
	}

	long long res=0;
	for (int i=0;i<81;i++)
	{
		res+=dp[order.size()][i];
	}
	cout<<res%bs<<endl;

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 384
n = int(input())
x = list(map(int, input().split()))
pivot = n // 2
l = []
for i in range(n):
    l.append([x[i], i])
l.sort()
r = []
for i in range(n):
    l[i].append(i)
    l[i] = l[i][1:]
    r.append([l[i][1], l[i][0]])
d1 = dict(l)
d2 = dict(r)
for i in range(n):
    if d1[i] >= pivot:
        print(x[d2[pivot-1]])
    else:
        print(x[d2[pivot]])

Measured memory_bytes: 94888
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
 
int main(void){
    int n,a[100] = {0};
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
     
    cout << a[n-1];
    for(int i = n-2; i >= 0; i--){
        cout << " " << a[i];
    }
    cout << endl;
}


Measured memory_bytes: 3072
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()

	s := make([]string, N)
	for i := 0; i < N; i++ {
		s = append(s, next())
	}

	for _, a := range s {
		if a == "Y" {
			fmt.Println("Four")
			return
		}
	}

	fmt.Println("Three")
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    string ans = "";
    REP(i,3){
        string c;
        cin >> c;
        ans += c[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll h, n;
  cin >> h >> n;

  vll as(n), bs(n);

  rep(i,n) cin >> as[i] >> bs[i];

  vvll dp(n+1, vll(h+1, INF));
  dp[0][0] = 0;
 
  rep(i, n){
    rep(j, h) dp[i+1][j] = dp[i][j];
    rep(j, h){
      ll nj = min(j + as[i], h);
      chmin(dp[i+1][nj], dp[i][nj]);      
      if(nj >= 0) chmin(dp[i+1][nj], dp[i+1][j] + bs[i]);
    }
  }

  cout << dp.back().back() << endl;

  return 0;
}


Measured memory_bytes: 81644
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//vc alp(26) ={'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'};
//cout<<""<<endl;
int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}	





Measured memory_bytes: 256
result = [0,0,0,0,0,0,0,0]
sheet = {}
for i in 0..2 do
    array = gets.split.map(&:to_i)
    for j in 0..2 do
        sheet[array[j]] = [i,j+3]
        sheet[array[j]] << 6 if i == j 
        sheet[array[j]] << 7 if (i - j).abs == 2
        sheet[array[j]] << 7 if i == 1 && j == 1
    end
end

output = "No"
N = gets.chomp.to_i
for i in 1..N do
    b = gets.chomp.to_i
    if not sheet.has_key?(b) then
        next
    end
    sheet[b].each do |j|
        if result[j] == 2 then
            output = "Yes"
            break
        end
        result[j] += 1
    end
    break if output == "Yes"
    sheet[b].clear
end

puts output


Measured memory_bytes: 1788