akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    boolean a[] = new boolean[N+10];
    for(int i=0; i<M; i++){
      int x = sc.nextInt();
      a[x] = true;
    }
    long dp[] = new long[N+10];
    dp[0] = 1;
    if(a[1] == true) dp[1] = 0;
    else dp[1] = 1;
    for(int i=2; i<=N; i++){
      if(a[i] == true) dp[i] = 0;
      else{
        dp[i] = dp[i-1] + dp[i-2];
        dp[i] %= MOD;
      }
    }
    out.println(dp[N]);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

const string str = "diverta";

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

    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
}


Measured memory_bytes: 384
let ($) f g = fun x -> g (f x)
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let (x, n) = Scanf.sscanf (read_line ()) "%d %d" @@ fun x n -> (x, n)
let p = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let () =
  Printf.printf "%d\n" @@ 
    if n = 0 then x
    else Array.init 102 (fun i -> i)
      |> Array.to_list
      |> List.filter (fun i -> not (List.mem i p))
      (* |> (fun acc -> List.iter (Printf.printf "%d ") acc; acc) *)
      |> List.map (fun i -> (abs (i - x), i))
      |> List.sort compare
      |> (List.hd $ snd)

Measured memory_bytes: 3880
#!/usr/bin/env python3
import math

def main():
    N = int(input())
    count = 0
    for i in range(N):
        str_num = str(i+1)
        if len(str_num)%2 != 0:
            count += 1
    print(count)
    
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;

#define mod 1000000007


int main()
{
    long long int w, h;
    cin >> w >> h;
    priority_queue<long long int> p, q;
    for(int i = 0; i < w; i++){
        long long int tmpp;
        cin >> tmpp;
        p.push(-tmpp);

    }
    for(long long int i = 0; i < h; i++){
        long long int tmpq;
        cin >> tmpq;
        q.push(-tmpq);
    }
    w++;
    h++;
    long long int ans = 0;
    long long int popedp = 0, popedq = 0;
    while(!q.empty() || !p.empty()){
        if(q.empty()){
            ans += p.top();
            p.pop();
            popedp++;
        } else if(p.empty()){
            ans += q.top();
            q.pop();
            popedq++;
        } else {
            // cout << p.top() << " " << q.top() << " " << ans <<  endl;
            if(p.top() > q.top()){
                if(popedq >= 1){
                    ans += (h - popedq) * p.top();
                } else {
                    ans += h * p.top();
                }
                p.pop();
                popedp++;
            } else {
                if(popedp >= 1){
                    ans += (w - popedp) * q.top();
                } else {
                    ans += w * q.top();
                }
                q.pop();
                popedq++;
            }
        }
    }
    cout << -ans << endl;
    return 0;}

Measured memory_bytes: 2548
import java.util.Scanner;
import java.lang.Math;

public class Main {
	private static int[] A;
	private static int H;
	private static int val;
	private static int l;
	private static int r;
	
	public static void swap(int[] A, int idx1, int idx2) {
		int temp = A[idx1];
		A[idx1] =  A[idx2];
		A[idx2] = temp;
	}
	
	public static void maxHeapify(int[] A,int i) {
		int largest;
		
		l = i*2; // get the left child index 
		r = i*2+1;
		
		// select the node which has the maximum value
		if (l <= H && A[l] > A[i]) {
			largest = l;
		} else {
			largest = i;
		}
		
		if (r <= H && A[r] > A[largest]) {
			largest = r;
		}
		
		if  (largest != i) {
			swap(A, i, largest);
			maxHeapify(A, largest);
		}
	}
	
	
	public static void buildMaxHeap(int[] A) {
		val =H/2;
		// val = (int) Math.ceil(H/2)+1;
		for(int i = val; i >0; i--) {
			maxHeapify(A, i);
		}
	}
	
	
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		H = input.nextInt();
		A =  new int[H+1];
		
		// Take inputs to build an array of trees
		for (int i=1; i <= H; i++) {
			A[i] = input.nextInt();
		}
		input.close();
		buildMaxHeap(A);
		
		// System.out.print(" ");
		for (int i=1; i <= H; i++) {
			System.out.print(" "+A[i]); 
		}
		// System.out.print(" 3 2 1");
		System.out.println();
	}
}


Measured memory_bytes: 171340
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = Integer.parseInt(stdIn.next());
    String s = stdIn.next();
    String t = stdIn.next();

    String[] sChar = s.split("", n);
    String[] tChar = t.split("", n);

    for (int i = 0; i < n; i++) {
      System.out.print(sChar[i] + tChar[i]);
    }
    System.out.println();
  }
}


Measured memory_bytes: 20564
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(S):
    S = S.copy()
    l_ind = np.where(S == -1)[0][:-1] + 1
    r_ind = np.where(S == -1)[0][1:]

    # 逆順にしておく
    N = len(l_ind)
    for i in range(N):
        S[l_ind[i]:r_ind[i]] = S[l_ind[i]:r_ind[i]][::-1]

    # Trie木の構築
    path = np.zeros_like(S)
    child = np.zeros((len(S), 26), np.int64)
    is_end = np.zeros(len(S), np.bool_)

    n_node = 1
    for i in range(N):
        node = 0
        for j in range(l_ind[i], r_ind[i]):
            path[j] = node
            if child[node][S[j]] == 0:
                child[node][S[j]] = n_node
                n_node += 1
            node = child[node][S[j]]
        is_end[node] = True
    child = child[:n_node]
    is_end = is_end[:n_node]
    ans = 0
    for i in range(N):
        se = 0
        for j in range(r_ind[i] - 1, l_ind[i] - 1, -1):
            se |= 1 << S[j]
            node = path[j]
            for k in range(26):
                if se & 1 << k:
                    if is_end[child[node][k]]:
                        ans += 1
    return ans - N

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba import njit, b1, i4, i8, f8
    import numba
    from numba.pycc import CC
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    main = cc_export(main, (i8[:],))
    cc.compile()

from my_module import main

N = int(readline())
S = np.array(list(read().rstrip()), np.int64)

S[S == ord('\n')] = -1
S[S > 0] -= ord('a')
S = np.insert(S, 0, -1)
S = np.append(S, -1)

print(main(S))

Measured memory_bytes: 301108
#include <iostream>
#include <string>

using namespace std;

int main(void){
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++){
		cout << (s[i] - 3 >= 'A' ?(char)(s[i] - 3):(char)(s[i]+23));
	}
	cout << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n];
  int ct = 0,ctmax = 0;
  
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
    if(i>0)
    if(arr[i]<= arr[i-1])
    ct++;
    else{
      if(ct>ctmax)
        ctmax = ct;
      ct = 0;
       if(i>0)
    if(arr[i]<= arr[i-1])
    ct++;
    }
    if(i==(n-1))
    {
        if(ct>ctmax)
        ctmax = ct;
      ct = 0;
    }
  }
 cout<<ctmax; 
  return 0;
}

Measured memory_bytes: 640
n,a,b = gets.split.map(&:to_i)
hp = Array.new(n){ gets.to_i }

def div_ceil(a,b)
  (a + b - 1) / b
end

# x回の攻撃で全てのモンスターのHPをゼロにできるか
query = -> x {
  y = hp.inject(0) do |acc,v|
    r = [v - b * x, 0].max    
    acc += div_ceil(r, a - b)
  end
  y <= x
}

ans = (0..10**9).bsearch{|x| query[x]}
puts ans

Measured memory_bytes: 2812
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define pb(n) push_back(n)
#define endl '\n'
#define debug(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define OUT2(n1,n2) cout << n1 << " " << n2 << endl
#define OUT3(n1,n2,n3) cout << n1 << " " << n2 << " " << n3 << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c; bool flg;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  IN(n);
  vi p(n);
  VIN(p);
  FOR(i,0,n-2) {
    if ((p[i] < p[i+1] && p[i+1] < p[i+2]) || (p[i] > p[i+1] && p[i+1] > p[i+2])) {
      ans++;
    }
  }

  OUT(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int T(char a,char b,char c){
    int ret =0;
    ret+=(int)(a-'0')*100;
    ret+=(int)(b-'0')*10;
    ret+=(int)(c-'0');
    return ret;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int m=s.size(),ans=1000;
    for(int i=0;i<m-2;i++){
        ans=min(ans,abs(753-T(s[i],s[i+1],s[i+2])));
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>p(n+1);
    vector<int>c(n+1);
    for(int i=1;i<=n;i++)
        cin>>p[i];
    for(int i=1;i<=n;i++)
        cin>>c[i];
    long long ans=-1e18;
    for(int i=1;i<=n;i++)
    {
        int cur=i;
        long long sum=0;
        vector<long long> temp;
        while(p[cur]!=i)
        {
            sum+=c[p[cur]];
            temp.push_back(sum);
            cur=p[cur];
        }
        sum+=c[i];
        temp.push_back(sum);
        int sz=(int)temp.size();
        ans=max(ans,*max_element(temp.begin(),temp.begin()+min(k,sz)));
        if(k>sz)
        {
            ans=max(ans,(k/sz)*sum+((k%sz>0)?(*max_element(temp.begin(),temp.begin()+k%sz)):0));
            ans=max(ans,(k/sz-1)*sum+*max_element(temp.begin(),temp.end()));
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3752
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        mut a: [usize;n],
    }
    a.sort();
    println!("{}", a[n-1]-a[0]);
}


Measured memory_bytes: 2140
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <climits>
#include <cmath>
#include <limits.h>
#include <ios>
#include <iomanip>
#include <map> // pair
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b){return b? gcd(b, a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  std::vector<ll> A(5);
  cin >> N;
  for(int i = 0; i < 5; i++){
    cin >> A[i];
  }
  vector<ll>::iterator minIt = min_element(A.begin(), A.end());
  size_t minIndex = std::distance(A.begin(), minIt);
  ll ans = 0;
  ans = (N + (A[minIndex] -1))/A[minIndex] + 4;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<=n;i++){
        if(m-2*i<0)break;
        if((m-2*i)%4==0&&(m-2*i)/4==(n-i)){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3536
import sys
import itertools

n, m = map(int, input().split())

nextList = [set() for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, sys.stdin.readline().split())
    nextList[a].add(b)
    nextList[b].add(a)

count = 0

nodes = range(2, n+1)
for v in itertools.permutations(nodes, n-1):
    now = 1
    error = False
    for i in v:
        if not i in nextList[now]:
            error = True
            break
        now = i
    if error != True:
        count += 1

print(count)



Measured memory_bytes: 39408
N,K=map(int, input().split())
V=list(map(int, input().split()))

#とるか戻すか
ruil=[0]*N
ruil[0]=V[0]

ruir=[0]*N
ruir[0]=V[-1]
for i in range(1,N):
    ruil[i]=ruil[i-1]+V[i]
    ruir[-(i+1)]=ruir[-i]+V[-(i+1)]
#操作何回やるか 0~K
#K回のうちX回とる　K-X回戻す 0~K
#左右の割合　0~X
ans=0
for i in range(K+1):
    if i==0:
        continue
    for j in range(0,i+1):
        if i/2<=j:
            continue
        #j: 戻す回数
        #i-j取る回数
        for k in range(i-j+1):
            if i-j>=N:
                get=V
            else:
                if i-j-k==0:
                    get=V[:k]
                else:
                    get=V[:k]+V[-(i-j-k):]
            get=sorted(get)
            #print(get,i)
            score=sum(get)-sum(get[:j])
            ans=max(ans, score)
            #print(score, get,i-j,j,k)

print(ans)



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int > vi;
typedef pair<int ,int > pii;
typedef vector<pii> vii;
const int inf=0x3f3f3f3f, maxn=100007, mod=1e9+7;
const ll linf=0x3f3f3f3f3f3f3f3fLL;
const ll P=19260817;
int fa[100007];
int n;
int find(int x){
	return x==fa[x]? x: fa[x]=find(fa[x]);
}
struct node{
	int x,y,id;
}a[100007];
bool cmp1(const node& a,const node& b){
	return a.x<b.x;
}
bool cmp2(const node& a,const node& b){
	return a.y<b.y;
}
struct edge{
	int x,y,val;
}e[100005<<2];
bool cmp3(const edge& a,const edge &b){
	return a.val<b.val;
}
int cnt;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].x,&a[i].y),a[i].id=i;
	sort(a+1,a+n+1,cmp1);
	for(int i=1;i<n;i++){
		e[++cnt].x=a[i].id;
		e[cnt].y=a[i+1].id;
		e[cnt].val=abs(a[i].x-a[i+1].x);
	}
	sort(a+1,a+n+1,cmp2);
	for(int i=1;i<n;i++){
		e[++cnt].x=a[i].id;
		e[cnt].y=a[i+1].id;
		e[cnt].val=abs(a[i].y-a[i+1].y);
	}
	sort(e+1,e+cnt+1,cmp3);
	int p=0;
	ll ans=0;
	for(int i=1;i<=cnt;i++){
		int fx=find(e[i].x);
		int fy=find(e[i].y);
		if(fx==fy)continue;
		fa[fx]=fy;
		ans+=e[i].val;
		p++;
		if(p==n-1)break;
	}
	printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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

	vll ans(N + 1, 0);

	repn(i, 200)repn(j, 200)repn(k, 200) {
		ll x = i * i + j * j + k * k + i * j + i * k + k * j;
		if (x <= N) { ans[x]++; }
	}

	repn(i, N) { cout << ans[i] << endl; }
}

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

int main(){

	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if(a >= k){
		cout << k << endl;
	}
	else if(a+b >= k){
		cout << a << endl;
	}
	else{
		cout << a - (k - a - b) << endl;
	}


	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];
int B[101010];

vector<int> V[3];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll S=0;
	FOR(i,N) {
		cin>>A[i];
		S+=A[i];
	}
	FOR(i,N) {
		cin>>B[i];
		S-=B[i];
	}
	if(S<0) return _P("-1\n");
	
	FOR(i,N) {
		if(A[i]>B[i]) V[0].push_back(A[i]-B[i]);
		if(A[i]<B[i]) V[1].push_back(B[i]-A[i]);
	}
	
	
	sort(ALL(V[0]));
	V[2]=V[0];
	sort(ALL(V[1]));
	int num=V[0].size()+V[1].size();
	
	while(V[1].size()) {
		x=min(V[0].back(),V[1].back());
		V[0].back()-=x;
		V[1].back()-=x;
		if(V[0].back()==0) V[0].pop_back();
		if(V[1].back()==0) V[1].pop_back();
	}
	
	FOR(i,V[0].size()) if(V[0][i]==V[2][i]) num--;
	cout<<num<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int gcd3 (int a,int b,int c){
    return gcd (gcd(a,b),c);
}

int main() {

int K;
ll  ans = 0;

cin >> K;

for (int i=1; i<K+1; i++){
    for (int j=1; j<K+1; j++){
        for (int k=1; k<K+1; k++){
            ans += gcd3 (i,j,k);

        }
    }
}

cout << ans << endl;


}


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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

const ll INF = 0x3f3f3f3f3f3f3f3f;

int main() {
    ll x, k, d; cin >> x >> k >> d;
    ll dif = abs(x), mv = dif / d;
    ll ans = INF;
    cerr << mv << endl;
    if (mv > k)
        ans = min(abs(x - k * d), abs(x + k * d));
    else if ((k - mv) % 2 == 0)
        ans = min(abs(x - mv * d), abs(x + mv * d));
    else {
        ans = min(abs(x - (mv + 1) * d), abs(x + (mv + 1) * d));
        ans = min(ans, min(abs(x - (mv - 1) * d), abs(x + (mv - 1) * d)));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
N, X, M = map(int,input().split())

exist = [False] * M 
exist[X] = True

A = [X]

while True:
    nex = A[-1]*A[-1] % M
    A.append(nex)
    if exist[nex]:
        break
    else:
        exist[nex] = True

L = len(A)
idx = 0
for i in range(L):
    if A[i] == A[-1]:
        idx = i
        break

ans = 0
for i in range(idx):
    ans += A[i]
    N -= 1
    if(N < 0): exit()

B = A[idx:(L-1)]

ans += (sum(B)*(N//len(B)) + sum(B[:(N%len(B))]))
print(ans)





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

const int maxN = 2e5 + 10;

int ans, n, m, q;
int mn1, mn2, a[maxN + 1], b[maxN + 1];

int main()
{
	scanf("%d %d %d", &n, &m, &q);
	mn1 = mn2 = 1e9;
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]), mn1 = min(mn1, a[i]);
	for(int i = 1; i <= m; i++) scanf("%d", &b[i]), mn2 = min(mn2, b[i]);

	ans = mn1 + mn2;
	for(int i = 1; i <= q; i++)
	{
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		ans = min(ans, a[x] + b[y] - z);
	}

	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 1024
//#include <bits/stdc++.h>                          //include all library
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
#include <numeric>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1


int main(){
	int N;
	cin >> N;
	vector<pair<int, int>> P(N+1);
	P[0] = make_pair(0, 0);

	for(int i=0; i<N; i++){
		int a, b;
		cin >> a >> b;

		P[i+1] = make_pair(b, a);
	}

	sort(P.begin(), P.end());

	bool flag = true;
	int sum = 0;
	for(int i=0; i<N; i++){
		if(P[i+1].first - sum < P[i+1].second) flag = false;
		sum += P[i+1].second;
	}

	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){

  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  //int pos;
  REP(i,n){
    cin >> a[i];
    //if(a[i] == 1)pos = i;
  }
  ll res = 0;
  res = (n-1+k-2)/(k-1);
  cout << res << endl;



  

  return 0;
}


Measured memory_bytes: 640
N = int(input())
num = 0


def dfs(k, a, b, c):
    global num
    if min(a, b, c) > 0 and int(k) <= int(N):
        num += 1
    elif int(k) > int(N):
        return

    dfs(k + '3', 1, b, c)
    dfs(k + '5', a, 1, c)
    dfs(k + '7', a, b, 1)


dfs('3', 1, 0, 0)
dfs('5', 0, 1, 0)
dfs('7', 0, 0, 1)
print(num)

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

N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
if A[0] != 0:
    ans = -1
else:
    for i in range(1, N)[::-1]:
        d = A[i] - A[i-1]
        if d > 1:
            ans = -1
            break
        if d == 1:
            ans += 1
        else:
            ans += A[i]
print(ans)




Measured memory_bytes: 11052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  int g=f/100;
  double m=0;
  int x,y;
  for(int i=0;i<=g/a;i++){
    for(int j=0;j<=(g-a*i)/b;j++){
      int h=f-100*a*i-100*b*j;
      for(int k=0;k<=h/c;k++){
        for(int l=0;l<=(h-k*c)/d;l++){
          if(i==0&&j==0&&k==0&&l==0) continue;
          if(c*k+d*l<=e*(a*i+b*j)){
            if(c*k+d*l>=m*(a*i+b*j)){
              m=(c*k+d*l)/((a*i+b*j)*1.0);
              x=a*i*100+b*j*100+c*k+d*l;
              y=c*k+d*l;
            }
          }
        }
      }
    }
  }
  cout<<x<<" "<<y<<endl;
}


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

int cnt[200001];
int cover[200001];
int val[200001];

int main()
{
	memset(cnt, 0, sizeof(cnt));
	memset(cover, 0, sizeof(cover));

	int N, M;
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		int a;
		cin >> a;
		val[i] = a;
		cnt[a]++;
		int pos =  a - cnt[a] + 1;
		if (pos > 0) cover[pos]++;
	}
	int exs = 0;
	for (int i = 1; i <= N; i++) {
		if (cover[i] == 0) exs++;
	}
	for (int i = 1; i <= M; i++) {
		int X, Y;
		cin >> X >> Y;
		int minus = val[X];
		int plus  = Y;
		val[X] = Y;
		int pos = minus - cnt[minus] + 1;
		if (pos > 0) {
			if (cover[pos] == 1) exs++;
			cover[pos]--;
		}
		cnt[minus]--;

		cnt[plus]++;
		pos = plus - cnt[plus] + 1;
		if (pos > 0) {
			if (cover[pos] == 0) exs--;
			cover[pos]++;
		}
		cout << exs << endl;
	}

	return 0;
}


Measured memory_bytes: 3840
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

typedef long long int ll; 
typedef pair<int,int> Pii;

int main(){
    int N,D,t,n,m;
    cin >> N >> D;
    t = D*2 + 1;
    n=N;
    m=0;
    while(n>0){
        n-=t;
        m++;
    }
    cout << m;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		long k = Long.parseLong(str[1]);

		long a[] = new long[n];

		str = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		long ans = 0;
		for (int i = 0; i < n; i++) {
			long migi = 0, zentai = 0;
			for (int j = i; j < n; j++)
				if (a[i] > a[j])
					migi++;
			for (int j = 0; j < n; j++)
				if (a[i] > a[j])
					zentai++;

			ans += migi * k % 1000000007;
			ans %= 1000000007;
			ans += (k - 1) * k / 2 % 1000000007 * zentai % 1000000007;
			ans %= 1000000007;
		}

		System.out.println(ans % 1000000007);
	}
}

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

int main()
{
    using namespace std;
    int32_t N;
    string S;
    cin >> N;
    cin >> S;
    
    int32_t x=0, xmax=0;
    for (auto iter = S.begin(); iter != S.end(); ++iter) {
        if (*iter == 'I') {
            x += 1;
        } else {
            x -= 1;
        }
        xmax = max(x, xmax);
    }
    
    cout << xmax << endl;
}

Measured memory_bytes: 256
// AOJ 1326: Stylish
// 2018/1/21

#include <stdio.h>
#include <string.h>

#define INF 100

typedef struct { int r, c, s, i; } T;	// i: indent
T ptbl[11], *pend;
T qtbl[11], *qend;

int ind[11];
char p[11][85];
char q[11][85];

int in()
{
	int n = 0;
	int c = getchar();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar();
	while (c >= '0');
	return n;
}

void calc()
{
	int R, C, S, i, k, r, c, s;
	char *pt;
	T *t;

	r = c = s = 0;
	i = 0; for (t = ptbl; t < pend; t++) {
		pt = p[i++], k = 0; while (*pt == '.') pt++, k++;
		t->r = r, t->c = c, t->s = s, t->i = k;

		while (*pt > ' ') {
			if      (*pt == '(') r++;
			else if (*pt == ')') r--;
			else if (*pt == '{') c++;
			else if (*pt == '}') c--;
			else if (*pt == '[') s++;
			else if (*pt == ']') s--;
			pt++;
		}
	}

	r = c = s = 0;
	i = 0; for (t = qtbl; t < qend; t++) {
		t->r = r, t->c = c, t->s = s;
		pt = q[i++]; while (*pt > ' ') {
			if      (*pt == '(') r++;
			else if (*pt == ')') r--;
			else if (*pt == '{') c++;
			else if (*pt == '}') c--;
			else if (*pt == '[') s++;
			else if (*pt == ']') s--;
			pt++;
		}
	}

	for (R = 1; R <= 20; R++) for (C = 1; C <= 20; C++) for (S = 1; S <= 20; S++) {
		for (t = ptbl; t < pend; t++) {
			if (R * t->r + C * t->c + S * t->s != t->i) goto next;
		}

		for (i = 0, t = qtbl; t < qend; t++, i++) {
			if (ind[i] == -1) continue;
			k = R * t->r + C * t->c + S * t->s;
			if      (ind[i] == INF) ind[i] = k;
			else if (ind[i] != k  ) ind[i] = -1;
		}
next:;
	}
}

int main()
{
	int P, Q, i;

	while (P = in()) {
		Q = in();
		pend = ptbl+P, qend = qtbl+Q;
		for (i = 0; i < P; i++) fgets(p[i], 85, stdin);
		for (i = 0; i < Q; i++) fgets(q[i], 85, stdin);

		for (i = 0; i < Q; i++) ind[i] = INF;
		calc();
		printf("0"); for (i = 1; i < Q; i++) printf(" %d", ind[i]);
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 2024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}


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

  if(s=="SUN")
  {
    cout<<7<<endl;
    return 0;
  }
  if(s=="SAT")
  {
    cout<<1<<endl;
    return 0;
  }
  if(s=="FRI")
  {
    cout<<2<<endl;
    return 0;
  }
  if(s=="THU")
  {
    cout<<3<<endl;
    return 0;
  }
  if(s=="WED")
  {
    cout<<4<<endl;
    return 0;
  }
  if(s=="TUE")
  {
    cout<<5<<endl;
    return 0;
  }
  if(s=="MON")
  {
    cout<<6<<endl;
    return 0;
  }

}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict

n, l = LI()
sums = [l + i for i in range(n)]
sums_sum = sum([l + i for i in range(n)])
if 0 in sums:
    print(sums_sum)
elif l > 0:
    print(sums_sum - l)
else:
    print(sums_sum - sums[-1])

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  map<string,int> jisho;
  for(int i=11;i%10!=0 && i<=99;i++){
    ostringstream oss;
    oss << i;
    jisho[oss.str()]=0;
  }
  for(int i=1;i<=N;i++){
    ostringstream oss;
    oss << i;
    string s = oss.str();
    string key = "";
    key.push_back(s[0]);
    key.push_back(s[s.length()-1]);
//    cout << key << endl;
    jisho[key]++;
  }
  int ans=0;

  for(int i=11;i<=99;i++){
    if (i%10==0) continue;
    ostringstream oss;
    oss << i;
    string s=oss.str();
    string key = "";
    key.push_back(s[s.length()-1]);
    key.push_back(s[0]);
    ans+=jisho[s]*jisho[key];
//    cout << ans << ":" + s +" " << jisho[s]<< endl;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

int main(){
    int k,s; cin >> k >> s;
    int ans=0;
    rep(x,k+1){
        rep(y,k+1){
            int z=s-x-y;
            if(0<=z&&z<=k) ans++;
        }
    }
    cout << ans << endl;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7

using namespace std;

int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};

int32_t main(){
    int h, w;
    cin >> h >> w;

    if(!(h*w%3)){
        cout << 0 << endl;
        return 0;
    }

    int ans=INF;
    FOR(i, 1, h){
        int t=w%2;
        int s[]={i*w, (h-i)*(w/2+t), (h-i)*(w/2)};
        int ma=-INF, mi=INF;

        REP(i, 3){
            ma = max(ma, s[i]);
            mi = min(mi, s[i]);
        }

        ans = min(ans, ma-mi);
    }

    swap(h, w);
    FOR(i, 1, h){
        int t=w%2;
        int s[]={i*w, (h-i)*(w/2+t), (h-i)*(w/2)};
        int ma=-INF, mi=INF;

        REP(i, 3){
            ma = max(ma, s[i]);
            mi = min(mi, s[i]);
        }

        ans = min(ans, ma-mi);
    }

    ans = min(ans, min(w, h));

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  int cnt=0;
  cin >> n;
  vector<int>p(n);
  for(int i=0;i<n;i++) cin >> p[i];
  for(int i=1;i<n-1;i++){
    if(p[i-1] < p[i] && p[i]<p[i+1]) cnt++;
    else if(p[i-1] > p[i] && p[i]>p[i+1]) cnt++;
  }
  cout<< cnt <<endl;
}


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

int main() {
  cout << setprecision(15);
  int n;
  cin >> n;
  int small = 9 - 1 + 1;
  int middle = 999 - 100 + 1;
  int large = 99999 - 10000 + 1;
  if      (n <= 9) cout << n << endl;
  else if (n <= 99) cout << small << endl;
  else if (n <= 999) cout << n - 100 + 1 + small << endl;
  else if (n <= 9999) cout << middle + small << endl;
  else if (n <= 99999) cout << n - 10000 + 1 + middle + small << endl;
  else cout << large + middle + small << endl; 
  return 0;
}


Measured memory_bytes: 256
def insertion_sort a, n, g
  g.upto(n-1) do |i|
    k = a[i]
    j = i - g
    while j >= 0 && k < a[j]
      a[j+g] = a[j]
      $cnt += 1
      j -= g
    end
    a[j+g] = k
  end

  a
end

def calc_ms n
  ms = []
  c = 0
  i = 1
  while c < 100 && i <= n
    ms << i
    i = 3 * i + 1
    c += 1
  end

  return c, ms.reverse
end

len = gets.to_i
arr = readlines.map(&:chomp).map(&:to_i)
$cnt = 0

m_length, ms = calc_ms len
ms.each do |m|
#  arr = insertion_sort arr, len, m
  insertion_sort arr, len, m
end

puts m_length
puts ms.join(" ")
puts $cnt
puts arr.join("\n")


Measured memory_bytes: 158704
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys


n = int(sys.stdin.readline().rstrip())
Xn = list(map(int, sys.stdin.readline().rstrip().split()))
Xn_s = sorted(Xn)
c_l = Xn_s[n//2-1]
c_r = Xn_s[n//2]
for x in Xn:
  if x <= c_l:
    print(c_r)
  elif x>= c_r:
    print(c_l)

Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define ll long long
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll tyo=(ll)1e12*2;
using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  for(int i=1;i<=2000;i++){
    if((int)(i*0.08)==A&&(int)(i*0.1)==B){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<"-1"<<endl;
}

Measured memory_bytes: 256
"""
c_r_5さんの
https://atcoder.jp/contests/practice2/submissions/16626085
を参考に
"""

code = """
# distutils: language=c++
# distutils: include_dirs=[/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include, /opt/atcoder-stl]
# cython: boundscheck=False
# cython: wraparound=False
cdef extern from "/opt/atcoder-stl/atcoder/math.hpp" namespace "atcoder" nogil:
    cdef long long floor_sum(long long n, long long m, long long a, long long b)

cpdef long long FloorSum(long long n, long long m, long long a, long long b):
    return floor_sum(n, m, a, b)
"""
import os,sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('atcoder.pyx','w').write(code)
    os.system('cythonize -i -3 -b atcoder.pyx')
  
import sys
from atcoder import FloorSum

N = int(input())
for i in range(N):
    print(FloorSum(*list(map(int,input().split()))))

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N;
string S;
vector<P> res;

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

  cin>>S;
  N=S.size();
  if(S[0]=='0'||S[N-1]=='1'){
    cout<<-1<<endl;
    return 0;
  }
  {
    bool ok=true;
    rep(i,N-1){
      if(S[i]!=S[N-2-i])ok=false;
    }
    if(!ok){
      cout<<-1<<endl;
      return 0;
    }
  }
  ll r=0,sz=1,idst=1;
  repl(i,1,N/2){
    if(S[i]=='0')continue;
    ll cnt=i-sz;
    ll nxtr=idst;
    ll idx=idst+1;
    res.push_back(P(nxtr,r));
    while(cnt>0){
      res.push_back(P(nxtr,idx++));
      cnt--;
    }
    r=nxtr; sz=i+1; idst=idx;
  }
  ll cnt=N-1-sz;
  ll nxtr=idst;
  ll idx=idst+1;
  res.push_back(P(nxtr,r));
  while(cnt>0){
    res.push_back(P(nxtr,idx++));
    cnt--;
  }
  rep(i,N-1){
    cout<<res[i].fi+1<<" "<<res[i].se+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 3264
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * ハッシュ
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=ja">ALDS1_4_C</a>
 */
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<String, Integer> map = new HashMap<>();

		for (int i = 0; i < n; i++) {
			String command = sc.next();
			String str = sc.next();
			if ("insert".equals(command)) {
				if (!map.containsKey(str)) {
					map.put(str, 1);
				}
			} else {
				if (map.containsKey(str)) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}

		sc.close();
	}

}



Measured memory_bytes: 254072
#include <stdio.h>

int main (void)

{

int W,H,x,y,r;

   scanf("%d""%d""%d""%d""%d",&W,&H,&x,&y,&r);

   if(r <= x&&r <= y&&x+r <= W&&y+r <= H){

   printf("Yes\n");

 }

 else{

  printf("No\n");

 }

return 0;

}

Measured memory_bytes: 584
num=[]
n=int(input())
while n!=0:
    if abs(n)%2==1:
        num.append("1")
        n=(n-1)//(-2)
    else:
        num.append("0")
        n=n//(-2)
if len(num)==0:
    num=["0"]
print("".join(num[::-1]))

Measured memory_bytes: 38256
X = int(input())

if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
elif 1800 <= X <= 1999:
    print(1)

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

namespace B___Shiritori
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            var a = new string[n];
            var hs = new HashSet<string> ();
            for (var i = 0; i < n; i++)
            {
                a[i] = Console.ReadLine ();
                hs.Add (a[i]);
            }
            if (a.Length > hs.Count)
            {
                Console.WriteLine ("No");
                return;
            }
            for (var i = 1; i < n; i++)
            {
                if (a[i - 1][a[i - 1].Length - 1] != a[i][0])
                {
                    Console.WriteLine ("No");
                    return;
                }
            }
            Console.WriteLine ("Yes");
        }
    }
}

Measured memory_bytes: 11348
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long int
int main(){
    ll a, b, c, k;
    cin>>a>>b>>c>>k;
    ll aa[a+1], bb[b+1], cc[c+1], m1[k*k+1], m2[k*k+1];
    for (ll i=1; i<=a; i++) cin>>aa[i];
    for (ll i=1; i<=b; i++) cin>>bb[i];
    for (ll i=1; i<=c; i++) cin>>cc[i];
    sort (aa+1, aa+a+1, greater <ll> ()), sort (bb+1, bb+b+1, greater <ll> ()), sort (cc+1, cc+c+1, greater <ll> ());
    for (ll i=1; i<=min(a, k); i++){
        for (ll j=1; j<=min(b, k); j++){
            m1[(i-1)*min(b, k)+j]=aa[i]+bb[j];
        }
    }
    sort (m1+1, m1+min(a, k)*min(b, k)+1, greater <ll> ());
    for (ll i=1; i<=min(min(a, k)*min(b, k), k); i++){
        for (ll j=1; j<=min(c, k); j++){
            m2[(i-1)*min(c, k)+j]=m1[i]+cc[j];
        }
    }
    sort (m2+1, m2+min(min(a, k)*min(b, k), k)*min(c, k)+1, greater <ll> ());
    for (ll i=1; i<=k; i++) cout<<m2[i]<<endl;
}

Measured memory_bytes: 35840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()

{
  //int A, B, C, X, Y;
  char s[101]={};
//  int a, b, c;
  int a[20000]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int min=101;
  int max=0;

  long cnt =0;
  long long A_temp;
//    int k=0;

//  scanf("%d", &a);
//  A_temp = A;
//  printf("%s\n", s);

  for(i=0;i<3;i++){
    scanf("%d", &a[i]);
    if(min>a[i]) min=a[i];
    if(max<a[i]) max=a[i];
  }
  
   printf("%d\n", max-min);   
//else printf("No\n");  
  
return 0;
}


Measured memory_bytes: 256
import java.io.*
import java.util.*

val pw = PrintWriter(System.out)
fun solve(N: Int, A: IntArray){
    // [3, 5, -1, 0] -> [3, 5, 11, 12]
    val cumSum = (0..N)
        .map{ Math.abs(A.getOrElse(it){ 0 } - A.getOrElse(it - 1){ 0 }) }
        .scanLeft(0){ a, b -> a + b }
        .toList()
        .last()!!
    repeat(N){
        val a = A.getOrElse(it - 1){ 0 }
        val b = A[it]
        val c = A.getOrElse(it + 1){ 0 }
        val (m, M) = Math.min(a,c) to Math.max(a, c)
        if (b < m) pw.println(cumSum - 2 * Math.abs(b-m))
        else if (b < M) pw.println(cumSum)
        else  pw.println(cumSum - 2 * Math.abs(b-M))
    }
    pw.flush()
    return
}

fun <T, R> Iterable<T>.scanLeft(initial: R, operation: (acc: R, T) -> R): Sequence<R> {
    var last = initial
    return this.asSequence().map { last = operation(last, it); last }
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val A = IntArray(N)
    for (i in 0 until N) {
        A[i] = sc.next().toInt()
    }
    solve(N, A)
}



Measured memory_bytes: 54856
/* To Kaise Hain Aaplog*/

/* Yalgaar Ho */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

const ll mod = 1e9 + 7;

int main()
{
    //shuru_krte_hai_bina_kisi_bakchodi_ke();
    int x,y;
    cin>>x>>y;
    if(y>4*x || y%2 || y<2*x){
        cout<<"No"<<"\n";
    }else{
        cout<<"Yes"<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3608