akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val B = readLine()!!.split(" ").map{it.toInt()}
    val D = B.sorted()

    if (B[0] != 0) {
        println(0)
        return
    }

    val st = Array(N) { 0 }

    for (i in D) {
        st[i]++
    }

    if (st[0] != 1) {
        println(0)
        return
    }

    var zi = st.indexOf(0)
    if (zi < 0) zi = st.size
    val pi = st.indexOfLast { it > 0 }

    if (pi > zi) {
        println(0)
        return
    }

    val MOD: Long = 998244353

    var res = ModInt(1L, MOD)
    for (i in 1 until zi) {
        res *= ModInt(st[i - 1].toLong(), MOD).pow(st[i].toLong())
    }

    println(res.value)
}

class ModInt (value: Long, val mod: Long) {
    init {
        if (mod <= 0) {
            throw IllegalArgumentException("ModInt cannot be created for non-positive modulus: $mod")
        }
    }

    val value = (value % mod + mod) % mod

    private fun assertSameMod(other: ModInt) {
        if (mod != other.mod) {
            throw IllegalArgumentException(
                "You cannot operate summation, subtraction and multiplication for ModInts with different moduli: $mod, ${other.mod}"
            )
        }
    }

    operator fun unaryMinus() = ModInt(mod - value, mod)

    operator fun plus(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value + other.value) % mod, mod)
    }

    operator fun plus(other: Long) = plus(ModInt(other, mod))

    operator fun minus(other: ModInt): ModInt {
        assertSameMod(other)

        return plus(-other)
    }

    operator fun minus(other: Long) = minus(ModInt(other, mod))

    operator fun times(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value * other.value) % mod, mod)
    }

    operator fun times(other: Long) = times(ModInt(other, mod))

    fun pow(k: Long): ModInt {
        var res = 1L
        var a = value
        var l = k

        while (l > 0) {
            if ((l and 1L) == 1L) {
                res = (res * a) % mod
            }

            a = a * a % mod
            l /= 2L
        }

        return ModInt(res, mod)
    }

    /**
     * Returns an inverse element of the value.
     * To ensure `m * m.inv() = 1`, the modulus should be prime, since it uses Fermat's little theorem.
     */
    fun inv() = pow(mod - 2)

    operator fun div(other: ModInt): ModInt {
        assertSameMod(other)
        if (other.value == 0L) {
            throw ArithmeticException()
        }

        return times(other.inv())
    }

    operator fun div(other: Long) = div(ModInt(other, mod))
}

class ModCombination(val n: Long, val mod: Long) {
    private val fact = Array(n.toInt() + 1) { ModInt(1, mod) }
    private val invfact = Array(n.toInt() + 1) { ModInt(1, mod) }

    init {
        for (i in 2..n.toInt()) {
            fact[i] = fact[i - 1] * i.toLong()
            invfact[i] = fact[i].inv()
        }
    }

    operator fun get(n: Long, m: Long): ModInt {
        if (m > n || n < 0 || m < 0) {
            return ModInt(0, mod)
        }

        return fact[n.toInt()] * invfact[m.toInt()] * invfact[(n - m).toInt()]
    }
}


Measured memory_bytes: 58340
#include <stdio.h>
int main (int argc, char * argv[])
{
    int n,b,min=0,max=0;
    long long sum = 0;
    int a[10000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&b);
        a[i] = b;
        sum +=a[i];
        
    }
    max = a[0];
    min = a[0];
    for(int i=1;i<n;i++){
        if(a[i]>max){
            max = a[i];
        }
        if(min>a[i]){
            min = a[i];
        }
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}



Measured memory_bytes: 2100
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    cnt += (a != i);
  }
  puts(cnt == 2 || cnt == 0 ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair

int n,m;

int main () {
	scanf("%d %d",&n,&m);
	printf("%d\n",(n-1)*(m-1));
	return 0;	
}

Measured memory_bytes: 128
n = int(input())
d = {}
for _ in range(n):
    s = list(input())
    s.sort()
    js = ''.join(s)
    if js in d:
        d[js] += 1
    else:
        d[js] = 1

cnt = 0
for v in d.values():
    cnt += (v*(v-1)//2)
print(cnt)

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

int n, k;
int h[100010];
int memo[100010];

int dp(int pos) {
    if (pos > n - 1) return 1 << 30;
    if (pos == n - 1) return 0;
    if (memo[pos] != -1) return memo[pos];
    int res = 1 << 30;
    for(int i = 1; i <= k; i++)
        res = min(res, abs(h[pos + i] - h[pos]) + dp(pos + i));
    return memo[pos] = res;
}

int main() {
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> h[i];
    memset(memo, -1, sizeof(memo));
    int ans = dp(0);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
namespace ITP1_3_B
{
    class Problem
    {

        public static List<string[]> getinputdata (){

            List<string[]> list_temp = new List<string[]>();
            string strdata = Console.ReadLine ();

            while (strdata!=null) {

                string[] s_temp = strdata.Split (' ');

                list_temp.Add (s_temp);

                strdata = Console.ReadLine ();

            }

            return list_temp;
        }



        public static void Main (string[] args)
        {
            List<string[]> arr_result = new List<string[]>();
            arr_result = getinputdata ();

            int cnt = arr_result.Count;

            for (int i = 0; i < cnt; i++)
            {
                if (arr_result[i][0]!="0")
                {

                    Console.WriteLine("Case " + (i+1) + ": " + arr_result[i][0]);
                }

            }

//      
//            foreach (var item in arr_result)
//            {
//                Console.WriteLine(item);
//            }



        }
    }
}

Measured memory_bytes: 11196
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long

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

   set<int> st;
   for(int i=0; i<n; i++){
        int x;
        cin>>x;
        st.insert(x);
   }

   cout<<(n==st.size() ? "YES": "NO");


}




Measured memory_bytes: 12888
N, x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
f=0
i=0
while x>=a[i]:
    x=x-a[i]
    i=i+1
    f=f+1
    if i==N:
        break
if i==N and x>0:
    print(f-1)
else:
    print(f)

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

//#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A >= B + C)
        C = 0;
    else
        C = C - A + B;
    cout << C << endl;
}

Measured memory_bytes: 256
n, m, l = map(int, input().split())

A = []
for g in range(n):
    A.append(list(map(int, input().split())))

B = []
for h in range(m):
    B.append(list(map(int, input().split())))

for i in range(n):
    output = []
    for j in range(l):
        temp = 0
        for k in range(m):
            temp += A[i][k] * B[k][j]
        output.append(temp)
    print(*output)

Measured memory_bytes: 8636
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
	double x1, y1, x2, y2, x3, y3, xp, yp;
	double a, b, c;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
		a = (x2 - x1)*(yp - y1) - (xp - x1)*(y2 - y1);
		b = (x3 - x2)*(yp - y2) - (xp - x2)*(y3 - y2);
		c = (x1 - x3)*(yp - y3) - (xp - x3)*(y1 - y3);
		if((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0)){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	ll X;
	cin >> X;
	int i = 0;
	ll now = 100;
	while(true){
		i++;
		now = now * 1.01;
		if(now >= X){
			break;
		}
	}
	cout << i << endl;
	
	return 0;
}


Measured memory_bytes: 3636
N, X = gets.split.map(&:to_i)
towns = gets.split.map(&:to_i).sort
first_point = nil
diff_array = []


diff = (towns[-1] - X).abs

towns.each_with_index{|i, idx|
  if X > i
    if diff > (X - i)
      first_point = i
      diff = (X - i)
    end
  else
    if diff > (i - X)
      first_point = i
      diff = (i - X)
    end
  end

  unless idx == 0
    diff_array << (towns[idx]-towns[idx-1])
  end
}

diff_array << diff
if diff_array.length == 1
  diff_array << diff
end
diff_array.delete(0)
diff_array.sort!

def gcd(x, y)
  if y == 0
    return y
  end

  if y > x
    gcd(y, x)
  end

  r = x % y
  if r.zero?
    return y
  end

  gcd(y, r)
end

result = diff_array.reduce{|memo, item|
  gcd(memo, item)
}

puts result


Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

template<class T> struct UF{
    vector<T> par,sz;

    UF(T n){
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i]=i;
            sz[i]=1;
        }
    }

    T find(T x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    bool unit(T x,T y){
        x=find(x);
        y=find(y);
        if(x==y) return false;
        if(sz[x]>sz[y]){
            par[y]=x;
            sz[x]+=sz[y];
        }
        else{
            par[x]=y;
            sz[y]+=sz[x];
        }
        return true;
    }

    bool same(T x,T y){return find(x)==find(y);}
};

int main(){
    ll n,m,ans=0;
    cin>>n>>m;
    bool vis[100010]={};
    int x,y,z;
    UF<ll> uf(n);
    fr(i,m){
        cin>>x>>y>>z;
        uf.unit(x-1,y-1);
    }
    fr(i,n){
        ll j=uf.find(i);
        if(vis[j]) continue;
        vis[j]=1;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1920
#include<stdio.h>
int main()
{
  int a,b,c=100,d,e,op[20]={0},sb[20]={0};
  char cnm[18];
  op[2]=1;
  gets(cnm);
  a=strlen(cnm);
  for(b=a-1;b>=0;b--)
  sb[a-b-1]=cnm[b]-'0';
  for(b=0;;b++)
  {
      for(c=0;c<=a-2;c++)
      {
          op[c]=op[c]+op[c+2];
         if(op[c]>=10) {op[c]-=10; op[c+1]+=1; }
      }
      d=-1;
      for(c=a;c>=0;c--)
      {
          if(op[c]>sb[c]) {d=1; break; }
          else if(op[c]<sb[c]) {d=0; break; }
      }
      if(d==-1||d==1) {printf("%d\n",b+1); break;}
  }
   return 0;
}

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


vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}
int main(){
    int n,k;
    cin>>n>>k;
    mod_build();
    if(n==k){
        cout<<1<<endl;
        rep(i,n-1)cout<<0<<endl;
        return 0;
    }
    rep(i,k){
        ll ans = 0;
        ans += comb(k-1,i)*comb(n-k-1,i-1)%mod;
        ans += 2*comb(k-1,i)*comb(n-k-1,i)%mod;
        ans += comb(k-1,i)*comb(n-k-1,i+1)%mod;
        cout<<ans%mod<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

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

const int max_s = 2020;
ll dp[max_s][max_s];

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

	ll MOD = 1e9 + 7;

	ll s;
	cin >> s;

	rep(i, s+1) rep(j, s+1) dp[i][j] = 0;
	dp[0][0] = 1;

	rep(i, s){
		ll t = 0;
		for(int j = 3 * i; j <= s - 3; j++){
			t += dp[i][j];
			t %= MOD;

			dp[i+1][j+3] += t;
			dp[i+1][j+3] %= MOD;
 		}
	}

	ll ans = 0;
	rep(i, s){
		ans += dp[i+1][s];
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 35112
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <array>
#include <string>
#include <map>
using namespace std;

#define DB(x)

/*
int getIntSp(){
    string str;
    getline(cin,str,' ');
    return stoi(str);
}

int getIntLF(){
    string str;
    getline(cin,str);
    return stoi(str);
}
 */


int main() {
    int N,M;
    string S;
    
    cin >> N >> M;
    cin >> S;
    
    int pos = N;
    vector<int> deme;
    
    while( pos > 0 )
    {
        int i = M;
        
        if( pos - M <= 0 ){
            deme.push_back(pos);
            break;  //  while
        }
        for( ; i > 0; --i )
        {
            if( '0' == S.c_str()[pos - i] )
            {
                deme.push_back(i);
                pos -= i;
                break;  //  for
            }
        }
        if( i == 0){
            cout << "-1" << endl;
            return 0;
        }
    };  //  while
    
    for( int i = (int)deme.size()-1; i > 0; --i )
    {
        cout << deme[i] << " ";
    }
    cout << deme[0] << endl;
    return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  bool flg = false;
  int k = 1;
  for (int i = 0; i < N; i++){
    if (a[i]==k){
      k++;
      flg = true;
    }
  }
  if (flg == false){
    cout << -1;
  } else {
    cout << N-k+1;
  }
}

Measured memory_bytes: 1024
n=int(input())
arr=[]
flag=True
s=input()
arr.append(s)
for _ in range(n-1):
  w=input()
  if w in arr:
    flag=False
  if s[-1] != w[0]:
    flag=False
  arr.append(w)
  s=w
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>

#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

#define MAX_N 10
typedef pair<int, int> pint;

class Permutation{
    int length = 0;
    int target[MAX_N];
    int perm[MAX_N];
    int used[MAX_N];

    stack<pint> stk;

public:
    Permutation(int a[], int n){
        length = n;

        for (int i = length - 1; i>= 0; i --) {
            target[i] = a[i];
            perm[i] = i;
            stk.push(make_pair(0, i));
        }
    }

    bool next_permutation(int res[]) {
        if (stk.empty()) return false;

        pint coor;
        int ind, num;

        for (int i = stk.top().first; i < length; i ++) {
            used[perm[i]] = -1;
        }

        while (!stk.empty()) {
            coor = stk.top();
            stk.pop();
            ind = coor.first;
            num = coor.second;
            perm[ind] = num;
            used[num] = ind;

            if (ind == length - 1) {
                for (int i = 0; i < length; i ++) {
                    res[i] = target[perm[i]];
                }
                return true;
            }

            for(int i = length - 1; i >= 0; i --) {
                if (used[i] == -1) {
                    stk.push(make_pair(ind+1, i));
                }
            }
        }
        return false;
    }
};

int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n >> m;
    int a[n], b[n][n], res[n];

    int s, t;
    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < n; j ++) {
            b[i][j] = 0;
        }
    }
    for (int i = 0; i < n; i ++) {
        a[i] = n-i-1;
    }
    res[n-1]=0;


    for (int i = 0; i < m; i ++) {
        cin >> s >> t;
        b[--s][--t] = 1;
        b[t][s] = 1;
    }

    Permutation per = Permutation(a, n-1);
    int count = 0, f;
    while (per.next_permutation(res)) {
        f = 1;
        for(int i = 0; i < n-1; i ++) {
            if (b[res[i]][res[i+1]] == 0) {
                f = 0;
                break;
            }
        }
        count += f;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)998244353
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, s;
signed main() {
	cin >> n >> s;
	for (int i = 2; i * i <= n; i++) {
		int cnt = 0, m = n;
		while (m) {
			cnt += m % i;
			m /= i;
		}
		if (cnt == s) {
			cout << i << endl;
			return 0;
		}
	}
	for (int i = sqrt(n); i >= 1; i--) {
		if ((n - s) % i)continue;
		int b = (n - s) / i + 1;
		if (b <= 1)break;
		int cnt = 0, m = n;
		while (m) {
			cnt += m % b;
			m /= b;
		}
		if (cnt == s) {
			cout << b << endl;
			return 0;
		}
	}
	if (n == s)cout << n + 1 << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
void ade(int& x,int y){x+=y;if(x>=mod)x-=mod;}
int add(int x,int y){return x+y<mod?x+y:x+y-mod;}
int qpow(int x,int k)
{
    int r=1;
    while(k)
    {
        if(k&1)r=1ll*r*x%mod;
        k>>=1;x=1ll*x*x%mod;
    }
    return r;
}
int C[1010][1010];
int fac[1010],ifac[1010];
void init()
{
    for(int i=0;i<=1000;++i)
    {
        C[i][0]=1;
        for(int j=1;j<=i;++j)C[i][j]=add(C[i-1][j],C[i-1][j-1]);
    }
    fac[0]=1;
    for(int i=1;i<=1000;++i)fac[i]=1ll*fac[i-1]*i%mod;
    ifac[1000]=qpow(fac[1000],mod-2);
    for(int i=999;i>=0;--i)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
int n,m;
int tr;
char s[110];
int a[110];
bool book[77];
bool eb[77];
bool check(int d)
{
    int cr=0,crb=0;
    for(;a[cr+1]==1&&cr+1<=d;cr++);
    crb=d-cr;
    memset(book,0,sizeof(book[0])*(m+3));
    memset(eb,0,sizeof(eb[0])*(m+3));
    int pr=0,pb=0;
    for(int t=1;t<=crb;++t)
    {
        while((s[pr]!='r'||book[pr])&&pr<=m)pr++;
        while((s[pb]!='b'||book[pb]||pb<=pr)&&pb<=m)pb++;
        if(pr>m||pb>m)return 0;
        book[pr]=book[pb]=1;
        eb[pb]=1;
    }
    int tcr=cr;
    for(int i=1;i<=m&&cr;++i)
        if(!book[i]&&s[i]=='r')cr--,book[i]=1;
    if(cr)return 0;
    for(int i=m,p=tcr+1,cnt=0;p<=d;--i)
    {
        if(!book[i])cnt++;
        if(eb[i])
        {
            cnt-=a[p]-2;
            if(cnt<0)return 0;
            p++;
        }
    }
    return 1;
}
int ans;
void calc(int d,int l)
{
    int s=d+1;
    for(int i=1;i<=d;++i)
        if(a[i]==1)s++;
        else s+=(a[i]-1)*2+1;
    int res=1ll*C[n-l+s-1][s-1]*fac[d]%mod;
    for(int i=1,j;i<=d;i=j+1)
    {
        for(j=i;a[j+1]==a[i]&&j<d;++j);
        res=1ll*res*ifac[j-i+1]%mod;
    }
    ade(ans,res);
}
bool dfs(int x,int la,int len,int sl)
{
    if(!check(x-1))return 0;
    if(x-1>tr)return 1;
    calc(x-1,len);
    int nl;
    for(int i=la;i<=m-sl;++i)
    {
        a[x]=i;
        nl=len;
        if(x!=1)nl++;
        if(i==1)nl++;
        else nl+=(i-1)*2-1;
        if(nl>n)break;
        if(!dfs(x+1,i,nl,sl+i))break;
    }
    return 1;
}
int main()
{
    init();
    scanf("%d%d",&n,&m);
    scanf("%s",s+1);
    for(int i=1;i<=m;++i)tr+=(s[i]=='r');
    dfs(1,1,0,0);
    printf("%d\n",ans);
    return 0;
}


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

int main(){
  vector <int> a(5); 
  int k;
  for(int i=0; i<a.size(); i++) cin >> a.at(i);
  cin >> k;

  
  for(int i=0; i<a.size(); i++){
    for(int j=0; j<a.size(); j++){
      if ( k < abs(a.at(i)-a.at(j)) ){
	cout << ":(" << endl;
	return 0;
      }
    }
  }
  
  cout << "Yay!" << endl;
  
  

  return 0;
}


Measured memory_bytes: 256
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let k: usize = read();
    let mut ans: usize = 0;
    for a in 1..=k {
      for b in 1..=k {
        for c in 1..=k {
          ans += gcd(a, gcd(b, c));
        }
      }
    }

    println!("{}", ans);
}

fn gcd(a: usize, b: usize) -> usize {
  if b > a {
    gcd(b, a);
  }

  if a % b == 0 {
    return b;
  }

  let r: usize = a % b;

  return gcd(b, r);
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


signed main(){

	lli n;
	cin>>n;

	cout<<(n+1)/2<<endl;



	return 0;
}

Measured memory_bytes: 256
using System;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string r = Console.ReadLine();
                if (r == null) break;
                double[] k0 = new double[6];
                 k0[0] = double.Parse(r.Split(' ')[0]);
                 k0[1] = double.Parse(r.Split(' ')[1]);
                 k0[2] = double.Parse(r.Split(' ')[2]);
                 k0[3] = double.Parse(r.Split(' ')[3]);
                 k0[4] = double.Parse(r.Split(' ')[4]);
                 k0[5] = double.Parse(r.Split(' ')[5]);
                string x, y;
                y = ((k0[2] * k0[3] - k0[0] * k0[5]) / (k0[1] * k0[3] - k0[0] * k0[4])).ToString();
                x = ((k0[2] - k0[1] * double.Parse(y)) / (k0[0])).ToString();
                Console.WriteLine(String.Format("{0:0.000} {1:0.000}", double.Parse(x), double.Parse(y)));
            }
        }
    }
}

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, L;
    cin >> N >> L;
    vector<string> v;
    copy(istream_iterator<string>{ cin }, istream_iterator<string>{}, back_inserter(v));
    sort(v.begin(), v.end());
    for(auto s : v) cout << s;
    cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

uint64_t n, k, ndiv = 1000000007;
uint64_t pt[2001][2001];

int main(void) {
    uint64_t i, j, x, y;
    cin >> n >> k;
    pt[0][0] = 1;
    for (i = 1; i <= 2000; i++) {
        for (j = 0; j <= i; j++) {
            if (j == 0 || j == i) {
                pt[i][j] = 1;
                continue;
            }
            pt[i][j] = (pt[i-1][j-1] + pt[i-1][j])%ndiv;
        }
    }
    for (i = 1; i <= k; i++) {
        x = pt[n-k+1][i];
        y = pt[k-1][i-1];
        cout << x*y%ndiv << endl;
    }
    return 0;
}


Measured memory_bytes: 30080
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int h,w;
  cin >>h >>w;
  
  vector<string> picture(h);
  
  for(int i; i<h; i++){
    cin >> picture.at(i);
  }
  
  string frame = "";
  char s = '#';
  for(int i; i<w+2; i++){
    frame += s;
  }
  
  vector<string> answer(h+2);
  answer.at(0) = frame;
  answer.at(h+1) = frame;
  
  for(int i=1; i<h+1; i++){
    answer.at(i) = s + picture.at(i - 1) + s;
  }
  
  for(int i; i<h+2; i++){
    cout << answer.at(i) << endl;
  }
   
}

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

#define N_MAX 1000000001

typedef struct{
    int x;
    int y;
} pos,lppos;

int64_t H,W,N;
int a,b;
int64_t output[10] = {0} ;
map<int64_t,bool> board;
map<int64_t,bool> is_counted;
vector<int> a_arr;
vector<int> b_arr;

// 中心座標
void check(int x,int y){
    if( x < 1 || W-1 <= x )return;
    if( y < 1 || H-1 <= y )return;
    if( is_counted.find(x+W*y) != is_counted.end() )return;
    is_counted[x+W*y] = true;
    
    int count = 0;
    
    for(int i = x-1 ; i <= x+1 ; i++ ){
        for(int j = y-1 ; j <= y+1 ; j++ ){
            if( board.find(i+W*j) != board.end() )
                count++;
        }
    }
    output[count]++;
}


int main(void){
    cin >> H;
    cin >> W;
    cin >> N;
    
    
    for(int i = 0 ; i < N ; i++ ){
        cin >> b;
        cin >> a;
        a--;b--;
        a_arr.push_back(a);
        b_arr.push_back(b);
        board[a+W*b] = true;
    }
    /*
    for(int i = 0 ; i < W ; i++ ){
        for(int j = 0 ; j < H ; j++ ){
            if( board.find(i+W*j) != board.end() )
                printf(".");
            else
                printf(" ");
        }
        printf("\n");
    }
    */
    for(int i = 0 ; i < N ; i++ ){
        a = a_arr[i];
        b = b_arr[i];
        
        for(int dx = -1 ; dx <= 1 ; dx++ ){
            for(int dy = -1 ; dy <= 1 ; dy++ ){
                check(a+dx,b+dy);
            }
        }
    }
    int64_t all_cells = ((int64_t)H-2) * (W-2);
    int64_t temp = 0;
    
    for(int i = 0 ; i < 10 ; i++ )
        temp += output[i];
    
    output[0] = all_cells  - temp;
    
    for(int i = 0 ; i < 10 ; i++ )
        printf("%lld\n",output[i]);
    
    // board.find(key) == board.end() ならない
    
    
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

struct UnionFind {
    vector<int> par;
    vector<ll> num;

    UnionFind(int N) : par(N), num(N) {
        for(int i = 0; i < N; i++){
        	par[i] = i;
        	num[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        num[ry] += num[rx];
    }

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m; cin>>n>>m;
	UnionFind uf(n+1);
	vector<pll> ab(m);

	for(int i=m-1; i>=0; i--)
		cin >> ab[i].fi >> ab[i].se;
	vll ans(m);
	ans[0] = (n*(n-1)/2);
	rep(i, m-1){
		ans[i+1] = ans[i];
		if (!uf.same(ab[i].fi, ab[i].se)){
			ans[i+1] -= uf.num[uf.root(ab[i].fi)] * uf.num[uf.root(ab[i].se)];
			uf.unite(ab[i].fi, ab[i].se);
		}
	}
	rep(i, m){
		cout << ans[m-i-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>

using namespace std;

int main(){
    
    int a, b;
    cin >> a >> b;
    int ans;
    int pt;
    if(a>=b){
        ans = a;
        pt = b;
    }
    
    else {
        ans = b;
        pt = a;
    }
    for(int i=0;i<ans;i++){
        cout << pt ;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
typedef long long LL;
const LL INF = 1e18; 
const int MAX_N = 3e5 + 5; 
int N, M, a[MAX_N]; 
LL s[MAX_N]; 
int stk[MAX_N], top; 
LL F[MAX_N], G[MAX_N], H[MAX_N], y[MAX_N]; 
long double slope(int i, int j) { return 1.0 * (y[j] - y[i]) / (j - i); } 
void Init(LL f[]) { 
    for (int i = 1; i <= N; i++) s[i] = s[i - 1] + a[i];
    top = 0; 
    for (int i = 1; i <= N; i++) { 
        while (top && slope(stk[top - 1], stk[top]) <= 1.0 * i) --top; 
        int j = stk[top]; 
        f[i] = f[j] - s[i - 1] + s[j] + 1ll * (i - j) * (i - j - 1) / 2; 
        y[i] = f[i] + s[i] + 1ll * (i + 1) * i / 2; 
        while (top && slope(i, stk[top]) >= slope(stk[top], stk[top - 1])) --top;
        stk[++top] = i; 
    } 
} 
void chkmax(LL &x, LL y) { if (x < y) x = y; } 
LL t[MAX_N];
//57766
void Div(int l, int r) { 
    if (l == r) return chkmax(H[l], max(1ll - a[l], F[l] + G[l] - a[l] + 1)); 
    int mid = (l + r) >> 1; 
    Div(l, mid), Div(mid + 1, r);
    stk[top = 1] = 0; 
    for (int i = l - 1; i <= mid; i++) { 
        y[i] = F[i] + s[i] + 1ll * (i - 1) * i / 2; 
        while (top > 1 && slope(stk[top], i) >= slope(stk[top - 1], stk[top])) --top; 
        stk[++top] = i; 
    } 
    for (int i = mid + 1; i <= r; i++) { 
        while (top > 1 && slope(stk[top - 1], stk[top]) <= 1.0 * i) --top; 
        int j = stk[top]; 
        t[i] = F[j] - s[i] + s[j] + 1ll * (i - j + 1) * (i - j) / 2; 
    } 
    t[r] += G[r + 1]; 
    for (int i = r - 1; i > mid; i--) 
        t[i] += G[i + 1], chkmax(t[i], t[i + 1]); 
    for (int i = mid + 1; i <= r; i++) chkmax(H[i], t[i]); 
    stk[top = 0] = N + 1; 
    for (int i = mid + 1; i <= r + 1; i++) { 
        y[i] = G[i] - s[i - 1] + 1ll * (i + 1) * i / 2; 
        while (top > 1 && slope(stk[top], i) >= slope(stk[top - 1], stk[top])) --top;
        stk[++top] = i; 
    } 
    for (int i = l; i <= mid; i++) { 
        while (top > 1 && slope(stk[top - 1], stk[top]) <= 1.0 * i) --top; 
        int j = stk[top]; 
        t[i] = G[j] - s[j - 1] + s[i - 1] + 1ll * (j - i) * (j - i + 1) / 2;
    } 
    t[l] += F[l - 1]; 
    for (int i = l + 1; i <= mid; i++) 
        t[i] += F[i - 1], chkmax(t[i], t[i - 1]); 
    for (int i = l; i <= mid; i++) chkmax(H[i], t[i]); 
} 
int main() {
    scanf("%d", &N); 
    for (int i = 1; i <= N; i++) scanf("%d", a + i); 
    Init(F); 
    reverse(&a[1], &a[N + 1]); 
    Init(G); 
    reverse(&G[1], &G[N + 1]); 
    reverse(&a[1], &a[N + 1]); 
    for (int i = 1; i <= N; i++) s[i] = s[i - 1] + a[i]; 
    for (int i = 1; i <= N; i++) H[i] = -INF; 
    Div(1, N); 
    scanf("%d", &M);
    while (M--) { 
        int p, x; scanf("%d %d", &p, &x); 
        printf("%lld\n", max(F[p] + G[p], H[p] + a[p] - x)); 
    } 
    return 0; 
} 

Measured memory_bytes: 19032
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    string s;
    cin >> s;
    rep(i, s.size() - 1){
        if(s[i] == 'A' && s[i + 1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());

            var V = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var C = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Console.WriteLine(V.Zip(C, (v, c) => (v - c)).Sum(x => x > 0 ? x : 0));
        }
    }
}

Measured memory_bytes: 13396
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '#' for _ in range(h)]
  s.append('#' * w)
  ft = [[i] * i for i in range(100)]
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '#':
        if start != -1:
          t = j - start
          if t < 100:
            yokoi[start:j] = ft[t]
          else:
            yokoi[start:j] = [t] * t
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '#':
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Measured memory_bytes: 38900
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<long long int> a(n);
  for(int i = 0; i < n ;i++){
    int b;
    cin >> b;
    a[i] = b;
  }
  int mn = 100;
  int y = m;
  sort(a.begin(),a.end());
  vector<int>b(mn);

  for(int i = 0; i < mn; i++){
    b[i] = n-1;
  }
  for(int i = 0; i < y; i++){
    int max = 0;
    int mj = 0;
    for(int j = 0; j < mn; j++){
      if(a[b[j]]>max){
	max = a[b[j]];
	mj = j;
      }
    }
    a[b[mj]]/=2;
    if(a[b[mj]] < a[b[mj]-1]){
      b[mj]--;
      if(b[mj]<0)b[mj] = 0;
    }
  }
  long long int ans = 0;
  for(int i = 0 ; i < n; i++){
    ans+= a[i];
  }
  cout << ans << endl;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)

typedef long long lint;

int H, W, dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
lint L;
string grid[110], dir = "NESW";

int visit[110][110][4], seq[41000];

bool able(int x, int y) {
	if (x < 0 || x >= W || y < 0 || y >= H) return false;
	return grid[y][x] == '.';
}

int main() {
	std::ios::sync_with_stdio(false);
	while (cin >> H >> W >> L, H) {
		int x = 0, y = 0, d = 0;
		
		for_(i,0,H) {
			cin >> grid[i];
			for_(j,0,W) if (grid[i][j] != '.' && grid[i][j] != '#') {
				x = j; y = i;
				d = dir.find(grid[i][j]);
				grid[i][j] = '.';		
			}
		}
		
		memset(visit, -1, sizeof(visit));
		
		lint s = 0;
		while (visit[y][x][d] < 0) {
			visit[y][x][d] = s;
			seq[s] = (y << 10) | (x << 2) | d;
			while (!able(x + dx[d], y + dy[d])) d = (d + 1) % 4;
			x += dx[d]; y += dy[d];
			++s;
		}
		
		int t = visit[y][x][d], id = L;
		if (s < L) id = t + (L - t) % (s - t);
		
		y = seq[id] >> 10;
		x = (seq[id] >> 2) & 0xff;
		d = seq[id] & 3;
		cout << y + 1 << " " << x + 1 << " " << dir[d] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1468
N, M=map(int, input().split())
from1=set([])
fromN=set([])
# a<b
for _ in range(M):
  a, b=map(int, input().split())
  if a==1:
    from1.add(b)
  if b==N:
    fromN.add(a)
while from1:
  if from1.pop() in fromN:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")
  
  

Measured memory_bytes: 24036
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    int s = N /111;
    if(N%111 != 0)s++;
    cout<<s*111<<endl;
    return 0;
}


Measured memory_bytes: 256
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 1000000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int n, Ans;
char S[N], T[N];
int bias, que[N], head, tail;

int main() {
	cin >> n;
	for (int i = 1; i <= n;i++) cin >> S[i];
	for (int i = 1; i <= n; i++) cin >> T[i];
	int ok = 1;
	for (int i = 1; i <= n; ++i) if (S[i] != T[i]) ok = 0;
	if (ok) return cout << 0, 0;
	head = 1, tail = 0;
	for (int i = n, j = n; i >= 1; --i) {
		if (j > i) j = i;
		while (head <= tail && que[head] + bias > i) ++head;
		Ans = std::max(Ans, tail - head + 2);
		if (i == 1 || T[i - 1] != T[i]) {
			while (j && S[j] != T[i]) --j;
			if (!j) return cout << -1, 0;
			--bias;
			que[++tail] = j - bias;
			--j;
		}
	}
	cout << Ans;
	return 0;
}


Measured memory_bytes: 9504
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    ll min_num = INF;
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
        min_num = min(min_num, A[i]);
    }
    vector<ll> min_index;
    for(size_t i=0;i<N; i++)
    {
        if(min_num == A[i]) min_index.push_back(i);
    }
    ll _idx = 0;
    ll dist=0;
    ll count = 0;
    if((N - min_index.size()) % (K-1) == 0) count = (N-min_index.size()) / (K-1);
    else count = (N-min_index.size()) / (K-1) + 1;
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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


int main(void){
	int n,i;
	int sum=0;
	double ave, var=0;
	int x[1000];
	scanf("%d", &n);

	do{
		
		for(i=0; i<n; i++){
			scanf("%d", &x[i]);
			sum += x[i];
		}
		ave = (double)sum / n;
		for(i=0; i<n; i++){
			var += (x[i]-ave)*(x[i]-ave);
		}
		var /= n;
		printf("%f\n", sqrt(var));
		sum = 0;
		var = 0;
		scanf("%d", &n);
	} while(n != 0);
	return 0;
}

Measured memory_bytes: 636
import math
A,B,H,M = map(int,input().split())
A_rad_std = 0.5
B_rad_std = 6
minute = H*60 + M
A_rad = math.radians(A_rad_std * minute)
B_rad = math.radians(B_rad_std * M)

A_Xpoint = A * math.cos(A_rad)
A_Ypoint = A * math.sin(A_rad)
B_Xpoint = B * math.cos(B_rad)
B_Ypoint = B * math.sin(B_rad)

d = math.sqrt((A_Xpoint - B_Xpoint)**2 + (A_Ypoint - B_Ypoint)**2)
print(d)

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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  int y = 0;
  double c;
  int count = 0;
  for(int i=0; i<n; i++){
    cin >> x.at(i);
    y += x.at(i);
  }
  c = 1.0 * y / n;
  int d = round(c);
  for(int i=0; i<n; i++){
    count += (x.at(i)-d) * (x.at(i)-d);
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
///////////////////////////////////////

int main() {
	int N, M; cin >> N >> M;
	int L[100100], R[100100];
	for (int i = 0; i < M; ++i) {
		cin >> L[i] >> R[i];
	}
	int table[100100];
	for (int i = 0; i < 100100; ++i) {
		table[i] = 0;
	}
	for (int i = 0; i < M; ++i) {
		table[L[i]]++;
		table[R[i]+1]--;
	}
	for (int i = 0; i <= N; ++i) {
		if (0 < i)table[i] += table[i - 1];
	}	
	int ans = 0;
	for (int i = 0; i <= N; ++i) {
		if (table[i] == M) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int k, a, b;
    cin >> k >> a >> b;
    int ans = 0;
    int i;
    for(i = a; i <= b; i++){
        if(i%k == 0){
            ans = 1;
        }
    }
    if(ans == 1){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
s = gets.split('')
N = s.count('N')
W = s.count('W')
S = s.count('S')
E = s.count('E')

if ((N > 0 && S == 0) || (S > 0 && N == 0) || (W > 0 && E == 0) || (E > 0 && W == 0))
    puts 'No'
else
    puts 'Yes'
end

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

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            //string s = Console.ReadLine();

            // 整数の入力
            //int n = int.Parse(Console.ReadLine());

            // 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            // 整数配列の入力
            var inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            int L = inputintArray[0];
            int R = inputintArray[1];
            int d = inputintArray[2];

            int cnt = 0;

            for(int i=L; i <= R; i++)
            {
                if (i % d == 0)
                {
                    cnt++;
                }
            }


            Console.WriteLine(cnt);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
#include <vector>

#define mem(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;

const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;

int main()
{
    int n, k, sum = 1;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        if(sum + k > sum *2){
            sum *= 2;
        }
        else
            sum += k;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef pair<int, int> P;

bool operator< (const P &a,const P &b){
  return a.first < b.first;
};
int main()
{
  long long int AA,BB,u,type,cou=0,a,b,t,s,N,A,B,v[100],res=0;
  long long int comb[58][58];
  double ave;
  comb[0][0] = 1;
  comb[0][1] = 0;
  comb[1][0] = 1;
  comb[1][1] = 1;
  for(int i=1;i<=51;i++)
    for(int j=0;j<=i;j++){
      if(j == 0)
        comb[i][j] = 1;
      else
        comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
  }
  cin >> N >> A >> B;
  REP(i,N)cin >> v[i];
  sort(v,v+N);
  a = A;
  ave = 0;
  u = 1;
  AA = A;
  BB = B;
  type = v[N-1];
  for(int i=N-1;a>0;a--,i--){
    ave += (double)v[i]/A;
    if(type != v[i]){
      cou = 0;
      u = 0;
      AA -= cou;
      BB -= cou;
    }
    type = v[i];
    cou++;
  }
  t = 0;
  REP(i,N){
    if(v[i] == type)
      t++;
  }
  
  
  if(u == 1){
    for(int i=A;i<=min(B,t);i++)res += comb[t][i];
  }else{
      res += comb[t][cou];
    }
  printf("%.7lf\n%lld\n",ave,res);
 
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=300+50;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,f[N<<1][N<<1];
char s[N][N],sq[N<<1][N<<1];

int main()
{
    n=read();
    rep(i,1,n) scanf("%s",s[i]+1);
    rep(i,1,n*2) rep(j,1,n*2)
    {
        int x=i,y=j;
        if (x>n) x-=n;
        if (y>n) y-=n;
        sq[i][j]=s[x][y];
    }
    /*rep(i,1,n*2)
    {
        rep(j,1,n*2) putchar(sq[i][j]);
        puts("");
    }*/
    int ans=0;
    rep(i,1,n*2-1) rep(j,1,n*2-1)
    {
        int cnt=0,k=0;
        while ((k<min(i,j)) && (sq[i][j-k]==sq[i-k][j])) k++;k--;
        //cout << i << " " << j << " " << k << endl;
        f[i][j]=1+min(f[i-1][j-1],k);
        if (f[i][j]>=n) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2432