akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200009],b[200009];
ll mod = 1e9 + 7;
main(){
    ll n, k;
    vector<ll> P, N;
    cin >> n >> k;
    for(ll i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] < 0) N.push_back(-a[i]);
        else P.push_back(a[i]);
    }
    if(k == n){
        ll ans = 1;
        for(int i = 1;i  <= n; i++){
            ans = ans *a[i] % mod;
        }
        cout << (ans + mod )% mod<<endl;
        return 0;
    }
    sort(N.rbegin(), N.rend());
    sort(P.rbegin(), P.rend());
    if(P.size() == 0 && k % 2 == 1 ){
        ll ans = 1;
        for(ll i = N.size()-k; i < N.size(); i++)
            ans = ans * (-N[i]) % mod;
        cout << (mod + ans) % mod << endl;
        return 0;
    }
    vector<ll> v;
    ll ans = 1;
    //N, (P+n-1)
    for(ll i =0 ; i+1 < N.size(); i+=2)
        v.push_back(N[i] * N[i+1]);
    for(ll i = k % 2; i+1 < P.size(); i+=2)
        v.push_back(P[i] * P[i+1]);
    if(k % 2) ans = P[0];
    sort(v.rbegin(), v.rend());
    for(ll i = 0; i < k/2; i++)
        ans = ans * (v[i]%mod) % mod;
    cout << ans << endl;





}


Measured memory_bytes: 8036
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
const int INF = 1001001001;

int main()
{
    int n;
    in n;
    ll l[87];
    l[0]=2;
    l[1]=1;
    for(int i=2;i<=n;i++)l[i]=l[i-2]+l[i-1];
    cout<<l[n]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B, C, D;
  cin >> N;
  A = N % 1000;
  B = A % 111;
  C = N / 10;
  D = C % 111;
  if (B == 0 || D == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
P = [0 for i in range(M)]
Y = [0 for i in range(M)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())

pref_year_city = [[] for i in range(N)]
for i in range(M):
    pref_year_city[P[i] - 1].append((Y[i], i))

for i in range(N):
    pref_year_city[i].sort()

ids = ["" for i in range(M)]
for i in range(N):
    for j, (_, city) in enumerate(pref_year_city[i]):
        ids[city] = "{:06d}{:06d}".format(i + 1, j + 1)
        
for i in range(M):
    print(ids[i])

Measured memory_bytes: 40668
#include <stdio.h>
 
void intpl(int N, int* buf, char* str) {
    int i=1;
    while(i<N) {
        if(str[i] == 'o') {
            if(buf[i] == 0) {
                buf[i+1] = buf[i-1];
            } else {
                buf[i+1] = 1 - buf[i-1];
            }
        } else {
            if(buf[i] == 0) {
                buf[i+1] = 1 - buf[i-1];
            } else {
                buf[i+1] = buf[i-1];
            }
        }
        i++;
    }
}
 
int check(int N, int* buf, char* str) {
    int res = 0;
 
    if(buf[N-1] == 0) {
        if(str[N-1] == 'o') {
            res = (buf[N-2] == buf[0]);
        } else {
            res = (buf[N-2] != buf[0]);
        }
    } else {
        if(str[N-1] != 'o') {
            res = (buf[N-2] == buf[0]);
        } else {
            res = (buf[N-2] != buf[0]);
        }
    }
 
    if(res == 0) return 0;
 
    if(buf[0] == 0) {
        if(str[0] == 'o') {
            res = (buf[N-1] == buf[1]);
        } else {
            res = (buf[N-1] != buf[1]);
        }
    } else {
        if(str[0] != 'o') {
            res = (buf[N-1] == buf[1]);
        } else {
            res = (buf[N-1] != buf[1]);
        }
    }
 
    return res;
}
 
 
 
void printAnimal(int N, int* buf) {
    for(int i=0;i<N;i++) {
        if(buf[i]) {
            printf("W");
        } else {
            printf("S");
        }
    }
    printf("\n");
}
 
 
int main() {
 
    char str[1000000];
    int N;
    scanf("%d", &N);
    scanf("%s", str);
 
    int buf[1000000];
    buf[0] = 0;
    buf[1] = 0;
    intpl(N, buf, str);
 
    if(check(N, buf, str)) {
        printAnimal(N, buf);
        return 0;
    }
 
    buf[0] = 0;
    buf[1] = 1;
    intpl(N, buf, str);
 
    if(check(N, buf, str)) {
        printAnimal(N, buf);
        return 0;
    }
 
    buf[0] = 1;
    buf[1] = 0;
    intpl(N, buf, str);
 
    if(check(N, buf, str)) {
        printAnimal(N, buf);
        return 0;
    }
 
    buf[0] = 1;
    buf[1] = 1;
    intpl(N, buf, str);
 
    if(check(N, buf, str)) {
        printAnimal(N, buf);
        return 0;
    }
 
    printf("-1\n");
 
    return 0;
}

Measured memory_bytes: 4480
A, B, K = list(map(int, input().split()))
a = A
b = B
for i in range(K):
	if i % 2 == 0:
		if a % 2 == 1:
			a -= 1
		b += int(a // 2)
		a = int(a // 2)
	else:
		if b % 2 == 1:
			b -= 1
		a += int(b // 2)
		b = int(b // 2)

print(a, b)

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

int main(void) {
	int N;
	scanf("%d", &N);
	vector<string> S(100100);
	int kouho[4] = {0};
	for (int i = 0; i < N; i++) {
		cin >> S[i];
		if (S[i] == "AC") {
			kouho[0]++;
		} else if (S[i] == "WA") {
			kouho[1]++;
		} else if (S[i] == "TLE") {
			kouho[2]++;
		} else if (S[i] == "RE") {
			kouho[3]++;
		}
	}

	cout << "AC x " << kouho[0] << endl;
	cout << "WA x " << kouho[1] << endl;
	cout << "TLE x " << kouho[2] << endl;
	cout << "RE x " << kouho[3] << endl;

	return 0;
}


Measured memory_bytes: 6460
/**Bismillahir Rahmanir Rahim.**/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long a, b, x, tmp, tmp2, ans;
    cin >> a >> b >> x;
    tmp = (a+x-1ll)/x;
    tmp2 = x*tmp;
    tmp = b - tmp2;
    if(tmp<0)
    {
        cout << 0 << endl;
        return 0;
    }
    ans = tmp/x + 1ll;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define REP(i,n) for(int i=0;i<signed(n);i++)
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
const ll MOD = 1000000007;
const ll INF = 9e9;
ll N,M,ans=INF;
ll A[300010],S[301000];
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N;
    REP(i,N){
        cin>>A[i];
        S[i]+=A[i];
        S[i+1]=S[i];
    }
    //a:右半分の区切り i:真ん中 b:左半分
    //s:右の和 t:左の和
    ll a=0,b=2,s,t;
    REP(i,N-1){
        if(i==b)b++;
        s=(S[i]-S[a])-S[a];
        t=(S[N-1]-S[b])-(S[b]-S[i]);
        bool f=true;
        if(i==0)continue;
        while(f){
            f=false;
            if(a+1==i)continue;
            if(std::abs(s)>std::abs(s-A[a+1]*2)){
                s-=A[a+1]*2;
                a++;f=true;
            }
        }
        f=true;
        while(f){
            f=false;
            if(b+1==N-1)continue;
            if(std::abs(t)>std::abs(t-A[b+1]*2)){
                t-=A[b+1]*2;
                b++;f=true;
            }
        }
        ans=min( ans,( max({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]})
        -min({S[a],S[i]-S[a],S[b]-S[i],S[N-1]-S[b]}) ) );
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
int main()
{
    ll n,m=1000000007;cin>>n;
    std::vector<std::vector<ll> > a(n+1,std::vector<ll>(n+1));
    for (int i = 1; i <= n; ++i)
    {
    	for (int j=0;j<n; ++j)
    	{
    		cin>>a[i][j];
    	}
    }
    std::vector<ll> mask(pow(2,n),0);
    mask[0]=1;
    for (int i = 0; i < pow(2,n); ++i)
    {
    	ll cnt=0;
    	for (int j = 0; j < n; ++j)
    	{
			if((i&(1<<j))>0)cnt++;    		 
    	}
    	//cout<<cnt<<"\n";
    	for (int j = 0; j < n; ++j)
    	{
    		//cout<<(i&(1<<j))<<" ";
			if((i&(1<<j))==0){
				//cout<<a[cnt+1][j]<<" a";
				if(a[cnt+1][j]>0){
					mask[(i|(1<<j))]=(mask[(i|(1<<j))]+mask[i])%m;
			//		cout<<mask[(i|(1<<j))]<<"\n";
				}
			}    		 
    	}
    	//cout<<i<<"\n";
    }
    
    cout<<mask[pow(2,n)-1]%m<<"\n";
    
}


Measured memory_bytes: 16640
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int n;
int a[100];
double ave;
int ans;
double mi;
int sum=0;

int main()
{
    scanf("%d",&n);
    mi=101;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    ave=sum*1.0/n;
    for(int i=0;i<n;i++)
    {
        if(mi>abs(ave-a[i]))
        {
            mi=abs(ave-a[i]);
            ans=i;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
(gets.to_i).times do
  n1 = gets.to_i
  n2 = gets.to_i

  #print (n1 + n2).to_s.length," : "
  if (n1 + n2).to_s.length > 80
      puts "overflow"
  else
      puts n1 + n2
  end
end



Measured memory_bytes: 6876
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    string s;
    while (true) {
        getline(cin, s);
//        cin.ignore();
        if (s == ".") break;

        stack<char> st;

        bool flag = true;
        for (auto e : s) {
            if (e == '[' || e == '(') {
                st.push(e);
            } else if (e == ']') {
                if (!st.empty() && st.top() == '[') {
                    st.pop();
                } else {
                    flag = false;
                    break;
                }
            } else if (e == ')') {
                if (!st.empty() && st.top() == '(') {
                    st.pop();
                } else {
                    flag = false;
                    break;
                }
            }
        }
        if(!st.empty()) flag = false;
        if (flag) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    ll m = 100;
    ll year = 0;
    ll x;
     cin >> x;
    while(1) {
        m*= 1.01;
        year++;
        if(m >= x) break;
    }
    cout << year << endl;
    return 0;
}

Measured memory_bytes: 3620
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  3002

ll n;
double p[N];
double dp[N][2];

double solve(){

	rep(i,0,N)dp[i][0]=dp[i][1]=0.0;
	dp[0][0]=dp[0][1]=1.0;
	dp[1][0]=p[0];
	// cerr<<p[0];
	// rep(j,0,n+1)cerr<<dp[j][0]<<" ";
	// cerr<<endl;
	rep(i,1,n){
		rep(j,1,n+1){
			dp[j][1]=dp[j][0] + (dp[j-1][0]-dp[j][0])*p[i];
		}
		rep(j,0,n+1){
			// cerr<<dp[j][1]<<" ";
			dp[j][0]=dp[j][1];
		}
		// cerr<<endl;
		// cerr<<dp[2][1]<<" lol"<<endl;
	}
	ll heads = n/2;
	heads++;
	// cerr<<"heads: "<<heads<<endl;
	return dp[heads][0];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
			cin>>n;
			rep(i,0,n)cin>>p[i];
			cout<<fixed<<setprecision(10)<<solve()<<endl;
	}
	return 0;
}

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

int main() {
  int n_max = 200005;
  int N;
  long long a[n_max],s[n_max];
  long long p;
  int b;
  long long a_sum = 0;

  for ( int i=0 ; i < n_max ; ++i) s[i] = 0;

  cin >> N;
  for ( int i=0 ; i < N ; ++i ) {
    cin >> b;
    a[i] = b; 
    s[b]++;
  }
  for ( int i=0 ; i < n_max ; ++i ){
    if ( s[i] > 1 ) {
      for ( int j=0 ; j < s[i] - 1; ++j){
        a_sum += (s[i] - j - 1);
      }
    }
  }
  for ( int i=0 ; i < N ; ++i ){
    cout << a_sum - ( s[a[i]] - 1 ) << endl;
  }
  return 0;
}

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

int main ()
{
    int n,h,s=0;
    cin>>h>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    if(s>=h)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c;
  cin>>a>>b>>c;
  long long k=min(a,c);
  a-=k;
  c-=k;
  k=min(b,c);
  b-=k;
  cout<<a<<" "<<b<<endl;
  
 return 0; 
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    ll ans=0;
    int n=in(),m=in();
    cout<<(n*3+m)/2<<endl;
}


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

using namespace std;

typedef long long ll;
typedef double d;

ll ar[10];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	for(int i=0;i<6;i++)
	{
		ll a;cin>>a;
		ar[a]++;
	}	
	for(int i=1;i<=4;i++)
		if(ar[i]>=3)
		{
			cout<<"NO";
			return 0;
		}
	cout<<"YES";	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

using namespace std;

typedef long long ll;
int N, M;
vector<pair<int, int>> E[201010];
vector<pair<int, int>> EE[201010];
int vis[201010], col[201010];
//---------------------------------------------------------------------------------------------------
#define no "No"
#define yes "Yes"

#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)

string solve() {
	rep(i, 0, N) if (!vis[i]) {
		col[i] = 0;
		vis[i] = 1;
		queue<int> que;
		que.push(i);
		while (!que.empty()) {
			int q = que.front(); que.pop();

			fore(p, E[q]) {
				if (vis[p.first]) {
					if (col[q] + p.second != col[p.first]) return no;
				}
				else {
					col[p.first] = col[q] + p.second;
					vis[p.first] = 1;
					que.push(p.first);
				}
			}

			fore(p, EE[q]) {
				if (vis[p.first]) {
					if (col[q] - p.second != col[p.first]) return no;
				}
				else {
					col[p.first] = col[q] - p.second;
					vis[p.first] = 1;
					que.push(p.first);
				}
			}
		}
	}

	return yes;
}
//---------------------------------------------------------------------------------------------------
int main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		E[a].push_back({ b, c });
		EE[b].push_back({ a, c });
	}
	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 17664
N = gets.to_i
As = gets.split.map(&:to_i)

cs = As.each_with_object(Array.new(N + 1, 0)){|a, o| o[a] += 1}
ds = (1 .. N).each_with_object(Array.new(N + 1, 0)){|i, o| o[cs[i]] += 1}
dcs = ds.reverse.inject([0]){|a, x| a << a.last + x}.drop(1).reverse
n, ans = N, N
(1 .. N).each do |k|
  while n < k*ans
    n -= dcs[ans]
    ans -= 1
  end
  puts ans
end

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

struct Node {
    int index = -1;
    int depth = -1;
    int parent = -1;
    int *child;
    int ccnt = 0;
    int type = 0;
};

void depth(Node *node, int x, int d) {
    node[x].depth = d;
    for (int i = 0; i < node[x].ccnt; ++i) {
        depth(node, node[x].child[i], d+1);
    }
}

int Root(Node *node, int x) {
    if (node[x].parent > -1) {
        Root(node, node[x].parent);
    } else {
        return x;
    }
}

int main() {
    int n, b, x, y, root;
    string child;
    string type[] = {"leaf", "internal node", "root"};
    cin >> n;
    Node a[n];
    for (int i = 0; i < n; ++i) {
        cin >> x >> y;
        a[x].index = x;
        a[x].child = new int[y];
        a[x].ccnt = y;
        for (int j = 0; j < y; ++j) {
            cin >> b;
            a[x].child[j] = b;
            a[x].type = 1;
            a[b].parent = x;
        }
    }
    
    root = Root(a, 0);
    a[root].type = 2;
    depth(a, root, 0);
    
    for (auto& i : a) {
        cout << "node " << i.index << ": parent = " << i.parent << ", depth = " << i.depth << ", " << type[i.type] << ", ";
        child = "[";
        for (int j = 0; j < i.ccnt-1; ++j) {
            child += to_string(i.child[j]) + ", ";
        }
        if (i.ccnt) { 
            child += to_string(i.child[i.ccnt-1]) + "]\n";
        } else {
            child += "]\n";
        }
        cout << child;
    }
    
    return 0;
}

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

using namespace std;

using ll = long long;

const int N = 3'001;

ll dp[N][N];

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

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

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j + i < n; ++j) {
            if ((n - i) % 2) {
                dp[i + 1][j] = max(dp[i][j] + a[j + i], dp[i][j + 1] + a[j]);
            } else {
                dp[i + 1][j] = min(dp[i][j] - a[j + i], dp[i][j + 1] - a[j]);
            }
        }
    }

    cout << dp[n][0] << endl;

    return 0;
}


Measured memory_bytes: 70016
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;
using ll = long long;

#define rep(i,n) for(int i = 0;i < n;i++)

int main()
{
    ll n;
    cin >> n;
    
    cout << (n*(n-1))/2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int s[100000];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> s[i];
	
	int ans = 0;
	
	int a, b;
	int c;	//a-b
	for (c = 1; c <= n - 2; c++) {
		vector<int> rui1;	//mc
		vector<int> rui2;	//(n-1)%c + mc
		int m;
		
		int su1 = 0, su2 = 0;
		rui1.push_back(0);
		for (m = 0; m * c < n; m++) {
			rui1.push_back(*rui1.rbegin() + s[m * c]);
		}
		su1 = *rui1.rbegin();
		
		rui2.push_back(0);
		for (m = 0; (n - 1) % c + m * c < n; m++) {
			rui2.push_back(*rui2.rbegin() + s[(n - 1) % c + m * c]);
		}
		su2 = *rui2.rbegin();
		
		//cout << "c = " << c << endl;
		//rep(i, rui1.size()) cout << rui1[i] << " "; cout << endl;
		//rep(i, rui2.size()) cout << rui2[i] << " "; cout << endl;
		
		m = -1;
		for (a = (n - 1) % c; a < n; a += c) {
			m++;
			int b = a - c;
			if (b <= 0) continue;
			if (a % c == 0 && a + b < n - 1) continue;
			//cout << a << ", " << b << endl;
			
			int score = su2 - rui2[m] + rui1[(n - 1 - a) / c + 1];
			//cout << "a, b = " << a << ", " << b  << ", score = " << score << endl;
			ans = max(score, ans);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3316
from itertools import *
from bisect import *
from math import *
from collections import *
from heapq import *
from random import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n=II()
    a,b=MI()
    n%=12
    for i in range(n):
        if i%2:b+=a
        else:a-=b
    print(a,b)

main()



Measured memory_bytes: 8176
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    
    print(max(a[0]+a[1],a[0]-a[1],a[0]*a[1]))

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    string s;
    cin >> s;
    cout << (s[0]=='o'||s.back()=='o'?'o':'x') << endl;
    return 0;
}



Measured memory_bytes: 3208
n=gets.to_i

as, bs = [], []
n.times.map{a,b=gets.split.map(&:to_i);as<<a;bs<<b}

cnt = 0
n.times.each do |i|
  i = n-1 - i

  cnt += (bs[i] - as[i] - cnt) % bs[i]
end

puts cnt

Measured memory_bytes: 4204
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;
long long N, A, B;
int main() {
	cin >> N >> A >> B;
	if (N == 1) {
		if (A == B)cout << "1" << endl;
		else cout << "0" << endl;
	}
	else {
		cout << max(0LL, (N - 2)*(B - A) + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s=list(input())

ss=[-1]*(len(s)+1)
kind=[]
i=0
tmp=s[0]
cnt=0
j=0
for i in range(len(s)):
    if tmp == s[i]:
        cnt+=1
    else:
        tmp=s[i]
        kind.append(cnt)
        # if mx < cnt:
        #     mx=cnt
        #     mxidx=i
        cnt=1
    if s[i]=='<':
        ss[i]=j
        j+=1
    else:
        j=0
kind.append(cnt)
j=0
for i in range(-1,-len(s)-1,-1):
    if s[i]=='>':
        ss[i]=j
        j+=1
    else:
        j=0
if ss[0]==-1:
    ss[0]=ss[1]+1


if ss[-1]==-1:
    ss[-1]=ss[-2]+1
    j=0

if s[0]=='>':
    j=1
    for i in range(0,len(s)) :
        if ss[i]==-1:
            ss[i]=max(kind[j],kind[j+1])
            j+=2
else:
    j=0
    for i in range(0,len(s)) :
        if ss[i]==-1:
            ss[i]=max(kind[j],kind[j+1])
            j+=2
ans=0
for i in range(0,len(s)+1):
    ans+=ss[i]

print(ans)


Measured memory_bytes: 94824
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

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

    return 0;
}

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

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		long[][] dp = new long[N + 1][N + 1];
		for (int l = 1; l <= N; l++) {
			for (int i = 0; i + l <= N; i++) {
				int j = i + l;
				boolean first = (N - l) % 2 == 0;
				if (first) {
					dp[i][j] = dp[i + 1][j] + A[i];
					dp[i][j] = Math.max(dp[i][j], dp[i][j - 1] + A[j - 1]);
				} else {
					dp[i][j] = dp[i + 1][j] - A[i];
					dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] - A[j - 1]);
				}
			}
		}
		System.out.println(dp[0][N]);
	}
}

Measured memory_bytes: 129772
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

bool search(int x, int a, int b) {
    int num = 0;
    FOR(i, max(1LL, x / 2 - 50), min(x / 2 + 50, x)) {
        int first = i;
        if (first >= a) first++;
        int second = x - i + 1;
        if (second >= b) second++;
        num = max(first * second, num);
        if (first * second < 0) {
            num = INF;
            break;
        }
    }

    int t = a * b;

    return num < t;
}

int solve(int a, int b) {
    int l = 0;
    int r = 3e9 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (search(mid, a, b)) {
            l = mid;
        } else {
            r = mid;
        }
    }
    return l;
}

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

    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        int ans = solve(a, b);
        cout << ans << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;

int n;
ll vet[100005];
ll dp[100005][2];

ll solve(int pos, int inv){
    if(pos >= n - 1) return (inv ? -vet[pos] : vet[pos]);
    ll &d = dp[pos][inv];
    if(d != -1) return d;
    ll res = solve(pos + 1, 0) + (inv ? -vet[pos] : vet[pos]);
    inv ^= 1;
    return d = max(res, solve(pos + 1, 1) + (inv ? -vet[pos] : vet[pos]));
}

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> vet[i];
    memset(dp, -1LL, sizeof dp);
    cout << solve(0, 0) << endl;
	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF=1e18,MOD=1e9+7;
int main(){
	int i,a,b,c;
	string s;

	int n,k;
	cin>>n>>k;
	cout<<n-k+1<<endl;
	
}


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

int main(){
    int n,k;
    cin>>n>>k;
    vector<double> dice(n);
    double mx=0,sum=0;
    for(int i=0;i<n;i++){
        double p;
        cin>>p;
        dice[i]=(p+1)/2;
        sum+=(1+p)/2;
        if(i>=k-1){
            mx=max(mx,sum);
            sum-=dice[i-k+1];
        }
    }
    cout<<setprecision(10)<<mx<<endl;
}


Measured memory_bytes: 1792
n = int(input())
a = [[],[]]
a[0] = [int(x) for x in input().split()]
a[1] = [int(x) for x in input().split()]

p = [[0] * n] * 2
for i in range(2):
  for j in range(n):
    if i - 1 >= 0 and j - 1 >= 0:
      p[i][j] = a[i][j] + max(p[i - 1][j], p[i][j - 1])
    elif i - 1 >= 0:
      p[i][j] = a[i][j] + p[i - 1][j]
    elif j - 1 >= 0:
      p[i][j] = a[i][j] + p[i][j - 1]
    else:
      p[i][j] = a[i][j]
res = p[1][n - 1]
print(res)


Measured memory_bytes: 3064
n=int(input())
p=list(map(int,input().split()))
p.reverse
import heapq
a = [p[0]]
heapq.heapify(a)

ans=0

#調査対象のやつが合致する場合は、次の最大値にヒープを移す。
for i in range(n):
  #print(a)
  temp=heapq.heappop(a)
  if p[i]<=temp:
    ans+=1
    heapq.heappush(a,p[i])
  else:
    heapq.heappush(a,temp)
print(ans)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
// #define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

using Int = __int128_t;
using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}


signed main() {
    int64_t a, b, c, d;

    cin >> a >> b >> c >> d;

    cout << max({a*c, a*d, b*c, b*d}) << endl;;

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
using namespace std;

int n;
multiset<int, greater<int>> st;
vector<int> vt;
int main() {
	int i, j, t;
	cin >> n;
	for(i=0; i<1<<n; i++) scanf("%d", &t), st.insert(t);
	vt.push_back(*st.begin());
	st.erase(st.begin());
	for(i=0; i<n; i++) {
		for(j=0; j<1<<i; j++) {
			auto x = st.upper_bound(vt[j]);
			if(x == st.end()) return puts("No"), 0;
			vt.push_back(*x);
			st.erase(x);
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 13692
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < n;i++)
using namespace std;
 
int main(){
    int count = 0;
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p.at(i);
    for(int i = 0;i < n - 2;i++){
        if((p.at(i) < p.at(i + 1) && (p.at(i + 1) < p.at(i + 2))) || 
        (p.at(i) > p.at(i + 1) && (p.at(i + 1) > p.at(i + 2)))){
            count++;
        }
    }
    cout << count << endl;
}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef vector<int> vint;

int main() {
  int n;
  while (cin >> n) {
    vint x(n), y(n), h(n);
    REP(i,n) cin >> x[i] >> y[i] >> h[i];

    REP(cx,101) REP(cy,101) {
      bool ok = true;
      long long ht;
      REP(i,n) if (h[i] != 0) ht = h[i] + abs(cx-x[i]) + abs(cy-y[i]);
      REP(i,n) if (max(ht - abs(cx-x[i]) - abs(cy-y[i]), 0LL) != h[i]) ok = false;
      // cout << cx << ' ' << cy << ' ' << ht << ' ' << ok << endl;
      if (ok) {
	cout << cx << ' ' << cy << ' ' << ht << endl;
	goto end;
      }
    }
  end:;
  }
}


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n, m;
    cin >> n >> m;
    vector<vector<i64>> g(n);
    vector<i64> in(n), a(n - 1 + m), b(n - 1 + m);
    for (i64 i = 0; i < n - 1 + m; i++) {
        cin >> a[i] >> b[i], a[i]--, b[i]--;
        g[a[i]].push_back(b[i]);
        in[b[i]]++;
    }

    i64 r = distance(begin(in), find(begin(in), end(in), 0));
    vector<i64> dist(n, 0);
    queue<i64> q;
    q.push(r);
    while (!q.empty()) {
        i64 t = q.front(); q.pop();
        for (auto& e : g[t]) {
            in[e]--;
            dist[e] = max(dist[e], dist[t] + 1);
            if (in[e] == 0) q.push(e);
        }
    }

    vector<i64> ans(n, -1);
    for (i64 i = 0; i < n - 1 + m; i++) {
        if (dist[b[i]] - dist[a[i]] == 1) ans[b[i]] = a[i];
    }
    for (auto& e : ans) cout << e + 1 << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 10240
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
 
using ull = unsigned long long int;
using ll = long long int;
using du = double;
using ld = long du;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vdu = vector<du>;
using vs = vector<string>;
using vc = vector<char>;
using si = set<int>;
using sll = set<ll>;
using sdu = set<du>;
using sld = set<ld>;
using pii = pair<int, int>;
using pll = pair<ll,ll>;
using pdu = pair<du,du>;
using pld = pair<ld,ld>;
using pis = pair<int,string>;
 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define sp(x) setprecision(x)<<fixed
#define loop(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pi acos(-1)
#define meme(a,x) memset(a,x,sizeof(a))
#define all(a) a.begin(),a.end()
 
//debugger
 
#ifdef KAIZER
#include "debug.h"
#else
#define debug(x...)
#endif
//debugger
 
//functions
bool check_pow(ll a)
{
    if((a&(a-1))==0) return true;
    else return false;
}
ld my_pow(ld a,int b)
{
    ld ans=1;
    for(int i=0;i<b;i++) ans*=a;
    return ans;
}
ll digits(ll a)
{
    string line=to_string(a);
    return line.size();
}
bool prime_check(ll a)
{
    bool flag=true;
    for(ll i=2;i<=sqrt(a);i++)
    {
        if(a%i==0) {flag=false; break;}
    }
    return flag;
}
bool comp(const pair<int,int> &a , const pair<int,int> &b)
{
    if(a.ff!=b.ff) return a.ff>b.ff;
    else return a.ss<b.ss;
}
bool comp2(const ll &a, const ll &b)
{
     return a>b;
}
 
//functions
bool rc(int x, int y)
{
    int z = double(x)*1.08;
    if (z==y) return true;
    else return false; 
}
 
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FASTIO;
    ll t;
    cin>>t;
    int x= (t)/1.08;
    if(rc(x,t)) cout<<x<<endl;
    else if(rc(x+1,t)) cout<<x+1<<endl;
    else if(rc(x-1,t)) cout<<x-1<<endl;
    else cout<<":(\n";
 }

Measured memory_bytes: 3700
symbol=[x for x in input().split()]
stack=[]

for i in range(len(symbol)):
    if symbol[i]!="+" and symbol[i]!="-" and symbol[i]!="*":
        stack.append(int(symbol[i]))
    elif symbol[i]=="+":
        b=stack.pop()
        a=stack.pop()
        stack.append(a+b)
    elif symbol[i]=="-":
        b=stack.pop()
        a=stack.pop()
        stack.append(a-b)
    elif symbol[i]=="*":
        b=stack.pop()
        a=stack.pop()
        stack.append(a*b)

print(stack.pop())



Measured memory_bytes: 5608
#スペース区切りの整数の入力
h1, m1, h2, m2, k = map(int, input().split())

asa = h1 * 60 + m1
yoru = h2 * 60 + m2 - k


if(yoru<=asa):
  print("0")
else:
  print(yoru-asa)

Measured memory_bytes: 9112
import sys
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
ct=[0 for i in range(n)]
fin=0
day=0
count=0
check=[0,0]
while count!=n*(n-1)//2 and day<=10**4:
  L=[0 for i in range(n)]
  f1=0
  for i in range(n):
    if L[i]==0 and ct[i]!=n-1:
      x=l[i][ct[i]]
      if l[x-1][ct[x-1]]-1==i and L[x-1]==0:
        ct[i]+=1
        ct[x-1]+=1
        L[i]=1
        L[x-1]=1
        count+=1
  day+=1
  check[0]=check[1]
  check[1]=count
  if check[0]==check[1]:
    print(-1)
    sys.exit()
if day>10**4:
  print(n*(n-1)//2)
  sys.exit()
print(day)

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

int main() {
  int h,w,n,i;
  cin>>w>>h>>n;
  int x[n],y[n],a[n];
  for(i=0;i<n;i++)
    cin>>x[i]>>y[i]>>a[i];
  
  int s,x1=0,x2=w,y3=0,y4=h;
  
  for(i=0;i<n;i++){
    if(a[i]==1)
      x1=max(x1,x[i]);
    else if(a[i]==2)
      x2=min(x2,x[i]);
    else if(a[i]==3)
      y3=max(y3,y[i]);
    else if(a[i]==4) 
      y4=min(y4,y[i]);
  }
  if(x2-x1<0 || y4-y3<0)
    s=0;
  else s=(x2-x1)*(y4-y3);
  cout<<s;
  
  
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        long q=sc.nextLong();
        long h=sc.nextLong();
        long s=sc.nextLong();
        long d=sc.nextLong();
        long n=sc.nextLong();
        long half=min(h,2*q);
        long one=min(half*2,s);
        long two=min(one*2,d);
        out.println((n/2)*two+n%2*one);
    }
}

Measured memory_bytes: 25172
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
	int a, b, d, r;
	double f;
	cin >> a >> b;
	d = a / b;
	r = a%b;
	f = (double)a / b;
	printf("%d %d %.8lf\n", d, r, f);
	return 0;
}

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

long long N;

int main(){
	int m = INT_MAX;
	scanf("%lld", &N);
	for(long long i = 1; i <= (long long)sqrt(N); i++)
		if(N % i == 0){
			string a = to_string(i);
			string b = to_string(N / i);
			m = min(m, (int)max(a.length(), b.length()));
		}
	
	printf("%d\n", m);
	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 x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double x2 = sc.nextDouble();
        double y2 = sc.nextDouble();

        System.out.printf("%f\n", Math.sqrt(Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0)));
        sc.close();
    }
}



Measured memory_bytes: 28280
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    diff = []

    for i in range(N):
        diff.append(A[i] - (i + 1))
    diff.sort()
    b = (diff[(N - 1) // 2] + diff[N // 2]) // 2

    result = 0
    for i in range(N):
        result += abs(A[i] - (i + 1 + b))
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 25196
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n+3);
	for(int i=0;i<n;i++){
		int l,r;
		cin>>l>>r;
		a[min(n+2,l)]++,a[min(n+2,r+1)]--;
	}
	for(int i=1;i<=n+2;i++) a[i]+=a[i-1];
	int res=0;
	for(int i=n+1;i>0;i--) if(a[i]>=i-1){
		res=i-1;
		break;
	}
	cout<<res<<endl;
}


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

int A[10000+1];
bool search(int t,int n)
{
	int i = 0;
	//A[n] = t;//将A[n]无效数设置为结束标志 
	while(A[i] != t && i < n){//经过了两次比较 
	//while(A[i] != t){//只经过一次比较，效率提高常数倍 
		i++;
	}
	return i != n;
}
int main()
{
	int n,q,t;
	int cnt = 0;
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for(int i = 0;i < q;i++){
		scanf("%d",&t);
		if(search(t,n) ){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
    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 comb(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;
}

//繰り返し二乗法 O(logN)
ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;//最下位ビットが立っているときにx^(2^i)をかける
        x = x * x % mod; //xを順次二乗していく
        n >>= 1;
    }
    return res;
}

//逆元を求める(フェルマーの小定理)X^(p-1)≡1 <=> X^(-1) ≡ X^(p-2) p:素数
ll mod_inv(ll x) {
    return mod_pow(x,MOD-2,MOD);
}

ll x[MAX],invx[MAX];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    comb_init();
    ll N=H+W;
    x[0]=1;
    for(int i=1;i<N;i++) x[i] = (x[i-1]*i)%MOD;
    REP(i,H-A) invx[i] = mod_pow(x[i],MOD-2,MOD);
    ll ans = 0;
    REP(i,H-A){
        ans += (comb(B-1+i,B-1)*comb(W-1-B+H-1-i,W-1-B));
        ans %= MOD;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 18816
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e6 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)  
int main(){
    //FL;
    fin;
    int n;
    string s;
    cin >> n >> s;
    int x[26 + 1], y [26 + 1];
    cls(x, 0);
    cls(y, 0);
    int mx = 0;
    fore(i, 1, n - 1){
        cls(x, 0);
        cls(y, 0);
        int j = 0;
        while(j < i)
            x[s[j++] - 'a']++;
        j = i;
        while(j < n)
            y[s[j++] - 'a']++;
        int tmp = 0;
        fore(i, 0, 26){
            if(x[i] && y[i])
                tmp++;
        mx = max(mx, tmp);
        }
    }
    cout << mx <<  '\n';
    time;
    return 0;
}   

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
const ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    mint ans = 1;
    vec<ll> cnt(N+3,0);
    cnt[0] = 3;
    for(int i=0;i<N;i++){
        if(cnt[A[i]]==0){
            cout << 0 << endl;
            return 0;
        }
        ans *= cnt[A[i]];
        cnt[A[i]]--;
        cnt[A[i]+1]++;
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
 
int main(void){
        int i,n;
        scanf("%d",&n);
        int num[100];
        for(i=1;i<=n;i++)
                scanf("%d",&num[i]);
        for(i=0;i<n;i++){
                if(i==n-1)
                        printf("%d",num[n-i]);
                else
                        printf("%d ",num[n-i]);
        }
        putchar('\n');
          return 0;
}

Measured memory_bytes: 600
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]
dp = {0: 0}
for i in range(N):
    for j in sorted(dp.keys(), reverse=True):
        w, v = wv[i][0], wv[i][1]
        nw = dp[j] + w
        nv = j + v
        if nw <= W:
            if nv in dp:
                if nw < dp[nv]:
                    dp[nv] = nw
            else:
                dp[nv] = nw


print(max(dp.keys()))

Measured memory_bytes: 11112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	if(t[0]==s[2] && t[2]==s[0] && t[1]==s[1]) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,l,r,s=0,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&l,&r);
		s+=r-l+1;
	}
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 128