akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<string>

using namespace std;

int ky[10005];
int bre(int t,int b,int c);
int brea(int t,int b,int c);
int n;

main(){
  int ans=99999;
  int temp;
  while(1){
    cin >> n;
    if(n==0) break;
    memset(ky,0,sizeof(ky));
    ans=99999;
    for(int i=1;i<=n;i++){
      cin >> ky[i];
    }
    for(int i=1;i<=n;i++){
      for(int j=1;j<=3;j++){
	if(ky[i]!=j && ans>(temp=bre(i,i+1,j))){
	  ans=temp;
	}
      }
    }
    printf("%d\n",ans);
  }
}

int bre(int t,int b,int c){
  int i,j;
  for(i=t-1;c==ky[i] && ky[i]!=0;i--){
    ;
  }
  for(j=b;c==ky[j] && ky[j]!=0;j++){
    ;
  }
  if((t-(i+1))+(j-b)+1>=4){
      return bre(i,j,ky[i]);
  }
  return n-(b-t-1);
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

//! get the number of p's included in n!
LL g(LL n, LL p) 
{
    if (n < p) return 0;
    LL q = n/p;
    return q + g(q, p);
}

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

    vector<LL> cnt(20); //! cnt[i] = number of 10^i in [1..N]

    LL N;
    cin >> N;
    cout << ((N%2) ? 0 : g(N/2, 5)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 2000001
#define CMAX 10000

int main(){
  static int n;
  static int A[MAX],C[CMAX+1],B[MAX];
  static int i,j;


  scanf("%d",&n);
  for(i=0;i<CMAX+1;i++){
    C[i]=0;
  }

  for(i=0;i<MAX+1;i++){
    B[i]=0;
  }

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

  for(i=1;i<=CMAX;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=n;j>0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

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

  return 0;
}
   
   

Measured memory_bytes: 16268
import collections
N = int(input())
s = list(map(int, input().split()))
item = 0
sum = 0
node = 0
count = 0
before = 0


c = collections.Counter(s)

for i in range(N):
    count = c[i]
    node += count

    if i == 0:
        if count != 1:
            break
        else:
            before = 1
            sum = 1
    else:
        if count == 0:
            break
        else:
            sum = sum * (c[i-1] ** count)
            before = count

if node != len(s) or s[0] != 0:
    print("0")
else:
    print(sum%998244353)

Measured memory_bytes: 19936
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def intread():
    return int(sysread())
def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())

def dfs(current, to, dists):
    c, c_cost = current
    dists[c] = c_cost
    for n, n_cost in to[c]:
        if dists[n] == -1:
            dfs((n, c_cost + n_cost), to, dists)
    return dists


def run():
    N = intread()
    to = [[] for _ in range(N+1)]
    for i in range(N-1):
        a,b,c = mapline()
        to[a].append((b, c))
        to[b].append((a, c))
    Q, K = mapline()

    dists = [-1] * (N+1)
    dists = dfs((K, 0), to, dists)
    for i in range(Q):
        x,y= mapline()
        print(dists[x] + dists[y])

if __name__ == "__main__":
    run()


Measured memory_bytes: 142368
n, m = [int(i) for i in input().split()]
a, b = [], []
for _ in range(m):
  a_, b_ = [int(i) for i in input().split()]
  a.append(a_)
  b.append(b_)
  
nodes = list(set(a)|set(b))

def dfs(node, visited, neighbors):
    visited[node] = 1
    candidates = [
        k for k, v in visited.items()
        if v==0 and k in neighbors[node]]
    
    for new_node in candidates:
        visited = dfs(new_node, visited, neighbors)
    
    return visited
  
bridges = 0
for idx in range(len(a)):
    
    a_ = [x for i, x in enumerate(a) if i!=idx]
    b_ = [x for i, x in enumerate(b) if i!=idx]
    
    neighbors = {x:set() for x in nodes}
    for k, (i, j) in enumerate(zip(a_, b_)):        
        neighbors[i].add(j)
        neighbors[j].add(i)
    
    visited = {x:0 for x in nodes}
    visited = dfs(a_[0], visited, neighbors)
    
    not_visited = sum([v==0 for k, v in visited.items()])
    if not_visited:
        bridges += 1
        
print(bridges)

Measured memory_bytes: 3064
// https://atcoder.jp/contests/abc141/tasks/abc141_a
#include <bits/stdc++.h>
using namespace std;

int main(void){
  string today;
  cin >> today;
  string tommorow;
  if (today == "Sunny"){
    tommorow = "Cloudy";
  }else if (today == "Cloudy"){
    tommorow = "Rainy";
  }else{
    tommorow = "Sunny";
  }
  cout << tommorow << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define vi vector<int>
#define pb emplace_back
#define ll long long int
#define vll vector<long long int>
#define vpi vector<pair<ll,ll>>
#define bit(x) __builtin_popcount(x)
#define all(x) (x).begin(), (x).end()
#define mem(a) memset(a , 0 ,sizeof a)
#define rep(i,n) for(int i=0 ; i<n ; ++i)
#define deb(x) cout << #x << " - " << x << endl;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD = 1e9 + 7;
const ll INF = 10000000000000000;
const ll MAX_N = 1e5 + 7;
 
using namespace std;

int main(){
    IOS;
    ll a,b,n;
    cin >> a >> b >> n;
    ll x = min(b-1,n);
    ll zz = (a *x )/b - (a * (x/b));
    cout <<zz << endl;
    return 0;
}

Measured memory_bytes: 3564
s = input()
a = int(s[0:2])
b = int(s[2:4])

if 0 < a < 13 and 0 < b < 13:
    print("AMBIGUOUS")
elif 0 < b < 13:
    print("YYMM")
elif 0 < a < 13:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int  main(){
    long n;
    cin >>n;
    vector<long> HP;
    for(long i=0;i<n;i++){
        long tmp;
        cin >> tmp;
        HP.push_back(tmp);
    }
    long g = __gcd(HP.at(0),HP.at(1));
    for (long i=2;i<n;i++){
        g = __gcd(g,HP.at(i));
    }
    printf("%ld",g);
}

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

int main() {

	string a;

	cin >> a;

	if (a[0]==a[2]) {
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}

	return 0;
}

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

#define INF INT_MAX

using namespace std;

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



int main(void){
 	cin.tie(0);
    ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> p(n);
	for(int i = 0;i < n;i++){
		cin >> p[i];
	}
	int ans = 0;
	for(int i = 1;i < n-1;i++){
		if((p[i-1] < p[i] && p[i] < p[i+1]) 
			|| (p[i-1] > p[i] && p[i] > p[i+1])){
			ans++;
		}
	}

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

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

using namespace std;

int main()
{
    string str;
    cin >> str;
    long long sum = 0;
    for (int i = 0; i < str.size(); i++)
        sum += str[i] - '0';
    if (sum % 9 == 0)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}

Measured memory_bytes: 3728
#include<iostream>
using namespace std;
int main() {
    int a,b,c,d,e,f;
    cin >> a >> b >> c ;
    if ( a <= b && a <= c){
        d = a;
        if (b <= c) {
            e = b;
            f = c;
        }
        else {
            e = c;
            f = b;
        }
    }
    else {
        if (b <= a && b <= c){
            d = b;
            if (a <= c){
                e = a;
                f = c;
            }
            else {
                e = c;
                f = a;
            }
        }
        else {
            d = c;
            if (a <= b){
                e = a;
                f = b;
            }
            else {
                e = b;
                f = a;
            }
        }
    } 
 cout << d << " " << e << " " << f << endl;   
 return 0;
 }


Measured memory_bytes: 3096
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#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 << '\n'; }
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;
const ll MOD = 1e9 + 7 ;
const ll N = 1e7 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int n ;
    cin >> n ; 
    map<string,int> mp ; 
    int nax = 0 ; 
    for(int i = 0; i < n; i++){
        string s ; 
        cin >> s ; 
        mp[s]++ ; 
        nax = max(nax, mp[s]);
    }
    for(auto p : mp){
        if ( p.second == nax ){
            cout << p.first << endl;
        }
    }
    return 0; 
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
const long long INF = numeric_limits<long long>::max();
int main() {
    string S, T;
    cin >> S >> T;

    ll ans = INF;
    for (ll i = 0; i < S.length() - T.length() + 1; ++i) {
        ll diffCount = 0;
#ifdef SOURCE_TEST
        PR(S[i]);
#endif
        for (ll j = 0; j < T.length(); ++j) {
            if (S[i + j] != T[j]) {
                diffCount++;
            }
        }
        ans = min(ans, diffCount);
    }

    PR(ans);

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int N = 10001;
int dp[N][N];
int main(){
	string s,t;
	cin >> s;
	cin >> t;
	for(int i=1;i<=s.size();i++){
		for(int j=1;j<=t.size();j++){
			if(s[i-1] == t[j-1]){
				dp[i][j] = max(dp[i][j-1],1+dp[i-1][j-1]);
			}
			else
				{
					dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
		}
	}

	if(dp[s.size()][t.size()] == 0)
	{
		cout << "";
		return 0;
	}
	//branch and bound
	int i=s.size(),j = t.size();
	string ans = "";
	while(i>0 && j >0){
		if(s[i-1] == t[j-1]){
			ans = ans + s[i-1];
			i--,j--;
		}
		else{
			if(dp[i-1][j] > dp[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans;
return 0;
}



Measured memory_bytes: 50728
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

s = readline().decode().strip()
q = int(readline())
is_reversed = False
qs = read().decode().split("\n")
left = []
right = [] 
for i in range(q):
    query = qs[i].split()
    t = int(query[0])
    if t == 1:
        is_reversed = not is_reversed
    elif t == 2:
        f = int(query[1])
        c = query[2]
        if f == 1:
            if is_reversed:
                right.append(c)
            else:
                left.append(c)
        elif f == 2:
            if is_reversed:
                left.append(c)
            else:
                right.append(c)

s = "".join(reversed(left)) + s + "".join(right)
if is_reversed:
    print(s[::-1])
else:
    print(s)

Measured memory_bytes: 80376
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
template<typename T>
bool all_same(vector<T> v1,vector<T> v2)
{
    sort(ALL(v1));
    sort(ALL(v2),greater<T>());
    return v1 == v2;
}
   
// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;

int main(){
    ll a,b,d,x=0,y=0,z,n,m,k,lank=1,w,sum=0,sum2=0,ans=0;
    string s,t;
    bool ok=true;
    cin >> n >> a >> b >> s;   
    rep(i,s.size()){
        if(s[i]=='a'){
            if(a+b>sum){
                sum++;
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
        }
        else if(s[i] == 'b'){
            if((a+b > sum) && lank <= b){
                lank++;
                sum++;
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
 
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n;
        cin >> n;
        ll a[n], b[n];
        rep(i, n) cin >> a[i];
        rep(i, n) cin >> b[i];

        ll time = 0;
        rep(i, n) {
            if (b[i] < a[i]) {
                time += (a[i] - b[i]);
                b[i] = a[i];
            }
        }
        rep(i, n) {
            if (a[i] < b[i]) {
                ll tmp = min(time, ll(((b[i] - a[i]) / 2.0)));
                time -= tmp;
                a[i] += 2 * tmp;
                if (time == 0) break;
            }
        }
        if (time > 0) {
            cout << "No" << endl;
            return 0;
        }
        rep(i, n) {
            if (a[i] > b[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> as(N);
  for(int i = 0; i < N; ++i) {
    cin >> as[i];
  }
  sort(as.begin(), as.end());
  cout << abs(as.front() - as.back()) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	
	int count=0;
	char S[4];
	scanf("%s",S);
	if (S[0] == S[1])
		count++;
	if (S[0] == S[2])
		count++;
	if (S[0] == S[3])
		count++;
	if (S[1] == S[3])
		count++;
	if (S[2] == S[3])
		count++;
	if (S[1] == S[2])
		count++;
	if (count == 2) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#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 = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;

    vl x(n+1), y(m+1);
    cin >> x[0] >> y[0];
    exrep(i, 1, n) {
        cin >> x[i];
    }
    exrep(i, 1, m) {
        cin >> y[i];
    }
    sort(all(x));
    sort(all(y));

    if(x[n] < y[0]) {
        out("No War");
    }
    else {
        out("War");
    }

    re0;
}

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

typedef long long ll;
 
int main(){
  int a, b;
  cin >> a >> b;
  string s, ans="Yes";
  cin >> s;
  for(int i=0; i<a; i++){
    if(s[i]=='-') ans = "No";
  }
  if(s[a]!='-') ans = "No";
  for(int i=a+1; i<a+b+1; i++){
    if(s[i]=='-') ans = "No";
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const int inf = (int)1e9 + 7;

int cost[10][10];
int a[202][202];
int dist[202][202];

main() {
    int h, w; scanf ("%d %d", &h, &w);
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            scanf ("%d", &cost[i][j]);
            dist[i][j] = cost[i][j];
        }
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            scanf ("%d", &a[i][j]);
        }
    }
    for (int k = 0; k <= 9; k++) {
        for (int i = 0; i <= 9; i++) {
            for (int j = 0; j <= 9; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (a[i][j] == -1 || a[i][j] == 1) {
                continue;
            }
            ans += dist[a[i][j]][1];
        }
    }
    cout << ans;
}


Measured memory_bytes: 512
#define ll long long
#define ffor(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--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

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

	string a,b,c;
	cin >> a >> b >> c;
	int a_len = a.length();
	int b_len = b.length();

	if(a[a_len-1] == b[0] && b[b_len-1] == c[0]) cout << "YES" << endl;
	else cout << "NO" << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int N;
	long long A, B;
	while(cin >> N >> A >> B){
		long long res = 0;
		long long pre, cur; cin >> cur;
		for(int i=1;i<N;i++){
			pre = cur;
			cin >> cur;
			res += min(B, (cur - pre)*A);
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
using ll = long long;


int main(){
    ll n,x=1,y=1,j;
    cin >> n;
    vector<ll> t(n),a(n);
    for(ll i=0;i<n;i++) cin >> t[i] >> a[i];
    for(ll i=0;i<n;i++){
        j = max(x/t[i],y/a[i])-1;
        while(1){
            j++;
            if((j*t[i])>=x&&(j*a[i])>=y){
                x = j*t[i];
                y = j*a[i];
                break;
            }
        }
    }
    cout << x+y << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int N,M;
    cin>>N>>M;
    int sum = 0, nmax = 0;
    for(int i = 0; i < M; i++){
        int A,B;
        cin >> A >> B;
        int okane =  max(N -  A,0);
        if (okane > nmax) nmax=okane;
        sum += okane;
            
    }
            cout << sum - nmax  << endl;
    
    
    
    return 0;
}



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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

int euclid(int a, int b)
{
    if (a < b)
        euclid(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int k, s;
    cin >> k >> s;

    int cnt = 0;
    for (int x = 0; x <= k; x++)
    {
        for (int y = 0; y <= k; y++)
        {
            int tp = s - (x + y);
            if (tp >= 0 && tp <= k)
                cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
fun main(args:Array<String>) {
    val n = readLine()!!.toLong()
    println(getAns(n))
}

fun getAns(n:Long):Long {
    var ans = 0L
    for(i in (1..n)) {
        if(i*i > n) {
            break
        }
        val b = (n-i)/i
        if(b == 0L) {
            continue
        }
        if(n%b == i) {
            ans += b
        }
    }
    return ans
}

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

#define qint queue<int>

int main() {
	vector<qint> vec; int an, tn, fn1, fn2, en;
	cin >> an >> tn; vec.resize(an);
	for (int i = 0; i < tn; i++) {
		cin >> fn1;
		switch (fn1) {
		case 0: cin >> fn2 >> en; vec[fn2].push(en); break;
		case 1: cin >> fn2;
			if (vec[fn2].empty()) continue;
			else cout << vec[fn2].front() << endl;
			break;
		case 2: cin >> fn2;
			if (vec[fn2].empty()) continue;
			else vec[fn2].pop();
			break;
		}
	}
	return 0;
}


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

using namespace std;

class Node {
public:
    explicit Node(int dst = 0, int idx = -1) : dst(dst), idx(idx) {}
    int dst, idx;
};

int main(){
    int N, M;
    while(cin >> N >> M){
        vector<vector<Node>> g(N);
        vector<int> D(N);
        for(auto& t : D) cin >> t;
        vector<pair<int,int>> d;
        for(int i=0;i<N;i++){
            d.emplace_back(D[i], i);
        }
        for(int i=0;i<M;i++){
            int U, V; cin >> U >> V;
            --U; --V;
            g[U].emplace_back(V, i);
            g[V].emplace_back(U, i);
        }
        sort(d.begin(), d.end());
        string res(N, '?');
        vector<long long> cost(M, -1);
        vector<int> state(N, 0);
        for(int i=0;i<N;i++){
            for(auto& e : g[d[i].second]){
                if(res[d[i].second] != '?') break;
                int pos = e.dst;
                if(D[pos] < d[i].first){
                    if(res[pos] != '?'){
                        res[d[i].second] = res[pos];
                        cost[e.idx] = d[i].first - D[pos];
                    }
                } else if(D[pos] == d[i].first){
                    cost[e.idx] = D[pos];
                    if(res[pos] != '?'){
                        res[d[i].second] = (res[pos] == 'W' ? 'B' : 'W');
                    } else {
                        res[d[i].second] = 'W';
                        res[pos] = 'B';
                    }
                }
            }
        }
        if(res.find('?') == string::npos){
            cout << res << endl;
            for(auto& t : cost) cout << (t == -1 ? 1000000000 : t) << endl;
        } else {
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 13556
// Java program For handling Input/Output 
import java.io.*; 
import java.util.*;
import java.math.*;
//import java.awt.*;

public class Main 
{ 
    FastReader sc;
    //actual logic
    void solve() throws IOException{
        int h = sc.ni();
        int a = sc.ni();

        System.out.println(h%a == 0 ? h/a : h/a + 1);
    }

    //constructor
    Main()
    {
        try{  
            sc = new FastReader();
        }catch(Exception e){
            System.out.println(e);
        }
    }


    //main metohd
    public static void main(String[] args) throws IOException
    { 
       new Main().solve();
   }
    //Utility methods

   static class FastReader{
    BufferedReader br;
    StringTokenizer st;
    FastReader(){
        br = new BufferedReader(new InputStreamReader(System.in));
        try{
            st = new StringTokenizer(br.readLine());
        }catch(Exception e){
            System.out.println(e);
        }
    }

    FastReader(String s){
        try{
            br = new BufferedReader(new FileReader(s));
            st = new StringTokenizer(br.readLine());
        }catch(Exception e){
            System.out.println(e);
        }
    }

    String ns(){
        if(!st.hasMoreTokens())
        {
            try{
                st = new StringTokenizer(br.readLine());
            }catch(Exception e){
                System.out.println(e);
            }    
        }
        return st.nextToken();

    }

    int ni(){
        return Integer.parseInt(ns());
    }

    long nl(){
        return Long.parseLong(ns());
    }

    double nd(){
        return Double.parseDouble(ns());
    }
}
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> h(n, 0);
  for(int i = 0; i < n; i++)
  {
    cin >> h[i];
  }
  vector<int> dp(n, 0);
  dp[1] = abs(h[0] - h[1]);
  for(int i = 2; i < n; i++)
  {
    dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

string shuffle(string s, int h){
    string head = s.substr(0, h);
    string tail = s.substr(h, s.size()-h);
    return tail + head;
}

int main(){
    string deck;
    int m, h;
    while (true) {
        cin >> deck;
        if (deck == "-"){ break; }
        cin >> m;
        for ( int i = 0; i < m; i++ ){
            cin >> h;
            deck = shuffle(deck, h);
        }
        cout << deck << endl;
    }
    return 0;
}



Measured memory_bytes: 3196
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

int main(void) {
  ll n, k;
  cin >> n >> k;
  n %= k;
  ll res = min(abs(n), abs(n-k));
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 888
n,k = map(int,input().split())
r,s,p = map(int,input().split())
txt = input()

score = {"s":r,"r":p,"p":s}

bef = [-1 for i in range(k)]

ans = 0
for i in range(k):
    ans += score[txt[i]]
    bef[i] = txt[i]



for i in range(k,n):
    sup = i%k
    if bef[sup] != txt[i]:
        ans += score[txt[i]]
        bef[sup] = txt[i]
    else:
        bef[sup] = -1

print(ans)


Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

class Stack
{
public:
    ll top;
    ll data[1000];
    Stack() : top(0){}

    void push(ll x)
    {
        data[++top] = x;
    }

    int pop(){
        top--;
        return data[top+1];
    }
};

int main(){
    Stack stack;
    string s;
    ll a, b;
    while(cin >> s){
        if(s == "+"){
            a = stack.pop(); b = stack.pop();
            stack.push(a+b);
        } else if(s == "-") {
            a = stack.pop(); b = stack.pop();
            stack.push(b-a);
        } else if(s == "*") {
            a = stack.pop(); b = stack.pop();
            stack.push(a*b);
        } else {
            stack.push(stoll(s));
        }
    }

    cout << stack.pop() << endl;
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define y1 y114514
using namespace std;
typedef complex<double> P;
typedef pair<double,int> Pair;

int u, n;
double xa, ya, xb, yb;
double x1, y1, x2, y2;
int o, l;
vector<Pair> v;

double cross(P a, P b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

int is_intersected_ls(P a1, P a2, P b1, P b2) {
	if((a1.real()-a2.real())*(b1.imag()-b2.imag()) + EPS > (a1.imag()-a2.imag())*(b1.real()-b2.real()) &&
	   (a1.real()-a2.real())*(b1.imag()-b2.imag()) < EPS + (a1.imag()-a2.imag())*(b1.real()-b2.real())) return 0;
	return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
		   ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

P intersection_ls(P a1, P a2, P b1, P b2) {
  P b = b2-b1;
  double d1 = abs(cross(b, a1-b1));
  double d2 = abs(cross(b, a2-b1));
  double t = d1 / (d1 + d2);
  return a1+(a2-a1)*t; 
}

int main(){
	P a, b;
	scanf("%d",&u);
	rep(i,u){
		cin >> xa >> ya >> xb >> yb;
		a = P(xa,ya); b = P(xb, yb);
		cin >> n;
		rep(j,n){
			cin >> x1 >> y1 >> x2 >> y2 >> o >> l;
			if(l == 0) o = o^1;
			P c = P(x1,y1), d = P(x2,y2);
			if(is_intersected_ls(a,b,c,d) == 0) continue;
			P e = intersection_ls(a,b,c,d);
			v.push_back(Pair(pow(e.real()-a.real(),2)+pow(e.imag()-a.imag(),2),o));
		}
		sort(v.begin(),v.end());
		int ans = 0;
		int st = 0;
		int cnt = 0;
		rep(j,v.size()){
			if(st != v[j].second){
				st = st^1;
				cnt++;
			}
		}
		ans = cnt;
		cnt = 0;
		st = 1;
		rep(j,v.size()){
			if(st != v[j].second){
				st = st^1;
				cnt++;
			}
		}
		ans = min(ans,cnt);
		cout << ans << endl;
		v.clear();
	}
}

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

using namespace std;

#define dbg(a) cout<<#a<<" = "<<a<<endl
#define dbg2(a,b) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<endl
#define dbg3(a,b,c) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<endl
#define dbg4(a,b,c,d) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<endl

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
const ll mod=1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//cout.precision(10);
//std::cout.setf( std::ios::fixed, std:: ios::floatfield );

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int x, y;
	cin>>x>>y;
	int z, count = 0;
	while(x--)
    {
    	cin>>z;
    	if(z >= y)
    	{
    		count++;
		}
	}
	cout<<count<<endl;
	return 0;
}


















Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[100010];
int num[100010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	sort(A,A+N);
	REP(i,N){
		num[i]=A[i];
	}
	REP(i,N){
		num[i+1]+=num[i];
	}
	int cnt=0;
	for(int i=N-1;0<=i;i--){
		if(num[i]*2>=A[i+1]){
			cnt++;
		}
		else{
			break;
		}
	}
	cout<<cnt<<endl;
	return 0;
}
//1 3 4
//1 2 7 20 30 40

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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

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

  int l[N];
  int i;
  for(i = 0; i < N; i++)
    cin >> l[i];
  
  std::qsort(l,N,4,compare_int);

  int j, k, m;
  int sum;
  int count = 0;
  for(j = N-1; j > 1 ; j--)
    {
      
      for(k = j-1; k > 0 ; k--)
	{
	  if(l[j]>2*l[k])
	    break;
	  for(m = k-1; m > -1; m--)
	    {
	      sum = l[k] + l[m];

	      if(l[j] < sum && sum <= 2*l[j])
		{
		  count++;
		}

	    }
	}
    }
  cout << count << endl;

  return 0;
}
      


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N, M, K, num, count int
	m := make(map[int]int)

	fmt.Scan(&N, &M)

	for e := 0; e < N; e++ {
		fmt.Scan(&K)
		for i := 0; i < K; i++ {
			fmt.Scan(&num)
			if _, ok := m[num]; ok {
				m[num]++
			} else {
				m[num] = 1
			}
		}
	}

	for _, elem := range m {
		if elem == N {
			count++
		}
	}

	fmt.Println(count)
	return
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n;
    cin>>n;
    string s;
    cin>>s;
    int m = sz(s);
    map<char, int> mp;
    rep(i, m) {
        mp[s[i]]++;
    }
    mint ans = 1;
    for (auto i : mp) {
        ans *= (i.second + 1);
    }
    cout<<ans - 1<<endl;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, m, a[100009], b, c;
vector<pair<int, int> > vec;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    reverse(a, a + n);
    for (int i = 0; i < m; i++) {
        cin >> b >> c;
        vec.pb(make_pair(c, b));
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    long long ans = 0;
    int cur = 0, cnt = 0, i = 0;
    while (1) {
        if (cnt == n) break;
        while (cur < m && vec[cur].se == 0) cur++;
        if ((cur < m && a[i] >= vec[cur].fi) || cur == m) {
            ans += a[i];
            i++;
        }
        else {
            ans += vec[cur].fi;
            vec[cur].se--;
        }
        cnt++;
    }
    cout << ans << "\n";
    //system("pause");
    return 0;
}


Measured memory_bytes: 1784
import sys
sys.setrecursionlimit(10000)
def fill(y,x):
    global w,h,l
    if 0<=y<h and 0<=x+1<w and l[y][x+1]==1:
        l[y][x+1]=0
        fill(y,x+1)
    if 0<=y<h and 0<=x-1<w and l[y][x-1]==1:
        l[y][x-1]=0
        fill(y,x-1)
    if 0<=y+1<h and 0<=x<w and l[y+1][x]==1:
        l[y+1][x]=0
        fill(y+1,x)
    if 0<=y-1<h and 0<=x<w and l[y-1][x]==1:
        l[y-1][x]=0
        fill(y-1,x)
    
    if 0<=y+1<h and 0<=x+1<w and l[y+1][x+1]==1:
        l[y+1][x+1]=0
        fill(y+1,x+1)
    if 0<=y-1<h and 0<=x+1<w and l[y-1][x+1]==1:
        l[y-1][x+1]=0
        fill(y-1,x+1)
    if 0<=y+1<h and 0<=x-1<w and l[y+1][x-1]==1:
        l[y+1][x-1]=0
        fill(y+1,x-1)
    if 0<=y-1<h and 0<=x-1<w and l[y-1][x-1]==1:
        l[y-1][x-1]=0
        fill(y-1,x-1)
    
while 1:
    w,h=map(int,input().split())
    if not w and not h:break
    l=[list(map(int,input().split())) for _ in range(h)]

    cnt=0
    while 1:
        cds=[[i,j.index(1)] for (i,j) in enumerate(l) if 1 in j]
        if not cds:
            break
        else:
            y,x=cds[0]
        l[y][x]=0
        fill(y,x)
        cnt+=1
    print(cnt)


Measured memory_bytes: 7896
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

int n;

int main(){
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=3500;i++){
		for(j=1;j<=3500;j++){
			double c=(1.0*i*j*n)/(4.0*i*j-1.0*i*n-1.0*j*n);
			double tmp=(int) c;
			if(fabs(tmp-c)<1e-6 && tmp>0){
				printf("%d %d %.0lf\n",i,j,tmp);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuffer sb = new StringBuffer();
		sb.append(s);
		String t = sc.next();
		int flg = 1;
		for(int i=0;i<s.length();i++){
			if(t.equals(sb.toString())){
				System.out.println("Yes");
				flg = 0;
				break;
			}
			char c = sb.toString().charAt(s.length()-1);
			sb.setLength(sb.length() - 1);
			sb.insert(0, c);
		}
		if(flg==1){
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n,k;
	cin >> n >> k;
	vector <int> a(n);
	int summ= 0;
	for(int i = 0;i < n;++i) cin >> a[i], summ = summ + min(abs(k - a[i]),a[i]);
	cout << 2 * summ << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
int main(){
	long s;int i,d,min=999;
	scanf("%ld",&s);
	for(i=0;i<8;i++){
	d=abs(s%1000-753);
	min=(min>d?d:min);
	s/=10;
	}
printf("%d",min);
}

Measured memory_bytes: 1704
n = int(input())
a = list(map(int, input().split()))

ans = 0
max_a = a[0]
for i in range(len(a)-1):
    if max_a<a[i+1]:
        max_a = a[i+1]
    if max_a>a[i+1]:
        ans += max_a - a[i+1]

print(ans)

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

int main(){
  string alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  char moji;
  cin >> moji;
  if (alp.find(moji) <= 25) cout << 'a' << endl;
  else cout << 'A' << endl;
}

Measured memory_bytes: 3596
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;

using namespace std;


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

    long long max_A = 0;

    vector<long long> A(N), B(N);
    for(int i = 0; i < N; ++i){
        cin >> A.at(i) >> B.at(i);
        max_A = max(max_A, A[i]);
    }

    vector<long long> table(H + max_A + 1, numeric_limits<long long>().max());
    table[0] = 0;

    for(long long i = 1; i <= H + max_A; ++i){
        for(long long j = 0; j < N; ++j){
            long long prev = max<long long>(0, i - A[j]);
            table[i] = min(table[i], table[prev] + B[j]);
        }
    }

    long long res = table[H];
    for(int i = H + 1; i <= H + max_A; ++i){
        res = min(res, table[i]);
    }
    cout << res;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        char[] s = S.toCharArray();
        char[] t = T.toCharArray();
        int[] R = new int[27];
        int[] R2 = new int[27];
        Arrays.fill(R, -1);
        Arrays.fill(R2, -1);
        for (int i = 0; i < S.length(); i++) {
            if (R[s[i] - 'a'] >= 0) {
                if (R[s[i] - 'a'] != (t[i] - 'a')) {
                    System.out.println("No");
                    return;
                }
            } else {
                R[s[i] - 'a'] = t[i] - 'a';
            }
            if (R2[t[i] - 'a'] >= 0) {
                if (R2[t[i] - 'a'] != (s[i] - 'a')) {
                    System.out.println("No");
                    return;
                }
            } else {
                R2[t[i] - 'a'] = s[i] - 'a';
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 30372
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

struct engine {
    ll x, y;
    long double angle;
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(30);

    ll N;
    cin >> N;
    vector<engine> engines;
    Rep (i, N) {
        ll x, y;
        cin >> x >> y;
        engines.push_back({x, y, atan2((long double) y, (long double) x)});
    }

    auto f = [](engine a, engine b) {
        return a.angle < b.angle;
    };

    sort(engines.begin(), engines.end(), f);

    // Rep (i, N) {
    //     cout << engines[i].x << " " << engines[i].y << " " << engines[i].angle << "\n";
    // }

    ll ans = 0;
    auto dist = [](ll x1, ll y1, ll x2, ll y2) {
        ll x = x1-x2;
        ll y = y1-y2;
        return x*x + y*y;
    };


    Rep (i, N) {
        ll nowx = 0;
        ll nowy = 0;
        chmax(ans, dist(nowx, nowy, 0, 0));
        for (ll j = i; j < i+N; j++) {
            nowx += engines[j%N].x;
            nowy += engines[j%N].y;
            chmax(ans, dist(nowx, nowy, 0, 0));
        }
    }

    cout << sqrt((long double) ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int X,Y,A,B,C; cin>>X>>Y>>A>>B>>C;
  priority_queue<pii> Q;
  rep(i,0,A){
    int X; cin>>X;
    Q.push(mp(X,0));
  }
  rep(i,0,B){
    int X; cin>>X;
    Q.push(mp(X,1));
  }
  rep(i,0,C){
    int X; cin>>X;
    Q.push(mp(X,2));
  }
  int ans=0,D=0,E=0,F=0;
  while(Q.size()>0){
    int G=Q.top().first,H=Q.top().second; Q.pop();
    if(H==0){
      if(D<X){
        ans+=G;
        D++;
        F++;
      }
    }
    else if(H==1){
      if(E<Y){
        ans+=G;
        E++;
        F++;
      }
    }
    else{
      ans+=G;
      F++;
    }
    if(F==X+Y) break;
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 10476
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;
#define rep(i, n) for (int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for (int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main()
{
    string S;
    cin >> S;
    int res = INF;

    for (int i = 0; i < 26; i++)
    {
        char target = (char)('a' + i);
        string T = S;
        int cnt = 0;
        bool isAll = 1;
        rep(i, T.size()) if (T[i] != target) isAll = false;
        if (isAll)
        {
            cout << 0 << endl;
            return 0;
        }
        while (1)
        {
            string new_T = "";
            for (int j = 0; j < T.size() - 1; j++)
            {
                if (T[j] == target || T[j + 1] == target)
                {
                    new_T.pb(target);
                }
                else
                {
                    new_T.pb('*');
                }
            }
            cnt++;
            bool ok = 1;
            for (int j = 1; j < new_T.size(); j++)
            {
                if (new_T[j] != new_T[j - 1])
                    ok = 0;
            }
            if (ok)
            {
                if (new_T[0] == target)
                {
                    res = min(cnt, res);
                }
                break;
            }
            T = new_T;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3616