akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,q,c;
    cin >> n >> k >> q;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin >> c;
        a[i] = b[i] = c;
    }
    SORT(b);
    b.erase(unique(all(b)),b.end());
    ll ans = INF;
    rep(i,(ll)b.size()){
        vector<vector<ll>> packet;
        vector<ll> stock;
        rep(j,n){
            if (a[j] < b[i]){
                if (!stock.empty()){
                    packet.push_back(stock);
                    stock.clear();
                }
            }
            else{
                stock.push_back(a[j]);
            }
        }
        if (!stock.empty()) packet.push_back(stock);
        stock.clear();
        rep(j,packet.size()){
            if (packet[j].size() < k) continue;
            SORT(packet[j]);
            rep(l,packet[j].size()-k+1){
                stock.push_back(packet[j][l]);
            }
        }
        if (stock.size() < q) continue;
        SORT(stock);
        chmin(ans,stock[q-1]-stock[0]);
    }
    PRINT(ans);
}


Measured memory_bytes: 384
/****JMD****/
/*
Nagendra Jha-11011
acm18in1495
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define ll long long int
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define f(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll(a.size())

using namespace std;

inline void display(list<ll> v)
{
    for(auto x:v) cout<<x<<" ";
    cout<<"\n";
}

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

    ll n;
    cin>>n;

    ll a[n];
    f(i,n) cin>>a[i];

    sort(a,a+n);

    ll p1=1,p2=n-2;

    list<ll> g;

    g.pb(a[0]);
    g.pb(a[n-1]);

    bool flag=true;

    while(p1<p2)
    {
        if(flag)
        {
            g.pb(a[p1]);
            g.pf(a[p2]);
            p1++;
            p2--;
            flag=false;
        }
        else
        {
            g.pf(a[p1]);
            g.pb(a[p2]);
            p1++;
            p2--;
            flag=true;
        }
    }

    if(p1==p2)
    {
        if(abs(g.front()-a[p1])>abs(g.back()-a[p1]))
        {
            g.pf(a[p1]);
        }
        else g.pb(a[p1]);
    }

    ll ans=0;

    auto it=g.begin();
    auto temp=g.begin();
    temp++;

    while(temp!=g.end())
    {
        ll v1=(*it);
        ll v2=(*temp);
        ans+=abs((*temp)-(*it));
        it++;
        temp++;
    }

    //display(g);

    cout<<ans;
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

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

using namespace std;

bool comp_by_sec(pair<long long int, long long int>a, pair<long long int, \
    long long int>b) {
    if(a.second!=b.second) {
        return a.second<b.second;
    } else {
        return a.first>b.first;
    }
}

int main() {
    long long int N;
    cin >> N;
    
    vector<pair<long long int, long long int> > AB(N, pair<long long int, \
        long long int>());
    long long int A, B;
    rep(i, N) {
        cin >> A >> B;
        // cout << "A = " << A << ", B = " << B << endl;
        AB[i] = make_pair(A, B);
        // cout << "AB[" << i << "] = (" << AB[i].first << ", " << AB[i].second << ")" << endl;
    }
    
    sort(AB.begin(), AB.end(), comp_by_sec);

    long long int time=0;
    rep(i, N) {
        time += AB[i].first;
        // cout << "task " << i << ": time = " << time << ", deadline = " << AB[i].second << endl;
        if(time<=AB[i].second);
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;

    return 0;
    
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
bool vstd[N];
vector<int>v[N];
void dfs(int node){
	if(vstd[node])return ;
	vstd[node]=true;
	for(int u:v[node]){
		dfs(u);
	}
	return;
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,m;cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y,w;cin>>x>>y>>w;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(!vstd[i]){
			ans++;dfs(i);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 12300
#include<stdio.h>
int main()
{
int x,i,sw,k;
  sw=0;
  scanf("%d",&x);
   k=x/7;
  if(x>=28) printf("Yes");
 
  else {
  for(i=0;i<=k;i++){
    if(x%4==0) sw++; 
    x=x-7;
   }
  if(sw==0) printf("No");
    else printf("Yes");
  }


return 0;}

Measured memory_bytes: 1708
test = ""
#test = \
"""
8
hmhmnknk uuuuuuuu
"""
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
    

n = int(input2())
a, b = input2().strip().split()

ans = ""
for i in range(n):
    ans += a[i]
    ans += b[i]

print(ans)


Measured memory_bytes: 3060
#include<cstdio>
 
int main()
{
while(true) {

int a, b, c, n;
int test[3000], r[1000];
int ans[1000];
scanf("%d%d%d", &a, &b, &c);
if(a == 0)
break;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d%d%d%d", test + i * 3, test + i * 3 + 1, test + i * 3 + 2, r + i);
test[i * 3] -= 1, test[i * 3 + 1] -= 1, test[i * 3 + 2] -= 1;
}

for(int i = 0; i < a + b + c; ++i)
ans[i] = 2;
for(int i = 0; i < n; ++i) {
if(r[i] != 1)
continue;
for(int j = i * 3; j < i * 3 + 3; ++j)
ans[test[j]] = 1;
}
for(int i = 0; i < n; ++i) {
if(r[i] != 0)
continue;
int correct = 0;
for(int j = i * 3; j < i * 3 + 3; ++j)
correct += (ans[test[j]] == 1);
if(correct != 2)
continue;
for(int j = i * 3; j < i * 3 + 3; ++j) {
if(ans[test[j]] != 1)
ans[test[j]] = 0;
}
}
for(int i = 0; i < a + b + c; ++i)
printf("%d\n", ans[i]);
}
return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  string S;
  cin >> S;

  vector<string> w{"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  REP(i, w.size()) {
    if (w[i] == S) {
      cout << i+1 << endl;
    }
  }
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  int n, now = 0, result = 0, flag;
  cin >> n;
  int a[2][n];
  rep(i, n){
    cin >> a[0][i];
  }
  rep(i, n){
    cin >> a[1][i];
  }

  rep(i, n){
    flag = 0, now = 0;
    rep(j, n){
      if (i == j) {
        now += a[flag][j];
        flag = 1;
      }
      now += a[flag][j];
    }
    result = max(result, now);
  }
  puts(result)
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 3e18
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int 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;
}

signed main() {
	int n, k, ans = 0;
	cin >> n >> k;
	int a[200004], f[200004];
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> f[i];
	}
	sort(f, f + n);
	sort(a, a + n);
	reverse(f, f + n);
	int s = 0, b = INF;
	rep(i, 500) {
		int mid = (s + b) / 2;
		int need = 0;
		rep(j, n) {
			int z = 0;
			need += max(z, a[j] - mid / f[j]);
		}
		if (need <= k) {
			b = mid;
		}
		else {
			s = mid;
		}
	}
	cout << b << endl;

	return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

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

    int N = scanner.nextInt();
    long M = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = (scanner.nextInt() / 2);

    long lcm = 1;
    for (int num : a) lcm = lcm(lcm, num);

    for (int num : a) {
      if ((lcm / num) % 2 == 0) {
        System.out.println(0);
        return;
      }
    }

    if (M < lcm) {
      System.out.println(0);
      return;
    }
    System.out.println((M - lcm) / (lcm * 2) + 1);
  }

  private static long lcm(long i, long j) {
    long gcd = gcd(i, j);
    return i / gcd * j;
  }

  private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  }
}


Measured memory_bytes: 50828
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {
	string s; cin >> s;
	int a = 0;
	int b = 0;
	int c = 0;
	for (int i = 0; i < s.size(); i++) {
		if(s[i] == 'a') {
			a++;
		}else if (s[i] == 'b') {
			b++;
		}else {
			c++;
		}
	}
	if (a == 1 and b == 1 and c == 1) {
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;	
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define mod 1000000007
#define eps 0.000000001
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define dbg(x) cout<<#x<<": "<<x<<endl;
const double PI = acos(-1.0);
using namespace std;

void cp()
{
	int x;
	cin>>x;
	ll ans = 0;
	ans += (x/500)*1LL*1000;
	x %= 500;
	ans += (x/5)*5;
	cout<<ans;
}

int main()
{
    FASTIO;
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
    	cp();
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int MAXN=1e5+10;
ll a[MAXN], dp[MAXN][2], b[MAXN];
int n;

ll solve(void)
{
    ll sum=0, ans=0;
    ans=a[0];
    bool flag;
    if(ans>0) flag=true;
    else flag=false;
    for(int i=1; i<n; i++)
    {
        ans+=a[i];
        if(flag)
        {
            if(ans>=0)
            {
                sum+=ans+1;
                ans=-1;
            }
            flag=false;
        }
        else
        {
            if(ans<=0)
            {
                sum+=abs(ans)+1;
                ans=1;
            }
            flag=true;
        }
    }
    return sum;
}

int main(void)
{
    ll ans=0, sum1=0, sum2=0;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%lld", &a[i]);
    }
    int cnt=a[0];
    sum1=a[0]>0?0:abs(a[0])+1;
    if(a[0]<=0) a[0]=1;
    sum1+=solve();
    sum2=cnt<0?0:cnt+1;
    if(cnt<0) a[0]=cnt;
    else a[0]=-1;
    sum2+=solve();
    ans=min(sum1, sum2);
    printf("%lld\n", ans);
    return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b; cin>>a>>b;
  a*=500;
  if (a>=b) out("Yes");
  out("No");
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;
typedef pair<ll,ll>pl;

const int MAX_N = 40;

ll N,W;
ll v[MAX_N];
ll w[MAX_N];
vector<pl> x,y;

void func(int si,int ti,vector<pl> &x){
  int size=ti-si;
  rep(i,1<<size){
    pl p=pl(0,0);
    rep(j,size){
      if(i&(1<<j)){
        p.first+=w[si+j];
        p.second+=v[si+j];
      }
    }
    x.push_back(p);
  }
}
  
int main(){
  cin>>N>>W;
  rep(i,N){
  	cin>>v[i]>>w[i];
  }
 
  func(0,N/2,x);
  sort(x.begin(),x.end());
  func(N/2,N,y);
  sort(y.begin(),y.end());
    
  ll target=0,maxm=-(1LL<<60),ans=0;
    
  for(int i=x.size()-1;i>=0;i--){
    while(target<y.size() && x[i].first+y[target].first <=W ){
      maxm=max(maxm,y[target].second);
      target++;
    }
    ans=max(ans,maxm+x[i].second);
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 43732
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] A = new long[n];

        for (int i = 0; i < n; i++) {
            A[i] = sc.nextLong();
        }
        long[] ba = new long[40];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 40; j++) {
                ba[j] += (A[i] >> j) & 1;
            }
        }

        long[] xors = new long[40];
        for (int j = 0; j < 40; j++) {
            xors[j] = (1L << j) * (ba[j] > n / 2 ? ba[j]: (n - ba[j]));
        }

        long ans = 0;
        long cur = 0;
        for (int j = 39; j >= 0; j--) {
            if (((k >> j) & 1) == 1) {
                long tmp = cur + ba[j] * (1L << j);
                for (int i = 0; i < j; i++) {
                    tmp += xors[i];
                }
                ans = Math.max(ans, tmp);
                cur += (n - ba[j]) * (1L << j);
            } else {
                cur += ba[j] * (1L << j);
            }
        }
        ans = Math.max(ans, cur);
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

class dice
{
    int U, S, E, W, N, L;
public:
    dice(int, int, int, int, int, int);
    void roll_1(int);
    void roll_2(int);
    int east();

};

dice::dice(int u, int s, int e, int w, int n, int l) : 
U(u), S(s), E(e), W(w), N(n), L(l){}

void dice::roll_1(int a)
{
    static int i;
    if(U == a) return;
    if(W == a){ i = U; U = W; W = L; L = E; E = i; return; }
    if(E == a){ i = U; U = E; E = L; L = W; W = i; return; }
    if(S == a){ i = U; U = S; S = L; L = N; N = i; return; }
    if(N == a){ i = U; U = N; N = L; L = S; S = i; return; }
    if(L == a){ i = U; U = L; L = i; i = S; S = N; N = i; return; }

    return;
}

void dice::roll_2(int b)
{
    static int j;
    if(S == b) return;
    if(E == b){ j = S; S = E; E = N; N = W; W = j; return; }
    if(W == b){ j = S; S = W; W = N; N = E; E = j; return; }
    if(N == b){ j = S; S = N; N = j; j = E; E = W; W = j; return; }

    return;
}

int dice::east(){ return E; }

int main()
{
    int u, s, e, w, n, l;
    cin >> u >> s >> e >> w >> n >> l;
    dice d = dice(u, s, e, w, n, l);

    int q, a, b;
    cin >> q;

    for(int k = 0; k < q; k++){
        cin >> a >> b;
        d.roll_1(a);
        d.roll_2(b);
        cout << d.east() << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define PI 3.14159265
#define ll long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 300000000000000001
#define infx 9223372036854775806
#define all(c) c.begin(),c.end()
#define mk(x,yy) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define ff first
#define ss second
#define re return
// #define endl "\n"
#define max2(x,y)           (x>y)?x:y
#define min2(x,y)           (x<y)?x:y
#define mid(s,e)               (s+(e-s)/2)
#define mini                   INT_MIN
#define maxo                   INT_MAX
#define rep(i,a,b) for(int i=a;i<(int)(b);++i)
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define show(a,n) for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl
#define ene cout<<"\n";

ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll power(ll x,  ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
 
bool compr(std::vector<ll> a, std::vector<ll> b)
{
    if(a[0]==b[0])
        return a[1]<b[1];
    else
        return a[0]<b[0];
}

bool comp(std::vector<ll> a, std::vector<ll> b)
{
    if(a[1]==b[1]&&a[2]==b[2])
        return a[0]<b[0];
    else if(a[1]==b[1])
        return a[2]>b[2];
    else
        return a[1]<b[1];
}

int main()
{
    #ifdef SHIVANSH 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll w;
    cin>>w;
    ll a[n][2];
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[i][0] = x;
        a[i][1] = y;
    }
    ll dp[w+1] = {};
    for(ll i=0;i<=w;i++)
        dp[i] = -1;
    dp[0] = 0;
    for(ll i=0;i<n;i++)
    {
        for(ll j=w;j>=1;j--)
        {
            if(j>=a[i][0]&&dp[j-a[i][0]]>=0)
            {
                dp[j] = max(dp[j],a[i][1]+dp[j-a[i][0]]);
            }
        }
    }
    ll ans = 0;
    for(ll i=0;i<=w;i++)
        ans = max(ans,dp[i]);
    cout<<ans<<endl;
}

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

int main(){
int n,y,a=-1,b=-1,c=-1;
 cin >> n >> y;
 y=y/1000;
  for(int i=0;i<=n;i++){
   if((y-n-4*i)%9==0 && (10*n-y-5*i)%9==0){
     a=(y-n-4*i)/9;
     b=i;
     c=(10*n-y-5*i)/9;
     break;
   }
  }
  if(a>=0 && c>=0){
  cout << a <<' '<< b << ' ' << c << endl;
  }
  else{
  cout << "-1 -1 -1" << endl;
  }
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int h, w;
	cin >> h >> w;

	vector<vector<char>> input(h, vector<char>(w));
	int black = 0;
	int white = 0;

	rep(i, h){
		rep(j, w){
			cin >> input[i][j];

			if(input[i][j] == '.') white++;
			else black++;
		}
	}

	// 幅優先探索
	// x y depth
	queue<vector<int>> que;
	que.push(vector<int>{0, 0, 0});

	vector<vector<bool>> check(h, vector<bool>(w, false));
	check[0][0] = true;

	bool flg = false;
	int num;

	while(!que.empty()){
		int x = que.front()[0];
		int y = que.front()[1];
		int depth = que.front()[2];
		que.pop();

		if(x == w - 1 && y == h - 1){
			flg = true;
			num = depth;
			break;
		}

		// 上
		if(0 < y && input[y - 1][x] == '.' && check[y - 1][x] == false){
			que.push(vector<int>{x, y - 1, depth + 1});
			check[y - 1][x] = true;
		}
		// 下
		if(y + 1 < h && input[y + 1][x] == '.' && check[y + 1][x] == false){
			que.push(vector<int>{x, y + 1, depth + 1});
			check[y + 1][x] = true;
		}
		// 左
		if(0 < x && input[y][x - 1] == '.' && check[y][x - 1] == false){
			que.push(vector<int>{x - 1, y, depth + 1});
			check[y][x - 1] = true;
		}
		// 右
		if(x + 1 < w && input[y][x + 1] == '.' && check[y][x + 1] == false){
			que.push(vector<int>{x + 1, y, depth + 1});
			check[y][x + 1] = true;
		}
	}

	if(!flg){
		cout << "-1";
	}
	else{
		cout << white - num - 1;
	}

	return 0;
}

Measured memory_bytes: 3620
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    ans=0
    for i in range(n):
        ans=max(ans,sum(l1[:i+1]+l2[i:]))
    print(ans)
resolve()

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


int main(){
    int N, M, C, cnt = 0;
    cin >> N >> M >> C;
    vector<int> B(M);
    rep(i, M) cin >> B[i];
    rep(i, N){
        int su = 0;
        rep(j, M){
            int A;
            cin >> A;
            su += A*B[j];
        }
        if(su+C>0) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }



template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if (abs(b - a) <= (v - w) * t) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3624
def main():
    s = input()
    N = len(s)
    S = []
    for j in range(N):
        S.append(s[j])
    result = 0
    for i in range(N - 1):
        if S[i] == S[i + 1]:
            result += 1
            if S[i + 1] == "0":
                S[i + 1] = "1"
            else:
                S[i + 1] = "0"
    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
x,y = map(int,input().split())

list1 = [1,3,5,7,8,10,12]
list2 = [4,6,9,11]
list3 = [2]

if x in list1 and y in list1:
	print('Yes')
	
elif x in list2 and y in list2:
	print('Yes')
	
elif x in list3 and y in list3:
	print('Yes')
	
else:
	print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
#include <set>
using namespace std;
int main(){
	int N; long long int K; 
	cin >> N >> K; 
	int A[200010] = {}; 
	vector<int> P[200010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
		P[A[i]].push_back(i); 
	}
	for(int i = 0; i < N; i++){
		P[A[i]].push_back(i + N); 
	}
	int next[200010] = {}; 
	for(int i = 1; i <= 200000; i++){
		for(int j = 0; j < (int) P[i].size() - 1; j++){
			if(P[i].at(j) >= N) break; 
			next[P[i].at(j)] = P[i].at(j+1); 
		}
	}
	long long int period = 0;
	vector<long long int> kieru = {}; 
	kieru.push_back(-1); 
	kieru.push_back(next[0]);
	for(int i = 0; i < 1145141919; i++){
		long long int last = kieru.at(kieru.size() - 1) + 1;
		int tmp = last % N; 
		int tsugi = next[tmp]; 
		long long ireru = last + (long long) tsugi - tmp; 
		kieru.push_back(ireru); 
		if(ireru % (long long) N == N - 1){
			period = (ireru + 1) / (long long) N; 
			break; 
		}
	}
	long long int nokori = K % period; 
	if(nokori == 0){
	    cout << endl; return 0; 
	} 
	int a = lower_bound(kieru.begin(), kieru.end(), nokori * N) - kieru.begin(); 
	long long int b = kieru.at(a-1) % (long long) N; 
	int index = ((int) b + 1) % N; 
	vector<int> ans = {}; 
	while(index < N){
		if(next[index] < N){
			index = next[index] + 1; continue;
		}
		else{
			ans.push_back(A[index]); index ++; 
		}
	}
	for(int i = 0; i < ans.size(); i++){
		cout << ans.at(i) << " "; 
	}
	cout << endl;
}

Measured memory_bytes: 17396
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int answer = 0;
    int sum = 0;
    
    for (int i=1; i<=n; i++) {
      int ns = i;
      int digSum = 0;
      while (ns > 0) {
        digSum += ns % 10;
        ns /= 10;
        }
      if (digSum >= a && digSum <= b)
        answer += i;
     }
    
  System.out.println(answer);
  }
}


Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

using namespace std;

const int N=100000;

int n,a[N];

int main()
{
	scanf("%d",&n);
	n<<=1;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);

	long long ans=0;
	for(int i=1;i<=n;i+=2)
		ans+=a[i];

	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int f(int n){
    if(n%2 == 0) return n/2;
    else return 3*n+1;
}

int main(void){
    int s;
    scanf("%d",&s);
    if(s == 1 || s == 2 || s == 4){
        printf("4\n");
    }else{
        int num = 1;
        while(1){
            // printf("%d\n",s);
            s = f(s);
            num += 1;
            if(s == 4) break;
        }
        printf("%d\n",num+3);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

void rippleShuffle(int (&cards)[50], int n, int c){
    int a_end = n / 2,
        a_pos = 0, b_pos = a_end, pos = 0;
    int _cards[50];

    while(pos < n){
        for(int i=0;i<c&&b_pos<n;i++){
            _cards[pos++] = cards[b_pos++];
        }

        for(int i=0;i<c&&a_pos<a_end;i++){
            _cards[pos++] = cards[a_pos++];
        }
    }

    std::copy(_cards, _cards+50, cards);
}

int main(){
    int N, R;
    while(std::cin >> N >> R, !std::cin.eof()){
        int cards[50], cs[50];
        REP(i, N){
            cards[i] = i;
        }

        REP(i, R){
            std::cin >> cs[i];
        }

        REP(i, R){
            rippleShuffle(cards, N, cs[i]);
        }

        printf("%d\n", cards[N-1]);
        // REP(i, N){
        //     printf("%d\n", cards[i]);
        // }
    }
}

Measured memory_bytes: 1144
#include <algorithm>
#include <climits>
#include <iostream>
#include <iomanip>
#include <random>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using std::cin;
using std::cerr;
using std::cout;
using std::endl;
using std::make_pair;
using std::pair;
using std::stack;
using std::string;
using std::unordered_map;
using std::unordered_set;
using std::vector;
using std::lower_bound;
using std::upper_bound;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  string s;
  cin >> s;

  if (n < 3) {
    cout << "0";
    return 0;
  }

  long comb_all = 1L * n * (n - 1) * (n - 2) / 6;

  int count_r = 0;
  int count_g = 0;
  int count_b = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') ++count_r;
    if (s[i] == 'G') ++count_g;
    if (s[i] == 'B') ++count_b;
  }

  long comb_r = 1L * count_r * (count_r - 1) * (count_r - 2) / 6;
  long comb_g = 1L * count_g * (count_g - 1) * (count_g - 2) / 6;
  long comb_b = 1L * count_b * (count_b - 1) * (count_b - 2) / 6;

  long comb_rg = 1L * count_r * (count_r - 1) / 2 * count_g;
  long comb_rb = 1L * count_r * (count_r - 1) / 2 * count_b;
  long comb_gr = 1L * count_g * (count_g - 1) / 2 * count_r;
  long comb_gb = 1L * count_g * (count_g - 1) / 2 * count_b;
  long comb_br = 1L * count_b * (count_b - 1) / 2 * count_r;
  long comb_bg = 1L * count_b * (count_b - 1) / 2 * count_g;

  long result = comb_all - comb_r - comb_g - comb_b
    - comb_rg - comb_rb - comb_gr - comb_gb - comb_br - comb_bg;

  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < n; ++j) {
      if (i + j * 2 >= n) {
        break;
      }
      if (s[i] != s[i + j] && s[i] != s[i + j * 2]
          && s[i + j] != s[i + j * 2]) {
        --result;
      }
    }
  }

  cout << result;

  return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static int n;
	public static int[] A;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		A = new int[n];

		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}
		insertionSort();

	}

	public static void insertionSort() {
		for (int i = 0; i < n; i++) {
			int v = A[i];
			int j = i - 1;
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;
			printA();
		}
	}

	public static void printA() {
		for (int i = 0; i < n - 1; i++) {
			System.out.print(A[i] + " ");
		}
		System.out.println(A[n - 1]);
	}
}


Measured memory_bytes: 31788
import collections
import sys
input = sys.stdin.readline
N = int(input())
ab = [list(map(int, input().split())) for i in range(N-1)]
eda = [set() for i in range(N)]
for a, b in ab:
    eda[a-1].add(b)
    eda[b-1].add(a)
max_e = 0
for i in range(N-1):
    max_e = max(max_e, len(eda[i]))
id = 0
for i in range(N):
    if len(eda[i]) == max_e:
        id = i

q = collections.deque([(id, 0)])
print(max_e)
d = dict()
for a, b in ab:
    d[(a-1, b-1)] = 0
    d[(b-1, a-1)] = 0
eda2 = [set() for j in range(N)]

g = [set() for i in range(N)]

for a, b in ab:
    g[a-1].add(b-1)
    g[b-1].add(a-1)


while(q):
    x, color = q.popleft()
    i = 1
    for y in g[x]:
        if i == color:
            i += 1
        d[(x, y)] = i
        d[(y, x)] = i
        g[y].remove(x)
        q.append((y, i))
        i += 1

for a, b in ab:
    print(d[(a-1, b-1)])


Measured memory_bytes: 145432
N, K = gets.split.map(&:to_i)

hash = {}

N.times do |i|
    a, b = gets.split.map(&:to_i)
    hash[a] ||= 0
    hash[a] += b
end

k = K

hash.keys.sort.each do |key|
    k -= hash[key]
    if k <= 0
        puts key
        exit
    end
end

exit

Measured memory_bytes: 7304
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string str;
	int n,ans=0,a=0,b=0,ba=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>str;
		for(int j=0;j<str.size()-1;j++)
		if(str[j]=='A'&&str[j+1]=='B')
		ans++;
		if(str[0]=='B')
		a++;
		if(str[str.size()-1]=='A')
		b++;
		if(str[str.size()-1]=='A'&&str[0]=='B')
		ba++;
	}
	ans+=min(a,b);
	if(ba==a&&ba==b&&ba!=0)
	ans--;
	cout<<ans;
	return 0;
}

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

using namespace std;
using ll = long long;

#define endl '\n'
#define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL);

const int mx = 1e5 + 9;

ll cyc_len = 0, cyc_sum = 0;
vector <int> adj[mx];
bitset <mx> mark;

int main() {
    FIO();

    ll n, x, m;
    cin >> n >> x >> m;
    for (ll i = 0; i < m; i++) {
        ll j = (i * i) % m;
        adj[i].push_back(j);
    }

    ll ans = 0;
    while (n > 0) {
        if (mark[x]) break;
        ans += x;
        mark[x] = 1;
        x = adj[x][0];
        n--;
    }

    if (n > 0) {
        mark = 0;
        int y = x;
        while (!mark[y]) {
            cyc_len++;
            cyc_sum += y;
            mark[y] = 1;
            y = adj[y][0];
        }

        ll d = n / cyc_len, r = n % cyc_len;
        ans += (d * cyc_sum);
        for (int i = 0; i < r; i++) {
            ans += x;
            x = adj[x][0];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 9124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include<vector>

using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i =0;i<n;++i)
//#define mod (ll)(1e9+7)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    bool f = true;
    if(S[0] == 'A'){
        int count = 0;
        int c = 0;
        for(int i=2;i<S.length()-1;i++){
            if(S[i]=='C'){
                count+=1;
                c = i;
            }
        }
        if(count == 1){
            for(int j = 1;j<S.length();j++){
                if(j==c||(S[j]-'a'>=0&&S[j]-'a'<26)){
                    //
                }else{
                    f = false;
                }
            }
        }else{
            f = false;
        }
    }else{
        f = false;
    }
    if(f){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }
    return 0;
}

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

public class Main 

{ 

	 static FastReader sc=new FastReader(); 
	  public static void main(String[] args) 
    {
    	int t = i();
         
		if(t>=30)
			System.out.println("Yes");
		else
			System.out.println("No");
    }
      	
        	
			
	
	
		
   static void input(int A[]) {
	   for(int i=0;i<A.length;i++) {
		   A[i]=sc.nextInt();
	   }
   }
     static int i() {
    	 return sc.nextInt();
     }
     static String s() {
    	 return sc.next();
     }
     static long l() {
    	 return sc.nextLong();
     }  
        static void shuffleArray(int[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }   
}
  
        
        
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
} 




Measured memory_bytes: 32724
import sys
import math
import bisect
from sys import stdin,stdout
from math import gcd,floor,sqrt,log
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br

sys.setrecursionlimit(100000000)

ii     =lambda: int(input())
si     =lambda: input()
jn     =lambda x,l: x.join(map(str,l))
sl     =lambda: list(map(str,input().strip()))
mi     =lambda: map(int,input().split())
mif    =lambda: map(float,input().split())
lii    =lambda: list(map(int,input().split()))

ceil   =lambda x: int(x) if(x==int(x)) else int(x)+1
ceildiv=lambda x,d: x//d if(x%d==0) else x//d+1

flush  =lambda: stdout.flush()
ssi =lambda: stdin.readline()
sii =lambda: int(stdin.readline())
sp  =lambda x: stdout.write(str(x))

mod=1000000007


#main code
n=ii()
arr=lii()
count=0
for i in range(1,n):
    if arr[i]<arr[i-1]:
        count+=arr[i-1]-arr[i]
        arr[i]=arr[i-1]
print(count)

Measured memory_bytes: 33800
#include <iostream>
#include <vector>
#include <map>
#include <string>

using namespace std;
typedef long long ll;

int PRIMES_COUNT = 11;
int PRIMES[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };

int main(){
	while(true){
		int base;
		string digits;
		cin >> base >> digits;
		if(base == 0){ break; }
		ll w = 1ll, input = 0;
		for(int i = digits.size() - 1; i >= 0; --i, w *= base){
			if('0' <= digits[i] && digits[i] <= '9'){
				input += (digits[i] - '0') * w;
			}else{
				input += (digits[i] - 'A' + 10) * w;
			}
		}
		vector<ll> counts(PRIMES_COUNT, 0);
		for(int i = 0; i < PRIMES_COUNT; ++i){
			ll tmp = input;
			while(tmp >= PRIMES[i]){
				tmp /= PRIMES[i];
				counts[i] += tmp;
			}
		}
		ll result = 0x7fffffffffffffffll;
		for(int i = 0; i < PRIMES_COUNT; ++i){
			int tmp = base, div = 0;
			while(tmp % PRIMES[i] == 0){
				tmp /= PRIMES[i];
				++div;
			}
			if(div != 0){ result = min(result, counts[i] / div); }
		}
		cout << result << endl;
	}
	return 0;
}

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

using i64 = long long;

template<long long MOD>
class Num {
private:
	long long expow(long long base, long long e) const {
		long long ans = 1;
		for (; e > 0; e/= 2) {
			if (e % 2)
				ans = ans * base % MOD;
			base = base * base % MOD; }
		return ans; }

public:
	long long val;

	Num(long long _val) {
		val = _val % MOD;
		val = val < 0 ? val + MOD : val; }
	Num() : val(0) { }

	inline Num operator + (const Num &arg) const {
		Num res;
		res.val = val + arg.val;
		res.val = res.val >= MOD ? res.val - MOD : res.val;
		return res; }

	inline Num operator - (const Num &arg) const {
		Num res;
		res.val = val - arg.val;
		res.val = res.val < 0 ? res.val + MOD : res.val;
		return res; }

	inline Num operator - () const {
		Num res;
		res.val = MOD - res.val;
		res.val = res.val == MOD ? 0 : res.val;
		return res; }

	inline Num operator ^ (const int &arg) const {
		return Num(expow(val, arg)); }

	inline Num operator * (const Num &arg) const {
		return Num(val * arg.val); }

	inline Num operator / (const Num &arg) const {
		return Num(val * expow(arg.val, MOD - 2)); }

	inline void operator += (const Num &arg) {
		(*this) = (*this) + arg; }

	inline void operator -= (const Num &arg) {
		(*this) = (*this) - arg; }

	inline void operator *= (const Num &arg) {
		(*this) = (*this) * arg; }

	inline void operator /= (const Num &arg) {
		(*this) = (*this) / arg; }

	inline void operator ^= (const long long &arg) {
		val = expow(val, arg); } };

template<long long MOD>
ostream &operator << (ostream &fo, const Num<MOD> &c) {
	fo << c.val;
	return fo; }

template<long long MOD>
istream &operator >> (istream &fi, Num<MOD> &c) {
	fi >> c.val;
	c = Num<MOD>(c.val);
	return fi; }

const int MOD = 1e9 + 7, N = 1e5 + 5;

i64 a, b;
int n;

i64 v[N];
Num<MOD> dp[N], s[N];

static inline Num<MOD> sum(int l, int r) {
	if (l > r)
		return 0;
	return s[r] - (l == 0 ? 0 : s[l - 1]); }

int main() {
#ifdef HOME
	freopen("agc09c.in", "r", stdin);
	freopen("agc09c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n >> a >> b;
	for (int i = 1; i <= n; ++i)
		cin >> v[i];

	if (a > b)
		swap(a, b);

	v[0] = -1e18;
	v[++n] = 2e18;

	for (int i = 3; i <= n; ++i) {
		if (v[i] - v[i - 2] < a) {
			cout << "0\n";
			return 0; } }

	dp[0] = dp[1] = s[0] = 1;
	s[1] = 2;

	for (int st = 0, dr = 0, i = 2; i <= n; ++i) {
		while (v[i] - v[st + 1] >= b)
			st+= 1;

		dp[i] = sum(dr, st);
		s[i] = s[i - 1] + dp[i];

		if (v[i] - v[i - 1] < a)
			dr = i - 1; }

	cout << dp[n] << endl;

	return 0; }



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

int main(){
    long long n;
    long long x,m;
    cin>>n>>x>>m;

    //出てきた余りを記録
    vector<int> mod;
    //繰り返しの最初のインデックスを保持
    vector<int> idx(m,-1);
    long long a = x;
    int count = 0;
    
    while(idx[a]==-1){
        idx[a] = count;
        mod.push_back(a);
        count++;
        if(count==n) break;
        x = a;
        a = (x*x) %m;
    }


    long long ans = 0;
    //繰り返されない部分の和
    for(int i=0;i<=idx[a]-1;i++){
        ans += mod[i];
    }
    //繰り返す部分
    //countはmodの長さ
    long long repeated = 0;
    for(int i=idx[a];i<count;i++){
        repeated += mod[i];
    }
    ans += repeated*((n-idx[a])/(count-idx[a]));
    if((n-idx[a])/(count-idx[a])){
        for(int i=0;i<(n-idx[a])%(count-idx[a]);i++){
            ans += mod[idx[a]+i];
        }
    }

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

Measured memory_bytes: 3984
def main():
	n, m = map(int, input().split())
	p = [0]*n
	for i in range(n):
		p[i] = list(map(int, input().split()))
	p.sort(key=lambda x: x[0])

	total = 0
	rest = m
	for i in range(n):
		if p[i][1] > rest:
			total += p[i][0]*rest
			break
		rest -= p[i][1]
		total += p[i][0] * p[i][1]
	print(total)

if __name__ == '__main__':
    main()

Measured memory_bytes: 29028
import numpy as np
import sys
read = sys.stdin.read
 

D = int(input())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
del CS
 
last = np.zeros((26, ))


def getContestType_at_d(d, k):
    s = -10000000
    for i in range(26):
        mask = np.ones((26, ))
        mask[i] = 0
        #ps = S[d][i] - np.sum(C * (d + 1 - last) * mask)
        score =S[d][i] - np.sum(C * (min(365, d + k) + 1 - last))
        if s < score:
            s = score
            t = i
 
    last[t] = d + 1
 
    return t + 1, s


#score = 0
#pscore = 0
ans = []
for d in range(D):
    t, s = getContestType_at_d(d, 10)
    ans.append(t)
    #ans.append(getContestType_at_d(d, k))
    #score += s
    #pscore += ps

#print('pscore:', pscore)
#print('score:', score)

 
print('\n'.join(map(str, ans)))

Measured memory_bytes: 27600
N, L = map(int, input().split())
a = [int(c) for c in input().split()]
m = 10**9
j = -1
for i in range(N-1):
  if a[i]+a[i+1]>=L:
    print('Possible')
    for j in range(1,i+1):
      print(j)
    for j in range(N-1, i+1, -1):
      print(j)
    print(i+1)
    break
else:
  print('Impossible')


Measured memory_bytes: 63984
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;

ll solve(int N, int W, vector<int>& w)
{
    vector<int> sum(N + 1);
    sort(w.begin(), w.end());
    
    for (int i = 0; i < N; i++) {
        sum[i + 1] = sum[i] + w[i];
    }

    if (sum[N] <= W) {
        return 1;
    }
    
    ll res = 0;
    vector<ll> dp(W + 1);
    constexpr ll MOD = ((1e9) + 7);
    
    dp[0] = 1;
    for (int i = N - 1; i >= 0; i--) {
        for (int j = W - w[i]; j >= 0; j--) {
            dp[j + w[i]] += dp[j];
            dp[j + w[i]] %= MOD;
        }

        int wl = max(0, W - sum[i] - w[i] + 1);
        int wr = W - sum[i] - (i > 0 ? w[i - 1] : 0);
        for (int j = wl; j <= wr; j++) {
            res += dp[j];
            res %= MOD;
        }
    }
    return res;
}

int main()
{
    int N, W;
    cin >> N >> W;
    vector<int> w(N);
    for (int i = 0; i < N; i++) {
        cin >> w[i];
    }
    cout << solve(N, W, w) << endl;
    return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
int n,a[100];
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=n-1;i>=1;i--)cout<<a[i]<<" ";
	cout<<a[0]<<endl;
}   



Measured memory_bytes: 3080
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

string s;
string t;

void input() {
  cin >> s >> t;
}

void solve() {
  int ans = 1e9;

  for (int i = 0; i < (int)s.size() - (int)t.size() + 1; ++i) {
    int cur = 0;

    for (int j = 0; j < (int)t.size(); ++j)
      cur += s[i + j] != t[j];

    ans = min(ans, cur);
  }

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 2;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


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

int main() {
  int N, D, X, S=0, p;
  cin >> N >> D >> X;
  S+=N;
  for (int i=0; i<N; i++) {
    cin >> p;
    if (D>p) {
      S+=(D-1)/p;
    }
  }
  cout << S+X << endl;
}


Measured memory_bytes: 3604
N = int(input())

sps = []
for i in range(N):
    tmp = input().split()
    s = tmp[0]
    p = int(tmp[1])
    sp = (i + 1,s,p)
    sps.append(sp)

sps = sorted(sps,key=lambda sp: (sp[1],-sp[2]))

for sp in sps:
    print(sp[0])

Measured memory_bytes: 3060
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
data = [[] for _ in range(H)]

k = 0
for i in range(N):
    for j in range(a[i]):
        data[k].append(i + 1)
        if len(data[k]) == W:
            k += 1

for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            print(data[i][j],'', end = '')
    else:
        for j in range(W):
            print(data[i][W - j - 1],'', end = '')
    print()





Measured memory_bytes: 9664