akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[][] a = new char[n][n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.next().toCharArray();
        }
        char[][] b = new char[m][m];
        for (int i = 0; i < m; i++) {
            b[i] = sc.next().toCharArray();
        }

        for (int startY = 0; startY <= n - m; startY++) {
            for (int startX = 0; startX <= n - m; startX++) {
                boolean hasMatch = true;

                loop : for (int i = 0; i < m; i++) {
                    for (int j = 0; j < m; j++) {
                        if (a[startY + i][startX+j] != b[i][j]) {
                            hasMatch = false;
                            break loop;
                        }
                    }
                }

                if (hasMatch) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");

    }
}


Measured memory_bytes: 35688
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int n,k,ans;

int main(){
	cin>>n;
	for(int i=0;;i++){
		if(i*7>n)break;
		for(int j=0;;j++){
			if(j*4+i*7>n)break;
			if(j*4+i*7==n){
			printf("Yes\n");
			return 0;
			}
		}
	}

		printf("No\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <map>

int main(){
    int n, m, l;

    std::cin >> n >> m >> l;

    std::vector<std::vector<long long> > v(n, std::vector<long long>(m));
    std::vector<std::vector<long long> > v2(m, std::vector<long long>(l));
    std::vector<std::vector<long long> > ans(n, std::vector<long long>(l));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            std::cin >> v[i][j];
        }
    }

    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            std::cin >> v2[i][j];
        }
    }

    for (int i = 0; i < n * l; i++) {
        long long sum = 0;
        for (int j = 0; j < m; j++) {
            sum += v[i / l][j] * v2[j][i % l];
        }
        ans[i / l][i % l] = sum;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            std::cout << ans[i][j] << (j != l - 1 ? " " : "");
        }
        std::cout << std::endl;
    }

    return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define pll              pair<long,long>
#define pii              pair<int,int>
#define scn(a)           scanf("%d", &a)
#define scn2(a, b)       scanf("%d%d", &a, &b)
#define scn3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pairl            pair<ll , ll >
#define scnl(a)          scanf("%lld", &a)
#define scnl2(a, b)      scanf("%lld%lld", &a, &b)
#define scnl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define scns(s)          scanf("%s",s)
#define prts(s)          printf("%s\n",s)
#define prt(a)           printf("%d\n", a)
#define prtl(a)          printf("%lld\n", a)
#define prs(a)           printf("%d ", a)
#define prt2(a, b)       printf("%d %d\n", a, b)
#define prt3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)          printf("%lld ", a)
#define prtl2(a, b)      printf("%lld %lld\n", a, b)
#define prtl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define ptcs(a)          printf("Case %d: ", a)
#define pf               printf
#define sc               scanf
#define vi               vector<int >
#define vil              vector<ll >
#define pb               push_back
#define mem(a, b)        memset((a), (b), sizeof(a))
#define lg2(n)           (31-__builtin_clz(n))
#define N                300005
#define inf              999999999
#define ll               long long
#define ull              unsigned long long
#define MIN              INT_MIN
#define MAX              INT_MAX
#define fast             ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type, less<int >, rb_tree_tag, tree_order_statistics_node_update> odrst;
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
//________________________________________________________________________________________________________________

int main()
{
    fast;
    ll n,a,b,x,y;
    cin>>n>>a>>b;
    if((b-a)%2==0)
    {
        cout<<(b-a)/2<<endl;
        return 0;
    }
    if((b-a)==1)
    {
        cout<<min(b-1,n-a)<<endl;
        return 0;
    }
    cout<<min((a+(b-a-1)/2),(n-b+1+(b-a-1)/2))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int main()
{
    int n,Y;
    while(cin>>n>>Y){
        Y/=1000;
        if(n*10<Y||n>Y){
            cout<<-1<<" "<<-1<<" "<<-1<<endl;
            continue;
        }
        int flag=0;
        for(int i=n;i>=0;i--){
            for(int j=n-i;j>=0;j--){
                for(int l=n-i-j;l>=0;l--){
                    if((i+j+l==n)&&(i*10+j*5+l==Y)){
                        cout<<i<<" "<<j<<" "<<l<<endl;
                        flag=1;
                        break;
                    }
                }
                if(flag) break;
            }
            if(flag) break;
        }
        if(!flag) cout<<-1<<" "<<-1<<" "<<-1<<endl;
    }
    return 0;
}


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

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x[3][3];
    for (int i = 0; i < 3; i ++) {
        for (int j = 0; j < 3; j ++) {
            cin >> x[i][j];
        }
    }
    int n, z;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> z;
        for (int j = 0; j < 3; j ++) {
            for (int k = 0; k < 3; k ++) {
                if (z == x[j][k]) {
                    x[j][k] = -1;
                }
            }
        }
    }
    int a = 0, b = 0;
    bool bingo = false;
    for (int i = 0; i < 3; i ++) {
        for (int j = 0; j < 3; j ++) {
            if (x[i][j] == -1) {
                a ++;
            }
            if (x[j][i] == -1) {
                b ++;
            }
        }
        if (a == 3 || b == 3) {
            bingo = true;
        }
        a = 0; b = 0;
    }
    a = 0; b = 0;
    for (int i = 0; i < 3; i ++) {
        if (x[i][i] == -1) {
            a ++;
        }
    }
    if (a == 3) {
        bingo = true;
    }
    if ((x[2][0] == -1 && x[1][1] == -1) && x[0][2] == -1 ) {
        bingo = true;
    }
    if (bingo) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

vint dx = {0,-1,1,0};
vint dy = {-1,0,0,1};
signed main(){
  int h,w;
  cin >> h >> w;
  vstring S(h);
  rep(i,h) cin >> S[i];
  int ans = 0;
  rep(i,h) rep(j,w){
    if(S[i][j] == '.'){
      vvint judge(h,vint(w,-1));
      queue<P> que;
      judge[i][j] = 0;
      que.push(make_pair(i,j));
      while(que.size() > 0){
        P use = que.front();
        int ox = use.first;
        int oy = use.second;
        //cout << "ox" << ox << "oy" << oy << endl;
        rep(s,4){
          int nx = ox + dx[s];
          int ny = oy + dy[s];
          if(0 <= nx && nx < h && 0 <= ny && ny < w){
            if(S[nx][ny] == '.' && judge[nx][ny] == -1){
              judge[nx][ny] = judge[ox][oy] + 1;
              //cout << "nx" << nx << "ny" << ny << " " << judge[nx][ny] << endl;
              que.push(make_pair(nx,ny));
              ans = max(ans,judge[nx][ny]);
            }
          }
        }
        que.pop();
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

S = input()
S_list = list(S)

tmp = [''] * (2 * 10**5)
tmp.extend(S_list)
tmp.extend([''] * (2 * 10**5))

Q = int(input())

rev = False
front_i = 2 * 10**5
end_i = front_i + len(S_list)
for i in range(Q):
    query = input()
    if len(query) == 1:
        # Type 1
        rev = not rev
    else:
        # Type 2
        [N, F, C] = [i for i in query.split()]
        F = int(F)
        front_flag = True
        if F == 2:
            front_flag = False
        if rev:
            front_flag = not front_flag
        
        if front_flag:
            front_i -= 1
            tmp[front_i] = C
        else:
            tmp[end_i] = C
            end_i += 1

if rev:
    print(''.join(reversed(tmp)))
else:
    print(''.join(tmp))

Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n],i;
  for(i=0;i<n;i++) cin>>a[i];
  int f[n],b[n];
  f[0]=a[0];
  for(i=1;i<n;i++)
  {
    f[i]=a[i];
    f[i]+=f[i-1];
  }
  b[n-1]=0;
  for(i=n-2;i>=0;i--)
  {
    b[i]=a[i+1]+b[i+1];
    
  }
  //for(i=0;i<n-1;i++) cout<<f[i]<<" "<<b[i]<<endl;
  int ans=INT_MAX;
  for(i=0;i<n-1;i++)
  {
    ans=min(ans,abs(f[i]-b[i]));
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	n %= 10;

	string ans="hon";
	if(n==0 || n==1 || n== 6 || n==8) ans="pon";
	if(n==3) ans="bon";

	cout << ans << endl;

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,ans=0;
int a[200000],cnt[200000];
int cntd[200000];
set<int>st;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        st.insert(a[i]);
    }
    sort(a,a+n);
    rep(i,n){
        cnt[a[i]]=upper_bound(a,a+n,a[i])-lower_bound(a,a+n,a[i]);
    }
    rep(i,n){
        cntd[a[i]]=cnt[a[i]-1]+cnt[a[i]]+cnt[a[i]+1];
        
    }
    rep(i,n)ans=max(ans,cntd[a[i]]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6528
n,m = gets.chomp.split(" ").map(&:to_i);
a = gets.chomp.split(" ").map(&:to_i);

sum = 0
for i in 0..(a.length-1) do
	sum = sum +a[i]
end

count = 0
for i in 0..(a.length-1) do
	if a[i]*4*m >=sum then
		count +=1
	end
end


if count >=m then
	puts "Yes"
else
	puts"No"
end


Measured memory_bytes: 14344
#include <stdio.h>
#define MAX 200


 //对数据进行判断。如果A>B,输出0；如果A!=B &&N==1 输出0；如果A==B，输出1；
//将组合问题，转化为数学问题。
//组合数，((N-1)B+A)+1-((N-1)A+B)=(B-A)(N-2)+1
int main(){
    int n,a,b;

    scanf("%d %d %d",&n,&a,&b);
    if(a>b || ((a!=b)&&n==1)){
        printf("0");
        return 0;
    }
    if(a==b){
        printf("1");
        return 0;
    }
    printf("%lld",(long long)(b-a)*(n-2)+1);
    return 0;
        
}


Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;

    int count[2][26] = {0};
    bool possible = false;

    if(s == t){
        possible = true;
    }
    else
    {
        for(int i=0;i<s.length();++i)
        {
            s = s[s.length() - 1] + s.substr(0, s.length() - 1);
            if ( s == t )
            {
                possible = true;
                break;
            }
        }
    }
    cout << (possible ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	if(s.compare(t)<0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n];
map<int,int> mp;
for(int i=0;i<n;i++)
    {cin>>arr[i];
    mp[arr[i]]+=1;
    }
int ans=0;
for(int i=0;i<n;i++)
    ans+=arr[i];
int t;
cin>>t;
while(t--)
{

   int a,b;
   cin>>a>>b;
   int x=mp[a];
   ans-=a*x;
   ans+=x*b;
   mp[a]-=x;
   mp[b]+=x;
   cout<<ans<<endl;
}















    return 0;
}


Measured memory_bytes: 10120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
char s[maxn];

int main() {
    scanf("%s", s);
    int cnt = 0, l = strlen(s);
    ll ans = 0;
    for(int i = 0; i < l; ++i) {
        if(s[i] == 'W') ans += i - cnt, cnt++;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  string s;
  cin >> s;
  bool ans = s[2]==s[3] && s[4]==s[5];
  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 888
#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, k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i, n) cin >> x[i];

  int ans = 2e9;
  for (int l = 0; l + k - 1 < n; ++l) {
    int r = l + k - 1;
    if (x[l] >= 0) ans = min(ans, x[r]);
    else if (x[r] <= 0) ans = min(ans, -x[l]);
    else if (x[r] + x[l] >= 0) ans = min(ans, -2 * x[l] + x[r]);
    else ans = min(ans, 2 * x[r] - x[l]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int a[105];
int main()
{
    int n;
    ll ans=1e17,sum;
    cin>>n;
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    for(int i=1; i<=100; i++)
    {
        sum=0;
        for(int j=1; j<=n; j++)
        {
            sum+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,sum);
    }
    cout<<ans;
    return 0;
}


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

int main(){
  string s,t;cin>>s>>t;
  bool ans=false;
  for(int i=0;i<s.size();i++){
    if(s==t){
      ans=true;
      break;
    }
    s=s.back()+s.substr(0,s.size()-1);
  }
  if(ans){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

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

void xpaint(int field[110][110], int init, int end);
void ypaint(int field[110][110], int init, int end);
int main() {
	int field[110][110] = { };
	int w, h, n;
	cin >> w >> h >> n;
	vector<int> x(n);
	vector<int> y(n);
	vector<int> z(n);
	
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}

	for (int i = 0; i < n; i++) {
		switch (z[i]) {
		case 1:
			xpaint(field, 0, x[i]);
			break;
		case 2:
			xpaint(field, x[i], w);
			break;
		case 3:
			ypaint(field, 0, y[i]);
			break;
		case 4:
			ypaint(field, y[i], h);
			break;
		}
	}

	int cnt = 0;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (field[i][j] == 0) cnt++;
		}
	}

	cout << cnt << endl;
	return 0;
}

void xpaint(int field[110][110], int init, int end) {
	for (int i = init; i < end; i++) {
		for(int j=0; j < 110; j++) {
			field[i][j]++;
		}
	}
}

void ypaint(int field[110][110], int init, int end) {
	for (int i = init; i < end; i++) {
		for (int j = 0; j < 110; j++) {
			field[j][i]++;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int n;
    cin>>n;

    vector<int> primes;
    for (int i = 2; i < 100001; i++) {
        bool find = true;
        for (auto p : primes) {
            if (p > (int)sqrt(i)) break;
            if (i % p == 0) find = false;
        }
        if (find) primes.push_back(i);
    }

    int cnt = 0;
    rep(i, n) {
        int a;
        cin>>a;
        bool find = true;
        for (auto p : primes) {
            if (p > (int)sqrt(a)) break;
            if (a % p == 0) find = false;
        }
        if (find) cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3252
function  parse_int(x)
    parse(Int, x)
end
function  MAP()
    map(parse_int, split(readline(), " "))
end
function INPUT()
    parse(Int, readline())
end
function test()
    list = 1:10
    println("$list")
    
end
function addstr(n)
    if n <= 25
        character = 'a' + n
        return character
    end
    return addstr(div(n, 26) - 1) * addstr(n % 26)
    
end
function solve()
    num = INPUT()
    println("$(addstr(num - 1))")
end
solve()

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

int Print(int a[], int p){
    for(int i=0;i<p;i++){
        if(i>0)printf(" ");
        printf("%d",a[i]);
    }
	printf("\n");
}

int main(){
    int n;
    int a[100];
    cin >> n ;
    for(int i=0;i<n;i++)cin >> a[i] ;
    int count = 0 ;
    
    for(int i=0;i<n-1;i++){
        int ind = i ;
        for(int j=i;j<n;j++){
            if(a[j]<a[ind]){
                ind = j ;
            }
        }
        int tmp = a[i];
        a[i] = a[ind];
        a[ind] = tmp;
        if(i!=ind)count++;
    }
    Print(a,n);
    cout << count << endl;

    return 0 ;
}



Measured memory_bytes: 3216
n = int(input())
h = list(map(int,input().split()))
dp = [0, abs(h[1]-h[0])]
for i in range(n-2):
    dp.append(min(dp[i]+abs(h[i+2]-h[i]), dp[i+1]+abs(h[i+2]-h[i+1])))
print(dp[n-1])

Measured memory_bytes: 55656
K,A,B = map(int,input().split())
if B <= A+1:
    print(K+1)
else:
    K = K - A + 1
    if K%2 == 0:
        print(int(K//2)*(B-A) + A)
    else:
        print(int(K//2)*(B-A) + A + 1)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { -1, 0, 1, 0, -1, 1, -1, 1 };

const int N = 20;
int visit[N][N];
int main(){
	int h, w;
	while (cin >> h >> w, h){
		vector<string> vs(h);
		rep(i, h) cin >> vs[i];

		map<string, int> m;
		rep(i, h) rep(j, w) rep(d, 8){
			MEMSET(visit, 0);
			string s;
			s += vs[i][j];
			visit[i][j] = 1;
			int nx = (j + dx[d] + w) % w, ny = (i + dy[d] + h) % h;
			while (!visit[ny][nx]){
				s += vs[ny][nx];
				++m[s];
				nx = (nx + dx[d] + w) % w, ny = (ny + dy[d] + h) % h;
			}
		}
		pair<int, string> ans = MP(0, "0");
		for (auto p : m){
			if (p.second > 1) ans = min(ans, MP(-(int)p.first.size(), p.first));
		}
		cout << ans.second << endl;
	}

	return 0;
}

Measured memory_bytes: 36032
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,m;
	cin>>n>>m;
	cout<<(n*(n-1))/2+(m*(m-1))/2<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int *n = malloc(sizeof(n)), *x = malloc(sizeof(int)), *count = malloc(sizeof(int)), max = 0;
	char *s = malloc(200005 * sizeof(char));
	scanf("%s", s);
	*n = strlen(s);
	*x = 0;
	*count = 0;
	for (int i=0; i<*n; ++i) {
	    if(s[i]=='A')
	        max=1;
	    if (s[i]=='Z' && max)
	        ++*x;
	} max = 0;
	for (int i=0; i<*n; ++i) {
	    if ((s[i]=='A' && *x) || (max && *x)) {
	        max = 1;
	        ++(*count);
	        if(s[i]=='Z')
	            --*x;
	    }
	}
	printf("%d\n", *count);
	return 0;
}

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

int main() {
	int a, b, c, x, ans = 0;
	cin >> a >> b >> c >> x;
	for (int i = 0;i <= a;i++) {
		for (int j = 0;j <= b;j++) {
			for (int k = 0;k <= c;k++) {
				if (x == 500 * i + 100 * j + 50 * k)ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a[][]=new int[3][3];
		int ans[][]=new int[3][3];
		for(int i=0;i<3;i++) {
			for(int j=0;j<3;j++) {
				a[i][j]=scan.nextInt();
				ans[i][j]=0;
			}
		}
		int n=scan.nextInt();
		int b[]=new int[n];
		for(int i=0;i<n;i++) {
			b[i]=scan.nextInt();
		}
		scan.close();

		for(int k=0;k<n;k++) {
			for(int i=0;i<3;i++) {
				for(int j=0;j<3;j++) {
					if( a[i][j] == b[k]) {
						ans[i][j]=1;
					}
				}
			}
		}
		int check=0;
		for(int i=0;i<3;i++) {
			int cnt = 0;
			for(int j=0;j<3;j++) {
				cnt+=ans[i][j];
			}
			if(cnt == 3) {
				check=1;
				break;
			}
		}
		for(int i=0;i<3;i++) {
			int cnt = 0;
			for(int j=0;j<3;j++) {
				cnt+=ans[j][i];
			}
			if(cnt == 3) {
				check=1;
				break;
			}
		}
		int cnt=0;
		for(int j=0;j<3;j++) {
			cnt+=ans[j][j];
		}
		if(cnt == 3) {
			check=1;
		}
		cnt=0;
		for(int j=0;j<3;j++) {
			cnt+=ans[2-j][j];
		}
		if(cnt == 3) {
			check=1;
		}

		System.out.println((check==1)? "Yes":"No");
	}
}

Measured memory_bytes: 23764
N=int(input())
S=list(input())
x=N-((N//26)*26)
empty=[]
for i in S:
    if ord(i)+x>90:
        a=chr(ord(i)+x-26)
        empty.append(a)
    else:
        a=chr(ord(i)+x)
        empty.append(a)
y=''.join(empty)
print(y)

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);
    string n; cin>>n;

    ll cnt = 0;
    for(auto e:n){
        cnt += (ll)(e - '0');
    }

    if(cnt%9==0) puts("Yes");
    else puts("No");

    return 0;

}

Measured memory_bytes: 3752
// b.go
package main

import (
	"fmt"
)

func abs(a float64) float64 {
	if a > 0 {
		return a
	}
	return -a
}

func average(t, x float64) float64 {
	return t - x*0.006
}

func main() {
	var (
		n       int
		t, a, h float64
	)
	fmt.Scanln(&n)
	fmt.Scanln(&t, &a)
	min := 100000000.0
	ans := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&h)
		d := abs(average(t, h) - a)
		if d < min {
			min = d
			ans = i
		}
	}
	fmt.Println(ans + 1)
}


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

int main() {
    int n, k, q;
    cin >> n >> k >> q;

    int pat[n] = {0};
    rep(i, q) {
        int a;
        cin >> a;
        a--;
        pat[a]++;
    }

    rep(i, n) {
        if (k - q + pat[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

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

    int D;
    cin >> D;
    vector<int> c(26), cc(26);
    rep(i, 26) {
        cin >> c[i];
        cc[i] = c[i];
    }
    vector<vector<int>> s(D);
    rep(i, D) {
        s[i].resize(26);
        rep(j, 26) cin >> s[i][j];
    }


    int v = 0;
    rep(d, D) {
        int x = -1;
        int best = -1000000;
        rep(i, 26) {
            int tmp = s[d][i] - cc[i];
            if (best < tmp) {
                x = i;
                best = tmp;
            }
        }
        cout << (x+1) << endl;
        rep(i, 26) {
            if (i == x) {
                cc[i] = c[i];
            } else {
                cc[i] += c[i];
            }
        }
    }

    return 0;
}




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

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
  int n,k;

  cin >>n>>k;
  COMinit();
  for(int i=1;i<=k;i++){
    cout<<COM((n-k+1),i)%MOD*COM(k-1,i-1)%MOD<<endl;
  }

}


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

typedef long long ll;

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

    int h,w;
    cin >> h >> w;
    char s[55][55];
    for(int i=0;i<55;i++){
        for(int j=0;j<55;j++){
            if(i==0 || j==0 || i>h || j>w) s[i][j] = '.';
            else cin >> s[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(s[i][j]=='#'){
                if(s[i+1][j]=='.' && s[i-1][j]=='.' && s[i][j+1]=='.' && s[i][j-1]=='.'){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(void){
  int N;
  float v[50];
  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> v[i];
  }
  sort(v,v+N);
  for(int i = 0;i<N-1;i++){
    v[i+1] = (v[i]+v[i+1])/2;
  }
  cout << v[N-1] << endl;
}

Measured memory_bytes: 888
#include<stdio.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
int main(){
  while(1){
    int n, k, i, sum = 0, ans = 0, nums[100000];
    scanf("%d%d", &n, &k);
    if(n ==0 && k == 0)return 0;
    for(i = 0;i < n;i++){
      scanf("%d", nums + i);
    }
    for(i = 0;i < k;i++){
      sum += nums[i];
    }
    ans = sum;
    for(i = k;i < n;i++){
      sum -= nums[i - k];
      sum += nums[i];
      ans = max(ans, sum);
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 988
program kth_term
  integer :: k
  integer, dimension(32) :: a = (/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/)
  read(*,*) k
  write(*,'(i0)') a(k)
end program kth_term

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = 1;
        int b = 1;

        while (true) {
            a = scanner.nextInt();
            b = scanner.nextInt();
            if (a > b) {
                int c;
                c = a;
                a = b;
                b = c;
            }
            if (a == 0 && b ==0) {
                break;
            }
            System.out.println(a + " " + b);
        }
    }
}

Measured memory_bytes: 35844
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

long long power(long long x,long long y){
   long long ans=1;
   x %= MOD;
   if(y < 0) return 0;
   while(y){
      if(y & 1) ans = (ans*x) %MOD;
      x = x*x % MOD;
      y /= 2;
   }
   return ans;
}
 
long long inv(long long x){
   return power(x,MOD-2);
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,k;
   cin >> n >> k;
   int ans = 0;
   vector<int> A(k+1);
   A[1] = power(k,n);
   for(int i=k;i>=2;i--){
      int mul = k/i;
      A[i] += power(mul,n);
      A[i] %= MOD;
      for(int j=2;j*j<=i;j++){
         if(i%j == 0){
            A[j] -= A[i];
            A[j] += MOD;
            A[j] %= MOD;
            if(i/j != j){
               A[i/j] -= A[i];
               A[i/j] += MOD;
               A[i/j] %= MOD;
            }
         }
      }
      A[1] -= A[i];
      A[1] += MOD;
      A[1] %= MOD;
   }
   f(i,1,k+1){
      ans += i*A[i];
      ans %= MOD;
   }
   cout << ans << '\n';

   return 0;
} 


Measured memory_bytes: 3988
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[10000];
    for (int i = 0; i < n; i++)
    {
        a[i] = i+1;
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i == n - 1)cout << endl;
        if (i != n - 1)cout << " ";
    }
    while (next_permutation(a,a+n))
    {
        for (int i = 0; i < n; i++)
        {
            cout << a[i];
            if (i == n - 1)cout << endl;
            if (i != n - 1)cout << " ";
       }
    }
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <string>
#define FIN freopen("inputs.txt", "r", stdin)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define f first
#define s second

int main(){
    // FIN;
    ll a, b, k;
    cin>>a>>b>>k;
  	if(a+b<=k)
    {
      cout<<0<<" "<<0<<endl;
    }
  	else
    {
      if(a>=k)
      	cout<<a-k<<" "<<b<<endl;
      else
        cout<<0<<" "<<b-(k-a)<<endl;
    }
    return 0;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    int d = a[i-1] + a[i] - x;
    if (d > 0) {
      if (a[i] >= d) a[i] -= d;
      else {
        a[i] = 0;
        a[i-1] -= d - a[i];
      }
      ans += d;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		long a = in.nextLong();
		String ios = in.next();
		long b = in.nextLong();
		long ans;

		if (ios.charAt(0) == '+')
			ans = a + b;
		else
			ans = a - b;

		out.println(ans);
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
} 


Measured memory_bytes: 23380
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Azhan Khan
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DKnapsack1 solver = new DKnapsack1();
        solver.solve(1, in, out);
        out.close();
    }

    static class DKnapsack1 {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int w = in.nextInt();

            int[] weights = new int[n];
            int[] values = new int[n];

            for (int i = 0; i < n; i++) {
                weights[i] = in.nextInt();
                values[i] = in.nextInt();
            }

            long[][] dp = new long[n + 1][w + 1];

            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= w; j++) {
                    if (i == 0 || j == 0) {
                        dp[i][j] = 0;
                    } else if (weights[i - 1] <= j) {
                        dp[i][j] = Math.max(values[i - 1] + dp[i - 1][j - weights[i - 1]], dp[i - 1][j]);
                    } else dp[i][j] = dp[i - 1][j];
                }
            }

            out.print(dp[n][w]);
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

    }
}


Measured memory_bytes: 126420
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n,q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> str_idx('z'-'a'+1);
    rep(i,n) {
        str_idx[s[i]-'a'].insert(i);
    }
    rep(j,q) {
        int que;
        cin >> que;
        if(que == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            str_idx[s[i]-'a'].erase(i);
            str_idx[c-'a'].insert(i);
            s[i] = c;
        }
        if(que == 2) {
            int l,r;
            cin >> l >> r;
            l--;r--;
            int alp_sum = 0;
            rep(alp, 'z'-'a'+1) {
                if(str_idx[alp].lower_bound(l) != str_idx[alp].upper_bound(r)) {
                    alp_sum++;
                }
            }
            cout << alp_sum << endl;
        }
    }
    int A = 0;
}


Measured memory_bytes: 24220
a,b,i,j,N,p,P,t[36],c[36],T[36],C[36];
int Q(int *a,int *b){
    for(i=0;i<N;printf("%c%d%s",a[i],b[i],i==N-1?"\n":" "),i++);
}
B(){
    for(i=0;i<N;i++)
    for(j=N-1;j>0;j--)
        if(t[j-1]>t[j]){
            t[j]^=t[j-1]^=t[j]^=t[j-1];
            c[j]^=c[j-1]^=c[j]^=c[j-1];
        }
    Q(c,t);
    puts("Stable");
}
S(){
    for(i=0;i<N;i++){
        for(j=p=i;j<N;j++)if(T[j]<T[p])p=j;
        P=T[p];T[p]=T[i];T[i]=P;
        P=C[p];C[p]=C[i];C[i]=P;
    }
    Q(C,T);
    for(i=p=0;i<N;i++)if(c[i]==C[i]&&t[i]==T[i])p++;
    puts(p==N?"Stable":"Not stable");
}

int main(){
    for(scanf("%d",&N);i<N;scanf(" %c%d",&c[i],&t[i]),T[i]=t[i],C[i]=c[i],i++);
    B();S();

}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vll>;
df data(n, vll(m));
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/range/algorithm.hpp> // boost::sort(arr)
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
using boost::algorithm::join; // string s = join(arr, "");
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (c - b == b - a ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

#define N_MAX (1<<18)

struct segsum{
  long long nn;
  long long dat1[(2 * N_MAX) - 1];
  long long dat2[(2 * N_MAX) - 1];

  void init(long long n1){
    nn = 1;

    while(nn < n1)nn *= 2;

    for(long long i = 0; i < 2 * nn - 1; i++){
      dat1[i] = 0;
      dat2[i] = 0;
    }
  }

  void add(long long a, long long b, long long x, long long k, long long l, long long r) {
    if (a <= l && r <= b) {
      dat1[k] += x;
    }
    else if (l < b && a < r) {
      dat2[k] += (min(b, r) - max(a, l)) * x;
      add(a, b, x, k * 2 + 1, l, (l + r) / 2);
      add(a, b, x, k * 2 + 2, (l + r) / 2, r);
    }
  }

  long long sum(long long a, long long b, long long k, long long l, long long r){
    if (b <= l || r <= a)return 0LL;
    else if (a <= l && r <= b) {
      return (dat1[k] * (r - l) + dat2[k]);
    }
    else {
      long long ret;
      ret = (min(b, r) - max(a, l)) * dat1[k];
      ret += sum(a, b, k * 2 + 1, l, (l + r) / 2);
      ret += sum(a, b, k * 2 + 2, (l + r) / 2, r);
      return ret;
    }
  }

  void add(long long a, long long b, long long c){
    return add(a,b,c,0,0,nn);
  }

  long long sum(long long a, long long b){
    return sum(a,b,0,0,nn);
  }
}segsum1;

int main(){
  ll n,d,A;
  cin>>n>>d>>A;
  segsum1.init(n+10);
  vector<pair<ll,ll> > vp;
  rep(i,0,n){
    ll a,b;
    cin>>a>>b;
    vp.pb(mp(a,b));
  }
  sort(all(vp));
  vector<ll> vx;
  rep(i,0,vp.sz){
    ll a = vp[i].fi;
    ll b = vp[i].se;
    vx.pb(a);
    segsum1.add(i,i+1,b);
  }
  ll ans = 0;
  vx.pb(1000000000000000000LL);
  rep(i,0,n){
    ll a = segsum1.sum(i,i+1);
    ll p = vx[i];
    if(a<=0)continue;
    long long low = i;
    long long high = n;
    
    while(low < high){
      long long mid = (high + low + 1) >> 1;
      if(vx[mid]<=p+2*d){
        low = mid;
      }
      else{
        high = mid - 1;
      }
    }
    ll dd = 0;
    if(a%A!=0)dd++;
    dd += a/A;
    segsum1.add(i,low+1,-dd*A);
    ans += dd;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16108
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using namespace std;

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
    };

    // 2次元用の標準入出力
    template<typename T>
    struct inpn {
        std::size_t szi, szj;
        inpn(std::size_t _szi, std::size_t _szj) : szi(_szi), szj(_szj) {}
        operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i)
                for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j];
            return a;
        }
    };

    inp inp1; // input one
}


int main() {

    int n = inp1;
    vector<vector<int>>abc(n, vector<int>(3));
    rep(i, n) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

    // dp[i][j] := i-1日目にjを活動して，i日目に獲得できる最大の幸福度
    vector<vector<int>> dp(n + 1, vector<int>(3, 0));
    dp[1][0] = abc[0][0];
    dp[1][1] = abc[0][1];
    dp[1][2] = abc[0][2];

    Rep(i, 1, n) {
        rep(j, 3) { // jで遊ぶ
            rep(k, 3) { // 前回kで遊んだ
                if (j == k) continue;
                chmax(dp[i + 1][j], dp[i][k] + abc[i][j]);
            }
        }
    }

    Cout(max({dp[n][0], dp[n][1], dp[n][2]}));

    return 0;
}

Measured memory_bytes: 11136
A, B, C, X = [int(input()) for i in range(4)]

res = 0
for a in range(A + 1):
	for b in range(B + 1):
		for c in range(C + 1):
			total = 500 * a + 100 * b + 50 * c
			if total == X:
				res += 1
print(res)

Measured memory_bytes: 9080
#include<iostream>

int main()
{   
    int a,b,c,max,min,tmp;
    std::cin >> a >> b >> c;

    if (c<b){
        tmp = b;
        b = c;
        c = tmp;
    }

    if (b<a){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    if (c<b){
        tmp = b;
        b = c;
        c = tmp;
    }

    
    std::cout << a <<" "<< b << " " << c << std::endl;
    return 0;
}


Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC034B2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string result = changeBCtoD(s);//"BC"をDに置き換える
            /*
            foreach (var item in result)
            {
                Console.Write(item);
            }
            Console.WriteLine();
            */
            result = changeBtoX(result);//"B"をｘに置き換える
            /*
            foreach (var item in result)
            {
                Console.Write(item);
            }
            Console.WriteLine();
            */
            result = changeCtoX(result);//"C"をｘに置き換える
            /*
            foreach (var item in result)
            {
                Console.Write(item);
            }
            Console.WriteLine();
            */
            string[] del = { "x" };
            string[] ans = result.Split(del, StringSplitOptions.RemoveEmptyEntries);
            long inversion = 0;
            foreach (string item in ans)
            {
                int[] a = new int[item.Length];
                int[] b = new int[2];
                long[] t = new long[item.Length];
                for (int i = 0; i < item.Length; i++)
                {
                    if (item[i] == 'A')
                    {
                        a[i] = 1;//Aを1に変える
                    }
                    else
                    {
                        a[i] = 0;//Dを0に変える
                    }
                 //   Console.Write(a[i]);
                }
               // Console.WriteLine();
                for (long j = 0; j < item.Length; j++)
                {
                    for (int jend = 0; jend <= a[j]; jend++)
                    {
                        t[j] += b[jend];
                    }
                    b[a[j]]++;
                    inversion += j - t[j];
                }
            }
                Console.WriteLine(inversion);
        }
        static string changeBCtoD(string s)
        {
            string[] del = { "BC" };
            string[] ans = s.Split(del, StringSplitOptions.None);
            string result = string.Join("D", ans);
            return result;
        }
        static string changeBtoX(string s)
        {
            string[] del = { "B" };
            string[] ans = s.Split(del, StringSplitOptions.None);
            string result = string.Join("x", ans);
            return result;
        }
        static string changeCtoX(string s)
        {
            string[] del = { "C" };
            string[] ans = s.Split(del, StringSplitOptions.None);
            string result = string.Join("x", ans);
            return result;
        }

    }
}


Measured memory_bytes: 32860
n = int(input())
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
cost = [[0, 0] for _ in range(n)]
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split()]
    cost[i] = [a[i]+b[i], i]
# a[i]-b[i]がmaxのものから取っていく
cost.sort()
cost.reverse()
scoreA = 0
scoreB = 0
for i in range(len(cost)):
    if i % 2 == 0:
        scoreA += a[cost[i][1]]
    else:
        scoreB += b[cost[i][1]]
print(scoreA -scoreB)

Measured memory_bytes: 28012