akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N,D,W;

struct Cake{
    int id,w,d;
};

void solve(){
    vector<int> P(N),S(N);
    for(int i=0;i<N;i++) cin>>P[i]>>S[i];

    Cake fir;
    fir.id=1;
    fir.w=W;
    fir.d=D;
    vector<Cake> res;
    res.push_back(fir);

    for(int k=0;k<N;k++){
        vector<Cake> nex;
        Cake tar;
        for(int j=0;j<res.size();j++){
            int cost=0;
            if(res[j].id>P[k]) cost=1;

            if(res[j].id==P[k]){
                tar=res[j];
            }else{
                res[j].id=res[j].id-cost;
                nex.push_back(res[j]);
            }
        }

        Cake a,b;
        S[k]%=(tar.w+tar.d);
        if(S[k]<tar.w){
            a={(int)nex.size()+1,S[k],tar.d};
            b={(int)nex.size()+2,tar.w-S[k],tar.d};
        }else{
            a={(int)nex.size()+1,tar.w,S[k]-tar.w};
            b={(int)nex.size()+2,tar.w,tar.d-(S[k]-tar.w)};
        }

        if(a.w*a.d>b.w*b.d){
            swap(a.id,b.id);
        }
        nex.push_back(a);
        nex.push_back(b);
        res=nex;
    }

    vector<int> v;
    for(int i=0;i<res.size();i++){
        v.push_back(res[i].w*res[i].d);
    }
    sort(v.begin(),v.end());

    for(int i=0;i<v.size()-1;i++) cout<<v[i]<<" ";
    cout<<v.back()<<endl;
}

int main(){
  while(1){
      cin>>N>>W>>D;
      if(N==0&&W==0&&D==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 3156
/*
g++ -std=c++14 -Wall -O2 -o main.exe main.cpp
main.exe
*/

#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
//最大公約数: gcd()
//最小公倍数: lcm()

#define ll long long int

using namespace std;

template <typename T>
string itos(T val){ //数値を文字列(string)に変換
	stringstream ss;

	ss << val;
	return ss.str();
}

int stoi(string s){ //文字列(string)を数値に変換
	stringstream ss;
	int val = 0;

	ss << s;
	ss >> val;
	return val;
}

template <typename T>
void sortasc(vector<T> &v){ //vectorを昇順にソート
    sort(v.begin(), v.end(), std::less<T>());
    return;
}

template <typename T>
void sortdesc(vector<T> &v){ //vectorを降順にソート
    sort(v.begin(), v.end(), std::greater<T>());
    return;
}

//------------------------------------------------------------------------------

int main(){
	string s;
	ll k, i;
	cin >> s >> k;

	for(i = 0; i < s.size(); i++){
		if(s[i] == '1' && (i + 1) == k){
			cout << "1" << endl;
			return 0;
		}
		else if(s[i] != '1') break;
	}

	cout << s[i] << endl; 

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char S[4];
	scanf("%s", S);
	if (S[0] == 'S' && S[1] == 'U') printf("7\n");
	else if (S[1] == 'A') printf("1\n");
	else if (S[1] == 'R') printf("2\n");
	else if (S[1] == 'H') printf("3\n");
	else if (S[1] == 'E') printf("4\n");
	else if (S[1] == 'U') printf("5\n");
	else printf("6\n");
	fflush(stdout);
	return 0;
}

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

int main(){
  int a, b;
  std::cin >> a >> b;
  int digit=0, bb = b; //桁
  while(bb > 0){
    bb/=10;
    digit++;
  }
  int product = 0; //積
  
  while(digit >0){
    a*=10;
    digit--;
  }
  int sum = a+b;
  for(int i =1;i<311;i++){
    if(sum == i*i){
      std::cout << "Yes" << endl;
      return 0;
    }
  }
  std::cout << "No" << endl;

}

Measured memory_bytes: 256
/**
 *  author:   TakeruOkuyama
 *  created:  
**/
#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>;

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    int K, S;
    cin >> K >> S;
    int ans = 0;
    rep(X, K+1){
        rep(Y, K+1){
            if(K >=  S - (X + Y) && 0 <= S - (X + Y)){
                ans++;
                
            }
        }
    }
    cout << ans << endl;
return 0;}

/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
   ll a,b;
   cin>>a>>b;
   ll sum=a+b;
   if(sum%2==0)cout<<sum/2<<endl;
   else cout<<"IMPOSSIBLE"<<endl;
}
   



Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
using namespace std;


int main()
{
    ll n; cin>>n;
    ll axa,baxa; cin>>axa>>baxa;
    n--;
    while(n--)
    {
        ll a,b; cin>>a>>b;
        ll aa,bb;
        aa=axa/a*a;
        if(aa<axa) aa+=a;
        ll cnt=aa/a;
        ll pot=cnt*b;
        if(pot>=baxa)
        {
            baxa=pot;
            axa=aa;
            continue;
        }
        else
        {
            bb=baxa/b*b;
            if(bb<baxa) bb+=b;
            aa=bb/b*a;
            axa=aa;
            baxa=bb;
        }
    }
    cout<<axa+baxa;
    return 0;
}


Measured memory_bytes: 256
import scala.io.Source.stdin

object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1

    for( i <- 3 to Math.sqrt(n).toInt by 2 )
    {
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
      primes(i) = primes(i) + primes(i-1)
      primes(i+1) = primes(i+1) + primes(i)
    }

    for(i<-Math.sqrt(n).toInt+1 to n)
      primes(i) = primes(i)+primes(i-1)

    primes
  }

  def main(args:Array[String]) = {
    val p = sieve(1000000)
    for(i <- stdin.getLines) {
      println(p(i.toInt))
    }
  }
}

Measured memory_bytes: 63644
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int H, W;
int sy, sx;
constexpr int MAX = 500;
bool yoko[MAX + 2][MAX + 2];
bool tate[MAX + 2][MAX + 2];
bool used[MAX + 2][MAX + 2][2];
bool memo[MAX + 2][MAX + 2][2];
constexpr int d[5] = {-1, 0, 1, 0, -1};
void init()
{
    for (int i = 0; i < H + 2; i++) {
        for (int j = 0; j < W + 1; j++) {
            yoko[i][j] = false;
        }
    }
    for (int i = 0; i < H + 1; i++) {
        for (int j = 0; j < W + 2; j++) {
            tate[i][j] = false;
        }
    }
    for (int i = 0; i < H + 2; i++) {
        for (int j = 0; j < W + 2; j++) {
            for (int k = 0; k < 2; k++) {
                used[i][j][k] = false;
                memo[i][j][k] = false;
            }
        }
    }
}

bool movable(const int y, const int x, const int dir, const bool rev)
{
    const int newy = y + d[dir];
    const int newx = x + d[dir + 1];
    if (newy >= 0 and newy <= H + 1 and newx >= 0 and newx <= W + 1) {
        if (dir == 0) {
            return (rev ? tate[newy][x] : not tate[newy][x]);
        } else if (dir == 1) {
            return (rev ? yoko[y][x] : not yoko[y][x]);
        } else if (dir == 2) {
            return (rev ? tate[y][x] : not tate[y][x]);
        } else {
            return (rev ? yoko[y][newx] : not yoko[y][newx]);
        }
    } else {
        return false;
    }
};

bool dfs(const int y, const int x, const bool rev)
{
    if (used[y][x][rev]) {
        return memo[y][x][rev];
    }
    used[y][x][rev] = true;
    if (y == 0 or y == H + 1 or x == 0 or x == W + 1) {
        used[y][x][rev] = true;
        memo[y][x][rev] = true;
        return true;
    }
    for (int dir = 0; dir < 4; dir++) {
        if (movable(y, x, dir, rev)) {
            const int newy = y + d[dir];
            const int newx = x + d[dir + 1];
            bool ans = true;
            for (int newrev = 0; newrev < 2; newrev++) {
                if (not dfs(newy, newx, newrev)) {
                    ans = false;
                    break;
                }
            }
            if (ans) {
                memo[y][x][rev] = true;
                return true;
            }
        }
    }
    memo[y][x][rev] = false;
    return false;
}

int main()
{
    while (true) {
        cin >> H >> W >> sy >> sx;
        if (H == 0 and W == 0 and sy == 0 and sx == 0) {
            break;
        }
        init();
        for (int i = 0; i < H; i++) {
            for (int j = 1; j <= W; j++) {
                int n;
                cin >> n;
                tate[i][j] = n == 1;
            }
            for (int j = 0; j <= W; j++) {
                int n;
                cin >> n;
                yoko[i + 1][j] = n == 1;
            }
        }
        for (int j = 1; j <= W; j++) {
            int n;
            cin >> n;
            tate[H][j] = n == 1;
        }

        cout << (dfs(sy, sx, false) ? "Yes" : "No") << endl;
    }
    return 0;
}



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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define pb push_back
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 9LL;

int n, k;
int in[N];

int main(){
	scanf("%d %d", &n, &k); int t = 0;
	for(int i = 1; i <= n; ++i){
		scanf("%d", &in[i]);
		if(in[i] <= 0)
			t = i;
		in[i] = abs(in[i]);
	}
	
	int res = MX;
	for(int j = 1; j <= t; ++j){
		if(j + k <= t)
			continue;
		if(n - j + 1 < k)
			break;
		
		int r = j + k - 1;
		res = min(res, in[j] * 2 + in[r]);
		res = min(res, in[j] + in[r] * 2);
	}
	
	if(t >= k)
		res = min(res, in[t - k + 1]);
	if(n - t >= k)
		res = min(res, in[t + k]);
	printf("%d\n", res);
	return 0;
}

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

using namespace std;

int dp[3010][3010];
string s, t;

int main(){
    cin >> s >> t;
    int n = s.length(), m = t.length();

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= m; j++){
            if(i == 0 || j == 0) dp[i][j] = 0;
            else if(s[i - 1] == t[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    
    int len = dp[n][m];
    int i = n, j = m;
    string res;
    while(i > 0 && j > 0){
        if(s[i - 1] == t[j - 1]){
            res.push_back(s[i - 1]);
            i--, j--, len--;
        }
        else if(dp[i - 1][j] > dp[i][j - 1]) i--;
        else j--;
    }
    reverse(res.begin(), res.end());
    cout << res << '\n';
}

Measured memory_bytes: 35584
n = int(input())
a = list(map(int, input().split()))
x = 0
b = [0] * n
for i in range(n):
    b[a[i] - 1] += 1

x = 0
for j in range(n):
    x += ((b[j] - 1) * b[j] / 2)

for k in range(n):
    print(int(x - b[a[k] - 1] + 1))

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

using namespace std;
using ll = long long;


int main()
{
    int h, w; cin >> h >> w;
    vector<vector<string>> s(h, vector<string>(w)); 
    for(int i = 0; i < h; i++)for(int j = 0; j < w; j++)cin >> s[i][j];

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(s[i][j] == "snuke") {
                cout << (char)('A' + j) << i+1 << endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,m) cin >> a.at(i);
    int total = 0;
    rep(i,m) total += a.at(i);
    if(total > n) cout << -1 << endl;
    else cout << n - total << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <map>
using namespace std;
int main() {
	long long int n=0, a=0, buf;
	cin >> n;
	map <long,long> map1;
	for (int i=0;i<n;i++){
		cin >> buf;
		map1[buf]++;
		if(map1[buf]%2==1)a++;
        else a--;
	}
	cout <<a;
  return 0;
}

Measured memory_bytes: 6528
#安定なソート
#4つの絵柄と9つの数字から成る36枚のカード
def bubble(nums,N):
    for i in range(N-1): #先頭が確定するまで調べる（確定したら先頭の次の値が先頭になる）
        j = N-1
        while j > i:
            if nums[j-1][1] > nums[j][1]:
                nums[j-1], nums[j] = nums[j], nums[j-1]
            j = j - 1 #交換したら次の値に移動する
    return nums

def selection(nums,N):
    for i in range(N-1):
        minj = i
        for j in range(i+1,N): #配列を探索し、最小値を見つける
            if nums[minj][1] > nums[j][1]:
                minj = j
        if minj != i:
            nums[minj], nums[i] = nums[i], nums[minj]
    return nums

N = int(input())
nums = input().split()
nums2 = nums.copy()
#numsをそのまま二つのソートで使うと、後のソートでは先のソートの影響を受けるので、コピーしておく
#あるいは、numsではなくnums[:]を引数とする

result1 = bubble(nums,N)
print(' '.join(map(str,result1)))
print("Stable")
result2 = selection(nums2,N)
print(' '.join(map(str,result2)))
print("Stable" if result1 == result2 else "Not stable")



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll a, b, c;
    cin >> a >> b >> c;
    a %= b;
    map<ll, ll> mp;
    rep(i, b)
    {
        if((a*i)%b == c ) ANS("YES");
    }
    ANS("NO");
}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


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

int main(){
  char input;
  cin >> input;
  if(input == 'a' || input == 'i' || input == 'u' || input == 'e' || input == 'o'){
    cout << "vowel" << endl;
  }
  else cout << "consonant" << endl;
}

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

#define MAX_N 200000

using namespace std;

string s;

int n, m;

vector <int> g[MAX_N + 1];

int ap[MAX_N + 1][2];

int que[MAX_N + 1];

void add(int a, int b)
{
    g[a].push_back(b);
}

int luat[MAX_N + 1];

int main()
{
    cin >> n >> m;

    cin >> s;

    int i;
    int a, b;
    for(i = 1; i <= m; i ++)
    {
        cin >> a >> b;

        add(a, b);

        if(a != b)
            add(b, a);
    }

    for(i = 1; i <= n; i ++)
    {
        for(auto u : g[i])
            ap[u][s[i - 1] - 'A'] ++;

    }

    int st = 1, dr = 0;
    for(i = 1; i <= n; i ++)
    {
        if(ap[i][0] < 1 || ap[i][1] < 1)
        {
            luat[i] = 1;
            que[++ dr] = i;
        }
    }

    while(st <= dr)
    {
        int cr = que[st ++];

        for(auto u : g[cr])
        {
            ap[u][s[cr - 1] - 'A'] --;

            if(luat[u] == 0 && (ap[u][0] < 1 || ap[u][1] < 1))
            {
                luat[u] = 1;
                que[++ dr] = u;
            }
        }
    }

    int rez = 0;
    for(i = 1; i <= n; i ++)
        rez = rez || (luat[i] == 0);

    cout << (rez == 1 ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 13444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 
 		long n =fr.nextLong() ,m =fr.nextLong() ,k =fr.nextLong() ,md =998244353l ,ans =0l ;
 		long fct[] =new long[(int)(n+1)] ,i ,j ,o ,p ;	fct[0] =1l ;	
 		
 		for (i =1 ; i<=n ; ++i)	fct[(int)i] =(fct[(int)(i-1)] * i)%md ;
 		
 		for (i =0 ; i<=k ; ++i) {
 			j =pow (m-1 , n-1l-i , md) ;	j =(j * m)%md ;
 			
 			p =fct[(int)(n-1)] ;	o =(fct[(int)i] * fct[(int)(n-1-i)])%md ;
 			o =pow (o , md-2l , md) ;	p =(p * o)%md ;

 			j =(j * p)%md ;	ans =(ans + j)%md ;
 		}
		op.println(ans) ;	op.flush();	op.close();
	}
	static long pow (long b , long e , long md) {
		if (e==0l)	return 1l;
		if (e==1l)	return b;
		long dm =pow(b,e/2l,md) ;	dm =(dm * dm)%md ;
		if ((e&1l)==1l)	{	dm =(b * dm)%md ;	}
		return dm ;
	}		
	static 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();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

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

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

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

int main(){
    int n, p[20];
    cin >> n;
    for(int i=0;i<n;++i) cin >> p[i];

    int cnt = 0;
    for(int i=1;i<n-1;++i){
        if(p[i-1] < p[i] && p[i] < p[i+1]) ++cnt;
        else if(p[i-1] > p[i] && p[i] > p[i+1]) ++cnt;
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        Set<Integer> nSet = new HashSet<Integer>();

        for(int i = 1;i<=N;i++){
            nSet.add(i);
        }
        for(int i=0;i<K;i++){
            int d = sc.nextInt();
            for(int j=0;j<d;j++){
                nSet.remove(sc.nextInt());
            }
        }
        System.out.println(nSet.size());

    }

}









Measured memory_bytes: 46416
li=[]
ok=False
a=int(input())
for i in range(1,10):
    for j in range(1,10):
        if(i*j==a and a%i==0 and a%j==0 ):
            li.append({i,j})
            break
if(len(li)>=1):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
using ll = long long;
using ull = unsigned long long;
const int maxnfact = 100010;
const ll md = 1e9+7;
ll N, K;
ll fact[maxnfact], fact_inv[maxnfact];
ll A[maxnfact];

inline long long add(long long a, long long b) {
 a += b;
 if (a >= md) a -= md;
 return a;
}

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

inline long long mul(long long a, long long b) {
  return  (a * b) % md;
}

inline long long mdpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline long long inv(long long a) {
  a %= md;
  if (a < 0) a += md;
  long long b = md, u = 0, v = 1;
  while (a) {
    long long t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

void pre() {
  fact[0] = 1;
  fact_inv[0] = 1;
  for(int i = 1; i < maxnfact; i++){
    fact[i] = mul(fact[i-1], i);
  }
  fact_inv[maxnfact - 1] = mdpow(fact[maxnfact - 1], md - 2);
  for (int i = maxnfact-1-1; i >= 1; i--) {
    fact_inv[i] = mul(fact_inv[i+1], i+1);
  }
}

inline ll nck(ll n, ll k) {
  if (k == 0) return 1;
  if (n < k) return 0;
  return mul(mul(fact[n], fact_inv[n-k]), fact_inv[k]);
}

int main() {
  fastio;
  cin >> N >> K;
  pre();
  for (int i = 0; i < N; i++) { cin >> A[i]; }
  sort(A, A + N);
  ll res = 0;
  for (int i = 0; i < N; i++) {
    ll choose = nck(i, K-1);
    res = add(res, mul(A[i], choose));
    choose = nck(N - i - 1, K-1);
    res = sub(res, mul(A[i], choose));
  }
  cout << res << endl;
}


Measured memory_bytes: 2560
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn main() {
    let n: u64 = input();
    let mut p_vec: Vec<u64> = Vec::new();
    for _ in 0..n {
        let p: u64 = input();
        p_vec.push(p);
    }
    p_vec.sort();
    let mut sum = 0;
    for i in 0..n as usize {
        if i == n as usize - 1 {
            sum += p_vec[i]/2;
        } else {
            sum += p_vec[i];
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 2156
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
void init(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main()
{
  init();
  int n;cin >> n;
  vecint a(n,0), b(n,0), c(n,0);
  REP(i,n){cin >> a[i] >> b[i] >> c[i];}
  vecint dpa(n,0), dpb(n,0), dpc(n,0);
  dpa[0] = a[0];
  dpb[0] = b[0];
  dpc[0] = c[0];
  REP(i,n - 1){
    dpa[i + 1] = max(dpb[i] + a[i + 1], dpc[i] + a[i + 1]);
    dpb[i + 1] = max(dpc[i] + b[i + 1], dpa[i] + b[i + 1]);   
    dpc[i + 1] = max(dpa[i] + c[i + 1], dpb[i] + c[i + 1]);
  }
  cout << max(dpa[n - 1], max(dpb[n - 1], dpc[n - 1])) << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
//#define Equality(a,b) (fabs(a-b)<0.00000001)
typedef long long LL;
#define epsilon 0.000000001
long double dp[301][301][301];
LL three=0,two=0,one=0,n;
long double unit=1.0;

short fequal(double a, double b)
{
    return fabs(a-b) < epsilon;
}

long double cal(LL i,LL j,LL k)
{
    //printf("INVESTIGATING %lld %lld %lld\n",i,j,k);
    long double a,b,c;
    if(i<=0)
    {
       // printf("DEFAULT INITIALIZING a\n");
        a=0.0;
    }
    else
    {
         if(fequal(dp[i-1][j+1][k],-1.0))
           {
             dp[i-1][j+1][k]==cal(i-1,j+1,k);
           }
        a=dp[i-1][j+1][k];  
    }


    if(j<=0)
    {
       // printf("DEFAULT INITIALIZING b\n");
        b=0.0;
    }
    else
    {
         if(fequal(dp[i][j-1][k+1],-1.0))
            {
            dp[i][j-1][k+1]==cal(i,j-1,k+1);
            }  
         b=dp[i][j-1][k+1];
    }

    if(k<=0)
    {
       // printf("DEFAULT INITIALIZING c\n");
        c=0.0;
    }
    else
    {
         if(fequal(dp[i][j][k-1],-1.0))
        {
            //printf("STORED %Lf in %lld %lld %lld\n",cal(i,j,k-1),i,j,k-1);            
          dp[i][j][k-1]=cal(i,j,k-1);
        }
        //printf("STORED %Lf in c\n",dp[i][j][k-1]);  
        c=dp[i][j][k-1];
    }
    if(i==0 && j==0 && k==0)
    {
        //printf("ENTERED NO MAN's LAND\n");
        return 0.0;
    }
    else
    {
       // printf("SAFE with %lld %lld %lld\n\n",i,j,k);
        //printf("a is %Lf\n",a);
       // printf("b is %Lf\n",b);
       // printf("c is %Lf\n",c);
        //printf("VALUE IS %Lf\n",dp[0][0][0]);
        dp[i][j][k]=((unit)/(long double)(i+j+k))*(unit*n+i*a +j*b+k*c);


       // printf("RETURNING %lld %lld %lld as %Lf\n\n\n",i,j,k,dp[i][j][k]);
        return dp[i][j][k];
    }
    
    
    
    
    
}

int main()
{
    LL i,j,k,temp;
    for(i=0;i<=300;i++)
    {
        for(j=0;j<=300;j++)
        {
            for(k=0;k<=300;k++)
            {
                dp[i][j][k]=-1.0;
            }
        }
    }
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&temp);
        if(temp==1)
        {
            one++;
        }
        else if(temp==2)
        {
            two++;
        }
        else
        {
            three++;
        }        
    }
    //printf("COUNT OF THREE IS %lld\n",three);
   // printf("COUNT OF two IS %lld\n",two);
   // printf("COUNT OF one IS %lld\n",one);
    if(dp[three][two][one]==-1.0)
    {
        dp[three][two][one]=cal(three,two,one);
    }
    //printf("0 0 1 IS %Lf\n",cal(0,0,1));


    /*for(i=0;i<=3;i++)
    {
        printf("%d %d %lld is %Lf\n",0,0,i,dp[0][0][i]);
    }*/
    printf("%0.12Lf",dp[three][two][one]);
}

Measured memory_bytes: 426496
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, T;
    cin >> n >> T;
    vector<int> c(n), t(n);
    rep(i, n) cin >> c[i] >> t[i];

    int best = 1e8;
    rep(i, n) {
        if (t[i] <= T) {
            if (best > c[i]) {
                best = c[i];
            }
        }
    }
    if (best == 1e8) {
        put("TLE")
    }
    else 
        put(best)

    
    return 0;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

        for(int i = 1; i <= 9; i++){
            if(a % i == 0 && a / i >= 1 && a / i <= 9){
                System.out.println("Yes");
                break;
            }
            if(i==9) System.out.println("No");
        }

    }

}


Measured memory_bytes: 21844
#include<stdio.h>
int main(){
    char palavra1[3];
    char palavra2[3];
    char palavra3[3];

    char palavra[3];

    scanf("%s",palavra1);
    scanf("%s",palavra2);
    scanf("%s",palavra3);

    palavra[0] = palavra1[0];
    palavra[1] = palavra2[1];
    palavra[2] = palavra3[2];
    palavra[3] = '\0';
    printf("%s\n",palavra);

}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("4 7");
            WillReturn.Add("2 9");
            WillReturn.Add("6 2");
            //8
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("1 10");
            WillReturn.Add("3 6");
            WillReturn.Add("5 2");
            WillReturn.Add("4 4");
            WillReturn.Add("2 8");
            //7
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("2");
            WillReturn.Add("1 1000000000");
            WillReturn.Add("1000000000 1");
            //1000000001
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    struct ABInfo
    {
        internal int A;
        internal int B;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();

        int[] wkArr = { };
        Action<string> SplitAct = pStr =>
            wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray();

        var ABList = new List<ABInfo>();
        foreach (string EachStr in InputList.Skip(1)) {
            SplitAct(EachStr);
            ABInfo WillAdd;
            WillAdd.A = wkArr[0];
            WillAdd.B = wkArr[1];
            ABList.Add(WillAdd);
        }

        ABList = ABList.OrderByDescending(X => X.A).ToList();
        Console.WriteLine(ABList[0].A + ABList[0].B);
    }
}


Measured memory_bytes: 32944
//https://atcoder.jp/contests/abc156/tasks/abc156_c
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    vector<ll> xn(N);
    for(auto&& x:xn){
        cin>>x;
    }
    ll ans=INT64_MAX;    
    FOR(i,0,100+1){
        ll p=i;
        ll val=0;
        FOR(j,0,xn.size()){
            ll d = p - xn.at(j);
            val += d*d;
        }
        ans=min(ans,val);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K;
  cin >> N >> K;
  vll a(N);
  vll sum(N+1, 0LL);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    sum.at(i+1) = sum.at(i) + a.at(i);
  }
  ll ng = 60LL;
  ll ok = -1LL;
  queue<ll> num;
  while(ng - ok > 1){
    ll mid = (ng + ok) / 2LL;
    ll x = (1LL << mid);
    ll xx = x * 2LL;
    queue<ll> num2;
    for(int i = 1; i <= N; i++){
      for(int j = 0; j < i; j++){
        ll n = (sum.at(i) - sum.at(j)) % xx;
        if(n >= x){
          num2.push(sum.at(i) - sum.at(j));
        }
      }
    }
    if(num2.size() >= K){
      ok = mid;
      num = num2;
    }
    else ng = mid;
  }

  if(sz(num) < K){
    cout << 0 << endl;
    return 0;
  }
  ll ans = (1LL << ok);
  for(int i = ok-1; i >= 0; i--){
    ll counter = 0;
    queue<ll> que1, que2;
    que1 = num;
    while(!que1.empty()){
      ll n = que1.front(); que1.pop();
      if((n>>i) & 1) que2.push(n);
    }
    if(que2.size() >= K){
      num = que2;
      ans += (1LL << i);
    }
  }
  cout<< ans << endl;
}

Measured memory_bytes: 4352
import java.util.*;
public class Main {

	//直角三角形かどうかを返す関数
	private boolean isRightTri(double a, double b, double c){
		final double EPS = 1.0e-08;
		double sum = Math.pow(a, 2) + Math.pow(b, 2);
		sum = Math.sqrt(sum);
		if(Math.abs(sum - c) < EPS)
			return true;
		else
			return false;
	}

	private boolean isLoz(int len1, int len2, int dia){
		if(len1 + len2 > dia && len1 == len2)
			return true;
		else
			return false;
	}

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("[,\\r\\n]+");
		int lec = 0, loz = 0;
		while(sc.hasNext()){
			int len1 = sc.nextInt();
			int len2 = sc.nextInt();
			int dia = sc.nextInt();
			if(isRightTri(len1, len2, dia))
				lec++;
			if(isLoz(len1, len2, dia))
				loz++;
		}
		System.out.printf("%d\n%d\n",lec, loz);
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<random>
#include<algorithm>
#define ll long long
using namespace std;
bool f[20];

int main()
{
    int x;
    for (int i=0; i<4; ++i)
    {
        cin>>x;
        f[x]=1;
    }
    if (f[1] && f[4] && f[7] && f[9])
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 768
#!/usr/bin/env ruby

# MOD = (10 ** 9) + 7
NNN = gets.chomp.to_i
dn = gets.chomp.split.map(&:to_i)

ans = 0
(NNN - 2).times do |i|
  ans += 1 if dn[i..(i+2)].sort[1] == dn[i+1]
end

p ans


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

bool lower_isOK(int index, int key, const vector<int> &v) {
    if (v.at(index) > key) return true;
    else return false;
}

int lower_binary_search(int key, const vector<int> &v) {
    int ng = -1;
    int ok = (int)v.size();

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (lower_isOK(mid, key, v)) ok = mid;
        else ng = mid;
    }
    return ok;
}


bool upper_isOK(int index, int key, const vector<int> &v) {
    if (v.at(index) < key) return true;
    else return false;
}

int upper_binary_search(int key, const vector<int> &v) {
    int ng = (int)v.size();
    int ok = -1;

    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (upper_isOK(mid, key, v)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> p(3, vector<int>(n));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> p.at(i).at(j);
        }
    }
    
    for (int i = 0; i < 3; i++)
    {
        sort(p.at(i).begin(), p.at(i).end());
    }
    
    vector<pair<int, int>> b;
    for (int i = 0; i < n; i++)
    {
        int index = lower_binary_search(p.at(1).at(i), p.at(2));
        if (index == -1) continue;

        b.push_back(make_pair(n - index, p.at(1).at(i)));
    }

    long long ans = 0;
    for (int i = 0; i < (int)b.size(); i++)
    {
        int index = upper_binary_search(b.at(i).second, p.at(0));
        if (index == n) continue;

        ans += (long long)(index + 1) * b.at(i).first;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <set>
 
int main()
{
  int n;
  std::cin >> n;
 
  std::vector<int> ax;
  for(int i=0; i<n; i++)
  {
    int a;
    std::cin >> a;
    ax.push_back(a);
  }
 
  std::multiset<int> colorHighs;

  for(int i=0; i<ax.size(); i++)
  {
    if( colorHighs.empty() ) { colorHighs.insert(ax[i]); continue; }

    auto it = colorHighs.lower_bound(ax[i]);
    bool failed = false;
    while( true )
    {
      if( it != colorHighs.end() ) { if( *it < ax[i] ) { break; } }
      if( it == colorHighs.begin() ) { failed = true; break; }
      it--;
    }

    if( failed ) { colorHighs.insert(ax[i]); continue; }
    colorHighs.erase(it);
    colorHighs.insert(ax[i]);
  }
  
  std::cout << colorHighs.size();
}


Measured memory_bytes: 5368
#include<iostream>
#include <complex>
#include <vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<list>
#include <iterator>
#include <utility>
#include <numeric>
#include <map>
#include <iomanip>
#include <sstream>
using namespace std;

#define intt long long




int main() {

	int N, M;
	map<int, int> mdata;
	map<int, int> yi;
	vector<vector<int>> pi;
	vector<pair<int, int>> ans;
	
	cin >> N >> M;

	pi.resize(N);
	ans.resize(M);

	int p, y;
	for(int i = 0;i < M; i++){
		cin >> p >> y;
		yi.insert(make_pair(y,i));
		pi[p-1].push_back(y);

	}
	for (int i = 0; i < N; i++) {
		if (pi[i].empty() != true) {
			sort(pi[i].begin(), pi[i].end());
			for (int j = 0; j < pi[i].size();j++) {
				ans[yi.at(pi[i][j])].first = i + 1;
				ans[yi.at(pi[i][j])].second = j + 1;
			}
		}
	}

	
	string s1, s2;
	for (int i = 0; i < M; i++) {
		ostringstream sout1, sout2;
		sout1 << std::setfill('0') << std::setw(6) << ans[i].first;
		sout2 << std::setfill('0') << std::setw(6) << ans[i].second;

		s1 = sout1.str();
		s2 = sout2.str();
		cout << s1 << s2 << endl;
	}

	return 0;

}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
using namespace std;
string s,st;
void digui(int w)
{
    if(s[w]=='e')
    {
        st="";
        for(int i=w;i<=w+4;i++) st+=s[i];
        if(st=="erase")
        {
            if(w+4==s.size()-1)
            {
                cout<<"YES\n";
                exit(0);
            }
            if(s[w+5]=='r')
            {
                if(w+5==s.size()-1)
                {
                    cout<<"YES\n";
                    exit(0);
                }
                digui(w+5+1);
            }
            else digui(w+4+1);
        }
        else return;
    }
    if(s[w]=='d')
    {
        st="";
        for(int i=w;i<=w+4;i++) st+=s[i];
        if(st=="dream")
        {
            if(w+4==s.size()-1)
            {
                cout<<"YES\n";
                exit(0);
            }
            if(s[w+5]=='e'&&s[w+6]=='r')
            {
                if(w+6==s.size()-1)
                {
                    cout<<"YES\n";
                    exit(0);
                }
                digui(w+6+1);
                digui(w+4+1);
            }
            else digui(w+4+1);
        }
        else return;
    }
}
int main()
{
    cin>>s;
    if(s[0]!='d'&&s[0]!='e')
    {
        cout<<"NO\n";
        return 0;
    }
    digui(0);
    cout<<"NO\n";
    return 0;
}

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

int main()
{
  string s, t, u;
  int a, b;

  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if (u == s)
  {
    cout << a - 1 << " " << b << endl;
  }
  else if (u == t)
  {
    cout << a << " " << b - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<ll> A(N,0);
  cin>>A;
  vector<ll> cnt(3,0);
  ll ans=1;
  for(auto &I:A){
    ll c=0,idx=-1;
    for(int j=0;j<3;j++){
      if(cnt[j]==I){c++; idx=j;}
    }
    if(c==0){ans=0; break;}
    ans*=c;
    cnt[idx]++;
    ans%=MOD;
  }
  cout<<ans<<endl;
  

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define ll long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
map<string,int> a;
vector<string> b;
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n=read();
	for(int i=1;i<=n;i++)
	{
		string x;
		cin>>x;
		a[x]++;
	}
	int maxn=0;
	for(auto i:a)
	{
		if(i.sec>maxn) maxn=i.sec;
	}
	for(auto i:a)
	{
		if(i.sec==maxn) b.pb(i.fir);
	}
	sort(b.begin(),b.end());
	for(auto i:b) cout<<i<<endl;
#ifdef __LOCAL__
	cout<<"Time Used : "<<clock()<<endl;
#endif
	return 0;
}



Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()	
{
	int a[4],sum;
	string s="+-",t;
	cin>>t;
	for(int i=0;i<4;i++)
	{
		a[i]=t[i]-'0';	
	}
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<2;k++)
			{
				if(i==0)sum=a[0]+a[1];
				else sum=a[0]-a[1];
				if(j==0)sum+=a[2];
				else sum-=a[2];
				if(k==0)sum+=a[3];
				else sum-=a[3];
				if(sum==7)
				{
					cout<<a[0]<<s[i]<<a[1]<<s[j]<<a[2]<<s[k]<<a[3]<<"=7"<<endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
import sys
from collections import deque
import math


# ans = 0
n = int(input())
#h = math.ceil(n/2)
dists = []
h = math.ceil(math.sqrt(n))
# i <= jとする
for i in range(1,h + 1):
    if n % i != 0:
      continue
    j = int(n / i)
    dists.append(i + j - 2)
print(min(dists))


# h = math.ceil(n/2)
# board1 = [[0]*h/2 for _ in range(h/2)]
# board2 = [[0]*h/2 for _ in range(h/2)]
# for i in range(1,h/2 + 1):
#   for j in range(1,h/2 + 1):
#     board1[i - 1][j - 1] = i * j
# for i in range(h/2 + 1,h + 1):
#   for j in range(h/2 + 1,h + 1):
#     board2[i - (h/2 + 1)][j - (h/2 + 1)] = i * j
# sx = 1
# sy = 1
# gx = 0
# gy = 0
# dist1 = [[-1]*h/2 for _ in range(h/2)]
# dist2 = [[-1]*h/2 for _ in range(h/2)]
# que = deque([(sy - 1,sx - 1)])
# dist1[sy - 1][sx - 1] = 0
# while que:
#   y,x = que.popleft()
#   if board1[y][x] == n:
#     ans = dist1[y][x]
#     break
#   for y1,x1 in [(y + 1,x),(y, x + 1)]:
#     if y1 < 0 or x1 < 0 or x1 >= h/2:
#       continue
#     if y1 >= h/2:
#       sy = y1
#       sx = x1
#       gy = y
#       gx = x
#       break
#     if dist1[y1][x1] != -1:
#       continue
#     if dist1[y1][x1] == -1:
#       dist1[y1][x1] = dist1[y][x] + 1
#       que.append((y1,x1))
# que = deque([sy,sx])
# dist2[sy][sx] = 0
# while que:
#   y,x = que.popleft()
#   if board2[y][x] == n:
#     ans = dist1[gy][gx] + dist2[y][x]
#     break
#   for y1,x1 in [(y + 1,x),(y, x + 1)]:
#     if y1 < 0 or x1 < 0 or x1 >= h/2:
#       continue
#     if y1 >= h/2:
#       sy = y1
#       sx = x1
#       break
#     if dist2[y1][x1] != -1:
#       continue
#     if dist2[y1][x1] == -1:
#       dist2[y1][x1] = dist2[y][x] + 1
#       que.append((y1,x1))
# print(ans)

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans = max(a*c,a*d);
	ll res = max(b*c,b*d);
	cout<<(max(res,ans));	
	return 0;
}

Measured memory_bytes: 3632
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll unsigned long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e18;
int main()
{
IOS
ll n;
ll l,r,d;
cin>>l>>r>>d;
ll cnt=0;
for(ll i=l;i<=r;i++)
{
    if(i%d==0)
        cnt++;
}
cout<<cnt;
return 0;
}


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

int main() {
    ld N;
    cin >> N;
    ll count =0;
 
    for(ld A = 1;A<=N;A++){
        
        count += ceill(N/A) -1;
        
    }
    cout << count << endl;
}


Measured memory_bytes: 3724
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string.h>
using namespace std;
int main(){
    int n, r;
    int ans;
    cin>>n>>r;
    if (n < 10){
        ans = r + 100 * (10 - n);
    }else{
        ans = r;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//Author: ReseeCher
#include<bits/stdc++.h>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
#define ckmax(a,b) (a)=max(a,b)
#define ckmin(a,b) (a)=min(a,b)
#define pb push_back
#define Ad(x,y) (x)=((x)+(y))%P
using namespace std;
const int N=305;
const int P=998244353;
LL R(){
    LL ans=0,f=1;char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) ans=ans*10+c-'0';
    return ans*f;
}
int a[N],n,m;
LL dp[N][N][N];
char s[N];
LL an[N];
int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	cin>>(s+1);int len=strlen(s+1);
	int K=R();
	++n;
	F(i,1,len)
		if(s[i]=='1')++a[n],++m;
		else ++n;
	
	dp[0][0][0]=1;
	F(i,0,n-1)
		F(j,0,m)
			F(k,0,m){
				if(!dp[i][j][k])continue;
				int lim=min(m+a[i+1]-j,min(m+a[i+1]-k,m));
				F(u,max(a[i+1]-j,0),lim){
					Ad(dp[i+1][j+(u-a[i+1])][k+max(0,u-a[i+1])],dp[i][j][k]);
				}
			}
	F(i,0,m)an[i]=dp[n][0][i];
	F(i,1,m)Ad(an[i],an[i-1]);
	cout<<an[min(K,m)];
    return 0;
}


Measured memory_bytes: 58356