akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int maxn= 1e5+10;
const int mod =1e9+7;
const double EPS = 1e-6;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    int num=0;
    while(n)
    {
        n/=k;
        num++;
    }
    cout << num <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int fun(int );
int fun(int N)
{
    int i;
    for(i=0;;i++)
    {
        if(pow(2,i+1)>N)
        {
            break;
        }
    }
    return pow(2,i);
}
int main()
{
    int N,s;
    scanf("%d",&N);
    s=fun(N);
    printf("%d\n",s);
    return 0;
}


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

int r, s, p;
int y[500000], x[500000];
int dist[500000];

int main() {
    int i;
    
    cin >> r >> s >> p;
    for (i = 0; i < p; i++) {
        cin >> y[i] >> x[i];
    }
    
    for (i = 0; i < p; i++) {
        int distY = r + 1 - y[i];
        int distX;
        if (x[i] <= s) { distX = s + 1 - x[i]; }
        else { distX = x[i] - s; }
        dist[i] = distY + distX;
    }
    sort(dist, dist + p, greater<int>());
    
    int ans = dist[0];
    for (i = 1; i < p; i++) {
        ans = max(ans, dist[i] + i);
    }
    cout << ans << endl;
    return 0;
}


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


int main()
{
	int n;
	cin>>n;
	int rem=n%10;
	if(rem==2||rem==4||rem==5||rem==7||rem==9) cout<<"hon"<<endl;
	else if(rem==0||rem==1||rem==6||rem==8) cout<<"pon"<<endl;
	else cout<<"bon"<<endl;
	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    vector<pair<ll, ll>> itv;
    for(ll i = 0; i < N; ++i) itv.push_back(make_pair(B[i], A[i]));
    sort(itv.begin(), itv.end());
    ll sum = 0;
    bool flag = true;
    for(ll i = 0; i < N; ++i){
        //cout << "first: " << itv[i].first << " second: " << itv[i].second << endl;
        sum += itv[i].second;
        if(sum > itv[i].first){
            flag = false;
            break;
        }
    }
    if(flag) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9584
import sys


class UnionFind:
    def __init__(self, n):
        # total number of nodes.
        self.n = n
        # node id -> root node id
        self._root_table = list(range(n))
        # root node id -> group size
        self._size_table = [1] * n

    def find(self, x):
        """Returns x's root node id."""
        r = self._root_table[x]
        if r != x:
            # Update the cache on query.
            r = self._root_table[x] = self.find(r)
        return r

    def union(self, x, y):
        """Merges two groups."""
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        # Ensure that x is the larger (or equal) group.
        if self._size_table[x] < self._size_table[y]:
            x, y = y, x

        self._size_table[x] += self._size_table[y]
        self._root_table[y] = x

    def size(self, x):
        return self._size_table[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self._root_table) if x == i]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())


input = sys.stdin.readline


def main():
    N = int(input())
    cities, xs, ys = [], [], []
    for i in range(N):
        x, y = map(int, input().split())
        cities.append((x, y))
        xs.append((x, i))
        ys.append((y, i))
    xs.sort()
    ys.sort()
    xd, yd = [], []
    for i in range(1, N):
        x1, c1 = xs[i - 1]
        x2, c2 = xs[i]
        if x2 - x1 <= abs(cities[c1][1] - cities[c2][1]):
            xd.append((x2 - x1, c1, c2))
        y1, c1 = ys[i - 1]
        y2, c2 = ys[i]
        if y2 - y1 < abs(cities[c1][0] - cities[c2][0]):
            xd.append((y2 - y1, c1, c2))
    xd.sort()

    uf = UnionFind(N)
    cost = 0
    merged_cnt = 0
    for d1, c1, c2 in xd:
        if not uf.same(c1, c2):
            uf.union(c1, c2)
            cost += d1
            merged_cnt += 1
            if merged_cnt == N - 1:
                break
    print(cost)


if __name__ == "__main__":
    main()


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF 1000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007

using namespace std;

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pwi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector< vector<pair<int,lli > > > wGraph;
//typedef vector<vector<int> > graph;
typedef vector<vector<lli> > matrix;

vi vals;
matrix chest(MAXN);
int n,m;
//int dp[10000][1<<13];

/*int knap(int i,int bitmask){

	if(i>=m){
		if(bitmask == 0){
			return -1000000;
		}else{
			return INT_MAX-1;
		}
	}

	if(dp[i][bitmask] != INT_MAX) return dp[i][bitmask];

	bool did = false;
	for(int k = 0;k<chest[i].size();++k){
		if(bitmask&(1<<chest[i][k])){
			did = true;
			bitmask-=(1<<chest[i][k]);
		}
	}

}*/

bool isValid(int bitmask,int ch){

	for(int i = 0;i<chest[ch].size();++i){
		if(!(bitmask&(1<<chest[ch][i]))){
			return true;
		}
	}

	return false;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(10);

 	cin>>n>>m;
 	
 	set<int> valid;
 	for(int i = 1;i<=n;++i){
 		valid.insert(i);
 	}

 	for(int i = 0;i<m;++i){
 		int v;
 		cin>>v;
 		vals.pb(v);

 		int qtd;
 		cin>>qtd;
 		for(int j = 0;j<qtd;++j){
 			int k;
 			cin>>k;
 			valid.erase(k);
 			chest[i].pb(k-1);
 		}

 	}
 	
 	if(valid.size() > 0){
 		cout<<-1<<endl;
 		return 0;
 	}

 	vi dp(1<<(n+1),INT_MAX);

 	for(int i = (1<<n)-1;i>=0;--i){

 		for(int k = 0;k<m;++k){

 			if(isValid(i,k)){

 				int actual = i;
 				for(int p = 0;p<chest[k].size();++p){
 					if(!(actual&(1<<chest[k][p]))){
 						actual|=(1<<chest[k][p]);
 					}
 				}

 				if(dp[actual] == INT_MAX){
	 				dp[i] = min(dp[i],vals[k]);
	 			}else{
	 				dp[i] = min(dp[i],dp[actual]+vals[k]);
	 			}
 			}

 		}

 	}
 	
 	cout<<dp[0]<<endl;

    return 0;

}


Measured memory_bytes: 234880
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

x = [0] * N
c = 0

for i in range(N):
    if A[i] < 0:
        c += 1
    x[i] = abs(A[i])

ans = sum(x)
if c % 2 == 1:
    ans -= min(x) * 2

print(ans)


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

int main() {
  
  string s;
  cin >> s;
  
  if(s.at(0) != s.at(1) && s.at(1) != s.at(2) && s.at(2) != s.at(3)){
    cout << "Good" << endl;
  }
  else cout << "Bad" << endl;  
   
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
bool point[100][100];

int main()
{
	int num,n1,n2,n3;
	cin >> num;
	for (int i = 0; i < num; i++) {
		cin >> n1 >> n2;
		for (int k = 0; k < n2; k++) {
			cin >> n3;
			point[n1 - 1][n3 - 1] = 1;
		}
	}
	for (int i = 0; i < num; i++) {
		for (int k = 0; k < num; k++) {
			if (k) { cout <<" "; }
			cout << point[i][k];
		}
		cout << endl;
	}
	
}


Measured memory_bytes: 3084
#include <stdio.h>
#define N 8
#define N2 2*N-1
#define FREE -1
#define NOT_FREE 1

int row[N],col[N];
int dpos[N2],dneg[N2];
int B[N][N]={};

void PrintBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(B[i][j]){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
	printf("Q");
      }else printf(".");
    }
    puts("");
  }
}

void Putqueen(int i){
  int j;
  if(i==N){
    PrintBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    Putqueen(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}

int main(){
  int i,j,k,r,c;
  for(i=0;i<N2;i++){
    if(i<N){
      row[i]=col[i]=FREE;
    }
    dpos[i]=dneg[i]=FREE;
  }
  
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    B[r][c]=NOT_FREE;
  }
  Putqueen(0);
  return 0;
}



Measured memory_bytes: 2108
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10**5+100)]
ans = 1
mx = -1
for i in d:
    lis[i] += 1
    if i > mx:
        mx = i
if lis[0] != 1 or d[0] != 0:
    print(0)
else:
    for i in range(1, mx+1):
        ans *= lis[i-1]**lis[i]
    print(ans%998244353)


Measured memory_bytes: 14020
#include <stdio.h>

int gcd(a, b){
  if(a == 0 || b == 0) return a + b;
  if(b > a) return gcd(b, a);
  return gcd(b, a % b);
}

void init(int *seg, int k){
  while(k > 0){
    for(int j = 0; j < k / 2; j++){
      seg[(k - 1 + 2 * j) / 2] = gcd(seg[k - 1 + 2 * j], seg[k + 2 * j]);
    }
    k /= 2;
  }
  return;
}

void update(int i, int x, int *seg, int k){
  i = k - 1 + i;
  seg[i] = x;
  while(k > 0){
    seg[(i - 1) / 2] = gcd(seg[2*((i - 1)/2) + 1], seg[2*((i - 1)/2) + 2]);
    i = (i - 1) / 2;
    k /= 2;
  }
  return;
}

int
main(int artc, char *argv[])
{
  int n;
  scanf("%d", &n);
  int k = 1;
  while(n > k) k *= 2;
  int seg[500000] = {};
  for(int i = 0; i < n; i++){
    scanf("%d", &seg[k - 1 + i]);
  }

  init(seg, k);
  

  int ans = 0; int temp;
  for(int i = 0; i < n; i++){
    temp = seg[k - 1 + i];
    update(i, 0, seg, k);
    ans = (ans > seg[0] ? ans : seg[0]);
    update(i, temp, seg, k);
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 998244353;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;
    
    vector<tuple<string, ll, ll>> tup;
    rep(i, n) {
        string s;
        ll p;
        cin >> s >> p;
        tup.emplace_back(s, -p, i+1);
    }
    sort(all(tup));

    for(auto x : tup) {
        out(get<2>(x));
    }

    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj, ti, tj;
  cin >> si >> sj >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vvi dist(h, vi(w, INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si, sj);
  while (!q.empty()) {
    int i = q.front().first, j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    rep(v, 4) {
      int ni = i + di[v], nj = j + dj[v];
      if (ni<0||nj<0||ni>=h||nj>=w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni, nj);
    }
    for (int ei = -2; ei <= 2; ei++) {
      for (int ej = -2; ej <= 2; ej++) {
        int ni = i + ei, nj = j + ej;
        if (ni<0||nj<0||ni>=h||nj>=w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni, nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 9528
//created by pyoxiao on 2020/05/02
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
LL A, B, N;
void solve() {
    scanf("%lld %lld %lld", &A, &B, &N);
    LL x = min(B - 1, N);
    printf("%lld\n", A * x / B);
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 3824
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int a; std::string s; std::cin >> a >> s;
  if(a < 3200) s = "red";
  fin(s);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define for(i,a,b) for(int i=a;i<(signed)b;i++)

using namespace std;
int dp[100005][3]={0};
signed main(){
    int n,k;
    cin>>n;
    int a[n],b[n],c[n];
    for(i,0,n){
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    for(i,1,n){
        for(j,0,3){
            if(j==0)
                dp[i][j] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
            if(j==1)
                dp[i][j] = max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
            if(j==2)
                dp[i][j] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
            
        }
    }
    // for(i,0,n){
    //     cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2];
    // }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

template<class V, int ME> class BIT {
public:
    V bit[1<<ME];
    V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
    void add(int e, V val) {e++; while(e<=1<<ME) bit[e-1]+=val,e+=e&-e;}
};

int main(){
	ll N, K;
	cin >> N >> K;
	vector<ll> a(N);
	REP(i, N) cin >> a[i];
	REP(i, N) a[i] -= K;

	vector<ll> b(N+1, 0);
	REP(i, N) b[i+1] = b[i] + a[i];

	vector<ll> aa(N+1);
	REP(i, N+1) aa[i] = b[i];

	sort(aa.begin(), aa.end());
	aa.erase(unique(aa.begin(), aa.end()), aa.end());
	map<ll, ll> mp;
	REP(i, aa.size()){
		mp[aa[i]] = i;
	}

	vector<ll> bb(N+1);
	REP(i, N+1) bb[i] = mp[b[i]];


	BIT<ll, 20> bit;
	REP(i, 1<<20) bit.bit[i] = 0;
	bit.add(bb[0], 1);
	ll res = 0;
	REP(i, N){
		res += (bit.total((1<<19)-1) - bit.total(bb[i+1]));
		bit.add(bb[i+1], 1);
	}
	cout << N*(N+1)/2 - res << endl;
    return 0;
}

Measured memory_bytes: 27136
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n' 

int n;
vector<int> adj[201];
int vis[201];
int st=1;
void dfs(int no,int col=1){
	vis[no]=col;
	for(auto j:adj[no]){
		if(vis[j]==0){
			dfs(j,3-col);
		}
		else{
			if(vis[j]==vis[no]){
				st=0;
			}
		}
	}
}
int vis2[201];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			char s;
			cin>>s;
			if(s=='1'){
				adj[i].pb(j);
			}
		}
	}
	dfs(0);
	if(st==0){
		cout<<-1<<endl;
		return 0;
	}
	int ans=0;
	for(int i=0;i<n;i++){
		vector<vector<int>> cur;
		cur.pb({i});
		for(int j=0;j<n;j++){
			vis2[j]=0;
		}
		vis2[i]=1;
		while(true){
			vector<int> kk;
			for(auto j:cur.back()){
				for(auto k:adj[j]){
					if(vis2[k]==0){
						vis2[k]=1;
						kk.pb(k);
					}
				}
			}
			if(kk.size()==0){
				break;
			}
			cur.pb(kk);
		}
		ans=max(ans,(int)cur.size());
	}
	cout<<ans<<endl;



	return 0;
}

Measured memory_bytes: 3824
n = int(input())
s = [input() for _ in range(n)]

a = [0]*5
for i in range(n):
    if s[i][0]=="M":
        a[0] += 1
    elif s[i][0]=="A":
        a[1] += 1
    elif s[i][0]=="R":
        a[2] += 1
    elif s[i][0]=="C":
        a[3] += 1
    elif s[i][0]=="H":
        a[4] += 1
        
S=0
for k in range(5):
    for l in range(k+1, 5):
        for m in range(l+1, 5):
            S += a[k]*a[l]*a[m]
            
print(S)

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

int main() {
  int n;
  cin >> n;
  vector<P> ab(n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    ab[i] = P(a, b);
  }

  sort(ab.begin(), ab.end());
  int ans = ab[0].first;
  for (int i = 1; i < n; ++i) {
    ans++;
    int order_diff = ab[i].first - ab[i - 1].first - 1;
    int value_diff = ab[i - 1].second - ab[i].second - 1;
    ans += min(order_diff, value_diff);
  }
  ans += ab.back().second;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main()
{
	ll n,w;
	cin>>n>>w;
	ll wt[n]={0},val[n]={0};
	for(ll i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
	}
	ll wt1[n]={0};
	wt1[0]=wt[0];
	for(ll i=1;i<=n;i++)
	{
		wt1[i]+=wt[i-1];
	}
	ll dp[n+1][w+1];
	ll currwt=0;
	
	for(ll i=0;i<=n;i++)
	{   
	    for(ll w1=0;w1<=w;w1++)
		{
		if(i==0 || w1==0)
		dp[i][w1]=0;
		else if(wt[i-1]<=w1)
		{
			dp[i][w1]=max(val[i-1]+dp[i-1][w1-wt[i-1]],dp[i-1][w1]);
		}
		else if(wt[i-1]>w1 && i*w1>0)
		dp[i][w1]=dp[i-1][w1];
	    }
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define f first
#define s second 
#define mp make_pair
#define inf 1<<30
using namespace std;

int main()
{
  int N,M,L,a,b,c,d;
  int dis[101][101],th[101][101];
  int dp[101][101];

  while(1){
    cin>>N>>M>>L;
    if(N+M+L==0)break;
    for(int i=0;i<101;i++){
      for(int j=0;j<101;j++){
	dis[i][j]=th[i][j]=dp[i][j]=inf;
      }
    }
    for(int i=0;i<M;i++){
      cin>>a>>b>>c>>d;
      a--;b--;
      dis[a][b]=c;
      dis[b][a]=c;
      th[a][b]=d;
      th[b][a]=d;
    }
    int ans=inf;
    dp[0][L]=0;
    priority_queue<pair<int,pair<int,int> > > pq;
    pq.push(mp(0,mp(0,L)));
    while(!pq.empty()){
      pair<int,pair<int,int> > u=pq.top();
      pq.pop();
      u.f=(-1)*u.f;
      if(dp[u.s.f][u.s.s]<u.f)continue;
      if(u.s.f==N-1){
	ans=u.f;
	break;
      }
      
      for(int i=0;i<N;i++){
	if(dis[u.s.f][i]==inf)continue;
	int c=u.s.s-dis[u.s.f][i];
	if(0<=c){
	  if(u.f<dp[i][c]){
	    dp[i][c]=u.f;
	    pq.push(mp(u.f*(-1),mp(i,c)));
	  }
	}
	if(u.f+th[u.s.f][i]<dp[i][u.s.s]){
	  dp[i][u.s.s]=u.f+th[u.s.f][i];
	  pq.push(mp((u.f+th[u.s.f][i])*(-1),mp(i,u.s.s)));
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1444
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
typedef long long LL;
//#define int long long

//booooooooooooost
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)
*/


signed main() {

	int a, b, c;

	cin >> a >> b >> c;

	if ((a == 5 && b == 7 && c == 5) || (a == 7 && b == 5 && c == 5) || (a == 5 && b == 5 && c == 7)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	std::ios::sync_with_stdio(false);
	ll l,r;
	cin>>l>>r;
	if(r/2019-l/2019!=0)cout<<0;
	else
	{
		ll ans=2020;
		for(ll i=l;i<r;i++)
		{
			for(ll j=i+1;j<=r;j++)
			{
				ans=min((i*j)%2019,ans);
			}
		}
		cout<<ans;
	}
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define M 100000
typedef struct PT{
    char name[11];
    int time;
} PT;
PT a[M+1];
int head=0,tail=0;
void Init()
{
    head=tail=0;
}
bool IsFull()
{
    return tail-head==-1||tail-head==M;
}
bool IsEmpty()
{
    return head==tail;
}
PT dequeue()
{
    if(IsEmpty())
    {
        cout<<"EMPTY"<<endl;
        exit(1);
    }
    if(head==M)
    {
        head=0;
        return a[M];
    }
    ++head;
    return a[head-1];
}
void enqueue(PT x)
{
    if(IsFull())
    {
        cout<<"FULL"<<endl;
        exit(1);
    }
    a[tail]=x;
    ++tail;
    if(tail==M+1)
        tail=0;
}
int main()
{
    PT in;
    int i,n,q,time=0;
    cin>>n>>q;
    for(i=0;i<n;i++)
    {
        //cin>>in.name>>in.time;
        scanf("%s%d",in.name,&in.time);
        enqueue(in);
    }
    while(!IsEmpty())
    {
        in = dequeue();
        if(in.time<=q)
        {
            time+=in.time;
            //cout<<in.name<<' '<<time<<endl;
            printf("%s %d\n",in.name,time);
        }
        else
        {
            time+=q;
            in.time-=q;
            enqueue(in);
        }
    }
    return 0;
}

Measured memory_bytes: 4684
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "p", long, "dist");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, k;
    scan(n, k);
    long cnt;
    foreach (b; iota(k + 1, n + 1))
    {
        auto p = n / b;
        cnt += max(p * (b - k), 0);
        cnt += max(0, n - p * b - k + 1);
    }
    if (k == 0)
        cnt -= n;
    cnt.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
const ll INF = 1e9 + 10 ;
const ll N = 110 ; 
int main(){
    fastio
    ll n , k , q ; 
    cin >> n >> k >> q ;
    vector<ll> cnt(n+2);
    for(ll i = 0; i < q; i++){
        ll a ;
        cin >> a ;
        cnt[1] += -1 ;
        cnt[a] -= -1 ;
        cnt[a + 1] += -1;
        cnt[n+1] -= -1;
    }
    for(ll i = 1; i <= n; i++){
        cnt[i] += cnt[i - 1] ;
    }
    for(ll i = 1; i <= n; i++){
        cnt[i] += k ;
    }
    for(ll i = 1; i <= n; i++){
        if ( cnt[i] <= 0 ){
            cout << "No" << endl;
        }
        else cout << "Yes" << endl;
    }
    return 0 ;
}






Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

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


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

using namespace std;

int main() {
	int n;
	cin >> n;
	int i;
	long long int sum = 0;
	for (i = 0; i < n; i++) {
		int a;
		cin >> a;
		sum += a - 1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(200002)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
x = [None] * (N)

def dfs(s):
    global x, G
    for t, d in G[s]:
        if x[t] is None:
            x[t] = x[s] + d
            if not dfs(t):
                return False
        else:
            if x[t] != x[s] + d:
                return False
    return True

for _ in range(M):
    L, R, D = map(int, input().split())
    G[L-1].append([R-1,  D])
    G[R-1].append([L-1, -D])

ans = True
for i in range(N):
    if x[i] is None:
        x[i] = 0
        ans &= dfs(i)

print("Yes" if ans else "No")

Measured memory_bytes: 135144
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

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

	map<string, ll> m;

	for (int i = 0; i < n; i++)
	{
		string temp;
		cin >> temp;
		
		m[temp] += 1;
	}

	ll maxx = 0;
	for (auto x: m)
	{
		maxx = max(x.second, maxx);
		
	}

	for (auto x : m)
	{
		if (x.second == maxx) cout << x.first << endl;
	}

	//cout << minAns << endl;

}


Measured memory_bytes: 25216
#include <cstdio>
#include <cstring>

int main()
{
	int m;
	while (scanf("%d", &m), m)
	{
		int a[7], b[7];
		for (int i = 0; i < m; ++i)
			scanf("%d %d", a+i, b+i);

		int combi[1001];
		memset(combi, 0, sizeof(combi));
		combi[0] = 1;
		for (int i = 0; i < m; ++i)
		{
			int c[1001];
			memset(c, 0, sizeof(c));
			for (int j = 1; j <= b[i]; ++j)
				for (int k = 1000 - j*a[i]; k >= 0; --k)
					if (combi[k])
						c[k + j*a[i]] += combi[k];
			for (int i = 0; i < 1001; ++i)
				combi[i] += c[i];
		}
		int g;
		scanf("%d", &g);
		while (g--)
		{
			int n;
			scanf("%d", &n);
			printf("%d\n", combi[n]);
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	cin >> N;
	std::vector<int> l(N);
	for(int i = 0; i < N; i++){
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	int sum = 0;
	for (int i = 0; i < N-1; ++i)
	{
		sum += l[i];
	}
	if(sum > l[N-1]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define tm1 first.first
#define tm2 first.second
#define tm3 second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll>tri;

const int N=4e5+20;
const ll inf=1e16;
ll mm[N],ans[N];
vector<tri>vec;
ll LS[N],LT[N],RS[N],RT[N];

int main(){	
	fastio;
	int s,t,q;cin>>s>>t>>q;
	vec.pb({{-inf,1},-1});
	vec.pb({{-inf,2},-1});
	vec.pb({{inf,1},-1});
	vec.pb({{inf,1},-1});
	vec.pb({{inf,2},-1});
	FER(i,0,s){
		ll k;cin>>k;
		vec.pb({{k,1},-1});
	}
	FER(i,0,t){
		ll k;cin>>k;
		vec.pb({{k,2},-1});
	}
	FER(i,0,q){
		ll k;cin>>k;
		vec.pb({{k,3},i});
	}
	sort(all(vec));
	ii esta={-2*inf,-2*inf};
	FER(i,0,sz(vec)){
		LS[i]=esta.ff;
		LT[i]=esta.ss;
		if(vec[i].tm2==1)esta.ff=LS[i]=vec[i].tm1;
		if(vec[i].tm2==2)esta.ss=LT[i]=vec[i].tm1;
	}
	esta={inf,inf};
	IFR(i,sz(vec)-1,0){
		RS[i]=esta.ff;
		RT[i]=esta.ss;
		if(vec[i].tm2==1)esta.ff=RS[i]=vec[i].tm1;
		if(vec[i].tm2==2)esta.ss=RT[i]=vec[i].tm1;
	}
	FER(i,2,sz(vec)-2)if(vec[i].tm3!=-1){
		LS[i]=abs(LS[i]-vec[i].tm1);
		LT[i]=abs(LT[i]-vec[i].tm1);
		RS[i]=abs(RS[i]-vec[i].tm1);
		RT[i]=abs(RT[i]-vec[i].tm1);
		ll val=min(max(LS[i],LT[i]),max(RS[i],RT[i]));
		val=min(val,2*LT[i]+RS[i]);
		val=min(val,2*RS[i]+LT[i]);
		val=min(val,2*LS[i]+RT[i]);
		val=min(val,2*RT[i]+LS[i]);
		ans[vec[i].tm3]=val;
	}
	FER(i,0,q)cout<<ans[i]<<endl;

	return 0;
}


Measured memory_bytes: 24808
n,m,k = map(int,input().split())
ans = 0
mod = 10**9+7
max = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, max + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
C = cmb(m*n-2,k-2,mod)
for i in range(1,n):
    ans += (i*(n-i)*(m**2))*C
for i in range(1,m):
    ans += (i*(m-i)*(n**2))*C
print(ans%mod)

Measured memory_bytes: 27040
#include<stdio.h>
#include<math.h>

int main()
{
	int num, record[2][100000], i, j, check;
	long long ans= 1;

	scanf("%d", &num);
	for(i= 0; i< 2; i++)
	{
		for(j= 0; j< num; j++)
			scanf("%d", &record[i][j]);
	}

	check= record[0][num- 1];
	for(i= 0; i< num; i++)
	{
		if(check== record[0][i] && check== record[1][i])
		{
			check= 0;
			break;
		}
	}

	if(check || record[0][num- 1]- record[1][0])
	{
		printf("0\n");
		return 0;
	}

	for(i= 1; i< num- 1; i++)
	{
		if(record[0][i]== record[0][i- 1] && record[1][i]== record[1][i+ 1])
		{
			if(record[0][i]> record[1][i])
				ans*= record[1][i];
			else
				ans*= record[0][i];
		}
			ans%= (long long)(pow(10, 9)+ 7);
	}

	printf("%lld\n", ans% (long long)(pow(10, 9)+ 7));

	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>

using namespace std;

int main()
{
  int H, N;
  cin >> H >> N;


  for (int i = 0; i < N; ++i)
  {
    int A;
    cin >> A;
    H -= A;
  }
  if (H <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
a, b,c = map(int, input().split())
y = list( map(int, input().split()))
ans=0
for i in range(a):
    x = list( map(int, input().split()))
    s = 0
    for m,n in zip(y,x):
        s+=m*n
    if s+c>0:ans+=1

print(ans)

Measured memory_bytes: 3060
A, B, K = map(int, input().split())

ret = set()
for i in range(A, A + K):
    if i <=B:
        ret.add(i)

for j in range(B - K + 1, B + 1):
    if j >= A:
        ret.add(j)

for n in sorted(list(ret)):
    print(n)


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int n,i,j,s,m,a[10];
    for(i=0;i<10;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<3;i++)
    {
        m=0;
        for(j=0;j<10;j++)
        {
            if(a[j]>m)
            {
                m=a[j];
                s=j;
            }
        }
        printf("%d\n",m);
        a[s]=0;
    }
    return 0;
}

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

int n;
vs a;

ll dfs(int id,int d){
	if(isdigit(a[id][d])) return a[id][d]-'0';
	char c=a[id][d];
	ll x=(c=='+'?0:1);
	for(int i=id+1;i<n&&d<a[i].size()&&a[i][d]=='.';i++) if(d+1<a[i].size()&&a[i][d+1]!='.'){
		ll y=dfs(i,d+1);
		if(c=='+') x+=y;
		else x*=y;
	}
	return x;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		cin>>n;
		if(n==0) break;
		a=vs(n);
		for(int i=0;i<n;i++) cin>>a[i];
		cout<<dfs(0,0)<<endl;
	}
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1e5+5;
int a[N],nxt[65][N];
ll id[N];
int main(){
	int n=read();
	For(i,1,n) a[i]=read(),id[i]=i;
	int m=read();ll k=read();
	For(i,1,m){
		int x=read();
		swap(id[x],id[x+1]);
	}
	For(i,1,n) nxt[0][i]=id[i];
	For(i,1,63){
		For(j,1,n) nxt[i][j]=nxt[i-1][nxt[i-1][j]];
	}
	For(i,1,n){
		id[i]=i;
		Rep(j,63,0) if(k>>j&1) id[i]=nxt[j][id[i]];
		id[i]=a[id[i]]-a[id[i]-1];
	}
	For(i,1,n){
		id[i]+=id[i-1];
		printf("%lld.0\n",id[i]);
	}
}

Measured memory_bytes: 29744
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________


	int n;
	cin >> n;
	int a[n];
	map<int, int>m;
	vi v;
	zip(i, 0, n)
	{
		cin >> a[i];
		m[a[i]]++;
		// if(m[a[i]]==4)
		// 	v.pb(a[i]),v.pb(a[i]);
		if (m[a[i]] == 2)
			v.pb(a[i]), m[a[i]] -= 2;
	}

	sort(all(v), greater<int>());
	if (v.size() >= 2)
	{
		cout << v[0]*v[1] << en;
	}
	else
	{
		cout << 0 << en;
	}


	return 0;
}



Measured memory_bytes: 10512
N = list(input())
N0 = int(N[len(N)-1])

if N0 == 2 or N0 == 4 or N0 == 5 or N0 == 7 or N0 == 9:
    print('hon')
elif N0 == 0 or N0 == 1 or N0 == 6 or N0 == 8:
    print('pon')
else:
    print('bon')

Measured memory_bytes: 9132
Q, H, S, D = map(int, input().split())
N = int(input())
Q_S, H_S, D_S = Q*4, H*2, D/2

if min(Q_S,H_S,S,D_S) == Q_S:
    print(Q_S*N)
elif min(Q_S,H_S,S,D_S) == H_S:
    print(H_S*N)
elif min(Q_S,H_S,S,D_S) == S:
    print(S*N)
else:
     if min(Q_S,H_S,S) == Q_S:
         print(D*(N//2)+Q_S*(N%2))
     elif min(Q_S,H_S,S) == H_S:
         print(D*(N//2)+H_S*(N%2))
     elif min(Q_S,H_S,S) == S:
         print(D*(N//2)+S*(N%2))


Measured memory_bytes: 3064
S = set(map(str, (input())))
s = list(S)
s.sort()
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range(len(s)):
    alphabet.remove(s[i])

if alphabet == []:
    print('None')
else:
    print(alphabet[0])

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

const int MOD = 1000000007;
class mint {
    using int64 = long long;
private:
    int64 x;
public:
    mint(const int64 x1=0) { x = x1%MOD; };

    mint& operator++(int n) { x+=1; return *this; };
    mint& operator--(int n) { x-=1; return *this; };
    mint& operator=(int64 n) { x=n%MOD; return *this; };
    mint& operator--() {x-=1; return *this; };
    mint& operator+=(const mint a) { if ( (x+=a.x) >= MOD) x-=MOD; return *this; }
    mint& operator-=(const mint a) { if ( (x+= MOD-a.x) >= MOD) x-= MOD; return *this; }
    mint& operator*=(const mint a) { (x*=a.x) %= MOD; return *this; }
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
    mint inv() const { return pow(MOD-2);}
    friend ostream& operator<<(ostream &os, const mint a) noexcept { return os << a.x; }
    constexpr bool operator == (const mint& r) const noexcept { return this->x == r.x; }
    constexpr bool operator != (const mint& r) const noexcept { return this->x != r.x; }
    mint pow(long long t) const {
        if (!t) return mint(1);
        mint a = pow(t>>1);
        a*=a;
        if(t&1) a*= *this;
        return a;
    }
};

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

    vector dp(4, vector<mint> (n+1, 0));
    dp[0][0] = 1;
    for (int i=1; i<=n; i++) {
        dp[0][i] = dp[0][i-1] * 8;
        dp[1][i] = dp[0][i-1] + dp[1][i-1] * 9;
        dp[2][i] = dp[0][i-1] + dp[2][i-1] * 9;
        dp[3][i] = dp[1][i-1] + dp[2][i-1] + dp[3][i-1] * 10;
    }
//    debug(dp[0]);
//    debug(dp[1]);
//    debug(dp[2]);
//    debug(dp[3]);

//    debug(dp[0][n] + dp[1][n] + dp[2][n] + dp[3][n]);
    cout << dp[3][n] << endl;
}

Measured memory_bytes: 41716
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const double PI=3.14159265358979323846;

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

int main()
{
	for(;;){
		int H, W;
		cin >> H >> W;

		if(H == 0 && W == 0)
			break;

		REP(j, H){
			if(j == 0 || j == H-1){
				REP(i, W){
					cout << "#";
				}
			}
			else{
				cout << "#";

				REP(i, W-2){
					cout << ".";
				}

				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}




Measured memory_bytes: 3060
const gInput = require('fs').readFileSync('/dev/stdin', 'utf8')
const input = gInput.split('\n').map( line => line.split(' ').map( s => parseInt(s)))

for(let nums of input){
    const [a,b] = nums.sort((x,y)=> x-y)
    if( a ===  0 && b === 0 ){ break }
    console.log(`${a} ${b}`)
}




Measured memory_bytes: 20424
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
typedef long long ll;
using namespace std;
ll h,w;
int main(int argc,char const* argv[])
{
  ll s1,s2,s3,s2w,s2h,maxs,mins;
  ll inf=1000000000000000;
  ll ans=inf,tmp;
  cin >> h >> w;
  for(int i=0;i<h;i++)
    {
      s1=i*w;
      s2h=(h-i)/2;
      s2=s2h*w;
      s3=(h-i-s2h)*w;
      tmp=max(s1,s2);
      maxs=max(tmp,s3);
      tmp=min(s1,s2);
      mins=min(tmp,s3);
      if((maxs-mins)<ans) ans=(maxs-mins);
      s2w=w/2;
      s2=(h-i)*s2w;
      s3=(h-i)*(w-s2w);
      tmp=max(s1,s2);
      maxs=max(tmp,s3);
      tmp=min(s1,s2);
      mins=min(tmp,s3);
      if((maxs-mins)<ans) ans=(maxs-mins);
    }

  for(int j=0;j<w;j++)
    {
      s1=j*h;
      s2w=(w-j)/2;
      s2=h*s2w;
      s3=h*(w-j-s2w);
      tmp=max(s1,s2);
      maxs=max(tmp,s3);
      tmp=min(s1,s2);
      mins=min(tmp,s3);
      if((maxs-mins)<ans) ans=(maxs-mins);
      s2h=h/2;
      s2=s2h*(w-j);
      s3=(h-s2h)*(w-j);
      tmp=max(s1,s2);
      maxs=max(tmp,s3);
      tmp=min(s1,s2);
      mins=min(tmp,s3);
      if((maxs-mins)<ans) ans=(maxs-mins);
    }
  
  cout << ans << endl;
  return 0;
}


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

int main() {
	int N, P[100], i, j, ind[100];
	char S[100][11];
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%s %d", S[i], &P[i]);
		for (j = i; j > 0; j--) {
			if (strcmp(S[ind[j - 1]], S[i]) > 0 || strcmp(S[ind[ j - 1 ]], S[i]) == 0 && P[ind[j - 1]] < P[i]) {
				ind[j] = ind[j - 1];
			}
			else {
				break;
			}
		}
		ind[j] = i;
	}
	for (i = 0; i < N; i++) {
		printf("%d\n", ind[i] + 1);
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
steps = list(map(int, input().split(" ")))

costs = [None] * N
costs[0] = 0
costs[1] = abs(steps[1] - steps[0])

for i in range(2, N):
    cost1 = costs[i-1] + abs(steps[i-1] - steps[i])
    cost2 = costs[i-2] + abs(steps[i-2] - steps[i])
    costs[i] = min(cost1, cost2)

print(costs[N-1])


Measured memory_bytes: 13928
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  cout<<fixed<<setprecision(10);
  int A,B,C;
  cin >> A >> B >> C;
  if(A+B+C>21) cout << "bust" << endl;
  else cout << "win" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int f = 1;
	string s;
	getline(cin,s);
	if(s[0]!='A') {
		cout<<"WA";
		return 0; 
	}
	for(int i=0;i<s.size();i++) {
		if(i==0)
			continue;
		if(s[i]=='C' && i>=2 && i!=s.size()-1 && f==1) {
			f = 2;
			continue;
		}
		if(s[i]>='A' && s[i]<='Z') {
			cout<<"WA";
			return 0;
		}
	}
	if(f!=1)
		cout<<"AC";
	else
		cout<<"WA";
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

struct Point {
    int x,y;
    Point(int x_=0, int y_=0) :
        x(x_), y(y_) {}
};
bool Peq(struct Point a, struct Point b) {
   return a.x == b.x && a.y == b.y;
}

// h,wおよびマップ情報を1-indexedで読み込む
// st,glを設定する
// pathにはどこから来たかが記載される．
ll h,w;
ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
char Maze[100][100];
ll flg[100][100];
Point path[100][100];
Point st,gl;
bool solve_Maze(){
  queue<Point> q;
  Point now;
  flg[st.x][st.y]=1;
  q.push(st);
  bool goal_flg=false;
  while(!q.empty()){
    now=q.front();q.pop();
    if(Peq(now,gl)){
      goal_flg=true;
      break;
    }
    rep(i,4){
      if(flg[now.x+dx[i]][now.y+dy[i]]==0&&Maze[now.x+dx[i]][now.y+dy[i]]=='.'){
        flg[now.x+dx[i]][now.y+dy[i]]=1;
        q.push(Point(now.x+dx[i],now.y+dy[i]));
        path[now.x+dx[i]][now.y+dy[i]]=now;
      }
    }
  }
  return goal_flg;
}

void show_path(){
  Maze[h][w]='X';
  Point now=gl,next;
  while(!(now.x==st.x&&now.y==st.y)){
    next=path[now.x][now.y];
    Maze[next.x][next.y]='X';
    now=next;
  }
}

int main(){
  cin>>h>>w;
  rep(i,h){
    rep(j,w){
      cin>>Maze[i+1][j+1];
    }
  }
  st=Point(1,1);
  gl=Point(h,w);

  if(solve_Maze()){
    show_path();
    ll ans=0;
    FOR(i,1,h+1){
      FOR(j,1,w+1){
        if(Maze[i][j]=='.'){
          ans++;
        }
      }
    }
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;

}

Measured memory_bytes: 384