akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final long a = sc.nextLong();
			final long b = sc.nextLong();
			final long c = sc.nextLong();
			
			if(a + b > c) {
				System.out.println("No");
				return;
			}
			
			final long left = (c - a - b) * (c - a - b);
			final long right = 4 * a * b;
			
			//System.out.println(left + " " + right);
			System.out.println(left > right ? "Yes" : "No");
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 23252
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n, k = map(int, input().split())

    MOD = 10**9 + 7

    s = 0
    for i in range(k, n + 2):
        a = ((i - 1) * i) // 2
        s = (s + (n * i) - (2 * a) + 1) % MOD

    print(s)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

int main(){
  string S ;
  cin >> S ;
  int a = S.size();
  bool ans = true;
  for(int i=0;i<a;i++){
    if(i%2!=0&&S[i]=='R') ans = false;
    if(i%2==0&&S[i]=='L') ans = false;
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
def is_palindrome(s):
    n = len(s)
    ok = True
    for i in range(n):
        if s[i] != s[n-i-1]:
            ok = False
    if ok: return True
    else: return False

s = input()
n = len(s)
h = (n-1) // 2
sa = s[0:h]
sb = s[h+1:n]
if is_palindrome(s) and is_palindrome(sa) and is_palindrome(sb):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
l1 = []
l2 = []

for i, h in enumerate(a):
    l1.append(i + h+1)
    l2.append(i - h+1)

c1 = Counter(l1)
c2 = Counter(l2)

cnt = 0

for h in (c1.keys() | c2.keys()):
    if h in c1.keys() and h in c2.keys():
        cnt += c1[h] * c2[h]

print(cnt)


Measured memory_bytes: 172388
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v) {
  for (auto & x : v) is >> x;
  return is;
}

template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) {
  auto n = v.size();
  os << "{";
  for (size_t i = 0; i < n; i++)
    {os << (i > 0 ? "," : "") << v.at(i);}
  return os << "}";
}

auto bat(int x, int j)
  { return (x >> j) & 1; }

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, g; std::cin >> n >> g;
  g /= 100;
  std::vector< int > p(n), c(n);
  rep(i, 0, n) {
    int x, y; std::cin >> x >> y;
    y /= 100;
    p.at(i) = x, c.at(i) = y;
  }
  auto inf = 1 << 30;
  auto cal = [&] (auto&& bs) {
    auto cost = 0;
    auto score = 0;
    rep(i, 0, n) {
      if (bat(bs, i)) {
        cost  += p.at(i);
        score += (i + 1) * p.at(i) + c.at(i);
      }
    }
    if (g <= score)
      { return cost; }
    auto j = -1;
    rep(i, 0, n) {
      if (!bat(bs, i))
        { j = i; }
    }
    assert(j != -1);
    auto q = (g - score + j) / (j + 1);
    if (p.at(j) <= q)
      { return inf; }
    cost  += q;
    score += q * (j + 1);
    assert(score - (j + 1) < g && g <= score);
    return cost;
  };
  auto ret = inf;
  auto N = 1 << n;
  rep(bs, 0, N)
    { cmn(ret, cal(bs)); }
  std::cout << ret << std::endl;
  return 0;
}


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



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


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

int n,e,s,t,ans=0;
bool visited[101]={};
bool checked[101]={};
vector<int> v[101];

void dfs(int num){
  if(visited[num]){
    ans=1;
    return;
  }
  visited[num]=true;
  for(int i=0;i<v[num].size();i++){
    if(!checked[v[num][i]])dfs(v[num][i]);
  }
  checked[num]=true;
  visited[num]=false;
}

int main()
{
  cin>>n>>e;
  for(int i=0;i<e;i++){
    cin>>s>>t;
    v[s].push_back(t);
  }
  for(int i=0;i<n;i++){
    if(!checked[i])dfs(i);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1216
//AtCoder Beginner Contest 176
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 2e5 + 5;
const ll INF = 1e9 + 5;
const ll mxN = 1000000007;
const double E = 1e-9;

//------------------------------------------------------------------------------
int n;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*ifstream cin("input.txt");
	ofstream cout("output.txt");*/
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll ans = 0, pre = a[0];
	for (int i = 1; i < n; i++)
	{
		if (a[i] < pre)
			ans += pre - a[i];
		else
			pre = a[i];
	}
	cout << ans;
	return 0;
}
//22-08-2020 17:47:34
//------------------------------------------------------------------------------

Measured memory_bytes: 3960
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int a ,b; cin >> a >> b;
	cout << (a*b%2==0?"Even":"Odd") << endl;
	return 0;
}

Measured memory_bytes: 256
# B
n, k = map(int, input().split())
d = [0]*(n+1)
for i in range(k):
    dd = int(input())
    a = list(map(int, input().split()))
    for j in range(dd):
        d[a[j]] += 1
ans = 0
for k in d:
    if k == 0:
        ans += 1
        
print(ans-1)

Measured memory_bytes: 9188
#include <iostream>
using namespace std;
#define MAX 1000000
typedef long long ll;

int n,k;
ll T [MAX];
int check(ll p){
    int i=0;
    for(int j=0;j<k;j++){
        ll s=0;
        while(s+T[i]<=p){
            s+=T[i];
            i++;
            if(i==n)return n;
        }
    }
    return i;
}

int solve(){
    ll min=0;
    ll max=100000*10000;
    ll mid;
    while(max-min>1){
        mid=(max+min)/2;
        int v=check(mid);
        if(v>=n)max=mid;
        else min=mid;
    }
    return max;
}
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>T[i];
    ll P=solve();
    cout<<P<<endl;
}


Measured memory_bytes: 3876
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    ll out = 0;
    ll less = min(X,Y);
    if((A+B)>2*C){
        out = C*2*less;
        if(X>Y) out += min(A,C*2)*(X-less);
        else out += min(B,C*2)*(Y-less);
    }else out = A*X+B*Y;
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
   string st;
   cin>>st;

   string t;
   cin>>t;

   int count=0;

   int stl=st.size();
   int tl=t.size();

   int start=51;

   for(int i=0;i<=stl-tl;i++){
       for(int j=0;j<tl;j++){
           if(st[j+i]!=t[j] && st[j+i]!='?') break;
           if(j==tl-1)start=i;
       }
   }

   if(start!=51){
       for(int i=0;i<stl;i++){
           
           if(i==start){
               for(int j=0;j<tl;j++){
                    cout<<t[j];
                }
                i+=tl-1;
           }else if(st[i]=='?'){
               cout<<"a";
           }else{
               cout<<st[i];
           }
       }
       cout<<endl;
   }else{
       cout<<"UNRESTORABLE"<<endl;
   }

}

Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a[2000010];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	rep(i, n - 1)cout << a[i] << " ";
	cout << a[n - 1] << endl;
}


Measured memory_bytes: 18692
///*
//#include<stdio.h>
//#include<stdlib.h>

#include<iostream>
using namespace std;

typedef struct gbhome {
	int cost;
	int time;
}gbh;

int main() {

	int n, time;
	int i, j;
	gbh *poi, smallest;

	cin >> n;
	cin >> time;
	//scanf_s("%d", &n);

	poi = new gbh[n];
	//poi = (gbh*)malloc(sizeof(gbh)*n);

	for (i = 0; i < n; i++) {
		cin >> poi[i].cost >> poi[i].time;
		//scanf("%d %d", &poi[i].cost, &poi[i].time);
	}

	
	for (i = 0; i < n; i++) {
		for (j = 0; j < n - 1; j++) {
			if (poi[j].time > poi[j + 1].time) {
				gbh fake = poi[j];
				poi[j] = poi[j + 1];
				poi[j + 1] = fake;
			}
		}
	}
	

	smallest = poi[0];

	for (i = 0; i < n; i++) {
		
		if (poi[0].time > time) {
			cout << "TLE";
			return 0;
		}

		if (poi[i].time > time) {
			break;
		}
		else if (smallest.cost > poi[i].cost) {
			smallest = poi[i];
		}

	}

	cout << smallest.cost;

	return 0;

}
//*/

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    float crane, tor;
    int craneI, torI;
    int x, y, flag=1;
    cin>>x>>y;
    crane = (4*x - y)*1.0/2;
    tor = (y - 2*x)*1.0/2;
    // cout<<crane<<tor;
    if(ceil(crane) != crane || crane<0){
        flag = 0;
    }
    if(ceil(tor) != tor || tor<0){
        flag = 0;
    }
    
    if(flag == 0){
        cout<<"No";
    }else{
        cout<<"Yes";
    }
    return 0;
}


Measured memory_bytes: 3740
#include<iostream>
#define PI 3.141592653589
using namespace std;

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

	
	for ( int i = 0; i < n; i++ ){
		if (i!=0){cout << " ";}
		cout << a[n-i-1];
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,d,A;cin>>n>>d>>A;
    set<pair<ll,pll> >x;
    rep(i,n){
        ll a,b;cin>>a>>b;
        x.insert(mp(a,mp(1,b)));
    }
    ll ans=0;
    ll now=0;
    for(auto e:x){
        ll a=e.first,b=e.second.first,c=e.second.second;
        //cout<<a<<' '<<b<<' '<<c<<endl;
        if(b){
            c-=now;
            if(c<=0)continue;
            ll f=(c-1)/A+1;
            ans+=f;
            x.insert(mp(a+2*d+1,mp(0,f*A)));
            now+=f*A;
        }else{
            now-=c;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
int arr[105];
int main() {
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> arr[i];
    }
    int j = 0;
    int minDiff = INT8_MAX;
    for(int i = 0; i < N; i++){
        if(j >= N){
            break;
        }
        int sum1, sum2;
        sum1 = sum2 = 0;
        for(int k = 0; k <= j; k++){
            sum1 += arr[k]; 
        }
        for(int k = j + 1; k < N; k++){
            sum2 += arr[k];
        }
        if(minDiff > abs(sum1 - sum2)){
            minDiff = abs(sum1 - sum2);
        }
        j++;
    }
    cout << minDiff << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int a[5],b,c,d,e,f,k;
    for(b=1;b<=4;b++)scanf("%d",&a[b]);
    for(b=1;b<=4;b++){
        for(c=b+1;c<=4;c++){
            if(a[b]<a[c]){
                d=a[b];
                a[b]=a[c];
                a[c]=d;
            }
        }
    }
    scanf("%d%d",&e,&f);
    if(f<e)k=a[1]+a[2]+a[3]+e;
    else k=a[1]+a[2]+a[3]+f;
    printf("%d\n",k);
    return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    string S;cin>>S;
    int ans=0;
    int tmp=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T'){
            tmp++;
        }
        else{
            if(ans<tmp){
                ans=tmp;
            }
            tmp=0;
        }
        if(ans<tmp){
            ans=tmp;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int INF = 200000;

int n, m, s, t;
vector<int> graph[100010];
vector<int> cost;

#define print(...) {for(auto x: __VA_ARGS__) cout<<x<<" ";}
#define debug(...) {cout<<#__VA_ARGS__": ";print(__VA_ARGS__);cout<<endl;}

void bfs() {
    queue<P> next; // P(node, cost)
    next.push(P(s, 0));
    cost[s] = 0;

    while(next.size() > 0 && cost[t] == INF) {
        P c = next.front(); next.pop();

        // けんけんぱで行けるところ
        for(auto n1 : graph[c.first]) {
            for(auto n2: graph[n1]) {
                for(auto n3: graph[n2]) {
                    if(cost[n3] != INF)
                        continue;
                    next.push(P(n3, c.second+1));
                    cost[n3] = c.second + 1;
                }
            }
        }
    }
}

int main() {
    cin >> n >> m;
    cost.assign(n, INF);

    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        graph[u].push_back(v);
    }
    cin >> s >> t;
    s--; t--;

    bfs();
    cout << (cost[t] != INF ? cost[t] : -1)  << endl;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
 ll n,m,sum=0;
  cin>>n>>m;
  ll a[n];
  for(ll i=0;i<n;i++)
  {
    ll k;
    cin>>k;
    a[i]=-k;
  }
  sort(a,a+n); 
  if(m>n)
  {
    cout<<"0";
  }
  else
  {
    ll j;
    if(m>0)
    {
      j=m;
    }
    else
    {
      j=0;
    }
   for(ll i=j;i<n;i++)
   {
     sum=sum+abs(a[i]);
   }
    cout<<sum;
  }
  
  
}


Measured memory_bytes: 1792
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n = readint;
    auto xs = readints;

    auto deque = Deque!int(n);
    for (int i = 0; i < xs.length; i++) {
        if ((i & 1) == 0) {
            deque.insertBack(xs[i]);
        }
        else {
            deque.insertFront(xs[i]);
        }
    }

    int[] buf;
    for (int i = 0; i < deque.length; i++) {
        buf ~= deque[i];
    }
    if (xs.length % 2 == 1)
        buf.reverse();
    writeln(buf.map!(to!string).join(" "));
}

struct Deque(T) {
    private T[] _buffer;
    private int _front;
    private int _back;

    this(int size) {
        _buffer = new int[size * 3];
        _front = _back = (size * 3) / 2;
    }

    bool empty() @property { return  _front == _back; }
    int length() @property { return _back - _front; }

    void insertFront(T value) {
        if (empty) {
            _buffer[_front] = value;
            _back++;
            return;
        }

        _buffer[--_front] = value;
    }

    void insertBack(T value) {
        if (empty) {
            _buffer[_front] = value;
            _back++;
            return;
        }

        _buffer[_back++] = value;
    }

    void removeFront() {
        assert(!empty);
        ++_front;
    }

    void removeBack() {
        assert(!empty);
        --_back;
    }

    T opIndex(int index) {
        return _buffer[_front + index];
    }
}


Measured memory_bytes: 14448
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n, x, l=0, cnt=1;
    cin >> n >> x;
    rep(i, n){
        int d;
        cin >> d;
        l += d;
        if(l <= x) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

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

    private void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        int r = Integer.parseInt(tokenizer.nextToken());
        int c = Integer.parseInt(tokenizer.nextToken());
        int k = Integer.parseInt(tokenizer.nextToken());
        long[][][] dp = new long[r][c][4];
        int[][] map = new int[r][c];
        for (int i = 0; i < k; i++) {
            tokenizer = new StringTokenizer(f.readLine());
            int r1 = Integer.parseInt(tokenizer.nextToken()) - 1;
            int c1 = Integer.parseInt(tokenizer.nextToken()) - 1;
            int v = Integer.parseInt(tokenizer.nextToken());
            map[r1][c1] = v;
        }
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                if (i != 0) {
                    for (int l = 0; l < 4; l++) {
                        dp[i][j][0] =  Math.max(dp[i - 1][j][l], dp[i][j][0]);
                    }
                }
                if (j != 0) {
                    for (int l = 0; l < 4; l++) {
                        dp[i][j][l] = Math.max(dp[i][j - 1][l], dp[i][j][l]);
                    }
                }
                for (int l = 2; l >= 0; l--) {
                    if (dp[i][j][l] == 0 && l != 0) continue;
                    dp[i][j][l + 1] = Math.max(dp[i][j][l + 1], dp[i][j][l] + map[i][j]);
                }
            }
        }

        long max = 0;
        for (int i = 0; i < 4; i++) max = Math.max(max, dp[r - 1][c - 1][i]);

        /*
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(map[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                System.out.print(Arrays.toString(dp[i][j]) + " ");
            }
            System.out.println();
        } */

        out.println(max);

        out.close();
    }
}

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

int main() {
  long N,M;
  cin >> N>>M;
  vector<int> a(N);

  for(int i=0;i<N;i++) cin>>a[i];
  long ans=0;

  priority_queue<int> que;
  for(int i=0;i<N;i++){
 que.push(a[i]);
    }

  for(int i=0;i<M;i++){
    int s = que.top()/2;
    que.pop();
    que.push(s);
  }

  for(int i=0;i<N;i++){
    if(!que.empty()){
      //cout <<que.top()<<endl;
      // 追加された仕事うち最も給料が高いものを取り出す
      ans += que.top();
      que.pop();
    }

}

cout<<ans<<endl;
}


Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
using namespace std;
struct as
{
	int number;
	int muq;
};
bool cmp(as& a,as& b)
{
	return a.muq<b.muq;
}
as a[100010];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].muq;
		a[i].number=i;
		//1 2
		//2 3
		//3 1
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		cout<<a[i].number<<" ";
	}
	return 0;
 } 

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    ll A; cin >> A;
    string B; cin >> B;
    int x;
    int s=100;
    for(int i=0;i<4;i++){
        if(i==1) continue;
        x += ((B[i])-'0')*s;
        s /= 10;
    }
    cerr << x << endl;
    cout << (A*x)/100 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#pragma warning(disable:4996)

using namespace std;

int main(){
	string S;
	int cntJOI,
		cntIOI;

	while (cin >> S){
		cntJOI = 0;
		cntIOI = 0;
		int i = 0;
		while (i + 2 <= S.size()){
			if (S.substr(i, 3) == "JOI"){
				cntJOI++;
				i += 2;
			}
			else if (S.substr(i, 3) == "IOI"){
				cntIOI++;
				i += 2;
			}
			else{
				i++;
			}
		}
		cout << cntJOI << endl;
		cout << cntIOI << endl;
	}

	return 0;
}

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

signed main()
{
	int n; cin >> n;
    int cnt{};
	map<int, int> a{};
	while (n--)
	{
		int tmp; cin >> tmp;

		++a[tmp];
	}

	for(auto itr: a){
		cnt += itr.second % 2;
	}

	cout << cnt << endl;
	
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() { 
  i64 N;
  cin >> N;
  vector<i64> A(N);
  {
    string S;
    cin >> S;
    rep(i,0,N) {
      A[i] = S[i] - '0';
    }
  }

  if(N == 2) {
    cout << std::abs(A[0] - A[1]) << endl;
    return 0;
  }

  {
    vector<i64> B(N - 1);
    rep(i,0,N - 1) {
      B[i] = std::abs(A[i] - A[i + 1]);
    }
    swap(A, B);
    N--;
  }

  vector<i64> cnt(N + 10);
  rep(i,1,N + 10) {
    i64 c = 0;
    i64 x = i;
    while((x & 1) == 0) {
      x >>= 1;
      c++;
    }
    cnt[i] = cnt[i - 1] + c;
  }

  auto func = [&]() {
    i64 sum = 0;
    rep(i,0,N) {
      i64 c = cnt[N - 1] - cnt[i] - cnt[N - 1 - i];
      if(c == 0) {
        sum += A[i];
      }
    }
    return sum;
  };

  bool odd = func() % 2 == 1;
  if(odd) {
    cout << 1 << endl;
    return 0;
  }
  rep(i,0,N) {
    if(A[i] == 1) {
      cout << 0 << endl;
      return 0;
    }
    if(A[i] == 2) {
      A[i] = 1;
    }
    else {
      A[i] = 0;
    }
  }

  odd = func() % 2 == 1;
  if(odd) {
    cout << 2 << endl;
    return 0;
  }
  else {
    cout << 0 << endl;
    return 0;
  }
}


Measured memory_bytes: 16048
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
int main() {
	int n, c;
	cin >> n >> c;
	vector<int> a(n), b(n);
	vector<vector<int> > dp;
	dp.assign(n + 2, vector<int> ());
	for(int i = 0; i <= n; ++i) {
		dp[i].assign(c + 1, 0);
	}
	vector<vector<int> > pre;
	pre.assign(405, vector<int> ());
	for(int i = 0; i <= 400; ++i) {
		pre[i].assign(405, 0);
	}
	for(int i = 0; i <= 400; ++i) {
		pre[i][0] = 1;
		for(int j = 1; j <= 400; ++j) {
			pre[i][j] = 1LL * pre[i][j - 1] * i % P;
		}
	}
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for(int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	dp[0][0] = 1;
	for(int i = 0; i < n; ++i) {
		vector<int> sum(c + 1, 0);
		for(int j = 0; j <= c; ++j) {
			for(int k = a[i]; k <= b[i]; ++k) {
				sum[j] = (sum[j] + pre[k][j]) % P;
			}
		}
		for(int j = 0; j <= c; ++j) {
			for(int k = 0; k + j <= c; ++k) {
				dp[i + 1][j + k] = (dp[i + 1][j + k] + 1LL * dp[i][j] * sum[k] % P) % P;
			}
		}
	}
	cout << dp[n][c] << '\n';
	return 0;
}


Measured memory_bytes: 1536
#include <vector>
#include<map>
#include<iostream>
#pragma GCC optimize("Ofast")

using namespace std;
using ll = long long;

const ll MOD = 1e9+7;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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


map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

void solve(long long N, std::vector<long long> A){
    map<ll, int> lcm;
    vector<map<int64_t, int>> www;
    for(int i = 0;i < N;i++){
        auto a = prime_factor(A[i]);
        www.push_back(a);
        for(auto b : a)lcm[b.first] = max(lcm[b.first], b.second);
    }
    ll ans = 0;
    for(int i = 0;i < N;i++){
        ans += modinv(A[i], MOD);
        ans %= MOD;
    }
    for(auto a : lcm){
        ans *= modpow(a.first, a.second, MOD);
        ans %= MOD;
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3896
#include"bits/stdc++.h"

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int>x(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans += min(x[i], K - x[i]);
	}
	cout << ans * 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{
	int a, b, c, i, j = 0;
	
	scanf( "%d %d %d", &a, &b, &c );
	
	for( i = a; i <= b; i++ ){
		if( c % i == 0 ){
			j++;
		}
	}
	
	printf( "%d\n", j );
	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int A, B, C, D, E, F;
	cin >> A >> B >> C >> D >> E >> F;

	int m1 = 0, m2 = 0;
	float maxD = 0.f;
	for (size_t i = 0; 100*A*i <= F; i++)
	{
		int mA = 100 * A*i;
		for (size_t j = 0; mA+100*B*j <= F; j++)
		{
			int mB = 100 * B*j;
			for (size_t k = 0; mA+mB+C*k <= F; k++)
			{
				int mC = C*k;
				for (size_t l = 0; mA+mB+mC+D*l <= F; l++)
				{
					int mD = D*l;
					if ((mA + mB)*E / 100 < mD + mC) {
						break;
					}
					float d = (float)(mD + mC) / (float)(mA + mB + mC + mD);
					if (d > maxD) {
						m1 = mA + mB + mC + mD;
						m2 = mC + mD;
						maxD = d;
					}
				}

			}
		}

	}
	if (m1 == 0) {
		m1 = 100 * A;
	}
	cout << m1 << " " << m2 << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

import queue
MOD = 10**9+7

def P(n, m, MOD=10**9+7):
    res = 1
    for i in range(m):
        res *= n - i
        res %= MOD
    return res

r = 0
dp = [1]*N

q = queue.Queue()
q.put((r, -1))
while not q.empty():
    v, p = q.get()
    if v == r: dp[v] = P(K-1, len(G[v]), MOD)
    elif len(G[v]) > 1: dp[v] = P(K-2, len(G[v])-1, MOD)
    for c in G[v]:
        if c == p: continue
        q.put((c, v))

ans = K
for n in dp:
    ans *= n
    ans %= MOD

print(ans)

Measured memory_bytes: 98632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <sstream>
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const ll maxn = 1000005;
const double pi = acos(-1.0);

int r,d,x[maxn];

int main()
{
    while(cin >> r >> d >> x[0])
    {
        for(int i = 1; i <= 10; i ++)
        {
            x[i] = x[i - 1] * r - d;
            cout << x[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int r , g , b, n ;
    cin >> r >> g >> b >> n ;
    
    int ans =  0 ;
    for(int i = 0 ; i < 3001 ; i++){
        for(int j = 0 ; j < 3001 ; j ++ ){
           if((n - r *i - g * j) % b == 0 &&(n - r *i - g * j) >= 0 ){
               ans ++ ;
           }
        }
    }

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

Measured memory_bytes: 256
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix


def idx(node, silver):
    silver = min(silver, SILVER_MAX)
    return node * (SILVER_MAX + 1) + silver


n, m, s = map(int, input().split())
uvab = [list(map(int, input().split())) for _ in range(m)]
cd = [list(map(int, input().split())) for _ in range(n)]

A_MAX = 50
SILVER_MAX = A_MAX * (n - 1)
N = (SILVER_MAX + 1) * n

U = []
V = []
C = []

# go through the road
for u, v, a, b in uvab:
    u -= 1
    v -= 1
    for silver in range(SILVER_MAX + 1):
        U.append(idx(u, silver + a))
        V.append(idx(v, silver))
        C.append(b)

        U.append(idx(v, silver + a))
        V.append(idx(u, silver))
        C.append(b)

# exchange gold to silver
for node, (c, d) in enumerate(cd):
    for silver in range(SILVER_MAX + 1):
        U.append(idx(node, silver))
        V.append(idx(node, silver + c))
        C.append(d)

# throw away silver
for node in range(n):
    for silver in range(SILVER_MAX):
        U.append(idx(node, silver + 1))
        V.append(idx(node, silver))
        C.append(0)

g = csr_matrix((C, (U, V)), shape=(N, N))
start = idx(0, s)
dist = dijkstra(g, indices=start).astype(int)
ans = dist[idx(1, 0)::SILVER_MAX+1]
print(*ans, sep="\n")


Measured memory_bytes: 128152
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

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

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

const int Maxn = 100010;
const int MOD = (int) 1e9 + 7;

int a[Maxn];
int dp[Maxn][13];

int n;

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

    string s;
    cin >> s;
    n = (int) s.size();
    for (int i = 0; i < n; ++i) {
        if (s[i] == '?') a[i] = -1;
        else a[i] = s[i] - '0';
    }

    dp[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 13; ++j) {
            if (a[i] != -1) {
                (dp[i + 1][(10 * j + a[i]) % 13] += dp[i][j]) %= MOD;
            } else {
                for (int k = 0; k < 10; ++k) {
                    (dp[i + 1][(10 * j + k) % 13] += dp[i][j]) %= MOD;
                }
            }
        }
    }

    cout << dp[n][5] << endl;
}

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

#define int long long

typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N,D;
string S;
string T;
signed main(){
    cin>>N>>S>>D;
    T=S;
    int cnt=0;
    for(int i=0;i<T.size()&&cnt<D;i++){
        if(S[i]=='0'){
            cnt++;
            T[i]='1';
        }
    }

    for(int i=T.size()-1;i>=0&&cnt<D;i--){
        if(S[i]=='1'){
            T[i]='0';
            cnt++;
        }
    }

    cout<<T<<endl;
    return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define inc(a) scanf("%c", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int main(void){
    ll W, H, N, x, y, a;
    in3(W, H, N);
    ll top=H, bottom=0, left=0, right=W;
    rep(i, N){
        in3(x, y, a);
        if(a==1) chmax(left, x);
        else if(a==2) chmin(right, x);
        else if(a==3) chmax(bottom, y);
        else chmin(top, y);
    }
    if(right<=left || top<=bottom) puts("0");
    else put((top-bottom)*(right-left));
    return 0;
}


Measured memory_bytes: 128
import random
def is_prime(q, k=5):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q & 1 == 0: return False
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1
    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True

q = int(input())
l, r = [0]*q, [0]*q
for i in range(q):
    il, ir = map(int, input().split())
    l[i], r[i] = il, ir

cnt = [0] * (10**5+1)
cnt[0], cnt[1], cnt[2] = 0, 0, 0
for i in range(3, 10**5+1):
    if i % 2 == 0:
        cnt[i] = cnt[i-1]
    else:
        if is_prime(i):
            if is_prime((i+1)//2):
                cnt[i] = cnt[i-1] + 1
            else:
                cnt[i] = cnt[i-1]
        else:
            cnt[i] = cnt[i-1]

for i in range(q):
    print(cnt[r[i]] - cnt[l[i]-1])


Measured memory_bytes: 73176
n, k = map(int, input().split())
s_list = input()

#r=lかつr+1=l-1かつr!=r+1となるようなr,lを選ぶと+2点操作になる.
# また、r=n-1かつl!=l-1あるいはl=0かつr!=r+1となるようなr,lを選ぶと+2点操作になる.
#それ以外の場合は必ず0点以下となる.
# つまり、l!=l-1かつl=R,l!=l-1かつl=L,r!=r+1かつr=R,r!=r+1かつr=Lの数をそれぞれ数え、いい感じにマッチングすれば答えが出る.
mismatch_count = {"R":[0, 0], "L":[0, 0]}
ans = 0
for i in range(n):
    if(i < n-1):
        if(s_list[i] != s_list[i+1]):
            mismatch_count[s_list[i]][1] += 1
        elif(s_list[i] == "R"):
            ans += 1
    if(i > 0):
        if(s_list[i] != s_list[i-1]):
            mismatch_count[s_list[i]][0] += 1
        elif(s_list[i] == "L"):
            ans += 1
            
plus_r = min(mismatch_count["R"])
plus_l = min(mismatch_count["L"])
left_r = max(mismatch_count["R"]) - plus_r
left_l = max(mismatch_count["L"]) - plus_l
if(k >= plus_r):
    ans += plus_r * 2
    k -= plus_r
    plus_l -= plus_r
elif(plus_r > 0):
    ans += k * 2
    k = 0
if(k >= plus_l):
    ans += plus_l * 2
    k -= plus_l
elif(plus_l > 0):
    ans += k * 2
    k = 0
if(k >= left_r):
    ans += left_r
    k -= left_r
    left_l -= left_r
elif(left_r > 0):
    ans += k
    k = 0
if(k >= left_l):
    ans += left_l
    k -= left_l
elif(left_l > 0):
    ans += k
    k = 0

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 3e3+5, inf = 1e9+7;
int n, k, i, j;
int A[N], dp[N][N], dp2[N][N];
string s;

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    cin>>n;
    cin>>s;
    rep(i, 1, n+1) dp2[n][i] = 1;
    for(int idx=n-1; idx>=1; idx--){
        for(int ls=1; ls<=n-idx+1; ls++) {
            int rm = n-idx+1, mr = rm - ls;
            if(s[idx-1]=='<')
                dp[idx][ls] = dp2[idx+1][rm] - dp2[idx+1][ls-1];
            else
                dp[idx][ls] = dp2[idx+1][ls-1];
            dp[idx][ls] = (dp[idx][ls]%inf+inf)%inf;
        }
        for(int ls = 1; ls<=n+1; ls++)
            dp2[idx][ls] = (dp2[idx][ls-1]+dp[idx][ls])%inf;            
    }
    cout<<dp2[1][n];
}

Measured memory_bytes: 139776
import java.util.*;

public class Main{

	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String s = in.next();
		char[] a = s.toCharArray();
		char[] b = new char[26];
		if(s.length() == 26){
			for(int i=25; i>0; i--){
				if(a[i-1] < a[i]){
					for(int j=25; j>0; j--) {
						if(a[j] > a[i-1]) {
							a[i-1] = a[j];
							String res = "";
							for(int k=0; k<i; k++) {
								res += a[k];
							}
							System.out.println(res);
							return;
						}
					}
				}
			}
			System.out.println(-1);
		} else{
			for(int i=0; i<s.length(); i++){
				b[a[i]-'a'] = a[i];
			}
			for(int i=0; i<26; i++){
				if(b[i] == 0){
					b[i] = (char) ('a' + i);
					System.out.println(s+b[i]);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 22740
fn read() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_string()
}

fn main() {
    read();
    let w: Vec<i16> = read()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();

    let mut s: i16 = 0;
    let mut t: i16 = w.iter().sum();
    let mut r: i16 = t;

    for &e in w.iter() {
        s += e;
        t -= e;
        let d = (s - t).abs();
        if d <= r {
            r = d;
        } else {
            break;
        }
    }

    println!("{}", r);
}


Measured memory_bytes: 4352
#include<iostream>
#include<set>

using namespace std;

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

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

	int g = 0, mx = 0;
	for(int i = 0; i < n; ++i){
		int a;
		cin >>a;
		g = gcd(g, a);
		mx = max(mx, a);
	}
	
	if(k % g == 0 && k <= mx){
		cout <<"POSSIBLE\n";
	}
	else{
		cout <<"IMPOSSIBLE\n";
	}

	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        mut aa: [usize; n]
    };
    aa.sort();
    aa.reverse();

    let mut pre_a = 0;
    let mut count = 0;
    let mut pairs = vec![];
    for a in aa {
        if a == pre_a {
            count += 1;
            if count == 2 {
                pairs.push(a);
                if pairs.len() == 2 {
                    println!("{}", pairs[0] * pairs[1]);
                    return;
                }
                count = 0;
            }
        } else {
            pre_a = a;
            count = 1;
        }
    }
    println!("0");
}


Measured memory_bytes: 4284
#from pprint import pprint
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。

# = map(int,input().split())

# = list(map(int,input().split()))

# = [list(map(int,input().split())) for _ in range(XXXX)]

n = str(input())



if n[-1] == "3":
    print("bon")
    exit()
elif n[-1] == "0" or n[-1] == "1" or n[-1] == "6" or n[-1] == "8":
    print("pon")
    exit()
else:
    print("hon")
    exit()
    


Measured memory_bytes: 61768
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; cin >> N;
  vector<ll> sum(N+1, 0);
  for (int i = 1; i <= N; ++i) {
    int w; cin >> w;
    sum[i] = sum[i-1] + w;
  }

  ll ans = 1<<30;
  for (int t = 1; t < N; ++t) {
    ll s1 = sum[t], s2 = sum[N]-sum[t];
    ans = min(ans, abs(s1-s2));
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vvi vector<vector<int>> 

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



    int n , k ;
    cin >> n >> k;

    vi a(n);
    for(int i = 0 ; i < n ; ++i) cin >> a[i];
    
    vi dp(k+1,0);
    for(int i = 0 ; i <= k ; ++i){
        for(auto x : a){
            if(i >= x)
                if(!dp[i-x]) dp[i] = 1; 
        }
    }

    if(dp[k])
        cout << "First" << '\n';
    else 
        cout << "Second" << '\n';




    return 0;
}

Measured memory_bytes: 640