akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  unsigned v;
  modular(long long a = 0) : v((a %= M) < 0 ? a + M : a) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m r) { if ((v += r.v) >= M) v -= M; return *this; }
  m& operator-=(m r) { if (v < r.v) v += M; v -= r.v; return *this; }
  m& operator*=(m r) { v = (uint64_t)v * r.v % M; return *this; }
  m& operator/=(m r) { return *this *= power(r, M - 2); }
  friend m operator+(m l, m r) { return l += r; }
  friend m operator-(m l, m r) { return l -= r; }
  friend m operator*(m l, m r) { return l *= r; }
  friend m operator/(m l, m r) { return l /= r; }
  friend bool operator==(m l, m r) { return l.v == r.v; }
  friend string to_string(m a) { return to_string(a.v); }
};

constexpr long long mod = 998244353;
using mint = modular<mod>;

vector<mint> fact, inv_fact, minv;
void prepare(int n) {
  fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1);
  for (int i = 0; i <= n; ++i) fact[i] = i ? i * fact[i - 1] : 1;
  inv_fact[n] = power(fact[n], mod - 2);
  for (int i = n; i; --i) inv_fact[i - 1] = i * inv_fact[i];
  for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1];
}
mint binom(int n, int k) {
  if (k < 0 or k > n) return 0;
  return fact[n] * inv_fact[k] * inv_fact[n - k];
}
template<> mint& mint::operator/=(mint r) {
  return *this *= r.v < minv.size() ? minv[r.v] : power(r, mod - 2);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  prepare(n);
  mint res = 0, sum = 0;
  for (int j = 0; j <= n / 2; ++j) {
    sum += binom(n, j);
  }
  for (int i = 0; i <= n / 2; ++i) {
    res += binom(n, i) * sum;
    sum = (sum + binom(n - i - 1, n / 2)) * minv[2];
  }
  cout << res.v << '\n';
}


Measured memory_bytes: 117504
#include <iostream>

int main(int argc, char const* argv[])
{
	int a, b, c;
	int count = 0;
	std::cin >> a >> b >> c;

	for (size_t i = a; i < b + 1; i++)
		if( c % i == 0)
			count++;

	std::cout << count << std::endl;
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

const int N = 1e5 + 5;

const int INF = 1e9 + 5;
            
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, c; cin >> n >> c;
    vector<ll> dp(c + 1);
    //dp[i] = max profit with knapSack capacity i;
    for(int i = 0; i < n; i++)
    {
        int w, v; cin >> w >> v;
        for(int j = c; j >= w; j--)
            dp[j] = max(dp[j], v + dp[j - w]);
    }
    cout << dp[c] << endl;

}

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

int num(int a){
    int sum=0;
    while(a>0){
        sum+=a%10;
        a/=10;
    }
    return sum;
}

int main()
{
    int n;cin>>n;
    int x = num(n);
    if(n%x==0)cout<<"Yes"<<endl;
    else cout<<"No\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll long long;
int main(){
ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
long n;
cin>>n;
string s;
int a=0;
int w=0;
int t=0;
int r=0;

for(long i=0;i<n;i++){
   cin>>s;
   if(s=="AC"){
      a++;
   }else
   if(s=="WA"){
      w++;
   }else
   if(s=="TLE"){
      t++;
   }else
   if(s=="RE"){
      r++;
      
   }
}
cout<<"AC"<<" "<<"x"<<" "<<a<<endl;  
cout<<"WA"<<" "<<"x"<<" "<<w<<endl;
cout<<"TLE"<<" "<<"x"<<" "<<t<<endl;
cout<<"RE"<<" "<<"x"<<" "<<r<<endl;
return 0;
}

Measured memory_bytes: 3648
N = int(input())
B = [int(b) for b in input().split()]
A = [0] * N
A[0] = B[0]
A[1] = B[0]
for i in range(N-1):
  if B[i] >= max(A[i], A[i]):
    A[i+1] = B[i]
  else:
    A[i] = B[i]
    A[i+1] = B[i]
print(sum(A))

Measured memory_bytes: 9160
n,a,b = map(int, input().split())
count = 0
for i in range(1,n+1):
    #print(list(map(int,str(25))))
    #print(i,sum(map(int,str(i))))
    if(a<=sum(map(int,str(i)))<=b):
        count += int(i)
print(count)

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var nm = Console.ReadLine().Split();
        var n = int.Parse(nm[0]);
        var m = int.Parse(nm[1]);

        var heap = new Heap<long>();
        foreach (var item in Console.ReadLine().Split())
            heap.push(-int.Parse(item));

        for (int i = 0; i < m; i++)
        {
            var x = heap.pop() / 2;
            heap.push(x);
        }

        var ans = 0L;
        while (0 < heap.count) ans += heap.pop();

        Console.WriteLine(-ans);
    }
}

class Heap<T> where T : IComparable
{
    List<T> list = new List<T>();

    public int count => list.Count;

    void swap(int i, int j)
    {
        var t = list[i];
        list[i] = list[j];
        list[j] = t;
    }

    public void push(T x)
    {
        list.Add(x);
        _push(list.Count - 1);
    }

    void _push(int i)
    {
        if (i == 0) return;

        var j = (i - 1) / 2;
        if (list[i].CompareTo(list[j]) < 0)
        {
            swap(i, j);
            _push(j);
        }
    }

    public T pop()
    {
        var x = list[0];
        list[0] = list[list.Count - 1];
        list.RemoveAt(list.Count - 1);
        _pop(0);
        return x;
    }

    void _pop(int i)
    {
        var j = i * 2 + 1;
        var k = i * 2 + 2;

        if (k < count &&
            list[k].CompareTo(list[i]) < 0 &&
            list[k].CompareTo(list[j]) < 0)
        {
            swap(i, k);
            _pop(k);
        }
        else if (j < count &&
            list[j].CompareTo(list[i]) < 0)
        {
            swap(i, j);
            _pop(j);
        }
    }
}


Measured memory_bytes: 30092
import java.util.Scanner;

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();
		for(int i=0;i<k;i++) {
			if(a%2 != 0) {
				a--;
			}
			a /= 2;
			b += a;
			if(++i>=k) {break;}
			if(b%2 !=0) {
				b--;
			}
			b /=2;
			a+=b;
		}
 sc.close();
System.out.println(a+" "+b);
	}
}


Measured memory_bytes: 23508
<?php  

fscanf(STDIN, "%d %d %d", $a,$b,$c);
$oldColor = -1;  
$count = 1;
$answer = "NO";

// while(true){

//   if( ($a%2) == 0 && ($c%2) == 1 )break;

//   if( $b<($a+$c) )break;

//   if(($a * $count) % $b == $c){
//     $answer = "YES";
//     break;
//   }

//   $count++;
// }

function gcd($a, $b) {
    if ($b === 0)
        return $a;

    return gcd($b, $a % $b);
}
  if( $c % gcd($a, $b) == 0){
    $answer = "YES";
  
  }


  


  echo $answer;
?>

Measured memory_bytes: 3576
#include<cstdio>
#include<cstring>

int main(){
	char ch[200];
	char p[100];
	char ch2[200];

	scanf("%s", ch);
	strcpy(ch2, ch);
	strcat(ch, ch2);

	scanf("%s", p);

	if (strstr(ch, p) == NULL) printf("No\n");
	else printf("Yes\n");

	return 0;
}


Measured memory_bytes: 2748
#include <iostream>
using namespace std;
int main(){
    int a,b;
    do {
        cin >> a >> b;
        if (a != 0 || b != 0){
            if (a > b)
                cout << b << " " << a << "\n";
            else cout << a << " " << b << "\n";
        }
    } while (a != 0 || b != 0);
    return 0;
}


Measured memory_bytes: 3064
# -*- coding:utf-8 -*-
import sys
N, K = map(int, input().split())
a, b, ans = ( [], [], [] )
for tmp in range(N):
    a, b = map(int, input().split())
    ans.append((a,b))
ans.sort()
s = 0
for tmp in range(len(ans)):
    s += (ans[tmp])[1]
    if s >= K:
        print((ans[tmp])[0])
        sys.exit()

Measured memory_bytes: 16940
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	int n, k;
	cin >> n >> k;

	if(k > (n - 1) * (n - 2) / 2) {
		cout << -1 << endl;
		return 0;
	}

	vector<pii> ans;
	for(int i = 2; i <= n; i++) {
		ans.push_back(pii(1, i));
	}

	int remain = (n - 1) * (n - 2) / 2 - k;
	for(int i = 2; i <= n - 1; i++) {
		for(int j = i + 1; j <= n; j++) {
			if(remain <= 0) break;
			ans.push_back(pii(i, j));
			remain--;
		}
	}

	cout << ans.size() << endl;
	for(auto p : ans) {
		cout << p.first << ' ' << p.second << endl;
	}
}


Measured memory_bytes: 384
def solve_r(n)
    if n==0
        "0"
    elsif  n%2==0
        "0" + solve_r(n/(-2))
    else                                                                             
        "1" + solve_r((n-1)/(-2))                                                    
    end                                                                              
end

def solve(n)
    solve_r(n).reverse.to_i
end

n=gets.to_i
puts solve(n)


Measured memory_bytes: 1788
# -*- coding: utf-8 -*-


def answer(N, A, B):

    if N < A:
        return N
    else:
        T = A + B
        P, Q = divmod(N, T)
        if Q < A:
            return A * P + Q
        else:
            return A * (P + 1)

N, A, B = map(int, input().split())
print(answer(N, A, B))

Measured memory_bytes: 38384
#include <bits/stdc++.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;
    double sum = 0;
    rep(i, n){
        int a;
        cin >> a;
        sum += 1.0/a;
    }
    double ans = 1/sum;
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    const int VMAX = 2005 * 2005;
    bitset<VMAX> dp;
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        dp |= dp << x;
    }
    vector<int> values;
    for (int i = 1; i < VMAX; ++i) {
        if (dp[i]) {
            values.push_back(i);
        }
    }
    cout << values[(SZ(values) - 1) / 2] << '\n';
}


Measured memory_bytes: 11244
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=5010;
ll n,m,a[maxn][220],stac[maxn],l[maxn][220],r[maxn][220];
ll dis[maxn],del[maxn][maxn];
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=2;i<=n;++i)scanf("%lld",&dis[i]),dis[i]=dis[i]+dis[i-1];
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) scanf("%lld",&a[i][j]);
	for(int j=1;j<=m;++j)
	{
		int top=0;
		for(int i=1;i<=n;++i){
			while(top&&a[stac[top]][j]<a[i][j])--top;
			l[i][j]=top?stac[top]+1:1;
			stac[++top]=i;
		}
		top=0;
		for(int i=n;i>=1;--i){
			while(top&&a[stac[top]][j]<a[i][j])--top;
			r[i][j]=top?stac[top]-1:n;
			stac[++top]=i;
		}
		for(int i=1;i<=n;++i){
			del[l[i][j]][i]+=a[i][j];
			del[i+1][i]-=a[i][j];
			del[l[i][j]][r[i][j]+1]-=a[i][j];
			del[i+1][r[i][j]+1]+=a[i][j];
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)del[i][j]+=del[i][j-1];
		for(int j=1;j<=n;j++)del[i][j]+=del[i-1][j];
		for(int j=i;j<=n;j++)ans=max(ans,del[i][j]-dis[j]+dis[i]); 
	} 
	printf("%lld\n",ans); 
}


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

int main()
{

    std::string S, T;
    std::cin >> S >> T;

    for (int i{}; i < T.size(); ++i)
    {
        if (S == T) 
        {
            std::cout << "Yes" << std::endl;
            return 0;
        }

        S = S[S.size() - 1] + S;
        S.erase(S.end() - 1);
    }

    std::cout << "No" << std::endl;
    
    return 0;
}

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

int H, W;
const int MAX_HW = 100;
char a[MAX_HW][MAX_HW];

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> a[i][j];
        } 
    }

    queue<int> row;
    for (int i = 0; i < H; i++){
        bool f = true;
        for (int j = 0; j < W; j++) {
            if (a[i][j] == '#') {
                f = false;
            }
        }
        if (f) row.push(i);
    }

    queue<int> column;
    for (int j = 0; j < W; j++){
        bool f = true;
        for (int i = 0; i < H; i++) {
            if (a[i][j] == '#') {
                f = false;
            }
        }
        if (f) column.push(j);
    }
    

    for (int i = 0; i < H; i++) {
        if (!row.empty() && row.front() == i) {
            row.pop();
            continue;
        }

        for (int j = 0; j < W; j++) {
            if (!column.empty() && column.front() == j) {
                column.pop();
                column.push(j);
                continue;
            }

            cout << a[i][j];
        }

        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxM = 1e5+7;
const int maxV = 90010;
 
const int MOD = 1e9+7;
 
int T;
const int maxN = 1e5+8;
const ll INF = 1000000000000000010LL;
const int K = 15;
ll a[maxN];
ll b[maxN];
int n;



int main() {
	int x,y;
	scanf("%d%d",&x,&y);
	int ans = max({x+y,x-y,x*y});
	cout<<ans<<endl;
    return 0;
}

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

import fractions
f=fractions.gcd(C,D)
f2=C*D//f

res = (B//C + B//D) - ((A-1)//C + (A-1)//D) - (B//f2 - (A-1)//f2)

print((B-A+1) - res)

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a == b){
        cout << "a == b" << endl;
    }
    else if(a > b){
        cout << "a > b" << endl;
    }
    else{
        cout << "a < b" << endl;
    }
}


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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

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

bool isp[1111111];

ll dp[100010][2];

void era(){
	isp[0] = isp[1] = true;
	for(int i = 2 ; i < 1000001;i++){
		if(!isp[i]){
			for(int j = 2*i;j < 1000001;j += i){
				isp[j] = true;
			}
		}
	}
}

int main()
{
	era();
	
	//SHOW1d(isp,100);
	
	int n;cin >> n;
	vector<int> v(n);
	REP(i,n){
		cin >> v[i];
	}
	
	dp[0][0] = 1;
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 2;j++){
			if(dp[i][j]){
				if(j == 0){
					if((i == 0 && !isp[v[i]]) ||(i > 1 && !isp[v[i]] && v[i] > v[i-2])){
						dp[i+1][1] = (dp[i+1][1] + dp[i][0]) % MOD;
					}
				}
				else{
					if(!isp[v[i]] && v[i] > v[i-1]){
						dp[i+1][1] = (dp[i+1][1] + dp[i][j]) %MOD;
					}
					dp[i+1][0] = (dp[i+1][0] + dp[i][j]) % MOD;
				}
			}
		}
	}
	
	//REP(i,n+1)cout << dp[i][0] << ' ';cout << endl;
	//REP(i,n+1)cout << dp[i][1] << ' ';cout << endl;
	
	cout << (dp[n][0] + dp[n][1]) % MOD << endl;

	return 0;
}


Measured memory_bytes: 5748
n, q = map(int,input().split())
s = input()

cnt = [0] * (n+1)

for i in range(n):
    if s[i] == 'C' and i != 0 and s[i-1] == 'A':
        cnt[i+1] = cnt[i] + 1
    else:
        cnt[i+1] = cnt[i]

for query in range(q):
    l, r = map(int,input().split())
    print(cnt[r] - cnt[l])

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

using namespace std;

int main() {
    string str;
    cin >> str;
    
    if(str=="SUN") {
        cout << 7 << endl;
    } else if(str=="SAT") {
        cout << 1 << endl;
    } else if(str=="FRI") {
        cout << 2 << endl;
    } else if(str=="THU") {
        cout << 3 << endl;
    } else if(str=="WED") {
        cout << 4 << endl;
    } else if(str=="TUE") {
        cout << 5 << endl;
    } else if(str=="MON") {
        cout << 6 << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


char a[55][55];

int main(){FIN

    ll n;cin>>n;
    vll a(n);
    REP(i,n) cin>>a[i];
    ll dis=0;
    REP(i,n){
        if(i==0) dis += abs(a[0]);
        else dis += abs(a[i]-a[i-1]);
    }
    dis += abs(a[n-1]);

    REP(i,n){
        ll dis2=dis;
        if (i==0) {
            dis2 -= abs(a[0]);
            dis2 -= abs(a[1]-a[0]);
            dis2 += abs(a[1]);
        }
        else if (i==n-1){
            dis2 -= abs(a[n-1]);
            dis2 -= abs(a[n-2]-a[n-1]);
            dis2 += abs(a[n-2]);
        }
        else {
            dis2 -= abs(a[i-1]-a[i]);
            dis2 -= abs(a[i]-a[i+1]);
            dis2 += abs(a[i-1]-a[i+1]);
        }
        cout<<dis2<<endl;
    }
    return 0;
}

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

int main() {
    string s;   cin >> s;
    int len = s.length();

    for (int bit = 0; bit < (1<<(len-1)); bit++) {
        int sum = s[0] - '0';
        for (int i = 0; i < len-1; i++) {
            if (bit & (1<<i))
                sum += s[i+1] - '0';
            else 
                sum -= s[i+1] - '0';
        }

        if (sum == 7) {
            cout << s[0];
            for (int i = 0; i < len-1; i++) {
                if (bit & (1<<i))
                    cout << "+" << s[i+1];
                else 
                    cout << "-" << s[i+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}

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

string S;

int main(){
	cin >> S;
	for(int i = 0; i < S.size() - 1; i++){
		if(S[i] == 'A' && S[i + 1] == 'C'){
			cout << "Yes" << endl;
			return 0;
		}
	}
			cout << "No" << endl;
			return 0;





}


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

int main(){

int n;
string str;
while(1){


cin>>n;if(n==0)break;
cin>>str;

int N[11]={};int x=0;

for(int i=0;i<100;i++)
{
int p=i%n;
if(str[i]=='M')N[p]++;
if(str[i]=='S'){x+=(N[p]+1);N[p]=0;}
if(str[i]=='L'){N[p]+=(x+1);x=0;}
}
for(int i=0;i<n;i++)
	for(int j=n-1;j>i;j--)
	{if(N[j]<N[j-1]){int t=N[j];N[j]=N[j-1];N[j-1]=t;}}


for(int i=0;i<n;i++)
{if(i>0)cout<<" ";
cout<<N[i];
}
cout<<" "<<x<<endl;
}
return 0;
}

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

using namespace std;

const int M = 2e5;
int n, arr[M];
long long memo[M][3], big = 2e16;

long long solve(int i, int twos) {
    if (i >= n) {
        if (n & 1) {
            if (twos > 2 || twos < 1)
                return -big;
            return 0;
        }
        if (twos > 1)
            return -big;
        return 0;
    }

    if (twos > 1 + (n & 1))
        return -big;

    long long &r = memo[i][twos];
    if (r == -1)
        r = arr[i] + max(solve(i + 2, twos), solve(i + 3, twos + (i < n - 2)));

    return r;
}

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

    memset(memo, -1, sizeof memo);
    cin >> n;
    long long ans = -2e18;

    for (int i = 0; i < n; i++)
        cin >> arr[i];

    if (n % 2 == 0)
        ans = max(solve(0, 0), solve(1, 1));
    else
        ans = max(max(solve(0, 0), solve(1, 1)), solve(2, 2));

    cout << ans << "\n";

    return 0;
}

/*

even at most 1
odd at most 2 and at least 1

1 2 3 4 5 6 7 8 9 10 11

*/

Measured memory_bytes: 15368
#include<bits/stdc++.h>
using namespace std;
#define mod             1000000007
#define w(x)            int x; cin>>x; while(x--)
#define mk(arr,n,type)  type *arr=new type[n];
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int *arr = new int[5];
	for (int z = 0; z < 5; z++) {
		cin >> arr[z];
		if (arr[z] == 0) {
			cout << z + 1 << " ";
		}
	}

	return 0;
}

Measured memory_bytes: 3560
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
	int D, S, T;
	cin >> D >> S >> T;
	if (S * T >= D) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for (int i = 0; i < s.length(); ++i)
		if(s[i] != t[i])
			++cnt;
	cout << cnt << endl;
}

Measured memory_bytes: 3856
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        long N=gl();
        String wr=gs();
        
        int wn=0;
        int rn=0;
        for (int i=0; i<N; i++) {
        	char c=wr.charAt(i);
        	if(c=='W') {
        		wn++;
        	} else {
        		rn++;
        	}
        }
        
        long ans=Math.min(wn, rn);
        
        long ans2=0;
        for (int i=0; i<rn; i++) {
        	char c=wr.charAt(i);
        	if(c=='W') {
        		ans2++;
        	}
        }
        
        System.out.println(Math.min(ans,  ans2));

//        if(K%2==0) {
//
//		    System.out.println(-1);
//        } else {
//        	System.out.println("No");
//
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 40184
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		Map<String, List<Integer>> book = new TreeMap<String, List<Integer>>();
		while(sc.hasNext()) {
			List<Integer> page = new ArrayList<Integer>();
			String[] text = sc.nextLine().split(" ");
			if(book.containsKey(text[0])) {
				page = book.get(text[0]);
				page.add(Integer.parseInt(text[1]));
				book.put(text[0], page);
			} else {
				page.add(Integer.parseInt(text[1]));
				book.put(text[0], page);
			}
		}

		for(String str : book.keySet()) {
			System.out.println(str);
			List<Integer> page = book.get(str);

			//???????????????????????????
			Collections.sort(page);

			for(int $ = 0; $ < page.size(); $++) {
				if($ == 0) {
					System.out.print(page.get($));
				} else {
					System.out.print(" " + page.get($));
				}
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 26228
h,w=map(int,input().split())
list=[]
a=[[b for b in input()] for _ in range(h)]
for i in range(w):
    list.append('#')
a.insert(0,list)
a.append(list)
for j in range(len(a)):
    a[j].insert(0,'#')
    a[j].append('#')
for k in range(len(a)):
    for l in range(w+2):
        print(a[k][l],end="")
    print('')

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

using ll = long long;

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    for (ll i = A; i <= min(B, A + K - 1LL); i++)
        cout << i << endl;
    for (ll i = max(B - K + 1LL, A + K); i <= B; i++)
        cout << i << endl;
    return 0;
}

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

#pragma warning( disable : 4996 )

#define si(n) scanf("%d", &n)
#define sll(n) scanf("%lld", &n)
#define ss(s) scanf("%s", &s)
#define pi(n) printf("%d\n", n)
#define pll(n) printf("%lld\n", n)
#define ps(s) printf("%s\n", s)
#define FOR(i, a, b) for (int i=a;i<=b;i++)

typedef long long ll;



void solve() {
	//input
	int n, m, k;
	cin >> n >> m >> k;
	vector<ll> a(n);
	for (auto& i : a) sll(i);
	vector<ll> b(m);
	for (auto& i : b) sll(i);

	//pre_sum O(n)
	vector<ll> a_sum(n + 1);
	a_sum[0] = 0;
	a_sum[1] = a[0];
	FOR(i, 2, n) {
		a_sum[i] = (ll)a_sum[i - 1] + a[i - 1];
	}
	vector<ll> b_sum(m + 1);
	b_sum[0] = 0;
	b_sum[1] = b[0];
	FOR(i, 2, m) {
		b_sum[i] = (ll)b_sum[i - 1] + b[i - 1];
	}
	//dp O(nlogm)
	int max_book = 0;
	FOR(i, 0, n) {
		if (a_sum[i] > k) {
			break;
		}
		//two pointers
		int l = 0, r = m, mid;
		while (l < r) {
			mid = (l + r) / 2;
			ll sum1 = b_sum[mid] + a_sum[i];
			ll sum2 = b_sum[mid + 1] + a_sum[i];
			if (sum1 <= k && sum2 > k) {
				break;
			}
			else if (sum1 > k) {
				r = mid - 1;
			}
			else if (sum1 < k) {
				l = mid + 1;
			}
		}
		mid = (l + r) / 2;
		max_book = max(max_book, i + mid);

	}
	cout << max_book << endl;
}

int main() {
	solve();
}

Measured memory_bytes: 9600
#include <stdio.h>

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define N 200010
#define MAX 1000000000000000000
#define MOD 1000000007

#include <stdio.h>

int main (void) {
    int n, a, i;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &a);
        if ((a % 2 == 0) &&
                ((a % 3 != 0) &&
                 (a % 5 != 0))) {
            puts("DENIED");
            return 0;
        }
    }

    puts("APPROVED");

    return 0;
}



Measured memory_bytes: 1640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    bool ans = false;
    if(a == b) {
        if(a != c) ans = true;
    } else {
        if(a == c || b == c) ans = true;
    }
    cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <ctype.h>
const int bufSize = 1e6;
inline char nc()
{
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename T>
inline T read(T& r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc())
        if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int maxn = 5e3 + 100;
int n, k, P[maxn], C[maxn];
long long sum[maxn], f[maxn];
int vis[maxn];
inline long long check(int s)
{
    for (int i = 0; i <= n; ++i) sum[i] = f[i] = -(1ll << 60), vis[i] = 0;
    sum[0] = 0;
    int u = s, i = 1;
    for (;; ++i)
    {
        u = P[u];
        sum[i] = sum[i - 1] + C[u];
        f[i] = std::max(f[i - 1], sum[i]);
        if (vis[u]) break;
        else vis[u] = i;
    }
    if (k <= i) return f[k];
    long long num = sum[i] - sum[vis[u]];
    if (num <= 0) return f[i];
    int len = i - vis[u];
    int times = (k - vis[u]) / len, pos = k - times * len;
    return f[pos] + num * times;
}
int main()
{
    read(n), read(k);
    for (int i = 1; i <= n; ++i) read(P[i]);
    for (int i = 1; i <= n; ++i) read(C[i]);
    long long ans = check(1);
    for (int i = 2; i <= n; ++i) ans = std::max(ans, check(i));
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1796
import collections
n = int(input())
lis = list(map(int,input().split()))
count = 0

countArray = [0]*n
calc=0

for i in range(n):
    calc += lis[i]
    countArray[i] = calc
    if calc == 0:
        count +=1

c = collections.Counter(countArray)
a = c.most_common()
for i in range(len(c.most_common())):
    counts = a[i][1]
    if counts < 2:
        break
    count += (counts * (counts - 1)) // 2
print(count)

Measured memory_bytes: 62576
//C++
//#pragma comment(linker, "/STACK:102400000,102400000")
//G++
//#define OPENSTACK
#define ONLINE_JUDGE
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cctype>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MOD = 998244353;
const int N = 3e5 + 1000, M = N;//刻意开大会消耗时间.

int ha[N], hb[N];
int x[N], y[N];

int main()
{
    #ifdef OPENSTACK
    int size = 64 << 20; // 64MB
    char *p = (char*)malloc(size) + size;
    #if (defined _WIN64) or (defined __unix)
        __asm__("movq %0, %%rsp\n" :: "r"(p));
    #else
        __asm__("movl %0, %%esp\n" :: "r"(p));
    #endif
    #endif
    #ifndef ONLINE_JUDGE
        freopen("../put/a.input","r",stdin);
        freopen("../put/a.output","w",stdout);
    #endif
    clock_t c1 = clock();
    //coding here......

    int h, w, m;
    cin >> h >> w >> m;
    int mx = 0, my = 0;

    for(int i = 1; i <= m; i ++){
        cin >> x[i] >> y[i];
        ha[x[i]] ++, mx = max(mx, ha[x[i]]);
        hb[y[i]] ++, my = max(my, hb[y[i]]);
    }
    
    LL t1 = 0, t2 = 0, t = 0;
    for(int i = 1; i <= h; i ++) if(ha[i] ==  mx) t1 ++;
    for(int i = 1; i <= w; i ++) if(hb[i] ==  my) t2 ++;

    t = t1 * t2;
    for(int i = 1; i <= m; i ++){
        if(ha[x[i]] == mx && hb[y[i]] == my) t --;
    }

    if(t) cout << mx + my << endl;
    else cout << mx + my - 1 << endl;
    //finish here......
    #ifndef ONLINE_JUDGE
        std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
    #endif
    #ifdef OPENSTACK
        exit(0);
    #else
        return 0;
    #endif
}

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

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

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

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

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

  cout << (N / 2) + (N&1) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"

const int N = 2e5;

int n, a[N], b[N];
ll ans;

int main () {
	ios_base::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n + 1; ++i) {
		cin >> a[i];
	}		
	for(int i = 1; i <= n; ++i) {
		cin >> b[i];
	}
	for(int i = 1; i <= n; ++i) {
		ans += min(a[i], b[i]);
//		a[i] -= min(a[i], b[i]);
		b[i] -= min(a[i], b[i]);
		ans += min(a[i + 1], b[i]);
		a[i + 1] -= min(a[i + 1], b[i]);
	}
	cout << ans;
	return 0;
}

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

int main()
{
    int dp[4][200]={0};
    int a[4][200];
    
    int n;cin>>n;
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=n;j++)
            cin>>a[i][j];
    }
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
    
    cout<<dp[2][n]<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);


typedef long long ll;
typedef long int li;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef long double ld;

#define mp make_pair
#define f first
#define s second

#define pu push
#define pb push_back

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define print(x) cout<<x<<endl;
#define printarray(a, start, end) for(int i=start; i<=end; i++) cout<<a[i]<<" "; cout<<endl;


ll n, k;
ll ar[200];
ll dp[105][100010];
ll pre[100010];
ll MOD=1000000007;

int main()
{
	fastio;
	cin>>n>>k;
	rep(i, n) cin>>ar[i];
	rep(i, n)
	{
		rep(j, k+1)
		{
			if(i==0)
			{
				if(j<=ar[i]) dp[i][j] = 1;
			}
			else
			{
				if(ar[i]>0)
				{
					if(j<=ar[i]) dp[i][j] = pre[j]%MOD;
					else dp[i][j] = (pre[j] - pre[max((ll)0, j-ar[i]-1)] + MOD)%MOD;
				}
				else
				{
					dp[i][j] = dp[i-1][j]%MOD;
				}
			}

		}

		rep(j, k+1)
		{
			if(j==0) pre[j]=dp[i][j]%MOD;
			else
			{
				pre[j] = (pre[j-1] + dp[i][j])%MOD;
			}
		}


	}
	print(dp[n-1][k]%MOD);
	return 0;
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = GetString();
            var T = GetString();

            if (T.Remove(T.Length - 1, 1) == S)
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
        }

        private static long[] GetLongNumArray()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => long.Parse(x)).ToArray();
        }

        private static long GetLongNum()
        {
            return long.Parse(Console.ReadLine());
        }

        private static string[] GetStringArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static string GetString()
        {
            return Console.ReadLine();
        }
    }
}


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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int a,b; cin >> a >> b;
    if (a*b % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

int main() {

  int a, b, c;
  cin >> a >> b >> c;
    
  bool poor = false;
    
    if(a == b && a != c)
      poor = true;
    if(b != c && a == c)
      poor = true;
    if(b == c && a != c)
      poor = true;

  if(poor)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <math.h>
 
using namespace std;
// https://qiita.com/Clpsplug/items/81fe12400d4093a8fb5a
 
int main() {
    long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int payment = 0;

    while (X >= 0 || Y >= 0)
    {
        if (X > 0 && Y > 0) {
            if (2*C < A+B) {
                payment += 2*C;
                X--;
                Y--;
            } else {
                payment += A+B;
                X--;
                Y--;
            }
        } else if (X == 0 && Y > 0) {
            if (2*C < B) {
                payment = payment + 2*C*Y;
                cout << payment << endl;
                return 0;
            } else {
                payment = payment + B*Y;
                cout << payment << endl;
                return 0;
            }
        } else if (X > 0 && Y == 0) {
            if (2*C < A) {
                payment = payment + 2*C*X;
                cout << payment << endl;
                return 0;
            } else {
                payment = payment + A*X;
                cout << payment << endl;
                return 0;
            }
        } else {
            cout << payment << endl;
            return 0;
        }
    }
    
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

#define MAX 500000
int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;


signed main()
{   
    gearup;
    int n;cin >> n;
    vl v(n);
    rep(i,n) cin >> v[i];
    sort(all(v)); //昇順ソート
    double res = (v[0] + v[1])*1.0/2;
    for(int i=2;i<n;i++){
        res = (res + v[i])/2;
    }
    cout << fixed << setprecision(6) << res << endl;
}

Measured memory_bytes: 256
N=int(input())
if 0<=N<=9:
  print(N)
elif 10<=N<=99:
  print(9)
elif 100<=N<=999:
  print(N-90)
elif 1000<=N<=9999:
  print(909)
elif 10000<=N<=99999:
  print(N-9090)
else:
  print(90909)

Measured memory_bytes: 3060
n,m = map(int,input().split())

mod =10**9+7
sum = 0
min = 0
max = 0

for k in range(1,n+2):
    min += k-1
    max += n-(k-1)

    if k >= m:
        sum = (sum + max-min+1) % mod
print(sum)


Measured memory_bytes: 9128
use std::ops::{Index, IndexMut};
use std::cmp::{Ordering};
use std::collections::BinaryHeap;
use std::cmp::{min, max};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! split {
    ($x: expr) => {
        ($x).trim().split(' ').collect()
    }
}

macro_rules! parse {
    ($x: expr) => {
        ($x).parse().unwrap()
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {}", stringify!($x), $x)
    }
}

fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!();
}

fn main() {
    
    let s = getline();
    let iv: Vec<_> = split!(s);
    let n: i64 = parse!(iv[0]);
    let s = getline();
    let iv: Vec<_> = split!(s);
    let a: Vec<i64> = iv.into_iter().map(|x| parse!(x)).collect();
    
    let mut l: i64 = 0;
    let mut r: i64 = 1e16 as i64;
    
    let hoge = 2*n;
    let check = |x: i64| {
        let mut res = false;
        for i in 0..hoge {
            let m = x+i;
            let sum: i64 = a.clone().into_iter().map(|x| max((x-(n-1-m)+n)/(n+1),0)).sum();
            res = res || sum <= m; 
        }
        res
    };
    
    while r-l > 1 {
        let m = (l+r)/2;
        if !check(m*hoge) {
            l = m;
        } else {
            r = m;
        }
    }

    if check(0) {
        r = 0;
    }
    
    let mut ans = -100;
    for i in 0..hoge {
        let m = r*hoge+i;
        let sum: i64 = a.clone().into_iter().map(|x| max((x-(n-1-m)+n)/(n+1),0)).sum();
        if sum <= m {
            ans = m;
            break;
        }
    }
    println!("{}",ans);

}



Measured memory_bytes: 4352
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,K = two_int()
R,S,P = map(int , input().split())
T=one_str()

dicts={}
dicts["r"] = R
dicts["s"] = S
dicts["p"] = P

checks=[False for i in range(N)]
hand=[]

index=0
output = []
for i in range(N):
    if T[i]=="r":
        output.append("p")
    elif T[i]=="s":
        output.append("r")
    else:
        output.append("s")

sums =0
for i in range(len(output)):
    if i <K:
        sums += dicts[output[i]]
        checks[i]=True
    else:
        if output[i]==output[i-K]:
            if checks[i-K]!=True:
                sums += dicts[output[i]]
                checks[i]=True

        else:
            sums += dicts[output[i]]
            checks[i]=True


print(sums)

Measured memory_bytes: 4980
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, K, a = 1, i;
    cin >> N >> K;
    
    for(i = 0; i < N; i++){
        if(a * 2 <= a + K)
        a = a * 2;
        
        else
        a = a + K;
    }
    cout << a << endl;
}


Measured memory_bytes: 3592
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    cnt = min(n, m // 2)
    n -= cnt
    m -= cnt * 2
    if m != 0:
        cnt += (m // 4)
    print(cnt)


if __name__ == '__main__':
    slove()


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

int main() {
  int N, A;
  cin >> N >> A;
  
  int b = N % 500;
  if (b <= A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;

  bool ok = false;
  if(n%2 == 0 && s.substr(0, n/2) == s.substr(n/2, n/2)) ok = true;

  cout << (ok ? "Yes" : "No") << endl;
  
}


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;
using P=pair<int,int>;

int main(){
  int n; ll k;
  cin>>n>>k;
  vector<int>a(n);
  rep(i,n) cin>>a[i];
  
  vector<int> s;
  vector<int> ord(n+1,-1);
  int c=1,l=0;
  {
    int v=1;
    while(ord[v]==-1){
      ord[v]=s.size();
      s.push_back(v);
      v=a[v-1];
    }
    c=s.size()-ord[v];
    l=ord[v];
  }
  if(k<l)cout<<s[k]<<endl;
  else{
    k-=l;
    k%=c;
    cout<<s[l+k]<<endl;
  }
  return 0;
}


Measured memory_bytes: 5876
#!/usr/bin/env python3
n, m = map(int, input().split())
l = [0] * m
r = [0] * m
for i in range(m):
    l[i], r[i] = map(int, input().split())
if min(r) - max(l) + 1 >= 0:
    print(min(r) - max(l) + 1)
else:
    print(0)


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

void solve() {
  long long n;
  cin>>n;
  string s="";
  for (int i=0; i<50; i++) {
    if (n<=0) {
      break;
    }
    int d;
    if (n%26!=0) {
      d=n%26-1;
    }
    else {
      d=25;
    }
    char c='a'+d;
    s+=c;
    n=(n-1)/26;
  }
  reverse(s.begin(), s.end());
  cout<<s;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define INF (INT_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

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

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

  long long ans = t[0];
  for(int i = 1; i < n; i++){
    ans = lcm(ans, t[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	if(a<=9 && b<=9)
	cout<<a*b;
	else 
	cout<<"-1";
   
	return 0;
}


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

bool isSquare(const int *const &x, const int *const &y, const int &D);

int main(int argc, char *argv[]){
    unsigned int N,D;
    std::cin >> N >> D;
    int X[N][D];
    for(auto &x : X){
        for(auto &xElement : x){
            std::cin >> xElement;
        }
    }

    int i,j;
    int numSquare=0;
    for(i=0; i<N; ++i){
        for(j=i+1; j<N; ++j){
            if(isSquare(X[i],X[j],D)){
                ++numSquare;
            }
        }
    }
    
    std::cout << numSquare << std::endl;

    return 0;
}

bool isSquare(const int *const &x, const int *const &y, const int &D){
    unsigned int squaredDistance = 0;
    for(int i=0; i<D; ++i){
        squaredDistance += (x[i]-y[i])*(x[i]-y[i]);
    }
    unsigned int distance = static_cast<unsigned int>(std::sqrt(static_cast<double>(squaredDistance)));
    if(distance*distance == squaredDistance){
        return true;
    }else{
        return false;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  string s;
  cin >> s;
  ll k=s.size();
  ll cnt=0;
  rep(i,k){
    if(s[i]=='g'){
      cnt++;
    }
    else
      cnt--;
  }
  cout << cnt/2 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main() {
    long long int n, b;
    std::cin >> n;
    std::vector<long long int> a(n);

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

    std::sort(a.begin(), a.end());
    if (n % 2 == 0) b = a[n/2];
    else b = a[(n-1)/2];

    long long ret = 0;

    for (auto j : a) {
        ret += std::abs(j - b);
    }

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

    return 0;
}

Measured memory_bytes: 1792
//JSD
#include<iostream>
#define Mod 1000000007
#define ll long long 
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
int main(){
	ll n,k;
	cin>>n>>k;
	ll a[n];
	int l[n]={0},r[n]={0};
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		ll count=0;
		for(int j=0;j<i;j++){
			if(a[i]>a[j]) count++;
		}	
		l[i]=count;
		count=0;
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]) count++;
		}
		r[i]=count;
	}
//	for(int i=0;i<n;i++){
//		cout<<l[i]<<" ";
//	}
//	cout<<"\n";
//	for(int i=0;i<n;i++){
//		cout<<r[i]<<" ";
//	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ll p1,p2;
		if(k%2==0){
			p1=(k/2)*((k+1));
			p1%=Mod;
			p2=(k/2)*((k-1));
			p2%=Mod;
		}	
		else{
			p1=(k)*((k+1)/2);
			p1%=Mod;
			p2=(k)*((k-1)/2);
			p2%=Mod;
		}
		ans=(ans+(p1*(r[i]))%Mod)%Mod;		
		ans=(ans+(p2*(l[i]))%Mod)%Mod;		
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256