akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	priority_queue<int>p;
	p.push(a);
	p.push(b);
	p.push(c);
	p.pop();
	int bell1 = p.top(); p.pop();
	int bell2 = p.top(); p.pop();
	cout << bell1 + bell2 << endl;
	return 0;
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, m) cin >> c[i] >> d[i];

  rep(i, n) {
    vector<int> dist(m);
    rep(j, m) dist[j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
    vector<int>::iterator iter = std::min_element(dist.begin(), dist.end());
    size_t index = distance(dist.begin(), iter);
    cout << index + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

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

    while(N--) {
        string str;
        getline(cin, str);
        int cursor = 0;
        int M;
        cin >> M;
        cin.ignore();

        while(M--) {
            string cmdline;
            getline(cin, cmdline);

            int delim = cmdline.find(' ');
            string cmd = cmdline.substr(0, delim);
            string target = cmdline.substr(delim+1);
            if(cmd == "forward") {
                if(target == "word") {
                    while(cursor < str.size() && str[cursor] == ' ') ++cursor;
                    while(cursor < str.size() && str[cursor] != ' ') ++cursor;
                }
                else if(target == "char") {
                    if(cursor < str.size()) ++cursor;
                }
                else {
                    cerr << "Unknown target in forward: " << target << endl;
                }
            }
            else if(cmd == "backward") {
                if(target == "word") {
                    if(cursor > 0) --cursor;
                    while(cursor > 0 && str[cursor] == ' ') --cursor;
                    while(cursor > 0 && str[cursor] != ' ') --cursor;
                    if(str[cursor] == ' ' && str[cursor+1] != ' ') ++cursor;
                }
                else if(target == "char") {
                    if(cursor > 0) --cursor;
                }
                else {
                    cerr << "Unknown target in backward: " << target << endl;
                }
            }
            else if(cmd == "delete") {
                if(target == "word") {
                    int idx = cursor;
                    bool ok = false;
                    while(idx < str.size() && str[idx] == ' ') ++idx;
                    while(idx < str.size() && str[idx] != ' ') {++idx; ok = true; }
                    if(ok) {
                        str.erase(cursor, idx-cursor);
                    }
                }
                else if(target == "char") {
                    if(cursor >= str.size()) continue;
                    str.erase(cursor, 1);
                }
                else {
                    cerr << "Unknown target in delete: " << target << endl;
                }
            }
            else if(cmd == "insert") {
                str = str.substr(0, cursor) + target.substr(1, target.size()-2) + str.substr(cursor);
                cursor += target.size()-2;
            }
            else {
                //cerr << "Unknown command: " << cmd << endl;
            }
            //cout << cmdline << endl;
            //cout << "\t" << str.substr(0, cursor) << '^' << str.substr(cursor) << endl;
        }
        cout << str.substr(0, cursor) << '^' << str.substr(cursor) << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int main(){
	int d;
	cin>>d;
	cout<<"Christmas";
	while(d<25){
		d++;
		cout<<" Eve";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
import math
import sys

MAX_N = 100000
MAX_LOG6 = int(math.log(MAX_N, 6))
MAX_LOG9 = int(math.log(MAX_N, 9))

def main(N):
    dp = [MAX_N] * (N + 1)
    for i in range(min(N + 1, 6)):
        dp[i] = i
    for i in range(N + 1):
        t = 1
        for j in range(1, MAX_LOG6 + 1):
            t *= 6
            if i - t < 0:
                break
            dp[i] = min(dp[i], dp[i - t] + 1)
        t = 1
        for j in range(1, MAX_LOG9 + 1):
            t *= 9
            if i - t < 0:
                break
            dp[i] = min(dp[i], dp[i - t] + 1)
    print(dp[N])

if __name__ == '__main__':
    N = int(sys.stdin.readline())
    main(N)

Measured memory_bytes: 3828
#include<iostream>
#include<bits/stdc++.h>
#define db(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define fr(i,a,n) for(int i=a;i<=(n);++i)
#define rf(i,a,n) for(int i=a;i>=(n);--i)
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define _ <<" "<<
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,pair<int,int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

vector<bool> vis;
vvi dp;

ll matching(vvi &a, int mask, int n){
	if(n==0)
		return 1;
	if(mask==0)
		return 0;
	if(dp[n][mask]!=-1)
		return dp[n][mask];
	ll val=0;
	// db(mask);
	for(int i=0;i<a.size();i++){
		// db2(a[n-1][i],(mask&(1<<i)));
		if(a[n-1][i]&&(mask&(1<<i))){
			// db2(n,mask);
			val+=matching(a,mask^(1<<i),n-1);
			val%=mod;
		}
	}
	dp[n][mask]=val%mod;
	// db(val);
	return dp[n][mask];
}
 
int main(){
  	int n;
  	cin>>n;
  	vvi a(n,vi(n,0));
  	int mask=0;
  	for(int i=0;i<n;i++){
  		mask|=(1<<i);
  		for(int j=0;j<n;++j){
  			cin>>a[i][j];
  		}
  	}
  	dp.clear();
  	dp.resize(n+1,vi(1<<n,-1));
  	cout<<matching(a,mask,n);
  // 	dp.resize(n,vi(n,1e18));

 	// for(int i=0;i<=n;i++){
 	// 	for(int j=0;j<=n;j++){
 	// 		if(i==j){
 	// 			dp[i][j]=i;
 	// 		}
 	// 	}
 	// }
  // 	cout<<dp[0][n-1]<<endl;
  	return 0;
}



Measured memory_bytes: 377216
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
	int flag,n,a[12],b[110],f[12];
	f[0]=1;
	for(int j=0;j<=10;j++){
		f[j+1]=f[j]*3;
	}
	while(~scanf("%d",&n)){
		flag=1;
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		for(int j=1;j<=n;j++){
			if(a[j]%2==0) flag=flag*2;
		}
		printf("%d\n",f[n]-flag);
	}
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

ll pow_mod(ll b, ll n) {
    if (n == 0) return 1;
    if (n == 1) return b;

    if (n % 2 != 0) {
        return (b % MOD * pow_mod(b, n - 1) % MOD) % MOD;
    } else {
        return (pow_mod(b, n / 2) % MOD * pow_mod(b, n / 2) % MOD) % MOD;
    }
}

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

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

    MSG(ans)

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
 #include <iostream>
 #include <vector>
 using namespace std;
 typedef long long ll;
 const int INF = 1 << 30;
 const ll INFll = 1ll << 60;
 
 int main() {
	 string s;
	 cin >> s;

	bool flag = false;
	for (int i = 0; i < s.size()-1; i++)
		flag = flag || (s[i] == s[i+1]);
	
	if(flag){
		cout << "Bad" << endl;
	}else{
		cout << "Good" << endl;
	}

 	return 0;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, s1, s2, s3);
  cout << (char)(s1[0] - 'a' + 'A') << (char)(s2[0] - 'a' + 'A') << (char)(s3[0] - 'a' + 'A');
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,mas[101][101],v[101],cnt=0,st[101];
queue<int> q;

void bfs(int u){
    v[u]++;
    //st[u]=cnt;
    q.push(u);
    while(!q.empty()){
        int n=q.front();
        q.pop();
        for(int i=1;i<N+1;i++){
            if(mas[n][i] && !v[i]){
                v[i]++;
                st[i]=st[n]+1;
                q.push(i);
            }
        }
    }
}

int main(void){
    // Your code here!
    int u,k,vx;
    cin>>N;
    
    for(int i=1;i<N+1;i++){
        cin>>u>>k;
        for(int j=1;j<k+1;j++){
            cin>>vx;
            mas[u][vx]++;
        }
    }
    
    bfs(1);
    for(int i=1;i<N+1;i++){
        if(i>1&& !st[i]) cout<<i<<" "<<"-1"<<endl;       
        else cout<<i<<" "<<st[i]<<endl;  
    } 
}



Measured memory_bytes: 3152
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int f[4][5];
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> num;
	rep(i, 0, n)cin >> a[i];
	sort(all(a));
	auto it = a.begin(), it2 = it;
	while (it != a.end()) {
		it2 = it;
		it = upper_bound(it, a.end(), *it);
		num.push_back(it - it2);
	}
	printf("%d\n", num.size() - (num.size() % 2 == 0));
	return 0;
}


Measured memory_bytes: 1276
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var l = o.a();
  var ans = [];
  for(var i = 1; i < 20; i++)ans[i] = [i,i+1,0];
  i = 1;
  while(l > 1){
    if(l & 1)ans.push([i,20,--l]);
    l >>= 1;
    ans.push([i,++i,l]);
  }
  ans[0] = [20,ans.length-1];
  return ans.map(a=>a.join(" ")).join("\n");
}

Measured memory_bytes: 7748
class RangeUpdateQuery
  def initialize(n, inf = Float::INFINITY)
    @n = n
    @l = 1
    while @l < n
      @l *= 2
    end
    @data = Array.new(2 * @l - 1) { inf }
  end

  def _update(s, t, x, l, r, k)
    if s == l && t == r
      @data[k] = x
    else
      if @data[k] > -1
        @data[2 * k + 1] = @data[2 * k + 2] = @data[k]
        @data[k] = -1
      end
      m = (l + r) / 2
      if t <= m
        _update(s, t, x, l, m, 2 * k + 1)
      elsif m <= s
        _update(s, t, x, m, r, 2 * k + 2)
      else
        _update(s, m, x, l, m, 2 * k + 1)
        _update(m, t, x, m, r, 2 * k + 2)
      end
    end
  end

  def update(s, t, x)
    # add [s, t+1]
    _update(s, t + 1, x, 0, @l, 0)
  end

  def _find(i, l, r, k)
    return @data[k] if @data[k] > -1
    m = (l + r) / 2
    if i < m
      return _find(i, l, m, 2 * k + 1)
    else
      return _find(i, m, r, 2 * k + 2)
    end
  end

  def find(s, t)
    _find(s, t, @l, 0)
  end
end



n, q = gets.split.map(&:to_i)
ruq = RangeUpdateQuery.new(n)
ans = []
q.times do
  com, s, t, x = gets.split.map(&:to_i)
  case com
  when 0
    ruq.update(s, t, x)
  when 1
    ans << ruq.find(s, 0)
  end
end
puts ans.map { |x| x == Float::INFINITY ? 2147483647 : x }


Measured memory_bytes: 10596
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FDR(i,a,n) for(int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline int Scan() {
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
inline void Out(int a) {
    if(a<0) {putchar('-'); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+'0');
}
const int N=1005;
//Code begin....

int main ()
{
    int n;
    scanf("%d",&n);
    int a=n/100, b=n%10;
    puts(a==b?"Yes":"No");
    return 0;
}


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

int main(){
  int n,goukei = 0;
  cin >> n;
  int a[100100];
  
  for(int i = 0;i < n;i++){
    cin >> a[i];
    goukei = goukei + a[i] - 1;
  }
  
 cout << goukei << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i, j, k, p[10][10], x, y, s, ansn = 0, ansm = 0;
  for(i = 0; i < 10; ++i) for(j = 0; j < 10; ++j) p[i][j] = 0;
  int inkx[4][4] = {
   {0, 0, 0, 0},
   {1, 0, 0, -1},
   {1, 1, -1, -1},
   {2, 0, 0, -2}
  }, inky[4][4] = {
    {0, 0, 0, 0},
    {0, 1, -1, 0},
    {1, -1, 1, -1},
    {0, -2, 2, 0}
  };
  while(scanf("%d,%d,%d", &x, &y, &s) != EOF) {
    p[y][x]++;
    for(i = 1; i <= s; ++i) for(j = 0; j < 4; ++j) 
        if(x + inkx[i][j] >= 0 && y + inky[i][j] >= 0 && x + inkx[i][j] < 10 && y + inky[i][j] < 10) p[y + inky[i][j]][x + inkx[i][j]]++;
  }
  for(i = 0; i < 10; ++i) for(j = 0; j < 10; ++j) {
    if(!p[i][j]) ++ansn;
    if(p[i][j] > ansm) ansm = p[i][j];
  }
  printf("%d\n%d\n", ansn, ansm);
  return 0;
}


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

int main(){
	int n, k, m, p;
	while(cin>>n>>k>>m, n||k||m){
		vector<int> stone(n);
		for(int i = 0; i < n; i++)stone[i] = i;
		p = m-1;
		while(n-- > 1){
			stone.erase(stone.begin()+p);
			p += k-1;
			if(p >= n)p = p%n;
		}
		cout<<stone[0]+1<<endl;
	}
	return 0;
}

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

#define llong long long 
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()
// #define rand __rand
// mt19937 rng(chrono::system_clock::now().time_since_epoch().count());  // or mt19937_64
// template<class T = int> T rand(T range = numeric_limits<T>::max()) {
    // return (T)(rng() % range);
// }

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    llong n, a, b; cin >> n >> a >> b;
    llong dis = b - a;
    if (dis % 2 == 0)  {
        cout << dis / 2;
    } else {
        cout << dis / 2 + min(a, n - b + 1); 
    }

    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
tower = [True]*N
H = list(map(int, input().split()))
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1]<H[B-1]:
        tower[A-1]=False
    elif H[B-1]<H[A-1]:
        tower[B-1]=False
    else:
        tower[A-1]=False
        tower[B-1]=False
ans = tower.count(True)
print(ans)

Measured memory_bytes: 20900
n = int(input())
a = [0] + list(map(int, input().split()))

for i in range(n, 0, -1):
    a[i] = sum(a[i::i]) % 2

print(sum(a))
for i in range(1, n + 1):
    if a[i] == 1:
        print(i)

Measured memory_bytes: 6844
/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 998244353
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
ll bit[2*N];
ll b[2*N];
int n;
void upd(int id,ll val){
    b[id]=(b[id]+val)%MOD;
}
ll query(int id){
	return bit[id];
}
ll qr(int l,int r){
	return (query(r)-query(max(0,l-1))+MOD)%MOD;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int k;
cin>>n>>k;
pii arr[k];
for(int i=0;i<k;i++){
	int l,r;
	cin>>l>>r;
	arr[i].first=l;
	arr[i].second=r;
}
sort(arr,arr+k);
bit[1]=1;
b[1]=1;
for(int i=2;i<=n;i++){
    for(int j=0;j<k;j++){
    	if(i-1<arr[j].first)break;
    	else if(i-1<=arr[j].second){
    		ll tmp=qr(1,i-arr[j].first);
    		upd(i,tmp);
            break;
    	}
    	else{
    		ll tmp=qr(i-arr[j].second,i-arr[j].first);
    		upd(i,tmp);
    	}
    }
    bit[i]=(b[i]+bit[i-1])%MOD;
    // cout<<b[i]<<endl;
}
cout<<b[n]<<endl;
return 0;
}

Measured memory_bytes: 6616
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    A = LI()

    # 1. Aの総和から操作の回数が分かる
    k, mod = divmod(sum(A), (n * (n + 1) // 2))
    if mod:
        return 'NO'

    A.append(A[0])
    diff = []
    for a1, a2 in zip(A[:-1], A[1:]):
        diff.append(a2 - a1)

    # 2. 逆に石を配る操作を考える
    # 一回の操作で1つのdkは-(n - 1), それ以外は+1される

    # 3. {di - k}は負かつnの倍数になっている必要がある
    return 'YES' if not any([(d - k) % n or d > k for d in diff]) else 'NO'


print(main())


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

using namespace std;

typedef long long LL;
const int kMaxN = 1e5+7;
int n;
LL A[kMaxN], B[kMaxN];
LL cnt = 0;

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%lld%lld", &A[i], &B[i]);
    }
    for(int i = 1; i <= n; i++) {
        A[i] = ((A[i]) % B[i] + B[i]) % B[i];
        A[i] = B[i] - A[i];
        if(A[i] == B[i])
            A[i] = 0;
    }
    LL S = A[n];
    cnt = S;
    for(int i = n - 1; i >= 1; i--) {
        if(S > A[i]) {
            LL x = (S - A[i]), y = (x / B[i] + (bool)(x % B[i]));
            S = max(S, A[i] + y * B[i]);
        }
    }
    cout<<S<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

struct Combination {
	vector<int64_t> _fact, _rfact, _inv;
	int64_t MOD;

	Combination(size_t sz, int64_t mod) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1), MOD(mod) {
		_fact[0] = _rfact[sz] = _inv[0] = 1;
		for (int i = 1; i <= sz; ++i) {
			_fact[i] = _fact[i - 1] * i % MOD;
		}
		_rfact[sz] = inverse(_fact[sz]);
		for (int i = sz - 1; i >= 0; --i) {
			_rfact[i] = _rfact[i + 1] * (i + 1) % MOD;
		}
		for (int i = 1; i <= sz; ++i) {
			_inv[i] = _rfact[i] * _fact[i - 1] % MOD;
		}
	}

	inline int64_t fact(int k) const { return _fact[k]; }
	inline int64_t rfact(int k) const { return _rfact[k]; }
	inline int64_t inv(int k) const { return _inv[k]; }

	int64_t inverse(int64_t x) const { return pow(x, MOD - 2); }
	int64_t pow(int64_t x, int64_t n) const {
		int64_t ret = 1;
		while (n > 0) {
			if (n & 1) { (ret *= x) %= MOD; }
			(x *= x) %= MOD;
			n >>= 1;
		}
		return ret;
	}

	int64_t P(int n, int r) const {
		if (r < 0 || n < r) { return 0; }
		return fact(n) * rfact(n - r) % MOD;
	}
	int64_t C(int n, int r) const {
		if (r < 0 || n < r) { return 0; }
		return fact(n) * rfact(r) % MOD * rfact(n - r) % MOD;
	}
	int64_t H(int n, int r) const {
		if (n < 0 || r < 0) { return 0; }
		return r == 0 ? 1 : C(n + r - 1, r);
	}
};

int main() {
	constexpr Int MOD = 1e9 + 7;
	Int N;
	cin >> N;
	vector<Int> x(N);
	for (int i = 0; i < N; ++i) { cin >> x[i]; }

	Combination cb(N, MOD);
	Int ans = 0;
	Int p = 0;
	for (int i = 0; i + 1 < N; ++i) {
		(p += cb.inv(i + 1)) %= MOD;
		(ans += (x[i + 1] - x[i]) * p) %= MOD;
	}
	cout << ans * cb.fact(N - 1) % MOD << endl;

	return 0;
}


Measured memory_bytes: 3328
N = int(input())
ABC = list(list(map(int,input().split(' '))) for i in range(N))
DP = list([0,0,0] for i in range(N+1))

for i in range(N):
  for j in range(3):
    DP[i+1][j] = ABC[i][j] + max(DP[i][j-1],DP[i][j-2])
print(max(DP[-1]))

Measured memory_bytes: 47324
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cmath>
#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()
#define fill(n) std::setfill('0')<<std::right<<std::setw(n)
template <typename T>
using vec = std::vector<T>;
using vi = vec<int>;
using vvi = vec<vi>;
using pii = std::pair<int, int>;
using ll = long long;
using ld = long double;
using namespace std;
const int MOD = 1000000007;

template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}

using AdjList = vector<vector<int>>;
using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }
// Recieve edge(=(int,int)) as an adj list.
AdjList getadj(int N, int M){
	// Initialize all lists of the graph as a empty vector.
	vector<int> init;
	vector<vector<int>> graph(N,init);
	rep(i,M){
		int a, b;
		cin >> a >> b;
		graph[a-1].emplace_back(b-1);
		graph[b-1].emplace_back(a-1);
	}
// rep(i,N)
//  putv(graph[i]);
	return graph;
}

ll Manhattan_dist(ll x1, ll y1, ll x2, ll y2){
	return abs(x1-x2) + abs(y1-y2);
}
void out(bool ans){
	if(ans == true) cout << "yes" << endl;
	else cout << "no" << endl;
}
void Out(bool ans){
	if(ans == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}
void OUT(bool ans){
	if(ans == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}
ll gcd(const ll a, const ll b){
	return (b==0) ? a : gcd(b,a%b);
}
// $\min\{s\in\mathbb{N}:p^s|n\}$
ll hmt_p_divide_n(ll p, ll n){
	ll s = 0;
	while(n%p == 0){
		n /= p;
		s++;
	}
	return s;
}

#include<iostream>
using namespace std;
int main(){
	int N;
	cin >> N;
	if(N==0){
		cout << "0" << endl;
		return 0;
	}

////
	string s="";
	while(N != 0){
		if(N%(-2) != 0) s+='1';
		else s+='0';
		if(N<0)
			N = (N-1)/(-2);
		else
			N = N/(-2);
	}
////

// 提出 #4656365
	// int i=1;
	// string s="";
	// while(N!=0){
	// 	if(N%(i*(-2))!=0){
	// 		N-=i;
	// 		s+='1';
	// 	}else s+='0';
	// 	i*=(-2);
	// }
////

	reverse(all(s));
	cout << s <<endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 整数の入力
            int N = Integer.parseInt(in.next());
            long[] L = new long[N + 1];
            L[0] = 2;
            L[1] = 1;
            for (int i = 2; i < N + 1; i++) {
                L[i] = L[i - 2] + L[i - 1];
            }

            // 出力
            out.println(L[N]);

        }

    }
}



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

int main() {
	string s;
  	cin >> s;
  	int ans = s.size(), sum = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'S')
        	sum++;
      	else {
          	if (sum > 0) {
				ans -= 2;
              	sum--;
            }
        }
    }
	cout << ans << endl;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}
	sort.Sort(sort.IntSlice(v))
	var ans = float64(v[0])
	for i := 1; i < n; i++ {
		ans = (ans + float64(v[i])) / 2.0
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
def sieve_of_eratosthenes(n):
    pl = [i for i in range(2, n + 1)] 
    i=0
    p = pl[0]
    while p**2<=n:
        pl = [pl[j] for j in range(len(pl)) if pl[j]%p!=0 or j<=i]
        i+=1
        p=pl[i]
    return pl

pl = sieve_of_eratosthenes(10**6)

X = int(input())

for p in pl:
    if p>=X:
        print(p)
        break

Measured memory_bytes: 133448
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

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

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

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    if((a<c&&c<b)||(b<c&&c<a)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

const int N = 1e5 + 10;
struct node {
    int w, id;
    bool operator < (const node &x) const {
        return w < x.w;
    }
}a[N];

int main() {
    int n;
    cin >> n;
    rep(i, 1, n) scanf("%d", &a[i].w), a[i].id = i;
    sort(a + 1, a + n + 1);
    rep(i, 1, n) printf("%d ", a[i].id); puts("");
    return 0;
}


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

nowT, nowX, nowY = 0, 0, 0

ans = True

for _ in range(N):
    nextT, nextX, nextY = map(int, input().split())
    dist = abs(nextX - nowX) + abs(nextY - nowY)
    time = nextT - nowT
    if dist > time:
        ans = False
    if (dist % 2) != (time % 2):
        ans = False
    nowT, nowX, nowY = nextT, nextX, nextY

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

Measured memory_bytes: 3064
///Bismillahir Rahmanir Rahim
///Hello_World_Its_Rakib_Alam_Bappi
#include<bits/stdc++.h>
using namespace std;
///ascii for  A=65   and   a=97
#define		int 	long long
#define 		pb 	push_back
#define 		mp 	make_pair
#define 		pi 	2*acos(0.0)
#define 		loopi 	for(int i = 0 ; i <t ; i++)
#define 		loopj 	for(int j = 0 ; j < n ; j++)
#define 		backj 	for(int j = n-1 ; j >=0 ; j--)
#define 		vect 	vector<int>
#define 		vec_it 	vector<int>::iterator vi
#define 		mapp 	map<int,int>m
#define 		pairr 	pair<int,int>p
#define 		sett	set<int>s
#define 		set_it 	set<int>::iterator si
#define 		yes 	cout<<"YES"<<endl
#define 		no 	cout<<"NO"<<endl
#define 		xx 	first
#define 		xy 	second
main()
{
    /// freopen ("in.txt" , "r",  stdin) ;
    string st;
    int n,k,t,temp=0,cnt=0,x,y=0,sum=0;
    cin>>k>>n;  int a[n];
    loopj
    {
    	cin>>a[j]; sum=sum+a[j];
    }
     if(sum>k)
	cout<<-1;
     else
	cout<<k-sum;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  map<string, ll> mp;
  string buf;
  ll result = 1, N; cin >> N;
  REP(i, N) {
    cin >> buf;
    auto itr = mp.find(buf);
    if (itr == mp.end()) {
      mp[buf] = 1;
    } else {
      itr->second += 1;
      result = max(result, itr->second);
    }
  }
  // cout << result << endl;
  for (auto kv : mp) {
    if (kv.second == result) {
      cout << kv.first << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 25216
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int a,b,c,x,count;
int main()
{
	while(~scanf("%d%d%d%d",&a,&b,&c,&x))
	{
		count=0;
		for(int i=0;i<=a&&i*500<=x;i++)
		{
			for(int j=0;j<=b&&i*500+j*100<=x;j++)
			{
				if((x-j*100-i*500)/50<=c) count++;
			 } 
		}
		printf("%d\n",count);
	}
}

Measured memory_bytes: 128
use std::collections::{BTreeMap, BTreeSet};
fn main() {
    let mut sc = Scanner::new();
    let x: u64 = sc.read();
    let y: u64 = sc.read();
    let (x, y) = if x > y { (y, x) } else { (x, y) };
    println!("{}", if y - x <= 1 { "Brown" } else { "Alice" });
    // exp();
}

fn exp() {
    let mut map = BTreeMap::new();
    map.insert((0, 0), 0);
    map.insert((0, 1), 0);
    map.insert((1, 1), 0);

    for i in 0..1000 {
        for j in i..1000 {
            grundy(i, j, &mut map);
        }
    }
}

fn grundy(x: usize, y: usize, map: &mut BTreeMap<(usize, usize), usize>) -> usize {
    let (x, y) = if x > y { (y, x) } else { (x, y) };

    if map.contains_key(&(x, y)) {
        return map[&(x, y)];
    }

    let mut grundy_nums = BTreeSet::new();
    for x_to_y in 1..(x / 2 + 1) {
        let next_x = x - x_to_y * 2;
        let next_y = y + x_to_y;
        grundy_nums.insert(grundy(next_x, next_y, map));
    }
    for y_to_x in 1..(y / 2 + 1) {
        let next_x = x + y_to_x;
        let next_y = y - y_to_x * 2;
        grundy_nums.insert(grundy(next_x, next_y, map));
    }

    let mut g = 0;
    loop {
        if !grundy_nums.contains(&g) {
            map.insert((x, y), g);
            if g == 0 {
                println!("{} {}", x, y);
            }
            return g;
        }
        g += 1;
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
n = int(input())
s = input()

w, e = 0, 0
cumsum = []
for i in range(n):
    if s[i] == "W":
        w += 1
        cumsum.append([w, e])
    else:
        e += 1
        cumsum.append([w, e])

ans = 10 ** 6
for i in range(n):
    if s[i] == "W":
        r = cumsum[-1][1] - cumsum[i][1]
        l = cumsum[i][0] - 1
        ans = min(ans, r+l)
    elif s[i] == "E":
        r = cumsum[-1][1] - cumsum[i][1]
        l = cumsum[i][0]
        ans = min(ans, r+l)

print(ans)

Measured memory_bytes: 43596
N = int(input())
p = [[0, 0, 0]]
for _ in range(N):
    p.append(list(map(int, input().split())))

for i in range(N):
    d = p[i+1][0] - p[i][0]
    diff = abs(p[i+1][1]-p[i][1]) + abs(p[i+1][2]-p[i][2])
    if d < diff or d % 2 != diff % 2:
        print('No')
        quit()
print('Yes')

Measured memory_bytes: 27300
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long lli;

int main() {
  int n;
  while(cin >> n && n) {
    int cnt = 0;
    lli sum[4001];
    fill(sum, sum+4001, 0LL);
    for(int i = 0; i < n; ++i) {
      lli id, e, num;
      cin >> id >> e >> num;
      if(sum[id] != -1) {
        sum[id] += e * num;
        if(sum[id] >= 1000000LL) {
          ++cnt;
          sum[id] = -1;
          cout << id << endl;
        }
      }
    }
    if(!cnt) cout << "NA" << endl;
  }
  return 0;
}

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

template<typename T1, typename T2> void cmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T1, typename T2> void cmin(T1 &a, T2 b) { if (a > b) a = b; }

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

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  long ans = 0;
  int mx = INT_MIN;
  for (auto a : A) {
    if (a < mx) ans += mx - a;
    cmax(mx, a);
  }
  cout << ans << "\n";
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

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

    int n;
    while(cin>>n,n)
    {
        vector<int> v(n);
        REP(i,n) cin>>v[i];
        sort(ALL(v));

        int diff=1e9;
        REP(i,v.size()-1){
            diff=min(diff,v[i+1]-v[i]);
        }
        cout<<diff<<endl;
    }
}

Measured memory_bytes: 3120
N = int(input())
x_list = []
u_list = []
for i in range(N):
    x_u = input().split(' ')
    x_list.append(float(x_u[0]))
    u_list.append(x_u[1])

sum = 0
for x, u in zip(x_list, u_list):
    if u == 'BTC':
        sum += 380000 * x
    elif u == 'JPY':
        sum += x

print(sum)


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

int main(){
    int n;  cin>>n;
    int card[n];    for(int i=0;i<n;i++)cin>>card[i];

    sort(card,card+n);

    int a=0;
    int b=0;
    for(int i=0;i<n;i++){
        if(i%2==0)a+=card[i];
        else b+=card[i];
    }

    cout<<abs(a-b)<<endl;

    return 0;
}


Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
       string word = Console.ReadLine();
       string[] alph = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
       
       bool[] judge = new bool[alph.Length];
       for(int a = 0;a < judge.Length;a++){
           judge[a] = false;
       }
       
       for(int x = 0;x < word.Length;x++){
           for(int y = 0;y < alph.Length;y++){
               if(word.Substring(x,1) == alph[y]){
                    judge[y] = true;
               }
           }
       }
       bool jd2 = false;
       for(int b = 0;b < judge.Length;b++){
           if(judge[b] == false){
               Console.WriteLine(alph[b]);
               jd2 = true;
               break;
               
           }
       }
      if(jd2 == false){
          Console.WriteLine("None");
      }
    }
}


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

int main() {
    int A[5];
    for(int i = 0; i < 5 ; i++){
        cin >> A[i];
    }
    if(A[0] == 0) cout << "1";    
    if(A[1] == 0) cout << "2"; 
    if(A[2] == 0) cout << "3"; 
    if(A[3] == 0) cout << "4"; 
    if(A[4] == 0) cout << "5"; 
	return 0;
}

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

using namespace std;
using ll = long long;

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

    string s;
    int q;

    cin >> s >> q;

    int query, f;
    char c;
    string head, tale;
    bool rvs = false;

    for(int i = 0; i < q; ++i) {
        cin >> query;
        if(query == 1) {
            rvs = !rvs;
        } else {
            cin >> f >> c;
            if(!rvs) {
                if(f == 1) {
                    head.push_back(c);
                } else {
                    tale.push_back(c);
                }
            } else {
                if(f == 1) {
                    tale.push_back(c);
                } else {
                    head.push_back(c);
                }
            }
        }
    }

    if(!rvs) {
        reverse(head.begin(), head.end());
        s = head + s + tale;
    } else {
        reverse(s.begin(), s.end());
        reverse(tale.begin(), tale.end());
        s = tale + s + head;
    }

    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 1200
#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define LC(a) (a<<1)
#define RC(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define CLR(arr,val) memset(arr,val,sizeof(arr))
#define FOR(i,start,end) for(int i=start;i<=end;i++)  
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=5e4+5;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}

int main(){
	int n,ans=0;
	cin>>n;
	FOR(i,1,n){
		int x;
		cin>>x;
		ans=gcd(ans,x);
	}
	int res=0;
	while(ans%2==0){
		ans/=2;
		res++;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int A, B;
int n, m, a, b, c, d, ans;
string s;

int main() {
    cin >> A >> B;
    if (B % A == 0) {
        write(A + B);
    }
    else {
        write(B - A);
    }
}

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

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int> a(n+2);

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

	LL sum = 0;
	for (int i = 0; i < n + 1; i++) {
		sum += abs(a[i] - a[i + 1]);
	}

	for (int i = 1; i < n+1; i++) {
		LL tmp = sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]);
		cout << tmp << endl;
	}
}
	

Measured memory_bytes: 1664
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class BinaryIndexTree:
    def __init__(self, n):
        self.size = n
        self._container = [0] * (n + 1)
        self.depth = n.bit_length()

    def sum(self, i):
        if i == 0:
            return 0
        s = 0
        while i > 0:
            s += self._container[i]
            i -= i & (-i)
        return s

    def add(self, i, x):
        if i == 0:
            return
        while i <= self.size:
            self._container[i] += x
            i += i & (-i)

    def lower_bound(self, x):
        s = 0
        idx = 0
        for i in range(self.depth, -1, -1):
            k = idx + (1 << i)
            if k <= self.size and s + self._container[k] < x:
                s += self._container[k]
                idx += 1 << i
        return idx + 1


def main():
    n = int(readline())
    p = list(map(int, readline().split()))
    idx = dict()

    for i, x in enumerate(p):
        idx[x] = i + 1

    bt = BinaryIndexTree(n + 2)
    bt.add(n + 2, 2)
    bt.add(1, 2)
    ans = 0

    for num in range(n, 0, -1):
        i = idx[num]
        s = bt.sum(i + 1)
        l1 = bt.lower_bound(s)
        l2 = bt.lower_bound(s - 1)
        r1 = bt.lower_bound(s + 1)
        r2 = bt.lower_bound(s + 2)

        ans += num * (i + 1 - l1) * (r2 - r1)
        ans += num * (r1 - i - 1) * (l1 - l2)
        bt.add(i + 1, 1)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 101008
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func exists(n, m int, s, c []int) bool {
	if n >= 2 {
		for i := 0; i < m; i++ {
			if s[i] == 1 && c[i] == 0 {
				return false
			}
		}
	}
	return true
}

func solve(n, m int, s, c []int) int {
	if !exists(n, m, s, c) {
		return -1
	}

	digitNum := make(map[int]int)
	for i := 0; i < m; i++ {
		num, ok := digitNum[s[i]]
		if ok && num != c[i] {
			return -1
		}
		digitNum[s[i]] = c[i]
	}

	ans := 0
	for i := 1; i <= n; i++ {
		num := digitNum[i]
		if num == 0 && n >= 2 && i == 1 {
			num = 1
		}
		ans += num * int(math.Pow10(n-i))
	}
	return ans
}

func main() {
	n, _ := strconv.Atoi(input())
	m, _ := strconv.Atoi(input())
	s := make([]int, m)
	c := make([]int, m)
	for i := 0; i < m; i++ {
		s[i], _ = strconv.Atoi(input())
		c[i], _ = strconv.Atoi(input())
	}
	fmt.Println(solve(n, m, s, c))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
signed main() {
	char a, b, c;
	cin >> a >> b >> c;
	if (a == '7' || b == '7' || c == '7')puts("Yes");
	else puts("No");
}


Measured memory_bytes: 3632
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;


int main() {
  string s;
  cin >> s;
  if(s.at(0)==s.at(1)&&s.at(1)==s.at(2)){
    cout << "Yes" << endl;
  }
  else if(s.at(1)==s.at(2)&&s.at(2)==s.at(3)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256