akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


int main(){
  int N;
  int64_t K;
  cin>>N;
  cin>>K;
  vector<int64_t> A(N);
  for(int i=0;i<N;++i){
    cin>>A.at(i);
  }

  bitset<40> s(K);
  int64_t sum=0;
  int d=39;
  while(d>=0 && !s.test(d)){
  for(int i=0;i<N;++i){
    bitset<40> t(A.at(i));
    if(t.test(d)){
      sum=sum+int64_t(pow(2,d));
    }
  }
    --d;
  }

  bool frag=false;

  for(int i=d;i>=0;--i){

    //i桁目の1の個数をカウント
    int count=0;
    for(int j=0;j<N;++j){
      bitset<40> t(A.at(j));
      if(t.test(i)){
        ++count;
      }
    }

    if(frag){
      sum=sum+int64_t(pow(2,i))*int64_t(max(count,N-count));
    }

    else{

      if(count>=N-count){

        if(s.test(i)){
          sum=sum+int64_t(pow(2,i))*int64_t(count);
          frag=true;
        }

        else{
          sum=sum+int64_t(pow(2,i))*int64_t(count);
        }
      }

      else{
        if(s.test(i)){
          sum=sum+int64_t(pow(2,i))*int64_t((N-count));
        }
        else{
          sum=sum+int64_t(pow(2,i))*int64_t(count);
        }
      }

    }
  }

if(d>=0){
  cout<<sum<<endl;
}
else{
    int64_t sum2=0;
    for(int i=0;i<N;++i){
      sum2=sum2+A.at(i);
    }
    cout<<sum2<<endl;
  }
}

Measured memory_bytes: 1152
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static io;
public class CompetitiveProgramming
{
  public void Solve()
  {
    var N = Int1;
    var A = Ints;
    int ans = 0;
    bool flag = true;
    while (flag)
    {
      flag = false;
      for (int j = N - 1; j >= 1; --j)
      {
        if (A[j] < A[j - 1])
        {
          var x = A[j];
          A[j] = A[j - 1];
          A[j - 1] = x;
          ans++;
          flag = true;
        }
      }
    }

    Write(A);
    Write(ans);
  }


}

class BIT
{

}



class Program
{
  static void Main(string[] args)
  {
    var CompetitiveProgramming = new CompetitiveProgramming();
    CompetitiveProgramming.Solve();
  }
}
public static class io
{
  public static string Str => Console.ReadLine();
  public static string[] Strs => Str.Split(' ');
  public static long[] Longs => Strs.Select(long.Parse).ToArray();
  public static int[] Ints => Strs.Select(int.Parse).ToArray();
  public static char[] Chars => Str.ToArray();
  public static double[] Doubles => Strs.Select(double.Parse).ToArray();
  public static long Long1 => Longs[0];
  public static int Int1 => Ints[0];
  public static char Char1 => Chars[0];
  public static double Double1 => Doubles[0];
  public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; }
  public static void Write(string a) => Console.WriteLine(a);
  public static void Write(params object[] i) => Write(string.Join(" ", i));
  public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
  public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); }
  public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); }
}



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

using namespace std;

int main(){

	int n,a[1000],ans,temp;

	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		ans=1000000;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(a[i]>=a[j]){
					temp=a[i]-a[j];
					ans=min(ans,temp);
				}
				else{
					temp=a[j]-a[i];
					ans=min(ans,temp);
				}
			}

		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3100
#include <stdio.h>
#include <stdlib.h>

struct node
{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node *Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x)
{
    while (x->left != NIL)
    {
        x = x->left;
    }
    return x;
}

Node treeMaximum(Node x)
{
    while (x->right != NIL)
    {
        x = x->right;
    }
    return x;
}

Node treeSearch(Node u, int k)
{
    if (u == NIL || k == u->key)
        return u;
    if (k < u->key)
        return treeSearch(u->left, k);
    else
        return treeSearch(u->right, k);
}

Node treeSuccessor(Node x)
{
    Node y;
    if (x->right != NIL)
        return treeMinimum(x->right); //case 1

    y = x->parent;
    while ((y != NIL) && x == y->right)
    {
        x = y;
        y = y->parent;
        return y; //case 2
    }
}

void treeDelete(Node z)
{
    Node y; // node to be deleted
    Node x; // child of y
}

void insert(int k)
{
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
            x = x->left;
        else
            x = x->right;
    }

    z->parent = y;

    if (y == NIL)
        root = z;
    else if (z->key < y->key)
        y->left = z;
    else
        y->right = z;
}

void inorder(Node u)
{
    if (u != NIL)
    {
        inorder(u->left);
        printf(" %d", u->key);
        inorder(u->right);
    }
}
void preorder(Node u)
{
    if (u != NIL)
    {
        printf(" %d", u->key);
        preorder(u->left);
        preorder(u->right);
    }
}

int main()
{
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%s", com);
        if (com[0] == 'f')
        {
            scanf("%d", &x);
            Node t = treeSearch(root, x);
            if (t != NIL)
                printf("yes\n");
            else
                printf("no\n");
        }
        else if (com[0] == 'i')
        {
            scanf("%d", &x);
            insert(x);
        }
        else if (com[0] == 'p')
        {

            inorder(root);
            // if(i != n-1)printf(" ");//空白処理
            printf("\n");

            preorder(root);
            // if(i != n-1) printf(" ");//空白処理
            printf("\n");
        }
        else if (com[0] == 'd')
        {
            scanf("%d", &x);
            treeDelete(treeSearch(root, x));
        }
    }

    return 0;
}



Measured memory_bytes: 25192
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define INF 100000000
#define rep(i,a,b) for(int (i)=a;(i)<(int)(b);(i)++)

int main(){
    ll N;
    cin >> N;
    vector<ll>A(N,0);
    rep(i,0,N) cin>>A[i];
    rep(i,0,N) A[i] = A[i]-1;
    vector<ll> sNum2(N,0);
    rep(i,0,N){
        sNum2[A[i]] +=1;
    }
    vector<ll> pairNum(N,0);
    rep(i,0,pairNum.size()){
        pairNum[i] = sNum2[i]*(sNum2[i]-1)/2;
    }
    ll total = accumulate(pairNum.begin(),pairNum.end(),0LL);
    rep(i,0,N){
        cout << total - (sNum2[A[i]]-1)<< endl;
    }
}

Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String[] s = new String[n];
		
		for(int i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		sc.close();
		int a = 0;// ...A
		int b = 0;// B...
		int c = 0;// B...A
		int ans = 0;
		for(int i = 0; i < n; i++) {
			String first = String.valueOf(s[i].charAt(0));
			String end = String.valueOf(s[i].charAt(s[i].length()-1));
			for(int j = 0; j < s[i].length()-1; j++) {
				String ich = String.valueOf(s[i].charAt(j));
				String ni = String.valueOf(s[i].charAt(j+1));
				if (ich.equals("A") && ni.equals("B")) {
					ans++;
				}
			}
			if(first.equals("B") && end.equals("A")) {
				c++;
			} else if (first.equals("B")) {
				b++;
			} else if (end.equals("A")) {
				a++;
			}
		}
		if (c == 0) {
			ans += Math.min(a,b);
		} else if (a == 0 && b == 0) {
			ans += c-1;
		} else if (a == 0 || b == 0) {
			ans += c;
		} else {
			ans += c+1 + Math.min(a-1,b-1);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 36404
import math
 
N = int(input())
Prime = []
ans = 0
 
def func(n):
    while n % 2 == 0:
        n = n // 2
        Prime.append(2)
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        while n % i == 0:
            n = n //i
            Prime.append(i)
    if n > 2:
        Prime.append(n)
 
func(N)
 
for i in set(Prime):
    c = i
    while N % c == 0:
        N = N // c
        ans += 1
        c = c * i
 
print(ans)

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

int main() {
	int a,b;
	cin >> a >> b;
	
	if (a < b) {
		cout << "a < b" << endl;
	}
	else if(a > b) {
		cout << "a > b" << endl;
	}
	else {
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int ans;
char S[10000];
inline void read(int &x)
{
	int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<3)+(data<<1)+(ch^'0'),ch=getchar();
	x=data*w;
}
int main()
{
	scanf("%s",S);
	for(register int i=0;i<strlen(S);++i)
		if(S[i]=='1')ans++;
	printf("%d\n",ans);
	return 0;
}

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

// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n), f(n), b(n);
  REP(i, n) { cin >> a[i]; }
  REP(i, n) {
    if (i == 0)
      f[i] = a[i];
    else
      f[i] = gcd(a[i], f[i - 1]);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1)
      b[i] = a[i];
    else
      b[i] = gcd(b[i + 1], a[i]);
  }
  int ans = -1;
  REP(i, n) {
    int g;
    if (i == 0)
      g = b[1];
    else if (i == n - 1)
      g = f[n-2];
    else
      g = gcd(f[i - 1], b[i + 1]);
    ans = max(ans, g);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4524
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 998244353;
const long long INF = 1LL << 60;


const int MAX_N = 1000010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c; cin >> a >> b >> c;
	if (a + b + c >= 22)cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}


Measured memory_bytes: 256
import math

tmp=input().split(" ")
tyousin=int(tmp[0])
tansin=int(tmp[1])
time_hour=int(tmp[2])
time_min=int(tmp[3])

long_kaku=2*math.pi*(time_min/60)
min_kaku=2*math.pi*((60*time_hour + time_min)/720)
angle=long_kaku-min_kaku

print(((tansin*math.sin(angle))**2 + (tyousin-(tansin*math.cos(angle)))**2)**0.5)

Measured memory_bytes: 9616
use proconio::{input, fastout};

const MOD: usize = 1_000_000_007;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let mut ans = 0;

    for i in k..=n + 1 {
        let min_ = i * (i - 1) / 2;
        let max_ = i * (2 * n - i + 1) / 2;
        ans += max_ - min_ + 1;
        ans %= MOD;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2200
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 = do
    [n,m] <- getIntList
    s <- getLine
    t <- getLine
    let l = lcm n m
        d = gcd n m
        si = n `div` d
        ti = m `div` d
        s' = [s !! (si*i) |i <- [0..d-1]]
        t' = [t !! (ti*i) |i <- [0..d-1]]
    print $ if s' == t' then l else -1

Measured memory_bytes: 9596
/*
 * 2342.cc: Light Road
 */

#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 */

const int MAX_N = 100;
const int MAX_M = 100;
const int MAX_A = 10;

const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};

const int INF = 1 << 30;

/* typedef */

struct Stat {
  int d, x, y, di, p, q;
  Stat() {}
  Stat(int _d, int _x, int _y, int _di, int _p, int _q):
    d(_d), x(_x), y(_y), di(_di), p(_p), q(_q) {}
  bool operator<(const Stat &s) const { return d < s.d; }
  bool operator>(const Stat &s) const { return d > s.d; }
};

typedef vector<Stat> vs;

/* global variables */

string flds[MAX_N];
bool pm[4][4], qm[4][4];
int dists[MAX_N][MAX_M][4][MAX_A + 1][MAX_A + 1];

/* subroutines */

/* main */

int main() {
  pm[0][3] = pm[1][2] = pm[2][1] = pm[3][0] = true;
  qm[0][1] = qm[1][0] = qm[2][3] = qm[3][2] = true;

  int n, m, a;
  cin >> n >> m >> a;

  int sx, sy, gx, gy;
  
  for (int y = 0; y < n; y++) {
    cin >> flds[y];
    for (int x = 0; x < m; x++)
      switch (flds[y][x]) {
      case 'S': sx = x; sy = y; break;
      case 'G': gx = x; gy = y; break;
      }
  }

  memset(dists, -1, sizeof(dists));
  dists[sy][sx][3][a][a] = 0;

  priority_queue<Stat,vs,greater<Stat> > q;
  q.push(Stat(0, sx, sy, 3, a, a));

  int mind = INF;
  
  while (! q.empty()) {
    Stat u = q.top(); q.pop();
    if (u.d != dists[u.y][u.x][u.di][u.p][u.q]) continue;

    if (u.x == gx && u.y == gy) {
      mind = u.d;
      break;
    }

    int rudi = (u.di + 2) % 4;
    
    for (int vdi = 0; vdi < 4; vdi++) {
      if (vdi == rudi) continue;
      if (u.x == sx && u.y == sy &&
	  (u.di != vdi || (u.d > 0 && (vdi == 1 || vdi == 3)))) continue;

      int vx = u.x + dxs[vdi], vy = u.y + dys[vdi];
      if (vx < 0 || vx >= m || vy < 0 || vy >= n || flds[vy][vx] == '#')
	continue;

      int vd = u.d, vp = u.p, vq = u.q;
      if (pm[u.di][vdi]) vd++, vp--;
      else if (qm[u.di][vdi]) vd++, vq--;

      if (vp >= 0 && vq >= 0 && dists[vy][vx][vdi][vp][vq] < 0) {
	dists[vy][vx][vdi][vp][vq] = vd;
	q.push(Stat(vd, vx, vy, vdi, vp, vq));
      }
    }
  }

  printf("%d\n", mind < INF ? mind : -1);
  return 0;
}

Measured memory_bytes: 20576
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			if(N >= 1800) {
				System.out.println(1);
			}else if(N >= 1600) {
				System.out.println(2);
			}else if(N >= 1400) {
				System.out.println(3);
			}else if(N >= 1200) {
				System.out.println(4);
			}else if(N >= 1000) {
				System.out.println(5);
			}else if(N >= 800) {
				System.out.println(6);
			}else if(N >= 600) {
				System.out.println(7);
			}else if(N >= 400) {
				System.out.println(8);
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32744
#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++)
#define REP(i,b,n) for(int i=b;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},dy[]={0,-1,0,1};

int main(){
	int a,b,c;
	while(cin>>a>>b>>c){
		if(cin.eof())break;
		int d =a*10000+b*100+c;
		if(d<18680908)cout<<"pre-meiji"<<endl;
		else if(d>=18680908&&d<=19120729){
			cout<<"meiji "<<a-1867<<' '<<b<<' '<<c<<endl;
		}
		else if(d>=19120730&&d<=19261224){
			cout<<"taisho "<<a-1911<<' '<<b<<' '<<c<<endl;
		}
		else if(d>=19261225&&d<=19890107){
			cout<<"showa "<<a-1925<<' '<<b<<' '<<c<<endl;
		}
		else{
			cout<<"heisei "<<a-1988<<' '<<b<<' '<<c<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1156
N, A, B = [int(x) for x in input().split()]

n_sum = 0
for i in range(1, N+1):
    digit_sum = sum([int(c) for c in str(i)])   # 各桁の和
    if digit_sum >= A and digit_sum <= B:
        n_sum += i
print(n_sum)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	ll n;
	cin >> n;
	ll nn;
	nn = sqrt(n);
	//cout << n;
	ll buffer(0);
	rep(i, nn-1) {
		if (n % (i + 2) == 0) {
			ll k =(i + 2);
			//cout << k;
			buffer = max(buffer, k);
		}
		
	}
	//cout << buffer;
	if (buffer == 0) {
		cout << n - 1;
		return 0;
	}
	ll p = n / buffer;
	cout << buffer + p - 2;
	return 0;
}

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

using namespace std;

void solve()
{
	vector<int> dim(4);
	for (int i = 0; i < 3; i++)
	{
		int a, b;
		cin >> a >> b;
		dim[a-1]++;
		dim[b-1]++;
	}
	for (int d : dim)
	{
		if (d == 0 || d >= 3)
		{
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

int N;
vector<int> small;
vector<int> big;
vector<int> curr(8);
vector<vector<int>> perms(50000);
int idx;

int solve(int pos, bool restrict) {
    if (pos == N) {
        for (int i = 0; i < N; ++i) {
            if (curr[i] != big[i])
                return 1;
        }
        return 0;
    }

    int ans = 0;
    if (restrict) {
        for (int i = small[pos]; i <= big[pos]; ++i) {
            curr[pos] = i;
            if (i == big[pos])
                ans += solve(pos+1, true);
            else
                ans += solve(pos+1, false);
        }
    } else {
        for (int i = 1; i <= N; ++i) {
            curr[pos] = i;
            ans += solve(pos+1, false);
        }
    }
    return ans;
}

void get_perms(int pos, vector<bool> &used) {
    if (pos == N) {
        for (int i = 0; i < N; ++i) {
            perms[idx].push_back(curr[i]);
        }
        ++idx;
        return;
    }

    for (int i = 1; i <= N; ++i) {
        if (used[i]) continue;
        used[i] = true;
        curr[pos] = i;
        get_perms(pos+1, used);
        used[i] = false;
    }
}


int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a; small.push_back(a);
    }
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a; big.push_back(a);
    }

    for (int i = 0; i < N; ++i) {
        if (small[i] != big[i]) {
            if (small[i] > big[i]) {
                for (int j = 0; j < N; ++j) {
                    int tmp = small[j];
                    small[j] = big[j];
                    big[j] = tmp;
                }
            }
            break;
        }
    }

    /*
    for (int i = 0; i < N; ++i)
        cout << small[i] << "\t";
    cout << "\n";
    for (int i = 0; i < N; ++i)
        cout << big[i] << "\t";
    cout << endl;
    */

    vector<bool> used(10, false);
    get_perms(0, used);
    int ans = 0;
    for (int i = 0; i < idx; ++i) {
        bool ok = false;
        for (int j = 0; j < N; ++j) {
            if (perms[i][j] > small[j]) {
                ok = true;
                break;
            } else if (perms[i][j] < small[j]) {
                break;
            }
        }
        if (!ok) continue;
        ok = true;
        for (int j = 0; j < N; ++j) {
            if (perms[i][j] > big[j]) {
                ok = false;
                break;
            } else if (perms[i][j] < big[j]) {
                break;
            }
        }
        if (ok) ++ans;
    }

    cout << ans << endl;

    //cout << solve(0, true) << endl;


    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int r;
    cin >> r;
    cout << 3 * r * r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define X 753
int main(void){
	char S[11];
	int min,i,meka;
	scanf("%s",S);
	min=X;
	for(i=0;i<8;i++){
		meka=100*(S[i]-48)+10*(S[i+1]-48)+(S[i+2]-48);
		if(min>abs(X-meka)){
			min=abs(X-meka);
		}
		if(strcmp(S+(i+3),"\0")==0){
			break;
		}
	}
	printf("%d\n",min);
	return 0;
}

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

#define rep(i,n) for(int i = 0;i < (n); ++i)
using namespace std;
using Graph = vector<vector<pair<int,int>>>;

typedef long long LL;
typedef long double LD;
const int mod = 1000000007;
//abc146d
Graph G;
int n;

void dfs(int v, int p, int pc, vector<int> &res){
    int color = 1;
    if(color == pc)color++;
    for(int i = 0;i < G[v].size(); i++){
        if(G[v][i].first == p)continue;
        res[G[v][i].second] = color;
        dfs(G[v][i].first, v, color, res);
        ++color;
        if (color == pc) ++color;
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    G.assign(n, vector<pair<int, int>>());
    rep(i , n - 1){
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i){
        int tmp = G[i].size();
        ans = max(tmp, ans);
    }
    vector<int> res(n - 1, -1);
    dfs(0, -1, -1, res);
    cout << ans << endl;
    for(int i = 0;i < res.size(); i++)cout << res[i] << endl;
}

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

int main() {
 int n,d=0; cin>>n;
  int p[n];
  for(int i=0;i<n;i++){
    
    cin>>p[i];
     if(p[i]!=i+1) d++;
  }

  if(d>2) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
    using namespace std;
    int main()
    {
        char a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a==b&&c==d&&a!=c&&a!=d)
        {
            cout<<"Yes";
        }
        else if(a==d&&b==c&&a!=b&&a!=c)
        {
            cout<<"Yes";
        }
        else if(a==c&&b==d&&a!=b&&a!=d)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
     
     
     
        return 0;
    }

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

int main()
{
  long n;
  std::cin >> n;
  std::vector<long> d(n);
  for(long i=0; i<n; i++) std::cin >> d[i];
  std::sort(d.begin(), d.end());
  long k=2, count=0;
  long pn = 0;
  long itr;
  while(pn<n)
  {
    for(itr=pn; d[itr]<k; itr++);
    pn = itr;
    if(pn==n/2)
    {
      count++;
    }
    k++;
  }
  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC179
{
    class Program
    {
        static void Main(string[] args)
        {
            //var NXT = Console.ReadLine().Split().Select(double.Parse).ToArray();
            var N = long.Parse(Console.ReadLine());
            //var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var L = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            //var ans = false;
            var ans = 0;
            for (int i = 1; i < Math.Sqrt(N); i++)
            {
                for (int j = i; i * j < N; j++)
                {
                    if (i == j) ans++;
                    else ans += 2;

                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 27556
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
			int d = sc.nextInt();
			set.add(d);
		}
		
		System.out.println(set.size());
		
		sc.close();
	}
}




Measured memory_bytes: 27256
// ABC096-B
// OrangeStar

#include<stdio.h>

int main(void){
  int h, w;
  scanf("%d %d", &h, &w);

  char s[h+2][w+2];
  int i, j;

  for(i=1; i<h+1; i++){
    scanf("%s", &s[i][1]);
  }
  for(i=0; i<h+2; i++){
    s[i][0]='.';
    s[i][w+1]='.';
  }
  for(i=0; i<w+2; i++){
    s[0][i]='.';
    s[h+1][i]='.';
  }

  int check=0;

  for(i=0; i<h+2; i++){
    for(j=0; j<w+2; j++){
      if(s[i][j]=='#'){
        if(s[i-1][j]=='.' &&
           s[i+1][j]=='.' &&
           s[i][j-1]=='.' &&
           s[i][j+1]=='.'){
             check=1;
        }
      }
      if(check==1){
        break;
      }
    }
    if(check==1){
      break;
    }
  }

  if(check==1){
    printf("No\n");
  }else{
    printf("Yes\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N,maxcount=0;
  string a;
  cin>>N;
  map<string,ll> mp;
  for(ll i=0;i<N;i++){
    cin>>a;
    mp[a]++;
  }
  for(auto i=mp.begin();i!=mp.end();i++){
    if((ll)(*i).second>maxcount){maxcount=(ll)(*i).second;}
  }
  for(auto i=mp.begin();i!=mp.end();i++){
    if((ll)(*i).second==maxcount){cout<<(string)(*i).first<<endl;}
  }
}

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

int main() {
  vector<string> vec = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string S;
  
  cin >> S;
  
  for (int i = 0; i<7; i++){
    if (S == vec.at(i)){
      cout << 7-i << endl;
    }
  }
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        
        if(line.equals("ABC")){
            System.out.println("ARC");
        }
        else{
            System.out.println("ABC");
        }
    }
}

Measured memory_bytes: 35756
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n,t = map(int,input().split())
  mi_ = float("inf")
  change = False
  for _ in range(n):
    c,t_ = map(int,input().split())
    if t_ <= t:
      mi_ = min(mi_,c)
      change = True
  if change:
    print(mi_)
  else:
    print('TLE')
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;


int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    sort(A.begin(), A.end());

    vector<int> a(1000005, 0);

    rep(i,N){
        int n = A[i];
        if( a[n] > 0){
            a[n]++;
            continue;
        }
        else{
            for(int j = n; j < 1000005; j = j + n) a[j]++;
        }
    }

    int ans = 0;
    rep(i,N){
        if (a[A[i]] == 1) ans++;
    }    

    cout << ans << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b, c, d;
int imo[123];

int main() {
	cin >> a >> b >> c >> d;
	imo[a]++, imo[b]--, imo[c]++, imo[d]--;
	int ans = 0;
	rep(i,110) {
		imo[i+1] += imo[i];
		if (imo[i]==2) ans++;
	}
	cout << ans << ln;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void doIt() {
		int H = sc.nextInt();
		int W = sc.nextInt();
		int s = H * W;
		int h = sc.nextInt();
		int w = sc.nextInt();
		s -= h * W + w * H - h * w;
		System.out.println(s);
		
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
const int N = 4001, mod = 998244353;

int n;
vector<bitset<N> > a;
bitset<N> k;

string in;

int sz (bitset<N> &T) {
	for(int i=N;i--;) {
		if(T[i] == 1) return i+1;
	}
	return 0;
}

int val (bitset<N> T) {
	int R = 0;
	for(int i=N;i--;) {
		R = (2*R + T[i]) % mod;
	}
	return (R + 1) % mod;
}

bool cmp (bitset<N> A, bitset<N> B) {
	for(int i=N;i--;) {
		if(A[i] < B[i]) return true;
		if(A[i] > B[i]) return false;
	}
	return false;
}

void elim (bitset<N> &A, bitset<N> &B) {
	int S = sz(B)-1;
	for(int i=N-1;i>=S;i--) {
		if(A[i] == 1) A ^= (B << (i-S));
	}
}

int main()
{
	cin >> n >> in;
	k = bitset<N>(in);
	for(int i=1;i<=n;i++) {
		cin >> in;
		a.push_back(bitset<N>(in));
	}
	for(int i=1;i<n;i++) {
		if(sz(a[0]) > sz(a[i])) {
			swap(a[0], a[i]);
		}
	}
	while(a.size() > 1) {
		auto &A = a[0], &B = a.back(), T = B;
		elim(B, A);
		swap(A, B);
		if(sz(A) == 0) {
			A = T;
			swap(A, B);
			a.pop_back();
		}
	}
	auto T = k;
	elim(T, a[0]);
	cout << (val(k>>(sz(a[0])-1)) + mod - cmp(k, k^T)) % mod << endl;
}


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

using namespace std;


int solve(vector<int> & prices, int K)
{
	sort(prices.begin(), prices.end());
	int res = 0;
	int i = 0;
	while(K) {
		res += prices[i++];
		K--;
	}
	return res;
}


int main()
{
	int N;
	int K;
	cin >> N >> K;
	vector<int> prices;
	int price;
	for (int i = 0; i < N; i++) {
		cin >> price;
		prices.emplace_back(price);
	}
	cout << solve(prices, K) << endl;
	return 0;
}


Measured memory_bytes: 3596
#!/usr/bin/env python3

N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

Tmp = [T - H[i] * 0.006 for i in range(N)]

tmp = 10 ** 9
ans = -1

for i in range(len(Tmp)):
    if tmp > abs(A-Tmp[i]):
        tmp = abs(A-Tmp[i])
        ans = i

print(ans+1)


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

int main(){
	int a,b;
	cin>>a>>b;
	string ans="IMPOSSIBLE";
	int an=0;
	if(a<b){
    	for(int i=a;i<b;i++){
    		if(abs(a-i)==abs(b-i)){
    			an=i;
    			break;
    		}
    	}
	}else{
	    for(int i=b;i<a;i++){
    		if(abs(a-i)==abs(b-i)){
    			an=i;
    			break;
    		}
    	}
	}
	if(an!=0)cout<<an;
	else cout<<ans;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int a,b,c;
  cin >> a >> b >> c;
  cout << max(c-(a-b),0) << endl;
  return 0;
}


Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;

signed main() {
    cin >> N;
    vector<pii> vs;
    rep(i,0,N) {
        int p; cin >> p;
        vs.push_back(pii(p, -1));
    }
    rep(i,0,N) {
        int p; cin >> p;
        vs.push_back(pii(p, 1));
    }

    sort(vs.begin(), vs.end());
    int ans = 1, rec = 0;
    rep(i,0,2*N) {
        int m = vs[i].second;
        if(m * rec >= 0) rec += m;
        else {
            (ans *= abs(rec)) %= MOD;
            rec += m;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n,m,q;
vector<int>a,b,c,d;
int ans;

void dfs(vector<int>A){
  if(A.size()==n+1){
    int now=0;
    rep(i,q){
      if(A[b[i]]-A[a[i]]==c[i])now+=d[i];
    }
    ans=max(ans,now);
    return ;
  }
  A.push_back(A.back());
  while(A.back()<=m){
    dfs(A);
    A.back()++;
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  cin >> n >>  m >> q;
  a=b=c=d=vector<int>(q);
  rep(i,q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  ans=0; 
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;     
}


Measured memory_bytes: 3680
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

long long a, b, c;

void input() {
	cin >> a >> b >> c;
}

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

	input();

	cout << b + min(a + b + 1, c) << "\n";

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//AピザX枚、BピザY枚いる
//ハーフが得な場合、min(X,Y)枚ハーフを買う
//ハーフが得な場合とは、
/*A,Bピザをmin(X,Y)枚ずつ買う時、min(X,Y)*(A + B) > 2min(X,Y) * C であれば、
ハーフで2min(X,Y) 枚買う
そうでなければ、A,Bピザをmin(X,Y)枚ずつ買う
*/
/*残りmax(X,Y)-min(X,Y)枚について、Aを買うとすると、A > C/2 のとき
ハーフを2*(max(X,Y)-min(X,Y))枚買う
そうでない時、Aをmax(X,Y)-min(X,Y)枚買う
*/

/*残りmax(X,Y)-min(X,Y)枚について、単体で買う場合とハーフで買う場合の安い方
を採用
*/

int main() {
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = 0;
  if(min(X,Y)*(A+B) > 2*min(X,Y)*C){
    ans += 2*min(X,Y)*C;
  }
  else{
    ans += min(X,Y)*(A+B);
  }

  int da = 0;//残りのAの枚数
  int db = 0;//残りのBの枚数
  if(X >= Y){
    da = X - Y;
    ans += min(A*da,2*da*C);
  }
  if( X < Y){
    db = Y - X;
    ans += min(B*db,2*db*C);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll MAX = 1000010;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  COMinit();
  ll x, y;
  cin >> x >> y;
  if ((2 * x - y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if ((2 * y - x) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  ll a = (2 * x - y) / 3;
  ll b = (2 * y - x) / 3;
  if (a < 0 || b < 0) {
    cout << 0 << endl;
    return 0;
  }
  a%=MOD;
  b%=MOD;
  cout << COM((a+b)%MOD, min(a,b)) << endl;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
ll a,b,k,ans1,ans2;
int main(){
  cin >> a >> b >> k;
  if(a<=k){
    k -= a;
    a = 0;
    b -= k;
  }else{
    a -= k;
  }
  cout << (a>0?a:0) << " " << (b>0?b:0) <<   endl;
}


Measured memory_bytes: 256
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,x,y,ans;
void solve()
{
    cin>>n>>m>>x>>y;vector<ll> ar(n),arr(m);
    for(int i=0;i<n;i++)
        cin>>ar[i];
    sort(ar.begin(),ar.end());
    for(int i=0;i<m;i++)
        cin>>arr[i];
    sort(arr.begin(),arr.end());
    bool flag=0;
    if(x>ar[n-1]||y<arr[0])
        {cout<<"War"<<endl;return;}
    for(int i=x;i<=y;i++)
    {
        if(i>ar[n-1]&&i<=arr[0])
            {flag=1;break;}
    }
    if(flag)
        cout<<"No War"<<endl;
    else
        cout<<"War"<<endl;
}
void solve2()
{
    cin>>n;ans=0;map<ll,ll>mp;
    for(int i=0;i<n;i++)
    {
        ll a;cin>>a;mp[a]++;
    }
    for(auto it:mp)
    {
       ans=max(ans,it.second);
        
    }
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define ull unsigned long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define ull unsigned long long 
#define sc second
#define pb push_back
#define mp make_pair
#define sp <<" "
#define all(a) (a).begin(),(a).end()
#define fi(i,a,n) for(int i=a ; i<n ; i++)
#define fd(i,n,a) for(int i=n-1 ; i>=a ; i--)
#define r0 return 0;
#define ln "\n"
#define INF (int)1e15
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   
void solve(){
    
}
int main(){
	fast
    // ll t;cin>>t;
    // while(t--) solve();
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll mx=max(a*c,max(a*d,max(b*c,b*d)));
    cout<<mx<<"\n";
	r0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#define INF 1e8

int min(int a,int b){
	return a>b?b:a;
}
int main(){
	int n,m;
	int st[2][101][101];//0:金額1:時間
	int i,j,k,l;
	while(1){
		int a,b,cost,time;
		int p,q,r;
		scanf("%d %d",&n,&m);
		if(n==0&&m==0){
			break;
		}
		for(i=0;i<=m;i++){
			for(j=0;j<=m;j++){
				st[0][i][j]=st[1][i][j]=INF;
			}
		}
		for(i=0;i<n;i++){
			scanf("%d %d %d %d",&a,&b,&cost,&time);
			st[0][a][b]=st[0][b][a]=cost;
			st[1][a][b]=st[1][b][a]=time;
		}
		for(k=0;k<=m;k++){
			for(i=0;i<=m;i++){
				for(j=0;j<=m;j++){
					st[0][i][j]=min(st[0][i][j],st[0][i][k]+st[0][k][j]);
					st[1][i][j]=min(st[1][i][j],st[1][i][k]+st[1][k][j]);
				}
			}
		}
		scanf("%d",&k);
		for(l=0;l<k;l++){
			scanf("%d %d %d",&p,&q,&r);
			printf("%d\n",st[r][p][q]);
		}
	}
	return 0;
}

Measured memory_bytes: 680
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
    char s[26];

    scanf("%s", s);

    for (int j = 0; j < strlen(s); j++) {
        for (int i = 0; i < strlen(s); i++) {
            if ((i != j) && (s[i] == s[j])) {
                puts("no");
                return 0;
            }
        }
    }

    puts("yes");

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> v;
  rep(i,2*N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));
  int ret = 0;
  rep(i,N){
    ret += min(v[2*i], v[2*i+1]);
  }
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 256
from collections import deque

N = int(input())
b = list(map(int, input().split()))

# 最後に挿入した数字は
# k番目のkとなる

# 1 2 2 1 2 3 2
# 複数通り該当するときは
# 最後の数が該当する
# 0 0 3 0 0 6
# 3を取り除くと
# 0 0 0 0 6 -> 矛盾

ans = deque()

q = deque(enumerate(b, 1))
r = deque()

flg = False
while q:
    idx, bb = q.pop()
    # print(idx, bb, r)
    if idx == bb:
        ans.appendleft(bb)
        if len(ans) == N:
            flg = True
            break
        q.extend(r)
        r = deque()
    else:
        r.appendleft((idx - 1, bb))

if flg:
    for aa in ans:
        print(aa)
else:
    print(-1)

Measured memory_bytes: 3316