akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        int N;

        public void Solve()
        {
            var set = new SortedSet<string>();
            N = int.Parse(Console.ReadLine());
            this.Calc('a', "");
        }

        private void Calc(char c, string text)
        {
            if (text.Length == N)
            {
                Console.WriteLine(text);
            }
            else
            {
                for (char i = 'a'; i <= c; i++)
                {
                    Calc(i == c ? (char)(c + 1) : c, text + i);
                }
            }
        }
    }
}


Measured memory_bytes: 15572
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a[s.size()+1],b[s.size()+1],suma=0,sumb=0;
	a[0]=0;
	b[0]=1;
	for(int i=0;i<s.size();i++){
		if(b[i]==1){
			b[i+1]=0;
		}
		else if(b[i]==0){
			b[i+1]=1;
		}
	}
	for(int i=0;i<s.size();i++){
		if(a[i]==1){
			a[i+1]=0;
		}
		else if(a[i]==0){
			a[i+1]=1;
		}
	}
	for(int i=0;i<s.size();i++){
		if(s[i]=='1' and a[i]==0){
			suma++;
		}
		if(s[i]=='0' and a[i]==1){
			suma++;
		}
		if(s[i]=='1' and b[i]==0){
			sumb++;
		}
		if(s[i]=='0' and b[i]==1){
			sumb++;
		}
	}
	cout<<min(suma,sumb);
}
//FELAROSSO 2019

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int n, q, b, m, e;
	std::vector<long> a;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	a.resize(n, 0);
	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> a[i];
#else
		std::cin >> a[i];
#endif
	}


#if INPUT_FROM_FILE
	ifs >> q;
#else
	std::cin >> q;
#endif

	for(int i = 0; i < q; i++){
#if INPUT_FROM_FILE
		ifs >> b >> m >> e;
#else
		std::cin >> b >> m >> e;
#endif

		std::rotate(a.begin() + b, a.begin() + m, a.begin() + e);
	}

	std::cout << a[0];
	for(int i = 1; i < a.size(); i++){
		std::cout << " " << a[i];
	}
	std::cout << std::endl;
	return 0;
}



Measured memory_bytes: 3148
#include <stdio.h>

int main(void){
  int A, B, C, D;
  scanf("%d %d %d %d", &A, &B, &C, &D);
  if(A + B > C + D){
    printf("Left\n");
  }else if(A + B == C + D){
    printf("Balanced\n");
  }else{
    printf("Right\n");
  }
  return 0;
}


Measured memory_bytes: 128
main :: IO ()
main = do
  po <- getLine
  print $ dist s po

s :: String
s = "CODEFESTIVAL2016"

dist :: String -> String -> Int
dist [] s2 = length s2
dist s1 [] = length s1
dist (a:s1) (b:s2) = (if a == b then 0 else 1) + dist s1 s2


Measured memory_bytes: 380
# -*- coding: utf-8 -*-
import math

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

ans = 0
for i in range(1, n+1):
    point = i
    e = 0
    while(point < k):
        point *= 2
        e += 1
    ans += 1/n * (1/2)**e

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

int main () {
    
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int dx = x2-x1;
    int dy = y2-y1;

    cout << x2 - dy << " ";
    cout << y2 + dx << " ";
    cout << x1 - dy << " ";
    cout << y1 + dx << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;

int main(){
	ll n; cin >> n;
	ll flag = static_cast<int>(sqrt(n)) + 1;
	for(;;--flag){
		bool jud = 0;
		if(!(n % flag)){
			jud = 1;
			for(int i = 0;; ++i){
				if(pow(10, i) == n / flag){
					cout << i + 1 << endl;
					break;
				}else if(pow(10, i) > n / flag){
					cout << i << endl;
					break;
				}
			}
		}
		if(jud) break;
	}
	return 0;
}

Measured memory_bytes: 256
N, C = map(int, input().split())
table = [[0]*(10**5 + 1) for i in range(C)]

st = [[] for i in range(C)]
for i in range(N):
  s, t, c = map(int, input().split())
  st[c-1].append([s, t])

st_new = [[] for i in range(C)]
for c in range(C):
  if st[c]:
    st[c].sort()
    st_new[c].append(st[c][0])
    n = len(st[c])
    for i in range(1, n):
      si, ti = st[c][i]
      sii, tii = st_new[c][-1]
      if si == tii:
        st_new[c][-1][1] = ti
      else:
        st_new[c].append([si, ti])

for c in range(C):
  for s, t in st_new[c]:
    table[c][s-1] += 1
    table[c][t] -= 1
  
for c in range(C):
  for i in range(1, 10**5+1):
    table[c][i] += table[c][i-1]

ans = 0
for i in range(10**5 + 1):
  num = 0
  for c in range(C):
    num += table[c][i]
  ans = max(ans, num)

print(ans)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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

int n;
ll t,sum,p;

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

	cin>>n>>t;
	REP(i,n) {
		ll q; cin>>q;
		sum+=min(t,q-p);
		p=q;
	}
	cout<<sum+t<<endl;

	return 0;
}


Measured memory_bytes: 256
function main()
  
  N = parse(Int,readline())
  
  SP = Tuple[]
  
  for i in 1:N
    (a,b) = split(chomp(readline())," ")
    push!(SP,(a,b))
  end
  
  SP_0 = Tuple[]
  for i in 1:N
    push!(SP_0,SP[i])
  end

  sort!(SP, rev = true, by = x -> parse(Int,x[2]))
  sort!(SP, by = x -> x[1])

  for i in 1:N, j in 1:N

    if SP[i] == SP_0[j]
      println(j)
    end
  end
  
end

main()

Measured memory_bytes: 115324
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,nn,a[200001];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(res i=1;i<=n;++i) cin>>a[i];
	sort(a+1,a+1+n),nn=unique(a+1,a+1+n)-a-1;
	if(n!=nn) cout<<"NO"<<'\n';else cout<<"YES"<<'\n';
	cout<<flush;
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 1024
///////////////////// author : TrEbLeCleF /////////////////////
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
/////////////////////////// ..... ///////////////////////////
#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }
/////////////////////////// ..... ///////////////////////////
#define int ll
#define pb(x) push_back(x)
#define print(v,s,e) for(int i = s; i < e; i++)cout << v[i]<<" ";cout<<"\n";
#define INF 1e17
#define PI 3.14159265358979323846 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
/////////////////////////// GLOBAL ///////////////////////////
const int mxn = 2e5+1;
int n,m,k;
int a[mxn],b[mxn];

/////////////////////////// GLOBAL ///////////////////////////
void solve(){
	cin >> n >> m >> k;
	for(int i=0; i<n; ++i) {
		cin >> a[i+1];
		a[i+1]+=a[i];
	}
	for(int i=0; i<m; ++i) {
		cin >> b[i+1];
		b[i+1]+=b[i];
	}
	int ans=0;
	for(int i=0, j=m; i<=n; ++i) {
		if(a[i]>k)
			break;
		while(a[i]+b[j]>k)
			--j;
		ans=max(i+j, ans);
	}
	cout << ans;
	
}

int32_t main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		freopen("TC", "r", stdin);
		//freopen("output.txt","w",stdout);
	#endif 
    ios_base:: sync_with_stdio(false); 
   	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
	#ifndef ONLINE_JUDGE
    	cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
    #endif
}

Measured memory_bytes: 6708
n = int(input())
a = list(map(int, input().split()))

aa = [0 for i in range(2*10**5)]
for i in range(n):
  aa[a[i]] += 1
 
ans = 0
for key in range(2*10**5):
  ans += aa[key]*(aa[key]-1)//2
    
for i in range(n):
  tmp1 = aa[a[i]]*(aa[a[i]]-1)//2
  aa[a[i]] -= 1
  tmp2 = aa[a[i]]*(aa[a[i]]-1)//2
  aa[a[i]] += 1
  print(ans-tmp1 + tmp2)
  



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

int main() {
  int N; cin >> N;
  int D[N][2]; for (int i = 0; i < N; i++) cin >> D[i][0] >> D[i][1];
  bool exists = false;
  for (int i = 0; i < N-2; i++) {
    if (D[i][0]==D[i][1] && D[i+1][0]==D[i+1][1] && D[i+2][0] == D[i+2][1]) {
      exists = true;
    }
  }
  cout << (exists ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,i;
    cin>>a>>b>>c>>d>>e;
    if(a==0)cout<<1;
    if(b==0)cout<<2;
    if(c==0)cout<<3;
    if(d==0)cout<<4;
    if(e==0)cout<<5;
    return 0;
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, intmax_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, intmax_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N; cin >> N;

    intmax_t maxv = 0;
    unordered_map<intmax_t, intmax_t> cnt;
    set<intmax_t> st;
    vector<intmax_t> a(N);
    for (auto &ai: a) {
        cin >> ai;
        st.insert(ai);
        cnt[ai]++;
        if (cnt[ai] >= 4) {
            chmax(maxv, ai * ai);
        }
    }

    vector<intmax_t> vec;
    for (auto &si: st) {
        if (cnt[si] >= 2) {
            vec.emplace_back(si);
        }
    }
    if (vec.empty()) {
        return cout << 0 << "\n", 0;
    }

    sort(vec.rbegin(), vec.rend());

    for (intmax_t i = 0; i < vec.size() - 1; ++i) {
        chmax(maxv, vec[i] * vec[i + 1]);
    }

    cout << maxv << "\n";

    return 0;
}


Measured memory_bytes: 9892
#include<bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=550;
const int inf=0x3f3f3f3f;
int _m,_n;//第一个是m多边形,第二个是n多边形
int X1[105],Y1[105],X2[105],Z2[105];//下标从0开始
double width(int X[],int Y[],int n,double x)//对于n个点的多边形(x,y)
{
    double down=1e8,up=-1e8;
    for(int i=0;i<n;++i)
    {
        int x1=X[i],y1=Y[i],x2=X[(i+1)%n],y2=Y[(i+1)%n];
        if(x1>x2){
            swap(x1,x2);swap(y1,y2);
        }
        if(x>=x1&&x<=x2){
            double y=y1+(x-x1)*(y2*1.0-y1)/(x2-x1);
            down=min(down,y);
            up=max(up,y);
        }
    }
    return max(0.0,up-down);
}
double f(double x)
{
    return width(X1,Y1,_m,x)*width(X2,Z2,_n,x);
}
double Simpson(double a,double b)//要求a<b
{
    double c=(a+b)/2.0;
    return (b-a)/6.0*(f(a)+4*f(c)+f(b));
}
vector<int> sx;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    while(cin>>_m>>_n)
    {
        if(_m==0&&_n==0) return 0;
        sx.clear();
        for(int i=0;i<_m;++i){
            cin>>X1[i]>>Y1[i];
            sx.push_back(X1[i]);
        }
        for(int i=0;i<_n;++i){
            cin>>X2[i]>>Z2[i];
            sx.push_back(X2[i]);
        }
        sort(sx.begin(),sx.end());
        int min1=*min_element(X1,X1+_m),max1=*max_element(X1,X1+_m);
        int min2=*min_element(X2,X2+_n),max2=*max_element(X2,X2+_n);
        double res=0;
        for(int i=0;i+1<sx.size();++i)
        {
            int a=sx[i],b=sx[i+1];
            if(a>=min1&&a<=max1&&a>=min2&&a<=max2&&b>=min1&&b<=max1&&b>=min2&&b<=max2)
            {
                res+=Simpson(a*1.0,b*1.0);
            }
        }
        cout<<fixed<<setprecision(10)<<res<<endl;
    }
}


Measured memory_bytes: 3276
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

int main(){
	
	int N, K;
	cin >> N >> K;
	ll ans = K;
	for(int i=1;i<N;i++) ans *= (K - 1);
	cout << ans << endl;
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main (void)
{
  int a, b, h, m;
  double hour, minute;
  double hx, hy, mx, my, dx, dy;

  scanf("%d %d %d %d", &a, &b, &h, &m);


  hour = ((double)h + (double)m / 60.0) * M_PI / 6.0;
  minute = (double)m * M_PI / 30.0;

  hx = (double)a * cos(hour);
  hy = (double)a * sin(hour);
  mx = (double)b * cos(minute);
  my = (double)b * sin(minute);
  dx = hx - mx;
  dy = hy - my;

  printf("%4.20f\n", sqrt(dx*dx+dy*dy));

  return 0;
}

Measured memory_bytes: 2536
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}


Measured memory_bytes: 3604
n, k = map(int, input().split())
d = list(map(int, input().split()))

ans = 0
for i in range(1, min(k + 1, len(d)+1)):
    s = 0
    for left in range(i+1):
        j = []
        if left > 0:
            j.extend(d[:left])
        if i-left > 0:
            j.extend(d[min(-(i - left), -1):])
        j = sorted(j)
        s = sum(j)
        for m in range(k - i):
            if len(j) <= m:
                break
            elif j[m] >= 0:
                break
            else:
                s -= j[m]
        ans = max(s, ans)
print(ans)


Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
 
int main(){
	ll n,q,k;
	cin >> n;
	vector<ll> a(n);
	FOR(i,0,n){
		cin >> a[i];
	}
	cin >> q;
	FOR(i,0,q){
		cin >> k;
		cout << POSL(a,k) << endl;
	}
}


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

int main(int argc, char const *argv[])
{
	int w, h, x, y, r;
	string s;

	cin >> w >> h >> x >> y >> r;

	if (0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h)
		s = "Yes";
	else
		s = "No";

	cout << s << endl;

	return 0;
}



Measured memory_bytes: 3200
n,m=map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
    a[i]+=[sum(a[i])]
    print(*a[i])
a=list(zip(*a[::-1]))
for i in range(m):print(sum(a[i]),end=' ')
print(sum(a[m]))


Measured memory_bytes: 5768
#include<cstdio>
#include<queue>
#define P std::pair<int,int>
#define F first
#define S second
std::deque<P> q;
int n;
bool used[100010];
signed main()
{
	scanf("%d",&n),q.push_back(P(1,1));
	while(!q.empty())
	{
		P u(q.front());q.pop_front();
		if(!used[u.F])
		{
			used[u.F]=1;
			if(!u.F)
				return printf("%d\n",u.S),0;
			q.push_front(P(u.F*10%n,u.S)),q.push_back(P((u.F+1)%n,u.S+1));
		}
	}
}

Measured memory_bytes: 1152
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let R2 T U = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U)
let R3 T U V = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V)
let R4 T U V W = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W)
let R5 T U V W X = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W),(c.[4]|>X)
let outl s = stdout.WriteLine(s|>string)
let outsep ls = stdout.WriteLine(String.concat " " (ls|>List.map string))
let outsepl ls = stdout.WriteLine(String.concat "\n" (ls|>List.map string))
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let a,b,c = R3 int int int
    outsep [c;a;b]
    0


Measured memory_bytes: 11348
n = int(input())
R = [int(input()) for _ in range(n)]
max_dif = - 10 ** 9
min_r = R[0]
l = len(R)
for i in range(1, l):
    max_dif = max(max_dif, R[i] - min_r)
    min_r = min(min_r, R[i])

print(max_dif)


Measured memory_bytes: 13592
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {

	Scanner sc;
	
	int solve(ArrayList<Integer> cards){
		int ace=0;
		int point=0;
		for(int card:cards){
			point+=card>10?10:card;
			ace+=card==1?1:0;
		}
		for(;point<=11&&ace>0;--ace){
			point+=10;
		}
		return point<=21?point:0;
	}
	
	String ns(){
		return sc.nextLine();
	}
	
	void io(){
		sc=new Scanner(System.in);
		
		while(true){
			StringTokenizer tok=new StringTokenizer(ns());
			ArrayList<Integer> cards=new ArrayList<Integer>();
			while(tok.hasMoreTokens()){
				cards.add(Integer.parseInt(tok.nextToken()));
			}
			if(cards.size()==1&&cards.get(0)==0) break;
			System.out.println(solve(cards));
		}
		sc.close();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}

}

Measured memory_bytes: 17472
#include <iostream>
#include <vector>
#include <string>



#define DEBUG(x) do {std::cerr << #x << ": " << x << std::endl; } while (0)


int main(int argc, const char ** argv){

	std::string s, t;
	std::cin >> s >> t;
	std::cout << t << s << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int cnt = 0;
  int right = 0;
  while (1) {
    if (cnt == 0) {
      right += k;
      cnt++;
    } else {
      right += k - 1;
      cnt++;
    }

    if (right >= n) break;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
n=int(input())
A=[]

append=A.append
for i in range(n):
  append(int(input()))
m1,m2=sorted(A)[-2],sorted(A)[-1]
for i in range(n):
  print(m1 if A[i]==m2 else m2)

Measured memory_bytes: 14764
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
 
public class Main {
    static class Team {
        int team, solved, elapsed;
        int[] penalty;
        Team(int t) {
            team =t ; 
            penalty= new int[11];
        }
    }
     
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
            while(sc.hasNext()) {
                int M = sc.nextInt();
                int T = sc.nextInt();
                int P = sc.nextInt();
                int R = sc.nextInt();
                if(T == 0) break;
                Team[] ts = IntStream.range(0, T).mapToObj(t -> new Team(t+1)).toArray(Team[]::new);
                 
                IntStream.range(0, R).forEach(dummy -> {
                    int m = sc.nextInt();
                    int t = sc.nextInt()-1;
                    int p = sc.nextInt();
                    int j = sc.nextInt();
                    if(j == 0) {
                        ts[t].solved++;
                        ts[t].elapsed += m;
                        ts[t].elapsed += ts[t].penalty[p];
                    }
                    else {
                        ts[t].penalty[p] += 20;
                    }
                });//準備
                 
                Arrays.sort(ts, (t1, t2)->{
                    if(t1.solved != t2.solved) {
                        return t2.solved - t1.solved;
                    }
                    else if(t1.elapsed != t2.elapsed) {
                        return t1.elapsed - t2.elapsed;
                    }
                    return t2.team - t1.team;
                });//問題数降順→経過時間で昇順
 
                int score = ts[0].solved * M + ts[0].elapsed;
                 
                System.out.print(ts[0].team);
                for(int i = 1; i < T; i++) {
                    int s = ts[i].solved * M + ts[i].elapsed;//同順位のものを探す
                    System.out.print(s == score ? "=" : ",");
                    System.out.print(ts[i].team);
                    score = s;
                }
                 
                System.out.println();
            }
        }
    }
}


Measured memory_bytes: 72716
L = int(input())

n = 0
M = 0

while L >= 2 ** n:
    n += 1

n -= 1

N = n + 2
ans = []

for i in range(N-2):
    ans.append([i+1,i+2,0])
    M += 1

for i in range(N-2):
    i += 1
    ans.append([i,i+1, 2 ** (N-2-i)])
    M += 1




now = 2 ** n
for i in range(n):

    j = n-1-i
    k = i + 3
    
    if (2 ** j) & L > 0:
        ans.append([1,k-1,now])
        M += 1
        now += 2 ** j

print (N-1,M)
for i in ans:
    print (i[0],i[1],i[2])



Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,cnt=0;
  cin >> n;
  int64_t a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n-1;i++){
    if(a[i]>=a[i+1]){
      cnt+=a[i]-a[i+1];
      a[i+1]+=a[i]-a[i+1];
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 5040
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main()
{
    ll A,B,N;
    cin >> A >> B >> N;
    if(B<=N)
        cout << (A*(B-1))/B << endl;
    else{
        cout << (A*N)/B << endl;
    }

}


Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;

long calc(long q, long temh, long teml, long shh, long shl){
  vector<long> k;
  for(auto first: {teml, temh}){
    for(auto second: {shl, shh}){
      if(first == -10000000000000 || first == 10000000000000) continue;
      if(second == -10000000000000 || second == 10000000000000) continue;
      k.push_back(abs(q-first)+abs(second-first));    
    }
  }
  for(auto first: {shl, shh}){
  	for(auto second: {teml, temh}){
      if(first == -10000000000000 || first == 10000000000000) continue;
      if(second == -10000000000000 || second == 10000000000000) continue;
      k.push_back(abs(q-first) + abs(second-first));    
    }
  }
  return *min_element(k.begin(),k.end());
}

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  vector<long> tem, sh;
  long dum;
  tem.push_back(-10000000000000);
  for(int i=0;i<a;i++) {
  	scanf("%ld", &dum);
    tem.push_back(dum);
  }
  tem.push_back(10000000000000);
  
  sh.push_back(-10000000000000);
  for(int i=0;i<b;i++) {
  	scanf("%ld", &dum);
    sh.push_back(dum);
  }
  sh.push_back(10000000000000);

  long q;
  for(int i=0;i<c;i++) {
  	scanf("%ld", &q);
    auto temh = lower_bound(tem.begin(),tem.end(),q);
    auto shh = lower_bound(sh.begin(),sh.end(),q);
    cout << calc(q,*temh,*(temh--),*shh,*(shh--)) << endl;
  }
	
  return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	vi v({1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51});
	int k;cin>>k;
	cout << v[k-1] << endl;	
	
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	vl a(n);
	rep(i, n) cin >> a[i];
	map<ll, int> mp;
	rep(i, n) mp[-a[i]]++;
	ll ans = 1LL;
	for(auto& p : mp) {
		if(p.se == 1) continue;
		if(ans == 1) {
			if(p.se >= 4) {
				cout << p.fi * p.fi << endl;
				return 0;
			}
			else ans = p.fi;
		}
		else {
			cout << ans * p.fi << endl;
			return 0;
		}
	}
	cout << 0 << endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) { 
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    int n,m;
    cin >> n >> m;
    vector<ll>ans;
    vector<int>a(m),b(m);
    rep(i,m) {
      cin >> a[i] >> b[i];
      a[i]--;b[i]--;
    }
    reverse(a.rbegin(),a.rend());
    reverse(b.rbegin(),b.rend());
    ll tmp = (ll)n*(ll)(n-1)/2;
    ans.push_back(tmp);
    UnionFind uf(n);
    rep(i,m) {
      if(!uf.same(a[i],b[i])) {
          int sa = uf.size(a[i]);
          int sb = uf.size(b[i]);
          tmp -= (ll)sa*(ll)sb;
          ans.push_back(tmp);
          uf.unite(a[i],b[i]);
      } else {
          ans.push_back(tmp);
      }
    }
    reverse(ans.begin(),ans.end());
    for(int i = 1;i<=m;i++) {
        cout << ans[i] << endl;
    }
}

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

int main(void){
    int height[10];
    for(int i=0;i<10;i++)
        std::cin>>height[i];
    std::sort(height,height+10);
    std::cout<<height[9]<<std::endl<<height[8]<<std::endl<<height[7]<<std::endl;
    return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>

int main(void)
{
	int a[100];
	int i, j, k = 0, tmp;
	int n;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		printf("%d", a[i]);
		if (i == n - 1) {
			printf("\n");
		}
		else {
			printf(" ");
		}
	}

	for (i = 1; i < n; i++) {
		tmp = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > tmp) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = tmp;

		while (k < n) {
			printf("%d", a[k]);
			k++;
			if (k == n) {
				k = 0;
				printf("\n");
				break;
			}
			printf(" ");
		}

		printf("");
	}

	return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <stdio.h>

int main() {
	int a;
	int b;	
	scanf("%d%d", &a, &b);
	if (b%a==0) {
		int p = a + b;
		printf("%d", p);
	}
	else {
		int q = b - a;
		printf("%d", q);
	}
	return 0;
}

Measured memory_bytes: 256
// ~maqsat~
/*
```````````````````````¶¶
````````````````````¶¶¶¶¶¶¶¶
```````````````````¶¶¶¶¶¶¶¶¶¶
```````````````````¶¶¶¶¶¶``¶¶¶
``````````````````¶````¶````¶¶
``````````````````¶```¶¶¶```¶¶¶
`````````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
````````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶```````````¶¶
```````````````¶¶¶¶¶````¶¶¶¶¶`¶¶¶¶¶``````¶¶¶¶¶¶¶¶¶
`````````````¶¶¶¶¶````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶`
`````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶```¶¶¶
```¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
`¶¶``¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
``````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
```````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
```````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
`````````¶¶``````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
```````````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶
```````````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶
````````````````````¶¶¶¶¶¶¶¶¶¶¶¶
`````````````````````¶¶¶¶¶¶¶¶¶¶¶
``````````````````````¶¶¶¶¶¶¶¶¶
````````````````````````¶¶¶¶¶
                 ready for halloween
*/
 
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)
 
using namespace std;
using namespace __gnu_pbds;
 
using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
 
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }
 
const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e15 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int main() {
    fre("");
    ACCELERATE;
    
    #define int ll
    
    int n;
    cin >> n;
    
    int a[N], b[N], c[N];
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    
    ll dp[N][5];
    
    dp[0][0] = max({a[0], b[0], c[0]});
    dp[0][1] = max({a[0], b[0], c[0]});
    dp[0][2] = max({a[0], b[0], c[0]});
    for(int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i-1][1] + b[i], dp[i-1][2] + c[i]);
        dp[i][1] = max(dp[i-1][0] + a[i], dp[i-1][2] + c[i]);
        dp[i][2] = max(dp[i-1][0] + a[i], dp[i-1][1] + b[i]);
    }
    
    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
    return 0;
}
/*
 
*/

Measured memory_bytes: 6528
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        String S = sc.next();

        if (S.length() <= K) {
            System.out.println(S);
        } else {
            String reshapedS = S.substring(0, K) + "...";
            System.out.println(reshapedS);
        }
        
    }
}

Measured memory_bytes: 38720
#include<iostream>
#include<algorithm>
#define llong long long
using namespace std;
int main(int argc, char const *argv[])
{
   llong a, b;
   cin >> a >> b;
   int minab = min(a, b);

   int d = 1;
   for(int i = 1; i <= minab; i++)
   {
      if(a%i == 0 && b%i == 0)
      {
         d = i;
      }
   }

   llong ans = (a*b)/d;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
//Author Name - Mohammad Shehar Yaar Tausif
#include <bits/stdc++.h>
using namespace std;

typedef long long int lld;

int main(){
    long arr[100000][3],n,i,j,DP[100000][3];
    cin>>n;
    for(i=0;i<n;i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    DP[0][0] = arr[0][0] ;
    DP[0][1] = arr[0][1] ;
    DP[0][2] = arr[0][2] ;

    for(i=1;i<n;i++){
        DP[i][0] = max(arr[i][0] + DP[i-1][1],arr[i][0] + DP[i-1][2]);
        DP[i][1] = max(arr[i][1] + DP[i-1][0],arr[i][1] + DP[i-1][2]);
        DP[i][2] = max(arr[i][2] + DP[i-1][1],arr[i][2] + DP[i-1][0]);
    }
    cout<<max(DP[n-1][0],max(DP[n-1][1],DP[n-1][2]))<<endl;
	return 0;
}


Measured memory_bytes: 4992
/*	* In the name of GOD
 * Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int n, m, x;
	cin >> n >> m >> x;
	int c[n];
	int a[n][m];
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	int mn = 2 * 10000000;
	int ALL = pow(2, n);
	bool f[n];
	for (int i = 0; i < ALL; i++){
		int y = i;
		for (int j = 0; j < n; j++){
			f[j] = y % 2;
			y /= 2;
		}
//		for (int j = 0; j < n; j++)
//			cout << f[j] << ' ';
//		cout << endl;
		int s1 = 0, s2[m] = {};
		for (int k = 0; k < n; k++){
			if (f[k]){
				s1 += c[k];
				for (int j = 0; j < m; j++)
					s2[j] += a[k][j];
			}
		}
		bool h = true;
		for (int j = 0; j < m; j++){
			if (s2[j] < x)
				h = false;
		}
		if (h){
			mn = min (mn, s1);
		}
	}

	if (mn == 2 * 10000000)
		cout << -1;
	else
		cout << mn;
}



Measured memory_bytes: 4064
#include<stdlib.h>
#include<stdio.h>
#include<string.h>



void print_A(int *A,int n){
  int i; 
  for(i=0;i<n-1;i++) printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
}


int main(){
  int n,i,j,key;
  int *A;
  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  for(i=0;i<n;i++){
    key=A[i];
    j=i-1;
    while(key <A[j] && j>=0){
      A[j+1]=A[j];
      j+=-1;
    }
    A[j+1]=key;
    print_A(A,n);
  }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
#define w(x) int x;cin>>x;while(x--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define ppi pair<Sint,int>
#define ppl pair<ll,ll>
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define mset multiset
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll binpow(ll x, ll y, ll p){  ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;}return res;}  
ll gcd(ll a, ll b){ if (b == 0) return a; return gcd(b, a % b); } 
bool parity(ll x,ll y){ bool f = ((x ^ y) < 0);return !f;}

int main()
{
    IOS

    string s,t;
    cin>>s>>t;

    int n=s.size();
    int m=t.size();

    int dp[n+1][m+1];

    for(int i=0;i<=n;i++)
        dp[i][0]=0;

    for(int i=0;i<=m;i++)
        dp[0][i]=0;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(s[i-1]==t[j-1])
                dp[i][j]=1+dp[i-1][j-1];
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string T="";
    int i=n,j=m;
    while(i>0&&j>0)
    {
        if(dp[i][j]>dp[i-1][j]&&dp[i][j]>dp[i][j-1])
        {
            T+=s[i-1];
            i--;
            j--;
        }
        else
        {
            if(dp[i][j]==dp[i-1][j])
                i--;
            else
                j--;
        }
    }
    reverse(all(T));
    cout<<T;

    return 0;

}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

vector <ll> par(100000);
vector <ll> d(100000, 0);

void init(ll n) {
  rep(i, n) {
    par.at(i) = i;
  }
  return;
}

ll find(ll n) {
  if (n == par.at(n)) {
    return n;
  } else {
    return par.at(n) = find(par.at(n));
  }
}

void unite(ll n, ll m) {
  n = find(n);
  m = find(m);
  if (n == m) return;
  if (d.at(n) < d.at(m)) {
    par.at(n) = m;
  } else {
    par.at(m) = n;
    if (d.at(n) == d.at(m)) d.at(n)++;
  }
  return;
}

bool same(ll n, ll m) {
  return find(n) == find(m);
}

int main() {
  ll n, m, l;
  cin >> n >> m >> l;
  init(n);
  vector <ll> F(n, 0);
  vector <ll> B(n, 0);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    unite(a, b);
    F.at(a)++;
    F.at(b)++;
  }
  rep(i, l) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    if (same(a, b)) {
      B.at(a)++;
      B.at(b)++;
    }
  }
  vector <ll> v(n);
  map <ll, ll> score;
  rep(i, n) {
    v.at(i) = find(i);
  }
  sort(v.begin(), v.end());
  ll tmp = 1;
  rep(i, n-1) {
    if (i < n-2) {
      if (v.at(i) == v.at(i+1)) {
        tmp++;
      } else {
        score[v.at(i)] = tmp;
        tmp = 1;
      }
    } else {
      if (v.at(i) == v.at(i+1)) {
        tmp++;
        score[v.at(i)] = tmp;
      } else {
        score[v.at(i)] = tmp;
        score[v.at(i+1)] = 1;
      }
    }
  }
  rep(i, n) {
    ll ans = score.at(find(i));
    ans -= F.at(i) + B.at(i) + 1;
    if (i) {
      cout << ' ' << ans;
    } else {
      cout << ans;
    }
  }
  cout << endl;
}

Measured memory_bytes: 10624
A, B, C, D = [int(i) for i in input().split()]

if (C % B == 0):
    t = C / B
else:
    t = (C // B) + 1

if (A % D == 0):
    t2 = A / D
else:
    t2 = (A // D) + 1

if (t > t2):
    print('No')
else:
    print('Yes')


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

using namespace std;

int F(int u) {
	if (u % 2) return 3 * u + 1;
	return u / 2;
}

int main() {
	int s, a[101], prev;
	cin >> s;
	a[1] = s;
	map<int, int> mp;
	mp[a[1]] = 1;
	prev = a[1];
	for (int i = 2;; ++i) {
		int tmp = F(prev);
		if (mp.find(tmp) != mp.end()) {
			cout << i;
			break;
		}
		mp[tmp] = 1;
		prev = tmp;
	}
	return 0;
}


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

int main() {
    long x=1000000007;
    long n,m;cin>>n>>m;
    vector<bool> a(n+1);
    for(long i=0;i<m;i++){
        int k;cin>>k;
        a.at(k)=true;
    }
    vector<long> p(n+1,0);
    p.at(0)=!a.at(0);
    p.at(1)=!a.at(1);
    for(int i=2;i<n+1;i++){
        if(a.at(i)) p.at(i)=0;
        else p.at(i)=(p.at(i-1)+p.at(i-2))%x;
    }
    cout<<p.at(n)%x<<endl;
    //for(int i=0;i<n+1;i++) cout<<p.at(i)<<endl;
}


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

int main(){
    int a[10000]; 
    cin >> a[0];

    int m = 0;
    bool flag = false;
    while(1){
        m++;
        if (a[m -1] % 2 == 0){
            a[m] = a[m - 1] / 2;
        }
        else{
            a[m] = 3 * a[m - 1] + 1;
        }
        for (int i = 0; i < m; i++){
            if (a[i] == a[m]){
                flag = true;
            }
        }
        if (flag == true) break;
    }
    cout << m + 1 << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
import collections


def resolve(in_):
    s = next(in_).strip()
    mod = 2019
    dp = [0] * (len(s) + 1)
    ch0 = ord(b'0')
    for i, b in enumerate(reversed(s), 1):
        dp[i] = (dp[i - 1] + (b - ch0) * pow(10, i, mod)) % mod

    return sum(v * (v - 1) // 2 for v in collections.Counter(dp).values())


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16544
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0;i< (n);i++)
#define N 1000010
int MNA(vector<int> arr){
	/*正の整数配列の最大値となるときの番号を返す*/
	int max=0;
	int n=0;
	REP(i,arr.size()){
		if(arr.at(i)>=max){
			max=arr.at(i);
			n=i;
		}
	}
	return n;
}

int main(){
	int n,t;
	cin>>n;
	vector<int> an(n);
	REP(i,n){
		cin>>an.at(i);
	}
	t=MNA(an);
	sort(an.begin(),an.end());
	REP(k,n){
		if(k==t){
			cout<<an.at(n-2)<<endl;
		}else{
			cout<<an.at(n-1)<<endl;
		}
	}
	return 0;
}

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

using namespace std;

#define mod 1000000007
#define ll long long int
#define mk make_pair
#define pb push_back
#define xx first
#define yy second


double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 1e7+1;
const int N=200010;


int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T=1;
//cin>>T;
while(T--){
int n,k;
cin>>n>>k;
int arr[n+1];
for(int i=1;i<=n;i++)cin>>arr[i];
ll dp[n+1];
dp[1]=0;
arr[0]=0;
for(int i=2;i<=n;i++){
    dp[i]=1e10;
    for(int j=1;j<=k;j++){
        if(i-j>0){
            dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
        }
    }
}
cout<<dp[n];
}
return 0;
}



Measured memory_bytes: 4636
#include<cstdio>
#include<iostream>

using namespace std;
int main(void){
	int N;
	int W,H;
	int dx,dy;
	int S,T;
	int mat[120][120];
	while(1){
		cin>>N;
		if(N==0)break;
		cin>>W>>H;
		for(int i=0;i<120;i++)for(int j=0;j<120;j++)mat[i][j]=0;
		while(N--){
			cin>>dx>>dy;
			mat[dy][dx]=1;
		}
		cin>>S>>T;
		int temp;
		int max;
		temp=max=0;
		for(int i=1;i<=H;i++){
			for(int j=1;j<=W;j++){
				for(int y=0;y<T;y++){
					if(y+i>H)break;
					for(int x=0;x<S;x++){
						if(x+j>W)break;
						if(mat[y+i][x+j]==1){
							temp++;
						}
					
					}
				}
				if(max<temp){
					max=temp;
				}
				temp=0;
			}
		}
		cout<<max<<endl;
	}

}

Measured memory_bytes: 924
// Date: 2020-04-03

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL fac[N], inv[N], a[N], ans[N];
int cnt[N];

LL C(int x, int y) {
    if(x < y || y < 0) return 0;
    return fac[x] * inv[y] % mod * inv[x-y] % mod;
}

void add(LL& x, LL y) {
    x = (x + y) % mod;
}

int main() {
    FIO;
    fac[0] = inv[0] = 1;
    rep(i, 1, N-1) fac[i] = fac[i-1] * i % mod, inv[i] = qpow(fac[i], mod-2, mod);
    int n;
    cin >> n;
    int v = 0;
    rep(i, 1, n+1) {
        cin >> a[i];
        cnt[a[i]]++;
        if(cnt[a[i]] == 2) v = a[i];
    }
    int x = -1, y = -1;
    rep(i, 1, n+1) if(a[i] == v) {
        if(x == -1) x = i;
        else y = i;
    }
    rep(i, 1, n+1) {
        add(ans[i], C(n-1, i));
        add(ans[i], 2*C(n-1, i-1)%mod);
        add(ans[i], -C(x+n-y, i-1)+mod);
        add(ans[i], C(n-1, i-2));
    }
    rep(i, 1, n+1) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;

	cout << (A - 1)*(B - 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  Int n;
  cin>>n;
  vector<Int> R(n);
  cin>>R;

  Int ans = -INF;
  Int mx = -INF;
  for(Int i=n-1;i>=0;i--){
    Max(ans, mx - R[i]);
    Max(mx, R[i]);
  }
  cout<<ans<<endl;
  
  return 0;
}



Measured memory_bytes: 4364
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());

    cout << (n == a.size()? "YES" : "NO") << endl;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
	"os"
	"sort"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	h := scanNums(N)
	//低い順に並べる
	sort.Sort(sort.IntSlice(h))
	min := math.MaxInt64
	for i := 0; i < N-K+1; i++ {
		hmin := h[i]
		hmax := h[i+K-1]
		if hmax-hmin < min {
			min = hmax - hmin
		}
	}
	debug("%v\n", h)
	fmt.Printf("%d\n", min)
}

/**
 * １行に空白区切りで数字を読み込み
 */
func scanNums(len int) (nums []int) {
	nums = make([]int, len)
	for i := 0; i < len; i++ {
		fmt.Scan(&nums[i])
	}

	return
}

//** DEBUG **/
const DEBUG_ENABLE = false

func debug(format string, a ...interface{}) (n int, err error) {
	if DEBUG_ENABLE {
		return fmt.Fprintf(os.Stdout, format, a...)
	} else {
		return 0, nil
	}
}


Measured memory_bytes: 7296