akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;

struct at{
	int x;
	int index;
}a[maxn];
bool cmp(at b,at c){
	return b.x<c.x;
}
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].x;
		a[i].index=i;
	}
	sort(a+1,a+n+1,cmp);
	cout<<a[1].index;
	for(int i=2;i<=n;i++){
		cout<<" "<<a[i].index;
	}
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 1664
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


a = S[0]
for c, d in zip(S, S[1:]):
    if c != d:
        a += d
print(len(a))


Measured memory_bytes: 23116
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
vector<pii> A[20];
;
void input() {
  ;
  ;
  cin >> N;
  rep(i, 0, N - 1) {
    int a;
    cin >> a;
    rep(j, 1, a) {
      int x, y;
      cin >> x >> y;
      x--;
      A[i].push_back(pii(x, y));
    }
  }
}
void solve() {
  int ans = -1;
  ;
  // searchall.
  for (int i = 0; i < (1 << N); ++i) {
    // cerr << "\n\n" << endl;
    int ls[N + 1];
    rep(uu, 0, N) { ls[uu] = -1; }  // initialize
    bool valid = true;
    for (int j = 0; j < N; ++j) {  // jが正直者の場合
      // debug(j);
      // debug((i >> j & 1));
      if (i >> j & 1) {
        if (ls[j] == 0) {
          // debug("dd");
          valid = false;
          break;
        }
        ls[j] = 1;

        for (auto pairs : A[j]) {
          int x = pairs.first;
          int y = pairs.second;
          //  debug2(x, y);
          if (y) {
            if (ls[x] == 0) {
              //     debug("a");
              valid = false;
              break;
            }
            ls[x] = 1;
          } else {
            if (ls[x] == 1) {
              //     debug("b");
              valid = false;
              break;
            }
            ls[x] = 0;
          }
        }
      } else {
        if (ls[j] == 1) {
          // debug("c");
          valid = false;
          break;
        }
        ls[j] = 0;
      }
    }
    if (valid) {
      int cnt = 0;
      for (int ll = 0; ll < N; ++ll) {
        if (ls[ll] == 1) {
          cnt++;
        }
      }
      //      debug2(i, cnt);
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;

  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
function parseInt(x) parse(Int, x) end

function main()
	n = parseInt(readline())
	count = 0
	flg = 0
	while count*7 <= n
		if (n-count*7)%4 == 0
			flg = 1
		end
		count += 1
	end
	if flg == 1
		print("Yes")
	else
		print("No")
	end
end

main()

Measured memory_bytes: 163068
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
int n,p;
string str;
ll dp[100000+10];
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>p;
    cin>>str;
    ll ans=0;
    if(p==2||p==5)
    {
    	for(int i=0;i<str.length();i++){
    		if((str[i]-'0')%p==0){
    			ans+=(i+1);
    		}
    	}
    }
    else{
    	ll po=1,rem=0;
    	for(int i=str.length()-1;i>=0;i--){
    		rem=(rem+(str[i]-'0')*po)%p;
    		po=po*10%p;
    		dp[rem]++;
    	}
    	ans=dp[0];
    	for(int i=0;i<p;i++){
    		ans+=dp[i]*(dp[i]-1)/2;
    	}
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 720
/**
       ������������    ������������
		Author : Avi J Patel
		University : DA-IICT
       ������������    ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define mod 1000000007
#define large 10000000000000001
int main()
{
	int n;
	cin>>n;
	vector<tuple<string,int,int>> a;
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		int a1;
		cin>>a1;
		a.pb(mt(s,a1,i));
	}
	sort(a.begin(),a.end());
	int i=0;
	while(i<n)
	{
		//cout<<i<<endl;
		vector<int> b;
		b.pb(get<1>(a[i]));
		while(i+1<n && get<0>(a[i])==get<0>(a[i+1])  )
		{
			//cout<<i+1<<endl;
			b.pb(get<1>(a[i+1]));
			i++;
		}
		sort(b.begin(),b.end());
		reverse(b.begin(),b.end());
		/*for(int j=0;j<b.size();j++)
		{
			cout<<b[j]<<" ";
		}
		cout<<endl;*/
		for(int j=0;j<b.size();j++){
			for(int k=0;k<n;k++)
			{
				if(b[j]==get<1>(a[k]))
				{
					cout<<get<2>(a[k])+1<<endl;
					break;
				}
			}
		}
		i++;
	}
	
    return 0;
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=2e5+11;
const int M=2e6+11;
const int W=1e3+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const ld EPS=1e-9;

int a[N];

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  sort(a+1,a+n+1);
  for(int i=2;i<=n;i++){
    if(a[i]==a[i-1]){
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=998244353;
int main(){
	long long n,a;
	cin>>n;
	long long ma=0;
	long long ans=0;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a>=ma){
			ma=a;
		}else{
			ans+=abs(ma-a);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3192
a, b, c = map(int, input().split())
k = int(input())

def dfs(A, B, C, i):
    if i == k:
        return ((A < B) and (B < C))
    return (dfs(A * 2, B, C, i + 1) or dfs(A, B * 2, C, i + 1) or dfs(A, B, C * 2, i + 1))

if dfs(a, b, c, 0):
    ans = "Yes"
else:
    ans = "No"

print(ans)


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

int main() {
	string a;
	cin>>a;
	if(a=="SUN")cout<<"7";
	if(a=="SAT")cout<< "1";
	if(a=="FRI")cout<< "2";
	if(a=="THU")cout<< "3";
	if(a=="WED")cout<< "4";
	if(a=="TUE")cout<< "5";
	if(a=="MON")cout<< "6";
	return 0;
}

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

ll l1[51][51];
ll dir[8][2]={{1,0},{0,1},{0,-1},{-1,0},{-1,1},{-1,-1},{1,-1},{1,1}};
map<ll,ll>di;


int main()
{
    string s,t;//cout<<min(s,t)<<endl;
    cin>>s;
    cin>>t;
    ll n,m;
    n=s.size();
    m=t.size();
    if(m>n){
        cout<<"UNRESTORABLE";return 0;
    }
    string ans="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
    for(int i=0;i<=n-m;i++){
        string s2=s;bool ok=true;
        for(int j=0;j<m;j++){
            if(s[i+j]!='?'&&s[i+j]!=t[j])ok=false;
            s2[i+j]=t[j];
        }
        if(ok){//cout<<1<<endl;
            replace(s2.begin(),s2.end(),'?','a');
            ans=min(ans,s2);
        }
    }
    if(ans=="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz")cout<<"UNRESTORABLE";
    else cout<<ans;
}


Measured memory_bytes: 256
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
        self.sizes = [1 for _ in range(size)]

    
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])
    
    def root(self, x):
        if self.parent[x] == x:
            return x
        else:
            root_x = self.root(self.parent[x])
            self.parent[x] = root_x
            return root_x


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.sizes[y] += self.sizes[x]
        else:
            self.parent[y] = x
            self.sizes[x] += self.sizes[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.sizes[self.find(x)]

N,M = map(int, input().split())

u = UnionFind(N)

for m in range(M):
    xyz = [int(i)-1 for i in input().split()]
    u.unite(xyz[0],xyz[1])

for n in range(N):
    u.root(n)

print(len(list(set(u.parent))))

Measured memory_bytes: 14760
#include <stdio.h>

long long int N;
long long int A[100001];
long long int uneven=0;

int main(){
	scanf("%lld",&N);
	for(int i=1;i<=N;i++){
		scanf("%lld",&A[i]);
		if(A[i]%2){
			uneven++;
		}
	}
	if(uneven%2==0){
		printf("YES");
	}else{
		printf("NO");
	}
}

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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 200005

struct matrix{
ll a[51][51];
matrix(){
memset(a,0,sizeof a);
}
};
matrix mul(matrix p,matrix b,int n){
    matrix c = matrix();
    for (int i=0; i<n; ++i)
        for (int k=0; k<n; ++k)
            for (int j=0; j<n; ++j)
                c.a[i][j]=(c.a[i][j]+ 1LL*p.a[i][k]*b.a[k][j])%mod;
    return c;
}

matrix unit;

int nn;
matrix modpow(matrix m,ll n){
  if (n==0)return unit;
  matrix half =modpow(m,n>>1);
  matrix out=mul(half,half,nn);
  if(n&1)
    out=mul(out,m,nn);
  return out;
}

int main(){
sp;
unit=matrix();
for(int i=0; i<51; ++i)
    unit.a[i][i]=1LL;
matrix p=matrix();
int n,x;
ll k;
cin>>n>>k;
nn=n;
for(int i=0; i<n;++i)
for(int j=0; j<n; ++j){
    cin>>x;
    p.a[i][j]=x;
}
ll ans=0;
matrix m=modpow(p,k);
for(int i=0; i<n; ++i)
    for(int j=0; j<n; ++j)
    ans=(ans+m.a[i][j])%mod;
cout<<ans;
return 0;}


Measured memory_bytes: 9984
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
int a[100010];
int arr[100010];
int main(void)
{
    int N; cin >> N;
    for(int i=0; i<N; ++i) cin >> a[i];
    
    sort(a, a+N);
    if(N%2==0){
        for(int i=0; i<N/2; ++i){
            if(i==0) arr[N/2-1] = a[0];
            else{
                if(N/2-2*i-1>=0) arr[N/2-2*i-1] = a[2*i];
                if(N/2+2*i-1<N) arr[N/2+2*i-1] = a[2*i-1];
            }
        }
        for(int i=0; i<N/2; ++i){
            if(i==0) arr[N/2] = a[N-1];
            else{
                if(N/2-2*i>=0) arr[N/2-2*i]= a[N-1-2*i+1];
                if(N/2+2*i<N) arr[N/2+2*i]= a[N-1-2*i]; 
            }
        }
        ll ans=0;
        for(int i=1; i<N; ++i){
            ans += abs(arr[i]-arr[i-1]);
        }
        cout << ans << endl;
    }else{
        ll ans1=0;
        ll ans2=0;
        arr[N/2] = a[0];
        for(int i=1; i<=N/2; ++i){
            if(N/2-2*i>=0) arr[N/2-2*i] = a[2*i];
            if(N/2+2*i<N) arr[N/2+2*i] = a[2*i-1];
        }
        
        for(int i=1; i<=N/2; ++i){
            if(N/2-2*(i-1)-1>=0) arr[N/2-2*(i-1)-1]= a[N-1-2*(i-1)];
            if(N/2+2*(i-1)+1<N) arr[N/2+2*(i-1)+1]= a[N-1-2*(i-1)-1]; 
        }
        for(int i=1; i<N; ++i){
            ans1 += abs(arr[i]-arr[i-1]);
        }
        
        
        arr[N/2] = a[N-1];
        for(int i=1; i<=N/2; ++i){
            if(N/2-2*i>=0) arr[N/2-2*i]= a[N-1-2*i];
            if(N/2+2*i<N) arr[N/2+2*i]= a[N-1-2*i+1]; 
        }
        
        for(int i=1; i<=N/2; ++i){
            if(N/2-2*(i-1)-1>=0)arr[N/2-2*(i-1)-1] = a[2*(i-1)];
            if(N/2+2*(i-1)+1<N) arr[N/2+2*(i-1)+1] = a[2*(i-1)+1];
        }
        for(int i=1; i<N; ++i){
            ans2 += abs(arr[i]-arr[i-1]);
        }
        cout << max(ans1, ans2) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    if ((a*b)%2==1) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21844
//
//  main.cpp
//  Chokudai_Contest_004
//
//  Created by tolemy on 2019/08/31.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, int> job;

#define rep(i, start, end) for (int i = (int)(start); i < (int)(end); i++)

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

    string s = "";
    cin >> s;

    if (s == "Sunny")
    {
        cout << "Cloudy";
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy";
    }
    else
    {
        cout << "Sunny";
    }

    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int count = 0;
    for(int i=0;i<n-2;i++)
    {
        if(s.at(i) == 'A')
        {
            if(s.at(i+1) == 'B')
            {
                if(s.at(i+2) == 'C')
                {
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

vector<vector<int>> G1,G2;
vector<vector<int>> dist;
int W,H;
int x[4] = {0,1,0,-1};
int y[4] = {1,0,-1,0};

void bfs() {
	queue<pii> que;
	que.push(pii(0,0));
	while(!que.empty()) {
		pii q = que.front();
		que.pop();
		//cout << q.fi << " " << q.se << endl;
		/* G[q.se][q.fi]
		isWall down: G2[q.se][q.fi]
		left: G2[q.se][q.fi-1]
		up: G2[q.se-1][q.fi]
		right: G2[q.se][q.fi]
		*/

		rep(i,4) {
			pii next = pii(q.fi + x[i], q.se + y[i]);
			//cout << next.fi << " " << next.se << endl;
			if(next.se < 0 || next.se >= H || next.fi < 0 || next.fi >= W) continue;
			if(dist[next.se][next.fi] != 1e9) continue;
			if(i == 0) {
				if(G2[q.se][q.fi]) continue;
			}
			if(i == 1) {
				if(G1[q.se][q.fi]) continue;
			}
			if(i == 2) {
				if(G2[q.se-1][q.fi]) continue;
			}
			if(i == 3) {
				if(G1[q.se][q.fi-1]) continue;
			}
			//cout << next.fi << " " << next.se << endl;
			dist[next.se][next.fi] = dist[q.se][q.fi] + 1;
			que.push(next);
		}
	}
}
int main() {
	while(1) {
		cin >> W >> H;
		if(W == 0 && H == 0) break;
		G1 = vector<vector<int>>(H, vector<int>(W));
		G2 = vector<vector<int>>(H, vector<int>(W));
		dist = vector<vector<int>>(H, vector<int>(W));
		rep(i,H) rep(j,W) dist[i][j] = 1e9;
		dist[0][0] = 1;
		rep(i,2*H-1) {
			if(i % 2 == 0) {
				rep(j,W-1) {
					cin >> G1[i/2][j];
				}
			}
			else {
				rep(j,W) {
					cin >> G2[i/2][j];
				}
			}
		}
		bfs();

		/*rep(i,H) {
			rep(j,W) {
				if(dist[i][j] == 1e9) cout << setw(3) << 0;
				else cout << setw(3) << dist[i][j];
			}
			cout << endl;
		}*/
		if(dist[H-1][W-1] == 1e9) dist[H-1][W-1] = 0;
		cout << dist[H-1][W-1] << endl;
	}

  return 0;
}


Measured memory_bytes: 3148
using System;
class Program
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		long N = long.Parse(s);
		long [] P = new long[N];
		long count = 0;
		string b = Console.ReadLine();
		P[0] = long.Parse(b);
		if(P[0] > 0){
			count = -1;
		} else {
			for(var i=1;i<N;i++){
				string t = Console.ReadLine();
				P[i] = long.Parse(t);
				if(P[i] - P[i-1] == 1){
					count += 1;
				} else if(P[i] - P[i-1] >= 2){
					count = -1;
					break;
				} else {
					count += P[i];
				}
			}
		}
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 17332
#include<iostream>
#include<iomanip>
using namespace std; 
 
int main ()
{
   double x,a,b;
   cin>>x>>a>>b;
   int desA,desB;
   desA=x-a;
   if(desA<0)
   {desA=desA*-1;}
   desB=x-b;
   if(desB<0)
   {desB=desB*-1;}
   if(desA>desB)
   cout<<"B";
   else
   cout<<"A";
    return 0;
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;



int main(void){
	int n,l ;
cin >> n >> l;
vector<string> s(n);
REP(i, 0, n) cin >> s[i];
sort(s.begin(), s.end());
REP(i, 0, n) cout << s[i];
cout << endl;
}


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


int main(){
  
  ll n,x;
  cin >>n >> x;
  ll a[n];
  rep(i,n) cin >> a[i];
  ll ans=0;
  rep(i,n-1){
    if(a[i]+a[i+1]>x){
      ans+=a[i]+a[i+1]-x;
      a[i+1]=max(x-a[i],0LL);
    }
  }
  cout << ans << endl;
    
  
  return 0;

}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(void)
{
	int N,i;
	string S;

	cin >> N >> S;
	if(N%2==1)
	{
		cout << "No" << endl;
		return 0;
	}
	else
		for(i=0;i<N/2;i++)
		{
			if(S[i]!=S[i+(N/2)])
			{
				cout << "No" << endl;
				return 0;
			}
		}

		cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define ld double
#define PB push_back
using namespace std;
const int MX = (1 << 18) + 100;
const int SQ = 3000;
const double PI = acos(-1.0);
const int K = 18;
int n;
string t;
int s[100005];
vector<pair<int , int> > edges;
int main()
{
	//freopen("In.txt" , "r" , stdin);
	cin >> t;
	n = t.size();
	for(int i = 1; i <= n; i++)
		s[i] = t[i - 1] - '0';
	if(s[n] == 1 || s[1] == 0)
	{
		cout << -1;
		return 0;
	}
	for(int i = 1; i <= n - 1; i++)
	{
		if(s[i] != s[n - i])
		{
			cout << -1;
			return 0;
		}
	}
	//int md = n / 2 + n % 2;
	edges.PB({1 , 2});
	int cur = 2;
	int batya = 2;
	int prev = 1;
	for(int i = 2; i <= n / 2 + n % 2; i++)
	{
		edges.PB({batya , ++cur});	
		if(s[i] == 1)
		{
			
			batya = cur;
		}
	}
	for(int i = 1; i <= n / 2 - 1; i++)
		edges.PB({batya , ++cur});
	for(int i = 0; i < edges.size(); i++)
	{
		printf("%d %d\n" , edges[i].first , edges[i].second);
	}
    return 0;

}

Measured memory_bytes: 2804
//此程序使用了qt专属名称，请勿模仿。侵权必究！！！
//我真是太菜了……
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2010;
int n,m,T,a[N][N]={},sv[N][N],sxe[N][N],sye[N][N];
int lx,ly,rx,ry,v,e;
char s[N];
inline int read()
{
	int sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
	return sum*flag;
}
int main()
{
//	freopen("duty.in","r",stdin);
//	freopen("duty.out","w",stdout);
	n=read();
	m=read();
	T=read();
	for(int i=1;i<=n;++i)
	{
		scanf("%s",s+1);
		for(int j=1;j<=m;++j)
		{
			a[i][j]=s[j]-'0';
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			sv[i][j]=sv[i-1][j]+sv[i][j-1]-sv[i-1][j-1]+a[i][j];
			sxe[i][j]=sxe[i-1][j]+sxe[i][j-1]-sxe[i-1][j-1]+(a[i][j]&&a[i][j+1]);
			sye[i][j]=sye[i-1][j]+sye[i][j-1]-sye[i-1][j-1]+(a[i][j]&&a[i+1][j]);
		}
	}
	while(T--)
	{
		lx=read(),ly=read(),rx=read(),ry=read();
		v=sv[rx][ry]-sv[lx-1][ry]-sv[rx][ly-1]+sv[lx-1][ly-1];
		e=(sxe[rx][ry-1]-sxe[lx-1][ry-1]-sxe[rx][ly-1]+sxe[lx-1][ly-1])+(sye[rx-1][ry]-sye[lx-1][ry]-sye[rx-1][ly-1]+sye[lx-1][ly-1]);
		printf("%d\n",v-e);
	}
	return 0;
}





Measured memory_bytes: 64896
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

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

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

int main()
{
	int A, B;
	while(cin >> A >> B)
		cout << gcd(A, B) << endl;

	return 0;
}

Measured memory_bytes: 1160
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int D = sc.nextInt();
    	int N = sc.nextInt();
    	int Dscore = (int) Math.pow(100, D);
    	int index = 0;
    	for (int i = 1;;i++) {
    		if (i%100 == 0) {
    			continue;
    		} else {
    			index++;
    			if (index == N) {
    				System.out.println(Dscore*i);
    				break;
    			}
    		}
    	}
    }
}

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

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

ll count(ll a, ll b, int M) {
    return b - a + (a <= b ? 0 : M);
}

int main() {
    int N, M; cin >> N >> M;
    vl a(N);
    rep(i,N) cin >> a[i];

    vl imos(2*M+1, 0);
    rng(i,1,N) {
        int l = a[i-1]+2;
        int r = a[i]+1+(a[i-1]<a[i]?0:M);
        imos[l]++;
        imos[r]--;
    }
    rep(i,2*M) imos[i+1] += imos[i];
    rng(i,1,N) {
        int l = a[i-1]+2;
        int r = a[i]+1+(a[i-1]<a[i]?0:M);
        imos[r] -= r - l;
    }
    rep(i,2*M) imos[i+1] += imos[i];

    ll fav = 1, mx = -1;
    rng(i,1,M+1) {
        imos[i] += imos[i+M];
        if (imos[i] > mx) {
            mx = imos[i];
            fav = i;
        }
    }
    ll ans = 0;
    rng(i,1,N) {
        ans += min(count(a[i-1], a[i], M), count(fav, a[i], M) + 1);
    }
    cout << ans << endl;
    return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  vi d(n);
  rep(i, 0, n) cin >> d[i];

  int ans = 0;
  rep(i, 0, n) rep(j, i+1, n){
    ans += d[i]*d[j];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 if r<H:
  if A[i]<A[l]:
   if A[l]<A[r]:A[i],A[r]=A[r],A[i];h(r)
   else:A[i],A[l]=A[l],A[i];h(l)
  elif A[i]<A[r]:A[i],A[r]=A[r],A[i];h(r)
 elif l<H and A[i]<A[l]:A[i],A[l]=A[l],A[i];h(l)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 64180
#include<stdio.h>
#include<stdlib.h>
#define ll long long
int cmp(const int *a, const int *b){
  return *b - *a;
}
int main(){
  int n, k;
  scanf("%d%d",&n,&k);
  int a[222222];
  for(int i=0;i<n;i++)scanf("%d",&a[i]);
  qsort(a,n,4,cmp);
  ll b=0;
  for(int i=k;i<n;i++)b+=a[i];
  printf("%lld\n",b);
  return 0;
}

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

int main() {
	string s;
  	cin>>s;
  
  	int hug=0;
  	int ketu=s.size();


  
  rep(i,ketu){
  	if(s[i]!=s[ketu-i-1])
    	hug++;
    }

  
  cout<<hug/2<<endl;
  
  
}

Measured memory_bytes: 256
h,w = map(int, input().split())
if (h%3==0 or w%3==0):
    print(0)
    exit()
ans = float("inf")
if (w%2==0):
    ans = min(ans, (h-h//3)*(w//2) - h//3*w)
    ans = min(ans, abs((h-h//3-1)*(w//2) - (h//3+1)*w))
else:
    if (h%3==1):
        ans = min(ans, max(abs((h-h//3)*(w//2) - h//3*w),abs((h-h//3)*(w//2+1) - h//3*w), abs(h-h//3)))
    else:
        ans = min(ans, max(abs((h-h//3-1)*(w//2) - (h//3+1)*w),abs((h-h//3-1)*(w//2+1) - (h//3+1)*w), abs(h-h//3-1)))
ans = min(ans,w)
    
a = w
w = h
h = a
#print(h,w)
if (w%2==0):
    ans = min(ans, (h-h//3)*(w//2) - h//3*w)
    ans = min(ans, abs((h-h//3-1)*(w//2) - (h//3+1)*w))
else:
    if (h%3==1):
        ans = min(ans, max(abs((h-h//3)*(w//2) - h//3*w),abs((h-h//3)*(w//2+1) - h//3*w), abs(h-h//3)))
    else:
        ans = min(ans, max(abs((h-h//3-1)*(w//2) - (h//3+1)*w),abs((h-h//3-1)*(w//2+1) - (h//3+1)*w), abs(h-h//3-1)))
ans = min(ans,w)
    
print(ans)

Measured memory_bytes: 3188
// One Quadrillion and One Dalmatians.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <string>
#include <cmath>

int main()
{
    unsigned long long q;
    std::cin >> q;

    int d = 1;
    for (d = 1; q - (std::pow(26ull, d)) > 0; d++) q -= (std::pow(26ull, d));

    q--;

    std::string out = "";
    for (int i = d - 1; i >= 0; i--)
    {
        out += 'a' + (q / (unsigned long long)std::pow(26ull, i));
        q %= (unsigned long long)std::pow(26ull, i);
    }

    std::cout << out;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 4108
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
using namespace std;
typedef long long ll;
typedef long double ld;
int A,B,Q;
vector<ll> As,Bs,Qs;
ll INF=(ll)1000*1000*1000*1000;
int main() {
  vector<char> buf(1<<24);
  fread(&buf[0],1,buf.size(),stdin);
  //vector<char>().swap(buf);
  istringstream stream(&buf[0]);

  cout << fixed << setprecision(15);
  stream >> A >> B >> Q;
  As.resize(A);Bs.resize(B);Qs.resize(Q);
  REP(i,A)
    stream >> As[i];
  REP(i,B)
    stream >> Bs[i];
  REP(i,Q) {
    ll x;
    stream >> x;
    auto ita=lower_bound(ALL(As),x);
    auto itb=lower_bound(ALL(Bs),x);
    // only go left
    ll ans=INF;
    vector<ll> alis,blis;
    if (ita!=As.end()) {
      alis.pb(*ita);
    }
    if (itb!=Bs.end()) {
      blis.pb(*itb);
    }
    if (ita!=As.begin()) {
      ita--;
      alis.pb(*ita);
    }
    if (itb!=Bs.begin()) {
      itb--;
      blis.pb(*itb);
    }
    for(ll a:alis)
      for(ll b:blis) {
        ans = min(ans,abs(a-x)+abs(b-a));
        ans = min(ans,abs(b-x)+abs(b-a));
      }
    cout << ans << endl;
  }


  return 0;
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

template<class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int D;
intvec C(26);
intmat S;
intvec last(26,-1);
ll score;

void input() {
	cin>>D;
	init(C);
	S.resize(D);
	for(int i=0; i<D; i++) init(S[i],26);
}

ll calc(int d, int c) {
	ll res=S[d][c];
	for(int i=0; i<26; i++) {
		res-=C[c]*(d-last[c]);
	}
	return res;
}

void solve() {
	srand(time(NULL));
	for(int d=0; d<D; d++) {
		ll temps=-LLINF;
		int oldc,oldd;
		for(int c=0; c<26; c++) {
			oldd=last[c];
			last[c]=d;
			if(chmax(temps,calc(d,c))) oldc=c;
			last[c]=oldd;
		}
		score+=temps;
		last[oldc]=d;
		cout<<oldc+1<<endl;
	}
}

int main() {
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3668
using System;

namespace AOJ.Volume0
{
    public class RankChecker
    {
        // 問題数
        static readonly int problem = 30;
        // チーム数
        static readonly int team = 100;

        public static int Main()
        {
            // 順位保存用の配列
            // rank[10] = 10問正解したチーム数
            var rank = new int[problem + 1];
            // チームの成績を保存する配列
            // score[10] = 整理番号10の正解数
            var score = new int[team + 1];

            while (true)
            {
                var input = Console.ReadLine().Split(',');
                int id = int.Parse(input[0]);
                int ac = int.Parse(input[1]);
                if (id == 0 && ac == 0) { break; }
                score[id] = ac;
                rank[ac]++;
            }

            // 順位を決める
            int sum = 1;
            for (int i = 30; i >= 0; i--)
            {
                if (rank[i] == 0) { rank[i] = -1; }
                else
                {
                    rank[i] = sum;
                    sum++;
                }
            }

            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                int id = int.Parse(input);
                int ac = score[id];
                Console.WriteLine(rank[ac]);
            }
            return 0;
        }
    }
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  string ans = "-1";
  for(int i=0; i<4; ++i){
    string nans;
    if(i%2 == 0) nans += 'S';
    else nans += 'W';
    if((i>>1)%2 == 0) nans += 'S';
    else nans += 'W';
    for(int j=1; j<n-1; ++j){
      if((nans[j] == 'W' && s[j] == 'o') || (nans[j] == 'S' && s[j] == 'x')){
        nans += (nans[j-1] == 'S' ? 'W':'S');
      }else{
        nans += (nans[j-1] == 'S' ? 'S':'W');
      }
    }
    bool frag = true;
    if(nans[n-1] == 'W' && s[n-1] == 'o' && nans[0] == nans[n-2]) frag = false;
    else if(nans[n-1] == 'W' && s[n-1] == 'x' && nans[0] != nans[n-2]) frag = false;
    else if(nans[n-1] == 'S' && s[n-1] == 'o' && nans[0] != nans[n-2]) frag = false;
    else if(nans[n-1] == 'S' && s[n-1] == 'x' && nans[0] == nans[n-2]) frag = false;
    if(nans[0] == 'W' && s[0] == 'o' && nans[1] == nans[n-1]) frag = false;
    else if(nans[0] == 'W' && s[0] == 'x' && nans[1] != nans[n-1]) frag = false;
    else if(nans[0] == 'S' && s[0] == 'o' && nans[1] != nans[n-1]) frag = false;
    else if(nans[0] == 'S' && s[0] == 'x' && nans[1] == nans[n-1]) frag = false;
    if(frag){
      ans = nans;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3812
n=int(input())
dp=[[0,0,0] for _ in range(n)]
for i in range(n):
  if i==0:
    dp[i]=list(map(int,input().split()))
  else:
    abc=list(map(int,input().split()))
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+abc[0]
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+abc[1]
    dp[i][2]=max(dp[i-1][1],dp[i-1][0])+abc[2]
answer=0
for j in range(3):
  answer=max(answer,dp[-1][j])
print(answer)

Measured memory_bytes: 85988
#include <bits/stdc++.h>
using namespace std;
 
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#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, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
 
#define lint long long
 
 
int main()
{
  lint n; cin>>n;
  lint sum = 0;
  if(n ==1) sum = 0;
  else sum = n*(n-1)/2;
  cout << sum<< "\n";
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
LL a;
int main(){
	cin >> a;
	if(a<7){
		puts("1");
		return 0;
		}
	if(a<11){
		puts("2");
		return 0;
		}
	if(!(a%11))
	cout << a / 11 * 2<< endl;
	else {
		if(a%11<7)
		cout << a / 11 * 2 + 1 << endl;
		else cout << a / 11 * 2 + 2 << endl;
	}
	return 0;
	}//

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

int main(){
	ll x;
	scanf("%lld", &x);
	ll ans = x/11;
	ans *= 2;
	x %= 11;
	if (x >= 7) ans += 2;
	else if (x != 0) ans++;

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 3804
#include <stdio.h>

int main(void){
    
    long X;
    int flag;

    scanf("%ld",&X);

    flag = 0;

    while(flag == 0){
        flag = 1;
        for(long i = 2; i < X; i++){
            if(X%i==0){
                flag = 0;
                break;
            }
        }
        if(flag == 0){
            X++;
        }
    }

    printf("%ld",X);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void)
{
    int a, b, c, x, ans=0, i, j, k;

    cin >> a >> b >> c >> x;

    for(i=0; i<=a; i++){
        for(j=0; j<=b; j++){
            for(k=0; k<=c; k++){
                if(500*i+100*j+50*k == x){
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque

n, q = map(int, input().split())
Q = deque()

ans = []
total = 0
for _ in range(n):
    p, t = input().split()
    Q.append([p, int(t)])

while len(Q) > 0:
    p, t = Q.popleft()
    if t<=q:
        total += t
        ans.append([p, total])
    else:
        total += q
        Q.append([p, t-q])

for v in ans:
    print(v[0], v[1])


Measured memory_bytes: 15076
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	int len = (int)s.size();
	int AC[len] = {};

	FOR(i, 1, len){
		if (s[i-1] == 'A' and s[i] == 'C') AC[i] = AC[i-1] + 1;
		else AC[i] = AC[i-1];
	}

	int l[q], r[q];

	REP(i, q) cin >> l[i] >> r[i];

	REP(i, q) cout << AC[r[i]-1] - AC[l[i]-1] << endl;

}


Measured memory_bytes: 2176
//============================================================================
// Name        : abc144_b.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : https://atcoder.jp/contests/abc144/tasks/abc144_b
//============================================================================

/*
 B - 81

 実行時間制限: 2 sec / メモリ制限: 1024 MB

 配点 : 200 点

 問題文
 高橋君は九九を覚えたので、1 以上 9 以下の 2 つの整数の積を計算することができます。
 整数 N が与えられるので、N を 1 以上 9 以下の 2 つの整数の積として表すことができるか判定し、
 できるなら 'Yes' を、できないなら 'No' を出力して下さい。

 制約

 ・1 <= N <= 100
 ・N は整数である。
 */

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

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

using ll = long long;
using ull = unsigned long long;

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

/**
 * エントリポイント．
 * @return 0.
 */
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	unordered_set<int> ok;
	rep(i, 1, 10)
	{
		rep(j, i, 10)
		{
			ok.insert(i * j);
		}
	}

	cout << (ok.find(n) != ok.end() ? "Yes" : "No") << endl;
	return 0;
}


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


int main() {
	
	long long a,b,c;
	cin>>a>>b>>c;
  long long ans;
	if(c<=a+b){cout<<"No"<<endl;}
	else if(4*a*b<(c-a-b)*(c-a-b)){cout<<"Yes"<<endl;}
	else {cout<<"No"<<endl;	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, i, a[200001], x=0, y, sum=0, min=INF;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> a[i];
        sum += a[i];
    }

    for(i=1; i<=N-1; i++){
        x += a[i];
        y = sum-x;

        chmin(min, abs(x-y));
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int n;
    cin >> n;
    int ok = 0, ng = n - 1, mid;
    string zero;
    cout << 0 << endl;
    cin >> zero;
    if (zero == "Vacant") return 0;
    while (ng - ok > 1) {
        mid = (ng + ok) / 2;
        cout << mid << endl;
        string now;
        cin >> now;
        if (now == "Vacant") return 0;

        ((mid % 2 == 0 && now == zero) || (mid % 2 == 1 && now != zero) ? ok
                                                                        : ng) =
            mid;
    }
    cout << ng << endl;
}

Measured memory_bytes: 852
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S;
    cin >> S;

    int N = S.length();
    int a = 0, b = 0;
    char c = '0';
    REP(i, N) {
        if (S[i] == c)
            a++;
        else
            b++;
        c = '1' - c + '0';
    }

    cout << min(a, b) << endl;

    return 0;
}

Measured memory_bytes: 512
[H, W] = map(int, input().split())
[Ch, Cw] = map(int, input().split())
[Dh, Dw] = map(int, input().split())

mp = []
for i in range(H):
    mp.append(list(input()))

[Ch, Cw, Dh, Dw] = [Ch-1, Cw-1, Dh-1, Dw-1] 

cur = [[Ch, Cw]] # queue
walked = [[Ch, Cw]]
steps = 0
step = [[1, 0], [0, 1], [-1, 0], [0, -1]]
warp = [[i, j] for i in range(-2, 3) for j in range(-2, 3) if not i==j==0]

while True:
    current = cur.pop()
#    print('currently at', current, 'with', steps, 'steps')
    for i in range(len(step)):
        nxt = [ current[0]+step[i][0], current[1]+step[i][1] ]
        if nxt[0] == Dh and nxt[1] == Dw:
            print (steps)
            quit()
        if 0<=nxt[0] <H and 0<=nxt[1]<W:
            if mp[nxt[0]][nxt[1]] == '#': # wall
                pass
            elif mp[nxt[0]][nxt[1]] == '.': # floor
                mp[nxt[0]][nxt[1]] = 'X'
                cur.append([nxt[0], nxt[1]])
                walked.append([nxt[0], nxt[1]])
    if len(cur) > 0: continue

    # no more walkable area; warp
    steps += 1
    for j in range(len(walked)):
        current = walked.pop()
        for i in range(len(warp)):
            nxt = [ current[0]+warp[i][0], current[1]+warp[i][1] ]
            if nxt[0] == Dh and nxt[1] == Dw:
                print (steps)
                quit()
            if 0<=nxt[0]<H and 0<=nxt[1]<W:
                if mp[nxt[0]][nxt[1]] == '#': # wall
                    pass
                elif mp[nxt[0]][nxt[1]] == '.': # floor
                    mp[nxt[0]][nxt[1]] = 'X'
                    cur.append([nxt[0], nxt[1]])
    if len(cur) == 0:
        print('-1')
        quit()
    walked = cur.copy()
        
        
    


Measured memory_bytes: 133676