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

#define COUT(x) cout << #x << " = " << (x) << ", "
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
typedef long long ll;
const int MOD = 1000000007;

int main(){
  ll N,C; cin >> N >> C;
  vector<vector<int>> vec(30, vector<int>(100010, 0));
  for(int i = 0; i < N; i++){
    int s,t,c;
    cin >> s >> t >> c;
    c--;
    vec[c][s]++;
    vec[c][t+1]--;
  }
  for(int i = 0; i < C; i++){
    for(int j = 1; j < 100010; j++){
      vec[i][j] += vec[i][j-1];
    }
  }

  int res = 0;
  for(int i = 0; i < 100010; i++){
    int tmp = 0;
    for(int j = 0; j < C; j++){
      if(vec[j][i] > 0){
	tmp++;
      }
    }
    if(tmp > res) res = tmp;
  }
  cout << res << endl;
}


Measured memory_bytes: 12416
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY puts("Yes")
#define NN puts("No")
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  int n,k;
  cin >> n >> k;
  cout << n % k << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a)
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {
    ll n;
    cin >> n;
    ll a[n];
    bool flag=0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i]%2==0){
            if(a[i]%3!=0&&a[i]%5!=0){
                flag=1;
            }
        }
    }
    if(flag==0) puts("APPROVED");
    else puts("DENIED");
	return 0;
}

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

using namespace std;

int main(){
    int n;
    long long int sum=0,ansp=0,ansm=0;
    cin >> n;
    vector<long long int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }

    for(int i=0;i<n;i++){
        if(i%2==0){
            sum += a[i];
            if(0<=sum){
                ansm += sum+1;
                sum =-1;
            }
        }else{
            sum += a[i];
            if(sum<=0){
                ansm += -sum+1;
                sum = 1;
            }
        }
    }

    sum=0;

    for(int i=0;i<n;i++){
        if(i%2==1){
            sum += a[i];
            if(0<=sum){
                ansp += sum+1;
                sum =-1;
            }
        }else{
            sum += a[i];
            if(sum<=0){
                ansp += -sum+1;
                sum = 1;
            }
        }
    }

    cout << min(ansp,ansm) << endl;
}

Measured memory_bytes: 1024
n = int(input()) - 1

def Base_10_to_n(x, n):
    tmp = x
    out = []
    while tmp>0:
        out.append(tmp % n)
        tmp = tmp // n 
    return out

keta = 1
tmp = 26
while tmp <= n:
    keta += 1
    tmp += 26**keta

n -= (tmp - 26**keta)

ans = []
for i in Base_10_to_n(n,26):
    ans.append(chr(ord('a')+i))
while keta!=len(ans):
    ans += ['a']
print("".join(reversed(ans)))

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n,res=0;
	cin>>n;
	for(ll i=1;i<=n;i++){
		ll x;
		cin>>x;
		if(x%2==1&&i%2==1)
		res++;
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
	solve();
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
using namespace std;
string s, t;
int n;
int main() {
	cin>>s>>t;
	n = s.size();
	for(int i=0; i<n; i++) {
		rotate(s.begin(), s.begin()+1, s.end());
		if(s==t) {cout<<"Yes"; return 0;}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
from collections import deque

def bfs(i):
    d[i] = 0
    q = deque()
    q.append(i)
    c = 1
    while True:
        if c == n:
            break
        p = q.popleft()
        c += 1
        h = G[p]
        for j in range(len(h)):
            if d[h[j]] == -1:
                q.append(h[j])
                v = w[p]
                d[h[j]] = d[p] + v[j]

n = int(input())
G = ["-1"] * n
w = ["-1"] * n
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    if G[a - 1] == "-1":
        G[a - 1] = [b - 1]
        w[a - 1] = [c]
    else:
        G[a - 1].append(b - 1)
        w[a - 1].append(c)
    if G[b - 1] == "-1":
        G[b - 1] = [a - 1]
        w[b - 1] = [c]
    else:
        G[b - 1].append(a - 1)
        w[b - 1].append(c)

q, k = map(int, input().split())
d = [-1] * n
bfs(k - 1)
for _ in range(q):
    x, y = map(int, input().split())
    print(d[x - 1] + d[y - 1])

Measured memory_bytes: 42764
program main
	implicit none
    integer(8)::k,s,ksmin,i,ans,j
    ans=0
    read(*,*)k,s
    ksmin=min(k,s)
    do i=0,ksmin
    	do j=0,min(s-i,k)
        	if(s-i-j<=k .and. 0<=s-i-j)then
            	ans=ans+1
            end if
        end do
    end do
    
    write(*,*) ans
    stop
end program main
    

Measured memory_bytes: 2776
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int h, w;
int sx, sy;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
bool used[21][21];
int color[21][21];

void dfs(int x, int y){
		for(int i = 0; i < 4; i++){
				int nx = x + dx[i];
				int ny = y + dy[i];
				if(nx >= 0 && nx < h && ny >= 0 && ny < w && !used[nx][ny] && color[nx][ny] == 1){
						used[nx][ny] = true;
						dfs(nx, ny);
				}
		}
}

int main(int argc, char const* argv[])
{
	while(true){
			cin >> w >> h;
			if(w == 0)break;
			for(int i = 0; i < h; i++){
					string s;
					cin >> s;
					for(int j = 0; j < w; j++){
							if(s[j] == '.' || s[j] == '@')color[i][j] = 1;
							else color[i][j] = -1;
							if(s[j] == '@'){
									sx = i; sy = j;
							}
							used[i][j] = false;
					}
			}
			dfs(sx, sy);
			int res = 0;
			used[sx][sy] = true;
			for(int i = 0; i < h; i++){
					for(int j = 0; j < w; j++){
							if(used[i][j] == 1)res++;
					}
			}
			cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=555555,mod=200003,g=2;
const double pi=3.141592653589793238;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
inline int qmo(int x){return x+(x>>31)*mod;}
inline int qpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod;
	return ans;
}
struct comp{
	double x,y;
	comp(double xx=0,double yy=0):x(xx),y(yy){}
	comp operator+(const comp &c)const{return comp(x+c.x,y+c.y);}
	comp operator-(const comp &c)const{return comp(x-c.x,y-c.y);}
	comp operator*(const comp &c)const{return comp(x*c.x-y*c.y,x*c.y+y*c.x);}
}A[maxn],Wn[maxn];
int n,a[maxn],id[maxn],pw[maxn],cnt[maxn],lim,l,rev[maxn];
ll cnt2[maxn],ans;
void init(){
	int pr=1;
	FOR(i,0,mod-1){
		id[pr]=i;
		pw[i]=pr;
		pr=1ll*pr*g%mod;
	}
}
void init(int upr){
	for(lim=1,l=0;lim<upr;lim<<=1,l++);
	FOR(i,0,lim-1) rev[i]=(rev[i>>1]>>1)|((i&1)<<(l-1));
	for(int i=1;i<lim;i<<=1) FOR(k,0,i-1) Wn[i+k]=comp(cos(pi/i*k),sin(pi/i*k));
}
void DFT(comp *A){
	FOR(i,0,lim-1) if(i<rev[i]) swap(A[i],A[rev[i]]);
	for(int i=1;i<lim;i<<=1){
//		comp Wn(cos(pi/i),sin(pi/i));
//		printf("Wn=(%.5lf,%.5lf)\n",Wn.x,Wn.y);
		for(int j=0;j<lim;j+=i<<1){
//			comp w(1,0);
			FOR(k,0,i-1){
				comp x=A[j+k],y=A[i+j+k]*Wn[i+k];
//				comp x=A[j+k],y=A[i+j+k]*w;
				A[j+k]=x+y;A[i+j+k]=x-y;
//				w=w*Wn;
			}
		}
	}
}
void IDFT(comp *A){
	DFT(A);
	reverse(A+1,A+lim);
	FOR(i,0,lim-1) A[i].x/=lim;
}
int main(){
	init();
	n=read();
	FOR(i,1,n){
		a[i]=read();
		if(a[i]) cnt[id[a[i]]]++;
	}
	FOR(i,0,mod-1) A[i].x=cnt[i];
	init(mod*2);
	DFT(A);
	FOR(i,0,lim-1) A[i]=A[i]*A[i];
	IDFT(A); 
	FOR(i,0,lim-1) cnt2[i%(mod-1)]+=ll(A[i].x+0.5);
	FOR(i,0,mod-1) ans+=cnt2[i]*pw[i];
	FOR(i,1,n) ans-=1ll*a[i]*a[i]%mod;
	ans/=2;
//	FOR(i,0,mod-1) if(cnt2[i]) printf("%d\n",pw[i]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 28132
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  priority_queue<ll> que;
  rep(i, n) {
    ll h;
    cin >> h;
    que.push(h);
  }
  for (int i = 0; i < min(k, n); i++) {
    que.pop();
  }
  ll s = 0;
  while (!que.empty()) {
    ll x = que.top();
    que.pop();
    s += x;
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 2420
N = int(input())
S = str(input())
max = 0
list_S = list(S)
for i in range(N-1):
    X = list_S[:i]
    Y = list_S[-(len(list_S)-i):]
    result = set(X) & set(Y)
    if max < len(result):
        max = len(result)
print(max)

Measured memory_bytes: 3060
while True:
    s = input().split()
    a = int(s[0])
    op = s[1]
    b = int(s[2])
    if op == "?":
        break
    
    if op == "+":
        print(a+b)
    if op == "-":
        print(a-b)
    if op == "*":
        print(a*b)
    if op == "/":
        print(a//b)


Measured memory_bytes: 5596
import sys
def main():
    input = sys.stdin.readline
    n = int(input())
    Vs = list(map(int, input().split()))
    #print(Vs)
    Vs_sorted = sorted(Vs)

    for i in range(n):
        #print(Vs_sorted)
        x = Vs_sorted[0]
        y = Vs_sorted[1]
        z = (x + y) / 2
        Vs_sorted.pop(0)
        Vs_sorted.pop(0)
        Vs_sorted.append(z)
        Vs_sorted.sort()
        if len(Vs_sorted) == 1:
          break

    print(Vs_sorted[0])
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b) f(i,0,n){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

/*****************************************************************************/


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

	int n, m;
	cin >> n >> m;
	vi p(100000), y(100000);
	vvi y_num(100001);
	f(i, 0, m) {
		cin >> p[i] >> y[i];
		y_num[p[i]].push_back(y[i]);
	}
	f(i, 0, n) {
		sort(all(y_num[i + 1]));
	}
	f(i, 0, m) {
		cout << setw(6) << setfill('0') << p[i];
		cout << setw(6) << setfill('0') << LL(lower_bound(all(y_num[p[i]]), y[i]) - y_num[p[i]].begin() + 1);
		cout << endl;
	}
	return 0;
}

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

using namespace std;

#define int long long

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

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

    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    int l = lcm(n, m);
    
    int step = lcm(l / n, l / m);
    for (int i = 0; i < l; i += step) {
        if (s[i / (l / n)] != t[i / (l / m)]) {
            cout << "-1\n";
            exit(0);
        }
    }

    cout << l << '\n';
    return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
vector<int> vec[4];

int main(int argc, char const* argv[])
{
  int w, h, n;
  cin >> w >> h >> n;
  for(int i = 0; i < n; i++){
    int x, y, a;
    cin >> x >> y >> a;
    a--;
    if(a == 0 || a == 1)vec[a].pb(x);
    else vec[a].pb(y);
  }
  int xl = 0;
  for(int x: vec[0]){
    xl = max(xl, x);
  }
  int xr = w;
  for(int x: vec[1]){
    xr = min(xr, x);
  }
  int yu = h;
  for(int y: vec[3]){
    yu = min(yu, y);
  }
  int yl = 0;
  for(int y: vec[2]){
    yl = max(yl, y);
  }
  if(xl >= xr || yu <= yl){
    cout << 0 << endl;
  }else{
    cout << (xr - xl) * (yu - yl) << endl;
  }
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    while (in.hasNext()){
      long N = in.nextInt();
      
      if (N % 2 == 0){
        System.out.println(N);
      } else {
        System.out.println(2 * N);
      }
    }
  }
}

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

int main() {
  string squares;
  int marblesCount;

  cin >> squares;

  for (int i = 0; i < squares.size(); i++) {
    if (squares[i] == '1') {
      marblesCount++;
    }
  }

  cout << marblesCount << endl;

  return 0;
}


Measured memory_bytes: 256
use itertools::iproduct;
use proconio::{input, marker::Chars};

fn main() {
    input!(h: usize, w: usize, k: usize, g: [Chars; h]);
    println!(
        "{}",
        iproduct!(0..1 << h, 0..1 << w)
            .filter(|&(bs, cs)| {
                iproduct!(
                    (0..h).filter(|&i| bs >> i & 1 == 1),
                    (0..w).filter(|&j| cs >> j & 1 == 1)
                )
                .filter(|&(i, j)| g[i][j] == '#')
                .count()
                    == k
            })
            .count()
    );
}


Measured memory_bytes: 2152
def p_xy(x,y):
  ansl.append(f"{x} {y}")

n=int(input())
a=list(map(int,input().split()))
mina=min(a)
maxa=max(a)
powa= maxa if abs(mina)<abs(maxa) else mina
powa_i=a.index(powa)
ansl=[]
if powa<0:
  for i in range(n):
    if a[i]>0:
      p_xy(powa_i+1,i+1)
  for i in reversed(range(1,n)):
      p_xy(i+1,i)
else:
  for i in range(n):
    if a[i]<0:
      p_xy(powa_i+1,i+1)
  for i in range(1,n):
    p_xy(i,i+1)
print(len(ansl))
print("\n".join(ansl))

Measured memory_bytes: 9248
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;

int main()
{
    int n, m;
    cin >> n >> m;
    Graph G(n);
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    s--, t--;

    // BFSして、二次元dpする。
    vector<vector<int>> dp(n, vector<int>(3, -1));
    queue<int> que;
    que.push(s);
    dp[s][0] = 0;
    while (!que.empty())
    {
        int v = que.front();
        que.pop();
        for (auto nv : G[v])
        {
            for (int j = 0; j < 3; j++)
            {
                if (dp[v][j] != -1 && dp[nv][(j + 1) % 3] == -1)
                {
                    que.push(nv);
                    dp[nv][(j + 1) % 3] = dp[v][j] + 1;
                }
            }
        }
    }
    if (dp[t][0] == -1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << dp[t][0] / 3 << endl;
    }

    return 0;
}


Measured memory_bytes: 11136
#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)

using ll = long long;
#define INF 1e9

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  int cnt = 0;
  REP(i, N){
    cin >> p[i];
    if(p[i] != i+1){
      cnt++;
    }
  }
  if(cnt <= 2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}


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

#define BUF_SIZE 1003
#define LEN_MAX 1000
#define ROW_MAX LEN_MAX+2
#define COL_MAX LEN_MAX+2

#define DIR_CNT 4
int next_dir4[DIR_CNT][2] = {
  {-1, 0},
  {0, -1},
  {0, 1},
  {1, 0},
};

void get_int2(char *line, int size, int *a1, int *a2) {
  if(!fgets(line, size, stdin)) return;
  sscanf(line, "%d %d", a1, a2);
}

enum {
  FREE = '.',
  WALL = '#'
};

struct point {
  int x;
  int y;
  int dist;
};

static struct point stack[LEN_MAX*LEN_MAX];
static int start = 0;
static int end = 0;

int is_empty(void) {
  return start == end;
}

void enqueue(struct point p) {
  stack[start++] = p;
}

struct point dequeue(void) {
  return stack[end++];
}

int main(void) {
  char line[BUF_SIZE];
  static char map[ROW_MAX][COL_MAX];
  int i, j;
  int row, col;
  get_int2(line, BUF_SIZE, &row, &col);
  int checked = 0;
  for(i = 1; i <= row; i++) {
    if(!fgets(line, BUF_SIZE, stdin)) return 0;
    for(j = 1; j <= col; j++) {
      map[i][j] = (line[j-1] == FREE);
      if(!map[i][j]) {
        struct point p = {i, j, 0};
        enqueue(p);
        checked++;
      }
    }
  }
  int cnt = (row*col);

  while(!is_empty()) {
    struct point p = dequeue();
    for(i = 0; i < DIR_CNT; i++) {
      int next_x = p.x + next_dir4[i][0];
      int next_y = p.y + next_dir4[i][1];
      if(!map[next_x][next_y]) continue;
      struct point np = {next_x, next_y, p.dist + 1};
      enqueue(np);
      map[next_x][next_y] = 0;
      checked++;
      if(checked == cnt) { // if all covered, early return
        printf("%d\n", np.dist);
        return 0;
      }
    }
  }

  printf("%d\n", 0);
  return 0;
}

Measured memory_bytes: 12928
sa = input()
sb = input()
sc = input()

def fun(a, b, c, x):
    if x == "a":
        temp = a
    elif x == "b":
        temp = b
    else:
        temp = c

    if len(temp) == 0:
        return x
    key = temp[0]
    temp = temp[1:len(temp)+1]
    if x == "a":
        a = temp
    elif x == "b":
        b = temp
    else:
        c = temp
    return fun(a, b, c, key)

print(fun(sa, sb, sc, "a").upper())

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const ll inf = 1LL << 62;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> x(N), y(N);
    Rep (i, N) {
        cin >> x[i] >> y[i];
    }

    ll ans = inf;
    Rep (i, N) {
        ll left = x[i];
        Rep (j, N) {
            ll right = x[j];
            Rep (k, N) {
                ll up = y[k];
                Rep (l, N) {
                    ll down = y[l];
                    ll cnt = 0;
                    Rep (m, N) {
                        if (left <= x[m] && x[m] <= right && down <= y[m] && y[m] <= up) cnt++;
                    }
                    if (cnt >= K) chmin(ans, (right - left) * (up - down));
                }
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, R;
    cin >> N >> R;

    cout << R + max(0, 100 * (10 - N)) << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-12;

int total_nights;
double mistake_probability,reference_diff,optimal_sleep_time;

double dfs(double R,double L,int count){
  double H = (R+L)/2.0;
  if(count >= total_nights){
    if(fabs(optimal_sleep_time - H) <= reference_diff + EPS){
      return 1.0;
    }
    else {
      return 0.0;
    }
  }

  if(L <= optimal_sleep_time + reference_diff
     && optimal_sleep_time - reference_diff <= R){
    return 1.0;
  }

  if(optimal_sleep_time + reference_diff < R
     || L < optimal_sleep_time - reference_diff){
    return 0.0;
  }

  double res = 0.0;

  if(H + EPS >= optimal_sleep_time){
    res += (1.0-mistake_probability) * dfs(R,H,count+1); //correct
    res += mistake_probability * dfs(H,L,count+1); //wrong
  }
  else{
    res += (1.0-mistake_probability) * dfs(H,L,count+1); //correct
    res += mistake_probability * dfs(R,H,count+1); //wrong
  }
  return res;
}

int main(){

  int R,L;
  while(~scanf("%d %d %d",&total_nights,&R,&L)){
    scanf("%lf %lf %lf",&mistake_probability,&reference_diff,&optimal_sleep_time);
    printf("%.9lf\n",dfs(R,L,0));
  }
}

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

int main(){
    int i = 0;
    int x[10000];
    while(true){
        cin >> x[i];
        if(x[i] == 0)
            break;
        i++;
    }
    for(int j = 0; j < i; j++){
        cout << "Case " << j + 1 << ": " << x[j] << endl;
    }
}


Measured memory_bytes: 3128
N = gets.to_i
Xs, Ys = readlines.map{|l| l.split.map(&:to_i)}.transpose

require 'set'

@p = Array.new(N + 1, -1)

def root(x)
  @p[x] < 0 ? x : @p[x] = root(@p[x])
end

def unite(x, y)
  x, y = root(x), root(y)
  if x != y
    x, y = y, x if @p[y] < @p[x]
    @p[x] += @p[y]
    @p[y] = x
  end
end

hx, hy = {}, {}
Xs.zip(Ys, [*0 ... N]) do |x, y, i|
  unite(i, hx[x]) if hx[x]
  hx[x] = i
  unite(i, hy[y]) if hy[y]
  hy[y] = i
end
sx, sy = Array.new(N){Set.new}, Array.new(N){Set.new}
N.times do |i|
  sx[root(i)] << Xs[i]
  sy[root(i)] << Ys[i]
end
puts  N.times.inject(0){|s, i| s + sx[i].size * sy[i].size} - N

Measured memory_bytes: 83188
n = int(input())
alist = list(map(int, input().split()))

alist.sort()

y = alist[0]

res = float('INF')

if y == alist[-1]:
    print(0)
    exit(0)

for i in range(y, alist[-1] + 1):
    cost = 0
    for a in alist:
        cost += (a - i)**2
    # print('rescos', res, cost)
    res = min(res, cost)
    if cost > res:
        break

print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
signed main(){
	int n;
	string s;
	cin>>s;
	n = s.size();
	for(int i=0;i<n;i++){
		if(i%2==0 && s[i]=='L'){
			cout<<"No"<<endl;
			return 0;
		}
		if(i%2==1 && s[i]=='R'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
long i,sum=0,k, x, max, mini;

cin>> k >> x;
max=x;
mini=x;
for (i=1;i<=k;i++)
{
sum+=x;
if (x<mini)
{
mini=x;
}
if (x>max)
{
max=x;
}
cin >> x;
}
cout << mini << " " << max << " " << sum<< endl;
return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;

int x3, x4, y3, y4;

void result() {
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

int main()
{
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int hen;
  int x = x2 - x1;
  int y = y2 - y1;
  hen = abs(x2-x1) * abs(x2-x1) + abs(y2-y1) * abs(y2-y1);
  hen = pow(hen, 0.5);

  x3 = x2 - y;
  x4 = x1 - y;
  y3 = y2 + x;
  y4 = y1 + x;

  result();







}

Measured memory_bytes: 256
s=input().split()
n=int(s[0])
m=int(s[1])
l=[[] for i in range(100000)]
d=[{} for i in range(100000)]
inp=[]
for i in range(m):
    s=input().split()
    p=int(s[0])
    y=int(s[1])
    inp.append((p,y))
    l[p-1].append(y)
for i in range(100000):
    l[i].sort()
for i in range(100000):
    cnt=1
    for j in l[i]:
        d[i][j]=cnt
        cnt+=1
for pa in inp:
    L=pa[0]
    R=d[L-1][pa[1]]
    L=str(L)
    R=str(R)
    for i in range(6-len(L)):
        print("0",end="")
    print(L,end="")
    for i in range(6-len(R)):
        print("0",end="")
    print(R)


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

int main()
{
  int D,L;
  int cnt = 0;

  cin >> D >> L;

  if(D % L == 0)
    {
      cnt = D/L;
    }
  else
    {
      cnt = D/L + D%L;
    }
  cout << cnt << endl;
}



Measured memory_bytes: 3100
#include <iostream>
using namespace std;
int n,m,*data;
int i,j,k;
int main(){
	while(cin>>n>>m){
		if(n==0 && m==0){break;}
		data=new int[m];
		for(i=0;i<m;i++){
			data[i]=0;
		}
		for(j=0;j<n;j++){
			for(i=0;i<m;i++){
				cin>>k;
				data[i]+=k;
			}
		}
		k=0;
		for(i=n;i>=0;i--){
			for(j=0;j<m;j++){
				if(data[j]==i && k!=m-1){
					cout<<j+1<<" ";
					k+=1;
				}else if(data[j]==i && k==m-1){
					cout<<j+1<<endl;
				}
			}
		}
	}
	return 0;
}

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

int main(){
    
    size_t n;
    std::string s;

    std::cin >> n >> s;

    if(n % 2 == 0 && s.substr(0, n / 2) == s.substr(n / 2, n / 2)){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	ull n, ans = 1;
	cin >> n;

	for (ull i = 1; i <= n/2; i++) {
		if (i*i <= n) {
			ans = i * i;
		}
		else {
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int x[31]={0};
	int a;
	while(cin>>a)
		x[a]=1;

	for(int i=1;i<=30;i++)
		if(x[i]==0)
			cout<<i<<endl;

	return 0;
}

Measured memory_bytes: 1160
/* Volume0 0003 Is it a Right Triangle? */
import java.util.Scanner;

class Main{
	public static void main(String[] args){

		int n, temp;
		Scanner stdIn = new Scanner(System.in);
		n = stdIn.nextInt();
		int[][] side = new int[n][3];

		for( int i = 0; i < n; i++) {
			for( int j = 0; j < 3; j++) {
				side[i][j] = stdIn.nextInt();
			}
			if ( side[i][0] < side[i][1] ){
				temp = side[i][0] ;
				side[i][0] = side[i][1];
				side[i][1] = temp;
			}
			if ( side[i][0] < side[i][2] ){
				temp = side[i][0] ;
				side[i][0] = side[i][2];
				side[i][2] = temp;
			}
		}

		for( int i = 0; i < n; i++) {
			if ( side[i][0]*side[i][0] == side[i][1]*side[i][1] + side[i][2]*side[i][2] ){
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}

	}
}

Measured memory_bytes: 35232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007

int main() {
  int N, M, R;
  cin >> N >> M >> R;
  vector<int> r(R);
  rep(i, 0, R) cin >> r[i];
  rep(i, 0, R) r[i]--;
  sort(r.begin(), r.end());
  vector<vector<ll>> d(N, vector<ll>(N, 1e18));
  rep(i, 0, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  rep(i, 0, N) d[i][i] = 0;
  rep(k, 0, N) rep(i, 0, N) rep(j, 0, N) {
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
  ll ans = 1e18;
  do {
    ll total = 0;
    rep(i, 1, R) {
      int c = r[i-1];
      int n = r[i];
      total += d[c][n];
    }
    ans = min(ans, total);
  } while (next_permutation(r.begin(), r.end()));
  cout << ans << endl;
  return 0;
}


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

static int DP[21][50001];
	
int main(){
	int n,m;
	cin>>n>>m;

	int c[20];
	for(int i=0;i<m;i++)
		cin>>c[i];
		
	const int IMF=50000;

	for(int i=0;i<=m;i++)
		DP[i][0]=0;
	for(int j=0;j<=n;j++)
		DP[0][j]=IMF;

	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(j<c[i-1])
				DP[i][j]=DP[i-1][j];
			else{
				if(DP[i-1][j]<DP[i][j-c[i-1]]+1)
					DP[i][j]=DP[i-1][j];
				else
					DP[i][j]=DP[i][j-c[i-1]]+1;
			}
		}
	}
	
	cout<<DP[m][n]<<endl;
	
	return 0;
}

	

Measured memory_bytes: 7140
use std::cmp;
use std::collections::VecDeque;

fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { stdin: sc.lock() };

    let n = sc.read();
    let lr = (0..n)
        .map(|_| (sc.read(), sc.read()))
        .collect::<Vec<(i64, i64)>>();
    let left: Vec<i64> = lr.iter().map(|&(left, _)| left).collect();
    let right: Vec<i64> = lr.iter().map(|&(_, right)| right).collect();

    let left_inv = left.iter().map(|&v| -v).collect();
    let right_inv = right.iter().map(|&v| -v).collect();

    let ans1 = solve(left, right);
    let ans2 = solve(right_inv, left_inv);
    println!("{}", cmp::max(ans1, ans2));
}

fn solve(left: Vec<i64>, right: Vec<i64>) -> i64 {
    let n = left.len();
    let mut left_q = left
        .iter()
        .enumerate()
        .map(|(i, &left)| (left, i))
        .collect::<Vec<_>>();
    left_q.sort();
    left_q.reverse();
    let mut left_q = left_q.iter().map(|&(_, i)| i).collect::<VecDeque<_>>();

    let mut right_q = right
        .iter()
        .enumerate()
        .map(|(i, &right)| (right, i))
        .collect::<Vec<_>>();
    right_q.sort();
    let mut right_q = right_q.iter().map(|&(_, i)| i).collect::<VecDeque<_>>();

    let mut ans = 0;
    let mut cur = 0;
    let mut used = vec![false; n];
    for i in 0..n {
        let mut k = None;
        let q = if i % 2 == 0 {
            &mut left_q
        } else {
            &mut right_q
        };
        while let Some(i) = q.pop_front() {
            if used[i] {
                continue;
            }
            used[i] = true;
            k = Some(i);
            break;
        }

        let k = k.unwrap();
        if cur < left[k] {
            ans += left[k] - cur;
            cur = left[k];
        } else if right[k] < cur {
            ans += cur - right[k];
            cur = right[k];
        }
    }
    ans + cur.abs()
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 20732
#include <stdio.h>
#include <math.h>
 
#define PI 3.14159265

typedef struct{
  double x;
  double y;
} xy;

void kock(xy,xy,int);


int main(){
  int n;
  xy s,f;

  s.x=0;
  s.y=0;
  f.x=100;
  f.y=0;
  
  scanf("%d",&n);
  if(n==0) scanf("%d",&n);

  printf("%.8f %.8f\n",s.x,s.y);
  kock(s,f,n);
  printf("%.8f %.8f\n",f.x,f.y);

  return 0;
}

void kock(xy s,xy f,int n){
  xy p1,p2,p3;

  if(n==0) return;

  p1.x=(f.x+2*s.x)/3;
  p1.y=(f.y+2*s.y)/3;
  p3.x=(2*f.x+s.x)/3;
  p3.y=(2*f.y+s.y)/3;

  p2.x=(p3.x-p1.x)*cos(PI/3)-(p3.y-p1.y)*sin(PI/3)+p1.x;
  p2.y=(p3.y-p1.y)*cos(PI/3)+(p3.x-p1.x)*sin(PI/3)+p1.y;

  kock(s,p1,n-1);
  printf("%.8f %.8f\n",p1.x,p1.y);
  kock(p1,p2,n-1);
  printf("%.8f %.8f\n",p2.x,p2.y);
  kock(p2,p3,n-1);
  printf("%.8f %.8f\n",p3.x,p3.y);
  kock(p3,f,n-1);

  return;
}



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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define INF (ll)1e18
#define MOD (ll)(1e9 + 7)

struct UnionFind{
    vector<int> nxt;
    vector<int> numm;
    vector<int> aaa;
    void init(int x){
        nxt.clear();
        numm.assign(x, 1);
        nxt.resize(x);
        aaa.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    int size(int x){
        return numm[find(x)];
    }
    inline void unite(int x,int y){
        if(find(x)==find(y))
            return;
        numm[find(x)] += numm[find(y)];
        aaa[find(x)] += aaa[find(y)];
        nxt[find(y)] = find(x);
    }
};

ll N,P[5050];
ll mk[5050];
ll dp[5050][5050];
vector<pll> a;
ll K;
ll N2;
ll i, j, k;

ll powl(ll a,ll b){
    if(b==0)
        return 1;
    ll c = powl(a * a % MOD, b / 2);
    if(b&1){
        return c * a % MOD;
    }
    return c;
}

int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &P[i]);
        --P[i];
    }

    fornum(i,0,N+3){
        k = 1;
        fornum(j,1,i+1){
            mk[i] += k;
            (k *= i - j) %= MOD;
        }
    }



    UnionFind uf;
    uf.init(N + 9);
    fornum(i,0,N){
        if(P[i]==-2){
            uf.aaa[uf.find(i)] += 1;
            ++K;
            continue;
        }
        //printf("%lld")
        uf.unite(i, P[i]);
    }
    fornum(i,0,N){
        if(uf.find(i)!=i)
            continue;

        a.push_back({uf.size(i), uf.aaa[i]});
    }
    N2 = a.size();
    ll ans = (N - (N2 - K)) * powl(N - 1, K) % MOD;
    //printf("%lld\n", ans);


    fornum(i,0,N2){
        if(a[i].second==0){
            //(ans += (a[i].first - 1) * powl(N - 1, K)) %= MOD;
            fornum(j, 1, K + 1)
            {
                (dp[i + 1][j] += dp[i][j]) %= MOD;
            }
        }else{
            //(ans += a[i].first * powl(N - 1, K)) %= MOD;
            (ans += MOD - (a[i].first - 1) * powl(N - 1, K - 1) % MOD) %= MOD;
            dp[i + 1][1] += a[i].first;
            fornum(j, 1, K + 1)
            {
                (dp[i + 1][j] += dp[i][j]) %= MOD;
                (dp[i + 1][j + 1] += dp[i][j] * a[i].first * j) %= MOD;
            }
        }
        //printf("%lld,%lld\n", i, ans);
    }
    
    fornum(i,2,K+1){
        //printf("a%lld,%lld\n", i, dp[N2][i]);
        (ans += MOD - dp[N2][i]* powl(N - 1, K - i) % MOD) %= MOD;
    }
    
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 201208
a, b, c = map(int, input().split(" "))
ret=0
if a>=b and a>=c:
    ret = 10 * a + (b+c)
elif b>=a and b>=c:
    ret = 10 * b + (a+c)
else:
    ret = 10 * c + (a+b)

print (ret)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <numeric>

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N, M; cin >> N >> M;

    if (M >= 2 * N) {
        long long diff = M - 2 * N;
        cout << N + diff / 4;
    } else {
        cout << M / 2 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int L, R;
    cin >> L >> R;
    vector<int> mod;
    int count = 0;
    for (int i = L; i <= R; i++)
    {
        if (count > 2020)
        {
            break;
        }
        mod.push_back(i % 2019);
        count++;
    }
    int ans = 2019;
    for (int i : mod)
    {
        for (int j : mod)
        {
            if (i == j)
            {
                continue;
            }
            ans = min(ans, (i * j) % 2019);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
template<typename T>inline void read(T &x)
{
    T s=0,f=1;char k=getchar();
    while(!isdigit(k)&&(k^'-'))k=getchar();
    if(!isdigit(k)){f=-1;k=getchar();}
    while(isdigit(k)){s=s*10+(k^48);k=getchar();}
    x=s*f;
}
void file()
{
    #ifndef ONLINE_JUDGE
        //freopen("water.in","r",stdin);
        //freopen("water.out","w",stdout);
    #endif
}
const int MAXN=1e6+7;
static int n,m,t;
static char s[MAXN];
inline void init()
{
    scanf("%s",s+1);
    t=0;read(m);
    n=strlen(s+1);
}
namespace DAWG
{
    int len[MAXN],pre[MAXN],nxt[MAXN][30],cnt[MAXN],e,cur,las,dp[MAXN];
    inline void extend(int c)
    {
        static int q,clone,i;
        len[cur=++e]=len[las]+1;cnt[cur]=1;
        for(i=las;~i&&!nxt[i][c];i=pre[i])nxt[i][c]=cur;
        if(i==-1)pre[i]=0;
        else
        {
            if(len[q=nxt[i][c]]==len[i]+1)pre[cur]=q;
            else
            {
                pre[clone=++e]=pre[q];len[clone]=len[i]+1;
                pre[q]=pre[cur]=clone;
                memcpy(nxt[clone],nxt[q],sizeof nxt[q]);
                for(;~i&&nxt[i][c]==q;i=pre[i])nxt[i][c]=clone;
            }
        }
        las=cur;
    }
}
using namespace DAWG;
inline bool cmp(int a,int b){return len[a]>len[b];}
static int sta[MAXN],tp,p[MAXN];
inline void solve()
{
    pre[0]=-1;
    Rep(i,1,n)extend(s[i]-'a');
    Rep(i,1,e)p[i]=i;
    sort(p+1,p+e+1,cmp);
    Rep(i,1,e+1)
    {
        if(t&&~pre[p[i]])cnt[pre[p[i]]]+=cnt[p[i]];
        else cnt[p[i]]=1;
    }
    cnt[0]=0;
    Rep(i,1,e+1)
    {
        dp[p[i]]=cnt[p[i]];
        Rep(j,0,25)if(nxt[p[i]][j])dp[p[i]]+=dp[nxt[p[i]][j]];
    }
    if(m>dp[0])return (void)puts("-1");
    static int pos=0;
    while(m)
    {
        m-=cnt[pos];
        if(m<=0)break;
        Rep(i,0,25)if(nxt[pos][i])
        {
            if(dp[nxt[pos][i]]<m)m-=dp[nxt[pos][i]];
            else
            {
                sta[++tp]=i;
                pos=nxt[pos][i];
                break;
            }
        }
    }
    Rep(i,1,tp)putchar(sta[i]+'a');puts("");
}
int main()
{
    file();
    init();
    solve();
    return 0;
}


Measured memory_bytes: 16640
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define f(i,n) for(int i=0 ; i<n ; i++)
#define fll(i,n) for(ll i=0 ; i<n ; i++)
#define f1(a,b,i) for(ll i=a ; i<b ; i++)
#define fd(i,n) for(int i=n-1 ; i>=0 ; i--)
#define ll long long
#define ld long double
#define vi vector<int>
#define  pii pair<int,int>
#define vl vector<ll>
#define INF 1e9
#define epsn 1e-12

using namespace std ;
int M=1e9+7 ;
ll pow(ll a, ll b){
    if(b==0)return 1 ;
    else if(b%2)return a*pow(a,b-1) ;
    else return pow(a,b/2)*pow(a,b/2) ;
}

ll gcd(ll a,ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
   
int main(){
    ll x ;
    cin>>x ;
    ll d=gcd(x,360) ;
    ll ans=360/d ;
    cout<<ans<<"\n" ;
    return 0 ;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    string s; cin >> s;
    ll n = s.size();
    vector<ll> a(n,0);
    a.at(0) = s.at(0) - '0';
    for(int i=1;i<n;i++){
        ll usiro = 0;
        for(int j=i;j>=1;j--){
            usiro = usiro + (s.at(j) - '0')*pow(10,i-j);
            //cout << usiro << endl;
            a.at(i) += a.at(j-1) + (usiro * (pow(2,j-1)));            
        }
        usiro = usiro + (s.at(0)-'0')*pow(10,i);
        a.at(i) += usiro;      
    }
   // rep(i,n) cout << a.at(i) << endl;  
    cout << a.at(n-1) << endl;
}

Measured memory_bytes: 384
class HeavyLightDecomposition:
    def __init__(self, g, root=0):
        self.g = g
        self.vid, self.head, self.heavy, self.parent = [0] * len(g), [-1] * len(g), [-1] * len(g), [-1] * len(g)
        self.dfs(root)
        self.bfs(root)

    def dfs(self, root):
        stack = [(root, -1)]
        sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)
        used = [False] * len(self.g)

        while stack:
            v, par = stack.pop()
            if not used[v]:
                used[v] = True
                self.parent[v] = par
                stack.append((v, par))
                stack.extend((c, v) for c in self.g[v] if c != par)
            else:
                if par != -1:
                    sub[par] += sub[v]
                    max_sub[par] = max(max_sub[par], (sub[v], v))
                self.heavy[v] = max_sub[v][1]

    def bfs(self, root=0):
        from collections import deque
        k, que = 0, deque([root])
        while que:
            r = v = que.popleft()
            while v != -1:
                self.vid[v], self.head[v] = k, r
                for c in self.g[v]:
                    if c != self.parent[v] and c != self.heavy[v]:
                        que.append(c)
                k += 1
                v = self.heavy[v]

    def lca(self, u, v):
        while self.head[u] != self.head[v]:
            if self.vid[u] > self.vid[v]:
                u, v = v, u
            v = self.parent[self.head[v]]
        else:
            if self.vid[u] > self.vid[v]:
                u, v = v, u
        return u

N = int(input())
g = [[] for _ in range(N)]
for i in range(N):
    for c in map(int, input().split()[1:]):
        g[i].append(c)
        g[c].append(i)
hld = HeavyLightDecomposition(g)
Q = int(input())
for _ in range(Q):
    u, v = map(int, input().split())
    print(hld.lca(u, v))

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

#define int long long

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

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

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

	vector<int> adj[n];
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		bool b = true;
		for (auto x : adj[i]) {
			if (h[x] >= h[i]) {
				b = false;
				break;
			}
		}
		if (b) ++cnt;
	}
	cout << cnt;
}


Measured memory_bytes: 10272
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll bit[800010];
ll u;
void bitinit(ll n){
    ll y=1;
    rep(i,0,69){
        
        if(y>=n){
            u=y;
            break;
        }
        y*=2;
    }
    fill(bit,bit+u+10,0);
}
void add(ll n,ll x){
    ll i=n;
    bit[i]+=x;
    bit[i]%=mod;
    while(i<u){
        i+=i&(-i);
        bit[i]+=x;
        bit[i]%=mod;
    }
}
ll sum(ll n){
    ll i=n;
    ll ret=0;
    while(i>0){
        ret+=bit[i];
        i-=i&(-i);
        ret%=mod;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    int l[n];rep(i,0,n)cin>>l[i];
    bitinit(10000);
    sort(l,l+n);
    ll ans=0;
    add(l[0]+l[1],1);
    rep(i,2,n){
        ans+=sum(9000)-sum(l[i]);
        rep(j,0,i){
            add(l[j]+l[i],1);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384