akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		
		int n=sc.nextInt();
		int a[]=new int[n];
		int sum=0;
		
		for(int i=0;i<n;i++) {
			a[i]=sc.nextInt();
			
		}
		Arrays.sort(a);
		for(int i=0;i<n-1;i++) {
			sum+=a[i];
		}
		
		System.out.println(a[n-1]<sum?"Yes":"No");
	}
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





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


string y = ":(";
string n = "Yay!";

bool ok(vector<int> v, int k) {
	if(v[4] - v[0] > k) return true;
	return false;
}
int main() {

	vector<int> a(5);
	for(auto &x: a) cin >> x;
	int k;
	cin >> k;
	if(ok(a, k)) cout << y << endl;
	else cout << n << endl;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
main = do
    argMatrix <- getIntMatrix
    putStrLn $ solve argMatrix


solve :: [[Integer]] -> String
solve argMatrix = if aMod > a
                  then "No"
                  else "Yes" 
    where
        n = head $ head argMatrix
        a = head $ last argMatrix
        aMod = mod n 500

Measured memory_bytes: 380
#include<iostream>
    #include<cmath>
    using namespace std;
     
    int main()
    {
      int n,t,a;
      cin>>n>>t>>a;
      int h[n];
      for(int i=0; i<n; i++)
      {
        cin>>h[i];
      }
      double mini=0, minh= abs(t-h[0]*0.006 -a);
      for(int i=1; i<n; i++)
      {
        if(abs(t-h[i]*0.006 -a) < minh)
        {
          minh = abs(t-h[i]*0.006 -a);
          mini = i;
        }
      }
      cout<<mini+1<<endl;
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

vector<int> cul_day(vector<int> cs,vector<int> ss,vector<int> t, int nd){
	vector<int> lasts(26,nd);
	rep(i, nd){
		lasts[t[i]]=nd-i-1;
	}
	rep(i,26){
		cout << lasts[i] << " ";
		ss[i] -= cs[i]*(1+lasts[i]);
	}
	cout << endl;
	return ss;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  int d;
  cin >> d;
  if(d % 1000 == 0){
	  cout << 0 << endl;
  }else{
	  cout << 1000-(d%1000) <<endl;
  }
  return 0;
}


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

int main(){
    int n;
    while(cin>>n,n){
        vector<int> a;
        for(int i=0,t;i<n;++i){
            cin>>t;
            a.push_back(t);
        }
        string s,ans;
        cin>>s;
				
				string TBL;
				for(char i='a';i<='z';++i) TBL += i;
				for(char i='A';i<='Z';++i) TBL += i;
				
        for(int i=0;i<s.size();++i){
            int x=a[i%a.size()];
            int p=TBL.find(s[i]);
            ans += TBL[(p-x+52)%52];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1224
import sys
sys.stdin.readline()
A = []
ans = []
operations = {'0': A.append, '1': lambda x: ans.append(A[int(x)]), '2': A.pop}
for query in sys.stdin:
    operations[query[0]](query[2:] if query[2:] else -1)
sys.stdout.writelines(ans)


Measured memory_bytes: 19960
#include<iostream>
using namespace std;
//セグ木
int GCD(int x,int y){
	return x%y==0?y:GCD(y,x%y);
}
class segment{
typedef int segClass;
public:
	segClass *tree;
	segClass u;
	int height,treeSize,dataSize;
	segment(long long int length,segClass unit){
		long long int pre = 1;
		height=1;
		u=unit;
		
		while(pre<length){
			pre*=2;
			height++;
		}
		
		treeSize = pre*2-1;
		dataSize = pre;
		tree = new segClass[treeSize];
		
		for(int i=0;i<dataSize;i++)set(i,unit);
		construct();

	}
	void replace(long long int index, segClass value){
		tree[treeSize-dataSize+index]=value;
		index=treeSize-dataSize+index+1;
		while(index>0){
			index/=2;
			tree[index-1]=f(tree[index*2-1],tree[index*2]);
		}
	}
	segClass result(long long int l,long long int r){return result(l,r,0,1<<(height-1),0);}
	segClass result(long long int l,long long int r,int s,int len,long long int ind){
		if(l==r)return get(l);
		else if(l==s && r==s+len-1)return tree[ind];
		len/=2;
		
		segClass res=u;
		long long int L=s,R=s+len-1;
		if(!(r<L || R<l))res=f(result(max(L,l),min(R,r),L,len,ind*2+1),res);
		L+=len;R+=len;
		if(!(r<L || R<l))res=f(result(max(L,l),min(R,r),L,len,ind*2+2),res);
		return res;
	}
	
	void construct(){for(int i=treeSize-2;i>0;i-=2)tree[i/2]=f(tree[i],tree[i+1]);}
	void set(long long int index, segClass value){tree[treeSize-dataSize+index]=value;}
	segClass get(long long int index){return tree[treeSize-dataSize+index];}
	
	segClass f(segClass a,segClass b){
		if(a==0)return b;
		else if(b==0)return a;
		else return GCD(a,b);
	}
};

int main(){
	int N,A,ans=1;
	cin>>N;
	segment seg(N,0);

	for(int i=0;i<N;i++){
		cin>>A;
		seg.set(i,A);
	}
	
	seg.construct();
	for(int i=1;i<N-1;i++)ans=max(ans,GCD(seg.result(0,i-1),seg.result(i+1,N-1)));
	ans=max(ans,seg.result(1,N-1));
	ans=max(ans,seg.result(0,N-2));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4716
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

vector<ll> res;

void enum_divisors(long long N) {
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N / i != i) res.push_back(N / i);
        }
    }
    // 小さい順に並べ替える
    sort(res.begin(), res.end());
}

vector<ll> resi;

void enum_divisorsi(long long N) {
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            resi.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N / i != i) resi.push_back(N / i);
        }
    }
    // 小さい順に並べ替える
    sort(resi.begin(), resi.end());
}

int main() {
    ll n;
    cin >> n;
    enum_divisors(n);
    enum_divisorsi(n - 1);
    ll ans = 0;
    ans += (ll)sz(resi);
    ans--;

    rep(i, sz(res)) {
        ll ri = res[i];
        ll cnt = res[i];
        if(ri==1) continue;
        bool flag = false;
        while (cnt <= n && flag == false&&n%cnt==0) {
            if ((n / cnt) % ri == 1) flag = true;
            cnt *= ri;
        }
        if (flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h> 

int main(void){ 
    int A,B,C,D;
    scanf("%d", &A);

    B = 0;
    D = 0;
    int a[A];

    for(int i=0; i < A; i++){
       scanf("%d" , &a[i]);
       B += a[i];
    }

   C = B*10/A;
   if(C>=0){
       C = (C+5)/10;
   }else{
       C = (C-5)/10;
   }
   
   for(int i=0; i < A; i++){
      
      D += (a[i] - C)*(a[i] - C) ;
   }

   printf("%d", D);
}

Measured memory_bytes: 128
n = int(input())
happiness_hash = {}
for i in range(n):
    a, b = tuple(map(int, input().split(' ')))
 
    happiness_hash[i] = (a, b)
 
sorted_happiness = sorted(happiness_hash.items(), key = lambda x : x[1][0] + x[1][1], reverse = True)
 
total = 0
i = 0
for k, v in sorted_happiness:
    happiness, selected = (0, k)
    if i % 2 == 0:
        happiness = v[0]
        total += happiness
    else:
        happiness = v[1]
        total -= happiness
    i += 1
 
print(total)

Measured memory_bytes: 36880
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N; cin >> N;
    ll ans = 0;
    repi(i,1,N+1) {
        if(i % 3 == 0) continue;
        if(i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
double R,G;

int main(int argc, char const *argv[])
{
    cin>>R>>G;
    cout<<2*G-R<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
public static void main(String[]  args){
 Scanner stdIn = new Scanner(System.in);
 
 int d = stdIn.nextInt();
 int t = stdIn.nextInt();
 int s = stdIn.nextInt();

if ((double)d/s<=t){System.out.print("Yes");}
else if ((double)d/s>t) {System.out.print("No");}

  }
}


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

int main()
{
    int n, m, dig = 0;
    cin >> n;
    m = n;
    while (n > 0)
    {
        dig += n % 10;
        n = n / 10;
    }
    if (m % dig == 0)
    {
        cout << "Yes"
             << "\n";
    }
    else
    {
        cout << "No"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*
import kotlin.math.acos
import kotlin.math.cos
import kotlin.math.round
import kotlin.math.sin

fun main(args: Array<String>) {
    val n = readLong()
    val mod = 1000000007L

    var ans = (10L.powMod(n, mod) + 8L.powMod(n, mod) - 9L.powMod(n, mod) - 9L.powMod(n, mod)) % mod
    if (ans < 0) ans += mod
    println(ans)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun Long.powMod(k: Long, mod: Long): Long {
    var r = 1L
    var n = this
    var kk = k
    while (kk > 0) {
        if (kk and 1 == 1L) {
            r = (r * n) % mod
        }
        n = (n * n) % mod
        kk = kk shr 1
    }
    return r
}

Measured memory_bytes: 34396
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

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

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b,q;
    cin>>a>>b>>q;
    vi s(a+2),t(b+2);
    s[0]=t[0]=-inf;
    REP(i,1,a)cin>>s[i];
    REP(i,1,b)cin>>t[i];
    s[a+1]=t[b+1]=inf;
    while(q--){
        int x;
        cin>>x;
        int sa=lower_bound(all(s),x)-s.begin();
        int sb=sa-1;
        int ta=lower_bound(all(t),x)-t.begin();
        int tb=ta-1;
        int ss[]={sa,sb};
        int tt[]={ta,tb};
        int ans=inf;
        rep(i,2){
            rep(j,2){
                ans=min({ans,abs(x-s[ss[i]])+abs(s[ss[i]]-t[tt[j]]),abs(x-t[tt[j]])+abs(t[tt[j]]-s[ss[i]])});
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2944
N ,L = map(int,input().split())
lis = []
for i in range(N):
  lis.append(L+i)

mini = 100
index = 0
for i in range(N):
  if mini > abs(lis[i]):
    mini = abs(lis[i])
    index = i

print(sum(lis)-lis[index])

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

int main() {
  int K;
  cin >> K;
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
             1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  cout << a[K - 1] << endl;
  return 0;
}

Measured memory_bytes: 3588
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max();

// RMQ
template<class T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree(int n_ = 0) : n(n_){
        n = 1;
        while(n < n_) n <<= 1;
        dat.resize(n*2, inf);
    }
    T query(int v, int w, int l, int r){
        if(v >= (int)dat.size()) return inf;
        if(r - l == w) return dat[v];
        if(r <= l) return inf;
        T res = inf;
        res = std::min(res, query(v*2, w/2, l, min(r, w/2)));
        res = std::min(res, query(v*2+1, w/2, max(0, l-w/2), r-w/2));
        return res;
    }
    void update(int i, T x){
        i += n;
        dat[i] = x;
        while(i != 1){
            dat[i>>1] = min(dat[i], dat[i^1]);
            i /= 2;
        }
    }
    T query(int l, int r){
        return query(1,n,l,r);
    }
    size_t size() const {
        return n;
    }
};

int main(){
    fastios();
    int n, q;
    while(cin >> n >> q){
        SegmentTree<int> st(n);
        rep(i,q){
            char c;
            int x, y;
            cin >> c >> x >> y;
            if(c == '0'){
                st.update(x,y);
            } else {
                cout << st.query(x,y+1) << endl;
            }
        }
    }
}

Measured memory_bytes: 2052
#include <stdio.h>
#include <inttypes.h>

int main(void)
{
    const uint_fast8_t g[] = { 0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
    uint_fast8_t       x, y;
    scanf("%" SCNuFAST8 " %" SCNuFAST8, &x, &y);
    puts(g[x] == g[y] ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Numerics;  // 参照

class _Class
{
  void _Do()
  {
    string N = Split.strings()[0];

    int a = N[0]-'0'-1;
    int b = N.Length - 1;

    int c = 0;
    for (int i = 0; i < N.Length; i++)
      c += (N[i]-'0');


    if (c > a + b * 9)
      Console.WriteLine(c);
    else
      Console.WriteLine( a + b * 9);
  }

  //
  static void Main(string[] args)
  {
    _(args);
    new _Class()._Do();
  }
  [Conditional("DEBUG")]
  static void _(string[] args)
  {
    if (args.Length != 0 && File.Exists(args[0]))
      Console.SetIn(new StreamReader(args[0]));
    else
      Console.Error.WriteLine("in");
  }
}

static class Split
{
  // 1
  public static string[] strings()
  {
    return Console.ReadLine().Split();
  }


  // [2.1] -2,147,483,648 ~ +2,147,483,647
  public static int[] ints()
  {
    var _s = Console.ReadLine().Split();

    var x = new int[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = int.Parse(_s[i]);

    return x;
  }

  // [2.2] 
  // -9,223,372,036,854,775,808 ~ 
  // +9,223,372,036,854,775,807
  public static long[] longs()
  {
    var _s = Console.ReadLine().Split();

    var x = new long[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = long.Parse(_s[i]);

    return x;
  }

  public static BigInteger[] bigs()
  {
    var _s = Console.ReadLine().Split();

    var x = new BigInteger[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = BigInteger.Parse(_s[i]);

    return x;
  }
}

Measured memory_bytes: 13140
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) throws Exception{    
        Scanner sc = new Scanner(System.in);
        // code
       
        String s = sc.next();
        
        int ans = func(0, s, s.length());
        
        
        if(ans  >= 1){
        	System.out.println("YES");
        }else{
        	System.out.println("NO");
        }
        
        sc.close();
    }
        
    static int func(int i, String s, int len){
    	int ans = 0;
    	
    	if(len - i <= 7){
    		if(len - i == 5){
            	if(s.substring(i, i+5).equals("dream")) ans += 1;
            	if(s.substring(i, i+5).equals("erase")) ans += 1;
            }else if(len - i == 6){
            	if(s.substring(i, i+6).equals("eraser")) ans += 1;
            }else if(len - i == 7){
            	if(s.substring(i, i+7).equals("dreamer")) ans += 1;
            }
    	}else if(s.substring(i, i+5).equals("dream")){
    		ans += func(i+5, s, len);
    		if(s.substring(i, i+7).equals("dreamer")) ans += func(i+7, s, len);
    	}else if(s.substring(i, i+5).equals("erase")){
    		ans += func(i+5, s, len);
    		if(s.substring(i, i+6).equals("eraser")) ans += func(i+6, s, len);
    	}
    	return ans;
    }
    
    
    
    
 
}

Measured memory_bytes: 18868
N = int(input())
A = list(map(int, input().split()))
sa = sum(A)
last = A[-1]
count = last
root = 1
for i in range(N):
  sa -= A[i]
  if root <= A[i]:
    print(-1)
    break
  elif root-A[i] > sa:
    root = sa + A[i]
  count+=root
  root = (root-A[i])*2
else:
  if count == 0 or root < last:
    count = -1
  print(count)


Measured memory_bytes: 20076
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int N;
    string S, T, ans;

    cin >> N >> S >> T;

    rep(i,N) {
        ans += S.substr(i,1) + T.substr(i,1);
    }

    cout << ans << endl;

    return 0;
    
}

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

int maze[12][12];
static const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

void printTable(int a[12][12]) {
	for (int i = 0; i < 12; i++) {
		for (int j = 0; j < 12; j++) {
			cout << a[i][j];
		}
		cout << endl;
	}
}

void dfs(int y, int x) {
	maze[y][x] = 0;
	for (int i = 0; i < 4; i++) {
		if (0 <= dx[i] + x && dx[i] + x < 12 && 0 <= dy[i] + y && dy[i] + y < 12 && maze[y + dy[i]][x + dx[i]] == 1) {
			dfs(y + dy[i], x + dx[i]);
		}
	}
}


int main()
{
	string s;
	while (cin>>s) {
		//memset(maze, 0, sizeof(maze));
		if (s.size() == 0)break;//if(cin.eof())break;
		//1 line 
		for (int i = 0; i < 12; i++) {
			maze[0][i] = s[i] - '0';
		}
		//2-12 line
		for (int i = 1; i < 12; i++) {
			cin >> s;
			for (int j = 0; j < 12; j++) {
				maze[i][j] = s[j] - '0';
			}
		}
		int ans = 0;
		//cout << "=======dfs???=======" << endl;
		//printTable(maze);
		//cout << "===================" << endl;
		//dfs
		for (int y = 0; y < 12; y++) {
			for (int x = 0; x < 12; x++) {
				if (maze[y][x] == 1) {
					dfs(y, x);
					ans++;
				}
			}
		}
		cout << ans << endl;
		//cout << "=======dfs???=======" << endl;
		//printTable(maze);
		//cout << "===================" << endl;
	}



	return 0;
}

Measured memory_bytes: 3040
#include<iostream>
#include<algorithm>
using namespace std;
long long mod=1e9+7;
long long  a[300009];
long long f[10];
bool cmp(long long x,long long y) {
	return abs(x)<abs(y);
}
bool cmp1(long long x, long long y){
	return x>y;
}
int main() {

	long long n,m;
	cin>>n>>m;
	for(long long i=1; i<=n; i++) {
		cin>>a[i];
		if(a[i]>=0) f[1]++;
		else f[2]++;
	}
	long long l=1,r=n;
	long long  ans=1;
	if(!f[1]&&m%2==1) {
		sort(a+1,a+1+n,cmp);
		for(long long i=1; i<=m; i++) {
			ans=a[i]*ans%mod;
		}
	} else {
		sort(a+1,a+1+n,cmp1);
		while(m>0) {
			if(m%2) ans=ans*a[l]%mod,l++,m--;
			else if(m>=2) {
				if(a[l]*a[l+1]>=a[r]*a[r-1]) {
					ans=ans*a[l]%mod*a[l+1]%mod;
					l+=2;
					m-=2;
				} else {
					ans=ans*a[r-1]%mod*a[r]%mod;
					r-=2;
					m-=2;
				}
			}
		}
	}
	cout<<(ans%mod+mod)%mod<<endl;
	return 0;
}



Measured memory_bytes: 4652
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
struct card{
	char suit;
	int x;
}a[100000],b[100000];

void merge(card T[],int x,int y){
	if (y-x>1){
		int m=(x+y)/2;
		int p=x,q=m,i=x;
		merge(T,x,m);
		merge(T,m,y);
		while(p<m||q<y){
			if (q>=y||(p<m&&b[p].x<=b[q].x)) T[i++]=b[p++];
			else T[i++]=b[q++];
		}
		for (int i=x;i<y;i++) b[i]=T[i];
	}
}
void msort(int x,int y){
	card c[y-x];
	merge(c,x,y);
}
int part(int p,int r){
	card x=a[r];
	int i=p-1;
	for (int j=p;j<r;j++)
		if(a[j].x<=x.x) swap(a[++i],a[j]);
	swap(a[i+1],a[r]);
	return i+1;
}
void qsort(int x,int y){
	if (y>x){
		int q=part(x,y);
		qsort(x,q-1);
		qsort(q+1,y);
	}
}
main(){
	int n,xx;char ch[2];
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		scanf("%s%d",ch,&xx);
		a[i].suit=b[i].suit=ch[0];
		a[i].x=b[i].x=xx;
	}
	msort(0,n);
	qsort(0,n-1);
	bool iss=true;
	for (int i=0;i<n;i++){
		if (a[i].suit!=b[i].suit){
			iss=false;
			break;
		}
	}
	if (iss) printf("Stable\n");
	else printf("Not stable\n");
	for (int i=0;i<n;i++) printf("%c %d\n",a[i].suit,a[i].x);
}


Measured memory_bytes: 5468
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
 cin>>n;
 long long int i,a[n+1],w=0,b[n];
for(i=0;i<n+1;i++){
    cin>>a[i];
}
for(i=0;i<n;i++){
    cin>>b[i];
}
long long int ans=0;
for(i=0;i<(n);i++){
    if(b[i]<=(a[i]+a[i+1])){
       if(b[i]>=a[i]) a[i+1]-=(b[i]-a[i]);
        ans+=b[i];
    }
    else{
        ans+=(a[i]+a[i+1]);
        a[i+1]=0;
        b[i]-=(a[i]+a[i+1]);
    }
}
cout<<ans<<endl;
  return 0;
}


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

using namespace std;

char s[1500010];
int n;
int all, bll;
char cll;
int st, en;
int len;
char a[1000010];

int main(void)
{
	scanf("%s", a);
	scanf("%d", &n);
	
	len = strlen(a);
	
	for(int i = 500000 ; i < 500000 + len ; i++)
	{
		s[i] = a[i - 500000];
	}
	
	st = 500000;
	en = 500000 + len;
	
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%d", &all);
		
		if(all == 1)
		{
			swap(st, en);
		}
		
		else
		{
			scanf("%d %c", &bll, &cll);
			
			if(st > en)
			{
				if(bll == 1)
					s[st++] = cll;
				
				else
					s[--en] = cll;
			}
			
			else
			{
				if(bll == 1)
					s[--st] = cll;
				
				else
					s[en++] = cll;
			}
		}
	}
	
	if(st > en)
	{
		for(int i = st - 1 ; i >= en ; i--)
			printf("%c", s[i]);
	}
	
	else
	{
		for(int i = st ; i < en ; i++)
			printf("%c", s[i]);
	}
	
	return 0;
}

Measured memory_bytes: 896
a=int(input())
b=int(input())
c=int(input())
x=int(input())
d=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k==x:
                d+=1
print(d)

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    vector<int> S(n+1);
    S[0] = 0;
    rep(i, n) S[i+1] = (S[i] + A[i] - 1) % k;
    map<int, int> mp;
    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans += mp[S[i]];
        mp[S[i]]++;
        if (i >= k-1) mp[S[i-(k-1)]]--; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
        long sum = 0, count1 = 0;
        for(int i = 0 ; i < n ; i++) {
            sum += a[i];
            if(i % 2 == 0 && sum <= 0) {
                count1 += Math.abs(sum) + 1;
                sum = 1;
            } else if(i % 2 == 1 && sum >= 0) {
                count1 += sum + 1;
                sum = -1;
            }
        }
        
        sum = 0;
        long count2 = 0;
        for(int i = 0 ; i < n ; i++) {
            sum += a[i];
            if(i % 2 == 0 && sum >= 0) {
                count2+= sum + 1;
                sum = -1;
            } else if(i % 2 == 1 && sum <= 0) {
                count2 += Math.abs(sum) + 1;
                sum = 1;
            }
        }
        System.out.println(Math.min(count1, count2));
    }
}


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

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

	int r;
	int s = 0;
	r = x;
	while(r % 10 != 0){
		s += r % 10;
		r = r / 10;
	}

	if(x % s == 0){
		std::cout << "Yes" << std::endl;
	}
	else{
		std::cout << "No" << std::endl;
	}

	return 0;
}



Measured memory_bytes: 256
#!/user/bin/env pypy3
import sys


def fast_input():
    return sys.stdin.readline()[:-1]


def solve(c_500: int, c_100: int, c_50: int, amount: int) -> int:
    combination_count = 0
    for i_500 in range(c_500 + 1):
        for i_100 in range(c_100 + 1):
            for i_50 in range(c_50 + 1):
                total_amount = i_500 * 500 + i_100 * 100 + i_50 * 50
                if total_amount == amount:
                    combination_count += 1
    return combination_count


def main():
    c_500 = int(fast_input())
    c_100 = int(fast_input())
    c_50 = int(fast_input())
    amount = int(fast_input())
    result = solve(c_500, c_100, c_50, amount)
    print(result)


main()


Measured memory_bytes: 9184
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
 
int main()
{
	int a,b;
	bool first = true;	
	for(;;){
		cin>>a>>b;		
		if(a==0) return 0;
		if(!first)
            		cout << endl;
       		else
            		first = false;
		if(a%4!=0) a=a-(a%4)+4;
		if((a%100==0)&&(a%400!=0)) a+=4;
		bool na=true;
		for(int i=a;a<=b;a=a+4){
			if((a%100==0)&&(a%400!=0)) continue;
			cout << a << endl;
			na=false;
		}
		if(na) cout<<"NA"<<endl;
	}
}

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

using namespace std;

const double eps = 1e-10;

struct P {
  double x, y;
  P(double x = 0.0, double y = 0.0): x(x), y(y) {}
};

bool inTri(P p[3], P a) {
  double dx[2], dy[2];
  double area_p, area_a = 0.0;

  for (int i = 0; i < 2; i++) {
    dx[i] = p[i].x - p[2].x;
    dy[i] = p[i].y - p[2].y;
  }

  area_p = abs(dx[0] * dy[1] - dx[1] * dy[0]) / 2.0;

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 2; j++) {
      dx[j] = p[(i + j) % 3].x - a.x;
      dy[j] = p[(i + j) % 3].y - a.y;
    }

    area_a += abs(dx[0] * dy[1] - dx[1] * dy[0]) / 2.0;
  }

  return area_a - area_p < eps;
}

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

  P pp[3], pk, ps;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> pp[j].x >> pp[j].y;
    }
    cin >> pk.x >> pk.y >> ps.x >> ps.y;

    bool in_k = inTri(pp, pk), in_s = inTri(pp, ps);
    if ((in_k && !in_s) || (!in_k && in_s)) {
      cout << "OK\n";
    } else {
      cout << "NG\n";
    }
  }

  return 0;
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i <= (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;

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

int main()
{
  int K;
  ll sum = 0;
  cin >> K;
  rep(i, K)
      rep(j, K)
          rep(k, K)
  {
    sum += gcd(gcd(i, j), k);
  }
  cout << sum << endl;
  return 0;
}

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

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

    map<string, int> mp;
    for (int i = 0; i < n; i++) {
        char op[20], s[20];
        scanf("%s %s", op, s);

        if (!strcmp(op, "find")) {
            cout << (mp[s] ? "yes" : "no") << endl;
        }
        else mp[s]++;
    }

    return 0;
}



Measured memory_bytes: 47520
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        H: usize,
        W: usize,
        Cs: [usize; 2],
        Ds: [usize; 2],
        Ss: [String; H],
    }

    let start = ((Cs[0] - 1) as isize, (Cs[1] - 1) as isize);
    let goal = ((Ds[0] - 1) as isize, (Ds[1] - 1) as isize);

    // 必要なワープ回数の最小値
    let mut warp_cnt: Vec<Vec<i64>> = Vec::new();
    for _h in 0..H {
        let arr = vec![std::i64::MAX; W];
        warp_cnt.push(arr);
    }

    let mut queue: VecDeque<(isize, isize)> = VecDeque::new();
    queue.push_back(start);
    warp_cnt[start.0 as usize][start.1 as usize] = 0;

    let dhws: Vec<(isize, isize)> = vec![(0, 1), (0, -1), (-1, 0), (1, 0)];
    let ds_magic: Vec<isize> = vec![-2, -1, 0, 1, 2];

    // WAで気付いたことメモ (21:56)
    // まず、歩き → 魔法 → 歩き →の順にFIFOでキューに入れると、まず魔法で行った後歩いて更新することになって、LTE
    // かと言って、歩き歩き歩き魔法魔法…の順に入れていくと、最後が魔法になって歩きで行けるはずのに余分にワープしている…?

    while !queue.is_empty() {
        let node: (isize, isize) = queue.pop_front().unwrap();

        for &(dh, dw) in dhws.iter() {
            let next_h = node.0 + dh;
            let next_w = node.1 + dw;


            if 0 <= next_h && next_h < H as isize && 0 <= next_w && next_w < W as isize {
                let next_is_road = &Ss[next_h as usize][next_w as usize..(next_w + 1) as usize] ==
                    ".";
                if !next_is_road {
                    continue;
                }

                let new_cnt = warp_cnt[node.0 as usize][node.1 as usize];
                let old_cnt = warp_cnt[next_h as usize][next_w as usize];

                if new_cnt < old_cnt {
                    // このnodeに行く甲斐がある
                    warp_cnt[next_h as usize][next_w as usize] = new_cnt;

                    // 魔法より歩き優先
                    queue.push_front((next_h, next_w));
                }
            }
        }

        // 魔法で行く場合
        for dh in ds_magic.iter() {
            for dw in ds_magic.iter() {

                let next_h = node.0 + dh;
                let next_w = node.1 + dw;


                if 0 <= next_h && next_h < H as isize && 0 <= next_w && next_w < W as isize {
                    let next_is_road =
                        &Ss[next_h as usize][next_w as usize..(next_w + 1) as usize] == ".";
                    if !next_is_road {
                        continue;
                    }

                    let new_cnt = warp_cnt[node.0 as usize][node.1 as usize] + 1;
                    let old_cnt = warp_cnt[next_h as usize][next_w as usize];

                    if new_cnt < old_cnt {
                        // このnodeに行く甲斐がある
                        warp_cnt[next_h as usize][next_w as usize] = new_cnt;
                        queue.push_back((next_h, next_w));
                    }
                }
            }
        }
    }

    let ans_cand = warp_cnt[goal.0 as usize][goal.1 as usize];
    let ans = if ans_cand == std::i64::MAX {
        -1
    } else {
        ans_cand
    };
    println!("{}", ans);
}


Measured memory_bytes: 12268
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	    // input A B
        // B 個の差込口を確保するのに A 個の差込口があるタップを何個用意すればよいか出力せよ
        // 4 10 -> 3 (10 - 1) / (4 - 1)
        // 8 9 -> 2 (9 - 1) / (8 - 1)
        // 8 8 -> 1 (8 - 1) / (8 - 1)
        Scanner sc = new Scanner(System.in);
        int numA = sc.nextInt();
        int numB = sc.nextInt();
        int retNum = (numB - 1) / (numA - 1);
        if((numB - 1) % (numA - 1) > 0){retNum++;}
        System.out.println(retNum);
    }
}


Measured memory_bytes: 23764
N = gets.to_i
A = gets.split.map(&:to_i)

A.unshift 0
(1..N).each do |i|
  A[i] += A[i - 1]
end

def calc(iP, iQ, iR) 
  l, h = [A[iP], A[iQ] - A[iP], A[iR] - A[iQ], A[N] - A[iR]].minmax
  h - l
end

def canMoveNext(s, f, i)
  return false if i + 1 == f
  (2 * A[i + 1] - A[f] - A[s - 1]).abs < (2 * A[i] - A[f] - A[s - 1]).abs
end

iP = 1
iR = 3
ans = calc(1, 2, 3)
(2..(N - 2)).each do |iQ|
  while canMoveNext(1, iQ, iP)
    iP += 1
  end
  while canMoveNext(iQ + 1, N, iR)
    iR += 1
  end 
  tmp = calc(iP, iQ, iR)
  ans = tmp if tmp < ans 
end
puts ans


Measured memory_bytes: 21516
#include <stdio.h>

int
main(void)
{
    int i, j, N, A[101], min, tmp, count;
    
    scanf("%d", &N);
    for(i = 0; i < N; ++i)
        scanf("%d", A + i);
    
    count = 0;
    for(i = 0; i < N; ++i) {
        min = i;
        for(j = i; j < N; ++j) {
            if(A[j] < A[min]) min = j;
        }
        if(i != min) {
            tmp = A[i];
            A[i] = A[min];
            A[min] = tmp;
            count++;
        }
    }
    for(i = 0; i < N-1; ++i)
        printf("%d ", A[i]);
    printf("%d\n%d\n", A[N-1], count);
}



Measured memory_bytes: 2100
def process():
    l = {}
    N = int(input().rstrip())
    for i in range(N):
        s =  input().rstrip()
        k = s[0]
        if not k in 'MARCH':
            continue

        if k in l:
            l[k] = l[k] + 1
        else:
            l[k] = 1

    if len(l) < 3:
        return 0

    num = 0
    march = ''.join(l.keys())
    for i1 in range(0, len(march)):
        k = march[i1]
        i1_num = l[k]
        for i2 in range(i1 + 1, len(march)):
            k = march[i2]
            i2_num = l[k]

            for i3 in range(i2 + 1, len(march)):
                k = march[i3]
                i3_num = l[k]
                num = num + i1_num * i2_num * i3_num

    return num

result = process()
print(result)


Measured memory_bytes: 3188
import static java.lang.Math.abs;
import java.util.Scanner;

/**
 *
 * @author Owner
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        int a,b,x;
        
        x=sc.nextInt();
        a=sc.nextInt();
        b=sc.nextInt();
        
        if(abs(x-a)<abs(x-b)){
            System.out.println("A");
        }
        else{
            System.out.println("B");
        }
    }
    
}

Measured memory_bytes: 23760
#include <bits/stdc++.h>
#define For(i,l,r) for (register int i=l; i<=r; i++)
using namespace std;
typedef unsigned long long LL;
typedef signed long long ll;
template <typename T>
inline void read(T &x) {
	char c = getchar(); int w = 1; x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main() {
	LL n;
	cin >> n;
	cout << n*(n-1)/2;
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
using namespace std;
int a[100005],b[100005];
int main() {
	int n; ll ans=0;
	cin>>n;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,n)cin>>b[i];
	rep(i,0,n)
		if(b[i]!=0) {
			if(b[i]<=a[i]) ans+=b[i],a[i]-=b[i],b[i]=0;
			else if(b[i]<=a[i]+a[i+1]){
				ans+=b[i]; b[i]-=a[i]; a[i+1]-=b[i];
				a[i]=0; b[i]=0;
			}
			else ans+=a[i]+a[i+1],a[i]=a[i+1]=0;
		}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};


int M_N = 199999;

vector<LL> fact;
vector<LL> inver(M_N+1);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=M_N;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[M_N]=fpow(fact[M_N],mod-2);
    for(int i=M_N-1;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 

int main(){
    int n,s;cin >> n >> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<LL>> dp(n+1,vector<LL> (7000,0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= s; j++) {
            dp[i+1][j+a[i]] = (dp[i+1][j+a[i]] + dp[i][j])%mod;
            dp[i+1][j] = (dp[i+1][j] + 2 * dp[i][j])%mod;
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}


Measured memory_bytes: 169052
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
int n,a[5];
int solve(int p,int t,int m,int c){
    int re=0;
    int np,nm,nt;
    if(p<=a[c]){
        np=p;
        re+=t;
        nm=m;
        if(nm!=0)re++;
        nt=t;
    }else{
        np=a[c];
        re+=(p*t+m)/a[c];
        nt=(p*t+m)/a[c];
        nm=p*t+m-a[c]*nt;
        re+=(nm+a[c]-1)/a[c];
        nm=nm%a[c];
    }
    if(c==4)return re;
    else {
        return 1+solve(np,nt,nm,c+1);
    }
}
signed main(){
    cin>>n;
    for(int i=0;i<5;i++)cin>>a[i];
    cout<<solve(n,1,0,0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n;
    cin >> n;
    if(n == 3 || n == 5 || n == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    m = int(input())
    count = {}
    for i in range(m):
        s = input()
        count.setdefault(s, 0)
        count[s] += 1

    n = int(input())
    for i in range(n):
        s = input()
        count.setdefault(s, 0)
        count[s] -= 1

    mx = max(count.values())
    print(mx if mx > 0 else 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define INF (1<<29)

#define INDEX(s,c) (find(s.begin(),s.end(),c)-s.begin()) 
int decode(string s){
	int i,no=s.size();
	int res=0;
	i = INDEX(s,'m');
	if(i!=no){
		if(i && isdigit(s[i-1]))res += 1000*(s[i-1]-'0');
		else res += 1000;
	}
	i = INDEX(s,'c');
	if(i!=no){
		if(i && isdigit(s[i-1]))res += 100*(s[i-1]-'0');
		else res += 100;
	}
	i = INDEX(s,'x');
	if(i!=no){
		if(i && isdigit(s[i-1]))res += 10*(s[i-1]-'0');
		else res += 10;
	}
	i = INDEX(s,'i');
	if(i!=no){
		if(i && isdigit(s[i-1]))res += 1*(s[i-1]-'0');
		else res += 1;
	}
	return res;
}
string encode(int n){
	string res;
	if(n%10){
		res += 'i';
		if(1<n%10)res += '0'+n%10;
	}
	n/=10;
	if(n%10){
		res += 'x';
		if(1<n%10)res += '0'+n%10;
	}
	n/=10;
	if(n%10){
		res += 'c';
		if(1<n%10)res += '0'+n%10;
	}
	n/=10;
	if(n%10){
		res += 'm';
		if(1<n%10)res += '0'+n%10;
	}
	reverse(res.begin(),res.end());
	return res;
}
int main(){
	int n;
	cin>>n;
	while(n--){
		string s,t;
		cin>>s>>t;
		int a=decode(s),b=decode(t);
		//cout<<a+b<<endl;
		cout<<encode(a+b)<<endl;
	}
	return 0;
}

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

int main() {
   int n;
   cin >> n;
   int v[30],c[30],ans=0;
   rep(i,n)
   cin >> v[i];
   rep(i,n)
   cin >> c[i];
   rep(i,n){
      if(v[i]-c[i]>0)
      ans+=v[i]-c[i];
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <ctime>
#include <fstream>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define de cout<<1
#define FOR(NAME,FIRST,END) for(int NAME=FIRST;NAME<=END;NAME++)
#define openi(s) freopen(s,"r",stdin)
#define openo(s) freopen(s,"w",stdout)
const bool debug=false;
const bool INJUDGE=false;
int n,a,b;
int main(){
	cin>>n>>a>>b;
	cout<<min(n*a,b)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,n,i,j,k,x;
    cin>>n;
    vector<ll>vi,v1,v2;
    ll sum1=0,sum2=0;
    for(i = 0 ;i<n ;i++)
    {
        cin>>x;
        vi.push_back(x);
        sum1+=x;
        if(i != n-1)
        v1.push_back(sum1);

    }
    ll mini =INT_MAX;
    for(i = n-1 ;i>=1;i--)
    {
        sum2+=vi[i];
        mini = min(mini,abs(sum2- v1[i-1]));
        //cout<<sum2<<" "<<vi[i-1]<<endl;
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 3564