akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vector<P> g(n);
	rep(i,n){
		cin>>g[i].fi>>g[i].se;
	}
	sort(begin(g),end(g),[](const P &a,const P &b){
		return a.se>b.se;
	});
	ll ans=0;
	map<ll,ll> mp;
	rep(i,k){
		ans+=g[i].se;
		mp[g[i].fi]++;
	}
	priority_queue<P,vector<P>,greater<P>> que;//(美味しさ,ネタ)
	rep(i,k){
		if(mp[g[i].fi]>=2){
			que.push({g[i].se,g[i].fi});
		}
	}
	ans+=(ll)mp.size()*(ll)mp.size();
	ll now=ans;
	FOR(i,k,n){//美味しさを引き換えに種類数を増やしていく
		if(mp.count(g[i].fi)) continue;//既に含まれていたら選ぶ意味なし
		bool flag=false;
		while(!que.empty()){
			auto hoge=que.top();
			que.pop();
			if(mp[hoge.se]==1) continue;
			now-=hoge.fi;
			now+=g[i].se;
			mp[hoge.se]--;
			mp[g[i].fi]++;
			flag=true;
			break;
		}
		if(flag) now+=(ll)mp.size()*(ll)mp.size()-((ll)mp.size()-1)*((ll)mp.size()-1);
		chmax(ans,now);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6776
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
#define PI = 3.14159265358979323846
/*------------------------------------------------------------------------------*/

int main(){
  int A, B;
  cin >> A >> B;

  if(A == B){
    cout << "Draw" << endl;
    return 0;
  }
  if(A == 1){
    cout << "Alice" << endl;
    return 0;
  }
  if(B == 1){
    cout << "Bob" << endl;
    return 0;
  }
  if(A > B){
    cout << "Alice" << endl;
  } else {
    cout << "Bob" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    int n, i, mi=1000000000, mx=0;
    cin >> n;
    int a;
    for(i=0; i<n; i++) {
        cin >> a;
        mi=min(a, mi);
        mx=max(a, mx);
    }
    cout << mx-mi << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
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 All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    string S;cin >> S;
    int slen = S.size();
    ll res = 0;
    for(int i=0;i<(1<<(slen-1));i++){
        ll acc = S[0]-'0',sum=0;
        for(int j=0;j<slen-1;j++){
            if(i&(1<<j)){
                sum+=acc;
                acc=0;
            }
            acc = acc*10+(S[j+1]-'0');
        }
        sum+=acc;
        res+=sum;
    }
    cout << res << endl;
    return 0;
}

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

string S;
int cnt[3] = {0};

int main()
{
    cin >> S;
    for(int i = 0; i < S.size(); i++)cnt[S[i] - 'a']++;
    sort(cnt,cnt + 3);
    if(cnt[2] - cnt[0] <= 1)printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int l[n], r[n];
    for (int i = 0; i < n; i++)
        cin >> l[i] >> r[i];

    int ans = 0;
    for (int i = 0; i < n; i++)
        ans += r[i] - l[i] + 1;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) { cout << a << endl; }
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(k);
    in(s);

    ll ans = 0;
    rep(x, k + 1) {
        rep(y, k + 1) {
            if (0 <= s - x - y && s - x - y <= k) {
                ++ans;
            }
        }
    }
    out(ans);
}

Measured memory_bytes: 256
// Problem Code: abc170_d

#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

int not_divisible(int N, vector<int>& A) {
	int cnt = 0, limit = *max_element(A.begin(), A.end());
	vector<bool> mark(limit + 1);
	unordered_map<int, int> freq;

	for (int x: A)
		freq[x]++;
	sort(A.begin(), A.end());

	for (int i = 0; i < N; i++) {
		if (mark[A[i]])
			continue;
		cnt += freq[A[i]] == 1;
		for (int x = A[i]; x <= limit; x += A[i])
			mark[x] = true;
	}

	return cnt;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	cout << not_divisible(N, A);
	return 0;
}

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

using ll = unsigned long long;

int main() {
  int N;
  cin >> N;
  vector<ll> as(N);
  for(int i = 0; i < N; ++i) {
    cin >> as[i];
  }
  sort(as.begin(), as.end());

  vector<ll> cusum(N);
  cusum[0] = as[0];
  for(int i = 1; i < N; i++) {
    cusum[i] = cusum[i - 1] + as[i];
  }

  int ans = 1;
  for(int i = N - 2; i >= 0; i--) {
    if(cusum[i] * 2 >= as[i + 1])
      ans++;
    else
      break;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> A;

void dfs(int num,int dep){
  if(dep == 18) return;
    if(num)A.push_back(num);
  dfs(num*10+2,dep+1);
  dfs(num*10+8,dep+1);  
}

typedef pair<int,int>P;
signed main(){
  int n;
  cin>>n;
  dfs(0,0);
  sort(A.begin(),A.end(),greater<int>());
  map<int,int> dp;
  
  dp[n] = 0,dp[1] = -1;

  for(int a:A){
    for(P p:dp){
      int num = p.first;
      int score = p.second;
      if(num % a) continue;
      while(num%a == 0) num/=a, dp[num] = max(dp[num],++score);
    }
  }

  int ans = dp[1];
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 4968
#include<bits/stdc++.h>
    using namespace std;
    #define forn(i, n)             for(int i = 0; i < n; i ++)
    #define forn1(i, n)            for(int i = 1; i <= n; i ++)
    #define pb push_back
    #define ll long long int
    #define fi first
    #define se second
    #define ii  pair<long long int, long long int>
    #define vi  vector <long long int>
    #define vii vector <pair <long long int, long long int > >
    #define all(cont)  cont.begin(), cont.end()
    #define EPS 1e-9
    #define MOD 1000000007
    #define range 
    #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
    #pragma GCC optimize ("Ofast")
    int main(){

     //   freopen("input.txt","r",stdin);
        IOS;
        clock_t clk = clock();
        int a;
        string s;cin>>a;
        cin>>s;
        cout<<((a<3200)?"red":s)<<endl;        



        cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
        return 0;
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n, m;
    cin>>n>>m;
    vi a(m);
    int tot=0;
    REP(i,0,m){
        cin>>a[i];
        tot+=a[i];
    }
    int rem=n-tot;
    if(rem<0){
        cout<<-1<<"\n";
    }
    else{
        cout<<rem<<"\n";
    }

    return 0;
}

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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}

//main------------------------------------------------------------------------------------------


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

    int n,m,x,y; cin >> n >> m >> x >> y;

    vector<int> a; rep(i,0,n) a.push_back(input());
    vector<int> b; rep(i,0,m) b.push_back(input());

    int maxa = *max_element(a.begin(), a.end());
    int minb = *min_element(b.begin(), b.end());
    rep(i,x+1,y+1){
        if(maxa < i && i <= minb){
            print("No War");
            return 0;
        }
    }

    print("War");

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = Integer.toString(n);
    if(s.charAt(0)=='9' || s.charAt(1)=='9'){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 19924
H,W=map(int,input().split())
maze=[]
maze.append(['#']*(W+2))
for i in range(H):
    tmp=['#']+list(input())+['#']
    if '.' in tmp:
        a,b=i,tmp.index('.')
    maze.append(tmp)
maze.append(['#']*(W+2))
infty=10**5

def far(a,b):
    cost[a][b]=0
    point[0].append((a,b))
    stocks=1
    highscore=0
    tops=[]
    while stocks>0:
        stocks-=1
        for i in range(infty):
            if point[i]==[]:
                continue
            else:
                a,b=point[i].pop(0)
                break
        if i==highscore:
            tops.append((a,b))
        elif i>highscore:
            highscore,tops=i,[(a,b)]
        if maze[a][b+1]=='.' and cost[a][b+1]==infty:
            cost[a][b+1]=i+1
            point[i+1].append((a,b+1))
            stocks+=1
        if maze[a][b-1]=='.' and cost[a][b-1]==infty:
            cost[a][b-1]=i+1
            point[i+1].append((a,b-1))
            stocks+=1
        if maze[a-1][b]=='.' and cost[a-1][b]==infty:
            cost[a-1][b]=i+1
            point[i+1].append((a-1,b))
            stocks+=1
        if maze[a+1][b]=='.' and cost[a+1][b]==infty:
            cost[a+1][b]=i+1
            point[i+1].append((a+1,b))
            stocks+=1
    return tops,i


cost=[[infty]*(W+2) for i in range(H+2)]
point=[[] for i in range(infty)]

a,b=far(a,b)[0][0]

cost=[[infty]*(W+2) for i in range(H+2)]
point=[[] for i in range(infty)]

tops=far(a,b)[0]
res=0


for i,j in tops:
    cost=[[infty]*(W+2) for tmp in range(H+2)]
    point=[[] for i in range(infty)]
    tmp=far(i,j)[1]
    if res<tmp:res=tmp

print(res)

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll modpow(ll n, ll r, ll mod) {
    ll ret = 1;
    ll p = n % mod;
    while (r > 0) {
        if (r & 1)
            ret = (ret * p) % mod;
        r /= 2;
        p = (p * p) % mod;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, P;
    cin >> N >> P;
    string S;
    cin >> S;
    ll ans = 0;
    if (P == 2 || P == 5) {
        REP(i, N) {
            ll n = S[i] - '0';
            if (n % P == 0)
                ans += i + 1;
        }
    }
    else {
        map<ll, ll> M;
        M[0]++;
        ll p = modpow(10LL, P - 2, P);
        ll s = 0;
        REP(i, N) {
            s = (s * 10LL + S[i] - '0') % P;
            ll q = modpow(p, i + 1, P);
            ll n = s * q % P;
            ans += M[n];
            M[n]++;
        }
    }

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

Measured memory_bytes: 4060
def main():
    n,m = map(int,input().split())
    sheet = [[0]*(m+1) for _ in range(n+1)]
    for i in range(n):
        r = list(map(int,input().split()))
        s = 0
        for j in range(m):
            sheet[i][j] = r[j]
            s += r[j]
            sheet[n][j] += r[j]
        sheet[i][m] = s
        sheet[n][m] += s
    for i in range(n+1):
        print (' '.join(map(str,sheet[i])))


if __name__ == '__main__':
    main()




Measured memory_bytes: 5712
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<typeinfo>
#include<sstream>
#include<list>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int stringInt(string a)
{
	return atoi(a.c_str());
}
string intString(int a)
{
	stringstream ss;
	ss<<a;
	return ss.str();
}
vector<int> SieveOfEratosthenes(int x)
{
	vector<int> a;
	vector<int> b(x+1,0);
	for(int i=2;i<=x;i++)
	{
		if(b[i]==0)
		{
			a.push_back(i);
			for(int l=i;l<=x;l+=i)
			{
				b[l]=1;
			}
		}
	}
	return a;
}
struct node
{
	int p,l,r;
};
int main() {
	int n;
	node a[100005];
	cin>>n;
	rep(i,n)a[i].p=a[i].r=a[i].l=-1;
	rep(i,n)
	{
		int id,k,c;
		int now=-1;
		cin>>id>>k;
		rep(l,k)
		{
			cin>>c;
			a[c].p=id;
			if(a[id].l==-1)a[id].l=c;
			if(now!=-1)
			{
				a[now].r=c;
			}
			now=c;
		}
	}
	rep(i,n)
	{
		int d=0;
		int now=i;
		while(1)
		{
			if(a[now].p==-1)break;
			else
			{
				d++;
				now=a[now].p;
			}
		}

		printf("node %d: parent = %d, depth = %d, ",i,a[i].p,d);
		if(a[i].l==-1&&a[i].p!=-1)
		{
			cout<<"leaf, []"<<endl;;
		}
		else if(a[i].p==-1)
		{
			cout<<"root, [";
			if(a[i].l!=-1)
			{
				cout<<a[i].l;
				now=a[i].l;
				while(1)
				{
					if(a[now].r==-1)break;
					cout<<", "<<a[now].r;
					now=a[now].r;
				}
			}
			cout<<"]"<<endl;
		}
		else
		{
			cout<<"internal node, [";
			cout<<a[i].l;
			now=a[i].l;
			while(1)
			{
				if(a[now].r==-1)break;
				cout<<", "<<a[now].r;
				now=a[now].r;
			}
			cout<<"]"<<endl;
		}
	}

}

Measured memory_bytes: 2372
#include "bits/stdc++.h"
using namespace std;

int main(void){
    int i = 0;
    string str;
    while (getline(cin, str) && str != ".") {
        stack<char> st;
        bool balanced = true;
        for (char c : str) {
            if (c == '(' || c == '[')
                st.push(c);
            else if (c == ')' || c == ']') {
                if (st.empty()) {
                    balanced = false;
                    break;
                } if (st.top() != '(' && c == ')') {
                    balanced = false;
                    break;
                } else if (st.top() != '[' && c == ']') {
                    balanced = false;
                    break;
                }
                st.pop();
            }
        }
        balanced = balanced && st.empty();
        cout << (balanced ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 3180
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

use std::io::Write;

fn calc(a: &Vec<i64>, d: i64) -> i64 {
    let mut b = a.clone();
    for b in b.iter_mut() {
        *b %= d;
    }
    b.sort();
    let mut ans = 0;
    let mut i = 0;
    let mut j = b.len() - 1;
    while i < j {
        if b[i] == 0 {
            i += 1;
        } else if b[j] == 0 {
            j -= 1;
        } else {
            let x = std::cmp::min(b[i], d - b[j]);
            b[i] -= x;
            b[j] = (b[j] + x) % d;
            ans += x;
        }
    }
    return ans;
}

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        n: usize,
        k: i64,
        a: [i64; n],
    }
    let sum = a.iter().fold(0, |z, x| z + x);
    let mut ans = 1;
    let mut i = 1;
    while i * i < sum {
        if sum % i == 0 {
            if calc(&a, i) <= k {
                ans = std::cmp::max(ans, i);
            }
            if calc(&a, sum / i) <= k {
                ans = std::cmp::max(ans, sum / i);
            }
        }
        i += 1;
    }
    if sum % i == 0 && calc(&a, i) <= k {
        ans = std::cmp::max(ans, i);
    }
    writeln!(out, "{}", ans).unwrap();
}

fn main() {
    run();
}


Measured memory_bytes: 4476
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>

using namespace std;

typedef pair<int,int> ii_t;

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

int bfs(int h, int w, vector<string> &field){
    vector<vector<int> > step(h,vector<int>(w,10000));
    queue<ii_t> que;
    step[0][0] = 0; 
    que.push(ii_t(0,0));

    while(!que.empty()) {
        ii_t cur = que.front();
        que.pop();
        // cerr << "# " << cur.first << " " << cur.second << endl;
        for (int k=0;k<4;k++) {
            int yy = cur.first + dy[k];
            int xx = cur.second + dx[k];
            if (0<=yy && yy<h && 0<=xx && xx<w && field[yy][xx] == '.' && step[yy][xx]== 10000) {
                if (yy==h-1 && xx==w-1) {
                    return step[cur.first][cur.second] + 1;
                }
                step[yy][xx] = step[cur.first][cur.second] + 1;
                que.push(ii_t(yy,xx));
            }
        }
    }

    return -1;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> field(h);
    int dots = 0;
    for(int i=0;i<h;i++) {
        cin >> field[i];
        for(int j=0;j<field[i].size();j++)
        if (field[i][j]=='.')
            dots++;
    }

    int st = bfs(h,w,field);
    if (st < 0) {
        cout << -1 << endl;
    }else {
    // cerr << "@ " << st << endl;
        cout << (dots - 1 - st) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import collections

N=int(input())
List = list(map(int, input().split()))
sumList = []
for i in range(N):
  sumList.append(List[i])
  sumList.append(List[i]+1)
  sumList.append(List[i]-1)
c = collections.Counter(sumList)
print(c.most_common()[0][1])

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

int main(){
    int a, b;
    cin >> a >> b;
    string s(b, '0'+a);
    string t(a, '0'+b);
    if(a < b){
        cout << s << endl;
    }
    else cout << t << endl;
    
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACB78A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            char A = input[0][0];
            char B = input[1][0];
            if (A < B)
            {
                Console.WriteLine("<");
            }
            else if (A > B)
            {
                Console.WriteLine(">");
            }
            else
            {
                Console.WriteLine("=");
            }

























        }
    }
}


Measured memory_bytes: 13140
def main():
    N,K = map(int, input().split())
    H = list(map(int, input().split()))
    H = sorted(H, reverse=True)
    if(len(H) < K):
        res = 0
    else:
        res = sum(H[K:])
    print(res)

if __name__ == "__main__":
    main()


Measured memory_bytes: 26024
import java.io.*;
import java.util.*;
public class Main {
	static class pair implements Comparable<pair>{
		long x,h;
		pair(long xx,long hh){x=xx;h=hh;}
		@Override
		public int compareTo(pair o) {
			return Long.compare(x,o.x);
		}
		
	}
	public static void main(String[] args) throws Exception {
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt(),d=sc.nextInt(),a=sc.nextInt();
		pair[]in=new pair[n];
		for(int i=0;i<n;i++) {
			in[i]=new pair(sc.nextLong(), sc.nextLong());
		}
		Arrays.sort(in);
		int i=0;
		PriorityQueue<Long>pq=new PriorityQueue<Long>();
		TreeSet<Long>xs=new TreeSet<Long>();
		HashMap<Long, Long>map=new HashMap<Long, Long>();
		
		long range=in[0].x+2l*d;
		long tot=0;
		long ans=0;
		while(i<n) {
			long damage=0;
			long nxtrange=-1;
			while(i<n && in[i].x<=range) {
				xs.add(in[i].x);
				pq.add(in[i].h+tot);
				map.put(in[i].x, in[i].h+tot);
				i++;
			}
			if(i!=n) {
				nxtrange=in[i].x-2l*d;
			}
			while(!xs.isEmpty() && (nxtrange==-1 || xs.first()<nxtrange)) {
				damage=Math.max(damage, (map.get(xs.first())-tot+a-1)/a);
				xs.pollFirst();
			}
			ans+=damage;
			tot+=damage*a;
			while(!pq.isEmpty() && pq.peek()<=tot) {
				pq.poll();
			}
			if(i==n)break;
			if(xs.isEmpty()) {
				range=in[i].x+2l*d;
			}
			else
				range=xs.first()+2l*d;
		}
		pw.println(ans);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


Measured memory_bytes: 104084
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n,x;
    cin>>n>>x;

    int m=2*n-1;

    if(x==1 || x==m)
    {
        cout<<"No";
        return;
    }

    cout<<"Yes\n";

    vi v(m+1);

    v[m/2]=1;
    v[m/2+1]=x;
    v[m/2+2]=m;

    int cur=1;
    for(int i=1;i<m/2;++i)
    {
        if(cur!=1 && cur!=x && cur!=m)
            v[i]=cur;
        else
            --i;
        ++cur;
    }

    for(int i=m/2+3;i<=m;++i)
    {
        if(cur!=1 && cur!=x && cur!=m)
            v[i]=cur;
        else
            --i;
        ++cur;
    }

    for(int i=1;i<=m;++i)
        cout<<v[i]<<"\n";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 3072
a,b=map(int,input().split())
def func(n,m):# 0<=i<=mのiを二進数表示した時、2^nのくらいが1となるiの個数。のiで(i//2^n)%2=1となるiの個数<=>i//2^nが奇数
  c=m//pow(2,n)
  d=m%pow(2,n)
  # m=c*pow(2,n)+d
  if c%2==0:
    return pow(2,n)*(c//2)
  else:
    return pow(2,n)*((c-1)//2)+d+1
i=0
while pow(2,i)<=b:
  i+=1
maxn=i
ans=0
for i in range(maxn+1):
  e=func(i,b)-func(i,max(0,a-1))
  if e%2==1:
    ans+=pow(2,i)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long x, y, ct;
	cin >> x >> y;
	ct = 1;
	while (x * 2 <= y) {
		x *= 2;
		ct++;
	}
	cout << ct << "\n";

	return 0;
}


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

using namespace std;

#include <bits/stdc++.h>

using namespace std;

int main()
{

    int n,d;
    cin>>n>>d;
    vector<vector<int>> ve;
    int x;
    vector<int> v;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<d;j++)
          {
             cin>>x;
             v.push_back(x);
          }
          ve.push_back(v);
          v.clear();
    }

int m=0,diff=0,v1,c=0;

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

            for(int k=0;k<d;k++)
            {
                m=ve[i][k] - ve[j][k];
                diff+=m*m;
            }
            v1=sqrt(diff);
            if(v1*v1==diff)c++;
            diff=0;
        }
    }
    cout<<c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 998244353
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 1000003
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int n,a,b,c,d,pref1[mx],pref2[mx];
string s1,s2;
int main(){
	cin>>s1>>s2;
	int n=s1.length(),m=s2.length();
	for(int i=1;i<=n;i++){
		pref1[i]=pref1[i-1];
		if(s1[i-1]=='A')pref1[i]++;
		else pref1[i]+=2;
	}
	for(int i=1;i<=m;i++){
		pref2[i]=pref2[i-1];
		if(s2[i-1]=='A')pref2[i]++;
		else pref2[i]+=2;
	}
	int q;
	cin>>q;
	while(q--){
		cin>>a>>b>>c>>d;
		int sa=pref1[b]-pref1[a-1];
		int du=pref2[d]-pref2[c-1];
		if(sa%3==du%3){
			cout<<"YES\n";
		}
		else cout<<"NO\n";
	}
}




Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)

int main(void){
    int X,Y,Z;
    cin >> X >> Y >> Z;
    swap(X,Y);
    swap(X,Z);
    cout << X<< " " << Y << " "<< Z << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int N=333;
int n,m,a[N][N],ans,p[N],cnt[N];bool vis[N];
int main(){
    scanf("%d%d",&n,&m);ans=n;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
    for(int i=1;i<=n;i++)p[i]=1;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++)cnt[j]=0;
        for(int j=1;j<=n;j++)cnt[a[j][p[j]]]++;
        int mx=0,q=0;
        for(int j=1;j<=m;j++)if(cnt[j]>mx)mx=cnt[j],q=j;
        ans=min(ans,mx);vis[q]=1;
        for(int j=1;j<=n;j++)while(vis[a[j][p[j]]])p[j]++;
    }
    cout<<ans;
    return 0;
}

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

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

    int sum   = 1;
    int count = 0;
    while (1) {
        if (sum >= b) break;
        sum += (a - 1);
        count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n;
	cin>>n;
	string s;
	set<string> st;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		st.insert(s);
	}
	cout<<S(st);
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 19288
#include <bits/stdc++.h>
#define pb push_back
#define ll long long

using namespace std;
int n,a[100005],dp[100005];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    cout<<dp[n-1]<<endl;
    return 0;
}



Measured memory_bytes: 1024
N,K=gets.split.map(&:to_i)
if K==0
    puts N*N
    exit
end
r=0
(K+1 .. N).each{|b|
    n=N/b
    r+=n*(b-K)
    m=N%b
    if m>=K
        r+=m-K+1
    end
    #warn [b,n,m,r].inspect
}
puts r


Measured memory_bytes: 14260
#include<iostream>
#include<string>

using namespace std;


int main() {

	string s;

	cin >> s;

	if (s[0] == s[1] && s[1] == s[2]) {
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}

	return 0;
	
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
DD = inpl()
cnts = defaultdict(int)
for d in DD:
    cnts[d] += 1

m = max(DD)

if DD[0] != 0 or cnts[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(1,m+1):
        if cnts[i] == 0:
            print(0)
            sys.exit()
        ans *= pow(cnts[i-1],cnts[i],mod)
        ans %= mod

    print(ans%mod)


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

using namespace std;

int main(){
  int N,tmp,cnt=1;
  cin >> N;
  
  vector<int> v;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
	v.push_back(tmp);
  }
  
  sort(v.begin(),v.end(),greater<int>());
  tmp = v[0];
  for(int i = 0; i<v.size();i++){
	if(tmp>v[i]){
      cnt++;
      tmp = v[i];
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200010
#define inf 2147483647
#define ll long long
#define pa(a, b) (data){a, b}
using namespace std;

struct edge{int x, y, next;}a[N*2];
struct data{int def, sum;}d[N];
int n, l, p[N], x, y, def[N], def1[N], sum[N], def_fa[N], fa[N], mx, mx1, R, L;
ll ans;
char S[N];

inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}
inline void dfs(int x){
	def[x]=def1[x]=1; sum[x]=S[x]=='1'?1:0;
	for(int i=p[x]; i; i=a[i].next)if(fa[x]!=a[i].y){
		fa[a[i].y]=x; dfs(a[i].y); sum[x]+=sum[a[i].y];
		if(def[x]<=def[a[i].y]+1){def1[x]=def[x]; def[x]=def[a[i].y]+1;}
		else if(def1[x]<=def[a[i].y]+1)def1[x]=def[a[i].y]+1;
	}
}
inline void dp(int x){
	for(int i=p[x]; i; i=a[i].next)if(fa[x]!=a[i].y){
		if(def[x]==def[a[i].y]+1)def_fa[a[i].y]=max(def_fa[x], def1[x])+1;
		else def_fa[a[i].y]=max(def_fa[x], def[x])+1;
		dp(a[i].y);
	}
}

int main(){
	scanf("%d", &n);
	l=0; memset(p, 0, sizeof(p));
	for(int i=1; i<=n-1; i++){scanf("%d%d", &x, &y); add(x, y); add(y, x);}
	scanf("%s", S+1);
	fa[1]=1; dfs(1);
	def_fa[1]=0; dp(1);
	ans=1; //全集
	for(int i=1; i<=n; i++){
		l=0;
		for(int j=p[i]; j; j=a[j].next)
			if(fa[i]==a[j].y)d[++l]=pa(def_fa[i]-1, sum[1]-sum[i]);
			else d[++l]=pa(def[a[j].y], sum[a[j].y]);
		mx=mx1=0;
		for(int j=1; j<=l; j++)
			if(mx<=d[j].def){mx1=mx; mx=d[j].def;}
			else if(mx1<=d[j].def)mx1=d[j].def;
		R=min(mx1+1, mx-1);
		if(R==-1)continue;
		if(S[i]=='1'){ans+=R+1; continue;}
		L=inf;
		for(int j=1; j<=l; j++)if(d[j].sum)L=min(L, d[j].def);
		if(L<=R)ans+=R-L+1;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 14720
#include<bits/stdc++.h>
#define pb push_back
#define int long long int
#define INF 1e18
#define vec vector<int>
#define REP(i,a,b) for(i=a;i<b;i++)
using namespace std;
int32_t main()
{
  int t=1;
  //cin>>t;
  while(t--)
  {
    int n,x,t;
    cin>>n>>x>>t;
    cout<<(int)(ceil(double(n)/x)*t)<<"\n";
  }
}


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

int main() {
  int X, A, B, aa, bb;
  cin >> X;
  
  aa = X % 10;
  for(int i = 0; i <= 150; i++){
    for(int j = -100; j <= i; j++){
      if(i*i*i*i*i - j*j*j*j*j == X){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
  
  return 0;
}

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

int main()
{
  string S;
  cin >> S;
  int64_t N = S.size();
  vector<int> v(N);
  for (int i = 0; i < N; i++)
  {
    v[i] = S[i] - '0';
  }
  reverse(v.begin(), v.end());
  v.push_back(0);
  int64_t ans = 0;
  for (int i = 0; i < N; i++)
  {
    if (v[i] <= 4)
    {
      ans += v[i];
    }
    else if (v[i] == 5)
    {
      if (v[i + 1] <= 4)
      {
        ans += v[i];
      }
      else
      {
        ans += (10 - v[i]);
        v[i + 1]++;
      }
    }
    else
    {
      ans += (10 - v[i]);
      v[i + 1]++;
    }
  }
  ans += v[N];
  cout << ans << endl;
}


Measured memory_bytes: 12084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
    ll i,j;
    ll n,a,b;
    cin>>n>>a>>b;
    cout<<min(a*n,b)<<endl;
    
}

Measured memory_bytes: 256
A,B,C,X,Y = map(int,raw_input().split())
if C * 2 > A + B:
	print A * X + B * Y
else:
	x = C * 2 * min(X,Y)
	if X < Y:
		if C * 2 < B:
			print Y * 2 * C
		elif C * 2 < B:
			print A * X + B * Y
		else:
			y = (Y - X) * B
			print x+y
	else:
		if C * 2 < A:
			print X * 2 * C
		elif C * 2 < A:
			print A * X + B * Y
		else:
			y = (X - Y) * A
			print x+y

Measured memory_bytes: 2568
#include <stdio.h>
int main(void){
	int n,m,i=0,j,k,c=0,d=0,a[1000],b[1000];
	scanf("%d %d",&n,&m);
	while(++i<=m){
		scanf("%d %d",&a[i],&b[i]);
		if(a[i]>=n)a[i]=b[i]=0,c++;
	}
	if(m-1>c){
		for(i=1;i<=m;i++)b[i]=n-a[i];
		i=0;
		while(++i<m){
			j=i;
			while(++j<=m)
			if(b[i]>b[j]){
				k=b[i];
				b[i]=b[j];
				b[j]=k;
			}
		}
		for(i=1;i<=m-c-1;i++)d+=b[i];
	}
	printf("%d\n",d);
	return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int a, b;

    scanf("%d%d", &a, &b);
    
    printf("%d\n", a * b);

    return 0;
}

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

using namespace std;
#define ll long long


const ll maxn=3*1e5+5;
priority_queue<ll,vector<ll>,greater<ll> >q;
priority_queue<ll>w;
ll lsum[maxn],rsum[maxn];
ll a[maxn];
ll n;

void solve()
{

    for(ll i=n+1;i<=2*n;i++)
    {
        ll ans=q.top();
        if(a[i]>ans)
        {


            lsum[i]=lsum[i-1]+a[i]-ans;
          //  cout<<a[i]<<' '<<ans<<' '<<lsum[i]<<endl;
            q.pop();
            q.push(a[i]);
        }
        else
            lsum[i]=lsum[i-1];
    }
    for(ll i=2*n;i>=n+1;i--)
    {
        ll ans=w.top();
        if(a[i]<ans)
        {
            rsum[i]=rsum[i+1]-ans+a[i];
            w.pop();
            w.push(a[i]);
        }
        else
            rsum[i]=rsum[i+1];
    }
    ll maxx=-1e18;
    for(ll i=n;i<=2*n;i++)
    {
        maxx=max(maxx,lsum[i]-rsum[i+1]);
    }
    printf("%lld\n",maxx);
}

int  main()
{
    while(scanf("%lld",&n)!=EOF)
    {
        memset(rsum,0,sizeof(rsum));
        memset(lsum,0,sizeof(rsum));
        while(!q.empty())
            q.pop();
        while(!w.empty())
        w.pop();
    for(ll i=1;i<=3*n;i++)
    {
         scanf("%lld",&a[i]);
         if(i<=n)
         {
             lsum[i]=lsum[i-1]+a[i];
             q.push(a[i]);
         }
         if(i>=2*n+1)
         {
             w.push(a[i]);
         }
    }
    rsum[3*n]=a[3*n];
    for(ll i=3*n-1;i>=2*n+1;i--)
        rsum[i]=rsum[i+1]+a[i];
    solve();
    }
    return 0;
}


Measured memory_bytes: 9588
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    int A, B, C;
    read(A, B, C);
    write(C - min(A - B, C));
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 256
#include<stdio.h>
typedef long long LL;
int main(){
	LL K;
	scanf("%lld",&K);
	LL n=50;
	printf("%lld\n",n);
	LL k=K/n;
	LL b=K%n;
	if(b==0){
		for(LL i=1;i<=n;++i) printf("%lld ",n-1+k);
	}
	else{
		for(LL i=1;i<=b;++i){
			printf("%lld ",n+k);
		}
		for(LL i=b+1;i<=n;++i){
			printf("%lld ",n-1+k-b);
		}
	}
//	while(1);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep( i, n ) for (long long i = 0; i < ( long long )(n); i++)

using namespace std;
typedef long long ll;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;


int main(){
  int n,k;
  int ans=0;
  cin>>n>>k;
  vector<bool> b(n,0);

  rep(i,k){
    int d;
    cin>>d;
      rep(j,d){
        int a;
        cin>>a;
        if(b[--a]==0)b[a]=1;
      }
  }

  rep(i,n){
    if(b[i]==0) ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n;
int a[200001];
int main()
{
	long long s=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) cin>>a[i];
	int j=0,suma=0,sumb=0;
	for(int i=1;i<=n;i++)
	{
		while(j+1<=n&&suma+a[j+1]==(sumb^a[j+1]))
		{
			j++;
			suma=suma+a[j];
			sumb=sumb^a[j];
		}
		suma=suma-a[i];
		sumb=sumb^a[i];
		s=s+j-i+1;
		
	}
	cout<<s;
}

Measured memory_bytes: 4548
from sys import stdin

def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()

A = [0] * 5
for i in range(5): A[i] = ri()
 
tot = 0
ma = 0
for i in range(len(A)):
    tot += (A[i] + 9) // 10 * 10
    if A[i] % 10 > 0 : ma = max(ma, 10 - A[i] % 10)

tot -= ma
print(tot)



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

ll m,n;
vl a;

vl F(){
	vl b(n+1);
	for(int i=0;i<n;i++) b[i+1]=b[i]+a[i]*2;
	reverse(a.begin(),a.end());
	for(auto &i:a) i=m-i;
	return b;
}

ll f(){
	vl b=F(),c=F();
	ll res=0;
	for(int i=0;i<n;i++){
		int L=(n-i+1)/2,R=(n-i)/2;
		res=max(res,b[i+L]-b[i]+c[R]-(L>R?a[i+L-1]:m-a[n-R]));
	}
	reverse(a.begin(),a.end());
	for(auto &i:a) i=m-i;
	return res;
}

int main(){
	cin>>m>>n;
	a=vl(n);
	for(auto &i:a) cin>>i;
	cout<<max(f(),f())<<endl;
}

Measured memory_bytes: 4992