akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

#define MAX_N 500
#define MAX_C 30

int N, C;
int d[MAX_C][MAX_C], c[MAX_N][MAX_N];

int calc(int col, int MOD)
{
    int res = 0;
    rep(i, N) rep(j, N) if ((i + j) % 3 == MOD) res += d[c[i][j]][col];
    return res;
}

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

    cin >> N >> C;
    rep(i, C) rep(j, C) cin >> d[i][j];
    rep(i, N) rep(j, N)
    {
        cin >> c[i][j];
        c[i][j]--;
    }
    vector<int> cost1(C), cost2(C), cost3(C);
    rep(i, C) cost1[i] = calc(i, 0);
    rep(i, C) cost2[i] = calc(i, 1);
    rep(i, C) cost3[i] = calc(i, 2);
    int ans = INF;
    rep(i, C) rep(j, C) rep(k, C)
    {
        if (i == j || j == k || k == i)
            continue;
        ans = min(ans, cost1[i] + cost2[j] + cost3[k]);
    }
    cout << ans << endl;
}

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

int main() {
  
  // 入力
  int N, M;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++) {
      cin >> s.at(i);
  }
  
  cin >> M;
  vector<string> t(M);
  for(int i = 0; i < M; i++) {
      cin >> t.at(i);
  }
  
  int reward, max_reward = 0;
  
  for(int i = 0; i < N; i++) {
      reward = 1;
      for(int j =  i + 1; j < N; j++) {
        if (s.at(i) == s.at(j)) {
              reward++;
          }

      }
      for(int j = 0; j < M; j++) {
          if (s.at(i) == t.at(j)) {
              reward--;
          }
      }
      if (max_reward < reward) {
          max_reward = reward;
      }
  }
  
  cout << max_reward << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#define it register int
#define ct const int
#define il inline
typedef long long ll;
ll Max(ll p,ll q){return p>q?p:q;}
#define P 1000000007
int f[5005];
il int ksm(it x,it L){
	it ans=1;while(L) L&1?ans=(0ll+ans)*x%P:0,x=(0ll+x)*x%P,L>>=1;
	return ans;
}
il int dfs(ct x){
	if(f[x]) return f[x];
	if(x==3||x==4||x==5) return f[x]=1;
	f[x]=1;
	for(it i=x-3;i>=3;--i) f[x]+=dfs(x-i),f[x]=(f[x]>=P?f[x]-P:f[x]);
	return f[x];
}
int main(){
	int n;scanf("%d",&n);
	if(n<3) return puts("0"),0;
	f[0]=1;
/*	for(it i=3;i<=n;++i)
		for(it j=i;j<=n;++j)
			f[j]+=f[j-i],f[j]=(f[j]>=P?f[j]-P:f[j]);
	for(it i=0;i<=n;++i) printf("%d ",f[i]);
	printf("%d",f[n]);*/
	printf("%d\n",dfs(n));
  	return 0;
}


Measured memory_bytes: 1732
card = []
for i in range(3):
  card += list(map(int, input().split()))
N = int(input())
bingo = [(1, 2, 3), (4, 5, 6), (7, 8, 9), (1, 4, 7), (2, 5, 8), (3, 6, 9), (1, 5, 9), (3, 5, 7)]
for i in range(N):
  n = int(input())
  if n in card:
    card[card.index(n)] = "hit"
#print(card)
ans = "No"
for patt in bingo:
  if card[patt[0]-1] == card[patt[1]-1] == card[patt[2]-1] == "hit":
    ans = "Yes"
    break
print(ans)

Measured memory_bytes: 3064
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const size_t size = 2e5 + 10;
ll head[size];
bool used[size];

ll solve() {
    ll N;
    cin >> N;
    V<ll> A(N);
    for(auto &&ele : A) cin >> ele;
    for(ll i = 0; i < N; i++) {
        if(i < A[i]) return -1;
        head[i] = i - A[i];
    }

    for(ll i = 0; i < N - 1; i++) if(head[i + 1] < head[i]) return -1;

    ll ans = 0;
    for(ll i = N - 1; 0 <= i; i--) {
        if(used[head[i]]) continue;
        used[head[i]] = true;
        ans += i - head[i];
    }

    return ans;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
 
void quicksort(int X[],int head,int tail);
 
main(){
  int N,M; //コマ,座標の数
  int i; //カウンター
  scanf("%d%d",&N,&M);
  int X[M]; //座標の配列
  int D[M-1]; //隣り合う座標の差
  int A=0;
  
  for(i=0;i<M;i++)
    scanf("%d",&X[i]);
  
  if(N<M){ //N>=Mの時すべてのコマを座標上に置くことが出来るので0
    quicksort(X,0,M-1);
    for(i=0;i<M-1;i++)
      D[i] = X[i+1] - X[i];
    quicksort(D,0,M-2);
    for(i=0;i<M-N;i++){
      A += D[i];
    }
  }
  
  printf("%d\n",A);
  
  return 0;
}
 
void quicksort(int X[],int head,int tail){
  int pivot; //ピボット
  int tmphead,tmptail;
  int i; //カウンター
  tmphead = head;
  tmptail = tail;
  pivot = X[head];
  while(head<tail){
    while(X[tail]>=pivot && head<tail) tail--;
    if(head!=tail) X[head++] = X[tail];
    while(X[head]<=pivot && head<tail) head++; 
    if(head!=tail) X[tail--] = X[head];
  }
  X[head] = pivot;
  pivot = head;
  head = tmphead;
  tail = tmptail;
  if(head<pivot)
  quicksort(X,head,pivot-1);
  if(tail>pivot)
  quicksort(X,pivot+1,tail);
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>

using namespace std;

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

    if(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int n = scan.nextInt();
		int [] s = new int[13];
		int [] h = new int[13];
		int [] c = new int[13];
		int [] d = new int[13];

		for(int i = 0;i<n;i++){
			String t = scan.next();
			if("S".equals(t)){
				int j = scan.nextInt();
				s[j-1]++;
			}else if("H".equals(t)){
				int j = scan.nextInt();
				h[j-1]++;
			}else if("C".equals(t)){
				int j = scan.nextInt();
				c[j-1]++;
			}else if("D".equals(t)){
				int j = scan.nextInt();
				d[j-1]++;
			}
		}

		for(int i=0;i<13;i++){
			if(s[i] == 0){
				int t = i+1;
				System.out.println("S "+t);
			}
		}
		for(int i=0;i<13;i++){
			if(h[i] == 0){
				int t = i+1;
				System.out.println("H "+t);
			}
		}
		for(int i=0;i<13;i++){
			if(c[i] == 0){
				int t = i+1;
				System.out.println("C "+t);
			}
		}
		for(int i=0;i<13;i++){
			if(d[i] == 0){
				int t = i+1;
				System.out.println("D "+t);
			}
		}
	}
}

Measured memory_bytes: 26228
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
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;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B; cin >> A >> B;

    int res = B;
    if(A <= 5) res = 0;
    else if(A <= 12) res /= 2;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a,b,l,r,f,u[1111];
vector<int>v[1111];
void dfs(int x,int d){
	u[x]=d;
	if(d)l++;
	else r++;
	r(i,v[x].size()){
		int nx=v[x][i];
		if(u[nx]!=-1){
			if(u[nx]==u[x])f++;
		}
		else{
			dfs(nx,d^1);
		}
	}
}
int main(){
	while(cin>>n>>m,n){
		l=r=f=0;
		r(i,n)v[i].clear();
		r(i,m){
			cin>>a>>b;
			a--;b--;
			v[a].push_back(b);
			v[b].push_back(a);
		}
		memset(u,-1,sizeof(u));
		dfs(0,0);
		if(f)cout<<0<<endl;
		else{
			vector<int>ans;
			if(l%2==0)ans.push_back(l/2);
			if(r%2==0&&l!=r)ans.push_back(r/2);
			sort(ans.begin(),ans.end());
			cout<<ans.size()<<endl;
			r(i,ans.size()){
				cout<<ans[i]<<endl;
			}
		}
	}
}


Measured memory_bytes: 3204
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
int C[5];
string s;
int main() {
	cin >> n;
	REP(i, n) {
		cin >> s;
		if (s[0] == 'M')C[0]++;
		if (s[0] == 'A')C[1]++;
		if (s[0] == 'R')C[2]++;
		if (s[0] == 'C')C[3]++;
		if (s[0] == 'H')C[4]++;
	}
	LL ans = 0;
	REP(i, (1 << 5)) {
		int count = 0;
		bool t[5] = {};
		REP(j, 5)if (i & 1 << j) {
			count++;
			t[j] = true;
		}
		if (count != 3)continue;
		LL num = 1;
		REP(j, 5) {
			if (t[j])num *= C[j];
		}
		ans += num;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var N int
var W int
var wv [][]int
var dp [][]int

func main() {
	N = nextInt()
	W = nextInt()
	wv = make([][]int, N+1)
	maxValue := N*int(math.Pow(10, 3)) + 1
	maxWeight := N*int(math.Pow(10, 9)) + 1
	wv[0] = make([]int, 2)
	for i := 1; i < N+1; i++ {
		wv[i] = nextInts(2)
	}

	dp = make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		dp[i] = make([]int, maxValue)
		for j := 0; j < maxValue; j++ {
			dp[i][j] = maxWeight
		}
	}

	dp[0][0] = 0

	for i := 1; i < N+1; i++ {
		for v := 0; v < maxValue; v++ {
			if v < wv[i][1] {
				dp[i][v] = dp[i-1][v]
			} else {
				dp[i][v] = MinIn2Values(dp[i-1][v], dp[i-1][v-wv[i][1]]+wv[i][0])
			}
		}
	}
	result := 0
	for i := 0; i < maxValue; i++ {
		if dp[N][i] <= W {
			result = i
		}
	}
	fmt.Println(result)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

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

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


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

int main(){
	
	int n,x;
	cin >> n >> x;
	
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	
	vector<int> d;
	d.push_back(0);
	
	rep(i,n){
		int now = d.back();
		d.push_back(now+l[i]);
		if(d.back() > x) break;
	}

	if(d.back() > x) cout << d.size()-1 << endl;
	else cout << d.size() << endl;
	return 0;
}

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

const ll INF = pow(10, 9) + 7;

int main() {
  int N;
  cin >> N;
  vector<string> a(N);
  rep(i,N) cin >> a[i];
  stack<pair<int,string>> S;
  sort(a.begin(),a.end());
  pair<int,string> aa(1,a[0]);
  S.push(aa);
  rep(i,N-1){
    if(a[i]!=a[i+1]){
      pair<int,string> aaa(1,a[i+1]);
      S.push(aaa);
      continue;
    }
    S.top().first++;
  }
  vector<pair<int,string>> V;
  while(!S.empty()){
    V.push_back(S.top());
    S.pop();
  }
  sort(V.rbegin(),V.rend());
  vector<string> ans;
  for(int i=0;i<V.size();i++){
    if(V[0].first != V[i].first) break;
    ans.push_back(V[i].second);
  }
  sort(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++) cout << ans[i] << endl;
}


Measured memory_bytes: 21832
def run_length(data, init=''):
    length = []
    tmp = init
    cnt = 0
    for c in data:
        if tmp != c:
            length.append(cnt)
            cnt = 0
        tmp = c
        cnt += 1
    length.append(cnt)
    return length

s = input()
rev = run_length(s)
# print(rev)
print(len(rev) - 2)

Measured memory_bytes: 3956
N=int(input())
X=[]
U=[]
for i in range(N):
    x,u=map(str,input().split())
    X.append(float(x))
    U.append(u)
money=0
for k in range(N):
    if U[k]=='JPY':
        money=money+X[k]
    else:
        money=money+X[k]*380000.0
print(money)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define p5 100005
using namespace std;
int dp[p5][3];
int main()
{
    int n,i,j;
    cin>>n;
    int ar[n+1][3];
    for(i=0;i<n;i++){
        for(j=0;j<3;j++){
            cin>>ar[i][j];
        }
    }
    for(i=1;i<=n;i++){
        dp[i][0]=max(dp[i][0],max(dp[i-1][1],dp[i-1][2]))+ar[i-1][0];
        dp[i][1]=max(dp[i][1],max(dp[i-1][0],dp[i-1][2]))+ar[i-1][1];
        dp[i][2]=max(dp[i][2],max(dp[i-1][0],dp[i-1][1]))+ar[i-1][2];
    }
    int ans=max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
//============================================================================
// Name        : CompleteBinaryTree.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

class BinaryHeap{
private:
	vector<int> contents;

public:
	BinaryHeap(){}

	void insert(int elem){
		contents.push_back(elem);
	}

	void writeHeap(){
		for(int i=0; i<contents.size(); i++){
			cout << " " << contents.at(i);
		}
	}

	void maxHeapify(int i){
		int l = i * 2 + 1;
		int r = i * 2 + 2;
		int largest = -1;
		if(l < contents.size() and contents.at(l) > contents.at(i)){
			largest = l;
		}else{
			largest = i;
		}

		if(r < contents.size() and contents.at(r) > contents.at(largest)){
			largest = r;
		}

		if(largest != i){
			int tmp = contents.at(i);
			contents.at(i) = contents.at(largest);
			contents.at(largest) = tmp;
			maxHeapify(largest);
		}
	}

	void buildMaxHeap(){
		for(int i = (contents.size()+1)/2 - 1; i>=0; i--){
			maxHeapify(i);
		}
	}

	/***
	void writeContent(int index){
		cout << "node " << index+1 << ": key = " << contents.at(index) << ", ";

		int parent_index = (index+1)/2 - 1;
		int left_index = (index+1) * 2 - 1;
		int right_index = (index+1) * 2;
		if(parent_index >= 0){
			cout << "parent key = " << contents.at(parent_index) << ", ";
		}
		if(left_index < contents.size()){
			cout << "left key = " << contents.at(left_index) << ", ";
		}
		if(right_index < contents.size()){
			cout << "right key = " << contents.at(right_index) << ", ";
		}
		cout << "\n";
	}
	***/

};

int main() {
	int n, input;
	BinaryHeap bh;

	cin >> n;
	for(int i=0; i<n; i++){
		cin >> input;
		bh.insert(input);
	}

	bh.buildMaxHeap();
	bh.writeHeap();
	cout << "\n";
}



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

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

long long gcm(long long a,long long b)
{
  long long g=gcd(a,b);
  return (a/g)*(b/g)*g;
}

int main()
{
  int N;scanf("%d",&N);
  long long T[N];
  for(int i=0;i<N;i++)scanf("%lld",&T[i]);
  long long g=T[0];
  for(int i=1;i<N;i++)g=gcm(g,T[i]);
  printf("%lld",g);
}

Measured memory_bytes: 3780
var main = function(input) {
  input = input.split(' ').map(x=>parseInt(x));
  var a = input[0];
  var b = input[1];
  var max　= a+b;
  if(max<a-b){
    max = a-b;
  }
  if(max<a*b){
    max=a*b;
  }
  if(max === -0){
    max = 0;
  }
  console.log(max);

    return 0; 
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100000000000000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N,K;
    cin >> N >> K;
    if((N-1) * (N-2) / 2 < K){
        cout << -1 << endl;
        return 0;
    }
    vector<pair<ll,ll>> ans;
    ll M = N-1,n = (N-1) * (N-2) / 2;
    FOR(i,1,N){
        ans.emplace_back(0,i);
    }
    FOR(i,1,N){
        FOR(j,i+1,N){
            if(n == K){
                goto END;
            }
            ans.emplace_back(i,j);
            M++;
            n--;
        }
    }
    END:
    cout << M << endl;
    rep(i,ans.size()){
        cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl; 
    }
}


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

int main() {

    rep(i, 100000000){
        int a, b;
        char c;
        cin >> a >> c >> b;
        if(c == '?') break;
        else if(c == '+') cout << a + b << endl;
        else if(c == '-') cout << a - b << endl;
        else if(c == '*') cout << a * b << endl;
        else if(c == '/') cout << a / b << endl;    
    }

}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int const N = 101, K = 1e5 + 1;
 
int n, k;
int arr[N];
 
int dp[K][2];
bool vis[K][2];
 
int pound(int stones, int turn)
{
    if (stones < 0)
        return turn;
    
    if (vis[stones][turn])
        return dp[stones][turn];
        
    vis[stones][turn] = 1;
    
    dp[stones][turn] = 1 - turn;
    for (int i = 0; i < n; ++i)
    {
        if (turn)
            dp[stones][turn] = max(dp[stones][turn], pound(stones - arr[i], 1 - turn));
        else
            dp[stones][turn] = min(dp[stones][turn], pound(stones - arr[i], 1 - turn));
    }
    
    return dp[stones][turn];
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> arr[i];
        
    if (pound(k, 1))
        cout << "First";
    else cout << "Second";
    
    return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#define rep(i,n) for((i)=0;(i)<(n);i++)

using namespace std;

int v[3],n,c;
string s;

int f(){
  n++;
  int r;
  if(s[n-1]=='(')r=f(),n++,r=s[n-1]=='+'?max(r,f()):min(r,f()),n++;
  else if(s[n-1]=='-')r=2-f();
  else if(isdigit(s[n-1]))r=s[n-1]-'0';
  else r=v[s[n-1]-'P'];
  return r;
}

int main(){ 
  cin >> s;
  if(s!="."){
    c=0;
    rep(v[0],3)rep(v[1],3)rep(v[2],3)n=0,c+=f()/2;
    cout << c << endl;
    main();
  }
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
ll f[MAXN];
void add(int i,int x)
{
    for (;i<MAXN;i|=i+1)
        f[i]+=x;
}
ll res(int l)
{
    ll sum=0;
    for (;l>=0;l=(l&(l+1))-1)
        sum+=f[l];
    return sum;
}
ll res(int l,int r)
{
    return res(r)-res(l-1);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    int n;
    cin>>n;
    ll d,a;
    cin>>d>>a;
    vector <pll > x(n);
    rep(i,n)
    cin>>x[i].fi>>x[i].se;
    sort(x.begin(),x.end());
    vector <ll> coord;
    for (int i=0;i<n;i++)
    {
        coord.pb(x[i].fi);
        coord.pb(x[i].fi+2*d+1);
    }
    sort(coord.begin(),coord.end());
    int o=0,p=0;
    vector <ll> ah;
    while (o<coord.size())
    {
        while (p<coord.size()&&coord[o]==coord[p])
            p++;
        ah.pb(coord[o]);
        o=p;
    }
    coord=ah;
    map <ll,ll> m;
    int cur=1;
    for (int i=0;i<coord.size();i++)
    {
        m[coord[i]]=cur;
        cur++;
    }
    ll ans=0;
    for (int i=0;i<n;i++)
    {
        ll y=res(0,m[x[i].fi]);
        if (y>=x[i].se)
            continue;
        ll t=(x[i].se-y+a-1)/a;
        ans+=t;
        add(m[x[i].fi],t*a);
        add(m[x[i].fi+2*d+1],-t*a);
    }
    cout<<ans;
}

Measured memory_bytes: 41580
N = gets.to_i
A = gets.split.map(&:to_i).sort.reverse
B = gets.split.map(&:to_i).sort
C = gets.split.map(&:to_i).sort

sum = 0
B.each do |b|
  i = A.bsearch_index do |a|
    a < b
  end

  j = C.bsearch_index do |c|
    c > b
  end

  next if i.nil? || j.nil?

  sum += (N - i) * (N - j)
end

p sum


Measured memory_bytes: 25680
#include <bits/stdc++.h>
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

map<int, int> have, need;

int main() {
    ios::sync_with_stdio(false);
    cout.precision(10);
    int n, m;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        int cur;
        cin >> cur;
        have[cur]++;
    }
    cin >> m;
    for(int i = 1; i <= m; i++) {
        int cur;
        cin >> cur;
        need[cur]++;
        if(need[cur] > have[cur]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 19072
n, m = map(int,input().split())
A = list(map(int,input().split()))
x = sum(A)* 1/(4*m)
ans = [int() for a in range(m)]
for i in range(n):
    if A[i] >= x:
        if A[i] > ans[0]:
            ans[0] = A[i]
            ans.sort()
ct = 0
for i in range(m):
    if ans[i] != 0:
        ct +=1
if ct == m:
    print("Yes")
else:
    print("No")


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;
int V[MAX_N];
map<int, int> even, odd;

signed main()
{
    cin >> N;
    REP(i, N) {
        cin >> V[i];
        if(i % 2 == 0) { even[V[i]]++; }
        else { odd[V[i]]++; }
    }
    pair<int, int> max_e1 = {0, 0}, max_e2 = {0, 0};
    pair<int, int> max_o1 = {0, 0}, max_o2 = {0, 0};
    for(const auto& e : even) {
        if(max_e1.second < e.second) {
            max_e2 = max_e1;
            max_e1 = e;
        }
        else if(max_e2.second < e.second) {
            max_e2 = e;
        }
    }
    for(const auto& o : odd) {
        if(max_o1.second < o.second) {
            max_o2 = max_o1;
            max_o1 = o;
        }
        else if(max_o2.second < o.second) {
            max_o2 = o;
        }
    }

    int ans = 0;
    // 数字がかぶってない
    if(max_e1.first != max_o1.first) {
        ans = N - max_e1.second - max_o1.second;
    }
    else {
        ans = N - max_e1.second - max_o2.second;
        ans = min(ans, N - max_e2.second - max_o1.second);
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x) & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

int D, T, S;

void solve() {

    scanf("%d %d %d", &D, &T, &S);

    int need = (D + S - 1) / S;

//    cout << need << endl;

    if(need <= T) puts("Yes");

    else puts("No");

}


int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


Measured memory_bytes: 3760
a=input()
b=input()
c=b.split(" ")
for i in range( len(c)):
  c[i]=int(c[i])
count=0
for i in range(len(c)):
  for j in range(i+1,len(c)):
    for k in range(j+1,len(c)):
      if (c[j]<c[i]and c[k]<c[i]and c[j]!=c[k]and c[i]<c[j]+c[k])or (c[i]<c[j]and c[k]<c[j]and c[i]!=c[k]and c[j]<c[i]+c[k])or (c[j]<c[k]and c[i]<c[k]and c[j]!=c[i]and c[k]<c[j]+c[i]):
        count+=1
print(count)
      

Measured memory_bytes: 9248
#include<stdio.h>

int main(){
  int x,y,d,swap;
  scanf("%d %d",&x,&y);
  if(y>x){
    swap = x;
    x = y;
    y = swap;
  }
  
  d = x%y;
  while(d!=0){
    x = y;
    y = d;
    d = x%y;
  }
  printf("%d\n",y);

  return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <limits.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;


const char* YesNo(bool b)
{
	if (b)
	{
		return "Yes";
	}
	else
	{
		return "No";
	}
}

int main()
{
	string S;
	cin >> S;

	bool ans = (S[2] == S[3] && S[4] == S[5]);
	cout << YesNo(ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
L E=70;W S(V<W>p){if(!E){return{1,0};}V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1){T[(x[1]+1)&1].push_back({x[0]/2,(x[1]+1)/2});}}for(L i;i<2;i++){L c=0;for(W x:T[!i]){L Q=(2*x[0]+x[1])%3;c^=Q+1;}if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p){v[0]++;}W A=S(p);A[0]--;return A;}int main(){L M=2e17,n,a,b;cin>>n;V<W>p(n);for(L i;i<n;i++){cin>>a>>b;p[i]={a+M,b+M};}W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
def meguru_bisect(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok


N, Q = map(int, input().split())
S = input()
t, d = [], []
for i in range(Q):
    ti, di = input().split()
    t.append(ti)
    d.append(di)


def solve(i):
    for j in range(Q):
        if S[i] == t[j]:
            if d[j] == "L":
                i -= 1
            else:
                i += 1

            if i < 0 or i >= N:
                return 1
    return 0


left = meguru_bisect(-1, N)
right = meguru_bisect(N, -1)
print(max(right-left-1, 0))

Measured memory_bytes: 85068
#include <functional>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#include <type_traits>
namespace loquat {
template <typename T>
static std::pair<T, T> extended_gcd(T a, T b){
	if(b == 0){ return std::pair<T, T>(1, 0); }
	const auto p = extended_gcd(b, a % b);
	return std::pair<T, T>(p.second, p.first - a / b * p.second);
}
}
namespace loquat {
template <int MOD>
class modulus_integer {
public:
	typedef modulus_integer<MOD> self_type;
private:
	int m_value;
	static self_type unsafe_construct(int x) noexcept {
		self_type y;
		y.m_value = x;
		return y;
	}
public:
	modulus_integer() noexcept
		: m_value(0)
	{ }
	modulus_integer(int x) noexcept
		: m_value(x % MOD)
	{
		if(m_value < 0){ m_value += MOD; }
	}
	int operator*() const noexcept { return m_value; }
	self_type& operator=(const self_type& x) noexcept {
		m_value = x.m_value;
		return *this;
	}
	self_type operator+(const self_type& x) const noexcept {
		const int y = m_value + x.m_value;
		return unsafe_construct(y >= MOD ? y - MOD : y);
	}
	self_type operator-(const self_type& x) const noexcept {
		const int y = m_value - x.m_value;
		return unsafe_construct(y < 0 ? y + MOD : y);
	}
	self_type operator*(const self_type& x) const noexcept {
		return unsafe_construct(
			static_cast<long long>(m_value) * x.m_value % MOD);
	}
	self_type operator/(const self_type& x) const {
		return (*this) * self_type(extended_gcd(x.m_value, MOD).first);
	}
	self_type& operator+=(const self_type& x) noexcept {
		return (*this = *this + x);
	}
};
template <int MOD>
inline std::ostream& operator<<(
	std::ostream& os, const modulus_integer<MOD>& x)
{
	os << *x;
	return os;
}
}
namespace loquat {
template <typename T, typename F = std::plus<T>>
class fenwick_tree {
public:
	using value_type = T;
private:
	std::vector<T> m_data;
	F m_func;
public:
	explicit fenwick_tree(
		size_t n,
		const value_type& x = value_type(),
		const F& f = F())
		: m_data(n + 1)
		, m_func(f)
	{
		m_data[0] = value_type();
		for(size_t i = 1; i <= n; ++i){
			m_data[i] = x;
			for(size_t j = i; (j & 1) == 0u; j >>= 1){
				m_data[i] = m_func(m_data[j], m_data[i]);
			}
		}
	}
	value_type query(size_t i) const {
		value_type s = m_data[i];
		for(i -= i & -i; i > 0; i -= i & -i){
			s = m_func(m_data[i], s);
		}
		return s;
	}
	void modify(size_t i, const value_type& x){
		const auto n = m_data.size();
		for(++i; i < n; i += i & -i){
			m_data[i] = m_func(m_data[i], x);
		}
	}
};
}
using namespace std;
static const int MOD = 1000000007;
using mint = loquat::modulus_integer<MOD>;
int main(){
	ios_base::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	const mint km = k, inv2 = mint(1) / mint(2);
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	const int m = 2001;
	loquat::fenwick_tree<mint> ft1(m), ft2(m);
	for(int i = 0; i < n; ++i){ ft1.modify(a[i], 1); }
	mint answer = 0;
	for(int i = n - 1; i >= 0; --i){
		const mint t = ft1.query(a[i]);
		answer += ft1.query(a[i]) * km * (km - 1) * inv2;
		answer += ft2.query(a[i]) * km;
		ft2.modify(a[i], 1);
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
takadaigo = a
sumsum= 0
for i in range(n-1):
    if a[i] > a[i+1]:
        sumsum += a[i] - a[i+1]
        a[i+1] = a[i]
print (sumsum)

Measured memory_bytes: 94112
n = int(input())
a = [int(x) for x in input().split()]
if 0 in a:
    print(0)
else:
    ans = 1
    for i in a:
        ans = ans * i
        if ans > 10**18:
            print(-1)
            break
    if ans <= 10**18:
        print(ans)

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

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

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

    long long x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<long long> p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];

    sort(p.begin(), p.end(), greater<long long>());
    sort(q.begin(), q.end(), greater<long long>());
    sort(r.begin(), r.end(), greater<long long>());

    vector<long long> s(x + y);

    rep(i, x) s[i] = p[i];
    rep(i, y) s[i + x] = q[i];

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

    long long sum = 0;
    long long z = x + y;
    rep(i, z) {
        sum += s[i];
    }

    for (int i = 0; i < c; i++) {
        long long t = sum;

        if(i>z)
            break;

        t = sum + r[i] - s[i];

        if(t>sum){
            sum = t;
        }else{
            break;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3968
from collections import Counter
N = int(input())
scounter = Counter([input() for _ in range(N)])
M = int(input())
tcounter = Counter([input() for _ in range(M)])

nums = []
for s in scounter.keys():
    nums.append(scounter[s] - tcounter[s])

max_num = max(nums)
print(max_num if max_num > 0 else 0)


Measured memory_bytes: 3316
/*input
3 2
2 1
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const int maxn=5e5+5;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<(a-c)*(b-d);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))
 
 
using namespace std;
 
 
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 
typedef long double LD;
 
int H,W,d;

bool Judge(){
	for(int n=0;n<=H;++n) for(int m=0;m<=W;++m){
		int tmp = n*W + m*H - 2*n*m;
		if(tmp == d || H*W-tmp==d) return true;
	}
	return false;
}
 
int main(){
	cin>>H>>W>>d;
	if(Judge()) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        boolean[] nonPrime = new boolean[50001];
        nonPrime[0] = true;
        nonPrime[1] = true;

        for (int i = 2; i <= 25000; i++) {
            if (nonPrime[i]) {
                continue;
            }

            for (int j = i + i; j <= 50000; j += i) {
                nonPrime[j] = true;
            }
        }

        String line;
        while (!(line = br.readLine()).equals("0")) {
            int x = Integer.parseInt(line);
            int result = 0;

            if (x % 2 == 0) {
                for (int j = 2; j <= x / 2; j++) {
                    if (!nonPrime[j] && !nonPrime[x - j])
                        result++;
                }
            } else {
                if (!nonPrime[x - 2])
                    result++;
            }

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


Measured memory_bytes: 30824
#include <iostream>

using namespace std;

int main(void)
{
    int N, a;

    cin >> N;

    if(N%2==1){
        a = N / 2 + 1;
    }

    else{
        a = N / 2;
    }
    cout << (double)a/N;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fir first
#define sec second
#define Mp make_pair
const int MAXN = 1e5 + 5;
const int MAXM = 1e5 + 5;
const int LB = 20 + 5;

struct Edge
{
	int next,to,c,w;
}e[MAXN<<1];
int head[MAXN],etot=0;
inline void add(int u,int v,int c,int w)
{
	e[++etot]=(Edge){ head[u],v,c,w};
	head[u]=etot;
}

int lb[MAXN];
int dep[MAXN],fa[MAXN][LB];
void lca_init(int u,int pre)
{
	for(int i=1; i<=lb[dep[u]]; ++i)
		fa[u][i] = fa[fa[u][i-1]][i-1];
	for(int i=head[u]; i; i=e[i].next)
	{
		int v=e[i].to;
		if(v==pre) continue;
		dep[v]=dep[u]+1; fa[v][0]=u;
		lca_init(v,u);
	}
}

int lca(int u,int v)
{
	if(dep[u]<dep[v]) swap(u,v);
	for(int i=lb[dep[u]]; dep[u]>dep[v]; --i)
		if(dep[fa[u][i]] >= dep[v])
			u=fa[u][i];
	if(u==v) return u;
	for(int i=lb[dep[u]]; fa[u][0]!=fa[v][0]; --i)
		if(fa[u][i] != fa[v][i])
			u=fa[u][i],
			v=fa[v][i];
	return fa[u][0];
}

struct Query
{
	int x,y,u,v;
	ll ans;
}q[MAXM];

vector<pii> id[MAXN];

ll sum[MAXN];
int cnt[MAXN];
void dfs(int u,int pre,ll dis)
{
	for(int i=0; i<(int)id[u].size(); ++i)
	{
		Query &now = q[id[u][i].fir];
		int k = id[u][i].sec;
		
		int x = now.x;
		ll y = now.y;
		now.ans += (dis - sum[x] + cnt[x]*y) * k;
	}
	
	for(int i=head[u]; i; i=e[i].next)
	{
		int v=e[i].to, c=e[i].c, w=e[i].w;
		if(v==pre) continue;
		
		sum[c]+=w; ++cnt[c];
		dfs(v,u,dis+w);
		sum[c]-=w; --cnt[c];
	}
}

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<n; ++i)
	{
		int u,v,c,w;
		scanf("%d%d%d%d",&u,&v,&c,&w);
		add(u,v,c,w);
		add(v,u,c,w);
	}
	
	for(int i=2; i<=n; ++i) lb[i]=lb[i>>1]+1;
	dep[0]=-1;
	lca_init(1,0);
	
	for(int i=1; i<=m; ++i)
	{
		int x,y,u,v;
		scanf("%d%d%d%d",&x,&y,&u,&v);
		q[i]=(Query){x,y,u,v,0};
		
		id[u].push_back(Mp(i,1));
		id[v].push_back(Mp(i,1));
		id[lca(u,v)].push_back(Mp(i,-2));
	}
	
	dfs(1,0,0);
	
	for(int i=1; i<=m; ++i)
		printf("%lld\n",q[i].ans);
	return 0;
}

Measured memory_bytes: 29816
from collections import Counter
n=int(input())
V=list(map(int, input().split()))
even=Counter(V[::2]).most_common(2)
odd=Counter(V[1::2]).most_common(2)
if even[0][0] != odd[0][0]:
    print(n-even[0][1]-odd[0][1])
else:
    if len(even) == 1 or len(odd) == 1: #most_commonの数が1
        print(n//2)
    else:
        print(n-max(even[0][1]+odd[1][1], even[1][1]+odd[0][1]))

Measured memory_bytes: 15588
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong

signed main(){
    int n,k;
    cin >> n >> k;
    if( int((n+1)/2) >= k ) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
S = input()

r = []
for i in range(len(S)):
    if S[i] == '0':
        r.append('0')
    elif S[i] == '1':
        r.append('1')
    elif S[i] == 'B':
        if len(r) > 0:
            r.pop(-1)

str_r = ""
for _r in r:
    str_r += _r

print(str_r)

Measured memory_bytes: 3060
n, m, q = gets.chomp.split(" ").map(&:to_i)
list = []
q.times do
  list << gets.chomp.split(" ").map(&:to_i)
end

max = 0
(1..m).to_a.repeated_combination(n) do |ar|
  calc = 0
  list.each do |a, b, c, d|
    calc += d if ar[b - 1] - ar[a - 1] == c
  end
  max = [max, calc].max
end

p max


Measured memory_bytes: 14692
#include<stdio.h>
 
int main(){
  int i,j,n;
  while(scanf("%d",&n)){
    if (n==0)
      break;
    int data[n+1][n+1];
    for (i=0;i<n;i++){
      int sum=0;
      for (j=0;j<n;j++){
        scanf("%d",&data[i][j]);
        sum+=data[i][j];
      }
      data[i][n]=sum;
    }
 
    for (i=0;i<n+1;i++){
      int sum=0;
      for (j=0;j<n;j++)
        sum+=data[j][i];
      data[n][i]=sum;
    }
 
    for (i=0;i<n+1;i++){
      for (j=0;j<n+1;j++)
        printf("%5d",data[i][j]);
      printf("\n");
    }
 
  }
 
  return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <vector>

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	
	vector<char> v;
	for (int i = 0; i < s.size(); ++i) v.push_back(s[i]);
	
	int res = 0;
	for (int i = 0; i < t.size(); ++i) {
		if (t[i] != s[i]) res++;
	} 
	
	cout << res << '\n';
	
	return 0;
}

Measured memory_bytes: 4104
// C program to compute sum of digits in 
// number. 
# include<iostream> 
using namespace std; 
/* Function to get sum of digits */

int main() 
{ 
  int n,cnt=0,k;
  cin>>n>>k;
  int d[n];
  long long sum=0;
  for(int i=0;i<n;i++)
  {
  	cin>>d[i];
  	if(d[i]>=k)
  		cnt++;
  }
 cout<<cnt;
return 0; 
} 


Measured memory_bytes: 640
package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

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

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}



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

//Prime Gap
public class Main{

	void run(){
		int N = 1299709;
		boolean[] p = new boolean[N+1];
		Arrays.fill(p, true);
		p[0]=p[1]=true;
		for(int i=2;i<=N;i++)if(p[i])for(int j=i+i;j<=N;j+=i)p[j]=false;
		Scanner sc = new Scanner(System.in);
		for(;;){
			int k = sc.nextInt();
			if(k==0)break;
			int l = k, r = k;
			while(!p[l])l--;
			while(!p[r])r++;
			System.out.println(r-l);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.close();

        if(a == 1) {
            System.out.println("YES");
            System.exit(0);
        }

        int tmpA = a;
        ArrayList<Integer> list = new ArrayList<>();
        for(int i=0; i<b; i++) {
            list.add(tmpA%b);
            tmpA += a;
        }

        if(list.contains(c)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    int a, b;
        cin >> a >> b;
    if(a>b)
        for(int i=0; i<a; i++)
            cout << b;
    else 
        for(int i=0; i<b; i++)
            cout << a;
    cout << endl;
}

Measured memory_bytes: 764
import sys
from collections import deque
from functools import lru_cache
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, K = read_values()
    P = [tuple(read_values()) for _ in range(N)]

    X = sorted([x for x, _ in P])
    Y = sorted([y for _, y in P])

    res = 10 ** 20
    for xl in range(N):
        for xr in range(xl + 1, N):
            for yl in range(N):
                for yr in range(yl + 1, N):
                    k = sum(X[xl] <= x <= X[xr] and Y[yl] <= y <= Y[yr] for x, y in P)
                    # print(f"X[{xl}, {xr}], Y[{yl}, {yr}] -> k:{k}")
                    if K <= k:
                        res = min(res, (X[xr] - X[xl]) * (Y[yr] - Y[yl]))
    print(res)



if __name__ == "__main__":
    main()



Measured memory_bytes: 71260