akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  long long N, x; cin >> N >> x;
  vector<long long> a(N);
  long long sum = 0;
  long long cnt = 0;
  for(long long i = 0; i < N; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  if(a[0] >= x) a[0] = x;
  for(int i = 1; i < N; ++i) {
    a[i] = min(a[i], x-a[i-1]);
  }
  for(int i = 0; i < N; ++i) cnt += a[i];
  cout << sum - cnt << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


/* SegTree<X>(n,fx,ex): モノイド(集合X, 二項演算fx, 単位元ex)についてサイズnで構築
    set(int i, X x), build(): i番目の要素をxにセット。まとめてセグ木を構築する。O(n)
    update(i,x): i 番目の要素を x に更新。O(log(n))
    query(a,b):  [a,b) 全てにfxを作用させた値を取得。O(log(n))
*/
template <typename X>
struct SegTree {
    using FX = function<X(X, X)>;
    int n;
    FX fx;
    const X ex;
    vector<X> dat;
    SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
 
    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }
 
    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
 
    // the minimum element of [a,b)
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return ex;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
    /* debug */
    inline X operator[](int a) { return query(a, a + 1); }
    void print() {
        for (int i = 0; i < n; ++i) {
            cout << (*this)[i];
            if (i != n) cout << ",";
        }
        cout << endl;
    }
};

int main(){
  int N; string S; cin >> N >> S;
  int Q; cin >> Q;
  using X = int;
  X ex = 0;
  auto fx = [](X x1, X x2) -> X{return x1 | x2;};
  SegTree<X> seg(N, fx, ex);
  rep(i, N){
    X x = 1<<(S[i] - 'a');
    seg.set(i, x);
  }
  seg.build();
  rep(i, Q){
    int a; cin >> a;
    if(a==1){
      int b; char c; cin >> b >> c; b--;
      X k = 1<<(c - 'a');
      seg.update(b, k);
    }
    else{
      int d, e; cin >> d >> e; d--;
      X ans = seg.query(d, e);
      cout << __builtin_popcount(ans) << endl;
    }
  }
}

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

int main()
{
    long long n,k;cin>>n>>k;
    long long ans=0;
    if(k%2==0)
    {
        long long half=n/(k/2)-n/k;
        ans=(n/k)*(n/k)*(n/k)+half*half*half;
    }
    else
    {
        ans=(n/k)*(n/k)*(n/k);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int factorial(int n)
{
  return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}
int main()
{
  ll i,n;
  cin>>n;
  vector<ll> a(n), b(n);
  for(i=0;i<n;i++) cin>>a[i];
  for(i=0;i<n;i++) cin>>b[i];
  map<vector<ll>, ll> mp;
  vector<ll> start(n);
  for(i=0;i<n;i++) start[i] = i+1;
  mp[start] = 1;
  for(i=2;i<=factorial(n);i++)
  {
   next_permutation(start.begin(), start.end());
   mp[start] = i;
  }
  cout<<abs(mp[a] - mp[b]);
  return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     int n,m,a,b,i,j;
     cin>>n>>m>>a>>b;
	 if(n/2<b || m/2<a)
	 {
		 cout<<"-1\n";
		 return 0;
	 }
	 for(i=0;i<n;i++)
	 {
		 for(j=0;j<m;j++)
			cout<<((i<b)^(j<a));
		 cout<<'\n';
	 }
}


Measured memory_bytes: 1280
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long N = scan.nextLong();
        if(N<10)System.out.println(N);
        else{
            int ans = 0;
            boolean all = true;
            while(N>0){

                if(N<10)ans += N-1;
                else{
                    all &= (N%10==9);
                    ans += 9;
                }
                N/=10;
            }
            if(all)++ans;
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 21844
S = input()
T = input()

ans = 1000000  # 適当に1001以上を初期値にしておきます

# Tが1文字のときlen(S)回、2文字のときlen(S) - 1回 …… なので、
# len(S) - len(T) + 1 パターンあります

for i in range(len(S) - len(T) + 1):
    score = 0
    U = S[i:i + len(T)]  # Sのi文字目から連続するlen(T)文字を、Uとします
    for j in range(len(T)):
        if U[j] != T[j]:
            score += 1
    ans = min(ans, score)

print(ans)


Measured memory_bytes: 73444
use std::io::{Read, Write};

struct CustomIO<'a> {
    sin: ::std::io::Bytes<::std::io::StdinLock<'a>>,
    sout: ::std::io::StdoutLock<'a>,
    buf: [u8; 20],
}
impl<'a> CustomIO<'a> {
    pub fn new(
        sin: ::std::io::Bytes<::std::io::StdinLock<'a>>,
        sout: ::std::io::StdoutLock<'a>,
    ) -> Self {
        CustomIO::<'a> {
            sin: sin,
            sout: sout,
            buf: [0u8; 20],
        }
    }

    pub fn readu32(&mut self) -> u32 {
        self.sin
            .by_ref()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0u32, |a, x| a * 10 + (x as u8 - b'0') as u32)
    }

    pub fn readu64(&mut self) -> u64 {
        self.sin
            .by_ref()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0u64, |a, x| a * 10 + (x as u8 - b'0') as u64)
    }

    pub fn readusize(&mut self) -> usize {
        self.sin
            .by_ref()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0usize, |a, x| a * 10 + (x as u8 - b'0') as usize)
    }

    pub fn writeu32(&mut self, mut v: u32) {
        let mut i = 20usize;
        while v != 0u32 {
            i -= 1usize;
            self.buf[i] = (v % 10) as u8 + b'0';
            v /= 10;
        }
        if i == 20usize {
            i = 19usize;
            self.buf[19] = b'0';
        }
        let _ = self.sout.write(&self.buf[i..20]);
    }

    pub fn writeu64(&mut self, mut v: u64) {
        let mut i = 20usize;
        while v != 0u64 {
            i -= 1usize;
            self.buf[i] = (v % 10) as u8 + b'0';
            v /= 10;
        }
        if i == 20usize {
            i = 19usize;
            self.buf[19] = b'0';
        }
        let _ = self.sout.write(&self.buf[i..20]);
    }

    pub fn writeusize(&mut self, mut v: usize) {
        let mut i = 20usize;
        while v != 0usize {
            i -= 1usize;
            self.buf[i] = (v % 10) as u8 + b'0';
            v /= 10;
        }
        if i == 20usize {
            i = 19usize;
            self.buf[19] = b'0';
        }
        let _ = self.sout.write(&self.buf[i..20]);
    }
}

fn main() {
    let stdin = ::std::io::stdin();
    let stdout = ::std::io::stdout();
    let mut cio = CustomIO::new(stdin.lock().bytes(),stdout.lock());

    let n= cio.readusize();
    let m= cio.readusize();
    let mut from1 = vec![false; n + 1];
    let mut fromn = vec![false; n + 1];
    for _ in 0..m {
        let a= cio.readusize();
        let b= cio.readusize();
        from1[b] |= a == 1;
        from1[a] |= b == 1;
        fromn[b] |= a == n;
        fromn[a] |= b == n;
    }
    let flg = from1
        .iter()
        .zip(fromn.iter())
        .fold(false, |acc, (&a, &b)| acc || a && b);
    println!("{}", if flg { "POSSIBLE" } else { "IMPOSSIBLE" });
}


Measured memory_bytes: 4352
K = int(input())

#再帰で実装できそう？

memo = set([])

PM = [-1,0,1]

def rec(n):
    if n > 3234566667:
        return
    ichi = n % 10
    for pm in PM:
        if (ichi + pm) != -1 and (ichi + pm) != 10:
            m = n*10 + ichi + pm
            if m not in memo:
                # print(m)
                # if m == 9900:
                #     print(n,ichi + pm)
                memo.add(m)
                rec(m)
    return

for i in range(1,10):
    memo.add(i)
    rec(i)



# rec(9)



memo = list(memo)
memo.sort()

# print(memo[:100])
# print(len(memo))
            
print(memo[K-1])           
            
    


Measured memory_bytes: 116408
import java.util.Scanner;

//Card Game
public class Main {

	int[] g, j;
	boolean[] u;
	int res;

	void dfs(int k, int pa, int pb) {
		int p, q;
		if (k == 9) {
			if (pb < pa) {
				res++;
			}
			return;
		}
		for (int i = 0; i < 9; i++) {
			if (!u[i]) {
				u[i] = true;
				if (j[k] < g[i]) {
					p = g[i] + j[k];
				} else {
					p = 0;
				}
				if (j[k] < g[i]) {
					q = 0;
				} else {
					q = g[i] + j[k];
				}
				dfs(k + 1, pa + p, pb + q);
				u[i] = false;
			}
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while (T-- != 0) {
			g = new int[9];
			j = new int[9];
			u = new boolean[9];
			for (int i = 0; i < 9; i++)
				g[i] = sc.nextInt();
			for (int i = 0; i < 9; i++)
				j[i] = sc.nextInt();
			res = 0;
			dfs(0, 0, 0);
			double x = res * 1.0 / 362880;
			System.out.printf("%.5f %.5f\n", x, 1 - x);
		}
	}

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

Measured memory_bytes: 18992
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
  
using namespace std;
const int inf = 1e9 + 7;




signed main() {
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif*/

    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);

    cout << a << " " << b << " " << c;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
while True:
    n = int(raw_input())
    if n == 0:
        break
    else:
        IDdic={}
        for k in range(n):  
            ID, p, q = map(int,raw_input().split())
            if ID not in IDdic:
                IDdic[ID] = [k, p*q]
            elif ID in IDdic:
                IDdic[ID][1] += p*q

        # IDの出現順はIDdic[ID][0] (=k)で確認できる
        temp = []        
        for key in IDdic.keys():
            m=0
            if IDdic[key][1] >=1000000 :
                m+=1
                temp.append((IDdic[key][0],key))
                temp=sorted(temp)
        for sortedID in temp:
            print sortedID[1]
        if temp==[]:
            print "NA"

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main(){

	vector<bool> used(1000000);
	set<ll> prime;
	
	REP(i, 2, 1000000){
		if(!used[i]) prime.insert(i);
		for(int j = 1; i * j < 1000000; j++){
			used[i*j] = true;
		}
	}
	
	int n;
	while(cin >> n){
		auto it = upper_bound(prime.begin(), prime.end(), n);
		cout << distance(prime.begin(), it) << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 6324
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, k = inpl()
a = inpl()
dp = [(0, 0)] * n
changed = set(range(n))
for j in range(k):
    for i in changed:
        l = max(0, i - a[i])
        r = min(n - 1, i + a[i])
        dp[i] = (l, r)
    imos = [0] * n
    for i in range(n):
        l, r = dp[i]
        imos[l] += 1
        if r < n - 1:
            imos[r + 1] -= 1
    tmp = 0
    for i in range(n):
        tmp += imos[i]
        a[i] = tmp
    if imos[0]==n:
        break
print(*a)


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

#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<"\n"
#define prints(a) for(auto i: a) cout<<i<<" "; cout<<"\n"
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e]

int main()
{
	fastio;
	int x, y, flag = 1;
	cin>>x>>y;

	for(int i=0; i<=x && flag; i++){
		if((2*i + 4*(x-i))==y){
			cout<<"Yes\n";
			flag = 0;
		}
	}

	if(flag)
		cout<<"No\n";

	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
using namespace std;
int x;
int y;
void musaMap(){

}
int main(){
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){

    cin >> x >> y;
    int p;
    cin >> p;
    vector<int> mfX(p);
    vector<int> mfY(p);
    vector<int> mtX(p);
    vector<int> mtY(p);

    for(int j = 0;j < p;j++){
      cin >> mfX[j] >> mfY[j] >> mtX[j] >> mtY[j];
    }
    int dx[2] = {0,1};
    int dy[2] = {1,0};
    
    vector<vector<int> > dp(y+2,vector<int>(x+2,0));
    dp[0][0] = 1;
    for(int j = 0;j < x+1;j++){
      for(int k = 0;k < y+1;k++){
	//	cout << j << " " << k << endl;
	int flag[2] = {0,0};
	for(int l = 0;l < p;l++){
	  for(int m = 0;m < 2;m++){
	    if(mfX[l] == j && mfY[l] == k){
	      if(mtX[l] == j+dx[m] && mtY[l] == k+dy[m]){
		flag[m] = 1;
	      }
	    }
	    if(mtX[l] == j && mtY[l] == k){
	      if(mfX[l] == j+dx[m] && mfY[l] == k+dy[m]){
		flag[m] = 1;
	      }
	    }
	  }
	}
	for(int l = 0;l < 2;l++){
	  if(flag[l] != 1){
	    //	    cout << l << endl;
	    //cout << dx[l] << dy[l] << endl;
	    dp[k+dy[l]][j+dx[l]] = dp[k+dy[l]][j+dx[l]] + dp[k][j];
	    //cout << k+dx[l] <<"   " <<k+dy[l] << endl;
	  }
	  
	}
      }
    }/*
    cout << "--------------" << endl;
    for(int j = 0;j < y+1;j++){
      for(int k = 0;k < x+1;k++) {
	cout << dp[j][k] << " ";
      }
      cout << endl;
    }
    cout << "--------------" << endl;*/
    if(dp[y][x] == 0){
      cout << "Miserable Hokusai!" << endl;
    }else{
      cout << dp[y][x] << endl;
    }
    
  }
  
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define s second
ll power(ll x, ll y, long long int mod = 1000000007){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
using namespace std;

int main() {
    fastio;
    int n, w;
    cin >> n >> w;
    int wt[n+1], v[n+1];
    ll dp[n+1][w+1];
    
    for(int i = 0; i <= n; i++) 
        for(int j = 0; j <= w; j++) 
            dp[i][j] = 0;
    
    for(int i = 1; i <= n; i++) {
        cin >> wt[i] >> v[i];
    }
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= w; j++) {
            //cout << wt[i] << " ";
            if(j >= wt[i]) {
                dp[i][j] = max((v[i] + dp[i-1][j-wt[i]]), dp[i-1][j]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    cout << dp[n][w] << endl;
}

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

string fill(string s) {
  while (s.size() < 6) s = "0" + s;
  return s;
}

string create_id(int p, int o) {
  return fill(to_string(p)) + fill(to_string(o));
}

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

  int n, m; cin >> n >> m;
  vector<int> p(m);
  vector<int> y(m);
  for (int i = 0; i < m; i++) cin >> p[i] >> y[i];
  vector<vector<vector<int>>> db(n + 1);
  for (int i = 0; i < m; i++) {
    db[p[i]].push_back({y[i], i});
  }
  vector<string> res(m);
  for (int i = 1; i < n + 1; i++) {
    sort(db[i].begin(), db[i].end());
    for (int j = 0; j < db[i].size(); j++) {
      res[db[i][j][1]] = create_id(i, j + 1);
    }
  }
  for (string &id : res) {
    cout << id << '\n';
  }
  return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {  
    int A,B;
    cin >> A >> B;
    if( A >= 10 || B >= 10){
        cout << -1 << endl;
        return 0;
    }
    else cout << A*B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  string S;
  cin >> S;
  int mx = 0;
  int cnt = 0;
  rep(i, 0, S.size()) {
    if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      cnt++;
      mx = max(mx, cnt);
    }
    else cnt = 0;
  }
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>
 
#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
void runtime(){cout<<fixed<<setprecision(5)<<1.0*clock()/CLOCKS_PER_SEC<<endl;}

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <class T>void read(vector<T> &a,int n){T x; a.clear();for(int i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}

int k;
string s;

int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
    
    cin>>k>>s;
    if(s.size()<=k)
        cout<<s<<"\n";
    else
    {
        for(int i=0;i<k;i++)
            cout<<s[i];
        cout<<"...\n";
    }
}


Measured memory_bytes: 3172
/// @file

#include <algorithm>
#include <iostream>
#include <string>

namespace {

bool run(std::istream& is, std::ostream& os);
}  // unnamed namespace

/// @brief エントリポイント
#ifdef _TEST
static int run()
#else
int main()
#endif
{
  try {
    if (run(std::cin, std::cout) == false) {
      std::cerr << "main funciton error.\n";
      return EXIT_FAILURE;
    }
  } catch (const std::exception& e) {
    std::cerr << "catch exception\n";
    std::cerr << e.what() << "\n";
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}

namespace {

/// @brief 実行処理
bool run(std::istream& is, std::ostream& os)
{
  const char SEARCH_CHAR('2');
  std::string n;
  is >> n;

  const std::size_t COUNT
    = std::count(n.begin(), n.end(), SEARCH_CHAR);
  os << COUNT << '\n';
  return true;
}
}  // unnamed namespace


Measured memory_bytes: 256
#!/usr/bin/env python3

N,K = [int(i) for i in input().split()]

if N == 0 or N % K == 0:
    ans = 0
elif N > K:
    ans = N % K
    ans = min(ans, abs(ans - K))
else:
    ans = min(N, abs(N - K))
    ans = min(ans, abs(ans - K))

print(ans)


Measured memory_bytes: 9184
( A, B, C, D ) = gets.split(' ').map(&:to_i)
E = C.lcm(D)
result = B.div(C) - (A-1).div(C) + B.div(D) - (A-1).div(D) - (B.div(E) - (A-1).div(E))
puts (B - A + 1) - result


Measured memory_bytes: 1788
#include<stdio.h>

int main(){
	int x;
	int y;
	scanf ("%d %d",&x,&y);
	int IR = 100*(10-x);
	
	int IRT = y+ IR;
	if(x<=10){
			printf("%d",IRT);
	}
	else {
		printf("%d",y);
	}
	
	
	return 0;
}

Measured memory_bytes: 3232
from itertools import permutations
from math import factorial
n=int(input())
A=[list(map(int,input().split())) for i in range(n)]

cnt=0
for i in permutations(A,n):
    for j in range(1,n):
        cnt +=((i[j-1][0]-i[j][0])**2+(i[j-1][1]-i[j][1])**2)**0.5
print(cnt/factorial(n))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;






int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    map <int,int>m;
    for(int i =0;i < n;i++){
        int no;
        cin>>no;
        m[no+1]++;
        m[no]++;
        m[no-1]++;
    }
    int maxi = 0,ans;
    tr(it,m){
        if(it->second >maxi){
            maxi = it->second;
            ans = it->first;
        }
    }
    cout<<maxi<<endl;








}















































Measured memory_bytes: 6144
from  math import gcd
 
 
k = int(input())
sum_c = 0
 
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum_c += gcd(gcd(a, b), c)
            
print(sum_c)

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

int main() {
    #define int long long int
	int n,w;
	cin>>n>>w;
	int knapsack[n+1][2];
	for(int i=1;i<=n;i++){
	    cin>>knapsack[i][0];
	    cin>>knapsack[i][1];
	}
	vector <vector <int>> dp(n+1,vector<int>(w+1,0));
	for(int i=1;i<=n;i++){
	    for(int j=0;j<=w;j++){
	        if(j-knapsack[i][0]>=0){
	            dp[i][j]=max(dp[i-1][j],dp[i-1][j-knapsack[i][0]]+knapsack[i][1]);
	        }
	        else dp[i][j]=dp[i-1][j];
	    }
	}
	cout<<dp[n][w]<<endl;
	
	return 0;
}

Measured memory_bytes: 83176
let ab_s = Array.init 3 @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a - 1, b - 1
let ds = Array.make 4 0
let _ = Array.(iter (fun (a, b) -> ds.(a) <- ds.(a) + 1; ds.(b) <- ds.(b) + 1) ab_s; print_endline @@ if List.for_all (fun d -> d <= 2) @@ to_list ds then "YES" else "NO")

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int n;cin >> n;
    ll sum=0;
    vector<ll> a(n);
    for(int i=0;i<n;i++) {
        cin >> a[i];
        sum += a[i];
    }

    vector<ll> ans(n);
    for(int i = 1; i < n; i+= 2) {
        sum -= 2*a[i];
    }
    ans[0]=sum;

    for(int i = 1; i < n; i++) {
        ans[i]=2 * a[i-1] -ans[i-1];
    }

    for(int i = 0; i < n-1; i++) {
        cout << ans[i] << ' ';
    }
    cout << ans[n-1] << endl;

    return 0;
}

Measured memory_bytes: 4760
import sys
n=int(input())
s=list(input())

if n%2!=0:
  print('No')
  sys.exit()

        
a=s[:n//2]
b=s[n//2:]

cnt=0
for i in range(n//2):
  if a[i]!=b[i]:
    cnt+=1

if cnt==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9152
using System;

class Program
{
    static void Main()
    {
        int S = int.Parse(Console.ReadLine());

        int h = S / 3600;
        int m = (S % 3600) / 60;
        int s = (S % 3600) % 60;

        System.Console.WriteLine("{0}:{1}:{2}", h, m, s);
    }
}

Measured memory_bytes: 9220
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = sc.next();

        int count = 0;
        for (int i = 0; i < s1.length(); i++) {
           if (s1.charAt(i) != s2.charAt(i)) {
               count++;
           }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 41236
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=100005;
int n,a[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int ans=0;
	for(int l=1,r=1;l<=n;l++){
		while(r<n&&a[r+1]-a[l]<=2) r++;
		ans=max(ans,r-l+1);
	}
	printf("%d\n",ans);
	return 0;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 200001

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, l;
    cin >> n >> l;
    ll s = 0;
    vi a(n);
    REP(i, 0, n) {
        a[i] = i+1;
        a[i] += l-1;
        s += a[i];
    }
    ll m = LLONG_MAX, x, p;
    REP(i, 0, n) {
        x = s - a[i];
        if (abs(s - x) < m) {
            m = abs(s-x);
            p = a[i];
        }
    }
    cout << s - p << endl;
    return 0;
}


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

int six(int x, int y) {
	return 6 * x + y;
}
int main() {
	int n;
	cin >> n;
	if (n == 3) {
		cout << 2 <<" "<< 3<<" " << 25 << endl;
	}
	else if (n == 4) {
		cout << 2 << " " << 5 << " " << 20 << " " << 63 << endl;
	}
	else {
		cout << 2 << " " << 3 << " " << 4 << " " << 6 << " ";
		int last = 6;
		int wa = 3;
		int cnt = 15;
		for (int i = 1; (i+1)*4 < n; i++) {
			cout << six(i, 2) << " " << six(i, 3) << " " << six(i, 4) <<" " << six(i, 6) << " ";
			last+=6;
			cnt += 1;
		}
		if (n %4 ==2) {
			cout << last + 3 << " ";
			cnt += 1;
		}
		else if (n %4== 3) {
			cout << last + 2 << " " << last + 4 << " ";
		}
		else if (n %4 == 0) {
			cout << last + 2 << " " << last + 3 << " " << last + 4 << " ";
			cnt += 1;
		}
		if (cnt % 2 == 1&&last+9<=30000) {
			cout << last + 9 << endl;
		}
		else if (cnt % 2 == 1 && last + 9 > 30000) {
			cout << last + 3 << endl;
		}
		else {
			cout << last + 6 << endl;
		}
	}
}

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

using namespace std;

int main() {
  int n;
  string s;
  map<string, int> c;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    c[s] += 1;
  }

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    c[s] -= 1;
  }

  int max = -1;
  for (auto p = c.begin(); p != c.end(); p++) {
    if (p->second > max) max = p->second;
  }

  cout << (max < 0 ? 0 : max) << endl;
  return 0;
}

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

int main(){
	int n,l;
	cin>>n>>l;
	string wor[n];
	for (int i = 0; i < n; i++){
		cin>>wor[i];
	}
	sort(wor, wor + n);
	for (int i = 0; i < n; i++){
		cout<<wor[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

struct LazySegTree {
	vector<ll> node, lazy;
	int n;
	
	LazySegTree(int _n) {
		n = 1;
		while (n < _n) n *= 2;
		
		node.resize(n * 2 - 1, 0);
		lazy.resize(n * 2 - 1, 0);
	}
	
	void eval(int k, int l, int r) {
		if (lazy[k] == 0) return;
		node[k] += lazy[k];
		if (r - l > 1) {
			lazy[k * 2 + 1] += lazy[k];
			lazy[k * 2 + 2] += lazy[k];
		}
		lazy[k] = 0;
	}
	
	void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		
		if (a >= r || b <= l) return;
		if (a <= l && r <= b) {
			lazy[k] += x;
			eval(k, l, r);
		}
		else {
			add(a, b, x, k * 2 + 1, l, (l + r) / 2);
			add(a, b, x, k * 2 + 2, (l + r) / 2, r);
			node[k] = max(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	
	ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		eval(k, l, r);
		
		if (a >= r || b <= l) return -1ll<<60;
		if (a <= l && r <= b) return node[k];
		return max( query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r) );
	}
};

int N, M;
int L[212345], R[212345];

int main() {
	cin >> N >> M;
	REP(i, N) scanf("%d %d", L + i, R + i);
	
	vector<pll> v(N);
	REP(i, N) v[i] = pii(L[i], R[i]);
	sort(ALL(v));
	
	LazySegTree seg(212345);
	REP(i, M + 2) seg.add(i, i + 1, i);
	
	int ans = max(N - M, 0);
	
	REP(i, N) {
		int l = v[i].fi, r = v[i].se;
		
		seg.add(1, r + 1, 1);
		chmax(ans, seg.query(1, M + 2) - (M + 1 + l) );
	}
	
	cout << ans << endl;
	
	return 0;
}


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

typedef long long lint;
#define M 1000000007

int main(){
    lint n,m;
    cin >> n >> m;
    lint *x,*y;
    x=new lint[n];
    y=new lint[m];
    for(int i=0;i<n;i++) cin >> x[i];
    for(int i=0;i<m;i++) cin >> y[i];

    lint ax=0,ay=0;
    for(lint i=1;i<n;i++){
        ax+=(x[i]-x[i-1])*i%M*(n-i)%M;
        ax%=M;
    }
    for(lint i=1;i<m;i++){
        ay+=(y[i]-y[i-1])*i%M*(m-i)%M;
        ay%=M;
    }
    cout << (ax*ay%M) << endl;

    delete[] x,y;
    return 0;
}

Measured memory_bytes: 1792
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;

const ll MOD = 1e9+7;

ll pow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 0b01) { 
            res *= a;
            res %= MOD;
        }
        a = a*a;
        a %= MOD;
        n >>= 1;
    }
    return res;
}

ll inv(ll num) {
    return pow(num, MOD - 2);
}

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

  int N; cin>>N;
  vl X=vl(N); REP(i,N) cin>>X[i];

  // 区間 [i,i+1] の距離を求める
  /*vl dx = vl(N-1, 0);
  REP(i,N-1) {
      dx[i] = X[i+1] - X[i];
  }*/

  // ec[i] := dx[i] を移動するスライムの数の期待値  
  /*vector<ll> ec(N-1, 0);
  REP(i,N-1) {
    for(ll j=1; j<=i+1; j++) {
      ec[i] += inv(j);
      ec[i] %= MOD;
    }
  }*/

  ll ans = 0;

  // 総移動距離の期待値を求める
  ll fact = 0;
  REP(i,N-1) {
    //ans += dx[i]*ec[i];
    fact += inv(i+1);
    fact %= MOD;
    
    ans += (X[i+1]-X[i])*fact;
    ans %= MOD;
  }

  // (N-1)! をかける
  REP(i,N-1) {
    ans *= (i+1);
    ans %= MOD;
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1024
MODE = "stdio"

line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = "\
  5
  10 1 5 4 17
  ".split("\n")
  tmp.each{|s|
    line << s.strip
  }
end

r=Array.new
r = line[1].split(" ").map(&:to_i)

printf("%d %d %d\n",r.min,r.max,r.inject(:+))

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

#define bs bitset<16>

int main(){
  string s;
  vector<bs> v;

  cin >> s;

  REP(i, int(pow(2, s.size() - 1))) {
    v.push_back(bs(i));
  }

  LL ans = 0;

  for (auto x:v) {
    vector<LL> tmp_v;
    int start = 0;
    REP(i, int(x.size())) {
      if (x[i] == 1) {
        tmp_v.push_back(stoll(s.substr(start, i - start + 1)));
        start = i + 1;
      }
    }
    tmp_v.push_back(stoll(s.substr(start, s.size() - start + 1)));
    ans += accumulate(tmp_v.begin(), tmp_v.end(), 0LL);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 512
import sys

input = sys.stdin.readline

N,Q = map(int,input().split())

row = [-1 for i in range(N+1)]
column = [-1 for i in range(N+1)]

R = N
C = N

res = (N-2)**2

for _ in range(Q):
    t,x = map(int,input().split())
    if t==1:
        if column[x]==-1:
            for i in range(x,N+1):
                if column[i] ==-1:
                    column[i] = R
                else:
                    break
            res -= column[x] - 2
        else:
            res -= column[x] - 2

        if x<=C:
            C = x
    else:
        if row[x]==-1:
            for i in range(x,N+1):
                if row[i] == -1:
                    row[i] = C
                else:
                    break
            res -= row[x] - 2
        else:
            res -= row[x] - 2

        if x<=R:
            R = x

    #print("row:",row)
    #print("column:",column)
    #print(res)

print(res)


Measured memory_bytes: 94500
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n) cin >> a[i];
    map<ll,ll> mp;
    ll sum = 0;
    ll ans = 0;
    if(a[0]==0) ans++;
    sum = a[0];
    mp[0]=1;
    for(ll i=1;i<n;++i){
        mp[-sum]++;
        sum+=a[i];
        ll cnt = (ll)mp[-sum];
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14336
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


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

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){ 
    ll x,ans;
    ans=0;
    cin >>x;
    while(x-500>=0){
        ans+=1000;
        x-=500;
    }
    while (x-5>0){
        ans+=5;
        x-=5;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
N = input()

num = len(N)
# print(N[num-1])
first_num = N[num-1]

if int(first_num) in [2,4,5,7,9]:
    print('hon')

elif int(first_num) in [0,1,6,8]:
    print('pon')

elif int(first_num) in [3]:
    print('bon')

    

Measured memory_bytes: 9108
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

int N;
bool a[40];
bool b[40];
int s;

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		int x;
		scanf("%d" , &x);
		s ^= x;
		int z = 0;
		for(; x % 2 == 0 ; ++z) x >>= 1;
		b[z] = 1;
	}
	for(int i = 0 ; s > 0 ; ++i){
		a[i] = s % 2 == 1;
		s >>= 1;
	}
	int ans = 0;
	repm(i,33,-1){
		if(a[i+1] ^ a[i]){
			if(b[i]){
				++ans;
			} else {
				ans = -1000;
			}
		}
	}
	printf("%d\n" , ans < 0 ? -1 : ans);
	return 0;
}


Measured memory_bytes: 128
import numpy as np
N,M,C = map(int,input().split())
Bi = list(map(int,input().split()))

result=0

for i in range(N):
	Ai = list(map(int,input().split()))
	Ax = np.array(Ai)
	Bx = np.array(Bi)
	Ci = Ax * Bx
	if sum(Ci) + C > 0:
		result = result + 1
	#print(Ci)

print(result)


Measured memory_bytes: 12504
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin >> n >> k;
    int pos;
    rep(i,n) {
        int a;
        cin >> a;
        if(a == 1) pos = i;
    }
    int ans = 0;
    ans += (pos+k-2)/(k-1);
    pos = ans*(k-1);
    ans += (n-1-pos+k-2)/(k-1);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include <vector>
#include <cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;

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 long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,l;
  ci(n>>l);
  ll pi=0;
  ll a=n+l-1;
  FOR(i,0,n){
    pi+=i+l;
    if(abs(a)>=abs(i+l)) a=i+l;
  }
  co(pi-a)
}

Measured memory_bytes: 256
import math
A,B = map(int,input().split())
Xa = A * 12.5
Xb = B * 10
X = math.ceil(max(Xa,Xb))
ansA = math.floor(X * 0.08)
ansB = math.floor(X * 0.1)
# print(ansA,ansB)
if A == ansA and B == ansB:
    print(X)
else:
    print(-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  char a;
  cin >> a;
  if(a=='a'||a=='i'||a=='u'||a=='e'||a=='o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}


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

int N;
long long A, B, C, D;
long long a[100010], b[100010];
int aL;
long long a2[100010], b2[100010];
int a2L;
int idx[100010];

int cmp(const void *aa, const void *bb)
{
	int i1 = *((int *)aa);
	int i2 = *((int *)bb);
	if(a2[i1] > a2[i2])
		return 1;
	else if(a2[i1] < a2[i2])
		return -1;
	else{
		return b2[i1]-b2[i2];
	}
}

/*int solve()
{
	int i, j, k;
	a[0] = A-D;
	b[0] = A-C;
	a[1] = A+C;
	b[1] = A+D;
	aL = 2;
	for(i=2; i<N; i++){
		a2L = 0;
		for(j=0; j<aL; j++){
			a2[a2L] = a[j]-D;
			b2[a2L] = b[j]-C;
			if(a2[a2L] <= B && b2[a2L] >= B)
				a2L ++;
			else if(a2[a2L] > B && a[j] > a2[a2L])
				a2L ++;
			else if(b2[a2L] < B && b[j] < b2[a2L])
				a2L ++;
			//a2L ++;
			a2[a2L] = a[j]+C;
			b2[a2L] = b[j]+D;
			a2L ++;
			if(a2[a2L] <= B && b2[a2L] >= B)
				a2L ++;
			else if(a2[a2L] > B && a[j] > a2[a2L])
				a2L ++;
			else if(b2[a2L] < B && b[j] < b2[a2L])
				a2L ++;
		}
		for(j=0; j<a2L; j++)
			idx[j] = j;
		qsort(idx, a2L, sizeof(int), cmp);
		aL = 0;
		long long st = 0;
		for(j=1; j<a2L; j++){
			if(b2[idx[st]] >= a2[idx[j]])
				continue;
			a[aL] = a2[idx[st]];
			b[aL] = b2[idx[j-1]];
			aL ++;
			st = j;
		}
		a[aL] = a2[idx[st]];
		b[aL] = b2[idx[j-1]];
		aL ++;
		//j = 0;
		//for(k=0; k<aL; k++){
		//	if(a[k]<=B && b[k]>=B){
		//		a[j] = a[k];
		//		b[j] = b[k];	
		//		j ++;
		//	}
		//}
		//aL = j;
	}
	for(i=0; i<aL; i++){
		if(a[i]<=B && b[i]>=B)
			return 1;
	}
	return 0;
}*/

int solve()
{
	int i;
	long long at, bt;
	for(i=0; i<N-1; i++){
		at = A - D*i + C*(N-1-i);
		bt = A - C*i + D*(N-1-i);
		if(B>=at && B<=bt)
			return 1;
		at = A + C*i - D*(N-1-i);
		bt = A + D*i - C*(N-1-i);
		if(B>=at && B<=bt)
			return 1;
	}
	return 0;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	scanf("%d", &N);
	scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
	if(solve() )
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
N,M = map(int, input().split())
Ss = list(map(int, input().split()))
Ts = list(map(int, input().split()))
mod = 10**9 + 7

x = 2160
dp = [[0]*x for i in range(x)]
for i in range(N):
    for j in range(M):
        if Ss[i] == Ts[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % mod
        else:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] - dp[i][j])%mod

print((dp[N][M]+1)%mod)

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

using namespace std;

#define ll long long
#define up(i,j,n)		for(int i=j;i<=n;i++)
#define down(i,j,n)	for(int i=j;i>=n;i--)
#define cmax(a,b)		a=max(a,b)
#define cmin(a,b)		a=min(a,b)
#define Auto(i,node)	for(int i=LINK[node];i;i=e[i].next)

const int MAXN=2e5+5;
const int oo=0x3f3f3f3f;

int N,M,deg[MAXN],col[MAXN];
ll ans=0,a=0,b=0,c=0;
bool vis[MAXN],isbi=0;

namespace Graph{
	struct edge{
		int y,next;
	}e[MAXN<<1];
	int LINK[MAXN],len=0;
	inline void ins(int x,int y){
		e[++len].next=LINK[x];LINK[x]=len;
		e[len].y=y;
	}
	inline void Ins(int x,int y){
		ins(x,y);
		ins(y,x);
		deg[x]++;deg[y]++;
	}
	void DFS(int node){
		vis[node]=1;
		Auto(i,node){
			if(!vis[e[i].y]){
				col[e[i].y]=col[node]*-1;
				DFS(e[i].y);
			}else if(col[e[i].y]!=col[node]*-1)
				isbi=0;
		}
	}
}using namespace Graph;

int main(){
//	freopen("input.in","r",stdin);
	scanf("%d%d",&N,&M);
	up(i,1,M){
		int x,y;
		scanf("%d%d",&x,&y);
		Ins(x,y);
	}
	up(i,1,N)if(!vis[i]){
		if(!deg[i])a++;
		else{
			isbi=1;
			col[i]=1;
			DFS(i);
			if(isbi)c++;
			else b++;
		}
	}
	ans=a*(N-a)+(N-a)*a+a*a+b*b+b*c+c*b+c*c*2;;
	cout<<ans<<endl;
	return 0;
}


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

int main (){
  int N;
  int j = 10;
  int hash = 0;
  cin >> N;
  int M = N;
  
  while (M != 0) {
    
    int a = M % j;
    M -= a;
    hash += a *10 /j;
    j *= 10;
      
  }
  
  if (N % hash == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a_abs = []
n_minus = 0
for ai in a:
    if ai < 0:
        n_minus += 1
        a_abs.append(-1 * ai)
    else:
        a_abs.append(ai)
if n_minus % 2 == 0:
    print(sum(a_abs))
else:
    a_abs.sort()
    print(sum(a_abs[1:]) - a_abs[0])


Measured memory_bytes: 14412
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

ll calculateSize(ll n){
    int out = 0;
    while(n>0){
        n /= 10;
        out++;
    }
    return out;
}

ll findDivisors(ll n) 
{ 
    ll vMin = 50;
    vector<ll> v; 
    for (int i=1; i<=sqrt(n); i++) 
    {
        ll vMax = 0;
        if (n%i==0) 
        { 
            if (n/i == i){ // check if divisors are equal 
                vMax = calculateSize(i);    
            }else{ 
                vMax = max(calculateSize(i),calculateSize(n/i)); 
            }
            
            if(vMax<vMin)vMin = vMax; 
        } 
    } 
    
    return vMin;
} 

int main(){
    ll n;
    cin>>n;
    cout<<findDivisors(n);
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i

k = -1
100_000.times{|i|
  if i*(i-1)/2==n
    k = i
  end
}

if k==-1
  puts "No"
  exit
end

#
puts "Yes"
puts k
ans = k.times.map{[k-1]}
num = 1
1.upto(k){|i|
  (i+1).upto(k){|j|
    ans[i-1] << num
    ans[(j-1)%k] << num
    num += 1
  }
}

ans.each{|x| puts x*" "}


Measured memory_bytes: 5372