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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;

signed main() {
    int N;
    cin >> N;
    int A1max, a2, S, X = 0;
    cin >> A1max >> a2;
    S = A1max + a2;
    rep(i, N - 2) {
        int a;
        cin >> a;
        X ^= a;
    }
    int D = (S - X) / 2;
    if (D < 0 || D & X || D > A1max || (S - X) & 1) {
        cout << -1 << endl;
        return 0;
    }
    int A1 = D;
    for (int i = 44; i >= 0; --i) {
        if ((X >> i) & 1) {
            A1 += (1ll << i);
            if (A1 > A1max)A1 -= (1ll << i);
        }
    }
    if (A1 == 0) {
        cout << -1 << endl;
    } else {
        cout << A1max - A1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    a, b = i_map()

    print(a+b if a+b < 24 else a+b-24)

if __name__ == '__main__':
    main()


Measured memory_bytes: 77172
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

ll a[105];
ll dp[105][100005];
vector <ll> sum(100005,0),new_sum(100005,0);

ll add(ll a, ll b)
{
	ll res = a + b;
	if(res >= mod)
		return res - mod;
	return res;
}

ll mult(ll a, ll b)
{
	long long res = a;
	res *= b;
	if(res >= mod)
		return res % mod;
	return res;
}

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n,k;
  cin>>n>>k;
  forn(i,1,n+1)
    cin>>a[i];
  dp[0][0]=1;
  forn(i,0,k+1)
    sum[i]=1;
  forn(i,1,n+1){
    forn(j,0,k+1){
      dp[i][j]=sum[j];
      if(j-a[i]-1>=0)
        dp[i][j]=add(dp[i][j],((-sum[j-a[i]-1])%mod+mod)%mod);
      new_sum[j]=dp[i][j];
      if(j-1>=0)
        new_sum[j]=add(new_sum[j],new_sum[j-1]);
    }
    sum=new_sum;
    /*cout<<i<<" : ";
    forn(j,0,k+1)
      cout<<dp[i][j]<<" ";
    cout<<endl;*/
  }
  ll ans=dp[n][k];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 80896
#include <bits/stdc++.h>
#define INL inline
#define REG register
#define DB double
#define LDB long double
#define ULL unsigned long long
#define LL long long

#define RPT(i,x,y) for (REG int i=(x);i<(y);i++)
#define DRPT(i,x,y) for (REG int i=(x);i>(y);i--)
#define MST(a,b) memset((a),(b),sizeof(a))
#define MRK() cout<<"Mark"<<endl;
#define WRT(x) cout<<#x<<" = "<<(x)<<endl;

#define MAXN 10000
#define MAXM 10000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5

#define _ 0
using namespace std;

int n,d;

int main()
{
	cin>>n>>d;
	cout<<n/(2*d+1)+(n%(2*d+1)!=0);
	return ~~(0^_^0);
}



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

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

	int h,w,n;
	cin>>h>>w>>n;
	int x1 = 0 , x2 = h;
	int y1 = 0 , y2 = w;
	for(int i=0;i<n;i++){
			int a,b,c;
			cin>>a>>b>>c;
			if(c == 1)
				x1 = max(x1,a);
			if(c == 2)
				x2 = min(x2,a);
				
			if(c == 3)
				y1 = max(y1,b);
			
			if(c == 4)
				y2 = min(y2,b);
	}
	
	if(x1 > x2 || y1 > y2)
		cout<<0<<endl;
	else
	cout<<(abs(x1-x2)*abs(y1-y2));
	
	
}



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


int main(){
  int n,k,s,i;
  cin >> n >> k >> s;
  vector<int> a(n);
  for(i=0;i<k;i++){
    a[i]=s;
    cout << a[i] << endl;
  }
  for(i=k;k<n;k++){
    a[k]=1000000000-1;
    cout << a[i] << endl;
  }
  return 0;
}


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

int main() {
  ll A,B;
  cin>>A>>B;
  int X=A+B;
  int Y=A-B;
  int Z=A*B;
  int ans=max(max(X,Y),Z);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=200002;

vector<ll> b,c,d;

struct bit{
  //binary indexed tree
  ll dat[MAX_N+1];
  int n=0;
  void init(int N){
    n=N;
    rep(i,N)  dat[i]=0;
    //サイズは余裕を持って宣言すること
  }
  ll sum(int i){//i以下の和を求める
    ll res=0;
    while(i>0){
      res+=dat[i];
      i -= i & -i;
    }
    return res;
  }
  void add(int i,ll a){//i番目の数にaを加える
    while(i<=n){
      dat[i]+=a;
      i += i & -i;
    }
  }
};

bit f;

int main(){
  ll N,K;
  cin >> N >> K ;
  b.resize(N+1);
  c.resize(N+1);
  d.resize(N+1);
  ll _sum=0;
  b[0]=0;
  rep(i,N){
    ll a;
    scanf("%lld",&a);
    _sum += a;
    b[i+1] = _sum - (i+1) * K;
  }
  rep(i,N+1) c[i]=b[i];
  sort(ALL(c));
  rep(i,N+1){
    int key = lower_bound(c.begin(),c.end(),b[i]) - c.begin();
    d[i] = key+1;
  }
  f.init(N+3);
  ll ans=0;
  rep(i,N+1){
    //cout << d[i] << endl;
    ans += f.sum(d[i]);
    f.add(d[i],1LL);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t N; cin>>N;

    int64_t ans=0,n=10;
    while(N%2==0 && n<=N){
        ans+=N/n;
        n*=5;
    }

    cout<<ans<<endl;
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 100005;
ll a[N];

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	REPU(i, 0, n) cin >> a[i];
	ll sum = accumulate(a, a + n, 0LL);
	ll cnt = n * 1LL * (n + 1) / 2;
	if (sum % cnt != 0) puts("NO");
	else {
		ll m = sum / cnt;
		ll tot = 0;
		REPU(i, 0, n) {
			int j = (i + 1) % n;
			if (a[j] - a[i] != m) {
				ll y = m - a[j] + a[i];
				if (y % n != 0) {
					puts("NO"); return 0;
				}
				y /= n;
				if (y <= 0) {
					puts("NO"); return 0;
				}
				tot += y;
			}
		}
		if (tot == m) puts("YES");
		else puts("NO");
	}

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))
 
 
using namespace std;
 
 
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 
typedef long double LD;
typedef unordered_set<int> ui;



int main(){
	std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	string s;
	cin>>s;
	if(s.find("AC") != string::npos) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

sx, sy, tx, ty = map(int, input().split())

mov_x = tx - sx
mov_y = ty - sy

ans = ''
ans += 'R' * mov_x
ans += 'U' * mov_y
ans += 'L' * mov_x
ans += 'D' * mov_y
ans += 'D'
ans += 'R' * (mov_x + 1)
ans += 'U' * (mov_y + 1)
ans += 'L'
ans += 'U'
ans += 'L' * (mov_x + 1)
ans += 'D' * (mov_y + 1)
ans += 'R'
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)

using namespace std;

int main(){

    string s;
    ll k;

    cin >> s;
    cin >> k;

    int ans = 1;

    for(ll i = 0; i < min((ll)s.size(),k); i++){

        if(s[i] != '1'){
            ans = s[i] - 48;
            break;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())

if N%2==1:
    print(0)
else:
    half_N = N//2
    count = 0
    ord = 1

    temp_count = half_N//(5**ord)
    count += temp_count
    while temp_count>0:
        ord += 1
        temp_count = half_N//(5**ord)
        count += temp_count
    print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>a>>b>>c>>d>>n;
    //一リットル
    ll iti;
    iti=min({a*4,b*2,c});
    //
    ll ni=min(iti*2,d);
    
    if(n%2==0)ans=ni*(n/2);
    else ans=ni*(n/2)+iti;
    Cout(ans);
    return 0;
}

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

using namespace std;

typedef long long int ll;

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

  string s, t;
  cin >> s >> t;
  int cnt = 0, n = s.length();

  for (int i = 0; i < n; i++) {
    cnt += (s[i] != t[i]);
  }

  cout << cnt << '\n';
}


Measured memory_bytes: 3836
n=int(input())
m=0
a=0
r=0
c=0
h=0

for i in range(n):
    s=input()
    if s[0]=="M":
        m+=1
    elif s[0]=="A":
        a+=1        
    elif s[0]=="R":
        r+=1        
    elif s[0]=="C":
        c+=1        
    elif s[0]=="H":
        h+=1

d=[0]*5
d[0]=m
d[1]=a
d[2]=r
d[3]=c
d[4]=h

import itertools
dsum=0
for i in itertools.combinations(range(5), 3):
    dsum=dsum+d[i[0]]*d[i[1]]*d[i[2]]
print(dsum)
     

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

#define pii pair <int, int>

#define mp make_pair

#define f first
#define s second

#define pb push_back

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const int N = 1e5 + 10;
const int NN = 20;
const int INF = 1e9 + 7;

struct edge{
  int x, y, z;
};

ll ans;
vector <pair <int, pair <int, int > > > g;
int n;
int p[N];
edge a[N];
pair <int, int> x[N], y[N], z[N];

int get (int x) {
  if (p[x] == x) {
    return x;
  }
  return p[x] = get(p[x]);
}

void unite (int a, int b, int mon) {
  int x = get(a);
  int y = get(b);
  if (x != y) {
    ans += mon * 1LL;
    p[x] = y;
  }
}

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    p[i] = i;
    scanf("%d%d", &a[i].x, &a[i].y);
    x[i].f = a[i].x;
    y[i].f = a[i].y;
    x[i].s = i;
    y[i].s = i;
    z[i].s = i;
  }
  sort (x + 1, x + 1 + n);
  sort (y + 1, y + 1 + n);
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= min(n, i + 3); j++) {
      g.pb({x[j].f - x[i].f, {x[i].s, x[j].s}});
    }
    for (int j = i + 1; j <= min(n, i + 3); j++) {
      g.pb({y[j].f - y[i].f, {y[i].s, y[j].s}});
    }
  }
  sort (g.begin(), g.end());
  for (int i = 0; i < g.size(); i++) {
    unite (g[i].s.f, g[i].s.s, g[i].f);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 18668
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

const int N=4e5+5;

int n;

struct Tnode
{
    vector<int> stop;
    int cnt;
    int P;
    int child[26];
};
string s[N];
Tnode Trie[N];
int nT=0,cnt[N],f[N][27][27],dem[27][27],sz[N];
char p[27];
int root,pos[27];

int AddNode()
{
    nT++;
    for(int i=0; i<26; i++) Trie[nT].child[i]=0;
    Trie[nT].P=0;
    Trie[nT].cnt=0;
    return nT;
}

void AddWord(string s,int i)
{
    int r=root;
    for(int i=0; s[i]!=0; i++)
    {
        int k=s[i]-'a';
        int l;
        if (Trie[r].child[k]==0)
        {
            l=AddNode();
            Trie[r].child[k]=l;
            Trie[l].P=r;
        }
        r=Trie[r].child[k];
    }
    Trie[r].stop.push_back(i);
    Trie[r].cnt++;
    while (r!=root)
    {
        r=Trie[r].P;
        Trie[r].cnt++;
    }
}

int CountPrefix(string s)
{
    int ret=0;
    int r=root;
    for(int i=0;i<s.size()-1;i++)
    {
        int k=s[i]-'a';
        ret+=Trie[Trie[r].child[k]].stop.size();
        r=Trie[r].child[k];
    }
    return ret;
}

void Find(int x)
{
    sz[x]=Trie[x].stop.size();
    for(int i=0;i<26;i++)
    {
        int to=Trie[x].child[i];
        if(to!=0)
        {
            Find(to);
            sz[x]+=sz[to];
        }
    }
}

void dfs(int x)
{
    int r=x;
    for(auto&id:Trie[x].stop)
    {
        for(int i=0;i<26;i++)
        {
            for(int j=0;j<26;j++) f[id][i][j]=dem[i][j];
        }
    }
    for(int i=0;i<26;i++)
    {
        if(Trie[r].child[i]==0) continue;
        int to=Trie[r].child[i];
        for(int j=0;j<26;j++)
        {
            if(i==j||Trie[r].child[j]==0) continue;
            int other=Trie[r].child[j];
            dem[i][j]+=sz[other];
        }
        dfs(to);
        for(int j=0;j<26;j++)
        {
            if(i==j||Trie[r].child[j]==0) continue;
            int other=Trie[r].child[j];
            dem[i][j]-=sz[other];
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        AddWord(s[i],i);
    }
    for(int i=1;i<=n;i++) cnt[i]=CountPrefix(s[i]);
    Find(root);
    dfs(root);
    int q;
    cin>>q;
    while(q--)
    {
        int k;
        cin>>k;
        for(int i=0;i<26;i++)
        {
            cin>>p[i];
            pos[p[i]-'a']=i;
        }
        int res=0;
        for(int i=0;i<=26;i++)
        {
            for(int j=0;j<=pos[i];j++)
            {
                //cout<<' '<<k<<' '<<i<<' '<<p[j]-'a'<<' '<<f[k][i][p[j]-'a']<<'\n';
                res=res+f[k][i][p[j]-'a'];
            }
        }
        cout<<res+cnt[k]+1<<'\n';
    }
}



Measured memory_bytes: 354048
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
int dp[55][55][2555]={};
signed main(){
    int n,a;cin>>n>>a;
    int maxi=-1;
    int x[55];rep(i,1,n+1){
        cin>>x[i]; maxi=max(maxi,x[i]);
    }//i枚目までを使い、合計でj枚使って、kを作れる洗濯指数
    rep(i,0,n+1){
        rep(j,0,i+1){
            rep(k,0,maxi*n+1){
                if(i==0&&k==0&&j==0)dp[i][j][k]=1;
                else if(i>=1&&k<x[i])dp[i][j][k]=dp[i-1][j][k];
                else if(i>=1&&j>=1&&k>=x[i])dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
                else dp[i][j][k]=0;
            }
        }
    }
    int ans=0;
    rep(i,1,n+1){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 55552
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _001_B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            long[] nx = ReadLongs();
            long n = nx[0];
            long x = nx[1];
            Console.WriteLine(Length(n, x));
        }

        static long Length(long n, long x)
        {
            if (x <= n - x)
            {
                long cnt = (n - x) / x;
                if ((n - x) % x == 0)
                {
                    return x * 3 * cnt;
                }
                else
                {
                    long margin = (n - x) % x;
                    return x * 3 * cnt + Length(margin + x, x);
                }
            }
            else
            {

                long cnt = x / (n - x);
                if (x % (n - x) == 0)
                {
                    return (n - x) * 3 * cnt;
                }
                else
                {
                    long nextX = x % (n - x);
                    return (n - x) * 3 * cnt + Length(n - x + nextX, nextX);
                }
            }
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int x=a/b, y=a%b;
    double z=(double)a/(double)b;
    cout << x << " " << y;
    cout <<fixed<< setprecision(5);
    cout << " " << z <<endl;
    return 0;

}


Measured memory_bytes: 3244
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
 
//  int a, b, c, d, e, X, Y;
  int a, b, c,  d, e,f;
  //  double  c;
//  long long  A[1000001]={};
  int  A[2000001]={};
  int  B[2000001]={};
  int  ans[100003]={};
  int  sum[100003]={};
  int  cnt_flag[100003]={};

  int  L[1003]={};


//  long long  a, b, c, d, X, Y;
//  long long   d, X, Y;
  long long JPY;
  double BTC;
  char s[200001]={};
  char t[200001]={};
  char u[200001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  int flag=0;
//  int flag[10000003]={};
  int tmp=0;
//  int min=1000000;
  int min=10;
  int len=0;
  int cnt=0;
  int cnt0=0;
  int cnt1=0;
  int num=0;
//  double ans=0.0;
//  long long ans=0;
  int max=0;
//  int sum=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
 

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

      if(a>b){
      cnt=a+cnt;
      a--;
    } else {
      cnt=b+cnt;
      b--;
    } 
        if(a>b){
      cnt=a+cnt;
      a--;
    } else {
      cnt=b+cnt;
      b--;
    } 
  printf("%d\n", cnt);
/*    
    for(j=0;j<b;j++){
      if( i==A[j][0])
        ans[j]=-sum[i];
      else if(i==A[j][1])
        ans[j]=ans[j]+sum[i];
      printf("%d\n",ans[j]);
    }
    */

//  printf("%s\n",s);
//    else  
  
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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 T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


bool solve(int x, vector<int> &dx){
  // dxを全て使って(各々の符号は反転してもよい)xをつくれるかどうか
  if (dx.size() == 0) return x == 0;
  int N = dx.size();
  // 面倒なのでxは非負にしとく
  x = max(x, -x);
  rep(i, N){ x += dx[i]; dx[i] *= 2; }

  sort(all(dx)); // なんとなくソート
  // dxを好きなだけ使って(重複なし)xを作れるかどうか
  // Nは高々4000個
  if (x > 16000) return false;
  vector<bool> seen(x+1, false);
  seen[0] = true;
  for (int i=0; i<N; i++){
    for (int j=x; j>=0; j--){
      if (seen[j]) continue; // もう作れてるやん
      if (j-dx[i] < 0) continue; // 貰い先がない
      if (!seen[j-dx[i]]) continue; // 貰い先がfalse
      seen[j] = true;
    }
  }
  return seen[x];
}

int main() {
  string s; cin >>s;
  int x,y; cin >>x >>y;
  int yoko = -1;
  int susumu = 0;
  int n = s.size();
  vector<int> dx,dy;
  for (int i=0; i<n; i++){
    if (s[i] == 'F'){
      if (yoko == -1) x--; // 最初は右に行くしかないので目標のx座標を減少させる
      else susumu++;
    }else if (s[i] == 'T'){
      if (yoko == -1) yoko = 0;
      else if (yoko == 1){ if (susumu) dx.push_back(susumu); yoko = 0;}
      else if (yoko == 0){ if (susumu) dy.push_back(susumu); yoko = 1;}
      susumu = 0;
    }
  }
  if (susumu){
    if (yoko == 1) dx.push_back(susumu);
    else if (yoko == 0) dy.push_back(susumu);
  }
  bool ok = solve(x, dx) && solve(y, dy);
  // dxを全て使って(各々の正負は反転してもよい)xを作り、
  // dyを全て使って(各々の正負は反転してもよい)yを作る問題。
  cout <<(ok ? "Yes" : "No") <<endl;
}

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

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(s == u){
        a--;
    }else{
        b--;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,H=map(int,input().split())
A=[]
B=[]
for _ in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)


amax=max(A)
#print(amax)
b=[]
for i in range(N):
    if B[i]>=amax:
        b.append(B[i])
b.sort()
#print(b)
cnt=0
while b:
    if H>0:
        H-=b.pop()
        cnt+=1
    if H<=0:
        print(cnt)
        exit()

cnt+=-(-H//amax)
print(cnt)


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , sum , s;
int a[MAXX];

int main()
{
    _FastIO;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    int ans = 10005;
    for(int i = 0; i < n; i++){
        s += a[i];
        int  k = abs(2 * s - sum);
        ans = min(ans , k);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	string s;
	cin >> s;
	s[1] = s[1] == 'B' ? 'R' : 'B';
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 3640
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

namespace AOJ2
{
    class Program
    {

        static List<int> CorrectCountList = new List<int>();

        static Dictionary<int, int> RankDict = new Dictionary<int, int>();

        static void Main(string[] args)
        {
            
            Dictionary<int, int> teamDict = new Dictionary<int, int>();
            
            while (true)
            {
                string[] inputArray = Console.ReadLine().Split(',');
                if (inputArray[0] == "0" && inputArray[1] == "0")
                {
                    break;
                }
                
                teamDict.Add(int.Parse(inputArray[0]), int.Parse(inputArray[1]));
                CorrectCountList.Add(int.Parse(inputArray[1]));
            }

            CorrectCountList =  CorrectCountList.Distinct().ToList();
            CorrectCountList.Sort();
            CorrectCountList.Reverse();

            SetDictionary();

            List<int> outList = new List<int>();

            string input;
            while ((input = Console.ReadLine()) != null)
            {
                int num = int.Parse(input);
                outList.Add(RankDict[teamDict[num]]);

            }

            foreach (int a in outList)
            {
                Console.WriteLine(a);
            }



        }

        static void SetDictionary()
        {
            for (int i = 0; i < CorrectCountList.Count; i++)
            {
                RankDict.Add(CorrectCountList[i], i + 1);
            }


        }
        
    }
}

Measured memory_bytes: 6440
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#include<map>
#include <limits>
# include <iomanip>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
int kaizyo(int a) {
	long long ans = 1;
	for (int i = a; i > 0; i--) {
		ans *= i;
		ans = ans % 1000000007;
		//cout << ans << endl;
	}
	ans = ans % 1000000007;
	return ans;
}
int main() {
	int N = 0, a[100005], b[100005];
		long long counto = 0;
	cin >> N;
	for (int i = 0; i <= N; i++) {
		cin >> a[i];

	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < N; i++) {
		if (a[i] >= b[i]) {
			counto += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
		else {
			counto += a[i];

			b[i] -= a[i];
			a[i] = 0;
			if (a[i + 1] > 0) {
				if (b[i] >= a[i + 1]) {
					counto += a[i + 1];
					b[i] -= a[i + 1];
					a[i + 1] = 0;
				}
				else {
					counto += b[i];
					a[i + 1] -= b[i];
					b[i] = 0;
				}
			}
			//cout << b[i] << endl;
		}


		//cout << counto << endl;
	}
	cout << counto << endl;
	return 0;
}


Measured memory_bytes: 1024
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;

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

  int n, cnt_ab = 0, last_a = 0, begin_b = 0, banda = 0;
  cin >> n;

  rep(i,n) {
    string s;
    cin >> s;
    rep(i,s.size()-1) if(s.substr(i,2) == "AB") cnt_ab++;
    if(s[0] == 'B') begin_b++;
    if(s[s.size()-1] == 'A') last_a++;
    if(s[0] == 'B' && s[s.size()-1] == 'A') banda++, begin_b--, last_a--;
  }

  if(banda == 0)cout << cnt_ab + min(begin_b, last_a) << endl;
  else if(begin_b + last_a > 0) cout << cnt_ab + banda + min(begin_b, last_a) << endl;
  else if(begin_b + last_a == 0) cout << cnt_ab + banda - 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <set>
#include <string>
#include <cstring>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define MAX 100
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 1e9
#define ll long long
#define vi vector<int>
#define all(a) a.begin(), a.end()
#define pb push_back
#define ull unsigned long long


using namespace  std;
const int N = 1e3 + 5;

void solve(){
    int A, B, C, D;
    std::cin >> A >> B >> C >> D;
    for(int i = 0;A > 0 && C > 0;i++) {
        if(i%2) A -= D;
        else C -= B;
    }
    std::cout << (A <= 0? "No":"Yes") << "\n";

}
int main() {
    fast;
    solve();

}



Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#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 <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
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();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
Graph G(100010);
vector<int> deg;
vector<bool> seen; 

int main(){
  int N;
  cin>>N;
  deg.assign(N,0);
  seen.assign(N,0);
  
  REP(i,N-1){
    int a,b;
    cin>>a>>b;
    --a,--b;
    G[a].PB(b);
    G[b].PB(a);
    deg[a]++,deg[b]++;
  }
  
  bool res=true;
  queue<int> Q;
  REP(i,N){
    if(deg[i]==1) Q.push(i);
  }
  
  while(!Q.empty()){
    int v=Q.front();
    Q.pop();
    if(seen[v]) continue;
    seen[v]=true;
    
    int nv=-1;
    FORE(i,G[v]){
      if(seen[i]==false) nv=i;
    }
    if(nv==-1){
      res=false;
      break;
    }
    seen[nv]=true;
    FORE(nnv,G[nv]){
      if(seen[nnv]) continue;
      deg[nnv]--;
      if(deg[nnv]==1) Q.push(nnv);
    }
  }
  
  if(res) co("Second");
  else co("First");
  return 0;
}

Measured memory_bytes: 6400
// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

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

const int MAXN = (int) 1e5;

int n;

struct node
{
	int u;
	LL D;

	inline bool operator < (const node &rhs) const { return this->D < rhs.D; }

	node() { }
	node(int _u, LL _D): u(_u), D(_D) { }
}d[MAXN + 5];

LL D[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 1; i <= n; ++i) d[i] = node(i, D[i] = read<LL>());
}

int size[MAXN + 5];
vector<int> adj[MAXN + 5];

inline LL dfs_sum(int u)
{
	LL res = size[u] - 1;
	for(auto v : adj[u]) res += dfs_sum(v);
	return res;
}

inline int dfs_chk(int u, LL D0)
{
	if(D[u] != D0) return 0;
	for(auto v : adj[u]) if(!dfs_chk(v, D0 - size[v] + n - size[v])) return 0;
	return 1;
}

inline void solve()
{
	static priority_queue<node> Q;
	static unordered_map<LL, int> id;
	static int vis[MAXN + 5];

	for(int i = 1; i <= n; ++i)
	{
		Q.push(d[i]);
		id[d[i].D] = d[i].u;
		size[d[i].u] = 1;
	}

	static vector<pii> E;

	while(SZ(Q) > 1)
	{
		int u = Q.top().u;
		LL D0 = Q.top().D;
		vis[u] = 1, Q.pop();

		int v = id[D0 + 2 * size[u] - n];
		if(!v || vis[v]) { puts("-1"); return; }
		E.emplace_back(u, v);
		adj[v].push_back(u);
		size[v] += size[u];
	}

	int rt = Q.top().u;
	if(!dfs_chk(rt, dfs_sum(rt))) { puts("-1"); return; }

	for(auto i : E) printf("%d %d\n", i.fst, i.snd);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 17812
#include<bits/stdc++.h>
using namespace std;
// ---------------------------------------------------------------------------
/*https://atcoder.jp/contests/abl/tasks/abl_c
Algo : count number of connected components in graph 
16:23
*/
// ---------------------------------------------------------------------------

#define FASTIO	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define fi(a,b) for(int i=a;i<=b;++i)
#define fj(a,b) for(int j=a;j<=b;++j)
#define all(x) x.begin(),x.end()
// #define int long long

// ---------------------------------------------------------------------------
// Global Variables
const int mod = 1e9+7;
const int maxn = 2e5 + 9;
vector<int>graph[maxn];
bool vis[maxn];
// ---------------------------------------------------------------------------
void dfs(int node){
	vis[node]=true;
	for(auto child:graph[node]){
		if(!vis[child])dfs(child);
	}
}
// ---------------------------------------------------------------------------
void test_case(int tc)
{
	// cout<<"Case #"<<tc<<": ";
	int n,m;cin>>n>>m;
	fi(1,m){
		int u,v;cin>>u>>v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	int cc = 0;
	fi(1,n){
		if(!vis[i])dfs(i),cc++;
	}
	cout<<cc-1<<"\n";
}

int32_t main()
{
	FASTIO;
	#ifndef ONLINE_JUDGE
		freopen("/home/suryakant/input.txt","r",stdin);
		freopen("/home/suryakant/output.txt","w",stdout);
	#endif
	
    int t=1;
    //cin>>t;
    for(int tc=1;tc<=t;++tc)test_case(tc);
}

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

int main(void) {
	int a,b;
	char op;

	do{
		scanf("%d %c %d",&a,&op,&b);
		if(op=='+'){
			printf("%d\n",a+b);
		}
		else if(op=='-'){
			printf("%d\n",a-b);
		}
		else if(op=='*'){
			printf("%d\n",a*b);
		}
		else if(op=='/'){
			printf("%d\n",a/b);
		}
	}while(op!='?');
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    p--;
    if (p != i) {
      cnt++;
    }
  }

  if (cnt <= 2) {
    puts("YES");
  } else {
    puts("NO");
  }

  return 0;
}


Measured memory_bytes: 3600
using System;

namespace ABC168B
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var str = Console.ReadLine();
            if (str.Length <= k)
            {
                Console.WriteLine(str);
            }
            else
            {
                Console.WriteLine(str.Substring(0, k) + "...");
            }
        }
    }
}


Measured memory_bytes: 17632
#include<iostream>
	#include <stdio.h>
	using namespace std;
	int main(){
	int h,w;
	while(cin>>h>>w){
		if(h==0 && w==0)
			break;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
	cout<<'#';
	}
	cout<<endl;
	}
	cout<<endl;
	}
	return 0;
	}



Measured memory_bytes: 3076
import java.util.*;
import java.util.stream.*;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        int m1 = sc.nextInt();
        int d1 = sc.nextInt();
        int m2 = sc.nextInt();
        int d2 = sc.nextInt();
        int isLast = m1 != m2 ? 1 : 0;
        System.out.println(isLast);
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int N;
ll memo[1000001][4];
bool visited[1000001][4];
ll f(int p, int q) {
	if (p == N) return q == 3 ? 1 : 0;
	if (visited[p][q]) return memo[p][q];
	visited[p][q] = true;
	ll r = f(p+1, q|1);
	r += f(p+1, q|2);
	r += f(p+1, q) * 8;
	return memo[p][q] = r % mod;
}
int main() {
	cin >> N;
	cout << f(0, 0) << endl;
}


Measured memory_bytes: 85428
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
  string a,b;
  cin>>a;
  b=a;
  reverse(a.begin(),a.end());
  if(a==b)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 1e9 +5;
int main() {
    int n;
    cin >> n;

    // dp[i][0,2] is the total cost such that we did activity on day i
    int dp[n][3];
    cin >> dp[0][0] >> dp[0][1] >> dp[0][2];

    for (int i = 1; i < n; i++) {
        int c[3];
        for (int j = 0; j < 3; j++) cin >> c[j];
        for (int new_dp[3], j = 0; j < 3; j++) {
            //int new_dp[3];
            for (int k = 0; k < 3; k++) new_dp[k] = dp[i - 1][k];
            new_dp[j] = 0;
            dp[i][j] = c[j] + max({new_dp[0], new_dp[1], new_dp[2]});
        }
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;

    return 0;
}


Measured memory_bytes: 4776
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N, maxim = 0;
    cin >> N;

    vector<ll> V(N+1);

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

    V[N] = (10e+9) +7;
    int k = 0;
    for (int i = 0; i < N;i++) {
        if (V[i] >= V[i+1]) k++;        
        else {
            maxim = max(maxim, k);
            k = 0;
        }
    }

    cout << maxim << endl;
    
    return 0;
}

Measured memory_bytes: 1024
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    ll ans = 0;
    for(int i = 0; i < n - 1; i++){
        ll tmp = a[i] + a[i + 1] - x;
        if(a[i] + a[i + 1] > x){
            if(a[i + 1] - tmp >= 0){
                a[i + 1] -= tmp;
                ans += tmp;
            } else {
                a[i + 1] = 0;
                ans += a[i + 1] + abs(tmp);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int n,i,j,m,a,b,c,d,r[102],t[102],p[102]={0};
  scanf("%d",&n);
  m=(n*(n-1))/2;
  while(m--){
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(c>d)p[a]+=3;
    if(c<d)p[b]+=3;
    if(c==d){
      p[a]++;
      p[b]++;
    }
  }
  for(i=0;i<=n;i++){//printf("%d ",p[i]);
    r[i]=i;//printf(":%d ",r[i]);
    for(j=i;j>1;j--){
      if(p[r[j-1]]<p[r[j]]){
	a=r[j-1];
	r[j-1]=r[j];
	r[j]=a;
      }
    }
  }//printf("\n");
  j=0;
  for(i=1;i<=n;i++){//printf(";%d ",r[i]);
    if(p[r[i-1]]-p[r[i]])j=i;
    t[r[i]]=j;
  }
  for(i=1;i<=n;i++)printf("%d\n",t[i]);
  return 0;
}
     

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

s=[0]*n
s[0]=a[0]
for i in range(1,n):
    s[i]=s[i-1]+a[i]

dmin=10**15
x=s[n-1]
for  i in range(n-1):
    dmin=min(dmin,abs(x-2*s[i]))
print(dmin)
    

Measured memory_bytes: 24832
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set> 
#include<cmath>
using namespace std;
long long p = 998244353;
//long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) { pa[x] = y; }
}
#define Yes "Yay!"
#define No ":("
signed main() {
	/*int h, w, k; cin >> h >> w >> k;
	V<string> s(h);
	rep(i, h) { cin >> s[i]; }
	rep(i, h) {
		rep(j, w) {
			if (s[i][j] == '#') { is_st[i] = true; }
		}
		s[i] += '.';
		if (is_st[i]) { s[i] = '#'; }
	}
	s.push_back(string(w + 1, '#'));
	int now_st = 1;
	h++; w++;*/
	int n; cin >> n;
	int ans = -1; int sum = 0;
	rep(i, n) {
		int d, c; cin >> d >> c;
		ans += c; sum += d * c;
	}
	ans += ((sum-1) / 9);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408