akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N, D, A; cin >> N >> D >> A;
  D = D * 2;
  vector<pair<long long, long long>> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i).first >> P.at(i).second;
  }
  sort(P.begin(), P.end());  // 座標の小さいものから攻撃
  long long ans = 0;
  long long total = 0;  // 有効範囲内のダメージ合計
  // first: 攻撃有効範囲の右端、second: ダメージ
  queue<pair<long long, long long>> q;
  for (int i = 0; i < N; i++) {
    long long X = P.at(i).first;
    long long H = P.at(i).second;
    while (!q.empty() && q.front().first < X) {
      total -= q.front().second;  // 有効範囲外になった攻撃
      q.pop();
    }
    H -= total;
    if (H > 0) {
      long long num = (H + A - 1) / A;  // 攻撃回数
      ans += num;
      long long damage = num * A;
      total += damage;
      // この攻撃の有効範囲の右端、ダメージを queue に push
      q.push(make_pair(X + D, damage));
    }
  }
  cout << ans << endl;
}

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


int main(){
  int N;
  cin >> N;
  
  vector<int>H(N);
  for(int i = 0; i < N; i++)cin >> H[i];
  
  reverse(H.begin(),H.end());
  
  for(int i = 0; i < N; i++){
    if(i == 0)continue;
    if(H[i]-H[i-1] == 1)H[i]--;
    else if(H[i] <= H[i-1])continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3716
import collections

n = int(input())
# n = 7

# s = [ 'zenkoku', 'touitsu', 'program' ]
s = []
t = [ [], [], [] ]

for i in range(3):
    s.append(input())
    # t.append([])
    for j in range(n):
        t[i].append(s[i][j])

u = []
for j in range(n):
    u.append([])
    for i in range(3):
        u[j].append(s[i][j])

sum = 0
for j in range(n):
    c = collections.Counter(u[j])
    most = c.most_common()[0]
    sum += 3 - most[1]
    # print(most, 3 - most[1])

print(sum)


Measured memory_bytes: 3316
#include<cstdio>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int s=0,ss=0;
    int m;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&m);
        if(m%4==0)
            s++;
        if(m%2==0)
            ss++;
    }
    if(n%2==1&&s>=(n-1)/2&&n>=2)
        printf("Yes\n");
    else if(n%2==0&&s>=n/2)
        printf("Yes\n");
    else if(s+ss>=n&&n>=2)
        printf("Yes\n");
    else if(n==1&&s==1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[300];
int main()
{
    int n,l;
    int sum=0,ans=1000000000;
    int cha=0;
    cin>>n>>l;
    for(int i=1;i<=n;i++){
        a[i]=l+i-1;
        sum+=a[i];
    }
    for(int i=1;i<=n;i++){
        if(abs(sum-(sum-a[i]))<ans){
           ans=abs(sum-(sum-a[i]));
           cha=sum-a[i];
        }
    }
    printf("%d",cha);
    return 0;
}



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


int main() {
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    ll nr=1,mr=1;
    //n!
    for(int i=1;i<=n;i++)nr=(nr*i)%MOD;
    //m!
    for(int i=1;i<=m;i++)mr=(mr*i)%MOD;
    if(n==m)cout<<(2*(nr*mr))%MOD<<endl;
    else cout<<(nr*mr)%MOD<<endl;
   
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */


/* add your algorithm here */

int main() {
  string s,t;
  cin >> s; cin >> t;
  ll mmax = max(s.size(), t.size());
  map<char, int> ms, mt;
  map<int, int> as, at;

  for (auto itr : s) {
    ms[itr] += 1;
  }

  for (auto itr : t) {
    mt[itr] += 1;
  }

  for (char ch = 'a'; ch <= 'z'; ch++) {
    as[ms[ch]] += 1;
    at[mt[ch]] += 1;
  }

  for (ll i = 0; i < mmax; ++i) {
    if (as[i] != at[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 19336
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

#define debug(x) cout << #x << "==" << x << endl;

const int INF = 1e+8;

using namespace std;

//??\???
#define MAX_N 100
#define MAX_W 10000
int N, W_LIM;
int V[MAX_N], W[MAX_N];

// dp table
int dp[MAX_N][MAX_W];
bool checked[MAX_N][MAX_W];

// int n: n???????????§?????????????????£???
// int w: w??\??????????????§
// return: ?????§?????????
int rec(int i, int w) {

  if( i == -1 ) { return 0; }   // out of bounds ??????????????????!

  if(checked[i][w] == true) {return dp[i][w]; }
  checked[i][w] = true;

  int ret;

  if (w < W[i]) {
    ret = rec(i - 1, w);
  } else {
    ret = max( rec(i - 1, w), rec(i - 1, w - W[i]) + V[i]);
  }

  return dp[i][w] = ret;

}


int main() {
  ios::sync_with_stdio(false);

  cin >> N >> W_LIM;

  for(int i = 0; i < N; i++) {
    cin >> V[i] >> W[i];
  }

  cout << rec(N-1, W_LIM) << endl;

  return 0;
}

Measured memory_bytes: 7788
#include <bits/stdc++.h>
using namespace std;
 
 
void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

void textIO()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
 
int main()
{
  	//textIO();
    fastIO();
 
    map <int, int> mp;
    bool flag = true;
    int n, m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int s, c;
        cin >> s >> c;
        if(mp.find(s) ==  mp.end()){
            mp[s] = c;
        }
        else if(mp[s] != c){
            flag = false;
        }
    }
    if(!flag){
        cout << -1 << '\n';
        return 0;
    }
    if(n!= 1 && mp.find(1)!= mp.end() && mp[1] == 0){
        cout << -1 << '\n';
        return 0;
    }
    if(n == 1 && mp.find(1) == mp.end())
        mp[1] = 0;
    for(int i=1;i<=n;i++){
        if(i == 1 && mp.find(1) == mp.end()){
            mp[1] = 1;
        }
        cout << mp[i];
    }
    cout << '\n';
 
    return 0;
}

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

int main() {
  int N, i{};
  cin >> N;
  vector<int> P(N), Q(N);
  for (auto &p : P) cin >> p;
  for (auto &q : Q) cin >> q;
  if (P > Q) swap(P, Q);
  while (P != Q) next_permutation(begin(P), end(P)), ++i;
  cout << i << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

const int HEIGHT_MAX = 1000;

int main()
{
	int n, m, a;
	while (std::cin >> n >> m >> a, n != 0 || m != 0 || a != 0) {
		// ツつ?づ敖つセツづーツ渉可甘コツ可サ (ツ可。ツ静シツづ按つオ)
		std::vector< std::vector< std::pair<int, int> > > amida(HEIGHT_MAX + 1, std::vector< std::pair<int, int> >());

		// ツ可。ツ静シツづーツ暗クツつュ
		for (int i = 0; i < m; ++i) {
			int h, p, q;
			std::cin >> h >> p >> q;
			amida[h].push_back(std::pair<int, int>(p, q));
		}

		// ツつ?づ敖つセツづーツつスツづ?づゥ
		int x = a;
		for (int h = HEIGHT_MAX; h >= 0; --h) {
			for (std::vector< std::pair<int, int> >::iterator it = amida[h].begin(); it != amida[h].end(); ++it) {
				if (it->first == x) {
					x = it->second;
					break;
				} else if (it->second == x) {
					x = it->first;
					break;
				}
			}
		}

		std::cout << x << std::endl;
	}
	return 0;
}

Measured memory_bytes: 932
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
struct coo{
	int x;
	int y;
	int h;
}c[110];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>c[i].x;
		cin>>c[i].y;
		cin>>c[i].h;
	}
	int cx,cy,ch;
	int p=0;
	while(c[p].h==0) p++;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			int ch=c[p].h+abs(i-c[p].x)+abs(j-c[p].y);
			int f=0;
			for(int k=0;k<n;k++)
			{
				int hh=ch-abs(i-c[k].x)-abs(j-c[k].y);
				if(hh<0) hh=0;
				if(hh!=c[k].h)
				{
					f=1;
					break;
				}
			}
			if(!f)
			{
				cout<<i<<' '<<j<<' '<<ch<<endl; return 0;
			} 
		}
	}
	
	
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 102333
#define maxm 2333
using namespace std;
int x[maxn], y[maxn];
char c[maxn];
int cb[maxm][maxm];
int Sb[maxm][maxm];
int cw[maxm][maxm];
int Sw[maxm][maxm];
int Sum(int (*S)[maxm], int i1, int j1, int i2, int j2) {
	return S[i2][j2] - S[i1][j2] - S[i2][j1] + S[i1][j1];
//	return reinterpret_cast<long long>(&S[1][233]) - reinterpret_cast<long long>(S);
}
int main() {
	int n, k, K;
	scanf("%d%d", &n, &k);
	K = 2 * k;
	for(int i = 1; i <= n; ++i) {
		scanf("%d%d %c", x + i, y + i, c + i);
		if(c[i] == 'B') ++cb[x[i] % K + 1][y[i] % K + 1]; 
		else ++cw[x[i] % K + 1][y[i] % K + 1]; 
	}
	for(int i = 1; i <= K; ++i) {
		for(int j = 1; j <= K; ++j) {
			Sb[i][j] = Sb[i - 1][j] + Sb[i][j - 1] - Sb[i - 1][j - 1] + cb[i][j];
			Sw[i][j] = Sw[i - 1][j] + Sw[i][j - 1] - Sw[i - 1][j - 1] + cw[i][j];
		}
	}
	int ans = 0;
	for(int i = 1; i <= k + 1; ++i) {
		for(int j = 1; j <= k + 1; ++j) {
			ans = max(ans, 
						   Sum(Sb, 0, 0, i-1, j-1)
						 + Sum(Sw, 0, j-1, i-1, j+k-1)
						 + Sum(Sb, 0, j+k-1, i-1, K)
						 + Sum(Sw, i-1, 0, i+k-1, j-1)
						 + Sum(Sb, i-1, j-1, i+k-1, j+k-1)
						 + Sum(Sw, i-1, j+k-1, i+k-1, K)
						 + Sum(Sb, i+k-1, 0, K, j-1)
						 + Sum(Sw, i+k-1, j-1, K, j+k-1)
						 + Sum(Sb, i+k-1, j+k-1, K, K)
			);
			ans = max(ans, 
						   Sum(Sw, 0, 0, i-1, j-1)
						 + Sum(Sb, 0, j-1, i-1, j+k-1)
						 + Sum(Sw, 0, j+k-1, i-1, K)
						 + Sum(Sb, i-1, 0, i+k-1, j-1)
						 + Sum(Sw, i-1, j-1, i+k-1, j+k-1)
						 + Sum(Sb, i-1, j+k-1, i+k-1, K)
						 + Sum(Sw, i+k-1, 0, K, j-1)
						 + Sum(Sb, i+k-1, j-1, K, j+k-1)
						 + Sum(Sw, i+k-1, j+k-1, K, K)
			);
		}
	} 
	cout << ans;
	return 0;
}


Measured memory_bytes: 77228
n = int(input())
a = []
a.append(list(map(int,input().split())))
a.append(list(map(int,input().split())))
dp1 = [0]*n
dp2 = [0]*n
dp1[0] = a[0][0]
dp2[0] = dp1[0]+a[1][0]
for i in range(1,n):
    dp1[i] = dp1[i-1]+a[0][i]
for i in range(1,n):
    dp2[i] = max(dp1[i],dp2[i-1])+a[1][i]
print(dp2[-1])

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct s {
	int row;
	int x, y;
	int prev;
	int cost;
	int ox;
	s() {};
	s(int x_, int y_, int row_, int cost_, int ox_, int p_) {
		x = x_; y = y_;
		row = row_; prev = p_;
		cost = cost_; ox = ox_;
	}

	bool operator<(const s & obj) const{
		return this->cost > obj.cost;
	}
};

int main() {
	int H, W;
	while(cin >> W >> H, H || W) {
		int f, m, o;
		vector<vector<int> > v;
		cin >> f >> m >> o;
		for(int i = 0; i < H; i++) {
			vector<int> u;
			for(int j = 0; j < W; j++) {
				int tmp;
				cin >> tmp;
				u.push_back(tmp);
			}
			v.push_back(u);
		}

		priority_queue
 q;
		for(int i = 0; i < W; i++) {
			if(o > 1) {
				int oxadd, costadd;
				oxadd = costadd = 0;
				if(v[0][i] > 0)
					oxadd = v[0][i];
				else
					costadd = -v[0][i];
				q.push(s(i,0,1<<i,costadd,min(o-1+oxadd,m),0));
			}
		}

		int res = 1e9;
		while(!q.empty()) {
			s cur = q.top(); q.pop();
//			cout << cur.x << " " << cur.y << " " << cur.cost << endl;
			if(cur.y == H-1 && cur.ox > 0 && cur.cost <= f) {
				res = cur.cost;
				break;
			}

			// move
			if(cur.prev != -1 && cur.x-1 >= 0 && (cur.row & (1 << (cur.x-1))) && cur.ox > 1) {
				q.push(s(cur.x-1, cur.y, cur.row, cur.cost, cur.ox-1, 1));
			}
			if(cur.prev != 1 && cur.x+1 < W && (cur.row & (1 << (cur.x+1))) && cur.ox > 1) {
				q.push(s(cur.x+1, cur.y, cur.row, cur.cost, cur.ox-1, -1));
			}

			// dig
			const int dx[] = {1,-1,0};
			const int dy[] = {0,0,1};
			for(int i = 0; i < 3; i++) {
				if(cur.ox > 1 && cur.x+dx[i] >= 0 && cur.x+dx[i] < W && cur.y+dy[i] < H && !((cur.row & (1 << (cur.x+dx[i])))*dx[i])) {
					int costadd, oxadd;
					costadd = oxadd = 0;
					if(v[cur.y+dy[i]][cur.x+dx[i]] > 0)
						oxadd = v[cur.y+dy[i]][cur.x+dx[i]];
					else
						costadd = -v[cur.y+dy[i]][cur.x+dx[i]];
					
					if(cur.cost + costadd <= f)
						q.push(s(cur.x+dx[i], cur.y+dy[i], ((!dy[i]) * cur.row) | (1 << (cur.x+dx[i])), cur.cost + costadd, min(cur.ox-1 + oxadd, m), 0));
				}
			}
		}

		if(res == 1e9)
			cout << "NA" << endl;
		else
			cout << res << endl;
	}
}

Measured memory_bytes: 51516
class EmployeeRecord
  NUM_EMPLOYEE = 4000
  MILLION = 1000000
  
  def initialize
    @sales = Array.new(NUM_EMPLOYEE + 1).fill(0, 0...(NUM_EMPLOYEE+1))
  end
  
  def updateSales(id, newSales)
    @sales[id] += newSales
  end
  
  def printIdOverMillionSales(idSet)
    count = 0
    for i in 0...idSet.size
      if @sales[idSet[i]] >= MILLION
        count += 1
        puts idSet[i]
      end
    end
    puts "NA"   if count == 0
  end
end

employee = nil
while true
  n = gets.to_i
  idSet = Array.new
  break   if n == 0
  employee = EmployeeRecord.new
  n.times do
    id, price, numItems = gets.split(" ").map{|i| i.to_i}
    idSet << id   if idSet.index(id) == nil
    employee.updateSales(id, price * numItems)
  end
  employee.printIdOverMillionSales(idSet)
end

Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
const int N=2005;
long long f[N][N],fac[N*N],inv[N*N];
long long fsp(long long x,int y){
	long long ans=1;
	while(y){
		if(y&1)	ans=ans*x%P;
		x=x*x%P,y>>=1;
	}
	return ans;
}
long long C(int n,int m){
	return fac[n]*inv[m]%P*inv[n-m]%P;
}
int n,m,k;
int main(){
	scanf("%d%d",&n,&k),m=n*k;
	fac[0]=inv[0]=f[0][0]=1;
	for(int i=1;i<=m;i++){
		fac[i]=fac[i-1]*i%P;
		inv[i]=fsp(fac[i],P-2);
	}
	if(k==1){
		puts("1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
			f[i][j]=(f[i][j-1]*C(m-i-(j-1)*(k-1)-1,k-2)%P*(n-j+1)+f[i-1][j])%P;
	printf("%lld\n",f[n][n]);
	return 0;
}

Measured memory_bytes: 94464
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<int, int>;

int prim(vector<vector<P>> g)
{
  priority_queue<P, vector<P>, greater<P>> que;
  int total = 0;
  vector<bool> used(g.size(), false);
  que.emplace(0, 0);
  while(!que.empty()){
    P p = que.top();
    que.pop();
    if(used[p.second]) continue;
    used[p.second] = true;
    total += p.first;
    for(auto &v: g[p.second]){
      que.emplace(v.second, v.first);
    }
  }
  return total;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<P> px(n), py(n);
  REP(i,n){ 
    cin >> px[i].first >> py[i].first;
    px[i].second = py[i].second = i;
  }
  
  vector<vector<P>> G(n);
  sort(ALL(px));
  sort(ALL(py));
  REP(i,n-1){
    int costx = px[i+1].first- px[i].first;
    G[px[i].second].emplace_back(px[i+1].second, costx);
    G[px[i+1].second].emplace_back(px[i].second, costx);
    int costy = py[i+1].first - py[i].first;
    G[py[i].second].emplace_back(py[i+1].second, costy);
    G[py[i+1].second].emplace_back(py[i].second, costy);
  }
  cout << prim(G) << '\n';
  return 0;
}


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

using namespace std;

int main(){
	int n;
  scanf("%d",&n);
  int temp = 0;
  for(int i = 0;i<n;i++){
  	int t;
    cin>>t;
    temp^=t;
  }
  if(temp==0)
    puts("Yes");
  else
    puts("No");
  return 0;
}

Measured memory_bytes: 256
S = input()
l = sorted(list(set(S)))

ans = ""
for i in range(len(l)):
  if ord(l[i]) !=  97 + i:
    ans = chr(97+i)
    break
  elif i == 25 and l[i] == "z":
    ans = "None"

if ans != "":
 print(ans)
else:
  print(chr(ord(l[-1])+1))

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

int main(void){
    int h, w;
    cin >> h >> w;
    char ma[110][110];
    int usei[110], usej[110];
    for(int i=0;i<110;++i){
        usei[i] = 1;
        usej[i] = 1;
    }
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin >> ma[i][j];
        }
    }
    for(int i=0;i<h;++i){
        int flg=1;
        for(int j=0;j<w;++j){
            if(ma[i][j]!='.') flg=0;
        }
        if(flg) usei[i] = 0;
    }
    for(int i=0;i<w;++i){
        int flg=1;
        for(int j=0;j<h;++j){
            if(ma[j][i]!='.') flg=0;
        }
        if(flg) usej[i] = 0;
    }
    for(int i=0;i<h;++i){
        if(usei[i]==0) continue;
        for(int j=0;j<w;++j){
            if(usej[j]==0) continue;
            cout << ma[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>  
using namespace std;
 
int main() {
    int n, N;
    cin >> n;
    vector<int> data;
    for(int i=0; i<n ; i++){
      cin >> N;
      data.push_back(N);
    }
    sort(data.begin(),data.end());
    cout << data[n-1] - data[0] << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val NM = readLine()!!.split(" ").map(String::toInt)
    val res = arrayOfNulls<MutablePair<Boolean, Int>>(NM[0] + 1)
    for (i in 1..NM[1]) {
        val a = readLine()!!.split(" ")
        val p = a[0].toInt()
        val s = a[1]
        if (res[p]?.k == true) continue
        val pair = res[p] ?: MutablePair(false, 0)
        if (s == "WA") pair.v += 1
        else pair.k = true
        res[p] = pair
    }
    val ans = res.filterNotNull().filter { e -> e.k }.map { e -> e.v }
    println("${ans.size} ${ans.sum()}")
}

class MutablePair<A, B>(var k: A, var v: B)

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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll big = 1000000007ll;
const ll big2 = 1000000009ll;
ll n,m,k,q,h,T;
ll x;

vector<ll> A;
vector<ll> B;
vector<ll> C;

ll BA[100001] = {0};

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    cin >> n;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        A.push_back(a);
    }
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        B.push_back(a);
    }
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        C.push_back(a);
    }

    sort(all(A));
    sort(all(B));
    sort(all(C));

    ll ans = 0;

    ll l = 0;

    A.push_back(big);

    for(ll c1 = 0; c1 < n; c1++){
        while(A[l] < B[c1])l++;
        BA[c1] = l;
    }

    B.push_back(big);
    ll sum = 0;
    l = 0;
    for(ll c1 = 0; c1 < n; c1++){
        while(B[l] < C[c1]){
            l++;
            sum += BA[l-1];
        }
        ans += sum;
    }

    cout << ans << "\n";

    return 0;
}


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

int main(){
    int X;
    cin >> X;
    int a = 0,b =0;
    for(int a=(-1000);a<1000;a++){
        for(int b=(-1000);b<1000;b++){
            if(a>b && (a*a*a*a*a) - (b*b*b*b*b) == X){
                cout << a << " " << b << endl;
                return 0;
            }
            
        }
        
    }
    return 0;
}

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

using namespace std;
#define int long long
int slv(int n)
{
    if(n==1)
    {
        return 1;
    }
    else
    {
        int x=(n/2);
        return 2*slv(x)+1;
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    cout<<slv(n);
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
    
ans=0

for i in range(0,N+1):
    A[i]=int(A[i])
for i in range(0,N):
    B[i]=int(B[i])

for i in range(0,N):
    if A[i]-B[i]>=0:
        ans+=B[i]
    elif A[i]-B[i]<0:
        if A[i+1]-(B[i]-A[i])<0:
            ans+=A[i]+A[i+1]
            A[i+1]=0
        else :
            ans+=B[i]
            A[i+1]=A[i+1]-(B[i]-A[i])
        
print(ans)

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


int  main(){
  string s;cin>>s;
  int m=s.size()/2;
  rep(i,m){
    if(i==0){continue;}
    int n=m-i;
    string s1,s2;
    s1=s.substr(0,n);
    s2=s.substr(n,n);
    if(s1==s2){cout<<2*n;break;}
  }
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int N;
    std::cin >> N;

    std::map<int, int> Idx;
    for (int i = 0; i < N; ++i) {
        int t;
        std::cin >> t;
        Idx[t] = i;
    }

    int maxLen = 0;

    int prev = -1;
    int count = 0;
    for (auto i : Idx) {
        if (prev < i.second) {
            count ++;
            maxLen = std::max(maxLen, count);
        }
        else {
            count = 1;
        }
        prev = i.second;
    }

#if 0
    for (int i = 1; i < N; ++i) {
        int len = 1;

        auto idx = Idx[i];

        for (int n = i+1; n <= N; ++n) {
            auto succIdx = Idx[n];
            if (succIdx < idx) {
                break;
            }
            len++;
            idx = succIdx;
        }
        maxLen = std::max(maxLen, len);
    }
#endif
    std::cout << N - maxLen << std::endl;

    return 0;
}


Measured memory_bytes: 9600
import fractions

n = int(input())
Numbers =list(map(int,input().split()))

def lcm(Numbers):
    N = len(Numbers)
    if N == 1:
        return Numbers[0]
    else:
        Numbers[N-2] = \
        Numbers[N-1]*Numbers[N-2] \
        //fractions.gcd(Numbers[N-1],Numbers[N-2])
        return lcm(Numbers[0:N-1])

print(lcm(Numbers))



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

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const int MX = 200 * 1000 + 7;

int a[MX];

vector<pair<int, int> > xx[MX];
ll sm[MX];

bool good[MX];

void go(int x) {
    if (xx[x][0].first < 0) {
        good[xx[x][0].second] = true;
    } else {
        for (auto& v : xx[x]) {
            if (v.first > 0) {
                good[v.second] = true;
            }
        }
    }
}


int main() {
#ifdef BZ
    freopen("in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        xx[i % 2].emplace_back(a[i], i);
    }

    for (int i = 0; i < 2; i++) {
        sort(xx[i].rbegin(), xx[i].rend());
        if (xx[i][0].first < 0) {
            sm[i] = xx[i][0].first;
        } else {
            for (auto x : xx[i]) {
                if (x.first >= 0) {
                    sm[i] += x.first;
                }
            }
        }
    }

    int bst = -1;
    if (sm[0] > sm[1]) {
        go(0);
    } else {
        go(1);
    }

    ll an = 0;
    vector<int> x;
    for (int i = 0; i < n; i++) {
        if (good[i]) {
            an += a[i];
        }
        x.push_back(good[i]);
    }

    vector<int> st;

    while (x.size() > 1) {
        if (x[0] == 0) {
            st.push_back(0);
            x.erase(x.begin());
        } else if (x[x.size() - 1] == 0) {
            st.push_back(x.size() - 1);
            x.erase(x.begin() + (x.size() - 1));
        } else {
            for (int i = 1; i + 1 < x.size(); i++) {
                if (x[i - 1] == x[i + 1] && x[i] == 0) {
                    x[i] = x[i - 1];
                    st.push_back(i);
                    x.erase(x.begin() + (i + 1));
                    x.erase(x.begin() + (i - 1));
                    break;
                }
            }
        }
    }

    cout << an << "\n";
    cout << st.size() << "\n";
    for (int x : st) {
        cout << x + 1 << "\n";
    }
}

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

using namespace std;
int64_t mod = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<int64_t>arr(n);
    for(auto & i : arr)
        cin >> i;
    vector<int64_t>sufsum;
    sufsum.push_back(0);
    for(int i = n-1; i > 0; --i){
        auto a = sufsum.back();
        a+=arr[i];
        sufsum.push_back(a);
    }
    reverse(sufsum.begin(),sufsum.end());
    int64_t ans = 0;
    for(int i = 0 ; i < n; ++i){
        ans+=(arr[i]*(sufsum[i]%mod));
        ans%=mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6892
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#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 rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

unsigned long long factorial[1000004]; 
    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod3; 
    }*/




unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 



  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
unsigned long long nc(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
 
  
    return (factorial[n]* modInverse(factorial[r], p) % p * modInverse(factorial[n - r], p) % p) % p; 
} 



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

   ll n;
   cin>>n;
   ll a[n+1];
   fo(i,n){
       cin>>a[i+1];
   }
   ll s1=0,s2=0;
   fo(i,n){
       s1+= a[i+1];
       s1%=mod;
       s2+= (a[i+1]*a[i+1])%mod;
       s2%=mod;
   }
   
   ll p = (s1*s1)%mod;
   p -= s2;
   if(p<0){
       p+= mod;
   }
   
   p*= (modInverse(2,mod));
   p%=mod;
   cout<<p;
    

    


	return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007

int main(){
  int N;
  cin>>N;
  int odd_count=0;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    odd_count+=A%2;
  }
  if(odd_count%2==0){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 384
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include <random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

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; }
typedef pair<int, int>P;
const int MOD = 998244353;const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

struct edge { int to, cost; };
int V;//頂点数
vector<edge>G[MAX];
int d[MAX];//始点からの距離
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

void solve() {
	int N; cin >> N;
	int M; cin >> M;
	REP(i, M) {
		int l, r, c; cin >> l >> r >> c;
		l--, r--;
		G[l].push_back({ N + i,c });
		G[N + i].push_back({ l,0 });
		G[N + i].push_back({ r,0 });
		G[r].push_back({ N + i,c });
	}
	V = N+M;
	REP(i, N) {
		d[i] = INF;
		if(i<N-1)G[i + 1].push_back({ i,0 });
	}
	d[0] = 0;
	dijkstra(0);
	if (d[N - 1] == INF)print(-1);
	else print(d[N - 1]);
}


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

	solve();
}




Measured memory_bytes: 23296
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			Integer[] p = new Integer[n];
			Integer[] q = new Integer[n];
			for(int i = 0 ; i < n ; i++) {
				p[i] = sc.nextInt();
			}
			for(int i = 0 ; i < n ; i++) {
				q[i] = sc.nextInt();
			}
			// 使える数字
			List<Integer> list1 = new LinkedList<>();
			List<Integer> list2 = new LinkedList<>();
			for(int i = 0 ; i < n ; i++) {
				list1.add(p[i]);
				list2.add(p[i]);
			}
			Collections.sort(list1);
			Collections.sort(list2);
			// その桁に何個あるか
			int[] tmp = new int[n];
			tmp[n - 1] = 1;
			tmp[n - 2] = 1;
			for(int i = n - 3 ; i >= 0 ; i--) {
				tmp[i] = tmp[i + 1] * (n - 1 - i);
			}
			int a = rank(p, tmp, list1);
			int b = rank(q, tmp, list2);
			System.out.println(Math.abs(a - b));

		}
	}

	private static int rank(Integer[] p, int[] tmp, List<Integer> list) {
		int rank = 1;
		for(int i = 0 ; i < p.length - 1 ; i++) {
			int a = p[i];
			int index = list.indexOf(a);
			rank += index * tmp[i];
			list.remove(index);
		}
		return rank;
	}
}


Measured memory_bytes: 22736
import java.util.Scanner;

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

		for (int i = 1; i < 10; i++) {
			if (n <= i * 111) {
				System.out.println(i * 111);
				break;
			}
		}

	}
}

Measured memory_bytes: 21972
import numpy as np
n, l = map(int, input().split())

x = []
for i in range(n):
        x.append(l + i)
        # print(i)

# print(x)
num = 0

def nearvalue(x, num):
        idx = np.abs(np.asarray(x) - num).argmin()
        del x[idx]
        # print(x)
        print(sum(x))

nearvalue(x, 0)

Measured memory_bytes: 20368
#include <stdio.h>

int main(){
int a,b;scanf("%d%d",&a,&b);
double ret=0;
for(int i=1;i<=a;i++){
double tmp=1.0/a;
int now=i;
while(now<b){
now*=2;
tmp/=2;
}
ret+=tmp;
}
printf("%.12f\n",ret);
}

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

int main(){
    int A,B,H,M;
    long double ans;
    cin >> A >> B >> H >> M;
    long double A_deg,B_deg;
    A_deg = 30*H+(0.5*M);
    B_deg = 6*M;
    long double deg = abs((A_deg - B_deg));
    long double cdeg = abs(deg*M_PI/180.0);
    ans = sqrtl((long double)(A*A+B*B)-(long double)(2*A*B*(cosl(cdeg))));
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}

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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	string s[n];
	map<string, int> mapa;
	vector<pair<int, string>> S;
	for(int i=0; i<n; i++) {
		cin>>s[i];
		mapa[s[i]]++;
	}
	for(auto it = mapa.begin(); it!=mapa.end(); ++it) {
		S.push_back(make_pair(it->second, it->first));
	}
	sort(S.begin(), S.end());
	int maks = S[S.size()-1].first;
	vector<string> Sx;
	for(int i=S.size()-1; i>=0; i--) {
		if(S[i].first==maks)
			Sx.push_back(S[i].second);
		else
			break;
	}
	sort(Sx.begin(), Sx.end());
	for(int i=0; i<Sx.size(); i++)
		cout<<Sx[i]<<"\n";
}


Measured memory_bytes: 33004
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const long long MOD = 998244353;
void solve(long long N, long long S, std::vector<long long> A){
  ll ans=0;
  vector<vector<ll>> dp(2,vector<ll>(S+1));
  REP(N){
    ll prev=(i%2)^1;
    ll now=i%2;
    For(j,S+1){
      dp[now][j]=dp[prev][j];
    }
    For(j,S+1-A[i]){
      if(dp[prev][j]>0){
        dp[now][j+A[i]]+=(dp[prev][j])%MOD;
        dp[now][j+A[i]]%=MOD;
      }
    }
    if(A[i]<S+1){
      dp[now][A[i]]+=i+1;
      dp[now][A[i]]%=MOD;
    }
    ans+=dp[now][S];
    ans%=MOD;
  }
  cout<<ans<<endl;
}

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


Measured memory_bytes: 384
import java.util.*;
 
public class Main {
 	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		int[][] c = new int[3][3];
		int[] a = new int[3];
		int[] b = new int[3];
		boolean find = true;

		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++){
				c[i][j] = sc.nextInt();
			}
		}

		for(int i=0; i<=c[0][0]; i++){
			a[0] = i;
			for(int j=0; j<3; j++){
				b[j] = c[0][j]-a[0];
			}

			a[1] = c[1][0]-b[0];
			for(int j=0; j<3; j++){
				int b1 = c[1][j]-a[1];
				if(b1!=b[j]){
					find=false;
				}
			}
			if(find==true){
				a[2] = c[2][0]-b[0];
				for(int j=0; j<3; j++){
					int b2 = c[2][j]-a[2];
					if(b2!=b[j]){
						find=false;
					}
				}
			}
			if(find==true){
				System.out.println("Yes");
				return;
			}
			find=true;
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;
ll n,d[101]={},z[100]={};
int main(void){
  cin>>n;
  for(int i=2;i<=n;i++){
    ll a=i,j=2;
    while(a!=1){
      if(a%j!=0){
        j++;
      }
      else{
        a/=j;
        d[j]++;
      }
    }
  }
  for(int i=2;i<=n;i++){
    z[d[i]]++;
  }
  for(int j=n;j>=2;j--){
    z[j]+=z[j+1];
  }
  ll ans=z[4]*(z[4]-1)*(z[2]-2)/2+z[24]*(z[2]-1)+z[14]*(z[4]-1)+z[74];
  cout<<ans<<endl;
}

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

#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define stringtovector(s, v) {for (int i = 0; i < (s).size(); ++i) v.push_back(s[i]);};
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;
const int mod = 1000000007;




int main() {
    float n,m; int k;
    cin >> n >> m >> k;
    cout << (int) ceil(n / m) * k;
}





Measured memory_bytes: 3684
#import<cstdio>
int main(){int n,m,d,x,y,i;for(;scanf("%d",&n),n;puts(n?"No":"Yes")){int f[21][21] = {0};for(i=n;i--;f[y][x] = 1)scanf("%d %d",&x,&y);scanf("%d",&m);x=y=10;for(i=m;i--;)for(scanf(" %c %d",&m,&d);d--;f[y][x]?n--,f[y][x]=0:0)x+=m==69?1:m==87?-1:0,y+=m==78?1:m==83?-1:0;}}

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

int main(){
	string ans="Good";
	
	string s;
	rep(i,4){
		cin >> s[i];
	}
	rep(i,3){
		if(s[i] == s[i+1]) ans = "Bad";
	}
	cout << ans << endl;
	return 0;
}


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

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

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

int main() {
    int N, Y;
    cin >> N >> Y;
    int ans = 0;
    int cst = Y-1000*N;
    rep(x,N+1)rep(y,N+1) {
    	int z = N-x-y;
    	int sum = 9000*x+4000*y;
    	if (sum == cst and 0 <= z) {
    		cout << x << " " << y << " " << z << endl;
    		return 0;
    	}
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
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; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int k, t;
  cin >> k >> t;
  vi a(t);
  rep(i, t) cin >> a[i];
  int m = distance(a.begin(), max_element(all(a)));
  cout << max(0LL, a[m] - 1 - (k - a[m])) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<climits>

typedef long long LL;
using namespace std;
const int mod = 998244353, maxn = 5e5 + 10;

int read()
{
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}

int fac[maxn], ifac[maxn], inv[maxn];

int C(int N, int M) { return (LL)fac[N] * ifac[M] % mod * ifac[N - M] % mod; }

int Pow(int x, int p)
{
	int r = 1;
	while(p)
	{
		if(p & 1) r = (LL)x * r % mod;
		x = (LL)x * x % mod; p >>= 1;
	}
	return r;
}

int main()
{

	int n = read(), m = read();

	fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;
	for(int i = 2; i <= max(n, m); ++i)
	{
 		fac[i] = (LL)fac[i - 1] * i % mod;
		inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod;
		ifac[i] = (LL)ifac[i - 1] * inv[i] % mod;
	}

	int ans = 0;
	for(int k = 0; k <= min(n, m); ++k)
		(ans += (LL)C(n, k) * C(m, k) % mod * fac[k] % mod * Pow(m + 1, n - k) % mod * Pow(n + 1, m - k) % mod * Pow(mod - 1, k) % mod) %= mod;
	cout << (ans + mod) % mod << endl;

	return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define maxn 110
#define ll long long
using namespace std;
const int mod=1e9+7;
int h[maxn],a[maxn],b[maxn],sz,n;

ll qpow(ll a,ll x)
{
    ll ret=1;
    while(x>0)
    {
        if(x&1) ret=ret*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return ret;
}
ll cal(int lb,int ub)
{
    ll ret=qpow(2,ub+1)+mod-qpow(2,lb);
    if(ret>=mod)ret-=mod;
    return ret;
}
ll dp[maxn][maxn];
void upd(int &x,int y)
{
    x=(x+y>=mod?x+y-mod:x+y);
}
int main()
{
    scanf("%d",&n);
    h[sz++]=1;
    for(int i=0;i<n;++i)
    {
        scanf("%d",&a[i]);
        h[sz++]=a[i];
    }
    sort(h,h+sz); sz=unique(h,h+sz)-h;
    dp[0][0]=2;
    for(int i=0;i<n;++i) b[i]=lower_bound(h,h+sz,a[i])-h;
    for(int i=1;i<=b[0];++i)
    {
        int ub=a[0]-(h[i-1]+1)+1;
        int lb=a[0]-(h[i])+1;
        //printf("h[%d]=%d,lb=%d,ub=%d\n",i,h[i],lb,ub);
        dp[0][i]=cal(lb,ub);
    }

    for(int i=1;i<n;++i)
    {
        dp[i][0]=dp[i-1][0]*2%mod;
        ll t=qpow(2,max(0,a[i]-a[i-1]));
        for(int j=1;j<=b[i];++j)
            if(dp[i-1][j])
                dp[i][j]=(dp[i][j]+dp[i-1][j]*t)%mod;
        for(int j=b[i]+1;j<sz;++j)
            if(dp[i-1][j])
            dp[i][0]=(dp[i][0]+dp[i-1][j]*2)%mod;
        if(b[i]>b[i-1])
        {
            for(int j=b[i-1]+1;j<=b[i];++j)
            {
                int ub=a[i]-(h[j-1]+1)+1;
                int lb=a[i]-(h[j])+1;
                ll ret=cal(lb,ub);
                dp[i][j]=(dp[i][j]+dp[i-1][0]*ret)%mod;
            }
        }
    }
    int ans=0;
    for(int i=0;i<sz;++i)
    {
        ans+=dp[n-1][i];
        if(ans>=mod) ans-=mod;
    }
    printf("%d\n",ans);
        //for(int j=len+1;j<sz;++j)
    return 0;
}


Measured memory_bytes: 384
// -*- coding:utf-8-unix -*-

use proconio::input;

// NOT WORK

fn root(v: &Vec<usize>, k: usize) -> usize {
    if v[k] == k {
        k
    } else {
        root(&v, v[k])
    }
}

fn main() {
    input! {
        n: usize,
        m: usize,
    }

    // constraint
    if m == 0 {
        println!("1");
        return;
    }

    let mut grp = 0;
    let mut vgrp = vec![0; n + 1];
    let mut vparent = vec![];
    for i in 0..n + 1 {
        vparent.push(i);

    }
    // let idx = vparent.clone();
    let mut vgrpnum = vec![0; n + 1];
    for _ in 0..m {
        input! {
            a: usize,
            b: usize,
        }
        // println!("a, b: {}, {}", a, b);
        if vgrp[a] == 0 && vgrp[b] == 0 {
            // new
            grp += 1;
            vgrp[a] = grp;
            vgrp[b] = grp;
            vgrpnum[grp as usize] = 2;
        } else {
            let root_a = root(&vparent, vgrp[a]);
            let root_b = root(&vparent, vgrp[b]);
            if root_a == 0 && root_b != 0 {
                // add a to group b
                vgrp[a] = root_b;
                vgrpnum[root_b] += 1;
            } else if root_a != 0 && root_b == 0 {
                // add b to group a
                vgrp[b] = root_a;
                vgrpnum[root_a] += 1;
            } else if root_a != root_b {
                if vgrpnum[root_b] < vgrpnum[root_a] {
                    // merge b to a
                    vgrp[b] = root_a;
                    vparent[root_b] = root_a;
                    vgrpnum[root_a] += vgrpnum[root_b];
                    vgrpnum[root_b] = 0;
                } else {
                    // merge a to b
                    vgrp[a] = root_b;
                    vparent[root_a] = root_b;
                    vgrpnum[root_b] += vgrpnum[root_a];
                    vgrpnum[root_a] = 0;
                }
            }
        }
        // println!("idx:     {:2?}", idx);
        // println!("vgrp:    {:2?}", vgrp);
        // println!("vparent: {:2?}", vparent);
        // println!("vgrpnum: {:2?}\n", vgrpnum);
    }

    let mut ans = 0;
    for i in 0..vgrpnum.len() {
        ans = ans.max(vgrpnum[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 8052
program main
  implicit none
  integer :: n, i, res
  integer, allocatable :: h(:)
  read (*, *) n
  allocate (h(n))
  read (*, *) h(:)
  res = 1
  do i = 2, n
    if (h(i) >= maxval(h(1:i - 1))) then
      res = res + 1
    end if
  end do
  write (*, "(i0)") res
end program main


Measured memory_bytes: 256
N = int(input().strip())
A= [int(x) for x in input().strip().split(" ")]

minus_list = filter(lambda x: x<0,A)
minus_cnt = len(list(minus_list))

abs_list = list(map(abs,A))

if minus_cnt % 2 == 0:
    print(sum(abs_list))
else:
    print(sum(abs_list) - 2* min(abs_list))


Measured memory_bytes: 14412
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    a = input()
    print(a[:4] + ' ' + a[4:])



if __name__ == '__main__':
    main()



Measured memory_bytes: 38256
#各配点の問題について、全て解くor全く解かないを決める
#点数に満たない場合は、配点のうち最も高いものを足りない分解く

d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]
ans = float('inf')

#まずはbitの列挙、一つずつ探索する
for bit in range(1<<d):
    count = 0
    sum = 0
    #残った配点を列挙するためにsetを用意しておく
    nokori = set(range(1,d+1))

    for i in range(d):
        #各bitが1の場合は解く, i=0は一桁目=1問目を見ている
        if bit & (1<<i):
            sum += pc[i][0] * (100*(i+1)) + pc[i][1]
            count += pc[i][0]
            #set.discard('x')で集合から'x'を削除する
            #i=0 -> 1桁目 -> discard(i+1), set(1, ..., d)
            nokori.discard(i+1)

    #合計sumが求めるgに達していない場合の処理をする
    #足すのは最大のものだけ、それ以外の場合は他のbitで処理
    #sumがgに足りないときはansに入れない
    if sum < g:
        #用いるのは、nokori集合の配点が最大のもの
        use = max(nokori)
        #解く問題数nを設定する
        #(g-sum): 必要な点数、use*100: 1問あたりの点数、切り上げて求める。最大はpi
        n = min(pc[use-1][0], -(-(g-sum)//(use*100)))
        count += n
        sum += n * use * 100
    #sumがgを超えた場合だけ、ansと比較する
    if sum >= g:
        ans = min(ans, count)

print(ans)



Measured memory_bytes: 3064