akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        int[] arr = new int[N];
        
        st = new StringTokenizer(br.readLine());

        for (int i=0; i<N; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
        }

        int[] dp = new int[N];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0]=0;
        dp[1]=Math.abs(arr[1]-arr[0]);

        for (int i=2; i<N; i++) {
            for (int j=i-1; j>=0 && i-j<=K; j--) {
                dp[i] = Math.min(dp[i],dp[j]+Math.abs(arr[i]-arr[j]));
            }
        }
        System.out.println(dp[N-1]);
    }
}


Measured memory_bytes: 35240
#include<stdio.h>

int main(void){
     
	int a,b;
	scanf("%d %d",&a,&b);
	
	if(a<b)
	{
	printf("a < b\n");
	}
	if(a>b)
	{
    printf("a > b\n");
	 }
	if(a==b)
	{
		printf("a == b\n");
	}

    return 0 ;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))  
#define lli long long int
#define ll long long 
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define BS binary_search
#define pii pair<lli,lli>
const long long int mod=1000000007;
//const long long int mod=998244353;
const long double PI=3.141592653589793;
const long long int inf=1e18;
const long long int inf2=LLONG_MAX;
#define setBitCount(x) __builtin_popcountll(x)
#define all(a) (a).begin(), (a).end()
#define all_r(a) (a).rbegin(), (a).rend()
#define endl "\n"
lli gcd(lli a,lli b)
{
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
}
// calculating (x^y)%p
lli power(lli x,lli y,lli p)
{
    lli res = 1;      
    x = x % p;  
    while (y > 0)
    {
        if (y & 1) //y is odd  
        res = (res*x) % p;
        y = y>>1; 
        x = ( (x%p)*(x%p) )% p;  
    }
    return res%p;
}
// calculating modular inverse using fermat little theorem
lli modInverse(lli n,lli p) 
{
    return power(n, p-2, p)%p;
}
 
// policy based data structures !!
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
// s.order_of_key (k) : Number of items strictly smaller than k
// *(s.find_by_order(k)) : K-th element in a set (counting from zero)
lli d;
string s;
lli dp[10005][105];
lli fun(lli n,lli sum)
{
   if(n==0)
   {
      if(sum==0)
      return 1;
      else
      return 0;
   }
   
   if(dp[n][sum]!=-1)
   return dp[n][sum];
   
   lli ans=0;
   for(lli i=0;i<=9;i++)
   {
      ans=(fun(n-1,(sum+i)%d)+ans)%mod;
   }
   
   dp[n][sum]=ans%mod;
   return ans%mod;
}
lli f(string s)
{
   lli len=s.size();
   lli ans=0;
   lli sum=0;
   for(lli i=0;i<len;i++)
   {
      lli nu=s[i]-'0';
      for(lli j=0;j<nu;j++)
      {
         ans=(fun(len-i-1,(sum+j)%d)+ans)%mod;
      }
      sum+=nu;
      sum%=d;
   }
   ans--;
   ans+=mod;
   ans%=mod;
   return ans;
}
void solve()
{
   cin>>s;
   cin>>d;
   memset(dp,-1,sizeof(dp));
   lli ans=f(s);
   
   lli sum=0;
   for(auto it:s)
   sum+=it-'0';
   
   if(sum%d==0)
   ans++;
   ans%=mod;
   cout<<ans;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    lli T;
    //cin>>T;
    T=1;
    while(T--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 9216
h,w = map(int, input().split())
s = [list(input().split()) for i in range(h)]
for key_i,i in enumerate(s):
  key_i += 1
  for key_j,j in enumerate(i):
    if j == "snuke":
      print(chr(ord("A")+key_j)+str(key_i))
      exit()

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

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {


        public void Solve()
        {

            var sc = new Scanner();
            int a = sc.NextInt();
            int b = sc.NextInt();
            int c = sc.NextInt();
            int x = sc.NextInt();
            int cnt = 0;
            for(int i=0;i<=a;i++)
            {
                for(int j=0;j<=b;j++)
                {
                    for(int k=0;k<=c;k++)
                    {
                        if(500*i+100*j+50*k==x)
                        {
                            cnt++;
                        }
                    }
                }
            }
            Console.WriteLine(cnt);
        }



        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];
    for(int i=0; i<N; i++) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;

    for(int i=0; i<N; i++) {
        ll pre = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        ll over = C.end() - upper_bound(C.begin(), C.end(), B[i]);
        ans += pre * over;
    }
    cout << ans << endl;
}

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

int main() {
  
  char b;
  cin >> b;
  
  if (b == 'A') {
    cout << 'T' << endl;
  }
  if (b == 'T') {
    cout << 'A' << endl;
  }
  if (b == 'C') {
    cout << 'G' << endl;
  }
  if (b == 'G') {
    cout << 'C' << endl;
  }

return 0;
}

Measured memory_bytes: 3632
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

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

m = (N - 1) * (N - 2) // 2

if K > m:
    print(-1)
    sys.exit()

ans = []

for i in range(1, N):
    ans.append((i, N))

c = m - K
cnt = 0

for i in range(1, N):
    for j in range(i + 1, N):
        if cnt == m - K:
            break
        ans.append((i, j))
        cnt += 1
    if cnt == m - K:
        break

print(len(ans))
for i, j in ans:
    print("{} {}".format(i, j))


Measured memory_bytes: 4476
from functools import lru_cache

N, W = [int(x) for x in input().split()]
VW = [[int(x) for x in input().split()] for _ in range(N)]

dp = [[0] * (W + 1) for j in range(N + 1)]

for i in range(1, N + 1):
    for j in range(W + 1):
        v, w = VW[i - 1]
        if w > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], v + dp[i - 1][j - w])

print(dp[N][W])






Measured memory_bytes: 26052
#pragma GCC optimize("Ofast,O2,O3")
#pragma GCC target("avx,avx2")
main()
{
	register long long l,r,k,res=0;long long n;
	scanf("%lld",&n);
	for(l=1;l<=n;l=r+1)
		k=n/l,r=n/k,res+=(l<=r-1&&r*k==n)?(r-1):0;
	printf("%lld\n",res);
}

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

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if(a + b >= x && x >= a) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
// nullbyte

#include <bits/stdc++.h>

using namespace std ;

typedef long long ll ;

const int MAXN = 1e5 + 69 ;
const int INF = 1e9 ;

#define pb push_back

int n , k , light , heavy , it , jt , ans , arr[MAXN] , dist[MAXN] , part[MAXN] ;

int main() {
        cin >> n >> k ; ans = INF ;
        for ( int i = 0 ; i < n ; i ++ ) {
                cin >> arr[i] ;
                if ( arr[i] <= 0 )
                        light ++ , it = i ;
                if ( arr[i] >= 0 ) {
                        heavy ++ ;
//                      if ( heavy <= k )
                                jt = i ;
                }
        }
        if ( light >= k )
                ans = min(ans , abs(arr[it - k + 1])) ;
        if ( heavy >= k )
                ans = min(ans , abs(arr[jt])) ;
        for ( int i = 1 ; i < n ; i ++ )
                dist[i] = abs(arr[i] - arr[i - 1]) ;
        for ( int i = 1 ; i < n ; i ++ )
                part[i] = part[i - 1] + dist[i] ;
        for ( int i = k - 1 ; i < n ; i ++ ) {
//              cout << part[i] - part[i - k + 1] << "\n" ;
                ans = min(ans , part[i] - part[i - k + 1] + min(abs(arr[i - k + 1]) , abs(arr[i]))) ;
        }
        cout << ans << "\n" ;
}

Measured memory_bytes: 1408
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# 
# s


S = input()
if len(S) % 2 != 0:
    print("No")
else:
    ans = "Yes"
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] + S[i+1] != "hi":
                ans = "No"
    print(ans)


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

int main() {
	int N, l, r, sum;
    cin >> N;
    sum = 0;
    for (int i = 0; i < N; i++){
      cin >> l >> r;
      sum += r - l + 1;
    }
    cout << sum << endl;
}

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

using namespace std;

int lcs(string x, string y) {
  vector<vector<int> > dp(x.size() + 1, vector<int>(y.size() + 1));
  int xl = x.size();
  int yl = y.size();
  int maxl = 0;
  x = ' ' + x;
  y = ' ' + y;

  for (int i = 0; i <= xl; i++) {
    dp[i][0] = 0;
  }
  for (int j = 1; j <= yl; j++) {
    dp[0][j] = 0;
  }

  for (int i = 1; i <= xl; i++) {
    for (int j = 1; j <= yl; j++) {
      if (x[i] == y[j]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
      maxl = max(maxl, dp[i][j]);
    }
  }
  return maxl;
}

int main() {
  int q;
  cin >> q;
  string x, y;
  rep(i, q) {
    cin >> x >> y;
    cout << lcs(x, y) << endl;
  }
  return 0;
}


Measured memory_bytes: 6880
#include<stdio.h>
            int main(){
              int N,A,B;
              if(1<=N<=20,1<=A<=50,1<=B<=50){
              scanf("%d %d %d",&N,&A,&B);
              int Train=N*A;
              if(Train < B){
                printf("%d",Train);
              }else{
                printf("%d",B);
              }
              return 0;
            }
            }

Measured memory_bytes: 128
import re
class c(int):
    def __add__(self,n):
        return c(int(self)+int(n))
    def __mul__(self,n):
        return c(int(self)*int(n))

s=input()
d=int(input())
a=eval(re.sub(r'(\d+)',r'c(\1)',s))
b=int(s[0])
for i in range(1,len(s),2):
    if s[i]=='+':b+=int(s[i+1])
    else:b*=int(s[i+1])
if(a==b==d):e='U'
elif(a==d):e='M'
elif(b==d):e='L'
else:e='I'
print(e)

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

/* Function checks if passed strings (str1
and str2) are rotations of each other */
bool areRotations(string str1, string str2)
{
/* Check if sizes of two strings are same */
if (str1.length() != str2.length())
		return false;

string temp = str1 + str1; 
return (temp.find(str2) != string::npos);
}

/* Driver program to test areRotations */
int main()
{
string str1;
string str2;
cin >> str1;
cin >> str2;
if (areRotations(str1, str2))
	printf("Yes");
else
	printf("No");
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>

using namespace std;

double stan_dev(double [], int);

double stan_dev(double s[], int count)
{
	double a = 0;
	double average = 0;
	for (int i = 0; i < count; ++i)
	{
		average += s[i];
	}
	average /= count;
	for (int i = 0; i < count; ++i)
	{
		a += pow(s[i] - average, 2.0); 
	}
	return sqrt(a / count);
}

int main(int argc, char const *argv[])
{
	int count = 0;
	while(true)
	{
		cin >> count;
		if (count == 0) break;
		double s[count];

		for (int i = 0; i < count; ++i)
		{
			cin >> s[i];
		}
		double a = stan_dev(s, count);
		printf("%lf\n", a);
	}
		
	return 0;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
#define optimize  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back

using namespace std;

int aa[105];
int main()
{
    optimize;

    int n,d,x,s=0;

    cin>>n>>d>>x;

    int a[n];

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

    for(int i =0;i<n;i++){
        s =s+ 1;
        int k = 1;
        while(1){
            if((k*a[i]+1)<=d){
                s = s+ 1;
                k++;
            }
            else
                break;
        }
    }

    cout<<s+x<<endl;

}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

class Amida{
public:
	Amida(int n, int m){
		_n = n;

		for(int i = 1; i <= n; i ++)
			for(int j = 1; j <= MAX_H; j ++)
				amidaMap[j][i] = i;
	}

	void set(int h, int p, int q){
		amidaMap[h][p] = q;
		amidaMap[h][q] = p;
	}

	int getGoal(int target){
		int curPos = target;
		for(int j = MAX_H; j >= 1; j --)
			curPos = amidaMap[j][curPos];
		return curPos;
	}

private:
	static const int MAX_H = 1000;
	static const int MAX_N = 100;
	int amidaMap[MAX_H + 1][MAX_N + 1];

	int _n;
};

int main(void){
	for(int n, m, a; cin >> n >> m >> a, n;){
		Amida amida(n, m);

		while(m --){
			int h, p, q; cin >> h >> p >> q;
			amida.set(h, p, q);
		}
		cout << amida.getGoal(a) << endl;
	}
	

	return 0;
}

Measured memory_bytes: 1552
#include<stdio.h>
char s[105];
int main()
{
    int n,max=0,i,j,k,p;
    scanf("%d",&n);
    scanf("%s",s);
    for(i=1;i<n;i++)
    {
       int  sum=0;
        for(j=0;j<i;j++)
        {
            int flag=1;
            for(p=0;p<j;p++)
            {
                if(s[p]==s[j])
                    flag=0;
            }
            if(flag==1)
            {
                for(k=i;k<n;k++)
            {
                if(s[j]==s[k])
                {
                    sum++;
                    break;
                }
            }
            }
        }
        if(max<sum)
            max=sum;
    }
    printf("%d",max);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    string S;
    cin >> S;
    ll mi=INF;
    crep(i){
        ll C=0,ma=-1;
        rep(j,S.size()){
            if(S[j]!=i){
                C++;
            }
            if(S[j]==i||j==S.size()-1){
                ma=max(C,ma);
                C=0;
            }
        }
        mi=min(ma,mi);
    }
    cout << mi << endl;
}

Measured memory_bytes: 256
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

def main():
    h,w,n,*a=map(int,open(0).read().split())
    ans=[]
    for k,v in enumerate(a):
        for i in range(v):
            ans.append(k+1)
#            print(ans)
            if len(ans)%w==0:
                if (len(ans)//w)%2:
                    print(*ans[-w:])
                else:
                    print(*ans[-w:][::-1])
if __name__ == '__main__':
    main()


Measured memory_bytes: 5956
from sys import stdin
input = stdin.readline

n, k = map(int, input().split())
arr = list(tuple(map(int, input().split())) for _ in range(n))
arr = sorted(arr, key=lambda x:x[0])
res = 0
for i in range(n):
    tk = min(k, arr[i][1])
    res += tk*arr[i][0]
    k -= tk
print(res)


Measured memory_bytes: 59424
#include<iostream>
#include<vector>
#define LL long long
LL N, M;
bool flag;
std::vector<int> G[100010];
int T[100010];
LL L, R;
void dfs(int g) {
	if (flag)return;
	if (T[g] == 1)L++;
	else R++;
	for (auto u : G[g]) {
		if (flag)return;
		if (!T[u]) {
			T[u] = ~T[g];
			dfs(u);
		}
		else if(T[u]!=~T[g]){
			flag = true;
			return;
		}
	}
}

int main() {
	std::cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b;
		std::cin >> a >> b;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}
	T[1] = 1;
	dfs(1);
	if (flag)std::cout << (N*(N - 1)) / 2 - M << std::endl;
	else std::cout << L * R - M <<std::endl;
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cmath>
#include <vector>
#include <string>

typedef long long ll;

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll N;
  std::cin >> N;

  bool judge = false;
  for (ll i = 1; i <= 9; i++) {
    for (ll j = 1; j <= 9; j++) {
      if (i * j == N) judge = true;
    }
  }

  if (judge) print("Yes");
  else print("No");

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int x,w,n,a1,a2,kioku,amida[30]={0};
	scanf("%d",&w);
	for(x=0; x<w; x++)
		amida[x]=x+1;
	scanf("%d",&n);
	for(x=0; x<n; x++)
	{
		scanf("%d,%d",&a1,&a2);
		kioku=amida[a1-1];
		amida[a1-1]=amida[a2-1];
		amida[a2-1]=kioku;
	}
	for(x=0; x<w; x++)
		printf("%d\n",amida[x]);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void)
{
	
	char str1[10];/*変数宣言*/
	char str2[10];
	char str3[10];
	
	scanf("%s", str1);/*一行目入力*/
	scanf("%s", str2);/*二行目入力*/
	scanf("%s", str3);/*三行目入力*/
	
	printf("%c%c%c\n", str1[0], str2[1], str3[2]);/*出力*/
	
	return 0;
}

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

int main()
{
 int N;
  int count=0;
  cin>>N;
  vector<int> vec(N+1);
  vec.at(N)=N+1;
  for(int i=0;i<N;i++)
  {
    cin>>vec.at(i);
  }
  for(int i=0;i<N;i++)
  {
   if(vec.at(i)!=i+1)
   {
   count++;
   }
  }
  
  if(count==2||count==0)
  {
  cout<<"YES"<<endl;
  }
  else
  {
   cout<<"NO"<<endl;
  }
  
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int N, M; cin >> N >> M;
  int s=1, e=N;
  rep(i,M) {
    int l, r; cin >> l >> r;
    s = max(s, l);
    e = min(e, r);
  } 
  cout << max(e-s+1,0) << endl;
  return 0;
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<int> > cnt(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    vector<int> done(w, 0);
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      if (done[j]) continue;
      int l = 0;
      while(j + l < w) {
        if (s[i][j + l] == '#') break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i][j+k] += l;
        done[j + k] = 1;
      }
    }
  }
  for (int j = 0; j < w; j++) {
    vector<int> done(h, 0);
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '#') continue;
      if (done[i]) continue;
      int l = 0;
      while(i + l < h) {
        if (s[i + l][j] == '#') break;
        l++;
      }
      for (int k = 0; k < l; k++) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, cnt[i][j] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20096
use std::io;

fn main() {
    let _n = read::<i32>();
    let mut a = read_vec::<String>();
    let mut b = a.clone();

    bubble_sort(&mut a);
    print_vec(&a);
    println!("Stable");

    selection_sort(&mut b);
    print_vec(&b);

    if is_stable(&a, &b) {
        println!("Stable");
    } else {
        println!("Not stable");
    }
}


// カードの数字を取り出す
pub fn get_num(input: &str) -> usize {
    // let card = &input;
    let num: usize = input[1..2].parse().unwrap();
    num
}

#[test]
fn test() {
    let c: usize = get_num(&"H4");
    assert_eq!(4, c);
}

/// 入力と出力から安定なソートか調べる
pub fn is_stable(input: &[String], out: &[String]) -> bool {
    let len = input.len();
    for i in 0..len {
        for j in i+1..len {
            // 同じ値が存在するか確認
            if get_num(input[i].as_str()) == get_num(input[j].as_str()) {
                for a in 0..len {
                    for b in a+1..len {
                        // 出力においてもi番目があと(b)、手前にj番目(a)が来ていたらFlase
                        if input[i] == out[b] && input[j] == out[a] {
                            return false;
                        }
                    }
                }
            }
        }
    }
    true
}


/// バブルソート
/// 何回更新したかを返す
/// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/2/ALDS1_2_A
pub fn bubble_sort(x: &mut [String]) {
    let mut flag = true;
    while flag {
        flag = false;
        for j in 1..x.len() {
            if get_num(x[j].as_str()) < get_num(x[j - 1].as_str()) {
                x.swap(j, j - 1);
                flag = true;
            }
        }
    }
}

/// 選択ソート
/// 左から順に最小の値を検索しては入れていく
/// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/2/ALDS1_2_B
pub fn selection_sort(x: &mut [String]) {
    for i in 0..x.len() {
        let mut minj = i;
        for j in i+1..x.len() {
            if get_num(x[j].as_str()) < get_num(x[minj].as_str()) {
                minj = j;
            }
        }
        x.swap(i, minj);
    }
}

fn print_vec<T: std::fmt::Display>(v: &Vec<T>) {
    for a in &v[0..v.len() - 1] {
        print!("{} ", a);
    }
    println!("{}", v[v.len() - 1]);
}

/// 標準入力から一行を読み取り、指定の型に変換する関数
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

/// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 5032
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	string s, t;
	


	ll x[10000007] = {};
	cin >> a;
	cin >> b;

	for (int i = 0; i < a; i++)
	{
		cin >> x[i];
	}
	sort(x, x + a);
	c = 10000000000000000;
	for (int i = 0; i < a-b+1; i++)
	{
		c = min(abs(x[i] - x[i + b-1]), c);
	}
	cout << c << endl;

	//cout << ans << endl;
	//cout <<  << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 78336
N=int(input())
R=len(str(N))
def dsum(X):
	return(sum([ int(n) for n in list(str(X))]))
cand=[dsum(N)]
for i in range(R):
	a = (N//(10**i))*(10**i) + int('9'*i) if i>0 else 0
	b = (N//(10**i)-1)*(10**i) + int('9'*i) if i>0 else 0
	if a<=N:
		cand.append(dsum(a))
	else:
		cand.append(dsum(b))
print(max(cand))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;
int c[10000];
string a;
int main(){
	cin>>a;
	for(int i=1;i<=1000;i++)c[i]=0;
	for(int i=0;i<a.size();i++)c[a[i]]++;
	//cout<<endl;
	for(int i='a';i<='z';i++)if(c[i]%2!=0)c[1]++;
	//for(int i='a';i<='z';i++)cout<<c[i]<<' ';
	//cout<<endl;
	//cout<<c[1]<<endl;
	if(!c[1])cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline

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

a.insert(0, 0)
c = dict()
c[1 + a[1]] = 1
cnt = 0

for x in range(2, n + 1):
    if x - a[x] in c.keys():
        cnt += c[x - a[x]]

    if x + a[x] < 0:
        continue

    if x + a[x] in c.keys():
        c[x + a[x]] += 1
    else:
        c[x + a[x]] = 1

print(cnt)

Measured memory_bytes: 40076
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
  int n; cin >> n;
  vector<ll> A(n),counter(1000100); 
  rep(i, n){
    cin >> A[i];
    counter[A[i]]++;
  }
  sort(all(A));

  int res = 0;
  vector<bool> check(1000100);
  rep(i, n){
    int num = A[i];
    if(counter[num]==1 && check[num] == false)res++;
    if(counter[num] == INF)continue;//既にふるいをかけているなら飛ばす
    for(int j=num; j<=1000000; j += num){
      check[j] = true;
    }
    counter[num] = INF;//INF=ふるいをかけた状態
  }

  cout << res << ln;
}



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

using namespace std;

struct edge {
	int idx;
	int src;
	int dst;
};

long long popcount(long long n)
{
	return n == 0 ? 0 : (n & 1) + popcount(n >> 1);
}

bool dfs(int N, const vector<vector<edge>>& g, int src, int dst, int parent, vector<int>& p)
{
	if (src == dst) {
		return true;
	}
	for (auto& e : g[src]) {
		if (e.dst == parent) {
			continue;
		}
		p.push_back(e.idx);
		if (dfs(N, g, e.dst, dst, e.src, p)) {
			return true;
		}
		p.pop_back();
	}
	return false;
}

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

	vector<vector<edge>> g(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		edge a2b = { i, a, b };
		edge b2a = { i, b, a };
		g[a].push_back(a2b);
		g[b].push_back(b2a);
	}

	vector<vector<vector<int>>> paths(N, vector<vector<int>>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i != j) {
				dfs(N, g, i, j, -1, paths[i][j]);
			}
		}
	}


	int M;
	cin >> M;
	vector<int> u(M), v(M);
	for (int i = 0; i < M; ++i) {
		cin >> u[i] >> v[i];
		--u[i];
		--v[i];
	}

	long long ans = 1LL << (N - 1);
	for (int mask = 1; mask < (1 << M); ++mask) {
		long long edge_set = 0;
		for (int k = 0; k < M; ++k) {
			if (mask & (1 << k)) {
				for (auto idx : paths[u[k]][v[k]]) {
					edge_set |= 1LL << idx;
				}
			}
		}
		long long c = 1LL << (N - 1 - popcount(edge_set));
		
		if (popcount(mask) & 1) {
			ans -= c;
		}
		else {
			ans += c;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main (String[] args) {
   	 Scanner sc = new Scanner(System.in);
   	 int N = sc.nextInt();
   	 Integer a[] = new Integer[N];
   	 for(int i = 0; i < N; i++) {
   		 a[i] = sc.nextInt();
   	 }
   	 Set<Integer> outputSet = new HashSet<Integer>(Arrays.asList(a));
   	 System.out.println(outputSet.size());
   	 sc.close();
    }
}


Measured memory_bytes: 36004
import sys

input = sys.stdin.readline

def main():
    S = input().rstrip('\n')
    t = '0168'
    if S[-1] == '3':
        print('bon')
    elif S[-1] in t:
        print('pon')
    else:
        print('hon')
if __name__ == '__main__':
    main()

Measured memory_bytes: 9052
/*
https://t.me/unstoppabIesoIvemachinechannel
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;






const int INF = 1e9;

signed main(){
    int n, m;
    cin >> n >> m;
    int nn = (1 << n);
    int dp[nn];
    dp[0] = 0;
    for (int i = 1; i < nn; i++){
        dp[i] = INF;
    }
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        int mesk = 0;
        for (int j = 0; j < b; j++){
            int c;
            cin >> c;
            c--;
            mesk |= (1 << c);
        }
        for (int mask = 0; mask < nn; mask++){
            dp[mask | mesk] = min(dp[mask | mesk], dp[mask] + a);
        }
    }
    if (dp[nn - 1] == INF){
        cout << -1;
    }else cout << dp[nn-1];
}


Measured memory_bytes: 256
// abc132d.cpp : Blue and Red Balls
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define upto(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define oute(x) cout<<(x)<<endl

#define MAX 2001
ll inv[MAX];

int main(){
  int N,K; cin>>N>>K;
  int red = N-K, blue = K;

  inv[1] = 1;
  upto(i,2,(red<blue? blue: red)+2,1)
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;

  ll ai = red + 1;
  oute(ai);
  upto(i,2,blue+1,1){
    ai = (ai *  (red-i+2) * (blue-i+1) % MOD) * (inv[i] * inv[i-1] % MOD) % MOD;
    oute(ai);
  }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
*A, = map(int, input().split())
C = {0: 1}
ans = 0
s = 0
for a in A:
    s = (s + a) % M
    ans += C.get(s, 0)
    C[s] = C.get(s, 0) + 1
print(ans)


Measured memory_bytes: 62576
use std::io;
use std::io::{stdout, Write};
use std::cmp;

fn main() {
    let mut X = String::new();
    io::stdin().read_line(&mut X);
    let mut vec :Vec<&str> = X.trim().split_whitespace().collect();
    let mut x :usize = vec[0].parse().unwrap();
    let mut y :usize = vec[1].parse().unwrap();
    for i in 0..=x{
        if (i*2 + (x-i)*4) == y {
            println!("Yes");
            return ()
        }
    }
    println!("No")
}

Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}


int main(){
    ll n;cin >> n;
    vl v(n);rep(i,n)cin >> v[i];
    ll ans=0;
    rep(i,n){
        repl(j,i+1,n){
            repl(k,j+1,n){
                if(v[i]==v[j]||v[j]==v[k]||v[k]==v[i])continue;
                //cout << 1 <<endl;
                bool ok=true;
                if(v[i]>=v[j]+v[k])ok=false;
                if(v[j]>=v[i]+v[k])ok=false;
                if(v[k]>=v[j]+v[i])ok=false;
                if(ok)ans++;
            }
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  ll ans = 0;
  rep(i, 1<<(n-1)) {
    ll cur = s[0]-'0';
    rep(j, n-1) {
      if((i>>j)&1) {
        ans += cur;
        cur = 0;
      } else {
        cur *= 10;
      }
      cur += s[j+1]-'0';
    }
    ans += cur;
  }
  cout << ans << "\n";
  return 0;
}


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

result = 0

if K == 1:
    B = A
    for i in range(N):
        for j in range(i+1, N):
            if B[i] > B[j]:
                result += 1
else:
    B = A + A
    for i in range(N):
        C = 0
        D = 0
        E = 0
        for j in range(i+1, N):
            if B[i] > B[j]:
                C += 1
        for j in range(N, N+i+1):
            if B[i] > B[j]:
                D += 1
        E = K * (K * (C + D) + C - D) // 2
        E = E % (10**9 + 7)
        result += E
    result = result % (10**9 + 7)

print(result)


Measured memory_bytes: 42604
#include <iostream>
using namespace std;
int main(void){
   int n, m;
   cin>>n>>m;
   int x[n][m],y[m],v;
   for(int i=0;i<n;i++){
       for(int j=0;j<m;j++){
           cin>>x[i][j];
       }
   }
   for(int i=0;i<m;i++){
       cin>>y[i];
   }
   for(int i=0;i<n;i++){
       v=0;
       for(int j=0;j<m;j++){
           v+=x[i][j]*y[j];
           
       }
       cout<<v<<endl;
   }
}



Measured memory_bytes: 3120
#include <iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n;
    for (int i=1; ; ++i) {
        cin >> n;
        if (n == 0) {
            break;
        }
        cout << "Case " << i << ": " << n << "\n";
    }
 
    return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int count = 0;
	for(int i=a;i<=b;i++){
		if(i%c==0)
		count++; 
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 3616
#include<set>
#include<map>
#include <unordered_map>
#include <unordered_set>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <strings.h>
#include <fstream>


#define f first
#define s second
#define pb push_back
#define lp(i,a,n) for(int (i)=(a);(i)<=(int)(n);(i)++)
#define lpd(i,n,a) for(int (i)=(n);(i)>=(a);--(i))
#define mp make_pair
#define clr(a, b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define eps 1e-8
#define infi 2000000007
#define infll 2e18
#define sz(a) (int) (a).size()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<ll, ll> mll;


int main(){
    int n,k,x;
    cin>>n>>k;
    lp(i,1,n){
        cin>>x;
    }
    cout<<(n  + k - 3 ) / (k - 1)<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    int a=scan.nextInt();
    int b=scan.nextInt();
    int k=scan.nextInt();
    int count=0;
    for(int i=a;i>0;i--){
      if((a%i==0)&&(b%i==0)) count++;
      if(count==k){
        System.out.println(i);
        i=0;
      }
    }
  }
}


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

int cal(int val){
    int cnt = 0;
    while(val % 100 == 0){
        val/=100;
        cnt++;
    }
    return cnt;
}


int main() {
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int d, n, cnt = 0, val = 1;
    cin >> d >> n;
    for(int i=0;i<d;i++){
        val *= 100;
    }
    while(1){
        if(cal(val) == d){
            cnt++;
        }
        if(cnt == n)
            break;
        val++;
    }

    cout << val << '\n';

    return 0;
}


Measured memory_bytes: 256
"""D."""

import sys

#def input() -> str:  # noqa: A001
#    """Input."""
#    return sys.stdin.readline()[:-1]


class UnionFindTree:
    """Union-find."""

    def __init__(self, n: int) -> None:
        """Init."""
        self.n = n
        self.rank = [-1] * n

    def find_root(self, x: int) -> int:
        """Find root."""

        if self.rank[x] < 0:
            return x

        self.rank[x] = self.find_root(self.rank[x])
        return self.rank[x]

    def union(self, x: int, y: int) -> None:
        """Unite two trees."""
        x_root = self.find_root(x)
        y_root = self.find_root(y)

        if x_root == y_root:
            return

        if x_root > y_root:
            x_root, y_root = y_root, x_root

        self.rank[x_root] += self.rank[y_root]
        self.rank[y_root] = x_root

    def get_size(self, x: int) -> int:
        """Get size."""
        return self.rank[self.find_root(x)] * -1

    def is_same(self, x: int, y: int) -> bool:
        """Is same group."""
        return self.find_root(x) == self.find_root(y)


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

tree = UnionFindTree(n)

for _ in range(m):
    a, b = map(int, input().split(' '))
    tree.union(a - 1, b - 1)

ans = 0

for i in range(n):
    ans = max(ans, tree.get_size(i))

print(ans)


Measured memory_bytes: 16788
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 19;

char s[N][N];
int p[N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  for (int mask = 0; mask < (1 << n); ++mask) {
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        ++cnt;
      }
    }
    if (cnt != (n + 1) / 2) {
      continue;
    }
    vector<int> a, b;
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        a.push_back(i);
      } else {
        b.push_back(i);
      }
    }
    for (int i = 0; i < (n + 1) / 2; ++i) {
      p[i] = i;
    }
    do {
      map<long long, int> w;
      map<long long, long long> r;
      for (int j = 0; j < m; ++j) {
        long long x = 0;
        long long rx = 0;
        long long z = 1;
        for (int i = 0; i < n / 2; ++i) {
          x += (s[a[p[i]]][j] - 'a') * z;
          x += (s[b[i]][j] - 'a') * z * 26;
          rx += (s[b[i]][j] - 'a') * z;
          rx += (s[a[p[i]]][j] - 'a') * z * 26;
          z *= 26 * 26;
        }
        if (n % 2 == 1) {
          x += (s[a[p[n / 2]]][j] - 'a') * z;
          rx += (s[a[p[n / 2]]][j] - 'a') * z;
        }
        ++w[x];
        r[x] = rx;
      }
      bool ok = true;
      int odd = 0;
      for (auto &e : w) {
        long long rx = r[e.first];
        if (rx == e.first) {
          if (e.second % 2 == 1) {
            ++odd;
          }
        } else {
          if (w.count(rx) == 0 || w[rx] != e.second) {
            ok = false;
          }
        }
      }
      if (ok && odd == m % 2) {
        puts("YES");
        return 0;
      }
    } while (next_permutation(p, p + (n + 1) / 2));
  }
  puts("NO");
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    int border = sc.nextInt();
    int can = 0;
    
    for (int i = 0; i < num; i++){
      if(sc.nextInt()>=border){
        can++;
      }
    }
    
    System.out.println(can);
  }
}

Measured memory_bytes: 47348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long llong;

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> rest(N);
  rep(i, N) {
    string S;
    int P;
    cin >> S >> P;
    rest[i] = make_tuple(S, -P, i + 1);
  }

  sort(rest.begin(), rest.end());
  rep(i, N) cout << get<2>(rest[i]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 2147483647
#define MOD 1000000007
using namespace std;
typedef pair<int,int> pii;
vector<int> arr[1010101];
int n,m;
main()
{
	cin>>n>>m;
	if(n*500>=m) puts("Yes");
	else puts("No");
}

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

using namespace std;

vector<vector<pair<int,int> > > G;
vector<long long> dist;

void dfs(int v, int prev, long long d) {
	dist[v] = d;
	for(auto&e:G[v]) {
		if(e.first==prev) continue;
		dfs(e.first,v,d+e.second);
	}
}

int main() {
	int n; cin >> n;
	G.resize(n);
	for(int i=1;i<n;++i) {
		int a,b,c; cin >> a >> b >> c;
		--a, --b;
		G[a].emplace_back(b,c);
		G[b].emplace_back(a,c);
	}
	dist.assign(n,0);
	int q,k; cin >> q >> k;
	--k;
	dfs(k,-1,0);
	while(q--) {
		int x,y; cin >> x >> y;
		--x, --y;
		cout << dist[x] + dist[y] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int l, r;
    cin >> l >> r;
    int answer = 0;
    if ((l / 2019) != (r / 2019)) {
        answer = 0;
    } else {
        answer = 2019;
        for (int i = l; i < r; ++i) {
            for (int j = i + 1; j <= r; ++j) {
                int mod = (long(i) * j) % 2019;
                answer = min(answer, mod);
            }
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
Sx, Sy, Tx, Ty = map(int, input().split())

Takasa = Ty-Sy
Haba = Tx-Sx

Ito = []

for i in range (0, Takasa):
	Ito.append('U')

for i in range (0, Haba):
	Ito.append('R')

for i in range (0, Takasa):
	Ito.append('D')

for i in range (0, Haba+1):
	Ito.append('L')

for i in range (0, Takasa+1):
	Ito.append('U')

for i in range (0, Haba+1):
	Ito.append('R')

Ito.append('DR')

for i in range (0, Takasa+1):
	Ito.append('D')

for i in range (0, Haba+1):
	Ito.append('L')

Ito.append('U')

print(*Ito, sep='')

Measured memory_bytes: 4852