akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = 1LL<<55;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  multiset <int> S;
  
  int q;
  cin>>q;
  while(q--){
    int cmd, num;
    cin>>cmd>>num;
    if(cmd == 0){
      S.insert(num);
      cout<<S.size()<<endl;
    }

    if(cmd == 1){
      cout<<S.count(num)<<endl;
    }
    
    if(cmd == 2){
      S.erase(num);
    }

    if(cmd == 3){
      int l = num, r;
      cin>>r;
      auto start = S.lower_bound(l);
      auto last= S.upper_bound(r);
      for(auto it = start; it != last; it++) cout<<*it<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 12420
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextInt();
        }
        sc.close();

        long all = Math.abs(a[0]) + Math.abs(a[n-1]);
        for(int i=0; i<n-1; i++){
            all += Math.abs(a[i+1] - a[i]);
        }

        System.out.println(all - Math.abs(a[0]) - Math.abs(a[1] - a[0]) + Math.abs(a[1]));
        for(int i=1; i<n-1; i++){
            System.out.println(all - Math.abs(a[i] - a[i-1]) - Math.abs(a[i+1] - a[i]) + Math.abs(a[i+1] - a[i-1]));
        }
        System.out.println(all - Math.abs(a[n-1] - a[n-2]) - Math.abs(a[n-1]) + Math.abs(a[n-2]));
    }
}


Measured memory_bytes: 66584
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include<string>
#include<cstring>
#include<complex>
#include<cmath>
using namespace std;
#define rep(i, n)   for(int i = 0; i < (int)(n); i++)
#define rrp(i, n)   for(int i = ((int)(n)); i >=0; i--)
#define mpp(i,j,k)  make_pair((int)(i),make_pair((int)(j),(int)(k)))
typedef pair<int,pair<int,int > > ppp;
typedef pair<int,int> pp;
typedef vector<int> vi;
typedef vector<vi>  vvi;
bool d[100001];
int  q[100001];
bool prime(int x){
if(x==1)return false;
if(x==2)return true;
if(x%2==0) return false;
for(int i=3;i<=sqrt(x);i+=2)if(x%i==0) return false;

return true;
}
int main(){
 rep(i,100001){d[i]=prime(i);}
 rrp(i,100001){if(i%2==1)d[i]&=d[(i+1)/2];}
d[2]=false;
 rep(i,100001){q[i]=0;if(d[i])q[i]=1;if(i>0)q[i]+=q[i-1];}
int Q;
int l[100000],r[100000];
cin>>Q;
rep(i,Q)cin>>l[i]>>r[i];
rep(i,Q)cout<<q[r[i]]-q[l[i]-1]<<endl;
  return 0;}




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

int main() {
	double v,y;
	int n;
	while (cin >> v) {
		y = v*v / 19.6;
		n = (y-0.0000000001) / 5;
		cout << n+2 << endl;
	}
	return 0;
}

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

f = [2] * (N+1)
f[0] = 0
f[1] = 1
for k in range(2, int(N**0.5)+1):
  if f[k] > 2:
    continue
  m = 1
  while k ** m <= N:
    for j in range(1, N//k**m + 1):
      f[j * k**m] = f[j] * (m+1)
    m += 1
  #print(f)
#print(k)
ans = 0
for i, ff in enumerate(f):
  ans+=i*ff
print(ans)


Measured memory_bytes: 146420
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	sum := 0
	for i := 1; i <= n; i++ {
		v := i
		d := 0
		for {
			d += v % 10
			v /= 10
			if v == 0 {
				break
			}
		}
		if a <= d && d <= b {
			sum += i
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <list>
using namespace std;
class NewList: private vector<list<int> >
{
public:

	NewList(int n): vector<list<int> >(n) {}

	void insert(int t, int x)
	{
		at(t).push_back(x);
	}

	void dump(int t)
	{
		if (!at(t).empty())
		{
			list<int>::iterator iter = at(t).begin();
			while (1)
			{
				cout << *iter;
				if (++iter == at(t).end())
				{
					cout << endl;
					return;
				}
				else
				{
					cout << " ";
				}
			}
		}
		else
		{
			cout << endl;
		}
	}

	void splice(int s, int t)
	{
		list<int>::iterator iter = at(t).end();
		at(t).splice(iter, at(s));
	}

};

int main()
{
	int n;
	cin >> n;
	NewList a(n);
	cin >> n;
	for (int i=0; i<n; ++i)
	{
		int c;
		cin >> c;
		if (c == 0)
		{
			int t, x;
			cin >> t >> x;
			a.insert(t, x);
		}
		else if (c == 1)
		{
			int t;
			cin >> t;
			a.dump(t);
		}
		else
		{
			int s, t;
			cin >> s >> t;
			a.splice(s, t);
		}
	}
	return 0;
}



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

void pf(int64_t a,queue<int64_t> &q){
  if(a<2){
    return;
  }
  int64_t n=2;
  bool flag=true;
  while(n<=sqrt(a)){
    if(a%n==0){
      a/=n;
      if(flag){
        q.push(n);
        flag=false;
      }
    }else{
      n++;
      flag=true;
    }
  }
  if(n!=a){
    q.push(a);
  }
}

int64_t gcd(int64_t a,int64_t b){
  int64_t r=max(a,b)%min(a,b);
  if(r==0){
    return min(a,b);
  }
  return gcd(min(a,b),r);
}

int main(){
  int64_t A,B;
  cin >> A >> B;
  queue<int64_t> q;
  q.push(1);
  pf(gcd(A,B),q);
  cout << q.size() << endl;
  return 0;
}


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

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 998244353;
const int MAXN = 3e3 + 5;

ll binpow(ll a, ll b) {
    if (b == 0) return 1ll;
    if (b % 2) {
        return (a * binpow(a, b - 1)) % MOD;
    } else {
        ll save = binpow(a, b / 2);
        return (save * save) % MOD;
    }
}

void solve() {
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<ll> newdp(s + 1), dp(s + 1); 
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        newdp.assign(s + 1, 0);
        for (int prevw = 0; prevw <= s; ++prevw) {
            if (prevw + a[i] <= s) {
                newdp[prevw + a[i]] += dp[prevw];
                newdp[prevw + a[i]] %= MOD; 
            }
            newdp[prevw] += dp[prevw] * 2ll;
            newdp[prevw] %= MOD;
        }
        dp = newdp;
    }
    cout << dp[s] << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);

int main() {
    string s;
    cin>>s;
    ll b=0;
    ll ans=0;
    for(char ch:s){
        if(ch=='B')
            b++;
        else ans+=b;
    }
    cout<<ans;
    return 0;
}

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

int main() {
    //
    int num;

    cin >> num;

    vector<pair<long long, long long>> p(num);
    for (int i = 0; i < num; i++) {
        long long a, b;
        cin >> a >> b;
        p.at(i) = make_pair(a+b, a-b);
    }

    sort(p.begin(), p.end());

    long long right = 0;
    long long cnt = 0;
    for (int i = 0; i < num; i++) {
        long long tmpL = p.at(i).second;
        long long tmpR = p.at(i).first;
        if (i == 0) {
            right = tmpR;
            continue;
        }
        if (tmpL < right) {
            cnt++;
        } else {
            right = tmpR;
        }
    }

    cout << num - cnt << endl;
    //
}


Measured memory_bytes: 4756
#!/usr/bin
# -*- cording: "utf-8" -*-
 
a = input().split()
a = list(map(int, a))
if (a[0] % 3 == 0) or (a[1] % 3 == 0) or ((a[0] + a[1]) % 3 == 0):
  print("Possible")
else:
  print("Impossible")

Measured memory_bytes: 3060
H,W = map(int,input().split())
a = [list(map(int,input().split())) for i in range(H)]

ans = []
for y in range(H-1):
    for x in range(W):
        if a[y][x]%2 == 1:
            ans.append('{} {} {} {}'.format(y+1,x+1,y+2,x+1))
            a[y][x] -= 1
            a[y+1][x] += 1

for x in range(W-1):
    if a[H-1][x]%2 == 1:
        ans.append('{} {} {} {}'.format(H,x+1,H,x+2))
        a[H-1][x+1] += 1

print(len(ans))
for s in ans:
    print(s)

Measured memory_bytes: 16344
package main

import (
  "fmt"
)

func main() {
  var N, K int
  fmt.Scan(&N, &K)
  A := make([]int, N)
  var x int
  for i := 0; i < N; i++ {
    fmt.Scan(&x)
    A[i] = x
  }
  B := make([]int, N + 1)
  for i := 0; i < N; i++ {
    B[i + 1] = B[i] + A[i]
  }
  M := make([][]int, N * (N + 1) / 2)
  S := make([]int, 40)
  pos := 0
  var alr, b int
  for r := 1; r < N + 1; r++ {
    for l := 0; l < r; l++ {
      alr = B[r] - B[l]
      M[pos] = make([]int, 40)
      for j := 39; j >= 0; j-- {
        b = alr % 2
        M[pos][j] = b
        S[j] += b
        alr /= 2
      }
      pos += 1
    }
  }
  cnt := 0
  for i := 0; i < 40; i++ {
    if S[i] < K {
      continue
    }
    cnt += int(1 << uint(39 - i))
    for j := 0; j < pos; j++ {
      if M[j][i] > 0 {
        continue
      }
      for k := i; k < 40; k++ {
        if M[j][k] == 0 {
          continue
        }
        M[j][k] = 0
        S[k] -= 1
      }
    }
  }
  fmt.Println(cnt)
}

Measured memory_bytes: 180720
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <fstream>
#include <cstring>
#include <stack>

using namespace std;

#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double

const ld pi = acos(-1);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
ostream& operator << (ostream &s, const vector<T> &x) {
    s << "[";
    for (auto it : x) {
        s << it << ", ";
    }
    s << "]";
    return s;
}

template<typename T>
ostream& operator << (ostream &s, const set<T> &x) {
    s << "{";
    for (auto it : x) {
        s << it << ", ";
    }
    s << "}";
    return s;
}


template<typename U, typename V>
ostream& operator << (ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

//---------------------------------------------------------------------

const int maxn = 1e5 + 5;
vector<int> g[maxn];
int ans = 0;
int k;

int dfs(int v) {
    int depth = 0;

    for (int to : g[v]) {
        int r = 1 + dfs(to);
        if (r == k && v != 1) {
            ans++;
        } else {
            chmax(depth, r);
        }
    }
    //cout << v << " " << depth << endl;
    return depth;
}

int main() {
    srand(time(NULL));
    retry:
#ifdef LOCAL
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
#endif

    int n;
    scanf("%d", &n);
    cin >> k;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }

    if (a[1] != 1) {
        a[1] = 1;
        ans++;
    }

    for (int i = 2; i <= n; i++) {
        g[a[i]].pb(i);
    }

    dfs(1);
    cout << ans << endl;


    return 0;
}





Measured memory_bytes: 10752
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 4005;
const long long INF = (1LL<<60);

int n;
long long a[N], x;
long long b[N][N];

int main(){
	scanf("%d%lld", &n, &x);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		a[i+n] = a[i];
	}
	for (int i = 1; i <= 2 * n; i++) {
		long long tmp = a[i];
		for (int j = i; j <= 2 * n; j++) {
			tmp = min(tmp, a[j]);
			b[i][j] = tmp;
		}
	}
	long long ans = INF;
	for (int i = 0; i <= n; i++) {
		long long Min = x * i;
		for (int j = n + 1; j <= 2 * n; j++) {
			Min += b[j - i][j];
		}
		ans = min(ans, Min);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 77696
//How many divisors?

#include<stdio.h>

int main(void)
{
    int a,b,c,cnt=0;
    scanf("%d%d%d",&a,&b,&c);

    do
    {
        if(c%a==0) cnt++;
    }while(a++!=b);

    printf("%d\n",cnt);

    return 0;

}


Measured memory_bytes: 2104
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI a(n+2), x(n+1);
    REP(i,n){
        scanf("%d", &a[i+1]);
        x[a[i+1]] = i+1;
    }

    VI s(n+2,1), f(n+2);
    ll ans = 0;
    FORR(i,n,1){
        ll l, r;
        int j = x[i];
        f[j] = 1;
        if (!f[j-1]) l = 0;
        else l = s[j-1];
        if (!f[j+1]) r = 0;
        else r = s[j+1];
        ans += (l+1)*(r+1)*i;
        s[j-l] = l+r+1;
        s[j+r] = l+r+1;
    }

    cout << ans << endl;

    return 0;
}


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

#define MOD 1000000007

int main()
{
    double a,b,x;
    cin>>a>>b>>x;
    if(x>=a*a*b/2)
    {
        double h = (double)x/a/a;
        double ans = (b-h)*2.0/a;
        ans = atan(ans);
        ans =ans*180.0/M_PI;
        cout<<fixed<<setprecision(10)<<ans<<endl;           
    }
    else
    {
        double w = (double)x/a/b;
        double ans = b/(2.0*w);
        ans=atan(ans);
        ans =ans*180.0/M_PI;
        cout<<fixed<<setprecision(10)<<ans<<endl; 
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[100005];
	long long ans=0;
	for(int i=1;i<=n+1;++i)
		cin>>a[i];
	for(int i=1,b;i<=n;++i){
		cin>>b;
		int x=max(0,a[i]-b);
		ans+=a[i]-x;
		b-=a[i]-x;
		a[i]=x;
		if(b>0)
		{
			int x=max(0,a[i+1]-b);
			ans+=a[i+1]-x;
			b-=a[i+1]-x;
			a[i+1]=x;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,string> P;
typedef long long int lld;
#define INF (1<<20)

int gcd(int x,int y) {
  int t;
  while(y!=0) {
    t = x % y;
    x = y;
    y = t;
  }
  return x;
}

int main(){
  int a,b;
  while(cin >> a >> b){
    cout << gcd(a,b) << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin>>x;
	for(int i=-200;i<=200;i++)for(int j=-200;j<200;j++){
		if(pow(i,5)-pow(j,5)==x){
			cout<<i<<" "<<j<<endl;
			return 0;
		}
	}
}

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

int main(){
  int a, b, c, d, e, f, g, h;
  cin >> a;
  b = a / 100;
  c = a % 100;
  d = c / 10;
  e = a % 10;
  cout << b + d + e << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INT(a) scanf("%d",&a)
#define STR(a) scanf("%s",a)
#define DBL(a) scanf("%lf",&a)
#define LNG(a) scanf("%lld",&a)
#define PI acos(-1)

int main(){
	long long r, d, x;
	cin>>r>>d>>x;

	for(int i=1;i<=10;i++){
		x = r*x - d;
		cout<<x<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,x=0;cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++)cin>>L.at(i);
  sort(L.begin(),L.end());
  for(int i=0;i<N-1;i++)x+=L.at(i);
  if(L.at(N-1)<x)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
inp=[[] for j in range(8)]
for j in range(N):
    x,y,z=map(int,input().split())
    inp[0].append(x+y+z)
    inp[1].append(-x+y+z)
    inp[2].append(x-y+z)
    inp[3].append(-x-y+z)
    inp[4].append(x+y-z)
    inp[5].append(-x+y-z)
    inp[6].append(x-y-z)
    inp[7].append(-x-y-z)

ans=[]
for j in range(8):
    inp[j].sort()
    inp[j].reverse()

    ans.append(sum(inp[j][0:M]))

print(max(ans))

Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define esc(ret) cout << (ret) << endl,quick_exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) repU(i,0,(n) - 1)
#define rep1(i,n) repU(i,1,(n))
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) ((a) & 1 == (b) & 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;

const pii dir[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int mod = 1e9 + 7;
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;

int N;
string S;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> S;
	rep(i,2)rep(j,2){
		string ret;
		if(i) ret += 'S';
		else ret += 'W';
		if(j) ret += 'S';
		else ret += 'W';
		int t;
		if(S[0] == 'o'){
			t = i ? j : (1 - j);
		}else{
			t = (!i) ? j : (1 - j);
		}
		repU(k,2,N - 1){
			bool b = (S[k - 1] == 'o') ^ (ret[k - 1] == 'S');
			if(!b){
				ret += ret[k - 2];
			}else{
				ret += (ret[k - 2] == 'S') ? 'W' : 'S';
			}
		}
		bool b = (S[N - 1] == 'o') ^ (ret[N - 1] == 'S');
		char c;
		if(!b){
			c = ret[N - 2];
		}else{
			c = (ret[N - 2] == 'S') ? 'W' : 'S';
		}
		if((ret[N - 1] == 'S') == t && c == ret[0]) esc(ret);
	}	
	esc(-1);
}




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


using namespace std;

int n;
int maxW;
vector<pair<int,int>> vec;
long long meme[105][100007];


long long solve(int index, int remain){
    if(index==n){
        return 0;
    }
    
    if(meme[index][remain]!=-1){
        return meme[index][remain];
    }
    long long res1;
    meme[index][remain] = res1 = solve(index+1,remain);
    long long res2 =0;
    if(remain>=vec[index].first){
        meme[index][remain] = res2 = solve(index+1,remain-vec[index].first) + vec[index].second;
    }
    return meme[index][remain] = max(res1,res2);
}

int main(){
    cin>>n>>maxW;
    memset(meme,-1,sizeof(meme));
    int one,two;
    for(int i = 0 ; i<n ; i++){
        cin>>one>>two;
        vec.push_back(make_pair(one,two));
    }
    long long go = solve(0, maxW);
    cout<<go<<endl;
    return 0;
}

Measured memory_bytes: 85652
def calc_sum(num):
    
    total = 0
    while num>0:
        q = num//10
        r = num%10
        total += r
        num = q
        
    
    return total 
    
while True:
    
    n = int(input())
    if n == 0:
        break
    print(calc_sum(n))


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


int main() {
    int h,w;
    cin>>h>>w;
    int num[10][10];
    for (auto &i : num) {
        for (int &j : i) {
            cin>> j;
        }
    }
    for (int m = 0; m < 10; ++m) {
        for (int j = 0; j < 10; ++j) {
            for (int i = 0; i < 10; ++i) {
                num[j][i] = min(num[j][i], num[j][m]+num[m][i]);
            }
        }
        //cout<<num[8][4]<<endl;
    }
    int count=0;
    for (int l = 0; l < h; ++l) {
        for (int i = 0; i < w; ++i) {
            int n;
            cin>>n;
            if(n==-1)continue;
            count+=num[n][1];
        }
    }
    cout<<count<<endl;
    return 0;
}

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


int main(void)
{
    int N;
    std::cin >> N;
    std::vector<unsigned int> a(N);
    for(int i = 0; i < N ;i++) {
        std::cin >> a[i];
    }

    std::vector<unsigned int> b(1000005);
    for (int x : a) {
        if(b[x] != 0) {
            b[x] = 2;
            continue;
        }
        for(int j = x; j < 1000005; j += x) {
            b[j]++;
        }
    }
    int count = 0;
    for(int x: a) {
        if(b[x] == 1) {
            count++;
        }
    }

    std::cout << count << std::endl;
    return 0;

}

Measured memory_bytes: 8016
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    ans = 0
    checked = [[0]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == '.' or checked[i][j]:
                continue
            queue = deque()
            queue.append((i, j))
            dx = [1, -1, 0, 0]
            dy = [0, 0, 1, -1]
            black = 1  # 黒マスの数
            white = 0
            checked[i][j] = 1

            while queue:
                nowy, nowx = queue.popleft()
                for k in range(4):
                    y = nowy + dy[k]
                    x = nowx + dx[k]
                    if 0 <= y < H and 0 <= x < W:
                        if checked[y][x]:
                            continue
                        if S[y][x] != S[nowy][nowx]:
                            if S[y][x] == '.':
                                white += 1
                            else:
                                black += 1
                            queue.append((y, x))
                            checked[y][x] = 1
            # print(i, j)
            ans += black * white
            # print(checked)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<int,int>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<60
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;

inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back
string S;
int main(){
    cin>>S;
    if(S[sz(S)-1]=='s'){
        cout<<S+"es"<<endl;
    }else{
        cout<<S+"s"<<endl;
    }
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a + 3);

	if (a[2] % 2 == 1) {
		cout << (long long)a[0] * a[1] << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  string s,t;
  cin >> s >> t;
  int ans=0;
  rep(i,s.size()) {
    if(s[i]==t[i]) ans++;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main(){
    int a;
    cin>>a;
    
    cout<<a+pow(a,2)+pow(a,3)<<"\n";
    return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;
using namespace std;

ll M = 1000000007;

std::vector<ll> fac(510000, 1), finv(510000, 1), inv(510000, 1);

void c4_init(ll m) {
    // fac[0] = fac[1] = 1;
    // finv[0] = finv[1] = 1;
    // inv[0] = inv[1] = 1;
    for (ll i = 2; i < 510000; i++) {
        fac[i] = fac[i - 1] * i % m;
        inv[i] = m - inv[m%i] * (m / i) % m;
        finv[i] = finv[i - 1] * inv[i] % m;
    }
}

ll c4(ll n, ll k, ll m) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % m) % m;
}

signed main() {
  ll N, K;
  cin>>N>>K;
  c4_init(M);
  for (ll i=1; i<=K; i++) {
    cout<<c4(N-K+1,i,M)*c4(K-1,i-1,M)%M<<endl;
  }
  return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int a,b,q;
  cin >> a >> b >> q;
  vector<long> s(a);
  vector<long> t(b);
  vector<long> x(q);
  map<long,int> sid;
  map<long,int> tid;
  rep(i,a){
    cin >> s.at(i);
    sid[s.at(i)] = i;
  }
  rep(i,b){
    cin >> t.at(i);
    tid[t.at(i)] = i;
  }
  rep(i,q){
    cin >> x.at(i);
  }
  long s1,s2,t1,t2;
  int tmps,tmpt;
  long r1,r2,r3,r4,r5,r6;
  long tmpx;
  long mini = 1e14;
  rep(i,q){
    if(x.at(i) > s.at(a-1)) s2 = 1e12;
    else s2 = *lower_bound(s.begin(), s.end(), x.at(i));
    if(x.at(i) > t.at(b-1)) t2 = 1e12;
    else t2 = *lower_bound(t.begin(), t.end(), x.at(i));
    if(x.at(i) < s.at(0)) s1 = -1e12;
    else if(x.at(i) > s.at(a-1)) s1 = s.at(a-1);
    else{
      tmps = sid[s2] - 1;
      s1 = s.at(tmps);
    }
    if(x.at(i) < t.at(0)) t1 = -1e12;
    else if(x.at(i) > t.at(b-1)) t1 = t.at(b-1);
    else{
      tmpt = tid[t2] - 1;
      t1 = t.at(tmpt);
    }
    tmpx = x.at(i);
    r1 = max(abs(tmpx - s1), abs(tmpx - t1));
    r2 = max(abs(t2 - tmpx), abs(s2 - tmpx));
    r3 = abs((tmpx - t1))*2 + abs(s2 - tmpx);
    r4 = abs((s2 - tmpx))*2 + abs(tmpx - t1);
    r5 = abs((tmpx - s1))*2 + abs(t2 - tmpx);
    r6 = abs((t2 - tmpx))*2 + abs(tmpx - s1);
    mini = min(min(min(r1,r2),min(r3,r4)),min(r5,r6));
    cout << mini << endl;
  }
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    int N, K, S;
    cin >> N >> K >> S;

    int fill = 1000000000, val = S;
    if (S == 1000000000) {
        fill = 1;
    }
    vint output;
    for (int i = 0; i < K; i++) {
        output.push_back(val);
    }
    for (int i = K; i < N; i++) {
        output.push_back(fill);
    }

    cout << output[0];
    for (int i = 1; i < N; i++) cout << " " << output[i];
    cout << endl;
    return (0);
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod = 1'000'000'007;

int main(){
    string s;
    cin >> s;
    static int64_t eq[100001], ls[100001];
    eq[0] = 2;
    ls[0] = 1;
    for(int i=1;i<s.size();i++){
        if(s[i] == '1'){
            eq[i] = (eq[i-1]*2) % mod;
            ls[i] = (ls[i-1]*3%mod + eq[i-1]) % mod;
        }else{
            eq[i] = eq[i-1];
            ls[i] = (ls[i-1]*3) % mod;
        }
    }

    cout << (eq[s.size()-1]+ls[s.size()-1]) % mod << endl;
    //cerr << eq[s.size()-1] << " " << ls[s.size()-1] << endl;
    
    return 0;
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main() {
  int H, W, K;
  cin >> H >> W >> K;

  char c[H][W];
  int sum = 0;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> c[i][j];
      if(c[i][j] == '#') sum++;
    }
  }
  int ans = 0;
  for(int bit = 0; bit < (1 << H); bit++) {
    for(int b = 0; b < (1 << W); b++) {
      int kazu = 0;
      vector<int> num;
      vector<int> n;
      for(int i = 0; i < H; i++) {
      if(bit & (1 << i)) {
        num.push_back(i);
      }
    }
    for(int j = 0; j < W; j++) {
      if(b & (1 << j)) {
        n.push_back(j);
      }
    }
  
        for(int i = 0; i < H; i++) {
          for(int j = 0; j < W; j++) {
         
            for(auto a : num) {
           if(i == a && c[i][j] == '#') kazu++;
          }
          for(auto b : n) {
            if(j == b && c[i][j] == '#') kazu++;
          }
          for(auto a : num) {
          for(auto b : n) {
            if(i == a && j == b && c[i][j] == '#') kazu--;
          }
          }
          
          }
  }
  if(sum - kazu == K) ans++;
  }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 4005;
const int MM = 998244353;

int D[MX][MX];

int main()
{
	map<int, int> L;
	int N;
	ll ans = 0;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= N; j++) scanf("%d", D[i]+j);
	}
	for(int i = 1; i <= N; i++){
		for(int j = i+1; j <= N; j++){
			int v = 1, ch = 0;
			for(int k = 1; k <= N; k++){
				if( k != i && k != j && D[i][k] + D[k][j] == D[i][j] ) v = 0;
				if( D[i][k] + D[k][j] < D[i][j] ) ch = 1;
			}
			if( ch ) return !printf("-1\n");
			if( v ) ans += D[i][j];
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 4992
import sys
n = int(input())
a_ls = list(map(int, input().split()))
ans = 1
if min(a_ls) != 0:
    for i in range(n):
        ans *= a_ls[i]
        if ans > 10**18:
            print(-1)
            sys.exit()
    if ans > 10**18:
        print(-1)
    else:
        print(ans)
else:
    print(0)
        


Measured memory_bytes: 21476
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;

int main(){
    int n,k;
    std::cin >> n>>k;
    VEC(ll,x,n);
    
    std::vector<ll> a,b;
    rep(i,n){
        if(x[i]<0)a.pb(x[i]);
        else b.pb(x[i]);
    }
    
    int aa=a.size(),bb=b.size();
    ll ans=INF64;
    rep(i,n-k+1){
        ll d=x[i],dd=x[i+k-1];
        if(ll(d)*dd<-1ll){
            ans=min({ans,abs(d)*2+dd,abs(d)+2*dd});
        }
        else ans=min(ans,max(abs(d),abs(dd)));
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 2424
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        final int A = Integer.parseInt(sc.next());
        final int B = Integer.parseInt(sc.next());
        long sums = 0;
        
        for (int i = 1; i <= N; i++) {
            int sum = i / 10000 + i / 1000 % 10 + i / 100 % 10 + i / 10 % 10 + i % 10;
            if (sum >= A && sum <= B)   sums += i;
        }
        
        out.println(sums);
        
        out.flush();
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int n;
map<int,int>ma;
int main()
{
    cin>>n;
    int i,x;
    for(i=1;i<=n;i++){
        cin>>x;
        if(++ma[x]>1)break;
    }
    cout<<(i==n+1?"YES":"NO");
    return 0;
}

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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#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 range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define width first
#define depth second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n, w, d; cin >> n >> w >> d, w;){
        vector<pii> cakes;
        cakes.pb(mp(w, d));

        rep(i, n){
            int p, s; cin >> p >> s;
            p--;
            s %= (2 * (cakes[p].width + cakes[p].depth));

            vector<pii> new_cakes;
            if(s < cakes[p].width){
                new_cakes.pb(mp(s, cakes[p].depth));
                new_cakes.pb(mp(cakes[p].width - s, cakes[p].depth));
            }
            else if((s -= cakes[p].width) < cakes[p].depth){
                new_cakes.pb(mp(cakes[p].width, s));
                new_cakes.pb(mp(cakes[p].width, cakes[p].depth - s));
            }
            else if((s -= cakes[p].depth) < cakes[p].width){
                new_cakes.pb(mp(s, cakes[p].depth));
                new_cakes.pb(mp(cakes[p].width - s, cakes[p].depth));
            }
            else{
                s -= cakes[p].width;
                new_cakes.pb(mp(cakes[p].width, s));
                new_cakes.pb(mp(cakes[p].width, cakes[p].depth - s));
            }

            cakes.erase(cakes.begin() + p);

            if(new_cakes[1].width * new_cakes[1].depth < new_cakes[0].width * new_cakes[0].depth){
                swap(new_cakes[0], new_cakes[1]);
            }

            rep(i, 2){
                cakes.pb(new_cakes[i]);
            }
        }

        vi res;
        rep(i, cakes.size()){
            res.pb(cakes[i].width * cakes[i].depth);
        }

        sort(all(res));
        rep(i, res.size()){
            cout << (i ? " ":"") << res[i];
        }
        cout << endl;
    }

	return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
vector<char>v;
string ans;
void dfs(int index,string res,int sum){
    if(res.size()==0){
        sum+=v[0]-'0';
        res.push_back(v[0]);
        dfs(index+1,res+"+",sum);
        dfs(index+1,res+"-",sum);
        return;
    }else if(index==4){
        if(sum==7)ans=res;
        return;
    }
    if(res[(int)res.size()-1]=='+'){
        sum+=v[index]-'0';
        res.push_back(v[index]);
        dfs(index+1,res+"+",sum);
        dfs(index+1,res+"-",sum);
    }else{
        sum-=v[index]-'0';
        res.push_back(v[index]);
        dfs(index+1,res+"+",sum);
        dfs(index+1,res+"-",sum);
    }
    
}
signed main(){
    vector<char>temp(4);
    rep(i,4)cin>>temp[i];
    v=temp;
    string t;
    dfs(0,t,0);
    rep(i,ans.size()-1)cout<<ans[i];
    cout<<"=7";
    cout<<endl;
}


Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let n: usize = get_input().parse().unwrap();

    let mut a = [(0, 0); 2];

    for i in 0..n {
        let j = get_input().parse().unwrap();
        if j > a[0].0 {
            a[1].0 = a[0].0;
            a[1].1 = a[0].1;
            a[0].0 = j;
            a[0].1 = i;
        } else if j > a[1].0 {
            a[1].0 = j;
            a[1].1 = i;
        }
    }

    for i in 0..n {
        println!("{}", if i != a[0].1 { a[0].0 } else { a[1].0 } );
    }
}


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

int n, m;
int w[1010];
int v[1010];
int dp[20005];

int main(void)
{
	cin >> m >> n;
	fill(dp, dp + 20005, 1000000000);
	dp[0] = 0;
	int minn = 1000000, minx = 1000000;
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = w[i]; j <= m + 10000; j++) {
			dp[j] = min(dp[j], dp[j - w[i]] + v[i]);
		}
	}
	int ans = 100000000;
	for(int i=m;i<=m+10000;i++) {
		ans = min(ans,dp[i]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
#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>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

ll dp[100][2];

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    rep(i,100) dp[i][0] = dp[i][1] = -1;
    dp[45][0] = 0;
    for(int d = 44; d >= 0; d--){
        ll mask = 1LL<<d;
        int num = 0;
        rep(i,n) if(a[i] & mask) num++;

        if(dp[d+1][1] >= 0) chmax(dp[d][1], dp[d+1][1] + mask*max(num, n-num));
        if(dp[d+1][0] >= 0){
            if(k & mask){
                chmax(dp[d][1], dp[d+1][0] + mask*num);
                chmax(dp[d][0], dp[d+1][0] + mask*(n-num));
            }
            else{
                chmax(dp[d][0], dp[d+1][0] + mask*num);
            }
        }
    }
    cout << max(dp[0][0], dp[0][1]) << endl;
}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N, K;
    int H[100001];
    cin >> N >> K;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
        if (H[i] >= K) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

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);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll n;



    vector<pair<ll,ll>>p;
void fs(ll a){
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        p.emplace_back(i,cnt);
    }
    return;
}


ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};
int main()
{
 string s,t;
 cin>>s>>t;
 ll sum;
 ll ans=10000;
 rep(i,s.size()-t.size()+1){
     sum=0;
     for(ll j=i;j<i+t.size();j++){
         if(s[j]!=t[j-i])sum++;
     }
     ans=min(ans,sum);
 }
 cout<<ans<<endl;
}
 




Measured memory_bytes: 3604
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)
 
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define repp(i, a, b) for(int i = a; i <= b; i++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, b, a) for(int i = b; i >= a; i--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in_edges(m) repp(i, 1, m){ll a, b; cin >> a >> b; v[a].pb(b), v[b].pb(a);}
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define endl "\n"
ll power(ll x, ll y); 

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    ll a, b, c;
    cin >> a >> b >> c;
    bool b1, b2, b3;
    b1 = (a == b && b != c);
    b2 = (a == c && b != a);
    b3 = (b == c && a != b);

    if(b1 | b2 | b3) cout << "Yes";
    else cout << "No";
    
}
 
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N;
  cin >> N;
  int A, B;
  int sum = 0;
  rep(i, N) {
    cin >> A >> B;
    sum += B - A + 1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,i=0;cin>>N;
  for(;N>=0;N-=4)if(N/3<=i++&&N%3==0)N=-1e7;
  if(N<-9)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
X,Y=map(int,input().split())

if X==1 and Y==1:
    print(1000000)
else:
    ANS=0

    if X==1:
        ANS+=300000
    elif X==2:
        ANS+=200000
    elif X==3:
        ANS+=100000

    if Y==1:
        ANS+=300000
    elif Y==2:
        ANS+=200000
    elif Y==3:
        ANS+=100000

    print(ANS)


Measured memory_bytes: 3316