akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  vector<pair<double,int> > vv;
  REP(k,3) {
    vector<pair<double,int> > v;
    REP(i,8) {
      int n;
      double t;
      cin >> n >> t;
      v.push_back(make_pair(t,n));
    }
    sort(ALL(v));
    REP(i,2)
      printf("%d %.2f\n",v[i].second,v[i].first);
    for(int i=2;i<8;i++)
      vv.push_back(v[i]);
  }
  sort(ALL(vv));
  REP(i,2)
    printf("%d %.2f\n",vv[i].second,vv[i].first);
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		int i, j;// loop counter
		int N/* number of element */, num[]/* array of number */, min/* order number of minimum number */;
		int count = 0;// count number of exchanging number
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		num = new int[N];
		for (i = 0; i < N; ++i) {
			num[i] = sc.nextInt();
		}
		for (i = 0; i < N; ++i) {
			min = i;
			for (j = i; j < N; ++j) {
				if (num[min] > num[j]) {
					min = j;
				}
			}
			if (min != i) {
				int tmp = num[i];
				num[i] = num[min];
				num[min] = tmp;
				++count;
			}
		}
		for (i = 0; i < N; ++i) {
			System.out.print(num[i]);
			if (i != N - 1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
		System.out.println(count);
		sc.close();
	}
}



Measured memory_bytes: 26348
def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    else:
        return True


def main():
    x = int(input())
    while True:
        if is_prime(x):
            break
        else:
            x += 1
    print(x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
N = int(input())
A_list = list(map(int, input().split())) # len : N+1
B_list = list(map(int, input().split())) # len : N
ans = 0
before_num = 0
for i in range(N+1):
    if i < N:
        if A_list[i] >= before_num:
            ans += before_num
            A_list[i] -= before_num
            if A_list[i] >= B_list[i]:
                ans += B_list[i]
                A_list[i] -= B_list[i]
                B_list[i] = 0
                before_num = 0
            elif A_list[i] < B_list[i]:
                ans += A_list[i]
                B_list[i] -= A_list[i]
                A_list[i] = 0 
                before_num = B_list[i]
        elif A_list[i] < before_num:
            ans += A_list[i]
            before_num = B_list[i]
            A_list[i] = 0
    if i == N:
        if A_list[i] >= before_num:
            ans += before_num
            A_list[i] -= before_num
        elif A_list[i] < before_num:
            ans += A_list[i]
            A_list[i] = 0

print(ans)
    

Measured memory_bytes: 19284
//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl

#define MAX_VALUE 9223372036854775807

int solve() {
	ll n;
	cin >> n;

	vector<ll> ls(n);
	REPD(i, 0, n) cin >> ls[i];
	
	sort(ls.begin(), ls.end());

	ll res = 0;
	REPD(i, 0, n) {
		REPD(j, i + 1, n) {
			if (ls[i] == ls[j]) continue;
			REPD(k, j + 1, n) {
				if (ls[j] == ls[k]) continue;
				if (ls[k] < ls[i] + ls[j]) ++res;
				else break;
			}
		}
	}

	RET(res);

	return 0;
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>n;
      rep(i,n){
        cin>>a;
        if(a%2!=0)cnt++;
      }
      if(cnt%2==0)Cout("YES");
      else Cout("NO");
    
       
return 0;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    string arr[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(int i=0;i<n;i++)cout<<arr[i];cout<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define UB upper_bound
#define LB lower_bound

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
const int SI=200010;

int main(){
	LL n,m;
	cin>>n;
	vector<LL> A,B;
	FOR(i,0,n){
		cin>>m;
		A.PB(m);
	}
	FOR(i,0,n){
		cin>>m;
		B.PB(m);
	}
	LL ans=0;
	FOR(i,0,30){
		LL k=1LL<<i;
		vector<LL> a,b;
		FOR(j,0,n){
			a.PB(A[j]&(2*k-1));
		}
		FOR(j,0,n){
			b.PB(B[j]&(2*k-1));
		}
		//if(!i)cout<<a.end()-a.begin()<<endl;
		sort(a.begin(),a.end());
		sort(b.begin(),b.end());
		LL plus=0;
		FOR(j,0,n){
			LL p=a[j];
			LL q0=k-p,q1=2*k-p;
			plus+=(LB(b.begin(),b.end(),q1)-LB(b.begin(),b.end(),q0));
			q0=3*k-p,q1=4*k-p;
			plus+=(LB(b.begin(),b.end(),q1)-LB(b.begin(),b.end(),q0));
		}
		//cout<<i<<" plus:"<<plus<<endl;
		plus&=1;
		ans|=(plus<<i);
		//cout<<i<<" "<<ans<<endl;
	}
	cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 8568
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define sPRINT(str) printf(#str "\n")
#define yOUT sPRINT(Yes)
#define nOUT sPRINT(No)
#define YOUT sPRINT(YES)
#define NOUT sPRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
 
using namespace std;

int main(void)
{   
    int h, w, cnt;

    cin >> h >> w;
    char a[h+1][w+1];
    REP(i, h){
        REP(j, w){
            cin >> a[i][j];
        }
    }

    REP(i, h){
        REP(j, w){
            if(a[i][j] == '.'){
                cnt = 0;
                for(int k = max(0, i-1); k <= min(h, i+1); k++){
                    for(int l = max(0, j-1); l <= min(w, j+1); l++){
                        if(a[k][l] == '#'){
                            cnt++;
                        }
                    }
                }
                cout << cnt;
            }
            else{
                cout << "#";
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        Ds: [(i64, i64); N],
    }

    for i in 0..N - 2 {
        let b0 = Ds[i].0 == Ds[i].1;
        let b1 = Ds[i + 1].0 == Ds[i + 1].1;
        let b2 = Ds[i + 2].0 == Ds[i + 2].1;

        if b0 && b1 && b2 {
            println!("Yes");
            return;
        }
    }

    println!("No");
}


Measured memory_bytes: 2156
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m;
    cin >> n >> m;
    VI deg(n);
    vector<multiset<int>> e(n);
    REP(i,m){
        int a = in() - 1, b = in() - 1;
        deg[a]++;
        deg[b]++;
        e[a].insert(b);
        e[b].insert(a);
    }

    int c4 = 0, c6 = 0;
    VI vs;
    REP(i,n){
        if (deg[i] % 2){
            cout << "No" << endl;
            return 0;
        }
        if (deg[i] == 4){
            c4++;
            vs.push_back(i);
        }
        if (deg[i] >= 6) c6++;
    }
    bool f = (c4 > 2 || c6 >= 1);
    if (c4 == 2){
        REP(i,n){
            if (e[i].size() != 2) continue;
            int x = *e[i].begin();
            e[i].erase(e[i].find(x));
            int y = *e[i].begin();
            e[i].erase(e[i].find(y));
            e[x].erase(e[x].find(i));
            e[x].insert(y);
            e[y].erase(e[y].find(i));
            e[y].insert(x);
        }
        if (e[vs[0]].count(vs[1]) != 4) f = true;
    }
    cout << (f ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 14720
#include <iostream>
#include <algorithm>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i=0; i< (int)(n); i++)
typedef long long ll;
bool DEBUG = true;

// find maximum kouyakusuu
// souinsuu bunkai the maximum kouyakusuu
// return the num of kinds of soinsuu + 1

ll gcd(ll a, ll b) {
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

// bool isseen(vector<int>& primes, int num) {
//     bool seen  = false;
//     rep(pi, primes.size()){
//         if (num % primes[pi] == 0) {
//             seen = true;
//             break;
//         }
//     }
//     return seen;
// }

int main() {
    ll A, B;
    cin >> A >> B;

    ll greatest_common_divisor;
    if (A > B) greatest_common_divisor = gcd(A, B);
    else greatest_common_divisor = gcd(B, A);

    ll ans = 1;
    ll top = greatest_common_divisor;
    for (ll i = 2; i*i < top; i++){
        if (top % i != 0) continue;
        ans++;
        while (top % i == 0) top /= i;
    }
    if (top != 1) ans++;
    cout << ans << endl;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	string S;
	cin >> S;

	int a = 10 * (S[0] - '0') + (S[1] - '0');
	int b = 10 * (S[2] - '0') + (S[3] - '0');

	if( a >= 1 && a <= 12 ) {
		if( b >= 1 && b <= 12 ) {
			cout << "AMBIGUOUS\n";
		}
		else {
			cout << "MMYY\n";
		}
	}
	else if( b >= 1 && b <= 12 ) {
		if( a >= 1 && a <= 12 ) {
			cout << "AMBIGUOUS\n";
		}
		else {
			cout << "YYMM\n";
		}
	}
	else {
		cout << "NA\n";
	}

	return 0;
}


Measured memory_bytes: 256
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  string s;
  cin >> s;
  fore(i, 0, 3) {
    if (s[i] == '7') {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";

  return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
        public static void main(String[] args){
            Scanner 平和堂 =new Scanner(System.in);
            int 彦根城 = 平和堂.nextInt();
            int[] 滋賀大学 = new int[彦根城];
            for(int 経済学部=0;経済学部<彦根城;経済学部++){
                滋賀大学[経済学部] = 平和堂.nextInt();
            }
            int おはようございます = 滋賀大学[0];
            int 留年者数 = 1;
            for(int データサイエンス学部=1;データサイエンス学部<彦根城;データサイエンス学部++){
                if(滋賀大学[データサイエンス学部]>=おはようございます){
                    留年者数++;
                    おはようございます=滋賀大学[データサイエンス学部];
                }
            }
            System.out.println(留年者数);
        }
}

Measured memory_bytes: 24020
import sys
input = sys.stdin.readline
import itertools
import collections


def main():
    N = int(input())

    a = 0
    for i in range(3, len(str(N)) + 1):
        for j in itertools.product("357", repeat=i):
            if len(collections.Counter(j)) >= 3:
                if int("".join(j)) <= N:
                    a += 1

    print(a)












if __name__ == '__main__':
    main()



Measured memory_bytes: 3316
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const N = readln.chomp.to!long;
    auto S = readln.chomp.map!(c => c.to!long).array;
    N.iota.map!(i => S[0..i].sort!((a,b) => a < b).uniq.filter!(c => S[i..$].canFind(c)).count).reduce!max.writeln;
}



Measured memory_bytes: 256
N = gets.to_i
XD = readlines.map{|l| l.split.map(&:to_i)}
M = 998244353

xd = XD.sort_by(&:first)
dp = Array.new(N + 1, 0)
dp[N] = 1
f = Array.new(N, 0)
s = 1
(N - 1).downto(0) do |i|
  x = i + 1
  while x < N && xd[x][0] < xd[i][0] + xd[i][1]
    x = f[x]
  end
  f[i] = x
  s = (s + dp[x])%M
  dp[i] = s
end
puts dp[0]

Measured memory_bytes: 35704
#include<bits/stdc++.h>
using namespace std;
/*int n,m=INT_MAX,x=INT_MIN;
int A[100];
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
        m = min(m, A[i]);
        x = max(x, A[i]);
    }
    long long ans = INT_MAX;
    for (int i = m; i < x+1; i++)
    {
        long long k = 0;
        for (int j = 0; j < n; j++)
        {
            k += (A[j] - i) * (A[j] - i);
        }
        ans = min(ans, k);
        //cout << ans << " ";
    }
    cout << ans;
}*/
//#define int long long
long long a, b, c;
//int fac[200001];

long long power(long long x, long long y, long long p)
{
    if (x == 1 and y != 0) return 1;
    long long res = 1;      // Initialize result 

    long long k = x % p;  // Update x if it is more than or 
                // equal to p 
    //cout << "(" << k << "," << y << "," << p << ")=";
    while (y > 0)
    {
        // If y is odd, multiply x with result 
        if (y & 1)
            res = (res * k) % p;
        //cout << y << ":" << res<<","<<k << " ";
        // y must be even now 
        y = y >> 1; // y = y/2  
        k = (k * k) % p;
    }
    //cout << res<<" ";
    return res;
}

long long modInverse(long long n, long long p)
{
    return power(n, p - 2, p);
}

long long nCrModP(long long n, long long r, long long p)
{
    // Base case 
    if (r == 0)
        return 1;
    long long z=1,y=1;
    for (long long i = n; i > n - r; i--)
        z = (z * i) % p;
    for (int i = 2; i <= r; i++)
        y = (y * i) % p;
    long long k= (z * modInverse(y, p))%p;
    //cout << "(" << n << "," << r << ")=" << k;
    return k;
}
int main()
{
    //fac[0] = 1;
    cin >> c >> a >> b;
    /*for (int i = 1; i <= c; i++)
        fac[i] = fac[i - 1] * i % 1000000007;*/
    int ans = power(2, c, 1000000007)-1;
    //cout << ans << " ";
    ans -= (nCrModP(c, a, 1000000007) + nCrModP(c, b, 1000000007)) % 1000000007;
    //cout << nCrModP(c, a, 1000000007)<<"->";
    //cout << nCrModP(c, b, 1000000007);
    if (ans >= 0)
        cout << ans;
    else cout << ans + 1000000007;
}


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

int main(){
    int n;
    cin >> n;
    int a[110];
    int res=1;
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n,greater<int>());
    
    for(int i=0;i<n-1;i++){
        if(a[i]!=a[i+1])res++;
    }
    
    cout << res;
}

Measured memory_bytes: 256
a,b,c,d = input()
a = int(a)
b = int(b)
c = int(c)
d = int(d)


for mask in range(1<<3):
	val = a
	if 1 & (mask >> 0):
		val += b
	else:
		val -= b

	if 1 & (mask >> 1):
		val += c
	else:
		val -= c
	
	if 1 & (mask >> 2):
		val += d
	else:
		val -= d

	if val == 7:
		if 1 & (mask>>0):
			op1 = "+"
		else:
			op1 = "-"
		if 1 & (mask>>1):
			op2 = "+"
		else:
			op2 = "-"
		if 1 & (mask>>2):
			op3 = "+"
		else:
			op3 = "-"
		print(str(a)+op1+str(b)+op2+str(c)+op3+str(d)+"=7")
		exit(0)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int a,b;
    cin >> a >> b;
    if(a<10 && b<10){
        cout << a*b << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

int main() {
    int n, m;
    cin >> n >> m;
    m /= 1000;
    m = 10 * n - m;
    if (m < 0) {
        cout << -1 << " " << -1 << " " << -1 << endl;
        return 0;
    }

    for (int i = 0; i <= n; i++) {
        int tmp = m - 9 * i;
        if (tmp < 0) break;
        if (tmp % 5 == 0 && tmp / 5 <= n - i) {
            cout << n - tmp / 5 - i << " " << tmp / 5 << " " << i << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong a, b;

int main() {

    cin >> a >> b;

    if (a >= 13) cout << b << endl;
    else if (a >= 6) cout << b / 2 << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   cin>>n;

   priority_queue<L, vector<L>, greater<L> > pq;
   for (int i = 0; i < n; ++i)
   {
      cin>>a[i];
      pq.push(a[i]);
   }

   while(sz(pq) != 1){
      L x = pq.top();
      pq.pop(); 
      L y = pq.top();
      pq.pop(); 
      pq.push((x+y) / 2.0);
   }

   cout<<pq.top();
   

   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
int dp[n+3];
for(int i=0;i<=n;i++)
    dp[i]=-1;
    int ok=1;
for(int i=0;i<m;i++)
{
    int a,b;
cin>>a>>b;
if(dp[a]==-1)
     dp[a]=b;
     else if(dp[a]!=b)
     {
         ok=0;
     }

}
if(n==1&&m==0)
{
    cout<<0<<endl;
    return 0;
}
int is=0;
for(int i=1;i<=n;i++)
{
    if(is)
    {
     if(dp[i]==-1)
     dp[i]=0;
    }
    else
    {
        if(dp[i]==-1)
            dp[i]=1;
        is=1;
    }
}
vector<int> ans;
for(int i=n;i>=1;i--)
    ans.pb(dp[i]);
    if(dp[1]==0&&n!=1)
    {
        ok=0;
    }
    
if(!ok)
{
    cout<<-1<<endl;
    return 0;
}
reverse(ans.begin(),ans.end());
for(int i=0;i<n;i++)
    cout<<ans[i];
cout<<endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
dp=[0]+[10**6]*100010

for i in range(1,n+1):
    power=1
    while power<=i:
        dp[i]=min(dp[i],dp[i-power]+1)
        power*=6
    power=1
    while power<=i:
        dp[i]=min(dp[i],dp[i-power]+1)
        power*=9

print(dp[n])

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

ll sub(ll a, ll b){
    return((a % MOD - b % MOD + MOD) % MOD);
}
ll ad(ll a, ll b){
    return((a % MOD + b % MOD) % MOD);
}


int a[105];
int dp[105][N];
int prefix[N];
int main(){
	fast;
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 0; i <= a[1]; i++){
		dp[1][i] = 1;
	}
	for(int i = 0; i <= k; i++){
		prefix[i] = (i == 0) ? 0 : prefix[i -  1];
		prefix[i] = ad(prefix[i], dp[1][i]);
	}

	for(int i = 2; i <= n; i++){
		for(int j = 0; j <= k; j++){
			int en = j - 0;
			int st = j - min(a[i], j);
			dp[i][j] = ad(dp[i][j], (st == 0) ? prefix[en] : sub(prefix[en],  prefix[st - 1]));
		}
		prefix[0] = 0;
		for(int j = 0; j <= k; j++){
			prefix[j] = (j == 0) ? 0 : prefix[j -  1];
			prefix[j] = ad(prefix[j], dp[i][j]);
			
		}
		
	}
	cout << dp[n][k];
	return 0;
}


Measured memory_bytes: 40832
#include <stdio.h>

int main(void)
{
  int S, h, m, s;
  scanf("%d", &S);

  if (S >= 0 && S < 86400)
  {
    h = S / 3600;

    m = (S - h*3600) / 60;

    s = (S - h*3600) - m*60;

    printf("%d:%d:%d\n", h, m, s);
  }

}



Measured memory_bytes: 2140
var primeNxt = new Array(1000000);

function primeGenerator()
{
    var p, fact, m;
    var maxN = 9999999;
    var primePrv = new Array(1000000);

    // Initial
    for(p=2;p<=maxN;++p){
        primeNxt[p] = p + 1;
        primePrv[p] = p - 1;
    }
    primePrv[2] = 0;
    primeNxt[maxN] = 0;
    
    // Make prime table (primeNxt)
    for(p=2;p*p<=maxN;p=primeNxt[p]){
        for(fact=p;p*fact<=maxN;fact=primeNxt[fact]){
            for(m=p*fact;m<=maxN;m*=p){
                primeNxt[primePrv[m]] = primeNxt[m];
                primePrv[primeNxt[m]] = primePrv[m];
            }
        }
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
 
process.stdin.on('data', function(input){
    primeGenerator();
    input.trim().split('\n').forEach(function(val){
        var N = parseInt(val);
        var cnt = 1;
        if( N == 1 ){
            console.log(0);
        }
        else if( N == 2 ){
            console.log(1);
        }
        else{
            for(var i=3;i<=N;i=primeNxt[i]){
               ++cnt;
            }
            console.log(cnt);
        }
    });
});

Measured memory_bytes: 254604
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
ab = sorted(ab, key = lambda x : x[1])

ans = 0
end = 0
for i in range(m):
    if ab[i][0] >= end:
        end = ab[i][1]
        ans += 1

print(ans)

Measured memory_bytes: 29852
#include <stdio.h>
int main(void){
    int a, i, OK, NG;
    int A[1000];
    scanf("%d", &a);
    for(i = 0; i < a; i++){
        scanf("%d", &A[i]);
    }
    OK = 0;
    NG = 1;
    for(i = 0; i < a; i++){
        if(A[i]%2 == 0){
            if(A[i]%3 == 0 || A[i]%5 == 0){
                //OK = OK + 1;
            }else{
                NG = NG - 1;
            }
                
        }
         
    }
    if(NG > 0){
        printf("APPROVED");
    }else{
        printf("DENIED");
    }
}


Measured memory_bytes: 128
s = input()
l = len(s)
k = 3
n = 753
min_diff = 100000000000
for i in range(l - k + 1):
    ss = int(s[i:(i + k)])
    diff = abs(n - ss)
    if diff < min_diff:
        min_diff = diff
print(min_diff)

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

int main(){
    string s; cin >> s;
    map<char,int> mp;

    for(int i = 'a'; i <= 'z'; i++){
        mp[i] = 0;
    }

    for(char c : s){
        mp[c]++;
    }

    for(auto a : mp){
        if(a.second == 0){
            cout << a.first << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
 int n; cin >> n;
 int x[n],y[n]; 
  rep(i,n){
    cin >> x[i];
    y[i] = x[i];
  }
  
  sort(x,x+n);
  
  for(int j=0;j<n;j++){
    if(y[j] <= x[n/2]-1){
      cout << x[n/2] << endl;
    } else {
      cout << x[n/2-1] << endl;
    }
  }
    
    
 return 0;
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"

using namespace std;

// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_5_A

const int N = 20;

void Main() {
    int n;
    cin >> n;
    vector<int> A(n, 0);
    int total = 0;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        total += A[i];
    }
    int Q;
    cin >> Q;
    vector<int> queries(Q, 0);
    map<int, bool> res;
    for (int q = 0; q < Q; ++q) {
        cin >> queries[q];
        res.insert(make_pair(queries[q], false));
    }

    for (auto q : res) {
        int m = q.first;
        if (m > total) {
            res[m] = false;
            continue;
        }
        int ok = false;
        for (int b = 0; b < (1 << N); ++b) {
            bitset<N> bit(b);
            int sum = 0;
            for (int i = 0; i < n; ++i) {
                if (bit[i]) {
                    sum += A[i];
                }
            }
            if (sum == m) {
                ok = true;
                break;
            }
        }
        res[m] = ok;
    }
    for (int q = 0; q < Q; ++q) {
        cout << (res[queries[q]] ? "yes" : "no") << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <string>
using namespace std;

#define For(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Rep(i,n) For(i,0,n)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF 1000000000

#define MAX_N 24

struct disk{
	int x, y, r, c;
	disk(int a, int b, int c, int d):x(a),y(b),r(c),c(d){}
};

int N;
char mem[1<<MAX_N];
vector<disk> D;

bool is_top(int k, int b){
	Rep(i,k) if((b&(1<<i)) == 0 && ((D[i].x-D[k].x)*(D[i].x-D[k].x)+(D[i].y-D[k].y)*(D[i].y-D[k].y) < (D[i].r+D[k].r)*(D[i].r+D[k].r))) return false;
	return true;
}

int dfs(int b){
	if(mem[b] != -1) return mem[b];
	int res = -1;
	Rep(i,N)For(j,i+1,N){
		if((b&(1<<i)) == 0 && (b&(1<<j)) == 0){
			if(D[i].c == D[j].c && is_top(i, b) && is_top(j, b)) res = max(dfs(b|(1<<i)|(1<<j)), res);
		}
	}
	if(res != -1) return mem[b] = res+2;
	else return mem[b] = 0;
}

int main(){
	while(1){
		cin >> N;
		if(N == 0) break;
		D.clear();
		Rep(i,N){
			int x, y, r, c;
			scanf("%d %d %d %d", &x, &y, &r, &c);
			D.pb(disk(x, y, r, c));
		}
		Rep(i,1<<N) mem[i] = -1;
		printf("%d\n", dfs(0));
	}
	return 0;
}

Measured memory_bytes: 17612
N = input()
F = [map(int, raw_input().split()) for _ in range(N)]
P = [map(int, raw_input().split()) for _ in range(N)]
res = -float('inf')
for i in range(1, 2 ** 10):
  mask = '0' * (10 - len(bin(i)) + 2) + bin(i)[2:]
  cand = 0
  for j in range(N):
    c = 0
    for k in range(10):
      c += F[j][k] & int(mask[k])
    cand += P[j][c]
  res = max(res, cand)
print res

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
int main(){
   string ans="Three";
   int n;
   std::cin >> n;
   for (int i = 0; i < n; i++) {
       /* code */
       string s;
       std::cin >> s;
       if(s=="Y")ans="Four";
   }
   std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
const int MAX_N=100;
int k[MAX_N];
int n;
string s;
void solve(){
  int p=0, u,l;
  for(char c:s){
    u=c-'A';
    l=c-'a';
    if(l>=0){
      l-=k[p];
      if(l<-26)cout<<(char)(l+'a'+52);
      else if(l<0)cout<<(char)(l+'A'+26);
      else cout<<(char)(l+'a');
    }else{
      u-=k[p];
      if(u<-26)cout<<(char)(u+'A'+52);
      else if(u<0)cout<<(char)(u+'a'+26);
      else cout<<char(u+'A');
    }
    p=(p+1)%n;
  }
  cout<<endl;
}
int main(){ _;
  while(cin>>n,n!=0){
    REP(i,n)cin>>k[i];
    cin>>s;
    solve();
  }
}

Measured memory_bytes: 1200
#define scanf_s scanf
#include <stdio.h>
#include<iostream>
#include <list>
#include <vector>
#include <iostream>
using namespace std;
#define MAX 101

int main()
{
	while (1) {
		int X, Y, r, cou = 0;
		scanf_s("%d %d", &X, &Y);
		if (X == 0 && Y == 0) break;
		if (X < Y) {
			r = X;	X = Y; Y = r;
		}
		 do{
			r = X % Y;
			X = Y; Y = r;
			++cou;
		 } while (r != 0);
		printf("%d %d\n", X, cou);
	}
}

Measured memory_bytes: 1188
// #include <bits/stdc++.h>//C++のライブラリすべてinclude
#include<stdio.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<tuple>
#include<map>//map<char,char> a["a"]="a"
#include<limits>//ex numeric_limits<int>::max()
#include<math.h>
#define llong long long
#define INF 999999999

using namespace std;

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

    string s,t;
    cin >>s>>t;

    std::map<char, char> mp;
    std::map<char, char> mp2;
    for (int i = 0; i < s.size(); ++i)
    {
        if(mp.find(s[i])==mp.end()){
            if (mp2.find(t[i])==mp2.end())
            {
                mp[s[i]]=t[i];
                mp2[t[i]]=s[i];
                continue;
            }
        }
        if(!((mp[s[i]]==t[i]) && (mp2[t[i]]==s[i]))){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 916
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    a: usize,
    mut b: usize,
    mut c: usize,
    k: usize
    }
    for _ in 0..k {
        if b <= a {
            b *= 2
        } else if c <= b {
            c *= 2
        }
    }
    let ans = if a < b && b < c {"Yes"} else {"No"};
    println!("{}", ans);
}


Measured memory_bytes: 2144
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    int tmp = 0;
    rep(i, n){
        int x, y; cin >> x >> y;
        if(x == y) {
            tmp++;
            if(tmp >= 3){
                puts("Yes");
                return;
            }
        }
        else tmp = 0;
    }
    puts("No");
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  string T;
  cin >> T;
  cout << "A" << T[0] << "C" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    ll n,m;
    cin >> n >> m;
    bool is_solved[n] = {false};
    ll wa_cnt[n] = {};
    rep(i,0,m){
        ll p;
        string s;
        cin >> p >> s;
        if(!is_solved[p-1]){
            if(s == "AC"){
                is_solved[p-1] = true;
            }
            else{
                wa_cnt[p-1]++;
            }
        }
    }

    ll wa_ans = 0,ac_ans = 0;
    rep(i,0,n){
        if(is_solved[i]){
            ac_ans++;
            wa_ans += wa_cnt[i];
        }
    }
    cout << ac_ans << " " << wa_ans << endl;
    return 0;
}


Measured memory_bytes: 4440
#include<bits/stdc++.h>
#define int long long
#define rep(i,m,n) for(int i=m;i<n;i++)
#define repr(i,n,m) for(int i=n;i>=m ;i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define do int n; cin>>n; vector<int>v1(n); rep(i,0,n) cin>>v1[i];
#define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define print(v1) rep(i,0,v1.size()){cout<<v1[i]<<" ";} cout<<"\n";

// oset s;s.insert(1);*s.find_by_order(index);=value(logn)order_of_key(k)=index

using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.first > b.first);
}
int modulo(int n,int m=1000000007){
    if(n<0){
        return (m-abs(n)%m)%m;
    }
    if(n%m>=0)return n%m; return n%m+m;;
}
bool isPrime(int n){
  for(int i=2;i*i<=n;i++){
    if(n%i==0)
      return false;
  }
  return true;
}
int power(int a,int n){
    if(n==0) return 1;
    if(n==1) return a;
    if(n==2) return (a*a)%mod;
    if(n&1){
        n--;
        return (a*power(power(a,2),n/2))%mod;
    }
    else return (power(power(a,2),n/2))%mod;
}
int fact(int n){
  int total=1;
  rep(i,2,n+1){
    total=(total*i)%mod;
    // cout<<total+mod<<"\n";
  }
  return (total)%mod;
}
int isLeap(int i){
  if(i%4==0){
    if(i%100==0&&i%400!=0)
      return 0;
    return 1;
  }
  return 0;
}
void solve()
{
    string s;
    cin>>s;
    int n=s.size();
    if(s[n-1]=='s')
      cout<<s+"es";
    else
      cout<<s+'s';

    
} 
 
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
   
   int t=1;
   //cin>>t;
   while(t--)
   {
      solve();
      cout<<"\n";
   }
   cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
  return 0;
 }

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

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

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U> void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
   LL H, W; cin >> H >> W;
   map<char,LL> cnt;
   for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
         char c; cin >> c;
         ++cnt[c];
      }
   }

   map<int,LL> num;
   for (auto it = cnt.begin(); it != cnt.end(); ++it) {
      for (auto k : { 4, 2, 1 }) {
         num[k] += it->second / k;
         it->second %= k;
      }
   }

   map<int,LL> a{{4,(H/2)*(W/2)},
                 {2,(H/2)*(W%2)+(W/2)*(H%2)},
                 {1,(H%2)*(W%2)}};

   if (num[4] < a[4]) {
      cout << "No" << endl;
      return 0;
   } else {
      num[2] += (num[4] - a[4]) * 2;
   }

   if (num[2] < a[2]) {
      cout << "No" << endl;
      return 0;
   } else {
      num[1] += (num[2] - a[2]) * 2;
   }

   if (num[1] < a[1]) {
      cout << "No" << endl;
      return 0;
   }

   cout << "Yes" << endl;

   return 0;
}


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

using namespace std;

typedef long long ll;

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

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

/*
 * ref. http://drken1215.hatenablog.com/entry/2018/06/08/210000
 *
 * usage:
 *
 * Combination *c;
 * 
 * const int MOD = 1000000007;
 * const int MAX_N = 100000;
 * 
 * int main(void) {
 *     int n, k;
 *     cin >> n >> k;
 *     c = new Combination(2 * MAX_N, MOD);
 *     cout << c->com(n + k - 1, k) << endl;
 *     delete(c);
 *     return 0;
 * }
 */
class Combination {
    public:
        const int max;
        const int mod;
        vector<ll> fac, finv, inv;

        Combination(int max, int mod) : max(max), mod(mod), fac(max), finv(max), inv(max) {
            init();
        }

        ll com(int n, int k) {
            if (n < k) return 0LL;
            if (n < 0 || k < 0) return 0LL;
            // return (fac[n] * ((finv[k] * finv[n - k]) % mod)) % mod;
            return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
        }

    private:
        void init() {
            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;
            }
        }
};

Combination *c;

const int MOD = 1000000007;
const int MAX_N = 100000;

vector<ll> A;

ll solve(const ll N, const ll K) {
    ll maxs = 0;
    for (int i = K; i <= N; i++) {
        ll v = A[i] * c->com(i - 1, K - 1);
        // printf("max[%d]: %lld\n", i, v);
        maxs = (maxs + (v % MOD)) % MOD;
    }

    ll mins = 0;
    for (int i = 1; i <= N - K + 1; i++) {
        ll v = A[i] * c->com(N - i, K - 1);
        // printf("min[%d]: %lld\n", i, v);
        mins = (mins + (v % MOD)) % MOD;
    }

    ll ans = (maxs - mins) % MOD;
    if (ans < 0) ans += MOD;
    return ans;
}

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

    A.resize(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    sort(A.begin() + 1, A.end());

    c = new Combination(2 * MAX_N, MOD);

    cout << solve(N, K) << endl;
    // cout << c->com(n + k - 1, k) << endl;

    delete(c);
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
using namespace std;
int main(){

	int n, k, q; cin >> n >> k >> q;
	vector<int> s(n,k - q);
	for (int i = 0; i < q; i++) {
		int a; cin >> a;
		s[a - 1]++;
	}
	for (int i = 0; i < n; i++) {
		if (s[i] <= 0) { cout << "No" << endl; }
		else { cout << "Yes" << endl; }
	}


	return 0;
}

Measured memory_bytes: 1024
n=int(input())
d={i:0 for i in range(2,n+1)}
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
for i in range(2,n+1):
    for j in prime_factorize(i):
        d[j]+=1
a=1
for v in d.values():
    a=a*(v+1)
print(a%(10**9+7))

Measured memory_bytes: 9104
function input()
  local inp = io.read()
  local r={}
  string.gsub(inp,"(%S+)", function (v) table.insert(r,tonumber(v)) end)
  return r
end

local n,m
local inp = input()
n = inp[1]
m = inp[2]
local b={}
local cnt = 1
local i=1
while i*i<=m do
  if m%i==0 then
    b[cnt]=i
    cnt = cnt+1
    b[cnt]=m//i
    cnt = cnt+1
  end
  i=i+1
end
local res = 1
for i=1,cnt-1,1 do
  if b[i]*n<=m then
    res = math.max(res,b[i])
  end
end
print(res)

Measured memory_bytes: 256
n,x=map(int,input().split())

a,p=[1],[1]

for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(N,X):
    if N==0:
        return 0 if X<=0 else 1

    elif X<=1+a[N-1]:
        return f(N-1,X-1)

    else:
        return p[N-1]+1+f(N-1,X-2-a[N-1])

print(f(n,x))

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

using ll = long long;
const int MAXN = 5100;
int N;
ll dp[MAXN][MAXN];
int P[MAXN];
ll A, B;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	cin >> N >> A >> B;
	for (int i = 1; i <= N; i++) {
		cin >> P[i];
	}
	P[N+1] = N+1;

	dp[0][0] = 0;
	for (int i = 1; i <= N+1; i++) {
		dp[i][i] = ll(1e18);
		for (int j = 0; j < i; j++) {
			if (P[i] > P[j]) dp[i][i] = min(dp[i][i], dp[i-1][j]);
			dp[i][j] = dp[i-1][j] + (P[i] > P[j] ? A : B);
		}
	}

	cout << dp[N+1][N+1] << '\n';

	return 0;
}


Measured memory_bytes: 199168
#include<bits/stdc++.h>
using namespace std;
long long m=998244353;

long long power(long long x,long long y)
{
    long long res = 1; x=x%m;
    while (y > 0)
    {
        if (y & 1) res = (res*x)%m;
        y = y>>1;
        x = (x*x)%m;
    }
    return res%m;
}


int main()
{
    int k,n;
    cin>>k>>n;
    long long a[n],ans=LLONG_MAX;
    for(int i=0; i<n; i++)
    {
        long long x=LLONG_MAX;
        cin>>a[i];
        if(i>0) x=k-a[i]+a[i-1];
        ans=min(ans,x);
    }
    ans=min(ans,a[n-1]-a[0]);
    cout<<ans<<endl;
    return 0;
}


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

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

typedef long long ll;

const int MAX_N = 10000;
const int INF = 1e6;

int main() {
  int n, a[MAX_N], amin, amax;
  ll sum;

  amin = INF;
  amax = -INF;
  sum = 0;

  cin >> n;
  REP(i, n) {
    cin >> a[i];
    amin = min(amin, a[i]);
    amax = max(amax, a[i]);
    sum += a[i];
  }

  cout << amin << ' ' << amax << ' ' << sum << endl;

  return 0;
}

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

void run(int r, int n) {
	vector< int > s(n), t(n), h(n);
	for (int i=0; i<n; ++i) cin >> s[i] >> t[i] >> h[i];
	
	double ans = 1e9;
	for (int x=-r; x<=r; ++x) {
		int hx = 0;
		for (int i=0; i<n; ++i) {
			if (abs(x) == r && s[i] <= r && r <= t[i]) hx = max(hx, h[i]);
			else if (s[i] < x && x < t[i]) hx = max(hx, h[i]);
		}
		for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) if (i != j && t[i] == s[j] && t[i] == x) hx = max(hx, min(h[i], h[j]));
		ans = min(ans, r - (double)r * sin(acos((double)x / r)) + hx);
	}
	
	printf("%.5lf\n", ans);
}

int main() {
	int r, n;
	while (cin >> r >> n, r) run(r, n);
}


Measured memory_bytes: 3608
/*
 * 2498.cc: Cube of Two
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int rps[6][2][4][2] =
  {{{{3, 0}, {5, 0}, {2, 0}, {4, 3}},
    {{3, 2}, {5, 2}, {2, 2}, {4, 1}}},
   {{{3, 1}, {4, 2}, {2, 1}, {5, 1}},
    {{3, 3}, {4, 0}, {2, 3}, {5, 3}}},
   {{{5, 2}, {1, 2}, {4, 2}, {0, 2}},
    {{5, 3}, {1, 3}, {4, 3}, {0, 3}}},
   {{{5, 0}, {0, 0}, {4, 0}, {1, 0}},
    {{5, 1}, {0, 1}, {4, 1}, {1, 1}}},
   {{{1, 1}, {3, 0}, {0, 2}, {2, 3}},
    {{1, 3}, {3, 1}, {0, 0}, {2, 2}}},
   {{{3, 2}, {1, 0}, {2, 1}, {0, 3}},
    {{3, 3}, {1, 2}, {2, 0}, {0, 1}}}};

/* typedef */

/* global variables */

string sfs[6];

/* subroutines */

void print_dev() {
  vector<string> dv(6, string(8, '.'));
  dv[0][2] = sfs[3][0]; dv[0][3] = sfs[3][1];
  dv[1][2] = sfs[3][2]; dv[1][3] = sfs[3][3];
  dv[2][0] = sfs[0][0]; dv[2][1] = sfs[0][1];
  dv[3][0] = sfs[0][2]; dv[3][1] = sfs[0][3];
  dv[2][2] = sfs[5][0]; dv[2][3] = sfs[5][1];
  dv[3][2] = sfs[5][2]; dv[3][3] = sfs[5][3];
  dv[2][4] = sfs[1][0]; dv[2][5] = sfs[1][1];
  dv[3][4] = sfs[1][2]; dv[3][5] = sfs[1][3];
  dv[2][6] = sfs[4][0]; dv[2][7] = sfs[4][1];
  dv[3][6] = sfs[4][2]; dv[3][7] = sfs[4][3];
  dv[4][2] = sfs[2][0]; dv[4][3] = sfs[2][1];
  dv[5][2] = sfs[2][2]; dv[5][3] = sfs[2][3];

  for (int i = 0; i < 6; i++) cout << dv[i] << endl;
}

void rot_sf(int i) {
  char t = sfs[i][2];
  sfs[i][2] = sfs[i][3]; sfs[i][3] = sfs[i][1]; sfs[i][1] = sfs[i][0];
  sfs[i][0] = t;

  for (int j = 0; j < 2; j++) {
    const int (&rp)[4][2] = rps[i][j];
    t = sfs[rp[3][0]][rp[3][1]];
    for (int k = 3; k > 0; k--)
      sfs[rp[k][0]][rp[k][1]] = sfs[rp[k - 1][0]][rp[k - 1][1]];
    sfs[rp[0][0]][rp[0][1]] = t;
  }
}

/* main */

// x-=L, x+=R, y-=D, y+=U, z-=B, z+=F
//  U    3
// LFRB 0514
//  D    2
//
//         010,011
//         110,111
// 010,110 110,111 111,011 011,010
// 000,100 100,101 101,001 001,000
//         100,101
//         000,001

int main() {
  sfs[0] = string(4, 'g'); // L
  sfs[1] = string(4, 'b'); // R
  sfs[2] = string(4, 'o'); // D
  sfs[3] = string(4, 'r'); // U
  sfs[4] = string(4, 'w'); // B
  sfs[5] = string(4, 'y'); // F
  //print_dev();

  string s;
  cin >> s;

  char t;
  
  for (int i = 0; i < s.size(); i++)
    switch (s[i]) {
    case 'L': rot_sf(0); break;
    case 'R': rot_sf(1); break;
    case 'D': rot_sf(2); break;
    case 'U': rot_sf(3); break;
    case 'B': rot_sf(4); break;
    case 'F': rot_sf(5); break;
    }

  print_dev();
  return 0;
}

Measured memory_bytes: 1192