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

/*                        [Template]                        */
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define Int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) x.find( y ) != x.end()
#define _matrix(T) vector<vector<T>>
template<class T>
auto matrix( int r, int c, T v ){
	return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
int mod = (int)1e9 + 7 ;
const int inf = (int)1e9 ;
/************************************************************/

int X[] = { 1, -1, 0, 0 } ;
int Y[] = { 0, 0, -1, 1 } ;
bool inside( int x, int y, int &H, int &W ) {
	return ( x >= 1 && x <= H && y >= 1 && y <= W ) ;
}

signed main(){
	int H, W ; cin >> H >> W ;
	int sx, sy ; cin >> sx >> sy ;
	int dx, dy ; cin >> dx >> dy ;
	let grid = matrix<char>( H + 1, W + 1, '.' ) ;
	for( int i = 1 ; i <= H ; i++ ){
		for( int j = 1 ; j <= W ; j++ ){
			cin >> grid[i][j] ;
		}
	}

	let dist = matrix<int>( H + 1, W + 1, inf ) ;
	dist[sx][sy] = 0 ;
	deque<pair<int,int>> q ;
	q.push_front( { sx, sy } ) ;
	int nx, ny ;
	while( !q.empty() ) {
		let cur = q.front() ;
		q.pop_front() ;
		for( int i = 0 ; i < 4 ; i++ ) {
			nx = cur.first + X[i], ny = cur.second + Y[i] ;
			if( inside( nx, ny, H, W ) && grid[nx][ny] != '#' ){
				if( dist[nx][ny] > dist[cur.first][cur.second] ){
					dist[nx][ny] = dist[cur.first][cur.second] ;
					q.push_front( { nx, ny } ) ;
				}
			}
		}
		for( int i = -2 ; i <= 2 ; i++ ){
			for( int j = -2 ; j <= 2 ; j++ ){
				nx = cur.first + i, ny = cur.second + j ;
				if( inside( nx, ny, H, W ) && grid[nx][ny] != '#' ){
					if( dist[nx][ny] > dist[cur.first][cur.second] + 1 ){
						dist[nx][ny] = dist[cur.first][cur.second] + 1 ;
						q.push_back( { nx, ny } ) ;					
					}
				}
			}
		}
	}	 
	if( dist[dx][dy] == inf ) cout << -1 ;
	else cout << dist[dx][dy] ;
	return 0 ;
}

Measured memory_bytes: 8624
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
using namespace std;

int main()
{
	int  H, W;
	cin >> H >> W;
	int h, w;
	cin >> h >> w;

	cout << H * W - (h * W + w * H - w * h) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, k;
  cin >> n >> k;
  vector<ll> h(n);
  REP(i, n) cin >> h[i];
  vector<ll> dp(n, INF);
  dp[0] = 0;
  REP(i, n){
    REP(j, k){
      if(i+j+1 >= n) break;
      chmin(dp[i+j+1], dp[i]+abs(h[i+j+1]-h[i]));
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 4836
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int x, y;
int a[10] = {1, 3, 5, 7, 8, 10, 12};
int b[10] = {4, 6, 9, 11};

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	scanf("%d%d", &x, &y);
	if(x == 2){
		if(y == 2){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
		return 0;
	}
	int cnt = 0;
	for(int i = 0; i < 4; ++i){
		if(b[i] == x)
			cnt++;
		if(b[i] == y)
			cnt++;
	}
	if(cnt == 2){
		printf("Yes\n");
		return 0;
	}
	cnt = 0;
	for(int i = 0; i < 7; ++i){
		if(a[i] == x)
			cnt++;
		if(a[i] == y)
			cnt++;
	}
	if(cnt == 2){
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
sum = 0
for i in range(N):
    if B[i] > A[i]: #勇者の方が強い
        B[i] -= A[i]
        sum += A[i]
        if B[i] > A[i+1]:
            sum += A[i+1]
            A[i+1] = 0
        else:
            sum += B[i]
            A[i+1] -= B[i]
    else:
        sum += B[i]
print(sum)


Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
#define mx 1000000000000000000
#define ll long long int
//ll a[40001000];
//ll number[20],used[20];
int main()
{
    string a,b,c;
    cin >> a;
    if(a[0]=='S')
        cout << "Cloudy" << endl;
    else if(a[0]=='R')
        cout << "Sunny" << endl;
    else if(a[0]=='C')
        cout << "Rainy" << endl;
    return 0;
}


Measured memory_bytes: 3468
#include<bits/stdc++.h>
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define fi first
#define se second
using namespace std;
template <class T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y){x=x>y?x:y;return;} 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;

ll a,b,c;

int main()
{
	cin>>a>>b>>c;
	if(c-a-b<0) cout<<"No"<<endl;
	else if((c-a-b)*(c-a-b)>4*a*b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;
    queue< pair<int, int> > q;
    int d[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            if(c == '#'){
                pair<int,int> p = make_pair(i,j);
                q.push(p);
                d[i][j] = 0;
            } else {
                d[i][j] = 100000000;
            }
        }
    }
    int dx[4] = {-1, 0, 0, 1};
    int dy[4] = {0, 1, -1, 0};
    while(!q.empty()){
        pair<int,int> p = q.front();
        q.pop();
        int x = p.first;
        int y = p.second;
        for(int i = 0; i < 4; i++){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
            if(d[nx][ny] == 100000000){
                d[nx][ny] = d[x][y]+1;
                pair<int,int> np = make_pair(nx, ny);
                q.push(np);
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            ans = max(ans, d[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int H, N;
vector<pair<int, int>> magic;

bool visited[10101];
ll dp[10101];

ll rec(int hp) {
    if (hp <= 0) return 0;
    if (visited[hp]) return dp[hp];
    visited[hp] = true;
    ll ret = 1ll << 60;
    for (auto& m: magic) ret = min(ret, rec(hp - m.first) + m.second);
    return dp[hp] = ret;
}

signed main() {

    cin >> H >> N;
    
    REP(i, N) {
        int A, B;
        cin >> A >> B;
        magic.emplace_back(A, B);
    }

    cout << rec(H) << endl;

}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
#define ll long long
ll ans,ans1;
int n;
ll a[15][15];
int main(){
	scanf("%d",&n);
	ans=0;ans1=0;
	int x=0,y=0,j;	
	for(int i=1;i<=n;i++){
		j=i;
		y=j%10;
		while(j/10)j/=10;
		x=j;
		a[x][y]++;
	}
	for(int i=1;i<=n;i++){
		j=i;
		y=j%10;
		while(j/10)j/=10;
		x=j;
		ans+=a[y][x];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
from operator import mul
def dot(v1, v2):
    return sum(map(mul, v1, v2))

def mat_mul(A, B, m):
    tB = tuple(zip(*B))
    return [[dot(A_i, B_j) % m for B_j in tB] for A_i in A]

def mat_pow(X, n, m):
    s = len(X)
    A = [[0] * s for i in range(s)]
    for i in range(s):
        A[i][i] = 1
    
    while n > 0:
        if n & 1:
            A = mat_mul(A, X, m)
        X = mat_mul(X, X, m)
        n >>= 1
    return A

def solve():
    from sys import stdin
    file_input = stdin
    while True:
        N, M, A, B, C, T = map(int, file_input.readline().split())
        if N == 0:
            break
        s = [list(map(int, file_input.readline().split()))]
        
        X = [[0] * N for i in range(N)]
        X[0][0] = B
        X[0][1] = A
        for i, X_i in enumerate(X[1:N-1], start=1):
            X_i[i - 1] = C
            X_i[i] = B
            X_i[i + 1] = A
        X[-1][-2] = C
        X[-1][-1] = B
        
        ans = mat_mul(s, mat_pow(X, T, M), M)
        print(*ans[0])

solve()


Measured memory_bytes: 6476
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
	char key[2] = {'i', 'w'};
	vector<pair<char, char> > iwi;
	iwi.push_back(pair<char, char>('i', 'i'));
	iwi.push_back(pair<char, char>('w', 'w'));
	iwi.push_back(pair<char, char>('(', ')'));
	iwi.push_back(pair<char, char>(')', '('));
	string in;
	cin >> in;
	int center = 0;
	if(in.size()%2) center = (in.size()-1)/2;
	else{
		center = in.size()/2;
		in.insert(center, "i");
	}

	int count = 0;
	for(int i = 0; i <= (in.size()-1)-center; i++){
		if(i){
			for(int j = 0; j < 4; j++){
				if(in[center-i]==iwi[j].first&&in[center+i]!=iwi[j].second){
					count++;
				}
			}
		}
		else{
			bool f = true;
			for(int j = 0; j < 3; j++){
				if(in[center+i]==key[j]) f = false;
			}
			if(f) count++;
		}
	}
	cout << count << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

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

  if(b+c<a){
    cout << 0 << endl;
  }
  else{
    cout << b+c-a << endl;
  }

  return 0;
}


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

int st[60];

int solve(int n,int p){
  memset(st,0,sizeof(st));
  int t = 0;
  int all = p;
  while(true){
    if(p){
      st[t]++;
      p--;
    }
    else{
      p+=st[t];
      st[t]=0;
      if(p==all) break;
    }
    t=(t+1)%n;
  }
  return t;
}
int main(){
  int n,p;
  while(cin>>n>>p,n||p){
    cout << solve(n,p) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K == 0:
    print(max(A))
    exit()

def f(x):
    cnt = 0
    for i in A:
        if i % x == 0:
            cnt += i//x - 1
        else:
            cnt += i//x
    
    if cnt <= K:
        return True
    else:
        return False


A_max = max(A)
ok = 0
ng = A_max
from math import log2, ceil
while ng - ok > 1:
    mid = (ok + ng) // 2
    if f(mid):
        ng = mid
    else:
        ok = mid
print(ceil(ng))


Measured memory_bytes: 104024
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    h = list(map(int, input().split()))

    ans = []
    tmp = 0
    for i in range(n-1):
        if h[i] >= h[i + 1]:
            tmp += 1
        else:
            ans.append(tmp)
            tmp = 0
    ans.append(tmp)
    print(max(ans))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14252
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0)
typedef long long ll;


ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

//#######################################




int main(){
  boost;
  string s,t;
  cin>>s>>t;
  int n=t.size();
  int mx=n;
  for(int i=0;i<s.size()-n+1;i++){
    string d=s.substr(i,n);
    int count=0;
    for(int j=0;j<n;j++){
      if(d[j]!=t[j]){
        count++;
      }
    }
     mx=min(count,mx);
  }
  cout<<mx;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n,k; cin >> n >> k;
  ll ans = 0;

  if (k == 0) { COUT((ll)n*n); return 0; }

  for (int b = k; b <= n; b++) {
    ans += (n / b) * (b-k);
    ans += max(0, (n%b)-k+1);
  }
  COUT(ans);
  return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}

const int N=100,W=10000;
int dp[N+1][W+1],n,m,v[N],w[N];

int rec(int i,int lw){
    if(dp[i][lw]>=0){
        return dp[i][lw];
    }
    int res;
    if(i==n){
        res=0;
    }else if(w[i]>lw){
        res=rec(i+1,lw);
    }else{
        res=max(rec(i+1,lw),rec(i+1,lw-w[i])+v[i]);
    }
    return dp[i][lw]=res;
}

int main(){
    int i;
    //入力
    cin>>n>>m;
    rep(i,n){
        cin>>v[i]>>w[i];
    }
    rep(i,n+1){
        rep(j,m+1){
            dp[i][j]=-1;
        }
    }
    //処理
    int mx=rec(0,m);
    //出力
    cout<<mx<<endl;
}


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

using namespace std;

#define int long long

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

typedef pair<int, int> PII;

//--------

int l[50];
vector<int> pressed;

signed main(){
    int N;
    string s;
    cin >> N;
    cin >> s;

    REP(i, N)
    {
        l[s[i] - 'a']++;
    }

    int ans = 1;

    REP(i, 50)
    {
        if(l[i] > 0)
        {
            ans *= (l[i] + 1);
            ans %= 1000000007;
        }
    }

    ans += 1000000006;

    cout << ans % 1000000007 << endl;

    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int N=5000010;
int n,a[N],len[N],v[N];
bool check(int x)
{
	int top=1;
	len[1]=a[1];v[1]=1;
	for (int i=2;i<=n;i++)
	{
		if (a[i]>a[i-1])
		{
			len[++top]=a[i];v[top]=1;
		}else
		{
			while (top&&len[top-1]>=a[i]) top--;
			while (top&&v[top]==x) top--;
			if (top==0) return 0;
			int K=min(a[i],len[top]),color=v[top];
			len[top]=K-1;
			if (len[top]==len[top-1]) top--;
			len[++top]=K;
			v[top]=color+1;
			if (len[top]!=a[i])
			{
				len[++top]=a[i];
				v[top]=1;
			}
		}
		while (top>1&&v[top]==v[top-1]) len[top-1]=a[i],top--;
	}
	return 1;
}
int erfen(int l,int r)
{
	while (l<r)
	{
		int mid=(l+r)>>1;
		if (check(mid)) r=mid;
			else l=mid+1;
	}
	return r;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	printf("%d\n",erfen(1,n));
	return 0;
}


Measured memory_bytes: 4224
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>


using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(ll i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
const ll MOD = 1e9 + 7;
vi 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' };

ll gcd(ll a, ll b) {
    if (a == 0 && b != 0) return(b);
    else if (a != 0 && b == 0) return(a);
    else if (a % b == 0)  return(b);
    else return(gcd(b, a % b));
}

int main() {
    ll N;
    cin >> N;
    vll a(N + 1);
    repp(i, N) cin >> a[i];
    vll L(N + 2);
    L[1] = 0;
    vll R(N + 2);
    R[N + 1] = 0;
    vll ans(N + 1);
    repp(i, N) {
        L[i + 1] = gcd(a[i], L[i]);
    }
    for (ll i = N; i >= 1; i--) {
        R[i] = gcd(R[i + 1], a[i]);
    }
    repp(i, N) {
        ans[i] = gcd(L[i], R[i + 1]);
    }
    sort(ans);
    riverse(ans);
    cout << ans[0] << endl;
}   

Measured memory_bytes: 3328
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long K, Q;
long long D[1 << 18];

long long solve(long long N, long long X, long long M) {
	long long S = X, ans = N - 1;
	for (int i = 0; i < K; i++) {
		long long V = (N + K - i - 2LL) / K;
		long long T1 = (D[i + 1] % M);
		S += V * T1;
		if (T1 == 0) ans -= V;
	}
	long long D1 = (X / M);
	long long D2 = (S / M);
	return ans - (D2 - D1);
}

int main() {
	cin >> K >> Q;
	for (int i = 1; i <= K; i++) cin >> D[i];

	for (int i = 1; i <= Q; i++) {
		long long A, B, C;
		cin >> A >> B >> C;
		cout << solve(A, B, C) << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
int main() {
    int n;
    cin>>n;
    vector<pair<ll,ll>> v;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }

    for(int i=0;i<n-1;i++){
        ll a=0,b=0;
        if(v[i].first>v[i+1].first){
            a=v[i].first/v[i+1].first;
            if(v[i].first%v[i+1].first!=0){
                a++;
            }

        }
        if(v[i].second>v[i+1].second){
            b=v[i].second/v[i+1].second;
            if(v[i].second%v[i+1].second!=0){
                b++;
            }

        }

        ll maxab=max(a,b);
        if(maxab!=0) {
            v[i + 1].first *= maxab;
            v[i + 1].second *= maxab;
        }

    }

    cout<<v[n-1].first+v[n-1].second<<endl;

    return 0;
}


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

int main(){
    int q;
    cin >> q;
    vector<bool> prime_flg(1e5+1, 1);
    prime_flg[0] = 0;
    prime_flg[1] = 0;
    for ( int i = 2; i <= 1e5; ++i ) {
        if ( prime_flg[i] ) {
            for ( int j = i + i; j <= 1e5; j += i ) {
                prime_flg[j] = 0;
            }
        }
    }
//    for ( int i = 0; i <= 10; ++i ) {
//        cout << i << " " << prime_flg[i] << endl;
//    }
    vector<int> ans(1e5+1);
    for ( int i = 2; i <= 1e5; ++i ) {
//        if ( i <= 10 ) {
//            cout << i << " " << prime_flg[i] << " " << prime_flg[(i+1)/2] << endl;
//        }
        if ( prime_flg[i] && prime_flg[(i+1)/2] ) {
            ans[i] = ans[i-1] + 1;
        }
        else {
            ans[i] = ans[i-1];
        }
//        if ( i <= 10 ) {
//            cout << ans[i] << endl;
//        }
    }
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << ans[r] - ans[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(),v.end()
#define inf14 1e14
#define inf18 1e18
void print(int a)                  {              cout<<a<<'\t'<<'\n';                      }
void print(int a,int b)                {          cout<<a<<'\t'<<b<<'\t'<<'\n';             }
void print(int a,int b,int  c)             {      cout<<a<<'\t'<<b<<'\t'<<c<<'\n';          }
void print(int a,int  b,int  c,int  d)         {  cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\n'; }
void print(int a,int  b,int  c,int  d,int  e)     { cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\t'<<e<<'\n';}
void print(vector<int> &a)                        { for(auto i:a)  cout<<i<<" ";   nl;      }
void print(string s)                              { cout<<s;nl;                             }

int v[100] , w[100001] , dp[100][100001]={};
void solve()
{
//    cout<<"hi";
    int n,maxWeight;    cin>>n>>maxWeight;


    for(int i=0 ; i<n ; i++)        cin>>w[i]>>v[i];

    dp[0][0] = 0;
    dp[0][w[0]] = v[0];
    int ans = 0;

    for(int i=1 ; i<n ; i++)
    {
        dp[i][0] = 0;
        for(int j=1 ; j<=maxWeight ; j++)
        {
            // we did not selected this item
            dp[i][j] = dp[i-1][j];

            // picked current object
            if(j>= w[i])
                dp[i][j] = max(
                            dp[i][j] ,
                            dp[i-1][ j - w[i] ] + v[i]
                            );
        }

    }
    for(int j=0 ; j<=maxWeight ; j++)
        ans = max(ans , dp[n-1][j]);
    print(ans);
}

int32_t main()
{
//    cout<<"ff";
   // ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
   //  int t;  cin>>t; while(t--)
    solve();
}/*

   vector<int> a = {157,26,9,-5782,0,5,17,-642,318,9,70,9,3210,-39,821,94,72,8,9,53,12,3,23};







*/


















Measured memory_bytes: 80968
#include<stdio.h>
#include<stdlib.h>
 
int main(){
    int n;
  scanf("%d",&n);
  
  if(n%10==7){
    printf("Yes");
  }else if((n%100)-(n%10)==70){
    printf("Yes");
  }else if(n-(n%100)==700){
    printf("Yes");
  }else{
    printf("No");
  }
    return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<cmath>
#include<algorithm>
using namespace std;


int main() {
	long long int a[5];
	long long int min = 10;
	long long int sum = 0;
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
		sum += a[i]-(a[i]%10);
		if (a[i] % 10 > 0)
		{
			sum += 10;
			if (a[i] % 10 < min)min = a[i] % 10;
		}
	}
	cout << sum - ((10 - min)%10) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int a, b;cin >> a >> b;
  cout << (a+b+1)/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 200005
using namespace std ;	int n ; 

int a[MAXN] ;

int gcd(int a, int b) {
	return b ? gcd(b, a%b) : a ;
}

inline bool check() {
	int ce = 0 , co = 0 , c1 = 0 ;
	long long sum = 0 ;
	int pos = 0 ;
	for (int i=1; i<=n; ++i)
		if ( a[i] & 1 )
			++co, pos = i , c1 += (a[i] == 1) , sum += a[i] ;
		else	++ce, sum += a[i] ;
	if ( c1 )	return ( sum - n ) & 1 ;
	if ( co == n )	return 0 ;
	if ( ce & 1 )	return 1 ;
	if ( (!( ce&1 )) && co > 1 )	return 0 ;
	--a[pos] ;
	int d = a[1] ;
	for (int i=2; i<=n; ++i)	d = gcd(d,a[i]) ;
	for (int i=1; i<=n; ++i)	a[i] /= d ;
	return check()^1 ;
}

int main() {
	scanf("%d",&n) ;
	for (int i=1; i<=n; ++i)	scanf("%d",a+i) ;
	puts(check()? "First":"Second") ;
	return 0 ;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
 public static void main(String[] args) { // ?¨??????\???????????????????????????????????????
  Scanner sc = new Scanner(System.in);
  int w = sc.nextInt();
  int n = sc.nextInt();
  int[] values = new int[w];
  for (int i = 0; i < values.length; i++) {
   values[i] = i + 1;
  }
  for (int i = 0; i < n; i++) {
   String str = sc.next();
   String[] ab = str.split(",");
   int a = Integer.parseInt(ab[0]) - 1;
   int b = Integer.parseInt(ab[1]) - 1; // a??¨b????????£???values??????????????????

   int c = values[a];
   values[a] = values[b];
   values[b] = c;
  }
  for (int i = 0; i < w; i++) {
   System.out.println(values[i]);
  }
 }
}

Measured memory_bytes: 26456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d; cin >> d;
    vector<int> c(26);
    rep (i, c.size()) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep (i, s.size()) { rep (j, s[0].size()) { cin >> s[i][j]; }}
    // rep (i, s.size()) { rep (j, s[0].size()) { cout << s[i][j] << " "; } cout << "\n";}
    vector<int> t(d);
    rep (i, t.size()) cin >> t[i];
    vector<ll> l(26, 0);
    rep (i, 26) eprintf("%d ", l[i]);

    ll sat = 0;
    rep (dy, d) {
        int k = t[dy] - 1;
        sat += s[dy][k];
        l[k] = dy + 1;
        eprintf("%lld ", sat);
        rep (i, 26) {
            sat -= c[i] * (dy + 1 - l[i]);
            if (c[i] * (dy + 1 - l[i]) < 0) {
                eprintf("(%d,%d,%d,%d)", dy,i,l[i],c[i] * (dy + 1 - l[i]));
            }
        }
        cout << sat << "\n";
    }
    return 0;
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 256
#define K 64

char s[N];
ll a[N];
ll dp[K];

bool add(ll b[], ll x)
{
    //cerr << "add(" << x << ")\n";
    while (x) {
        int i = bsrll(x);
        //cerr << "msb(" << x << ") = " << i << '\n';
        if (!b[i]) {
            b[i] = x;
            return true;
        }
        x ^= b[i];
    }
    return false;
}

void solve()
{
    int n;

    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    cin >> s;
    retif(s[n-1] == '1') cout << "1\n", void();
    fill_n(dp, K, 0);
    for (int i = n-1; i >= 0; --i) {
        retif(add(dp, a[i]) && s[i] == '1') cout << "1\n", void();
    }
    cout << "0\n";
}

int main()
{
    canhazfast();

    int t;
    cin >> t;
    for (; t; --t) solve();

    return 0;
}


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

int main() {
    int n, m, ans, temp, sum = 0;
    cin >> n >> m;
    rep(i, m) {
        cin >> temp;
        sum += temp;
    }
    ans = max(-1, n - sum);
    cout << ans << endl;
}

Measured memory_bytes: 3636
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc129/tasks/abc129_c

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

#include <iostream>
using namespace std;

template<int Mod>
struct MintBase {
  int64_t x; // typedef long long int64_t;
  MintBase(int64_t x=0):x((x%Mod+Mod)%Mod){}
  MintBase operator-() const { return MintBase(-x);}
  MintBase& operator+=(const MintBase a) {
    if ((x += a.x) >= Mod) x -= Mod;
    return *this;
  }
  MintBase& operator-=(const MintBase a) {
    if ((x += Mod-a.x) >= Mod) x -= Mod;
    return *this;
  }
  MintBase& operator*=(const MintBase a) { (x *= a.x) %= Mod; return *this;}
  MintBase operator+(const MintBase a) const { return MintBase(*this) += a;}
  MintBase operator-(const MintBase a) const { return MintBase(*this) -= a;}
  MintBase operator*(const MintBase a) const { return MintBase(*this) *= a;}
  MintBase pow(int64_t t) const {
    if (!t) return 1;
    MintBase a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime Mod
  MintBase inv() const { return pow(Mod-2);}
  MintBase& operator/=(const MintBase a) { return *this *= a.inv();}
  MintBase operator/(const MintBase a) const { return MintBase(*this) /= a;}
};

//const int Mod = 1000000007;
//const int Mod = 998244353;

using mint = MintBase<1000000007>;

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint factorial(const mint& x)
{
    mint ans = 1;
    for(mint i = x.x; i.x != 0; i -= 1)
    {
        ans *= i;
    }
    return ans;
}

mint factorial(const mint& x, const mint& n)
{
    mint ans = 1;
    mint m = x;
    for(int64_t i = 0; i < n.x; ++i)
    {
        ans *= m;
        m -= 1;
    }
    return ans;
}

mint Combination(int64_t x, int64_t y)
{
    return  factorial(x, y) / factorial(y);
}

int main(int, const char**)
{
    int n, m;
    cin >> n >> m;
    vector<mint> counts(n + 1, -1);
    rep(i, m)
    {
        int a;
        cin >> a;
        counts[a] = 0;
    }
    
    counts[0] = 1;
    rep(i, n)
    {
        auto t = i + 1;
        if(counts[t].x == 0)
        {
            continue;
        }
        if(t == 1)
        {
            counts[t] = 1;
            continue;
        }
        counts[t] = counts[t - 1] + counts[t - 2];
    }
    cout << counts[n].x << endl;
    return 0;
}


Measured memory_bytes: 4040
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ').map(Number)).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left >= n && right >= n) return;
    if (left < n && arr[left] > arr[i]) largest = left;
    else largest = i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 110736
#include<bits/stdc++.h>
using namespace std;
#define pb push_back 
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,a,b) for(int i=a;i<b;i++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define printmp(b) for(auto y:b) {printP(y);}

#define print(a) for(auto x:a) cout<<x<<' ';cout<<endl;
#define printM(b) for(auto y:b) {print(y);}
#define printP(p) cout<<p.first<<' '<<p.second<<endl;
typedef long long int ll;
typedef unsigned long long int ull;

/* 

*/
ll apowb(ll a,ll b)
{
  if(b==0)
  return 1;
  if(b==1)
  return a;
  if(b%2==0)
  {
    return apowb(a*a,b/2);

  }else
  {
    return apowb(a*a,b/2)*a;

  }
  
}

void solve()

{
 int n,x,t;
 cin>>n>>x>>t;

 int v=ceil((double)n/x);
 cout<<t*v;


   



   //cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;  
   
}


int main()
{
  /*
6
4 0
4 41
0 1000000
44 0
1 0
10000 1000000


  */
  fast;
  int t=1;
 //cin>>t;
  while(t--){
  
  solve();
 cout<<endl;
   
}
  
  
      
      return 0;
    }

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(int argc, char const *argv[])
{
    unsigned short *A, *B;

    int C[VMAX + 1];
    int n, i, j;
    scanf("%d", &n);

    A = (unsigned short*)malloc(sizeof(short) * n + 1);
    B = (unsigned short*)malloc(sizeof(short) * n + 1);

    for (int i = 0; i <= VMAX; i++) C[i] = 0;

    for (int i = 0; i < n; i++) {
        scanf("%hu", &A[i + 1]);
        C[A[i + 1]]++;
    }
    
    for (i = 1; i <= VMAX; i++) {
        C[i] = C[i] + C[i - 1];
    }

    for (j = 1; j <= n; j++) {
        B[C[A[j]]] = A[j];
        C[A[j]]--;
    }

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

    return 0;
}




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

int diff(int a, int b) {
    return a > b ? a - b : b - a;
}

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int dp[n];
    dp[0] = 0; // if you dont move you burn nothing
    dp[1] = diff(a[1], a[0]);

    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 2] + diff(a[i], a[i - 2]), dp[i - 1] + diff(a[i], a[i - 1]));
    }

    cout << dp[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 3940
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<utility>
#include<map>
#include<queue>

using namespace std;

#define LL long long
#define Linf (LL)1e18
const int dx[4] = { 1,-1,0,0 };
const int dy[4] = { 0,0,1,-1 };

LL n,a[200002],sum[200002];
int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		sum[i]=(i?sum[i-1]:0ll)+a[i];
	}
	LL ans = 1e18;
	for(int i=0; i<n-1; i++){
		ans=min(ans,abs(sum[n-1]-sum[i]*2));
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	//input
	int H, A;
	cin >> H >> A;

	//calculation
	int output = H / A;
	if (H % A != 0) {
		output++;
	}

	//output
	cout << output << endl;


	return 0;
}


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

int main(){    
    int N, M;
    cin >> N >> M;
    vector<vector<int>> a;
    a = vector<vector<int>>(N, vector<int>(N,0));
    for(int i=0; i<M; i++){
        int s, g;
        cin >> s >> g;
        s--;  g--;
        a[s][g] = 1;  a[g][s] = 1;
    }

    vector<int> path;
    int ans = 0;
    for(int i=1; i<N; i++) path.push_back(i);
    do{
        int now = 0;
        for(int i=0; i<N-1; i++){
            int next = path[i];
            if(a[now][next]!=1) break;
            if(i==N-2) ans++;
            now = next;
        }
    } while(next_permutation(path.begin(), path.end()));

    cout << ans << endl;
}


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

int main()
{
	int a, b;

	cin >> a >> b ;

	if (a<=b) {
		cout << a << endl;
	}

	else {
		cout << a-1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		long M = sc.nextLong();
		long S1 = M - (2 * N);
        if(S1 < 0) System.out.println((M / 2));
        else System.out.println((N + S1 / 4));
	}
}


Measured memory_bytes: 22740
from sys import stdin
a,b,m  = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
M = []
for i in range(m):
    M.append([int(x) for x in stdin.readline().rstrip().split()])
t = []
for i in range(m):
    t.append(A[M[i][0]-1] + B[M[i][1]-1] - M[i][2])
t = min(t)
k = min(A) + min(B)
print(min(t,k))


Measured memory_bytes: 83436
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

vector<Int> factorize(Int M){
    vector<Int> res = {};
    for(Int i=1; i*i <= M; i++){
        if(M % i == 0) {
            res.push_back(i);
            if(i*i != M) res.push_back(M/i);
        }
    }
    sort(res.begin(), res.end(), greater<Int>());
    return res;
}

int main(){
    Int N, K, sum = 0; vector<Int> A(510,0);
    cin >> N >> K;
    rep1(i,N){
        cin >> A[i];
        sum += A[i];
    }

    vector<Int> f = factorize(sum);

    rep(factor,f.size()){
        Int d = f[factor];

        vector<Int> rem(510);
        rep1(i,N) rem[i] = (A[i] % d);
        sort(rem.begin()+1, rem.begin()+1+N);

        vector<Int> sum_minus(510,0), sum_plus(510,0);
        rep1(i,N){
            sum_minus[i] = sum_minus[i-1] + rem[i];
            sum_plus[i] = sum_plus[i-1] + (d-rem[i]);
        }

        rep1(i,N){
            if(sum_minus[i] == (sum_plus[N]-sum_plus[i])){
                if(sum_minus[i] <= K){
                    cout << d << endl; return 0;
                }
            }
        }
    }
}


Measured memory_bytes: 384
# coding: utf-8
#union-findを用いた解法
N,M=map(int,input().split())
ans = 0
L = []
def UF(l):
    #親のノードを格納　2の親が4のとき par[2]=4
    par=[0]
    #木の深さを格納　根が2の深さが3の時 rank[2]=3
    rank=[0]
    
    #初期化
    for i in range(1,N+1):
        par.append(i)
        rank.append(0)
    
    #xの根を探す、同時に通過したノードすべてを根に直接つける
    def find(x):
        #xの親がxならば根なのでxを返す
        if par[x]==x:
            return x
        else:
            #違う場合は親の親を捜し自分の親にする
            par[x] = find(par[x])
            #再帰的に行うと根が見つかる
            return par[x]
    
    #xが属する木とyが属する木を併合する
    def unite(x,y):
        #根を探す
        root_x=find(x)
        root_y=find(y)
    
        #根が同じなら元からつながっているので終わり
        if root_x == root_y:
            return
    
        #ランクが大きい木の根の直下にランクが小さい木を結合
        if rank[root_x] < rank[root_y]:
            par[root_x] = root_y
    
        else:
            par[root_y] = root_x
    
        #ランクが等しいときのみランクが増える#なぜ#yにxが結合？
        if rank[root_x]==rank[root_y]:
            rank[root_x]+=1
    
    #xとyが同じ木に存在するかを調べる
    def same(x,y):
        return find(x)==find(y)
    for i in range(M-1):
        a = l[i][0]
        b = l[i][1]
        unite(a, b)
    for i in range(1, N):
        if not same(i, i+1):
            return True

#main
for i in range(M):
    L.append(list(map(int,input().split())))

for i in range(M):
    l = L[0:i] + L[i+1:]
    if UF(l):
        ans += 1
print(ans)

Measured memory_bytes: 68268
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
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;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

void solve(void){

	int N, P;
	cin >> N >> P;

	vecll dp(2, 0);
	dp[0] = 1;

	rep(N, i)
	{
		int a;
		cin >> a;
		if (a&1)
		{
			ll tmp = dp[0];
			dp[0] += dp[1];
			dp[1] += tmp;
		}
		else
		{
			dp[0] *= 2;
			dp[1] *= 2;
		}
	}

	cout << dp[P] << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;
 
vector<vector<int> > s;
vector<int> c;

ll score(vector<int> held,int k){
    vector<int> ld(26,0);
    ll ans=0;

    rep(i,held.size()){
        int t=held[i];
        ld[t]=i+1;
        ans+=s[i][t];
        rep(j,26){
            ans-=c[j]*(i+1-ld[j]);
        }
    }

    rep(i,26){
        ans-=c[i]*(held.size()+k*(1+k)+1-ld[i]);
    }

    return ans;
}

int main(){
    int d; cin >> d;
    vector<int> cc(26);
    c=cc;
    rep(i,26) cin >> c[i];
    vector<vector<int> > ss(d);
    s=ss;
    rep(i,d)rep(j,26){
        int a; cin >> a;
        s[i].push_back(a);
    }
 
    //vector<int> ld(26,0);
    vector<vector<int> > ds(26);
    vector<int> ans;
    rep(p,26){
        vector<int> days(0);
        ll tmps=-INF;
    rep(i,d){
        ll now=-INF;
        int whatday;
        rep(j,26){
            vector<int> tmp=days;
            tmp.push_back(j);
            ll sc=score(tmp,p);
            if(sc>now){
                whatday=j;
                now=sc;
            }
        }
        days.push_back(whatday);
    }
    ll nows=score(days,0);
    if(tmps<nows){
        ans=days;
        tmps=nows;
    }
    }
    rep(i,d) cout << ans[i]+1 << endl;
return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int MAXN=100010;

int f[MAXN], mark[MAXN];
P Q[MAXN];

int getf(int k, int id)
{
	return mark[k] < id ? k : f[k] = getf(f[k], id);
	/*如果k?点被??的??早于????，就返回k。否?????k的父?点，
	且因???路径上有一些?点未被??或者???期，可以路径??,直接?被
	???点到最近???点路径上的所有?点都指向最近???点*/
}

int main()
{
	int n, q;
	while(~scanf("%d %d", &n, &q),n + q)
	{
		for(int i = 2; i <= n; i++)
		{
			scanf("%d", &f[i]);
			mark[i] = inf;
		}
		int cnt = 0;
		char c;
		int x;
		for(int i = 1; i <= q; i++)
		{
            getchar();
			scanf("%c %d", &c, &x);
			if(c == 'Q')
			Q[cnt++] = P(i, x);//P(i,x)表示在i?刻??x的最近??点
			else
			mark[x] = min(mark[x], i);//mark[i]表示i?点第一次被??的??，inf表示未被??
		}
		ll ans = 0;
		for(int i = cnt - 1; i >= 0; i--)
		ans += getf(Q[i].second, Q[i].first);
		printf("%lld\n", ans);
	}
 	return 0;
}

Measured memory_bytes: 4820