akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <functional>
using namespace std;

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

#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

VI X;
int N,K;

int main(){

	cin >> N >> K;
	X.resize(N);
	REP(i,N){
		int a;
		cin >> a;
		X[a-1]++;
	}
	sort(X.begin(),X.end(),greater<int>());
	long long ans = 0;
	REP(i,N){
		if(i<K)
			continue;
		ans += (long long)X[i];
	}

	cout << ans;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n,l;
  cin >> n >> l;
  vector<string > input(n);
  rep(i,n){
    cin>>input[i];
  }

  sort(input.begin(),input.end());
  string ans="";
  rep(i,n){
    ans += input[i];
  }
  cout << ans << endl;
  return 0;
    

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;
const int MAX = 100010;


ll inv[MAX];//逆元
void makeInv() {
	inv[1] = 1;
	FOR(i, 2, MAX) {
		inv[i]= MOD - inv[MOD%i] * (MOD / i) % MOD;
	}
}

//階乗のmod
ll FactMod(int n, int m) {
	ll x = 1;
	FOR(i, 1, n + 1) {
		x *= i;
		x %= m;
	}
	return x;
}

ll cum[MAX];//累積和
ll Ex[MAX];//ブロックiのコストがかかる回数の期待値
ll A[MAX];

int main() {

	int N; cin >> N;
	FOR(i,1, N+1) {
		cin >> A[i];
	}

	makeInv();
	ll fact = FactMod(N, MOD);

	cum[0] = 0;
	cum[1] = 1;
	FOR(i, 2, MAX) {
		cum[i] = (cum[i - 1] + inv[i]) % MOD;
	}

	FOR(i,1, N + 1) {
		Ex[i] = cum[i] - cum[0] + cum[N - i + 1] - cum[1];
		Ex[i] %= MOD;
	}

	ll ans = 0;
	FOR(i, 1, N + 1) {
		ans += Ex[i] * A[i];
		ans %= MOD;
	}
	ans *= fact;
	ans %= MOD;

	cout << ans << endl;
}




Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			int n = Integer.valueOf(sc.nextLine());
			int count = 0;

			for (int i = 1; i <= n; i++) {
				int content = sc.nextInt();
				if (i % 2 == 1 && content % 2 == 1) {
					count ++;
				}
			}

			System.out.println(count);


		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}


Measured memory_bytes: 36052
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    a.sort()
    x = list(set(a))
    if len(x) > 3:
        print("No")
    elif len(x) == 3:
        x1 = bisect_right(a, x[0]) - bisect_left(a, x[0])
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        x3 = bisect_right(a, x[2]) - bisect_left(a, x[2])
        if ((x[0] ^ x[1] ^ x[2]) == 0) and (x1 == x2 == x3):
            print("Yes")
        else:
            print("No")
    elif len(x) == 2:
        x1 = bisect_right(a, 0)
        x2 = bisect_right(a, x[1]) - bisect_left(a, x[1])
        if x1 * 2 == x2:
            print("Yes")
        else:
            print("No")
    elif len(x) == 1:
        if x[0] == 0:
            print("Yes")
        else:
            print("No")
    return

#B
def B():
    n, m = LI()
    if m % 2:
        print(-1)
        return
    edg = [[] for _ in range(n)]
    ins = defaultdict(int)
    c = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
        ins[a] += 1
        ins[b] += 1
    dag = [[] for _ in range(n)]
    q = deque()
    q.append((0, -1))
    for i in edg[0]:
        q.append((i, 0))
    while q:
        now, per = q.pop()
        if per == -1:
            continue
        if c[now]:
            pass
        
    for d in dag:
        if len(d) % 2:
            print(-1)
            return
    for num, d in enumerate(dag):
        for x in d:
            print(num + 1, x + 1)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 58992
#include<stdio.h>

int main(void) {
	int h[10];
	int i,j;
	
	for(i=0; i<10; i++) 
		scanf("%d", &h[i]);
	
	for(i=0;i<10;i++) {
		for(j=i; j<10; j++) {
			if(h[i] < h[j]) {
				int swap =h[i];
				h[i] = h[j];
				h[j] = swap;
			}
		}
	}
	
	for(i=0; i<3; i++)
		printf("%d\n", h[i]);	
	
	
	return 0;
}

Measured memory_bytes: 600
a = int(input())
mylist = input().split(" ")
mylist = [int(i) for i in mylist]
list2 = []
for i in range(a):
  c = sum(mylist[0:i])
  d = sum(mylist[i:a+1])
  list2.append(abs(c-d))
print(min(list2))

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll K;
const int N = 50;
ll ans [N];
const ll LIM = 1e16 + 1000;

int main()
{
	scanf("%lld",&K);

	FOR(i,0,N){
		ans [i] = N - 1;
		ans [i] += K / N;
		if(i < K % N){
			ans [i] += N;
		}
		ans [i] -= K % N;
	}
	printf("%lld\n",N);
	FOR(i,0,N){
		printf("%lld\n",ans [i]);
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
int main() {
	int n, k; std::cin >> n >> k;
	std::vector<int> number(n); for (auto& a : number) std::cin >> a;
	std::vector<bool> memo(k + 1, false);
	for (auto i = 0; i <= k; ++i) {
		if (!memo[i]) {
			for (const auto& a : number) if (i + a <= k) {
				memo[i + a] = true;
			}
			else break;
		}
	}
	if (memo.back()) std::cout << "First" << std::endl;
	else std::cout << "Second" << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, W;
  string DE[4] = {"maerd","esare","resare","remaerd"};
  int L, N, K;
  cin >> S;
  L = S.size();
  N = L;
  bool H = true;
  reverse(S.begin(), S.end());
  
  
  while(H){
     W = "";
     bool H2 = true;
     if(N == 0){
     break;
     }
     if(N < 5){
     H = false;
     break;
     }
    
     if(S.at(L - N) == 'm' || S.at(L - N) == 'e'){
        for(int i = 0;i < 5;i++){
        W = W + S.at(L - N + i);
        }
        if(W == DE[0] || W == DE[1]){
        N = N - 5;
        H2 = false;
        }
     }
    
     else if(S.at(L - N) == 'r'){
        if(S.at(L - N + 2) == 's'){
        K = 1;
        }
        else if(S.at(L - N + 2) == 'm'){
        K = 2;
        }
        else{
        H = false;
        break;
        }
        for(int i = 0;i < 5 + K;i++){
        W = W + S.at(L - N + i);
        }
        if(W == DE[1 + K]){
        N = N - 5 - K;
        H2 = false;
        }
     }
     if(H2){
     H = false;
     }
  }
 
  if(H){
  cout << "YES" << endl;
  }
  else{
  cout << "NO" << endl;
  }
}

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

int f[101];
int main(void){
 int a,b,c; cin >> a >> b >> c;
 f[a] = 1; f[b] = 1; f[c] = 1;
 int cnt = 0;
 for(int i=0;i<=100;i++) if (f[i]) cnt++;
 cout << cnt << endl;
 return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())  # 標準入力
D = map(int, input().split())  # 嫌いな数字のリスト
D_str = list(map(str, D))
m = N

while True:
    for n in str(m):
        if n in D_str:
            break
    else: # breakされなかったら実行される
        print(m)
        break
    m += 1

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

int main(){
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  
  int m = max({a1, a2, a3});
  int s = min({a1, a2, a3});
  
  int ans = m - s;
  cout << ans << endl;
}
  
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int N, X;
	int sum = 0;
	int ans;
	vector<int> m;
	cin >> N >> X;
	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		sum += tmp;
		m.push_back(tmp);
	}

	X -= sum;
	ans = N;
	ans += X / (*min_element(m.begin(), m.end()));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define n_max 20
#define q_max 200

int n_array[n_max];
int q_array[q_max];
int solve(int i, int m);
	int n, q;

int main(void){
	int i, j,  sum =0;
	int ans;
	scanf("%d", &n);
	for(i =0;i<n;i++){
		scanf("%d", &n_array[i]);
	}
	
	scanf("%d", &q);
	for(i =0;i<q;i++){
		scanf("%d", &q_array[i]);
	}
	
	for(i = 0;i<q;i++){
		
		
		if(solve(0, q_array[i])){
			printf("yes\n");
		}
		else{printf("no\n");}
	}
	
	return 0;
}
	
int solve(int i, int m){
	int res =0;
	if(m ==0){
		return 1;
	}
	if(i >= n){
		return 0;
	}
	
	res = solve(i+1 , m) || solve(i+1, m-n_array[i]);
	return res;
}


Measured memory_bytes: 2080
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll,ll>;
ll modpow(ll x, ll y);
const ll mod = pow(10, 9) + 7;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    ans = modpow(10, n) - 2*modpow(9, n) + modpow(8, n);
    ans %= mod;
    ans = (ans + mod)%mod;
    cout << ans << endl;
}

ll modpow(ll x, ll y){
    ll r = 1;
    for(ll i = 0; i < y; i++){
        r *= x%mod;
        r %= mod;
    }
    return r%mod;
}

Measured memory_bytes: 3624
// 2011/08/16 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string srv;
		cin >> srv;
		if(srv=="0")		// ツ閉カツ篠堋療ア
			break;

		int ptA = 0;
		int ptB = 0;
		for(int i=1; i<srv.size(); i++)
			if(srv[i]=='A')
				ptA++;
			else
				ptB++;

		if(ptA>ptB)
			ptA++;
		else
			ptB++;

		cout << ptA << ' ' << ptB << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll fact[100005];

void init(){
  fact[0] = fact[1] = 1;

  for(ll i = 2; i <= 100000; i++)
    fact[i] = fact[i-1] * i % mod;

}

ll solve(ll x, ll y){
  if(x < y)return 0;
  if(y < x - 1)return 0;

  return fact[x] * fact[y] % mod;
}

int main(){


  ll n, m;

  cin >> n >> m;

  init();

  cout << (solve(n, m) + solve(m,n) )% mod << '\n';


  return 0;
}


Measured memory_bytes: 1024
# https://cs.stackexchange.com/questions/93030/algorithm-for-checking-if-a-list-of-integers-is-pairwise-coprime

import math
n = int(input())
nums = list(map(int, input().split()))

gcd_ = nums[0]
for num in nums[1:]:
    gcd_ = math.gcd(gcd_, num)

if gcd_ >= 2:
    print('not coprime')
    exit()



def smallest_divisor(num, start):
    if num == 1:
        raise ValueError("error!")
    d = start
    while d * d <= num:
        if num % d == 0:
            return d
        d += 1
    return num


prime_set = set()

for num in nums:
    if num == 1:
        continue

    soinsuu = set()
    
    warareru = num
    start = 2
    while True:
        divi = smallest_divisor(warareru, start)
        soinsuu.add(divi)
        warareru = warareru // divi
        start = divi
        if warareru == 1:
            break
    # print(soinsuu)
    if soinsuu & prime_set:
        print('setwise coprime')
        exit()
    else:
        prime_set |= soinsuu

print('pairwise coprime')


Measured memory_bytes: 205396
import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
 
dp = [0] * n
 
dp[0] = 0
dp[1] = dp[0] + abs(arr[1] - arr[0])
 
for i in range(2, len(arr)):
	dp[i] = min(dp[i - 1] + abs(arr[i - 1] - arr[i]), dp[i - 2] + abs(arr[i - 2] - arr[i]))
 
print(dp[len(arr) - 1])

Measured memory_bytes: 14016
#include <iostream>
#include <set>
#include <map>
using namespace std;

bool check(const string& s, const string& t) {
  set<char> chars(begin(s), end(s));
  for (char c : t) {
    if (chars.count(c) == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  string s, t;
  cin >> s >> t;
  if (check(s, t)) {
    map<char, int> index, next[s.size()];
    for (int i = s.size() - 1; i >= 0; --i) {
      index[s[i]] = s.size() + i;
    }
    for (int i = s.size() - 1; i >= 0; --i) {
      index[s[i]] = i;
      next[i] = index;
    }
    int64_t result = 0;
    for (int64_t i = 0; i < t.size(); ++i) {
      result += next[result % s.size()][t[i]] - result % s.size() + 1;
    }
    cout << result;
  } else {
    cout << -1;
  }
  return 0;
}

Measured memory_bytes: 127380
# frozen_string_literal: true

Inf = 100_000_000_000
$n = gets.chomp.to_i
$a = gets.split.map(&:to_i)
def limits(b)
  min = Inf
  max = -Inf
  $n.times do |i|
    diff = $a[i] - (b + i + 1)
    min = diff if diff < min
    max = diff if diff > max
  end
  [min, max]
end

def diff(b)
  sum = 0
  $n.times do |i|
    sum += ($a[i] - (b + i + 1)).abs
  end
  sum
end
lower, upper = limits(0)
l = (lower..upper).bsearch do |b|
  diff(b+1) - diff(b) > 0
end
puts diff(l)


Measured memory_bytes: 16012
s = input()
s = s[::-1]
t_list = ['dream','dreamer','erase','eraser']
t_list = [t[::-1] for t in t_list]
 
ans = 'NO'
i = 0
while i < len(s):  
  p = i
  for t in t_list:        
    if s[i:i+len(t)] == t:      
      i += len(t)
      if i == len(s):
        ans ='YES'
      break
  if p==i or ans=='YES':
    break
 
print(ans) 

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int line[2020];
int main(){
    int n, x, y;
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            if(i <= x){
                if(j <= x){
                    line[j-i]++;
                }
                else if(j >= y){
                    line[j-i+x-y+1]++;
                }
                else{
                    line[min(j-x, y-j+1)+x-i]++;
                }
            }
            else if(i >= y){
                line[j-i]++;
            }
            else{
                if(j >= y){
                    line[min(y-i, i-x+1)+j-y]++;
                }
                else{
                    line[min(j-i, y-j+i-x+1)]++;
                }
            }
        }
    }
    for(int i = 1; i < n; i++){
        printf("%d\n", line[i]);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; cin >> N >> M; 
	long long int P = 1e9+7; 
	int S[2019] = {}; int T[2019] = {}; 
	for(int i = 1; i <= N; i++){
		cin >> S[i]; 
	}
	for(int i = 1; i <= M; i++){
		cin >> T[i]; 
	}
	long long int dp[2019][2019] = {}; 
	for(int i = 0; i < 2019; i++){
		dp[i][0] = 1; dp[0][i] = 1; 
	}
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= M; j++){
			if(S[i] == T[j]) dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % P; 
			else dp[i][j] = (P + dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]) % P; 
		}
	}
	cout << dp[N][M] << endl; 
}

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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	int a, b;
	int sa;
	int dp[1000] = {};

	cin >> a >> b;

	sa = b - a;
	FOR(i, 1, 999) {
		dp[i] = dp[i - 1] + i;
	}
	FOR(i, 2, 999) {
		if (sa == dp[i] - dp[i - 1]) {
			cout << dp[i] - b << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 int H, W;
 int seen[10000][10000];
  char S[10000][10000];
vector<pair<ll, ll>> prime_factorize(ll n) { //素因数分解と各素数の個数
    vector<pair<ll, ll>> res;

    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i != 0)
        {
            continue;
        }
        int num = 0;
        
        while (n % i == 0)
        {
            ++num;
            n /= i;
        }
        res.push_back(make_pair(i, num));
       
    }
     if (n != 1) 
        {
            res.push_back(make_pair(n, 1));
        }
        return res;
        
} 
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
    return x / GCD(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void dfs(int st, int fi) {
  //  cout << st << " " << fi <<  endl;
    if (st < 0 || fi < 0 || st >= H || fi >= W)
    {
        return ;
    }
    if (S[st][fi] == '#')
    {
        return ;
    }

    if (seen[st][fi] == 1)
    {
        return ;
    }
    
    
    if (S[st][fi] == '.')
    {
        seen[st][fi] = 1;
    }
    

    dfs(st + 1, fi);
    dfs(st, fi + 1);
    dfs(st, fi - 1);
    dfs(st - 1, fi);
    
}
int main() {
    int N;
    cin >> N;
    vector<int> p(N + 1);
    p[1] = 0;
    for(int i = 2; i <= N; i++) {
        int n = i;
        vector<pair<int, int>> b;
       for(int j = 2; j * j <= n; j++) {
           if(n % j != 0) continue;
           int ex = 0;

           while(n % j == 0) {
               ex++;
               n /= j;
           }

           b.push_back({j, ex});
       }
       if(n != 1) b.push_back({n, 1});

       for(auto v : b) {
           p[v.first] += v.second;
       }
    }


    /*for(int i = 1; i <= N; i++)
        cout << p[i] << endl;*/

    ll ans = 1;

    for(int i = 2; i <= N; i++) {
        ans *= (p[i] + 1);
        ans %= 1000000007;
    }

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


Measured memory_bytes: 3532
a=list(map(int,input().split()))
b=list(range(a[1],a[0]+a[1]))
c=min(b)
d=max(b)
if c==0 or d==0:
    e=0
elif c/d>0:
    if c>0:
        e=c
    else:
        e=d
else:
    e=0
print(sum(b)-e)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    ll n, d; cin >> n >> d;
    int count = 0;
    REP(i, 0, n){
        ll a, b; cin >> a >> b;
        if((d * d) >= (a * a + b * b)){
            count++;
        }
    }
    cout << count << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  sort(ALL(a));

  int ok = n, ng = -1;
  while(abs(ok-ng) > 1) {
    int mid = (ok+ng) / 2;
    vector<ll> vec = a;
    rep(i, mid) vec[i+1] += vec[i];
    bool f = true;
    for(int i = mid; i < n-1; ++i) {
      if(vec[i+1] <= 2*vec[i]) vec[i+1] += vec[i];
      else {
        f = false;
        break;
      }
    }
    if(f) ok = mid;
    else ng = mid;
  }
  cout << n-ok << endl;
}

Measured memory_bytes: 4748
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int n, m;
	cin >> n >> m;
	int ans = 1900 * m + 100 * (n - m);
	ans *= pow(2, m);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

typedef struct{
  int num,id;
  char mark;
} card;

void swap(card *a,card* b){
  card t=*a;*a=*b,*b=t;
}

int partition(card *A,int p,int r){
  int x=A[r].num,i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j].num<=x){
      i=i+1;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}

void quickSort(card *A,int p,int r){
  if(p<r){
    int q=partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

int isStable(card *a,int n){
  int i;
  for(i=0;i<n-1;i++){
    if(a[i].num==a[i+1].num && a[i].id>a[i+1].id)return 0;
  }
  return 1;
}

int main(void){

  int n,i;
  card A[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&A[i].mark,&A[i].num);
    A[i].id=i;
  }
  quickSort(A,0,n-1);

  printf("%s\n",isStable(A,n)?"Stable":"Not stable");
  for(i=0;i<n;i++)
    printf("%c %d\n",A[i].mark,A[i].num);
  
  return 0;
}

Measured memory_bytes: 1780
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
	int n;
	cin >> n;
	Vi A(n), B(n), C(n);
	rep(i, n)  cin >> A[i] >> B[i] >> C[i];

	Vii D(n, Vi(3, 0));
	//初期条件
	D[0][0] = A[0];  D[0][1] = B[0];  D[0][2] = C[0];
	//dp
	for (int i = 1; i < n; i++) {
		D[i][0] = max(D[i - 1][1], D[i - 1][2]) + A[i];
		D[i][1] = max(D[i - 1][0], D[i - 1][2]) + B[i];
		D[i][2] = max(D[i - 1][0], D[i - 1][1]) + C[i];
	}
	cout << max(D[n - 1][0], max(D[n - 1][1], D[n - 1][2])) << endl;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll ans=0;
  string s;
  cin >> s;
  int j = s.size();
  int a[j] = {0};
  
  if(s[0]=='A'){a[0]=1;}
  if(s[1]=='A'){a[1]=a[0]+1;}
  
  for(int i=2; i<j; i++){
    if(s[i]=='A'){
      a[i]=a[i-1]+1;
    }
    
    if(s[i-1]=='B' && s[i]=='C'){
      ans += a[i-2];
      a[i] = a[i-2];
    }
  }

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

Measured memory_bytes: 1412
#include <iostream>
using namespace std;
int main()
{
	int a;
	cin>>a;
		//读入一个三位数，求出它当中有几个1.
	if(a==111){
		cout<<"3"<<endl;
	}	if(a==101||a==110)
			{
			cout<<"2"<<endl;
			}
			if(a==11)
				cout<<"2"<<endl;
			if(a==10)
				cout<<"1"<<endl;
				if(a==1)
					cout<<"1"<<endl;
			if(a==010||a==100)
				{
				cout<<"1"<<endl;
				}if(a==000)
					{
					cout<<"0"<<endl;
						}
	
	return 0;
	 } 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		char a=s[s.size()-1];
                string b=s;
		for(int j=0;j<s.size()-1;j++) s[j+1]=b[j];
                s[0]=a;
		if(s==t){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N,P=map(int,input().split())
xs=[]
ys=[]
dp=[[[1e9 for i in range(N+1)] for j in range(N+1)] for k in range(N+1)]
memo=[[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
    x,y=map(int,input().split())
    xs.append(x)
    ys.append(y)

for start in range(N):
    preuse=0
    for now in range(start,N+1):
        if(now==start):
            preuse=0
            memo[start][now]=0
        else:
            nx=max(0,xs[now-1]-preuse)
            preuse=max(0,ys[now-1]-nx)
            memo[start][now]=memo[start][now-1]+preuse


dp[0][0][0]=0
for now in range(N):
    for l in range(now+1):
        for score in range(N):
           dp[now+1][l][score+1]=min(dp[now+1][l][score+1],dp[now][l][score]+memo[l][now+1]-memo[l][now])
           dp[now+1][now+1][score]=min(dp[now+1][now+1][score],dp[now][l][score])

ans=0
for l in range(N+1):
    for score in range(N):
        if(dp[N][l][score]<=P):
            ans=max(ans,score)


print(ans)       

Measured memory_bytes: 22500
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define X first
#define Y second
using namespace std;

int main(){
	double a;
	while(cin >> a){
		if(cin.eof()) break;
		double sum = a;
		for(int i = 2; i <= 10; i++){
			if(i%2) a /= 3.0;
			else a *= 2.0;
			sum += a;
		}
		printf("%0.8f\n", sum);
	}
	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

const int N = 1010;
int a[N];

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++)	scanf("%d", &a[i]);
	
	sort(a, a + n);
	
	int ans = 0;
	for(int i = 0; i < k; i++)	ans += a[i];
	printf("%d\n", ans);
	return 0;
}

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

int main(){
    
    int a,b,k;
    cin >> a >> b >> k;
    int i = 101;
    int j = 0;
    while(j < k){
        i = i - 1;
        if(a % i == 0 && b % i == 0){
            j++;
        }
    }
    cout << i << endl;
    
    return 0;
}

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




int main(){
    int N;cin >> N;
    vector<int> t(N),v(N);
    LL T=0;
    for (int i = 0; i < N; i++) {
        cin >> t[i];
        T+=t[i];
        t[i]*=2;
    }
    for (int i = 0; i < N; i++) {
        cin >> v[i];
        v[i]*=2;
    }
    v.pb(0);
    t.pb(2);
    vector<vector<double>> dp(2*T+1,vector<double> (201,0.0));
    int c=0;
    for (int i = 0; i < 2*T; i++) {
        int lim=v[c];
        if(--t[c]==0){
            c++;
            lim=min(v[c],lim);
        }
        for (int j = 0; j < 201; j++) {
            if(dp[i][j]==0.0&&j!=0) continue;
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+j/4.);
            if(j<200) dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+j/4.+0.025);
            if(j>0) dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]+j/4.-0.025);
        }
        for (int j = lim+1; j < 201; j++) {
            dp[i+1][j]=0.0;

        }
    }
    cout << setprecision(10) << fixed << dp[2*T][0] << endl;
    return 0;
}



Measured memory_bytes: 64256
#include<bits/stdc++.h>
#define int long long
static const int INF = 1000000000000;
static const int MAX_N = 1e+6 +10;
using namespace std;

struct edge{
    int to,cost;
    edge(){}
    edge(int p1,int p2){
        to=p1;
        cost=p2;
    }
};

typedef pair<int,int> P;
vector<edge> G[MAX_N];
int D[MAX_N];

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(D,D+110,INF);
    D[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v=p.second;
        if(D[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e = G[v][i];
            if(D[e.to]>D[v]+e.cost){
                D[e.to] = D[v]+e.cost;
                que.push(P(D[e.to],e.to));
            }
        }
    }
}

signed main(){
    int n,m;
    while(n!=0&&m!=0){
        cin>>n>>m;
        for(int i=0;i<=110;++i){
            G[i].clear();
        }
        int cnt=m;
        while(cnt){
            int a,b,c,d,e;
            int f;
            cin>>f;
            if(f==0){
                cin>>a>>b;
                dijkstra(a);
                if(D[b]!=INF)cout<<D[b]<<endl;
                else cout<<-1<<endl;
            }
            else {
                cin>>c>>d>>e;
                G[c].push_back(edge(d,e));
                G[d].push_back(edge(c,e));
            }
            cnt--;
        }
    }
    return 0;
}

Measured memory_bytes: 26372
import java.util.ArrayList;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int worker_number = sc.nextInt();
        int[] worker_number_counter = new int[worker_number];

        for(int i = 0;i < worker_number-1;i++){
            worker_number_counter[sc.nextInt()-1] += 1;
        }
        for(int i : worker_number_counter){
            System.out.println(i);
        }
    }
}

Measured memory_bytes: 69464
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

const LL inf = 1000000000000000;

int main()
{
	
	LL N, W;
	cin >> N >> W;

	vector<LL> w(N), v(N);

	LL sm = 0;
	for (LL i = 0; i < N; ++i) {
		cin >> w[i] >> v[i];
		sm += v[i];
	}

	LL V = sm+1;

	LL g[2][V];

	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < V; ++j) {
			g[i][j] = inf;
		}
	}

	g[0][v[0]] = w[0];
	g[0][0] = 0;


	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < V; ++j) {
			if (j >= v[i]) {
				if (g[0][j-v[i]] != inf) {
					g[1][j] = min(g[0][j-v[i]]+w[i], g[0][j]);
				}
			}
			else {
				g[1][j] = g[0][j];
			}
		}

		for (int j = 0; j < V; ++j) {
			g[0][j] = g[1][j];
		}
	}

	LL maxval = 0;
	for (int i = 0; i < V; ++i) {
		if (g[0][i] <= W) {
			maxval = i;
		}
	}

	cout << maxval << endl;


	 
}

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

using namespace std;
int main (){
    int n;
    cin >> n;
    int x[n];
    int r=0;
    int l=100;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
        r=max(x[i],r);
        l=min(x[i],l);
    }
    int cost=INT32_MAX;
    int tcost;
    for (int i = l; i <= r; i++)
    {
        tcost=0;
        for (int j = 0; j < n; j++){
            tcost+=(x[j]-i)*(x[j]-i);
        }
        cost=min(cost,tcost);
    }
    cout << cost << "\n";
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

int lucus(int n, int r) {
    for (int i=0; i<=30; ++i) {
        int nn = (int)((n & (1<<i)) != 0);
        int rr = (int)((r & (1<<i)) != 0);
        if (nn == 0 && rr == 1) return 0;
    }
    return 1;
}

bool check(const vector<int> &v, int N) {
    int sum = 0;
    for (int i=0; i<N; ++i) {
        sum += v[i] * lucus(N-1, i);
        sum %= 2;
    }
    return sum % 2 == 1;
}

void solve() {
    int N;
    cin >> N;
    string s;
    cin >> s;

    vector<int> v(N);
    for (int i=0; i<N; ++i) v[i] = s[i] - '1';
    if (check(v, N)) {
        cout << 1 << '\n';
    } else {
        if (count(v.begin(), v.end(), 1)) {
            cout << 0 << '\n';
        } else {
            for (int &x : v) x /= 2;
            if (check(v, N)) {
                cout << 2 << '\n';
            } else {
                cout << 0 << '\n';
            }
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 8200
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q, W, H, R, C;
string S;

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

    cin >> N >> K;
    vector<vector<int>> G = make_vec<int>(N, N);
    REP(i, N) {
        REP(j, N) { G[i][j] = 1; }
    }

    if (N == 2) {
        if (K == 0) {
            cout << 1 << endl;
            cout << "1 2" << endl;

        } else {
            cout << -1 << endl;
        }
        return 0;
    }

    if (K > (N - 1) * (N - 2) / 2) {
        cout << -1 << endl;
        return 0;
    } else {
        int cnt = 0;
        REP(i, N) {
            if (cnt == K) break;
            FOR(j, i + 1, N - 1) {
                if (cnt == K) break;
                G[i][j] = 0;
                cnt++;
            }
        }

        cout << N * (N - 1) / 2 - K << endl;
        REP(i, N) {
            FOR(j, i + 1, N) {
                if (G[i][j] > 0) {
                    cout << i + 1 << " " << j + 1 << endl;
                }
            }
        }
        return 0;
    }
}


Measured memory_bytes: 256
import std.stdio, std.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional, std.bigint, std.random;

void main() {
  auto S = readln.chomp;
  if (S[0] == S[1]) {
    writeln("1 2");
    return;
  }
  foreach (i; 0..S.length-2) {
    if (S[i] == S[i+1] || S[i+1] == S[i+2] || S[i+2] == S[i]) {
      writeln(i+1, " ", i+3);
      return;
    }
  }
  writeln("-1 -1");
}


Measured memory_bytes: 508
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] i=str.split(" ");
		int r=Integer.parseInt(i[0]),c=Integer.parseInt(i[1]);
		int [][]hyo=new int[r+2][c+2];
		for (int x=1;x<=r;x++){
			 str = br.readLine();
			 i=str.split(" ");
			 for(int y=0;y<c;y++){
			hyo[x][y+1]=Integer.parseInt(i[y]);
			hyo[x][c+1]+=Integer.parseInt(i[y]);
			hyo[r+1][y+1]+=Integer.parseInt(i[y]);}
			hyo[r+1][c+1]+=hyo[x][c+1];
		}
		for (int x=1;x<=r+1;x++){
			for(int y=1;y<=c+1;y++){System.out.print(hyo[x][y]);
			if(y!=c+1){System.out.print(" ");}}
			System.out.println();
		}
		}}

Measured memory_bytes: 25980
#include <stdio.h>

int main (void)

{

int a, b;

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

if(a>b){

printf("a > b\n");

}

else if(a<b){

printf("a < b\n");

}

else{

printf("a == b\n");

}

return 0;

}
 

Measured memory_bytes: 580
N = int(input())
F="abcdefghijklmnopqrstuvwxyz"
def cy(ans,l):
  
  if len(ans)==N:
    print(ans)
  else:
    for i in range( min(l+2,27) ):
      k=ans+F[i]
      cy(k,max(l,i))

cy("a",0)

Measured memory_bytes: 59252
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(long i=0;i<n;++i)

int main()
{
    long n,k;
    cin >> n >> k;
    long a,b;
    vector<pair<long,long> > v; 
    F(n){
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    long ans=0,cnt=0;
    F(v.size()){
        cnt += v[i].second;
        if(cnt>=k){
            ans = v[i].first;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int n,m,k;
int fren[100005], sz[100005];
set < int > sf[100005];
set < int > bck[100005];

int f( int u ){
	if ( fren[u] != u ) return fren[u] = f(fren[u]);
	return u;
}

int main(){
	
	scanf("%d%d%d",&n,&m,&k);
	for ( int i = 1; i <= n; i++ ){
		fren[i] = i;
		sz[i] = 1;
	}
	for ( int i = 1; i <= m; i++ ){
		int a, b;
		scanf("%d%d",&a,&b);
		sf[a].insert(b);
		sf[b].insert(a);
		if ( f(a) != f(b) ){
			int pa = f(a), pb = f(b);
			if ( pa < pb ) swap(pa,pb);
			sz[pb] += sz[pa];
			fren[pa] = pb;
		}
	}
	
	for ( int i = 1; i <= k; i++ ){
		int a, b;
		scanf("%d%d",&a,&b);
		bck[a].insert(b);
		bck[b].insert(a);
	}
	
	for ( int i = 1; i <= n; i++ ){
		int ans = sz[f(i)] - 1;
		ans -= sf[i].size();
		for ( auto v : bck[i] ){
			if ( v == i ) continue;
			if ( f(v) == f(i) && sf[i].find(v) == sf[i].end() ) {
				ans--;
			}
		}
		printf("%d",ans);
		if ( i < n ) printf(" ");
		else printf("\n");
	}
	return 0;
}

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

vector<ll> A;

signed main(){
	ll N, K;
	cin >> N >> K;
	A = vector<ll>(N);
	for(int i = 0; i < N; i++){
		cin >> A.at(i);
	}
	for(int i = 0; i < N-K; i++){
		if(A.at(i) < A.at(i+K)){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
 
	return 0;
}

Measured memory_bytes: 4768
//https://atcoder.jp/contests/abc150/tasks/abc150_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
    ll N; cin>>N;
    string S; cin>>S;
    ll ans=0;
    FOR(i,0,S.size()){
        if (i+1>=S.size()||i+2>=S.size()) continue;
        if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C') ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n;
    double deno=0.0, ans;
  	scanf("%d", &n);
  	int num[n];
  	for(int i=0; i<n; i++) 
    {  
      	scanf("%d", &num[i]);
      	deno += 1.0 / num[i];   
	}
  
  	printf("%f", 1.0/deno);
  
  	return 0;
}

Measured memory_bytes: 128
s = gets.chomp
t = gets.chomp
n =  s.size
m = t.size

res = m
0.step(n - m) do |i|
  cnt = 0
  0.step(m - 1) do |j|
    cnt += 1 if s[i + j] != t[j]
  end
  res = [cnt, res].min
end
puts res

Measured memory_bytes: 14324
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	int counter=1;
	uint64_t jumps= t;
	while(jumps%360!=0){
		counter++;
		jumps+=t;
	}
	cout<<counter<<"\n";
}


Measured memory_bytes: 3624
#!/usr/bin/env python3
#AGC11 B
import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n = int(input())
a = list(map(int,input().split()))
a.sort()
b = list(accumulate(a))
b = list(map(lambda x:2*x,b))
ans = 1
for i in range(n-1):
    if a[i+1] <= b[i]:
        ans += 1
    else:
        ans = 1
print(ans)


Measured memory_bytes: 64744
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;

int main() {

    int n;
    cin >> n;
    vector<ll>a(n*3);
    rep(i, 0, n*3) {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    ll ans =0;
    for (int i = 1; i < n*2 ; i+=2) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
    
}



Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define vvl vector<vector<ll>>
#define vl  vector<ll>
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
//lcm:�ŏ����{���Agcd:�ő����
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back 
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

ll n;
ll k;
//string s;
signed main(){
	acc_io;
	ll ans;
	cin>>n>>k;
	ans=k;
	rep(i,0,n-1) ans*=(k-1);
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  
  int a = 1;
  
  for(int i; i < N; i++){
    if(a*2 > a + K){
      a += K;
    }else{
      a = a*2;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>
using namespace std;
stack<char>s;
int main()
{
	string t;
	cin>>t;s.push(t[0]);
	for(int i=1;i<t.length();i++)
	{
		if(t[i]=='T'&&s.size()&&s.top()=='S') s.pop();
		else s.push(t[i]); 
	}
	cout<<s.size();
	return 0;
}


Measured memory_bytes: 644