akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n,m,c,ans;
int b[30];
int a[30][30];
signed main(){
	cin>>n>>m>>c;
	for(int i=1;i<=m;i++)cin>>b[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++){
		int tot=c;
		for(int j=1;j<=m;j++)tot+=a[i][j]*b[j];
		if(tot>0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m;
vector<int>v[N];
int main()
{
    scanf("%d%d",&n,&m);
    int k;scanf("%d",&k);
    while(k--)
    {
        int x,y;scanf("%d%d",&x,&y);
        v[y].push_back(x);
    }
    v[1].push_back(n+1);
    for(int i=1;i<=m;i++) sort(v[i].begin(),v[i].end());
    int l=0,r=n+1;
    for(int i=1;i<=m;i++)
    {
        l++;
        for(int j=0;j<v[i].size();j++)
        {
            if(v[i][j]==l) l++;
            else if(v[i][j]>l)
            {
                r=min(r,v[i][j]);
                break;
            }
        }
    }
    printf("%d\n",r-1);
}


Measured memory_bytes: 8704
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}

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

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long 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()
{
    int M, N, K, L;
    int X, Y,Z;
    //int A[200000];

    lli count = 0;
    lli temp, temp2;
    lli max = -LLINF,min = LLINF;
 

    scanf("%d%d%d", &X,&Y,&Z);

    swap(&X, &Y);
    swap(&X, &Z);

    printf("%d %d %d", X, Y, Z);
   

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int a,b;
  
  cin >> a >> b;
  
  if(a<=b){
    for(int i=0;i<b;i++){
    cout << a;
    }
    cout << endl;
  }
  else{
    for(int i=0;i<a;i++){
    cout << b;
    }
    cout << endl;
  }

}

Measured memory_bytes: 256
/**
 * Created by hiroqn on 13/10/08.
 */
var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
function main(){
  var str = input[0];
  if(str.length < 6){
    console.log('INVALID');
    return;
  }
  if(str.match(/[a-z]/) === null){
    console.log('INVALID');
    return;
  }
  if(str.match(/[0-9]/) === null){
    console.log('INVALID');
    return;
  }
  if(str.match(/[A-Z]/) === null){
    console.log('INVALID');
    return;
  }
  console.log('VALID');

}

Measured memory_bytes: 7652
#include<iostream>

using namespace std;

int R;

int main(){
	cin >> R;

	if(R < 1200){
		cout << "ABC" << endl;
	}else if(R < 2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
//A Way to Invite Friends
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct Friend{
	int NMin, NMax;//人数最小最大
	bool operator<(const Friend& var) const{ return NMin < var.NMin; };
};

int main(){
	int FriendNum;//友人の数
	vector<Friend> Fri;//友人リスト
	int InviteFNum = 0;//招ける友人人数
	//代入
	cin >> FriendNum;
	Fri.reserve(FriendNum);
	{
		Friend temp;
		for (int i = 0; i < FriendNum; ++i){
			cin >> temp.NMin >> temp.NMax;
			//条件に一致し得ない友人を除外
			if (temp.NMin <= FriendNum + 1){
				Fri.push_back(temp);
			}
		}
	}

	//条件一致人数確認
	int CurFri = 0;
	for (int i = Fri.size(); i > 0; --i){
		//NMin <= i+1 <= NMaxである人数のカウント
		for (vector<Friend>::iterator it = Fri.begin(); it != Fri.end(); ++it){
			if (it->NMin <= (i + 1) && (i + 1) <= it->NMax)++CurFri;
		}
		//カウント人数(CurFri)が条件人数(i)以上ならok.->出力
		if (CurFri >= i){
			CurFri = i;
			break;
		} else{
			CurFri = 0;
		}
	}

	cout << CurFri << endl;
	return 0;
}

Measured memory_bytes: 1796
#include<iostream>                                              
#include<cmath>                                                 
using namespace std;                                            
                                                                
int main(void) {                                                
  int a, b;                                                     
  while (cin >> a >> b) {                                       
    int ans = log10(a+b)+1;                                     
    cout << ans << endl;                                        
  }                                                             
  return 0;                                                     
}                                                               
                     

Measured memory_bytes: 3344
<?php
list($sx, $sy, $tx, $ty) = ints();
echo str_repeat('R', $tx - $sx) .
    str_repeat('U', $ty - $sy) .
    str_repeat('L', $tx - $sx) .
    str_repeat('D', $ty - $sy) .
    'D' . str_repeat('R', $tx - $sx + 1) .
    str_repeat('U', $ty - $sy + 1) . 'L' .
    'U' . str_repeat('L', $tx - $sx + 1) .
    str_repeat('D', $ty - $sy + 1) . 'R';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4604
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
cnt = 0
s = x
for i in range(N):
    if i == N - 1:
        if s == a[i]:
            cnt += 1
        break
    s -= a[i]
    if s < 0:
        break
    elif s == 0:
        cnt += 1
        break
    else:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
S = input()

ans = 7

if S == "MON":
    ans = 6
elif S == "TUE":
    ans = 5
elif S == "WED":
    ans = 4
elif S == "THU":
    ans = 3
elif S == "FRI":
    ans = 2
elif S == "SAT":
    ans = 1

print(ans)



Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int main(){
  int N,T; cin >> N >> T; int min_cost = 1e5;
  for(int i = 0; i < N; i++){
    int c,t; cin >> c >> t;
    if( t <= T){ min_cost = min( min_cost, c);}}
  
  if( min_cost == 1e5){ cout << "TLE" << endl;}
  else{ cout << min_cost << endl;}
  
  return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

template<long long mod>
class modint{
private:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
public:
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  modint& operator+=(const modint&b)
  {    return (*this) = (*this) + b;  }
  modint& operator-=(const modint&b)
  {    return (*this) = (*this) - b;  }
  modint& operator*=(const modint&b)
  {    return (*this) = (*this) * b;  }
  modint& operator/=(const modint&b)
  {    return (*this) = (*this) / b;  }
  modint& operator++()
  {    (*this)+=1; return (*this);  }
  modint& operator--()
  {    (*this)-=1; return (*this);  }
  modint operator++(int){
    modint tmp(*this);
    ++(*this);
    return tmp;
  }
  modint operator--(int){
    modint tmp(*this);
    --(*this);
    return tmp;
  }    
  modint pow(unsigned long long i){
    if(i == 0) return 1;
    if(i & 1){
      return (*this) * (this->pow(i-1));
    }
    modint<mod>hpow = (this->pow(i>>1));
    return hpow * hpow;
  }
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
  friend istream& operator>>(istream&is, modint&a){
    long long x; is >> x;
    a = x;
    return is;
  }
};

using mint = modint<1000000007>;

int main(){
  int n,k; cin >> n >> k;
  mint sum(0);
  mint l(0);
  mint r(0);
  for(int i = 0; i <= n; ++i){
    l += i;
    r += n-i;
    if(i+1 >= k) sum += r - l + 1;
  }
  cout << sum << endl;
  return 0;
}




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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;
		if (A >= 13) {
			ans = B;
		} else if (A >= 6 && A <= 12) {
			ans = B / 2;
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

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

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

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

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

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

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

Measured memory_bytes: 21204
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  lll n,d,cnt,x,y;
  cnt = 0;

  cin >> n >> d;
  double dist;
  for(ii=0;ii<n;ii++){
    cin >> x >> y;
    dist = sqrt(x*x + y*y);
    if(dist <= d){
      cnt++;
    }
  }

  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  std::string S;
  std::cin >> S;
  vector<int> l(S.size() + 1), g(S.size() + 1);
  for (int i = 0; i < S.size(); ++i)
  {
    if (S[i] == '<')
      l[i + 1] = l[i] + 1;
    else
      l[i + 1] = 0;
  }
  for (int i = S.size() - 1; i >= 0; --i)
  {
    if (S[i] == '>')
      g[i] = g[i + 1] + 1;
    else
      g[i] = 0;
  }
  ll ans = 0;
  for (int i = 0; i <= S.size(); ++i)
    ans += max(l[i], g[i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4740
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

const int MAX_N = (int)1e5 + 777;

string s, t;
int pref_s[MAX_N], pref_t[MAX_N];

void solve() {
	cin >> s >> t;

	pref_s[0] = (s[0] == 'A' ? 1 : -1);
	pref_t[0] = (t[0] == 'A' ? 1 : -1);

	for(int i = 1; i < len(s); ++i) {
		pref_s[i] = pref_s[i - 1] + (s[i] == 'A' ? 1 : -1);
	}

	for(int i = 1; i < len(t); ++i) {
		pref_t[i] = pref_t[i - 1] + (t[i] == 'A' ? 1 : -1);
	}

	int q;
	cin >> q;

	while(q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		--a, --b, --c, --d;

		int sum = pref_s[b] - pref_t[d];

		if(a > 0)
			sum -= pref_s[a - 1];

		if(c > 0) 
			sum += pref_t[c - 1];

		sum %= 3;

		if(sum < 0)
			sum += 3;

		cout << (sum == 0 ? "YES\n" : "NO\n");
	}
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 1744
N,M = map(int,input().split())
SC = [list(map(int,input().split())) for _ in range(M)]

NUM = [-1 for _ in range(N)]

flag = 0
for i in range(M):
    if NUM[SC[i][0]-1] == -1:
        NUM[SC[i][0]-1] = SC[i][1]
    elif NUM[SC[i][0]-1] != SC[i][1]:
        flag = 1
        break
if NUM[0] == -1:
    if N == 1:
        NUM[0] = 0
    else:
        NUM[0] = 1

ans = 0
for i in range(N):
    if NUM[i] != -1:
        ans += NUM[i]*10**(N-i-1)

if flag == 1 or (NUM[0] == 0 and N != 1):
    print(-1)
else:
    if NUM[0] == -1:
        print(ans+10**(N-1))
    else:
        print(ans)


Measured memory_bytes: 3064
package main

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

func main() {
	sc := NewScanner()

	m := sc.NextInt()
	n := sc.NextInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = sc.NextInt()
	}
	sort.Ints(arr)
	ds := []int{}
	for i := 1; i < n; i++ {
		d := arr[i] - arr[i-1]
		if d < 0 {
			d *= -1
		}
		ds = append(ds, d)
	}
	sort.Ints(ds)
	ans := 0
	for i := 0; i < len(ds)-m+1; i++ {
		ans += ds[i]
	}
	fmt.Printf("%+v\n", ans) // output for debug

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 7168
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    map<int, int> m;
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        if (a[a[i] - 1] == i + 1)
            ret++;
    }
    cout << ret / 2 << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
	int x,y;
	int a,b;
	double c;
	scanf("%d %d", &x, &y);
	a=x/y;
	b=x%y;
	c=(double)x/(double)y;
	printf("%d %d %f\n", a,b,c);
	return 0;
}

Measured memory_bytes: 636
def main():
    N = int(input())
    if(N<4):
        print('No')
        return
    if(N%4==0 or N%7==0):
        print('Yes')
        return
    
    tmp = 0
    while(N>tmp):
        if((N-tmp)%4==0):
            print('Yes')
            return
        tmp = tmp+7
    
    print('No')
    


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
import itertools


def solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    # dict = {}
    # for i in range(Q):
    #     if not c[i] in dict:
    #         dict[c[i]] = 0
    #     dict[c[i]] += d[i]
    # m = 0
    # C = -1
    # for i in dict.items():
    #     m = max(m, i[1])
    # for i in dict.items():
    #     if i[1] == m:
    #         C = i[0]
    # s = 0
    # for i in range(1, M + 1):
    #     for j in range(1, M + 1):
    #         for k in range(Q):
    #             if j - i == C or i - j == C:
    #                 if i == a[k] and j == b[k]:
    #                     s += d[k]
    # print(s)
    ts = itertools.combinations_with_replacement(range(1, M + 1), N)
    m = 0
    for t in ts:
        s = 0
        for i in range(Q):
            if t[b[i] - 1] - t[a[i] - 1] == c[i]:
                s += d[i]
        m = max(m, s)
    print(m)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (Q)  # type: "List[int]"
    b = [int()] * (Q)  # type: "List[int]"
    c = [int()] * (Q)  # type: "List[int]"
    d = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import Data.Bits

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  putStrLn $ if solve'' n as then "Yes" else "No"


solve'' n as = patternA || patternB || patternC
  where
    patternA = length keys == 3
      && keyCond
      && countCond
    patternB = all (0==) as
    patternC = (length keys) == 2
        && min fs sn == 0
        && (mp Map.! (min fs sn)) * 2 == mp Map.! (max fs sn)
    mp = toCountMap as
    keys = Map.keys mp
    (a:b:c:_) = keys
    (fs:sn:_) = keys
    keyCond = xor a b == c && xor b c == a && xor c a == b 
    countCond = mp Map.! a == mp Map.! b && mp Map.! a == mp Map.! c
  

toCountMap :: (Ord k) => [k] -> Map.Map k Int
toCountMap = Map.fromListWith (+) . flip zip (repeat 1)


Measured memory_bytes: 47484
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
	int a;
	string s;
	cin >> a >> s;
	
	if(a>=3200) cout << s << endl;
	else cout << "red\n";
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int a[200005],l[200005],r[200005];

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
rep(i,1,n)cin>>a[i];
stack<int> s;
s.push(0);
rep(i,1,n)
{
	while(1)
	{
		if(s.empty())break;
		int id=s.top();
		if(a[id]>=a[i])
		s.pop();
		else
		{
			l[i]=id;
			break;
		}
	}
	s.push(i);
}
while(!s.empty())s.pop();
rep(i,1,n)r[i]=n+1;
s.push(n+1);
ren(i,n,1)
{
	while(1)
	{
		if(s.empty())break;
		int id=s.top();
		if(a[id]>a[i])
		s.pop();
		else
		{
			r[i]=id;
			break;
		}
	}
	s.push(i);
}
ll ans=0;
rep(i,1,n)
{
	ans+=1ll*(i-l[i])*(r[i]-i)*a[i];
}
ol(ans);
return 0;
}


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

using namespace std;

#define ll long long

int bin_pow(int a, int pow) {
    if (pow == 0) return 1;
    if (pow == 1) return a;
    if (pow % 2 == 0) {
        int tmp = bin_pow(a, pow / 2);
        return tmp * tmp;
    }
    return a * bin_pow(a, pow - 1);
}

int fact(int x) {
    int ans = 1;

    for (int i = 1; i <= x; i++) ans *= i;
    return ans;
}

int count(vector<int> a) {
    int ans = 0;
    unordered_set<int> was;
    for (int i = 0; i < a.size(); i++) {
        int count = a[i] - 1;
        for (int j = 1; j < a[i]; j++) {
            count -= was.count(j);
        }
        ans += count * fact(a.size() - i - 1);
        was.insert(a[i]);
    }

    return ans;
}

ll m = 1000000007;

bool isPrime(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

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

    int n;
    cin >> n;

    vector<int> a(n);

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

    int was = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == was + 1) {
            was++;
        }
    }

    if (was == 0) {
        cout << -1;
        return 0;
    }

    cout << (n - was);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORTR(x) sort(ALLR(x))
#define SORT(x) sort(ALL(x))
#define SUM(x) accumulate(ALL(A), 0)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
const int INF  = 1<<30;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n";

void Main()
{
	ll N;
	ll result=0;
	string S;
	cin>>N;
	VI a(N);
	REP(i, N) cin >> a[i];

	REP(i,N) {
		ll cnt=a[i];
		while (cnt % 2 == 0) {
			cnt /= 2;
			result++;
		}
	}

	cout << result << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 384
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto X = readln.chomp.to!int;
    auto n = X / 100;
    auto d = X % 100;

    int c;
    while (d >= 5) {
        d -= 5;
        ++c;
    }
    if (d >= 4) {
        d -= 4;
        ++c;
    }
    if (d >= 3) {
        d -= 3;
        ++c;
    }
    if (d >= 2) {
        d -= 2;
        ++c;
    }
    if (d >= 1) {
        ++c;
    }
    writeln(c <= n ? 1 : 0);
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

int main(){
  long long S;
  scanf("%lld", &S);
  long long x1, x2, x3, y1, y2, y3;
  x1=0;
  y1=0;
  x2=1e9;
  y2=1;
  //y3 = (S+1e9-1)/(long long)1e9;
  y3 = (S+(long long)1e9-1)/(long long)1e9;
  x3 = abs((long long)1e9*y3-S);
  
  printf("%lld %lld %lld %lld %lld %lld\n", x1, y1, x2, y2, x3, y3);
  //std::cout << abs(x2*y3-x3*y2) << std::endl;
  return 0;
}


Measured memory_bytes: 256
import math
while True:
    try:
        N, K = map(int, input().split())
        
        P = 0
        if K <= N:
            P = (N-K+1) / N
            
        for i in range(1, min(K, N+1)):
            p = math.ceil(math.log2(K/i))
            P += (1/N) * (0.5**p)
        print(P)
    except:
        break

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a){
        cout<<k<<"\n";
        return;
    }
    if(k<=a+b){
        cout<<a<<"\n";
        return;
    }
    cout<<a-(k-a-b)<<"\n";
    
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define ll long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}

signed main()
{
	string s;
	cin>>s;
	if(s.length()%2!=0) cout<<"No";
	else
	{
		for(int i=0;i<s.length();i++)
		{
			// cout<<i<<" "<<s[i]<<endl;
			if(i&1)
			{
				if(s[i]!='i')
				{
					cout<<"No\n";
					return 0;
				}
			}
			else
			{
				if(s[i]!='h')
				{
					cout<<"No\n";
					return 0;
				}
			}
		}
		cout<<"Yes\n";
	}

	return 0;
}



Measured memory_bytes: 256
s = int(input())

n = list(map(str,input()))

ans = int(0)
D = int(s%2)
S = int(s/2)

for i in range(S):
  if n[i] == n[S+i]:
    ans += 1
    
if ans == S and D != 1:
  print('Yes')
else:
  print('No')

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

bool compare1(pair<int, int> p1, pair<int, int> p2)
{
	return (p1.first > p2.first);
}

int main()
{
	int i, n, m, diff, val=0, x;

	cin >> n >> m;

	int a[m], ans[m];
	vector<pair<int, int>> v;

	for(i=0; i<m; i+=1)
		cin >> a[i];

	sort(a, a+m);

	if(n>=m)
	{
		cout << 0 << endl;
		return 0;
	}

	memset(ans, 0, sizeof(ans));
	ans[0]=1;
	for(i=1; i<m; i+=1)
	{
		diff=a[i]-a[i-1];
		v.push_back(make_pair(diff, i));
	}
	sort(v.begin(), v.end(), compare1);

	for(i=0; i<n-1; i+=1)
		ans[v[i].second]=1;

	x=0;
	for(i=1; i<m; i+=1)
	{
		if(ans[i]==1)
		{
			val+=a[i-1]-a[x];
			x=i;
		}
	}
	if(ans[m-1]!=1)
		val+=a[m-1]-a[x];

	cout << val << endl;
}

Measured memory_bytes: 2168
package main

import (
	"fmt"
)

var a, b, c, d []int

func main() {
	var n, m, q int
	fmt.Scan(&n, &m, &q)
	a, b, c, d = make([]int, q), make([]int, q), make([]int, q), make([]int, q)
	for i := range a {
		fmt.Scan(&a[i], &b[i], &c[i], &d[i])
		a[i]--
		b[i]--
	}

	var max int
	for i := 1; i <= m; i++ {
		for j := i; j <= m; j++ {
			if n == 2 {
				sl := []int{i, j}
				sum := calc(sl)
				if sum > max {
					max = sum
				}
			}
			for k := j; k <= m; k++ {
				if n == 3 {
					sl := []int{i, j, k}
					sum := calc(sl)
					if sum > max {
						max = sum
					}
				}
				for l := k; l <= m; l++ {
					if n == 4 {
						sl := []int{i, j, k, l}
						sum := calc(sl)
						if sum > max {
							max = sum
						}
					}
					for l5 := l; l5 <= m; l5++ {
						if n == 5 {
							sl := []int{i, j, k, l, l5}
							sum := calc(sl)
							if sum > max {
								max = sum
							}
						}
						for l6 := l5; l6 <= m; l6++ {
							if n == 6 {
								sl := []int{i, j, k, l, l5, l6}
								sum := calc(sl)
								if sum > max {
									max = sum
								}
							}
							for l7 := l6; l7 <= m; l7++ {
								if n == 7 {
									sl := []int{i, j, k, l, l5, l6, l7}
									sum := calc(sl)
									if sum > max {
										max = sum
									}
								}
								for l8 := l7; l8 <= m; l8++ {
									if n == 8 {
										sl := []int{i, j, k, l, l5, l6, l7, l8}
										sum := calc(sl)
										if sum > max {
											max = sum
										}
									}
									for l9 := l8; l9 <= m; l9++ {
										if n == 9 {
											sl := []int{i, j, k, l, l5, l6, l7, l8, l9}
											sum := calc(sl)
											if sum > max {
												max = sum
											}
										}
										for l10 := l9; l10 <= m; l10++ {
											if n == 10 {
												sl := []int{i, j, k, l, l5, l6, l7, l8, l9, l10}
												sum := calc(sl)
												if sum > max {
													max = sum
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	fmt.Println(max)
}

func calc(sl []int) int {
	var sum int
	for i := range a {
		if sl[b[i]]-sl[a[i]] == c[i] {
			sum += d[i]
		}
	}
	return sum
}


Measured memory_bytes: 1852
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    int sum = 0;
    int b = 10;
    for(int i = 0; i < 5; i++){
        int a;cin>>a;
        if(a%10 > 0 && a%10 < b) b = a%10;
        sum += ((a - 1)/10 + 1)*10;
    }
    cout << sum - 10 + b << endl;
    return 0;
    
}


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

void Main() {
  int n, k, q;
  int c;
  std::cin >> n >> k >> q;
  int a[n];
  for (int i = 0; i < n; i++) {
    a[i] = 0;
  }

  for (int i = 0; i < q; i++) {
    std::cin >> c;
    a[c - 1] += 1;
  }

  for (int i = 0; i < n; i++) {
    if (k - (q - a[i]) <= 0) {
      std::cout << "No" << std::endl;
    } else {
      std::cout << "Yes" << std::endl;
    }
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 1024
import math
def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

X = int(input())
for i in range(X,10**8+1):
    if is_prime(i):
        print(i)
        break

Measured memory_bytes: 3064
<?php
ob_start();
echo file_get_contents('php://stdin');
$input = ob_get_contents();
ob_end_clean();
$input = (int)trim($input);
if($input === 3 || $input === 5 || $input === 7) {
    echo "YES".PHP_EOL;
    exit;
}
echo "NO".PHP_EOL;

Measured memory_bytes: 4604
#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>
#include<tuple>
using namespace std;
typedef long long unsigned int ll;

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

int main() {
    string s,t;
    cin>>s>>t;
    vector<int>start(26,-1);
    vector<int>goal(26,-1);
    for(int i=0;i<s.size();i++){
        int a=s[i]-'a';
        int b=t[i]-'a';
        if(start[a]!=-1 ||goal[b]!=-1){
            if(start[a]!=b ||goal[b]!=a){
            cout<<"No"<<endl;
            return 0;
        
        }
        }
        else{
            start[a]=b;
            goal[b]=a;
        }
    }
            cout<<"Yes"<<endl;
        
    
        return 0;
    }
   

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

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

    for (int i = 0; i <= 1000; i++)
    {
        for (int j = -1000; j <= i; j++)
        {
            if ((long long) i * i * i * i * i - (long long) j * j * j * j * j == x)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
inline void init() { /*cin.tie(nullptr);*/ cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n; cin >> n;

    vector<string> s(n);
    cout << "0\n"; 
    fflush(stdout);
    cin >> s[0];
    if (s[0] == "Vacant")return 0;

    int l = 1, r = n;
    while (1) {
        int mid = (l + r) / 2;
        cout << mid << "\n";
        fflush(stdout);
        cin >> s[mid];
        if (s[mid] == "Vacant")return 0;

        if ((mid % 2 == 0 && s[0] == s[mid]) || (mid % 2 == 1 && s[0] != s[mid]))l = mid + 1;
        else r = mid;
    }
}


Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;


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

  int num_a=0, num_b=0, num_ab=0, cnt=0;

  for (int i=0;i<N;++i){
    int flag=0;
    string s;cin>>s;
    int M=s.size();
    if(s[0]=='B'){
      flag=1;
      num_b++;
    }
    if(s[M-1]=='A'){
      num_a++;
      if(flag==1) {
        num_ab++;
      }
    }

    for (int j=1;j<M;++j){
      if(s[j-1]=='A'&&s[j]=='B') cnt++;
    }
  }

  int x=num_a-num_ab, y=num_b-num_ab;
  int tmp=min(x, y)+num_ab;
  if(x==0&&y==0) tmp=num_ab-1;
  if(num_ab==0) tmp=min(x,y);
  cnt+=tmp;


  cout << cnt << endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define pr pair<int, int>
#define x first
#define y second
using namespace std;

template<typename T>
void read(T& n){
	char ch; int sign = 1;
	while (!isdigit(ch = getchar())) if (ch == '-') sign = -1;
	n = ch - '0';
	while (isdigit(ch = getchar())) n = n * 10 + ch - '0';
	n *= sign;
}
typedef long long ll;
const int INF = 1e9 + 7;
const int N = 211111;
int n;
int a[N], pos[N], f[2][N][44];
struct node{
	int v, l, r;
	bool operator <(const node rhs) const{
		return v > rhs.v;
	}
};
priority_queue<node> heap;

void init(int idx){
	for (int i = 1; (1 << i) <= n; ++i)
		for (int j = 1; j + (1 << i) - 1 <= n; ++j)
			f[idx][j][i] = min(f[idx][j][i-1], f[idx][j+(1<<i-1)][i-1]);
}
int query(int idx, int l, int r){
	if (l > r||l <= 0||r > n) return INF;
	int k = 0; while((1ll << k) <= r - l + 1) k++; k--;
	return min(f[idx][l][k], f[idx][r-(1<<k)+1][k]);
}
void dfs(int l, int r){
	int t1 = pos[query(l % 2, l, r)], t2 = pos[query(l % 2 == 0, t1 + 1, r)];
	printf("%d %d ", a[t1], a[t2]);
	heap.push((node){query(l % 2, l, t1 - 1), l, t1 - 1});
	heap.push((node){query((t1 + 1) % 2, t1 + 1, t2 - 1), t1 + 1, t2 - 1});
	heap.push((node){query((t2 + 1) % 2, t2 + 1, r), t2 + 1, r});
	while(!heap.empty()){
		node t = heap.top(); heap.pop();
		if (t.l <= t.r) dfs(t.l, t.r);
	}
}

int main(){
	read(n);
	memset(f, 127, sizeof(f));
	rep(i, 1, n){
		read(a[i]), pos[a[i]] = i;
		if (i % 2 == 0) f[0][i][0] = a[i];
		else f[1][i][0] = a[i];
	}
	init(0), init(1); dfs(1, n); puts("");
	return 0;
}

Measured memory_bytes: 88176
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let mut T = read![i64, i64; N];
    T.sort();

    let mut PQ = vec![];
    for s in 0..N {
        let (sx, sy) = T[s];

        for t in s + 1..N {
            let (tx, ty) = T[t];

            let u = (sx - tx, sy - ty);
            let v = (tx - sx, ty - sy);

            PQ.push(u);
            PQ.push(v);
        }
    }
    PQ.sort();
    PQ.dedup();

    let mut min_cost = std::i64::MAX;

    if N == 1 {
        min_cost = 1;
    }

    for &(p, q) in &PQ {
        let mut set = BTreeSet::new();
        for i in 0..N {
            set.insert(T[i]);
        }

        let mut cost = 0;
        while let Some(&(x, y)) = set.iter().next() {
            set.remove(&(x, y));
            cost += 1;

            let (mut x, mut y) = (x, y);
            loop {
                x += p;
                y += q;

                if !set.remove(&(x, y)) {
                    break;
                }
            }
        }

        min_cost = min(min_cost, cost);
    }

    println!("{}", min_cost)
}


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

int main() {
  int n;
  cin >> n;
  int sum = 0;
  vector<int> v(n);
  for(int i=0; i<n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  sort(v.rbegin(), v.rend());
  cout << sum - v[0]/2 << endl;
  return 0;
}

Measured memory_bytes: 3664
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

w = input()
W = Counter(w)
for v in W.values():
	if v%2:
		print("No")
		break
else:
	print("Yes")

Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
#define INF 2e9
vector<tuple<int, int ,int>> vec;
void Write(int obj, int len){
    for(int i = 0; i < vec.size(); i++){
        tuple<int, int, int> t = vec[i];
        if(get<2>(t) == INF){
            if(get<1>(t) - get<0>(t) + 1 > len){
                vec.insert(vec.begin() + i, make_tuple(get<0>(t), get<0>(t) + len - 1, obj));
                vec[i + 1] = make_tuple(get<0>(t) + len, get<1>(t), INF);
                break;
            }
            else{
                vec[i] = make_tuple(get<0>(t), get<1>(t), obj);
                len -= get<1>(t) - get<0>(t) + 1;
            }
        }
    }
}
void Delete(int obj){
     for(int i = 0; i < vec.size(); i++){
        tuple<int, int, int> t = vec[i];
        if(get<2>(t) == obj){
            vec[i] = make_tuple(get<0>(t), get<1>(t), INF);
        }
     }
}
int Read(int index){
     for(int i = 0; i < vec.size(); i++){
        tuple<int, int, int> t = vec[i];
        if(get<0>(t) <= index && get<1>(t) >= index){
            return get<2>(t) != INF ? get<2>(t) : -1;
        }
     }
}
int main(){
    int n;
    char com;
    int arg, arg2;
    while(cin >> n && n){
        vec.clear();
        vec.push_back(make_tuple(0, INF, INF));
        for(int i = 0; i < n; i++){
            cin >> com;
            if(com == 'W'){
                cin >> arg >> arg2;
                Write(arg, arg2);
            }
            else if(com == 'D'){
                cin >> arg;
                Delete(arg);
            }
            else{
                cin >> arg;
                cout << Read(arg) << endl;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
int main(){
  int n;
  cin>>n;
  double p[n];
  for(int i=0;i<n;i++) cin>>p[i];
  ///dp[x][y],x->number of head,y->number of coins
  double dp[n+1][n];
  memset(dp,0,sizeof dp);
  dp[0][0]=1-p[0];
  for(int i=1;i<n;i++) dp[0][i]=dp[0][i-1]*(1-p[i]);
  dp[1][0]=p[0];
  for(int i=1;i<=n;i++){
    for(int j=1;j<n;j++){
      if(i>j+1) dp[i][j]=0;
      else dp[i][j]=dp[i-1][j-1]*p[j]+dp[i][j-1]*(1-p[j]);
   
    }
  }
  double ans=0;
 for(int i=0;i<=n;i++){
   for(int j=0;j<n;j++) if(j==n-1 && i>n/2) ans+=dp[i][j];
  
 }
  printf("%.10f",ans);
}

Measured memory_bytes: 70528