akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;
 
int main(){
 
  int n, k[100], x, i, j;
  string sta="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", s;
 
  while(cin>>n, n){
    for(i=0;i<n;i++) cin>>k[i];
    cin>>s;
 
    for(i=0;i<s.size();i++){
      for(j=0;j<56;j++){
	if(s[i]==sta[j]){
	  x=j-k[i%n];
	  if(x<0){
	    x+=52;
	    break;
	  }else break;
	}
      }
      cout<<sta[x];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3144
import sys
import bisect

readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    B = list(map(int, readline().split()))
    C = list(map(int, readline().split()))

    A.sort()
    C.sort()

    ans = 0
    for b in B:
        ansA = bisect.bisect_left(A, b)
        ansC = N - bisect.bisect_right(C, b)
        ans += ansA * ansC

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 22720
"use strict";

const main = arg => {
    const A = parseInt(arg.split("\n")[0].split(" ")[0]);
    const B = parseInt(arg.split("\n")[0].split(" ")[1]);
    const C = parseInt(arg.split("\n")[0].split(" ")[2]);
    console.log(A <= C && C <= B ? "Yes" : "No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9420
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
 cin.tie(0);
 ios::sync_with_stdio(false); 
  string s,w;
  cin>>s;
  w=s;
  bool f=false;
  reverse(w.begin(),w.end());
  if(s==w)f=true;
  for(int i=0;i<s.length();i++){
    if(w.substr(i,1)=="b"){
      w.replace(i,1,"d");
    }else if(w.substr(i,1)=="d"){
      w.replace(i,1,"b");
    }else if(w.substr(i,1)=="p"){
      w.replace(i,1,"q");
    }else if(w.substr(i,1)=="q"){
      w.replace(i,1,"p");
    }
  }
  if(s==w)f=true;
  if(f){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl; 
  }
  return 0; 
}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

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

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  cin >> n >> m;
  vector<string> a(n),b(m);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,m){
    cin >> b[i];
  }

  if(n == 1 ){
    cout << ((a[0] == b[0]) ? "Yes" : "No") << endl;
    return 0;
  }
  rep(i,n-m){
    rep(j,n-m){
      bool f = true;
      rep(k,m){
        rep(l,m){
          if(a[i+k][j+l] != b[k][l]) f = false;
        }
      }
      if(f) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> b(m);
    vector<ll> aa(n-1);
    vector<ll> bb(m-1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n-1; i++) {
        aa[i] = a[i + 1] - a[i];
    }
    for (int i = 0; i < m-1; i++) {
        bb[i] = b[i + 1] - b[i];
    }
    ll aaa=0;
    ll bbb=0;
    for (int i = 0; i < n - 1; i++) {
        aaa += aa[i] * (i + 1) % 1000000007 * (n - i-1) % 1000000007;
        aaa %= 1000000007;
    }
    for (int i = 0; i < m - 1; i++) {
        bbb += bb[i] * (i + 1) % 1000000007 * (m - i-1) % 1000000007;
        bbb %= 1000000007;
    }
    cout << aaa * bbb % 1000000007 << endl;
}

Measured memory_bytes: 3328
def get_prime(x):
    for i in range(2, x+1):
        amari = x%i
        #print(x,i, amari)
        if amari == 0:
            if i == x:
                return x
            else:
                return -1
        else:
            continue
    
    return x

X  = int(input())

flag = True
num = 0
answer = 0
while flag:
    v = X+num 
    if get_prime(v) > 0:
        flag = False
    num += 1

print(v)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String[] s = S.split("");
        boolean isa = true;
        int a = 0;
        int z = 0;
        for(int i=0; i<s.length; i++) {
            if(isa) {
                if(s[i].equals("A")) {
                    a = i;
                    isa = false;
                }
            }
            if(s[i].equals("Z")) z = i;
        }
        System.out.println(z-a+1);
     }
}

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

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll x = a * c;
  ll y = a * d;
  ll z = b * c;
  ll w = b * d;
  cout << max(max(max(x,y),z),w) << endl;
}

Measured memory_bytes: 3648
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(a<b) cout << "a < b" << endl;
    else if(a>b) cout << "a > b" << endl;
    else cout << "a == b" << endl;
}



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

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define br cout<<endl;
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
const int MAX = 100005;
const int INF = 1e9+7;
const ll LINF = 1e18 + 7;

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

int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    ll ar[n+5],ans=0;
    map<int, int>m;
    for(int i=0;i<n;i++)
    {
        ll a,r=0;
        cin>>a;
        ans^=a;
        while(a%2==0)
        {
            r++;
            a=a/2;
        }
        m[r]++;
    }
    ll x=1<<30,f=0,res=0;
    for(int i=30;i>=0;i--)
    {
        if(ans & x)
        {
            if(m[i])
            {
                ll c=x-1;
                ans^=c;
            }
            else
            {
                f=1;
                break;
            }
            res++;
        }
        x/=2;
    }
    if(f)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

#define maxn 1000010
int notp[maxn];
int vis[maxn];
int prm[maxn],tot;
int ai[maxn];

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

void sieve(int n){
	notp[1]=1;
	for(int i=2;i<=n;i++){
		if(!notp[i])
			prm[++tot]=i;
		for(int j=1;1ll*prm[j]*i<=n&&j<=tot;j++){
			notp[i*prm[j]]=1;
			if(i%prm[j]==0)
				break;
		}
	}
}

inline int readin(){
	int x=0,s=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')s=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*s;
}

int main(){
	int n,g;
	n=readin();
	sieve(1000001);
	for(int i=1;i<=n;i++)
		ai[i]=readin();
	g=ai[1];
	for(int i=2;i<=n;i++)
		g=gcd(g,ai[i]);
	if(g>1){
		puts("not coprime");
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(!notp[ai[i]])vis[ai[i]]++;
		else {
			for(int j=1;j<=100&&prm[j]<=ai[i];j++){
				if(ai[i]%prm[j]==0){
					vis[prm[j]]++;
				}
				while(ai[i]%prm[j]==0)
					ai[i]/=prm[j];
			}
			if(ai[i]>1)vis[ai[i]]++;
		}
	}
	for(int i=2;i<=1000000;i++)
		if(vis[i]>=2){
			puts("setwise coprime");
			return 0;
		}
	puts("pairwise coprime");
        return 0+0-0+0;
}

Measured memory_bytes: 15532
#include<bits/stdc++.h>
using namespace std;
template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<998244353>;

const int V = 5.01e6;
const int MAXV = int(V * 1.1);
num fact[MAXV];
num ifact[MAXV];
void precomp() {
	fact[0] = 1;
	for (int i = 1; i <= V; i++) fact[i] = fact[i-1] * num(i);
	ifact[V] = fact[V].inv();
	for (int i = V; i >= 1; i--) ifact[i-1] = ifact[i] * num(i);
}

num choose(int n, int r) {
	if (0 <= r && r <= n) return fact[n] * ifact[n-r] * ifact[r];
	else return 0;
}
num distribute(int n, int b) {
	return choose(n + b - 1, b - 1);
}

// good if:
// sum = 3M
// # odd <= M
// max <= 2M
// (each person gets <= M ops, but that's implied by max <= 2M)

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	precomp();

	int N, M;
	cin >> N >> M;

	num ans = distribute(3 * M, N);

	// subtract ones with max too big
	for (int i = 2 * M + 1; i <= 3 * M; i++) {
		ans -= num(N) * distribute(3 * M - i, N-1);
	}

	// subtract with too many odds
	for (int i = M+2; i <= N; i += 2) {
		ans -= choose(N, i) * distribute((3 * M - i) / 2, N);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 43264
#include<bits/stdc++.h>
//typedef long long ll;
//#define ull       unsigned long long
#define int       long long
#define F           first
#define S           second
#define endl        "\n"//<<flush
#define eps         1e-6
#define lowbit(x)   (x&(-x))
#define PI          acos(-1.0)
#define inf         0x3f3f3f3f
#define MAXN        0x7fffffff
#define INF         0x3f3f3f3f3f3f3f3f
#define pa          pair<int,int>
#define ferma(a,b)  pow(a,b-2)
#define pb          push_back
#define all(x)      x.begin(),x.end()
#define memset(a,b) memset(a,b,sizeof(a));
#define IOS         ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
void file()
{
#ifdef ONLINE_JUDGE
#else
    freopen("cin.txt","r",stdin);
    //  freopen("cout.txt","w",stdout);
#endif
}
signed main()
{
    IOS;
    //file();
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=1e6;i++)
    {
        double num=i;
        if((int)(num*0.08)==a&&(int)(num*0.1)==b)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;


    return 0;
}


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


void solve(long long A, long long B, long long K){
    if(A > K){
        A = A - K;
    }else{
        if(B > K - A){
            B = B - (K - A);
        }else{
            B = 0;
        }
        A = 0;
    }
    cout << A << " " << B << endl;
    return;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

using namespace std;
using ll = long long;

ll dp[200005][4];

int main() {
	int x,y,z;
	cin >> x >> y >> z;
	cout << z << ' ' << x << ' ' << y << ' ' << endl;
	return 0;
}


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

const int t[7][7] = {
	{0, 300, 500, 600, 700, 1350, 1650},
	{6, 0, 350, 450, 600, 1150, 1500},
	{13, 7, 0, 250, 400, 1000, 1350},
	{18, 12, 5, 0, 250, 850, 1300},
	{23, 17, 10, 5, 0, 600, 1150},
	{43, 37, 30, 25, 20, 0, 500},
	{58, 52, 45, 40, 35, 15, 0}
};

const int B = 17 * 60 + 30, E = 19 * 60 + 30;

int main()
{
	int id1, h1, m1;
	int id2, h2, m2;
	while (scanf("%d", &id1), id1){
		scanf("%d %d %d %d %d", &h1, &m1, &id2, &h2, &m2);
		if (id1 > id2) swap(id1, id2);
		int t1 = h1 * 60 + m1;
		int t2 = h2 * 60 + m2;
		--id1; --id2;
		int v = t[id1][id2];
		int l = t[id2][id1];
		bool f = true;
		if (l > 40) f = false;
		if (((B <= t1 && t1 <= E) || (B <= t2 && t2 <= E)) && f){
			v /= 2;
			int f = !!(v % 50);
			v = v / 50 * 50 + f * 50;
		}
		printf("%d\n", v);
	}
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <algorithm>
using namespace std;
int H, W, ra, o, a[40][40], sum[40][40]; pair<int, int> dp[40][40][40][40];
int rng(int x1, int y1, int x2, int y2) {
	return sum[y2][x2] + sum[y1][x1] - sum[y2][x1] - sum[y1][x2];
}
pair<int, int> solve(int x1, int y1, int x2, int y2) {
	if (dp[y1][x1][y2][x2].first != -1) return dp[y1][x1][y2][x2];
	int rng_ = rng(x1, y1, x2, y2);
	pair<int, int> ret = make_pair(1, rng_);
	for (int i = x1 + 1; i < x2; i++) {
		int petl = rng(x1, y1, i, y2);
		int petr = rng(i, y1, x2, y2);
		if (min(petl, petr) >= o) {
			pair<int, int> resl = solve(x1, y1, i, y2);
			pair<int, int> resr = solve(i, y1, x2, y2);
			pair<int, int> res = make_pair(resl.first + resr.first, min(resl.second, resr.second));
			ret = max(ret, res);
		}
	}
	for (int i = y1 + 1; i < y2; i++) {
		int petl = rng(x1, y1, x2, i);
		int petr = rng(x1, i, x2, y2);
		if (min(petl, petr) >= o) {
			pair<int, int> resl = solve(x1, y1, x2, i);
			pair<int, int> resr = solve(x1, i, x2, y2);
			pair<int, int> res = make_pair(resl.first + resr.first, min(resl.second, resr.second));
			ret = max(ret, res);
		}
	}
	//cout << y1 << ' ' << x1 << ' ' << y2 << ' ' << x2 << ' ' << ret.first << ' ' << ret.second << endl;
	return dp[y1][x1][y2][x2] = ret;
}
int main() {
	while (cin >> H >> W >> ra, H) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) cin >> a[i][j];
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				for (int k = i + 1; k <= H; k++) {
					for (int l = j + 1; l <= W; l++) dp[i][j][k][l].first = -1;
				}
			}
		}
		o = sum[H][W] - ra;
		pair<int, int> ret = solve(0, 0, W, H);
		cout << ret.first << ' ' << ret.second - o << endl;
	}
}

Measured memory_bytes: 12024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long l0 = 2; long l1 = 1;
		long li = 0;
		for(int i = 2; i <= n; i++) {
			li = l0+l1;
			l0 = l1; l1 = li;
		}
		System.out.println(n == 1 ? 1 : li);
		sc.close();
	}
}

Measured memory_bytes: 23764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace code_festival_2016_c {
    class Program {
        static void Main(string[] args) {
            bool c = false;
            bool f = false;
            string str = Console.ReadLine();
            for(int i = 0; i < str.Length; i++) {
                if (str[i] == 'C') {
                    c = true;
                }else if (str[i] == 'F' && c == true) {
                    f = true;
                }
            }
            Console.WriteLine((f)?"Yes":"No");
 
        }
    }
}

Measured memory_bytes: 2648
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int s;
  cin >> s;
  vector<int> v;
  v.push_back(s);
  long i = 0;
  while(true){
    if(v[i]%2==0){
      v.push_back(v[i]/2);
    }else{
      v.push_back(3*v[i]+1);
    }
    i++;
    for(int j = 0; j<i;j++){
      if(v[j]==v[i]){
        cout<<i+1;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
P1 = 0
P2 = 0

arr = list(map(int, input().strip().split()))
arr = sorted(arr)

for i in range(0,len(arr)):
  if i%2 == 0:
    P1 = P1+arr[i]
  elif i%2 ==1:
    P2 = P2+arr[i]
print(abs(P2-P1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MAX_N 200000
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, a[MAX_N+5]; lnt tot;
int main() {
	read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]), a[i] -= i;
	sort(a+1, a+n+1);
	for (int i = 1; i <= n; i++)
		tot += abs(a[i]-a[(n+1)/2]);
	return printf("%lld\n", tot), 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

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

  vector <int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  vector <int> B(N);
  bool flag = true;
  
  vector <int> ans;
  for (int i = N - 1; i >= 0; i--){
    int deg = B[i] % 2;

    if (deg != A[i]){
      ans.push_back(i + 1);

      int num = i + 1;
      for (int j = 1; j * j <= num; j++){
        if (j * j == num){
          B[j - 1] ++;
        }else if(num % j == 0){
          B[j - 1] ++;
          B[(num / j) - 1] ++;
        }
      }
    }
  } 

  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++){
    cout << ans[i];
    if (i == ans.size() - 1) cout << endl;
    else cout << " ";
  }
  


  return 0;
}

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(S: str):
    for i in range(2, len(S), 2):
        s = S[:len(S)-i]
        if s[:len(s)//2] == s[len(s)//2:]:
            print(len(s))
            break
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
#include<string>
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t;
  scanf("%d %d\n",&a,&b);
  cin >> u;
  if(s==u){
    a--;
  }
  else{
    b--;
  }
  printf("%d %d\n",a,b);
  return 0;
}

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

int main() {
  string str;
  map<char, int> count;
  cin >> str;
  for (auto charactor : str) {
    count[charactor] += 1;
  }

  bool is_different = true;
  for (auto itr : count) {
    if ( itr.second > 1 ) {
      is_different = false;
      break;
    }
  }
  cout << (is_different ? "yes" : "no") << endl;
}


Measured memory_bytes: 256
K=int(input())
from collections import deque
q=deque([i for i in range(1,10)])
for i in range(K-1):
    tmp=q.popleft()
    if tmp%10!=0:
        q.append(10*tmp+(tmp-1)%10)
    q.append(10*tmp+tmp%10)
    if tmp%10!=9:
        q.append(10*tmp+(tmp+1)%10)
print(q.popleft())


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

int main()
{
    string s;
    cin >> s;
    int A,B,C,D;
    A = (int)(s.at(0)-'0');
    B = (int)(s.at(1)-'0');
    C = (int)(s.at(2)-'0');
    D = (int)(s.at(3)-'0');

    int ppp = A+B+C+D;
    int ppm = A+B+C-D;
    int pmp = A+B-C+D;
    int pmm = A+B-C-D;
    int mpp = A-B+C+D;
    int mpm = A-B+C-D;
    int mmp = A-B-C+D;
    int mmm = A-B-C-D;
    if(ppp==7)
    {
        cout << A << '+' << B << '+' << C << '+' << D << "=7" << endl;
    }
    else if(ppm==7)
    {
        cout << A << '+' << B << '+' << C << '-' << D << "=7" << endl;
    }
    else if(pmp==7)
    {
        cout << A << '+' << B << '-' << C << '+' << D << "=7" << endl;
    }
    else if(pmm==7)
    {
        cout << A << '+' << B << '-' << C << '-' << D << "=7" << endl;
    }
    else if(mpp==7)
    {
        cout << A << '-' << B << '+' << C << '+' << D << "=7" << endl;
    }
    else if(mpm==7)
    {
        cout << A << '-' << B << '+' << C << '-' << D << "=7" << endl;
    }
    else if(mmp==7)
    {
        cout << A << '-' << B << '-' << C << '+' << D << "=7" << endl;
    }
    else if(mmm==7)
    {
        cout << A << '-' << B << '-' << C << '-' << D << "=7" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
using ll = long long;
using namespace std;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s, t;
    cin >> s >> t;
    SORT(s);
    RSORT(t);
    if (s < t)
        std::cout << "Yes" << '\n';
    else
        std::cout << "No" << '\n';

    return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    file_input = sys.stdin
    H, W = map(int, file_input.readline().split())
    side_length = 0
    prev = [0] * (W + 1)
    for line in file_input:
        tile_line = map(int, line.split())
        current = [0] * (W + 1)
        for i, tpl in enumerate(zip(tile_line, prev, prev[1:]), start=1):
            t, p1, p2 = tpl
            if t:
                current[i] = 0
            else:
                current[i] = min(p1, p2, current[i - 1]) + 1
        prev = current
        side_length = max(side_length, max(current))
    print(side_length ** 2)

solve()

Measured memory_bytes: 7728
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10; 
bool book[maxn];


int main(){
	int s;
	cin>>s;
	int ans = 1;
	//book[0]=false;
	while(!book[s]){
		book[s]=true;
		if(s%2==0){
			s = s/2;
		}
		else{
			s = 3*s+1;
		}
		ans++;
	} 
	cout<<ans;
} 

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

int main()
{
  int n,m;
  int a,b;
  int count=0;
  
  cin>>n>>m;
  
  vector<long long int> h(n);
  vector<int> check(n);
  fill(check.begin(),check.end(),0);
  
  for(int i=0;i<n;i++)
  {
    cin>>h[i];
  }
  
  for(int j=0;j<m;j++)
  {
    cin>>a>>b;
    
    if(h[a-1]<h[b-1])
    {
      check[a-1]=-1;
      if(check[b-1]==0)
      {
        check[b-1]=1;
      }
    }
    else if(h[a-1]==h[b-1])
    {
      check[a-1]=-1;
      check[b-1]=-1;
    }
    if(h[a-1]>h[b-1])
    {
      check[b-1]=-1;
      if(check[a-1]==0)
      {
        check[a-1]==1;
      }
    }
  }
  
  for(int s=0;s<n;s++)
  {
    if(check[s]==-1)
    {
      count++;
    }
  }
  
  cout<<n-count<<endl;
  
  return 0;
}

Measured memory_bytes: 4532
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    ll N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<string> s(N);
    for(auto& x: s) cin >> x;

    vector<char> ans(N);
    for(int i=0; i<N; i++){
        if(s[i] == "AB"){
            if(A == 0 && B == 0){
                cout << "No" << endl; return 0;
            }
            if(A < B){
                A++; B--;
                ans[i] = 'A';
            }else if(A > B){
                A--; B++;
                ans[i] = 'B';
            }else if(i!=N-1 && s[i+1]=="BC"){
                A--; B++;
                ans[i] = 'B';
            }else{
                A++; B--;
                ans[i] = 'A';
            }
        }

        else if(s[i] == "BC"){
            if(B == 0 && C == 0){
                cout << "No" << endl; return 0;
            }
            if(B < C){
                B++; C--;
                ans[i] = 'B';
            }else if(B > C){
                B--; C++;
                ans[i] = 'C';
            }else if(i!=N-1 && s[i+1]=="AC"){
                B--; C++;
                ans[i] = 'C';
            }else{
                B++; C--;
                ans[i] = 'B';
            }
        }

        else{
            if(C == 0 && A == 0){
                cout << "No" << endl; return 0;
            }
            if(C < A){
                C++; A--;
                ans[i] = 'C';
            }else if(C > A){
                C--; A++;
                ans[i] = 'A';
            }else if(i!=N-1 && s[i+1]=="AB"){
                C--; A++;
                ans[i] = 'A';
            }else{
                C++; A--;
                ans[i] = 'C';
            }
        }
    }

    cout << "Yes\n";
    for(int i=0; i<N; i++) cout << ans[i] << "\n";
}


Measured memory_bytes: 6436
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

int n, k;
vector < int > arr;

int cache[100010][2];

//Taro - 0, Jiro - 1
bool dpSol(int left, bool turn)
{
    if(left == 0)
        return !turn;
        
    int &res = cache[left][turn];
    
    if(res != -1)
        return res;
        
    bool chance = 0;
    bool atleast_one = 0;
    for(int i = 0; i < n; ++i)
    {
        if(left - arr[i] >= 0)
        {
            if(dpSol(left - arr[i], !turn) == turn)
                atleast_one = 1;
            chance = 1;
        }
    }
    
    if(!chance)
        return res = !turn;
    if(atleast_one == 1)
        return res = turn;
    return res = !turn;
}

int main()
{
    fastIO
    
    cin >> n >> k;
    arr = vector < int >(n);
    for(int i = 0; i < n; ++i)
        cin >> arr[i];
        
    memset(cache, -1, sizeof(cache));
        
    bool winner = dpSol(k, 0);
    if(winner)
        cout << "Second";
    else
        cout << "First";
        
    return 0;
}

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

#define int long long

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (3e15)

using namespace std;

int N, A, B, K;

int mod = 998244353;

int fac[300005];
int rev[300005];

int binpow(int x, int p) {
    if (p == 0) return 1;

    if (p % 2 == 0)
        return binpow((x * x) % mod, p / 2);
    else
        return (x * binpow(x, p - 1)) % mod;
}

int nCr(int n, int r) {
    if (r > n) return 0;
    return ((fac[n] * rev[r]) % mod * rev[n - r]) % mod;
}

void precalc(int n) {
    fac[0] = fac[1] = 1;
    FOR(i, 2, n + 2)
    fac[i] = (fac[i - 1] * i) % mod;

    rev[n + 1] = binpow(fac[n + 1], mod - 2) % mod;
    REV(i, n, 0) { rev[i] = (rev[i + 1] * (i + 1)) % mod; }
}

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

    cin >> N >> A >> B >> K;

    precalc(N + 1);

    int ans = 0;
    int amax = K / A;

    FOR(a, 0, amax) {
        int r = K - A * a;
        if (r % B != 0) continue;
        int b = r / B;
        ans = (ans + (nCr(N, a) * nCr(N, b)) % mod) % mod;
    }
    cout << ans % mod << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000
//bool cmp(P a,P b){ return a.second < b.second;}

ll N,M,ans=0;
ll A[100010];
P B[100010];
priority_queue<ll> Q;


int main(){
	std::ios_base::sync_with_stdio(false);
	cin>>N>>M;
	REP(i,N)cin>>A[i];
	ll count=0;
	REP(i,M){
		bool f=false;
		ll a,b;
		cin>>a>>b;
		B[i]={b,a};
	}
	sort(A,A+N);
	sort(B,B+M);
	REP(i,M){
		bool f=false;
		DEB(B[M-1-i].second)END
		REP(k,B[M-1-i].second){
			Q.push(B[M-1-i].first);
			count++;
			if(count>N){f=true;break;}
		}
		if(f)break;
	}
	REP(i,N){
		if(A[i]<Q.top()){
			A[i]=Q.top();
			Q.pop();
		}
		if(Q.empty())break;
	}
	REP(i,N){ans+=A[i];}

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

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    vector<int> a(N);
    int k;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (i == 0) {
            k = 1;
        }
        else {
            if (a[i-1] == a[i]) {
                k++;
            }
            else {
                ans += k/2;
                k = 1;
            }
        }
    }
    ans += k/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
class UnionFind
  def initialize(size)
    @parent = (0...size).to_a
    @rank = Array.new(size, 0)
  end

  def find(x)
    return x if @parent[x] == x
    return (@parent[x] = find(@parent[x]))
  end

  def unite(x, y)
    x, y = find(x), find(y)
    return if x == y
    if @rank[x] < @rank[y]
      @parent[x] = y
    else
      @parent[y] = x
      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def same(x, y)
    find(x) == find(y)
  end
end

n, k, l = gets.split.map(&:to_i)
road = UnionFind.new(n)
rail = UnionFind.new(n)
k.times do
  x, y = gets.split.map { |c| c.to_i - 1 }
  road.unite(x, y)
end
l.times do
  x, y = gets.split.map { |c| c.to_i - 1 }
  rail.unite(x, y)
end
road = n.times.map { |i| road.find(i) }
rail = n.times.map { |i| rail.find(i) }
inter = n.times.map { |i| road[i] + n * rail[i] }
h = {}
inter.each { |x| h[x] ||= 0; h[x] += 1 }
inter.each { |x| puts h[x] }


Measured memory_bytes: 24316
#include <stdio.h>
int S[100005];
int binarysearch(int A[], int n, int key)
{
	int left = 0;
	int right = n;
	while(left<right)
	{
		int mid = (left+right)/2;
		if(A[mid]==key) return mid;
		else if(A[mid] < key) left = mid+1;
		else if(A[mid] > key) right = mid;
	}
	return -1;
}
int main(int argc, char const *argv[])
{
	int n,q;
	int cnt = 0;
	scanf("%d",&n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	for (int i = 0; i < q; ++i)
	{
		int t;
		scanf("%d",&t);
		int ans = binarysearch(S,n,t);
		if(ans!=-1) cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 3056
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int N;
	long[] x, y;

	private int calc(long p, long q) {
		boolean[] b = new boolean[N];

		int result = 0;

		for (int i = 0; i < N; i++) {
			// x[i]-p, [y]-q を探し、あればb[j]をtrueにする
			for (int j = 0; j < N; j++) {
				if (i == j) {
					continue;
				}

				if (x[j] == x[i] - p && y[j] == y[i] - q) {
					b[j] = true;
				}
			}
		}

		for (boolean x : b) {
			if (!x) {
				result++;
			}
		}
		return result;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		N = sc.nextInt();

		x = new long[N];
		y = new long[N];

		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}

		sc.close();

		int ans = Integer.MAX_VALUE;

		// p,qの候補の列挙
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				long p = x[i] - x[j];
				long q = y[i] - y[j];

				ans = Math.min(ans, calc(p, q));

			}
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> H;

	cin >> N;
	H.resize(N);
	for (auto &h : H)
		cin >> h;

	llong ans = 0, cnt = 0, before = 0;
	for (auto h : H) {
		if (before >= h) {
			++cnt;
		} else {
			ans = max(ans, cnt);
			cnt = 0;
		}
		before = h;
	}

	cout << max(cnt, ans) << endl;

	return 0;
}

Measured memory_bytes: 1024
s = list(input())
count = 0
add,even = ["R","U","D"],["L","U","D"]
for i in range(len(s)):
    if (i % 2 == 0) and (s[i] in add):
        count += 1
    elif (i % 2 == 1) and s[i] in even:
        count += 1
print("Yes" if count == len(s) else "No")


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<double> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  double ans = v[0];
  for (int i = 1; i < n; i++) {
    ans = (ans + v[i]) / 2.;
  }
  printf("%.10lf\n", ans);
  return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n){
        int a;
        cin >> a;
        v[i] = v[max(0, i-1)] + a;
    }
    int ans = 1e9;
    REP(i, n-1){
        chmin(ans, abs(v.back() - 2*v[i]));
    }
    cout << ans << endl;
    return 0;
}


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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/




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

	vector<int> a(n, 0);
	
	for(int i = 0; i < n; ++i){
		int start = i;
		while(i+1 < n && s[i] == s[i+1]){
			i++;
		}
		int cnt = i - start + 1;
		if(s[i] == 'R'){
			// R R R L L 
			// o e o e o    odd even
			// 1 2 3        cnt
			//     2 1      R distribution  (answer)
			//L = cnt/2 == 1, R = (cnt+1)/2 == 2
			a[i] += (cnt+1)/2;
			a[i+1] += cnt/2;
		}
		else if(s[i] == 'L'){
			//R L L L R L
			//o e o e o e
			//  1 2 3
			//1 2
			//
			a[start] += (cnt+1)/2;
			a[start-1] += cnt/2;
		}
	}

	for (size_t i = 0; i < n; i++)
	{
		cout << a[i] << " ";
	}
	
}


Measured memory_bytes: 1104
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int c[13];
int in[13][13];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, m, x;
    cin >> n >> m >> x;
    int i, j;
    rep(i, n) {
        cin >> c[i];
        rep(j, m) {
            cin >> in[i][j];
        }
    }
    ll s[m], k;
    ll ans(LINF);
    rep(i, two(n)) {
        ll t(0);
        memset(s, 0, sizeof(s));
        rep(j, n) {
            int tj = two(j);
            if (tj & i) {
                t += c[j];
                rep(k, m) s[k]+=in[j][k];
            }
        }
        rep(j, m) {
            if (s[j] < x) break;
        }
        if (j == m) {
            ans = min(ans, t);
        }
    }
    if (ans == LINF) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		int[] a = new int[n];
		
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		
		scanner.close();
		
		int cnt = 0;
		
		int m;
		for (m = 0; (n >> m) > 0; m++);
		int[] g = new int[m];
		for (int i = 0; i < m; g[i] = (1 << (m - i - 1)), i++);
		
		for (int k = 0; k < m; k++) {
			for (int i = g[k]; i < n; i++) {
				int v = a[i];
				int j = i - g[k];
				
				while (j >= 0 && a[j] > v) {
					a[j + g[k]] = a[j];
					j -= g[k];
					cnt ++;
				}
				a[j + g[k]] = v;
			}
		}
		
		System.out.println(m);
		for (int i = 0; i < m - 1; i++) {
			System.out.print(g[i] + " ");
		}
		System.out.println(g[m - 1]);
		
		System.out.println(cnt);
		
		for (int i = 0; i < n; i++) {
			System.out.println(a[i]);
		}
	}
} 



Measured memory_bytes: 298788
#include<bits/stdc++.h>
#define M_PI       3.14159265358979323846
#define Speed_UP  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define 	pb	push_back 
#define 	ff	first 
#define 	ss	second 
#define sz(x) (int)x.size()
#warning Remeber to change t
using namespace std;
typedef long long ll;
inline void setIO(string name="") {
	#ifndef ONLINE_JUDGE 
	freopen((name+".in").c_str(), "r", stdin); 
	freopen((name+".out").c_str(), "w", stdout);
	#endif
	}
const ll mx=1e6+5;
ll prime[mx+5];
set <ll> factor(ll n){
  set<ll>r;
  while(n!=1){
    if(prime[n]==0){
      r.insert(n);
      n=1;
      continue;
    }
    r.insert(prime[n]);
      n/=prime[n];
  }
  return r;
  
  }
int main(){
	Speed_UP
  prime[0]=prime[1]=-1;
  for(int i=2;i*i<=mx;i++){
    if(prime[i]==0){
      for(int j=i*i;j<=mx;j+=i){
        if(prime[j]==0)
          prime[j]=i;
      }
    }
  }
	
  ll n;
  cin>>n;
  ll arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  
  set<ll>f;
  bool pairwise=1;
  for(int i=0;i<n;i++){
    set<ll>s=factor(arr[i]);
    for(auto u:s){
      if(f.count(u)==1){
        pairwise=0;
      }else{
        f.insert(u);
      }
    }
  }
  if(pairwise==0){
    ll st=arr[0];
    for(int i=1;i<n;i++){
      st=__gcd(st,arr[i]);
    }
    if(st==1)
      cout<<"setwise coprime";
    else
      cout<<"not coprime";
  }else{
    cout<<"pairwise coprime";
  }




}


Measured memory_bytes: 22868
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define pii pair<pair <int, int>, int>
#define vi vector <int>
const ll mod = 1000000007;
const ll nmax=1000003;
#define int ll
int n, m, p, d[50001];
vi g1[2505];
vector<pi> g[50001];
vector<pii> edg;

bool viz[2505], viz1[2505];

void dfs(int nod){
    viz[nod]=1;
    for(int i: g1[nod]){
        if(!viz[i]){
            dfs(i);
        }
    }
}

void dfs1(int nod){
    viz1[nod]=1;
    for(pi i: g[nod]){
        if(!viz1[i.x]){
            dfs1(i.x);
        }
    }
}

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>m>>p;
    for(int i=1, x, y, c; i<=m; i++){
        cin>>x>>y>>c;
        g[x].pb({y, p-c});
        g1[y].pb(x);
        //edg.pb({{x, y}, c});
    }

    dfs(n);
    dfs1(1);
    //for(int i=1; i<=n; i++) cout<<viz[i]<<" ";
    vi prev;
    set<int> s;
    prev.pb(1);
    for(int i=2; i<=n; i++) d[i]=1e9;
    for(int i=1; i<=n; i++){
        for(int x : prev){
            for(pi xd: g[x]){
                int y=xd.x, c=xd.y, lol=d[y];
                d[y]=min(d[y], d[x]+c);
                if(i==n && viz[y] && viz1[y] && lol!=d[y]) return cout<<-1, 0;
                if(lol!=d[y]) s.insert(y);
            }
        }
        prev.clear();
        for(int nod: s) prev.pb(nod);
        s.clear();
    }
    cout<<max(0LL, -d[n]);
}


Measured memory_bytes: 1920