akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int maxn = 1e5 + 5;
int n, X;
int b[maxn], l[maxn], u[maxn];
lli empt[maxn], full[maxn], delta[maxn];

int order[maxn];

bool cmp(int i, int j)
{
    return delta[i] > delta[j];
}

void ReadInput()
{
    cin >> n >> X;
    for(int i = 0; i < n; ++i)
    {
        cin >> b[i] >> l[i] >> u[i];
        empt[i] = -1LL * b[i] * l[i];
        full[i] = 1LL * (X - b[i]) * u[i];
        delta[i] = full[i] - empt[i];
    }
    for(int i = 0; i < n; ++i) order[i] = i;
    sort(order, order + n, cmp);
}

lli score(int i, lli k)
{
    if(k >= b[i]) return 1LL * b[i] * l[i] + (k - b[i]) * u[i];
    return k * l[i];
}

bool Check(lli k)
{
    int q = k / X, r = k % X;
    lli tot = 0;
    for(int i = 0; i < n; ++i)
        tot += empt[i];
    for(int i = 0; i < q; ++i)
        tot += delta[order[i]];
    for(int i = 0; i < n; ++i)
    {
        lli ntot = tot;
        if(i >= q)
            ntot += score(order[i], r);
        else
        {
            ntot -= delta[order[i]];
            ntot += delta[order[q]];
            ntot += score(order[i], r);
        }
        if(ntot >= 0) return true;
    }
    return false;
}

void Solve()
{
    lli low = 0, high = 1LL * X * n;
    while(low <= high)
    {
        lli mid = (low + high) / 2;
        if(Check(mid)) high = mid - 1;
        else low = mid + 1;
    }
    cout << low << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


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

using namespace std;

#define REP(var, n)  for (int var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<int>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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

auto solve() {
    string S;
    cin >> S;
    int n = S.size();
    int z = 0;
    for (auto &&c:S) if (c == '0') z++;
    int o = n - z;
    return min(z, o) * 2;
}


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

//    cout << (solve() ? "Heisei" : "TBD") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
    cout << solve() << endl;
//    solve();

    return 0;
}

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

int main()
{	
	string S;
	cin >> S;
	int flage = 0;
	for(int i = 0;i<S.size();i+=2){
		if(S[i]=='L'){
			flage =1;
			break;
		}
		else if(S[i+1]=='R'){
			flage =1;
			break;
		}
	}
	if(flage==0)cout << "Yes";
	else cout <<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll h1,m1,h2,m2,l;cin>>h1>>m1>>h2>>m2>>l;
    ll time=h2*60+m2-h1*60-m1;
    cout<<time-l<<"\n";
}


Measured memory_bytes: 3632
n, m = map(int, input().split())
e = []
for i in range(m):
    e.append(list(map(int, input().split())))

e.sort(key=lambda x:x[1])
ret = 0


l = 0
for i in range(m):
    if e[i][0] < l:
        continue
    else:
        l = e[i][1]
        ret += 1
    
print(ret)


Measured memory_bytes: 64828
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

typedef long long ll;

int N, K;

int main(void) {
    scanf("%d %d", &N, &K);
    
    if (N % K == 0) puts("0");
    else puts("1");

	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0

for l in range(min(N, K) + 1): #左側から取る個数
    left = N - l #筒に残っている数
    for r in range(min(left, K - l) + 1): #右側から取る個数
        k = K - l - r #捨てる個数
        tmp = V[:l] + V[N - r:]
        tmp.sort(reverse = False)
        t = sum(tmp)
        for i in range(min(k, l + r)): #最大捨てることができる個数
            if tmp[i] < 0:
                t -= tmp[i]
            else:
                break
        
        ans = max(ans, t)

print (ans)

Measured memory_bytes: 3064
#include <math.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main()
{
int n;
int T=0;
int H=0;
cin >> n;
for(int i=0;i<n;i++)
{
string Taro,Hanako;
cin >> Taro >> Hanako;
int mi=min(Taro.size(),Hanako.size());
for(int j=0;j<mi;j++)
{
if(Taro.at(j)>Hanako.at(j))
{
T+=3;
break;
}
else if(Taro.at(j)<Hanako.at(j))
{
H+=3;
break;
}
else
{
if(j==mi-1)
{
if(Taro.size()>Hanako.size())T+=3;
else if(Taro.size()<Hanako.size())H+=3;
else{H++;T++;}
}
}
}
}
cout << T << " " << H << endl;
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long va,vb,i,j,k,n,a[100001],b[100001],x;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    va=a[0];
    vb=b[0];
    for(i=1;i<n;i++){
        x=max(ceil((long double)va/a[i]),ceil((long double)vb/b[i]));
        
        va=a[i]*x;
        vb=b[i]*x;
        
    }
    cout<<va+vb;

}


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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define pi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
#define vl vector<ll>
#define vii vector<pair<int,int> >
#define vll vector<pair<long long,long long> >
#define pb push_back
#define mp make_pair3

const ll mod=1e9+7;
#define MAX 100000

template<typename T>
void max_self(T &a,T b){
    a = max(a,b);
}

template<typename T>
void min_self(T &a,T b){
    a = min(a,b);
}

ll binexpo(ll a,ll b,ll c){

    if(b==0) return 1;
    else if(b%2==0) return binexpo(((a%c)*(a%c))%c,b/2,c)%c;
    else return ((a%c)*(binexpo(((a%c)*(a%c))%c,b/2,c)%c))%c;
}

int main(){

    std::ios_base::sync_with_stdio(0);
    cin.tie(0);

    cout.setf(ios::fixed);
    cout<<setprecision(9);
    int n;
    cin>>n;

    double prob[n];
    FOR(i,0,n) cin>>prob[i];

    if(n == 1){
        cout<<prob[0];
        exit(0);
    }

    double dp[n+1][n+1];
    memset(dp,0.0,sizeof(dp));

    dp[1][0] = 1-prob[0];
    FOR(i,2,n+1) dp[i][0] = dp[i-1][0] * (1 - prob[i-1]);

    dp[1][1] = prob[0];

    FOR(i,2,n+1){
        FOR(j,1,n+1){
            if(j>i) break;
            dp[i][j] = dp[i-1][j-1]*(prob[i-1]) + dp[i-1][j]*(1 - prob[i-1]);
        }
    }

    double ans = 0.0;
    for(int i = (n/2)+1;i<=n;i++) ans+= dp[n][i];

    cout<<ans;

    return 0;
}

Measured memory_bytes: 70656
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

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

int main() {
  LL N, x; cin >> N >> x;
  vector<LL> a(N); cin >> a;

  LL cnt = 0;
  for (int i = 0; i < N - 1; ++i) {
    LL vi = a[i] + a[i + 1];
    if (vi > x) {
      cnt += vi - x;
      a[i + 1] -= vi - x;
      if (a[i + 1] < 0) a[i + 1] = 0;
    }
  }
  cout << cnt << endl;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    int cnt = 0;
    rep(i, n) rep(j, n) {
        rep(k, m) rep(l, m) {
            if (i+k >= n || j+l >= n) continue;
            if (a[i+k][j+l] == b[k][l]) {
                cnt++;
            }
        }
        if (cnt == m * m) {
            cout << "Yes" << endl;
            return 0;
        }
        cnt = 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int a,b;
  cin>>a>>b;

  cout<<((a<10 && b<10)? a*b:-1)<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define ggr getchar();getchar();return 0
using namespace std;
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a<=c&&c<=b)||(a>=c&&c>=b))puts("Yes");
	else puts("No");
	ggr;
}


Measured memory_bytes: 256
from collections import defaultdict

if __name__ == '__main__':
    n, k = [int(x) for x in input().split()]
    p = []
    p_dict = defaultdict(list)
    ans = 0
    stop = False
    for i in range(n):
        p.append(str(input()))
    for prob in p:
        p_dict[prob[0]].append(prob)
    while True:
        cnt = 0
        more_to_go = False
        sorted_dict = sorted(p_dict, key=lambda x: len(p_dict[x]), reverse=True)
        for key in sorted_dict:
            if p_dict[key]:
                p_dict[key].pop()
                cnt += 1
                if cnt == k:
                    ans += 1
                    more_to_go = True
                    break
        if not more_to_go:
            break
    print(ans)

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split(' ');
            int a = int.Parse(imp[0]);
            int b = int.Parse(imp[1]);
            int c = int.Parse(imp[2]);

            if(a+b==c)
            {
                Console.Write("Yes");
            }
            else if(a+c==b)
            {
                Console.Write("Yes");
            }
            else if(b+c==a)
            {
                Console.Write("Yes");
            }
            else
            {
                Console.Write("No");
            }
            System.Threading.Thread.Sleep(1000);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

int main(void){
	int i,n,j=0;
	int a[100],b[100]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		if(i>0)scanf(" ");
		scanf("%d",&a[i]);
	}
	for(j=0;j<n;j++){
		b[j]=a[(n-1)-j];
	}
	for(i=0;i<n;i++){
		printf("%d",b[i]);
		if(!(i==(n-1)))printf(" ");
	}
	printf("\n");
	return 0;
}


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

int main(){
    int H,W; cin>>H>>W;
    vector<string> a(H);
    vector<bool> row(H,false);
    vector<bool> col(W,false);
    for(int i=0;i<H;i++){
        cin>>a[i];
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(a[i][j]=='#'){
                row[i]=true;
                col[j]=true;
            }
        }
    }

    for(int i=0;i<H;i++){
        if(row[i]){
            for(int j=0;j<W;j++){
                if(col[j]){
                    cout<<a[i][j];
                }
            }
            cout<<endl;
        }
    }
}

Measured memory_bytes: 256
const main = (input: string) => {
    let [r, D, x] = input.trim().split(" ").map(str => parseInt(str))
    const OUTPUT_LINE = 10;
    let answer: string = "";

    for (let i = 0; i < OUTPUT_LINE; i++) {
        if (i !== OUTPUT_LINE - 1) {
            answer = `${answer}${r * x - D}\n`;
        } else {
            answer = `${answer}${r * x - D }`;
        }
        x = r * x - D
    }

    console.log(answer);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7628
inp = input()
n = int(inp)
inp = input()
split_input = inp.split()
numbers = []
for st in split_input:
    numbers.append(int(st))
right_pass = 10000000000
left_t = 0
right_t = len(numbers)
left_pass = 10000000000

while True:
    t = left_t + (right_t - left_t) // 2
    if t == left_t:
        left = 0
        for i in numbers[:t]:
            left += i
        right = 0
        for i in numbers[t:]:
            right += i
        print(abs(right-left))
        exit()
    left = 0
    for i in numbers[:t]:
        left += i
    right = 0
    for i in numbers[t:]:
        right += i
    if left > right:
        if t - 1 == left_t:
            print(min(left-right, left_pass))
            exit()
        right_t = t
        right_pass = left - right
    elif left < right:
        if t + 1 == right_t:
            print(min(right-left, right_pass))
            exit()
        left_t = t
        left_pass = right - left
    else:
        print(0)
        exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ARRAY_LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
using namespace std;
typedef  unsigned long long ull;
typedef  long long ll;

int main(void){
  ll h;
  ll w;
  cin >> h >> w;
  ll ans;
  if(h % 3 == 0 || w % 3==0){
    ans = 0;
  }
  else{
    ans = h * w + 1;
    ll sx,sy,sz,s;
    ll d,e;
    FOR(i,1,h){
      sx = i*w;
      e = h-i;
      s = e*w;
      sy = e*(w/2);
      sz = s - sy;
      d = max({sx,sy,sz}) - min({sx,sy,sz});
      ans = min(d,ans);
      if(e > 1){
        sy = (e/2)*w;
        sz = s - sy;
        d = max({sx,sy,sz}) - min({sx,sy,sz});
        ans = min(d,ans);
      }
    }

    swap(h,w);

    FOR(i,1,h){
      sx = i*w;
      e = h-i;
      s = e*w;
      sy = e*(w/2);
      sz = s - sy;
      d = max({sx,sy,sz}) - min({sx,sy,sz});
      ans = min(d,ans);

      if(e > 1){
        sy = (e/2)*w;
        sz = s - sy;
        d = max({sx,sy,sz}) - min({sx,sy,sz});
        ans = min(d,ans);

      }
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    long long n;
    scanf("%lli",&n);
    long long a[n];
    long long t[n];
    for (int i=0;i<n;i++) {
        t[i] = 0;
    }
    long long tmp;
    for (long long i=0;i<n;i++) {
        scanf("%lli",&a[i]);
        tmp = a[i];
        t[tmp-1] = i+1;
    }
    for(int i=0;i<n;i++) {
        printf("%lli ",t[i]);
    }
    return 0;
}

Measured memory_bytes: 3224
#include<stdio.h>

int n;
int a[60],next[60];

int main()
{
   while(scanf("%d",&n)!=EOF)
   {
	  if (n==0) break;
      for (int i=1;i<=n;i++)
		  scanf("%d",&a[i]);
	  for (int i=1;i<=n;i++)
	  {
		 int j;
		 for (j=i+1;j<=n;j++)
	     if (a[j]!=a[j-1]+1)
			 break;
		 next[i]=j-1;
	  }
	  int ca=0;
	  int i=1;
	  while(i<=n)
	  {
		 ca++;
		 if (ca!=1) printf(" ");
	     if (next[i]!=i)
		 printf("%d-%d",a[i],a[next[i]]);
		 else
			 printf("%d",a[i]);
		 i=next[i]+1;
	  }
	  printf("\n");
   }
   return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
template<class T>
void printvec(std::vector<T> vec){
  std::size_t n = vec.size();
  for(int i = 0; i<n - 1; ++i){
    std::cout << vec[i] << " ";
  }
  std::cout << vec[n - 1] << std::endl;
}

int main(int const argc, char const** argv){
  int n;
  std::cin >> n;
  std::vector<int> vec;
  for(int i = 0; i<n; ++i){
    int j;
    std::cin >> j;
    vec.push_back(j);
  }
  int count = 0;
  int flag = 1;

  for(int i = 0;i<n ; ++i){
    for(int j = i; j>0; --j){
      if(vec[j - 1]>vec[j]){
	std::swap(vec[j - 1], vec[j]);
	count++;
      }
    }
  }

  for(int j = n - 1; j != 0; j--){
    if(vec[j]<vec[j - 1]){
      std::swap(vec[j], vec[j - 1]);
      count++;
      flag = 1;
    }
  }
  
  printvec(vec);
  
  std::cout << count << std::endl;
  
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define dow(i,j,k) for (int i = j; i >= k; i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef pair<int, int> pi;
typedef long long ll;
int n;
int main() {
	scanf("%d", &n);
	if ((!(n & (n - 1)))) return puts("No"), 0;
	puts("Yes");
	int m = n;
	if (n % 2 == 0) m--;
	printf("%d %d\n", n + 1, 3);
	for (int i = 2; i < m; i += 2) {
		printf("%d %d\n", i, i + 1);
		printf("%d %d\n", i, 1);
		printf("%d %d\n", i + n + 1, i + n);
		printf("%d %d\n", i + n + 1, 1);
	}
	if (n % 2 == 0) {
		int x = n & -n;
		int y = n - x;
		printf("%d %d\n", n, x);
		printf("%d %d\n", y + n + 1, n * 2);
	}
	return 0;
}
		

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

int main(){
  string s;
  cin >> s;
  int k=1;
  if(s.at(2) != s.at(3)) k=-1;
  if(s.at(4) != s.at(5)) k=-1;
  
  if(k >0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
from itertools import count, repeat

h = int(input().split()[0])
a0 = repeat('.')
r0 = count()
for i in range(h):
  a = input()
  r = [i]
  for x, y, z, u in zip(a0, '.' + a, a, r0):
    r.append(min(u + (x + z == '.#'), r[-1] + (y + z == '.#')))
  a0 = a
  r0 = r[1:]
print(r[-1])


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(){
  int x, maxx = 0;
  int cnt[102];
  vector<int> v;

  memset(cnt, 0, sizeof(cnt));

  while(cin >> x){
    cnt[x]++;
    if(maxx < cnt[x]){
      maxx = cnt[x];
      v.clear();
      v.push_back(x);
    }
    else if(maxx == cnt[x]){
      v.push_back(x);
    }
  }

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

  for(int i = 0; i < v.size(); i++){
    cout << v[i] << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int n,m,x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    rep(i,n) {
        cin >> c[i];
        rep(j,m) {
            cin >> a[i][j];
        }
    }
    int money = INF;
    bool ok = false;
    rep(i,1<<n) {
        int tmp = 0;
        bool ok1 = true;
        vector<int> rikai(m,0);
        rep(j,n) {
            if (i>>j & 1) {
                tmp += c[j];
                rep(k,m) {
                    rikai[k] += a[j][k];
                }
            }
        }
        rep(k,m) {
            if (rikai[k] < x) {
                ok1 = false;
                break;
            }
        }
        if (ok1) {
            ok = true;
            chmin(money, tmp);
        }
    }
    if (!ok) {
        cout << -1 << endl;
    } else {
        cout << money << endl;
    }
}

Measured memory_bytes: 3596
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""
(N,M) = (int(i) for i in input().split(" "))
S = [[int(i) for i in input().split()]for m in range(M)]
L = [s[0] for s in S]
R = [s[1] for s in S]
print(min(R)-max(L)+1 if min(R)-max(L)+1>0 else 0)

Measured memory_bytes: 23680
#include<stdio.h>
int main(void){
    int c[26]={0};
    int i=0;
    char CC[1204]={'\0'};
    fread(CC,1,1200,stdin);
    while(CC[i]!='\0'){
        if(CC[i]>=65 && CC[i]<=90){
            c[CC[i]-65]++;
            i++;
        }else if(CC[i]>=97 && CC[i]<=122){
            c[CC[i]-97]++;
            i++;
        }else{
            i++;
            continue;
        }
    }
    for(int j=0;j<26;j++){
        printf("%c : %d\n",j+97,c[j]);
    }
    return 0;
}


Measured memory_bytes: 2056
N = int(input())
s = input()
ans1 = 0
ans2 = 0
DP = [0 for i in range(N)]
s = s[::-1]
if s[0] == ".":
    DP[0] = 1

for i in range(1, N):
    DP[i] = DP[i - 1]
    if s[i] == ".":
        DP[i] += 1

ans = N * 20
DP = DP[::-1]


DP2 = [0 for i in range(N)]
s = s[::-1]
if s[0] == "#":
    DP2[0] = 1

for i in range(1, N):
    DP2[i] = DP2[i - 1]
    if s[i] == "#":
        DP2[i] += 1

ans = DP[0]
for i in range(1, N):
    #print(ans, DP[i] + DP2[i - 1])
    ans = min(ans, DP[i] + DP2[i - 1])
ans = min(ans, DP2[N - 1])
print(ans)

Measured memory_bytes: 12880
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const n = +input[0];
const f = [];
for (let i = 0; i < n; i++) {
	f.push(Number.parseInt(input[i + 1].replace(/\s/g, ""), 2));
}
const p = [];
for (let i = 0; i < n; i++) {
	p.push(input[i + n + 1].split(" ").map((x: string): number => +x));
}

const bitCount = (i: number) => {
	i = i - ((i >>> 1) & 0x55555555);
	i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
	i = (i + (i >>> 4)) & 0x0f0f0f0f;
	i = i + (i >>> 8);
	i = i + (i >>> 16);
	return i & 0x3f;
};

let result = -Infinity;
for (let time = 1; time < 0b10000000000; time++) {
	let profit = 0;
	for (let i = 0; i < n; i++) {
		const ci = bitCount(f[i] & time);
		profit += p[i][ci];
	}
	if (profit > result) {
		result = profit;
	}
}

console.log(result);


Measured memory_bytes: 7628
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

using Graph = vector<vector<int>>;
vector<vector<int>> tsort(Graph &g) {
    int n = g.size(), k = 0;
    vector<int> indeg(n), que, nxt;
    for (int u = 0; u < n; u++) for (int v: g[u]) ++indeg[v];
    vector<vector<int>> dist(n);
    for (int v = 0; v < n; v++) if (indeg[v] == 0) que.emplace_back(v);
    while (!que.empty()) {
        for (int u: que) {
            dist[k].emplace_back(u);
            for (int v: g[u]) if (--indeg[v] == 0) nxt.emplace_back(v);
        }
        swap(que, nxt); nxt.clear(); k++;
    }
    if (*max_element(indeg.begin(), indeg.end()) != 0) return {};
    return dist.resize(k), dist;
}

int main() {
    int n; cin >> n;
    int sz = 0;
    map<pair<int, int>, int> idx;
    for (int u = 0; u < n; u++) {
        for (int v = u + 1; v < n; v++) idx[{u, v}] = idx[{v, u}] = sz++;
    }
    vector<vector<int>> a(n, vector<int>(n - 1));
    for (auto &ai: a) for (int &aij: ai) cin >> aij, aij--;
    Graph g(sz);
    for (int u = 0; u < n; u++) for (int i = 0; i < n - 2; i++) {
        g[idx[{u, a[u][i]}]].emplace_back(idx[{u, a[u][i + 1]}]);
    }
    auto res = tsort(g);
    if (res.empty()) {
        cout << -1 << endl;
    } else {
        cout << res.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 150528
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int M = in.nextInt();
		int K = in.nextInt();
		
		if(M==0) {
			if(K==0) System.out.println("0 0");
			else returnNone();
			return;
		}
		if(M==1) {
			if(K==0) System.out.println("0 1 1 0");
			else returnNone();
			return;
		}
		
		double max = Math.pow(2,M)-1;
		
		if(K>max) {
			returnNone();
			return;
		}
		StringBuilder sb = new StringBuilder();
		sb.append(K);
		for(int i=0;i<=max;i++) {
			if(i==K) continue;
			sb.append(" ");
			sb.append(i);
		}
		sb.append(" ");
		sb.append(K);
		for(int i=(int) max;i>=0;i--) {
			if(i==K) continue;
			sb.append(" ");
			sb.append(i);
		}
		System.out.println(sb.toString());
	}
	
	private void returnNone() {
		System.out.println("-1");
	}

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

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

int N,x,ans[300000]; bool v[300000];

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

    if (N==2){
        if (x==2) cout << "Yes\n 1\n2\n3\n";
        else cout << "No\n";
        return 0;
    }

    if (x==1 || x==2*N-1){ cout << "No\n"; return 0; }

    if (x==2 || x==2*N-2){
        if (x==2){
            ans[N]=x,ans[N+1]=x-1;
            ans[N+2]=x+1;
            ans[N-1]=x+2;
            v[x]=v[x-1]=v[x+1]=v[x+2]=1;
        }
        else{
            ans[N]=x,ans[N+1]=x+1;
            ans[N+2]=x-1;
            ans[N-1]=x-2;
            v[x]=v[x+1]=v[x-1]=v[x-2]=1;
        }
    }
    else{
        ans[N]=x,ans[N-1]=x-1,ans[N+1]=x+1;
        ans[N-2]=x+2,ans[N+2]=x-2;
        v[x]=v[x-1]=v[x+1]=v[x+2]=v[x-2]=1;
    }

    int i,t=1;
    cout << "Yes\n";
    for (i=1; i<=2*N-1; i++)
        if (ans[i]!=0) cout << ans[i] << "\n";
        else{
            while (v[t]) t++;
            cout << t << "\n";
            t++;
        }


    return 0;
}


Measured memory_bytes: 1536
n = int(input())						# 5
p =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

ans=0
for i in range(n-2):
	a = p[i]
	b = p[i+1]
	c = p[i+2]
	
	if (a<b)and(b<c): ans+=1
	if (a>b)and(b>c): ans+=1

print(ans)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){int N;cin>>N;vector<int>a(N);for(int i=0;i<N;i++)cin>>a.at(i);
           sort(a.begin(),a.end());int x=1;for(int i=1;i<N;i++)if(a.at(i)-a.at(i-1))x++;
           cout<<x<<endl;}


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

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	unsigned int n;
	cin >> n;
	string s;
	cin >> s;
	if (s.length() <= n)
		cout << s << endl;
	else
	{
		string k;
		k = s.substr(0, n);
		cout << k << "...\n";
	}



	return 0;
}

Measured memory_bytes: 3616
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        int a[n+1];
        loop(i,1,n) cin>>a[i];
        map<int,int> b;
        vector<int> c;
        int i=1;
        c.push_back(1);
        b[1]=0;
        int id = 0;
        while(1){
            if(b.find(a[i])==b.end()){
                c.push_back(a[i]);
                b[a[i]]=c.size()-1;
                i=a[i];
            }else{
                id = b[a[i]];
                break;
            }
        }
        if(k<=id){
            cout<<c[k]<<"\n";
        }else{
            k-=id;
            k = id+k%(c.size()-id);
            cout<<c[k]<<"\n";
        }
    }
    return 0;
}

Measured memory_bytes: 18600
s = input()
if s == "SSS":
    print("0")
elif s == "RSS" and "SRS" and "SSR":
    print("1")
elif s == "SRS":
    print("1")
elif s == "SSR":
    print("1")
elif s == "RSR":
    print("1")
elif s == "RRS":
    print("2")
elif s == "SRR":
    print("2")
elif s == "RRR":
    print("3")
else :
    print(" ")

Measured memory_bytes: 9012
implicit integer(a-z)
    character(3)::ans="No"
    
    read(*,*)n
    
    imax=n/4
    jmax=n/7
    
    do j=0,jmax
    	do i=0,imax
        	if(i*4+j*7.eq.n) ans="Yes"
        end do
    end do
    
    write(*,*)ans
end 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
		int a, b, c = 0, d = 0;
		for (int i = 0; i < 4; i++) {
			cin >> a;
			c = c + a;
		}
		for (int i = 0; i < 4; i++) {
			cin >> b;
			d = d + b;
		}
		if (c < d)
			cout << d << endl;
		else {
			cout << c << endl;
		}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<=n;i++)
typedef long long ll;
using namespace std;
int main()
{
   int N,x;
   cin >> N >> x;
   vector<int>a(N);
   rep(i,0,N){
       cin >> a[i];
   }
   ll ans = 0;
   rep(i,0,N){
       if(i==0){
           if(a[i]>x){
               ans+=a[i]-x;
               a[i]=x;
           }
       }
       else{
           if(a[i]+a[i-1]>x){
               ans+=a[i]+a[i-1]-x;
               a[i]=x-a[i-1];
           }
       }
   }

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

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

static uint64_t limit;
static uint64_t ans;

static void dfs(uint64_t n, uint64_t m)
{
  if (n > limit) return;
  if (m == 7) ans++;
  dfs(n * 10 + 3, m | 1);
  dfs(n * 10 + 5, m | 2);
  dfs(n * 10 + 7, m | 4);
}

int main()
{
  cin >> limit;
  dfs(0, 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=5e2+50;
const ll mod=1e9+7;
using namespace std;
int dx[]={-1,1,0,0},dy[]={0,0,-1,1},n,p[nmax*nmax],f[nmax][nmax],x,y,nx,ny,i,j,rs,vl;
bitset<nmax>a[nmax];
pair<int,int>pr[nmax*nmax];
queue<pair<int,int> >q;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n*n;i++)cin>>p[i];
	for(i=1;i<=n;i++)for(j=1;j<=n;j++)f[i][j]=min(min(i-1,j-1),min(n-i,n-j)),a[i][j]=1,pr[n*(i-1)+j]=mkp(i,j);
	for(i=1;i<=n*n;i++)
	{
		x=pr[p[i]].fr,y=pr[p[i]].sc;
		rs+=f[x][y];
		a[x][y]=0;
		q.push(mkp(x,y));
		while(!q.empty())
		{
			x=q.front().fr,y=q.front().sc;
			q.pop();
			vl=f[x][y]+a[x][y];
			for(j=0;j<4;j++)
			{
				nx=x+dx[j],ny=y+dy[j];
				if(nx<1 || nx>n || ny<1 || ny>n || f[nx][ny]<=vl)continue;
				q.push(mkp(nx,ny));
				f[nx][ny]=vl;
			}
		}
	}
	cout<<rs<<endl;
	return 0;
}


Measured memory_bytes: 7620
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a,b,c;
	cin >> a; cin >> b; cin >> c;
	abs(a-b)<abs(a-c)?cout << "A"<< endl: cout << "B" << endl;

	
}

Measured memory_bytes: 256
longs, x, y = map(int, input().split())
s_lst = [v for v in input()]

cnt = 0
b_cnt = 0
for i, s in enumerate(s_lst):
    if s == 'a' and cnt < x + y:
        s_lst[i] = 'Yes'
        cnt += 1

    elif s == 'b':
        b_cnt += 1
        if cnt < x + y and b_cnt <= y:
            s_lst[i] = 'Yes'
            cnt += 1
        else:
            s_lst[i] = 'No'
    else:
        s_lst[i] = 'No'
for v in s_lst:
    print(v)

Measured memory_bytes: 4696
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	int n, i;
	cin >> n >> i;
	cout << n+1-i <<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
for k in range(60):
  t=1<<k
  z=o=0
  for i in a:
    if i&t:o+=1
    else:z+=1
  ans=(ans+(z*o*t))%mod
print(ans)


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

using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<ll>;

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  ll n;
  cin >> n;
  cout << n * (n - 1) / 2 << "\n";
}


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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

bool ok(const vi& uses,int cap,double x)
{
	double cur=cap,a[3]={};
	rep(k,3){
		a[k]=cur;
		rep(i,uses.size()){
			cur-=uses[i];
			cur+=x;
			cur=min<double>(cur,cap);
			if(cur<0) return false;
		}
	}
	return abs(a[1]-a[2])<EPS;
}

int main()
{
	for(int n,cap;cin>>n>>cap && n|cap;){
		vi uses(86400);
		rep(i,n){
			int s,t,u; cin>>s>>t>>u;
			repi(j,s,t) uses[j]=u;
		}
		double lo=0,hi=1e6;
		rep(_,50){
			double mi=(lo+hi)/2;
			if(ok(uses,cap,mi))
				hi=mi;
			else
				lo=mi;
		}
		printf("%f\n",lo);
	}
}

Measured memory_bytes: 1544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,l[110],i,j,k;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> l[i];
  }
  int ans=0;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(k=j+1;k<n;k++){
        if(l[i]!=l[j] && l[j]!=l[k] && l[i]!=l[k] && l[i]<l[j]+l[k] && l[k]<l[j]+l[i] && l[j]<l[i]+l[k]){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3672
import java.util.*;
public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String sa = sc.next();
		String sb = sc.next();
		String scc = sc.next();
		int a=0,b=0,c=0,turn=0;
		for(;;) {
			if(turn==0) {
				if(sa.length()==a){
					System.out.println('A');
					break;
				}
				turn =sa.charAt(a)-'a';
				a++;
			}else if(turn==1) {
				if(sb.length()==b) {
					System.out.println('B');
					break;
				}
				turn =sb.charAt(b)-'a';
				b++;
			}else{
				if(scc.length()==c) {
					System.out.println('C');
					break;
				}
				turn = scc.charAt(c)-'a';
				c++;
			}
		}

	}

}

Measured memory_bytes: 21844
N, Ma, Mb = gets.chomp.split(" ").map(&:to_i)
a = []
b = []
c = []

N.times do
  abc = gets.chomp.split(" ").map(&:to_i)
  a << abc[0]
  b << abc[1]
  c << abc[2]
end

nmax = 40
abmax = 10
inf = c.max * N * 10

dp = Array.new(nmax+1){Array.new(nmax*abmax + 1){Array.new(nmax*abmax + 1, inf)}}
dp[0][0][0] = 0

(0...N).each do |i|
  (0..(nmax*abmax)).each do |ca|
    (0..(nmax*abmax)).each do |cb|
      next if dp[i][ca][cb] == inf
      dp[i+1][ca][cb] = [dp[i+1][ca][cb], dp[i][ca][cb]].min
      dp[i+1][ca+a[i]][cb+b[i]] = [dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb] + c[i]].min
    end
  end
end

ans = []
(1..(nmax*abmax)).each do |ca|
  (1..(nmax * abmax)).each do |cb|
    if ca*Mb == cb * Ma then
      ans << dp[N][ca][cb]
    end
  end
end

if ans.min == inf then
  puts -1
else
  puts ans.min
end


Measured memory_bytes: 54780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[m];
		int[] d = new int[m];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			b[i] = scan.nextInt();
		}
		for(i = 0; i < m; i++) {
			c[i] = scan.nextInt();
			d[i] = scan.nextInt();
		}
		for(i = 0; i < n; i++) {
			int x = a[i] - c[0];
			int y = b[i] - d[0];
			if(x < 0) {
				x = x * (-1);
			}
			if(y < 0) {
				y = y * (-1);
			}
			int min = x + y;
			int check = 1;
			for(int j = 1; j < m; j++) {
				x = a[i] - c[j];
				y = b[i] - d[j];
				if(x < 0) {
					x = x * (-1);
				}
				if(y < 0) {
					y = y * (-1);
				}
				int t = x + y;
				if(t < min) {
					min = t;
					check = j + 1;
				}
			}
			System.out.println(check);
		}
	}
}

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

using namespace std;

vector<vector<int>> G;
vector<int> memo;

int dp(int u) {
  if (memo[u] != -1) return memo[u];
  int res = 0;
  for (auto v : G[u]) {
    res = max(res, dp(v) + 1);
  }
  return memo[u] = res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  G.resize(N), memo.resize(N, -1);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].emplace_back(y);
  }
  int res = 0;
  for (int i = 0; i < N; i++) {
    res = max(res, dp(i));
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 8192
program prob4
    implicit none
    integer(8) :: N
    integer(8), allocatable :: A(:)
    integer(8) :: L
    integer(8) :: i, index, S, ans

    read(*,*) N
    allocate(A(N))
    read(*,*) A

    L = sum(A)

    S = 0
    do i = 1, N
        S = S + A(i)
        if(S > L/2) then
            index = i
            exit
        end if
    end do

    ans = min(2*S - L, L-2*S+2*A(index))
    write(*,*) ans
    deallocate(A)
    stop
contains
end program prob4

Measured memory_bytes: 4616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 10000000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;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())

// vector<vector<int>> data(3, vector<int>(4));

typedef pair<ll,ll> P;
#define MAX_V 200001
struct edge { ll to, cost; };
vector<edge> g[MAX_V];
ll d1[MAX_V], d2[MAX_V], d3[MAX_V];

ll r1 = -1, r2 = -1;

void dijkstra1(int s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d1, d1 + MAX_V, INF);
	d1[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d1[v] < p.first) continue;
		for (int i = 0; i < g[v].size(); i++) {
			edge e = g[v][i];
			if (d1[e.to] > d1[v] + e.cost) {
				d1[e.to] = d1[v] + e.cost;
				que.push(P(d1[e.to], e.to));
			}
		}
	}
}

void dijkstra2(int s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d2, d2 + MAX_V, INF);
	d2[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d2[v] < p.first) continue;
		for (int i = 0; i < g[v].size(); i++) {
			edge e = g[v][i];
			if (d2[e.to] > d2[v] + e.cost) {
				d2[e.to] = d2[v] + e.cost;
				que.push(P(d2[e.to], e.to));
			}
		}
	}
}

void dijkstra3(int s) {
	// greater<P>を指定することでfirstが小さい順に取り出せるようにする
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d3, d3 + MAX_V, INF);
	d3[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d3[v] < p.first) continue;
		for (int i = 0; i < g[v].size(); i++) {
			edge e = g[v][i];
			if (e.to == r2) continue;
			if (d3[e.to] > d3[v] + e.cost) {
				d3[e.to] = d3[v] + e.cost;
				que.push(P(d3[e.to], e.to));
			}
		}
	}
}



int main(){	
	long long U;
	long long N;
	long long V;
	scanf("%lld",&N);
	vector<long long> A((N-1)-1+1);
	vector<long long> B((N-1)-1+1);
	scanf("%lld",&U);
	scanf("%lld",&V);
	U--; V--;
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
		A[i]--; B[i]--;
		edge e1 = {B[i],1};
		g[A[i]].push_back(e1);
		edge e2 = {A[i],1};
		g[B[i]].push_back(e2);
	}
	dijkstra1(U);
	dijkstra2(V);
	

	rep(i, N) {
		if (d1[i] == (d1[V]-1)/2 && d2[i] == (d1[V]+2)/2) r1 = i;
	}
	rep(i, N) {
		if (d1[i] == (d1[V]+1)/2 && d2[i] == (d1[V])/2) r2 = i;
	}

	if (d1[V] == 1) {
		cout << "0" << endl;
		return 0;
	}

	if (d1[V] == 2) {
		cout << "1" << endl;
		return 0;
	}

	dijkstra3(r1);
	ll l = -1;
	rep(i, N) {
		if (d3[i] != INF) l = max(l, d3[i]);
	}
	if (d1[V]%2 == 1) cout << (d1[V]-1)/2+l << endl; else cout << (d1[V]-1)/2+l+1 << endl;
	return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dp[10001];

void solve() {
  int N, K; cin >> N >> K;
  string S; cin >> S;
  int ans = 0;
  REP1(i, N-1) { // num of happiness
    // if ((S[i]=='L' and i-1>0 and S[i-1]==S[i]) or (S[i]=='R' and i+1<N and S[i]==S[i+1])) ans++;
    if (S[i-1]==S[i]) ans++;
  }
  int ops = 0;
  int memo = -1;
  REP1(i, N-1) {
    if (ops>=K) break;
    if (S[i-1]!=S[i]) 
    { 
      if (memo == -1) memo = i;
      else
      {
        ans+=2; ops++;
        memo = -1;
      }
    }
  }
  if (memo != -1 and ops<K) ans++;
  cout << ans << endl;

}

int main(int argc, char const *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  solve();
  return 0;
}


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


#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define piii pair<int,pii>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repc(i,a,n) for(int i=a;i<n;++i)
#define  repd(i,a,n) for(int i=a;i>n;--i)

using namespace std;
using ll = long long;
const ll N = 3*1e5 +5 ;
const ll mod = 1e9+7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;

typedef vector<int> vi;


void solve(){
	ll x;
	cin>>x;
	ll ans = x/500 * 1000 ;
	ans += ((x%500)/5)*5;
	cout<<ans;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output1.txt", "w", stdout);
	//#endif
	solve(); 
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli N,A,B,C,D,E,F,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  lli d[4]={-1,1,N,0-N};
  Vec(P,lli,N*N,0);
  Vec(G,lli,N*N,0);
  Vec(Fl,bool,N*N,1);
  rep(i,0,N*N)cin >> P[i];
  Vec(dist,lli,N*N,0);
  rep(i,0,N*N){
    A=i%N;
    B=i/N;
    dist[i]=min(min(A,N-A-1),min(B,N-B-1));
  }
  rep(i,0,N*N){
    sum+=dist[P[i]-1];
    queue<lli>que;
    que.push(P[i]-1);
    Fl[P[i]-1]=0;
    while(!que.empty()){
      auto v=que.front();que.pop();
      rep(j,0,4){
        auto nv=v+d[j];
        if(0>nv||nv>=N*N)continue;
        if(dist[nv]<=dist[v]+Fl[v])continue;
        dist[nv]=dist[v]+Fl[v];
        que.push(nv);
      }
    }
  }
  Out(sum);
}


Measured memory_bytes: 8936
#include <iostream>
#include<iomanip>
#include<algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

double x,y;

int main(){
	while(cin>>x>>y){
		if(x<35.5&&y<71) cout<<"AAA"<<endl;
		else{
			if(x<37.5&&y<77) cout<<"AA"<<endl;
			else{
				if(x<40&&y<83) cout<<"A"<<endl;
				else{
					if(x<43&&y<89) cout<<"B"<<endl;
					else{
						if(x<50&&y<105) cout<<"C"<<endl;
						else{
							if(x<55&&y<116) cout<<"D"<<endl;
							else{
								if(x<70&&y<148) cout<<"E"<<endl;
								else cout<<"NA"<<endl;
							}
						}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 1220