akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            Console.WriteLine(n % 2 == 0 ? n : 2 * n);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;cin>>a>>b;
    if(a<=9&&b<=9) cout<<a*b;
    else cout<<-1;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [[0 for i in range(M)] for j in range(N)]

for i in range(N):
    A[i] = list(map(int, input().split()))

ans = float('inf')
for i in range(M):
    rank = [0] * M
    for j in range(N):
        rank[A[j][0] - 1] += 1
    ans = min(ans, max(rank))
    remove_idx = rank.index(max(rank)) + 1
    for j in range(N):
        A[j].remove(remove_idx)
print(ans)


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


int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  sort(l.begin(),l.end());
  int ans = 0;
  rep(b,n)rep(a,b){
    int ab = l[a]+l[b];
    int R = lower_bound(l.begin(),l.end(),ab) - l.begin();
    int L = b+1;
    ans += R-L;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

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

    int n,ans = 0,l,r;
    cin>>n;
    vector<char>c(n);
    rep(i,n)cin>>c[i];
    l = 0;
    r = n - 1;
    while(true){
        while(c[l] == 'R' && l < n)l++;
        while(c[r] == 'W' && r >= 0)r--;
        if(l >= r)break;
        c[l] = 'R';
        c[r] = 'W';
        ans++;
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> vec(m);
  for (auto &v : vec)
    cin >> v;
  sort(vec.begin(), vec.end());

  vector<ll> vec2(max(n,m));
  for (ll i = 1; i < m; ++i)
    vec2[i-1] = vec[i] - vec[i-1];
  sort(vec2.begin(), vec2.end(), greater<ll>());

  cout << accumulate(vec2.begin() + n - 1, vec2.end(), 0) << endl;
}

Measured memory_bytes: 4696
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

int main() {
    int n, m;
    std::vector<std::vector<int>> e;

    std::cin >> n >> m;
    e.reserve(n+10);
    for (int i = 0; i < n + 2; i++) {
        e.push_back(std::vector<int> {});
    }

    for (int i = 0; i < m; i++) {
        int a,b;
        std::cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    int ret = 0;
    std::deque<std::vector<int>> q {{1}};
    while (true) {
        if (q.empty()) break;

        auto visited = std::vector<int>(q.front());
        auto current = visited.back();

        if (visited.size() == n) {
            ret++;
            q.pop_front();
            continue;
        }

        for (const auto next : e[current]) {
            if (std::find(visited.begin(), visited.end(), next) == visited.end()) {
                auto pushvec = std::vector<int>(visited);
                pushvec.push_back(next);
                q.push_back(pushvec);
            }
        }

        q.pop_front();
    }

    std::cout << ret << std::endl;

    return 0;
}

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

int main(){
  double H,W,w,h,x,y;
  cin>>W>>H>>w>>h>>x>>y;
  double ax=min(W/2,(w/2)+x);
  double ay=min(H/2,(h/2)+y);
  double bx=max(-W/2,x-(w/2));
  double by=max(-H/2,y-(h/2));
  //cout<<(ax+bx)
  printf("%.10f\n",(double)(ay+by)/(ax+bx));
}



Measured memory_bytes: 3284
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N - 1];
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			--A[i];
		}
		for (int i = 0; i < N; ++i) {
			B[i] = sc.nextInt();
			ans += B[i];
		}
		for (int i = 0; i < N - 1; ++i) {
			C[i] = sc.nextInt();
		}
		for (int i = 0; i < N - 1; ++i) {
			if (A[i] + 1 == A[i + 1]) {
				ans += C[A[i]];
			}
		}
		System.out.println(ans);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int main() {
	int N;
	string S;

	cin >> N;
	cin >> S;

	for (int i = 0; S[i] != '\0'; i++) {
		S[i] += N;
		if ((int)S[i] > (int)90) {
			S[i]-=26;
		}
	}

	cout << S << endl;


	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{   
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string[] strx = Console.ReadLine().Split(' ');
        string[] stry = Console.ReadLine().Split(' ');
        double[] datax = new double[n];
        double[] datay = new double[n];
        double[] dis = new double[n];
        double p1 = 0;
        double p2 = 0;
        double p3 = 0;
        double nugen = 0;      

        for(int i = 0; i < n; i++)
        {
            datax[i] = double.Parse(strx[i]);
            datay[i] = double.Parse(stry[i]);
            double s = datax[i] - datay[i];
            dis[i] = s > 0 ? s : -s;
        }

        double p2sum = 0;
        double p3sum = 0;
        for(int i = 0; i < n; i++)
        {
            p1 += dis[i];
            p2sum += Math.Pow(dis[i], 2);
            p3sum += Math.Pow(dis[i], 3);
        }
        p2 = Math.Sqrt(p2sum);
        p3 = Math.Pow(p3sum, 1.0 / 3.0);
        nugen = dis.Max();

        Console.WriteLine(string.Format("{0:f6}\n{1:f6}\n{2:f6}\n{3:f6}", p1, p2, p3, nugen));

    }
}


Measured memory_bytes: 18396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=505,mod=1e9+7;
const ll mod2=(ll)mod*mod*7;
int n,x,to[N];
ll dp[N][N],ni[N],fac[N];
void add(ll &a,ll b){
	a+=b; if(a>=mod2)a-=mod2;
}
ll ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	n=read(); x=read()+1;
	For(i,fac[0]=1,x)fac[i]=fac[i-1]*i%mod;
	ni[x]=ksm(fac[x],mod-2);
	Rep(i,x,1)ni[i-1]=ni[i]*i%mod;
	For(i,1,n)to[read()]++;
	dp[0][0]=1;
	Rep(i,x,1){
		Rep(j,x,0)Rep(o,j,0)if(dp[j][o]){
			dp[j][o]%=mod;
			For(k,1,to[i])dp[j][o]=dp[j][o]*(j-o*i)%mod;
			//cout<<i<<" "<<j<<" "<<o<<" "<<dp[j][o]<<endl;
			for(int k=1;j+i*k<=x;k++){
				add(dp[j+i*k][o+k],ni[k]*dp[j][o]);
			}
		}
	}
	ll ans=0;
	For(i,0,x){
		//cout<<dp[x][i]*fac[i]%mod<<endl;
		ll t=dp[x][i]%mod*fac[i]%mod;
		ans=(ans+(i%2?t:mod-t))%mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5496
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = min(A)+min(B)
for _ in range(m):
    x,y,c = map(int,input().split())
    ans = min(ans,A[x-1]+B[y-1]-c)
print(ans)

Measured memory_bytes: 24872
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); (i)++)

int main()
{
	long long n;
	int ans = 100000;
	cin >> n;
	rep(i, 1, (int)sqrt(n))
	{
		if (n%i == 0)
		{
			int da = to_string(i).size();
			int db = to_string(n / i).size();
			ans = min(ans, max(da, db));
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int arr[n][3];
	for(int i=0;i<n;i++)
	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	int dp[n][3];
	dp[0][0]=arr[0][0],dp[0][1]=arr[0][1],dp[0][2] = arr[0][2];
	for(int i=1;i<n;i++)
	{
		dp[i][0] = arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	int ans = dp[n-1][0];
	ans = max(ans,dp[n-1][1]);
	ans = max(ans,dp[n-1][2]);
	cout<<ans;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 4001;
int lss[2][N][2 * N];
//lss[0][i][j] = the number of elements less than or equal to j in b0 b1 b2
int dp[2 * N][N];
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  char c;
  int pos;
  int p1, p2;
  p1 = p2 = 0;
  vector<int> pos1(n);
  vector<int> pos2(n);
  for(int i = 0;i < 2 * n;i++){
    cin >> c >> pos;
    if(c == 'W')
      pos1[pos - 1] = i;
    else
      pos2[pos - 1] = i;
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < 2 * n;j++){
      lss[0][i][j] = pos1[i] == j ? 1 : 0;
      lss[1][i][j] = pos2[i] == j ? 1 : 0;
    }
  }
  for(int i = 1;i < n;i++){
    for(int j = 0;j < 2 * n;j++){
      lss[0][i][j] += lss[0][i - 1][j];
      lss[1][i][j] += lss[1][i - 1][j];
    }
  }
  for(int i = 1;i < 2 * n;i++){
    for(int j = 0;j < n;j++){
      lss[0][j][i] += lss[0][j][i - 1];
      lss[1][j][i] += lss[1][j][i - 1];
    }
  }
  const int OO = 1e9;
//  for(int i = 1;i <= n;i++){
//    dp[0][i] = -OO;
//  }
  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n;j++){
      dp[i][j] = OO;
    }
  }
  dp[0][0] = 0;
  for(int i = 1;i <= 2 * n;i++){
    for(int j = 0;j <= i && j <= n;j++){
      // j number of whites
      // i - j number of blacks
      // add black
      int w = j;
      int b = i - j;
      if(j)
        dp[i][j] = dp[i - 1][j - 1] + (j - 1 ? (j - 1 - lss[0][j - 2][pos1[j - 1]]) : 0) + (i - j ? (i - j - lss[1][i - j - 1][pos1[j - 1]]) : 0);
      if(i - j)
        dp[i][j] = min(dp[i][j], dp[i - 1][j] +
                                 (j ? (j - lss[0][j - 1][pos2[i - j - 1]]) : 0) +
                                 (i - j - 1 ? (i - j - 1 - lss[1][i - j - 2][pos2[i - j - 1]]) : 0));
    }
  }
//  for(int i = 0;i <= n;i++){
//    for(int j = 0;j <= n;j++){
//      cout << dp[i][j] << ' ';
//    }
//    cout << endl;
//  }
  cout << dp[2 * n][n];
  return 0;
}


Measured memory_bytes: 190208
# -*- coding: utf-8 -*-
from collections import Counter

counter = Counter()
odds = 0
eat = 0

N = int(input())
for A in list(map(int, input().split())):
    counter[A] += 1

types = len(counter)

for k, v in counter.items():
    if v >= 2 and v%2 == 0:
        eat += v//2 - 1
        odds += 1
    elif v>= 2 and v%2 == 1:
        eat += v//2

if odds%2 == 0:
    eat += odds / 2
    print(types)
else:
    eat += odds // 2 + 1
    print(types-1)
    

Measured memory_bytes: 18784
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int 
#define pb push_back
#define xx first
#define yy second
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ull t;
	t=1;
	while(t--)
	{
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll A[2]={a,b},B[2]={c,d};
		
		ll i,j,ans=-1*(1e18);
		
		for(i=0;i<2;i++)
		{
			for(j=0;j<2;j++)
			{
				ll p=A[i]*B[j];
				ans=max(ans,p);
			}
		}
		
		cout<<ans;	
	}
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll po(ll a, ll b)
{
	if (b == 0)return 1;
	ll z = po(a, b / 2);
	z = z*z%mod;
	if (b & 1)z = z*a%mod;
	return z;
}
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
int main()
{
	ll a, b, t;
	scanf("%lld%lld%lld", &a, &b, &t);
	ll ga = gcd(a, t), gb = gcd(b, t);
	ll tim = ga*gb;
	a /= ga, b /= gb;
	ll g = gcd(a, b);
	ll ans = (po(2, g) + po(2, a) + po(2, b) - 1 - 2) % mod;
	printf("%lld\n", po(ans, tim));
}

Measured memory_bytes: 256
n = gets.to_i

ans = 0
for i in 1..((n-1)**0.5).to_i
  #puts "#{i} : #{((n-1)/i - i) * 2}"
  ans += ((n-1)/i - i+1) * 2
  ans -= 1 if i*i <= n-1
end
puts ans

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

#define int long long
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;

    int a[n];
    int inv[n];
    memset(inv, 0, sizeof inv);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        inv[a[i]]++;
        if (inv[a[i]] > 3) {
            cout << 0;
            return 0;
        }
    }

    vector<int> cinv[n];
    for (int i = 0; i < n; ++i) {
        cinv[a[i]].push_back(i);
    }

const int mod = 1'000'000'007;
    int mx = *max_element(a, a + n);
    int dp[n];
    memset(dp, 0, sizeof dp);
    dp[0] = (inv[0] == 1) ? 3 : 6;
    for (int i = 1; i <= mx; ++i) {
        if (cinv[i - 1].size() < cinv[i].size()) {
           cout << 0;
           return 0;
        }
        int k = (int) cinv[i - 1].size(), m = (int) cinv[i].size();
        vector<int> from(k);
        for (int j = 0; j < k; ++j)
            from[j] = j;
        
        do {
            bool can = 1;
            for (int p = 0; p < k; ++p)
                if (p == m) {
                    break;
                } else
                    can &= cinv[i - 1][from[p]] < cinv[i][p];
            dp[i] = (dp[i] + can * dp[i - 1]) % mod;
            vector<int> prev(k);
            if (m == 1 && k >= 2) {
                if (from[0] == k - 1)
                    break;
                from[0]++;
                from[1] = -1;
            } else
                next_permutation(from.begin(), from.end());
        } while (!is_sorted(from.begin(), from.end()));
    }

    cout << dp[mx] << endl;
}


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

int main()
{
  int num, dist;
  cin >> num >> dist;
  int ans = 0;
  for (int i = 0; i < num; i++)
  {
    int64_t x, y;
    cin >> x >> y;
    x = abs(x);
    y = abs(y);
    if (x * x + y * y <= (int64_t)dist * dist)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


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

int digit_sm(int K) {
    int res = 0;
    while (K > 0) res += K % 10, K /= 10;
    return res;
}

int main() {
    int N;
    cin >> N;
    int res = 1000000000;
    for (int A = 1; A < N; ++A) {
        int B = N - A;
        res = min(res, digit_sm(A) + digit_sm(B));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main(){
  ll n,w;cin>>n>>w;
  vector<vector<ll>>a(n,vector<ll>(2));
  for(ll i=0;i<n;i++){
    cin>>a.at(i).at(0);
    cin>>a.at(i).at(1);
  }
  vector<vector<ll>>dp(n,vector<ll>(1000000,0));  
  for(ll sum_w=0;sum_w<=w;sum_w++){
    if(sum_w+a.at(0).at(0)<=w){
      dp.at(0).at(sum_w+a.at(0).at(0))=a.at(0).at(1);
    }
  }
  
  for(ll i=1;i<n;i++){
    for(ll sum_w=0;sum_w<=w;sum_w++){
      dp.at(i).at(sum_w)=max(dp.at(i).at(sum_w),dp.at(i-1).at(sum_w));
      if(sum_w+a.at(i).at(0)<=w){
        dp.at(i).at(sum_w+a.at(i).at(0))=max(dp.at(i).at(sum_w+a.at(i).at(0)),dp.at(i-1).at(sum_w)+a.at(i).at(1));
      }
    }
  }
  ll ans=0;
  for(ll sum_w=0;sum_w<=w;sum_w++){
    ans=max(ans,dp.at(n-1).at(sum_w));
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 792540
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }
#define output(x) cout << x << endl;

int main() {
    int N, i;
    cin >> N >> i;
    cout << N - (i - 1) << endl;
}

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

int main() {
	int n,k;cin>>n>>k;
	vector<int> b(n);
	for(int i=0;i<k;++i) cin>>b[i];
	
	for(int bit=0;bit<(1LL<<k);++bit){
		bitset<64> bs(0);
		for(int i=0;i<k;++i){
			if(bit>>i&1) bs.set(b[i]);
		}
		cout<<bs.to_ulong()<<":";
		for(int i=0;i<k;++i){
			if(bit>>i&1) {
				cout<<" "<<b[i];
			}
		}
		cout<<endl;
	}
  return 0;
}



Measured memory_bytes: 3068
n,k=[int(i) for i in input().split()]
row=input()

cLR=0
cRL=0
oLR=0
oRL=0

if row[0]=="L":
    oRL+=1
else:
    oLR+=1
    
if row[-1]=="L":
    oLR+=1
else:
    oRL+=1

happiness=0
for i in range(n-1):
    a=row[i]
    b=row[i+1]
    if a=="L" and b=="R":
        cLR+=1
    elif b=="L" and a=="R":
        cRL+=1
    else:
        happiness+=1
    

if min(cLR,cRL)>=k:
    ans=happiness+k*2 
elif cLR>cRL and cRL+1==k:
    ans=happiness+cRL*2+1
elif cLR<cRL and cLR+1==k:
    ans=happiness+cLR*2+1
elif cLR>cRL:
    ans=happiness+cRL*2+min(oRL,cLR-cRL)
elif cLR<cRL:
    ans=happiness+cLR*2+min(oLR,cRL-cLR)
else:
    ans=happiness+cLR*2 
    
print(ans)

        
    

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod  998244353
const int N = 200010;
const int M = 3 * N;

int n , m , u , v;

int po[M] , mx;

vector< vector< int > > g[3];

vector< int > arr[3];


bool has[N];

void make(vector< vector< int > > &g , vector< int > &v){
	v.resize(n);
	for(int i = n - 1; i >= 0;i--){
		for(int j = 0 ;j <= (int)g[i].size() + 2;j++) has[j] = false;
		for(int j = 0 ;j < (int)g[i].size();j++){
			has[v[g[i][j]]] = true;
		}
		while(has[v[i]]) v[i]++;
		mx = max(mx , v[i]);
	}
}

int dp[4][N];



int main(){
	po[0] = 1;
	po[1] = ((long long)1e18) % mod;
	for(int i = 2;i < M;i++){
		po[i] = (long long)po[i - 1] * po[1] % mod;
	}
	scanf("%d",&n);
	for(int i = 0 ;i < 3;i++){
		g[i].resize(n);
		scanf("%d",&m);
		for(int j = 0 ;j < m;j++){
			scanf("%d%d",&u,&v);
			u--,v--;
			if(u > v) swap(u , v);
			g[i][u].push_back(v);
		}
		make(g[i] , arr[i]);
	}
	dp[3][0] = 1;
	for(int j = 25;j >= 0;j--){
		if(((mx >> j) & 1) == 1){
			mx = (1 << (j + 1)) - 1;
			break;
		}
	}
	for(int i = 2;i >= 0;i--){
		for(int x = 0 ; x <= mx;x++){
			dp[i][x] = 0;
			for(int j = 0 ;j < (int)arr[i].size();j++){
				dp[i][x] += (long long)dp[i + 1][(x ^ arr[i][j])] * po[j + 1] % mod;
				if(dp[i][x] >= mod) 
					dp[i][x] -= mod;
			}
		}
	}
	printf("%d\n",dp[0][0]);
	return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  queue<ll> a[n];
  rep(i,n){
      rep(j,n-1){
          ll tmp ;cin >> tmp;
          tmp--;
          a[i].push(tmp);
      }
  }
  ll ans = 0;
  set<ll> s;
  rep(i,n){
      if(a[a[i].front()].front()==i){
          if(!s.count(i)){
              s.insert(i);
          }
          if(!s.count(a[i].front())){
              s.insert(a[i].front());
          }
      }
  }
  while(s.size()){
      set<ll> ss = s;
      s.clear();
      auto it = ss.begin();
      while(it!=ss.end()){
          a[*it].pop();
          it++;
      }
      it = ss.begin();
      while(it!=ss.end()){
        ll i = *it;
        if(a[i].size() && a[a[i].front()].size() &&  a[a[i].front()].front()==i){
          if(!s.count(i)){
              s.insert(i);
          }
          if(!s.count(a[i].front())){
              s.insert(a[i].front());
          }
        }
          it++;
      }
      ans++;
  }
  rep(i,n){
      if(a[i].size()){
          cout << -1 << endl;
          return 0;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9088
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

const int MXN=100005;
vl G[MXN];
ll dp[MXN],memo[MXN];

void dfs(ll v){
    if(memo[v]!=-1){
        return;
    }
    if(G[v].size()==0){
        memo[v]=dp[v]=0;
        return;
    }
    rep(i,G[v].size()){
        dfs(G[v][i]);
        chmax(dp[v],dp[G[v][i]]+1);
        memo[v]=dp[v];
    }
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--;y--;
        G[x].pb(y);
    }
    rep(i,N){
        dp[i]=memo[i]=-1;
    }
    rep(i,N){
        dfs(i);
    }
    ll ans=-1;
    rep(i,N){
        chmax(ans,dp[i]);
    }
    cout << ans << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 12484
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
const int w=3e5+5;
const ll mod=1e9+7;
int a[w],b[w];
int main()
{
    int i,j;
    int k,q;
    cin>>k>>q;
    for(i=0;i<k;i++)
        scanf("%lld",&a[i]);
    while(q--)
    {
        int n,x,m;
        scanf("%d %d %d",&n,&x,&m);
        ll s=0;
        for(i=0;i<k;i++)
        {
            b[i]=a[i]%m;
            if(b[i]==0)
                b[i]=m;
            s+=b[i];
        }
        ll ans=x+s*((n-1)/k);
        for(i=0;i<(n-1)%k;i++)
            ans+=b[i];
        printf("%lld\n",n-1-(ans/m-x/m));
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

bool ABC(int n) {
	if (0 < n && n < 13) {
		return true;
	}
	else {
		return false;
	}
}

int main(void) {
	rapid_pleaseAC_fast;

	llint n, k;
	cin >> n >> k;
	llint x = n / k;
	x = n - k * x;
	llint y = abs(x - k);
	cout <<min(y,x) << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
typedef pair<int, int> P;

int r, c, n;
int calc(int x, int y) {
    if (x == 0) {
        return y;
    } else if (x == r) {
        return r + 2 * c - y;
    } else if (y == 0) {
        return 2 * (r + c) - x;
    } else {
        return c + x;
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cin >> r >> c >> n;

    vector <P> vec;
    for (int i = 0; i < n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        if ((x1 % r == 0 || y1 % c == 0) && (x2 % r == 0 || y2 % c == 0)) {
            int l1 = calc(x1, y1);
            int l2 = calc(x2, y2);
            vec.push_back(P(min(l1, l2), i));
            vec.push_back(P(max(l1, l2), i));
        }
    }

    sort(vec.begin(), vec.end());

    stack <int> st;
    for (int i = 0; i < vec.size(); i++) {
        if (st.size() == 0) {
            st.push(vec[i].second);
        } else {
            if (vec[i].second == st.top()) {
                st.pop();
            } else {
                st.push(vec[i].second);
            }
        }
    }

    if (st.size() > 0) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll calcNumOfCombination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll calcNumOfPermutation(ll n, ll r) {
  return factorial(n) % mod / factorial(n - r) % mod;
}

int main() {
  ll n, m;
  cin >> n >> m;
  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return 0;
  }
  ll nc, mc;
  if ((n + m) % 2 == 0) {
    nc = calcNumOfPermutation(n, n) % mod;
    mc = calcNumOfPermutation(m, m) % mod;
    cout << 2 * (nc * mc) % mod << endl;
  } else {
    nc = calcNumOfPermutation(n, n) % mod;
    mc = calcNumOfPermutation(m, m) % mod;
    cout << nc * mc % mod << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
MOD = 10**9 + 7
N = int(input())
S = []
x = 0
for a in map(int, input().split()):
    x ^= a
    S.append(x)

A = defaultdict(int)
B = defaultdict(int)
L = defaultdict(int)
Z = 0

for s in S:
    if s == 0:
        Z += 1
    else:
        A[s] = (A[s] + (Z - L[s])*B[s])%MOD
        B[s] = (A[s] + B[s] + 1)%MOD
        L[s] = Z

if S[-1] != 0:
    print((A[S[-1]] + 1)%MOD)
else:
    print((sum(B.values()) + pow(2, Z-1, MOD))%MOD)

Measured memory_bytes: 73360
#define s(a,b) (t=a,a=b,b=t)
f(int*a){*a=(*a&7)<<4|*a>>4;}char p[9];m,a,b,c,t,r;main(n){while(scanf("%d",&n),n){r=1,a=97,b=82,c=67;while(n--){scanf("%s",p);m=*p-76;if(m%6==0){s(b,c);t=m>0?f(&c):f(&b);}else if(1<m&&m<8){s(a,b);t=m^7?f(&b):f(&a);}else{s(a,c);t=m>0?f(&c):f(&a);}r+=a&7;}printf("%d\n",r);}}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{

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

	    char[] S = sc.next().toCharArray();
	    int ans = 0;
	    char[] N = {'C','O','D','E','F','E','S','T','I','V','A','L','2','0','1','6'};

	    for(int i = 0;i<16;i++){
	    	if(S[i]!=N[i]){
	    		ans++;
	    	}
	    }
	    System.out.println(ans);
	}
}

Measured memory_bytes: 9556
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
template<class T>bool chmax(T &a, const T &b) { if( a < b ) { a = b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) { if( b < a ) { a = b; return 1; } return 0;}

#ifdef LOCAL
	#define eprintf(...) printf(__VA_ARGS__)
#else 
	#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int main() {
	int N;
	scanf("%d", &N);
	char S1[59], S2[59];
	scanf("%s", S1);
	scanf("%s", S2);

	lli ans = 0;
	int s = 0;
	if (S1[0] == S2[0]) {
		ans = 3;
		s = 1;
	} else {
		ans = 6;
		s = 2;
	}

	for (int i = s; i < N;) {
		if (S1[i] == S2[i]) {
			if (S1[i-1] == S2[i-1]) ans *= 2;
			else ans *= 1;
			i += 1;
		} else {
			if (S1[i-1] == S2[i-1]) ans *= 2;
			else ans *= 3;
			i += 2;
		}
		eprintf("%lld\n", ans);
		ans %= 1000000007;
	}

	printf("%lld\n", ans);
	return 0;
}



Measured memory_bytes: 256
n = int(input())
if n==2:
    print(-1)
else:
    a3 = ['aa.', '..a', '..a']
    a4 = ['aabc', 'ddbc', 'bcaa', 'bcdd']
    a5 = ['aabba', 'bcc.a', 'b..cb','a..cb', 'abbaa']
    a6 = ["aabc.." , 'ddbc..','..aabc', '..ddbc', "bc..aa", "bc..dd"]
    a7 = ["aabbcc.", "dd.dd.a", "..d..da", "..d..db", "dd.dd.b", "..d..dc", "..d..dc"]
    
    if n==3:
        for p in a3:
            print(p)
    else:
        a44 = ['.'*(n-4) + x for x in a4]
        if n%4==0:
            lt = []
            for i in range(n//4):
                for j in range(len(a44)):
                    a44[j] = a44[j][(n-4):] + a44[j][:(n-4)]
                    lt.append(a44[j])
            for st in lt:
                print(st)
        else:
            x = n//4 - 1 
            r = n%4 + 4 
            q = []
            if r==5:
                q = ['.'*(n - 5) + m for m in a5]
            elif r==6:
                q = ['.'*(n - 6) + m for m in a6]
            elif r==7:
                q = ['.'*(n - 7) + m for m in a7]
            lt = []
            for i in range(x):
                for j in range(len(a44)):
                    a44[j] = a44[j][(n-4):] + a44[j][:(n-4)]
                    lt.append(a44[j])
            for j in q:
                lt.append(j)
            for st in lt:
                print(st)
            
                
            
        

Measured memory_bytes: 43632
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

  while (N--) {
    string str;
    cin>> str;
  vector<string> v;    
    v.resize(6 * (str.size() - 1) + 2);
    int idx = 0;  
    v[idx++] = str;
    for (int i = 1; i < str.size(); i++) {
      string head = str.substr(0, i);
      string tail = str.substr(i);      
      reverse(head.begin(), head.end());
      v[idx++] = head + tail;
      v[idx++] = tail + head;
      reverse(tail.begin(), tail.end());
      v[idx++] = head + tail;
      reverse(head.begin(), head.end());
      v[idx++] = head + tail;
      v[idx++] = tail + head;
      reverse(tail.begin(), tail.end());
      v[idx++] = tail + head;
    }
    reverse(str.begin(), str.end());
    v[idx++] = str;
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    cout << v.size() << endl;;
  }
  return 0;
}

Measured memory_bytes: 988
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int r = ni();
		double rr = r * 2.0 * Math.PI;
		out(rr);

	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


Measured memory_bytes: 35896
a, b, h, m = gets.split("\s").map(&:to_f)

hour_ang = ((h*60.0 + m) % 720.0) / 2.0
minu_ang = 6.0 * m
digr = (hour_ang - minu_ang).abs % 360
digr = digr <= 360 ? digr : 360 - digr
th = Math::PI * digr / 180.0

x = [a, b].min
y = [a, b].max

print Math.sqrt(x**2 + y**2 - 2*x*y*Math.cos(th))


Measured memory_bytes: 14744
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  string x;
  std::cin >> x;
  stack<char> st;
  for(int i=0; i<x.size(); i++){
    if(x[i]=='S') st.push('S');
    else{
      if(!st.empty() && st.top()=='S') st.pop();
      else st.push('T');
    }
  }
  std::cout << st.size() << '\n';

  return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,A,B,C,D,E;
  cin>>N>>A>>B>>C>>D>>E;
  cout<<4+N/min(A,min(B,min(C,min(D,E))))+(N%min(A,min(B,min(C,min(D,E))))+min(A,min(B,min(C,min(D,E))))-1)/min(A,min(B,min(C,min(D,E))))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

vector<pair<LL, LL>> prime_factorization(LL x) {
	assert(x > 0);
	vector<pair<LL, LL>> f;
	for(LL i = 2; i <= x; i++) {
		if(i * i > x) { i = x; }
		if(x % i == 0) {
			f.EB(i, 0);
			while(x % i == 0) { f.back().SE++; x /= i; }
		}
	}
	return f;
}

vector<LL> divisors(LL x) {
	auto pf = prime_factorization(x);
	vector<LL> d = { 1 };
	for(auto e: pf) {
		int ds = d.size();
		inc(i, ds) {
			LL v = d[i];
			inc(j, e.SE) { v *= e.FI; d.PB(v); }
		}
	}
	sort(ALL(d));
	return d;
}

LL n, k, a[500], s;

int main() {
	cin >> n >> k;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) { s += a[i]; }
	auto d = divisors(s);
	reverse(ALL(d));
	
	RF(e, d) {
		vector<int> v(n);
		inc(i, n) { v[i] = a[i] % e; }
		sort(ALL(v));
		
		LL x = 0, y = 0;
		inc(i, n) { y += e - v[i]; }
		
		bool f = false;
		inc(i, n + 1) {
			f |= (max(x, y) <= k && (x - y) % e == 0);
			if(i == n) { break; }
			x += v[i];
			y -= e - v[i];
		}
		
		if(f) {
			cout << e << endl;
			return 0;
		}
	}
	
	UR;
	
	return 0;
}


Measured memory_bytes: 256
K, N = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.sort()

d = []
for i in range(N):
  if i == N-1:
    d.append(a[0] + K - a[N-1])
  else:
    d.append(a[i+1] - a[i])

maxDistance = max(d)
startIndex = d.index(maxDistance)
ans = 0
for i in range(N-1):
  ans += d[startIndex - i-1]

print(ans)

Measured memory_bytes: 25452
num = list(map(int,input().split()))
cnt_five = 0
cnt_seven = 0
def serch_five(a):
	if a == 5:
		return 1
	else:
		return 0
def serch_seven(a):
	if a == 7:
		return 1
	else:
		return 0

for i in num:
	cnt_five += serch_five(i)
	cnt_seven += serch_seven(i)
if cnt_five == 2 and cnt_seven == 1:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int K, X;
	cin >> K >> X;
	int diff = max(0, K-1);


	for(int i=diff; i>0; i--) {
		if(i!=diff) cout << " ";
		cout << X-i;
	}
	if(diff != 0) cout << " ";
	cout << X;
	for(int i=1; i<=diff; i++) {
		cout << " " << X+i;
	}

	// cout << "[deb: val ]" << val <<endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<map>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<utility>
#include<string.h>
#include<string>
#define n 200000
#define loop(i, a, b) for(int i=a; i<=b; i++)
using namespace std;
typedef pair<int, int> P;
typedef long long lli;
typedef double llf;
bool visit[n + 50];
int arr[n + 50], arr2[n + 50], a, b, c, d, e, f;
string str1, str2;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
vector<edge> V[n + 50];
void addedge(int a, int b, int c)
{
	edge temp;
	temp.from = a;
	temp.to = b;
	temp.weight = c;
}

////////////////////////////////////////

void solve()
{
	cin >> str1;
	int sum = 700;
	loop(i, 0, str1.size() - 1) if(str1[i] == 'o') sum += 100;
	cout << sum << '\n';
}
int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 0, times - 1)
	{
		solve();
		printf("\n");
	}
	return 0;
}



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

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


Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    string s;
    cin >> N >> s;
    ll red = 0, blue = 0;
    for (char c : s) {
        (c == 'R' ? red++ : blue++);
    }
    cout << (red > blue ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int cnt[1001001];

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

int main(void){
	int n,i,j,g=0,a;
	bool flag = true;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> a;
		g = gcd(a,g);
		++cnt[a];
	}
	for(i=2; i<=1000000; ++i){
		a = 0;
		for(j=i; j<=1000000; j+=i){
			a += cnt[j];
		}
		if(a>1){
			flag = false;
			break;
		}
	}
	if(flag){
		std::cout << "pairwise coprime" << std::endl;
	}else if(g == 1){
		std::cout << "setwise coprime" << std::endl;
	}else{
		std::cout << "not coprime" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 7536
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f

int main()
{
    char s1[1000],s2[1000],s3[1000];
    int a,b;
    while(~scanf("%s%s%d%d%s",s1,s2,&a,&b,s3))
    {
        if(strcmp(s1,s3)==0)
        {
            a--;
        }
        else
            b--;
            printf("%d %d\n",a,b);
    }
}


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

int main() {
	int n, a, b;
	string s;
	cin >> n >> a >> b;
	cin >> s;

	for (int i = 0; i < n; i ++)
		if (s[i] == 'c')
			cout << "No" << endl;
		else if (a == 0 && b == 0)
			cout << "No" << endl;
		else if (s[i] == 'a') {
			cout << "Yes" << endl;
			if (a > 0) a --; else b --;
		} else if (s[i] == 'b') {
			if (b > 0) {
				cout << "Yes" << endl;
				b --;
			} else
				cout << "No" << endl;
		}
}

Measured memory_bytes: 896
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using vvll = vector<vll>;
const double EPS = 1e-9;
const ll MOD=1e9+7;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  ll n; cin>>n;
  vector<double> p(n);
  rep(i,n) cin>>p[i];
  vector<vector<double>> dp(n,vector<double>(n+1,0.0));
  dp[0][0]=1-p[0];
  dp[0][1]=p[0];
  for( ll i=1; i<n; i++ ){
    dp[i][0] = dp[i-1][0]*(1-p[i]);
    for( ll j=1; j<=i+1; j++ ){
      dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
    }
  }
  double psum=accumulate(dp[n-1].begin()+(n>>1)+1,dp[n-1].end(),0.0);
  cout<<setprecision(10)<<psum<<endl;
}


Measured memory_bytes: 73748
#include<stdio.h>
#include<string.h>

int main(void)
{
	char mozi[1001];
	int i, a;
	scanf("%s", mozi);
	a=strlen(mozi);
	for(i=0; i<a; i++)
	{
		if(mozi[i]=='A')
		{
			mozi[i]='X';
		}
		else if(mozi[i]=='B')
		{
		mozi[i]='Y';
		}
		else if(mozi[i]=='C')
		{
		mozi[i]='Z';
		}
		else
		{
		mozi[i]=mozi[i]-3;
		}
	}
	printf("%s\n", mozi);
	return 0;
}



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


def solve():
    N, K = map(int, input().split())
    l = [tuple(map(int, input().split())) for _ in range(N)]
    candidates = [K]
    b = 0
    for i in range(30)[::-1]:
        if K&(1<<i):
            candidates.append(b + (1<<i) - 1)
            b += (1<<i)

    ans = 0
    for k in candidates:
        buf = 0
        for i, j in l:
            if i|k==k:
                buf += j
        ans = max(ans, buf)
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 22596