akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]){
    int m, i, k, s[100];
    char card[201], copy[1000];
    long count;
    
    while(1){
        scanf("%s",card);
        if( strcmp( card , "-" ) == 0 ){
            break;
        }
        count = strlen(card);
        scanf("%d",&m);
        for( k = 0 ; k < m ; k++ ) {
            scanf("%d",&s[k]);
            for( i = 0 ; i < s[k] ; i++ ){
                copy[i] = card[i];
            }
            for( i = 0 ; i < count - s[k] ; i++ ){
                card[i] = card[s[k]+i];
            }
            for( i = 0 ; i < s[k] ; i++ ){
                card[count-s[k]+i] = copy[i];
            }
        }
        printf("%s\n",card);
    }
    
    return 0;
}

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

using namespace std;

int main(){
    int n, sum1 = 0, sum2 = 0, ans = INT_MAX;
    cin >> n;
    vector<int> Xs;

    for(int i = 0; i < n; ++i)
    {
        int Xi; cin >> Xi;
        sum1 += (Xi * Xi);
        sum2 += Xi;
        Xs.push_back(Xi);
    }


    for(int p = 1; p <= 100; p++)
    {
        ans = min(ans, sum1 + p*(n*p - 2 * sum2));
    }


    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
while input = gets

  if (input.to_i) == 0
    exit
  else
    n = input.to_i
    score = Array.new(n, nil)
    sum = 0
  end

  for roop in 0 .. (n - 1)
    score[roop] = gets.to_i
  end

  score.sort!

  for roop in 1 .. (n - 2)
    sum += score[roop]
  end

  puts sum / (n - 2)
end

Measured memory_bytes: 6096
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

ll dp[110][110000];

int main(){
  string s;
  cin>>s;
  if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int min=10000000;
                int a,b,sum,tens;

                for(int j=1; j<=N/2; j++){
                        a = j;
                        b = N - a;
                        sum = 0;
                        while(a != 0){
                                sum += a % 10;
                                a /= 10;
                        }
                        while(b != 0){
                                sum += b % 10;
                                b /= 10;
                        }
                        if(min>sum){
                                min = sum;
                        }
                }
                System.out.println(min);
        }
}


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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep (i,n){
        cin >> a.at(i);
    }
    ll ans=0;
    for(int i=1;i<a.size();i++){
        if(a.at(i)<a.at(i-1)){
            ans+=a.at(i-1)-a.at(i);
            a.at(i)=a.at(i-1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n,k;
        cin>>n>>k;
        set<ll>s;
        rep(i,0,k)
        {
            ll d;
            cin>>d;
            // s.insert(s);
            rep(i,0,d)
            {
                ll x;
                cin>>x;
                s.insert(x);
            }
        }
        cout<<n-s.size()<<endl;
    }
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

vector<ll> divisors(ll n){
	vector<ll> res;
	for(ll i = 2;i * i <= n; ++i){
		if(n%i == 0){
			res.push_back(i);
			if(i != n/i)res.push_back(n/i);
		}
	}
	if(n != 1)res.push_back(n);
	return res;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	ll n;
	cin >> n;
	ll ans = 0;
	ans += divisors(n-1).size();
	auto res = divisors(n);
	for(ll div:res){
		ll t = n;	
		while(t%div==0)t/=div;
		t%=div;
		ans += t == 1;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
	int n,i,s=0;
	cin>>n;
	int a[n],b[n],c[n-1];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	cin>>b[i];
	for(i=0;i<n-1;i++)
	cin>>c[i];
	s=b[a[0]-1];
	for(i=1;i<n;i++)
	{
	    s+=b[a[i]-1];
	    if(a[i]==a[i-1]+1)
	    {
	        s+=c[a[i]-2];
	    }
	}
	cout<<s<<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 n = sc.nextInt();
        int k = sc.nextInt();
        int nt=0 ,kt=0;
        for(int i=1; i<n; i++) {
            nt += i;
        }
        for(int i=1; i<k; i++) {
            kt += i;
        }
        System.out.println(nt + kt);
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;



template <typename T> T gcd(T a, T b) {if(b == 0) return a;return gcd(b,a%b);}
template <typename T> T lcm(T a, T b) {return a*b/gcd(a,b);}
template <typename T> T extgcd(T a, T b, T& x, T& y){
    T d = a;
    if(b != 0){
        d = extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else x=1,y=0;
    return d;
}
template <typename T> T modpow(T x, T n, T m) {
    if(n==0) return 1;
    T resp = modpow(x*x%m,n/2,m);
    if(n&1) resp = resp*x%m;
    return resp;
}
template <typename T> T modinverse(T a, T m) {
    T x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}
struct combination {
    ll M = mod;
    vector<ll> fact,ifact;
    combination(ll n):fact(n+1),ifact(n+1){
        fact[0]=1;ifact[0]=1;
        for (ll i = 0; i<n; i++) {
            fact[i+1] = fact[i]*(i+1) % M;
            ifact[i+1] = ifact[i]*modpow(i+1, M-2, M) % M;
        }
    }
    ll com(ll a, ll b){
        if(a == 0 && b == 0)return 1;
        if(a < b || a < 0)return 0;
        ll tmp = ifact[a-b] * ifact[b] % M;
        return tmp * fact[a] % M;
    }
};

int main()
{
    ll N,K;
    cin >> N >> K;
    combination C(20004);
    for (ll i = 1; i <= K; i++) {
        cout << C.com(N-K+1,i)*C.com(K-1,i-1)%mod << endl;
    }
    

    
    
    
    

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int x[100010] = {};
	int N;
	cin >> N;
	rep(i, N) {
		int a;
		cin >> a;
		x[a]++;
		x[a + 1]++;
		x[a + 2]++;
	}
	int ans = 0;
	for (int i = 0; i < 100010; i++) {
		ans = max(ans, x[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
	int n,i,a=0,b,m,z,f;
	char s[200000];
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>s[i];
		if(s[i]=='R')
		{
			a++;
			z=i;
		}
	}
	b=n-a;
	if(b==0||b==n)
	cout<<0;
	else if(a<=b)
	{
		m=a;
		for(i=0;i<a;i++)
		{
			if(s[i]=='R')
			m--;
		}
		cout<<m;
	}
	else if(a>b)
	{
		m=a;
		for(i=0;i<a;i++)
		{
			if(s[i]=='R')
			m--;
		}
		f=0;
		for(i=0;i<z;i++)
		{
			if(s[i]=='W')
			f++;
		}
		if(f<m)
		m=f;
		cout<<m;
	}
}

Measured memory_bytes: 3780
#include <iostream>
using namespace std;
char ch[12][12];
int dh[]={1,0,-1,0},dw[]={0,-1,0,1};
void dfs(int h,int w){
	ch[h][w]='0';for(int i=0;i<4;i++){
		int nx=h+dh[i],ny=w+dw[i];
		if(nx>=0&&nx<12&&ny>=0&&ny<12&&ch[nx][ny]=='1')dfs(nx,ny);
	}return ;
}
int main(){
	while(cin>>ch[0]){
		int solve=0;
		for(int i=1;i<12;i++)cin>>ch[i];
		for(int i=0;i<12;i++)for(int j= 0;j<12;j++)if(ch[i][j]=='1'){dfs(i,j);solve++;}
		cout << solve << endl;
	  }
}

Measured memory_bytes: 1140
import java.util.*;

public class Main {

    static <T extends Comparable<? super T>> boolean nextPermutation(T[] sequence) {
        int first = getFirst(sequence);
        if (first == -1) return false;
        int toSwap = sequence.length - 1;
        while (sequence[first].compareTo(sequence[toSwap]) >= 0) --toSwap;
        swap(sequence, first++, toSwap);
        toSwap = sequence.length - 1;
        while (first < toSwap) swap(sequence, first++, toSwap--);
        return true;
    }

    static <T extends Comparable<? super T>> int getFirst(T[] sequence) {
        for (int i = sequence.length - 2; i >= 0; --i)
            if (sequence[i].compareTo(sequence[i + 1]) < 0) return i;
        return -1;
    }

    static <T extends Comparable<? super T>> void swap(T[] sequence, int i, int j) {
        T tmp = sequence[i];
        sequence[i] = sequence[j];
        sequence[j] = tmp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] p = new Integer[n];
        Integer[] q = new Integer[n];
        Integer[] perm = new Integer[n];
        for (int i = 0; i < n; ++i) p[i] = sc.nextInt();
        for (int i = 0; i < n; ++i) q[i] = sc.nextInt();
        for (int i = 0; i < n; ++i) perm[i] = i + 1;

        int pNum = 0, qNum = 0;
        int cnt = 1;
        do {
            if (Arrays.equals(perm, p)) pNum = cnt;
            if (Arrays.equals(perm, q)) qNum = cnt;
            ++cnt;
        } while (nextPermutation(perm));

        System.out.println(Math.abs(pNum - qNum));
    }
}

Measured memory_bytes: 23436
#include<iostream>
using namespace std;
int fib(int n)
{
    int F[50];
    if(n<=1) return 1;
    F[0] = 1;
    F[1] = 1;
    for(int i = 2 ; i <= n; i++)
    {
        F[i] = F[i-1] + F[i-2];
    }
    return F[n];
}

int main()
{
    int n;
    cin>>n;
    cout<<fib(n)<<endl;
    return 0;
}

Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<numeric>
#include<queue>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<bool> ok(n,false);
    priority_queue<pair<int,int>> q;
    ll c=0,ans=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        int b;
        cin>>b;
        if(a[i]<b) ans++,c+=b-a[i];
        else q.push(make_pair(a[i]-b,i));
    }
    while(c>0){
        if(q.empty()){
            cout<<-1<<endl;
            return 0;
        }
        int i=q.top().second;
        int x=q.top().first;
        q.pop();
        c-=x;
        if(x!=0) ans++; 
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4680
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;

ll dp[100010][4];

void f(ll &a, ll b){
  if(b>=MOD)b-=MOD;
  a += b;
  if(a>=MOD)a-=MOD;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  string s;
  cin >> s;
  
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  
  int n = s.size();
  rep(i,n){
    rep(j,4){
      if(s[i]=='?')f(dp[i+1][j],3*dp[i][j]);
      else f(dp[i+1][j],dp[i][j]);
    }
    if(s[i]=='A' || s[i]=='?') f(dp[i+1][1],dp[i][0]);
    if(s[i]=='B' || s[i]=='?') f(dp[i+1][2],dp[i][1]);
    if(s[i]=='C' || s[i]=='?') f(dp[i+1][3],dp[i][2]);
  }
  
  cout << dp[n][3] << endl;
    
  return 0;
}


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

#define MOD 1000000007

long long pows(long long a, long long n) {
  long long left = n;
  long long ans = 1;
  long long ks = a;
  while(left > 0) {
    if(left%2 == 1) {
      ans = ans*ks%MOD;
    }
    left /= 2;
    ks = ks*ks%MOD;
  }
  return ans;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long ex0 = pows(10,n)-pows(9,n);
  long long ex9 = pows(10,n)-pows(9,n);
  long long or09 = pows(10,n)-pows(8,n);
  long long ans = ex0+ex9-or09+MOD*(long long)3;
  cout << ans%MOD << endl;
  
}

Measured memory_bytes: 3652
use std::io;

fn main() {
    let mut input_string = String::new();
    io::stdin()
        .read_line(&mut input_string)
        .unwrap();
    let input_ints: Vec<u8> = input_string.trim().split(" ")
        .map(|s| s.parse::<u8>().unwrap())
        .collect();
    let (a, b) = (input_ints[0], input_ints[1]);

    let output = if a+b == 15 { "+" }
                 else if a*b == 15 { "*" }
                 else { "x" };
    println!("{}", output);
}


Measured memory_bytes: 4476
n = int(input())
a = list(map(int,input().split()))
if(1 in a):
  ans = 0
  jud = 0
  f = 1
  for i in range(n):
    if(a[i]!=f):
      ans += 1
    else:
      f += 1
  print(ans)
else:
  print(-1)


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

int main() {
  ll n,m;
  cin >> n >> m;
  vector<int> ok(n,0);
  vector<ll> no(n,0);
  rep(i,m) {
    ll p;
    string s;
    cin >> p >> s;
    p--;
    if(ok[p]) continue;
    if(s == "WA") no[p]++;
    else ok[p] = 1;
  }
  ll ans = 0;
  rep(i,n) {
    if(ok[i]) ans++;
  }
  cout << ans << endl;
  ans = 0;
  rep(i,n) {
    if(ok[i]) ans += no[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
struct edge { LL to, cost; };

const LL inf = 11234567890123;
LL N, M;
std::vector<LL>dist;
std::vector<std::vector<edge>>G;

// s -> t の経路中に負閉路が存在するか
bool bellman_ford(LL n, LL s, LL t)
{
	std::fill(dist.begin(), dist.end(), inf);
	dist[s] = 0;
	rep(i, 2 * n)
	{
		for (LL v = 1; v <= n; ++v)
		{
			for (auto e : G[v])
			{
				if (dist[v] != inf && dist[e.to] > dist[v] + e.cost)
				{
					dist[e.to] = dist[v] + e.cost;
					if (i >= n - 1 && e.to == t) return true;
				}
			}
		}
	}
	return false;
}

int main()
{
	in >> N >> M;
	std::vector<LL>a(M), b(M), c(M);
	dist.resize(N + 1); G.resize(N + 1);
	rep(i, M)
	{
		in >> a[i] >> b[i] >> c[i];
		G[a[i]].push_back({ b[i],-c[i] });
	}
	if (bellman_ford(N, 1, N)) out << "inf" << std::endl;
	else out << -dist[N] << std::endl;
	return 0;
}


Measured memory_bytes: 384
n,k = map(int, raw_input().split())
c = 0
for d in range(k+1,n+1):
    p = (n - k) / d
    c += (p+1) * (d-k)
    c -= max(0, (p+1) * d - 1 - n)
    if k == 0: c -= 1
print c


Measured memory_bytes: 5764
#include <bits/stdc++.h>
#define filename "longestpath"
#define int long long
#define N 100005

using namespace std ;

bool chk[N] ;
vector <int> a[N] ;
int f[N] ;
int n ,m ;

void open()
{
    //freopen(filename".inp","r",stdin) ;
    //freopen(filename".out","w",stdout) ;
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    cout.tie(0) ;
}
void readinp()
{
    cin >> n >>m ;
    for (int i = 1 ; i <= m ; i++)
    {
        int x , y ;
        cin >> x >> y ;
        a[x].push_back(y) ;
    }
}
int recall(int x)
{
    if (chk[x]) return f[x] ;
    chk[x] =1 ;
    int &ans = f[x] ;
    ans = 0 ;
    for (int i : a[x]) 
        ans = max(ans , recall(i) + 1) ;
    return ans ;
}
void process()
{
    int res = 0 ;
    for (int i = 1 ; i <= n ; i++)
        res = max(res , recall(i)) ;
    cout << res ;
}
signed main()
{
    open() ;
    readinp() ;
    process() ;
}

Measured memory_bytes: 11868
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009


ll wt[110],val[110];
ll dp[110000];
void solve()
{
	ll n,w;
	rl2(n,w);
	fr(i,0,n)
	{
		rl2(wt[i],val[i]);
	}

	fr(i,0,n)
	{
		frr(j,w+1,0)
		{
			if(j+wt[i]<=w)
			{
				dp[j+wt[i]]=max(dp[j+wt[i]],dp[j]+val[i]);
			}
		}
	}
	ll ans=0;
	fr(i,0,w+1)
		ans=max(ans,dp[i]);
	wl(ans);
	NL;
	//ll k[n+1][w+1];
	// fr(i,0,n+1)
	// {
	// 	fr(j,0,w+1)
	// 	{
	// 		if(i==0||j==0)
	// 			k[i][j]=0;
	// 		else if(wt[i-1]<=j)
	// 		{
	// 			k[i][j]=max(val[i-1]+k[i-1][j-wt[i-1]],k[i-1][j]);
	// 		}
	// 		else
	// 			k[i][j]=k[i-1][j];

	// 	}
	// }
	//wl(k[n][w]);
	//NL;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> N >> T;
    vi a(N);
    cin >> a;
    int mx = 0;
    int mn = INF;
    REP(i, N) {
        chmin(mn, a[i]);
        chmax(mx, a[i] - mn);
    }
    map<int, int> mp;
    map<int, int> mem;
    REP(i, N)
    mp[a[i]]++;
    REP(i, N) {
        ans += mp[a[i] + mx] - mem[a[i] + mx];
        mem[a[i]]++;
    }
    cout << ans << endl;
}

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

int main(){

  
  int n;
  int sum;
  int s;
  int max,min;

  while(cin >> n){
    if(n==0){ break; }
    sum = 0;
    max=0,min=1000;

    for(int i=0; i<n; i++){
      cin >> s;
      if(s>max){ max=s; }
      if(s<min){ min=s; }

      sum += s;
    }

    sum -= max+min;

    cout << sum/(n-2) << endl;

  }


  return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int dsum(int x) {
    int sum = 0;
    while (x > 0) {
        sum += x % 10;
        x /= 10;
    }
    return sum;
}

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

    int ans = 1e9;
    rep(i, 1, n) {
        ans = min(ans, dsum(i) + dsum(n - i));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
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;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}
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(a > b){ a=b; return 1; } return 0; }

bool isPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2){
    if (num % i == 0){
      return false;
    }
  }
  return true;
}

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

  string s;
  ll n;
  cin >> s >> n;

  ll index = 0;
  while(1){
    ll num = s[index] - '0';
    n -= pow(num, 5000000000000000);
    if(n <= 0){
      cout << s[index] << endl;
      return 0;
    }
    index++;
  }
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main() {
	int n;cin>>n;
	if (n <= 999)cout << "ABC" << endl;
	else cout << "ABD" << endl;
	return 0;
}

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

int main() {
    int A,B;
    cin>>A>>B;
    
    int ans=0;
    
    if(A<B){
        swap(A,B);
    }
    if(A==B){
        ans=2*A;
        cout<<ans<<endl;
        return 0;
        
    }
    ans=A+A-1;
    cout<<ans<<endl;
    return 0;
    
    
    
    
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s,t;
    cin>>s>>t;
    int num=0;
    for(int i=0;i<s.length();i++){
        if(s[i]==t[i]) num++;
    }
    cout<<num<<endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

sumA = sum(A)
divisors = []
for i in range(1, sumA + 1):
    if i * i > sumA:
        break
    if sumA % i != 0:
        continue
    divisors.append(i)
    if sumA // i != i:
        divisors.append(sumA // i)

divisors.sort(reverse=True)

ans = 0
for d in divisors:
    costs = [a % d for a in A]
    costs.sort()
    if sum(costs[:N - sum(costs) // d]) <= K:
        print(d)
        break


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
#define pb push_back 
#define x first 
#define y second 
#define MOD 1000081
 
using namespace std;
typedef long long ll;
typedef pair< int , int > PII;
const int dirx[] = {-2,-1,1,2, 1, -1};
const int diry[] = {0,1,1,0, -1, -1};
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("eqs.in", "r", stdin);
    freopen("eqs.out", "w", stdout);
    #endif
}
 
int n, m;
int a[100100];
vector < int > V, R;
set < int > S;
 
int main(){ 
    //debugMode();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    while (n--) cin >> m, S.insert(m);
    cout << S.size();
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(){cout << -1 << '\n';}
const int INF = 1e18;

signed main(){
    string s, t; cin >> s >> t;
    reverse(all(t));
    YES(s == t);
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    string s;
    cin >> s;
    s += s;
    s.pop_back();
    string p;
    cin >> p;
    bool flag2 = false;
    rep(i,s.size() - p.size() +1){
        bool flag = true;
        rep(j,p.size()){
            if(s.at(i+j) != p.at(j)) flag = false;
        }
        if(flag) flag2 = true;
    } 
    if(flag2) cout << "Yes";
    else cout << "No";
    cout << endl;

return 0;
}


Measured memory_bytes: 3160
using System;
using System.Linq;

namespace ABC116_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split().Select(int.Parse).ToArray();

            if (h.Length == 1)
            {
                Console.WriteLine(h[0]);
                return;
            }

            long cnt = 0;
            var min = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (h[i] <= h[i + 1]) continue;
                cnt += h[i] - min;
                min = h[i + 1];
            }
            if (h[N - 2] <= h[N - 1])
            {
                cnt += h[N - 1] - min;
            }
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13268
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	bs := NewBufScanner(in)
	bw := NewBufWriter(out)
	defer bw.w.Flush()
	n, a := bs.IntScan(), bs.IntScan()
	str := "No"
	if a >= n % 500 {
		str = "Yes"
	}
	bw.Printf(str)
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 1024), 1e+9)
	s.Split(bufio.ScanWords)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// IntScan Scan Data
func (b *BufScanner) IntScan() int {
	v, err := strconv.Atoi(b.Scan())
	if err != nil {
		panic(err)
	}
	return v
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

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

int main(){
  int N, W;
  cin >> N >> W;
  int dp[10001];
  fill_n( dp, W + 1, -1);
  dp[0] = 0;

  for(int i = 0; i < N; i++){
    int v, w;
    cin >> v >> w;
    for(int j = w; j <= W; j++){
      if(dp[j - w] != -1) dp[j] = max( dp[j - w] + v, dp[j]);
    }
  }
  cout << *max_element( dp, dp + W + 1) << endl;
}                           

Measured memory_bytes: 1200
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main(){
	while ( true ) {
		int x, y;
		cin >> x;
		cin >> y;

		if ( x == 0 && y == 0 ) {
			break;
		}

		int small, large;

		if ( x < y ) {
			small = x;
			large = y;
		
		} else {
			small = y;
			large = x;
		}

		cout << small << " " << large << endl;

	}
}

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

using namespace std;

#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ull unsigned long long int

const int INF = 1e9 + 7;
const int N = 1e5+5;


int main() {

	IO;

	int n;
	cin >> n;
	
	vector<int> a(n);
	
	for (int i = 0; i < n; ++i) cin >> a[i];
	
	int mn = a[0];
	int cnt = 1;
	
	for (int i = 1; i < n; ++i) {
		if (a[i] < mn) {
			++cnt;
			mn = a[i];
		}
	}
	
	cout << cnt;
}


Measured memory_bytes: 3960
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-9;
using vi = vector <int>;
using vvi = vector <vi>;

int combination(int n, int k)
{
  if(k < 0 || n < k) return (0);
  int ret = 1;
  for(int i = 1; i <= k; ++i) {
    ret *= n--;
    ret /= i;
  }
  return (ret);
}

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	int v[n];
	map <int, int> mp;
	rep(i, n) {
		cin >> v[i];
		mp[v[i]]++;
	}

	sort(v, v + n);
	reverse(v, v + n);

	long double ans = 0;
	int combi = 0;
	for (int i = a; i <= b; i++) {
		long double sum = 0;
		int cnt = 1;
		for(int j = 0; j < i; j++) {
			sum += v[j];
			if(j != 0 && v[j - 1] == v[j]) {
				cnt++;
			} else {
				cnt = 1;
			}
		}
		if(ans <= sum / i) {
			if(ans != sum / i) {
				combi = 0;
			}
			ans = sum / i;
			combi += combination(mp[v[i - 1]], cnt);
		}
	}
	printf("%.10Lf\n%lld\n", ans, combi);
}

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

long long calc(long long a, long long b, long long c)
{
	long long x = max({ a, b, c });
	long long y = min({ a, b, c });

	return abs(x - y);
}

int main(void)
{
	long long H, W;
	cin >> H >> W;

	long long min = 9999999999999;
	long long S1, S2, S3, ans;
	for (int j = 0; j < 2; ++j) {
		for (int i = 1; i < H; ++i) {
			S1 = i * W;
			S2 = (H - i) / 2 * W;
			S3 = (H - i + 1) / 2 * W;
			ans = calc(S1, S2, S3);
			if (min > ans)	min = ans;

			S2 = (H - i) * (W / 2);
			S3 = (H - i) * ((W + 1) / 2);
			ans = calc(S1, S2, S3);
			if (min > ans)	min = ans;
		}
		int tmp = H;
		H = W;
		W = tmp;
	}

	cout << min << endl;

	return 0;
}

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

typedef long long int ll;
#define pb push_back
#define mp make_pair
#define N 200005

vector <int> adj[N];
int black[N],white[N],vis[N],vis1[N];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	int n,i,u,v;
	cin>>n;
	for(i=1;i<n;i++){
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	queue <int> p,q;
	p.push(1);
	q.push(n);
	black[1]=0;
	white[n]=0;

	while(!p.empty()){
		int s = p.front();
		vis[s]=1;
		for(i=0;i<adj[s].size();i++)
			if(!vis[adj[s][i]]){
				black[adj[s][i]] = black[s]+1; 
				p.push(adj[s][i]);
			}

		p.pop();

	}
	while(!q.empty()){
		int s = q.front();
		vis1[s]=1;
		for(i=0;i<adj[s].size();i++)
			if(!vis1[adj[s][i]]){
				white[adj[s][i]] = white[s]+1; 
				q.push(adj[s][i]);
			}

		q.pop();

	}
	int count=0;
	for(i=1;i<=n;i++){
		// cout<<black[i]<<" "<<white[i]<<endl;
		if(black[i]<=white[i]){
			count++;
		}
	}

	if(count>(n-count)){
		cout<<"Fennec"<<endl;
	}
	else
		cout<<"Snuke"<<endl;






	return 0;
}


Measured memory_bytes: 10496
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

struct UF {
	vector<int> data;
	UF(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool find(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

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

    int n,m;cin>>n>>m;
    vector<P> v(m);
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;a--;b--;
        v[i]=P(a,b);
    }
    int res=0;
    for(int i=0;i<m;i++){
        // v[i] を削除
        UF uf(n);
        for(int j=0;j<m;j++){
            if(i==j) continue;
            int a=v[j].first,b=v[j].second;
            uf.unite(a,b);
        }
        if(uf.size(0)!=n) res++;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
N = int(input())
W = list(map(int,input().split()))
# abs_list = list()
# for i in range(len(W)):
# 	abs_list.append(abs(sum(W[:i+1])-sum(W[i+1:])))
# print(min(abs_list))

W_sum = list()
W_sum.append(0)
for i in range(N):
	W_sum.append(W_sum[i] + W[i])

ans = 100000007
for i in range(len(W_sum)):
	ans = min(ans, abs((W_sum[N] - W_sum[i]) - W_sum[i]))

print(ans)


Measured memory_bytes: 61768
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>

void test_case()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int mx=a[0], ans=1;
    for(int i=1;i<n;i++) {
        if(a[i]<=mx) {
            ans++;
            mx=min(mx,a[i]);
        }
    }
    cout<<ans;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


Measured memory_bytes: 4380
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 10000;
int a[MAXN + 10];
bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	int p = 0;
	while (scanf("%d", &a[p++])!=EOF);
	sort(a, a + p,cmp);
	printf("%d\n%d\n%d\n", a[0], a[1], a[2]);
	return 0;
}


Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  srand((unsigned)time(NULL));
  int h1,m1,h2,m2,k;
  cin >> h1>>m1>>h2>>m2>>k;
  cout << h2*60+m2-h1*60-m1-k << endl;
  return 0;
}


Measured memory_bytes: 3636
/*Lucky_Glass*/
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=1e5,inf=(1<<29);

struct GGRAPH{
	struct GNODE{int to,lim;GNODE *nxt,*rev;}Gnod[N*20];
	GNODE *Gtop[N*5],*Gcnt;
	void Init(){
		Gcnt=Gnod;
		memset(Gtop,NULL,sizeof Gtop);
	}
	void AddEdge(int u,int v,int lim,int rlim){
		GNODE *p=++Gcnt,*q=++Gcnt;
		*p=(GNODE){v,lim,Gtop[u],q};Gtop[u]=p;
		*q=(GNODE){u,rlim,Gtop[v],p};Gtop[v]=q;
	}
}Gflw;
GGRAPH::GNODE *cap[N*5];

int n,Gn,Ps,Pt;
int Ip[N+3],Iq[N+3],Edep[N*5];
bool Bp[N+3],Bq[N+3];

bool BFS(){
	for(int i=1;i<=Gn;i++) Edep[i]=inf;
	queue<int> que;
	que.push(Ps);Edep[Ps]=0;
	while(!que.empty()){
		int u=que.front();que.pop();
		for(auto it=Gflw.Gtop[u];it;it=it->nxt){
			int v=it->to;
			if(Edep[v]!=inf || !it->lim) continue;
			Edep[v]=Edep[u]+1;
			que.push(v);
		}
	}
	return Edep[Pt]!=inf;
}
int Aug(int u,int flwin){
	if(u==Pt) return flwin;
	int flwout=0;
	while(cap[u]){
		int v=cap[u]->to;
		if(!cap[u]->lim || Edep[u]+1!=Edep[v]){
			cap[u]=cap[u]->nxt;
			continue;
		}
		int flwv=min(cap[u]->lim,flwin-flwout);
		flwv=Aug(v,flwv);
		cap[u]->lim-=flwv;
		cap[u]->rev->lim+=flwv;
		flwout+=flwv;
		if(flwout==flwin) break;
		cap[u]=cap[u]->nxt;
	}
	return flwout;
}
int Dinic(){
	int maxflw=0;
	while(BFS()){
		for(int i=1;i<=Gn;i++) cap[i]=Gflw.Gtop[i];
		maxflw+=Aug(Ps,inf);
	}
	return maxflw;
}
int main(){
	Gflw.Init();
	scanf("%d",&n);Gn=2*n;
	Ps=++Gn,Pt=++Gn;
	for(int i=1;i<=n;i++) scanf("%d",&Ip[i]),Ip[i]++; // 1~n
	for(int i=1;i<=n;i++) scanf("%d",&Iq[i]),Iq[i]++; // n+1~2n
	for(int i=1;i<=n;i++)
		if(!Bp[i]){
			Gn++;
			int u=i;
			while(!Bp[u]){
				Bp[u]=true;
				Gflw.AddEdge(Gn,u,inf,inf);
				u=Ip[u];
			}
		}
	for(int i=1;i<=n;i++)
		if(!Bq[i]){
			Gn++;
			int u=i;
			while(!Bq[u]){
				Bq[u]=true;
				Gflw.AddEdge(Gn,u+n,inf,inf);
				u=Iq[u];
			}
		}
	for(int i=1;i<=n;i++){
		if(Ip[i]==i && Iq[i]==i && Ip[i]==Iq[i]){
			Gflw.AddEdge(Ps,i+n,1,0);
			Gflw.AddEdge(i+n,Pt,1,0);
		}
		if(Ip[i]!=i && Iq[i]==i && Ip[i]!=Iq[i]){
			Gflw.AddEdge(Ps,i,1,0);
		}
		if(Ip[i]==i && Iq[i]!=i && Ip[i]!=Iq[i]){
			Gflw.AddEdge(i+n,Pt,1,0);
		}
		if(Ip[i]!=i && Iq[i]!=i && Ip[i]==Iq[i]){
			Gflw.AddEdge(i,i+n,1,1);
		}
		if(Ip[i]!=i && Iq[i]!=i && Ip[i]!=Iq[i]){
			Gflw.AddEdge(i+n,i,1,0);
		}
	}
	int Rr=Dinic();
	printf("%d\n",n-Rr);
	return 0;
}


Measured memory_bytes: 32640
a = list(map(int, input().split())) 

money_hon_list = []
for i in range(a[0]):
    money_hon_list.append(list(map(int, input().split())) )

money_hon_list = sorted(money_hon_list ,key=lambda x:(x[0],x[1]))

botles = 0
sum_money = 0
for j in range(len(money_hon_list)):
    for k in range(money_hon_list[j][1]):
        if botles < int(a[1]):
            sum_money += money_hon_list[j][0]
            botles += 1
        else:
            break

print(sum_money)
    
    


Measured memory_bytes: 36192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
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;}



signed main(){
	int M,D;
	cin>>M>>D;
	int ans = 0;
	FOR(i,1,M+1){
		FOR(j,1,D+1){
			int a=j/10;
			int b=j%10;
			if(a<2||b<2)continue;
			//cout<<a<<" "<<b<<endl;
			if(a*b==i)ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct point{ // 点を表す構造体
    int x_elem;
    int y_elem;
}point;

point deg90rot(point vtx1, point vtx2){ // vtx1を中心にvtx2を90度回転させた座標を返す関数
    /* 複素数平面上で考える。
     * 複素数 z1 を中心に複素数 z2 を90°回転させた複素数 z は
     *   z = (z2 - z1)i + z1  と表される。
     *
     * z1 = x1 + iy1, z2 = x2 + iy2 とすると
     * z = {x2 + iy2 - (x1 + iy1)}i + x1 + iy1
     *   = {x2 - x1 + i(y2 - y1)}i + x1 + iy1
     *   = -(y2 - y1) + i(x2 - x1) + x1 + iy1
     *   = x1 + y1 - y2 + i(- x1 + x2 + y1)
     */
    point vtx;
    vtx.x_elem = vtx1.x_elem + vtx1.y_elem - vtx2.y_elem;
    vtx.y_elem = - vtx1.x_elem + vtx2.x_elem + vtx1.y_elem;
    return vtx;
}

int main(void){
    point vtx1, vtx2, vtx3, vtx4;
    scanf("%d%d%d%d", &vtx1.x_elem, &vtx1.y_elem, &vtx2.x_elem, &vtx2.y_elem);
    
    // vtx1, vtx2, vtx3, vtx4 は反時計回りに並んでいる
    vtx4 = deg90rot(vtx1, vtx2); // vtx4はvtx1を中心にvtx2を90°回転させた座標にある。
    vtx3 = deg90rot(vtx4, vtx1); // vtx3はvtx4を中心にvtx1を90°回転させた座標にある。
  
    printf("%d %d %d %d\n", vtx3.x_elem, vtx3.y_elem, vtx4.x_elem, vtx4.y_elem);
    return 0;
}

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

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(true){
    if(b >= c){
      cout << "Yes" << endl;
      break;
    }
    if(d >= a){
      cout << "No" << endl;
      break;
    }
    a = a - d;
    c = c - b;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


int main() {
    int N, M; cin >> N >> M;
    if(abs(N-M)>1){
        cout << 0 << endl;
        return 0;
    }

    ll a = 1;
    for(int i=1; i<=N; i++){
        a *= i;
        a %= mod;
    }
    
    ll b = 1;
    for(int i=1; i<=M; i++){
        b *= i;
        b %= mod;
    }
    
    if(N==M) a*=2;
    cout << a*b%mod << endl;
    
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        ABC178EPoint[] points = new ABC178EPoint[n];
        for(int i=0; i<n; i++) {
            ABC178EPoint point = new ABC178EPoint();
            point.x = in.nextLong();
            point.y = in.nextLong();
            points[i] = point;
        }

        Arrays.sort(points, new ABC178EPoint1());
        long ans1 = Math.abs(points[0].x - points[n-1].x) + Math.abs(points[0].y - points[n-1].y);
        Arrays.sort(points, new ABC178EPoint2());
        long ans2 = Math.abs(points[0].x - points[n-1].x) + Math.abs(points[0].y - points[n-1].y);

        System.out.println(Math.max(ans1, ans2));
    }
}
class ABC178EPoint {
    long x;
    long y;
}
class ABC178EPoint1 implements Comparator<ABC178EPoint> {
    // y=x+a の直線と衝突する順番。切片の順番。 a=y-x
    @Override
    public int compare(ABC178EPoint o1, ABC178EPoint o2) {
        long ans = (o1.y-o1.x) - (o2.y-o2.x);
        return ans<0 ? -1 : (ans>0 ? 1 : 0);
    }
}
class ABC178EPoint2 implements Comparator<ABC178EPoint> {
    // y=-x+a の直線と衝突する順番。切片の順番。a=y+x
    @Override
    public int compare(ABC178EPoint o1, ABC178EPoint o2) {
        long ans = (o1.x+o1.y) - (o2.x+o2.y);
        return ans<0 ? -1 : (ans>0 ? 1 : 0);
    }
}


Measured memory_bytes: 67172