akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.14159265
#define pb push_back
#define bits(n) __builtin_popcount(n)

void solve()
{
    
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t=1;
    //cin >> t;
    while(t--)
    {
        int a[3][3];
        for (int i = 0; i < 3; i++)
        {
            for (int j= 0; j < 3; j++)
            {
                    cin >> a[i][j];
                }
            }
        
        int n;
        cin >> n;
        //int b[n];
        for (int k = 0; k < n; k++)
        {
            int b;
            cin >> b;
            int z=0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (b == a[i][j])
                    {
                      //cout<<"Yes";
                        a[i][j] = 0;
                        z=1;
                        break;
                    }
                }
                if(z==1)
                break;
            }
        }

        for (int i = 0; i < 3; i++)
        {
            int c = 0;
            for (int j = 0; j < 3; j++)
            {
                if (a[i][j] == 0)
                    c++;
                if (c == 3)
                {
                    cout << "Yes";
                    return 0;
                }
            }
        }
        for (int i = 0; i < 3; i++)
        {
            int c = 0;
            for (int j = 0; j < 3; j++)
            {
                if (a[j][i] == 0)
                    c++;
                if (c == 3)
                {
                    cout << "Yes";
                    return 0;
                }
            }
        }
      //cout<<c;
        int c = 0;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (i == j && a[i][j] == 0){
                    c++;
              //cout<<c;
                }
            }
        }
        if (c == 3)
        {
            cout << "Yes";
            return 0;
        }
     // cout<<c;
        int d = 0;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (i + j == 2 && a[i][j] == 0)
                    d++;
            }
        }
        if (d == 3)
        {
            cout << "Yes";
            return 0;
        }
        else
            cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    map<ll, int> m;
    bool ok=true;
    for(int i=0; i<n; i++){
        cin>>a[i];
        m[a[i]]++;
        if(m[a[i]]==2){
            ok=false;
        }

    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

int main() {
	long long int n, W, v[100001]={0}, temp, temp2, max;
	cin>>n>>W;
	while(n--){
		cin>>temp>>temp2;
		for(int i=100000;i>=0;i--){
			if(v[i-temp2]==0){
				continue;
			}
			else if(i-temp2>0){
				if((v[i]>v[i-temp2]+temp||v[i]==0)&&v[i-temp2]+temp<=W){
					v[i]=v[i-temp2]+temp;
				}
			}
		}
		if(v[temp2]>temp||v[temp2]==0){
				v[temp2]=temp;
		}
	}
	for(int i=0;i<=100000;i++){
		if(v[i]!=0){
			max=i;
		}
	}
	cout<<max;
	return 0;
}

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

#define REP(i,n) for(int i=0;i<=(int)n;i++)
#define REP1(j,n) for(int j=0;j<=(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n, y;
	cin >> n >> y;
	REP(i, n) {
		REP1(j, n-i) {
			int z = ((n - i - j) < 0) ? 0 : n - i - j;
			if (y == i * 10000 + j * 5000 + z * 1000) {
				cout << i <<" "<< j <<" "<< z << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;

}



Measured memory_bytes: 256
# dp[i]: i+1にくるまでにかかったコストの最小値
N = int(input())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N-1):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]))
    if i < N-2:
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]))
print(dp[-1])

Measured memory_bytes: 53440
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

#define max_n 10000

int main(void) {
    int i,j;
    int n;
    cin >> n;
    while(n--){
        string s;
        cin >> s;
        i = 0;
        vector<vi> v(max_n);
        vector<vi> a(max_n);

        queue<int> q;

        rep(i,s.size()){
            if(s[i] == '['){
                //cout << i << " " << "A" << " " << q.size() << endl;
                v[q.size()].push_back(i);
                q.push(i);
            }else if(s[i] == ']'){
                //cout << i << " " << "B" << " " << q.size() << endl;
                q.pop();
                v[q.size()].push_back(i);
            }else{
                int t = s[i] - '0';
                while(isdigit(s[i+1])){
                    t *= 10;
                    t += s[i+1] - '0';
                    i++;
                }
                a[q.size()-1].push_back((t+1)/2);
            }

        }


        rep(i,max_n)if(a[i+1].size())break;

        for(; i >= 0; i--)rep(j,v[i].size()){
            int s = v[i][j];
            int g = v[i][j+1]; j++;
            int si = lower_bound(all(v[i+1]), s) - v[i+1].begin();
            int gi = lower_bound(all(v[i+1]), g) - v[i+1].begin();
            gi--;
            si /= 2;
            gi /= 2;
            vi p;
            for(int k = si; k <= gi; k++) p.push_back(a[i+1][k]);
            sort(all(p));
            int sum = 0;
            for(int k = 0; k < p.size()/2 + 1; k++ ) sum += p[k];

            a[i].push_back(sum);

        }

        cout << a[0][0] << endl;

    }
}



Measured memory_bytes: 3396
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n");
  const [n, k] = lines.shift().split(' ').map(Number);
  const w = lines.map(Number);

  const canAllStack = (p) => {
    let cnt = 0, sum = 0;
    for (let i = 0; i < k; i++)
      for (sum = 0; sum + w[cnt] <= p;) {
        sum += w[cnt++];
        if (cnt === n) return n;
      }
    return cnt;
  };

  let mid, left = 0, right = 1e9;
  while (right - left > 1) {
    mid = (right + left) / 2;
    if (canAllStack(mid) >= n) right = mid;
    else left = mid;
  }
  console.log(Math.floor(right));
})();



Measured memory_bytes: 29488
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    REP(i, 1, 100000) {
        double a = (double)i * 0.08;
        double b = (double)i * 0.1;
        ll aa = floor(a);
        ll bb = floor(b);
        if (aa == A && bb == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
}


Measured memory_bytes: 256
import math
N = int(input())

ans = 0
for i in range(3,N+1):
    if i < 105:
        continue
    elif i%2 == 0:
        continue
    counter = 1
    n = math.floor(math.sqrt(i))
    for j in range(2,n+1):
        a = 0
        while i%j == 0:
            a += 1
            i /= j
        if a > 0:
            counter *= (a+1)
    if counter == 8:
        ans += 1
print(ans)
            

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, x;
	cin >> n >> x;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	//I think this is just a greedy
	ll ans = 0LL;
	for(ll i = 0; i < (n - 1); i++){
		if((a[i] + a[i + 1]) > x){
			if(a[i] > x){
				ans += a[i + 1];
				a[i + 1] = 0;
				ans += a[i] - x;
			}
			else{
				ans += (a[i] + a[i + 1]) - x;
				a[i + 1] -= (a[i] + a[i + 1]) - x;
			}
		}
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		double ans = 0;
		String str = "";
		double num = 0;
		for(int i = 0;i <n;i++){
			num = saori.Hayamin();
			str = saori.nextHayami();
			if(str.equals("JPY")){
				ans += num;
			} else {
				ans += num*380000;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
/* ex4_2
    riverstone*/

#include<stdio.h>
#include<math.h>

int main(void){

    //時針の長さlen_hourと分針の長さlen_minute、その瞬間での時hourと分minuteを受け取る
    double len_hour, len_minute, hour, min;
    scanf("%lf %lf %lf %lf", &len_hour, &len_minute, &hour, &min);

    double theta_h = 2 * M_PI * (hour + min/60)/12; //時針と12の間のなす角度 [rad]
    double theta_m = 2 * M_PI * min/60; //分針と12の間のなす角度[rad]
    double theta = theta_h - theta_m; //時針と分針の間のなす角度[rad]
    
    //余弦定理より距離を求める
    double ans = sqrt(pow(len_hour, 2) + pow(len_minute, 2) - 2*len_hour*len_minute * cos(theta)); 
 
    printf("%.10f\n", ans); //ansを出力
 
    return 0;

}

Measured memory_bytes: 2600
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;

const int max_n=100000+10;
int a[max_n];
int b[max_n];
int t[max_n];


int main(){
  int n;
  cin>>n;
  bool flag=true;
  for(int i=1;i<=n;i++){
    cin>>t[i]>>a[i]>>b[i];
    int tmp;
    tmp=abs(a[i]-a[i-1])+abs(b[i]-b[i-1]);
    if(tmp<=t[i]-t[i-1] and tmp%2==(t[i]-t[i-1])%2){
      continue;
    }
    else {flag=false;}
  }
  if(flag)
  cout<<"Yes\n"<<endl;
  else cout<<"No\n"<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += a[i]-1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  	long long n, k, sum = 0;
  	vector<long long> vec;
  	cin >> n >> k;
  	for(long long i = 0; i < n; i++) {
     	long long x;
      	cin >> x;
      	vec.push_back(x);
    }
  	sort(vec.rbegin(), vec.rend());
  	for(long long i = k; i < n; i++) {
     	sum += vec[i]; 
    }
  	cout << sum << endl;
	return 0; 
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int n;
  cin >> n;
  ll y;
  cin >> y;
  ll a = y/(ll)10000+1;
  ll b = y/(ll)5000+1;
  for(int i = 0; i <= a; i++) {
    for(int j = 0; j <= b && (i+j)<=n; j++) {
      if(i*10000+j*5000+(n-i-j)*1000 == y) {
        cout << i << " " << j << " " << n-i-j << endl;
        return 0;
      } 
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    string s, t, u;
    bool flag;
    cin >> s >> t;
    vector<string> ans;
    for(int i = (int)s.size() - (int)t.size(); i >= 0; i--){
        flag = 1;
        u.erase(u.begin(), u.end());
        for(int j = 0; j < (int)t.size(); j++){
            if(s[i+j] != '?' && s[i+j] != t[j]){
                flag = 0;
                break;
            }
        }
        if(flag == 1){
            for(int j = 0; j < (int)s.size(); j++){
                if(i <= j && j < i + (int)t.size()){
                    u += (s[j] == '?' ? t[j-i] : s[j]);
                }
                else{
                    u += (s[j] == '?' ?   'a'  : s[j]);
                }
            }
            ans.push_back(u);
        }
    }
    if(ans.empty() != 0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 256
X=int(input())

A=X-X//500*500
B=A-A//100*100
C=B-B//50*50
D=C-C//10*10
E=D//5
app=X//500*1000 + E*5

F=A//5
maxi=X//500*1000 + F*5

print(max([app,maxi]))

Measured memory_bytes: 3060
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A, B = map(int, readline().split())
    P = list(map(int, readline().split()))
    a = 0
    b = 0
    c = 0
    for p in P:
        if p<=A:
            a += 1
        elif A<p<=B:
            b += 1
        else:
            c += 1
    print(min(a,b,c))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

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

	constexpr int LEN = 8;

	for(int n, m; cin >> n >> m && (n | m);) {
		vector<tuple<bool, vector<int>, string>> rules;

		rep(i, n) {
			string which, source, destination;
			cin >> which >> source >> destination;

			const string sum = source + destination;
			vector<int> pos;
			pos.reserve(LEN * 2);
			rep(j, sum.size()) {
				if(sum[j] == '?') pos.emplace_back(j);
			}

			const bool is_permit = (which[0] == 'p');
			rules.emplace_back(is_permit, pos, sum);
		}

		reverse(ALL(rules));
		vector<tuple<string, string, string>> match;
		match.reserve(m);

		rep(i, m) {
			string source, destination, body;
			cin >> source >> destination >> body;

			for(const auto &rule : rules) {
				string sum = source + destination;

				for(const auto &pos : get<1>(rule)) {
					sum[pos] = '?';
				}

				if(get<2>(rule) == sum) {
					if(get<0>(rule)) match.emplace_back(source, destination, body);
					break;
				}
			}
		}

		cout << match.size() << endl;
		for(const auto &e : match) {
			cout << get<0>(e) << " " << get<1>(e) << " " << get<2>(e) << endl;
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1400
import math
N=int(input())
x=[]
min=10000000000000000
ans=0
sqN=math.ceil(math.sqrt(N))
for i in range(1,sqN+1):
  if N%i==0:
    j=int(N/i)
    a=[i,j]
    x.append(a)
for i,j in x:
  if i+j<=min:
    ans=i+j-2
    min=i+j
print(ans)

Measured memory_bytes: 3464
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<string, int> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}

string in;
int tot[55][55];

int main()
{
	ios_base::sync_with_stdio(false);
	ll n;
	while (cin >> n) {
		ll t0=1,a0=1;
		rep(i, n) {
			ll t, a;
			cin >> t >> a;

			ll c1 = (t0 + t - 1) / t;
			ll c2 = (a0 + a - 1) / a;
			ll N = max(c1, c2);
			t0 = N * t;
			a0 = N * a;
		}
		cout << t0 + a0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; ++i) cin >> a[i];

	long long money=1000, stock=0;
	for(int i=0; i<n-1; ++i){
		if(a[i]<a[i+1]){
			stock = money/a[i];
			money %= a[i];
		}
		money += stock*a[i+1];
		stock=0;
	}
	cout << money << endl;
}

Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,j,N,H,W,ans=0;
  cin>>N;
  ans+=N/500*1000;
  N%=500;
  ans+=N/5*5;
  print(ans);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
S = sorted([int(input()) for i in range(n)])
ans = sum(S)

if ans % 10 != 0:
    print(ans)
else:
    for i in range(n):
        if S[i] % 10 != 0:
            ans -= S[i]
            break
        elif i == n-1:
            ans = 0
            
    print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
  int N, T;
  scanf("%d %d", &N, &T);
  vi t(N);
  cin >> t[0];
  ll sum = T;
  for (int n = 1; n < N; n++) {
    cin >> t[n];
    if (t[n] < t[n-1] + T) {
      sum = sum - (t[n-1] + T - t[n]) + T;
    } else {
      sum += T;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
  int N;
  cin >> N;
  vector<string> S(N);

  for(int i = 0;i < N;i++){
    cin >> S[i];
  }
  sort(S.begin(),S.end());
  S.erase(unique(S.begin(),S.end()),S.end());
  cout << S.size();

  return 0;
}

Measured memory_bytes: 9596
#include<cstdio>
#include<algorithm>
using namespace std;
long long A,B,k;
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%lld %lld %lld",&A,&B,&k);
	if(B-A+1<=2*k) {
		for(long long i=A;i<=B;i++)
			printf("%lld\n",i);
	} else {
		for(long long i=0;i<k;i++)
			printf("%lld\n",A+i);
		for(long long i=k-1;i>=0;i--)
			printf("%lld\n",B-i);
	}
	return 0;
}

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

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());
  
  long N,M;
  cin>>N>>M;

  vector< pair <long,long> > E(N);
  for(int i=0;i<N;i++){
    cin>>E.at(i).first>>E.at(i).second;
  }

  sort(E.begin(),E.end());

  //for(int i=0;i<N;i++) cout<<E.at(i).first<<','<<E.at(i).second<<endl;

  long ans=0;
  long num;
  long i=0;
  while(num<M){
    num += E.at(i).second;
    ans += E.at(i).first*E.at(i).second;
    i++;
  }
  //cout<<num<<','<<ans<<','<<i<<endl;
  ans = ans-(num-M)*E.at(i-1).first;
  cout<<ans<<endl;
}

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

int main() {
  // ひなあられN個
  int N;
  cin >> N;
  bool Y = false;

  
  // ここにプログラムを追記
  for (int i = 0; i < N; i ++) {
    string S;
    cin >> S;
    if (S == "Y") {
      Y = true;
    }
  }
  if (Y) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
 
template<class I>
inline I max(I a, I b) {
	return a > b ? a : b;
}
 
long long _k, n, p[5010], c[5010], preans[5010], ed[5010], dis[5010], ans = -2147483647;
bool vis[5010];
 
long long getend(long long now, long long _from, long long _st) {
	if (!vis[now]) {
		vis[now] = 1;
		preans[now] = c[now] + preans[_from];
		long long t = getend(p[now], now, _st);
		ed[now] = t == -1  ? now : t,
		dis[now] = t == -1 ? 0 : dis[p[now]] + 1;
		return ed[now];
	}
	else
		return -1;
}
 
int main(void) {
	scanf("%lld%lld", & n, & _k);
	for (int i = 1; i <= n; ++i)
		scanf("%lld", p + i);
	for (int i = 1; i <= n; ++i)
		scanf("%lld", c + i);
	for (int i = 1; i <= n; ++i)
		if (!vis[i])
			ed[i] = getend(i, 0, i);
	for (int i = 1; i <= n; ++i) {
		long long tans = 0, k = _k, ttans = -2147483647, tttans = 0;
		if (dis[i] >= k) {
			long long now = i;
			for (int j = 1; j <= k; ++j)
				tans += c[now],
				ttans = max(ttans, tans),
				now = p[now];
		} else {
			long long now = i;
//			printf("%d\n", dis[now]);
			while (dis[now]) {
				tans += c[now],
				ttans = max(ttans, tans),
				now = p[now],
				--k;
				if (k == 0)
					goto A;
			}
			tans += c[now],
			ttans = max(ttans, tans),
			--k,
			tttans = tans;
			if (k / (dis[p[now]] + 1) > 0) {
				tans += preans[ed[i]] * (k / (dis[p[now]] + 1) - 1),
				k %= (dis[p[now]] + 1),
				k += dis[p[now]] + 1;
			} else {
				k %= (dis[p[now]] + 1);
			}
			tans = max(tans, tttans),
			now = p[now];
			if (!k)
				goto A;
			if (tans != tttans)
			for (int j = 1; j <= k; ++j)
				tans += c[now],
				ttans = max(ttans, tans),
				now = p[now];
			else while (dis[now]) {
				tans += c[now],
				ttans = max(ttans, tans),
				now = p[now],
				--k;
				if (k == 0)
					goto A;
			}
		}
A:
//		printf("%d\n", ttans);
		ans = max(ans, ttans);
	}
	printf("%lld\n", ans);
	return 0;
}


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

ll INF = 1e18;
ll MOD = 1e9+7;



int main() {
    ll N; cin >> N;
    string S; cin >> S;
    map<char, ll> M;
    for(auto ch : S) M[ch]++;
    ll ans = M['R'] * M['G'] * M['B'];
    for(int s = 1; s < N; s++){
        int i = 0;
        int j = s;
        int k = 2*s;
        if(k >= N) break;
        for(int l = 0; l < N; l++){
            if(k+l >= N) break;
            //
            if(S[i+l] != S[j+l] && S[j+l] != S[k+l] && S[k+l] != S[i+l]) {
                ans--;
            }
        }
    } 
    cout << max(ans, (ll)0) << endl;

}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n;
	cin>>n;
	ll count = 0;
	ll a[n];
	for(ll i = 0; i<n; i++)
	{
		cin>>a[i];
	}
	for(int i = 0; i<n-2; i++)
	{
		for(int j = i; j<n-1; j++)
		{
			if(a[i]==a[j])
			{
				continue;
			}
			for( int k = j; k<n; k++)
			{
				if(a[j]==a[k]|| a[k]==a[i])
				{
					continue;
				}
				else
				{
				if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i])
				{
					count++;
				}
				}
			}
		}
	}
	cout<<count;
}

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

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;


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

	cin>>N>>M;
	vector<long long int>dp(1<<N,MOD);
	dp[0]=0;
	for(int i=0;i<M;i++){
		cin>>L>>R;
		int bit=0;
		for(int j=0;j<R;j++){
			cin>>K;
			bit|=1<<(K-1);
		}
		for(int j=0;j<1<<N;j++){
			//if(j&bit)continue;
			dp[j|bit]=min(dp[j|bit],dp[j]+L);
		}
	}
	if(dp.back()==MOD)dp.back()=-1;
	cout<<dp.back()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int s[5],i,k,j,sum;
	for(i=0;i<5;i++){
	scanf("%d",&s[i]);
	}
	for(j=0;j<4;j++){
		for(k=j+1;k<5;k++){
			if(s[k]>s[j]){
				sum=s[j];
				s[j]=s[k];
				s[k]=sum;
			}
		}
	}
	printf("%d %d %d %d %d\n",s[0],s[1],s[2],s[3],s[4]);
	return 0;
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RANK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 2e5+233; 
int a[maxn],n,ans=0;
bool check(int limit){
	rep(i,0,n){
		if(a[n-i]>=limit&&a[n-i-1]>=limit) return 1;
		if(a[n-i]<limit&&a[n-i-1]<limit) return 0;
		if(a[n+i]>=limit&&a[n+i+1]>=limit) return 1;
		if(a[n+i]<limit&&a[n+i+1]<limit) return 0;
	}
	return a[1]>=limit;
}
int main(){
	n = rd();
	Rep(i,1,2*n-1) a[i] = rd();
	int l = 1,r = 2*n+1;
	while(l <= r){
		int mid = (l+r) >> 1;
//		printf("[%d %d]\n",mid,check(mid));
		if(check(mid) == 1){
			l = mid + 1;
			ans = mid;
		} else{
			r = mid - 1;
		}
	}writeln(ans);
	return 0;
}




/*	for (int i=0;i<n-1;i++){
		int s0=0,s1=0;
		if (a[n-i]>=mid&&a[n-i-1]>=mid) s1++;
		if (a[n-i]<mid&&a[n-i-1]<mid) s0++;
		if (a[n+i]>=mid&&a[n+i+1]>=mid) s1++;
		if (a[n+i]<mid&&a[n+i+1]<mid) s0++;
		if (s1) return 1;
		if (s0) return 0;
	}
*/

Measured memory_bytes: 1024
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
//void chmin(ll &a,ll b){ if(a>b) a = b ;}

int main(){
    ll n,k ;
    cin >> n >> k ;
    vector<pll> a(n) ;
    for(int i=0;i<n;i++) cin >> a[i].second >> a[i].first ;
    sort(all(a)) ;
    reverse(all(a)) ;
    vll cnt(n+1,0) ;
    ll pos1,pos2 ;
    ll sum = 0 ;
    ll add = 0 ;
    for(int i=0;i<k;i++){
        sum += a[i].first ;
        if(cnt[a[i].second]==0) add++ ;
        cnt[a[i].second]++ ;
    }
    pos1 = k-1 ;
    pos2 = k ;
    ll ans = sum+add*add ;
    while(1){
        while(0<=pos1&&cnt[a[pos1].second]<=1) pos1-- ;
        if(pos1==-1) break ;
        while(pos2<n&&cnt[a[pos2].second]>=1) pos2++ ;
        if(pos2==n) break ;
        sum -= a[pos1].first-a[pos2].first ;
        add++ ;
        cnt[a[pos1].second]-- ; pos1-- ;
        cnt[a[pos2].second]++ ; pos2++ ;
        chmax(ans,sum+add*add) ;
    }
    cout << ans << endl ;
}

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

int main()
{
    string s;
    int count[26] = {};
    while (getline(cin, s)) {
        for (int i = 0; i < int(s.size()); i++) {
            char c = s[i];
            if (0x41 <= c && c <= 0x5a) count[c - 0x41] += 1;
            else if (0x61 <= c && c <= 0x7a) count[c - 0x61] += 1;
        }
    }
    for (int i = 0; i < 26; i++) {
        cout << char(i + 0x61) << " : " << count[i] << endl;
    }
}



Measured memory_bytes: 3172
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;

ll gdc(ll x, ll y)
{
	if (y>x) 
	{
		ll t=y;
		y=x;
		x=t;
	}
	ll r=x%y;
	while (r>0)
	{
		x=y;
		y=r;
		r=x%y;
	}
	return y;
}

int main(int argc, char *argv[])
{
	ll a,b;

	cin >> a >> b;
	ll g=gdc(a,b);
	cerr << g << endl;
	
	int ret=1;
	for (ll i=2; i*i<=g;i++)
	{
			//cerr << "1:g=" << g << " i=" << i << endl;
		if (g%i==0)
		{
			//cerr << "2:g=" << g << " i=" << i << endl;
			ret++;
			while (g%i==0) g/=i;
			//cerr << "3:g=" << g << " i=" << i << endl;
		}
	}
	ret+=(g>1);

	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[100005]={};
  int sum=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
 	sum+=abs(a[i]-a[i-1]);
 }
  sum+=abs(a[n]);
  for(int i=1;i<=n;i++){
    if((a[i-1]<a[i]&&a[i]<a[i+1])||(a[i]-1>a[i]&&a[i]>a[i+1])){
      cout<<sum<<endl;
    }else{
      cout<<sum-(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))+abs(a[i+1]-a[i-1])<<endl;
    }
  }
}

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

int main() {
  int n; cin >> n;
  int r1 = n%10;
  string ans = "hon";
  if (r1 == 0 || r1 == 1 || r1 == 6 || r1 == 8) ans = "pon";
  if (r1 == 3) ans = "bon";
  cout << ans << endl;
}

Measured memory_bytes: 3628
#!/usr/bin/env python

n = int(input())
a = list(map(int, input().split()))

now = 1 
for i in range(n):
    if a[i] == now:
        now += 1

now -= 1
if now == 0:
    print(-1)
else:
    ans = n-now
    print(ans)


Measured memory_bytes: 32272
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll h,w,n;
  cin >> h >> w >> n;
  ll a[h][w];
  mem(a);
  while(n--) {
    int x,y,z;
    cin >> x >> y >> z;
    rep(i,h) {
      rep(j,w) {
        if(z==1&&i<x) a[i][j]=1;
        if(z==2&&i>=x) a[i][j]=1;
        if(z==3&&j<y) a[i][j]=1;
        if(z==4&&j>=y) a[i][j]=1;
      }
    }
  }
  ll ans=h*w;
  rep(i,h)rep(j,w) ans-=a[i][j];
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

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

  int a, b, c;
  cin >> a >> b >> c;

  if (a + b == c || a + c == b || b + c == a) cout << "Yes\n";
  else cout << "No\n";

  return (0);
}


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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort((c).begin(), (c).end(), greater<int>());
#define fi first
#define se second
  
typedef pair<int,int> P;
typedef vector<int> vi;

int N;
vi d;

signed main() {
    cin>>N;
    rep(i,0,N) {
        int D; cin>>D; d.pb(D);
    }

    SORT(d);
    int n=N/2-1,ans=0;
    if(d[n]==d[n+1]) {
        ans=0;
    }else{
        ans=d[n+1]-d[n];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1400
N = int(input())
S = list(map(int, input().split()))
Q = int(input())
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    idx = int((head+tail)/2)
    if target_num == S[idx]:
        return True
    elif target_num < S[idx]:
        if head == idx:
            return False
        return binary_search(target_num, head, idx-1)
    else:
        if tail == idx:
            return False
        return binary_search(target_num, idx+1, tail)


match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S)-1):
        match_count += 1

print(str(match_count))


Measured memory_bytes: 16712
n=int(input())

pdat=[]
mdat=[]

for i in range(n):
    s=input()
    
    mini=0
    now=0
    for q in range(len(s)):
        if s[q]=="(":
            now+=1
        else:
            now-=1
            mini=(min(mini,now))
    if now>=0:
        pdat.append((now,mini,mini-now))
    else:
        mdat.append((now,mini,mini-now))

pdat.sort(key=lambda x:-x[1])
mdat.sort(key=lambda x:x[2])

now=0
for d in pdat+mdat:
    if now+d[1]<0:
        print("No")
        break
    now+=d[0]
else:
    if now==0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 235804
#include <cstdio>
#include <vector>
#include <functional>

using namespace std;

int main() {
    vector<int> a(3);
    for (int i = 0; i < 3; i++) {
        int d;
        scanf("%d", &d);
        a.push_back(d);
    }
    sort(a.begin(), a.end(), greater<int>());
    printf("%d\n", a[0] * 10 + a[1] + a[2]);
    return 0;
}


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

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 2; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 

const double PI =  3.141592653589793;

int main(){
	IO;
	ll n,m,a;
	cin>>n>>m;
	map<ll,ll> mp;
	while(m--){
		cin>>a;
		mp[a]++;
	}
	ll dp[n+1];
	dp[0]=1;
	(mp[1]==0)?dp[1]=1:dp[1]=0;
	forni(i,n){
		(mp[i]==0)?dp[i]=(dp[i-1]+dp[i-2])%inf:dp[i]=0;
	}
	cout<<dp[n]<<"\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""

Measured memory_bytes: 7296
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int w,a,b;
    while(sf("%d %d %d",&w,&a,&b)==3)
    {
        if(b>a)pf("%d\n",max(0,b-(a+w)));
        else pf("%d\n",max(0,a-(b+w)));
    }
    return 0;
}
 









 




























Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 4000000000000000001


int main(){

	string s1,s2;
	cin>>s1>>s2;
	reverse(s2.begin(),s2.end());
	
	if(s1==s2){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    cin >> n >> m;
    vector<vector<int>> graph(n+1);
    for(int i = 0; i<m; i++){
        int x,y,z;
        cin >> x >> y >> z;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    
    vector<int> arrival(n+1);
    for(int i = 0; i<n+1; i++){
        arrival[i] = -1;
    }
    
    int arrivalcounter = 0;
    int counter = 1;
    vector<int> q;
    q.push_back(1);
    int qcounter = 1;
    int temp = 2;
    while(arrivalcounter < n){
        if(qcounter == 0){
            counter += 1;
            while(arrival[temp] != -1){
                temp += 1;
            }
            q.push_back(temp);
            qcounter += 1;
        }
        arrival[q[0]] = 1;
        arrivalcounter += 1;
        
        while(qcounter != 0){
            for(int i = 0;i<graph[q[0]].size(); i++){
                if(arrival[graph[q[0]][i]] == -1){
                    arrival[graph[q[0]][i]] = 1;
                    arrivalcounter += 1;
                    q.push_back(graph[q[0]][i]);
                    qcounter += 1;
                }
            }
            q.erase(q.begin());
            qcounter -= 1;
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 7288
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::string T;
ll ans = 0;

int main()
{
  std::cin >> T;

  rep( i, T.size() ) if( T[i] == '?' ) {
    T[i] = 'D';
  }

  std::cout << T << std::endl;

  return 0;
}

Measured memory_bytes: 3768
// ABC060A - 

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

typedef unsigned long long int ull;
typedef long long int ll;

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

	if ((A[A.size()-1] == B[0])&&(B[B.size()-1] == C[0])) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256