akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
int main() {
    ll N;
    cin>>N;
    vi d(N,-1);
    vector<vp> e(N,vp());
    REP(i,N-1){
        ll a,b,c;
        cin>>a>>b>>c;
        e[a-1].push_back(make_pair(b-1,c));
        e[b-1].push_back(make_pair(a-1,c));
    }
    ll Q,K;
    cin>>Q>>K;
    queue<ll> que;
    que.push(K-1);
    d[K-1]=0;
    while(!que.empty()){
        ll prev=que.front();
        que.pop();
        for (P& p: e[prev]){
            if(d[p.first]<0){
                d[p.first]=d[prev]+p.second;
                que.push(p.first);
            }
        }
    }
    REP(i,Q){
        ll x,y;
        cin>>x>>y;
        cout<<d[x-1]+d[y-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 9984
N,M = map(int,input().split())

Ss = [list(map(int,input().split()))[1:] for _ in range(M)]
Ps = list(map(int,input().split()))

ans = 0
switch_pattern_num = 2**N

for i in range(switch_pattern_num):
    binary = format(i,'0%ib'%N)
    satisfied = True
    for j,S in enumerate(Ss):
        count = 0
        for e in S:
            if int(binary[e-1]):
                count += 1
        if count % 2 != Ps[j]:
            satisfied = False
    if satisfied:
        ans += 1
print(ans)


Measured memory_bytes: 3064
import heapq

n=int(input())

p=list(map(int,input().split()))

  # heapqライブラリのimport

a = []
heapq.heapify(a)  

#print(heapq.heappop(a))  # 最小値の取り出し
#print(a)

#heapq.heappush(a, -2)

cnt=0
for item in p:
    heapq.heappush(a,item)
    temp=heapq.heappop(a)
    if temp>=item:
        cnt+=1
    heapq.heappush(a,temp)
    #print(a)
print(cnt)




Measured memory_bytes: 93776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll a, b, h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
s, c = [], []
flag = false
hash = {}

M.times do |i|
  s[i], c[i] = gets.split.map(&:to_i)
  if hash[s[i]].nil?
    hash[s[i]] = c[i]
  # 同じ桁数に異なる2つの数が要求された場合，-1出力
  elsif hash[s[i]] != c[i]
    flag = true
  end
end

# puts "#{hash}"

# 左から1桁目が0かつ桁数が2以上の時，-1出力
if hash[1] == 0 and N >= 2
  flag = true
end

if flag
  puts -1
  exit
end

# ansは最初は先頭に'1'と，その後にN-1個の'0'で埋めておく
ans = []
ans = ans.fill('0',0..N-1)
if N >= 2
  ans[0] = '1'
end

hash.each do |key, val|
    ans[key-1] = val.to_s
end 

puts "#{ans.inject(:+)}"

Measured memory_bytes: 14248
<?php  
    while ($line = fgets(STDIN)) {
     $tmp[] = trim($line);
    }
	$array = explode(" ", $tmp[0]);
	$N = $array[0];
	$K = $array[1];
	$h = array();
	for ($i = 1; $i <= $N; $i++) {
        array_push($h,$tmp[$i]);
    }
	sort($h);
	$i = 0;
	$min = PHP_INT_MAX;
	while($i + ($K-1) < count($h)) {
      $first = $h[$i];
      $end = $h[$i+($K-1)];
      $diff = $end - $first;
      if ($diff < $min) {
        $min = $diff;
      }
      $i++;
    }
	echo($min);
?>

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

int main(){
    int K;
    string S;

    cin >> K >> S;
    if(S.length()<=K){
        cout << S << endl;
    }else{
        REP(int,i,0,K) cout << S[i];
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
struct edge {int to,w,p;};
int n,m,used[100],a,b,c,cnt;
vector<edge> v[100];
int dfs(int s,int t,int r){
    if(s==t)return r;
    used[s]=1;
    for(int i=0;i<v[s].size();i++){
        edge &u=v[s][i];
        if(used[u.to]==0&&u.w>0){
            int F=dfs(u.to,t,min(r,u.w));
            if(F>0){
                u.w-=F;v[u.to][u.p].w+=F;return F;
            }
        }
    }
    return 0;
}
int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        edge p={b,c,(int)v[b].size()};v[a].push_back(p);
        edge q={a,0,(int)v[a].size()-1};v[b].push_back(q);
        cnt++;
    }
    int res=0;
    while(1){
        for(int i=0;i<100;i++)used[i]=0;
        int P=dfs(0,n-1,1e9);
        if(P==0)break;
        res+=P;
    }
    cout<<res<<endl;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int a, b;
    cin >> a >> b;
    int c = b-a;
    c = c*(c+1)/2;
    cout << c-b << endl;
}


Measured memory_bytes: 256
cT = [] * 5 
kiriage = [] * 5 
shimo1 = [] * 5 
import math
for i in range(5):
    cT.append(int(input()))
for i in range(5):
    kiriage.append(math.floor((cT[i] + 10 - 1)/10) * 10)
for i in range(5):
    shimo1.append(cT[i] % 10)
timeCount = 0
minshimo1 = 10
for i in range(5):
    if shimo1[i] == 0:
        timeCount += cT[i]
    else:
        timeCount += kiriage[i]
        if shimo1[i] < minshimo1:
            minshimo1 = shimo1[i]
if minshimo1 != 10:
    timeCount -= (10 - minshimo1)
print(timeCount)


Measured memory_bytes: 3064
n = int(input())
d = {
    i: {j: 0 for j in range(10)} for i in range(1, 10)
}
res = 0
for i in range(n+1):
    str_i = str(i)
    t_i = int(str_i[0])
    b_i = int(str_i[-1])
    if b_i == 0:
        continue
    res += d[b_i][t_i] * 2
    d[t_i][b_i] += 1
    res += 1 if t_i == b_i else 0
print(res)


Measured memory_bytes: 40940
n, k = gets.split.map(&:to_i)
r, s, p = gets.split.map(&:to_i)
t = gets.chomp.chars

groups = t.each_with_index.group_by{|it, i| i % k}.values.map{|it| it.map{|a, i| a}}

point_of_win = {
    'r' => p,
    's' => r,
    'p' => s,
}
score = 0
groups.each{|g|
    skip = false
    (0..(g.size() - 1)).each{|i|
        if i == 0 || skip || g[i] != g[i - 1]
            skip = false
            score += point_of_win[g[i]]
        else
            skip = true
        end
    }
}

puts score


Measured memory_bytes: 38760
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;


// 1-indexed

bool cmp(const pii& a, const pii&b){
    if(a.first == b.first){
        return a.second < b.second;
    }

    return a.first < b.first;
}
int a, b, c, d, e,f;
bool used[500010];

int main() {
    //cout << fixed << setprecision(15);

    int n; cin >> n;
    vi v(100010);

    REP(i, n){
        int a, b; cin >> a >> b;
        v[a]++;
        v[b+1]--;
    }

    for(int i=0; i<100010; ++i){
        if(i>0) v[i] += v[i-1];
    }

    int ans = 0;
    for(int i=1; i<100010; ++i){
        if(v[i]>=i-1){
            ans = max(ans ,i);
        }
    }
    cout << ans-1 << endl;
    
    return 0;
}


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

int main(void) {
    int N;
    int level = 0;
    int fragment = 0;
    string s;
    string prefix = "";
    string suffix = "";

    cin >> N >> s;
    for(int i=0;i<N;i++) {
        if(s[i] == ')'){
            if(level == 0) {
                fragment++;
            } else {
                level--;
            }
        } else {
            level++;
        }
    }

    for(int i=0;i<fragment;i++) {
        prefix += '(';
    }
    for(int i=0;i<level;i++) {
        suffix += ')';
    }

    cout << prefix << s << suffix << "\n";

    return 0;
}


Measured memory_bytes: 256
X, Y, A, B, C = gets.split.map(&:to_i)
R = gets.split.map(&:to_i).max(X)
G = gets.split.map(&:to_i).max(Y)
P = gets.split.map(&:to_i).sort.reverse
RG = (R + G).sort

ans = 0
(X + Y).times.inject(0) do |j, i|
  if j < P.size && P[j] > RG[i]
    ans += P[j]
    j + 1
  else
    ans += RG[i]
    j
  end
end
puts ans


Measured memory_bytes: 28360
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int a[100005];
pii p[100005];
int main(){
    int n, m, b, c;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    sort(a+1, a+1+n);
    for(int i=1;i<=m;i++){
        scanf("%d%d", &b, &c);
        p[i] = pii(c, b);
    }   
    sort(p+1, p+1+m);
    reverse(p+1, p+1+m);
    b = 1;
    for(int i=1;i<=m;i++){
        int mx = p[i].first, j = p[i].second;
        for(int k=b;k<=min(b+j-1, n);k++) a[k] = max(a[k], mx);
        b += j;
        b = min(b, n+1);
    }
    LL ans = 0;
    for(int i=1;i<=n;i++) ans += a[i];
    printf("%lld\n", ans);
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int h = Integer.valueOf(se[0]);
			int w = Integer.valueOf(se[1]);
			if (h == 0 && w == 0)
				break;
			doMain(inCnt, h, w);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int h, int w) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++)
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
					System.out.print("#");
				else
					System.out.print(".");
			System.out.println("");
		}
		System.out.println("");
	}
}

Measured memory_bytes: 31124
#include <bits/stdc++.h>
using namespace std;
int h,w;
int dr[] = {0,1}, dc[] = {1,0};
string board[10];
bool ok(int r, int c)
{
	if(0 <= r && r < h && 0 <= c && c < w)
		return true;
	return false;
}
int main()
{
	cin>>h>>w;
	for (int i = 0; i < h; ++i)
	{
		cin>>board[i];
	}
	int pr = 0, pc = 0;
	bool flag = true;
	while(flag)
	{
		flag = false;
		board[pr][pc] = '.';
		for (int i = 0; i < 2; ++i)
		{
			int nr = pr + dr[i], nc = pc + dc[i];
			if(ok(nr,nc) && board[nr][nc] == '#')
			{
				pr = nr;
				pc = nc;
				flag = true;
				break;
			}
		}
	}
	if(pr == h-1 && pc == w-1)
	{
		bool ans = true;
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				ans = (ans && (board[i][j] == '.'));
			}
		}
		if(ans)
			cout<<"Possible\n";
		else
			cout<<"Impossible\n";
	}
	else
		cout<<"Impossible\n";
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
    int input_second;
    int output_hour;
    int output_minute;
    int output_second;

    scanf("%d", &input_second);

    output_hour = input_second / 3600;
    output_second = input_second - 3600 * output_hour;

    output_minute = output_second / 60;
    output_second = output_second - 60 * output_minute;

    printf("%d:%d:%d\n", output_hour, output_minute, output_second);
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll a, b, x; cin >> a >> b >> x;

    ll u = b / x;

    if (a % x == 0) {
        cout << u - a / x + 1 << endl;
    } else {
        cout << u - a / x << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int X, N;
  cin>>X>>N;
  map<int, int> amap;
  int p;
  for(int i=0;i<N;++i) {
    cin>>p;
    amap[p]++;
  }
  int ans = 1000;
  for(int i=-300;i<=300;++i) {
    if(amap[i]>0) continue;
    if(abs(ans-X)>abs(i-X)) ans = i;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
vector<vector<int> >mark[8];
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a[n];
    for(int i=0;i<m;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int t;
            cin>>t;
            a[t-1].push_back(i);
        }
    }
    vector<int>bulb;
    for(int i=0;i<m;i++){
        int t;
        cin>>t;
        bulb.push_back(t);
    }
    int ans=0;
    for(int i=0;i<(1<<n);i++){
        int c=i;
        int mm[m];
        for(int j=0;j<m;j++){
            mm[j]=0;
        }
        int yy=0;
        while(c>0){
            if(c%2){
                for(int j=0;j<a[yy].size();j++){
                    mm[a[yy][j]]++;
                }
            }
            yy++;
            c=c/2;
        }
        int ch=1;
        for(int i=0;i<m;i++){
            if(mm[i]%2!=bulb[i]){
                ch=0;
            }
        }
        if(ch){
            ans++;
        }

    }
    cout<<ans;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
for i in range(len(A)):
    val=A[i]
    j=i-1
    while (j>=0 and A[j]>val):
        A[j+1]=A[j]
        j=j-1
    A[j+1]=val

    string=[str(a) for a in A]
    out=' '.join(string)
    print(out)




Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define db double
#define inf 0x3f3f3f3f
using namespace std;

const int maxn=2e5+10;
ll a[maxn];
bool cmp(ll x,ll y){
	return x>y; 
}
 
int main(){
	int n;
	cin>>n;
	ll ans=0;
	for(int i=0;i<n;i++) {
		cin>>a[i];
	} 
	sort(a,a+n,cmp);
	ans=a[0];
	int cnt=1;
	for(int i=1;i<n;i++) {
		if(cnt==n-1)break;
		ans+=a[i];
		cnt++;
		if(cnt<n-1) {
			ans+=a[i];cnt++;
		}
		else {
			break;
		}
	}
	cout<<ans<<endl;
} 

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int n;
vector<vector<pair<int,int> > > p(15);
bool judge(int bit){
    for(int i=0;i<n;i++){ //n人について調べる
        if( !(bit & (1<<i)))continue;
        for(auto z:p[i]){
            int X = z.first;
            int Y = z.second; //Yが1ならXは本当

            if(Y==1) if(!(bit & (1<<X))) return false;
            if(Y==0) if(bit & (1<<X)) return false;
        }
    }
    return true;
}
signed main()
{   
    gearup;
    cin >> n;
    rep(i,n){
        int a; cin >> a;
        rep(j,a){
            int x,y; cin >> x >> y;x--;
            p[i].push_back(make_pair(x,y));
        }
    }
    ll res = 0;
    //ビット全探索 正直者を1とする
    for(int bit=0;bit<(1<<n);bit++){

        if(judge(bit)){
            ll cnt = 0;
            rep(j,n) if(bit & (1<<j)) cnt++;
            res = max(res,cnt);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
long long p,x,y,ans;
int main ()
{
	scanf("%lld%lld",&x,&y);
	p=y/x;
	while(p)
	{
		p/=2;
		ans++;
	}
	printf("%lld\n",ans);
	return 0;
}

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

signed main() {
  int n;
  cin >> n;
  map<int, int> cnt;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  for (auto&& w : cnt) {
    if (w.second >= 2) v.push_back(w.first);
    if (w.second >= 4) v.push_back(w.first);
  }
  sort(begin(v), end(v), greater<int>());
  int ans;
  if (v.size() < 2)
    ans = 0;
  else
    ans = v[0] * v[1];
  cout << ans << endl;
}


Measured memory_bytes: 6528
# -*- coding:utf-8 -*-
N = int(input())
S = input()
x = 0
maximum = 0

for factor in range (0, len(S)):
    if S[factor] == 'I':
        x += 1
    elif S[factor] == 'D':
        x -= 1
    
    if maximum < x:
        maximum = x

print(maximum)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
signed main(){
    int n;
    cin>>n;
    int t[100];
    int a=0;
    for(int i=0;i<n;i++){
        cin>>t[i];
        a+=t[i];
    }
    int m;
    cin>>m;
    int p[100],x[100];
    for(int i=0;i<m;i++){
        cin>>p[i]>>x[i];
        cout<<a-(t[p[i]-1]-x[i])<<endl;
    }
    return 0;
}





Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
const int maxn=50005,mod=998244353;
int mo(const int x){
	return x>=mod?x-mod:x;
}
int power(int a,int x){
	int re=1;
	while(x){
		if(x&1)re=1ll*re*a%mod;
		a=1ll*a*a%mod,x>>=1;
	}
	return re;
}
int rev[maxn*4],N;
void NTT(int*F,int rv){
	for(int i=0;i<N;++i)if(rev[i]<i)
		F[rev[i]]^=F[i]^=F[rev[i]]^=F[i];
	for(int mid=1;mid<N;mid<<=1){
		int len=mid<<1,gn=power(3,(mod-1)/len);
		for(int i=0;i<N;i+=len){
			for(int j=0,g=1;j<mid;++j,g=1ll*g*gn%mod){
				int l=i+j,r=l+mid;
				int L=F[l],R=1ll*F[r]*g%mod;
				F[l]=mo(L+R),F[r]=mo(mod-R+L);
			}
		}
	}
	if(!rv)return;reverse(F+1,F+N);int tmp=power(N,mod-2);
	for(int i=0;i<N;++i)F[i]=1ll*tmp*F[i]%mod;
}
int F[maxn*4],G[maxn*4],S[maxn*2],L[maxn*2],R[maxn*2];
void solve(int l,int r){
	if(l==r)return;int mid=(l+r)>>1,o=mid+1;
	solve(l,mid);solve(o,r);
	int mx=R[l]-L[l]+R[o]-L[o]-1,cn=-1;N=1;
	while(N<mx)N<<=1,++cn;
	for(int i=1;i<N;++i)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<cn);
	int cf=0,cg=0;
	for(int i=L[l];i!=R[l];++i)F[cf++]=S[i];
	for(int i=L[o];i!=R[o];++i)G[cg++]=S[i];
	while(cf!=N)F[cf++]=0;while(cg!=N)G[cg++]=0;
	NTT(F,0);NTT(G,0);
	for(int i=0;i<N;++i)F[i]=1ll*F[i]*G[i]%mod;
	NTT(F,1);
	for(int i=0;i<mx;++i)S[L[l]+i]=F[i];
	R[l]=L[l]+mx;
}
int GO[maxn],iac[maxn*2],fac[maxn*2];
int binom(int n,int m){
	return 1ll*iac[m]*iac[n-m]%mod*fac[n]%mod;
}
int a[maxn*2];
int main(){
	int n;read(n);
	GO[0]=1;
	for(int i=1;i<=n;++i)
		GO[i]=1ll*GO[i-1]*(i*2-1)%mod;
	iac[0]=iac[1]=fac[0]=fac[1]=1;
	for(int i=2;i<=n*2;++i)
		iac[i]=1ll*(mod-mod/i)*iac[mod%i]%mod;
	for(int i=2;i<=n*2;++i)
		iac[i]=1ll*iac[i-1]*iac[i]%mod,fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=1;i<=n*2;++i)read(a[i]);
	sort(a+1,a+n*2+1);int cnt=0,num=0;
	for(int l=1,r=l;l<=n*2;l=r=r+1){
		while(r+1<=n*2&&a[r+1]==a[l])++r;
		int len=r-l+1;++num;L[num]=cnt;
		for(int x=0;x*2<=len;++x)
			S[cnt++]=1ll*GO[x]*binom(len,x*2)%mod;
		R[num]=cnt;
	}
	solve(1,num);
	int mx=R[1]-L[1],delta=L[1],ans=0;
	for(int i=0;i<mx;++i){
		int tmp=1ll*GO[n-i]*(S+delta)[i]%mod;
		if(i&1)tmp=mo(mod-tmp);
		ans=mo(ans+tmp);
	}
	write(ans),pc('\n');
	return 0;
}


Measured memory_bytes: 6360
#include<bits/stdc++.h>
using namespace std;
long long n,a,b;
inline int read()
{
   int sum=0,x=1;
   char ch=getchar();
   while (ch<'0'||ch>'9')
   {
       if (ch=='-')
	     x=-1;
	   ch=getchar();
   }
   while (ch>='0'&&ch<='9')
   {
   	   sum=sum*10+ch-'0';
	   ch=getchar();
   }
   return sum*x;
}
inline void write(int x)
{
    if (x<0)
	{
        putchar('-');
        x=-x;
    }
    if (x>9)
      write(x/10);
    putchar(x%10+'0');
    return;
}
int main()
{
	n=read();a=read();b=read();
	if (a+b>n+1||a*b<n)
	{
		write(-1);
		return 0;
	}
	while (n)
	{
		long long s=min(a,n-(b-1));
		for (register long long i=n-(s-1);i<=n;++i)
		{
			write(i);
			putchar(' ');
		}
		n-=s;
		--b;
	}
	return 0;
}

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

int main(){
  int S;
  cin >> S;
  int h, h2, m, s;
  h = S / 3600;
  h2 = S % 3600;
  m = h2 / 60;
  s = h2 % 60;
  cout << h << ":" << m << ":" << s << endl; 
}



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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<ll> X(N), Y(N), Z(N);
    rep(i, N) cin >> X[i] >> Y[i] >> Z[i];

    ll ans = 0;
    rep(x, 2) {
        rep(y, 2) { 
            rep(z, 2) {
                vector<ll> V(N);
                rep(i, N) {
                    ll res = 0;
                    if (x) res -= X[i];
                    else res += X[i];

                    if (y) res -= Y[i];
                    else res += Y[i];

                    if (z) res -= Z[i];
                    else res += Z[i];

                    V[i] = res;
                }

                sort(V.begin(), V.end(), greater<ll>());
                ans = max(ans, accumulate(V.begin(), V.begin() + M, 0LL));
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void) {

        double r;

        scanf("%lf", &r);
        if(r <= 0 || r >= 10000) return 1;

        printf("%.6lf %.6lf\n", M_PI*r*r, 2*M_PI*r);

        return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cfenv>
#include <cmath>

using namespace std;

int main() {
  double a,b,n;
  cin>>a>>b>>n;
  map<int,int> an;
  int count=0;
  double i=0;
  int tem =0;
  int max =0;
  int key = 0;
  double tem2;
  i = b-1;
    tem = floor(a*i/b) - a*floor(i/b);
    i = n;
    tem2 = floor(a*i/b) - a*floor(i/b);
    if(b-0.1<n)
    cout<<tem<<endl;
    else
      cout<<tem2<<endl;
      

  return 0;
}

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

int main(){
	string O, E;
	cin >> O >> E;

	string res = "";
	for(int i = 0; i < O.size(); ++i) {
		res += O[i];

		if(O.size() - E.size() == 1 && i == O.size() - 1) {
			
		} else {
			res += E[i];
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;

string p;

bool isPal(int a, int b) {
	int i = a-1, j = b-1;
	while (i < j) {
		if (p[i] != p[j]) return false;
		++i; --j;
	}
	return true;
}

int main() {
	cin.sync_with_stdio(false); cin.tie(nullptr);
	cin >> p;
	int n = p.size();
	if (isPal(1, n) && isPal(1, (n - 1) / 2) && isPal((n + 3) / 2, n))
		cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
-- ALDS1_1_D Maximum Profit

import Data.Array

main = interact $ (flip (++) "\n") . show . (\(n:xs) -> greatestDiff (take n xs)) . map read . lines

-- post: returns an array, a, of length equal to xs, where
-- a[i] = min {xs[j] : j <= i}
leasts (x:xs) = leasts' (x:xs) x
leasts' [] _ = []
leasts' (x:xs) g = if x < g then x:(leasts' xs x) else g:(leasts' xs g)

-- post: returns an array, g, of length equal to xs, where
-- g[i] = max {xs[j] : j >= i}
greatests :: [Int] -> [Int]
greatests = reverse . aux . reverse
    where aux (x:xs) = greatests' [] (x:xs) x
          greatests' front [] _ = reverse front
          greatests' front (x:xs) l = if x > l then (greatests' (x:front) xs x) else (greatests' (l:front) xs l)

greatestDiff xs = let (l:ls) = leasts xs
                      (_:g:gs) = greatests xs
                      getmax _ [] m = m
                      getmax [] _ m = m
                      getmax (l:ls) (g:gs) m = getmax ls gs (if g - l > m then g - l else m)
                  in  getmax ls gs (g - l)

Measured memory_bytes: 116556
#include<bits/stdc++.h>
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define ui unsigned int 
using namespace std;
int main()
{
	int a, b;
	while (cin >> a >> b) {
		int s = a + b;
		int c = 0;
		while (s > 0) {
			s = s / 10;
			c++;
		}
		cout << c<<endl;
	}
}




Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    string s, t;
    cin >> s >> t;
    int q;
    cin >> q;
    vector<int> sum_s(s.size()+1);
    vector<int> sum_t(t.size()+1);
    sum_s[0] = 0;
    sum_t[0] = 0;
    for(int i = 0; i < s.size(); i++)
    {
        int cand = 0;
        if(s[i] == 'A') cand = 1;
        else cand = 2;
        sum_s[i+1] = sum_s[i] + cand;
    }
    for(int i = 0; i < t.size(); i++)
    {
        int cand = 0;
        if(t[i] == 'A') cand = 1;
        else cand = 2;
        sum_t[i+1] = sum_t[i] + cand;
    }
    for(int i = 0; i < q; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int g1 = (sum_s[b] - sum_s[a-1]) % 3;
        int g2 = (sum_t[d] - sum_t[c-1]) % 3;
        if(g1 == g2)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(a,b);
    // vl A(n); in1(A); 
    FOR(i,1,12501){
        if((ll)(i*0.08)==a && (ll)(i*0.1)==b){
            out(i);
            return 0;
        }
    }
    cout << -1 << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>
#include <map>
using namespace std;

int N, A[100009], sum = 0, minx = (1 << 30);

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; sum += A[i];
		minx = min(minx, sum / i);
	}
	cout << minx << endl;
	return 0;
}


Measured memory_bytes: 3112
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
ll a, b, k;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a>>b>>k;
    a-=k;
    if(a<0){
        b+=a;
        a=0;
    }
    if(b<0){
        b=0;
    }
    cout << a<<" "<<b << "\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool isinclude(int x, int *g, int N);
int main(){
    int x,y;
    cin >> x >> y;
    int a[] = {1,3,5,7,8,10,12}, b[] = {4,6,9,11};
    cout << (((isinclude(x,a,7) && isinclude(y,a,7)) || (isinclude(x,b,4) && isinclude(y,b,4)) || x == y ) ? "Yes" : "No") << endl;
}

bool isinclude(int x, int *g, int N ){
    for(int i = 0; i < N; i++){
        if(x == g[i]) return true;
    }
    return false;
}

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

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

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

	int h,w; cin >> h >> w;
	char f[101][101];

	for (int i = 0;i < h;i++){
		for (int j = 0;j < w;j++){
			cin >> f[i][j];
		}
	}

	for (int i = 0;i < h;i++){
		for (int j = 0;j < w;j++){
			for (int k = j;k >= 0;k--){
				if(f[i][k] == 'c'){
					cout << j-k ;
					break;
				}
				if(k == 0) cout << "-1";
			}
			if(j != w-1) cout << " ";
		}
		cout << endl;
	}

	return 0;

}



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

#define int long long

#define MOD 1000000007
#define PB(a) push_back(a);
#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)
using  ll = long long;

struct zahyo {
	int lx;
	int ly;
	int rx;
	int ry;
};

queue<zahyo> q;
int lx, ly, rx, ry;
int px1, px2, py1, py2;
int w, h;
int cost[52][52][52][52];
int m[2][52][52];
#define INF 1000000000

void init()
{
	rep(i, 52) rep(j, 52) rep(k, 52) rep(l, 52) {
		cost[i][j][k][l] = INF;
	}
	rep(i, 52) rep(j, 52) {
		m[0][i][j] = 0;
		m[1][i][j] = 0;
	}
		
}

bool mypush(int lx, int ly, int rx, int ry)
{
	if (cost[ly][lx][ry][rx] != INF) return false;
	if (!(px1 == lx && py1 == ly && px2 == rx && py2 == ry)) {
		if (px1 == lx && py1 == ly) return false;
		if (px2 == rx && py2 == ry) return false;
	}
	zahyo z;
	z.lx = lx;
	z.ly = ly;
	z.rx = rx;
	z.ry = ry;
	q.push(z);
	return true;
}

signed main()
{
	while (true) {
		cin >> w >> h;
		if (w == 0) break;
		init();
		rep(i, h) {
			string s[2];
			cin >> s[0] >> s[1];
			rep(cnt, 2) rep(j, w) {
			if (s[cnt][j] == 'L') {
					lx = j+1;
					ly = i+1;
				}
				if (s[cnt][j] == 'R') {
					rx = j+1;
					ry = i+1;
				}
				if (s[cnt][j] == '#') {
					m[cnt][i+1][j+1] = 0;
				} else {
					m[cnt][i+1][j+1] = 1;
				}
				if (s[cnt][j] == '%') {
					if (cnt == 0) {
						px1 = j+1;
						py1 = i+1;
					} else {
						px2 = j+1;
						py2 = i+1;
					}
				}
			}
		}
		cost[ly][lx][ry][rx] = 1;
		zahyo ztmp;
		ztmp.lx = lx;
		ztmp.ly = ly;
		ztmp.rx = rx;
		ztmp.ry = ry;
		q.push(ztmp);
		int dlx[] = {0, 1, 0, -1};
		int dly[] = {-1, 0, 1, 0};
		int drx[] = {0, -1, 0, 1};
		int dry[] = {-1, 0, 1, 0};
		while (!q.empty()) {
			zahyo z = q.front();
			q.pop();
			rep(i, 4) {
				int nlx, nly, nrx, nry;
				int lxt, lyt, rxt, ryt;
				nlx = lxt = z.lx;
				nly = lyt = z.ly;
				nrx = rxt = z.rx;
				nry = ryt = z.ry;
				if (dlx[i]) {
					if (m[0][lyt][dlx[i]+lxt] == 1) nlx = dlx[i]+lxt;
					if (m[1][ryt][drx[i]+rxt] == 1) nrx = drx[i]+rxt;
				} else {
					if (m[0][lyt+dly[i]][lxt] == 1) nly = dly[i]+lyt;
					if (m[1][ryt+dry[i]][rxt] == 1) nry = dry[i]+ryt;
				}
				if (mypush(nlx, nly, nrx, nry)) {
					cost[nly][nlx][nry][nrx] = 1;
				}
			}
		}
		if (cost[py1][px1][py2][px2] == 1) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 61904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653

ll kaijyo[210000];

void runfirst(){ //必ず回す!!
	kaijyo[0] = 1;
	FOR(i,1,209999) kaijyo[i] = (kaijyo[i-1]*i)%MOD;
}

ll powe(ll a, ll b){ //aのb乗のmod
	ll ret = 1;
	while(0 < b){
		if((b%2) == 0){
			a = (a*a)%MOD;
			b >>= 1;
		}
		else{
			ret = (ret*a)%MOD;
			b--;
		}
	}
	return ret;
}

ll C(ll m, ll n){
	return (kaijyo[m]*((powe(kaijyo[m-n],MOD-2) * powe(kaijyo[n],MOD-2))%MOD)%MOD);
}


int main(){
	ll n, a, b, ans; cin >> n >> a >> b;
	runfirst();
	ll x = powe(2,n)-1;
	ll y = powe(kaijyo[a],MOD-2);
	ll z = powe(kaijyo[b],MOD-2);
	FORD(i,n,n-a+1) y = (y*i)%MOD;
	FORD(i,n,n-b+1) z = (z*i)%MOD;
	x -= (y+z);
	while (x<0) {
		x += MOD;
	}
	cout << x << endl;
}

Measured memory_bytes: 1920
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    vector<int>x;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0'){
            x.push_back(0);
        }else if(s[i]=='1'){
            x.push_back(1);
        }else if(s[i]=='B'){
            if(x.size()==0){
                continue;
            }else{
                x.pop_back();
            }
        }
    }
    for(int i=0;i<x.size();i++){
        cout << x[i];
    }
}

Measured memory_bytes: 256
function main()
    function calc_low_total()
        total = low = 0
        for c in readline()
            if c == '('
                total += 1
            else
                total -= 1
                low = min(low,total)
            end
        end
        ifelse(0 < total,(1,low,total), (-1,total-low,total))
    end
    flag = true
    res = 0
    for (p_or_n,low,total)  in sort([calc_low_total() for i in 1:parse(Int,readline())],rev=true)
        if res+ifelse(p_or_n == 1,low,total-low) < 0
            flag = false
            break
        end
        res+=total
    end
    println(ifelse(flag && res == 0,"Yes","No"))
end
main()


Measured memory_bytes: 260652
w,h,n=map(int,input().split())
l=[[int(j) for j in input().split()] for i in range(n)]
b=c=0
d=w
e=h
for i in range(n):
    a=l[i][2]
    if a==1:b=max(b,l[i][0])
    if a==2:d=min(d,l[i][0])
    if a==3:c=max(c,l[i][1])
    if a==4:e=min(e,l[i][1])
print([(d-b)*(e-c),0][(d<b)|(e<c)])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
#include <cctype>
#include <ctype.h>
#include <math.h>
char toupper(char c);
char toupper(char c)
{
    return (c - 0x20);
}

using namespace std;
int main() {
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
  int p=i*1.08;
  if(p==n){
    cout<<i<<endl;
    return 0;
  }
  }
  cout<<":("<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{  
  int n;
  long a[200100];
  long long ans = 0;
  
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  
  int now = a[0];
  
  for(int i=1;i<n;i++)
  {
    if(now > a[i])
    {
      ans += now-a[i];
    }
    if(now < a[i]) now = a[i];
  }
  
  cout << ans << endl;
  return 0;
}

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

#define MAX_N (20000)

int main(int argc, char *argv[]) {
  // read inputs
  int N, ps[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &ps[i]);
    ps[i]--;  // NOTE : modified inputs
  }

  // solve
  int as[MAX_N], bs[MAX_N];
  for (int i = 0; i < N; i++) {
    as[i] = (i + 1) * (N + 1);
    bs[i] = (N - i) * (N + 1);
  }
  for (int i = 0; i < N; i++) {
    as[ps[i]] += i;
  }
  for (int i = 0; i < N; i++) {
    printf("%d ", as[i]);
  }
  printf("\n");
  for (int i = 0; i < N; i++) {
    printf("%d ", bs[i]);
  }
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 768
#include<string>
#include<iostream>
using namespace std;
int n;
long long x[100001],a,b;
int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	  cin>>x[i];
	long long ans=0;
	for(int i=2;i<=n;i++)
	  if((x[i]-x[i-1])*a>b) ans+=b;
	  else ans+=(x[i]-x[i-1])*a;
	cout<<ans;
}

Measured memory_bytes: 1024
// Problem: B - Go to Jail
// Contest: AtCoder - AtCoder Beginner Contest 179
// URL: https://atcoder.jp/contests/abc179/tasks/abc179_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable" 
//#pragma GCC diagnostic ignored "-Wformat"

using namespace std ;

#define   Pi     2*acos(0.0)
#define   LINF   1LL<<63
#define   ll     long long
#define   ull    unsigned long long
#define   pb     push_back
#define   mp     make_pair
#define   MAX    500006
#define   MAX1   10000008
#define   mem(a,v)   memset(a,v,sizeof(a))
#define   all(x) x.begin(),x.end()
#define   lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define yes   cout<<"YES"<<endl
#define no   cout<<"NO"<<endl
#define buga  cout<<1<<endl
#define bugb  cout<<2<<endl
#define bugc  cout<<3<<endl
#define bugd  cout<<4<<endl
#define buge  cout<<5<<endl

void fastIO (){ios_base::sync_with_stdio(false);cin.tie(0); cout.precision(20);}

ll A[MAX];
ll B[MAX];
ll C[MAX];
vector< ll >V;
vector< ll >Ans;
vector< pair<ll,ll> >VP;
map< ll,ll >M;
vector<ll>prime;
bool mark[MAX1];
ll N=1e7;
void seive (){int limit = sqrt(N*1.0)+2;mark[1]=1;for (int i=4;i<=N;i+=2)mark[i]=1;prime.push_back(2);for (int i=3;i<=N;i+=2){if(!mark[i]){prime.push_back(i);if(i<=limit){for (int j=i*i;j<=N;j+=i*2)mark[j]=1;}}}}

/*
ll bin_pow(ll o, ll s) {
    if (s == 0) return 1;
    if (s == 1) return o % mod;
    ll d = bin_pow(o, s/2);
    d = (d * 1ll * d) % mod;
    if (s % 2 == 1)
        d = (d * 1ll * o) % mod;
    return d;
}
*/

int main ()
{
    fastIO();
    ll a,b,c,d,n,m,k,l,p,q,r,t,x,y;
    ll cnt=0,cntr=0,sum=0,ans=1,check=0;
    ll Max= 0,Max1=-1e18+1,Min=LINF;
    string s,s1,s3,s4;

    //cin>>n;
   cin>>n;
   
   for(int i = 1; i<= n; i++){
   		cin>>A[i]>>B[i];
   }
   for(int i = 1; i<=n-3+1;i++){
   	check = 0;
   	 for(int j = 1; j <= 3; ++j){
   	 	//cout<<A[i+j]<<" "<<B[i+j]<<endl;
   	 	if(A[j+i-1]!=B[j+i-1]){
   	 		check = 1;
   	 		break;
   	 		
   	 	}
   	 }
   	 if(check ==0){
   	 	cout<<"Yes"<<endl;return 0;
   	 }
   }
   cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs;
		inputs = br.readLine().split(" ");
		int n = Integer.parseInt(inputs[0]), m = Integer.parseInt(inputs[1]);

		N[] nodes = new N[n];
		for ( int i = 0; i < n; i++ ) {
			nodes[i] = new N(i);
		}

		for ( int i = 0; i < m; i++ ) {
			inputs = br.readLine().split(" ");
			int x = Integer.parseInt(inputs[0]) - 1, y = Integer.parseInt(inputs[1]) - 1;
			nodes[x].chldList.add(nodes[y]);
			nodes[y].prntCnt++;
		}

		ArrayDeque<N> toCheck = new ArrayDeque<>();
		for ( N node : nodes ) {
			if ( node.prntCnt == 0 ) toCheck.add(node);
		}

		int lenMax = 0;
		while ( toCheck.size() > 0 ) {
			N node = toCheck.pollFirst();
			for ( N chld : node.chldList ) {
				chld.prntCnt--;
				chld.len = Math.max(node.len + 1, chld.len);
				lenMax = Math.max(lenMax, chld.len);
				if(chld.prntCnt == 0) {
					toCheck.add(chld);
				}
			}			
		}
		System.out.println(lenMax);
	}
}

class N implements Comparable<N> {

	int				id			= 0;
	int				len			= 0;
	int				prntCnt		= 0;
	ArrayList<N>	chldList	= new ArrayList<>();

	public N(int id) {
		this.id = id;
	}

	@Override
	public int compareTo(N o) {
		return this.prntCnt - o.prntCnt;
	}
}


Measured memory_bytes: 54516
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 105;
string s;
int k;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s >> k;
    set<string> pq;
    int i = 0, j = 0;
    int n = s.length();
    for(i = 0; i < n; i++){
        string st = "";
        for(j = i; j < min(n, i + 100); j++) {
            st += s[j];
            pq.insert(st);
        }
    }
    string ans = "";
    while(k--) {
        ans = *pq.begin();
        pq.erase(ans);
        //cout << ans << "\n";
    }
    cout << ans;
    return 0;
}

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

void solve() 
{
    ll n;cin>>n;
    vector<ll> arr(n,0);
    ll temp = 0;
    for(ll i = 0;i<n;i++){
        ll x;cin>>x;
        temp ^= x;
        arr[i] = x;
    }
    for(ll i = 0;i<n;i++)
    {
        arr[i] = temp ^ arr[i];
    }
    for(ll i = 0;i<n;i++){
        cout << arr[i] << " ";
    }
    cout << endl;
} 

//driver
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll test = 1;
    // cin>>test;
    for(ll i = 0;i<test;i++)
    {
        solve();
    }
}    

Measured memory_bytes: 4760
#include <iostream>

using namespace std;

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

const int inf = 1e9 + 10;

int dp[100010];
int N, W;
int w[101], v[101];

int main()
{
	cin >> N >> W;
	rep(i, N) {
		cin >> w[i] >> v[i];
	}

	rep(i, 100010) dp[i] = inf;

	dp[0] = 0;
	rep(i, N) {
		for (int j = 100000; j >= 0; --j) {
			if (j - v[i] < 0) break;
			dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
		}
	}

	for (int i = 100000; i >= 0; --i) {
		if (dp[i] <= W) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 640