akhauriyash/Code-Regression huggingface dataset:
import math

#n = int(input())
#a = int(input())
a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
#string = input()
#ls = [int(input()) for i in range(n)]
#ls1 = [input() for i in range(n)]
#m = int(input())
#ls2 = [input() for i in range(m)]
num = str(a) + str(b)
num = int(num)
tmp = pow(num,0.5)
if math.ceil(tmp) == math.floor(tmp):
  print("Yes")
  quit()
else:
  print("No")

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

int main() {
  int N;
  cin >> N;
  
  int ans=0;
  
  int x;
  cin >> x;
  while(x%2==0){
    x /= 2;
    ans++;
  }
  
  rep(i, N-1){
    cin >> x;
    rep(j, ans){
      if(x%2==0){
        x /= 2;
      }
      else{
		ans = j;
        break;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    int main(){
    int x,y,i,n,c;
    vector <int> a(100010);
    cin >> n;
    x = 10000000;
    y = 0;
    for(i=0;i<n;i++){
    cin >> a[i];
    x = min(x,a[i]);
    y = max(y,a[i]);
    }
    for(i=0;i<n;i++){
    if((y-x)>1){
    cout << "No" << endl;
    return 0;
    }
    }
    c = 0;
    for(i=0;i<n;i++){
    if(a[i]==x){
    c++;
    }
    }
    if(y>x){
    if(x>=c && (n+c)>=2*(x+1)){
    cout << "Yes" << endl;
    }else{
    cout << "No" << endl;
    }
    }else{
    if(n-2*y>=0 || y==(n-1)){
    cout << "Yes" << endl;
    }else{
    cout << "No" << endl;
    }
    }
    }

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll big2 = 998244353;

string s;

bool ss(ll i, ll j){
    string res = "";
    for(int c1 = 0; c1 < i; c1++){
        res += s[c1];
    }
    for(int c1 = j+1; c1 < s.length(); c1++){
        res += s[c1];
    }
    return (res == "keyence");
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;


   cin >> s;
   if(s == "keyence"){
    cout << "YES\n";
    return 0;
   }
   for(int c1 = 0; c1 < s.length(); c1++){
        for(int c2 = c1; c2 < s.length(); c2++){
            if(ss(c1,c2)){
                cout << "YES\n";
                return 0;
            }
        }
   }
   cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
var s:ansistring;
    i,m,t:longint;
begin
  readln(s);
  for i:=1 to length(s) do
  begin
    if s[i]='S' then inc(m);
    if (m<>0)and(s[i]='T') then
    begin
      dec(m);
      inc(t,2);
    end;
  end;
  writeln(length(s)-t);
end.

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

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  int L = 0;
  int R = 0;
  for (int i = 0; i < M; i++){
    int a;
    cin >> a;
    if (a < X) L++;
    else R++;
  }
  cout << min(L, R) << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let x: i32 = read();
    for i in 0..n + 1 {
        for j in 0..n - i + 1 {
            let k = n - i - j;
            if i * 10000 + j * 5000 + k * 1000 == x {
                println!("{} {} {}", i, j, k);
                return ();
            }
        }
    }
    println!("{} {} {}", -1, -1, -1);
}


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

int main(int argc, char const *argv[])
{
	int n,tik;
	while(~scanf("%d %d",&n,&tik)){
		int item[n+5];
		int te;
		priority_queue <int,vector<int>,less<int> > it ;
		for (int i = 0; i < n; ++i)
		{
			scanf("%d",&te);
			it.push(te);
		}
		for (int i = 0; i < tik; ++i)
		{
			int te=it.top()/2;
			it.pop();
			it.push(te);
			
		}
		long long ans=0;
		while(!it.empty()){
			ans+=it.top();
			it.pop();
		}
		printf("%lld\n",ans );
		
	}
	return 0;
}

Measured memory_bytes: 892
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort{|x,y|y<=>x} end##
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
t1,t2=gsmi
gcd=t1.gcd(t2)
t1/=gcd
t2/=gcd

a1,a2=gsmi
b1,b2=gsmi

da1=t1*a1
da2=t2*a2
db1=t1*b1
db2=t2*b2

da=da1+da2
db=db1+db2
diff=(da-db).abs

putsend 'infinity' if diff==0
putsend 0 if da>db&&da1>=db1 || da<db&&da1<=db1

d=(da1-db1).abs
cnt = (d/diff.to_f).ceil * 2
cnt+=1 if d%diff==0
# スタート時補正
cnt-=1

puts cnt

Measured memory_bytes: 1916
N = int(input())
A = list(map(int,input().split()))
right = [0]
A = A[::-1]
for i in range(1, N):
    if A[i] >= A[i - 1]:  right.append(right[-1] + 1)
    else:  right.append(0)
ans = max(right)
print(ans)

Measured memory_bytes: 91632
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 50;
constexpr ll Y_I_MAX = 1000000000;

ll N;
/*
bool bfs(){
	while(!que.empty()){
		pair<int,int> q=que.front();
		que.pop();
		rep(i,4){
			int nx=q.first+dx[i];
			int ny=q.second+dy[i];
			if(0<=nx && nx<H && 0<=ny && ny<W){
				if(a[nx][ny]=='g'){
					return true;
				}else if(a[nx][ny]=='.'){
					a[nx][ny]='#';
					que.push(make_pair(nx,ny));
				}
			}
		}
	}
	return false;
}
*/
void input() {
	scanf("%lld", &N);
	//vector<vector<ll>> d(N, vector<ll>(N, 0));
	vector<pair<ll,ll>> a(N,pair<ll,ll>());

	rep(i, N) {
		cin>>a[i].first>>a[i].second;
		
	}
	ll c=0;
	ll maxval=0;
	rep(i,N){
		rep(j,N){
			c=0;
			if(i==j)continue;
			ll xdif=a[i].first-a[j].first;
			ll ydif=a[i].second-a[j].second;
			rep(k,N){
				rep(l,N){
					if(k==l)continue;
					if(a[k].first+xdif==a[l].first && a[k].second+ydif==a[l].second)c++;
				}
			}
			chmax(maxval,c);

		}
	}

	printf("%lld\n", N-maxval);
}

signed main() {
	input();
	return 0;
}


Measured memory_bytes: 636
def isPrime(n):
    if n < 2:
        # 2未満は素数でない
        return False
    if n == 2:
        # 2は素数
        return True
    for p in range(2, n):
        if n % p == 0:
            # nまでの数で割り切れたら素数ではない
            return False
    # nまでの数で割り切れなかったら素数
    return True


x = int(input())

for n in range(x, 10**6):
    if n > 2 and n % 2 == 0:
        continue

    if isPrime(n):
        break

print(n)

Measured memory_bytes: 2940
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n = input()
s = list(n)
r = 0
b = 0

cnt = 0
for i in s:
    if i == '0':
        if b > 0:
            b -= 1
            cnt += 2
        else:
            r += 1
    else:
        if r > 0:
            r -= 1
            cnt += 2
        else:
            b += 1
print(cnt)



Measured memory_bytes: 8776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n, a, b;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();
        solve();
    }

    void solve() {
        int plan1 = n * a;
        if (plan1 < b) {
            System.out.println(plan1);
        } else {
            System.out.println(b);
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            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: 23124
//ABC098C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n;
	string s;
	cin >> n >> s;
	vector<int> x(n);
	x.at(0) = 0;
	for(int i=1;i<n;i++){
		if(s.at(i) == 'E'){
			x.at(0)++;
		}
	}
	for(int i=1;i<n;i++){
		x.at(i) = x.at(i-1);
		if(s.at(i-1) == 'W'){
			x.at(i)++;
		}
		if(s.at(i) == 'E'){
			x.at(i)--;
		}
	}
	sort(x.begin(),x.end());
	cout << x.at(0) << endl;
	return 0;
}

Measured memory_bytes: 1796
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    x = LIST()
    print(x.index(0)+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10420
def gcd(a, b):
    a,b = min(a,b),max(a,b)
    while b:
	    a, b = b, a % b
    return a

#least multi
def lm(a,b):
    return a*b // gcd(a,b)

N =input()
list = input().split(" ")
int_li = [int(s) for s in list]

m = 1
for i in int_li:

    m = lm(m,i)
m-=1

ans = 0
for i in int_li:
    ans += m%i

print(ans);


Measured memory_bytes: 3316
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  string a="A",b="B",c="C";
  cin >> str;
  for(int i=0;i<str.size();i++){
    if(str[i]==a[0] || str[i]==b[0] || str[i]==c[0])
      str[i]+=26;
    str[i]-=3;
  }
  cout << str << endl;

}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int k, q;
	cin >> k >> q;
	vector<ll> d(k);
	rep(i, k) cin >> d[i];

	const ll dsum = accumulate(begin(d), end(d), 0LL);
	// [0, n)

	rep(loop, q) {
		ll n, x, m;
		cin >> n >> x >> m;

		ll eq = 0LL;
		
		ll gt = 0LL;

		// ll a_0 = x
		// ll a_1 = x + d_0
		// ll a_k = x + d_{k - 1}

		ll last = x;
		const ll num = n - 1;
		
		rep(i, k) {
			// eq
			if (d[i] % m == 0) {
				eq += 1LL *  (num / k + (i < num % k));
			}

			// gt
			last += 1LL * (num / k + (i < num % k)) * (d[i] % m);
		}

		gt += (last / m - x / m);


		const ll ans = n - 1 - eq - gt;
		// cerr << eq << " " << gt << endl;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long n,a[200010];
int main(){
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	if(n%2==1){
		long long ans=0;
		for(int i=1;i<=n;i++)
			ans=ans+abs(a[i]-a[n/2+1]);
		printf("%lld\n",ans);
		return 0;
	}
	else{
		long long ans=0;
		for(int i=1;i<=n;i++)
			ans=ans+abs(a[i]-a[n/2]);
		printf("%lld\n",ans);
		return 0;
	}
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
#        for line in sys.stdin:
#            lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n, k = [int(e) for e in lines[0].split(" ")]

    hs = [int(e) for e in lines[1].split(" ")]

    return (n, k, hs)


def solve(n, k, hs):


    result = len([h for h in hs if h >= k])

    return result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 12368
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef unsigned int ui;
typedef long long ll;
const ui P=1000000007;
ui F[4040][4040];
ui C[8080],I[8080];
int T[200200][2];
#define f(i,j) F[i+2020][j+2020]
int main(){
	int N;scanf("%d",&N);
	for(int i=0;i<N;++i)
		scanf("%d%d",T[i],T[i]+1),++f(T[i][0],T[i][1]);
	C[0]=1,I[8000]=624583629;
	for(ll i=1;i<=8000;++i)C[i]=C[i-1]*i%P;
	for(ll i=8000;i;--i)I[i-1]=I[i]*i%P;
	#define calc(a,b) (C[(a)]*ll(I[(b)])%P*I[(a)-(b)]%P)
	for(int i=2000;i>=-2000;--i)
		for(int j=2000;j>=-2000;--j)
			f(i,j)=(f(i,j)+f(i+1,j)+f(i,j+1))%P;
	ui ans=0;
	for(int i=0;i<N;++i)
		ans=(ans+f(-T[i][0],-T[i][1])+P-calc((T[i][0]+T[i][1])*2,T[i][0]*2))%P;
	printf("%lld\n",ans*500000004ll%P);
	return 0;
}

Measured memory_bytes: 65024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    string s;
    cin >> s;
    int l = -1, r = -1;
    rep(i, 0, s.size()){
        if(s[i] =='A'){
            l = i; break;
        }
    }
    repb(i, s.size() - 1, 0){
        if(s[i] == 'Z'){
            r = i; break;
        }
    }
    cout << r - l + 1 << endl;
}

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

int main() {
    int n, p;
    cin >> n;
    string s;
    tuple<string, int, int> spi[n];
    rep(i, n) {
        cin >> s >> p;
        p = -p;
        spi[i] = tie(s, p, i);
    }
    sort(spi, spi + n);
    rep(i, n) {
        cout << get<2>(spi[i])+1 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int n, m;
int l, r, ll, rr;
int main() {
	scanf("%d%d", &n, &m);
	ll = 0; rr = 1000000;
	for (int i = 0; i < m; i++) {
		scanf("%d%d", &l, &r);
		if (ll < l)ll = l;
		if (rr > r)rr = r;
	}
	if (ll > rr)printf("0");
	if (ll <= rr)printf("%d", rr - ll + 1);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	ll a[n+1],b[n];
	forn(i,0,n+1) cin>>a[i];
	forn(i,0,n) cin>>b[i];
	
	ll cnt=0;
	forn(i,0,n){
		if(b[i]<=a[i]){
			cnt+=b[i]; a[i]-=b[i];
		}
		else{
			b[i]-=a[i];
			cnt+=a[i];
			cnt+=min(b[i],a[i+1]);
			a[i+1]-=min(b[i],a[i+1]);
		}
	}
	
	cout<<cnt<<'\n';
	
	return 0;
}


Measured memory_bytes: 5196
import Control.Monad (replicateM)

main :: IO ()
main = do
    [h, w] <- map read . words <$> getLine
    a <- replicateM h getLine
    putStr . solve $ a

solve :: [String] -> String
solve a = replicate l '#' ++ "\n"
       ++ (concat . map (\s -> "#" ++ s ++ "#\n") $ a)
       ++ replicate l '#' ++ "\n" where
    l = length (head a) + 2

Measured memory_bytes: 1404
x,y = map(int,input().split())

for i in range(x+1):
    for i2 in range(x+1-i):
        i3 = x-(i+i2)
        y1 = y-(10000*i+5000*i2+1000*i3)
        if y1 == 0:
            break
    if y1==0:
        break
if y1==0:
    print(i,i2,i3)
else:
    print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    cin >> n;
    int big,small;
    rp(i,n){
        int a;
        cin >> a;
        if(i==0){
            big=small=a;
            continue;
        }
        chmax(big,a);
        chmin(small,a);
    }
    print(big-small);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 256
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("src/aoj1174/input.txt"));
			//System.setOut(new PrintStream(new FileOutputStream("src/aoj1172/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}

	Scanner sc;
	void run() {
		sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			if (n == 0) break;
			solve(n);
		}
	}

	void solve(int n) {
		int[] xs = new int[n];
		int[] ys = new int[n];
		int[] rs = new int[n];
		int[] cs = new int[n];
		for (int i = 0; i < n; i++) {
			xs[i] = sc.nextInt();
			ys[i] = sc.nextInt();
			rs[i] = sc.nextInt();
			cs[i] = sc.nextInt();
		}
		boolean[][] isOver = new boolean[n][n];
		for (int i = 0; i < n; i++)
			for (int j = i + 1; j < n; j++) {
				if ((xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j]) < (rs[i] + rs[j]) * (rs[i] + rs[j])) {
					isOver[i][j] = true;
				}
			}

		int ans = 0;
		boolean[] visited = new boolean[1 << n];
		visited[(1 << n) - 1] = true;
		for (int set = (1 << n) - 1; set >= 0; set--) {
			if (!visited[set]) continue;
			ans = max(ans, n - Integer.bitCount(set));

			for (int i = 0; i < n; i++) if ((set >> i & 1) == 1)
				for (int j = i + 1; j < n; j++) if ((set >> j & 1) == 1)
					if (cs[i] == cs[j]){
						boolean ok = true;
						for (int k = i - 1; k >= 0; k--) if ((set >> k & 1) == 1 && isOver[k][i]) ok = false;
						for (int k = j - 1; k >= 0; k--) if ((set >> k & 1) == 1 && isOver[k][j]) ok = false;

						if (ok) {
							int nset = set;
							nset ^= (1 << i);
							nset ^= (1 << j);
							visited[nset] = true;
						}
				}
		}
		System.out.println(ans);
	}

	void tr(Object... os) {
		System.err.println(deepToString(os));
	}
}

Measured memory_bytes: 28000
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

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

	string s;
	cin >> s;

	ll ans = 0;

	ll blackCnt = 0;
	ll whiteCnt = 0;
	// 黒より右にある白の数をすべて数える
	rep(i, s.size()) {
		if (s[i] == 'B') blackCnt++;
		else whiteCnt++;
	}

	rep(i, s.size()) {
		if (s[i] == 'B') {
			ans += whiteCnt;
		}
		else {
			whiteCnt--;
		}
	}

	cout << ans << endl;

	return 0;
}

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

void getAC() {	
	ios_base :: sync_with_stdio(false); cin.tie(0);
	int n , m; cin >> n >> m;
	if (n == m) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}
 
int main() {	
	getAC();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

vector<int> pow2{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912};
vector<ll> factorial(2,1);
ll nckmodp(ll n,ll k,ll p){
  if(n < k || n <= 0 || k < 0)return 1;
  while(factorial.size() <= n){
    ll i = factorial.size();
    factorial.push_back(i*factorial[i-1]%p);
  }
  ll n1 = factorial[n],n2 = factorial[k],n3 = factorial[n-k];
  vector<ll> a2,a3;
  FOR(i,0,pow2.size()){
    a2.push_back(n2);
    a3.push_back(n3);
    n2 = (n2*n2)%p;
    n3 = (n3*n3)%p;
  }
  n2 = 1;
  n3 = 1;
  FOR(i,0,pow2.size()){
    if(pow2[i]&(p-2)){
      n2 *= a2[i];
      n3 *= a3[i];
      n2 %= p;
      n3 %= p;
    }
  }
  return (n1*n2%p)*n3%p;
}

int main(){
  ll H,W,A,B;
  cin >> H >> W >> A >> B;
  ll ans = nckmodp(H-1+W-1,H-1,INF);
  FOR(i,0,B)ans = (INF+ans-(nckmodp(H-A-1+i,i,INF)*nckmodp(A-1+W-1-i,A-1,INF))%INF)%INF;
  cout << ans << endl;
}


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

int main() {
  int n;
  cin>>n;
  vector<int> A(n);
  rep(i,n) cin>>A[i];
  if(n%2==0){
    rep(i,n/2) cout<<A[n-1-2*i]<<" ";
    rep(i,(n+1)/2) cout<<A[2*i]<<" ";
  }
  else{
    rep(i,(n+1)/2) cout<<A[n-1-2*i]<<" ";
    rep(i,n/2) cout<<A[2*i+1]<<" ";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007
//#define MOD 7

using namespace std;

int main(void){
    // Your code here!
    long long a, b;
    long long count = 0;
    
    cin >> a >> b;
    for(int i = 1; i < b - a; i++)
        count += i;
        
    cout << count - a << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

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

    int H, W;
    string s = "";
    while(1){
        cin >> H >> W;
        if(H == 0 and W == 0){
            break;
        }else{
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    s += "#";
                }
                cout << s << endl;
                s = "";
            }
        }
        cout << endl;
    }

    return 0;
}

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

int main(){

    int n, m; cin >> n >> m;
    vector<int> a(n);
    vector<int> b(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];

    vector<int> vote(n, 0);
    for(int i = 0; i < m; i++){

        for(int j = 0; j < n; j++){
            if(a[j] <= b[i]){
                vote[j]++;
                break;
            }
        }
    }

    int ma = 0;
    int idx;
    for(int i = 0; i < n; i++){
        if(ma < vote[i]){
            ma = vote[i];
            idx = i + 1;
        }
    }

    cout << idx << endl;
    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>


int main(){

  int n, k, i, a, b;

  while(1){
    scanf("%d", &n);
    if(n==0)
      break;
    a=0;
    b=0;
    for(i=0;i<n;i++){
      scanf("%d", &k);
      if(k<=1) a++;
      if(k==0) b++;
    }
    if(n==a) printf("NA\n");
    else printf("%d\n", n-b+1);
  }
  
  
  return 0;
}

Measured memory_bytes: 612
#include<stdio.h>
#include<math.h>

int main( void ) 
{
 
    int n;
    scanf( "%d", &n );
    
    int i, j;
    int num[10000];
    int cnt = n;
    for( i=0; i<n; i++ ) {
        scanf( "%d", &num[i] );
    }
    for( i=0; i<n; i++ ) {    
        if( 2 == *(num+i) || 3 == *(num+i) ) { continue; }
        
        if( 0 == *(num+i)%2 ) {
            cnt--;
        } else {
            int max = sqrt( num[i] );
            for( j=3; j<=max; j+=2 ) {
                if( 0 == *(num+i)%j ) {
                    cnt--;
                    break;
                }
            }
        }
    }
     
    printf( "%d\n", cnt );
    
    return 0;
}

Measured memory_bytes: 628
data = [input() for x in range(0, 2, 1)]

num = [int(x) for x in data[1].split(" ")]

flag = 0
cnt = 0

while flag == 0:
  
  #偶数かチェック:
  for i in range(0, len(num), 1):
    if num[i] %2 == 0:
      pass
    else:
      flag = 1
      
  if flag == 1: break
        
 #置換
  for i in range(0, len(num), 1):
    num[i] = num[i] / 2
      
  cnt += 1
    
print(cnt)
      
  


Measured memory_bytes: 3064
s=input()
t=input()
count=0
if len(s)==len(t):
    for i in range(len(t)):
        if t[i]!=s[i]:
            count+=1
    print(count)
    exit()
ans=10000
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if t[j]!=s[i+j]:
            count+=1
    ans=min(ans,count)
    count=0
print(ans)

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

int main()
{
  int n;
  cin >> n;
  vector <int> d(n);
  for (int i = 0; i < n; i++){
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int ans = 1;
  for (int i = 0; i < n - 1; i++){
    if (d.at(i) != d.at(i + 1)) ans++;
  }
  cout << ans << endl;
}

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

int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(a[0] == 5 && a[1]==5 && a[2]==7){
    cout<<"YES"<<endl;
  } else{
    cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
int n,k;
char s[110];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>k>>s+1;
	n=strlen(s+1);
	if(n<=k) printf("%s\n",s+1);
	else{
		rep(i,1,k) cout<<s[i];
		puts("...");
	}
	return 0;
}

Measured memory_bytes: 3636
N, M = map(int,input().split())
interval=[[] for i in range(N)]
for i in range(M):
    l, r, a = map(int,input().split())
    interval[r-1].append((l-1, a))

# N: 処理する区間の長さ
INF = 10**30-1

LV = (N-1).bit_length()
N0 = 2**LV
data = [0]*(2*N0)
lazy = [0]*(2*N0)

def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if not v:
            continue
        lazy[2*i-1] += v; lazy[2*i] += v
        data[2*i-1] += v; data[2*i] += v
        lazy[i-1] = 0

# 区間[l, r)にxを加算
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] += x; data[R-1] += x
        if L & 1:
            lazy[L-1] += x; data[L-1] += x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = max(data[2*i-1], data[2*i])

# 区間[l, r)内の最大値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = -INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

dp=[0]*N # dp[i] = max upto i. SegTree maintans max s.t. rightmost 1 is at i

for i in range(N):
    for j in range(len(interval[i])):
        l, a = interval[i][j]
        update(l, i+1, a)
    dp[i] = max(query(0, i+1), 0)
    update(i+1, i+2, dp[i]) # write "max up to i" at i+1 so that, in the next step, updates yields "max s.t. rightmost 1 is at i+1"

print(dp[-1])

Measured memory_bytes: 123396
temp=input()
temp=temp.split(" ")
p=[]
for i in temp:
    p.append(int(i))
if p[0]+p[1]==p[2]+p[3]:
    print("Balanced")
if p[0]+p[1]<p[2]+p[3]:
    print("Right")
if p[0]+p[1]>p[2]+p[3]:
    print("Left")


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

int main()
{
	string s;
	cin>>s;
	int i=s[s.size()-1]-'0';
	if(i==2||i==4||i==5||i==7||i==9)
		cout<<"hon"<<endl;
	else if(i==0||i==1||i==6||i==8)
		cout<<"pon"<<endl;
	else
		cout<<"bon"<<endl;
	return 0;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var S = Console.ReadLine();
            var answer = (S.Length >= 6 && S[2] == S[3] && S[4] == S[5]) ? "Yes" : "No";
            Console.WriteLine(answer);
        }
    }
}


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

int main(void) {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> r;
  string s;
  int p;
  for (int i = 0; i < N; i++) {
    cin >> s >> p;
    r.emplace_back(s, -p, i);
  }
  sort(r.begin(), r.end());
  for (int i = 0; i < N; i++) {
    cout << get<2>(r[i]) + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = list(input())
n = len(N)
K = int(input())

dp1 = [[0] * (K + 1) for _ in range(n + 1)] #N以下が確定していて、0以外の数をk個使ったとき
dp2 = [0] * (n + 1) #N以下が確定していないときの0以外の数の個数

for i in range(n):
    a = int(N[i])

    if a != 0:
        dp2[i + 1] = dp2[i] + 1
    else:
        dp2[i + 1] = dp2[i]
    
    #0を使うことで0以外の数が増えないパターン
    for k in range(K + 1):
        dp1[i + 1][k] = dp1[i][k]

    #0以外の数を使うことで0以外の数が増えるパターン
    for k in range(K):
        dp1[i + 1][k + 1] += dp1[i][k] * 9
    
    #今回でN以下が確定するパターン
    tmp = dp2[i] #確定する前までに0以外の数を何個使っているか
    if a == 0: #今回でN以下が確定することはない
        continue
    else:
        if tmp > K: #すでにK個以上の0以外の数を使っているとき
            continue
        else:
            if tmp == K: #ちょうどK個使っている時
                dp1[i + 1][tmp] += 1 #0を使うしかない
            else:
                dp1[i + 1][tmp] += 1 #0を使うしかない
                dp1[i + 1][tmp + 1] += (a - 1) #N以下を確定させるためaは使えない

ans = dp1[n][K]
if dp2[n] == K:
    ans += 1

print (ans)

# print (dp1)
# print (dp2)

Measured memory_bytes: 3064
#include <stdio.h>
#define sentinel 1000000000
#define N 500000

int count=0;

void Merge(int a[],int left,int mid,int right){
  int n1,n2,i,j,L[N],R[N],k;
  n1= mid-left;
  n2 = right - mid;
  for(i=0;i<n1;i++){
    L[i] = a[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=a[mid+i];
  }

  L[n1]=sentinel;
  R[n2]=sentinel;

  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i]<R[j]){
      a[k]=L[i];
      i++;
      count++;
    }else{
      a[k] = R[j];
      j++;
      count++;
    }
  }
}



void Merge_sort(int a[],int left,int right){
  int mid;
  if(left+1<right){
  mid = (left + right )/2;
  Merge_sort(a,left,mid);
  Merge_sort(a,mid,right);
  Merge(a,left,mid,right);
}

}



int main(){
  int n,i,a[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  Merge_sort(a,0,i);
  for(i = 0; i < n-1  ; i++) {
   printf("%d ",a[i]);
 }

 printf("%d\n",a[n-1]);
 printf("%d\n",count);
 return 0;


}

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

using namespace std;
using ii = pair<int, int>;

vector<int> digits(int n)
{
    vector<int> ds;

    do {
        ds.push_back(n % 10);
        n /= 10;
    } while (n);

    reverse(ds.begin(), ds.end());

    return ds;
}
int solve(int N, const vector<ii>& xs)
{
    int a, b;

    if (N == 1)
    {
        a = 0;
        b = 9;
    } else if (N == 2)
    {
        a = 10;
        b = 99;
    } else
    {
        a = 100;
        b = 999;
    }

    for (int n = a; n <= b; ++n)
    {
        auto ds = digits(n);

        bool ok = true;

        for (auto x : xs)
        {
            auto i = x.first - 1, v = x.second;

            if (ds[i] != v)
            {
                ok = false;
                break;
            }
        }

        if (ok)
            return n;
    }

    return -1;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<ii> xs(M);

    for (int i = 0; i < M; ++i)
        cin >> xs[i].first >> xs[i].second;

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 109;
int a[N], b[N], c[N], d[N], n, m, q;
ll ans = 0;

void backtrack(int idx,int last, vector<int> &vv) {
	if(idx == n) {
		ll cur = 0;
		for (int i = 0; i < q; ++i) {
			if(vv[b[i]] - vv[a[i]] == c[i])
				cur += d[i];
		}
		ans = max(ans, cur);
		return;
	}
	for (int i = last; i < m; ++i) {
		vv.push_back(i);
		backtrack(idx + 1, i, vv);
		vv.pop_back();
	}
}

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	cin >> n >> m >> q;
	vector<int> vv;
	for (int i = 0; i < q; ++i) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		--a[i], --b[i];
	}
	vector<int> v;
	backtrack(0,0, v);
	cout << ans;
	return 0;
}


Measured memory_bytes: 3644
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
int K = sc.nextInt();
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};

System.out.println(A[K-1]);
    }
}



Measured memory_bytes: 21588
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*

*/

string s="Christmas",t=" Eve";
ll n;

int main(void){
	cin>>n;
	cout<<s;
	rep(i,25-n)cout<<t;
	cout<<endl;
	return 0;
}

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

const int mod = 1000000007;

long long rpow(long long n, long long p) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    long long tmp = rpow(n, p / 2);
    return tmp * tmp % mod;
  }
  return n * rpow(n, p - 1) % mod;
}

void Main() {
  int n, a, b;
  cin >> n >> a >> b;

  long long nn = (rpow(2, n) - 1) % mod;

  long long x = 1, y = 1;
  for (int i = 0; i < a; i++) {
    x = x * (n - i) % mod;
    y = y * (i + 1) % mod;
  }
  long long aa = x * rpow(y, mod - 2) % mod;
  x = 1; y = 1;
  for (int i = 0; i < b; i++) {
    x = x * (n - i) % mod;
    y = y * (i + 1) % mod;
  }
  long long bb = x * rpow(y, mod - 2) % mod;
  if (nn < aa + bb) cout << ((nn + mod - aa) % mod + mod - bb) % mod << endl;
  else cout << nn - aa - bb << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
import collections

N, X, Y = list(map(int, input().split()))
dists = [
        min(abs(j-i), abs(X-1-i)+1+abs(Y-1-j), abs(Y-1-i)+1+abs(X-1-j))
        for i in range(N-1) for j in range(i+1, N)
    ]
c = collections.Counter(dists)
ans = [c[K] for K in range(1,N)]
print(*ans, sep='\n')

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	if(s == "SAT")
	cout << 1;
	if(s == "SUN")
	cout << 7;
	if(s == "MON")
	cout << 6;
	if(s == "TUE")
	cout << 5;
	if(s == "WED")
	cout << 4;
	if(s == "THU")
	cout << 3;
	if(s == "FRI")
	cout << 2;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    vector<ll>b(0);
    sort(rall(a));
    b.pb(a[0]);
    ll ans=0;
    REP(i,1,n){
        ans+=b[i-1];
        b.pb(a[i]);
        b.pb(a[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9028
N = int(input())
h = list(map(int,input().split(' ')))
ans = 0
while sum(h) > 0:
  ans += 1
  flag = False
  for i in range(N):
    if h[i] > 0:
      h[i] -= 1
      flag = True
    elif flag is True:
      break

print(ans)



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

int n;

int main(){
	while( cin >> n ){
		if( n == -1 )break;
		
		int ans[30],cor = 0;
		
		if( n == 0 ){
			ans[0] = 0;cor++;
		}
		while( n > 0 ){
			ans[cor] = n%4;
			n/=4;
			cor++;
		}
		for(int i = cor-1;i>=0;i--)
			cout << ans[i];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
# C - Dice and Coin
n, k = list(map(int, input().split()))
prob = 0

for i in range(1, n+1):
    if i >= k:
        prob += 1/n
    else:
        m = 1
        while i*2**m < k:
            m += 1
        prob += 1/n * (0.5) ** m
        
print(prob)

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

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

  if (A < B) cout << B * 2 - 1 << endl;
  else if (A > B) cout << A * 2 - 1 << endl;
  else cout << A + B << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  vector<bool> dp(s.size() + 10, false);
  dp[0] = true;
  for (int i = 0; i < s.size(); i++) {
    if (!dp[i]) continue;
    if (s.substr(i, 5) == "dream") dp[i + 5] = true;
    if (s.substr(i, 7) == "dreamer") dp[i + 7] = true;
    if (s.substr(i, 5) == "erase") dp[i + 5] = true;
    if (s.substr(i, 6) == "eraser") dp[i + 6] = true;
  }
  if (dp[s.size()]) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> A(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        A[i] = make_pair(a, i + 1);
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < n; i++) {
        if (i) {
            cout << " ";
        }
        cout << A[i].second;
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int main(){
  string s;
  getline(cin,s);
  
  int q;
  scanf ("%d", &q);
  //string muda;
  //getline(cin,muda);
  //cout << q << endl;
  //q = atoi(muda.c_str());
  int jun = 1;

  string mae = "";

  for(int i=0; i<q ; i++){
    int t;
    scanf("%d", &t);
    //cout << t << endl;
    if(t==1){
      jun *= -1;
    }else{
  
      int f;
      char c;
      scanf(" %d %c ",&f, &c);
      //scanf("%c",&c);
      //f = fc[2] - '0'; c=fc[4]; //
      //cin >> f >> c ; //scanf("%d %s", &f, &c);
      //c#out << "input| " << f<< " " << c <<  endl;
    
      int jun2 = 1;
      if(f==1){
        jun2 = 1;
      }else{
        jun2 = -1;
      }

      if(jun * jun2 == 1){
        mae = mae + c;
      }else{
        s = s + c;        /* code */
      }
    }
  }

  //cout << jun << endl;
  if(jun == 1){
    for (int i = mae.size()-1; i>=0; i-- ){
      printf("%c",mae[i]);
    }
    for (int i = 0; i<s.size(); i++){
      printf("%c",s[i]);
    }
  }else{
    for (int i=1; i<=s.size();i++ ){
      printf("%c",s[s.size()-i]);
    }
    for (int i=0; i<mae.size(); i++){
      printf("%c",mae[i]);
    }
  }

  cout << endl;
  return 0;
}

Measured memory_bytes: 1580