akhauriyash/Code-Regression huggingface dataset:
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	if len(res)==0:
		res = [n]
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	data = [2]
	#data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	ans = [x for x in data if x!=0]
	#ans = data[:]
	return ans

n = readInt()
a = readInts()
a.sort()

max_a = 10**6
ans = [0]*(max_a+1)

for i in a:
	ans[i]+=complex(1,1)
for i in set(a):
	if ans[i].imag>0:
		for j in range(i*2,len(ans),i):
			ans[j]+=2

count = 0
for i in ans:
	if i.imag>0 and i.real==1:
		count+=1

print(count)

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

int main(){
    int N;
    long long K;
    std::cin >> N >> K;
    std::vector< long long > A(N);
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }
    
    std::vector< int > bit_cnt(40, 0);
    
    for(int i=0; i<N; i++){
        for(int j=0; j<40; j++){
            long long mask = (long long)1 << j;
            if(A[i] & mask){
                bit_cnt[j]++;
            }
        }
    }
    
    long long f_max_X = 0;
    for(int i=40; i>=0; i--){
        if(bit_cnt[i] * 2 < N){
            long long f_max_X_tmp = f_max_X + ((long long)1 << i);
            if(f_max_X_tmp > K){
                continue;
            }else{
                f_max_X = f_max_X_tmp;
            }
        }
    }
    
    long long ans = 0;
    for(int i=0; i<40; i++){
        long long mask = (long long)1 << i;
        if(f_max_X & mask){
            ans += (N - bit_cnt[i]) * mask;
        }else{
            ans += bit_cnt[i] * mask;
        }
    }
    
    std::cout << ans << std::endl;
    
    
    return 0;
    
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const ll INF = 1e18;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    if(n%2 == 0){
        ll res1 = 0,res2 = 0;
        rep(i,n){
            if(i%2 ==0) res1 += a[i];
            else res2 += a[i];
        }
        ll ans =  max(res1,res2);
        vector<vector<ll>> dp2(n+1,vector<ll>(2,-INF));
        dp2[1][0] = a[0];
        for(int i=2;i<=n;i++){
            if(i-2>=1){
                if(dp2[i-2][0] != -INF)dp2[i][0] = dp2[i-2][0] + a[i-1];
                if(dp2[i-2][1] != -INF)dp2[i][1] = dp2[i-2][1] + a[i-1];
            }if(i-3 >=1){
                if(dp2[i-3][0] != -INF)dp2[i][1] = max(dp2[i][1],dp2[i-3][0] + a[i-1]);
            }
        }
        ans = max(ans,max(dp2[n][1],dp2[n-1][0]));
        cout << ans << endl;
        return 0;
    }
    vector<vector<ll>> dp(n+1,vector<ll>(3,-INF));
    dp[1][0] = a[0];
    for(int i=2;i<=n;i++){
        if(i-2 >= 1){
            if(dp[i-2][0] != -INF)dp[i][0] = dp[i-2][0] + a[i-1];
            if(dp[i-2][1] != -INF)dp[i][1] = dp[i-2][1] + a[i-1];
            if(dp[i-2][2] != -INF)dp[i][2] = dp[i-2][2] + a[i-1];
        }if(i-3 >=1){
            if(dp[i-3][0] != -INF)dp[i][1] = max(dp[i][1],dp[i-3][0] + a[i-1]);
            if(dp[i-3][1] != -INF)dp[i][2] = max(dp[i][2],dp[i-3][1] + a[i-1]);
        }if(i-4 >=1){
            if(dp[i-4][0] != -INF)dp[i][2] = max(dp[i][2],dp[i-4][0] + a[i-1]);
        }
    }
    vector<vector<ll>> dp2(n+1,vector<ll>(2,-INF));
    dp2[2][0] = a[1];
    for(int i=3;i<=n;i++){
        if(i-2>=1){
            if(dp2[i-2][0] != -INF)dp2[i][0] = dp2[i-2][0] + a[i-1];
            if(dp2[i-2][1] != -INF)dp2[i][1] = dp2[i-2][1] + a[i-1];
        }if(i-3 >=1){
            if(dp2[i-3][0] != -INF)dp2[i][1] = max(dp2[i][1],dp2[i-3][0] + a[i-1]);
        }
    }
    ll ans = max({dp[n][2],dp[n-1][1],dp[n-2][0],dp2[n][1],dp2[n-1][0]});
    ll res1 = 0,res2 = 0;
    rep(i,n){
        if(i%2 ==1) res1 += a[i];
        if(i%2 ==0 && i != 0) res2 += a[i];
    }
    ans = max(ans,max(res1,res2));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26724
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{

    int n;
    cin >> n;
    vector<int> a(n);

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

    double ave = 0.0;
    for (auto &e : a)
    {
        ave += e;
    }
    ave /= n;

    double dist = 10e7;
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        if (abs(ave - a[i]) < dist)
        {
            dist = abs(ave - a[i]);
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n,a,b = map(int, input().split())
rs = (b-a)//2

if (b-a) % 2 == 0:
    print(rs)
else:
    if a==1 and b==n:
        print(n//2)
    elif (a-1) > (n-b):
        print(rs+(n-b+1))
    else:
        print(rs+a)

Measured memory_bytes: 3060
n = int(input())
ls = []
lt = []

for i in range(n):
    s,t = input().split()
    ls.append(s)
    lt.append(int(t))

x = input()

ct = 0
for i in range(ls.index(x)+1, len(lt)):
    ct += lt[i]
    
print(ct)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
namespace Program
{
    using namespace std;
    class Solver
    {
    private:
        int N;
        vector<int> v;
        int X = 10000001;

    public:
        Solver()
        {
            cin.tie(0);
            ios::sync_with_stdio(false);

            cin >> N;
        }
        void Solve()
        {
            int s = 0;

            //v.resize(N);

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

                if (s > N)
                {
                    X = s - N;
                    v.push_back(i);
                    f();
                    break;
                }
                else if (s == N)
                {
                    v.push_back(i);
                    f();
                    break;
                }
                else
                {
                    v.push_back(i);
                }
            }
        }

        void f()
        {
            int tmp = 0;
            for (int i = 0; i < v.size(); i++)
            {
                if (v[i] != X)
                {
                    cout << v[i] << "\n";
                    tmp += v[i];
                    if (tmp == N) break;
                }
            }
        }
    };
}

int main()
{
    // メモリリーク検出
    //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF
    //    | _CRTDBG_DELAY_FREE_MEM_DF
    //    | _CRTDBG_CHECK_ALWAYS_DF
    //    | _CRTDBG_LEAK_CHECK_DF);

    // メンバ関数ポインタ取得
    void (Program::Solver::*pSolve)() = &Program::Solver::Solve;

    // コンストラクタ呼び出し
    Program::Solver obj;

    // .*演算子でアクセス
    (obj.*pSolve)();
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

long n, q;
// 木
vector<vector<long>> to;
vector<long> ans;
void dfs(long i, long p);

int main() {
  cin >> n >> q;
  to.assign(n, vector<long>());
  rep(i, n - 1) {
    long a, b;
    cin >> a >> b;
    // 0-indexed に揃える
    a--;
    b--;
    // aからbへのエッジを追加
    to[a].push_back(b);
    // 無向グラフなので逆方向のエッジも追加
    to[b].push_back(a);
  }

  ans.resize(n);
  rep(i, q) {
    long p, x;
    cin >> p >> x;
    // 0-indexedに変換
    p--;
    ans[p] += x;
  }

  dfs(0, -1);

  rep(i, ans.size()) { cout << ans[i] << " "; }
  cout << endl;
}

// p: 親ノード
void dfs(long i, long p = -1) {
  long a = ans[i];
  for (auto v : to[i]) {
    // 親には戻らない
    if (v == p) {
      continue;
    }

    // ans[v] += ans[i];
    ans[v] += a;
    dfs(v, i);
  }
}


Measured memory_bytes: 24320
#include <iostream>
#include <fstream>
#include <random>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;



int main() {

    //freopen("../input.txt", "r", stdin);

    ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();

    string s;
    cin >> s;
    int q = 0;
    cin >> q;

    deque<char> beg, end;
    bool isreversed = false;

    for (int qq = 0; qq < q; ++qq) {
        int cmd;
        cin >> cmd;
        if (cmd == 1) {
            isreversed = !isreversed;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (isreversed) {
                if (f == 1) {
                    end.push_back(c);
                } else {
                    beg.push_front(c);
                }
            } else {
                if (f==1) {
                    beg.push_front(c);
                } else {
                    end.push_back(c);
                }
            }
        }
    }
    string total;
    if (isreversed) {
        swap(beg, end);
        reverse(s.begin(), s.end());
    }

    while (beg.size()) {
        if (!isreversed) {
            total += beg.front();
            beg.pop_front();
        } else {
            total += beg.back();
            beg.pop_back();
        }
    }

    total += s;

    while(end.size()) {
        if (!isreversed) {
            total += end.front();
            end.pop_front();
        } else {
            total += end.back();
            end.pop_back();
        }
    }

    cout << total;


    return 0;
}

Measured memory_bytes: 1328
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[200010];
ll kai[200010];
ll m;
ll beki(ll n,ll k){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=m;
    }
    now*=now;
    now%=m;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n){
  return beki(n,mod-2);
}
void nckinit(ll n){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=mod;
  }
  gya[n]=gyaku(kai[n]);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=mod;
  }
  gya[0]=1;
}    
ll nck(ll n,ll k){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  ret*=gya[k];
  ret%=mod;
  return ret;
}
ll npk(ll n,ll k){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  return ret;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  int h[n];rep(i,0,n)cin>>h[i];
  int ans=0;
  int now=0;
  rep(i,1,n){
    if(h[i]<=h[i-1])now++;
    else{
      ans=max(ans,now);
      now=0;
    }
  }
  ans=max(ans,now);
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

#define SIZE 10

using namespace std;

int main(void) {
	vector<int> list;
	for (int i = 0; i < SIZE; i++) {
		int n;
		cin >> n;
		list.push_back(n);
	}
	sort(list.begin(), list.end());

	for (int i = 9; i >= 7; i--) {
		cout << list[i] << "\n";
	}
	int n;
	cin >> n;
	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
const long long INFll=1ll*INF*INF;
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << endl;
#define sz(a) int((a).size())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    //unordered_map<long long, int, custom_hash>
    //gp_hash_table<long long, int, custom_hash>
};
long long genrand(long long L,long long R)
{
	return uniform_int_distribution<long long>(L, R)(rng);
}
int mul(int a, int b,int mod = MOD) {
	return int(a * 1ll * b % mod);
}
int norm(int a,int mod = MOD) {
	while(a >= mod) a -= mod;
	while(a < 0) a += mod;
	return a;
}
int powmod(int x,int y,int mod = MOD){
	int res = 1;
	while(y>0)
	{
		if(y&1)
			res = mul(res,x,mod);
		x = mul(x,x,mod);
		y=y>>1;
	}
	return res;
}
int inv(int a,int mod = MOD) {
	return powmod(a, mod - 2);
}
int main() {
	
	long double r; cin>>r;
	long double ans = r * 2 * PI;
	cout<<fixed<<setprecision(20)<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3784
from collections import Counter
n=int(input())
v=list(map(int, input().split()))
v1=[]
v2=[]
for i in range(0,n-1,2):
    v1.append(v[i])
    v2.append(v[i+1])

v1C=list(sorted(list(Counter(v1).items()), key=lambda x: x[1]))
v2C=list(sorted(list(Counter(v2).items()), key=lambda x: x[1]))

a=v1C[-1][1]
b=v2C[-1][1]
if v1C[-1][0]==v2C[-1][0]:

    if len(v1C)>1 and len(v2C)>1:
        if (len(v1)-v1C[len(v1C)-2][1]+len(v2)-b)>(len(v1)-a+len(v2)-v2C[len(v2C)-2][1]):
            b=v2C[len(v2C)-2][1]
        else:
            a=v1C[len(v1C)-2][1]
    elif a>=b and (len(v1C)>1 or len(v2C)>1):
        b=v2C[len(v2C)-2][1]
    elif a<b and (len(v1C)>1 or len(v2C)>1):
        a=v1C[len(v1C)-2][1]
    else:
        b=0

print(len(v1)-a+len(v2)-b)


Measured memory_bytes: 21212
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
int N, A[200005], B[200005];
int cumB[35];
int amt[35][200005];
int ans = 0;

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

    cin >> N;
    for (int i = 1; i <= N; i++) cin >> A[i];
    for (int i = 1; i <= N; i++) {
        int x;
        cin >> x;
        B[i] = x;
        for (int j = 29; j >= 0; j--) {
            cumB[j] ^= (x >> j) & 1;
            amt[j][i] = x % (1 << j);
        }
    }
    for (int i = 29; i >= 0; i--) {
        sort(amt[i] + 1, amt[i] + N + 1);
    }

    for (int i = 1; i <= N; i++) {
        int x = A[i];
        int temp = 0;
        for (int j = 29; j >= 0; j--) {
            int dig = (N & 1) & ((x >> j) & 1);
            int rem = x % (1 << j);
            dig ^= cumB[j];
            int pos = (int)(lower_bound(amt[j], amt[j] + N + 1, (1 << j) - rem) - amt[j]);
            int amt = N + 1 - pos;
            dig ^= (amt & 1);
            temp ^= (dig << j);
        }
        ans ^= temp;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 28592
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
	cin >> n;
	vi a(n+2);
	a[0] = 0;
	a[n+1] = 0;
	int sum = 0;
	rep(i,n) {
		cin >> a[i+1];
		sum += abs(a[i+1]-a[i]);
	}
	sum += abs(a[n]);
	rep(i,n) {
		cout << sum - abs(a[i+1]-a[i]) - abs(a[i+2]-a[i+1]) + abs(a[i+2]-a[i]) << endl;
	}
	return;
}

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

Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N;

    scanf("%d", &N);

    char S1[N+1], S2[N+1];

    scanf("%s%s", S1, S2);

    long long ans = 1;

    int t;

    if(S1[0] == S2[0]){
        ans = 3;
        t = 1;
    }else{
        ans = 6;
        t = 0;
    }

    long long m = 1000000007;

    for(int i = 1; i < N; i++){
        if(S1[i] == S2[i]){
            if(t == 1){
                ans = (ans * 2) % m;
            }
            t = 1;
        }
        if(S1[i] == S1[i+1]){
            if(t == 1){
                ans = (ans * 2) % m;
            }else{
                ans = (ans * 3) % m;
            }
            t = 0;
        }
    }

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

    return 0;
}

Measured memory_bytes: 1736
S = input()+"R"
R = 0
L = 0
ans = [0]*(len(S)-1)
for i in range(len(S)-1):
    if S[i] == "R":
        if S[i+1] == "L":
            R += 1
            if R % 2 == 0:
                ans[i] += R//2
                ans[i+1] += R//2
            else:
                R -= 1
                ans[i] += R//2+1
                ans[i+1] += R//2
            point = i
        else:
            R += 1
    else:
        if S[i+1] == "R":
            L += 1
            if L % 2 == 0:
                ans[point] += L//2
                ans[point+1] += L//2
            else:
                L -= 1
                ans[point] += L//2
                ans[point+1] += L//2+1
            R = 0
            L = 0
        else:
            L += 1

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


Measured memory_bytes: 17160
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-09 16:26:39
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    int ans = x;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= d; j += a[i]) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
	
	int n,i,j,k;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int c=0;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			for(k=j+1;k<n;k++)
			{
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i])
				{
					if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[k]+a[j]>a[i]) 
					c++;
				}
			}
		}
	}
	cout<<c<<endl;
	
	return 0;
}

Measured memory_bytes: 3648
char*a,*b;main(i,m){for(;~scanf("%as%as",&a,&b);printf("%d\n",m)){int C[2][4001]={m=0},j,t;for(;*a;a++,i^=1)for(j=0;t=b[j++];t>m?m=t:0)t=C[1-i][j]=*a-t?0:C[i][j-1]+1;}}

Measured memory_bytes: 544
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long int ll;
char s[100005];
int main()
{	
	cin>>s;
	int len=strlen(s),shitou=0,bu=0;
	int ans=0;
	for(int i=0;i<len;++i){//bu<=shitou
		if(s[i]=='g'){
			if(bu<shitou){ans++;bu++;}
			else shitou++;
		}
		else {
			if(bu<shitou)bu++;
			else {shitou++;ans-=1;}
		}
	//	printf("i=%d shitou=%d bu=%d\n",i+1,shitou,bu);
	}
	printf("%d\n",ans);	
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;

int main() {
    string s, t; cin >> s >> t;
    int ans = 0;
    if (s[0] == t[0]) ans++;
    if (s[1] == t[1]) ans++;
    if (s[2] == t[2]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int N;
int C[500],S[500],F[500];
int sumtime;

int Solve(int x){
    sumtime=S[x]+C[x];
    for(int i=x+1; i<N-1; i++){
        if(sumtime<=S[i])sumtime=S[i]+C[i];
        else {
            int t=(sumtime-S[i])/F[i];
            if(t*F[i]==sumtime-S[i])sumtime=S[i]+t*F[i]+C[i];
            else if(t*F[i]<sumtime-S[i])sumtime=S[i]+(t+1)*F[i]+C[i];
        }
    }
    return sumtime;
}

int main(){
    cin>>N;
    rep(i,N-1){
        cin>>C[i]>>S[i]>>F[i];
    }
    rep(i,N-1){
        sumtime=0;
        cout<<Solve(i)<<endl;
    }
    cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;

vector<int> V;
vector<int> g[MAX];
int U[MAX];

void dfs(int v)
{
	U[v] = 1;
	V.push_back(v);
	FOR(i, 0, SZ(g[v]))
	{
		int to = g[v][i];
		if (U[to]) continue;
		
		dfs(to);
		break;
	}
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	U[0] = 1;
	V.push_back(0);
	dfs(g[0][0]);
	reverse(ALL(V));

	FOR(i, 0, SZ(g[0]))
	{
		int to = g[0][i];
		if (U[to]) continue;

		dfs(to);
		break;
	}

	cout << SZ(V) << endl;
	FOR(i, 0, SZ(V))
	{
		cout << V[i] + 1 << " ";
	}
	cout << endl;
}


Measured memory_bytes: 7160
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int time = sc.nextInt();
		int num[] = new int[8];
		String temp;
		for(int i = 0; i < time; i++){
			temp = sc.next();
			for(int k = 0; k< 8; k++){
				num[k] = Integer.valueOf(temp.substring(k,k+1));
			}
			Arrays.sort(num);
			int c = 1;
			int min = 0;
			int max = 0;
			for(int x = 0; x < 8;x++){
				max = max + num[x] * c;	
				min = min + num[7-x] * c;
				c = c * 10;
			}
			//System.out.println("max is " + max);
			//System.out.println("min is " + min);
			System.out.println(max - min);
			
		}
	}
}

Measured memory_bytes: 25860
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <string> str(n);
    int c0=0;
    int c1=0;
    int c2=0;
    int c3=0;
    for(int i=0; i<n; i++){
        cin >> str[i];
        if(str[i]=="AC"){
            c0++;
        }else if(str[i]=="WA"){
            c1++;
        }else if(str[i]=="TLE"){
            c2++;
        }else if(str[i]=="RE"){
            c3++;
        }
    }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;
}




Measured memory_bytes: 6424
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <complex>
#include <regex>
#include <random>
using namespace std;

#define rep(i,n)	for(lint i = 0; i < n; i++)
#define repr(i,n)	for(lint i = n - 1; i >= 0; i--)
#define repi(i,ini,n)	for(lint i = ini; i < n; i++)
#define repir(i,ini,n)	for(lint i = n-1; i >= ini; i--)
#define repb(i,start,end)	for(lint i = start; i <= end; i++)
#define repbr(i,start,end)	for(lint i = end; i >= start; i--)

#define bit(n)				(1LL << (n))

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rg(v, ini, end) v.begin() + ini, v.begin()+end

#define ret return 0;
#define chmax(a, b) a=mmax(a,b)
#define chmin(a, b) a=mmin(a,b)

using lint = long long;
using ulint = unsigned long long;
using ld = long double;
struct xy
{
	lint x, y;
	xy() :x(0), y(0) {}
	xy(lint _x, lint _y) : x(_x), y(_y) {}
	xy operator+(const xy& p) const
	{
		return xy(x + p.x, y + p.y);
	}
	bool operator<(xy p) const
	{
		if (y == p.y)
			return x < p.x;
		return y < p.y;
	}
};
struct xyd
{
	ld x, y;
	xyd() :x(0), y(0) {}
	xyd(long double _x, long double _y) : x(_x), y(_y) {}
};
using vec = vector<lint>;
using vecd = vector<ld>;
using vecs = vector<string>;
using vecp = vector<xy>;
template<class T> using vect = vector<T>;
class vec2 : public vector<vector<lint>>
{
public:
	vec2() {}
	vec2(lint n) : vector(n) {}
	vec2(lint h, lint w) : vector(h, vector<lint>(w)) {}
	vec2(lint h, lint w, lint v) : vector(h, vector<lint>(w, v)) {}
};

template<class T> using priq = priority_queue<T>;
template<class T> using rpriq = priority_queue<T, vector<T>, greater<T>>;
template<class Key, class Val> using hashmap = unordered_map<Key, Val>;
template<class Key> using hashset = unordered_set<Key>;

mt19937 mtrand((random_device())());

const double pi = 3.141592653589793238462;
const lint intmax = 9223372036854775807;
const lint inf = 1100100100100100100LL;

constexpr lint div2(lint p, lint q)
{
	return (p + q - 1) / q;
}

#if(__cplusplus < 201703L)

	lint gcd(lint a, lint b) {
		while (1) {
			if (a < b) swap(a, b);
			if (!b) break;
			a %= b;
		}
		return a;
	}

	lint lcm(lint a, lint b)
	{
		return a / gcd(a, b) * b;
	}

#endif

template<class T>
struct nval {
	lint n;		// counts
	T val;
	nval() : n(0) {};
	nval(lint _n, T _val) : n(_n), val(_val) {};
};

template<class It, class It2>
auto spacel(It i, It2 end)
{
	if (i + 1 == end)
	{
		return '\n';
	}
	else
	{
		return ' ';
	}
}

ostream& setp(ostream& ost)
{
	cout << setprecision(60) << fixed;
	return ost;
}

const ulint mod = 1000000007;
//const ulint mod = 998244353;
const ld eps = 0.0000001;


int main()
{
	lint a, b;
	cin >> a >> b;
	cout << a / b << ' ' << a % b << ' ' << setp << ld(a) / b << endl;
	return 0;
}



Measured memory_bytes: 3288
N, M = map(int, input().split())
A = [int(a) for a in input().split()]    
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i]-1]] for i in range(M)]

best = sorted(B, key = lambda x: x[1]*10-x[0])[0]

adj = max((N - 200),0)//best[1]
N -= best[1] * adj

X = [0] + [-10**9] * N
for i in range(1, N+1):
    if i > 50 and i < N-50:
        X[i] = X[i-best[1]]*10 + best[0]
    else:
        for b in B:
            if b[1] <= i:
                if X[i-b[1]] == 0:
                    X[i] = max(X[i], b[0])
                else:
                    X[i] = max(X[i], X[i-b[1]]*10 + b[0])

ans = str(X[N])
if adj > 0:
    ans = ans[:10] + str(best[0]) * adj + ans[10:]

print(ans)

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N; cin >> N;
    vector<int> vV(N); for(uint i=0; i<N; ++i){ cin >> vV[i]; }
    vector<int> vC(N); for(uint i=0; i<N; ++i){ cin >> vC[i]; }

    int sum=0;
    for(uint i=0; i<N; ++i){
        int buf = vV[i] - vC[i];
        if(buf>0){ sum += buf; }
    }
    cout << sum << endl;
    
    return 0;
}

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

int main() {
    string s;
    cin>>s;
    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}

Measured memory_bytes: 3572
// Problem : C - One-stroke Path
// Contest : AtCoder - AtCoder Beginner Contest 054
// URL : https://atcoder.jp/contests/abc054/tasks/abc054_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define MOD 1000000007
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
int tot;
int n,m;
void dfs(int i,vi *adj,vi &visited,int inStack){
	visited[i] = 1;
	for(auto j:adj[i]){
		if(!visited[j])dfs(j,adj,visited,inStack+1);
	}
	if(inStack == n)tot++;
	visited[i] = 0;
}
int main() {
    // your code goes here
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    vi adj[n+1];
    for(int i = 0;i<m;i++){
    	int u,v;
    	cin >> u >> v;
    	adj[u].pb(v);
    	adj[v].pb(u);
    }
    vi visited(n+1,0);
    tot=0;
    dfs(1,adj,visited,1);
    cout << tot << "\n";
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>


#define fs first
#define sc second

using namespace std;

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

const ll mod = 998244353;
ll fact[210200];
ll invfact[210200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll powMod(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return powMod(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll dp[101000][3];
int main(){
    int N;
    ll a[101000], b[101000], c[101000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i = 0; i < 101000; i++){
        fill(dp[i], dp[i]+3, 0);
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for(int i = 0; i < N-1; i++){
        dp[i+1][0] = max(dp[i][1], dp[i][2]) + a[i+1];
        dp[i+1][1] = max(dp[i][0], dp[i][2]) + b[i+1];
        dp[i+1][2] = max(dp[i][0], dp[i][1]) + c[i+1];
    }

    cout << max(max(dp[N-1][0], dp[N-1][1]), dp[N-1][2]) << endl;


    return 0;
}


Measured memory_bytes: 6656
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLine().Split(' ');
            var ans = 'a';
            string a = s[0];
            if (Char.IsUpper(a, 0))
            { ans = 'A'; }

            WriteLine(ans);
            Out.Flush();
        }

    }

    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
        public static long Combination(long n, long m)
        { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Lcm(long n, long m)
        { return n * m / Gcd(n, m); }
        public static long Pow(long n, long m)
        { return (m == 1 || m == 0) ? 1L : n * Pow(n, m - 1); }
    }
}

Measured memory_bytes: 25900
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<strinx>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(void){
 	int n,x; 
	cin>>n>>x;
  vi m(n);
  rep(i,n)cin>>m[i];
  sort(m.begin(),m.end());
  rep(i,n)x-=m[i];
  cout<<n + x / m[0]<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n, d;
	cin >> n >> d;
	vi v(n);
	rep(i, n) cin >> v[i], v[i] -= d;
	sort(all(v));
	auto it = upper_bound(all(v), 0);
	if(it == v.end()) cout << "kusoge" << endl;
	else cout << accumulate(it, v.end(), 0) << endl;
	return 0;
}

Measured memory_bytes: 3172
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}


int main(){
	ll a, b, c, d;
  cin>>a>>b>>c>>d;
  c -= a; d -= b;
  string res;
  res += string(c, 'R')+string(d, 'U');
  res += string(c, 'L')+string(d, 'D');
  res += "D"+string(c+1, 'R')+string(d+1, 'U')+"L";
  res += "U"+string(c+1, 'L')+string(d+1, 'D')+"R";
  cout<<res<<endl;
                   
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define FOR_EX(i, a, b) for (int i = a; i < b; i++)
#define FOR_IN(i, a, b) for (int i = a; i <= b; i++)

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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("testcase_11.in", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    int a[n];
    FOR_EX(i, 0, n) {
        cin >> a[i];
    }
    // Binary search for 1 then 2 then 3 and update start
    // int cur = 0;
    // int *next = a;
    // int *end = a + n;
    // while (next != end) {
    //     if (next && *next == cur + 1) {
    //         cur++;
    //     }
    //     next = lower_bound(next + 1, end, cur);
    // }
    // cout << (cur >= 1 ? n - cur : -1) << endl;
    int look = 1;
    for (auto &i : a) {
        if (i == look) {
            look++;
        }
    }
    cout << (look - 1 >= 1 ? n - look + 1 : -1) << endl;
}


Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
//class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader stdReader =
            new BufferedReader(new InputStreamReader(System.in));
        String[] nums = stdReader.readLine().split(" ");
        
        int a = Integer.parseInt(nums[0]);
        int b = Integer.parseInt(nums[1]);
        
        System.out.println(a*b + " " + 2*(a+b) );
	}
}

Measured memory_bytes: 16896
#include <cstdint>
#include <iostream>

using namespace std;

bool isok(int64_t n, int64_t m) { return m > 0 && n / m == n % m; }

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

  int64_t n;
  cin >> n;

  int64_t ans = 0;
  for (int64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (isok(n, i - 1)) ans += i - 1;
      if (i != n / i && isok(n, n / i - 1)) {
        ans += n / i - 1;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] words = new String[n];
    for(int i = 0; i < n; i++) {
      words[i] = sc.next();
    }
    boolean judge = true;
    for(int i = 0; i < n; i++) {
      for(int j = i + 1; j < n; j++) {
        if(j == n) {
          break;
        }else if (words[i].equals(words[j])) {
          System.out.println("No");
          return;
        }
      }
    }
    for(int i = 0; i < n - 1; i++) {
      if(words[i].charAt(words[i].length() - 1) != words[i + 1].charAt(0)) {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }

}


Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long K;
	cin >> K;
	if (K == 0) {
		cout << 2 << endl << 1 << " " << 1;
	}
	else if (K == 1) {
		cout << 3 << endl << 1 << " " << 0 << " " << 3;
	}
	else if (K < 50) {
		cout << K << endl;
		for (int i = 0; i < K; i++) {
			cout << K;
			if (i != K - 1) cout << " ";
		}
	}
	else {
		cout << 50 << endl;
		for (int i = 0; i < K % 50; i++) {
			cout << 99 + K / 50 - K % 50 << " ";
		}
		for (int i = K % 50; i < 50; i++) {
			cout << 49 + K / 50 - K % 50;
			if (i != 49) cout << " ";
		}
	}
}

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

int main(){
	int N;
	cin >> N;
	int cnt = 0;
	for(int i=1; i<=N-1; i++){
		for(int j=1; j*i<=N-1; j++){
			cnt++;
		}
	}

	cout << cnt << endl;


	return 0;
}


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

int pre[200010];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	map<int,int> m;
	long long int ans=0;
	m[0]++;
	for(int i=1,x;i<=n;i++){
		cin>>x;
		pre[i]=((pre[i-1]+x-1)%k+k)%k;
		if(i>=k)
			m[pre[i-k]]--;
		ans+=m[pre[i]];
		m[pre[i]]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 10368
n = int(input())
a = list(map(int, input().split()))
 
ans = 1
 
a.sort(reverse=True)
 
if 0 not in a:
    for x in range(n):
        ans *= a[x]
 
        if ans > 10**18:
            ans = -1
            break
else:
    ans = 0
 
print(ans)

Measured memory_bytes: 21540
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
q = int(input())

counter = Counter(a)
sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので

# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）
for _ in range(q):
    before, after = map(int, input().split())

    # 合計を変更します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]

    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0

    print(sum_res)

Measured memory_bytes: 24144
#import math
#from decimal import Decimal
import numpy as np
# nの約数を全て求める
# n!が大きすぎ＞　解説をみると。。
# ex; 24 = 2^3 * 3
#       (1,2,3,4,6,8,12,24) > 8個

# approach, 1~Nごとに、素因数分解をして、カウントする。
# 最後に掛け合わせる。
lim = 10 ** 9 + 7
n = int(input())
# https://note.nkmk.me/python-prime-factorization/

num = [0] * (n + 1)
#num[1] = 1

for i in range(2, n + 1):
    temp = i
    # even number
    while (temp % 2 == 0):
        if (num[2] == 0):
            num[2] = 1
        num[2] += 1
        # print('2A')
        temp //= 2

    f = 3
    # odd number
    while (f * f <= temp):
        if (temp % f == 0):
            if (num[f] == 0):
                num[f] = 1
            num[f] += 1
            #print('B', f)
            temp //= f
        else:
            f += 2
    # prime number
    if (temp != 1):
        if (num[temp] == 0):
            num[temp] += 1
        num[temp] += 1
        #print('C', temp)

numA = np.array(num)
numAA = np.argwhere(numA != 0)
numAAA = numAA.tolist()
# print(numA)

ans = 1
for i in numAAA:
    tar = i[0]
    ans *= num[tar]

#ans = sum(num)
ans %= lim

print(ans)


Measured memory_bytes: 27276
#include <bits/stdc++.h>
using i64 = long long;

const std::vector<int> c { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> v;
    for (int i = 0; i < m; i++) {
        int d;
        std::cin >> d;
        v.push_back(d);
    }
    std::sort(v.begin(), v.end());
    std::vector<std::string> dp(10010);

    for (const auto d : v) dp[c[d]] = std::max(dp[c[d]], std::to_string(d));

    for (int i = 0; i <= n; i++) {
        for (const auto d : v) {
            if (i < c[d]) continue;
            if (i && !dp[i - c[d]].size()) continue;
            dp[i] = std::max(dp[i], dp[i - c[d]] + (char)('0' + d), [](auto &lhs, auto &rhs) {
                return lhs.size() < rhs.size() || (lhs.size() == rhs.size() && lhs < rhs);
            });
        }
    }

    std::cout << dp[n] << std::endl;

    return 0;
}


Measured memory_bytes: 41472