akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int insertion_sort(int *A, int N, int g)
{
    int v;
    int j;
    int cnt = 0;

    for (int i = g; i < N; i++)
    {
        v = A[i];
        j = i - g;
        while (j >= 0 && A[j] > v)
        {
            A[j + g] = A[j];
            j -= g;
            cnt += 1;
        }
        A[j + g] = v;
    }
    return cnt;
}

void shell_sort(int *A, int N)
{
    int cnt = 0;
    int m = 0;
    int G[100];

    for (int h = 1; h <= N; h = 3 * h + 1)
    {
        G[m] = h;
        m += 1;
    }

    for (int i = m - 1; i >= 0; i--)
    {
        cnt += insertion_sort(A, N, G[i]);
    }

    printf("%d\n", m);
    for (int i = m - 1; i >= 0; i--)
    {
        if (i == 0)
        {
            printf("%d\n", G[i]);
        }
        else
        {
            printf("%d ", G[i]);
        }
    }
    printf("%d\n", cnt);
}

int main(void)
{
    int N;
    int A[1000000];

    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &A[i]);
    }

    shell_sort(A, N);
    for (int i = 0; i < N; i++)
    {
        if (i == N - 1)
        {
            printf("%d\n", A[i]);
        }
        else
        {
            printf("%d ", A[i]);
        }
    }

    return 0;
}


Measured memory_bytes: 5676
N, M = gets.chomp.split(" ").map(&:to_i)
MOD = 10 ** 9 + 7

require "prime"

#組み合わせ個数
def choose(n, r, mod)
  return 0 if not (0 <= r and r <= n)
  return 1 if r == 0 or r == n
  fact(n, mod) * inverse(fact(r, mod) * fact(n-r, mod) % mod, mod) % mod
end
#階乗(MODあり)
@fact = [1]
def fact(n, mod)
  if n > @fact.size then
    f = @fact[-1]
    (@fact.size+1..n).each{|i|
      f = (f * i) % mod
      @fact << f
    }
  end
  @fact[n-1]
end
#逆元(MODあり)
def inverse(x, mod)
  pow(x, mod-2, mod)
end
#べき乗(MODあり)(繰り返し２乗法)
def pow(x, n, mod)
  ans = 1
  while n > 0
    ans = ans * x % mod if n.odd?
    x = x * x % mod
    n >>= 1
  end
  ans
end

t = Hash.new
ans = 1
M.prime_division.each{|k, v|
  if not t.key?(v) then
    wk = 0
    (1..v).each{|i|
      wk = (wk + choose(N, i, MOD) * choose(v-1, i-1, MOD)) % MOD
    }
    t[v] = wk
  end
  ans = (ans * t[v]) % MOD
}

puts ans


Measured memory_bytes: 3964
import java.util.*;
import java.math.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] t = new long[n];
    for(int i = 0; i < n; i++){
      t[i] = sc.nextLong();
    }
    long tmp = t[0];
    for(int i = 1; i < n; i++){
      tmp = gcd(tmp, t[i]);
    }
    
    System.out.println(tmp);
  }
  
  public static long gcd(long a, long b){
    long max = Math.max(a, b);
    long min = Math.min(a, b);
    while(max % min != 0){
      max = max % min;
      long tmp = max;
      max = min;
      min = tmp;
    }
    BigInteger bi = new BigInteger(String.valueOf(a));
    bi = bi.multiply(new BigInteger(String.valueOf(b)));
    bi = bi.divide(new BigInteger(String.valueOf(min)));
    String tmp = bi.toString();
    return Long.parseLong(tmp);
  }
}


Measured memory_bytes: 23252
// 提出時に消す


import java.util.Scanner;

// 提出時にMainに変更する
public class Main {
    public static void main(String[] args) throws Exception {
        // System.out.println("Hello Java");
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double h = sc.nextDouble();
        double m = sc.nextDouble();

        double allmin = h * 60 + m;

        // ans^2 = a^2 + b^2 + 2ab * cos(Ans)
        double ans = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(Math.abs((allmin / 2) - (m * 6)))));

        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 37460
package main

import "fmt"

func main() {
	var n, a, result int
	fmt.Scanf("%d", &n)
	for ; n > 0; n-- {
		fmt.Scanf("%d", &a)
		result |= a
	}
	for ; result&1 == 0; result >>= 1 {
		n++
	}
	fmt.Printf("%d\n", n)
}


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

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
/*なるべく正の数が多くなるように操作を行う
*/


int main() {
   ll N;
   cin >> N;
   vector<ll> A(N);
   rep(i,N){
       cin >> A[i];
   }
   bool flag0 = false;//0があるか否か
   int c = 0;//A[i]<0となる個数
   rep(i,N){
       if(A[i] < 0) c++;
       if(A[i] == 0) flag0 = true;
   }
   ll ans = 0;
   ll sum = 0;
   ll m = 30000000000;//|A[i]|のmin 
   rep(i,N){
       m = min(m,abs(A[i]));
   }

    rep(i,N){
        sum += abs(A[i]);
    }
   
   if(c%2 == 0 || flag0){//全てを非負にできる
       ans = sum;
   }
   else{//一つを除いて非負にできる
     ans = sum - 2*m;
   }
   cout << ans << endl;
 }


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n,v[100010];
    cin>>n;
    for(int i=0;i<n;i++)cin>>v[i];
    ll ans=1;
    for(int i=1;i<n;i++){
	if(v[i-1]>=v[i])ans++;
    }
    cout<<ans<<endl;
    cout<<n<<endl;
}





Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
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;}
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;}
int const INF = 1001001001;


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

int n;
cin >> n;
vector<P> data1, data2;
rep(i,n) {
    string s;
    cin >> s;
    stack<char> st;
    int r = 0, l = 0;
    rep(j,SZ(s)) {
        if(s[j] == '(') {
            st.push(s[j]);
            l++;
        }
        else {
            if(st.empty() || st.top() == ')') {
                st.push(s[j]);
                r++;
            }
            else {
                st.pop();
                l--;
            }
        }
    }
    // r := )...)の個数 
    // l := (...(の個数
    if(r <= l) data1.push_back(P(r,l));
    else data2.push_back(P(l,r));
}

sort(all(data1));
sort(all(data2),greater<P>());

int HP = 0;
for(auto p : data1) {
    if(HP < p.first) {
        cout << "No" << endl;
        exit(0);
    }
    HP += p.second - p.first;
}

for(auto p : data2) {
    if(HP < p.second) {
        cout << "No" << endl;
        exit(0);
    }
    HP -= p.second - p.first;
}

if(HP == 0) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 11528
n,m=map(int, input().split())
sl=[]
sc=["0"]*(n+1)
for _ in range(m):
  s,c = map(int, input().split())
  if s == 1 and c == 0 and n != 1:
    print(-1)
    exit()
  if s in sl and sc[s] != c:
    print(-1)
    exit()
  sl.append(s)
  sc[s]=c
  
if n >= 2 and sc[1] == "0":
  sc[1]=1
#print(sc)
print(int(''.join(map(str, sc[1:n+1]))))

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s; cin >>s; int n=s.size(),x=1,v=0,ans=0;
  vector<int>r(2019,0);
  for(int i=1; i<=n; i++){
    v=(v+x*(s[n-i]-'0'))%2019;
    x=(x*10)%2019; r[v]++;}
  for(int i=0; i<2019; i++) ans+=r[i]*(r[i]-1)/2;
  cout <<ans+r[0];
return 0;}

Measured memory_bytes: 3708
use std::collections::HashMap;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let (n, p): (usize, usize) = parse!(it, 2);
    let s: Vec<usize> = it
        .next()
        .unwrap()
        .chars()
        .map(|x| x.to_digit(10).unwrap() as usize)
        .rev()
        .collect();
    if p == 2 || p == 5 {
        let mut ret = 0;
        for i in 0..s.len() {
            if s[i] % p == 0 {
                ret += n - i;
            }
        }
        println!("{}", ret);
        return;
    }
    let mut memo = vec![0; p];
    memo[0] = 1;
    let mut cur = 0usize;
    let mut ret = 0usize;
    let mut mul = 1;
    for i in 0..s.len() {
        cur = (cur + s[i] * mul) % p;
        mul = mul * 10 % p;
        ret += memo[cur];
        memo[cur] += 1;
    }
    println!("{}", ret);
}


Measured memory_bytes: 6396
fun main(args: Array<String>) {

    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val hList = readLine()!!.split(" ").map { it.toInt() }

    val sortedHList = hList.sortedDescending()
    val restHList = sortedHList.drop(K)
    val answer = restHList.map { it.toLong() }.sum()
    println(answer)
}

Measured memory_bytes: 85396
package main

import (
	"fmt"
)

func main() {

	var K int
	var S string
	fmt.Scan(&K)
	fmt.Scan(&S)

	if len(S) <= K {
		fmt.Println(S)
	} else {
		ans := S[:K]
		ans += "..."
		fmt.Println(ans)
	}

}


Measured memory_bytes: 1772
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        for (int i = k; i < n; i++) {
            if (a[i] > a[i - k]) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 59996
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main (void)
{
	int a[12];

	for (int i = 0; i < 12; i++)
	{
		cin >> a[i];
	}
	sort (a,a + 12);
	int ng = 0,p = 0;

	for (int j = 0; j < 3; j++)
	{
		for (int i = j + (3 * j); i < j + (3 * j) + 3; i++)
		{
			if (a[i] != a[i + 1])
			{
				ng += 1;
				p += 1;
				break;
			}
		}
		if (p == 1)
		{
			break;
		}
	}
	if (ng != 0)
	{
		cout << "no" << endl;
	}
	else
	{
		cout << "yes" << endl;
	}
}


Measured memory_bytes: 3144
#include <stdio.h>

int n, q, a[100005],com,x,y;

void add(int x, int y) {
    a[x]+=y;
    return;
}

void getsum(int x, int y) {
    int count=0;
    for (int j = x; j <= y; j++)
    {
        count+=a[j];
    }
    printf("%d\n",count);
    return;
}


int main () {
    scanf("%d%d",&n,&q);
    for (int i = 1; i <= q; i++)
    {
        scanf("%d%d%d",&com,&x,&y);
        (com==0)?add(x,y):getsum(x,y);
        
    }
    

}


Measured memory_bytes: 2232
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val input = readLine()!!.split(" ")
    val list :MutableList<Int> = mutableListOf<Int>()
    for(i in 0..n-1){
        list.add(input[i].toInt())
    }

    list.sort()

    var sum = 0

    for(i in 0..n-2){
        sum = sum + list[i]
    }

    if(sum <= list[n-1]){
        println("No")
    }
    else{
        println("Yes")
    }
}


Measured memory_bytes: 38000
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int x=0;
    int m = 0;
    REP(i, s.size()) {
        if(s[i] == 'I')
            x++;
        else
            x--;
        if(x>m)
            m = x;
    }
    cout << m << endl;
}


Measured memory_bytes: 764
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String i = scan.nextLine();
		String[] s = i.split(" ");
		byte a = Byte.parseByte(s[0]);
		byte b = Byte.parseByte(s[1]);
		if(a < 10 && b < 10) {
			System.out.println(a*b);
		}else {
			System.out.println(-1);
		}
	}
}


Measured memory_bytes: 23764
#!/usr/bin/env python3
from collections import Counter
from functools import reduce
from itertools import permutations
import sys

try:
    from typing import Set, Tuple
except ImportError:
    pass


def factor(n: int):
    k = 2
    while n % k == 0:
        n //= k
        yield k
    k = 3
    while n != 1:
        while n % k == 0:
            n //= k
            yield k
        k += 2


def solve(N: int):
    m = reduce(
        lambda a, b: a + b,
        (
            Counter(factor(i))
            for i in range(1, N + 1)
        )
    )
    # 75 = 3 * 5 * 5 = 3 * 25 = 15 * 5
    qss = [
        [74],
        [2, 4, 4],
        [2, 24],
        [4, 14],
    ]
    nums = set()  # type: Set[Tuple[Tuple[int, int], ...]]
    for qs in qss:
        for ps in permutations(m.keys(), len(qs)):
            if any(m[p] < q for p, q in zip(ps, qs)):
                continue
            num = sorted(zip(ps, qs))
            nums.add(tuple(num))
    print(len(nums))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3748
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

f(0, [], []).
f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

main :-
    get_number(A),
    get_string(S),
    (3200 =< A) -> writeln(S) ; writeln("red").


Measured memory_bytes: 8080
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int n, k;
    cin >> n >> k;
    if (k == 1)
        cout << 0;
    else
        cout << n - k;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>

int main(){
  
  int N,K;
  int tmp=0;
  int sum=0;
  scanf("%d %d",&N,&K);
  
  int l[N];
  for(int i=0; i<N; i++){
    scanf("%d",&l[i]);
  }

  for(int i=0; i<N; i++){
    for(int j=0; j<N-1; j++){
      if(l[j] < l[j+1]){
        tmp = l[j];
        l[j] = l[j+1];
        l[j+1] = tmp;
      }
    }
  }

  for(int i=0; i<K; i++){
    sum += l[i];
  }
  printf("%d",sum);

}

Measured memory_bytes: 128
def main():
    N, M = (int(i) for i in input().split())
    if N == 1 and M == 1:
        print(1)
    elif N == 1 or M == 1:
        print(max(N, M) - 2)
    elif N == 2 or M == 2:
        print(0)
    else:
        print((N-2)*(M-2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #pragma GCC optimize("O2")
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef multiset <ll> mms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define deb(x) cout << #x << " " << x << endl;
#define ff first
#define ss second
#define pb(v) push_back(v)
#define lb(v) lower_bound(v)
#define ub(v) upper_bound(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b) {
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s) {
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v) {
	forl(i,v.size()) cout<<v[i]<<" ";
	cout<<"\n";
}
void pa(ll *v, ll size) {
	forl(i,size) cout<<v[i]<<" ";
	cout<<"\n";
}
void removeDups(mv &v) {
	sort(all(v));
	mv::iterator it = unique(v.begin(), v.end());
	v.resize(distance(v.begin(), it));
}
inline ld kthRoot(ld n, ll k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}
ll power(ll x, ll y, ll p) {
	ll res=1;
	x=x%p;
	while(y>0) {
		if(y&1) res = (res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x, ll mod) {
	if(x>=mod) x%=mod;
}

ll mod = 1e9 + 7;

void thisIsMain() {
	ll d, t, s;
	cin>>d>>t>>s;
	if(d <= t * s) cout<<"Yes\n"; else cout<<"No\n";
}

int main(void)
{
	fastio
	ll t = 1;
	// cin>>t;
	while(t--) thisIsMain();
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> cnt(d, vector<int>(d));
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        ++cnt[x % d][y % d];
    }
    vector<vector<int>> ma(d, vector<int>(d));
    vector<vector<int>> mi(d, vector<int>(d));
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < d; ++j) {
            int ng = -2, ok = 1000;
            while (ng < ok - 1) {
                int m = (ok + ng) / 2;
                if ((m + 1) * (m + 1) >= cnt[i][j]) {
                    ok = m;
                }
                else {
                    ng = m;
                }
            }
            ma[i][j] = ok;
            if ((ok + 1) * ok >= cnt[i][j]) {
                mi[i][j] = ok - 1;
            }
            else {
                mi[i][j] = ok;
            }
        }
    }
    vector<P> v;
    int mma = 0;
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < d; ++j) {
            mma = max(mma, ma[i][j]);
        }
    }
    vector<bool> vi(d, false), vj(d, false);
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < d; ++j) {
            if (mi[i][j] == mma) {
                vi[i] = true;
                vj[j] = true;
            }
            else if (ma[i][j] == mma) {
                v.push_back(P(i, j));
            }
        }
    }
    int ans = M;
    int mai = 0;
    for (int i = 0; i < d; ++i) {
        if (vi[i]) mai = i;
    }
    for (int i = 0; i < d; ++i) {
        int maj = 0;
        for (int j = 0; j < d; ++j) {
            if (vj[j]) maj = j;
        }
        for (int j = 0; j < d; ++j) {
            int maa = max(mai, maj) + mma * d;
            if (maa < ans) {
                for (auto& p : v) {
                    int k = p.first, l = p.second;
                    int ofsi = (i <= k ? k - i : k - i + d);
                    int ofsj = (j <= l ? l - j : l - j + d);
                    if (ofsi < ofsj) {
                        maa = max({ maa, ofsi + ma[k][l] * d, ofsj + mi[k][l] * d });
                    }
                    else {
                        maa = max({ maa, ofsi + mi[k][l] * d, ofsj + ma[k][l] * d });
                    }
                }
            }
            ans = min(ans, maa);

            maj = max(0, maj - 1);
            if (vj[j]) {
                maj = d - 1;
            }
        }
        mai = max(0, mai - 1);
        if (vi[i]) {
            mai = d - 1;
        }
    }
    cout << ans << "\n";
    return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    int N,L;
    cin >> N >> L;
    vector<string> S(N);
    string ans = "";
    for (int i = 0; i < N; i++){
        cin >> S[i];
    }
    sort(all(S));
    for (int i = 0; i < N; i++){
        ans += S[i];
    }
    cout << ans << endl;



    return 0;
}


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

using cat = long long;

cat pow(cat a, cat e, cat mod) {
	if(e <= 0) return 1;
	cat x = pow(a, e/2, mod);
	x = x * x % mod;
	return (e&1) ? x * a % mod : x;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	cat mod = 998244353;
	vector< vector<cat> > pw(3001, vector<cat>(3001, 1));
	for(int i = 1; i <= 3000; i++) for(int j = 1; j <= 3000; j++) pw[i][j] = pw[i][j-1] * i % mod;
	vector< vector<cat> > pw_inv(3001, vector<cat>(3001, 1));
	for(int i = 1; i <= 3000; i++) {
		int r = pow(i, mod-2, mod);
		for(int j = 1; j <= 3000; j++) pw_inv[i][j] = pw_inv[i][j-1] * r % mod;
	}
	vector< vector<cat> > cnt(C+1, vector<cat>(D+1, 0));
	vector< vector<cat> > sx(C+1, vector<cat>(D+1, 0));
	vector< vector<cat> > sy(C+1, vector<cat>(D+1, 0));
	cnt[A][B] = 1;
	for(int i = A; i <= C; i++) for(int j = B; j <= D; j++) {
		if(i == A && j == B) continue;
		if(i == A) {
			cnt[i][j] = cnt[i][j-1] * i % mod;
			continue;
		}
		if(j == B) {
			cnt[i][j] = cnt[i-1][j] * j % mod;
			continue;
		}
		cnt[i][j] = ((i-1) * (j-1) + i-1 + j-1) % mod * cnt[i-1][j-1] % mod;
		if(i > 1) sx[i][j] = sx[i-1][j] + (i-2) * cnt[i-2][j-1] % mod * pw_inv[j][i-1] % mod;
		if(j > 1) sy[i][j] = sy[i][j-1] + (j-2) * cnt[i-1][j-2] % mod * pw_inv[i][j-1] % mod;
		cnt[i][j] = (cnt[i][j] + sx[i][j] % mod * pw[j][i] + sy[i][j] % mod * pw[i][j]) % mod;
	}
	cout << cnt[C][D] << "\n";
}


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

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7
typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int a[100001];
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	long long int nowprice = 2;
	long long int ans = a[0] - 1;
	for (int i = 1; i < n; i++){
		if (nowprice == a[i]){
			nowprice++;
		}
		else if (nowprice < a[i]){
			ans += (a[i] - 1) / nowprice;
		}
		// cout << a[i] << " " << ans << " " << nowprice << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353 
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        ll n,s;
        cin>>n>>s;
        ll a[n];
        for(ll i=0;i<n;i++)
            cin>>a[i];
        ll ans=0;
        ll b[n+1];
        b[0]=1ll;
        ll c=fermat_inv(2ll);
        for(ll i=1;i<=n;i++)
            b[i]=(b[i-1]*2ll)%MOD;
        vector <ll> dp(s+1,0ll);
        dp[0]=b[n];
        for(ll i=0;i<n;i++){
            for(ll j=s-a[i];j>=0;j--)
                dp[j+a[i]]=(dp[j+a[i]]+(dp[j]*c)%MOD)%MOD;
        }
        cout<<dp[s]<<"\n";
    }
    return 0;
}

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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }


int main(void) {
    int n, a, b;
    cin >> n;
    if(n==1) {
        cout << "Hello World" << endl;
    }
    else {
        cin >> a >> b;
        cout << a + b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#BFS(幅優先探索のテンプレート)
from collections import deque
inf = float("INF")

N,M = map(int,input().split())
path = [[] for i in range(N)]
dist = [inf for i in range(N)]
visited = [0 for i in range(N)]

for _ in range(M):
    a,b = map(int,input().split())
    a = a - 1
    b = b - 1
    path[a].append(b)
    path[b].append(a)

def bfs(path,root,visited):
    #頂点の距離は0
    dist[root] = 0
    #頂点0を初期ノードに設定、訪問済みにする
    visited[root] = 1
    #初期ノードをキューに追加
    queue = deque([root])
    #BFS開始(キューが空になるまで行う)
    while queue:
        #キューから先頭頂点を取り出す
        current = queue.popleft()
        for i in path[current]:
            #すでに訪問図済みの頂点は探索しない
            if visited[i] == 1:
                continue
            else:
                #新たな頂点iに対して距離情報を更新してキューに追加
                dist[i] = current + 1#距離情報の更新
                visited[i] = 1#訪問済みにする
                queue.append(i)#キューに追加

    if all([i == 1 for i in visited]):
        return "Yes"
    else:
        return "No"

flag = bfs(path,0,visited)
print(flag)

if flag == "Yes":
    for i in range(1,N):
        print(dist[i])

Measured memory_bytes: 38316
#include <iostream>
#include <cstdint>
#include <string>
#include <vector>
#include <algorithm>

using i64 = std::int64_t;

constexpr i64 exp10[] = {
	1,
	10,
	100,
	1000,
	10000,
	100000,
	1000000,
	10000000,
	100000000,
	1000000000
};

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

	std::vector<i64> a(n);
	std::string s;
	for (auto&& e : a) {
		std::cin >> s;
		
		auto i = s.find('.');
		if (i == std::string::npos)
			e = static_cast<i64>(std::stoi(s)) * 1000000000;
		else
			e = static_cast<i64>(std::stoi(s.substr(0, i))) * 1000000000 + static_cast<i64>(std::stoi(s.substr(i + 1))) * exp10[9 - (s.size() - i - 1)];
	}

	i64 ans = 0;
	std::vector count(19, std::vector<int>(19, 0));
	for (auto&& e : a) {
		int c2 = 0, c5 = 0;
		while (e % 2 == 0) {
			e /= 2;
			++c2;
		}
		while (e % 5 == 0) {
			e /= 5;
			++c5;
		}
		c2 = std::min(c2, 18);
		c5 = std::min(c5, 18);

		for (int i = 18 - c2; i <= 18; ++i)
			for (int j = 18 - c5; j <= 18; ++j)
				ans += count[i][j];

		++count[c2][c5];
	}

	std::cout << ans << std::endl;
}


Measured memory_bytes: 4840
import sys
n, y = map(int, input().split())

for a in list(range(n+1)):
	for b in list(range(n+1-a)):
		c = n - a - b
		if a+b+c==n and 10000*a + 5000*b + 1000*c==y:
			print('{} {} {}'.format(a,b,c))
			sys.exit()

print('-1 -1 -1')

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

using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define debug(x) cerr << #x << ":" << x << endl;
#define debug2(x) for(auto a : x) cerr << a << " "; cerr << endl;
#define debug3(x) rep(i, sizeof(x)) cerr << x[i] << " "; cerr << endl;

vector<pii> around = {MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1)};

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

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

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

    auto display = [](vector<int> &v) {
        rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : " ");
    };

    display(a);

    REP(i, 1, n) {
        int v = a[i];
        int j = i - 1;
        while (j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        display(a);
    }
    return 0;
}




Measured memory_bytes: 3168
import fractions

n = list(map(int, input().split()))
n = n[0]
a = list(map(int, input().split()))

left=[0 for i in range(n)]
right=[0 for i in range(n)]
left[0] = a[0]
right[-1] = a[-1]
for i in range(n-2):
    left[i+1] = fractions.gcd(left[i],a[i+1])
    right[-i-2] = fractions.gcd(right[-i-1],a[-i-2])

gcds=[left[n-2], right[1]]
for i in range(n-2):
    gcds.append(fractions.gcd(left[i], right[i+2]))

print(max(gcds))

Measured memory_bytes: 91104
#include <iostream>
using namespace std;
int main()
{
	int L,A,B,C,D; int dayA,dayB,ans;
	cin >> L >> A >> B >> C >> D ;
	if(A%C==0) dayA=A/C; else dayA=A/C+1;
	if(B%D==0) dayB=B/D; else dayB=B/D+1;
	ans=L-max(dayA,dayB);
	cout << ans << '\n' ;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A+B==C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B>C+D) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}



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

using INT = long long;

static INT const P = 1000000007;

template <INT P>
class Modulo;

template <INT P>
Modulo<P> power(INT, INT);

template<INT P>
class Modulo {
  INT val;

  friend
  std::ostream&
  operator<<(std::ostream& os, Modulo const& m) {
    return os << m.val;
  }

  friend
  Modulo<P>
  operator+(Modulo<P> const& a, Modulo<P> const& b) {
    return a.val + b.val;
  }

  friend
  Modulo<P>
  operator*(Modulo<P> const& a, Modulo<P> const& b) {
    return a.val * b.val;
  }

  friend
  Modulo<P>
  operator-(Modulo<P> const& a, Modulo<P> const& b) {
    return P + a.val - b.val;
  }

  friend
  Modulo<P>
  operator/(Modulo<P> const& a, Modulo<P> const& b) {
    return a * power<P>(b.val, P-2);
  }

  static std::vector<INT> _facts;

public:
  Modulo(INT v) : val(v % P) {};

  static INT facts(size_t n) {
    auto s = _facts.size();
    if (s < n+1) {
      _facts.resize(n+1);
      for (size_t i=s; i<n+1; i++) {
        if (i==0) {
          _facts[0] = 1;
        } else {
          _facts[i] = (_facts[i-1] * i) % P;
        }
      }
    }
    return _facts[n];
  }
};

template<INT P>
std::vector<INT> Modulo<P>::_facts;

template <INT P>
Modulo<P>
power(INT a, INT b) {
  if (b == 0) {
    return 1;
  }

  if (b % 2 == 0) {
    auto d = power<P>(a, b/2);
    return d*d;
  }

  return a * power<P>(a, b-1);
}

template <INT P>
Modulo<P>
comb(INT n, INT r) {
  if (n<0 || r<0 || n<r) return 0;
  if (n==0 || r==0) return 1;

  if (n-r<r) r = n-r;

  Modulo<P> a=1;
  for (INT i=0; i<r; i++) a = a*(n-i);
  auto b = Modulo<P>::facts(r);

  return a / b;
}

int main() {
  INT n, a, b;
  std::cin >> n >> a >> b;

  auto ans = power<P>(2, n) - 1;
  ans = ans - comb<P>(n, a);
  ans = ans - comb<P>(n, b);

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int N = sc.nextInt();
        //String S = sc.next();

        int a;
        
        a = (int)Math.pow(100, D) * N;
        if(N==100){
            a = (int)Math.pow(100, D) * (N+1);
        }
        System.out.println(a);
        
        
                
            

        }
        
        

        
        
        }

Measured memory_bytes: 35856
#include <bits/stdc++.h> 
#define ll long long
#define the_num 1000000007
#define ano_num 998244353
#define forn(n) for(int i=0;i<n;i++)
#define For(i,start_i,n) for(int i=start_i;i<n;i++)
#define test int t;cin >> t;while(t--)
#define all(v) v.begin(),v.end()
#define in_arr(arr,n) int arr[n];forn(n) cin >> arr[i];
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define take(data_type,n) data_type n;cin >> n;
using namespace std;
  
int main(){ 
    fast
    take(int,k);
    take(string,s);
    if(s.length() <= k){
        cout << s << '\n';
    }
    else{
        cout << s.substr(0,k).append("...") << '\n';
    }
} 

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>

using namespace std;

uint64_t count_p(int l, uint64_t p, const vector<uint64_t> pnum, const vector<uint64_t> bnum, const vector<uint64_t> sum)
{
	assert(p <= sum[l]);
	if (l == 0) {
		return 1;
	}
	if (p <= 1) {
		return 0;
	}
	if (p >= sum[l] - 1) {
		return pnum[l];
	}

	uint64_t spos = 0;
	bool     is_rev = false;

	if (p == sum[l] / 2 + 1) {
		return pnum[l] / 2 + 1;
	}
	
	if (p > sum[l] / 2 + 1) {
		spos = sum[l] - p;
		is_rev = true;
	}
	else {
		spos = p;
	}

	uint64_t num = count_p(l - 1, spos - 1, pnum, bnum, sum);
	uint64_t ret = is_rev ? pnum[l] - num : num;
	return ret;
}

int main()
{
	int l; uint64_t p; cin >> l >> p;

	// 総数
	vector<uint64_t> pnum(l + 1);
	vector<uint64_t> bnum(l + 1);
	vector<uint64_t>  sum(l + 1);
	pnum[0] = 1; bnum[0] = 0; sum[0] = 1;
	{
		for (int i = 1; i <= l; i++) {
			pnum[i] = (pnum[i-1] * 2) + 1;
			bnum[i] = (bnum[i-1] * 2) + 2;
			sum[i] = bnum[i] + pnum[i];
		}
	}

	uint64_t val = count_p(l, p, pnum, bnum, sum);

	cout << val << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF -1
#define WHITE 0
#define BLACK 1
#define GRAY 2
#define MAX 101
void BFS();
int Dequeue();
void Enqueue(int );
int G[MAX][MAX];
int Q[MAX],head=0,tail=0;
int vertex[MAX],edge[MAX];
int color[MAX];
int time,n;
int d[MAX];  /*頂点からの距離*/
int main() 
{
 int i,j;
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
 scanf("%d%d",&vertex[i],&edge[i]);
 	for(j=1;j<=edge[i];j++)
 	{
		scanf("%d",&G[vertex[i]][j]);
 	}
 }
 BFS(vertex[1]);
 for(i=1;i<=n;i++) printf("%d %d\n",vertex[i],d[vertex[i]]);
 return 0;
}

void BFS(int s)
{
 int i,empty,u,v;
 for(i=1;i<=n;i++)
 {
 	color[i] = WHITE;
 	d[i] = INF;
 }
 color[s] = GRAY;
 d[s] = 0;
 empty = 0;
 Enqueue(s);
 empty++;
 while( empty != 0)
 {
	u = Dequeue();
	empty--;
	for(i=1;i<=edge[u];i++)
	{
		v = G[u][i];
		if(color[v] == WHITE)
		{
			color[v] = GRAY;
			d[v] = d[u]+1;
			Enqueue(v);
			empty++;
		}
	}
 }
 color[u] = BLACK;
}

int Dequeue()
{
 if(head == MAX) head = 0;
 return Q[head++];
}

void Enqueue(int value)
{
 if(tail == MAX) tail =0;
 Q[tail++] = value;
}

Measured memory_bytes: 636
#include <iostream>
using namespace std;
 
int main() {
	string s;
	cin >> s;
	int a, z;
 
	bool flag = true;
	for (int i = 0; i < s.size(); i++) 
	{
		if (s[i] == 'A' && flag) 
		{
			a = i;
			flag = false;
		}
		else if (s[i] == 'Z') z = i;
	}
	cout << z - a + 1 << endl;
}

Measured memory_bytes: 3760
N = [int(input()) for _ in range(5)]
A = []
B = []
C = []
for n in N:
    n = list(str(n))
    n.reverse()
    A.append(int(n[0]))
for a in A:
  if a == 0:
    B.append(100)
  else:
    B.append(a)
    C.append(10-a)
b = min(B)
if b == 100:
  b = 10
print(sum(N)+sum(C)-(10-b))

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

typedef vector <long long> vi;
typedef vector <vi> vvi;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ll long long

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

    ll happy[n][3];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++)
            cin >> happy[i][j];

    ll dp[n][3];
    dp[0][0] = happy[0][0];
    dp[0][1] = happy[0][1];
    dp[0][2] = happy[0][2];

    for (int i = 1; i < n; i++)
        for (int j = 0; j < 3; j++)
            dp[i][j] = max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3]) + happy[i][j];
    
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n";
}


Measured memory_bytes: 4992
mod = 10 ** 9 + 7

H, W = map(int, input().split())
A = [list(input()) for i in range(H)]

dp = [[0] * W for i in range(H)]
dp[0][0] = 1

for i in range(H):
    for j in range(W):
        if i + 1 < H and A[i + 1][j] != '#':
            dp[i + 1][j] += dp[i][j] % mod
        if j + 1 < W and A[i][j + 1] != '#':
            dp[i][j + 1] += dp[i][j] % mod

print(dp[H - 1][W - 1] % mod)

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

int main(){
    int a[3];
    for(int i = 0; i < 3; i++){
        cin >> a[i];
    }

    int sc = 0, fc = 0;
    for(int i = 0; i < 3; i++){
        if(a[i] == 7) sc++;
        if(a[i] == 5) fc++;
    }
    if(sc == 1 && fc == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
t = gcd(a,b)
L = []
for i in range(2,10**6+1):
  while t%i == 0:
    t = t//i
    if i not in L:
      L.append(i)
if t != 1:
  L.append(t)
print(len(L)+1)


Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
INF = 1<<32
MOD = 1000000007  # type: int

# def iterate_tokens():
#     for line in sys.stdin:
#         for word in line.split():
#             yield word
# tokens = iterate_tokens()
# n = int(next(tokens))  # type: int
# k = int(next(tokens))  # type: int


def solve(n: int, k: int):
    fact = [1] * (n+1)
    ifact = [1] * (n+1)
    for i in range(1, n+1):
        fact[i] = i*fact[i-1] % MOD

    ifact[-1] = pow(fact[-1], MOD-2, MOD)
    for i in range(n-1, 0, -1):
        ifact[i] = ifact[i+1] * (i+1) % MOD

    def comb(n, r, MOD=10**9+7):
        return fact[n] * ifact[n-r] * ifact[r] % MOD
    
    
    ans = 0
    for i in range(min(k, n-1)+1):
        ans += comb(n, i) * comb(n-1, i) % MOD
        ans %= MOD
    
    print(ans)

    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(n, k)

if __name__ == '__main__':
    main()

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;


int main() {
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> x(m), y(m);
    REP(i, m) {
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
    }

    vector<bool> isIn(n, false);
    vector<int> ball_num(n, 1);
    isIn[0] = true;

    REP(i, m) {
        if(isIn[x[i]]) isIn[y[i]] = true;
        if(ball_num[x[i]] == 1) {
            isIn[x[i]] = false;
        }
        ball_num[x[i]]--, ball_num[y[i]]++;
    }

    REP(i, n) if(isIn[i]) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int32_t main()
{
	
	int l,r,d;
	cin>>l>>r>>d;

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

	cout<<cnt<<endl;
	return 0;
}

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

int main()
{
	auto pow_mod = [](int64_t a, int64_t n, int64_t mod) {
		int64_t r = 1;
		for (; n; n >>= 1)
		{
			if (n & 1)
			{
				(r *= a) %= mod;
			}
			(a *= a) %= mod;
		}
		return r;
	};

	int64_t n;
	cin >> n;
	vector<int64_t> ds(n);
	for (auto &&d : ds)
	{
		cin >> d;
	}

	map<int64_t, int64_t> mp;
	for (auto &&d : ds)
	{
		mp[d]++;
	}

	if ((ds[0] != 0) || (mp[0] != 1))
	{
		cout << 0 << endl;
		return 0;
	}

	int64_t ans = 1, mod = 998244353;

	int64_t pre = 1;
	for (auto &&p : mp)
	{
		if (0 < p.first && mp.find(p.first - 1) == mp.end())
		{
			cout << 0 << endl;
			return 0;
		}

		(ans *= pow_mod(pre, p.second, mod)) %= mod;
		pre = p.second;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 7296
void main() {
	auto n = ri;
	int[dchar][int] a;
	auto c = new RedBlackTree!dchar;
	foreach(i; 0..n) {
		auto S = rs;
		foreach(j; S) {
			a[i][j]++;
			c.insert(j);
		}
	}
	debug a.writeln;
	int[dchar] b;
	foreach(i; c.array) b[i] = int.max;
	foreach(i; a) {
		debug i.writeln;
		foreach(j; c.array) {
			if(j in i) b[j] = min(b[j], i[j]);
			else b[j] = 0;
		}
	}
	dstring res;
	foreach(i; c.array) {
		res ~= i.repeat(b[i]).array;
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

int main(){
    int r, g, b, n;
    cin >> r >> g >> b;
    n = 100*r + 10*g + b;
    if(n%4 == 0)
        cout << "YES" << '\n';
    else
        cout << "NO" << '\n';
    return 0;
}

Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: -int(x) ,input().split()))
heapq.heapify(a)

for _ in range(m):
    tmp = -heapq.heappop(a)
    tmp //= 2
    heapq.heappush(a,-tmp)
print(-sum(a))


Measured memory_bytes: 14184
M, D = map(int, input().split())
ans = 0
for i in range(M):
    m = i + 1
    for j in range(D):
        d = j + 1
        if len(str(d)) >= 2:
            d_1 = d % 10
            d_10 = d // 10
            if d_1 >= 2 and d_10 >= 2 and d_1 * d_10 == m:
                ans += 1
print(ans)

Measured memory_bytes: 3060
N = int(input())

x = []
y = []
t = []

for i in range(N):
    t_, x_, y_ = map(int, input().split())
    t.append(t_)
    x.append(x_)
    y.append(y_)

ans = "Yes"
for i in range(N):
    if x[i] + y[i] > t[i]:
        ans = "No"
        break
    if t[i] % 2 == 0 and (x[i] + y[i]) % 2 == 1:
        ans = "No"
        break
    elif t[i] % 2 == 1 and (x[i] + y[i]) % 2 == 0:
        ans = "No"
        break

print(ans)


Measured memory_bytes: 11728
#include <stdio.h>
int main(void){
    int a,i,max,mini,n;
    long long int sum;
    max=-1000000;
    mini=1000000;
    sum=0;
    scanf("%d",&n);
 
    for (i=1 ; i<=n ; i=i+1){
        scanf("%d",&a);
        if(mini>a) mini=a;
        if(max<a) max=a;
        sum=sum+a;
    }
    printf("%d %d %lld\n",mini,max,sum);
    return 0;
}



Measured memory_bytes: 2104
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	string s , t ;
	cin>> s >> t ;
	for(ll i=0;i<s.length();i++){
		if(s[i]!=t[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
	int a[8];
	char s[9];
	int z, zz, vi, i, u, sai, ansmost, ans;
	
	scanf("%d", &z);
	
	for (zz = 0; zz < z; zz++) {
		scanf("%s", &s);
		ansmost = 0;
		ans = 0;
		for (vi = 0; vi < 8; vi++) {
			a[vi] = (s[vi] - '0');
		}
		for (i = 0; i < 8; i++) {
			for (u = 0; u < 8; u++) {
				if (a[i] < a[u]) {
					sai = a[i];
					a[i] = a[u];
					a[u] = sai;
				}
			}
		}
		for (i = 0; i < 8; i++) {
			ans = (ans * 10) + a[i];
		}
		for (i = 7; i >= 0; i--) {
			ansmost = (ansmost * 10) + a[i];
		}
		printf("%d\n", ansmost - ans);
	}
	
	return (0);
}	

Measured memory_bytes: 596