akhauriyash/Code-Regression huggingface dataset:
// Problem : E - Max-Min Sums
// Contest : AtCoder Beginner Contest 151
// URL : https://atcoder.jp/contests/abc151/tasks/abc151_e
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include <bits/stdc++.h>

using namespace std;

int N, K;
long long MOD = 1e9+7;
long long arr[1000005];
long long fact[1000005];

long long mult(long long a, long long b){
	return (a*b)%MOD;
}

long long add(long long a, long long b){
	return (a+b)%MOD;
}

long long qikpow(long long b, long long e){
	if(!e){
		return 1;
	}
	long long ret = qikpow(b, e/2);
	ret = mult(ret, ret);
	if(e&1){
		ret = mult(ret, b);
	}
	return ret;
}

long long divd(long long a, long long b){
	return mult(a, qikpow(b, MOD-2));
}

long long sub(long long a, long long b){
	a = add(a, -b);
	if(a < 0){
		a += MOD;
	}
	return a;
}

long long choose(long long n, long long r){
	if(n-r < 0){
		return 0;
	}
	return divd(fact[n], mult(fact[r], fact[n-r]));
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> K;
	fact[0] = 1;
	for(int i = 1; i<=N; i++){
		fact[i] = mult(i, fact[i-1]);
		cin >> arr[i];
	}
	sort(arr+1, arr+1+N);
	long long ans = 0;
	for(int i = 1; i<=N; i++){
		ans = add(ans, mult(arr[i], choose(i-1, K-1)));
		ans = sub(ans, mult(arr[i], choose(N-i, K-1)));
	}
	cout << ans << "\n";
}

Measured memory_bytes: 5120
def pay500():
    a_max = min(int(x / 500), a)

    return [x - 500 * i for i in range(a_max + 1)]


def pay100(pay: int):
    b_max = min(int(pay / 100), b)
    return [pay - i * 100 for i in range(b_max + 1)]


def pay50(pay_list: list):
    def canPay(pay: int):
        if 50 * c >= pay:
            return True
        else:
            return False

    return list(map(canPay, pay_list))


def judge():
    def countTrue(l: list, count: int, remain: int):
        count += l[remain].count(True)
        if remain > 0:
            countTrue(l, count, remain - 1)
        else:
            print(count)

    a_list = pay500()
    b_list = list(map(pay100, a_list))
    c_list = list(map(pay50, b_list))
    c_len = len(c_list)

    countTrue(c_list, 0, c_len - 1)


a = int(input())
b = int(input())
c = int(input())
x = int(input())

judge()


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

using namespace std;
using ll = long long;
using vi = vector<int>;

// 1 2 1  1 2 1  1 2 1

//     1 2 1
// l   0 1 0
// r   0 1 0

// 1 : r(i) * k + l(i) * (k - 1)
// 2 : r(i) * (k - 1) + l(i) * (k - 2)
// 3 : r(i) * (k - 2) + l(i) * (k - 3)

int const MOD = 1e9 + 7;

inline ll add(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; }
inline ll mult(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }

int solve(int n, ll k, vi a)
{
    vi l(n, 0), r(n, 0);
    for (int i = 0; i < n; ++i)
    {
        for (int j = i - 1; j >= 0; --j)
        {
            l[i] += (a[j] < a[i]);
        }
        for (int j = i + 1; j < n; ++j)
        {
            r[i] += (a[j] < a[i]);
        }
    }

    ll ans   = 0;
    ll sumk  = (k * (k + 1)) / 2;
    ll sumk1 = sumk - k;
    for (int i = 0; i < n; ++i)
    {
        ans = add(ans, add(mult(r[i], sumk), mult(l[i], sumk1)));
    }

    return ans;
}

int main(void)
{
    int n, k;
    vi  a;
    cin >> n >> k;
    a.resize(n);

    for (auto &ai : a)
        cin >> ai;

    cout << solve(n, k, a) << endl;

    return 0;
}


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

int main(){
	int l,r,d;
	cin>>l>>r>>d;
	int count = 0;
	for(int i = l;i<=r;i++){
		if(i%d==0) count++;
	}

	cout<<count;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <string>

using namespace std;

int n;
map<string, vector<string> > mp;
string q;
set<string> ans, used;

void dfs(string v)
{
  used.insert(v);
  if(mp[v].size() == 0){
    ans.insert(v);
    return;
  }
  for(auto it = mp[v].begin(); it != mp[v].end(); it++){
    if(!used.count(*it)) dfs(*it);
  }
}

int main(void)
{
  while(1){
    cin >> n;
    if(n == 0) break;

    mp.clear();

    string s;
    string name; int p;
    for(int i = 0; i < n; i++){
      cin >> s;
      for(int j = 0; j < s.size(); j++){
        if(s[j] == ':'){
          name = s.substr(0, j);
          p = j;
          break;
        }
      }
      string t;
      for(int j = p+1; j < s.size(); j++){
        if(s[j] >= 'a' && s[j] <= 'z') t += s[j];
        else mp[name].push_back(t), t = "";
      }
      if(i == 0) q = name;
    }

    /*for(auto it = mp.begin(); it != mp.end(); it++){
      cout << it->first << " : ";
      for(int i = 0; i < it->second.size(); i++) cout << it->second[i] << " "; cout << endl;
    }*/

    ans.clear(), used.clear();
    dfs(q);
    cout << ans.size() << endl;
  }

  return 0;
}



Measured memory_bytes: 3312
l, r = map(int, input().split())
p = l // 2019
if 2019 * (p + 1) <= r:
    print(0)
    exit()
ans = 2019
for i in range(l, r):
    for j in range(i+1, r+1):
        ans = min(ans, i*j%2019)
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define PI (atan(1)*4)

using namespace std;

int main()
{
	double a, b, n, i, x;
	double rad;
	cin >> a >> b >> x;
	if(2*x <= a*a*b) {
		rad = atan((a*b*b)/(2*x));
	} else {
		rad = atan(2*((b/a) - x/(a*a*a)));
	}
	// cout << rad*180.0/PI << endl;
	printf("%.7lf\n", rad*180.0/PI); 
	return 0;
}


Measured memory_bytes: 512
import sys

n, t = [int(_) for _ in input().split()]
inputList = [[ int(_) for _ in input().split()] for _ in range(n)]
sortedList = sorted(inputList, key=lambda x:x[0])

for data in sortedList:
  cc, tt = data
  if tt <= t:
    print(cc)
    sys.exit()

print("TLE")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    int A, B, H, M; cin >> A >> B >> H >> M;
    double pi = 3.14159265358979;
    double X = H * 30 + M * 0.5, Y = M * 6;
    double angle = min(abs(X - Y), abs(360 - (X - Y)));  
    double ans = pow(A, 2) + pow(B, 2) - 2 * A * B * cos(angle / 180.0 * pi);
    ans = sqrt(ans);
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 4228
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10%2019
    mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()

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

typedef long long LL;
typedef unsigned long long ULL;
#define int long long
#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') bo = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		res = (res << 1) + (res << 3) + ch - '0';
		ch = getchar();
	}
	return bo * res;
}

template <typename T>
void read(T &x) {
	x = read();
}

template <typename T, typename... Argv>
void read(T &a, Argv &... argv) {
	read(a);
	read(argv...);
}

const int N = 3000, M = 100010;
LL a[N][N], prime[M], tot;
bool vis[M];

void init(int n) {
	for (int i = 2; i <= n; ++ i) {
		if (!vis[i]) prime[++ tot] = i;
		for (int j = 1; j <= tot && prime[j] * i <= n; ++ j) {
			vis[i * prime[j]] = 1;
			if (i % prime[j] == 0) break;
		}
	}
}

LL lcm(LL x, LL y) {
	if (!x || !y) return x | y;
	LL o = std::__gcd(x, y);
	return x / o * y;
}

signed main() {
	init(M - 1);
	int n = read();
	if (n == 2) return puts("4 7\n23 10"), 0;
	for (int i = 1; i <= n; ++ i) {
		for (int j = ((i + 1) & 1) + 1; j <= n; j += 2) {
			a[i][j] = prime[(i + j) / 2] * prime[n + (i - j) / 2 + (n + 1) / 2];
		}
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = (i & 1) + 1; j <= n; j += 2) {
			a[i][j] = lcm(lcm(a[i - 1][j], a[i][j - 1]), lcm(a[i + 1][j], a[i][j + 1])) + 1;
		}
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= n; ++ j) {
			printf("%lld ", a[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 16000
import itertools

N = int(input())
li = list(map(int, input().split()))
if N <= 2:
    print('0')
else:
    cnt = 0
    for team in itertools.combinations(li, 3):
        i = team[0]
        j = team[1]
        k = team[2]
        if i + j > k and j + k > i and k + i > j:
            if i != j and j != k and k != i:
                cnt += 1
    print(cnt)

Measured memory_bytes: 67856
#include<stdio.h>

int main(void){
  int n,tmp,c=0;
  scanf("%d",&n);
  int l[n];
  for(int i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){

      if(l[i]>l[j]){
        tmp=l[i];
        l[i]=l[j];
        l[j]=tmp;
      }
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(l[i]!=l[j] && l[j]!=l[k] && l[i]+l[j]>l[k]){
          c++;
        }
      }
    }
  }
  printf("%d\n",c);
return 0;
}
          
      


Measured memory_bytes: 1680
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve(){
	LL h,w;
	cin>>h>>w;
	if(w==1 || h==1){
		cout<<1<<endl;
		return;
	}
	cout<<(1ll * h*w+1)/2ll<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

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

        int n = sc.nextInt();
        sc.nextLine();

        int f[][] = new int[n][10];
        int p[][] = new int[n][11];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 10; j++) {
                f[i][j] = sc.nextInt();
            }
            sc.nextLine();
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 11; j++) {
                p[i][j] = sc.nextInt();
            }
            sc.nextLine();
        }
        sc.close();

        int min = Integer.MIN_VALUE;
        for (int i = 1; i < (1 << 10); i++) {
            int cc = 0;
            for (int j = 0; j < n; j++) {
                int c = 0;
                for (int k = 0; k < 10; k++){
                    if ((i >> k & 1) == 1 && f[j][9 - k] == 1) {
                        c++;
                    }
                }
                cc += p[j][c];
            }
            if (min < cc) {
                min = cc;
            }
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 26836
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int binary(vector<int> a,lint key) {
  lint left = 0;
  lint right = a.size();
  while(left<right){
    lint mid = (left+right)/2;
    if(a[mid] == key){
      return 1;
    }
    else if(key<a[mid]){
      right = mid;
    }
    else{
      left = mid+1;
    }
  }
  return 0;
}


int main(){
  int n,k,result;
  result=0;
  vector<int> a,b;
  cin>>n;
  rep(i,n){
    int A;
    cin>>A;
    a.pb(A);
  }
  cin>>k;
  rep(i,k){
    int A;
    cin>>A;
    b.pb(A);
  }
  rep(i,k){
    result+=binary(a,b[i]);
  }
  log(result);
  
}


Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int N;
  cin >> N;
  i64 ans =0;
  rep(i,0,N - 1){
    i64 a;
    cin >> a;
    ans += (a - 1) % a;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int k,x;
    cin>>k>>x;
    int s = max(x - k + 1, -1000000);
    int t = min(x + k - 1, +1000000);
    for(int i=s;i<=t;++i)
    {
        cout<<i<<" ";
    }
}

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

int main(){
    ll A,B;
    cin >> A >> B;
    if(A <= 12)
        B /= 2;
    if(A <= 5)
        B = 0;
    cout << B <<  "\n";
    return 0;
} 


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    Int N;
    Int ans;
    cin >> N;

    vi A = vi(N);
    rep(i,N){
        cin >> A[i];
    }

    sort(A.begin(), A.end());

    Int min_a = A[0];
    int now_i = 0;
    rep(i,N){
        if(now_i == i) continue;
        if(min_a == 1){
            ans =1;
            break;
        }
        Int amari = A[i]%min_a;
        if(amari == 1){
            ans = 1;
            break;
        }
        if(amari != 0){
            A[i]=amari;
            min_a = min(amari,min_a);
            ans = min_a;
            now_i = i;
            i = -1;
        }
        if(amari == 0){
            ans = min_a;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
N,A,B,C,D=map(int,input().split())
x=N//A
y=N//C
if x==N/A:
    X=N//A
else:
    X=N//A+1

if y==N/C:
    Y=N//C
else:
    Y=N//C+1

if X*B > Y*D:
    print(Y*D)
else:
    print(X*B)


Measured memory_bytes: 5600
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>>anss(H, vector<int>(W,1000));
	for (int i = 0; i < H; ++i) {
		string st; cin >> st;
		for (int j = 0; j < W; ++j) {
			if (st[j] == 'c') {
				for (int k = j; k < W; ++k) {
					anss[i][k] = min(anss[i][k], k - j);
				}
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (anss[i][j] == 1000)anss[i][j] = -1;
			cout << anss[i][j];
			if (j != W - 1) {
				cout << " ";
			}
			else cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3216
n,k=map(int,input().split(' '))
a=[0 for i in range(n+1)]
for z in range(k):
  x=int(input())
  temp=map(int,input().split(' '))
  for i in temp:
    a[i]+=1
c=0
for i in range(1,n+1):
  if(a[i]==0):
    c+=1
print(c)

Measured memory_bytes: 9184
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int match = scan.nextInt();
		String taro;
		String hanako;
		int taroWin = 0;
		int hanakoWin = 0;
		for(int kaisuu=0; kaisuu<match; kaisuu++){
			//???????????£??\?????????????????¨??????????????????????????????????¶?????????¨??§????????°?????????????????????????????????
			taro = scan.next();
			hanako = scan.next();
			taro = taro + "0";
			hanako = hanako + "0";
			char[] taroChar = taro.toCharArray();
			char[] hanakoChar = hanako.toCharArray();
			for(int i=0; i<taro.length() && i<hanako.length(); i++){
				//?????????????????????
				String charToString = String.valueOf(taroChar[i]);
				byte[] taroNumber = charToString.getBytes("US-ASCII");
				charToString = String.valueOf(hanakoChar[i]);
				byte[] hanakoNumber = charToString.getBytes("US-ASCII");
				//??????????±????
				if(taroNumber[0] > hanakoNumber[0]){
					taroWin += 2;
					hanakoWin -= 1;
					break;
				}
				else if(taroNumber[0] < hanakoNumber[0]){
					hanakoWin += 2;
					taroWin -= 1;
					break;
				}
			}
			//?????????????????????
			taroWin += 1;
			hanakoWin += 1;
		}
		System.out.println(taroWin+" "+hanakoWin);
	}
}

Measured memory_bytes: 30740
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
const n = Number(list[0]);
const A = list[1].trim().split(' ');
const q = Number(list[2]);
const mi = list[3].trim().split(' ');

class KeyMap {
  constructor() {
    this.map = {};
  }
  get(...args) {
    let map = this.map;
    args.forEach(arg => {
      map[arg] = map[arg] || {};
      map = map[arg];
    });
    return map;
  }
}

const dp = new Map();
const keyMap = new KeyMap();
const memo = (i, m) => {
  if (dp.has(keyMap.get(i, m))) {
    return dp.get(keyMap.get(i, m));
  }
  if (i === n || m <= 0) {
    return m === 0;
  }

  const nI = i + 1;
  const nM = m - A[i];
  dp.set(keyMap.get(nI, m), memo(nI, m));
  dp.set(keyMap.get(nI, nM), memo(nI, nM));
  return dp.get(keyMap.get(nI, m)) || dp.get(keyMap.get(nI, nM));
}
for (let i = 0; i < q; i++) {
  console.log(memo(0, Number(mi[i])) ? 'yes' : 'no');
}
// console.log(dp);


Measured memory_bytes: 30600
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main(){
	ll w,h,x,y;
	cin>>w>>h>>x>>y;

	ld tot = (ld)(w*h)/2;
	int ans =0;
	if(w%2==0 && h%2==0 && x == w/2 && y==h/2){
		ans = 1;
	}

	cout<<fixed<<setprecision(20);
	cout<<tot<<" "<<ans<<endl;



}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
ll n,d,a;
cin>>n>>d>>a;
V<ll> x(n),h(n);
V<P> dd(n);
for(int i=0;i<n;i++){
    cin>>x[i]>>h[i];
    dd[i].fi=x[i];dd[i].se=h[i];
}
ll ans=0,now=0;
V<ll> t(n+1,0);
sort(all(x));
sort(all(dd));
for(int i=0;i<n;i++){
    now-=t[i];
    if(dd[i].se-now<=0)continue;
    int it=upper_bound(all(x),x[i]+2*d)-x.begin();
    ans+=(dd[i].se-now+a-1)/a;
    t[it]+=(dd[i].se-now+a-1)/a*a;
    now+=(dd[i].se-now+a-1)/a*a;
}
cout<<ans<<endl;
}


Measured memory_bytes: 8064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t 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(int64_t 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) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vvi G(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    function<void(int, int, mint&)> dfs = [&](int i, int j, mint &res) {
        int h = k-1;
        if(i == 0) {
            h = k;
        }
        for(int ne:G[i]) {
            if(ne == j) continue;
            dfs(ne, i, res);
            res *= --h;
        }
    };

    mint ans = k;
    dfs(0, -1, ans);
    cout << ans.x << endl;
}

Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<int> L(n);
	rep(i, n) cin >> L.at(i);
	int sum = 0;
	sort(L.begin(), L.end());
	for (int i = 0; i < n - 2; i += 1) {
		int a = L.at(i);
		for (int j = i + 1; j < n - 1; ++j) {
			int b = L.at(j);
			for (int k = j + 1; k < n; ++k) {
				int c = L.at(k);
				if (abs(b - c) < a) sum++;
				else break;
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)
#define AAA (1000000007)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


int i, j, k;

int main() {
	int N;
	vector<ull> A;
	vector<ull> B;
	cin >> N;
	rep(i, 0, N) {
		ull temp;
		cin >> temp;
		A.push_back(temp);
		if (i != 0)
			B.push_back(B[i - 1] + temp);
		if (i == 0)
			B.push_back(temp);

	}
	ull total = B.back();

	ull ans = (total > 2 * B[0] ? total - 2 * B[0] : 2 * B[0] - total);

	rep(i, 0, N) {
		ull temp = (total > 2 * B[i] ? total - 2 * B[i] :  2 * B[i] - total);

		if (ans > temp)
			ans = temp;


	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 3564
# include <bits/stdc++.h>
# define sz(a) int(a.size())
# define vec vector  
# define pb push_back

const int Sz = (int)3e5 + 2;

using namespace std;

int ans[Sz];       
int n, m;

int l[Sz], r[Sz];
vec<int> add[Sz], del[Sz];


struct fenwick {
	int n;
	vec<int> t;
	fenwick (int n) : n(n), t(n + 1) {}

  void add (int id, int x) {
  	for (int i = id; i >= 1; i -= (i & (-i)))
  		t[i] += x;
  }
  int get (int id) {
  	int res = 0;
  	for (int i = id; i <= n; i  += (i & (-i)))
  		res += t[i];   
  	return res;
  }    
};

inline void Read_rap() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
}	

int main()
{
	Read_rap();            
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> l[i] >> r[i];
		add[l[i]].pb(i);
		del[r[i]].pb(i);
	}        

	fenwick T(m);
	vec<int> dv[m + 1];
	for (int i = 1; i <= m; i++)
		for (int j = i; j <= m; j += i)
			dv[j].pb(i);                             

	for (int i = 1; i <= m; i++) {
		for (int j : add[i]) {
			T.add(r[j], +1);
		}                  

		for (int d : dv[i]) {
			ans[d] += T.get(i) - T.get(i + d);
		}	      
		                    
		for (int j : del[i]) {
			T.add (r[j],-1);
		}
	}
	for (int i = 1; i <= m; i++)
		cout << ans[i] << endl;
				
			
	return 0;
}

Measured memory_bytes: 33920
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    P = LI()

    # 全てのa_iとa_i+1の差をn以上にする
    A = [n * i + 1 for i in range(1, n + 1)]
    B = A[::-1]

    # この時点では全てのiでA[i] + B[i]が等しい
    # A[i]とB[i]の和をPの順番に並べ替えるためにA[i]の値を減らす
    # A[i]の減少量の最大値はnだけど，
    # 全てのA[i]は1以上減少するので数列Aの単調増加は崩れない
    for i, p in enumerate(P):
        A[p - 1] -= n - i

    print(*A)
    print(*B)
    # print([A[i] + B[i] for i in range(n)])


main()


Measured memory_bytes: 6352
#include <bits/stdc++.h> 
using namespace std;
int main()
{
int n;
cin >>n; 
char s[100];
for(int i=0;i<n;i++)
{
	cin >>s[i];
}
int num1=0,num2=0;
for(int i=0;i<n;i++){
    if(s[i]=='R') num1++;
    if(s[i]=='B') num2++;
}
if(num1>num2) cout << "Yes"<<endl;
else cout << "No"<<endl;
return 0;	
} 





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

int n, i, a[maxN], b[maxN];
ll sA, sB, sum;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (i = 0; i < n; i++){
		cin >> a[i];
		sA += a[i];
	}
	for (i = 0; i < n; i++){
		cin >> b[i];
		sB += b[i];
	}
	if (sB < sA){
		return cout << "No" << endl, 0;
	}
	for (i = 0; i < n; i++){
		if (a[i] < b[i]){
			sum += (b[i] - a[i]) / 2 + (b[i] - a[i]) % 2;
		}
	}
	cout << (sum <= sB - sA ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 384
def main
  n = gets.chomp.to_i

  # 数列を読み込み、
  # 数字ごとに出現数をカウントする * 2本（偶数列、奇数列
  even_nums = Hash.new(0)
  odd_nums = Hash.new(0)
  gets.split.each_with_index do |c, idx|
    num = c.to_i
    if idx.even?
      even_nums[num] += 1
    else
      odd_nums[num] += 1
    end
  end
  # pp even_nums
  # pp odd_nums

  # 出現数がMAXの数字＆カウント、および出現数が2番目のカウントを見つける
  # 2本
  evens = even_nums.sort_by {|(k, v)| v}
  odds = odd_nums.sort_by {|(k, v)| v }
  # pp evens
  # pp odds

  e_max, e_max_cnt = evens[-1]
  o_max, o_max_cnt = odds[-1]
  # puts e_max, e_max_cnt
  # puts o_max, o_max_cnt

  # 出現数MAXの数字が偶奇で異なっていれば、それで決定
  if e_max != o_max
    puts n / 2 - e_max_cnt + n / 2 - o_max_cnt
    return
  end

  # 同じであれば、MAX数字＋2番目数字 で両サイドカウントして
  # より多い方（変更数が少ない方）で決定
  e_max2_cnt = if evens.length == 1
                 0
               else
                 evens[-2][1]
               end
  o_max2_cnt = if odds.length == 1
                 0
               else
                 odds[-2][1]
               end
  eo = e_max_cnt + o_max2_cnt
  oe = o_max_cnt + e_max2_cnt

  if eo < oe
    puts n - oe
  else
    puts n - eo
  end
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 19704
class Combi
  def initialize(sum)
    @sum = sum
  end

  attr_accessor :sum

  def calc(num)
    ret = 0

    (0..9).to_a.repeated_permutation(num).each do |ary|
      ret += 1 if ary.inject(:+) == @sum
    end

    return ret
  end
end

while line = gets
  puts Combi.new(line.to_i).calc(4)
end

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

int main()
{
int N;
cin >> N;
vector<int> C(N - 1), a(N - 1), b(N - 1);
for(int i = 0; i < N - 1;i++) {
cin >> C[i] >> a[i] >> b[i];
}
for(int i = 0;i < N;i++) {
int res = 0;
for(int j = i;j < N - 1;j++) {
res = max((res + b[j] - 1) / b[j] * b[j], a[j]) + C[j];
}
cout << res << endl;
}
}

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

int main(){
	ll n,m;
	cin >> n >> m;
	ll a;
	if(n == 1){
		cin >> a;
		if(a % m == 0) cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	vector<ll> b(n+1);
	map<ll,ll> mp{};
	for(ll i(0);i<n;++i){
		cin >> a;
		b[i+1] = b[i] + a;
		ll t = b[i+1] % m;
		if(mp.count(t) == 0){
			mp[t] = 1;
		}else{
			mp[t]++;
		}
	}
	ll ans(0);
	for(auto i = mp.begin();i != mp.end(); ++i){
		ll p = i->second;
		if(p <= 1) continue;
		ans += p * (p-1) / 2;
		if(i-> first == 0)ans += p;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<stack>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n, a,k;
string str;
bool no[10];
//-------------------関数----------------------//

bool check(ll num) {
	str = to_string(num);
	ll siz = str.size();
	REP(i, siz) {
		if (no[str[i] - '0']) {
			return false;
		}
	}
	return true;
}

int main() {
	cin >> n >> k;
	REP(i, k) {
		cin >> a;
		no[a] = true;
	}
	while (1) {
		if (check(n)) { break; }n++;
	}
	cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = 5000000;

struct pt
{
	int x, y;
	pt() { }
};

int H[maxn], F[maxn], used[maxn];

struct hash_table
{
	hash_table() { }

	int getpos(int h) const
	{
		int i = h % maxn;
		for (; used[i] && H[i] != h; ++i) if (i == maxn) i = 0;
		return i;
	}

	int& operator[](int h)
	{
		int i = getpos(h);
		H[i] = h;
		used[i] = 1;
		return F[i];
	}
};

struct fenwick
{
	int n;
	hash_table F;

	fenwick() { n = inf; }

	void upd(int i, int x)
	{
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	}

	int get(int i)
	{
		int res = 0;

		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);

		return res;
	}
};

int n;
pt s, f;
pt p[maxn];

bool read()
{
	if (scanf("%d %d %d %d %d", &s.x, &s.y, &f.x, &f.y, &n) != 5)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].x, &p[i].y);

	return true;
}

bool cmp(pt a, pt b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); }

void solve()
{
	if (s.x > f.x)
		swap(s, f);

	if (s.y > f.y)
	{
		f.y = 2 * s.y - f.y;

		forn (i, n)
			p[i].y = 2 * s.y - p[i].y;
	}

	vector<pt> pp;

	forn (i, n)
		if (s.x <= p[i].x && p[i].x <= f.x && s.y <= p[i].y && p[i].y <= f.y)
			pp.push_back(p[i]);

	sort(pp.begin(), pp.end(), cmp);
	fenwick dp;

	forn (i, size(pp))
		dp.upd(pp[i].y, dp.get(pp[i].y) + 1);

	int lis = dp.get(inf);
	long double ans = 0;

	if (lis != min(f.y - s.y, f.x - s.x) + 1)
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * lis;
	else
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * (lis - 1) + 10 * M_PI;

	printf("%.15f\n", (double) ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 62320
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

from heapq import heapify, heappop, heappush
def Main():
    n, m = read_ints()
    a = read_int_list()
    a = [-x for x in a]
    heapify(a)
    
    while m:
        cost = heappop(a)
        if cost == 0:
            break
        heappush(a, -(-cost//2))
        m -= 1
    print(-sum(a))

if __name__ == '__main__':
    Main()

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

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a, b) cout << #a << " = " << a << " ---- " << #b << " = " << b << endl;
#define F first
#define S second
#define pb push_back

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;

const int MOD = 1e9+7;

ll fast_pow(ll b, ll e){
	ll ret = 1;
	while(e){
		if(e&1) ret = (ret*b)%MOD;
		b = (b*b)%MOD, e = e>>1;
	}
	return ret;
}

ll inv(ll n){
	return fast_pow(n, MOD-2);
}

ll fat(ll n){
	ll ret = 1;
	rep(i, 1, n+1){
		ret = (ret*i)%MOD;
	}
	return ret;
}

int N;
ll A[100010], B[100010], T[100010], S[100010];


int main(){
	
	scanf("%d", &N);
	rep(i, 1, N+1) scanf("%lld", &A[i]);
	
	rep(i, 1, N+1){
		S[i] = (S[i-1] + inv(i))%MOD;
	}
	
	rep(i, 1, N+1){
		B[i] = (S[N-i+1]+S[i]-1+MOD)%MOD;
	}	
	
	rep(i, 1, N+1){
		T[i] = (B[i]*A[i])%MOD;
	}
	
	ll ans = 0;
	
	rep(i, 1, N+1){
		ans = (ans+T[i])%MOD;
	}	
	
	ans = (ans*fat(N))%MOD;
	
	printf("%lld\n", ans);
	
	return 0;
}

Measured memory_bytes: 3328
/*
 
dunjen_master
 
*/
 
 

 
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

inline ll mul(ll a,ll b){

    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}

  

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

/* ordered_set A;
   A.insert(x);
   A.erase(x);
   A.order_of_key(x) // no of elements less than (<) x
   *A.find_by_order(k-1) // kth smallest element
*/



double pie=acos(-1);


int main(){
 

  
 // cout<<pie<<endl;
  double r;
  cin>>r;
  double ans=2.0*pie*r;

  printf("%.12lf\n",ans);
  
  
  
  return 0;
  }
  


   

    


    


    
    
    
    
 
    


Measured memory_bytes: 3772
#include <stdio.h>
main(){
	int i;
	int p[3],j[2];
	scanf("%d %d %d",&p[0],&p[1],&p[2]);
	scanf("%d %d",&j[0],&j[1]);
	int pa=2000;
	int ju=2000;
	for(i=0;i<3;i++){
		if(pa>p[i]){
			pa=p[i];
		}
	}
	for(i=0;i<2;i++){
		if(ju>j[i]){
			ju=j[i];
		}
	}
	printf("%d\n",pa+ju-50);
	return 0;
}

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

double solve() {
    ll N;
    cin >> N;
    vector<ll> X(N), Y(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> X[i] >> Y[i];
    }
    auto dist = [](double x1, double y1, double x2, double y2) {
        double dx = x2 - x1;
        double dy = y2 - y1;
        return sqrt(dx*dx + dy*dy);
    };
    auto dist_ij = [&](int i, int j) {
        return dist(X[i], Y[i], X[j], Y[j]);
    };
    double m = 0;
    for ( int i1 = 0; i1 < N; i1++ ) {
        for ( int i2 = i1+1; i2 < N; i2++ ) {
            double hf = dist(X[i1], Y[i1], X[i2], Y[i2]) / 2;
            m = max(m, hf);
        }
    }
    for ( int i1 = 0; i1 < N; i1++ ) {
        for ( int i2 = i1+1; i2 < N; i2++ ) {
            for ( int i3 = i2+1; i3 < N; i3++ ) {
                if ( (X[i2]-X[i1])*(Y[i3]-Y[i1]) == (X[i3]-X[i1])*(Y[i2]-Y[i1]) ) continue;
                double d12 = dist_ij(i1,i2);
                double d23 = dist_ij(i2,i3);
                double d31 = dist_ij(i3,i1);
                if ( d12 < d23 ) swap(d12, d23);
                if ( d12 < d31 ) swap(d12, d31);
                if ( d12*d12 > d23*d23 + d31*d31 ) continue;
                double s = (d12 + d23 + d31) / 2;
                double r = d12 * d23 * d31 / (4 * sqrt(s*(s-d12)*(s-d23)*(s-d31)));
                m = max(m, r);
            }
        }
    }
    return m;
}

int main() {
    cout.setf(ios::fixed);
    cout.precision(16);
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main(){
    int n;
    bool ok=false;
    cin>>n;
    for(int i=1; i<10; i++){
        if(n%i==0&& (n/i)<10) ok = true;
    }
    cout<<(ok ? "Yes": "No")<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void){
    char s[10];
    scanf("%s", s);

    int i1 = (s[0] -'0') * 10 + (s[1] - '0');
    int i2 = (s[2] -'0') * 10 + (s[3] - '0');

    if(1 <= i1 && i1 <= 12){
        if(1 <= i2 && i2 <= 12){
            printf("AMBIGUOUS\n");
        }else{
            printf("MMYY\n");
        }
    }else{
        if(1 <= i2 && i2 <= 12){
            printf("YYMM\n");
        }else{
            printf("NA\n");
        }
    }
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,k;
	scanf("%d%d", &n,&k);
	vector<int> a(n);
	for(int i=0; i<n; i++) scanf("%d", &a[i]);
	sort(a.begin(), a.end());
	int ans = 0;
	for(int i=0; i<k; i++) ans += a[i];
	cout << ans;
	return 0;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int > vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
 
#define ALL(x) (x).begin(), (x).end()
#define RESET(x) memset((x), 0, sizeof (x))
#define FOR(i, b, e) for ( int i = (b); i < (e); ++i)
#define RE(i, n) FOR(i, 0, (n))
#define FOREACH(i, x, y) for ( int i = (x); i <= (y); ++i)
#define two(X) (1<<(X))//NOTES:two(
#define contain(S,X) (((S)&two(X))!=0)//NOTES:contain(
#define chkmin(X, Y) (X) = min((X), (Y))
#define chkmax(X, Y) (X) = max((X), (Y))
#define sqr(X) ((X) * (X))
 
const ll maxn = (ll) 5e5 + 100;
const ll maxm = (ll) 1e6;
const int LOGN = 22;
const ll INF = 1e15+ 10;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-12;



int main() {
#ifndef ONLINE_JUDGE
  //  freopen("in.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
    int x;
    while (cin >> x) {
        ll ma = 1;
        for (int p = 2; p <= 10; ++p) {
            for (int i = 1; i * i <= x; ++i) {
                ll y = pow((ll)i, p);
                if (y <= x) {
                    chkmax(ma, y);
                } else {
                    break;
                }
            }
        }
        cout << ma << endl;
    }
   
    return 0;
}

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

typedef long long ll;

#define f(i, q) for(ll i = 0; i < q; i++)  

int main() {
    vector<string> s(10000);
    string tmp;
    ll n, count , a, b, m_c;

    cin >> n;
    f(i, n) cin >> s.at(i);

    count = a = b = m_c = 0;
    f(i, n) {
        tmp = s.at(i);
        // 文字列中（先頭と最後尾を除く）にあるABの数を求める．
        // for(int j = 0; j < tmp.size() - 1; j++) {
        f(j, tmp.size() - 1) {
            if( tmp.at(j) == 'A' && tmp.at(j+1) == 'B')
                count++;
        }

        // 先頭のBと最後尾のAの数を求める．
        if(tmp.at(0) == 'B')
            b++;
        if(tmp.at(tmp.size() - 1) == 'A')
            a++;

        if(tmp.at(0) == 'B' || tmp.at(tmp.size() - 1) == 'A')
            m_c++;
        
    }

    if(m_c <= min(a, b) && m_c != 0) {
        count += min(a, b) - 1;
    } else {
        count += min(a, b);
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
 
const int mxN = 2e5 + 1;
ll h, w;
string s[1000];
ll dp[1001][1001] = {};
 
int main()
{
FIO
 
    cin >> h >> w;
    For(h) cin >> s[i];
    dp[1][1] = 1;
    FOR(h)
    {
        Rep(j,1,w)
        {
            if(i == 1 && j == 1) continue;
            if(s[i-1][j-1] == '#')
                dp[i][j] = 0;
            else
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
        }
    }
    cout << dp[h][w] << endl;
}

Measured memory_bytes: 12468
K, N = map(int, input().split())
A = list(map(int, input().split()))

diffA = []
_a = K + A[0]
for a in A[::-1]:
    diffA.append(_a - a)
    _a = a
maxid = diffA.index(max(diffA))
diffA.pop(maxid)
print(sum(diffA))


Measured memory_bytes: 26420
#include <cstdio>

int main(){
    char s[100001];
    scanf("%s",s);
    bool a[26];
    for(int i = 0; i < 26; i++){
        a[i] = true;
    }
    for(int i = 0; s[i] != '\0'; i++){
        if(a[s[i] - 97]){
            a[s[i] - 97] = false;
        }
    }
    for(int i = 0; i < 26; i++){
        if(a[i]){
            printf("%c\n",'a' + i);
            break;
        }
        if(i == 25){
            printf("None\n");
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll x[1500010];
ll y[1500010];
ll xx[1510],yy[1510];
int main(){
	ll n,m;
	while(scanf("%lld%lld",&n,&m),n){
		ll s=0,t;
		xx[0]=yy[0]=0;
		rep(i,0,n){
			scanf("%lld",&t);
			s+=t;
			xx[i+1]=s;
		}
		s=0;
		rep(i,0,m){
			scanf("%lld",&t);
			s+=t;
			yy[i+1]=s;
		}
		rep(i,0,1500010)x[i]=y[i]=0;
		rep(i,0,n+1)rep(j,i+1,n+1)x[xx[j]-xx[i]]++;
		rep(i,0,m+1)rep(j,i+1,m+1)y[yy[j]-yy[i]]++;
		ll ans=0;
		rep(i,1,1500010)ans+=x[i]*y[i];
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 25244
#include <bits/stdc++.h> 
using namespace std; 
int main(){
  int N;
  cin>>N;
  for(int r=0; r<9; r++){
    for(int i=0; i<9; i++){
      if((r+1)*(i+1) == N){
         cout << "Yes" << endl;
         return 0;
      }
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 200004;
const int MOD =998244353
 ;
const int INV2 = (MOD+1)/2;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

     signed main(){
       COMinit();
int n,m,k,ans=0;
cin>>n>>m>>k;
for(int i=k;i>=0;i--){
 ans=(ans+COM(n-1,i)*modpow(m-1,n-1-i,MOD)%MOD)%MOD;

}
cout<<m*ans%MOD<<endl;







}


        


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

#include <algorithm>
#include <vector>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, K) {
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
def uneven_numbers(N: int)->int:
    if N < 10:
        return N
    elif N < 100:
        return 9
    elif N < 1000:
        return N-90
    elif N < 10000:
        return 909
    elif N < 100000:
        return N - 9090
    else:
        return 90909


if __name__ == "__main__":
    N = int(input())

    ans = uneven_numbers(N)
    print(ans)


Measured memory_bytes: 2940
#include <stdio.h>

int main(){
   int n,i,ac,wa,tle,re;
   char s[4];

   scanf("%d",&n);
   for (ac=wa=tle=re=i=0;i<n;i++) {
      scanf("%s",s);
      if (s[0]=='A') ac++;
      else if (s[0]=='W') wa++;
      else if (s[0]=='T') tle++;
      else if (s[0]=='R') re++;
   }
   printf("AC x %d\n",ac);
   printf("WA x %d\n",wa);
   printf("TLE x %d\n",tle);
   printf("RE x %d\n",re);
   return 0;
}


Measured memory_bytes: 1728
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
  
 int main()
 {
   int N;
   int arr[10];
   int v1,v2;
   while(cin>>arr[0])
   {
     double sum=arr[0];
     char temp;
     cin>>temp;
     double sum2=0;
     for(int i=1;i<10;i++)
     {
       char temp_2;
       cin>>arr[i]>>temp_2;
       sum+=arr[i];
     }
     char temp_3;
     cin>>v1>>temp_3>>v2;
     int result;
     double dis=1.0*v1/(v1+v2)*sum;
     for(int i=0;i<10;i++)
     {
       sum2+=arr[i];
       if(dis<=sum2)
       { 
         result=i+1;
         break;
       }           
     }
     cout<<result<<endl;  
   }
   //while(1);     
   return 0; 
 }
 

Measured memory_bytes: 3076