akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n,k;
  cin >> n >> k;
  if(n<=k/2) cout << n << endl;
  else if(k>=n) cout << k-n << endl;
  else{
    n=n%k;
    if(n<=k/2) cout << n << endl;
    else cout << k-n << endl;
  }
}

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

int main()
{
	int h,n;
  	cin >> h >> n;
  	int a;
  	for(int i=0;i<n;i++)
    {
    	cin >> a;
      	h -= a;
    }
  	if(h<=0)
    {
      cout << "Yes" << endl;
    }
  	else 
    {
    	cout << "No" << endl;
    }
}

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

#define MAX_N 200010

unsigned long int A[MAX_N], res;
int mv, K, N;

int main() {
    std::cin >> N >> K;
    for (int i=0; i<N; i++) {
        int idx;
        std::cin >> idx;
        ++A[idx];
        mv = std::max(mv, idx);
    }

    std::sort(A, A+mv+1, std::greater<unsigned long int>());
    res = N;
    for (int i=0; i<K; i++) res -= A[i];
    std::cout << res << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <boost/functional/hash.hpp>
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUGM(xs) cout<<#xs<<": ";REP(_i,(int)xs.size())cout<<xs[_i]<<", ";cout<<endl;
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(xs) begin(xs),end(xs)
#define _1 first
#define _2 second
#define P(k, v) make_pair(k, v)
#define PII pair<int, int>
using namespace std;
template<class T> using V = vector<T>;
template<class K> using uset = unordered_set<K, boost::hash<K>>;
template<class K, class V> using umap = unordered_map<K, V, boost::hash<K>>;
int dx[] = { 0, 1, 0, -1 }, dy[] = { 1, 0, -1, 0 }; // ??? ??? ??? ???

int main() {
    while(true){
        int n; scanf("%d", &n);
        if(n==0)return 0;
        uset<PII> hs;
        REP(i,n){int f,s;scanf("%d %d",&f,&s);hs.emplace(P(f,s));};
        int m; scanf("%d", &m);
        umap<char,int> conv = {{'N',0},{'E',1},{'S',2},{'W',3}};
        V<PII> xys(m);
        REP(i,m){char c;scanf(" %c %d",&c,&xys[i]._2);xys[i]._1=conv[c];}
        int x=10,y=10;
        REP(i,m){
            REP(j,xys[i]._2){
                x+=dx[xys[i]._1], y+=dy[xys[i]._1];
                hs.erase(P(x,y));
            }
        }
        if(hs.size()==0)printf("Yes\n");
        else printf("No\n");
    }
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int h[n];
  int count = 0;
  for(int i = 0;i<n;i++){
    cin >> h[i];
    if(h[i] >= k)count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

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

		// 入力値の取得
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		
		// 結果の出力
		System.out.println(Z + " " + X + " " + Y);

		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    string s; cin>>s;
    rep(i,3) if (s[i] == '7') {
        cout << "Yes" << '\n';
        return 0;
    }
    cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define rep1(i,s,e) for(int i=s;i<e;i++)
#define rep2(i,s,e,c) for(int i=s;i>=e;i--)
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define pfn() printf("\n")
#define pfs() printf(" ")
#define sfi(x) scanf("%d",&x)
#define sfi1(x,y) scanf("%d%d",&x,&y)
#define sff(x) scanf("%lf",&x)
#define sfl(x) scanf("%lld",&x)
#define memset1(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const int MAX = 1e4 + 50;
const int mod = 1e9+7;
int a[2005];
ll pre[2005]={0},net[2005]={0};
ll cal(ll k){
	return (1+k)*k/2%mod;
}
int main(){
	ll N,K;
	cin>>N>>K;
	for(int i=0;i<N;i++){
		sfi(a[i]);
	}
	ll mul=cal(K),mul1=(mul-K+mod)%mod;
	for(int i=0;i<N;i++){
		for(int j=0;j<i;j++){
			if(a[j]<a[i]) pre[i]++;
		}
		for(int j=i+1;j<N;j++){
			if(a[j]<a[i]) net[i]++;
		}
	}
	ll ans=0;
	for(int i=0;i<N;i++){
		ans=(ans+net[i]*mul%mod)%mod;
		ans=(ans+pre[i]*mul1%mod)%mod;
	}
	ans=(ans+mod)%mod;
	pfl(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) cout << c << "\n";
	else if (a == c) cout << b << "\n";
	else cout << a << "\n";

	return 0;
}


Measured memory_bytes: 888
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;
#define cni cin

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int n,m,k,ans=INT_MAX;
string s;

main(){
	cin>>s;
	
	for(int i=0;i<s.size()-2;i++){
		string t;
		for(int j=i;j<i+3;j++){
			t+=s[j];
		}
		debug(t);
		ans=min(ans,abs(toInt(t)-753));
	}
	dans;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int x,y,z;
    cin>>x>>y>>z;
    printf("%d %d %d\n",z,x,y);
    return 0;
}

Measured memory_bytes: 888
def pow_mod(a, b, p):
    res = 1
    mul = a
    for i in range(len(bin(b)) - 2):
        if (1 << i) & b:
            res = (res * mul) % p
        mul = (mul ** 2) % p
    return res


def comb_mod(n, r, p, factorial=None, invert_factorial=None):
    return (factorial[n] * invert_factorial[r] * invert_factorial[n - r]) % p


def main():
    p = 10 ** 9 + 7
    n, k = map(int, input().split())

    factorial = [1] * (n + 1)
    for i in range(1, n + 1):
        factorial[i] = (factorial[i - 1] * i) % p

    invert_factorial = [0] * (n + 1)
    invert_factorial[n] = pow_mod(factorial[n], p - 2, p)
    for i in range(n - 1, -1, -1):
        invert_factorial[i] = (invert_factorial[i + 1] * (i + 1)) % p

    res = 0
    for i in range(min(k + 1, n)):
        res = (res + comb_mod(n, i, p, factorial, invert_factorial)
               * comb_mod(n - 1, i, p, factorial, invert_factorial)) % p
    print(res)


main()


Measured memory_bytes: 18804
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n, i;
        n = cin.nextInt();
        int[] A = new int[n];
        for (i = 0; i < n; i++) {
            A[i] = cin.nextInt();
        }
        
        insertionSort(A, n);
    }
    static void insertionSort(int[] A, int n) {
        int i, j, v;
        for (i = 0; i < n; i++) {
            v = A[i];
            for (j = i - 1; j >= 0 && A[j] > v; j--) {
                A[j + 1] = A[j];
            }
            A[j + 1] = v;
            printArray(A, n);
        }
    }
    static void printArray(int[] A, int n) {
        int i;
        for (i = 0; i < n - 1; i++) {
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    }
}


Measured memory_bytes: 33340
#include <stdio.h>

int main(void){

    int x, h1=0, h2=0, h;
    scanf("%d",&x);

    h1 = x / 500;
    h1 = h1 * 1000;
    
    h2 = (x % 500) / 5;
    h2 = h2 * 5;

    h = h1 + h2;
    printf("%d\n", h);

    return 0;
    
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	int cnt = 0;
	vector<int> ans;
	for (int i = 1; i <= min(a, b); i++) {
		if (a%i == 0 && b%i == 0) {
			ans.push_back(i);
			cnt++;
		}
	}
	cout << ans[cnt - k] << endl;
	return 0;
}

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

int main(){
	char s[100001];
	int k;
	cin>>s>>k;
	
	int i, tmp, len;
	len=strlen(s);
	for(i=0;i<len;i++){
		if(s[i]=='a'&&i!=len-1) continue;
		tmp=s[i];
		if((123-tmp)<=k&&i!=len-1){
			k-=(123-tmp);
			s[i]='a';
		}   
		else if(i==len-1){
			k%=26;
			tmp=s[i];
			tmp+=k;
			if(tmp>=123) {tmp-=123; tmp+=97;}
			s[i]=tmp;
		}
	}
	
	for(i=0;i<len;i++){
		if(s[i]>122){
			tmp=s[i]-97;
			tmp%=26;
			s[i]=97+tmp;
		}
		cout<<s[i];
	}	
	cout<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] str = s.split("/");
		if(Integer.parseInt(str[0])>=2019 && Integer.parseInt(str[1])>4) {
			System.out.println("TBD");
		}else {
			System.out.println("Heisei");
		}
	}
}

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

template <typename T>
class BIT{
  vector<T> array;
  int n;
public:
  BIT(int num){
    n = num;
    array.resize(n + 1);
  }
  T sum(int i){
    T s = 0;
    while(i > 0){
      s += array[i];
      i -= i & -i;
    }
    return s;
  }
  T sum(int i, int j){
    return sum(j)-sum(i-1);
  }
  void add(int i, T x){
    while(i <= n){
      array[i] += x;
      i += i & -i;
    }
  }
};

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>a(n);

  rep(i,n){
    cin>>a[i];
    a[i]-=k;
  }

  //累積和
  vector<ll>S(n+1);
  for(int i=1; i<=n; ++i){
    S[i]=S[i-1]+a[i-1];
  }
  
  //座標圧縮
  map<ll,int>mp;
  rep(i,n+1)mp[S[i]]++;
  int cnt=1;
  for(auto &p:mp){
    p.second=cnt;
    cnt++;
  }
  rep(i,n+1){
    S[i]=mp[S[i]];
  }

  ll ans=(ll)n*(n+1)/2;
  BIT<int>bit(n+1);
  rep(i,n+1){
    bit.add(S[i],1);
    ans-=bit.sum(n+1)-bit.sum(S[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 18828
//good bye 2019//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	ll t=min(n,k);
	cout<<n-t<<" "<<max(m+t-k,0ll)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N; cin >> N;
  string S = to_string(N);
  int fx = 0;
  for(char c:S) fx += c-'0';
  printf(N%fx?"No\n":"Yes\n");
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
#include <functional>
#include <vector>

using namespace std;

struct edge {
    int from, to;
    int dist;
    int cost;
    edge(int from, int to, int dist, int cost) : 
        from(from), to(to), dist(dist), cost(cost){}
};

#define INF (1<<28)
#define MAX_N 10001
int N, M;
vector<edge> graph[MAX_N];
vector<edge> prevs[MAX_N];
int dist[MAX_N];

void dijkstra() {
    fill(dist, dist+N, INF);
    for (int i = 0; i < N; i++) prevs[i].clear();
    typedef pair<int, int> P; // 最短距離, 頂点番号
    priority_queue< P, vector<P>, greater<P> > q;
    dist[0] = 0;
    q.push(P(0, 0));

    while (!q.empty()) {
        P p = q.top(); q.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < graph[v].size(); i++) {
            edge e = graph[v][i];
            if (dist[e.to] > dist[v] + e.dist) {
                //printf("%d ", e.to);
                dist[e.to] = dist[v] + e.dist;
                prevs[e.to].clear(); prevs[e.to].push_back(e);
                q.push(P(dist[e.to], e.to));
            } else if (dist[e.to] == dist[v] + e.dist) {
                //printf("%d ", e.to);
                prevs[e.to].push_back(e);
            }
        }
    }
}

bool used[MAX_N];
int solve(int v) {
    //printf("   v: %d\n", v);
    if (used[v]) return 0;
    int min_cost = INF;
    for (int i = 0; i < prevs[v].size(); i++) {
        min_cost = min(min_cost, prevs[v][i].cost);
    }
    //printf("    return: %d\n", min_cost);
    return min_cost;
}

int main() {
    while (scanf("%d %d", &N, &M), N || M) {
        for (int i = 0; i < N; i++) graph[i].clear();
        for (int i = 0; i < N; i++) prevs[i].clear();
        for (int i = 0; i < M; i++) {
            int u, v, d, c;
            scanf("%d %d %d %d", &u, &v, &d, &c);
            u--, v--;
            graph[u].push_back(edge(u, v, d, c));
            graph[v].push_back(edge(v, u, d, c));
        }
        dijkstra();

        int total = 0;
        fill(used, used+N, false);
        for (int i = 1; i < N; i++) {
            total += solve(i);
        }
        printf("%d\n", total);
    }
    return 0;
}

Measured memory_bytes: 4140
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;


int main(){
    int n;
    scanf("%d\n", &n);
    int l[2*n];

    for (int i = 0; i < 2*n; i++) {
        scanf("%d", &l[i]);
    }

    for (int i = 0; i < 2*n; i++) {
        for (int j = i+1; j < 2*n; j++) {
            if(l[i] > l[j]){
                int tmp = l[i];
                l[i] = l[j];
                l[j] = tmp;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += l[i*2];
    }

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

    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n string
	var K int
	fmt.Scan(&n, &K)
	digit := len(n)

	// dp := make([][2][4]int, digit+1)
	var dp [101][2][4]int
	dp[0][0][0] = 1

	for i := 0; i < digit; i++ { // 先頭桁から繰り返し
		d := int(n[i] - '0')

		// j: 未満フラグ。0がK個以上→1
		for j := 0; j < 2; j++ {

			// k: 0を含む数
			for k := 0; k < K+1; k++ {
				cnt := 9
				if j == 0 { // 対応する値より小さい値を入れたことがない
					cnt = d
				}

				for num := 0; num <= cnt; num++ {
					nj := j
					nk := k

					if num != 0 { // 0でない数字のカウント
						nk++
					}

					if K < nk { // 0でない数字がK個以上
						continue
					}

					if j == 0 {
						if num > d {
							continue
						}
						if num < d {
							nj = 1
						}
					}
					dp[i+1][nj][nk] += dp[i][j][k]
				}
			}
		}
	}
	fmt.Println(dp[digit][0][K] + dp[digit][1][K])
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
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, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    vll a(N), b(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    for (size_t i = 0; i < N; i++)
    {
        cin >> b[i];
    }

    ll sumA = accumulate(all(a), 0LL), sumB = accumulate(all(b), 0LL);
    ll op = sumB - sumA,n1=0,n2=0;

    for (size_t i = 0; i < N; i++)
    {
        ll K = b[i] - a[i];
        if (a[i] < b[i])
        {

            //           a[i] += ((K+1)/2) * 2;
            n1 += ((K + 1) / 2);
        }
        else
        {
            n2 += abs(K);
        }
    }
    cout << ((max(n1,n2) <= op) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <climits>

typedef long long ll;

const int MAXN = 3e5 + 7;
const ll HA = 998244353;

ll fac[MAXN], inv[MAXN];

ll fp(ll a, ll b = HA - 2) {
    ll ret = 1;
    while (b) {
        if (b & 1) ret = ret * a % HA;
        a = a * a % HA, b >>= 1;
    }
    return ret;
}

void init() {
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= 300000; i++) fac[i] = fac[i - 1] * i % HA;
    inv[300000] = fp(fac[300000]);
    for (int i = 300000 - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % HA;
    // for (int i = 1; i <= 30; i++) {
    //     printf("%lld\n", fac[i]);
    // }
}

ll C(ll n, ll m) {
    if (n < m) return 0;
    return fac[n] * inv[m] % HA * inv[n - m] % HA;
}

int main(int argc, char *argv[]) {
    init();
    int n, A, B;
    ll k, ans = 0;
    scanf("%d %d %d %lld", &n, &A, &B, &k);
    for (int i = 0; i <= n; i++) {
        if ((k - 1ll * A * i) % B) continue;
        if ((k - 1ll * A * i) < 0) continue;
        ll b = (k - 1ll * A * i) / B;
        if (b > n) continue;
        // printf("i = %d, b = %lld\n", i, b);
        ans = (ans + C(n, i) * C(n, b) % HA + HA) % HA;
    }
    printf("%lld\n", ans);
} 

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

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

    vector<int> h(N);
    for(int i=0;i<N;i++){
        cin >> h[i] ;
    }

    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<N;i++){
        dp[i] = min( dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]) );
    }

    cout << dp[N-1] << endl;
}

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

const int N =100010, inf=0x3f3f3f3f;
int dp[N];
int main(){
  int n, k;scanf("%d%d", &n, &k);
  memset(dp, inf, sizeof dp);
  dp[0]=0;
  vector<int> v(n);
  for(int i=0;i<n;i++)scanf("%d", &v[i]);

  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<i+k+1 && j<n;j++)
      dp[j]=min(dp[j], dp[i]+abs(v[i]-v[j]));
  }
  printf("%d\n", dp[n-1]);
}


Measured memory_bytes: 1024
import queue
def readInt():
    return list(map(int, input().split()))

N, M = readInt()

graph = [[] for i in range(N)] #部屋がどことつながっているかを入れるリスト 
v = [-1 for i in range(N)] #部屋を探索したことがなければ-1
v[0] = [0]

for i in range(M):
    x, y = readInt()
    graph[x-1].append(y-1) #graph[0]は部屋1
    graph[y-1].append(x-1)


q = queue.Queue()
q.put(0)

while not q.empty():
    n = q.get()
   
    for j in graph[n]:
        if v[j]!=(-1):
            continue
        q.put(j)
        v[j] = n
        
print("Yes")
for i in range(1, N):
    print(v[i] + 1)

Measured memory_bytes: 34252
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    int m,n,o,i;
    string a;
    //cin>>m>>n>>o;
    cin>>a;
    for(i=0;i<3;i++)
    {
        if(a[i]=='1') cout<<'9';
        else if(a[i]=='9') cout<<'1';
        else cout<<a[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double db;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define case_for(n) for(int i = 1 ; i <= n ; i ++) { cout<<"Case "<<i<<": "<<endl; solve();}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll power(ll a, ll b, ll p) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p, b /= 2; }return ans; }
int hw_check(string a, int l, int r) { int ans = r - l + 1; for (l, r; l < r; l++, r--)if (a[l] != a[r]) return 0; return ans; }
string movesubstr(string a, int l, int r) { string s = "";	for (int i = l; i <= r; i++) s.push_back(a[i]);	return s; }


void solve()
{
	string a; cin >> a;
	string l = "ABC", r = "ARC";
	if (a == "ABC") cout << r;
	else cout << l;

}
	
/*
3 3
3 3 3
4 1 3
4 1 3
*/
int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(nullptr),cout.tie(0);

	/*int t; cin >> t;
	while (t--) 
	{
		solve();
	}*/
	solve();
	return 0;
}
/*

*/

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using vll = vector<ll>;
const ll INF = 1e15 + 5;
int main() {
	int n, W; cin >> n >> W;
	vector<vll> dp(2, vll(W + 1));
	vi w(n), v(n);
	for (int i = 0; i < n; i++){
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j <= W; j++){
			dp[1][j] = dp[0][j];
			if (j - w[i] < 0) continue;
			dp[1][j] = max(dp[1][j], dp[0][j - w[i]] + v[i]);
		}
		dp[0] = dp[1];
	}
	cout << dp[0][W] << endl;

}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

int par[100];
int chl[100];
int chr[100];
P data[100];

ll gcd(ll u, ll v){
	while(u > 0){
		if(u < v) swap(u, v);
		u %= v;
	}
	return v;
}

ll lcm(ll u, ll v){
	return u / gcd(u, v) * v;
}

ll calc(int v){
	ll lw, rw;
	if(chr[v] == -1 && chl[v] == -1){
		return data[v].first + data[v].second;
	}else if(chr[v] == -1){
		return lcm(calc(chl[v]), data[v].second) /
			data[v].second * (data[v].first + data[v].second);
	}else if(chl[v] == -1){
		return lcm(calc(chr[v]), data[v].first) / 
			data[v].first * (data[v].first + data[v].second);
	}else{
		lw = calc(chl[v]);
		rw = calc(chr[v]);
		ll c = lcm(lw * data[v].first, rw * data[v].second);
		return c / data[v].first + c / data[v].second;
	}
}

int main(){
	int n, root;
	while(cin >> n && n){
		memset(par, -1, sizeof(par));
		memset(chl, -1, sizeof(chl));
		memset(chr, -1, sizeof(chr));
		rep(i, n){
			cin >> data[i].first >> data[i].second >> chl[i] >> chr[i];
			chl[i]--, chr[i]--;
			if(chl[i] != -1) par[chl[i]] = i;
			if(chr[i] != -1) par[chr[i]] = i;

			int a = gcd(data[i].first, data[i].second);
			data[i].first /= a;
			data[i].second /= a;
		}
		rep(i, n) if(par[i] == -1){
			root = i;
			break;
		}

		cout << calc(root) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        n: usize, m: usize,
        ab: [(Usize1, Usize1); m],
    }

    let mut uft = UFT::new(n);
    for (a, b) in ab {
        uft.merge(a, b);
    }

    let mut rank = vec![0usize; n];
    for i in 0..n {
        rank[uft.root(i)] += 1;
    }
    let ans = rank.iter().max().unwrap();
    println!("{}", ans);
}

#[allow(dead_code)]
/// Union Find Tree
pub struct UFT {
    pub par: Vec<usize>,
    pub rank: Vec<usize>,
}
impl UFT {
    #[allow(dead_code)]
    pub fn new(n: usize) -> Self {
        UFT {
            par: (0..n).collect(),
            rank: vec![0; n],
        }
    }
    #[allow(dead_code)]
    pub fn root(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            let p = self.par[x];
            let pp = self.root(p);
            self.par[x] = pp;
            pp
        }
    }
    #[allow(dead_code)]
    pub fn merge(&mut self, x: usize, y: usize) {
        let x = self.root(x);
        let y = self.root(y);
        if x == y {
            return;
        }
        if self.rank[x] < self.rank[y] {
            self.par[x] = y;
        } else {
            self.par[y] = x;
            if self.rank[x] == self.rank[y] {
                self.rank[x] += 1;
            }
        }
    }
}

Measured memory_bytes: 10804
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <utility>
#include <vector>

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

using namespace std;

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

    string S;
    cin >> S;

    char last = S[0];
    int len = 0;

    std::vector<int> combined;

    REP(i, S.size()) {
        if (last == S[i]) {
            len++;
        } else {
            if (last == '0') {
                combined.push_back(-len);
            } else {
                combined.push_back(+len);
            }
            len = 1;
            last = S[i];
        }
    }

    if (last == '0') {
        combined.push_back(-len);
    } else {
        combined.push_back(+len);
    }

    // REP(i, combined.size()) { cout << combined[i] << endl; }

    // マイナスの値をK個含む連続した累積和をとる．

    int best = 0;
    int current = 0;

    std::deque<int> dq;
    int minus_size = 0;

    REP(i, combined.size()) {
        if (combined[i] >= 0) {
            current += combined[i];

            dq.push_back(combined[i]);
        } else {
            current -= combined[i];
            dq.push_back(combined[i]);
            minus_size++;

            if (minus_size > K) {
                if (dq.front() > 0) {
                    current -= dq.front();
                    dq.pop_front();
                }

                if (dq.front() < 0) {
                    current += dq.front();
                    dq.pop_front();
                }
            }
        }

        best = max(best, current);
    }

    cout << best << endl;

    return 0;
}


Measured memory_bytes: 1020
#include <stdio.h>

int main(void)
{
    int n, a, min, max, i;
    long total = 0L;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &a);
        if (i == 0) {
            min = max = a;
        } else {
            if (a < min) {
                min = a;
            } else if (a > max) {
                max = a;
            }
        }
        total += a;
    }
    printf("%d %d %ld\n", min, max, total);
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long
#define MAX 1000000
#define INF 1000000 
#define M 1000000007
#define PI 2 * acos(0.0)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main(){
    fast_io
    ll n;
    cin>>n;
    ll val = 7;
    ll ans = -1;
    for(ll i = 1;i<=MAX;i++){
        if(val%n == 0){
            ans = i;
            break;
        }
        val = (val*10+7)%n;
    }
    cout<<ans<<endl;
    return 0;
}

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

#A
def A():
    while True:
        n = II()
        if not n:
            break
        a = IR(n)
        a.sort()
        print(sum(a[1:-1])//(n-2))
            
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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



Measured memory_bytes: 8196
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;

int popcount(uint x) {
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

int tzcnt(uint x) {
    return popcount(~x & x - 1);
}

struct Point {
    int x, y;

    Point(int p, int q) : x(p), y(q) {}
};

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

    int x;
    cin >> x;

    int m = 1;

    for (int i = 2; i <= x; ++i) {
        int t = i;

        while (true) {
            if (t * i <= x) t *= i;
            else break;
        }

        if (t != i) m = max(m, t);
    }

    out(m);
    
    int aaa;
    cin >> aaa;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
#define ll long long
ll mod = 1000000000+7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    cout.tie(NULL);
    ll T;
    T=1;
    //cin>>T;
    start:
    while(T--)
    {
        ll n;
        cin>>n;
        int a[n+1]={0};
        for(int i=1;i<=n;i++)
        {
            for(int j=i;j<=n;j+=i)
            {
                a[j]++;
            }
        }
        ll ans = 0;
        for(ll i=1;i<=n;i++)
        {
            ll t = i*a[i];
            ans += t;
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 42700
N, M = (int(i) for i in input().split(' '))
py=[]
p =[]

# 全都市を配列に代入
for i in range(M):
    p = [i]
    p.extend([int(j) for j in input().split(' ')])
    py.append(p)

# 設立年で一度ソートする
py.sort(key = lambda x: x[2])
pcid = [1] * N # 各県の都市ID

for i in range(M):
    p = py[i][1] # 県ID
    py[i][2] = pcid[p-1]
    pcid[p-1] += 1

py.sort(key=lambda x:x[0])
for t in py:
    print('{0:0>6}{1:0>6}'.format(t[1],t[2]))
    

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

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

using vi = vector<int>;

map<vi, int> mp; // mp[ある盤面]: その盤面に到るまでの手数

void bfs(vi origin) {
  // キューの初期化
  queue<vi> que;
  que.push(origin);
  // データの初期化
  mp[origin] = 0;

  while (que.size()) {
    // 軸を取り出す
    vi axis = que.front(); que.pop();

    // 0の場所を求める
    int zeroPos = 0;
    for (int i = 0; i< axis.size(); i++) {
      if (axis[i] == 0) zeroPos = i;
    }
    int y = zeroPos / 4, x = zeroPos % 4;
    int pos = y * 4 + x;

    // 軸から行ける場所を列挙
    for (int i = 0; i < 4; i++) {
      int ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= 2 || nx < 0 || nx >= 4) continue;
      int npos = ny * 4 + nx;
      vi next = axis;
      swap(next[npos], next[pos]);
      if (mp.count(next)) continue;
      // 行けるならキューとデータを更新する
      mp[next] = mp[axis] + 1;
      que.push(next);
    }
  }
}


signed main() {
  // 前処理
  vector<int> origin(8);
  iota(origin.begin(), origin.end(), 0);
  bfs(origin);

  string s;
  while (getline(cin, s)) {
    vi v;
    for (int i = 0; i < s.size(); i+=2) {
      v.push_back(s[i] - '0');
    }
    // 前処理の結果を出力するだけ
    cout << mp[v] << endl;
  }

  return 0;
}


Measured memory_bytes: 5704
<?php
// C
fscanf(STDIN, '%d', $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$ans = 0;
for ($i = 0; $i < $n; $i++) {
    while (!($a[$i] % 2)) {
        $ans++;
        $a[$i] /= 2;
    }
}
echo $ans;

Measured memory_bytes: 6648
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

var n int
var nums []string

func rec(s string) int {
	if len(s) > len(strconv.Itoa(n))+1 {
		return math.MaxInt64
	}
	sv, _ := strconv.Atoi(s)
	if sv >= n {
		return sv
	}

	ans := math.MaxInt64
	for _, v := range nums {
		ans = min(ans, rec(s+v))
	}
	return ans
}

func main() {
	n = scanInt()
	k := scanInt()
	d := make(map[int]bool)
	for i := 0; i < k; i++ {
		x := scanInt()
		d[x] = true
	}

	nums = make([]string, 0, 10)
	for i := 0; i <= 9; i++ {
		if !d[i] {
			nums = append(nums, strconv.Itoa(i))
		}
	}
	fmt.Println(rec(""))
}


Measured memory_bytes: 1536
package main

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

func paths(h, w int, grid [][]byte) int {
	dp := make([][]int, h)
	for i := 0; i < h; i++ {
		dp[i] = make([]int, w)
	}

	dp[0][0] = 1
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if grid[i][j] == '#' {
				continue
			}
			if i > 0 && grid[i-1][j] != '#' {
				dp[i][j] += dp[i-1][j]
			}
			if j > 0 && grid[i][j-1] != '#' {
				dp[i][j] += dp[i][j-1]
			}
			if dp[i][j] > int(math.Pow(10, 9)+7) {
				dp[i][j] = dp[i][j] % int(math.Pow(10, 9)+7)
			}
		}
	}

	return dp[h-1][w-1]
}

var inp *bufio.Scanner

func ScanInt() int {
	inp.Scan()
	res, _ := strconv.Atoi(inp.Text())
	return res
}

func ScanByteArray(size int) []byte {
	res := make([]byte, size)
	inp.Scan()
	copy(res, inp.Text())
	return res
}

func main() {
	inp = bufio.NewScanner(os.Stdin)
	inp.Split(bufio.ScanWords)
	h := ScanInt()
	w := ScanInt()
	grid := make([][]byte, h)
	for i := 0; i < h; i++ {
		grid[i] = ScanByteArray(w)
	}
	fmt.Println(paths(h, w, grid))
}


Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ


		Scanner scan = new Scanner(System.in);
		for(int c=1;;c++){
			int W = scan.nextInt();
			if(W==0)
				break;
			int N = scan.nextInt();
			int[] v = new int[N];
			int[] w = new int[N];
			for(int i=0;i<N;i++){
				String[] t = scan.next().split(",");
				v[i]=Integer.parseInt(t[0]);
				w[i]=Integer.parseInt(t[1]);
			}

			int[][] dp = new int[N+1][W+1];
			for(int j=0; j<=W;j++)
				dp[N][j]=0;

			for(int i=N-1;i>=0;i--){
				for(int j=0;j<=W;j++){
					if(w[i]>j){
						dp[i][j]=dp[i+1][j];
					}
					else{
						dp[i][j]=Math.max(dp[i+1][j],v[i]+dp[i+1][j-w[i]]);
					}
				}
			}

			int p=0;
			for(int j=0;j<=W;j++){
				if(dp[0][j]>dp[0][p])
					p=j;
			}

			System.out.println("Case "+c+":");
			System.out.println(dp[0][p]);
			System.out.println(p);
		}
	}

}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

int main() {
	int n, x;
	cin >> n >> x;
	VI a(n);
	rep(i, 0, n) scanf("%d", &a[i]);
	sort(ALL(a));

	rep(i, 0, n){
		if (x >= a[i]) {
			x -= a[i];
		} 
		else {
			cout << i << "\n";
			return 0;
		}
	}
	if (x != 0) cout << n -1 << "\n";
	else cout << n << "\n";
}


Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)

fun main(args: Array<String>) {
    val (a, b) = readListOfInt()

    println((a-1) * (b-1))
    pw.flush()
}

fun inputList() = 
    readLine()!!.split(" ").map(String::toInt)

fun sum_digits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

/****** Decrared Functions ******/

// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }


fun println(value : Any) {
    pw.println(value)
}

fun gcd(a: Long, b: Long): Long = 
    if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
    if(b==0L) a else gcd(b, a % b)


Measured memory_bytes: 36068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

int main(){
   ll a;
   cin >> a;
   cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;

#define mod             1000000007
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";
#define read(x)         freopen("in.txt","r",stdin);
#define write(x)        freopen("out.txt","w",stdout);
#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define sz              3000005
int arr[sz];
int main(){
    Fast;///using Fast I/O
    int a,b,c, i,j,k, t,n,m;
    cin>>n;
    for(i=1; i<=n; i++)cin>>arr[i];
    sort(arr+1,arr+n+1);
    reverse(arr+1,arr+n+1);

    ll sum=arr[1];
    for(i=2; i<=n/2; i++)sum+=(2*1LL*arr[i]);
    if(n%2){
        sum+=(arr[n/2+1]);
    }
    cout<<sum<<endl;


    return 0;
}


Measured memory_bytes: 4288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp90 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int N = st[0];
            int K = st[1];

            var x = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int ans = Math.Abs(x[0]) + x[K - 1] - x[0];

            int min_i = 0;

            //K本のろうそくの一番左端のろうそくについて、それぞれについて両側からスタートするパターンを検討しつつ、全部調べる
            for (int i = 0; i + K - 1 < N; i++) {
                min_i = x[i + K - 1] - x[i] + Math.Min(Math.Abs(x[i + K - 1]), Math.Abs(x[i]));
                ans = Math.Min(ans, min_i);
            }

            Console.WriteLine(ans);

        }

    }
}

Measured memory_bytes: 20960
#include<stdio.h>
#include<string.h>
int main(){
    char ch;
    do{
        scanf("%c",&ch);
        if(ch>='a'&&ch<='z'){
            ch=ch-32;
        }else if (ch>='A'&&ch<='Z'){
            ch=ch+32;
        }
        printf("%c",ch);
        }while(ch!='\n');
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>s;
	n = s.size();
	string r;
	int res = 0;
	char c;
	int ans = 1e9;
	for(int i = 0; i < n; ++i){
		if(i % 2 == 0)c = '0';
		else c = '1';
		if(s[i] != c)res++;
	}
	ans = min(ans, res);
	res = 0;
	for(int i = 0; i < n; ++i){
		if(i % 2 == 0)c = '1';
		else c = '0';
		if(s[i] != c)res++;
	}
	ans = min(ans, res);
	cout<<ans<<endl;
	return 0;
}

/*
0000000000
0011001100



 */


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
 
int main(){
    float f;
    while( std::cin>>f, f>=0){
        int i=f;
        f=f-i;
        if( i>255 ){std::cout<<"NA"<<std::endl;continue;}
        int Fnum=(1<<4)*f;
        if( Fnum != (1<<4)*f ){std::cout<<"NA"<<std::endl;continue;}
        int count=8;
        while( count-- )
            std::cout<<((i&(1<<count))==0?'0':'1');
        std::cout<<'.';
         
        count=4;
        while( count-- )
            std::cout<<((Fnum&(1<<count))==0?'0':'1');
         
        std::cout<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 1212
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	s = s[:len(s)-1]
	for {
		if len(s)%2 == 0 && s[:len(s)/2] == s[len(s)/2:] {
			fmt.Println(len(s))
			return
		}
		s = s[:len(s)-1]
	}
}


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

const int N = 540, N2 = 254000;

int n, n2;
int pos[N], a[N2];
int o[N], remain[N];

int main() {
	int i, j;
	scanf("%d", &n), n2 = n * n;
	for (i = 1; i <= n; ++i) scanf("%d", pos + i), a[pos[i]] = i, o[i - 1] = i;
	std::sort(o, o + n, [] (const int x, const int y) {return pos[x] < pos[y];});
	for (i = 1; i <= n; ++i) remain[i] = i - 1;
	j = !remain[*o];
	for (i = 1; i <= n2 && j < n; ++i)
		if (!a[i]) for (--remain[ a[i] = o[j] ]; j < n && !remain[o[j]]; ++j);
		else if (remain[a[i]]) break;
	if (j < n) return puts("No"), 0;
	for (i = 1; i <= n; ++i) remain[i] = n - i;
	j = (remain[o[n - 1]] ? n - 1 : n - 2);
	for (i = n2; i && j >= 0; --i)
		if (!a[i]) for (--remain[ a[i] = o[j] ]; j >= 0 && !remain[o[j]]; --j);
		else if (remain[a[i]]) break;
	if (j >= 0) return puts("No"), 0;
	puts("Yes");
	for (i = 1; i <= n2; ++i) printf("%d%c", a[i], i == n2 ? 10 : 32);
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n, k, ans = 0;
	int x[110];

	cin >> n >> k;

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

	for (int i = 0; i < n; i++) {
		ans += 2 * min(x[i], k - x[i]);
	}

	cout << ans << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
n=int(input())
A=list(map(int,input().split()))
q=int(input())

for i in range(q):
    query=list(map(int,input().split()))
    if query[0]==0:
        print(min(A[query[1]:query[2]]))
    else:
        print(max(A[query[1]:query[2]]))



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	ll a, b, c, d,tmp=0;
	cin >> a >> b >> c >> d;
	if (a < 0 && 0 <= b || c < 0 && 0 <= d)tmp = 0;
	else tmp = a * c;
	cout << max(max(max(max(a*c,a*d),b*c),b*d),tmp) << endl;


	return 0;
}



Measured memory_bytes: 3604
/**
 * @author      : cromarmot (yexiaorain@gmail.com)
 * @license     : GPL
 * @created     : 星期六 9月 28, 2019 20:11:11 CST
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define ten5 100000+10
#define MOD 1000000007
#define rep(i,a,n) for (int i=a;i<n;i++)
#define iif(c,t,f) ((c)?(t):(f))
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
const double pi = acos(-1.0);

ll x,y;

ll gcd(ll a,ll b){
  return b==0?a:gcd(b,a%b);
}

int main(){
  cin>>x>>y;
  ll g = gcd(x,y);
  int ans = 1;
  rep(i,2,1000001){
    if(g%i == 0){
      ans++;
      while(g % i == 0){
        g/=i;
      }
    }
    if(g == 1)break;
  }
  if(g != 1){
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

/*
 *
 * hash prime
 61,83,113,151,211,281,379,509683,911
 1217,1627,2179,2909,3881,6907,9209
 12281,16381,21841,29123,38833,51787,69061,92083
 122777,163729,218357,291143,388211,517619,690163,999983
 1226959,1635947,2181271,2908361,3877817,5170427,6893911,9191891
 12255871,16341163,21788233,29050993,38734667,51646229,68861641,91815541
 122420729,163227661,217636919,290182597,386910137,515880193,687840301,917120411
 1000000007,1000000009
 * */



Measured memory_bytes: 256