akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastReader in = new FastReader();
        test a=new test();
        a.solve(in,out);
        out.close();
    }
}

class test {
    public void solve(FastReader in, PrintWriter out) {
        int x =in.nextInt();
        int n=in.nextInt();
        ArrayList<Integer> my =new ArrayList<>();
        for(int i=0;i<n;i++){
            my.add(in.nextInt());
        }
        Collections.sort(my);
        if(n==0){
            out.println(x);
        }
        
        else if(!my.contains(x)){
            out.println(x);
        }
        else{
            int k=x;int i=1;
            while(true){
                if(!my.contains(k-i)){
                    k=k-i;
                    break;
                }
                else if(!my.contains(k+i)){
                    k=k+i;
                    break;
                }
                i++;
            }
            out.println(k);
        }
    }
}

class FastReader{
    BufferedReader br;
    StringTokenizer st;

    public FastReader(){
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next(){
        while(st==null || !st.hasMoreElements()){
            try{
                st=new StringTokenizer(br.readLine());
            }
            catch(IOException e){
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt(){
        return Integer.parseInt(next());
    }

    Long nextLong(){
        return Long.parseLong(next());
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }
    String nextLine(){
        String str="";
        try{
            str=br.readLine();
        }
        catch(IOException e){
            e.printStackTrace();
        }
        return str;
    }
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  string result = "No";
  if (s.size() % 2 == 0) {
    rep(i, s.size() / 2) {
      if (s.substr(i * 2, 2) == "hi") {
        result = "Yes";
      } else {
        result = "No";
        break;
      }
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int  N = 100;

int main(){
	int M[N][N]; // 0 0 起点的邻接矩阵 
	int n,u,k,v;
	cin >> n;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			M[i][j] = 0;
		}
	}
	for(int i = 0;i < n;i++){
		cin >> u >> k;
		u--;		//转换为0起点 
		for(int j = 0;j < k;j++){
			cin >> v;
			v--;
			M[u][v] = 1; //在u和v之间画出一条边 
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0 ;j < n;j++){
			if(j) cout << " ";
			cout << M[i][j]; 
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
#define P 1000000007
#define N_MAX 2000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
    return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}

void init(){
    fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
    for(int i = 2; i <= N_MAX; i++){
        fac[i] = (fac[i-1]*i)%P;
        inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
        finv[i] = (finv[i-1]*inv[i])%P;
    }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll c(n);re(i, n) std::cin >> c[i];
  sort(all(c));
  init();
  vll seq(1000000, 1);rep(i, 1, 1000000) seq[i] = (seq[i-1]*2)%P;
  ll ans = 0;
  for(int i=0;i<n;i++){
    ll tmp = pp(c[i], seq[i]);
    ll lef = n - 1 - i;
    ll p = pp(lef, (lef==0?0:seq[lef-1]));
    p = (p + seq[lef])%P;
    tmp = pp(tmp, p);
    ans = (ans + tmp)%P;
    //std::cout << p << '\n';
  }
  ans = pp(ans, seq[n]);
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 56448
// ConsoleApplication10.cpp : アプリケーションのエントリ ポイントを定義します。
//
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;


int main()
{
	int N, M, X, y, j, c,ans, i, k,l, m, sum;
	cin >> N;
	vector<int> A(N*3);
	int B[300000] = {};
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (i = N; i < 2 * N; i++) {
		A[i]=A[i-N]+1;
	}
	for (i = 2*N; i < 3 * N; i++) {
		A[i] = A[i - 2*N] - 1;
	}
	sort(A.begin(), A.end());
	int ptr;
	ptr = 0;
	m = 0;
	while (ptr < 3 * N) {
		int cc = A[ptr];
		while (ptr < 3 * N&&A[ptr] == cc) {
			ptr++;
			B[m]++;
		}
		m++;
	}
	
	sort(B, B + m, greater<int>());

	cout << B[0] << endl;







	return 0;
}





Measured memory_bytes: 2560
///----> bismillahir rahmanir rahim <---- -- { ^ _ ^ }
///     { ^_^ }   { ^ _ ^ }
#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;

//<--------------------------------------------typo section--------------------------------------------->
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;
typedef priority_queue<int>piwi;
typedef queue<int>kiwi;
typedef map<int,int>mi;
typedef map<string,int>mis;
typedef multimap<int,int>muli;
typedef multimap<string,int>muls;
typedef multiset<int>si;

//<----------------------------------------------------Narcos----------------------------------------------->
#define endl "\n"
#define Y cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define sp " "
#define PB push_back
#define F first
#define S second
#define as(a) (a).begin(),(a).end()
#define ras(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define ki 1LL
#define MOD 1000000007
#define over return 0;
#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define test int t;cin>>t;while(t--)


//<-----------------------------------------------------Const--------------------------------------------------->
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


//<--------------------------------------------------------------------------------------------------->
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

const long long MAX_SIZE = 1000001; vector<long long >isprime(MAX_SIZE , true); vector<long long >prime; vector<long long >SPF(MAX_SIZE); void manipulated_seive(int N) { isprime[0] = isprime[1] = false ; for (long long int i=2; i<N ; i++) { if (isprime[i]) { prime.push_back(i); SPF[i] = i; } for(int j=0;j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) { isprime[i*prime[j]]=false; SPF[i*prime[j]] = prime[j] ; } } }
int man_seive(int n){ manipulated_seive(n); for(int i=0;i<prime.size() && prime[i]<=n;i++)
cout<<prime[i]<<endl;
}
ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }

//continue;

//-----------------------------> YOUR JOURNEY STARTS HERE ------------------------------------>>

int main(){
    optimize();
    string h;
    cin>>h;
    if(h[h.length()-1]=='s'){
        cout<<h<<"es"<<endl;
    }
    else{
            cout<<h<<"s"<<endl;
    }
over
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    vector<int> v(3);
    for(int i = 0; i < 3; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    bool ok = true;
    if(v[0] != 5) ok = false;
    if(v[1] != 5) ok = false;
    if(v[2] != 7) ok = false;
    
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll MOD = 1e9+7;
const static ll INF = 1e14;


int main() {
    ll N; cin >> N;
    string S; cin >> S;
    vector<vector<ll>> DP(N+1, vector<ll>(N+1, 0));
    for(int i = 0; i < N; i++) DP[0][i] = 1;
    vector<ll> D = DP[0];
    if(S[0] == '<') for(int i = D.size()-2; i >= 0; i--) D[i] = D[i]+D[i+1];
    else for(int i = 1; i < N; i++) D[i] = D[i]+D[i-1];

    for(int i = 1; i < N; i++){
        if(S[i-1] == '<'){
            for(int j = 0; i+j < N; j++){
                DP[i][j] = D[j+1]%MOD;
            }
        }
        else {
            for(int j = 0; i+j < N; j++){
                DP[i][j] = D[j]%MOD;
            }
        }
        if(i == N-1) break;
        D = DP[i];
            if(S[i] == '<') for(int i = D.size()-2; i >= 0; i--) D[i] = (D[i]+D[i+1])%MOD;
            else for(int i = 1; i < N; i++) D[i] = (D[i]+D[i-1])%MOD;
    }
    cout << DP[N-1][0]%MOD << endl;


}


Measured memory_bytes: 70784
#include<stdio.h>

int main(void){  

int a, b, c;  

int count = 0;  

int i;  

scanf("%d %d %d" ,&a ,&b ,&c);  

for(i=a; i<=b; i++){   

if(c%i==0)count++;  

}  

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

return 0;

}

Measured memory_bytes: 596
import java.io.*;

public class Main{
    public static void main(String[]args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        while((str = br.readLine()) != null){
            String[] str2 = str.split(" ");
            int a = Integer.parseInt(str2[0]);
            int b = Integer.parseInt(str2[1]);

            int digits = Integer.toString(a + b).length();
            System.out.println(digits);
        }
    }
}

Measured memory_bytes: 24292
#include <iostream>
#include <vector>
#include <cstring>
#include <cmath>

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,n) for(int i=(a);i<(n);i++)
using namespace std;

int main(){
  int n;
	bool dp[303][303];
	int ans[303];
  while(cin>>n,n){
    vector<int> w(n);
    REP(i,n)cin>>w[i];
    fill(dp[0],dp[n],false);
    fill(ans,ans+n,0);
    for(int i = 0;i <n;i++)dp[i][i+1] |= abs(w[i+1]-w[i])<=1;
    for(int width = 2;width <= n;width++){
      for(int l = 0;l + width <= n;l++){
				int r = l + width-1;
				for(int d = l;d < r;d++){//-1??¨???
					dp[l][r] |= dp[l][d]&&dp[d+1][r];
					dp[l][r] |= !(width&1) && dp[l+1][r-1] && abs(w[l]-w[r]) <=1;
				}
      }
    }
		/*		FOR(width,1,n+1){
			REP(l,n-width){
				cout << dp[l][l+width] << ' ';
				}
			cout << endl;
			}*/
    for(int i = 0;i<n;i++){
			//i-1?????§????????£????????????
			//i??\????????´??°??§??????????????????i???????????¶??§i-1??????????????????
			//ans[i]???????????´??°???????????§????????????divide??°??????????????????????????¢?????´??°???????????????
			if(i > 0)ans[i] = max(ans[i],ans[i-1]);
      for(int r = i+1;r<n;r++){
				//i-1?????§????????£??????????????????i???????§???????????¶????????????????????????¨?????´??°????????????
				if(dp[i][r]) ans[r] = max(ans[r],(i>0?ans[i-1]:0) + (r-i+1));
      }
    }
    cout << ans[n-1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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; }

#define mod 1000000007LL
#define eps 0.0001
#define pi acos(-1)
#define INF 10000000000000000

#define rep(i, n) for(int i = 0;i < n;++i)
#define rep1(i, n) for(int i = 1;i < n;++i)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define chmin

#define lset(h, n) memset(h, n, sizeof(h));
    

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // ---------------------
    // コーディング開始
    // ---------------------
    ll n;
    cin >> n;

    ll i = 0;
    ll k = 0;
    ll ans=0;

    while(k<n){
        k+=i;
        ans++;
        i++;
    }

    pri(ans-1);




    return 0;
}



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

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

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

    map<char, long long> mp;
    for(long long i = 0; i < s.size(); i++){
        mp[s[i]]++;
    }

    for(long long i = 0; i < t.size(); i++){
        if(mp.count(t[i]) == 0){
            cout << -1 << endl;
            return 0;
        }
    }

    s += s;
    map<char, vector<long long>> mp2;
    for(long long i = 0; i < s.size(); i++){
        mp2[s[i]].push_back(i);
    }

    for(auto &x: mp2){
        sort(x.second.begin(), x.second.end());
    }

    long long ans = mp2[t[0]][0], now = mp2[t[0]][0], ss = s.size();
    bool f = false;
    for(long long i = 1; i < t.size(); i++){
        if(now == ss - 1){
            ans += 1;
            now = 0;
            f = true;
        }
        long long idx = lower_bound(mp2[t[i]].begin(), mp2[t[i]].end(), now + (f ? 0 : 1)) - mp2[t[i]].begin();
        f = false;
        if(idx == mp2[t[i]].size()){
            ans += ss - now + mp2[t[i]][0];
            now = mp2[t[i]][0];
        }else{
            ans += mp2[t[i]][idx] - now;
            now = mp2[t[i]][idx];
        }
    }

    cout << ans + 1 << endl;

    return 0;
}

Measured memory_bytes: 2916
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, K, Q;
	cin >> N >> K >> Q;
	VI P(N);
	REP(i, N)P[i] = K - Q;
	REP(i, Q) {
		int a;
		cin >> a;
		a--;
		P[a]++;
	}
	REP(i, N) {
		if (P[i] <= 0) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


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

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    vector<ll> f(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> f[i];
    }
    sort(h.begin(), h.end());
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    ll ok = 1000000000011;
    ll ng = -1;
    while (ok-ng>1) {
        ll mid = (ok + ng) / 2;
        ll sho = 0;
        ll zer = 0;
        for (int i = 0; i < n; i++) {
            sho += max(h[i]-(mid / f[i]), zer);
        }
        if (sho > k)ng = mid;
        else ok = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 6420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{

    public static final int FIRST_NUMBER = 0;
    public static final int SECOND_NUMBER = 1;

    public static void main(String[] args) throws NumberFormatException, IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	// ?¨?????????°
	int vertical = Integer.parseInt(br.readLine());
    // ???????????°
	int horizontal = Integer.parseInt(br.readLine());

	List<int[]> changeRequests = new ArrayList<>();
	for (int i = 0; i < horizontal; i++) {
	    String[] changeRequestStr = br.readLine().split(",");
	    int[] changeRequest = new int[2];
	    changeRequest[FIRST_NUMBER] = Integer.parseInt(changeRequestStr[FIRST_NUMBER]);
	    changeRequest[SECOND_NUMBER] = Integer.parseInt(changeRequestStr[SECOND_NUMBER]);
	    changeRequests.add(changeRequest);
	}

	int[] outputArray = getDrawedArray(changeRequests, vertical, horizontal);

	for (int i = 1; i < outputArray.length; i++) {
	    System.out.println(outputArray[i]);
	}

    }

    /**
     *
     * @param changeRequests
     * @param vertical
     * @param horizontal
     */
    private static int[] getDrawedArray(List<int[]> changeRequests, int vertical, int horizontal) {
	int[] outputArray = new int[vertical + 1];
	for (int i = 1; i < outputArray.length; i++) {
	    outputArray[i] = i;
	}

	for (int[] changeRequest : changeRequests) {
	    int mediator = 0;
	    mediator = outputArray[changeRequest[FIRST_NUMBER]];
	    outputArray[changeRequest[FIRST_NUMBER]] = outputArray[changeRequest[SECOND_NUMBER]];
	    outputArray[changeRequest[SECOND_NUMBER]] = mediator;

	}

	return outputArray;

    }

}

Measured memory_bytes: 24196
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            long lar = sc.nextInt();
            long sma = sc.nextInt();
            long max = lar, min = sma;
            while (sma != 0) {
                lar = lar % sma;
                long freespace = lar;
                lar = sma;
                sma = freespace;
            }
            System.out.println(lar + " " + (max / lar * min));
        }
    }
}

Measured memory_bytes: 17216
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define int long long
#ifdef ONLINE_JUDGE
const int maxn = 3e5 + 10;
#else
const int maxn = 3e5 + 10;
#endif
using namespace std;
int fac[maxn], inv[maxn], N, M;
inline int exgcd(int a, int b, int& x, int& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    int d = exgcd(b, a % b, x, y), tmp = x;
    x = y;
    y = tmp - a / b * y;
    return d;
}
inline int Inv(int a, int b)
{
    int d, x, y;
    d = exgcd(a, b, x, y);
    return (x + b) % b;
}
void init()
{
    fac[0] = 1;
    for (ri i = 1; i < maxn; ++i) {
        fac[i] = fac[i - 1] * i % MOD;
    }
    for (ri i = 0; i < maxn; ++i) {
        inv[i] = Inv(fac[i], MOD);
    }
}
inline int cnm(int n, int m)
{
    if (n < m)
        return 0;
    return fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin >> N >> M;
    init();
    vector<int> p;
    for (ri i = 2; i * i <= M; ++i) {
        if (M % i == 0) {
            int cnt = 0;
            while (M % i == 0) {
                ++cnt;
                M /= i;
            }
            p.push_back(cnt);
        }
    }
    if (M != 1)
        p.push_back(1);
    int ans = 1;
    for (auto e : p) {
        ans *= cnm(N + e - 1, N - 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  if(M1!=M2){
    cout << "1" << endl;
    return 0;
  }
  cout << "0" << endl;
  return 0;
}

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

ans = [0] * (10**4 + 1)

for x in range(1, 101):
  for y in range(1, 101):
    for z in range(1, 101):
      v = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if v <= 10**4:
        ans[v] += 1

for i in range(1, N+1):
  print(ans[i])

Measured memory_bytes: 69304
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = []
for b in range(Q):
  BC.append(list(map(int, input().split())))

T = [0]*200000
#T[i] = A中の数値iの数

for i in A:
  T[i]+=1
S = sum(A)
for i in BC:
  b,c = i
  n = int(T[b])
  sa = c*n - b*n
  S = S + c*n - b*n
  print(S)
  T[b]=0
  T[c]+=n
  #print(S, [b,T[b], 0],[c,T[c],T[c]+T[b]], sa, S+sa)

Measured memory_bytes: 33176
k,n = map(int,input().split())
li = list(map(int,input().split()))
li.append(li[0]+k)
d_li = [0] * n
for i in range(len(li)-1):
    d_li[i] = li[i+1] - li[i]
d_li.sort()
print(sum(d_li[:n-1]))

Measured memory_bytes: 26420
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


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

	string a = "dream", b = "dreamer", c = "erase", d = "eraser";
	reverse(s.begin(), s.end());
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	reverse(c.begin(), c.end());
	reverse(d.begin(), d.end());
	string ans = "";
	for (int i = 0; i < s.size(); i++) {
		ans += s[i];
		if (ans == a) {
			s.erase(0, a.size());
			i -= a.size();
			ans = "";
		}
		if (ans == b) {
			s.erase(0, b.size());
			i -= b.size();
			ans = "";
		}
		if (ans == c) {
			s.erase(0, c.size());
			i -= c.size();
			ans = "";
		}
		if (ans == d) {
			s.erase(0, d.size());
			i -= d.size();
			ans = "";
		}
	}
	if (s.size() == 0) cout << "YES" << endl;
	else cout << "NO"<< endl;	
	return 0;
}


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

int main()
{
    char c1[4], c2[4];
    
    cin >> c1 >> c2;
    
    if((c1[0] == c2[2]) && (c1[1] == c2[1]) && (c1[2] == c2[0])) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int data[100005];

int ngcd(int *a, int n)
{
    if (n == 1)
        return *a;
    return __gcd(a[n - 1], ngcd(a, n - 1));
}

int main()
{
    int n, k, allGcd;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%d", &data[i]);
    sort(data, data + n);
    if (data[n - 1] < k)
    {
        puts("IMPOSSIBLE");
        return 0;
    }
    allGcd = ngcd(data, n);
    for (int i = n - 1; i >= 0; --i)
    {
        if ((data[i] - k) % allGcd == 0)
        {
            puts("POSSIBLE");
            return 0;
        }
    }
    puts("IMPOSSIBLE");

    return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
#include<string.h>
int main()
{
    char w[100], main[200], cpy[100];
    int wl,mainlen,i,j,c=0,y = 0;

    scanf("%s",&main)   ; mainlen=strlen(main) *2;
    scanf("%s",&w)    ; wl=strlen(w);

    strcpy(cpy,main);
    strcat(main,cpy);

    for(i=0;  i< mainlen-wl ; i++)
    {
        for(j=0; j<wl;j++)
        {
            if(main[i+j] == w[j]) c++;
        }
        if(c==wl) y=1;
        else c=0;
    }

    if(y==1) printf("Yes\n");
    else printf("No\n");

    return 0;


}




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

using namespace std;

#define ll unsigned long long
#define endl "\n"
#define MOD 1000000007

vector <ll> ad[200006];
vector <ll> vis(200006,0);

ll ans=0, n, m;

void addedge(ll x, ll y){
  ad[x].push_back(y);
  ad[y].push_back(x);
}

ll dfs(ll node){
  vis[node]=1;
  ++ans;
  for(ll x:ad[node]){
    if(!vis[x]){
      dfs(x);
    }
  }
  return ans;
}

void solve(){
  ll ans=0, n;
  cin >> n;
  ll a[n];
  for(ll i=0; i<n; i++){
  	cin >> a[i];
  }
 // sort(a,a+n);
  for(ll i=0;i<n;i++){
  	for(ll j=i+1;j<n;j++){
  		for(ll k=j+1; k<n;k++){
  			if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[k]+a[j]>a[i] && a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i]	)
  				++ans;
  		}
  	}
  }
  	cout << ans << endl;
}  

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 9444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

int main(){
  int W,H,X,Y; cin>>W>>H>>X>>Y;
  cout<<double(W)*double(H)/2<<" "<<(X*2==W&&Y*2==H)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;
int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<int> esum(n+1,0);
    vector<int> wsum(n+1,0);
    for(int i=0;i<n;i++){
        if('E'==s[i]){
            esum[i+1]=esum[i]+1;
            wsum[i+1]=wsum[i];
        }else{
            esum[i+1]=esum[i];
            wsum[i+1]=wsum[i]+1;
        }
    }
    int min=1000000;
    for(int i=0;i<n;i++){
        int sum=wsum[i]+(esum.back()-esum[i+1]);
        if(min>sum){
            min=sum;
        }
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pairs;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}


int main(){
    ll n; cin>>n;
    ll h = n/3600, m = (n%3600)/60, s = n-h*3600-m*60;
    cout<<h<<":"<<m<<":"<<s<<endl;
    
    return 0;
}
 
    
    



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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
A = sorted(LIST(), reverse=1)

if K >= N:
    print(0)
    exit()

A = A[K:]
print(sum(A))


Measured memory_bytes: 26020
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索
不変なもの・偶奇に注目

*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
#include<set>
using namespace std;
#define INF 1LL<<60
#define MAX 10000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,bool> P;
//typedef pair< pair<int,int>,pair<int,int> > p;
//#define int ll int main->signed main
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

//http://drken1215.hatenablog.com/entry/2019/09/29/012000

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> V[1100];
    for(int i=0;i<M;i++){
      int a,b;
      cin>>a>>b;
      a--; b--;
      V[a].push_back(b);
    }
    int shortest=N+1;
    vector<int> res;
    for(int s=0;s<N;s++){
      vector<int> dist(N,-1);
      vector<int> prev(N,-1);
      queue<int> que;
      que.push(s); dist[s]=0;
      while(!que.empty()){
        auto v=que.front(); que.pop();
        for(auto nv : V[v]){
          if(dist[nv]==-1){
            dist[nv]=dist[v]+1;
            prev[nv]=v;
            que.push(nv);
          }
        }
      }
      for(int t=0;t<N;t++){
        if(t==s || dist[t]==-1) continue;
        for(auto nt: V[t]){
          if(nt==s){
            vector<int> temp({s});
            int cur=t;
            while(cur!=s) temp.push_back(cur),cur=prev[cur];
            if(shortest>temp.size()){
              shortest=temp.size();
              res=temp;
            }
          }
        }
      }
    }
    if(shortest==N+1) cout<<-1<<endl;
    else{
      cout<<res.size()<<endl;
      for(auto v:res) cout<<v+1<<endl;
    }
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 0;
        while(i++ < 1000) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H < 3 || W < 3) break;
            for(int j=0; j<H; j++) {
                for(int k=0; k<W; k++) {
                    if(j == 0 || j == H-1) System.out.printf("#");
                    else if(k == 0 || k == W-1) System.out.printf("#");
                    else System.out.printf(".");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 56096
import sys
from bisect import bisect_left, bisect_right, insort

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
S = list('-' + sr())
d = [[] for _ in range(26)]
for i in range(1, N+1):
    s = S[i]
    o = ord(s) - ord('a')
    insort(d[o], i)

Q = ir()
for _ in range(Q):
    q, a, b = sr().split()
    if q == '1':
        a = int(a)
        if S[a] == b:
            continue
        prev = ord(S[a]) - ord('a')
        d[prev].pop(bisect_left(d[prev], a))
        next = ord(b) - ord('a')
        insort(d[next], a)
        S[a] = b
    else:
        a = int(a); b = int(b)
        ans = 0
        for alpha in range(26):
            if bisect_right(d[alpha], b) - bisect_left(d[alpha], a) >= 1:
                ans += 1
        print(ans)

# 17


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

using namespace std;

const int MAXN = 2e5 + 20, MAXM = 124, SZ = 26, L = 32;
const long long inf = 1e18 + 100, mod = 1e9 + 7;
mt19937 rnd;

long long fact[MAXN];

long long power(long long x, long long n) {
    if (!n)
        return 1LL;

    if (n & 1LL)
        return power(x, n - 1) * x % mod;

    long long y = power(x, n >> 1LL);
    return y * y % mod;
}

long long div(long long a) {
    return power(a, mod - 2);
}

long long C(long long n, long long k) {
    long long p = 1;
    for (long long j = 1; j <= k; ++j) {
        p *= (n - k + j);
        p %= mod;
    }
    p *= div(fact[k]);
    return p % mod;
}

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    fact[0] = 1;
    for (long long j = 1; j < min(n + 1, MAXN); ++j) {
        fact[j] = fact[j - 1] * j % mod;
    }

    long long sum = power(2, n) + mod - 1;
    sum %= mod;
    sum += mod - C(n, a);
    sum %= mod;
    sum += mod - C(n, b);
    sum %= mod;
    cout << sum << '\n';
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}

Measured memory_bytes: 1792
def main():
    from fractions import gcd

    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    a = A[0]
    n = 1
    while a & 1 == 0:
        n <<= 1
        a >>= 1

    lcm = 1
    for a in A:
        if a % n != 0 or a % (2 * n) == 0:
            print(0)
            return
        lcm = lcm * a // gcd(lcm, a)
        if lcm > M * 2:
            print(0)
            return

    print((M - lcm // 2) // lcm + 1)


main()


Measured memory_bytes: 16284
#include <cstdio>
#include <vector>
using namespace std;
const double BMI_FAT = 25.0;

int main(int argc, char *argv[]) {
	vector<int> fat_list;
	
	int id;
	float mass, height;
	while (EOF != fscanf(stdin, "%d,%f,%f", &id, &mass, &height)) {
		float bmi = mass / (height * height);
		if (BMI_FAT <= bmi) {
			fat_list.push_back(id);
		}
	}
	// print
	const int list_size = static_cast<int>(fat_list.size());
	if (list_size > 0) {
		for (int i = 0; i < list_size; i++) {
			printf("%d\n", fat_list[i]);
		}
	}
	else {
		puts("ツ該ツ督鳴づ按つオ");
	}
	return 0;
}

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

int main() {
	int N;
	long long A[110];
	long long answer = 0;

	std::cin >> N;

	for (int i = 0; i < N; i++)
		std::cin >> A[i];

	for (int i = 0; i < N - 1; i++)
		for (int j = i + 1; j < N; j++)
			answer = std::max(answer, std::abs(A[j] - A[i]));

	std::cout << answer << std::endl;

	return 0;
}

Measured memory_bytes: 256
//外灯をつける→次の外灯まで移動する→外灯が消える、N * (W + H)頂点の拡張ダイクストラ。スタートとゴールは大きさ-1の外灯。
//O(N^2 * (W + H) * logほげ)くらい。
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <tuple>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int INF = 1e+9;
int w, h, n;
int x[102], y[102];
int minCost[102][1100];	//minCost[場所][外灯の大きさ + 1]

signed main() {
	int i, j;
	
	cin >> w >> h >> n;
	rep(i, n) { cin >> x[i] >> y[i]; }
	x[n] = 1;
	y[n] = 1;
	x[n + 1] = w;
	y[n + 1] = h;
	n += 2;
	
	rep(i, n) rep(j, 1100) minCost[i][j] = INF;
	
	typedef tuple<int, int, int> T;
	priority_queue<T, vector<T>, greater<T> > que;
	
	minCost[n - 2][0] = 0;
	que.push(T(0, n - 2, 0));
	while (!que.empty()) {
		T now = que.top(); que.pop();
		int cst = get<0>(now);
		int pos = get<1>(now);
		int sz = get<2>(now) - 1;
		
		rep(j, n) {
			if (pos == j) continue;
			int lowSz = abs(x[j] - x[pos]) + abs(y[j] - y[pos]) - sz - 1;
			if (j == n - 2 && lowSz >= 0) { continue; }
			if (j == n - 1 && lowSz >= 0) { lowSz++; }
			if (lowSz < 0) lowSz = 0;
			if (minCost[j][lowSz + 1] > cst + lowSz) {
				minCost[j][lowSz + 1] = cst + lowSz;
				que.push(T(cst + lowSz, j, lowSz + 1));
			}
		}
	}
	
	int ans = INF;
	rep(i, 1100) ans = min(ans, minCost[n - 1][i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5380
/*
 * Author : Sadi
 * Wed 08/07/2020
 * 23:27:06.51
 */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

	int a;
	string s;
	cin >> a;
	cin >> s;
	if(a < 3200) {
		cout << "red" << endl;
	}    
	else {
		cout << s << endl;
	}
    return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	ll n, a;
	cin >> n;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		while (a % 2 == 0) {
			ans++;
			a /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}


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

bool contains(string s, string t) {
  return s.find(t) != string::npos;
}

int main() {
  string s;
  while (getline(cin, s)) {
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < s.length(); j++) {
        if (s[j] >= 'a' && s[j] <= 'z') {
          if (s[j] == 'z') s[j] = 'a';
          else s[j]++;
        }
      }
      if (contains(s, "the") || contains(s, "this") || contains(s, "that"))
        break;
    }
    cout << s << endl;
  }  
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  //int a, b, c, d;
  string a, b;
  cin >> a >> b;
  
  //int ans = 0;
  string ans = "No";
  int num = stoi(a + b);
  rep(i, 400){
    if (i * i == num) ans = "Yes";
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    m1, d1 = map(int, args[0].split())
    m2, d2 = map(int, args[1].split())
    return '1' if m1+1 == m2 else '0'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159265358979323

//int calc1(float a,float b,float c,float d,float e,float f,float *x,float *y);
//void quick(int *,long long,long long);
//int comp(char *a,char *b);
int make(int *a,int n,int b,char *c[4],char *buf);

int main(){
	
	char buf[100];
	int   a[4];
	char  *b[4];

	b[0]=(char *)malloc(sizeof(char)*20);
	b[1]=(char *)malloc(sizeof(char)*20);
	b[2]=(char *)malloc(sizeof(char)*20);
	b[3]=(char *)malloc(sizeof(char)*20);

	while(1){
		scanf("%d %d %d %d",a,a+1,a+2,a+3);
		if(a[0]==0&&a[1]==0&&a[2]==0&&a[3]==0)
			break;
		sprintf(b[0],"%d",a[0]);
		sprintf(b[1],"%d",a[1]);
		sprintf(b[2],"%d",a[2]);
		sprintf(b[3],"%d",a[3]);
		if(make(a,4,10,b,buf)==0)
			printf("0\n");
		else
			printf("%s\n",buf);
	}
	return 0;
}

int make(int *a,int n,int b,char *c[4],char *buf){

	int i,j,k,d[4];
	char *e[4];
	e[0]=(char *)malloc(sizeof(char)*20);
	e[1]=(char *)malloc(sizeof(char)*20);
	e[2]=(char *)malloc(sizeof(char)*20);
	e[3]=(char *)malloc(sizeof(char)*20);

	
	if(n==1){
		if(a[0]==b){
			sprintf(buf,"%s",c[0]);
			return 1;
		}else
			return 0;
	}
	for(i=0;i<=n-2;i++)
		for(j=i+1;j<=n-1;j++){
			k=0;
			while(k<i){
				d[k]=a[k];
				e[k]=c[k];
				k++;
			}
			while(k+1<j){
				d[k]=a[k+1];
				e[k]=c[k+1];
				k++;
			}
			while(k+2<n){
				d[k]=a[k+2];
				e[k]=c[k+2];
				k++;
			}
			d[k]=a[i]+a[j];
			sprintf(e[k],"(%s+%s)",c[i],c[j]);
			if(make(d,n-1,b,e,buf)==1)
				return 1;
			d[k]=a[i]-a[j];
			sprintf(e[k],"(%s-%s)",c[i],c[j]);
			if(make(d,n-1,b,e,buf)==1)
				return 1;
			d[k]=a[j]-a[i];
			sprintf(e[k],"(%s-%s)",c[j],c[i]);
			if(make(d,n-1,b,e,buf)==1)
				return 1;
			d[k]=a[i]*a[j];
			sprintf(e[k],"(%s*%s)",c[i],c[j]);
			if(make(d,n-1,b,e,buf)==1)
				return 1;
		}
	return 0;
}

Measured memory_bytes: 2456
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    (*A,) = map(int, read().split())
    k = A[-1]

    for i in range(5):
        for j in range(i + 1, 5):
            if A[j] - A[i] > k:
                print(':(')
                return

    print('Yay!')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
int main(){
  int n;
  long long int ans=0,s1=0;
  cin>>n;
  const int N=n;
  long long int a[N];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=n-1;i>0;i--){
    s1=(s1+a[i])%MOD;
    ans=(ans+s1*a[i-1])%MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5164
#include<stdio.h>

int main()
{
  int arr[3];
  for(int i = 0; i<3; i++)
    {
      scanf("%d", &arr[i]);
    }
  for(int i = 0; i<2; i++)
    {
      if(arr[i]>=arr[i+1])
	{
	  printf("No\n");
	  return 0;
	}
    }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 2068
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

int N;
vector<pair<int, int>> v;
int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		int a, b;
		cin >> a >> b;
		v.PB(MP(b, a));
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	int l = INT_MAX;
	for(int i=0; i<N; i++){
		if(l > v[i].first) l = v[i].first;
		l -= v[i].second;
	}
	if(l >= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 2420
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;

int main()
{
    fast();
    ll a,b;
    cin>>a>>b;

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

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int mod=1e4+7;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main(){
    int w,h,n,x,y,a;
    cin>>w>>h>>n;
    int l=0,r=w,u=h,d=0;
    for(int i=0;i<n;i++){
        cin>>x>>y>>a;
        if(a==1) l=max(l,x);
        else if(a==2) r=min(r,x);
        else if(a==3) d=max(d,y);
        else u=min(u,y);
    }
    cout<<max(0,r-l)*max(0,u-d)<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


class MODCombination:
    def __init__(self, n, p):
        self.n = n
        self.p = p  # MOD
        self.fac, self.ifac = self.make_fac_tables_mod_p(n, p)

    @staticmethod
    def make_fac_tables_mod_p(n, p):
        assert n >= 1
        fac = [0] * (n + 1)   # _______ factorial: n!
        ifac = [0] * (n + 1)  # inverse factorial: n!^{-1}
        inv = [0] * (n + 1)   # inverse element  : n ^{-1}
        fac[0] = fac[1] = 1
        ifac[0] = ifac[1] = 1
        inv[1] = 1
        for i in range(2, n + 1):
            fac[i] = fac[i - 1] * i % p
            inv[i] = p - inv[p % i] * (p // i) % p
            ifac[i] = ifac[i - 1] * inv[i] % p
        return fac, ifac

    def nCk(self, n, k):
        # nCk = n! * k!^{-1} * (n-k)!^{-1}
        return ((self.fac[n] * self.ifac[n - k]) % self.p) * self.ifac[k] % self.p


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()
    mod_comb = MODCombination(N - 1, P)

    ans = 0
    for n in range(K - 1, N):
        max_A = A[n]
        min_A = A[-n - 1]
        ans += (max_A - min_A) * mod_comb.nCk(n, K - 1)
        ans %= P

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24824