akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int N;
  while (cin >> N && N != 0) {
    int x;
    cin >> x;
    vector<int> v(1, 1);
    int ans = x == 0 ? 1 : 0;
    int prev = x;
    for (int i = 1; i < N; i++) {
      cin >> x;
      if (prev == x) {
        v.back()++;
        if (x == 0) {
          ans++;
        }
      } else {
        if (i % 2 == 0) {
          v.push_back(1);
          if (x == 0) {
            ans++;
          }
        } else {
          if (v.size() == 1) {
            v.back()++;
            if (x == 0) {
              ans = v.back();
            } else {
              ans = 0;
            }
          } else {
            const int y = v.back();
            v.pop_back();
            v.back() += y + 1;
            if (x == 0) {
              ans += y + 1;
            } else {
              ans -= y;
            }
          }
        }
      }
      prev = x;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 908
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N;

/*==================================================*/
/*function*/
vector<int> hurui_v(int n) {
    vector<int> v;
    bool *isPrime_v;
    isPrime_v = new bool[n + 1];
    isPrime_v[0] = isPrime_v[1] = false;
    for (int i = 2; i < n + 1; i++) isPrime_v[i] = true;
    for (int i = 2; i*i <= n; i++) {
        for (int j = i * 2; j < n + 1; j += i) {
            isPrime_v[j] = false;
        }
    }
    for (int i = 0; i < n + 1; i++) {
        if (isPrime_v[i]) v.push_back(i);
    }
    delete[] isPrime_v;
    return v;
}
/*==================================================*/

int main() {
    cin>>N;

    vector<int> v = hurui_v(55555);
    vector<int> ans;
    REP(i,0,v.size()){
        if(v[i] % 10 == 1){
            ans.push_back(v[i]);
        }
        if(ans.size() == N){
            break;
        }
    }

    REP(i,0,N){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    

    return 0;
}


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

int main(void){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N,0);

    for (ll i = 0; i < N; i++)
    {
        cin >> A[i];
        B[A[i] - 1]++;
    }

    ll prod = 0;
    for(ll i = 0; i < N; i++){
        prod += B[i] * (B[i] - 1) / 2;
    }

    for(ll k = 0; k < N; k++){
        ll pat;
        pat = prod - (B[A[k]-1] - 1);
        cout << pat << endl;
    }

    return 0;
}


Measured memory_bytes: 6428
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int N, R;

int main() {
  cin >> N >> R;

  if (N >= 10)
    cout << R << endl;
  else
    cout << R + 100 * (10 - N) << endl;

  return 0;
}


Measured memory_bytes: 3612
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10

    S = input()
    count_B = 0
    ans = 0
    for c in S:
        if c == 'B':
            count_B += 1
        else:
            ans += count_B
    print(ans)
    
main()

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n,d;
    cin >> n >> d;
    if(n==0) return 0;
    vector<stack<pair<int,int>>> st(n);
    int m;
    rep(i,n){
      cin >> m;
      int sum=0;
      int c;
      rep(j,m){
        cin >> c;
        sum+=c;
        st[i].push({sum,c});
      }
    }
    while(1){
      int ma=0,mi=IINF;
      int dd=0,id=-1;
      rep(i,n){
        if(!st[i].empty()){
          ma=max(ma,st[i].top().first);
          mi=min(mi,st[i].top().first);
        }else{
          mi=0;
        }
      }
      rep(i,n){
        if(st[i].empty()) continue;
        if(st[i].top().first==ma){
          if(dd<st[i].top().second){
            dd=st[i].top().second;
            id=i;
          }
        }
      }
      if(ma-mi>d){
        CNO;
        goto next;
      }
      if(ma==0) break;
      int one=0,two=0;
      rep(i,n){
        if(st[i].empty()) continue;
        if(i==id){
          st[i].pop();
        }else{
          while(!st[i].empty()){
            if(st[i].top().first-st[i].top().second<ma-d) break;
            st[i].pop();
          }
        }
      }
    }
    CYES;
    next:;
  }
  return 0;
}



Measured memory_bytes: 3240
input = gets.chomp.split(" ").map(&:to_i)
a = input[0]
b = input[1]
x = input[2]

if x <= a*a*b.to_f/2
  h = x*2 / (a*b).to_f
  angle = Math.atan(b/h)
else
  x = a*a*b - x
  h = x * 2 / (a*a).to_f
  angle = Math.atan(h/a)
end
angle = angle * 180 / Math::PI
puts angle


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a, ll b)
{
    if(b == 0)  return a;
    return gcd(b, a%b);
}
int main()
{
	int n;
	ll k;
	cin >> n >> k;
	ll a[n + 1];
	for(int i = 1; i <= n; i++) cin >>a[i] ;
	ll g = a[1];
	ll mx = a[1];
	for(int i = 2; i <= n; i++) g = gcd(g, a[i]), mx = max(mx, a[i]);
	if(k > mx) { cout << "IMPOSSIBLE"; return 0; }
	for(int i = mx; i >=0 ; )
	{
		if(i == k) {cout << "POSSIBLE"; return 0; }
		i -= g;
	}
	cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

solve :: Int -> Int -> VU.Vector (Int, Int) -> Int
solve !n !m !abn = (\(x, _, _) -> x) $ foldl'
  (\(!acc, !mx, !tgts) (!pos) ->
    let (acc', mx') = if mx == pos then (acc + 1, n) else (acc, mx)
    in  case tgts of
          ((s, t) : tgts') | s == pos -> (acc', mx' `min` t, tgts')
          _                           -> (acc', mx', tgts)
  )
  (0, n, targets)
  [0 .. n - 1]
 where
  targets =
    VU.toList
      $ VU.filter (\(x, y) -> y < n)
      $ VU.zip (VU.fromList [0 .. n - 1])
      $ VU.accumulate min (VU.replicate n n) abn

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  abn <-
    VU.replicateM m
    $   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
  print $ solve n m abn


Measured memory_bytes: 4220
#include <iostream>
using namespace std;
int n,w,a,b,dp[10001],ans;
int main(void){
    cin>>n>>w;
    for(int i=1;i<=w;i++)dp[i]=-1;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        for(int j=w-b;j>=0;j--){
            if(dp[j]!=-1){
                dp[j+b]=max(dp[j+b],a+dp[j]);
            }
        }
    }
    for(int i=0;i<=w;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}



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

//関数
    
    
//main関数
int main() {
    
    
    //入力
    long N;
    cin>>N;
    vector<long> p(N);
    for(int i=0;i<N;i++){
        cin>>p.at(i);
    }
    
    
    
    
    //計算
    vector<long> a(N),b(N);
    for(int i=0;i<N;i++){
        a.at(i)=(i+1)*30000;
        b.at(i)=(N-i)*30000;
    }
    for(int i=0;i<N;i++){
        a.at(p.at(i)-1)+=i;
    }
    
    //出力
    for(int i=0;i<N-1;i++){
        cout<<a.at(i)<<" ";
    }
    cout<<a.at(N-1)<<endl;
    
    for(int i=0;i<N-1;i++){
        cout<<b.at(i)<<" ";
    }
    cout<<b.at(N-1)<<endl;
}

Measured memory_bytes: 1152
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n,m = invr()
nums = inlt()
standard = (sum(nums))/(4*m)
nums.sort(reverse = True)
has = True
index = 0
while index < m:
    if nums[index] < standard:
        has = False
        break
    index += 1
if has:
    print('Yes')
else:
    print('No')
#print()


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

int main() {
	int n;
	// your code goes here
	while(cin>>n){
	if (n==0) break;	
	int a[11]={0};
	int keta=-1;
	for(int u=1;u<11;u++){
		a[u]=n%8;
		n=(n-a[u])/8;
		if(keta == -1 && n==0) keta=u;
		
	}
	
	for(int y=keta;y>0;y--){
		if(a[y]==0) cout<<"0";
		if(a[y]==1) cout<<"1";
		if(a[y]==2) cout<<"2";
		if(a[y]==3) cout<<"3";
		if(a[y]==4) cout<<"5";
		if(a[y]==5) cout<<"7";
		if(a[y]==6) cout<<"8";
		if(a[y]==7) cout<<"9";
		
	}
	cout<<endl;
	
	
	
	
	}
	

}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}



void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using namespace std;

class BResistorsInParallel {
public:
	void solve(std::istream& in, std::ostream& out) {
		double x, ans = 0.0;
		int n;
		in >> n;

		for (int i = 0; i < n; i++)
		    in >> x, ans += 1.0/x;

		out.precision(16);
		out << 1/ans;
	}
};

int main() {
	BResistorsInParallel solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e6+6;
const int mod = 1e9+107;
const int inf = 1e8;
ll cnt[N];
int a[N];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    ll ans =0;
    for(int i=n;i>=1;i--){
        int x = i-a[i];
        if(x>=1 and x<N){
            cnt[x]++;
        }
        int y = i+a[i];
        if(y>=1 and y<N){
            ans+=cnt[y];
        }
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 6000
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

struct fPoint
{
    double x;
    double y;
};

float sign(fPoint p1, fPoint p2, fPoint p3)
{
  return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);
}

bool PointInTriangle(fPoint pt, fPoint v1, fPoint v2, fPoint v3)
{
  bool b1, b2, b3;

  b1 = sign(pt, v1, v2) < 0.0f;
  b2 = sign(pt, v2, v3) < 0.0f;
  b3 = sign(pt, v3, v1) < 0.0f;

  return ((b1 == b2) && (b2 == b3));
}


int main()
{
    fPoint p1,p2,p3,pp;
    while(cin>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y>>pp.x>>pp.y)
    {
        cout<<(PointInTriangle(pp,p1,p2,p3)?"YES":"NO")<<endl;
    }
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int comp(const void * a, const void * b){
	return *(int *) a - *(int *)b;
}

int main(){
	int n;
	scanf("%d", &n);
	int a[n];
	for(int i = 0;i<n;++i){
		scanf("%d", &a[i]);
	}
	qsort(a,n,sizeof(a[0]),comp);
	printf("%d\n",a[(n)/2] - a[(n-2)/2]);
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string S, T;
    cin >> S >> T;

    bool can = true;
    map<char, char> mpS, mpT;
    for (int i = 0; i < S.size(); i++) {
        char s = S[i];
        char t = T[i];
        if (mpS.count(s)) if (mpS[s] != t) can = false;
        if (mpT.count(t)) if (mpT[t] != s) can = false;
        mpS[s] = t;
        mpT[t] = s;
    }

    cout << (can ? "Yes" : "No") << endl;
    

    return 0;
}

Measured memory_bytes: 776
n,m=map(int,input().split())
std = [list(map(int,input().split())) for i in range(n)]
chk = [list(map(int,input().split())) for i in range(m)]
for s in std:
  ans=[]
  for i in range(m):
    ans.append([abs(s[0]-chk[i][0])+abs(s[1]-chk[i][1]),i+1])
    ans.sort()
  print(ans[0][1])

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

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    vector<ll> a(n + 1);

    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j += i)a[j] += j;
    }
    ll sum = 0;
    cout << accumulate(a.begin(), a.end(), 0LL) << endl; 
}

Measured memory_bytes: 81372
#include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>

using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
ll longinf=1ll<<60;



ll n,m,s,t;
ll dista[100002],distb[100002];
vector<P> machia[100002],machib[100002];
priority_queue<P,vector<P>,greater<P>> quea,queb;
ll mini[100002];

int main(){
  cin>>n>>m>>s>>t;
  rep1(i,m){
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    machia[u].push_back(make_pair(a,v));
    machia[v].push_back(make_pair(a,u));
    machib[u].push_back(make_pair(b,v));
    machib[v].push_back(make_pair(b,u));
  }
  rep1(i,n){
    dista[i]=longinf;
    distb[i]=longinf;
  }
  dista[s]=0;
  rep0(i,machia[s].size()){
    quea.push(machia[s][i]);
    dista[machia[s][i].second]=machia[s][i].first;
  }
  while(quea.size()){
    P p=quea.top();
    quea.pop();
    if(p.first>dista[p.second]) continue;
    for(int i=0;i<machia[p.second].size();i++){
      ll c=machia[p.second][i].first;
      ll ne=machia[p.second][i].second;
      if(c+dista[p.second]<dista[ne]){
        dista[ne]=c+dista[p.second];
        quea.push(make_pair(c,ne));
      }
    }
  }
   distb[t]=0;
  rep0(i,machib[t].size()){
    queb.push(machib[t][i]);
    distb[machib[t][i].second]=machib[t][i].first;
  }
  while(queb.size()){
    P p=queb.top();
    queb.pop();
    if(p.first>distb[p.second]) continue;
    for(int i=0;i<machib[p.second].size();i++){
      ll c=machib[p.second][i].first;
      ll ne=machib[p.second][i].second;
      if(c+distb[p.second]<distb[ne]){
        distb[ne]=c+distb[p.second];
        queb.push(make_pair(distb[ne],ne));
      }
    }
  }
  ll shozikin=1e15;
  mini[n]=dista[n]+distb[n];
  for(int i=n-1;i>=1;i--){
    mini[i]=min(mini[i+1],dista[i]+distb[i]);
  }
  rep1(i,n){
    cout<<shozikin-mini[i]<<endl;
  }
    return 0;
}

Measured memory_bytes: 22132
#include <iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

int merge(int A[], int N, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++)
    {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++)
    {
        R[i] = A[mid + i];
    }
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++)
    {
        cnt++;
        if (L[i] <= R[j])
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}

int mergeSort(int A[], int N, int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergeSort(A, N, left, mid);
        mergeSort(A, N, mid, right);
        merge(A, N, left, mid, right);
    }
}

int main()
{
    int A[MAX], n, i;
    cnt = 0;
    cin >> n;
    // int A[] = {8, 5, 9, 2, 6, 3, 7, 1, 10, 4};
    // int n = sizeof(A) / sizeof(*A);
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }

    mergeSort(A, n, 0, n);
    for (int i = 0; i < n; i++)
    {
        if (i)
        {
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 7000
#include <stdio.h>
#define gc getchar_unlocked
#define pc putchar_unlocked

int ini() {
  int v = 0;
  for (char c = gc(); '0' <= c && c <= '9'; c = gc())
    v = v * 10 + (c - '0');
  return v;
}

void puti(int v) {
  char b[10]; int n = 0;
  while (v)b[n++] = '0' + v % 10, v /= 10;
  if (!n)b[n++] = '0';
  while (n--)pc(b[n]);
}

int main() {
  int x = ini();
  for (int i = 360;; i += 360) {
    if (i % x == 0) {
      puti(i / x);
      return 0;
    }
  }
}

Measured memory_bytes: 1480
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String o = sc.next();
        String e = sc.next();
        for (int i = 0; i < o.length(); i++) {
            try {
                System.out.print(o.charAt(i));
                System.out.print(e.charAt(i));
            } catch (Exception a) {

            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 21972
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

const LL MOD = 1e9 + 7;
const LL M = 1;
LL n;
vector<vector<LL>> link;

LL dp[50][50][M+1] = {0};
map<LL,LL> memo[50][50];

LL f(LL i, LL j, LL k) {
    if(k <= M){
        return dp[i][j][k];
    }
    if(EXIST(memo[i][j], k)){
        return memo[i][j][k];
    }
    LL x = k/2;
    LL y = k - x;
    LL sum = 0;
    REP(t,n){
        sum += (f(i, t, x) * f(t, j, y)) % MOD;
        sum %= MOD;
    }
    memo[i][j].insert(MP(k, sum));
    return sum;
}

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

    LL k;
    cin>>n>>k;
    link.resize(n);
    REP(i,n){
        REP(j,n){
            LL a;
            cin>>a;
            if(a == 1)link[i].PB(j);
        }
    }

    REP(i,n)dp[i][i][0] = 1;
    REP(len,M){
        REP(i,n){
            for(LL to : link[i]){
                REP(st, n){
                    dp[st][to][len+1] += dp[st][i][len];
                    dp[st][to][len+1] %= MOD;
                }
            }
        }
    }

    LL ans = 0;
    REP(i,n)REP(j,n){
        ans += f(i, j, k);
        ans %= MOD;
    }
    PUTS(ans);
}

Measured memory_bytes: 18944
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	ll X, Y;
	cin >> X >> Y;
	ll ans = 0;
	while (X <= Y) {
		ans++;
		X *= 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#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 solve(){
  string s; cin>>s;
  int ans = 0;
  char pre = '0';
  int N = s.size();
  REP(i,N){
    if(s[i] != pre){
      pre = s[i];
      ++ans;
    }else{
      ++i;
      pre = '0';
      if(i<N){ ++ans; }
    }
  }
  return ans;
}

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll h,n,tong = 0;
int main()
{
    cin >> h >> n;
    for(ll i = 1;i <= n;i ++)
    {
        ll u;
        cin>>u;
        tong+=u;
    }
    tong >= h ? cout << "Yes" : cout << "No" ;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int ma[101][101];
int main()
{
    int a,b,n,x,y,k;
    cin>>a>>b>>n;

    for(int i=0;i<n;i++){
        cin>>x>>y>>k;
        if(k==1){
            for(int i=0;i<b;i++){
                for(int j=0;j<x;j++)ma[i][j]=1;
            }
        }
        if(k==2){
            for(int i=0;i<b;i++){
                for(int j=x;j<a;j++)ma[i][j]=1;
            }
        }
        if(k==3){
            for(int i=b-y;i<b;i++){
                for(int j=0;j<a;j++)ma[i][j]=1;
            }
        }
        if(k==4){
            for(int i=0;i<b-y;i++){
                for(int j=0;j<a;j++)ma[i][j]=1;
            }
        }
    }
    int c=0;
    for(int i=0;i<b;i++){
    for(int j=0;j<a;j++){
        //cout<<ma[i][j];
     if(!ma[i][j])c++;
    }
    //cout<<"\n";
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() {return numeric_limits<long long>::min();}
ll mal() {return numeric_limits<long long>::max();}

#define R3(i, a, b) for(long long i=(a); i<(b); ++i)
#define R2(i, b) for(long long i=0; i<(b); ++i)
#define R1(b) for(long long i=0; i<(b); ++i)
#define RR(i, a, b) for(long long i=a; i>b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// debug: shift + f9
// sanitize: shift + f11

int main(int argc, char **argv) {
    ll N;
    cin >> N;

    if(N%2 == 0)
        cout << N/2 << endl;
    else
        cout << (N/2) + 1 << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i = 0; i < N; i++) cin >> X.at(i);
  sort(X.begin() , X.end());
  
  vector<int> S;
  for(int i = X.front(); i <= X.back(); i++){
    int a=0;
    for(int k = 0; k < N; k++){
      a += (i-X.at(k))*(i-X.at(k));
    }
    S.push_back(a);
  }
  sort(S.begin() , S.end());
  cout << S.at(0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
int N,C;
int s[100000],t[100000],c[100000];
int sm[200002];
int tt[200002];

int main(){
  scanf("%d%d",&N,&C);

  for(int i=0;i<N;i++)
    scanf("%d%d%d",&s[i],&t[i],&c[i]);
  for(int i=1;i<=C;i++){
    
    for(int j=0;j<200002;j++)tt[j]=0;
    for(int j=0;j<N;j++)if(c[j]==i)tt[s[j]*2-1]++,tt[t[j]*2]--;
    for(int j=1;j<200002;j++)tt[j]+=tt[j-1];
    for(int j=0;j<200002;j++)if(tt[j]>0)sm[j]++;
  }
  int mx=0;
  for(int j=0;j<200002;j++)if(mx<sm[j])mx=sm[j];
  printf("%d\n",mx);
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
double a[20],b[20],n,k,ans;
int main()
{
	cin>>n>>k;
	for(int i=0;i<=17;i++)
	{
		a[i]=(1<<i);
		b[i]=1/a[i];
	}
	for(int i=1;i<=n;i++)
	{
		int t=0;
		while(a[t]*i<k)
			t++;
		ans+=1/n*b[t];
	}
	printf("%.12lf\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int x, a, b, c;
	a = 0;
	b = 0;
	c = 0;
	for (int i = 0; i <= 9; i++) {
		cin >> x;
		if (a <= x) {
			c = b;
			b = a;
			a = x;
			goto a;
		}
		if (b <= x) {
			c = b;
			b = x;
			goto a;
		}
		if (c <= x) {
			c = x;
			goto a;
		}
	a:;
	}
	cout << a << endl;
	cout << b << endl;
	cout << c << endl;
}



Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        String s = sc.next();
        StringBuilder answer = new StringBuilder();
        for (int i = 0; i < n; i++) {
            String a = String.valueOf(s.charAt(i));
            if ((i + 1) == k) {
                a = a.toLowerCase();
            }
            answer.append(a);
        }
        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 35588
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - T or T
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);

  printf("%d\n", min(n * a, b));
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a[100];
	int i;
	for (i = 0; i < 100; i++)
	{
		a[i] = 0;
	}
	int N, M;
	scanf("%d%d", &N, &M);
	for (i = 0; i < M; i++)
	{
		int b, c;
		scanf("%d%d", &b, &c);
		a[b]++;
		a[c]++;
	}
	for (i = 1; i <= N; i++)
	{
		printf("%d\n", a[i]);
	}
}


Measured memory_bytes: 128
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
const ll mod = 1000;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n) { ll s = 1;while (n) { if (n & 1) { s = s * a % mod; }a = (a*a) % mod;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(long long x) { if (x <= 1)return false;if (x == 2)return true;if (x % 2 == 0)return false;long long i, m;m = sqrt(x);f(i, 2, m) { if (x % i == 0)return false; }return true; }

const int N = 2e5 + 5;

int t;

int main()
{

	//cin >> t;
	ll n, k;
	while (cin >> n >> k)
	{
		string a;
		while (n)
		{
			char b = n % k;
			n /= k;
			a += b;
		}
		cout << a.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9+7;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	vector<int> dp(100001, INF);
	rep(i,n){
		*lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
	}
	cout << (lower_bound(dp.begin(), dp.end(), INF) - dp.begin()) << endl;
	return 0;
}


Measured memory_bytes: 3620
fun main(args: Array<String>) {
  val S = readString()
  var sum = 0
  for (i in 0 until (S.length + 1) / 2) {
    if (S[i] != S[S.length - 1 - i]) sum++
  }
  println(sum)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(' ')
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 33472
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

const int MAX_N = 100000;
const int MAX_V = 1000000000;

PII ps[MAX_N];

int main() {
  ll x = 1, y = 0, z = 0, n, m = 0, k, h, ans = 0, w, sum = 1, Max = -1e9 - 1,
     cnt = 0, Min = 1e9 + 1;
  string s, t, u;
  bool ok = true;
  cin >> n;
  VL a(n), b(n);
  rep(i, n) { cin >> a[i] >> b[i]; }

  PII ps[MAX_N];

  rep(i, n) { ps[i] = {a[i] + b[i], a[i] - b[i]}; }
  sort(ps, ps + n);
  int now = -MAX_V;
  ans = 0;
  rep(i, n) {
    if (now <= ps[i].second) {
      ans++;
      now = ps[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
n, m = map(int, input().split())
sub = [list(input().split()) for j in range(m)]
li = [[0 for i in range(n)]for j in range(2)]
for i in range(m):
    x = int(sub[i][0])-1
    if sub[i][1] == 'AC':
        if li[0][x] == 0:
            li[0][x] += 1
    elif li[0][x] == 0:
        li[1][x] += 1
    else:
        next

ac = sum(li[0])
wa = 0
for i in range(n):
    if li[0][i] == 1:
        wa += li[1][i]

print('{} {}'.format(ac,wa))



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

int main(void) {
  int A, B, ans;
  cin >> A >> B;
  
  ans = A - 2*B;
  
  if(ans<=0) cout << 0 << endl;
  else cout << ans << endl;
  
  
  return 0;
}

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

int main()
{
   vector<int> v(3);
   for(int i=0; i<3; i++) cin >> v[i];
   sort(v.begin(), v.end());
   for(int i=0; i<2; i++) cout << v[i] << " ";
   cout << v[2] << endl;
}


Measured memory_bytes: 3160
l,r = map(int,input().split())
if r - l >= 2019:
    print(0)
else:
    ans_o = (l*(l+1))%2019
    for i in range(l,r):
        for j in range(i+1,r+1):
            ans = (i*j)%2019
            ans_o = min(ans,ans_o)
    print(ans_o)


Measured memory_bytes: 40428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var arare = Console.ReadLine().Split();
            Console.WriteLine(arare.Distinct().Count() == 3 ? "Three" : "Four");
        }
    }
}

Measured memory_bytes: 13280
// https://atcoder.jp/contests/abc127/tasks/abc127_d

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, a, b, c;
    cin >> n >> m;
    vector<PII> v;
    REP(i, n) {
        cin >> a;
        v.push_back(PII(a, 1));
    }
    REP(i, m) {
        cin >> b >> c;
        v.push_back(PII(c, b));
    }
    sort(ALLR(v));
    ll sum = 0;
    int cnt = n;
    for (const auto &x : v) {
        if (x.second < cnt) {
            cnt -= x.second;
            sum += (ll)x.first * x.second;
        } else {
            sum += (ll)x.first * cnt;
            break;
        }
    }
    cout << sum << '\n';

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const ll Mod = 1e9 + 7;
const ll Inf = 2242545357980376863LL;
const ll Log = 20;
const ll N = 1ll << Log;
const int Maxn = 5e2 + 10;
const int Base = 101;

ll c1[30], c2[30];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(c2, 31 , sizeof c2);
	ll n, m;
	cin >> n >> m;
	ll s1 = 0, s2 = 0;
	ll sm = 0, v;
	for(int i = 0; i < n; i++){
		cin >> v;
		s1 += ((v * i) - sm);
		sm += v;
	}
	sm = 0;
	for(int i = 0; i < m; i++){
		cin >> v;
		s2 += ((v * i) - sm);
		sm += v;
	}
	cout << (s1 % Mod)*(s2 % Mod) % Mod;
	return 0;
}


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

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = getIntList >>= \(n:_) -> replicateM n getLine >>= \ss -> putStrLn $ concat (sort ss)

Measured memory_bytes: 1404
#include<iostream>
#include<cstdio>
const int N=1e5+5;
int n,cnt,head[N],nxt[N<<1],to[N<<1],deg[N];
void init() {
    for(int i=0;i<n;i++) head[i]=-1,deg[i]=0;cnt=0;
}
void addEdge(int u,int v) {
    nxt[cnt]=head[u];to[cnt]=v;head[u]=cnt++;
}
int dfs(int u,int fa) {
    int ans=0;bool f=false;
    for(int i=head[u];~i;i=nxt[i]) {
        int v=to[i];if(v==fa) continue;
        int tmp=dfs(v,u);
        ans+=tmp?tmp:f;
        f=f||!tmp;
    }
    return ans;
}
int main() {
    scanf("%d",&n);init();int u,v;
    for(int i=1;i<n;i++) scanf("%d%d",&u,&v),addEdge(u,v),addEdge(v,u),deg[v]++,deg[u]++;
    int root=-1;
    for(int i=0;i<n;i++) if(deg[i]>2) root=i;
    printf("%d\n",root==-1?1:dfs(root,-1));
    return 0;
}


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

int N, M, Q;
vector<int> a, b, c, d;
int A[10];

int dfs(int i, int A_pi) {
  int res = -1, sum = 0;
  if (i == N) {
    for (int j = 0; j < Q; ++j) {
      sum += A[b[j] - 1] - A[a[j] - 1] == c[j] ? d[j] : 0;
    }
  }

  if (i == N) {
    return sum;
  }

  for (int j = A_pi; j <= M; ++j) {
    A[i] = j;
    res = max(dfs(i + 1, A[i]), res);
  }

  return res;
}

int main() {
  cin >> N >> M >> Q;
  a.resize(Q), b.resize(Q), c.resize(Q), d.resize(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  // A.resize(N);
  cout << dfs(0, 1) << endl;
}

Measured memory_bytes: 3588
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


struct Edge {
    int t;
    int diff;
};

int V[100000];
int visited[100000];
vector<vector<Edge>> E;

void dfs(int v) {
    visited[v] = 1;
    for(int i = 0; i < E[v].size(); i++) {
        if (visited[E[v][i].t] == 0) {
            V[E[v][i].t] = V[v] + E[v][i].diff;
            dfs(E[v][i].t);
        } 
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    E.resize(N);
    for(int i = 0; i < M; i++) {
        int l, r;
        int d;

        cin >> l >> r >> d;
        l--, r--;

        E[l].push_back((Edge){r, d});
        E[r].push_back((Edge){l, -d});
    }

    for (int i = 0; i < 100000; i++) {
        V[i] = 0;
        visited[i] = 0;
    }

    for(int i = 0; i < N; i++) {
        if (visited[i] == 0) {
            dfs(i);
        }
    }

    for (int i = 0; i < N; i++) {
        for(int j = 0; j < E[i].size(); j++) {
            if (V[E[i][j].t] - V[i] != E[i][j].diff) {
                cout << "No" << endl;
                return 0;
            }

        }
    }

    cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 11392
#include<iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
using namespace std;

int main()
{
	std::string str;
	long int n = 0;
	long int s = 0;

	std::cin >> str;

	n = atoi(str.c_str());

	for (int i = 0; i < str.length(); i++) {
		s += str[i] - '0';
	}

	if(n%s == 0)
		std::cout << "Yes" << '\n';
	else
		std::cout << "No" << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int a[4];
int main() {
  IOS;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (s == "AC")
      a[0]++;
    else if (s == "WA")
      a[1]++;
    else if (s == "TLE")
      a[2]++;
    else
      a[3]++;
  }
  cout << "AC x " << a[0] << endl;
  cout << "WA x " << a[1] << endl;
  cout << "TLE x " << a[2] << endl;
  cout << "RE x " << a[3] << endl;
}

Measured memory_bytes: 3656
N, M = gets.split.map(&:to_i)

o = 1000000007
anser = 0

if (N-M).abs>=2 then
    ##
elsif (N-M).abs == 0 then
    nn = (1..N).inject{|an, t| an= ((an%o)*(t%o))%o}
    anser = ((nn% o) * (nn% o) * 2) % o
else
    nn = (1..[N,M].min).inject{|an, t| an= ((an%o)*(t%o))%o}
    mn = nn*[N,M].max
    anser = ((nn% o) * (mn% o)) % o
end

puts anser

Measured memory_bytes: 1788
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
count = 0
for i in range(q):
  l = -1
  u = len(s)
  while (u - l > 1):
    x = (u + l) // 2
    if s[x] >= t[i]:
      u = x
    else:
      l = x
  if s[l] == t[i] or s[u] == t[i]:
    count += 1
print(count)


Measured memory_bytes: 16704
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int num = S.length();
		sc.close();

		for (int i = 0; i < num; i++) {
			System.out.print("x");
		}
	}

}


Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int n,a[100005],q;
ll sum1[100005],sum0[100005];
int ask(ll v)
{
	int l=1,r=n;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(a[mid]<v)l=mid+1;
		else r=mid-1;
	}
	return l;
}
void work(int v)
{
	int l=1,r=n+1;
	while(l<=r)
	{
		int mid=l+r>>1;
		if(a[mid]<v)l=mid+1;
		else if(mid-ask(2*v-a[mid])+1<n-mid)l=mid+1;
		else if(mid-ask(2*v-a[mid])+1>n-mid)r=mid-1;
		else
		{
			r=mid;
			break;
		}
//		printf("mid=%d->%d %d\n",mid,l,r);
	}
	int p=2*r-n+1;
	if(p<1)p=1;
	if(p>r)p=r;
//	printf("l=%d r=%d\n",p,r);
	ll ans=sum1[n]+sum0[n]-sum1[r]-sum0[r];
//	printf("%lld ",ans);
	ans+=((p&1)^(n-p+1&1)?sum0[p-1]:sum1[p-1]);
	printf("%lld\n",ans);
}
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum1[i]=sum1[i-1],sum0[i]=sum0[i-1];
		if(i&1)sum1[i]+=a[i];
		else sum0[i]+=a[i];
	}
	sum1[n+1]=sum1[n],sum0[n+1]=sum0[n];
	while(q--)
	{
		int v;
		scanf("%d",&v);
		work(v);
	}
	return 0;
}

Measured memory_bytes: 3584
//C
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main(void) {
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) { cin >> a.at(i); }
	sort(a.begin(),a.end());
	int result = k;
	int b = a.at(0) + k - a.at(n - 1);
	result -= b;
	for (int i = 0; i < n-1; i++) {
		result = min(result, k - a.at(i + 1) + a.at(i));
	}
	cout << result << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii ;
const int mod = 1e9 + 7;

ll binPow(ll x, ll y, ll md = mod){
    ll res = 1;
    x %= mod;
    while(y){
        if(y & 1){
            res = (res * x) % mod;
        }
        y >>= 1;
        x = (x * x) % mod;
    }
    return res;
}

void vout(vector<ll> v){
    for(int i = 0; i < v.size(); i++){
        cout << v.at(i) << "\n";
    }
}

void solve(){
    vector<ll> vec(10, 0);
    ll h, w, all, n;
    map<pii, int> sq;
    cin >> h >> w >> n;
    all = (h - 2) * (w - 2);
    vector<int> a, b;
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        bool u, d, l, r;
        u = d = l = r = false;
        if(x > 2)
            u = true;
        if(y > 2)
            l = true;
        if(x < h - 1)
            d = true;
        if(y < w - 1)
            r = true;
        if(u&&y>1&&y<w) (sq.count(pii (x-2,y-1))?sq.at(pii (x-2,y-1))+=1:sq[pii (x-2,y-1)]=1);
        if(u&&l) (sq.count(pii (x-2,y-2))?sq.at(pii (x-2,y-2))+=1:sq[pii (x-2,y-2)]=1);
        if(u&&r) (sq.count(pii (x-2,y))?sq.at(pii (x-2,y))+=1:sq[pii (x-2,y)]=1);
        if(d&&y>1&&y<w) (sq.count(pii (x,y-1))?sq.at(pii (x,y-1))+=1:sq[pii (x,y-1)]=1);
        if(d&&l) (sq.count(pii (x,y-2))?sq.at(pii (x,y-2))+=1:sq[pii (x,y-2)]=1);
        if(d&&r) (sq.count(pii (x,y))?sq.at(pii (x,y))+=1:sq[pii (x,y)]=1);
        if(l&&x>1&&x<h) (sq.count(pii (x-1,y-2))?sq.at(pii (x-1,y-2))+=1:sq[pii (x-1,y-2)]=1);
        if(r&&x>1&&x<h) (sq.count(pii (x-1,y))?sq.at(pii (x-1,y))+=1:sq[pii (x-1,y)]=1);
        if(x>1&&x<h&&y>1&&y<w) (sq.count(pii (x-1,y-1))?sq.at(pii (x-1,y-1))+=1:sq[pii (x-1,y-1)]=1);
    }
    for(pair <pii, int> p : sq){
        vec.at(p.second) += 1;
    }
    vec.at(0) = all - sq.size();
    vout(vec);
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 56576