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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;

struct exam {
    ll A, B;
};

static bool cmp(const exam &x, const exam &y) {
    return (x.A - x.B) > (y.A - y.B);
}
int main() {
    ll n;
    cin >> n;
    vector<exam> nums(n);
    ll sumA = 0;
    ll sumB = 0;
    for (auto i = 0; i < n; ++i) {
        cin >> nums[i].A;
        sumA += nums[i].A;
    }
    for (auto i = 0; i < n; ++i) {
        cin >> nums[i].B;
        sumB += nums[i].B;
    }
    if (sumA < sumB) {
        cout << -1 << endl;
    } else {
        ll res = 0;
        ll c = 0;
        for (int i = 0; i < n; ++i) {
            if (nums[i].A < nums[i].B) {
                ++res;
                c += nums[i].B - nums[i].A;
            }
        }
        if (res == 0) {
            cout << 0 << endl;
            return 0;
        }
        sort(nums.begin(), nums.end(), cmp);
        for (int i = 0; i < n; ++i) {
            ll diff = (nums[i].A - nums[i].B);
            if (diff <= 0) continue;
            ++res;
            if (diff >= c) {
                break;
            } else {
                c -= diff;
            }
        }
        cout << min(res, n) << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	const Int MOD = 1e9 + 7;
	Int N, K;
	cin >> N >> K;
	vector<vector<int>> g(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}

	vector<vector<Int>> memo(N, vector<Int>(2, 0));
	Int res = 1;
	vector<bool> used(N, false);
	used[0] = true;
	deque<int> que;
	que.push_back(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop_front();
		(res *= max(K - memo[v][0] - memo[v][1], (Int)0)) %= MOD;

		Int cnt = 0;
		for (auto u : g[v]) {
			if (used[u]) { continue; }
			que.push_back(u);
			used[u] = true;
			memo[u][0] = 1;
			memo[u][1] = memo[v][0] + cnt;
			++cnt;
		}
	}
	cout << res % MOD << endl;

	return 0;
}


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

using namespace std;

int A, B;

const int K = 3;
void addAround (vector < int > &v, int n)
{
    for (int dx=-K; dx<=K; dx++)
        v.push_back (n + dx);
}

bool ok (int N)
{
    if (N < A)
    {
        ///max i(N+1-i) for 1<=i<=N
        ///max (N+1)i - i^2
        int i = (N + 1) / 2;
        return (1LL * i * (N + 1 - i) < 1LL * A * B);
    }
    if (N < B)
    {
        ///max i(N+1-i) for 1<=i<A
        ///max (i + 1)(N + 1 - i) for A<=i<=N
        vector < int > useful;
        addAround (useful, 1);
        addAround (useful, A);
        addAround (useful, A / 2);
        addAround (useful, (N + 1) / 2);
        addAround (useful, N);
        sort (useful.begin (), useful.end ());
        useful.erase (unique (useful.begin (), useful.end ()), useful.end ());
        for (auto i : useful)
        {
            if (i < 1 || i > N) continue;
            long long curr = 1LL * (i + (i >= A)) * (N + 1 - i);
            if (curr >= 1LL * A * B) return 0;
        }
        return 1;
    }
    ///max i(N+1-i)
    vector < int > useful;
    addAround (useful, 1);
    addAround (useful, A);
    addAround (useful, (N + 1) / 2);
    addAround (useful, N);
    addAround (useful, B);
    addAround (useful, A / 2);
    addAround (useful, B / 2);
    sort (useful.begin (), useful.end ());
    useful.erase (unique (useful.begin (), useful.end ()), useful.end ());
    for (auto i : useful)
    {
        if (i < 1 || i > N) continue;
        long long curr = 1LL * (i + (i >= A)) * ((N + 1 - i) + ((N + 1 - i) >= B));
        if (curr >= 1LL * A * B) return 0;
    }
    return 1;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

int tests;
scanf ("%d", &tests);
while (tests --)
{
    scanf ("%d %d", &A, &B);
    if (A > B) swap (A, B); ///A <= B now
    int p = 1, u = 2 * B - 1, ras = 0;
    while (p <= u)
    {
        int mij = p + (u - p) / 2;
        if (ok (mij)) ras = mij, p = mij + 1;
        else u = mij - 1;
    }
    printf ("%d\n", ras);
}
return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int a = 1;
	while (a <= n)a *= 2;
	cout << a / 2 << endl;
}



Measured memory_bytes: 256
A,B,C,D=map(int, input().split())
if A<C:
  if C<B:
    if D<B:
      print(D-C)
    else:
      print(B-C)
  else:
    print(0)
else:
  if A<D:
    if B<D:
      print(B-A)
    else:
      print(D-A)
  else:
    print(0)


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set> 
#include<cmath>
using namespace std;
//long long p = 998244353;
long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n, int mod) {
    if (n == 0) { return 1 % mod; }
    int x = rui(a, n / 2, mod);
    x *= x; x %= mod;
    if (n % 2 == 1) { x *= a; x %= mod; }
    return x;
}
vel pa;
int root(int x) {
    if (pa[x] == -1) { return x; }
    int ans = root(pa[x]); pa[x] = ans;
    return ans;
}
void marge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) { pa[x] = y; }
}
int gcd(int x, int y) {
    if (x < y) { return gcd(y, x); }
    if (y == 0) { return x; }
    return gcd(y, x % y);
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
vel uni(vel x) {
    if (x.size() == 0) { return x; }
    sor(x);
    int n = x.size();
    vel ans(1, x[0]);
    for (int j = 1; j < n; j++) {
        if (x[j - 1] != x[j]) { ans.push_back(x[j]); }
    }
    x = ans;
    return x;
}
void pr(vel& v) {
    int n = v.size();
    if (n != 0) {
        cout << v[0];
        rep(i, n - 1) {
            cout << " " << v[i + 1];
        }
        cout << endl;
    }
}
signed main(){
    int n; cin >> n;
    int a; cin >> a;
    int ans = 0;
    rep(i, n - 1) {
        int x; cin >> x;
        if (x > a) { ans++; }
        a = x;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3724
/*
 * Author: FreePascal
 * Created Time:  2011-8-31 12:36:01
 * File Name: a.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <stack>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

const int maxn = 1000 + 100;
int n,m,s[maxn],b[maxn][maxn];
int main() {
    while (scanf("%d%d",&n,&m) != EOF){
        if (n == 0 && m == 0) break;
        for (int i = 0; i < m; i++) scanf("%d",&s[i]);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) scanf("%d",&b[i][j]);
        bool flag = true;
        for (int i = 0; i < m; i++){
            int sum = 0;
            for (int j = 0; j < n; j++) sum += b[j][i];
            if (sum > s[i]) {
                flag = false;
                break;
            }
        }
        if (!flag) puts("No");
        else puts("Yes");
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int i = 1;
		int x = i;
		
		for(x=i;i<=n;i++){
			x = i;
			if(x%3 == 0){
				System.out.print(" "+i);
				continue;
			}
			if(x%10 == 3){
				System.out.print(" "+i);
				continue;
			}
			x /= 10;
			while(x != 0){
				if(x%10 == 3){
					System.out.print(" "+i);
					break;
				}else {
					x /= 10;
					continue;
				}
				
			}
			
			
		}
		System.out.printf("\n");
		sc.close();
	}
	

}

Measured memory_bytes: 24196
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<cmath>
#define ll long long
#define maxn 5000
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,first[1010],dp[1010],x[1010],cnte,minn[5010][2];
struct edge{
	int to,next;
}a[2010];
inline void add(int u,int v){
	a[++cnte]=(edge){v,first[u]};first[u]=cnte;
}
void clear(int p){for(int i=0;i<=maxn;i++) minn[i][p]=1e9;}
bool dfs(int u,int f){
//	cout<<"enter dfs "<<u<<' '<<f<<' '<<first[u]<<'\n';
	int i,v,pre=1,cur=0,tans=1e9,j;dp[u]=0;if(first[u]==-1) return 1;
	for(i=first[u];~i;i=a[i].next){
		v=a[i].to;
		if(!dfs(v,u)) return 0;
	}
	clear(cur);minn[0][cur]=0;
	for(i=first[u];~i;i=a[i].next){
		v=a[i].to;
		swap(cur,pre);clear(cur);
		for(j=0;j<=x[u];j++){
			if(j>=x[v]) minn[j][cur]=min(minn[j][cur],minn[j-x[v]][pre]+dp[v]);
			if(j>=dp[v]) minn[j][cur]=min(minn[j][cur],minn[j-dp[v]][pre]+x[v]);
		}
	}
	for(i=0;i<=x[u];i++) tans=min(tans,minn[i][cur]);
//	cout<<"dfs "<<u<<' '<<f<<' '<<x[u]<<' '<<tans<<'\n';
	if(tans==1e9) return 0;
	dp[u]=tans;return 1;
}
int main(){
	memset(first,-1,sizeof(first));
	n=read();int i,t1;
	for(i=2;i<=n;i++) t1=read(),add(t1,i);
	for(i=1;i<=n;i++) x[i]=read();
	if(dfs(1,0)) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}


Measured memory_bytes: 384
#include <iostream>
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	// your code goes here
	ll n;
	cin>>n;
	ll w;
	cin>>w;
	ll arr[n+1][2];
	arr[0][0]=0;
	arr[0][1]=0;
	for(ll i=1;i<=n;i++)
	{
		cin>>arr[i][0]>>arr[i][1];
	}
	for(ll i=1;i<n;i++)
	{
		for(ll j=i+1;j<=n;j++)
		{
			if(arr[j][0]>arr[i][0])
			{
				ll t=arr[j][0];
				arr[j][0]=arr[i][0];
				arr[i][0]=t;
				t=arr[j][1];
				arr[j][1]=arr[i][1];
				arr[i][1]=t;
			}
		}
	}
	ll brr[n+1][w+1];
	for(ll i=0;i<=n;i++)
	{
		brr[i][0]=0;
	}
	for(ll i=0;i<=w;i++)
	{
		brr[0][i]=0;
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=w;j++)
		{
			if(j-arr[i][0]>=0)
			brr[i][j]=max(brr[i-1][j],brr[i-1][j-arr[i][0]]+arr[i][1]);
			else
			brr[i][j]=brr[i-1][j];
		}
	}
	cout<<brr[n][w];
	
	
	
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	auto sum_div = [&](ll n, ll k) {
		return k * (n / k * (n / k + 1)) / 2;
	};
	cout << sum_div(n, 1) - sum_div(n, 3) - sum_div(n, 5) + sum_div(n, 15) << '\n';
}


Measured memory_bytes: 3644
N = gets.to_i
A = [0] + gets.split.map(&:to_i)

l = Array.new(N+2, 0)
r = Array.new(N+2, 0)
1.upto(N) do |i|
  l[i] = l[i-1].gcd(A[i])
end
N.downto(1) do |i|
  r[i] = r[i+1].gcd(A[i])
end

ans = []
1.upto(N) do |i|
  ans << l[i-1].gcd(r[i+1])
end
puts ans.max


Measured memory_bytes: 11788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vl a(n+1);
	rep(i,n)cin>>a[i+1];
	partial_sum(all(a),a.begin());
	sort(all(a));
	ll ans=0,cnt=1;
	rep(i,n){
		if(a[i]!=a[i+1]){
			ans+=cnt*(cnt-1)/2;
			cnt=0;
		}
		cnt++;
	}
	cout<<ans+cnt*(cnt-1)/2<<endl;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())
H = tuple(map(int, input().split()))

n_max = 0
n = 0
last = H[-1]
for x in H[-2::-1]:
    if x >= last:
        n += 1
    else:
        n_max = max(n, n_max)
        n = 0
    last = x
n_max = max(n, n_max)
print(n_max)

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

int main(){
  
  int n, q, b, e, t;
  
  cin >> n;
  vector<int> A(n);
  vector<int>::iterator a = A.begin();
  for(int i = 0;i < n;i++) cin >> A[i];
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> b >> e >> t;
    swap_ranges(a + b, a + e, a + t);
  }
  
  for(int i = 0;i < n;i++){
    cout << (i?" ":"");
    cout << A[i];
  }
  cout << endl;
  
  return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
ll gcd(ll a,ll b){
    return (a%b)? gcd(b,a%b):b;
}
int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll ans = gcd(A[0],A[1]);
    for (int i = 2; i < N; i++) {
        ans = gcd(ans,A[i]);
    }

    cout << ans << endl;


    return 0;
}


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

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

int main() {
    ll n;
    cin >> n;
    ll minnum = 2000000000000000;
    vector<ll> t(5);
    rep(i, t.size()) {
        cin >> t[i];
        minnum = min(minnum, t[i]);
    }

    ll g = n / minnum;
    if (n % minnum != 0) g++;
    ll ans = 5 + (g - 1);
    cout << ans << endl;
}

Measured memory_bytes: 3160
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007LL;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
llint LBI(vector<int>&ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint UBI(vector<int>&ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin>>a>>b;
	cout<<((b-a)*(b-a-1)/2)-a<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
    int N,M,C,A;
    cin>>N>>M>>C;
    A=0;
    int B[M];
    for(int i=0;i<M;i++){
        cin>>B[i];
    }
    
    for(int i=0;i<N;i++){
        int D[M];
        int P;
        P=0;
        for(int j=0;j<M;j++){
            cin>>D[j];
            
            P=P+B[j]*D[j];
            
        }
        
        if(P+C>0){
            A=A+1;
        }
      

    }



    
    cout<<A<<endl;    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		StringBuilder sb = new StringBuilder();

		String s = sc.nextLine();

		for (int i = 0; i < s.length(); i++) {
			switch (s.charAt(i)) {
			case '0':
				sb.append("0");
				break;
			case '1':
				sb.append("1");
				break;
			case 'B':
				if (!sb.toString().equals("")) {
					sb.deleteCharAt(sb.length() - 1);
				}
				break;
			}
		}
		System.out.println(sb);
		sc.close();
	}
}



Measured memory_bytes: 21844
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    if c_l[i]<i:
        cnt+=c_l[i]
    else:
        cnt+=c_l[i]-i
print(cnt)

Measured memory_bytes: 70052
import java.util.*;

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

        int N = sc.nextInt();
        
        if(N<4){
            System.out.println("No");
        }
        else{
            loop:for(int i=0; i<=N/4; i++){
                for(int j=0; j<=N/7; j++){
                    if(4*i+7*j==N){
                        System.out.println("Yes");
                        break loop;
                    }
                }
                if(i==N/4){
                    System.out.println("No");
                }
            }
        }
    }
}

Measured memory_bytes: 25172
import java.util.*;

public class Main {
	static int count = 0;

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] K = new int[N];
		int[][] A = new int[N][100];
		for (int i=0; i<N; i++) {
			K[i] = sc.nextInt();
			for (int j=0; j<K[i]; j++) {
				A[i][j] = sc.nextInt();
			}
		}

		int[][] matrix = new int[N][M];
		for (int i=0; i<N; i++) {
			for (int j=0; j<K[i]; j++) {
				matrix[i][A[i][j]-1] = 1;
			}
		}
		
		int[] check = new int[M];
		for (int i=0; i<M; i++) {
			for (int j=0; j<N; j++) {
				check[i] += matrix[j][i];
			}
			
			if(check[i]==N) {
				count++;
			}
		}
		
		System.out.println(count);

	}

}


Measured memory_bytes: 24532
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),k=nxt();
    int test=0;
    while(n--)
    {
        int x=nxt();
        test+=min(2*abs(x),2*abs(k-x));
    }
    cout<<test<<endl;
    
    return 0;   
}




 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int d, n;
    cin >> d >> n;
    int left = pow(100, d);
    int cnt = 0;
    int i = left;
    while(true){
        int x = i;
        int c = 0;
        while(x > 0 && x % 100 == 0){
            x /= 100;
            c++;
        }
        if(c == d) cnt++;
        if(cnt == n){
            cout << i;
            return 0;
        }
        i++;
    }
}

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

n = input()
for i in range(1, n + 1):
    a = long(raw_input())
    b = long(raw_input())
    c = a + b
    d = c
    digit = 0
    while c > 0:
        c = c / 10
        digit += 1

    if digit > 80:
        print 'overflow'
    else:
        print d

Measured memory_bytes: 4692
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

int main(){
 int x;
 cin >> x;
 cout << x*x*x << '\n';
}

Measured memory_bytes: 3080
/**********************************************
 *Author*        :jxf378440404
 *Created Time*  : 2018/10/27 20:08:33

*********************************************/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;

int vis[MaxN + 5];
int pos[MaxN + 5];
int flag[3000][3000];

int main()
{
	int n,a,cnt;
	while(~scanf("%d",&n)){
		a = sqrt(2 * n);
		for(int i = 1; i <= n;i++) vis[i] = 0,pos[i] = 0;
		if(a * (a + 1) == n * 2){
			printf("Yes\n");
			printf("%d\n",a + 1);
			for(int i = 1;i <= a + 1;i++){
				for(int j = 1;j <= a + 1;j++) flag[i][j] = 0;
			}
			for(int i = 1;i <= a + 1;i++){
				cnt = 0;
				printf("%d",a);
				for(int j = 1;j <= n;j++){
					if(vis[j] == 2) continue;
					else if(vis[j] == 1){
						if(flag[pos[j]][i] == 0){
							flag[pos[j]][i]++;
							vis[j]++;
							printf(" %d",j);
							cnt++;
						}
					}
					else{
						printf(" %d",j);
						cnt++;
						vis[j]++;
						pos[j] = i;
					}
					if(cnt == a) break;
				}
				printf("\n");
			}
		}
		else printf("No\n");
	}
    return 0;
}

Measured memory_bytes: 7168
#include <iostream>

int main() {
	std::string in;
	int ans = 0;
	std::cin >> in;
	int length = in.size();
	for(int i = 0; i < length / 2; ++i) {
		if(in[i] != in[length - i - 1]) ans++;
	}
	std::cout << ans << std::endl;
}


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

a = [0] + list(map(int, input().split())) + [0]

s = 0



for i in range(n+1):
    s += abs(a[i+1] - a[i])

for i in range(1,n+1):
    if (a[i] - a[i-1])*(a[i+1] - a[i]) < 0:
        if abs(a[i] - a[i-1]) < abs(a[i+1] - a[i]):
            print(s - 2*abs(a[i] - a[i-1]))
        else:
            print(s - 2*abs(a[i+1] - a[i]))
    else :
        print(s)







Measured memory_bytes: 14048
from collections import deque
S = input()
T = input()

s = deque(list(S))
t = deque(list(T))

n = len(s)
for i in range(n):
    if t == s:
        print("Yes")
        break
    a = t.popleft()
    t.append(a)
else:
    print("No")


Measured memory_bytes: 3316
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
#define pb push_back
const int maxn = 200000+5;
string s[105];
int main()
{
    int n,l;
//    scanf("%d%d",&n,&l);
    cin>>n>>l;
    for (int i=1;i<=n;++i) {
        cin>>s[i];
    }
    sort(s+1,s+1+n);
    for (int i=1;i<=n;++i)
        cout<<s[i];
    cout<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <locale>
#include <list>
using namespace std;
#define FORN(i,m,n) for(ll i=m; i<ll(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
#define p_b(x) push_back(x)
#define m_p(a,b) make_pair(a,b)
typedef long long ll;
typedef long double ld;

ld get(int a, int b, int c, int d){
  return sqrt(((a-c)*(a-c))+((b-d)*(b-d)));
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n; cin>>n;
  vector<pair<int,int> > v(n);
  vector<int> path(n);
  vector<vector<ld> > dist(n,vector<ld>(n));
  FORN(i,0,n) {
    cin>>v[i].first>>v[i].second;
    path[i] = i;
  }
  FORN(i,0,n){
    FORN(j,0,n){
      dist[i][j] = get(v[i].first,v[i].second,v[j].first,v[j].second);
    }
  }
  ld sum = 0;
  do{
    ld tmp = 0;
    FORN(i,0,n-1){
      tmp += dist[path[i]][path[i+1]];
    }
    sum += tmp;
  }while(next_permutation(path.begin(),path.end()));
  int tot = 1;
  FORN(i,1,n+1) tot *= i;
  cout<<setprecision(10)<<fixed<<sum/tot<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){ 
  ll n,a,b;
  cin>>n>>a>>b;
  ll hp[n];
  rep(i, n){
    cin>>hp[i];}
 ll hpa[n];
  
  ll l=1;
  ll r=1000000000;
  ll ans=0;
  for(ll k=0;k<50;k++){
    ll p=(l+r)/2;
    ll cnt=0;
    rep(i, n){
     
      hpa[i]=max(hp[i]-b*p,(ll)0);
     cnt+=(hpa[i]+a-b-1)/(a-b);
    }
    if(cnt<=p){
      r=p;
    ans=p;}
    else{
      l=p;}
    }
  
    
    cout<<ans<<endl;
   
}

Measured memory_bytes: 1792
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll N,M,Q;
ll a[55], b[55], c[55], d[55];
ll ans = 0;

void dfs(vector<ll> v){
    if(v.size() == 0){
        rep(i,1,M+1){
            vector<ll> v2 = v;
            v2.push_back(i);
            dfs(v2);
        }
    }else if(v.size() < N){
        ll sz = v.size();
        ll cur = v[sz-1];
        rep(i,cur,M+1){
            vector<ll> v2 = v;
            v2.push_back(i);
            dfs(v2);
        }
    }else{
        ll res = 0;
        rep(i,0,Q){
            if(v[b[i]] - v[a[i]] == c[i]) res += d[i];
        }
        ans = max(ans, res);

    }

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;

    rep(i,0,Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    rep(i,0,Q){
        a[i]--; b[i]--;
    }
    vector<ll> v;
    dfs(v);
    print(ans);

}

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

int main(){
  vector<vector<int>> a(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a.at(i).at(j);
    }
  }
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int b;
    cin>>b;
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(b==a.at(j).at(k)) a.at(j).at(k)*=0;
      }
    }
  }
  if(a.at(0).at(0)==0&&a.at(0).at(1)==0&&a.at(0).at(2)==0) cout<<"Yes"<<endl;
  else if(a.at(1).at(0)==0&&a.at(1).at(1)==0&&a.at(1).at(2)==0) cout<<"Yes"<<endl;
  else if(a.at(2).at(0)==0&&a.at(2).at(1)==0&&a.at(2).at(2)==0) cout<<"Yes"<<endl;
  else if(a.at(0).at(0)==0&&a.at(1).at(0)==0&&a.at(2).at(0)==0) cout<<"Yes"<<endl;
  else if(a.at(0).at(1)==0&&a.at(1).at(1)==0&&a.at(2).at(1)==0) cout<<"Yes"<<endl;
  else if(a.at(0).at(2)==0&&a.at(1).at(2)==0&&a.at(2).at(2)==0) cout<<"Yes"<<endl;
  else if(a.at(0).at(0)==0&&a.at(1).at(1)==0&&a.at(2).at(2)==0) cout<<"Yes"<<endl;
  else if(a.at(0).at(2)==0&&a.at(1).at(1)==0&&a.at(2).at(0)==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3608
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		char op = sc.next().charAt(0);
		int b = sc.nextInt();
		if( op == '+' ){System.out.println(a+b);}
		else if( op == '-' ){System.out.println(a-b);}
                return;
	}
}

Measured memory_bytes: 9804
#include <iostream>

using namespace std;

int a[200000];

int main(){
	
	int n;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	long long int ans = 10000000000000000;
	
	long long int ans1 = 0;
	
	long long int sum = 0;
	
	for(int i = 0; i < n; i++){
		sum += a[i];
		if(i % 2 == 0){
			if(sum < 1){
				ans1 += 1 - sum;
				sum = 1;
			}
		}else{
			if(sum > -1){
				ans1 += sum + 1;
				sum = -1;
			}
		}
	}
	
	ans = min(ans1, ans);
	
	ans1 = 0;
	
	for(int i = 0; i < n; i++){
		a[i] *= -1;
	}
	sum = 0;
	
	for(int i = 0; i < n; i++){
		sum += a[i];
		if(i % 2 == 0){
			if(sum < 1){
				ans1 += 1 - sum;
				sum = 1;
			}
		}else{
			if(sum > -1){
				ans1 += sum + 1;
				sum = -1;
			}
		}
	}
	
	ans = min(ans1, ans);
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let (n, w) = get!(usize, usize);
    let mut w_base = 0;
    let mut ws = Vec::new();
    let mut vs = Vec::new();
    for i in 0..n {
        let (w, v) = get!(usize, usize);
        if i == 0 {
            w_base = w;
        }
        ws.push(w - w_base);
        vs.push(v);
    }

    let mut dp: Vec<Vec<Vec<i64>>> = vec![vec![vec![-1; n*3+1]; n+1]; n+1];
    dp[0][0][0] = 0;
    for i in 0..n {
        for j in 0..n {
            for k in 0..n*3+1 {
                if dp[i][j][k] == -1 { continue; }
                dp[i+1][j][k] = cmp::max(dp[i+1][j][k], dp[i][j][k]);
                if (j+1)*w_base + k + ws[i] <= w {
                    dp[i+1][j+1][k+ws[i]] = cmp::max(dp[i+1][j+1][k+ws[i]], dp[i][j][k] + (vs[i] as i64));
                }
            }
        }
    }
    let mut r = 0;
    for j in 0..n+1 {
        for k in 0..n*3+1 {
            r = cmp::max(r, dp[n][j][k]);
        }
    }
    println!("{}", r);
}

Measured memory_bytes: 28924
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int D = cin.ReadInt;
            int G = cin.ReadInt;

            int[] p = new int[D];
            int[] c = new int[D];
            for(int i = 0; i <D;i++){
                p[i] = cin.ReadInt;
                c[i] = cin.ReadInt;            
            }

            int ans = 1001;
            int score, solve;
            for(int bit = 0;bit <  (1<<D);bit++){
                score = 0;
                solve = 0;
                for(int i=0;i<D;i++){
                    if((bit & (1<<i)) > 0){
                        score += p[i] * (100* (i + 1)) + c[i];
                        solve += p[i];
                    }
                }
                if(score >= G){
                    ans = Min(ans, solve);
                }
                else{
                    for(int i=D-1;i>=0;i--){
                        if((bit & (1<<i)) > 1) continue;
                        for(int j = 0; j<p[i]; j++){
                            if(score >= G) break;
                            score += 100*(i+1);
                            solve += 1;
                        }
                    }
                    ans = Min(ans,solve);
                }
            }
            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 27752
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut, SubAssign, Range};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet, HashMap};
use std::fmt::{Display, Formatter, Error};
use std::hash::{Hash, Hasher};

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

fn main() {
    loop {
        let_all!(r: usize, c: usize);
        if r == 0 && c == 0{
            return
        }
        println!("{}", if r * c % 2 == 0{"yes"}else{"no"});
    }
}



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

int main()
{
	int n;
	scanf("%d",&n);
	ll ans = 0;
	for(int i = 1 ; i <= n ; i++)
	{
		if (i%3 != 0 && i%5 != 0) ans += i;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
using namespace std;
int main() {

	//D

	int v[52];
	int n, k;
	cin >> n >> k;
	int i;
	v[0] = 0;
	for (i = 1; i <= n; i++) {
		cin >> v[i];
	}
	v[n + 1] = 0;
	int Lj[52];
	int Rj[52];
	Lj[0] = 0;
	for (i = 1; i <= n+1; i++) {
		Lj[i] = Lj[i - 1] + v[i];
	}
	Rj[n + 1] = 0;
	for (i = n; i >= 0; i--) {
		Rj[i] = Rj[i + 1] + v[i];
	}
	int sum = 0;
	for (i = 0; i <= n + 1; i++)sum += v[i];
	int max = 0;

	priority_queue<int> equeue;
	int j;
	int krem, l, sumcheck;
	for (i = 0; i <= n; i++) {
		for (j = i + 1; j <= n + 1; j++) {
			if (i + (n + 1 - j) <= k) {//k回以下しか取ってはいけない．
				krem = k - (i + (n + 1 - j));
				sumcheck =  Lj[i] + Rj[j];
				for (l = 0; l <= i; l++) {
					equeue.push(-v[l]);
				}
				for (l = n + 1; l >= j; l--) {
					equeue.push(-v[l]);
				}
				for (l = 0; l < krem; l++) {
					if (equeue.size() > 0) {
						if (equeue.top() > 0) {
							sumcheck = sumcheck + equeue.top();
							equeue.pop();
						}
						else { break; }
					}
					else { break; }
				}
				if (sumcheck > max) {
					max = sumcheck;
					//cout << sumcheck << ' ' << i << ',' << j << endl;
				}
				while (equeue.size())equeue.pop();
			}
			
		}
	}
	cout << max << endl;
	return 0;

	//C
	/*int n, m;
	cin >> n >> m;
	int k,s ;
	int i, j;
	int comb[11][11];
	for (i = 0; i < 11; i++) {
		for (j = 0; j < 11; j++) {
			comb[i][j] = 0;
		}
	}
	for (i = 1; i <= m; i++) {
		cin >> k;
		for (j = 0; j < k; j++) {
			cin >> s;
			comb[i][s] = 1;
		}
	}
	int p[11];
	for (i = 1; i <= m; i++) {
		cin >> p[i];
	}
	int bin[11] = { 0,1,2,4,8,16,32,64,128,256,512 };
	int ii;
	int counter = 0;
	int bcheck;
	int bflag;
	for (i = 0; i < bin[n]*2; i++) {
		bflag = 0;
		for (ii = 1; ii <= m; ii++) {
			bcheck = 0;
			for (j = 1; j <= n; j++) {
				if ((i ^ bin[j]) != i + bin[j]) {
					bcheck = bcheck + comb[ii][j];
				}
			}
			if (bcheck % 2 != p[ii]) {
				bflag = 1;
			}

		}
		if (bflag == 0) {
			counter++;
		}
	}
	cout << counter << endl;
	return 0;
	*/




	//B
	/*string  s[100];
	//cin >> s >> t;
	int n;
	int p[100];
	cin >> n;
	int i;
	int num[100];
	for (i = 0; i < n; i++) {
		cin >> s[i] >> p[i];
		num[i] = i + 1;
	}

	string ss;
	int pp;
	int j;
	for (i = n-1; i > 0; i--) {
		for (j = 0; j < i; j++) {
			if (s[j] > s[j + 1]) {
				ss = s[j];
				s[j] = s[j + 1];
				s[j + 1] = ss;
				pp = p[j];
				p[j] = p[j + 1];
				p[j + 1] = pp;
				pp = num[j];
				num[j] = num[j + 1];
				num[j + 1] = pp;
			}
			else if((s[j] == s[j+1]) && (p[j] < p[j+1])){
				pp = p[j];
				p[j] = p[j + 1];
				p[j + 1] = pp;
				pp = num[j];
				num[j] = num[j + 1];
				num[j + 1] = pp;
			}
		}
	}
	for (i = 0; i < n; i++) {
		cout << num[i] << endl;
	}
	return 0;
	//if (s < t) {
	//	cout << s;
	//}
	//else {
	//	cout << t;
	//}
	return 0;
	*/

	//A

	/*int a, p;
	cin >> a >> p;
	p = p + a * 3;
	cout << (p - (p % 2)) / 2 << endl;
	return 0;*/



}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, a[55], b[55], c[55], dp[55][55][55][55]; bool vis[55][55][55][55];
int rec(int pos, int rem, int lv2, int lv1) {
	if (pos == n) return 0;
	if (vis[pos][rem][lv2][lv1]) return dp[pos][rem][lv2][lv1];
	int ret = -999999999;
	for (int i = 0; i <= rem; i++) {
		int res = rec(pos + 1, rem - i, i, lv2);
		int cs = c[pos];
		for (int j = 1; j <= 8; j++) {
			for (int k = 0; k <= j; k++) {
				int l = j - k;
				if (k <= lv2 && l <= lv1) {
					cs = max(cs, a[pos] * k + b[pos] * l);
				}
			}
		}
		ret = max(ret, res + cs);
	}
	vis[pos][rem][lv2][lv1] = true;
	return dp[pos][rem][lv2][lv1] = ret;
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
	int ret = -999999999;
	for (int i = 0; i <= m; i++) ret = max(ret, rec(0, m - i, i, 0));
	cout << ret << endl;
	return 0;
}

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

int solve(int x) {
  int ret = 1150;
  if(x <= 10) return ret;
  if(x <= 20) {
    ret += (x-10)*125;
    return ret;
  }else if(x <= 30) {
    ret += (x-20)*140 + 1250;
    return ret;
  }else{
    ret += 1250 + 1400 + (x-30)*160;
    return ret;
  }
}

int main() {
  int i;
  while(cin>>i, (i != -1))
    cout<<4280-solve(i)<<endl;
}

Measured memory_bytes: 0
S = input()
T = input()

used = []
res  = []

for i in range(len(S)):
    if S[i] not in used:
        used.append(S[i])
    res.append(used.index(S[i]))

#print(used)
#print(res)
used = []
ret = []

for i in range(len(T)):
    if T[i] not in used:
        used.append(T[i])
    ret.append(used.index(T[i]))

if res == ret:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 6832
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

int main() {
    string s, t;
    cin >> s >> t;
    map<char, char> m1, m2;
    for (int i = 0; i < s.length(); ++i) {
        if(m1[s[i]] == 0) m1[s[i]] = t[i];
        else if(m1[s[i]] != t[i]) {
            cout << "No" << "\n";
            return 0;
        }
    }
    for (int i = 0; i < s.length(); ++i) {
        if(m2[t[i]] == 0) m2[t[i]] = s[i];
        else if(m2[t[i]] != s[i]) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> graph[100002];
int cnt[100002],fis=-1;
vector<int> ds;
void dfs(int v,int p){
	cnt[v]=1;
	ds.push_back(v);
	if(v==n){
		fis=ds[(ds.size()+1)/2];
	}
	for(int i=0;i<graph[v].size();i++){
		int u=graph[v][i];
		if(u!=p){
			dfs(u,v);
			cnt[v]+=cnt[u];
		}
	}
	ds.pop_back();
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	dfs(1,0);
	cout<<((cnt[fis]*2<n)?"Fennec":"Snuke")<<endl;
	return 0;
}


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

int main(){
    char b;
    cin >> b;
    if(b=='A'){
        cout << "T";
    }
    else if(b=='T'){
        cout << "A";
    }
    else if(b=='C'){
        cout << "G";
    }
    else {
        cout << "C";
    }
    cout << endl;
    return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N;
int lo[6],hi[6];
ll dp[2][1<<6][1<<6][1<<6][10];
bool match0[6][10];
bool match1[6][10];
bool match2[6][10][10];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1){
    cin>>N;
    if(N==0)break;
    memset(match0,0,sizeof(match0)); memset(match1,0,sizeof(match1)); memset(match2,0,sizeof(match2));
    rep(i,N){
      cin>>lo[i]>>hi[i];
      repl(j,lo[i],hi[i]+1){
        if(j>=10){
          match0[i][j/10]=true;
          match2[i][j/10][j%10]=true;
        }
        if(j<10)match1[i][j]=true;
      }
    }
    int crt=0,nxt=1;
    rep(s0,1<<N)rep(s1,1<<N)rep(s2,1<<N)rep(j,10)dp[crt][s0][s1][s2][j]=0;
    dp[crt][1][1][0][0]=1;
    ll res=0;
    rep(i,N*2){
      rep(s0,1<<N)rep(s1,1<<N)rep(s2,1<<N)rep(j,10)dp[nxt][s0][s1][s2][j]=0;
      rep(s0,1<<N)rep(s1,1<<N)rep(s2,1<<N)rep(j,10){
        if(dp[crt][s0][s1][s2][j]==0)continue;
        rep(d,10){
          ll ns0=0,ns1=0,ns2=0;
          bool done=false;
          rep(l,N){
            if(((s0>>l)&1)&&match0[l][d]){
              ns2|=(1<<l);
            }
            if(((s1>>l)&1)&&match1[l][d]){
              if(l<N-1){
                ns0|=(1<<(l+1)); ns1|=(1<<(l+1));
              }else{
                done=true;
              }
            }
            if(((s2>>l)&1)&&match2[l][j][d]){
              if(l<N-1){
                ns0|=(1<<(l+1)); ns1|=(1<<(l+1));
              }else{
                done=true;
              }
            }
          }

          dp[nxt][ns0][ns1][ns2][d]+=dp[crt][s0][s1][s2][j];
          if(done)res+=dp[crt][s0][s1][s2][j];
        }
      }
      swap(crt,nxt);
    }
    cout<<res<<endl;
  }
  return 0;
}



Measured memory_bytes: 44064