akhauriyash/Code-Regression huggingface dataset:
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
  
i = list(map(int, input().split()))
out = Base_10_to_n(i[0], i[1])
print(len(str(out)))

Measured memory_bytes: 3060
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]


h,w = map(int, input().split())
s = [list(input()) for _ in range(h)]

dx = [ 0, -1, -1, -1,  0,  1, 1, 1 ]
dy = [ 1,  1,  0, -1, -1, -1, 0, 1 ]

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            cnt = 0
            for k in range(8):
                x = i + dx[k]
                y = j + dy[k]
                if ( x >= 0 and x < h and y >=0 and y < w):
                    if (s[x][y] == "#"):
                        cnt+=1
            s[i][j] = str(cnt)
#print(s)

for i in range(h):
    for j in range(w):
        print(s[i][j], end="")
    print("")





Measured memory_bytes: 9092
// #[warn(dead_code)]
// const TOP: u64 = 1000000007;

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

// use std::collections::BTreeMap;

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let n: i32 = iter.read();

	// use std::collections::BTreeMap;
	let mut sum: i32 = 0;
	let mut map: Vec<i32> = Vec::new();
	for _ in 0..n {
		let w: i32 = iter.read();
		map.push(w);
		sum += w;
	}

	let mut min: i32 = sum;
	let mut left: i32 = 0;
	// println!("{:?}", map);
	for &w in map.iter() {
		left += w;
		let tmp = (sum - left - left).abs();
		// println!("{} {} {}", tmp, sum, left);
		if tmp > min {
			println!("{}", min);
			return;
		}
		min = tmp;
	}
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b;
	string s,t,u;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	if(s==u){
		--a;
	}else{
		--b;
	}
	cout << a << " " << b << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int A[1000];
  int N;
  int i,j,v,n;

  /* 入力 */
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
 
  
  for(n=0;n<N;n++){
    if(n>0) printf(" ");
    printf("%d",A[n]);
  }
  printf("\n");
    

  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
      
    for(n=0;n<N;n++){
      if(n>0) printf(" ");
      printf("%d",A[n]);
    }
    printf("\n");
  }
  return 0;
}
   



Measured memory_bytes: 2068
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<int> a(3);

int main()
{
    cin>>a[0]>>a[1]>>a[2];
    SORT(a);
    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    
    vector<ll> left(n+1,0),right(n+1,0);
    rep(i,n) left[i+1]=left[i]+a[i];
    for(ll i=n-1;i>=0;i--) right[i]=right[i+1]+a[i];
    ll mini=10000000000;
    rep(i,n){
        mini=min(mini,abs(right[i]-left[i]));
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=5e3+100;
ll dp[N][N];
ll zar[N];
int32_t main(){
    ll n,mod;
    cin >> n >> mod;
    ll k=n/2;
    if (n%2==1){
        for (int i=2;i<=k+1;i++){
            zar[i]=i-1;
        }
        zar[n+1]=1;
        for (int i=n;i>k+1;i--){
            zar[i]=zar[i+1]+1;
        }
    }
    else{
        for (int i=2;i<=k;i++){
            zar[i]=i-1;
        }
        zar[n+1]=1;
        for (int i=n;i>k+1;i--) zar[i]=zar[i+1]+1;
        zar[k+1]=zar[k+2];
    }
    dp[1][0]=1;
    for (int i=2;i<=n;i++){
        for (int j=0;j<N;j++){
            dp[i][j]=dp[i-1][j];
            if (zar[i]<=j) dp[i][j]+=dp[i][j-zar[i]];
            dp[i][j]%=mod;
        }
    }
    ll ans=0;
    for (int i=0;i<n;i++){
        ll z=dp[n][i];
        z*=(n-i);
        ans+=z%mod;
        ans%=mod;
    }
    cout << ans << endl;

}


Measured memory_bytes: 200832
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();

		List<Integer> a = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			a.add(sc.nextInt());
		}

		sc.close();

		Collections.sort(a);
		Collections.reverse(a);

		System.out.print(a.get(0) - a.get(a.size() - 1));

	}

}

Measured memory_bytes: 21844
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
            a[i] = sc.nextInt();
        }
        long left = t[0];
        long right = a[0];
        for (int i = 1; i < n; i++) {
            long hidari = t[i];
            long migi = a[i];
            if (left <= hidari && right <= migi) {
                left = hidari;
                right = migi;
            } else {
                long c = left / hidari;
                if (left % hidari != 0) {
                    c++;
                }
                long b = right / migi;
                if (right % migi != 0) {
                    b++;
                }
                long max = Math.max(c, b);
                left = hidari * max;
                right = migi * max;
            }
        }
        System.out.println(left + right);
        sc.close();
    }
}

Measured memory_bytes: 24784
'use strict';
const main = x => {
  const n = parseInt(x[0], 10);
  const h = x[1].split(' ').map(val => parseInt(val, 10));
  // console.log(n, h);
  let count = 0;
  let ans = 1;
  h[0]--;
  for(let i=0; i<n-1; i++) {
    if(h[i]<h[i+1])h[i+1]--;
    if(h[i]>h[i+1])return console.log("No");
  }
  return console.log("Yes");
  
};
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 17804
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, a, b;
  cin >> n >> a >> b;
  if ((b - a) % 2 == 0) {
    cout << (b - a) / 2 << "\n";
  } else {
    int ans = min({n - a, b - 1, min(n - b, a - 1) + (b - a + 1) / 2});
    cout << ans << "\n";
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n;
	cin>>n;
	int ans=800*n;
	ans-=(n/15)*200;
	cout<<ans;
		
	
	return 0;
}

Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().rstrip())
a = list(map(int, stdin.readline().rstrip().split()))
amax = max(a)
amin = min(a)
ans = 10 ** 9 + 7
for i in range(amin, amax + 1):
    tmp = 0
    for ai in a:
        tmp += (ai - i) ** 2
    if tmp < ans:
        ans = tmp
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a, b, c, d[ohara], tmp, tmpp, m, h, w, x, y, sum, pos, k, t[ohara], neta[ohara], fine = 0;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};
pair<ll, ll> p[ohara];
unordered_map<ll, ll> spp;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> k;
    priority_queue<pair<ll, ll>> in;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> out;
    rep(i, n) cin >> t[i] >> d[i];
    rep(i, n) p[i] = make_pair(d[i], t[i]);
    sort(p, p + n);
    reverse(p, p + n);
    rep(i, k)
    {
        cnt += p[i].first, neta[p[i].second]++;
        if (neta[p[i].second] == 1)
            fine++;
    }
    rep(i, k)
    {
        if (neta[p[i].second] >= 2)
        {
            out.push({p[i].first, p[i].second});
        }
    }
    cnt += fine * fine;
    rrep(i, k, n)
    {
        if (neta[p[i].second] == 0 && spp[p[i].second] == 0)
        {
            in.push({p[i].first, p[i].second});
            spp[p[i].second] = 1;
        }
    }
    ans = cnt;
    while (1)
    {
        if (out.empty() || in.empty())
            break;
        cnt -= fine * fine;
        fine++;
        cnt += fine * fine;
        pair<ll, ll> pp;
        while (1)
        {
            pp = out.top();
            if (out.empty() || in.empty())
                break;
            if (neta[pp.second] >= 2)
                break;
            out.pop();
        }
        if (out.empty() || in.empty())
            break;
        cnt -= pp.first;
        neta[pp.second]--;
        out.pop();

        pp = in.top();
        in.pop();
        cnt += pp.first;
        neta[pp.second]++;
        ans = max(ans, cnt);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 13060
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		if(A+B < 2*C) {
			System.out.println((A*X)+(B*Y));
		}else {
			int ans = 0;

			ans += Math.min(X, Y) * (2*C);

			int price = 0;
			if(X>Y) price = A;
			else price = B;

			ans += Math.min(price, 2*C) * Math.abs(X-Y);
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 22612
// B - Palindromic Numbers
#include <bits/stdc++.h>
using namespace std;

int main(){
	int a,b; cin>>a>>b;
	int cnt = 0;
	for(int i=a; i<=b; ++i){
		int l = i/10000;
		int l2 = i%10000 / 1000;
		int r2 = i%100 / 10;
		int r = i%10;
		if(l==r && l2==r2) cnt++;
	}
	cout<< cnt <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <queue>
#include <complex>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
  int n;

  cin >> n ; //nは10の5乗数

  vector<long> t(n);
  vector<long> x(n);
  vector<long> y(n);
  for (int i = 0; i < n; ++i) {
    cin >> t[i] >> x[i] >> y[i];
  }



  bool ans=true;
  int px=0,py=0;
  int pt=0;

  for (int i = 0; i < n; ++i){
    cerr  << "t:" <<t[i] - pt  <<"   x:" <<abs(px-x[i]) <<"   y:" <<abs(py-y[i]) <<endl;
    if (t[i] - pt >= abs(px-x[i]) + abs(py-y[i])  && (t[i] - pt + abs(px-x[i]) + abs(py-y[i]) )%2 ==0 ){
      px = x[i];
      py = y[i];
      pt =t[i];
    }else{
      ans=false;
      break;
    }
  }


  cout <<(ans?"Yes":"No");


  return 0;
}


Measured memory_bytes: 2560
n,k = (int(w) for w in input().split()[:2])
r,s,p = (int(w) for w in input().split()[:3])
t = input()

h = {'r': 'p', 's': 'r', 'p': 's'}
score = {'r': r, 's': s, 'p': p, 'e': 0}

z = [h[c] for c in t]
for i in range(k, n):
    if z[i]==z[i-k]: z[i] = 'e'

x = sum(score[v] for v in z)

print(x)


Measured memory_bytes: 4212
# https://note.nkmk.me/python-union-find/

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

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

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

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

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

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

N, M, K = map(int, input().split())
par = [-1]*N
#直接友達になっている人数とブロックしている人数をカウント
num = [0]*N

uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    #友達関係をつなげる
    uf.union(a, b)
    #直接友達なのでカウントする
    num[a] += 1
    num[b] += 1

for _ in range(K):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    # print(f"c{c}, d{d}, uf.same(c, d) {uf.same(c, d)}")
    #同じグループに属している場合、size()にカウントされるのでnumを増やす
    if uf.same(c, d):
        num[c] += 1
        num[d] += 1
# print(num)
for i in range(N):
    #直接友達関係の人と同じグループでブロックしている人、自分自身を除く人数が候補となる
    print(uf.size(i)-1-num[i], end=" ")

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

int n;

vector<string> ans;

void dfs(string s, char mx){
    if (s.size() == n){
        ans.push_back(s);
        return;
    }
    for(char c = 'a'; c <= mx; c++){
        if (c == mx) dfs(s + c, char(mx + 1));
        else dfs(s + c, mx);
    }
}


int main(){
    cin >> n;
    dfs("", 'a');
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 7796
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <queue>
typedef long long LL;
inline int getint()
{
	int r = 0,s = 0;char c = getchar();for(;!isdigit(c);c = getchar()) s |= c == '-';
	for(;isdigit(c);c = getchar()) r = (((r << 2) + r) << 1) + (c ^ '0');return s ? -r : r;
}
struct node
{
	int c0,c1,id;
	inline friend bool operator < (const node &a,const node &b)
	{
		return 1LL * a.c0 * b.c1 < 1LL * a.c1 * b.c0;
	}
};
std::priority_queue<node> Q; 
const int N = 200020;
int cnt[2][N],p[N],fa[N],n;
inline int find(int x){return x == fa[x] ? x : (fa[x] = find(fa[x]));}
int main()
{
	n = getint();
	for(int i = 2;i <= n;i++) p[i] = getint();
	for(int i = 1;i <= n;i++) fa[i] = i,++cnt[getint()][i];
	for(int i = 2;i <= n;i++) Q.push((node){cnt[0][i],cnt[1][i],i});
	LL ans = 0;
	while(Q.size())
	{
		node now = Q.top();
		Q.pop();
		int u = now.id;
		if((cnt[0][u] != now.c0) || (cnt[1][u] != now.c1)) continue;
		int v = fa[u] = find(p[u]);
		ans += 1LL * cnt[0][u] * cnt[1][v];
		cnt[0][v] += cnt[0][u];
		cnt[1][v] += cnt[1][u];
		if(v != 1) Q.push((node){cnt[0][v],cnt[1][v],v});
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 8052
//g++  5.4.0

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,K; cin >> n>>K;
    vector<int> arr(n);
    for(int i = 0; i < n; i++) cin >> arr[i];
    vector<bool> dp(K+1,0);
    for(int i = 0; i <= K; i++){
        for(int j = 0; j < n; j++){
            if(i >= arr[j] && !dp[i-arr[j]]) dp[i] = true;
        }
    }
    
    cout << (dp[K] ? "First" : "Second") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
int main(void){
	int W,H,x,y,r;
	bool ans = true;
	cin >> W >> H >> x >> y >>r;
	if((x+r) > W){
		ans = false;
	}
	if(x < r){
		ans = false;
	}
	if((y+r) > H){
		ans = false;
	}
	if(y < r){
		ans = false;
	}
	if(ans){cout << "Yes" << endl;}
	else{cout << "No" << endl;}
	return 0;
}

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

#define int long long
int arr[100005];
int dp[100005];
int n;

int f(int i)
{
	if(i==n-1)
	{
		return 0;
	}
	if(i>=n)
	{
		return 1000000000;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	if(i==n-2)
	{
		return dp[i]= abs(arr[i]-arr[i+1]) + f(i+1);
	}
	return dp[i] = min(abs(arr[i]-arr[i+1])+f(i+1),abs(arr[i] - arr[i+2])+f(i+2));
}

int32_t main()
{
	cin>>n;
	for(int i=0;i<n;i++)	cin>>arr[i];
	memset(dp,-1,sizeof(dp));
	cout<<f(0);
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
 
int main(){
    unsigned len,num;
    std::string tmp;
    std::cin >> len >> num;
    std::cin >> tmp;
    std::vector<unsigned> sum={0};
    unsigned total=0;
    
    for(unsigned i=1; i<len; i++){
        if(tmp[i-1]=='A' && tmp[i]=='C')
            total++;
        sum.push_back(total);
    }
  
  //for(auto n:sum)
  //  std::cout << n;
  //std::cout << std::endl;
    
    for(unsigned i=0; i<num; i++){
        int l,r;
        std::cin >> l >> r; l--;r--;
        std::cout << sum[r]-sum[l] << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAXN 100010

long long x[MAXN], v[MAXN];
long long shun[MAXN], ni[MAXN];
long long mx1[MAXN], mx2[MAXN];

int main() {
	long long n, c; cin >> n >> c;
	memset(shun, 0, sizeof(shun));
	memset(ni, 0, sizeof(ni));
	for (int i = 1; i <= n; i ++) {
		cin >> x[i] >> v[i];
		shun[i] = shun[i-1] + v[i];
	}
	for (int i = n; i > 0; i --)
		ni[i] = ni[i+1] + v[i];
		
	long long ans = max(0LL, max(shun[n]-x[n], ni[1]-c+x[1]));
	memset(mx1, 0, sizeof(mx1));
	memset(mx2, 0, sizeof(mx2));
	for (int i = 1; i <= n; i ++) mx1[i] = max(mx1[i-1], shun[i] - 2*x[i]);
	for (int i = n; i > 0; i --) mx2[i] = max(mx2[i+1], ni[i] - 2*(c-x[i]));
	
	for (int i = 1; i <= n; i ++) 
		ans = max(ans, shun[i]-x[i]+mx2[i+1]);
	for (int i = n; i > 0; i --) 
		ans = max(ans, ni[i]-c+x[i]+mx1[i-1]);
		
	cout << ans << endl;	
	return 0;	
}

Measured memory_bytes: 4992
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  int n,h,w;
  cin >> n >> h >> w;
  cout << (n - h + 1) * (n - w + 1) << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  solve();
  return 0;
}

Measured memory_bytes: 256
data Suit = S|H|C|D deriving (Eq,Ord,Show,Read)

data Trump = Trump Suit Int deriving (Eq)

instance Show Trump where
	show (Trump suit rank) = (show suit) ++ " " ++ (show rank)

instance Ord Trump where
	(>) (Trump a x) (Trump b y)
	 |a==b = x>y
	 |otherwise = a>b
	(<) (Trump a x) (Trump b y)
	 |a==b = x<y
	 |otherwise = a<b
	(<=) (Trump a x) (Trump b y)
	 |a==b = x<=y
	 |otherwise = a<=b
	(>=) (Trump a x) (Trump b y)
	 |a==b = x>=y
	 |otherwise = a>=b
	 

readTrump :: String->Trump
readTrump xs = Trump (read (head xs:[]) :: Suit) (read (tail xs) :: Int)

quickSort :: (Ord a) => [a]->[a]
quickSort [] = []
quickSort xs = (smallerOrEqual xs) ++ [head xs] ++ (larger xs)
	where
	smallerOrEqual xs = quickSort $ filter (<= head xs) (tail xs)
	larger xs = quickSort $ filter (> head xs) xs
	
trumpComp :: [Trump]->[Trump]->[Trump]
trumpComp x [] = x
trumpComp (x:xs) yys@(y:ys)
	|x==y = trumpComp xs ys
	|x/=y = x : trumpComp xs yys

trumpList :: [Trump]
trumpList = [Trump x y|x<-[S,H,C,D],y<-[1..13]]

filterTrump :: [Trump]->[Trump]
filterTrump = trumpComp trumpList

main = getContents >>= putStr.unlines.map show.filterTrump.quickSort.map readTrump.tail.lines

Measured memory_bytes: 4120
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    REP(i, n){
        cin >> x[i] >> y[i];
    }

    map<pii, int> cnt;
    REP(i, n){
        REP(j, n){
            if(i==j) continue;
            cnt[{x[j]-x[i], y[j]-y[i]}]++;
        }
    }
    int maxx = 0;
    for(auto p: cnt)
        maxx = max(maxx, p.second);

    cout << n - maxx << endl;
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Linq;

class C {
    public static void Main() {
        var line = Console.ReadLine().Split();
        var n = int.Parse(line[0]);
        var a = int.Parse(line[1]);
        var x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var sum = n * a;
        var b = new long[sum + 1, n + 1];
        b[0, 0] = 1;
        foreach (var i in x)
            for (int j = sum; j >= i; --j)
                for (int k = 1; k <= n; ++k) b[j, k] += b[j - i, k - 1];
        var answer = Enumerable.Range(1, n).Sum(size => b[size * a, size]);
        Console.WriteLine(answer);
    }
}


Measured memory_bytes: 13332
-- Math Functions - Distance II

import Control.Monad
import Control.Applicative
import Text.Printf

main :: IO ()
main = do
  _  <- getLine
  [xs, ys] <- map (map read . words) <$> replicateM 2 getLine
  mapM_ (putStrLn . show . distance xs ys) [1, 2, 3, -1]

distance :: [Double] -> [Double] -> Double -> Double
distance xs ys (-1) = maximum . map abs $ zipWith (-) xs ys
distance xs ys p    = (** (1 / p)) . sum . map ((** p) . abs) $ zipWith (-) xs ys



Measured memory_bytes: 4480
from scipy.sparse import*
f=csgraph.johnson
n,m,l,*t=map(int,open(0).read().split())
m*=3
print(*f(f(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1,sep='\n')

Measured memory_bytes: 40756
#include <iostream>

using namespace std;

int main() {

	int n, m, count=0,city=0;

	cin >> n >> m;

	if (n < 1 || m < 1) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 1; i < n; i++) {
		count++;
	}
	for (int i = 1; i < m; i++) {
		city += count;
	}

	cout << city << endl;
	return 0;

}

Measured memory_bytes: 256
N, Y = map(int, input().split())

for i in range(Y // 10000 + 1):
    for j in range((Y - 10000 * i) // 5000 + 1):
        if ((i + j + (Y - 10000 * i - 5000 * j) // 1000 == N) and
                ((Y - 10000 * i - 5000 * j) // 1000 >= 0)):
            print(i, j, (Y - 10000 * i - 5000 * j) // 1000)
            quit()
print("-1 -1 -1")

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define f(i,x,n) for(ll i=x;i<n;i++)
#define rf(i,x,n) for(ll i = x; i >= n; i--)
#define all(c) c.begin(),c.end()
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 2e3 + 10; 
int main()
{   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  	int a,b,c,d;cin>>a>>b>>c>>d;
  	while(a>0 && c>0){
  		c -= b;
  		a -= d;
  	}
  	if(c<=0) cout<<"Yes";
  	else cout<<"No";
	return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int n = 0;
  for(int i = 1; i <= N; i++) {
    int m = 0;
    m += i/10000;
    m += i/1000 - i/10000 * 10;
    m += i/100 - i/1000 * 10;
    m += i/10 - i/100 * 10;
    m += i % 10;
    if(m >= A && m <= B) {
      n += i;
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 256
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#define ff  first
#define ss  second
#define pb  push_back
#define ll  long long
#define ld  long double
#define eb  emplace_back
#define ull unsigned long long
#define all(v) v.begin(), v.end()
#define rep(i,x,n)  for(int i=x;i<n;i++)
#define repr(i,x,n) for(int i=x;i>=n;i--)
#define bolt ios::sync_with_stdio(false)
using namespace std;

void IoI() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

int32_t main() {
	//IoI();
	bolt;
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, x, y; cin >> n >> x >> y;
	ll val = 0;
	map <int, int> m;
	rep (i, 1, n + 1) {
		rep (j, i + 1, n + 1) {
			val = min(abs(i - j), abs(x - i) + abs(y - j) + 1);
			m[val]++;
		}
	}
	rep (j, 1, n) {
		cout << m[j] << endl;
	}

	return 0;
}

Measured memory_bytes: 384
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

bool solve() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto S = s[2]-1;
    auto G1 = s[3]-1;
    auto G2 = s[4]-1;
    if (N == 0) return false;

    auto D = new int[][](N, N);
    foreach (i; 0..N) foreach (j; 0..N) D[i][j] = i == j ? 0 : 1 << 29;

    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        D[s[0]-1][s[1]-1] = s[2];
    }

    foreach (i; 0..N)
        foreach (j; 0..N)
            foreach (k; 0..N)
                D[j][k] = min(D[j][k], D[j][i] + D[i][k]);

    N.iota.map!(i => D[S][i] + D[i][G1] + D[i][G2]).reduce!min.writeln;

    return true;
}

void main() {
    while (solve()) {}
}



Measured memory_bytes: 3112
#include<stdio.h>

#define Max 100000

int parent(int i){
  return i / 2;
}

int left(int i){
  return 2 * i ;
}

int right(int i){
  return 2 * i + 1;
}


int main(){
  int h, i, A[Max + 1];

  scanf("%d", &h);
  for(i = 1 ; i <= h ; i++) scanf("%d", &A[i]);

  for(i = 1 ; i <= h ; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(parent(i) >= 1) printf("parent key = %d, ", A[parent(i)]);
    if(left(i) <= h) printf("left key = %d, ", A[left(i)]);
    if(right(i) <= h) printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }
 
  return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define P 1000000007
#define inf 1e18
vector<ll> adj[100005];
ll d[200005];
bool used[200005];
queue<ll> q;
void bfs(ll s)
{
    for (ll i = 0; i <= 100005; i++)
    {
        d[i] = inf;
        used[i] = false;
    }
    d[s] = 0;
    used[s] = true;

    q.push(s);
    while (!q.empty())
    {
        ll v = q.front();
        q.pop();
        for (ll i = 0; i < adj[v].size(); i++)
        {
            if (!used[adj[v][i]])
            {
                d[adj[v][i]] = d[v] + 1;
                used[adj[v][i]] = true;
                q.push(adj[v][i]);
            }
        }
    }
}
int main()
{
    ll n, i;
    cin >> n;
    ll a[n + 1];
    for (i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        adj[i + 1].push_back(x);
        //adj[x].push_back(i + 1);
    }
    bfs(1);
    if(d[2] == inf)
    cout<<"-1\n";
    else
    cout << d[2] << "\n";

    return (0);
}


Measured memory_bytes: 9952
import itertools

H,W,M=[int(i) for i in input().split(" ")]

target=[]
for i in range(M):
    target.append(tuple([int(j)-1 for j in input().split(" ")]))

target=set(target)

tate=[0 for i in range(H)]
yoko=[0 for i in range(W)]
for t in target:
    tate[t[0]]+=1
    yoko[t[1]]+=1



tate_max=max(tate)
yoko_max=max(yoko)

tate_max_ind=[]
for i,t in enumerate(tate):
    if t==tate_max:
        tate_max_ind.append(i)

yoko_max_ind=[]
for i,y in enumerate(yoko):
    if y==yoko_max:
        yoko_max_ind.append(i)

for iter in itertools.product(tate_max_ind,yoko_max_ind):
    if (iter in target)==False:
        print(tate_max+yoko_max)
        break

else:
    print(tate_max+yoko_max-1)


Measured memory_bytes: 88356
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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

long long n, k;
vector<long long> a;
vector<long long> f;

bool check(long long x) {
	long long cost = 0;
	for (long long i = 0; i <= n - 1; i++) {
		if (a[i]*f[i] <= x) continue;
		cost += ((a[i] * f[i] - x + f[i] - 1) / f[i]);
	}

	return cost <= k;
}


int main() {

	cin >> n >> k;
	a.resize(n); for (long long i = 0; i <= n - 1; i++) cin >> a[i];
	f.resize(n); for (long long i = 0; i <= n - 1; i++) cin >> f[i];

	sort(a.begin(), a.end());
	sort(f.begin(), f.end(), greater<long long>());

	long long lo = 0, hi = 0, ans = -1;

	for (int i = 0; i <= n - 1; i++) {
		hi += (a[i] * f[i]);
	}

	while (lo <= hi) {
		long long mid((lo + hi) >> 1);

		if (check(mid)) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}

	cout << ans;


	return 0;
}

Measured memory_bytes: 6360
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// Nの入力
		int N = sc.nextInt();
		
		// 3桁のパスワードのパターンを出力
		double pattern = Math.pow(N, 3);
		System.out.println(Integer.toString((int)pattern));
		sc.close();
	}
}


Measured memory_bytes: 21844
n, m, l = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(m)]
[print(*x) for x in [[sum(j*k for j,k in zip(x,y)) for y in zip(*B)] for x in A]]



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

string s;

int main(void){
	
	cin >> s;
	
	if(s.front() == s.back()){
	    int num = (int)s.size() - 2;
	    printf("%s\n", (num % 2) ? "Second" : "First");
	}
	else{
	    int num = (int)s.size() - 2;
	    printf("%s\n", (num % 2) ? "First" : "Second");
	}
	
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		String str = sc.next();
		
		switch (str) {
		case "A":
			System.out.println("T");
			break;
		case "C":
			System.out.println("G");
			break;
		case "T":
			System.out.println("A");
			break;
		case "G":
			System.out.println("C");
			break;

		default:
			break;
		}
	}
}


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

using namespace std;

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

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    int ans = a.back();
    rep(i,n-1)ans = gcd(ans, a[i]);
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#define REP(i, START, n, STEP) for(int i = START; i < (n); i += (STEP))
#define rep(i, n) REP(i, 0, n, 1)
using namespace std;

typedef long long int ll;

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

	if (n % 2 == 0) {
		cout << 0.5;
		return 0;
	}
	else {
		double m;
		m = (((double)n + 1) / 2) / n;
		cout << setprecision(10) << fixed << m;
		return 0;
	}
}


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


int main(){
  int n;
  char S[10001];
  cin>>n>>S;
  int k=strlen(S);
  for(int i=0;i<k;i++){
      S[i]+=n;
      if(S[i]>'Z')S[i]-=26;
  }
  cout<<S<<endl;
}

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

int main() {
	vector <int> x(3);
	rep(i,3) cin >> x[i];
	sort(x.begin(), x.end());
	int ans = 0;
	while (x[0] < x[2] - 1) {
		x[0] += 2;
		ans++;
	}
	while (x[1] < x[2] - 1) {
		x[1] += 2;
		ans++;
	}
	sort(x.begin(), x.end());
	if (x[0] < x[1]) ans += 2;
	if (x[1] < x[2]) ans++;
	cout << ans;
	return 0;
}

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

const int MAX = 200000;
const int INF = 1073741823; // 10^30-1、使わない辺とかに用いる

int main() {
	int N;
	static int A[MAX], B[MAX];
	cin >> N;
	for (int i = 0;i < N;i ++) {
		cin >> A[i] >> B[i];
	}
	int64_t operate = 0, operate2 = 0;
	int min = INF;
	for (int i = 0;i < N;i ++) {
		if (A[i] <= B[i]) {
			operate += B[i];
		} else {
			operate2 += B[i];
			if (min > B[i]) min = B[i];
		}
	}
	if (min == INF) { // 要は、全部同値
		cout << 0;
		return 0;
	}
	cout << operate + operate2 - min;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、とざん君は任意のA[i]<=B[i]の要素に対し、A[i]を1減らそうとするはず
その方が得だからね
また、げざん君は任意のA[i]<B[i]の要素にたいし、B[i]を1減らそうとするはず
その方が得だから
だから、まずA[i]<=B[i]の要素があった場合は確実にB[i]回の操作が行われる
だからまずこれらの操作の総和を取ろう
そして、げざん君はB[i]-A[i]で余った操作を利用して任意のA[i]>B[i]になっている要素をA[i]<B[i]にするはずだ
だから、次に考えるべきはその余った操作をA[i]-B[i]に振り分けて、最大何個取れるか
今余った操作回数をn、各要素のA[i]-B[i]をx, その時のA[i]をyとする
これはどう考えてもナップサック問題
と思ったが、よく考えれば1個の要素さえ切り捨てればそれ以外全部取れるような
なので最も少ないB[i]を除き全部取ってしまおうか、なんだO(N)じゃん
*/

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	vector<long long> a(3*N,0);
	int i;

	for (i=0;i<3*N;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	long long aw=0;
	for (i=N;i<3*N;i+=2){
		aw+=a[i];
	}
	cout<<aw<<endl;
	return 0;
}

Measured memory_bytes: 2560
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.conv;

void main() {
	auto c = readMatrix!int(3, 3);
	(check(c) ? "Yes" : "No").writeln;
}

bool check(int[][] a) {
	return a[0][0] == a[0][1] + a[1][0] - a[1][1]
		&& a[1][0] == a[1][1] + a[2][0] - a[2][1]
		&& a[0][1] == a[0][2] + a[1][1] - a[1][2]
		&& a[1][1] == a[1][2] + a[2][1] - a[2][2];
}

// ===================================

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (isBasicType!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

int ri() {
	return readAs!int;
}

Measured memory_bytes: 256
s=input()
n=len(s)

a=[None]*n
a[0]=int(s[0])


for i in range(n-1):
  a[i+1]=a[i]*10+sum(int(j) for j in s[:i+2])*(2**i)+int(s[i+1])*(2**i)

print(a[n-1])

Measured memory_bytes: 3060
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

#define rep(i, n)	for(int i=0;i<n;i++)
#define repn(i, n)	for(int i=1;i<=n;i++)
#define set(i, n)	memset(i, n, sizeof(i))

#define mx		1000007
#define pb		push_back
#define inf 	(1 << 30)

#define f	first
#define s 	second

using namespace std;

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

int w, h, n, mat[105][105];

void color(int x, int y, int c){
	repn(i, h){
		repn(j, w){
			if(c == 1 && j <= x) mat[i][j] = 1;
			if(c == 2 && j > x) mat[i][j] = 1;
			if(c == 3 && i <= y) mat[i][j] = 1;
			if(c == 4 && i > y) mat[i][j] = 1;
		}
	}
}

int solve(){
	int ret = 0;
	repn(i, h){
		repn(j, w){
			ret += !mat[i][j];
		}
	}
	return ret;
}

int main(){
	int x, y, a;
	scanf("%d %d %d", &w, &h, &n);
	rep(i, n){
		scanf("%d %d %d", &x, &y, &a);
		color(x, y, a);
	}
	printf("%d\n", solve());
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
vector<int> ipow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	ipow2.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1; ipow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	int INV = inverse(2);
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		ipow2[i]=mult(ipow2[i-1],INV);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}

const int N = 611;
int match[N];
int dp[N][N];
int dp2[N][N];
int n,k; 
int F[N];
int active;
int cnt[N][N];

int solve(int l, int r)
{
	if(dp[l][r]!=-1) return dp[l][r];
	if((r-l)%2==0) return 0;
	int ans=0;
	cnt[l][r]=r-l+1;
	for(int i=l;i<=r;i++)
	{
		if(match[i]!=-1)
		{
			int v=match[i];
			if(v>=l&&v<=r)
			{
				cnt[l][r]--;
			}
			else {return dp[l][r]=0;}
		}
	}
	assert(cnt[l][r]%2==0);
	ans=F[cnt[l][r]];
	return (dp[l][r] = ans);
}

int solve2(int l, int r)
{
	if(dp2[l][r]!=-1) return dp2[l][r];
	if((r-l)%2==0) return 0;
	int ans=solve(l,r);
	for(int i=l;i<r;i++)
	{
		ans=add(ans,MOD-mult(solve2(l,i),solve(i+1,r)));
	}
	return (dp2[l][r]=ans);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	memset(dp,-1,sizeof(dp)); memset(match,-1,sizeof(match)); memset(dp2,-1,sizeof(dp2));
	init(N);
	cin>>n>>k; n*=2; active=n;
	for(int i=0;i<k;i++)
	{
		int x,y; cin>>x>>y; x--; y--; active-=2;
		match[x]=y; match[y]=x;
	}
	F[0]=1;
	for(int i=2;i<N;i+=2)
	{
		F[i] = mult(fact[i], mult(ipow2[i/2], ifact[i/2]));
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if((j+i)%2==0) continue;
			//if((i==(j+1)%n)&&(i!=0)) continue;
			//cerr<<i<<' '<<j<<' '<<solve(i,j)<<' '<<solve2(i,j);
			//cerr<<' '<<cnt[i][j]<<' '<<F[active-cnt[i][j]]<<' '<<mult(solve2(i,j),F[active-cnt[i][j]])<<'\n';
			solve(i,j);
			ans=add(ans,mult(solve2(i,j),F[active-cnt[i][j]]));
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 4608
def main():
    H, W = map(int, input().split())
    if H == 1 or W == 1:
        print(1)
        return

    ans = 0
    ans += ((W + 1) // 2) * ((H + 1) // 2)
    ans += (W // 2) * (H // 2)
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <random>
#include <map>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)
#define YN(f) f?cout<<"YES"<<endl:cout<<"NO"<<endl;
#define yn(f) f?cout<<"Yes"<<endl:cout<<"No"<<endl;

int ans=1100000000;
int a[200000];

signed main(){
	int n,k;cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=0;i+k-1<n;i++){
		ans=min(ans,a[i+k-1]-a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
struct UnionFind {vector<int> par, cnt;
    UnionFind(int NV) { par.clear(); cnt.resize(NV, 1); rep(i, 0, NV) par.push_back(i); }
    void reset() { rep(i, 0, cnt.size()) cnt[i] = 1; rep(i, 0, par.size()) par[i] = i; }
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) {x = operator[](x); y = operator[](y);
        if (x != y) par[x] = y, cnt[y] += cnt[x];}};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, M;
int A[101], B[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, M) cin >> A[i] >> B[i], A[i]--, B[i]--;

    int ans = 0;
    rep(i, 0, M) {
        UnionFind uf(N);
        rep(j, 0, M) if (j != i) uf(A[j], B[j]);
        int c = 0;
        rep(j, 0, N) if (j == uf[j]) c++;
        if (1 < c) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256