akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter

val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, t) = listOfInt()
    val tt = listOfLong()

    var sum = 0L
    for (i in 0 until n) {
        if (i == 0) {
            sum += t
            continue
        }

        val diff = tt[i] - tt[i-1]
        if (diff < t) {
            sum += diff
        } else {
            sum += t
        }
    }

    println(sum)
}

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

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 81048
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#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 ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  int n; cin >> n;
  for(int i = 1; i <= 9; i++) {
   for(int j = 1; j <= 9; j++) {
    if(i * j == n) {
     cout << "Yes" << endl;
     return 0;
    }
   }
  }
 cout << "No" << endl; 
  return 0;
}


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

using namespace std;

typedef long long ll;

bool check[10005];
int prime[10005],tot;

void pre(int n) {
  for(int i=2;i<=n;i++) {
  	if (!check[i]) prime[++tot]=i;
  	for(int j=1;j<=tot&&i*prime[j]<=n;j++) {
  		check[i*prime[j]]=n;
  		if (i%prime[j]==0) break;
	  }
  }
}

map <int,bool> mp;

void calcgcd(int n) {
  int t=n;
  for(int i=2;i*i<=t;i++)
    if (n%i==0) {
    	mp[i]=1;
    	while (n%i==0) n/=i;
	}
  if (n>1) mp[n]=1;
}

int num[10005],val[10005];

bool checkval(int n,int x,int mod) {
  int s=0;
  for(int i=n;i>=0;i--) s=(s*x+num[i])%mod;
  return s==0;
} 

int main() {
  srand(19260817);
  int n;
  scanf("%d",&n);
  pre(n+1);
  for(int i=n;i>=0;i--) scanf("%d",&num[i]);
  int d=0;
  for(int i=0;i<=n;i++) d=__gcd(d,abs(num[i]));
  calcgcd(d);
  ll s=0;
  for(int i=0;i<=n;i++) s+=num[i];
  for(int i=1;i<=tot;i++) {
  	int p=prime[i];
    if (num[0]%p==0&&s%p==0) {
    	bool ok=1;
    	for(int j=0;j<p;j++) val[j]=j;
    	random_shuffle(val,val+p);
    	for(int j=0;j<p;j++)
    	  if (!checkval(n,j,p)) {
    	  	ok=0;
    	  	break;
		  }
		if (ok) mp[p]=1;
	}
  }
  for(map<int,bool>::iterator it=mp.begin();it!=mp.end();it++)
    printf("%d\n",it->first);
  return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N = Integer.parseInt(sc.next());
      int[] d = new int[N];
      for (int i = 0; i < N; ++i) {
        d[i] = Integer.parseInt(sc.next());
      }
      
      int result = 0;
      for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
          result += d[i] * d[j];
        }
      }
      
      
      System.out.println(result);
    }

}

Measured memory_bytes: 23892
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            long kcookie = sc.nextLong();
            long acookie = sc.nextLong();
            long count = sc.nextLong();

            long ans1 = Math.max(0, kcookie - count);
            long ans2 = Math.max(0, Math.min(kcookie+acookie-count,acookie));
            System.out.println(ans1 + " " + ans2);
            }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    string s; cin >> s;
    if(s[0] == 'Y'
    && s[1] == 'A'
    && s[2] == 'K'
    && s[3] == 'I'){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
D = int(input())
C = [0] + list(map(int, input().split())) # type_iのvの下がりやすさ = C[i]
S = [0] + [[0] + list(map(int, input().split())) for _ in range(D)]

T = [0] + [int(input()) for _ in range(D)]
last = [0] + [0 for _ in range(26)]

v = 0 # 現在の満足度
for d in range(1, 1+D): # d = 1, 2, ..., Dについて
    v += S[d][T[d]] # s_di満足度が増える
    last[T[d]] = d # type_T[d]を開催した最後の日をdに設定
    # 満足度現象の計算
    for i in range(1, 27): # type1～27まで
        v -= C[i] * (d - last[i])
    print(v)

Measured memory_bytes: 9288
<?php
//https://stackoverflow.com/questions/5506888/permutations-all-possible-sets-of-numbers

function pc_permute($items, $perms = array( )) {
    if (empty($items)) {
        // もう取り出すものがなければその時点の$permsが順列の一つなのでそのまま返却 
        $return = array($perms);
    } else {
        $return = array();
        // 並んでる数字を順番にみてく
        for ($i =  0; $i < count($items); $i++) {
            // 処理対象の配列と、組み合わせを保持してる変数を別変数にコピー
            // array_spliceなどは破壊的なメソッドなので退避しないと元配列が変更される
            $newitems = $items;
            $newperms = $perms;
            // インデックスが$iの値を$fooにとる。($newitemsからは削除される)
            list($foo) = array_splice($newitems, $i, 1);
            // 取り除いた値（$foo)を組み合わせの候補の先頭に持ってくる
            array_unshift($newperms, $foo);
            // 最終的に呼び出し元に返却する配列に追加する
            // 追加する配列は、一文字削ったあとの$newitems,
            // 現段階での組み合わせの$newpermsを引数に、再帰的に自分を呼び出した結果
            $return = array_merge($return, pc_permute($newitems, $newperms));
        }
    }
    return $return;
}

// ----------------------------------------------------
// こっから実際に解く
// ----------------------------------------------------

// 入力値の取得（int変換)
$N = intval(trim(fgets(STDIN)));
// 入力値の取得（配列化）
$P = explode(" ",trim(fgets(STDIN)));
$Q = explode(" ",trim(fgets(STDIN)));

// 順列の生成
$a = range(1,$N);
$permutated = pc_permute($a);
sort($permutated);

$p_index = -1;
$q_index = -1;

// 列挙した順列をfor文で確認していき、PとQの位置を確認する
for ($i=0; $i < count($permutated); $i++){
  if ($permutated[$i] == $P){
    $p_index = $i;
  }
  if ($permutated[$i] == $Q){
    $q_index = $i;
  }
}

// 答えの計算
$ans = abs($p_index - $q_index);
printf("%d\n",$ans);


Measured memory_bytes: 23416
#include<bits/stdc++.h>
using namespace std;
const double EPS=1E-8;
typedef vector<double> vec;
typedef vector<vec> mat;
vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      B[i][j]=A[i][j];
  for(int i=0;i<n;i++) B[i][n]=b[i];
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)
      if(abs(B[j][i])>abs(B[pivot][i])) pivot=j;
    swap(B[i],B[pivot]);
    if(abs(B[i][i])<EPS) return vec();
    for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
    for(int j=0;j<n;j++){
      if(i!=j){
	for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
      }
    }
  }
  vec x(n);
  for(int i=0;i<n;i++) x[i]=B[i][n];
  return x;
}
int main(){
  int d;
  while(cin>>d,d){
    vec v(d+3);
    for(int i=0;i<d+3;i++) cin>>v[i];
    int ans=0;
    mat m(d+3,vec(d+2));
    for(int i=0;i<d+3;i++)
      for(int j=0;j<d+1;j++)
	m[i][j]=pow(1.0*i,j);
    for(int i=0;i<d+3;i++){
      for(int j=i+1;j<d+3;j++){
	vec b(d+1);
	mat A(d+1,vec(d+1));
	for(int k=0,l=0;k<d+3;k++)
	  if(i!=k&&j!=k) A[l]=m[k],b[l]=v[k],l++;
	vec x=gauss_jordan(A,b);
	double res[2]={};
	for(int k=0;k<d+1;k++){
	  res[0]+=x[k]*m[i][k];
	  res[1]+=x[k]*m[j][k];
	}
	//cout<<res[0]<<" "<<v[i]<<endl;
	//cout<<res[1]<<" "<<v[j]<<endl;
	if(abs(res[0]-v[i])+1e-5>1.0&&abs(res[1]-v[j])<1e-5) ans=i;
	if(abs(res[0]-v[i])<1e-5&&abs(res[1]-v[j])+1e-5>1.0) ans=j;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int s[200005];
ll ans[200005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",s+i);
	}
	ll ans=0,cnt=0;
	for(int i=2;i<=n;i++){
		if(s[i]>=i || s[i]>s[i-1]+1){
			cout<<-1;
			return 0;
		}
		if(s[i]==s[i-1]+1) ans++;
		else{
			ans+=s[i];
		}		
	}
	if(s[1]){ans=-1;}
	cout<<ans;
	return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: code-festival-2017-qual-a_c / Link: https://code-festival-2017-quala.contest.atcoder.jp/tasks/code_festival_2017_quala_c?lang=en  ----- */
/* ------問題------

縦 H 行、横 W 列の行列 A があります。 上から i 行目、左から j 列目の要素を aij とします。 各 aij は英小文字です。
すぬけ君は、A の要素を自由に並べ替え、縦 H 行、横 W 列の行列 A' を作ろうとしています。 このとき、次の条件が成り立つようにします。
A' のどの行およびどの列もそれぞれ回文になっている。
条件を満たす A' が存在するか判定してください。

-----問題ここまで----- */
/* -----解説等-----

対象になるためには4点対称な場所に置けば良い。
残りを考えると、H,Wのどちらかが奇数だと2個対、全部奇数で1点のみ1個だけをおける。
これを実際に確かめる。

----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	int H, W;
	cin >> H >> W;
	VS s(H);
	FOR(i, 0, H) {
		cin >> s[i];
	}
	VI a(26, 0);
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			a[s[i][j] - 'a']++;
		}
	}
	ans = 1;
	int c1 = 0, c2 = 0;
	FOR(i, 0, 26) {
		if (a[i] % 4 == 2)c2++;
		if (a[i] % 2 == 1)c1++;
	}
	if (c1 > 1)ans = 0;
	if (c1 && ((H % 2 == 0) || (W % 2 == 0)))ans = 0;
	if (H % 2 == 1)c2 -= W / 2;
	if (W % 2 == 1)c2 -= H / 2;
	if (c2 > 0)ans = 0;

	cout << (ans ? "Yes" : "No") << "\n";

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)



int main(){
    int n;
    cin>>n;
    
    int c=0;
    for(int i=1;;i++){
        c+=i;
        if(c>=n){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>

int f(int n)
{
    if(n%2==0) return n/2;
    else return 3*n+1;
}

int main()
{
    // std::cout << std::fixed << std::setprecision(5);
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(m, 0);
    for(int i=0; i<n; i++)
    {
        int k;
        std::cin >> k;
        for(int i=0; i<k; i++)
        {
            int temp;
            std::cin >> temp;
            a[temp-1]++;
        }
    }
    int cnt=0;
    for(auto i : a)
    {
        if(i==n) cnt++;
    }
    std::cout << cnt << std::endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

const initBufSize, maxBufSize = 10000, 1000000

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = nextInt()
	}
	return res
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(r, n int) int {
	return int(math.Pow(float64(r), float64(n)))
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initBufSize), maxBufSize)
	x := nextInt()
	var deposit int
	var interest float64
	deposit = 100
	count := 0
	for {
		count++
		interest = float64(deposit) * 0.01
		deposit += int(interest)
		if deposit >= x {
			break
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)

int main() {
    ll N,K;
    cin >> N >> K;
    ll memo = N / K;
    ll memo1 = N / K;
    memo1++;
    ll memo2 = N / K;
    memo2--;
    ll ans = abs(N-(memo*K));
    ans = min(ans,abs(N - (memo1 * K)));
    ans = min(ans,abs(N - (memo2 * K)));
    ans = min(ans,N);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include <string>
#define loop(i,n) for(int i=0;i<(int)n;i++)

using namespace std;

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

int l;
cin>>l;

string s[n];

loop(i,n) cin>>s[i];

sort(s,s+n);

string ans;

loop(i,n) ans=ans+s[i];
cout<<ans;

}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int maxn = 20;


int n,m,X;
int cost[maxn];
int v[maxn][maxn];
int A[maxn];
int ans = INT_MAX/2;

int32_t main() {
	//FAST
	
	cin >> n >> m >> X;
	for (int i =0;i<n;i++) {
		cin >> cost[i];
		for (int j =0;j<m;j++) {
			cin >> v[i][j];
		}
	}
	
	for (int x=0;x<(1 << n);x++) {
		memset(A,0,sizeof A);
		int total = 0;
		
		for (int i =0;i<n;i++) {
			if ((1 << i) & x) {
				total += cost[i];
				for (int j =0; j<m;j++) {
					A[j] += v[i][j];
				}
			}
		}
		bool fail = false;
		for (int j=0;j<m;j++) {
			if (A[j] < X) fail = true;
		}
		
		if (!fail) ans = min(ans,total);
	}
	if (ans == INT_MAX/2) cout << -1;
	else cout << ans;
}







Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		char b = sc.next().charAt(0);
		int c = sc.nextInt();
		if(b == '+') {
			System.out.println(a+c);
		}
		else {
			System.out.println(a-c);
		}
	}
}

Measured memory_bytes: 35720
#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
int sum;
int main() {
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i],sum^=a[i];
	for(int i=1; i<=n; i++)
		cout<<(sum^a[i])<<" ";
	return 0;
}
//475254

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

int main() {
  int64_t n, a, b;
  std::cin >> n >> a >> b;

  std::vector<int64_t> h(n);

  for (auto &i : h) {
    std::cin >> i;
  }

  std::sort(h.begin(), h.end());
  const auto sum = std::accumulate(h.cbegin(), h.cend(), 0ll);
  std::vector<int64_t> cum(n + 1, 0);

  for (int64_t i = 1; i < n + 1; i++) {
    cum[i] = cum[i - 1] + h[i - 1];
  }

  auto itr = h.cbegin();
  int64_t count = 0;

  while (true) {
    const auto index = std::distance(h.cbegin(), itr);
    const auto p_sum = sum - cum[index]
      - (n - index) * count * b - count * (a - b);
    if (p_sum <= 0) {
      break;
    }
    const auto add = (p_sum - 1) / ((n - index - 1) * b + a) + 1;
    count += add;
    itr = std::upper_bound(itr, h.cend(), count * b);
    if (itr == h.cend()) {
      break;
    }
  }

  const auto judge = [&] (const auto c) {
    auto itr = std::upper_bound(h.cbegin(), h.cend(), c * b);
    auto count = c;
    for (; itr != h.cend(); itr++) {
      count -= (*itr - c * b - 1) / (a - b) + 1;
      if (count < 0) {
        return false;
      }
    }
    return true;
  };

  int64_t start = count, end = count + n;

  if (judge(start)) {
    std::cout << count << std::endl;
    return 0;
  } else {
    while (1 < end - start) {
      const auto next = (start + end) / 2;
      if (judge(next)) {
        end = next;
      } else {
        start = next;
      }
    }
    std::cout << end << std::endl;
    return 0;
  }

  return 0;
}

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

const ll INF = 1LL << 60;

ll N;
vector<ll> A;
int main() {
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    ll max_a = A[N - 1];

    vector<ll> b(N, 1);
    vector<ll> D(max_a + 1, 1);

    map<ll, ll> mp;
    for (int i = 0; i < N; i++) {
        mp[A[i]]++;

        if (mp[A[i]] >= 2) {
            D[A[i]] = 0;
        }
    }

    // 倍数をふるい落す
    for (int i = 0; i < N; i++) {
        if (b[i]) {
            b[i] = 0;
            for (int j = 2 * A[i]; j <= max_a; j += A[i]) {
                D[j] = 0;
            }
        }
    }

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

Measured memory_bytes: 26604
#include <iostream>
#include <array>
#include <algorithm>

auto print = [](auto x){ std::cout << x; };
auto println = [](auto x){ std::cout << x << std::endl; };
auto read = [](){int x; std::cin >> x; return x;};
auto print_dice = [](const std::array<int, 6> & dice){
                    std::for_each(dice.begin(), dice.end(), [](auto x){std::cout << x << " ";});
                    print('\n');
                  };

void roll(std::array<int, 6> & dice, char direction);
void perm(std::array<int, 6> &, std::array<int, 4>);

int main ()
{
  std::array<int, 6> dice;

  for (int i=0; i<6; i++)
    {
      dice.at(i) = read();
    }
  
  std::string directions;
  std::cin >> directions;

  for (char direction : directions)
    {
      roll(dice, direction);
      //print_dice(dice);
    }


  println(dice.at(0));
}

void roll(std::array<int, 6> & dice, char direction)
{
  std::array<int, 4> perm_index;
  switch (direction)
    {
    case 'N':
     perm_index = {0, 1, 5, 4};
      perm(dice, perm_index);
      break;
    case 'E':
      perm_index = {0, 3, 5, 2};
      perm(dice, perm_index);
      break;
    case 'W':
      perm_index = {0, 2, 5, 3};
      perm(dice, perm_index);
      break;
    case 'S':
      perm_index = {0, 4, 5, 1};
      perm(dice, perm_index);
      break;
    }
}

void perm(std::array<int, 6> & dice, std::array<int, 4> perm_index)
{
  auto temp = dice.at(perm_index.at(0));
  for (int i=0; i<3; i++)
    {
      dice.at(perm_index.at(i)) = dice.at(perm_index.at(i+1));
    }
  dice.at(perm_index.at(3)) = temp;
}


Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
using namespace std;
main(){
	int n;
	while(cin>>n,n){
		int c=0;
		unsigned long long k=1;
		for(int i=1;i<=n;++i){
			k*=i;
			while(k%10==0){
				c++;
				k/=10;
			}
			k%=10000000000;
		}
		cout<<c<<endl;
	}
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T>
inline T LCM(T a, T b) { return (a + (b - 1)) / b; }
template<class T>
inline T round_int(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vl a(n), sum(n + 1);
	rep(i, n) cin >> a[i], sum[i + 1] = sum[i] + a[i];

	ll res = INF;
	rep(i, n) {
		int low = 0, high = i;
		while (high - low > 1) {
			int mid = (high + low) / 2;
			if (sum[mid] >= sum[i] - sum[mid]) high = mid;
			else low = mid;
		}

		long long P = sum[low], Q = sum[i] - sum[low]; // 候補1
		long long P2 = sum[high], Q2 = sum[i] - sum[high]; // 候補2
		long long left_min = min(P, Q), left_max = max(P, Q);
		if (abs(P2 - Q2) < abs(P - Q)) left_min = min(P2, Q2), left_max = max(P2, Q2);

		low = i, high = n;
		while (high - low > 1) {
			int mid = (high + low) / 2;
			if (sum[mid] - sum[i] >= sum[n] - sum[mid]) high = mid;
			else low = mid;
		}

		long long R = sum[low] - sum[i], S = sum[n] - sum[low]; // 候補1
		long long R2 = sum[high] - sum[i], S2 = sum[n] - sum[high]; // 候補2
		long long right_min = min(R, S), right_max = max(R, S);
		if (abs(R2 - S2) < abs(R - S)) right_min = min(R2, S2), right_max = max(R2, S2);

		// 真ん中の切れ目が i であるときの暫定解
		long long tmp = max(left_max, right_max) - min(left_min, right_min);
		res = min(res, tmp);
	}
	cout << res << endl;
}

Measured memory_bytes: 3328
h,w,k=map(int,input().split())
c=[]
for i in range(h):
    y=list(input())
    c.append(y)
s=0
for i in range(2**h):
    for j in range(2**w):
        t=0
        for a in range(h):
            for b in range(w):
                if (i//(2**a))%2==1 and (j//(2**b))%2==1 and c[a][b]=="#":
                    t+=1
        if t==k:
            s+=1
print(s)

Measured memory_bytes: 9204
#include<iostream>
using namespace std;
int main() {
	int X, Y;
	cin >> X >> Y;
	if (Y % 2 == 0) {
		if (2 * X <= Y && 4 * X >= Y) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
const int N=1e5+5;///1e18+5

void solve()
{
    int x;
    cin>>x;
    if(x>=400 && x<=599)cout<<8<<endl;
    else if(x>=600 && x<=799)cout<<7<<endl;
    else if(x>=800 && x<=999)cout<<6<<endl;
    else if(x>=1000 && x<=1199)cout<<5<<endl;
    else if(x>=1200 && x<=1399)cout<<4<<endl;
    else if(x>=1400 && x<=1599)cout<<3<<endl;
    else if(x>=1600 && x<=1799)cout<<2<<endl;
    else if(x>=1800 && x<=1999)cout<<1<<endl;
}

int main()
{
   // freopen("input.txt","r",stdin);
    IO;

    int tc=1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}


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

constexpr ll MOD = ll(1e9)+7;

using Matrix = vector<vector<ll> >;

Matrix mul(const Matrix &a, const Matrix &b){
    Matrix c;
    c.resize(a.size());
    for(int i=0;i<a.size();i++){
        c[i].resize(b[0].size());
    }
    for(int i=0;i<a.size();i++){
        for(int k=0;k<a[0].size();k++){
            for(int j=0;j<b[0].size();j++){
                c[i][j] += a[i][k] * b[k][j];
                c[i][j] %= MOD;
            }
        }
    }
    return c;
}

Matrix power(Matrix a, ll k){
    Matrix res;
    res.resize(a.size());
    for(int i=0;i<a.size();i++){
        res[i].resize(a.size());
    }
    for(int i=0;i<a.size();i++){
        res[i][i] = 1;
    }
    while(k > 0){
        if(k&1){
            res = mul(res, a);
        }
        a = mul(a, a);
        k >>= 1;
    }
    return res;
}

int main() {
    ll n, k;
    cin >> n >> k;
    Matrix a, b;
    a.resize(n, vector<ll>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> a[i][j];
        }
    }
    b = power(a, k);
    ll ans = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans += b[i][j];
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=105;
int n,m;
bool e[N][N];
int match[N];
bool vis[N];
bool dfs(int u)
{
	for(int v=1;v<=n;v++)
		if(e[u][v]&&!vis[v])
		{
			vis[v]=1;
			if(!match[v]||dfs(match[v]))
			{
				match[v]=u;
				return true;
			}
		}
	return false;
}
void KM()
{
	memset(match,0,sizeof(match));
	for(int i=1;i<=n;i++)
	{
		memset(vis,false,sizeof(vis));
		dfs(i);
	}
	return;
}
int a[N][N],b[N][N],id[N][N];
bool book[N][N];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&a[i][j]);
			id[i][j]=(a[i][j]-1)/m+1;
		}
	for(int k=1;k<=m;k++)
	{
		memset(e,0,sizeof(e));
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				if(!book[i][j]) e[i][id[i][j]]=1;
		KM();
		for(int j=1;j<=n;j++)
		{
			int u=match[j];
			for(int v=1;v<=m;v++)
				if(!book[u][v]&&id[u][v]==j)
				{
					book[u][v]=true;
					b[u][k]=a[u][v];
					break;
				}
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%d ",b[i][j]);
		printf("\n");
	}
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<j;k++)
				if(b[j][i]<b[k][i]) swap(b[j][i],b[k][i]);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			printf("%d ",b[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 3796
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$a = (int)$input[0];
$b = (int)$input[1];
$k = (int)$input[2];

if ($k - $a > 0) {
	$b = max(0, $b - ($k - $a));
	$a = 0;
}else{
	$a = $a - $k;
}
echo $a . " " . $b;

Measured memory_bytes: 4732
n = int(input())
hli = list(map(int,input().split()))

f_inf = float('inf')
dp = [f_inf] * (10**5+10)

def chooseMin(a,b):
    if(a<b):
        return a
    else:
        return b
# 初期条件
dp[0] = 0
for i in range(1,n):
    dp[i] = chooseMin(dp[i], dp[i-1] + abs(hli[i]-hli[i-1]))
    #一番目の足場ではひとつ前しか存在しない
    if (i>1):
        dp[i]=chooseMin(dp[i], dp[i-2]+abs(hli[i]-hli[i-2]))

print(dp[n-1])


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

int main(){
    int n; cin >> n;
    int d[n];
    for(int i = 0; i < n; i++) cin >> d[i];
    int m; cin >> m;
    int t[m];
    for(int i = 0; i < m; i++) cin >> t[i];
    sort(d,d+n);
    sort(t, t+m);
    int j = 0;
    for(int i = 0; i < m;){
        if(t[i] == d[j]){
            j++; i++;
        }else{
            if(t[i] > d[j]) {j++; continue;}
            cout << "NO" << endl; return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1792
from operator import itemgetter
n, *ABCD = map(int, open(0).read().split())
AB = sorted([(a, b) for a, b in zip(ABCD[:2*n:2], ABCD[1:2*n:2])], key=itemgetter(1))
CD = sorted([(c, d) for c, d in zip(ABCD[2*n::2], ABCD[2*n+1::2])])

for c, d in CD:
    t_AB = [(a, b) for a, b in AB if a < c and b < d]
    if t_AB:
        AB.remove(t_AB[-1])
print(n-len(AB))

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

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct Edge
{
	int s, t, cost;
	Edge(int s,int t,int cost):s(s),t(t),cost(cost){}
	Edge():Edge(-1,-1,-1){}
};

vector<Edge> G[100000];
int d[100000];
int V, E;

void shortest_path(int s)
{
	rep(i, 0, V)d[i] = INF;
	d[s] = 0;

	priority_queue<pii, vector<pii>, greater<pii>> pq;
	pq.push(mp(0, s));

	while (!pq.empty())
	{
		pii p = pq.top(); pq.pop();
		if (d[p.second] < p.first)
		{
			continue;
		}
		for (auto& e : G[p.second])
		{
			if (d[e.t] > d[e.s] + e.cost)
			{
				d[e.t] = d[e.s] + e.cost;
				pq.push(mp(d[e.t], e.t));
			}
		}
	}
}

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

	int start;
	cin >> V >> E >> start;
	rep(i, 0, E)
	{
		int s, t, c;
		cin >> s >> t >> c;
		G[s].push_back(Edge(s, t, c));
		//G[t].push_back(Edge(t, s, c));
	}

	shortest_path(start);

	rep(i, 0, V)
	{
		printf(d[i] == INF ? "INF\n" : "%d\n", d[i]);
	}
	
	return 0;
}


Measured memory_bytes: 15428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dp[4200];
int main() {
	for(ll i=0;i<4200;i++){
		dp[i]=INF;
	}
	dp[0]=0;
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		ll op=0;
		for(ll j=0;j<y;j++){
			ll now;
			cin>>now;
			now--;
			now=pow(2,now);
			op=op|now;
		}
		for(ll j=0;j<4200;j++){
			if(ll(j|op)<4200){
			dp[j|op]=min(dp[j]+x,dp[j|op]);
			}
		}
	}
	ll ans=0;
	for(ll i=0;i<n;i++){
	  ans=ans|ll(pow(2,i));
	}
//	cout <<ans<<endl;
if(dp[ans]==INF){
	cout << -1;
	return 0;
}
	cout <<dp[ans];
	// your code goes here
	return 0;
}

Measured memory_bytes: 4136
n=gets.to_i
t,a=gets.split.map(&:to_i)
h=gets.split.map(&:to_i)

min=1000
ans=0
n.times do |i|
    if (t-h[i]*0.006-a).abs<min
        ans=i+1
        min=(t-h[i]*0.006-a).abs
    end
end
puts ans


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

#define sz(x) x.size()
#define F first
#define S second 
#define mp make_pair

using namespace std;

string a, b, ans;
int dp[3005][3005], ok[3005][3005];
pair<int, int>p[3005][3005];

int main(){
	cin >> a >> b;
	for(int x = 0; x < a.size(); x++){
		for(int y = 0; y < b.size(); y++){
			int i = x + 1, j = y + 1;
			if(a[x] == b[y]){
            	dp[i][j] = dp[i - 1][j - 1] + 1;
            	p[i][j] = mp(i - 1, j - 1);
            	ok[i][j] = 1;
			}
			else{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				if(dp[i - 1][j] >= dp[i][j - 1]) 
					p[i][j] = mp(i - 1, j);
				else
					p[i][j] = mp(i, j - 1);
			}
		}
	}
	p[0][0] = mp(-1, -1);
	p[0][1] = mp(-1, -1);
	p[1][0] = mp(-1, -1);
	int s = sz(a), k = sz(b);
	while(p[s][k] != mp(-1, -1)){
		if(ok[s][k] == 1){
			ans += a[s - 1];
		}
		int l = p[s][k].F, r = p[s][k].S;
		s = l;
		k = r;
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}

Measured memory_bytes: 141312
#include <iostream>

int main(void) {
    int a, b;
    std::cin >> a >> b;
    if ( a == b){
        std::cout << "a == b" << std::endl;
    }
    else if ( a > b ){
        std::cout << "a > b" << std::endl;
    }
    else if ( a < b ){
        std::cout << "a < b" << std::endl;
    }
}



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

using ll = long long;

int main() {
    int N, a[2][3], b[3];
    cin >> N;
    rep(i, 2) rep(j, 3) cin >> a[i][j];
    rep(i, 3) b[i] = a[1][i] - a[0][i];
    vector<vector<ll>> dp1(4, vector<ll>(N + 1, 0));
    rep(i, 3) {
        rep(j, N + 1) {
            dp1[i + 1][j] = dp1[i][j];
            if (j >= a[0][i]) {
                ll x = dp1[i + 1][j - a[0][i]] + b[i];
                if (x > dp1[i + 1][j]) dp1[i + 1][j] = x;
            } 
        }
    }
    N += dp1[3][N];
    vector<vector<ll>> dp2(4, vector<ll>(N + 1, 0));
    rep(i, 3) {
        rep(j, N + 1) {
            dp2[i + 1][j] = dp2[i][j];
            if (j >= a[1][i]) {
                ll x = dp2[i + 1][j - a[1][i]] - b[i];
                if (x > dp2[i + 1][j]) dp2[i + 1][j] = x;
            } 
        }
    }
    cout << N + dp2[3][N] << endl;
}

Measured memory_bytes: 977024
'''
Created on 2020/08/21

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  A,B,K=map(int,pin().split())
  for i in range(K):
    if i%2==0:
      if A%2==1:
        A-=1
      A=A//2
      B+=A
    else:
      if B%2==1:
        B-=1
      B=B//2
      A+=B 
  print(f"{A} {B}")
  return 
main()

Measured memory_bytes: 9104
//
//  main.cpp
//  codeforces
//
//  Created by cfhaiteeh on 29/5/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define  LL long long

using namespace  std;
const int maxn=123456;

void init(){
   
   
}





void play(){
   
   
}
void pri(){
   // printf("%lld\n",ans);
}
char ch[5];
int main() {
    while(scanf("%s",ch+1)!=EOF){
        int sum=0;
        for(int i=1;i<=4;i++){
            if(ch[i]=='+')sum++;
            else sum--;
        }
        cout<<sum<<endl;
        //init();
       // play();
       // pri();
    }
    return 0;
}


Measured memory_bytes: 256
package main

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

type node struct {
	key   int
	left  *node
	right *node
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextOperation() int {
	sc.Scan()
	if sc.Text() == "insert" {
		return 1
	} else {
		return 0
	}
}
func Print(nodes []int) {
	// 木の走査によって得られたint型スライスを引数に、
	// 指定されたフォーマットに出力する関数
	writer := bufio.NewWriter(os.Stdout)
	for _, v := range nodes {
		writer.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	writer.Write([]byte("\n"))
	writer.Flush()
}
func Insert(root *node, value int) *node {

	if root == nil {
		return &node{value, nil, nil}
	}

	var parent *node
	anode := root
	for anode != nil {
		parent = anode
		if anode.key > value {
			anode = anode.left
		} else {
			anode = anode.right
		}
	}

	if parent.key > value {
		parent.left = &node{value, nil, nil}
	} else {
		parent.right = &node{value, nil, nil}
	}
	return root
}
func Inorder(root *node, store []int) []int {
	if root != nil {
		store = Inorder(root.left, store)
		store = append(store, root.key)
		store = Inorder(root.right, store)
	}
	return store
}
func Preorder(root *node, store []int) []int {
	if root != nil {
		store = append(store, root.key)
		store = Preorder(root.left, store)
		store = Preorder(root.right, store)
	}
	return store
}
func main() {
	sc.Split(bufio.ScanWords)
	var root *node
	n := nextInt()
	for i := 0; i < n; i++ {
		if nextOperation() == 1 {
			key := nextInt()
			root = Insert(root, key)
		} else {
			Print(Inorder(root, []int{}))
			Print(Preorder(root, []int{}))
		}
	}
}



Measured memory_bytes: 51804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

string s[110];
int main(void){
	int h, w; cin >> h >> w;
	rep(i, h) cin >> s[i];
	rep(i, h){
		cout << s[i] << endl;
		cout << s[i] << endl;
	}
	return 0;
}

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

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    REP (i, N) {
        cin >> P[i];
    }
    sort(P.begin(), P.end());
    int ans = 0;
    REP (i, K) {
        ans += P[i];
    }
    cout << ans << endl;

    return 0;
}

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

inline void prime(int *p, int n){

  fill(p, p+n, 1);

  p[0] = 0;
  p[1] = 0;
  for(int i=2; i<=n; i++){
    for(int j=2; i*j<=n; j++){
      p[i*j] = 0;
    }
  }

}

int main(){

  int p[1000000], cnt, n;

  prime(p, 1000000); 
  
  while(cin >> n){
    if(n == 0) break;
    cnt = 0;

    for(int i=0; i<=n/2; i++){
      if(p[i] == 1 && p[n-i] == 1) cnt++;
    }

    cout << cnt << endl;

  }
  
  return 0;

}

Measured memory_bytes: 5064
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int n;
  cin>>n;
  VI a;
  REP(i, n){
    int v;
    cin >>v;
    a.push_back(v);
  }
  SORT(a);
  int sum=0;
  REP(i, n-1){
    sum+=a[i];
  }
  if(a[n-1]<sum){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1LL << 60;

int main()
{
  ll x, n;
  cin >> x >> n;

  ll *a = new ll[102];
  FOR(i, 0, 101)
  {
    a[i] = false;
  }

  REP(i, n)
  {
    ll p;
    cin >> p;
    a[p] = true;
  }

  ll ans = 0;
  ll m = INF;
  FOR(i, 0, 101)
  {
    if (a[i])
      continue;

    ll y = abs(x - i);
    if (y < m)
    {
      ans = i;
      m = y;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] array = new String[n];
        for (int a = n-1; a >= 0; a--) {
            array[a] = String.valueOf(sc.nextInt());
        }
        System.out.println(String.join(" ", array));
        sc.close();
    }
}


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

const int M=1e5+5;
vector<int> g[M];

int dp[M];
int dfs(int u)
{
	if(dp[u]) return dp[u];
	for(int v:g[u])
		dp[u]=max(dp[u],dfs(v));
	return ++dp[u];
}

int main()
{
	int n,m; scanf("%d%d",&n,&m);
	int u,v;
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,dfs(i));
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <set>

using namespace std;

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

	set<string> subs;
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < s.size(); j++) {
			auto t = s.substr(j, i);
			subs.insert(t);
		}
	}

	auto it = subs.begin();
	it = next(it, k - 1);
	cout << *it << endl;
	return 0;
}


Measured memory_bytes: 1664
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let s = next()
    let pos = 0
    let ans = 0
    const target = "ACGT"
    while(pos<s.length){
        let cnt = 0
        while(pos<s.length && target.includes(s[pos])){
          cnt++
          pos++
        }
        ans = Math.max(ans, cnt)
        pos++
    }
    console.log(ans)
}
Main()


Measured memory_bytes: 29388
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

vector<int> par;

int root(int a) {
	if (par[a] == a)return a;
	return par[a] = root(par[a]);
}

void unite(int a, int b) {
	int art = root(a), brt = root(b);
	if (art == brt)return;
	par[brt] = art;
}

int main() {
	int N, K; cin >> N >> K;
	vector<int> P(N);
	par = vector<int>(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i];
		par[i] = i;
	}

	int str = 1, un = -1;
	for (int i = 1; i < N; i++) {
		if (P[i - 1] < P[i]) {
			str++;
			if (str >= K) {
				if (un == -1)un = i - K + 1;
				else unite(un, i - K + 1);
				//cout << "i=" << i << endl;
			}
		}
		else str = 1;
	}

	deque<int> dq1, dq2;
	dq1.push_back(0), dq2.push_back(0);
	for (int i = 0; i < N; i++) {
		while (!dq1.empty()&&P[dq1.back()] > P[i]) {
			dq1.pop_back();
		}
		dq1.push_back(i);

		while (!dq1.empty() && dq1.front() < i - K) {
			dq1.pop_front();
		}

		while (!dq2.empty() && P[dq2.back()] < P[i]) {
			dq2.pop_back();
		}
		dq2.push_back(i);

		while (!dq2.empty() && dq2.front() < i - K) {
			dq2.pop_front();
		}

		if (i >= K) {
			if (i-K == dq1.front() &&  i== dq2.front()) {
				unite(i - K, i + 1 - K);
			}
		}
	}

	int cnt = 0;
	map<int, bool> va;
	for (int i = 0; i <= N - K; i++) {
		int rt = root(i);
		if (va[rt])continue;
		va[rt] = true;
		cnt++;
		//cout << "rt=" << rt << endl;
	}
	cout << cnt << endl;
}

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

bool isPalin(string S, int N) {
	for (int i = 0; i < N; i++) {
		if (S[i] != S[N - 1 - i]) {
			return false;
		}
	}
	return true;
}

int main() {
	string S;
	cin >> S;
	int N = S.size();
	if (isPalin(S, N) && isPalin(S.substr(0, (N - 1) / 2), (N - 1) / 2)) {
		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<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int n,x=0,y=0;
    cin>>n;
    vector<int> w(n),a(n);
    rep(i,n){
        cin>>w[i];
    }
    rep(t,n){
        rep(i,n){
            if (i<=t) x+=w[i];
            else y+=w[i];
        }
        a[t]=abs(x-y);
        x=0;
        y=0;
    }
    sort(ALL(a));
    cout<<a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    string S, T;
    long A, B;
    scan(S, T);
    scan(A, B);
    auto U = sread();
    if (U == S)
        A--;
    if (U == T)
        B--;
    writefln("%s %s", A, B);
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=2e4+10;
int n,a[N],b[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
int main()
{
	//freopen("Construct Sequences.in","r",stdin);
	read(n);
	for(RG int i=1;i<=n;i++) a[i]=i*(n+1), b[i]=(n-i+1)*(n+1);
	for(RG int i=1,aa;i<=n;i++)
	{
		read(aa);
		a[aa]-=(n-i+1);
	}
	for(RG int i=1;i<=n;i++) printf("%d ",a[i]); printf("\n");
	for(RG int i=1;i<=n;i++) printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 768
while True :
    try :
        A = list(input().split())
        B = list(input().split())
        
        hit = 0
        blow = 0
        
        for i in range(4) :
            if A[i] == B[i] :
                hit += 1
                
            elif B[i] in A :
                blow += 1
                
        print(hit, blow)
    
    except :
        break


Measured memory_bytes: 5556