akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 110;
int N, M;
int cost[MAX][MAX];
int war[MAX][MAX];

int main(void) {
    scanf("%d%d", &N, &M);
    REP(i, MAX) REP(j, MAX) {
        cost[i][j] = war[i][j] = INF;
    }
    REP(i, M) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        a--;b--;
        cost[a][b] = cost[b][a] = c;
        war[a][b] = war[b][a] = c;
    }
    int ans = M;
    REP(k, N) REP(i, N) REP(j, N) {
        chmin(war[i][j], war[i][k] + war[k][j]);
    }
    REP(i, N) FOR(j, i + 1, N) if (cost[i][j] != INF) {
        ans -= (cost[i][j] == war[i][j]);
    }
    printf("%d\n", ans);
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

struct R {
    int id;
    string s;
    int p;

    bool operator<(const R& r) const { return s != r.s ? s < r.s : p > r.p; }
};

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

    int n;
    cin >> n;

    vector<R> r(n);
    rep(i, 0, n) {
        r[i].id = i + 1;
        cin >> r[i].s >> r[i].p;
    }

    sort(all(r));
    rep(i, 0, n) { cout << r[i].id << endl; }

    return 0;
}

Measured memory_bytes: 256
x = int(input())
d = {}
for i in range(1000):
  b = (-1000+i)**5
  d[b] = -1000+i
for i in range(1000):
  a = i**5
  d[a] = i
  if a-x in d:
    b = d[a-x]
    a = i
    break
print(a,b)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n,m;
vector<int> g[111111];
bool vis[111111];
vector<int> a,b;

void dfs(int v,vector<int>& tmp){
  vis[v]=true;
  for(int nv: g[v]){
    if(!vis[nv]){
      dfs(nv,tmp);
      break;
    }
  }
  tmp.pb(v+1);
  return ;
}

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].pb(b); g[b].pb(a);
  }
  vector<int> resa,resb,res;
  dfs(0,resa);
  dfs(0,resb);
  reverse(all(resb));
  rep(i,resa.size())res.pb(resa[i]);
  repl(i,1,resb.size())res.pb(resb[i]);
  cout<<res.size()<<endl;
  rep(i,res.size()){
    printf("%d%c", res[i],i==res.size()-1?'\n':' ');
  }
	return 0;
}


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

int main() {
  ll n;
  cin >> n;
  string ans;
  while(n>0){
    n--;
    ans += 'a'+n%26;
    n/=26;
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
}


Measured memory_bytes: 3604
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

D, G = MAP()
pc = [LIST() for _ in range(D)]
count_min = 1000000000
for i in range(1<<D):
	sum_ = 0
	count = 0
	i = list("{:b}".format(i).zfill(D))
	# print(i)
	for j in range(D):
		if i[j] == '1':  # j = '1' なら全部加える
			sum_ += (j+1)*100*pc[j][0] + pc[j][1]
			count += pc[j][0]
	if sum_ >=  G:
		if count < count_min:
			# print("更新", count_min,"->",count)
			count_min = count
	else:  # 中途半端にとる
		for j in range(D-1, -1, -1):
			if i[j] == '0':  # G - sum_ : 残りのポイント
				num = ceil((G-sum_)/((j+1)*100))
				# print(num)
				if num > pc[j][0]:
					count = 1000000000
					break
				count += ceil((G-sum_)/((j+1)*100))
				break
		if count < count_min:
			# print("更新", count_min,"->",count)
			count_min = count

print(count_min)


Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	ll total = 0;
	if(n>=500){
		int tmp = n/500;
		n-= tmp*500;
		total+=tmp*1000;
	}
	if(n>=5){
		int tmp1 = n/5;
		n-= tmp1*5;
		total+=tmp1*5;
	}
	out(total);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

#include <iostream>
#include <vector>
#include <tuple>
#include <string>

using namespace std;

#define MIN(A, B)	((A) < (B) ? (A) : (B))

int main(int argc, char const *argv[]) {
	int n;
	cin >> n;

	int a['z' - 'a' + 1];
	int t['z' - 'a' + 1];

	for (int i = 'a'; i <= 'z'; ++i) {
		a[i - 'a'] = 32767;
	}

	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;

		for (int j = 'a'; j <= 'z'; ++j) {
			t[j - 'a'] = 0;
		}

		for (int j = 0; j < s.length(); ++j) {
			t[s[j] - 'a'] += 1;
		}

		for (int j = 'a'; j <= 'z'; ++j) {
			a[j - 'a'] = MIN(a[j - 'a'], t[j - 'a']);
		}
	}

	for (char i = 'a'; i <= 'z'; ++i) {
		for (int j = 0; j < a[i - 'a']; ++j) {
			cout << i;
		}
	}
	cout << endl;
	return 0;
}

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

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

  if ((s[0] == s[1]) && (s[1] == s[2]) && (s[2] == s[3])){
    cout << "No" << endl;
  }else if((s[0] == s[1] && s[2] == s[3]) || (s[0] == s[2] && s[1] == s[3]) || (s[0] == s[3] && s[1] == s[2]) ){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }




  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int h,w,i,k;
	scanf("%d%d",&h,&w);
	char s[h+2][w+3];
	for(i=0;i<=h+1;i++)
		{
		if(i==0 || i==h+1)
			{for(k=0;k<=w+1;k++){s[i][k]='#';}}
		else	{scanf("%s",s[i]);}
		}
	for(i=1;i<=h;i++)
		{
		for(k=w+1;k>=0;k--)
			{
			if(k==w+1 || k==0){s[i][k]='#';}
			else {s[i][k]=s[i][k-1];}
			}
		}
	
	for(i=0;i<=h+1;i++)
		{
		for(k=0;k<=w+1;k++)
			{printf("%c",s[i][k]);}
		printf("\n");
		}
return 0;
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,p,e=0,o=0,a,c=1,b,d=0;
  cin>>n>>p;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a%2==0) e++;
    else o++;
  }
  for(int i=0;i<e;i++) c*=2;
  for(int i=p;i<=o;i+=2){
    b=1;
    for(int j=0;j<i;j++){
      b*=o-j;
      b/=j+1;
    }
    d+=b*c;
  }
  cout<<d;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m; cin>>n>>m;
	vll a(n), use(n, 0);
	priority_queue<pair<ll, ll> > que;
	rep(i, n){
		cin>>a[i];
		que.push(mp(a[i], i));
	}
	rep(i, m){
		pair<ll, ll> p = que.top(); que.pop();
		ll num = p.fi;
		ll idx = p.se;
		use[idx]++;
		que.push(mp(num/2, idx));
	}
	ll ans=0;
	rep(i, n){
		ans+=a[i]/(1ll<<use[i]);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3956
def main():
    s = list(map(int, list(input())))
    n = len(s)
    dp = [1]
    mod = 998244353
    for i, c in enumerate(s):
        dp2 = [0]*(i+2)
        for r in range(i+1):
            if r+c > 0:
                dp2[r+c-1] = (dp2[r+c-1]+dp[r]) % mod
            if i+2-r-c > 0:
                dp2[r+c] += (dp2[r+c]+dp[r]) % mod
        dp = dp2
    for i in range(n):
        dp2 = [0]*(n-i)
        for r in range(n-i+1):
            if r > 0:
                dp2[r-1] = (dp2[r-1]+dp[r]) % mod
            if n-i-r > 0:
                dp2[r] = (dp2[r]+dp[r]) % mod
        dp = dp2
    print(dp[0] % mod)


main()


Measured memory_bytes: 42716
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;

int main(){
    int n;
    cin>>n;
    int a[200020],b[200020];
    rep(i,0,n)cin>>a[i],b[i]=a[i];
    sort(a,a+n);
    
    int med1=a[n/2-1],med2=a[n/2];
    rep(i,0,n){
        if(b[i]>med1)cout<<med1<<endl;
        else cout<<med2<<endl;
    }
    return 0;
}

Measured memory_bytes: 3712
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce
import bisect

MOD = 10**9 + 7
INF = float('inf')

A, V = list(map(int, input().split()))
B, W = list(map(int, input().split()))
T = int(input())

dist = abs(A-B)
vel = (V-W)*T

if dist <= vel:
    print("YES")
else:
    print("NO")

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

bool f(int x) {
    int keta = 0;
    while (x) {
        keta++;
        x /= 10;
    }
    return keta%2 == 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int pre = -999;
    rep(i, n) {
        if (pre <= h[i]-1) pre = h[i]-1;
        else if (pre <= h[i]) pre = h[i];
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int gcd = a[0];
	for(int i=0;i<n;i++)gcd=__gcd(a[i],gcd);
	int maxi = INT_MIN;
	for(int i=0;i<n;i++)maxi=max(maxi,a[i]);
	if(k%gcd!=0||k>maxi)cout<<"IMPOSSIBLE"<<endl;
	else cout<<"POSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n+2][4];
    for(int i=0;i<n;i++)
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    for(int i=n-2;i>=0;i--)
    {
        arr[i][0]+=max(arr[i+1][1],arr[i+1][2]);
        arr[i][1]+=max(arr[i+1][0],arr[i+1][2]);
        arr[i][2]+=max(arr[i+1][0],arr[i+1][1]);
    }
    arr[0][0]=max(arr[0][0],arr[0][1]);
    arr[0][0]=max(arr[0][0],arr[0][2]);
    cout<<arr[0][0];
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%i",&n);
	vector<int> a(n*2);
	for(int &i:a)scanf("%i",&i);
	sort(a.begin(),a.end());
	int ans=0;
	for(int i=0;i<2*n;i+=2)ans+=a[i];
	printf("%i\n",ans);
	return 0;
}

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


long long func(long long N,long long A){
  long long res=A*(2*N-A+1)/2-A*(A-1)/2+1;
  return res;
}

int main(){
  long long N,K,mod=1000000007;
  cin >> N >> K;
  long long sum=0;
  for(long long i=K;i<N+2;i++){
    long long A=func(N,i)%mod;
    sum=(sum+A)%mod;
  }
  cout << sum <<endl;
}

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

int main(){
    long long int n,a,b;
    cin>>n>>a>>b;

    long long int ans = -(a*(n-1)+b)+(b*(n-1)+a)+1;
    if(ans<0)ans=0;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
using   ll=long long;
using   ld=long double;
 
#define fast           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl           "\n"
#define int            long long 
#define pb             push_back
#define mp             make_pair
#define vll            vector<ll>
#define ff              first
#define ss              second
#define pll            pair<ll,ll>
#define ALL(v)         v.begin(),v.end()
#define ALLR(v)        v.rbegin(),v.rend()
#define pii            3.14159265358979323
 
void solve()
{
    ll n,m,p,ans=0,cn=0;
    
    cin>>n>>m;
    
    string s;
    
    map<ll,ll> tt;
    
    vector<ll> vis(n+1,0);
    
    for(int i=0;i<m;i++)
    {
        cin>>p>>s;
        
        if(vis[p])    continue;
        
        if(s=="AC") 
        {
            ans+=tt[p];
            cn++;
            vis[p]++;
        }
        else
        {
            tt[p]++;
        }
    }
    
    cout<<cn<<" "<<ans;
}
 
 
signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define make0(a) memset(a,0,sizeof(a))
#define make1(a) memset(a,-1,sizeof(a))
#define ALL(v) v.begin(),v.end()
#define pi pair <int,int>
#define pll pair <ll,ll>
#define fast_cin() ios_base::sync_with_stdio(0)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int mod = 1e9+7;

ll solve(pair <vector <int>, ll> a[], int n, vector <int> k, int res)
{
	ll ans = 0;
	for(int i = 1; i <= n; i ++)
	{
		vector <int> tbin = a[i].F;
		bool accept = true;
		for(int j = 0; j < res; j++)
		{
			if(tbin[j] == 1 and k[j] == 0)
				accept = false;
		}
		if(tbin[res] == 1)
			accept = false;
		// if(res == 30)
		// 	cout << tbin[res] << endl;
		ans += (accept == true ? a[i].S:0);
	}
	return ans;
}

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

	vector <int> k_bin;
	pair <int, ll> tmp[n + 1];
	pair <vector <int>, ll> a[n + 1];
	for(int i = 1; i <= n; i++)
		cin >> tmp[i].F >> tmp[i].S;
	if(k == 0)
	{
		ll ans = 0;
		for(int i = 1; i <= n; i++)
			ans += (tmp[i].F == 0 ? tmp[i].S:0);
		cout << ans << endl;
		return 0;
	}
	while(k)
	{
		k_bin.pb(k % 2);
		k /= 2;
	}
	for(int x = k_bin.size(); x < 30; x++)
		k_bin.pb(0);
	reverse(ALL(k_bin));
	k_bin.pb(0);


	int p = 0;
	for(p; p <= 30; p++)
		if(k_bin[p] == 1)
			break;


	for(int i = 1; i <= n; i++)
	{
		int x = tmp[i].F;
		a[i].S = tmp[i].S;
		vector <int> bin;
		while(x)
		{
			bin.pb(x % 2);
			x /= 2;
		}
		for(int x = bin.size(); x < 30; x ++)
			bin.pb(0);
		reverse(ALL(bin));
		bin.pb(0);
		a[i].F = bin;
	}
	ll ans = 0;
	for(int i = 0; i < 30; i++)
		if(k_bin[i])
			ans = max(ans, solve(a, n, k_bin, i));
	ans = max(ans, solve(a, n, k_bin, 30));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 21120
#include <cctype>
#include <string>
#include <cstring>
#include <iostream>

using namespace std;

int main()
{
    string S;
    
    int C[26];
    
    memset(C, 0, sizeof(C));
    
    while(getline(cin, S))
    {
        for(unsigned i = 0; i < S.size(); i++)
        {
            if(isalpha(S[i]))
            {
                if(S[i] < 91)
                {
                    C[S[i] - 65]++;
                }
                else
                {
                    C[S[i] - 97]++;
                }
            }
        }
    }
    
    for(int i = 0; i < 26; i++)
    {
        cout << (char)(i + 97) << " : " << C[i] << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3156
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  long long a[N];
  long long b[N];
  for (int i = 0; i < N; ++i) {
    cin >> a[i] >> b[i];
  }

  long long ret = 0;
  for (int i = N - 1; i >= 0; --i) {
    if (a[i] + ret == 0)
      continue;
    if (a[i] + ret > b[i] && (a[i] + ret) % b[i] != 0) {
      ret += b[i] * ((a[i] + ret) / b[i] + 1) - (a[i] + ret);
    } else if (a[i] + ret < b[i] && b[i] % (a[i] + ret) != 0) {
      ret += b[i] - (a[i] + ret);
    }
  }

  cout << ret << 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 FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s;
	cin >> s;
	if (s.back() == '3') cout << "bon" << endl;
	else if (s.back() == '0' || s.back() == '1' || s.back() == '6' || s.back() == '8') cout << "pon" << endl;
	else cout << "hon" << endl;
    
    return 0;
}


Measured memory_bytes: 3616
#B - 文字列大好きいろはちゃんイージー

mylist=[]
mylist_int=[]
words=[]
sorted_words=[]
result=""


mylist=input().split()
mylist_int=[int(s) for s in mylist]

#numberは文字列の数、lengthは文字列の長さ

number=mylist_int[0]
length=mylist_int[1]

for i in range(number):
    words.append(input())
    #print(words)
    
result=words #初期値
    
#sortedという関数を使う
sorted_words=sorted(words)

#print(sorted_words)

#sorted_wordsを連結する

result="".join(sorted_words)
    
print(result)

Measured memory_bytes: 38256
from collections import deque 
from copy import deepcopy
# 初期入力
import sys
input = sys.stdin.readline
H,W = (int(i) for i in input().split())
map_initial =[["#"]*(W+2) for i in range(H+2)] #周囲を壁にするため＋２
for h in range(1,H+1):
    map_initial[h] =["#"] +list(input().strip()) +["#"]

def BSF(x,y):
    dist =0
    map =deepcopy(map_initial)
    if map[x][y] =="#":
        return dist 
    dq =set()
    dq.add((x,y))
    dq_sarch =set()
    while len(dq) >0:
        h,w =dq.pop()
        map[h][w] ="#" #通り済を壁にする
        if map[h+1][w]==".":
            dq_sarch.add((h+1,w))
        if map[h-1][w]==".":
            dq_sarch.add((h-1,w))
        if map[h][w+1]==".":
            dq_sarch.add((h,w+1))
        if map[h][w-1]==".":
            dq_sarch.add((h,w-1))
        if len(dq)==0:
            dq =deepcopy(dq_sarch)
            dq_sarch.clear()
            dist +=1
        #print(h,w,dist,end="\t")
    return dist-1

#スタート位置を全探索し、最長距離を探す
dist_all =[]
for i in range(1,H+1):
    for j in range(1,W+1):
        dist_all.append(BSF(i,j) )
print(max(dist_all))

Measured memory_bytes: 9696
#include <iostream>
#include <string>
using namespace std;
#define MOD 1000000007

int main(int argc, char const *argv[]) {
  int n;
  long long ans=1;
  std::cin >> n;

  for(int i=2; i<=n; i++){
    ans=(ans*i)%MOD;
  }

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


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 100005;

int n,m,v,p;
int a[MAXN];

bool ok(int cur)
{
	if (a[cur] + m < a[p])
		return 0;
	ll tot = 0;
	for (int i = p;i <= n;i++)
		if (i != cur && a[i] < a[cur] + m)
			tot += min(m,a[cur] + m - a[i]);
	return tot >= (ll)(v - 1) * m;
}

int main()
{
	scanf("%d%d%d%d",&n,&m,&v,&p);
	for (int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	sort(a + 1,a + n + 1);
	reverse(a + 1,a + n + 1);
	v = max(1,v - p + 1);
	int low = p,high = n;
	while (low < high)
	{
		int mid = low + high + 1 >> 1;
		if (ok(mid))
			low = mid;
		else
			high = mid - 1;
	}
	printf("%d\n",low);
	return 0;
}


Measured memory_bytes: 640
from sys import stdin

N = int(stdin.readline())
a_dict = {}
A = list(map(int, stdin.readline().split()))
for a in A:
    if a in a_dict:
        a_dict[a] += 1
    else:
        a_dict[a] = 1

sum_comb = 0
B = set(A)
for b in B:
    n = a_dict[b]
    sum_comb += n * (n - 1) // 2

for a in A:
    ans = sum_comb
    n = a_dict[a]
    ans -= n * (n - 1) // 2
    ans += (n - 1) * (n - 2) // 2
    print(ans)


Measured memory_bytes: 85456
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	nn := n / (a + b)
	na := n % (a + b)
	var nb int
	if na >= a {
		nb = a
	} else {
		nb = na
	}
	fmt.Println(nn*a + nb)
}


Measured memory_bytes: 512
input = input().split(" ")
if int(input[0]) == int(input[1]):
  string = ""
  for i in range(int(input[1])):
    string += input[0]
  print(string)
else:
  stro = ""
  strt = ""
  for i in range(int(input[1])):
    stro += input[0]
  for i in range(int(input[0])):
    strt += input[1]
  if int(stro) > int(strt):
    print(stro)
  elif int(strt) > int(stro):
    print(strt)

Measured memory_bytes: 3064
n = int(input())
b = [int(i) for i in str(input()).split(" ")]
a = [0] * (n)

for i in range(n - 1):
  # b[i] >= max(a[i], a[i+1])
  if i == 0:
    a[i] = b[i]

  if i == n - 1 - 1:
    a[i + 1] = b[i]
  else:
    a[i + 1] = min(b[i], b[i + 1])

print(sum(a))

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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  string s = stin();
  int cum_black_count[n+1];
  int cum_white_count[n+1];
  cum_black_count[0] = 0;
  for(int i = 0; i < n; ++i) {
    cum_black_count[i+1] = cum_black_count[i];
    if(s[i] == '#') ++cum_black_count[i+1];
  }
  cum_white_count[n] = 0;
  for(int i = n-1; i >= 0; --i) {
    cum_white_count[i] = cum_white_count[i+1];
    if(s[i] == '.') ++cum_white_count[i];
  }
  int min_ans = LLONG_MAX;
  for(int i = 0; i < n+1; ++i) {
    min_ans = min(min_ans, cum_black_count[i] + cum_white_count[i]);
  }
  cout << min_ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3716
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const ll INF = 1<<30;
const ll MOD = 1e9 + 7;
const ll MAX_N = 110;
ll G[MAX_N][MAX_N];
ll dp[MAX_N][MAX_N];
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < n; j++) dp[i][j] = G[i][j] = INF;
    }
    for(ll i = 0; i < n; i++) dp[i][i] = G[i][i] = 0;
    for(ll i = 0; i < m; i++)
    {
        ll a, b, c; cin >> a >> b >> c;
        a--, b--;
        G[a][b] = c;
        G[b][a] = c;
        dp[a][b] = c;
        dp[b][a] = c;
    }
    for(ll k = 0; k < n; k++)
    {
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < n; j++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
        }
    }
    ll ans = 0;
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < n; j++)
        {
            if(G[i][j] == INF) continue;
            if(dp[i][j] != G[i][j]) ans++;
        }
    }
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 384
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), [](char a, char b){return a > b;});
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i] != i+1)
        {
            count++;
        }
    }
    //cout << count << endl;
    if(count <= 2)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

ll n;
string s0, s;
ll anscnt = 0;
vector<string> ans;
vector<bool> used(26, false);
void dfs(ll pos) {
    if (pos == n) {
        // if (ans.size() == 10) {
        //     ll x = lower_bound(all(ans), s) - ans.begin();
        //     if (x < 10) {
        //         ans[x] = s;
        //         rep(i, x+1, 10) {
        //             ans[i] = ans[i-1];
        //         }
        //     }
        // }
        // else {
        //     ans.pb(s);
        // }
        ans.pb(s);
        ++anscnt;
        return;
    }
    ll c = s0[pos] - 'a';
    if (used[c]) {
        s[pos] = s0[pos];
        dfs(pos+1);
    }
    if (c+1 < 26 && !used[c+1]) {
        used[c+1] = true;
        s[pos] = s0[pos]+1;
        dfs(pos+1);
        used[c+1] = false;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> s0, s0 != "#") {
        n = s0.size();
        s = s0;
        ans.clear();
        anscnt = 0;
        used[0] = true;
        dfs(0);
        sort(all(ans));
        cout << ans.size() << endl;
        if (ans.size() > 10) {
            rep(i, 5) cout << ans[i] << endl;
            rep(i, 5) cout << ans[ans.size()-5+i] << endl;
        }
        else {
            each(a, ans) cout << a << endl;
        }
        // cout << anscnt << endl;
        // each(a, ans) cout << a << endl;
    }
}



Measured memory_bytes: 4220
#include<stdio.h>

int main(void)
{
    int n, m, i, j, card[4][14] ={0};
    char s, S[]="SHCD";
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf(" %c %d", &s, &m);
        for (j=0; j<4; j++)
             if (s == S[j]) card[j][m] =1;
    }
    for (i = 0; i < 4; i++) {
        for (j = 1;  j < 14; j++) {
            if (card[i][j] == 0) {
                printf("%c %d\n", S[i], j);
             }
         }
    }
}




Measured memory_bytes: 2076
import sys
import math
import numpy as np
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def S():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


inf = float("inf")
mod = 10 ** 9 + 7

h, w = MI()

white = 0
s = [["#"] * (w + 2)]
for i in range(h):
    line = S()
    white += line.count(".")
    s.append(["#"] + list(line) + ["#"])
s.append(["#"] * (w + 2))
s[1][1] = "#"


dxy = ((0, 1), (0, -1), (1, 0), (-1, 0))

step = 1
q = [(1, 1)]
while q:
    qq = []
    for x, y in q:
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy
            if s[nx][ny] == "#":
                continue
            if nx == h and ny == w:
                print(white - (step + 1))
                exit()
            qq.append((nx, ny))
            s[nx][ny] = "#"
    q = qq
    step += 1

print(-1)


Measured memory_bytes: 12448
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int A,B,C;
      cin >> A >> B >> C;
      
      if (A == B && A == C) {
        cout << "No" << endl;
      }
      
      else if (A != B && B != C && A != C) {
        cout << "No" << endl;
      }
      
      else {
        cout << "Yes" << endl;
      }
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vb used;
vvi g;
vi ans;
ll dfs(ll i){
    ans.pb(i+1);
    used[i]=true;
    for(ll x:g[i])if(!used[x]){
        return dfs(x);
    }
    return i;
}
int main(){
    ll n,m;cin>>n>>m;
    g=vvi(n);
    used=vb(n,false);
    rep(i,m){
        ll a,b;cin>>a>>b;a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(0);
    reverse(all(ans));
    for(ll x:g[0])if(!used[x]){
        dfs(x);
        break;
    }
    out(ans.size());
    outv(ans);
}

Measured memory_bytes: 10868
def solve():
    s = input()

    if s.count("W") == 0 or s.count("W") == len(s):
        return 0

    counter = 0
    i = len(s) - 1
    while 0 < i:
        tail = s[i]
        # print("i, tail", i, tail)
        if tail == "W":
            # 右端に B を打つ
            # print("B")
            counter += 1
            # 直近の B を探す
            while 0 < i and not s[i] == "B":
                i -= 1
            # print("\t", i)
            # assert s[i] == "B"

            # 左端の B を探す
            if s[i - 1] == "B":
                while 0 < i and s[i - 1] == "B":
                    i -= 1
            # print("\t\t", i)

        else:
            # 右端に W を打つ
            # print("W")
            counter += 1
            # 直近の W を探す
            while 0 < i and not s[i] == "W":
                i -= 1
            # print("\t", i)
            # assert s[i] == "W"

            # 左端の W を探す
            if s[i - 1] == "W":
                while 0 < i and s[i - 1] == "W":
                    i -= 1
            # print("\t\t", i)

    # print("c", counter)

    return counter


if __name__ == '__main__':
    res = solve()
    print(res)



Measured memory_bytes: 40944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

void change(string s, vector<set<int>>& index, int i, char c){
    if (s[i] == c) return;
    int pre = s[i] - 'a';
    int to = c - 'a';
    index[pre].erase(i);
    index[to].insert(i);
    return;
}

int calc(string s, vector<set<int>>& index, int l, int r){
    int res = 0;
    rep(i, index.size()){
        if (index[i].size() == 0) continue;
        auto itr = index[i].lower_bound(l);
        if (itr == index[i].end()) continue;
        if (*itr <= r) res++;
    }
    return res;
}

int main(){
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> index(26);
    rep(i,n){
        int j = s[i] - 'a';
        index[j].insert(i);
    }

    vector<int> ans;
    rep(k,q){
        int t;
        cin >> t;
        if (t == 1){
            int i;
            char c;
            cin >> i >> c;
            i--;
            change(s, index, i, c);
            s[i] = c;
        }else{
            int l, r;
            cin >> l >> r;
            l--; r--;
            ans.push_back(calc(s, index, l, r));
        }
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 27844
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
// Time Complexity: faster than O(logN)[O(ArkInv(N))]
// UnionFind.data: if minus -> size of subtree (node is root)
// if plus -> parent of the node
struct UnionFind {
    vector<int> data;
    UnionFind(int sz){
        data.assign(sz,-1);
    }
    int find(int x){
        if(data[x]<0) return x;
        return data[x]=find(data[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if(x==y) return false;
        if(data[x]>data[y]) swap(x,y);
        data[x]+=data[y];
        data[y]=x;
        return true;
    }
    int size(int x){
        return (-data[find(x)]);
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
};
#pragma endregion library

int main(){
    int n,m ; cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int x,y,z; cin >> x >> y >> z;
        x--; y--;
        uf.unite(x,y);
    }
    set<int> par;
    rep(i,n){
        par.emplace(uf.find(i));
    }
    cout << par.size() << '\n';
    
}


Measured memory_bytes: 8304
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        n=int(input())
        l=[list(map(int,input().split())) for i in range(n)]
        l.insert(0,[0,0,0])
        for j in range(n):
            t,x,y=l[j+1][0]-l[j][0],l[j+1][1]-l[j][1],l[j+1][2]-l[j][2]
            if t<(abs(x)+abs(y))or t%2!=(abs(x)+abs(y))%2:
                return 'No'
        return 'Yes'
    print(main())
resolve()

Measured memory_bytes: 57564
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}
//小文字=大文字+32
int main() {
	int n;
	cin >> n;
	vector<ll>h(n);
	vector<ll>cost(n);
	rep(i, n) {
		cin >> h[i];
	}
	cost[0] = 0;
	cost[1] = labs(h[1]-h[0]);
	for (int i = 2; i < n; i++) {
		cost[i] = min(cost[i - 1] +labs(h[i] - h[i - 1]),cost[i - 2] + labs(h[i] - h[i - 2]));

	}
	cout << cost[n - 1];
	
}


Measured memory_bytes: 4760
// ALDS_1_2_A Bubble Sort

#include <iostream>
#define NMAX	100

void swap(int *array, int a, int b){
	int tmp;

	tmp = array[a];
	array[a] = array[b];
	array[b] = tmp;

	return;
}

int main(int argc, char *argv[]){
	int N;
	int A[NMAX];
	int swap_cnt = 0;

	std::cin >> N;
	for(int i=0 ; i<N ; i++){
		std::cin >> A[i];
	}

	bool is_sorted = false;
	for(int j=0 ; (j<=N-1)&&(!is_sorted) ; j++){
		is_sorted = true;
		for(int i=N-1 ; i>j ; i--){
			if(A[i] < A[i-1]){
				is_sorted = false;
				swap(A, i, i-1);
				swap_cnt++;
			}
		}
	}

	for(int i=0 ; i<N-1 ; i++){
		std::cout << A[i] << " ";
	}
	std::cout << A[N-1] << std::endl;
	std::cout << swap_cnt << std::endl;

	return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<int> B(N - 1);
  for(int i = 0; i < N - 1; i++) {
    cin >> B.at(i);
  }
  long long ans = B.at(0);
  for(int i = 1; i < N - 1; i++) {
    ans += min(B.at(i - 1), B.at(i));
  }
  ans += B.at(N - 2);
  cout << ans << endl;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


int N;
int a[200001];
int ball[200001];

signed main(){
    cin >> N;
    REP(i, N){
        cin >> a[i + 1];
        ball[i + 1] = 0;
    }
    int cnt = 0;
    for(int i = N; i >= 1; i--){
        ball[i] = a[i];
        for(int j = 2; i * j <= N; j++){
            ball[i] = ball[i] ^ ball[i * j];
        }
        if(ball[i] == 1) cnt++;
    }
    PRINT(cnt);
    REP(i, N){
        if(ball[i + 1] == 1) cout << i + 1 << " ";
    }
    if(cnt > 0) cout << endl;
    return 0;
}

Measured memory_bytes: 2432
t1 = [35.5, 37.5, 40.0, 43.0, 50.0, 55.0, 70.0]
t2 = [71.0, 77.0, 83.0, 89.0, 105.0, 116.0, 148.0]
s = ["AAA", "AA", "A", "B", "C", "D", "E", "NA"]
while True:
    try:
        x1, x2 = map(float, raw_input().split())
        i = 0
        while i<7 and (t1[i]<=x1 or t2[i]<=x2):
            i += 1
        print s[i]
    except EOFError:
        break

Measured memory_bytes: 4244
import itertools

N = int(input())
X = []
Y = []
seq = list(itertools.permutations([i for i in range(1,N+1)]))
a = 0
for i in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
for h in range(len(seq)):
    for i in range(N-1):
        a += ((X[seq[h][i]-1]-X[seq[h][i+1]-1])**2+(Y[seq[h][i]-1]-Y[seq[h][i+1]-1])**2)**0.5
print(a/len(seq))

Measured memory_bytes: 13900
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using P = pair<int,int>;
const int INF = 1e9;
#define rep(i,N) for(int (i) = 0; (i) < (N);++(i))

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

    int dp[100100];
    rep(i,N+1) dp[i] = INF;
    dp[0] = 0;

    for(int i = 1;i <= N;++i){
        for(int six = 6; six <= i; six *= 6){
            dp[i] = min(dp[i],dp[i-six]+1);
        }
        for(int nine = 9; nine <= i; nine *= 9){
            dp[i] = min(dp[i],dp[i-nine]+1);
        }
        dp[i] = min(dp[i],dp[i-1]+1); 
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

int main()
{

  int N;
  cin >> N;
  vector<int> A(N);
  priority_queue<int> Q;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    Q.push(A[i]);
  }

  int v0 = Q.top();
  Q.pop();
  int v1 = Q.top();

  for (int i = 0; i < N; ++i) {
    if (A[i] == v0) {
      cout << v1 << endl;
    }
    else {
      cout << v0 << endl;
    }
  }
  return 0;
}

int main1()
{

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  
  int v0 = -1;
  int i0 = -1;
  for (int i = 0; i < N; ++i) {
    if (v0 < A[i]) {
      v0 = A[i];
      i0 = i;
    }
  }
  vector<int> B(A);
  B[i0] = 0;
  int v1 = 0;
  for (int i = 0; i < N; ++i) {
    if (v1  < B[i]) {
      v1 = B[i];
    }
  }
    
  for (int i = 0; i < N; ++i) {
    if (A[i] == v0) {
      cout << v1 << endl;
    }
    else {
      cout << v0 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3316
#include <stdio.h>
#include <string.h>

#define N 200
#define M 3
#define INF 200000

int main(void){
	int n,i,j,k;
	int f[N];
	int score[N];
	int list[N][M];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		score[i]=0;
		for(j=0;j<M;j++){
			scanf("%d",&list[i][j]);
		}
	}
	
	for(i=0;i<M;i++){
		for(j=0;j<n;j++) f[j]=1;
		for(j=0;j<n;j++){
			for(k=0;k<n && f[j];k++){
				if(j==k) continue;
				if(list[j][i]==list[k][i]){f[j]=f[k]=0;}
			}
		}
		for(j=0;j<n;j++){
			//printf("bug:%d %d %d %s\n",i,j,k,((f[j])?("true"):("false")));
			if(f[j]){
			score[j]+=list[j][i];
			}
		}
	}
	for(i=0;i<n;i++) printf("%d\n",score[i]);
	return 0;
}

Measured memory_bytes: 600