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

long long foo(long long n){
  if(n==0)return 1;
  return foo(n-1)*n;
}

long long huga(long long n,long long r){
  //cout<<n<<" "<<r<<endl; 
  //cout<<foo(n-r)<<" C "<<foo(r)<<endl;
  //return foo(n)/(foo(r)*foo(n-r));
  if(r==1)return n;
  return huga(n,r-1)*(n-r+1)/r;
}


int main(){
  long long N, A, B, count = 0, temp = 0, i, countb = 0;
  long long v[100] = {}, ansb = 0;
  double ans = 0;

  cin>>N>>A>>B;

  for(i = 1; i <= N; i++){
    cin>>v[i];
  }
  sort(v+1, v+N+1);

  for(i = 0;i < A;i++){
    ans += v[N-i];
  }

  
  for(i = 1; i <= N; i++){
    if(v[N]==v[i])count++;
  }

  if(v[N]== v[N-A+1]){
    ansb = 0;
     for(int i = A; i <= B; i++){
       if(v[N-i+1] != v[N])break;
       ansb += huga(count,i);
     }
  }else{
    
    int cntF=0;
    int cntS=0;

    for(int i=1;i<=N;i++){
      if( v[i] > v[N-A+1] ){
	cntF++;
      }
      if( v[i] == v[N-A+1] ){
	cntS++;
      }
    }
    ansb = huga( cntS , A - cntF );    
    
  }
  
  printf("%.7f ", ans/A);
  //cout<<temp<<endl;
  //cout<<count<<" "<<countb<<endl;
  cout<<ansb<<endl;
  //cout<<(long long)pow(countb+A, count+countb)<<endl;
  //cout<<(long long)pow(2, countb+count)-1<<endl;
   //printf(" %ld\n", (long long)pow(countb+(long long)A, count+countb));
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), fprintf(), scanf()
#include <stdlib.h>         // exit()
#include <string.h>         // strlen(), strcpy(), strcmp(), memset()
#include <stdbool.h>

// #define DEBUG 1
#define N_DICT 1000000
#define N_HASH 512000
#define L_STRINGS 50000000

typedef struct dict_tbl
{
	const char* str;
	int next;
} dict_t;

const char NUL = '\0';
int lineno;
dict_t dict[N_DICT];
char k[256];
int s_hash[N_HASH];
char strings[L_STRINGS];
int n_dict;
int ix;
int l_max;

void
cleanup(int ecode)
{
	exit(ecode);
}

int
hash(const char* str)
{
	int h;
	int i;

	h = 0;
	for (i = 0; str[i] != NUL; ++i)
		h = h * 4 + k[(int)str[i]];

	return h % N_HASH;
}

void
insert(const char* str)
{
	int u;

	if (n_dict >= N_DICT)
	{
		fprintf(stderr, "line %d: Dictionary area overflow. size:%d\n", lineno, N_DICT);
		cleanup(1);
	}

	if (ix + strlen(str) + 1 > L_STRINGS)
	{
		fprintf(stderr, "line %d: Strings area overflow. size:%d\n", lineno, L_STRINGS);
		cleanup(1);
	}

	char* s = &strings[ix];
	strcpy(s, str);
	ix += strlen(str) + 1;

	int h = hash(s);
	dict[n_dict].str = s;
	dict[n_dict].next = s_hash[h];

	s_hash[h] = n_dict;
	n_dict++;

	int i = 0;
	for (u = s_hash[h]; u != -1; u = dict[u].next)
		i++;

	if (i > l_max)
		l_max = i;
}

bool
find(const char* str)
{
	int u;

	u = s_hash[hash(str)];
	for (; u != -1; u = dict[u].next)
	{
		if (strcmp(str, dict[u].str) == 0)
			return true;
	}

	return false;
}

void
init()
{
	int i;

	for (i = 0; i < N_HASH; ++i)
		s_hash[i] = -1;

	memset(k, 0x00, sizeof(k));
	k['A'] = 1;
	k['C'] = 2;
	k['G'] = 3;
	k['T'] = 4;

	lineno = 0;
	n_dict = 0;
	ix = 0;
	l_max = 0;
}

int
main(int argc, char** argv)
{
	char command[8];
	char str[14];
	int n = 0;
	int i;

	init();
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		lineno++;
		scanf("%s %s", command, str);
		switch (command[0])
		{
		case 'i':
			insert(str);
			break;

		case 'f':
		default:
			printf("%s\n", find(str) ? "yes" : "no");
			break;
		}
	}

#ifdef DEBUG
	int count = 0;
	for (i = 0; i < N_HASH; ++i)
	{
		if (s_hash[i] == -1)
			count++;
	}

	fprintf(stderr, "n_dict:%d ix:%d l_max:%d count:%d\n", n_dict, ix, l_max, count);
#endif
	return 0;
}

Measured memory_bytes: 22004
# https://atcoder.jp/contests/abc167/tasks/abc167_d
# コンテスト中は周期性を用いたが、今回はdoublingで解いてみる

import sys
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def ints(): return list(map(int, read().split()))


N, K = ints()
A = mina(*ints())
# 10^18のは60bitで表せるのでnxt tableをつくるのに最大1.2 * 10^7 ぐらい。ギリ間に合いそう


nxt = [[-1] * N for _ in ra(K.bit_length())]  # [k][v]...vから2^k回移動したノード
# 初期化
for v, nx in enu(A):
    nxt[0][v] = nx

# テーブル埋め
for k in ra(K.bit_length() - 1):
    for v in ra(N):
        nxt[k + 1][v] = nxt[k][nxt[k][v]]

# 答えの取得
now = 0  # はじめは0地点にいる
for k in ra(K.bit_length()):
    if (K >> k) & 1:
        # kbit目が立ってたらこの回数分だけ移動
        now = nxt[k][now]
print(now + 1)


Measured memory_bytes: 177184
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

int N;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    if(N==2){
        cout << -1 << endl;
        return 0;
    }
    if(N==3){
        cout << "aa." << endl << "..a" << endl << "..a" << endl;
      	return 0;
    }
    if(N==7){
        cout << "aabbcc." << endl << "dd.dd.a" << endl << "..d..da" << endl <<  "..d..db" << endl << "dd.dd.b" << endl << "..d..dc" << endl <<  "..d..dc" << endl;
        return 0;
    }
    ll nN=N;
    if(nN%2!=0){
        nN-=5;
    }
    rep(i,nN){
        rep(j,N){
            if(i%2==0&&(i<=j&&j<=i+1)){
                cout << 'a';
            }
            else if(i%2==1&&(i-1<=j&&j<=i)){
                cout << 'b';
            }
            else if((i/2*2+2)%nN==j){
                cout << 'c';
            }
            else if((i/2*2+3)%nN==j){
                cout << 'd';
            }
            else{
                cout << '.';
            }
        }
        cout << endl;
    }
    vc c={'e','e','f','f','e','f','g','g','.','e','f','.','.','g','f','e','.','.','g','f','e','f','f','e','e'};
    if(N%2){
        FOR(i,nN,N){
            rep(j,N){
                if(j<nN){
                    cout << '.';
                }
                else{
                    cout << c[5*(i-nN)+j-nN];
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 3676
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int a=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<i;j++){
            if(s[j]==s[i]){
                a++;
            }
        }
    }
    if(a==0){
        cout<<"yes"<<endl;
    }else{
        cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
n = h * w
raw = []
for i in range(h):
  tmp = input()
  add = []
  for j in range(w):
    if tmp[j] == '.':
      add.append(0)
    else:
      add.append(1)
  raw += add
wf = [[1000 for _ in range(n)] for _ in range(n)]
for i in range(n):
  if raw[i] == 0:
    wf[i][i] = 0
    d = []
    if i-w >= 0:
      d.append(i-w)
    if i+w < n:
      d.append(i+w)
    if i%w != 0:
      d.append(i-1)
    if (i+1)%w != 0:
      d.append(i+1)
    for e in d:
      if raw[e] == 0:
        wf[i][e] = 1
#for x in wf:
  #print(x)
for k in range(n):
  for i in range(n):
    for j in range(n):
      if wf[i][k] + wf[k][j] < wf[i][j]:
        wf[i][j] = wf[i][k] + wf[k][j]
ans = 0
for i in range(n):
  for j in range(n):
    if ans < wf[i][j] % 1000:
      ans = wf[i][j]
print(ans)
#for x in wf:
  #print(x)

Measured memory_bytes: 43356
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
 
int main() {
    LL N, H;
    cin >> N >> H;
    vector<LL> a(N), b(N);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];
 
    // 振り最強剣
    LL a_max = *max_element(all(a));
    // 強いものから投げる
    sort(all(b));
    reverse(all(b));
    LL ans = 0;
    for(int i=0; i<N; i++){
        if(a_max < b[i]){
            H -= b[i];
            ans++;
            // 投げで倒した
            if(H <= 0) break;
        }
    }
    // 剣を振りまくって倒す
    if(H > 0) ans += (H + (a_max-1)) / a_max;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

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

void Main(){
    ll N, M;
    cin >> N >> M;
    vec<int> foods(M);
    REP(i, N){
        ll K;
        cin >> K;
        REP(j, K){
            ll A;
            cin >> A;
            foods[A-1]++;
        }
    }
    int cnt = 0;
    REP(i, M){
        if(foods[i]==N){
            cnt++;
        }
    }
    cout << cnt << el;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int main(){

  int n; cin >> n;
  vector<int> a(n);
  int f = 0;
  int t = 0;
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
    if( a[i] % 4 == 0 ) f++;
    else if( a[i] % 2 == 0 ) t++;
  }
  int e = n - f - t;

  vector<int> b(n, 0);
  for(int i=0; i<n; i++){
    if( i % 2 == 0 ){
      if( e > 0 ){
        b[i] = 1;
        e--;
      }else {
        b[i] = 2;
      }
    } else {
      if( f > 0 ){
        b[i] = 4;
        f--;
      }else {
        b[i] = 2;
      }
    }
  }

  for(int i=0; i<n-1; i++){
    if( (b[i] * b[i+1]) % 4 != 0 ){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


//


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n;
	cin>>n;
	
	vector<long long> a(n);
	
	for(int i=0;i<n;i++)
	cin>>a[i];
	
	vector<vector<long long>> dp(n,vector<long long> (n,1e15)),dp1(n,vector<long long> (n,1e15)),dp2(n,vector<long long> (n,1e15));
	
	for(int i=0;i<n;i++)
	{		
		if(n%2)
		{
			dp1[i][i]=a[i];
			dp2[i][i]=0;
		}
		else
		{
			dp1[i][i]=0;
			dp2[i][i]=a[i];
		}
		dp[i][i]=dp1[i][i]-dp2[i][i];
	}
	
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<n-i;j++)
		{
			if((n-i)%2==0)
			{
				if(dp1[j][i+j-1]-(dp2[j][i+j-1]+a[i+j])<dp1[j+1][i+j]-(dp2[j+1][i+j]+a[j]))
				{
					dp[j][i+j]=dp1[j][i+j-1]-(dp2[j][i+j-1]+a[i+j]);
					dp1[j][i+j]=dp1[j][i+j-1];
					dp2[j][i+j]=dp2[j][i+j-1]+a[i+j];
				}
				else
				{
					dp[j][i+j]=dp1[j+1][i+j]-(dp2[j+1][i+j]+a[j]);
					dp1[j][i+j]=dp1[j+1][i+j];
					dp2[j][i+j]=dp2[j+1][i+j]+a[j];
				}
			}
			else
			{
				if(dp1[j][i+j-1]+a[i+j]-dp2[j][i+j-1]<dp1[j+1][i+j]+a[j]-dp2[j+1][i+j])
				{
					dp[j][i+j]=dp1[j+1][i+j]+a[j]-dp2[j+1][i+j];
					dp1[j][i+j]=dp1[j+1][i+j]+a[j];
					dp2[j][i+j]=dp2[j+1][i+j];
				}
				else
				{
					dp[j][i+j]=dp1[j][i+j-1]+a[i+j]-dp2[j][i+j-1];
					dp1[j][i+j]=dp1[j][i+j-1]+a[i+j];
					dp2[j][i+j]=dp2[j][i+j-1];
				}
			}
		}
	}
	
	cout<<dp[0][n-1];
}

Measured memory_bytes: 211584
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;
#include<iostream>
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
int main() {
	ll N;
	cin >> N;
	vector<ll>v;
	for (ll i = 7; i<50000; i += 5) {
		if (prime(i))
			v.push_back(i);
	}
	for (ll i = 0; i<N; ++i) {
		cout << v[i] << " ";
	}
	cout << "" << endl;
}


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

using namespace std;

#define int long long

int n;

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

	cin >> n;
	int res = n-1;
	for (int i=2;i*i<=n;i++)
		if (n%i == 0)
			res = min(res,i-1 + (n/i)-1);
	cout << res;						
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll mod = 1e9+7;

int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> w(n), d(n); 
  rep(i,n) cin >> w[i] >> d[i];

  ll l = 0, r = (1LL << 61);

  auto ok = [&](ll m) {
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
      if (m < w[i]) continue;
      cnt += (m - w[i]) / d[i] + 1;
    }
    return cnt >= k;
  };

  while (r - l > 1) {
    ll m = l + (r - l) / 2;
    if (ok(m)) r = m;
    else l = m;
  }
 
  cout << r << endl;
  return 0;
} 

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int long N,A,B,C,D,E;
  cin>>N>>A>>B>>C>>D>>E;
  int long key=min(A,B);
  key=min(key,C);
  key=min(key,D);
  key=min(key,E);
  int long p=(N-1)/key+1;
  cout<<p+4<<endl;
}

Measured memory_bytes: 384
from collections import deque

def main():
    S = input()
    Q = int(input())
    
    SS = deque()
    for s in S:
        SS.append(s)
    
    cnt = 0
    for i in range(Q):
        query = input().split()
        if(query[0] == "1"):
            cnt += 1
        else:
            if(query[1] == "1"):
                if(cnt%2 == 0):
                    SS.appendleft(query[2])
                else:
                    SS.append(query[2])
            else:
                if(cnt%2 == 0):
                    SS.append(query[2])
                else:
                    SS.appendleft(query[2])
    
    ans = list(SS)
    if(cnt%2 == 0):
        print(''.join(ans))
    else:
        print(''.join(ans[::-1]))
main()

Measured memory_bytes: 10476
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n, m;
	cin >> n >> m;
	
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i], a[i] /= 2;
	
	int lcm = a[0];
	for(int i = 1; i < n; i++){
		lcm = lcm*a[i]/__gcd(a[i],lcm);
	}
	while(1){
		int p = 0;
		for(int i = 0; i < n; i++){
			if((lcm-a[i]) % (2*a[i])){
				lcm *= 2;
				p = 1;
				break;
			}
		}
		if(!p)
			break;
		if(lcm > m)
			break;
	}
	
	cout << max(m / lcm - m / (2*lcm),0LL);

	return 0;
}



Measured memory_bytes: 1024
N,M=map(int,input().split(' '))
H=list(map(int,input().split(' ')))

data=[]
for n in range(N):
  data.append(H[n]-1)
    
for m in range(M):
  a,b=map(int,input().split(' '))
  data[a-1]=max(data[a-1],H[b-1])
  data[b-1]=max(data[b-1],H[a-1])
  
ans=0
for n in range(N):
  if H[n-1]-1==data[n-1]:
    ans+=1
print(ans)

Measured memory_bytes: 85892
#include <iostream>

#define REP(i, n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main() {
    int n;
    cin >> n;
    int a[2][n + 1];
    a[0][0] = 0;
    a[1][0] = 0;
    REP(i, n) {
        cin >> a[0][i + 1];
    }
    REP(i, n) {
        cin >> a[1][i + 1];
    }
    int b[n + 1];
    b[0] = 0;
    REP(i, n) {
        b[i+1] = b[i] + a[1][i+1];
    }
    int max = -1;
    int sum = 0;
    REP(i, n + 1) {
        sum += a[0][i];
        int score = sum + b[n] - b[i-1];
        max = score > max ? score : max;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var w, a, b int
	fmt.Scan(&w, &a, &b)
	
	ans := 0
	if a + w < b {
		ans = b - (a + w)
	} else if b + w < a {
		ans = a - (b + w)
	} 
	fmt.Println(ans)
}

Measured memory_bytes: 1768
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n;
    cin >> n;
    ll zmin = INFLL, zmax = -INFLL;
    ll wmin = INFLL, wmax = -INFLL;
    vi x(n), y(n);
    for(ll i=0; i<n; i++){
        cin >> x[i] >> y[i];
        ll z = x[i] + y[i];
        ll w = x[i] - y[i];
        chmin(zmin, z);
        chmax(zmax, z);
        chmin(wmin, w);
        chmax(wmax, w);
    }
    cout << max(zmax - zmin, wmax - wmin) << endl;
}

Measured memory_bytes: 6344
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

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

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
#define IINF (1<<21)
typedef long long ll;

int N;
vector<pair<int, int> > G[100010];
int d[100010];
int available[100010];


void dfs(int s) {
  available[s] = 0;
  for (vector<pair<int, int> >::iterator it = G[s].begin(); it != G[s].end(); it++) {
    int v = it->first;
    int w = it->second;
    if (!available[v]) continue;


    d[v] = d[s] + w;
    dfs(v);
  }
}

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

  REP(i, N - 1) {
    int s, t, w;
    cin >> s >> t >> w;
    G[s].push_back(make_pair(t, w));
    G[t].push_back(make_pair(s, w));
  }

  REP(i, N) {
    d[i] = IINF;
    available[i] = 1;
  }
  d[0] = 0;
  dfs(0); // tekitou yatsu

  int farv = 0;
  REP(i, N) {
    if (d[i] == IINF) continue;
    if (d[farv] < d[i]) {
      farv = i;
    }
  }
  // dump(farv);
  // dump(d[farv]);
  // dump(d[0]);
  // dump(d[1]);
  // dump(d[2]);
  // dump(d[3]);

  REP(i, N) {
    d[i] = IINF;
    available[i] = 1;
  }
  d[farv] = 0;
  dfs(farv); // tekitou yatsu

  int maxv = 0;
  REP(i, N) {
    if (d[i] == IINF) continue;
    maxv = max(maxv, d[i]);
  }

  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 12472
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
string tstring(ll n){
  string t=to_string(n);
  while(t.size()<6){
    t="0"+t;
  }
  return t;
}
int main(){
  ll n,m;cin>>n>>m;
  vector<vp> s(n);vll pp(m);
  vector<string> ans(m);
  rep(i,0,m){
    ll y,p;cin>>p>>y;
    s[p-1].push_back(make_pair(y,i));
    pp[i]=p;
  }
  rep(i,0,n)sort(s[i].begin(),s[i].end());
  for(auto u:s){
    rep(i,0,u.size()){
      
      ans[u[i].second]=tstring(pp[u[i].second])+tstring(i+1);
      
    }
  }
  rep(i,0,m){
    cout<<ans[i]<<endl;
  }
}








Measured memory_bytes: 12568
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

int root[101];
int ranks[101];

struct E{
	E(int from, int to, int cost):from(from), to(to), cost(cost){}
	int from, to, cost;
	bool operator < (const E & e)const{
		return cost < e.cost;
	}
};

void Init(){
	for(int i = 0; i < MAX; i++){
		root[i] = i;
		ranks[i] = 1;
	}
}

int find(int x){
	if(root[x] == x) return x;
	else return root[x] = find(root[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(ranks[x] < ranks[y]){
		root[x] = y;
	}else{
		root[y] = x;
		if(ranks[x] == ranks[y]) ranks[x]++;
	}
}

int main(){
	int n, m;
	while(cin >> n && n != 0){
		cin >> m;
		Init();
		vector<E> tb;
		for(int i = 0; i < m; i++){
			int a, b, cost;
			scanf("%d,%d,%d", &a, &b, &cost);
			tb.push_back(E(a, b, cost));
		}

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

		int ans = 0;
		for(int i = 0; i < tb.size(); i++){
			if(find(tb[i].from) != find(tb[i].to)){
				ans += (tb[i].cost/100) - 1;
				unite(tb[i].from, tb[i].to);
			}
		}

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

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

typedef long long ll;
const int maxn = 5e5 + 5, mod = 998244353;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

void dec(int &a, int b) {a -= b; if (a < 0) a += mod;}

int fpow(int x, int k)
{
	int res = 1;
	while (k) {
		if (k & 1) res = (ll)res * x % mod;
		k >>= 1; x = (ll)x * x % mod;
	}
	return res;
}

int n, m, fac[maxn], ifac[maxn];

int C(int m, int n)
{
	if (n > m) return 0;
	return (ll)fac[m] * ifac[n] % mod * ifac[m - n] % mod;
}

int main()
{
	n = gi(); m = gi();
	if (m < n) return puts("0"), 0;
	
	fac[0] = 1;
	for (int i = 1; i <= m; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
	ifac[m] = fpow(fac[m], mod - 2);
	for (int i = m - 1; ~i; --i) ifac[i] = (ll)ifac[i + 1] * (i + 1) % mod;

	int ans = 0;
	for (int R = 0, B; R <= m; ++R) {
		B = m - R;
		if (R == B) --B;
		int L = R - B;
		if (L < 0 || (n - L) > B) continue;
		int T = B - (n - L);
		ans = (ans + C(R + B, R)) % mod;
		if (L < n) dec(ans, C(R + B, R + T + 1));
	}
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 4096
N = gets.to_i
As = gets.split.map(&:to_i)
Bs = As.reverse

memo = []
memo[0] = As[0]
(N-1).times{|x|
    memo[x+1] = memo[x].gcd(As[x+1])
}
memo2 = []
memo2[0] = Bs[0]
(N-1).times{|x|
    memo2[x+1] = memo2[x].gcd(Bs[x+1])
}

def gcd_skip_i(i,memo,memo2)
    if (i === 0) then
        return memo2[N-2]
    elsif (i === N-1) then
        return memo[N-2]
    else
        return memo[i-1].gcd(memo2[(N-1) - (i+1)])
    end
end

ans2 = 0
N.times{|x|
    ans2 = [ans2, gcd_skip_i(x,memo,memo2)].max
}

puts ans2


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

int main()
{
    long long a, b, n;
    cin >> n >> a >> b;
    long long ans = 0;
    ans += (n / (a + b)) * a;
    if (n%(a + b) <= a) ans += n%(a + b);
    else ans += a;
    cout << ans << "\n";
}


Measured memory_bytes: 256
N=list(input())
if len(N) == 1:
    print(int(N[0]))
    exit()
all9 = True
for i in range(1,len(N)):
    if N[i] != '9':
        all9 = False
        break

c = int(N[0])
if not all9:
    c -= 1
print(c + 9 * (len(N)-1))


Measured memory_bytes: 61864
/* 	ex5_4
   	masaaki52	*/
#include <stdio.h>
#include <string.h>
int main(void){
  char string[11];
  int i,count=0,max=0;
  scanf("%s",string);
  for(i=0;i<strlen(string)+1;i++){
    switch(string[i]){
      case 'A': case 'C': case 'G': case 'T':
        count++;
        break;
      default:
        if(count > max){
          max = count;
        }
        count = 0;
    }
  }
  printf("%d",max);
  return 0;
}


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

constexpr ll INF = ll(1e+18) + 1;

int main() {
    int N;
    int a[8] = {};
    int rate;
    int ans_min=0, ans_max=0;
    int over = 0;

    cin >> N;
    rep(i, N) {
        cin >> rate;
        if (rate < 3200) { a[rate/400]++; }
        else {over++;}
    }

    rep(i, 8) {
        if (a[i] > 0) {
            ans_min++;
        }
    }

    ans_max = ans_min+over;
    ans_min = max(ans_min, 1);

    cout << ans_min << " " << ans_max << endl;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int x;
	cin >> x;
	if(x>=30){
		cout << "Yes" << "\n";
	}
	else{
		cout << "No" << "\n";
	}
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
 
typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;
 
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
 
const int maxn = 200010;
const int mlog = 20;
 
int pos[ maxn ];
int vsize[ mlog ], len;
 
int mr[ maxn ][ mlog ], ml[ maxn ][ mlog ];
int dppref[ 1 << mlog ], dpsuff[ 1 << mlog ];
 
int bestcover[ maxn ];
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
#ifdef MARX
    freopen("data.in", "r", stdin);
#endif
 
    int n, V;
    cin >> n >> V;
 
    int v = V >> 1;
 
    for (int i = 0; i < n; ++i)
        cin >> pos[i];
 
    for (len = 0; vsize[len++] = v; v >>= 1);
    vsize[ len ] = V;
 
    for (int i = 0; i <= len; ++i){
        mr[ n - 1 ][i] = n - 1;
        ml[ 0 ][i] = 0;
    }
 
    for (int i = 1; i < n; ++i){
        for (int j = 0; j <= len; ++j){
            if (pos[i] - pos[i - 1] <= vsize[j])
                ml[i][j] = ml[i - 1][j];
            else
                ml[i][j] = i;
        }
    }
 
    for (int i = n - 2; i >= 0; --i){
        for (int j = 0; j <= len; ++j){
            if (pos[i + 1] - pos[i] <= vsize[j])
                mr[i][j] = mr[i + 1][j];
            else
                mr[i][j] = i;
        }
    }
 
    dppref[0] = -1;
    dpsuff[0] = n;
 
    int mask = (1 << len);
 
    for (int i = 1; i < mask; ++i){
        dppref[i] = 0;
        dpsuff[i] = n - 1;
 
        for (int j = 0; j < len; ++j){
            if (i >> j & 1){
                int m = i ^ (1 << j);
 
                // prefix
 
                if (dppref[m] == n - 1)
                    dppref[i] = n - 1;
                else
                    dppref[i] = max(dppref[i], mr[ dppref[m] + 1 ][j]);
 
                // suffix
 
                if (dpsuff[m] == 0)
                    dpsuff[i] = 0;
                else
                    dpsuff[i] = min( dpsuff[i], ml[ dpsuff[m] - 1 ][j]);
            }
        }
    }
 
    mask--;
 
    for (int i = 0; i < n; ++i)
        bestcover[i] = oo;
 
    for (int i = 0; i <= mask; ++i){
        int comp = mask ^ i;
        
        int pA = dppref[ i ], pB = dpsuff[ comp ];

        if (pA >= 0)
        	bestcover[ pA ] = min( bestcover[ pA ], pB );
    }
 
    for (int i = n - 2; i >= 0; --i)
        bestcover[i] = min( bestcover[i], bestcover[i + 1] );
 
    for (int i = 0; i < n; ++i){
        int pA = ml[i][len], pB = mr[i][len];
 
        bool ok = false;
 
        if (pA == 0){
            if (dpsuff[ mask ] <= pB + 1)
                ok = true;
        }
        else
            ok = bestcover[pA - 1] <= pB + 1;
 
        cout << (ok ? "Possible" : "Impossible") << endl;
    }
 
    return 0;
}

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

#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int A, B, C; in(A); in(B); in(C);

  if (A == B && B == C && A % 2 == 0)
    out(-1);
  else {
    int count = 0;
    while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
      int newA = B/2+C/2,
          newB = C/2+A/2,
          newC = A/2+B/2;
      A = newA;
      B = newB;
      C = newC;
      ++count;
    }
    out(count);
  }
  return 0;
}


Measured memory_bytes: 256
////


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define REP(i,l,r) for(ll i=l; i<(ll)(r); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
#define swap(l,r) {ll tp=l;l=r;r=tp;}
const ll MOD = 1000000007;
int upcmpll(const void *a,const void *b){
    return (*(ll*)a == *(ll*)b?0:(*(ll*)a > *(ll*)b?1:-1));
}
void sort_u(ll *a,int n){qsort(a,n,sizeof(ll),upcmpll);}

int main(){
    int n, k; scanf("%d%d", &n, &k);
    int d[15] = {0};
    rep(i, k){
        int x;
        scanf("%d", &x);
        d[x] = 1;
    }
  
    int ans = n-1, ng = 1;
    while(ng){
      ans++;
      int tmp = ans;
      ng = 0;
      while(tmp){
        if(d[tmp%10]){
          ng = 1;
          break;
        }
        tmp /= 10;
      }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1728
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;

const ll MOD = 1000000007;

ll modpow(ll a, ll b){//a^b
    if(b == 1) return a;
    if(b&1) return modpow(a, b-1) * a % MOD;
    ll tmp = modpow(a, b/2);
    return tmp * tmp % MOD;
}

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> da(k+1, -1);
    da[k] = modpow(k, n);
    for(int i = k; i > 1;i--){
        if(da[k/i] == -1){
            da[k/i] = modpow(k/i, n);
            rip(j, k/i + 1, 2){
                da[k/i] = (da[k/i]-da[k/i/j]+MOD)%MOD;
            }
        }
        da[k] = da[k]-da[k/i]+MOD;
        da[k] %= MOD;
    }
    ll ans = 0;

    rip(i,k+1,1) ans += da[k/i] * i, ans %= MOD;
    // vdeb(da);
    cout << ans%MOD << endl;
    // cout << modpow(k, n) << endl;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powmod(x*x%MOD,n/2);
    if(n % 2)ans = ans * x % MOD;
    return ans;
}
ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}
ll combi(ll n,ll r){
    ll num = 1;
    for(ll i = 1;i <= r;i++){
        num = divmod((n-i+1)*num,i);
    }
    return num;
}
main(){
    ll N,M;
    cin >> N >> M;
    map<int,int> mp;
    vector<int> prime;
    ll num = M;
    for(ll i = 2;i * i <= num;i++){
        if(num % i == 0){
            mp[i]++;
            //prime.push_back(i);
            num /= i;
            i--;
        }
    }
    //if(num != 1)prime.push_back(num);
    if(num != 1)mp[num]++;
    ll ans = 1;
    for(auto p:mp){
        ll r = p.second;
        ll res = combi(N + r - 1, r);
        ans = (ans * res) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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;}

int main(){
  string S; cin >> S;
  ll N = sz(S);
  reverse(all(S));
  ll ans = 0;
  vector<ll> A(N+1,0);
  rep(i,N) A[i] = S[i]-'0';
  vector<vector<ll>> dp(2, vector<ll>(N+2,0));
  dp[0][0] = 1;
  //dp[i][j]:下からi桁目まで払う j=0ならおつりあり 1ならきっちり
  for(int i=1; i<=N+1; i++){
    dp[0][i] = min(dp[0][i-1]+9-A[i-1], dp[1][i-1]+10-A[i-1]);
    dp[1][i] = min(dp[0][i-1]+1+A[i-1], dp[1][i-1]+A[i-1]);
  }
  ans = min(dp[1][N+1], dp[0][N+1]+1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 32644
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N,A,B,ans;
  cin>>N>>A>>B;
  ans=A+B-N;
  if(ans<0) ans=0;
  cout<<min(A,B)<<" "<<ans<<endl;
}



Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <cstdio>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main()
{
	ll n, k, x, y;
	cin >> n >> k >> x >> y;
	if (n > k)
	{
		cout << x * k + (n - k) * y << endl;
	}
	else
	{
		cout << x * n << endl;
	}
	return 0;
}

Measured memory_bytes: 256
k = int(input())
l = list(map(int, input().split()))
if (l[1] - l[0]) >= k or l[0] % k == 0 or l[1] % k == 0:
  print("OK")
else:
  while l[0] != l[1]:
    l[0] += 1
    if l[0] % k == 0:
      print("OK")
      exit()
  print("NG")

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

int main() {
  string s;
  cin >> s;
  int ans=0;
  for(int i=1;i<s.size();i++){
    if(s.at(i)==s.at(i-1)){
      ans++;
      if(s.at(i)=='0') s.at(i)='1';
      else s.at(i)='0';
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef long double ld;

typedef long long ll;

using namespace std;


ll n;
ll m,c,k,i,d,y,a[2000000],b[200000],ok,x=1e18;

string s,t;

ll dp[500][500];

ll rec(ll l,ll r)
    {
        if(l==r)return 0;
        
        if(l>r)return 0;

        if(dp[l][r]!=-1)return dp[l][r];

        ll c1 = 1e18;
        for(int i=0;i<r-l;i++)
        {
           c1 = min(c1,rec(l,l+i)+rec(l+i+1,r)+b[r]-b[l-1]);
        }

        return dp[l][r]=c1;

    }


int main()
{
    memset(dp,-1,sizeof dp);

    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i],b[i]=b[i-1]+a[i];

    if(n>1)
    cout<<rec(1,n);
    else
        cout<<a[1];
}


Measured memory_bytes: 4224
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
  size_t n, wmax;
  std::cin >> n >> wmax;

  std::vector<size_t> w(n);
  std::vector<size_t> v(n);
  for (size_t i = 0; i < n; ++i) std::cin >> w[i] >> v[i];

  std::vector<std::vector<size_t>> dp(n + 1);
  dp[0].resize(wmax + 1, 0);

  for (size_t i = 1; i <= n; ++i) {
    dp[i].resize(wmax + 1, 0);
    const auto wi = w[i - 1];
    const auto vi = v[i - 1];
    for (size_t j = 0; j <= wmax; ++j) {
      dp[i][j] = std::max(dp[i][j], dp[i - 1][j]);
      if (j >= wi) dp[i][j] = std::max(dp[i][j], dp[i - 1][j - wi] + vi);
    }
  }

  std::cout << dp[n][wmax] << std::endl;
}


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

int main(){
  vector<string> num = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

  int n;
  cin >> n;
  string ans;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    
    ans = "";
    int j = 0;
    stack<int> st;
    for(int j = 0; j < s.length(); j++){
      if(s[j] == '0'){
        if(st.empty())continue;
        ans += num[st.top()][(st.size() - 1) % num[st.top()].size()];

        while(!st.empty())st.pop();
      }else{
        st.push(s[j] - '0');
      }
    }
    cout << ans << endl;
  }
}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


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

int main() {
    ios_base::sync_with_stdio(0);
    
    int r, c, n;
    cin >> r >> c >> n;
    
    struct val {
        int x, y, type, id;
    };
    
    vector <val> vals;
    
    FOR(i,1,n) {
        vector <val> here;
        
        FOR(_,1,2) {
            int x, y;
            cin >> x >> y;
            
            int type = -1;
            if (x == 0) type = 0;
            else if (y == c) type = 1;
            else if (x == r) type = 2;
            else if (y == 0) type = 3;
            
            if (type != -1) {
                here.pb({x, y, type, i});
            }
        }
        
        if (SIZE(here) == 2) {
            copy(here.begin(), here.end(), back_inserter(vals));
        }
    }
    
    sort(vals.begin(), vals.end(), [](const val &a, const val &b) -> bool {
        if (a.type != b.type) {
            return a.type < b.type;
        }
        
        return (a.type > 1) xor (mp(a.x, a.y) < mp(b.x, b.y));
    });
    
    stack <int> s;
    
    for (auto &v : vals) {
        if ((!s.empty() && s.top() == v.id)) {
            s.pop();
        } else {
            s.push(v.id);
        }
    }
    
    cout << (s.empty() ? "YES" : "NO");

    return 0;
}

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


Measured memory_bytes: 6000
from collections import defaultdict


def calc(H, W):
    if H % 3 == 0 or W % 3 == 0:
        return 0
    ans = min(H, W)
    h1 = H // 2
    h2 = H - h1
    for w in range(W + 1):
        a = H * w
        b = (W - w) * h1
        c = (W - w) * h2
        ans = min(ans, max(abs(a - b), abs(a - c)))
    return ans


def solve(H, W):
    return min(calc(H, W), calc(W, H))


def main():
    H, W = map(int, input().split())
    print(solve(H, W))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    cout<<n/2+n%2<<endl;
}

Measured memory_bytes: 256
import math 
import bisect
import heapq
from collections import deque

n,m = map(int, input().split())
a = list(map(int,input().split()))
a = list(map(lambda x: x*(-1), a))

heapq.heapify(a)
for i in range(m):
    mx = heapq.heappop(a)*(-1)
    mx = mx/2.
    heapq.heappush(a, mx*(-1))

a = list(map(lambda x: x*(-1), a))
sum =0
for i in range(n):
    sum += int( heapq.heappop(a) )

print(sum)

Measured memory_bytes: 14540
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;

class Program
{
    public static void Main( )
    {
        var input = Console.ReadLine( ).Split( ).Select( int.Parse ).ToArray( );
        int N = input[ 0 ];
        int W = input[ 1 ];
        var adjacencyList = Enumerable.Range( 1, N + 1 ).Select( x => new List<int>( ) ).ToList( );
        for ( int i = 1; i < W + 1; i++ )
        {
            var AB = Console.ReadLine( ).Split( ).Select( int.Parse ).ToArray( );
            adjacencyList[ AB[ 0 ] ].Add( AB[ 1 ] );
            adjacencyList[ AB[ 1 ] ].Add( AB[ 0 ] );
        }

        /* BFS */
        var queue = new Queue<int>( );
        var ans = Enumerable.Repeat( int.MaxValue, N + 1 ).ToArray( );
        ans[ 0 ] = ans[ 1 ] = 1;
        queue.Enqueue( 1 );
        while ( queue.Count > 0 )
        {
            var nowIdx = queue.Dequeue( );
            foreach ( int adjIndex in adjacencyList[ nowIdx ] )
            {
                // unReached
                if ( ans[ adjIndex ] == int.MaxValue )
                {
                    ans[ adjIndex ] = nowIdx;
                    queue.Enqueue( adjIndex );
                }
            }
        }

        if ( ans.Contains( int.MaxValue ) )
        {
            Console.WriteLine( "No" );
        }
        else
        {
            Console.WriteLine( "Yes" );
            foreach ( var adjIndex in ans.Skip( 2 ) )
            {
                Console.WriteLine( adjIndex );
            }
        }


    }

}


Measured memory_bytes: 57256
// B - Magic 2
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int r,g,b,K; cin>>r>>g>>b>>K;
	rep(i, K+1) rep(j, K+1-i) rep(k, K+1-i-j){
		int rr = r * (1<<i), gg = g * (1<<j), bb = b * (1<<k);
		if(rr < gg && gg < bb){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}


Measured memory_bytes: 3608
def func(x):
    return (x+1)/2

n, k = map(int, input().split())
P = list(map(func, map(int, input().split())))
t = sum(P[0:k])
r = t
for i in range(n-k):
    t = t-P[i]+P[i+k]
    r = r if r>t else t
print(r)


Measured memory_bytes: 23588
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*   
*   文件名称：A.cpp
*   创 建 者：YaliKiWi
*   创建日期：2019年07月20日
*   描    述：
*
================================================================*/


#include<bits/stdc++.h>
using namespace std;
long long n;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	cout<<3*n*n;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
nums = list(sorted(map(int, input().split())))

dq = [0] * (nums[-1] + 1)

for num in nums:
    dq[num] += 1
    if dq[num] == 1:
        for i in range(num*2, nums[-1]+1, num):
            dq[i] += 2

print(dq.count(1))


Measured memory_bytes: 32300
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
ans,sa=1,abs(a-(t-h[0]*0.006))
for i in range(1,n):
    if sa>abs(a-(t-h[i]*0.006)):
        ans,sa=i+1,abs(a-(t-h[i]*0.006))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int n;
  cin>>n;
  vector<int> s(n);
  for(int &x:s){
    cin>>x;
  }
  int q;
  cin>>q;
  vector<int> t(q);
  for(int &x:t){
    cin>>x;
  }
  int count=0;
  for (int i=0;i<q;i++){
    for(int j=0;j<n;j++){
      if(t.at(i)==s.at(j)){
        count++;
        break;
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  int C[10][10];
  for(int i=0; i<10; i++)
    for(int j=0; j<10; j++)
      cin >> C[i][j];
  int A[H][W];
  for(int i=0; i<H; i++)
    for(int j=0; j<W; j++)
      cin >> A[i][j];

  for(int w=0; w<10; w++)
    for(int u=0; u<10; u++)
      for(int v=0; v<10; v++)
        C[u][v] = min(C[u][v], C[u][w] + C[w][v]);

  int mp = 0;
  for(int i=0; i<H; i++)
    for(int j=0; j<W; j++)
      if (A[i][j] != -1)
        mp += C[A[i][j]][1];

  cout << mp << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if (a>b && b!=1){
        cout<<"Alice"<<endl;
    }
    if (a==1 && a!=b){
        cout<<"Alice"<<endl;
    }
    if(b>a && a!=1){
        cout<<"Bob"<<endl;
    }
    if(b==1 && b!=a){
        cout<<"Bob"<<endl;
    }
    if(a==b){cout<<"Draw"<<endl;
    }
}


Measured memory_bytes: 256
<?php
list($H, $N) = ints();
$dp = array_fill(0, $N + 1, array_fill(0, $H + 1, 10**18));
$dp[0][0] = 0;
for($i = 1; $i <= $N; $i++){
  $dp[$i] = $dp[$i-1];
  $dpi = &$dp[$i];
  list($a, $b) = ints();
  for($j = 1; $j <= $H; $j++){
    if($j - $a >= 0){
      $dpi[$j] = min($dpi[$j], $dpi[$j-$a]+$b);
    }else{
      $dpi[$j] = min($dpi[$j], $b);
    }
  }
}
//o($dp);
echo $dp[$N][$H];
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}

Measured memory_bytes: 686584
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, d;
  cin >> n >> d;
  vector<ll> v1(n);
  vector<ll> v2(n);
  rep(i, n) cin>> v1[i] >> v2[i];
  int count = 0;
  for (int i = 0; i < n; ++i) {
    if(v1[i]*v1[i] + v2[i]*v2[i] <= d*d) count++;
  }
  cout << count << endl;

}


Measured memory_bytes: 6332