akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
        	BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        	int n = Integer.parseInt( kb.readLine( ) );
			String[] str = kb.readLine( ).split( " " );
			int[] S = new int[ n ];
			for( int i=0; i<n; i++ ) {
				S[i] = Integer.parseInt( str[i] );
			}

        	int q = Integer.parseInt( kb.readLine( ) );
			str = kb.readLine( ).split( " " );
			int[] T = new int[ q ];
			for( int i=0; i<q; i++ ) {
				T[i] = Integer.parseInt( str[i] );
			}

			int cnt = 0;
            int low, high, middle;
			for( int i=0; i<q; i++ ) {
				low = 0;
				high = n-1;
				middle = n/2;
				while( low <= high ) {
					if( T[i] == S[middle] ) {
					cnt++;
					break;
					} else if( T[i] < S[middle] ) {
						high = middle - 1;
					} else {
						low = middle + 1;
					}
					middle = ( low+high )/2;
				}               
			}
			System.out.println( cnt );

        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

Measured memory_bytes: 42472
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n, r;
	cin >> n >> r;
	if (n >= 10) cout << r << endl;
	else cout << r + 100 * (10 - n) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,b;
	char op;
	while(scanf("%d %s %d",&a,&op,&b)==3){
		if(op == '?') break;
	switch(op){
	case '+' :{
		printf("%d\n",a+b);
		break;
			  }
	case '-' :{
		printf("%d\n",a-b);
		break;
			  }
	case '*' :{
		printf("%d\n",a*b);
		break;}
	case '/' :{
		printf("%d\n",a/b);
		break;
			  }
	}
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
#define ll long long
ll x,y,i,j;
int main ()
{
   cin>>x>>y;
   for (i=0;i<=100;++i)
   {
       for (j=0;j<=100;++j)
       {
           if (i*2+j*4==y && i+j==x)
           {
               cout<<"Yes\n";
               return 0;
           }
       }
   }
   cout<<"No\n";
   return 0;
}



Measured memory_bytes: 3620
N, M = map(int, input().split())
P = []
S = []
for i in range(M):
	p, s = input().split()
	P.append(int(p))
	S.append(s)

collect=[0]*N
miss = [0]*N

for a in range(M):
	if S[a] == "AC":
		if collect[P[a]-1] != 1:
			collect[P[a]-1] += 1
	else:
		if collect[P[a]-1] != 1:
			miss[P[a]-1] += 1

AC = sum(collect)
WA = 0
for a in range(N):
	if collect[a] == 1:
		WA += miss[a]


print(AC, WA)

Measured memory_bytes: 15320
numerosSTR = input().split(" ")
for i in numerosSTR:
    a = int(numerosSTR[0])
    b = int(numerosSTR[1])
    c = int(numerosSTR[2])
minimos=[a,b,c]
k = min(minimos)
minimos.pop(minimos.index(k))
print(k+min(minimos))
    

Measured memory_bytes: 2940
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(N-1):
    if a[i]+a[i+1]>x:
        diff=a[i]+a[i+1]-x
        ans+=diff
        a[i+1]-=min(diff,a[i+1])
print(ans)


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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl

int N, X;
vi s(N);

// 挿入DP
/*
N通りの順列をすべて調べ上げる DP として代表的なのは

bitDP (今回は制約が N≤200 なので無理)
挿入 DP
箱根駅伝みたいな DP

*/

int main() {
  int N, X;
  cin >> N >> X;

  vi s(N, 0);
  FOR(i, 0, N) cin >> s[i];

  sort(s.begin(), s.end());
  vector<vl> dp(N + 1, vl(X + 1, 0));
  //値Xに対して、先頭からi文字使った時に表れるあまりの総和
  // dp[ i ][ x ] := スタート時点での整数が x であるときに、最初の i
  // 個についての順列すべてを考えたときに得られる値の総和
  // dp[ 0 ][ x ] = x スタート時点の整数Xに対して最初の0個について考える

  // dp[ i + 1 ][ x ] = dp[ i ][ x % s[ i ]] + i × dp[ i ][ x ]
  // スタートがx%s[i]の状態で残りi-1個の順列全てでの総和 +
  // スタートがxでi-1の順列全てでの総和

  ll MOD = 1000000007;

  FOR(x, 0, X + 1) dp[0][x] = x;

  FOR(length, 1, N + 1) {  //もらうDP
    FOR(x, 0, X + 1) {
      // DEBUG(x);
      dp[length][x] +=
          dp[length - 1][x % s[length - 1]] + (length - 1) * dp[length - 1][x];
      dp[length][x] %= MOD;
    }
  }

  cout << dp[N][X] << endl;
}



Measured memory_bytes: 158592
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<"### "<<x<<endl;
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
inline int read(){
    int x=0;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}

int main(){
	int n;
	scanf("%d",&n);
	
	cout<<(3*n*n);





}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int count_digits(int x){
  int res = 0;
  while(x > 0){
    res++;
    x /= 10;
  }
  return res;
}
int main(){
  ll n, m;
  cin >> n >> m;
  vector<pair<pair<ll, ll>, ll> > p(m);
  rep(i, m) {
    cin >> p[i].first.first >> p[i].first.second;
    p[i].second = i;
  }
  vector<pair<ll, string>> ans(m);
  sort(p.begin(), p.end());
  ll cur = p[0].first.first;
  ll count = 1;
  rep(i, m){
    ll pref = p[i].first.first;
    ll year = p[i].first.second;
    if(cur != pref){
      count = 1;
      cur = pref;
    }
    int digits = count_digits(pref);
    string id = string(max(6 - digits, 0), '0') + to_string(pref);
    digits = count_digits(count);
    id += string(max(6 - digits, 0), '0') + to_string(count);
    ans[i] = make_pair(p[i].second, id);
    count++;
  }
  sort(ans.begin(), ans.end());
  rep(i, m){
    cout << ans[i].second << endl;
  }
}


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    
	string s, t;
    cin >> s >> t;
    int ans = 0;
    
    for (int i = 0; i < s.length(); i++)
            if (s[i] != t[i])
                    ans++;
    cout << ans << endl;
}


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

#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
//map<int, int>::iterator itr; 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    while(t--){
        long a,v,b,w,p;
        cin>>a>>v>>b>>w>>p;
        long dist=abs(a-b);
        long ans=0;
        if(v>w){
            ans=v-w;
        }
        if(ans*p>=dist){
            cout<<"YES\n";
        }
        else{
            cout<<"NO\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll a,b,c;cin >> a >>b >>c;
    ll k;cin >> k;
    ll ans=0;
    ans=min(a,k);
    if(a>=k){
        cout <<ans <<endl;
    }
    else{
        k=k-a-b;
        if(k>0)ans-=k;
        cout <<ans <<endl;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()

using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  // R*i + G*j
  for (int i = 0; i <= N; i += R) {
    for (int j = 0; i+j <= N; j += G) {
      int k = N-i-j;
      if (0 <= k && k % B == 0) {
        ans++;
      }
    }
  }
  cout << ans << '\n';
}


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

typedef long long ll;

int main(void){
    int n,t;
    cin>>n>>t;
    vector<ll> s(n+1);
    ll cycle = 0;
    rep(i,n) {
        // debug(i);
        ll h;
        cin>>h;
        s[i+1] = s[i] + h;
        cycle = max(cycle, h);
        ll tt = t-s[i];
        // debug(tt);
        ll res = tt/cycle + 1;
        // debug(cycle);
        // debug(res);
        // debug((tt%cycle));
        // debug(h);
        if(tt%cycle >= h) res++;
        if(t<s[i]) cout<<1<<endl;
        else cout<<res<<endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if(((A-10)>=0)||((B-10)>=0)){
        cout << -1 << endl;
    }
    else{
        cout<< A*B <<endl;
    }
    return 0;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n,q,k;
	cin>>n>>k>>q;
	int p[n]={};
	int s=q-k;
	for(int i=0; i < q; i++){
		int b;
		cin>>b;
		b--;
		p[b]++;
	}
	for(int i=0; i < n; i++){
		if(p[i]>s){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define MAX 200005
                int main()
                {
                      string s;
                      int arr[500] = {0};
                      cin>>s;
                      int l = s.size();

                      for(int i = 0 ; i < l ; i++)
                      {
                            arr[s[i]]++;
                      }
                      for(int i = 'a' ; i <= 'z' ; i++)
                      {
                            if(arr[i] % 2)
                            {
                                printf("No\n");
                                return 0;
                            }
                      }
                      printf("Yes\n");
                }

Measured memory_bytes: 256
//Author- Vaibhav Singh


#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
*/
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
  long long lcm(long long a, long long b){//?????????
   return a * b / gcd(a, b);
}

/*
ll po(ll z,ll z1)
{
    ll rer=0;
    rer=     ((z*(z-1))/2+(z1*(z1-1))/2);
    return rer;

}
*/
/*
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
*/
/*
bool is_prime(ll n){
    for(ll i = 2;i*i<=n;i++){
        if(n%i == 0) return false;
    }
    return true;
}
*/
int inv(int a){
    return powerm(a,mod-2,mod);
}

ll const N=1e5;
ll fact[N], invfact[N];
 
void precompute(){
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = (fact[i-1]*i)%mod;
    invfact[N-1] = inv(fact[N-1])%mod;
    for(int i=N-2;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod;
}
 
ll ncr(ll n, ll r){
    if(n<r) return 0;
    return (((fact[n]*invfact[r])%mod)*invfact[n-r])%mod;
}


//*88888*********5555555555555555******88888888$$$$$$$$$$******!!!!!!!!!!

       int main()
       {
           //????????
    fast

    ll a,b;
    cin>>a;
    ll i,j,f=0;
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=9;j++)
        {
            if(i*j==a)
            {
                f=1;
            }
        }
    }


       if(f==0)
       {
           No
           re
       }
Yes








//?????????
re}

Measured memory_bytes: 3628
#include<stdio.h>

int main() {
	static int  n, a[200000];
	

	scanf("%d", &n);
	for (int  i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	static int b[200000] = {};
	for (int i = n / 2; i < n; i++) {
		b[i] = a[i];
	}

	int sum;
	for (int i = n / 2 - 1; i >= 0; i--) {
		sum = 0;
		for (int j = i; j < n; j += i + 1) {
			sum += b[j];
		}
		if (sum % 2 != a[i]) {
			b[i] = 1;
		}
	}

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (b[i])cnt++;
	}
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) {
		if (b[i])printf("%d ", i + 1);
	}








	/*
	for (int i = 0; i < n/2; i++) {
		for (int j = i; j < n; j = j + i+1) {

			sum = sum + a[j];

		}
		if (sum % 2 != a[i]) {
			a[i] = 1;
		}
	}

	int count = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] == 1) {
			count++;
		}
	}

	printf("%d\n", count);
	int count2 = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 1) {
			count2++;
			if (count2 != count) {
				printf("%d ", a[i]);
			}
			else {
				printf("%d\n", a[i]);
				break;
			}
		}
	}
	*/
	return 0;
}

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

using namespace std;

const int maxn = 2e5 + 5;

int N;
long long ans,A[maxn];

int main()
{
	scanf("%d",&N);
	for(int i=1;i<=N;i++) scanf("%lld",&A[i]);
	for(int i=2;i<=N;i++)
	{
		if(A[i] < A[i-1])
		{
			ans += A[i-1] - A[i];
			A[i] = A[i-1];
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 5328
import java.util.Scanner;
 
class Main {
	int n;
	int[] h;
	int[] cost;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		h = new int[n];
		cost = new int[n];
		for(int i = 0; i < n;i++){
			h[i] = sc.nextInt();
			cost[i] = Integer.MAX_VALUE;
		}
		cost[0] = 0;
	}
	int cntString(String str,char target){
		int cnt = 0;
		for(char s : str.toCharArray()){
			if(s == target){
				cnt++;
			}
		}
		return cnt;
	}
	void solve(){
		for(int i = 0;i < n;i++){
			if(i+1<n){
				if(cost[i+1]>cost[i]+Math.abs(h[i]-h[i+1])){
					cost[i+1] = cost[i] + Math.abs(h[i]-h[i+1]);
				}
			}
			if(i+2<n){
				if(cost[i+2]>cost[i]+Math.abs(h[i]-h[i+2])){
					cost[i+2] = cost[i] + Math.abs(h[i]-h[i+2]);
				}
			}
		}
		System.out.println(cost[n-1]);
	}
}


Measured memory_bytes: 58984
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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


int main(){
    int n; cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    int q; cin >> q;
    REP(i, q){
        int b, m, e; cin >> b >> m >> e;
        rotate(a.begin()+b, a.begin()+m, a.begin()+e);
    }
    REP(i, n){
        if(i) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

 int M,D;
 cin >> M >> D;

 int ans = 0;
 for(int i = 4;i <= M;i++) {
   for(int j = 22;j <= D;j++) {
     int ten = j / 10;
     int rest = j % 10;
     if(ten < 2 || rest < 2) continue;
     if(i == ten * rest) ans++;
   }
 }

 cout << ans << endl;
  
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n, k;
  cin >> n >> k;

  vector<int> v(n);
  rep(i, 0, n) cin >> v[i];

  ll ans = 0;
  rep(l, 0, k + 1) {
    rep(r, 0, k - l + 1) {
      if (l + r > n)
        continue;
      int d = k - l - r;
      ll now = 0;
      vector<int> s;
      rep(i, 0, l) {
        now += v[i];
        s.push_back(v[i]);
      }
      rep(i, n - r, n) {
        now += v[i];
        s.push_back(v[i]);
      }

      sort(s.begin(), s.end());
      rep(i, 0, d) {
        if (i >= s.size() || s[i] > 0)
          break;
        now -= s[i];
      }

      ans = max(ans, now);
    }
  }

  cout << ans << endl;
}


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

/* 解答見た */

int main()
{
    string s;
    int k;

    cin >> s;
    cin >> k;

    int n = s.size();
    vector<string> v;

    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j <= n && j - i <= 5; j++)
        {
            v.push_back(s.substr(i, j - i));
        }
    }
    sort(v.begin(), v.end());

    v.erase(unique(v.begin(), v.end()), v.end());

    cout << v[k - 1] << endl;

    return 0;
}

Measured memory_bytes: 1660
#include <cstdio>
#include <algorithm>

using namespace std;

int k, x;

int main() {

	scanf("%d %d", &k, &x);

	for (int i = x - k + 1; i <= x + k - 1; i++) {
		printf("%d ", i);
	}

	puts("");

	return 0;

}

Measured memory_bytes: 128
############################
# 再帰的に呼出す関数
def half(a,b,low,high): #aは配列,bはソートされてない要素,cはcenter

    if(low > high):
        return 0

    c = int((low+high)/2)

    if(a[c] == b):
        return 1
    elif(a[c] < b):
        return half(a,b,c+1,high)
    elif(a[c] > b):
        return half(a,b,low,c-1)
    else:
        return 1
#############################


n = int(input())
s = list(map(int,input().split()))
q = int(input())
r = list(map(int,input().split()))
cou = 0

for i in range(q):
    cou += half(s,r[i],0,len(s))

print(cou)


Measured memory_bytes: 16708
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <string.h>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;

ll pw(ll a, ll p) {
	ll ans = 1;
	while (p > 0) {
		if (p & 1) {
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
		p /= 2;
	}
	return ans;
}

ll inv(ll a) {
	return pw(a, MOD - 2);
}

int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = pw(2, n) - 1;
	vector<ll> fact(200000 + 1, 1);
	for (ll i = 1; i <= 200000; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
	}
	ll opa = 1, opb = 1;
	for (ll i = n - a + 1; i <= n; i++) {
		opa = (opa * i) % MOD;
	}
	for (ll i = n - b + 1; i <= n; i++) {
		opb = (opb * i) % MOD;
	}
	ans -= (opa * inv(fact[a])) % MOD;
	ans -= (opb * inv(fact[b])) % MOD;
	ans = ((ans % MOD) + MOD) % MOD;
	cout << ans;
}



Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    StringBuilder sb=new StringBuilder(scan.next());
    int q=Integer.parseInt(scan.next());

    for(int i=0;i<q;i++){
      String order=scan.next();
      int a=Integer.parseInt(scan.next());
      int b=Integer.parseInt(scan.next());

      if(order.equals("print")){
        System.out.println(sb.substring(a,b+1));
      }else if(order.equals("replace")){
        String replaceStr=scan.next();
        sb.replace(a,b+1,replaceStr);
      }else if(order.equals("reverse")){
        StringBuilder buf=new StringBuilder(sb.substring(a,b+1));
        buf.reverse();
        sb.replace(a,b+1,buf.toString());
      }
    }
  }
}



Measured memory_bytes: 28620
#include <stdio.h>
#include <stdlib.h>

#define INVALID -1

int	g_res = 0;

void	dec_ary(int *ary, int start, int end)
{
	int	i;

	if (start == end)
		return ;
	for (i = start; i < end; i++)
		ary[i]--;
	g_res++;
}

void	init_invalid(int *ary, int size)
{
	int	i;

	for (i = 0; i < size; i++)
		ary[i] = INVALID;
}

int		check_element(int *ary, int *zero_index, int size)
{
	int	i, num = 0;

	for (i = 0; i < size; i++)
		if (ary[i] == 0)
		{
			*zero_index++ = i;
			num++;
		}
	return (num);
}

int	main(void)
{
	int	N, i, j, ele;
	int	*h ,*zero_index;

	scanf("%d", &N);
	h = malloc(sizeof(int) * N);
	for (i = 0; i < N; i++)
		scanf("%d", &h[i]);
	zero_index = malloc(sizeof(int) * N);
	init_invalid(zero_index, N);
	while ((ele = check_element(h, zero_index, N)) < N)
	{
		if (ele == 0)
		{
			dec_ary(h, 0, N);
			continue ;
		}
		dec_ary(h, 0, zero_index[0]);
		if (ele > 1)
		{
			for (i = 0; i < ele - 1; i++)
				dec_ary(h, zero_index[i] + 1, zero_index[i + 1]);
		}
		dec_ary(h, zero_index[ele - 1] + 1, N);
	}
	printf("%d\n", g_res);
	free(h);
	free(zero_index);
	return (0);
}

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

int main(){
    long long n,w,max_v = 0;
    long long INF = 1e18L + 5;
    cin>>n>>w;
    vector<long long> v(n),wi(n);
    for(long long i = 0;i<n;i++){
        cin>>wi[i]>>v[i];
        max_v += v[i];
    }
    vector<long long> value(max_v+1,INF);
    value[0] = 0;

    for(long long i =0;i<n;i++){

        for(long long val = max_v - v[i]; val >=0;val--){
            value[val+v[i]] = min(value[val+v[i]], value[val] + wi[i]);
        }

    }
    long long answer = 0;
    for(long long i = 0;i<=max_v;i++){
        //cout<<value[i]<<"..";
        if(value[i]<=w)
            answer = max(answer,i);
    }
    cout<<answer<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

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

  vector<int> a(2 * N - 1);
  for (int i = 0; i < (int)(2 * N - 1); ++i) a[i] = i + 1;

  if (x < N) {
    rotate(a.begin(), a.begin() + x, a.begin() + N);
  } else if (x > N) {
    rotate(a.begin() + N - 1, a.begin() + x - 1, a.end());
  }

  cout << "Yes" << endl;
  for (int i = 0; i < (int)(2 * N - 1); ++i) cout << a[i] << endl;
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<ctime>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<tuple>
#include<cassert>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iomanip>
#include<climits>
#include<typeinfo>
#include<utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
double pi = 3.141592653589793238;
using ll = long long;
using namespace std;

ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpcombination[10000][10000];

ll modi = 1000000007;
ll combination(ll n, ll r) {
	if (n == r) { return dpcombination[n][n] = 1; }
	else if (r == 0) { return dpcombination[n][0] = 1; }
	else if (r == 1) { return dpcombination[n][1] = n; }
	else if (dpcombination[n][r]) { return dpcombination[n][r]; }
	else { return dpcombination[n][r] = combination(n - 1, r - 1) % modi + combination(n - 1, r) % modi; }
}

void clockman(int time1) {

	cout << 1.0*(clock() - time1) / CLOCKS_PER_SEC << endl;
	return;
}
//cout << fixed << setprecision(10)

void printVec(std::vector<int> &vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}


int main() {
	int mod = 1000000007;
	int n, m;
	cin >> n >> m;
	vector<int>a(m);
	vector<int>b(n+1);
	b[0] = 0;
	for (int i = 0;i < m;i++) {
		cin >> a[i];
		b[a[i]] = 1;
		if (i > 0) {
			if (a[i]- a[i - 1] == 1) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	vector<int>d(n + 1);
	d[0] = 1;
	if (b[1] == 1)d[1] = 0;
	else d[1] = 1;

	for (int i = 2;i < n+1;i++) {
		if (b[i] == 1)d[i] = 0;
		else {
			d[i] = (d[i - 1] + d[i - 2]) % mod;
		}

	}
	for (int i = 0;i < n;i++) {
		//cout << b[i] << " " << d[i] << endl;
	}


	cout << d[n] << endl;

	return 0;
}

Measured memory_bytes: 4164
#include<stdio.h>
int main(void)
{
	int n, m,i,ai[1001],k,x,y,wk;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d",&ai[i]);
	}
	for(k=1;k<=m;k++){
		for(i=1;i<=n-1;i++){
			x=ai[i]%k;
			y=ai[i+1]%k;
			if(x>y){
				wk=ai[i];
				ai[i]=ai[i+1];
				ai[i+1]=wk;			
			}	
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",ai[i]);
	}
	return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
  cin>>a>>b;
  char C;
  C=b[2];
  b[2]=b[0];
  b[0]=C;
  for(int i=0; i<a.size(); i++)
  {
    if(a[i]!=b[i])
    {
      cout<<"NO\n";
      return 0;
    }
  }
  cout<<"YES\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for (int i = (a); i < (b); i++)

long long a, b, c;
int main() {
	scanf("%lld %lld %lld", &a, &b, &c);
	if (a%2 == 0 || b%2 == 0 || c%2 == 0) {
		puts("0"); return 0;
	}
	printf("%lld\n", min(b*c, min(a*c, a*b)));

	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define ll long long
#define si scanf("%d",&n)
#define sl scanf("%lld",&n)
#define pi printf("%d",n)
#define pl printf("%d",n)
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b>=c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main()
{
    ll n, m; cin >> n >> m;

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

    ll ans = n - sum;

    if (ans < 0) ans = -1;
        
    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3668
/**
 *      ///----- My Info -----///
 *      Code by: Ernesto Abreu
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
**/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu
#include <debug/to_string.h>
#endif
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
    	///----- My Template -----///
///======================================================================================================================================
/// Red-Black Tree
// #include <ext/pb_ds/assoc_container.hpp>  // .find_of_order(x); .order_of_key(x);
// using namespace __gnu_pbds;
// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set;
/// Function
#define pi (acos(-1))
#define lg2(x) 31-__builtin_clz(x)
#define lgx(x,b) log(b)/log(x)
/// Macros
#define fst first
#define scd second
#define left (node<<1)
#define right ((node<<1)+1)
#define size(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Debug
#define _end cout << "\n"
#ifdef Ernest0_0Abreu
#define db(x) cerr << "[ "<< #x << " ]: " << to_string(x) << "\n"
#define dbrange(x,begin,end) cerr << "[ "<< #x << " ]: " << to_string(x,begin,end) << "\n"
#define dbname(x) cerr << to_string(x,#x) << "\n"
#define dbnamerange(x,begin,end) cerr << to_string(x,#x,begin,end) << "\n"
#define dbmat(x,begin_n,end_n,begin_m,end_m) cerr << to_string(x,#x,begin_n,end_n,begin_m,end_m) << "\n"
#else 
#define db(x) ;
#define dbrange(x,begin,end) ;
#define dbname(x) ;
#define dbnamerange(x,begin,end) ;
#define dbmat(x,begin_n,end_n,begin_m,end_m) ;
#endif
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const int MAXN = 1e6+7;
const int MOD = 1e9+7;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021, 1000000033;
///=======================================================================================================================================
#define int long long
		///----- My code -----///



int32_t main(){
	
	ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

	int a, b;
	cin >> a >> b;
	if(a <= b) cout << "unsafe\n";
	else cout << "safe\n";

	return 0;
}

Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
bool formtri(int a,int b,int c)
{
	if(a==b || b==c || c==a)
	return false;
	if(((a+b)>c && (a+c)>b )&& (b+c)>a)
	return true;
	else
	return false;
}
int main()
{
 int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;++i)
    {
   	 cin>>arr[i];
	}
	int res=0;
	for(int i=0;i<n-2;++i)
	{
		for(int j=i+1;j<n-1;++j)
		{
			for(int k=j+1;k<n;++k)
			{
				if(formtri(arr[i],arr[j],arr[k]))
				{
				res++;
					    }
			}
		}
	}
	cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n;
    cin >> n;
    vector<LL> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<LL> t = a;

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

    set<LL> st;

    for(int i = 0; i < n; i += 2){
        st.insert(t[i]);
    }

    LL ans = 0;
    
    for(int i = 0; i < n; i += 2){
        auto itr = st.find(a[i]);
        if(itr == st.end()){
            ans++;
        }
    }

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

Measured memory_bytes: 4224
n,y=map(int,input().split())

for i in range(n+1):
    for j in range(n+1-i):
        k = n-i-j

        if 10000*i + 5000*j + 1000*k ==y:
            print(i,j,k)
            exit(0)

print(-1,-1,-1)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
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;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    if(S[0]==S[1] && S[0] == S[2]){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(),vec.end()
#define ll long long
#define debug(x) cout << "debug: " << x << endl;

int main(){
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << fixed << setprecision(10) << w * h / 2.0 << " ";
    if (w==2*x&&h==2*y)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    
}

Measured memory_bytes: 256
from fractions import gcd
a,b,c,d=map(int,input().split())
ans=(b-a+1)
lcm=(c*d)//gcd(c,d)
dba=(a//c-int(a%c==0))+(a//d-int(a%d==0))-(a//lcm-int(a%lcm==0))
dbb=(b//c)+(b//d)-(b//lcm)
dbb-=dba
ans-=dbb
print(ans)
        
        

Measured memory_bytes: 5340
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
    int h, w, k, c = 0, d = 0;
    cin >> h >> w >> k;
    char master[h][w], mirror[h][w];
    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
            cin >> master[j][i];
        }
    }

    for (int i = 0; i < pow(2, w); i++) {
        for (int j = 0; j < pow(2, h); j++) {
            for (int q = 0; q < h; q++) {
                for (int p = 0; p < w; p++) {
                    if (((i & (1 << p)) | (j & (1 << q))) == 0) {
                        mirror[q][p] = master[q][p];
                    } else
                        mirror[q][p] = '0';
                }
            }
            for (int p = 0; p < w; p++) {
                for (int q = 0; q < h; q++) {
                    if (mirror[q][p] == '#') {
                        c++;
                    }
                }
            }
            if (c == k) {
                d++;
                c = 0;
            } else {
                c = 0;
            }
        }
    }
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 4064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
using namespace std;

int main() {
    int n;
    int a = 0, count = 0, ans = 0;

    cin >> n;

    vector<pair<int, int> > z;

    for (int i = 0; i < n ; i++) {
        int x, y;
        cin >> x >> y;
        z.push_back (make_pair(x, y));
    }

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int p=0, q=0;
            p = z[j].first - z[i].first;
            q = z[j].second - z[i].second;
            count = 0;

            for (int k = 0; k < n; k++) {

                for (int l = 0; l < n; l++) {
                    if (z[l] == make_pair(z[k].first + p, z[k].second + q)) {
                        count++;
                    }
                    
                }
            }
            
            if (count > a) a = count;
        }
    }

    ans = n - a;
    if (ans == 0) ans = 1;
    cout << ans << endl;
}


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


int main()
{
  int n;
  string s1,s2;
  cin>>n>>s1>>s2;
  for(int i=0;i<n;i++){
    cout<<s1[i]<<s2[i];
  }
    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);
		double r = sc.nextDouble();
		double pi = Math.PI;
		double area = pi * r * r;
		double length = 2 * pi * r;
		System.out.printf("%f %f", area, length);
	}

}



Measured memory_bytes: 28416
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = 1; i < (ll)(n); i++)
#define P pair<ll, ll>
typedef long long ll;
const ll mod = 1e9+7;

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;}

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(int x, int y){
  if(x % y == 1) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(int x, int y){
  return x * y / gcd(x, y);
}
// n個の最大公約数
ll ngcd(vector<int> a){
  int res;
  res = a[0];
  for(int i=1; i<a.size() && res!=1; i++){
    res = gcd(res, a[i]);
  }
  return res;
}
// n個の最小公倍数
ll nlcm(vector<int> a){
  int res;
  res = a[0];
  REP(i, a.size()){
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(int x){
  int i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
int digsum(int x){
  int res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int x;
  cin >> x;
  if(x == 3 || x == 5 || x == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}






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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;
const int maxn=1e6+5;
string s[maxn];

vector<pii> type1,type2;
int sum=0;
void solve(int id)
{
	int sum_val=0,min_val=0;
	rep(i,0,s[id].size())
	{
		if(s[id][i]=='(') sum_val++;
		else sum_val--;
		min_val=min(min_val,sum_val);
	}
	if(min_val>=0)
	{
		sum+=sum_val;
		return ;
	}
	if(sum_val>=0)
	{
		type1.pb(mp(min_val,sum_val));
		return ;
	}
	else
	{
		type2.pb(mp(min_val,sum_val));
		return ;
	}
}
bool comp1(const pii &s1,const pii &s2)
{
	return s1.fi>s2.fi;
}
bool comp2(const pii &s1,const pii &s2)
{
	return (s1.fi-s1.se)<(s2.fi-s2.se);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	rep(i,0,n)
	{
		cin>>s[i];
		solve(i);
	}
	sort(all(type1),comp1);
	rep(i,0,type1.size())
	{
		if(type1[i].fi+sum<0)
		{
			cout<<"No\n";
			return 0;
		}
		sum+=type1[i].se;
	}
	sort(all(type2),comp2);
	rep(i,0,type2.size())
	{
		if(sum+type2[i].fi<0)
		{
			cout<<"No\n";
			return 0;
		}
		sum+=type2[i].se;
	}
	if(sum!=0) cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 43340
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll sum = a+b ;
    ll re = n/sum;
    ll ans= re * a;
    ll amari = min(n-re*sum,a);  
    ans+=amari;
    cout << ans << endl;
    return 0;



   


    /*ll n,a,b;
    cin >> n >> a >> b;
    ll sum = a+b ;
    ll re = int(n/sum);
    ll ans= re * a;
    bool flag = true;
    if(n%sum != n-sum*re){
        flag = false;
    }

    cout << flag << endl;
    return 0;*/




}



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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
  string s; cin >> s;

  bool before = false;
  for(int i=a; i<c; i++) {
    if (s[i-1] == '#' && s[i] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i=b; i<d; i++) {
    if (s[i-1] == '#' && s[i] == '#') {
      cout << "No" << endl;
      return 0;
    }
  }
  if (c<d) {
    cout << "Yes" << endl;
    return 0;
  }
  for(int i=b-1; i<d; i++) {
    if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 592
n = int(input())
A = list(map(int, input().split()))
ans = sum([abs(item) for item in A])
def flip(a):
    res = [a[0]]
    for i in range(len(a) - 2):
        if a[i] < 0:
            a[i+1] = - a[i+1]
        res.append(a[i+1])
    return(res)
r = flip(A[:])
l = flip(A[::-1])[::-1]
costs = []
for ri, li in  zip(r, l):
    if ri * li >= 0:
        costs = [0]
        break
    else:
        costs.append(min(abs(ri), abs(li)))
print(ans - 2 * min(costs))


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

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def calc_fraction_mod(numerator, denominator):
    '''
        returns numerator / denominator (mod MOD)
    '''
    inv = pow(denominator, MOD - 2, MOD)
    return numerator * inv % MOD

def solve(N: int, A: "List[int]", B: "List[int]"):
    conns = [[] for _ in range(N)]
    for i in range(N - 1):
        conns[A[i] - 1].append(B[i] - 1)
        conns[B[i] - 1].append(A[i] - 1)

    pows = []
    for i in range(N + 1):
        pows.append(pow(2, i, MOD))

    num = [0]
    visited = [False] * N
    def dfs(idx):
        visited[idx] = True
        children = 0
        subs = []
        for c in conns[idx]:
            if visited[c]:
                continue
            sub = dfs(c)
            children += sub
            subs.append(sub)
        subs.append(N - children - 1)
        #tmp = pow(2, N - 1, MOD)
        tmp = pows[N - 1]
        tmp -= 1 # all white
        for sub in subs:
            #tmp -= pow(2, sub, MOD) - 1
            tmp -= pows[sub] - 1
        num[0] += tmp
        return children + 1
    dfs(0)

    #deno = pow(2, N, MOD)
    deno = pows[N]
    num = num[0]
    ret = calc_fraction_mod(num, deno)
    print(ret)
    return

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

if __name__ == '__main__':
    main()


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

import fileinput
import math

def main():
    i = 1
    while True:
        inputData = int(input())

        if (inputData == 0):
            break
        else:
            print('Case %d: %d' % (i, inputData))
            i += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 6416