akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long



#if 0
const int MOD = ;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}
#endif

#if 0
int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}
#endif

using namespace std;

const int MAXN = 1000;

bool mat[MAXN + 1][MAXN + 1];


int main() {
#if 0
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, j, n, m, a, b;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> m >> a >> b;

    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            bool cur = 0;
            if(i <= b && j <= a) {
                cur = 1;
            }
            if(i > b && j > a) {
                cur = 1;
            }
            cout << cur;
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 1280
from collections import defaultdict

n, m = map(int, input().split())
prefecture = [[] for _ in range(n+1)]
tpl_lst=[]
for i in range(m):
    p, y = map(int, input().split())
    prefecture[p].append(y)
    tpl_lst.append((p,y))

for p in prefecture:
    if len(p)>=2:
        p.sort()

d = defaultdict(list)
for idx, pre in enumerate(prefecture):
    if len(pre)>=1:
        for i, year in enumerate(pre):
            d[(idx, year)]=[idx, i+1]

for tpl in tpl_lst:
    id = d[tpl][0]*(10**6) + d[tpl][1]
    id = str(id)
    id = "0"*(12-len(id)) + id
    print(id)
#print(prefecture)

Measured memory_bytes: 55628
n=int(input())
a=sorted(list(map(int,input().split())))
b=sorted(list(set(a)))
l=len(b)
if l>=4:
    print("No")
    exit()
else:
    if l==1:
        if b[0]==0:
            print("Yes")
        else:
            print("No")
    elif l==2:
        if n%3!=0:
            print("No")
        else:
            if b[0]!=0:
                print("No")
            else:
                cnt1=a.count(b[0])
                cnt2=a.count(b[1])
                if cnt2==(n//3)*2:
                    print("Yes")
                else:
                    print("No")
    else:
        if n%3!=0:
            print("No")
        else:
            cnt1=a.count(b[0])
            cnt2=a.count(b[1])
            cnt3=a.count(b[2])
            if cnt1!=n//3 or cnt2!=n//3 or cnt3!=n//3:
                print("No")
            else:
                if b[0]^b[2]!=b[1]:
                    print("No")
                else:
                    print("Yes")


Measured memory_bytes: 14592
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  for (ll i = 0; i < N; ++i) {
    cin >> H.at(i);
  }
  vector<ll> dp(N, INF);
  dp.at(0) = 0;
  for (ll i = 0; i < N; ++i) {
    for (ll j = 1; j <= K; ++j) {
      ll temp = min(N - 1, i + j);
      if (i + j > N - 1) {
        break;
      }
      dp.at(temp) = min(dp.at(temp), dp.at(i) + abs(H.at(i) - H.at(temp)));
    }
  }
  cout << dp.at(N - 1) << "\n";
}


Measured memory_bytes: 4780
import math

X = int(input())

if X == 1:
    print(1)
    exit()

for i in reversed(range(1, X+1)):
    for j in range(2, int(math.sqrt(i))+1):
        if abs(math.log(i, j) - round(math.log(i, j))) <= 0.0000001:
            print(i)
            exit()
    if i == 1:
        print(1)


Measured memory_bytes: 3060
#include<algorithm> 
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 61
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
pair<int,int> q[MN*MN*2+5];
int h,w,n,Lx[MN+5],num1,Ly[MN+5],x[MN+5],y[MN+5],num2,ans;
int vis[MN+5][MN+5],b[MN+5][MN+5],d[MN+5][MN+5],W[4],top;
const int dis[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
void Update(int x,int y)
{
	if(vis[x][y]) return;vis[x][y]=1;
	for(int k=0;k<4;++k)
	{
		int nx=x+dis[k][0],ny=y+dis[k][1];
		if(nx<1||ny<1||nx>num1||ny>num2||b[nx][ny]) continue;
		if(d[x][y]+W[k]<d[nx][ny])
		{
			d[nx][ny]=d[x][y]+W[k];
			if(!W[k]) Update(nx,ny);
			else q[++top]=make_pair(nx,ny);
		}
	}	
}
void Bfs(int x,int y)
{
	memset(vis,0,sizeof(vis));
	memset(d,63,sizeof(d));d[x][y]=0;q[top=MN*MN]=make_pair(x,y);
	for(int i=MN*MN;i<=top;++i)
	{
		int x=q[i].first,y=q[i].second;
		Update(x,y);
	}
}
inline int S(int x,int y){return 1LL*(Lx[x]-Lx[x-1])*(Ly[y]-Ly[y-1])%mod;}
int main()
{
	h=read();w=read();n=read();
	Lx[num1=1]=h;Ly[num2=1]=w;
	for(int i=1;i<=n;++i)
	{
		x[i]=read()+1,y[i]=read()+1;
		Lx[++num1]=x[i];if(x[i]>1) Lx[++num1]=x[i]-1;
		Ly[++num2]=y[i];if(y[i]>1) Ly[++num2]=y[i]-1;
	}
	sort(Lx+1,Lx+num1+1);num1=unique(Lx+1,Lx+num1+1)-Lx-1;
	sort(Ly+1,Ly+num2+1);num2=unique(Ly+1,Ly+num2+1)-Ly-1;
	for(int i=1;i<=n;++i)
		b[lower_bound(Lx+1,Lx+num1+1,x[i])-Lx]
		 [lower_bound(Ly+1,Ly+num2+1,y[i])-Ly]=1;
	for(int i=1;i<h;++i)
	{
		int a=1LL*w*i%mod,b=1LL*w*(h-i)%mod;
		for(int j=1;j<=n;++j) 
			if(x[j]<=i) --a<0?a+=mod:0;
			else --b<0?b+=mod:0;
		ans=(ans+1LL*a*b)%mod;
	}
	for(int i=1;i<w;++i)
	{
		int a=1LL*h*i%mod,b=1LL*h*(w-i)%mod;
		for(int j=1;j<=n;++j) 
			if(y[j]<=i) --a<0?a+=mod:0;
			else --b<0?b+=mod:0;
		ans=(ans+1LL*a*b)%mod;
	}
	for(int i=1;i<=num1;++i) for(int j=1;j<=num2;++j) if(!b[i][j])
	{
		W[0]=0;W[1]=1;W[2]=1;W[3]=0;Bfs(i,j);
		for(int x=1;x<i;++x) for(int y=j;y<=num2;++y) if(!b[x][y])
			ans=(ans+1LL*d[x][y]*S(i,j)%mod*S(x,y))%mod;
		W[0]=1;W[1]=0;W[2]=1;W[3]=0;Bfs(i,j);
		for(int x=i;x<=num1;++x) for(int y=j+1;y<=num2;++y) if(!b[x][y])
			ans=(ans+1LL*d[x][y]*S(i,j)%mod*S(x,y))%mod;	
		W[0]=1;W[1]=0;W[2]=0;W[3]=1;Bfs(i,j);
		for(int x=i+1;x<=num1;++x) for(int y=1;y<=j;++y) if(!b[x][y])
			ans=(ans+1LL*d[x][y]*S(i,j)%mod*S(x,y))%mod;
		W[0]=0;W[1]=1;W[2]=0;W[3]=1;Bfs(i,j);
		for(int x=1;x<=i;++x) for(int y=1;y<j;++y) if(!b[x][y])
			ans=(ans+1LL*d[x][y]*S(i,j)%mod*S(x,y))%mod;
	}
	cout<<ans;
	return 0;
}

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

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

using namespace std;

int main(){
	int a,b; scanf("%d%d",&a,&b);
	puts(a+b==15?"+":a*b==15?"*":"x");
	return 0;
}


Measured memory_bytes: 3760
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };

int N;
vi A;

int main() {
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];
    int M = INT32_MIN;
    vector<pair<int, int>> ans;

    bool allPositive = true, allNegative = true;
    rep(i, N) {
        if (A[i] >= 0) allNegative = false;
        else if (A[i] < 0) allPositive = false;
    }

    if (allPositive || allNegative) {
        if (allPositive) {
            sort(all(A));
            int sub = A[0];
            for (int i = 1; i < N - 1; ++i) {
                ans.emplace_back(sub, A[i]);
                sub -= A[i];
            }
            ans.emplace_back(A[N - 1], sub);
            M = A[N - 1] - sub;
        }
        else {
            sort(all(A), greater<int>());
            int sub = A[0];
            for (int i = 1; i < N - 1; ++i) {
                ans.emplace_back(sub, A[i]);
                sub -= A[i];
            }
            ans.emplace_back(sub, A[N - 1]);
            M = sub - A[N - 1];
        }
    }
    else {
        vi posi, nega;
        rep(i, N) {
            if (A[i] >= 0) posi.push_back(A[i]);
            else nega.push_back(A[i]);
        }

        int p = posi[0];
        rep(i, 1, nega.size()) {
            ans.emplace_back(p, nega[i]);
            p -= nega[i];
        }
        int n = nega[0];
        rep(i, 1, posi.size()) {
            ans.emplace_back(n, posi[i]);
            n -= posi[i];
        }
        ans.emplace_back(p, n);
        M = p - n;
    }

    write(M);
    rep(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

Measured memory_bytes: 3520
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

void cumsum(vector<vector<int>> &v){
    int N = v.size();
    int M = v[0].size();
    for(int i=1; i<N; i++)
        for(int j=1; j<M; j++)
            v[i][j] += v[i][j-1];
    for(int i=1; i<N; i++)
        for(int j=1; j<M; j++)
            v[i][j] += v[i-1][j];
}

int sub(vector<vector<int>> &v, int y1, int x1, int y2, int x2){
    return v[y2][x2] - v[y2][x1-1] - v[y1-1][x2] + v[y1-1][x1-1];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<string> S(N);
    for(int i=0; i<N; i++) cin >> S[i];

    vector<vector<int>> num(N+1, vector<int>(M+1, 0));
    for(int i=0; i<N; i++)
        for(int j=0; j<M; j++)
            if(S[i][j] == '1')
                num[i+1][j+1] = 1;

    cumsum(num);

    vector<vector<int>> yoko(N+1, vector<int>(M+1, 0));
    vector<vector<int>> tate(N+1, vector<int>(M+1, 0));

    for(int i=1; i<=N; i++)
        for(int j=2; j<=M; j++)
            if(S[i-1][j-1] == '1' && S[i-1][j-2] == '1') yoko[i][j] = 1;
    for(int i=2; i<=N; i++)
        for(int j=1; j<=M; j++)
            if(S[i-1][j-1] == '1' && S[i-2][j-1] == '1') tate[i][j] = 1;

    cumsum(yoko); cumsum(tate);

    for(int i=0; i<Q; i++){
        int x1, y1, x2, y2;
        cin >> y1 >> x1 >> y2 >> x2;
        int a = sub(num,  y1, x1, y2, x2);
        int b = sub(yoko, y1, x1+1, y2, x2);
        int c = sub(tate, y1+1, x1, y2, x2);
        cout << a - b - c << endl;
    }

    return 0;
}

Measured memory_bytes: 53888
#include "bits/stdc++.h"
//#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;

bool comp(const pll& a, const pll& b) {
	return a.first < b.first;
}
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i * i <= n; ++i)
	{
		if (n % i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i * i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}


template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}
ll nCr(ll n, ll r);//コンビネーション
int permutation(int n, int r);//nPk パーミュテーション
int factorial(int k);//階乗

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	//priority_queue<int> q;
	string s = {};
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	ll x[100005] = {};
	ll y[100005] = {};
	string str[200005] = {};
	//char* ch[200005] = {};
	char* ch1 = {};
	//ll z[302][302] = {};
	cin >> a;
	std::vector<string> data;
	for (int i = 0; i < a; i++)
	{
		//cin >> str[i];
		cin >> str[i];
		//cin >> ch[i];
		//ch[i] = str[i];

		data.push_back(str[i]);
	}
	sort(data.begin(), data.end());//昇順ソート
	{
		for (int i = 0;i < data.size();i++)
		{
			//cout << data[i] << endl;
		}
	}
	for (int i = 0; i < a; i++)
	{
		if (s != data[i])
		{
			s = data[i];
			b = 0;
		}
		else
		{
			b++;
			ans = max(ans, b);
		}
	}
	//cout << endl;

	for (int i = 0;i < a;i++)
	{
		//cout << data[i] << endl;
	}
	b == 0;
	s = "";
	for (int i = 0; i < a; i++)
	{
		if (s != data[i])
		{
			s = data[i];
			b = 0;
		}
		else
		{
			b++;
			//ans = max(ans, b);
		}
		if (ans == b)
		{
			cout << data[i] << endl;
		}

	}
	//return 0;

	/*cout << c << endl;
	cout << b << endl;*/
	//cout << fixed << setprecision(10) <<tmp << endl;
	//cout<<factorial<10><<endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}

int permutation(int n, int r) {
	int n_sum, r_sum;
	int i;
	r = n - r;
	n_sum = factorial(n);
	r_sum = factorial(r);
	return n_sum / r_sum;
}

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

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

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

  vector<bool> ac(N);
  vector<int> penal(N);
  int penal_sum = 0, ac_sum = 0;
  for(int i = 0; i < M; i++){
    int p;
    string S;
    cin >> p >> S;
    p--;
    if(S == "AC"s){
      if(!ac[p]){
        ac[p] = true;
        ac_sum++;
        penal_sum += penal[p];
      }
    }else{
      if(!ac[p]){
        penal[p]++;
      }
    }
  }
  cout << ac_sum << ' ' << penal_sum << endl;
}


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

int main(void)
{
    int K;
    int ans = 0;
    int odd, even;
    cin >> K;
    for (int i = 1; i <= K; i++)
    {
        for (int j = 1; j < i; j++)
        {
            if (i % 2 == 0 && j % 2 == 1)
            {
                ans += 1;
            }
            else if (i % 2 == 1 and j % 2 == 0)
            {
                ans += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i < (int)(b);++i)

int main(void) {
    while (true) {
        string S;
        cin >> S;
        if(S == "#")
        {
            return 0;
        }
        int sx,sy;
        int tx, ty;
        cin >> sx >> sy >> tx >> ty;
        sx--; sy--; tx--; ty--;

        int H = 1;
        rep(i, S.size())
        {
            if(S[i] == '/')
            {
                H++;
            }
        }

        int W = 0;
        rep(i, S.size())
        {
            if(S[i] == '/')
            {
                break;
            }
            else if(S[i]=='b')
            {
                W++;
            }
            else
            {
                W +=(S[i]-'0');
            }

        }

        int M[H][W];
        memset(M, 0, sizeof(M));
        int y = 0;
        int x = 0;
        rep(i, S.size())
        {
            if(S[i] == '/')
            {
                y++;
                x = 0;
            }
            else if(S[i]=='b')
            {
                M[y][x] = 1;
                x++;
            }
            else{
                int t  = (S[i] - '0');
                x += t;
                
            }
    
        }
        M[sx][sy] = 0;
        M[tx][ty] = 1;

        rep(i, H)
        {
            int cnt = 0;
            rep(j, W)
            {
                if(M[i][j] == 1)
                {
                    if(cnt > 0)
                    {
                        cout << cnt;
                        cnt = 0;
                    }
                    cout << "b";
                }
                else
                {
                    cnt++;
                }

            }
            if(cnt > 0)
            {
                cout << cnt;
            }
            if(i != H - 1)cout << "/";
        }
        cout << endl;
    }

}


Measured memory_bytes: 3012
#include <iostream>

using namespace std;

long long MOD = 1000000007;

//n^rを計算
long long mod_power(long long n, long long r){
  long long ans = 1;
  //rの二進展開を考える
  while(r>0){
    //rの右端ビットが立っていればansの更新
    if(r & 1 == 1)
      ans = ans * n % MOD;
    //繰り返し二乗法
    n = n * n % MOD;
    //rの1ビットシフト
    r >>= 1;
  }
  return ans;
}

//nCrを計算
long long mod_comb(long long n, long long r){
  long long den = 1, num = 1; //分母，分子
  long long ans;
  
  //分母はr!
  for(long long i=1; i<=r; i++)
    den = den * i % MOD;

  //分子は頑張る
  for(long long i=0; i<r; i++)
    num = num * (n-i) % MOD;

  //フェルマーの小定理を使う(a^p-2)
  ans = num * mod_power(den, MOD-2) % MOD;
  
  return ans;
}


int main(){
  long long N, a, b;
  cin >> N >> a >> b;
  //入力終わり

  //二項定理の利用

  //1種類も選ばないときをひいておく
  long long ans = mod_power(2, N)-1;

  //NCaとNCbもひく
  ans = (ans + MOD - mod_comb(N, a) ) % MOD;
  ans = (ans + MOD - mod_comb(N, b) ) % MOD;

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


Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let n = buf.trim().parse().unwrap();
    let mut v = vec![0 as u64; n];
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let mut buf = buf.split_whitespace();
    for i in 0..n {
        v[i] = buf.next().unwrap().parse().unwrap();
    }
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let q = buf.trim().parse().unwrap();
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let mut buf = buf.split_whitespace();
    let mut count = 0;
    for _ in 0..q {
        let a: u64  = buf.next().unwrap().parse().unwrap();
        for e in &v {
            if a == *e {
                count += 1;
                break;
            }
        }
    }
    println!("{}", count);
}



Measured memory_bytes: 5036
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

int main(){
    int x, y;

    while(true){
        cin >> x >> y;
        if(x == 0 && y == 0) break;

        if(x <= y) cout << x << " " << y << endl;
        else cout << y << " " << x << endl;
    }
}


Measured memory_bytes: 3016
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
using namespace std;

int main ()  {
  

  int a, p;
  cin >> a >> p;
  int make_pieces = a * 3;
  int all_pieces = make_pieces + p;
  all_pieces = all_pieces / 2;
  cout << all_pieces << "\n";



	return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
#define PII pair<int, int>
using namespace std;
typedef long long LL;
//const int MOD = 1e9+7;
const auto INF  = (LL)1e18;
const int N = 1e5+5;

LL dis1[N*2];
LL dis2[N*2];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int pre = 0;
    scanf("%d", &pre);
    LL totall = 0;
    for(int i=2; i<=n; i++) {
        int x;
        scanf("%d", &x);
        if(x < pre)
            x += m;
        totall += x - pre;
        dis1[pre+1]++;
        dis1[x+1]--;
        dis2[pre+1] += pre+1;
        dis2[x+1] -= pre+1;
        pre = (x <= m ? x : x-m);
    }
    for(int i=1; i<=2*m; i++) {
        dis1[i] += dis1[i-1];
        dis2[i] += dis2[i-1];
    }
    LL answer = INF;
    for(int i=1; i<=m; i++) {
        LL x = dis1[i]*i - dis2[i] + dis1[i+m]*(i+m) - dis2[i+m];
        answer = min(answer, totall - x);
    }
    printf("%lld\n", answer);
}








Measured memory_bytes: 3328
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

import itertools as iter
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


from string import ascii_lowercase
print(ascii_lowercase[ascii_lowercase.index(input())+1])

Measured memory_bytes: 5828
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll mod = 1e9+7;

int main(){
    int N;cin >> N;
    string s,t;cin >> s >> t;
    map<char, ll> mp;
    mp[s.front()]++;
    for(int i = 1;i < N;i++){
        if(i == N-1 && s[i] && t[i])break;
        mp[s[i]] %= mod;
        mp[t[i]] %= mod;
        mp[s[i]] += mp[t[i]];
        mp[s[i]] %= mod;
    }
    cout<<mp[t.back()] % mod<<endl;
}



Measured memory_bytes: 3284
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int MOD=1e9+7;
ll a[N],sum[N],par[N];

int f(int x){
    return x==par[x]?x:par[x]=f(par[x]);
}

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

    int n,m;
    cin >>n>>m;
    for(int i=1;i<=n;i++)   cin >> a[i];
    for(int i=1;i<=n;i++)   par[i]=i;
    for(int i=1;i<=m;i++){
        int a,b;
        cin >> a>> b;
        int ra=f(a);
        int rb=f(b);
        par[rb]=ra;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        if(f(i)==f(a[i]))   ans++;
    }
    cout <<ans << endl;

    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807


void solve()
{
  string S;
  int N,L;
  cin>>N>>L;
  cin>>S;

  vector<int> vec (S.size(),0);
  vector<pair<int,int> > mat(N);

  for (int i = 0; i < L; i++)
  {
    int A,B;
    cin>>A>>B;
    mat[i].first = A;
    mat[i].second = B;
  }
  
  for (int i = 0; i < S.size() - 1; i++)
  {
    if ( (S[i] == 'A')&&(S[i+1] == 'C'))
    {
      vec[i+1]++;
    }
  }

  for (int i = 0; i < S.size() -1; i++)
  {
    vec[i+1] += vec[i];
    // cout<<vec[i]<<endl;
  }
  
  for (int i = 0; i < L; i++)
  {
    cout<<vec[mat[i].second -1 ] - vec[mat[i].first - 1]<<endl;
  }
  
  
  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}


Measured memory_bytes: 2176
n = int(input())
a = list(map(int, input().split()))

a_sum = sum(a)
x = a[0]
y = a_sum - x
min_diff = 10000000000
diff = abs(y - x)

for i in range(1, n-1):
    x += a[i]
    y -= a[i]
    diff = abs(y - x)
    if diff < min_diff:
        min_diff = diff

if diff < min_diff:
    min_diff = diff
print(min_diff)

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

int main()
{
	int h, w; cin >> h >> w;
	
	vector<vector<char>> c(h + 2, vector<char>(w + 2));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> c[i][j];
		}
	}

	bool can = true;

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (c[i][j] == '#') {
				if (c[i - 1][j] == '#' || c[i + 1][j] == '#' || c[i][j - 1] == '#' || c[i][j + 1] == '#') {
				}
				else {
					can = false;
				}
			}
		}
	}
	
	if (can) cout << "Yes" << endl;
	else  cout << "No" << endl;
		
	return 0;
}

Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll r;
    in >> r;

    out << 3*r*r << endl;
 

 

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    int x, t;
    cin >> x >> t;
    cout << ((x - t >= 0 ? x - t : 0)) << endl;
    return 0;
}


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

using namespace std;

int main() {

	int N;
	
	cin >> N;

	if (N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9)
	{
		cout << "hon";
	}
	else if (N % 10 == 3)
	{
		cout << "bon";
	}
	else
	{
		cout << "pon";
	}

	return 0;
	
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

int a[200010];
int b[200010];

void solve(){

    ll k,n;
    cin >> k >> n;
    rep(i,n){
        cin >> a[i];
    }
    a[n]=a[0]+k;
    rep(i,n){
        b[i]=a[i+1]-a[i];
    }
    ll m = 0;
    rep(i,n){
        m=max(ll(m), ll(b[i]));
    }
    cout << k-m << endl;

}

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


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
using namespace std;

char c[85];

bool search_th(){
  bool f = false;
  for (int i = 0; i < strlen(c); i++){
    if ((c[i] == 't' && c[i+1] == 'h' && c[i+2] == 'e') ||
        (c[i] == 't' && c[i+1] == 'h' && c[i+2] == 'i' && c[i+3] == 's') ||
        (c[i] == 't' && c[i+1] == 'h' && c[i+2] == 'a' && c[i+3] == 't')){
          f = true;  break;
    }
  }
  return f;
}

int main(){
  while (cin.getline(c, sizeof(c))){
    while (1){
      if (search_th() == true){
      cout << c << endl;
      break;
      }
      for (int j = 0; j < strlen(c); j++){
        if (c[j] >= 'a' && c[j] <= 'y'){
          c[j]++;
        } else if (c[j] == 'z'){
          c[j] = 'a';
        }
      }
    }
    for (int i = strlen(c); i < 85; i++){
      c[i] = '\0';
    }
  }
  return 0;
}



Measured memory_bytes: 2900
#include <iostream>
#include <string>
using namespace std;
int main() {
    int a, b; string op;
    while(true) {
        cin >> a >> op >> b;
        if (op == "?") break;
        else if(op == "+") cout << a + b;
        else if(op == "-") cout << a - b;
        else if(op == "*") cout << a * b;
        else cout << a / b;
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3064
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int A, B, C;
	std::cin >> A >> B >> C;
	std::cout << C - (std::min(A, B + C) - B) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

int main(){
    int n,A[1000];
    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&A[i]);
    }
    
    for (int i =n-1;i>-1;i--)
    {
        if(i-n+1)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}


Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl

const int MOD = 1000000007;

int n;
int main() {
    cin >> n;
    vector<ll> a(n), b(n+1, 0);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) b[i+1] = b[i] + a[i];

    ll ans = 0;
    rep(i, 0, n){
        ll t = b[n] - b[i+1]; t %= MOD;
        ans += a[i]*t;
        ans %= MOD;
    }

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


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

typedef long long LL;
typedef pair<int, int> II;

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    int a[10];
    for (int i = 1; i <= 7; ++i) cin >> a[i];

    LL ans = 0;
    for (int x = 0; x < 2; ++x) {
        if (x <= min(a[1], min(a[4], a[5])))
            ans = max(ans, (a[1] - x) / 2 * 4ll + a[2] * 2ll + (a[4] - x) / 2 * 4ll + (a[5] - x) / 2 * 4ll + x * 6);
    }
    cout << ans / 2;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        if (n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

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


	switch (s[s.length() - 1])
	{
		case '2':
			cout << "hon" << endl;
			break;
		case '4':
			cout << "hon" << endl;
			break;
		case '5':
			cout << "hon" << endl;
			break;
		case '7':
			cout << "hon" << endl;
			break;
		case '9':
			cout << "hon" << endl;
			break;
		case '0':
			cout << "pon" << endl;
			break;
		case '1':
			cout << "pon" << endl;
			break;
		case '6':
			cout << "pon" << endl;
			break;
		case '8':
			cout << "pon" << endl;
			break;
		case '3':
			cout << "bon" << endl;
			break;
	}

}

Measured memory_bytes: 3624
import sys
import re

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = input()
    if re.fullmatch('A?KIHA?BA?RA?', S):
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9568
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($i = 0; $i < $H; $i++){
  $line = trim(fgets(STDIN));
  for($j = 0 ; $j < $W; $j++){
    $map[$i][$j] = $line[$j];
  }
}
$current[] = [0,0];
$d = 0;
$dotCount = 0;
foreach($map as $line){
  foreach($line as $cell){
    $dotCount += $cell == ".";
  }
}
while($current){
  $next = [];
  foreach($current as list($cy, $cx)){
    foreach([[0,1],[0,-1],[1,0],[-1,0]] as list($dy, $dx)){
      if(isset($map[$cy+$dy][$cx+$dx]) && $map[$cy+$dy][$cx+$dx] == '.'){
        $next[] = [$cy+$dy,$cx+$dx];
        $map[$cy+$dy][$cx+$dx] = "#";
        if($cy+$dy == $H-1 && $cx+$dx == $W-1){
          echo $dotCount - $d - 2,"\n";
          exit;
        }
      }
    }
  }
  $current = $next;
  $d++;
}
echo -1,"\n";


Measured memory_bytes: 4728
ans=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
print(ans[K-1])

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

int main()
{
	char a[20];
	char b[20];
	cin >> a;

	for (int i = 0, j = 0; a[i] != NULL; j++) {
		b[j] = a[i];
		if (j == 4) {
			b[i] = ' ';
		} else {
			i++;
		}
		cout << b[j];
	}
	cout << "\n";

//	cout << b;

	return (0);
}

Measured memory_bytes: 256
using System;

class ABC{
  static void Main(){
    string N = Console.ReadLine();
    string[] Ai = Console.ReadLine().Trim().Split(' ');
    for (int i = 0; i < int.Parse(N); i++)
    {
      if (int.Parse(Ai[i]) % 2 == 0 && int.Parse(Ai[i]) % 3 != 0 && int.Parse(Ai[i]) % 5 != 0)
      {
        Console.WriteLine("DENIED");
        return;
      }
    }
    Console.WriteLine("APPROVED");
  }
}


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


const int n_day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
struct Date {
  // year, month, day, a day of the week
  int y, m, d, e;
  Date() {}
  Date(int y, int m, int d, int e = -1) : y(y), m(m), d(d), e(e) {}
 
  bool operator < (const Date &o) const {
    if(y != o.y) return y < o.y;
    if(m != o.m) return m < o.m;
    return d < o.d;
  }
 
  bool isLeapYear() {
    if(y % 400 == 0) return true;
    if(y % 100 == 0) return false;
    if(y % 4 == 0) return true;
    return false;
  }

  int getDays() {
    int nd = n_day[m];
    if(m == 2) nd += isLeapYear();
    return nd;
  }

  void next() {
    e = (e+1)%7;
    if(d == getDays()) {
      d = 1;
      if(m == 12) {
        m = 1;
        ++y;
      } else {
        ++m;
      }
    } else {
      ++d;
    }
  }
 
  void back() {
    e = (e+6)%7;
    if(d == 1) {
      if(m == 1) {
        m = 12;
        --y;
      } else {
        --m;
      }
      d = getDays();
    } else {
      --d;
    }
  }
};

// AOJ 0125
int main() {
  int y1, m1, d1, y2, m2, d2;
  while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2) {
    if(y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0)
      break;
    Date d(y1,m1,d1), end(y2,m2,d2);
    int res = 0;
    while(d < end) {
      ++res;
      d.next();
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
//#pragma GCC target("avx,avx2,sse4.2")
#define re register
#define rep(q, a, b) for (re int q = a, q##_end_ = b; q <= q##_end_; ++q)
#define dep(q, a, b) for (re int q = a, q##_end_ = b; q >= q##_end_; --q)
#define mem(a, b) memset(a, b, sizeof a)
#define debug(a) cerr << #a << ' ' << a << "___" << endl
using namespace std;
//char buf[10000000], *p1 = buf, *p2 = buf;
#define Getchar() getchar()//p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000000, stdin), p1 == p2) ? EOF : *p1++
template<typename T>
void in(T &r) {
    static char c;
    r = 0;
    while (c = Getchar(), c < 48)
        ;
    do
        r = (r << 1) + (r << 3) + (c ^ 48);
    while (c = Getchar(), c > 47);
}
const int mn=55;
int n,m,val[mn][mn];
bool check(int a,int b){
	int tot=0;
	rep(q,1,m)tot+=(val[a][q]-val[b][q])*(val[a][q]-val[b][q]);
	if((int)sqrt(tot)*(int)sqrt(tot)==tot)return 1;
	return 0;
}
int main(){
	int ans=0;
	cin>>n>>m;
	rep(q,1,n)rep(w,1,m)cin>>val[q][w];
	rep(q,1,n)rep(w,q+1,n){
		if(check(q,w))++ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; public Pair(int xx, int yy) { x = xx; y = yy; } }
    private static int[] dx = { 1, 0, -1, 0 };
    private static int[] dy = { 0, -1, 0, 1 };
    public static void Main()
    {
        int N = NextInt();
        long[] V = LineLong();
        long[] C = LineLong();
        long ans = 0;
        for (int i = 0; i < N; i++)
            if (V[i] - C[i] > 0) ans += (V[i] - C[i]);
        Console.WriteLine(ans);
        
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 11476
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
int main(){
    int n=in(),m=in();
    vector<pii>p(n);
    rep(i,n){
        int a=in(),b=in();
        p[i]=mp(a,b);
    }
    sort(All(p));
    pq que;
    int id=0;
    ll ans=0;
    for(int i=1;i<=m;i++){
        while(p[id].first==i){
            que.push(p[id].second);
            id++;
        }
        if(!que.empty()){
            ans+=que.top();
            que.pop();
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1788
object Main extends App {
  val n = scala.io.StdIn.readInt()
  val aInput = scala.io.StdIn.readLine()
  val aArray = aInput.split(" ").map(_.toInt).toVector

  var result = "APPROVED"
  aArray.foreach { a =>
    if (a % 2 == 0) {
      if (a % 3 != 0 && a % 5 != 0) {
        result = "DENIED"
      }
    }

  }
  println(result)

}

Measured memory_bytes: 25552
#include<stdio.h>
int min(int x,int y){
  if(x>y)return x;
  return y; 
}
int main(){
  int max,c=0,de,i,j,k;
  char h;
  while(scanf("%d %d",&max,&de)){
    if(max==0)break;
    int kachi[de],omosa[de];
    int sou[max+1];
    for(i=1;i<max+1;i++)sou[i]=-1;
    sou[0]=0;
    for(i=0;i<de;i++)scanf("%d %c %d",&kachi[i],&h,&omosa[i]);
    for(i=0;i<de;i++){
      for(j=max-omosa[i];j>-1;j--){
	if(sou[j]!=-1){
	  sou[j+omosa[i]]=min(sou[j+omosa[i]],sou[j]+kachi[i]);
	}
      }
    }
    k=0;
    de=0;
    for(i=0;i<max+1;i++){
      if(k<sou[i]){
	k=sou[i];
	de=i;
      }
    }
    printf("Case %d:\n%d\n%d\n",++c,k,de);
  }
  return 0;
}


Measured memory_bytes: 612
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {
    input!{
        N:usize,
        S:Chars,
    }
    let A = S.iter().map(|&s| if s=='(' {1} else {-1}).collect::<Vec<_>>();
    let mut L = vec![0;N+1];
    let mut R = vec![0;N+1];
    for i in 1..N+1{
        L[i] = L[i-1]+A[i-1];
    }
    for i in (0..N).rev(){
        R[i] = R[i+1]+A[i];
    }
    let l = (-*L.iter().min().unwrap()) as usize;
    let r = (*R.iter().max().unwrap()) as usize;
    println!("{}{}{}","(".repeat(l),Chars2String(&S),")".repeat(r));
}

fn Chars2String(C:&Vec<char>) -> String {C.iter().collect::<String>()}

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

int main(){
  string S;
  cin >> S;
  string ans;
  for(int i=0; i<S.size(); i++){
    if(S.at(i)=='0' || S.at(i)=='1') ans+=S.at(i);
    else if(ans.size()!=0) ans.erase(ans.begin()+ans.size()-1);
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s; int w; cin>>w;
	for (int i=0; i<s.size(); i+=w)
		cout<<s[i];
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  string S,T;
  cin >> S >> T;
  int ans=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)) ++ans;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3920
#include <iostream>
#include <vector>

int main(){
    uint32_t N = 0;
    uint64_t sum = 0;
    std::cin >> N;
    std::vector<uint16_t> d_vec(N, 0);
    for(int i = 0; i < N; i++){
        std::cin >> d_vec[i];
    }
    
    for(int k = 0; k < N; k++){
        for(int l = 0; l < k; l++){
            sum += d_vec[l] * d_vec[k];
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, std::vector<long long> a){
    vector<i64> ans(N);
    rep(i, 32){
        i64 cnt = 0;
        rep(j, N) if((((1LL)<<i) & a[j]) != 0) cnt++;
        if(cnt % 2 == 1){
            rep(j, N) if((((1LL)<<i) & a[j]) == 0) ans[j] += (1LL<<i);
        }else{
            rep(j, N) if((((1LL)<<i) & a[j]) != 0) ans[j] += (1LL<<i);
        }
    }
    rep(i, N - 1) cout << ans[i] << " ";
    cout << ans[N - 1] << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

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


Measured memory_bytes: 6424
#include<bits/stdc++.h>
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define ll long long
#define M 100000007
#define fr first
#define sc second
#define endl "\n"
#define vc vector
#define pb push_back
#define pii pair<ll, ll>
#define psi pair<string, ll>
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define PI 3.14159265
#define r0 return 0
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;


int main() {
  fast
  int h,a,cnt=0;
  cin>>h>>a;
  cnt=h/a;
  h-=cnt*a;
  if(h!=0) cnt++;
  cout<<cnt;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
const int maxn = 1e3;
int num[4];
char ch[4];
int flag;
int book[4];
void dfs(int step,int sum)
{
    if(step > 3) return;
    if(flag) return;
    if(sum == 7&&step == 3)
    {
        for(int i = 0;i < 3;i++)
            cout << num[i] << ch[i];
        cout << num[3] << "=7";
        flag = 1;
        return;
    }
    for(int i = 0;i < 2;i++)
    {
        if(i == 0)
        {
            ch[step] = '+';
            dfs(step+1,sum+num[step+1]);
        }
        else if(i == 1)
        {
            ch[step] = '-';
            dfs(step+1,sum-num[step+1]);
        }
    }
}
int main()
{
    int a;
    while(cin >> a)
    {
        flag = 0;
        num[3] = a%10;
        a/=10;
        num[2] = a%10;
        a/=10;
        num[1] = a%10;
        a/=10;
        num[0] = a%10;
        dfs(0,num[0]);
        cout << endl;
    }
    return 0;
}


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

int main(){
	int n;
  cin >> n;
  int a[n];
  rep(i, n){
    cin >> a[i];
  }
  for(int i = n-1; i > 0; i--){
    if(a[i-1] > a[i]) a[i-1]--;
    if(a[i-1] > a[i]) {
//      cout << a[i-1] << " " << a[i] << endl;
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

int main()
{
    while(true){
        int n,m;
        cin >> n>>m;
        if(n==0&&m==0)break;
        vector<int> f;
        vector<int> a;
        int b[m],c[m];
        for(int i=0;i<m;i++){
            cin >> b[i]>> c[i];
            if(b[i]==1){
                f.push_back(c[i]);
                a.push_back(c[i]);
                }
            else if(c[i]==1){
                f.push_back(b[i]);
                a.push_back(b[i]);
                }
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<(int)f.size();j++){
                if(f[j]==b[i])a.push_back(c[i]);
                else if(f[j]==c[i])a.push_back(b[i]);
            }
        }
        set<int> ans;
        for(int i=0;i<(int)a.size();i++){
            if(a[i]!=1)ans.insert(a[i]);
        }
        cout << ans.size()<< endl;
    }

    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5+5;

int dp[2][3] = {};

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int ans = 0, n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) {
			int mx = 0, x;
			cin >> x;
			for (int k = 0; k < 3; k++) {
				if (k != j) {
					mx = max(mx, dp[(i&1)^1][k]);
				}
			}
			dp[i&1][j] = mx + x;
			ans = max(ans, mx + x);
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3616