akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

ll hh[] = {-1, -1, -1, 0, 1, 1, 1, 0};
ll ww[] = {-1, 0, 1, 1, 1, 0, -1, -1};

int
main(int argc, char const *argv[])
{
    vector<string> s, ans;
    ll h, w;
    cin >> h >> w;
    for (ll i = 0; i < h; i++)
    {
        string temp;
        cin >> temp;
        s.push_back(temp);
    }
    ans = s;

    for (ll i = 0; i < h; i++)
    {
        for (ll k = 0; k < w; k++)
        {
            if (s[i][k] == '#') continue;
            ll cnt = 0;
            for (ll p = 0; p < 8; p++)
            {
                if (i + hh[p] >= 0 && i + hh[p] < h && k + ww[p] >= 0 && k + ww[p] < w)
                {
                    if (s[i + hh[p]][k + ww[p]] == '#')
                        cnt++;
                }
            }
            ans[i][k] = (char)(cnt + 48);
        }
    }
    

    for (ll i = 0; i < h; i++)
    {
        cout << ans[i] << endl;
    }
}

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

int main(){
    int N, u, v;
    std::cin >> N >> u >> v;
    u--; v--;
    std::vector< std::vector< int > > AB(N);
    for(int i=1; i<N; i++){
        int tmpa, tmpb;
        std::cin >> tmpa >> tmpb;
        tmpa--; tmpb--;
        AB[tmpa].push_back(tmpb);
        AB[tmpb].push_back(tmpa);
    }
    
    std::vector< int > min_dist(N, 1e9);
    std::vector< int > min_route;
    std::deque< int > pos;
    std::deque< int > prepos;
    std::deque< int > dist;
    std::vector< int > route;
    pos.push_back(v);
    prepos.push_back(-1);
    dist.push_back(0);
    
    while(!pos.empty()){
        int c_pos = pos[0];
        int c_prepos = prepos[0];
        int c_dist = dist[0];
        pos.pop_front();
        prepos.pop_front();
        dist.pop_front();
        
        if(min_dist[c_pos] <= c_dist){
            continue;
        }
        
        route.resize(c_dist);
        route.push_back(c_pos);
        
        min_dist[c_pos] = c_dist;
        if(c_pos == u){
            min_route = route;
            break;
        }
        
        for(int i=0; i<AB[c_pos].size(); i++){
            if(AB[c_pos][i] == c_prepos){
                continue;
            }
            pos.push_front(AB[c_pos][i]);
            prepos.push_front(c_pos);
            dist.push_front(c_dist+1);
        }
    }
    
    int center = (min_route.size() % 2 == 0) ? min_route[min_route.size() / 2] : min_route[min_route.size() / 2 + 1];
    int pre_center = (min_route.size() % 2 == 0) ? min_route[min_route.size() / 2 - 1] : min_route[min_route.size() / 2];
    int center_dist = (min_route.size() % 2 == 0) ? min_route.size() / 2 : min_route.size() / 2 + 1;
    
    pos.clear();
    prepos.clear();
    dist.clear();
    pos.push_back(center);
    prepos.push_back(-1);
    dist.push_back(0);
    min_dist.assign(N, 1e9);
    int max_dist = 0;
    
    while(!pos.empty()){
        int c_pos = pos[0];
        int c_prepos = prepos[0];
        int c_dist = dist[0];
        pos.pop_front();
        prepos.pop_front();
        dist.pop_front();
        
        if(c_pos == pre_center){
            continue;
        }
        if(min_dist[c_pos] <= c_dist){
            continue;
        }
        
        min_dist[c_pos] = c_dist;
        if(max_dist < c_dist){
            max_dist = c_dist;
        }
        
        for(int i=0; i<AB[c_pos].size(); i++){
            if(AB[c_pos][i] == c_prepos){
                continue;
            }
            pos.push_back(AB[c_pos][i]);
            prepos.push_back(c_pos);
            dist.push_back(c_dist+1);
        }
    }
    
    std::cout << center_dist + max_dist - 1 << std::endl;
    
    
    return 0;
    
}


Measured memory_bytes: 9732
#include <iostream>
using namespace std;
typedef long long ll;
ll C[26];
ll S[365][26];
int main() {
  ios::sync_with_stdio(false);
  int D;
  cin >> D;
  for (int i=0; i<26; i++) {
    cin >> C[i];
  }
  for (int i=0; i<D; i++) {
    for (int j=0; j<26; j++) {
      cin >> S[i][j];
    }
  }
  for (int i=0; i<D; i++) {
    cout << (i%26  + 1) << '\n';
  }
}

Measured memory_bytes: 3732
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function rng(a,b,c,d)
	if a<b || b>d || a%b > c
		println("No")
	else
		lbd = gcd(b,d)
		init = a%b
		x = init+div(b-init-1, lbd)*lbd
		if x > c
			println("No")
		else
			println("Yes")
		end
	end
end

function main()
	n = readline() |> parseInt
	for i in 1:n
		a,b,c,d = readline() |> split |> parseMap
		rng(a,b,c,d)
	end
end

main()

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

double dist(int x1, int y1, int x2, int y2, int r1, int r2) {
    double di = sqrt(ll(x1 - x2) * (x1 - x2) + ll(y1 - y2) * (y1 - y2));
    di = di - r1 - r2;
    return di > 0 ? di : 0;
}

// dijkstra法
struct edge { int to; double cost; };
vector<vector<edge>> G;//グラフ
vector<double> d;//sからの距離(INFで初期化)

void dijkstra(int s) {
    typedef pair<double, int> P; // (cost,v)
    priority_queue<P, vector<P>, greater<P>> pq;
    d[s] = 0;
    pq.push(P(0, s));
    while (!pq.empty()) {
        P p = pq.top(); pq.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (edge e : G[v])
        {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                pq.push({d[e.to], e.to});
            }
        }
    }
}

struct sircle {
    int x, y, r;
};

int main() {
    int xs, ys, xt, yt; cin >> xs >> ys >> xt >> yt;
    int n; cin >> n;
    vector<sircle> sir(n+2);
    G.resize(n + 2);
    d.resize(n + 2,1e308);
    REP(i, n) {
        int x, y, z; scanf("%d %d %d", &x, &y, &z);
        sir[i] = {x,y,z};
    }
    sir[n] = {xs,ys,0};
    sir[n+1] = {xt,yt,0};
    REP(i, n + 1) {
        FOR(j, i + 1, n + 2) {
            double dis = dist(sir[i].x, sir[i].y, sir[j].x, sir[j].y, sir[i].r, sir[j].r);
            G[i].push_back({j,dis});
            G[j].push_back({i,dis});
        }
    }
    dijkstra(n);
    printf("%.10f\n", d[n + 1]);
    return 0;
}

Measured memory_bytes: 22640
#include <bits/stdc++.h>
using namespace std;
bool f(int a)
{
  int k[5];
  for (int i=0; i<5; i++) {
    k[i] = a % 10;
    a /= 10;
  }
  return k[0]==k[4] && k[1]==k[3];
}
 
int main()
{
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i=a; i<=b; i++) {
    if (f(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

const int maxn = 1e5 + 20;

ll x[maxn] , a[maxn] , b[maxn] , k;

int main()
{
	int n;
	cin >> n >> k;
	ll sum = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
		sum += b[i] * k;
		a[i] = (a[i] * (100 - k)) + b[i] * k;
	}
	sort(a , a + n);
	ll tmp = 0;
	for(int i = n - 1; i >= 0; i--)
	{
		tmp += a[i];
		if(tmp >= sum)
		{
			cout << n - i << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 1792
s = input()

a = set()
a.add('R')
a.add('U')
a.add('D')

b = set()
b.add('L')
b.add('U')
b.add('D')

flag = 1
for i, si in enumerate(s):
    if i % 2 == 0 and si not in a:
        flag = 0

for i, si in enumerate(s):
    if i % 2 == 1 and si not in b:
        flag = 0

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n,*b=map(int,open(0).read().split())
b=[0]+b
ans=[]
for i in range(n):
  for i in range(len(b)-1,0,-1):
    if i==b[i]:
      ans.append(b.pop(i))
      break
  else:
    print(-1)
    exit()
for i in ans[::-1]:
  print(i)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int X = nextInt();
  int Y = nextInt();
  ll ans = 0;
  if (X == 3) ans += 100000;
  if (X == 2) ans += 200000;
  if (X == 1) ans += 300000;
  if (Y == 3) ans += 100000;
  if (Y == 2) ans += 200000;
  if (Y == 1) ans += 300000;
  if (X == 1 && Y == 1) ans += 400000;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
n = int(input())
arr = [int(input()) for i in range(n)]

numset = set(arr)
maxval = max(numset)
count = 0

if len(numset) == 1:
    for i in range(n):
        print(maxval)
else:
    numset.remove(maxval)
    semimax = max(numset)
    for j in range(n):
        if arr[j] == maxval:
            count +=1
    for i in range(n):
        if arr[i] == maxval and count == 1:
            print(semimax)
        else:
            print(maxval)

Measured memory_bytes: 17164
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  rep(i,n) cin >> v[i];
  rep(i,n) cin >> c[i];
  int ans = 0;
  for(int i = 0; i < (1 << n); i++){
    bitset<21> s(i);
    int x = 0;
    int y = 0;
    rep(j,n){
      if(s.test(j)){
        x += v[j];
        y += c[j];
      }
    }
    ans = max(ans,x -y);
  }
  cout << ans << endl;
}
 

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
using namespace std;

typedef pair<double, double> P;

bool inRange(double v, double l, double r){
    return l<=v && v<=l;
}

bool compare_y(P a, P b){
    return a.second < b.second;
}

double getClosestPair(vector<P> &v, int s, int t){
    if(t-s<=1) return INT_MAX;
    const double mid = v[(s+t)/2].first;
    const double d1 = getClosestPair(v, s, (s+t)/2);
    const double d2 = getClosestPair(v, (s+t)/2, t);
    double d = min(d1, d2);
    inplace_merge(v.begin()+s, v.begin()+(s+t)/2, v.begin()+t, compare_y);
    vector<P> use;
    for(int i=s; i<t; i++){
        if(fabs(v[i].first-mid)>d) continue;
        for(int j=use.size()-1; j>=0; j--){
            if(fabs(v[i].second-use[j].second)>d) break;
            double dx = v[i].first-use[j].first;
            double dy = v[i].second-use[j].second;
            d = min(d, sqrt(dx*dx + dy*dy));
        }
        use.push_back(v[i]);
    }
    return d;
}

int main(){
    int n;
    double x, y;
    cin >> n;
    vector<P> v;
    for(int i=0; i<n; i++){
        P p;
        cin >> p.first >> p.second;
        v.push_back(p);
    }
    sort(v.begin(), v.end());
    printf("%f\n",getClosestPair(v, 0, v.size()));
}

Measured memory_bytes: 7560
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

Int a,b,c,d, n;

int main(){
	cin >> a >> b >> c >> d >> n;
	Int cnt = 0;
	if(n >= 2){
		cnt += min(a * 8, min(b * 4, min(c * 2, d))) * (n / 2);
		n %= 2;
	}
	if(n != 0){
		cnt += min(a * 4, min(b * 2, c));
	}
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

int main(void){
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    if(A<0 && B<0 && C>0 && D>0){
        cout << B*C << endl;
        return 0;
    }
    
    if(A>0 && B>0 && C<0 && D<0){
        cout << A*D << endl;
        return 0;
    }
    
    ll X,Y;
    X = B*D;
    Y = A*C;
    cout << max(X,Y) << endl;
    
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int n,a[200005],cnt,ans[200005],dp[200005];
vector<int> v[200005];
map<int,int> mp;
struct segtree{
    int dat[1048580],n;
    void build(int nn)
    {
        n=1;
        while(n<=nn) n<<=1;
        for(int i=0;i<2*n-1;i++) dat[i]=-inf;
    }
    void update(int k,int a){
        k+=n-1;
        dat[k]=a;
        while(k>0){
            k=(k-1)/2;
            dat[k]=max(dat[(k<<1)+1],dat[(k<<1)+2]);
        }
    }
    int query(int l,int r){
        if(l > r) return -inf;
        return query(l,r+1,0,0,n);
    }
    int query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return -inf;
        if(a<=l&&r<=b) return dat[k];
        return max(query(a,b,(k<<1)+1,l,(l+r)>>1),query(a,b,(k<<1)+2,(l+r)>>1,r));
    }
}seg;
void dfs(int x,int fa,int mx){
    dp[x] = max(seg.query(1, a[x] - 1),0) + 1;
    ans[x] = max(mx, dp[x]);
    int old = seg.query(a[x], a[x]);
    seg.update(a[x], dp[x]);
    rap(i,0,v[x].size()){
        int to = v[x][i];
        if(to == fa) continue;
        dfs(to,x,max(mx, dp[x]));
    }
    seg.update(a[x], old);
}
int main()
{
    scanf("%d",&n);
    rep(i,1,n) scanf("%d",a+i), mp[a[i]] = 0;
    rap(i,1,n){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        v[t1].pb(t2);
        v[t2].pb(t1);
    }
    for(mit it = mp.begin(); it != mp.end(); it++) it->se = ++cnt;
    rep(i,1,n) a[i] = mp[a[i]];
    seg.build(n);
    dfs(1,0,-1);
    rep(i,1,n) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 43712
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    //Main
    public static void main(String args[]) throws Exception {

        Scanner Input = new Scanner(System.in);
        long W = Input.nextLong();
        long a = Input.nextLong();
        long b = Input.nextLong();

        if (a == b) {
            System.out.println("0");
        } else if (a > b) {
            if (a <= b + W) {
                System.out.println("0");
            } else {
                System.out.println(a - (b + W));
            }
        } else if (b > a) {
            if (b <= a + W) {
                System.out.println("0");
            } else {
                System.out.println(b - (a + W));
            }

        }

    }
}


Measured memory_bytes: 21716
/*
Author- Aasav Badera
Time- Sun Sep 13 17:18:19 2020
*/
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#ifdef LOCAL  
#include <sys/resource.h>
#define meminc             rlimit rlim;if (getrlimit(RLIMIT_STACK, &rlim)) return 1;rlim.rlim_cur = 268435456;if (setrlimit(RLIMIT_STACK, &rlim)) return 2;
#else
#define meminc      
#endif
#ifdef LOCAL
#define dbg(args...)       { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
#define dbg(args...)
#endif
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
#define ll                 int
#define vi                 vector<int >
#define ordered_set        tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// -------------------Standard Traversal Moves---------------------
// vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1};
// vi fx = {2, -2, 2, -2,  1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2};
// vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1};
// ----------------------------------------------------------------

#define rep(i, a, b)       for(int  i=a;i<b;i++)
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (int )x.size()
#define yes                cout << "YES" << endl
#define no                 cout << "NO" << endl
#define endl               '\n' 
// const int hell = (int)998244353;
const int hell = (int)1e9 + 7;
const long long int inf = 3223372036854775807;
const double PI = 3.14159265;
const int N = (int) 1e6 + 5;
int n, m, k, a[N];


int32_t main()
{
    meminc;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cerr.precision(10);
    cout.precision(25);
    cout << fixed;
    #ifdef LOCAL
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    int tests = 1;
    // cin >> tests;
    rep(test, 1, tests+1)
    {
        cin >> n;
        if(!n)cout << 1;
        else cout << 0;
    }
    #ifdef LOCAL
        // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}

Measured memory_bytes: 3648
// Aizu 1101: A Simple Offline Text Editor
// 2017.9.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char buf[1010], *p;

int main()
{
	int n, m, cmd, par, f;
	char t[200], *cp, *q, *qq;

	fgets(t, 50, stdin), n = atoi(t); while (n-- > 0) {
		fgets(buf, 1000, stdin);
		p = buf + strlen(buf) - 1; if (*p < ' ' && p >= buf) *p = 0; p = buf; // remove '\n'
		fgets(t, 50, stdin), m = atoi(t); while (m-- > 0) {
			fgets(t, 150, stdin); cp = t; while (*cp == ' ') cp++;
			cmd = *cp; while (*cp >= 'a') cp++; while (*cp == ' ') cp++;
			par = *cp;
			if (cmd == 'f') {    // forward
				if (!*p) continue;
				if (par == 'c') p++;
				else { while (*p == ' ') p++; while (*p > ' ') p++; }
			} else if (cmd == 'b') {   // backward
				if (p == buf) continue;
				if (par == 'c') p--;
				else {
					f = 1, p--;
					while (f && *p <= ' ') { if (p == buf) f = 0; else p--;	}
					while (f && *p >  ' ') { if (p == buf) f = 0; else p--; }
					if (f && *p == ' ') p++;
				}
			} else if (cmd == 'd') {  // delete
				if (!*p) continue;
				if (par == 'c') {
					qq = p, q = p+1; while (*p) *p++ = *q++; *p = 0; p = qq;
				} else {
					f = 0, q = p; while (*q == ' ') q++; while (*q > ' ') f = 1, q++;
					if (f) { qq = p; while (*p) *p++ = *q++; *p = 0; p = qq; }
				}
			} else {  // insert
				int w = strlen(cp)-2;
				q = cp + w; if (*q == '"') w--;  // remove '\n'
				if (w > 0) {
					q = buf + strlen(buf);
					while (p <= q) *(q + w) = *q, q--;
				}
				cp++; while (w-- > 0) *p++ = *cp++;
			}
//printf("#"); q = buf; while (q < p) putchar(*q++); putchar('^'); while (*q) putchar(*q++); putchar('\n');
		}
		q = buf; while (q < p) putchar(*q++); putchar('^'); while (*p) putchar(*p++); putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1812
#include <iostream>

using namespace std;

int main(){
	int hit,sum,ct,i;
	while(cin>>ct,ct){
		i=ct/4;
		sum=0;
		for(int j=0;j<i;j++){
			cin>>hit;
			sum+=hit;
		}
		cout<<sum<<endl;
	}
}

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

ll solve(vector<int> &weight, vector<int> &value, int w) {
  int n = value.size();
  vector<ll> dp(w + 1, 0);
  for (int j = 0; j < n; ++j) {
    for (int wt = w; wt - weight[j] >= 0; --wt) {
      dp[wt] = max(dp[wt], value[j] + dp[wt - weight[j]]);
    }
  }
  return dp[w];
}

int main() {
  int n, w;
  cin >> n >> w;
  vector<int> value(n, 0);
  vector<int> weight(n, 0);
  for(int i = 0; i < n; ++i) {
    cin >> weight[i];
    cin >> value[i];
  }
  cout << solve(weight, value, w) << '\n';
  return 0;
}


Measured memory_bytes: 4020
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <cassert>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
int main(){
	int N;
	cin >> N;
	string S[N];
	int P[N];
	int M[N];
	for(int i = 0; i < N; i++){
		cin >> S[i] >> P[i];
		M[i] = i;
	}
	for(int j = 0; j < N; j++){
		for(int l = 0; l < N; l++){
			if(j > l){
				if(S[j] < S[l]){
					string s = S[j];
					S[j] = S[l];
					S[l] = s;
					int m = M[j];
					M[j] = M[l];
					M[l] = m;
					int p = P[j];
					P[j] = P[l];
					P[l] = p;
				}
				else if(S[j] == S[l]){
					if(P[j] > P[l]){
					string s = S[j];
					S[j] = S[l];
					S[l] = s;
					int m = M[j];
					M[j] = M[l];
					M[l] = m;
					int p = P[j];
					P[j] = P[l];
					P[l] = p;
					}
				}
			}
		}
	}
	for(int k = 0; k < N; k++){
		cout << M[k] + 1 << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define MAX 10

void solve(string line, int N){
  int C[N];
  int B = 0;
  for (int i = 0; i < N; i++ ) C[i] = 0;

  for ( int i = 0; i < line.size(); i++ ){
    char f = line[i];
    int p = i%N;
    
    if ( f == 'M' ){
      C[p]++;
    } else if ( f == 'S' ){
      C[p]++;
      B += C[p];
      C[p] = 0;
    } else if ( f == 'L' ){
      C[p]++;
      C[p] += B;
      B = 0;
    }
  }

  sort(C, C+N);

  for ( int i = 0; i < N; i++ ) cout << C[i] << " ";
  cout << B << endl;
}

main(){
  int N;
  string line;

  while(1){
    cin >> N;
    if ( N == 0 ) break;
    cin >> line;
    int S = 0, L = 0, M = 0;
    solve(line, N);
  }
}

Measured memory_bytes: 1232
def f(n):
    for i in range(1,n):
        p=n+1-i
        for j in range(i+1,n+1):
            if j!=p:
                print(i,j)


n=int(input())
if n%2==0:
    print((n-2)*n//2)
    f(n)
else:
    print((n-3)*(n-1)//2+n-1)
    f(n-1)
    for i in range(1,n):
        print(i,n)

Measured memory_bytes: 3612
n,k = (int(x) for x in input().split())

if n == 0 or k == 1 or n == k:
	print(0)
	exit()

if n < k:
	print(n) if n < k - n else print(k-n)
else :
	mod = n % k 
	print(mod) if mod < k - mod else print(k-mod)

Measured memory_bytes: 38256
#include <stdio.h>

int main()
{
 int a, b, c, max, add, n, i;

 scanf("%d", &n);

 for(i=0; i<n; i++){
  scanf("%d%d%d", &a, &b, &c);
  add=a*a + b*b + c*c;
  if(a>b){
   if(a>c){
    add -= a*a;
    max = a*a;
   }else{
    add -= c*c;
    max = c*c;
   }
  }else{
   if(b>c){
    add -= b*b;
    max = b*b;
   }else{
    add -= c*c;
    max = c*c;
   }
  }
  printf("%s\n", (add==max)?"YES":"NO");
 }
 return(0);
}
  

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

int main(){
    int n; cin >> n;
    set<int> s;
    rep(i, n){
        int a; cin >> a;
        s.insert(a);
    }
    cout << ((int)s.size()%2 ? s.size() : s.size()-1) << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

struct edge{int from,to,cost;};



int main(void){
	int l;
	cin>>l;
	if(l==2){
		cout<<"2 2"<<endl;
		cout<<"1 2 1"<<endl;
		cout<<"1 2 0"<<endl;
		return 0;
	}
	l--;
	int memoL = l;
	vector<int> bits;
	int d = 1;
	while(l>0){
		if(l%2==0){
			bits.push_back(0);
		}else{
			bits.push_back(1);
		}
		l /= 2;
		d *= 2;
	}
	d /= 2;
	int memo = d;

	reverse(bits.begin(),bits.end());
	int last0 = INF;
	rep(i,bits.size()){
		if(bits[i] == 0){
			last0 = i;
		}
	}
	vector<edge> ans;
	rep(i,bits.size()){
		edge e1 = {i,i+1,d};
		edge e0 = {i,i+1,0};
		if(i!=0){
			ans.push_back(e1);
			ans.push_back(e0);		
		}
	
		if(i!=0 && bits[i] == 1 && last0 >= i){
			edge es = {1,i+1,memo};
			ans.push_back(es);
			memo += d;
		}
		if(i == last0){
			edge el = {1,i+1,memo};
			ans.push_back(el);
		}
	
		d /= 2;
	}
	if(last0 == INF){
		edge ef = {1,bits.size(),memoL};
		ans.push_back(ef);
	}
	cout<<bits.size()<<" "<<ans.size()<<endl;
	rep(i,ans.size()){
		cout<<ans[i].from<<" "<<ans[i].to<<" "<<ans[i].cost<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int a,b;
	int year[4096];
	int i;
	
	for(i=0;i<3001;i++)
	{
		if((i%4==0 && i%100!=0) || i%400==0)
			year[i]=1;
		else
			year[i]=0;
	}
	int flag=0;
	for(;;)
	{
		cin >> a >> b ;
		if(a==0 && b==0)
			break;
		
		if(flag==1)
			cout << endl;
		flag=1;
		int flag2=0;
		for(i=a;i<=b;i++)
		{
			if(year[i]==1)
			{
				flag2=1;
				cout << i << endl;
			}
		}
		if(flag2!=1)
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
n = int(input())
data = [int(s) for s in input().split()]

#Bi = max(Ai,Ai+1)
#max(A1,A2) <= 0 == A1,A2<= 0
# max(A2,A3) <= 153 == A2,A3<= 153
#max(A3,A4) <= 10 == A3,A4 <= 10
#max(A1) = 0
#max(A2) = 0
#max(A3) = 10

#Ai = min(Bi,Bi-1)
ans = []
ans.append(data[0])
if len(data) >= 2:
  for i in range(1,n-1):
    ans.append(min(data[i],data[i-1]))
ans.append(data[len(data)-1])

print(sum(ans))

"""for i in ans:
  print(i)
"""

  


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
vector<vector<int>> dp ; 
vector<vector<int>>v   ;
int mod = 1e9+7;
int n ;
int solve(int index,int mask)
{
	if(index==n)
	{
		return 1;
	}
	if(dp[index][mask]!=-1)return dp[index][mask];
	int res=0;
	for(int j=0;j<n;j++)
	{
		if(v[index][j]==1 && (mask & (1<<j) ))
		{
			res=(res+(solve(index+1,mask^(1<<j)))%mod)%mod;
		}
	}
	return dp[index][mask]=res ;
}

int main() {
	cin>>n;
	v.resize(n,vector<int>(n));
	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	cin>>v[i][j];
	dp.clear();
	int mask = (1<<n)-1;///mask=n times 1's
	dp.resize(n,vector<int>(mask+1,-1)) ;
	cout<<solve(0,mask);
	
	
	return 0;
}

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

int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}

int main() {
	int n, t = 0, arr[101], i, cnt = 0;
	scanf("%d", &n);

	for (i = 0; i < n; i++)scanf("%d", &arr[i]);
	qsort(arr, n, 4, cmp);

	for (i = 0; i < n; i++) {

		if (arr[i] != t) {
			cnt++;
			t = arr[i];
		}
	}
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll n,s=0;
  cin>>n;
  ll d=n;
  while(d>0)
  {
    s+=(d%10);
    d/=10;
  }
  if(n%s==0)
  {
    Yes
  }
  else
    No
    
}
return 0;
}

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

int main() {
  map<char, int> pages;
  map<char, string> cards;
  cin >> cards['a'] >> cards['b'] >> cards['c'];
  char turn = 'a';
  while (pages[turn] != cards[turn].size()) {
    turn = cards[turn][pages[turn]++];
  }
  cout << static_cast<char>(toupper(turn)) << endl;
}


Measured memory_bytes: 256
using System.Linq;
using System.Text;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

namespace AtCoder
{
    class Program
    {

        const int BiggestMod = 998244353;

        public static void Main()
        {
            var num = long.Parse(Console.ReadLine());
            Console.WriteLine(num + num * num + num * num * num);

        }

    }

}

Measured memory_bytes: 27364
#include<iostream>
#include<cstdio>
using namespace std;
int maxx(int a,int b,int c){
	a=max(a,b);
	return max(a,c);
}
int main(){
	int a,b,c,n;
	scanf("%d%d",&a,&b);
	c=maxx(a+b,a-b,a*b);
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <string.h>
#include <cmath>
#include <deque>
#include <algorithm>
#include <time.h>
#include <math.h>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#define ms(a) memset(a,0,sizeof(a))
#define st(a,n) sort(a,a+n)
#define fr(i,k,n) for(int i=k;i<=n;++i)
#define FR(i,k,n) for(int i=n;i>=k;--i)
#define pb push_back
#define inf 0x3f3f3f
#define vc vector
#define exp 1e-6
#define ci cin
#define co cout
#define ed endl
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int mod =1e9+7;
const int maxn=1e5+10;
const double pi=acos(-1);
int main()
{
    string s;
    ci>>s;
    int pos1=0,pos2=1,ans1=0,ans2=0;
    fr(i,0,s.size()-1)
    {
        if((s[i]-'0')==pos1)
            ans1++;
        if((s[i]-'0')==pos2)
            ans2++;
        pos1^=1,pos2^=1;
    }
    co<<min(ans1,ans2)<<ed;
    return 0;
}



Measured memory_bytes: 512
S=list(input())
T=list(input())
p=-1; i=0; e=0
for i in range(len(S)-len(T)+1):
  for j in range(len(T)):
    if S[j+i]==T[j] or S[j+i]=="?":
      e=e+1
      #print(i,p,e)
    else:
      e=0
      break
    if e==len(T):
      p=i
      e=0
    #print(i,p,e)
if p==-1:
  print("UNRESTORABLE")
else:
  S[p:p+len(T)]=T
  for i in range(len(S)):
    if S[i]=="?":
      S[i]="a"
  print("".join(S))

Measured memory_bytes: 3064
# operator.add(a, b)
# operator.mul(a, b)

"""
https://komiyam.hatenadiary.org/entry/20131202/1385992406
大雑把に言って、平衡二分探索木からinsert,delete,split,mergeなどができないよう制限したのがsegment treeで、
segment treeの区間[L,R)に対するクエリをL=0に制限したのがbinary indexed treeだと見なすことができます。
"""


class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)
    

# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
def AOJ_DSL_2_A():
    n, q = map(int, input().split())
    e = (1 << 31) - 1
    A = [e] * n
    seg = SegmentTree(A, min, e)

    for i in range(q):
        t, x, y = map(int, input().split())
        if t == 0:
            seg.update(x, y)
        else:
            print(seg.get(x, y + 1))


# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B
def AOJ_DSL_2_B():
    from operator import add
    import sys
    n, q = map(int, input().split())
    e = 0
    A = [e] * n
    seg = SegmentTree(A, add, e)
    
    query = sys.stdin.readlines()
    for i in range(q):
        t, x, y = map(int, query[i].split())
        x -= 1
        if t == 0:
            A[x] += y
            seg.update(x, A[x])
        else:
            y -= 1
            print(seg.get(x, y + 1))


def ABC125_C():
    from fractions import gcd
    N = int(input())
    A = list(map(int, input().split()))
    
    seg = SegmentTree(A, gcd, 0)
    ans = 0
    for i in range(N):
        ans = max(ans, gcd(seg.get(0, i), seg.get(i + 1, N)))
    print(ans)


AOJ_DSL_2_A()
# AOJ_DSL_2_B()
# ABC125_C()



Measured memory_bytes: 9496
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3];
	int A,B;
	cin>>A>>B;
	a[0]=A+B;
	a[1]=A-B;
	a[2]=A*B;
	sort(a,a+3);
	cout<<a[2]<<endl;
	return 0;
}

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

inline ll gcd(const ll &a, const ll &b) { return b==0 ? a : gcd(b, a%b); }
inline ll lcm(const ll &a, const ll &b) { return a / gcd(a, b) * b; }

int main() {
	
	long long a, b;
	
	while(cin >> a >> b) {
		cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
		if(cin.eof()) break;
	}
	
	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(void){
    int N, tmp;
    std::cin >> N;
    std::vector<int> lst;

    for(int i=0; i<N; ++i){
       std::cin >> tmp;
       lst.push_back(tmp);
    }
    std::sort(lst.begin(),lst.end());
    int ret = lst[N/2] - lst[N/2-1];
    if(ret < 0)
        ret = 0;
    std::cout << ret << std::endl;
    return 0;
        
}
 

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int D, G; cin >> D >> G;
	vector<int> P(D, 0), C(D, 0);
	rep (i, D){
		cin >> P[i] >> C[i];
	} // end rep

	int res = accumulate(ALL(P), 0);

	for (int i = 0; i < (1<<D); ++i){
		int sum = 0;
		int currN = 0;
		// 全完した問題群
		for (int j = 0;j < D; ++j){
			if (i & (1<<j)){
				sum += 100 * (j + 1) * P[j] + C[j];
				currN += P[j];
			} // end if
		} // end if

		if (sum >= G){
			if (currN < res){
				res = currN;
			} // end if
		}else{
			int solved = 0;
			for (int j = D - 1; j >= 0; --j){
				if (!(i & (1<<j))){
					for (int p = 0; p < P[j]; ++p){
						sum += 100 * (j + 1);
						++solved;
						if (sum >= G){
							if (currN + solved < res){
								res = currN + solved;
								break;
							} // end if
						} // end if
					} // end for
				} // end if
				if (solved != 0) break;
			} // end for
		} // end if
	} // end for

	cout << res << endl;
	
	return 0;
}

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

int main() {
  int a[3], k;
  cin>>a[0]>>a[1]>>a[2]>>k;
  sort(a, a + 3);
  int ans = a[0] + a[1];
  for (int i=0; i<k; i++) {
    a[2] *= 2;
  }
  ans += a[2];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    long sum;
    int i, n, num, min, max;
    scanf("%d\n%d", &n, &num);
    min = num;
    max = num;
    sum = num;
    for (i = 1; i < n; i ++) {
        scanf("%d", &num);
        sum += num;
        if (num > max) max = num;
        if (num < min) min = num;
    }    
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}

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

t = 0
if N >= 10:
    t += 9
    if N >= 1000:
        t += 900
        if N >= 100000:
            t += 90000
        else:
            t += max(N - 9999, 0)
    else:
        t += max(N - 99, 0)
else:
    t += N

print(t)

Measured memory_bytes: 2940
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S_arr = _in[0]  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    N = len(S_arr)-1
    cnt = 0
    for bit in range(1<<N):
        # bit = 0: '', 1: '+'
        tmp = []
        pointa = 0
        for i in range(N):
            if bit&(1<<i):
                tmp.append(int(S_arr[pointa:i+1]))
                pointa = i+1
        else:
            tmp.append(int(S_arr[pointa:]))
        cnt += sum(tmp)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 41260
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005,mod=998244353;
int n,ans=1,RG,GB,RB,R,G,B;
char s[N*3];
int main(){
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n*3;i++){
		if(s[i]=='R'){
			if(GB){
				ans=1LL*ans*GB%mod;
				GB--;
			}else if(G){
				ans=1LL*ans*G%mod;
				G--;
				RG++;
			}else if(B){
				ans=1LL*ans*B%mod;
				B--;
				RB++;
			}else{
				R++;
			}
		}else if(s[i]=='G'){
			if(RB){
				ans=1LL*ans*RB%mod;
				RB--;
			}else if(R){
				ans=1LL*ans*R%mod;
				R--;
				RG++;
			}else if(B){
				ans=1LL*ans*B%mod;
				B--;
				GB++;
			}else{
				G++;
			}
		}else{
			if(RG){
				ans=1LL*ans*RG%mod;
				RG--;
			}else if(R){
				ans=1LL*ans*R%mod;
				R--;
				RB++;
			}else if(G){
				ans=1LL*ans*G%mod;
				G--;
				GB++;
			}else{
				B++;
			}
		}
	}
	while(n){
		ans=1LL*ans*n%mod;
		n--;
	}
	printf("%d\n",ans);
	return 0;
}

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

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

using namespace std;

const int INF=1<<29;

int solve(string s,string t){
	int n=s.length();

	vector cost(n+1,vector(n+1,0));
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {
		cost[i][j]=cost[i-1][j-1]+(s[i-1]==t[j-1]?1:0);
	}

	vector dp(n+1,vector(n+1,INF));
	dp[n][n]=0;
	for(int i=n;i>=0;i--) for(int j=n;j>=0;j--) {
		if(i>0) dp[i-1][j]=min(dp[i-1][j],dp[i][j]+cost[i][j]);
		if(j>0) dp[i][j-1]=min(dp[i][j-1],dp[i][j]+cost[i][j]);
	}
	return dp[0][0];
}

int main(){
	int h,w; cin>>h>>w;
	vector<string> B(h);
	rep(i,h) cin>>B[i];

	int ans=0;
	rep(j,w-1){
		string s,t;
		rep(i,h){
			s+=B[i][j];
			t+=B[i][j+1];
		}
		ans+=solve(s,t);
	}
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 4192
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void yes(bool c) { if (c)print("Yes"); else print("No"); };
void YES(bool c) { if (c)print("YES"); else print("NO"); };
 
void solve() {
    ll N; cin >> N;
    string ans;
    ll m = N%10;
    if(m==3) ans = "bon";
    else if(m==0 || m== 1 || m==6 || m==8) ans = "pon";
    else ans = "hon";
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3604
int main(){
  
  int a,b,c;
  
  scanf("%d %d %d",&a,&b,&c);
  
  if(a==b&&b==c){
    printf("No");
  }else if(a!=b&&a!=c&&b!=c){
    printf("No");
  }else{
    printf("Yes");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
	int n, sum = 0, cnt;

	cin >> n;

	for (int i = 7; i <= n; i += 2){
		cnt = 0;
		for (int j = 1; j <= i; j++){
			if (i % j == 0)
				cnt++;
		}
		if (cnt == 8)
			sum++;
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
# N = 100000
A = list(map(int, input().split()))
# A = [1000000000] * N
A.sort()
sum_val = [0] * N
sum_val[0] = A[0]
for i in range(1, N):
    sum_val[i] = sum_val[i - 1] + A[i]

ans = 1
for i in range(N - 2, -1, -1):
    if 2 * sum_val[i] >= A[i + 1]:
        ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 20576
def main08():
    data = input().split()
    nl = []
    for i in range(2):
        nl.append(int(data[i]))
    hantei = nl[0] + nl[1]
    result = 0
    if hantei <= nl[0] and 1 <= hantei:
        for i in range(nl[0]):
            result = result + nl[1] + i
    elif nl[1] > 0:
        for i in range(nl[0]-1):
            result = result + nl[1] + i + 1
    else:
        for i in range(nl[0]-1):
            result = result + nl[1] + i
    print(result)

if __name__ == "__main__":
    main08()

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
int main(void)
{
   char a[102];
   char b[102];

   cin >> a >> b;

   if (strlen(a) > strlen(b)) {
       cout << "GREATER" << endl;
       return 0;
   }
   if (strlen(a) < strlen(b)) {
       cout << "LESS" << endl;
       return 0;
   }

   for (int i = 0; i < strlen(a); i++) {
       if (a[i] == b[i]) {
           continue;
       }
       if (a[i] > b[i]) {
           cout << "GREATER" << endl;
           return 0;
       }
       else {
           cout << "LESS" << endl;
           return 0;
       }
   }
   cout << "EQUAL" << endl;

   return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }

// a >= b であること
ll gcd(ll a, ll b) {
  ll next = a % b;
  if(next == 0) return b;
  return gcd(b, next);  
}

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

int main() {
  int N;
  cin >> N;
  vector<ll> T(N);
  for(int i=0; i<N; ++i) cin >> T[i];
  
  ll ans = T[0];
  for(int i=1; i<N; ++i) {
    ans = lcm(ans, T[i]);
  }
  
  cout << ans << endl;
  
  return 0;
}



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

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+5; 

const double PI =  3.141592653589793;

int main(){
	IO;
	ll n,x,d=0,l,cnt=1;
	bool finish=false;
	cin>>n>>x;
	forn(i,n){
		cin>>l;
		d += l;
		if(d>x)finish=true;
		if(!finish)cnt++;
	}
	cout<<cnt<<"\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


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



int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
template<class V, int ME> class BIT {
public:
    V bit[1 << ME];
    V operator()(int e) { V s = 0; e++; while (e) s = add(s, bit[e - 1]), e -= e&-e; return s; }
    void update(int e, V v) { e++; while (e <= 1 << ME) bit[e - 1] = add(bit[e - 1], v), e += e&-e; }
};
int N;
int dp[1010101];
BIT<int, 20> sm;
//-----------------------------------------------------------------------------------
int main() {
    cin >> N;

    dp[1] = N;
    sm.update(1, dp[1]);
    dp[2] = add(dp[1], mul(N - 1, N - 1), N - 1);
    sm.update(2, dp[2]);
    rep(i, 3, N + 1) {
        // Naive
        //dp[i] = add(dp[i - 1], mul(N - 1, N - 1), N - i + 2);
        //rep(j, 1, i - 2) dp[i] = add(dp[i], dp[j]);

        // Optimized
        dp[i] = add(dp[i - 1], mul(N - 1, N - 1), sm(i - 3), N - i + 2);
        sm.update(i, dp[i]);
    }

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

Measured memory_bytes: 8192
A, B, K = map(int, input().split())

for i in range(K//2):
    if A % 2 == 1:
        A -= 1
    tmp = A // 2
    A -= tmp
    B += tmp
    if B % 2 == 1:
        B -= 1
    tmp = B // 2
    A += tmp
    B -= tmp

if K % 2 == 1:
    if A % 2 == 1:
        A -= 1
    tmp = A // 2
    A -= tmp
    B += tmp

print(A, B)
    

Measured memory_bytes: 3060