akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  char a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  int count=0;
  for(int i=0;i<n;i++){
    if(a[i]!=a[i+1])   count++;
  }
  if(count==3)  cout<<"Three"<<endl;
  if(count==4)  cout<<"Four"<<endl;
  return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);

    int counter = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> h.at(i);
        if (k <= h.at(i))
        {
            counter++;
        }
    }
    cout << counter << endl;
}


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

int main() {
	char zu[8][8];

	while (cin >> zu[0]) {
		for (int i = 1;i < 8;i++)cin >> zu[i];

		int a, b;
		for (int i = 0;i < 8;i++) {
			for (int j = 0;j < 8;j++) {
				if (zu[i][j] == '1') {
					a = i;
					b = j;
					goto FIN;
				}
			}
		}
		FIN:

		if (a<=6&&b<=6&&zu[a][b] == zu[a][b + 1] &&zu[a][b]== zu[a + 1][b] &&zu[a][b]== zu[a + 1][b + 1])cout << 'A' << endl;
		else if (a<=4&&zu[a][b] == zu[a + 1][b]&&zu[a][b] == zu[a + 2][b] && zu[a][b] == zu[a + 3][b])cout << 'B' << endl;
		else if (b <= 4 && zu[a][b] == zu[a][b + 1] && zu[a][b] == zu[a][b + 2] && zu[a][b] == zu[a][b + 3])cout << 'C' << endl;
		else if (b >= 1 && a <= 5 && zu[a][b]== zu[a + 1][b] && zu[a][b] == zu[a + 1][b - 1] && zu[a][b] == zu[a + 2][b - 1])cout << 'D' << endl;
		else if (b <= 5 && zu[a][b] == zu[a][b + 1] && zu[a][b] == zu[a + 1][b + 1] && zu[a][b] == zu[a + 1][b + 2])cout << 'E' << endl;
		else if (a <= 5 && zu[a][b] == zu[a + 1][b] && zu[a][b] == zu[a + 1][b + 1] && zu[a][b] == zu[a + 2][b + 1])cout << 'F' << endl;
		else cout << 'G' << endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    ll K, A, B;
    cin >> K >> A >> B;
    ll ans = 1;
    if(A > B - 2){
        ans += K;
    }else{
        if(A + 1 <= K){
            ll leave = K - (A - 1); //ビスケットの数がA枚にたどりついたときに残っている実行可能回数
            ll cycle = leave / 2;
            ll pan = leave % 2;
            ans = A + (B - A) * cycle + pan;
        }else{
            ans += K;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,A,B = map(int,input().split())
if (B-A)%2==0:
    print(str(int(B-(B+A)//2)))
else:
    if N-B>A-1:
        print(str(int(A+(B-A-1)//2)))
    else:
        print(str(int(N-B+1+(B-A-1)//2)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

int main()
{
    fastio;
    int n;
    cin >> n;
    
    bool ok = true;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if (x % 2 == 0 && !(x % 5 == 0 || x % 3 == 0))
            ok = false;
    }

    if (ok)
        cout << "APPROVED";
    else
        cout << "DENIED";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL <<60;
int chmin(int i,int j){if(i<=j){return i;}
                       else{return j;}}
int main(){
  int n; cin >> n;
  int i,j;
  vector<int> dp(n+1,0);//dp[i]はi円取り出すのに必要な最低回数。
  for(i=0;i<=n;i++){dp[i]=i;}
  for(i=1;i<n+1;i++){
    for(j=1;j<i;j++){
      if(i-pow(6,j)>=0){dp[i]=chmin(dp[i],dp[i-pow(6,j)]+1);}
      else{break;}}
    for(j=1;j<i;j++){
      if(i-pow(9,j)>=0){dp[i]=chmin(dp[i],dp[i-pow(9,j)]+1);}
      else{break;}}
  }
  cout<<dp[n]<<endl;
  return 0;
}
      
    
  


Measured memory_bytes: 640
#include<cstdio>

int main(){
    int count[1201];
    char ch;
    while(scanf("%c",&ch) != EOF){
        if(ch >= 'a' && ch <= 'z'){
            count[ch - 'a']++;
        }
        else if(ch >= 'A' && ch <= 'Z'){
            count[ch - 'A']++;
        }
    }
    for(int j = 0;j < 26; j++){
        printf("%c : %d\n",j + 'a',count[j]);
    }
    return 0;
}


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

using namespace std;

class Point{
    public:
    int x;
    int y;
    Point(){x=0;y=0;}
    Point(int a,int b){x=a;y=b;}
    Point& operator =(const Point& in){this->x=in.x;this->y=in.y;return *this;}
};

int main(){
    Point s,t,n;
    cin>>s.x>>s.y>>t.x>>t.y;
    string result;
    n=s;

        /*経路右 */
    while(t.x-n.x>0){
        result+="R";
        n.x++;
    }
    /*経路上 */
    while(t.y-n.y>0){
        result+="U";
        n.y++;
    }
    /*経路左 */
    while(n.x-s.x>0){
        result+="L";
        n.x--;
    }
    /*経路下 */
    while(n.y-s.y>0){
        result+="D";
        n.y--;
    }
    /*S位置とG位置の調整 */
    n.y--;
    result+="D";
    t.x++;
    while(t.x-n.x>0){
        result+="R";
        n.x++;
    }
    /*経路上 */
    while(t.y-n.y>0){
        result+="U";
        n.y++;
    }
    n.x--;
    result+="L";
    n.y++;
    result+="U";
    s.x--;
    /*経路左 */
    while(n.x-s.x>0){
        result+="L";
        n.x--;
    }
    /*経路下 */
    while(n.y-s.y>0){
        result+="D";
        n.y--;
    }
    result+="R";

    cout<<result<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import itertools
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
        a=list(range(1,n+1))
        s=0
        for b in itertools.combinations(a,3):
            c=sum(b)
            if c==x:
                s+=1
        print(s)


Measured memory_bytes: 5636
import math

A,B,C,D = map(int,input().split())

#C,Dの最小公倍数
E = C*D//math.gcd(C,D)
def num_mult(fro,to,mult):
    goal = to//mult
    if fro % mult == 0:
        start = fro // mult
    else:
        start = fro // mult + 1
    
    return goal - start + 1

ans = B-A+1
#Cの倍数
ans -= num_mult(A,B,C)
#Dの倍数
ans -= num_mult(A,B,D)
#C,Dの公倍数
ans += num_mult(A,B,E)

print(ans)

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

#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	int N;
	cin >> N;
	vector<vi> ed(N);
	vi deg(N);
	rep(i,0,N-1) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		ed[a].push_back(b);
		ed[b].push_back(a);
		deg[a]++;
		deg[b]++;
	}

	vi deg1, deg0;
	rep(y,0,N) {
		if (deg[y] == 1) deg1.push_back(y);
		if (deg[y] == 0) deg0.push_back(y);
	}

	vi dead(N);
	auto kill = [&](int found) {
		dead[found] = 1;
		trav(y, ed[found]) {
			--deg[y];
			if (deg[y] == 1) deg1.push_back(y);
			if (deg[y] == 0) deg0.push_back(y);
		}
	};

	for (;;) {
		while (!deg0.empty() && dead[deg0.back()]) deg0.pop_back();
		if (!deg0.empty()) {
			cout << "First" << endl;
			return 0;
		}

		while (!deg1.empty() && (dead[deg1.back()] || deg[deg1.back()] != 1)) deg1.pop_back();
		if (deg1.empty()) break;
		int x = deg1.back();
		deg1.pop_back();
		assert(deg[x] == 1);
		int found = -2;
		trav(y, ed[x]) {
			if (!dead[y]) found = y;
		}

		assert(found != -2);
		kill(found);

		while (!deg0.empty() && dead[deg0.back()]) deg0.pop_back();
		assert(!deg0.empty());
		int f = deg0.back();
		deg0.pop_back();
		kill(f);
	}
	cout << "Second" << endl;
	exit(0);
}


Measured memory_bytes: 7040
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int L = 1;
  int R = N;
  bool flg = true;
  for (int i = 0; i < M; ++i) {
    int _L, _R;
    cin >> _L >> _R;
    if (L <= _L && _R <= R) {
      L = _L;
      R = _R;
    } else if (_L <= L && R <= _R) {
      continue;
    } else if (L <= _L && _L <= R && R <= _R) {
      L = _L;
    } else if (_L <= L && L <= _R && _R <= R) {
      R = _R;
    } else {
      flg = false;
    }
  }
  if (flg) {
    printf("%d\n", R - L + 1);
  } else {
    printf("0\n");
  }
}

Measured memory_bytes: 3212
N = int(input())
dp = [[[[0]*4 for _ in range(4)] for _ in range(4)] for _ in range(N-2)]
for i in range(4):
    for j in range(4):
        for k in range(4):
            if i==0 and j==1 and k==2: continue #AGC
            if i==0 and j==2 and k==1: continue #ACG
            if i==1 and j==0 and k==2: continue #GAC
            dp[0][i][j][k] = 1
MOD = 10**9+7
for i in range(N-3):
    for ppp in range(4):
        for pp in range(4):
            for p in range(4):
                for n in range(4):
                    if pp==0 and p==1 and n==2: continue #AGC
                    if pp==0 and p==2 and n==1: continue #ACG
                    if pp==1 and p==0 and n==2: continue #GAC
                    if ppp==0 and p==1 and n==2: continue #A?GC
                    if ppp==0 and pp==1 and n==2: continue #AG?C
                    dp[i+1][pp][p][n] += dp[i][ppp][pp][p]
                    dp[i+1][pp][p][n] %= MOD
ans = sum(sum(sum(a) for a in b) for b in dp[-1])
print(ans%MOD)

Measured memory_bytes: 3444
H, W, A, B = gets.split.map(&:to_i)

(H - B).times do
  arr = []
  (W - A).times do
    arr << 0
  end
  A.times do
    arr << 1
  end
  puts arr.join("")
end

(B).times do
  arr = []
  (W - A).times do
    arr << 1
  end
  A.times do
    arr << 0
  end
  puts arr.join("")
end

Measured memory_bytes: 2940
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [(usize, [usize1]); m]
    }
    let mut keys = Vec::with_capacity(m);
    for i in 0..m {
        keys.push((v[i].0, v[i].1.iter().cloned().fold(0, |ac, x| ac + (1 << x))));
    }
    let mut dp = vec![vec![1 << 60; 1 << n]; m + 1];
    dp[0][0] = 0;
    for i in 0..m {
        for j in 0..1 << n {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][j | keys[i].1] = min(dp[i + 1][j | keys[i].1], dp[i][j] + keys[i].0);
        }
    }
    let ans = dp[m][(1 << n) - 1];
    if ans == 1 << 60 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 41212
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int sum=0;
  for(int i=0;i<n;i++)
    sum+=arr[i];
  bitset<4000001> b;
  b[0]=1;int ans=0;
  if(n==0) cout<<"0"<<endl;
  else if(n==1) cout<<arr[0]<<endl;
  else if(n==2) cout<<max(arr[0],arr[1])<<endl;
  else
  {
    for(int i=0;i<n;i++)
      b=b | (b << arr[i]);
    for(int i=(sum+1)/2;i<=sum;i++)
    {
      if(b[i])
      {
        ans=i;
        break;
      }
    }
    cout<<ans<<endl;
  }
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    int W[N];
    int diff[N-1];

    for (int i=0; i<N; ++i) {
        cin >> W[i];
    }

    for (int t=0; t<N; t++) {
        int sum1 = 0;
        int sum2 = 0;
        for (int i=0; i<=t; i++) {
            sum1 += W[i];
        }
        for (int j=t+1; j<N; j++) {
            sum2 += W[j];
        }
        diff[t] = abs(sum1 - sum2);
    }

    int diff_min = 10001;
    for (int i=0; i<N; i++) {
        if (diff_min > diff[i]) {
            diff_min = diff[i];
        }
    }
    cout << diff_min << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

ll n;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    if (n % 10 == 7 || (n / 10 % 10 == 7) || n / 100 == 7)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


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

const int N = 2e5 + 10;
int x[N], p[N];
int I[N], D[N];
template <class T, class U> inline void smax(T &a, U b) { a = a > b ? a : b; }
template <class T, class U> inline void smin(T &a, U b) { a = a < b ? a : b; }

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> x[i]; x[i]--;
    p[x[i]] = i;
  }
  for(int i = 0; i < n; i++) {
    if(x[i] == n - 1) continue;
    if(p[x[i] + 1] > i) {
      smax(I[x[i] + 1], I[x[i]] + 1);
    }
  }
  for(int i = n - 1; i >= 0; i--) {
    if(x[i] == 0) continue;
    if(p[x[i] - 1] < i) {
      smax(D[x[i] - 1], D[x[i]] + 1);
    }
  }
  ll ans = 1e18;
  for(int i = 0; i < n; i++) {
    ll t = i - I[i] + n - 1 - i - D[i];
    smin(ans, t);
  }
  cout << ans << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<vector<pair<int, int>>> graph(N);
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--, w %= 2;
    graph[u].emplace_back(make_pair(v, w));
    graph[v].emplace_back(make_pair(u, w));
  }

  queue<pair<int, int>> que;
  que.push(make_pair(0, 0));

  vector<int> color(N, -1);

  while (!que.empty()) {
    auto q = que.front();
    que.pop();

    int u = q.first, w = q.second;

    if (w % 2 == 0) {
      color[u] = 0;
    } else {
      color[u] = 1;
    }
    for (auto p : graph[u]) {
      if (color[p.first] != -1) continue;
      que.push(make_pair(p.first, p.second + w));
    }
  }

  for (int i = 0; i < N; i++) {
    cout << color[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 6784
s = input()
cnt_01 = 0
cnt_10 = 0

for i in range(len(s)):
    if (i % 2 == 0 and s[i] == "0") or (i % 2 == 1 and s[i] == "1"):
        cnt_01 += 1
    if (i % 2 == 0 and s[i] == "1") or (i % 2 == 1 and s[i] == "0"):
        cnt_10 += 1

print(min(cnt_01, cnt_10))


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


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    cin>>s;
    int now = 0;
    string ans="";
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='B') now++;
        else{
            if(now==0) ans+=s[i];
            now = max(now-1,0);
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int i,a;
    string s;
    cin>>s;
    i=a=0;
    label:
    while(i<s.length()) {
      if((s[i]=='0' && s[i+1]=='1') || (s[i]=='1' && s[i+1]=='0')){
          s.erase(i,2);
          a+=2;
          if(i)
            i--;
          else
            i=0;
          goto label;
        }
      i++;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<string>
using namespace std;
int n,m,a[200009],dp[200009],f[200009],b[200009];
void update(int x,int val)
{
  for (;x<=m;x+=x&-x) f[x]=max(f[x],val);
}
int query(int x)
{
  int ans=0;
  for (;x;x-=x&(-x))ans=max(ans,f[x]);
  return ans;
}
int main()
{
  scanf("%d",&n);
  for (int i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=a[i];
  sort(b+1,b+1+n);
  m=unique(b+1,b+1+n)-b-1;
  for (int i=1;i<=n;i++) 
  {
   a[i]=lower_bound(b+1,b+1+m,a[i])-b;
  }
  for (int i=1;i<=n/2;i++) swap(a[i],a[n-i+1]);
  int now=0,ans=0;
  for (int i=1;i<=n;i++) 
  {
  	now=query(a[i])+1;
  	update(a[i],now);
  	ans=max(ans,now);
  }
  printf("%d\n",ans);
  return 0;
} 

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

int main() {
    string s;
    cin >> s;

    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
        int l = 0;
        for (int j = i; j < s.length(); j++) {
            if (s[j] != 'A' && s[j] != 'C' && s[j] != 'G' &&s[j] != 'T') {
                break;
            }
            l++;
        }

        ans = max(ans, l);
    }

    cout << ans << endl;

    return 0;
}


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

#define MAX 100005
#define NIL -1

struct node{
  int p;
  int r;
  int l;
};

struct node T[MAX];
int n,D[MAX];

void print(int u){
  int c,i;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);
 
  if(T[u].p==NIL)printf("root, [");
  else if(T[u].l==NIL)printf("leaf, [");
  else printf("internal node, [");

  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i!=0){
      printf(", ");
    }
    printf("%d",c);
  }
  printf("]\n");
}


int rec(int u, int p){
  D[u]=p;
  if(T[u].r!=NIL) rec(T[u].r,p);
  if(T[u].l!=NIL) rec(T[u].l,p+1);
}


int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
    T[i].r=NIL;
    T[i].l=NIL;
  }
  
 for(i=0;i<n;i++){
   scanf("%d %d",&v,&d);
   for(j=0;j<d;j++){
     scanf("%d",&c);
     if(j==0){
       T[v].l=c;
     }
     else{
       T[l].r=c;
     }
     l=c;
     T[c].p=v;
   }
 }

 
 for(i=0;i<n;i++){
   if(T[i].p==NIL) r=i;
 }

 rec(r,0);
  for(i=0;i<n;i++){
    print(i);
  }

  return 0;
}



Measured memory_bytes: 6464
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b, c;
  cin >> a >> b >> c;

  if (a + b >= c)
    cout << b + c << endl;
  else
    cout << a + b * 2 + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;



int main(){
	string s;
	int q;
	cin >> s;
	cin >> q;
	
	string rhead;
	string tail;
	
	bool reversed = false;
	for ( int i = 0; i < q; i++ ){
		int type, f;
		string c;
		cin >> type;
		if ( type == 1 ){
			reversed = !reversed;
		}
		else {
			cin >> f >> c;
			if ( f == 1 && !reversed || f == 2 && reversed ){
				rhead = rhead + c;
			}
			else {
				tail = tail + c;
			}
		}
	}
	
	string head = rhead;
	reverse( head.begin(), head.end() );
	
	s = head + s + tail;
	if ( reversed )
		reverse( s.begin(),s.end() );
	
	cout << s << endl;
	
	return 0;
}



Measured memory_bytes: 4856
// ソートがボトルネックの貪欲だった、、、
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> ab(M);
    for (int i = 0; i < M; ++i) {
        cin >> ab[i].first >> ab[i].second;
    }
    auto cmp = [](pair<int, int> &a, pair<int, int> &b) -> bool { return a.second < b.second; };
    sort(ab.begin(), ab.end(), cmp);
    int prev = -1;
    int res = 0;
    for (auto p : ab) {
        //cout << p.first << " : " << p.second << endl;
        if (p.first <= prev) continue;
        ++res;
        prev = p.second - 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
	int a;
	int b;

	scanf("%d", &a);
	scanf("%d", &b);

	if(a < b){
		printf("a < b\n");
	}else if(a > b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}

	return 0;
}

Measured memory_bytes: 580
from queue import Queue

inp = input
out = print

n,m = map(int, inp().split())

adj = {i:[] for i in range(1, n+1)}

for i in range(m):
    u,v = map(int, inp().split())
    adj[u].append(v)
    adj[v].append(u)

seen = [False for _ in range(n+1)]
par = [0 for _ in range(n+1)]
q = Queue()
q.put(1)
seen[0] = seen[1] = True

while not q.empty():
    u = q.get()
    
    for v in adj[u]:
        if not seen[v]:
            q.put(v)
            seen[v] = True
            par[v] = u

if sum(seen) != n+1:
    out('No')

else:
    out('Yes')
    for i in range(2, n+1):
        out(par[i])

Measured memory_bytes: 106128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N, Q;
  cin >> N >> Q;
  vector<triple> a;
  rep(i, N) {
    ll S, T, X;
    cin >> S >> T >> X;
    a.emplace_back(X, S, T);
  }
  sort(all(a)); // Sorted by X.

  set<P> D; // The set of pairs. The pair is (Di, i).
  rep(i, Q) {
    ll d;
    cin >> d;
    P p(d, i);
    D.emplace(p);
  }

  vector<ll> ans(Q, -1);

  // Here, D is sorted. We want to know the position of Si-0.5-Xi and Ti-0.5-X in D.
  // We check [S-X, T-X) by lower_bound (S-X <= Q[i..j] < T-X).
  rep(i, N) {
    ll S, T, X;
    tie(X, S, T) = a[i];

    P sp(S-X, 0); // the second is dummy.
    auto sit = D.lower_bound(sp);
    P tp(T-X, 0); // the second is dummy.
    auto tit = D.lower_bound(tp);

    for (auto it = sit; it != tit; ++it) {
      ans[(*it).second] = X; // Set distance
    }
    D.erase(sit, tit);
  }

  rep(i, Q) {
    cout << ans[i] << endl;
  }
}


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

using namespace std;

int main()
{
    char c ;
    cin>>c ;
    if(c == 'A')
        cout<<"T" ;
    else if(c == 'T')
        cout<<"A" ;
    else if(c == 'C')
        cout<<"G";
    else
        cout<<"C";
    return 0 ;
}


Measured memory_bytes: 256
def main():
    m = 10000
    ft = 5000
    ot = 1000

    
    
    
    N, Y = map(int, input().split(' '))

    for i in range(N + 1):
        m_count = m * i

        for j in range(N - i + 1):
            ft_count = ft * j
            k = N - i - j
            ot_count = ot * k

            if Y == m_count + ft_count + ot_count:
                print(str(i) + ' ' + str(j) + ' ' + str(k))
                return

    print(str(-1) + ' ' + str(-1) + ' ' + str(-1))
main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind{
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

signed main(){
  int n,q;
  cin>>n>>q;
  UnionFind uf(n);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<uf.same(x,y)<<endl;
    else uf.unite(x,y);
  }
  return 0;
}
/*
verified on 2017/04/28
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A&lang=jp
*/

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    string SS, T;
    cin >> SS >> T;
    for (int i = SS.size() - T.size(); i >= 0; i--) {
        bool ok = true;
        REP(j, T.size()) {
            if (SS[i + j] != '?' && SS[i + j] != T[j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            string S = "";
            REP(k, SS.size()) {
                if (k < i || i + T.size() <= k) {
                    if (SS[k] == '?') S += 'a';
                    else S += SS[k];
                } else {
                    S += T[k - i];
                }
            }
            cout << S << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int tot = 0;

		for (int i = 0; i <= n; i++) {
			int ans = calcSumofDigits(i);
//			System.out.print(" ans_out "+ ans);
//			System.out.println(" i "+ i);
			if (a <= ans && ans <= b) {
				tot += i;
			}

		}
		System.out.println(tot);
	}

	static int calcSumofDigits(int n) {
		int ans = 0;
		while (n > 0) {
			ans += n % 10;
			n = n / 10;
//   			System.out.println(" ans "+ ans);
//   			System.out.println(" n "+ n);
		}
		return ans;
	}
}


Measured memory_bytes: 23636
#include<stdio.h>
#include<string.h>
int main()
{
	int a[3005];
	int n,i,j,k;
	scanf("%d",&n);
	int sum=0;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		sum=sum+a[i];
	}
	printf("%d\n",sum-n);
}

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

const int maxn = 105;
int f[maxn][maxn][maxn], d[maxn][maxn], ans[maxn][maxn][3];
int A, B, mxA, mxB, n;
set<pair<pair<int,int>,int> > s;

int main() {
	scanf("%d%d", &A, &B);
	rep (i, 1, A) rep (j, 1, B) scanf("%d", &d[i][j]);
	rep (a, 0, 100) rep (b, 0, 100) rep (c, 0, 100) if (a + b + c <= 100) {
		rep (i, 1, A) if (!f[a][b][c])
			rep (j, 1, B) if (a * i + b * j + c < d[i][j]) {
				//printf("%d %d %d\n", a, b, c);
				f[a][b][c] = 1; break;
			}
	}
	rep (i, 1, A) rep (j, 1, B) {
		int flag = 0;
		rep (a, 0, 100) if (!flag)
			rep (b, 0, 100) if (!flag && a * i + b * j <= d[i][j]) 
				rep (c, 0, 100) if (a * i + b * j + c == d[i][j] && !f[a][b][c]) {
					ans[i][j][0] = a; ans[i][j][1] = b; ans[i][j][2] = c;
					mxA = max(mxA, a); mxB = max(mxB, b); flag = 1; break;
				}				
		if (!flag) return puts("Impossible"), 0;
	}
	puts("Possible");
	n = mxA + mxB + 2;
	rep (i, 1, mxA) s.insert(make_pair(make_pair(i, i+1), -1));
	rep (i, n-mxB, n-1) s.insert(make_pair(make_pair(i, i+1), -2));
	rep (i, 1, A) rep (j, 1, B) {
		s.insert(make_pair(make_pair(ans[i][j][0]+1, n-ans[i][j][1]), ans[i][j][2]));
		//printf("# %d %d   %d %d %d\n", i, j, ans[i][j][0], ans[i][j][1], ans[i][j][2]);
	}
	printf("%d %d\n", n, (int)s.size());
	for (auto x : s)
		if (x.second == -1) printf("%d %d X\n", x.first.first, x.first.second);
		else if (x.second == -2) printf("%d %d Y\n", x.first.first, x.first.second);
		else printf("%d %d %d\n", x.first.first, x.first.second, x.second);
	printf("%d %d\n", 1, n);
	return 0;
}

Measured memory_bytes: 3968
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main(){
    ll x,a,b;
    cin >> x >> a >> b;
    ll s=abs(x-a);
    ll t=abs(x-b);
    if(s<t) cout << 'A' << endl;
    else cout << 'B' << endl;
    return 0;
} 


Measured memory_bytes: 3644
#!/usr/bin/env python
# coding: utf-8

# In[11]:


N,C,K = map(int, input().split())
T = []
for i in range(N):
    T.append(int(input()))


# In[13]:


T = sorted(T)
ans = 0
p = 0
t = 0
for i in range(N):
    if t == 0:
        t = T[i]
    if T[i] <= t+K:
        p += 1
        if p >= C:
            ans += 1
            p = 0
            t = 0
    else:
        t = T[i]
        ans += 1
        p = 1
if p > 0:
    ans += 1
print(ans)


# In[ ]:






Measured memory_bytes: 14164
//Pantyhose(black) + glasses = infinity

#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

int cnt[5];

int main() {
	#ifdef GLASSES_GIRL
		freopen(FILE_NAME".inp", "r", stdin);
		freopen(FILE_NAME".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0); cin.tie(0);
	for (int i=1; i<=3; ++i) {
		int x, y;
		cin >> x >> y;
		++cnt[x];
		++cnt[y];
	}
	int tmp = 0;
	for (int i=1; i<=4; ++i)
		tmp += cnt[i]%2;
	if (tmp==0 || tmp==2)
		puts("YES");
	else
		puts("NO");
}

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

int main() {
  int A, B, M, mia = 1e9, mib = 1e9;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  for (int i = 0, x; i < A && cin >> x; i++) mia = (x < mia) ? x : mia, a.at(i) = x;
  for (int i = 0, x; i < B && cin >> x; i++) mib = (x < mib) ? x : mib, b.at(i) = x;
  int ans = 1e9;
  for (int i = 0, x, y, c; cin >> x >> y >> c; i++) ans = min(ans, a.at(--x) + b.at(--y) - c);
  cout << min(ans, mia + mib) << "\n";
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<map>
using namespace std;

int swaps = 0;

void bubbleSort3(int array[] , int n) {
  for(int x=0; x<n; x++)
	{
		for(int y=0; y<n-2; y++)
		{
			if(array[y]>array[y+2])
			{
				int temp = array[y+2];
				array[y+2] = array[y];
				array[y] = temp;
			}
      if(array[y]>array[y+1])
			{
				int temp = array[y+1];
				array[y+1] = array[y];
				array[y] = temp;
        swaps++;
			}
		}
	}
}

int n;
int a[200050];
int main() {
  scanf("%d",&n);
  map<int,int>mp;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    mp[a[i]] = i;
  }
  sort(a,a+n);
  int ans = 0;
  for(int i=0;i<n;i++){
    if(abs(mp[a[i]]-i)%2!=0) ans++;
  }
  //bubbleSort3(a,n);
  printf("%d\n",ans/2);
  return 0;
}


Measured memory_bytes: 5376
#include<stdio.h>
int main(){
  int n,x,min = 1000;
  scanf("%d %d",&n,&x);
  int a[n];
  for(int i = 0;i < n;i++){
    scanf("%d",&a[i]);
    x -= a[i];
    if(min > a[i]){
      min = a[i];
    }
  }
  printf("%d\n",n + x / min);
  return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
#read=sys.stdin.buffer.read
#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

s=input().rstrip("\n")
t=input().rstrip("\n")
if s==t[:len(t)-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9032
import sys
input = sys.stdin.readline

S = input().strip()
if S == 'SUN':
    print(7)
if S == 'MON':
    print(6)
if S == 'TUE':
    print(5)
if S == 'WED':
    print(4)
if S == 'THU':
    print(3)
if S == 'FRI':
    print(2)
if S == 'SAT':
    print(1)

Measured memory_bytes: 3060
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    min4(a,b,c,d)   min(min(a,b),min(c,d))
#define    max4(a,b,c,d)   max(max(a,b),max(c,d))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
    //test
    {
        int n;
        cin>>n;
        if(n>=400 and n<=599)cout<<8;
        else if(n>=600 and n<=799)cout<<7;
        else if(n>=800 and n<=999)cout<<6;
        else if(n>=1000 and n<=1199)cout<<5;
        else if(n>=1200 and n<=1399)cout<<4;
        else if(n>=1400 and n<=1599)cout<<3;
        else if(n>=1600 and n<=1799)cout<<2;
        else if(n>=1800 and n<=1999)cout<<1;

    }

End;
}


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

int main(){
  string s;//入力させます
  cin >> s;
  int len = s.length() + 1;
  int k;
  cin >> k;
  string ranking[] = {"zzzzzz","zzzzzz","zzzzzz","zzzzzz","zzzzzz"};
  for(int i=1;i<=k;++i){
    for(int j=0;j<len-i;++j){
      string Temp = s.substr(j, i);
      for(int ii=k-1;ii>=0;--ii){
        if(Temp.compare(ranking[ii])==0){
          break;
        }else if(Temp.compare(ranking[ii])<0&&ii==0){
          for(int jj=3;jj>=0;jj--){
            ranking[jj+1] = ranking[jj];
          }
          ranking[0] = Temp;
        }else if(Temp.compare(ranking[ii])>0){
          if(ii==4){
            break;
          }
          for(int jj=3;jj>=ii+1;--jj){
            ranking[jj+1] = ranking[jj];
          }
          ranking[ii+1] = Temp;
          break;
        }
      }
    }
  }
  cout << ranking[k-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;

void solve()
{	
	int n,r; cin >> n>>r;
	int ans;
	if(n>=10)ans=r;
	else ans=r+100*(10-n);
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
using System;
class Program{
  static void Main(){
    var src = Console.ReadLine().Split(' ');
    if((src[0]==src[1] && src[0] != src[2])||
       (src[0]==src[2] && src[0] != src[1])||
       (src[1]==src[2] && src[0] != src[1]))
      Console.WriteLine("Yes");
    else
      Console.WriteLine("No");
  }
}

Measured memory_bytes: 11092
/*
´Ó×óµ½ÓÒÓÐN¸öÕý·½ÐÎÅÅ³ÉÒ»ÐÐ¡£´Ó×ó±ßÊýµÚi¸öÕý·½ÐÎµÄ¸ß¶ÈÊÇh i¡£


*/

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N = 1e5 + 7;
int n;
int H[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&H[i]);
	for(int i=1;i<=n;++i) {
		if(H[i]>H[i-1]) H[i]--;
		else if(H[i]<H[i-1]) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll n, m, k = 0, l = 0,x,y;

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

set<int> mn;



int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	vector<int> a(n+1,0),dp(n+2,0);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	dp[1] = abs(a[1] - a[0]);

	for (int i = 0; i < n-1; i++) {
		
			dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i] - a[i + 1]));
			dp[i + 2] = dp[i] + abs(a[i] - a[i + 2]);
	}
	cout << dp[n - 1];

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll int>
#define vs vector<string>
#define v vector<int>
#define mi map<int,int>
#define mc map<char,int>
//ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	string s;
	cin>>s;
	if(s=="SUN"){
		cout<<7 <<"\n";
		}	
		else if(s=="MON"){
			cout<<6 <<"\n";
			}
			else if(s=="TUE"){
				cout<<5 <<"\n";
				}
				else if(s=="WED"){
					cout<<4 <<"\n";
					}
					else if(s=="THU"){
						cout<<3 <<"\n";
						}
						else if(s=="FRI"){
							cout<<2 <<"\n";
							}
							else if(s=="SAT"){
								cout<<1 <<"\n";
								}
}


Measured memory_bytes: 3648
#include <stdio.h>
int main (){
  int x,y,result;

  while(1){
   
 
  
    scanf("%d%d",&x,&y);

    if(x==0&&y==0) break;
  
    if(x>y) printf("%d %d\n",y,x);
     else     printf("%d %d\n",x,y);
    
  }
  
  return 0;
}

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

long long n,A,B;

int main()
{
	scanf("%lld%lld%lld",&n,&A,&B);
	if (A>B) swap(A,B);
	if ((B-A)%2==0) printf("%lld\n",(B-A)/2); else
	{
		long long ans=min((A+B-1)/2,(n-B+1+n-A)/2);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final char[] chars = scanner.nextLine().toCharArray();
        final int[] answer = new int[chars.length];

        final List<Integer> rIndexes = new ArrayList<>();
        final List<Integer> lIndexes = new ArrayList<>();

        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == 'R') {
                rIndexes.add(i);
            } else {
                lIndexes.add(i);
            }
        }

        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == 'R') {
                final int lIndex = findLIndex(i, lIndexes);
                if ((lIndex - i) % 2 == 0) {
                    answer[lIndex]++;
                } else {
                    answer[lIndex - 1]++;
                }
            } else {
                final int rIndex = findRIndex(i, rIndexes);
                if ((i - rIndex) % 2 == 0) {
                    answer[rIndex]++;
                } else {
                    answer[rIndex + 1]++;
                }
            }
        }

        for (final int i : answer) {
            System.out.print(i + " ");
        }

    }

    private static int findRIndex(final int index, final List<Integer> rIndexes) {
        final int i = -(Collections.binarySearch(rIndexes, index) + 2);
        return rIndexes.get(i);
    }

    private static int findLIndex(final int index, final List<Integer> lIndexes) {
        final int i = -(Collections.binarySearch(lIndexes, index) + 1);
        return lIndexes.get(i);
    }
}


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

int main(){
  int l,n = 0;
  cin >> l;

  // 頂点数
  while(1<<n <= l) n++;
  vector<vector<int>> ans;

  // 2進数の辺を作る
  for(int i=1; i<n; i++){
    ans.push_back({i, i+1, 1<<(i-1)});
    ans.push_back({i, i+1, 0});
  }

  // 今できている経路の最大長。これをL-1にするまで経路を足す。
  int now = (1<<(n-1)) - 1;

  for(int i=n-1;i>=1;i--){
    if(now == l-1) break;

    // 頂点iからのショートカット追加で増える経路数
    int gain = 1<<(i-1);

    if(now + gain <= l-1){
      ans.push_back({i,n,now+1});
      now += gain;
    }
  }
  int m = ans.size();
  cout << n << " " << m << endl;

  for(auto v : ans){
    cout << v[0] << " " << v[1] << " " << v[2] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll a,b;
	cin>>a>>b;
	ll c = a+b;
	if(c%2==0)
	{
		cout<<c/2<<endl;
	}
	else
	{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3620
#include <stdint.h>
#include <stdio.h>

/* At most three digits. */
unsigned readUnsigned() {
    int c;
    do { c = ::getchar_unlocked(); } while (c < '0');
    unsigned result = c - '0';
    if ((c = ::getchar_unlocked()) >= '0') {
        result *= 10;
        result += c - '0';
        if ((c = ::getchar_unlocked()) >= '0') {
            result *= 10;
            result += c - '0';
        }
    }
    return result;
}

unsigned N, M;
unsigned A[304][304];

bool valid(unsigned x) {
    unsigned I[304] = {0};
    bool bad[304] = {0};
    for (unsigned sports = M;;) {
        unsigned counts[304] = {0};
        for (unsigned i = 0; i < N; ++i) {
            if (++counts[A[i][I[i]]] > x) {
                unsigned badsport = A[i][I[i]];
                bad[badsport] = true;
                if (--sports * x < N) return false;
                for (unsigned j = 0; j < N; ++j) {
                    while (bad[A[j][I[j]]]) {
                        ++I[j];
                    }
                }
                goto next;
            }
        }
        return true;
next:;
    }
    return false;
}

int main() {
    N = readUnsigned();
    M = readUnsigned();
    for (unsigned i = 0; i < N; ++i) {
        for (unsigned j = 0; j < M; ++j) {
            A[i][j] = readUnsigned() - 1;
        }
    }

    unsigned x = 0;
    for (unsigned step = M; step; step /= 2) {
        while (!valid(x + step)) x += step;
    }
    printf("%u\n", x + 1);
}


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int,int> pii;
vector<pii> v;
int main(){
	int N,M;
	scanf("%d %d",&N,&M);
	for(int i=0;i<N;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		v.push_back({a,b});
	}
	sort(v.begin(),v.end());
	long long sum=0;
	int cnt=0;
	for(auto it : v){
		if(cnt>=M) break;
		int p=it.first, num=it.second;
		int getsu=min(M-cnt,num);
		cnt+=getsu;
		sum+=((long long)p)*getsu;
	}
	printf("%lld",sum);
}

Measured memory_bytes: 1400
import java.io.*;
import java.util.*;
public class Main{
	static BufferedReader br;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static int n;
	static double[]arr;
	static double[][]dp;
	static double prob(int ind,int heads)
	{
		if(heads>n-heads)
			return 1;
		if(ind==n)
			return 0;
		if(dp[ind][heads]!=-1)
			return dp[ind][heads];
		double res=(1-arr[ind])*prob(ind+1,heads)+arr[ind]*prob(ind+1,heads+1);
		dp[ind][heads]=res;
		return res;
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		n=cin();
		String[] cmd=br.readLine().split(" ");
		arr=new double[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=Double.valueOf(cmd[i]);
		}
		dp=new double[n+1][n+1];
		for(int i=0;i<=n;i++)
		{
			Arrays.fill(dp[i], (double)(-1));
		}
		System.out.println(prob(0,0));
	}
}


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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  bool flag=1;

  if(n==1&&s.at(0)=='L') flag=0;
  REP(i,n-1){
    if(i%2 && s.at(i+1)=='L') flag=0;
    if(!(i%2) && s.at(i+1)=='R') flag=0;
  }

  if(flag) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    int m;
    cin>>m;
    vpii res;
    rep(i,0,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        pii v=make_pair(b,a);
        res.push_back(v);
    }
    sort(res.begin(),res.end());
    int ans=0;
    vpii sep;
    rep(i,0,m){
        pii e=res[i];
        int rcmp=res[i].first;
        int lcmp=res[i].second;
        int n=sep.size();
        if(n==0)sep.push_back(e),ans++;
        else{
            bool check=true;
            rep(j,0,n){
                int rv=sep[j].first;
                int lv=sep[j].second;
                if(rv<=lcmp)continue;
                else{
                    chmax(lv,lcmp);
                    check=false;
                }
            }
            if(check)sep.push_back(e),ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1400
#include<stdio.h>
 
int main(){
  int n,i;
  int flag=0;
  long int sum=0;
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    if(i%3==0)
      flag=1;
    else if(i%5==0)
      flag=1;
    
    if(flag==0)
      sum=sum+i;
    flag=0;
  }
  
  printf("%ld",sum);
  
  return 0;
}

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

int main(void)
{
  int n,m,l,i,j,k;
  long int a[101][101]={};
  long int b[101][101]={};
  long int c[101][101]={};

  cin >> n >> m >> l;

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

  for(j = 1; j <= m; j++){
    for(k = 1; k <= l; k++){
      cin >> b[j][k];
    }
  }

  for(i = 1; i <= n; i++){
    for(k = 1; k <= l; k++){
      c[i][k] = 0;
      for(j =1; j <=m; j++){
        c[i][k] = c[i][k] + a[i][j]*b[j][k];
      }
      cout << c[i][k];
      if(k != l) cout << " ";
    }
    cout << endl;
  }

  return 0;
}

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

int main() {
    int l,r,d,i,count=0;
    
    cin >> l >> r >>d;
    
    for(i=l;i<=r;i++)
    {
       
        if(i%d==0){
          count++;
        }
        
    }
    cout<<count;
   
}


Measured memory_bytes: 3624