akhauriyash/Code-Regression huggingface dataset:
def digit(x):
    ret = 0
    while x > 0:
        x //= 2
        ret += 1
    return ret

def main():
    N = int(input())
    A = list(map(int, input().split()))
    g = 0
    for i in range(2, N):
        g ^= A[i]
    a0 = A[0]
    a1 = A[1]
    ans = 0
    half = 2**20
    if a0 < half:
        for i in range(a0):
            t0 = a0 - i
            t1 = a1 + i
            if t0 ^ t1 == g:
                print(i)
                return
        print(-1)
        return

    # check upper part (2**20 <= x)
    ug = g >> 20
    b0 = a0 >> 20
    b1 = a1 >> 20
    upper_ans_0 = -1 # a0: no borrow, a1: no carry
    for i in range(b0):
        t0 = b0 - i
        t1 = b1 + i
        if t0 ^ t1 == ug:
            upper_ans_0 = i
            break

    upper_ans_1 = -1 # a0: no borrow, a1: carry
    for i in range(b0):
        t0 = b0 - i
        t1 = b1 + 1 + i
        if t0 ^ t1 == ug:
            upper_ans_1 = i
            break

    upper_ans_2 = -1 # a0: borrow, a1: no carry
    for i in range(b0-1):
        t0 = b0 - 1 - i
        t1 = b1 + i
        if t0 ^ t1 == ug:
            upper_ans_2 = i
            break

    upper_ans_3 = -1 # a0: borrow, a1: carry
    for i in range(b0-1):
        t0 = b0 - 1 - i
        t1 = b1 + 1 + i
        if t0 ^ t1 == ug:
            upper_ans_3 = i
            break

    # print(upper_ans_0, upper_ans_1, upper_ans_2, upper_ans_3)
    # check lower part (0 ... 2**20)
    lower_answers = []
    for i in range(half):
        t0 = (a0 - i) % half
        t1 = (a1 + i) % half
        if t0 ^ t1 == (g % half):
            lower_answers.append(i)
    if len(lower_answers) == 0:
        print(-1)
        return
    # print(len(lower_answers))
    # print(lower_answers)
    answers = []
    for l in lower_answers:
        if (a0 % half) >= l:
            # a0: no borrow
            if (a1 % half) + l < half:
                # no carry
                if upper_ans_0 != -1:
                    answers.append((upper_ans_0 << 20) + l)
            else:
                # carry
                if upper_ans_1 != -1:
                    answers.append((upper_ans_1 << 20) + l)
        else:
            # a0: borrow
            if (a1 % half) + l < half:
                # no carry
                if upper_ans_2 != -1:
                    answers.append((upper_ans_2 << 20) + l)
            else:
                # carry
                if upper_ans_3 != -1:
                    answers.append((upper_ans_3 << 20) + l)
    if len(answers) == 0:
        print(-1)
        return
    answers.sort()
    print(answers[0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 9372
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e4 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	read(n);
	string s;
	cin >> s;
	
	int cnt[n + 10][3] = {};
	FORD (i, n - 1, 0)
	{
	    FOR (j, 0, 2) cnt[i][j] = cnt[i + 1][j];
	    if (s[i] == 'R') cnt[i][0]++;
	    if (s[i] == 'G') cnt[i][1]++;
	    if (s[i] == 'B') cnt[i][2]++;
	}
	
	int ans = 0;
	FOR (i, 0, n - 1)
	{
	    FOR (j, i + 1, n - 1)
	    {
	        if (s[i] == s[j]) continue;
	        char ch = 'R' + 'G' + 'B' - s[i] - s[j];
	        
	        if (ch == 'R') ans += cnt[j + 1][0];
	        if (ch == 'G') ans += cnt[j + 1][1];
	        if (ch == 'B') ans += cnt[j + 1][2];
	        
	        if (2*j - i < n && s[2*j - i] == ch) ans--;
	        //cout << i << " " << j << ": " << ans << " " << 2*j - i << " " << ch <<  " " << s[2*j - i] << endl;
	    }
	}
	
    cout << ans;
}



























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

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

int main()
{
    string s;
    cin >> s;
    int l = s.size();
    REP(l)if(s[i]-3 < 'A') s[i] = s[i] - 3 + 26; else s[i] -= 3;
    cout << s << endl;

    return 0;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n , k ;
    cin >> n >> k ;

    vll v ( n ) ;
    for ( int i=0 ; i < n ; i ++ )
        cin >> v[i] ;

    sort ( allrev ( v ) ) ;

    ll ans = 0 ;
    for ( int i = k ; i < n ; i ++ )
        ans += v[i] ;

    cout << ans ;
    line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

const i32 mod = 1000000007;

i32 comb (i32 n, i32 k) {
  if (!(0 <= k && k <= n)) return 0;
  i32 a = 1;
  i32 b = 1;
  for (i32 i = 1; i <= k; ++i) {
    a = (i64) a * (n + 1 - i) % mod;
    b = (i64) b * i % mod;
  }
  while (b > 1) {
    a = (i64) a * (mod - mod / b) % mod;
    b = mod % b;
  }
  return a;
}

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  i32 ans = comb (n + k - 1, k - 1);
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run ();
  return 0;
}


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

int main(void){

	int N;
	cin >> N;

	int K;
	cin >> K;

	vector<int> ht(N,0);

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

	vector<int> ans(N,INT_MAX);

	ans[0] = 0;

	for(int i=1;i<N;i++){

		for(int j=i-1; j>= max(0,i-K); j--){
			ans[i]= min(ans[i],ans[j]+abs(ht[i]-ht[j]));
		}
	}

	cout << ans[N-1];
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_N = 100000;
 
int n, a[MAX_N];
 
int main(){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int k;
        cin >> k;
        if(binary_search(a, a + n, k)) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 3484
#include <iostream>
//#include <vector>
#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    string a;
    int tmp;
    cin >> a;
    tmp = a[0]-'a';
    if(tmp>=0){
        cout << 'a' << endl;
    }else{
        cout << 'A' << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
k,a,b = map(int,input().split())
cokie = 1
if b < a:
    cokie += k
    print(cokie)
else:
    if k < a-1 or b-a < 2:
        cokie += k
        print(cokie)
    else:
        cokie += a-1
        k -= a-1
        b_a = k//2
        hit = k%2
        cokie += b_a*(b-a) + hit 
        print(cokie)


Measured memory_bytes: 8940
import java.util.*;

public class Main {

    public static void main(String[] args)
    {
        //変数
        int count=0;
        boolean sw=false;
        int max=Integer.MIN_VALUE;
        int min=Integer.MAX_VALUE;
        int answer=0;
        int tmp=0;
        List<Long> list1=new ArrayList<>();
        int array1[]=new int[5];
        //入力
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        //処理
        for(int i=0;i<2;i++) {
            if (A > B) {
                answer += A;
                A--;
            } else if (A < B) {
                answer += B;
                B--;
            } else {
                answer += A;
                A--;
            }
        }
        /*
        Collections.sort(a);
        System.out.println(Arrays.toString(a.toArray()));
        //System.out.println(Arrays.toString(X));
		//System.out.println(Arrays.deepToString(a));
        */
        System.out.println(answer);
    }
}

Measured memory_bytes: 23252
k = int(input())
pre = [1,2,3,4,5,6,7,8,9]
if k <= 9:
    print(pre[k-1])
    exit()

count = 9
while True:
    cur = []
    for e in pre:
        last = e%10
        for i in [-1, 0, 1]:
            nxt = last+i
            if 0<=nxt<=9:
                count += 1
                value = 10*e + nxt
                if count == k:
                    print(value)
                    exit()
                cur.append(value)

    pre = cur


Measured memory_bytes: 42352
n = gets.to_i
a = gets.split.map(&:to_i)
ans_m = 1000
ans_r = 0

(n-1).times do |i|
    if a[i] < a[i+1]
        ans_r =  ans_m/a[i]
        ans_m -= ans_r*a[i]
        ans_m +=  ans_r*a[i+1]
    end
end

p ans_m

Measured memory_bytes: 14292
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define P pair<ll, ll>
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

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

int main(void)
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, 0, h) cin >> s[i];
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<P> que;
    rep(i, 0, h) rep(j, 0, w) if (s[i][j] == '#') que.push({i, j}), dist[i][j] = 0;
    while (!que.empty())
    {
        int y = que.front().first, x = que.front().second;
        que.pop();
        rep(i, 0, 4)
        {
            int ny = y + dy[i], nx = x + dx[i];
            if (0 <= ny && ny < h && 0 <= nx && nx < w && dist[ny][nx] == -1)
                dist[ny][nx] = dist[y][x] + 1, que.push({ny, nx});
        }
    }
    int ans = 0;
    rep(i, 0, h) ans = max(ans, MX(dist[i]));
    cout << ans << endl;
}

Measured memory_bytes: 25332
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr front()
#define tp top()
typedef long long int ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
typedef pair <int, pii> pip;
#define iofast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define iofile freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
const ll LLINF = 1e18;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
const int SIZE = 100005;

int N, K;
int A[SIZE];
int dp[SIZE];

int main (){
	
	for(int i=0;i<SIZE;i++){
		dp[i]=INF;
	}
	dp[0]=0; dp[1]=0;
	A[0]=0;
	scanf("%d %d", &N, &K);
	for(int i=1;i<=N;i++){
		scanf("%d", &A[i]);
		for(int j=1;j<=K;j++){
			if(i-j<1) break;
			dp[i]=min(dp[i],dp[i-j]+abs(A[i-j]-A[i]));
		}
	}
	printf("%d\n", dp[N]);
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
   //cout << std::fixed;
    //cout << std::setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    unordered_map<int,int> map;
    for(int i=0;i<n;i++){
        int k; cin>>k;
        for(int j=0;j<k;j++){
            int x; cin>>x;
            map[x]++;
        }
    }
    int l=0;
    for(auto x : map){
        if(x.second==n) l++;
    }
    cout<<l;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 long long INF = 1LL << 60;

typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair

int main(){
  int H, W, m;
  cin >> H >> W >> m;
  vector<int> cnth(H, 0);
  vector<int> cntw(W, 0);
  set<pii> st;
  rep(i, m){
    int h, w;
    cin >> h >> w;
    h--, w--;
    cnth[h]++;
    cntw[w]++;
    st.insert(mp(h, w));
  }

  int mah = 0;
  int maw = 0;
  rep(i, H) chmax(mah, cnth[i]);
  rep(i, W) chmax(maw, cntw[i]);
  vector<int> ih;
  vector<int> iw;
  rep(i, H) if(cnth[i] == mah) ih.push_back(i);
  rep(i, W) if(cntw[i] == maw) iw.push_back(i);

  rep(i, ih.size()){
    rep(j, iw.size()){
      if(!st.count(mp(ih[i], iw[j]))){
        cout << mah + maw << endl;
        return 0;
      }
    }
  }

  cout << mah + maw -1 << endl;

  return 0;
}


Measured memory_bytes: 23872
from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import math
 
# sys.stdin = open('input')
 
def inp(force_list=False):
    re = map(int, raw_input().split())
    if len(re) == 1 and not force_list:
        return re[0]
    return re
 
def inst():
    return raw_input().strip()
 
def gcd(x, y):
   while(y):
       x, y = y, x % y
   return x
 
mod = 1000000007
def idx(c):
    return ord(c) - ord('a')

class Fenwick(object):
    def __init__(self, n):
        self.n = n
        self.da = [0] * n
    
    def add(self, pos, x):
        while pos < self.n:
            self.da[pos] += x
            pos |= pos + 1

    def ps(self, pos):
        re = 0
        while pos >= 0:
            re += self.da[pos]
            pos &= pos + 1
            pos -= 1
        return re

    def sum(self, x, y):
        return self.ps(y) - self.ps(x-1)

def my_main():
    n, nq = inp()
    da = inp(True)
    q = []
    for i in range(nq):
        l, r = inp()
        q.append((l, r, i))
    q.sort(key=lambda e:e[-2])
    mp = [-1] * (510000)
    now = -1
    fw = Fenwick(n)
    ans = [0] * nq
    for l, r, idx in q:
        l -= 1
        r -= 1
        while now < r:
            now += 1
            if mp[da[now]]!=-1:
                fw.add(mp[da[now]], -1)
            mp[da[now]] = now
            fw.add(now, 1)
        ans[idx] = fw.sum(l, r)

    print '\n'.join(map(str, ans))



my_main()

Measured memory_bytes: 245392
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
const double pi=acos(-1.0);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int main(void){
    int a,b;
    cin>>a;
    if(a==1)b=0;
    if(a==0)b=1;
    cout<<b<<endl;
    
    
}

Measured memory_bytes: 3628
h, w = map(int, input().split())
b = 0
l = [0]*h
for k in range(h):
  a = str(input())
  for k_ in range(w):
    if a[k_] == '#':
      b += 1
  l[k] = a
#l = [str(input()) for _ in range(h)]
 
from collections import deque
 
queue = deque()
visit = [[-1]*w for _ in range(h)]
queue.append([0, 0])
visit[0][0] = 1
 
while queue:
  y, x = queue.popleft()
  if y == h-1 and x == w-1:
    print(h*w-visit[y][x]-b)
    exit()
  for i, j in ([-1, 0], [1, 0], [0, 1], [0, -1]):
    new_y, new_x = y+i, x+j
    if (new_x>=0) and (new_x<w) and (new_y>=0) and (new_y<h) and l[new_y][new_x]=='.' and visit[new_y][new_x] == -1:
      visit[new_y][new_x] = visit[y][x]+1
      queue.append([new_y,new_x])
    else:
      continue
else:
  print('-1')

Measured memory_bytes: 40048
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
const ll inf=1e9+7;
const ll ful=1e18;
using namespace std;
namespace mp = boost::multiprecision;
int main() 
{
	int N;
	mp::cpp_int ans=1;
	cin>>N;
	vector<ll> A(N);
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		if(A[i]==0) ans=0;
	}
	sort(A.begin(),A.end());
	bool flag=true;
	for(int i=0;i<N;i++)
	{
		ans*=A[i];
		if(ans>ful) 
		{
			flag=false;
			break;
		}
	}
	if(flag)
	{
		cout<<ans<<endl;
	}
	else
	{
		cout<<-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define sz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define PB push_back
#define PF push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define vec vector
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void solve(){
	ll a, b, k;
	
	cin >> a >> b >> k;
	
	cout << max(0LL, a-k) << ' ' << max(0LL, b - (max(0LL,k-a))); 
}

int main(){
	int t = 1;

	while(t--){
		solve();
	}
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		char[] Sprime = s.nextLine().toCharArray();
		char[] T = s.nextLine().toCharArray();
		int SprimeLength = Sprime.length;
		int TLength = T.length;
		boolean matched = false;
		outer: for (int i = Sprime.length - T.length; i >= 0; i--) {
			for (int j = 0; j < TLength; j++) {
				if (Sprime[i + j] != '?' && Sprime[i + j] != T[j]) {
					continue outer;
				}

			}
			for (int j = 0; j < TLength; j++) {
				Sprime[i + j] = T[j];

			}
			matched = true;
			break;

		}
		if (matched) {
			// マッチしました
			for (int i = 0; i < Sprime.length; i++) {
				if (Sprime[i] == '?')
					Sprime[i] = 'a';
			}
			System.out.println(Sprime);
		} else {
			System.out.println("UNRESTORABLE");
		}
	}

}


Measured memory_bytes: 22996
#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;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T,V> &x){cerr<<'{';__print(x.first);cerr<<',';__print(x.second);cerr<<'}';}
template<typename T>
void __print(const T &x){int f=0;cerr<<'{';for(auto &i:x)cerr<<(f++ ? "," : ""),__print(i);cerr<<"}";}
void _print(){cerr<<"]\n";}
template<typename T,typename... V>
void _print(T t, V... v) {__print(t);if(sizeof...(v))cerr<<", ";_print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define sz(x) (int)x.size()                         					
#define all(x) x.begin(), x.end()           		
#define lb lower_bound                  	
#define ub upper_bound             		
                                   	
typedef long long ll;           		
typedef pair<int, int> pii;     	
typedef pair<ll, ll> pll;       	
typedef long double ld;
          						
template<typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;    
template<typename T> void print(T x){cerr<<x<<'\n';}
inline ll bip(ll x,ll n,ll mod){ll res=1;while(n){if(n&1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}                 		
																															 
const int maxn = 1e9;
const ll inf = 1e18;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int N = 5e5 + 10;

string s;
int r[N], a[N];

void solve() {
	cin >> s;

	int n = sz(s);

	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '>') r[i] = r[i + 1] + 1;
		else r[i] = 0;
	}

	if (s[0] == '>') a[0] = r[0];
	for (int i = 1; i <= n; i++) {
		if (i == n) {
			if (s[i - 1] == '<') a[i] = a[i - 1] + 1;
		} else {
		    if (s[i - 1] == '<') a[i] = max(a[i - 1] + 1, r[i]);
		    else a[i] = r[i];
		}
	}
	ll ans = 0;
	for (int i = 0; i <= n; i++) ans += a[i];
	cout << ans;
}
 
int main() {
    SpeedForce;
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
        cout << '\n';
    }
}    

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

int main() {
	int K, N;
	int* p;
	cin >> N;
	cin >> K;
	p = new int[N];

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

	//sort
	int S;
	for (int i = 0; i < N; i++) {
		for (int m = 0; m < N-i-1; m++) {
			
			if (p[m] >= p[m+1]) {
				S = p[m];
				p[m] = p[m + 1];
				p[m + 1] = S;
			}

		}
	}
	long long ans=0;

	for (int i = 0; i < K; i++) {
		ans = ans + p[i];
	}
	cout << ans;
}

Measured memory_bytes: 3172
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int X, Y;
  cin >> X >> Y;

  for (int i = 0; i <= X; i++) {
    if(Y == (2*i + 4*(X-i))){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#define h 500001
void maxheapify(int );

void buildmaxheapify(void);

int A[h];
int H;
int main(){

  int i;

  scanf("%d",&H);

  for(i = 1 ; i <= H ; i++){
    scanf("%d",&A[i]);
  }

  //  for(i = 1 ; i <= H ; i++) maxheapify(i);

  buildmaxheapify();

  for(i = 1 ; i <= H ; i++)printf(" %d",A[i]);
  printf("\n");
  return 0;
}

void maxheapify(int k){

  int r,l,largest,temp;
  l = 2*k;
  r = 2*k+1;

  if(l <= H && A[l] > A[k])
    largest = l;

  else largest = k;

  if(r <= H && A[r] > A[largest])
    largest = r;

  if(largest != k){
    temp = A[k];
    A[k] = A[largest];
    A[largest] = temp;

    maxheapify(largest);
  }
}

void buildmaxheapify(void){
  int i;

  for( i = H/2 ; i >= 1 ; i--)maxheapify(i);
}

Measured memory_bytes: 2548
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int a,b,c;cin>>a>>b>>c;
    if(a>b)swap(a,b);
    if(a<=c&&c<=b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#define ll long long
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<vector<ll>> v(N+1);
	ll sum=0;
	for(int i=0; i<N; ++i){
	    int t;
	    ll d;
	    cin >> t >> d;
	    v[t].push_back(d);
	    sum += d;
	}
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq_g;
	priority_queue<ll, vector<ll>, greater<ll>> pq_f;
	vector<int> cnt(N+1, 0);
	ll num=0;
	for(int i=1; i<=N; ++i){
	    if(v[i].size()>0){
	        ++num;
	        sort(v[i].begin(), v[i].end(), greater<ll>());
	        if(v[i].size()==1) pq_f.push(v[i][0]);
	        else{
	            for(int j=1; j<v[i].size(); ++j) pq_g.push(make_pair(v[i][j], i));
	        }
	    }
	}
	for(int i=N; i>K; --i){
	    if(pq_f.size()==0){
	        sum -= pq_g.top().first;
	        ++cnt[pq_g.top().second];
	        if(cnt[pq_g.top().second]+1==v[pq_g.top().second].size()){
	            pq_f.push(v[pq_g.top().second][0]);
	        }
	        pq_g.pop();
	    }else if(pq_g.size()==0){
	        sum -= pq_f.top();
	        --num;
	        pq_f.pop();
	    }else if(pq_g.top().first<2*num-1+pq_f.top()){
	        sum -= pq_g.top().first;
	        ++cnt[pq_g.top().second];
	        if(cnt[pq_g.top().second]+1==v[pq_g.top().second].size()){
	            pq_f.push(v[pq_g.top().second][0]);
	        }
	        pq_g.pop();
	    }else{
	        sum -= pq_f.top();
	        --num;
	        pq_f.pop();
	    }
	}
	cout << sum+num*num << endl;
	return 0;
}


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    R = [0]
    for a in A:
        R.append(R[-1] + a)
    ans = 10**9*(2*10**5)
    for i in range(1, N):
        ans = min(ans, abs(R[N] - R[i] - R[i]))
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int k;
  scanf("%d", &k);
  string s;
  cin >> s;

  if (s.length() > k)
    cout << s.substr(0, k) << "..." << endl;
  else
    cout << s << endl;

  return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
const int N = (int) 1e5;
long long a[N+5],ans=(long long)2e15,n,k,i;
int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    cin>>a[i];
     for(i=1;i+k-1<=n;i++)
    {
        int l=i,r=i+k-1;
        ans=min(ans,a[r]-a[l]+min(abs(a[l]),abs(a[r])));
    }
    cout<<ans;
}

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

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}

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

bool in_range(ll x, ll y, ll H, ll W) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

template <class Maze>
vector<vector<int>> shortest_path(const Maze &maze, char wall, int s_x, int s_y) {
    int H = maze.size();
    int W = maze[0].size();
    vector<vector<int>> dp(H, vector<int>(W, H * W));
    if (maze[s_x][s_y] == '#') {
        return dp;
    }
    queue<pii> q;
    dp[s_x][s_y] = 0;
    q.push(pii(s_x, s_y));
    while (!q.empty()) {
        int x, y;
        tie(x, y) = q.front();
        q.pop();
        for (int k = 0; k < 4; ++k) {
            int x_next = x + dx[k];
            int y_next = y + dy[k];
            if (in_range(x_next, y_next, H, W) && maze[x_next][y_next] != wall && dp[x_next][y_next] > dp[x][y] + 1) {
                dp[x_next][y_next] = dp[x][y] + 1;
                q.push(pii(x_next, y_next));
            }
        }
    }
    return dp;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    REP(i, H) cin >> s[i];

    const int INF = H * W;
    
    int result = 0;
    REP(s_x, H) {
        REP(s_y, W) {
            auto dp = shortest_path(s, '#', s_x, s_y);
            REP(i, H) REP(j, W) {
                if (dp[i][j] != INF) {
                    amax(result, dp[i][j]);
                }
            }
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
S = input() 
K = int(input()) 
l = len(S)
ren = [0]*l
cnt = 0
 
for i in range(1,l):
  if S[i] == S[i-1]:
    cnt += 1
  elif S[i] != S[i-1]:
    ren[cnt] +=1
    cnt = 0
  if i == l-1:
    ren[cnt] +=1
    
ren = [K*i for i in ren]
   
if ren[l-1] or l ==1:
  print((l*K)//2)
  sys.exit()
  
if S[0]==S[-1]:
  start = 0
  while S[start]==S[start+1]:
    start += 1
  end = 0
  while S[-1-end]==S[-2-end]:
    end += 1
  ren[start+end+1] += K-1
  ren[start] -= K-1
  ren[end] -= K-1
 
 
ans = 0
 
for i in range(1,l):
  if i%2 ==0:
    ans += (i//2)*ren[i]
  else:
    ans += ((i+1)//2)*ren[i]
      
print(ans)

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


template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, n;
    cin >> h >> w >> n;
    //vector<int> y(h), x(w);
    int x[100010], y[100010];

    set<P> s;
    set<P> used;

    rep(i, 0, n){
        int a, b;
        cin >> a >> b;
        a--; b--;
        y[i] = a;
        x[i] = b;
        s.insert(make_pair(a, b));
    }

    ll ans[10];
    rep(i, 0, 10) ans[i] = 0;

    rep(i, 0, n){
        rep(j, 0, 9){
            //注目黒領域の近傍に注目する
            int cy = y[i] + dy[j];
            int cx = x[i] + dx[j];
            if(!(0 <= cy && cy < h && 0 <= cx && cx < w)) continue;
            if(used.count(make_pair(cy, cx)) == 1)continue;
            int cnt = 0;
            rep(k, 0, 9){
                int ny = cy + dy[k];
                int nx = cx + dx[k];

                if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) break ;//正方形が作れないとき
                if(s.count(make_pair(ny, nx)) == 1) cnt++;
                if(k == 8){
                    used.insert(make_pair(cy, cx));
                    ans[cnt]++;
                }
            }

        }
    }

    ll sum = 0;
    rep(i, 1, 10) sum += ans[i];
    cout << (h-2) * (w- 2) - sum << endl;
    rep(i, 1, 10) cout << ans[i] << endl;
    return 0;

}

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

int main() {
	//input
	int N;
	cin >> N;

	vector<int> A(N);
	for (int i = N - 1; i >= 0; i--) {
		cin >> A[i];
	}

	//calculation
	int64_t output = 0;
	int64_t sum = A[0];
	for (int i = 1; i < N; i++) {
		output += sum * A[i];
		if (output >= 1000000000 + 7) {
			output %= 1000000000 + 7;
		}
		sum += A[i];
		if (sum >= 1000000000 + 7) {
			sum -= 1000000000 + 7;
		}
	}

	//output
	cout << output << endl;


	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define E(a) cout << #a << ' ' << a << '\n'


const ll M=5e5+5,LG=17,inf=1e18;

int n,m;

ll a[M];

int main()
{
	cin >> n;
	For(i,0,n)
	{
		cin >> a[i];
		a[i]--;
	}
	ll cnt=0;
	For(i,0,n-1)
	{
		if (a[i]==i)
		{	
			swap(a[i],a[i+1]);
			cnt++;
		}
	}
	cout << cnt+(a[n-1]==n-1);
}


Measured memory_bytes: 1024
//Tonight's the night and it is going to happen again and again.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define T ll t; cin>>t; while(t--)
#define mod 1000000007
#define f(n) for(ll i = 0;i<n;i++)
#define endl "\n"
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
    int x;cin>>x;
    if(x>=30){cout<<"Yes";}else{cout<<"No";}
}

Measured memory_bytes: 3636
package main

import (
	"fmt"
	"math"
)

var W, H, x, y, ans float64

func main() {
	fmt.Scan(&W, &H, &x, &y)

	if x == W/2 && y == H/2 {
		fmt.Println(W*H/2, 1)
	} else {
		fmt.Println(W*H/2, 0)
	}
}

/*  ----------------------------------------  */

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}
type SortBy []XY

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y > a[j].y
	}
	return a[i].x > a[j].x
}


Measured memory_bytes: 512
#!/bin/bash
read name
read name2
namelen=${#name}
name2len=$((${#name2} - 1))
if [ $namelen -eq $name2len ]; then
	if [ $name = ${name2:0:namelen} ]; then
    	echo "Yes"
    else
    	echo "No"
    fi
else
	echo "No"
fi

Measured memory_bytes: 3724
// https://atcoder.jp/contests/abc130/tasks/abc130_b

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main() 
{
    ll n,x,d,sum=1;
    cin >> n >> x;
    ll p; 
    cin >> p;
    d = 0;
    for (ll i=0; i<n-1; i++)
    {
        d += p;
        if (d<=x) sum++;
        ll l;
        cin >> l;
        p = l;
    }
    d += p;
    if (d<=x) sum++;
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template<class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template<class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int H,W;
    cin>>H>>W;
    vector<string> s(H);
    cin>>s;
    vector<vector<int>> ans(H,vector<int>(W,-1));
    REP(i,H) {
        REP(j,W) {
            int cnt=0;
            REPR(k,j) {
                if(s[i][k]=='c') {
                    ans[i][j]=cnt;
                    break;
                }
                cnt++;
            }
        }
    }
    REP(i,H) {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


int main(){
    int L,R,d;
    cin>>L>>R>>d;
    int cnt=0;
    FOR(i,L,R+1)if(i%d==0)cnt++;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3628
# coding: utf-8
# Your code here!
A, B, C, K = map(int, input().split())
ans=0
i=0

if K==A:
    print(A)
elif K<A:
    print(K)
elif K>A:
    if A+B>=K:
        print(A)
    elif A+B<=K:
        HIKU=K-(A+B)
        print(A-HIKU)



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


int main() {
    int A, B, C; cin >> A >> B >> C;

    if (A == B && B != C) {
        cout << "Yes" << endl;
    }else if (B == C && C != A) {
        cout << "Yes" << endl;
    }else if (C == A && A != B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  cin >> s;
  int n = s.size();

  vi ans(n), m(n), l;

  rep(i, n-1) {
    if (s[i] == 'R' && s[i+1] == 'L') {
      m[i] = 1;
      l.push_back(i);
    }
  }

  rep(i, n) {
    if (s[i] == 'R') {
      int ind = *lower_bound(all(l), i);
      int dis = abs(ind - i);
   //   cerr << ind << " " << dis << endl;
      ans[ind+dis%2]++;
    } else {
      int ind = *(lower_bound(all(l), i)-1);
      int dis = abs(ind - i);
  //    cerr << ind << " " << dis << endl;
      ans[ind+dis%2]++;
    }

  }
//  rep(i, n) cerr << ans[i];
//  cerr << endl;

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


Measured memory_bytes: 1616
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
ll p[200010];
int main(){
    cin>>N;
    ll inf=40000;
    for(ll i=0;i<N;i++){
        ll a;cin>>a;
        p[a-1]=i;
    }

    for(ll i=0;i<N;i++)cout<<inf*(i+1)+p[i]<<" ";
    cout<<endl;
    for(ll i=0;i<N;i++)cout<<inf*(N-i)<<" ";
    cout<<endl;
    return 0;
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
#define log2(x) (log(x)/log(2))
#define ln '\n'
#define bln(i,n) ((i==n-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;

bool ok(string &s) {
	int a[26] = {};
	each(i,s) a[i-'a']++;
	rep(i,26) if (a[i]>=2) return false;
	return true;
}

signed main() {
	cin >> s;
	int n = s.size();
	if (s>="zyxwvutsrqponmlkjihgfedcba") return cout << -1 << ln, 0;
	
	int a[26] = {};
	bool ka = false;
	each(i,s) {
		a[i-'a']++;
		if (a[i-'a']>=2) ka = true;
	}
	
	int cnt = 0;
	rep(i,26) if (a[i]) cnt++;
	if (!ka && cnt<=25) {
		cout << s;
		rep(i,26) if (!a[i]) return cout << (char)('a'+i) << ln, 0;
	}
	
	repr(i,n-1) {
		while (s[i]<='z') {
			s[i]++;
			if (s[i]<='z' && ok(s)) return cout << s << ln, 0;
		}
		s.pop_back();
		if (i==0) return cout << -1 << ln, 0;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>

using namespace std;

int main() {
  int x;
  cin>>x;
  int ans = (x/500)*1000 + ((x%500)/5)*5;
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
#0や1のケースに注意
#index out of range

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    tugi = [0]*n
    tugi[0] = 1
    s = 0
    cnt = 1
    while 1:
        s = a[s] - 1
        cnt += 1
        if tugi[s] > 0:
            break
        tugi[s] = cnt
    cnt -= 1
    if cnt-1 >= k:
        for i in range(n):
            if tugi[i]==k+1:
                print(i+1)
    else:
        #s=ループスタート
        loop = [s]
        for i in range(cnt - (tugi[s]-1)-1):
            s = a[s] - 1
            loop.append(s)
        s = a[s]-1
        amari = (k-(tugi[s]-1)) % (len(loop))
        print(loop[amari]+1)

if __name__ == '__main__':
    main()

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

// #define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;

using ll = long long;

int N, A[303], C[4];
double dp[303][303][303];

signed main() {
  cin >> N;
  rep(i, 0, N) cin >> A[i];
  rep(i, 0, N) C[A[i]]++;

  rep(c3, 0, N + 1) rep(c2, 0, N + 1) rep(c1, 0, N + 1) {
      int sm = c1 + c2 + c3;
      if (sm == 0) continue;

      dp[c1][c2][c3] = 1.0 * N / sm;
      if (c1) dp[c1][c2][c3] += dp[c1 - 1][c2][c3] * c1 / sm;
      if (c2) dp[c1][c2][c3] += dp[c1 + 1][c2 - 1][c3] * c2 / sm;
      if (c3) dp[c1][c2][c3] += dp[c1][c2 + 1][c3 - 1] * c3 / sm;
  }

  coutd(dp[C[1]][C[2]][C[3]]);
}


Measured memory_bytes: 217344