akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a[3];
	int x=0,y=0;
	for(int i=0;i<3;i++)
	{
		cin >> a[i];
		if(a[i]==5) x++;
		if(a[i]==7) y++;
	}
	if(x==2&&y==1) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
} 

Measured memory_bytes: 256
/*
    LEARNING DP:    Knapsack 2
        + CHOSE some of the N items have VALUES
        + THE CAPACITY of the knapsack is W.
        + MAXIMUM VALUES.
    CONSTRAINT:
        + 1 <= N <= 100
        + 1 <= WEIGHT <= 1000,000,000 // DIF
        + 1 <= VALUE <= 10^3 * N // DIF
    QUESTION:
        WHICH WEIGHT? and WHICH ITEMS?
    IF WE KNOW:
        if we know the knapsack 1, so now the WEIGHT become the VALUE
    PRE DP:

    TIME COMPLEXITY:
        O(N*MAX(VALUE)*N)
*/
#include <bits/stdc++.h>
using namespace std;

#define DB(_x)      cout << #_x << " is " << (_x) << "\n";
#define FOR(_a,_b)  for (_a = 0; _a < _b; ++_a)
#define fs          first
#define sc          second
//#define IOFILE

using LL = long long;
using LD = long double;
using VI = vector<int>;
using PI = pair<int,int>;

void Excalibur(){
    int n, w, i, j;
    LL limit = 1e5+1;
    LL limitW = 1e12;
    while (cin >> n >> w){
        vector<PI> a(n);
        for (auto &x: a) cin >> x.fs >> x.sc;
        vector<LL> dp(limit,limitW);
        dp[0] = 0;
        FOR (i, n){
            for (j=limit-1; j>=0; --j){
                if (j-a[i].sc >= 0 && dp[j-a[i].sc] != limitW){
                    if (dp[j-a[i].sc] + a[i].fs <= w){
                        dp[j] = min(dp[j],dp[j-a[i].sc] + a[i].fs);
                    }
                }
            }
        }

        LL ans = 0;
        for (int i=0; i<limit; ++i){
            if (dp[i] <= w) ans = max(ans,1LL*i);
        }
        cout << ans << "\n";
    }
}

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

#ifdef  IOFILE
    freopen("INPUT.in", "r", stdin);
    freopen("OUTPUT.out", "w", stdout);
#endif

Excalibur();
return 0;}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x;
    cin >> n >> m >> x;
    int a[m];
    int r=0;
    int l=0;
    for(int i=0;i<m;i++){
        cin >> a[i];
        if(a[i]<x)l++;
        else r++;
    }
    if(l>r)cout << r << endl;
    else cout << l << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	multiset<int> mm;
	REP(i, 1<<N) {
		int s;
		scanf("%d", &s);
		mm.insert(s);
	}
	
	multiset<int> cm;
	cm.insert(*mm.rbegin());
	mm.erase(--mm.end());
	
	bool ans = true;
	while (ans && !mm.empty()) {
		multiset<int> nm;
		for (auto it = cm.rbegin(); it != cm.rend(); ++it) {
			auto tar = mm.lower_bound(*it);
			if (tar == mm.begin()) {
				ans = false;
				break;
			}
			else {
				--tar;
				nm.insert(*it);
				nm.insert(*tar);
				mm.erase(tar);
			}
		}
		cm = nm;
	}
	
	puts(ans ? "Yes": "No");
	
	
	return 0;
}

Measured memory_bytes: 24832
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
int main()
{
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  
  vector<int> times = {A, B, C, D, E};
  int last = *times.begin() % 10;
  int total_times = 0;
  
  for(auto i = times.begin(); i < times.end(); i++){
    
    if( last % 10 > *i % 10 && *i % 10 != 0 ){ last = *i % 10; } 
    
    if( *i % 10 == 0 ){ total_times += *i; } 
    else{ total_times += *i + (10 - (*i % 10)); }
    
    // cout << *i + (10 - (*i % 10)) << endl;
  }

  if( last == 0 ){ cout << total_times; }
  else{ cout << total_times - (10 - last); }
}

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

dp=[0]*(n)
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    c1=dp[i-1]+abs(h[i]-h[i-1])
    if i>=2:
        c2=dp[i-2]+abs(h[i]-h[i-2])
    dp[i]=min(c1,c2)
print(dp[-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vvs vector<vs>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
  int A, B;
  cin >> A >> B;
  if (A<=8 && B<=8) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, a[114514], b[114514];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	REP(i, n) {
		b[i] = a[i - 1] * 2 - b[i - 1];
	}
	int add = (a[n - 1] * 2 - b[n - 1]) / 2;
	rep(i, n) {
		if (i % 2 == 0)cout << b[i] + add << " ";
		else cout << b[i] - add << " ";
	}
}


Measured memory_bytes: 2944
import math
n = int(input())

num = int(math.sqrt(n))
div = []
for i in range(1, num+1):
  if n % i == 0:
    div.append([i, n//i])
  
ans = float('inf')
for i in div:
  temp = (i[0]-1) + (i[1]-1)
  if temp < ans:
    ans = temp
print(temp)

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Dice {
	public int[] value;
	public Dice(String[] info) {
		this.value = new int[6];
		for (int i = 0; i < value.length; i++) {
			this.value[i] = Integer.parseInt(info[i]);
		}
	}

	public int getTop( ) {
		return value[0];
	}

	public void rollingNorth() {
		int work = this.value[0];
		this.value[0] = this.value[1];
		this.value[1] = this.value[5];
		this.value[5] = this.value[4];
		this.value[4] = work;
	}

	public void rollingWest() {
		int work = this.value[0];
		this.value[0] = this.value[2];
		this.value[2] = this.value[5];
		this.value[5] = this.value[3];
		this.value[3] = work;
	}

	public void changeTop(int index) {
		if (index < 3) {
			rollingNorth();
		} else if (index == 3) {
			rollingWest();
		} else if (index == 4) {
			rollingWest();
			rollingWest();
		}
	}

	public void turn(String direction) {
		int work = 0;;
		if (direction.equals("S")) {
			// ?????????????¨??????¢
			work = this.value[1];
			this.value[1] = this.value[3];
			this.value[3] = this.value[4];
			this.value[4] = this.value[2];
			this.value[2] = work;
		} else {
			// ????????????????????¢
			work = this.value[0];
			this.value[0] = this.value[2];
			this.value[2] = this.value[5];
			this.value[5] = this.value[3];
			this.value[3] = work;
		}
	}

	public boolean isMatch(Dice target) {
		for (int i = 1; i < this.value.length; i++) {
			if (this.value[i] != target.value[i]) {
				return false;
			}
		}
		return true;
	}
}

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Dice dice1 = new Dice(br.readLine().split(" "));
		Dice dice2 = new Dice(br.readLine().split(" "));
		boolean isMatch = false;

		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 4; j++) {
				if (dice1.getTop() != dice2.getTop()) break;
				isMatch = dice1.isMatch(dice2);
				if (isMatch) break;
				dice2.turn("S");
			}
			if (isMatch) break;
			dice2.changeTop(i);
		}

		if (isMatch) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

long long gcd(long long a, long long b) {
  long long tmp;
  while ( a%b != 0 ) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

long long lcm(long long a, long long b) {
  return a * b / gcd(a, b);
}

int main() {
  long long a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,T,c,t; cin>>N>>T;
    map<int,int> m;
    rep(i,N){
        cin>>c>>t;
        m[c] = t;
    }
    for(auto itr = m.begin(); itr != m.end(); ++itr){
        // cout<<"cost = "<<itr->first<<", time = "<<itr->second<<endl;
        if(itr->second <= T){
            cout << itr->first << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
}


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

C = []
S = []
F = []
for i in range(N-1):
    cc,ss,ff=[int(i) for i in input().split()]
    #例えば[-y,x]とかにして正負とか左右とか入れ替えも可能です
    C.append(cc)
    S.append(ss)
    F.append(ff)

jikan = [0]*N
for i in reversed(range(N-1)):
    for j in range(i,N-1):
        jikan[i] = math.ceil(max(S[j],jikan[i])/F[j])*F[j] + C[j]
#    print(jikan)
for i in range(N):
    print(jikan[i])



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll


using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1e5 + 7;

int a[N], sum[N];

signed main()
{
	IO_OP;
	
	int n, M;
	cin >> n >> M;
	for (int i = 1; i <= n; i++)
		cin >> a[i];	
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + a[i];
	int l = 2, r = 2e5;
	while (l <= r) {
		int m = (l + r) / 2;
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			int pos = lower_bound(a + 1, a + n + 1, m - a[i]) - a - 1;
			cnt += n - pos;
		}
		if(cnt < M) r = m - 1;
		else l = m + 1;
	}
	int cnt = 0;
	int s = 0;
	for (int i = 1; i <= n; i++) {
		int pos = lower_bound(a + 1, a + n + 1, r - a[i]) - a - 1;
		cnt += n - pos;
		s += (sum[n] - sum[pos]) + a[i] * (n - pos);
	}		
	s -= (cnt - M) * r;
	cout << s << endl;
}





Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from collections import deque


def read():
    O = input().strip()
    E = input().strip()
    return O, E


def solve(O, E):
    ans = []
    oq = deque(O)
    eq = deque(E)
    while eq:
        ans.append(oq.popleft())
        ans.append(eq.popleft())
    if oq:
        ans.append(oq.popleft())
    return "".join(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9232
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int MOD = (int)1e9 + 7;
const int N = 3003;

int n, dp[N][N], pref[N], suf[N];
string s;

signed main() {
  init_ios();
  cin >> n >> s;
  dp[0][1] = 1;
  suf[1] = 1;
  for (int i = 1; i < N; ++i)
    pref[i] = i;
  for (int i = 1; i < n; ++i) {
    for (int v = 1; v <= i+1; ++v) {
      if (s[i-1] == '<')
        dp[i][v] = pref[v-1];
      else
        dp[i][v] = suf[v];
    }
    for (int v = 1; v <= i+1; ++v)
      pref[v] = (pref[v-1]+dp[i][v])%MOD;
    for (int v = i+1; v >= 1; --v)
      suf[v] = (suf[v+1]+dp[i][v])%MOD;
  }
  int res = 0;
  for (int v = 1; v <= n; ++v)
    res = (res+dp[n-1][v])%MOD;
  cout<<res<<"\n";
}

Measured memory_bytes: 69120
n, q = map(int, raw_input().split())
n0 = 2**n.bit_length()
INF = 2**31-1
data = [INF]*(n0*2)
def update(k, a):
    k += n0 - 1
    data[k] = a
    while k:
        k = (k - 1) / 2
        data[k] = min(data[2*k+1], data[2*k+2])
def query(a, b, k, l, r):
    if b <= l or r <= a:
        return INF
    if a <= l and r <= b:
        return data[k]
    vl = query(a, b, 2*k+1, l, (l + r) / 2)
    vr = query(a, b, 2*k+2, (l + r) / 2, r)
    return min(vl, vr)
def find(s, t):
    print query(s, t+1, 0, 0, n0)
for i in xrange(q):
    com, x, y = map(int, raw_input().split())
    [update, find][com](x, y)

Measured memory_bytes: 9300
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
int main()
{
    int n, k;
    while(~scanf("%d%d", &n, &k))
    {
        LL ans = 0;
        LL d = n/k;
        if(k & 1)
        {
            printf("%lld\n", d*d*d);
            continue;
        }
        ans += d*d*d;
        LL h = k/2;
        if(d*k + h <= n)
            d++;
        ans += d*d*d;
        printf("%lld\n", ans);
    }
    return 0;
}


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

typedef long long ll;
int N;
int A[100005];
ll ans;
 
int main(){
 
	cin>>N;
 
	for(int i=0; i<N; i++){
		scanf("%d",&A[i]);
	}

	int P=1;

	for(int i=0; i<N; i++){
		if(P<A[i]){
			if(A[i]%P==0){
				ans+=A[i]/P-1;
				A[i]=1;
			}
			else{
				ans+=A[i]/P;
				A[i]=A[i]%P;
			}
		}
		if(P==A[i]){
			P=A[i]+1;
		}
	}

	cout<<ans<<endl;
 
	return 0;
 
}

Measured memory_bytes: 640
from collections import deque
H, W = map(int, input().split())
CY, CX = map(lambda x: int(x)-1, input().split())
DY, DX = map(lambda x: int(x)-1, input().split())

gridgraph = [input() for _ in range(H)]
q = deque()
q.append([CY, CX])
# 更新されるなら追加
adjacent = [[1, 0], [0, 1], [-1, 0], [0, -1]]
INF = float("inf")
distant = [[INF]*W for _ in range(H)]
distant[CY][CX] = 0
visited = set()
while len(q):
    cy, cx = q.popleft()
    if (cy, cx) in visited:
        continue
    visited.add((cy, cx))
    for dy, dx in adjacent:
        ny, nx = cy+dy, cx+dx
        if ny < 0 or ny >= H or nx < 0 or nx >= W:
            continue
        if gridgraph[ny][nx] == "." and distant[ny][nx] > distant[cy][cx]:
            distant[ny][nx] = distant[cy][cx]
            q.appendleft([ny, nx])
    for i in range(-2, 3, 1):
        for j in range(-2, 3, 1):
            target_y, target_x = cy+i, cx+j
            if target_y < 0 or target_y >= H or target_x < 0 or target_x >= W:
                continue
            if gridgraph[target_y][target_x] == "." and distant[target_y][target_x] > distant[cy][cx]+1:
                distant[target_y][target_x] = distant[cy][cx]+1
                q.append([target_y, target_x])
if distant[DY][DX] == INF:
    print(-1)
else:
    print(distant[DY][DX])


Measured memory_bytes: 196088
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) (v).begin(),(v).end()
const ll MOD = 1e9 + 7;

int main() {
	string S;
	cin >> S;
	for (int i = 0; i < 3; i++) {
		if (S[i] == S[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main()
{
	while(1){
		int deg[128]={0},a,b;
		while(1){
			int f=scanf("%d%d",&a,&b);
			if(!~f)	return 0;
			if(a==0&&b==0)	break;
			deg[a]++;
			deg[b]++;
		}

		bool ok=(deg[1]%2==1)&&(deg[2]%2==1);
		for(int i=3;i<128;i++)	ok&=(deg[i]%2==0);
		puts(ok?"OK":"NG");
	}
}

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

using namespace std;

const int mod = (int) 1e9 + 7;
const int N = (int) 2e5 + 7;

void add(int& A, int B) {
    A += B;
    while (A >= mod) {
        A -= mod;
    }
}

int sub(int A, int B) {
    int res = A - B;
    while (res < 0) {
        res += mod;
    }
    return res;
}

int mult(int A, int B) {
    return (long long) A * B % mod;
}

int n;
int a[N];
int pref[N];

int get(int l, int r) {
    if (l) {
        return sub(pref[r], pref[l - 1]);
    }
    return pref[r];
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pref[i] = a[i];
        if (i) {
            add(pref[i], pref[i - 1]);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int sum = get(i + 1, n - 1);
        add(ans, mult(a[i], sum));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5212
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
int fcs(char x)
{
	int t;
	t=x;
	t-=48;
	return t;
}
int main()
{
	//48:'0'   57:'9'
	int a[99999],tint[1100],i,j,t,len,h;
	char tchar[1100];
	scanf("%s",tchar);
	t=tchar[0];
	while(t!=48)
	{
		
		i++;
		h=0;
		len=strlen(tchar);
		for(j=0;j<=len-1;j++)
			tint[j+1]=fcs(tchar[j]);
		for(j=1;j<=len;j++)
			h+=tint[j];
		a[i]=h;
		scanf("%s",tchar);
		t=tchar[0];
	}
	for(j=1;j<=i;j++)
		printf("%d\n",a[j]);
	return 0;
}


Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
 
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
 
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
 
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
 
#define pb(a) push_back(a)
 
ll n,m,k;
ll cnst=1000000007LL;

ll moddiv(ll a,ll b,ll c){
	ll x0=c;
	ll x1=b;
  ll x2;
	ll n0=0LL;
	ll n1=1LL;
  ll n2;
	ll t=a%b;
  ll m;
  ll ans;
	if (t==0) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=n0-m*n1;
      n2%=c;
      if (x2==1){
        ans=(n2+c)%c;
        break;
      }
      x0=x1;
      x1=x2;
      n0=n1;
      n1=n2;
    }
	ans=a+((t*ans)%c)*b-t;
	return ans/b;
}





 
int main(){
  ll ans=0LL;
  cin >> n >> m >> k;
  ll k2ans=0LL;
  REP(x,m){
    REP(y,n){
      ll x1=m-x-1;
      ll xline=x*(x+1)/2+x1*(x1+1)/2;
      ll y1=n-y-1;
      ll yline=y*(y+1)/2+y1*(y1+1)/2;
      k2ans+=xline*n+yline*m;
      k2ans%=cnst;
    }
  }
  
  k2ans=moddiv(k2ans,2LL,cnst);
  ll nmt=k2ans;
  k-=2;
  ll nm=n*m;

  REP(i,k){
    nmt=nmt*(nm-2-i);
    nmt%=cnst;
    nmt=moddiv(nmt,i+1,cnst);
  }
  
  ans=nmt;
  cout<<ans<<endl;
 
  return 0;
}

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

using namespace std;

int main()
{
    int N, M, nsum = 1, msum = 1;
    scanf("%d %d", &N, &M);
    if (N != 0)
    {
        nsum = N * (N-1) / 2;
    }
    else
    {
        nsum = 0;
    }
    
    if (M != 0)
    {
        msum = M * (M-1) / 2;
    }
    else
    {
        msum = 0;
    }
    
    printf("%d\n", nsum + msum);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<algorithm>
#include<vector>
using namespace std;
typedef complex < double > P;
typedef vector< P > G;
struct L:public vector< P >{ // L:線分
  L(const P& a,const P& b){push_back(a);push_back(b);}
};
const double EPS = 1e-8;
const double INF = 1e12;
namespace std{
  bool operator <(const P& a,const P& b){
    return  real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a,const P& b){
  return imag(conj(a) * b);
}
double dot(const P& a,const P& b){
  return real(conj(a) * b);
}
int ccw(P a,P b,P c){
  b -= a; c -= a;
  if(cross(b,c) > 0) return 1;
  if(cross(b,c) < 0) return -1;
  if(dot(b,c) < 0) return 2; // c--a--b
  if(norm(b) < norm(c)) return -2; // a--b--c
  return 0; // a--c--b
}
int n_covex_hull(vector<P> ps){
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  vector<P> ch(2*n);
  for(int i = 0 ; i < n ; ch[k++] = ps[i++] ){
    while(k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  }
  for(int i = n-2, t = k+1 ; i >= 0 ; ch[k++] = ps[i--] ){
    while(k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  }
  return k - 1;
}

int main(){
  int n;
  char o;
  while(cin >> n, n){
    vector< P > pts(n);
    for(int i = 0 ; i < n ; i++ ){
      cin >> pts[i].real() >> o >>pts[i].imag();
    }
    cout << n - n_covex_hull(pts) << endl;
  }
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int ninf = 0xc0c0c0c0;
int main(){
	string s;
	cin>>s;
	char c=s[s.length()-1];
	switch(c){
		case '2' :case '4': case '5': case '7': case '9': 
			cout<<"hon\n";
			break;
		case '3':
			cout<<"bon\n";
			break;
		default :cout<<"pon\n"; 
	}
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w,n; cin>>h>>w>>n;
	vector<vector<int>>ans(h,vector<int>(w));
	for(int i=1,y=0,x=0;i<=n;++i){
		int a; cin>>a;
		while(a){
			if(x==w)x=0,++y;
			ans.at(y).at(x)=i;
			--a,++x;
		}
	}
	for(int y=0;y<h;++y){
		if(y&1)for(int x=w-1;x>=0;--x){
			cout<<ans.at(y).at(x);
			if(x!=0)cout<<" "s;
		}else for(int x=0;x<w;++x){
			cout<<ans.at(y).at(x);
			if(x!=w-1)cout<<" "s;
		}
		cout<<"\n"s;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb                     push_back
#define ll                     long long int
#define fi                     first
#define se                     second
#define ii                     pair<long long int, long long int>
#define vi                     vector <long long int>
#define vii                    vector <pair <long long int, long long int > >
#define all(cont)              cont.begin(), cont.end()
#define EPS                    1e-9
#define MOD                    1000000007
#define range
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
 

int main(){
 
    IOS;
    clock_t clk = clock();
    // freopen("input.txt",  "r", stdin);
    // freopen("output.txt", "w", stdout);
 //map<char,int> m;
 int n;
 cin >> n;
 string s; cin >> s;
 int count=0;
if(s.size()>=1)count=1;
forn(i,n-1)
 {
 	if(s[i]!=s[i+1])
 	{
 		count++;
 	}
 }
 cout<<count;
    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll a,b;
cin>>a>>b;
if(a+b>9){
    cout<<"error"<<endl;
}else{
    cout<<a+b<<endl;
}
}









Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <random>
#include <iterator>
#include <cstring>
#include <deque>

//#include <bits/stdc++h>

#define ll long long

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll X;
    cin >> X;
    ll ans = 0;
    ans += (X / 500) * 1000;
    X %= 500;
    ans += (X / 5) * 5;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <string>

using namespace std;

// stringをlong intに
// string a = "123";
// stoi(a)
//
// long intをstringに
// long int a = 123;
// to_string(a)
//
// charをlong intに
// char a = '1';
// (long int)a - 48 // asciiコードを値にする

// stringのソート
// string str = "abccba";
// sort(str.begin(), str.end());
//
// ハッシュテーブル
// unordered_map<string, long int> mp;
// mp["aabbcc"] = 0;

// 配列Aにcinする
int main() {
  long int N;
  cin >> N;
  vector<long int> B(N-1);
  for (long int i = 0; i < N-1; i++) {
    cin >> B.at(i);
  }

  vector<long int> A(N);
  A.at(0) = B.at(0);
  for (long int i = 0; i < N-1; i++) {
    if (i+1 < N-1) {
      if (B.at(i+1) == B.at(i)) {
        A.at(i+1) = B.at(i+1);
      }

      if (B.at(i+1) < B.at(i)) { // TODO: error handling
        A.at(i+1) = B.at(i+1);
      }

      if (B.at(i+1) > B.at(i)){ // エッジケースで死にそう
        A.at(i+1) = B.at(i);
        //if (i+2 < N-1) {
        //  if (B.at(i+2) >= B.at(i+1)) {
        //    A.at(i+1) = B.at(i+1);
        //  } else {
        //    A.at(i+1) = B.at(i+2);
        //  }
        //} else {
        //  A.at(i+1) = A.at(i);
        //}
      }
    } else {
      A.at(i+1) = B.at(i);
    }
  }

  long int sum = 0;
  for (long int i = 0; i < N; i++) {
    sum += A.at(i);
  }
  cout << sum << endl;

  return 0;
}

// 標準入出力
//long int main() {
//	long int a, b;
//	cin >> a >> b;
//  if (a * b % 2 == 0) {
//	  cout << "Even" << endl;
//  } else {
//	  cout << "Odd" << endl;
//  }
//  return 0;
//}

// 文字列を1文字ずつループ
//long int main() {
//  string str;
//  cin >> str;
//  long int sum = 0;
//  for(long int i = 0; i < (long int)str.size(); ++i){
//    char ch = str[i];
//
//    if (ch == '1') {
//      sum++;
//    }
//  }
//  cout << sum << endl;
//  return 0;
//}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;

int main() {
    string s;
    cin >> s;
    rep(i,s.size()){
        if (s[i]=='?') s[i]='D';
    }
    cout << s << endl;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    I vec;
    CIN(N);
    double ans = 0;
    REP(a,N){
        CIN(B);
        ans +=B;
        vec.push_back(B);
    }
    ans /= N;
    double ins = INF;
    int A = 0;
    REP(a,N){
        if(abs(1.0 * vec.at(a) - ans) < ins){
            A = a;
            ins = abs(1.0 * vec.at(a) - ans);
        }
    }
    COUT(A);
    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0);
    int a, b;
    cin >> a >> b;
    
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9)
        cout << a * b;
    else
        cout << -1;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   IOS;
   int a[10][10];
   bool p[10][10];
   MEM(p,0);
   for(int i=1;i<=3;i++){
       for(int j=1;j<=3;j++){
           cin >> a[i][j];
           //p[i][j]=1;
       }
   }
   int n;
   cin >> n;
   
   for(int i=1,x;i<=n;i++){
       cin >> x;
       bool o=0;
       for(int j=1;j<=3;j++){
           for(int k=1;k<=3;k++){
               if(a[j][k]==x){
                   p[j][k]=1;
                   o=1;
                   break;
               }
           }
           if(o==1)break;
       } 
   }
   bool pp=0;
   if(p[1][1]==1&&p[2][2]==1&&p[3][3]==1)pp=1;
   if(p[1][3]==1&&p[2][2]==1&&p[3][1]==1)pp=1;
   if(p[1][1]==1&&p[1][2]==1&&p[1][3]==1)pp=1;
   if(p[2][1]==1&&p[2][2]==1&&p[2][3]==1)pp=1;
   if(p[3][1]==1&&p[3][2]==1&&p[3][3]==1)pp=1;
   if(p[1][1]==1&&p[2][1]==1&&p[3][1]==1)pp=1;
   if(p[1][2]==1&&p[2][2]==1&&p[3][2]==1)pp=1;
   if(p[1][3]==1&&p[2][3]==1&&p[3][3]==1)pp=1;
   if(pp==1)cout<<"Yes";
   else
   {
       cout<<"No";
   }
   
}


Measured memory_bytes: 256
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from heapq import heappush,heappop
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
# mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file=0




def f(x,y,z):
    return (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x)
def solve():


    # for _ in range(ii()):
    
        

    n=ii()
    ans=[0]*(n+1)
    for i in range(1,n+1):
        for j in range(1,n+1):
            if f(i,j,1)>n:
                break
            for k in range(1,n+1):
                x=f(i,j,k)
                if x>n:
                    break
                ans[x]+=1

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





        
if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):
            sys.stdin=open('input1.txt', 'r')
            sys.stdout=open('output1.txt','w')
        else:
            input=sys.stdin.readline
    solve()


Measured memory_bytes: 75264
from collections import Counter
mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n, k = map(int, input().split())
    s = input()
    cnt = 0
    for i in range(n-1):
        if s[i] != s[i+1]:
            cnt += 1
    ans = n - 1 - cnt
    while cnt >= 2 and k > 0:
        ans += 2
        cnt -= 2
        k -= 1

    if k > 0 and cnt > 0:
        ans += 1

    print(ans)

main()


Measured memory_bytes: 39408
def main():
    n, m = [int(x) for x in input().strip().split()]

    # 正解したかどうか
    flag = [False] * n
    # AC までの挑戦数
    trial = [0] * n
    for _ in range(m):
        tmp = input().strip().split()
        idx = int(tmp[0])-1
        # すでに AC を出している場合
        if flag[idx]:
            continue
        # AC だった場合
        flag[idx] = (tmp[1] == "AC")
        if flag[idx]:
            continue
        # WA とか
        trial[idx] += 1

    # AC
    pen = 0
    for f, t in zip(flag, trial):
        if not f:
            continue
        pen += t

    print(flag.count(True), pen)


if __name__ == "__main__":
    main()


Measured memory_bytes: 46808
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()))

    if N == 1:
        print(0)
        exit()

    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: 24912
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  if(n > m) {
    int tmp;
    tmp = n;
    n = m;
    m = tmp;
  }
  for(int i=0; i < m; i++) {
    cout << n;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;

int main() {
	int n;
	int i;
	vector<long long> fib;
	scanf("%d",&n);
	fib.resize(n+1);
	fib[0]=fib[1]=1;
	for(i=2; i<=n; ++i) {
		fib[i]=fib[i-1]+fib[i-2];
	}
	printf("%lld\n",fib[n]);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for(int i = 0; i < (int)(n) ; i++)

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

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


void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B) {
    vector <pair<ll, ll>> ps;
    for (int i = 0; i < N; i++) {
        ps.push_back({A[i], B[i]});
    }
    sort(ps.rbegin(), ps.rend());

    priority_queue<long long> Q;
    long long ans = 0;
    for (int i = M - 1; i >= 0; i--) {
        while (ps.size() && i + ps.back().first <= M) {
            Q.push(ps.back().second);
            ps.pop_back();

        }
        if (Q.size()) {
            ans += Q.top();
            Q.pop();
        }
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}



Measured memory_bytes: 5232
import itertools

def resolve():
	l,r=map(int,input().split())
	k=min(r+1,l+2020)
	lst=[i%2019 for i in range(l,k)]
	if 0 in lst:
		ans=0
	elif 673 in lst:
		if len(lst)>3:
			ans=0
		elif 672 in lst or 675 in lst:
			ans=0
		else:
			ans=1346
	else:
		ans=min([(i[0]*i[1])%2019 for i in list(itertools.combinations(lst,2))])
	
	print(ans)
resolve()

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

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

    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    int cnt = 1, ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == cnt) cnt++;
        else ans++;
    }

    cout << (ans == n ? -1 : ans) << endl;
    return 0;
}

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

int main(){
	string s ; 
	cin >> s ; 
	int n = 3 ; 
	for(int mask=0;mask<(1<<n);mask++){
		int ans = s[0] - '0' ; 
		for(int j=0;j<n;j++){
			if ( (1<<j) & mask ){
				ans += s[j+1]-'0' ; 
			}
			else 
				ans -= s[j+1]-'0' ; 
		}
		if ( ans == 7 ){
			cout << s[0] ; 
			for(int j=0;j<n;j++){
				if ( (1<<j) & mask ){
					cout << "+" << s[j+1] ;
				}
				else 
					cout << "-" << s[j+1] ; 
			}
			cout << "=7" << endl;
			return 0 ; 
		}
	}
	return 0 ; 
}

Measured memory_bytes: 256
N, M = map(int, input().split())
k, s = [], []
for _ in range(M):
  t =list(map(int, input().split()))
  k.append(t[0])
  s.append(t[1:])
p = list(map(int, input().split()))

def all_on(i: int):
  for j in range(M):
    count = 0
    for sw in s[j]:
      if i & (1<<(sw-1)):
        count += 1
    if count%2 != p[j]:
      return False
  return True

ans = 0
for i in range(1<<N):
  if all_on(i):
    ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int a = Integer.parseInt(line1[0]);
        int b = Integer.parseInt(line1[1]);
        int max = a + b;
        int d = a - b;
        if(d > max) max = d;
        int e = a * b;
        if(e > max) max = e;
        System.out.println(max);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,count=0;
  cin>>n>>k;
  int h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
    if(h[i]>=k)
        count++;
  }
  cout<<count<<"\n";
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
    int x,y;
    
    while(1){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0){
            break;
        }
        if(x < y){
            printf("%d %d\n",x,y);
        }else{
            printf("%d %d\n",y,x);
        }
    }
    return(0);
}


Measured memory_bytes: 2036
N, M = map(int, input().split())
*X, = map(int, input().split())
X.sort()

ans = 0
if N < M:
    L = []

    for i in range(M-1):
        L.append(X[i+1] - X[i])

    L.sort()
    for i in range(M-N):
        ans += L[i]
print(ans)

Measured memory_bytes: 13968
n,d,a= map(int, input().split( ))
ms = []
for i in range(n):
    xi,hi = map(int, input().split( ))
    tmp = 0
    if hi%a:
        tmp+=1
    ms.append([xi,hi//a+tmp])

ms.sort()
ans = ms[0][1]
tmp = ms[0][1]
from collections import deque

Q = deque()
Q.append(0)

for i in range(1,n):

    while Q:###ifから変更
        tmp2 = Q.popleft();
        if ms[tmp2][0]+2*d<ms[i][0]:###tmpじゃないわms[tmp2][0]だわ
            tmp -= ms[tmp2][1]
        else:
            Q.appendleft(tmp2)
            break###
    ms[i][1]-=tmp###
    ms[i][1] = max(ms[i][1],0)###

    if ms[i][1]>0:
        #ms[i][1]-=tmp　二回引いてるわ
        ans += ms[i][1]
        Q.append(i)
        tmp += ms[i][1]
print(ans)


Measured memory_bytes: 83084
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define debug(var) do{cout << #var << " : "; print(var); } while(0)
using namespace std;
typedef long long ll;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }
const int INF = 1e9;
const int MOD = 1e9+7;

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

	int N; cin >> N;
	set<int> A;
	rep(i, N) {
		int x; cin >> x;
		// print(x);
		// print(A.count(x));
		if (!A.count(x)) {
			A.insert(x);
		} else {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

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

int main(){
	int n,a,b;cin>>n>>a>>b;
	string s;cin>>s;
	int pass=0,bpass=0;
	for(int i=0;i<n;i++){
		if(s[i]=='a'){
			if(pass<a+b){
				cout<<"Yes"<<endl;
				pass++;
			}else{
				cout<<"No"<<endl;
			}
		}else if(s[i]=='b'){
			if(pass<a+b&&bpass<b){
				cout<<"Yes"<<endl;
				pass++;bpass++;
			}else{
				cout<<"No"<<endl;
			}
		}else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3752
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int n, x;
	cin >> x >> n;
	int a[n];
	int mn = 10000000;
	int an = -1;
	int is[201] = {};
	for (int i = 0; i < n; i++)
		cin >> a[i], is[a[i]] = true;
	for (int i = 0; i <= 200; i++){
		if (is[i])
			continue;
		if (abs(i - x) < mn){
			mn = abs(i - x);
			an = i;
		}
	}
	cout << an;
}


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

using namespace std;
    vector<int> eratosu(12000710,1);

    int solve(int N){
        if(eratosu[N] == 1)return 0;
        int upIndex;
        for(upIndex = N; eratosu[upIndex] == 0; upIndex++);
        int dind = 0;
        for(dind = N; eratosu[dind] == 0; dind--);
        return upIndex - dind;
    }

int main(){

    eratosu[0] = 0;
    eratosu[1] = 0;

    for(int i = 2; i < eratosu.size(); i++){
        if(eratosu[i] == 1){
            for(int j = 2; j * i < eratosu.size(); j++){
                eratosu[i*j] = 0;
            }
        }
    }

    int N;
    vector<int> ans;
    while(1){
        cin>>N;
        if(!N)break;
        ans.push_back(solve(N));
    }

    for(int i : ans)cout<<i<<endl;
}


Measured memory_bytes: 49620
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n";
using namespace std;
using ll=long long;
using ld=long double;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) for (auto vvv : vv) cout << vvv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

using dbg::Debug;
Debug debug;

class BPopularVote {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll n, m;
	    in >> n >> m;
	    vector<ll> a(n);
	    ll cnt = 0;
	    ll sum = 0;
	    for(int i=0; i<n; i++){
	        in >> a[i];
	        sum += a[i];
	    }

	    for(int i=0; i<n; i++){
            if(a[i]*4*m >= sum) cnt++;
	    }

	    ans(cnt >= m, out);
	}
};


int main() {
	BPopularVote solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256