akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,a,b) for (int i = (a); i < (b); ++i)


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

    rep2(i,1,100000){
        if(int(floor(i*0.08))==a && int(floor(i*0.1))==b){
            cout<<i<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline int in(){int x;std::cin>>x;return x;}

using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;

template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}
signed main(){
  int N,M;
  cin>>N>>M;
  int rmin = N;
  int lmax = 0;
  int L,R;
  rep(i,M){
    cin>>L>>R;
    if(L>lmax)lmax=L;
    if(R<rmin)rmin=R;
  }
  int ans = (rmin - lmax+1 >= 0)? rmin - lmax+1 :0;
  print(ans);
  return 0;
}


Measured memory_bytes: 256
//49
#include<iostream>
#include<string>

using namespace std;

int main(){
  int rta[128];
  rta['Z']=0;
  rta['I']=1;
  rta['V']=5;
  rta['X']=10;
  rta['L']=50;
  rta['C']=100;
  rta['D']=500;
  rta['M']=1000;
  for(string s;cin>>s;){
    s+='Z';
    int ans=0;
    for(int i=0;i<s.size()-1;i++){
      if(rta[s[i]]>=rta[s[i+1]]){
	ans+=rta[s[i]];
      }else{
	ans-=rta[s[i]];
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int maxn = 1e5 + 5;
const int mod = 998244353;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, m;
    cin >> n >> m;
    map<ll,int>mp;
    ll ret = 1;
    for (int i = 2 ; i <= sqrt(m) ; i++) {
        int cnt = 0;
        while(m % i == 0) {
            cnt++;
            m /= i;
        }
        cnt /= n;
        while(cnt--) {
            ret *= i;
        }
    }
    if (n == 1) {
        ret *= m;
    }
    cout << ret << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(x,n) for(int x = 0; x < n; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define fore(i,a,b) for(int i = a; i < b; i++)
using namespace std;
typedef long long ll;

const int MXN = 2e5 + 1;
const ll MOD = 1e9 + 7;
ll A[MXN], Ai[MXN];

ll bE(ll b, ll e){
  ll r = 1;
  while(e)
    if(e&1) r=(r*b)%MOD, e--;
    else b=(b*b)%MOD, e/=2;
  return r;
}

int main() {
  A[0] = Ai[0] = 1;

  fore(i,1,MXN) A[i] = (A[i-1] * (ll)i)%MOD, Ai[i] = bE(A[i], MOD-2LL);
  int N, M; cin >> N >> M;

  if(abs(N-M) > 1)
    cout << "0\n";
  else if(abs(N-M) == 1)
    cout << (A[N] * A[M])%MOD << "\n";
  else
    cout << (2LL * (A[N] * A[M])%MOD)%MOD << "\n";
}


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



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

	vector<ll> C(n);
	vector<vector<ll>> A(n,vector<ll>(m));
	for(int i = 0;i<n;i++)
	{
		cin >>C[i];
		for(int j = 0;j<m;j++)
		{
			cin >> A[i][j];
		}
	}
	ll ans = LLONG_MAX;
	for(int bit = 0;bit<(1<<n);bit++)
	{
		ll now = 0;
		vector<ll> XX(m);
		for(int i = 0;i<n;i++)
		{
			if((bit>>i)&1)
			{
				now += C[i];
			
			for(int j = 0;j<m;j++)
			{
				XX[j] += A[i][j];
			}
			}
		}
		bool flag = true;
		for(auto i:XX)
		{
			if(i<x)flag = false;
		}
		if(flag)ans = min(ans,now);
	}
	cout<<(ans==LLONG_MAX?-1:ans)<<endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int count = 0;
    int en500 = sc.nextInt();
    int en100 = sc.nextInt();
    int en50  = sc.nextInt();
    int sum   = sc.nextInt();
    
    for(int i=0; i<=en500; i++){
      for(int j=0; j<=en100; j++){
        for(int k=0; k<=en50; k++){
          if((i*500 + j*100 + k*50) == sum){
            count++;
          }
        }
      }
    }
    System.out.println(count);
  }
}

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

int main() {
   int N,W;
   cin >> N >> W;
   int v[N],w[N];
   for (int i=0; i<N; i++) {
       cin >> v[i] >> w[i];
   }
   int count[N][W+1];
   for (int i=0; i<N; i++) {
       for (int j=0; j<W+1; j++) {
           count[i][j]=0;
       }
   }
   for (int i=0; i<N; i++) {
       for (int j=0; j<=W; j++) {
           if (i==0) {
               if (w[i]>j) continue;
               count[0][j]=v[i];
               continue;
           }
           if (j==0) continue;
           if (j<w[i]) {
               count[i][j]=count[i-1][j];continue;
           }
           count[i][j]=max(count[i-1][j],count[i-1][j-w[i]]+v[i]);
       }
   }
   cout << count[N-1][W] << endl;
}


Measured memory_bytes: 7012
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll INF = 1101101101101;
bool is_prime(ll n) {
  for (ll i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  int cnt = 0;
  map<ll, bool> mp;
  ll i = 0;
  vector<ll> k(1000100, INF);
  int t = 0;
  map<ll, bool> mp2;
  for (ll i = 2; i < 1000100; i++) {
    if (is_prime(i) == true) {
      for (ll j = 1; j <= 1000100; j++) {
        if (t > 1000100) break;
        if (pow(i, j) > 1000100) break;
        if (mp2[pow(i, j)] == false) {
          k[t] = pow(i, j);
          mp2[k[t]] = true;
          t++;
        }
      }
    }
  }
  sort(k.begin(), k.end());
  while (n >= 2) {
    if (n % k[i] == 0 && mp[k[i]] == false) {
      n /= k[i];
      mp[k[i]] = true;
      cnt++;
      //cout << k[i] << " " << n << " " << cnt << endl;
    }
    if (i > t) {
      if (n >= 1000101 && mp[n] == false) {
        cnt++;
      }
      break;
    }
    i++;
  }
  cout << cnt << endl;
}

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

ll power(ll x, ll n){
    if(n == 0) return 1LL;
    ll res = power(x * x % MOD, n/2);
    if(n % 2 == 1) res = res * x % MOD;
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.size();
    ll ans = 0;
    ll sum[200010] = {};
    map<ll,ll> mp;
    mp[0]++;
    rrep(i,N-1,0){
        ll idx = N-1-i;
        ll v = (S[i] - '0') * power(10, idx) % MOD;
        sum[idx+1] = (sum[idx] + v) % MOD;

        ll cur = sum[idx+1];

        ll val = (MOD + cur + 2*MOD) % MOD;
        ans += mp[val];
        mp[sum[idx+1]]++;
    }
    print(ans);
}

Measured memory_bytes: 5272
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    long N, x;
    cin >> N >> x;
    long a[100];
    for(int i = 0; i < N; i++) cin >> a[i];
    sort(a, a+N);
    long sum = 0;
    for(int i = 0; i < N; i++) {
        sum += a[i];
        if(sum > x){
            cout << i << endl;
            return 0;
        }
    }
    if(sum < x) cout << N-1 << endl;
    else cout << N << endl;
}

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

using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back
#define int long long

signed main(){

	int count[100002]={0};
	
	int n;
	cin>>n;

	int a[n];

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


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

		if(a[i]==0){
			count[a[i]]++;
			count[a[i]+1]++;
		}else{
			count[a[i]]++;
			count[a[i]-1]++;
			count[a[i]+1]++;
		}
	}

	// for(int i=0;i<10;i++){
	// 	cout<<count[i]<<" ";
	// }cout<<endl;

	int ans=-1;
	
	for(int i=0;i<100000;i++){
		ans=max(ans,count[i]);
	}

	cout<<ans<<endl;
}

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

int main()
{
    long long int r,D,x;
    cin>>r>>D>>x;

    for(int i = 0;i<10;i++)
    {
        x=r*x-D;
        cout<<x<<endl;
    }
}

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

int main()
{
    int n,i;
    cin >> n;
    vector<int> p(n);
    for(i = 0;i < n;++i){
        cin >> p.at(i);
    }
    int num = 0;
    for(i = 1;i < n-1;++i){
        if(p.at(i) < p.at(i+1) && p.at(i) > p.at(i-1)){
            ++num;
        }else if(p.at(i) > p.at(i+1) && p.at(i) < p.at(i-1)){
            ++ num;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200009],b[200009];
struct P{
	int a,b;
	inline bool operator<(P x)const{return a<x.a;}
}c[200009];
int main(){
	int n,i,j,x=2e9,y=0,z=2e9,w=0,ans2=2e9;
	long long ans1;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%d%d",&c[i].a,&c[i].b);
		if(c[i].a>c[i].b)j=c[i].a,c[i].a=c[i].b,c[i].b=j;
		x=min(x,c[i].a),y=max(y,c[i].b);
		z=min(z,c[i].b),w=max(w,c[i].a);
	}
	ans1=(w-x)*1ll*(y-z),y-=x;
	sort(c+1,c+n+1);
	for(i=1,j=2e9;i<n;++i){
		j=min(c[i].b,j);
		w=max(w,c[i].b);
		x=min(j,c[i+1].a);
		ans2=min(ans2,w-x);
	}
	printf("%lld\n",min(ans1,ans2*1ll*y));
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  int a[n];
  bool flag=true;
  REP(i,n){
    cin>>a[i];
    if(a[i]%2==1){
      flag = false;
    }
  }
  if(flag){
    cout<<"second"<<endl;
  }else{
    cout<<"first"<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i, 10000) cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <time.h>
struct card
{
    char x;
    int num;
};
typedef struct card card;
void SelectionSort(card *p,int n);
void BubbleSort(card *p,int n);
int isStable(card *p,card *q,int n);
int main ()
{
    int number,i;
    card p[100],r[100],q[100];
    scanf("%d",&number);
    for(i = 0; i < number ; i++)
    {
        scanf(" %c%d",&p[i].x,&p[i].num);
    }
    for(i = 0;i < number;i++)
    {
        r[i] = p[i];
        q[i] = p[i];
    }
    BubbleSort(p,number);
    printf("Stable\n");
    SelectionSort(r,number);
    if(isStable(q,r,number))
    printf("Stable\n");
    else
    printf("Not stable\n");

    return 0;
}
void BubbleSort(card *p,int n)
{
    int i,j;
    card temp;
    for(i = 0;i < n - 1;i++)
    {
        for(j = n - 1;j > i;j--)
        {
            if(p[j].num<p[j-1].num)
            {
                temp = p[j];
                p[j] = p[j-1];
                p[j-1] = temp;

            }
        }
    }
    for(i = 0;i < n;i++)
    {
        if(i>0)printf(" ");
        printf("%c%d",p[i].x,p[i].num);
    }
    printf("\n");
}
void SelectionSort(card *p,int n)
{
    int i,j,k;
    card temp;
    for(i = 0;i < n - 1;i++)
    {
        k = i;
        for(j = i;j < n;j++)
        {
            if(p[j].num<p[k].num)
                k = j;
        }
        if(k!=i)
        {
            temp = p[k];
            p[k] = p[i];
            p[i] = temp;
        }
    }
    for(i = 0;i < n;i++)
    {
        if(i>0)printf(" ");
        printf("%c%d",p[i].x,p[i].num);
    }
    printf("\n");
}
int isStable(card *p,card *q,int n)
{


    int i, j ,a ,b;
     for(i=0;i < n;i++)
        for(j = i+1;j < n;j++)
            for(a = 0;a < n;a++)
                for(b = a+1;b < n;b++)
                if(p[i].num == p[j].num&&p[i].x==q[b].x&&p[j].x==q[a].x&&p[i].num==q[b].num&&p[i].num==q[b].num)
                 return 0;
    return 1;

}



Measured memory_bytes: 2120
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000

int main() {
    int N;
    cin >> N;
    ll MOD = pow(10, 9) + 7;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    ll res = 0;
    ll twos = 1;
    rep(j, 60) {
        ll even = 0, odd = 0;
        rep(i, N) {
            if (A[i] & ((ll)1 << j))
                odd++;
            else
                even++;
        }
        ll add = (odd * even) % MOD * twos % MOD;
        res += add;
        res %= MOD;
        twos = twos * 2 % MOD;
    }

    cout << res << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>

int sumDigit(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(void){
  int n;
  scanf("%d", &n);
  int sum = sumDigit(n);
  if(n % sum == 0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A - 1) / D < (C - 1) / B){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3592
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
a,b,k = map(int, input().split())

for i in range(0,k):
  if i%2==0:
    if a%2==1:
      a=a-1
    a = a /2
    b=b+a
  else:

    if b%2==1:
      b=b-1
    b=b/2
    a=a+b
print("%d %d"%(int(a),int(b)))


Measured memory_bytes: 3060
S = list(map(str, input()))
unreadble = 0
for i in range(len(S)):
  if i % 2 == 0:
    if S[i] == "L":
      unreadble += 1
  else:
    if S[i] == "R":
  	  unreadble += 1
if unreadble >= 1:
  print("No")
else:
  print("Yes")

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

const long INF = (1LL << 55);

namespace hidden {
  std::stack<void*> pstack;
};
void push(void* p) {
  hidden::pstack.push(p);
}
void pop() {
  hidden::pstack.pop();
}

template<typename TWeight = int>
class Network {
public:
  Network() {}
  std::vector< std::tuple<int, TWeight> > *edges;
  int v;
};

template<typename TWeight = int>
Network<TWeight> initNetwork(int v) {
  Network<TWeight> network;
  network.edges = new std::vector< std::tuple<int, TWeight> > [v + 3];
  network.v     = v + 3;
  return network;
}

template<typename TWeight = int>
void deleteNetwork(Network<TWeight> network) {
  if( network.edges == nullptr ) {
    delete [] network.edges;
  }
}

template<typename TWeight = int>
void addEdge(int from, int to, TWeight weight) {
  auto *network = (Network<TWeight>*)hidden::pstack.top();
  network->edges[from].push_back(std::make_tuple(to, weight));
}

template<typename TWeight = int>
std::vector<TWeight> dijkstra(Network<TWeight> network, int source) {
  std::vector<TWeight> res(network.v, INF);
  res[source] = 0;
  std::priority_queue< std::tuple<TWeight, int> > q;
  q.push(std::make_tuple(0, source));
  while( not q.empty() ) {
    TWeight dist; int id;
    std::tie(dist, id) = q.top(); q.pop();
    dist = -dist;
    for(auto edge : network.edges[id]) {
      int next; TWeight weight;
      std::tie(next, weight) = edge;
      auto nextdist = dist + weight;
      if( nextdist >= res[next] ) continue;
      res[next] = nextdist;
      q.push(std::make_tuple(-nextdist, next));
    }
  }
  return res;
}

int main() {
  int v, e, r;
  scanf("%d %d %d", &v, &e, &r);
  auto network = initNetwork<long>(v);
  push(&network);
  for(int i = 0; i < e; ++i) {
    int s, t; long d;
    scanf("%d %d %ld", &s, &t, &d);
    addEdge(s, t, d);
  }
  pop();
  auto dists = dijkstra(network, r);
  for(int i = 0; i < v; ++i) {
    if( dists[i] != INF ) {
      printf("%ld\n", dists[i]);
    }
    else {
      puts("INF");
    }
  }
}

Measured memory_bytes: 19412
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, k;
LL a[1010];
LL sum = 0;

bool cond(LL d){
    vector<LL> v;
    for(int i = 1;i <= n;i++)v.emplace_back(a[i]%d);
    sort(ALL(v));
    vector<LL> rui(n + 1, 0);
    for(int i = 1;i <= n;i++){
        rui[i] = rui[i - 1] + v[i - 1];
    }
    for(int i = 0;i <= n;i++){
        LL a = rui[i];
        LL b = (n - i)*d - (rui[n] - rui[i]);
        //cout << d << " " << a << " " << b << endl; 
        if(max(a, b) <= k)return true;
    }
    return false;
}

int main(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        sum += a[i];
    }
    LL ans = 0;
    for(LL i = 1;i * i <= sum;i++){
        if(sum % i == 0){
            if(cond(i))ans = max(ans, i);
            if(cond(sum/i))ans = max(ans, sum/i);
        }
    }
    cout << ans << endl;
}

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if(a+b>=k) ans = min(a,k);
    else ans = a -(k-a-b);
    cout <<  ans << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int A, B, X;

	cin >> A>>B>>X;

	cout << ((A<= X && X-A <=B) ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<math.h>
using namespace std;

int main(){
    string S;
    cin >> S;
    int num[150]={};
    sort(S.begin(), S.end());
    for(int i=0; i<S.size(); i++){
        num[(int)S.at(i)]++;
        //cout << (int)S.at(i) << endl;
    }
    bool frag=false;
    for(int i=97; i<=97+25; i++){
        if(num[i]==0){
            cout << (char)i << endl;
            frag=true;
            break;
        }
        //cout << num[i] << endl;
    }
    
    if(frag==false){
        cout << "None" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n, ans = 1e9;
void solve()
{
    cin >> n;
    for( int i = 1; i <= n / 2; i ++ )
    {
        ll x = i, z = n - i, sx = 0, sz = 0;
        while( x )sx += x % 10, x /= 10;
        while( z )sz += z % 10, z /= 10;
        ans = min( ans, sz + sx );
    }
    cout << ans;
}
int main()
{

	/*cin >> tests;
	while( t -- )*/
	    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int f[1000001];

int main() {
    int n;
    cin >> n;
    int a[n];

    

    rep(i,n){
        cin >> a[i];
        f[a[i]]++;
    }
    sort(a,a+n);
    int ans = 0;

    srep(i,1,1000001){
        if(f[i] == 0) continue;
        if(f[i] >= 2) continue;
        int flag = 1;
        srep(j,2,i){
            if(j*j > i)break;
            if(i % j == 0 && f[j] > 0){
                flag = 0;
                break;
            }
            if(i % j == 0 && f[i/j] > 0){
                flag = 0;
                break;
            }
        }
        if(i >= 2 && f[1] >= 1) flag = 0;
        ans+= flag;
    }

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




Measured memory_bytes: 8280
<?php
list($n,$k)=explode(" ",trim(fgets(STDIN)));
$i=0;
while($n>$i){
  $h[]=trim(fgets(STDIN));
  ++$i;
}
sort($h);
$j=0;
--$k;
$ans=pow(10,9)+7;
while($k<$n){
  $ans=min($ans,$h[$k]-$h[$j]);
  ++$j;
  ++$k;
}
echo $ans;

Measured memory_bytes: 12792
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#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 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	int n,m;
	cin >> n >> m;
	cout << ((n*(n-1))/2)+((m*(m-1))/2) << endl;
	return 0;
}

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

int  W, H, K;
int J[1001][1001] = {0};
int O[1001][1001] = {0};
int I[1001][1001] = {0};
string m[1001];

// [x1,x2] && [y1,y2] の領域の総和を計算する.
int sum_J(int x1, int y1, int x2, int y2){
	return J[y1][x1] - J[y1][x2+1] - J[y2+1][x1] + J[y2+1][x2+1];
}
int sum_O(int x1, int y1, int x2, int y2){
	return O[y1][x1] - O[y1][x2+1] - O[y2+1][x1] + O[y2+1][x2+1];
}
int sum_I(int x1, int y1, int x2, int y2){
	return I[y1][x1] - I[y1][x2+1] - I[y2+1][x1] + I[y2+1][x2+1];
}

int main(){
	cin >> H >> W >> K;
	for(int y = 0; y < H; y++){
		cin >> m[y];
	}
	
	for(int y = 0; y < H; y++){
		for(int x = 0; x < W; x++){
			J[y][x] = (m[y][x] == 'J')? 1 : 0;
			O[y][x] = (m[y][x] == 'O')? 1 : 0;
			I[y][x] = (m[y][x] == 'I')? 1 : 0;
		}
	}
	// 累積和の計算
	for(int y = 0 ; y < H ; y++ ){
		for(int x = W-1 ; x >= 0 ; x-- ){
			J[y][x] += J[y][x+1];
			O[y][x] += O[y][x+1];
			I[y][x] += I[y][x+1];
		}
	}
	for(int y = H-1 ; y >= 0 ; y-- ){
		for(int x = 0 ; x < W ; x++ ){
			J[y][x] += J[y+1][x];
			O[y][x] += O[y+1][x];
			I[y][x] += I[y+1][x];
		}
	}
	
	for(int i = 0; i < K; i++){
		int x1, y1, x2, y2;
		cin >> y1 >> x1 >> y2 >> x2;
		x1--; y1--; x2--; y2--;
		cout << sum_J(x1, y1, x2, y2) << " " << sum_O(x1, y1, x2, y2) << " " << sum_I(x1, y1, x2, y2) << endl;
	}
}

Measured memory_bytes: 13948
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define MAX 1000000

int main(){
	int a[MAX+1];
	for(int i=0; i<=MAX+1; i++) a[i]=0;
	int s, cnt=1;
	cin >> s;
	a[s]++;
	while(1){
		if(s%2==0) s/=2;
		else s=3*s+1;
		a[s]++;
		cnt++;
		if(a[s]>=2) break;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main() {
for (int i = 0; i < 50; i++){
int M, F, R; 
cin >> M >> F >> R; 
if(M == -1 && F == -1 && R == -1) break; 
else if(M == -1 || F == -1) cout << "F" << endl; 
else if(M + F >= 80) cout << "A" << endl; 
else if(M + F >= 65) cout << "B" << endl; 
else if(M + F >= 50) cout << "C" << endl;
else if(M + F >= 30 && R >= 50) cout << "C" << endl; 
else if(M + F >= 30 && R < 50) cout << "D" << endl; 
else if(M + F < 30) cout << "F" << endl; 
}
}


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


using namespace std;
using ll = long long;
const int N = 1e6 + 600;



int n ,k;
string str;
int main() {
    cin >> n >> k >> str;
    int indx = 0;
    char c = str[indx];
    int ans = 0;
    while(k){
            while(indx < str.size() && str[indx] == c)
                    indx++;
            if(indx != str.size()){
                    char t = str[indx];
                    while(indx < str.size() && str[indx] == t)
                           str[indx] = c, indx++;
                    k--;
                    if(!k)break;
            }
            else
                break;
    }
    for(int i = 0; i < str.size() - 1; ++i){
            if(str[i] == str[i + 1])
                    ans++;
    }
    cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main() {
	int k, n;
	cin >> n >> k;
	vector<int> v_inputs(n);
	for (int i = 0; i < n; ++i) {
		cin >> v_inputs[i];
	}
	sort(v_inputs.begin(), v_inputs.end());

	int score = 0;
	for (int i = 0; i < k; ++i) {
		score += v_inputs[i];
	}

	cout << score << endl;

	return 0;
}

Measured memory_bytes: 3164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()){
			char[] b = stdIn.next().toCharArray();
			if((b[0]!='s')&&((b[0]==b[1]&&b[1]==b[2])||
					(b[0]==b[3]&&b[3]==b[6])||
					(b[0]==b[4]&&b[4]==b[8]))){
				System.out.println(b[0]);
			}
			else if((b[4]!='s')&&((b[3]==b[4]&&b[4]==b[5])||
					(b[1]==b[4]&&b[4]==b[7])||
					(b[2]==b[4]&&b[4]==b[6]))){
				System.out.println(b[4]);
			}
			else if((b[8]!='s')&&((b[6]==b[7]&&b[7]==b[8])||
					(b[2]==b[5]&&b[5]==b[8]))){
				System.out.println(b[8]);
			}
			else{
				System.out.println("d");
			}
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    cout << max(A + B, max(A - B, A * B));
    return 0;
}


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

from sys import stdin


ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()

a_list = []
for _ in range(H):
    a_list.append(na())
a_list.append([0]*W)  # for simple loop code

operation = []
for y in range(H):
    if y % 2 == 0:
        for x in range(W-1):
            if a_list[y][x] % 2 == 1:
                a_list[y][x+1] += 1
                operation.append([y+1, x+1, y+1, x+2])
        if a_list[y][W-1] % 2 == 1:
            a_list[y+1][W-1] += 1
            operation.append([y+1, W, y+2, W])
    else:
        for x in range(W-1, 0, -1):
            if a_list[y][x] % 2 == 1:
                a_list[y][x-1] += 1
                operation.append([y+1, x+1, y+1, x])
        if a_list[y][0] % 2 == 1:
            a_list[y+1][0] += 1
            operation.append([y+1, 1, y+2, 1])

if operation != [] and operation[-1][2] == H+1:
    operation.pop()

# Result
print(len(operation))
for op in operation:
    print(op[0], op[1], op[2], op[3])


Measured memory_bytes: 30276
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
    ll N;
    cin >> N;
    ll max_i = static_cast<ll>(sqrt(N));
    vector<ll> candidates;
    for (ll i = 1; i <= max_i+1; i++) {
        if (N % i == 0) {
            candidates.push_back(i);
        }
    }

    ll ans = 2 * N;
    for (auto c : candidates) {
        ll c_ans = (c - 1) + (N / c - 1);
        if (c_ans < ans) ans = c_ans;
    }

    if (ans == 2 * N) {
        cout << 0 << endl;
        return 0;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	Scanner scan = new Scanner(System.in);
	double[] x;
	double[] y;
	public void run(){
		while(scan.hasNext()){
			String[] str = scan.next().split(",");
			x = new double[4];
			y = new double[4];
			for(int i = 0,k = 0;i < 8;i+=2){
				x[k] = Double.parseDouble(str[i]);
				y[k++] = Double.parseDouble(str[i+1]);
			}
			System.out.println(((check(0)&check(1)&check(2)&check(3))?"YES":"NO"));
		}
	}
	public boolean check(int p){
		int t = 0;
			t += ((x[p]*(y[(p+1)%4] - y[(p+2)%4]) + x[(p+1)%4]*(y[(p+2)%4] - y[p]) + x[(p+2)%4]*(y[p] - y[(p+1)%4])) >= 0)?1:-1;
			t += ((x[p]*(y[(p+2)%4] - y[(p+3)%4]) + x[(p+2)%4]*(y[(p+3)%4] - y[p]) + x[(p+3)%4]*(y[p] - y[(p+2)%4])) >= 0)?1:-1;
			t += ((x[p]*(y[(p+3)%4] - y[(p+1)%4]) + x[(p+3)%4]*(y[(p+1)%4] - y[p]) + x[(p+1)%4]*(y[p] - y[(p+3)%4])) >= 0)?1:-1;
		return ((t==3) || (t==-3))?false:true;
	}
}

Measured memory_bytes: 17304
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    all_odd = 1
    for i in A:
        if i % 2 == 0:
            all_odd *= 2
        else:
            all_odd *= 1

    print(3 ** N - all_odd)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10112
#include <stdio.h>
#include <string.h>


int main(void){
  char s[500001];
  int len;
  scanf("%s",s );
  len=strlen(s);
  //printf("%d\n",len );

  int a[len+1],b[len+1],main[len+1];
  int count;
  long long sum;
//初期化
  for (int i = 0; i < len+1; i++) {
    a[i]=0;
    b[i]=0;
  }

  for (int i = 0; i < len; i++) {
    count=1;
    while (s[i]=='<') {
      a[i+1]=count;
      count++;
      //printf("%d",i );
      if (i>len) {
        break;
      }
      i++;
    }
  }
//puts("");

  for (int i = len; i >=0; i--) {
    count=1;
    while (s[i]=='>') {
      b[i]=count;
      count++;
      //printf("%d",i );
      if (i<=0) {
        break;
      }
      i--;
    }
  }
//puts("");



  for (int i = 0; i < len+1; i++) {
    if (a[i]>=b[i]) {
      main[i]=a[i];
    }else{
      main[i]=b[i];
    }
  }

  for (int i = 0; i < len+1; i++) {
    sum+=main[i];
  }
  //printf("%d",main[len+1] );
  //printf("\n");
  printf("%lld\n",sum );

  return 0;
}


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

using namespace std;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
int sub(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);

const int N=500001;
int fa[N];
vi adj[N];
int get(int x){
	if(fa[x]==x)return x;
	return fa[x]=get(fa[x]);
}

void merge(int x,int y){
	x=get(x),y=get(y);
	fa[y]=x;
}
vector<pi>ans;
int cnt[N];
void dfs(int u,int p){
	for(auto i:adj[u]){
		if(i!=p)
		dfs(i,u);
	}
	if(cnt[u]&1){
		if(p==-1)return;
		ans.pb(mp(u,p));
		cnt[u]++;
	}
	else{
		if(p==-1)return;
		ans.pb(mp(p,u));
		cnt[p]++;
	}
}
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)fa[i]=i;
	
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		if(get(x)==get(y)){
			ans.pb(mp(x,y));
			cnt[x]++;
		}
		else{
			merge(x,y);
			adj[x].pb(y);
			adj[y].pb(x);
		}

	}
	if(m&1){
		cout<<"-1";
		return;
	}
	dfs(0,-1);
	for(auto i:ans)cout<<i.F+1<<' '<<i.S+1<<"\n";
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//cin>>tc;
	for(int _=0;_<tc;_++){
		//cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}

int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}

void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}

int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}

int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;
}


Measured memory_bytes: 23540
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int N=1e5+5;
vector<int>ve[N];
priority_queue<int>qe;
int main()
{
	int n,m;
	cin>>n>>m;
	int a,b;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(m-a+1<1)continue;
		ve[m-a+1].push_back(b);
	}
	int anx=0;
	for(int i=m;i>=1;i--){
		for(int j=0;j<ve[i].size();j++){
			qe.push(ve[i][j]);
		}
		if(!qe.empty()){
			anx+=qe.top();qe.pop();
		}
	}
	cout<<anx<<"\n";
}

Measured memory_bytes: 8468
#include <iostream>
#include <cstring>
#define MAXNUM 110
using namespace std;
char S[MAXNUM];
char T[MAXNUM];
int main()
{
    memset(S,0,sizeof(S));
    memset(T,0,sizeof(T));
    cin>>S>>T;
    bool flag = false;
    int length = strlen(S);
    int i;
    int point_t;
    int j;
    for(i=0;i<length;i++)
    {
        point_t = 0;
        for(j=0;j<length;j++)
        {
            if(T[point_t]!=S[(i+j+length)%length])
                break;
            point_t++;
        }
        if(point_t==length)
        {
            flag = true;
            break;
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int t;
    int c;
    t = n;
    c = 0;
    while(t>0){
        c += t%10;
        t /=10;
    }
    if(n%c==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}




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

int main(){
  string s;
  cin >> s;
  
  if (s == "ABC")
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
  
  return 0;
}

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


#define li          long long int
#define uli         unsigned long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n,k;
li r,s,p;
string t;

int main() {
    cin>>n>>k;
    cin>>r>>s>>p;
    cin>>t;
    li res=0;
    rin{
        if (i>=k && t[i]==t[i-k]){
            // gaman
            t[i]='a';
        } else {
            if(t[i]=='r'){
                res+=p;
            }else if(t[i]=='s'){
                res+=r;
            }else{
                res+=s;
            }
        }
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
using namespace std;
ll int l(ll int x,ll int *b,ll int m,ll int k)
{
	ll int l=0,r=m,ans=-1;
	while(l<=r)
	{
		ll int mi=l+(r-l)/2;
		if (b[mi]<=x)
		{
			ans=mi;
			l=mi+1;
			
		}
		else
		r=mi-1;
		
	}
	return ans;
}
int main()
{
	ll int n,m,k;
	cin>>n>>m>>k;
	ll int a[n+1],b[m+1],s=0;
	a[0]=0;
	b[0]=0;
	for(int i=0;i<n;i++)
	{
		ll int x;
		cin>>x;
		s+=x;
		a[i+1]=s;
		
	}
	s=0;
	for(int i=0;i<m;i++)
	{
		ll int x;
		cin>>x;
		s+=x;
		b[i+1]=s;
	}
	ll int ans=0,r=m;
	for(int i=0;i<=n;i++)
	{
		if(a[i]>k)
		break;
		while(b[r]>k-a[i])
		r-=1;
		ans=max(ans,i+r);
	
	}
	cout<<ans<<endl;
	
	
	
}
    
	
		

	
			

		


 






Measured memory_bytes: 6748
n=int(input())
p=list(map(int,input().split()))
res=0
for i in range(n-2):
	if p[i]<p[i+1] and p[i+1]<p[i+2]:
		res+=1
	elif p[i]>p[i+1] and p[i+1]>p[i+2]:
		res+=1
print(res)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
	  freopen("input.txt","r",stdin);
	  freopen("output.txt","w",stdout);
    #endif
	int n;
	cin>>n;
	int flag=0;
	while(n!=0)
	{
		if(n%10==7)
		{
			flag=0;
			break;
		}
		else flag=1;
		
	n=n/10;
	}
	if(flag==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
 
int main(void){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    {
        int cnt = 0;
        while (a >= b && cnt < k) {
            b *= 2;
            cnt++;
        }
        while (b >= c && cnt < k) {
            c *= 2;
            cnt++;
        }
    }

    if (a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

a=[int(0)]
a+=[int(input()) for i in range(N)]
s=sum(a)
a.sort()
frag=0

for i in range(N+1) :
    if a[i]%10!=0 :
        frag+=1

    
if frag!=0 :
    for i in range(N) :
        if (s-a[i])%10!=0 :
            s-=a[i]
            break



if frag==0 :
    print(int(0))
else :
    print(s)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  if(vec.at(N / 2 - 1) == vec.at(N / 2)){
    cout << 0 << endl;
  }
  else{
    cout << vec.at(N / 2) - vec.at(N / 2 - 1) << endl;
  }
}

Measured memory_bytes: 640
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
     	int n = scan.nextInt();
      	int m = scan.nextInt();
      	int x = scan.nextInt();
      	int[] A = new int[m];
      	int smallcounter = 0;//the number which smaller than x
      	int bigcounter = 0;//the number which larger than x
      	for(int i = 0; i < m; i++){
        	A[i] = scan.nextInt();
          	if(A[i] < x){
            	smallcounter++;
            }
          	else{
            	bigcounter++;
            }
        }
      	if(smallcounter < bigcounter){
        	System.out.print(smallcounter);
        }
      	else{
        	System.out.print(bigcounter);
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 100001;
ll dp[101][MAX] = {};

struct item{
    ll w,v;
};

item lis[101];

int main() {
    

    ll n,w;
    cin >> n >> w;
    for (ll i=1;i<=n;i++){
        item p;
        cin >> p.w >> p.v;
        lis[i] = p;
    }
    for (ll i=1;i<=n;i++){
        for (ll j=1;j<=w;j++){
            ll pre, post;
            pre = dp[i-1][j];
            if(j - lis[i].w >= 0){
                post = dp[i-1][j-lis[i].w] + lis[i].v;
                dp[i][j] = max(pre, post);
            }else{
                dp[i][j] = pre;
            }
        }
    }
    cout << dp[n][w] << endl;
}




Measured memory_bytes: 78336
#include <string>
#include <fstream>
#include <streambuf>
#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    string s;
    int k;
    cin>>s;
    cin>>k;
    for (int i=0; i<s.length(); i++) {
        if (s[i]=='a') {
            continue;
        }
        if (k>='z'+1-s[i]) {
            k=k-('z'+1-s[i]);
            s[i]='a';
            continue;
        }
        
    }
    long last=s.length()-1;
    s[last]='a'+(s[last]-'a'+k)%26;
    cout<<s<<endl;
   
    return 0;
}


Measured memory_bytes: 512
import java.nio.Buffer;
import java.util.*;
import java.io.*;

public class Main {
    static long [] map=new long[100001];
    static long [] ans=new long[100001];
    static int max2=987654321;
    static long dp(int N){
        if(N<=1) return 0;
        if(ans[N]!=max2) return ans[N];
        ans[N]=Math.min(ans[N],dp(N-1)+Math.abs(map[N-1]-map[N]));
        ans[N]=Math.min(ans[N],dp(N-2)+Math.abs(map[N-2]-map[N]));
        return ans[N];
    }
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        for(int i=1;i<=N;i++){
            map[i]=sc.nextLong();
            ans[i]=max2;
        }
        ans[1]=0;
        ans[2]=Math.abs(map[1]-map[2]);
        long k=dp(N);
        System.out.println(k);

    }
}

Measured memory_bytes: 82120