akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    auto getPositions = [&]() {
        vector<int> res;
        for (int i = 0; i < n && res.size() < k;) {
            if (s[i] == 'o') {
                res.push_back(i);
                i += c + 1;
            } else {
                ++i;
            }
        }
        return res;
    };
    vector<int> l, r;
    l = getPositions();
    reverse(s.begin(), s.end());
    r = getPositions();
    for (int i = 0; i < k; i++) r[i] = n - 1 - r[i];
    reverse(r.begin(), r.end());
    for (int i = 0; i < k; i++) {
        if (l[i] == r[i]) cout << l[i] + 1 << '\n';
    }
}


Measured memory_bytes: 3448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXSIZE=30000020;
const int mod=1000000007;
int bufpos;
char buf[MAXSIZE];
#define NEG 0
void init(){
	//freopen("piling.in","r",stdin);
	//freopen("piling.out","w",stdout);
	buf[fread(buf,1,MAXSIZE,stdin)]='\0';
	bufpos=0;
}
#if NEG
int readint(){
	bool isneg;
	int val=0;
	for(;!isdigit(buf[bufpos]) && buf[bufpos]!='-';bufpos++);
	bufpos+=(isneg=buf[bufpos]=='-');
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return isneg?-val:val;
}
#else
int readint(){
	int val=0;
	for(;!isdigit(buf[bufpos]);bufpos++);
	for(;isdigit(buf[bufpos]);bufpos++)
		val=val*10+buf[bufpos]-'0';
	return val;
}
#endif
char readchar(){
	for(;isspace(buf[bufpos]);bufpos++);
	return buf[bufpos++];
}
int readstr(char* s){
	int cur=0;
	for(;isspace(buf[bufpos]);bufpos++);
	for(;!isspace(buf[bufpos]);bufpos++)
		s[cur++]=buf[bufpos];
	s[cur]='\0';
	return cur;
}
int f[3003][2],g[3003][2];
inline void add(int &x,int y){
	x+=y;
	if (x>=mod)
		x-=mod;
}
int main(){
	init();
	int n=readint(),m=readint()-1;
	for(int i=0;i<n;i++)
		f[i][i==0]=1;
	for(int i=0;i<m;i++){
		memset(g,0,sizeof(g));
		for(int j=0;j<n;j++){
			add(g[j+1][0],f[j][0]);
			add(g[j+1][1],f[j][1]);
			add(g[j][0],f[j][0]);
			add(g[j][0],f[j][0]);
			add(g[j][1],f[j][1]);
			add(g[j][1],f[j][1]);
			if (j){
				add(g[j-1][j==1],f[j][0]);
				add(g[j-1][1],f[j][1]);
			}
		}
		swap(f,g);
	}
	int ans=0;
	for(int i=0;i<n;i++)
		add(ans,f[i][1]);
	add(ans,ans);
	add(ans,ans);
	printf("%d",ans);
}

Measured memory_bytes: 256
use std::cmp;

const INF: i64 = 1e15 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let k: usize = sc.read();
    let v: Vec<i64> = sc.vec(n);
    let u: Vec<i64> = v.iter().rev().map(|&v| v).collect();

    let left_dp = get_table(v);
    let right_dp = get_table(u);

    let mut ans = -INF;
    for pop_left in 0..(n + 1) {
        for pop_right in 0..(n + 1) {
            if pop_left + pop_right > n {
                break;
            }
            for push_left in 0..(pop_left + 1) {
                for push_right in 0..(pop_right + 1) {
                    if pop_left + pop_right + push_left + push_right > k {
                        break;
                    }

                    let a = left_dp[pop_left][push_left] + right_dp[pop_right][push_right];
                    ans = cmp::max(ans, a);
                }
            }
        }
    }

    println!("{}", ans);
}

fn get_table(v: Vec<i64>) -> Vec<Vec<i64>> {
    let n = v.len();
    let mut dp = vec![vec![-INF; n + 1]; n + 1];
    dp[0][0] = 0;
    for pop in 1..(n + 1) {
        let mut popped = vec![];
        let mut sum = 0;
        for i in 0..pop {
            popped.push(v[i]);
            sum += v[i];
        }
        dp[pop][0] = sum;
        popped.sort();
        for push in 1..(pop + 1) {
            let v = popped[push - 1];
            sum -= v;
            dp[pop][push] = sum;
        }
        assert_eq!(sum, 0);
    }
    dp
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let N = input[0].split(' ')[0]
	let K = input[0].split(' ')[1]
	let result = K
	for(let i = 1; i < N; i++) {
		result = result * (K - 1)
	}
	console.log(result)
}   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
n=int(input())
_n=n
if n==1:
    print(0)
    exit()
ans=0
for i in range(2,10**6+9):
    c=i
    while(n%c==0):
        n//=c
        ans+=1
        c*=i
    while(n%i==0):
        n//=i
    if n==1:
        break
if i<n:
    ans+=1
print(ans)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

const string YES = "Yes";
const string NO = "No";
#define judge(f) cout<<((f)?YES:NO)<<"\n";


int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    string t=string(T.begin(),T.end()-1);
    // cout << t << endl;
    judge(S==t);
    return 0;
}


Measured memory_bytes: 3628
#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()
{
  int N;
  cin >> N;
  vector<int>A(N);
  for(int i=0; i < N; i++)
    cin >> A[i];
  int ans=0;
  int s = A[0];
  int c = 1;
  for(int i=1; i < N; i++){
    if(A[i] == s)
      c++;
    else{
      ans += c / 2;
      c = 1;
      s = A[i];
    }
  }
  ans += c/2;
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define ll long long

int main() {
    int n;
    cin>>n;
    map<string,ll>mp;
    vector<ll>v(n);
    for(ll i=0;i<n;i++){
        string t;ll x;
        cin>>t>>x;
        mp[t]=i;
        v[i]=x;
    }
    string t;
    cin>>t;
    ll s=0;
    for(ll i=mp[t]+1;i<n;i++)
        s+=v[i];
    cout<<s<<endl;
}

Measured memory_bytes: 256
while 1:
    a,op,b=input().split()
    if op=='?':
        break
    a=int(a)
    b=int(b)
    if op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(int(a/b))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    int a,b;
    cin>>a>>b;
    if(b==1) 
    {
        cout<<0;
        return 0;
    }
    int ans= 1;
    t=a;
    while(t<b)
    {
        t--;
        t+=a;
        ans++;
    }
    cout<<ans;


    return 0;
}



Measured memory_bytes: 256
class node:
    def __init__(self, id):
        self.id = id
        self.root = self

    def findRoot(self):
        if self == self.root:
            return self
        else:
            self.root = self.root.findRoot()
            return self.root

    def resetRoot(self):
        self.root = self

class Tree:
    def __init__(self, num):
        self.nodes = {i:node(i) for i in range(num)}

    def union(self, one, other):
        root1 = one.findRoot()
        root2 = other.findRoot()
        root1.root = root2.root = self.nodes[min(root1.id, root2.id)]

    def resetTree(self):
        for n in self.nodes.values():
            n.resetRoot()

    def makeTree(self, Edge):
        self.edge = Edge
        for x,y in Edge:
            self.union(self.nodes[x-1], self.nodes[y-1])


def main():
    with open(0) as f:
        N, M = map(int, f.readline().split())
        Edge = [tuple(map(int, line.split())) for line in f.readlines()]
    
    tree = Tree(N)
    ans = 0
    for i in range(M):
        edge = [v for  v in Edge if v != Edge[i]]
        tree.makeTree(edge)
        if any(x.findRoot().id != 0 for x in tree.nodes.values()):
            ans += 1
        tree.resetTree()
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9224
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i,init , n) for (int i = init; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = 2 * pow(10, 9) + 1;//+1しないとREになるかも(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

ll max(ll a, ll b) { return (a > b) ? a : b; }
ll min(ll a, ll b) { return (a < b) ? a : b; }


const ll MOD = pow(10, 9) + 7;
ll add_modp(ll a, ll b, ll p) {
	// a+b mod p
	return (a % p + b % p) % p;
}

ll sub_modp(ll a, ll b, ll p) {
	ll res = add_modp(a, -b, p);
	if (res < 0) return  res + MOD;
	return res;
}

//https://atcoder.jp/contests/abc147/submissions/8896778
ll mul_modp(ll a, ll b, ll p) {
	// a*b mod p
	return ((a % p) * (b % p)) % p;
}

// a^n mod p
ll pow_modp(ll a, ll n, ll p) {
	
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = mul_modp(res, a, p);
		a = mul_modp(a, a, p);
		n >>= 1;
	}
	return res;
}










int main(void) {

	ll n, a, b;
	cin >> n >> a >> b;

	//ll ans = pow(2, n) - 1;

	ll ans = pow_modp(2, n, MOD) - 1;
	//cout << "yah1   " << ans << endl;
	ll nCa = 1, nCb = 1;

	for (int i = 0; i < a; i++) {
		//nCa *= n - i;
		//nCa /= a - i;
		nCa = mul_modp(nCa, n - i, MOD);
		nCa = nCa * (pow_modp(a - i, MOD - 2, MOD));
	}
	for (int i = 0; i < b; i++) {
		//nCb *= n - i;
		//nCb /= b - i;
		nCb = mul_modp(nCb, n - i, MOD);
		nCb = nCb * (pow_modp(b - i, MOD - 2, MOD));
	}

	//cout << "yah2   " << n << "C" << a << " = " << nCa << endl;

	//cout << "yah3   " << n << "C" << b << " = " << nCb << endl;


	//ans = ans - nCa - nCb;
	ans = sub_modp(ans, nCa, MOD);
	ans = sub_modp(ans, nCb, MOD);
	cout << ans << endl;

}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[][] board = new int[H + 2][W + 2];
        for (int i = 0; i < H; i++) {
            char[] f = sc.next().toCharArray();
            for (int l = 0; l < W; l++)
                board[i + 1][l + 1] = f[l] == '#' ? -1 : 0;
        }
        int[][] round = { { -1, 1 }, { 0, 1 }, { 1, 1 }, { 1, 0 }, { 1, -1 }, { 0, -1 }, { -1, -1 }, { -1, 0 } };
        for (int y = 1; y <= H; y++) {
            for (int x = 1; x <= W; x++) {
                if(board[y][x]==-1)continue;
                int cnt = 0;
                for (int k = 0; k < 8; k++) {
                    if (board[y + round[k][0]][x + round[k][1]] == -1)
                        cnt++;
                }
                board[y][x] = cnt;
            }
        }
        for (int y = 1; y <= H; y++) {
            for (int x = 1; x <= W; x++) {
                if (board[y][x] == -1) {
                    System.out.print('#');
                } else {
                    System.out.print(board[y][x]);
                }
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 24404
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  string S;
  cin >> S;
  const regex re("(.*)keyence|k(.*)eyence|ke(.*)yence|key(.*)ence|keye(.*)nce|"
                 "keyen(.*)ce|keyenc(.*)e|keyence(.*)");
  cout << (regex_match(S, re) ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
int main(){
	fast;
	ll t,x; cin>>x;
	for(auto i=1;;++i){
		if((i*x)%360==0){
			cout<<i<<'\n';
			return 0;
		}
	} 
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>

using namespace std;

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

int wh[21];
int dh[21];

int main(){
    while(1){
        int w, d;
        cin >> w >> d;

        if(w==0) break;

        REP(i, 21){
            wh[i] = 0;
            dh[i] = 0;
        }

        REP(i, w){
            int wi;
            cin >> wi;
            wh[wi] += 1;
        }
        REP(i, d){
            int di;
            cin >> di;
            dh[di] += 1;
        }

        REP(i, 21){
            dh[i] = max(0, dh[i]-wh[i]);
        }

        int output = 0;
        REP(i, 21){
            output += i*(dh[i] + wh[i]);
        }

        cout << output << endl;
    }
}

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

void	write_1line(int H, int W, int h_idx)
{
	if (h_idx == 0 || h_idx == H - 1) {
		for (int j = 0; j < W; ++j)
			cout << "#";
		cout << "\n";
	} else {
		cout << "#";
		for (int j = 1; j < W - 1; ++j)
			cout << ".";
		cout << "#\n";
	}
}

int	main()
{
	int	H, W;
	while (cin >> H >> W) {
		if (H == 0 && W == 0) break;
		for (int i = 0; i < H; ++i)
			write_1line(H, W, i);
		cout << endl;
	}
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
int main() 
{ 
	fastio;
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	ll n, k;
	cin>>n>>k;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);

	for (int i = 2; i < n; ++i)
	{
		ll q=k;
		ll min1 = INT_MAX;
		while(q--){
			if(i-q>0){
				min1 = min(min1, dp[i-q-1] + abs(a[i]-a[i-q-1]));
			}
		}
		dp[i] = min1;
	}
	// for (int i = 0; i < n; ++i)
	// {
	// 	cout<<dp[i]<<endl;
	// }
	cout<<dp[n-1];
} 

Measured memory_bytes: 1408
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;

const ll N = 3010;
const ll p = 998244353;

ll dp[N][N];

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	for (ll i = a; i <= c; i++) {
		for (ll j = b; j <= d; j++) {
			if (i == a && j == b) dp[i][j] = 1;
			else if (i == a) dp[i][j] = dp[i][j - 1] * a % p;
			else if (j == b) dp[i][j] = dp[i - 1][j] * b % p;
			else {
				dp[i][j] += dp[i - 1][j] * j;
				dp[i][j] += dp[i][j - 1] * i;
				dp[i][j] %= p;
				dp[i][j] -= dp[i - 1][j - 1] * (i - 1) * (j - 1) % p;
				if (dp[i][j] < 0) dp[i][j] += p;
			}
		}
	}
	
	cout << dp[c][d] << endl;

	return 0;
}

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

#define null               ""
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

struct edge {
    int u, v;
    num val;
    edge() {}
    edge(int u, int v, num val) {
        this->u = u;
        this->v = v;
        this->val = val;
    }
};

int n, pr[200005];
num ans, d, w[200005];
vector<edge> dat;

bool inline cmp(edge a, edge b) {
    return a.val < b.val;
}

int find_pr(int a) {
    return pr[a] == a ? a : pr[a] = find_pr(pr[a]);
}

void solve(int l, int r) {
    if (l == r)  return;
    int mid = (l + r) >> 1, pl = 0, pr = 0;
    num ml = 5e18, mr = 5e18;
    circ (i, l, mid) {
        num cur = w[i] - d * i;
        if (cur < ml) {
            pl = i;
            ml = cur;
        }
    }
    circ (i, mid + 1, r) {
        num cur = w[i] + d * i;
        if (cur < mr) {
            pr = i;
            mr = cur;
        }
    }
    circ (i, mid + 1, r) {
        dat.push_back(edge(pl, i, ml + w[i] + d * i));
    }
    circ (i, l, mid) {
        dat.push_back(edge(i, pr, mr + w[i] - d * i));
    }
    solve(l, mid);
    solve(mid + 1, r);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> d;
    cont (i, n) {
        cin >> w[i];
    }
    solve(1, n);
    sort(all(dat), cmp);
    cont (i, n) {
        pr[i] = i;
    }
    loop (i, dat.size()) {
        int u = dat[i].u, v = dat[i].v, pu = find_pr(u), pv = find_pr(v);
        num val = dat[i].val;
        if (pu == pv)  continue;
        pr[pv] = pu;
        ans += val;
    }
    cout << ans << endl;
}


Measured memory_bytes: 69472
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int P = sc.nextInt();
        
        int pie = (A * 3 + P) / 2;
        
        System.out.println(pie);
    }
}


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

using namespace std;

int main() {

    int K, A, B;
    cin >> K >> A >> B;

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

    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3596
n, m = map(int, input().split())
a = []
b = []

for i in range(n):
    a.append([int(s) for s in input().split()])

for i in range(m):
    b.append(int(input()))

for i in range(n):
    sum = 0
    for j in range(m):
        sum += a[i][j] * b[j]
    print(sum)



Measured memory_bytes: 6012
//36
#include<iostream>

using namespace std;

double fact(int x){
  double r=1;
  while(x){
    r*=x--;
  }
  return r;
}

int main(){
  char s[41];
  cin>>s;
  char ap[128]={};
  for(int i=0;s[i];i++){
    ap[s[i]]++;
  }
  int no=0;
  for(int i=0;i<128;i++){
    no+=ap[i]%2;
  }
  if(no>1){
    cout<<0<<endl;
  }else{
    int n=0;
    double k=1;
    for(int i=0;i<128;i++){
      n+=ap[i]/2;
      k*=fact(ap[i]/2);
    }
    cout<<(long long)(fact(n)/k+.5)<<endl;
  }
  return 0;
}
    
  

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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define SIN(x) string x; cin>>x;
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x,v) lower_bound((x).begin(),(x).end(),(v))-(x).begin();
#define uboundv(x,v) upper_bound((x).begin(),(x).end(),(v))-(x).begin();
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;
typedef long double LD;

using namespace std;

#define N 3500
int main() {
	ios::sync_with_stdio(0);
	SIN(s);
	F(s.size()-8) cout<<s[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <numeric>
#include <algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef pair<int, int> P;
int n, m, ans=0;

int main(){
  cin >> n >> m;
  vector<int> bridge(m);
  vector<P> ps(m);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    ps[i] = P(b, a);
  }
  sort(ps.begin(), ps.end());
  int cur = -100001;
  for(int i=0; i<m; i++){
    if(cur <= ps[i].second){
      ans++;
      cur = ps[i].first;
//      cout << ps[i].first << " " << ps[i].second << endl;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4584
/**
 *      ///----- My Info -----///
 *      Code by: Unk
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
**/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu 
#include <debug/to_string.h>
#endif
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
        ///----- My Template -----///
///===================================================================================================================================
/// Debug
#define _end cout << "\n"
#ifndef Ernest0_0Abreu
#define db(x) ;
#define dbrange(x,begin,end) ;
#define dbname(x) ;
#define dbnamerange(x,begin,end) ;
#define dbmat(x,begin_n,end_n,begin_m,end_m) ;
#define dbST(x,end) ;
#define db_end ;
#endif
///Function
#define pi (acos(-1))
#define lg2(x) ( 31-__builtin_clz(x) )
#define lgx(x,n) ( log(n) / log(x) )
/// Macros
#define fst first
#define scd second
#define left (node<<1)
#define right ((node<<1)+1)
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const int MAXN = 2e5+7;
const int MOD = 1e9+17;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027, 3079, 10079;
/// Module Prime Numbers: 3, 200017, 1000033, 998244353, 1000000007, 1000000009, 1000000021;
#define int long long
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
///===================================================================================================================================
        ///----- My code -----///

int dp[MAXN], ans[MAXN];
vi G[MAXN];

	void bfs(int node){
		queue<int> q;
		q.push(node);
		while(!q.empty()){
			node = q.front(); q.pop();
			for(auto it : G[node]){
				if(!dp[it]){
					dp[it] = dp[node]+1;
					ans[it] = node;
					q.push(it);
				}
			}
		}
	}

int32_t main(){
    
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

 	int N, M;
 	cin >> N >> M;
 	for(int i = 1; i <= M; ++i){
 		int a, b;
 		cin >> a >> b;
 		G[a].push_back(b);
 		G[b].push_back(a);
 	}

 	bfs(1);
 	bool mk = true;
 	for(int i = 2; i <= N; ++i){
 		if(dp[i]);
 		else mk = false;
 	}
 	if(!mk) {cout << "No"; return 0;}
 	cout << "Yes\n";
 	for(int i = 2; i <= N; ++i)
 		{cout << ans[i]; _end;}

    return 0;
}


Measured memory_bytes: 16076
n,m=list(map(int, input().split()))
p=[[i+1, list(map(int, input().split()))] for i in range(m)]
p.sort(key=lambda x: x[1][1])

s = []
o = {}
for i, (c,(d,b)) in enumerate(p):
    a = d
    if not a in o.keys():
        o[a] = 1
    else:
        o[a] += 1
    s.append([c, d, o[a]])

s.sort(key=lambda x: x[0])
for (a,b,c) in s:
    print("".join([str(b).zfill(6), str(c).zfill(6)]))

Measured memory_bytes: 53740
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2");
            WillReturn.Add("1 3 1 2");
            //3
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("100 1 2 3 14 15 58 58 58 29");
            //135
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] LArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
        Array.Sort(LArr);

        int Answer = 0;
        for (int I = 0; I <= LArr.GetUpperBound(0); I += 2) {
            Answer += LArr[I];
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll K, H, W, total = 0, Ans = 0;cin>> H >> W >> K;
vector<string> table(H);
map<ll, ll> Highth;
map<ll, ll> Width;

rep(i, 0, H)
cin >> table[i];

rep(i, 0, H){
rep(j, 0, W){

if(table[i][j] == '#'){
Highth[i]++;Width[j]++;total++;}

}}

rep(I, 0, (1 << H)){
rep(J, 0, (1 << W)){

bitset<6> P(I);
bitset<6> Q(J);
ll h = 0, w = 0;

    rep(i, 0, 6){
    if(P.test(i)){
    h += Highth[i];
    }
    }

    rep(j, 0, 6){
    if(Q.test(j)){
    w += Width[j];
    }
    }

    rep(i, 0, H){
    rep(j, 0, W){
    if(P.test(i) && Q.test(j)){
    if(table[i][j] == '#')h-=1;
    }}}

if(total - h - w == K)Ans++;
}
}
cout << Ans;
}

Measured memory_bytes: 3576
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;
using W = double;
using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;
using Poly = vector<P>;
#define X real()
#define Y imag()
const W EPS = (1e-7), pi = acos(-1);

namespace std{
  bool operator < (const P& a, const P& b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
  bool cmp_y(const P &a, const P &b){
    return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;
  }
  bool operator == (const P& a, const P& b){
    return abs(a-b) < EPS;
  }
}

double dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}
P projection(P a, P b){ return dot(a, b)/abs(b)/abs(b)*b;}

//直線aと直線bの交点
P intersection(L a, L b){
  P af = a.first, as = a.second, bf = b.first, bs = b.second;
  return af + cross(bs-bf,af-bf)/(-cross(bs-bf,as-bf)+cross(bs-bf,af-bf))*(as-af);
}

int main(){
  int n;
  P a = P(1,0)*P(cos(-2*pi/3),sin(-2*pi/3));
  P b = P(1,0)*P(cos(-1*pi/3),sin(-1*pi/3));
  while(cin >> n, n){
    int k;
    cin >> k;
    vector<P> ps;
    vector<W> ys;
    for(int i = 0; i < n; ++i){
      W x, y;
      cin >> x >> y;
      ps.emplace_back(x,y);
      ys.push_back(y);
    }
    sort(ps.begin(), ps.end(), cmp_y);
    sort(ys.begin(), ys.end());
    int t = 0;
    W ans = 1e9;
    L base(P(0,0),P(1,0));
    vector<pair<W,int>> V;
    for(int j = 0; j < n; ++j){
      P p = ps[j];
      L l(p,p+a), r(p,p+b);
      V.emplace_back(intersection(base,l).X,-j-1);
      V.emplace_back(intersection(base,r).X,j+1);
    }
    sort(V.begin(), V.end());
    vector<bool> alive(n,true);
    for(int i = 0; i < n; ++i){
      if(i > 0 and abs(ys[i]-ys[i-1]) < EPS) continue;
      while(ps[t].Y < ys[i]-EPS){
        alive[t] = false;
        ++t;
      }
      if(t > k) break;
      W r = 0;
      int s = 0;
      size_t m = 0;
      vector<bool> alive_ = alive;
      vector<bool> used(n,false);
      W d = ys[i]/sqrt(3)*2;
      for(size_t j = 0; j < V.size(); ++j){
        W l = V[j].first;
        int idx = V[j].second;
        if(idx >= 0) continue;
        if(not alive_[-idx-1]) continue;
        while(m < V.size() and s < n-k){
          int idx_ = V[m].second;
          if(idx_ <= 0 or (not alive_[idx_-1]) or V[m].first < l + d - EPS){
            ++m;
            continue;
          }
          r = V[m].first;
          ++s;
          ++m;
          used[idx_-1] = true;
        }
        if(s < n-k) break;
        ans = min(ans,r-l-d);
        alive_[-idx-1] = false;
        if(used[-idx-1]){
          --s;
          used[-idx-1] = false;
        }
      }
    }
    printf("%.12f\n",ans*3);
  }
}



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



int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int a, b; cin >> a >> b;
    if (a >= 13) cout << b << '\n';
    else if (a >= 6 && a <= 12) cout << b / 2 << '\n';
    else cout << 0 << '\n';
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int32_t main()
{
	IOS;
	int a;
	double d;
	cin >> a >> d;
	int b = round(d * 100);
	int ans = a * b;
	ans /= 100;
	cout << ans;
	return 0;
}


Measured memory_bytes: 3780
#クイックソート
import copy
 
INF = 10000000000
def merge(A, left, mid, right):
    count = 0
    L = A[left:mid] + [(INF,INF)]
    R = A[mid:right] + [(INF,INF)]
     
    i, j = 0, 0
    for k in range(left, right):
        count = count + 1
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i = i + 1
        else:
            A[k] = R[j]
            j = j + 1
    return count
 
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        countL = mergeSort(A, left, mid)
        countR = mergeSort(A, mid, right)
        return merge(A, left, mid, right) + countL + countR
    return 0

def partition(A, p, r):
    x = A[r][1]
    i = p
    for j in range(p, r):
        if A[j][1] <= x:
            A[i], A[j] = A[j], A[i]
            i += 1
        
        
    A[i], A[r] = A[r], A[i]
    
    return i

n = int(input())
A = [input().split() for _ in range(n)]
A = [(a[0], int(a[1])) for a in A]
B = [(a[0], int(a[1])) for a in A]

def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q+1, r)
        
quickSort(A, 0, n-1)
mergeSort(B, 0, n)
if A == B:
    print('Stable')
else:
    print("Not stable")
    
ans = [str(a[0])+" "+str(a[1]) for a in A]
ans = '\n'.join(ans)
print(ans)



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

string S;

int main() {
    
    long long K;
    cin >> S >> K;
    
    int non_one = S.size();
    
    for(int i=0; i<S.size(); i++)
        if(S[i] != '1')
        {
            non_one = i;
            break;
        }
    
    if(K < non_one+1)
    {
        cout << 1 << "\n";
        return 0;
    }
    
    cout << S[non_one] << "\n";
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

if (h % 3) * (w % 3) == 0:
    print(0)
    exit()

ans = min(h, w)

a = [0,0,0]
for i in range(2):
    b = h // 3 + i
    a[0] = b * w
    a[1] = (h - b) * (w // 2)
    a[2] = (h - b) * (w - (w // 2))

    ans = min(ans, max(a) - min(a))

for i in range(2):
    b = w // 3 + i
    a[0] = b * h
    a[1] = (w - b) * (h // 2)
    a[2] = (w - b) * (h - (h // 2))

    ans = min(ans, max(a) - min(a))

print(ans)

Measured memory_bytes: 3188
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut min = 1;
    let mut result = 0;
    for i in 0..n {
        if a[i] == min {
            min += 1;
        } else {
            result += 1;
        }
    }
    if result == n {
        println!("-1");
    } else {
        println!("{}", result);
    }
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

int main()
{
	int H, W, A, B;
	cin >> H >> W >> A >> B;

	vvi c(H, vi(W, 0));

	rep(i, W - A) c[0][i] = 1;

	rep(i, W - A)
	{
		rep(j, H - B)
		{
			c[j][i] = 1;
		}
	}

	repl(i, H - B, H)
	{
		repl(j, W - A, W)
		{
			c[i][j] = 1;
		}
	}

	rep(i, H)
	{
		rep(j, W)
		{
			cout << c[i][j];
		}

		cout << endl;
	}

	return 0;
}

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

int main(){
	int N;
	cin >> N;
	char c[N];
	int wi = N, ri = -1;
	for(int i=0;i<N;i++){
		cin >> c[i];
		if(c[i] == 'R') ri = i;
		if(c[i] == 'W' && wi == N) wi = i;
	}
	int ans = 0;
	while(wi < ri){
		c[wi] = 'R';
		c[ri] = 'W';
		ans++;
		while(c[wi] == 'R' && wi < N){
			wi++;
		}
		while(c[ri] == 'W' && ri > -1){
			ri--;
		}
	}
	cout << ans << endl;
}


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

#define F first
#define S second
#define pii pair<int, int>
#define mod 1000000007

int N, A[2099], Z, W, ans = 0;

int main() {
    //freopen("input.in","r",stdin);
 	//freopen("output.out","w",stdout);
    cin >> N >> Z >> W;
    for(int i = 0;i < N;i++) {
        cin >> A[i];
    }
    ans = abs(A[N-1]-W);
    for(int i = 0;i < N;i++) {
        int minm = abs(A[N-1]-A[i]);
        for(int j = i+1;j < N-1;j++) {
            minm = min(minm, abs(A[N-1]-A[j]));
        }
        ans = max(ans, minm);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int ls, lt;
char s[1010], t[1010];
int cal(int x)
{
	int now = 0;
	for(int i = 1; i <= lt; i++)
		if(s[x + i - 1] != t[i])
			now++;
	//printf("<%d>\n",now);
	return now;
}
int main()
{
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	ls = strlen(s + 1);
	lt = strlen(t + 1);
	int ans = lt;
	for(int i = 1; i <= ls - lt + 1; i++)
		ans = min(ans, cal(i)); 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3760
import java.util.*;
import java.io.PrintWriter;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		for(int i = 0; i < n - 1; i++) {
			if(a[i] == a[i + 1]){
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}

Measured memory_bytes: 64800
def move(lon, lat, com):
    target, other, pop_index, insert_index = lon, lat, 0, 3
    if com == "E" or com == "W":
        target, other = lat, lon
    if com == "S" or com == "W":
        pop_index, insert_index = 3, 0
    target.insert(insert_index, target.pop(pop_index))
    other[0], other[2] = target[0], target[2]


def set_upper(lon, lat, upper):
    com = "N" if upper in lon else "E"
    for _i in range(4):
        move(lon, lat, com)
        if lon[0] == upper:
            break


def rotate(lon, lat, com):
    if com == "R":
        lon[1], lat[1], lon[3], lat[3] = lat[3], lon[1], lat[1], lon[3]
    elif com == "L":
        lon[1], lat[1], lon[3], lat[3] = lat[1], lon[3], lat[3], lon[1]


longitude = [1, 2, 6, 5]
latitude = [1, 4, 6, 3]
values = list(input().split())
n = int(input())
for i in range(n):
    U, F = input().split()
    set_upper(longitude, latitude, values.index(U) + 1)
    for j in range(3):
        if longitude[1] == values.index(F) + 1:
            break
        rotate(longitude, latitude, "R")
    print(values[latitude[3] - 1])



Measured memory_bytes: 5608
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/assoc_container.hpp> 
using namespace std; using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define FORd(i,a,b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define print(x) cout << x << newl;
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 

const int MXN = 2e5 + 5;
//const int MXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;


string s, t;
int dp[3010][3010];

int main(){ FAST
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

    cin >> s >> t;
    F0R(i,sz(s)){
        F0R(j,sz(t)){
            if (s[i] == t[j]){
                if (i == 0 || j == 0) dp[i][j] = 1;
                else dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                if (i == 0 && j > 0) dp[i][j] = dp[i][j-1];
                if (i > 0 && j == 0) dp[i][j] = dp[i-1][j];
                if (i > 0 && j > 0) dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    int si = sz(s) - 1, ti = sz(t) -1;
    string ans = "";
    while(si >= 0 && ti >= 0){
        if (s[si] == t[ti]){
            ans += s[si];
            --si; --ti;
        }
        else{
            if (si == 0 && ti == 0) break;
            else if ((si == 0 && ti > 0) || (si > 0 && ti > 0 && dp[si][ti-1] >= dp[si-1][ti])) --ti;
            else if ((si > 0 && ti == 0) || (si > 0 && ti > 0 && dp[si-1][ti] > dp[si][ti-1])) --si;
        }
    }
    reverse(ans.begin(),ans.end());
    finish(ans);














	return 0;
}


Measured memory_bytes: 35584
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

char str[200005];

int main(int argc, char* argv[])
{
    long n, m;
    scanf("%ld%ld", &n, &m);
    scanf("%s", str);

    vector<vector<long> > z(n);

    long i,j;
    for(i=0; i<m; i++) {
        long a, b;
        scanf("%ld%ld", &a, &b);
        z[a-1].push_back(b-1);
        z[b-1].push_back(a-1);
    }

    queue<long> que;
    for(i=0; i<n; i++) {
        long a=0, b=0;
        for(j=0; j<z[i].size(); j++) {
            if(str[z[i][j]]=='A') a++;
            else                  b++;
        }
        if(a==0||b==0) {
            que.push(i);
        }
    }

    vector<long> flag(n, 0);
    while( !que.empty() ) {
        long i = que.front();
        que.pop();

        if(flag[i]) continue;

        long a=0, b=0;
        for(j=0; j<z[i].size(); j++) {
            if(!flag[z[i][j]]) {
                if(str[z[i][j]]=='A') a++;
                else                  b++;
            }
        }
        if(a==0||b==0) {
            flag[i]=1;
            for(j=0; j<z[i].size(); j++) {
                if(!flag[z[i][j]]) {
                    que.push( z[i][j] );
                }
            }
        }
    }

    for(i=0; i<n; i++) {
        if(flag[i]==0) {
            printf("Yes\n"); return 0;
        }
    }
    printf("No\n");

    return 0;
}


Measured memory_bytes: 14080
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	String s,t;
	public void solve() {
		N = nextInt();
		s = next();
		t = next();

		for(int i = 0;i < N;i++){
			boolean flag = true;
			for(int j = 0;j < N - i;j++){
				if(s.charAt(i + j) != t.charAt(j)){
					flag = false;
					break;
				}
			}

			if(flag){
				out.println(N + i);
				return;
			}
		}

		out.println(N * 2);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    ll a,b,m;
    cin>>a>>b>>m;
    ll aa[100005]={};
    ll bb[100005]={};
    ll aamin=1LL<<62; ll bbmin=1LL<<62;
    REP(i,100005)aa[i]=1LL<<62;
    REP(i,100005)bb[i]=1LL<<62;
    REP(i,a){
        cin>>aa[i];
        if(aa[i]<aamin)aamin=aa[i];
    }
    REP(i,b){
        cin>>bb[i];
        if(bb[i]<bbmin)bbmin=bb[i];
    }
    //cout<<aamin<<bbmin<<endl;
    ll min=aamin+bbmin;
    ll x,y,c;
    REP(i,m){
        cin>>x>>y>>c;
        ll val = aa[x-1]+bb[y-1]-c;
        if(val<min)min=val;
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U;typedef long long ll;typedef pair<int,int > P;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	//int ttt;scanf("%d",&ttt);for(int i=1;i<=ttt;i++)
	inp();
	return 0;
}
void inp(){
	int n;scanf("%d",&n);
	int a;
	ll sum = 0;
	for(int i =0;i<n;i++){
		scanf("%d",&a);
		sum += a;
	}
	printf("%lld", sum - n);
}
//c.cc by xsthunder at Wed Jul 25 22:55:02 2018


Measured memory_bytes: 128