akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int const MAXN = 500;
int N, K, A[MAXN], tmp[MAXN], sum;

bool isOK(int v) {
  if(sum%v != 0) return false;
  int tsum = 0;
  for(int i = 0; i < N; ++i) tsum += (tmp[i] = A[i]%v);
  std::sort(tmp, tmp+N);
  int n = N - tsum/v;
  int x = 0;
  for(int i = 0; i < n; ++i) x += tmp[i];
  return x <= K;
}

int main() {
  N = getZ(); K = getZ(); sum = 0;
  for(int i = 0; i < N; ++i) sum += (A[i] = getZ());
  std::vector<int> divisors;
  for(int i = 1; i*i <= sum; ++i) {
    if(sum%i != 0) continue;
    divisors.push_back(i);
    if(i*i != sum) divisors.push_back(sum/i);
  }
  std::sort(divisors.begin(), divisors.end(), std::greater<int>());
  for(int i: divisors) if(isOK(i)) fin(i);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <utility>
#include <queue>
using namespace std;

using Graph = vector<vector<int>>;

bool bfs(const Graph& G, int n){
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));

    while(!q.empty()){
        int v = q.front().first;
        int cost = q.front().second;
        q.pop();

        for(auto u : G[v]){
           if(cost+1 == 2 && n == u) return true; 
           if(cost < 2){
                q.push(make_pair(u, cost+1));
           }
        }
    }

    return false;
}

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

    Graph G(n);
    n--;

    for(int i = 0; i < m; ++i){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
    }

    if(bfs(G, n)) cout << "POSSIBLE\n";
    else cout << "IMPOSSIBLE\n";

    return EXIT_SUCCESS;
}


Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	string n;
	cin >> n;
	int len = n.length();

	vector<vector<int>> dp(2, vector<int>(len+1));
	{
		
		dp[0][0] = 0;
		dp[1][0] = 1;
	}
	for (int i = 0; i < n.length();i++) {
		int num = n[i] - '0';
		int m = min(dp[0][i], dp[1][i]);
		dp[0][i + 1] = m + num;
		int pay = (num == 9 ? 2 : num + 2);
		dp[1][i + 1] = min(m + pay, dp[1][i] + (10 - (num)) - (i == 0 ? 0 : 1));
		//cout << dp[0][i + 1] << " " << dp[1][i + 1] << endl;
	}

	cout << min(dp[0][len], dp[1][len]) << endl;
}



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

template<class T>
struct SegmentTree {
private:
    int n;
    T def;
    vector<T> node;
public:
    SegmentTree(int sz, T _def) {
        def = _def;
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2 * n - 1, def);
    }
    void update(int x, T val) {
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = max(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    T getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return node[k];
        T vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
};

int main() {
    int N; cin >> N;
    vector<int> H(N), A(N);
    for(int i = 0; i < N; ++i) cin >> H[i];
    for(int i = 0; i < N; ++i) cin >> A[i];
    SegmentTree<long long> dp(N + 1, 0);
    for(int i = 0; i < N; ++i) {
        long long a = dp.getmax(0, H[i]) + A[i];
        long long b = dp.getmax(H[i], H[i]);
        dp.update(H[i], max(a, b));
    }
    cout << dp.getmax(0, N + 1) << endl;
    return 0;
}


Measured memory_bytes: 6016
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int N,M;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		N = nextInt();
		long [][]LR = new long [N][3];
		long [][]l=new long[N][2],r=new long[N][2];
		for(int i=0;i<N;i++) {
			LR[i][0]=nextLong();
			LR[i][1]=nextLong();
			LR[i][2]=LR[i][1]-LR[i][0]+1;
			l[i][0] = LR[i][0];
			r[i][0] = LR[i][1];
			l[i][1] = i;
			r[i][1] = i;
		}
		Arrays.sort(l,(a1,a2)->Long.compare(a2[0],a1[0]));
		Arrays.sort(r,(a1,a2)->Long.compare(a1[0],a2[0]));

		long []onesum = new long[N];
		for(int i=0;i<N;i++) {
			long L = l[0][0];
			long R = r[0][0];
			if(l[0][1]==i)L = l[1][0];
			if(r[0][1]==i)R = r[1][0];
			long abs = R-L+1;
			if(abs <= 0)abs = 0;
			onesum[i]=LR[i][2]+abs;
		}
		Arrays.sort(onesum);

		Arrays.sort(LR,(a1,a2)->MyComparator(a1[0],a2[0],a1[1],a2[1]));
		Arrays.sort(LR,(a1,a2)->absComp(a1[0],a2[0],a1[1],a2[1]));
		long L = LR[0][0];
		long R = LR[0][1];
		long Abs = R - L + 1;
		long []lrA = new long[N];
		lrA[0] = Abs;
		for(int i=1;i<N-1;i++) {
			L=Math.max(L,LR[i][0]);
			R=Math.min(R,LR[i][1]);
			long abs = R-L+1;
			if(abs <= 0)break;
			lrA[i] = abs;
		}
		long [] lrB = new long [N];
		L = LR[N-1][0];
		R = LR[N-1][1];
		for(int i=N-1;i>0;i--) {
			L=Math.max(L,LR[i][0]);
			R=Math.min(R,LR[i][1]);
			long abs = R-L+1;
			if(abs <= 0)break;
			lrB[i] = abs;
		}

		long max = onesum[N-1];
		for(int i=0;i<N-1;i++) {
			max = Math.max(max, lrA[i]+lrB[i+1]);
		}
		out.println(max);

	}


	private int absComp(long a1, long a2, long b1, long b2) {
		if(b1 - a1 < b2 - a2)return 1;
		if(b1 - a1 > b2 - a2)return -1;
		return 0;
	}

	private int MyComparator(long a1, long a2, long b1, long b2) {
		if(a1 > a2) return 1;
		else if(a1 < a2) return -1;
		if(b1 > b2) return 1;
		else if(b1 < b2) return -1;
		return 0;
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

Measured memory_bytes: 72956
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int K;
	cin >> K;
	if (s == "1") {
		cout << 1 << endl;
		return 0;
	}
	int ind = 0;
	REP(i, SZ(s)) {
		if (i + 1 == K) {
			cout << s[i] << endl;
			break;
		}
		if (s[i] != '1') {
			cout << s[i] << endl;
			break;
		}
	}
	PAU;
	return 0;
}


Measured memory_bytes: 504
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner stdin=new Scanner(System.in);
		int  a=stdin.nextInt();
		int  b=stdin.nextInt();
		int  c=stdin.nextInt();
		int  d=stdin.nextInt();
		int l=a+b;
		int r=c+d;

		if(l>r)
			System.out.println("Left");
		else if(l<r)
			System.out.println("Right");
		if(l==r)
			System.out.println("Balanced");
	}
}

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

ll val[10][10];
ll n;
int len;

int get_dig(ll k) {
  int cnt = 1;
  while ((k /= 10) != 0) ++cnt;
  return cnt;
}

void set_val() {
  ll p = 1;
  for (int i = len-1; i >= 0; --i) {
    p *= 10;
    val[i][len-1] = n % p;
  }
  for (int i = len-1; i >= 0; --i) {
    for (int j = len-2; j >= i; --j) {
      val[i][j] = val[i][j+1] / 10;
    }
  }
}

ll dfs(int l, int d) {
  if (d == len) return 0;
  ll t = max(1, (int)pow(2, len-d-2));
  return (t * val[l][d] + dfs(d+1, d+1) ) + dfs(l, d+1);
}

int main() {
  cin >> n;
  len = get_dig(n);
  set_val();
  ll ans = dfs(0, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 2 * (int)1e5 + 10;
int a[maxN];
int n;
int main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] -= i;
    }
    sort(a + 1, a + n + 1);
    int val = a[(n + 1) / 2];
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += abs(a[i] - val);
    }
    cout << ans;
	return 0;
}


Measured memory_bytes: 1024
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

#define amen ;
#define vec vector
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()

typedef long long ll;
typedef double d;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;
typedef unsigned int ui;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);

    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int cnt = 0;

		for(int i=0; i<n; i++){
			int t = sc.nextInt();
			if(t<a || t>=b) cnt++;
		}

		System.out.println(cnt);
	}
}

Measured memory_bytes: 9808
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define all(c) c.begin(), c.end()
#define pb push_back
#define ll long long
#define ull unsigned long long
const int MAXN = 1e3 + 5;
const int MOD = 1e9 + 7;
using namespace std;

int main()
{

int n,k;
cin >> n >> k;
string s;
cin >> s;
s[k-1]=tolower(s[k-1]);
cout << s;




} 

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;
  int k=-0;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);


  /* your code */
  for(i=1;i<=n;i++)
  {
  	scanf("%d",&A[i]);
  	if(k<A[i])
  	{
  		k=A[i];
  	}
  }
  	for(i=0;i<=k;i++)
  	{
  		C[i]=0;
  	}
  	for(j=1;j<=n;j++)
  	{
  		C[A[j]]++;
  	}
  	for(i=1;i<=k;i++)
  	{
  		C[i]+=C[i-1];
  	}
  	for(j=n;j>=1;j--)
  	{
  		B[C[A[j]]]=A[j];
  		C[A[j]]--;
  	}
	
  	for(i=1;i<=n;i++)
  	{
  		if(i==1)
  		{
  			printf("%d",B[i]);
  			
  		}
  		else
  		{
  			printf(" %d",B[i]);
  		}
  	}	
  		printf("\n");
  	
  return 0;
}


Measured memory_bytes: 9564
//ΔABC129F
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
int m;
LL d;
int mul(int x,int y){
	return (LL)x*y%m;
}
int fpow(LL x,LL y){
	int z=1;
	x%=m;
	while(y){
		if(y&1)
			z=mul(z,x);
		y>>=1;
		x=mul(x,x);
	}
	return z;
}
pair<int,int> solve(LL w,int o){
	if(w==1)
		return make_pair(1,0);
	int a,b,e=fpow(o,w/2);
	pair<int,int> p=solve(w/2,o);
	a=p.first,b=p.second;
	p.first=mul(a,e+1);
	p.second=(mul(b,e+1)+mul(a,(w/2)%m))%m;
	if(w&1){
		a=p.first,b=p.second;
		p.first=(mul(a,o)+1)%m;
		p.second=(b+a)%m;
	}
	return p;
}
int main()
{
	LL w,l,r,o,a,b,c,s;
	int i;
	pair<int,int> p;
	cin>>w>>l>>r>>m;
	d=r;
	r=l+d*(w-1);
	s=0;
	o=1;
	for(i=0;i<18;i=i+1){
		a=max(l,o);
		a+=(l%d-a%d+d)%d;
		b=min(r,o*10-1);
		b-=(b%d-r%d+d)%d;
		o*=10;
		if(a>b)
			continue;
		c=(b-a)/d+1;
		s=mul(s,fpow(o,c));
		p=solve(c,o%m);
		s+=mul(a%m,p.first);
		s+=mul(d%m,p.second);
		s%=m;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a[6], i, j, f_1=0;

    for(i=0; i<6; i++) {
        scanf("%d", &a[i]);
    }

    for(i=0; i<5; i++) {
        for(j=5; j>0; j--) {
            if(i>=j) {
                break;
            }
            if(a[j] - a[i] > a[5]) {
                f_1 = -1;
                break;
            }
        }
        if(f_1!=0) {
            break;
        }
    }

    if(f_1==0) {
        printf("Yay!\n");
    } else if (f_1==-1) {
        printf(":(\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> cs(n);
  for(int i=0;i<n;i++) cin>>cs[i];
  sort(cs.rbegin(),cs.rend());

  using M = Mint<int>;
  if(n==1) drop(M(cs[0])*M(2));

  M ans{0};
  for(int i=0;i<n;i++)
    ans+=M(2).pow(n-2)*M(i+2)*M(cs[i]);
  ans*=M(2).pow(n);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
sw = 0
count = 1
for i in range(n-1):
    if sw == 1:
        if a[i+1]<a[i]:
            sw = 0
            count += 1
    elif sw == -1:
        if a[i+1]>a[i]:
            sw = 0
            count += 1
    else:
        if a[i+1]>a[i]:
            sw = 1
        elif a[i]>a[i+1]:
            sw = -1
print(count)

Measured memory_bytes: 14252
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo[100005] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	cin >> s;
	char x;
	x = s[0];
	for (int i = 1; i < s.length(); i++)
	{
		if (x!=s[i])
		{
			ans++;
		}
		x = s[i];
	}
	cout <<ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int string_length = 0;
    int string_num = 0;

    //input the number of strings and its lengths
    cin >> string_num >> string_length;

    //input strings
    vector<string> str_vec;
    string str_temp;
    for(int i = 0; i < string_num; i++){
        cin >> str_temp;
        str_vec.push_back(str_temp);
    }
    //sort the strings ascending order
    sort(str_vec.begin(), str_vec.end());

    //merge the sorted strings
    string str_result;
    vector<string>::iterator it = str_vec.begin();
    for(; it != str_vec.end(); it++){
        str_result += *it;
    }

    cout << str_result << endl;

}


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


signed main() {
  int N;
  cin >> N;
  int A = N / 1000;
  int B = ( N / 100 ) % 10;
  int C = ( N / 10 ) % 10;
  int D = N % 10;
  
  if( A+B+C+D == 7 ){
    cout << A << "+" << B << "+" << C << "+" << D << "=7" <<endl;
  }else if( A+B+C-D == 7 ){
    cout << A << "+" << B << "+" << C << "-" << D << "=7" <<endl;
  }else if( A+B-C+D == 7 ){
    cout << A << "+" << B << "-" << C << "+" << D << "=7" <<endl;
  }else if( A+B-C-D == 7 ){
    cout << A << "+" << B << "-" << C << "-" << D << "=7" <<endl;
  }else if( A-B+C+D == 7 ){
    cout << A << "-" << B << "+" << C << "+" << D << "=7" <<endl;
  }else if( A-B+C-D == 7 ){
    cout << A << "-" << B << "+" << C << "-" << D << "=7" <<endl;
  }else if( A-B-C+D == 7 ){
    cout << A << "-" << B << "-" << C << "+" << D << "=7" <<endl;
  }else if( A-B-C-D == 7 ){
    cout << A << "-" << B << "-" << C << "-" << D << "=7" <<endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
const ll MOD = 1000000007;
//const ll MOD = 998244353;

int main() {
	ll N, T;
	cin >> N >> T;
	vector<ll> Ts(N);
	for (int i = 0;i < N;i++) {
		cin >> Ts[i];
	}
	ll ans = 0;
	for (int i = 1;i <= N;i++) {
		if (i == N)ans += T;
		else ans += min(T, Ts[i] - Ts[i - 1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int n,m;
vvp G;
vi used;
int out=0;
int f(){
	int sum=0;
	rep(i,n)if(used[i]){
		int mi=inf;
		rep(j,G[i].size())if(used[G[i][j].first])mi=min(mi,G[i][j].second);
		if(mi==inf)mi=0;
		sum+=mi;
	}
	// cout<<sum<<endl;
	// show1d(used);
	return sum;
}
map<pii,int>ma;
void dfs(int a){
	if(a==n)return ;
	bool H=true;
	rep(j,a)if(used[j]&&ma[{a,j}]==0)H=false;
	dfs(a+1);
	if(H){
		used[a]=1;
		out=max(out,f());
		dfs(a+1);
		used[a]=0;
	}
}
int main(){
	cin>>n>>m;
	G=vvp(n);
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		G[a].pb({b,c});
		G[b].pb({a,c});
		ma[{a,b}]=1;
		ma[{b,a}]=1;
	}
	used=vi(n);
	dfs(0);
	cout<<out<<endl;
}

/*
int n;
vvi in;
map<pii,int>ma;
bool dfs(int a){
	rep(i,n+1){
		if(i==n)return true;
		if(in[i][3]==0){
			
		}
	}
}
int main(){
	while(cin>>n,n){
		in=vvi(n,vi(4));
		ma.clear();
		rep(i,n){
			int a,b;
			char c;
			cin>>a>>b>>c;
			in[i]={a,b,c=='y',0};
			ma[{a,b}]=i+1;
			if(c=='x')a++;
			else b++;
			ma[{a,b}]=i+1;
		}
		if(dfs(0))cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}
*/








Measured memory_bytes: 3444
//AtCoder ABC093 C - Same Integers
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    vector<ll> abc(3);
    cin>>abc[0]>>abc[1]>>abc[2];
    sort(abc.begin(),abc.end());
    ll dif0=abc[2]-abc[1];
    ll dif1=abc[2]-abc[0]; //こっちがおおきい
    ll ans=dif0;
    dif1-=dif0;
    ans+=(dif1/2);
    if(dif1%2==1)ans+=2; //残りがあるなら+2
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define setpre(a) cout.precision(a),cout<<fixed;
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

int n;
string s;
map<string, int> m;

int main() {Tie
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << '\n';
    cout << "WA x " << m["WA"] << '\n';
    cout << "TLE x " << m["TLE"] << '\n';
    cout << "RE x " << m["RE"] << '\n';
}


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

int main(){
  int x, n;
  cin >> x >> n;
  set<int> p;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    p.insert(a);
  }
  
  int ans = 100000;
  for(int i = -1; i < 102; i++){
    if(p.count(i)) continue;
    if(abs(x-i) < abs(x-ans)) ans = i;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
//using System.Linq;
class Program
{
  //static List<string> list;
	static void Main(string[] args)
	{
		// 入力フェーズ
        int N = int.Parse(Console.ReadLine());
        int[] t = new int[N];

        for(int i=0; i<N; i++)
        {
          t[i] = int.Parse(Console.ReadLine());
        }

        // 最大値と合計値をだす
        int max = 0, sum = 0;
        for(int i=0; i<N; i++)
        {
          if(max < t[i])
            max = t[i];

          sum += t[i];
        }

        int ret = sum - max/2;
        
    // 出力
        Console.WriteLine(ret);
    }
		class myClass{ //自作クラス
			public int ID {set; get;}
			public long Point {set; get;}
		}
    static private int getMaxPoint(int solve, int[,] table)
    {
      int ret = 0;

      return ret;
    }

}


Measured memory_bytes: 11092
//
// Created by rknguyen on 4/28/18.
//

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

bool myUnique(int i, int j) {
    return (i == j);
}

map < long long, int > m;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n; cin >> n;
    vector <int> a(n + 1);
    vector <long long> s(n + 1, 0), sums;


    sums.push_back(0);
    m[0] = 1;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
        ++ m[s[i]];
        sums.push_back(s[i]);
    }

    vector <long long> b;
    /*int ll = sums.size();
    sort(sums.begin(), sums.end());
    for (int i = 0; i < sums.size(); ++i) {
        long long val = sums[i];
        b.push_back(m[val]);
        int j = i + 1;
        while (sums[j] == val && j < ll)
            ++j;
        i = j;
    }*/
    sort(sums.begin(), sums.end());
    vector<long long>::iterator it;
    it = unique(sums.begin(), sums.end());
    sums.resize(distance(sums.begin(),it));

    for (int i = 0; i < (int) sums.size(); ++i)
        b.push_back(m[sums[i]]);

    sort(b.begin(), b.end());

    int sz = b.size();
    long long res = 0;
    for (int i = 0; i < sz; ++i) {
        if (b[i] < 2) continue;
        res += (b[i] * (b[i] - 1)) / 2LL;
    }

    cout << res << endl;
}

Measured memory_bytes: 19696
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define FLOOR(x) ((int)floor(((double)x)))
#define CEIL(x) ((int)ceil(((double)x)))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mt make_tuple
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


int Q;
llint A, B;


bool judge(llint m){
	repe(i, m/2-2, m/2+2){
		if(i < 0 || B-A < i) continue;
		if((A+i)*(A+m-i) >= A*B) return false;
	}
	return true;
}


llint solve(){
	if(A > B) swap(A, B);
	llint ans = 2*(A-1);
	llint l = 0, r = B-A+1;
	while(r - l > 1){
		llint m = l+(r-l)/2;
		if(judge(m)) l = m;
		else r = m;
	}
	return ans+l;
}


signed main(){
	cin >> Q;

	rep(i, 0, Q) cin >> A >> B, cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define INF (1 << 30) - 1

int main(){
	int a[6] = {2, 3, 5, 10, 12, 15}, dp[51], n;
	int b[6] = {380, 550, 850, 1520, 1870, 2244};
	for(int i = 0;i < 51;i++)dp[i] = INF;
	dp[0] = 0;
	
	for(int i =  0;i <= 50;i++){
		for(int j = 0;j < 6;j++){
			if(i >= a[j])dp[i] = min(dp[i], dp[i-a[j]] + b[j]);
		}
	}
	while(cin >> n, n)cout << dp[n/100] << endl;
	return 0;
}

Measured memory_bytes: 2980
#include <stdio.h>

int main(void){

	int a, b;

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

	if(a < b){
		printf("a < b\n");
	}else if(a > b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}

	return 0;
}

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

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

    for (int i = 0; i < s.size(); i++) {
        if (i + 1 < s.size()) {
            if (s[i] == s[i + 1]) {
                cout << i + 1 << " " << i + 2 << endl;
                return 0;
            }
        }

        if (i + 2 < s.size()) {
            if (s[i] == s[i + 2]) {
                cout << i + 1 << " " << i + 3 << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[] args){
  String s;
  Scanner scanner = new Scanner(System.in);
  s = scanner.nextLine();
  final int MOD = 2019;
  int power_of_ten  =1;
  int n = s.length(), suf  = 0;
  long answer = 0;
  int[] cnt_suf = new int[MOD];
  cnt_suf[suf]++;
  
  for (int i= n -1; i >=0; i--){
    int digit = s.charAt(i) - '0';
    suf = (suf + digit * power_of_ten) % MOD;
    power_of_ten = 10 * power_of_ten % MOD;
    answer += cnt_suf[suf];
    cnt_suf[suf]++;
  }
  System.out.println(answer);
}
  
}

Measured memory_bytes: 41192
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int a[110];
int main(){
  int N;
  cin>>N;
  int x;
  cin>>x;
  rep(i,N)cin>>a[i];

  sort(a,a+N);
  int ans=0;
  int res=0,memo_idx=0;
  rep(i,N){
    x-=a[i];
    ans++;

    if(x<=0){
      res=x+a[i];memo_idx=i;
      break;
    }
  }

  if(res!=a[memo_idx])ans--;
  cout<<ans<<endl;
}


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

////////////
// ModInt //
////////////

// 四則演算の最も左に存在する値がModIntでなければキャストでバグる
// 例えばx = mint * 1000;やx = ModInt(1000) * mint;はいいがx = 1000 * mint;は駄目。
template<int64_t mod_ = 1'000'000'007>
class ModInt {
private:
	int64_t integer_;

public:
	constexpr ModInt(const int64_t initial_number = 0)
		: integer_(initial_number){}
	
	// 四則演算
	constexpr ModInt operator+(const ModInt& operand) const
	{
		ModInt ret{this->integer_ + operand.integer_};
		if (ret.integer_ >= mod_)
			ret.integer_ -= mod_;
		return ret;
	}
	constexpr ModInt operator-(const ModInt& operand) const
	{
		ModInt ret{this->integer_ - operand.integer_};
		if (ret.integer_ < 0)
			ret.integer_ += mod_;
		return ret;
	}
	constexpr ModInt operator*(const ModInt& operand) const
	{
		return {this->integer_ * operand.integer_ % mod_};
	}
	constexpr ModInt operator/(const ModInt& operand) const
	{
		return *this * (operand ^ (mod_ - 2));
	}

	// 累乗
	constexpr ModInt operator^(const int64_t operand) const
	{
		ModInt ret{1}, pow_ope{this->integer_};
		for (int64_t pow{operand}; pow > 0; pow >>= 1)
		{
			if (pow & 1) ret *= pow_ope;
			pow_ope *= pow_ope;
		}
		return ret;
	}

	// 代入
	constexpr ModInt& operator=(const ModInt& operand)
	{
		this->integer_ = operand.integer_;
		return *this;
	}
	constexpr ModInt& operator+=(const ModInt& operand)
	{
		*this = *this + operand;
		return *this;
	}
	constexpr ModInt& operator-=(const ModInt& operand)
	{
		*this = *this - operand;
		return *this;
	}
	constexpr ModInt& operator*=(const ModInt& operand)
	{
		*this = *this * operand;
		return *this;
	}
	constexpr ModInt& operator/=(const ModInt& operand)
	{
		*this = *this / operand;
		return *this;
	}

	// その他
	constexpr operator int64_t() { return integer_; }

	constexpr ModInt getOne() const
	{
		return ModInt(1ll);
	}
	constexpr ModInt getZero() const
	{
		return ModInt(0ll);
	}
};
using Mint = ModInt<>;

////////////////
// 組み合わせ //
///////////////

template<int64_t mod_ = 1'000'000'007, int max_ = 200'000>
class Combination {
public:
	std::array<ModInt<mod_>, max_ + 1> inv, fact, finv;

	constexpr Combination()
	{
		inv[0] = inv[1] = fact[0] = fact[1] = finv[0] = finv[1] = 1;
		for (int num{2}; num <= max_; num++)
		{
			inv[num] = (mod_ - (int64_t)inv[mod_ % num] * (mod_ / num) % mod_) % mod_;
			fact[num] = num * fact[num - 1] % mod_;
			finv[num] = inv[num] * finv[num - 1] % mod_;
		}
	}

	constexpr ModInt<mod_> getCombi(const int n, const int r) const
	{
		if (r < 0 || n < 0 || n - r < 0) return 0;
		return fact[n] * finv[r] * finv[n - r];
	}

	constexpr ModInt<mod_> getPerm(const int n, const int r) const
	{
		if (r < 0 || n < 0 || n - r < 0) return 0;
		return fact[n] * finv[n - r];
	}
};
Combination<> combi;

int main()
{
	int N;
	std::string S;
	std::cin >> N >> S;
	Mint ans(combi.fact.at(N));
	int64_t count{};
	for (int i{}; i < 2 * N; i++)
	{
		if (((S.at(i) == 'W') + ((2 * N - i - 1) & 1)) % 2)
			count++;
		else
		{
			ans *= Mint(count);
			if (count == 0) break;
			count--;
		}
		assert(count >= 0);
	}
	if (count != 0) ans = Mint(0ll);
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define SQ(x)           ((x)*(x))
#define LCM(x,y)        (((x)/gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             printf("Ripon\n")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int kx[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
int ky[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<'\n';}
//*************useless stuff*************//
#define TC 0
#define mod 10000007
#define N 1000000

void solve(int T) {
    int k;
    cin>>k;
    ll sum = 0;
    rep(i,1,k){
        rep(j,1,k){
            rep(l,1,k){
                sum+= __gcd(__gcd(i,j),l);
            }
        }
    }
    cout<<sum<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>

int main(int argc,char* argv[]) {
	int n,k;
	int x,y;
	int i;
	scanf("%d",&n);
	scanf("%d",&k);
	for(i=0;i<k;i++) {
		scanf("%d %d",&x,&y);
		if(x*2>n)x=n-x+1;
		if(y*2>n)y=n-y+1;
		if(x>y)printf("%d\n",(y-1)%3+1);
		else printf("%d\n",(x-1)%3+1);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
main() {
  int A,B,K; cin>>A>>B>>K;
  vector<int> xs;
  for(int i=1; i<=100; ++i)
    if(A%i==0 && B%i==0) xs.push_back(i);
  cout<< xs[xs.size() - K] <<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc114/tasks/abc114_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int n;
    cin >> n;
    // ラムダ関数を再帰呼び出しするため auto は使えない
    function<int(string)> fn = [&](string s) {
        if (s != "" && stoll(s) > n) {
            return 0LL;
        }
        int ret = 1;
        vector<char> v = {'3', '5', '7'};
        for (auto &x : v) {
            if (s.find(x) == string::npos) {
                ret = 0;
                break;
            }
        }
        for (auto &x : v) {
            ret += fn(s + x);
        }
        return ret;
    };

    cout << fn("") << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3628
// マージソート
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 500000
const int INFTY = 2147483647;

int cmp_count = 0;

void mergeSort(int A[], int left, int right);
void merge(int A[], int left, int mid, int right);

int main(void)
{
    int A[MAX_N];
    int n;

    scanf("%d", &n);

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

    // マージソートを実施
    mergeSort(A, 0, n);

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        if( i )
        {
            printf(" ");
        }

        printf("%d", A[i]);
    }

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

    return 0;
}

// マージソートを実施する関数
void mergeSort(int A[], int left, int right)
{
    // 最小単位まで分割する
    if ( left + 1 < right )
    {
        int mid = ( left + right ) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
  }

  return;
}

// 分割された要素を並び替える関数
void merge(int A[], int left, int mid, int right)
{

    vector<int> L, R;

    int n1 = mid - left;
    int n2 = right - mid;

    // L[0...n1], R[0...n2] を生成
    for(int i = 0; i < n1; i++)
    {
        // 前半部分の配列を作成する
        L.push_back(A[left + i]);
    }

    for(int i = 0; i < n2; i++)
    {
        // 後半部分の配列を作成する
        R.push_back(A[mid + i]);
    }

    // 前半と後半の配列の最後の要素に最大値を入れておく
    // ( 比較時の番兵として使用 )
    L.push_back(INFTY);
    R.push_back(INFTY);

    int i = 0;
    int j = 0;

    for(int k = left; k < right; k++)
    {
        // 前半部分の配列と後半部分の配列を比較する
        if ( L[i] <= R[j] )
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }

        cmp_count++;
    }
}



Measured memory_bytes: 7356
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
	char str[8];
	int top = 0, stack[100];

	while(scanf("%s", str) != EOF)
	{
		switch(str[0])
		{
			case '+': --top; stack[top-1] = stack[top-1] + stack[top]; break;
			case '-': --top; stack[top-1] = stack[top-1] - stack[top]; break;
			case '*': --top; stack[top-1] = stack[top-1] * stack[top]; break;
			case '/': --top; stack[top-1] = stack[top-1] / stack[top]; break;
			default:  stack[top++] = atoi(str); break;
			
		}
	}
	printf("%d\n", stack[0]);
}




Measured memory_bytes: 2148
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (1 << 12)
#define MOD ((ll)1e9 + 7)

ll mem[MAXN][MAXN];

ll f(int x, int y) {
	if ((x < 0) || (y < 0)) {
		return 0;
	}
	if ((x == 0) && (y == 0)) {
		return 1;
	}
	ll & ret = mem[x][y];
	if (ret != -1) {
		return ret;
	}
	ret = f(x - 2, y - 1) + f(x - 1, y - 2);
	ret %= MOD;
//	cerr << x << " " << y << " " << ret << endl;
	return ret;
}

int x, y;

ll mypow(ll n, ll k) {
	ll ret = 1;
	ll cur = n;
	while (k) {
		if (k & 1) {
			ret *= cur;
			ret %= MOD;
		}
		cur *= cur;
		cur %= MOD;
		k >>= 1;
	}
	return ret;
}

ll inv(ll x) {
	return mypow(x, MOD - 2);
}

ll cnk(ll n, ll k) {
	if ((k < 0) || (k > n)) {
		return 0;
	}
	ll ret = 1;
	for (ll i = n - k + 1; i <= n; i++) {
		ret *= i;
		ret %= MOD;
	}
	for (ll i = 1; i <= k; i++) {
		ret *= inv(i);
		ret %= MOD;
	}
	return ret;
}

ll solve(ll x, ll y) {
	if ((x + y) % 3) {
		return 0;
	}

	int n = (x + y) / 3;
	int k = (x - y + n) / 2;
	return cnk(n, k);

}

int main() {
	memset(mem, -1, sizeof(mem));
	cin >> x >> y;
	//cout << f(x, y) << endl;

/*	for (int i = 0; i < MAXN; i++) {
		for (int j = 0; j < MAXN; j++) {
			if (solve(i,j) != f(i,j)) {
				cout << i << " " << j << " " << solve(i,j) << " " << f(i,j) << endl;
				return 0;
			}
		}
	}*/
	cout << solve(x, y) << endl;

	return 0;
}


Measured memory_bytes: 134264
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans



h,w = readInts()
print("#"*(w+2))
a = []
for i in range(h):
	print("#",end="")
	print(readChar(),end="")
	print("#")




print("#"*(w+2))

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

int m, n;
int dfs(int b[100][100], int y, int x){
	int a[100][100];
	for(int i = 0;i < 100;i++)
	for(int j = 0;j < 100;j++)a[i][j] = b[i][j];
	if(!a[y][x])return 0;
	int ans = a[y][x] = 0;
	if(a[y-1][x])ans = max(ans, dfs(a, y-1, x));
	if(a[y+1][x])ans = max(ans, dfs(a, y+1, x));
	if(a[y][x-1])ans = max(ans, dfs(a, y, x-1));
	if(a[y][x+1])ans = max(ans, dfs(a, y, x+1));
	return ans+1;
}

int main(){
	int a[100][100];
	while(cin >> m >> n, m){
		fill((int*)a, (int*)(a+100), 0);
		for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)cin >> a[i][j];
		
		int ans = 0;
		for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)ans = max(ans, dfs(a, i, j));
		cout << ans << endl;
		//cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4348
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
#define what(x) cerr << #x << " is " << x << endl;

const int inf = 1<<30;

int main(){
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for(int i = 0; i < R; ++i) {
        cin >> r[i];
    }
    sort(r.begin(), r.end());
    vector<ll> A(M), B(M), C(M);
    for(int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i] >> C[i];
    }
    vector<vector<ll> > d(N, vector<ll>(N, inf));
    for(int i = 0; i < M; ++i) {
        d[A[i]-1][B[i]-1] = C[i];
        d[B[i]-1][A[i]-1] = C[i];
    }
    for(int i = 0; i < N; ++i) {
        d[i][i] = 0;
    }
    for(int k = 0; k < N; ++k) {
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    ll ret = inf;
    do {
        ll temp = 0;
        for(int i = 0; i < R-1; ++i) {
            temp += d[r[i]-1][r[i+1]-1];
        }
        ret = min(ret, temp);
    } while(next_permutation(r.begin(), r.end()));

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>

#define MIN(a,b) ((a)<(b)?(a):(b))

void run(void){
  int h,w;
  scanf("%d%d",&h,&w);
  int c[100];
  const int f=10;
  int i,j,k;
  for(i=0;i<f*f;i++) scanf("%d",c+i);
  for(k=0;k<f;k++){
    for(i=0;i<f;i++){
      for(j=0;j<f;j++){
	c[i*f+j]=MIN(c[i*f+j],c[i*f+k]+c[k*f+j]);
      }
    }
  }
  int ans=0;
  for(i=0;i<h*w;i++){
    int a;
    scanf("%d",&a);
    if(a<0) continue;
    ans+=c[a*f+1];
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128