akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
hN = LIST()

# dp[足場番号] = そこまで行くための最小コスト
dp = [INF] * (N)
dp[0] = 0
for i in range(N):
    for j in range(1, K+1):
        if i+j < N:
            # j個先に跳ぶ
            dp[i+j] = min(dp[i] + abs(hN[i+j]-hN[i]), dp[i+j])
print(dp[N-1])


Measured memory_bytes: 81032
#include <iostream>
#define int long long
using namespace std;

int mod = 1000000007;
int n;

signed main() {
	int i;
	
	cin >> n;
	
	int ans = 1;
	for (i = 1; i <= n; i++) {
		ans *= i;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <limits>
#include <vector>

template <class Monoid>
struct SegmentTree {
  using T = typename Monoid::type;
  int N_, N;
  std::vector<T> dat;

  SegmentTree(const int N_) : N_(N_) {
    assert(N_ > 0);
    N = 1;
    while (N < N_) {
      N <<= 1;
    }
    dat.assign(2 * N - 1, Monoid::identity());
  }

  SegmentTree(const std::vector<T> &dat_) : N_(dat_.size()) {
    assert(N_ > 0);
    N = 1;
    while (N < N_) {
      N <<= 1;
    }
    dat.assign(2 * N - 1, Monoid::identity());
    std::copy(dat_.begin(), dat_.end(), dat.begin() + N - 1);
    for (int i = N - 2; i >= 0; i--) {
      dat[i] = Monoid::merge(dat[2 * i + 1], dat[2 * i + 2]);
    }
  }

  int size() { return N_; }

  void update(int key, T val) {
    assert(0 <= key && key < N_);

    key += N - 1;
    dat[key] = val;

    while (key > 0) {
      key = (key - 1) / 2;
      dat[key] =
          Monoid::merge(dat[2 * key + 1], dat[2 * key + 2]);  // rewrite here
    }
  }

  inline const T &operator[](const int k) const { return dat.at(N - 1 + k); }
  inline T &operator[](const int k) { return dat.at(N - 1 + k); }

  T query(int low, int high) const {
    T left_ret = Monoid::identity(), right_ret = Monoid::identity();
    for (low += N, high += N; low < high; low >>= 1, high >>= 1) {
      if (low & 1) {
        left_ret = Monoid::merge(left_ret, dat[low - 1]);
        low++;
      }
      if (high & 1) {
        high--;
        right_ret = Monoid::merge(dat[high - 1], right_ret);
      }
    }
    return Monoid::merge(left_ret, right_ret);
  }
};

template <typename T>
struct RangeSumQuery {
  using type = T;
  static type identity() { return T(0); }
  static type merge(const type &l, const type &r) { return l + r; }
};

template <typename T>
struct RangeMinQuery {
  using type = T;
  static type identity() { return std::numeric_limits<T>::max(); }
  static type merge(const type &l, const type &r) { return std::min(l, r); }
};

template <typename T>
struct RangeMaxQuery {
  using type = T;
  static type identity() { return T(0); }
  static type merge(const type &l, const type &r) { return std::max(l, r); }
};

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

  int N; std::string S; int Q; std::cin >> N >> S >> Q;
  std::vector<SegmentTree<RangeMaxQuery<short>>> segts(26, SegmentTree<RangeMaxQuery<short>>(N));
  for (int i = 0; i < N; i++) {
    int s = S[i] - 'a';
    segts[s].update(i, 1);
  }

  for (int i = 0; i < Q; i++) {
    int t; std::cin >> t;
    if (t == 1) {
      int idx; char c; std::cin >> idx >> c;
      segts[S[idx-1]-'a'].update(idx-1, 0);
      segts[c-'a'].update(idx-1, 1);
      S[idx-1] = c;
    } else {
      int l, r; std::cin >> l >> r;
      int ans = 0;
      for (int j = 0; j < 26; j++) {
        ans += segts[j].query(l-1, r);
      }
      std::cout << ans << '\n';
    }
  }


  return 0;
}

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

int main(void){
  int W, Q;
  while(cin >> W >> Q, W | Q){
    vector<char> field(W, '#');
    int id, w;
    for(int p=0; p < Q; p++){
      char c; cin >> c;
      if(c == 's'){
        bool flg = false;
        int id, w; cin >> id >> w;
        for(int i=0; i <= W - w; i++){
          flg = true;
          int index;
          for(int j=0; j < w; j++){
            if(field[i+j] != '#'){
              flg = false;
            }
          }
          if(flg){
            cout << i << endl;
            for(int j=0; j < w; j++){
              field[i+j] = id + '0';
            }
            break;
          }
        }
        if(!flg){
          cout << "impossible" << endl;
        }
      }else{
        int id; cin >> id;
        for(int i=0; i < W; i++){
          if(field[i] == id + '0')
            field[i] = '#';
        }
      }
    }
    cout << "END" << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)

int main() {
    int N, Y;
    cin >> N >> Y;

    for (int a = 0; a <= N; a++) {
        for (int b = 0; b <= N; b++) {
            int c = N - a - b;
            if (c >= 0) {
                if (a * 10000 + b * 5000 + c * 1000 == Y) {
                    cout << a << ' ' << b << ' ' << c << endl;
                    return 0;
                }
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

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) begin(v),end(v)
#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; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int N, K, C;
string S;
int R[212345], L[212345];

int main() {
	cin >> N >> K >> C >> S;
	
	memset(R, -1, sizeof(R));
	memset(L, -1, sizeof(L));
	
	int can = 0, pos = 0;
	R[0] = 0;
	while (pos < N) {
		if (S[pos] == 'o') {
			pos += C + 1;
			++can;
			R[can] = pos;
		}
		else ++pos;
	}
	
	can = 0; pos = N - 1;
	L[0] = N - 1;
	while (pos >= 0) {
		if (S[pos] == 'o') {
			pos -= C + 1;
			++can;
			L[can] = pos;
		}
		else --pos;
	}
	
	set<int> ss;
	REP(i, N) if (S[i] == 'o') ss.insert(i);
	
	vector<int> ans;
	REP(x, K) {
		if (R[x] == -1) break;
		if (L[K - x - 1] == -1) break;
		
		// R[x] <= y <= L[K - x - 1] の 'o'を数える
		auto it = ss.lower_bound(R[x]);
		if (*it <= L[K - x - 1]) {
			if (next(it, 1) == ss.end()) ans.emplace_back(*it);
			else if (*next(it, 1) > L[K - x - 1]) ans.emplace_back(*it);
		}
	}
	for (auto x : ans) printf("%d\n", x + 1);
	return 0;
}


Measured memory_bytes: 13692
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  string a;
  cin>>a;
  int ans=1e9;
  int N = a.size();
  for(int i = 0; i <= N - 3; ++i){
   int num = (a[i] - '0') * 100 + (a[i+1] - '0') * 10 + a[i+2] - '0';
   ans = min(ans, abs(num - 753));
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    string s; cin >> s;
    vector<string> ss={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    for(int i=0; i<7; ++i){
        if(ss[i]==s){
            cout << 7-i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=3e3+5;
int i,j,n,a[maxn],sg[maxn],k[maxn],ne[maxn<<1],num,g[maxn<<1];
int d[maxn],b;
void add(int x,int y){
	ne[++num]=k[x],k[x]=num,g[num]=y;
}
void dfs(int x){
	int i;
	for(i=k[x];i;i=ne[i]){
		int go=g[i];
		if (a[go]<a[x])	dfs(go);
	}
	b++;
	for(i=k[x];i;i=ne[i]){
		int go=g[i];
		if (a[go]<a[x])	d[sg[go]]=b;
	}
	for(i=0;d[i]==b;i++);
	sg[x]=i;
}
int main(){
	n=read();
	fo(i,1,n) a[i]=read();
	fo(i,1,n-1){
		int x=read(),y=read();
		add(x,y),add(y,x);
	}
	fo(i,1,n) {
		dfs(i);
		if (sg[i]) printf("%d ",i);
	}
}
 

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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

Int gcd(Int a, Int b) {
	return (b == 0) ? a : gcd(b, a%b);
}

int main() {
	Int n, a, b, g, res;
	IL {
		cin >> n >> a >> b;
		if (n == 0 && a == 0 && b == 0) break;
		g = gcd(a, b);
		res = 0;
		if (g > 1) {
			res += n - n / g;
			n /= g;
			a /= g;
			b /= g;
		}
		repn (i, 1, a) {
			rep (j, a) {
				if (b * j % a == i) {
					if (b * j > n) res += n / a + (i <= n % a ? 1 : 0);
					else res += b * j / a;
					break;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int now = 0;
		int x =0;
		int y = 0;
		for (int i=0;i<N;i++) {
			int t = sc.nextInt();
			int xt = sc.nextInt();
			int yt = sc.nextInt();
			int cost = Math.abs(x-xt)+Math.abs(y-yt);
			if (cost>t-now) {
				System.out.println("No");
				return ;
			}
			if((t-now-cost)%2!=0) {
				System.out.println("No");
				return ;
			}
			x = xt;
			y = yt;
			now = t;
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 57388
import bisect
N = list(input())
nums = len(N)
mass = [1 for _ in range(nums)]

prev = N[0]
dicr = []
dicl = []
all = []
for i in range(1, len(N)):
  if prev == "R" and N[i] == "L":
    dicr.append(i-1)
    dicl.append(i)
    all.append(i)
    all.append(i-1)
  prev = N[i]
all = set(all)
dicr = sorted(dicr)
dicl = sorted(dicl)
for i in range(len(N)):
  if i not in all:
    mass[i] = 0
    if N[i] == "R":
      ind = dicr[bisect.bisect_left(dicr, i)]
      rest = ind-i
      if rest%2 == 0:
        mass[ind] += 1
      else:
        mass[ind+1] += 1
    else:
      ind = dicl[bisect.bisect_left(dicl, i)-1]
      rest = ind-i
      if rest%2 == 0:
        mass[ind] += 1
      else:
        mass[ind-1] += 1
mass = [str(m) for m in mass]
print(' '.join(mass))

Measured memory_bytes: 20552
// ARC095
// D - Binomial Coefficients

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;

int N;
int a[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a + N);

    if (N == 2) {
        cout << a[1] << " " << a[0] << endl;
        return 0;
    }

    int n = a[N - 1];
    int mid_idx = upper_bound(a, a + N - 1, n / 2) - a;
    int r = (a[mid_idx] - n / 2 > n / 2 - a[mid_idx - 1]) ? a[mid_idx - 1]
                                                          : a[mid_idx];
    cout << n << " " << r << endl;

    return 0;
}


Measured memory_bytes: 640
// 2011/02/23 Tazoe

#include <iostream>
#include <string>
#include <queue>
#include <map>
using namespace std;

struct change{
	string dat;
	int tim;
};

int main()
{
	while(true){
		struct change wor;
		cin >> wor.dat;
		if(wor.dat=="0")
			break;
		wor.tim = 0;

		queue<struct change> que;
		que.push(wor);

		map<string, bool> mem;

		int cost;
		while(true){
			if(que.empty()){
				cost = -1;
				break;
			}

			wor = que.front();
			que.pop();
//			cout << wor.dat << ' ' << wor.tim << endl;

			if(mem[wor.dat])
				continue;
			mem[wor.dat] = true;

			bool flg = true;
			for(int i=1; i<wor.dat.size(); i++)
				if(wor.dat[i]!=wor.dat[0]){
					flg = false;
					break;
				}
			if(flg){
				cost = wor.tim;
				break;
			}

			struct change tmp;
			for(int i=0; i<wor.dat.size()-1; i++)
				if(wor.dat[i]==wor.dat[i+1])
					continue;
				else if(wor.dat[i]!='r'&&wor.dat[i+1]!='r'){
					tmp.dat = wor.dat;
					tmp.dat[i] = tmp.dat[i+1] = 'r';
					tmp.tim = wor.tim+1;
					que.push(tmp);
				}
				else if(wor.dat[i]!='g'&&wor.dat[i+1]!='g'){
					tmp.dat = wor.dat;
					tmp.dat[i] = tmp.dat[i+1] = 'g';
					tmp.tim = wor.tim+1;
					que.push(tmp);
				}
				else if(wor.dat[i]!='b'&&wor.dat[i+1]!='b'){
					tmp.dat = wor.dat;
					tmp.dat[i] = tmp.dat[i+1] = 'b';
					tmp.tim = wor.tim+1;
					que.push(tmp);
				}
		}

		if(cost==-1)
			cout << "NA" << endl;
		else
			cout << cost << endl;
	}

	return 0;
}

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

int main(){
	long N,M;
	cin>>N>>M;
	map<long,long> arr;
	long A,B;
	for(int i=0;i<N;++i){
		cin>>A>>B;
		arr[A]+=B; //同じ金額のジュースが別店で売られていたら和をとっていく
	}
	long total=0;
	long money=0;
	for(auto itr=arr.begin();itr!=arr.end();++itr){
		if(total+itr->second>=M){
			money+=(M-total)*itr->first;
			break;
		}
		else{
			total+=itr->second;
			money+=itr->second*itr->first;
		}
	}
	cout<<money<<endl;
}


Measured memory_bytes: 6528
a,b,c,d=list(input())
for i in range(8):
  op=list(str(bin(i)[2:].zfill(3)).replace('0','-').replace('1','+'))
  siki=a+op[0]+b+op[1]+c+op[2]+d
  ans=eval(siki)
  if ans == 7:
    print(siki+'=7')
    break

Measured memory_bytes: 3060
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N-1];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N-1; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int[] cnt = new int[N+5];
         for(int x: arr)
            cnt[x]++;
         int ans = N;
         for(int i=1; i <= N; i++)
         {
            ans = cnt[i];
            System.out.println(ans);
         }
      }
   }

Measured memory_bytes: 56936
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

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

	queue<string> q;
	q.push("a");
	

	for (int i = 1; i < N; ++i) {
		auto t = move(q);
		while (!t.empty()) {
			string s = move(t.front());
			t.pop();
			char m = *max_element(s.begin(), s.end());
			for (char c = 'a'; c <= m + 1; ++c) {
				q.push(s + c);
			}
		}
	}
	vector<string> ans;
	while (!q.empty()) {
		ans.emplace_back(move(q.front()));
		q.pop();
	}
	sort(ans.begin(), ans.end());
	for (auto& s : ans) {
		cout << s << endl;
	}
}


Measured memory_bytes: 10748
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll maxn=202;
const ll inf=0x3f3f3f3f;

ll dis[maxn][maxn];
ll n,m,r;
vector<int> rt;

void floyd() {
	for (ll k=1; k<=n; ++k)
		for (ll i=1; i<=n; ++i)
			for (ll j=1; j<=n; ++j)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}

int main() {
	cin>>n>>m>>r;
	for (ll i=1,a; i<=r; ++i) {
		cin>>a;
		rt.push_back(a);
	}
	memset(dis,inf,sizeof(dis));
	for (ll i=1,a,b,c; i<=m; ++i) {
		cin>>a>>b>>c;
		dis[a][b]=dis[b][a]=min(dis[b][a],min(dis[a][b],c));
	}
	floyd();
	sort(rt.begin(),rt.end());
	int ans=inf;
	do {
		int tmp=0;
		for (int i=0; i<rt.size()-1; ++i)
			tmp+=dis[rt[i]][rt[i+1]];
		ans=min(ans,tmp);
	} while (next_permutation(rt.begin(),rt.end()));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
from sys import stdin
from collections import Counter
mod = 10**9+7
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = 2**(N//2)
if N % 2 == 0:
    for i in A:
        if i % 2 == 0:
            ans = 0
    for j in Counter(A).values():
        if j != 2:
            ans = 0
else:
    for i in A:
        if i % 2 != 0:
            ans = 0
    for j,k in Counter(A).items():
        if j != 0 and k != 2:
            ans = 0
    if Counter(A)[0] != 1:
        ans = 0
print(ans%mod)

Measured memory_bytes: 14820
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
MAX = 10**18
zero = 0
for i in range(N):
    if A[i] == 0:
        zero = 1
        break
if zero == 1:
    print(0)
else:
    cur = 1
    flag = 0
    for i in range(N):
        a = A[i]
        cur *= a
        if cur > MAX:
            flag = 1
            break
    if flag == 1:
        print(-1)
    else:
        print(cur)

Measured memory_bytes: 23780
def main():
    X = int(input())
    if X == 2:
        print(2)
        exit()
    if X % 2 == 0:
        X += 1
    while True:
        flag = True
        for i in range(3, X, 2):
            if X % i == 0:
                flag = False
                break
        if flag is True:
            print(X)
            break
        else:
            X += 2


if __name__ == '__main__':
    main()


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef pair<int, int> pii;

class Error {};

map<string, pii> vars;

void calc(vs& factor) {
    stack<pii> stk;
    for (const string& f : factor) {
        if (isdigit(f[0])) {
            int m = stoi(f);
            stk.push({m, m});
        } else if (isalpha(f[0])) {
            stk.push(vars[f]);
        } else {
            pii b = stk.top(); stk.pop();
            pii a = stk.top(); stk.pop();
            int ma = 0, mi = 255;
            int r;
            switch (f[0]) {
            case '+':
                FOR(A, a.first, a.second+1) {
                    FOR(B, b.first, b.second+1) {
                        r = (A + B) % 256;
                        ma = max(ma, r);
                        mi = min(mi, r);
                    }
                }
                break;
            case '-':
                FOR(A, a.first, a.second+1) {
                    FOR(B, b.first, b.second+1) {
                        r = (A - B + 256) % 256;
                        ma = max(ma, r);
                        mi = min(mi, r);
                    }
                }
                break;
            case '*':
                FOR(A, a.first, a.second+1) {
                    FOR(B, b.first, b.second+1) {
                        r = (A * B) % 256;
                        ma = max(ma, r);
                        mi = min(mi, r);
                    }
                }
                break;
            case '/':
                if (b.first == 0) throw Error();
                FOR(A, a.first, a.second+1) {
                    FOR(B, b.first, b.second+1) {
                        r = (A / B) % 256;
                        ma = max(ma, r);
                        mi = min(mi, r);
                    }
                }
                break;
            }
            stk.push({mi, ma});
        }
    }
}

int main() {
    int m;
    cin >> m;
    REP(i, m) {
        string name;
        int a, b;
        cin >> name >> a >> b;
        vars[name] = {a, b};
    }
    int n;
    cin >> n;
    vs factor(n);
    REP(i, n) cin >> factor[i];
    try {
        calc(factor);
        cout << "correct" << endl;
    } catch (Error e) {
        cout << "error" << endl;
    }
}

Measured memory_bytes: 3256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace MyProgram{
    public class Program
    {	
        public static void Main(string[] args)
    	{
           int n = int.Parse(Console.ReadLine());
           
           if(n == 7 || n == 5 || n == 3)
           {
               Console.WriteLine("YES");
           }
           else
           {
               Console.WriteLine("NO");
           }
    	}
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, mx = 0 , mn = INT_MAX;
int sum = 0;
cin>>n;
for(int i = 0 ; i<n ; i++){
    int x;
    cin>>x;
    sum += (x-1);
}
cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;


int main() {
 int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(b-a)<=d&&abs(c-b)<=d){
    cout << "Yes" << endl;
  }
  else if(abs(a-c)<=d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
#define MOD 1000000007;

/*
    Ball and Boxes 11
*/

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

    int ans;

    if(n <= k){
        ans = 1;
    }else{
        ans = 0;
    }

    cout << ans << endl;
    return 0;
}
 
 



Measured memory_bytes: 3124
#include <algorithm>
#include <bitset>
#include <complex>
#include <cassert>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <math.h>
#include <memory>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define INF_LL 4000000000000000000LL
#define INF 1000000000
#define EPS 1e-8
#define LL long long
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define setzero(a) memset(a,0,sizeof(a))
#define setdp(a) memset(a,-1,sizeof(a))
#define bits(a) __builtin_popcountll(a)

using namespace std;

int get(int x) {
  int ans = 0;
  while (x) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  if (n % get(n))
    cout << "No";
  else
    cout << "Yes";
  return 0;
}


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

using namespace std;

int main(void){
    string S;
    cin >> S;
    map<char, int> m;
    for(char c : S) m[c]++;
    for(auto mm : m){
        if(mm.second != 2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 764
local mfl, mce = math.floor, math.ceil
local n = io.read("*n")
local a = {}
local t = {}
for i = 1, 1000 * 1000 do
  t[i] = 0
end
for i = 1, n do
  a[i] = io.read("*n")
end
local acmp = {}
for i = 1, n do
  local v = a[i]
  if not acmp[v] then acmp[v] = 1
  else acmp[v] = acmp[v] + 1
  end
end
for v, cnt in pairs(acmp) do
  local lim = mfl(1000000 / v)
  for j = 1, lim do
    t[j * v] = t[j * v] + cnt
  end
end
local c = 0
for i = 1, n do
  local v = a[i]
  if t[v] == 1 then
    c = c + 1
  end
end
print(c)


Measured memory_bytes: 22244
#include <iostream>

using namespace std;

main(){
  int n;
  while(cin >> n){
    for(int c=0;c<n;c++){
      int s, g;
      cin >> s >> g;
      int d;
      if(s<=5 && g<s){
	d=0;
      }else{
	d=1;
      }
      if(d==1){
	bool finish=false;
	for(int i=s;i<10;i++){
	  cout << i;
	  if(i==g){
	    finish=true;
	    break;
	  }
	  cout << ' ';
	}
	if(finish){
	  cout << endl;
	  continue;
	}
	if(g<=5){
	  for(int i=5;i>=0;i--){
	    cout << i;
	    if(i==g){
	      break;
	    }
	    cout << ' ';
	  }
	  cout << endl;
	}else{
	  for(int i=5;i>0;i--){
	    cout << i;
	    cout << ' ';
	  }
	  for(int i=0;i<5;i++){
	    cout << i;
	    cout << ' ';
	  }
	  for(int i=5;i<10;i++){
	    cout << i;
	    if(i==g) break;
	    cout << ' ';
	  }
	  cout << endl;
	}
      }else{
	for(int i=s;i>=0;i--){
	  cout << i;
	  if(i==g) break;
	  cout << ' ';
	}
	cout << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
    
    static int n;
    static int m;
    static ArrayList<Integer>[] g;
    static boolean[] used;
    static boolean[] qued;
    static int[] dis;
    static final int INF = 1_000_000_000 + 1;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        n = sc.nextInt();
        m = sc.nextInt();
        
        g = new ArrayList[n];
        for(int i=0; i<n; i++){
            g[i]= new ArrayList<Integer>();
        }
        
        used = new boolean[n];
        Arrays.fill(used, false);
        qued = new boolean[n];
        Arrays.fill(qued, false);
        
        for(int i=0; i<m; i++){
            int l = sc.nextInt();
            int r = sc.nextInt();
            int d = sc.nextInt();
            g[l-1].add(r-1);
            g[l-1].add(d);
            g[r-1].add(l-1);
            g[r-1].add(-d);
        }
        
        dis = new int[n];
        for(int i=0; i<n; i++){
            dis[i] = INF;
        }
        
        boolean ans = true;
        for(int i=0; i<n; i++){
            if(!used[i]){
                boolean res = dfs(i);
                if(!res){
                    ans = false;
                }
            }
        }
        
        System.out.println(ans ? "Yes" : "No");
    }
    
    public static boolean dfs(int v){
        boolean res =  true;
        
        Deque<Integer> q = new ArrayDeque<Integer>();
        q.push(v);
        dis[v] = 0;
        
        while(q.size()!=0){
            int now = q.pop();
            used[now] = true;
            for(int i=0; i<g[now].size(); i+=2){
                int next = g[now].get(i);
                if(!used[next]){
                    if(dis[next]==INF){
                        dis[next] = dis[now] + g[now].get(i+1);
                    }else if(dis[next] != dis[now] + g[now].get(i+1)){
                        res = false;
                    }
                    if(!qued[next]){
                        q.push(next);
                        qued[next] = true;
                    }
                }
            }
        }
        return res;
    }
    
}


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

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	int ans = 0;
	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])) || ((p[i + 1] < p[i])&&(p[i] < p[i - 1]))) {
			ans += 1;
		}
		else {
			continue;
		}
	}
	cout << ans << endl;
}

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

int main()
{
  string s;
  cin >> s;
  int a=0, b=0;
  for(int i=0; i<3; i++){
    if(s[i]=='A') a++;
    else b++;
  }
  if(a==3 || b==3) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


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

int main(){
    int N; cin >> N;
    char s[110];
    for (int i=0; i < N ; i++) cin >> s[i];

    int r=0,b=0;
    for (int i=0; i < N ; i++) {
        if(s[i] == 'R') r++;
        if(s[i] == 'B') b++;
    }

        if( r > b ) cout << "Yes" << endl;
        else cout << "No" <<endl;
    

}

Measured memory_bytes: 256
fn getline() -> String {
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

#[allow(unused_macros)]
macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

#[allow(unused_macros)]
macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display,
{
    for (i, e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, BTreeMap, HashMap, HashSet};
#[allow(unused_imports)]
use std::collections::btree_map::Entry::{Occupied, Vacant};
fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    #[allow(unused_macros)]
    macro_rules! print { ($($arg:tt)*) => (write!(out, $($arg)*).unwrap()); }
    #[allow(unused_macros)]
    macro_rules! println { () => (writeln!(out).unwrap()); ($($arg:tt)*) => (writeln!(out, $($arg)*).unwrap()); }
    
    let n = readl!(usize);
    let mut d = readlvec!(i32);
    d.push(0);

    let mut cnt = BTreeMap::new();
    for &e in &d {
        let hoge = cnt.entry(e).or_insert(0);
        *hoge += 1;
    }

    let mut s = 1;
    let mut de = Vec::new();
    for (&k, &c) in &cnt {
        if c == 1 {
            s |= 1<<k;
        } else if c == 2 {
            de.push(k);
            de.push(24-k);
        } else {
            println!("0");
            return;
        }
    }

    
    let mut ans = 0;
    for mask in 0..(1<<13) {
        let mut vec = Vec::<i32>::new();
        for i in 0..13 {
            if (s>>i)&1 == 1 {
                if ((mask >> i)&1) == 1 {
                    vec.push(i);
                } else {
                    vec.push((24-i)%24);
                }
            }
        }
        vec.append(&mut de.clone());
        let mut mi = 24;
        for i in 0..vec.len() {
            for j in 0..i {
                mi = min(mi, min(24-(vec[i]-vec[j]).abs(), (vec[i]-vec[j]).abs()));
            }
        }
        // debug!(mi);
        ans = max(mi, ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>

#define ll long long
#define db double
#define MAX 0x7fffffff
#define init inline int
#define INF 0X3fffffff

using namespace std;

inline long long read()
{
    ll f=1,s=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
    return s*f;
}


ll a,b,c;

int main()
{
	string s;
	cin>>s;
	int len=s.size()-1;
	for(int i=0;i<=len/2;i++)
	{
		if(s[i]!=s[len-i]) a++;
	}
	cout<<a;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <climits>

#define N 1001
using namespace std;


char a[N][N];
int c[N][N];

int w,h,n;

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

char cz[10] = {'0','1','2','3','4','5','6','7','8','9'};

queue<int> xque;
queue<int> yque;


int main(){
	
	
	
		
		
		scanf(" %d",&h);
		scanf(" %d",&w);
        scanf(" %d",&n);
		
		
		
		
		int si=0,sj=0;
		for(int j=0;j<h;j++){
			for(int i=0;i<w;i++){
				scanf(" %c",&a[i][j]);
				if(a[i][j] == 'S'){
					si=i; sj=j;
				} 
			}
		}
		
		int ans=0;
        for(int p=1;p<=n;p++){
            for(int i=0;i<w;i++){
			 for(int j=0;j<h;j++){
			    c[i][j] = 100000000;
			 }
		    }
            while(xque.size()){
                xque.pop();
                yque.pop();
            }
            xque.push(si);
            yque.push(sj);
            c[si][sj] = 0;
            while(xque.size()){
                int i = xque.front(); xque.pop();
                int j = yque.front(); yque.pop();
                
                if(a[i][j] == cz[p]){
                    ans += c[i][j];
                    si = i; sj = j;
                    break;
                }
                
                for(int k=0;k<4;k++){
                    int nx = i+dx[k];
                    int ny = j+dy[k];
                    int tm = c[i][j]+1;
                    if((0<=nx)&&(nx<w)&&(0<=ny)&&(ny<h)&&(a[nx][ny]!='X')&&(c[nx][ny]>tm)){
                        xque.push(nx);
                        yque.push(ny);
                        c[nx][ny] = tm;
                    }		
                }
                
            }
        }
		
		printf("%d\n", ans);
	
	
	
	
	return 0;
}

Measured memory_bytes: 5940
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
    double a;
    cin >>a;
    double x,y;
    x=a*a*3.141592653589;
    y=2*a*3.141592653589;
    
    printf("%.6lf %.6lf\n", x,y);
    return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int cnt[100010];
int main()
{
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		cnt[A]++;
	}
	for (int i = 0; i <= 100000; i++) {
		if (cnt[i] != 0) {
			if (cnt[i] % 2 == 1) {
				cnt[i] = 1;
			}
			else {
				cnt[i] = 2;
			}
		}
	}
	int even = 0;
	for (int i = 0; i <= 100000; i++) {
		if (cnt[i] != 0) {
			if (cnt[i] % 2 == 1)ans++;
			else even++;
		}
	}
	ans += even - (even % 2);
	cout << ans << endl;
}


Measured memory_bytes: 640
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")

a,b = ma()
if a*b > 0 :
    if a+b >0:print("Positive")
    elif abs(b-a+1)%2==0:print("Positive")
    else:print("Negative")
else:print("Zero")










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

using namespace std;

int main(){
	int n;

	cin>> n;
vector<int>t(n);

int sum = 0;

for(int i = 0;i < n;i++){
  cin>>t[i];
	sum += t[i];
}

int m;
cin >> m;

vector<int>p(m);
vector<int>x(m);

for(int i = 0;i < m;i++){
	cin >> p[i] >>x[i];
	cout << sum -t[p[i]-1]+x[i] <<endl;
}

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> d(n);
    rep(i, n) cin >> d[i];
    sort(all(d));
    cout << (d[n / 2] - d[n / 2 - 1]) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int x, y;
    cin >> x >> y;
    
    if(x == y){
        cout << x << endl;
    }
    
    else if(x < y){
        int a = y % x;
        for(int i = a; i > 0; i--){
            if(a % i == 0 && y % i == 0){
                cout << i << endl;
                break;
            }
        }
    }
    
    else{
        int a = x % y;
        for(int i = a; i > 0; i--){
            if(a % i == 0 && x % i == 0){
                cout << i << endl;
                break;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Min(a, b) ((a < b)? a : b)
#define Max(a, b) ((a > b)? a : b)
#define Abs(x) ((x>=0)? x : -x)/*Return the absolute value of x.*/
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int a, b, n, m;
	scanf("%d%d%d", &n, &a, &b);
	m = Min((n*a), b);
	printf("%d", m);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <math.h>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define PI 3.1415926535897932384626
typedef struct { long x, y; } pt;

void solve() {

}

int main() {
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double deg_h = (h * 60 + m) /720.0 * 360.0;
	double deg_m = m / 60.0 * 360.0;
	double deg = (deg_h - deg_m) / 180.0 * PI;
	double len = sqrt(a * a + b * b - 2 * a * b * cos(deg));
	printf("%.16lf\n", len);
}

Measured memory_bytes: 4256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define FFOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>
 
 
signed main(){
	
	int n,k;cin>>n>>k;
	
	int idx;
	rep(i,n)
	{
		int a;cin>>a;
		if(a==1)idx = i+1;
	}
	
	int ans = (idx -1 +k - 2)/(k-1);
	idx = ans*(k-1)+1;
	
	ans += (n-idx+k-2)/(k-1);
	
	cout << ans << endl;
	
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int[] w = new int[10];
		int[] k = new int[10];
		for(int i=0;i<10;i++){
			w[i]=stdIn.nextInt();
		}
		for(int i=0;i<10;i++){
			k[i]=stdIn.nextInt();
		}
		Arrays.sort(w);
		Arrays.sort(k);
		int sum_w=0, sum_k=0;
		for(int i=7;i<10;i++){
			sum_w+=w[i];
			sum_k+=k[i];
		}
		System.out.println(sum_w+" "+sum_k);
	}
}

Measured memory_bytes: 0
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

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

func main() {
	mod := 1000000007
	n, _ := strconv.Atoi(input())
	m, _ := strconv.Atoi(input())
	a := make([]int, m)
	for i := 0; i < m; i++ {
		a[i], _ = strconv.Atoi(input())
	}

	dp := make([]int, n+2)
	dp[0] = 0
	dp[1] = 1
	dp[2] = 1
	for i := 3; i < n+2; i++ {
		dp[i] = dp[i-1] + dp[i-2]
		dp[i] %= mod
	}

	if m == 0 {
		fmt.Println(dp[n+1])
	} else {
		steps := make([]int, m+1)
		steps[0] = a[0]
		for i := 1; i < m; i++ {
			steps[i] = a[i] - a[i-1] - 1
		}
		steps[m] = n - a[m-1]

		ans := 1
		for i := 0; i < m+1; i++ {
			ans *= dp[steps[i]]
			ans %= mod
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 3014;

vector <int> w;
int tab[SIZE][SIZE];

string s1, s2;
int d1, d2;

    void input(){
        cin >> s1 >> s2;
        d1 = s1.size();
        d2 = s2.size();
    }

    void LCS(){
        
    for(int i = 2; i < d2+2; i++)
        for(int k = 2; k < d1+2; k++){
            if(tab[0][i] == tab[k][0])
                tab[k][i] = tab[k-1][i-1] + 1;
            else
                tab[k][i]=max(tab[k-1][i],tab[k][i-1]);
        }
        return;
    }

    void backtrack(){

        int c=tab[d1+1][d2+1], i = d1 + 1, k = d2 + 1;
        w.push_back(s1[d1-1]);


    while(true){
        if(tab[i][k]==0)
            break;

        if(tab[i][k] == tab[i-1][k-1] + 1 && tab[i][k] != tab[i-1][k]){
            c=tab[i-1][k-1];
            w.push_back(s1[i-2]);
            i--;
            k--;
        }

        else{
            if(tab[i-1][k] > tab[i][k-1]){
            c=tab[i-1][k];
            i--;
           }
            else{
            c=tab[i][k-1];
            k--;
            }
        }
    }
return;
}

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

    input();

    for(int i=2; i < d1+2; i++)
        tab[i][0] = s1[i-2];
    for(int i=2; i < d2+2; i++)
        tab[0][i] = s2[i-2];
    
    LCS();
    backtrack();

    for(int i = w.size()-1; i > 0; i--)
        cout << char(w[i]);
    
    return 0;

}


Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int k;
    cin >> k;
    int x = 7;
    for(int i = 1; i <= 1000000; i++)
    {
        if(x % k == 0)
        {
            cout << i << endl;
            return 0;
        }
        x %= k;
        x = x * 10 + 7;
    }
    cout << -1 << endl;
}



Measured memory_bytes: 3636
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
int main() {
	
	int A, B, C, D, E;
	int min = 99999;
	int ans = 0;
	cin >> A >> B >> C >> D >> E;
	int a[] = { A, B, C, D, E };

	for (int i = 0; i <= 4; i++) {
		if (a[i] % 10 < min && a[i] % 10 > 0) {
			min = a[i] % 10;
		}
		if (a[i] % 10 > 0) {
			a[i] = a[i] + (10 - a[i] % 10);
		}
		ans += a[i];
	}

	if (min == 99999) {
		min -= 99989;
	}
	if (ans < 50) {
		ans = 40;
	}
	cout << ans - (10 - min);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        string s;
        cin>>s;
        int l=s.length();
        int sum=0;
        for(int i=0;i<l;i++)
            sum+=s[i]-'0';

        if(sum%9==0)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
    }

Measured memory_bytes: 3732
#include<stdio.h>
int main(void){
 int K,N,p[1001]={0},i,tmp,count=0,answer=0;
 
 scanf("%d %d",&N,&K);
 
 for(i=0;i<N;i++){
  scanf("%d",&tmp);
  p[tmp]+=1;
 }
 
 for(i=0;i<1001;i++){
   if(p[i]==0){
     continue;
   }else{
    answer += i*p[i];
    count += p[i];
    if(count>K){
     answer = answer - (count - K)*i;
     break;
    }
    if(count==K){
      break;
    }
   }
 }
 printf("%d",answer);
 return 0; 
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"     
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e5+5;
int n,a[N],b[N],cache[102][N],w;

int dp(int pos,int weight)
{
     if(weight>w)
          return -1e15;
     if(pos==n+1)
          return 0;
     int &ans=cache[pos][weight];
     if(ans!=-1)
          return ans;
     ans=max(b[pos]+dp(pos+1,weight+a[pos]),dp(pos+1,weight));
     return ans;
}

int32_t main()
{
	IOS;

     memset(cache,-1,sizeof cache);
	cin>>n>>w;
	
	for(int i=1;i<=n;i++)
	     cin>>a[i]>>b[i];
	
	cout<<dp(1,0);
	     
	return 0;
}

Measured memory_bytes: 80128