akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

double dist(const vector<int> &a, const vector<int> &b, int p) {
    int n = sz(a);
    if (p == 1) {
        double res = 0;
        rep(i, n) res += abs(a[i] - b[i]);
        return res;
    } else if (p == 2) {
        double res = 0;
        rep(i, n) res += pow(a[i] - b[i], 2);
        res = sqrt(res);
        return res;
    } else if (p == 3) {
        double res = 0;
        rep(i, n) res += pow(abs(a[i] - b[i]), 3);
        res = cbrt(res);
        return res;
    } else {
        double res = 0;
        rep(i, n) chmax(res, (double)abs(a[i] - b[i]));
        return res;
    }
}

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

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    cout << fixed << setprecision(15) << endl;
    cout << dist(a, b, 1) << endl;
    cout << dist(a, b, 2) << endl;
    cout << dist(a, b, 3) << endl;
    cout << dist(a, b, -1) << endl;    
}



Measured memory_bytes: 3508
def dfs(i,St,res):
    if i==3:
        if res == 7:
            print(St+"=7")
            exit()
        return

    dfs(i+1,St+'+'+S[i+1],res+int(S[i+1]))
    dfs(i+1,St+'-'+S[i+1],res-int(S[i+1]))

S=input()
dfs(0,S[0],int(S[0]))

Measured memory_bytes: 3060
N,M=map(int,input().split())
belong=list()
group=list()

def init(X):
  global belong
  global group
  belong=list(range(X))
  group=[[i] for i in range(X)]

def unite(x,y):
  if len(group[belong[x]])<len(group[belong[y]]):
    x,y=y,x
  if belong[x]==belong[y]:
    return True
  z=belong[y]
  for i in range(len(group[z])):
    belong[group[z][-1]]=belong[x]
    group[belong[x]].append(group[z][-1])
    del group[z][-1]
  return False

init(N)
a,b=0,0
for i in range(M):
  a,b=map(int,input().split())
  unite(a-1,b-1)
P=0
for i in range(N):
  if len(group[i]):
    P+=1
print(P-1)


Measured memory_bytes: 87256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repr(i, n, a) for (int i = (n)-1; i >= (a); i--)
#define repit(it, v) for (auto(it) = (v).begin(); (it) != (v).end(); (it)++)
#define sortt(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define co(x) cout << (x)
#define con(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define mkp make_pair
#define mkt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
// inline void fastio() { ios::sync_with_stdio(false), cin.tie(0); }
/******* Variable ***********************************/
const int maxn = 1e6 * 50;
const double inf = 0x3f3f3f3f3f;
const double pi = 3.141592653589;
/******* Function ***********************************/
/******* Main ****************************************/
void Main() {
  double r;
  cin >> r;
  cout << pi * r * r << " " << 2 * pi * r << endl;
}

/******* 笑顔!笑顔! ^_^ Smaile!Smaile! ^_^ ****************/
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: 3280
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;

     signed main(){
        int n,w,a,b;
        cin>>n>>w;
        map<int,int> mp,mp2;
        mp[0]=0;mp2[0]=0;
   for(int i=0;i<n;i++){
      cin>>a>>b;
   for(auto it=mp.begin();it!=mp.end();it++){
      mp2[it->first]=max(mp2[it->first],it->second);
      if(it->first + a<=w)mp2[it->first +a]=max(mp2[it->first +a],it->second +b);
     
   }
   mp.clear();
   swap(mp,mp2);
   }
   int ans=0;
     for(auto it=mp.begin();it!=mp.end();it++)ans=max(ans,it->second);
     cout<<ans<<endl;


      }

        


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    char s;
    cin >> s;
    if (s >= 'a' && s <= 'z') cout << "a" << endl;
    else cout << "A" << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0; i<(int)n; i++)
ll power(ll x,ll n);
bool isprime(ll n);


void test_case()
{
    int n,m,a,b;
    cin>>n>>m;
    vector<int> adj[n+1];
    while(m--) {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    priority_queue<pii,vector<pii>, greater<pii>> q;
    q.push({0,1});
    int d[n+1];
    int p[n+1];
    for(ll i=0;i<=n;i++)
        d[i]=INT_MAX;
    d[1]=0;
    while(!q.empty()) {
        int d_v=q.top().first;
        int v=q.top().second;
        q.pop();
        if(d_v!=d[v])
            continue;
        for(auto edge:adj[v]) {
            int to=edge;
            if(d[v]+1<d[to]) {
                d[to]=d[v]+1;
                p[to]=v;
                q.push({d[to],to});
            }
        }
    }
    for(ll i=2;i<=n;i++)
        if(d[i]==INT_MAX) {
            cout<<"No";
            return;
        }
    cout<<"Yes\n";
    for(ll i=2;i<=n;i++) {
        cout<<p[i]<<"\n";
    }

}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}
ll power(ll x,ll n)
{
    ll ans=1;
    while(n>0) {
        if(n&1)
            ans*=x;
        n>>=1;
        x*=x;
    }
    return ans;
}

bool isprime(ll n)
{
    if(n==2 || n==3)
        return true;
    if(n<=1 || n%2==0 || (n%6!=1 && n%6!=5))
        return false;
    for(ll i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true;
}


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

int N;
string s,t;

int main() {
    cin>>N>>s>>t;
    string ans(2*N,' ');
    for (int i=0; i<N; i++) {
        ans[2*i]=s[i];
        ans[2*i+1]=t[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#import <Foundation/Foundation.h>
int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}
// 昇順に並んだ values の中で searchValue を 左から探したときに初めて上回る(order>0) / 右から探したときに初めて下回る(order<0) ような index を探す（ない場合は -1 を返す）
int binary_search(int searchValue, int *values, int minIndex, int maxIndex, int order) {
    int midIndex = (minIndex + maxIndex) / 2;
    int midValue = values[midIndex];
    int maxValue = values[maxIndex];
    if (minIndex == midIndex) { // 区間の長さが2になったとき
        if (order > 0) {
            if (searchValue < midValue) { // 左がサーチ値を上回るなら左
                return midIndex;
            }
            if (searchValue < maxValue) { // 左がサーチ値以下かつ右がサーチ値を上回るなら右
                return maxIndex;
            }
        } else {
            if (searchValue > maxValue) { // 右がサーチ値を下回るなら右
                return maxIndex;
            }
            if (searchValue > midValue) { // 右がサーチ値以上かつ左がサーチ値を下回るなら左
                return midIndex;
            }
        }
        return -1; // 区間の長さが2のとき両端とも条件を満たさないなら存在しない
    }
    if (order > 0) {
        if (midValue <= searchValue) { // 中央での値がまだ上回っていないなら右半分
            return binary_search(searchValue, values, midIndex, maxIndex, order);
        } else {
            return binary_search(searchValue, values, minIndex, midIndex, order);
        }
    } else {
        if (midValue >= searchValue) { // 中央での値がまだ下回っていないなら左半分
            return binary_search(searchValue, values, minIndex, midIndex, order);
        } else {
            return binary_search(searchValue, values, midIndex, maxIndex, order);
        }
    }
}

int main() {
    int n;
    scanf("%d", &n);
    int *L = (int *)malloc(sizeof(int) * n);
    for (int i = 0; i < n; i++) scanf("%d", L + i);
    qsort(L, n, sizeof(int), asc);
    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            int a = L[i];
            int b = L[j];
            int k = binary_search(b - a + 1, L, 0, i - 1, -1);
            ans += i - 1 - k;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 7120
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int N=in.nextInt();
			int a=in.nextInt(),b=in.nextInt();
			int ac=in.nextInt();
			int bc[]=new int[N];
			for(int i=0;i<N;i++)
				bc[i]=in.nextInt();
			int cost=a;
			int cal=ac;
			int max=cal/cost;
			Arrays.sort(bc);
			for(int i=N-1;i>=0;i--)
			{
				cost+=b;
				cal+=bc[i];
				max=Math.max(max, cal/cost);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>

#define PRIME_MAX 1000000
int getprimes(int list[], int top){
    int i, j;
    int index = 0;
    char tmp[PRIME_MAX];

    for(i=0;i<top;i++) {
        tmp[i] = 1;
    }
   
    tmp[0] = tmp[1] = 0;
    for(i=2;i<top;i++) {
        if(tmp[i] == 1) {
            /* 素数 */
            list[index] = i;
            index ++;
            for(j=2;j*i<top;j++) {
                tmp[j*i] = 0;
            }
        }
    }

    list[index] = -1;
    return index;
}

int main(void) {
    int i, c;
    int n, base;
    int size;
    int primes[100000];
    int div[1000];
    int d;
    size = getprimes(primes, PRIME_MAX);
   
    while(scanf("%d\n", &base) == 1) {
        i = d = 0;
        n = base;
        while(n > 1) {
        	if((n % primes[i]) == 0) {
        		div[d] = primes[i];
        		n /= primes[i];
        		d++;
        	} else {
        		i++;
        	}
        	
        	if(i >= size) {
        		div[d] = n;
        		d++;
        		break;
        	}
        }
        
        printf("%d:", base);
        for(i=0;i<d;i++) {
        	printf(" %d", div[i]);
        }
        printf("\n");
    }
   
    return 0;
}

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

int main()
{
ll n ;
cin >> n ;
string s ;
cin >> s ;
if(n%2){
cout << "No" << endl;
return 0;
}
rep(i,n/2){
  if(s[i]!=s[i+n/2]){
    cout << "No" << endl;
    return 0;
  }
}
cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
# encoding: utf-8

# youtube解説動画による解法を実装する。

n = gets.to_i
$a = Array.new
for i in 0..n-1
  $a[i] = gets.to_i
end

# ascending order
$a.sort!

weight = Array.new(n)
signal1 = Array.new(n)
signal2 = Array.new(n)

# weight を作る
(0..n-1).each do |i|
  if i == 0 || i == n-1 then
    weight[i] = 1
  else
    weight[i] = 2
  end
end

# signal1 を作る
(0..n-1).each do |i|
  if i.odd? then
    signal1[i] = 1
  else
    signal1[i] = -1
  end
end

# signal2 を作る
(0..n-1).each do |i|
  if i.even? then
    signal2[i] = 1
  else
    signal2[i] = -1
  end
end

ws1 = Array.new(n)
ws2 = Array.new(n)

(0..n-1).each do |i|
  ws1[i] = weight[i] * signal1[i]
  ws2[i] = weight[i] * signal2[i]
end

ws1.sort!
ws2.sort!

ans1 = 0
ans2 = 0
for i in 0..n-1
  ans1 += ws1[i] * $a[i]
  ans2 += ws2[i] * $a[i]
end 

if ans1 >= ans2 then
  puts ans1
else
  puts ans2
end


Measured memory_bytes: 9432
#include<iostream>
using namespace std;
#define N 144
#define MAX 16
const int infty = 4096;

/*
 * ref: Spaghetti Source
 * weight minimum_steiner_tree(const vector<int> &T, const matrix * &g);
 */
int MinimumSteinerTree(int nt, int T[], int n, int G[][N]){
  if( nt <= 1 ) return 0;
  int d[n][n];

  for(int i=0;i<n;++i)
    for(int j=0;j<n;++j)
      d[i][j]=G[i][j];

  for(int k=0;k<n;++k)
    for(int i=0;i<n;++i)
      for(int j=0;j<n;++j)
	d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  
  const int space = 1<<nt;
  int dp[space][n];
  for(int s=0;s<space;++s)
    for(int x=0;x<n;++x)
      dp[s][x]=infty;

  // |S| = 2
  for(int p=0;p<nt;++p)
    for(int q=0;q<n;++q)
      dp[1<<p][q]=d[T[p]][q];
  
  /*
  for(int s=1;s<space;++s){
    if(!(s&(s-1)))continue;
    for(int p=0;p<n;++p)
      for(int e=0;e<s;++e)
	if((e|s)==s)
	  dp[s][p]=min(dp[s][p],dp[e][p]+dp[s-e][p]);
    for(int p=0;p<n;++p)
      for(int q=0;q<n;++q)
	dp[s][p]=min(dp[s][p],dp[s][q]+d[p][q]);
  }
  */
  // |S| >= 2
  for(int s=1;s<space;++s){
    for(int p=0;p<n;++p){
      int tmp = infty;
      for(int q=0;q<n;++q)
	for(int e=0;e<s;++e)
	  if((e|s)==s)
	    tmp = min(tmp,d[p][q]+dp[e][q]+dp[s-e][q]);
      dp[s][p]=min(dp[s][p],tmp);
    }
  }
  
  int ret=infty;
  for(int s=0;s<space;++s)
    for(int q=0;q<n;++q)
      ret=min(ret,dp[s][q]+dp[(space-1)-s][q]);

  return ret;
}

int main()
{
  while(true){
    int H,W;
    int M[MAX][MAX]={{0,},};
    int G[N][N];
    int numChoco=0;
    int T[MAX];
    cin >> H >> W;
    if(H==0&&W==0)break;
    
    for(int i=0;i<H;++i){
      for(int j=0;j<W;++j){
	cin>>M[i][j];
	if(M[i][j]==1){
	  T[numChoco++]=i*W+j;
	}
      }
    }

    const int di[] = {-1,0,1,0};
    const int dj[] = {0,1,0,-1};

    for(int i=0;i<H*W;++i){
      for(int j=0;j<H*W;++j){
	G[i][j]=infty;
      }
    }
    
    for(int i=0;i<H;++i){
      for(int j=0;j<W;++j){
	G[i*W+j][i*W+j]=0;
	for(int k=0;k<4;++k){
	  int ti=i+di[k];
	  int tj=j+dj[k];
	  if(0<=ti&&ti<H&&0<=tj&&tj<W){
	    G[i*W+j][ti*W+tj]=G[ti*W+tj][i*W+j]=1;
	  }
	}
      }
    }
    
    cout << H*W-(MinimumSteinerTree( numChoco, T, H*W, G )+1) << endl;

  }
  return 0;
}

Measured memory_bytes: 1064
#include <iostream>

using namespace std;

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

	if (H == 1 || W == 1) {
		cout << 1 << endl;
	}
	else {
		long long ans = (H * W + 1) / 2;
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase

def main():
    s = input().strip()
    if s[-1]=='s':
        print(s+'es')
    else:
        print(s+'s')
    
#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

Measured memory_bytes: 62592
a,b,c = gets.split.map(&:to_f)
r = c * Math::PI / 180
h = b * Math.sin(r)
s = a * h / 2
w = b * Math.cos(r)
d = Math.hypot(a-w,h)
l = a + b + d
puts [s,l,h] * "\n"

Measured memory_bytes: 6184
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()

d = []
for i in range(m-1):
    d.append(x[i+1] - x[i])
d.sort(reverse=True)

print((x[-1] - x[0]) - sum(d[:n-1]))


Measured memory_bytes: 57512
n = int(input())
h = list(map(int, input().split()))
t = 0
result = 0
for i in range(n - 1):
  if h[i + 1] <= h[i]:
    t += 1
  else:
    result = max(t, result)
    t = 0
result = max(t, result)
print(result)


Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <map>
#include <utility>
using namespace std;
map<pair<int,int>,string> mp;
string s[7]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
int main(){
	int cnt=3;
	for(int i=1;i<=12;i++){
		int days;
		if(i==2)	days=29;
		else if(i&1) 	days=(i<=7?31:30);
		else 		days=(i<=7?30:31);
		for(int j=1;j<=days;j++){
			mp[make_pair(i,j)]=s[cnt++];
			cnt%=7;
		}
	}
	int m,d;
	while(true){
		cin>>m>>d;
		if(m==0)	return 0;
		cout<<mp[make_pair(m,d)]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include "bits/stdc++.h"
using namespace std;
#define maxn 100001
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define pb push_back
#define mp make_pair

vector<pair<int,long long>> e[maxn];
int n, x, y, z;
int w[maxn], t[maxn];
long long c[maxn];
long long fa_side_sum[maxn];

long long fa_s(int v){
	return c[v] * (2 * min(w[v], n - w[v] - 1));
}
long long son_s(int v){
	return c[v] * (2 * min(w[v] - 1, n - w[v]));
}
long long diff_s(int v){
	return c[v] * (2 * min(w[v], n - w[v]) - 1);
}

void dfs(int u, int fa){
	for (auto p : e[u]){
		int v = p.first;
		if (v != fa){
			c[v] = p.second;
			dfs(v, u);
			// fa[v] = u
			// c[v] is length of v --> fa[v]
			//cout << v << ' ' << fa_s(v) << ' ' << son_s(v) << endl;
			fa_side_sum[u] += fa_side_sum[v];
			w[u] += w[v];
		}
	}
	w[u] ++;
	fa_side_sum[u] += fa_s(u);
	//cout << u << ' ' << w[u] << ' ' << c[u] << endl;
}

long long ans = 0;
void gao(int u, int fa, long long sum){
	//cout << '!' << u << ' ' << sum << endl;
	for (auto p : e[u]){
		int v = p.first;
		if (v != fa){
			// calc ans(v,u)
			long long tmp = sum - fa_s(v) + diff_s(v);
			ans = max(ans, tmp);
			//cout << v << ' ' << tmp << endl;
			gao(v, u, sum - fa_s(v) + son_s(v));
		}
	}
}

void solve(){
	cin >> n;
	rep(i, n - 1){
		cin >> x >> y >> z;
		e[x].pb(mp(y, z));
		e[y].pb(mp(x, z));
	}
	dfs(1, 0);
	gao(1, 0, fa_side_sum[1]);
	cout << ans;
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(0);
    solve();
}

Measured memory_bytes: 15232
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#define INF 999999999
#define lint long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define rep0(i, n) for(int i = 0; i < (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    lint A, B, C, D, E;
    cin >> A >> B >> C >> D;
    E = C*D/gcd(C,D);
    lint ableC = B / C - (A-1) / C;
    lint ableD = B / D - (A-1) / D;
    lint ableE = B / E - (A-1) / E;
    cout << (B-A+1)-(ableC+ableD-ableE);
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
	int n, k;
	cin >> n >> k;
	
	ll low = 0, high = 1e18;
	while(high-low>1) {
		ll mid = (high+low)/2, tmp = mid;
		//cout << high << " " << mid << " " << low << endl;
		bool flag = false;
		REP(i, n-1) {
			tmp -= (tmp-1)/k+1;
			if(tmp <= 0) flag = true;
		}
		if(flag) low = mid;
		else high = mid;
	}
	cout << low << endl;

	return 0;
}

Measured memory_bytes: 3096
n = int(input())
cnt = [0] * 10**5

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            cnt[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1

for i in range(1,n+1):
    print(cnt[i])

Measured memory_bytes: 69296
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner kbd = new Scanner(System.in);
        int n = kbd.nextInt();
        int[][] jwels = new int[n][2];
        for (int i = 0; i < n; i++) {
            // 価値
            jwels[i][0] = kbd.nextInt();
        }
        for (int k = 0; k < n; k++) {
            // コスト
            jwels[k][1] = kbd.nextInt();
        }
        int max = 0;
        for (int j = 0; j < n; j++) {
            if (jwels[j][0] > jwels[j][1]) {
                max = max + (jwels[j][0] - jwels[j][1]);
            }
        }
        System.out.println(max);
    }
}

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

using namespace std;

using ll = long long;
using ld = long double;
using li = __int128;
using uli = unsigned __int128;

#define fi first
#define se second

template <typename T> void s_min(T& a, T b) {
	if (a > b) a = b;
}

template <typename T> void s_max(T& a, T b) {
	if (a < b) a = b;
}

const ll INF = 1e18;

int main() {
	ios_base::sync_with_stdio(0);

	int N, W;
	cin >> N >> W;
	vector<int> w(N + 1), v(N + 1);
	for (int i = 1; i <= N; i++) cin >> w[i] >> v[i];
	const int V = 1000 * N;
	vector<vector<ll>> dp(N + 1, vector<ll> (V + 1, INF));
	dp[1][0] = 0;
	dp[1][v[1]] = w[1];
	for (int i = 2; i <= N; i++) {
		for (int j = 0; j <= V; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j < v[i]) continue;
			s_min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= V; i++) {
		if (dp[N][i] <= W) ans = i;
	}
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 83180
import java.util.*;

class Solver {
  private int[] count;
  
  Solver(String text) {
    count = new int[text.length() + 1];
    char[] textArray = text.toCharArray();
    count[0] = 0;
    count[1] = 0;
    for (int i = 1; i < text.length(); i++) {
      if (textArray[i-1] == 'A' && textArray[i] == 'C') {
        count[i+1] = count[i] + 1;
      } else {
        count[i+1] = count[i];
      }
//      System.out.println(count[i+1]);
    }
  }
  
  public int solve(int l, int r) {
    return count[r] - count[l];
  }
}

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    
    int n = s.nextInt();
    int q = s.nextInt();
    Solver solver = new Solver(s.next());
    for (int i = 0; i < q; i++) {
      int l = s.nextInt();
      int r = s.nextInt();
      System.out.println(solver.solve(l, r));
    }
  }
}



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

const int maxn = 1e5 + 5;
long long dp [maxn][3];

int main () {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> dp[i][j];
    }
  }
  for (int i = 1; i < n; i++) {
    dp[i][0] += max (dp[i - 1][1], dp[i - 1][2]);
    dp[i][1] += max (dp[i - 1][0], dp[i - 1][2]);
    dp[i][2] += max (dp[i - 1][0], dp[i - 1][1]);
  }
  cout << max ({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << '\n';
}

Measured memory_bytes: 2560
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
    }
}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return (fac[n]/(fac[k]*fac[n - k])) ;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  sort(ALL(v));
  ll ans=v[n-1];
  ll cnt=0;
  double tmp1=((double)v[n-1]/2);
  double tmp2=((double)v[n-1]/2);
  rep(i,n-1){
    if(tmp1>(double)abs(v[i]-tmp2)){
      tmp1=(double)abs(v[i]-tmp2);
      cnt=i;
    }
  }
  cout<<ans<<' '<<v[cnt]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
static const int INF = 1e+9+7;

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

  bool C = false;
  bool flag = false;
  if(S[0] == 'A'){
    flag = true;
    rep(i,1,sz(S)){
      if(i != 1 && i != sz(S)-1 && !C && S[i] == 'C') C = true;
      else if(S[i] >= 'A' && S[i] <= 'Z') flag = false;
    }
  }

  if(C && flag) print("AC");
  else print("WA");


  return 0;
}


Measured memory_bytes: 764
#include <stdio.h>

int n,s_i[1001];
long dp[1001][8]={0};
char s[1001];

long check(int m,int p){
    if(m>n) return 1;
    if(dp[m][p]) return dp[m][p]%10007;
    
    for(int i=1;i<8;i++){
        //  printf("%d %d\n",i,s_i[m]);
        if((i&s_i[m]) && (i&p))
            dp[m][p]+=check(m+1,i);
    }
    
    return dp[m][p];
}


int main(void){
    scanf("%d %s",&n,s);
    
    for(int i=1;i<=n;i++)
        switch(s[i-1]){
            case 'J' :
                s_i[i]=1; break;
            case 'O' :
                s_i[i]=2; break;
            case 'I' :
                s_i[i]=4; break;
        }
    
    printf("%ld\n",check(1,1)%10007);
    return 0;
    
}

Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a = Integer.parseInt(br.readLine());
		System.out.println((int)Math.pow(a, 3));
	}
}

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

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

#define ALL(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0, __##i##_length = (n); i < __##i##_length; i++)
#define rep_reverse(i, n) for (ll i = (n)-1; 0 < i; i--)
#define FOR(i, from, to)                                                       \
  for (ll i = (from), __##i##_end = (to); i < __##i##_end; i++)
#define FOR_REVERSE(i, from, to)                                               \
  for (ll i = (to)-1, __##i##_end = (from); __##i##_end <= i; i--)
#define foreach(e, v) for (const auto e : (v))
#define vfree(v) std::vector<int>().swap(v)
#define DEBUG(x) cout << #x << " = " << (x) << endl

using namespace std;
typedef int64_t ll;
typedef vector<ll> llv;
typedef vector<llv> llvv;

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  llv to_dot(n + 1, 0);
  llv to_sharp(n + 1, 0);
  rep(i, n) {
    if (s[i] == '#')
      to_dot[i + 1] = to_dot[i] + 1;
    else
      to_dot[i + 1] = to_dot[i];
  }
  rep_reverse(i, n) {
    if (s[i] == '.')
      to_sharp[i - 1] = to_sharp[i] + 1;
    else
      to_sharp[i - 1] = to_sharp[i];
  }
  ll min_change = n;
  rep(i, n) min_change = min(to_dot[i] + to_sharp[i], min_change);
  cout << min_change << endl;
  return 0;
}


Measured memory_bytes: 3716
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC162
{
    class MainClass
    {

        static int[] s;
        static long[,] g = new long[201, 201];
        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            long sum = 0;
            for (int i = 1; i <= s[0]; i++)
            {
                for (int j = 1; j <= s[0]; j++)
                {
                    for (int k = 1; k <= s[0]; k++)
                    {
                        sum += Gcd(i, Gcd(j, k));



                    }
                }
            }

            WriteLine(sum);
        }
        public static long Gcd(long a, long b)
        {
            if (g[a, b] != 0)
            {
                return g[a, b];
            }
            long tmp;
            // a<bにする
            if (a >= b)
            {
                tmp = a;
                a = b;
                b = tmp;
            }

            if (a == 0)
            {
                g[a, b] = b;
                return b;
            }

            tmp = a;
            a = b % a;
            b = tmp;
            g[a, b] = Gcd(a, b);
            return g[a, b];

        }
    }
}


Measured memory_bytes: 27976
<?php

$book = array();
while (($line = trim(fgets(STDIN))) !== '') {
    sscanf($line, '%s %d', $word, $n);
    if (!isset($book[$word])) {
        $book[$word] = array();
    }
    $book[$word][] = $n;
}

ksort($book);
foreach ($book as $word => $arr) {
    sort($arr);
    printf("%s\n%s\n", $word, implode(' ', $arr));
}

Measured memory_bytes: 6640
#include<bits/stdc++.h>
using namespace std;
main(){
    int N, ma, maxi;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
        cin >> vec[i];
    }
    maxi = 0;
    for(int i = 0; i < N - 1; i++){
        ma = 0;
        for(int j = i; j < N - 1; j++){
           if(vec[j] >= vec[j + 1]){
               ma++;
           if(ma > maxi){
               maxi = ma;
           }
           }
           else{break;}
        }
        if(maxi == N - i){break;}
    }
    cout << maxi << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 1270;

int main() {
    int n, m, r, q;
    while (cin >> n >> m && n){
        VVI a(m,VI(N));
        cin >> r;
        while (r--){
            int t, x, y, s;
            cin >> t >> x >> y >> s;
            y--;
            if (s == 0) a[y][t]--;
            else a[y][t]++;
        }
        REP(i,m) REP(j,N-1) a[i][j+1] += a[i][j];
        cin >> q;
        while (q--){
            int ans = 0;
            int ts, te, x;
            cin >> ts >> te >> x;
            x--;
            FOR(i,ts,te-1){
                if (a[x][i] > 0) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

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

main(){
    ll n;
    cin>>n;
    string s;
    while(n){
        ll p = n%26;
        if(p==0){
            s.push_back('z');
            n--;
        }
        else{
            char c = 'a' + p -1;
            s.push_back(c);
        }
        n/= 26;
    }
    reverse(s.begin(),s.end());
    cout<<s;
}

Measured memory_bytes: 3628
from collections import Counter
N,A = map(int, input().split())
X = list(map(int, input().split()))

"""
普通にやると最大で2**50通りなのでTLE
i枚選んだ時に合計がi*Aになる物を考えるとよい

"""

# 0枚からN枚まで選んで、合計値がkeyでその組み合わせの数がvalue
dp = [Counter() for _ in range(N+1)]
dp[0][0] = 1

for i, a in enumerate(X): # i番目のカードまで選べる
    for j in reversed(range(i+1)): # j枚選ぶとき（０～i枚の範囲）、逆順にしないと１枚目にX_iを選んで３枚目にもX_iを選ぶみたいな重複が発生するのでこれを回避するために逆順にする
        for k,v in dp[j].items(): # j枚選んだ時の合計値とその組み合わせの個数についてみていく
            dp[j+1][k+a] += v # j+1枚目としてi番目のカードを選ぶ時に合計がk+aになる個数は、j枚選んでｋになる個数と同じ（それぞれの場合にaを足してできる）

ans = 0
for i, C in enumerate(dp):
    if i >= 1:
        ans += C[i*A]
print(ans)

Measured memory_bytes: 5492
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
a = LIST()

max_a = max(a)
a.remove(max_a)
a.sort()

idx = bisect(a, max_a//2)
if len(a) == 1 or idx == 0:
	print(max_a, a[0])
elif idx == n-1:
	print(max_a, a[-1])
elif abs(a[idx-1]-max_a/2) >= abs(a[idx]-max_a/2):
	print(max_a, a[idx])
else:
	print(max_a, a[idx-1])


Measured memory_bytes: 16112
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    string s, srev;
    cin>>s;
    reverse_copy(s.begin(), s.end(), back_inserter(srev));
    stack<int> st, strev;
    int space = 0;
    int spacerev = 0;
    vector<int> cut, cutrev;
    rep(i, s.size()) {
        if (s[i] == '\\') st.push(i);
        else if (s[i] == '/' && !st.empty()) {
            int l = st.top(); st.pop();
            space += i - l;
            if (st.empty()) {
                cut.push_back(space);
                space = 0;
            }
        }

        if (srev[i] == '/') strev.push(i);
        else if (srev[i] == '\\' && !strev.empty()) {
            int l = strev.top(); strev.pop();
            spacerev += i - l;
            if (strev.empty()) {
                cutrev.push_back(spacerev);
                spacerev = 0;
            }
        }
    }
    if (space != 0) cut.push_back(space);
    if (spacerev != 0) cutrev.push_back(spacerev);

    int sum = accumulate(cut.begin(), cut.end(), 0);
    reverse(cutrev.begin(), cutrev.end());
    int cnt = 0;
    int ci = 0;
    int cri = 0;
    vector<int> ans = {0};
    space = 0; spacerev = 0;
    for (int i = 1; i < sum + 1; ++i) {
        if (space + cut[ci] == i && spacerev + cutrev[cri] == i) {
            space += cut[ci]; spacerev += cutrev[cri];
            ans.push_back(i);
            ci++; cri++; cnt++;
        }
        else if (space + cut[ci] == i) {
            space += cut[ci];
            ans.push_back(i);
            ci++; cnt++;
        }
        else if (spacerev + cutrev[cri] == i) {
            spacerev += cutrev[cri];
            ans.push_back(i);
            cri++; cnt++;
        }
    }

    cout<<sum<<endl;
    cout<<cnt;
    rep(i, ans.size() - 1) cout<<" "<<ans[i + 1] - ans[i];
    cout<<endl;
}


Measured memory_bytes: 3324
package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var S string
	var ans int = 700
	fmt.Scan(&S)
	strs := strings.Split(S, "")

	for i := 0; i < len(strs); i++ {
		if strs[i] == "o" {
			ans += 100
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) > abs(a[j]) }


Measured memory_bytes: 640
import sys
import numpy as np 

c = np.array(sys.stdin.read().split(), dtype=np.int8).reshape(3, 3)

def main(c):
    c -= c[0]
    c -= c[:, 0][:, None]
    return 'No' if np.count_nonzero(c) else 'Yes'

if __name__ == '__main__':
    ans = main(c)
    print(ans)

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

vector<int> a(50), b(50), c(50), d(50);
vector<ll> arr;
int n, m, q;
int ans = 0;

void cal_score() {
  int t = 0;
  REP(i, q) {
    if (arr[b[i] - 1] - arr[a[i] - 1] == c[i]) t += d[i];
  }
  ans = max(ans, t);
}


void dfs(vector<ll> &a) {
  if (a.size() == n) {
    //処理
    //DEBUGS(a);
    cal_score();
    return;
  }
  ll s;
  if (arr.empty()) s = 0;
  else
    s = arr[arr.size() - 1];
  for (ll i = s; i < m; i++) {
    a.push_back(i);
    dfs(a);
    a.pop_back();
  }
}

int main() {
  cin >> n >> m >> q;
  REP(i, q) { cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i); }

  dfs(arr);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
n, k = gets.chomp.split.map(&:to_i)
d = gets.chomp.split.map(&:to_i)

zero = d.include?(0)

usable = (1..9).to_a.select{|e| !d.include?(e) }
usable.push(0)

ans = 10 ** 9
usable.repeated_permutation(5) do |a|
  num = "#{a[0]}#{a[1]}#{a[2]}#{a[3]}#{a[4]}".to_i
  next if zero && num.to_s =~ /0/
  next unless num >= n
  ans = num if ans > num
end
p ans


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

#define REP(i,n) for(int i=0;i<n;i++)
using ld=long double;

int v[4];
ld n,dp[301][301][301];
ld f(int a,int b,int c){
  if(dp[a][b][c]>=0)return dp[a][b][c];
  ld res=0,z=n-a-b-c;
  if(a)res+=a*f(a-1,b,c);
  if(b)res+=b*f(a+1,b-1,c);
  if(c)res+=c*f(a,b+1,c-1);
  res*=1/(n-z);
  res+=(a+b+c)*n/((n-z)*(n-z));
  return dp[a][b][c]=res;
}

int main(){
  cin>>n;
  REP(i,n-0.1){int x;cin>>x;v[x]++;}
  REP(i,301)REP(j,301)REP(k,301)dp[i][j][k]=-1;
  dp[0][0][0]=0;
  cout<<fixed<<setprecision(12)<<f(v[1],v[2],v[3])<<endl;
}

Measured memory_bytes: 426496
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,cnt=1,ans=1; cin>>n;
    vector<int> p(n,0),pos(n+1,0);
    rep(i,n){
        cin>>p[i];
        pos[p[i]]=i;
    }
    for(int i=1;i<n;i++){
        if(pos[i]<pos[i+1]) cnt++;
        else cnt=1;
        ans=max(ans,cnt);
    }
    cout<<n-ans<<endl;
}

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

int main(){
  int n; cin >> n;
  vector<int> p; p.resize(n);
  for(int i=0; i<n; i++) cin >> p[i];
  
  int count = 0;
  for(int i=0; i<n-2; i++){
    vector<int> v = {p[i], p[i+1], p[i+2]}; sort(v.begin(), v.end());
    if(v[1] == p[i+1]) count++;
  }
  cout << count << "\n";
} 

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

int main()
{
  string s;
  bool odd_step=true, even_step=true;
  cin >> s;
  for(int i=0; i<s.size(); i+=2)
  {
    if(s[i]=='L')
    {
      even_step = false;
      break;
    }
  }
  for(int i=1; i<s.size(); i+=2)
  {
    if(s[i]=='R')
    {
      odd_step = false;
      break;
    }
  }
  
  cout << (odd_step && even_step ? "Yes" : "No") << endl;
  return 0;
}

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

using namespace std;

int main() {
  int N, Q;
  cin >> N >> Q;
  
  string S;
  cin >> S;
  
  vector<int> s(N+1, 0);
  
  for (int i = 1; i < N; i++) {
    if (S.at(i-1) == 'A' && S.at(i) == 'C') {
      s[i+1] = s[i] + 1;
    } else {
      s[i+1] = s[i];
    }
  }
  
  for(int i = 0; i < Q; i++) { 
    int l, r;
    cin >> l >> r;
    
    if (l == 1) {
      cout << s[r] << endl;
    } else if (S.at(l-2) =='A' && S.at(l-1) == 'C') {
      cout << s[r] - s[l-1] - 1 << endl;
    } else {
      cout << s[r] - s[l-1] << endl;
    }
  }
}

Measured memory_bytes: 1408
S = input()

N = len(S)
S_list = [i for i in S]
check = 0

S_0 = S_list
for i in range(len(S_0)//2):
    if S_0[i] != S_0[-(i+1)]:
        check = 1

S_1 = S_list[:(N-1)//2]
for i in range(len(S_1)//2+1):
    if S_1[i] != S_1[-(i+1)]:
        check = 1

S_2 = S_list[(N+3)//2-1:]
for i in range(len(S_2)//2+1):
    if S_2[i] != S_2[-(i+1)]:
        check = 1

if check == 0:
    print('Yes')
else:
    print('No')


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

#define ll long long

using namespace std;

const int N = 2e5 + 123, MAXN = 1e9;

int n;

ll h[N], a[N], dp[N], ans, L[N * 40], R[N  *40], sz = 1, t[N * 40];

void upd (int pos, ll val, int v = 1, int tl = 1, int tr = MAXN) {
    if (tl == tr) {
        t[v] = max (val, t[v]);
        return;
    }int tm = (tl + tr) >> 1;
    if (pos <= tm) {
        if (!L[v])L[v] = ++ sz;
        upd (pos, val, L[v], tl, tm);
    }else {
        if (!R[v])R[v] = ++ sz;
        upd (pos, val, R[v], tm + 1, tr);
    }
    t[v] = max (t[L[v]], t[R[v]]);
}

ll get (int l, int r, int v = 1, int tl = 1, int tr = MAXN) {
    if (tl > r || l > tr || !v) return 0;
    if (tl >= l && r >= tr)return t[v];
    int tm = (tl + tr) >> 1;
    return max (get (l, r, L[v], tl, tm), get (l, r, R[v], tm + 1, tr));
}

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        cin >> h[i];
    }
    for (int i = 1;i <= n;i ++) {
        cin >> a[i];
    }
    for (int i = 1;i <= n;i ++) {
        dp[i] = get (1, h[i] - 1) + a[i];
        upd (h[i], dp[i]);
        ans = max (ans, dp[i]);
    }
    cout << ans;
}


Measured memory_bytes: 20480
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int k = in.nextInt();
        int a[] = new int[n];
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        long sum=0L;
        for(int i=0;i<n-k;i++) sum+=a[i];
        out.println(sum);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 57820
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    string s; cin >> s;
    int a = (s[0] - '0') * 10 + (s[1] - '0');
    int b = (s[2] - '0') * 10 + (s[3] - '0');
    //monthが成り立つ
    bool YYMM = (1 <= b && b <= 12);
    bool MMYY = (1 <= a && a <= 12);
    if (YYMM) {
        if (MMYY) puts("AMBIGUOUS"); //A and B
        else puts("YYMM"); //A \ B
    } else {
        if (MMYY) puts("MMYY"); //B \ A
        else puts("NA"); // !(A or B)
    }
}


Measured memory_bytes: 256