akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 問題文が長くて難しい...
int main() {
  int N, K;
  cin >> N >> K;

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    ans += min(2 * x, 2 * (K - x));
  }

  cout << ans << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
int main() {
	double a, b, n, m, x[1010], ans = 0, add;
	string S;
	cin >> a >> b >> n;
	for (int i = 0; i < a; i++)
		cin >> x[i];

	for (int i = 0; i < a; i++)
		ans += ceil(b / x[i]);

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);
int main(){
  int n, m;cin>>n>>m;
  vector<vector<int>> dis(n, vector<int>(n, INF));
  vector<pair<P, int>> edge(m);
  for(int i=0;i<m;i++){
    int a, b, c;cin>>a>>b>>c;a--;b--;
    dis[a][b]=dis[b][a]=c;
    edge[i]=make_pair(P(a, b), c);
  }
  for(int i=0;i<n;i++)dis[i][i]=0;
  for(int k=0;k<n;k++){
  	for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(dis[i][k]==INF || dis[k][j]==INF)continue;
        dis[i][j] = min(dis[i][j], dis[i][k]+dis[k][j]);
      }
    }
  }
  int ans=m;
  for(int i=0;i<m;i++){
    bool used=false;
    for(int j=0;j<n;j++){
      if(dis[j][edge[i].first.first]==dis[j][edge[i].first.second]+edge[i].second)used=true;
    }
    if(used)ans--;
  }
  cout<<ans<<endl;
}


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

int main() {
  ll n; cin >> n;
  ll ans;
  for(ll i = n; i<(n+111); i++){
    ll a = i/100; //100
    ll b = i%100; 
    ll c = b/10; //10
    ll d = b%10; //1
    if(a==c && c==d){
      ans+=i;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
n,d = gets.split.map(&:to_i)
dots = []
n.times {dots << gets.split.map(&:to_i)}
ans = 0
(0...n-1).each do |i|
  (i+1..n-1).each do |j|
    l = 0
    [dots[i],dots[j]].transpose.each {|a,b| l += (a-b)**2}
    ans += 1 if Integer.sqrt(l)**2 == l
  end
end
puts ans


Measured memory_bytes: 14268
#include<cstdio>
int a[10000], b[10000];
int main() {
	int n, i;
	long long ashort = 0, bshort = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	for (i = 0; i < n; i++) {
		scanf("%d", &b[i]);
		if (a[i] > b[i])bshort += a[i] - b[i];
		else ashort += (b[i] - a[i]) / 2;
	}
	if (ashort >= bshort)printf("Yes");
	else printf("No");
	return 0;
}

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

#define ll long long
#define lp(i,n) for(int i=0; i<n; i++)
#define pb push_back
const long double pi=3.141592654;
#define OSOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;


ll inv[100000],fact[100000],mod = 1e9+7;
ll fp(ll base, ll exp)
{
	if (exp == 0)
		return 1;
	ll ans = fp(base, exp / 2);
	ans = (ans * ans) % mod;
	if (exp % 2 != 0)
		ans = (ans * (base% mod)) % mod;
	return ans;
}
void calcFacAndInv(ll n)
{
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = (i * fact[i - 1]) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
	return (fact[n] * inv[n - r]) % mod;
}

int main()
{
	OSOS
	calcFacAndInv(9999);
	ll n; cin>>n;
	vector<string>v;
	string sp="",sq="";
	int q[n],p[n],tmp[n];
	for(int i=0; i<n; i++)
	{
		cin>>p[i];
		sp+=to_string(p[i]);
		tmp[i]=p[i];
	}
	for(int i=0; i<n; i++)
	{
		cin>>q[i];
		sq+=to_string(q[i]);
	}
	//cout<<sp<<" "<<sq<<"\n";
	sort(tmp,tmp+n);
	do{
		string s = "";
		for(int i=0; i<n; i++)
		{
			s+=to_string(tmp[i]);
		}
	//	cout<<s<<"\n";
	v.pb(s);
	}while(next_permutation(tmp,tmp+n));
	sort(v.begin(),v.end());
	int qc=0 , pc=0;
	for(int i=0; i<(int)v.size();i++)
	{
		if(v[i] == sq)
			qc=i+1;
		if(v[i] == sp)
			pc = i+1;
	}
	cout<<abs(qc-pc);
}


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

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

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
/*vector<int> d(N+1,-1);

//頂点xとの各点との最短距離を求める
void bfs(int x,Graph &G){
  d[x] = 0;
  queue<<int> que;
  que.push(x);

  // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
}*/

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N){
    cin >> a[i];
  }
  vector<int> num(100000 + 5);
  rep(i,N){
    num[a[i]]++;
    num[a[i]+1]++;
    if(a[i] >=1) num[a[i]-1]++;
  }
  int ans = 0;
  rep(i,num.size()){
    ans = max(ans,num[i]);
  }
  cout << ans << endl;
 }


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

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int A  = keyboard.nextInt();
		int P  = keyboard.nextInt();
        
		System.out.println((A*3 + P)/2);
		keyboard.close();	
	}
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a != 2 && b != 2) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 23508
from collections import deque
def MI(): return map(int, input().split())
def bfs(field,s):
  q=deque([(0,s)])
  MOVE=[(-1,0),(0,-1),(0,1),(1,0)]
  d,i,j=-1,-1,-1
  dist=[[-1]*W for i in range(H)]  
  while q:
    d,(i,j)=q.popleft()
    if dist[i][j]!=-1:
      continue
    dist[i][j]=d
    for di,dj in MOVE:
      ni=i+di
      nj=j+dj
      if not 0<=ni<H or not 0<=nj<W:
        continue
      if field[ni][nj]=='#':
        continue
      if dist[ni][nj]!=-1:
        continue
      q.append((d+1,(ni,nj)))
  return d,i,j
H,W=MI()
field=[input() for _ in range(H)]
ans=0
for i in range(H):
  for j in range(W):
    if field[i][j]=='.':
      d,i,j=bfs(field,(i,j))      
      ans=max(ans,d)
print(ans)

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

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

class UnionFind
{
  private:
    vector<int> par;
    vector<int> sizes;

  public:
    UnionFind(int N) : par(N), sizes(N, 1)
    {
        rep(i, N) par[i] = i;
    }

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

        return par[x] = find(par[x]);
    }

    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);

        if (x == y)
            return;

        if (sizes[x] < sizes[y])
            swap(x, y);

        par[y] = x;
        sizes[x] += sizes[y];
    }

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

    int size(int x)
    {
        return sizes[find(x)];
    }
};

int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);
    map<string, int> mp;
    rep(i, N)
    {
        string a;
        int x;
        cin >> a >> x;
        vec[mp[a] = i] = x;
    }

    UnionFind uf(N);

    int M; 
    cin >> M;
    rep(i, M) 
    {
        string s, t;
        cin >> s >> t;
        if(!uf.same(mp[s], mp[t])) uf.unite(mp[s], mp[t]); 
    }

    rep(i, N) vec[uf.find(i)] = min(vec[uf.find(i)], vec[i]);

    int ans = 0;

    rep(i, N) ans += vec[uf.find(i)];

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


Measured memory_bytes: 3856
<?php
error_reporting(0);
//list($Q,$H,$S,$D) = explode(" ",trim(fgets(STDIN)));
$A = trim(fgets(STDIN));
$len=strlen($A);
$result=0;
/*
for($i=0;$i<$len;$i++) {
  for($j=$i;$j<$len;$j++) {
    if ($j==$i) continue;
    if ($A[$j]!=$A[$i]) {
      $result++;
    }
  }
}
printf("%d\n",$result+1);
 */
$ret=0;
$chk=array();
for($i=0;$i<$len;$i++) {
  $ret+=$i;
  if (isset($chk[$A[$i]])) {
    $same+=$chk[$A[$i]];
    $chk[$A[$i]]++;
  }
  else {
    $chk[$A[$i]]=1;
  }
}
printf("%d\n",$ret+1-$same);


Measured memory_bytes: 3956
//invincible M15
//IIT-(ISM)Dhanbad
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define pi  3.141592653589793238462643383279
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 1000000007;
/*------------------------------------- THE GAME IS ON ---------------------------------------------*/
void solve()
{
     ll n;
     cin>>n;
     vector<ll>v(n),pref(n);
     for(int i=0;i<n;i++)cin>>v[i];
     pref[0]=v[0];
     for(int i=1;i<n;i++)
     {
            pref[i]=pref[i-1]+v[i];
     }
     ll ans=0;
     for(int i=0;i<n;i++)
     {
           ll z=(pref[n-1]-pref[i])%M;
           ans+=v[i]*z;
           ans%=M;
     }
     cout<<ans<<endl;
       
}
int32_t main()
{
   high_functioning_sociopath
   ll t=1;
   //cin>>t;
   while(t--)
   {
      solve();
   }
}

Measured memory_bytes: 6368
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
int main() {

	string S;
	int change = 0;

	cin >> S;

	for (int i = 0; i < S.size() - 1; i++) {

		if (S[i] != S[i + 1])change++;

	}

	cout << change << endl;

	return 0;
}

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

char s[10];

int main(){
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<len-1;i++){
		if(s[i]=='A' && s[i+1]=='C'){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
 
 
int main()
{
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
 
  sort(l.begin(), l.end());
 
  int ans = 0;
 
  for (int i = 0; i < n;i++){
    for (int j = i + 1; j < n;j++){
      for (int k = j + 1; k < n; k++)
      {
        if(l[i]==l[j] || l[j]==l[k])
          continue;
        if (l[i] + l[j] > l[k])
        {
          if(l[i]!=l[j] || l[j]!=l[k])
            ans++;
        }
      }
    }
  }
 
    cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3552
'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0])
    const K = parseInt(input[1])
    const x = input[2].split(' ').map(v => parseInt(v))
    let sum = 0
    x.forEach(v => {
        let b = Math.abs(K - v)
        if(v < b){
            sum += v * 2
        }else{
            sum += b * 2
        }
    })
    console.log(sum)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21064
n = int(input())
a = []
a = list(map(int, input().split()))
b = []
b = list(map(int, input().split()))
m = 0
for i in range(1,n):
    a[i] += a[i-1]
    b[n-i-1] += b[n-i]
for i in range(0,n):
    if  a[i] + b[i] > m:
        m =  a[i] + b[i]
print(m)


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

int main(){
    ll x;
    cin>>x;
    if(x%11>6)cout<<x/11*2+2<<endl;
    else if(x%11==0)cout<<x/11*2<<endl;
    else cout<<x/11*2+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int f(int a){
    if(a < 0){
        return a * -1;
    }
    return a;
}

int main(){
    int n, l;
    scanf("%d%d", &n, &l);
    int a = l;
    int sum = 0;
    for(int i=2; i<=n; i++){
        int b = l+i-1;
        if(f(b) < f(a)){
            sum += a;
            a = b;
        }else{
            sum += b;
        }
    }
    printf("%d", sum);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, m; std::cin >> n >> m;
    std::vector<std::vector<int>> edg(n);
    for (int i = 0; i < m; i++) {
        int a, b; std::cin >> a >> b;
        a--; b--;
        edg[a].push_back(b);
        edg[b].push_back(a);
    }
    std::vector<int> dist(n, 1e9);
    dist[0] = 0;
    std::deque<int> que;
    que.push_back(0);
    while (!que.empty()) {
        int pos = que.front();
        que.pop_front();
        for (int u : edg[pos]) {
            if (dist[u] <= dist[pos] + 1) continue;
            dist[u] = dist[pos] + 1;
            que.push_back(u);
        }
    }
    bool ok = true;
    for (int i = 0; i < n; i++) ok &= dist[i] < 1e9;
    if (!ok) {
        std::cout << "No" << std::endl;
        return 0;
    }
    std::cout << "Yes" << std::endl;
    for (int i = 1; i < n; i++) {
        for (int u : edg[i]) {
            if (dist[u] == dist[i] - 1) {
                std::cout << u + 1 << std::endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 10268
#include<queue>
#include<cstdio>
int main()
{
	char a[12],b[12],c[12];
	int diff = 'A' - 'a';
	scanf("%s%s%s",a,b,c);
	a[0] += diff; b[0] += diff; c[0] += diff;
	printf("%c%c%c",a[0],b[0],c[0]);
	return 0;
}

Measured memory_bytes: 128
N=int(input())
for i in range(N):
    x,y,z=map(int,input().split())
    if x**2+y**2==z**2:
        print("YES")
    elif x**2+z**2==y**2:
        print("YES")
    elif y**2+z**2==x**2:
        print("YES")
    else:
        print("NO")
        



Measured memory_bytes: 5596
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(int j=0;j<n/2;j++){
            int sub;
            sub=a[j];
            a[j]=a[n-j-1];
            a[n-j-1]=sub;
        }
        for(int k=0;k<n;k++){
            if(k<n-1){
           System.out.print(a[k]+" ");
           }
            if(k==n-1){
                System.out.println(a[k]);
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26264
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;
int32_t X[1000];
int32_t Y[1000];
int32_t P[1000];//木
std::vector<int32_t> C[1000];//木
void input_tree()
{
	in >> N;
	for (int32_t i = 1; i <= N - 1; ++i)
	{
		int p;
		in >> p; ; --p;
		P[i] = p;
		C[p].push_back(i);
	}
}

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}
int32_t dp[1000][5001];//頂点、他色重さを最小に
int32_t DP(int i, int w, int V)
{
	if (i >= C[V].size()) {
		return (w>=0)?0:50001000;
	}
	if (w < 0) {
		return 50001000;
	}
	if (dp[i][w] != -1) {
		return dp[i][w];
	}
	return dp[i][w] = std::min(DP(i + 1, w - X[C[V][i]], V)+Y[C[V][i]], DP(i + 1, w - Y[C[V][i]], V)+ X[C[V][i]]);
}

bool func(int i)
{
	if (C[i].empty()) {
		return true;
	}
	for (auto& c : C[i])
	{
		if (!func(c)) { return false; }
	}
	for (int32_t j = 0; j < C[i].size(); j++)
	{
		fill_all(dp[j], -1);
	}
	Y[i] = DP(0, X[i], i);
	return Y[i]< 50001000;
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	input_tree();
	for (int32_t i = 0; i < N; i++)
	{
		in >> X[i];
	}
	if (N == 1) {
		out << "POSSIBLE" << endl; return 0;
	}

	out << (func(0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;


	return 0;
}
#endif

Measured memory_bytes: 20472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

bool cub[500][500][500];
void solve(int n, int h){
    rep(i, n) rep(j, n) rep(k, n) cub[i][j][k] = true;

    string c;
    int a, b;
    rep(i, h){
        cin >> c >> a >> b;
        a--; b--;
        if(c == "xy") {
            rep(i, n) cub[a][b][i] = false;
        }else if(c == "xz"){
            rep(i, n) cub[a][i][b] = false;
        }else{
            rep(i, n) cub[i][a][b] = false;
        }
    }

    int ans = 0;
    rep(i, n) rep(j, n) rep(k, n) ans += cub[i][j][k];
    pr(ans);
    return;
}

int main()
{
    int n, h;
    while(cin >> n >> h){
        if(n==0 && h==0) break;
        solve(n, h);
    }
    return 0;}


Measured memory_bytes: 125088
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, H; 
  cin >> N >> H;

  vector<int> A(N), B(N);
  REP(i, N) cin >> A[i] >> B[i];

  sort(ALL(A), greater<>());
  sort(ALL(B), greater<>());

  vector<int> sum(N+1, 0);
  REP(i, N) sum[i+1] += sum[i]+B[i];

  int ans = INF;
  REP(i, N+1){
    if(H-sum[i] <= 0){
      chmin(ans, i);
      break;
    }
    chmin(ans, i+(H-sum[i]+A[0]-1)/A[0]);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 2560
object Main extends App {
	val s = scala.io.StdIn.readLine.toList.toArray

	val t1 = s.take(2).mkString.toInt
	val t2 = s.takeRight(2).mkString.toInt

	if(0 < t1 && t1 < 13 && 0 < t2 && t2 < 13){
		println("AMBIGUOUS")
	}else if(0 < t1 && t1 < 13){
		println("MMYY")
	}else if(0 < t2 && t2 < 13){
		println("YYMM")
	}else{
		println("NA")
	}

}

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int maxv = *max_element(d.begin(), d.end());
    int count = 0;
    for (int i = 1; i <= maxv; i++) {
        if (i < d[0]) continue;
        int p = upper_bound(d.begin(), d.end(), i) - d.begin();
        if (p == N - p) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 640
(defun split-and-parse-integer (string)
  (loop for i = 0 then (1+ j)
    as j = (position #\Space string :start i)
    collect (parse-integer (subseq string i j))
     while j))

(defparameter n (read))
(defparameter k (read))
(defparameter lst (split-and-parse-integer (read-line)))
(princ (let ((sorted-lst (subseq (sort (copy-list lst) #'<)0 k ))
      )
  (loop for i
     in sorted-lst 
     sum i
       )
))

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

public class Main {
    private static Scanner in;

    private static int n;
    private static int[] h;
    private static int[] dp;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        
        n = in.nextInt();
        h = new int[n];
        dp = new int[n-1];

        Arrays.fill(dp, -1);

        for(int i=0; i<n; i++) h[i] = in.nextInt();

        System.out.println(solve(0));


    }

    public static int solve(int i) {
        if (i==n-1) return 0;

        if (dp[i]!=-1) return dp[i];

        return dp[i]=Math.min(Math.abs(h[i+1]-h[i])+solve(i+1), i+2<n?Math.abs(h[i+2]-h[i])+solve(i+2):(int)1e9);

    }

}

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

int main(){
  int a,b;
  cin >> a >>b;
  int ans = 0;
  
  ans = (a+b-3)/(a-1);
  cout << ans << endl;
  return 0;
}

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

int main(){
  int N, L;
  cin >> N >> L;
  vector<string> vec(N);
  for(int i = 0; i < N; i ++){
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  
  for(int i = 0; i < N; i ++){
    cout << vec[i];
  }
  
}

  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
using namespace std;
ll A,B,n,m,ans;
int main(){
	cin>>A>>B;n=__gcd(A,B);m=sqrt(n);
	for(ll i=2LL;i<=m;i+=1LL){
		if(n%i!=0)continue;
		ans+=1LL;while(n%i==0)n/=i;
	}
	printf("%lld\n",ans+(n==1?1:2));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(int, a, b, c);
	out(std::max({ a,b,c }) * 9 + a + b + c);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <cstring>

using namespace std;
const int INF = (1<<30);
typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for (int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair

ll ans = 0;
ll a[2000011];
int main() 
{
   int n;
   cin>>n;
   rep(i,n) {
       cin>>a[i];
       if(i) a[i]+=a[i-1];
   }
    sort(a,a+n);
    int isSame=0;
    ll l=1;
    rep(i,n){
        if(a[i]==0) ans++;

        if(i){
          if(a[i]==a[i-1]){
             l++;
          }else{
             ans+=((l*(l-1))/2);
             l=1;
          }
         }
    }
    ans+=(l*(l-1))/2;
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    a = min(a, w - a);
    b = max(b, h - b);

    if(a * h > b * w){
        cout << "No" << endl;
        return 0;
    }
    a = max(a, w - a);

    ll m[h][w];
    ll hc[h];
    ll wc[w];

    rep(i, 0 ,h){
        hc[i] = a;
    }
    rep(i, 0 ,w){
        wc[i] = b;
    }
    rep(i, 0, h){
        rep(j, 0, w){
            if(hc[i] && wc[j]){
                m[i][j] = 1;
                hc[i]--;
                wc[j]--;
            }else{
                m[i][j] = 0;
            }
        }
    }

    rep(i, 0, h){
        rep(j, 0, w){
            cout << m[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 9088
#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];
	}

	for (int i = 0; i < N; i++) {
		if (A[i] % 2 == 0) {
			if (A[i] % 3 != 0 && A[i] % 5 != 0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}

	cout << "APPROVED" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000000
#define VMAX 10000

void CountingSort(unsigned short X[],unsigned short Y[]);

int C[VMAX + 1];
int n;

int main(){
  unsigned short *X,*Y;
  int i;

  scanf("%d",&n);

  X = malloc(sizeof(short) * n + 1);
  Y = malloc(sizeof(short) * n + 1);

  for(i = 0;i < n;i++){
    scanf("%hu",&X[i + 1]);
  }

  CountingSort(X,Y);

  for(i = 1;i <= n;i++){
    if(i > 1){
      printf(" ");
    }
    printf("%u",Y[i]);
  }
  printf("\n");

  free(X);
  free(Y);

  return 0;
}

void CountingSort(unsigned short X[],unsigned short Y[]){
  int i,j;
  
  for(i = 0;i <= VMAX;i++){     
    C[i] = 0;
  }
  for(j = 1;j <= n;j++){                     /*C[i]にiの出現数を記録する*/
    C[X[j]]++;
  }
  for(i = 1;i <= VMAX;i++){      /*i以下の数の出現数を記録する*/
    C[i] = C[i] + C[i-1];
  }
  for(j = 1;j <= n;j++){
    Y[C[X[j]]] = X[j];
    C[X[j]]--;
  }

}



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

int main(){
  int A, B;
  cin >> A >> B;
   
  /*
  A + n(A-1) >= B
  n >= (B-A)/(A-1)
  欲しい答えはこの n+1
  */
  cout << (B+A-3)/(A-1) << endl;
  return 0;
}

Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let a: usize = sc.read();
    println!("{}", a + a * a + a * a * a);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2168
import java.util.Scanner;

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

    //input
    int[] numArray = new int[5];
    for(int i = 0; i < numArray.length; i++){
      numArray[i] = sc.nextInt();
    }

    //output
    for(int i = 0; i < numArray.length; i++){
      if( numArray[i] == 0 ){
        System.out.println(i+1);
        break;
      }
    }

  }
}


Measured memory_bytes: 26856
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64
    }

    println!("{}", if n/100%10==n%10 {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i
k = gets.to_i
antena = [a,b,c,d,e]
if antena.sort[-1]-antena.sort[0] > k
   puts(":(")
else
   puts("Yay!")
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
	
		int tap = 1;
		int count = 0;
		while(tap < b) {
			tap += a - 1;
			count++;
		}
		
		System.out.println(count);
	}
}


Measured memory_bytes: 23124
n=gets.to_i
r=0
a,b,c=$<.map{|e|[0]+e.split.map(&:to_i).sort+[Float::INFINITY]}
(1..n).each{|z|
i=(0..n+1).bsearch{|i|a[i]>=b[z]}-1
k=(0..n+1).bsearch{|k|b[z]<c[k]}
r+=i*(n+1-k)
}
p r

Measured memory_bytes: 33956
import java.io.*
import java.util.*

fun solve(N: Long){
    var n = 1
    while(n <= N){
        n = n shl 1
    }
    println(n shr 1)

    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    solve(N)
}



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

bool isprime(int x) {
	for (int i = 2;i < (int)sqrt(x);++i) {
		if (x % i == 0) {
			return false;
		}
	}
	return true;
}

int main() {
	int X;
	cin >> X;
	while (true) {
		if (isprime(X)) {
			cout << X << endl;
			return 0;
		}
		X++;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define EVEL 1

#ifndef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
    int N;
    string S;
    int ans,temp;
int main(){
    cin>>N>>S;
    for(auto x:S){
        if(x=='I')temp++;
        else temp--;
        ans=max(ans,temp);
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef pair<int,int> p;
vector<p> G[100000];
vector<int> color(100000);

int N;

void dfs(int k,int c){
  color[k]=c;
  for(int i=0;i<G[k].size();i++){
    if(color[G[k][i].first]==0){
      if(G[k][i].second%2==1) dfs(G[k][i].first,-c);
      else dfs(G[k][i].first,c);
    }
  }
}

int main(){
  cin >> N;
  for(int i=0;i<N-1;i++){
    int u,v,w;
    cin >> u;
    cin >> v;
    cin >> w;
    u=u-1;
    v=v-1;
    p vw(v,w);
    p uw(u,w);
    G[u].push_back(vw);
    G[v].push_back(uw);
  }
  for(int i=0;i<N;i++){
    color.at(i)=0;
  }
  dfs(0,1);
  for(int i=0;i<N;i++){
    if(color[i]==-1) cout << '0' << endl;
    else cout << '1' << endl;
  }
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, r;
    cin >> n >> r;
    cout << r + max(0, 100 * (10 - n)) << endl;
    return 0;
}


Measured memory_bytes: 256
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define int long long
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 1e9 +7;
int t,n,m,k,x,y;
 
inline void add(int& x, int y)
{
	x += y;
	if (x >= MOD) x -= MOD;
}

inline void sub(int& x, int y)
{
	x -= y;
	if (x < 0) x += MOD;
}

inline int mult(int x, int y)
{
	return x * (long long) y % MOD;
}


ll modpow(int n,int p){
    if(p==0) return 1;
    if(p%2) return (modpow(n,p-1)*1LL*n)%MOD;
    else{
        ll half=modpow(n,p/2);
        return (half*1LL*half)%MOD;
    }
}

ll modinv(int d){
    return modpow(d,MOD-2);
}

int32_t main()
{
	IOS;
	cin>>n>>k;
	int ans=0;
	forsn(i,k,n+2){
		int mn=(i*(i-1))/2;
		int mx=(n*(n+1))/2 - ((n-i)*(n-i+1))/2;
		add(ans,(mx-mn+1)%MOD);
	}
	cout<<ans%MOD<<ln;
}


Measured memory_bytes: 3660
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect();
    let mut ans = 1;
    // zouka:1, gensyo:2
    let mut retu = 0;
    for i in 0..n - 1 {
        if retu == 0 {
            if a[i] < a[i + 1] {
                retu = 1;
            }
            if a[i] > a[i + 1] {
                retu = 2;
            }
        }
        if (retu == 1 && a[i] > a[i + 1]) || (retu == 2 && a[i] < a[i + 1]) {
            retu = 0;
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int K;
    cin >> K;
    int N = s.size();
    set<string> st;
    for (int i=0;i<N;i++){
        for (int j=0;j<K;j++){
            string t = s.substr(i,min(N-i,j+1));
            st.insert(t);
        }
    }
    string ans;
    for (auto it=st.begin();it!=st.end();it++){
        K--;
        if (K==0) {
            ans = *it;
            break;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 4832
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <regex>
#include <string>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

vector<string> S;

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

	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		S.push_back(s);
	}

	sort(S.begin(), S.end());
	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	cout << endl;


	return 0;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A*B<C*D){
    cout << C*D << endl;
  }
  else if(A*B>C*D){
    cout << A*B << endl;
  }
  else if(A*B==C*D){
    cout << A*B << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n,y;scanf("%d %d",&n,&y);
	for(int i=0;i<=n;i++){
	for(int j=0;j<=n-i;j++){
		if(y-(i*10000+j*5000+(n-i-j)*1000)==0){
			printf("%d %d %d\n",i,j,n-i-j);
			return 0;
		
	}}
}

	printf("%d %d %d\n",-1,-1,-1);
	return 0;
}

Measured memory_bytes: 128
/*
 *  Author : Jun_SH
 *  Solution for ABC 096 D
 */
#include<bits/stdc++.h>
using namespace std;
const int maxn= 56000;
int check[maxn];
int vis[maxn];
void init(){
    memset(vis,false,sizeof(vis));
    for(int i=2;i<=maxn;++i){
        if(vis[i])continue;
        for(int j=2*i;j<maxn;j+=i){
            vis[j]=true;
        }
    }
}
int n;
int main(){
    init();
    cin>>n;
    vector<int>ans;
    for(int i=11;i<maxn&&n;i+=5){
        if(!vis[i]){
            ans.emplace_back(i);
            n--;
        }
    }
    for(auto i:ans)
        cout<<i<<" ";
    cout<<endl;
}


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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll a,b;
    cin>>a>>b;
    if(b%a==0) cout<<a+b<<endl;
    else cout<<b-a<<endl;
}


Measured memory_bytes: 256
n = int(input())

count = 0

i = 1

count = 0
limit = 100

nums = [0] * n

for x in range(limit):
    for y in range(limit):
        for z in range(limit):
            cal =  (x + 1) ** 2 + (y + 1) ** 2 + (z + 1) ** 2 + (x + 1) * (y + 1) + (y + 1) * (z + 1) + (z + 1) * (x + 1)
            if(cal > n):
                break
            nums[cal - 1] += 1

for n in nums:
    print(n)

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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

bool is_prime(ll n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else if (n % 2 == 0) {
        return false;
    }
 
    for (ll i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

void solve() {
    int x;
    cin >> x;
    while (x < INF) {
        if (is_prime(x)) {
            cout << x << EOL;
            return;
        }
        x++;
    }
}
 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void rotate(int d[], int id2, int id4){
	int tmp = *d;
	d[0] = d[id2];
	d[id2] = d[5];
	d[5] = d[id4];
	d[id4] = tmp;
}

int main(){
	int n;
	while(cin >> n, n){
		int d[]={1,2,3,4,5,6},dir,rot=0,res=1;
		for(int i=0;i<n;i++){
			char s[9]; cin >> s;
			if(*s%6-4){
				dir=(*s-78?*s%5-1:0)+rot&3;
				dir=dir+1+(1-dir%2*2)*(dir/2);
				rotate(d, dir, 5-dir);
//				if(dir == 0) rotate(d, 1, 4);
//				if(dir == 1) rotate(d, 2, 3);
//				if(dir == 2) rotate(d, 4, 1);
//				if(dir == 3) rotate(d, 3, 2);
			} else rot+=*s+3;
			res+=*d;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        long x = Long.valueOf(line);
        x -= 6;
        System.out.println((long)Math.ceil(x/5.5)+1);
    }
}

Measured memory_bytes: 21204
"use strict";
// import bigInt from 'big-integer'

const Main = input => {
  input = input.trim().split("\n");
  const n = input[0];
  const array = input[1].split(" ");

  const map = new Map();
  let next = 1;
  for (let i = 0; i < n; i++) {
    const num = parseInt(array[i]);
    if (next === num) {
      if (!map.get(num)) {
        map.set(num, 1);
        next++;
      }
    }
  }

  console.log(map.size === 0 ? -1 : n - map.size);
};

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 45100
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long MOD = 1000000007;
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		
		// 計算
		long result = 0;
		long[] fact = fact(n, MOD);
		long[] invFact = invFact(fact, MOD);
		long maxSum = 0;
		long minSum = 0;
		for(int i = 0; i < n; i++){
		    long now = a[i];
		    maxSum += now*combination(i, k-1, fact, invFact, MOD)%MOD;
		    minSum += now*combination(n-(i+1), k-1, fact, invFact, MOD)%MOD;
		}
		result = maxSum + MOD - minSum;
		result %= MOD;
		
		// 出力
		System.out.println(result);
	}
	public static long pow(long a, long n, long MOD) {
	    long res=1;
	    while (n>0) {
	        if ((n-n/2*2)==1) {
	            res=(res*a)%MOD;
	        }
	        a=(a*a)%MOD;
	        n>>=1;
	    }
	    return res%MOD;
	}
	
	public static long[] fact(int n, long MOD) {
	    long[] f = new long[n+1];
	    for(int i = 0; i < n+1; i++){
	        if(i == 0) f[i] = 1;
	        if(i > 0) f[i] = (f[i-1]*i)%MOD;
	    }
	    return f;
	}
	
	public static long[] invFact(long[] fact, long MOD) {
	    int len = fact.length;
	    long[] f = new long[len];
	    for(int i = 0; i < len; i++){
	        f[i] = pow(fact[i], MOD - 2, MOD);
	    }
	    return f;
	}
	
	public static long combination(int n, int k, long[] fact, long[] invFact, long MOD) {
		if(n < 0 || k < 0) return 0;
	    if(n < k) return 0;
	    long a = fact[n];
	    long b = invFact[k];
	    long c = invFact[n-k];;
	    return (((a*b)%MOD)*c)%MOD;
	}	
}


Measured memory_bytes: 50472