akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x1 = sc.nextInt()
    val x2 = sc.nextInt()
    val x3 = sc.nextInt()
    val x4 = sc.nextInt()
    val x5 = sc.nextInt()
    println(problem170a(x1, x2, x3, x4, x5))
}

fun problem170a(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int): Int {
    return when {
        x1 == 0 -> return 1
        x2 == 0 -> return 2
        x3 == 0 -> return 3
        x4 == 0 -> return 4
        x5 == 0 -> return 5
        else -> 0
    }
}

Measured memory_bytes: 36416
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define drep(i,cc,n) for(int i=cc;i>n;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin >> n;
    int ans = n % 10;
    if(ans == 3) cout<<"bon"<<endl;
    else if(ans == 0 || ans == 1 || ans == 6 || ans == 8) cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n,k,q;
    cin >> n >> k >> q;
    ll a[100005];
    vector <int> vc(100005,0);
    REP(i,q){
        cin >> a[i];
        vc[a[i]-1]++;
    }
    int answer = 0;
    REP(i,n){
        if((k -q)+vc[i] <= 0 )cout << "No"<<endl;
        else cout << "Yes" << endl;
    }
    //cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define f first
#define s second 
#define mp make_pair
#define inf 1<<30
using namespace std;

int main()
{
  int N,M,L,a,b,c,d;
  int dis[101][101],th[101][101];
  int dp[101][101];

  while(1){
    cin>>N>>M>>L;
    if(N+M+L==0)break;
    for(int i=0;i<101;i++){
      for(int j=0;j<101;j++){
	dis[i][j]=th[i][j]=dp[i][j]=inf;
      }
    }
    for(int i=0;i<M;i++){
      cin>>a>>b>>c>>d;
      a--;b--;
      dis[a][b]=c;
      dis[b][a]=c;
      th[a][b]=d;
      th[b][a]=d;
    }
    int ans=inf;
    dp[0][L]=0;
    priority_queue<pair<int,pair<int,int> > > pq;
    pq.push(mp(0,mp(0,L)));
    while(!pq.empty()){
      pair<int,pair<int,int> > u=pq.top();
      pq.pop();
      u.f=(-1)*u.f;
      if(dp[u.s.f][u.s.s]<u.f)continue;
      if(u.s.f==N-1){
	ans=min(ans,u.f);
	continue;
      }
      
      for(int i=0;i<N;i++){
	if(dis[u.s.f][i]==inf)continue;
	int c=u.s.s-dis[u.s.f][i];
	if(0<=c){
	  if(u.f<dp[i][c]){
	    dp[i][c]=u.f;
	    pq.push(mp(u.f*(-1),mp(i,c)));
	  }
	}
	if(u.f+th[u.s.f][i]<dp[i][u.s.s]){
	  dp[i][u.s.s]=u.f+th[u.s.f][i];
	  pq.push(mp((u.f+th[u.s.f][i])*(-1),mp(i,u.s.s)));
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t;cin>>t;while(t--)
#define f(i,n) for (int i=0;i<n;i++)
#define fa(i,a,b) for (int i=a;i<b;i++)
#define b(i,a,b) for (int i=a;i>=b;i--)
#define pb push_back
#define pp pop_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define fi first    
#define se second
#define SZ(x) ((int)(x).size())
#define db(x) cout<<">"<<#x<<" = "<<x<<endl;
#define MOD 1000000007
#define vll vector<ll>
#define ce cout<<endl
int main() 
{ 
    fast;
    char c;
    cin>>c;
    if(c>='a' && c<='z')
        cout<<'a';
    else
        cout<<'A';
    return 0; 
} 

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>

using namespace std;

typedef struct _Point {
	double x;
	double y;
} Point;
typedef Point Vector;

Point subPoint(Point a, Point b) {
	Point ret;
	ret.x = a.x - b.x;
	ret.y = a.y - b.y;
	return ret;
}

bool apint(Point a, Point b, Point c, Point p) {
	Vector ab = subPoint(b, a);
	Vector bp = subPoint(p, b);
	Vector bc = subPoint(c, b);
	Vector cp = subPoint(p, c);
	Vector ca = subPoint(a, c);
	Vector ap = subPoint(p, a);
	double c1 = ab.x * bp.y - ab.y * bp.x;
	double c2 = bc.x * cp.y - bc.y * cp.x;
	double c3 = ca.x * ap.y - ca.y * ap.x;
	if( ( c1 > 0 && c2 > 0 && c3 > 0 ) || ( c1 < 0 && c2 < 0 && c3 < 0 ) )
		return true;
	return false;
}

int main() {
	Point a, b, c, p;
	while (cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> p.x >> p.y) {
		if (apint(a, b, c, p) == true)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define ll long long
#define mp(a, b) make_pair(a, b)
#define newline cout << endl;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(),v.end()
using namespace std;

template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p)
{
    out << '(' << p.ff << ", " << p.ss << ')';
    return out;
}

template <typename T> ostream& operator<<(ostream& out, vector<T> const& v)
{
    int l = v.size();
    for (int i = 0; i < l - 1; i++)
        out << v[i] << ' ';
    if (l > 0)
        out << v[l - 1];
    return out;
}

template <typename T> void trace(const char* name, T&& arg1) { cout << name << " : " << arg1 << endl; }

template <typename T, typename... Args> void trace(const char* names, T&& arg1, Args&&... args)
{
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    trace(comma + 1, args...);
}

/*Input*/
const ll vsize = 1e6;
vector<ll> v(vsize), cost(vsize);
ll n;
/*Input*/

int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    clock_t tStart = clock();
    int test;
    test = 1;
    /* cin >> test; */
    while (test--) {
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> v[i];
        }
        cost[0] = 0;
        for(int i = 1; i < n; i++){
            if(i==1){
                cost[i] = abs(v[i-1] - v[i]);
                continue;
            }
            cost[i] = min( cost[i-1] + abs(v[i-1]-v[i]), cost[i-2] + abs(v[i-2] - v[i])  );
        }
        cout << cost[n-1] << "\n";
    }
#ifdef LOCAL_DEFINE
    printf("Time taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
#endif
    return 0;
}









Measured memory_bytes: 18668
#include<stdio.h>
#include<string.h>

struct cell{
    struct cell *prev;
    struct cell *next;
    int flag;
}s[10000],*now;

int main(){
    int i,flag,m,n,tmp;
    char str[10000],t[10000];

    while(scanf("%d%d",&m,&n),m+n){
        tmp = m;
        for(i = 0;i <= m;i++){
            if(i)s[i].prev = &s[i - 1];
            else s[i].prev = &s[m - 1];
            if(i == m - 1)s[i].next = &s[0];
            else s[i].next = &s[i + 1];
            s[i].flag = 1;
        }
        now = &s[0];

        for(i = 1;i <= n;i++){
            scanf("%s",str);
            if(tmp == 1)continue;
            if(i % 3 == 0){
                if(i % 5 == 0){
                    flag = strcmp(str,"FizzBuzz");
                }else{
                    flag = strcmp(str,"Fizz");
                }
            }else if(i % 5 == 0){
                flag = strcmp(str,"Buzz");
            }else{
                if(i == atoi(str))flag=0;///////
                else flag=1;
            }
            if(flag){
                now -> prev -> next = now -> next;
                now -> next -> prev = now -> prev;
                now -> flag = 0;
                tmp--;
            }
            now = now -> next;
        }

        for(i = 0,flag = 0;i < m;i++){
            if(s[i].flag == 1){
                if(!flag){
                    printf("%d",i+1);
                    flag = 1;
                }else{
                    printf(" %d",i+1);
                }
            }
        }
        puts("");
    }
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N;
vint A[1111];
signed main(){
	cin>>N;
	rep(i,N){
		A[i].resize(N-1);
		rep(j,N-1)cin>>A[i][j],A[i][j]--;
		reverse(all(A[i]));
	}

	vint lis;
	rep(i,N){
		int x=A[i].back();
		if(A[x].back()==i)lis.pb(i);
	}

	int T=0;
	while(lis.size()){
		T++;

		vint nex;
		for(auto x:lis){
			A[x].pop_back();
			if(A[x].size()==0)continue;
			int y=A[x].back();
			if(A[y].back()==x){
				nex.pb(x);nex.pb(y);
			}
		}
		lis=nex;
	}

	rep(i,N)if(A[i].size()){
		cout<<-1<<endl;
		return 0;
	}
	cout<<T<<endl;
	return 0;
}

Measured memory_bytes: 8064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

#include <unordered_map>
#include <iomanip>

int n, lo, hi;
vll v;
unordered_map<ll, int> cnt;
ll C[51][51]; // C[n][k] -> nCk

void comb_table(int N)
{
	REPC(i, N)
		REPC(j, i)
		{
			if (j == 0 or j == i)
				C[i][j] = 1LL;
			else
				C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
		}
}

void init()
{
	comb_table(50);
	cin >> n >> lo >> hi;
	v.resize(n);
	REP(i, n)
	{
		ll tmp; cin >> tmp;
		v[i] = tmp;

		auto p = cnt.insert(MP(tmp, 1));
		if (!p.second)
			++p.first->second;
	}

	sort(ALL(v), greater<ll>());

	//for (auto i = cnt.begin(); i != cnt.end(); i++)
	//	cout << i->first << " : " << i->second << endl;
}

int main()
{
	init();

	double bestAv = (double)accumulate(v.begin(), v.begin() + lo, 0LL) / lo;
	cout << setprecision(24) << bestAv << endl;
	ll ans = 0;

	for (int items = lo; items <= hi; items++)
	{
		if (items != lo)
		{
			bool flag = true;
			REP(i, items)
				if (v[i] != v[0]) flag = false;
			if (!flag) break;
		}
			
		unordered_map<ll, int> um;
		REP(i, items)
		{
			auto p = um.insert(MP(v[i], 1));
			if (!p.second)
				++p.first->second;
		}

		ll tmp = 1;
		for (auto it = um.begin(); it != um.end(); it++)
		{
			tmp *= C[cnt.find(it->first)->second][it->second];
		}
		ans += tmp;
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans=1e9,a[10005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		int sa=0,sb=0;
		for(int j=1;j<=n;j++)
			if(j<=i)sa+=a[j];
			else sb+=a[j];
		ans=min(ans,abs(sa-sb));
	}
	cout<<ans;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace ABC023D
{
	class Program
	{
		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

			var min = input[0];
			var ans = 1;
			for (var i = 1; i < input.Length; i++)
			{
				if (input[i] < min)
				{
					ans++;
					min = input[i];
				}
			}

			System.Console.WriteLine(ans);
		}

	}
}

Measured memory_bytes: 34012
N = gets.chomp.to_i
rest = []
i = 0
j = 0

while i < N
  rest << gets.chomp.split(" ")
  rest[i] << i + 1
  i += 1
end

rest = rest.sort_by { |r| r[0] }

while j < N
  k = j + 1
  while k < N
    if rest[k][1].to_i > rest[j][1].to_i && rest[k][0] == rest[j][0]
      tmp = rest[k]
      rest[k] = rest[j]
      rest[j] = tmp
    end
    k += 1
  end
  j += 1
end

rest.each { |r|
  puts r[2]
}


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>

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

using namespace std;

int main(){
  int n, m, ind, lim, flag;

  cin >> n >> m;
  vector<string> vn(n);
  vector<string> vm(m);

  rep(i, n) cin >> vn[i];
  rep(i, m) cin >> vm[i];

  lim = n - m + 1;
  rep(i, lim){
      flag = 0;
      ind = vn[i].find(vm[0]);
      if(ind != string::npos){
          rep(j, m - 1){
              if(vm[j + 1] != vn[i + j + 1].substr(ind, m)){
                  flag = 1;
                  break;
              }
          }
          if(flag == 0){
              cout << "Yes" << endl;
              flag = 2;
              break;
          }
      }
  }
  if(flag != 2) cout << "No" << endl;

}

Measured memory_bytes: 3604
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int l = in.nextInt();
		String[] a = new String[n];
		for (int i = 0; i < n; ++i) {
			a[i] = in.next();
		}
		Arrays.sort(a);
		for (int i = 0; i < n; ++i) {
			System.out.print(a[i]);
		}
	}
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	// ここに処理を記述

	int K;
	cin >> K;

	ll ans = 0;
	REP(t,K){
		int a = t+1;
		REP(u,K){
			int b = u+1;
			REP(v,K){
				int c = v+1;
				ans += gcd(gcd(a,b),c);
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
  string s;
    cin >> n >> k >> s;
    if(s[k-1] == 'A') s[k-1] = 'a';
    else if(s[k-1] == 'B') s[k-1] = 'b';
    else s[k-1] = 'c';
  
  for(int i = 0; i < n; i++)
  {
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
N,Y = map(int,input().split())


def solve(N,Y):
    if Y > 10000*N:
        print("-1 -1 -1")
        return
    for a in range(N+1):
        for b in range(N+1-a):
            if a*1000+b*5000+(N-a-b)*10000 == Y:
                print(N-a-b, b, a)
                return
    print("-1 -1 -1")

solve(N,Y)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

int main() {
	int n;
	std::cin >> n;

	std::vector<int> v;
	v.resize(n);
	for (auto&e : v)
		std::cin >> e;

	decltype(v) tab;
	tab.resize(n);
	tab[0] = 0;
	tab[1] = std::abs(v[1] - v[0]);
//	tab[2] = std::abs(v[2] - v[0]);

	if(n>2)
	for (int i{ 2 }; i < n; ++i) {
		auto walk = std::abs(v[i] - v[i - 1]);
		auto step = std::abs(v[i] - v[i - 2]);
		auto min_cost = std::min( walk + tab[i-1], step+tab[i-2] );
		//std::cout << min_cost << "\n";
		tab[i] = min_cost;
	}
	/*
	for (const auto&e : tab)
		std::cout << " " << e;
	std::cout << "\n";
	*/
	std::cout << tab[n-1] << "\n";
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int l,x;
  set<int> s;
  cin>>l;
  for(int i=0;i<l;i++)
  {
    cin>>x;
    s.insert(x);
  }
  if(s.size()==l) cout<<"YES";
  else cout<<"NO";
  return 0;
}
  

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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	int n;
	int check = 0;
	int ans = 1;
	cin >> n;
	vector<string> s(n);
	for( int i=0; i<n; i++ )	cin >> s[i];

	sort( all(s) );

	for( int i=1; i<n; i++ ){
		if( s[check] != s[i] ){
			ans++;
			check = i;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9596
package main

import (
	"container/list"
	"fmt"
	"strings"
)

type input struct {
	q  int
	f1 int
	f2 string
}

func main() {
	var s string
	var qn int
	fmt.Scan(&s, &qn)

	var q, f1 int
	var f2 string
	rev := false
	// top := make([]byte, 0, qn)
	// bottom := make([]byte, 0, qn)
	dq := list.New()
	dq.PushFront(s)

	for i := 0; i < qn; i++ {
		fmt.Scan(&q)
		if q == 1 {
			rev = !rev
		} else {
			fmt.Scan(&f1, &f2)
			if (!rev && f1 == 1) || (rev && f1 == 2) {
				dq.PushFront(f2)
			} else {
				dq.PushBack(f2)
			}
		}
	}

	ss := make([]string, dq.Len())
	i := 0
	for e := dq.Front(); e != nil; e = e.Next() {
		ss[i] = e.Value.(string)
		i++
	}
	ans := strings.Join(ss, "")
	if rev {
		ans = reverse(ans)
	}
	fmt.Println(ans)
}

func reverse(str string) string {
	rs := []rune(str)
	for i, j := 0, len(str)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}


Measured memory_bytes: 24704
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int n;
// dp[i][j][k] = 1貫の寿司を置いている皿が i 枚
//               2                         j
//               3                         k   あるときの操作回数の期待値
// dp[i][j][k] = 1 + (i / n) * dp[i - 1][j][k]
//                 + (j / n) * dp[i + 1][j - 1][k]
//                 + (k / n) * dp[i][j + 1][k - 1]
//                 + (1 - (i + j + k) / n ) * dp[i][j][k]
//             = (n + i * dp[i - 1][j][k] + j * dp[i + 1][j - 1][k] k * dp[i][j + 1][k - 1]) / (i + j + k)
double dp[301][301][301];

double rec(int one, int two, int three) {
  if (dp[one][two][three] != -1) return dp[one][two][three];
  dp[one][two][three] = n;
  if (one - 1 >= 0) dp[one][two][three] += one * rec(one - 1, two, three);
  if (two - 1 >= 0) dp[one][two][three] += two * rec(one + 1, two - 1, three);
  if (three - 1 >= 0) dp[one][two][three] += three * rec(one, two + 1, three - 1);
  dp[one][two][three] /= one + two + three;
  return dp[one][two][three];
}

int main() {
  // freopen("input.txt", "r", stdin);

  cin >> n;
  int one, two, three;
  one = two = three = 0;
  REP(i, n) {
    int a; cin >> a;
    if (a == 1) ++one;
    else if (a == 2) ++two;
    else ++three;
  }
  REP(i, 301) REP(j, 301) REP(k, 301) dp[i][j][k] = -1;
  dp[0][0][0] = 0;
  printf("%.10f\n", rec(one, two, three));
  return 0;
}


Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int k, t;
    cin >> k >> t;
    vi a(t);
    rep(i, t) cin >> a[i];
    if (t == 1) {
        cout << a[0]-1 << endl;
        return 0;
    }
    int mx = *max_element(a.begin(), a.end());
    int sm = accumulate(a.begin(), a.end(), 0);
    int ok = sm - mx + 1;
    cout << max(mx - ok, 0) << endl;
}

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

using namespace std;

int main()
{
	string R;
	cin >> R;
	if(R.length()<=10 && R.length()>=4)
	{
		int lenR=R.length();
		if(R[0]!='A')
		{
			cout<< "WA";
			return 0;
		}
		if(!(R[1]>='a' && R[1]<='z'))
		{
			cout<< "WA";
			return 0;
		}
		if(!(R[lenR-1]>='a' && R[lenR-1]<='z'))
		{
			cout<< "WA";
			return 0;
		}
		else
		{
			int count=0;
			for(int i=2;i<lenR-1;i++)
			{
				if(R[i]=='C')
				{
					count++;
				}
				else if(!(R[i]>='a' && R[i]<='z'))
				{
					cout<< "WA";
					return 0;
				}
			}
			if(count!=1)
			{
				cout<< "WA";
				return 0;
			}
			cout<< "AC";
			return 0;

		}
	
	}
	else
	{
		cout<< "WA";
		return 0;
	}

}

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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD   = 1e9 + 7;
const double PI = acos(-1.0);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int INF   = 1e18;

#define fastio            ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define f first
#define s second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define spc " "
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

const int MAXN = 1e6 + 5;
void solve(){
    int n;
    cin >> n;
    vi a(n);
    if(n == 1){
        cout << 1 << endl;
        return;
    }

    rep(i, n){
        cin >> a[i];
    }
    int ans = 0;

    sort(all(a));

    vi mark(MAXN);
    set<int> done;

    if(a[0] == 1){
        ans = a[1] == 1 ? 0 : 1;
    }else{
        rep(i, n){
            int num = a[i];
            if(present(done, num)){
                mark[num] = 1;
            }
            else{
                for(int j = 2 * num; j < MAXN; j += num){
                    mark[j] = 1;
                }
                done.insert(num);
            }
        }
        rep(i, n)
            if(!mark[a[i]]) ans++;
    }





    cout << ans << endl;






}

signed main(){
    fastio;

    solve();

    return 0;
}


Measured memory_bytes: 21748
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=200010;
int n,p,hs[MAXN],pw10[MAXN],inv[MAXN],tabl[MAXN];
char c[MAXN];
int qpow (int a,int b) {
	int res=1;
	while (b) {
		if (b&1) {res=(1ll*res*a)%p;}
		a=(1ll*a*a)%p,b>>=1;
	}
	return res;
}
int main () {
	scanf("%d%d",&n,&p);
	scanf("%s",c+1);
	for (int i=1;i<=n/2;i++) {swap(c[i],c[n-i+1]);}
	if (p==2) {
		ll ans=0;
		for (int i=1;i<=n;i++) {
			if (!((c[i]-'0')&1)) {ans+=n-i+1;}
		}
		printf("%lld\n",ans);
		return 0;
	} else if (p==5) {
		ll ans=0;
		for (int i=1;i<=n;i++) {
			if (!((c[i]-'0')%5)) {ans+=n-i+1;}
		}
		printf("%lld\n",ans);
		return 0;
	}
	pw10[0]=inv[0]=1,pw10[1]=10,inv[1]=qpow(10,p-2);
	for (int i=1;i<=n;i++) {
		pw10[i]=(1ll*pw10[i-1]*10)%p,inv[i]=(1ll*inv[i-1]*inv[1])%p;
		hs[i]=((1ll*pw10[i-1]*(c[i]-'0'))%p+hs[i-1])%p;
	}
	ll ans=0;
	for (int i=n;i>=0;i--) {
		ans+=tabl[hs[i]];
		tabl[hs[i]]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2816
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int thrdDigit = Integer.parseInt(String.valueOf(n).substring(0, 1));
        int repdigit = thrdDigit * 100 + thrdDigit * 10 + thrdDigit;

        if (n <= repdigit) {
            System.out.println(repdigit);
            return;
        }
        int nextRepDigit = (thrdDigit + 1) * 100 + (thrdDigit + 1) * 10 + thrdDigit + 1;
        System.out.println(nextRepDigit);

    }

}


Measured memory_bytes: 23636
n = gets.to_i
xx = gets.chomp.split.map(&:to_i)

yy = xx.sort

(0...n).each do |i|
  if xx[i] <= yy[n / 2 - 1]
    puts(yy[n / 2])
  else
    puts(yy[n / 2 - 1])
  end
end

Measured memory_bytes: 25316
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<string>
#include<stack>
#include<cmath>
#include<map>
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define per(i,l,r) for(int i=(r-1);i>=l;i--)
#define P pair<int,int>
#define ll long long
using namespace std;
ll mod=1e9+7;
ll dp[100005][15];
int main ()
{
	string s;
	cin>>s;
	memset(dp,0,sizeof(dp));
	
	rep(i,0,s.size())
	{
		if(i==0)
		{
			if(s[0]=='?')
			{
				rep(i,0,10)dp[1][i]=1;
			}
			else dp[1][s[0]-'0']=1;
			continue;
		}
		if(s[i]=='?')
		{
			rep(j,0,10)
			{
				rep(k,0,13)//af
				{
					ll op=dp[i][k]+dp[i+1][(k*10+j)%13];
					dp[i+1][(k*10+j)%13]=op%mod;
				}
			}
		}
		else 
		{
			rep(k,0,13)
			{
				dp[i+1][(k*10+s[i]-'0')%13]=(dp[i][k]+dp[i+1][(k*10+s[i]-'0')%13])%mod;	
			}	
		} 
	} 
	cout<<dp[s.size()][5]; 
} 

Measured memory_bytes: 12160
#include <iostream>
#include <algorithm>
#include<functional>
#include<stdio.h>
#include<stdlib.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#include<vector>
#include<cmath>
using namespace std;
int a[1000000];
int b[1000000];
int main() {
	int N;
	int D;
	cin >> N >> D;
	if (N % (2 * D + 1) == 0) {
		cout << N / (2 * D + 1);
	}
	else{
		cout << N / (2 * D + 1) + 1;
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
  public static void Main(string[] args)
  {
    var input = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int a = input[1], b = input[2];
    var candidates = new List<int>();
    for (var i = 1; i <= input[0]; i++)
    {
      var intStr = i.ToString();
      var sum = 0;
      foreach (var c in intStr)
      {
        var digit = (int) Char.GetNumericValue(c);
        sum += digit;
      }
      if (sum >= a && sum <= b) candidates.Add(i);
    }
    Console.WriteLine($"{candidates.Sum()}");
  }
}


Measured memory_bytes: 13396
# coding: utf-8
# Your code here!
import sys

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

yoyuu = [A[i]-B[i] for i in range(N)]
yoyuu.sort(reverse=True)
# print(yoyuu)
if sum(yoyuu) < 0:
    print(-1)
    sys.exit()
    
nega_sum = 0
ans = 0
for tmp in yoyuu:
    if tmp < 0:
        nega_sum -= tmp
        ans += 1
tmp_sum = 0
for tmp in yoyuu:
    if tmp_sum < nega_sum and tmp > 0:
        tmp_sum += tmp
        ans += 1
        
print(ans)

Measured memory_bytes: 18524
#include <iostream>
using namespace std;
int main(){
    int N, C;
    cin >> N >> C;
    int p, c = 0;

    for(int i = 1; i <= C; i++){
        cin >> p;
        c += p;
    }
    if(c % (N + 1) == 0) cout << (c / (N + 1)) << endl;
    else cout << (c / (N + 1) + 1) << endl;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int X, Y;
  cin >> X >> Y;
  int ans(0);

  for (int i = X; i <= Y; i = 2 * i)
    ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
"""
連結無向グラフ
道標をおいた時に、全ての部屋からの最短路となる必要がある。
"""
n,m = map(int,readline().split())
#隣接リスト
g = [[] for i in range(n)]
for i in range(m):
    x,y = map(int,readline().split())
    x,y = x-1,y-1
    g[x].append(y)
    g[y].append(x)
ans = [-1]*n

deq = deque([0])
while deq:
    fr = deq.popleft()
    for go in g[fr]:
        if ans[go] == -1:
            ans[go] = fr
            deq.append(go)
        

print("Yes")
for i in ans[1:]:
    print(i+1)

Measured memory_bytes: 90620
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;

int H, W;
vector<string> field;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int bfs(int x, int y){
    Graph dist(H, vector<int>(W, -1));
    queue<P> que;

    que.push(P(x, y));
    dist[x][y] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();

        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second +dy[i];

            if (0 <= nx && nx < H && 0 <= ny && ny < W && field[nx][ny] != '#' && dist[nx][ny] == -1) {
                que.push(P(nx, ny));
                dist[nx][ny] = dist[p.first][p.second] + 1;
            }
        }
    }

    int maxi = 0;
    for (int i = 0; i < H; i++) maxi = max(maxi, (int)*max_element(dist[i].begin(), dist[i].end()));

    return maxi;
}

int main() {
    int ans = 0;
    cin >> H >> W;
    field.resize(H);
    for (int i = 0; i < H; i++) cin >> field[i];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (field[i][j] == '.') ans = max(ans, bfs(i, j));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		int bi = Math.max(a, b);
		int sm = Math.min(a, b);
		for(int i = 0; i < bi; i++) {
			System.out.print(sm);
		}
	}
}

Measured memory_bytes: 20436
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int N,K;

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

  cin>>N>>K;

  if (K > (N-1)*(N-2)/2) {
    cout<<"-1\n";
    return 0;
  }

  vector<pii> res;
  for(int i=2;i<=N;i++) res.pb({1,i});
  queue<pii> q;
  for(int i=2;i<=N;i++) for(int j=i+1;j<=N;j++) q.push({i,j});

  while (K++ < (N-1) * (N-2)/2) res.pb(q.front()), q.pop();

  cout<<res.size()<<endl;
  for(auto pr:res) cout<<pr.fst<<' '<<pr.snd<<endl;

  return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""043-d"""


import sys


def main():
    """Main function."""
    s = input()
    len_ = len(s)

    for i in range(len_ - 2):
        if s[i] == s[i + 1]:
            print(i + 1, i + 2)
            sys.exit(0)
        if s[i] == s[i + 2]:
            print(i + 1, i + 3)
            sys.exit(0)

    if len_ >= 2 and s[-2] == s[-1]:
        print(len_ - 1, len_)
        sys.exit(0)

    print(-1, -1)


if __name__ == '__main__':
    sys.exit(main())

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

int main() {
    int N;
    cin >> N;
    vector<int> G[N], W[N];
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(v); G[v].push_back(u);
        W[u].push_back(w); W[v].push_back(w);
    }

    vector<int> color(N, -1);
    queue<int> que;
    vector<bool> visited(N, false);
    color[0] = 0;
    que.push(0);
    visited[0] = true;
    while (!que.empty()) {
        int u = que.front(); que.pop();
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            if (visited[v]) continue;
            color[v] = (color[u] + W[u][i]) % 2;
            visited[v] = true;
            que.push(v);
        }
    }

    for (int i = 0; i < N; i++) {
        cout << color[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 11904
n,m=map(int,input().split())
mod1,mod2=10**9+7,998244353
mod=mod1
ans=(m+1)%mod
if n!=1:
    a=m//(n-1)
    ans=((m+1)*(a+1)+(m+1)*a-(n-1)*a*(a+1))%mod
print(ans)


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

struct point{
    ll x, y;
};

/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    char ch, alphabet = 'a'-1;
    string answer ="None";
    set<char> s;
    while(cin >> ch){
        s.insert(ch);
    }
    for(int i = 0; i < 26; i++){
      	alphabet++;
        if(s.find(alphabet) == s.end()){
            answer = alphabet;
            break;
        }
    }
    cout << answer << '\n';
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main{
	 
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long k = scan.nextLong();
 
		SortedSet<Long> set = new TreeSet<>();
		Map<Long, Long> map = new HashMap<>();
		for(int i = 0; i < n; i++){
			long a = scan.nextLong();
			long b = scan.nextLong();
			set.add(a);
			if(map.containsKey(a)){
				map.put(a, map.get(a) + b);
			}else{
				map.put(a, b);
			}
		}
 
		for(Iterator it = set.iterator();it.hasNext();){
			long num = (long) it.next();
			k -= map.get(num);
			if(k <= 0){
				System.out.println(num);
				break;
			}
		}
 
	}
 
}


Measured memory_bytes: 98584
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
   int n;
   int x=0;
   
   cin >> n;
   
   for(int i=3;i<=n;i++){
     if (i % 3 == 0){ cout << " " << i; }
     else {
       x = i;
       do{
          if(x % 10 == 3){ cout << " " << i; break;}
          x /= 10;
       } while(x);
     }
   }
   
   cout << endl;
   
   return 0;
}


Measured memory_bytes: 3060
package main

import (
    "fmt"
)

func main(){
    var N,M int
    fmt.Scan(&N,&M)
    A := make([]int, M)
    B := make([]int, M)
    for i:=0; i<M; i++ {
        fmt.Scan(&A[i], &B[i])
        A[i]--
        B[i]--
    }
   tree := make([]int, N)
   uc := make([]int, M)
   size := make([]int, N)
   for i:=0;i<N;i++{ 
       tree[i] = i
       size[i] = 1
   }
  
   var find func(int) int
   find = func(v int) int{
        parent := tree[v]
        if parent == v { 
            return v
        } else {
            root := find(parent)
            tree[v] = root
            return root 
        }
    }

   uc[M-1] = N*(N-1)/2
   for i:=M-1; i>0; i-- {
       ra := find(A[i])
       rb := find(B[i])
       if ra != rb {
           tree[ra] = rb
           uc[i-1] = uc[i] - size[ra]*size[rb]
           new_size := size[ra] + size[rb]
           size[ra] = new_size
           size[rb] = new_size
       }else{
            uc[i-1] = uc[i]
        }    
    }

   for i:=0; i<M; i++ {
       fmt.Println(uc[i])
   }
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

ll f(ll H) {
  if (H == 0) return 0;
  if (H == 1) return 1;
  return 1 + 2 * f(H/2);
}

int main2() {
  ll H = nextLong();
  ll ans = f(H);
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    string s;
    cin>>n>>s;
    int x=0,x_max=0;
    for(int i=0;i<n;i++){
        if('I'==s[i]){
            x++;
        }else{
            x--;
        }
        if(x>x_max){
            x_max=x;
        }
    }
    cout<<x_max;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    cout << (n - 2) * 180 << endl;
    return 0;
}

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

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 r;
  cin >> r;
  cout << 3 * r * r << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++)
        cin >> A[i];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(A[i] < A[j]) {
                int t = A[i];
                A[i] = A[j];
                A[j] = t;
            }
        }
    }    
    cout << A[N-1]-A[0] << endl;
    
    return 0;
}

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

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

const long long MOD = 1000000007;

int main(){
  int h1,h2,m1,m2,t1,t2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  t1 = h1*60 + m1;
  t2 = h2*60 + m2;
  int ans = t2-t1-k;
  if(ans<=0) cout << 0 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3632
l = []
l = input().split()

stack = []

def ReversePolishNotation(i):
    global l
    if l[i] == '+' :
        b = mypop()
        a = mypop()
        push(a+b)
    elif l[i] == '-':
        b = mypop()
        a = mypop()
        push(a-b)
    elif l[i] == '*':
        b = mypop()
        a = mypop()
        push(a*b)
    else:
        push(int(l[i]))


def mypop():
    global stack
    return stack.pop(-1)

def push(n):
    global stack
    stack.append(n)


for i in range(len(l)):
    ReversePolishNotation(i)

print(mypop())



Measured memory_bytes: 5604
n,a,b,c = map(int,input().split())
l = [[*input()] for _ in range(n)]
l2 = l[1:]+["ABC"]
d = {"A":a, "B":b, "C":c}
a2 = a + 1
b2 = b + 1
c2 = c + 1
isNo = 0
if (a>0)+(b>0)+(c>0)>= 1:
  if d[l[0][0]] == 0 and d[l[0][1]] == 0:
    isNo = 1
  elif a+b+c == 1:
    for s,s2 in zip(l,l2):
      if d[s[0]]<d[s[1]]:
        d[s[1]]+=-1
        d[s[0]]+=1
        if s[0] not in s2:
          isNo = 1
          break
      else:
        d[s[1]]+=1
        d[s[0]]+=-1
        if s[1] not in s2:
          isNo = 1
          break
  else:isNo = 0
else:isNo = 1

d = {"A":a, "B":b, "C":c}
if isNo:print("No")
else:
  print("Yes")
  for s,s2 in zip(l,l2):
    if d[s[0]] > d[s[1]]:
      d[s[0]]+=-1
      d[s[1]]+=1
      print(s[1])
    elif d[s[0]] < d[s[1]]:
      d[s[1]]+=-1
      d[s[0]]+=1
      print(s[0])
    else:
      if s[0] in s2:
        d[s[1]]+=-1
        d[s[0]]+=1
        print(s[0])
      else:
        d[s[0]]+=-1
        d[s[1]]+=1
        print(s[1])

Measured memory_bytes: 22472
using System;

namespace atCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int[] button = new int[n];

            for (int i = 0; i < n; i++)
            {
                button[i] = int.Parse(Console.ReadLine());
            }

            int count = 1;

            if (button[0] != 2)
            {
                count++;

                int x = button[0] - 1;

                while (count <= n)
                {
                    if (button[x] == 2)
                    {
                        break;
                    }
                    else
                    {
                        x = button[x] - 1;
                    }

                    count++;
                }
            }

            if (n < count)
            {
                count = -1;
            }

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 13280
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
int main()
{
    int N;
    vector<pair<int,int>> works;
    ll A,B;
    ll total = 0;

    cin >> N;
    REP(i,N){
        cin >> A >> B;
        works.pb(make_pair(B,A));
    }
    sort(works.begin(),works.end());
    for(auto w : works){
        total += w.second;
        if(total > w.first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 5364
#include <iostream>
#include <algorithm>
int main() {
    int t[5];
    for (auto &x: t) std::cin >> x;
    int ans = 0;
    for (auto x: t) ans += (x + 9) / 10 * 10;
    for (auto &x: t) x = (x - 1) % 10 + 1;
    ans = ans - 10 + *std::min_element(&t[0], &t[5]);
    std::cout << ans;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int N;
    scanf("%d", &N);
    int C[N], V[N];
    int sum = 0;
    for(int i=0; i<N; i++)
        scanf("%d", &V[i]);
    for(int i=0; i<N; i++){
        scanf("%d", &C[i]);
        sum += (V[i] > C[i]) ? V[i]-C[i] : 0;
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define inf 0x3f3f3f3f
using namespace std;

int main()
{
    int n,t,a,x;
    while(cin>>n)
    {
        cin>>t>>a;
        double mo = inf,mm,mark;
        for(int i=0;i<n;i++)
        {
            cin>>x;
            mm=t-0.006*x;
            if(fabs(mm-a)<fabs(mo-a))
            {
                mark=i+1;
                mo=mm;
            }
        }
        cout<<mark<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var num int
	fmt.Scan(&num)

	var sum float64
	for i := 0; i < num; i++ {
		var (
			n float64
			s string
		)
		fmt.Scan(&n, &s)

		if s == "BTC" {
			sum += n * 380000
		} else {
			sum += n
		}
	}

	fmt.Println(sum)
}


Measured memory_bytes: 512
N,M=map(int,input().split())
H=list(map(int,input().split()))
AB=[list(map(int,input().split())) for i in range(M)]
anlist=[1]*N
for i in range(M):
  if H[AB[i][0]-1]>H[AB[i][1]-1]:
    anlist[AB[i][1]-1]=0
  elif  H[AB[i][0]-1]<H[AB[i][1]-1]:
    anlist[AB[i][0]-1]=0
  else:
    anlist[AB[i][0]-1]=0
    anlist[AB[i][1]-1]=0
print(sum(anlist))
    

Measured memory_bytes: 31900
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


int h, w, a, b;
int ans[1005][1005];
int cnt[1005];
signed main() {
	cin >> h >> w >> a >> b;
	rep(i, h + 1) {
		int sum = a * i + (w - a) * (h - i);
		rep(j, w + 1) {
			int sum2 = b * j + (h - b) * (w - j);
			if (sum == sum2) {
				rep(k, h) {
					int noko;
					if (k < i)noko = a;
					else noko = w - a;
					rep(l, w) {
						if (!noko)continue;
						if (l < j && cnt[l] < b) {
							noko--; cnt[l]++;
							ans[k][l] = 1;
						}
						if (l >= j && cnt[l] < (h - b)) {
							noko--; cnt[l]++;
							ans[k][l] = 1;
						}
					}
				}
				rep(k, h) {
					rep(l, w) {
						cout << ans[k][l];
					}
					cout << endl;
				}
				return 0;
			}
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 9088
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	s=list(RD())
	t=list(RD())
	s.sort()
	t.sort(reverse=True)
	print("Yes" if s<t else "No")




if __name__ == "__main__":
	main()


Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
	cin >> N;
	vector<int> a(N);
	rep(i,N)cin >> a[i];
	cin >> M;
	vector<int> b(M);
	rep(i,M)cin >> b[i];
	sort(ALL(a));
	sort(ALL(b));
	int cnt = 0;
	for(int i=0;i<N;i++){
		if(a[i]==b[cnt])cnt++;
	}
	if(cnt==M)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 1792