akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

INF = 10 ** 60

def li():
    return [int(x) for x in input().split()]


N = int(input())
h = li()

dp = [INF] * N

# 初期条件
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[N - 1])

Measured memory_bytes: 85408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
using namespace std;
#define ll long long


int main() {
    long N; cin >> N;
    ll ans=0;
    for(long i=1; i*(i+1)<N; ++i){
        if(N%i==0) ans += N/i-1;
    }
    cout << ans << endl;
    return 0;
}


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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int A,B,Q;
    cin >> A >> B >> Q;
    vector<ll> S;
    vector<ll> T;
    rep(i,A) {
        ll s;
        cin >> s;
        S.push_back(s);
    }
    rep(i,B) {
        ll t;
        cin >> t;
        T.push_back(t);
    }
    sort(S.begin(),S.end());
    sort(T.begin(),T.end());
    
    rep(i,Q) {
        ll ans = 1e18;
        ll x;
        cin >> x;
        auto idx_s = lower_bound(S.begin(),S.end(), x) - S.begin();
        auto idx_t = lower_bound(T.begin(),T.end(), x) - T.begin();

        int idx_sm = idx_s-1;
        int idx_tm = idx_t-1;
        if (idx_s==S.size()) idx_s = -1;
        if (idx_t==T.size()) idx_t = -1;

        if (idx_s!=-1 && idx_t!=-1) {
            ll tmp = max(S[idx_s]-x, T[idx_t]-x);
            ans = min(ans,tmp);
        }
        if (idx_sm!=-1 && idx_tm!=-1) {
            ll tmp = max(x-S[idx_sm], x-T[idx_tm]);
            ans = min(ans,tmp);
        }
        if (idx_s!=-1 && idx_tm!=-1) {
            ll tmp = S[idx_s]-x + 2*(x-T[idx_tm]);
            ans = min(ans,tmp);
            tmp = x-T[idx_tm] + 2*(S[idx_s]-x);
            ans = min(ans,tmp);
        }
        if (idx_t!=-1 && idx_sm!=-1) {
            ll tmp = T[idx_t]-x + 2*(x-S[idx_sm]);
            ans = min(ans,tmp);
            tmp = x-S[idx_sm] + 2*(T[idx_t]-x);
            ans = min(ans,tmp);
        }
        cout << ans << endl;

    }
}


Measured memory_bytes: 5536
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>
#include<cmath>


using namespace std;


int main(){

    int n;
    cin >> n;

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

    unsigned long long x = 1, y = 1;

    for(int i=0;i<n;i++){
        unsigned long long n = 1;
        n = max(n, (x+a[i]-1)/a[i]);
        n = max(n, (y+b[i]-1)/b[i]);
        x = n * a[i];
        y = n * b[i];
        //cout << ":" << x << "," << y << endl;
    }

    cout << x+y << endl;

}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	as := nextIntSlice(sc, n)
	next := 1
	count := 0
	for i := 0; i < len(as); i++ {
		if as[i] == next {
			next++
			continue
		} else {
			count++
		}
	}
	if len(as) == count {
		fmt.Println(-1)
		return
	}
	fmt.Println(count)
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 5116
import java.util.*;
 
class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int x[] = new int[N];
        int y[] = new int[N];
        int h[] = new int[N];
        for (int i = 0; i < N; i++) {
        	x[i] = sc.nextInt();
        	y[i] = sc.nextInt();
        	h[i] = sc.nextInt();
        }
        
        for (int Cx = 0; Cx <= 100; Cx++) {
            for (int Cy = 0; Cy <= 100; Cy++) {
            	int kh = -1;
            	boolean yn = true;
            	for (int i = 0; i < N; i++){
            		if (h[i] == 0) {
            			continue;
            		}
            		kh = h[i] + Math.abs(x[i] - Cx) + Math.abs(y[i] - Cy);
            		break;
            	}
            	for (int i = 0; i < N; i++){
            		int eh = Math.max(kh - Math.abs(x[i] - Cx) - Math.abs(y[i] - Cy),0);
            		if (eh != h[i]) {
            			yn = false;
            			break;
            		}
            	}
            	if (yn == false) {
            		continue;
            	} else {
            		System.out.printf("%d %d %d", Cx, Cy, kh);
            	}
            }
        }
    }
}

Measured memory_bytes: 22996
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> b[10];
int t[10];
int dp[11][2001];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,p;
	int i,j,k;
	for(i=0;i<10;i++)t[i]=0;
	scanf("%d %d",&n,&p);
	for(i=0;i<n;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		b[y-1].push_back(x);
		t[y-1]+=x;
	}
	for(i=0;i<10;i++){
		sort(b[i].begin(),b[i].end());
		b[i].push_back(0);
	}
	for(i=0;i<=10;i++)for(j=0;j<=p;j++)dp[i][j]=-1;
	dp[0][0]=0;
	for(i=1;i<=10;i++){
		for(j=0;j<=p;j++){
			int x=t[i-1];
			int c;
			for(k=0;k<b[i-1].size();k++){
				c=b[i-1].size()-k-1;
				if(j+c<=p&&dp[i-1][j]!=-1)dp[i][j+c]=max(dp[i][j+c],dp[i-1][j]+x+c*(c-1));
				x-=b[i-1][k];
			}
		}
	}
	printf("%d\n",dp[10][p]);
	return 0;
}

Measured memory_bytes: 1152
def resolve():
    n,x=map(int, input().split())
    l=list(map(int, input().split()))
    l.sort()
    num=0
    cnt=0
    for i in range(n-1):
        if num+l[i]<=x:
            num+=l[i]
            cnt+=1
    if l[n-1]==x-num:
        cnt+=1
    print(cnt)
resolve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

ll X[9]={1,2,3,4,5,6,7,8,9};
int main() {
ll N;
  cin >>N;
  vl P(N);
  vl Q(N);
  rep(i,N) {
cin >>P.at(i);
  }
rep(i,N) {
cin >>Q.at(i);
}

  
  ll a=0;
  ll b=0;
 ll c=0;
  
  
  do{
    c++;
     bool aa=true;
  bool bb=true;
    rep(i,N) {
if(P.at(i)!=X[i]) {
aa=false;
}
      if(Q.at(i)!=X[i]) {
bb=false;
}
    }
    
    if(aa) {
      a=c;
    }
if(bb) {
b=c;
}

    
    
  }
while(next_permutation(X,X+N));

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

  


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

using namespace std;
int main(void) {
long long int k,n;cin>>k>>n;long long int a[n],distance[n];
  for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n-1;i++)distance[i]=a[i+1]-a[i];distance[n-1]=a[0]+ (k-a[n-1]);
  int max=0,index=0;
  for(int i=0;i<n;i++){
    if(distance[i]>max){ index=i; max=distance[i];}
    //cout<<max<<"  "<<index<<endl;
  }
 cout<<k-distance[index];
}

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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n); 0<=i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

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

    cout << (A*B) << endl;

    return 0;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;


public class Main {
		
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[] count = new int[10];
			
			for(int i = 0; i < n; i++){
				count[sc.nextInt()]++;
			}
			
			for(int i : count){
				if(i == 0){
					System.out.println("-");
				}else{
					for(int j = 0; j < i; j++){
						System.out.print("*");
					}
					System.out.println();
				}
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main(){
int n , l ;
cin>>n>>l;
int A[n+1];
for(int i=1 ; i<=n ; i++) cin>>A[i];
bool flag = 0;
int pos = 0;
for(int i=1 ; i<n ; i++){
    if(A[i]+A[i+1]>=l){
        flag = 1;
        pos = i;
        break;
    }
}


if(flag == 0){
    cout<<"Impossible"<<endl;
    return 0;
}
else{
    cout<<"Possible"<<endl;

for(int i=1 ; i<pos ; i++){
    cout<<i<<endl;
}

for(int i=n-1 ; i>=pos ; i--)
    cout<<i<<endl;
}
}


Measured memory_bytes: 4000
x, k, d = map(int, input().split())
x = abs(x)
if k * d >= x:
    # 右側
    ans1 = x % d
    # 左側
    ans2 = abs(ans1 - d)
    # x//d -> 右側に必要な最低限の手数
    # k-最低限の手数 が　偶数 -> そこへ着地
    # 奇数ならもう1つdマイナスのやつへ着地
    if (k - (x // d)) % 2 == 0:
        print(ans1)
    else:
        print(ans2)
else:
    print(x - (k * d))


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

int main() {
  long long int n,count,ans;
  cin>>n;
  ans=2*(n/11);
  count=n%11;
  if(0<count && count<7){
    ans+=1;
  }else if(7<=count){
    ans+=2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cerr << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> PII;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

ll N, C;


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

    cin >> N >> C;
    vector<ll> x;
    vector<ll> v;
    REP(i, N) {
        ll tx, tv;
        cin >> tx >> tv;
        x.push_back(tx);
        v.push_back(tv);
    }

    ll ans = 0;

    // 初期位置をO，描く円弧の両端をA，Bとする
    // OA + 2OB or OB + 2OA の大きい方が解となる

    ll vsum = 0;
    vector<ll> ga(N+1), gb(N+1);
    ga[N] = gb[N] = 0;

    for (int i = N - 1; i >= 0; i--) {
        vsum += v[i];
        ga[i] = MAX(ga[i + 1], vsum - (C - x[i])); // OB
        gb[i] = MAX(gb[i + 1], vsum - (C - x[i]) * 2); // 2OB
    }

    ans = max(ga[0], gb[0]);
    vsum = 0;

    REP(i, N) {
        vsum += v[i];
        ans = MAX(ans, vsum - x[i] * 2 + ga[i + 1]); // 2OA + OB
        ans = MAX(ans, vsum - x[i] + gb[i + 1]); // OA + 2OB
    }

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


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int n; cin >> n;
	while(n){
		int k = n%10;
		n/=10;
		if(k==7){
			cout<<"Yes\n";
			return;
		}
	}
	cout<<"No\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	while(scanf("%d %d %d",&a,&b,&c)!=EOF){
		if(a==b)
			printf("%d\n",c);
		else if(a==c)
			printf("%d\n",b);
		else
			printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
    int H, W;
    cin >> H >> W;
    auto dp = vector<vector<ll>>(H, vector<ll>(W,0));
    ll mod = 1000 * 1000 * 1000 + 7;
    dp[0][0] = 1;
    string grid[H];
    for(int i = 0; i< H; i++) {
        cin >> grid[i];
    }
    for(int i = 0; i < H ;i++) {
        for (int j= 0; j < W ; j++){
            if (i!=0) {
                dp[i][j] += dp[i-1][j];
            }
            if (j!=0){
                dp[i][j] += dp[i][j-1];
            }
            if (grid[i][j] == '#') {
                dp[i][j] = 0;
            }
            dp[i][j]%=mod;
        }
    }
    cout << dp[H-1][W-1] << endl;

}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

//約数列挙
template <class T>
vector<T> divisor(T x){
	vector<T> res;
	for(T i=1;i*i<=x;i++){
		if(x%i==0){
			res.push_back(i);
			if(i!=x/i){
				res.push_back(x/i);
			}
		}
	}
	return res;
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> ret=divisor(n);
	ll ans=inf;
	for(auto x:ret){
		ll y=n/x;
		chmin(ans,ll(max(to_string(x).size(),to_string(y).size())));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll x,a;
  cin>>x>>a;
  ll ans=10;
  if(x<a)ans=0;
  cout<<ans<<endl;
}


Measured memory_bytes: 888
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

bool prime[SIZE + 1];
int like_num[SIZE + 1];

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

    for( int i = 2; i <= SIZE; ++i ) {
        if( !prime[i] ) {
            for( int j = i * 2; j <= SIZE; j += i ) {
                prime[j] = true;
            
            }
        }
    }

    for( int i = 3; i <= SIZE; i += 2 ) {
        if( !prime[i] && !prime[(i + 1) / 2] ) {
            like_num[i] = 1;

        }
    }

    for( int i = 3; i <= SIZE; ++i ) {
        like_num[i] += like_num[i - 1];

    }

    int q;
    cin >> q;
    for( int i = 0; i < q; ++i ) {
        int l, r;
        cin >> l >> r;
        cout << like_num[r] - like_num[l - 1] << endl;

    }

    return 0;
}



Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,t,c=0,tm=0,a;
  cin>>n>>t;
  cin>>a;
  tm=a+t;
  c=t;
  for(int i=1;i<n;i++){
    cin>>a;
    if(tm>a)
      c+=a+t-tm;
    else
      c+=t;
    tm=a+t;
  }
  cout<<c;
}

Measured memory_bytes: 256
/*Anikash Chakraborty cpp*/
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define w(t) int t; cin>>t; while(t--)
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<long long>
#define MAX 100002
#define MOD 1000000007
#define ll long long
 
using namespace std;
ll bigmod(ll b, ll p, ll md){if(p==0) return 1;if(p%2==1){ return ((b%md)*bigmod(b,p-1,md))%md;} else {ll y=bigmod(b,p/2,md);return (y*y)%md;}}
bool vis[MAX];
vector<ll> adj[MAX];
void dfs(ll u)
{
    vis[u] = true;
    for(auto i:adj[u])
        if(!vis[i]) dfs(i);
}

ll dp[MAX];
int solve(vi &a,ll i,ll n){
    if(i>=n) return 0;
    if(dp[i]!=-1) return dp[i];
    if(i+2<=n){
        return dp[i]=min(abs(a[i]-a[i+1])+solve(a,i+1,n),abs(a[i]-a[i+2])+solve(a,i+2,n));
    }
    else return dp[i]=abs(a[i]-a[i+1])+solve(a,i+1,n);
    
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        memset(dp,-1,sizeof dp);
    
        ll n;
        cin>>n;
        vi a(n);

        REP(i,n) cin>>a[i];
        
        cout<<solve(a,0,n-1)<<endl;

        // REP(i,n) cout<<dp[i]<<" ";
        // cout<<endl;
        

    
    
 
}



Measured memory_bytes: 7680
n = int(input())

lst1 = list(map(int,input().split()))

dic1 = dict()
oe = 1
if n%2 == 1:
    oe = 0
for i in range(oe,n,2):
    dic1[i] = 0

for i in lst1:
    if i in dic1:
        dic1[i] += 1
    else:
        print(0)
        exit()

if oe == 0:
    if dic1[0] != 1:
        print(0)
        exit()

ans = 1
for i in dic1.values():
    if i == 2:
        ans*=2
    elif i == 0 or i > 2:
        ans = 0
        break
print(ans%(10**9+7))



Measured memory_bytes: 55532
#include <stdio.h>

int main()
{
	int n, i, m, j;
	int array[100];
	int tmp;
	int count = 0;
	int min;
	int ichi = 0;
	scanf("%d", &n);

	for (i = 1; i <= n; i++) {
		scanf("%d", &array[i]);
	}

	min = array[1];

	for (m = 1; m<n; m++) {
		min = array[m];
		for (j = m + 1; j <= n; j++) {
			if (min>array[j]) {
				min = array[j];//最小値探索
				ichi=j;//最小値の位置を記憶する
			}
		}
		if (array[m] != min) {
			tmp = array[m];
			array[m] = min;
			array[ichi] = tmp;
			count++;
		}
	}


	for (i = 1; i <= n; i++) {
		if (i != n) {
			printf("%d ", array[i]);
		}
		else {
			printf("%d\n", array[i]);
		}
	}
	printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


int H,W; int b[1000][1000] = {0};
int solve(){
  cin >> H>>W;
  queue<pair<int,int>> q;
  REP(i,H){
    char c[W]; cin >> c;
    REP(j,W){
      if(c[j]=='#'){
        b[i][j] = 1;
        q.push( make_pair(i,j) ); 
      }
    }
  }
  int ans = 0;
  while(!q.empty()){
    queue<pair<int,int>> q_next;
    while(!q.empty()){
      int i= q.front().first;
      int j= q.front().second;
      for(int h=-1;h<=1;++h){
        for(int w=-1;w<=1;++w){
          if(h!=0 && w!=0){continue;}
          int idx_y = i+h;
          int idx_x = j+w;
          if(idx_y>=0 && idx_y<H && idx_x>=0 && idx_x<W){
            if(b[idx_y][idx_x]==0){
              b[idx_y][idx_x] = 1;
              q_next.push( make_pair(idx_y,idx_x) );
            }
          }
        }
      }
      q.pop();
    }
    if(!q_next.empty()){ ++ans; }
    q = q_next;
  }
  return ans;
}

int main(){
  int ans = solve();
  cout << ans <<"\n";
}

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

int main () {
  int a,b;
  cin >> a >> b;

  int c=max(a,b);
  int d=min(a,b);

  if (c==2) cout << 3 << endl;
  else if (c==3 &&d==2) cout << 1 << endl;
  else cout << 2 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    int N;
    cin >> N;
    LL a[N][N];
    LL ans=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> a[i][j];
            ans+=a[i][j];
        }
    }
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(a[i][j]>a[i][k]+a[k][j]){
                    puts("-1");
                    return 0;
                }
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                if(i==j||i==k||j==k) continue;
                if(a[i][j]==a[i][k]+a[k][j]){
                    ans-=a[i][j];
                    break;
                }
            }
        }
    }
    cout << ans/2 << endl;
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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



ll memo[10];
ll me(int n) {
  if (n == 0) {
    return 1;
  } else if (n == 1) {
    return 1;
  } else {
    if (memo[n-1] == -1) memo[n-1] = me(n-1);
    if (memo[n-2] == -1) memo[n-2] = me(n-2);
    memo[n] = memo[n-1] + memo[n-2];
    return memo[n];
  }
}

ll dp[110][10];
int H, W, K;

int main () {
  cin >> H >> W >> K;

  Rep(i, 10) {
    memo[i] = -1;
  }
  memo[0] = 1;
  memo[1] = 1;

  dp[0][1] = 1;

  rep(h, H) {
    rep(w, W) {
      ll cur = dp[h-1][w];

      if ((w-1) > 0) {
        dp[h][w-1] += cur * me(w-2) * me(W-w);
        dp[h][w-1] %= MOD;
      }
      if ((w+1) <= W) {
        dp[h][w+1] += cur * me(w-1) * me(W-w-1);
        dp[h][w+1] %= MOD;
      }
      dp[h][w] += cur * me(w-1) * me(W-w);
      dp[h][w] %= MOD;
    }
  } 

  rep(h, H) {
    rep(w, W) {
      //cout << h << " " << w << "\n";
      //cout << dp[h][w] << "\n";
    }
  }

  cout << dp[H][K] << "\n";
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int N, K;
  cin >> N >> K;

  vector<bool> nn(N, false);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int b;
      cin >> b;
      nn[b - 1] = true;
    }
  }

  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (nn[i] == false) {
      sum++;
    }
  }

  cout << sum << '\n';

  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	return B;
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

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

	vector<int> task(3);
	cin >> task[0];
	cin >> task[1];
	cin >> task[2];

	cout << vmax(task) - vmin(task) << endl;

ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}




Measured memory_bytes: 504
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
    return a * a;
}

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int X, Y;
    cin >> X >> Y;
    cout << X + Y / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)
#define M 1000000007


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n;
    for0(n)
    {
        cin>>x;
        if(i>0&&x<m)
        {
            c+=(m-x);
            x=m;
        }
        m=x;
    }
    cout<<c<<endl;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  int* arr= new int[n];
  for(int i=0;i<n;i++){
      cin>>arr[i];
  }
    int count_ans=0,cv=1;
    for(int i=0;i<n;i++){
        if(arr[i]==cv){
            cv++;
            count_ans++;
        }
    }
    if(count_ans==0&&cv==1) cout<<"-1";
    else{
        cout<<n-count_ans<<endl;
    }
cout<<endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * <p>
	 * 与えられた三辺で直角三角形が作れるかを判定する。
	 * </p>
	 *
	 * @param args
	 *            利用しない。
	 * @throws IOException
	 */
	public static void main(String[] args) throws NumberFormatException,
			IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int lineCount = Integer.parseInt(br.readLine());
		for (int i = 0; i < lineCount; i++) {

			String[] input = br.readLine().split(" ");
			int side1 = Integer.parseInt(input[0]);
			int side2 = Integer.parseInt(input[1]);
			int side3 = Integer.parseInt(input[2]);

			if (isRightTriangle(side1, side2, side3)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}

	/**
	 * 三辺の長さから、直角三角形であるかどうかを判定する。<br>
	 * 注意：第一引数に最も長い辺を与えること。
	 *
	 * @param side1
	 *            辺1
	 * @param side2
	 *            辺2
	 * @param side3
	 *            辺3
	 * @return 直角三角形であるかどうか
	 */
	private static boolean isRightTriangle(int side1, int side2, int side3) {

		boolean isRightTriangle = false;
		if (side1 >= side2 && side1 >= side3) {
			isRightTriangle = (side1 * side1 == side2 * side2 + side3 * side3);
		} else if (side2 >= side1 && side2 >= side3) {
			isRightTriangle = (side2 * side2 == side1 * side1 + side3 * side3);
		} else {
			isRightTriangle = (side3 * side3 == side1 * side1 + side2 * side2);
		}

		return isRightTriangle;
	}
}

Measured memory_bytes: 20232
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
// other libs
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) {
  return a * b / gcd(a, b);
}

class dijkstra {
private:
  int V;
  int d[100002];
  priority_queue<P, vector<P>, greater<>> que;

public:
  dijkstra(int v, int s, vector<edge> G[]) {
    V = v;
    update(s, G);
  }

  void update(int s, vector<edge> G[]) {
    fill(d, d + V + 1, 100000000000ll);
    d[s] = 0;
    que.push(make_pair(0, s));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      int v = p.second;
      if (d[v] < p.first)
        continue;
      rep(i, G[v].size()) {
        edge e = G[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(make_pair(d[e.to], e.to));
        }
      }
    }
  }

  int find(int e) {
    return d[e];
  }
};
template<typename T>
class Union_Find {
private:
  vector<T> t, s;

public:
  Union_Find(T max_length) {
    rep(i, max_length + 1) {
      t.push_back(i);
      s.push_back(1);
    }
  }

  void Union(T x, T y) {
    if (same(x, y))
      return;
    T tx = Find(x), ty = Find(y);
    if (s[tx] < s[ty]) {
      s[ty] += s[tx];
      t[tx] = ty;
    }
    else if (s[tx] > s[ty]) {
      s[tx] += s[ty];
      t[ty] = tx;
    }
    else if (tx > ty) {
      t[tx] = ty;
      s[ty] += s[tx];
    }
    else {
      t[ty] = tx;
      s[tx] += s[ty];
    }
  }
  T Find(T n) {
    if (t[n] == n)
      return n;
    else
      return t[n] = Find(t[n]);
  }

  bool same(T x, T y) {
    return Find(x) == Find(y);
  }

  T get_Size(size_t a) {
    return s[a];
  }
};
bool ifPrime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

set<int> prime_num_factor(int n){
  if(n<2)return set<int>();
  set<int> prime;
  prime.insert(2);
  for(int i=3;i<=n;i++){
    for(int it:prime){
      if(it*it>i){
        prime.insert(i);
        break;
      }
      if(i%it==0)break;
    }
  }
  return prime;
}
vector<int> makeDivisors(int n){
  vector<int> re;
  REP(i,1,sqrt(n)+1){
    if(n%i==0){
      re.push_back(i);
      if(i!=n/i)re.push_back(n/i);
    }
  }
  return re;
}
int modPow(int a,int n,int mod){
  int ret=1;
  while(n){
    if(n&1)ret=ret*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return ret;
}
signed main(signed argc, char* argv[]) {
  int n;
  cin>>n;
  int ans=n;
  for(int i=1;i*i<=n;i++){
    if(n%i==0)ans=min(ans,i+n/i-2);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    int aa[q], b[q], c[q], d[q];
    rep(i,q){
        cin >> aa[i] >> b[i] >> c[i] >> d[i];
        aa[i]--;
        b[i]--;
    }

    int ans = 0;

    int loop = 1 << (n+m-1);
    int w = n + m - 1;

    rep(i,loop){
        int ii = i;
        int f[w];
        int cnt = 0;
        rep(j,w){
            f[j] = ii % 2;
            ii /= 2;
            cnt += f[j];
        }
        if(cnt != n)continue;
        int a[n] = {};
        int num = 1;
        int now = 0;
        rep(j,w){
            if(f[j] == 0){
                num++;
            }else{
                a[now] = num;
                now++;
            }
        }
        int tmp = 0;
        rep(j,q){
            if(a[b[j]] - a[aa[j]] == c[j])tmp += d[j];
        }
        ans = max(ans, tmp);
        /*
        rep(j,n)cout << a[j] << ' ';
        cout << tmp << endl;
        */
    }

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




Measured memory_bytes: 3636
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main(){
    string S;
    cin >> S;
    int old = S[0];
    int count = 0;
    for(int i=1;i<S.length();i++){
        if (old!=S[i]) count++;
        old = S[i];
    }
    cout << count << endl;
    return 0;


}


Measured memory_bytes: 512
from itertools import permutations
from math import sqrt

n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]

total = 0
for pattern in permutations(xy):
    dis = 0
    for j in range(n - 1):
        dis += sqrt((pattern[j][0] - pattern[j + 1][0]) ** 2 + (pattern[j][1] - pattern[j + 1][1]) ** 2)
    total += dis

ans = total / len(list(permutations(xy)))
print(ans)


Measured memory_bytes: 76268
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000;

//main関数
int main() {
    
    //入力
    long N;
    cin>>N;
    
    
    //計算
    
    vector<long> dp(N+1,INF);
    
    dp.at(0)=0;
    for(int i=1;i<N+1;i++){
        long pre=INF;
        
        //1
        dp.at(i)=min(dp.at(i),dp.at(i-1)+1);
        
        //6
        long sixx=1;
        while(i-sixx*6>=0) sixx*=6;
        dp.at(i)=min(dp.at(i),dp.at(i-sixx)+1);
        
        //9
        long ninn=1;
        while(i-ninn*9>=0) ninn*=9;
        dp.at(i)=min(dp.at(i),dp.at(i-ninn)+1);
    }
    
    //出力
    cout<<dp.at(N)<<endl;
}

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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

/*int ter_search(int l,int r)
{
    while((r-l)>0)
    {
        int m1=l+(r-l)/3;
        int m2=r-(r-l)/3;
        int f1=f(m1);
        int f2=f(m2);
        if(f1>f2)
         l=m1+1;
         else
          r=m2-1;
    }
    return f(l);
}*/

int32_t main()
{
    int cnt=0;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
         cnt++;
    }
    cout<<cnt<<"\n";
    return 0;
}

Measured memory_bytes: 3852
import java.util.Collections;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		LinkedList<Work> works = new LinkedList<>();
		for(int i=0; i<N; i++) {
			works.add(new Work(in.nextInt(), in.nextInt()));
		}
		Collections.sort(works);
		
		PriorityQueue<Work> candidate = new PriorityQueue<Work>(
				(a,b)->-Integer.compare(a.value, b.value)
		);
		
		long ans = 0;
		for(int rem=1; rem<=M; rem++) {
			while(!works.isEmpty() && works.peek().delay<=rem) 
				candidate.add(works.poll());
			if(!candidate.isEmpty())
				ans += candidate.poll().value;
		}
		System.out.println(ans);
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
	
	class Work implements Comparable<Work>{
		public int delay;
		public int value;
		public Work(int A, int B) {
			delay = A;
			value = B;			
		}
		@Override
		public int compareTo(Work targ) {
			if(delay == targ.delay) {
				return -Integer.compare(value, targ.value);
			}
			return Integer.compare(delay, targ.delay);
		}
	}
}

Measured memory_bytes: 85380
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;


int main(){
	int m;
	while(~scanf("%d",&m)){
		if(m==0) break;
		vector<P> stars;
		for(int i=0;i<m;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			stars.push_back(P(x,y));
		}
		int n;
		vector<P> sky;
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			sky.push_back(P(x,y));
		}

		map<P,int> diff;
		for(int i=0;i<sky.size();i++){
			for(int j=0;j<stars.size();j++){
				int diff_x = sky[i].first - stars[j].first;
				int diff_y = sky[i].second - stars[j].second;
				diff[P(diff_x,diff_y)]++;
			}
		}

		int x,y;
		for(map<P,int>::iterator it = diff.begin(); it != diff.end(); it++){
			if(it->second == stars.size()){
				x = it->first.first;
				y = it->first.second;
				break;
			}
		}
		printf("%d %d\n",x,y);
	}
}

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

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> pq;
    rep(i, 0, N) {
        int a; cin >> a;
        pq.push(a);
    }
    while(M-- && pq.top() != 0) {
        int t = pq.top(); pq.pop();
        pq.push(t / 2);
    }
    long long ans = 0;
    while(!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a<b&&b<c)yn;
    return 0;
}
 
 



Measured memory_bytes: 3084
N, K = map(int, input().split())


def f(X, n):
    X_dumy = X
    out = ''
    while X_dumy > 0:
        out = str(X_dumy % n) + out
        X_dumy = int(X_dumy / n)
    return out


print(len(str(f(N, K))))


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

int main()
{
  string S, T;
  int a, b;
  string U;
  
  cin >> S >> T;
  cin >> a >> b;
  cin >> U;

  if (S == U) a--;
  else b--;
  
  cout << a << " " << b << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    long long int x,ans;
    cin >> x;
    ans = (x/11)*2;
    if(x%11>6) ans += 2;
    else if(x%11>0) ans += 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.println(Main.calc(s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt()));
	}

	public static long calc(int a, int b, int c, int x, int y) {

		long res = Long.MAX_VALUE;
		// cの枚数のとりうる最大値
		long exmax = Math.max(x, y) * 2;
		for (int cn = 0; cn <= exmax; cn += 2) {
			long aVal = Math.max(a * (x - cn / 2), 0);
			long bVal = Math.max(b * (y - cn / 2), 0);
			long cVal = c * cn;
			res = Math.min(aVal + bVal + cVal, res);
		}
		return res;
	}

}

Measured memory_bytes: 23764