akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int d[10+5],vis[10+5];
int n,k,ans;
bool Check(int x)
{
	int num;
	num=x%10;
	for(int i=0;i<=9;i++)
		if(vis[num])
			return false;
	while(x>=10)
	{
		x/=10;
		num=x%10;
		for(int i=0;i<=9;i++)
			if(vis[num])
				return false;
	}
	return true;
}
int Solve()
{
	int ret=n;
	while(!Check(ret))
	{
		ret++;
	}
	return ret;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d",&d[i]);
		vis[d[i]]=1;
	}
	if(k==1&&d[0]==1)
	{
		printf("%d\n",n);
		return 0;
	}
	ans=Solve();
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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

int main(){
    int N, M; cin >> N >> M;
    VI a(N, 0); VB b(N, false);
    if(N != 1) a[0] = 1;
    REP(i, M){
        int s, c; cin >> s >> c;
        --s;
        if(b[s] && a[s] != c){
            cout << -1 << endl;
            return 0;
        }
        a[s] = c;
        b[s] = true;
    }
    if(N != 1 && a[0] == 0){
        cout << -1 << endl;
        return 0;
    }
    REP(i, N) cout << a[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;

int main(void) {
	int a, b;
	int x, i;
	
	while(1) {
		cin >> a >> b;
		if(cin.eof()) { break; }
		
		x = a + b;
		for(i=1; x+1-pow(10, i) > 0; i++);
		cout << i << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n;
    cin >> n;
    set<char> kinds;
    REP(i, n) {
        char color;
        cin >> color;
        kinds.insert(color);
    }
    if (kinds.size() == 3) {
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>

using namespace std;

int main() {
	int n, i, j, top_h, xx, yy, k, abs_h, max_h, start;
	vector<int>x, y, h;
	bool check;
	
	cin >> n;

	x.resize(n);
	y.resize(n);
	h.resize(n);

	for (i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	max_h = -1;

	for (i = 0; i < n; i++) {
		if (h[i] > 0) {
			start = i;
			break;
		}
	}

	for (i = 0; i <= 100; i++) {
		for (j = 0; j <= 100; j++) {
			top_h = h[start] + abs(i - x[start]) + abs(j - y[start]);
			check = true;
			for (k = 0; k < n; k++) {
				if (h[k] == 0) {
					abs_h = abs(i - x[k]) + abs(j - y[k]);
					if (top_h > abs_h) {
						check = false;
						break;
					}
				}
				else {
					abs_h = h[k] + abs(i - x[k]) + abs(j - y[k]);
					if (top_h != abs_h) {
						check = false;
						break;
					}
				}
			}
			if (check) {
				if (max_h < top_h) {
					max_h = top_h;
					xx = i;
					yy = j;
				}
			}
		}
	}

	cout << xx << " " << yy << " " << max_h;

	return 0;
}

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

using namespace std;

int main() {
	string str;
	cin >> str;
	int N = (int)str.size();
	int n = N/2;
	for (int i=0; i<n; i++) {
		char swap = str[i];
		str[i] = str[N-i-1];
		str[N-i-1] = swap;
	}
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <vector>
//#include <algorightm>
#include <map>
#include <tuple>
//#include <cstudio>

int main() {
    int N;
    std::cin >> N;
    int a,b,sum;
    while (N > 0 ){
        std::cin >> a >> b;
        sum+= (b - a) + 1;
        N--;
    }
    std::cout << sum <<std::endl;

}


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToList();
            Console.WriteLine(Search(input[0], input[1], 2019));
        }

        private static int Search(int L, int R, int mod)
        {
            var r = R % mod;
            if (L <= R - r) return 0;

            var ret = mod - 1;
            for (int i = L; i < R; i++)
            {
                for (int j = i + 1; j <= R; j++)
                {
                    var tmp = (i % mod) * (j % mod) % mod;
                    if (tmp < ret) ret = tmp;
                    if (ret == 0) return 0;
                }
            }
            return ret;
        }
    }
}


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

int main () {
    int N;
    int a, b, c, d;

    cin >> N;

    a = N / 1000;
    b = (N % 1000) / 100;
    c = (N % 1000) % 100 / 10;
    d = ((N % 1000) % 100) % 10;

    if ((a == b) && (b == c)) {
      cout << "Yes" << endl;
    } else if ((b == c) && (c == d)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import itertools

import numpy as np

n, m = map(int, input().split())

light = []

for i in range(m):
    light.append(list(map(int, input().split())))

p_list = list(map(int, input().split()))

result = 0
for i in itertools.product([0, 1], repeat=n):
    i = np.array(i)
    s = 0
    for l in light:
        sel = np.array(l[1:]) - 1
        chk = np.sum(i[sel])
        if chk % 2 != p_list[s]:
            break
        s += 1
    
    if s == m:
        result += 1
            

print(result)



Measured memory_bytes: 14412
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

a,b,c=map(int, input().split())
divs=make_divisors(c)
print(sum(1 for i in divs if i>=a and i<=b))


Measured memory_bytes: 5644
# -*- coding: utf-8 -*-


def main():
    from math import floor
    import sys
    input = sys.stdin.readline

    a, b, n = map(int, input().split())

    if n < b:
        print(floor(a * n / b))
    else:
        x = b - 1
        print(floor(a * x / b) - a * floor(x / b))


if __name__ == '__main__':
    main()


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    map<int, int> p;
    for(int i = 0; i < N; i++) {
        p[A[i] - 1] += 1;
    }

    for(int i = 0; i < N; i++) {
        cout << p[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 13556
/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  2020.07.15

 * Solution:
  To be updated.

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <string>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct _{
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
} read;

const int maxn = 100000;
struct P {
	int x[maxn + 5];
};

int N;
P operator * (const P &a, const P &b) {
	P c;
	for (int i = 1; i <= N; i ++)
		c.x[i] = b.x[a.x[i]];
	return c;
}

P inv (const P &a) {
	P b;
	for (int i = 1; i <= N; i ++)
		b.x[a.x[i]] = i;
	return b;
}

P a[10], r, tmp;

int main () {
	N = read;
	int M = read;
	for (int i = 1; i <= N; i ++)
		a[1].x[i] = read;
	for (int i = 1; i <= N; i ++)
		a[2].x[i] = read;
	for (int i = 1; i <= N; i ++)
		r.x[i] = i;

	for (int i = 3; i <= 7; i ++)
		a[i] = inv(a[i - 2]) * a[i - 1];

	int Mx = (M - 2) / 6, My = M - Mx * 6;
	tmp = a[1] * a[4];

	for (int k = Mx; k; k >>= 1) {
		if (k & 1) r = r * tmp;
		tmp = tmp * tmp;
	}

	tmp = inv(r) * a[My] * r;

	for (int i = 1; i <= N; i ++)
		printf("%d ", tmp.x[i]);
	puts("");
}


Measured memory_bytes: 7892
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
using ll = long long;

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

int main() {
	string S = "abcdefghijklmnopqrstuvwxyz";
	
	char C;
	cin >> C;

	int in = C - 'a';
	cout << S[in+1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330 ;
const ll INF = 1e17;

ll a[N];
int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    ll n, r;
    cin >> n >> r;
    if (n >= 10) {
    	return cout << r, 0;
	}
	ll res= 100 * (10- n);
	res += r;
	cout << res;
	    
    return (0);
}

Measured memory_bytes: 764
a, b, c, d, e, f = gets.split.map(&:to_i)

cntA = f / (100 * a)
cntB = f / (100 * b)
maxNodo = 0
maxWater = 0
maxSugar = 0

for numA in 1..cntA
	for numB in 0..cntB
		break if (100*a*numA + 100*b*numB) > f
		cntC = (a*numA+b*numB)*e / c
		cntD = (a*numA+b*numB)*e / d
		for numC in 0..cntC
			for numD in 0..cntD
				sugar = c*numC + d*numD
				break if sugar > e*(a*numA+b*numB)
				water = 100*a*numA + 100*b*numB
				break if (water + sugar) > f
				temp = 100.0*sugar/(water+sugar)
				if maxNodo <= temp
					maxNodo = temp
					maxWater = water
					maxSugar = sugar
				end
			end
		end
	end
end

print(maxWater+maxSugar, " ", maxSugar, "\n")

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

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

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

#A
def A():
    a, b, c = LI()
    ans = 10 ** 5
    ans = min(ans, abs(a - b) + abs(b - c))
    ans = min(ans, abs(a - c) + abs(b - c))
    ans = min(ans, abs(a - c) + abs(a - b))
    print(ans)
    return

#B
def B():
    s, t = S(), S()
    f = 0
    for i in range(len(s)):
        f = f or s[i:] + s[:i] == t
    print(["No","Yes"][f])
    return

#C
def C():
    return

# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!! 
def D():
    n, m = LI()
    d = defaultdict(int)
    for _ in range(m):
        a, b = LI_()
        d[a] = max(d[a], n-b)
    mi = 0
    ans = 0
    for i in range(n - 1):
        if mi < d[i]:
            mi = d[i]
        if i == n - mi - 1:
            mi = 0
            ans += 1
    print(ans)
    return

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


Measured memory_bytes: 55772
S = input()
s = 'keyence'

ans = 'NO'
for i in range(len(s)):
    judge = True
    for j in range(i):
        if S[j] != s[j]: judge = False
    for j in range(-1,-len(s)+i-1,-1):
        if S[j] != s[j]: judge = False
    if judge: ans ='YES'
print(ans)

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

int main() {
  ll n;
  cin >> n;
  map<string, ll> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    m[s]++;
  }

  ll ans = 0;
  for (auto x : m) {
    if (x.second >= 2)
      ans += x.second * (x.second - 1) / 2;
  }
  cout << ans << endl;
}


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

using namespace std;

using ll = long long;

struct Axis
{
  ll x;
  ll y;

  bool operator<(const Axis &another) const
  {
    return (x == another.x) ? y < another.y : x < another.x; //年齢を比較
  };
  //2つのconstを付けないとコンパイルエラーになるので注意!!
};

int main(){

  int n;

  // すべての組み合わせの差を計算

  cin >> n;
  cin.ignore();

  ll tmpx, tmpy;
  Axis a[n];
  for (int i = 0; i < n; i++){
    cin >> tmpx >> tmpy;
    cin.ignore();
    a[i].x = tmpx;
    a[i].y = tmpy;
  }

  sort(a, a +n); // xの差を非負整数に
  
  // すべての組み合わせの差を計算
  int m = n * (n-1) / 2;
  Axis d[m];
  int ptr = 0;
  for (int i = 0; i < n; i++){
    for (int j = i + 1; j < n; j++){
      tmpx = a[j].x - a[i].x; // 正
      tmpy = a[j].y - a[i].y;
      d[ptr].x = tmpx;
      d[ptr].y = tmpy;
      ++ptr;
    }
  }

  /*
  for (int i = 0; i < ptr; i++){
    cout <<"i = " << i << " p = " << d[i].x << " q = " << d[i].y << endl;
  }
  */
  

  //cout << endl;
  sort(d, d + ptr);

  int cnt = 1;
  int tmpcnt = 1;

  /*
  for (int i = 0; i < ptr; i++){
    cout <<"i = " << i << " p = " << d[i].x << " q = " << d[i].y << endl;
  }
  */
  
  for (int i = 0; i < ptr - 1; i++){
    if((d[i].x == d[i+1].x) && (d[i].y == d[i + 1].y)){
      //cout << "UPDATE" << endl;
      ++tmpcnt;
    } else {
      if(tmpcnt > cnt){
        //cout << "UPDATEC" << endl;
        cnt = tmpcnt;
      }
      tmpcnt = 1;
    }
  }

  if(n - cnt == 0){
    cout << 1 << endl;
    return 0;
  }

  cout << n - cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
        }
        Arrays.sort(a);
        int answer = a[N-1]-a[0];
        System.out.println(answer);
    }
}


Measured memory_bytes: 21844
N, K = map(int, input().split())
P = [int(x) for x in input().split()]
B = [0] * (N+1)
for i in range(1, N+1):
    B[i] = P[i-1] + B[i-1]
ans = 0
for i in range(K, N+1):
    ans = max(ans, B[i] - B[i-K])

print((ans+K)/2)

Measured memory_bytes: 24676
N=int(input())
A,B=map(int,input().split())
p = list(map(int,input().split()))
c=[]
d=[]
e=[]
for i in range(N):
    if p[i]<=A:
        c.append(p[i])
    if A+1 <= p[i] <= B:
        d.append(p[i])
    if B+1 <= p[i]:
        e.append(p[i])

        
print(min(len(c),len(d),len(e)))


Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#define ll long long
using namespace std;

int main()
{
    char a;
    cin >> a;
    cout << (char)(a + 1) << endl;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    # 降順にぶちこむ人を選んでいく。
    # 実際に手で書けばわかるが、ある数がn個あるとき、
    # n*2回心地よさを感じるようになる。
    # ただし、最初の1個目だけは心地よさ0なので、そこを考慮する
    dic = {}
    for a in As:
        if not a in dic: dic[a] = 0
        dic[a] += 1

    keys = []
    for key in dic.keys():
        keys.append(key)
    keys.sort(reverse=True)

    ans = 0
    n = N - 1
    dic[keys[0]] -= 1
    ans += keys[0]
    n -= 1

    for i, key in enumerate(keys):
        if dic[key] == 0:
            continue

        if (dic[key]*2) <= n:
            ans += key*(dic[key]*2)
            n -= dic[key]*2
        else:
            ans += key*n
            n -= n
            break

    print(ans)


if __name__ == "__main__":
    solve()


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

int main(void) {
    int* array;
    int n, count;
    
    while(cin >> n) {
        array = new int[n + 1];
        count = 0;

        for(int i = 0; i <= n; ++i) {
            array[i] = 0;
        }
        for(int i = 2; i <= n; ++i) {
//iの倍数に全て印をつける。
            if(array[i] == 0) {
                for(int j = i; j <= n; j += i) {
                    array[j] = 1;
                }
                count++;
            }
        }
        cout << count << endl;
        delete[] array;
    }
}


Measured memory_bytes: 7200
n, m = map(int, input().split())
X = list(map(int, input().split()))
A = []
if n >= m:
  print(0)
else:
  Y = sorted(X)
  for i in range(m-1):
    A.append(Y[i+1]-Y[i])
  B = sorted(A)
  if n-1 != 0:
    del B[-(n-1):]
  print(sum(a for a in B))

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	long long int n, k; cin >> n >> k;
	long long int a = n - (n/k)*k;
	long long int b = abs(a-k);
	cout << min(a, b) << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {


        //long[] a = new long[n];


        //string[] s = Console.ReadLine().Split(' ');

        int n = int.Parse(Console.ReadLine());


        for (int i = 1; i <= n; i++)
        {
            if (i % 3 == 0 || i % 10 == 3)
            {
                Console.Write(" {0}",i);
                continue;
            }
            int x = i;
            while(x>0)
            {
                x = x / 10;
				if (x % 10 == 3)
				{
					Console.Write(" {0}", i);
                    break;
				}
            }


        }

        Console.WriteLine("");


    }
}

Measured memory_bytes: 9292
#include<stdio.h>
       
int main(void){
       
int a,b,c,i;
int n=0;
scanf("%d %d %d",&a,&b,&c);
 
for(i=a;i<=b;i++){
 if(c%i==0){
  n++;
 }
}
 
printf("%d\n",n);
  
return 0;
}


Measured memory_bytes: 2096
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()

	ans := n * n * n
	fmt.Println(ans)
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC103 D - Islands War

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  vector<pair<int, int> > ab(M, pair<int, int>());
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int> > > pq;
  REP(i, M){
    int a, b; cin >> a >> b;
    ab[i] = {a, b};
  }
  sort(ab.begin(), ab.end());
  vector<int> a(M, 0);
  REP(i, M){
    pq.push({ab[i].second, i});
    a[i] = ab[i].first;
  }
  int ans = 0, idx = -1;
  while(!pq.empty()){
    auto cur = pq.top(); pq.pop();
    if(cur.second <= idx) continue;
    auto itr = upper_bound(a.begin(), a.end(), cur.first-1);
    itr--;
    idx = itr-a.begin();
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2552
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   long N = sc.nextLong();
   long M = sc.nextLong();
   
   long ans = 1;
   if(Math.abs(N-M)>1) System.out.println(0);
   else
   {
     if(N==M) 
     {
       for(long i=N;i>=1;i--)
       {
         ans*= i;
         ans = ans%1000000007;
       }
       ans = ans*ans;
       ans = ans%1000000007;
       ans *=2 ;
       ans = ans%1000000007;
     }
     else
     {
       if(N+1==M)
       {      
         for(long i=N;i>=1;i--)
         {
           ans*= i;
           ans = ans%1000000007;
         }
         ans = ans*ans;
         ans = ans%1000000007;
         ans *= N+1;
         ans = ans%1000000007;
       }
       else
       {
         for(long i=M;i>=1;i--)
         {
           ans*= i;
           ans = ans%1000000007;
         }
         ans = ans*ans;
         ans = ans%1000000007;
         ans *= M+1;
         ans = ans%1000000007;         
       }
     }
    System.out.println(ans);
   }
 }
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

class UnionFind {
public:
   vector<int> parent, rank;

   UnionFind(int size) {
      parent.resize(size, 0);
      rank.resize(size, 0);
      for (int i = 0; i < size; i++) {
         parent[i] = i;
      }
   }

   int find(int x) {
      if(parent[x] == x) {
         return x;
      } else {
         return parent[x] = find(parent[x]);
      }
   }

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

      if (rank[x] < rank[y]) {
         parent[x] = y;
      } else {
         parent[y] = x;
         if (rank[x] == rank[y]) rank[x]++;
      }
   }

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

int main() {
   int n, k, l;
   cin >> n >> k >> l;
   UnionFind s(n), t(n);
   rep (i, k) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      s.unite(a, b);
   }
   rep (i, l) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      t.unite(a, b);
   }

   map<pair<int, int>, int> m;
   rep (i, n) {
      m[{s.find(i), t.find(i)}]++;
   }
   rep (i, n) {
      printf("%d%c", m[{s.find(i), t.find(i)}], i == n-1? '\n':' ');
   }

   return 0;
}

Measured memory_bytes: 15104
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

string N;

int main() {

	cin >> N;

	N[0]++;

	cout << N << endl;

	return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = int.Parse(Console.ReadLine());
        double[] x = new double[n];
        double[] y = new double[n];


        for (int i = 0; i < n; i++)
        {
            string[] input = Console.ReadLine().Split(' ');
            x[i] = double.Parse(input[0]);
            y[i] = double.Parse(input[1]);
        }

        double tmp1 = 1;
        for (int i = n; i > 0; i--)
        {
            tmp1 *= i;
        }

        //順列作成
        double tmp2 = 0;
        var range = Enumerable.Range(0, n).ToArray();
        foreach (var item in AllPermutation(range))
        {
            for (int i = 0; i < item.Length - 1; i++)
            {
                tmp2 += Math.Sqrt((x[item[i]] - x[item[i + 1]]) * (x[item[i]] - x[item[i + 1]]) + (y[item[i]] - y[item[i + 1]]) * (y[item[i]] - y[item[i + 1]]));
            }

        }


        Console.WriteLine(tmp2 / tmp1);
    }


    static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable
    {
        var a = new List<T>(array).ToArray();
        var res = new List<T[]>();
        res.Add(new List<T>(a).ToArray());
        var n = a.Length;
        var next = true;
        while (next)
        {
            next = false;

            // 1
            int i;
            for (i = n - 2; i >= 0; i--)
            {
                if (a[i].CompareTo(a[i + 1]) < 0) break;
            }
            // 2
            if (i < 0) break;

            // 3
            var j = n;
            do
            {
                j--;
            } while (a[i].CompareTo(a[j]) > 0);

            if (a[i].CompareTo(a[j]) < 0)
            {
                // 4
                var tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                Array.Reverse(a, i + 1, n - i - 1);
                res.Add(new List<T>(a).ToArray());
                next = true;
            }
        }
        return res;
    }

}

Measured memory_bytes: 22360
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 2019;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

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

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

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

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

int main()
{
  string s;
  cin >> s;

  ll arr[200100];
  ll count[3000];

  // int keta = 0;
  // for (int i = s.size() - 1; i >= 0; i--)
  // {
  //   struct mint m(10);
  //   struct mint tmp(s[i] - '0');
  //   int val = (tmp * m.pow(keta)).x;
  //   arr[i] = (arr[i + 1] + val) % 2019;
  //   count[arr[i]]++;
  //   keta++;
  // }

  ll keta = 1;
  reverse(s.begin(), s.end());
  rep(i, s.size())
  {
    ll val = (keta * (s[i] - '0')) % 2019;
    if (i == 0)
      arr[i] = val % 2019;
    else
      arr[i] = (arr[i - 1] + val) % 2019;
    count[arr[i]]++;
    keta *= 10;
    keta %= 2019;
  }

  ll ans = 0;
  rep(i, 2019)
  {
    if (i == 0)
    {
      if (count[i] == 0)
        continue;
      if (count[i] == 1)
      {
        ans++;
        continue;
      }
      ans += ((count[i] + 1) * count[i]) / 2;
      continue;
    }

    ans += (count[i] * (count[i] - 1)) / 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5308
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using lint = long long;
using ldouble = long double;

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

    lint ok = -1, ng = 1LL << 60;
    while (ng - ok > 1) {
        lint mid = (ok + ng) / 2;

        lint rem = mid;
        for (int i = 0; i < N - 1; ++i) {
            rem -= (rem + K - 1) / K;
        }

        (rem == 0 ? ok : ng) = mid;
    }

    cout << ok << endl;
    return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main( void ){
  long long a,b,c; cin >> a >> b >> c;
  if( a % 2 == 0 || b%2 == 0 || c % 2 == 0){
    cout << 0 << "\n";
  }else{
    cout << min(a*b,min(b*c, a*c)) << "\n";
  }
}

Measured memory_bytes: 764
use proconio::input;

fn main() {
    input! {
        p: (i32, i32, i32),
    };
    let n = p.0;
    let a = p.1;
    let b = p.2;
    let mut cnt = 0;
    for i in 1..n+1 {
        let mut x = i;
        let x4 = x / 10000;
        x -= x4 * 10000;
        let x3 = x / 1000;
        x -= x3 * 1000;
        let x2 = x / 100;
        x -= x2 * 100;
        let x1 = x / 10;
        x -= x1 * 10;
        let x0 = x;
        let xs = x4 + x3 + x2 + x1 + x0;
        if a <= xs && xs <= b {
            cnt += i;
        }
    }
    println!("{}", cnt);
}


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

r = int((N*2)**0.5)-1
#print(r)
if (r+1)*(r+2)//2!=N:
    print("No")
    exit()
cnt = 1
L = [[] for i in range(r+2)]
for i in range(1, r+2):
    for j in range(i+1, r+3):
        L[i-1].append(cnt)
        L[j-1].append(cnt)
        cnt += 1
print("Yes")
print(r+2)
for i in range(r+2):
    print(r+1, *L[i])


Measured memory_bytes: 9416
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

unsigned long long pow(unsigned long long n, int k) {
	unsigned long long res = 1;
	while (k--) {
		res *= n;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	unsigned long long ans = 1;
	vector<unsigned long long> a(n);
	for (auto&& i : a) {
		cin >> i;
	}
	sort(begin(a), end(a));
	if (a[0] == 0) {
		cout << 0 << "\n";
		return 0;
	}
	for (auto&& i : a) {
		if (pow(10ull, 18) / ans < i) {
			ans = -1;
			break;
		}
		ans *= i;
	}
	cout << static_cast<long long>(ans) << "\n";
}


Measured memory_bytes: 3964
main = getLine >>= mapM_ print . itp1_10_b . map read . words
itp1_10_b [a,b,c] = [s,l,h]
 where
  s = a * h / 2.0
  l = a + b + (sqrt $ (a - (cos (c * pi / 180.0) * b))^2 + h^2)
  h = sin (c * pi / 180.0) * b

Measured memory_bytes: 4092
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef vector<vector<int>> Graph;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area
ll MOD = 1000000007;
//main area
int main(){
    ll n;
    cin >> n;
    if(n == 1) cout << 0 << endl;
    else if(n == 2) cout << 2 << endl;
    else{
        ll cnt10 = 1, cnt9 = 1, cnt8 = 1;
        rep(i,n){
            cnt10 *= 10;
            cnt9 *= 9;
            cnt8 *= 8;
            cnt10 %= MOD;
            cnt9 %= MOD;
            cnt8 %= MOD;
        }
        ll ans = cnt10 - 2*cnt9 + cnt8;
        ans %= MOD;
        if(ans < 0) ans += MOD;
        cout << ans << endl;
    }
}
/*



*/

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    int n;
    cin>>n;
    vpii v;
    rep(i,n){
        int y;
        cin>>y;
        v.pb(mp(y,i+1));
    }
    Sort(v);
    rep(i,n){
        fin(v[i].second);
    }
    
//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 1780
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;

int main() {
	
	int n;
	cin >> n;
	
	if (n == 0) {
		cout << "0" << endl;
		return 0;
	}

	string str = "";

	while (n != 0) {
		int r = n % 2;

		if (r < 0)r += 2;

		n = (n - r)/(-2);

		if(r==1){
			str += "1";
		}
		else {
			str += "0";
		}
	}

	reverse(str.begin(), str.end());

	cout << str << endl;

}

Measured memory_bytes: 256
n = int(input())
s = [str(input()) for _ in range(n)]

#s = ['b','b','c','ab','ab','aa','aa','a','a']

c ={}
for i in s :
  if i in c :
    c[i] += 1
  else :
    c[i] = 1

x = max(c.values())

ans = []
for i in c.items(): # i ('a', 2)
  if i[1] == x :
    ans.append(i[0])

ans.sort()
out = '\n'.join(ans)
print(out)

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

using namespace std;

int main(){
    int n;
    vector<int> di;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        di.push_back(tmp);
    }

    int total = 0;
    for (int x = 0; x < di.size(); x++){
        if(x >= di.size()){
            break;
        }

        for (int y = x + 1; y < di.size(); y++)
        {
            total += di[x] * di[y];
        }
    }

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

const int N = 1e3 + 5;

vector<a2> g[N];

ll d[N];
int cnt[N];
bool in[N];
bool valid[N];

const ll inf = LLONG_MAX;
int n,m;

bool dfs(int x){
	if(in[x])return 0;	
	in[x] = 1;
	if(x == n-1)return 1;
	bool res = 0;
	for(a2 a:g[x])res |= dfs(a[0]);
	return res;
}

bool spfa(){
	fill(d,d+N,inf);
	memset(in,0,sizeof(in));
	queue<int> q;
	q.push(0);
	d[0] = 0;
	in[0] = 1;
	while(q.size()){
		int u = q.front();
		in[u] = 0;
		q.pop();
		for(a2 e:g[u]){
			if(!valid[e[0]])continue;
			if(d[u] + e[1] < d[e[0]]){
				d[e[0]] = d[u] + e[1];
				if(!in[e[0]]){
					in[e[0]] = 1;
					q.push(e[0]);
					++cnt[e[0]];
					if(cnt[e[0]] == n)return 0;	
				}
			}
		}
	}
	return 1;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	rep(i,0,m){
		int x,y,w;
		cin >> x >> y >> w;
		--x,--y;
		g[x].push_back(a2{y,-w});
	}
	rep(i,0,n){
		memset(in,0,sizeof(in));
		valid[i] = dfs(i);
	}
	bool val = spfa();
	if(val){
		cout << -d[n-1] << '\n';
	}
	else{
		cout << "inf" << '\n';
	}
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[2020], invf[2020];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
	int n, k;
	cin>>n>>k;
	int a[22];
	for(int i=0; i<k; i++){
		cin>>a[i];
	}
	fac(n);
	ll dp[22][1010]={};
	dp[0][0]=1;
	for(int i=0; i<k; i++){
		for(int j=0; j<=n; j++){
			for(int l=j; l<=min(n, a[i]+j); l++){
				(dp[i+1][l]+=dp[i][j]*comb(n-j, l-j)%MOD*comb(n-(l-j), a[i]-(l-j)))%=MOD;
			}
		}
	}
  cout<<dp[k][n]<<endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int A[51];
pair<int,int> P[51];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	K++;
	int sum=0;
	FOR(i,N) {
		cin>>A[i];
	}
	
	vector<int> T;
	int pre=-1;
	while(K--) {
		int mi=1010,tar=-1;
		FOR(i,N) if(i!=pre) {
			if(A[i]==0) return _P("-1\n");
			if(A[i]<mi) mi=A[i],tar=i;
		}
		FOR(i,N) if(i!=pre&&i!=tar) {
			T.push_back(i+1);
			A[i]--;
		}
		T.push_back(tar+1);
		A[tar]--;
		pre=tar;
	}
	
	cout<<T.size()<<endl;
	FORR(t,T) cout<<t<<" ";
	cout<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner a = new Scanner(System.in);
        int sec = a.nextInt();
        if (sec >= 0 && sec < 86400){
            int hours = sec / 3600;
            int minutes = (sec % 3600) / 60;
            int second = (sec % 3600) % 60;

            System.out.println(hours + ":" + minutes + ":" + second);
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 17356
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		int []P = nextIntArray(N);

		int cnt = 1,min = P[0];
		for(int i=1;i<N;i++) {
			if(min >= P[i]) {
				cnt++;
				min = P[i];
			}
		}
		out.println(cnt);
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}

	long lcm(long m, long n) {
	        return m * n / gcd(m, n);
	}
}

Measured memory_bytes: 51160
#include <iostream>
#include <stdio.h>

#include <string>

#include <vector>
#include <list>
#include <map>

#include <algorithm>
#include <utility>

using namespace std;

int main(const int argc, const char **argv){
  int N;
  scanf("%d", &N);

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

  int prev_min = 1000000000;

  while (true){
    int min = 1000000000;
    int min_idx = 0;

    for(int i = 0; i < A.size(); i++){
      if(A[i] < min && A[i] != 0){
        min = A[i];
        min_idx = i;
      }
    }

    if(prev_min == min){
      break;
    }else{
      prev_min = min;
    }

    for(int i = 0; i < A.size(); i++){
      if(i != min_idx){
        A[i] = A[i] % min;
      }
    }
  }

  printf("%d\n", prev_min);

  return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10 ** 6)
from itertools import combinations_with_replacement

def check(abcd, pattern):
    result = 0
    for a,b,c,d in abcd:
        if (pattern[b-1] - pattern[a-1]) == c:
            result += d
    return result

def main():
    N, M, Q = map(int, input().split())
    abcd = [list(map(int, input().split())) for _ in range(Q)]
    ans = 0
    for pattern in combinations_with_replacement(range(1, M+1), N):
        ans = max(ans, check(abcd, pattern))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 80112
#include<set>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
const int MaxN =100000+100;
    using namespace std;
    struct node
    {
    	int da;
    	int flag;
    }Node[2*MaxN];
    int len=0;
    bool cmp(struct node a,struct node b)
    {
    	return a.da>b.da;
    }
    int main()
    {
    	int N;
    	int H;
    	cin>>N>>H;
    	for(int i=0;i<N;i++)
    	{
    		int a,b;
    		cin>>a>>b;
    		Node[len].da=a;
    		Node[len++].flag=0;
    		Node[len].da=b;
    		Node[len++].flag=1;
    	}
    	sort(Node,Node+len,cmp);
    	int at=0;
    	for(int i=0;i<len && H>0;i++)
    	{
    		if(Node[i].flag==1)
    		{
    			H-=Node[i].da;
    			at++;
    		}
    		else
    		{
    				int num=H/Node[i].da;
    				if(H%Node[i].da!=0)
    					num++;
    				at+=num;
    				break;
    		}
    	}
    	cout<<at<<endl;
    	return 0;
     } 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T){
  cout << (S == T.substr(0, T.size()-1) ? YES : NO) << endl;
}

signed main(){
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
}


Measured memory_bytes: 3604