akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,a[maxn],t,ans,p,X[maxn];
const ll mod=1000000007;

inline ll pw(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod; b>>=1;
	}
	return ans;
}

inline void wk(int x)
{
	for(int i=2;i*i<=x;i++)
	{
		int cnt=0;
		if(x%i==0)
		{
			while(x%i==0) x/=i,cnt++;
			X[i]=max(X[i],cnt);
		}
	}
	if(x) X[x]=max(X[x],1);
}

int main()
{
	n=read(); rep(i,1,n) a[i]=read(),wk(a[i]); t=1;
	rep(i,1,maxn-5) if(X[i]) t=(t*pw(i,X[i]))%mod;
	rep(i,1,n) ans=(ans+t*pw(a[i],mod-2)%mod)%mod; cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int lc[3005][3005] = { };

int main(){
	string a, b;
	cin >> a >> b;
	int n = a.size(), m = b.size();
	REP(i, n){
		REP(j, m){
			lc[i+1][j+1] = max(lc[i][j+1], lc[i+1][j]);
			if(a[i] == b[j]) lc[i+1][j+1] = max(lc[i][j]+1, lc[i+1][j+1]);
		}
	}
	string ans = "";
	int i = n, j = m;
	while(i!=0 && j!=0){
		if(i > 0 && lc[i-1][j] == lc[i][j]) i--;
		else if(j > 0 && lc[i][j-1] == lc[i][j]) j--;
		else{
			i--; j--;
			ans = a[i] + ans;
		}
	}
	cout << ans << endl;
} 

Measured memory_bytes: 35456
#!/usr/bin/env python

def solve():
    N = int(input())
    scores = [0]*N
    A = [0]*N
    B = [0]*N
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b
        scores[i] = (i, a + b)
    scores = sorted(scores, key=lambda x: x[1], reverse=True)
    
    ans = 0
    for i in range(N):
        if i%2 ==0:
            ans += A[scores[i][0]]
        else:
            ans -= B[scores[i][0]]
    print(ans)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 26856
<?php
$input=explode(' ',trim(fgets(STDIN))); // // 1 2 3 ……
$k_num = trim(fgets(STDIN)); //数字や文字列

sort($input);

for ($i = 0; $i < $k_num; $i++) {
    $input[2] = $input[2] * 2;
}

echo( array_sum($input) );
?>

Measured memory_bytes: 3828
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int count = 1;
		int max = sc.nextInt();

		for(int i = 0; i < n-1; i++){
			int hotel = sc.nextInt();
			if(hotel >= max) {
				count++;
				max = hotel;
			}
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include <iostream>

#define N 20

using namespace std;

int main(void) {
  int i, n, max, diff;
  int V[N], C[N];
  
  cin >> n;
  for(i = 0; i < n; i++) cin >> V[i];
  for(i = 0; i < n; i++) cin >> C[i];
  
  for(i = 0; i < n; i++) {
    diff = V[i] - C[i];
  	if(diff > 0) max += diff;
  }
  
  cout << max << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int>x(n);
    rep(i,n)cin>>x[i];
    sort(x.begin(),x.end());
    int ans=1e9;
    for(int i=0; i<=n-k; ++i){
        if(x[i]<0&&x[i+k-1]>0)ans=min({ans,
        abs(x[i]*2)+abs(x[i+k-1]),
        abs(x[i])+abs(x[i+k-1]*2)});
        else ans=min(ans,max(abs(x[i]),abs(x[i+k-1])));
    }
    cout<<ans<<endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 400005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int work_f[SIZE], work_b[SIZE];

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

    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    int cnt = 0;
    for(int i = 0; i < s.size() && cnt < k; ++i) {
        if(s[i] == 'o') {
            work_f[cnt] = i;
            ++cnt;
            i += c;

        }
    }

    cnt = k - 1;
    for(int i = s.size() - 1; i >= 0 && cnt >= 0; --i) {
        if(s[i] == 'o') {
            work_b[cnt] = i;
            --cnt;
            i -= c;

        }
    }

    for(int i = 0; i < k; ++i) {
        if(work_f[i] == work_b[i]) {
            cout << work_f[i] + 1 << endl;

        }
    }
    return 0;
}



Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
long long n,m;
int main()
{
	long long i;
	int k =2;
	cin>>n>>m;
	if(n%m==0)
	{
		printf("-1\n");
		return 0;
	}
	for(i=n*2;i<=1e18;i+=n)
	{
		if(i%m!=0)
		{
			printf("%d\n",i);
			return 0;
		}
		k++;	
	}
	printf("-1\n");
	return 0;
} 

Measured memory_bytes: 256
from collections import deque


N = int(input())
A = list(map(int, input().split()))
q = deque()
for i, a in enumerate(A):
    if i % 2 == 0:
        q.append(a)
    else:
        q.appendleft(a)

ans = []
if len(A) % 2 == 1:
    while q:
        ans.append(q.pop())
else:
    while q:
        ans.append(q.popleft())

print(*ans)


Measured memory_bytes: 25412
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    v.emplace_back(INF<int>);
    int cur = 0, curr = 0, ans = 0;
    while(cur < n){
        if(v[cur] >= v[cur+1]) cur++, curr++;
        else {
            ans = max(ans, curr);
            curr = 0;
            cur++;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
vector<int> bs[114514],fs[114514];
ll par[114514];
ll rankk[114514];
ll sz[114514];
void init(int n){
	for(int i=0;i<=n;i++){
		par[i] = i;
		rankk[i]=0;
		sz[i] = 1;
	}
}
ll find(ll x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}
void unite(ll x, ll y){
	x = find(x);
	y = find(y);
	if(x==y)return;
	if(rankk[x]<rankk[y]){
		par[x]=y;
		sz[y] += sz[x];
	}else{
		par[y]=x;
		sz[x] += sz[y];
		if(rankk[x]==rankk[y])rankk[x]++;
	}
}
signed main(){
	int n,m,k;
	cin>>n>>m>>k;
	init(n);
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		fs[a].pb(b); fs[b].pb(a);
		unite(a,b);
	}
	for(int i=0;i<k;i++){
		int c,d;
		cin>>c>>d;
		bs[c].pb(d); bs[d].pb(c);
	}
	for(int i=1;i<=n;i++){
		int ans = sz[find(i)] - 1;
		for(int j=0;j<fs[i].size();j++){
			if( find(i) == find( fs[i][j] ) ) ans--;
		}
		for(int j=0;j<bs[i].size();j++){
			if( find(i) == find( bs[i][j] ) ) ans--;
		}
		cout<<ans<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 16116
score = {}
result = {}
while line = gets.chomp
  break if line == "0,0"
  p, s = line.split(",").map(&:to_i)
  result[p] = s
  score[s] = true
end

rank = score.keys.sort{|a, b| b<=>a}

while p = gets
  puts rank.index(result[p.to_i]) + 1
end

Measured memory_bytes: 8540
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forn(i,a,n) for(int i =a; i <n;i++)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
const lli inf = 10000000000000000ll;
#define MAXN 1000005
lli dp[MAXN];// en cada indice guardamos el min peso para llegar a ese valor
int main(){__
	lli n,w;
	cin >> n >> w;
	vi p(n),c(n);
	forn(i,0,n){
		cin >> p[i] >> c[i];
	}
	lli sum =0ll;
	for(int x : c) sum+=x;
	for(int i =0; i < MAXN; i++) dp[i] = inf;
	dp[0] = 0;
	for(int i =0; i < n; i++){
		for(int x = sum; x >= c[i]; x--){
			dp[x] = min(dp[x], dp[x - c[i]] + p[i]);
		}
	}
	int ans =0;
	for(int i =0; i <= sum ; i++){
		if(dp[i] <= w){
			ans = max(ans,i);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
	string S;
	cin >> S;
	vector<string> w = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	rep(i, 7){
		if(w.at(i) == S){
			cout << 7 - i << endl;
		}
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

using ll=long long;

template <typename T>
T in(){
    T x;
    cin >> x;
    return x;
}

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

main(){
    ll a=in<ll>(),b=in<ll>(),k=in<ll>();
    if (a>=k){
        a-=k;
    }
    else {
        k-=a;
        a=0;
        if (b>=k){
            b-=k;
        }
        else b=0;
    }
    cout << a << ' ' << b << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main() {
	int A, B;
	cin >> B >> A;

	int ans = A;
	if (ans == 100)
		ans = 101;
	for (int i = 0; i < B; i++)
		ans *= 100;
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n,x; cin>>n>>x;
  int ans=1;
  int dist=0;
  for (int i=0; i<n; i++){
    int l; cin>>l;
    dist+=l;
    if (dist<=x) ans+=1;
    else break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
int n;
double sushi(int o,int z, int t){
	if(z<0||o<0||t<0)
	return 0.0;
	if(z==0&&o==0&&t==0)
	return 0.0;
	if(dp[o][z][t]>=0.0)
	return (double) dp[o][z][t];
	dp[o][z][t]= o*sushi(o-1,z,t)+z*sushi(o+1,z-1,t)+t*sushi(o,z+1,t-1)+n;
	dp[o][z][t]/=(o+z+t);
	return dp[o][z][t];
}
int main(){
	
	int  o=0,z=0,t=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
	cin>>a[i];
	if(a[i]==2)
	z++;
	else if(a[i]==1)
	o++;
	else
	t++;
	}
	memset(dp,-1.0,sizeof (dp));
	dp[0][0][0]=0.0;

	cout<<fixed<<setprecision(12)<<sushi(o,z,t);
	
	
	
}

Measured memory_bytes: 216800
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long n; cin >> n;
	long long maxx = -2000000000, minx = 2000000000;
	for (int i = 0; i < n; i++){
		long long x; cin >> x;
		maxx = max(maxx, x - minx);
		minx = min(x, minx);
	}
	cout << maxx << endl;
	char c; cin >> c;
}

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

using namespace std;

int main() {

	long a,b,c,d;
	cin >> a >> b >> c >> d;

	while (a > 0 || c > 0) {
		c = c - b;
		if (c <= 0) { break; }
		a = a - d;
		if (a <= 0) { break; }

	}

	cout << (c<=0? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#define mMin(a, b) ((a) < (b))? (a) : (b)

int H, N;
int A[1010], B[1010];
int dp[10010], min;

int main()
{
    scanf("%d %d",&H,&N);
    for ( int i=0; i<N; i++ ) scanf("%d %d",&A[i],&B[i]);
    
    for (int h=1; h<=H; h++){
        min = 1e9;
        
        for (int n=0; n<N; n++){
            if (A[n] < h) min = mMin(min, B[n] + dp[h-A[n]]);
            else          min = mMin(min, B[n]);
        }
        dp[h] = min;
    }
    
    printf("%d\n",dp[H]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second

typedef long long ll;

using namespace std;

int main()

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

    int a;

    cin >> a;

    cout << 3*a*a;

    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <vector>

int read_cin()
{
	int input;
	std::cin >> input;
	return input;
}

int main(void)
try
{
	const int N = read_cin();
	const int K = read_cin();
	std::vector<int> count(N, 0);
	for (int i = 0; i < K; i++)
	{
		const int d_i = read_cin();
		for (int j = 0; j < d_i; j++)
		{
			const int n = read_cin();
			++count[n-1];
		}
	}
	int result = 0;
	for (const int &value: count)
	{
		if (value == 0)
		{
			++result;
		}
	}
	std::cout << static_cast<int>(result) << std::endl;
}
catch (const std::exception& e)
{
	std::cout << e.what();
	return EXIT_FAILURE;
}
catch (...)
{
	return EXIT_FAILURE;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>

typedef long long ll;
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if ((a + b)%3 == 0)
	{
		cout << "Possible" << endl;
	}
	else if (a % 3 == 0)
	{
		cout << "Possible" << endl;
	}
	else if (b % 3 == 0)
	{
		cout << "Possible" << endl;
	}
	else
	{
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 384
import math
from collections import deque
from collections import defaultdict

#自作関数群
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)
	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

w = readChar()

d = defaultdict(int)

for i in w:
	d[i]+=1

for i in d:
	if d[i]%2==1:
		print("No")
		exit()

print("Yes")

Measured memory_bytes: 3444
using System;
namespace object１
{
    public class Program
    {
        public static void Main(string[] args)
        {
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j < 10; j++)
                {
                    Console.WriteLine(i + "x" + j+"="+i*j);
                }
            }
        }

       
    }
}



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

#define ll long long
#define pb push_back
#define fr(a,b) for(ll i=a;i<=b;i++)
#define mod 1000000007
#define inf (1LL<<60)
 
ll sum[401][401];
ll dp[401][401];
 
ll solve(vector<int>&arr,int i,int j){
    //base case
    if(i==j)
    return 0;
    //lookup
    if(dp[i][j]!=-1)
    return dp[i][j];
      ll mincost=inf;
    for(int k=i;k<j;k++)
    {
mincost=min(mincost,sum[i][j]+solve(arr,i,k)+solve(arr,k+1,j));
    }
 
 
return dp[i][j]=mincost;
}
 
void prepocess(vector<int>&arr,int n)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            sum[i][j]=arr[j]+((j==i)?0:sum[i][j-1]);
        }
    }
}
 
int main()
{ int n;
    cin>>n;
    // cout<<n;
    vector<int>arr(n+1);
    memset(dp,-1, sizeof(dp));
   
    fr(1,n)
    cin>>arr[i];
    prepocess(arr,n);
    cout<<solve(arr,1,n);
    return 0;
 
}

Measured memory_bytes: 2816
#include <iostream>

int main(int argc, char const *argv[])
{
	int num1, num2;

	while (1) {
		std::cin >> num1 >> num2;
		if (num1 == 0 && num2 ==0) {
			break;
		}
		if (num1 < num2) {
			std::cout << num1 << " " << num2 << std::endl;
		}
		else {
			std::cout << num2 << " " << num1 << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
program shift
  implicit none
  integer(8), parameter :: modu = 998244353
  character(301) :: s
  integer :: k, n, a(302) = 0, m = 1, x = 0, h = 0, r, d, w, c, b, i, j
  integer(8) :: dp(0:300, 0:301) = 0
  read(*,*) s, k
  n = len_trim(s)
  s(n + 1:n + 1) = '0'
  do i = 1, n + 1
    if (s(i:i) == '0') then
      m = m + 1
      a(m) = x
    else
      x = x + 1
    end if
  end do
  k = min(k, x)
  dp(0, 0) = 1
  do i = 1, m - 1
    do j = h, 0, -1
      r = min(k - j, a(i + 1) - a(i))
      do d = 1, r
        w = j + d
        do c = 0, a(m) - a(i + 1)
          b = c + d
          dp(w, c) = dp(w, c) + dp(j, b)
          if (dp(w, c) > modu) dp(w, c) = dp(w, c) - modu
        end do
      end do
      do c = 1, a(m) - a(i + 1)
        dp(j, c) = dp(j, c) + dp(j, c - 1)
        if (dp(j, c) > modu) dp(j, c) = dp(j, c) - modu
      end do
    end do
    h = min(k, h + a(i + 1) - a(i))
  end do
  write(*,'(i0)') mod(sum(dp(0:h, 0)), modu)
end program shift

Measured memory_bytes: 3384
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define V vector
#define pb push_back
using namespace std;
void MI(int &a, int v) {a = min(a,v);}
void MA(int &a, int v) {a = max(a,v);}

signed main() {
    int n,d;
    cin>>n>>d;
    int a[n]; F(i,n) cin>>a[i];
    int minToFail[n+1];
    minToFail[n] = 1;
    DEC(i,n) {
        minToFail[i] = minToFail[i+1];
        if (minToFail[i+1] > a[i] / 2)
            minToFail[i] += a[i];
    }
    int cur[n+1];
    cur[0] = d;
    F(i,n) {
        cur[i+1] = min(cur[i], abs(cur[i]-a[i]));
    }
    int q; cin>>q;
    F(qq,q) {
        int pos; cin>>pos;
        if (cur[pos-1] >= minToFail[pos])
            P("YES");
        else
            P("NO");
    }
}

Measured memory_bytes: 14720
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

struct Student {
    int A;
    int numberOfStudent;
};

int cmpStudent(const void *s1, const void *s2);

int main() {
    int N = 0;
    scanf("%d", &N);
    struct Student *arOfStudents = NULL;
    arOfStudents = (struct Student *) malloc(sizeof(struct Student) * N);
    int i;
    for (i = 0; i < N; ++i) {
        arOfStudents[i].numberOfStudent = i + 1;
        scanf("%d", &arOfStudents[i].A);
    }

    qsort(arOfStudents, N, sizeof(struct Student), cmpStudent);

    for (i = 0; i < N; ++i) {
        printf("%d ", arOfStudents[i].numberOfStudent);
    }

    free(arOfStudents);
    arOfStudents = NULL;
}

int cmpStudent(const void *s1, const void *s2) {
    struct Student S1 = * (struct Student *) s1;
    struct Student S2 = * (struct Student *) s2;
    return S1.A < S2.A ? -1 : 1;
}

Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static int InsertionSort(final int N, final int G, int[] A){
		int cnt = 0;
		//System.out.println("> " + G);
		for(int i = G; i < N; i++){
			final int v = A[i];
			int j = i - G;
			//System.out.println(i + " " + j);
			while(j >= 0 && A[j] > v){
				A[j + G] = A[j];
				j -= G;
				cnt++;
			}
			
			A[j + G] = v;
		}
		
		return cnt;
	}
	
	public static void ShellSort(final int N, int[] A){
		int cnt = 0;
		int m = 1;
		int[] G = new int[100];
		G[0] = 1;
		for(int i = 1; i < N; i++, m++){
			G[i] = G[i - 1] * 3 + 1;
			if(G[i] > N){
				break;
			}
		}
		
		for(int i = 0; i < m; i++){
			cnt += InsertionSort(N, G[m - i - 1], A);
		}
		
		System.out.println(m);
		for(int i = m - 1; i >= 0; i--){
			if(i != m - 1){
				System.out.print(" ");
			}
			System.out.print(G[i]);
		}
		System.out.println();
		System.out.println(cnt);
		for(int i = 0; i < N; i++){
			System.out.println(A[i]);
		}
		
	}
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		int[] A = new int[N];
		
		for(int i = 0; i < N; i++){
			A[i] = sc.nextInt();
		}
		
		ShellSort(N, A);
		
		
	}
}

Measured memory_bytes: 296972
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!

        Scanner sc = new Scanner (System.in);
        
        int a = sc.nextInt();
        
    
        String x="";
        //ac
            //wa
            //tle
            //re
        int ac=0;
        int wa=0;
        int tle=0;
        int re=0;
        
        
        for(int i=0;i<=a;i++){
            x=sc.nextLine();
            if(x.equals("AC")){
                ++ac;
            }else if (x.equals("WA")){
                ++wa;
            }else if (x.equals("TLE")){
                ++tle;
            }else if (x.equals("RE")){
                ++re;
            }
            
            
            //ac
            //wa
            //tle
            //re
        }
        System.out.println("AC x "+ac);
        System.out.println("WA x "+wa);
        System.out.println("TLE x "+tle);
        System.out.println("RE x "+re);
        
    }
}


Measured memory_bytes: 60104
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long ll;

int main(){
  int ans;
  ll a,b;
  cin>>a>>b;
  if(a<=0 && b>=0){
    cout<<"Zero"<<endl;
    return 0;
  }else if(b<0){
    if((b-a)%2==0){
      ans=-1;
    }else ans=1;
  }else{
    ans=1;
  }
  if(ans==1) cout<<"Positive"<<endl;
  else cout<<"Negative"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int[] num = new int[101];
        int cnt = 0;

        for(int i =1;i<101;i++){
            if(a%i==0 && b%i==0){
                cnt++;
                num[cnt] = i;
                //System.out.println(i);
            }
        }

        System.out.println(num[cnt-k+1]);
      
    }
}


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

int main() {
  string S;
  cin >> S;
  
  int ans = 0, sum = 0;
  for (int i = 0; i < S.size(); i++) {
    
    if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') {
      sum++;
    } else {
      sum = 0;
    }
    ans = max(ans, sum);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3624
# gets.split.map(&:to_i)

n = gets.to_i
c = []
s = []
f = []
(n-1).times do
  tc, ts, tf = gets.split.map(&:to_i)
  c << tc
  s << ts
  f << tf
end

n.times do |i|
  t = 0
  for j in i...(n-1)
    t = s[j] if t < s[j]
    t += f[j] - (t - s[j]) % f[j] if (t - s[j]) % f[j] != 0
    t += c[j]
  end
  p t
end


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

map<ll, ll> prime_factor(ll x) {
    map<ll, ll> ret;
    for (ll a = 2; a*a<=x; ++a) {
        if (x%a == 0) {
            ret[a]++;
            x /= a;
            while (x%a == 0) {
                ret[a]++;
                x /= a;
            }
        }
    }
    if (x != 1) ret[x] = 1;
    return ret;
}

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

    ll G = __gcd(A, B);
    cout << prime_factor(G).size() + 1 << endl;
}


Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad
main=do
  [xs, ys, zs] <- replicateM 3 $ map read.words <$> getLine
  let g[x,y,z] = x==y && y==z
  let f xs ys= g $ zipWith (-) xs ys
  if f xs ys && f ys zs
  then putStrLn "Yes"
  else putStrLn "No"


Measured memory_bytes: 508
from math import ceil


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    def check(Min):
        kill = 0
        for a in A:
            kill += (ceil(a/Min)-1)
        return kill <= K

    l = 0
    r = 1000000000

    while r-l > 1:
        mid = (l+r)//2
        if check(mid):
            r = mid
        else:
            l = mid
    print(r)
        


if __name__ == '__main__':
    main()

Measured memory_bytes: 30908
import numpy as np
N = int(input())
temp = input()
a = np.array([int(i) for i in temp.split()])

list_X = [0]*1000000

for ele in a:
    list_X[ele] += 1
    list_X[ele-1] += 1
    list_X[ele+1] += 1

print(max(list_X))

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

int main(){
	string s;
	int f=0,cnt=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(!f&&s[i]=='A') f=1;
		else if(f&&s[i]=='Z'){
			f=0;
			cnt++;
		}
	}
	if(!cnt) cout<<-1;
	else for(int i=0;i<cnt;i++) cout<<"AZ";
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3212
#include <stdio.h>
int main(){
  int i,j,n,h[3][2],m[3][2],s[3][2],ha,ma,sa;


  for(i=0;i<3;i++){
    scanf("%d %d %d %d %d %d",&h[i][0],&m[i][0],&s[i][0],&h[i][1],&m[i][1],&s[i][1]);
  }

  for(i=0;i<3;i++){
    ha=h[i][1]-h[i][0];
    ma=60-m[i][0]+m[i][1];
    sa=60-s[i][0]+s[i][1];
    if(s[i][0]>s[i][1])ma-=1;
    if(m[i][0]>m[i][1])ha-=1;
    if(ma>=60)ma%=60;
    if(sa>=60)sa%=60;
    printf("%d %d %d\n",ha,ma,sa);
  }

  return 0;
}

Measured memory_bytes: 600
import sys
from collections import deque
def m():
 s=sys.stdin.readlines()
 q=int(s[0].split()[1])
 f=lambda x,y:(x,int(y))
 d=deque(f(*e.split())for e in s[1:])
 t,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()


Measured memory_bytes: 17732
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：凸 n 角形の面積
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/0079
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
vector<complex<ld>> cord;

// 入力
void input() {
  ld x, y;
  while (~scanf("%Lf,%Lf", &x, &y)) {
    cord.push_back(complex<ld>(x, y));
  }
}

ld cross_product(complex<ld> a, complex<ld> b) { return (conj(a) * b).imag(); }

void solve() {
  cout << fixed << setprecision(10);
  ll n = cord.size();
  rep1(i, n-1) { cord[i] -= cord[0]; }
  cord[0]-=cord[0];
  ld ans = 0.0;
  rep1(i, n - 2) { ans += cross_product(cord[i], cord[i + 1])/2.0; }
  cout << abs(ans) << endl;
}

int main() {
  input();
  solve();
  return 0;
}



Measured memory_bytes: 3188
import sys
x = int(input())
if x == 2:
    print(2)
    sys.exit()
prime = [2]
for i in range(3, 1000000, 2):
    all(i % p != 0 for p in prime) and prime.append(i)
    if i >= x and i in prime:
        print(i)
        sys.exit()

Measured memory_bytes: 41820
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
using namespace std;

int main(){
  int a, b, c, d, e, f, tot = 0, sug = 0;
  cin >> a >> b >> c >> d >> e >> f;
  a*=100;
  b*=100;

  rep(i, 0, 100)rep(j, 0, 100)rep(k, 0, 100)rep(l, 0, 100){
    int totwat = a*i + b*j;
    int totsug = c*k + d*l;

    if(totwat+totsug <= f){
      if(totwat/100 * e >= totsug){
        if(sug*(totwat+totsug) <= totsug*tot){
          tot = totwat+totsug;
          sug = totsug;
        }
      }
    }
  }
  cout << tot << " " << sug << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pow2(x) (ll(1)<<x)
#define pb push_back
#define mp make_pair
#define w(t) int t;scanf("%d",&t);while(t--)
#define For(i,n) for(int i=0;i<n;i++)
#define scan(n) int n;scanf("%d", &n);
using namespace std;
const int sz = 1e5 + 7;
const int INF = 1e9;
int n,k;
vector<int> v(sz);
int mn;
int solve(int i=0)
{
    if(i>=n-1)
        return 0;
    if(i < n - 2)
        return mn = min(solve(i + 1) + abs(v[i] - v[i+1]), solve(i+2) + abs(v[i] - v[i+2]));
    else if(i==n-2)
        return abs(v[i] - v[i+1]);
}
int main()
{
    scanf("%d%d", &n, &k);
    For(i,n)
        scanf("%d", &v[i]);
    vector<int> ans(n,INF);
    ans[0] = 0;
    for(int i=1;i<n;i++)
    {
        for(int j = max(i-k,0);j<i;j++)
            ans[i] = min(ans[i],ans[j] + abs(v[i] - v[j]));
    }
    cout<<ans[n-1];
}


Measured memory_bytes: 4032
N,M,K = map(int,input().split())
A = [0]*N
B = [0]*M
A = list(map(int,input().split()))
B = list(map(int,input().split()))

b = []
b.append(0)
tmp = 0
for i in range(M):
    b.append(tmp+B[i])
    tmp = tmp+B[i]# M冊全部呼んだとする
a = [0]
for i in range(N):
    a.append(a[i]+A[i])
#print(b)
ans,j = 0,M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j] > K - a[i]:#Kを超えてたらこの冊数読むの諦める
        j -= 1
    ans = max(ans,i+j)#最大冊数を更新していく

print(ans)


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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
    {
        cout<<k<<endl;
        return 0;
    }
    k-=a;
    k-=b;
    if(k>0)
    {
        cout<<(a)+(-1*(min(k,c)))<<endl;
    }
    else
    {
        cout<<a<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<queue>
#include<string>

using namespace std;

void bfs();

const int Infty = 20000000;

bool **M;
int *dist,n;
string *color;
queue<int> Q;

int main(){
	cin>>n;
	M = new bool*[n]; for(int i=0;i<n;i++) M[i] = new bool[n];
	color = new string[n]; dist = new int[n];
	
	for(int i=0;i<n;i++) M[i] = M[i]-1; M = M-1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) M[i][j] = false;
	}
	color = color-1; dist = dist-1;

	int vertex,deg,edge;
	for(int i=1;i<=n;i++){
		cin>>vertex>>deg;
		for(int j=1;j<=deg;j++){
			cin>>edge;
			M[vertex][edge] = true;
		}
	}

	bfs();

	for(int i=1;i<=n;i++){
		cout<<i<<" ";
		if(dist[i]!=Infty)
			cout<<dist[i]<<endl;
		else
			cout<<-1<<endl;
	}

	for(int i=1;i<=n;i++) delete [] (M[i]+1); delete [] (M+1);
	delete [] (color+1); delete [] (dist+1);
}

void bfs(){
	for(int i=1;i<=n;i++){
		color[i] = "WHITE"; dist[i] = Infty;
	}

	int s = 1;
	Q.push(s);
	color[s] = "GRAY";
	dist[s] = 0;
	int u;
	while(!Q.empty()){
		u = Q.front();
		Q.pop();
		for(int v=1;v<=n;v++){
			if(M[u][v]==true&&color[v]=="WHITE"){
				Q.push(v);
				color[v] = "GRAY";
				dist[v] = 0;
				dist[v] = dist[u]+1;
			}
		}
		color[u] = "BLACK";
	}
}

Measured memory_bytes: 3228
io = DATA.eof? ? STDIN : DATA
n=io.gets.to_i
l=io.gets.split.map(&:to_i)
cnt=0
(0...n).to_a.combination(3).each do |i,j,k|
  a,b,c=[l[i],l[j],l[k]].sort
  next if a==b || b==c
  if a+b>c
    cnt+=1
  end
end
puts cnt

__END__


Measured memory_bytes: 14392
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	double x = 0, y = 0;
	double ang = 90;
	for (;;)
	{
		string str;
		cin >> str;

		stringstream ss;
		ss << str;

		double d, a;
		ss >> d;
		ss.ignore();
		ss >> a;

		double rad = ang * M_PI / 180.0;
		x += d * cos(rad);
		y += d * sin(rad);

		if (d == 0 && a == 0)
		{
			break;
		}
		ang -= a;
	}

	cout << (int)x << endl;
	cout << (int)y << endl;
}


Measured memory_bytes: 3688
s = input()
tc = [ chr(i)*2 for i in range(ord('a'), ord('z')+1) ]  + [ chr(i)+chr(j)+chr(i) for i in range(ord('a'), ord('z')+1) for j in range(ord('a'), ord('z')+1)]
x=y=-1
t = "0"
for i in tc:
  if i in s:
    t = i
for i in range(len(s)-len(t)+1):
    if s[i:i+len(t)] == t:
      x = i+1
      y = i+len(t)
print(x, y)

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


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;

// #define  part ..
#define listi vector<int >
#define listll vector< long long >
#define pii pair<int ,int >
#define pll pair<long long ,long long >
#define heap priority_queue<long long >
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define mod 1000000007
#define maxx 200006
#define ll long long
#define quick   ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0);
#define rep(i,a,b) for(int i=a;i<b;i++)
long long gcd(long long a, long long b) {
  
  if(b==0){
    return a;

  }

  return gcd(b,a%b);
}
 


// end of #define 

// define globals ...


long long ni() {
  int c = getchar();
  while (c < '0' || c > '9') c = getchar();
  long long ret = 0.0;
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret;
}




int Main(){
int n;
cin>>n;

int ac=0,wa=0,tle=0,re=0;
for(int i=0;i<n;i++){

  string s;
  cin>>s;
  if(s=="AC"){
    ac++;


  }
  else if(s=="TLE"){
   tle++;

  }
 else if(s=="RE"){
  re++;
 }
 else{
  wa++;
 }
}

cout<<"AC x "<<ac<<endl;
cout<<"WA x "<<wa<<endl;
cout<<"TLE x "<<tle<<endl;
cout<<"RE x "<<re<<endl;







  return 0;


}












// main function..
int main ()
{
  quick;




  Main ();


}


Measured memory_bytes: 3652
def myAnswer(N:int,T:list,M:int,P:list,X:list)-> None:
   #all_time = sum(T)
   for i in range(M):
      print(sum(T) - T[P[i]-1] + X[i])

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   T = list(map(int,input().split()))
   M = int(input())
   P = []
   X = []
   for _ in range(M):
      p,x=map(int,input().split())
      P.append(p)
      X.append(x)
   myAnswer(N,T[:],M,P[:],X[:])

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
def input_li():
    return list(map(int, input().split()))

def input_int():
    return int(input())

N = input_int()
h_li = input_li()
dp = [0] * N
dp[0] = 0
dp[1] = abs(h_li[1] - h_li[0])
for i in range(2, N):
    dp[i] = min(
        dp[i - 1] + abs(h_li[i] - h_li[i - 1]),
        dp[i - 2] + abs(h_li[i] - h_li[i - 2])
    )
print(dp[-1])


Measured memory_bytes: 85080
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
// const int k_mod = 1e9 + 7;
const int k_mod = 998244353;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	int a;
	int b;
} P;

/*
 * @fn modpow
 * @brief O(logn): a^n % mod
 * @param a: 基数
 * @param n: 指数
 * @param mod: 法
 */
ll modpow( ll a, ll n, ll mod ) {
	ll res = 1;
	while (n > 0){
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main( void ){
	int N; cin >> N;
	int times = N / 100, a = ( N % 100 ) / 5;
	bool can = ( a < times );
	can |= (a == times && (N%100)%5 == 0);
	cout << can << endl;
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
chars = gets.chomp.chars
ans = Array.new(chars.size, 0)

groups = []
count_r = 0
count_l = 0
prev = 'R'
i_r = 0
i_l = 0
start_i = 0

chars.size.times do |i|
  next if i == 0
  if i == chars.size - 1
    tmp = chars[start_i..i]
    groups << tmp
    break
  end
  if prev == 'L' && chars[i] == 'R'
    tmp = chars[start_i..i-1]
    groups << tmp
    start_i = i
  end
  prev = chars[i]
end

offset = 0

groups.each do |chunk|
  if chunk.size.odd?
    cnt_r = chunk.size / 2 + 1
  else
    cnt_r = chunk.size / 2
  end

  cnt_l = chunk.size / 2

  chunk.size.times do |i|
    next if i == 0
    if chunk[i - 1] == 'R' && chunk[i] == 'L'
      # sleep 1
      # p [cnt_r, cnt_l]
      if i % 2 == 0
        ans[offset + i - 1] = cnt_l
        ans[offset + i] = cnt_r
      else
        ans[offset + i - 1] = cnt_r
        ans[offset + i] = cnt_l
      end
    end
  end

  offset += chunk.size
end

puts ans.join(' ')


Measured memory_bytes: 16892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int A,B;
	cin>>A>>B;
	int ans = max(A+B,max(A-B, A*B));
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
A, B = map(int, input().split())


def calc(A, B):
    k = B - A + 1
    if k % 4 == 0:
        return 0
    elif k % 4 == 1:
        return B
    elif k % 4 == 2:
        return 1
    elif k % 4 == 3:
        return 1 ^ B


if A == B:
    print(A)
else:
    if A % 2 != 0:
        print(calc(A + 1, B) ^ A)
    else:
        print(calc(A, B))

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

int main(){
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n){
    cin >> x[i] >> y[i];
  }
  vector<int> order(n);
  rep(i, n) order[i] = i;

  double sum = 0;
  int count = 0;
  do{
    rep(i, n-1){
      int dx, dy;
      dx = x[order[i]] - x[order[i+1]];
      dy = y[order[i]] - y[order[i+1]];
      sum += sqrt(dx * dx + dy * dy);
    }
    count++;
  } while(next_permutation(order.begin(), order.end()));
  sum = sum / count;
  cout << fixed << setprecision(7) << sum << endl;
  return 0;
}

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

using namespace std;

int main(){
    int N;
    string S, T;
    string U;
    cin >> N >> S >> T;
    for (int i = 0; i < N; i++){
        U.push_back(S.at(i));
        U.push_back(T.at(i));
    }
    cout << U << endl;
}


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

int main(){
    int h, w,i;
    string temp;
    vector<string> strs;
    cin >> h >> w;
    for(i=0;i<h;i++){
        cin >> temp;
        temp = "#" + temp + "#";
        strs.push_back(temp);
    }

    int j;
    for(j=0;j<w+2;j++){
        cout << "#";
    }
    cout << endl;
    for (i=0;i<h;i++){
        cout << strs.at(i) << endl;
    }
    for(j=0;j<w+2;j++){
        cout << "#";
    }
    cout << endl;

}

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

using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  if (K < 1e7) {
    int now = 0;
    for (int i = 0; i < K; i++) {
      now = A[now];
    }
    cout << now + 1 << endl;
    return 0;
  }
  vector<int> B(N, -1);
  B[0] = 0;
  int cnt = 0;
  int now = 0;
  int c1, c2;
  while (1) {
    now = A[now];
    cnt++;
    if (B[now] != -1) {
      c1 = B[now];
      c2 = cnt;
      break;
    }
    B[now] = cnt;
  }
  K -= c1;
  long long K2 = K % (c2 - c1);
  for (int i = 0; i < K2; i++) {
    now = A[now];
  }
  cout << now + 1 << endl;

  return 0;
}
/* vim:set fdm=marker: */


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

using namespace std;

typedef long long ll;

const int N = 1e5 + 10, M = 1e6 + 10;
const int mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;

int t;

int main()
{
    int n;
    cin >> n;
    int flag = 1;
    for(int i  =0; i < n; i++)
    {
        int x;
        cin >> x;
        if(x % 2 == 0)
        {
            if(x % 3 == 0 || x % 5 == 0)
                continue;
            else
            {
                flag = 0;
            }
            
        }
    }
    if(flag)
        puts("APPROVED");
    else
    {
        puts("DENIED");
    }
    
    return 0;
}


Measured memory_bytes: 256
/*
 * atcoder/abc139/e.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }

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

const int MAXN = 1005;
const int MAXV = MAXN*MAXN/2;
int n, m;
vector<int> G[MAXV];

int ids[MAXN][MAXN];

// これがfalseだと辺の数を数える.
#define COUNT_VERTEXES 1
// #define MAXV 100010
vector<int> dp(MAXV, -1);
vector<bool> visited(MAXV, false);
int dfs(int v) {
  int &cc = dp[v];
  if (visited[v] && cc == -1) {
    // loop
    return -1;
  }
  if (~cc) return cc;
  visited[v] = true;
  int res = COUNT_VERTEXES;
  for (auto&& u: G[v]) {
    int ret = dfs(u);
    if (ret == -1) return -1;
    chmax(res, ret + 1);
  }

  return cc = res;
}
int longest(int V) {
  int ans = 0;
  loop(i,0,V) {
    int ret = dfs(i);
    if (ret == -1) { return -1; }
    chmax(ans, ret);
  }
  return ans;
}


void solve() {
  cin >> n;

  m = 0;
  loop(i,0,n-1) {
    loop(j,i+1,n) {
      // cout << m << ": " << i << " " << j << endl;;
      ids[i][j] = ids[j][i] = m++;
    }
  }

  int a;
  loop(i,0,n) {
    int prev_id = -1;
    loop(j,1,n) {
      cin >> a;
      a--;
      int id = ids[i][a];
      if (prev_id == -1) {
        prev_id = id;
        continue;
      }
      G[prev_id].push_back(id);
      prev_id = id;
    }
  }

  cout << longest(m) << endl;
}


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

using namespace std;

typedef unsigned long long ull;

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

    int n, m;
    cin >> n >> m;
    if (n == m)
        cout << "Yes";
    else
        cout << "No";    
    
    return 0;
}

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

#define sc second
#define fr first

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
using namespace std;




int main(){

    ios::sync_with_stdio(0);
    cin .tie(0),cout.tie(0);

    cout.precision(18);

    double d; cin >> d;
    cout << (d / 3)*(d / 3)*(d / 3);


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    
    string a,b,c;
    cin>>a>>b>>c;
    cout<<(a.back()==b.front()&&b.back()==c.front() ? "YES":"NO")<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int sq(int n){return n*n;}
int main(){
  int n,m;
  int i,j,k;
  cin >> n >> m;
  while(n!=0){
    int inf = 1 << 30;
    int c[16]={},x[20001]={};
    for(i=0;i<m;i++) cin >> c[i];
    for(i=0;i<n;i++) cin >> x[i];
    
    int dp[256]={};
    int pre[256]={};
    fill(dp,dp+256,inf);
    fill(pre,pre+256,inf);
    
    int p;
    for(i=0;i<m;i++){
      p= 128+c[i];   
      if(p<0) p=0;
      if(p>255) p=255;
      dp[p]=sq(x[0]-p);
    }
    
    for(i=1;i<n;i++){
      for(j=0;j<256;j++) pre[j]=dp[j];
      fill(dp,dp+256,inf);
      for(j=0;j<256;j++){
	for(k=0;k<m;k++){
	  p=j+c[k];
	  if(p<0) p=0;
	  if(p>255) p=255;
	  dp[p]=min(dp[p],pre[j]+sq(x[i]-p));
	}
      }
    }
    
    int o=inf;
    for(i=0;i<256;i++) o=min(o,dp[i]);
    cout << o << endl;
    
    cin >> n >> m;
  }
  return 0;
}

Measured memory_bytes: 1248
var n,i:longint;
    a,x:longint;
    max,maxx,min:longint;
    z:longint;
begin
  read(n);
  min:=maxlongint;
  for i:=1 to n do
  begin
    read(a,x);
    if a>max then max:=a;
    if x<min then min:=x;
  end;
  writeln(max+min);
end.


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

int main(){
    int A, B,N;
    int sum,ans = 0;;
    int cur =10;

    cin >> N >> A >> B;

    for(int i = 1;i <= N;i++){
        sum = 0;
        cur = i;
        while(cur > 0){
            sum += cur%10;
            cur /= 10;
        }
        if( A <= sum && sum <= B)
        ans += i;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1367

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int n, m, e;
	vector<pair<int,int>> t;
	
	cin>>n>>m;
	
	for(int i = 1; i <= n; i++){
		t.push_back(make_pair(0,i));
	}
	
	for(int i = 1; i <= m; i++){
		cin>>e;
		t[e-1].first = -i;
	}
	
	sort(t.begin(), t.end());
	
	for(int i = 0; i < n; i++){
		cout<<t[i].second<<endl;
	}
	return 0;
}


Measured memory_bytes: 6960