akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

class Main{
		private static int my_pow(int a){
		return a*a;
		}
		private static int l_square(int size){
			int sum = 0,count=1;
			for(int i=size;i<=600-size;i=i+size){
				sum = sum+my_pow(count*size)*size;
				count++;
			}
			return sum;
		}
		
		public static void main(String args[]) throws IOException{
			ArrayList<Integer> inp = new ArrayList<Integer>();
			ArrayList<Integer> sq_size = new ArrayList<Integer>();
			ArrayList<Integer> res = new ArrayList<Integer>();
			
			Scanner scan = new Scanner(System.in);
			while(scan.hasNext()){
				String str1 = scan.next();
				inp.add(Integer.valueOf(str1).intValue());
			}

			for(int i=0;i<inp.size();i++){
				res.add(l_square(inp.get(i)));
			}
			for(int i=0;i<res.size();i++){
				System.out.println(res.get(i));
			}
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {

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

        char[][] c = new char[3][3];
        for (int i = 0; i < 3; i++) {
            String temp = sc.next();
            for (int j = 0; j < 3; j++) {
                c[i][j] = temp.charAt(j);
            }
        }
        for (int i = 0; i < 3; i++) {
            System.out.print(String.valueOf(c[i][i]));
        }
        System.out.println();

    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

    string S;
    cin >> S;

    int a = stoi(S.substr(0, 2));
    int b = stoi(S.substr(2, 2));

    bool a_can_mm = false;
    bool b_can_mm = false;

    if (a > 0 && a < 13) a_can_mm = true;
    if (b > 0 && b < 13) b_can_mm = true;

    string ans;
    if (a_can_mm && b_can_mm) ans = "AMBIGUOUS";
    else if (a_can_mm && !b_can_mm) ans = "MMYY";
    else if (!a_can_mm && b_can_mm) ans = "YYMM";
    else ans = "NA";

    cout << ans << endl;

    return 0;
}


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

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int n;
    long k;
    cin >> n >> k;
    vector<long> a(n);
    vector<long> f(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> f[i];
    
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    
    long l = -1;
    long r = 1000000000000ll;
    while (r > l + 1) {
        long m = (r + l) / 2;
        long s = 0;
        for (int i = 0; i < n; i++) {
            // a * f <= m
            // a <= m / f
            long aa = m / f[i];
            if (a[i] > aa) {
                s += a[i] - aa;
            }
        }
        if (s > k) {
            l = m;
        } else {
            r = m;
        }
    }
    cout << r;
    

    return 0;
}

Measured memory_bytes: 3328
import java.util.HashMap;
import java.util.Scanner;

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

                long N = scan.nextLong();

                HashMap<Long, String> alphabetHash = new HashMap<Long, String>();
                alphabetHash.put((long)0, "a");
                alphabetHash.put((long)1, "b");
                alphabetHash.put((long)2, "c");
                alphabetHash.put((long)3, "d");
                alphabetHash.put((long)4, "e");
                alphabetHash.put((long)5, "f");
                alphabetHash.put((long)6, "g");
                alphabetHash.put((long)7, "h");
                alphabetHash.put((long)8, "i");
                alphabetHash.put((long)9, "j");
                alphabetHash.put((long)10, "k");
                alphabetHash.put((long)11, "l");
                alphabetHash.put((long)12, "m");
                alphabetHash.put((long)13, "n");
                alphabetHash.put((long)14, "o");
                alphabetHash.put((long)15, "p");
                alphabetHash.put((long)16, "q");
                alphabetHash.put((long)17, "r");
                alphabetHash.put((long)18, "s");
                alphabetHash.put((long)19, "t");
                alphabetHash.put((long)20, "u");
                alphabetHash.put((long)21, "v");
                alphabetHash.put((long)22, "w");
                alphabetHash.put((long)23, "x");
                alphabetHash.put((long)24, "y");
                alphabetHash.put((long)25, "z");


                long len = 1;

                while (N - Math.pow(26, len) > 0) {
                	N -= Math.pow((long)26, len);
                	len++;
                }

                N--;

                while (len > 0) {
                	long temp = N/(long)Math.pow(26, len-1);
                	System.out.print(alphabetHash.get(temp));
                	N %= Math.pow(26, len-1);
                	len--;
                }

                System.out.println();

                scan.close();

        }

}

Measured memory_bytes: 35804
open Printf
open Scanf

let id x = x

let solve n =
  let ht = Hashtbl.create n in
  let rec f x =
    if x = 0 then ()
    else begin
        let s = scanf "%s " id in
        Hashtbl.replace ht s true;
        f (x - 1)
      end in
  f n;
  Hashtbl.length ht

let () =
  scanf "%d " solve |> printf "%d\n"


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

int main(){
 long long a,b,c,k;
 cin>>a>>b>>c>>k;
 long long ans=0;
long long temp=k;

    if(temp>=a){ans+=a;
    temp-=a;}
    else{
        ans+=temp;
        temp-=a;
    }
    if(temp>0){
        temp-=b;
    }
    if(temp>0){
        ans-=temp;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3624
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	n := readInt()
	println(n * (n + 1) / 2)
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int pop(void);
void push(int);
int isEmpty(void);
//int atoi( const char *str );

int top=0;
int S[100];

int main(){
  int x,y;
  char s[199];

  while(scanf("%s", s) != EOF){


    if ( s[0] == '+' ){
      x = pop();
      y = pop();
      push(x+y);
    } else if ( s[0] == '-' ){
      x = pop();
      y = pop();
      push(y-x);
    } else if ( s[0] == '*' ){
      x = pop();
      y = pop();
      push(x*y);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",pop());

  return 0;
}

int pop(){
  top--;
  return S[top+1];
}

void push(int x){
  top++;
  S[top] = x;
}

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

typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    
    ll dif=(b-a)+1;
    
    ll c1=b/c-a/c;
    if(a%c==0) c1++;
    
    ll d1=b/d-a/d;
    if(a%d==0) d1++;
    
    ll lcm=c/__gcd(c,d);
    lcm*=d;
    
    ll lcm1=b/lcm-a/lcm;
    if(a%lcm==0) lcm1++;
    
    ll tot=dif-c1-d1+lcm1;
    
    cout<<tot;
    
    return 0;

}

Measured memory_bytes: 256
num = gets.to_i
array = []
line = "####################"
resident = Array.new(4){|i| Array.new(3){|i| Array.new(10, 0)}}

def calc_num(info, resident)
  # puts info
  resident[info[:building] - 1][info[:floor] - 1][info[:room] - 1] += info[:v]
  return resident
end

def describe(building)
  output = ""
  for i in 0..building.length - 1 do
    for j in 0..building[i].length - 1 do
      output += " "
      output += building[i][j].to_s
    end
    output += "\n"
  end
  puts output
end

for i in 1..num do
  input = gets.chomp
  info = input.split(" ")
  info2 = {building:(info[0].to_i), floor:(info[1].to_i), room:(info[2].to_i), v:(info[3].to_i)}
  array << info2
end

# puts line

for j in 0..array.length - 1 do
  info = array[j]
  resident = calc_num(info, resident)
end

# puts line

for i in 0..resident.length - 1 do
  describe(resident[i])
  if i != resident.length - 1 then
    puts line
  end
end

Measured memory_bytes: 6124
def gcd(a, b):
    """calculate the greatest common divisor of a, b

    >>> gcd(54, 20)
    2
    >>> gcd(147, 105)
    21
    >>> gcd(100000002, 39273000)
    114
    """
    if a > b:
        a, b = b, a

    if a == 0:
        return b

    return gcd(b % a, a)


def run():
    a, b = [int(i) for i in input().split()]
    print(gcd(a, b))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
long long one=0,two=0,onetwo=0,n,m,x,y,a,b,c,d,e,f,xy;
bool ok=false;
int main()
{
	cin >>n>>m>>x>>y;
	if(n%x)
	ok=true;
//	cout <<ok<<endl;
	a=n-n%x+(int)ok*x;
	b=m-m%x;
	one=(b-a)/x+1;
	ok=false;
	if(n%y)
	ok=true;
//	cout <<ok<<endl;
	c=n-n%y+(int)ok*y;
	d=m-m%y;
	two=(d-c)/y+1;
	ok=false;
	xy=x*y/__gcd(x,y);
	if(n%xy)
	ok=true;
//	cout <<ok<<endl;
	e=n-n%xy+(int)ok*xy;
	f=m-m%xy;
	onetwo=(f-e)/xy+1;
//	cout <<xy<<" "<<one<<" "<<two<<" "<<onetwo<<endl;
	cout <<m-n+1-one-two+onetwo<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;

ll Combination(int n, int r){
        ll num = 1;
        for(int i = 1; i <= r; i++){
            num = num * (n - i + 1) / i;
        }
        return num;
    }
int main()
{
    int n,p;
    cin>>n>>p;
    vector<int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    int oddcount=0;
    rep(i,n)
    {
        if(a[i]%2==1)
        {
            oddcount++;
        }
    }
    ll oddc=0;
    ll nc=0;
    if(p==0)
    {
        
        int oddnum=0;
        while(oddnum<=oddcount)
        {
            oddc+=Combination(oddcount,oddnum);
            oddnum+=2;
        }
        
    }
    else
    {
        int oddnum=1;
        while(oddnum<=oddcount)
        {
            oddc+=Combination(oddcount,oddnum);
            oddnum+=2;
        }
        
    }
    if((n-oddcount)%2==1)
        {
            for(int i=0;i<=(n-oddcount)/2;i++)
            {
                nc+=Combination(n-oddcount,i);
            }
            nc*=2;
        }
        else
        {
            for(int i=0;i<(n-oddcount)/2;i++)
            {
                nc+=Combination(n-oddcount,i);
            }
            nc*=2;
            nc+=Combination(n-oddcount,(n-oddcount)/2);
        }

    cout<<nc*oddc<<endl;
    
}

Measured memory_bytes: 384
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,0,n)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;
const int _N = 2e5;

int n,m;

int sub[1<<26];
int dp[_N];
int state[_N];
int cnt[26];

int main() {
	string s;
	cin >> s;
	n = s.size();
	REP(i,n){
		cnt[s[i]%26]++;
		REP(j,26)
			if(cnt[j]%2)
				state[i]|=1<<j;
	}
	REP(i, 1<<26){
		sub[i]=INF;
	}
	dp[0]=1;
	sub[state[0]] = dp[0];
	sub[0] = 0;

	FOR(i, 1, n){
		dp[i] = INF;
		dp[i] = min(dp[i], sub[state[i]]+1);
		REP(j,26){
			dp[i] = min(dp[i], sub[state[i]^(1<<j)]+1);
		}
		sub[state[i]] = min(sub[state[i]], dp[i]);
	}

	cout << dp[n-1] << endl;
}


Measured memory_bytes: 264324
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long

int main(void){
  ll a;
  string s;
  cin>>a>>s;
  ll ini='A'-0;
  rep(i,s.size()){
  	s[i]=(s[i]-ini+a)%26+ini;
  }
  cout<<s;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <string>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

string M[51];
int x[4] = { -1,0,1,0 };
int y[4] = { 0,1,0,-1 };

int main()
{
	int H, W;
	cin >> H >> W;
	REP(i, H)
	{
		cin >> M[i];
	}

	REP(h, H)
	{
		REP(w, W)
		{
			if (M[h][w] == '.')
			{
				continue;
			}
			REP(i, 4)
			{
				int cx = w + x[i], cy = h + y[i];
				if (cx < 0 || cy < 0 || cx >= W || cy >= H)
				{
					continue;
				}
				if (M[cy][cx] == '#')
				{
					break;
				}
				if (i == 3)
				{
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int a[200005];
int dis[200005];

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a[i];
	}
	int cnt=0;
	dis[0]=a[0];
	cnt+=a[0];
	for(int i=1;i<m;i++)
	{
		dis[i]=a[i]-a[i-1];
		
		cnt+=dis[i];
	}
	dis[m]=n-a[m-1];
	cnt+=dis[m];
	sort(dis,dis+m+1);
	int ans=1e9;
//	cout<<cnt<<endl;
	for(int i=1;i<m+1;i++)
	{
		ans=min(ans,cnt-dis[i]);
	}
	ans=min(ans,a[m-1]-a[0]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int n; cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    ll w = 0, h = 0;
    rep(i, n-1) {
        if(a[i] == a[i+1]) {
            w = h;
            h = a[i];
            i++;
        }
    }
    cout << (w * h) << endl;
    return 0;
}


Measured memory_bytes: 1024
n, m = (int(x) for x in input().split())
x = [int(x) for x in input().split()]
if n >= m:
    print(0)
else:
    x.sort()
    dis = [abs(x[i+1] - x[i]) for i in range(m-1)]
    dis.sort()
    ans = dis[::-1]
    for _ in range(n-1): ans.pop(0)
    print(sum(ans))

Measured memory_bytes: 13840
#include<iostream>
#include<algorithm>

using namespace std;

int const N = 2e3 + 41;
int const MOD = 924844033;

int n, k, cnt[N], sz, dp[N + 5][N + 5][4], f[N];

void calcF(){
	f[0] = 1;
	for(int i=1;i<N;++i){
		f[i] = f[i-1] * 1LL * i % MOD;
	}
}

void prepare(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}

void calcCnt(){
	for(int i=0;i<k;++i){
		for(int j=i;j<n;j+=k){
			++cnt[i];
		}
	}
}

void add(int &a, int b){
	a += b;
	if(a >= MOD){
		a -= MOD;
	}
}

int sum(int a, int b){
	return (a+b) % MOD;
}

int getSum(int p, int t){
	long long ret = 0;
	for(int i=0;i<4;++i){
		ret += dp[p][t][i];
	}
	return ret % MOD;
}

void calcDp(){
	dp[0][0][0] = 1;
	for(int i=0;i<k;++i){
		for(int j=1;j<=cnt[i];++j){
			++sz;
			for(int t=0;t<N;++t){
				if(j == 1){
					add(dp[sz][t][0], getSum(sz-1, t));
				}else{
					//0
					int v0 = getSum(sz-1, t);
					add(dp[sz][t][0], v0);
					//1
					int v1 = sum(dp[sz-1][t][0], dp[sz-1][t][1]);
					add(dp[sz][t+1][1], v1);
					//2
					int v2 = sum(dp[sz-1][t][0], dp[sz-1][t][2]);
					add(dp[sz][t+1][2], v2);
					//3
					int v3 = dp[sz-1][t][0];
					add(dp[sz][t+2][3], v3);
				}
			}
		}
	}
}

void read(){
	scanf("%d%d",&n,&k);
}

int main(){
	prepare();
	read();
	calcF();
	calcCnt();
	calcDp();
	int ans = 0;
	for(int i=0;i<=n;++i){
		long long sign = (i&1 ? -1 : 1);
		ans += getSum(n, i) * sign * f[n-i] % MOD;
		ans %= MOD;
	}
	if(ans < 0){
		ans += MOD;
	}
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 64256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 1e6 + 5, S = 1e3 + 5;

int n, nodes;
int order[S][S];
int idx[S][S];
vector<int> g[N];
int in[N];

int get_idx(int a, int b)
{
  if(a > b)
    swap(a, b);
  return idx[a][b];
}

void add_edge(int f, int t)
{
  in[t]++;
  g[f].pb(t);
}

void topo_sort()
{
  queue<int> q;
  int levels = 0, vis = 0;
  for(int i = 0 ; i < nodes ; i++)
    if(!in[i])
      q.push(i);
  while(!q.empty()){
    int s = q.size();
    levels++;
    while(s--){
      int u = q.front();
      q.pop();
      vis++;
      for(int i = 0 ; i < sz(g[u]) ; i++){
        int v = g[u][i];
        if(!--in[v]){
          q.push(v);
        }
      }
    }
  }
  if(vis < nodes)
    cout << -1 << endl;
  else
    cout << levels << endl;
}

int main()
{
  scanf("%d", &n);
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n - 1 ; j++){
      int k;
      scanf("%d", &k);
      order[i][j] = --k;
    }
  }
  nodes = 0;
  for(int i = 0 ; i < n ; i++){
    for(int j = i + 1 ; j < n ; j++)
      idx[i][j] = nodes++;
  }
  for(int i = 0 ; i < n ; i++){
    for(int j = 1 ; j < n - 1 ; j++){
      add_edge(get_idx(i, order[i][j - 1]), get_idx(i, order[i][j]));
    }
  }
  topo_sort();
  return 0;
}


Measured memory_bytes: 50944
#include <bits/stdc++.h>
#define ll long long

const int mxn = 1e5+1;

using namespace std;

vector < int> adj[mxn+1], visited(mxn+1, 0), dist(mxn+1, 0);

void dfs(int u){
    if(visited[u])
        return;
    visited[u] = 1;
    for(int v: adj[u]){
        if(!visited[v])
            dfs(v);
        dist[u] = max(dist[u], dist[v]+1);
    }
}

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

    int n, m;
    cin>>n>>m;
    for(int i=0; i<m; i++){
        int x, y;
        cin>>x>>y;
        adj[x].push_back(y);
    }
    for(int i=1; i<=n; i++){
        if(!visited[i])
            dfs(i);
    }
    
    int ans = *max_element(dist.begin()+1, dist.end());
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	int a[n];
	map<int, int>mt;
	int sum = 0;
	zip(i, 0, n)
	{
		cin >> a[i];
		sum += a[i];
		mt[a[i]]++;;
	}
	int q;
	cin >> q;
	int ans = 0;
	while (q--)
	{
		int x, y;
		cin >> x >> y;
		int var = mt[x];
		sum -= mt[x] * x;
		sum += mt[x] * y;
		mt[x] -= var;
		mt[y] += var;
		cout << sum << en;
		//mt[x]=y;
	}
	//
	// zip(i,0,n)
	// {
	// 	ans+=mt[a[i]];
	// }
	// cout<<ans<<en;

	return 0;
}



Measured memory_bytes: 10260
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

vector<pint> v[1010];
ll dist[1010];
int used[1010];

void bfs(){
  queue<int> q;
  q.push(0);
  dist[0]=0;
  while(q.size()){
    int x=q.front();q.pop();
    if(used[x]>=3000)continue;
    for(auto e:v[x]){
      if(dist[e.first]>dist[x]+e.second){
        dist[e.first]=dist[x]+e.second;
        used[e.first]++;
        q.push(e.first);
        }
      }
    }
  }

int main(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    v[a-1].push_back({b-1,-c});
    }
  rep(i,n)dist[i]=longinf;
  bfs();
  if(used[n-1]>1000)cout<<"inf"<<endl;
  else cout<<-dist[n-1]<<endl;
  return 0;
  }


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

int main() {
  int N;
  cin >> N;
  
  int ns[N];
  for (int i = 0; i < N; i++) {
    cin >> ns[i];
  }
  
  int c = 0;
  while (true) {
    bool all_even = true;
    for (int i = 0; i < N; i++) {
      all_even = (ns[i] % 2 == 0);
      if (!all_even) break;
    }
    if (all_even) {
      for (int i = 0; i < N; i++) {
        ns[i] /= 2;
      }      
      c++;
    } else {
      break;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl            '\n'
#define mem(a, n)       memset(a, n, sizeof(a))
#define repeat(n)       for(int i=0; i<n; i++)
#define Unique(n)       (n).erase(unique(all(n)), (n).end())
#define isPowerOfTwo(n) (n && !(n & (n - 1)))
#define NumofDigits(n)  ((int)log10(n)+1)
#define all(a)          a.begin(), a.end()

long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a*b/gcd(a, b); }

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }

/*
    Special functions:
        find_by_order(k) --> returns iterator to the kth largest element counting from 0
        order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

int main(){
    quicken();

    int a, b, c; cin >> a >> b >> c;
    if(b<a) swap(a, b);

    if(c>=a && c<=b) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

A = list(map(int, input().split()))
A.sort()

ans = (A[2]-A[1]) + (A[1]-A[0])//2 + ((A[1]-A[0])%2)*2
print(ans)

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

int main() {
  int k, x;
  cin >> k >> x;
  if(x <= k*500) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a,b;
	cin>>a>>b;
	ll g = __gcd(a,b);
	ll ans=0;
	for(ll i=2;i*i<=g;i++)
	{
		if ((g%i)==0)
			ans++;
		while((g%i)==0)
		{
			g=g/i;
		}
	}
	if (g>1)
		ans++;
	cout<<ans+1;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vs = vector<string>;
using ii = vector<vector<long long>>;
int main() {
    string a;
    cin >> a;
    ll count = 0;
    ll asas = 0;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] == 'W') {
            asas += i - count;
            count++;
        }
    }
    cout << asas << endl;
}

Measured memory_bytes: 3752
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums := make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}

	a := nums[0]
	b := nums[1]

	if b > a {
		fmt.Println(0)
	} else if b*2 > a {
		fmt.Println(0)
	} else {
		fmt.Println(a - 2*b)
	}

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int INF = 100100100;

int c[10][1005];

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  int ans = INF;
  rep(div, 1 << (h-1)) {
    int g = 0;
    vector<int> id(h);
    rep(i, h) {
      id[i] = g;
      if (div>>i&1) ++g;
    }
    ++g;
    rep(i, g)rep(j, w) c[i][j] = 0;
    rep(i, h)rep(j, w) c[id[i]][j] += (s[i][j] - '0');
    bool ok = true;
    rep(i, g)rep(j, w) if(c[i][j] > k) ok = false;
    if(!ok) continue;
    
    int num = g-1;
    vector<int> now(g);
    auto add = [&](int j){
      rep(i, g) now[i] += c[i][j];
      rep(i, g) if(now[i] > k) return false;
      return true;
    };
    rep(j, w){
      if(!add(j)){
        num++;
        now = vector<int>(g);
        add(j);
      }
    }
    ans = min(ans, num);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9, mod = 1e9 + 7;
const long long OO = 1e18+25;

int n, k,a[N],mem[N];

int dp(int idx=0)
{
    if(idx == n-1) return 0;
    int &ret = mem[idx];
    if(ret != oo) return ret;
    for(int i=1; i<=k && idx+i < n; i++)
        ret = min(ret, dp(idx+i)+abs(a[idx]-a[idx+i]));
    return ret;
}

int main()
{
    fill(mem, mem+N, oo);
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++) scanf("%d",a+i);
    a[n+1] = oo;
    a[n] = a[n-1];
    printf("%d",dp());
    return 0;
}
	     		 					   	 	 								 	

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout<<setprecision(12)<<fixed;
	ll n;cin>>n;
	double ans = 0.5;
	if(n%2==0){
		cout<<ans<<endl;
		return 0;
	}else{
		ans = (n/2+1.0)/(n);
		cout<<ans<<endl;
	}































	
}

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

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

    double tax = 1.08;

    int hint = N / tax; 

    for ( int i = hint-2; i <= hint +3; i++){
        int price = i * tax;
        if ( N == price ){
            cout << i << endl;
            return 0;
        }
    }

    cout<< ":(" <<endl;
    return 0;
}



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

int n, ans = 0;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        ans = __gcd(ans, x);
    }
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
  int n;
  cin >> n;
  int p[n];
  int ans=0,MAX=0;
  rep(i,n){
    cin >> p[i];
    ans+=p[i];
    MAX=max(MAX,p[i]);
  }
  cout << ans-MAX/2 << endl;
  return 0;
}

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

using namespace std;
typedef unsigned long long ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    ll A1 = t1 * a1;
    ll A12 = A1 + t2 * a2;
    ll B1 = t1 * b1;
    ll B12 = B1 + t2 * b2;

    //無限に続く
    if(A12 == B12){
        cout << "infinity" << endl;
        return 0;
    }

    if(A12 < B12){
        swap(A12, B12);
        swap(A1, B1);
    }

    ll ans = 0;
    if(A1 > B1){
        //永遠に交わらない
        cout << "0" << endl;
    }else if(A1 < B1){
        //交わるところが出てくる
        if((B1-A1) % (A12-B12) != 0){
            ans = (B1-A1) / (A12-B12)  * 2 + 1;
        }else{
            ans = (B1-A1) / (A12-B12) * 2;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
from collections import Counter

N, A = map(int, input().split(" "))
X = list(map(int, input().split(" ")))

X = [x-A for x in X]

c = Counter([0])
for x in X:
    d = Counter()
    for k, v in c.items():
        d[k+x] += v
    c += d

print(c[0]-1)

Measured memory_bytes: 3572
#include<iostream>
#include<functional>
#include<vector>
#include<queue>

using namespace std;

#define MMAX 100
#define INF 10000000

typedef pair<int,int> PII;

struct side{
	int dir,wei[2];
};

int main(void){

	int n,m;
	int a,b,cost,time;
	int k;
	int p,q,r;
	int es;
	int nod[MMAX+1];
	vector<side> ed[MMAX+1];
	priority_queue<PII,vector<PII>,greater<PII> > pq;
	side tmp;
	PII pii;
	int nm;

	while(1){

		for(int i=0;i<=MMAX;i++) nod[i]=0;
		for(int i=0;i<=MMAX;i++){
			if(!ed[i].empty()) ed[i].clear();
		}
		while(!pq.empty()) pq.pop();

		cin>>n>>m;
		if(n==0&&m==0) break;

		for(int i=0;i<n;i++){
			cin>>a>>b>>cost>>time;
			tmp.dir=b,tmp.wei[0]=cost,tmp.wei[1]=time;
			ed[a].push_back(tmp);
			tmp.dir=a;
			ed[b].push_back(tmp);
		}

		cin>>k;

		for(int i=0;i<k;i++){

			cin>>p>>q>>r;
			for(int j=0;j<=m;j++) nod[j]=INF;
			nod[p]=0;
			pq.push(PII(0,p));

			while(!pq.empty()){
				pii=pq.top();
				pq.pop();
				nm=pii.second;
				if(nod[nm]<pii.first) continue;
				es=ed[nm].size();
				for(int j=0;j<es;j++){
					tmp=ed[nm][j];
					if(nod[tmp.dir]>nod[nm]+tmp.wei[r]){
						nod[tmp.dir]=nod[nm]+tmp.wei[r];
						pq.push(PII(nod[tmp.dir],tmp.dir));
					}
				}
			}
			cout<<nod[q]<<endl;

		}

	}

}

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

int i,n,x,y;
int a[200007],b[200007];
vector<int> edge[200007];

void DFS1(int pos, int par, int dep) {
    a[pos] = dep;
    
    for (int i = 0; i < edge[pos].size(); i++) if (edge[pos][i] != par) {
        DFS1(edge[pos][i],pos,dep+1);
    }
}

void DFS2(int pos, int par, int dep) {
    b[pos] = dep;
    
    for (int i = 0; i < edge[pos].size(); i++) if (edge[pos][i] != par) {
        DFS2(edge[pos][i],pos,dep+1);
    }
}

int main() {
    scanf("%d",&n);
    for (i=0 ; i<n-1 ; i++) {
        scanf("%d%d",&x,&y);
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    
    DFS1(1,-1,0);
    DFS2(n,-1,0);
    
    x = 0;
    y = 0;
    for (i=1 ; i<=n ; i++) {
        //printf("%d %d\n",a[i],b[i]);
        if (a[i] <= b[i]) x++; else y++;
    }
    
    //printf("%d %d\n",x,y);
    if (x > y) printf("Fennec\n"); else printf("Snuke\n");
}

Measured memory_bytes: 15744
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <climits>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    long long int x,c=0;
    cin >> x;
    c = (x/11)*2;
    if(x-c/2*11>6){
        c+=2;
    }else if(x-c/2*11>0){
        c++;
    }
    cout << c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

vector<ll> fact, invfact;
ll modpower(ll x, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n&1)res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll n){
    return modpower(n,MOD-2,MOD);
}
void COMinit(ll k){ //空っぽの配列を二つ
   k++;
   fact.resize(k, 0);
   invfact.resize(k, 0);
   fact[0] = 1;
   repi(i, k, 1)
   {
       fact[i] = fact[i - 1] * i % MOD;
   }
   invfact[k - 1] = inv(fact[k - 1]);
   repd(i, k - 2, 0)
   {
       invfact[i] = invfact[i + 1] * (i + 1) % MOD;
   }
   return;
}
ll nCk(vector<ll> &fact,vector<ll> &invfact,ll n, ll k){ //この関数を使う前にCOMinit
   if (k < 0 || n < k)
       return 0LL;
   return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}
ll com(ll n, ll k)
{
    ll iv = 1;
    ll fa = 1;
    repi(i, k, 0)
    {
        fa *= (n - i);
        fa %= MOD;
    }
    repi(i, k + 1, 1)
    {
        iv *= inv(i);
        iv %= MOD;
    }
    return fa * iv % MOD;
}

//---------main function----------

int main()
{
    int x,n;
    cin >> x >> n;
    int p[n];
    repi(i,n,0){
        cin >> p[i];
    }
    ll a = INF,ans = INF;
    repi(i,200,-100){
        bool ok = false;
        repi(j,n,0){
            if(i == p[j]){
                ok = true;
                break;
            }
        }
        if(ok)continue;
        if(abs(x-i) < a){
            a = abs(x-i);
            ans = i;
            // cout << i << " " << abs(x-i) << endl;
        }else if(abs(x-i) == a){
            ans = min(ans,i);
        }
    }
    cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3596
use std::io::Read;
use std::cmp;

fn main() {
    let mut b = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_line(&mut b).expect("failed");

    let s = b.trim();
    match s {
        "A" => println!("T"),
        "T" => println!("A"),
        "C" => println!("G"),
        "G" => println!("C"),
        _ => println!("_"),
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int zpr(){
	string s;
	cin>>s;
	if(s=="Vacant"){
		return -1;
	}
	if(s=="Male"){
		return 1;
	}
	if(s=="Female"){
		return 0;
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	int n;
	int a[200000];
	cin>>n;
	cout<<"0"<<endl;
	a[0]=zpr();
	if(a[0]==-1){
		return 0;
	}
	a[n]=a[0];
	int k=n/2;
	cout<<k<<endl;
	a[k]=zpr();
	if(a[k]==-1){
		return 0;
	}
	int max=n;
	int min=0;
	int midl=k;
	while(a[midl]!=-1){
		if((max+a[max]-midl-a[midl]+2)%2!=0){
			min=midl;
			midl=(midl+max)/2;
			cout<<midl<<endl;
			a[midl]=zpr();
			if(a[midl]==-1){
				return 0;
			}
		}
		else{
			max=midl;
			midl=(midl+min)/2;
			cout<<midl<<endl;
			a[midl]=zpr();
			if(a[midl]==-1){
				return 0;
			}
		}
	}
	return 0;
}

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

int main() {
	int n;
	std::cin >> n;
	int d[n];
	for (int i = 0; i < n; i++) {
	    std::cin >> d[i];
	}
	sort(d,d+n);
	
	std::cout << d[n/2] - d[n/2 - 1] << std::endl;
	
	return 0;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <queue>
#include <unordered_map> 
#include <iomanip>
#include <random>
#include <future>
#include <thread>
#include <utility>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
#define PN 1000000007
typedef long long LL;
//#define int long long


//booooooooooooost
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int), 多倍長小数(mp::cpp_dec_float_100)



LL inv_mod(LL a, LL m)
{
	LL b, x, u, q, tmp;

	b = m; x = 1; u = 0;
	while (b > 0) {
		q = a / b;
		tmp = u; u = x - q * u; x = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}

	return (x < 0) ? m + x : x;
}



signed main() {

	int N, M;
	vector<pair<int, int>> ab;

	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		ab.push_back(pair<int, int>(a, b));
	}

	vector<int>ans;
	ans.assign(N, 0);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			if (ab[j].first == i + 1 || ab[j].second == i + 1) ++ans[i];
		}
		
	}

	for (int i = 0; i < N; ++i) {
		cout << ans[i] << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
 
typedef pair<string,string> pss;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
 
 
int find_cent(string s){
    int count = 0;
    for(int i=0; i< s.size(); i++){
        if(s[i] == '(') count++;
        else if(s[i] == ')') count--;
        
        if(count==0) return i;
    }
    return -1;
}
 
pss dfs(string a, string b){
    if(a.size()==0||b.size()==0)return pss("","");
    
    string ret = "";
    string a_l="",a_r="",b_l="",b_r="";
    
    int a_cent, b_cent;
    
    a_cent = find_cent(a);  //get ) pos
    b_cent = find_cent(b);  //get ) pos
    
    a_l = a.substr(1, a_cent-1);
    b_l = b.substr(1, b_cent-1);
    
    int a_n = 0;
    while(a[a_cent] != ']'){
        if('0' <= a[a_cent] && a[a_cent] <= '9'){ a_n *= 10; a_n += (int)a[a_cent] - '0';}
        a_cent++;
    }
    
    a_r = a.substr(a_cent+2, a.size()-a_cent-3); //?
    
    a_cent = a_n;
    
    
    int b_n = 0;
    while(b[b_cent] != ']'){
        if('0' <= b[b_cent] && b[b_cent] <= '9'){ b_n *= 10; b_n += (int)b[b_cent] - '0';}
        b_cent++;
    }
    
    b_r = b.substr(b_cent+2, b.size()-b_cent-3);
    
    b_cent = b_n;
    
    
//    cout << a_l << " [ " << a_cent << " ] "<< a_r << endl;
//    cout << b_l << " [ " << b_cent << " ] "<< b_r << endl;
    
    pss res_l = dfs(a_l,b_l);
    pss res_r = dfs(a_r,b_r);
    
    string res_a = '('+res_l.first + ")["+to_string(a_cent)+"](" + res_r.first+')';
    string res_b = '('+res_l.second + ")["+to_string(b_cent)+"](" + res_r.second+')';
 
    return pss(res_a,res_b);
}
 
int main(){
    string a, b;
    cin >> a >> b;
    pss res = dfs(a, b);
    
    a = res.first;
    b=res.second;
    
    vector<int> numa,numb;
    
    for(int i=0;i<a.size();i++){
        if(a[i]!='[')continue;
        string tmp="";
        for(int j=i+1;;j++){
            if(a[j]!=']')tmp+=a[j];
            else {i=j;break;} //?
        }
        numa.pb(stoi(tmp));
    }
    
    for(int i=0;i<b.size();i++){
        if(b[i]!='[')continue;
        string tmp="";
        for(int j=i+1;;j++){
            if(b[j]!=']')tmp+=b[j];
            else {i=j;break;} //?
        }
        numb.pb(stoi(tmp));
    }
    
    rep(i,numa.size()){
        numa[i]+=numb[i];
    }
    
    
    int cou=0;
    rep(i,a.size()){
        if(a[i]<'0'||'9'<a[i]){
            cout<<a[i];
        }
        if(a[i]=='['){
            cout<<numa[cou];
            cou++;
            while(a[i+1]!=']')i++;
 
        }
    }
    cout<<endl;
}

Measured memory_bytes: 3424
#include <cstdio>
#include <cstring>
char s[1000011];int n,k;const int p=1e9+7;
inline int qpow(int bs,int ex){int ans=1;while(ex){if(ex&1)ans=1ll*ans*bs%p;bs=1ll*bs*bs%p;ex>>=1;}return ans;}
int fac[2000001],ifac[2000001];
int main()
{
	scanf("%d%s",&k,s+1);n=strlen(s+1);int ans=0;
	fac[0]=1;for(int i=1;i<=2e6;++i)fac[i]=1ll*fac[i-1]*i%p;
	ifac[2000000]=qpow(fac[2000000],p-2);for(int i=2e6-1;i>=0;--i)ifac[i]=1ll*ifac[i+1]*(i+1)%p;
	for(int i=0;i<=k;++i)(ans+=1ll*fac[n+k-i-1]*ifac[n-1]%p*ifac[k-i]%p*qpow(26,i)%p*qpow(25,k-i)%p)%=p;printf("%d\n",ans);return 0;
}

Measured memory_bytes: 18304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  vector<int> ans;
  while(vec.size() > 0){
    bool change = false;
    for(int i=vec.size()-1; i>=0; i--){
      if(vec.at(i) == i+1){
        ans.push_back(i+1);
        vec.erase(vec.begin()+i);
        change = true;
        break;
      }
    }
    if(change == false){
      break;
    }
  }
  if(ans.size() == N){
    for(int i=N-1; i>=0; i--){
      cout << ans.at(i) << endl;
    }
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 256
def Calculate_RPN(L):
    St = []
    for i in L:
        if i == '+':
            b, a = float(St.pop()), float(St.pop())
            St.append(a+b)
        elif i == '-':
            b, a = float(St.pop()), float(St.pop())
            St.append(a-b)
        elif i == '*':
            b, a = float(St.pop()), float(St.pop())
            St.append(a*b)
        elif i == '/':
            b, a = float(St.pop()), float(St.pop())
            St.append(a/b)
        else:
            St.append(i)

    return St[0]


while True:
    try:
        s = raw_input().split()

    except EOFError:
        break

    print Calculate_RPN(s)

Measured memory_bytes: 6428
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int MAXN = 1400 + 10;

int row, column;
int maze[MAXN][MAXN], pre[MAXN][MAXN], dp[MAXN][MAXN];
int ans;

bool isVaild(int r0, int c0, int r1, int c1){
	return !(pre[r1][c1] - pre[r0 - 1][c1] - pre[r1][c0 - 1] + pre[r0 - 1][c0 - 1]);
}

int main(void)
{
	scanf("%d%d", &row, &column);
	for(int r = 1; r <= row; r++)	for(int c = 1; c <= column; c++)
		scanf("%d", &maze[r][c]), pre[r][c] = pre[r][c - 1] + pre[r - 1][c] + maze[r][c] - pre[r - 1][c - 1];
	for(int r = 1; r <= row; r++)	for(int c = 1; c <= column; c++)	for(int i = sqrt(ans); i < min(r, c); i++){
		if(!isVaild(r - i, c - i, r, c))	break;
		ans = max(ans, dp[r][c] = (i + 1) * (i + 1));
		//printf("dp[%d][%d] = %d\n", r, c, dp[r][c]);
	}printf("%d\n", ans);
	return 0;
} 


Measured memory_bytes: 20404
def f(n):
    if n %2 == 0:return n//2
    else: return 3*n+1
s = int(input())
nums = [s] + [0]*10**6
for i in range(1000000):
    if f(nums[i]) in nums:
        print(i+2)
        break
    else:
        nums[i+1] = f(nums[i])

    

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

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

  int N;
  cin >> N;
  int A[9] = {};
  rep(i, N){
    int a;
    cin >> a;
    a /= 400;
    if(a >= 8) a = 8;
    A[a]++;
  }
  int minans = 0, maxans = 0;
  rep(i, 8){
    if(A[i] > 0){
      maxans++;
      minans++;
    }
  }
  if(minans == 0) minans++;
  cout << minans << ' ' << maxans + A[8] << endl;
}

Measured memory_bytes: 256