akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int intpow(int a, int n) {
	// a^nのint ver
	rep(i, n - 1)
		a *= a;
	return a;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1)) % mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n, int k) {
	//nのk桁目
	rep(i, k - 1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int binary(int n) {
	//10進数→2進数
	int ans = 0;
	for (int i = 0; n > 0; i++) {
		ans += n % 2 * intpow(10, i);
		n /= 2;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	string S;
	cin >> S;
	if (S[2] == S[3] && S[4] == S[5])
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
h = 0
w = 0
listh = []
listw = []
count = 0

while(True):
    h, w = map(int,input().split())
    if h ==0 and w == 0:
        break
    listh.append(h)
    listw.append(w)
    count += 1

for i in range(count):
    str = ''
    for h in range(listh[i]):  
        for w in range(listw[i]):
            str += '#'
        print(str)
        str = ''
    print('')


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

using namespace std;

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

    int tt = 0, ft = 0, ot = 0;
    bool ans = false;
    
    for (ft = 0 ; ft <= N ; ft++) {
        for (ot = 0 ; ot <= N - ft ; ot++) {
            tt = N - ft - ot;
            if( (10000 * tt) + (5000 * ft) + (1000 * ot) == Y) {
                ans = true;
                break;
            }
        }
        if (ans) break;
    }
    
    if (! ans) cout<<"-1 -1 -1"<<endl;
    else cout<<tt<<" "<<ft<<" "<<ot<<endl;
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
height_lst = list(map(int,input().split()))
flag = True

if n==1:
    print('Yes')
else:
    if height_lst[0]==1:
        height1 = 1
    elif height_lst[0]>1:
        height1 = height_lst[0]-1

    for i in range(1,n):
        height = height_lst[i]
        if height==1:
            possible_lst = [1]
        elif height>1:
            possible_lst = [height-1,height]

        if max(possible_lst)<height1:
            flag = False
            break
        else:
            if min(possible_lst)>=height1:
                height1 = min(possible_lst)
            else:
                height1 = max(possible_lst)

    if flag:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 14396
def ans_num(num):
    min_list=(sorted(num,reverse=True))
    #print(min_list)
    max_list=sorted(num)
    #print(max_list)
    max_num=0
    min_num=0
    for i in range(len(num)):
        max_num+=max_list[i]*(10**i)
        min_num+=min_list[i]*(10**i)
    return max_num-min_num

N=int(input())
for i in range(N):
    num=list(map(int,input()))
    print(ans_num(num))
    
    



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int> > ab(m);
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(m<a)continue;
        ab[m-a].push_back(b);
    }
    priority_queue<int> q;
    int ans=0;
    for(int i=m-1;i>=0;i--){
        for(int b : ab[i]){
            q.push(b);
        }
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
int main(){	
    long long x,i=2,sum=1;
    cin>>x;
    for(;i<=x;i++){
    	if(i%3==0||i%5==0);
    	else	sum+=i;
	}
	cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int p=0;
    while(n>0)
    {
        int x=n%10;
 
        if(x==7)
        {
            p=1;
            break;
 
        }
        n=n/10;;
    }
    if(p)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 3596
S = input()
mod = 2019

array = []
for i in range(len(S)):
    x = (int(S[len(S)-1-i])*pow(10,i,mod))%mod
    array.append(x)
array2 = [0]
y = 0
for i in range(len(S)):
    y = (y+array[i])%mod
    array2.append(y)
array3 = [0] * 2019
ans = 0
for i in range(len(array2)):
    z = array2[i]
    ans += array3[z]
    array3[z] += 1
print(ans)
#3*673


Measured memory_bytes: 23792
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    int n;cin>>n;
    int x = n%1000;
    cout << (x==0 ? 0 : 1000-x) << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long
#define mod 1000000007

signed main(void)
{
	int n; cin >> n;
	if (n <= 1) {cout << "0" << endl; return 0;}
	int ans, a = 1, b = 1, c = 1;
	rep (i, n)
	{
		a *= 10; a %= mod;
		b *= 9; b %= mod;
		c *= 8; c %= mod;
	}
	ans = a - 2 * b + c;
	ans %= mod;
	if (ans < 0) ans += mod;
	cout << ans << endl;
}


Measured memory_bytes: 3608
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    
    System.out.println((A + B) % 24);
  }

}


class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 21332
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''


a,b,c = map(int,input().split())
if( (a==b and a!=c) or (b==c and b!=a) or (a==c and a!=b) ):
	print("Yes")
else:
	print("No")


Measured memory_bytes: 38256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//  10:00-
bool solve(void){
	int n,m,i,j;cin>>n>>m;
	if(n==0){return false;}
	vector<int>a(n);
	int ans=-1;
	for(i=0;i<n;i++){cin>>a[i];}
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(a[i]+a[j]<=m){maxeq(ans,a[i]+a[j]);}
		}
	}
	if(ans==-1){cout<<"NONE"<<endl;}
	else{cout<<ans<<endl;}
	return true;
}
int main(void){
	while(solve()){}
}



Measured memory_bytes: 3076
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, S := nextInt(), nextLine()
	ans := 0
	for i := 0; i+3 <= N; i++ {
		if S[i:i+3] == "ABC" {
			ans++
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1816
import numpy as np

N, M, C = map(int, input().split())

B = list(map(int, input().split()))
Ai = []
for n in range(N):
    Ai.append(list(map(int, input().split())))

B = np.array(B)
count = 0
for a in Ai:
    a = np.array(a)
    if (a * B).sum() + C > 0:
        count += 1

print(count)


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

int main() {
    int n;
    cin >> n;
    int ans = (n + 1.07) / 1.08;
    if (floor(ans * 1.08) != n) {
        cout << ":(" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define ll unsigned long long
using namespace std;
ll h,c;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(); cout.tie();
  
    cin>>h>>c;
    ll res=h*c;
    if ((h>1) && (c>1)) cout<<(res+1)/2;
    else cout<<1;

}



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

int main(){
	int d, hd;
	int sum;
	while(cin >> d){
		sum = 0;
		hd = d;
		while(hd < 600){
			sum += hd*hd*d;
			hd += d;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim a As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim b As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim c As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim ans As Integer = 0
    Dim before As Integer = -1
    For i As Integer = 0 To n - 1
      ans += b(a(i) - 1)
      If a(i) = before + 1 Then ans += c(before - 1)
      before = a(i)
    Next
    Console.WriteLine(ans.ToString())
  End Sub
End Class

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int B[1000000];
int m;
vector<int> G;

void insertionSort(int B[], int m, int g)
{
int i=0;
for(i=g ; i<m ; i++)
{
int v =B[i];
int j= i-g;
while(j>=0 && B[j]>v)
{
B[j+g]=B[j];
j-=g;
cnt++;
}
B[j+g]=v;
}
}

void shellSort(int B[], int m)
{
  int i=0;
  int h=0;
for (h=1; ; )
{
if(h>m)break;
G.push_back(h);
h=3*h+1;
}
for(i=G.size()-1;i>=0;i--)
{
insertionSort(B,m,G[i]);
}
}

int main()
{
int i=0;

cin>> m;
for(i=0;i<m; i++)
{
scanf("%d",&B[i]);
}
cnt = 0;

shellSort(B,m);

cout << G.size() << endl;
for(i = G.size()-1;i>=0;i--)
{
printf("%d",G[i]);
if(i)printf(" ");
}
printf("\n");
printf("%d\n",cnt);
for(i=0;i<m; i++)
{
printf("%d\n",B[i]);
}
return 0;
}



Measured memory_bytes: 7160
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main() {
	int K, N;
	cin >> N >> K;
	vector<int> D(K);
	for (int i = 0; i < K; i++) {
		cin >> D[i];
	}
	for (int x = N; x < 100000; x++) {
		set<int> s;
		int tmp = x;
		while (tmp != 0) {
			s.insert(tmp % 10);
			tmp = tmp / 10;
		}
		bool flag = true;
		for (int i = 0; i < K; i++) {
			if (s.count(D[i]) != 0) {
				flag = false;
			}
		}
		if (flag) {
			cout << x;
			break;
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	ll m=0,a=0,r=0,c=0,h=0;
	rep(i,N){
		string s; cin>>s;
		if(s[0]=='M') m++;
		else if(s[0]=='A') a++;
		else if(s[0]=='R') r++;
		else if(s[0]=='C') c++;
		else if(s[0]=='H') h++;
	}

	ll d[5];
	ll A[10]={0,0,0,0,0,0,1,1,1,2};
	ll B[10]={1,1,1,2,2,3,2,2,3,3};
	ll C[10]={2,3,4,3,4,4,3,4,4,4};
	d[0]=m,d[1]=a,d[2]=r,d[3]=c,d[4]=h;
	ll ans=0;
	for(int i=0;i<10;i++){
		ans+=d[A[i]]*d[B[i]]*d[C[i]];
	}
	cout<<ans;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

from itertools import combinations_with_replacement

N, M, Q = map(int, input().split()) 
ABCD = [list(map(int, input().split())) for _ in  range(Q)]

lst = list(combinations_with_replacement(range(1, M + 1), N))

ans = 0
for l in lst:
    tmp = 0
    for a, b, c, d in ABCD:
        if l[b - 1] - l[a - 1] == c:
            tmp += d
    ans = max(tmp, ans)
    
print(ans)

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

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

using namespace std;
using graph=vector<vector<int>>;

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

const int INF=1<<29;

vector<int> BFS(const graph& G,int s){
	int n=G.size();
	vector<int> d(n,INF);
	d[s]=0;
	queue<int> Q; Q.emplace(s);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		for(int v:G[u]) if(d[v]==INF) {
			d[v]=d[u]+1;
			Q.emplace(v);
		}
	}
	return d;
}

int main(){
	int h,w; scanf("%d%d",&h,&w);
	char B[20][21];
	rep(i,h) scanf("%s",B[i]);

	graph G(h*w);
	rep(i,h) rep(j,w) if(B[i][j]=='.') rep(k,4) {
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<=h && 0<=x && x<w && B[y][x]=='.') G[i*w+j].emplace_back(y*w+x);
	}

	int ans=0;
	rep(i0,h) rep(j0,w) {
		auto d=BFS(G,i0*w+j0);
		rep(i,h) rep(j,w) if(d[i*w+j]<INF) ans=max(ans,d[i*w+j]);
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] a = new String[H];
        for(int i = 0; i < H;i++){
            a[i] = sc.next();
        }
        boolean[] row = new boolean[H];
        Arrays.fill(row, false);
		boolean[] col = new boolean[W];
		Arrays.fill(col, false);
		for(int i = 0; i < H;i++){
		    for(int j = 0; j < W; j++){
		        if(a[i].charAt(j) == '#'){
		            row[i] = true;
		            col[j] = true;
		        }
		    }
		}
		for(int i = 0; i < H;i++){
		    if(row[i] == true){
		        for(int j = 0; j < W;j++){
		            if(col[j] == true){
		                System.out.print(a[i].charAt(j));
		            }
		           
		        }
		        System.out.println();
		    }
		}
    }
}


Measured memory_bytes: 25044
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));


		int N = sc.nextInt();
		String s = sc.next();

		char[] letters = s.toCharArray();
		int max=0;


		for (int i = 1; i < letters.length; i++) {
			ArrayList<Character> first = new ArrayList<>();
			ArrayList<Character> last = new ArrayList<>();

			boolean[] firstChecker = new boolean['z'-'a'+1];
			boolean[] lastChecker = new boolean['z'-'a'+1];

			for (int j = 0; j < i; j++) {
				first.add(letters[j]);
			}
			for (int j = i; j < letters.length; j++) {
				last.add(letters[j]);
			}

			for (Character character : first) {
				firstChecker['z'- character] = true;
			}
			for (Character character : last) {
				lastChecker['z'- character] = true;
			}




			int thisResult = 0;

			for (int j = 0; j < firstChecker.length; j++) {
				if (firstChecker[j] && lastChecker[j]) {
					thisResult++;
				}
			}
			if (thisResult>max) {
				max = thisResult;
			}
		}

		out.println(max);
		out.close();
	}

	//-----------http://codeforces.com/blog/entry/7018---------------------------------
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	}
	//--------------------------------------------------------

}


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

int main(){
    int H,W;
    while(1){
       cin >> H >> W; 
       if(H==0&&W==0) break;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if((i+j)%2==0){
              cout << "#";
              }else{
                  cout << ".";
              }
            }
            cout << "\n";
        }
        cout << endl;
    }
    
    return 0;
}


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

int main(void){
	double xa=0, ya=0;
	double x, sita=90;
	double sita2;
	
	while(1){
		scanf("%lf, %lf", &x, &sita2);
		if(x == 0 && sita2 == 0){
			break;
		}
		
		xa += x * cos(sita * M_PI / 180);
		ya += x * sin(sita * M_PI / 180);
		sita -= sita2;
	}
	
	if(xa <= 0){
		printf("%.0f\n", ceil(xa));
	}else{
		printf("%.0f\n", floor(xa));
	}
	if(ya <= 0){
		printf("%.0f\n", ceil(ya));
	}else{
		printf("%.0f\n", floor(ya));
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  vector<int> t(26,0);
  bool ans = true;
  for(int i =0;i<s.size();i++){
    t.at(s.at(i) - 'a')++;
  }
  for(int i:t){
    if( i %2 !=0){
      ans = false;
    }
  }
  cout << (ans ? "Yes":"No");
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
#define int long long
int a,b,c,k;
#undef int
int main()
{
	#define int long long
	cin>>a>>b>>c>>k;
	while(b<=a && k>=0)b*=2,--k;
	while(c<=b && k>=0)c*=2,--k;
	if(k>=0)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
int main()
{   ll n,k;cin>>n>>k;
     ll a[n];
 for(ll i=0;i<n;i++){
   cin>>a[i];
 }
 sort(a,a+n);
 ll ans=0;
 ll i=0;
 while(k>0){
   ans+=a[i];
   i++;
   k--;
 }
 cout<<ans<<endl;
 
 
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(void)
{
	char s[7];

	cin >> s;

	if (s[0] == 'S')
		cout << "Cloudy" << endl;
	else if(s[0] == 'C')
		cout << "Rainy" << endl;
	else if(s[0] == 'R')
		cout << "Sunny" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
#define maxn 100005
const ll mod = 1000000007;
int n;
ll x[maxn],f[maxn],fct[maxn],down[maxn];
int main(){
  n = getint();
  for(int i = 1;i <= n;i++) x[i] = getll();
  fct[0] = 1;
  for(int i = 1;i <= n;i++) fct[i] = fct[i - 1] * i % mod;
  down[0] = 1;
  for(int i = 1;i < n;i++) down[i] = down[i - 1] * (n - i) % mod;
  // f[0] = 0;
  for(int i = 1;i <= n;i++){
    f[i] = (f[i - 1] + fct[i] + (i - 1) * (f[i - 1] - fct[i - 1])) % mod;
    (f[i] += mod) %= mod;
  }
  ll ans = 0;
  for(int i = 1;i < n;i++){
    (ans += f[i] * down[n - i - 1] % mod * (x[i + 1] - x[i])) %= mod;
  }
  putll(ans,'\n');
  bufo.flush();
  return 0;
}


Measured memory_bytes: 3456
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}

int X, N;
int p[110];
int ans = 101;

int main() {
    cin >> X >> N;
    //Nはpの個数
    REP(i, N) cin >> p[i];
    sort(p, p + N);

    for (int i = 100; i >= -1; i--) {
        if (abs(ans - X) >= abs(i - X)) {
            bool chk = true;
            REP(j, N) if (i == p[j]) {
                chk = false;
            }
            if (chk) ans = i;
        }
    }
    //REP(i, 100) {
    //    cout << i + 1 << endl;
    //}
    cout << ans << endl;
}


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

using namespace std;

vector <string> sh;

map <string, int> ans;

int main() {
  int n, maxx = 0;
  string tr;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> tr;
    ++ans[tr];
  }
  for (pair <string, int> e: ans) {
    maxx = max(maxx, e.second);
  }
  for (pair <string, int> e: ans) {
    if (e.second == maxx) {
      sh.push_back(e.first);
    }
  }
  sort(sh.begin(), sh.end());
  for (int i = 0; i < sh.size(); ++i) {
    cout << sh[i] << '\n';
  }
}


Measured memory_bytes: 26868
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int h = sc.nextInt();
        int m = sc.nextInt();

        double thetaA = 30 * h + 0.5 * m;
        double thetaB = 6 * m;
        double theta = thetaA - thetaB;
        double x = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(theta * Math.PI / 180));
        System.out.println(x);
        // out.println("Hello World");
        out.flush();
    }

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

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


Measured memory_bytes: 36084
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

int main()

{

	double a, p;	int N;

	cin >> N;

	if (N % 2 == 0)

		p = N / 2;

	else

		p = N / 2 + 1;

	a = p / N;

	printf("%.10lf\n", a);

	return 0;

}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	
	public void solve() throws IOException {
		char[][] data = new char[8][];
		for(int i = 0; i < 8; i++){
			data[i] = nextToken().toCharArray();
		}
		writer.println(90);
		for(int i = 0; i < 8; i++){
			for(int j = 7; j >= 0; j--){
				writer.print(data[j][i]);
			}
			writer.println();
		}
		writer.println(180);
		for(int i = 7; i >= 0; i--){
			for(int j = 7; j >= 0; j--){
				writer.print(data[i][j]);
			}
			writer.println();
		}
		writer.println(270);
		for(int i = 7; i >= 0; i--){
			for(int j = 0; j < 8; j++){
				writer.print(data[j][i]);
			}
			writer.println();
		}
		writer.flush();
	}
	public static void main (String args[]) throws IOException {
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 9308
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Bismillahirrahmanirrahim
#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k,dp[105][7][7][7][7];
string s;
vector<int> v;

inline lo add(lo x,lo y){
	if(x+y>=mod) return x+y-mod;
	return x+y;
}

inline lo f(lo sira,lo son0,lo son1,lo son2,lo son3){
	lo cevv=0;
	if((son1==1 && son2==2 && son3==3) || (son1==1 && son2==3 && son3==2) || (son1==2 && son2==1 && son3==3) || (son0==1 && son2==2 && son3==3) || (son3==3 && son1==2 && son0==1)) return 0;
	if(sira>n) return 1;
	if(~dp[sira][son0][son1][son2][son3]) return dp[sira][son0][son1][son2][son3];
	//~ if(son1==0){
		//~ cevv+=f(sira+1,1,son1,son2,son3);
		//~ cevv+=f(sira+1,2,son1,son2,son3);
		//~ cevv+=f(sira+1,3,son1,son2,son3);
		//~ cevv+=f(sira+1,4,son1,son2,son3);
	//~ }
	else if(son1==0){
		cevv=add(cevv,f(sira+1,son0,1,son2,son3));
		cevv=add(cevv,f(sira+1,son0,2,son2,son3));
		cevv=add(cevv,f(sira+1,son0,3,son2,son3));
		cevv=add(cevv,f(sira+1,son0,4,son2,son3));
	}
	else if(son2==0){
		cevv=add(cevv,f(sira+1,son0,son1,1,son3));
		cevv=add(cevv,f(sira+1,son0,son1,2,son3));
		cevv=add(cevv,f(sira+1,son0,son1,3,son3));
		cevv=add(cevv,f(sira+1,son0,son1,4,son3));
	}
	else if(son3==0){
		cevv=add(cevv,f(sira+1,son0,son1,son2,1));
		cevv=add(cevv,f(sira+1,son0,son1,son2,2));
		cevv=add(cevv,f(sira+1,son0,son1,son2,3));
		cevv=add(cevv,f(sira+1,son0,son1,son2,4));
	}
	//~ else if(son1==1 && son2==2){
		//~ cevv+=f(sira+1,1,2,2);
		//~ cevv+=f(sira+1,1,2,1);
		//~ cevv+=f(sira+1,1,2,4);
	//~ }
	else{
		cevv=add(cevv,f(sira+1,son1,son2,son3,2));
		cevv=add(cevv,f(sira+1,son1,son2,son3,1));
		cevv=add(cevv,f(sira+1,son1,son2,son3,4));
		cevv=add(cevv,f(sira+1,son1,son2,son3,3));
	}
	return dp[sira][son0][son1][son2][son3]=cevv;
}

int main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld",&n);
	printf("%lld\n",f(1,0,0,0,0));
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long
#define fori(i,n) for (int i=0; i<int(n);i++)
#define srt(v) sort(v.begin(), v.end())
const int INF = 1e9;
const double PI = 3.14159265358979323846;

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

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

void solve(){

}

int main(){
	load;
    int target, n;
    cin >> target >> n;
    if (n==0){
    	cout << target;
    	return 0;
    }
    vector<int> v(n);
    set<int> s;
    fori(i, n){
    	cin >> v[i];
    	s.insert(v[i]);
    }
    int d, minD = INF, ans = 0;
    for(int i=-150; i<=150; i++){
	   if (s.find(i) != s.end()) continue;
	   d = abs(target - i);
	   if (d < minD){
		   minD = d;
		   ans = i;
	   }
    }
    cout <<ans;

    return 0;
}



Measured memory_bytes: 3664
#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 int long long
using namespace std;

int n;

signed main(){
    int ans = 0;
    while(1){
        cin >> n;
        if(n == 0) break;
        int t[10010];
        rep(i, 0, n) cin >> t[i];
        sort(t, t + n);
        rep(i, 0, n){
            ans += t[i] * (n - 1 - i);
        }
        cout << ans << endl;
        ans = 0;
    }

}

Measured memory_bytes: 3128
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ n, k ] <- readInts
	ps :: [ Double ] <- map fromIntegral <$> readInts
	let
		ps' = map ( ( / 2 ) . succ ) ps
		( as, bs ) = ( take k &&& drop k ) ps'
		s = sum as
	printf "%.10f\n" $ maximum $ slide s ps' bs

slide s _ [] = [s]
slide s (a:as) (b:bs) = s : slide s' as bs
	where
		s' = s - a + b

Measured memory_bytes: 38268
def solve(N, S):
    alp = [chr(i) for i in range(65, 65+26)]
    new_text = ''

    for i in range(len(S)):
        new_char_i = alp.index(S[i]) + N

        if new_char_i >= len(alp):
            new_char_i -= len(alp)

        new_text += alp[new_char_i]

    return new_text


N = int(input())
S = input()

print(solve(N, S))


Measured memory_bytes: 40556
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    rep(i, 1000) {
        int s = i * b + c;
        if (s % a == 0) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int Q = sc.nextInt();
        StringBuilder sbL = new StringBuilder("");
        StringBuilder sbR = new StringBuilder("");
        boolean nowReverse = false;
        for (int i = 0; i < Q; i++) {
            int T = sc.nextInt();
            if (T == 1) {
                nowReverse = nowReverse? false : true;
            } else {
                int F = sc.nextInt();
                String C = sc.next();
                if (F == 1) {
                    if (nowReverse) {
                        sbR.append(C);
                    } else {
                        sbL.append(C);
                    }
                } else {
                    if (nowReverse) {
                        sbL.append(C);
                    } else {
                        sbR.append(C);
                    }
                }
            }
        }
        String L = sbL.toString();
        String R = sbR.toString();
        S = reverseString(L) + S + R;
        System.out.println(nowReverse? reverseString(S) : S);
    }

    public static String reverseString(String S) {
        StringBuffer str = new StringBuffer(S);
        return str.reverse().toString();
    }
}


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

int main(){
    ll N;
    cin >> N;
    vector<ll> W(N);
    ll sum=0;
    rep(i,N){
        cin >> W[i];
        sum+=W[i];
    }
    ll ans=INF;
    ll tmp=0;
    rep(i,N-1){
        tmp+=W[i];
        ans = min(ans,abs((sum-tmp)-tmp));
    }
    cout << ans << endl;
}

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

double d(double x, double y, double z, double w){
	double ret;
	ret = pow(x *1000 - z * 1000, 2) + pow(y * 1000 - w * 1000, 2);
	return sqrtf(ret);
}

int main(){
	int n;
	double x[2], y[2], r[2], dd;
	cin >> n;
	for(int i = 0;i<n;i++){
		cin >> x[0] >> y[0] >> r[0] >> x[1] >> y[1] >> r[1];
		dd = d(x[0], y[0], x[1], y[1]);
		if(dd > (r[0]+r[1]) * 1000){
			cout << 0 << endl;
		}
		else if(dd + r[0] * 1000 < r[1] * 1000){
			cout << -2 << endl;
		}
		else if (dd + r[1] * 1000 < r[0] * 1000) {
			cout << 2 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3028
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    ll ans=0;
    if(k>a){
        ans = a;
        k -= a;
    }else{
        cout << k << endl;
        return 0;
    }
    
    if(k>b){
        k -=b;
    }else{
        cout << ans << endl;
        return 0;
    }
    
    ans -= k;
    cout << ans << endl;
    return 0;
}


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

const int MAXN = 1005;
int N, K;
int a[MAXN];
ll psum[MAXN];

int main() {
    // freopen("./input.txt", "r", stdin);
    cin >> N >> K;
    psum[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        psum[i] = a[i] + psum[i - 1];
    }
    vector<ll> sub;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= i; j++) {
            sub.push_back(psum[i] - psum[j - 1]);
        }
    }    
    sort(sub.begin(), sub.end());

    ll ans = 0;
    int size = sub.size();
    for (int i = 45; i >= 0; i--) {
        ll next = ans + ((ll)1 << i);
        int cnt = 0;
        for (int j = 0; j < size; j++) {
            if ((sub[j] & next) == next) {
                cnt++;
            }
        }
        if (cnt >= K) {
            ans = next;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

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

    IREP(i, (ll)sqrt(n)+1, 1){
        if(n%i==0){
            cout << (i+n/i-2) << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
def fact(n):
  v = 1
  for i in range(2, n + 1):
    v = v * i % 1000000007
  return v

n, m = map(int, input().split())
if abs(n - m) > 1:
  print('0')
elif n == m:
  print(2 * fact(n) * fact(m) % 1000000007)
else:
  print(fact(n) * fact(m) % 1000000007)

Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define ld long double
#define fast ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define F(i,a,b) for(int i= (int)(a); i<(int)(b);i++)
#define FI(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define what_is(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
const int N = 1e6+7 ;
string s ;

int32_t main(){fast ;
	int n,k ;
	cin >> n ;
	int ans = MOD ;
	while(n){
		int rem = n % 1000 ;
		cerr << rem  << ' ' << ans << endl ;
		ans = min(ans ,abs(753-rem)) ;
		n /= 10 ;
	}
	cout << ans << endl ;
}




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

int func(long long a, long long b){

    int a_size = to_string(a).size();
    int b_size = to_string(b).size();

    return max(a_size, b_size);

}

int main(){

    long long n;
    cin >> n;

    int Fmax = 10;
    for(int i = 1; i <= min((long long)100000, n); i++){
        if(n % i == 0){
            int F = func(i, n/i);
            Fmax = min(Fmax, F);
        } 
    }
    cout << Fmax << endl;

}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
result = 0
for i in range(x, n+1, 1):
    if i in a:
        ans += 1

for j in range(x, -1, -1):
    if j in a:
        result += 1
print(min(ans, result))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned char ubyte;

const ld EPS = 1e-10;
const ld PI = acos(-1.0);
const int INF = (int)1e9 + 5;
const ll LINF = (ll)1e18 + 5;

template<class T> 
ll abs(const T & x) { return x < 0 ? -x : x; }

template<class T> 
ll round(const T & x) { return x < 0 ? x - 0.5 : x + 0.5; }

template<class T> 
bool chmin(T & x, const T & y) {
	if (y < x) {
		x = y;
		return true;
	}
	return false;
}

template<class T>
ostream & operator <<(ostream & os, const vector<T> & v) {
	os << "{";
	for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); ++it) {
		os << *it;
		if ((it + 1) != v.end()) os << ", ";
	}
	os << "}";
	return os;
}

template<class P, class Q>
ostream & operator <<(ostream & os, const pair<P, Q> & p) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template<class T> 
bool chmax(T & x, const T & y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

#define all(a) (a).begin(), (a).end()

const int P = (ll)1e9 + 7;
const int MAX_MASK = 1 << 18;

int _F[MAX_MASK][2], _NF[MAX_MASK][2];

int main() {
	srand(time(0));
#ifdef LOCAL 
	freopen("input.txt", "r", stdin);
#else
#endif

	int n, x, y, z;

	cin >> n >> x >> y >> z;

	x += y + z;
	y += z;

	int needMask = (1 << x) | (1 << y) | (1 << z);

	auto F = _F;
	auto FN = _NF;

	F[1][0] = 1;

	for (int pref = 0; pref < n; pref++) {
		for (int mask = 0; mask < MAX_MASK; mask++) {
			for (int was = 0; was < 2; ++was) {
				int cur = F[mask][was];
				if (cur == 0) continue;
				for (int c = 1; c <= 10; c++) {
					int nmask = ((mask << c) & (MAX_MASK - 1)) | 1;
					int nwas = (was || ((nmask & needMask) == needMask));
					int & to = FN[nmask][nwas];
					to += cur;
					if (to >= P) to -= P;
				}
			}
		}
		swap(F, FN);
		memset(FN, 0, sizeof(_F));
	}

	int res = 0;

	for (int mask = 0; mask < MAX_MASK; mask++) {
		res = (res + F[mask][1]);
		if (res >= P) res -= P;
	}

	cout << res << endl;
}

Measured memory_bytes: 4352
N,M = map(int,input().split())
LRD = [list(map(int,input().split())) for _ in [0]*M]

E = [{} for _ in [0]*N]
for L,R,D in LRD:
    E[L-1][R-1] = D
    E[R-1][L-1] = -D

V = [None]*N
breakFlg = False
for i in range(N):
    if V[i]!=None:
      	continue
    V[i] = 0
    q = [i]
    while q:
        j = q.pop()
        v = V[j]
        for k,d in E[j].items():
            if V[k] == None:
                V[k] = v+d
                q.append(k)
ans = True
for l,e in enumerate(E):
    for r,d in e.items():
        ans = ans and V[r]-V[l]==d
    if not ans:
      	break
print("Yes" if ans else "No")


Measured memory_bytes: 113424