akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	int N, M; cin >> N >> M;
	vector<vector<int>> edge(N + 1);
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	deque<int> deq;
	deq.push_front(1), deq.push_back(edge[1][0]);
	vector<bool> vi(N + 1);
	vi[1] = true, vi[edge[1][0]] = true;

	bool flag = true;
	while (flag) {
		flag = false;
		int left = deq.front();
		for (auto to:edge[left]) {
			if (vi[to])continue;
			vi[to] = true;
			deq.push_front(to);
			flag = true;
			break;
		}

		int right = deq.back();
		for (auto to : edge[right]) {
			if (vi[to])continue;
			vi[to] = true;
			deq.push_back(to);
			flag = true;
			break;
		}
	}

	cout << deq.size() << endl;
	for (int i = 0; i < deq.size(); i++) {
		cout << deq[i] << " ";
	}
}


Measured memory_bytes: 9008
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A,B;
  cin>>A>>B;
  if(A+B>=10)cout<<"error"<<endl;
  else cout<<A+B<<endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * B - 81
 * https://atcoder.jp/contests/abc144/tasks/abc144_b
 */
#include <bits/stdc++.h>
using namespace std;

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

  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	string str;
	string apple("apple"),peach("peach");
	getline(cin,str);
	for(int i=0;i<str.length();i++){
		string sub = str.substr(i,5);
		if(sub==apple){
			str.replace(i,5,peach);
		}
		else if(sub==peach){
			str.replace(i,5,apple);
		}
	}
	cout<<str<<endl;
	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

// https://beta.atcoder.jp/contests/abc062/tasks/abc062_b

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

    REP(i, W+2) cout << "#";
    cout << "\n";

    string s;
    REP(i, H) {
        cin >> s;
        cout << "#" + s  + "#" << "\n";
    }

    REP(i, W+2) cout << "#";
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
D=[1<<99]*K=gets.to_i
q=[D[1]=1]
while n=q.shift
	[[n*10%K,0,:unshift],[(n+1)%K,1,:<<]].each{|e,d,m|
		(D[e]>x=D[n]+d)&&(D[e]=x;q.send(m,e))
	}
end
p D[0]

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

int main()
{
    int n;
    cin>> n;
    int a[n];
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    int maxv=-2000000000;
    int minv=a[0];

    for (int i=1;i<n;++i){
        maxv=max(maxv,a[i]-minv);
        minv=min(minv,a[i]);
    }
    cout << maxv<< endl;
    return 0;

}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(ll i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

const double one = 1.0;
const double PI = 3.141592653589;

int main() 
{
	ll n;
	cin>>n;
	vector<P> vl(n);
	FOR(i,0,n)cin>>vl[i].fi>>vl[i].se;
	FOR(i,0,n-2)
	{
		if( vl[i].fi == vl[i].se && vl[i+1].fi == vl[i+1].se && vl[i+2].fi == vl[i+2].se )
		{
			cout<<"Yes"<<endl;return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3596
package main

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

func main() {
	var n, d int
	fmt.Scan(&n, &d)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	count := 0
	for i := 0; i < n; i++ {
		var x, y int
		sc.Scan()
		x, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		y, _ = strconv.Atoi(sc.Text())
		if x*x+y*y <= d*d {
			count++
		}
	}
	fmt.Println(count)

}


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

int main() {
  int N, H, d=0;
  cin >> H >> N ;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    d += vec.at(i);
  }
  if(d >= H) cout << "Yes" ;
  else cout << "No" ;
}


Measured memory_bytes: 640
//ProblemB

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//for
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forbe(i, begin, end) for(decltype(begin) i = (begin); i != (end); ++i)
#define forbes(i, begin, end, step) for(decltype(begin) i = (begin); i != (end); i += (step))

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
#define fi first
#define se second

//vector
template <typename Value>
static inline void fillv(Value& x, const Value& val) { x = val; }
template <typename Vector, typename Value>
static inline void fillv(Vector& v, const Value& val) { for (auto& x : v) fillv(x, val); }

static inline void Solve();

int main(int argc, char* argv[]) {
#ifdef REDIRECT_STDIO
	REDIRECT_STDIO;
#endif // REDIRECT_STDIO

	Solve();
	return 0;
}

//ProblemB
void Solve() {
	string s;
	int w;
	cin >> s >> w;
	for (size_t i = 0; i < s.length(); i += w) {
		cout << s[i];
	}
	cout << endl;
}


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

int n; string s;
int b[100000];
bool ok(int i, int j) {
	b[0] = i; b[prv(0)] = j;
	for (int i = 0; nxt(i) != prv(0); i = nxt(i)) {
		if ((b[i] && s[i] == 'o') || (!b[i] && s[i] == 'x'))b[nxt(i)] = b[prv(i)];
		else b[nxt(i)] = !b[prv(i)];
	}
	rep(i, n) {
		if (b[i]) {
			if (!((s[i] == 'o'&&b[prv(i)] == b[nxt(i)]) || (s[i] == 'x'&&b[prv(i)] != b[nxt(i)])))return false;
		}
		else {
			if (!((s[i] == 'o'&&b[prv(i)] != b[nxt(i)]) || (s[i] == 'x'&&b[prv(i)] == b[nxt(i)])))return false;
		}
	}
	return true;
}
signed main() {
	cin >> n >> s;
	rep(i, 2)rep(j, 2) {
		if (!ok(i, j))continue;
		rep(k, n) {
			if (b[k])printf("S");
			else printf("W");
		}
		printf("\n");
		return 0;
	}
	puts("-1");
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define r_rep(i,n) for(int i=n-1;i>=0;i--)
#define ll long long

int main(){
    int h,w;
    string s[2010];
    cin>>h>>w;
    rep(i,h) cin>>s[i];
    int a[2010][2010],b[2010][2010];

    rep(i,h){
        int x=1;
        rep(j,w){
            if(s[i][j]=='#'){
                a[i][j]=0;
                x=1;
            }
            else{
                a[i][j]=x;
                x++;
            }
        }
    }
    rep(i,h){
        int x=0,y;
        r_rep(j,w){
            if(x>0){
                a[i][j]=y;
                x--;
            }
            else{
                x=y=a[i][j];
                x--;
            }
        }
    }

    rep(i,w){
        int x=1;
        rep(j,h){
            if(s[j][i]=='#'){
                b[j][i]=0;
                x=1;
            }
            else{
                b[j][i]=x;
                x++;
            }
        }
    }
    rep(i,w){
        int x=0,y;
        r_rep(j,h){
            if(x>0){
                b[j][i]=y;
                x--;
            }
            else{
                x=y=b[j][i];
                x--;
            }
        }
    }
    int m=0;
    rep(i,h){
        rep(j,w){
            a[i][j]+=b[i][j];
            m=max(m,a[i][j]);
        }
    }

    cout<<m-1<<endl;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  // 全部偶数の状態で相手に渡し続ければ勝てる
  // 初手が全部偶数なら後攻が勝ち
  // そうでなければ先手が勝ち

  int N; cin >> N;
  bool flg = true;
  for(int i = 0; i < N; i++){
    ll tmp; cin >> tmp;

    if(tmp % 2 != 0){
      flg = false;
      break;
    }
  }
  cout << (flg ? "second" : "first") << endl;
}


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

long double a, b, c, d, e, f, A, B, C, P, S, r, m, ans;

int main(){
	cin >> a >> b>> c >> d >> e >> f;
	A = sqrt((a - c) * (a - c) + (b - d) * (b - d));
	B = sqrt((c - e) * (c - e) + (d - f) * (d - f));
	C = sqrt((a - e) * (a - e) + (b - f) * (b - f));	
	P = (A + B + C) / 2, S = sqrt(P * (P - A) * (P - B) * (P - C));
	r = S / P, m = max(A, max(B, C));
	ans = m * r / (2 * r + m), printf("%.12lf", (double)ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n , nn , ans , a[200005] , b[200005] , maxn ;
bool fmid(int mid){
	for(int i = 1 ; i <= nn ; i++){
		if(a[i] < mid)
			b[i] = 0;
		else
			b[i] = 1;
	}
	int ans1 = 1e8 + 7;
	int ans2 = 1e8 + 7;
	for(int i = 1 ; i <= nn ; i++){
		if(b[i] == b[i + 1]){
			if(b[i]){
				ans1 = min(ans1 , min ( abs ( n - i ) , abs ( n - ( i + 1 ) ) ));
			} else{
				ans2 = min(ans2 , min ( abs ( n - i ) , abs ( n - ( i + 1 ) ) ));
			}
		}
	}
	if(ans1 == 1e8 + 7 && ans2 == 1e8 +7)
		return (n&1)==b[n];
	return ans1<ans2;
}

int main() {
	cin >> n ;
	nn = n * 2 - 1;
	for(int i = 1 ; i <= nn ; i ++){
		cin >> a[i];
	}
	int l = -1 , r = 1e8;
	while(r-l>1){
		int mid=(l+r)>>1;	
		if(fmid(mid)) l=mid;
		else r=mid;
	}	
	cout << l ;
}

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

typedef long long ll;

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

    vector<long long> shrine, temple, location(q);

    shrine.push_back(-1e12);
    temple.push_back(-1e12);

    ll in;
    for (int i = 0; i < a; i++) cin >> in, shrine.push_back(in);
    for (int i = 0; i < b; i++) cin >> in, temple.push_back(in);
    for (int i = 0; i < q; i++) cin >> location[i];

    shrine.push_back(1e12);
    temple.push_back(1e12);

    for (int i = 0; i < q; i++) {
        auto Itr1 = upper_bound(shrine.begin(), shrine.end(), location[i]) - 1;
        auto Itr2 = upper_bound(shrine.begin(), shrine.end(), location[i]);
        auto Itr3 = upper_bound(temple.begin(), temple.end(), location[i]) - 1;
        auto Itr4 = upper_bound(temple.begin(), temple.end(), location[i]);

        long long A[2] = {*Itr1, *Itr2}, B[2] = {*Itr3, *Itr4};
        long long ans = 1e18;
        for (int k = 0; k < 2; k++) {
            for (int j = 0; j < 2; j++) {
                ans = min(min(abs(A[k] - location[i]), abs(B[j] - location[i])) + abs(A[k] - B[j]), ans);
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3828
mod=10**9+7
# N=int(input())
# S=input()
# A,B,C,D=map(int,input().split())
from collections import defaultdict
Hash=defaultdict(lambda:0)
N=int(input())
for i in range(N):
    Hash[input()]+=1
print(len(Hash.keys()))
# print(N)

Measured memory_bytes: 132544
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def integer_factorization(n):
    prime_count = collections.Counter()
    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n //= i
            prime_count[i] += 1
    if n > 1:
        prime_count[n] += 1
    return prime_count

def main():
    n = I()
    d = integer_factorization(n)
    cnt = 0
    for key, val in d.items():
        cur = 1
        used = set()
        while val > 0:
            if cur > val:
                break
            val -= cur
            cnt += 1
            used.add(cur)
            cur += 1
    print(cnt)
main()



Measured memory_bytes: 10948
import math
ans = 0
N,D = map(int, input().split())
a = [list(map(int, input().split())) for i in range(N)]
for j in range(N):
  x = a[j][0] * a[j][0]
  y = a[j][1] * a[j][1]
  if math.sqrt(x + y) <= D:
    ans += 1

print(ans)

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

int n,a[100010];

int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    vector<int> b;
    b.push_back(a[0]);
    for(int i=1;i<n;i++){
        if(a[i]<=*b.begin()){
            b.insert(b.begin(),a[i]);
        }
        else{
            *(lower_bound(b.begin(),b.end(),a[i])-1)=a[i];
        }
    }
    cout<<b.size()<<endl;
}

Measured memory_bytes: 1276
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> b = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            b.add(sc.nextInt());
        }

        int[] ans = new int[n];
        int k = 0;
        for (int i = 0; i < n; i++) {
            boolean ok = false;
            for (int j = b.size(); j > 0; j--) {
                if (b.get(j - 1).equals(j)) {
                    b.remove(j - 1);
                    ans[k++] = j;
                    ok = true;
                    break;
                }
            }
            if (!ok) {
                System.out.println(-1);
                return;
            }
        }
        for (int i = n - 1; i >= 0; i--) {
            System.out.println(ans[i]);
        }
    }
}


Measured memory_bytes: 25044
#include <iostream>

using namespace std;

int main()
{
     int N,j=0,i,B[100],flag=1,M;
     cin>>N;
     int A[N];
     for(i=0;i<N;i++)
     {

        cin>>A[i];
        if(A[i]%2==0)
        {
            B[j]=A[i];
            j++;
        }
     }
     M=j;
     for(j=0;j<M;j++)
     {
if(B[j]%3!=0&&B[j]%5!=0)
{
  flag=0;
  cout<<"DENIED";
  break;
}
     }
     if(flag)
     {
         cout<<"APPROVED";
     }

    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 ll;

int main(){
    long X;
    cin >> X;

    long A, B;
    A = 120;
    for(A = 120; A >= 0; A--){
        for(B = A-1; B > -120; B--){
            if(pow(A, 5) - pow(B, 5) > X){
                break;
            }
            if(pow(A, 5) - pow(B, 5) == X){
                cout << A << " " << B << endl;
                return 0;
            }

        }
    }

    // for(int i = 180; i >= 100; i--){
    //     ans = pow(i, 5) - pow(i-1, 5);
    //     printf("i = %d, %ld\n", i, ans);
    //     if (ans < 1000000000) break;
    // }

    // A = pow(X, 0.25);

    // cout << pow(177, 5) - pow(176, 5) << endl;


    return 0;
}

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


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

	sort(A.begin(), A.end());
	cout << abs(A.at(0) - A.at(A.size()-1)) << endl;

}


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

const int N = 500 + 5;

int main()
{
	int x, y;
	cin >> x >> y;
	if (x == y)
	{
		cout << 0 << endl;
	}
	else if (x < y)
	{
		if (x >= 0) cout << (y - x) << endl;
		else
		{
			if (y <= 0) cout << (y - x) << endl;
			else if (abs(x) == abs(y)) cout << 1 << endl;
			else if (abs(x) < abs(y)) cout << 1 + y + x << endl;
			else cout << abs(x) - abs(y) + 1 << endl;
		}
	}
	else
	{
		if (y >= 0) cout << 1 + min(y + x, abs(x) - abs(y) + 1);
		else if (x <= 0) cout << min(abs(x) + abs(y) + 1, 1 + abs(y) - abs(x) + 1) << endl;
		else if (abs(x) == abs(y)) cout << 1 << endl;
		else if (abs(x) < abs(y)) cout << abs(y) - abs(x) + 1 << endl;
		else cout << 1 + abs(x) - abs(y) << endl;
	}
	return 0;
}

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

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

const int MAX = 10010;      // 素数判定する最大の数
bool IsPrime[MAX];
vector<int> Era(int n = MAX) {
    vector<int> res;
    IsPrime[0] = false; IsPrime[1] = false;
    for (int i = 2; i < n; ++i) IsPrime[i] = true;
    for (int i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            res.push_back(i);
            for (int j = i*2; j < n; j += i) IsPrime[j] = false;
        }
    }
    return res;
}

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}

int main() {
    int N; cin >> N;
    vector<vector<long long> > res(N, vector<long long>(N, 0));
    vector<int> primes = Era();
    for (int wa = 0; wa <= N*2; wa += 2) {
        for (int sa = -N/2*2; sa <= N/2*2; sa += 2) {
            if ((wa + sa) & 1) continue;
            int i = (wa + sa) / 2;
            int j = (wa - sa) / 2;
            if (i < 0 || i >= N || j < 0 || j >= N) continue;
            if ((i + j) & 1) continue;
            res[i][j] = primes[wa/2] * primes[(sa + N/2*2)/2 + N];
        }
    }
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if ((i + j) % 2 == 0) continue;
            long long L = 1;
            for (int k = 0; k < 4; ++k) {
                int ni = i + dx[k], nj = j + dy[k];
                if (ni < 0 || ni >= N || nj < 0 || nj >= N) continue;
                L = LCM(L, res[ni][nj]);
            }
            res[i][j] = L + 1;
        }
    }
    if (N == 2) res[0][1] = res[1][0]*2-1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }
}

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

vector<vector<int>> graph(222222);
vector<long long> X(222222,0);
int N,Q;
vector<bool> visit(222222,false);

void BFS(){
	queue<int> que;
	que.push(0);
	visit[0]=true;
	while(!que.empty()){
		int f=que.front();
		que.pop();
		for(int t:graph[f]){
			if(visit[t])continue;
			X[t]+=X[f];
			que.push(t);
			visit[t]=true;
		}
	}
}

int main(){
	cin >> N >> Q;
	for(int i=0;i<N-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	for(int i=0;i<Q;i++){
		int p,x;
		scanf("%d%d",&p,&x);
		p--;
		X[p]+=x;
	}
	
	BFS();
	
	for(int i=0;i<N;i++){
		if(i==N-1)printf("%d\n",X[i]);
		else printf("%d ",X[i]);
	}
	
	return 0;
}

Measured memory_bytes: 17012
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
  int n, l, cnt;
  cin >> n;
  vector<int> a;
  for(int i=0;i<n;i++){
    cin >> l;
    a.push_back(l);
  }
  cnt = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(abs(a[i]-a[j]) < a[k] && a[k] < a[i]+a[j] && a[i] != a[j] && a[j] != a[k] && a[k] != a[i]){
          cnt++;
        }
      }
    }
  }
  cout << cnt;
}

Measured memory_bytes: 3600
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int x[51];
ll dp[51][5001];
int main() {
  int n, a;
  cin >> n >> a;
  int mx = a, tmp;
  reps(i, n){
	cin >>tmp;
	x[i]=tmp -a;
	mx = max(mx, tmp);
  }
  rep(j, n+1)
  rep(t, (2*n*mx+1)){
	  if(j == 0 && t == n*mx)
		  dp[j][t] = 1LL;
	  else if(j > 0 && ((0 > t - x[j]) || (t - x[j] > 2*n*mx)))
		  dp[j][t] = dp[j-1][t];
	  else if(j > 0 && (0 <= t - x[j]) && (t - x[j] <= 2*n*mx))
		  dp[j][t] = dp[j-1][t]+dp[j-1][t-x[j]];
	  else 
		  dp[j][t] = 0LL;
  }
  cout << dp[n][n*mx] - 1 << endl;
  return 0;
}


Measured memory_bytes: 2176
from functools import reduce

N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

def findGCM(a,b):
    while 1:
        if a%b == 0:
            return b
        else:
            a = a%b
        
        if b%a == 0:
            return a
        else:
            b = b%a


def findLCM(a,b):
    gcm = findGCM(a,b)
    return a*b//gcm

ans = reduce(findLCM,T)
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////


int main(){
    ll s;cin>>s;
    ll x1=(ll)1E9;
    
    ll a=s/x1;
    ll b=s%x1;
    if(b!=0){
        b=x1-b;
        a=a+1;
    }
    ll x2=1;
    ll y2=a;
    ll y1=b;
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<0<<" "<<0<<endl;
    
    return 0;
}

















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

constexpr int nax = 2e3, maxm = 2e3;
using Grid = array< array< int, maxm + 1 >, nax + 1 >;

int n, m, q;
Grid pio, poz, gr;

int sum(const Grid& gr, int x1, int x2, int y1, int y2)
{
    return gr[x2][y2] - gr[x1 - 1][y2] - gr[x2][y1 - 1] + gr[x1 - 1][y1 - 1];
}

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

    cin >> n >> m >> q;

    for (int i = 1; i <= n; ++i)
    {
        string s; cin >> s;
        for (int j = 1; j <= m; ++j)
            gr[i][j] = (s[j - 1] == '1');
    }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            poz[i][j] = (gr[i][j] and gr[i][j - 1]);
            pio[i][j] = (gr[i][j] and gr[i - 1][j]);
        }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            poz[i][j] += poz[i - 1][j] + poz[i][j - 1] - poz[i - 1][j - 1];
            pio[i][j] += pio[i - 1][j] + pio[i][j - 1] - pio[i - 1][j - 1];
            gr[i][j] += gr[i - 1][j] + gr[i][j - 1] - gr[i - 1][j - 1];
        }

    for (int i = 0; i < q; ++i)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << sum(gr, x1, x2, y1, y2) - sum(pio, x1 + 1, x2, y1, y2) - sum(poz, x1, x2, y1 + 1, y2) << '\n';
    }
}

Measured memory_bytes: 48768
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] array = new int[3];
    for(int i = 0; i < 3; i++){
      array[i] = -1;
    }
    for(int i = 0; i < m; i++){
      int s = sc.nextInt()-1;
      int c = sc.nextInt();
      if(n!=1&&s==0&&c==0){
        System.out.println(-1);
        return;
      }
      if(array[s] != -1&&array[s] != c){
        System.out.println(-1);
        return;
      }
      if(array[s] == -1){
        array[s] = c;
      }
    }
    for(int i = 0; i < 3; i++){
      if(n != 1&& i == 0 && array[i] == -1){
        array[i] = 1;
      }
      if(array[i] == -1){
        array[i] = 0;
      }
    }
      int num = 0;
      for(int i = 0; i < n; i++){
        if(i != 0){
          num = num*10;
        }
        num = num + array[i];
      }
      System.out.println(num);
    }
  }

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

int main(){
  int k,x;
  cin >> k >> x;
  
  int left = max(-1000000,x+1-k);
  int right = min(1000000,x-1+k);
  for(int i=left;i<=right;i++){
    cout << i << " ";
  }
  cout << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int f[200010];
	cin>>n;
	for(int i=1;i<=n;i++)
	scanf("%d",&f[i]);
	int ans[200010];
	memset(ans,0,sizeof(ans));
	for(int i=n;i>=1;i--)
	{
		int num=0;
		for(int j=1;j*i<=n;j++) num+=ans[j*i];
		num%=2;
		if(num!=f[i]) ans[i]=1;
	}
	int num=0;
	for(int i=1;i<=n;i++) num+=ans[i];
	cout<<num<<endl;
	for(int i=1;i<=n;i++)
	if(ans[i]) printf("%d ",i);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
/*    .___.
     /     \
    | O _ O |
    /  \_/  \
  .' /     \ `.
 / _|       |_ \
(_/ |       | \_)
    \       /
   __\_>-<_/__
   ~;/     \;~     */

#define ll long long
#define s(x) scanf("%lld",&x)
#define s1(x,y) scanf("%lld %lld",&x,&y)
int dx[]= {-1,-1,1,1,0,0,-1,1};
int dy[]= {1,-1,-1,1,-1,1,0,0};
int fx[]= {1,-1,0,0};
int fy[]= {0,0,1,-1};
ll mod = 1000000000+7;
int main()
{
    //freopen("output.txt","w",stdout);
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


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

using namespace std;

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

int main() {
    int a, b, x; cin >> a >> b >> x;
    if(x<=a+b && x>=a) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N;

void put(string s, char used) {
    if (s.length() == N)
    {
        cout << s << endl;
        return;
    }

    for (char c = 'a'; c <= used; c++) {
        if (c == used) {
            put(s + c, (char)(used + 1));
        }
        else {
            put(s + c, used);
        }
    }
}

int main(void)
{
    cin >> N;
    put("", 'a');
    return 0;
}

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


//グローバルに書いておくと、関数の有効範囲がプログラムの全範囲になる。
vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p = -1){
	for(int u : to[v]){
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u,v);
	}
}

int main(){
	int N,Q;
	cin >> N >> Q;
	
	rep(i,N-1){
		int a,b;
		cin >> a >> b;
		--a,--b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	
	ans.resize(N);
	
	rep(i,Q){
		int p,x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	
	dfs(0);
	
	rep(i,N){
		cout << ans[i] << endl;
	}
}



Measured memory_bytes: 23552
#include <stdio.h>
int main(){
			int a,b;
			scanf("%d %d",&a,&b);
			
			if (a<b)	printf("a < b\n");
			else if (a>b)	printf("a > b\n");
			else if (a==b)	printf("a == b\n");
			
			return 0;
			}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define FOR(x,n) for(int x = 0; x < n; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
const int MXN = 1e5 + 1;
int N;
ll A[3*MXN], m1[3*MXN] = {}, m2[3*MXN] = {};
int main() { FIN;
  cin >> N;
  FOR(x,3*N) cin >> A[x];

  priority_queue< int, vector<int>, greater<int> > mns;
  priority_queue<int> mxs;

  ll totalMX = 0;
  FOR(x,N) totalMX += A[x], mns.push(A[x]);
  m1[N-1] = totalMX;
  for(int x = N; x < 3*N; x++){
    totalMX += A[x]; mns.push(A[x]);
    totalMX -= mns.top(); mns.pop();
    m1[x] = totalMX;
  }

  ll totalMN = 0, i = 3*N-1;
  FOR(x,N) totalMN += A[3*N-1-x], mxs.push(A[3*N-1-x]), i = 3*N-1-x;
  m2[i] = totalMN;
  for(int x = i-1; x >= 0; x--){
    totalMN += A[x]; mxs.push(A[x]);
    totalMN -= mxs.top(); mxs.pop();
    m2[x] = totalMN;
  }

  ll ans = -(1LL<<62);
  for(int x = N-1; x < i; x++)
    ans = max(ans, m1[x] - m2[x+1]);

  cout << ans << "\n";
}

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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define INF 10 ** 18

using namespace std;

int main() {

	SINT32 N = 0;
	SINT32 M = 0;
	SINT32 Q = 0;
	SINT64 ANS = 10000000001;

	cin >> N >> M >> Q;

	vector<SINT64> ADATA(N+2);
	vector<SINT64> BDATA(M+2);
	vector<SINT64> QDATA(Q);
	ADATA[0] = -100000000000;
	ADATA[N+1] = 100000000000;
	BDATA[0] = -100000000000;
	BDATA[M+1] = 100000000000;
	
	for (SINT32 i = 0; i < N; i++) {
		cin >> ADATA[i+1];
	}
	for (SINT32 i = 0; i < M; i++) {
		cin >> BDATA[i+1];
	}
	for (SINT32 i = 0; i < Q; i++) {
		cin >> QDATA[i];
	}
	sort(ADATA.begin(),ADATA.end());
	sort(BDATA.begin(),BDATA.end());
//	sort(QDATA.begin(),QDATA.end());

	for (SINT32 i = 0; i < Q; i++) {
		SINT32 APOSI;
		SINT32 BPOSI;
		ANS = 100000000001;
		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


		ANS = MIN(ANS,ABS(MAX(ADATA[APOSI],BDATA[BPOSI])-QDATA[i]));
		ANS = MIN(ANS,ABS(QDATA[i] - MIN(ADATA[APOSI-1],BDATA[BPOSI-1])));

		ANS = MIN(ANS,(ADATA[APOSI]-QDATA[i])+(ADATA[APOSI]-BDATA[BPOSI-1]));
		ANS = MIN(ANS,(BDATA[BPOSI]-QDATA[i])+(BDATA[BPOSI]-ADATA[APOSI-1]));

		ANS = MIN(ANS,(QDATA[i]-ADATA[APOSI-1])+(BDATA[BPOSI]-ADATA[APOSI-1]));
		ANS = MIN(ANS,(QDATA[i]-BDATA[BPOSI-1])+(ADATA[APOSI]-BDATA[BPOSI-1]));

		cout <<ANS <<endl;
	}


	
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
*/

Measured memory_bytes: 3712
#include <iostream>
#include <cstring>
#include <string>
using namespace std;

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

typedef pair<int,int> P;

int h, w, s;
int area[34][34];
int sum;
pair<int, int> memo[34][34][34][34];
int rec[34][34][34][34];


void mkRec(){
	int i, j;
	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			rec[i][j][i][j] = area[i][j];
			
			for(int y = i - 1; y >= 0; y--)
				rec[y][j][i][j] = rec[y + 1][j][i][j] + area[y][j];
			
			for(int y = i; y >= 0; y--){
				int s = 0;
				for(int x = j; x >= 0; x--){
					s += rec[y][x][i][x];
					rec[y][x][i][j] = s;
				}
			}
		}
	}
}


P split(int ax, int ay, int bx, int by){
	P max_group, group, g1, g2;
	int sum_e = 0;
	int i, j;
	
	if(memo[ay][ax][by][bx].first != 0) return memo[ay][ax][by][bx];

	max_group = P(1, max_group.second = s - (sum - rec[ay][ax][by][bx]));

	for(i = ay; i < by; i++){
		if(sum - rec[ay][ax][i][bx]	> s || 
		   sum - rec[i+1][ax][by][bx] > s) continue;
		g1 = split(ax, ay, bx, i);
		g2 = split(ax, i+1, bx, by);
		group = pair<int, int>(g1.first + g2.first, min(g1.second, g2.second));
		max_group = max(max_group, group);
	}
	for(j = ax; j < bx; j++){
		if(sum - rec[ay][ax][by][j] > s || 
		   sum - rec[ay][j+1][by][bx] > s) continue;
		g1 = split(ax, ay, j, by);
		g2 = split(j + 1, ay, bx, by);
		group = pair<int, int>(g1.first + g2.first, min(g1.second, g2.second));
		max_group = max(max_group, group);
	}
	return memo[ay][ax][by][bx] = max_group;
}


int main(void){
	int i,j;
	pair<int, int> ans;
	while(cin >> h >> w >> s , h){
		memset(memo, 0, sizeof(memo));
		sum = 0;
		for(i = 0; i < h; i++){
			for(j = 0; j < w; j++){
				cin >> area[i][j];
				sum += area[i][j];
			}
		}
		mkRec();
		ans = split(0, 0, w - 1, h - 1);
		cout << ans.first << " " << ans.second << endl;
		
	}
}

Measured memory_bytes: 16764
def resolve():
    import numpy as np
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = np.cumprod(np.array(A))

    for i in range(n - k):
        if A[i] < A[k + i]:
            print("Yes")
        else:
            print("No")

resolve()

Measured memory_bytes: 50064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    vector<int> cumsum_E(N + 1, 0), cumsum_W(N + 1, 0);
    for (int i = 0; i < N; i++) {
        cumsum_E.at(i + 1) = cumsum_E.at(i) + (S.at(i) == 'E');
        cumsum_W.at(i + 1) = cumsum_W.at(i) + (S.at(i) == 'W');
    }
    
    int ans = N;
    
    for (int i = 0; i < N; i++) {
        ans = min(ans, cumsum_W.at(i) + cumsum_E.at(N) - cumsum_E.at(i + 1));
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2964
package main

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

var sc *bufio.Scanner

type uf struct {
	size  int
	pare  int
	child []int
}

var p []uf

func main() {
	sc = bufio.NewScanner(os.Stdin)
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	inits(n)
	for i := 0; i < m; i++ {
		tmp := IntBufScan()
		add(tmp[0], tmp[1])
	}
	ans := 0
	for _, i := range p {
		if i.size > ans {
			ans = i.size
		}
	}
	fmt.Println(ans)
}
func inits(n int) {
	p = append(p, uf{size: 1})
	for i := 0; i < n; i++ {
		p = append(p, uf{size: 1})
	}
}
func add(ain, bin int) {
	a := root(ain)
	b := root(bin)
	if a == b {
		return
	}
	p[a].size += p[b].size
	p[a].child = append(p[a].child, b)
	p[b].pare = a
}
func root(a int) int {
	pare := p[a].pare
	if pare == 0 {
		return a
	} else {
		tmp := root(pare)
		p[a].pare = tmp
		return tmp
	}
}
func BufScan() string {
	sc.Scan()
	return sc.Text()
}

func IntBufScan() []int {
	var inInts []int
	inString := BufScan()
	in := strings.Split(inString, " ")
	tmp1, _ := strconv.Atoi(in[0])
	tmp2, _ := strconv.Atoi(in[1])
	inInts = []int{tmp1, tmp2}
	return inInts
}


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

int n, h[100019], dp[100019];
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> h[i], dp[i] = 1000000000;
	dp[1] = 0;
	for (int i = 1; i <= n; i++)
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1])), dp[i + 2] =
				min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	cout << dp[n];
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int heap[2000000] = {0};
int size = 0;

int parent(int i) {
  if(i % 2 == 1){
    return (i - 1) / 2;
  } else {
    return (i - 2) / 2;
  }
}

int left_child(int i){
  return (i * 2) + 1;
}

int right_child(int i){
  return (i * 2) + 2;
}

void push(int x){
  int i = size++;

  while(i > 0){
    int p = parent(i);
    if(heap[p] >= x) break;
    else {
      heap[i] = heap[p];
      i = p;
    }
  }

  heap[i] = x;
}

int pop(){
  int ret = heap[0];
  int x = heap[--size];

  int i = 0;
  while(left_child(i) < size){
    int l = left_child(i), r = right_child(i);
    if(r < size && heap[r] > heap[l]) l = r;
    if(heap[l] <= x) break;
    heap[i] = heap[l];
    i = l;
  }

  heap[i] = x;
  return ret;
}
int main(){
  int k;
  string meirei;

  while(1){
    cin >> meirei;
    if(meirei == "insert"){
      cin >> k;
      push(k);
    } else if (meirei == "extract"){
      cout << pop() << endl;
    } else {
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 6988
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		ArrayList<Integer> x=new ArrayList<>();
		int m = sc.nextInt();
		String s = m+"";
		int n=sc.nextInt();
		
		for(int i=0;i<n;i++)
			x.add(sc.nextInt());
		
		for(int i=m;i<=100000;i++){
			
			String ss=i+"";
			boolean b=true;
			
			for(int j=0;j<ss.length();j++){
				if(x.contains(ss.charAt(j)-'0')){
					b=false;
					break;
				}
			}
			
			if(b){
				System.out.print(i);
				break;
			}
		}
	}
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

int n, m, q, ans = 0;
vector<int> a, b, c, d, sum;
int bfs() {
  int cnt = 0;
  rep(i, 0, q) if (sum[b[i]] - sum[a[i]] == c[i]) cnt += d[i];
  return cnt;
}
void dfs(int x, int y) {
  if (x == n + 1) {
    chmax(ans, bfs());
    return;
  } else {
    rep(i, y, m + 1) {
      sum[x] = i;
      dfs(x + 1, i);
    }
  }
}

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  cin >> n >> m >> q;
  a.resize(55);
  b.resize(55);
  c.resize(55);
  d.resize(55);
  sum.resize(55);
  rep(i, 0, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(1, 1);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

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

    vector<vector<ll>> d(N, vector<ll>(N, INF));
    ll A[N][N];

    rep(i, N) {
        rep(j, N) {
            cin >> A[i][j];
            d[i][j] = A[i][j];
        }
    }

    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                if ((i == j) || (j == k) || (i == k)) continue; 
                if (d[i][j] == (d[i][k] + d[k][j])) {
                    A[i][j] = 0;
                }
                else if (d[i][j] > (d[i][k] + d[k][j])) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    ll sum = 0;
    rep(i, N) {
        repd(j, i, N) {
            // cout << i << ":" << j << " " << A[i][j] << " ";
            sum += A[i][j];
        }
        // cout << endl;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1664
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    vector<int> a(3, 0);
    for (int i = 0; i < 3; i++)
        cin >> a[i];

    int sum = accumulate(all(a), 0);
    if (sum >= 22) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}


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

int
main(int argc, char **argv)
{
	int i, j, n, q, a, c = 0;
	int *s;

	scanf("%d", &n);
	if (n <= 0)
		return 1;

	s = (int *)malloc(sizeof(int) * n);
	if (s == NULL)
		return 1;

	for (i = 0; i < n; i++)
		scanf("%d", s + i);

	scanf("%d", &q);
	if (q <= 0)
		return 1;

	for (i = 0; i < q; i++) {
		scanf("%d", &a);
		for (j = 0; j < n; j++)
			if (a == s[j]) {
				c++;
				break;
			}
	}

	printf("%d\n", c);

	return 0;
}



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

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

    ll n,k;
    cin >> n >> k;
    vector<pair<ll,ll>> p(n);
    for (ll i = 0;i < n;i++){
        cin >> p[i].first >> p[i].second;
    }

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

    ll now = 0;
    ll ans = 0;

    for (ll i = 0; i < n; i++){
        now += p[i].second;
        if (now >= k){
            ans = p[i].first;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int H,W;
        cin>>H>>W;
        if(H==0&&W==0){
            return 0;
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cout<<'#';
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


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


int main(){
    int N, nums[1005] = {};
    cin>>N;
    
    bool f = false;
    for(int i=0; i<N; i++){
        cin>>nums[i];
        if(nums[i] == 0) f = true; 
    }
    
    if(!f){
        cout<<0<<endl;
        return 0;
    }
    
    //cout<<"test"<<endl;
    
    int keta = 1;

    while(1){
        for(int i = pow(10,keta-1); i < pow(10,keta); i++){
            bool flag = false;
            for(int j = 0; j <= N-keta; j++){
                int tmp = 0;
                int digit = pow(10, keta-1);
                for(int k = 0; k < keta; k++){
                    tmp += nums[j + k] * digit;
                    digit /= 10;
                }
                //cout<<"i; "<<i<<", tmp: "<<tmp<<" keta: "<<keta<<endl;
                if(tmp == i){
                    flag = true;
                    break;
                }
            }
            if(!flag){
                cout<<i<<endl;
                return 0;
            }
            if(i == pow(10,keta)-1) keta++;
        }
   }
        
    return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j<= 9; ++j) {
      if (i * j == N) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int main() {
  string s;
  int ans=0,cnt=0;

  cin >> s;

  for(int i=0;i<s.length();i++) {
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T') {
      cnt++;
      if(ans<cnt) {ans=cnt;}
    }
    else {cnt=0;}
  }


  cout << ans << endl;

  return 0;
}


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

int main() 
{
    int n;
    cin >> n;
    map<string, int> mp;
    for (int i=0; i<n; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    int m;
    cin >> m;
    for (int i=0; i<m; i++)
    {
        string s;
        cin >> s;
        mp[s]--;
    }
    int maxx = -INT_MAX;
    for (auto x:mp)
        maxx = max(maxx,x.second);
    cout << (maxx<0?0:maxx);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

ll com(int r, int c) {
	if(c == 0) return 1ll;
	if(r < c) return 0ll;
	ll ret = 1ll;
	for(int i = 1; i <= c; i++) {
		ret *= r - i + 1;
	}
	for(int i = 1; i <= c; i++) {
		ret /= i;
	}
	return ret;
}

int main() {
	string n;
	cin >> n;
	int k;
	cin >> k;
	int count = 0;
	rep(i, n.size()) if(n[i] != '0') count++;
	if(n.size() < 4) {
		int n2 = stoi(n);
		if(n2 <= 110 && k == 3) {
			cout << 0 << endl;
			return 0;
		}
		else if(n2 <= 10 && k >= 2) {
			cout << 0 << endl;
			return 0;
		}
	}
	int remain_n = n.size();
	int remain_k = k;
	ll ans = 0;
	rep(i, n.size()) {
		if(n[i] != '0') {
			ans += (n[i] - '1') * com(remain_n - 1, remain_k - 1) * pow(9, remain_k - 1);
			ans += com(remain_n - 1, remain_k) * pow(9, remain_k);
			remain_k--;
		}
		if(remain_k == 0) break;
		remain_n--;
	}
	if(count >= k) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256