akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> l(n, -1), r(n, -1);
    int nextl = 0, nextr = n-1;
    int cntl = 1, cntr = 0;
    for(int i = 0; i < n; i++) {
        if(nextl <= i && s[i] == 'o') {
            l[i] = cntl++;
            nextl = i+c+1;
        }
        if(l[i] == k) break;
    }
    for(int i = n-1; i >= 0; i--) {
        if(nextr >= i && s[i] == 'o') {
            r[i] = (k-cntr++);
            nextr = i-c-1;
        }
        if(r[i] == 1) break;
    }
    for(int i = 0; i < n; i++) {
        if(l[i] != -1 && l[i] == r[i]) cout << i+1 << endl;
    }
}

Measured memory_bytes: 5248
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define M 10
#define N 210
ll c[M][M], h, w, a[N][N];

int main(){
	cin>>h>>w;
	rep(i, M) rep(j, M) cin>>c[i][j];
	rep(i, h) rep(j, w) cin>>a[i][j];
	rep(k, M) rep(i, M) rep(j, M) c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
	ll res = 0;
	rep(i, h) rep(j, w){
		if(a[i][j]>=0) res += c[a[i][j]][1];
	}
	cout<<res<<endl;
	
	return 0;
}


Measured memory_bytes: 640
// AOJ 2791: Cabbage
// 2017.11.29 bal4u@uu

#include <stdio.h>

int que[1001], top;

char buf[5003], *bp;
int getint() { int n = 0; while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf); return n; }

int main()
{
	int n, m, a, b, d, i, ans;

    fgets(bp=buf, 40, stdin);
	n = getint(), bp++, m = getint(), bp++;
	a = getint(), bp++, b = getint();
	fgets(bp=buf, sizeof(buf), stdin);
	ans = 0; top = 0;
	for (i = 0; i < n; i++) {
		d = getint(), bp++;
		if (d >= a) que[top++] = d, ans++;
		else break;
	}

	if (n - ans < m) {
		while (top) {
			d = que[--top];
			if (d <= b) ans--;
			else break;
		}
	}
	printf("%d\n", ans);
    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int sum = 0;
  if(a<b){
    int mem = a;
    a = b;
    b = mem;
  }

  sum = a;
  a--;
  if(a>b) cout << sum + a << endl;
  else cout << sum + b << endl;
  return 0;


}


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

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    
    int *p = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    int count = 0;
    for (int i = 1; i < n - 1; i++) {
        if (((p[i] > p[i - 1]) && (p[i+1] > p[i])) ||
            ((p[i] > p[i + 1]) && (p[i-1] > p[i]))) {
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};
BIT<int,20> bt;

int N;
int A[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	
	int ret=-1;
	for(i=29;i>=0;i--) {
		int cand=ret+(1<<i);
		ZERO(bt.bit);
		int cur=101010;
		ll tot=0;
		bt.add(cur,1);
		FOR(x,N) {
			cur+=((A[x]>=cand)?1:-1);
			tot+=bt(cur);
			bt.add(cur,1);
		}
		if(tot>=1LL*N*(N+1)/2-tot) ret=cand;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4736
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
long long gcd(long long a,long long b){
	while(a){b%=a;swap(a,b);}return b;
}
int L[110000];
int R[110000];
int p[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<a;i++){
		L[i+1]=gcd(L[i],p[i]);
	}
	for(int i=0;i<a;i++){
		R[i+1]=gcd(R[i],p[a-1-i]);
	}
	int ret=0;
	for(int i=0;i<a;i++){
		ret=max(ret,(int)gcd(L[i],R[a-i-1]));
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1280
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == i + 1) {
            ans += 1;
            i += 1;
        }
    }

    ans.writeln;
}


Measured memory_bytes: 4156
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = INT_MAX;
const ll LINF = 922337203685477580LL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

const int N = 1e5+1000;

//head

int n, k;
int h[N];
int dp[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  rep(i, n) cin >> h[i];

  fill(dp+1, dp+n, INF);
  rep(i, n-1) {
    rep(j, k) {
      chmin(dp[i+j+1], dp[i] + abs(h[i]-h[i+j+1]));
    }
  }

  cout << dp[n-1] << endl;
}

Measured memory_bytes: 4400
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
// #define double long double
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N   200005
#define MAX 300005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
//#define endl "\n"
#define inf 1e+15
int fact[N];
int powmod(int x , int y){
	int res = 1;
	while(y>0){
		if(y&1)
			res = (res*x)%mod;
		x=(x*x)%mod;
		y/=2;
	}
	return res;
}
int get(int x , int y){
	   int res = 1;
	   res  = fact[x];
	   res  *= powmod(fact[y] , mod-2) % mod;
	   res %= mod;
	   res  *= powmod(fact[x-y] , mod-2)%mod;
	   res %= mod;
	   return res;
}
signed main(){
  fast;
  int n , m , k , ans = 0;
  cin>>n>>m>>k;
  fact[0] = 1;
  for(int i=1;i<= n*m ; i++)
  	fact[i] = (fact[i-1] * i) % mod;
  for(int i=0;i<= m;i++)  ans += (((m-i)*n*n % mod )*i) % mod , ans%= mod;
  for(int i=0;i<= n;i++)  ans += (((n-i)*m*m % mod)*i)%mod ,  ans %= mod;

  ans = (ans * get(n*m -2 , k-2)) %mod;
  cout << ans << endl;

}
  


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

int main() {
    int n, ai, count = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> ai;
        while (ai % 2 == 0) {
            ai /= 2;
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
ll bit[500005];
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
	if(number1 > number2){
		swap(number1,number2);
	}
	if(number1 == 0 || number1 == number2){
		return number2;
	}else{
		return gcd(number2 % number1,number1);
	}
}

ll i,j,k,ii,jj,r,l;
ll n,num,sum,ans;
ll a,b,c,d,e,g,h,w;
ll x[500005],y[500005],z[500005];
bool dp[10000];
char s[500005];

ll bitsum(ll i){
	ll s = 0;
	while(i>0){
		//p("hoi");
		s += bit[i];
		i -= i & -i;
	}
	return s;
}
void bitadd(ll b,ll x){
	while(b <= n){
		//p("hoi");
		bit[b] += x;
		b += b & -b;
	}
}

int main(){
	cin >> h >> w >> a >> b;
	num = (h/a) * (w/b);
	ll pos,nega;
	pos = (h * w - num) * 512;
	nega = ((a * b - 1) * 512 + 1) * num;
	if(pos > nega){
		p("Yes");
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				if(i % a == 0 && j % b == 0){
					pe(-1 * (a * b - 1) * 512 - 1);
				}else{
					pe(512);
				}
			}
			el;
		}
	}else{
		p("No");
	}
	return 0;
}

Measured memory_bytes: 28672
#!/usr/bin/env python3
import sys
# sys.setrecursionlimit(10000000)
INF = 1<<32


from bisect import bisect_left, bisect_right

def solve(N: int, M: int, A: "List[int]"):
        
    def binary_search(left: int, right: int):
        s = 0
        c = 0
        mi = INF

        while right-left > 1 or c < M:
            # print("test: ", left, " ", right)
            mid = (left+right)//2
            # print("mid: ", mid)
            # mid以上の価値の握手の個数を求める
            # s = []
            s = 0
            c = 0
            mi = INF
            for i in range(N):
                p = bisect_left(A, mid-A[i])
                if p != N:
                    mi = min(mi, A[i]+A[p])
                # print(A[i], A[p:], aq[N]-aq[p],  A[i]*(N-p))
                s += aq[N]-aq[p]
                s += A[i]*(N-p)
                c += N-p
                
            # mid以上の握手の個数がM以上か否か
            if c > M:
                left = mid

            else:
                right = mid
        
        if c > M:
            s -= (c-M)*mi

        return s

    A.sort()
    aq = [0] * (N+1)
    for i in range(N):
        aq[i+1] = aq[i] + A[i]

    print(binary_search(1, A[-1]*2))
    
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 55804
N, X, Y = map(int, input().split())
ans = [0]*(N-1)
for i in range(1, N+1):
    for j in range(i+1, N+1):
        # 使わない場合
        a = abs(j - i)
        # 使う場合
        b = abs(i - X) + abs(j - Y) + 1
        ans[(min(a, b))-1] += 1
for i in ans:
    print(i)


Measured memory_bytes: 3572
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner in = new Scanner(System.in);
    	int n = in.nextInt();
    	int a[] = new int [n];
    	long sum = 0;
    	for(int i = 0;i < n;i++){
    		a[i] = in.nextInt();
    		sum = sum + a[i];
    	}
    	Arrays.sort(a);
    	System.out.print(a[0]+ " "+a[a.length - 1]+" "+sum);
    	System.out.println();
	}
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL ans = 0;
	string s; cin >> s;
	int A = s.front() == 'A';
	int C = 0;
	int BIG = 0;
	int cid = 0;
	FOR(i, 2, SZ(s) - 1) {
		if (s[i] == 'C')C++,cid = i;
	}
	if (C == 1) {
		FOR(i, 1, SZ(s)) {
			if (cid == i)continue;
			BIG |= isupper(s[i]);
		}
	}
	if (A&&C == 1 && !BIG) {
		cout << "AC" << endl;
	}
	else {
		cout << "WA" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
s=input()
n=len(s)
e,p,r=exit,print,range
for i in r(n-1):
 if s[i]==s[i+1]:e(p(i+1,i+2))
for i in r(n-2):
 if s[i]==s[i+2]:e(p(i+1,i+3))
p(-1,-1)

Measured memory_bytes: 9164
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 1e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
void prllP(pair<ll,ll> a){
	cout<<a.first<<" "<<a.second<<endl;
}
void addmul(ll& a,ll b){
	add_self(a,0);add_self(b,0);
	a*=b;
	add_self(a,0);
}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
vector<ll>v[nax];
vector<pair<ll,ll>> dp(nax ,{0,0});

pair<ll,ll> dfs(ll x, ll parent){
ll jj = 0 ;
if(dp[x] != make_pair(jj,jj))return dp[x];

pair<ll,ll> ans ={1,1} ;
for(auto child : v[x]){
	if(child!=parent)dfs(child,x);
}
// case 1 palling x white 
ll res  = 1 ;
for(auto child:v[x]){
if(child == parent)continue ; 
// add_self(ans.first , dp[child].first);
// add_self(ans.first , dp[child].second);
// addmul(res , (dp[child].first + dp[child].second));
// add_self(ans.second , dp[child].first);


addmul(ans.first , (dp[child].first + dp[child].second));
addmul(ans.second , dp[child].first);


}

// ans.first = res;

// if(ans == make_pair(0,0))ans={1,1};
// cout<<x<<" ";prllP(ans);
return dp[x] = ans; 

}

signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n ; cin>>n;
for(ll i = 0 ; i<n -1; i++){
	ll a , b; cin>>a>>b;
	v[a].push_back(b);
	v[b].push_back(a);
}

dfs(1,-1);

ll res = (dp[1].first + dp[1].second)%mod;

cout<<res;



	

	
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    string s;
    cin >> s;

    int cnt = 0;
    int ans = 0;
    for (auto c: s) {
        if (c == 'R') cnt++;
        else cnt = 0;
        chmax(ans, cnt);
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, K: int):
    return int(N % K != 0)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(N, K)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5140
n=int(input())
sp=[]

for i in range(n):
    sp.append(list(input().split()))
    sp[i][1]=int(sp[i][1])
    sp[i].append(i+1)

sp=sorted(sp,key=lambda x:x[1], reverse=True)
sp=sorted(sp,key=lambda x:x[0])

for i in range(n):
    print(sp[i][2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

template <typename T> inline T read(){
    T sum = 0;
    int fl = 1,ch = getchar();
    for(; !isdigit(ch); ch=getchar()) if(ch == '-') fl = -1;
    for(; isdigit(ch); ch=getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
    return sum * fl;
}

const int maxn = 100 + 5;

int n;
struct node{
	string name;
	int p;
	int id;
}a[maxn];

bool cmp(node x,node y){
	if(x.name == y.name) return x.p > y.p;
	return x.name < y.name;
}

int main(){
	n = read<int>();
	for(int i = 1; i <= n; i++){
		cin >> a[i].name;
		a[i].p = read<int>();
		a[i].id = i;
	}
	sort(a + 1, a + n + 1, cmp);
	for(int i = 1; i <= n; i++){
		printf("%d\n",a[i].id);
	}
	return 0;
}

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


int main() {
  int x,y,z,k;
  cin>>x>>y>>z>>k;
  vector<long>a(x);
  vector<long>b(y);
  vector<long>c(z);
  
  rep(i,x){
    cin>>a.at(i);
  }
  rep(i,y){
    cin>>b.at(i);
  }
  rep(i,z){
    cin>>c.at(i);
  }
  vector<long>d;
  rep(i,x){
    rep(j,y){
      d.push_back(a.at(i)+b.at(j));
    }
  }
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  vector<long>e;
  rep(i,min(k,x*y)){
    rep(j,z){
      e.push_back(d.at(i)+c.at(j));
    }
  }
  sort(e.begin(),e.end());
  reverse(e.begin(),e.end());
  
  rep(i,k){
    cout<<e.at(i)<<endl;
  }
}
            

Measured memory_bytes: 43240
import java.util.Scanner;

public class Main {

	private static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) {

		int x = scan.nextInt();
		int y = scan.nextInt();
		int z = scan.nextInt();

		System.out.println(z +" "+ x +" "+ y);

	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;

const long long B=1000000000000000003LL;
const long long P=1000000000000000031LL;

long long mul(long long x,long long y,long long m){
	long long z=0;
	for(;y;y>>=1){
		if(y&1){z+=x;if(z>=m)z-=m;}
		x+=x;if(x>=m)x-=m;
	}
	return z;
}

long long pow_binary_mod(long long x,long long y,long long m){
	long long z=1;
	for(;y;y>>=1){
		if(y&1)z=mul(z,x,m);
		x=mul(x,x,m);
	}
	return z;
}

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

	int N;
	string s;
	cin>>N>>s;
	long long Brev=pow_binary_mod(B,P-2,P);
	vector<long long> o(N+1),p(N+1);p[0]=1;
	for(int i=1;i<=N;i++){
		p[i]=p[i-1];o[i]=o[i-1];
		if(s[i-1]=='>'){
			p[i]=mul(p[i],B,P);
		}else if(s[i-1]=='<'){
			p[i]=mul(p[i],Brev,P);
		}else if(s[i-1]=='+'){
			o[i]=(o[i]+p[i])%P;
		}else if(s[i-1]=='-'){
			o[i]=(o[i]-p[i]+P)%P;
		}
	}
	map<long long,int>m;
	long long r=0;
	for(int i=N;i>=1;i--){
		m[o[i]]++;
		r+=m[(mul(o[N],p[i-1],P)+o[i-1])%P];
	}
	printf("%lld\n",r);
}

Measured memory_bytes: 35604
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, arr[101], mn = 1e9;
int main() {
    IOS
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
        arr[i] += arr[i-1];
    }
    for (int i = 1; i < n; ++i) {
        mn = min(mn, abs((arr[n]-arr[i])-arr[i]));
    }
    cout << mn << endl;

    return 0;


}


Measured memory_bytes: 256
// finish date: 2019/2/22

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    vvi abc(N, vi(3)), dp(N, vi(3, 0));
    rep(i, N) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    dp[0][0] = abc[0][0], dp[0][1] = abc[0][1], dp[0][2] = abc[0][2];
    FOR(i, 1, N) {
        dp[i][0] = max(dp[i][0], abc[i][0] + max(dp[i - 1][1], dp[i - 1][2]));
        dp[i][1] = max(dp[i][1], abc[i][1] + max(dp[i - 1][0], dp[i - 1][2]));
        dp[i][2] = max(dp[i][2], abc[i][2] + max(dp[i - 1][0], dp[i - 1][1]));
    }
    cout << max({dp[N - 1][0], dp[N - 1][1], dp[N - 1][2]}) << endl;

    return 0;
}

Measured memory_bytes: 11136
# -*- coding:utf-8 -*-
import sys,math,statistics
input = sys.stdin.readline
n = int(input())
a = [int(_) for _ in input().split()]
c1 = math.floor(statistics.mean(a))
c2 = math.ceil(statistics.mean(a))
a1 = sum([(i-c1)**2 for i in a])
a2 = sum([(i-c2)**2 for i in a])
print(min(a1,a2))

Measured memory_bytes: 10932
#include <bits/stdc++.h>
using namespace std; 
int main()
{
  int n;
  string str;
  cin >> str;
  n = stoi(str);
  int count = 0;
  int sosuu[10000] = {0};
  for (int i = 2; i <= 55555; ++i) {
    bool is_sosuu = true;
    for (int j = 0; j < count; ++j) {
      if (sosuu[j] > (int)sqrt(i)) {
        break;
      }
      if (i % sosuu[j] == 0) {
        is_sosuu = false;
      }
    }
    if (is_sosuu) {
      sosuu[count++] = i;
    }
  }
  unsigned int ncount = 0;
  int result[n] = {0};
  for (unsigned int i = 0; i < count; i++) {
    if (sosuu[i] % 5 == 1) {
      result[ncount] = sosuu[i];
      ncount++;
 
      if (ncount == n) {
        break;
      }
    }
  }
 
  cout << result[0];
  for (size_t i = 1; i < n; i++) {
    cout << " " << result[i];
  }
  cout << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int A, B, C;

	cin >> A >> B >> C;

	int p = max(A, B);
	p = max(p, C);

	int ans = A + B + C + p * 10 - p;

	cout << ans;


	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int editDistance(string x,string y){
  int n=x.length(),m=y.length();
  int INF=1LL<<55LL;
  vector<vector<int> > dp(n+1,vector<int>(m+1,INF));
  for(int i=0;i<=n;i++) dp[i][0]=i;
  for(int i=0;i<=m;i++) dp[0][i]=i;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
      dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
      dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(x[i-1]!=y[j-1]));
    }
  }
  return dp[n][m];
}
signed main(){
  string s1,s2;
  cin>>s1>>s2;
  cout<<editDistance(s1,s2)<<endl;
  return 0;
}

Measured memory_bytes: 10840
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N=Integer.parseInt(sc.next());
int[][][] vv=new int[4][3][10];
for(int i=0;i<N;i++){
int b=Integer.parseInt(sc.next());
int f=Integer.parseInt(sc.next());
int r=Integer.parseInt(sc.next());
int v=Integer.parseInt(sc.next());
vv[b-1][f-1][r-1]+=v;
}

for(int F=0;F<4;F++){
for(int j=0;j<3;j++){
    for(int i=0;i<10;i++){
    if(i!=9){System.out.print(" "+vv[F][j][i]);}else{System.out.println(" "+vv[F][j][i]);}
    }
if(F!=3&&j==2)System.out.println("####################");
}
}

}
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    string s1, s2, s3, s4;
    cin >> s1 >> s2;

    // 処理
    reverse_copy(s1.begin(), s1.end(), back_inserter(s3));
    reverse_copy(s2.begin(), s2.end(), back_inserter(s4));

    // 出力
    if (s1 == s4 && s2 == s3) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def parse_line(line):
  ret = []
  for c in line:
    if c == "b":
      ret.append("b")
    else:
      for _ in range(int(c)):
        ret.append(".")
  return ret

def parse_jfen(s):
  return list(map(parse_line, s.split("/")))

def to_jfen(mp):
  ret = ""
  cnt = 0
  for line in mp:
    cnt = 0
    for c in line:
      if c == "b":
        if cnt != 0:
          ret += str(cnt)
          cnt = 0
        ret += "b"
      else:
        cnt += 1
    if cnt != 0:
      ret += str(cnt)
    ret += "/"
  return ret[:-1] 

while True:
  s = input()
  if s == "#":break
  mp = parse_jfen(s)
  a, b, c, d = map(int, input().split())
  mp[a - 1][b - 1] = "."
  mp[c - 1][d - 1] = "b"
  print(to_jfen(mp))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e18 + 7;


int main (){
    string s[3];
    int atual = 0;

    cin >> s[0] >> s[1] >> s[2];
    char last = s[atual].front();
    

    while (!s[atual].empty()){
        last = s[atual].front();
        s[atual].erase(s[atual].begin());
        atual = last - 'a';
    }

    cout << (char(last - 32)) << endl;

    return 0;
}

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

using namespace std;

int main()
{
    string s;
    int a = 0,b = 0;
    cin >> s;
    for(char c : s){
      switch(c){
        case 'A':
          a++;
          break;
        case 'B':
          b++;
      };
    }
    if(a != 0 && b != 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

/**
 * Created by btk on 2017/03/16.
 */
public class Main {
    static int N;
    static long[] A;
    static FastScanner in;
    static PrintWriter out;
    static void init(){
        N = in.nextInt();
        A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextLong();
        }
    }
    static void solve(){
        Arrays.sort(A);
        long[] B = Arrays.copyOf(A,N);
        for (int i = 1; i < N; i++) {
            B[i] += B[i-1];
        }
        for (int i = 1; i < N; i++) {
            if(B[N-i-1] * 2 < A [N-i]){
                out.println(i);
                return;
            }
        }
        out.println(N);
    }
    public static void main(String[] args){
        in = new FastScanner();
        out = new PrintWriter(System.out);
        init();
        solve();
        out.close();
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 25280
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

// void v_print(vi &v){for(auto e:v){printf("%d,",e);}puts("");}//

vi solve(int N, vi &A){
	vi ans(N+1);
	int ia = 1;
	int mid = N/2;
	if(N%2){//odd
		mid++;
		ans[mid] = A[ia++];
	}
	// v_print(ans);//
	int f = mid-1, b = mid+1;
	if(N%2 == 0){//even
		f++;
	}
	while(ia<=N){
		if(ia%2){//odd
			ans[f--] = A[ia];
		}
		else{//even
			ans[b++] = A[ia];
		}
		ia++;
	}
	// v_print(ans);//
	if(N%2 == 0) reverse(ans.begin()+1,ans.end());
	// v_print(ans);//
	return ans;
}

int main(){
	int N; cin>>N; // 1<=N<=2*10^5
	vi A(N+1); // 0<=ai <=10^9
	rp(i,1,N+1) cin>>A[i];
	vi ans = solve(N, A);
	rp(i,1,N+1) cout<<ans[i]<<" ";
}


Measured memory_bytes: 3840
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a int
	var s, buf string
	fmt.Scan(&buf)
	fmt.Scan(&s)
	a, _ = strconv.Atoi(buf)
	if a >= 3200 {
		fmt.Println(s)
		return
	}
	fmt.Println("red")
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 200005;
typedef long long ll;
int main(){
  int N; cin >> N;
  ll a[MAX_N];
  ll x;
  ll y;
  for(int i=0;i<N;i++){
    cin >> a[i];
    if(i>0){
      y += a[i];
    }
  }
  x = a[0];
  ll ans = abs(x - y);
  ll temp;
  for(int i=1; i<N-1;i++){
    x = x + a[i];
    y = y - a[i];
    temp = abs(x-y);
    if(temp < ans){
      ans = temp;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
    int n, b, r, f, v, house[4][3][10];
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                house[i][j][k] = 0;
            }
        }
    }
    cin >> n;
    for(int i = 0; i<n; ++i){
        cin >> b >> f >> r >> v;
        house[b-1][f-1][r-1] += v;
    }
    
    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<10; k++){
                    cout << " " << house[i][j][k];
            }
            cout << endl;
        }
        if(i - 3) cout << "####################"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char c;
  cin >> c;
  cout << char(c + 1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int N, K;

template <typename T>
void f(T S, int* V) {
	S[1][0] = V[0];
	S[1][1] = 1;
	for (int i = 1; i <= N; ++i) {
		S[i][0] = S[i - 1][0] + V[i - 1];
		S[i][1] = S[i - 1][1] + 1;
	}

	for (int i = min(N - 1, K); i >= 0; --i) {
		priority_queue<int> neg;
		for (int j = 1; j < i; ++j) {
			if (V[j - 1] < 0)
				neg.push(-V[j - 1]);
		}
		int n = 1;
		int s = S[i][0];
		while (!neg.empty() && i + n <= K) {
			s = s + neg.top();
			if (S[i + n][0] <= s) {
				S[i + n][0] = s;
				S[i + n][1] = S[i][1];
			}
			neg.pop();
			n += 1;
		}
	}
}

int main() {
	cin >> N >> K;
	int V1[50];
	int V2[50];
	for (int i = 0; i < N; ++i) {
		cin >> V1[i];
	}
	for (int i = 0; i < N; ++i) {
		V2[i] = V1[N - i - 1];
	}

	int res = 0;
	int si = 0;
	int SI[101][2] = { 0 };
	int SJ[101][2] = { 0 };

	f(SI, V1);
	f(SJ, V2);

	int ans = 0;
	for (int i = 0; i <= K; ++i) {
		for (int j = 0; i + j <= K; ++j) {
			if (SI[i][1] + SJ[j][1] <= N) {
				ans = max(SI[i][0] + SJ[j][0], ans);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(N);
  ll ans, mx = -INF;
  REP(i, N) {
    LCIN(a, b);
    if (a > mx) {
      ans = a + b;
      mx = a;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
int main(){
    int N;
    cin >> N;
    vector<int> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    int ans = 0;
    
    rep(i,N){
        int sum = 0;
        repi(j,0,i) sum += A[j];
        repi(j,i,N-1) sum += B[j];
        ans = max(sum,ans);
    }
    pr(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	string s, t;
	cin >> s >> t;
	for(int i = 0; i < s.size(); i++){
			bool flag = true;
			for(int j = 0; j < s.size(); j++){
					if(j + i >= s.size()){
							if(s[j] != t[i + j - s.size()]){
									flag = false;
									break;
							}
					}else{
							if(s[j] != t[i+j]){
									flag = false;
									break;
							}
					}
			}
			if(flag){
					cout << "Yes" << endl;
					return 0;
			}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int h,w,n;cin>>h>>w>>n;
	int ans=0;
	ans += n/max(h,w);
	if(n%max(h,w)!=0){
		ans++;
	}
	cout<<ans<<endl;
} 

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

namespace ConsoleApplication1
{
    class Program
    {
        static string[] input;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            input = Console.ReadLine().Split(' ');

            string[] C1 = new string[n];
            string[] C2 = new string[n];

            input.CopyTo(C1, 0);
            BubbleSort(C1, n);
            PrintResult(C1, n);

            input.CopyTo(C2, 0);
            SelectionSort(C2, n);
            PrintResult(C2, n);
        }

        static void BubbleSort(string[] c,int n)
        {
            for(int i= 0; i < n; i++)
            {
                for(int j = n - 1; j > i; j--)
                {
                    if (c[j][1] < c[j - 1][1])
                    {
                        string temp = c[j];
                        c[j] = c[j - 1];
                        c[j - 1] = temp;
                    }
                }
            }
        }

        static void SelectionSort(string[] c,int n)
        {
            for(int i= 0; i < n; i++)
            {
                int minj = i;

                for(int j = i; j < n; j++)
                {
                    if (c[j][1] < c[minj][1]) minj = j;
                }

                string temp = c[i];
                c[i] = c[minj];
                c[minj] = temp;
            }
        }

        static void PrintResult(string[] c, int n)
        {
            bool isStable = true;

            for(int i = 0; i < n - 1; i++)
            {
                Console.Write(c[i] + " ");

                if (isStable && c[i][1] == c[i + 1][1])
                {
                    int index1 = Array.IndexOf(input, c[i]);
                    int index2 = Array.IndexOf(input, c[i + 1]);

                    if (index1 > index2) isStable = false;
                }
            }
            Console.WriteLine(c[n - 1]);

            Console.WriteLine(isStable ? "Stable" : "Not stable");
        }
    }
}

Measured memory_bytes: 8852
n = int(input())

d12 = [map(int, input().split()) for _ in range(n)]
d1, d2 = [list(i) for i in zip(*d12)]

for i in range(n-2):
  if d1[i] == d2[i]:
    if d1[i+1] == d2[i+1]:
      if d1[i+2] == d2[i+2]:
        print("Yes")
        break
else:
  print("No")

Measured memory_bytes: 9192
import java.util.*;class Main{public static void main(String[]z){int i,j,k,c,t,b;Scanner s=new Scanner(System.in);for(;(t=s.nextInt())>0;System.out.println(b))for(b=i=0;i++<t;)for(j=i+1;j++<t;b+=c==t?1:0)for(c=0,k=i;k<j;k++)c+=k;}}

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


int main() {
    ll n;
    std::cin >> n;
    vector<ll> d(n);
    for (int i = 0; i < n; i++) {
        std::cin >> d[i];
    }
    if(d[0]!=0){
        std::cout << 0 << std::endl;
        return 0;
    }
    sort(d.begin(),d.end());
    
    vector<ll> dp(n,0);
    
    
    ll res = 1;
    dp[0]++;
    for (int i = 1; i < n; i++) {
        if(d[i]==0){
            std::cout << 0 << std::endl;
            return 0;
        }
        
        res *= dp[d[i]-1];
        res %= 998244353;
        
        dp[d[i]]++;

        if(res==0){
            std::cout << 0 << std::endl;
            return 0;
        }
    }
    std::cout << res << std::endl;
}


Measured memory_bytes: 1792
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
CD = [list(map(int,input().split())) for _ in range(M)]

Ans = [0]*N

for i in range(N):
    dis = 10**10
    a,b = AB[i]
    for j in range(M):
        c,d = CD[j]
        tmp_dis = abs(a-c)+abs(b-d)
        if dis > tmp_dis:
            dis = tmp_dis
            Ans[i] = j+1

for ans in Ans:
    print(ans)

Measured memory_bytes: 3064