akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int N,K;
int *D;
void input(){
    int i;
    scanf("%d%d",&N,&K);
    D=(int*)malloc(K);
    for(i=0;i<K; i++) scanf("%d", &D[i]);
}

int judgement(int x){
    int i, j=0;
    for(i=0;i<K;i++){
        if(x==D[i]) j=1;
    }
    if(j==1) return 0;
    else return 1;
}

int main(){
    int a[5];
    int judge[5];
    int pay;
    int i;
    input();
    pay=N;
    while(1){
        a[4]=pay/10000, a[3]=(pay-a[4]*10000)/1000, a[2]=(pay-a[4]*10000-a[3]*1000)/100;
        a[1]=(pay-a[4]*10000-a[3]*1000-a[2]*100)/10, a[0]=pay-a[4]*10000-a[3]*1000-a[2]*100-a[1]*10;
        
        if(pay>=1e4){
            for(i=0;i<5;i++) judge[i]=judgement(a[i]);
        }else if(pay>=1e3){
            for(i=0;i<4;i++) judge[i]=judgement(a[i]);
            judge[4]=1;
        }else if(pay>=1e2){
            for(i=0;i<3;i++) judge[i]=judgement(a[i]);
            judge[4]=1, judge[3]=1;
        }else if(pay>=10){
            for(i=0;i<2;i++) judge[i]=judgement(a[i]);
            judge[4]=1, judge[3]=1,judge[2]=1;
        }else{
            for(i=0;i<1;i++) judge[i]=judgement(a[i]);
            judge[4]=1, judge[3]=1,judge[2]=1,judge[1]=1;
        }
        
        if(judge[0]==0||judge[1]==0||judge[2]==0||judge[3]==0||judge[4]==0) pay++;
        else break;
    }
    
    printf("%d\n", pay);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
	int n,i;
	scanf("%d",&n);
	long long a;
	int t=0,f=0;
	for(i=0;i<n;i++){
		scanf("%lld",&a);
		if(a%4==0)f++;
		else if(a%2==0)t++;
	}
	if(f>=n/2 || t>=n-2*f)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
using namespace std;
struct node{
    long long f;
    long long num;
};
bool cmp(node a,node b){
	return a.f<b.f;
}
struct node data[100005];
int main(){
    long long N,K;
    while(cin>>N>>K){
        for(long long i=0;i<N;i++){
            cin>>data[i].f>>data[i].num;
        }//输入数据
	    sort(data,data+N,cmp);//缺少一个排序 
        long long sum=0;
        for(long long i=0;i<N;i++){
            sum=sum+data[i].num;
            if(sum>=K){
                cout<<data[i].f<<endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#ifdef __APPLE__
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

const int N = (int)1e6 + 123;
const int MOD = (int)1e9 + 7;
const int inf = (int)5e8;
const long long infll = (long long)1e17;


void solve() {
    int q, h, s, d;
    int n;
    scanf("%d %d %d %d %d", &q, &h, &s, &d, &n);
    long long m = n * 4ll;
    h = min(h, 2 * q);
    s = min(s, 2 * h);
    d = min(d, 2 * s);
    long long ans = m / 8 * d;
    m %= 8;
    ans += m / 4 * s;
    m %= 4;
    ans += m / 2 * h;
    m %= 2;
    ans += m * q;
    printf("%lld\n", ans);
}

int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = (int) 1e6 + 10;
const int MOD = (int) 1e9 + 7;

char a[110];
int main(){
	scanf("%s", a);
	if (a[0] == 'S') {
		puts("Cloudy");
	} else if (a[0] == 'C') {
		puts("Rainy");
	} else puts("Sunny");
    return 0;
}


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

int main() {
	int N, C; cin >> N >> C;
	vector<deque<pair<int, int>>> vs(C);
	for (int i=0; i<N; i++) {
		int s, t, c; cin >> s >> t >> c;
		c--;
		vs[c].emplace_back(s, t);
	}

	for (int i = 0; i < C; i++) {
		sort(vs[i].begin(), vs[i].end());
	}

	for (int i = 0; i < C; i++) {
		if (vs[i].empty()) continue;
		deque<pair<int, int>> nv;
		nv.push_back(vs[i][0]);
		for (int j = 1; j < (int)vs[i].size(); j++) {
			if (nv.back().second == vs[i][j].first) {
				auto e = nv.back();
				nv.pop_back();
				e.second = vs[i][j].second;
				nv.push_back(e);
			} else {
				nv.push_back(vs[i][j]);
			}
		}
		vs[i] = nv;
	}
/*
	for (int i = 0; i < C; i++) {
		for (auto e: vs[i]) {
			cout << "(" << e.first << ", " << e.second << ") ";
		}
		cout << "\n";
	}
*/
	vector<int> line(100001);
	for (auto channel: vs) {
		for (auto p: channel) {
			for (int i = p.first; i <= p.second; i++) {
				line[i]++;
			}
		}
	}
	cout << *max_element(line.begin(), line.end()) << "\n";
}

Measured memory_bytes: 1536
/*" بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ -In the name of Allah."
   Never stop chasing!-MD.SOURAV.

   ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
   ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
   ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
   [███████████████████].░░░░░░░░░░░░░░
   ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░
*/

#include <bits/stdc++.h>


#define endl           "\n"
#define MAX            32000
#define F              first
#define S              second
#define sz(x)          x.size()
#define li             long int
#define gcd(a,b)       _gcd(a,b)
#define pb             push_back
#define mp             make_pair
#define asrt(a,n)      sort(a,a+n)
#define MOD 	       1000000007
#define ll             long long int
#define lcd(a,b)       (a*b)/gcd(a,b)
#define mp(x,y)        make_pair(x,y)
#define no             cout<<"NO"<<endl
#define yes            cout<<"YES"<<endl
#define f(i, a, n)     for(int i=a;i<n;i++)
#define test           int t;cin>>t;while(t--)
#define srt(v)         sort(v.begin() , v.end())
#define basrt(a,n)     sort(a,a+n, greater<int>())
#define debug(x)         cout << #x<< ": "<< x<< endl;
#define sumof(x)       accumulate(x.begin(),x.end(),0);
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ignore         cin.ignore (std::numeric_limits<std::streamsize>::max(),'\n');
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }



using namespace std;

double pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664 ;
typedef vector<ll> vll;
typedef vector<int> vii;
typedef map<ll,ll> mllll;
typedef map<char,ll> mchll;
typedef map<string,ll> msll;
typedef vector<pair<ll,ll>> vpllll;
typedef vector<pair<int,int>> vpiiii;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll a1 = a * c;
    ll a2 = a * d;
    ll b1 = b * c;
    ll b2 = b * d;
    cout << max(max(a1, a2), max(b1, b2));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll test_case;
    test_case=1;
    //cin>>test_case;
    while(test_case--)
	{
		solve();
	}

	return 0;
}


Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>
int n,a[2005],b[2005],cnt[2005];
long long ans=0;
int solve(int l,int r){return b[r]-b[l-1];}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),cnt[a[i]]++;
	for (int i=1;i<=2000;i++) b[i]=cnt[i]+b[i-1];
	std::sort(a+1,a+n+1);
	for (int i=1;i<=1000;i++)
	{
		ans=ans+1ll*cnt[i]*(cnt[i]-1)*(cnt[i]-2)/3/2/1;
		for (int j=i+1;j<=1000;j++)
	        ans=ans+1ll*cnt[i]*cnt[j]*solve(j+1,i+j-1)+(i+i>j?1ll*cnt[i]*(cnt[i]-1)/2/1*cnt[j]:0)+1ll*cnt[j]*(cnt[j]-1)/2/1*cnt[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b<c){
        cout<<b+a+b+1<<endl;
    }else{
        cout<<b+c<<endl;
    }
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long LL;
const int LEN = 2e5 + 10;
LL n, k, nums[LEN], L, R;

int main() {
    scanf("%lld%lld", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &nums[i]);
    }
    sort(nums, nums + n);
    L = -1e18, R = 1e18;
    while (L + 1 != R) {
        LL Mid = (L + R) / 2;
        LL cnt = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i] < 0) {
                int l = i, r = n;
                while (l + 1 != r) {
                    int mid = (l + r) / 2;
                    if (nums[i] * nums[mid] <= Mid) {
                        r = mid;
                    } else {
                        l = mid;
                    }
                }
                cnt += n - r;
            } else {
                int l = i, r = n;
                while (l + 1 != r) {
                    int mid = (l + r) / 2;
                    if (nums[i] * nums[mid] <= Mid) {
                        l = mid;
                    } else {
                        r = mid;
                    }
                }
                cnt += l - i;
            }
        }
        if (cnt < k) {
            L = Mid;
        } else {
            R = Mid;
        }
    }
    printf("%lld\n", R);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i < (n); ++i)
#define repD(i, a, n) for(ll i = a; i > (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
// #define mp make_pair
#define pb push_back
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
long long Ceil(long long a, long long b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
ll p=1000000007;
float E = 0.00000000000001;
ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    if(y%2==0){
        ll q=power(x,y/2);
        q=q%p;
        return (q*q)%p;
    }
    ll q=power(x,y/2);
    q=q%p;
    return ((x%p)*((q*q)%p))%p; 
}
bool isPowerOfTwo (long long x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}  

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a); 
}
long long int mod(long long int a, long long int b) {
    long long int ret = a%b; return ret>=0? ret: ret+b; 
}

int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){ 
        int n;
        cin>>n;
        vector <int> vec(int(1e5), 0);
        for(int x = 1 ; x <= 100 ; x++)
            for(int y = 1 ; y <= 100 ; y++)
                for(int z = 1 ; z <= 100 ; z++)
                    vec[x*x + y*y + z*z + x*y + y*z + x*z]++;
        for(int i = 1 ; i <= n ; i++)
            cout<<vec[i]<<endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;

    double p;
    if (n % 2 == 0)
    {
        p = 0.5;
    }
    else
    {
        p = ((n + 1) / 2.0) / n;
    }
    
    cout << p << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B, Q;
  cin>>A>>B>>Q;
  vector<ll> S(A), T(B);
  for(int i=0;i<A;++i) cin>>S[i];
  for(int i=0;i<B;++i) cin>>T[i];
  ll X;
  ll hidaris, migis, hidarit, migit;
  ll hs, ms, ht, mt;
  ll ans;
  for(int i=0;i<Q;++i) {
    cin>>X;
    hidaris = upper_bound(S.begin(), S.end(), X) - S.begin() - 1;
    migis = lower_bound(S.begin(), S.end(), X) - S.begin();
    hidarit = upper_bound(T.begin(), T.end(), X) - T.begin() - 1;
    migit = lower_bound(T.begin(), T.end(), X) - T.begin();
    if(hidaris<0) hs = big;
    else hs = S[hidaris];
    if(migis>=A) ms = big;
    else ms = S[migis];
    if(hidarit<0) ht = big;
    else ht = T[hidarit];
    if(migit>=B) mt = big;
    else mt = T[migit];
    ans = abs(X-hs) + min(abs(hs-ht), abs(hs-mt));
    ans = min(ans, abs(X-ms) + min(abs(ms-ht), abs(ms-mt)));
    ans = min(ans, abs(X-ht) + min(abs(ht-hs), abs(ht-ms)));
    ans = min(ans, abs(X-mt) + min(abs(mt-hs), abs(mt-ms)));
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 4836
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

struct node{
	int money;
	int a[15];
}book[15];
int b[15];

int main(){
	int n,m,x;
	cin>>n>>m>>x;
	for(int i=0;i<n;i++){
		cin>>book[i].money;
		for(int j=0;j<m;j++) cin>>book[i].a[j];
	}
	int ans=1e7;
	for(int i=0;i<(1<<n);i++){
		memset(b,0,sizeof b);
		int sum=0;
		for(int j=0;j<n;j++)
			if(i>>j&1){
				sum+=book[j].money;
				for(int k=0;k<m;k++) b[k]+=book[j].a[k];
			}
		bool flag=1;
		for(int j=0;j<m;j++) if(b[j]<x) flag=0;
		if(flag) ans=min(ans,sum);
	}
	if(ans==1e7) cout<<"-1";
	else cout<<ans;
	return 0;
}

Measured memory_bytes: 3608
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

made_num = list()
for i in range(1, 2**n):
    total = 0
    i_tmp = i
    for j in range(n):
        if i_tmp % 2 == 1:
            total += A[j]
        i_tmp //= 2
    made_num.append(total)

made_num_set = set(tuple(made_num))
for k in range(q):
    if m[k] in made_num_set:
        print("yes")
    else:
        print("no")




Measured memory_bytes: 51052
#include <iostream>
#include <queue>
#include <vector>

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

using namespace std;

struct Edge {int node; int weight;};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef pair<int, int> PII;

using namespace std;

vector<int> djikstra(Graph g, int v) {
    priority_queue<PII, vector<PII>, greater<PII> > q;

    q.push(PII(0, v));

    vector<int> distances(g.size(), -1);
    vector<bool> seen(g.size(), false);
    distances[v] = 0;
    while (! q.empty()) {
        PII p = q.top();
        q.pop();

        int distance = p.first;
        int node = p.second;
        if (!seen[node]) {
            seen[node] = true;
            for (Edge edge : g[node]) {
                if (distances[edge.node] == -1 || distances[edge.node] > distance + edge.weight) {
                    distances[edge.node] = distance + edge.weight;
                    q.push(PII(distances[edge.node], edge.node));
                }
            }
        }


    }

    return distances;
}

int getFurtherPoint(Graph g, int v) {
    vector<int> minDistances = djikstra(g, v);

    int m = -1;
    int point = -1;
    FOR(i, minDistances.size()) {
        if(minDistances[i] > m) {
            m = minDistances[i];
            point = i;
        }
    }

    return point;
}

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

    Graph g(n);

    FOR(_, n-1) {
        int s, t, w;
        cin >> s >> t >> w;
        g[s].push_back(Edge{t, w});
        g[t].push_back(Edge{s, w});
    }

    int v1 = getFurtherPoint(g, 0);
    vector<int> d1 = djikstra(g, v1);
    int v2 = getFurtherPoint(g, v1);
    vector<int> d2 = djikstra(g, v2);

    FOR(i, d1.size()) {
        cout << (d1[i] > d2[i] ? d1[i] : d2[i]) << endl;
    }
}



Measured memory_bytes: 5024
bing1 = list(map(int, input().split()))
bing2 = list(map(int, input().split()))
bing3 = list(map(int, input().split()))

bingo = [bing1,bing2,bing3]
res = [[0,0,0],[0,0,0],[0,0,0]]

n = int(input())

for i in range(n):
    c = int(input())
    for j in range(3):
        for k in range(3):
            if bingo[j][k] == c:
                res[j][k] = 1
                break
                
ress = "No"
if sum(res[0]) == 3 or sum(res[1]) == 3 or sum(res[2]) == 3:
    ress = "Yes"
elif res[0][0] + res[1][0] + res[2][0] == 3 or res[0][1] + res[1][1] + res[2][1] == 3 or res[0][2] + res[1][2] + res[2][2] == 3:
    ress = "Yes"
elif res[0][0] + res[1][1] + res[2][2] == 3 or res[0][2] + res[1][1] + res[2][0] == 3:
    ress = "Yes"
print(ress)

Measured memory_bytes: 3064
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b=mp()
if (a*b)%2==1:
    print("Odd")
else:
    print("Even")

Measured memory_bytes: 76948
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

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

int main() {
    ll N;
    cin >> N;
    ll A[N];
    rep(i,N){
        cin >> A[i];
        if(A[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    sort(A,A+N);
    ll out = 1;
    ll lim = 1000000000000000000;
    rep(i,N){
        ll next_limit = lim/out;
        if(A[i]>next_limit){
            out = -1;
            break;
        }else out *= A[i];
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 4412
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
     int n,count = 0;
     cin >> n;
     string s;
     cin >> s;
     for(int i = 0; i < n; i++){
        if(s[i]=='A' && s[i + 1]=='B' && s[i + 2]=='C'){
            count++;
        }
     }
     cout << count << '\n';
     return 0;
 }


Measured memory_bytes: 3580
# coding:utf-8


def inpl(): return list(map(int, input().split()))


H, W = inpl()
N = int(input())
A = inpl()
color = 0
ans = []
for h in range(H):
    tmp = []
    if h % 2 == 0:
        for w in range(W):
            A[color] -= 1
            tmp.append(color + 1)
            if A[color] == 0:
                color += 1
        ans.append(tmp)

    else:
        for w in range(W)[::-1]:
            A[color] -= 1
            tmp.append(color + 1)
            if A[color] == 0:
                color += 1
        tmp.reverse()
        ans.append(tmp)

for row in ans:
    print(' '.join(map(str, row)))

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s1 = sc.next();
		String s2 = sc.next();
		
		if(s1.charAt(0) == s2.charAt(2)
				&& s1.charAt(1) == s2.charAt(1)
						&& s1.charAt(2) == s2.charAt(0)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}


Measured memory_bytes: 23124
#include<stdio.h>

int judge(int,int,int);

int a[10];

int main(){
    int i,j;
    int n;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        for(j=0;j<10;j++){
            scanf("%d",&a[j]);
        }
        
        if(judge(0,0,0)==1){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    
    return 0;
}

int judge(int c,int d,int m){
    if(m>=10){
        return 1;
    }else{
        if(a[m]>c){
            if(judge(a[m],d,m+1)==1){
                return 1;
            }
        }
        if(a[m]>d){
            if(judge(c,a[m],m+1)==1){
                return 1;
            }
        }
        return 0;
    }
}

Measured memory_bytes: 580
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a+b==c)
    printf("Yes");
    else if(b+c==a)
    printf("Yes");
    else if(a+c==b)
    printf("Yes");
    else
    printf("No");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

template <class M, class OM = M>
struct DelaySegmentTree{
  using FX = function<M(M, M)>;
  using FA = function<M(M, OM)>;
  using FM = function<OM(OM, OM)>;
  using FP = function<M(M, int)>;
  FX fx;
  FA fa;
  FM fm;
  FP fp;
  int n;
  M ex;
  OM em;
  vector<M> data;
  vector<OM> delay;

  DelaySegmentTree(int sz, FX fx, FA fa, FM fm, FP fp, M ex, OM em) 
  : fx(fx), fa(fa), fm(fm), fp(fp), ex(ex), em(em), data(sz*4, ex), delay(sz*4, em){
    n = 1; while(n < sz) n *= 2;
  }

  void build(vector<M> v){
    for(int k = 0; k < v.size(); k++){
      data[k+n-1] = v[k];
    }
    for(int k = n-2; k >= 0; k--){
      data[k] = fx(data[2*k+1], data[2*k+2]);
    }
  }

  void eval(int k, int len){
    if(delay[k] == em) return;
    if(k < n-1){
      delay[2*k+1] = fm(delay[2*k+1], delay[k]);
      delay[2*k+2] = fm(delay[2*k+2], delay[k]);
    }
    data[k] = fa(data[k], fp(delay[k], len));
    delay[k] = em;
  }

  void update(int a, int b, OM x){ update(a, b, x, 0, 0, n); }
  void update(int a, int b, OM x, int k, int l, int r){
    eval(k, r - l);
    if(b <= l || r <= a) return;
    if(a <= l && r <= b){
      delay[k] = fm(delay[k], x);
      eval(k, r - l);
    }else{
      update(a, b, x, 2*k+1, l, (l+r)/2);
      update(a, b, x, 2*k+2, (l+r)/2, r);
      data[k] = fx(data[2*k+1], data[2*k+2]);
    }
  }

  M getval(int a, int b){ return getval(a, b, 0, 0, n); }
  M getval(int a, int b, int k, int l, int r){
    eval(k, r - l);
    if(b <= l || r <= a) return ex;
    if(a <= l && r <= b) return data[k];
    M vl = getval(a, b, 2*k+1, l, (l+r)/2);
    M vr = getval(a, b, 2*k+2, (l+r)/2, r);
    return fx(vl, vr);
  }

  void print(int n){
    cout << "[";
    for(int i = 0; i < n; i++){
      cout << getval(i, i+1) << ", ";
    }
    cout << "]" << endl;
  }
};


signed main(){

  int n, q; cin >> n >> q;
  auto fx = [](int a, int b){ return min(a, b); };
  auto fa = [](int a, int b){ return a + b; };
  auto fm = [](int a, int b){ return a + b; };
  auto fp = [](int a, int b){ return a; };
  DelaySegmentTree<int> seg(n, fx, fa, fm, fp, INF, 0);
  seg.build(vector<int>(n, 0));

  for(int i = 0; i < q; i++){
    int qt; cin >> qt;
    if(qt == 0){
      int s, t, x; cin >> s >> t >> x;
      seg.update(s, t+1, x);
    }else{
      int s, t; cin >> s >> t;
      cout << seg.getval(s, t+1) << endl;
    }
    //seg.print(n);
  }

  return 0;
}


Measured memory_bytes: 9960
//Coalbert Ramirez
//AtCoder Begginer Contest 159A - The Number of Even Pairs
#include <bits/stdc++.h>
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  cout << n*(n-1)/2 + m*(m-1)/2 <<"\n";
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int P[201];

int main() {
  int m, nmin, nmax;
  while (true) {
    scanf("%d %d %d", &m, &nmin, &nmax);
    if (m == 0 && nmin == 0 && nmax == 0) break;
    for (int i=0;i<m;i++) scanf("%d", &P[i]);
    int max_gap = -1, max_n = -1;
    for (int n=nmin;n<=nmax;n++) {
      const int gap = P[n-1]-P[n];
      if (gap >= max_gap) {
        max_gap = gap;
        max_n = n;
      }
    }
    printf("%d\n", max_n);
  }
  return 0;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"
#define llevel 20
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}

int _runtimeTerror_()
{
	
	ll n,x,y,i,j;
	cin>>n>>x>>y;
	ll z=y-x;
	ll ans[n+1];
	for(i=1;i<=n;++i)
		ans[i]=0;
	for(i=1;i<=n;++i)
	{
		for(j=i+1;j<=n;++j)
		{
			ll xx=j-i;
			ll yy=abs(x-i)+abs(y-j)+1;
			ans[min(xx,yy)]++;
		}	
	}
	for(i=1;i<n;++i)
		cout<<ans[i]<<endl;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int64_t N, X, M;
	cin >> N >> X >> M;
	vector<int64_t> v(M,0),w(M, -1);
	if (X == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	int64_t su = 0;
	int64_t curr = 0;
	while (w[X] == -1)
	{
		v[X] = su;
		w[X] = curr;
		su += X;
		X = (X * X) % M;
		++curr;
		if (curr == N)
		{
			cout << su << endl;
			return 0;
		}
 	}
	int64_t dist = curr - w[X];
	int64_t sud = su - v[X];
	int64_t re = (N - curr) / dist;
	curr += re * dist;
	su += re * sud;
	while (curr < N)
	{
		su += X;
		X = (X * X) % M;
		++curr;
	}
	cout << su << endl;
	return 0;
}


Measured memory_bytes: 4748
#include <stdio.h>

int main(){
	int a, b;
	int ans = 0;
  
	scanf("%d%d",&a,&b);

	for (int i = 0; i < 2; i++) {
		if (a > b) {
			ans += a; a--;
		}
		else {
			ans += b; b--;
		}
	}
	printf("%d", ans);

return 0;


}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int d[200005];
int main(void)
{
    int n,k,a,cnt=0,ans=0;
    scanf("%d %d" ,&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d" ,&a);
        d[a]++;
    }
    sort(d+1,d+n+1);
    for(int i=1;i<=n;i++)
    {
        if(d[i]>0)
            cnt++;
    }

    for(int i=1;i<=(n-k);i++)
        ans+=d[i];
    printf("%d" ,ans);
    return 0;
}


Measured memory_bytes: 896
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int dp[3050][8000] = {};
int main() {
	int n, t;
	cin >> n >> t;
	vector<pair<int, int>>np;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		np.push_back(make_pair(a,b));	
	}
	sort(np.begin(), np.end());
	for (int i = 0; i < n; i++) {
		int a = np[i].first;
		int b = np[i].second;
		for (int j = 0; j < 8000; j++) {
			if (j - a >= 0 && j - a < t) {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - a] + b);
			}
			else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}
	int ans = 0; 
	for (int i = 7999; i >= 0; i--) {
		ans = max(ans, dp[n][i]);
	}
	cout << ans;
}

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


int main()
{
	int N;
	static int t[100010];
	static int x[100010];
	static int y[100010];

	cin >> N;
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
	}

	bool enabled = true;

	for (int i = 0; i < N; i++) {
		int span = t[i + 1] - t[i];
		int x_dist = std::abs(x[i + 1] - x[i]);
		int y_dist = std::abs(y[i + 1] - y[i]);

		if (span >= x_dist + y_dist && (span - x_dist - y_dist) % 2 == 0) {
			//ok
		}
		else
		{
			enabled = false;
			break;
		}
	}

	if (enabled) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 1408
N = int(input())
s = []
for i in range(N):
    s.append(int(input()))
stot = sum(s)
#i個のうちいくつか使ってjにできるか
dp = [[False for i in range(stot+101)] for j in range(N+1)]
dp[0][0] = True
for i in range(N):
    for j in range(stot):
        dp[i+1][j+s[i]] = dp[i][j] or dp[i+1][j+s[i]]
        dp[i+1][j] = dp[i][j] or dp[i+1][j]

ans = 0
for i in range(stot+1):
    if dp[N][i] and i % 10 != 0:
        ans = i
print(ans)


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;


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

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

	vector<int> pref(n + 1);
	for (int i = 1; i <= n; i++) {
		pref[i] = ((i ? pref[i - 1] : 0) + a[i - 1] % k) % k;
	}
	for (int i = 1; i <= n; i++) {
		pref[i] = (pref[i] - i%k + k) % k;
	}
	
	map<int, int> mp;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i - k>= 0) mp[pref[i - k]]--;
		ans += mp[pref[i]];
		mp[pref[i]]++;
	}

	cout << ans;
}
	

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String a[] = new String[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.next();
        }

        Set<String> set = new HashSet<>();
        
        for (int i = 0; i < n; i++) {
            set.add(a[i]);
        }
        
        if(set.size() == 4){
            System.out.println("Four");
        }else{
            System.out.println("Three");
        }

        sc.close();
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	ll N;cin >> N;
	vector<ll> A(N); rep(i,N) cin >> A[i];

	if(N == 1) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 0;
	ll mx = A[0];
	for(int i = 1; i < N; i++){
		if(A[i] < mx){
			ans += mx-A[i];
		}
		else{
			mx = A[i];
		}
	}

	cout << ans << endl;
}	

Measured memory_bytes: 12620
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
#define int ll
void solve() {
    int m;
    cin >> m;
    int ans = -1;
    int cnt = 0;
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        ans += b;
        cnt += a * b;
    }
    ans += (cnt-1LL) / 9LL;
    cout << ans << endl;
}
#undef int
int main() {
    init();
    solve();
}


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

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

  int n;
  while(cin>>n&&n){
    int ans = 0;
    for(int i=0;i<n/4;++i){
      int tmp;cin>>tmp;
      ans += tmp;
    }
    cout<<ans<<endl;
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main(){
 string s;
 cin>>s;
  
 if(s == "ABC"){
  cout<< "ARC" <<endl;
 } 
 else if(s == "ARC"){
  cout<< "ABC" <<endl;
 } 
}


Measured memory_bytes: 3596
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 1000000000
typedef long long ll;
typedef pair<ll,int> P;

ll dp[110][110000];

int main(){
  ll N,W,w[110],v[110];
  cin>>N>>W;
  for(int i=1;i<=N;i++){
    cin>>w[i]>>v[i];
  }

  for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
      dp[i][j]=dp[i-1][j];
      if(j-w[i]>=0) dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
    }
  }
  ll ans=0;
  for(int i=0;i<=W;i++){
    ans=max(ans,dp[N][i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 87424
n = int(input())
ar = list(map(int,input().split(" ")))
st = ar[0] - 1
for i in range(1,n):
    if st <= ar[i]:
        if ar[i] == st:
            st = ar[i]
        else:
            st = ar[i] - 1
    else:
        print("No")
        exit()
print("Yes")

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

int main()
{
	int N, M;
	while (cin >> N >> M && N != 0 || M != 0)
	{
		int r;
		cin >> r;
		static int timeLine[10000 + 1][24 * 60 - 540];
		static int pcNumber[1000 + 1];
		for (int i = 0; i < M + 1; i++)
		{
			for (int j = 0; j < 24 * 60 -540;j++)
			{
				timeLine[i][j] = 0;
			}
		}

		for (int i = 0; i < r; i++)
		{
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			if (s == 1)
			{
				pcNumber[n] = t;
			}
			else
			{
				for (int j = pcNumber[n] - 540; j < t- 540; j++)
				{
					timeLine[m][j] = 1;
				}
			}
		}

		int q;
		cin >> q;

		for (int i = 0; i < q; i++)
		{
			int start, end, m;
			cin >> start >> end >> m;
			int ans = 0;
			for (int j = start -540; j < end - 540; j++)
			{
				if (timeLine[m][j] == 1)
				{
					ans++;
				}
			}

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

Measured memory_bytes: 35980
//57
#include<iostream>

using namespace std;

int main(){
  bool cmp[50001]={true,true};
  for(int i=2;i<50001;i++){
    if(!cmp[i]){
      for(int j=2;j*i<50001;j++){
	cmp[i*j]=true;
      }
    }
  }
  for(int n;cin>>n,n;){
    int ans=0;
    for(int i=0;i<=n-i;i++){
      ans+=!cmp[i]&&!cmp[n-i];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 916
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int cnt = 0;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        if (a == cnt+1) {
            cnt++;
        }
    }
    if (cnt == 0) {
        cout << -1 << endl;
    } else {
        cout << n-cnt << endl;
    }
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main()
{
    char arr[6];
    string result;
    for(int i=0;i<6;i++){
        cin>>arr[i];
    }
    for(int i=0;i<6;i++){
        if(arr[2]==arr[3]&&arr[4]==arr[5]){
            result="Yes";
        }
        else{
            result="No";
        }
    }
cout<<result;
    return 0;
}

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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, T; cin>>n>>T;
    vector<int> t(n);
    REP(i,n) cin>>t[i];
    int ans = 0;
    REP(i,n-1){
        if(t[i+1]-t[i]>T) ans+=T;
        else ans+=t[i+1]-t[i];
    }
    ans+=T;
    print(ans);
    return 0;
}

Measured memory_bytes: 1024
/* author : akshatjai258 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define int ll
#define mod int(1e9 + 7)
#define inf int(1e9)
#define endl "\n"
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define fi first
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define memf(a) memset(a, false, sizeof(a))
#define all(v) v.begin(), v.end()
#define se second
#define mp make_pair
#define pb push_back
#define w(x)  \
	int x;    \
	cin >> x; \
	while (x--)
#define ps(x, y) fixed << setprecision(y) << x
void prep()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
}
int32_t main()
{
	prep();
	string s,t;
	cin>>s>>t;
	int n=t.length();
	string p=s+t[n-1];
	if(p==t)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
const int FIVE = 101010;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
int a,b,c,d;
//=============================
void input()
{
    cin>>a>>b>>c>>d;
}
//=============================
void func(){}
int diff(int x, int y){
    return abs(x-y);
}
//=============================
void solve()
{
    bool ans = true;
    if ((diff(b,c)>d || diff(a,b)>d) && diff(a,c)>d)ans=false;
    cout<<(ans ? "Yes" : "No")<<endl;
    
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

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

using namespace std;

#define LL long long
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int i,n;
LL k,a[200005];

bool Check(LL val)
{
    LL cnt=0;
    for(i=1;i<=n;i++)
    {
        cnt+=a[i]/val;
        if(a[i]%val == 0)--cnt;
    }
    return cnt > k;
}

int main()
{
    FAST();
    LL l=1,m,r=0;
    cin >> n >> k;
    for(i=1;i<=n;i++)cin >> a[i],r=max(r,a[i]);
    while(l <= r)
    {
        m=(l+r) >> 1LL;
        if(Check(m))l=m+1;
        else r=m-1;
    }
    cout << l;
    return 0;
}


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

int main() 
{
    int m, f,r,su;
    while (true){
       cin >> m >> f >> r;
       su = m + f;
       if (m == -1 && f == -1 && r == -1){
           break;
       }
       else if (m == -1 || f == -1 || su < 30){
           cout << "F" << endl;
       }
       else if(su >= 80){
           cout << "A" <<endl;
       }
       else if(su >= 65){
           cout << "B" << endl;
       }
       else if(su >= 50){
           cout << "C" << endl;
       }

       else{
           if(r >= 50) cout << "C" << endl;
           else cout << "D" << endl;
       }

    }
    return 0;

}




Measured memory_bytes: 3080
#include <iostream>
#include <queue>
#include <string>
#include<algorithm>
using namespace std;

#define P pair<string,int>


queue<P> d;
int n, q;
int main() {
	int nowtime = 0;
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		string name; int time;
		cin >> name >> time;
		d.push(P(name, time));
	}

	while (!d.empty()) {
		if (d.front().second <= q) {
			nowtime += d.front().second;
			cout << d.front().first << " " << nowtime << endl;
			d.pop();
		}else {
			P buf = d.front();
			d.pop();
			buf.second -= q;
			nowtime += q;
			d.push(buf);
		}
	}

}

Measured memory_bytes: 6216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main() {
int n,k;
cin>>n>>k;
vector<int> p(n+1,0);
p[0]=1;
for(int i=0; i<n; i++)
{
    p[i+1]=min(p[i]+k, p[i]*2);
}

cout<<p[n]<<endl;
}


Measured memory_bytes: 256