akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


long long int MOD = 1000000007;

long long int p[2000006], inv_p[2000006];

long long int POW(long long int x, long long int k) {

	if (k == 0) { return 1; }

	if (k % 2 == 1) { return (POW(x, k - 1)*x) % MOD; }

	long long int tmp = POW(x, k / 2);

	return (tmp*tmp) % MOD;
}

long double C(int n, int m) {
	
	long long int tmp = p[n];

	tmp = (tmp*inv_p[n - m]) % MOD;
	tmp = (tmp*inv_p[m]) % MOD;

	return tmp;
}

int main(void) {

	long long int X, Y;

	cin >> X >> Y;

	p[0] = 1;
	p[1] = 1;
	for (int i = 2; i <= 2000000; i++) {
		p[i] = p[i - 1] * i;
		p[i] %= MOD;
	}

	for (int i = 0; i <= 2000000; i++) {
		inv_p[i] = POW(p[i], MOD - 2);
	}

	/*for (int i = 1; i <= 10; i++) {
		cout << i << " " << p[i] << " " << inv_p[i] << " " << (p[i] * inv_p[i]) % MOD << endl;
	}*/


	long long int a, b;

	

	if ((X*2-Y)<0 || (X * 2 - Y) % 3 != 0) { cout << 0 << endl; return 0; }

	if ((-X + 2 * Y) < 0 || (-X + 2 * Y) % 3 != 0) { cout << 0 << endl; return 0; }

	a = (-X + 2 * Y) / 3;
	b = (X * 2 - Y) / 3;

	long int ans = 0;

	ans = C(a + b, a);

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 31616
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long A = sc.nextLong();
   long B = sc.nextLong();
   long ans = 0;
   long N = gcd(A,B);
   boolean flg = false;
   for(int k = 1;k<=Math.sqrt(N);k++)
   {
     flg = true;
     if(A%k==0&&B%k==0) 
     {
       for(int i = 2;i<=Math.sqrt(k);i++)
       {
         if(k%i==0) 
         {
           flg = false;
           break;
         }
       }
       if(flg) ans++;
       flg = true;
     }
     if(A%(N/k)==0&&B%(N/k)==0&&N!=1) 
     {
       for(int i = 2;i<=Math.sqrt(N/k);i++)
       {
         if((N/k)%i==0) 
         {
           flg = false;
           break;
         }
       }
       if(flg) ans++;
       flg = true;
     }
   }
  System.out.println(ans);
 }
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}

Measured memory_bytes: 22356
#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;}

const int64 mod = 1e9+7;

using Row = vector<int64>;
using Mat = vector<Row>;

int32 dp[112345] = {};
int32 N;
vector<int32> a;

int32 dfs(int32 rest){
	if(~dp[rest]) return dp[rest];
	if(rest < a[0]) return 0;
	dp[rest] = 0;
	REP(i, a.size()){
		if(rest >= a[i])
			dp[rest] |= (dfs(rest-a[i]) == 0);
	}
	return dp[rest];
}

int main(void){
	memset(dp, -1, sizeof dp);
	int64 K;
	cin >> N >> K;
	a.resize(N);
	REP(i, N) cin >> a[i];
	cout << (dfs(K) ? "First" : "Second") << endl;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b;
  cin >> a >> b;
  if (a > b * 2)
    cout << a - b * 2 << endl;
  else
    cout << 0 << endl;
}

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

int main() {
    string s; cin >> s;
    int N = s.size() + 1;
    vector<ll> A(N);
    for(int i=0;i<N-1;++i) {
        if(s[i]=='<') A[i+1]=A[i]+1; 
    }
    for(int i=N-2;i>=0;--i) {
        if(s[i]=='>') A[i]=max(A[i],A[i+1]+1);
    }
    ll ans = 0;
    for(int i=0;i<N;++i) ans += A[i];
    cout << ans << endl;
}

Measured memory_bytes: 4740
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N = lread();
    auto A = new long[](N);
    auto B = new long[](N);
    foreach (i; 0 .. N)
        scan(A[i], B[i]);
    A.sort();
    B.sort();
    long m = (N & 1) ? A[N / 2] : A[N / 2] + A[N / 2 - 1];
    long M = (N & 1) ? B[N / 2] : B[N / 2] + B[N / 2 - 1];
    writeln(M - m + 1);
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#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 RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

constexpr int H_MAX = 400;
constexpr int W_MAX = 400;
int H, W;
string s[H_MAX];
bool used[H_MAX][W_MAX];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main(void) {
    cin >> H >> W;
    REP(i, H) cin >> s[i];

    ll result = 0;

    // for check
    ll count_all_black = 0;
    ll count_all_white = 0;

    REP(i, H) REP(j, W) {
        if (!used[i][j]) {
            PRINT("New");
            queue<pii> q;
            q.push(pii(i, j));
            used[i][j] = true;
            ll count_black = 0;
            ll count_white = 0;
            while (!q.empty()) {
                int x, y;
                tie(x, y) = q.front();
                PRINT(x);
                PRINT(y);
                q.pop();
                char c = s[x][y];
                if (c == '#') {
                    count_black++;
                } else if (c == '.') {
                    count_white++;
                } else {
                    assert(0);
                }
                REP(k, 4) {
                    int nx = x + dx[k];
                    int ny = y + dy[k];
                    if (0 <= nx && nx < H && 0 <= ny && ny < W && !used[nx][ny] && s[nx][ny] != c) {
                        q.push(pii(nx, ny));
                        used[nx][ny] = true;
                    }
                }
            }
            PRINT(count_black);
            PRINT(count_white);
            result += count_black * count_white;

            count_all_black += count_black;
            count_all_white += count_white;
        }
    }
    assert(count_all_black + count_all_white == H * W);
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

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


Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

if b <= c or d <= a: # abcd, cdab
    print(0)
elif a <= c:
    if b <= d: # acbd
        print(b-c)
    else: # acdb
        print(d-c)
else:
    if b <= d: # cabd
        print(b-a)
    else: # cadb
        print(d-a)


Measured memory_bytes: 2940
import math
x = int(input())

def prime(x):
    if x == 2:
        return True
    elif x % 2 == 0:
        return False
    elif x > 2:
        for i in range(3, math.floor(math.sqrt(x))+1,2):
            if x % i == 0:
                return False
        return True
while prime(x) != True :
    x += 1
print(x)


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

int main(){
    string s;
    cin >> s;
    bool ok = false;
    rep(i,2){
        if(s[i]!=s[i+1]) ok=true; 
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 1000005
typedef long long int ll;
int main()
{
    int i,j,k,a,b,n,m,f,p;
    string str;
    in2(n,m);
    vi v(n);
    read(v,i,n);
    vii vp(m);
    rep(i,m)
        in2(vp[i].S,vp[i].F);
    asc(v);
    asc(vp);
    reverse(all(vp));
    j=0;
    rep(i,m)
    {
        a=vp[i].F,b=vp[i].S;
        while(j<n & v[j]<a & b>0)
            v[j]=a,b--,j++;
        if(j==n | v[j]>a)
            break;
    }
    ll ans=0;
    rep(i,n)
        ans+=v[i];
    outl(ans);


}


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

#define watch(x) cout<<#x<<" -> "<<x<<endl
#define ALL(x) x.begin() , x.end()
#define INF 100000

typedef long long ll;

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    long long sum = 0;
        cin>>s;
        for (int i = 0; i < s.size(); i++){
            sum = sum + (s[i]-'0');
        }
        if (sum % 9 == 0){
            cout<<"Yes"<<endl;
            return 0;
        }
        cout<<"No"<<endl;
}



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

#define Debug(x) x
typedef int regular_int;
// #define int ll
typedef long long ll;

template <int MOD=1000000007>
struct mint {
  int value;
  static const int MOD_value = MOD;

  mint(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
  mint(long long a, long long b) : value(0){ *this += a; *this /= b;}

  mint& operator+=(mint const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
  mint& operator-=(mint const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
  mint& operator*=(mint const& b) {value = (long long)value * b.value % MOD;return *this;}

  friend mint mexp(mint a, long long e) {
    mint res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
    return res;
  }
  friend mint inv(mint a) { return mexp(a, MOD - 2); }

  mint& operator/=(mint const& b) { return *this *= inverse(b); }
  friend mint operator+(mint a, mint const b) { return a += b; }
  friend mint operator-(mint a, mint const b) { return a -= b; }
  friend mint operator-(mint const a) { return 0 - a; }
  friend mint operator*(mint a, mint const b) { return a *= b; }
  friend mint operator/(mint a, mint const b) { return a /= b; }
  friend ostream& operator<<(ostream& os, mint const& a) {return os << a.value;}
  friend istream& operator>>(istream& is, mint const& a) {is >> a.value; return is;}
  friend bool operator==(mint const& a, mint const& b) {return a.value == b.value;}
  friend bool operator!=(mint const& a, mint const& b) {return a.value != b.value;}
};
typedef mint<1000000007> M;
M inv(int a) { return inv(M(a)); }

M f[1000020], as[1000020], bs[1000020];

M b(int n, int k){
    if (n < 0 || k < 0 || n < k){
        return 0;
    }
 //   cout << "b(" << n  << ", " << k << "): " << (((f[n] * inv(f[k])) % M) * inv(f[n - k])) % M << endl;
    return f[n] * inv(f[k]) * inv(f[n - k]);
}

regular_int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(12) << fixed;


    int N, A, B, C;
    cin >> N >> A >> B >> C;
    f[0] = f[1] = as[0] = bs[0] = 1;
    for (int i = 1; i < 3 * N + 5; ++i) {
        f[i] = f[i - 1] * i;
        as[i] = as[i - 1] * A * inv(A + B);
        bs[i] = bs[i - 1] * B * inv(A + B);
    }
    M res = 0;
    for (ll i = N; i < 2 * N; ++i){
        M p = i * 100 * inv(A + B) * b(i-1, N-1) * (as[N] * bs[i - N] + as[i - N] * bs[N]);
        res += p;
    }
    cout << res << endl;
	return 0;
}


Measured memory_bytes: 12032
#include <stdio.h>

int main(){
  int a[26],i,j;
  char ch;

  for(i=0;i<26;i++) a[i]=0;

  while(1){
    if(scanf("%c",&ch)==EOF) break;
    if(('A'<=ch)&&(ch<='Z')) ch+=('a'-'A');
    if(('a'<=ch)&&(ch<='z')) a[ch-'a']++;
  }
  for(i=0;i<26;i++) printf("%c : %d\n",i+'a',a[i]);
    
  return 0;
}

Measured memory_bytes: 540
#include <iostream>
using namespace std;
#define MAX 2000000
int H,A[MAX+1];
void maxHeapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
  if(l<=H &&A[l]>A[i]) largest = l;
  else largest = i;
  if(r<=H && A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}

int main(){
  cin >> H;
  for(int i=1;i<=H;i++) cin >> A[i];
  for(int i= H/2;i>=1;i--) maxHeapify(i);
  for(int i=1;i<= H;i++){
    cout <<" "<<A[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 4968
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long H, W, K;
    scan(H, W, K);
    auto C = new string[](H);
    foreach (i; 0 .. H)
        C[i] = sread();
    char[][] f(uint h, uint w)
    {
        auto ret = new char[][](H, W);
        foreach (i; 0 .. H)
            foreach (j; 0 .. W)
            {
                if ((h & (1 << i)) || (w & (1 << j)))
                {
                    ret[i][j] = 'r';
                }
                else
                {
                    ret[i][j] = C[i][j];
                }
            }
        return ret;
    }

    long eval(char[][] s)
    {
        long ret;
        foreach (i; 0 .. H)
            foreach (j; 0 .. W)
                ret += s[i][j] == '#';
        return ret;
    }

    long ans;
    foreach (i; 0 .. 1 << H)
        foreach (j; 0 .. 1 << W)
        {
            auto s = f(i, j);
            if (eval(s) == K)
                ans++;
        }
    writeln(ans);
}


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

for h in range(1, 3501):
    for n in range(1, 3501):
        num = N * h * n
        denom = 4 * h * n - N * n - N * h
        if denom > 0 and num % denom == 0:
            w = num // denom
            break
    else:
        continue
    break
print(h, n, w)


Measured memory_bytes: 40528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi   = vector<int>;
using vll  = vector<ll>;
using vc   = vector<char>;
using vvll  = vector<vll>;
using vvi  = vector<vi>;
using vvc  = vector<vc>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;


int main() {
    char alpha; cin >> alpha;
    int kind = alpha;
    int A = 'A', Z='Z';
    if(A <= kind && kind <= Z){
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }
}

Measured memory_bytes: 3576
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int p,q,a,n;
int ans;
int t[10];
 
void rec(int x,int y,int z){
  int sum=0;
  for(int i=0;i<x;i++){
    sum+=(y/t[i]);
  }
  if(sum*q==p*y){
    ans++;
  }else if(sum*q>p*y){
    return;
  }
 
  if(x==n)return;
  for(int i=z;i<=a;i++){
    if(y*i>a)break;
    t[x]=i;
    rec(x+1,y*i,i);
  }
}
 
int main(){
  while(1){
    scanf("%d %d %d %d",&p,&q,&a,&n);
    if(p==0&&q==0&&a==0&&n==0)break;
    ans=0;
    rec(0,1,1);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,a,b,k,c=0;
	cin>>a>>b>>k;
	if (a>b) swap(a,b);
	for (j=a;j>=1;j--)
	{
		if (a%j==0&&b%j==0)
		{
			c++;
			if (c==k) 
			{
				cout<<j;
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
ll n,cnt=1,MOD=(int)1e9+7;
bool isprime(int n) {
    if(n == 2)return true;
    if(n < 2 || n%2 == 0) return false;
    for(int i=3;i*i<=n;i+=2)
    	if(n%i == 0)
    		return false;
    return true;
}
int main() {
	cin>>n;
	loop(n+1,i,2){
		if(isprime(i)){
			ll j=1,res=0;
			while(pow(i,j)<=n){
//				cout<<pow(i,j)<<endl;
				res+=(n/pow(i,j++));
			}
			cnt*=((res+1)%MOD);
			cnt%=MOD;
		}
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=200100;
int n,a[maxn],q;
struct node
{
	int l,r;
}c[maxn];
bool cmp(node a,node b)
{
	if(a.l==b.l) return a.r>b.r;
	return a.l<b.l; 
}
struct tree
{
	int l,r,mi;
	tree *ls,*rs;
	tree()
	{
		ls=rs=NULL;
		l=r=mi=0;
	}
	void update()
	{
		mi=min(ls->mi,rs->mi);
	}
	void build(int lx,int rx)
	{
		l=lx;r=rx;
		if(l==r) {mi=(l==0)?0:maxn;return;}
		int mid=(l+r)>>1;
		(ls=new tree)->build(lx,mid);
		(rs=new tree)->build(mid+1,rx);
		update();
	}
	void mdf(int pl,int c)
	{
		if(l==r) {mi=min(mi,c);return;}
		int mid=(l+r)>>1;
		if(pl<=mid) ls->mdf(pl,c);
		else rs->mdf(pl,c);
		update();
	}
	int qry(int lx,int rx)
	{
		if(l==lx&&r==rx) return mi;
		int mid=(l+r)>>1;
		if(rx<=mid) return ls->qry(lx,rx);
		else if(lx>mid) return rs->qry(lx,rx);
		else return min(ls->qry(lx,mid),rs->qry(mid+1,rx));
	}
}*xtr;
int main()
{
	scanf("%d",&n);
	int num=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);	
		num+=(1-a[i]);
	}
	(xtr=new tree)->build(0,n);	
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
		scanf("%d%d",&c[i].l,&c[i].r);	
	sort(c+1,c+q+1,cmp);	
	c[0].l=1;
	int p=1;
	for(int i=1;i<=n;i++)
	{
		for(;c[p].l==i;p++)
			xtr->mdf(c[p].r,xtr->qry(c[p].l-1,c[p].r));
		xtr->mdf(i,xtr->qry(i-1,i-1)+2*a[i]-1);		
	}
	printf("%d",num+xtr->qry(n,n));
	return 0;
}

Measured memory_bytes: 21376
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

type Num struct {
	count int
	isOne bool
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	S := sc.nextRuneSlice()
	D := []Num{}
	now := S[0]
	cnt := 1
	for i := 1; i < N; i++ {
		if now == S[i] {
			cnt++
		} else {
			D = append(D, Num{cnt, now == '1'})
			if now == '1' {
				now = '0'
			} else {
				now = '1'
			}
			cnt = 1
		}
	}
	D = append(D, Num{cnt, now == '1'})
	ans, sum := 0, 0
	r := 0
	for l := 0; l < len(D); l++ {
		var nextRight int
		if D[l].isOne {
			nextRight = min(len(D), l+2*K+1)
		} else {
			nextRight = min(len(D), l+2*K)
		}
		for r < nextRight {
			sum += D[r].count
			r++
		}
		if ans < sum {
			ans = sum
		}
		sum -= D[l].count
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 7040
#include <iostream>
#include <queue>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;

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

    priority_queue<long, vector<long>, greater<long>> s;

    int cnt = 0;
    for(int i=1; i<=9; i++){
        s.push(i);
    }

    long ans;
    while(cnt != K){
        long now = s.top();
        s.pop();
        cnt++;
        if(cnt == K){
            ans = now;
            break;
        }

        long d = now - now/10*10;
        if(d%10 != 0) s.push(now*10+d-1);
        s.push(now*10+d);
        if(d%10 != 9)  s.push(now*10+d+1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2420
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
u=Counter(s)
for i in u.values():
    if i%2==0:
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    string s;
    cin >> s;
    int res = 0;
    rep(i, 3) {
        if(s[i]-'0') res++;
    }

    cout << res << endl;

    return 0;
}

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

int main() {
  int N, N_fake; // 入力の数字
  int order;
  int output = 0;
  cin >> N;
 
  // 桁数を求める
  N_fake = N;
  for (int i = 0; i < 10; i++){
    N_fake = N_fake / 10;
    if (N_fake == 0){
      break;
    }
    order ++;
  }
  
  // cout << "桁数は:" << order+1 << endl;

  N_fake = N;
  for (int i = 0; i < order+1; i++){
    int test;
    test = N_fake / std::pow(10,order-i);
    N_fake -= test * std::pow(10,order-i);
    // cout << test << endl;
    output += test;
  }

  if (N % output == 0){
    cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n;cin>>n;
    ll a[100001];rep(i,0,100000)a[i]=0;
    ll sum=0;
    rep(i,0,n-1){
        ll A;cin>>A;
        a[A]++;
        sum+=A;
    }
    ll q;cin>>q;
    rep(i,0,q-1){
        ll b,c;cin>>b>>c;
        sum+=(c-b)*a[b];
        a[c]+=a[b];
        a[b]=0;
        cout<<sum<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 4428
import numpy as np
H, W = map(int, input().split())
a = np.array([list(input()) for _ in range(H)])

# 行
del_index_0 = []
for i in range(H):
    if np.all(a[i]==['.']*W):
        del_index_0.append(i)
b = np.delete(a, del_index_0, axis=0)

# 列
del_index_1 = []
for i in range(W):
    if np.all(b[:,i]==['.']*(H-len(del_index_0))):
        del_index_1.append(i)
c = np.delete(b, del_index_1, axis=1)

for i in c:
    print(''.join(i))

Measured memory_bytes: 12540
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll a,b;
  cin>>a>>b;
  vector<ll> v;
  v.push_back(a);
  v.push_back(b);
  sort(ALL(v));
  if(v[0]==1){
    if(v[1]==2){
      cout<<3<<endl;
    }else{
      cout<<2<<endl;
    }
  }else{
    cout<<1<<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define rep1(i,N) for(int i=1;i<=(int)N;i++)
#define pb push_back
#define all(c) c.begin(),c.end()
#define show(x) cout<<#x<<" "<<x<<endl
#define chmax(x,y) x=max(x,y)
#define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
#define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);
using namespace std;
const int MN=100000;
struct edge {int to,w,rev;};
typedef vector< vector<edge> > Graph;
Graph G,oG;
void add_edge(int x,int y,int w,int way){
	if(way==1){
		G[x].pb({y,w,-1});
	}else{
		int X=G[x].size(),Y=G[y].size();
		G[x].pb({y,w,Y});
		G[y].pb({x,w,X});
	}
}

typedef pair<int,int> P;
int memo[300000][4];
bool vis[300000][4];
int inf=1e8;
int dfs(int v,int eid){
	eid++;
	if(memo[v][eid]!=-1) return memo[v][eid];
	if(vis[v][eid]){
		return inf;
//		puts("Infinite");
	}
	vis[v][eid]=1;
	int ret=0;
	// rep(i,G[v].size()) if(i!=eid-1){
	// 	edge& e=G[v][i];
	// 	chmax(ret,dfs(e.to,e.rev)+e.w);
	// }
	if(G[v].size()>0 && eid!=1) chmax(ret,dfs(G[v][0].to,G[v][0].rev)+G[v][0].w);
	if(G[v].size()>1 && eid!=2) chmax(ret,dfs(G[v][1].to,G[v][1].rev)+G[v][1].w);
	if(G[v].size()>2 && eid!=3) chmax(ret,dfs(G[v][2].to,G[v][2].rev)+G[v][2].w);
	memo[v][eid]=ret;
	return ret;
}

int rs[100001]={};
int its[100000]={};

int main(){
	BEGIN_STACK_EXTEND(128*1024*1024);
	int N,M;
	cin>>N>>M;
	oG.resize(N);
	rep(i,M){
		int x,y,w;
		scanf("%d %d %d",&x,&y,&w);
		x--,y--;
		if(w==1){
			oG[x].pb(edge{y,1,-1});
		}else{
			int X=oG[x].size(),Y=oG[y].size();
			oG[x].pb(edge{y,1,Y});
			oG[y].pb(edge{x,1,X});
		}
	}
	int newN=0;
	rep(i,N){
		int sz=oG[i].size();
		if(sz==0) sz=1;
		rs[i]=newN;
		its[i]=rs[i];
		newN+=sz;
	}
	rs[N]=newN;
	G.resize(newN);
	rep(x,N){
		int n=rs[x+1]-rs[x];
		for(int v=rs[x];v<rs[x]+n-1;v++) add_edge(v,v+1,0,2);
		for(edge e: oG[x]){
			if(e.rev==-1){	//one way
				add_edge(its[x],rs[e.to],1,1);
				its[x]++;
			}else{
				if(x<e.to){
					add_edge(its[x],its[e.to],1,2);
					its[x]++;
					its[e.to]++;
				}
			}
		}
	}
	int ans=0;
	N=newN;
//	rep(i,N) assert(G[i].size()<=3);
	rep(i,N) rep(j,4) memo[i][j]=-1;
	rep(i,N) chmax(ans,dfs(i,-1));
	if(ans>=inf) puts("Infinite");
	else cout<<ans<<endl;
	END_STACK_EXTEND;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
const ll mod = 1e9+7;

void sieve(size_t max, vector<bool> &isPrime){
    isPrime[0] = false; 
    isPrime[1] = false; 
    for (size_t i = 2; i*i <= max; ++i) 
        if(isPrime[i])
            for(size_t j=2; i*j <= max; ++j) 
                isPrime[i*j] = false; 
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	ll st=-1, ed=0;
	for (auto i = 0; i < s.size(); i++){
		if (st==-1 && s[i]== 'A'){ st = i; }
		if (s[i] == 'Z'){ ed = i; }
	}
	cout << ed-st+1 << endl;
}


Measured memory_bytes: 720
N = int(input())
s=[]
for i in range(N):
    s.append(int(input()))
t=[]
for i in range(N):
    if s[i]%10 != 0:
        t.append(s[i])
        s[i] = 0

t.sort()
sum_s=sum(s)
sum_t=sum(t)
if len(t) != 0:
    if sum_t%10 == 0:
        sum_t -= t[0]
sum = sum_s + sum_t
if sum%10 == 0:
    print(0)
else:
    print(sum)

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
	int n,i,m,b,c,t,sum =0,j;
	int a[100005],f[100005];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		scanf("%d",&b);
		scanf("%d",&c);
		t = a[b];
		//printf("t=%d\n",t);
		a[b] = c;
		//printf("%d\n",a[b]);
		for(j=1;j<=n;j++){
			f[i] += a[j];
			//printf("a[%d]=%d\n",j,a[i]);
		}
		sum = 0;
		a[b] = t;
	}
	for(i=1;i<=m;i++){
		printf("%d\n",f[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i=1; i<=n; i++){
    if ( i>1) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for( i=1; i<=n; i++) scanf("%d", &A[i]);

  trace(A, n);

  int key;
  for( i=2; i<=n; i++) {
    key = A[i];
    /* insert A[i] into the sorted sequence A[0,...,j-1] */
    j = i-1;
    while( j>0 && A[j]>key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    trace(A, n);
  }

  return 0;
}

Measured memory_bytes: 608
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int K = sc.nextInt();
    	int X = sc.nextInt();
    	sc.close();
    	System.out.println(500*K >= X ? "Yes" : "No");
    }
}

Measured memory_bytes: 22728
import java.util.*;
import java.io.*;
  
class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int x = Integer.parseInt(br.readLine());
        StringBuilder sb = new StringBuilder();
        int count=0;
        int a=1,b;
        if(x>=3 && x<=10000){
            for(; count<x; count++){
                 b = a/10;
                    if(a%3==0){
                        sb.append(" ");
                        sb.append(a);
                    }else{
                        b = a;
                        while(b!=0){
                            if(b%10==3){
                                sb.append(" ");
                                sb.append(a);
                                break;
                            }
                            b /= 10;
                        }
                    }
                    a++;
            }
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 25348
A, B, C, D = map(int, input().split())

# 最小公倍数を求める
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z

def lcm (m,n):
    return int(m * n / gcd(m,n))

div_C = (B//C) - ((A // C - 1) if A % C == 0 else (A // C))
div_D = (B//D) - ((A // D - 1) if A % D == 0 else (A // D))
mul = lcm(C,D)
div_mul = (B//mul) - ((A // mul - 1) if A % mul == 0 else (A // mul))
ans = (B - A + 1) - (div_C + div_D - div_mul)
print(ans)

Measured memory_bytes: 3064
import math
n=int(input())
csf=[list(map(int,input().split())) for i in range(n-1)]

for j in range(n-1):
    now=0
    for i in range(j,n-1):
        if csf[i][1]>=now:
            now=csf[i][1]+csf[i][0]
        else:
            now=csf[i][1]-((csf[i][1]-now)//csf[i][2])*csf[i][2]+csf[i][0]
    print(now)
print(0)



Measured memory_bytes: 3188
import numpy as np

N = int(input())
H = np.array(list(map(int, input().split())))

ans_1 = min(H[np.where(H==H.max())[0].min():]) > max(H)-2
tmp = H[1:] - H[:-1]
ans_2 = all(tmp > -2)

print("Yes") if ans_1 & ans_2 else print("No")

Measured memory_bytes: 23136
s = $stdin.gets.chomp
t = 'A','C','G','T'
len = 0
max = 0
s.size.times do |i|
  (i..s.size).each do |j|
    if t.include?(s[j])
      len += 1
    else
      break
    end
  end
  max = [max,len].max
  len=0
end
puts max

Measured memory_bytes: 1916
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
 /* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////




int main() {
	int A[5];
	rep(i,5){cin >> A[i];}
	vector<int> B(5); //余りを格納
	rep(i,5){B.at(i) = A[i] % 10;}
	int ans = 0;
	rep(i,5){ans += A[i] / 10;}
	ans *= 10;
	sort(ALL(B));
	rep(i,5)
	{
		if(B.at(i) != 0){ans += B.at(i) + (4-i)*10; break;}
	}
	




	cout << ans << endl;
}

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

int H, W, C, M, s, t, res, cap[310][310];
bool used[310];
enum { source = 300, sink, nwin, nwout, ncin, ncout, nmio };

bool dfs(int v)
{
    used[v] = true;
    for(int i = 0; i < 310; ++i)
        if(cap[v][i] > 0 && (i == sink || (!used[i] && dfs(i)))) {
            --cap[v][i]; ++cap[i][v]; return true;
        }
    return false;
}

int main()
{
    while(cin >> H >> W >> C >> M && H >= 0)
    {
    	fill_n(*cap, 310*310, 0);
        cin >> cap[nwin][nwout] >> cap[ncin][ncout] >> cap[nmio][sink];

        for(int i = 0; i < H; ++i)
            cap[source][i] = cap[i][nwin] = 1;
        for(int i = 0; i < W; ++i) {
        	cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[t-1][50+i] = 1; }
            cap[50+i][100+i] = cap[100+i][ncin] = 1;
        }
        for(int i = 0; i < C; ++i) {
        	cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[100+t-1][150+i] = 1; }
            cap[nwout][150+i] = cap[150+i][200+i] = cap[200+i][nmio] = 1;
        }
        for(int i = 0; i < M; ++i) {
        	cin >> s;
            for(int j = 0; j < s; ++j) { cin >> t; cap[200+t-1][250+i] = 1; }
            cap[ncout][250+i] = cap[250+i][sink] = 1;
        }

        res = 0;
        do fill_n(used, 310, false); while(dfs(source) && ++res);
        cout << res << endl;
    }
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int N = (int)S.size();
    int r = N;
    while (r > 0) {
        int l = r - 5;
        if (l >= 0) {
            string s = S.substr(l, r - l);
            if (s == "dream" || s == "erase") {
                r = l;
                continue;
            }
        }
        l = r - 6;
        if (l >= 0) {
            string s = S.substr(l, r - l);
            if (s == "eraser") {
                r = l;
                continue;
            }
        }
        l = r - 7;
        if (l >= 0) {
            string s = S.substr(l, r - l);
            if (s == "dreamer") {
                r = l;
                continue;
            }
        }
        break;
    }
    if (r == 0) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}


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

int main() {
    int n, m;cin >> n >> m;
    if(n == 1 && m == 0){
        cout << 0 << endl;
        return 0;
    }
    vector<int> num(n, -1);
    bool exist = true;
    for (int i = 0; i < m; i++)
    {
        int s, c;cin >> s >> c;
        if(num.at(n-s) == -1)num.at(n-s) = c;
        else if(num.at(n-s) != c)exist = false;
    }
    if(num.at(n-1) == 0 && num.size() > 1)exist = false;
    if(num.at(n-1) == 0 && num.size() == 1){
        cout << 0 << endl;
        return 0;
    }
    int ans;
    if(exist){
        ans = max(1, num.at(n-1))*pow(10, n-1);
        for (int i = 1; i < n; i++)
        {
            ans += max(0, num.at(n-1-i))*pow(10, n-i-1);
        }        
    }
    else ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int p[n];
  for(int i=0;i<n;i++)cin>>p[i];
  int cnt=0;
  for(int i=1;i<n-1;i++){
    cerr << p[i-1] << p[i] << p[i+1] <<endl;
    if((p[i-1]<p[i] && p[i]<p[i+1])||(p[i-1]>p[i] && p[i]>p[i+1])){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long sum=0;
        for(int i=1;i<H+100;i++) {
        	if(H<(long)Math.pow(2, i)) {
        	   sum = (long)Math.pow(2,i)-1;
        	   break;
        	}
        }
        
        System.out.println(sum);
        		
    }
}

Measured memory_bytes: 23252
X,N=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=0
ans1=X
for i in range(1,102):
    if i in p:
        a=p.pop(0)
        continue
    A=abs(X-i)
    if ans1>A:
        ans1=A
        ans=i
    elif ans1==A:
        ans=min(ans,i)
    else:
        break
print(ans)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int main() {
    int i,j,c=0;
    string s;
    cin>>s;
    int n=s.length();
    for(i=0; i<n/2; i++) {
        if(s[i]!=s[n-1-i]) {
            c++;
        }
    }
    cout<<c<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E15;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////
 

ll INF=1E9;

int main(){
    ll n;cin>>n;
    ll go[n];rep(i,0,n-1)cin>>go[i];
    sort(go,go+n);
    vector<ll>v;
    ll pos=0;
    while(pos<=n-1){
        ll c=1;
        while(pos<=n-2&&go[pos]==go[pos+1]){
            pos++;c++;
        }
        v.pb(c);
        pos++;
    }
    v.pb(0);
    sort(v.begin(),v.end());
    ll m=v.size();
    ll sm[m];sm[0]=0;
    rep(i,1,m-1)sm[i]=sm[i-1]+v[i];
    //rep(i,0,m-1)cout<<sm[i]<<" ";cout<<endl;
    
    rep(k,1,n){
        ll ok=0,ng=INF;
        while(ng-ok>1){
            ll mid=(ok+ng)/2;
            ll po=lower_bound(v.begin(),v.end(),mid)-v.begin();
            ll sum=sm[po-1]+(m-po)*mid;
            if(sum>=k*mid){
                ok=mid;
            }else{
                ng=mid;
            }
        }
        cout<<ok<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 8556
import sys
sys.setrecursionlimit(10**7)
def check(li):
    global ans
    res=0
    for i in range(Q):
        if(li[b[i]-1]-li[a[i]-1]==c[i]):
            res+=d[i]
    ans=max(ans,res)

def dfs(li,last,M):
    if(len(li)==N):
        check(li)
        return 
    l=li.copy()
    for i in range(last,M+1):
        dfs(l+[i],i,M)

import itertools
N,M,Q=map(int,input().split())
a,b,c,d=[],[],[],[]
for i in range(Q):
    A,B,C,D=map(int,input().split())
    a.append(A);b.append(B);c.append(C);d.append(D)
ans=0
dfs([],1,M)
print(ans)

Measured memory_bytes: 9200
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int n = s.size();
    vector<int> p(n + 1);
    p[0] = -1;
    for (int i = 1; i <= n; i++) {
        int k = p[i - 1];
        while (k >= 0 && s[k] != s[i - 1]) k = p[k];
        p[i] = k + 1;
    }
    std::reverse(s.begin(), s.end());
    vector<int> pr(n + 1);
    pr[0] = -1;
    for (int i = 1; i <= n; i++) {
        int k = pr[i - 1];
        while (k >= 0 && s[k] != s[i - 1]) k = pr[k];
        pr[i] = k + 1;
    }

    int per = n - p[n];
    if (per != n && n % per == 0) {
        if (per == 1) {
            cout << n << " 1";
        } else {
            int res = 0;
            for (int i = 1; i < n; i++) {
                int p1 = i - p[i];
                int p2 = n - i - pr[n - i];
                if (p1 == i || i % p1 != 0) {
                    if (p2 == n - i || (n - i) % p2 != 0) {
                        res++;
                    }
                }
            }
            cout << "2 " << res;
        }
    } else {
        cout << "1 1";
    }

    return 0;
}

Measured memory_bytes: 4764