akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> e(m);
  for (auto& x : e) {
    cin >> x.first >> x.second;
    x.first--;
    x.second--;
  }
  vector<int> par(n, -1);
  auto root = [&](int t) {
    if (par[t] < 0) return t;
    for (int i = t;; i = par[i])
      if (par[i] < 0) return par[t] = i;
  };
  vector<ll> ans;
  ll a = (ll)n * (n - 1) / 2;
  for (int i = m; i--;) {
    ans.push_back(a);
    int r1 = root(e[i].first), r2 = root(e[i].second);
    if (r1 != r2) {
      a -= (ll)par[r1] * par[r2];
      if (par[r1] > par[r2]) swap(r1, r2);
      par[r1] += par[r2];
      par[r2] = r1;
    }
  }
  reverse(ans.begin(), ans.end());
  for (auto x : ans) cout << x << endl;
}


Measured memory_bytes: 3444
use std::io;
use std::str::FromStr;

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

fn input_int_tuple() -> (i32, i32) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<i32> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}


fn main() {
    let (n, _) = input_int_tuple();
    let mut vec: Vec<String> = Vec::new();
    for i in 0..n {
        vec.push(input());
    }
    vec.sort();
    for s in vec {
        print!("{}", s);
    }
}


Measured memory_bytes: 4352
#define s(X,Y,Z)(t=X,X=Y,Y=t,p=Z?&X:&Y,*p^=127,a&7)
m,a,b,c,t,r,*p;main(n){while(r=scanf("%d",&n),n){for(a=49,b=42,c=35;n--;scanf(" %c%*s",&t),m=t-76,r+=m%6==0?s(c,b,m):1<m&m<8?s(b,a,m^7):s(c,a,m>0));printf("%d\n",r);}}

Measured memory_bytes: 0
N=int(input())
import numpy as np
lis=np.array([1]*N)
mod=10**9+7
def prime_fac(n,l):
  for i in range(2,int(n**(1/2))+1):
    count=0
    while n%i==0:
      n=n//i
      count+=1
      
    l[i-1]+=count
    
  if n!=1:
    l[n-1]+=1
  return l
  
for i in range(2,N+1):
  lis=prime_fac(i,lis)
  
ans=1
lis=lis[lis>1]
for i in lis:
  ans=ans*i%mod
print(ans)

Measured memory_bytes: 12404
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	int n; cin >> n;
	int a = n / 100;
	int b = n % 100;
	if (a >= 1 && a <= 12) {
		if (b >= 1 && b <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else {
			cout << "MMYY" << endl;
		}
	}
	else{
		if (b >= 1 && b <= 12) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a,b;

void solve(){
	for(int i=1;i<=10000;i++){
		if(i*8/100==a && i*10/100==b){
			printf("%d\n",i);
			return;
		}
	}
	printf("-1\n");
}

int main(void){
	
	scanf("%d%d",&a,&b);
	solve();
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,t,a[200010];
ll s=0;

int main(){
	cin >> n >> t;
	REP(i,0,n) cin >> a[i];
	REP(i,0,n-1){
		if(a[i]+t<=a[i+1]) s+=t;
		else s+=a[i+1]-a[i];
	}
			
	cout << s+t << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main () {
  int X;
  cin >> X;
  int a = X / 100;
  int b = X % 100;
  int kj = (b - 1) / 5;
  kj ++;
  cout << (a >= kj ? 1 : 0) << endl;
}

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

int     main() {
        int N;
        cin >>N;
        long a;
        long S=0;
        for (int i=0; i<N; i++) {
                cin >>a;
                while (0==a%2) {
                        S++;
                        a /=2;
                }
        }
        cout << S << endl;
        return 0;
};

Measured memory_bytes: 256
N, M = map(int, input().split())
ans = [0] * N
ans[0] = 1
w = [1] * N

for i in range(M):
  x, y = map(int, input().split())
  w[x-1] -= 1
  w[y-1] += 1
  if ans[x-1] == 1:
    ans[y-1] = 1
    if w[x-1] == 0:
      ans[x-1] = 0
    
print(sum(ans))

Measured memory_bytes: 10312
#include<bits/stdc++.h>
using namespace std;
#define LL                  long long
#define ull                 unsigned long long LL
#define scl(n)              scanf("%lld", &n)
#define scf(n)              scanf("%lf", &n)
#define sci(n)              scanf("%d", &n)
#define scii(n,m)           scanf("%d %d",&n,&m)
#define sciii(n,m,p)        scanf("%d %d %d",&n,&m,&p)

#define MOD                 1000000007
#define MODP                99999999999973LL
#define pb                  push_back
#define mp                  make_pair
#define pp                  pair<LL,LL>
#define memo(a,b)           memset(a,b,sizeof(a))
#define INF                 1e9+1
#define EPS                 1e-8
#define Pi                  acos(-1.0)
LL bigmod(LL b, LL p, LL md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {LL y=bigmod(b,p/2,md);return (y*y)%md;}}
#define N 100002

LL arr[110],val[110];
LL n,W;

LL  dp[110][100009];
int vis[110][100009];

LL solve(int pos,int profit)
{
    if(profit==0)
        return 0;
    if(pos==n)
        return INF;
    if(profit<0)
        return INF;

    if(vis[pos][profit]==1)
        return dp[pos][profit];
    vis[pos][profit]=1;

    int ans1=arr[pos]+solve(pos+1,profit-val[pos]);
    int ans2=solve(pos+1,profit);

    return dp[pos][profit]=min(ans1,ans2);




}

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

    for(int i=0;i<n;i++)
        cin>>arr[i]>>val[i];

    for(int i=n*1000;i>=0;i--)
    {
        if(solve(0,i)<=W)
        {
            cout<<i<<endl;
            break;
        }
    }


    return 0;
}



/* LL dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; */ // 4 Direction
/* LL dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; */ // 8 Direction
/* LL dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* LL dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


Measured memory_bytes: 120960
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using cand_t = pair<char,pair<ll,ll>>;
ll d_l1(pair<ll,ll> a,pair<ll,ll> b){
    return abs(a.first-b.first)+abs(a.second-b.second);
}
void arm(pair<ll,ll> p_start,pair<ll,ll> p_end,ll dist){
    if(dist==0&&p_start==p_end){
        cout << endl;
        return;
    }
    if(dist<1)dist=1;
    vector<cand_t> candidate;
    candidate.push_back({'L',{p_start.first-dist,p_start.second}});
    candidate.push_back({'R',{p_start.first+dist,p_start.second}});
    candidate.push_back({'D',{p_start.first,p_start.second-dist}});
    candidate.push_back({'U',{p_start.first,p_start.second+dist}});
    std::sort(candidate.begin(),candidate.end(),[&](cand_t a,cand_t b){return d_l1(p_end,a.second)<d_l1(p_end,b.second);});
    cout << candidate[0].first;
    arm(candidate[0].second,p_end,dist/2);
}
int main(){
    int n;
    cin >> n;
    vector<pair<ll,ll>> xy;
    bool is_even;
    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if(i==0)is_even=((x+y)%2==0);
        else if(is_even!=((x+y)%2==0)){
            cout << -1 << endl;
            return 0;
        }
        xy.push_back({x,y});
    }
    cout << 33 + (is_even?1:0) << endl;
    rep(i,33) cout << (1LL<<(32-i)) << " ";
    if(is_even) cout << 1;
    cout << endl;
    rep(i,n)arm({0,0},xy[i],1LL<<32);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

int main()
{
  uint64_t N;
  cin >> N;

  uint64_t ans = 0;

  ans += N*(N+1)/2;

  uint64_t N3 = N/3;
  ans -= N3*(N3+1)/2*3;

  uint64_t N5 = N/5;
  ans -= N5*(N5+1)/2*5;

  uint64_t N15 = N/15;
  ans += N15*(N15+1)/2*15;
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3652
t = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
if (t[0]*a[0]+t[1]*a[1] == t[0]*b[0]+t[1]*b[1])
    puts "infinity"
    exit
end
if (a[0] > b[0]) 
    a,b = b,a
end
u = t[0]*a[0]+t[1]*a[1]
v = t[0]*b[0]+t[1]*b[1]
if (v > u)
    puts 0
    exit
end
ok = 0
ng = 2**62
while (ng-ok > 1)
    mid = (ok+ng)/2;
    if (mid*u+t[0]*a[0] < mid*v+t[0]*b[0])
        ok = mid
    else
        ng = mid
    end
end
ans = ok*2+1
if ng*u+t[0]*a[0] == ng*v+t[0]*b[0]
    ans += 1
end
puts ans

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

using ll=long long;
using ld=long double;

int main(){
  ll a,b,c;
  std::cin>>a>>b>>c;
  ll d = c-a-b;
  if(d > 0 && (d*d > 4*a*b))
    std::cout<<"Yes\n";
  else
    std::cout<<"No\n";
}


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

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using i32 = int_fast32_t;
using u32 = uint_fast32_t;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using usize = size_t;

namespace chrono = std::chrono;
using namespace std::literals;

#define all(c) (c).begin(), (c).end()

__attribute__((constructor))
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

int main() {
  i32 a, b, c;
  cin >> a >> b >> c;
  if (a == b) {
    cout << c;
  } else if (a == c) {
    cout << b;
  } else {
    cout << a;
  }
  cout << endl;
}


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

using namespace std;
typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define gcd __gcd
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int)(1e9+7);

int pDivisors(int n, int t)
{
    vector<int> v;
    int mx = 0;
    for (int i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            if(i<=t)mx = max(i, mx);
            if(n/i<=t)mx = max(n/i, mx);
        }

    }
    return mx;
}

int x[102],y[202], h[234];
void _(){
    int n,a,b;
    cin >> n >> a >>b;
    if(n == 1)cout << "Hello World";
    else cout << a+b;


}


int main() {
#ifdef Debug
    freopen("/home/joduskame/Desktop/cpp/IO/Input.txt", "r", stdin);
    freopen("/home/joduskame/Desktop/cpp/IO/Output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}






Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
int main() {
  ll n;
  cin >> n;
  Graph g(n);
  vector<int> ans(n, -1);
  vector<map<ll, ll>> mp(n);

  for(int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
    mp[u][v] = w;
    mp[v][u] = w;
  }
  ans[0] = 0;
  queue<int> que;
  vector<int> seen(n, 0);
  que.push(0);
  while(!que.empty()) {
    int now = que.front();
    seen[now] = 1;
    que.pop();
    for(auto p : g[now]) {
      if(seen[p] == 1) {
        continue;
      }
      if(mp[now][p] % 2 == 0) {
        ans[p] = ans[now];
      } else {
        ans[p] = ans[now] ? 0 : 1;
      }
      que.push(p);
    }
  }
  for(int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 27208
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <functional>
#include <queue>

#define rep(i, n) for(int i = 0, end = (int)(n); i < end; i++)

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

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

int main() {
    ll a, b;
    cin >> a >> b;
    cout << (ll)((a+b+1)/2) << endl;
    return 0;
}


Measured memory_bytes: 256
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input().rstrip('\n')
    w = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
    print(w[s])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int a[100][100];
	int x, y;
	int i, j, k;
	int num;
	int ni[40], nj[40];
	
	while (1){
		for (i = 0; i < 100; i++){
			for (j = 0; j < 100; j++){
				a[i][j] = 0;
			}
		}
		
		scanf("%d %d", &x, &y);
		
		if (x == 0 && y == 0){
			break;
		}
		
		scanf("%d", &num);
		for (k = 0; k < num; k++){
			scanf("%d %d", &ni[k], &nj[k]);
		}
		x--;
		y--;
		
		for (k = 0; k < num; k++){
			a[ni[k] - 1][nj[k] - 1] = -1;
		}
		
		a[x - 1][y] = a[x][y - 1] = 1;
		for (i = x; i >= 0; i--){
			for (j = y; j >= 0; j--){
				if (a[i][j] == 0){
					a[i][j] = a[i + 1][j] + a[i][j + 1];
				}
				else if (a[i][j] == -1){
					a[i][j] = 0;
				}
			}
		}
		
		printf("%d\n", a[0][0]);
	}
	
	return (0);
}

Measured memory_bytes: 1064
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, x = mi()
    L = list(map(lambda point: abs(int(point) - x), input().split()))
    g = L[0]
    for i in range(1, n):
        g = gcd(g, L[i])
    print(g)




if __name__ == "__main__":
    main()


Measured memory_bytes: 16348
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int a,b,c,x,y;

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int n = a * x + b * y;

    int m = 2 * c * max(x, y);

    int p = x < y ? b : a;
    int q = 2 * c * min(x, y) + p * abs(x - y);
  
    int ans = min(n, min(m, q));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAXN 100
#define MAXW 100000

typedef struct ABC {
  int v,w;
} ITEM;

ITEM A[MAXN+1];
long long  S[MAXN+1][MAXW+1];

long long  napsack ( int n, int w )
{
	int i,j;
	long long tmp1, tmp2;

	for ( i = 0; i <= w; i++ ) S[0][i] = 0;
	for ( i = 0; i <= n; i++ ) S[i][0] = 0;

	for ( i = 1; i <= n; i++ ) {
		for ( j = 1; j <= w; j++ ) {
			if ( A[i].w > j ) S[i][j] = S[i-1][j];
			else {
				tmp1 = S[i-1][j];
				tmp2 = S[i-1][j-A[i].w]+A[i].v;
				S[i][j] = tmp1 > tmp2 ? tmp1:tmp2;
			}
		}
	}

	return S[n][w];
}


int main(void)
{
	int n,i,w;

	scanf("%d", &n); scanf("%d", &w);
	for ( i = 1; i <= n; i++ ) scanf("%d%d", &A[i].w, &A[i].v);


	printf("%ld\n", napsack(n,w));

	return 0;
}


Measured memory_bytes: 79104
# coding: utf-8
# Your code here!
N=int(input())

A=list(map(int,input().split()))
B=list(map(int,input().split()))

count=0
for i in range(N):
    hiku=min(A[i],B[i])
    count+=hiku
    A[i]-=hiku
    B[i]-=hiku
    hiku=min(A[i+1],B[i])
    count+=hiku
    A[i+1]-=hiku
    B[i]-=hiku

print(count)



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

int main(){
  int n;
  cin >> n;
  for(int i = n; ; i++){
    if(i % 10 == (i / 10) % 10 && i % 10 == i / 100){
      cout << i << endl;
      return 0;
    }
  }
}

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

int main(){
    int N,D;
    cin >> N >> D;
    
    int cnt = 0;
    for(int i = 1;i <= 20;i++){
        if(N <= (1 + 2*D)*i){
            cnt = i;
            break;
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
import math
def isMore(N,K):#- N以上の数で、０でないのが丁度K個
    #-len(N)よりもKがおおきかったら0
    if len(N) < K:
        return 0
    #最高位の数字を1つ繰り上げれば、なんでも大きい。ただし、Kは1以上
    if K>=1:
        tmp = (9-int(N[0]))*fact[len(N)-1]//((fact[len(N)-K])*(fact[K-1]))*(9**(K-1))
        if len(N)==1:
            return tmp
        elif len(N)>1 and N[0]=='0':
            return tmp + isMore(N[1:],K)
        elif len(N)>1 and N[0]!='0':
            return tmp + isMore(N[1:],K-1)
    if K == 0:
        return 0

N = input()
K = int(input())
lenN = len(N)
fact = [1]*101
for i in range(1,101):
    fact[i] = fact[i-1]*i

ans = fact[lenN]//((fact[lenN-K])*fact[K])*(9**K)
ans -= isMore(N,K)
print(ans)


Measured memory_bytes: 9212
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<map>
#include<queue>

int const MAXN = 2e5;

std::pair<int, int> mon[MAXN];
int N, D, A;

int main() {
  std::cin >> N >> D >> A; D += D;
  for(int i = 0; i < N; ++i) {
    int X, H; std::cin >> X >> H;
    mon[i] = std::make_pair(X, (H+A-1)/A);
  }
  std::sort(mon, mon+N);
 
  int64_t ans = 0, sum = 0; 
  std::queue<std::pair<int, int>> q;
  for(int i = 0; i < N; ++i) {
    while(!q.empty() && q.front().first < mon[i].first) {
      sum -= (int64_t)q.front().second;
      q.pop();
    }
    int c = mon[i].second;
    if(c <= sum) continue;
    c -= sum;
    q.push(std::make_pair(mon[i].first+D, c));
    sum += (int64_t)c;
    ans += (int64_t)c;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 2688
def examA():
    S = SI()
    M = int(S[5:7]);  D = int(S[8:10])
    if M<=4:
        ans = "Heisei"
    else:
        ans = "TBD"
    print(ans)
    return




import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()


Measured memory_bytes: 3444
class MinMaxSum {
  def inputScanner: List[Long] = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    List.fill(n)(sc.nextLong())
  }
  def check(list: List[Long] ): Unit = {
   val ma:Long = list.max
   val mi:Long = list.min
   val sum:Long = list.sum
    println(s"$mi $ma $sum")
  }
}
object Main {

  def main(args: Array[String]) {
    val c = new MinMaxSum
    c.check(c.inputScanner)
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  char a[H][W];
  vector<int> tate(W), yoko(H); 
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }

  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(a[i][j] == '#') { tate[j] = 1; yoko[i] = 1; }
    }
  }

  for(int i = 0; i < H; i++) {
    if(yoko[i] == 1){
    for(int j = 0; j < W; j++) {
     if(tate[j] == 1) cout << a[i][j]; 
    }
    cout << endl;
    }
  }


  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int MAXN=1e5+10;
char a[20];
int m,n,l,p,k,ans,tot;
bool flg;
int inline read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int main()
{
	scanf("%s",a+1);
	n=strlen(a+1);
	if (a[1]!='A')
	{
		printf("WA");
		return 0;
	}
	flg=true;
	for (int i=2;i<=n;i++)
	{
		p=a[i]-'a';
		if (p>=0 && p<26)
		{
			continue;
		}
		
		p=a[i]-'C';
		if (!p)
		{
			if (i>2 && i<n)
			{
				if (flg)
				{
					flg=false;
					continue;
				}
			}
		}
		
		printf("WA");
		return 0;
	}
	
	if (flg)
	{
		printf("WA");
		return 0;
	}
	
	printf("AC");

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const LL mo=1e9+7;
const int N=1e6;
char s[N+3];
int len;
LL fac[N+10],f[N+10],a[N+10],b[N+10],c[N+10];
int main() {
    fac[0]=1;
    for (int i=1;i<=N;i++) fac[i]=fac[i-1]*3%mo;
    scanf("%s",s+1);
    len=strlen(s+1);
    a[0]=b[0]=c[0]=f[0]=0;
    for (int i=1;i<=len;i++) {
        f[i]=f[i-1]+(s[i]=='?');
        a[i]=a[i-1]+(s[i]=='A');
        b[i]=b[i-1]+(s[i]=='B');
        c[i]=c[i-1]+(s[i]=='C');
    }
    int sum=f[len];
    LL ans=0;
    for (int i=1;i<=len;i++) {
        if (s[i]=='?') {
            LL now=f[i-1]*(sum-f[i])%mo*fac[sum-3]%mo;
            now=(now+f[i-1]*(c[len]-c[i])%mo*fac[sum-2])%mo;
            now=(now+a[i-1]*(sum-f[i])%mo*fac[sum-2])%mo;
            now=(now+a[i-1]*(c[len]-c[i])%mo*fac[sum-1])%mo;
            ans=(ans+now)%mo;
        }
        if (s[i]=='B') {
            LL now=f[i-1]*(sum-f[i])%mo*fac[sum-2]%mo;
            now=(now+f[i-1]*(c[len]-c[i])%mo*fac[sum-1])%mo;
            now=(now+a[i-1]*(sum-f[i])%mo*fac[sum-1])%mo;
            now=(now+a[i-1]*(c[len]-c[i])%mo*fac[sum])%mo;
            ans=(ans+now)%mo;
        }
    }
    ans=(ans%mo+mo)%mo;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 19712
// Problem : C - Vacation
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_c?lang=en
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define Ma7moud_7amdy                 \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define Open_Sesame Open()
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define watch(x) cout << #x << " = " << x << endl;
#define RT(x) return cout << (x), 0;
#define Accepted 0
typedef long long ll;
typedef vector<int> vi;
const int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
void Open()
{
#ifndef ONLINE_JUDGE 
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
const int mod = ll(1e9 + 7), N = 1e5 + 5;
//“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent

struct Vacation {
	int Swim, bugs, homework;
};
int n;
vector<Vacation> v;
//int mem[N][4];
int dp[N][4];
/*int solve(int idx = 0, int prev = 0)
{
	if (idx == n)
		return 0;
	int& ret = mem[idx][prev];
	if (~ret)return ret;
	ret = 0;
	if (prev != 1)
		ret = max(ret, solve(idx + 1, 1) + v[idx].Swim);
	if (prev != 2)
		ret = max(ret, solve(idx + 1, 2) + v[idx].bugs);
	if (prev != 3)
		ret = max(ret, solve(idx + 1, 3) + v[idx].homework);

	return ret;
}*/
int main()
{
	Ma7moud_7amdy;
//	Open_Sesame;
	//clr(mem, -1);
	cin >> n;
	v = vector<Vacation>(n);
	for (int i = 0; i < n; i++)
		cin >> v[i].Swim >> v[i].bugs >> v[i].homework;
	//cout << solve() << endl;

	//baseCase
	dp[n][1] = dp[n][2] = dp[n][3] = 0;


	for (int idx = n-1; idx >=0; idx--) {
		int& ret1 = dp[idx][1];
		int& ret2 = dp[idx][2];
		int& ret3 = dp[idx][3];
		ret1 = ret2 = ret2 = 0;;

		ret1 = max(ret1, dp[idx + 1][2] + v[idx].Swim);
		ret1 = max(ret1, dp[idx + 1][3] + v[idx].Swim);

		ret2 = max(ret2, dp[idx + 1][1] + v[idx].bugs);
		ret2 = max(ret2, dp[idx + 1][3] + v[idx].bugs);

		ret3 = max(ret3, dp[idx + 1][1] + v[idx].homework);
		ret3 = max(ret3, dp[idx + 1][2] + v[idx].homework);

	}

	cout << max({ dp[0][1],dp[0][2],dp[0][3] }) << endl;
}


Measured memory_bytes: 5744
#!/usr/bin/env python
# coding: utf-8

import re


def get_factorial(n):
    factorial = 1
    for i in xrange(1, n + 1):
        factorial = factorial * i
    return factorial


def main():
    params = []
    while 1:
        param = int(raw_input())
        if param == 0:
            break
        else:
            params.append(param)

    for param in params:
        print re.findall(r"0*$", str(get_factorial(param)))[0].__len__()

if __name__ == '__main__':
    main()

Measured memory_bytes: 7256
def nyu():
    N = int(input())
    h = list(map(int,input().split())) 

    return N,h

def mizuyari(N,H):
    cnt =0
    flg = False
    h = H

    while flg == False:
    ##開始点を見つける
        start = 0
        for n in range(N):
            if h[n] != 0:
                start = n
                break
            elif n == N-1 and h[n] == 0:
                flg = True
                break
    #開始地点から水やり開始
        for n in range(start,N):
            if h[n] == 0:
                break
            else :
                h[n] -= 1
        cnt += 1

    print(cnt-1)







    



N,h =nyu()
mizuyari(N,h)







Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
  long long int a,b,c,d;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  while( c >0 || a>0)
  {
    c=c-b;
      if(c <=0)
      {printf("Yes");
       break;
      }
    a=a-d;
      if(a<=0)
      {printf("No");
      break;}
  }
return 0;}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
string subs(string s,int a,int b)
{
    string s1="";

    for(int i = a; i < b; i++)
        s1 = s1 + s[i];

    return s1;
}
vector<string> palindromic(string s)
{
    vector<string> v ;

    for (float i = 0; i < s.length();
                                 i += .5)
    {
        float Radius = i -(int)i;
        while ((i + Radius)
         < s.length() && (i - Radius)
         >= 0 && s[((int)(i - Radius))]
             == s[((int)(i + Radius))])
        {

    v.push_back(subs(s,(int)(i -Radius), (int)(i + Radius + 1)));

         Radius++;
        }
    }

    return v;
}
int main(){

        string g;
         char str[100000];
           cin>>str;

         for(int i=0;str[i]!='\0';i++)
             g.append(1,str[i]);

       vector<string> vect = palindromic(g);

         cout<<vect.size();
}*/
int main(){

     string n;
       cin>>n;

       ll sum =0;
       for(int i=0;i<n.length();i++)
        sum+=n[i]-48;

        if(sum % 9==0)
        cout<<"Yes";

        else
        cout<<"No";
}

Measured memory_bytes: 3728
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

bool visit(vvi &g, int v, vi &order, vi &color) {
  color[v] = 1;
  REP(i, g[v].size()) {
    if (color[g[v][i]] == 2) continue;
    if (color[g[v][i]] == 1) return false;
    if (!visit(g, g[v][i], order, color)) return false;
  }
  order.push_back(v); color[v] = 2;
  return true;
}
bool topologicalSort(vvi &g, vi &order) {
  int n = g.size();
  vi color(n);
  REP(u, n) if (!color[u] && !visit(g, u, order, color))
    return false;
  reverse(ALL(order));
  return true;
}

int main() {
    int n;
    cin>>n;
    int m;
    cin>>m;
    vvi g(n);
    REP(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
    }
    vi order;
    bool f=topologicalSort(g,order);
    assert(f);
    REP(i,order.size()){
        cout<<order[i]+1<<endl;
    }
    REP(i,n-1){
        bool flag=false;
        REP(j,g[order[i]].size()){
            if(g[order[i]][j]==order[i+1]){
                flag=true;
                break;
            }
        }
        if(!flag){
            cout<<1<<endl;
            return 0;
        }
    }
    cout<<0<<endl;
}

Measured memory_bytes: 2216
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

string num[10]={"* = ****","* =* ***","* =** **","* =*** *","* =**** "," *= ****"," *=* ***"," *=** **"," *=*** *"," *=**** "};

int main(){
	string s;
	int cnt=0;
	while(cin>>s){
		if(cnt>0)cout<<endl;
		if(s.size()<5){
			while(s.size()<5){
				s='0'+s;
			}
		}
		rep(i,8){
			string temp="";
			rep(j,s.size()){
				temp+=num[s[j]-'0'][i];
			}
			cout<<temp<<endl;
		}
		cnt++;
	}
	return 0;
}

Measured memory_bytes: 1188
#include<stdio.h>
#include<math.h>
int main(void)
{
    double n;
    int i;
    double sum;
    double num[1000];
    double ave,s;
     
    while(1)
    {
        sum=0;
        s=0;
         
        scanf("%lf",&n);
        if(n==0)
        {
            break;
        }
         
        for(i=0;i<n;i++)
        {
            scanf("%lf",&num[i]);
            sum+=num[i];
        }
        ave=sum/n;
         
        for(i=0;i<n;i++)
        {
            s+=(num[i]-ave)*(num[i]-ave);
        }
        printf("%lf\n",sqrt(s/n));
    }
     
    return 0;
}



Measured memory_bytes: 2132
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set] 
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector< ll > lvi;
typedef vector< vi > vvi;
typedef vector< lvi > lvvi;
typedef pair< int,int > ii;
typedef pair< ll,ll > lii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#define mp make_pair
#define ld long double
#define ull unsigned long long int
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
	ll k;
	cin>>k;
	ll last=1;
	for(int i=2;i<=k;i++)
	{
		lvi a(12,0);
		ll temp=last;
		ll j=0;
		while(temp>0)
		{
			ll curr=temp%10;
			a[j]=curr;
			j++;
			temp/=10;
		}
		bool flag=false;
		for(int r=0;r<j;r++)
		{
			if(a[r]!=9) flag=true;
		}
		if(!flag)
		{
			last=pow(10LL,j);
			// cout<<last<<endl;
			continue;
		}
		int pos=j-1;
		for(int r=0;r<j-1;r++)
		{
			int x=a[r]+1;
			if(x>9) continue;
			if(abs(x-a[r+1])<=1) 
			{
				pos=r;
				break;
			}
		}
		a[pos]++;
		for(int r=pos-1;r>=0;r--)
		{
			a[r]=a[r+1]-1;
			a[r]=max(0LL,a[r]);
		}
		ll powers=1;
		last=0;
		for(int r=0;r<j;r++)
		{
			last=last+powers*a[r];
			powers*=10;
		}
		// cout<<last<<endl;
	}
	cout<<last<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

total = 6
A = int(input())
B = int(input())
#a, b, c, d = (int(i) for i in input().split())  
#a = [int(i) for i in input().split()] 
#e = [[int(i) for i in input().split()] for i in range(n)] 

print(total -A - B)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=1;
    char memo=s[0];
    for(ll i=1;i<n;i++){
        if(memo!=s[i]){
            ans++;
            memo=s[i];
        }
    }
    cout<<ans<<endl;
}

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

#define int long long int

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif
//!

int32_t main()
{
	GO
	//fioe();
	int l;
	cin>>l;
	double x = l/3.0;
	double ans = x*x*x;
	printf("%.8f\n",ans);	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
  int N;
  double sum=0;
  cin>>N;
  vector<double>a(N);
  vector<string>b(N);
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=0;i<N;i++){
    if(b[i]=="JPY"){
      sum=sum+a[i];
    }
    else{
      sum=sum+a[i]*380000;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
p = p[A-X:]
q = list(map(int, input().split()))
q.sort()
q = q[B-Y:]
r = list(map(int, input().split()))
apple = p+q+r
apple.sort()
print(sum(apple[len(apple)-X-Y:]))

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


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if ((a<=c) && (c<=b) ) {
		if (d<=b) cout << d-c << endl;
		else cout << b-c << endl;
	}
	else if ((a<=d) && (d<=b)) {
		cout << d-a << endl;
	}
	else {
		if ((c<a) && (b<d)) cout << b-a << endl;
		else cout << 0 << endl;
	}

}


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

namespace _0229
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0 && x[2] == 0 && x[3] == 0 && x[4] == 0 && x[5] == 0)
                {
                    break;
                }
                Console.WriteLine(100 + x[0] * 80 + x[1] * 54 + x[2] * 7 + x[3] * 2 - (x[5] - x[4] - x[0] * 5 - x[1] * 3) * 3);
            }
        }
    }
}

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

using namespace std;
typedef pair<int, int> P;
const int MAXH = 301;
const int MAXW = 301;
const int MAXQ = 1e5 + 10;

int a[MAXH][MAXW];
P field[MAXH*MAXW];
bool visited[MAXH*MAXW];
vector<int> cost[MAXH*MAXW];
int l[MAXQ], r[MAXQ];

int h, w, d, q;
void solve() {
  for (int y=0;y<h;y++) {
    for (int x=0;x<w;x++) {
      field[a[y][x] - 1] = P(x, y);
    }
  }

  for (int i=0;i<=w*h;i++) {
    if (!visited[i]) {
      cost[i].resize((w*h-i) / d + 5);
      cost[i][0] = 0;
      for (int j=1;i + j * d<=w*h;j++) {
        visited[i + j * d] = true;
        P& p1 = field[i + (j-1) * d];
        P& p2 = field[i + j * d];
        cost[i][j] = cost[i][j-1] + abs(p1.first - p2.first) + abs(p1.second - p2.second);
      }
    }
  }


  for (int i=0;i<q;i++) {
    l[i]--;r[i]--;
    int start = l[i] % d;
    cout << (cost[start][(r[i] - start) / d] - cost[start][(l[i] - start) / d]) << endl;
  }
}

int main() {
  cin >> h >> w >> d;
  for (int y=0;y<h;y++) {
    for (int x=0;x<w;x++) {
      cin >> a[y][x];
    }
  }
  cin >> q;
  for (int i=0;i<q;i++) {
    cin >> l[i] >> r[i];
  }
  solve();
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;	cin >> s >> t;
  int a,b;	cin >> a >> b;
  string u;	cin >>u;
  if(s==u)	a--;
  if(t==u)	b--;
  cout << a << " " << b;
}

Measured memory_bytes: 3580
#include <iostream>
#include <regex>
#include <locale>

using namespace std;

int main() {
  string s;
  cin >> s;
  regex re("AAA|BBB");
  if ( regex_match(s, re) ) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
const int mod = 1000000007;
 
int main() {
    int n,k;
    cin >> n >> k;
    LL count = 0;
    LL min,max;

    for(LL i = k;i <= n+1 ; i++) {
        min = ((i)*(i-1))/2;
        max = ((i)*(n+n-i+1))/2;
        // cout << min << endl;
        // cout << max << endl;
        count += max - min + 1;
    }
    cout << (count%mod) << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main ( String[] args ) {
		int[] deta = new int[128];
		int in , i , max = 0;
		Scanner sc = new Scanner(System.in);
		while ( sc.hasNext() ) {
			in = sc.nextInt();
			deta[in]++;
			if ( deta[in] > max ) max = deta[in];
		}
		for ( i = 1; i <= 100; i++ )
			if ( deta[i] == max ) System.out.println(i);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include<vector>
#include <map>
using namespace std;
 
int main(void){
    // Your code here!
    long long N;
    cin >> N;
    
    long long A[N];
    
    for(int i = 0; i < N ; i++)cin >> A[i];
    
    std::map<int,vector<long long>> map;
    std::map<int,long long> sumRes;
    long long sum = 0;
    vector<long long> record;
    
    
    
    for(int i = 0; i < N ; i++){
        map[A[i]].push_back(i);
        record.push_back(A[i]);
    }
    
    for(int i = 1; i < N+1 ; i++){
        sum += i-1;
        sumRes[i]=sum;

    }
    
    long long ans;
    long long res = 0;
    for(int i = 0; i < N+1 ; i++){
        ans = map[i].size();
        //cout <<"aaa" <<  ans << endl;

        res += sumRes[ans];
        
    }
    
    
    vector<long long> sss;
    long long ss;
    long long res2;
    for(int i = 0; i < N+1 ; i++){
        ss = map[A[i]].size();
        //cout << ss << endl;
        res2 = sumRes[ss-1] - sumRes[ss];
        //cout << res2 << endl;
        sss.push_back(res2);
    }
    
    for(int i = 0; i < N ;i++){
        //cout << record[i]<<endl;
        cout << res + sss[i] <<endl;
    }
    
    
    
    
    
}

Measured memory_bytes: 38768
// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}
__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    ll n, x, m;
    cin >> n >> x >> m;
    
    vector<int> id(m, -1);
    vector<int> a;
    int len = 0;
    ll tot = 0;
    while (id[x] == -1) {
        id[x] = len++;
        tot += x;
        a.push_back(x);
        x = (x * x) % m;
    }
    int cycle = len - id[x];
    ll cycle_sum = 0;
    for (int i = id[x]; i < len; ++i) cycle_sum += a[i];

    ll ans = 0;
    if (n <= len) {
        rep(i, n) ans += a[i];
    } else {
        ans += tot;
        n -= len;
        ans += cycle_sum * (n / cycle);
        n %= cycle;
        rep(i, n) ans += a[id[x] + i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3976
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int x, y, z;
	cin >> x >> y >> z;
	cout << (x - z) / (y + z) << endl;


	return 0;
}

Measured memory_bytes: 256
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

res = abs(a - (t - h[0] * 0.006))
ans = 1
for i in range(len(h)):
    x = h[i]
    res_n = abs(a - (t - x * 0.006))
    # print(res_n)
    if res > res_n:
        res = res_n
        ans = i + 1

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
int main()
{
	int x,y,z;
	cin>>x>>y>>z;
	cout<<(x-z)/(y+z)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

 int main()
{

 int x,y,z;
 
 for(;;){

              scanf("%d %d",&x,&y);
              if(x == 0 && y == 0) break;
              if(x>y)z=x,x=y,y=z;
              printf("%d %d\n",x,y);

              }

 return 0;
}
 



Measured memory_bytes: 1980
n,m = map(int,input().split())
ans = 1
for i in range(1,int(pow(m,0.5))+1):
    if m%i == 0:
        if i <= m//n:
            ans = max(ans,i)
        if m//i <= m//n:
            ans = max(ans,m//i)
print(ans)

Measured memory_bytes: 9392
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

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


int main()
{
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll minsofar = 1e16;
    ll curr;
    REP(i, 5) {
        cin >> curr;
        minsofar = min(minsofar, curr);
    }
    ll ans = (n + minsofar - 1) / minsofar + 4LL;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	ll n,k;cin>>n>>k;
	vector<vector<int>> e(n);
	if(n==1){
		cout<<k<<endl;
		return 0;
	}
	rep(i,1,n-1){
		int a,b;cin>>a>>b;
		--a,--b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	int x = max(n,k);
	vector<ll> par(x);
	par[0]=1;
	ll MOD = 1000000007;
	vector<bool> passed(n, false);
	passed[0]=true;
	rep(i,1,k-2){
		par[i]=par[i-1]*(k-1-i)%MOD;
	}
	ll ans = k * par[e[0].size()-1]%MOD;
	ans = ans*(k-1)%MOD;
	queue<int> q;
	rep(i,0,e[0].size()-1){
		q.push(e[0][i]);
	}
	while(!q.empty()){
		int now = q.front();
		q.pop();
		ans = ans * par[e[now].size()-1] % MOD;
		passed[now]=true;
		rep(i,0,e[now].size()-1){
			if(!passed[e[now][i]]){
			q.push(e[now][i]);
			}
		}
	}
	cout<<ans<<endl;
}


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

int main(){
    ll h;
    cin >> h;
    ll count = 0;
    while(true){
        h /= 2;
        count++;
        if(h == 0) break;
    }
    ll ans = 0;
    for(int i =0; i < count; i++) ans += pow(2, i);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#define ICES 10

int main(){
    int num[ICES];
    int n, tmp;

    while (scanf("%d",&n), n!=0){
        for (int i=0; i<ICES; i++) num[i]=0;
        for (int i=0; i<n; i++){
            scanf("%d", &tmp);
            num[tmp]++;
        }
        for (int i=0; i<ICES; i++){
            if (num[i]==0){
                printf("-\n");
            } else {
                for (int j=0; j<num[i]; j++){
                    printf("*");
                }
                printf("\n");
            }
        }
    }    
    return 0;
}

Measured memory_bytes: 1000
while 1:
    n=int(input())
    if not n:break
    l=input().split()
    d={}
    f=False
    for (cnt,i) in enumerate(l):
        if i in d:
            d[i]+=1
        else:
            d[i]=1
        pl=n-cnt-1
        dd=sorted(d.items(),key=lambda x:x[1])
        if len(dd)>1:
            if dd[-1][1]>dd[-2][1]+pl:
                print(dd[-1][0],cnt+1)
                f=True
                break
        else:
            if float(dd[0][1])/n>0.5:
                print(dd[0][0],cnt+1)
                f=True
                break

    if not f:
        print("TIE")
        



Measured memory_bytes: 5632