akhauriyash/Code-Regression huggingface dataset:
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
void no() {
    cout<<-1<<endl;
    exit(0);
}
int main() {
    cout.precision(15);
    cout << fixed;
    ll N;
    cin >> N;
    vector<ll> A(N+1);
    REP(i,N+1)
        cin>>A[i];
    if (A[0]>0) {
        if (A[0]==1 && N==0) {
            cout<<1<<endl;
            exit(0);
        }else {
            no();
        }
    }
    if (N==0) {
        if (A[0]!=1){
            no();
        }else{
            cout<<1<<endl;
            exit(0);
        }
    }

    ll rest=0;
    REP(i,N+1)
        rest+=A[i];
    ll ans=1;
    ll free=1;
    for(int i=1;i<N+1;++i) {
        ll nf=free*2-A[i];
        rest-=A[i];
        if (nf<0)no();
        free=min(nf,rest);
        ans+=free;
        ans+=A[i];
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4252
#include <iostream>
using namespace std;
int main()
{
  int a,b;
  char op;
  while(1)
  {
    cin>>a>>op>>b;
    if(op=='?')
      break;
    else
      switch(op)
    {
      case '+':
        cout<<a+b;
        break;
      case '-':
        cout<<a-b;
        break;
      case '*':
        cout<<a*b;
        break;
      case '/':
        cout<<a/b;
        break;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[100];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 1; i < n - 1; i++) {
		int b[3];
		b[0] = a[i - 1];
		b[1] = a[i];
		b[2] = a[i + 1];
		sort(b, b + 3);
		if (a[i] == b[1]) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s; int k;
    cin >> s >> k;
    for (int i = 0; i < sz(s) && k > 0; i++) {
        if (s[i] == 'a') continue;
        int diff = 'z' - s[i] + 1;
        if (diff <= k) {
            s[i] = 'a';
            k -= diff;
        }
    }
    k %= 26;
    char ch = s[sz(s) - 1];
    ch = 'a' + (ch - 'a' + k) % 26;
    s[sz(s) - 1] = ch;
    cout << s << "\n";
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>

using namespace std;
using ll = long long;
using ld = long double;

namespace NyaGadget
{
	struct NyaStruct {
		ll times = 0;
		ll v = 0;
	};

	auto NyaSort = [](const NyaStruct& l, const NyaStruct& r)
	{	// 降順は演算子>, 昇順は演算子<, if順の優先でソートされる
		return l.v > r.v;
	};
}

#define all(collection) (collection).begin(), (collection).end()              // begin to end
#define divc(a, b) ceil((ld) a / (ld) b);                                     // div ceiling
#define rep(i, begin, end) for (ll i = begin; i < end; i++)                   // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)                  // repeat reverse
#define size(collection) ((ll) (collection).size())                           // collection size
/********** for each macro **********/
#define fori(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#define each(i, e, v) fori(i, auto& e: v)
#define forir(i, ...) if(ll i = size(v)) for(__VA_ARGS__) if(i--, true)
#define eachr(i, e, v) forir(i, auto& e: boost::adaptors::reverse(v))

using namespace NyaGadget;

int main(void)
{
	ll N, M; cin >> N >> M;

	vector<ll> A(N);
	each(i, e, A)
		cin >> e;

	vector<NyaStruct> B(M);
	each(i, e, B)
		cin >> e.times >> e.v;
	sort(all(A));
	sort(all(B), NyaSort);

	vector<ll> change;
	[&]
	{
		each(i, e, B)
		{
			rep(j, 0, e.times)
			{
				change.push_back(e.v);
				if (size(change) == N) return;
			}
		}
	}();

	each(i, e, change)
		if (A[i] < e) A[i] = e;

	cout << accumulate(all(A), 0LL);
	return 0;
}


Measured memory_bytes: 3704
double x[100],y[100],t,u,a,b,s;n,i,j,k,c;main(m){for(;scanf("%d",&n),i=n;printf("%d\n",m)){for(m=1;i--;scanf("%lf,%lf",x+i,y+i));for(i=n;j=--i;)for(;j--;)if(s=(u=acos(hypot(x[j]-x[i],y[j]-y[i])/2))<9)for(t=atan2(y[j]-y[i],x[j]-x[i]);c=0,s+3;s-=2)for(a=x[i]+cos(t+s*u),b=y[i]+sin(t+s*u),k=n;k--;)hypot(a-x[k],b-y[k])<1.1&&++c>m?m=c:0;}}

Measured memory_bytes: 0
#include<iostream>
#include<string>
using namespace std;
int h,w,k, res;
char c[10][10];
int main(){
    cin >> h >> w >> k;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)cin >> c[i][j];
    }
    res = 0;
    for(int maskr = 0;maskr < (1<<h);maskr++){
        for(int maskc=0;maskc<(1<<w);maskc++){
            int black = 0;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(((maskr >> i)&1)==0 && ((maskc >>j)&1) == 0 && (c[i][j] == '#'))black++;
                }
            }
            if(black == k)res++;
        }
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 3720
def solve(string):
    n, *fp = map(int, string.split())
    f = "".join(map(str, fp[:10 * n]))
    p = fp[10 * n:]
    int_f = [int(f[10 * i:10 * (i + 1)], 2) for i in range(n)]
    return str(
        max(
            sum([p[11 * i + bin(o & _f).count("1")]
                 for i, _f in enumerate(int_f)])
            for o in range(1, 2**10)))


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(2 * n)])))


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

int main() {
	int n,x,k;
	cin>>n>>k;
	vector<int>v;
	for(int i=0;i<n;i++){
	    cin>>x;
	    v.push_back(x);
	}
	vector<int>result(n,INT_MAX);
	result[0]=0;
	for(int i=0;i<n;i++){
	    for(int j=i+1;j<=i+k;j++){
                if(j<n){
	            result[j]=min(result[j],abs(v[i]-v[j])+result[i]);}
	    }
	}
// 	for(auto it=result.begin();it!=result.end();it++){cout<<*it<<endl;}
	cout<<*(result.end()-1);
	
	return 0;
}







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

int main()
{
int i;
int N;
char S[ 200 ];
char C;
int iL;
int iR;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> S;

	iL = 0;
	iR = 0;
	i = 0;
	while( ( C = S[ i ] ) != '\0' )
	{
		if( C == ')' )
		{
			if( iL > 0 )	iL--;
			else			iR++;
		}
		else
			iL++;

		i++;
	}

	cout << string( iR, '(' );
	cout << S;
	cout << string( iL, ')' );
	cout << endl;

	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
void nckinit(ll n,ll md){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=md;
  }
  gya[n]=gyaku(kai[n],md);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=md;
  }
  gya[0]=1;
}
ll nck(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  ret*=gya[k];
  ret%=md;
  return ret;
}
ll npk(ll n,ll k,ll md){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=md;
  return ret;
}
bool f(string s){
    string t=s;
    reverse(t.begin(),t.end());
    rep(i,0,s.size()){
        if(s[i]!=t[i])return false;
        
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    double l;cin>>l;
    l/=3.0;
    l=l*l*l;
    cout<<fixed<<setprecision(12)<<l<<endl;
    
}







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

#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int

using namespace std;

inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

int gcd(int x, int y){
	while (y){
		x %= y;
		swap(x, y);
	}
	return x;
}

const int mod = 1000000007;

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

int main(){

	long long ans = 0;
	int n = nxt();
	int cur = 0;
	for (int i = 0; i < n; i++){
		int x = nxt();
		ans += x;
		if (x == 0){
			ans -= cur;
			cur = 0;
		}
		else
			cur ^= (x % 2);
	}

	ans -= cur;

	cout << ans / 2 << "\n";

	return 0;
}


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

using namespace std;

int main()
{
    int n,m;
    set <int> a,b;
    cin>>n;
    while(n--)
    {
        int x;
        cin>>x;
        a.insert(x);
    }
    cin>>m;
    while(m--)
    {
        int x;
        cin>>x;
        b.insert(x);
    }
    vector <int> c;
    set_intersection(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
    for(int i=0;i<c.size();i++)
    {
        cout<<c[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 21956
a,b = gets.split(" ").map(&:to_i)
a = a-1
t = 0

if a % 2 == 0
  if (a/2) % 2 == 0
    t = 0
  else
    t = 1
  end
  a = a ^ t
else
  if ((a+1)/2) % 2 == 0
    a = 0
  else
    a = 1
  end
end

if b % 2 == 0
  if (b/2) % 2 == 0
    t = 0
  else
    t = 1
  end
  b = b ^ t
else
  if ((b+1)/2) % 2 == 0
    b = 0
  else
    b = 1
  end
end

ans = a ^ b

puts ans




Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
  static void Main(string[] args)
  {
        long[] arr1 = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        long n = arr1[0];
        long k = arr1[1];
        long[] arr = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        long start = 1;
        long ansInd = 0;
        long[] arrC = new long[n];
        arrC = arrC.Select(a => a = -1).ToArray();
        arrC[start - 1] = ansInd;
        long count = 1;

        while (count <= k)
        {
            ansInd++;
            start = arr[start - 1];
            count++;
            if(arrC[start - 1] < 0)arrC[start - 1] = ansInd;
            else
            {
                long befInd = arrC[start - 1];
                long target = befInd + (k - befInd) % (ansInd - befInd);
                start = Array.IndexOf(arrC, target) + 1;
                break;
            }
        }
        Console.WriteLine(start);
  }
        

}



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

int A, B, X;

int main() {
    cin >> A >> B >> X;

    if (A > X) cout << "NO" << endl;
    else if (A+B < X) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main(){
    int L;
    int R;
    int d;
    cin >> L >> R >> d;

    int cnt = 0;
    for(int i = L; i <= R; i++){
        if(i % d == 0){
            cnt++;
        }
    }

    cout << cnt << endl;

}

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

int main() {
  int a,b,c;
  string ans;

  cin >> a >> b >> c;

  //22以上かで場合分け
  if (22 <= a + b + c) {
    ans = "bust";
  }
  else {
    ans = "win";
  }

  cout << ans << endl;
}

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

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

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

    ll k[n];
    ll mod = 10e8 + 7;
    for(int i = 0; i < n; i++){
        k[i] = sum;
        k[i] %= mod;
        sum -= a[i];
    }

    ll ans = 0;
    
    for(int i = 0; i < n - 1; i++){
        ans += a[i] * k[i + 1];
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6764
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  vector<string> vec(n);
  rep(i,n) cin >> vec[i];
  
  vector<ll> march(5,0);
  
  rep(i,n){
    if(vec[i][0] == 'M') march[0]++;
    if(vec[i][0] == 'A') march[1]++;
    if(vec[i][0] == 'R') march[2]++;
    if(vec[i][0] == 'C') march[3]++;
    if(vec[i][0] == 'H') march[4]++;
  }
  
  ll ans = 0;
  ans += march[0] * march[1] * march[2];
  ans += march[0] * march[1] * march[3];
  ans += march[0] * march[2] * march[3];
  ans += march[1] * march[2] * march[3];
  ans += march[0] * march[1] * march[4];
  ans += march[0] * march[2] * march[4];
  ans += march[1] * march[2] * march[4];
  ans += march[0] * march[3] * march[4];
  ans += march[1] * march[3] * march[4];
  ans += march[2] * march[3] * march[4];
  
  cout << ans;

  return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime> 

using namespace std;

int main(void){
	string str;
	while(getline(cin, str)){
		for(int j=0;j<26;j++){
			for(int i=0;i<str.size();i++){
				if(str[i]>='a' && str[i]<='z'){
					str[i]=(str[i]=='z')? 'a' : str[i] + 1;
				}
			}
			if( str.find( "the" ) != string::npos || str.find( "this" ) != string::npos || str.find( "that" ) != string::npos){
				cout << str << endl;
			}

		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

void solve(long long N, string S) {
    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        char a = i / 100 % 10 + '0';
        char b = i / 10 % 10 + '0';
        char c = i % 10 + '0';
        int x = S.find(a);
        if(x == -1 ) continue;
        int y = S.find(b, x+1);
        if( y == -1 ) continue;
        int z = S.find(c, y+1);
        if( z == -1 ) continue;
        ans++;
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    string S;
    cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n= readLine()!!.toInt()
    val k= readLine()!!.toInt()
    val x= readLine()!!.toInt()
    val y= readLine()!!.toInt()
    if(n>k){
        println(k*x+(n-k)*y)
    }else{
        println(n*x)
    }
}

Measured memory_bytes: 31496
# ABC125D - Flipping Signs
def main():
    # neg % 2 == 0 -> all negatives disappear
    # else -> move all neg to the smallest one (abs(i))
    # if 0 in A -> move all neg there but min will be 0
    N = int(input())
    A = tuple(map(int, input().split()))
    mi = abs(min(A, key=abs))
    abs_sum = sum(abs(i) for i in A)
    neg = sum(i < 0 for i in A)
    ans = abs_sum if neg % 2 == 0 else abs_sum - mi * 2
    print(ans)


if __name__ == "__main__":
    main()

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

int main(){
	int h,w;
	cin >> h >> w;
	char c[h][w];
	int sum = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >>  c[i][j];
			if(c[i][j] == '#')sum++;
		}
	}
	if(sum == h + w - 1)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
 
        int scnt = 0;
        int tcnt = 0;
        String s = sc.next();
        for (int i = 0, len = s.length(); i < len; ++i) {
            if (s.charAt(i) == 'S') {
                ++scnt;
            } else if (scnt > 0 && s.charAt(i) == 'T') {
                --scnt;
            } else {
                ++tcnt;
            }
        }
 
        out.println((scnt + tcnt));
        out.flush();
    }
}

Measured memory_bytes: 26568
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
// Int MOD = 998244353;

Int dp[101][100005];

int main() {
    ios::sync_with_stdio(false);
    Int N, W;
    cin >> N >> W;
    vector<Int> w(N), v(N);
    Int vmax = 0;
    for (Int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
        vmax += v[i];
    }
    for (Int i = 0; i <= N; i++) {
        for (Int j = 0; j <= vmax; j++) {
            dp[i][j] = 1e9;
        }
    }
    dp[0][0] = 0;
    for (Int i = 0; i < N; i++) {
        for (Int j = 0; j <= vmax; j++) {
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]);
            if (j - v[i] >= 0) {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            }
        }
    }
    Int res = 0;
    for (Int i = 0; i <= vmax; i++) {
        if (dp[N][i] <= W) res = i;
    }
    dump(res);
    return 0;  
} 

Measured memory_bytes: 79232
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
      int N=int.Parse(str[0]);
      int X=int.Parse(str[1]);
      int T=int.Parse(str[2]);
      int tmpN=N;
      int ans=0;
      while(tmpN>0){
       tmpN-=X;
        ans+=T;
      }
      Console.WriteLine(ans);
    }
    
  }

}


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

int main(){
	int x,a,b; cin>>x>>a>>b;
	int c=(x-a)/b;
	cout << x-a-c*b << endl;	
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i,j,k,key;
  int l;
  int A[100];
  
  scanf("%d",&l);
  
  for(i=0;i<l;i++)
    {
      scanf("%d",&A[i]);
    }
  
  for(i=0;i<l-1;i++)
    {
      printf("%d ",A[i]);
    }

  printf("%d",A[l-1]);
 
  printf("\n");
  
  for(i=1;i<l;i++)
    {
      key = A[i];

      j = i-1;
      
      while(j>=0 && A[j]>key)
	{
	  A[j+1] = A[j];
	  j--;
	}
  
      A[j+1] = key;
      
      for(k=0;k<l-1;k++)
	{
	  printf("%d ",A[k]);
	}

      printf("%d",A[l-1]);
      
      printf("\n");
     
    }

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
using namespace std;
const int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main() {
        int n;
        cin>>n;
        cout<<arr[n-1]<<'\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(void)
{
char s[101];
char p[101];
int n, m, i, j;
 
scanf("%s", s);
scanf("%s", p);
 
n = strlen(s);
m = strlen(p);
 
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
if (s[(i + j) % n] != p[j])
{
break;
}
}
if (j == m)
{
i = -1;
break;
}
}
 
if (i < 0) {
puts("Yes");
} else {
puts("No");
}
return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  const Int MAX = 303;
  Int n;
  cin>>n;
  vector<Int> cnt(n+1,0);
  for(Int x=1;x<=MAX;x++)
    for(Int y=1;y<=MAX;y++)
      for(Int z=1;z<=MAX;z++){
        Int s=x*x+y*y+z*z+x*y+y*z+z*x;
        if(s<=n) cnt[s]++;
      }

  for(Int i=1;i<=n;i++) cout<<cnt[i]<<newl;
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using f32 = float;
using f64 = double;
using f80 = __float80;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<LL>;
using vvl = vector<vl>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
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;
}
int main()
{
    LL n, a, b, c;
    cin >> a >> b >> c;
   vector<LL>aa;
  if(((b-a)/2)<c){
    FOR(i,a,b+1){
      cout<<i<<endl;
             }
       return 0;
  }
    FOR(i,a, a + c)cout << i<<endl;
    FOR(i,b - c+1,b+1)cout << i<<endl;
}

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

using namespace std ;
using namespace __gnu_pbds;

template <typename T> // *s.find_by_order(0), s.order_of_key(2) ;
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define reMin(a, b) a = min(a, b)
#define reMax(a, b) a = max(a, b)

#define lint long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef vector < int > vi ;
typedef pair < int, int > pii ;

const int N = 303 ;
const int MOD = 1e9 + 7 ;
const lint INF = 1e18 ;

lint cost[N][N], dp[N][N], ans[N][N], residue[N][N] ;
lint L ;
int n, m, w, u, v, q ;

int main()
{
    fastio; cin >> n >> m >> L ;

    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            dp[i][j] = dp[j][i] = cost[i][j] = cost[j][i] = INF ;

    for(int i = 0; i < N; i++) dp[i][i] = 0, cost[i][i] = 0, ans[i][i] = 0 ;

    for(int i = 0; i < m; i++)
    {
        cin >> u >> v >> w ;
        if(w > L) continue ;
        dp[u][v] = dp[v][u] = w ;
    }

    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                reMin(dp[i][j], dp[i][k] + dp[k][j]);


    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            if(dp[i][j] <= L)
                cost[i][j] = 1 ;

    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                reMin(cost[i][j], cost[i][k] + cost[k][j]);

    cin >> q ;
    while(q--)
    {
        cin >> u >> v ;
        if(cost[u][v] >= INF) cout << -1 << endl ;
        else cout << cost[u][v] - 1 << endl ;
    }

}



Measured memory_bytes: 2688
def compute_gcd(x, y):
   while(y):
       x, y = y, x % y
   return x
# This function computes LCM
def compute_lcm(x, y):
   lcm = (x*y)//compute_gcd(x,y)
   return lcm
A, B = [int(i) for i in input().split()]
print(compute_lcm(A, B))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const ll INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

void warshall_floyd(int n, vector<vector<ll>> &d) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<vector<ll>> A(N, vector<ll>(N)), B(N, vector<ll>(N));
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      cin >> A[i][j];
      B[i][j] = A[i][j];
    }
  }
  
  warshall_floyd(N, B);
  
  ll ans = 0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      if(A[i][j] != B[i][j]){
        ans = -1;
        break;
      }
      ll minVia = INF;
      for(int k=0; k<N; k++){
        if(k == i || k == j) continue;
        minVia = min(B[i][k] + B[k][j], minVia);
      }
      if(minVia > B[i][j])
        ans += B[i][j];
    }
    if(ans == -1) break;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <cstdint>
 
using namespace std;
 
int main()
{
	int_least32_t n, m;
	cin >> n >> m;
 
	vector<string> a( n ), b( m );
	for(auto& x : a) {
		cin >> x;
	} 
 
	for(auto& x : b) {
		cin >> x;
	}
 
	int_least32_t dif{ n - m + 1 };
	string temp;
	bool isok;
	for(auto i = 0; i < dif; ++i) {
		for(auto j = 0; j < dif; ++j) {
			isok = true;
			for(auto k = 0; k < m; ++k) {
				if(b[k] != a[i + k].substr(j, m)) {
					isok = false;
					break;
				}
			}
			if(isok) {
				goto end;
			}
		}
	}

end:
	if(isok) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>

typedef long long LL;

#define int LL

const int MAXN = 1e5 + 5;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T MAX( const _T a, const _T b )
{
	return a > b ? a : b;
}

template<typename _T>
_T MIN( const _T a, const _T b )
{
	return a < b ? a : b;
}

int BIT[MAXN];
int a[MAXN], s[MAXN];
int N;

int lowbit( const int &x ) { return x & ( -x ); }
void update( int x, const int v ) { for( ; x <= N ; x += lowbit( x ) ) BIT[x] += v; }
int getSum( int x ) { int ret = 0; while( x ) ret += BIT[x], x -= lowbit( x ); return ret; }

bool chk( const int len )
{
	LL ret = 0; int mn = N;
	for( int i = 1 ; i <= N ; i ++ ) s[i] = a[i] >= len ? -1 : 1;
	for( int i = 1 ; i <= N ; i ++ ) s[i] += s[i - 1], ret += s[i] > 0, mn = MIN( mn, s[i] );
	for( int i = 1 ; i <= N ; i ++ ) BIT[i] = 0, s[i] += 1 - mn;
	for( int i = 1 ; i <= N ; i ++ ) ret += getSum( s[i] - 1 ), update( s[i], 1 );
	return ret <= 1ll * N * ( N + 1 ) / 4;
}

signed main()
{
	int l = 1e9, r = -1;
	read( N );
	for( int i = 1 ; i <= N ; i ++ ) read( a[i] ), l = MIN( l, a[i] ), r = MAX( r, a[i] );
	int mid;
	while( r - l > 1 )
	{
		if( chk( mid = l + r >> 1 ) ) l = mid;
		else r = mid - 1;
	}
	if( chk( r ) ) write( r );
	else write( l );
	putchar( '\n' );
	return 0;
}
/*
3
1 3 2
*/

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,t,b,c,d,a,l,r;
    string s;
    cin>>s;
    ll sz=s.size(),sum=0,cnt=0;
    for(i=sz-1; i>=0; i--)
    {
        sum+=s[i]-'0';
    }
    if(sum%9!=0)
        cout<<"No"<<'\n';
    else
        cout<<"Yes"<<'\n';
}











Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}




int main(){
	char c;
	cin >> c;

	int a  =  c - 'A';
	//cout << a << endl;
	if(a < 26) cout << 'A' << endl;
	else cout << 'a' << endl; 





}


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

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

int N;
Graph G;

vector<int> ans;

//vをcに塗る
void dfs(int v, int p, int col = 1){
  ans[v] = col;
  for(auto e : G[v]){//eは{to,cost}のpairのイテレータ
    if(e.first == p) continue;//親だったらスルー
    if((e.second)%2 == 1) dfs(e.first,v,1-col);//距離が奇数だったら色を変える
    else dfs(e.first, v, col);//距離が偶数だったら色は変えない
  }
}

int main(){
  cin >> N;
  G.assign(N,vector<Edge>());//vector<Edge>型の変数の空集合で初期化
  for (size_t i = 0; i < N-1; i++) {
    int u, v, w;
    cin >> u >>v >> w;
    u--; v--;
    G[u].push_back(Edge(v,w));
    G[v].push_back(Edge(u,w));
  }
  ans.assign(N,0);
  dfs(0,-1,1);
  for(auto v :ans) std::cout << v << '\n';
}


Measured memory_bytes: 8192
n = int(input())
a = list(map(int, input().split()))

safe = list()
for i in range(n - 1):
    for j in range(i + 1, n):
        pro = a[i] * a[j]

        digit = [pro % (10 ** k) // (10 ** (k - 1)) for k in range(1, 10)]

        while digit[-1] == 0:
            digit = digit[:-1]

        if len(digit) == 1:
            safe.append(pro)
            continue

        flag = True
        for k in range(len(digit) - 1):
            if digit[k + 1] - digit[k] != -1:
                flag = False
                break

        if flag:
            safe.append(pro)

if safe:
    safe.sort()
    print(safe[-1])
else:
    print(-1)


Measured memory_bytes: 5628
N = int(input())
P = list(map(int, input().split()))

from itertools import groupby

answer = 0
for k,g in groupby([p==i for p, i in zip(P, range(1,N+1))]):
  if k:
    l = len(list(g))
    answer += l//2 + l%2
      
print(answer)
      

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, x;
  cin >> N >> A;
  x=N % 500;
  if (x <= A) {
    cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;  
  }
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 1;
const int OOO = 1;
using namespace std;

int n;
vector<pair<int, int>> a;
vector<int> b;
ll ans = inf;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	a.resize(n);
	for (auto &i : a) cin >> i.first >> i.second;
	ll s1 = 0, s2 = 0;
	for (int i = 0; i < n; i++) {
		s1 += a[i].first, s2 += a[i].second;
		b.push_back(a[i].first);
		b.push_back(a[i].second);
	}
	ans = min(s1, s2);
	sort(b.begin(), b.end());
	b.resize(n + 2);
	ll s = 0;
	for (int i = 0; i < n; i++) s += b[i];
	for (int i = 0; i < n; i++) {
		if (a[i].first > a[i].second) swap(a[i].first, a[i].second);
		s2 = s;
		if (a[i].first == b[n - 1] && a[i].second == b[n])
			ans = min(ans, s + b[n + 1] - b[n - 1]);
		else {
			if (a[i].second <= b[n - 1]) {
				s2 -= a[i].first;
				s2 -= a[i].second;
				s2 += b[n];
				s2 += b[n + 1];
			}
			else if (a[i].first <= b[n - 1]) {
				s2 -= a[i].first;
				s2 += b[n];
			}
			ans = min(ans, s2);
		}
	}
	finish(ans);
}

Measured memory_bytes: 2168
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
string solve(int N, int D){
  int m[100];
  vector<int> c[100];
  vector<int> sum[100];
  int cnt = 0;
  REP(i, N){
    cin>>m[i];
    cnt += m[i];
    c[i] = vector<int>(m[i]);
    sum[i] = vector<int>(m[i] + 1);
    REP(j, m[i]) cin>>c[i][j];
    REP(j, m[i]) sum[i][j + 1] = sum[i][j] + c[i][j];
  }
  if(N == 1) return "Yes";
  REP(iter, cnt){ //10000
    vector<int> v(N);
    REP(i, N) {
      v[i] = sum[i][m[i]];
    }
    int di = -1;
    sort(v.begin(), v.end());
    REP(i, N)if(m[i] > 0){
      int Max = v.back();
      int Min = v.front();
      if(Max == sum[i][m[i]]) Max = v[v.size() - 2];
      else if(Min == sum[i][m[i]]) Min = v[1];
      if(Max - min(Min, sum[i][m[i] - 1]) <= D){
        di = i;
        break;
      }
    }
    if(di == -1) return "No";
    else m[di]--;
  }
  return "Yes";
}

int main(){
  int N, D;
  while(cin>>N>>D && N){
    cout<<solve(N, D)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1304
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int m1,d1,m2,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  cout << (m1 != m2) << endl; 
}


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

int main()
{
  int N;
  int count=0;
  cin >> N;
  vector <int> P(N);
  for(int i=0; i<N; i++)
  {
    cin >> P.at(i);
  }
  int min=P.at(0);
  for(int i=1; i<N; i++)
  {
    if(min>P.at(i))
    {
      count++;
      min=P.at(i);
    }
  }

  cout << count+1 <<endl;

}

Measured memory_bytes: 1024
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if v == w:
    print('NO')
else:
    if a <= b:
        if 0 <= (b-a)/(v-w) <= t:
            print('YES')
        else:
            print('NO')
    else:
        if 0 <= (b-a)/(w-v) <= t:
            print('YES')
        else:
            print('NO')

Measured memory_bytes: 9192
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))

c = 0
flag = True
while flag:
    flag = False
    for i in range(N - 1, 0, -1):
        if A[i] < A[i - 1]:
            A[i], A[i - 1] = A[i - 1], A[i]
            c += 1
            flag = True
print(' '.join((str(x) for x in A)))
print(c)

Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,s,i,j,l=0;
	scanf("%d%d",&k,&s);
	for(i=0;i<=k;i++)
	{
		for(j=0;j<=k;j++)
		{
			if(s-i-j<=k && 0<=s-i-j)l++;
		}
	}
	printf("%d\n",l);
}

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

int main()
{
	string s;
	cin >> s;
	if(s == "Sunny")cout << "Cloudy\n";
	if(s == "Rainy")cout << "Sunny\n";
	if(s == "Cloudy")cout << "Rainy\n";
	return 0;
}

Measured memory_bytes: 256
num = int(input())

sum = (1 / 2 * num * (num + 1))

t = num // 3
f = num // 5
c = num // 15

three = (t * ((t * 3) + 3) / 2)
five = (f * ((f * 5) + 5) / 2)
com = (c * ((c * 15) + 15) / 2)

print(int(sum - three - five + com))

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

lint n, k;
vector<lint> w;

bool check(lint key){
    lint cnt = 1, tmp = 0;
    rep(i, n){
        if(w[i] > key){
            return false;
        }
        tmp += w[i];
        if(tmp > key){
            tmp = w[i];
            cnt++;
        }
    }
    return cnt <= k;
}

lint meguruSearch(lint ok, lint ng){
    lint mid;
    while(abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

int main(){
    cin >> n >> k;
    w.resize(n);
    lint sum = 0;
    rep(i, n){
        cin >> w[i];
        sum += w[i];
    }
    lint ans = meguruSearch(sum, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		   Scanner sc=new Scanner(System.in);
		    
		   String a=sc.next();
		   String b=sc.next();
		   
		  if(a.length()!=b.length()) {
			  if(a.length() > b.length()) {
				  System.out.println("GREATER");
				  System.exit(0);
			  }else {
				  System.out.println("LESS");
				  System.exit(0);
			  }
		  }
		   
		  if(a.compareTo(b)>0) {
			  System.out.println("GREATER");
		  }else if(a.compareTo(b)<0) {
			  System.out.println("LESS");
		  }else {
			  System.out.println("EQUAL");
		  }

	}

}


Measured memory_bytes: 23892
#include <stdio.h>

int count(char*s,int size,int center){
  int ctr=0;
  for(int i=0;i<center;i++){
    ctr+=(s[i]=='W');
  }
  for(int i=center+1;i<size;i++){
    ctr+=(s[i]=='E');
  }
  return ctr;
}

int main(void){
  int size;
  scanf("%d",&size);
  char s[1000000];
  scanf("%s",s);

  int min=100000000;
  int buf=count(s,size,0);
  min=buf;
  for(int split=1;split<size;split++){
    if(s[split-1]=='W'){
      buf++;
    }else{}
    if(s[split]=='E'){
      buf--;
    }else{}
    min=buf<min?buf:min;
  }
 
  printf("%d",min);
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

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

ll calc(mat &s, vec &c, vec &ans){
    ll res = 0;
    vec last(26, 0);
    rep(day, N){
        last[ans[day]] = day + 1;
        rep(i, 26){
            if(i == ans[day]){
                res += s[day][i];
            }else{
                res -= c[i] * (day + 1 - last[i]);
            }
        }
    }
    return res;
}

int main() {
    cin>>N;
    vec c(26), last(26, 0), ans(N);
    mat s(N, vec(26)), ans_another(26, vec(1, 0));
    rep(i,26) cin>>c[i];
    rep(i,N) rep(j, 26) cin>>s[i][j];
    ll score = 0;
    rep(day, N){
        vec temp(26, 0);
        rep(i, 26) temp[i] += s[day][i];
        rep(i, 26) temp[i] += c[i] * (day + 1 - last[i]);
        auto ite = max_element(ALL(temp));
        ans[day] = ite - temp.begin();
        ans_another[ans[day]].push_back(day + 1);
        last[ite - temp.begin()] = day + 1;
        rep(i, 26){
            if(i == ans[day]){
                score += s[day][i];
            }else{
                score -= c[i] * (day + 1 - last[i]);
            }
        }
    }
    rep(i,26) ans_another[i].push_back(N + 1);

    ll total_num = 150000;
    while(total_num) {
        mat minus(N + 1, vec(26, 0));
        priority_queue<P> pque;
        rep(i, 26) {
            vec &table = ans_another[i];
            int id = 0;
            reps(day, 1, N) {
                if (table[id + 1] == day) {
                    ++id;
                } else {
                    ll weight = s[day - 1][i], len = table[id + 1] - table[id] - 1;
                    ll wh = day - table[id];
                    weight += c[i] * ((len * (len + 1) / 2) - (wh * (wh - 1) / 2 + (len - wh) * (len - wh + 1) / 2));
                    pque.emplace(weight, day * 26 + i);
                }
            }
        }
        if((total_num -= 20) < 0) break;
        rep(check, 10000) {
            P p = pque.top();
            pque.pop();
            ll day = p.se / 26, i = p.se % 26;
            --day;
            ll old = ans[day];
            ans[day] = i;
            if (!chmax(score, calc(s, c, ans))) {
                ans[day] = old;
                total_num -= check * 10;
                check += check * 10;
            }
            if((--total_num) < 0) break;
        }
    }

    rep(i,N) cout<<ans[i] + 1<<'\n';
}


Measured memory_bytes: 3992
#include <iostream>
#include <algorithm>
using namespace std;
int D[100][100];
int main() {
  ios::sync_with_stdio(false);
  int N; cin >> N;
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      cin >> D[i][j];
    }
  }
  long long ans = 0;
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      ans += min(D[i][j], D[j][i]);
    }
  }
  ans /= 2;
  cout << ans << endl;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 10;
int N, u[maxn], v[maxn];
int main()
{
    scanf("%d", &N);
    for(int i = 1; i <= N - 1; i++)
        scanf("%d %d", &u[i], &v[i]);
    LL ans = 0;
    for(int i = 1; i <= N; i++)
        ans += (LL) i * (N - i + 1);
    for(int i = 1; i <= N - 1; i++)
    {
        if(u[i] > v[i])
            swap(u[i], v[i]);
        ans -= (LL) u[i] * (N - v[i] + 1);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 5376
N,M=map(int,input().split())
Appp=[0]*N
Appn=[0]*N
Apnp=[0]*N
Apnn=[0]*N
Anpp=[0]*N
Anpn=[0]*N
Annp=[0]*N
Annn=[0]*N
for i in range(N):
  a,b,c=map(int,input().split())
  Appp[i]=a+b+c
  Appn[i]=a+b-c
  Apnp[i]=a-b+c
  Apnn[i]=a-b-c
  Anpp[i]=-a+b+c
  Anpn[i]=-a+b-c
  Annp[i]=-a-b+c
  Annn[i]=-a-b-c
Appp.sort(reverse=True)
Appn.sort(reverse=True)
Apnp.sort(reverse=True)
Apnn.sort(reverse=True)
Anpp.sort(reverse=True)
Anpn.sort(reverse=True)
Annp.sort(reverse=True)
Annn.sort(reverse=True)
print(max(sum(Appp[:M]),sum(Appn[:M]),sum(Apnp[:M]),sum(Apnn[:M]),sum(Anpp[:M]),sum(Anpn[:M]),sum(Annp[:M]),sum(Annn[:M])))






Measured memory_bytes: 73660
#include <bits/stdc++.h>
#define itr(i,n) for(int i=0; i<n; ++i)

using namespace std;
using ll = long long;
const int MOD = 998244353;

ll power(ll x, ll n, ll M = MOD){
    ll res = 1;
    if(n > 0){
        res = power(x, n / 2, M);
        if(n%2 == 0)res = (res * res) % M;
        else res = (((res * res) % M) * x) % M;
    }
    return res;
}

ll mod_inv(ll n, ll M = MOD){
    return power(n, M-2, M);
}

ll product(ll s, ll r, ll n){ //初項s公比r項数n
    ll value = s;
    if (r == 1){
        value *= n;
        value %= MOD;
        return value;
    }
    value *= (power(r, n) - 1 + MOD);
    value %= MOD;
    value *= mod_inv(r-1);
    value %= MOD;
    return value;
}

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, M, K; cin >> N >> M >> K;
    vector<ll> v(N, 1);
    for (int i = 0; i < N-2; i++){
        v[i+1] = v[i] * (N-i-1);
        v[i+1] %= MOD;
        v[i+1] *= mod_inv(i+1);
        v[i+1] %= MOD;
    }
    ll ans = M;
    ans *= power(M-1, N-1);
    ans %= MOD;
    ll j = M;
    for (int i = 1; i < N; i++){
        if (N - i <= K){
            ans += v[i-1]*j;
            ans %= MOD;
        }
        j *= M-1;
        j %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4772
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        p: usize,
        a: [usize; n],
    }
    let mut count_even = 0;
    for i in a.iter() {
        if i % 2 == 0 {
            count_even += 1;
        }
    }
    if count_even == n && p == 0 {
        println!("{}", 2usize.pow(n as u32));
    } else if count_even == n && p == 1 {
        println!("0");
    } else {
        println!("{}", 2usize.pow((n - 1) as u32));
    }
}


Measured memory_bytes: 2180