akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}

inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

constexpr int mod = 1e9 + 7;
std::vector<std::vector<int>> Edge;
std::vector<int> Depth;
std::vector<int> ParSize;
std::vector<lli> White, Black;

int main(void){
    int n; scanf("%d", &n);
    Edge.resize(n);
    for(int _ = 1; _ < n; ++_){
        int a, b; scanf("%d%d", &a, &b); a--; b--;
        Edge[a].push_back(b); Edge[b].push_back(a);
    }
    Depth.assign(n, -1); ParSize.assign(n, 0);
    std::queue<int> Q; Q.push(0); Depth[0] = 0;
    while(not Q.empty()){
        int v = Q.front(); Q.pop();
        for(int nv : Edge[v]) if(Depth[nv] == -1){
            Depth[nv] = Depth[v] + 1; ParSize[v]++;
            Q.push(nv);
        }
    }
    White.assign(n, 1); Black.assign(n, 1);
    std::stack<int> Stk;
    REP(i, n) if(ParSize[i] == 0){White[i] = 1; Black[i] = 1; Stk.push(i);}

    while(not Stk.empty()){
        int v = Stk.top(); Stk.pop();
        for(int par : Edge[v]) if(Depth[par] < Depth[v]){
            (White[par] *= (White[v] + Black[v])) %= mod;
            (Black[par] *=  White[v]) %= mod;
            if((--ParSize[par]) == 0) Stk.push(par);
            break;
        }
    }
    printf("%lld\n", (White[0] + Black[0]) % mod);




    


    

    
    
    return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>

int main(void){
  int i,a,b;
  int c,count;
  count=0;
  while((scanf("%d %d",&a,&b)==2)){
    c=a+b;
    while(1){
      c=c/10;
      count++;
      if(c==0)break;
    }
    printf("%d\n",count);
    count=0;
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define forit(it, st) for(auto it : st)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
ll xr[N][62][2], sum[62][2];
void solve(){
	int n;
	cin >> n;
	ll a[n];
	rep(i, n){
		cin >> a[i];
		ll q = a[i];
		int p = 62, cc = 0;
		while(p--){
			xr[i][cc][q % 2]++;
			sum[cc++][q % 2]++;
			q /= 2;
		}
	}
	ll res = 0;
	rep(i, n){
		ll mul = 1;
		for(int j = 0; j < 62; ++j){
			for(int k = 0; k < 2; ++k){
				if(xr[i][j][k]){
					sum[j][k] -= xr[i][j][k % 2];
					res += (sum[j][k ^ 1]) * mul;
					mul *= 2;
					mul %= mod;
					res %= mod;
				}
			}
		}
	}
	cout << res;

}
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}


Measured memory_bytes: 293248
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    int chk = -1;
    int pnt = 0;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);

    for(int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    
    for(int i = 0; i < n; i++) {
        cin >> b.at(i);
    }

    for(int i = 0; i < n-1; i++) {
        cin >> c.at(i);
    }

    for(int i = 0; i < n; i++) {
        int x = a.at(i) - 1;
        pnt += b.at(x);
        if(x - 1 == chk && x != 0) {
            pnt += c.at(x - 1);
        }
        chk = x;

    }
    
    cout << pnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    char tmp = s[0];
    int ans = 1;
    rep(i, n){
        if (tmp != s[i]){
            ans++;
            tmp = s[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


char *cs = "CODEFESTIVAL2016";
int main(void){
	char s[20];
	scanf("%s",s);
	int n=0;
	rep(i,16){
		if(s[i]!=cs[i])n++;
	}
	printf("%d\n",n);
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, odd = 0, even = 0;
	int num;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> num;
		if(num % 2) {
			odd++;
		} else {
			even++;
		}
	}

	even += odd / 2;
	odd %= 2;

	if(odd) {
		cout << "NO" << endl;
	} else {
		cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] a){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		for(int i = 0; i < N; i++){
			int d = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt();
			if(d > b){
				int multi = d;
				d = b;
				b = multi;
			}
			if(b > c){
				int multi = b;
				b = c;
				c = multi;
			}
			if(d * d + b * b == c * c) System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23544
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
int main(void){
    string N;
    cin>>N;
    if(N.at(0)==N.at(1) && N.at(1)==N.at(2))cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int A[101];
    int left=0,right=0;
    
    for(int i=0; i < M; i++)
    {
        cin >> A[i];
        
        if( X > A[i] )
            left++;
        else
            right++;
    }

    cout << min(left,right) << endl;

    return 0;
}

Measured memory_bytes: 256
// ahmed mohamed hanfy 
// 19-4-2018 
//virual contest vjudge c problem

#include <bits/stdc++.h>
// #include <sstream>
// #include<vector>

#define lp(i,n)     for(int i=0 ; i <  n  ; ++i)
#define lp_1(i,n)   for(int i=1 ; i <= n ; ++i)
#define Rlp(i,n)    for(int i=n; i>=0 ; --i)
// #define _lp(i,j,n) for(int i=j; i<=n ; ++i)
#define pb push_back
#define mp make_pair


using namespace std;

typedef long long ll;
typedef set <int>          seti;
typedef set <ll>          setll;
typedef set <char>          setC;
typedef long double   	    ld;
typedef vector<int>         vi;
typedef vector<double>      vd;
typedef vector < vi >       vvi;
typedef vector < vd >       vvd;
typedef vector <string>     vs;
const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int i=0,j=0;
    if(a ==5)  i++;
    if(b==5) i++;
    if(c==5) i++;
    if(a ==7)  j++;
    if(b==7) j++;
    if(c==7) j++;
    if(i ==2 && j==1){cout<<"YES"<<endl; return 0;}
    else {
        cout<<"NO"<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...)
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)

#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 2000010

template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}

//FILE* outFile;

inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int main(){
    int j,k,i,T,ca=0,n,K=0,m;
    int r,g,b, ans = 0;
    scanf("%d%d%d%d", &r, &g, &b, &n);
    rep(i, 0, n+1){
        if(i * r > n)break;
        rep(j, 0, n-i+1){
            K = i * r + j * g;
            if(K > n)break;
            if((n - K) % b == 0)ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    const MAX: usize = 100_000;
    let is_prime = enumerate_primes(MAX);
    let mut s: Vec<usize> = vec![0; MAX + 1];
    let mut i = 3;
    while i <= MAX {
        if is_prime[i] && is_prime[(i + 1) / 2] {
            s[i] = s[i - 2] + 1;
        } else {
            s[i] = s[i - 2];
        }
        i += 2;
    }

    let q: usize = iterator.next().unwrap().parse().unwrap();
    let mut result = String::new();
    for _ in 0..q {
        let l: usize = iterator.next().unwrap().parse().unwrap();
        let r: usize = iterator.next().unwrap().parse().unwrap();

        let sl = if l == 1 {
            0
        } else {
            s[l - 2]
        };
        let sr = s[r];
        result.push_str(&format!("{}\n", sr - sl));
    }
    return result.trim().to_string();
}

fn enumerate_primes(n: usize) -> Vec<bool> {
    let mut is_prime = vec![true; n + 1];
    is_prime[0] = false;
    is_prime[1] = false;

    let mut i = 2;
    while i * i <= n {
        if is_prime[i] {
            let mut j = i * 2;
            while j <= n {
                is_prime[j] = false;
                j += i;
            }
        }
        i += 1;
    }

    return is_prime;
}


Measured memory_bytes: 8700
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
const int N = 100005;
int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t;cin>>t;while(t--)
    {
        int i, j, k, n, m,a,b,c,d, ans = 0, cnt = 0, sum = 0;
        cin >> a >> b >> c >> k;
        if(a+b >= k){
            ans = min(a,k) ;
        }else{
            k -= b;
            ans += a;
            k -= a;
            ans -= k ;
        }
        cout << ans ;
        
    }
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		System.out.println(calcNumOfCombination(N, 2)+calcNumOfCombination(M, 2));

		}
	 public static int calcNumOfCombination(int n, int r){
	        int num = 1;
	        for(int i = 1; i <= r; i++){
	            num = num * (n - i + 1) / i;
	        }
	        return num;
	    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin >> n;
		int a[n+1];
		rep(i,1,n+1) cin >> a[i];
		int dp[n+1][n+1];
		rep(i,0,n+1){
			rep(j,0,n+1){
				dp[i][j] = -INF;
			}
		}
		rep(i,1,n+1) dp[i][i] = a[i];
		rep(gap,1,n){
			rep(i,1,n-gap+1){
				int j = i+gap;
				dp[i][j] = max(a[i]-dp[i+1][j], a[j]-dp[i][j-1]);
			}
		}
		cout<<dp[1][n];
	}
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
	//freopen("in.txt", "r", stdin);
	int n, m, q;
    cin >> n >> m >> q;
    int a[505][505];
    memset(a, 0, sizeof(a));
    rep(i,0,m) {
        int l, r;
        cin >> l >> r;
        a[l][r]++;
    }

    rep(i,0,501) {
        rep(j,1,501) {
            a[i][j] = a[i][j-1] + a[i][j];
        }
    }
    rep(i,0,501) {
        rep(j,1,501) {
            a[j][i] = a[j-1][i] + a[j][i];
        }
    }

    rep(i,0,q) {
        int l, r;
        cin >> l >> r;
        int ret = a[500][r] - a[l-1][r];
        cout << ret << '\n';
    }
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 2e5+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;

int x, y;
int main() {
	scanf("%d%d", &x, &y);
	for (int i = 0; i <= x; i++) {
		int j = x - i;
		if (i * 2 + j * 4 == y) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}



Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
int d[4][2]={1,0,0,1,-1,0,0,-1};
ll a[maxn];
int main() {
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    map<ll,ll> ma;
    ll ans=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        ma[i-a[i]]++;
    }
    for(int i=1;i<=n;i++){
        ans+=ma[i+a[i]];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int sum=0,A[101],N;
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];

    for(int i=0;i<N-1;i++){
        int minj = i;
        for(int j = i+1;j<N;j++){
            if (A[j] < A[minj]){
                minj = j;
            }
        }
        if(minj!=i){
            swap(A[i],A[minj]);
            sum++;
        }
    }
    
    for(int i=0;i<N;i++){
        if(i) cout << " ";
        cout << A[i] ;
    }
    cout << endl;
    cout << sum << endl;
    return 0;
}


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

int fab,fbc,fcd;
int main(){
  int n;
  cin>>n;
  ll a,b,c;
  cin>>a>>b>>c;
  
  if(a+b+c==0){
    puts("No");
    return 0;
  }
  vector<string> s(n);
  rep(i,n) cin>>s[i];
  string ans;
  rep(i,n){
    if(s[i]=="AB"){
      if(a==0&&b==0){
	puts("No");
	return 0;
      } 
      if(a<b){
	ans+='A';
	a++;
	b--;
      }
      else if(a>b){
	ans+='B';
	b++;
	a--;
      }
      else{
	if(i<=n-1&&s[i+1]=="AC"){
	  ans+='A';
	  a++;
	  b--;
	}
	else if(i<=n-1&&s[i+1]=="BC"){
	  ans+='B';
	  b++;
	  a--;
	}
	else{
	  ans+='B';
	  b++;
	  a--;
	}
      }
    }
    if(s[i]=="AC"){
      if(a==0&&c==0){
	puts("No");
	return 0;
      } 
      if(a<c){
	ans+='A';
	a++;
	c--;
      }
      else if(a>c){
	ans+='C';
	c++;
	a--;
      }
      else{
	if(i<=n-1&&s[i+1]=="AB"){
	  ans+='A';
	  a++;
	  c--;
	}
	else if(i<=n-1&&s[i+1]=="BC"){
	  ans+='C';
	  c++;
	  a--;
	}
	else{
	  ans+='C';
	  c++;
	  a--;
	}
      }
    }
    if(s[i]=="BC"){
      if(c==0&&b==0){
	puts("No");
	return 0;
      } 
      if(c<b){
	ans+='C';
	c++;
	b--;
      }
      else if(c>b){
	ans+='B';
	b++;
	c--;
      }
      else{
	if(i<=n-1&&s[i+1]=="AC"){
	  ans+='C';
	  c++;
	  b--;
	}
	else if(i<=n-1&&s[i+1]=="AB"){
	  ans+='B';
	  b++;
	  c--;
	}
	else{
	  ans+='B';
	  b++;
	  c--;
	}
      }
    }
  }
  puts("Yes");
  rep(i,ans.size()) cout<<ans[i]<<endl;
  return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }

constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};

int main(){
    int N,x;cin>>N>>x;
    if(x==1 or x==2*N-1){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    int n=2*N-1;
    if(N==x){
        rep(i,n) cout << i+1 << endl;
        return 0;
    }else if(N<x){
        rep(i,N-1) cout << i+1 << endl;
        int dif = x-N;
        rep(i,N-dif) cout << x + i << endl;
        rep(i,dif) cout << N + i << endl;
    }else{
        int dif=N-x;
        rep(i,dif) cout << x+1+i << endl;
        rep(i,N-dif) cout << i+1 << endl;
        for(int i=N;i<n;i++) cout << i+1 << endl;
    }
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
long long arr[1000007];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long n,i,j,k,x,y,z;
    x=0;
    cin>>n;
    for (i=1;i<n;i++)
    {
    	if (n%i==0)
    	{
    		x=x+n/i -1;
		}
		else
		{
			x=x+n/i;
		}
	}
	cout<<x<<endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
const long long inf=1e9+7;
const int maxn=1e6;
int n;
int a[maxn+5];
int gcd(int a,int b){
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int tot=0;
bool used[maxn+5];
int fen(int x){
	int sqr=sqrt(x);
	for(int i=2;i<=sqr;i++){
		if(x%i==0){
			if(used[i])return 0;
			used[i]=1;
		}
		while(x%i==0){
			x/=i;
		}
	}
	if(x!=1){
		if(used[x])return 0;
		used[x]=1;
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int ans=1;
	for(int i=1;i<=n;i++){
		if(!fen(a[i])){
			ans=0;
			break;
		}
	}
	if(ans==1){
		printf("pairwise coprime");
		return 0;
	}
	ans=a[1];
	for(int i=2;i<=n;i++){
		ans=gcd(ans,a[i]);
	}
	if(ans==1){
		printf("setwise coprime");
		return 0;
	}
	printf("not coprime");
	return 0;
}

Measured memory_bytes: 7688
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  int n ;
  cin >> n ;
  vector<int> num(n) ;
  REP(i,n){
    cin >> num.at(i) ;
  }
  
  int ans = 0 ;
  
  int i=1 ;
  while(i<n){
    if(num.at(i-1)==num.at(i)){
      ans++ ;
      i += 2 ;
    }
    else{
      i++ ;
    }
  }
  
  cout << ans <<endl ;


  return 0 ;
}





Measured memory_bytes: 256
import sys
import copy
s = int(input())

def f(n):
    if n%2==0:
        return int(n/2)
    else:
        return 3*n+1

for i in range(1000000):
    if i == 0:
        a=[s]
    else:
        a.append(f(a[i-1]))
    
    if a.count(a[i]) == 2:
        print(i+1)
        sys.exit(0)


Measured memory_bytes: 9332
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
map<P,P> mp;
map<P,int> vis;
bool dfs(P p,int c){
	P q=mp[p];
	vis[p]=c;
	if(vis[q]==0){
		bool b=dfs(q,-c);
		if(!b) return 0;
	}
	rep(i,4){
		P np=P(p.fs+dx[i],p.sc+dy[i]);
		if(np==q||!mp.count(np)) continue;
		if(vis[np]!=0){
			if(vis[np]!=c) return 0;
		}else{
			bool b=dfs(np,c);
			if(!b) return 0;
		}
	}
	return 1;
}
int main(){
	while(true){
		int N;
		cin>>N;
		if(N==0) break;
		mp.clear();
		vis.clear();
		rep(i,N){
			int x,y;
			char c;
			cin>>x>>y>>c;
			P p=P(x,y);
			if(c=='x'){
				P q=P(x+1,y);
				mp[p]=q,mp[q]=p;
			}else{
				P q=P(x,y+1);
				mp[p]=q,mp[q]=p;
			}
		}
		bool ok=1;
		for(auto pp:mp){
			P p=pp.fs;
			if(vis[p]!=0) continue;
			if(!dfs(p,1)) ok=0;
		}
		if(ok) puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 12396
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
a,b,c,d=map(int,input().split())
ans=max(a*c,b*d,b*c,a*d)
print(ans)

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

int main() {
  string S;
  cin >> S;
  int count=0;
  
  for(int i=0; i<S.size(); i++) {
    if(i%2==0) {
      if(S.at(i)=='L') {
        count++;
        break;
      }
    }
    else if(i%2==1) {
      if(S.at(i)=='R') {
        count++;
        break;
      } 
    }
  }
  if(count==0) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;
     
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
     
    for(int i=0;i<n;i++){
         
        int j=i;
        while(j>0 && a[j-1]>a[j]){
            swap(a[j-1],a[j]);
            j--;
        }
      
        for(int j=0;j<n-1;j++) cout<<a[j]<<" ";
        cout<<a[n-1]<<endl;
    }
     
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>

int main()
{
	char aa, ba, ca, da;
	std::cin >> aa >> ba >> ca >> da;
	
	int a = aa - '0', b[4];
	b[0] = ba - '0';
	b[1] = ca - '0';
	b[2] = da - '0';
	int sum = a;
	
	for (int i = 0; i < 8; ++i)
	{
		int curSum = sum;
		for (int j = 0; j < 3; ++j)
		{
			if (i & (1 << j))
			{
				curSum += b[j];
			}
			else
			{
				curSum -= b[j];
			}
		}
		
		if (curSum == 7)
		{
			std::cout << a;
			for (int j = 0; j < 3; ++j)
			{
				if (i & (1 << j))
					std::cout << "+" << b[j];
				else
					std::cout << "-" << b[j];
			}
			
			std::cout << "=7";
			return 0;
		}
	}
}

Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C (GCC 5.4.1)
*/

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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(void)
{
	int k,t,a;
	int max = 0;
	scanf("%d %d", &k,&t);
	for(int i = 0; i < t; ++i){
		scanf("%d", &a);
		max = (max > a) ? max : a;
	}
	printf("%d\n",
		(max - 1 - (k - max) > 0) ? (max - 1 - (k - max)) : 0);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (1000000007)
#define N (100010)
int n,ans,h[N],dp[N];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&h[i]);
	for (int i=n;i>=1;--i){
		if (h[i]>=h[i+1]) dp[i]=dp[i+1]+1;
		else dp[i]=1;
		ans=max(ans,dp[i]);
	}
	printf("%d",ans-1);
		
}


Measured memory_bytes: 1024
S = input()
d = {}

for i in range(ord("a"), ord("z") + 1):
    d[chr(i)] = False

for c in S:
    d[c] = True

ans = "None"
for i in range(ord("a"), ord("z") + 1):
    if not d[chr(i)]:
        ans = chr(i)
        break
print(ans)


Measured memory_bytes: 3188
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

typedef std::vector<int> vec;

bool power_of_2(int n) {
    return (n & (n - 1)) == 0;
}

int max_divisor(int n) {
    return n & -n;
}

int g(const vec& sequence) {
    int sum = 0;
    for (int i = 0; i < sequence.size(); i++) {
        sum += sequence[i];
    }

    vec table(sum + 1);
    std::fill(table.begin() + 1, table.end(), -1);
    table[0] = 0;

    sum = 0;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        for (int a = sum & -x; a >= 0; a -= x) {
            if (table[a] >= 0) {
                int b = a + x;
                table[b] = std::max(table[a] + 1, table[b]);
            }
        }
        sum += sequence[i];
    }

    int max = 0;
    for (int i = 1; i <= sum; i <<= 1) {
        max = std::max(max, table[i]);
    }
    return max;
}

vec extract(const vec& sequence, int k) {
    vec subsequence;
    int min = INT_MAX;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        if (x % k == 0 && power_of_2(x / k)) {
            subsequence.push_back(x);
            min = std::min(min, x);
        }
    }
    for (int i = 0; i < subsequence.size(); i++) {
        subsequence[i] /= min;
    }
    return subsequence;
}

int f(const vec& sequence) {
    vec numbers;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        numbers.push_back(x / max_divisor(x));
    }
    std::sort(numbers.begin(), numbers.end());
    numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end());

    int max = 0;
    for (int i = 0; i < numbers.size(); i++) {
        int k = numbers[i];
        const vec& subsequence = extract(sequence, k);
        max = std::max(max, g(subsequence));
    }
    return max;
}

int main() {
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        vec sequence(n);
        for (int i = 0; i < n; i++) {
            std::cin >> sequence[i];
        }
        std::cout << f(sequence) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3568
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = IntRead();
        int[] box = SpRead(' ').Select(int.Parse).ToArray();
        var sorted = box.OrderBy(v => v);
        int[] pf = new int[N];
        int i = 1;
        if (N % 2 == 1) { pf[0] = 0; i = 2; }
        for (; i < N; i += 2) pf[i - 1] = pf[i] = i;
        long ans = 0;
        if (pf.SequenceEqual(sorted))
        {
            int M = (N % 2 == 0 ? N : N - 1) / 2;
            ans = 1;
            for (i = 0; i < M; i++) {
                ans *= 2;
                ans %= INF;
            }
        }
        Console.WriteLine(ans);
    }
}

public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static long[] LSRead()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
}


Measured memory_bytes: 19936
#include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


void printv(vvi v){
	for(int i = 0; i < v.size(); i++){
		for(int j = 0; j < v.size(); j++){
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	return ;
}


signed main() {
	
	cin1(n);

	vi p(n+2);
	rep(i,1,n+1) {
		cin2(p[i-1],p[i]);
	}

	
	vvi dp(n,vi(n,0));
	for (int i = 2; i <= n; i++) { //???????????°
		for (int j = 0; j < n - i + 1; j++) { //??´???(??????)
			dp[j][j+i-1] = INF;
			for (int k = j; k < j + i - 1; k++ ) { //?????????
				dp[j][j+i-1] = min(dp[j][j+i-1],dp[j][k] + dp[k+1][j+i-1] + p[j] * p[k+1] * p[j+i]);
			}
		}
	}
	//printv(dp);
	cout(dp[0][n-1]);
		
	return 0;
}

Measured memory_bytes: 3136
n, m, l = [int(i) for i in input().split()]

A = []
B = []
C = []

for ni in range(n):
    A.append([int(i) for i in input().split()])

for mi in range(m):
    B.append([int(i) for i in input().split()])

for i in range(n):
    C.append([])
    for j in range(l):
        C[i].append(0)
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]

for ni in range(n):
    print(" ".join([str(s) for s in C[ni]]))

Measured memory_bytes: 8884
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

int main(){
	int n, k;
	int sum = 0;
	scanf("%i %i", &n, &k);
	int a[n];
	for(int i = 0; i < n; i++){
		scanf("%i", &a[i]);
	}
	int tmp;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			if(a[i] > a[j]){
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}

	for(int i = 0; i < k; i++){
		sum += a[i];
	}

	printf("%i\n", sum);
	return 0;
}

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> PII;
typedef pair <long long,long long> PLL;

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

#define PI              acos(-1.0)

int setBit(int n,int pos) { return n = n | (1 << pos); }
int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
bool checkBit(ll n,ll pos) { return (bool)(n & (1LL << pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction

/******************************************************************************************/

const int MAX = 100010;
const int INF = 2000000000;
//const int MOD = 1000000007;

int ara[MAX];

int main() {
//    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int ans = INF,cnt;
    int n,k;
    sii(n,k);
    for(int i=1;i<=n;i++) {
        si(ara[i]);
    }

    int tt;

    for(int i=1;i<=k;i++) {
        cnt = 1;
        tt = n - k;
        if(n>0) {
            cnt += (tt/(k-1));
            if(tt % (k-1)!=0) cnt++;
        }
        ans = min(ans,cnt);
    }

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

    return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int K;
    cin >> K;
    if(K%2==0) cout << K*K/4 << endl;
    else cout << (K/2)*(K/2+1) << endl;
}

Measured memory_bytes: 256
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AtCoder
{
    class Program
    {
        private static long mod = 1000000007;
        static void Main(string[] args)
        {
            //var n = int.Parse(ReadLine());
            var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();

            var n = line[0];
            var d = line[1];
            var d2 = d * d;
            var count = 0;
            for(var i = 0; i < n; i++)
            {
                var pos = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
                if(d2 >= pos[0] * pos[0] + pos[1] * pos[1])
                {
                    count++;
                }
            }

            WriteLine(count);
        }
    }
}


Measured memory_bytes: 41160
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int lim = 55555;
    vector<char> prime(lim + 1, true);
    prime[0] = prime[1] = false;
    for(int i = 2; i <= lim; i++){
        if(prime[i]){
            for(int j = i + i; j <= lim; j += i){
                prime[j] = false;
            }
        }
    }
    int cnt = 0;
    for(int i = 2; i <= lim && n; i++){
         cnt += prime[i] && i % 5 == 1;
         if(prime[i] && i % 5 == 1){
             cout << i << ' ';
             n--;
         }
    }
}


Measured memory_bytes: 256
def threeArea(w, h, ans):
  for i in range(1, h):
    recA = w * i
    width = w//2
    recB = (h-i) * width
    recC = w * h - recA - recB
    diff = max(recA, recB, recC) - min(recA, recB, recC)
    
    height = (h - i) //2
    recB = w * height
    recC = w * h - recA - recB
    diff = min(diff, max(recA, recB, recC) - min(recA, recB, recC))
    if ans > diff:
      ans = diff
  return ans

H, W = (int(i) for i in input().split())
 
ans = float('inf')
ans = threeArea(W, H, ans)
ans = threeArea(H, W, ans)
 
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <deque>
#include <vector>
#include <string>
using namespace std;
void print_table(vector<vector<char> > table){
  for(int i = 0; i < table.size(); ++i){
    for(int j = 0; j < table[i].size(); ++j){
      cout << table[i][j];
    }
    cout << endl;
  }
}  
int main(){
  int n;
  while(true){
    cin >> n;
    if(n == 0){
      break;
    }
    vector<vector<char> > table;
    for(int i = 0; i < n; ++i){
      string tmp;
      cin >> tmp;
      const char *tmp_arr = tmp.c_str();
      vector<char> arr;
      for(int j = 0; tmp_arr[j] != '\0'; ++j){
        arr.push_back(tmp_arr[j]);
      }
      while(arr.size() <= 51){
        arr.push_back('*');
      }
      table.push_back(arr);
    }
    for(int i = 1; i < n; ++i){
      for(int j = 0; j < table[i].size()-1; ++j){
        if(table[i][j+1] != '.'){
          table[i][j] = '+';
          break;
        }
      }
    }
    for(int i = n-2; i > 0; --i){
      for(int j = 0; j < table[i].size(); ++j){
        if(table[i][j] != '.'){
          continue;
        }
        if(table[i+1][j] == '+' || table[i+1][j] == '|'){
          table[i][j] = '|';
        }
        else{
          table[i][j] = ' ';
        }
      }
    }
    for(int i = 0; i < table[n-1].size(); ++i){
      if(table[n-1][i] == '.'){
        table[n-1][i] = ' ';
      }
    }
    for(int i = 1; i < n; ++i){
      for(int j = 0; j < table[i].size(); ++j){
        if(table[i][j] != '|'){
          continue;
        }
        if(table[i-1][j] != '+' && table[i-1][j] != '|'){
          table[i][j] = ' ';
        }
      }
    }
    for(int i = 0; i < n; ++i){
      while(table[i].back() == '*'){
        table[i].pop_back();
      }
    }
    print_table(table);
  }
  return 0;
}

Measured memory_bytes: 2324
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ff first
#define ss second
#define input(a) scanf("%lld",&a)
#define M 1000000007
#define inf 1<<30

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;

ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    return gcd(b%a,a);
}

ll bigMod(ll base,ll power)
{
    if(power==0)
        return 1;
    ll x=bigMod(base,power/2);
    x=(x*x)%M;
    if(power&1)
        x=(x*base)%M;
    return x;
}

ll n,m,u,v,flg[100100],par[100100];

vector<ll>lst[100100];
stack<ll>tp;

void dfs(int n)
{
    if(flg[n])
        return;
    flg[n]=1;
    for(int i=0;i<lst[n].size();i++)
        dfs(lst[n][i]);
    tp.push(n);
}

int main()
{
    cin>>n>>m;
    for(int i=1;i<n+m;i++){
        cin>>u>>v;
        lst[u].push_back(v);
    }
    for(int i=1;i<=n;i++)
        dfs(i);
    while(!tp.empty()){
        v=tp.top();
        for(int i=0;i<lst[v].size();i++)
            par[lst[v][i]]=v;
        tp.pop();
    }
    for(int i=1;i<=n;i++)
        cout<<par[i]<<endl;
    return 0;
}



Measured memory_bytes: 11676
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
int main(){

	int n;
	int x[51], y[51];
	int count = 1;
	while(cin >> n && n != 0){
		double ans=0;
		for(int i=0; i<n; ++i){
			cin >> x[i] >> y[i];

		}
		for(int i=0; i<n; ++i){
			int j=i, k=i+1;
			if(i==n-1) k=0;
			ans += x[j]*y[k] - x[k]*y[j];
		}
		ans = fabs(ans)/2;
		printf("%d %.1f\n", count, ans);
		count++;
	}

	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    Fr(i,5){
        int x;
        cin>>x;
        if(!x) return cout<<i<<'\n',0;
    }
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dp[510];
int n;
int a[510][510];
void solve(int l, int r, int d){
	int x=r-l+1;
  if(x==1) return;
	if(x==2){
		a[l][r]=d;
		return;
	}else if(x==3){
		a[l][l+1]=a[l+1][l+2]=d;
		a[l][l+2]=d+1;
		return;
	}
	int k;
	for(int i=1; i<=x-1; i++){
		if(dp[x]==max(dp[i], dp[x-i])+1){
			k=i;
			break;
		}
	}
	for(int i=l; i<=l+k-1; i++){
		for(int j=l+k; j<=r; j++){
			a[i][j]=d;
		}
	}
	solve(l, l+k-1, d+1);
	solve(l+k, r, d+1);
}
int main()
{
	cin>>n;
	dp[1]=dp[2]=1;
	dp[3]=2;
	for(int i=4; i<=n; i++){
		dp[i]=dp[i-1]+1;
		for(int j=1; j<=i-1; j++){
			dp[i]=min(dp[i], max(dp[j], dp[i-j])+1);
		}
	}
	solve(1, n, 1);
	for(int i=1; i<=n-1; i++){
		for(int j=i+1; j<=n; j++){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1536
# Atcoder Problem Solving
# F - Takahashi's Basics in Education and Learning
import math
L, A, D, mod = map(int, input().split())
que = []

ans = 0
# 1桁、......20桁のグループに分類する
for i in range(1, 22):
    #10**(i-1) <= A+D*(j) < 10**(i)
    if (10**(i-1)-A+D) % D == 0:
        lowest = max(1, (10**(i-1)-A+D)//D)
    else:
        lowest = max(1, (10**(i-1)-A+D)//D+1)
    highest = 0
    if (10**i-A+D) % D == 0:
        highest = min((10**i-A+D)//D-1, L)

    else:
        highest = min((10**i-A+D)//D, L)

    if 1 <= lowest <= highest:
        que.append((i, lowest, highest))


def poly_sum(X, N, mod):
    # return X^N +    .... X^1+1 mod
    # O(logN)
    if N == 0:
        return 1
    if N == 1:
        return (X+1) % mod
    else:
        if N % 2 == 0:
            tmp_res = poly_sum(X, N//2, mod)
            return ((pow(X, N//2, mod)+1)*tmp_res-pow(X, N//2, mod)) % mod

        elif N % 2 != 0:
            tmp_res = poly_sum(X, N//2, mod)
            return (pow(X, N//2+1, mod)+1)*tmp_res % mod


def sum_of_poly_sum(X, N, mod):
    # return poly_sum(X,N,mod)+ poly_sum(X,N-1,mod) +poly_sum(X,N-2,mod) +.....  + poly_sum(X,1,mod) + poly_sum(X,0,mod)
    # O(logN*logN)
    if N == 0:
        return poly_sum(X, 0, mod)
    elif N == 1:
        return (poly_sum(X, 1, mod)+poly_sum(X, 0, mod)) % mod
    else:
        return ((sum_of_poly_sum(X, (N-1)//2, mod))*(pow(X, N//2+1, mod)+1)+(N//2+1)*poly_sum(X, N//2, mod)) % mod


def find_mod(length, lowest, highest, mod):
    # length 桁　の lowest 項目から highest 項目における連結巨大数のmodular
    X = pow(10, length, mod)
    if highest > lowest:
        base = (A+D*(lowest-1))*poly_sum(X, highest-lowest, mod) + \
            D*sum_of_poly_sum(X, highest-lowest - 1, mod)
    elif highest == lowest:
        base = A+D*(lowest-1)
    return base % mod


que.reverse()

digits = 0
for length, lowest, highest in que:
    ans += find_mod(length, lowest, highest, mod)*pow(10, digits, mod)
    ans %= mod
    digits += length*(highest+1-lowest)

print(ans % mod)


Measured memory_bytes: 75772
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define EQ(a,b) (abs((a)-(b))<EPS)
int seg[(1<<21)-1];
void add(int m,int score)
{
	m+=(1<<20)-2;
	seg[m]+=score;
	while(m>0)
	{
		m=(m-1)/2;
		seg[m]=max(seg[m*2+1],seg[m*2+2]);
	}
	return;
}
int find()
{
	int res=0;
	while(res<(1<<20)-1)
	{
		if(seg[0]==seg[res*2+1])res=res*2+1;
		else res=res*2+2;
	}
	return res-(1<<20)+2;
}
int main()
{
	int n,q;
	cin >> n >> q;
	for(int i=0;i<q;i++)
	{
		int a,v;
		cin >> a >> v;
		add(a,v);
		cout << find() << ' ' << seg[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 9272