akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main()
{
    //　数値の定義
    //　文字列の定義
    string s; //入力文字
    cin >> s;
    
    // 識別
    bool flag1 = false;
    bool flag2 = false;

    if(s.compare(2, 1, s, 3, 1) == 0){
        flag1 = true;
    }
    if(s.compare(4, 1, s, 5, 1) == 0){
        flag2 = true;
    }

    //判定
    if(flag1 && flag2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
  
  int x,y,a,b;
  cin >> x >> y;
  
  int hantei = 0;
  
  for ( int i = 0; i <= x; i++){
    if ( i * 2 + ( x - i ) * 4 == y ){
      hantei = 1;
      break;
    }
  }
  
  if ( hantei ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
    
}



Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

int main() {
  int N;
  cin >> N;
  int ans;
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    if (i == 0) {
      ans = tmp;
    } else {
      ans = gcd(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int main() {
   fast();
  long long n,p;
  cin>>n>>p;
  long long d=sqrt(p);
  map<long long int,long long int> m;
 
  while(p%2==0){
      p=p/2;
      m[2]++;
  }
  long long l=p;
  for(long long i=3;i<=sqrt(l);i++){
    while(l%i==0){
      l=l/i;
      m[i]++;
    }
  }
  if(l>2){
    m[l]++;
  }
  long long ans=1;
  for(auto i:m){
    long long t=(i.second)/n;
    long long a=i.first;
    ans*=binpow(a,t);
  }
  cout<<ans<<"\n";
   




}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N;
  string S;
  cin >> S;
  if(S[0] != '1' || S[S.size()-1] != '0'){
    cout << -1 << endl;
    return 0;
  }
  REP(i,S.size()-1){
    if(S[i] != S[S.size()-2-i]){
      cout << -1 << endl;
      return 0;
    }
  }
  int from,to,las=S.size();
  REP(i,S.size()-1){
    if(S[S.size()-2-i] == '0'){
      from = las;
      to = S.size()-2-i+1;
    }else{
      from = las;
      to = S.size()-2-i+1;
      las = to;
    }
    cout << from << " " << to << endl;
  }
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 1664
use std::io::*;
use std::str::FromStr;
//portable utility
#[allow(dead_code)]
fn switch<T>(flag: bool, true_value: T, false_value: T) -> T {
    if flag {
        true_value
    } else {
        false_value
    }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_string() -> Vec<char> {
    read::<String>().chars().collect()
}

#[allow(dead_code)]
fn read_vector<T: FromStr>(number: i32) -> Vec<T> {
    (0..number).map(|_| read()).collect()
}

//main program
fn main() {
    let (k, n): (i32, i32) = (read(), read());
    let a: Vec<i32> = read_vector(n);

    let mut max_val = 0;
    for i in 0..(n - 1) as usize {
        let val = a[i + 1] - a[i];
        if max_val < val {
            max_val = val;
        }
    }
    let val = k - a[(n - 1) as usize] + a[0];
    if max_val < val {
        max_val = val;
    }

    println!("{}", k - max_val);
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int k, length, pointer;
string S, s[100005];

int main(){

    cin >> S >> k;
    length = S.size();

    for (int i = 1; i <= 5; i++){
        for (int j = 0; j <= length-i; j++){
            s[pointer++] = S.substr(j,i);
        }
    }

    sort(s, s+pointer);
    unique(s, s+pointer);

    cout << s[k-1] << endl;

    return 0;

}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int now=6,a,b;
	cin>>a>>b;
	cout<<now-a-b<<'\n';
    return 0;
}



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

int selection_sort(int a[], int n) {
  int swaps = 0;
  for (int i = 0; i < n - 1; ++i) {
    int minj = i;
    for (int j = i; j < n; ++j) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    swap(a[i], a[minj]);
    if (i != minj) {
      ++swaps;
    }
  }
  return swaps;
}

int main() {
  int a[100], n, i, swaps;
    cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  swaps = selection_sort(a, n);

  for (int i = 0; i < n; ++i) {
    if (i > 0) {
      cout << ' ';
    }
    cout << a[i];
  }
  cout << endl;
  cout << swaps << endl;

  return 0;
}



Measured memory_bytes: 3088
#include <iostream>

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

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

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

	long long int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 0 || i % 5 == 0)
		{
			continue;
		}
		ans += i;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32,
        a: i32
    }
    println!("{}",
        if n % 500 <= a {"Yes"} else {"No"}
    );
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n,k;
 cin>>n>>k;
 vector<int> h(n);
 for(int i=0;i<n;i++) cin>>h[i];
 vector<int> dp(n);
 dp[n-1]=0;
 for(int i=n-2;i>=0;i--){
  dp[i]=1e9+7;
  for(int j=i+1;j<n&&j<=i+k;j++){
   dp[i]=min(dp[i],abs(h[j]-h[i])+dp[j]);
  }
 }
 cout<<dp[0]<<endl;
 return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
    int A,B;
    char s[11];
    cin >> A >> B;
    int S = A+B+1;
    cin >> s;
    int i;
    for(i=0;i<S;i++){
        if (i !=A && ('0'> s[i] || s[i]>'9'))break;
        if (i==A && s[i]!='-')break;
    }
    if(i==S)cout << "Yes";
    else cout << "No";
    return 0;

}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        HashMap<Integer, Integer> map = new HashMap<>();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
            if(map.containsKey(A[i])){
                map.put(A[i], map.get(A[i]) + B[i]);
            }
            else{
                map.put(A[i], B[i]);
                list.add(A[i]);
            }
        }

        Collections.sort(list);

        long ans = 0L;
        for(int i=0; i<list.size(); i++){
            int x = list.get(i);
            if(map.get(x)<=M){
                ans += 1L * x * map.get(x);
                M -= map.get(x);
            }
            else{
                ans += 1L * x * M;
                M=0;
            }
            if(M==0){
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 98236
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 1e5 + 10, lim = 1e8;
const ll ub = 1e13;
int a[N];
ll ma[N];
bool ch(int n){
	ll nex = 0, cur = 1LL;
	for(int i = 0; i <= n; i++){
		ma[i] = min(ma[i], cur);
		nex  = 2 * (cur - a[i]);
		if(nex < 0) return false;
		cur = nex;
		if(nex >= ub) return true; 
	}
	return true;

}
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i <= n; i++){
		scanf("%d", &a[i]);
		if(i == 0) ma[i] = 1LL;
		else ma[i] = min(2LL * ma[i - 1], ub); 
	}
	bool io = ch(n);
	if(!io) return !printf("-1");
	ll tot = 1LL * a[n], cur = 1LL * a[n], nex;
	for(int i = n; i > 0; i--){
		nex = min(ma[i - 1], cur + 1LL * a[i - 1]);
		cur = nex;
		tot += nex;
	}
	printf("%lld", tot);

}

Measured memory_bytes: 5000
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
#define input(A,N) for(ll i=0;i<N;i++) cin>>A[i];
int main()
{
    fasino
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    #endif
    ll a,b ;
  cin>>a>>b;
  cout<<a*b;
    return 0;
}

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

int main()
{	

	int A,B,M;
	cin>>A>>B>>M;
	int a[A]={0},b[B]={0},pr[M]={0},min_a=0,min_b=0;
	cin>>a[0];
	min_a=a[0];
	for (int i = 1; i < A; ++i)
	{cin>>a[i];
		if(min_a>a[i])
			min_a=a[i];
		/* code */
	}
	cin>>b[0];
	min_b=b[0];
	for (int i = 1; i < B; ++i)
	{cin>>b[i];
		if(min_b>b[i])
			min_b=b[i];
	/* code */
	}
	int x,y,c,min=0;
	cin>>x>>y>>c;
	pr[0]=a[x-1]+b[y-1]-c;
	min=pr[0];
	for (int i = 1; i < M; ++i)
	{cin>>x>>y>>c;
		pr[i]=a[x-1]+b[y-1]-c;
		if(min>pr[i])
			min=pr[i];
		/* code */
	}
	if(min_a+min_b<min)
		cout<<min_a+min_b;
	else
	cout<<min;
return 0;
}

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

int main(){
  string s; cin>>s;
  s[0]='2';
  s[1]='0';
  s[2]='1';
  s[3]='8';
  for(int i=0;i<s.size();i++){
    cout<<s[i];
  }
  return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d %d %d %d",$a,$b,$c,$k);

$ans = 0;
for ($i = 1;$i <= $k;++$i) {
    if ($a >= $k) {
        $ans = $k;
        break;
    } else if ($a > 0) {
        $ans += $a;
        $i += ($a - 1);
        $a = 0;
    } else if ($b > 0) {
        $i += ($b - 1);
        $b = 0;
    } else {
        $ans -= $k - ($i - 1);
        break;
    }
}
echo $ans.PHP_EOL;

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

int main()
{
  double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  cout << fixed << setprecision(5)
       << (double)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) << endl;
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()

using namespace std;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/

int main() {
	ll A, B, C, X, ans = 0; cin >> A >> B >> C >> X;
	for (int i = 0;i <= A;i++) {
		for (int j = 0;j <= B;j++) {
			for (int k = 0;k <= C;k++) {
				if (i * 500 + j * 100 + k * 50 == X) ans++;
				if (i * 500 + j * 100 + k * 50 > X) break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
previous_t = 0
for i in range(n):
    t, x, y = list(map(int, input().split()))
    if x + y > t:
        print("No")
        break
    if (x + y) % 2 != t % 2:
        print("No")
        break
    if previous_t > 0 and (abs(x - previous_x) + abs(y - previous_y) > (t - previous_t)):
        print("No")
        break
    previous_t = t
    previous_x = x
    previous_y = y
else:
    print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int N = 1e5 + 5;
int dp[N];
int arr[N];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < N; i++) {
		dp[i] = inf;
	}
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j >= 0) {
				dp[i] = min(dp[i], abs(arr[i] - arr[i - j]) + dp[i - j]);
			}
		}
	}
	cout << dp[n - 1];
	return 0;
}


Measured memory_bytes: 1024
type uf_node = {
    mutable par: int;
    mutable rank: int;
}
;;

let uf_make n = Array.init n (fun i -> { par = i; rank = 0 })
;;

(* 根を求める *)
let rec uf_find uf x =
    if uf.(x).par == x
        then x
        else
            let par = uf.(x).par in
            let v = uf_find uf par in
            uf.(x).par <- v;
            v
;;

(* xとyの集合を併合 *)
let rec uf_unite uf x y =
    let x = uf_find uf x in
    let y = uf_find uf y in
    if x != y then
        if uf.(x).rank < uf.(y).rank
            then (
                uf.(x).par <- y;
                ()
            )
            else (
                uf.(y).par <- x;
                if uf.(x).rank == uf.(y).rank then (
                        uf.(x).rank = uf.(x).rank + 1;
                        ()
                )
            )
;;

let uf_some uf x y = uf_find uf x == uf_find uf y
;;

let rec parse_xy_list_ m l =
    if m == 0
        then l
        else parse_xy_list_ (m - 1) ((let [x; y] = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string in (x, y)) :: l)
;;
let parse_xy_list m = parse_xy_list_ m [] |> List.rev
;;

let () =
    let [n; m] = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string in
    let p_list = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string in
    let xy_list = parse_xy_list m in
    let uf = uf_make n in
    List.iter (fun xy -> let x, y = xy in uf_unite uf (x - 1) (y - 1)) xy_list;
    let res = p_list |> List.mapi (fun i x -> uf_some uf i (x - 1)) |> List.filter (fun x -> x) |> List.length in
    Printf.printf "%d\n" res
;;



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

const long long NINF = -1e18;

int N,W;
long long dp[105][100005];
int K[105];
int V[105];

long long solve(int x, int rem) {
    if (x >= N) return 0;
    if (rem == 0) return 0;
    if (dp[x][rem] != -1) return dp[x][rem];

    long long take = NINF;
    if (rem - K[x] >= 0) take = V[x] + solve(x + 1, rem - K[x]);

    long long dont_take = solve(x + 1, rem);
    return dp[x][rem] = max(take, dont_take);
}

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

    memset(dp, -1, sizeof(dp));
    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> K[i];
        cin >> V[i];
    }

    cout << solve(0, W) << "\n";
}



Measured memory_bytes: 82304
#include <stdio.h>

int main(void) {
	int  a, b;
	scanf("%d %d", &a, &b);

	if (a >= 13) {
		printf("%d",b);
	}
	else if(a>=6) {
		printf("%d", b / 2);
	}
	else {
		printf("0");
	}



	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

int main() {
  string s;
  cin>>s;
  frn(i,s.size()) {
    if((i+1)%2==1) cout<<s[i];
  }
}

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

int main(){
	int A;
	int B;

	cin >> A >> B;

	if(A%3==0){
	 cout << "Possible";
	}
	else if(B%3==0){
	 cout << "Possible";
	}
	else if((A+B)%3==0){
	 cout << "Possible";
	}else{
     cout << "Impossible";
	}
	cout << endl;

//    if(A%3!=0){
//    }
//    if(B%3/=0)












}


Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y,z;
	ll		ans = 0;
	string	s;
	cin >> n;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));
	for(i=1;i<=n;i++) {
		ans = 0;
		for(x=1;x<=sqrt(i);x++) {
			for(y=1;y<=x;y++) {
				for(z=1;z<=y;z++) {
					if (x*x+y*y+z*z+x*y+y*z+z*x==i) {
						if (x==y && y==z) ans++;
						else if (x==y && y!=z) ans+=3;
						else if (x==z && y!=z) ans+=3;
						else if (x!=y && y==z) ans+=3;
						else ans+=6;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3488
import java.util.*;


public class Main {
	
	void AOJ0044(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			for(int i=n-1; i>1; i--){
				if(isPrime(i)){
					System.out.print(i+" ");
					break;
				}
			}
			for(int i=n+1; ; i++){
				if(isPrime(i)){
					System.out.println(i);
					break;
				}
			}
		}
	}
	
	void AOJ0009(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int count=0;
			boolean[] prime = new boolean[n+1];
			Arrays.fill(prime, true);
			for(int i=2; i<=n; i++){
				if(prime[i]){
					count++;
					for(int j=i+i; j<=n; j+=i)	prime[j]=false;
				}
			}
			System.out.println(count);
		}
	}
	
	ArrayList<Integer> Sieve(int n){
	     ArrayList<Integer> prime = new ArrayList<Integer>();
	     if(n<2)	return prime;
	     boolean[] list = new boolean[n];
	     Arrays.fill(list, true);
	     list[1]=false;
	     for (int i=2; i<n; i++) {
	          if (list[i]) {
	               prime.add(i);
	               for (int j=i+i; j<n; j+=i)	list[j] = false;
	          }
	     }
	     return prime;
	}
	
	boolean isPrime(int n){
		for(int i=2; i*i<=n; i++){
			if(n%i==0)	return false;
		}
		return true;
	}

	public static void main(String[] args) {
		new Main().AOJ0044();
	}

}

Measured memory_bytes: 12000
N = int(input())
A = list(map(int,input().split()))
ans = 0
ls = []
ans = 0
for i in range(N):
  if i == N-1:
    if A[i] == i+1:
      A[i],A[i-1] = A[i-1],A[i]
      ans += 1
  else:
    if A[i] == i+1:
      A[i],A[i+1] = A[i+1],A[i]
      ans += 1
print(ans)


Measured memory_bytes: 20572
# include <bits/stdc++.h>
using namespace std;
# define int long long
const int N = 2e5 + 10, mod = 1e9 + 7, INF = 8e18;
bool prime(int x){
	for(int i = 2; i * i <= x; i ++)if(x % i == 0) return false;
	return true;
}
main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	while(true){
		if(prime(n)){
			cout << n << '\n';
			return 0;
		}
		++ n;
	}
}

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

using namespace std;

int main() {


    int N; cin >> N;
    vector<vector<int> > a(2, vector<int>(N));
    for (int i = 0; i < 2; ++i){
        for (int j = 0; j < N; ++j) {
            cin >> a[i][j];
        }
    }

    // 累積和
    vector<vector<int> > s(2, vector<int>(N+1, 0));

    // vector<int> s(N+1, 0); // s[0] = 0 になる
    // for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

    int c = 0;
    int d = 0;
    int m = -1;
    for (int i = 0; i < N; ++i) {
        d = 0;
        c = 0;
        for (int j = 0; j < N; ++j) {
            c += a[d][j];
            if (j == i ){
                d  =1  ;
                c += a[d][j];
            }
        }
//        cout << c << endl;
        if ( c > m ){
            m = c;
        }
    }
    cout << m << endl;



}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

char s[111111];
int k, l;

int main(void) {
  scanf("%s", s);
  scanf("%d", &k);
  l = strlen(s);

  for (int i = 0; i < l; i++) {
    if (s[i] != 'a' && 'z'-s[i] < k) {
      k -= 'z'-s[i]+1;
      s[i] = 'a';
    }
  }

  s[l-1] = (s[l-1]-'a'+k)%26+'a';
  
  printf("%s\n", s);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int satis[50][3];
int n, m;
typedef pair<int, int> P;
typedef pair<int, P> PP;
map<PP, int> memo;
int dfs(int idx, int lev1, int rest){
  PP arg = PP(idx, P(lev1, rest));
  if(memo.count(arg)) return memo[arg];
  if(idx == n) return 0;
  int res = -INF;
  for(int lev2 = 0; lev2 <= rest; lev2++){
    int maxp = satis[idx][2];
    for(int u2 = 0; u2 <= lev2; u2++){
      for(int u1 = 0; u1 <= lev1; u1++){
        if(u2 == 0 && u1 == 0) continue;
        if(u1 + u2 > 8) continue;
        maxp = max(maxp, satis[idx][0] * u2 + satis[idx][1] * u1);
      }
    }
    res = max(res, dfs(idx + 1, lev2, rest - lev2) + maxp);
  }
  return memo[arg] = res;
}

int main(){
  while(cin>>n>>m){
    memo.clear();
    REP(i, n) REP(j, 3) cin>>satis[i][j];
    cout<<dfs(0, 0, m)<<endl;
  }
  return 0;
}

Measured memory_bytes: 5180
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b) cout<<"a > b"<<endl;
    else if(a<b) cout<<"a < b"<<endl;
    else if(a==b) cout<<"a == b"<<endl;
    return 0;
}


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

const int MAXN = 200001;
struct Edge{
    int end , upEd;
}Ed[MAXN];
bool vis1[MAXN] , vis2[MAXN];
int LTK1[MAXN] , LTK2[MAXN] , cnt[MAXN] , head[MAXN] , N , M , K , cntEd , cntLTK;
struct Queue{
    int arr[MAXN] , hd , tl;
    inline void init(){
        hd = tl = 0;
    }
    inline bool empty(){
        return hd == tl;
    }
    inline void push(int a){
        arr[tl++] = a;
    }
    inline void pop(){
        hd++;
    }
    inline int front(){
        return arr[hd];
    }
}q;
unordered_map < long long , int > m;

inline void addEd(int a , int b){
    Ed[++cntEd].end = b;
    Ed[cntEd].upEd = head[a];
    head[a] = cntEd;
}

inline void bfs1(int dir){
    q.init();
    q.push(dir);
    cntLTK++;
    vis1[dir] = 1;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        LTK1[t] = cntLTK;
        for(int i = head[t] ; i ; i = Ed[i].upEd)
            if(!vis1[Ed[i].end]){
                vis1[Ed[i].end] = 1;
                q.push(Ed[i].end);
            }
    }
}

inline void bfs2(int dir){
    q.init();
    while(!q.empty())
        q.pop();
    q.push(dir);
    cntLTK++;
    vis2[dir] = 1;
    while(!q.empty()){
        int t = q.front();
        q.pop();
        LTK2[t] = cntLTK;
        for(int i = head[t] ; i ; i = Ed[i].upEd)
            if(!vis2[Ed[i].end]){
                vis2[Ed[i].end] = 1;
                q.push(Ed[i].end);
            }
    }
}

int main(){
    cin >> N >> M >> K;
    for(int i = 1 ; i <= M ; i++){
        int a , b;
        scanf("%d%d" , &a , &b);
        addEd(a , b);
        addEd(b , a);
    }
    for(int i = 1 ; i <= N ; i++)
        if(!vis1[i])
            bfs1(i);
    memset(head , 0 , sizeof(head));
    cntLTK = cntEd = 0;
    for(int i = 1 ; i <= K ; i++){
        int a , b;
        scanf("%d%d" , &a , &b);
        addEd(a , b);
        addEd(b , a);
    }
    for(int i = 1 ; i <= N ; i++)
        if(!vis2[i])
            bfs2(i);
    for(int i = 1 ; i <= N ; i++)
        m[LTK1[i] * 200000ll + LTK2[i]]++;
    for(int i = 1 ; i <= N ; i++)
        printf("%d " , m.find(LTK1[i] * 200000ll + LTK2[i])->second);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n;

int main(){
    cin >> n;
    vector<string> vs(n);
    ll ans = 0;
    ll cnt[3] = {};
    rep(i,n){
        cin >> vs[i];
        if(vs[i][0] == 'B' && vs[i].back() == 'A')cnt[1]++;
        else if(vs[i].back() == 'A')cnt[0]++;
        else if(vs[i][0] == 'B')cnt[2]++;
        rep(j,vs[i].size()-1){
            if(vs[i][j] == 'A' && vs[i][j+1] == 'B')ans++;
        }
    }
    ans += max((ll)0,(cnt[1]-1));
    // cout << ans << endl;
    if(cnt[1] > 0){
        if(cnt[0] > 0){
            ans++;
            cnt[0]--;
        }
        if(cnt[2] > 0){
            ans++;
            cnt[2]--;
        }
    }
    ans += min(cnt[0],cnt[2]);
    cout << ans << endl;
}


Measured memory_bytes: 768
#include <stdio.h>
int main(void){
    int a, b, c, k, i;
    
    scanf("%d%d%d",&a,&b,&c);
    scanf("%d",&k);
    
    if((a>=b)&&(a>=c)){
        for(i=0;i<k;i++) a=a*2;
    }
    else if((b>a)&&(b>=c)){
        for(i=0;i<k;i++) b=b*2;
    }
    else if((c>a)&&(c>b)){
        for(i=0;i<k;i++) c=c*2;
    }
    printf("%d\n",a+b+c);
    return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>

int main()
{
  int n, m, c;
  std::cin >> n >> m >> c;
  std::vector<int> b;
  for (int i = 0; i < m; i++) {
    int val;
    std::cin >> val;
    b.push_back(val);
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int score = c;
    for (int k = 0; k < m; k++) {
      int a;
      std::cin >> a;
      score += a * b.at(k);
    }
    if (score > 0) {
      cnt++;
    }
  }
  std::cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
(function(stdin) {
  // Define Function

  // Declare Variable
  const greterOrLess = {
    true : 'a > b',
    false: 'a < b'
  };

  const inputs  = stdin.toString().trim().split('\n');
  const cols = inputs[0].split(' ').map(Number);
  // Main Procedure
  const result = (function(a, b) {

    return (a === b) ? 'a == b' : greterOrLess[a > b];

  }(cols[0], cols[1]));

  // Display
  console.log(result);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15564
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  while (in.hasNextLine()) {
	String text = in.nextLine();
	text = text.replace("apple", "P");
	text = text.replace("peach", "apple");
	text = text.replace("P", "peach");
	System.out.println(text);
  }
}
}

Measured memory_bytes: 12000
N, K = map(int, input().split())
A = list(map(int, input().split()))

m = {}
for i, a in enumerate(A):
    m[i+1] = a

visited = []
cycle = set()
current_city = 1
visited.append(current_city)
cycle.add(current_city)
cycle_start_index = -1
while 1:
    current_city = m[current_city]
    if current_city in cycle:
        cycle_start_index = visited.index(current_city)
        break
    else:
        visited.append(current_city)
        cycle.add(current_city)

cycle_before = visited[:cycle_start_index]
cycle_after = visited[cycle_start_index:]
if len(cycle_before) - 1 < K:
    print(cycle_after[(K - len(cycle_before)) % len(cycle_after)])
else:
    print(cycle_before[K])

Measured memory_bytes: 157760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int a=scn.nextInt();
		int b=scn.nextInt();
		System.out.println(Integer.max(a+b, Integer.max(a-b, a*b)));
	}

}


Measured memory_bytes: 21076
#include <iostream>


#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#include <stdio.h>
#include <vector> 
#include <map> 
#include <algorithm>
#include <functional>
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>

#include<iostream>
using namespace std;

std::vector< std::vector<int> > graph;
std::vector<int> c;


void rr(int root, int count) {
	if (count == 0){
		return;
	}
	for(const auto &a : graph[root]) {
		c[a] += count;

		rr(a, count);
	}
}

void eee(int root, int count) {
	c[root] += count;
	for (const auto &a : graph[root]) {
		eee(a, c[root]);
	}
}

int main()
{

	std::string s, t;
	cin >> s;

	char a[3][30] = {
		"Sunny",
		"Cloudy",
		"Rainy"
	};

	for (int i = 0; i < 3; ++i) {
		if (strcmp(a[i], s.c_str())) continue;

		printf("%s\n", a[(i+1)%3]);
	}


	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ull = unsigned long long;
using P = pair<int, int>;


ull E = 1000000007;
ull e = 10007;
const double pi = 3.14159265359;


int main() {
    int N;
    cin >> N;
    multiset<int> L;
    for (int i = 0; i < N; ++i) {
        int l;
        cin >> l;
        L.insert(l);
    }
    auto it = L.rbegin();
    int max_ = *it;
    ++it;
    int sum = 0;
    while (it != L.rend()) {
        sum += *it;
        ++it;
    }
    if (max_ < sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
#define SEG_LEN (1 << 18)
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
template <class T>
class SegTree{
  private:
    int n;                       // 葉の数
    vector<T> data;              // データを格納するvector
    T def;                       // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;    // 点更新で使う処理
  public:
    SegTree(size_t _n,T _def,function<T(T,T)> _operation,function<T(T,T)> _update):def(_def),operation(_operation),update(_update){
      n = 1;
      while(n < _n)n *= 2;
      data = vector<T>(2 * n + 2,def);
    }
    void change(int ind,T x){
      ind += n;
      data[ind] = update(data[ind],x);
      while(true){
        ind /= 2;
        if(ind == 0)break;
        data[ind] = operation(data[ind * 2],data[ind * 2 + 1]);
      }
    }
    T query(int l,int r){
      l += n;
      r += n + 1;
      long long ans = def;
      while(l < r){
        if(l % 2 == 1){
          ans = operation(ans,data[l]);
          l++;
        }
        if(l >= r)break;
        l /= 2;
        if(r % 2 == 1){
          ans = operation(ans,data[r - 1]);
          r--;
        }
        r /= 2;
      }
      return ans;
    }
    T operator[](int i){
      return data[i + n - 1];
    }
}; 
int main(){
  int n;
  cin >> n;
  SegTree<long long>seg(n,0,[](long long a,long long b){return gcd(a,b);},[](long long a,long long b){return b;});
  rep(i,n){
    int tmp;
    cin >> tmp;
    seg.change(i,tmp);
  }
  ll ans = 0;
  rep(i,n){
    if(i == 0)ans = max(ans,seg.query(1,n - 1));
    else if(i == n - 1)ans = max(ans,seg.query(0,n - 2));
    else ans = max(ans,gcd(seg.query(0,i - 1),seg.query(i + 1,n - 1)));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2304
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (b<a) System.out.println(a-1);
		else System.out.println(a);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "")
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

char M(char a, char b) {
    if(a == 'T' && b == 'F') return 'F';
    return 'T';
}

int main() {
    ll N;
    cin >> N;
    char a, b;
    cin >> a >> b;
    char now = M(a, b);
    for(ll i = 2; i < N; i++) {
        char c;
        cin >> c;
        now = M(now, c);
    }
    cout << now << endl;
    return 0;
}



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

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	string a,b;
	cin >> a >> b;
	rev(a);
	if(a == b){
		P("YES");
	}else{
		P("NO");
	}
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair


int n, a[202020], ans;

int main(){
cin >> n;
rep(i, 1, n)cin >> a[i];
rep(i, 1, n-1){
if(a[i]==i)swap(a[i], a[i+1]), ans++;
}
rep(i, 2, n){
if(a[i]==i)swap(a[i], a[i+1]), ans++;
}
cout << ans << endl;


return 0;}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int n,m,a[10000];

    int i;
    scanf("%d %d",&n,&m);

    for(i=0;i<m;i++)
    {
        scanf("%d",&a[i]);
        n = n - a[i];
    }

    if(n > -1)
    printf("%d\n",n);
    else
    {
        printf("-1\n");
    }
    

    return 0;
    
}

Measured memory_bytes: 1752
# int(input()) # 入力が1つ
from copy import deepcopy
n, x = map(int, input().split()) # 入力が複数
box = [int(i) for i in input().split()] # 配列で数字
org = deepcopy(box)


for i in range(n - 1):
    if box[i] + box[i + 1] > x:
        t = max(x - box[i], 0)
        box[i + 1] = t
        if box[i] > x:
            box[i] = x
ans = 0
for i, j in zip(box, org):
    ans += (j - i)
print(ans)


Measured memory_bytes: 89452
#include <bits/stdc++.h>
using namespace std;
template<typename _Tp>inline void IN(_Tp&dig)
{
	char c;dig=0;
	while(c=getchar(),!isdigit(c));
	while(isdigit(c))dig=dig*10+c-'0',c=getchar();
}
int n,m,f[200005],cnt1=1,cnt2;
int findf(int a){return f[a]==a?a:f[a]=findf(f[a]);}
int main()
{
	IN(n),IN(m);
	for(int i=1;i<=(n<<1);i++)f[i]=i;
	for(int i=1,a,b;i<=m;i++)
	{
		IN(a),IN(b);
		f[findf(a)]=findf(b+n);
		f[findf(b)]=findf(a+n);
	}
	for(int i=1;i<=n;i++)
		if(findf(i)==findf(i+n))
			printf("%lld\n",(long long)(1ll*n*(n-1)/2)-m),exit(0);
	for(int i=2;i<=n;i++)if(findf(1)==findf(i))cnt1++;else cnt2++;
	printf("%lld\n",(long long)(1ll*cnt1*cnt2-m));
	return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

n = int(input())
a = [int(x) for x in input().split()]

max_a = [0]*(n + 1)
"""
if n == 0 and a[0] == 0:
    print(-1)
    sys.exit()
"""
for i in range(n + 1):
    if i == 0:
        max_a[i] = 1
    else:
        max_a[i] = (max_a[i - 1] - a[i - 1])*2
        if max_a[i] < 0:
            print(-1)
            sys.exit()
# print(max_a)
for i in range(n, -1, -1):
    if i == n:
        if max_a[i] < a[i]:
            print(-1)
            sys.exit()
        max_a[i] = a[i]
    else:
        min_p = max_a[i + 1] // 2 + int(max_a[i + 1] % 2 == 1)
        max_p = max_a[i + 1]
        if max_a[i] < min_p:
            print(-1)
            sys.exit()
        max_a[i] = min(max_p + a[i], max_a[i])
print(sum(max_a))
# print(max_a)




Measured memory_bytes: 701284
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    vector<int> height(n);
    for(int &i : height)
    {
        scanf("%d",&i);
    }
    const int INF=1e9+5;
    vector<int> dp(n,INF);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<n)
            {
                dp[j]=min(dp[j],dp[i]+abs(height[i]-height[j]));
            }
        }
    }

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

}




Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc106_c
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            long k = long.Parse(Console.ReadLine());
            int p = 0;

            for(int i = 0; i < s.Length; ++i)
            {
                if(s[i] != '1')
                {
                    p = i;
                    break;
                }
            }

            if(k - 1 < p)
            {
                Console.WriteLine(1);
            } else
            {
                Console.WriteLine(s[p]);
            }

        }
    }
}


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

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;
}
const ll LINF = 1LL << 60;
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

const ll mod = 1e9+7;

int main() {
  int N, M; cin >> N >> M;
  vector<int> oks(N+1, true); // 壊れた階段
  for(int i=0; i<M; i++){
    int a; cin >> a;
    oks[a] =false;
  }

  vector<ll> dp(N+1);
  dp[0] = 1;
  for(int now=0; now<N; now++){
    for(int next=now+1; next<=min(N, now+2); next++){
      if(oks[next]){
        dp[next] += dp[now];
        dp[next]%=mod;
      }
    }
  }
  cout << dp[N] << endl;

}


Measured memory_bytes: 1408
N,A,B=map(int,input().split())
a=A
b=B
if (B-A)%2==0:
    ans=int((B-A)//2)
    print(ans)
else:
    ans=B-1
    ans=min(ans,N-A)
    ans2=A-1
    A=1
    B=B-(a-1)
    ans2+=1
    B-=1
    ans2+=int((B-A)//2)
    ans=min(ans,ans2)
    A=a
    B=b
    ans2=N-B
    B=N
    A=A+(N-b)
    ans2+=1
    A+=1
    ans2+=int((B-A)//2)
    ans=min(ans,ans2)
    print(int(ans))

Measured memory_bytes: 3188
package main

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

func solution(s string) int {
        c := 0
        out := 0
        for i := 0; i < len(s); i++ {
                if s[i] == 'B' {
                        c++
                } else {
                        out += c
                }
        }
        return out
}

func main() {
        var fp *os.File = os.Stdin
        reader := bufio.NewReaderSize(fp, 1024)
        s := readLine(reader)
        fmt.Println(solution(s))
}

func readLine(reader *bufio.Reader) string {
        buf := make([]byte, 0, 1024)

        for {
                l, p, _ := reader.ReadLine()

                buf = append(buf, l...)

                if !p {
                        break
                }
        }
        return string(buf)
}

Measured memory_bytes: 2048
N, M = map(int, input().strip().split())
#print(N, M)
inventory = []
for i in range(N):
    priceQuantity = list(map(int, input().strip().split()))
    inventory.append(priceQuantity)
#print(inventory)
inventory.sort()
#print(inventory)
total = 0
spent = 0
step = 0
#print(step, total, spent)
#print(inventory)
#print()
while total < M:
    while inventory[step][1] > 0:
        total = total + 1
        spent = spent + inventory[step][0]
        inventory[step][1] = inventory[step][1] - 1
        if total == M:
            break
        #print(step, total, spent)
        #print(inventory)
        #print()
        #time.sleep(.1)
    step = step + 1
    #print(step, total, spent)
    #print(inventory)
    #print()
    #time.sleep(.1)

#print(step, total, spent)
#print(inventory)
#print()
print(spent)


Measured memory_bytes: 61016
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N = gets_i
ab_list = N.times.map do
  gets_i_list
end.sort{|x,y| x[1] <=> y[1]}

total = 0
ab_list.each do |a, b|
  total += a
  if total > b
    puts "No"
    exit
  end
end
puts "Yes"

Measured memory_bytes: 19576
#include<stdio.h>

int main(void)
{
	int i;
	scanf("%d",&i);
	if(i==22){
		printf("Christmas Eve Eve Eve\n");
	}else if(i==23){
		printf("Christmas Eve Eve\n");
	}else if(i==24){
		printf("Christmas Eve\n");

	}else {
		printf("Christmas\n");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[] b = new boolean[4];

		for (int i = 0; i < n; i++) {
			char a = sc.next().charAt(0);
			switch (a) {
				case 'P':
				b[0] = true;
				break;
				case 'W':
				b[1] = true;
				break;
				case 'G':
				b[2] = true;
				break;
				case 'Y':
				b[3] = true;
				break;
			}
		}

		int cnt = 0;
		for (int i = 0; i < 4; i++) {
			if (b[i]) {
				cnt++;
			}
		}

		if (cnt == 3) {
			System.out.println("Three");
		} else {
			System.out.println("Four");
		}
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <climits>
using namespace std;

static const long long INFTY = (1LL<<32);

#define MAX 100000

long long A[MAX];


int main() {
    int n;
    long long k;
    long long a;
    
    cin >> n >> k;
    
    long long mx = 0;
    long long mn = INFTY;
    for ( int i = 0; i < n; i++ ) {
        cin >> a;
        A[i] = a;
        mx = max(mx, a);
        if ( A[i] == k ) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    
    sort(A, A + n);
    
    for ( int i = 1; i < n; i++ ) {
        if ( A[i] - A[i - 1] == 0 ) continue;
        mn = min(mn, A[i] - A[i - 1]);
    }
  
    long long ans = mx - k;
    if ( ans < 0 ) {
        cout << "IMPOSSIBLE" << endl;
    } else if ( ans % mn == 0 ) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1024