akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <list>

int h, w, n;
int hw[100][100];

int main(int argc, char *argv[])
{
    std::list<int> list;
    std::cin >> h >> w >> n;
    int tmp;
    for (int i = 0; i < n; i++) {
        std::cin >> tmp;
        for(int j = 0; j < tmp; j++){
            list.push_back(i+1);
        }
    }
    for(int i = 0; i < h; i++){
        if(i % 2){
            for(int j = 0; j < w; j++){
                hw[i][j] = list.front();
                list.pop_front();
            }
        }
        else{
            for(int j = w - 1; j >= 0; j--){
                hw[i][j] = list.front();
                list.pop_front();
            }
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            std::cout << hw[i][j] << ' ';
        }
        std::cout << std::endl;
    }
    return 0;
}


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

public class Main {
	
	public void solve(){
		int N = nextInt();
		int[] L = new int[2*N];
		for(int i = 0; i < 2*N; i++){
			L[i] = nextInt();
		}
		Arrays.sort(L);
		int sum = 0;
		for(int i = 0; i < N; i++){
			sum += L[i * 2];
		}
		out.println(sum);
	}
	
	
	private static PrintWriter out;

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

	public static int nextInt() {
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if (str.charAt(0) == '-') {
			minus = true;
			i++;
		}
		int len = str.length();
		for (; i < len; i++) {
			char c = str.charAt(i);
			if (!('0' <= c && c <= '9'))
				throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}

	public static long nextLong() {
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if (str.charAt(0) == '-') {
			minus = true;
			i++;
		}
		int len = str.length();
		for (; i < len; i++) {
			char c = str.charAt(i);
			if (!('0' <= c && c <= '9'))
				throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}

	public static String next() {
		int c;
		while (!isAlNum(c = read())) {
		}
		StringBuilder build = new StringBuilder();
		build.append((char) c);
		while (isAlNum(c = read())) {
			build.append((char) c);
		}
		return build.toString();
	}

	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;

	private static int read() {
		if (bufferLength < 0)
			throw new RuntimeException();
		if (bufferIndex >= bufferLength) {
			try {
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufferLength <= 0)
				return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}

	private static boolean isAlNum(int c) {
		return '!' <= c && c <= '~';
	}
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct segtree{
    int n;
    vector<pii> dat;
    segtree(int size,pii x){
        n=1;
        while(n<size) n*=2;
        dat.assign(2*n-1,x);
    }
    // update k th element
    void update(int k,pii a) {
        k+=n-1; // leaf
        dat[k]=a;
        while(k>0) {
            k=(k-1)/2;
            dat[k]=max(dat[k*2+1],dat[k*2+2]);
        }
    }
    // min [a, b)
    pii query(int a,int b) { return query(a,b,0,0,n); }
    pii query(int a,int b,int k,int l,int r) {
        if(r<=a or b<=l) return make_pair(-1,-1);
        if(a<=l and r<=b) return dat[k];
        int m=(l+r)/2;
        return max(query(a,b,k*2+1,l,m),query(a,b,k*2+2,m,r));
    }
};

void solve(){
    while(true){
        int n,q;
        cin >> n >> q;
        if(n==0 and q==0) break;

        vector<int> parent(n,-1);
        vector<vector<int>> children(n);
        vector<bool> is_leaf(n,true);
        rep(i,1,n){
            cin >> parent[i];
            --parent[i];
            children[parent[i]].emplace_back(i);
            is_leaf[parent[i]]=false;
        }

        vector<int> depth(n);
        vector<vector<int>> belong(n);
        vector<segtree> segs;
        function<void(int,int)> calc_depth=[&](const int v,const int d){
            depth[v]=d;
            for(const auto& u:children[v]) calc_depth(u,d+1);
        };
        calc_depth(0,0);
        rep(i,0,n) if(is_leaf[i]){
            segs.emplace_back(segtree(depth[i]+1,make_pair(-1,-1)));
            segs.back().update(0,make_pair(0,0));
            int v=i;
            while(v!=-1){
                belong[v].emplace_back(segs.size()-1);
                v=parent[v];
            }
        }

        ll ans=0;
        vector<bool> done(n);
        rep(i,0,q){
            char ch;
            int v;
            cin >> ch >> v;
            --v;
            if(ch=='M'){
                if(done[v]) continue;
                done[v]=true;
                for(const int tmp:belong[v]) segs[tmp].update(depth[v],make_pair(depth[v],v));
            }else ans+=segs[belong[v][0]].query(0,depth[v]+1).second+1;
        }
        cout << ans << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 44676
#include <bits/stdc++.h>
#define INF 0x3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define PB push_back
#define GCD __gcd
#define COUNT1 __builtin_popcount
#define FORJ(i,j,k) for(int i=j; i<k; ++i)
#define FOR(i,k) FORJ(i,0,k)
#define FORR(i,k) for(int i=k; i>=0; --i)
#define FORE(x,v) for(auto &x : v)
#define FORG(y,x,g) FOR(y, sz(g)) FOR(x, sz2(g))
#define CIN(a) int a; cin>>a;
#define CINC(a) char a; cin>>a;
#define CINS(a) string a; cin>>a;
#define CIND(a) double a; cin>>a;
#define CINL(a) ll a; cin>>a;
#define CINP(a) PII a; cin>>a.F>>a.S;
#define CINLINE(a) string a; getline(cin, a);
#define CIN2(a,b) int a,b; cin>>a>>b;
#define CIN3(a,b,c) int a,b,c; cin>>a>>b>>c;
#define CIN4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d;
#define CINV(n,a) VI a; FOR(i,n) { CIN(x); a.PB(x); }
#define CINV2(n,a,b) VI a,b; FOR(i,n) { CIN2(x,y); a.PB(x); b.PB(y);}
#define CINVP(n,a) VP a; FOR(i,n) { CINP(p); a.PB(p);}
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x.begin())
#define D(x) cout<<#x<<": "<<(x)<<endl
#define H cout<<"H"<<hcnt++<<endl;

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<bool> VB;
typedef vector<string> VS;
typedef vector<PII> VP;
typedef vector<VI> GI;
typedef vector<VB> GB;
typedef vector<vector<char> > GC;
typedef map<char,int> MC;
typedef map<int,int> MI;
typedef map<string,int> MS;

void OUT(auto x) { cout<<x<<endl; }
void OUTP(const PII &p) { cout<<p.F<<" "<<p.S<<endl; }
void OUTB(int x) { cout<<bitset<32>(x)<<endl; }
void OUTN(const auto &x) { cout<<x->d<<endl; }
void OUTV(const auto &x) { FORE(d,x) cout<<d<<" "; cout<<endl; }
void OUTVP(const VP &x) { FORE(d,x) cout<<d.F<<" "<<d.S<<endl; }
void OUTVN(const auto &x) { FORE(d,x) cout<<d->d<<" "; cout<<endl; }
void OUTG(const auto &x) { FORE(v,x) { FORE(u,v) cout<<u; cout<<endl; } }
void OUTM(const auto &x) {FORE(p,x) cout<<p.F<<":"<<p.S<<" "; cout<<endl;}
PII operator+(const PII &l, const PII &r) { return {l.F+r.F, l.S+r.S}; }
void amin(auto &x, auto y) { if(y < x) x = y; }
void amax(auto &x, auto y) { if(x < y) x = y; }
bool bet(auto x, auto l, auto r) { return x>=l && x<r; }
auto mod(auto x, auto m) { return ((x % m) + m) % m; }
bool IsSameSign(auto a, auto b) { return ((a>=0) ^ (b<0)); }
int sz(const auto &x) { return (int)x.size(); }
int sz2(const auto &x) { return (int)x[0].size(); }
bool IsSafe(const auto &x, int i) { return bet(i,0,sz(x)); }
auto Safe(const auto &x, int i) { return IsSafe(x,i) ? x[i] : 0; }
bool Find(const auto &x, auto y) { return x.find(y) != x.end(); }
void Tally(const auto &v, auto &m) { FORE(x,v) m[x]++; }

int hcnt=1;
VP nb4 = {{0,1}, {1,0}, {0,-1}, {-1,0}};
VP nb8 = {{0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}};

//#include "custom.h"

int main() {
  CIN2(n,m);
  if(n>1) n-=2;
  if(m>1) m-=2;
  OUT((ll)n*m);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;

long A, B, C;

int main()
{
	cin >> A >> B >> C;
	if ((A%2) * (B%2) * (C%2) ==0){
		cout << 0 << endl;
		return 0;
	} 
	long long ans;
	long long a=B*C;
	long long b=C*A;
	long long c=A*B;
	ans = min(min(a,b),c);
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from copy import copy


fin = sys.stdin.readline
N, x = [int(elem) for elem in fin().split()]
a_list = [int(elem) for elem in fin().split()]

min_total_cost = float('inf')
min_so_far = a_list[:]
for num_magics in range(N):
    for i in range(N):
        min_so_far[i] = min(min_so_far[i], a_list[i - num_magics])
    total_cost = sum(min_so_far) + num_magics * x
    min_total_cost = min(min_total_cost, total_cost)
print(min_total_cost)


Measured memory_bytes: 43116
/*
       _________
      /         \
     /  _     _  \
    /   0     0   \
   |       ||     |
   |              | => HI
    \     -----   /
     \           /
      \_ _ _ _ _/
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T = 1;
	for(int t = 1; t <= T; t++){
		int a,b,c,k;
		cin >> a >> b >> c >> k;
		for(int i = 0;i < k; i++){
			if(a >= b){
				b *= 2;
			}else{
				if(b >= c){
					c *= 2;
				}
			}
		}
		if(a < b and b < c){
			cout << "Yes\n";
		}else{
			cout << "No\n";
		}
	}
}




Measured memory_bytes: 3612
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int H = sc.nextInt();
    	int W = sc.nextInt();
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < H; i++) {
    		String tmp = sc.next();
    		sb.append(tmp + "\n" + tmp + "\n");
    	}
    	System.out.println(sb);
    }
}

Measured memory_bytes: 22996
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def f(s, last, N):
    if len(s) == N:
        print(s)
        return

    for i in range(last):
        f(s + l_alp[i], last, N)

    f(s + l_alp[last], last+1, N)


def main():
    N = I()
    ans = []

    f('a', 1, N)

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()



Measured memory_bytes: 82560
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let s: String = read().unwrap();

    if n == 1 {
        println!("No");
    } else {
        if &s[0..n / 2] == &s[n / 2..] {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

Measured memory_bytes: 4352
n = int(input())
h = list(map(int,input().split()))
ans = 1
max_h = 0
for i in range(1,n):
    if h[0] <= h[i] and max_h <= h[i] and h[i] >= h[i-1]:
        ans += 1

    max_h = max(h[i],max_h)

print(ans)

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

void selectionSort(vector<int> A, int N);

int main() {
    
    int N;
    cin >> N;
    
    vector<int> A(N);
    for (int i=0; i<N; i++) {
        cin >> A.at(i);
    }
    
    selectionSort(A, N);
    
    return 0;
}

void selectionSort(vector<int> A, int N) {
    int count = 0;
    for (int i=0; i<N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A.at(j) < A.at(minj)) {
                minj = j;
            }
        }
        if (i != minj) {
            int tmp = A.at(i);
            A.at(i) = A.at(minj);
            A.at(minj) = tmp;
            count++;
        }
    }
    for (int i=0; i<N; i++) {
        cout << A.at(i);
        if ( i == N-1) {
            cout << endl;
        } else {
            cout << ' ';
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define fio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
using namespace std;
const int INF = 1e9 + 7;

int main(){
    ///preprocessing
    #ifndef ONLINE_JUDGE
    freopen("test.inp", "r", stdin);
    #endif // ONLINE_JUDGE
    fio;
    ///code below
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d});
}


Measured memory_bytes: 3592
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
li = [a, b, c, d, e]

l1 = [i % 10 for i in li]
min_idx = -1
for i in range(len(l1)):
    if min_idx == -1 or l1[i] != 0 and l1[i] < l1[min_idx]:
        min_idx = i
last = li.pop(min_idx)

output = 0
for x in li:
    if x % 10 != 0:
        x = x - (x % 10) + 10
    output += x
print(output + last)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c;
    cin>>c;
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        cout<<"vowel"<<endl;
    else
        cout<<"consonant"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ii {
    int a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
};
struct iii {
    int a, b, c;
    bool operator < (iii o) const {
        return tie(a, b, c) < tie(o.a, o.b, o.c);
    }
};

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 1000005;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    int bound = 0;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        bound = max(bound, A[i]);
        ans += bound-A[i];
    }
    cout << ans << "\n";
    
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int a, b, h;

int main(){
	cin >> a >> b >> h;
	
	cout << (a+b)*h/2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    using System;
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            var num = int.Parse(String.Join("", Console.ReadLine().Split(' ')));

            var sqrt = Math.Sqrt(num);
            var isSquare = sqrt % 1 == 0;
            var result = isSquare ? "Yes" : "No";
            //出力
            Console.WriteLine(result);

            //Console.ReadLine();
        }

        private static string OddOrEven(int i1, int i2)
        {
            return ((i1 % 2 == 0) || (i2 % 2 == 0)) ? "Even" : "Odd";
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

template <class T>
inline void read(T &x)
{
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int ans[10];
int n, m;
bool is[10];

int main()
{
    read(n), read(m);
    if (!m)
    {
        if (n == 1) 
        {
            puts("0");
            return 0;
        }
        else    
        {
            printf("1");
            for (int i = 2; i <= n; ++i)    printf("0");
            puts("");
            return 0;
        }
    }
    for (int i = 1, s, c; i <= m; ++i)
    {
        read(s), read(c);
        if (is[s] && ans[s] != c)
        {
            puts("-1");
            return 0;
        }
        is[s] = true;
        ans[s] = c;
    }
    if (n > 1 && ans[1] == 0 && is[1])
    {
        puts("-1");
        return 0;
    }
    if (!is[1]) ans[1] = 1;
    for (int i = 1; i <= n; ++i)    printf("%d", ans[i]);
    puts("");
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys 
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def union(x,y):
    x = find(x)
    y = find(y)
    if x != y:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y] #xにyの個数くっつける 
        par[y] = x #yをxにくっつける
        return 

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

N,Q = map(int,readline().split())
#0-index
par = [-1]*N
for _ in range(Q):
    x,y = map(int,readline().split())
    x-=1; y-=1
    union(x,y)

ans = set()
for i in range(N):
    ans.add(find(i))
print(len(ans)-1)

Measured memory_bytes: 79252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll h,w,n;
  cin>>h>>w>>n;
  vll c(h,vl(w));
  ll sum=0;
  ll a;
  rep(i,n){
    cin>>a;
    rep(j,a){
        ll y=sum/w,x=sum%w;
        c[y][x]=i+1;
        sum++;
    }
  }
  rep(i,h){
      rep(j,w){
          if(i%2==1){
              cout<<c[i][w-1-j]<<" ";
          }
          else{
              cout<<c[i][j]<<" ";
          }
      }
      cout<<endl;
  }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size()
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, n) for (int i = 1; i <= n; i++)
#define ford(i, n) for (int i = n; i >= 0; i--)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define foreach(itr, c) for (__typeof((c).begin(), (c).end()) itr = c.begin(); itr != c.end(); itr++)
#define fill(a, b) memset(a, b, sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

using namespace std;

int main()
{
    int k;
    int ans;
    int res = -1;
    int t = 0;

    cin >> k;

    if (k == 2 || k == 5)
    {
        cout << res;
        return 0;
    }

    rep(i, 1000000)
    {
        t += 7;
        if (t % k == 0)
        {
            res = i + 1;
            break;
        }

        t = (t * 10) % k;
    }

    cout << res;
    return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

const int P = 1000 * 1000 * 1000 + 7;
const int MAXN = 5100;

int sum (int x, int y) {
	return (x + y) % P;
}

int mult (int x, int y) {
	return (x * (long long) y) % P;
}

int myPow (int x, int k) {
	if (k == 0) {
		return 1;
	}
	
	int res = myPow(x, k / 2);
	res = mult(res, res);
	if (k % 2 == 1) {
		res = mult(res, x);
	}

	return res;
}

int inv (int x) {
	return myPow(x, P - 2);
}

string s;
int d[MAXN][MAXN];

int main () {
    ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	int k;
	cin >> k;
	cin >> s;
	int n = sz(s);
                                                
    d[0][0] = 1;
    for (int i = 0; i < k; ++i) {
    	for (int j = 0; j <= i; ++j) {
    		d[i + 1][j + 1] = sum(d[i + 1][j + 1], mult(2, d[i][j]));
    		d[i + 1][max(j - 1, 0)] = sum(d[i + 1][max(j - 1, 0)], d[i][j]);
    	}
    }

    int res = mult(d[k][n], inv(myPow(2, n)));
    cout << res << endl;

	return 0;
}


Measured memory_bytes: 67456
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef vector <string> VS;

const int size = 31;
VS lines( size );
bool O[size][10];
int n, m, a, d;

bool dfs( int t, int k ) {
    if ( t == d ) {
        return k == a - 1;
    }
    if ( k == 0 ) {
        if ( O[t][k] ) return dfs( t + 1, k + 1 );
    } else if ( k == n - 1 ) {
        if ( O[t][k-1] ) return dfs( t + 1, k - 1 );
    } else {
        if ( O[t][k] ) return dfs( t + 1, k + 1 );
        if ( O[t][k-1] ) return dfs( t + 1, k - 1 );
    }
    return dfs( t + 1, k );
}

bool check() {
    return dfs( 0, m - 1 );
}

void solve() {
    for ( int i = 0; i < d; ++ i ) {
        for ( int j = 0; j < n; ++ j ) {
            if ( O[i][j] ) continue;
            if ( ( j-1 >= 0 && O[i][j-1] ) || ( j+1 < n-1 && O[i][j+1] ) ) continue;
            O[i][j] = true;
            if ( check() ) {
                cout << i + 1 << " " << j + 1 << endl;
                return;
            }
            O[i][j] = false;
        }
    }
    cout << 1 << endl;
}

int main() {
    while ( cin >> n && n ) {
        cin >> m >> a >> d;
        for ( int i = 0; i < d; ++ i ) {
            cin >> lines[i];
        }
        for ( int i = 0; i < d; ++ i ) {
            for ( int j = 0; j < n; j++ ) {
                O[i][j] = false;
            }
        }
        for ( int i = 0; i < d; ++ i ) {
            for ( int j = 0; j < n - 1; ++ j ) {
                O[i][j] = ( lines[i][j] == '1' );
            }
        }
        if ( check() ) {
            cout << 0 << endl;
        } else {
            solve();
        }
    }
    return 0;
}

Measured memory_bytes: 0
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let K: usize = sc.get();
    let T: usize = sc.get();
    let a: Vec<i64> = sc.vec(T);
    let mut amax = 0;
    for i in 0..T {
        amax = max(amax, a[i]);
    }
    let ans = max(amax - 1 - (K as i64 - amax), 0);
    println!("{}", ans);
}


Measured memory_bytes: 4352
N, A, B, C, D = map(int, input().split())
S = input()
if C < D:
    Aok = "##" not in S[A-1:C]
    Bok = "##" not in S[B-1:D]
    if Aok and Bok:
        print("Yes")
    else:
        print("No")
else:
    Aok = "##" not in S[A-1:C]
    Bok = "##" not in S[B-1:D]
    jumpok = "..." in S[B-2:D+1]
    if Aok and Bok and jumpok:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 40816
#include <stdio.h>
#define N 8

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];
int X[N][N];

void init(){
  int i, j;
  for(i=0; i<N; i++) row[i] = col[i] = 0;
  for(i=0; i<2*N-1; i++) dpos[i] = dneg[i] = 0;
  for(i=0; i<N; i++) {
    for(j=0; j<N; j++) {
      X[i][j] = 0;
    }
  }
}

void printBoard(){
  int i, j;
  for(i=0; i<N; i++) {
    for(j=0; j<N; j++) {
      if(X[i][j] == 1) {
    if(row[i] != j) return;
      }
    }
  }
  for(i=0; i<N; i++) {
    for(j=0; j<N; j++) {
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void putQueen(int i) {
  int j;
  if(i == N) {
    printBoard();
    return;
  }

  for(j=0; j<N; j++) {
    if(col[j] == 1 || dpos[i+j] == 1 || dneg[i-j+N-1] == 1) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = 1;
    putQueen(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = 0;
  }
}

int main() {
  int i, k, r, c;

  init();

  scanf("%d",&k);
  for(i = 0; i < k; i++) {
    scanf("%d%d",&r,&c);
    X[r][c] = 1;
  }

  putQueen(0);

  return 0;
}




Measured memory_bytes: 2112
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    sort(ALL(s));
    vector<pair<string, int>> p;
    p.push_back(make_pair(s[0], 1));
    for(int i = 1;i < n;i++){
        if (s[i] == p.back().first){
            p.back().second++;
        }else{
            p.push_back(make_pair(s[i], 1));
        }
    }

    int mx = -1;
    rep(i, p.size()){
        mx = max(mx, p[i].second);
    }
    rep(i, p.size()){
        if (p[i].second == mx) cout << p[i].first << "\n";
    }
}


Measured memory_bytes: 17780
#!/usr/bin/env python3
N = int(input())
p = list(map(int, input().split()))

r = [0] * N
for i in range(N):
    r[p[i] - 1] = i + 1
a = list(30000 * (i + 1) for i in range(N))
print(' '.join(map(str, a)))
b = list(30000 * (N - (i + 1)) + r[i] for i in range(N))
print(' '.join(map(str, b)))


Measured memory_bytes: 7992
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e6 + 10, MOD = 1e9 + 7;



int main() {
    fastInp;
    
    ll x;
    cin >> x;

    ll pr = 0, i = 1;
    while (true) {
        pr += i;
        if (pr >= x) {
            cout << i << "\n";
            return 0;
        }
        i++;
    }

    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>

int main(){
  char A[101], B[101], C[101];
  int Ai, Bi, Ci;
  char X;

  scanf("%s", A);
  scanf("%s", B);
  scanf("%s", C);
  X = A[0];
  Ai = 0, Bi = 0, Ci = 0;

  while(1){
    if(X == 'a'){
      if(A[Ai] == '\0'){
        printf("A");
        break;
      }else{
        X = A[Ai];
        Ai++;
      }
    }
    else if(X == 'b'){
      if(B[Bi] == '\0'){
        printf("B");
        break;
      }else{
        X = B[Bi];
        Bi++;
      }
    }
    else if(X == 'c'){
      if(C[Ci] == '\0'){
        printf("C");
        break;
      }else{
        X = C[Ci];
        Ci++;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

int main () {
    int k;

    cin >> k;

    long long ans = 0;

    for (int i = 1 ; i <= k ; ++ i) {
        for (int j = 1 ; j <= k ; ++ j) {
            for (int v = 1 ; v <= k ; ++ v) {
                ans += __gcd(i, __gcd(j, v));
            }
        }
    }

    cout << ans << endl;
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <array>
#include <type_traits>
#include <functional>
#include <utility>

int main()
{
    long long a, b;
    char op;
    std::cin >> a >> op >> b;
    switch (op) {
    case '+':
        std::cout << a + b;
        break;
    case '-':
        std::cout << a - b;
        break;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9+7;
long long dp[1000001][4];
long long solve(int ind, int cond){
    if (ind==0){
        return cond==3;
    }
    if (dp[ind][cond]!=-1)
        return dp[ind][cond];
    long long cur = 0;
    for (int i=0; i<=9; i++){
        if (i==0){
            if (cond==3){
                cur = (cur+solve(ind-1, cond))%M;
            }
            else if (cond==2){
                cur = (cur+solve(ind-1, 3))%M;
            }
            else if (cond==1){
                cur = (cur+solve(ind-1, cond))%M;
            }
            else cur = (cur+solve(ind-1, 1))%M;
        }
        else if (i==9){
            if (cond==3 || cond==2)
                cur = (cur+solve(ind-1, cond))%M;
            else if (cond==0)
                cur = (cur+solve(ind-1, 2))%M;
            else cur = (cur+solve(ind-1, 3))%M;
        }
        else cur = (cur+solve(ind-1, cond))%M;
    }
    return dp[ind][cond] = cur;

}
int main(){
    memset(dp, -1, sizeof(dp));
    int no;
    cin >> no;
    cout << solve(no, 0) << "\n";
}

Measured memory_bytes: 97324
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define rep(a,b) for(ll int a=0;a<b;a++)
#define Tcase int t;cin>>t;while(t--)
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int flag=0,count_it=0;
  for(int i=0;i<n;i++){
       // cout<<flag<<endl;
  	if(flag==0 && s[i]=='A')
      flag++;
    else if(flag==1 && s[i]=='B')
      flag++;
    else if(flag==2 && s[i]=='C')
      flag++;
    else if(s[i]=='A')
      flag=1;
      else
        flag=0;
    if(flag==3){
      count_it++;
      flag=0;
      }
  }
  cout<<count_it<<endl;
return 0;
}








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

int main()
{
	int H, N, A;

	cin >> H >> N;

	int sum = 0;
	for(int i = 1; i <= N; i++)
    {
        cin >> A;
        sum = sum + A;
    }

    if(sum >= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
    int x,a,b;
    cin >> x >> a >> b;
    int d=abs(x-a);
    int e=abs(x-b);
    (e > d)? cout << "A" : cout << "B";
    return 0;
}

Measured memory_bytes: 256
S = input()
A, B, C, D = map(int, list(S))

check = False
for i in range(2):
    if check:
        i = 0
        break
    for j in range(2):
        if check:
            j = 0
            break
        for k in range(2):
            ans = A
            if i==0:
                ans += B
            else:
                ans -= B
            
            if j==0:
                ans += C
            else:
                ans -= C
            
            if k==0:
                ans += D
            else:
                ans -= D
            
            if ans == 7:
                check = True
                break

if i==0:
    i = "+"
else:
    i = "-"

if j==0:
    j = "+"
else:
    j = "-"

if k==0:
    k = "+"
else:
    k = "-"

print("{}{}{}{}{}{}{}=7".format(A, i, B, j, C, k, D))


Measured memory_bytes: 3064
<?php
$x = trim(fgets(STDIN));
for($i=-118; $i<=119; $i++){
	for($j=-118; $j<=119; $j++){
		if(pow($i, 5) - pow($j, 5) == $x){
			$ans = "$i $j" . "\n";
			break;
		}
	}
}

echo $ans;

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

using namespace std;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

const u64 MOD = 1000000007;

template <std::uint_fast64_t Modulus>
class ModInt {
  using u64 = std::uint_fast64_t;

 public:
  u64 x;

  constexpr ModInt(const u64 x = 0) noexcept : x(x % Modulus){};

  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    x += rhs.x;
    if (x >= Modulus) {
      x -= Modulus;
    }
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (x < rhs.x) {
      x += Modulus;
    }
    x -= rhs.x;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    x = x * rhs.x % Modulus;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    u64 n = Modulus - 2;
    while (n) {
      if (n & 1) {
        *this *= rhs;
      }
      rhs *= rhs;
      n /= 2;
    }
    return *this;
  }
  constexpr ModInt operator++(int) noexcept {
    ModInt y = *this;
    x += 1;
    return y;
  }
  constexpr ModInt operator--(int) noexcept {
    ModInt y = *this;
    x -= 1;
    return y;
  }
  constexpr bool operator==(const ModInt rhs) noexcept { return x == rhs.x; }
  constexpr bool operator!=(const ModInt rhs) noexcept { return x != rhs.x; }

  friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
    is >> rhs.x;
    return is;
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
    os << rhs.x;
    return os;
  }
};

template <typename T, typename U>
T pow(T x, U n) {
  T res = 1;
  while (n > 0) {
    if (n & 1) res *= x;
    x *= x;
    n >>= 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  map<int, int> primes;
  for (int i = 0; i < N; i++) {
    int x = A[i];
    for (int p = 2; p * p <= A[i]; p++) {
      int cnt = 0;
      while (x % p == 0) {
        x /= p;
        cnt++;
      }
      primes[p] = max(primes[p], cnt);
    }
    if (x > 1) primes[x] = max(primes[x], 1);
  }

  using mint = ModInt<MOD>;

  mint l = 1;
  for (auto itr = primes.begin(); itr != primes.end(); itr++) {
    l = l * pow(static_cast<mint>(itr->first), itr->second);
  }
  mint res = 0;
  for (int i = 0; i < N; i++) {
    res += l / A[i];
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <stack>
#include <vector>

int dots_num(std::string s) {
    int num = 0;
    int loop = 0;
    while (s[loop] == '.') {
        ++num; 
        ++loop;
    }
    return num;
}

int value_num(char c) {
    int ret;
    if (c == '+') {
        ret = -1; 
    } else if (c == '*') {
        ret = -2;
    } else {
        ret = (int) c - 48;
    }
    return ret;
}

void dfs(int n) {
    std::string s;
    std::stack<std::pair<int, int> > st;
    st.push(std::make_pair(0, 0));
    int dots;
    int value;
    int start_dots;
    std::vector<int> enzan(2);
    std::pair<int, int> p;

    for (int i = 0; i < n; i++) {
        std::cin >> s;
        dots = dots_num(s);
        value = value_num(s[dots]);


        while (1) {
            if (st.top().first <= dots) {
                break; 
            }
            start_dots = st.top().first;
            enzan[0] = 0;
            enzan[1] = 1;
            while (1) {
                if (start_dots > st.top().first) {
                    break;
                }
                enzan[0] += st.top().second;
                enzan[1] *= st.top().second;
                st.pop();
            }
            if (st.top().second == -1) {
                p = std::make_pair(st.top().first, enzan[0]);
                st.pop();
                st.push(p);
            } else if(st.top().second == -2) {
                p = std::make_pair(st.top().first, enzan[1]);
                st.pop();
                st.push(p);
            }
        }
        st.push(std::make_pair(dots, value));
    }

    while (1) {
        if (st.top().first == 0) {
            break; 
        }
        start_dots = st.top().first;
        enzan[0] = 0;
        enzan[1] = 1;
        while (1) {
            if (start_dots > st.top().first) {
                break;
            }
            enzan[0] += st.top().second;
            enzan[1] *= st.top().second;
            st.pop();
        }

        if (st.top().second == -1) {
            p = std::make_pair(st.top().first, enzan[0]);
            st.pop();
            st.push(p);
        } else if(st.top().second == -2) {
            p = std::make_pair(st.top().first, enzan[1]);
            st.pop();
            st.push(p);
        }
    }

    std::cout << st.top().second << std::endl;
    return;
}

int main(void) {
    int n;

    while (1) {
        std::cin >> n;
        if (n == 0) {
            break;
        }
        dfs(n);
    }
    return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
#define N 	100*1000+5


void solve(){
	string s;
	cin>>s;
	int tem = 1, st = -1, en =-1;
	rep(i,0,sz(s)){
		if(s[i]=='A' && tem){st = i;tem = 0;}
		if(s[i]=='Z')en = i;
	}
	cout<<en-st+1<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 720
/*
s[n]=0
s[1]=1
s[i]=s[n-1-i]
の3条件が明らかに必要。

辺はn-1本あるので、sに0が多いときは、同じ大きさの木がたくさんできるようにしないといけない
大きさ1の木は必ず存在するので、それが多くなるようにすることを考えてみる
sが1000...,1100...,1110...,10100...,などの場合を考えることで（twitterの図）
いい感じのものを思いつける
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

char s[100010];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	int flag=s[n]=='0'&&s[1]=='1';
	rep(i,1,n)flag&=s[i]==s[n-i];
	if(!flag){
		puts("-1");
		return 0;
	}
	
	int prev=n;
	for(int i=n-1;i>=1;i--){
		printf("%d %d\n",prev,i);
		if(s[i]=='1')prev=i;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    vector<pair<int,int> > a(100000);
    vector<pair<int,int> > b(100000);
    for(int i=0;i<n;i++){
        int v;
        cin>>v;
        if(i%2==0){
            a.at(v-1).first++;
            a.at(v-1).second=v;
        }
        else{
            b.at(v-1).first++;
            b.at(v-1).second=v;
        }
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a.at(a.size()-1).second!=b.at(b.size()-1).second)
        cout<<n-a.at(a.size()-1).first-b.at(b.size()-1).first<<endl;
    else cout<<n-max(a.at(a.size()-1).first+b.at(b.size()-2).first,a.at(a.size()-2).first+b.at(b.size()-1).first)<<endl;;
    return 0;
}


Measured memory_bytes: 3328
s=str(input())
num=len(s)-7

ans="NO"

if num==0:
    if s=="keyence":
        ans="YES"

s=s+"!"

s1=""
s2=s[0:num]
s3=s[num:]

for _ in range(8):
    if s1+s3=='keyence!':
        ans="YES"
        break
    s1=s1+s2[0]
    s2=s2[1:]+s3[0]
    s3=s3[1:]

print(ans)

Measured memory_bytes: 3064
n = int(input())
ais = list(map(int, input().split()))
if len(ais) == 1:
  print(1)
  quit()
if ais[0] < ais[1]:
  tend = 1
elif ais[0] > ais[1]:
  tend = -1
else:
  tend = 0
pref = ais[1]
ans = 1
for a in ais[2:]:
  if pref < a and tend == -1:
    ans += 1
    tend = 0
  elif pref > a and tend == 1:
    ans += 1
    tend = 0
  elif tend == 0:
    if pref < a:
      tend = 1
    elif pref > a:
      tend = -1
    elif pref == a:
      pass
  pref = a
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

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

    vector<double> E(n+1, 0);
    double ans = -1;
    rep(i, 1, n+1)
    {
        double p;
        cin >> p;
        double exp = (p + 1.0) / 2.0;
        // E[i] += exp;
        // if (i+k <= n) E[i+k] -= exp; 
        E[i] = E[i-1] + exp;

        if (i >= k) ans = max(ans, E[i] - E[i - k]);
    }


    // rep(i, 0, n)
    // {
    //     E[i+1] += E[i];
    // }

    // sort(E.begin(), E.end());
    // reverse(E.begin(), E.end());

    // cout << E[0] << endl;
    cout << fixed<<setprecision(10)<<ans << endl;
}


Measured memory_bytes: 1792
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 3888
#include <iostream>

using namespace std;
/** Problem0104 : Magical Tiles **/
int main()
{
	char room[110][110];
	int w, h, x, y;
	
	while (cin >> h >> w, w != 0 && h != 0) {
		for (int y=0; y<h; y++) {
			for (int x=0; x<w; x++) {
				cin >> room[x][y];
			}
		}

		x=0; y=0;
		while (1) {
			if (room[x][y] == '>') {
				room[x][y] = 'L';
				x++;
			} else if (room[x][y] == '<') {
				room[x][y] = 'L';
				x--;
			} else if (room[x][y] == '^') {
				room[x][y] = 'L';
				y--;
			} else if (room[x][y] == 'v') {
				room[x][y] = 'L';
				y++;
			} else if (room[x][y] == 'L') {
				cout << "LOOP" << endl;
				break;
			} else if (room[x][y] == '.') {
				cout << x << " " << y << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1172
def matrix_chain_multiplication(n, list):
    matrix = [[0 for i in range(n)] for j in range(n)]

    for i in range(n-1):
        for j in range(n-i-1):
            k = j+i+1
            matrix[j][k] = float('inf')
            for r in range(j, k):
                matrix[j][k] = min(matrix[j][k],
                    matrix[j][r] + matrix[r+1][k]
                    + list[j]*list[r+1]*list[k+1])

    return matrix[0][n-1]

if __name__ == '__main__':
    n = int(input())

    list = list(map(int, input().split()))
    for i in range(n-1):
        list.append(int(input().split()[1]))

    print(matrix_chain_multiplication(n, list))

Measured memory_bytes: 7756