akhauriyash/Code-Regression huggingface dataset:
nums = list(map(int, input().split()))
x = nums[2] -nums[0]
y = nums[3] - nums[1]
a = 'R' * x + 'U'* y
b = 'L' * x + 'D'* y
c = 'D' + 'R' * (x+1) + 'U'* (y+1) + 'L'
d = 'U' + 'L' * (x+1) + 'D'* (y+1) + 'R'
print(a+b+c+d)

Measured memory_bytes: 3064
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int m;
pair < int , int > pp[N];

int main(){
    cin >> n >> m;
    int mn = 1e5;
    int mx = 0;
    for(int i = 1; i <= m; i++){
        int l , r;
        cin >> l >> r;
        pp[i] = {l , r};
        mx = max(mx , l);
        mn = min(mn , r);
    }
    if(mn < mx){
        cout << 0 << endl;
    } else {
        cout << mn - mx + 1 << endl;
    }
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

using ll = long long;
using ull = unsigned long long;
using veci = vector<int>;
using vecll = vector<ll>;
using vecull = vector<ull>;

int A, B;

int main(void) {
    cin >> A >> B;

    cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            IO io = new IO();

            //ここから
            int n, k;
            int[] str = io.ReadLineToIntArray();
            n = str[0];
            k = str[1];
            int[] height = new int[n];
            for(int i = 0; i < n; i++)
            {
                height[i] = io.ReadLineToInt();
            }
            height = height.OrderBy(h => h).ToArray();

            int min = int.MaxValue;
            for(int i = 0; i < n - k+1; i++)
            {
                int temp = height[i + k - 1] - height[i];
                if (min > temp)
                {
                    min = temp;
                }
            }

            //ここまで
            Console.Write(min);
            Console.ReadKey();
        }
    }

    //関数
    public class Func
    {
        public void Swap<T>(ref T a,ref T b)
        {
            T temp;
            temp = a;
            a = b;
            b = temp;
        }
    }

    //IOを担う関数群
    public class IO
    {
        //stringの入力
        public string ReadLineToString()
        {
            return Console.ReadLine();
        }

        //intの入力
        public int ReadLineToInt()
        {
            return int.Parse(Console.ReadLine());
        }

        //空白区切りの複数の文字列の入力をstring[]にして返す
        public string[] ReadLineToStringArray()
        {
            return Console.ReadLine().Split(' ').ToArray();
        }


        //空白区切りの複数の整数の入力をint[]にして返す
        public int[] ReadLineToIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        //空白区切りの複数の文字列の入力をList<string>で受け取る
        public List<string> ReadLineToStringList()
        {
            return Console.ReadLine().Split(' ').ToList();
        }

        //空白区切りの複数の整数の入力をList<int>で受け取る
        public List<int> ReadLineToIntList()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }

}


Measured memory_bytes: 18396
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  ll x;
  cin >> x;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];

  ll ans = 0;
  for(int i = 0;i < n-1;i++){
    if(a[i] + a[i+1] > x){
      ll a_0 = a[i];
      ll a_1 = a[i+1];
      a[i+1] = max(x - a[i],(ll)0);
      a[i] = max((ll)0,x - a[i+1]);
      ans += a_1 - a[i+1];
      ans += a_0 - a[i];
    }
  }

  reverse(a.begin(),a.end());

  for(int i = 0;i < n-1;i++){
    if(a[i] + a[i+1] > x){
      ll a_0 = a[i];
      ll a_1 = a[i+1];
      a[i+1] = max(x - a[i],(ll)0);
      a[i] = max((ll)0,x - a[i+1]);
      ans += a_1 - a[i+1];
      ans += a_0 - a[i];
    }
  }

  cout << ans << endl;


}


Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



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

	if ((a*b) % 2 == 0)
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int n,ans=0;
  int p[21];
  cin>>n;
  for(int i=1;i<=n;i++) cin>>p[i];
  for(int i=2;i<n;i++) if(p[i-1]<p[i]&&p[i]<p[i+1]||p[i-1]>p[i]&&p[i]>p[i+1]) ans++;
  cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n,k,q;
  cin >> n >> k >> q;
  
  vector<int> cont(n);
  
  for(int i = 0 ; i < q ; i++){
    int a;
    cin >> a;
    a--;
    cont.at(a)++;
  }
  
  for(int i = 0 ; i < n ; i++){
    cont.at(i) += k-q;
    if(cont.at(i) < 1){
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}


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

using namespace std;

priority_queue<int> pq;
int N;
int ans;

int main() {
	scanf("%d", &N);
	for(int i = 1; i <= 2 * N; i++) {
		int x; scanf("%d", &x);
		pq.push(x);
	}
	for(int i = 1; i <= N; i++) {
		int a = pq.top(); pq.pop();
		int b = pq.top(); pq.pop();
		ans += min(a, b);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(len(A)):
    B.append(A[i]*2)
B_2 = []
for i in range(len(B)):
    if i%2 != 0:
        B_2.append(B[i])
    else:
        pass


C = []
C.append(sum(A) - sum(B_2)) 

for i in range(len(A)-1):
    C.append(B[i]-C[i])
for i in range(len(C)):
    C[i] = str(C[i])

answer = ' '.join(C)
print(answer)

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

int r[100001],t[100001],a[100001],now,ans,tmp,dir=-1;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int X,K;
	cin>>X>>K;
	for(int i=1;i<=K;i++)
		cin>>r[i];
	int q;
	cin>>q;
	for(int i=1;i<=q;i++)
		cin>>t[i]>>a[i];
	int M=X,m=0,t1=0,t2=1;
	while(t2<=q){
		if(t1!=K&&t[t2]>r[t1+1]){
			t1++;
			now=dir*(r[t1]-r[t1-1]);
			M=max(0,min(M+now,X));
			m=max(0,min(m+now,X));
			tmp+=now;dir*=-1;
		}
		else{
			ans=max(m,min(M,a[t2]+tmp));
			ans=max(0,min(X,ans+dir*(t[t2]-r[t1])));
			cout<<ans<<'\n';
			t2++;
		}
	}

}


Measured memory_bytes: 2432
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int n;
    cin>>n;
    set<long long>S;
    for(int i =1;i<=n;i++)
    {
        long long temp;
        cin>>temp;
        if(S.count(temp)==0)S.insert(temp);
        else if(S.count(temp)==1)S.erase(temp);
    }
    cout<<S.size()<<endl;
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <complex>
#include <cmath>
#include <stdio.h>

using namespace std;

typedef complex<double> P;

const double PI = acos(-1.0);

int main(){
	int N, D;
	while(cin >> N >> D, N){
		P p = P(0,0); double dir = PI/2;
		for(int i=0;i<N;i++){
			int L, R, T; cin >> L >> R >> T;
			if(L==R){
				p = p + T*L/180.0*PI*P(cos(dir), sin(dir));
			}
			else {
				double r = R == 0 ? D : ((double)L/R+1)/((double)L/R-1)*D;
				P c = p + P(cos(dir), sin(dir))*P(0,-1)*r;
				double agl = (r > 0 ? -L/abs(r+D) : R/abs(r-D))*T*PI/180.0;
				dir += agl;
				p = (p-c)*P(cos(agl), sin(agl))+c;
			}
		}
		printf("%.8lf\n%.8lf\n", real(p), imag(p));
	}
}

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

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

    long long a[n];

    for(long long i = 0; i < n; i++) cin >> a[i];

    long long ans = x;

    for(long long i = 0; i < n; i++){
        long long cnt = 0;
        long long start = 1;

        while(start <= d){
            start += a[i];
            cnt++;
        }
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
typedef long long ll;

ll n;
ll ans;

int main()
{
    scanf("%lld", &n);

    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ll d = i - 1;

            if (d != 0 && n / d == n % d) {
                ans += d;
            }

            d = n / i - 1;

            if (d != 0 && n / d == n % d) {
                ans += d;
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, K = list(map(int, sys.stdin.buffer.readline().split()))
H = list(map(int, sys.stdin.buffer.readline().split()))

H.sort(reverse=True)
ans = sum(H[K:], 0)
print(ans)


Measured memory_bytes: 21972
import heapq
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = list(map(lambda x: x*(-1), A)) 

heapq.heapify(A) # リストを優先度付きキューへ

for i in range(M):
  num = heapq.heappop(A)
  num = ((-1)*num) //2 
  #単純にnum = num//2とすると
  #num = -9のとき num//2 = -5になってしまう
  #(cf)num == 9のときは num//2 = 4
  num = -num
  heapq.heappush(A,num)
  
ans = -sum(A)
print(ans)

Measured memory_bytes: 14180
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  ll N;
  cin >> N;
  int x = 26;
  vector<int> v;
  while (1) {
    ll tmp = N / x;
    if (tmp == 0) {
      if (N % x != 0) {
        v.push_back(N % x);
      }
      v.push_back(N / x);
      break;
    }

    v.push_back(N % x);
    if (N % x == 0) {
      tmp--;
    }
    N = tmp;
  }

  for (int i = v.size() - 2; i >= 0; i--) {
    if (v[i] == 0) {
      printf("z");
      continue;
    }
    printf("%c", 'a' - 1 + v[i]);
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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; }

int main(){
  int n;
  cin >> n;
  for(int i=0;i<20;i++){
    if(i*1000 - n >= 0){
      cout << i*1000 - n << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3632
/*
Submitted With (^^) by -> Hossam ^_^
 _____________________
|     ___     ___     |
|    (^_^)   (^_^)    |
|   /( | )\_/( | )\   |
|_____|_|_____|_|_____|
*/

#include <bits/stdc++.h>

using namespace std;

inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
}

#define X first
#define Y second
#define ll long long
#define inf (0x7fffffffffffffff)
#define all(x) x.begin(), x.end()
#define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;

const int mod = (int)1e9 + 7;
const int MX = (int)2e5 + 5;

const int MAX_NODES = 5000 * 1000;

int n, k;
string res;

struct Trie{

	int sz;
	int t[MAX_NODES][26];

	Trie(){
		memset(t, 0xff, sizeof t);
		// memset(cnt, 0, sizeof cnt);
		sz = 0;
	}

	void insert(string s){
		int node = 0;
		for(int i = 0; i < s.size(); ++i){
			if(t[node][s[i] - 'a'] == -1)
				t[node][s[i] - 'a'] = ++sz;
			// ++cnt[node][s[i] - 'a'];
			node = t[node][s[i] - 'a'];
		}
	}

	void find(int node){
        
        if(k == 0){
            cout << res << endl;
            exit(0);
        }

        for(int i = 0; i < 26; ++i){
            if(t[node][i] != -1){
                node = t[node][i];
                k--;
                res.push_back((char)('a' + i));
                find(node);
                res.pop_back();
            }
        }

	}

}trie;

int main()
{
    prep();

    string s;

    cin >> s >> k;
    n = s.size();

    // for(int i = 0; i < n; ++i){
    //     string cur = s.substr(i);
    //     // cerr << cur << endl;
    //     trie.insert(cur);
    // }

    // trie.find(0);

    vector<string> vv;
    for(int i = 0; i < n; ++i){
        for(int len = 1; len <= 5 && i + len <= n; ++len){
            vv.push_back(s.substr(i, len));
        }
    }

    sort(all(vv));
    auto it = unique(all(vv));
    // for(auto x : vv){
    //     cout << x << endl;
    // }
    cout << vv[k - 1] << endl;
    
    // ZXC
    return 0;
}

Measured memory_bytes: 509436
/*input
ABC
*/
#include "bits/stdc++.h"
using namespace std;
const long long md = 1e9 + 7;
long long a[1000005], n;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s;cin>>s;
	cout << s[0] << char(s[1]^('R'^'B')) << s[2] << endl;;
}

Measured memory_bytes: 3660
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=1e6+1000;
const int mod=1e9+7;
int ksm(int num,int t){
    int res=1;
    for(;t;t>>=1,num=1ll*num*num%mod){
        if(t&1)res=1ll*res*num%mod;
    }
    return res;
}
int inv(int num){return ksm(num,mod-2);}
int main(){
    int n;cin>>n;
    ll ans=0;
    rep(i,1,n)ans=(ans+inv(1ll*ksm(3,i)*n%mod*(n+1-i)%mod))%mod;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
  int n, t[100010];
  string s[100010], x;
  int ans = 0, sub;
  
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> t[i];
  }
  
  cin >> x;

  for (int i = 0; i < n; i++) {
      if (s[i] == x) {
          sub = i;
          break;
      }
  }

  for (int i = sub+1; i < n; i++) {
      ans += t[i];
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;

int main(void) {
	int n=0;
	vector<string> r;
	cin >> n;
	for (int i=0; i<n; i++)
	{
		int a=0,b=0,c=0;
		scanf("%d %d %d",&a,&b,&c);
		if ((a*a+b*b==c*c)||(b*b+c*c==a*a)||(c*c+a*a==b*b))
		{
			r.push_back("YES");
		} else {
			r.push_back("NO");
		}
	}
	for (int i=0; i<n; i++)
	{
		cout << r[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define lint long long

using namespace std;

int main()
{
  int a,b,c;
  cin >> a >> b >> c;

  set<int> box;
  box.insert(a);
  box.insert(b);
  box.insert(c);
  if(box.size()==2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

input = sys.stdin.readline

D = int(input())
c = np.array(list(map(int, input().split())), dtype=int)
S = np.array([list(map(int, input().split())) for _ in range(D)], dtype=int)
T = np.array([int(input()) for _ in range(D)], dtype=int)
dissatis = np.zeros(26, dtype=int)

v = 0
for i, (s, t) in enumerate(zip(S, T)):
    v += s[t-1]
    dissatis += c
    dissatis[t-1] = 0
    v -= np.sum(dissatis)
    print(v)


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

int main()
{
  long long int n,wt;
  cin>>n>>wt;

  long long int w[n],val[n],i,j,ans;

  for(i=0;i<n;i++)
    cin>>w[i]>>val[i];

  long long int dp[n+1][wt+1];

  for(i=0;i<=n;i++)
  {
    for(j=0;j<=wt;j++)
    {
      if(i==0 || j==0)
        dp[i][j]=0;
      else if(w[i-1]<=j)
        dp[i][j]=max(val[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
      else
        dp[i][j]=dp[i-1][j];
    }
    //ans=dp[][j];
  }


  cout<<dp[n][wt]<<endl;

return 0;
}


Measured memory_bytes: 79104
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
const int Max=10000000;
bool prime[Max];
int main(void){
    int in;
    for(int i=0;i<Max;i++)prime[i]=true;
    prime[1]=false;
    for(int i=2;i<Max;i++){
        if(prime[i]){
            for(int s=i*2;s<=Max;s+=i)prime[s]=false;
        }
    }
    while(cin>>in){
        int cnt=0;
        for(int i=1;i<=in;i++){
            if(prime[i])cnt++;
        }
        cout << cnt << "\n";
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}

int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

	IOS
	
	ll n;
	cin>>n ;
	ll ans=0;
	for(ll i=1;i<=n;i++)
		ans+=i*(n-i+1);

	for(ll i=0;i<n-1;i++)
	{
		ll x ,y;
		cin>>x>>y;
		if(x>y) swap(x,y);
		ans-=x*(n-y+1);
	}

	cout<<ans<<endl;
 
	
	return 0;
}

Measured memory_bytes: 3640
#!/usr/bin/python3
# -*- coding: utf-8 -*-



S = str(input())+"R"
N = len(S)
state = [0 for _ in range(N)]

rs = [0,0] ## [num,index]
ls = [0,0] ## [num,index]
for i,c in enumerate(S):
  if c == "R":
    if ls[0] == 0:
      rs[0] += 1
      rs[1] = i
    else:
      state[ls[1]] += ls[0]//2+ls[0]%2
      state[ls[1]-1] += ls[0]//2
      ls = [0,0]
      rs = [1,i]
  elif c == "L":
    if rs[0] == 0:
      ls[0] += 1
    else:
      state[rs[1]] += rs[0]//2+rs[0]%2
      state[rs[1]+1] += rs[0]//2
      rs = [0,0]
      ls = [1,i]     

for i in range(N-1):
  print(state[i],end=" ")
print()

Measured memory_bytes: 51552
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<fstream>
#include<vector>
#include<stack>

using namespace std;
#define ll long long
#define mem(i,j) memset(i,j,sizeof i)
#define up(i,j,k) for(int i=j;i<k;i++)
#define uup(i,j,k) for(int i=j;i>=k;i--)
#define mod(x) (x)%mod
#define sfi(i) scanf("%d",&i)
#define sfs(i) scanf("%s",i)
#define sfc(i) scanf("%c",&i)
#define sfl(i) scanf("%lld",&i)
#define sfd(i) scanf("%lf",&i)
#define sff(i) scanf("%f",&i)
#define wt(a) cout<<"This is:"<<a<<endl
#define sf() cout<<"This is a flag"<<endl

const int N = 1010;
const ll llinf = 0x7fffffffffffffff;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int MAX = 5e2 + 5;

int main()
{
	int a, b, c, d;
	sfi(a);
	sfi(b);
	sfi(c);
	sfi(d);
	printf("%d\n", min(a, b) + min(c, d));
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <unordered_map>
#include <algorithm>
#include <cmath>

using namespace std;

// typedef
typedef long long ll;

// container util
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(c) int((c).size())
#define EACH(i,c) for(auto (i)=(c).begin(); (i)!=(c).end(); ++(i))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))

// repetition
#define FOR(i,m,n) for(ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for(ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)

// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl

// constant
const double    EPS     = 1e-10;
const int       INFTY   = (1<<21);
const ll        MOD     = (ll) 1e9+7;

// clear memory
#define CLR(a) memset((a),0,sizeof(a))

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << " " << __FILE__ << endl


int main() {
    ll m, n; cin >> m >> n;
    int max_e = 0;
    unordered_map<int, int> p;
    FOR(i, 2, sqrt(n)+1) {
        while(n % i == 0) {
            p[i]++;
            max_e = max(max_e, p[i]);
            n /= i;
        }
    }
    if(n > 1) {
        p[n]++;
        max_e = max(max_e, p[n]);
    }

    int N = max_e+m-1;
    vector<ll> combi((N+1)*(max_e+1));
    FOR(i, 1, N+1) {
        FOR(j, 1, max_e+1) {
            if(j > i)  combi[i*(max_e+1)+j] = 0;
            if(j == 1) combi[i*(max_e+1)+j] = i;
            else combi[i*(max_e+1)+j] = (combi[(i-1)*(max_e+1)+j] + combi[(i-1)*(max_e+1)+j-1]) % MOD;
        }
    }
    ll ans = 1;
    EACH(i, p) {
        ans = (ans*combi[(i->second+m-1)*(max_e+1)+i->second]) % MOD;
    }
    cout << ans << endl;
    return 0;
}
/*
D - Factorization
https://atcoder.jp/contests/abc110/tasks/abc110_d
*/


Measured memory_bytes: 23680
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };



char s[301][301];
char c[301][301];

int main() {
	int N;
	cin >> N;
	REP(i, N) {
		REP(j, N) {
			cin >> s[i][j];
		}
	}
	int ans = 0;
	REP(A, N) {
			REP(i, N){
				REP(j, N) {
					c[(i + A) % N][j] = s[i][j];
				}
			}
			int cnt = 0;
			bool ok = true;
			while (cnt <N) {
				FOR(i, cnt, N) {
					if (c[i][cnt] != c[cnt][i]) {
						ok = false;
						break;
					}
				}
				cnt++;
				if (!ok)break;
			}
			if(ok)ans++;
	}
	cout << ans*N << endl;
	return 0;
}

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

int main() {
    int N; cin >> N;
    while(N--) {
        int x, y, a, b; cin >> x >> y >> a >> b;
        int ans = x * a + y * b;
        ans = min(ans, 4*(x*max(a,5)+y*max(2,b))/5);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int H, A, B;
  int ans = 0;
  
  cin >> H >> A >> B;

  for(int i=A;i<=B;i++)
    ans += H%i == 0;

  cout << ans << endl;
  
  return 0;
}




Measured memory_bytes: 3100
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = input()

cnt = 0
for i in range(len(s)//2):
    if s[i] != s[-1-i]:
        cnt += 1
print(cnt)

Measured memory_bytes: 9252
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
		int t = 1;
		t = Integer.parseInt(reader.readLine());
		System.out.println(t<30?"No":"Yes");
	}
}

Measured memory_bytes: 32500
fn main() {
    let r: u32 = read();
    println!("{}", r * r);
}








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

// 標準入力から一行を読み取り、指定の型に変換する関数
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

// 標準入力からn行を読み取り、各行を空白文字で分割し、各要素を指定の型に変換する関数
pub fn read_vec2<T: std::str::FromStr>(n: u64) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int n=N%10;
		if(n==2||n==4||n==5||n==7||n==9) {
			System.out.println("hon");
		}
		else if(n==0||n==1||n==6||n==8) {
			System.out.println("pon");
		}
		else {
			System.out.println("bon");
		}
	}
}


Measured memory_bytes: 35716
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  int count;
  for(count=0;count<10000000;count++){
    sort(a,a+3);
    if(a[0] == a[1] && a[1] == a[2]){
      break;
    }
    if(a[1]-a[0] >= 2){
      a[0]=a[0]+2;
      continue;
    }

    a[0]=a[0]+1;
    a[1]=a[1]+1;
  }
  cout << count << endl;
  return 0;
}

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

int n, a[1025][1025], vis[1025];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (a[x][a[x][0]] == i && vis[i] == 0 && vis[x] < 1) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 2 - 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;




int main(){
    int n;
    cin>>n;
    cout<<n*(n-1)/2-n/2<<endl;
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            if((n%2==1 && i+j!=n) ||(n%2==0 && i+j!=n+1)){
                cout<<i<<' '<<j<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;


int main() {
	int n;
	cin >> n;
	int p[n];
	rep(i,n) {
		cin >> p[i];
	}
	int ans = 0;	
	rep(i,n-2) {
		if((p[i] < p[i+1] && p[i+1] < p[i+2]) ||  (p[i] > p[i+1] && p[i+1] > p[i+2])) {
			++ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a + 1):
    p = 500 * i
    for j in range(b + 1):
        q = 100 * j
        for k in range(c + 1):
            r = 50 * k
            if p + q + r == x:
                count += 1
                
print(count)

Measured memory_bytes: 3060
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD2 1000000007
#define MOD 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
typedef pair<int, int> pr;
typedef vector<int> VI;
typedef vector<pr> VP;
typedef vector<string> VS;
typedef vector<vector<int>> VV;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
int fast_pow(int x, int y, int p);
int dp[101][100001];

void solve() {
    int n,W;
    cin>>n>>W;
    int w[n],val[n];
    for(int i=0;i<n;i++){
        cin>>val[i]>>w[i];
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=100000;j++){
            dp[i][j]=INT_MAX;
        }
    }
    dp[0][0]=0;
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=100000;j++){
            dp[i][j]=dp[i-1][j];
            if(j-w[i-1]>=0){
                dp[i][j]=min(dp[i][j],val[i-1]+dp[i-1][j-w[i-1]]);
            }
            if(dp[i][j]<=W){
                ans=max(ans,j);
            }
        }
    }
    cout<<ans<<endl;
}

int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

Measured memory_bytes: 79232
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main()
	{
		int N = GetInt();
		int M = GetInt();

		var uf = new UnionFind(262144);
		var setL = new HashSet<int>();
		for(int i = 0; i < N; i++)
		{
			int K = GetInt();
			for(int j = 0; j < K; j++)
			{
				int L = GetInt() - 1;
				setL.Add(L);
				if(!uf.IsSame(i, N + L))
					uf.Merge(i, N + L);
			}
		}

		Console.WriteLine((uf.Size(0) == (N + setL.Count)) ? "YES" : "NO");
	}
}


public class UnionFind
{
	private int[] par = null;
	private int[] rank = null;
	private int[] ccSize = null;
	
	public UnionFind(int n)
	{
		par = new int[n];
		rank = new int[n];
		ccSize = new int[n];
		for(int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
			ccSize[i] = 1;
		}
	}

	public bool IsSame(int x, int y)
	{
		return (Root(x) == Root(y));
	}

	public int Root(int x)
	{
		if(par[x] == x)
			return x;

		int r = Root(par[x]);
		par[x] = r;
		return r;
	}
	
	public bool Merge(int x, int y)
	{
		int rx = Root(x);
		int ry = Root(y);
		if(rx == ry)
			return false;
		
		if(rank[rx] < rank[ry])
		{
			int tmp = rx;
			rx = ry;
			ry = tmp;
		}
		else if(rank[rx] == rank[ry])
			rank[rx]++;

		par[ry] = rx;
		ccSize[rx] = ccSize[rx] + ccSize[ry];
		return true;
	}

	public int Size(int x)
	{
		return ccSize[Root(x)];
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 28244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, l, s, t, g;
  g = 0;
  s = 0;
  t = 10000;
  in2(n, l);
  rep(i, n){
    s = s + l + i;
    if(abs(t) > abs(l + i))
      t = l + i;
  }
  out(s - t);
  memi;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
list=[]
i=0
j=0
l=0
m=0
o=0
c=max(a)
for i in range(n):
  if c!=a[i]:
    continue
  else:
    list.append(i)
if len(list)>1:
  for l in range(n):
    print(c)
else:
  del a[list[0]]
  d=max(a)
  for o in range(n):
    if o==list[0]:
      print(d)
    else:
      print(c)
      
    

Measured memory_bytes: 20448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	ll a,b,c; cin >> a >> b >> c;
	if(c-a-b<0){
		cout << "No"; return 0;
	}
	if(4*a*b < (c-a-b)*(c-a-b)) cout << "Yes";
	else cout << "No";

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;cin>>n;
	int x=0,y=0,z=0;
	for(int i=0;i<n;++i){int a;cin>>a;if(a%4==0)++x;else if(a%2==0)++y;else ++z;}
	if(x+(y==0)>=z)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    static final int[] dx = new int[]{1, 0, -1, 0};
    static final int[] dy = new int[]{0, 1, 0, -1};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();

        boolean[][] s = new boolean[H][W];
        for (int i = 0; i < H; i++) {
            String str = sc.next();
            for (int j = 0; j < W; j++) {
                s[i][j] = str.charAt(j) == '#' ? true : false;
            }
        }

        boolean isOk = true;
        loop:
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (s[i][j]) {
                    boolean tmpIsOk = false;
                    for (int k = 0; k < 4; k++) {
                        int ni = i + dx[k];
                        int nj = j + dy[k];

                        if (ni >= 0 && ni < H && nj >= 0 && nj < W && s[ni][nj]) {
                            tmpIsOk = true;
                        }
                    }

                    if (!tmpIsOk) {
                        isOk = false;
                        break loop;
                    }
                }

            }
        }

        if (isOk) {
            out.println("Yes");
        } else {
            out.println("No");
        }
    }
}

Measured memory_bytes: 25300
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

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

typedef pair<int ,int> P;


int main()
{

// N A B C X
// Y1 Y2 ... YN
    int N,A,B,C,X;
    while(cin >> N >> A >> B >> C >> X )
    {
        if( N == 0 && A==0 && B==0 && C==0 && X==0 ) { break;}
        deque<int> deq;
        int tmp;
        rep(i,N) { cin >> tmp; deq.push_back(tmp); }

        int count = 0;

        int x = X;
        while ( !( deq.empty() ) )
        {
            if( x == deq.front() )
            {
                deq.pop_front();
            }
            x = (A*x + B)%C;
            count++;
            if(count > 10001){break;}
        }
        if(count >10001 ){ cout << -1 <<endl;}
        else { cout << count-1 << endl; }
    }
    return 0;
}

Measured memory_bytes: 1196
n,k=map(int,input().split())
a=list(map(int,input().split()))
for _ in range(min(k,41)):
  b=[0]*(n+1)
  for i in range(n):
    l=max(0,i-a[i])
    r=min(n,i+a[i]+1)
    b[l]+=1
    b[r]-=1
  for i in range(n-1):
    b[i+1]+=b[i]
  a=b[:n]
print(*a)

Measured memory_bytes: 222104
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	w, h, n := iScan(), iScan(), iScan()
	p, q := 0, 0
	for i := 0; i < n; i++ {
		x, y, a := iScan(), iScan(), iScan()
		if a == 1 {
			p = larger(p, x)
		} else if a == 2 {
			w = smaller(w, x)
		} else if a == 3 {
			q = larger(q, y)
		} else if a == 4 {
			h = smaller(h, y)
		}
	}
	fmt.Println(larger(0, w-p) * larger(0, h-q))
}


Measured memory_bytes: 1776
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        int a,b;
        cin>>a>>b;
        printf("%d %d %.9f\n",a/b,a%b,1.*a/b);
        return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }


int main(){
    ll n,h; cin>>n>>h;
    vector<ll> a(n), b(n);
    rep(i,n) cin>>a[i]>>b[i];
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    ll res=0;
    rep(i,n){
        if(b[i]<a[0] || h<=0) break;
        h-=b[i];
        res++;
    }
    if(h>0){
        if(h%a[0]==0) res+=h/a[0];
        else res+=h/a[0] + 1;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const int N = 1e5 + 10;
vector<int> prime;
bool np[N];

int gcd(int m, int n){
	return n ? gcd(n, m%n) : m;
}

int main(){
	for (int i = 2; i < N; ++i){
		if(!np[i]){
			prime.push_back(i);
			for (int j = i * 2; j < N; j += i) np[j] = 1;
		}
	}

	int m, a, b;
	while (cin >> m >> a >> b, m){
		int g = gcd(a, b);
		a /= g, b /= g;

		tuple<int, int, int> ans = MT(0, 0, 0);
		rep(i, prime.size()){
			int p = prime[i];
			if (p*p > m) break;
			int lb = i, ub = prime.size();
			while (ub - lb > 1){
				int mid = (lb + ub) / 2;
				if (p*prime[mid] <= m && a*prime[mid] <= p*b) lb = mid;
				else ub = mid;
			}
			if (p*prime[lb] > m) continue;
			if (a*prime[lb] > p*b) continue;
			ans = max(ans, MT(p*prime[lb], p, prime[lb]));
		}
		int _, w, h;
		tie(_, w, h) = ans;
		cout << w << ' ' << h << '\n';
	}

	return 0;
}

Measured memory_bytes: 1408
// AOJ ALDS1_9_C Priority Queue
// 2018.4.27 bal4u

#include <stdio.h>

#define QSIZE 2000002

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

typedef struct { long long t; } QUE;
QUE que[QSIZE + 5];
int qsize;

void max_heapify(int i)
{
	int l, r, max;
	QUE qt;
	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t > que[i].t) max = l; else max = i;
	if (r < qsize && que[r].t > que[max].t) max = r;
	if (max != i) {
		qt = que[i], que[i] = que[max], que[max] = qt;
		max_heapify(max);
	}
}

void deq()
{
	que[0] = que[--qsize];
	max_heapify(0);
}

void enq(long long t)
{
	int i, max;
	QUE qt;

	i = qsize++;
	que[i].t = t;
	while (i > 0 && que[max = PARENT(i)].t < que[i].t) {
		qt = que[i]; que[i] = que[max], que[max] = qt;
		i = max;
	}
}


// バッファを経ずstdinから数値を得る
#define gc() getchar_unlocked()
//#define gc() getchar()
long long in()
{
	long long n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int main()
{
	int k;

	qsize = 0;
	while (1) {
		if (gc() == 'e') {
			if (gc() == 'n') break;
			k = 6; while (k--) gc();
			printf("%lld\n", que[0].t);
			deq();
		} else {
			k = 6; while (k--) gc();
			enq(in());
		}
	}
	return 0;
}



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

#define reint register int
#define coint const int

using namespace std;

typedef long long ll;

coint MOD = 998244353;
coint SIZE = 200000 + 5;

inline int getint(void) {
    reint x = 0, ch = getchar(), f = 0;
    for (; (ch < '0' || ch > '9') && ch != '-'; ch = getchar());
    if (ch == '-') f = 1, ch = getchar();
    for (; ch >= '0' && ch <= '9';
        x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar());
    return f ? -x : x;
}

inline ll mod(ll num) {
    if (num < 0) num += MOD;
    if (num >= MOD) num -= MOD;
    return num;
}

struct BinaryIndexedTree {
    int li[SIZE];

    inline void clear(void) { memset(li, 0, sizeof li); return; }
    BinaryIndexedTree(void) { clear(); return; }
    inline int lowbit(coint num) { return num & (-num); }

    inline void modify(coint ind, coint k) {
        for (reint i = ind; i < SIZE; i += lowbit(i)) li[i] += k;
        return;
    }

    inline ll query(coint ind) {
        register ll res = 0;
        for (reint i = ind; i; i -= lowbit(i)) res += li[i];
        return res;
    }
};

struct Point { int x, y; };

inline int cmpY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

Point li[SIZE];
BinaryIndexedTree bit;
int tmp[SIZE];
ll pow2[SIZE];

int main(void) {
    coint n = getint();
    for (reint i = 1; i <= n; ++i) li[i].x = getint(), li[i].y = getint();

    for (reint i = 1; i <= n; ++i) tmp[i] = li[i].x;
    sort(tmp + 1, tmp + n + 1);
    for (reint i = 1; i <= n; ++i)
        li[i].x = lower_bound(tmp + 1, tmp + n + 1, li[i].x) - tmp;
    for (reint i = 1; i <= n; ++i) tmp[i] = li[i].y;
    sort(tmp + 1, tmp + n + 1);
    for (reint i = 1; i <= n; ++i)
        li[i].y = lower_bound(tmp + 1, tmp + n + 1, li[i].y) - tmp;
    //for (reint i = 1; i <= n; ++i)
        //printf("{%d, %d}\n", li[i].x, li[i].y);

    pow2[0] = 1;
    for (reint i = 1; i <= n; ++i) pow2[i] = pow2[i - 1] * 2 % MOD;

    ll ans = n * (pow2[n] - 1) % MOD;
    for (reint i = 1; i <= n; ++i)
        ans = mod(ans - pow2[i - 1] + 1), ans = mod(ans - pow2[n - i] + 1),
        ans = mod(ans - pow2[i - 1] + 1), ans = mod(ans - pow2[n - i] + 1);

    sort(li + 1, li + n + 1, cmpY), bit.clear();
    for (reint i = 1; i <= n; ++i) {
        coint cnt = bit.query(li[i].x);
        ans = mod(ans + pow2[cnt] - 1);
        ans = mod(ans + pow2[i - 1 - cnt] - 1);
        bit.modify(li[i].x, 1);
        //printf("i = %d, cnt = %d\n", i, cnt);
    }
    bit.clear();
    for (reint i = n; i; --i) {
        coint cnt = bit.query(li[i].x);
        ans = mod(ans + pow2[cnt] - 1);
        ans = mod(ans + pow2[n - i - cnt] - 1);
        bit.modify(li[i].x, 1);
        //printf("i = %d, cnt = %d, x = %d\n", i, cnt, li[i].x);
    }

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

    return 0;
}



Measured memory_bytes: 4992