akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
  int a,b,c;
  scanf("%d%d",&a,&b);
  if(b==100){
    c=1000*a+b;
  }else if(b>=10){
    c=100*a+b;
  }else{
    c=10*a+b;
  }
  int num[c];
  int left=1;
  int right=c/2;
  int mid;
  for(int i=1;i<=c;i++){
    num[i]=i;
  }
  while(left<=right){
    mid=(left+right)/2;
    if(num[mid]*num[mid]==c){
      puts("Yes");
      return 0;
    } else if(num[mid]*num[mid]<c){
      left=mid+1;
    } else {
      right=mid-1;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	void solve() throws IOException {
		int n = ni();
		int m = ni();
		int q = ni();
		int[][] a = new int[n + 1][n + 1];
		for (int i = 0; i < m; i++) {
			int s = ni();
			int e = ni();
			a[s][e]++;
		}
//		Helper.tr(a);
		for (int i = 1; i <= n; i++)
			for (int j = i; j <= n; j++) {
				a[i][j] += a[i][j - 1];
			}
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++) {
				a[j][i] += a[j-1][i];
			}
//		Helper.tr(a);
		for (int i = 1; i <= q; i++) {
			int s = ni();
			int e = ni();
			out.println(a[e][e]-a[s-1][e]-a[e][s-1]+a[s-1][s-1]);
		}
	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}

Measured memory_bytes: 60772
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

int dp[5005][5005];

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

    int n; string s;
    cin >> n >> s;

    for(int i=n-1; i>=0; i--){
        for(int j=n-1; j>=0;j--){
            if(s[i] != s[j]) dp[i][j]=0;
            else dp[i][j] = dp[i+1][j+1]+1;
        }
    }

    int ans = 0;
    rep(i,n) rep(j,n){
        if(i>=j) continue;  // i<j
        ans = max(ans, min(dp[i][j], j-i));
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 98048
#from collections import defaultdict, deque
#import itertools
#import numpy as np
#import re
import bisect

def main():
    N = int(input())
    SS = []
    for _ in range(N):
        SS.append(input())
    S = []
    for s in SS:
        while '()' in s:
            s = s.replace('()', '')
        S.append(s)
    #print(S)
    S = [s for s in S if s != '']
    sum_op = 0
    sum_cl = 0
    S_both_op = []
    S_both_cl = []
    for s in S:
        if not ')' in s:
            sum_op += len(s)
        elif not '(' in s:
            sum_cl += len(s)
        else:
            pos = s.find('(')
            if pos <= len(s) - pos:
                S_both_op.append((pos, len(s)-pos))  #closeのほうが少ない、'))((('など -> (2,3)
            else:
                S_both_cl.append((pos, len(s)-pos))  #closeのほうが多い、')))(('など -> (3,2)

    # S_both_opは、耐えられる中でより伸ばす順にしたほうがいい？
    #S_both_op.sort(key=lambda x: (x[0], x[0]-x[1]))  #closeの数が小さい順にsortかつclose-openが小さい=伸ばす側にsort
    #S_both_cl.sort(key=lambda x: (x[0], x[0]-x[1]))  #これもcloseの数が小さい順にsortかつclose-openが小さい=あまり縮まない順にsort
    S_both_op.sort(key=lambda x: x[0])
    S_both_cl.sort(key=lambda x: -x[1])

    for p in S_both_op:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]

    for p in S_both_cl:
        sum_op -= p[0]
        if(sum_op < 0 ):
            print('No')
            exit()
        sum_op += p[1]
    
    if sum_op == sum_cl:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()

Measured memory_bytes: 56928
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]

def set_top(dice, top):
    return [dice[i] for i in mask[top]]

def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]

def equal(dice1, dice2):
    if sorted(dice1) != sorted(dice2):
        return False
    
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False

def diff_check_all(dices, n):
    for i in range(n -1):
        for j in range(i + 1, n):
            if equal(dices[i], dices[j]):
                return False
    return True
            

n = int(input())
dices = [input().split() for _ in range(n)]

print('Yes' if diff_check_all(dices, n) else 'No')


Measured memory_bytes: 5612
n = int(input())
a = list(map(int,input().split()))
b = a[::2]
c = a[1::2]
br = a[-2::-2]
cr = a[::-2]

if n%2==0:
    print(' '.join(map(str, cr+b)))
else:
    print(' '.join(map(str, cr + c)))

Measured memory_bytes: 32036
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define ryuque(t) priority_queue<t,vec<t>,greater<t>>
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define MOD 1000000007ll
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}

//nCk(mod p)
const ll NUM=2;
ll fac[NUM],finv[NUM],inv[NUM];
void cmodf(ll p=MOD){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	rep(i,2,NUM){
		fac[i]=fac[i-1]*i%p;
		inv[i]=p-inv[p%i]*(p/i)%p;
		finv[i]=finv[i-1]*inv[i]%p;
	}
}
ll cmod(ll n,ll k,ll p=MOD){
	return fac[n]*(finv[k]*finv[n-k]%p)%p;
}

//最大公約数
ll gcd(ll n,ll m){
	ll k=n%m;
	while(k!=0){n=m;m=k;k=n%m;}
	return m;
}
ll gcd(vector<ll> a){
	rep(i,1,a.size()){
		ll k=a[i-1]%a[i];
		while(k!=0){
			a[i-1]=a[i];
			a[i]=k;
			k=a[i-1]%a[i];
		}
	}
	return a.back();
}

//最小公倍数
ll lcm(ll n,ll m){
	ll t=n*m,k=n%m;
	while(k!=0){n=m;m=k;k=n%m;}
	return t/m;
}
ll lcm(vector<ll> a){
	ll n;
	rep(i,1,a.size()){
		n=a[i-1]*a[i];
		ll k=a[i-1]%a[i];
		while(k!=0){
			a[i-1]=a[i];
			a[i]=k;
			k=a[i-1]%a[i];
		}
		n/=a[i];
		a[i]=n;
	}
	return n;
}

//keyの小さい方から探していった時に初めてvalueがjoken以上になる時のkey（keyが増えたらvalueも増えるか同じになるとき）
ll value(ll key) {
	/*変更*/
	return 0;
}
ll mink(ll lkey,ll rkey/*ここも調べる*/,ll joken){
	ll mkey;
	while(lkey!=rkey){
		mkey=(lkey+rkey)/2;
		if(value(mkey)>=joken)rkey=mkey;
		else lkey=mkey+1;
	}
	return rkey;
}

//ペア配列の整理
struct pea{
	ll f,s;
	bool operator<(const pea &c)const{
		return f!=c.f?f<c.f:s<c.s;
	};
};

//変数定義

//再帰関数

//アルゴリズム
void solve(){
	ll n;cin>>n;
	vec<vll> we(n,vll(n,MOD));
	vec<set<ll>> ch(n);
	vec<vll> pa(n);
	rep(i,0,n){
		ll u,k;cin>>u>>k;
		rep(j,0,k){
			ll v,c;cin>>v>>c;
			ch[u].insert(v);
			pa[v].pub(u);
			we[u][v]=c;
		}
	}
	vll a,ans(n);
	ans[0]=0;
	a.pub(0);
	rep(i,0,pa[0].size())ch[pa[0][i]].erase(0);
	while(a.size()!=n){
		ll m=MOD;ll jj;
		rep(i,0,a.size()){
			for(auto j=ch[a[i]].begin();j!=ch[a[i]].end();j++){
				if(ans[a[i]]+we[a[i]][*j]<m){
					m=ans[a[i]]+we[a[i]][*j];
					jj=*j;
				}
			}
		}
		ans[jj]=m;
		a.pub(jj);
		rep(i,0,pa[jj].size())ch[pa[jj][i]].erase(jj);
	}
	rep(i,0,n){
		cout<<i<<' '<<ans[i]<<kai;
	}
}


Measured memory_bytes: 3240
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (h, n): (usize, usize);
    input!(h, n);
    let a = input_vector::<usize>();
    let s = a.iter().sum::<usize>();
    if s < h {
        println!("No");
    } else {
        println!("Yes");
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int x = a + b;
  
  if (x % 2 == 0) cout << x / 2 << endl;
  else cout << (x + 1) / 2 << endl;
}

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

int main(){
  int n,r=0;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  rep(i,n) if(v[i] != i+1) r++;
  if(r>2) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  string a, b;
  cin >> a >> b;
  reverse(b.begin(), b.end());
  cout << (a == b ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String[] hon = {
            "pon", //0
            "pon", //1
            "hon", //2
            "bon", //3
            "hon", //4
            "hon", //5
            "pon", //6
            "hon", //7
            "pon", //8        
            "hon" //9        
        };
        int N = sc.nextInt();

        System.out.println(hon[N%10]);
    }
}

Measured memory_bytes: 27084
#include <iostream>

using namespace std;

int N;
int X[100];
const int inf = 1000000000;
#define rep(i, c) for(int i = 0; i < int(c); i ++)

int main() {
	cin >> N;
  	rep(i, N) cin >> X[i];
  	int ans = inf;
  	rep(i, 100) {
    	int cost = 0;
      	rep(j, N) cost += (i - X[j]) * (i - X[j]);
      	if (ans > cost) {
        	ans = cost;
        } 
    }
  
  	printf("%d", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n, q;
	cin >> n;
	vector<int> S(n);

	for (int i = 0; i < n; i++)
	{
		cin >> S.at(i);
	}

	cin >> q;
	// vector<int> T;
	// for (int i = 0; i < q; i++)
	// {
	// 	cin >> T.at(i);
	// }

	int count = 0;
	int t;

	//順番に見て行って同じだったらcount++
	for (int i = 0; i < q; i++)
	{
		cin >> t;
		for (int j = 0; j < n; j++)
		{
			if (S.at(j) == t)
			{
				// tmpS.erase(tmpS.begin + j);
				count++;
				break;
			}
		}
	}

	cout << count << endl;
}


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

using namespace std;

string s;
int main()
{
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5])
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define REP(i, n) for(int i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) out << (x) << endl;

using namespace std;


class BAcCepted {
public:
    string S;
    string ans = "AC";

    void solve(std::istream& in, std::ostream& out) {
        in >> S;
        if (S[0] != 'A') ans = "WA";
        ll cnt = 0;
        for (int i = 2; i <= S.length() - 2; i++) if (S[i] == 'C') cnt++;
        if (cnt != 1) ans = "WA";
        REP(i, S.length()) {
            if (S[i] - 'a' < 0 && i != 0 && S[i] != 'C') ans = "WA";
        }
        DUMP(ans);
    }
};


int main() {
    BAcCepted solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//typedef long long ll;
//const int MOD=1e9+7;
int main(){
  int n; cin >>n; int m=0;
  map<string,int>mapp;
  for(int i=0; i<n; i++){string s; cin >>s; mapp[s]++;}
  for(auto it=mapp.begin(); it!=mapp.end(); it++) m=max(m,it->second);
  for(auto it=mapp.begin(); it!=mapp.end(); it++)
  if(it->second==m) cout <<it->first<<endl;
return 0;}

Measured memory_bytes: 25216
n = int(input())
A = list(map(int, input().split()))
cnt = [0, 0, 0]
for a in A:
    if a % 4 == 0:
        cnt[2] += 1
    elif a % 2 == 0:
        cnt[1] += 1
    else:
        cnt[0] += 1


if cnt[2] < cnt[0]-1:
    print('No')
else:
    if cnt[2] == cnt[0]-1:
        if cnt[1]:
            print('No')
        else:
            print('Yes')
    else:
        print('Yes')


Measured memory_bytes: 20012
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int x=0;
  cin>>n;
  vector<int>vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);}
  for(int i=0;i<n;i+=2){
    if (vec.at(i)%2==1){x+=1;}
  }
  cout<<x<<endl;}

Measured memory_bytes: 3628
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y,ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        ll w=(p*p)%z;
        if(y%2==0)
         return w;
        else
        return (x*w)%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    string s;
    cin>>s;
    int n=s.length()-1;
    if(s[n]=='s')
    cout<<s<<"es";
    else
    cout<<s<<"s";}

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

int main(){ 
    string s;
    cin>>s;
    if(s[5]=='1'){
        cout<<"TBD";   }
        else if(s[6]=='1'||s[6]=='2'||s[6]=='3'||s[6]=='4'){
            cout<<"Heisei";
        }else{
            cout<<"TBD";
        }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int[][] boob=new int[H+2][W+2];
		int[][] suji=new int[H][W];

		for(int i=0; i<=H+1; i++) {
			for(int j=0; j<=W+1; j++) {
				boob[i][j]=0;
			}
		}
		String a="";
		for(int i=1; i<=H; i++) {
			a=sc.next();
			for(int j=1; j<=W; j++) {
				if(a.charAt(j-1)=='.') {
					boob[i][j]=0;
				}

				else if(a.charAt(j-1)=='#') {
					boob[i][j]=1;
				}
			}
		}

		int counter=0;
		for(int i=1; i<=H; i++) {
			for(int j=1; j<=W; j++) {
				counter=0;
				if(boob[i][j]==0) {
					for(int k=-1; k<=1; k++) {
						for(int l=-1; l<=1; l++) {
							suji[i-1][j-1]+=boob[i+k][j+l];
						}
					}
				}
				else {
					suji[i-1][j-1]=10;
				}
			}
		}
		String b="";
		for(int i=0; i<H; i++) {
			b="";
			for(int j=0; j<W; j++) {
				if(suji[i][j]<10) {
					b=b+""+suji[i][j];
				}
				else {
					b=b+"#";
				}
			}
			System.out.println(b);
		}
	}
}

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

int main() {
  int n, y, b, r, t;
  while (cin >> n, n) {
    int ans = 0;
    double g, maxg = 0.0;
    cin >> y;
    while (n--) {
      cin >> b >> r >> t;
      if (t == 1) g = 1 + y * (r / 100.0);
      else  g = pow(1 + r / 100.0, y);
      if (g > maxg) {
        ans = b;
        maxg = g;
      }
    }
    cout << ans << "\n";
  }
}


Measured memory_bytes: 3364
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  ll n, x;
  scanf("%lld%lld", &n, &x);
  printf("%lld\n", n - x > 0 ? n - x : 0);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 2007, inf = 0x3f3f3f3f;
int n, ans = inf;
int son[N]; char s[N];
vector<int>G[N];
struct data {int L, R;}t[N];
data operator +(data a, data b) {
	data res;
	res.R = a.R + b.R;
	if(a.L > b.L) swap(a, b);
	if(a.R <= b.L) res.L = b.L - a.R;
	else res.L = res.R & 1;
	return res;
}
void dfs(int u, int fa) {
	son[u] = s[u] == '1';
	t[u] = (data){0, 0};
	int sum = 0;
	for(auto v:G[u]) if(v ^ fa) {
		dfs(v, u);
		son[u] += son[v];
		t[v].L += son[v];
		t[v].R += son[v];
		t[u] = t[u] + t[v];
		sum += t[v].R;
	}
	t[u].L = inf;
	for(auto v:G[u]) if(v ^ fa) {
		Min(t[u].L, sum - t[v].R - t[v].L);
	}
	if(t[u].L > 0) t[u].L = t[u].R & 1;
	else t[u].L = -t[u].L;
}
int main() {
#ifdef fwat
#endif
	n = gi();
	scanf("%s", s + 1);
	rep(i, 1, n - 1) {
		int x = gi(), y = gi();
		G[x].pb(y);
		G[y].pb(x);	
	}
	rep(i, 1, n) {
		dfs(i, 0);
		if(t[i].L == 0) Min(ans, t[i].R / 2);
	}
	printf("%d\n", ans == inf ? -1 : ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=805;
//i_am_noob
int n,c[20],v[20],ans=0;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n;
	rep(n) cin >> c[i];
	rep(n) cin >> v[i];
	rep(n) if(c[i]>v[i]) ans+=c[i]-v[i];
	print1(ans);
	return 0;
}


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

int main(void) {
  int n, d;
  cin >> n >> d;

  // input
  int x[n][d];
  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin >> x[i][j];
    }
  }

 // loop i, j (i < j)
  int ans = 0;
  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){

      // calculate dist^2
      int dist2 = 0;
      for(int k=0; k<d; k++){
        dist2 += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
      }

      // Is dist2 a square number?
      // max dist2 is estimated to be 16000
      for(int r=0; r*r<20000; r++){
        if(dist2 == r*r) ans++;
      }

    }
  }

  // output
  cout << ans << endl;
}


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

int main(){
  int n;
  cin >> n;
  if (n % 2 != 0){
    puts("No");
    return 0;
  }
  string s;
  cin >> s;
  for (int i = 0; i < n/2; i++){
    if (s.at(i) != s.at(i+n/2)){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int n;
    cin>>n;
    string s;
    cin>>s;
    map<char,vector<int>> mp;
    rep(i,n){
        mp[s[i]].push_back(i);
    }
    int ans=0;
    rep(i,n){
        rep(j,i){
            if(s[i]==s[j])continue;
            int a='R'+'G'+'B';
            char c=a-s[i]-s[j];
            if(binary_search(mp[c].begin(),mp[c].end(),i+i-j)){
                ans--;
            }
            ans+=mp[c].end()-upper_bound(mp[c].begin(),mp[c].end(),i);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3680
#include <stdio.h>
int main(void)
{
	int a, b;
	while(scanf("%d %d", &a, &b)!=EOF && !(a==0 && b==0)){
		if(a > b)
			printf("%d %d\n", b, a);
		else
			printf("%d %d\n", a, b);
	}
	return 0;
} 

Measured memory_bytes: 600
/****************************************************
*   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,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>

#define deb(x) cout << #x << " is " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long k, n;
	cin >>k >>n;
	vector<long long> arr(n);
	for(long long i = 0; i < n; i++)
		cin >>arr[i];
	long long mx = 0, prev = 0;
	for(long long i = 0; i < n; i++) {
		mx = max(mx, abs(prev - arr[i]));
		prev = arr[i];
	}
	mx = max(mx, k - arr[n-1] + arr[0]);
	cout <<k - mx;
	return 0;
}


Measured memory_bytes: 1920
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<math.h>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

int main() {
	string a, b, c;
	ll n;
	ll ans = 0;
	cin >> n >> a >> b >> c;
	REP(i, 0, n - 1) {
		if (a[i] == b[i] && b[i] == c[i]) {
			continue;
		}
		else if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) {
			ans += 2;
		}
		else {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<pair<string, int>> M(N);
    string S;
    for (int i = 0; i < N; i++) cin >> M[i].first >> M[i].second;
    cin >> S;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (M[i].first != S) ans += M[i].second;
        else ans = 0;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll T[2], A[2], B[2];
    rep(i,2)cin >> T[i];
    rep(i,2)cin >> A[i];
    rep(i,2)cin >> B[i];
    ll AM[2], BM[2];
    rep(j,2)AM[j] = A[j] * T[j];
    rep(j,2)BM[j] = B[j] * T[j];
    ll dist[2];
    rep(j,2)dist[j] = BM[j] - AM[j];
    // 最初の移動を+に変換
    if(dist[0] < 0){
        dist[0] = -dist[0];
        dist[1] = -dist[1];
    }
    // 繰り返す
    if(dist[0] + dist[1] == 0){
        cout << "infinity" << endl;
        return 0;
    }
    // 最初+で、次も+なら、ずっと+
    if(dist[0] > 0 && dist[0] + dist[1] > 0){
        cout << 0 << endl;
        return 0;
    }
    // print(AM);
    // print(BM);
    // print(dist);
    ll c = dist[0], d = dist[1];
    ll ans = abs(d) / abs(c + d)*2-1;
    if(abs(d) % abs(c+d) == 0)ans -= 1;
    cout << ans << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;



int main(){
  string s,t;
  int ans=0;
  cin >>s >> t;
  rep(i,3){
    if(s[i]==t[i])ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 
string conv(int no,int n)
{
    string s;
    while(no!=0)
    {
        s+=((no%2)+'0');
        no/=2;
    }
    int l=s.length();
    if(l!=n)
    {
        for(int i=1;i<=n-l;++i)
            s+='0';
    }
    return s;
}
signed main()
{
    SPEED;
    int n,m,x,ans=1e18,i,j,k;
    cin>>n>>m>>x;
    vector<int> a[n+1];
    for(i=1;i<=n;++i)
    {
        for(j=0;j<m+1;++j)
        {
            int c;
            cin>>c;
            a[i].pb(c);
        }
    }
    for(i=1;i<powl(2,n);++i)
    {
        string s=conv(i,n);
        int sum[m+1]={0},cost=0,flag=0;
        for(int j=1;j<=n;++j)
        {
            if(s[j-1]=='1')
            {
                for(k=1;k<=m;++k)
                {
                    sum[k]+=a[j][k];
                }
                cost+=a[j][0];
            }
        }
        for(k=1;k<=m;++k)
        {
            if(sum[k]<x)
            {
                flag=1;
            }
        }
        if(flag==0)
            ans=min(ans,cost);
    }
    if(ans!=1e18)
        cout<<ans;
    else
        cout<<-1;
}

Measured memory_bytes: 3716
#include<cstdio>
#include<iostream>

using namespace std;
#define INF 99
	
int n, m, i, j, a, b, c, d, start, goal, money, hashira, minroot, tax[102][102] = {}, root[102] = {}, used[102] = {};

int main() {

	cin >> n >> m;
	//?????????
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) tax[i][j] = INF;
		tax[i][i] = 0;
		root[i] = INF;
		used[i] = 0;
	}
	//?????????????????¨?????\???
	for (i = 0; i < m; i++) {
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		tax[a][b] = c;
		tax[b][a] = d;
	}
	//????????????,??´??????,????????????????????????,??±????????¨
	scanf("%d,%d,%d,%d", &start, &goal, &money, &hashira);

	money -= hashira;
	//?????????????????????stert???goal
	root[start] = 0;
	while (1) {
		minroot = INF;
		for (i = 1; i <= n; i++) {
			if (used[i] == 0 && root[i] < minroot) {
				minroot = root[i];
				j = i;
			}
		}
		if (j == goal) {
			break;
		}
		else {
			used[j] = 1;
			for (i = 1; i <= n; i++) {
				if (root[j] + tax[j][i] < root[i]) root[i] = root[j] + tax[j][i];
			}
		}
	}
		//???????????´??°
		money -= root[goal];

		//?????????
		for (i = 1; i <= n; i++) {
			root[i] = INF;
			used[i] = 0;
		}
		//?????????????????????goal???start
		root[goal] = 0;
		while (1) {
			minroot = INF;
			for (i = 1; i <= n; i++) {
				if (used[i] == 0 && root[i] < minroot) {
					minroot = root[i];
					j = i;
				}
			}
			if (j == start) {
				break;
			}
			else {
				used[j] = 1;
				for (i = 1; i <= n; i++) {
					if (root[j] + tax[j][i] < root[i]) root[i] = root[j] + tax[j][i];
				}
			}
		}
			money -= root[start];
		
		cout << money << endl;
		return 0;
	
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,k,s;
    cin>>n>>k>>s;
    Vec a(n);

    rep(i,n){
        if(i<k){
            a[i] = s;
        }else{
            if(s<=1){
                a[i] = s+1;
            }else{
                a[i] = s-1;
            }
        }
    }
    rep(i,n){
        cout<<a[i]<<" ";
    }
    return  0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				String[] code=new String[n+1];
				for(int i=0; i<n; i++) {
					String str=sc.next();
					String s="";
					s+=String.valueOf(str.charAt(0));
					for(int j=0; j<str.length()-1; j++) {
						if(str.charAt(j)=='a'|| str.charAt(j)=='i'|| str.charAt(j)=='u'|| str.charAt(j)=='e'|| str.charAt(j)=='o') {
							s+=String.valueOf(str.charAt(j+1));
						}
					}
					code[i]=s;
				}
				int c=0;
				int ans=0;
				for(int k=0; k<50; k++) {
					c=0;
					for(int i=0; i<n; i++) {
						for(int j=i+1; j<n; j++) {
							String str1=code[i].substring(0, Math.min(k+1, code[i].length()));
							String str2=code[j].substring(0, Math.min(k+1, code[j].length()));
							if(str1.equals(str2)){
								c=1;
							}
						}
					}
					if(c==0) {
						ans=k+1;
						break;
					}
				}
				if(c>0) {
					System.out.println(-1);
				}
				else {
					System.out.println(ans);
				}
				
			}


		}
	}
}


Measured memory_bytes: 68380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
const int mod=1e9+7;
ll pow1(ll a,ll b)
{
	ll r=1;
	while(b)
	{
		if(b&1)
			r=r*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return r;
}
ll s[maxn],a[maxn];
ll work(int n)
{
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=a[i]*s[n-i+1]%mod;
		ans%=mod;
	}
	return ans;
}
int main()
{
	int n;scanf("%d",&n);
	ll fac=1;
	for(int i=1;i<=n;i++)
	{
		fac=fac*i%mod;
		scanf("%lld",&a[i]);
		s[i]=pow1(i,mod-2);
		s[i]=(s[i-1]+s[i])%mod;
	}
	ll ans=fac*work(n)%mod;
	reverse(a+1,a+n+1);
	ans+=fac*work(n);
	ans%=mod;
	for(int i=1;i<=n;i++)
		ans=(ans-a[i]*fac%mod+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/agc016_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

bool isSame(string s) {
  bool ret = true;
  rep(i, s.size() - 1) { ret &= s[i] == s[i + 1]; }
  return ret;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string s;
  cin >> s;

  set<char> se(s.begin(), s.end());
  int ans = 100;
  string org = s;
  for (auto c : se) {
    int cnt = 0;
    while (!isSame(s)) {
      cnt++;
      string sd = s.substr(0, s.size() - 1);
      rep(i, sd.size() - 1) {
        if (s[i] == c || s[i + 1] == c) {
          sd[i] = c;
        } else {
          sd[i] = s[i];
        }
      }
      s = sd;
    }
    ans = min(ans, cnt);
    s = org;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin


def input():
    return stdin.readline()[:-1]


def intput():
    return int(input())


def sinput():
    return input().split()


def intsput():
    return map(int, sinput())


n = intput()

s = input()

if n % 2 == 0 and s[:n // 2] == s[n // 2:]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	int n, i, p[22], ans=0;
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> p[i];
	for (i = 1; i < n - 1; i++) {
		if ((p[i] > p[i - 1] && p[i] < p[i + 1]) || (p[i]<p[i - 1] && p[i]>p[i + 1]))
			ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout << x << endl;
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

void doubling(vector<int> &a,vector<vector<ll>> &ret){
    int SZ=a.size();
    vector<int> next(1001001,-1);
    //ret[0][i]:=i-indexedの要素数
    rep(k,2){
        rep(i,SZ){
            if(next[a[i]]!=-1){
                ret[0][next[a[i]]%SZ]=k*SZ+i-next[a[i]]+1;
            }
            next[a[i]]=k*SZ+i;
        }
    }
    for(int k=0;k+1<60;k++){
        rep(i,SZ){
            ret[k+1][i]=ret[k][i]+ret[k][(ret[k][i]+i)%SZ];
        }
    }
}

signed main(){
    ll n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    vector<vector<ll>> res(60,vector<ll>(n));
    doubling(a,res);
    ll st=0,sum=0,lst=k*n;
    while(1){
        int idx=0;
        rep(k,60){
            if(res[k][st]+sum>=lst){
                idx=k-1;
                break;
            }
        }
        if(idx==-1){
            break;
        }
        sum+=res[idx][st];
        st=sum%n;
    }
    
    vector<bool> ok(n,1);
    vector<int> v(200200,-1);

    for(int i=st;i<n;i++){
        if(v[a[i]]!=-1){
            for(int j=v[a[i]];j<=i;j++){
                ok[j]=0;
                v[a[j]]=-1;
            }
        }else{
            v[a[i]]=i;
        }
    }
    for(int i=st;i<n;i++){
        if(ok[i]) cout << a[i]+1 << " ";
    }
    
}


Measured memory_bytes: 98788
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
H=gets.to_i
W=gets.to_i
puts (N-H+1)*(N-W+1)

Measured memory_bytes: 1788
a, b, c, k = map(int, input().split())

ans = 0

if a > k:
    ans += 1*k
    k = 0
else:
    ans += 1*a
    k -= a

if b > k:
    ans += 0*k
    k = 0
else:
    ans += 0*b
    k -= b

if c > k:
    ans += -1*k
    k = 0
else:
    ans += -1*c
    k -= c


print(ans)


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

int main(){
  int n,x,t;
  int c = 0;
  cin >> n >> x >> t;
  if (n % x == 0)
  c = n/x;
  else{
    c = n/x +1;
  }
  cout << c*t;
   
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

int main(){
    int Q;  cin >> Q;
    ll suma = 0, sumb = 0;
    priority_queue<ll> ql;
    priority_queue<ll, vector<ll>, greater<ll>> qr;
    ql.push(-1e18);
    qr.push(1e18);
    while(Q--){
        int q;  cin >> q;
        if(q==1){
            ll a, b;  cin >> a >> b;
            sumb += b;

            if(ql.size() == qr.size()){
                if(ql.top() <= a && a <= qr.top()){
                    suma += 0;
                }else{
                    suma += min(abs(ql.top() - a), abs(a - qr.top()));
                }
            }else{
                suma += abs(ql.top() - a);
            }

            if(qr.top() <= a){
                qr.push(a);
            }else{
                ql.push(a);
            }

            if(ql.size() == qr.size() + 2){
                qr.push(ql.top());
                ql.pop();
            }else if(ql.size() == qr.size() - 1){
                ql.push(qr.top());
                qr.pop();
            }
        }else{
            cout << ql.top() << " " << suma+sumb << endl;
        }
    }
}


Measured memory_bytes: 3828
a, b, c, x, y = map(int, input().split())
if a+b < 2*c:
    print(a*x + b*y)
else:
    if x > y:
        if a < 2*c:
            print(2*y*c + (x-y)*a)
        else:
            print(2*x*c)
    else:
        if b < 2*c:
            print(2*x*c + (y-x)*b)
        else:
            print(2*y*c)

Measured memory_bytes: 38384