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

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, s, n) for(int i = s; i < n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define FOREACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;

//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------


//function---------------------------------------------------------------------------------------------------------------------
int main() {
	string str;
	cin >> str;
	int n;
	int ans = 0;
	int str_size = str.size();
	scanf( "%d", &n );
	rep( i, n ) {
		string sch;
		cin >> sch;
		sch = sch + sch;
		rep( j, 10 ) {
			if ( sch.substr( j, str_size ) == str ) {
				ans++;
				break;
			}
		}
	}
	printf( "%d\n", ans );
	return 0;
}

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

int main() {
    long long int H;
    cin >> H;

    long long int N = 0;  // /2の回数

    while (H != 1) {
        H = H / 2;
        N++;
    }

    long long int cnt = 0;  //攻撃回数

    for (long long int i = 0; i < N + 1; i++) {
        cnt += pow(2, i);       
    }

     cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  cout << (n - 1) * 1LL * n / 2 << endl;
}


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

using namespace std;
int dp[100005][5];
int arr[100005];
int brr[100005];
int crr[100005];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>arr[i]>>brr[i]>>crr[i];
    }

    for(int i=1;i<=n;++i){
            dp[i][1] = max(dp[i-1][2], dp[i-1][3])+arr[i];
            dp[i][2] = max(dp[i-1][3], dp[i-1][1])+brr[i];
            dp[i][3] = max(dp[i-1][2], dp[i-1][1])+crr[i];
    }
    cout<<max(dp[n][1], max(dp[n][2], dp[n][3]));
    return 0;
}


Measured memory_bytes: 6664
#include <bits/stdc++.h>
#define INF 1e+9
using namespace std;

signed main(){
	int n,x,mi = INF;
	cin >> n >> x;
	for(int i = 0;i < n;i++){
		int a;
		cin >> a;
		x -= a;
		mi = min(a,mi);
	}
	cout << n + x / mi << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def update(index, value, bit):
  #print('update', index, value)
  while index < len(bit):
    #print('update', index)
    bit[index] += value
    index += index & -index
  #print('done')
    
    
def cumsum(index, bit):
  ans = 0
  while index > 0:
    #print('cumsum', index)
    ans += bit[index]
    index -= index & -index
  #print('done', ans)
  return ans
  

def main():
  N, q = [int(x) for x in input().split()]
  C = [int(x)-1 for x in input().split()]
  Q = []
  for i in range(q):
    l, r =  [int(x)-1 for x in input().split()]
    Q.append((i, l, r))
  Q.sort(key=lambda x: x[2])
  leftmost = [-1] * N
  bit = [0] * (N+1)
  prev = -1
  ans = [0] * q
  for i, l, r in Q:
    #print(i, r, l)
    to_update = {}
    for x in range(prev+1, r+1):
      to_update[C[x]] = x
    for c, x in to_update.items():
      if leftmost[c] >= 0:
        update(leftmost[c] + 1, -1, bit)
      leftmost[c] = x
      update(x + 1, 1, bit)
    prev = r
    #print(i, r, l)
    #print(C)
    #print([cumsum(i, bit) for i in range(1, N+1)])
    ans[i] = cumsum(r + 1, bit) - cumsum(l, bit)
    
  for a in ans:
    print(a)
  

main()

Measured memory_bytes: 229576
/*
??????-???_
  -????????????=- ???
  ''???-???"''-=?????????=- ???_
          "'rfi??????-???"''-?????????=-???_
           .i?????????i=??? "''???-???"''-?????????=-???_
           i?????????i.??????=- .   "'???-???"''-?????????-???_
          .i???=???i"'???-"_-=?????????=- .  "'???-???"''-?????????-???_
          i?????????i.         " ???"_-=?????????=-.,.??¨rfi??????-???"???|
         .i?????????i                  "  ???"  -???i??????i "'???-''???
         i??????=i                             "i??????i
        .i?????????i                             i??????i
        i?????????i                              i??????i
       .i?????????i                               i??????i
       i?????????i                               i??????i
      .i?????????i                               i???=i
     i????????????i                                 i??????i
     i????????????i                                 i??????i
     i????????????i                                i??????i
     i????????????i                                 i??????i
    i????????????i                                  i??????i
    i????????????i                                  i=??????i
   i????????????i                                  i?????????i
   i???????????????i                                  ?¨"""?¨
   ???????????????                         
*/

#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
vvi dp(1050, vi(1050));

int lcs(string x, string y) {
	int ans = 0;
	int m = x.length();
	int n = y.length();

	x = ' ' + x;
	y = ' ' + y;

	REP3(i, 1, m) {
		REP3(j, 1, n) {
			if (x[i] == y[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else if (dp[i - 1][j] >= dp[i][j - 1]) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = dp[i][j - 1];
			}

			ans = max(ans, dp[i][j]);
		}
	}

	return ans;
}

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

	int q;
	cin >> q;

	string str1, str2;
	REP(i, q) {
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << "\n";
	}
	return 0;
}

Measured memory_bytes: 7564
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <float.h>

using namespace std;
#define ll long long


int main(void){
    ll r,d,x;
    cin>>r>>d>>x;
    for(int i=0;i<10;i++){
        x=r*x-d;
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
typedef long long ll;
using namespace std;
int main() {
	int n;
	cin >> n;
	int v[25];
	int c[25];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int j = 0; j < n; j++) {
		cin >> c[j];
	}
	
	
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (v[i] > c[i]) {
			ans += v[i] - c[i];
		}

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

Measured memory_bytes: 256
//Author: Rahul Purohit

#include<bits/stdc++.h>
#define vi vector<int>
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define ll  long long int
#define pi pair<ll,ll>
#define f first
#define mp make_pair
#define mod 1000000007
#define s second
#define pb push_back
#define mp make_pair
#define N 100001
using namespace std;
int gcd(int a, int b)
{
	if(b==0)
		return a;
	else
		return (b,a%b);
}
/*ll isp[N]={1};
void sieve(int n)
{
	isp[0]=isp[1]=0;
	for(int i=2;i<=n;i++)
	{
		if(isp[i]==1)
		{
			for(int j=i*i;j<=n;j+=i)
			{
				isp[j]==0;
			}
		}
	}
}*/
ll pow(int x,int  y,int m)
{
	ll ans=1;
	while(y!=0)
	{
		if(y%2==1)
		{
			ans=(ans*x)%m;
		}
		x=(x*x)%m;
		y/=2;
	}
	return ans;
}
template <class x>
void swap(x &a,x &b)
{
	x tp;
	tp=a;
	a=b;
	b=tp;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

    string a;
    ll n,q;
    cin>>n>>q;
    cin>>a;
    ll x,y;
    ll ar[n]={0};
    rep(i,1,n+1)
    {
        if(a[i]=='C'&&a[i-1]=='A')
        {
            ar[i]=ar[i-1]+1;
        }
        else
        {
            ar[i]=ar[i-1];
        }
    }
    /*rep(i,0,n)
    {
        cout<<ar[i]<<endl;
    }*/
    while(q--)
    {
        cin>>x>>y;
        cout<<ar[y-1]-ar[x-1]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1872
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main () {
    int side[3];
    int rectangle=0;
    int lozenges=0;
    while(scanf("%d,%d,%d",&side[0],&side[1],&side[2])!=EOF){
        
        
        if(side[0]*side[0]+side[1]*side[1]==side[2]*side[2]){
            rectangle++;
        }else if(side[0]==side[1]){
            lozenges++;
        }
        
    }
    
    cout<<rectangle<<endl<<lozenges<<endl;
    return 0;
}

Measured memory_bytes: 1208
def f(n):
    ret = 0
    for i in range(40):
        mod = 2**(i+1)

        num = n//mod
        rem = n%mod

        ct = num*(mod//2)
        ct += max(0, rem - mod//2 + 1)
        if ct%2 == 1:
            ret |= (1<<i)

    return ret

def main():
    a,b = map(int,input().split())
    if a > 0:
        a -= 1
    return f(b)^f(a)

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;
}

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

Measured memory_bytes: 256
def main():
    count = int(input())
    num_str = input().split()
    num_list = []
    num_list = [int(s, 10) for s in num_str]
    sum = 0
    for i in range(count):
        sum += num_list[i]
    print(sum - count)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
ll gcd(ll a, ll b){
    return b != 0 ? gcd(b, a%b) : a;
}
int main(){

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

    }
    ll min_hp = hp[0];
    for(int i = 1; i < n; i++){
        min_hp = gcd(min_hp, hp[i]);
    }
    cout << min_hp << endl;
    return 0;
}

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

int root[100010]; //root[i]=i's parent
ll element[100010];

void init(int n){
  for(int i=0;i<n;i++) root[i]=i,element[i]=1;
}//reset
int find(int x){
  if(root[x]==x){
    return x;
  }
  else{
    return root[x]=find(root[x]);
  }
}//search x's parent
bool same(int x,int y){
  return find(x)==find(y);
}
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  root[x]=y;
  element[y]+=element[x];
}//x->y

int main(){
  ll n,m;
  cin>>n>>m;
  init(n);
  int edge[m][2];
  for(int i=m-1;i>=0;i--){
    cin>>edge[i][0]>>edge[i][1];
    edge[i][0]--;
    edge[i][1]--;
  }
  ll ans[m];
  ans[0]=0;
  for(int i=0;i<m-1;i++){
    if(same(edge[i][0],edge[i][1])==true){
      ans[i+1]=ans[i];
      /*for(int j=0;j<n;j++){
        cout<<root[j]<<" ";
      }
      cout<<ans[i+1]<<" ";
      cout<<endl;*/
      continue;
    }
    ans[i+1]=ans[i]+element[find(edge[i][0])]*element[find(edge[i][1])];
    unite(edge[i][0],edge[i][1]);
    /*for(int j=0;j<n;j++){
      cout<<root[j]<<" ";
    }
    cout<<ans[i+1]<<" ";
    cout<<endl;*/
  }
  for(int i=m-1;i>=0;i--){
    cout<<(n*(n-1))/2-ans[i]<<endl;
  }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;



signed main(){
	int N,K;
	cin>>N>>K;
	if(K==1){
		cout<<0<<endl;
		return 0;
	}
	map<int,int>mp;
	mp[0]++;
	int ans = 0;
	int now = 0;
	vector<int>memo(N,-1);
	REP(i,N){
		if(i-K>=0){
			mp[memo[i-K]]--;
		}else if(i-K==-1)mp[0]--;
		int t;
		cin>>t;
		now+=t-1+K;
		now%=K;
		ans+=mp[now];
		mp[now]++;
		memo[i]=now;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 14336
#include<stdio.h>
#include<iostream>
 
using namespace std;
 
int main(void){
  
 int a,b,sum;
  
  cin>>a>>b;
  
  if(a==b){
    sum = 2 * a;
  }else if(a>b){
    sum = a + a - 1;
  }else if(b>a){
    sum = b + b - 1;
  }
  
  cout<<sum<<endl;
  
  
  return 0;
  
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main()
{
       int a, b;

       scanf("%d %d", &a, &b);

       if( 1 <= a && a <= 9 && 1 <= b && b <=9 )
       {
              printf("%d\n", a * b );
       }
       else 
              printf("-1\n");
       return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

//int k;
//string s;
signed main(){
	acc_io;
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double A,B,C,d;
	double x1,y1,x2,y2;
	x1=a*sin(30*(h*60+m)*PI/(180*60));
	y1=a*cos(30*(h*60+m)*PI/(180*60));
	x2=b*sin(m*6*PI/180);
	y2=b*cos(m*6*PI/180);

	x1=x2-x1;
	y1=y2-y1;
	double ans;
	ans=sqrt(x1*x1+y1*y1);
	cout << fixed << setprecision(14) << ans << endl;	
//	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4136
a = input().split()
a = [int(a[i]) for i in range(3)]

if (a[0] == 7 and a[1] == 5 and a[2] == 5) \
    or (a[0] == 5 and a[1] == 7 and a[2] == 5) \
    or (a[0] == 5 and a[1] == 5 and a[2] == 7):
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
ll n,k,a[MAXN];
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    sort(a+1,a+n+1);
    ll last=0,sum=0;
    for(ll i=1;i<=n-1;i++)
    {
        sum+=a[i];
        if(sum*2<a[i+1]) last=i;
    }
    printf("%lld\n",n-last);
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int a,b;
int main() {
  cin >> a >> b;
  if(a+b==15) {
    cout << '+' << '\n';
  }
  else if(a*b==15) {
    cout << '*' << '\n';
  }
  else {
    cout << 'x' << '\n';
  }
  return(0);
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = a[i] - (i + 1)
a = sorted(a)
b = a[n // 2]
total = 0
for i in range(n):
    total += abs(a[i] - b)
print(total)


Measured memory_bytes: 25196
def naiive(xs)
  n = xs.size
  cx = 0
  while true
    m = xs.max
    break if m <= n - 1
    xs[xs.index m] -= n + 1
    n.times do |i|
      xs[i] += 1
    end
    cx += 1
  end
  cx
end

K = gets.to_i
N = 50
A = N - 1 + K / N
xs = [A] * N
rest = K % N

rest.times do |i|
  xs[i] += N
  N.times do |j|
    next if i == j
    xs[j] -= 1
  end
end

p N
puts xs.join(' ')
# p naiive(xs)


Measured memory_bytes: 3836
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const long long INFL = 2e18;
const int MOD = 1000000007;
const long long MAX = 1000100;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2;i < MAX;i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
	COMinit();
	int s;
	cin >> s;

	int ans = 0;

	for(int i = 1;i <= 2000;i++){
		//何個に分割するか決め打つ.
		if(s - 3 * i < 0){
			break;
		}

		int rem = s - 3 * i;

		ans += COM(i+rem-1,rem);
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 27072
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define TEN5 100000 //10^5
#define TEN9 1000000000 //10^9
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    string s;
    cin >> s;
    s = s.substr(0, s.length() - 1);
    while(s.length() != 1) {
        if (s.length() % 2 == 0) {
            int flag = 0;
            rep(i,s.length()/2) {
                if (s[i] != s[s.length()/2 + i])
                    flag = 1;
            }
            if (flag == 0) {
                break;
            }
        }
        s = s.substr(0, s.length() - 1);
    }

    cout << s.length() << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

ll n, m;
ll root[500000];
ll sz[500000];
vector<ll> ans;
vector<pii> v;
ll res = 0;

int Root(int x)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x]);
}

void Merge(int a, int b)
{
    a = Root(a);
    b = Root(b);
    if (a == b) return;
    if (sz[a] <= sz[b])
    {
        res += sz[a] * sz[b];
        sz[b] += sz[a];
        root[a] = b;
    }
    else
    {
        res += sz[a] * sz[b];
        sz[a] += sz[b];
        root[b] = a;
    }
}

signed main()
{
    srand(time(NULL));
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b, k;
    cin >> a >> b >> k;
    cout << min(k, b / a);
}


Measured memory_bytes: 256
let counting_sort a b k n =
  let c = Array.make (k + 1) 0 in
  Array.iter (fun e -> c.(e) <- c.(e) + 1) a;
  for i = 1 to k do
    c.(i) <- c.(i) + c.(i-1)
  done;
  for i = n - 1 downto 0 do
    c.(a.(i)) <- c.(a.(i)) - 1;
    b.(c.(a.(i))) <- a.(i);
  done

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  let b = Array.make n 0 in
  counting_sort a b 10000 n;
  print_int b.(0);
  for i = 1 to n - 1 do
    print_string " "; print_int b.(i);
  done;
  print_newline ()

Measured memory_bytes: 36124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x,ans;
void solve(ll a,ll b){
    if (a<b) swap(a,b);
    ans+=a/b*b*2;
    a%=b;
    if (a==0) return void(ans-=b);
    solve(b,a);
}
int main()
{
    cin>>n>>x;
    if (x>n-x) x=n-x;
    ans=n;
    solve(x,n-x);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n;
	cin>>n;
	
	vector<int> v(n);
    vector<int> ans;
	for(int i=0;i<n;i++)
	{
	  cin>>v[i];
       if(v[i]==i+1)
       {
       	 ans.push_back(i+1);
       }
	}
    int at=0;
	 for(int i=0;i<n;i++)
	 {
	 	if(v[i]==i+1)
	 	{   
	 		at++;
	 		if(i+1<n&& v[i+1]==i+2)
	 		{
	 			i++;
	 		}
	 	}
	 }

	 cout<<at<<"\n";
}

Measured memory_bytes: 1276
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll R, C, K, r[212345], c[212345], v[212345];
ll memo[4][3123][3123];

ll item[3123][3123];

ll dp(ll rr, ll cc, ll i) {
	if (memo[i][rr][cc] != -1) return memo[i][rr][cc];
	if (rr == 0 && cc == 0) {
		if (i == 0) return memo[i][rr][cc] = 0;
		else return memo[i][rr][cc] = item[rr][cc];
	}
	ll ret = 1ll << 63;
	if (rr > 0) ret = max(ret, dp(rr - 1, cc, 3));
	if (cc > 0) ret = max(ret, dp(rr, cc - 1, i));
	if (i) {
		if (rr > 0) ret = max(ret, dp(rr - 1, cc, 3) + item[rr][cc]);
		if (cc > 0) ret = max(ret, dp(rr, cc - 1, i - 1) + item[rr][cc]);
	}

	return memo[i][rr][cc] = ret;
}

int main() {

	memset(memo, 0xff, sizeof(memo));
	cin >> R >> C >> K;
	rep(i, K) cin >> r[i] >> c[i] >> v[i];
	rep(i, K) item[r[i] - 1][c[i] - 1] = v[i];

	cout << dp(R - 1, C - 1, 3) << endl;

	return 0;
}


Measured memory_bytes: 386244
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        int tmp = 4*i + 7*j;
        if (N == tmp) {
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21844
from itertools import chain,product

N = int(input())

P = list(chain((0,), map(lambda x: int(x)-1,input().split())))
X = list(map(int,input().split()))

L = [list() for _ in range(N)]

debug = [None]*N

for i in reversed(range(N)):
  p = P[i]
  l = L[i]

  x = X[i]

  # len(l) < 10のとき全探索、それ以上はDP
  if len(l) < 10:
    m = -1
    for s in product(*l):
      n = sum(s)
      if n <= x:
        m = max(n,m)
    if m == -1:
      print('IMPOSSIBLE')
      exit()
    m = sum(chain.from_iterable(l)) - m
  else:
    offset = sum(min(t) for t in l)
    x -= offset
    if x < 0:
      print('IMPOSSIBLE')
      exit()
    dp = [False]*(x+1)
    dp[0] = True
    s = 0
    for a,b in l:
      d = abs(a-b)
      s += d
      for j in reversed(range(x-d+1)):
        dp[j+d] = dp[j+d] or dp[j]
    m = x
    while not dp[m]:
      m -= 1
    m = s-m
    m += offset
    x += offset

  debug[i] = (x,m)
  L[p].append((x,m))
  L[i] = None

print('POSSIBLE')



Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  char n;
  cin >> n ;
  
  pri(char(n+1));









  //ll n=10;

  //ll f = 1;
  //rep1(i,n){
  //  f*=i;
  //  f%=mod;
  //}
  //ll fn = f;
  //ll inv = mod_pow(f, mod - 2, mod);
  //ll invs[n+1];
  //invs[n] = inv;
  //for(ll i = n;i>1;i--){
  //  inv *= i;
  //  inv %= mod;
  //  invs[i - 1] = inv;
  //}
  //rep(i,n){
  //  pri(invs[i]);
  //}

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,j,k;
  string s;
  cin>>n>>s;
  vector<int> x(n+1);
  for(j=1;j<=n;j++){
    if(s.at(j-1)=='o') x.at(j)=1;
    else if(s.at(j-1)=='x') x.at(j)=-1;
  }
  vector<int> s1_={1,1,-1,-1};
  vector<int> s2_={1,-1,1,-1};
  for(k=0;k<4;k++){
    vector<int> y(n+1);
    y.at(1)=s1_.at(k);
    y.at(2)=s2_.at(k);
    y.at(0)=y.at(2)*y.at(1)*x.at(1);
    for(j=3;j<=n;j++) y.at(j)=y.at(j-2)*y.at(j-1)*x.at(j-1);
    if(y.at(0)==y.at(n)&&y.at(1)==y.at(n-1)*y.at(n)*x.at(n)){
      for(j=1;j<=n;j++){
        if(y.at(j)==1) cout<<'S';
        else if(y.at(j)==-1) cout<<'W';
      }
      cout<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 4256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	int x = read.to!int;
	
	int[] ls;
	foreach(i; 0 .. n) ls ~= read.to!int;
	
	int sum;
	int ans;
	foreach(l; ls){
		if(sum <= x) ans += 1;
		sum += l; 
	}
	if(sum <= x) ans += 1;
	
	ans.writeln;
}


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

int main() {
    long long n;
    long long ans=1;
    int mod = 1000000007;

    cin >> n;
    
    for (int i = 1; i <= n; i++){
        ans= (ans*i)%mod;
    }
    cout << ans << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int 
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
 
 
int main(){
    fast;
    string a,b; cin >> a >> b;
    int n1 = a.size();
    int n2 = b.size();
    a= "*" + a;
    b = "*" + b;
    int dp[n1+1][n2+1];
    memset(dp,0,sizeof(dp));
    string ans = "";
    for(int i=1 ; i<n1+1 ; i++){
        for(int j=1 ; j<n2+1 ; j++){
            if(a[i]==b[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i= n1,j = n2;
    while(i>=1 && j>=1){
        if(a[i]==b[j] && dp[i-1][j-1]+1  == dp[i][j]){
            ans+=a[i];
            i--,j--;
        }
        else if(dp[i-1][j] == dp[i][j])
                i--;
        else if(dp[i][j-1] == dp[i][j])
                j--;
            
            
 
    }
    reverse(all(ans));
    cout << ans << endl;
}


Measured memory_bytes: 35456
#include<iostream>
using namespace std;
long long ans=0;
long long a;
int main(){
	cin>>a;
	if(a % 2 == 1){
		cout<<0;
		return 0;
	}
	else{
		a/=10;
		ans+=a;
		while(a > 0){
			a/=5;
			ans+=a;
		}
		cout<<ans;
		return 0;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long int
#define tc int t; cin>>t; while(t--)
#define inn ll arr[n]; for(int i=0;i<n;i++) cin>>arr[i];
#define fora(i,n); for(ll i=0;i<n;i++)
#define forb(i,a,n); for(int i=a;i<n;i++)
#define mod 1000000007

int main()
{

//THIS CODE IS CREATED BY ANSHJAIN18
ll n;
cin>>n;
pair<ll,ll> arr[n];
fora(i,n) {
cin>>arr[i].first;
arr[i].second=i; }
sort(arr,arr+n);
ll cnt=1;
ll idx=arr[0].second;
for(ll i=1;i<n;i++)
{
    if(arr[i].second<idx)
    {
        cnt++;
        idx=arr[i].second;
    }


}
cout<<cnt<<endl;


return 0; }

Measured memory_bytes: 3328
function readline_STDIN()
    return Base.readline(Base.STDIN)
end

function read_length_edges(stdin)
    return Base.parse.(Base.split(stdin))
end

function exawizards2019_A(A::Base.Int64, B::Base.Int64, C::Base.Int64)

    if Base.isequal(A, B) && Base.isequal(B, C)
        return "Yes"
    else
        return "No"
    end

end

A, B, C = read_length_edges(readline_STDIN())
Base.println(Base.STDOUT, Main.exawizards2019_A(A, B, C))

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

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

  valarray<int> re(a);
  for (auto&& e : re) cin >> e;

  valarray<int> mw(b);
  for (auto&& e : mw) cin >> e;

  valarray<int> ans(m);
  for (auto&& e : ans) {
    int x, y, c;
    cin >> x >> y >> c;
    e = re[x - 1] + mw[y - 1] - c;
  }

  cout << min(ans.min(), re.min() + mw.min()) << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
string s,t;
int F[3005][3005],i,j,n,N;
char A[30005];
void backtrack(int i, int j) {
    if (i == 0 || j == 0) return ;
    if (s[i-1] == t[j-1]) {
        A[++N]=s[i-1];
        backtrack(i-1,j-1);
    } else {
        if (F[i][j-1] > F[i-1][j]) backtrack(i,j-1);
        else backtrack(i-1,j);
    }
}
int main()
{
    //freopen("LCS.inp","r",stdin);
    cin >> s;
    cin >> t;
    int n=s.size();
    int m=t.size();
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
            if (s[i-1] == t[j-1]) {
                F[i][j]=F[i-1][j-1]+1;
            } else {
                F[i][j]=max(F[i-1][j], F[i][j-1]);
            }
        }
    }
    backtrack(s.size(),t.size());
    for (i = N; i > 0; i--) {
        cout << A[i];
    }
    return 0;
}


Measured memory_bytes: 35456
n,q = map(int,input().split())
L = [0]*(n+1)
graph = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
for i in range(q):
    a,b = map(int,input().split())
    L[a] += b
q = [(1,0)]
while len(q) > 0:
    c = q.pop()
    x, par = c[0], c[1]
    L[x] += L[par]
    for child in graph[x]:
        if par == child:
            continue
        q.append((child,x))
print(' '.join(map(str,L[1:])))

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

int main(){
	int a, b;

	while(1){
	  cin >> a >> b;
	  if( a == 0 && b == 0 ) break;

	  for( int i = 0; i < a; i++){
		for( int j = 0; j < b; j++){
			cout << "#";
		}
		cout << endl;
	 }
	 cout << endl;
        }

return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define vl vector<ll>
#define vi vector<int>
#define vli vector <pair <ll, int> >
#define vll vector <pair <ll, ll> >
#define vii vector <pair <int, int> >
using namespace std;

const ll MAXN = 1e5 + 100;
ll n, m;
string a, b;

map < ll, char> mp;

string nans1, nans2, mans1, mans2;

int gcd(int a, int b){
    while(b){
        a %= b;
        swap(a, b);
    }
    return a;
}

long long lcm(long a, long b){
    return a / gcd(a, b) * b;
}

int main(){

mal

cin >> n >> m;
cin >> a >> b;


if(n == 1 || m == 1 || a[0] != b[0]) {cout << -1;return 0;}

ll l = lcm(n, m);

for(int i = 1; i < n; ++i) {

    mp[i * (l / n) + 1] = 1;

}

for(int i = 1; i < m; ++i) {

    ll k = i * (l / m) + 1;

    if(mp[k]) {

        if(a[(k - 1) / (l / n)] != b[i]) {cout << -1;return 0;}

    }

}

cout << l;

return 0;
}


Measured memory_bytes: 10880
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;

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

  vector<ll> a(3*n+10);

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

  // 昇順に処理する
  priority_queue< ll, vector<ll>, greater<ll> > que;
  ll tmp = 0;

  for (int i = 0; i < n; i++) {
    que.push(a[i]);
    tmp += a[i];
  }

  vector<ll> memo_a(3*n+5);
  memo_a[n-1] = tmp;

  for (int k = n; k <= 2*n; k++) {
    que.push(a[k]);
    tmp += a[k];
    tmp -= que.top();
    memo_a[k] = tmp;
    que.pop();
  }


  // 降順に処理する
  priority_queue<ll> que2;
  tmp = 0;

  for (int i = 3*n-1; i >= 2*n; i--) {
    que2.push(a[i]);
    tmp += a[i];
  }

  vector<ll> memo_b(3*n+5);
  memo_b[2*n] = tmp;

  for (int k = 2*n-1; k >= n-1; k--) {
    que2.push(a[k]);
    tmp += a[k];
    tmp -= que2.top();
    memo_b[k] = tmp;
    que2.pop();
  }

  ll ans = -1e18;
  
  for (int k = n-1; k < 2*n; k++) {
    ans = max(ans, memo_a[k] - memo_b[k+1]);
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 8948
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int x = in.nextInt();
            out.println(x >= a && x <= a + b ? "YES" : "NO");
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufLength == -1)
                throw new InputMismatchException();
            if (bufPointer >= bufLength) {
                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (bufLength == -1)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public long nextLong() {
            long n = 0;

            boolean minus = false;
            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || b > '9')
                throw new NumberFormatException();

            while (true) {
                if (b >= '0' && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (isSpaceChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 21332
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
#define INF 2147483647
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
int main(){
    int n,h,w;
    cin>>n>>h>>w;
    int a[1111],b[1111];
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    int co=0;
    for(int i=0;i<n;i++){
        if(a[i]>=h && b[i]>=w)co++;
    }
    cout<<co<<endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
const int INF=0x3f3f3f3f;
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
struct edge{
	int to,nxt,cap,flow;
}e[30005];
int a[105],last[105],cur[105],dis[105],S,T,n,cnt=1;
ll min(ll x,ll y) {return x<y?x:y;}
void insert(int u,int v,int w)
{
	e[++cnt]=(edge){v,last[u],w,0};
	last[u]=cnt;
}
int bfs()
{
	queue<int> q;
	for(int i=1;i<=n+2;i++) dis[i]=INF;
	dis[S]=0;q.push(S);
	while(q.size())
	{
		int x=q.front();q.pop();
		for(int i=last[x];i;i=e[i].nxt)
		if(e[i].cap>e[i].flow&&dis[e[i].to]==INF)
		{
			dis[e[i].to]=dis[x]+1;
			q.push(e[i].to);
		}
	}
	return dis[T]!=INF;
}
ll dfs(int x,ll low)
{
	if(x==T||low==0) return low;
	ll ret=0,st;
	for(int &i=cur[x];i;i=e[i].nxt)
	{
		cur[x]=i;
		if(dis[e[i].to]==dis[x]+1&&(st=dfs(e[i].to,min(low,e[i].cap-e[i].flow)))>0)
		{
			ret+=st,low-=st;
			e[i].flow+=st,e[i^1].flow-=st;
			if(!low) break;
		}
	}
	return ret;
}
ll dinic()
{
	ll ret=0;
	while(bfs())
	{
		for(int i=1;i<=n+2;i++) cur[i]=last[i];
		ret+=dfs(S,INF);
	}
	return ret;
}
ll ans;
int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	S=n+1;T=n+2; 
	for(int i=1;i<=n;i++)
	{
		if(a[i]>0) ans+=a[i],insert(i,T,a[i]),insert(T,i,0);
		else insert(S,i,-a[i]),insert(i,S,0);
	}
	for(int i=1;i<n;i++)
		for(int j=2;j<=n/i;j++)
		{
			insert(i,i*j,a[i*j]);
			insert(i*j,i,0);
		}
	ans-=dinic();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
program ABC_093_A_abcofABC
   implicit none
   character(3) a
   read(*, *) a
   if(a == 'abc') then
       write(*, *) 'Yes'
   else if(a == 'acb') then
       write(*, *) 'Yes'
   else if(a == 'bac') then
       write(*, *) 'Yes'
   else if(a == 'bca') then
       write(*, *) 'Yes'
   else if(a == 'cab') then
       write(*, *) 'Yes'
   else if(a == 'cba') then
       write(*, *) 'Yes'
   else
       write(*, *) 'No'
   end if
end program ABC_093_A_abcofABC

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

int main(){
  int w,mo;
  while(cin >> w,w!=-1){
  	mo=1150;
  	if(w>10){
  		w-=10;
  		if(w>10){
  			mo+=1250;
  			w-=10;
  			if(w>10){
  				mo+=1400;
  				w-=10;
  				if(w>0) mo+=w*160;
  			}
  			else{
  				mo+=w*140;
  			}
  		}
  		else{
  			mo+=w*125;
  		}
  	}
  	cout << 4280-mo << endl;
  	}
	return 0;
}

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef long long ll;
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;

ll dp[51][5001];

void Main() {
  int N, A;
  scanf("%d%d", &N, &A);
  vi X(N);
  rep(i, N) {
    scanf("%d", &X[i]);
    X[i] -= A;
  }

  dp[0][2500] = 1;

  rep(i, N) rep(s, 5000) if (dp[i][s]) {
    dp[i+1][s] += dp[i][s];
    dp[i+1][s+X[i]] += dp[i][s];
  }
  ll ans = dp[N][2500]-1;
  _p("%lld\n", ans);
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 896
n = int(input())
A = [0]*10**7

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            A[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1

print(*A[1:n+1],sep='\n')

Measured memory_bytes: 87592
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        sc.close();
        boolean sa = false;
        boolean sine = false;
        if(n % 2 != 0){
            System.out.println("No");
            sine = true;
        }else{
            int[] a = new int[n / 2];
            int[] b = new int[n / 2];
            for(int i = 0 ; i < n / 2 ; i++ ){
                a[i] = s.charAt(i);
                b[i] = s.charAt(i + n / 2);
                if(a[i] != b[i]){
                    sa = true;
                }
            }
        }
        if(sa == true){
            System.out.println("No");
        }else if(sine == false){
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 35660