akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = list(input())

def string_match(str):
    length = len(str)
    half = length//2
    fore_str = str[0:half]
    aft_str = str[half:]
    flg = True
    for i in range(0, half):
        if fore_str[i] != aft_str[i]:
            flg = False
            break
    return flg


if n % 2 != 0:
    flg = False
else:
    flg = string_match(s)

if flg:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
bool subset(string big , string small){
	int ptr = 0;
	for(char c : small){
		while(ptr < big.size() && big[ptr] != c){
			++ptr;
		}
		if(ptr == big.size()){
			return 0;
		}
		++ptr;
	}
	return 1;
}
int main(){
	string str;
	cin >> str;
	if(subset("AKIHABARA" , str) && subset(str , "KIHBR")){
		cout << "YES\n";
	}
	else{
		cout << "NO\n";
	}
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    D = set(list(map(int, input().split())))

    def dfs(L):
        if len(L) == 6:
            return

        for i in range(10):
            if i not in D:
                L.append(str(i))
                res = int("".join(L))
                if res >= n:
                    ans.append(res)
                dfs(L)
                L.pop()

        return ans

    ans = []
    dfs([])
    ans.sort()
    for i in ans:
        if n <= i:
            print(i)
            break


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 26644
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip>
#include<sstream>
#include<string.h>
using namespace std;
double z[200003];
double y[200003];
int main()
{
    int n, i, k, j;
    double a;
    while (cin >> n >> k)
    {
        a = 0;
        for (i = 0;i < k-1;i++)
        {
            cin >> z[i];
            z[i] = (z[i] + 1) / 2;
        }
        cin >> z[i];
        z[i] = (z[i] + 1) / 2;
        for (j = 0;j < k;j++)
        {
            a += z[j];
        }
        j = 0;
        y[j++] = a;
        for (i++;i < n;i++, j++)
        {
            cin >> z[i];
            z[i] = (z[i] + 1) / 2;
            y[j] = y[j - 1];
            y[j] -= z[i - k];
            y[j] += z[i];
            if (a < y[j])
                a = y[j];
        }
        cout << fixed << setprecision(12);
        cout << a << '\n';
    }
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>
int main(){
	int k;
	char str[100];
	scanf("%d", &k);
	scanf("%s", str);
	int len = strlen(str);
  	if (len > k) {
  		for (int i = 0; i < k; i++) {
      	printf("%c", str[i]);
  		}
  	printf("...\n");
  	}
	else { 
    	 printf("%s", str);
    }
  	
	return 0;
}

Measured memory_bytes: 1732
class UnionFindWithRank(object):
    par = []
    rank = []
    cache = True
    log = []

    def __init__(self, n):
        for i in range(n):
            self.par.append(i)
            self.rank.append(0)

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            p = self.root(self.par[x])
            self.par[x] = p
            return p

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        ox, oy = x, y
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            x, y = y, x
            self.par[y] = x

        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

n, q = map(int, input().split())
u = UnionFindWithRank(n)
for _ in range(q):
    c, a, b= map(int, input().split())
    a, b = a, b
    if c == 0:
        u.unite(a, b)
    else:
        print(1 if u.same(a, b) else 0)


Measured memory_bytes: 6140
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	pairs := make([]Pair, n)
	var x, y int
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		pairs[i] = Pair{x, y}
	}

	mx := 0
	pm := make(map[[2]int]int)
	for i := 0; i < n-1; i++ {
		pi := pairs[i]
		for j := i + 1; j < n; j++ {
			pj := pairs[j]
			k1 := [2]int{pi.x - pj.x, pi.y - pj.y}
			k2 := [2]int{pj.x - pi.x, pj.y - pi.y}
			pm[k1]++
			pm[k2]++
			mx = max(mx, max(pm[k1], pm[k2]))
		}
	}

	fmt.Println(n - mx)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// Pair .
type Pair struct {
	x, y int
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;
    
    vl s(n);
    rep(i, n) {
        cin >> s[i];
    }
    vl t(m);
    rep(i, m) {
        cin >> t[i];
    }
    
    vvl dp(n, vl(m));  // dp[i][j] : s[i]とt[j]まででs[i]とt[j]を含む整数列として等しい空でない部分列の組の個数
    vvl rui(n+1, vl(m+1));  // rui[i][j] : sum_{0 <= x < i, 0 <= y < j} dp[x][y]
    rep(i, n) {
        rep(j, m) {
            if(s[i] == t[j]) {
                dp[i][j] = rui[i][j] + 1;
            }
            rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] + mod - rui[i][j] + dp[i][j];
            dp[i][j] %= mod;
            rui[i+1][j+1] %= mod;
        }
    }
    
    out((rui[n][m] + 1)%mod);
    re0;
}

Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define pq 	priority_queue<int, vector<int>, greater<int> >
ll e=  1000000007;
using namespace std;

int main(){
	

ll n;
cin>>n;
ll a[n+2],b[n+1];
for(ll i=1;i<n+2;i++)
{
	cin>>a[i];
}
for(ll i=1;i<n+1;i++)
{
	cin>>b[i];
}	
ll sum=0;
for(ll i=1;i<n+1;i++)
{
	if(a[i]>=b[i]){
		sum=sum+b[i];
	}
	else {
	sum=sum+a[i];
	b[i]-=a[i];
	if(a[i+1]<=b[i])
	{
		sum=sum+a[i+1];a[i+1]=0;
		}
		else{
			sum=sum+b[i];
			a[i+1]-=b[i];
			
		}	
		
	}
	
}
cout<<sum;
	
 return 0;
}

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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B<C+D){
  cout << "Right" << endl;
  }
  else if(A+B==C+D){
  cout << "Balanced" << endl;
  }
  else{
  cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int coin_through_num(const int& K, const int& i)
{
    int ans = 0, tmp = i;
    while (true) {
        if (K <= tmp) return ans;
        tmp *= 2;
        ++ans;
    }
}

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

    double ans = 0.0;
    rrep (i, 1, N) {
        if (i <= K-1) {
            int head_n = coin_through_num(K, i);
            ans += ((1.0/N) * pow(0.5, head_n));
        }
        else {
            ans += 1.0/N;
        }
    }
    printf("%.10f", ans);
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, x = li()

if n == 2:
    if x == 2:
        print("Yes")
        for i in range(1, 4):
            print(i)

    else:
        print("No")

else:
    ans = [0]*(2*n - 1)
    rem = [i for i in range(1, 2*n)]

    if x == 1 or x == 2*n-1:
        print("No")

    else:
        print("Yes")
        if x == 2:
            ans[n - 2] = x+1
            ans[n - 1] = x
            ans[n] = x-1
            ans[n + 1] = x+2

            for i in range(x-1, x+3):
                rem.remove(i)

            for idx in range(2*n-1):
                if n-2 <= idx <= n+1:
                    continue

                ans[idx] = rem.pop()

        else:
            ans[n - 2] = x - 1
            ans[n - 1] = x
            ans[n] = x + 1
            ans[n + 1] = x - 2

            for i in range(x - 2, x + 2):
                rem.remove(i)

            for idx in range(2 * n - 1):
                if n - 2 <= idx <= n + 1:
                    continue

                ans[idx] = rem.pop()

        print("\n".join(map(str, ans)))


Measured memory_bytes: 25032
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string s;
    cin >> s;
    if (s.size() == 2)
        cout << s << endl;
    else {
        char t1 = s[0];
        char t2 = s[2];
        s[0] = t2;
        s[2] = t1;
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
class Main{
	
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int times = scan.nextInt();
		int num[] =new int[times];
		mathClass keisan =new mathClass();
		for(int i=0; i<times;i++){
			num[i] = scan.nextInt();
		}
//		int[] nouse = keisan.shellSort(num, times);
		int[] nouse = new int[times];
		nouse = keisan.shellSort(num,times);
		keisan.disp(nouse);


	}
}
class mathClass{
	static int cnt = 0;
	static int tm =0;
	public mathClass(){
		
	}
	//?????????????????????????????????
	public int[] insertSort(int[] A,int n,int g){
		for(int i=g ;i<n;i++){
			int v = A[i];
			int j = i-g;
			while(j>=0 && A[j]>v){
				A[j+g] = A[j];
				j = j - g;
				cnt ++;
			}
			A[j+g] = v;
		}
//		System.out.println("cnt is "+cnt);
		return A;
	}
	//?????§?????????????????????
	public int[] shellSort(int[] A,int n){
		mathClass keisan =new mathClass();
		cnt = 0;
		int[] ret = A.clone();
		int importG[]  = new int[100];
		tm =0;
		for(int i=1; i<n; i=3*i+1){
			importG[tm] = i;
			tm++;
		}
		int G[] = new int [tm];
		for(int i=0;i<tm;i++){
			
			G[i] = importG[tm-1-i];
		}

		int m = G.length;//??????G?????????
		keisan.disp2(m,G);
		
		for(int i=0;i<m;i++){
			ret = keisan.insertSort(A, n, G[i]);
			
		}
		return ret;
	}
	//???????????¨???
	public void disp(int[] ary){
		System.out.println(cnt);
		for(int i=0;i<ary.length;i++){
			System.out.println(ary[i]);
		}
	}
	public void disp2(int m,int[] ary){
		if(tm == 0){
			System.out.println(1);
			System.out.println(1);
		}
		else{
			System.out.println(m);
			for(int i=0;i<ary.length;i++){
				
				System.out.print(ary[i]);
				if(i == ary.length-1){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		}
	}
}

Measured memory_bytes: 300020
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;

typedef int W;

const int MAX_V = 400 * (1 << 10);
const W INF = 1 << 20;

struct edge {
	int to;
	W cost;
};
typedef pair<W, int> P;

vector<edge> G[MAX_V];
W d[MAX_V];


void dijkstra(int s) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d, d + MAX_V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int w, h;
string b[20];
int wf[20][20][20][20];

struct point {
	int x, y;
};

int v(int x, int y) {
	return w * y + x;
}

int v2(int x, int y, int s) {
	return s * (h*w) + v(x, y);
}

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

	while(cin >> w >> h, w | h) {
		memset(wf, INF, sizeof wf);
		for(int i = 0; i < 20; i++) {
			for(int j = 0; j < 20; j++) {
				for(int k = 0; k < 20; k++) {
					for(int l = 0; l < 20; l++) {
						if(i == k && j == l) wf[i][j][k][l] = 1;
						else wf[i][j][k][l] = INF;
					}
				}
			}
		}
		for(int i = 0; i < MAX_V; i++) {
			G[i].clear();
		}

		for(int i = 0; i < h; i++) {
			cin >> b[i];
		}
		vector<point> p;
		int sx = -1, sy = -1;
		for(int y = 0; y < h; y++) {
			for(int x = 0; x < w; x++) {
				if(b[y][x] == 'o') {
					sx = x, sy = y;
				}
				if(b[y][x] == '*') {
					p.push_back(point{ x, y });
				}
				if(b[y][x] != 'x') {
					int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };
					for(int i = 0; i < 4; i++) {
						int nx = x + dx[i], ny = y + dy[i];
						if(0 <= nx && nx < w && 0 <= ny && ny < h && b[ny][nx] != 'x') {
							wf[x][y][nx][ny] = wf[nx][ny][x][y] = 1;
						}
					}
				}
			}
		}

		for(int kx = 0; kx < w; kx++) {
			for(int ky = 0; ky < h; ky++) {
				for(int ix = 0; ix < w; ix++) {
					for(int iy = 0; iy < h; iy++) {
						for(int jx = 0; jx < w; jx++) {
							for(int jy = 0; jy < h; jy++) {
								wf[ix][iy][jx][jy] = min(wf[ix][iy][jx][jy],
									wf[ix][iy][kx][ky] + wf[kx][ky][jx][jy]);
							}
						}
					}
				}
			}
		}

		p.push_back(point{ sx, sy });
		for(int i = 0; i < p.size(); i++) {
			for(int j = 0; j < p.size(); j++) {
				for(int k = 0; k < 1 << (p.size() - 1); k++) {
					if(k & (1 << j)) {
						G[v2(p[i].x, p[i].y, k)].push_back(
							edge{ v2(p[j].x, p[j].y, k ^ (1 << j)), wf[p[i].x][p[i].y][p[j].x][p[j].y] }
						);
					}
				}
			}
		}

		dijkstra(v2(sx, sy, (1 << (p.size() - 1)) - 1));
		int ans = INF;
		for(int i = 0; i < p.size() - 1; i++) {
			ans = min(ans, d[v2(p[i].x, p[i].y, 0)]);
		}

		if(ans == INF) {
			cout << -1 << endl;
		}
		else {
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 20432
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>//"geometry.cpp"
#include <iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <algorithm>//"lower_bound(it,it,v)", "next_permutation(a,a+n)"
#include <functional>//"greater<T>" Ex. sort(a,a+n,greater<int>());
#include <cmath>//"abs", "sqrt"
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef pair<int,int> pii;

vector<int> g[100000];
int d[100000];//distance from 1
bool f[100000];

int dfs(int v){
	int ret=1;
	for(int j=0;j<g[v].size();++j){
		int w=g[v][j];
		if(f[w]) continue;
		f[w]=true;
		ret+=dfs(w);
	}
	return ret;
}

int main(){
	int n;
	cin>>n;
	for(int j=0;j<n-1;++j){
		int a,b;
		cin>>a>>b;
		g[--a].pb(--b);
		g[b].pb(a);
	}
	fill(f,f+n,false);
	queue<int> q;
	q.push(0);
	f[0]=true;
	while(!q.empty()){
		int v=q.front();
		q.pop();
		for(int j=0;j<g[v].size();++j){
			int w=g[v][j];
			if(f[w]) continue;
			f[w]=true;
			d[w]=d[v]+1;
			q.push(w);
		}
	}
	vector<int> c;
	fill(f,f+n,false);
	f[0]=true;
	for(int v=n-1;v!=0;){
		for(int j=0;j<g[v].size();++j){
			int w=g[v][j];
			if(d[w]!=d[v]-1) continue;
			c.pb(v);
			f[v]=true;
			v=w;
		}
	}
	c.pb(0);
	int snu=0;
	for(int i=0;i<c.size()/2;++i){
		snu+=dfs(c[i]);
	}
	if(snu>=(n+1)/2) cout<<"Snuke"<<endl;
	else cout<<"Fennec"<<endl;
}

Measured memory_bytes: 9980
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] reader= ReadLine().Split(' ');
        int leng = int.Parse(reader[1]);
        
        int[] counter = new int[100010];
        int[] wcount = new int[100010];
        int ac =0;
        int wa = 0;
        
        for(int i=0;i<leng;i++){
            string[] reader2 = ReadLine().Split(' ');
            int num = int.Parse(reader2[0]);
            string aw = reader2[1];
            if(aw == "AC"){
                counter[num]++;
                if(counter[num] == 1){
                    ac++;
                    wa+= wcount[num];
                }
            }else if(aw == "WA"){
                if(counter[num] == 0){
                    wcount[num]++;
                }
            }
        }
        WriteLine($"{ac} {wa}");
    }
}


Measured memory_bytes: 17868
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] ab = scanner.nextLine().split(" ", 2);
        int a = Integer.parseInt(ab[0]);
        int b = Integer.parseInt(ab[1]);
        if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}


Measured memory_bytes: 23252
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n,i,j,k,c=0,temp;
   cin>>n;
   int a[n];
   for(i=0;i<n;i++)
   cin>>a[i];
    for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
        if(a[i]>a[j]){
           temp=a[i];
           a[i]=a[j];
           a[j]=temp;
      }
    }
}
    
   for(i=0;i<n;i++){
      for(j=i+1;j<n;j++){
        for(k=j+1;k<n;k++){ 
           if(a[i]!=a[j] && a[j]!=a[k]){
            if(a[i]+a[j]>a[k])
                c++;
        }
      }
    }
  }
     cout<<c<<endl;
     return 0;
   
}

Measured memory_bytes: 3592
n = int(input())
org_list = list(map(int, input().split()))
org_list.sort(reverse=True)

i = 0
AliceScore = 0
BobScore = 0

while i <= n-1:
    if i % 2 == 0:
        AliceScore += org_list[i]
    else:
        BobScore += org_list[i]
    i += 1

print(AliceScore - BobScore)

Measured memory_bytes: 3060
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] NX = Console.ReadLine().Split(' ');
        int N = int.Parse(NX[0]);
        int X = int.Parse(NX[1]);
        int[] m = new int[N];
        int ans = 0;
        for(int i=0;i<N;i++)
        {
            m[i] = int.Parse(Console.ReadLine());
        }
        Array.Sort(m);
        int rem = X;
        for(int i = 0; i < N; i++)
        {
            rem -= m[i];
        }
        ans = rem / m[0] + N;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
int ar[100005];

bool solve(){
  lint cnt=0;
  int odd=0,one=0;
  REP(i,n){
    if(ar[i]==1) ++one;
    cnt+=ar[i]-1;
    if(ar[i]&1) ++odd;
  }
  if(n==1){
    return true;
  }
  if(odd>=2 || one>0){
    if(cnt%2) return false;
    else return true;
  }
  assert(odd==1);
  if(cnt%2){
    return false;
  }
  REP(i,n) if(ar[i]&1){
    --ar[i];
  }
  int g=0;
  REP(i,n) g=__gcd(ar[i],g);
  REP(i,n) ar[i]/=g;
  return (solve()^true);
}
int main(){
  cin>>n;
  REP(i,n){
    scanf("%d",&ar[i]);
  }
  puts(solve()?"Second":"First");
  return 0;
}





Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    lint n, k;
    cin >> n >> k;
    vector<pair<lint, lint>> p(n);
    repeat(i, n) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());
    lint cnt = 0;
    repeat(i, n) {
        cnt += p[i].second;
        if (cnt >= k) {
            cout << p[i].first << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k;



//方針　a(n)をsortして小さいものから順に大きいものと交換していく
int main(){
    ll n,m;cin>>n>>m;
    

    vector<ll> a(n);
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());//aをsort    

    vector<ll> b(m),c(m);
    for(i=0;i<m;i++){
        cin>>b[i]>>c[i];
    }

    vector<pair<ll,ll>> P(m);
    for(i=0;i<m;i++){
        P[i]=make_pair(c[i],b[i]);
    }

    sort(P.begin(),P.end(),greater<pair<ll,ll>>());
    //cが大きい順になるように交換したいのでsort

    ll num=0,key=0,sum=0;
    for(i=0;i<m;i++){
        vector<long long int>::iterator position;//binary search  交換したいので、まず、交換不可能なa[i]のうち最小のものを探す
        position=lower_bound(a.begin()+num,a.end(),P[i].first);//置き換え済みのものの次から順に見ていく
        key=distance(a.begin(),position);
        if(key==num && P[i].first<a[num]){break;}
        
        key-=num;//num:置き換え済みのものの個数->keyは次に置き換え可能なものの個数
        if(key>=P[i].second){sum+=P[i].first*P[i].second;num+=P[i].second;}
        //a[num]以前のa[i]は置き換え済み
        //keyがcの個数(b)以上の時はb個を小さいものからcで置き換える方がよい
        else{sum+=P[i].first*key;num+=key;break;}
    }

    for(i=num;i<n;i++){
        sum+=a[i];
    }

    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int64_t x;
    cin >> x;

    int64_t ans = 0;
    ans = x / 11;
    ans *= 2;
    if(0 < x % 11 && x % 11 <= 6){
        ++ans;
    }
    else if(x % 11 > 6){
        ans += 2;
    }
    cout << ans << endl;

    return 0;
};

Measured memory_bytes: 256
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for i in range(n)])
shop,cost,rest=0,0,m
while True:
    if ab[shop][1]<rest:
        cost += ab[shop][1]*ab[shop][0]
        rest -= ab[shop][1]
        shop+=1
    else:
        cost+=ab[shop][0]*rest
        break
print(cost)

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


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

    if(s == "SUN") cout<<7<<endl;
    else if(s == "MON") cout<<6<<endl;
    else if(s == "TUE") cout<<5<<endl;
    else if(s == "WED") cout<<4<<endl;
    else if(s == "THU") cout<<3<<endl;
    else if(s == "FRI") cout<<2<<endl;
    else if(s == "SAT") cout<<1<<endl;


    return 0;
}

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

// ループによる最大公約数
long long gcd(long long x, long long y){
  long long r;
  if(x < y) swap(x, y);
  
  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

// gcdを利用した最小公倍数
long long lcm(long long x, long long y){
  return x * y / gcd(x, y);
}

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long count = b - a + 1, x, y, z, w, p, q;
  
  x = (a - 1) / c;
  y = b / c;
  count -= (y - x);
  
  z = (a - 1) / d;
  w = b / d;
  count -= (w - z);
  
  p = (a - 1) / lcm(c, d);
  q = b / lcm(c, d);
  count += (q - p);
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

int main(){
int n;
int cnt=0;
int flg=0;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
    cin>>a.at(i);
}

while(1){
    flg=0;
    for(int i=0;i<n;i++){
        if(a.at(i)%2!=0){
            flg++;
        }
        a.at(i)=a.at(i)/2;
    }
    if(flg>0){
        cout<<cnt<<endl;
        break;
    }
    cnt++;
}
}













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

int main()
{
	int s;
	cin >> s;
	int ans = 0;
	vector<int> A(1000);
	A[0] = s;
	int flag = 0;
	for (int i = 0;i < 1000;i++) {
		if (A[i] % 2 == 0) {
			A[i + 1] = A[i] / 2;
		}
		else if (A[i] % 2 == 1) {
			A[i + 1] = 3 * A[i] + 1;
		}
		for (int j = 0;j < i+1;j++) {
			if (A[i + 1] == A[j]) {
				flag = 1;
			}
		}
		if (flag == 1) {
			ans = i + 2;
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
palace = []
for i in range(1, n+1):
    candidate =[]
    temperature =abs(a -(t - h[i-1] *0.006))
    candidate.append(temperature)
    candidate.append(i)
    palace.append(candidate)
sort_palace = sorted(palace)
print(sort_palace[0][1])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
ll n;
ll a,b,c;
vector<ll> l(10);
ll dfs(ll i, ll x, ll y, ll z){
    if(i==n){
        if(x!=a && y!=b && z!=c){
        return abs(x) + abs(y) + abs(z);
        }else{
            return LINF;
        }
    }else{
        ll ans = LINF;
         ans = min(ans ,dfs(i+1, x,y,z));
         if(a==x){
         ans = min(ans ,dfs(i+1, x-l[i],y,z));
         }else{
         ans = min(ans ,10+dfs(i+1, x-l[i],y,z));
         }
         if(b==y){
         ans = min(ans ,dfs(i+1, x,y-l[i],z));
         }else{
         ans = min(ans ,10+dfs(i+1, x,y-l[i],z));
         }
         if(c==z){
         ans = min(ans ,dfs(i+1, x,y,z-l[i]));
         }else{
         ans = min(ans ,10+dfs(i+1, x,y,z-l[i]));
         }
         return ans ;
    }

}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
   cin >> n >> a >> b >> c;
  REP(i,n){
      cin >> l[i];
  }
  ll ans = dfs(0,a,b,c);
  cout << ans << endl;

}



Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  val buff = StdIn.readLine().split(' ').map(_.toInt)
  
  @tailrec def printReverse(index: Int): Unit = {
    
    if(index == 0) println(buff(0))
    else {
      print(buff(index) + " ")
      printReverse(index-1)
    }
  }
  
  printReverse(n-1)
  
}


Measured memory_bytes: 43804
// Blackjack
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>

using namespace std;

int main ()
{
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;

    if ((A1 + A2 + A3) <= 21) {
        cout << "win" << endl;
    }
    else {
        cout << "bust" << endl;
    }
    return 0;
}

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

using namespace std;

using int64 = long long;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

struct Bipartite_Graph : UnionFind
{
  vector< int > color;

  Bipartite_Graph(int v) : color(v + v, -1), UnionFind(v + v) {}

  bool bipartite_graph_coloring()
  {
    for(int i = 0; i < color.size() / 2; i++) {
      int a = find(i);
      int b = find(i + (int) color.size() / 2);
      if(a == b) return (false);
      if(color[a] < 0) color[a] = 0, color[b] = 1;
    }
    return (true);
  }

  bool operator[](int k)
  {
    return (bool(color[find(k)]));
  }
};

int main()
{
  int64 N, M;
  cin >> N >> M;
  Bipartite_Graph uf(N);
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b + N);
    uf.unite(b, a + N);
  }
  if(uf.bipartite_graph_coloring()) {
    int64 beet = 0;
    for(int i = 0; i < N; i++) beet += uf[i];
    int64 other = N - beet;
    cout << beet * other - M << endl;
  } else {
    cout << N * (N - 1) / 2 - M << endl;
  }
}

Measured memory_bytes: 1792
while True:
    s = input()
    if s == 'END OF INPUT':
        break
    
    # for word in s.split():
    #     print(len(word), end='')
    # print()
    
    count = 0
    for i in range(len(s)):
        if s[i:i + 1] == ' ':
            print(count, end='')
            count = 0
        else:
            count += 1
    
    print(count)


Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=310;
char s[N];
int m,ss[N],p[N];
int dp[N][N][N],ans;

void upd(int &a,int b) {
	a+=b; if (a>=mod) a-=mod;
}
int main() {
	scanf("%s%d",s,&m);
	int n=strlen(s);
	reverse(s,s+n);
	m=min(m,n);
	int p0=0;
	rep(i,0,n) {
		if (s[i]=='0') ss[p0+1]=ss[p0],p0++;
		else p[p0]++,ss[p0]++;
	}

	dp[0][0][0]=1;
	rep(i,1,p0+2) rep(k,0,m+1) {
		int t=0;
		rep(j,0,ss[i-1]+1) {
			for (int z=0;z<p[i-1]&&z<=j;z++)
				upd(dp[i][j][k+p[i-1]-z],dp[i-1][j-z][k]);
			if (j-p[i-1]>=0) upd(t,dp[i-1][j-p[i-1]][k]);
			upd(dp[i][j][k],t);
		}
	}
	rep(i,0,m+1) upd(ans,dp[p0+1][ss[p0]][i]);
	printf("%d\n",ans);
}

Measured memory_bytes: 31120
#include<stdio.h>
int main()
{
    int a,b,c ;
    scanf ("%d%d%d",&a,&b,&c) ;
    for (int i=1; i>0; i++){
        if (a*i%b==c) {
            printf ("YES\n") ;
            exit (0) ;
        }
        if (i>1 && a*i%b==a%b){
            printf ("NO\n") ;
            exit (0) ;
        }
    }
    return 0 ;
}


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

using i64 = long long;
using P = pair<i64, i64>;


void solve(long long A, long long B, long long K){
    if(A < K){
        cout << 0 << " " << max(B - (K - A), 0LL) << endl;
    }else{
        cout << A - K << " " << B << endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
 
int main(){
  int n;
  vector<int> result;
 
  while(cin>>n,n!=0){
    int count=0;
    int i=n+1;
    if(n!=1){
      if(i%2==0) i++;
      while(i<=2*n){
    int k=0;
    for(int j=3;j<=sqrt(i);j+=2){
      if(i%j==0){
        k=1;
        break;
      }
    }
    if(k==0) count++;
    i+=2;
      }
    }
    else count++;
     
    result.push_back(count);
  }
   
  for(auto i:result){
    cout<<i<<endl;
  }
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll a, b, c;
cin >> a >> b >> c;    
    if (a + b + c >= 22) cout << "bust\n";
    else cout << "win\n";
}



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

const int N = 1e5 + 5;
vector< pair< int, int> > Vp;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d %d", &a, &b);
		if(a > b) swap(a, b);
		Vp.emplace_back(b, a);
	}

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

	int last = 0, res = 0;
	for(auto it: Vp) {
		int a = it.first, b = it.second;
		if(b < last) continue;
		res++;
		last = a;
	}
	printf("%d\n", res);
}

Measured memory_bytes: 1400
#include<iostream>
#include<iomanip>
#include<complex>
using namespace std;
typedef complex<double> Point;

Point Prj(Point z1, Point z2, Point z3) {
    Point z = (z3 - z1) / (z2 - z1);
    return (z2 - z1) * z.real() + z1;
}

int main() {
    int n;
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> n;
    Point z1(x1, y1), z2(x2, y2);
    while (n--)
    {
        cin >> x3 >> y3;
        Point z3(x3, y3);
        Point p = Prj(z1, z2, z3);
        cout << fixed << setprecision(10) << p.real() << " " << p.imag() << endl;
    }
    return 0;
}


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

#define ll long long

int N, W;
int v[111], w[111];
int dp[111][11111];

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

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j >= w[i]) {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            } else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 7416
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int n;
  string s;
  int k;
  cin >> n >> s >> k;
  char c = s[k-1];
  LOOP(i,n){
    if(s[i] != c){
      s[i] = '*';
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
import           Control.Monad
import           Data.List.Split

main :: IO ()
main = do
  (s : ss) <- getLine
  let combi = replicateM (length ss) [True, False]

  let pairs = map (splitOn "+" . isrtPls (s : ss)) combi

  let sums  = [ (sum . map read) x | x <- pairs ]
  print $ sum sums

isrtPls :: String -> [Bool] -> String
isrtPls s [] = s
isrtPls (s : ss) (c : cs) =
  if c then s : '+' : isrtPls ss cs else s : isrtPls ss cs


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

long fact(long i) {
    if (i == 0) return 1l;
    return i * fact(i-1) % MOD;
}

int main() {
    long n;
    cin >> n;
    cout << fact(n) <<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){

  int n, ans = 1000000000, tmp = 0;
  cin >> n;

  int a[n];

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

  for (int i = 0; i < n; i++) {
    tmp = 0;

    while(true){

        if (a[i] % 2 == 0) {
          a[i] = a[i] / 2;
          tmp += 1;
        }else{
          ans = min(ans, tmp);
          break;
        }
    }
  }

  cout << ans << endl;



}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;

int main()
{
	int n,k,x,y,ans;
	while(~scanf("%d%d%d%d",&n,&k,&x,&y)){
		ans = min(n,k) * x;
		if(n > k) ans += (n - k) * y;
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main (void){

  int W,H,x,y,r;

  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if (x-r<0){
    printf("No\n");
  } else if (x+r>W){
    printf("No\n");
  } else if (y-r<0){
    printf("No\n");
  } else if (y+r>H){
    printf("No\n");
  } else {
    printf("Yes\n");
  }

  return 0;
}

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

#define int long long
#define double long double

using namespace std;

#define REP(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) REP(i, 0, n)
#define PER(i, a, b) for (int(i) = (a - 1); i >= (b); (i)--)
#define per(i, n) PER(i, n, 0)
#define each(i, n) for (auto &i : n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define dum(val) cerr << #val " = " << val;
#define dump(val) cerr << #val " = " << val << endl;
#define FILL(a, v) fill(a, a + sizeof(a) / sizeof(*a), v)

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const int mod = 1e9 + 7;
const int INF = 1e9;

signed main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}

	int ans = 0;
	rep(i, n - 1) {
		if (a[i] == i && a[i + 1] == i + 1) {
			swap(a[i], a[i + 1]);
			ans++;
		}
	}
	rep(i, n) {
		if (a[i] == i) {
			if (i - 1 >= 0 && a[i - 1] != i) {
				swap(a[i], a[i - 1]);
			} else if (i + 1 <= n - 1 && a[i + 1] != i) {
				swap(a[i], a[i + 1]);
			}
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
n = input()
sq = [map(int,raw_input().split()) for u in xrange(n)]
s_sq = [[[0]*n for u in xrange(n)] for uu in xrange(n)]
#s_sq[lower_end][left_end][right_end]
ma = -1000 * 100 * 100
for y in xrange(n):
    temp = [0] * (n+1)
    for x in xrange(n):
        #make sum of the sequence left_end == 0, right_end == n
        temp[x] = temp[x-1] + sq[y][x]
    for tx in xrange(n):
        for ex in xrange(tx,n):
            s_sq[y][tx][ex] = max([0,s_sq[y-1][tx][ex]]) + temp[ex] - temp[tx-1]
            ma = max([ma,s_sq[y][tx][ex]])
print ma

Measured memory_bytes: 25356
#include<stdio.h>
#define MAX 10000
#define NIL -1

/* 木のデータを入れる構造体*/
struct Node { int p, l, r; };
struct Node T[MAX];
int n;

/* 構造体のデータを表示する関数*/

/* 先行順巡回*/
void preParse(int u) {
    if ( u == NIL ) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

/* 中間順巡回*/
void inParse(int u) {
    if ( u == NIL ) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

/* 後行順巡回*/
void postParse(int u) {
    if ( u == NIL ) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main(void) {
   int i, v, l, r, root;

   scanf("%d", &n);
   /* データの設定*/
   for ( i = 0; i < n; i++ ) {
       T[i].p = NIL;
   }

   for ( i = 0; i < n; i++ ) {
       scanf("%d %d %d", &v, &l, &r);
       T[v].l = l;
       T[v].r = r;
       if ( l != NIL ) T[l].p = v;
       if ( r != NIL ) T[r].p = v;
   }

   for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;

   printf("Preorder\n"); // 1行目
   preParse(root);
   printf("\n");
   printf("Inorder\n"); // 3行目
   inParse(root);
   printf("\n");
   printf("Postorder\n"); // 5行目
   postParse(root);
   printf("\n");

   return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s, t;
	cin >> s >> t;

	s += s;
	ll n = sz(s);
	vvl next(n+1,vl(26,oo));
	FORD(i,0,n) {
		next[i] = next[i+1];
		next[i][s[i]-'a'] = i;
	}
	n /= 2;

	ll res = 0, i = 0;
	for (char c: t) {
		ll j = next[i][c-'a'] + 1;
		if (j >= oo) {
			cout << -1 << endl;
			return 0;
		}
		res += j-i;
		i = j % n;
	}
	cout << res << endl;
}



Measured memory_bytes: 49004
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

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

const int N = (int)2e6 + 5;
const int inf = (int)1e9 + 7;

int n;
int p[N];
int l[N], r[N];
int mx[20][N], lg[N];
stack < int > s;

int get(int l, int r){
  int z = lg[r - l + 1];
  return max(mx[z][l], mx[z][r - (1 << z) + 1]);
}

int getl(int pos, int x){
  if(pos == 1 && p[pos - 1] > x){
    return 1;
  }
  int e = pos;
  for(int j = 20; j >= 0; --j){
    if(e > (1 << j) && get(e - (1 << j), pos - 1) < x) e -= (1 << j);
  }
  return pos - e + 1;
}

int getr(int pos, int x){
  if(pos == n && p[pos + 1] > x){
    return 1;
  }
  int e = pos;
  for(int j = 20; j >= 0; --j){
    if(e + (1 << j) <= n && get(pos + 1, e + (1 << j)) < x) e += (1 << j);
  }
  return e - pos + 1;
}

int main(){
  scanf("%d", &n);
  for(int i = 2; i <= n; ++i) lg[i] = lg[i / 2] + 1;
  for(int i = 1; i <= n; ++i){
    scanf("%d", p + i);
    mx[0][i] = p[i];
  }

  for(int j = 1; j < 20; ++j){
    for(int i = 1; i + (1 << j) - 1 <= n; ++i){
      mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + (1 << (j - 1))]);
    }
  }
  for(int i = 1; i <= n; ++i){
    while(!s.empty() && p[s.top()] < p[i]) r[s.top()] = i, s.pop();
    s.push(i);
  }
  while(!s.empty()) r[s.top()] = n + 1, s.pop();
  for(int i = n; i >= 1; --i){
    while(!s.empty() && p[s.top()] < p[i]) l[s.top()] = i, s.pop();
    s.push(i);
  }
  while(!s.empty()) l[s.top()] = 0, s.pop();
  ll ans = 0;
  for(int i = 1; i <= n; ++i){
    if(p[i] == n) continue;
    if(l[i] != 0){
      int j = l[i];
      int le = getl(j, p[i]);
      int re = r[i] - i;
      ans += le * 1ll * re * p[i];

    }
    if(r[i] != n + 1){
      int j = r[i];
      int le = i - l[i];
      int re = getr(j, p[i]);
      ans += le * 1ll * re * p[i];
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 50152
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define Reza ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define         ll          long long
#define         yes         cout<<"YES"<<endl
#define         no          cout<<"NO"<<endl
#define         ff          first
#define         sc          secound
#define         MAX         10000

int main()
{
    Reza;
    string s,s2,s3,s4,s5;
      ll q,n,a,b,c,d,x,y,o,cnt=0,cnt2=1,sum=0,mm=0,mx=0;
   cin>>n;
   for(ll i=1;i<=n;i++){
     for(ll j=1;j<=n;j++){
        for(ll k=1;k<=n;k++){
            a=__gcd(i,__gcd(j,k));
            sum+=a;

        }
     }
   }
   cout<<sum<<endl;


    return 0;

}






Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int prod = 0;
  rep(i, n) {
    cin >> a[i];
    prod ^= a[i];
  }
  rep(i, n) {
    cout << (prod ^ a[i]) << endl;
  }

  return 0;
}


Measured memory_bytes: 4036
#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(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> c(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }

    vector<int> ans_m(m);
    ll sum = 1e9;
    ll memo = 0;
    int state = -1;

    for(int bit=0;bit < (1<<n);bit++){
        rep(k,m) ans_m[k] = 0;
        memo = 0;
        rep(j,n){
            if(bit & (1<<j)){
                memo += c[j];
                rep(i,m){
                    ans_m[i] += a[j][i];
                }
            }
        }
        rep(abc,m){
            if (ans_m[abc] < x){
                break;
            }
            if(abc == m-1){
                sum = min(sum,memo);
                state = 0;
            }
        }
    }
    if(state == -1){
        cout << -1 << endl;
    }else{
        cout << sum << endl;
    }
}

Measured memory_bytes: 3632
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;
        string s; cin >> s;
        vector<int >left(26,0);
        vector<int>right(26,0);
        for(int i = 0; i<n; i++){
            right[s[i]-'a']++;
        }
        int res =0;
        for(int i = 0; i<n; i++){
            right[s[i]-'a']--;
            left[s[i]-'a']++;
            int ans = 0;
            for(int  j = 0; j<26; j++){
                if(left[j]!=0 and right[j]!= 0)ans++;
            }
            res = max(res,ans);
        }
        cout<<res<<endl;
return 0;
}



Measured memory_bytes: 3656