akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    string s, t;
    getline(cin, s);
    getline(cin, t);

    bool correct = true;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            correct = false;
            break;
        }
    }
    cout << (correct ? "Yes" : "No");
    return 0;
}

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

const ll mod=1000000007;

int main() {
  ll n,k;
  cin >> n >> k;
  vector<int> v(n);
  r(i,n){
    cin >> v[i];
    v[i]--;
  }
  int a[n],b=1,loop1,loop2;
  r(i,n)a[i]=0;
  queue<int> q;
  q.push(0);
  while(!q.empty()){
    if(a[v[q.front()]]!=0){
      loop1=a[v[q.front()]];
      loop2=b;
      break;
    }
    a[v[q.front()]]=b;
    q.push(v[q.front()]);
    q.pop();
    b++;
  }
    if(k>=loop2){
      k=(k-loop1)%(loop2-loop1)+loop1;
    }
      r(i,n)if(a[i]==k)cout<<i+1<<endl;
}


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

int main()
{
 long long a,b,k;
  cin >> a >> b >> k;
  
  if(k>a){
    b = b-(k-a);
    a=0;
  }
  else
    a=a-k;
  if(a<0)
    a=0;
  if(b<0)
    b=0;
  cout << a << " "<<b << endl;
  return 0;
}

Measured memory_bytes: 256
n, h = map(int, input().split())
arr = []
for _ in range(n) :
    a,b = map(int, input().split())
    arr.append((a,-1))
    arr.append((b,1))

arr.sort()
arr.reverse()

cnt = 0
ans = 10**9 + 100
for p in arr :
    if p[1] == -1 :
        # a
        ans = min(ans, cnt + (h+p[0]-1)//p[0])
    elif p[1] == 1 and h>0 :
        # b
        h -= p[0]
        cnt += 1
        if h <= 0 :
            h = 0
            ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 24332
// きさま！ 見ているなッ！

#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>
#include<thread>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;


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

	int total = 0;

	vec A(N);
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		total += A[i];
	}

	int cnt=0;
	for (int i = 0; i < N; ++i)
	{
		if (A[i]* (4 * M) >= total)++cnt;
	}

	if (cnt >= M)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;

long long a[5], n, m, i;
char s[11];

int main()
{
	while(cin >> n)
	{
		getchar();
		for(i = 0; i < 5; i++) a[i] = 0;
		for(i = 0; i < n; i++)
		{
			scanf("%s",s);
			if(s[0] == 'M') a[0]++;
			if(s[0] == 'A') a[1]++;
			if(s[0] == 'R') a[2]++;
			if(s[0] == 'C') a[3]++;
			if(s[0] == 'H') a[4]++;
			getchar();
		}
		m = a[0] * a[1] * a[2] + a[0] * a[1] * a[3] + a[0] * a[1] * a[4] + a[1] * a[2] * a[3] + a[1] * a[2] * a[4] + a[2] * a[3] * a[4] + a[1] * a[4] * a[3] + a[0] * a[3] * a[4] + a[0] * a[2] * a[3] + a[0] * a[2] * a[4];
		cout << m << endl;
	}
	return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    if(n==1)
    cout << "Hello World" << "\n ";
    else
    {
        int x, y;
        cin >> x >> y;
        cout
            << x+y<< "\n";
    }
    
        

    return 0;
}

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

int main(){
  int m1,d1,m2,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1!=m2)cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long long unsigned int ull;
#define INF 1LL << 29

int main(){
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int> > trains(N, vector<int>(N,0));// iからjまで走る列車の数
	for (int i = 0; i < M; i++) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		trains[l][r]++;
	}
	vector<vector<int> > train_s(N, vector<int>(N + 1, 0)); //るいせきわ
	for (int i = 0; i < N; i++)for (int j = 1; j < N + 1; j++) {
		if (j == 1) {
			train_s[i][j-1] = 0;
		}
		train_s[i][j] = train_s[i][j - 1] + trains[i][j - 1];
	}
	for (int i = 0; i < Q; i++) {
		int p, q, ans = 0;
		cin >> p >> q;
		p--; q--;
		for (int i = p; i <= q; i++) {
			if (p != 0) {
				ans += train_s[i][q + 1] - train_s[i][p - 1];
			}
			else {
				ans += train_s[i][q + 1];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i,N) {
    cin >> A[i];
  }
  rep(i,N) {
    if(A[i] % 2 == 0) {
      if(A[i] % 3 == 0 || A[i] % 5 == 0) continue;
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N, res, l, r;
  
  	cin >> N;
  	for( int i = 0; i < N; i++) {
    	cin >> l >> r;
      	res += r-l+1;
    }
  
  	cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
typedef long long ll;

int main(void) {
  ll i, j, q, a, b, t, ans;
  scanf("%lld", &q);
  for(i = 0; i < q; ++i) {
    scanf("%lld%lld", &a, &b);
    if(a > b) t = b, b = a, a = t;
    ans = sqrt(a * b - 1);
    j = ans + 1;
    if(j == a) ++j;
    else {
      if(ans != a && (a * b - 1) / ans == (a * b - 1) / j) --ans;
      --ans;
    }
    ans += (a * b - 1) / j;
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, digit, ans;
  ans = -1;
  string stN;  
  char chN[3];
  cin >> N >> M;
  
  vector<vector<char>> con (2, vector<char>(M));  
  for(int i = 0;i < M;i++){
  cin >> con.at(0).at(i) >> con.at(1).at(i);
  }
  
  for(int i = 0;i < 999;i++){
  bool gudge = true;
  stN = to_string(i);
  digit = stN.size();
    if(digit != N){
    continue;
    } 
    for(int k = 0; k < N;k++){
    chN[k] = stN.at(k);
    }
    
    for(int j = 0;j < M;j++){
      if(con.at(0).at(j) == '1'){
        if(chN[0] != con.at(1).at(j)){
        gudge = false;
        }
      }
      else if(con.at(0).at(j) == '2'){
        if(chN[1] != con.at(1).at(j)){

        gudge = false;
        }      
      }      
      else if(con.at(0).at(j) == '3'){
        if(chN[2] != con.at(1).at(j)){

        gudge = false;
        }   
      }
    }
    if(gudge){
    ans = i;
    break;
    }
  }

  cout << ans << endl;
}

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

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

using ll = long long;
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int i = 1;
	while(1){
		if(i < n) i *= 2;
		else if(i == n) break;
		else{
			i /= 2;
			break;
		}
	}
	cout << i << "\n";
	return 0;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    x, k, d = MII()
    if k*d <= abs(x):
        if x >= 0:
            print(x-k*d)
        else:
            print(abs(x+k*d))
    else:
        m = x//d
        n = x%d
        if (k-m)%2==0:
            print(n)
        else:
            print(abs(n-d))

if __name__ == '__main__':
    main()

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

int main(){

    for(char c; cin >> c; ){
        if(c==',')cout<<' ';
        else cout<<c;
    } 
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}
int highestPowerof2(int n)
{
   int p = (int)log2(n);
   return (int)pow(2, p);  
}
ll powermod(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;  
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
 
int main()
{
    ll n;
    cin>>n;
  cout<<((powermod(10,n,M)-(2*powermod(9,n,M))%M+powermod(8,n,M))%M+M)%M;
        
}


Measured memory_bytes: 3660
#include<cstdio>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a==b) printf("Draw\n");
	else if((a>b && b!=1) || (a==1 && b!=1)) printf("Alice\n");
	else printf("Bob\n");
	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  ll L,R;
  cin>>L>>R;
  ll num=2019;
  if(L==R){
    cout<<(L*R)%num<<endl;
    return 0;
  }
  ll l=L%num;
  ll r=R%num;
  ll LL=L/num;
  ll RR=R/num;
  ll Min=INF;
  if(LL==RR){
    vector<int>a;
    for(int i=l;i<=r;i++)a.push_back(i);
    for(int i=0;i<a.size();i++){
      for(int j=i+1;j<a.size();j++){
        Min=min(Min,(a[i]*a[j])%num);
      }
    }
  }
  else{
    Min=0;
  }
  cout<<Min<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>


int main(){
  int day;
  cin >> day;
  
  //int day = (d[0] - '0') * 10 + d[1] - '0';
  int n = 25 - day;
  cout << "Christmas";
  for(int i = 0; i < n; i++){
    cout << " Eve";
  }
  
  cout << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<functional>
#include<math.h>
#include<algorithm>
typedef long long ll;
using namespace std;

int main(){
  int N;
  int K;
  string S;

  cin >> N >> S >> K;

  char dame = S[K-1];
  for(int i=0;i<N;i++){
    if(S[i]!=dame){
      S[i] = '*';
    }
  }

  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
//Have FUN

using namespace std;

#include<bits/stdc++.h>

const int maxn=1e5+10;

bool mark[maxn];
int n,m,s,t,h[maxn],up[maxn],par[maxn];
vector <int> a[maxn];

vector < pair<int,int> > ans;
vector <pair<int, int> > ed;
void input()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>s>>t;
		a[s].push_back(t);
		a[t].push_back(s);
		if(s>t)
            swap(s,t);
		ed.push_back(make_pair(s,t));
	}
}

void dfs(int x)
{
	mark[x]=true;
	up[x]=h[x];
	for(int i=0;i<a[x].size();i++)
	{
		int child=a[x][i];
		if(!mark[child])
		{
		    par[child]=x;
			h[child]=h[x]+1;
			dfs(child);
            up[x]=min(up[x],up[child]);

		}
		else
            if(child!=par[x])
                up[x]=min(up[x],h[child]);
	}
}

int main ()
{
	input();
	dfs(0);
	for(int i=0; i<m; i++)
        {
            int fi=ed[i].first, se=ed[i].second;
            if(h[fi]>h[se])
                swap(fi,se);
            if(up[se]>=h[se])
                ans.push_back(make_pair(min(fi,se), max(fi,se)));
        }
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
	return 0;
}

Measured memory_bytes: 5112
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
ll n,m,k,a,b,c,ans,fa[100001],ra[100001],L,cnt;
vector<P> v;
ll find(ll x){
    if(x==fa[x])return x;
    return fa[x]=find(fa[x]);
}
void uni(ll x,ll y){
    x=find(x),y=find(y);
    if(x==y)return ;
    if(ra[x]<ra[y])swap(x,y);
    fa[y]=x;
    if(ra[x]==ra[y])ra[x]++;
    return ;
}
int main(void){
    
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        a--,b--;
        v.push_back({a,b});
    }
    for(int i=0;i<m;i++){
        for(int i=0;i<100001;i++)fa[i]=i;
        for(int j=0;j<m;j++){
            if(i==j)continue;
            uni(v[j].F,v[j].S);
        }
        cnt=0;
        for(int j=0;j<n;j++){
            if(find(0)==find(j))cnt++;
        }
        //cout<<cnt<<endl;
        if(cnt!=n)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
vector<int> sum;
int tmp=0,ans=(1e9);
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		tmp+=x;
		sum.push_back(tmp); 
	}
	for(int i=1;i<n-1;i++)
	{
		int tmp1=sum[i],tmp2=sum[n-1]-sum[i];
		ans=min(ans,abs(tmp1-tmp2));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N;
    cin >> N;
    vector<double> V(N);
    for(int i=0;i<N;i++)cin >> V[i];
    double ans=0;
    priority_queue<double,vector<double>,greater<double>> que;
    for(int i=0;i<N;i++) que.push(V[i]);
    while(que.size()>1){
        double a,b;
        a = que.top();
        que.pop();
        b = que.top();
        que.pop();
        que.push((double)(a+b)/2);
    }
    cout << que.top() << endl;
    

    return 0;
}

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

using namespace std;

typedef long long ll;

ll md = 1000000007;

vector<ll> kai(100003);

int main(int, char**)
{
	ll n, k , ans;
	cin >> n >> k;

	if (k == 1) cout << 0 << endl;
	else {
		n -= (k - 1);
		cout << (n - 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
"use strict"

/**
 * @param {number[]} ws
 * @param {number} p
 * @param {number} k
 */
const check = (ws, p, k) => {
  let sum = 0
  let kCount = 1
  let sumMax = 0
  for (let i = 0; i < ws.length; i++) {
    if (ws[i] > p) {
      // p大きさが足りない
      return -1
    }

    if (sum + ws[i] > p) {
      if (kCount === k) {
        // p大きさが足りない
        return -1
      } else {
        // 次のトラック
        kCount++
        sum = 0
      }
    }
    sum = sum + ws[i]

    // 1つのトラックあたりの最大積載量を更新
    if (sum > sumMax) sumMax = sum
  }
  // 荷物全部つめた

  // pをもっと小さくできるかもしれない
  return 1
}

/**
 * @param {number[]} ws
 * @param {number} k
 * @param {number} left
 * @param {number} right
 */
const search = (ws, k, left, right) => {
  if (left === right) return left
  let p = Math.floor((right + left) / 2)
  // console.log(`p:${p} left:${left} right:${right} k:${k}`)
  const result = check(ws, p, k)
  if (result < 0) return search(ws, k, p+1, right) // pは右側
  else if (result > 0) return search(ws, k, left, p) // pは左側
  else return p
}

let rows = 0
let n = 0
let k = 0
const ws = []
let sumW = 0
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
})
reader.on("line", (line) => {
  rows++
  if (rows === 1) {
    ;[n, k] = line
      .trim()
      .split(" ")
      .map((x) => Number(x))
  } else {
    const w = Number(line.trim())
    ws.push(w)
    sumW = sumW + w
    if (rows - 1 === n) {
      const result = search(ws, k, 1, sumW)
      console.log(result)
      process.exit(0)
    }
  }
})



Measured memory_bytes: 25724
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int[] d = new int[n];
		
		for (int i = 0; i < n; i++) {
			d[i] = sc.nextInt();
		}

		int s = 0;
		
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n ; j++) {
				s += d[i] * d[j];
			}
		}
	
		System.out.println(s);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;

// 深さ優先探索
vector<bool> seen; 
int dfs(const Graph &G, int v, int ans) {
    seen[v] = true;
    for (auto e : G[v]) {
        if (!seen[e.to]) {
            ans = dfs(G, e.to, ans+1);
        }
    }
    return ans;
}


int main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    Graph G(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }
    seen.assign(n, false); 
    int ans = 0; 
    for (int i = 0; i < n; i++) {
        if (!seen[i]) {
            chmax(ans, dfs(G, i, 1));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23572
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 5e6 + 17;

struct pt
{
	int x, y;
	pt() { }
};

struct hash_table
{
	int sz;
	vector<int> H, F, used;
	hash_table() { }

	hash_table(int n)
	{
		sz = n;
		H.resize(sz);
		F.resize(sz);
		used.resize(sz);
	}

	int getpos(int h) const
	{
		int i = h % sz;
		for (; used[i] && H[i] != h; ++i) if (i == sz) i = 0;
		return i;
	}

	int& operator[](int h)
	{
		int i = getpos(h);
		H[i] = h;
		used[i] = 1;
		return F[i];
	}
};

struct fenwick
{
	int n;
	hash_table F;

	fenwick() { n = inf, F = hash_table(maxn); }

	void upd(int i, int x)
	{
		for (; i < n; i |= i + 1)
			F[i] = max(F[i], x);
	}

	int get(int i)
	{
		int res = 0;

		for (; i >= 0; i &= i + 1, --i)
			res = max(res, F[i]);

		return res;
	}
};

int n;
pt s, f;
pt p[maxn];

bool read()
{
	if (scanf("%d %d %d %d %d", &s.x, &s.y, &f.x, &f.y, &n) != 5)
		return false;

	forn (i, n)
		scanf("%d %d", &p[i].x, &p[i].y);

	return true;
}

bool cmp(pt a, pt b) { return make_pair(a.x, a.y) < make_pair(b.x, b.y); }

void solve()
{
	if (s.x > f.x)
		swap(s, f);

	if (s.y > f.y)
	{
		f.y = 2 * s.y - f.y;

		forn (i, n)
			p[i].y = 2 * s.y - p[i].y;
	}

	vector<pt> pp;

	forn (i, n)
		if (s.x <= p[i].x && p[i].x <= f.x && s.y <= p[i].y && p[i].y <= f.y)
			pp.push_back(p[i]);

	sort(pp.begin(), pp.end(), cmp);
	fenwick dp;

	forn (i, size(pp))
		dp.upd(pp[i].y, dp.get(pp[i].y) + 1);

	int lis = dp.get(inf);
	long double ans = 0;

	if (lis != min(f.y - s.y, f.x - s.x) + 1)
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * lis;
	else
		ans = 100.0 * (f.y - s.y + f.x - s.x) - 20.0 * lis + 5 * M_PI * (lis - 1) + 10 * M_PI;

	printf("%.15f\n", (double) ans);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 62192
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    int amin = INFINITY;
    int amax = -INFINITY;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        amin = min(amin, a[i]);
        amax = max(amax, a[i]);
    }
    cout << amax - amin << endl;
    return 0;
}

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

public class Main {
  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);
    final int k = scanner.nextInt();
    scanner.nextLine();
    final int[] a = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

    final int[] extended = new int[a.length * 2];
    for (int i = 0; i < a.length * 2; i++) {
      extended[i] = a[i % a.length];
      if (i >= a.length) extended[i] += k;
    }

    int min = Integer.MAX_VALUE;
    for (int i = 0; i < a.length; i++) {
      min = Math.min(min, extended[i + a.length - 1] - extended[i]);
    }
    System.out.println(min);
  }
}

Measured memory_bytes: 58080
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int A, B, C;
        cin >> A >> B >> C;

        int ma = max({A, B, C});
        if (ma == A + B + C - ma)
        {
                cout << "Yes" << endl;
        } else{
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    int n,m,c;
    cin >> n >> m >> c;
    int b[m];
    inrep(m,b);
    int ans = 0;
    rep(i,0,n){
	ll cnt = c;
	rep(j,0,m){
	    int a;
	    cin >> a;
	    cnt += a*b[j];
	}
	if(cnt > 0)ans++;
    }
    P(ans);
    return  0;
}


Measured memory_bytes: 256
using System;

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());

		var b = false;
		for (int i = 1; i <= 9 && !(b = n % i == 0 && n / i <= 9); i++) ;
		Console.WriteLine(b ? "Yes" : "No");
	}
}


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

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

int main()
{
	int n;
	cin >> n;
	vector<P> v(n);
	rep(i, n)
		cin >> v[i].first >> v[i].second;

	double sum = 0;
	rep(i, n) for(int j = i + 1; j < n; j++)
	{
		sum += sqrt(
			(v[j].first - v[i].first) * (v[j].first - v[i].first) +
			(v[j].second - v[i].second) * (v[j].second - v[i].second));
	}

	int num = 2, all = 1;
	rep(i, n - 2) num *= (i + 2);
	rep(i, n) all *= (i + 1);

	cout << setprecision(16) << sum * num / all << endl;

	return 0;
}

Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<u32> = procon_read();
	let n = v[0];
	let k = v[1];
	println!("{}", k*((k-1).pow(n-1)));
}


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

using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p.at(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> q.at(i);
    }

    vector<int> v(n);
    iota(v.begin(), v.end(), 1);

    int a = 0, b = 0;
    int cnt = 0;
    do {
        bool same = true;
        for (int i = 0; i < n; i++) {
            if (v.at(i) != p.at(i)) same = false;
        }
        if (same) a = cnt;

        same = true;
        for (int i = 0; i < n; i++) {
            if (v.at(i) != q.at(i)) same = false;
        }
        if (same) b = cnt;

        cnt++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ul unsigned long long int
#define vi vector<int>
#define vl vector<int64_t>
#define all(x) x.begin(),x.end()
#define pb push_back
#define fo(x,a,b) for(int x=a; x<b; x++)
#define rfo(x,a,b) for(int x=a; x>=b; x--)
#define fi first
#define sec second
#define mp make_pair
int sgn(int x) { return x>0 ? 1 : ( x<0 ? -1 : 0); }
typedef pair<int,int> pairs;
double pi = 3.14159265358979323846;
ll mod = 1000000007;

void solve()
{
    int ans=0;
    string s,t;
    cin>>s>>t;
    int m = s.size(), n=t.size();
    ans=n;
    for(int i=0;i<=m-n;i++)
    {
        int temp=n;
        for(int j=i, k=0;k<n;j++,k++)
        {
            temp-=(s[j]==t[k]);
        }
        ans=min(ans,temp);
    }
    cout<<ans;
    cout<<"\n";
    return;
}
int main()
{
#ifdef _DEBUG
    freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    //cin>>t;
    //while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	long long a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a,a+n);
	cout << a[n-1]-a[0] << endl;
	return 0; 
}

Measured memory_bytes: 256
def main():
    k = int(input())
    count = 1
    num = 7
    if k % 2 == 0 or k % 5 == 0:
        print(-1)
        exit()
    while True:
        if num % k == 0:
            print(count)
            exit()
        num = (num*10+7) % k
        count += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 62828
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

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

int main(){
    
    double n,k;
    cin >> n>>k;
    double ans=0;
    
    for(int i=1;i<=n;i++){
        int score=i;
        double subans=1.0/n;
        if(i>=k){
            ans+=(n-k+1)/n;
            break;
        }
        while(score<k){
            subans=subans/2;
            score=score*2;
        }
        ans+=subans;
    }
    
    printf("%.10lf\n",ans);
    
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
ll n, m;
ll a[200005];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	ll ans = 0;
	rep(i, n) {
		if (a[i + 1] - a[i] > 1 || a[i] > i) {
			cout << -1 << endl;
			return 0;
		}
		if (a[i] == a[i + 1]) {
			ans += a[i];
		}
		else if (a[i] > a[i + 1]) {
			ans += a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int j=0;
        for(int i=0;i<n;i++){
            if(sc.nextInt()-1==j){
                j++;
            }
        }
        if(j>0){
            System.out.println(n-j);
        }else{
            System.out.println(-1);
        }
    }
}

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

using namespace std;

int main()
{
	string S, T, U;
	int A, B;

	cin >> S >> T >> A >> B >> U;

	if (S == U)
		A--;
	else if (T == U)
		B--;

	cout << A << ' ' << B << endl;

}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 62;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k;
  cin>>n>>k;
  vll x(n),y(n);
  rep(i,n) cin>>x[i]>>y[i];
  ll ans=INF;
  rep(i,n){
    for(int j=i+1;j<n;j++){
      ll ii=i;
      ll jj=j;
      rep(o,n){
        for(int p=o+1;p<n;p++){
          ll oo=o;
          ll pp=p;
          ll xx=0;
      for(int u=0;u<n;u++){
        if(x[ii]<x[jj]) swap(ii,jj);
        if(y[oo]<y[pp]) swap(oo,pp);
        if(x[ii]>=x[u]&&x[jj]<=x[u]){
          if(y[oo]>=y[u]&&y[pp]<=y[u])xx++;
        }
      }

      if(xx>=k){
        ans=min(ans,abs(x[ii]-x[jj])*abs(y[oo]-y[pp]));
      }
        }
      }
    }
  }
  COUT(ans);
}

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

const int MAPSIZE = 20;

using namespace std;

void p(int (*a)[MAPSIZE], int size = MAPSIZE){
	for(int i = 0; i < size; i++){
		for(int j = 0; j < size; j++){
			cout << a[i][j];
		}
		cout << endl;
	}
}

int main(){
	int mapdata[MAPSIZE][MAPSIZE];
	int route[MAPSIZE][MAPSIZE];

	int x, y;
	while(true){
		cin >> x >> y;
		if(!x && !y) break;

		fill((int*)mapdata, (int*)(mapdata + sizeof(mapdata)/sizeof(*(mapdata))), 1);

		for(int i = 1; i <= y; i++){
			for(int j = 1; j <= x; j++){
				cin >> mapdata[i][j];
			}
		}

		fill((int*)route, (int*)(route + sizeof(route)/sizeof(*(route))), 0);

		// 下からルート数を入れていく
		for(int i = y; i >= 0; i--){
			for(int j = 1; j <= x; j++){
				switch(mapdata[i][j]){
				case 0: // 移動可能 => ( x-1 , y+1 )、 ( x , y+1 )、 ( x+1 , y+1 ) の経路数値合計（斜めは移動可能マスのみ加算）
					// 但し、i == yの時は1
					if(i == y){
						route[i][j] = 1;
					}
					else{
						route[i][j] = route[i+1][j-1]*(!mapdata[i+1][j-1]) + route[i+1][j] + route[i+1][j+1]*(!mapdata[i+1][j+1]);
					}
					break;
				case 1:// 障害物 => 0
					route[i][j] = 0;
					break;
				case 2:// ジャンプ台=> (x,y+2) の経路数
					// 但し、i+1 >= y のときは1
					if(i+1 >= y){
						route[i][j] = 1;
					}else{
						route[i][j] = route[i+2][j];
					}
					break;
				}
			}
		}
//		p(route, x+3);
		int sum = 0;
		for(int i = 1; i <= x; i++){
			sum += route[1][i];
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
# N, M = gets.chomp.split.map(&:to_i)
S = gets.chomp.chars
# T = gets.chomp.chars
N = S.size

# Try 0101...
ans1 = 0
0.upto(N-1).each do |i| # even should 0, odd should be 1
  target = (i % 2 == 0) ? '0' : '1'
  if S[i] != target
    ans1 += 1
  end
end
# p "ans1: #{ans1}"

# Try 1010...
ans2 = 0
0.upto(N-1).each do |i| # even should 0, odd should be 1
  target = (i % 2 == 0) ? '1' : '0'
  if S[i] != target
    ans2 += 1
  end
end
# p "ans2: #{ans2}"

p [ans1, ans2].min

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

int main()
{
  int n;
  string s;
  cin >> n >> s;

  for (int i = 0; i < s.size(); i++)
  {
    char c = s[i] + n;
    if (c - '0' > 42)
    {
      c -= 26;
    }

    cout << c;
  }
  cout << endl;
}


Measured memory_bytes: 3652
#include <stdio.h>
#define QMAX 100000
int is_prime[QMAX+1];
void sieve(int n);
int main(void) {
  int i, q, l, r, lnum[QMAX+1] = {0};
  sieve(QMAX);
  for (i = 1; i <= QMAX; i += 2) lnum[i] = is_prime[i] && is_prime[(i+1)/2];
  for (i = 1; i <= QMAX; i++) lnum[i] += lnum[i-1];
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d %d", &l, &r);
    printf("%d\n", lnum[r] - lnum[l-1]);
  }
  return 0;
}

void sieve(int n)
{
  int i, j;
  for (i = 0; i <= n; i++) is_prime[i] = 1;
  is_prime[0] = is_prime[1] = 0;
  for (i = 2; i <= n; i++) {
    if (is_prime[i]) {
      for (j = i * 2; j <= n; j += i) is_prime[j] = 0;
    }
  }
}


Measured memory_bytes: 1280
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private static final int INF = Integer.MAX_VALUE / 2;

    private void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a == b) {
            _out.println(c);
        } else if (a == c) {
            _out.println(b);
        } else {
            _out.println(a);
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

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

using namespace std;

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


Measured memory_bytes: 256
n=int(input())
sumx=0
for i in range(n):
  x_,u_=map(str,input().split())
  x_=float(x_)
  if u_=='BTC':
    x_=float(380000)*x_
    sumx+=x_
    
  else:
    sumx+=float(x_)
    
print(sumx)
      

Measured memory_bytes: 9144
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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(a > b){a = b; return 1;} return 0;}


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a[3];
  cin >> n >> a[0] >> a[1] >> a[2];
  vector<int> l(n);
  rep(i, n)cin >> l[i];
  int res = inf;
  // 00: no 01: a, 10: b, 11: c
  for(int i = 0; i < (1<<n); i++){
    for(int j = 0; j < (1<<n); j++){
      vector<int> la[3];
      for(int k = 0; k < n; k++){
        int t1 = (i >> k) % 2;
        int t2 = (j >> k) % 2;
        if(t1 == 0 && t2 == 1)la[0].pb(l[k]);
        else if(t1 == 1 && t2 == 0)la[1].pb(l[k]);
        else if(t1 == 1 && t2 == 1)la[2].pb(l[k]);
      }
      bool flag = true;
      int rtmp = 0;
      for(int k = 0; k < 3; k++){
        int sum = accumulate(all(la[k]), 0);
        if(sz(la[k]) == 0){
          flag = false;
          break;
        }
        rtmp += abs(a[k] - sum);
        rtmp += 10 * (sz(la[k])-1);
      }
      if(flag)res = min(res, rtmp);
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String s = saori.nextHayami();
		if(s.equals("Sunny")){
			System.out.println("Cloudy");
		} else if(s.equals("Cloudy")){
			System.out.println("Rainy");
		} else if(s.equals("Rainy")){
			System.out.println("Sunny");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<int> ip(mx,0);

bool isprime(int x){
  if(x==2){ return true; }
  if(x<2 || x%2==0){ return false; }
  
  int sqrtx = ceil(sqrt(x));
  for(int i=3; i<=sqrtx; i+=2){ if(x%i==0){ return false; } }
  return true;
}

int main(){

  for(int i=3; i<100002; i+=2){ 
    ip[i]=ip[i-2]+(isprime(i)&isprime((i+1)/2) ?1:0); 
  }
  
  int q;
  cin >> q;
  rep(i,q){
    int a,b; cin >> a >> b; if(a==1){a=2;}
    cout << ip[b]-ip[a-2] << endl;    
  }
  return 0;
}


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

def main():
    maxi = 0
    for i in range(N):
        maxi = max(maxi, H[i])
        if maxi - H[i] > 1:
            return False
    return True

if main():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 63984
n=int(input())
lis=[[] for _ in range(n)]
for i in range(n):
  a,b,c=map(int,input().split())
  lis[i]=[a,b,c]  
dp=[[0]*(n+1) for _ in range(3)]
for i in range(1,n+1):
  dp[0][i]=max(dp[1][i-1]+lis[i-1][0],dp[2][i-1]+lis[i-1][0])
  dp[1][i]=max(dp[0][i-1]+lis[i-1][1],dp[2][i-1]+lis[i-1][1])  
  dp[2][i]=max(dp[0][i-1]+lis[i-1][2],dp[1][i-1]+lis[i-1][2])
d=dp[0][n]
for i in range(1,3):
  if dp[i][n]>d:
    d=dp[i][n]
print(d)


Measured memory_bytes: 63136
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    queue<ll> que;
    ll n;cin>>n;
    FOR(i,1,9) que.push(i);
    ll now=0;
    REP(i,n){
        now = que.front();
        que.pop();
        if (now%10==0){
            que.push(now*10+0);
            que.push(now*10+1);
        }
        else if(now%10==9){
            que.push(now*10+8);
            que.push(now*10+9);
        }
        else{
            ll matu = now%10;
            que.push(now*10+matu-1);
            que.push(now*10+matu+0);
            que.push(now*10+matu+1);
        }
    }

    cout<<now<<endl;
    
    return 0;
}


Measured memory_bytes: 4740
R, G, B, N = map(int, input().split())
ans = 0
Rmax=N//R
Gmax=N//G
for i in range(Rmax+1):
    for j in range(Gmax+1):
        total=i*R+j*G
        if N-total<0:
            break
        elif (N-total)%B==0:
            ans+=1
    if j==0:
        break
print(ans)


Measured memory_bytes: 66548