akhauriyash/Code-Regression huggingface dataset:
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var n=arr.shift()-0;
arr.forEach(v=>{
   var sente=v.split(" ").map(Number);
   var gote=[];
   for(var i=1;i<=13;i++)gote.push(i);
   gote=gote.filter(x=> !(x==7 || sente.includes(x)));
   var saiki=function(a,b,min,max,sg){
      if(a.length==0)return true;
      else if(b.length==0)return false;
      if(sg==0){
         var cnt=0;
         if(a.includes(min)){
            if(saiki(a.filter(v=> v!=min),b,min-1,max,1))cnt++;
         }
         if(a.includes(max)){
            if(saiki(a.filter(v=> v!=max),b,min,max+1,1))cnt++;
         }
         if(!a.includes(min) && !a.includes(max)){
            if(saiki(a,b,min,max,1))cnt++;
         }
         if(cnt==0)return false;
         else return true;
      }else if(sg==1){
         var cnt=0;
         if(b.includes(min)){
            if(!saiki(a,b.filter(v=> v!=min),min-1,max,0)) cnt++;
          }  
         if(b.includes(max)){
            if(!saiki(a,b.filter(v=> v!=max),min,max+1,0)) cnt++;
         }
         if(!b.includes(min) && !b.includes(max)){
            if(!saiki(a,b,min,max,0))cnt++;
         }
         if(cnt==0)return true;
         else return false;
      }
   };
   
   var flag = saiki(sente,gote,6,8,0,0);
   console.log(flag?"yes":"no");
});


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

int main(){
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  a.push_back(a[0]+k);
  int l = 0;
  rep(i,n)l = max(l, a[i+1]-a[i]);
  int ans = k-l;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4828
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[n*2];
        for (int i = 0; i < n*2; i++) {
            l[i] = sc.nextInt();
        }
        Arrays.sort(l);
        int ans = 0;
        for (int i = 0; i < n*2; i+=2) {
            ans += l[i];
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 21332
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        ArrayList<SimpleEntry<Integer, Integer>> list = new ArrayList<SimpleEntry<Integer, Integer>>();
        for(int i=0;i<N;i++){
            list.add(new SimpleEntry<Integer, Integer>(i+1, sc.nextInt()));
        }
        Collections.sort(list,Comparator.comparing(SimpleEntry::getValue));
        for(int i=0;i<N;i++){
            System.out.print(list.get(i).getKey()+" ");
        }
        System.out.println();
    }
}

Measured memory_bytes: 68992
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    let xs = read_vec_i64();
    let k = read_i64();
    let x = xs.iter().max().unwrap();
    let res = xs.iter().sum::<i64>() - x + x * (2 as i64).pow(k as u32);
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}


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

const int maxn=100005;
int n,m,u,v,all;
vector<int>edge[maxn];
bool vis[maxn];
int sum[maxn],coef[maxn];

void predfs(int x,int p,int d){
	sum[x]=d;
	vis[x]=true;
	all+=sum[x];
	for(int i=0;i<int(edge[x].size());i++){
		int y=edge[x][i];
		if(y==p)continue;
		if(!vis[y])predfs(y,x,-d);
		else u=x,v=y;
	}
}

void dfs(int x,int p){
	for(int i=0;i<int(edge[x].size());i++){
		int y=edge[x][i];
		if(y==p||(x==u&&y==v)||(x==v&&y==u))continue;
		dfs(y,x);
		sum[x]+=sum[y];
		coef[x]+=coef[y];
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	u=v=0;
	predfs(1,0,1);
	if(m==n-1){
		if(all)puts("-1");
		else{
			dfs(1,0);
			long long ans=0;
			for(int i=1;i<=n;i++)ans+=abs(sum[i]);
			printf("%lld\n",ans);
		}
	}
	else if(sum[u]!=sum[v]){
		if(all)puts("-1");
		else{
			coef[u]++;coef[v]--;
			dfs(1,0);
			vector<int>val;
			val.push_back(0);
			for(int i=1;i<=n;i++){
				if(coef[i]>0)val.push_back(-sum[i]);
				else if(coef[i]<0)val.push_back(sum[i]);
			} 
			sort(val.begin(),val.end());
			int best=val[int(val.size())/2];
			long long ans=abs(best);
			for(int i=1;i<=n;i++)
				ans+=abs(best*coef[i]+sum[i]);
			printf("%lld\n",ans);
		}
	}
	else{
		if(all&1)puts("-1");
		else{
			long long ans=abs(all/2);
			sum[u]-=all/2;sum[v]-=all/2;
			dfs(1,0);
			for(int i=1;i<=n;i++)ans+=abs(sum[i]);
			printf("%lld\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 18060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

// ABC120C - Unification
// https://atcoder.jp/contests/abc120/tasks/abc120_c
void ABC120C() {
	string S;
	cin >> S;

	int ans = 0;
	int i = 0;
	while (i < S.size()) {
		//cout << "S.size() : " <<  S.size() << endl;

		//cout << "------" << endl;
		if (S.substr(i, 2) == "01" || S.substr(i, 2) == "10") {
		//if (S.substr(i, 2) == "01") {
			//2文字消去
			S = S.erase(i, 2);
			//cout << S << endl;
			//消した文字数をカウント
			ans += 2;

			//消したら上のキューブが落ちてくるので1個戻って判定をやり直す
			if (i >= 1) {
				i--;
			}			
			//cout << "i : " << i << endl;
			continue;
		}

		//ヒットしないときは次へ進む
		i++;
	}

	//cout << S << endl;
	cout << ans << endl;
}

int main() {
	ABC120C();

	return 0;
}

Measured memory_bytes: 512
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())

print(math.factorial(n)%mod)

Measured memory_bytes: 42736
import java.io.PrintWriter

val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

fun modPow(X: Long, N: Long, m: Long): Long {
    var x = X
    var n = N
    var ans = 1L
    while (n > 0) {
        if (n % 2 == 1L) {
            ans = ans * x % m
            n -= 1
        }
        x = x * x % m
        n /= 2
    }
    return ans
}

fun func() {
    val (N, M, K) = listOfLong()
    val mod = 1000000007L
    var a1 = 1L
    for (i in 0 until K - 2) {
        a1 = a1 * (N * M - 2 - i) % mod
        a1 = a1 * modPow(i + 1, mod - 2, mod) % mod
    }
    var ansX = 0L
    for (i in 1 .. N) {
        ansX += a1 * i * (N - i) * M * M % mod
    }
    var ansY = 0L
    for (i in 1 .. M) {
        ansY += a1 * i * (M - i) * N * N % mod
    }
    println((ansX + ansY) % mod)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }


Measured memory_bytes: 37560
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

max_digits = 60
MOD = 10**9 + 7

ans = 0
for i in range(max_digits):
    one_num = np.count_nonzero((a >> i) & 1)
    radix_mod = 2**i % MOD
    ans += (radix_mod * one_num * (n - one_num)) % MOD
print(ans%MOD)

Measured memory_bytes: 48824
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,M,C;
  cin>>N>>M>>C;
  vector<int> B(M);
  for(int i=0; i<M; i++){
    int b;
    cin>>b;
    B.at(i)=b;
  }
  vector<vector<int>> code(N, vector<int>(M));
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
      int a;
      cin>>a;
      code.at(i).at(j)=a;
    }
  }
  int count=0;
  int sum=0;
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
      sum+=code.at(i).at(j)*B.at(j);
    }
    if(sum+C>0){
      count++;
    }
    sum=0;
  }
  cout<<count<<endl;
}


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

int main() {
  char a;
  cin >> a;
  
  if(a=='a'){
    cout << "vowel" <<endl;
  }
  else if(a=='i'){
    cout << "vowel" <<endl;
  }
  else if(a=='u'){
    cout << "vowel" <<endl;
  }
  else if(a=='e'){
    cout << "vowel" <<endl;
  }
  else if(a=='o'){
    cout << "vowel" <<endl;
  }
  else {
    cout << "consonant" <<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)

int main(){
  int d;  scanf("%d", &d);
  int c[30], ccp[30], cid[30], s[370][30], t[370] = {0}, last[30] = {0};
  for(int i=1; i<=26; i++){  scanf("%d", c+i); ccp[i] = c[i]; cid[i] = i; }
  
  int topOfDay[370] = {0};
  for(int i=1; i<=d; i++){
    int top = 0;
    for(int j=1; j<=26; j++){
      scanf("%d", &s[i][j]);
      if(s[i][j] > top){
	top = s[i][j];
	topOfDay[i] = j;
      }
    }
  }

  for(int i=1; i<26; i++)
    for(int j=i+1; j<=26; j++)
      if(ccp[i] < ccp[j]){
	swap(int, ccp[i], ccp[j]);
	swap(int, cid[i], cid[j]);
      }
  
  for(int i=1; i<=d; i++){
    int ans = -1;
    if(i % 10 == 0)  ans = cid[1];
    else if(i % 16 == 0)  ans = cid[2];
    else if(i % 18 == 0)  ans = cid[3];
    else if(i % 21 == 0)  ans = cid[4];

    if(ans < 0)
      ans = topOfDay[i];
  
    printf("%d\n", ans);
  }

  return 0;
}


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

int main(){
    long N,K;
    cin >> N >> K;
    long p[N+1];
    double E[N+1], SE[N+1];
    SE[0]=0.0;
    for(long i=1; i<=N; i++){
        cin >> p[i];
        E[i]=( (double) p[i]+1)/2.0;
        SE[i]=SE[i-1]+E[i];
    }

    double ans,tmp;
    ans=0.0;
    for(long i=K; i<=N; i++){
        tmp = SE[i] - SE[i-K];
        if( tmp > ans ){
            ans = tmp;
        }
    }

    cout << setprecision(9) << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s;

bool solve() {
    int l = s.size();
    int idx = -1;
    for (int i = 0; i < l; i++) {
        if (s[i] == 'C') {
            idx = i;
            break;
        }
    }
    if (idx < 0) return false;
    for (int i = idx; i < l; i++) {
        if (s[i] == 'F')
            return true;
    }
    return false;
}

void input() {
    cin >> s;
}

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

    input();
    cout << (solve()?"Yes":"No") << endl;
}

Measured memory_bytes: 384
#include "iostream"
#include "string"

using namespace std;

int main() {
	int n;
	cin >> n;
	long long a[87];
	a[0] = 2LL;
	a[1] = 1LL;
	for (int i = 2; i <= n; i++) {
		a[i] = a[i - 1] + a[i - 2];
	}
	cout << a[n] << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ALDS1_10_B_MatrixChainMultiplication
{
	class Program
	{
		static void Main ( string[] args )
		{
			//input
			int dataCount = int.Parse (Console.ReadLine ());

			int[] vector = new int[dataCount + 1];
			for (int lp = 1; lp < vector.Length; lp++)
			{
				int[] inputNum = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();
				vector[lp - 1] = inputNum[0];
				vector[lp] = inputNum[1];
			}

			//process
			int[,] matrixCountTable = new int[dataCount + 1, dataCount + 1];

			for (int range = 2; range <= dataCount; range++)
			{
				for (int startIndex = 1; startIndex <= dataCount - range + 1; startIndex++)
				{
					int lastIndex = startIndex + range - 1;
					matrixCountTable[startIndex, lastIndex] = int.MaxValue;

					for (int spotIndex = startIndex; spotIndex <= lastIndex - 1; spotIndex++)
					{
						int matrixCount = vector[startIndex - 1] * vector[spotIndex] * vector[lastIndex];

						matrixCountTable[startIndex, lastIndex] = Math.Min (
							matrixCountTable[startIndex, lastIndex],
							matrixCountTable[startIndex, spotIndex] + matrixCountTable[spotIndex + 1, lastIndex] + matrixCount
						);
					}
				}
			}

			Console.WriteLine (matrixCountTable[1, dataCount]);
		}
	}
}

Measured memory_bytes: 9532
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

map<int, int> mp;
set<int> st;

int pos;
int now;
bool flag;

void add(int a) {
  //debug(a); debugln(pos);
  if (a > pos) {
    pos = a;
  } else if (a == pos) {
    mp[-a]++;
    while (mp[-a] >= now) {
      if (a > 1) {
        mp.erase(-a);
        a--;
        mp[-a]++;
      } else {
        flag = false;
        return;
      }
    }
    if (mp[-a] == 0) {
      mp.erase(-a);
    }
  } else {
    pos = a;
    for(auto e : mp) {
      if (e.first < -a) {
        st.insert(e.first);
      } else {
        break;
      }
    }
    for(auto e : st) {
      mp.erase(e);
    }
    st.clear();
    add(a);
  }
}

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

  int N; cin >> N;
  vector<int> A(N);
  now = 0;
  flag = true;
  rep(i, N) {
    cin >> A.at(i);
    if (flag && A.at(i) > now) {
      now = A.at(i);    
    } else {
      flag = false;
    }
  }

  if (flag) {
    cout << 1 << endl;
    return 0;
  }

  int sup = N;
  int min = 1;
  while (min < sup-1) {
    now = (sup+min)/2;
    mp.clear();
    pos = 0;
    flag = true;
    rep(i, N) {
      int a = A.at(i);
      add(a);
      if (!flag) break;
    }
    if (!flag) {
      debug(now);debugln("failed");
      min = now;
    } else {
      debug(now);debugln("succeeded");
      sup = now;
    }
  }  
  cout << sup << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char a[305][305];
int c[305][305];
int main(){
	int r,b,k,num=0;
	cin>>r>>b>>k;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=b;j++){
			cin>>a[i][j];
			if(a[i][j]=='#') c[i][j]=++num;
		}
	}
	for(int i=2;i<=r;i++){
		for(int j=1;j<=b;j++){
			if(c[i][j]) continue;
			c[i][j]=c[i-1][j];
		}
	}
	for(int i=r-1;i>=1;i--){
		for(int j=1;j<=b;j++){
			if(c[i][j]) continue;
			c[i][j]=c[i+1][j];
		}
	}
	for(int i=1;i<=r;i++){
		for(int j=2;j<=b;j++){
			if(c[i][j]) continue;
			c[i][j]=c[i][j-1];
		}
	}
	for(int i=1;i<=r;i++){
		for(int j=b-1;j>=1;j--){
			if(c[i][j]) continue;
			c[i][j]=c[i][j+1];
		}
	}
	for(int i=1;i<=r;i++){
		for(int j=1;j<=b;j++){
			cout<<c[i][j]<<" ";
		}
		cout<<endl;
	}
}

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

#define ll long long
using namespace std;

const int N = 3e3 + 5;
int n;
ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> dp[1][i];
    }
    for(int len = 2; len <= n; len++) {
        for(int i = 0; i + len <= n; i++) {
            dp[len][i] = max(dp[1][i + len - 1] - dp[len - 1][i], dp[1][i] - dp[len - 1][i + 1]);
        }
    }
    cout << dp[n][0] << endl;
}

Measured memory_bytes: 70016
# coding: utf-8

import sys
input = sys.stdin.readline

def f2(N, s):
    MOD = int(1e9 + 7)
    dp = [1] * N
    for i in range(1, N):
        csum = list(dp)
        for j in range(1, N - i + 1):
            csum[j] += csum[j - 1]
        csum_ = csum[N - i]
        i_ = i - 1
        for j in range(N - i):  # N-(i+1)+1 = N-i
            dp[j] = csum[j] if s[i_] == ">" else (csum_ - csum[j] + MOD) % MOD
    return(dp[0])

N = int(input()) # 2 <= N <= 30000
s = input().rstrip() # len(s) = N - 1
print(f2(N, s))


Measured memory_bytes: 7144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < (b); ++i)
#define rrep(i,a,b) for(int i = b; i --> (a);)
#define all(v) v.begin(),v.end()
#define trav(x,v) for(auto &x : v)
#define sz(v) (int)(v).size()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, m, q;
	cin >> n >> m;
	vector<vi> gr(n);
	rep(_,0,m){
		int a,b;
		cin >> a >> b;
		--a, --b;
		gr[a].push_back(b);
		gr[b].push_back(a);
	}
	cin >> q;
	priority_queue<pair<pii,int>> ko;
	vector<vi> st(n,vi(11,-1));
	vi cols(q);
	rep(i,0,q){
		int v,d;
		cin >> v >> d >> cols[i];
		--v;
		ko.push({{i,d}, v});
	}
	while(!ko.empty()){
		auto tr = ko.top();
		ko.pop();
		pii pa = tr.first;
		int v = tr.second;
		if(st[v][pa.second] >= pa.first) continue;
		st[v][pa.second] = pa.first;
		if(pa.second > 0){
			--pa.second;
			trav(u, gr[v]) if(st[u][pa.second] < pa.first)
				ko.push({pa, u});
		}
	}
	rep(i,0,n){
		int mycol = -1;
		rep(j,0,11) mycol = max(mycol, st[i][j]);
		cout << (mycol == -1 ? 0 : cols[mycol]) << endl;
	}
}

Measured memory_bytes: 23020
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  ll n,k;
  cin >> n >> k;

  long double ans = 0;
  ll dig = 1;
  if(n>k) ans += n-k;
  for(int i = min(n,k); i>0; --i){
    while(i*dig<k){
      dig <<= 1;
    }
    ans += (1/static_cast<long double>(dig));
  }
  ans /= static_cast<long double>(n);
  printf("%.10Lf\n",ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2];
int i,j,k,l,t,n,m,tot;
void add(int x,int y){
	go[++tot]=y;
	nxt[tot]=h[x];
	h[x]=tot;
}
int perfect(int x,int y){
	int t=h[x];
	int p=0;
	while (t){
		if (go[t]!=y) p+=perfect(go[t],x);
		t=nxt[t];
	}
	if (p>=2) return p;
	else return p^1;
}
int main(){
	scanf("%d",&n);
	fo(i,1,n-1){
		scanf("%d%d",&j,&k);
		add(j,k);add(k,j);
	}
	if (perfect(1,0)==0) printf("Second\n");
	else printf("First\n");
}

Measured memory_bytes: 2176
def main():
    import itertools

    n = int(input())
    ps = tuple(map(int, input().split()))
    qs = tuple(map(int, input().split()))

    num_list = list(itertools.permutations([i for i in range(1, n+1)]))

    print(abs(num_list.index(ps) - num_list.index(qs)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8052
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int 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;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

int vec[45][2];
int k[45];
int dp[45][2];
int a[100005];

signed main() {
	int n, K;
	cin >> n >> K;
	{
		int i = 0;
		while (K > 0) {
			k[i] = K % 2;
			K /= 2;
			i++;
		}
	}
	rep(i, n) {
		cin >> a[i];
		int x = a[i];
		int j = 0;
		while (x > 0) {
			if (x % 2 == 1) {
				vec[j][1]++;
			}
			x /= 2;
			j++;
		}
	}
	rep(i, 41) {
		vec[i][0] = n - vec[i][1];
	}
	rep(i, 41) {
		vec[i][0] = n - vec[i][1];
		vec[i][0] *= ((int)1 << i);
		vec[i][1] *= ((int)1 << i);
		swap(vec[i][0], vec[i][1]);
	}
	reverse(vec, vec + 41);
	reverse(k, k + 41);

	rep(i, 42) {
		dp[i][0] = -1;
		dp[i][1] = -1;
	}
	dp[0][0] = 0;
	rep(i, 41) {
		rep(j, 2) {
			if (dp[i][j] != -1) {
				rep(d, (j ? 2 : k[i] + 1)) {
					dp[i + 1][j || d < k[i]] = max(dp[i + 1][j || d < k[i]], vec[i][d] + dp[i][j]);
				}
			}
		}
	}
	cout << max(dp[41][0], dp[41][1]) << endl;


	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int[][] c = new int[3][3];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = sc.nextInt();
            }
        }

        boolean flag = false;
        for (int x = 0; x <= 100; x++) {
            int a1 = c[0][0] - x;
            int a2 = c[0][1] - x;
            int a3 = c[0][2] - x;
            int b1 = x;
            int b2 = c[1][0] - a1;
            int b3 = c[2][0] - a1;

            if (c[1][1] == a2+b2 && c[1][2] == a3+b2 && c[2][1] == a2+b3 && c[2][2] == a3+b3) {
                flag = true;
                break;
            }
        }

        if (flag) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int numProblems = Integer.parseInt(br.readLine());
    int sum = 0;
    int minimumScoreProblem = 101;
    int tempScore = 0;
    
    for (int i=0; i<numProblems; i++){
      tempScore = Integer.parseInt(br.readLine());
      sum += tempScore;
      if(minimumScoreProblem>tempScore && tempScore%10 != 0){
        minimumScoreProblem = tempScore;
      }
    }
    int maxPoint;
    if (sum%10 != 0){
      maxPoint = sum;
    } else if (minimumScoreProblem == 101){
      maxPoint = 0;
    } else {
      maxPoint = sum - minimumScoreProblem;
    }
    System.out.println(maxPoint);
  }
}


Measured memory_bytes: 23124
#include <iostream>
#include<numeric>
using namespace std;
int gcd(int a,int b){
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
int main() {
  int n;
  cin>>n;
  int *a=new int[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int ans=a[0];
  for(int i=0;i<n;i++){
    ans=gcd(ans,a[i]);
  }
  cout <<ans;
  return 0;
}

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7; // 998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator*(long long y,const mint& m){ return m*y; }

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	static mint dp[101][100001],sum[100002];
	dp[0][0]=1;
	rep(i,n){
		sum[0]=dp[i][0];
		rep(j,k+1) sum[j+1]=sum[j]+dp[i][j];

		rep(j,k+1){
			dp[i+1][j]=sum[j+1]-sum[max(j-a[i],0)];
		}
	}
	printf("%d\n",dp[n][k].to_int());

	return 0;
}


Measured memory_bytes: 40064
n, k, q = map(int, input().split())
a = list(map(int, input().split()))

set_a = sorted(set(a))

result = 1000000000
for y in set_a:
    counter = 0
    candidate = []
    for i in range(n):
#        print(counter, a[i], y)
        if a[i] < y:
            if counter >= k:
#                print(a[i-counter:i-1])
                candidate = candidate + sorted(a[i-counter:i])[:counter - k + 1]
            counter = 0
        elif i == n - 1:
            if counter + 1 >= k:
                candidate = candidate + sorted(a[i-counter:i+1])[:counter - k + 2]
        else:
            counter += 1
#    print(candidate)
    if len(candidate) >= q:
        z = sorted(candidate)[q - 1] - y
        if z < result:
            result = z

print(result)

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

public class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<Integer> tubeB = new ArrayList<Integer>();
		ArrayList<Integer> tubeC = new ArrayList<Integer>();
		ArrayList<String> ans = new ArrayList<String>();
		
		int n = Integer.parseInt(br.readLine());
		main:
		for (int i = 0; i < n; i++) {
			tubeB.clear();
			tubeC.clear();
			StringTokenizer st = new StringTokenizer(br.readLine()," ");
			
			tubeB.add(Integer.parseInt(st.nextToken()));
			while (st.hasMoreTokens()) {
				
				boolean flag = false;
				int ball = Integer.parseInt(st.nextToken());
				if (tubeB.get(tubeB.size() - 1) < ball) {
					tubeB.add(ball);
					flag = true;
					continue;
				}
				if (tubeC.size() == 0) {
					tubeC.add(ball);
					continue;
				}
				if (tubeC.get(tubeC.size() - 1) < ball) {
					tubeC.add(ball);
					flag = true;
					continue;
				}
				if (!flag) {
					ans.add("NO");
					continue main;
				}
			}
			ans.add("YES");
		}
		
		for (String a : ans) {
			System.out.println(a);
		}
	}
	
}

Measured memory_bytes: 9064
def d_cake_123_binary_search():
    """editorialの解法4 O(K^2log(max(P))"""
    # 参考: https://atcoder.jp/contests/abc123/submissions/4871511
    import sys
    import bisect
    input = sys.stdin.readline
    X, Y, Z, K = [int(i) for i in input().split()]
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    C = tuple(map(int, input().split()))
    ab = sorted([e1 + e2 for e2 in B for e1 in A])  # A, Bの要素は全部調べる

    # rejected 以上の値は，美味しさの合計がそれ以上である個数が K 個未満である
    accepted, rejected = -1, 10**11
    while abs(accepted - rejected) > 1:
        mid = (accepted + rejected) // 2
        count = sum([len(ab) - bisect.bisect_left(ab, mid - e) for e in C])
        if count >= K:
            accepted = mid
        else:
            rejected = mid

    ans = []
    for e in C:
        idx = bisect.bisect_left(ab, accepted - e)
        ans.extend(e + _ab for _ab in ab[idx:])
    ans.sort(reverse=True)
    return '\n'.join(map(str, ans[:K]))

print(d_cake_123_binary_search())

Measured memory_bytes: 537456
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int a, b, c, k; cin >> a >> b >> c >> k;
  while (k > 0 && a >= b) {
    --k;
    b *= 2;
  }
  while (k > 0 && b >= c) {
    --k;
    c *= 2;
  }
  cout << (a < b && b < c ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 3632
open Printf
open Scanf

let () =
  let s = scanf "%s " (fun x -> x) in
  let ss = String.length s in
  let rec count c i =
    if i = ss then c
    else if s.[i] = '1' then count (c + 1) (i + 1)
    else count c (i + 1) in
  count 0 0 |> printf "%d\n"


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,k;
long long a[1009];
long long dp[109][100009];
long long psum[109][100009];
int mod = 1000000007;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dp[0][0] = 1;
	psum[0][0] = 1;
	for(int i=1;i<=k;i++)psum[0][i] = (psum[0][i] + psum[0][i-1])%mod;
	for(int i=1;i<=n;i++){
		dp[i][0] = 1;
		psum[i][0] = 1;
		for(int j=1;j<=k;j++){
			long long x = psum[i-1][j];
			if(j-a[i]-1 >= 0){
				x = (x - psum[i-1][j-a[i]-1] + mod)%mod;
			}
			dp[i][j] = x;
		}
		for(int j=1;j<=k;j++){
			psum[i][j] = (dp[i][j] + psum[i][j-1])%mod;
		}
	}
	cout<<dp[n][k]<<endl;
}


Measured memory_bytes: 162048
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    a,b,x = map(int,input().split())
    if a > x:
        print('NO')
    elif a + b >= x:
        print('YES')
    else:
        print('NO')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38508
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

int main(){
    string s;
    cin>>s;
    bool flagN=false;
    bool flagW=false;
    bool flagS=false;
    bool flagE=false;

    for(int i=0;i<s.size();i++){
        if(s[i]=='W') flagW=true;
        if(s[i]=='N') flagN=true;
        if(s[i]=='S') flagS=true;
        if(s[i]=='E') flagE=true;
    }

    if(flagW^flagE or flagS^flagN ) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

    return 0;
};


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

bool chk[244140624];
int n;
string ins, s;

int h(string &s) {
    int ret = 0;
    for (int i=0; i<(int)s.size(); ++i) {
        ret *= 5;
        if (s[i] == 'A')
            ret += 1;
        else if (s[i] == 'C')
            ret += 2;
        else if (s[i] == 'G')
            ret += 3;
        else
            ret += 4;
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    while (n--) {
        cin >> ins >> s;
        if (ins[0] == 'i') {
            chk[h(s)] = true;
        } else {
            cout << (chk[h(s)] ? "yes" : "no") << endl;
        }
    }
    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs {cout<<"-1\n";return 0;}
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

int x_d(ll x) {
  int d = 0;
  while (x) {
    ++d;
    x >>= 1;
  }
  return d;
}

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

  int T;
  cin >> T;
  rep(t, T) {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    string S;
    cin >> S;

    vector<ll> ch(62);

    bool ok = true;
    drep(i,N) {
      ll AA = A[i];
      while (AA != 0) {
        int d = x_d(AA);
        if (ch[d] == 0) {
          if (S[i] == '0') {
            ch[d] = AA;
          } else {
            ok = false;
          }
          break;
        }
        AA = AA ^ ch[d];
      }
    }
    cout << (ok ? '0' : '1') << '\n';
  }
  return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100;

int n;
char s[MAXN];

int main()
{
	int t1=0,t2=0;
	bool flag=0;
	scanf("%s",s);
	if(s[0]!='A') flag=1;
	for(int i=0;i<strlen(s);i++) {
		if(s[i]=='C') {
			t1++;
			if(i<2||i>strlen(s)-2)
				flag=1;
		}
		if(s[i]!='C'&&s[i]!='A'&&('A'<=s[i]&&s[i]<='Z'))
			flag=1;
	}
	if(t1!=1)
		flag=1;
	printf("%s",flag?"WA":"AC");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
  int n;
  cin>>n;
  int ans=0;
  int ma=0;
  vector<int>a(n);
  rep(i,n){
    cin>>a.at(i);
    if(a.at(i)>=ma){
      ans++;
      ma=a.at(i);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define mod 1000000007
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 0;
  scanf("%lld", &n);
  ll a[n], dp[n][2];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), dp[i][0] = dp[i][1] = -1e18;
  dp[0][1] = 0, dp[1][1] = 0;
  dp[0][0] = a[0];
  dp[1][0] = a[0] > a[1] ? a[0] : a[1];
  for(i = 2; i < n; ++i) {
    if(i & 1) dp[i][0] = dp[i - 1][0], dp[i][1] = dp[i - 1][1];
    else dp[i][1] = dp[i - 1][0];
    if(dp[i][0] < dp[i - 2][0] + a[i]) dp[i][0] = dp[i - 2][0] + a[i];
    if(dp[i][1] < dp[i - 2][1] + a[i]) dp[i][1] = dp[i - 2][1] + a[i];
  }
  printf("%lld", dp[n - 1][n & 1]);
  return 0;
}

Measured memory_bytes: 6416
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	

int n,x,y,count=0,flag=0;
cin>>n;

for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		if(count==3) break;
		else if(x==y) 
			{
				count++;
				flag=0;
			}
		else {count=0;}
	}

	if(count==3) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 3632
#include<cstdio>

using namespace std;

bool coprime(int a,int b){
	for(int t;b;t=a,a=b,b=t)	a%=b;
	return a==1;
}

int capa[1002][1002],flow[1002][1002],src,snk,sz;

bool findAugPath(int u,int *path,int &len,bool *visited,int i=0){
//if(i>10){puts("error");return false;}
//for(int j=0;j<i;j++)putchar(' ');printf("%d\n",u);
	path[i]=u;
	visited[u]=true;
	if(u==snk){ len=i+1; return true; }
	for(int v=0;v<sz;v++){
		if(!visited[v] && capa[u][v]-flow[u][v]>0){
//			visited[v]=true;
			bool b=findAugPath(v,path,len,visited,i+1);
//			visited[v]=false;
			if(b)	return true;
		}
	}
	return false;
}

int main(){
	for(int m,n;scanf("%d%d",&m,&n),m;){
		static int blue[500],red[500];
		for(int i=0;i<m;i++)	scanf("%d",blue+i);
		for(int j=0;j<n;j++)	scanf("%d",red+j);

		src=0,snk=m+n+1,sz=m+n+2;
		for(int i=0;i<sz;i++)for(int j=0;j<sz;j++){
			capa[i][j]=0;
			flow[i][j]=0;
		}

		for(int i=0;i<m;i++)	capa[src][1+i]=1;
		for(int i=0;i<m;i++)for(int j=0;j<n;j++){
			if(!coprime(blue[i],red[j]))	capa[1+i][1+m+j]=1;
		}
		for(int j=0;j<n;j++)	capa[1+m+j][snk]=1;

//for(int i=0;i<sz;i++){for(int j=0;j<sz;j++)printf("%2d ",capa[i][j]);puts("");}puts("");
		static int path[1002],len;
		static bool visited[1002];
		while(1){
			for(int u=0;u<sz;u++)	visited[u]=false;
			if(!findAugPath(src,path,len,visited))	break;
			for(int i=1,u=path[0];i<len;i++){
				int v=path[i];
				flow[u][v]++;
				flow[v][u]--;
				u=v;
			}
//for(int i=0;i<sz;i++){for(int j=0;j<sz;j++)printf("%2d",flow[i][j]);puts("");}puts("");
		}

		int maxmatch=0;
		for(int i=0;i<m;i++)for(int j=0;j<n;j++){
			if(flow[1+i][1+m+j]==1)	maxmatch++;
		}
		printf("%d\n",maxmatch);
	}

	return 0;
}

Measured memory_bytes: 8644
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();

    if ((x % y) == 0) {
      System.out.println(-1);
    } else {
      System.out.println(x);
    }

  }
}

Measured memory_bytes: 35768
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

int main(){
  int A, B, C, K;
  std::cin >> A >> B >> C;
  std::cin >> K;
  int cnt = 0;
  while(B<=A){
    B*=2;
    cnt++;
  }
  while(C<=B) {
    C*=2;
    cnt++;
  }
  if (cnt<=K) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

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

constexpr double EPS = 0.00001;

int main() {
	cout.precision(10);
	cout.setf(ios::fixed);

	for(int q; cin >> q && q != -1;) {
		double x = q / 2.0;

		while(abs(x * x * x - q) >= EPS * q) {
			x -= ((x * x * x) - q) / (3 * x * x);
		}

		cout << x << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1224
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int n,m;
  cin>>n>>m;
  pair<int,int>A[n],C[m];
  rep(i,n) {
    int a,b;
    cin>>a>>b;
    A[i].F=a;
    A[i].S=b;
  }
  rep(i,m) {
    int c,d;
    cin>>c>>d;
    C[i].F=c;
    C[i].S=d;
  }
  rep(i,n) {
    int a=A[i].F;
    int b=A[i].S;
    int mi=inf;
    int w=1;
    rep(j,m) {
      int c=C[j].F;
      int d=C[j].S;
      if(abs(a-c)+abs(b-d)<mi) {
        mi=abs(a-c)+abs(b-d);
        w=j+1;
      }
    }
    cout<<w<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int lcs(string X, string Y) {
  int memo[1010][1010];
  int m = X.size();
  int n = Y.size();
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 0; i < m; i++) {
    memo[i][0] = 0;
  }
  for (int j = 0; j < m; j++) {
    memo[0][j] = 0;
  }
  int max_lcs = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        memo[i][j] = memo[i-1][j-1] + 1;
      } else {
        memo[i][j] = max(memo[i][j-1], memo[i-1][j]);
      }
      max_lcs = max(max_lcs, memo[i][j]);
    }
  }
  return max_lcs;
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string X, Y;
    cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }
}



Measured memory_bytes: 7140
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222



ll a[33];


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


  cin >> n >> m;
  rep(i, n) {
    ll k;
    cin >> k;
    rep(j, k) {
      ll x;
      cin >> x;
      a[x]++;
    }
  }
  rep(i, m + 1) if (a[i] == n) ans++;
  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  (h:w:_) <- fmap (map read . words) getLine :: IO [Int]
  am <- replicateM h $ map read . words <$> getLine :: IO [[Int]]
  let bam = map (map even) am
  let ans = (solve 1 bam) ++ (vSolve w bam)
  print $ length ans
  forM_ (map (unwords . map show) ans) putStrLn


solve :: Int -> [[Bool]] -> [[Int]]
solve _ [] = []
solve i (as:am) = (manip i 1 as) ++ (solve (i + 1) am)
  where
    manip :: Int -> Int -> [Bool] -> [[Int]]
    manip _ _ (a:[]) = []
    manip i j (a:as)
      | a = manip i (j + 1) as
      | otherwise = [i, j, i, j + 1] : (manip i (j + 1) $ move as)

move :: [Bool] -> [Bool]
move [] = []
move (a:as) = (not a):as

vSolve :: Int -> [[Bool]] -> [[Int]]
vSolve w am = manip 1 $ map (even . length . filter (\x -> not x)) $ am
  where
    manip _ (b:[]) = []
    manip i (b:bs)
      | b = manip (i + 1) bs
      | otherwise = [i, w, i + 1, w] : (manip (i + 1) (move bs))


Measured memory_bytes: 61564
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  string s; cin >> s;
  int n = s.size();

  bool a = s[0] == s.back();
  bool b = n % 2 == 0;

  if (a ^ b) {
    cout << "Second" << endl;
  } else {
    cout << "First" << endl;
  }

  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<cstring>
#include<fstream>
#include<queue>
#include<stack>
using namespace std;

int main()
{
	int n, m;
	int a[51] = {};
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		a[s]++;
		a[t]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << a[i] << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{

    static int top = 0;
    static int[] stack = new int[1000];
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String[] n = (sc.nextLine()).split(" ");

        for(int i = 0; i < n.length; i++){
            if(n[i].equals("+")){
                int b = pop();
                int a = pop();
                push(a + b);
            }else if(n[i].equals("-")){
                int b = pop();
                int a = pop();
                push(a - b);
            }else if(n[i].equals("*")){
                int b = pop();
                int a = pop();
                push(a * b);
            }else
            push(Integer.parseInt(n[i]));
        }
        System.out.println(pop());
    }

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

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



Measured memory_bytes: 26092