akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int solve(void);
void search(vector<vector<int>> &v, vector<int> &pos, vector<int> &count, vector<int> &numlist, map<int,int> inlist, int d);
void debug_output(vector<vector<int>> &v);

int main(void) {

	//FILE *fpin = freopen("data.txt", "r", stdin);
	while(solve()){}
	//while (1) {}
	return 0;

}

int solve(void) {

	int n, d;
	cin >> n >> d;
	if (!(n | d)) { return 0; }
	vector<vector<int>> v(n);
	vector<int> count(1000000+1,0);
	vector<int> numlist;
	map<int, int> invnumlist;
	vector<int> pos(n);

	for (int i = 0; i < n; i++) {
		int c;
		cin >> c;
		v[i].resize(c+1);
		v[i][0] = 0;
		pos[i] = c;
		for (int j = 1; j <= c; j++) {
			cin >> v[i][j];
			if (j > 0) v[i][j] += v[i][j - 1];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < v[i].size(); j++) {
			count[v[i][j]] ++;
		}
	}

	for (int i = 0; i < count.size(); i++) {
		if (count[i] > 0) {
			invnumlist[i] = numlist.size();
			numlist.push_back(i);
		}
	}
	
	search(v, pos, count, numlist, invnumlist, d);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += pos[i];
	}
	if (ans == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 1;

}

void search(vector<vector<int>>& v, vector<int>& pos, vector<int>& count, vector<int>& numlist, map<int, int> inlist, int d)
{
	bool b = true;
	int low = 10000000, high = numlist.size() - 1;

	for (int i = 0; i < v.size(); i++)
		low = min(v[i][pos[i]], low);

	low = inlist[low];

	while (b) {

		b = false;

		//??´??°??????
		/*
			i??????j?????????????????????????????????????????????
		*/
		for (int i = 0; i < v.size(); i++) {
			for (int j = pos[i]; j > 0; j--) {
				if (count[numlist[high]] == 1 && v[i][j] == numlist[high]) {
				
					/*
						??????????????¨high?????´??°???????????´???
					*/
					int next = v[i][j - 1];
					int k = high - 1;
					for (; k >= 0 && (count[numlist[k]] == 0); k--);
					if ( abs(numlist[k] - min(numlist[low], next)) <= d) {
						high = k;
						low = min(low, inlist[next]);
						count[v[i][j]]--;
						pos[i] = j - 1;
						b = true;
					}
					else {
						break;
					}
				}
				else {
					/*
						??????????????¨high?????´??°??????????????´???
					*/
					if ( abs(numlist[high] - min(numlist[low], v[i][j - 1])) <= d) {
						//???????????????
						low = min(low, inlist[v[i][j - 1]]);
						pos[i] = j - 1;
						count[v[i][j]] --;
						b = true;
					}
					else {
						//??????????????????
						break;
					}
				}
			}
		}
	}
}


void debug_output(vector<vector<int>>& v)
{
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 7832
n,t = gets.split.map(&:to_i)
data = []
n.times do
  tmp = gets.split
  data << [tmp[0],tmp[1].to_i]
end

result = []

now_t = 0
while !data.empty?
  if data[0][1] > t
    now_t += t
    data[0][1] -= t
    incomplete_elem = data.shift
    data << incomplete_elem 
  else
    now_t += data[0][1]
    complete_elem = data.shift
    result << complete_elem[0]+" "+now_t.to_s
  end
end
puts result.join("\n")

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

int days[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int from_1_1(int m, int d) 
{
    int day_from_1_1 = d;
    for (int i = 0; i < m; i++) {
        day_from_1_1 += days[i];
    }
    return day_from_1_1;
}

int main(void)
{
    int m, d;
    string day;
    while (cin >> m >> d) {
        if (m == 0 && d == 0) break;
        switch ( from_1_1(m, d) % 7 ) {
            case 1:
                day = "Thursday";
                break;
            case 2:
                day = "Friday";
                break;
            case 3:
                day = "Saturday";
                break;
            case 4:
                day = "Sunday";
                break;
            case 5:
                day = "Monday";
                break;
            case 6:
                day = "Tuesday";
                break;
            case 0:
                day = "Wednesday";
                break;
            default: // DO_NOTHING
                break;
        }
        cout << day << endl;
    }
    return 0;
}
    

Measured memory_bytes: 0
K, X = map(int, input().split())
if (X-K+1 > -1000000) and (X+K < 1000000):
  print(' '.join([str(i) for i in range(X-K+1, X+K)]))
elif (X-K+1 < -1000000) and (X+K < 1000000):
  print(' '.join([str(i) for i in range(-1000000, X+K)]))
elif (X-K+1 > -1000000) and (X+K > 1000000):
  print(' '.join([str(i) for i in range(X-K+1, 1000000)]))
elif (X-K+1 < -1000000) and (X+K > 1000000):
  print(' '.join([str(i) for i in range(1000000, 1000000)]))

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

int main(){
  int N;
  int64_t FBt=0;
  cin>>N;
  for(int i=1;i<=N;i++){
    if(i%3==0&&i%5==0){
      continue;
    }
    else if(i%3==0){
      continue;
    }
    else if(i%5==0){
      continue;
    }
    else{
      FBt+=i;
    }
  }
  cout<< FBt<<endl;

}


Measured memory_bytes: 3632
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >>  A>> B;
  vector<ll> x;
  if (A%2 == 0 || B%2 == 0) cout << "No"<<endl;
  else cout << "Yes" << endl;
  
  
 
}


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

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


Measured memory_bytes: 256
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int r, g;
  cin >> r >> g;
  int d = (g-r)*2;
  cout << r + d << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    vector<int> num(n);
    REP(i, n) num[i] = i + 1;
    vector<int> fst, sec;
    REP(i, n){
        int tmp; cin >> tmp;
        fst.push_back(tmp);
    }
    REP(i, n){
        int tmp; cin >> tmp;
        sec.push_back(tmp);
    }
    int a = 0, b = 0;
    int cnt = 1;
    while(whole(next_permutation, num)){
        if(num == fst) a = cnt;
        if(num == sec) b = cnt;
        cnt++;
    }
    cout << abs(a - b) << endl;
}

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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a,ll b){	if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;}	return ans;}


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	
	int a,b,c,d,k;
	cin>>a>>b>>c>>d>>k;
	db(((c*60+d-a*60-b-k)>0?(c*60+d-a*60-b-k):0));
	/*
	int test1;cin>>test1;while(test1--){ 
		
	 }
	 //*/
return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int H[N];
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    int ans=0;
    for(int i=0;i<N;i++){
        bool flg=true;
        for(int j=0;j<i;j++){
        if(H[j]>H[i]) flg=false;
        }
        if(flg) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;
    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int low = 0;
        int high = N;
        int lowpos = check(0);
        if (lowpos == 2) return;
        while (high - low > 1)
        {
            int mid = (high + low) / 2;
            int midpos = check(mid);
            if (midpos == 2) return;
            if(midpos == (lowpos + (mid - low) % 2) % 2)
            {
                low = mid;
                lowpos = midpos;
            }
            else
            {
                high = mid;
            }
        }
    }
    
    int check(int p)
    {
        Console.WriteLine(p);
        string ans = cin.next();
        if (ans == "Male") return 0;
        else if (ans == "Female") return 1;
        return 2;
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13640
#include <stdio.h>
int main(void)
{
	int a[10], c, d=10, e=0, i, j;
	
	for(i=0;i<5;i++) scanf("%d",&a[i]);
	
	for(i=0;i<5;i++){
	    c=a[i]%10;
	    if(c!=0){
	        if(c<d){
	            d=c;
	            j=i;
	        }
	    }
	}
	for(i=0;i<5;i++){
	    if(i!=j){
	        c=a[i]%10;
	        if(c!=0) a[i]=a[i]+10-c;
	        e+=a[i];
	    }
	}
	e=e+a[j];
	printf("%d\n",e);
	return 0;
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

const double EPS = 1e-10;

double add(double a, double b) {
	if(abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
	return a + b;
}

struct Point {
	double x, y;
	Point() {}
	Point(double x, double y) : x(x), y(y) {
	}
	Point operator + (Point p) {
		return Point(add(x, p.x), add(y, p.y));
	}
	Point operator - (Point p) {
		return Point(add(x, -p.x), add(y, -p.y));
	}
	Point operator * (double d) {
		return Point(x * d, y * d);
	}
	double dot(Point p) {
		return add(x * p.x, y * p.y);
	}
	double det(Point p) {
		return add(x * p.y, -y * p.x);
	}
};

bool cmp_x(const Point& p, const Point& q) {
	if(p.x != q.x) return p.x < q.x;
	return p.y < q.y;
}

vector<Point> convex_hull(Point *ps, int n) {
	sort(ps, ps + n, cmp_x);
	int k = 0;
	vector<Point> qs(2 * n);

	for(int i = 0; i < n; ++i) {
		while(k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) --k;
		qs[k++] = ps[i];
	}
	for(int i = n - 2, t = k; i >= 0; --i) {
		while(k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) --k;
		qs[k++] = ps[i];
	}
	qs.resize(k - 1);
	return qs;
}

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

    double x[4], y[4];
    while((scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])) != EOF) {
        Point p[4];
        for(int i = 0; i < 4; ++i) {
            p[i].x = x[i]; p[i].y = y[i];
        }
        vector<Point> ps = convex_hull(p, 4);
        printf("%s\n", (ps.size() == 4) ? "YES" : "NO");
    }
    return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ll tr = n / i;
        ans += (((tr) * (tr + 1)) / 2) * i;
    }
    cout << ans << '\n';
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 3624
import java.util.*;


public class Main {
	public static void main(String[] args) {	 
	        int number1;
	        int number2;
	        int answer;
	        Scanner in = new Scanner(System.in);
	        Stack<Integer> stack = new Stack<Integer>();
	        String operator = in.nextLine();
	        String[] arr = operator.split(" ");
	        
	        for(String t : arr){
	           
	                switch(t){
	                    case "+":
	                    	number1 = stack.pop();
	                    	number2 = stack.pop();
	                        stack.push(number2 + number1);
	                        break;
	                    case "-":
	                    	number1 = stack.pop();
	                    	number2 = stack.pop();
	                        stack.push(number2 - number1);
	                        break;
	                    case "*":
	                    	number1 = stack.pop();
	                    	number2 = stack.pop();
	                        stack.push(number2 * number1);
	                        break;
	                    case "/":
	                    	number1 = stack.pop();
	                    	number2 = stack.pop();
	                        stack.push(number2 / number1);
	                        break;
	                       
	                    default:
	                    	stack.push(Integer.parseInt(t));
	                    	break;
	                }
	            }
	        answer = stack.pop();
	        System.out.println(answer);
	    }
}



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

int main() {
    string s;
    cin >> s;
    if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

void solve() {
    int n, m; cin >> n >> m;
    if (n < m) swap(n, m);
    if (n - m > 1) {
        cout << 0 << "\n";
        return;
    }
    int ans = 1;
    FOR(i, 1, n + 1) ans = mult(ans, i);
    FOR(i, 1, m + 1) ans = mult(ans, i);
    if (n == m) ans = mult(ans, 2);
    cout << ans << "\n";
}

int main() {
    int JUDGE_ONLINE = 1;
    if (fopen("in.txt", "r")) {
        JUDGE_ONLINE = 0;
        assert(freopen("in.txt", "r", stdin));
        //assert(freopen("out.txt", "w", stdout));
    }
    else {
        ios_base::sync_with_stdio(0), cin.tie(0);
    }
    solve();
    if (!JUDGE_ONLINE) {
        //cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    }
    return 0;
}

Measured memory_bytes: 892
use proconio::*;

fn run() {
    input! {
        k: u32,
        a: u32,
        b: u32,
    }
    let x = (a + k - 1) / k * k;
    if x <= b {
        println!("OK");
    } else {
        println!("NG");
    }
}

fn main() {
    run();
}

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

int main(){
	int N;
	cin >> N;
	for(int i = 0; i <= N/7; i++){
		if((N - 7 * i) % 4 == 0){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
def dis(i,j,x,y):
    a = j-i
    b = abs(i-x)+abs(j-y)+1
    c = abs(i-y)+abs(j-x)+1
    return min(a,b,c)
n,x,y = map(int,input().split())
ans = [0 for i in range(n)]
for i in range(1,n):
    for j in range(i+1,n+1):
        ans[dis(i,j,x,y)-1]+= 1
for i in range(n-1):
    print(ans[i])


Measured memory_bytes: 50524
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Double l;
        cin >> l;
        Double ans = l * l * l / 27.;
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
int read(char *s){
    R int len=0;R char ch;while(((ch=getc())>'9'||ch<'0'));
    for(s[++len]=ch;(ch=getc())>='0'&&ch<='9';s[++len]=ch);
    return s[len+1]='\0',len;
}
double readdb()
{
    R double x=0,y=0.1,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(x=ch-'0';(ch=getc())>='0'&&ch<='9';x=x*10+ch-'0');
    for(ch=='.'&&(ch=getc());ch>='0'&&ch<='9';x+=(ch-'0')*y,y*=0.1,ch=getc());
    return x*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
    if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int P=998244353;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int inc(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
clock_t start=clock();
inline void ck(){
    if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0);
}
int main(){
	int r;cin>>r;
	cout<<r*r<<endl;
	return 0;
}

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

bool inV(vector<int> v,int x){
  for(auto i:v){
    if(x == i){
      return true;
    }
  }
  return false;
}

int main() {
  int X;
  int N;
  
  vector<int> p;
  
  cin >> X;
  cin >> N;
  
  int minD = -1;
  int minValue = -1;
  for(int i = 0;i < N;++i){
    int t;
    cin >> t;
    p.push_back(t);
  }
  
  for(int i = 0;;++i){
    if(inV(p,X + -1 * i) == false){
      cout << X + -1 * i << endl;
      return 0;
    }
    if(inV(p,X + 1 * i) == false){
      cout << X + 1 * i << endl;
      return 0;
    }
  }
  
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const ll INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int a,b,c; cin>>a>>b>>c;
  bool f=0;
  if(a==b&&a!=c)
  f=1;
  else if(b==c&&b!=a)
  f=1;
  else if(a==c&&a!=b)
  f=1;

  if(f)
  puts("Yes");
  else
  puts("No");
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,ans=0;
    cin>>n;
    map<int, int> p;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        p[a]++;
        p[a-1]++;
        p[a+1]++;
    }
    for(auto x:p){
        ans=max(ans,x.second);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
typedef pair<int, int> pii;
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int x, y, a, b, c; cin>>x>>y>>a>>b>>c;
	vector<int> r(a), g(b), n(c);
	for(auto &a: r) cin>>a;
	for(auto &a: g) cin>>a;
	for(auto &a: n) cin>>a;
	RSORT(r);
	RSORT(g);
	RSORT(n);
	int p1=x-1, p2=y-1, p3=0;
	while(p3 < c){
		if(p1 < 0 && p2 < 0) break;
		if(p1 < 0){
			int tmp = min(g[p2], n[p3]);
			if(tmp == n[p3]) break;
			else{
				g[p2] = n[p3];
				p2--;
				p3++;
			}
		}
		else if(p2 < 0){
			int tmp = min(r[p1], n[p3]);
			if(tmp == n[p3]) break;
			else{
				r[p1] = n[p3];
				p1--;
				p3++;
			}
		}else{
			int tmp = min({r[p1], g[p2], n[p3]});
			if(tmp == n[p3]) break;
			else{
				if(tmp == r[p1]){
					r[p1] = n[p3];
					p1--;
					p3++;
				}else{
					g[p2] = n[p3];
					p2--;
					p3++;
				}
			}
		}
	}
	ll sum = 0;
	for(int i = 0; i < x; i++) sum += r[i];
	for(int i = 0; i < y; i++) sum += g[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

ll nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}


int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    int A[220000];
    rep(i,n) {
        int s;
        cin >> s;
        A[i] = s;
        mp[s]++;
    }
    ll ans = 0;
    for (auto& p : mp) {
        int a = p.second;
        ans += (ll)nCr(a, 2);
    }

    rep(i, n) {
        int s = mp.at(A[i]);
        ll trueans = ans - (ll)nCr(s, 2) + (ll)nCr(s-1,2);
        cout << trueans << endl;
    }
    return 0;

}

Measured memory_bytes: 8320
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def div3(x): 
    div = defaultdict(int)
    check = 2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check == 0:
            div[check] += 1
            x /= check
        check += 1
    if x != 1:
      div[x] += 1
    return div

def main():
    n = inp()
    dp = [i for i in range(51)]
    for i in range(50):
        dp[i+1] += dp[i]
    div = div3(n)
    ans = 0
    for e in div:
        ans += bisect.bisect_right(dp,div[e]) - 1
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 11144
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define dump(x)      cerr << #x << " = " << (x) << endl;


int main() {
    LL N, K;
    cin >> N >> K;
    VI V(N);
    REP(i, N) {
        cin >> V[i];
    }
    LL ans = 0;
    REP(nl, min(N, K) + 1) {
        REP(nr, min(N, K) + 1 - nl) {
            VI tmp(nl + nr);
            REP(i, nl) {
                tmp[i] = V[i];
            }
            REP(i, nr) {
                tmp[SZ(tmp) - 1 - i] = V[SZ(V) - 1 - i];
            }
            SORT(tmp);
            LL ans_ = 0;
            for (LL i = 0; i < SZ(tmp); ++i) {
                if (i < K - SZ(tmp) && tmp[i] < 0) continue;
                ans_ += tmp[i];
            }
            if (ans_ > ans) ans = ans_;
        }
    }
    cout << ans << endl;
	
    return 0;
}


Measured memory_bytes: 256
S = input()
dp = [[0]*13 for _ in range(len(S))]
mod = 10**9+7
for i in range(13):
    if S[0] == "?":
        dp[0][i] = 1 if i <= 9 else 0
    else:
        dp[0][i] = 1 if int(S[0]) == i else 0
for i in range(1,len(S)):
    if S[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i][(k*10+j) % 13] = (dp[i][(k*10+j) % 13]+dp[i-1][k])%mod
    else:
        j = int(S[i])
        for k in range(13):
            dp[i][(k*10+j)%13] = (dp[i][(k*10+j)%13]+dp[i-1][k])%mod
print(dp[len(S)-1][5])

Measured memory_bytes: 61916
#include <stdio.h>
int main(void)
{
        int a[10000],m,n,i,j=0,k,l=0;

        scanf("%d%d",&n,&m);
        for(i=0; i<n; i++){
                scanf("%d",&a[i]);
                j=j+a[i];
        }
        for(i=0; i<n; i++)
              if(a[i]*4*m>=j) l++;
              //a[i]<j/4m
        
        if(l>=m) printf("Yes\n");
        else printf("No\n");
                return 0;
}

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

int main() {
string S;
  int n,k;
  cin >> n >> k;
  cin >> S;
  if(S[k-1]=='A'){
  S[k-1]='a';
  }
  if(S[k-1]=='B'){
  S[k-1]='b';
  }
  if(S[k-1]=='C'){
  S[k-1]='c';
  }
  cout << S << endl;
  
}

Measured memory_bytes: 256
import sys
n = int(input())
h = list(map(int,input().split()))

for i in range(1,n):
     if h[i] == h[i-1] - 1:
          h[i] += 1
     elif h[i] <= h[i-1] - 2:
          print('No')
          sys.exit()
print('Yes')



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

vector<ll> A, P;

ll f(int N, ll X){
	if(N == 0) return X<=0? 0:1;
	else if(X <= 1LL+A[N-1]) return f(N-1, X-1);
	else return P[N-1] + 1LL + f(N-1, X-2LL-A[N-1]);
}

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

	A.push_back(1);
	P.push_back(1);
	for(int i=0; i<N; ++i){
		A.push_back(A[i]*2LL + 3LL);
		P.push_back(P[i]*2LL + 1LL);
	}

	cout<< f(N, X) <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#define	MOD  1000000007;
#define PI = 3.14159265358979323846;
using namespace std;

long long lcd(long long a, long long b) {
	if (b == 0)
	{
		return a;
	}

	return lcd(b, a%b);
}

int main()
{
	int N;
	cin >> N;
	long long T[100];
	long long A = 1;
	for (int i = 0; i < N; i++)
	{
		cin >> T[i];
	}
	sort(T, T + N);

	for (int i = 0; i < N; i++)
	{
		A = A / lcd(A, T[i]) * T[i];
		//if (max(T[i], A) % min(T[i], A) == 0)
		//{
		//	A = max(T[i], A);
		//}
		//else {
		//	A = A*T[i] / lcd(A, T[i]);
		//}
	}

	cout << A << endl;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    private static long findCity(long K, int[] arr) {
        int city = 1, count = 1;
        Map<Integer, Integer> map = new HashMap<>();

        while (K > 0 && !map.containsKey(city)) {
            map.put(city, count);
            city = arr[city];
            count++;
            K--;
        }

        if (K == 0) {
            return city;
        }

        K = K % (count - map.get(city));
        if (K < 0) {
            K += (count - map.get(city));
        }

        while (K > 0) {
            city = arr[city];
            K--;
        }

        return city;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] arr = new int[N + 1];

        for (int i = 1; i <= N; i++) {
            arr[i] = sc.nextInt();
        }
        System.out.println(findCity(K, arr));
        sc.close();
    }
}


Measured memory_bytes: 58164
from collections import deque
char = deque(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'])

string = list(input())

for i in range(len(string)):
    if string[i] in char:
        char.remove(string[i])

output = char.popleft() if char else "None"
print(output)

Measured memory_bytes: 4340
n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|s| s.to_i}
alc,bob=0,0
e=0
a.sort.reverse.each{|i|
  if e%2==0
    alc+=i
  else
    bob+=i
  end
  e+=1
}
puts alc-bob

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for (int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef vector<vector<vector<ll>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
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;
}
// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// vector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
int gcd(int a, int b) {
    while (a != b) {
        if (a > b) {
            if (a % b == 0)
                return b;
            else
                a = a % b;
        }
        if (a < b) {
            if (b % a == 0)
                return a;
            else
                b = b % a;
        }
    }
    return a;
}

int main() {
    int n;
    cin >> n;
    vector<int> x(n),y(n);
    rep(i,0,n) cin >> x[i] >> y[i];

    double dist = 0.0;
    vector<int> ord(n);
    rep(i,0,n) ord[i] = i;
    do {
        double tmp = 0;
        rep(i,0,n-1) {
            double dx = abs(x[ord[i]]-x[ord[i+1]]);
            double dy = abs(y[ord[i]]-y[ord[i+1]]);
            tmp += sqrt(dx*dx+dy*dy);
        }
        dist += tmp;

    } while (next_permutation(ord.begin(), ord.end()));
    rep(i,1,n+1) dist /= i;
    cout << fixed << setprecision(10) << dist << endl;
    return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>

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 RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-9;

const int MAX = 100010;
int N;
int A[MAX];

bool check(int idx) {
    LL now = A[idx];
    for (int i = N - 1; i >= 0; --i) {
        if (idx != i) {
            if (now * 2 >= A[i]) {
                now += A[i];
            } else {
                return false;
            }
        }
    }
    return true;
}

int main() {
    scanf("%d", &N);
    REP(i, N) {
        scanf("%d", A + i);
    }
    sort(A, A + N);
    reverse(A, A + N);
    int high = N, low = 0;
    while (high - low > 1) {
        const int mid = (high + low) / 2;
        (check(mid) ? low : high) = mid;
    }
    //DEBUG(low)DEBUG(high)
    printf("%d\n", high);
}


Measured memory_bytes: 768
import sys


def ways(n: int, x: int) -> int:
    counter = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            for k in range(j + 1, n + 1):
                if i + j + k == x:
                    counter += 1
    return counter


def resolve():
    for line in sys.stdin:
        n, x = map(int, line.split())
        if n == x == 0:
            break

        print(ways(n, x))


resolve()


Measured memory_bytes: 5600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i, n) for(int i=0;i<n;i++)
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define szz(x) (int)(x).size()
#define Fi first
#define Se second
typedef long double ldouble;

const ll MOD = 1e9 + 7;

ll pw(ll x, ll y = MOD - 2) {
	ll res = 1;
	while(y) {
		if(y & 1) res = res * x % MOD;
		x = x * x % MOD;
		y >>= 1;
	}
	return res;
}

ll F[2000020];

ll nCr(int n, int r) { return F[n] * pw(F[r]) % MOD * pw(F[n-r]) % MOD; }

void solve(){
	F[0] = 1;
	for(int i=1;i<2000020;i++) F[i] = i * F[i-1] % MOD;
	int n; scanf("%d", &n);
	ll ans = F[n-1];
	for(int i=1;i<n-1;i++) {
		ll val = nCr(n-1, i);
		if(2*i-1 >= n-1) {
			val -= nCr(i-1, n-1-i);
			if(val < 0) val += MOD;
		}
		val = val * F[i] % MOD * F[n-1-i] % MOD;
		ans = (ans + val) % MOD;
	}
	printf("%lld\n", ans);
}

int main() {
	//DM(); return 0;
	int tc = 1; // scanf("%d", &tc);
	for(int t=1;t<=tc;t++) {
	//	printf("Case #%d: ", t);
		solve();
	}
	return 0;
}


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

int main(void) {
    int n, i, j, ans, num2[10][10] = {0};
    char str[7];

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        sprintf(str, "%d", i + 1);
        num2[str[0] - '0'][str[strlen(str) - 1] - '0']++;
    }

    for (i = 0; i < 10; i++) {
        for (j = 0; j < 10; j++) {
            ans += num2[i][j] * num2[j][i];
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int a[5];
	forn(i,5) cin>>a[i];
	forn(i,5) if(a[i]==0){ cout<<i+1; return 0; }
	
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>

using namespace std;


int main() {

  int n,k;


  cin >> n;
  
  cin >> k;

  for(int i=0;i<k;i++) {

    int a,b;

    cin >> a >> b;

    if(n%2==0) {

      if(a>n/2) a=n+1-a;

    }

    else {

      if(a>n/2+1) a=n+1-a;

    }

    if(n%2==0) {

      if(b>n/2) b=n+1-b;

    }

    else {

      if(b>n/2+1) b=n+1-b;

    }
    

    switch(a%3) {

      //©
    case 0:
      
      if(b<a) {

	if(b%3==0) cout << 3 << endl;

	else cout << b%3 << endl;

      }
    
      else  cout << 3 << endl;

      break;

      //Ô
    case 1:

      if(b<a) {

	if(b%3==0) cout << 3 << endl;

	else cout << b%3 << endl;

      }

      else cout << 1 << endl;

      break;

      //Â
    case 2:

      if(b<a) {

	if(b%3==0) cout << 3 << endl;

	else cout << b%3 << endl;

      }

      else cout << 2 << endl;

      break;

    }


  }

  return 0;

}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))

int mpow(int a, int b) {
	int res = 1;
	rep(i, b)res *= a;
	return res;
}

bool judge(priority_queue<int>& me, priority_queue<int>& opp) {
	priority_queue<int> me_clear, opp_leave;
	while (!me.empty()) {
		int now = me.top(); me.pop();
		while (!opp.empty() && opp.top() >= now) {
			opp_leave.push(opp.top());
			opp.pop();
		}
		if (opp.empty()) {
			return false;
		}
		me_clear.push(now);
		me_clear.push(opp.top()); opp.pop();
	}
	me = me_clear;
	while (!opp_leave.empty()) {
		opp.push(opp_leave.top());
		opp_leave.pop();
	}
	return true;
}

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

	int total = mpow(2, N);
	vector<int> S(total);
	rep(i, total)cin >> S[i];
	priority_queue<int> me, opp;
	for (int num : S)opp.push(num);
	me.push(opp.top()); opp.pop();

	bool res = true;
	rep(i, N)if (!judge(me, opp)) {
		res = false;
		break;
	}
	cout << (res ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 5644
// In the name of God

#include <bits/stdc++.h>

using namespace std;

vector< pair<int,int> > graph;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int mx = (n-1)*(n-2)/2;
	if(k>mx) {
		cout << -1;
		exit(0);
	}
	for(int i=2;i<=n;i++) {
		graph.push_back(make_pair(1, i));
	}
	int go = mx - k;
	for(int i=2;i<=n;i++) {
		if(!go) break;
		for(int j=i+1;j<=n;j++) {
			if(!go) break;
			go--;
			graph.push_back(make_pair(i, j));
		}
	}
	if(go) {
		cout << -1;
		exit(0);
	}
	cout << graph.size() << "\n";
	for(auto x : graph) {
		cout << x.first << " " << x.second << "\n";
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;

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

	sort(box, box + n);
	int64_t sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += box[i];
	}

	cout << box[0] << " " << box[n-1] << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3200