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

public class Main {
	public static void main( String[] args ) {
		Main heap = new Main();
		heap.exec();
	}

	public void execText() {
		int[] tests = {-90,3,2,1};
		exec(tests);
		for( int value : tests ) {
			if( value == -90 ) {
				continue;
			}
			System.out.println(value);
		}
	}

	public void exec() {
		Scanner sc = null;
		try {
			sc = new Scanner(System.in);
			sc.nextLine();
			String[] lines = sc.nextLine().split(" ");
			int[] heaps = new int[lines.length+1];
			for( int i = 1; i < heaps.length; i++ ) {
				heaps[i] = Integer.parseInt(lines[i-1]);
			}
			exec(heaps);
			StringBuilder bld = new StringBuilder();
			for( int i = 1; i < heaps.length; i++ ) {
				bld.append(" ");
				bld.append(heaps[i]);
			}
			System.out.println(bld.toString());
		} finally {
			if( sc != null ) {
				sc.close();
			}
		}
	}

	public void exec( int[] heaps ) {
		for( int ii = heaps.length/2; ii >= 1; ii-- ) {
			maxHeapfy(heaps, ii);
		}
	}

	public static final void maxHeapfy( int[] heaps, int index ) {
		int leftIndex = left(index);
		int rightIndex = right(index);
		int largest = index;

		if( leftIndex < heaps.length && heaps[leftIndex] > heaps[largest]) {
			largest = leftIndex;
		}

		if( rightIndex < heaps.length && heaps[rightIndex] > heaps[largest] ) {
			largest = rightIndex;
		}

		if( largest != index ) {
			int value = heaps[index];
			heaps[index] = heaps[largest];
			heaps[largest] = value;
			maxHeapfy(heaps,largest);
		}
	}

	public static final int left( int value ) {
		return 2 * value;
	}

	public static final int right( int value ) {
		return 2 * value + 1;
	}
}



Measured memory_bytes: 107356
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, M) = read!(usize, usize);
    let T = read![usize, usize; M];

    let mut S = vec![None; N];
    let mut ok = true;

    for (mut s, c) in T {
        s -= 1;

        match S[s] {
            Some(old_c) => {
                if old_c != c {
                    ok = false;
                    break;
                }
            }
            None => {
                S[s] = Some(c);
            }
        }
    }

    let is_zero = N == 1 && S[0].map_or(true, |c| c == 0);
    if is_zero {
        println!("0");
        return;
    }

    if S[0] == Some(0) {
        ok = false;
    }

    if S[0].is_none() {
        S[0] = Some(1);
    }
    for i in 1..N {
        if S[i].is_none() {
            S[i] = Some(0);
        }
    }

    if ok {
        let S = S
            .into_iter()
            .map(|o| (b'0' + o.unwrap() as u8) as char)
            .collect::<String>();
        println!("{}", S);
    } else {
        println!("-1");
    }
}


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

#define pii pair<int, int>
#define fi first
#define se second
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair

const int N = 1e5+1;

ll gcd(ll a, ll b){
	if(a < b)
		return gcd(b, a);
	if(b == 0)
		return a;
	return gcd(b, a%b);
}

int a[N] = {0};

int main(){
	ll n, m;
	string s, t;
	cin >> n >> m >> s >> t;
	ll k = gcd(m, n);
	ll a = n/k, b = m/k;

	ll ans = k*a*b;
	for(int i = 0; i < k; i++){
		if(s[i*a] != t[i*b])
			ans = 0;
	}
	if(ans)
		cout << ans << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Goods{
	private int value;
	private int weight;
	private char goodsType;
	private long time;
	private String name;

	//コンストラクタ
	public Goods(int v, int w, char gt, long t, String na) {
		value = v;
		weight = w;
		goodsType = gt;
		time = t;
		name = na;
	}

	//ゲット--------------------------
	public int getValue() { return value;}
	public int getWeight() { return weight;}
	public char getType() {return goodsType;}
	public long getTime() {return time;}
	public String getName() {return name;}
}

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			Goods[] array = new Goods[n];  //Goodsの配列
			for (int i=0; i<n; i++) {
				int v = sc.nextInt();
				int w = sc.nextInt();
				String gt0 = sc.next();
				char gt = gt0.charAt(0);
				long t = sc.nextLong();
				String na = sc.next();
				array[i] = new Goods(v,w,gt,t,na);
			}
			Arrays.sort(array,new Comparator<Goods>() {
				@Override
				public int compare(Goods g0, Goods g1) {
					if (g0.getValue() > g1.getValue()) return 1;
					else if (g0.getValue() < g1.getValue()) return -1;
					if (g0.getWeight() > g1.getWeight()) return 1;
					else if (g0.getWeight() < g1.getWeight()) return -1;
					if (g0.getType() > g1.getType()) return 1;
					else if (g0.getType() < g1.getType()) return -1;
					if (g0.getTime() > g1.getTime()) return 1;
					else if (g0.getTime() < g1.getTime()) return -1;
					if (g0.getName().compareTo(g1.getName()) > 0) return 1;
					return -1;
				}
			});
			for (int i=0; i<n; i++) {
				System.out.println(array[i].getValue() + " " + array[i].getWeight()+ " " + array[i].getType()+ " " + array[i].getTime()+ " " + array[i].getName());
			}
		}
	}
}



Measured memory_bytes: 185312
#include <iostream>
using namespace std;
int main(){
	long long int a, b, k;
	cin >> a >> b >> k;
	if(k <= a){
		cout << a - k << " " << b << endl;
	}else if((k - a) <= b){
		cout << "0 " << b - (k - a) << endl;
	}else{
		cout << "0 0" << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
V = [int(x) for x in input().split()]

for v in range(N-1):
    V.sort()
    min1 = V.pop(0)
    min2 = V.pop(0)
    new = (min1 + min2) / 2
    V.append(new)

print(V[0])

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

int main(){
  while(1){
  int N,m=0,l=0;
  cin>>N;
  if(N==0) break;
  for(int i=0;i<N;i++){
    
    int k;
    cin>>k;
    if(k==0){
      l++;
	}else if(k==1){
      m++;
	}
      
  }if(N==l+m){
    cout<<"NA"<<endl;
  }else if(l!=0){
    cout<<N+1-l<<endl;
  }else{
    cout<<N+1<<endl;
  }
  }
  
  return 0;
}
  
    
    
    



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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int a, b;
	cin >> a >> b;
	cout << a*b << endl;
	
	return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(void){
	int d=0;
	int a[3];
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	for(int i=0;i<3;i++){
		if(a[i]==5||a[i]==7){
			d+=a[i];
		}
	}
	if(d==17){
		printf("YES");
	}else{
		printf("NO");
	}
}

Measured memory_bytes: 1656
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long total = 1;
      for(int i = 0; i < n; i++) {
      long a = sc.nextLong();
      if(a == 0) {
        total = 0;
      } else {
        if(total <= ((long)Math.pow(10, 18) / a)) {
          if(total >= 0) total *= a;
        } else {
          total = -1;
        }
      }
    }
      System.out.print(total);
    }
}


Measured memory_bytes: 59688
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> d;
    for (int i = 0; i < n; ++i) {
        int t ;
        cin >> t;
        d.push_back(t);
    }

    vector<int> res;
    for (int i = 0; i < d.size(); ++i) {
        for (int j = i + 1; j < d.size(); ++j) {
            res.push_back(d[i] * d[j]);
        }
    }
    int ret = 0;
    for (auto p : res) {
        ret += p;
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1003,INF=1<<30;

vector<int> S[MAX];

int main(){
    
    int N;cin>>N;
    vector<int> X(N);
    
    for(int i=0;i<N-1;i++){
        int a;cin>>a;a--;
        S[a].push_back(i+1);
    }
    
    for(int i=0;i<N;i++){
        cin>>X[i];
    }
    
    int dp[N][2];
    
    for(int i=0;i<N;i++){
        for(int j=0;j<2;j++){
            dp[i][j]=0;
        }
    }
    
    bool ok=true;
    
    for(int i=N-1;i>=0;i--){
        if(S[i].size()==0){
            dp[i][0]=X[i];
            dp[i][1]=0;
        }else{
            int M=int(S[i].size());
            int can[M+1][5001];
            for(int k=0;k<M+1;k++){
                for(int j=0;j<5001;j++){
                    can[k][j]=0;
                }
            }
            
            int a=dp[S[i][0]][0],b=dp[S[i][0]][1];
            
            if(a<5001) can[1][a]=1;
            if(b<5001) can[1][b]=1;
            
            int sum=a+b;
            
            for(int k=2;k<=M;k++){
                int a=dp[S[i][k-1]][0],b=dp[S[i][k-1]][1];
                sum+=(a+b);
                for(int j=5000;j>=0;j--){
                    if(j-a>=0&&can[k-1][j-a]) can[k][j]=1;
                    if(j-b>=0&&can[k-1][j-b]) can[k][j]=1;
                }
            }
            
            int maxi=-1;
            
            for(int j=X[i];j>=0;j--){
                if(can[M][j]){
                    maxi=j;
                    break;
                }
            }
            
            if(maxi==-1){
                ok=false;
            }
            else{
                dp[i][0]=X[i];
                dp[i][1]=sum-maxi;
            }
        }
    }
    
    if(ok) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    
}


Measured memory_bytes: 19840
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
A = [int(input()) for _ in range(5)]

def calc(p):
    t = 0
    for n, i in enumerate(p):
        t += A[i]
        if n == 4:
            break
        r = t % 10
        t += (10 - r) % 10
    return t

ans = INF
for p in permutations(range(5)):
    ans = min(calc(p), ans)
print(ans)



Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
using namespace std;
int main(){
    int N;
    cin>>N;
    int ans = N;
    REP(i,N){
        int d;
        cin >> d;
        ans -= (d&1) == 1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3100
import java.util.*;
import java.math.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int n= sc.nextInt();
    int a=sc.nextInt();
    int b=sc.nextInt();
    System.out.println(Math.min(n*a, b));
    
  }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;

namespace ProgramingStydying
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine();
            var input2 = Console.ReadLine();

            var a = new List<char>();
            var b = new List<char>();

            var length = Math.Min(input1.Length, input2.Length);

            for (int i = 0; i < input1.Length; i++) 
            {
                a.Add(input1[i]);
            }
            for (int i = 0; i < input2.Length; i++)
            {
                b.Add(input2[i]);
            }

            a.Sort();
            b.Sort();
            b.Reverse();

            var ans = "No";

            for(int i = 0; i < length; i++)
            {
                if(a[i] < b[i])
                {
                    ans = "Yes";
                    break;
                }
                if (a[i] > b[i])
                {
                    break;
                }
                else
                {
                    if (i == length - 1)
                    {
                        if (input1.Length < input2.Length)
                        {
                            ans = "Yes";
                        }
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 26000
n = int(input())
As = list(map(int, input().split()))
rs = []
for m in {0, 1}:
  r = 0
  s = 0
  for i in range(n):
    A = As[i]
    if i%2 == m:
      if s+A >= 0:
        r += s+A+1
        s = -1
      else:
        s += A
    else:
      if s+A <= 0:
        r += -(s+A)+1
        s = +1
      else:
        s += A
  #print(m, r)
  rs.append(r)
r = min(rs)
print(r)


Measured memory_bytes: 14332
import java.util.*;
import java.io.*;
public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5))
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}

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

int main() {
  ll n, m, k; cin >> n >> m >> k;
  vector<ll> a(n), b(m), as(n+1), bs(m+1);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  rep(i, n) as[i+1] = as[i] + a[i]; 
  rep(i, m) bs[i+1] = bs[i] + b[i];
  int index = 0;
  rep(i, n+1) {
    if (as[i] <= k) index = i;
    else break;
  }
  ll ans = index;
  if (as[n] + bs[m] <= k) {
    cout << n + m << endl;
    return 0;
  }
  rep(i, index+1) {
    int t = k - as[i];
    int s = upper_bound(bs.begin(), bs.end(), t) - bs.begin();
    if (s > 0) {
      if (bs[s-1] <= t)
        ans = max(ans, i + s - 1);
    }
    //cout << t << " " << i << " " << s << endl;
  }
  cout << ans << endl;
  return 0;
}

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

map<ll,ll>f;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,s=0;
    cin>>n;
    ll l1[n+1];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
        s+=l1[i];
        f[l1[i]]++;
    }
    ll q,b,c;
    cin>>q;
    for(int i=1;i<=q;i++){
        cin>>b>>c;
        s+=(ll)((c-b)*f[b]);
        cout<<s<<endl;
        f[c]+=f[b];f[b]=0;
    }
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
using ll=long long;
using vl=vector<ll>;

int main(){
    ll n,k;cin >> n >>k;
    vl a(n),b(n);
    rep(i,n)cin >> a[i] >> b[i];
    ll res=0;
    rep(i,30){
        if((1LL<<i)&k){
            ll t=(1LL<<i);
            ll p=((k&~(1<<i))|(t-1));
            ll sum=0;
            rep(j,n){
                if(p==(p|a[j]))sum+=b[j];
            }
            res=max(res,sum);
        }
    }
    ll tot=0;
    rep(j,n){
        if(k==(k|a[j]))tot+=b[j];
    }
    cout << max(res,tot) <<endl;
}   


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

const int MOD = 924844033;

int dp[2001][2001][2];

int main() {
    int n, k; cin >> n >> k;
        
    vector<int> sizes;

    for(int i = 1; i <= k; ++i) {
        int cnt = 0;
        for(int j = i; j <= n; j += k)
            cnt++;
        sizes.push_back(cnt);
        sizes.push_back(cnt);
    }

    int m = sizes.size();
     
    dp[0][0][0] = 1;

    for(int i = 1; i <= n; ++i) 
        for(int j = 0; j <= n; ++j) {
            dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) % MOD;
            if(j >= 1)
                dp[i][j][1] = (dp[i - 1][j - 1][0]);
        }
        
    vector<vector<int>> M(m + 1, vector<int> (n + 1, 0));
    
    for(int i = 1; i <= sizes[0]; ++i)
        M[0][i] = (dp[sizes[0] - 1][i][0] + dp[sizes[0] - 1][i][1]) % MOD;
    
    M[0][0] = 1;

    for(int i = 1; i < m; ++i) 
        for(int j = 0; j <= n; ++j) {
            for(int here = 0; here <= min(j, sizes[i]); ++here) {
                M[i][j] += ((1LL * M[i - 1][j - here]) * (dp[sizes[i] - 1][here][0] + dp[sizes[i] - 1][here][1]) % MOD) % MOD;
                M[i][j] %= MOD;
            }
        }
    
    vector<int> fact(n + 1, 1);
    for(int i = 1; i <= n; ++i)
        fact[i] = 1LL * fact[i - 1] * i % MOD;
    
    int sign = 1;
    int ans = 0;

    for(int i = 0; i <= n; ++i) {
        ans += 1LL * M[m - 1][i] * fact[n - i] * sign % MOD;
        if(ans < 0)
            ans += MOD;
        ans %= MOD;
        sign *= -1;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 62976
// ------------------------------------
// Date:2018/ 2/25
// Problem:ABC 049 DayDream c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int main()
{
  string inputStr,tmp,tmp2;
  // state 0: ,1:dream, 2:erase, 3:e, 4:r
  int state = 0;
  bool output = true;
  
  cin >> inputStr;
  REP(num, inputStr.size()) {
    switch(state) {
      case 0:
        tmp = inputStr.substr(num,5);
        if (tmp == "dream") {
          state = 1;
        } else if (tmp == "erase") {
          state = 2;
        } else {
          output = false;
        }
        num += 4;
        break;
        // dream
      case 1:
        tmp = inputStr.substr(num,5);
        if (tmp == "dream") {
          num += 4;
        } else if (tmp == "erase") {
          state = 2;
          num += 4;
        } else if (tmp[0] == 'e') {
          state = 3;
        } else {
          output = false;
        }
        break;
        // erase
      case 2:
        tmp = inputStr.substr(num,5);
        if (tmp == "dream") {
          state = 1;
          num += 4;
        } else if (tmp == "erase") {
          num += 4;
        } else if (tmp[0] == 'r') {
          state = 4;
        } else {
          output = false;
        }
        break;
        // e
      case 3:
        if (inputStr[num] == 'r') {
          state = 4;
        } else {
          output = false;
        }
        break;
        // r
      case 4:
        tmp = inputStr.substr(num,5);
        tmp2 = inputStr.substr(num,3);
        if (tmp == "dream") {
          state = 1;
        } else if (tmp == "erase") {
          state = 2;
        } else if (tmp2 == "ase") {
          state = 2;
          num -= 2;
        } else {
          output = false;
        }
        num += 4;
        break;
    }
    /*
    debug(num);
    cout << state << endl;
     */
  }
  if (state == 3) output = false;
  cout << (output?"YES":"NO") << endl;
  return 0;
}



Measured memory_bytes: 512
#include <cstdio>
#include<iostream>
#include <iomanip>

using namespace std;

int main(void){

	int h,m,s;
	int ok;

	while(1){

		cin>>h>>m>>s;
		if(h==-1&&m==-1&&s==-1) break;
		ok=120*60-(h*60*60+m*60+s);
		cout<<setfill('0')<<setw(2)<<ok/(60*60)<<":"<<setfill('0')<<setw(2)<<ok%(60*60)/60<<":"<<setfill('0')<<setw(2)<<ok%(60*60)%60<<endl;
		cout<<setfill('0')<<setw(2)<<(ok*3)/(60*60)<<":"<<setfill('0')<<setw(2)<<(ok*3)%(60*60)/60<<":"<<setfill('0')<<setw(2)<<(ok*3)%(60*60)%60<<endl;
	}

    return 0;
}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n, i = 1;
  cin >> n;
  while (i * i <= n) {
    i++;
  }
  i--;
  cout << i * i << endl;
  return 0;
}


Measured memory_bytes: 3584
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

int main() {
  int n, m, a, b, i, j, cnt = 0;
  cin >> n >> m;
  vector<int> line(n);
  for (i = 0; i < n; ++i) line[i] = i + 1;
  vector<vector<int>> table(n, vector<int>(n, 0));
  for (i = 0; i < m; ++i) {
    cin >> a >> b;
    table[a - 1][b - 1] = 1;
    table[b - 1][a - 1] = 1;
  }

  do {
    if (line[0] != 1) break;
    for (i = 0; i < n - 1; ++i) {
      if (table[line[i] - 1][line[i + 1] - 1] == 0) break;
      if (table[line[i] - 1][line[i + 1] - 1] == 1) continue;
      if (table[line[i + 1] - 1][line[i] - 1] == 1) continue;
    }
    if (i == n - 1) cnt++;
  } while (next_permutation(line.begin(), line.end()));

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	int k;
	cin>>k;
	while(k--)a[2]*=2;
	cout<<a[0]+a[1]+a[2]<<endl;
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	int cntA = 0;
	int cntB = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') cntA++;
		if (s[i] == '1') cntB++;
	}
	int ans = min(cntA, cntB) * 2;
	cout << ans << endl;
	return 0;
}


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

int main()
{
  cin>>S;
  if(S[2]==S[3]&&S[4]==S[5]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int a, b, c, d;
  string A, B, C, D;
  cin >> a;
  vector<int> x(a);
  vector<int> y;
  vector<int> z;
  vector<int> w;
  vector<string> X;
  vector<string> Y;
  vector<string> Z;
  vector<string> W;
  rep(i, a) cin >> x[i];

  int ans = 0;
  //string ans = "Yes";
  //string ans = "No";
  //string ans = "YES";
  //string ans = "NO";
  int cnt = 0;
  rep(i, a - 1){
    if (x[i] >= x[i + 1]) cnt++;
    else cnt = 0;
    ans = max(cnt, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
int main(void)
{
    sync;
    int n,x,t;
    cin>>n>>x>>t;
    cout<<(ll)ceil(1.0*n/x)*t<<endl;
    return 0;
}

Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n)
    {
        if(n%10==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        else
        {
            n/=10;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void) {
	int a;
	int h=0,m=0,s=0;
	scanf("%d",&a);
	while(a>=3600) a-=3600,h++;
	while(a>=60) a-=60,m++;
	s=a;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 592
#include <iostream>

using namespace std;

int main() {
  int n, m, c, b[20];
  cin >> n >> m >> c;
  for (int i = 0; i < m; ++i) cin >> b[i];
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int sum = c;
    for (int j = 0; j < m; ++j) {
      int a;
      cin >> a;
      sum += b[j] * a;
    }
    if (sum > 0) cnt++;
  }
  cout << cnt << endl;
}


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

int main() {
    int n, m;
    int A[100][100], B[100];
    int x,y;
    int c;

    cin >> n >> m;
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++) {
            cin >> x;
            A[i][j] = x;
        }
    }
    
    for (int j = 0; j < m; j++) {
        cin >> y;
        B[j] = y;
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++) {
            c += A[i][j] * B[j];
        }
        cout << c << endl;
        c = 0;
    }
    return 0;
}


Measured memory_bytes: 3112
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	ss := make([]int, n)

	for i := 0; i < n; i++ {
		ss[i] = getNextInt(scanner)
	}

	dp := make([]int, 10001)
	dp[0] = 1
	for i := 0; i < n; i++ {
		for j := 10001 - 1; j-ss[i] >= 0; j-- {
			if dp[j-ss[i]] == 0 {
				continue
			}
			dp[j] = dp[j-ss[i]]
		}
	}

	ans := 0
	for i := 10001 - 1; i >= 0; i-- {
		if i%10 == 0 {
			continue
		}
		if dp[i] > 0 {
			ans = i
			break
		}
	}
	fmt.Println(ans)
	writer.Flush()
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define prin(a) cout<<(a)<<endl
using ll=int64_t;
using namespace std;

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    int a,b;
    cin>>a>>b;
    if(a>9 || b>9){
        cout<<-1<<endl;
        return 0;
    }
    cout<<(a*b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int MAX=100;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int INF=1<<21;

int n;
int A[MAX][MAX];

int prim(){
  int i,color[MAX],d[MAX],p[MAX],mincost,k,sum;
  for(i=0;i<n;i++){
    color[i]=WHITE;
    d[i]=INF;
  }
  d[0]=0;
  p[0]=-1;

  while(1){
    mincost=INF;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	k=i;
      }
    }
    if(mincost==INF) break;
    color[k]=BLACK;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && A[k][i]!=INF){
	if(A[k][i]<d[i]){
	  d[i]=A[k][i];
	  p[i]=k;
	  color[i]=GRAY;
	}
      }
    }
  }
  sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1){
      sum+=A[i][p[i]];
    }
  }
  return sum;
}

int main(){
  int i,j,a;
  cin>>n;

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      cin>>a;
      if(a!=-1){
	A[i][j]=a;
      }
      else A[i][j]=INF;
    }
  }

  cout<<prim()<<endl;

  return 0;
}

	
      

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

int main(){
  double a , b;
  double x;
  int y;
  
  cin >> a >> b;
  x = ( a + b ) / 2;
  y = x;
  
  if (x != y){
    x += 0.5; 
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;
const int INF=1e9;

string comp(string s,string t){
  if(s.size()>t.size())return s;
  if(s.size()<t.size())return t;

  for(int i=0;i<s.size();i++){
    if(s[i]>t[i])return s;
    if(s[i]<t[i])return t;
  }
  return s;
}

signed main(){
  int n,m;
  cin>>n>>m;
  vector<int> cu(10,0);
  int cst[]={0,2,5,5,4,5,6,3,7,6};
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    cu[a]++;
  }

  vector<string> dp(n+11,"");
  for(int i=1;i<10;i++){
    char a='0'+i;
    if(cu[i]==1)dp[cst[i]]=a;
  }

  for(int i=0;i<n;i++){
    for(int j=1;j<10;j++){
      char x='0'+j;
      if(cu[j]==1&&dp[i]!="")dp[i+cst[j]]=comp(dp[i+cst[j]],dp[i]+x);
    }
  }
  cout<<dp[n]<<endl;
}


Measured memory_bytes: 43776
n, c, k = gets().split.map(&:to_i)
t = []
n.times {
  t << gets.to_i
}

t.sort!

res = 1
j = 0

n.times {|i|
  if i >= j + c || t[i] > t[j] + k
    res += 1
    j = i
  end
}

puts res


Measured memory_bytes: 4016
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int[] num1 = new int[100];
        int[] num2 = new int[100];
        while(true){
            int n = sc.nextInt();
            int r = sc.nextInt();
            if(n==0&&r==0) break;
            for(int i=0;i<n;i++){
                num1[i] = n-i;
            }
            for(int x=0;x<r;x++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                for(int j=0;j<p-1;j++){
                    num2[j] = num1[j];
                }
                for(int k=0;k<c;k++){
                    num1[k] = num1[k+p-1];
                }
                for(int m=c;m<c+p-1;m++){
                    num1[m] = num2[m-c];
                }
            }
            System.out.println(num1[0]);    
        }
    }
}


Measured memory_bytes: 36808
n,W = map(int,input().split())
v = [];w = []
for j in range(n):
    a,b = map(int,input().split())
    v.append(a);w.append(b)

dp = [[0 for _ in range(W+1)] for _ in range(n+1)]

for i in range(n):
    for j in range(W+1):
        if j < w[i]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i][j])
print(dp[-1][-1])
#print(dp)



Measured memory_bytes: 42296
while 1:
	N,Q = map(int,raw_input().split())
	if N == 0: break
	C = [0]*100
	for _ in range(N):
		D = map(int,raw_input().split())
		for i in D[1:]:
			C[i] += 1
	print C.index(max(C)) if max(C) >= Q else 0

Measured memory_bytes: 4208
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let a: Vec<i32> = s.take(n).map(|a| a.parse().unwrap()).collect();
	let mut b = a.clone();
	b.sort();
	b.dedup();
	let mut bit = BIT::new(b.len());
	let mut ans = 0;
	for a in a.iter() {
		let i = b.binary_search(a).unwrap();
		let s = bit.sum(i);
		if s > 0 {
			let j = bit.lower_bound(&s);
			bit.add(j, -1);
		} else {
			ans += 1;
		}
		bit.add(i, 1);
	}
	println!("{}", ans);
}

pub struct BIT<T> {
	data: Vec<T>,
}

impl<T> BIT<T>
where
	T: Clone + Default + std::ops::Add<Output = T>,
{
	pub fn new(n: usize) -> Self {
		Self {
			data: vec![T::default(); n],
		}
	}

	pub fn construct(a: Vec<T>) -> Self {
		let mut a = a;
		for i in 0..a.len() {
			if i | (i + 1) >= a.len() {
				continue;
			}
			let v = a[i].clone();
			a[i | (i + 1)] = a[i | (i + 1)].clone() + v;
		}
		Self { data: a }
	}

	pub fn sum(&self, i: usize) -> T {
		let mut r = T::default();
		let mut i = i;
		while i > 0 {
			r = r + self.data[i - 1].clone();
			i &= i - 1;
		}
		r
	}

	pub fn add(&mut self, i: usize, value: T) {
		let mut i = i;
		while i < self.data.len() {
			self.data[i] = self.data[i].clone() + value.clone();
			i |= i + 1;
		}
	}

	pub fn lower_bound(&self, value: &T) -> usize
	where
		T: Ord + std::ops::Add<Output = T>,
	{
		let mut s = T::default();
		let msb = 8 * std::mem::size_of::<usize>() - self.data.len().leading_zeros() as usize;
		let mut len = 1 << msb;
		let mut l = 0;
		while len > 0 {
			if let Some(a) = self.data.get(l + len - 1) {
				let t = s.clone() + a.clone();
				match t.cmp(&value) {
					std::cmp::Ordering::Less => {
						l += len;
						s = t;
					}
					_ => (),
				}
			}
			len >>= 1;
		}
		l
	}
}


Measured memory_bytes: 4184
N = int(input())
L = []
from bisect import bisect_right
for _ in range(N):
    u = -int(input())
    index = bisect_right(L,u)
#    print(index)
    if index == len(L):
        L.append(u)
    else:
        L[index ] = u
print(len(L))


Measured memory_bytes: 7072
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll Ab(ll x){
    if(x>=0)return x;
    else return -x;
}

int main(void){
    ll n,q;
    cin>>n;
    vector<ll>s(n);
    for(ll i=0;i<n;i++)cin>>s[i];
    cin>>q;
    vector<ll>t(q);
    for(ll i=0;i<q;i++)cin>>t[i];
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    int ans = 0;
    set<ll>st;
    for(ll i=0;i<n;i++){
        auto itr = lower_bound(t.begin(),t.end(),s[i]);
        if(itr == t.end())continue;
        else{
            if((*itr)==s[i])st.insert(s[i]);
        }
    }
    cout<<(int)st.size()<<endl;
    return 0;
}


Measured memory_bytes: 3812
module Mod = struct
  module type S = sig val modulo : int end
  module Make (S : S) = struct open S
    let modulo = modulo
    let (+^) a b = (a + b) mod modulo
    let (-^) a b = (a - b + modulo) mod modulo
    let ( *^ ) a b = (a * b) mod modulo
    let rec ( **^ ) a n =
      if n = 0 then 1
      else if n mod 2 = 1 then a *^ a **^ (n-1)
      else let t = a **^ (n/2) in t *^ t
    let inv a = a **^ (modulo-2)
    let (/^) a b = a *^ inv b
  end
end
module M = Mod.Make(struct let modulo = 1000000007 end)
open M

let sqrt_floor n =
  let rec f m = if m * m > n then m-1 else f (m+1) in f 1

let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let m = sqrt_floor n in
  let a = Array.init k (fun _ -> Array.make (m+1) 0) in
  let b = Array.init k (fun _ -> Array.make (max m (n/(m+1)+1) + 1) 0) in
  for i = 1 to m do a.(0).(i) <- i done;
  for i = n/(m+1) downto 1 do b.(0).(i) <- b.(0).(i+1) +^ (n / i - n / (i+1)) done;
  for i = 1 to k-1 do
    for j = 1 to m do
      a.(i).(j) <- a.(i).(j-1) +^ a.(i-1).(m) +^ b.(i-1).(j);
    done;
    for j = n/(m+1) downto 1 do
      b.(i).(j) <- b.(i).(j+1) +^ (n / j - n / (j+1)) *^ a.(i-1).(j);
    done;
  done;
  a.(k-1).(m) +^ b.(k-1).(1) |> Printf.printf "%d\n"


Measured memory_bytes: 50684
#define Z(V) for(v=360,m=g();--m;V+=sin(x*z))v-=x=g();V+=sin(v*z)
a;g(){scanf("%d",&a);a?a:exit(0);}main(m,v,x){for(;;){double s=0,t=0,z=.0174533,e=.000001;Z(s);Z(t);puts(s>t+e?"1":s+e<t?"2":"0");}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prarr(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 1e16+10;
const int MOD = 1e9+7;
const int MAXN = 2e5+10;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int a[100];
    int b[100];
    int c[100];
    int tmp;
    rep(i,n) cin>>a[i];
    ll ans = 0;
    rep(i,n)
    {
    	cin>>b[i];
    	ans+=tmp;
    }	
    rep(i,n-1)
    {
    	cin>>c[i];
    	ans+=tmp;
    }
    ans = 0;
    a[n]=0;
    rep(i,n)
    {
    	ans+=b[a[i]-1];
    	if(a[i]==a[i+1]-1)
    		ans+=c[a[i]-1];
    }
    cout<<ans<<endl;
    return 0;

}
    

Measured memory_bytes: 256
N = int(input())
ls = list(map(int, input().split()))
o = max(ls)
p = min(ls)

#if ((o == p) and (N >= 2 * o)):
if (o == p):
    if (o == (N - 1) or (N >= 2 * o)):
        print('Yes')
    else:
        print('No')
elif ((o - p) == 1):
    u = len([ x for x in ls if x == p])
    if ((o - u) > 0 and 2 * (o - u) <= (N - u)):
        print('Yes')
    else:
        print('No')
else:
    print('No')


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

template <class T> void readPoint(vector< vector<T> >& vec, int idx) {
    T x, y;
    vector<T> point(2);
    std::cin >> x >> y;
    point[0] = x;
    point[1] = y;
    vec[idx] = point;
}
int main()
{
    int size;
    cin >> size;
    vector< vector<int> > points(size);
    //vector<int> y(size);
    for (int i = 0; i < size; i++) {
        readPoint(points, i);
        //readVal(y, i);
    }
    int ans(1), dir(0), vecx(0), vecy(0), new_vecx(0), new_vecy(0);
    for (int i = 0; i <= size; i++) {
        new_vecx = points[(i + 1) % size][0] - points[i % size][0];
        new_vecy = points[(i + 1) % size][1] - points[i % size][1];
        int cross_prod = (vecx * new_vecy - vecy * new_vecx);
        if (cross_prod != 0) {
            if (cross_prod * dir >= 0) {
                dir = cross_prod > 0 ? 1 : -1;
            }
            else {
                ans = 0;
                break;
            }
        }
        vecx = new_vecx;
        vecy = new_vecy;
    }
    cout << ans << "\n";
    return 0;
}



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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007 , inf = 0x3f3f3f3f;

struct netflow
{
	static const int _n = _ + _ , _e = 9999999;

	int to[_e],ne[_e],he[_n],ecnt,ev[_e];
	inline void adde(int a,int b,int c){to[++ecnt]=b,ev[ecnt]=c,ne[ecnt]=he[a],he[a]=ecnt;}
	inline void addde(int a,int b,int c){adde(a,b,c),adde(b,a,0);}

	int dcnt,S,T,dis[_n],gap[_n];

	inline int bfs()
	{
		memset(dis,-1,sizeof(int)*(dcnt+2));
		queue<int> q;
		q.emplace(T),dis[T]=0;
		while(!q.empty())
		{
			int a=q.front();q.pop();
			for(int i=he[a];i;i=ne[i])
			{
				if(!ev[i^1])continue;
				int b=to[i];
				if(dis[b]<0)dis[b]=dis[a]+1,q.emplace(b);
			}
		}
		if(dis[S]<0)return 0;
		memset(gap,0,sizeof(int)*(dcnt+2));
		for(int i=1;i<=dcnt;i++)gap[dis[i]]++;
		return 1;
	}
	
	int dfs(int x,int f)
	{
		if(x==T || !f)return f;
		int mid=dcnt;
		int r=f;
		for(int &i=he[x];i;i=ne[i])
		{
			if(ev[i]<=0)continue;
			int b=to[i];
			if(dis[x]==dis[b]+1)
			{
				int g=dfs(b,min(r,ev[i]));
				r-=g,ev[i]-=g,ev[i^1]+=g;
				if(dis[S]>=dcnt)return f-r;
				if(!r)break;
			}
			mid=min(mid,dis[b]);
		}
		if(f==r){if(--gap[dis[x]]==0)dis[S]=dcnt;dis[x]=mid+1,gap[dis[x]]++;}
		return f-r;
	}
	
	int heBuf[_n];

	inline int run(int s,int t)
	{
		S=s,T=t;
		memset(dis,0,sizeof(int)*(dcnt+2));
		memset(gap,0,sizeof(int)*(dcnt+2));
		gap[0]=dcnt;
		memcpy(heBuf,he,sizeof(int)*(dcnt+2));

		int sflw=0;
		while(memcpy(he,heBuf,sizeof(int)*(dcnt+2)),bfs())sflw+=dfs(S,inf);
		return sflw;
	}
	
	netflow()
	{
		memset(he,0,sizeof(he)),ecnt=1;
	}
}f;

int n,ta[_],tb[_],xa[_]={0},xac=0,xb[_]={0},xbc=0;

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)ta[i]=ty()+1;
	for(int i=1;i<=n;i++)tb[i]=ty()+1;

	for(int i=1;i<=n;i++)if(!xa[i]){xa[i]=++xac;for(int j=ta[i];!xa[j];j=ta[j])xa[j]=xac;}
	for(int i=1;i<=n;i++)if(!xb[i]){xb[i]=++xbc;for(int j=tb[i];!xb[j];j=tb[j])xb[j]=xbc;}
	
	f.dcnt=xac+xbc;
	int s=++f.dcnt,t=++f.dcnt;
	
	int ans=n;
	for(int i=1;i<=n;i++)
	{
		if(ta[i]==i && tb[i]==i){ans--;continue;}
		if(ta[i]==i)f.addde(s,xac+xb[i],1);
		else if(tb[i]==i)f.addde(xa[i],t,1);
		else{f.addde(xa[i],xac+xb[i],1);if(ta[i]==tb[i])f.addde(xac+xb[i],xa[i],1);}
	}
	ans-=f.run(s,t),printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 16896
def get_num(n, x):
    ans = 0
    for n3 in xrange(min(n, x - 3), (x + 2) / 3, -1):
        for n2 in xrange(min(n3 - 1, x - n3 - 1), (x - n3) / 2, -1):
            # if n3-1 > x-n3-1:
            #     # print("fizz")
            #     pass
            # else:
            #     print("buzz")
            if n3 + min(n2 - 1, x - n3 - n2):
                ans += 1
    return ans


data = []
while True:
    [n, x] = [int(m) for m in raw_input().split()]
    if [n, x] == [0, 0]:
        break
    if x < 3:
        print(0)
    else:
        print(get_num(n, x))

Measured memory_bytes: 6304
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int NUM = 2e5 + 5;
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        int n; cin>>n;
        vector<ll> a(n);
        for(auto &i:a) cin>>i;
        ll sm = 0;
        for(auto x:a) sm+=x;
        vector<ll> x;
        ll x1 = sm;
        for(int i=1;i<n;i+=2) x1-=2*a[i];
        x.pb(x1);
        ll x2 = 2*a[0]-x1;
        x.pb(x2);
        for(int i=1;i<n-1;i++){
            ll new_x = 2*a[i]-x2;
            x2 = new_x;
            x.pb(new_x);
        }
        for(auto y:x) cout<<y<<" ";
    }   
}


Measured memory_bytes: 3060
import itertools as it

n, m = map(int, input().split())
a = list(list(map(int, input().split())) for _ in range(m))

#print(a)

#無向グラフのルート作成（リスト）
for i in range(len(a)):
    a.append([a[i][1],a[i][0]])
#print(a)


#１を始点とするルートを全探索で作成
lis  = list(it.permutations(range(2, n + 1)))
#print(lis)
for i in range(len(lis)):
    lis[i] = (1,) + lis[i]
#print(lis)

#リストに変換
lis2 = []
for i in range(len(lis)):
    lis[i] = list(lis[i])
    lis2.append(lis[i])
#print(lis2)

#ルート探索
#lis3 = []
ans = 0
for i in range(len(lis2)):
    check = True
    for j in range(len(lis2[i]) - 1):
        if lis2[i][j : j + 2] not in a:
            check = False
    if check:
        ans += 1
print(ans)


Measured memory_bytes: 10172
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var n, k int
	fmt.Fscan(read, &n, &k)

	cnt := 0
	for n > 0 {
		cnt++
		n /= k
	}
	fmt.Fprintln(write, cnt)
}


Measured memory_bytes: 640
n=int(input())
r = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(n)]

from operator import itemgetter
r = sorted(r, key=itemgetter(1),reverse=1)
b = sorted(b)

x=0
y=[200,200]
z=[0,0]

for i in range(n):
    for j in range(n):
        if b[i][0] > r[j][0] and b[i][1] > r[j][1]:
            x+=1
            r[j] = y
            b[i] = z
            break

print(x)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n, k; cin >> n >> k;
    ll ans = ll(n/k) * (n/k) * (n/k);
    if(!(k%2)){
        ll dif = (n + k/2)/k;
        ans += dif * dif * dif;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <queue>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[200005], b[200005];
priority_queue<P> Q;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	
	for(int i = 0; i < n; i++){
		Q.push(make_pair(b[i], i));
	}
	
	llint ans = 0;
	while(Q.size()){
		llint id = Q.top().second;
		//cout << id << endl;
		//for(int i = 0; i < n; i++) cout << b[i] << " "; cout << endl;
		Q.pop();
		if(b[id] == a[id]) continue;
		if(b[id] < a[id]){
			cout << -1 << endl;
			return 0;
		}
		llint d = b[(id+1)%n] + b[(id-1+n)%n], m = max(a[id], max(b[(id+1)%n], b[(id-1+n)%n]));
		llint c = (b[id]-m+d-1) / d;
		ans += c;
		b[id] -= c*d;
		Q.push(make_pair(b[id], id));
		
		if(b[id] == a[id]) continue;
		if(b[id] < a[id]){
			cout << -1 << endl;
			return 0;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 9456
import java.util.*;

class Main {
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
ArrayList<Integer> li = new ArrayList<>();
li.add(sc.nextInt());
li.add(sc.nextInt()); 
li.add(sc.nextInt());
Collections.sort(li);
if(li.get(2) == li.get(0) + li.get(1)){
System.out.println("Yes");
 }else{
System.out.println("No");
}

}
}

Measured memory_bytes: 21716
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define inf 0x3f3f3f3f

using namespace std;

struct Data {
  int l,r,id;
  Data() {}
  Data(int a,int b,int c):l(a),r(b),id(c) {}
  bool operator < (const Data & b) const {return l<b.l;}
};

Data a[2005];
int maxn[2005];

char s1[2005],s2[2005];

inline int dis(int x,int y,int n) {
  int p=abs(x-y);
  return min(p,(n-p)%n);
}

int main() {
  scanf("%s%s",s1,s2);
  int n=strlen(s1);
  bool ok1=0,ok2=0;
  for(int i=0;i<n;i++) {
  	if (s1[i]=='1') ok1=1;
  	if (s2[i]=='1') ok2=1;
  }
  if (!ok2) {
  	puts((ok1)?"-1":"0");
  	return 0;
  }
  int p=0;
  while (s2[(0-p+n)%n]!='1') p++;
  a[0].l=p;
  for(int i=1;i<n;i++) {
  	if (s2[i]=='1') p=0; else p++;
  	a[i].l=p;
  }
  p=0;
  while (s2[(n-1+p)%n]!='1') p++;
  a[n-1].r=p;
  for(int i=n-2;i>=0;i--) {
  	if (s2[i]=='1') p=0; else p++;
  	a[i].r=p;
  }
  for(int i=0;i<n;i++) a[i].id=i;
  sort(a,a+n);
  int ans=inf;
  for(int i=0;i<n;i++) {
  	int v1=i,v2=(n-i)%n,cnt=0;
  	for(int j=n-1;j>=0;j--) {
  		maxn[j]=maxn[j+1];
  		if (s1[a[j].id]!=s2[(a[j].id-i+n)%n]) {
		  maxn[j]=max(maxn[j],a[j].r);
		  cnt++;
	    }
	  }
	int p=0,q=maxn[0];
	ans=min(ans,cnt+p+dis(p,v1,n)+2*q);
	ans=min(ans,cnt+q+dis(q,v2,n)+2*p);
	for(int j=0;j<n;j++) {
		if (s1[a[j].id]!=s2[(a[j].id-i+n)%n]) p=max(p,a[j].l);
		q=maxn[j+1];
		ans=min(ans,cnt+p+dis(p,v1,n)+2*q);
		ans=min(ans,cnt+q+dis(q,v2,n)+2*p);
	}
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256