akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    string S, T;
    int ans = 1000000007;
    cin >> S >> T;
    for (int i = 0; i < int(S.size() - T.size() + 1); i++){
        int same = 0;
        for (int j = 0; j < int(T.size()); j++){
            if (S.at(i + j) == T.at(j)){
                same++;
            }
        }
        ans = min(ans, int(T.size() - same));
    }
    cout << ans << endl;
}

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

int main() {
  int N;

  cin >> N;

  vector<int> a(N);

  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }

  int i = 0;
  int ai = a.at(i);
  for (i = 0; i < N - 1; i++) {
    if (ai == 2) {
      break;
    }
    ai = a.at(ai - 1);
  }

  if (i < N - 1) {
    cout << i + 1 << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3796
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
int main() {
    long long N;
    cin >> N;
    long long yaku = 1;
    for(long long i = 1; i * i <= N; i++) {
        if(N % i == 0) {
            yaku = i;
        }
    }
    cout << (yaku + N / yaku) - 2 << endl;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, K = sc.nextInt
  val XYCs = List.fill(N)((sc.nextInt, sc.nextInt, sc.next))
  val K2 = 2 * K
  val m = Array.fill[Int](K2 + 1, K2 + 1){0}
  XYCs.foreach { t =>
    val x = t._1 % K2
    val y = (t._2 + (if (t._3 == "W") K else 0)) % K2
    m(x + 1)(y + 1) += 1
    m((x + K) % K2 + 1)((y + K) % K2 + 1) += 1
  }
  for(i <- 1 to K2; j <- 1 to K2) m(i)(j) += m(i - 1)(j) + m(i)(j - 1) - m(i - 1)(j - 1)
  val cs = for(i <- 1 to K; j <- 1 to K) yield m(i + K)(j + K) - m(i)(j + K) - m(i + K)(j) + m(i)(j)
  println(Math.max(cs.max, N - cs.min))
}

Measured memory_bytes: 155516
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}

int main() {
	vector<double> a(5); CI a;
	VI b(5);
	double tmp = 0;
	int memo = 0;
	int ans = 0;
	REP(i, 5) {
		a[i] /= 10;
		b[i] = ceil(a[i]);
		if (tmp < b[i] - a[i]) {
			memo = i;
			tmp = b[i] - a[i];
		}
		ans += b[i]*10;
		a[i] *= 10;
		b[i] *= 10;
	}

	CO ans - b[memo] + a[memo] EN;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  n, a, b = map(int, input().split())
  x = list(map(int, input().split()))
  
  ans = 0
  for i in range(n-1):
    ans += min(a * (x[i+1] - x[i]), b)
  
  print(ans)
  
  
  
  
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 20124
import sys
input = sys.stdin.readline
from bisect import *

def judge(x):
    cnt = 0
    
    for Ai in A:
        cnt += N-bisect_left(A, x-Ai+1)
    
    return cnt<M

def binary_search():
    l, r = 0, 2*max(A)
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
border = binary_search()
acc = [0]*(N+1)

for i in range(N):
    acc[i+1] = acc[i]+A[i]
    
cnt = 0
ans = 0

for Ai in A:
    j = bisect_left(A, border-Ai+1)
    cnt += N-j
    ans += (N-j)*Ai+acc[N]-acc[j]

ans += (M-cnt)*border
print(ans)

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

int main() {
    int N,M,X;
    cin >>N>>M>>X;
    vector<vector<int>> rikaido(N,vector<int> (M+1));
    rep(i,N){
        rep(j,M+1){
            cin>>rikaido[i][j];
        }
    }
    int amount= 10000000;
    for(int bit=0;bit<(1<<N);bit++){
        vector<int> now(M+1);
        bool able =true;
        rep(i,N){
            if(bit&(1<<i)){
                rep(j,M+1){
                    now[j]+=rikaido[i][j];
                }
            }
        }
        rep(j,M){
            if(now[j+1]<X){
                able=false;
            }
        }
        if(able){
            amount=min(amount,now[0]);
        }
    }
    if(amount==10000000){
        cout<<"-1"<<endl;
    }else{
        cout<<amount<<endl;
    }
}

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

int main(){
  ll k, n;
  cin >> k >> n;
  ll a[n];
  ll ans = INF;
  rep(i,n) cin >> a[i];
  for(int i = 1; i < n; i++) ans = min(ans,k-(a[i]-a[i-1]));
  ans = min(ans,-a[0]+a[n-1]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(){
	int i,j,k,n,b,f,r,v,cnt=1,house[5][4][11]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		house[b][f][r]+=v;
		if(house[b][f][r]<0){
			house[b][f][r]=0;
		}else if(house[b][f][r]>9){
			house[b][f][r]=9;
		}
	}
	for(i=1;i<=4;i++){
		for(j=1;j<=3;j++){
			for(k=1;k<=10;k++){
				printf(" %d",house[i][j][k]);
			}
			printf("\n");
		}
		if(i!=4){
			printf("####################\n");
		}
	}
	return 0;
}
		
			


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n,m,q;
    int s[666][666] = {{}};
    int a,b;

    Scd3(n,m,q);
    n+=2;

    Rep(i,m){
        Scd2(a,b);
        s[a][++b]++;
    }
    /*{{{ 
    Rep(i,m){
        Scd2(a,b);
        s[a][a]++;
        s[a][b+1]--;
        s[b+1][a]--;
        s[b+1][b+1]++;
    }*/

    Rep(i,n){
        Repe(j,n,1){
            s[i][j] += s[i][j-1];
        }
    }
    Rep(i,n){
        Repe(j,n,1){
            s[j][i] += s[j-1][i];
        }
    }

    //}}}*/


    Rep(i,q){
        Scd2(a,b);
        a--;
        b++;
        printf ("%d\n", s[b][b] - s[a][b] - s[b][a] + s[a][a] );
    }

    return 0;
}



Measured memory_bytes: 2688
N,A,B=[int(_) for _ in input().split() ]
if A>=B:
    BIG=A
    SMALL=B
if B>A:
    BIG=B
    SMALL=A

MAX=SMALL

if BIG+SMALL<=N:
    MIN=SMALL
    print(str(MAX)+' 0')
    exit(0)


MIN=BIG+SMALL-N
print(str(MAX)+' '+str(MIN))



Measured memory_bytes: 3060
#include<iostream>
int n;
int a[200000];
int main() {
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	if (n%2 == 0) {
		for (int i = 1; i < n; i++) {
			std::cout << a[n-i] << " ";
			i++;
		}
		for (int i = 0; i < n; i++) {
			std::cout << a[i] << " ";
			i++;
		}
	}
	else {
		for (int i = 1; i <= n; i++) {
			std::cout << a[n-i] << " ";
			i++;
		}
		for (int i = 1; i < n; i++) {
			std::cout << a[i] << " ";
			i++;
		}
	}
	system("pause");
	return 0;
}

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

#define MAX_N 100000

int main() {
    int N;
    cin >> N;
    int a[MAX_N+1];
    bool is_pushed[MAX_N+1];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        is_pushed[i] = false;
    }
    int target = 1;
    int count = 0;
    bool flag = false;
    while (1) {
        if (is_pushed[target-1]) break;
        is_pushed[target-1] = true;
        count++;
        target = a[target-1];
        if (target == 2) {
            flag = true;
            break;
        }
    }
    if (flag)
        cout << count << endl;
    else
        cout << -1 << endl;
    return 0;
}


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

typedef long long ll;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> mp(h);
    int initial_count = 0;
    for (int i = 0; i < h; i++) {
        cin >> mp[i];
        for (int k = 0; k < w; k++)
            if (mp[i][k] == '#')
                initial_count++;
    }
    queue<tuple<int, int, int>> q;
    int dx[] = {1, -1, 0, 0};
    int dy[] = {0, 0, 1, -1};
    q.push({0, 0, 0});
    mp[0][0] = '-';
    while (!q.empty()) {
        auto front = q.front();
        q.pop();
        int cur_h = get<0>(front);
        int cur_w = get<1>(front);
        int cur_count = get<2>(front);
        if (cur_h == h-1 && cur_w == w-1) {
            cout << h*w - initial_count - cur_count - 1;
            return 0;
        }
        for (int i = 0; i < 4; i++) {
            int new_h = cur_h + dx[i];
            int new_w = cur_w + dy[i];
            if (new_h < 0 || new_h >= h)
                continue;
            if (new_w < 0 || new_w >= w)
                continue;
            if (mp[new_h][new_w] == '.') {
                mp[new_h][new_w] = '-';
                q.push({new_h, new_w, cur_count+1});
            }
        }
    }
    cout << -1;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    char* s = new char[n];

    for(int i=0; i<n; i++) {
        cin >> s[i];
        if(s[i] == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }

    cout << "Three" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int X;
    cin >> X;
    write(X / 500 * 1000 + X % 500 / 5 * 5);
}

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

using namespace std;

int main()
{
  int a[13] = {0,
               1,
               2,
               1,
               3,
               1,
               3,
               1,
               1,
               3,
               1,
               3,
               1};

  int x, y;

  scanf("%d %d", &x, &y);

  printf(a[x] == a[y] ? "Yes" : "No");
}

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

int main()
{
	long long n,m,k;
	cin>>n>>m>>k;
	
	long long i,j;
	
	if(k>=0 && k<n)
	{
		i=n-k;
		j=m;
	}
	else if(k>=n && k<n+m)
	{
		i=0;
		j=m+n-k;
	}
	else
	{
		i=0;
		j=0;
	}
	
	cout<<i<<' '<<j<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  vector<int> imos(N + 2);
  REP(i, M)
  {
    cin >> L[i] >> R[i];
    // L[i]--, R[i]--;
    imos[L[i]]++;
    imos[R[i] + 1]--;
  }
  REP1(i, N)
  imos[i + 1] += imos[i];
  int ans = 0;
  REP1(i, N)
  {
    if (imos[i] == M)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

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

typedef long long int ll;

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

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

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

const int mod = 1000000007;

bool isIn(long xl, long yl, long xr, long yr, P target) {
  bool res = true;
  res = res && xr >= target.first;
  res = res && yr >= target.second;
  res = res && xl <= target.first;
  res = res && yl <= target.second;
  return res;
}

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

  int x, y, z, k;
  cin >> x >> y >> z >> k;
  
  vector<long> a(x);
  vector<long> b(y);
  vector<long> c(z);

  fillLong(a, x);
  fillLong(b, y);
  fillLong(c, z);

  vector<long> ab;
  vector<long> abc;

  rep(i, x) {
    rep(j, y) {
      ab.push_back(a[i] + b[j]);
    }
  }

  sortvinv(ab);

  rep(i, min(k, (int)ab.size())) rep(j, z) {
    abc.push_back(ab[i] + c[j]);
  }

  sortvinv(abc);

  rep(i, k) {
    cout << abc[i] << endl;
  }
}


Measured memory_bytes: 43112
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=(1<<18)+10;
int n,k,s,t,m;
vector<int> a;
ll C[55][55],ways[55];
ll cnt[maxn];
void solve()
{
	for(int i=0;i<m;i++)
	{
		for(int msk=0;msk<(1<<m);msk++)
		{
			if(!(msk>>i&1))
			{
				cnt[msk^(1<<i)]+=cnt[msk];
			}
		}
	}
}
void solve2()
{
	for(int i=m-1;i>=0;i--)
	{
		for(int msk=0;msk<(1<<m);msk++)
		{
			if(!(msk>>i&1))
			{
				cnt[msk^(1<<i)]-=cnt[msk];
			}
		}
	}
}
int main()
{
	scanf("%d%d%d%d",&n,&k,&s,&t);
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		if(((x&s)==s)&&((x|t)==t))a.push_back(x);
	}
	if(a.empty())
	{
		printf("0\n");
		return 0;
	}
	n=a.size();
	C[0][0]=1;
	for(int i=1;i<55;i++)
	{
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++)C[i][j]=C[i-1][j]+C[i-1][j-1];
	}
	for(int i=0;i<55;i++)
	{
		for(int j=0;j<=i&&j<k;j++)ways[i]+=C[i][j];
	//	if(i<=n)cout<<i<<" "<<ways[i]<<endl;
	}
	int free=(s^t);
	vector<int> bts;
	bts.clear();
	for(int i=0;i<18;i++)if(free>>i&1)bts.push_back(i);
	m=bts.size();
	for(int i=0;i<n;i++)
	{
		int tmp=a[i];
		a[i]=0;
		for(int j=0;j<m;j++)if(tmp>>bts[j]&1)a[i]|=(1<<j);
	//	cout<<a[i]<<endl;
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		memset(cnt,0,sizeof(cnt));
		for(int j=i+1;j<n;j++)
		{
			cnt[a[i]^a[j]]++;
		}
	//	for(int j=0;j<(1<<m);j++)cout<<cnt[j]<<endl;system("pause");
		solve();
		for(int j=0;j<(1<<m);j++)
		{
			cnt[j]=ways[cnt[j]];
		}
		solve2();
		ans+=cnt[(1<<m)-1];
	}
//	if(ans<0)ans=-ans;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5836
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef long long ll;
const int MAX_N=2e5;
vector<int> G[MAX_N];
int N;
unordered_map<int,int> memo[MAX_N];
int mxv[MAX_N],ans[MAX_N],par[MAX_N];
void calmxv(int v,int p){
	if (v!=0){
		mxv[v]=max(v,mxv[p]);
	}
	for(auto e:G[v]){
		if (e!=p){
			calmxv(e,v);
		}
	}
}
int dfs(int v,int x,int p){
	if (memo[v].find(x)!=memo[v].end()){
		return memo[v][x];
	}
	int res=0;
	for(auto e:G[v]){
		if (e!=p && e<x){
			res+=dfs(e,x,v)+1;
		}
	}
	return memo[v][x]=res;
}
void calpar(int v,int p){
	par[v]=p;
	for(auto e:G[v]){
		if (e!=p){
			calpar(e,v);
		}
	}
}
void slv(int v,int p){
	if (v!=0){
		if (p==0){
			ans[v]=1;
		}else if (v>mxv[par[p]]){
			ans[v]=ans[p]+dfs(v,mxv[p],p)+1;
		}else{
			ans[v]=ans[p]+dfs(v,mxv[p],p)-dfs(v,mxv[par[p]],p);
		}
	}
	for(auto e:G[v]){
		if (e!=p){
			slv(e,v);
		}
	}
}
int main(){
	cin>>N;
	REP(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	calpar(0,-1);
	mxv[0]=0;
	calmxv(0,-1);
	ans[0]=0;
	slv(0,-1);
	REP(i,N-1){
		if (i){
			cout<<" ";
		}
		cout<<ans[i+1];
	}
	cout<<endl;
	return 0;
}

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

#define ld long double
#define ll long long int
#define ull unsigned long long int

using namespace std;

int main() {

    long long N, K;
    cin >> N >> K;

    double count = 0;
    double ans;


    for (int i = 1; i <= N; ++i) {
        if (i >= K) {
            count++;
            continue;
        }

        // i = 3, K=10のとき
        int temp = i;
        int tempCount = 0;
        while (1) {
            temp = temp * 2;
            tempCount++;
            if (temp >= K) {
                count += pow(0.5, tempCount);
                break;
            }
        }

    }


    ans = count / N;

    cout << fixed << setprecision(13) << ans << endl; // C++

    // cout << ans << endl;

}

Measured memory_bytes: 512
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	ll A, B, M; cin >> A >> B >> M;
	vector<ll> a(A), b(B);
	rep(i, A)cin >> a[i];
	rep(i, B)cin >> b[i];
	vector<ll> x(M), y(M), e(M);
	rep(i, M) cin >> x[i] >> y[i] >> e[i];

	vector<ll> c(A), d(B);
	rep(i, A) c[i] = a[i];
	rep(i, B) d[i] = b[i];

	sort(ALL(c)); sort(ALL(d));
	int ans = c[0] + d[0];

	rep(i, M) {
		if (ans > a[x[i] - 1] + b[y[i] - 1] - e[i])ans = a[x[i] - 1] + b[y[i] - 1] - e[i];

	}

	cout << ans << endl;
}

Measured memory_bytes: 5760
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

// splitテゥツ鳴「テヲツ閉ー (1テヲツ鳴?・ツュツ療」ツδ静」ツδシテ」ツつクテ」ツδァテ」ツδウテ」ツ?づヲツ個?・ツョツ堙」ツ?陛」ツつ古」ツ?淌ヲツ鳴?・ツュツ療」ツ?ァテヲツ鳴?・ツュツ療・ツ按療」ツつ津・ツ按?・ツ可イ)
vector<string> split(string s, char c) {
    vector<string> ret;
    string temp;
    replace(s.begin(), s.end(), c, ' ');
    stringstream ss(s);
    while(ss >> temp) ret.push_back(temp);
    return ret;
}

bool visited[100010];
vector<int> G[100010];
map<string, int> m;
map<int, string> rev;
int id = 0;

int get_id(string x) {
    if(m.count(x)) return m[x];
    else {
        m[x] = id;
        rev[id++] = x;
        return m[x];
    }
}

void add_edge(string x, string y) {
    int a = get_id(x), b = get_id(y);
    G[a].push_back(b);
}

void dfs(set<int> &S, int p, int par=-1) {
    bool leaf = true;
    for(auto to : G[p]) {
        if(to == par) continue;
        leaf = false;
        if(visited[to]) continue;
        visited[to] = true;
        dfs(S, to, p);
    }
    if(leaf) S.insert(p);
}

signed main() {
    int N;
    while(cin >> N, N) {
        m.clear();
        memset(visited, false, sizeof(visited));
        rep(i,0,100010) G[i].clear();
        id = 0;

        rep(i,0,N) {
            string s; cin >> s;
            vector<string> t = split(s, ':');
            t[1] = t[1].substr(0, (int)t[1].length() - 1);

            string from = t[0];
            vector<string> to = split(t[1], ',');
            rep(j,0,to.size()) {
                add_edge(from, to[j]);
            }
        }

        set<int> S;
        dfs(S, 0);
        cout << S.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 5932
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip> // for /* << std::fixed << std::setprecision(k) << */
using namespace std;

//defines

#define forn(n) for(int i = 0; i < n; i++)
#define pb push_back
#define int long long

int32_t main() {
	int n;
	
	cin >> n;
	
	vector<double> p(n);
	
	for (int i = 0; i < n; i++)
		cin >> p[i];
		
	vector<vector<double>> dp(n+1, vector<double>(n+1));
	
	dp[0][0] = 1;
	
	for (int i = 1; i <= n;i++)
		dp[0][i] = 0;
	
	for (int i = 1; i <= n;i++) {
		dp[i][0] = dp[i-1][0]*(1-p[i-1]);
		
		for (int j = 1; j <= n; j++) 
			dp[i][j] = dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*p[i-1];
	}
		
	double ans = 0;
	
	for (int i = (n+1)/2;i <= n;i++)
		ans += dp[n][i];
		
	cout << std::fixed << std::setprecision(15) << ans;
}



Measured memory_bytes: 73784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N, M; cin >> N >> M;
    vector<int> p(M), y(M);
    vector<int> order[N+1];

    for(int i=0; i<M; i++){
        cin >> p[i] >> y[i];
        order[p[i]].push_back(y[i]);
    }

    for(int i=1; i<=N; i++) sort(order[i].begin(), order[i].end());

    for(int i=0; i<M; i++){
        auto itr = lower_bound(order[p[i]].begin(), order[p[i]].end(), y[i]);
        int rank = itr - order[p[i]].begin() + 1;
        printf("%06d%06d\n", p[i], rank);
    }
}

Measured memory_bytes: 7680
import sys
# A,B,C = [int(n) for n in input().split()]
N = int(input())
# S = str(input())
# T = str(input())
# a,b,c = [int(n) for n in input().split()]
MARCH = ["M","A","R","C","H"]
MARCHn = {"M":0,"A":0,"R":0,"C":0,"H":0}
S = [0]*N
s = set()
n = 0
P=[0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2]
Q=[1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3]
R=[2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4]
for i in range(N):
    S[i] = str(input())
    initi = S[i][0]
    if(initi in MARCH):
        MARCHn[initi] = MARCHn[initi]+1
ans = 0
for i in range(10):
    ans += MARCHn[MARCH[P[i]]]*MARCHn[MARCH[Q[i]]]*MARCHn[MARCH[R[i]]]
print(ans)


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  ll n; std::cin >> n;
  vector<ll> c(5); rep(i, 5) std::cin >> c[i];
  sort(rng(c));
  std::cout << (n + c[0] - 1) / c[0] + 4 << "\n";
}


Measured memory_bytes: 256
n,*L=map(int,open(0).read().split())
con=[[]for _ in range(n)]
for a,b in zip(*[iter(L)]*2):
	con[a-1].append(b-1)
	con[b-1].append(a-1)
dist=[-1]*n
dist[0]=0
farthest=0
q=[0]
while q:
	cur=q.pop()
	for nxt in con[cur]:
		if dist[nxt]<0:
			dist[nxt]=dist[cur]+1
			if dist[farthest]<dist[nxt]:
				farthest=nxt
			q.append(nxt)
dist=[-1]*n
dist[farthest]=0
diameter=0
q=[farthest]
while q:
	cur=q.pop()
	for nxt in con[cur]:
		if dist[nxt]<0:
			dist[nxt]=dist[cur]+1
			diameter=max(diameter,dist[nxt])
			q.append(nxt)
print("Second" if diameter%3==1 else "First")

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

int main() {
	int n,m;cin>>n>>m;
	vector<long long> x(n),y(m);
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	for(int i=0;i<m;i++){
		cin>>y[i];
	}
	long long def=1;
	for(int i=0;i<9;i++){
		def*=10;
	}
	def+=7;
	int interval=n-1;
	vector<long long> mul(interval);
	long long temp=interval;
	mul[0]=temp;
	for(int i=1;i<(interval+1)/2;i++){
		temp+=interval-2*i;
		mul[i]=temp;
	}
	for(int i=interval-1;i>=interval/2;i--){
		mul[i]=mul[interval-i-1];
	}
	long long xsum=0;
	long long ysum=0;
	for(int i=0;i<interval;i++){
		xsum+=mul[i]*(x[i+1]-x[i]);
		if(xsum>def)xsum%=def;
	}
	interval=m-1;
	temp=interval;
	mul=vector<long long>(interval);
	mul[0]=temp;
	for(int i=1;i<(interval+1)/2;i++){
		temp+=interval-2*i;
		mul[i]=temp;
	}
	for(int i=interval-1;i>=interval/2;i--){
		mul[i]=mul[interval-i-1];
	}
	for(int i=0;i<interval;i++){
		ysum+=mul[i]*(y[i+1]-y[i]);
		if(ysum>def)ysum%=def;
	}
	long long ans=xsum*ysum;
	if(ans>def)ans%=def;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=2e5+5;
pair<int,int>pre[maxn],after[maxn];
int n;
int vis[maxn],a[maxn],b[maxn],p[maxn];
int solve(int s){
	int cnt=0;
	for(int i=0;i<n;i++)vis[i]=0;
	for(int i=0;i<n;i++){
		if((s>>i)&(1)){
			cnt++;
			pre[i]=mkp(b[i],1);
			after[i]=pre[i];
		}
		else {
			pre[i]=mkp(a[i],0);
			after[i]=pre[i];
		}
	}
	if(cnt&1)return inf;
	cnt=0;
	sort(after,after+n);

	//for(int i=0;i<n;i++)cout<<after[i].first<<" "<<after[i].second<<endl;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			//if(i==1&&j==0)cout<<abs(i-j)%2<<" fuck "<<pre[i].second<<" "<<vis[j]<<endl;
			if(after[j].first==pre[i].first&&((abs(i-j)%2)==pre[i].second)&&vis[j]==0){
				//cout<<abs(i-j)%2<<" fuck1 "<<pre[i].second<<" "<<vis[j]<<endl;
				vis[j]=1,cnt++,p[i]=j;
				break;
			}
		}
	}
//	cout<<cnt<<" "<<n<<endl;
	if(cnt!=n)return inf;
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(p[j]<p[i])ans++;
		}
	}

	return ans;
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);
	int ans=inf;
	//solve(6);
	for(int i=0;i<1<<n;i++){
		ans=min(ans,solve(i));
	}
	printf("%d\n",ans==inf?-1:ans);
}

Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n], b = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = a[i];
		}
		Arrays.sort(a);
		int max = a[n-1];
		int next = a[n-2];
		if(max == next) {
			for(int i =0; i < n; i++) {
				System.out.println(max);
			}
		}else {
			for(int x : b) {
				if(x == max) {
					System.out.println(next);
				}else {
					System.out.println(max);
				}
			}
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 58516
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {

  int h, w, n, sr, sc;
  string s, t;
  int cs[4] = {}, ct[4] = {};
  cin >> h >> w >> n;
  cin >> sr >> sc;
  cin >> s >> t;

  int x;
  x = sc;
  //s-l t-r
  rep(i, n) {
    if (s[i] == 'L') x--;
    if (x < 1) {
      cout << "NO\n";
      return 0;
    }
    if (t[i] == 'R' && x < w) x++;
  }
  
  //s-r t-l
  x = sc;
  rep(i, n) {
    if (s[i] == 'R') x++;
    if (x > w) {
      cout << "NO\n";
      return 0;
    }
    if (t[i] == 'L' && x > 1) x--;
  }

  //s-u t-d
  x = sr;
  rep(i, n) {
    if (s[i] == 'U') x--;
    if (x < 1) {
      cout << "NO\n";
      return 0;
    }
    if (t[i] == 'D' && x < h) x++;
  }

  //s-d t-u
  x = sr;
  rep(i, n) {
    if (s[i] == 'D') x++;
    if (x > h) {
      cout << "NO\n";
      return 0;
    }
    if (t[i] == 'U' && x > 1) x--;
  }

  cout << "YES\n";

  return 0;

}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	string s; cin >> s;
	int ans = 0, cnt = 0;
	for(char c : s) {
		if(c == 'R') ++cnt;
		else cnt = 0;
		ans = max(ans, cnt);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
int main(void){
    ll h,w,k;
    cin>>h>>w>>k;
    char c[h][w];
    ll count_b=0;
    rep(0,i,h){
        rep(0,j,w){
            cin>>c[i][j];
            if(c[i][j]=='#')++count_b;
        }
    }
    //cout<<count_b<<endl;
    ll ans=0;
    rep(0,bit1,1<<h){
        rep(0,bit2,1<<w){
            ll tmp=0;
            vector<ll>s1,s2;
            rep(0,i,h)if(bit1&1<<i)s1.pb(i);
            rep(0,i,w)if(bit2&1<<i)s2.pb(i);
            ll n=s1.size(),m=s2.size();
            //if(n==0&&m!=0)continue;
            //if(n!=0&&m==0)continue;
            rep(0,i,n){
                rep(0,j,w){
                    if(c[s1[i]][j]=='#')++tmp;
                }
            }
            rep(0,i,h){
                rep(0,j,m){
                    if(bit1&1<<i)continue;
                    if(c[i][s2[j]]=='#')++tmp;
                }
            }
            if(count_b-tmp==k)++ans;
            //cout<<bit1<<" "<<bit2<<" "<<count_b-tmp<<endl;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3616
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        long max = 0;

        for(int i = 0;i < n;i++){
            int dis = sc.nextInt();
            list.add(dis);
        }

        if(list.contains(0)){
            max = k- list.get(n-1);
        }else{
            max = k - list.get(n-1) + list.get(0);
        }

        for(int i = 1;i < n;i++){
            long distance = list.get(i)-list.get(i-1);
            if(distance>max){
                max = distance;
            }
        }
        
        System.out.println(k-max);
    }
}

Measured memory_bytes: 86652
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template <class T> inline T gcd(T a, T b) {if(a==0) return b; return gcd(b%a,a);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd(a,b);}
template <class T> inline T sum(vector<T> &vec) {T res=0; for (int i = 0; i < vec.size(); i++) res += vec[i]; return res;}
template <class T> inline T mpow(T a, T b) {if(b==0)return 1; T c = mpow(a,b/2);if(b%2==1)return c*c*a; return c*c;}
const int INF = 1 << 30;
const long long INFLL = 1LL << 60;
typedef pair<int, int> P;

#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define FOR(i,n) for (int (i)=0;(i)<(n);(i)++)
#define REPB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define FORB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define SORT(A) sort((A).begin(),(A).end())


int main() {
    /*
    int N,M; cin >> N >> M;
    if (N == M) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }*/

    /*
    int a, b; cin >> a >> b;

    int c = 0, d = 0;
    FOR(i,b-1) {
        c += a;
        c *= 10;
    } c += a;
    FOR(i,a-1) {
        d += b;
        d *= 10;
    } d += b;
    cout << max(c,d) << endl;
    */

    int N; cin >> N;
    vint P(N);
    FOR(i,N) cin >> P[i];
    
    int m = 1e9, res = 0;
    FOR(i,N) {
        if (m >= P[i]) {
            res++;
            m = P[i];
        }
    }
    cout << res << endl;




}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;
const double EPS = 1e-8, INF = 1e12, PI = acos(-1.0);
typedef complex<double> P;
namespace std{
	bool operator<(const P& a, const P& b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
inline double cross(const P& a, const P& b){ return imag(conj(a)*b); }
inline double dot(const P& a, const P& b){ return real(conj(a)*b); }
struct L : public vector<P>{
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};
typedef vector<P> G;
inline int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if(cross(b, c) >  EPS)   return +1;      // counter clockwise
	if(cross(b, c) < -EPS)   return -1;      // clockwise
	if(dot(b, c)   < -EPS)   return +2;      // c--a--b on line
	if(norm(b)+EPS <norm(c)) return -2;      // a--b--c on line
	return 0;                                   // c is between a and b (inclusive)
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0];
  if (abs(A) < EPS) return m[0];
  return m[0] + B / A * (m[1] - m[0]);
}
P circumcenter(const P &x, const P &y, const P &z){
	P a = y - x, b = z - x;
	return crosspoint(L(a / 2.0, a / 2.0 + a * P(0, 1)),
		L(b / 2.0, b / 2.0 + b * P(0, 1))) + x;
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	G ps;
	rep(i, n){
		int x, y; cin >> x >> y;
		ps.emplace_back(P(x, y));
	}
	double ans = INF;
	
	auto calc = [&](P c){
		double res = 0;
		for(P p : ps) res = max(res, abs(p - c));
		return res;
	};
	
	rep(i, n) rep(j, i) ans = min(ans, calc((ps[i] + ps[j]) * 0.5));
	rep(i, n) rep(j, i) rep(k, j) ans = min(ans, calc(circumcenter(ps[i], ps[j], ps[k])));
	
	printf("%.20f\n", ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var g = 0;
        var p = 0;
        var resv = 0;
        var resl = 0;
        for(var i = 0; i < str.Length; i++)
        {
            if (str[i] == 'g')
            {
                if (g > p)
                {
                    p++;
                    resv++;
                }
                else g++;
            }
            else
            {
                if (g > p)
                    p++;
                else
                {
                    g++;
                    resl++;
                }
            }
        }
        WriteLine(resv - resl);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}

Measured memory_bytes: 13116
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    P, Q, R = map(int, input().split())
    print(sum([P, Q, R]) - max([P, Q, R]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include<iostream>

int main(){
	int a[44722],b,c,d,e=0,f=1;
	while(std::cin >> b >> c){
	for(d=2;d*d<=b||d*d<=c;){
		if(b%d==0&&c%d==0){
			a[e] = d;
			e++;
			b = b / d;
			c = c / d;
		}else break;
	}
	for(d=3;d*d<=b||d*d<=c;d=d+2){
		while(1){
			if(b%d==0&&c%d==0){
			a[e] = d;
			e++;
			b = b / d;
			c = c / d;
			}else break;
		}
	}
	a[e] = 0;
	for(e=0;a[e]>0;e++){
		f = f * a[e];
	}
	std::cout << f;
	f = f * b * c;
	std::cout << " " << f << std::endl;
	e = 0;
	f = 1;
	}

	return 0;
}

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

int main(){
  int P,Q,R;
  cin >> P >> Q >> R;
  int a = P + Q;
  int b = P + R;
  int c = Q + R;
  int d =min(a,b);
  cout << min(c,d) << endl;
}

Measured memory_bytes: 256
import java.io.*;

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

        try{
            line = br.readLine();
        }catch(IOException e){ 
            System.out.println(e);
        }

        while(line != null){
            String[] dataS = new String[2];
            dataS = line.split(" " , 2);

            int[] dataI = new int[2];
            
            for(int i = 0; i < 2; i++){
                dataI[i] = Integer.parseInt(dataS[i]);
            }

            System.out.println(dataI[0] + dataI[1]);
            try{
                line = br.readLine();
            }catch(IOException e){
                System.out.println(e);
            }
    }
    }
}

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

int main(){
  int n,m,numa=-1,j=0;
  ll ans=0,k,ansm=0,ttl=0;cin>>n>>m>>k;
  vector<ll> a(n,0),b(m,0);
  bool f=0;

  REP(i,n){
    cin>>a.at(i);
    if(!f){ 
      if(ttl+a.at(i)<=k){
        ttl+=a.at(i);
        ans++;
        ansm=max(ansm,ans);
        numa=i;
      }else f=1;      
    }
  }
  REP(i,m) cin>>b.at(i);

  if(numa==-1){
    while(j<m&&ttl+b.at(j)<=k){
      ttl+=b.at(j);
      ans++;
      ansm=max(ansm,ans);
      j++;
    }
  }else for(int i=numa;i>=0;i--){
    while(j<m&&ttl+b.at(j)<=k){
      ttl+=b.at(j);
      ans++;
      ansm=max(ansm,ans);
      j++;
    }
    ttl-=a.at(i);
    ans--;
  }
  while(j<m&&ttl+b.at(j)<=k){
    ttl+=b.at(j);
    ans++;
    ansm=max(ansm,ans);
    j++;
  }

  cout<<ansm;
}

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

int main()
{
    int r = 0;
    int c = 0;
    
    std::cin >> r;
    std::cin >> c;

    std::vector< std::vector<int> > table(r + 1, std::vector<int>(c + 1, 0));
    
    for(int i = 0; i < r; ++i)
    {
        for(int j = 0; j < c; ++j)
        {
            std::cin >> table.at(i).at(j);
        }
    }
    
    for(int i = 0; i < r; ++i)
    {
        for(int j = 0; j < c; ++j)
        {
            table.at(i).at(c) += table.at(i).at(j);
        }
    }
    
    for(int i = 0; i < r; ++i)
    {
        for(int j = 0; j < c + 1; ++j)
        {
            table.at(r).at(j) += table.at(i).at(j);
        }
    }    
    
      for(int i = 0; i < r + 1; ++i)
    {
        for(int j = 0; j < c + 1; ++j)
        {
            std::cout << table.at(i).at(j);
            if(c != j)
            {
                std::cout << " ";
            }
            else
            {
                std::cout << std::endl;
            }
        }
    }      
    
    return 0;
}


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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { for (auto& _e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }

int main(void) {
	ll A, B;
	cin >> A >> B;
	int cnt = 0;
	while (A <= B) {
		A *= 2;
		++cnt;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
using namespace std;

const int mxN = 1e5;
int dp[mxN];
bool vis[mxN];
vector<int> adj[mxN];

void dfs(int u) {
    vis[u] = 1;
    for(int v : adj[u]) {
        if(!vis[v])
            dfs(v);
        dp[u] = max(dp[u], 1+dp[v]);
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    memset(dp, 0, sizeof(dp));
    memset(vis, 0, sizeof(vis));
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v, --u, --v;
        adj[u].push_back(v);
    }

    for(int i = 0; i < n; i++) {
        if(!vis[i])
            dfs(i);
    }
    
    int ans = *max_element(dp, dp+n);
    cout << ans << '\n';
}


Measured memory_bytes: 12244
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[]str = Console.ReadLine().Split();
		long A = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		long C = long.Parse(str[2]);
		long D = long.Parse(str[3]);
		long ans = -(long)Math.Pow(10,18);
		ans = Math.Max(ans,A*C);
		ans = Math.Max(ans,A*D);
		ans = Math.Max(ans,B*C);
		ans = Math.Max(ans,B*D);
		Console.WriteLine(ans);
	}
}

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

using namespace std;

int main() {

    int a, b, c, d;

    cin >> a >> b >> c >> d;
    int ans;

    // 重複期間があるか
    if  (c >= b)
    {
        cout << 0 << endl;
        return 0;
    }

    int start = max(a,c);
    int last = min(b,d);

    ans = last - start;

    ans = max(0, ans);

    cout << ans << endl;

}


Measured memory_bytes: 256