akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
const int mod = 1000000007;
int N, M;
int main() {
	cin >> N >> M;
	if (N - M <= -2 || 2 <= N - M) cout << 0 << endl;
	else {
		int ret = 1;
		for (int i = 1; i <= N; i++) ret = 1LL * ret * i % mod;
		for (int i = 1; i <= M; i++) ret = 1LL * ret * i % mod;
		cout << ret * (N - M == 0 ? 2 : 1) % mod << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int a[4], b[4];
    while(cin >> a[0]){
        REP(i, 1, 4){
            cin >> a[i];
        }
        rep(i, 4){
            cin >> b[i];
        }

        int hi = 0, bl = 0;
        rep(i, 4){
            if(a[i] == b[i]){
                ++hi;
            }else{
                rep(j, 4){
                    if(i == j){
                        continue;
                    }
                    if(a[j] == b[i]){
                        ++bl;
                    }
                }
            }
        }

        cout << hi << " " << bl << endl;
    }

    cout << flush;

    return 0;
}


Measured memory_bytes: 3076
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Main {
	private static Object GRAY = new Object();
	private static Object BROWN = new Object();
	private static Object GREEN = new Object();
	private static Object SKYBLUE = new Object();
	private static Object BLUE = new Object();
	private static Object YELLOW = new Object();
	private static Object ORANGE = new Object();
	private static Object RED = new Object();
	private static List<Object> RATES_DEFAULT = Arrays.asList(GRAY, BROWN, GREEN, SKYBLUE, BLUE, YELLOW, ORANGE, RED);

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		scanner.nextLine();

		Function<Integer, Object> classifier = i -> {
					if (i < 400) return GRAY;
					if (i < 800) return BROWN;
					if (i < 1200) return GREEN;
					if (i < 1600) return SKYBLUE;
					if (i < 2000) return BLUE;
					if (i < 2400) return YELLOW;
					if (i < 2800) return ORANGE;
					if (i < 3200) return RED;
					return new Object();
				};
		List<Object> rates = Arrays.stream(scanner.nextLine().split(" ")).map(Integer::parseInt).map(classifier).distinct().collect(Collectors.toList());

		int max = rates.size();
		rates.retainAll(RATES_DEFAULT);
		int min = Math.max(rates.size(), 1);
		System.out.println(min + " " + max);
	}
}


Measured memory_bytes: 29908
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, c, k;
  cin >> n >> c >> k;
  vl t(n);
  rep(i, n) cin >> t[i];
  sort(all(t));
  ll now = 0, cnt = 0, ans = 0;
  rep(i, n) {
    if(t[i] > now || cnt == c) {
      ans++;
      now = t[i] + k;
      cnt = 1;
    } else
      cnt++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3976
main :: IO()
main = do
    n <- getLine 
    putStrLn $ if isCoffee n then "Yes" else "No"

isCoffee :: String -> Bool
isCoffee s =
    let
        c3 = s !! 2 
        c4 = s !! 3
        c5 = s !! 4
        c6 = s !! 5 
    in
    c3 == c4 && c5 == c6



Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=INF;
 
int main() {
    int n;
    cin >> n;
    ll k;
    cin >> k;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    vector<int> e(0),d(n,-1);
    int r=0,c=0;
    while(true){
        if (d[r]!=-1) break;
        d[r]=c;
        e.push_back(r+1);
        r=a[r]-1;
        c++;
    }
    if (k<c) cout << e[k] << endl;
    else{
        ll y=d[r],b=e.size();
        cout << e[y+(k-c)%(b-y)] << endl;
    }
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL LINF=1LL<<62;
const LL mod=1e9+7;




int main(){
    int n,q;
    string s;
    cin >> n >> s >> q;
    for (int p = 0; p < q; p++) {
        int k;cin >> k;
        LL ans=0;
        vector<LL> m(n+1,0);
        for (int i = 0; i < n; i++) {
            m[i+1]=m[i]+(s[i]=='M'?1:0);
        }
        LL sum=0;
        queue<LL> que;
        for (int i = n-1; i >= 0; i--) {
            if(!que.empty()&&que.front()-k>=i){
                sum-=m[que.front()+1]-m[i+1];
                que.pop();
            }
            if(s[i]=='C'){
                que.push(i);
            }
            else if(s[i]=='M'){
                sum+=que.size();
            }
            else if(s[i]=='D'){
                ans+=sum;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 17228
#include<iostream>

using namespace std;

int main(void){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  A += B;
  C += D;
  if(A > C) cout << "Left" << endl;
  else if(A == C) cout << "Balanced" << endl;
  else cout << "Right" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
 
ll mod = 1e9+7;
 
ll max(ll a, ll b ) {
	if(a>b)
		return a;
	else return b;
}
ll min(ll a, ll b ) {
	if(a<b)
		return a;
	else return b;
}

int main() {
	ll ttt;
	//cin>>ttt;
	ttt = 1;
	while(ttt--) {
		//0 1 2 3 4 5
		//0 1 2
		string s,t; cin>>s>>t;
		ll ans = 1e10;
		for(int i=0; i<=s.length()-t.length(); i++) {
			ll ct = 0;
			for(int j=i; j<i+t.length(); j++) {
				if(s[j]!=t[j-i]) ct++;
			}
			ans = min(ct,ans);
		}
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;

int N , a[200005] ;

void solve(){
	long long ans = 0 ;
	int Lpt = 1 , Rpt = 1 , sum = 0 , xsum = 0 ;
	while( Rpt <= N ){
		sum += a[Rpt] , xsum ^= a[Rpt] ;
		while( sum != xsum ) sum -= a[Lpt] , xsum ^= a[Lpt++] ;
		ans += Rpt - Lpt + 1 , Rpt ++ ;
	} printf( "%lld" , ans ) ;
}

int main(){
	scanf( "%d" , &N ) ;
	for( int i = 1 ; i <= N ; i ++ )
		scanf( "%d" , &a[i] ) ;
	solve() ;
}


Measured memory_bytes: 896
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}
	}
}



Measured memory_bytes: 26192
N=int(input())
W=list(map(int,input().split()))
a=100000
for i in range(N-1):
    s1=0
    s2=0
    for j in range(N):
        if j <= i:
            s1 += W[j]
        else:
            s2 += W[j]
    a=min(a,abs(s1-s2))
    #print("s1,s2=",s1,",",s2)
print(a)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
	int A, B;
	double T;
	int ans = 0;
	cin >> A >> B >> T;

	T += 0.5;
	int i = 1;
	int ET = A;

	while (ET <= T) {
		ans += B;
		i++;
		ET = i*A;
	}

	cout << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> ans(n);
  for(int i = 1; i < n; i++){
    int a;
    cin >> a;
    ans[a - 1]++;
  }
  for(int i = 0; i < n; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.14159265359;
typedef pair<int,int> P;

signed main() {
    int H,W,K;
    cin >> H >> W >> K;
    vector<vector<char>> vec(H,vector<char>(W));
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            cin >> vec.at(i).at(j);
        }
    }
    vector<vector<int>> ret(H,vector<int>(W));
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            ret.at(i).at(j) = 0;
        }
    }
    int cnt = 1;
    for(int i = 0;i < H;i++) {
        bool count = false;
        for(int j = 0;j < W;j++) {
            if(vec.at(i).at(j) == '#') {
                count = true;
            }
        }
        if(count == true) {
            bool cnt2 = false;
            for(int j = 0;j < W;j++) {
                if(vec.at(i).at(j) == '#') {
                    if(cnt2 == false) {
                        ret.at(i).at(j) = cnt;
                    }
                    else {
                        cnt++;
                        ret.at(i).at(j) = cnt;
                    }
                    cnt2 = true;
                }
                if(j == W - 1) {
                    ret.at(i).at(j) = cnt;
                    cnt++;
                }
                else {
                    ret.at(i).at(j) = cnt;
                }
            }
        }
    }
    for(int i = 0;i < H;i++) {
        if(ret.at(i).at(0) == 0) {
            for(int j = i;j >= 0;j--) {
                if(ret.at(j).at(0) != 0) {
                    for(int k = 0;k < W;k++) {
                        ret.at(i).at(k) = ret.at(j).at(k);
                    }
                    break;
                }
            }
            for(int j = i;j < H;j++) {
                if(ret.at(j).at(0) != 0) {
                    for(int k = 0;k < W;k++) {
                        ret.at(i).at(k) = ret.at(j).at(k);
                    }
                    break;
                }
            }
        }
    }
    for(int i = 0;i < H;i++) {
        for(int j = 0;j < W;j++) {
            cout << ret.at(i).at(j);
            if(j == W - 1) {
                cout << endl;
            }
            else {
                cout << " ";
            }
        }
    }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),Y=in();
	int maxA = Y/10000;
	for(int A=0;A<=maxA;A++){
		int maxB = (Y-10000*A)/5000;
		for(int B=0;B<=maxB;B++){
			int C = (Y-10000*A-5000*B)/1000;
			if((A+B+C)==N){
				cout << A << ' ' << B << ' ' << C << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}


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

//UnionFind
const int64_t n = 100000;
vector<int64_t> par(n);
vector<int64_t> size(n);

void init(int n){
  for(int i=0; i<n; i++){
    par.at(i) = i;
    size.at(i) = 1;
  }
}

int root(int x){
  if(par.at(x) == x){
    return x;
  }
  else{
    return par.at(x) = root(par.at(x));
  }
}

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

void unite(int x, int y){
  x = root(x);
  y = root(y);
  if(x == y){
    return;
  }
  if (size.at(x) < size.at(y)){
    swap(x, y);
  }
  size.at(x) += size.at(y);
  par.at(y) = x;
}

int size_x(int x){
  return size.at(root(x));
}


int main(){
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> cost(N);
  for(int i=0; i<N; i++){
    cin >> cost[i];
  }
  init(N);
  for(int i=0; i<M; i++){
    int64_t a, b;
    cin >> a >> b;
    unite(a,b);
  }
  
  int64_t INF = 1e9+10;
  
  vector<int64_t> MIN(N,INF);
  for(int i=0; i<N; i++){
    int64_t x = root(i);
    MIN[x] = min(MIN[x],cost[i]);
  }
  
  int64_t ans = 0;
  
  map<int64_t,int64_t> mp;
  for(int i=0; i<N; i++){
    if(MIN[i] == INF){
      continue;
    }
    else{
      if(mp.count(MIN[i])){
        mp[MIN[i]]++;
      }
      else{
        mp[MIN[i]] = 1;
      }
      ans += MIN[i];
    }
  }
  
  int64_t group = 0;
  
  for(int i=0; i<N; i++){
    if(mp.count(cost[i])){
      if(mp[cost[i]] > 0){
        mp[cost[i]]--;
        cost[i] = INF;
        group++;
      }
    }
  }
  
  if(group == 1){
    cout << 0 << endl;
  }
  else if((group-1)*2 > N){
    cout << "Impossible" << endl;
  }
  else{
    sort(cost.begin(),cost.end());
    for(int i=0; i<group-2; i++){
      ans += cost[i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 9600
R,G,B,N=map(int,input().split())
#xR+yG+zB=Nの自然数解の個数
ans=0
for x in range(int(N/R)+1):
    for y in range(int(N/G)+1):
        nokori=N-x*R-y*G
        if nokori>=0 and nokori%B==0:
            ans+=1
print(ans)

Measured memory_bytes: 40812
def main():
    N,M=map(int,input().split())
    H=[int(_) for _ in input().split()]
    near=[[i] for i in range(N)]
    flag=[i for i in range(N)]
    for m in range(M):
        A,B=map(int,input().split())
        near[A-1].append(B-1)
        near[B-1].append(A-1)
    ans=0
    for n in near:
        k=1
        for j in n[1:]:
            if H[n[0]] <= H[j]:
                k=0
        if k:
            ans+=1
    print(ans)

main()

Measured memory_bytes: 39868
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
typedef unsigned long long ull ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define rrep(i , n) for ( int i = n-1; i >=0 ; i--)

#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	ull size_; 
	std::vector<ull> par, rank, count;

public:
	UnionFind() : size_(0), par(std::vector<ull>()), rank(std::vector<ull>()), count(std::vector<ull>()) {};
	UnionFind(ull size__) : size_(size__) {
		par.resize(size_); rank.resize(size_); count.resize(size__);
		for (ull i = 0; i < size_; i++) par[i] = i, rank[i] = 0, count[i] = 1;
	}
	ull size() { return size_; }
	// ull root(ull x) { return par[x] == x ? x : par[x] = root(par[x]); }
	
	ull root(ull x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	
	bool same(ull x, ull y) { return root(x) == root(y); }

	void unite(ull x, ull y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y, count[y]+=count[x], count[x]=0;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++, count[x]+=count[y], count[y]=0;
		else par[y] = x, count[x] += count[y], count[y] = 0;
	}

	ull size__(ull x)
	{
		return count[root(x)];
	}

	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};
/*
maybe sth wrong 
got wa in one problem
*/
ll modpow(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}

	if (b % 2)
	{
		return a * modpow(a, b-1) % MOD;
	}
	else
	{
		ll halfB = b / 2;
		ll half = modpow(a, halfB);
		return half * half % MOD;
	}
}

ll calcComb(ll n, ll m)
{
	if (m > n-m)
	{
		return calcComb(n, n-m);
	}

	ll ansMul = 1;
	ll ansDiv = 1;

	rep(i, m)
	{
		ansMul *= (n-i);
		ansDiv *= (i+1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}

	return ansMul * modpow(ansDiv, MOD - 2) % MOD;
}

__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}


int main()
{
	ll N, K;
	
	cin >> N >> K;

	double p[N];

	double s[N+1];
	s[0] = 0;
	rep(i, N)
	{
		double tmp ;
		cin >> tmp;

		p[i] = (1+tmp) / 2.0;
		s[i+1] = s[i] + p[i];
	}

	double max_ = 0.0;

	
	for(int i = K; i <= N; i++)
	{
		max_ = max(max_, s[i] - s[i-K]);
	}
	
	//cout << max_ << endl;
	//printf("%lf\n", max_);
	std::cout << std::setprecision(7) << max_ << std::endl;

	
	return 0;
}


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

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

  vector<int> a(n);
  for (auto &i : a) {
    cin >> i;
    --i;
  }
  a.push_back(-1);

  int ans = 0;
  for (int i = 0; i < n + 1; ++i) {
    if (a[i] == i) {
      ans++;
      swap(a[i], a[i + 1]);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define INF 200000001
using namespace std;

typedef pair<int,int> pi;

int main(){
    int n,m;
    cin>>n>>m;
    pi student[n];
    pi check[m];
    for(int i=0; i<n; ++i){
        int a,b;
        cin>>a>>b;
        student[i]=make_pair(a,b);
    }
    for(int i=0; i<m; ++i){
        int c,d;
        cin>>c>>d;
        check[i]=make_pair(c,d);
    }
    for(int i=0; i<n; ++i){
        int max1=INF,k=0;
        for(int j=0; j<m; ++j){
            if(max1>abs(student[i].first-check[j].first)+ abs(student[i].second - check[j].second)){
                max1=abs(student[i].first-check[j].first)+ abs(student[i].second - check[j].second);
                k=j;
            }
        }
        cout<<k+1<<"\n";
    }
}

Measured memory_bytes: 256
void main()
{
    long n = rdElem;

    long f(long x)
    {
        return x * (x + 1) / 2;
    }

    long l, r = n;
    while (r - l > 1)
    {
        long m = (l + r) / 2;
        long p = f(m);
        if (p < n) l = m;
        else r = m;
    }

    long total = f(r);
    long diff = total - n;
    foreach (i; 1 .. r+1)
    {
        if (i != diff) i.writeln;
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
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()
A = LIST()

if N <= K:
	print(1)
else:
	print(ceil((N-K)/(K-1)) + 1)

Measured memory_bytes: 14576
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;
    
    namespace ConsoleApp2
    {
    class Program
    {

        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();



            Console.WriteLine((3 * NK[0] + NK[1]) / 2);



        }
    }
}


Measured memory_bytes: 13268
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main(){
    string s;
    cin >> s;
    cout<<s[0];
    cout<<s[1];
    cout<<s[2]<<endl;
    return 0;
}

Measured memory_bytes: 3604
n = int(input())
h_lst = sorted([int(input()) for _ in range(n)])


def solve():
    ans = 1
    cnt = 0
    while h_lst:
        for _ in range(4):
            if h_lst:
                add = h_lst.pop() - cnt
                if add <= 0:return ans
                ans += add
            else:
                return ans
        cnt += 1
    return ans


print(solve())




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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);

ll ans = 0, n, m;
vector<vector<ll>> q(8);
void dfs(set<ll> s, ll now) {
    s.insert(now);
    // cout << now+1 << endl;
    // cout << s.size() << endl;
    if(s.size() == n) {
        ans++;
    }
    else {
        rep(i, q[now].size()) {
            if(!s.count(q[now][i])) {
                dfs(s, q[now][i]);
            }
        }
    }
}

int main() {
    cin >> n >> m;
    rep(i, m) {
        ll a, b; cin >> a >> b;
        a--; b--;
        q[a].push_back(b);
        q[b].push_back(a);
    }
    set<ll> s;
    dfs(s, 0);

    cout << ans << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans=0;
  string s;
  cin >> s;
  for (int i=0;i<s.size()/2;i++) {
    if(s.at(i)!=s.at(s.size()-i-1)) ans++;
  };
  cout << ans << endl;
}

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 REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
int main(void)
{
    int n,k;
    cin>>n>>k;
    int count;
    count =0;
    for(int i=0;n>0;i++){
       
        n/=k;
        
        count++;
    }

    cout<<count<<endl;

    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int a,b,c; cin >> a >> b >> c;
    string ans = "No";
    if (a==b && a!=c) ans = "Yes";
    if (b==c && b!=a) ans = "Yes";
    if (c==a && c!=b) ans = "Yes";
    cout << ans << endl;

    return 0;
}

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

typedef long long int int64;
static const int64 mod = 1000000007LL;

struct vertex {
	int estart;
	int parent,depth;
	int64 pw;
} v[1003];
struct edge {
	int enext,to;
	int64 w;
} e[4003];int en;
void addedge(int a,int b,int64 w)
{
	e[en].enext = v[a].estart;e[en].to = b;e[en].w = w;v[a].estart = en++;
	e[en].enext = v[b].estart;e[en].to = a;e[en].w = w;v[b].estart = en++;
}
void dfs(int i)
{
	for(int j = v[i].estart;j != -1;j = e[j].enext) {
		int to = e[j].to;
		if(to != v[i].parent) {
			v[to].parent = i;
			v[to].depth = v[i].depth + 1;
			v[to].pw = e[j].w;
			dfs(to);
		}
	}
}
int64 maxww(int a,int b)
{
	int64 ans = 0LL;
	if(v[a].depth < v[b].depth) std::swap(a,b);
	while(v[a].depth > v[b].depth) {
		if(v[a].pw > ans) ans = v[a].pw;
		a = v[a].parent;
	}
	while(a != b) {
		if(v[a].pw > ans) ans = v[a].pw;
		a = v[a].parent;
		if(v[b].pw > ans) ans = v[b].pw;
		b = v[b].parent;
	}
	return ans;	
}
int64 pow2(int n)
{
	int64 val = 1;
	for(int i = 0;i < n;++i) {
		val = val * 2;
		if(val > mod) val -= mod;
	}
	return val;
}
struct cedge {
	int a,b;
	int64 w;
} ee[2003];
int n,m;
int64 x;
int rep[1003],rank[1003];
int getrep(int i)
{
	if(rep[i] == i) return rep[i];
	return rep[i] = getrep(rep[i]);
}
bool merge(int a,int b)
{
	a = getrep(a), b = getrep(b);
	if(a == b) return false;
	if(rank[a] > rank[b]) std::swap(a,b);
	rep[a] = b;
	if(rank[a] == rank[b]) ++rank[b];
	return true;
}
bool cmp1(const cedge &a,const cedge &b) {
	return a.w < b.w;
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%lld",&x);
	for(int i = 0;i < n;++i) {
		rep[i] = i;
		v[i].estart = -1;
		v[i].parent = -1;
	}
	for(int i = 0;i < m;++i) {
		scanf("%d%d%lld",&ee[i].a,&ee[i].b,&ee[i].w);
		--ee[i].a;--ee[i].b;
	}
	std::sort(ee,ee+m,cmp1);
	int64 maxw = 0;
	for(int i = 0;i < m;++i) {
		if(merge(ee[i].a,ee[i].b)) {
			x -= ee[i].w;
			maxw = ee[i].w;
			addedge(ee[i].a,ee[i].b,ee[i].w);
		}
	}
	for(int i = 0;i < n;++i) if(getrep(i) != getrep(0)) {
		printf("0\n");
		return 0;
	}
	if(x < 0) {
		printf("0\n");
		return 0;
	}
	v[0].depth = 0;
	dfs(0);
	int cnt1 = 0;
	int cnt3 = 0;
	int cnt4 = 0;
	for(int i = 0;i < m;++i) {
		int64 w2 = ee[i].w - maxww(ee[i].a,ee[i].b);
		if(w2 == 0) ++cnt1;
		else if(w2 == x) ++cnt3;
		else if(w2 > x) ++cnt4;
	}
	// if x==0 then cnt2=cnt3=0
	if(x == 0) {
		printf("%lld\n", (pow2(cnt1)-2)*pow2(m-cnt1)%mod);
	} else {
		printf("%lld\n", 2LL*(pow2(cnt3)-1)*pow2(cnt4)%mod);
	}
}


Measured memory_bytes: 384
import copy
n = int(input())
a = list(map(int, input().split()))

color = [0]*9
for i in range(n):
    rate = min(a[i]//400, 8)
    color[rate] += 1

ans_min = 0
color_min = copy.deepcopy(color)
for c in color_min[:-1]:
    if c > 0:
        ans_min += 1
ans_min = max(1, ans_min)

ans_max = 0
color_max = copy.deepcopy(color)
for c in color_max[:-1]:
    if c > 0:
        ans_max += 1
ans_max += color_max[-1]

print(ans_min, ans_max)

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

class alds
{
    static void Main()
    {
        List<int> heap= new List<int>();
        heap.Add(0);
        int size = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        foreach (string data in input)
        {
            heap.Add(int.Parse(data));
        }
        for (int i = 1; i <= size; i++)
        {
            Console.Write("node ");
            Console.Write(i);
            Console.Write(": key = ");
            Console.Write(heap[i]);
            int par = (int)Math.Floor((double)i/2);
            if (par > 0)
            {
                Console.Write(", parent key = ");
                Console.Write(heap[par]);
            }
            int lef = i * 2;
            if (lef <= size)
            {
                Console.Write(", left key = ");
                Console.Write(heap[lef]);
            }
            int rit = i * 2 + 1;
            if (rit <= size)
            {
                Console.Write(", right key = ");
                Console.Write(heap[rit]);
            }
            Console.WriteLine(", ");
        }
    }
}

Measured memory_bytes: 15844
#include <bits/stdc++.h>
using namespace std;
int h,w;
int sx,sy,gx,gy;
int cost[20][20][202];
int dx[4] ={0,0,1,-1};
int dy[4] ={1,-1,0,0};
const int INF = 1<< 28;
struct state{
  int x,y,c,t;
  state(){}
  state(int ax,int ay,int ac,int at):x(ax),y(ay),c(ac),t(at){}
  bool operator>(const state& right)const{
    return c > right.c;
  }
};

int main(){
  cin >> h >> w;
  for(int i = 0;i < 20;i++)for(int j = 0;j < 20;j++)for(int k = 0;k < 202;k++)cost[i][j][k] = INF;
  vector<vector<char> > field(h,vector<char>(w));
  
  for(int i = 0;i < h;i++){
    for(int j =0 ;j < w;j++){
      cin >> field[i][j];
      if(field[i][j] == 'S') {
	sx = j;sy = i;
      }else if(field[i][j] == 'G'){
	gx = j;gy = i;
      }	
    }
  }
  
  int n;
  cin >> n;
  vector<vector<vector<char> > > field_n(n+1,vector<vector<char> >(h,vector<char>(w,0)));
  vector<int> time(n);
  for(int j = 0;j < h;j++){
    for(int k = 0;k < w;k++){
      field_n[0][j][k] = field[j][k];
    }
  }
  for(int i = 0;i < n;i++){
    cin >> time[i];
    for(int j = 0;j < h;j++){
      for(int k = 0;k < w;k++){
	cin >> field_n[i+1][j][k];
      }
    }
  }
  priority_queue<state,vector<state>,greater<state> > que;
  que.push(state(sx,sy,0,0));
  while(!que.empty()){
    state cur = que.top();
    que.pop();
    int cx = cur.x;
    int cy = cur.y;
    int cc = cur.c;
    int ct = cur.t;
    int t_index = -1;
    for(int i = 0;i < time.size();i++){
      if(time[i] > ct+1){
	t_index = i;
	break;
      }
    }
    if(t_index == -1)t_index = n;
    if(ct+1>=200)ct=200;
    if(cost[cy][cx][ct+1] > cc && field_n[t_index][cy][cx] != '#'){
      cost[cy][cx][ct+1] = cc;
      que.push(state(cx,cy,cc,ct+1));
    }
    
    for(int i = 0;i < 4;i++){      
      int nx,ny;
      nx = cx+dx[i];ny = cy+dy[i];
      if(nx < 0 || nx >= w || ny < 0 || ny >= h || field_n[t_index][ny][nx] == '#'){

	continue;
      }
      if(cost[ny][nx][ct+1] > cc+1){
	cost[ny][nx][ct+1] = cc+1;
	que.push(state(nx,ny,cc+1,ct+1));
      }	  	  
    }    
  }
  
  int ans = INF;
  for(int i=0;i < 202;i++){
    ans = min(ans,cost[gy][gx][i]);
  }
  cout << (ans!=INF ? ans:-1) << endl;
  
  

  
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

vector<int> bfs(vector<vector<int>> &G, int s){
    vector<int> d(G.size(), MOD);
    d[s] = 0;
    queue<int> Q;
    Q.emplace(s);
    while(!Q.empty()){
        int i = Q.front(); Q.pop();
        for (auto &&j : G[i]) {
            if(d[i] + 1 < d[j]){
                d[j] = d[i] + 1;
                Q.emplace(j);
            }
        }
    }
    return d;
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<int>> G(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        x--; y--;
        G[x].emplace_back(y);
        G[y].emplace_back(x);
    }
    auto d1 = bfs(G, s), d2 = bfs(G, t);
    vector<int> cnt(n);
    for (auto &&j : d2) {
        if(j < n)cnt[j]++;
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int to = d1[t]-d1[i]-2;
        if(to >= 0 && to < n){
            ans += cnt[to];
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 10588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), new Converter<string, int>(x => int.Parse(x)));
            Array.Sort(A);
            Array.Reverse(A);
            long rect_upper = 0;
            long rect = 0;
            for (int i = 1; i < A.Length; i++)
            {
                if (rect_upper == 0)
                {
                    if (A[i - 1] == A[i])
                    {
                        rect_upper = A[i];
                        i++;
                    }
                }
                else
                {
                    if (A[i - 1] == A[i])
                    {
                        rect= A[i] * rect_upper;
                        break;
                    }
                }

            }

            Console.WriteLine(rect);
            Console.ReadLine();
        
        }
    }
}


Measured memory_bytes: 18528
#include <iostream>
#include <cstdio>
#include <cfloat>
#include <cmath>
#include <random>
#include <algorithm>
#define norm(X) ((X) * (X))
using namespace std;
using ll = long long;
    
struct Point {
    ll x, y;
    ll z;
};

int main() {
    ll n;
    Point e[105];
    double ans = 0;
    ll sx[4] = {};
    ll sy[4] = {};

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> e[i].x >> e[i].y;

        e[i].z = 0;
        if (e[i].y > 0) {
            e[i].z |= 2;
        }
        if (e[i].x > 0) {
            e[i].z |= 1;
        }

        sx[e[i].z] += e[i].x;
        sy[e[i].z] += e[i].y;
    }

    mt19937 rnd((random_device())());
    ll x, y;

    for (int z = 0; z < 4; z++) {
        
        for (int k = 0; k < 30000; k++) {
            x = sx[z];
            y = sy[z];

            for (int i = 0; i < n; i++) {
                ll zz = 0;
                if (e[i].y > 0) zz |= 2;
                if (e[i].x > 0) zz |= 1;
                e[i].z = (zz == z ? -1 : 1);
            }

            for (int j = 0; j < 300; j++) {
                ll indx = rnd() % n;

                if (e[indx].z != -1) {
                    if (norm(x) + norm(y) < norm(x + e[indx].x) + norm(y + e[indx].y)) {
                        x += e[indx].x;
                        y += e[indx].y;
                        e[indx].z = -1;
                    }
                }
                else {
                    if (norm(x) + norm(y) < norm(x - e[indx].x) + norm(y - e[indx].y)) {
                        x -= e[indx].x;
                        y -= e[indx].y;
                        e[indx].z = 1;
                    }
                }
            }

            ans = max(ans, hypot(x, y));
        }
    }
    
    printf("%.*lf\n", DBL_DIG, ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
using namespace std;
const int N = 20010;
int a[N], b[N], p[N], rk[N];
int main() {
	int n; scanf("%d",&n); rep(i,1,n) scanf("%d",&p[i]);
	rep(i,1,n) rk[p[i]] = i;
	rep(i,2,n) if (rk[i] > rk[i - 1]) a[i] = rk[i] - rk[i - 1]; else b[i - 1] = rk[i - 1] - rk[i];
	rep(i,2,n) if (!a[i]) a[i] = 1, b[i - 1]++;
	rep(i,1,n - 1) if (!b[i]) b[i] = 1, a[i + 1]++;
	a[1] = 1; rep(i,2,n) a[i] += a[i - 1];
	b[n] = 1; dep(i,n - 1,1) b[i] += b[i + 1];
	rep(i,1,n) printf("%d ",a[i]); printf("\n");
	rep(i,1,n) printf("%d ",b[i]); printf("\n");
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ff first
#define ss second
#define pi 3.14159
int main()
{
    int arr[10];

    int i;

    for(i=0; i<10; i++)
        cin>>arr[i];

     sort(arr, arr+10, greater<int>());

    for(i=0; i<3; i++) cout<<arr[i]<<endl;
}

Measured memory_bytes: 1176
#include <iostream>
using namespace std;
int main()
{
    string S,T,U;
    int A,B;
    cin>> S >> T;
    cin>> A >>B ;
    cin>>U;
    if (U==S)
        A=A-1;
    else if (U==T)
        B=B-1;
    cout<<A <<" "<<B;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int be,af;
  bool ari[4]={true,true,true,true};
  string s,a,b;
  cin >> s;
  b = s.substr(2);
  a = s.substr(0,2);
  be = stoi(a);
  af = stoi(b);
  if(be==0||be>12) ari[0]=false;
  if(af==0||af>12) ari[1]=false;
  if(ari[0]==true&&ari[1]==false) cout << "MMYY\n";
  else if(ari[0]==false&&ari[1]==true) cout << "YYMM\n";
  else if(ari[0]&&ari[1]) cout << "AMBIGUOUS\n";
  else cout <<"NA\n";
}


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

using namespace std;

const int MAX_N = 1e5 + 5;
vector <int> graph[MAX_N];
vector <int> component(MAX_N, 0);

void dfs(int v, int parent_v, int component_no)
{
    component[v] = component_no;

    for(int i = 0; i < graph[v].size(); i++)
    {
        int child_v = graph[v][i];

        if(parent_v == child_v || component[child_v] != 0) continue;

        dfs(child_v, v, component_no);
    }
}

int main()
{
    int no_of_vertices, no_of_edges;
    cin >> no_of_vertices >> no_of_edges;

    for(int i = 1; i <= no_of_edges; i++)
    {
        int u, v, z;
        cin >> u >> v >> z;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    int no_of_components = 0;
    for(int i = 1; i <= no_of_vertices; i++)
    {
        if(component[i] == 0)
        {
            no_of_components++;

            dfs(i, 0, no_of_components);
        }
    }

    cout << no_of_components;
    return 0;
}


Measured memory_bytes: 12416
from sys import stdin
import math

N = int(stdin.readline().rstrip())
P = [int(x) for x in stdin.readline().rstrip().split()]
Q = [int(x) for x in stdin.readline().rstrip().split()]
rp = [int(x + 1) for x in range(N)]
rq = [int(x + 1) for x in range(N)]

index_p = 0
index_q = 0

for i in range(N):
    index_p += math.factorial(N - i - 1) * (rp.index(P[i]) - 1)
    index_q += math.factorial(N - i - 1) * (rq.index(Q[i]) - 1)
    rp.remove(P[i])
    rq.remove(Q[i])

print(abs(index_p - index_q))


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int x, y;
	cin >> x >> y;
	int a[7] = {1, 3, 5, 7, 8, 10, 12}, b[4] = {4, 6, 9, 11}, c = 0, d = 1;
	for (int i = 0 ; i < 7 ; i++) {
		if (a[i] == x) c++;
		if (a[i] == y) c++;
	}
	if (c == 2) cout << "Yes\n", d = 0;
	c = 0;
	for (int i = 0 ; i < 4 ; i++) {
		if (b[i] == x) c++;
		if (b[i] == y) c++;
	}
	if (c == 2 && d) cout << "Yes\n", d = 0;
	if (x == 2 && y == 2 && d) cout << "Yes\n", d = 0;
	if (d) cout << "No\n";  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;

int main() {
  long long N,M;
  cin>>N>>M;
  ll a[M];
  cin>>a[0];
  for(int i=1;i<M;i++){
    cin>>a[i];
    a[i]+=a[i-1];
    
  }
  if(N-a[M-1]>=0){
    cout<<N-a[M-1];
  }
  else{
    cout<<-1;
  }
  
}

Measured memory_bytes: 3696
import java.math.BigInteger;
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		BigInteger a = new BigInteger(sc.next());
		BigInteger b = new BigInteger(sc.next());
		
		System.out.println(a.remainder(b));
	}

}



Measured memory_bytes: 26564
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  ll A, B;
  string S;
  cin >> A >> B;
  cin >> S;

  ll count = 0;
  rep(i, A + B + 1) {
    if (S[i] == '-') count++;
  }

  if (count == 1 && S[A] == '-') {
    COUT("Yes");
  } else {
    COUT("No");
  }
  return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;
	class Main{

		public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
int su;
su=sc.nextInt();
long kei=1;
for(int i=1;i<=su;i++){
	kei=kei*i;
}
	
System.out.println(kei);	
	}
	}
	    

Measured memory_bytes: 25864
#include <stdio.h>

int main(){
  int a, b, x; // a >= b
  /* There are "x" in this program
     in order to store the value of "a". */
  
  scanf("%d %d",&a,&b);
  if( a <= b ){
    x = a;
    a = b;
    b = x;
  }
  while( a%b ){
    x = a;
    a = b;
    b = x%b;
  }
  printf("%d\n",b);
  
  return 0;
}



Measured memory_bytes: 2080
#include<stdio.h>
#include<stdlib.h>

#define min(a,b) ((a)<(b)?(a):(b))

struct st{
	int num;
	int c;
	int cd;
};

int main(){
	int n,c,i,j,k,l;
	int d[31][31];
	int cc[500][500];
	scanf("%d%d",&n,&c);
	int se[3][100]={0},tt[3]={0};
	for(i=0;i<c;i++){
		for(j=0;j<c;j++){
			scanf("%d",&d[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			scanf("%d",&cc[i][j]);
			se[(i+j)%3][cc[i][j]-1]++;
		}
	}
	long long ans=2000000000000000;
	for(i=0;i<c;i++){
		for(j=0;j<c;j++){
			for(k=0;k<c;k++){
				long long tmp=0;
				if(i==j||j==k||k==i)continue;
				for(l=0;l<c;l++)tmp+=d[l][i]*se[0][l];
				for(l=0;l<c;l++)tmp+=d[l][j]*se[1][l];
				for(l=0;l<c;l++)tmp+=d[l][k]*se[2][l];
				ans=min(ans,tmp);
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1152
def bubble_sort(a, n):
    flag = 1
    switch = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):
            if a[j] < a[j-1]:
                temp = a[j]
                a[j] = a[j-1]
                a[j-1] = temp
                flag = 1
                switch += 1
    print(' '.join([str(i) for i in a]))
    print(switch)


def main():
    n = int(input())
    nums = input()
    nums = list(map(int, nums.split(' ')))
    bubble_sort(nums, n)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	reverse(b.begin(),b.end());
	if(b>a) cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int N=5000;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s,t,ans="";
	unsigned int i,j,n,m,a,b,dp[N][N];
	cin>>s>>t;
	n=s.length(); m=t.length();
	for(i=0;i<n;++i) dp[i][0]=0;
	for(i=0;i<m;++i) dp[0][i]=0;
	for(i=1;i<=n;++i){
		a=i-1;
		for(j=1;j<=m;++j){
			b=j-1;
			if(s[a]==t[b]) dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[a][b+1],dp[a+1][b]);
		}
	}
	i=n; j=m;
	while(i>0&&j>0){
		a=dp[i][j]; if(a==0) break;
		while(a==dp[i][j-1]) --j;
		while(a==dp[i-1][j]) --i;
		ans+=s[i-1];
		--i;--j;
	}reverse(ans.begin(),ans.end());
	cout<<ans;
}

Measured memory_bytes: 60288
//************************************JAI SAI RAM*************************************** 
// ED ROUND 85 DIV 2 PROBLEM D HARD TO THINK OF and hard TO IMPLEMENT .
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n";
#define pair pair<ll,ll> 
ll MAX=LLONG_MAX;
ll MIN=LLONG_MIN;
ll P=1000000007;
ll power(ll x, ll y, ll p)  
{  
    ll res = 1;     // Initialize result  
    if(y==0)
    return 1;
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,l,m,n,o,p,q,r,s,t,x,a[500001]={0},b[5001],c[5001],tt=0;
    cin>>n>>k;
    o=0;
    ll tot=power(k,n,P);
    t=0;
    for(i=k;i>=1;i--)
    {
        s=power(k/i,n,P);
        a[i]=s;
        for(j=2*i;j<=k;j+=i)
        a[i]=(a[i]-a[j]+P)%P;
        o=(o+(a[i]*i)%P)%P;
    }
    cout<<o<<endl;
    return 0;
}  
    


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int N; cin >> N;
    int K; cin >> K;
    int h[N];
    int ans=0;
    for(int i=0;i<N;i++){
        cin >> h[i];
        if(h[i]>=K) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640