akhauriyash/Code-Regression huggingface dataset:
import statistics
import math

MOD = 10**9+7


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

    c = 0
    t = 0
    for i in range(n-1):
        c += pow(i+1, MOD-2, MOD)
        t += c * (x[i+1]-x[i])
        t %= MOD

    fact = math.factorial(n-1) % MOD
    print(t * fact % MOD)


main()


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

int main() {
  string S;
  int x=700;
  cin>>S;
  	if(S[0]=='o') x+=100;
    if(S[1]=='o') x+=100;
    if(S[2]=='o') x+=100;
  cout<<x<<endl;
}


Measured memory_bytes: 256
import sys
def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    else:
        return gcd(y,x%y)

N,M=map(int,input().split())
S=input()
T=input()
L=N*M//gcd(N,M)
n=L//N
m=L//M
l=n*m//gcd(n,m)
i=l//n
j=l//m
for k in range(N//i):
    if S[i*k]==T[j*k]:
        continue
    else:
        print(-1)
        sys.exit()
print(L)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll asize=1e6+5;
typedef pair<ll,ll> pl;
typedef pair<pl,ll> ppl;

int main(){
//	ios_base::sync_with_stdio(0),cin.tie(NULL);
	ll n,x,cnt=0,ans=0;
	vector<ll>v;
	cin>>n;
	while(n%2==0)n/=2,cnt++;
	if(cnt>0)v.push_back(cnt),cnt=0;
	x=sqrt(n);
	for(ll i=3;i<x+1;i+=2){
		cnt=0;
		while(n%i==0){
			cnt++;
			n/=i;
		}
		if(cnt>0)v.push_back(cnt);
	}
	if(n>1)ans++;
	for(auto x:v){
		if(x>=36)ans+=8;
		else if(x>=28)ans+=7;
		else if(x>=21)ans+=6;
		else if(x>=15)ans+=5;
		else if(x>=10)ans+=4;
		else if(x>=6)ans+=3;
		else if(x>=3)ans+=2;
		else if(x>=1)ans+=1;
	}
	cout<<ans;
	return 0;	
}
// 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
//Available in Snips
#define fi(i, x, y)   for (__typeof(x) i = x; i < y; i ++)
#define fir(i, x, y)  for (__typeof(x) i = x; i > y; i --)
#define fv(x)   for (auto itr = x.begin(); itr != x.end(); itr ++)
#define fvr(x)  for (auto itr = x.end() - 1; itr != x.begin() - 1; itr --)

int n, a[10009], sum;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		while (a[i] % 2 == 0) { a[i] /= 2; sum++; }
	}
	cout << sum << endl;
	return 0;
	

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N;
    cin >> N;

    int ans = N;

    rep(i,N+1) {
        int count = 0;
        int t = i;
        while (t > 0) {
            count += t % 6;
            t /= 6;
        }
        t = N - i;
        while (t > 0) {
            count += t % 9;
            t /= 9;
        }
        ans = min(ans, count);
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
int main() {
	int l, index;
	string str;
	cin >> l;
	cin >> str;
	cin >> index;
	char c = str[index-1];
	REP(i, str.size()) {
		if (str[i] != c) {
			str[i] = '*';
		}
	}
	cout << str << endl;
	return 0;
}

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

signed main(){
    int h,w,k;cin>>h>>w>>k;
    char s[h][w];
    int ans[h][w];
    rep(i,h)rep(j,w)cin>>s[i][j];
    int c=1;
    bool al[h];
    fill(al,al+h,false);
    for(int i=0;i<h;i++){
        bool e=false;
        for(int j=0;j<w;j++){
            if(s[i][j]=='.')ans[i][j]=c;
            else {
                if(e)c++;
                ans[i][j]=c;
                e=true;
            }
        }
        if(!e)al[i]=true;
        if(e)c++;
    }
    if(al[0]){
        int i=1;
        while(al[i])i++;
        rep(j,w)ans[0][j]=ans[i][j];
    }
    rep(i,h-1){
        if(al[i+1])rep(j,w)ans[i+1][j]=ans[i][j];
    }
    rep(i,h)rep(j,w)printf("%lld%s",ans[i][j],(j==w-1?"\n":" "));
}


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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

void dfs(string s, char mx, ll N)
{
    if (s.length() == N)
    {
        cout << s.c_str() << endl;
    }
    else
    {
        for (char c = 'a'; c <= mx; c++)
        {
            dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx), N);
        }
    }
}

int bfs(int a, int b, int h, int w, char tmp[][101])
{
    int ans[101][101] = {0};
    char c[101][101] = {0};
    queue<pair<int, int>> s;

    for (int i = 0; i <= h; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            c[i][j] = tmp[i][j];
        }
    }

    s.push(make_pair(a, b));

    while (s.size() > 0)
    {

        pair<int, int> tmp = s.front();
        s.pop();
        c[tmp.first][tmp.second] = '#';
        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (tmp.first + i < 1 || tmp.first + i > h)
                {
                    continue;
                }
                if (tmp.second + j < 1 || tmp.second + j > w)
                {
                    continue;
                }
                if (i != 0 && j != 0)
                {
                    continue;
                }
                if (i == 0 && j == 0)
                {
                    continue;
                }
                if (c[tmp.first + i][tmp.second + j] == '#')
                {
                    continue;
                }
                c[tmp.first + i][tmp.second + j] = '#';
                if (ans[tmp.first + i][tmp.second + j] == 0)
                {
                    ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1;
                }
                else
                {
                    ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1);
                }
                s.push(make_pair(tmp.first + i, tmp.second + j));
            }
        }
    }

    int asd = 0;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            asd = max(a, ans[i][j]);
        }
    }

    return asd;
}

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

    vector<ll> A(n);
    ll a2=0;
    ll a4=0;
    ll a=0;
    for(int i=0; i<n; i++){
        cin >> A[i];
        if(A[i]%4==0) a4++;
        else if(A[i]%2==0) a2++;
        else a++;
    }
    if(a2 > 0)
        n = n-a2+1;

    if(n-1-a4 <= a4){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	//n := r.nextInt()
	r.Scan(true)
	a := r.nextStringArray().toInts()

	const MOD = 1000000007
	clrs := make(map[int]int, 100000)
	clrs[0] = 3
	ans := 1
	for _, v := range a {
		ans = (ans * clrs[v]) % MOD
		clrs[v]--
		clrs[v+1]++
	}
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 6912
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

// doot diddly donger cuckerino Hahahahahah
// Created by White Knife on 15/04/20.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC target("popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

// @formatter:off
#define F               first
#define S               second
#define all(x)          (x).begin(), (x).end()
#define sz(x)           (long long) (x).size()
#define sim             template<typename T
#define ris             return *this
#define dor             > debug & operator <<
#define eni(x)          sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> range(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << range(all(i)); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;

using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template <typename T> T gcd(T x, T y) { return (y == 0) ? x : gcd(y, x % y); }
template<typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template<typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
template <typename T> T rand(T x, T y) { return rand() % (y - x + 1) + x; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// @formatter:on


class BTrickOrTreat {
public:
  
  void solveOne(istream &cin, ostream &cout) {
  
  }
  
  void solve(std::istream &cin, std::ostream &cout) {
    int n, k;
    cin >> n >> k;
    map<int, int> mp;
    for (int rep = 0; rep < k; ++rep) {
      int d;
      cin >> d;
      for (int i = 0; i < d; ++i) {
        int x;
        cin >> x;
        mp[x]++;
      }
    }
    cout << (n - sz(mp)) << '\n';
  }
};

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
	BTrickOrTreat solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

signed main() {
    int A, B;
    cin >> A >> B;

    int ans = -1;

    if (A < 10 && B < 10) {
        ans = A * B;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//
//AISing 2020
//B
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> a(n);
    REP(i, n) cin >> a[i];

    int ans=0;
    REP(i,n){
        if (((i+1)%2==1) && (a[i]%2==1)) ans++;
    }

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


Measured memory_bytes: 3596
def main():
    N = int(input())
    S = {}
    for _ in range(N):
        s = input()
        if s not in S:
            S[s] = 0
        S[s] += 1
    maxCount = max(S.values())
    res = [s for s, ct in S.items() if ct == maxCount]
    res = sorted(res)
    for s in res:
        print(s)


    

main()

Measured memory_bytes: 32988
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;

long memo[1000000];

long func(long n){
    if(memo[n]) return memo[n];
    if(n==1) return 1;
    memo[n]=func(n-1)+n;
    return memo[n];
}

int main(){
    int n;
    cin >> n;
    map<string, int> m;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    long ans=0;
    for(auto x:m){
        if(x.second==1) continue;
        ans += func(x.second-1);
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if (N - K >= 0) {
    cout << X * K + Y * (N - K) << endl;
  }
  else {
    cout << X * N << endl;
  }
}


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

using namespace std;

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

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

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

int main() {
    int x;
    cin >> x;
    if (x >= 400 && x <= 599) {
        cout << 8 << endl;
    } else if (x >= 600 && x <= 799) {
        cout << 7 << endl;
    } else if (x >= 800 && x <= 999) {
        cout << 6 << endl;
    } else if (x >= 1000 && x <= 1199) {
        cout << 5 << endl;

    } else if (x >= 1200 && x <= 1399) {
        cout << 4 << endl;


    } else if (x >= 1400 && x <= 1599) {
        cout << 3 << endl;

    } else if (x >= 1600 && x <= 1799) {
        cout << 2 << endl;

    } else if (x >= 1800 && x <= 1999) {
        cout << 1 << endl;

    }
    return 0;
}


Measured memory_bytes: 3632
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  string s;
  int n;
  cin >> s;
  n = s.size();
  for(int i=0;i<n;i++) cout <<"x";
  cout << endl;
}


Measured memory_bytes: 256
/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include<bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock()*1.0 / CLOCKS_PER_SEC << endl;
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);
 
int main() {
  ioso
  #ifndef ONLINE_JUDGE
  ffe
  #endif
  string s;
  cin >> s;
  ll cn = 0;
  if(s[0]=='R' and s[1]=='R' and s[2]=='R') {
    cout << 3 << endl;
  }
  else if(s[0]=='R' and s[1]=='R' || s[1]=='R' and s[2]=='R') {
    cout << 2 << endl;
  }
  else if(s[0]=='S' and s[1]=='S' and s[2]=='S'){
    cout << 0 << endl;
  }
  else {
    cout <<1 << endl;
  }
}

Measured memory_bytes: 3648
n,a,b=list(map(int, input().strip().split()))
s=input().strip()
x=0
y=0
for i in range(n):
    if s[i]=='a':
        if x<a+b:
            print("Yes")
            x=x+1
        else:
            print("No")
    elif s[i]=='b':
        if x<a+b and y<b:
            print("Yes")
            x=x+1
            y=y+1
        else:
            print("No")
    else:
        print("No")

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

int main() {
  char s[101];
  cin >> s;
  int len = strlen(s);
  int cnt = 0;
  for (int i = 0; i < len / 2; i++) {
    if (s[i] != s[len - i - 1]) {
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>

void solve() {
    int h, w, m;
    std::cin >> h >> w >> m;

    std::vector<int> xcnt(h, 0), ycnt(w, 0);
    std::set<std::pair<int, int>> ps;

    while (m--) {
        int x, y;
        std::cin >> x >> y;

        ++xcnt[--x], ++ycnt[--y];
        ps.emplace(x, y);
    }

    std::vector<int> yis(w);
    std::iota(yis.begin(), yis.end(), 0);
    std::sort(yis.begin(), yis.end(),
              [&](auto i, auto j) { return ycnt[i] > ycnt[j]; });

    int ans = 0;
    for (int x = 0; x < h; ++x) {
        for (auto y : yis) {
            int cnt = xcnt[x] + ycnt[y];
            if (cnt <= ans) break;

            bool ex = ps.count(std::make_pair(x, y));
            if (ex) --cnt;

            ans = std::max(ans, cnt);
        }
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 20880
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // cout << fixed << setprecision(10);

    LL A, B, M;
    cin >> A >> B >> M;
    vector<LL> a, b;
    LL a_min = INT_MAX, b_min = INT_MAX;

    REP(i, A)
    {
        LL temp;
        cin >> temp;
        a.push_back(temp);
        if(a_min > temp)
        {
            a_min = temp;
        }
    }

    REP(i, B)
    {
        LL temp;
        cin >> temp;
        b.push_back(temp);
        if(b_min > temp)
        {
            b_min = temp;
        }
    }

    LL res = a_min + b_min;

    REP(i, M)
    {
        LL x, y, c, temp;
        cin >> x >> y >> c;
        temp = a.at(x-1) + b.at(y-1) - c;
        if(res > temp)
        {
            res = temp;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2548
#include <stdio.h>

int main(int argc, char** argv)
{
	int i, j, v, m, n, *matrix1, *matrix2;
	scanf("%d %d", &n, &m);

	matrix1 = (int *)malloc(sizeof(int) * n * m);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf("%d", &v);
			matrix1[i * m + j] = v;
		}
	}

	matrix2 = (int *)malloc(sizeof(int) * m);
	for (i = 0; i < m; i++) {
		scanf("%d", &v);
		matrix2[i] = v;
	}

	for (i = 0; i < n; i++) {
		int out = 0;
		for (j = 0; j < m; j++) {
			out += (matrix1[i * m + j] * matrix2[j]);
		}
		printf("%d\n", out);
	}
	free(matrix1);
	free(matrix2);
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
using namespace std;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
vector<string>g;
vector<vector<bool>>used;
int cnt = 0;
int dfs(int y,int x){
    used[y][x] = true;
    char c = g[y][x];
    if(c == '#')cnt++;
    int cal = (c == '.');
    rep(k,4){
        int ny = y + dy[k];
        int nx = x + dx[k];
        if(valid(nx, ny) and c != g[ny][nx] and !used[ny][nx]){
            cal += dfs(ny,nx);
        }
    }
    return cal;
}
signed main(){
    cin >> H >> W;
    g = vector<string>(H);
    used = vector<vector<bool>>(H,vector<bool>(W,false));
    for(auto & s :g) cin >> s;
    int ans = 0;
    rep(i,H)rep(j,W)if(g[i][j] == '#' and !used[i][j]){
        ans += dfs(i,j) * cnt;
        cnt = 0;
    }
    cout << ans << endl;
}




Measured memory_bytes: 13056
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//最大公約数
long long gcd(long long a, long long b) {
  if (a < b) std::swap(a, b);
  long long r = a % b;
  while (r) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vll a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    a[i] /= 2;
  }

  ll lcm = a[0];
  for (ll i = 1; i < n; i++) {
    lcm *= a[i] / gcd(a[i], lcm);
  }
  for (ll i = 0; i < n; i++) {
    if (lcm / a[i] % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 0;
  if (lcm <= m) {
    ans++;
    m -= lcm;
    ans += m / (2 * lcm);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <string.h>
#include <queue>
#include <functional>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int d[10];
	for (int i = 0; i < k; i++) {
		cin >> d[i];
	}

	while (1) {
		int tmp = n;
		int judge = 0;
		while (tmp > 0) {
			for (int i = 0; i < k; i++) {
				if (d[i] == tmp % 10) {
					judge = 1; break;
				}
			}
			if (judge == 0)tmp /= 10;
			else { break; }
		}
		if (judge == 0)break;
		else n += 1;
	}
	cout << n;
}

Measured memory_bytes: 256
#include<stdio.h>
#define ll long long

void swap(ll *a,ll *b){
  ll tmp=*a;
  *a=*b;
  *b=tmp;
}

// ll gcd(ll a,ll b){
//   if(a<b) swap(&a,&b);
//   if(b==0) return a;
//   return gcd(a%b,b);
// }

long long int gcd(long long int a, long long int b)
{
	long long int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main(){
  ll n,m,i,a[100005];
  scanf("%lld %lld",&n,&m);
  for(i=0;i<n;i++){
    scanf("%lld", &a[i]);
    a[i] /= 2;
  }
  ll l=a[0];
  for(i=0;i<n;i++) l = l/gcd(l,a[i])*a[i];
  for(i=0; i<n; i++){
    if(l/a[i]%2==0){
      printf("0\n");
      return 0;
    }
  }
  printf("%lld\n",(m/l+1)/2);
  return 0;
}

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

const int N = 2*100010;

int a[N];

int main()
{
	int n;
	cin >> n;
	int q=n-1;
	while(q--)
	{
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout << a[i] <<endl;
	}
	return 0;
 } 

Measured memory_bytes: 4460
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline

N, *p = map(int, read().split())

p = np.array(p, np.int64) - 1
a = np.arange(30000, 30000 * N + 1, 30000)
b = a[::-1]
idx = np.arange(1, N + 1)
a = a + idx[np.argsort(p)]
print(' '.join(map(str, a.tolist())))
print(' '.join(map(str, b.tolist())))


Measured memory_bytes: 15264
#define rep(i,n)for(i=0;i<n;i++)
W,H,m,c[10][10];
DP[51][10][10][10][10];
CalcO(o,x,y){
	c[x][y]>0?o+=c[x][y]:0;
	return o>0?o>m?m:o:0;
}
CalcF(f,x,y){
	return c[x][y]<0?f+c[x][y]:f;
}
Walk(x,y,l,r,o,f){
	int*p=&DP[o][y][x][l][r];
	f>*p?*p=f:0;
}
Dig(x,y,l,r,o,f){
	Walk(x,y,l,r,CalcO(o-1,x,y),CalcF(f,x,y));
}
main(){
	int*p,x,y,g,d,v,f,o,l,r,f0;
	for(;scanf("%d%d",&W,&H)*W;){
		scanf("%d%d%d",&f0,&m,&o);
		rep(y,H)rep(x,W)
			scanf("%d",&c[x][y]);
		f0++;
		if(o>1)
			rep(x,W)
				DP[CalcO(o-1,x,0)][0][x][x][x]=CalcF(f0,x,0);
		rep(y,H-1)rep(g,W)for(o=m;o>1;o--)rep(d,2)rep(l,W-g)rep(v,g+1)
		{
			r=l+g;
			if(p=&DP[o][y][x=d?l+v:r-v][l][r],f=*p){
				*p=0;
				Dig(x,y+1,x,x,o,f);
				x?x>l?Walk(x-1,y,l,r,o-1,f):Dig(x-1,y,x-1,r,o,f):0;
				x<W-1?x<r?Walk(x+1,y,l,r,o-1,f):Dig(x+1,y,l,x+1,o,f):0;
			}
		}
		f=0;
		rep(x,W)rep(o,m)
			p=&DP[o+1][H-1][x][x][x],*p>f?f=*p:0,*p=0;
		printf(f?"%d\n":"NA\n",f0-f);
		memset(DP,0,sizeof(*DP)*2);
	}
}

Measured memory_bytes: 0
#import<atcoder/all>
using namespace std;int n,m;vector<int>a,b;int main(){cin>>n>>m;for(;n--;a.push_back(m))cin>>m;for(;cin>>m;)b.push_back(m);for(int i:atcoder::convolution(a,b))cout<<i<<' ';}

Measured memory_bytes: 19060
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

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

int main() {
  int N;
  cin >> N;
  if (N%2==0) cout <<  N/2  << endl;
  else cout <<  (N+1)/2  << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    int n;
    cin>>n;
    map<int,int> sm;
    for(int i=1;i<=n;i++){
        auto pf=prime_factorize(i);
        for(auto p : pf) sm[p.first]+=p.second;
    }


    int ans=0;
    for(int i=2;i<=n;i++) if(74<=sm[i]) ans++;
    for(int i=2;i<=n;i++){
        for(int j=2;j<=n;j++){
            if(i!=j && 14<=sm[i] && 4<=sm[j]) ans++;
        }
    } 
    for(int i=2;i<=n;i++){
        for(int j=2;j<=n;j++){
            if(i!=j && 24<=sm[i] && 2<=sm[j]) ans++;
        }
    } 
    for(int i=2;i<=n;i++){
        for(int j=2;j<=n;j++){
            for(int k=j+1;k<=n;k++){
                if(i!=j && i!=k && 2<=sm[i] && 4<=sm[j] && 4<=sm[k]) ans++;
            } 
        }
    } 

    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define double long double
#define x first
#define y second
#define long long long
#define int long 



           //       |----|       /\      |    |   -----   |
           //       |   /       /  \     |    |     |     |
           //       |--/       /----\    |----|     |     |
           //       |   \     /      \   |    |     |     |
           //       |    \   /        \  |    |   -----   -------

int n,k;
int arr[300006];
int cache[300005];
int dp(int i)
{
	if(i==n-1)
		return 0;
	if(cache[i]!=-1)
		return cache[i];
	int mini=2000000000;
	for(int j=i+1;j<min(n,i+k+1);j++)
		mini=min(mini,labs(arr[i]-arr[j])+dp(j));
	return cache[i]=mini;
}
int32_t main()
{
    IOS
    cin>>n>>k;
    for(int i=0;i<n;i++)
    	cin>>arr[i];
    memset(cache,-1,sizeof(cache));
    cout<<dp(0);
}

Measured memory_bytes: 9088
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

use std::collections::HashMap;
// 自力で解けなかった
fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        n: usize,
    }

    let mut freq: HashMap<(usize, usize), usize> = HashMap::new();
    for i in 1..(n + 1) {
        let pair = head_and_tail(i);
        let c = freq.entry(pair).or_insert(0);
        *c += 1;
    }

    let mut count = 0;
    for i in 1..(n + 1) {
        let pair = head_and_tail(i);
        let rp = &(pair.1, pair.0);
        count += match freq.get(rp) {
            Some(x) => *x,
            None    => 0,
        };
    }

    return count.to_string();
}

fn head_and_tail(i: usize) -> (usize, usize) {
    let mut x = i;
    let mut head = x;
    while x > 0 {
        head = x;
        x /= 10;
    }
    return (head, i % 10);
}

Measured memory_bytes: 4352
//
// Created on 2020/01/26.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    int ans;
    int h;
    int a;
    cin>>h>>a;
    ans = 0;
    while (h>0){
        h -= a;
        ans ++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#include<vector>
using namespace std;
int x[4][30] = {
	{23, 1, 2,26, 4, 5,29, 7, 8,20,10,11,12,13,14,17,16,15,18,19, 9,21,22, 0,24,25, 3,27,28, 6},
	{ 0, 1,21, 3, 4,24, 6, 7,27, 9,10,18,14,13,12,15,16,17,11,19,20, 2,22,23, 5,25,26, 8,28,29},
	{ 0, 1, 2, 3, 4, 5,21,22,23,11,10, 9,17,13,14,15,16,12,18,19,20, 6, 7, 8,24,25,26,27,28,29},
	{27,28,29, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,15,14,16,17,20,19,18,21,22,23,24,25,26, 0, 1, 2}
};
vector<int> S = { 1,1,1,1,1,1,1,1,1,2,2,2,4,4,4,6,6,6,5,5,5,3,3,3,3,3,3,3,3,3 };
vector<int> D(30, 0);
map<vector<int>, int>M;
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 30; j++)cin >> D[j];
		queue<pair<vector<int>, int> >Q; M.clear();
		while (!Q.empty())Q.pop(); Q.push(make_pair(D, 0)); M[D] = 1;
		if (D == S) { cout << "0" << endl; goto E; }
		while (!Q.empty()) {
			vector<int>A = Q.front().first; int AA = Q.front().second; Q.pop();
			for (int j = 0; j < 4; j++) {
				vector<int>B = A;
				for (int k = 0; k < 30; k++)B[x[j][k]] = A[k];
				if (B == S) { cout << AA + 1 << endl; goto E; }
				if (M[B] == 0) { Q.push(make_pair(B, AA + 1)); M[B] = 1; }
			}
		}
	E:;
	}
	return 0;
}

Measured memory_bytes: 3232
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func getInput() (int, int) {
	sc.Split(bufio.ScanWords)

	sc.Scan()
	N, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	Y, _ := strconv.Atoi(sc.Text())

	return N, Y
}

func main() {

	N, Y := getInput()

	for x := 0; x <= N; x++ {
		for y := 0; y <= N-x; y++ {
			if 10000*x+5000*y+1000*(N-x-y) == Y {
				fmt.Printf("%d %d %d\n", x, y, N-x-y)
				return
			}
		}

	}

	fmt.Println("-1 -1 -1")
}


Measured memory_bytes: 640
//gcc -std=gnu11 -O2 -o a.out main.c -lm

#include <stdio.h>

int main(void)
{
    int res;

    int w, h, n;
    int x[100];
    int y[100];
    int a[100];
    int i;
    int w0;
    int h0;
    int w1;
    int h1;

    // input
    res = scanf("%d%d%d", &w, &h, &n);
    for (i = 0; i < n; i++) {
        res = scanf("%d%d%d", &x[i], &y[i], &a[i]);
    }

    w0 = 0;
    h0 = 0;
    w1 = w;
    h1 = h;
    for (i = 0; i < n; i++) {
        switch (a[i]) {
        case 1: // x<xi
            if (w0 < x[i]) w0 = x[i];
            break;
        case 2: // x>xi
            if (w1 > x[i]) w1 = x[i];
            break;
        case 3: // y<yi
            if (h0 < y[i]) h0 = y[i];
            break;
        case 4: // y>yi
            if (h1 > y[i]) h1 = y[i];
            break;
        default:
            break;
        }
    }
    if (w0 > w1) w0 = w1; // will be 0.
    if (h0 > h1) h0 = h1; // will be 0.

    // output
    printf("%d\n", (w1 - w0) * (h1 - h0));

	return 0;
}



Measured memory_bytes: 128
n, m = (int(x) for x in input().split())
c = [0 for _ in range(m)]
for _ in range(n):
    r = [int(x) for x in input().split()]
    for i in r[1:]:
        c[i-1] += 1
print(c.count(n)) if n in c else print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pr pair<ll, ll>
#define vct vector<ll>
#define vpt vector<pr>
#define st set<ll>
#define pq priority_queue<ll>
#define mat vector<vector<ll> >
#define F(i, n) for (i = 0; i < (1LL*n); i++)
#define Fr(i, n) for (i = n - 1; i >= 0; i--)
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<long long, int, custom_hash>
void prv(vct v)
{
    for (ll i = 0; i < v.size(); i++)
        cout << v[i] << " ";
    cout << "\n";
}
ll poww(ll x, ll y, ll m)
{
    ll res = 1;
    while (y)
    {
        if (y % 2 == 0)
        {
            x = (x * x) % m;
            y = y / 2;
        }
        else
        {
            res = (res * x) % m;
            y--;
        }
    }
    return res;
}
void deb(string s, ll n)
{
    cout << s << " : " << n << "\n";
}
void prn(ll n) { cout << n << "\n"; }
void prs(string n) { cout << n << "\n"; }

mat mt;
void setmtsize(ll m,ll n, ll ini=0){
    mt.resize(m,vector<ll>(n,ini));
}
void prmt(mat m){
    for(ll i=0;i<(1LL*m.size());i++)prv(m[i]);
}

ll n, k, m, l, r, x, y, ans=0;
ll t, t1, t2;

ll i, j;
ll a, b;
ll mod = 1000000007;


void solve()
{
    cin>>n;
    vct v(n);
    F(i,n)cin>>v[i];
    ll cn=0;
    F(i,n)if(((i%2)==0)&&(v[i]%2==1))cn++;
    prn(cn);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

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

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

const long long MOD = 1000000007;

int main(){
  string s;
  cin >>s;
  bool ans=true;
  rep(i,3){
    if(s.at(i)==s.at(i+1)) ans=false;
  }
  if(ans) cout << "Good" <<endl;
  else cout <<"Bad"<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0

for i in range(N):
  # i番目の街のモンスターを倒せるだけ倒す
  tmp = min(A[i], B[i])
  ans += tmp
  A[i] -= tmp
  B[i] -= tmp
  
  # i+1番目の街のモンスターを倒せるだけ倒す
  tmp2 = min(A[i+1],B[i])
  ans += tmp2
  A[i+1] -= tmp2
  B[i] -= tmp2
print(ans)

Measured memory_bytes: 18624
#include <iostream>
#include <string>
#include <utility>
#include <queue>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define llint long long
#define inf 1e18
#define eps 1e-9
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

struct vec2d{
	double x, y;
	vec2d(){}
	vec2d(double x, double y){
		this->x = x, this->y = y;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec2d operator+(vec2d ope){
		return vec2d(add(x, ope.x), add(y, ope.y));
	}
	vec2d operator-(vec2d ope){
		return vec2d(add(x, -ope.x), add(y, -ope.y));
	}
	vec2d operator*(double t){
		return vec2d(x*t, y*t);
	}
	vec2d operator/(double t){
		return vec2d(x/t, y/t);
	}
	double dot(vec2d ope){
		return add(x*ope.x, y*ope.y);
	}
	double cross(vec2d ope){
		return add(x*ope.y, -y*ope.x);
	}
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
};

double distPP(vec2d p, vec2d q){
	return (p-q).norm();
}

double distSP(vec2d p, vec2d q, vec2d x)
{
	if((x-p).dot(q-p) <= 0) return distPP(p, x);
	if((x-q).dot(p-q) <= 0) return distPP(q, x);
	return fabs( (x-p).cross(q-p) / distPP(p, q) );
}

bool isOnS(vec2d p, vec2d q, vec2d x)
{
	return (p-x).cross(q-x) == 0 && (p-x).dot(q-x) <= 0;
}

bool isCross(vec2d p, vec2d q, vec2d r, vec2d s)
{
	if((q-p).cross(s-r) == 0){
		return isOnS(p, q, r) || isOnS(p, q, s) || isOnS(r, s, p) || isOnS(r, s, q);	
	}
	double t = (r-p).cross(s-r) / (q-p).cross(s-r);
	vec2d x = p + (q-p)*t;
	return isOnS(p, q, x) && isOnS(r, s, x);
}

bool getCrossPointLL(vec2d p, vec2d q, vec2d r, vec2d s, vec2d &dest)
{
	if((q-p).cross(s-r) == 0) return false;
	double t = (r-p).cross(s-r) / (q-p).cross(s-r);
	dest = p + (q-p)*t;
	return true;
}

llint n;
vec2d p[55];

bool getCircumCenter(vec2d p, vec2d q, vec2d r, vec2d &dest)
{
	vec2d A = (p+q)/2, B = (p+r) * 0.5;
	vec2d da = A - p, db = B - p;
	vec2d nA = vec2d(da.y, -da.x), nB = vec2d(db.y, -db.x);
	nA = nA / nA.norm(), nB = nB / nB.norm();
	return getCrossPointLL(A, A+nA, B, B+nB, dest);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i].x >> p[i].y;
	
	if(n == 2){
		printf("%.11f\n", distPP(p[1], p[2])*0.5);
		return 0;
	}
	
	double ans = inf;
	for(int i = 1; i <= n; i++){
		for(int j = i+1; j <= n; j++){
			vec2d c = (p[i] + p[j]) * 0.5;
			double r = distPP(c, p[i]);
			bool flag = true;
			for(int l = 1; l <= n; l++){
				if(distPP(c, p[l]) > r + eps){
					flag = false;
					break;
				}
			}
			if(flag) ans = min(ans, r);
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = i+1; j <= n; j++){
			for(int k = j+1; k <= n; k++){
				vec2d c;
				if(!getCircumCenter(p[i], p[j], p[k], c)) continue;
				double r = distPP(c, p[i]);
				bool flag = true;
				for(int l = 1; l <= n; l++){
					if(distPP(c, p[l]) > r + eps){
						flag = false;
						break;
					}
				}
				if(flag) ans = min(ans, r);
			}
		}
	}
	printf("%.11f\n", ans);
	
	return 0;
}

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


typedef long long ll;

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

    string s;
    cin >> s;

    if(s == "ABC") cout << "ARC\n";
    else cout << "ABC\n";

    return 0;
}

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

int main()
{

  for (int i = 0; i < 5; i++)
  {
    int x;
    cin >> x;

    if (x == 0)
    {
      cout << i + 1 << endl;
      return 0;
    }
  }
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
	return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

llint cnt = 0;
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
int h, w;
llint bc = 0, wc = 0;
string mas[401];
bool done[401][401] = {};

int dfs(int x, int y, char nc)
{
    if(nc == '#') bc++;
    else wc++;
    done[y][x] = true;
    //co << x << ' ' <<  y << ' ' << nc << en;
    for(int i = 0; i < 4; i++) {
	int nx = x + dx[i];
	int ny = y + dy[i];
	if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
	if(mas[ny][nx] != nc && !done[ny][nx]) {
	    if(nc == '.') dfs(nx, ny, '#');
	    else          dfs(nx, ny, '.');
	}
    }
    
    return 0;
}

int main()
{
    ci >> h >> w;

    rep(i, h) ci >> mas[i];
    
    rep(i, h) {
	rep(j, w) {
	    if(mas[i][j] == '#' && !done[i][j]) {
		bc = wc = 0;
		dfs(j, i, '#');
		cnt += bc * wc;
	    }
	}
    }
	    
    co << cnt << en;
    
    return 0;
}


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

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
using namespace std;

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int R, G, B, N;

signed main()
{
    cin >> R >> G >> B >> N;

    int r = ceil(N / R);
    int g = ceil(N / G);
    int b = ceil(N / B);

    int ans = 0;

    rep(i, r + 1)
    {
        rep(j, g + 1)
        {
            if (N < (i * R + j * G))
            {
                break;
            }

            int t = N - (i * R + j * G);

            if (t % B == 0)
            {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
  int N; cin>>N;
  int a=0,b=0,n[110],k=0;

  for(int i=0;i<N;i++) cin>>n[i];
  
  for(int i=0;i<N;i++){
    int max=0;
    for(int j=0;j<N;j++){
      if(max<n[j]){
        max=n[j];
        k=j;
      }
      if(j==N-1) n[k]=0;
    }
    if(i%2==0) a+=max;
    else b+=max;
  }

  cout<<abs(a-b)<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(void){
    int n;
    int a,b;
    int yes=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        if(a==b){yes++;}
        else{yes=0;}
        if(yes>=3){printf("Yes\n");return 0;}
    }
    printf("No\n");

}

Measured memory_bytes: 1660
from operator import add, mul, sub, or_


class BIT:
    def __init__(self, n, op, ie):
        self.n = n
        self.tree = [ie]*(n+1)
        self.op = op

    def update(self, i, v):
        while i <= self.n:
            self.tree[i] = self.op(self.tree[i], v)
            i += i & -i

    def query(self, i):
        v = 0
        while i:
            v = self.op(self.tree[i], v)
            i -= i & -i
        return v


N, Q = map(int, input().split())
*c, = map(int, input().split())

q = [[] for _ in range(N+1)]
for i in range(Q):
    x, y = map(int, input().split())
    q[y-1].append([i, x-1])

bit = BIT(N, add, 0)
finds = [-1]*(N+1)
ans = [0]*Q
for i in range(N):
    if finds[c[i]] != -1:
        bit.update(finds[c[i]]+1, -1)

    finds[c[i]] = i
    bit.update(finds[c[i]]+1, 1)

    for j, x in q[i]:
        ans[j] = bit.query(i+1) - bit.query(x)

for a in ans:
    print(a)


Measured memory_bytes: 174764