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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

int n, l;
vi w;
vi v;
void in(){
    cin >> n >> l;
    rep(i,0,n){
        w.push_back(input());
        v.push_back(input());
    }
}
int dp[110][101010];
int dfs(int i, int sum){

   
    if(sum > l) return -inf;

    if(i == n) return 0;
     if(dp[i][sum] > -1) return dp[i][sum];
    return dp[i][sum] = max(dfs(i + 1, sum), dfs(i + 1, sum + w[i]) + v[i]);



}

void solve(){
    memset(dp, -1, sizeof(dp));
    print(dfs(0,0));


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

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

int n;
int W;
int w[128],v[128];
int tt;
int dp[128][101000];

int main(){
	cin>>n>>W;
	for(int i=1;i<=n;++i) cin>>w[i]>>v[i],tt+=v[i];
	memset(dp,0x3f3f3f3f,sizeof(dp));
	for(int i=0;i<=n;++i) dp[i][0]=0;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=v[i];++j) dp[i][j]=dp[i-1][j];
		for(int j=v[i];j<=tt;++j){
			dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
		}
	}
	for(int i=tt;i>=0;--i){
		if(dp[n][i]<=W) cout<<i<<"\n",exit(0);
	}
	return 0;
}

Measured memory_bytes: 50688
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);i--)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

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

  int tmp = 0;
  tmp += b/c - (a-1)/c;
  //debug(tmp);
  tmp += b/d - (a-1)/d;
  //debug(tmp);
  int g = c*d/__gcd(c,d);

  tmp -= b/g - (a-1)/g;
  //debug(tmp);
  //debug(g);
  cout << (b-a+1) - tmp << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int k, s, day, K, S, a,b;
	cin >> day >> k >> s >> K >> S;
	if (k%K==0)a= k / K;
	else a= k / K + 1;
	if (s%S==0)b= s / S;
	else b= s / S+1;

	if (b < a)day -= a;
	else day -= b;
	cout << day << endl;

	return 0;
}

Measured memory_bytes: 1164
n = int(input())
a = list(map(int, input().split()))
Sum = 0
a.insert(0, 0)
a.append(0)
s = []
b = []
for i in range(len(a) - 1):
    b.append(abs(a[i] - a[i + 1]))
Sum_b = sum(b)
for i in range(len(b) - 1):
    ans = Sum_b - (b[i] + b[i + 1]) + abs(a[i] - a[i + 2])
    print(ans)


Measured memory_bytes: 57068
dog_ape = list(map(int,input().split(" ")))
dog_ape.sort()
cut     = (10**9)+7

def kai(n):
    ans = 1
    r   = 0
    for i in range(n):
        ans *= (i+1)**2
        if ans > cut:
            ans %= cut
    return ans

if dog_ape[0] == dog_ape[1]:
    ans = ( kai(dog_ape[0]) )*2
    ans %= cut
    print(ans)

elif dog_ape[1] - dog_ape[0] == 1:
    ans = kai(dog_ape[0])*(dog_ape[1])
    ans %= cut
    print(ans)

else:
    print(0)  


Measured memory_bytes: 3064
import unittest


def solve_small(n):
    total = 0
    for m in range(1, n):
        if n // m == n % m:
            total += m
    return total


def solve(n):
    if n == 1:
        return 0
    conds = set()
    conds.add(n-1)
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            conds.add(i-1)
            conds.add(n // i - 1)
    total = 0
    for m in list(conds):
        if n // m == n % m:
            total += m
    return total


def main():
    n = int(input())
    result = solve(n)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 8
        actual = solve(n)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 1000000000000
        actual = solve(n)
        expected = 2499686339916
        self.assertEqual(actual, expected)


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
#define FL(i,a,b) for(int i = a;i<b;i++)
typedef vector<int> vi;
typedef long long int lli;
typedef long int li;
const int inf = numeric_limits<int>::max();

#define PI 3.14159265358979323846




int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d",a*b);
}



Measured memory_bytes: 3784
#include <stdio.h>

int main(void)
{
	int d, i;
	long sum;
	
	while (scanf("%d", &d) != EOF){
		sum = 0;
		for (i = 1; i < 600 / d; i++){
			sum += (i * d)*(i * d) * d;
		}
		printf("%ld\n", sum);
	}
	
	return 0;
}

Measured memory_bytes: 596
class uf_tree():

    def __init__(self,n):
        self.n = n
        self.par = [i for i in range(n)]

    def indep(self):
        dep =0
        for i in range(self.n):
            if i == self.par[i]:
                dep += 1

        return dep

    def unite(self,child,mas):
        if self.root(child) == self.root(mas):
            return
        else:
            self.par[self.root(child)] = self.root(mas)

    def root(self,i):
        if self.par[i] == i:
            return i
        else:
            self.par[i] = self.root(self.par[i])
            return self.par[i]

    def same(self,x,y):
        if self.root(x) == self.root(y):
            return True
        else:
            return False



n,m = map(int,input().split())
uf = uf_tree(n+1)
for i in range(m):
    x,y,z = map(int,input().split())
    uf.unite(x,y)

print(uf.indep()-1)


Measured memory_bytes: 122016
import sys
sys.setrecursionlimit(10**7)
 
N, Q = map(int, input().split())
root = [[] for _ in range(N)]
ans = [0]*N
 
for _ in range(N-1):
  a,b=map(int, input().split())
  a,b=a-1,b-1
  root[a].append(b)
  root[b].append(a)

for _ in range(Q):
  p,x=map(int, input().split())
  ans[p-1]+=x
  
visited=[False]*N
def dfs(v):
  visited[v] = True
  for go in root[v]:
    if visited[go]:
      continue
    ans[go] += ans[v]
    dfs(go)

dfs(0)
print(*ans)

Measured memory_bytes: 223468
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

ll dp[3030][3030][5];

int main(){
	ll r,c,k; cin >> r >> c >> k;
	vector<vector<int>> a(r,vector<int>(c,0));
	rep(i,k){
		int x,y,t; scanf("%d%d%d",&y,&x,&t); y--; x--;
		a[y][x] = t;
	}
	rep(i,r) rep(j,c) rep(k,4) dp[i][j][k] = -linf;
	dp[0][0][0] = 0;
	dp[0][0][1] = a[0][0];
	rep(i,r){
		rep(j,c){
			if(i > 0){
				rep(k,4) chmax(dp[i][j][0], dp[i-1][j][k]);
				rep(k,4) chmax(dp[i][j][1], dp[i-1][j][k] + a[i][j]);
			}
			if(j > 0){
				rep(k,4) chmax(dp[i][j][k+(a[i][j]>0)], dp[i][j-1][k] + a[i][j]);
				rep(k,4) chmax(dp[i][j][k], dp[i][j-1][k]);
			}
		}
	}
	ll ans = 0;
	rep(i,4) chmax(ans, dp[r-1][c-1][i]);
	cout << ans << "\n";
}

Measured memory_bytes: 393348
/////////////////////////////////////////////////////////////////////////////////
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'               `$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$//  
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$'                   `$$$$$$$$$$$$$$$$$$$$$$$$$$$$//
//$$$'`$$$$$$$$$$$$$'`$$$$$$!                       !$$$$$$'`$$$$$$$$$$$$$'`$$$//
//$$$$  $$$$$$$$$$$  $$$$$$$                         $$$$$$$  $$$$$$$$$$$  $$$$//
//$$$$. `$' \' \$`  $$$$$$$!       $$        $$      !$$$$$$$  '$/ `/ `$' .$$$$//
//$$$$$. !\  i  i .$$$$$$$$       $$$$      $$$$      $$$$$$$$. i  i  /! .$$$$$//
//$$$$$$   `--`--.$$$$$$$$$        $$        $$       $$$$$$$$$.--'--'   $$$$$$//
//$$$$$$L        `$$$$$^^$$                           $$^^$$$$$'        J$$$$$$//
//$$$$$$$.   .'   ""~   $$$    $.                 .$  $$$   ~""   `.   .$$$$$$$//
//$$$$$$$$.  ;      .e$$$$$!    $$.             .$$  !$$$$$e,      ;  .$$$$$$$$//
//$$$$$$$$$   `.$$$$$$$$$$$$     $$$.         .$$$   $$$$$$$$$$$$.'   $$$$$$$$$//
//$$$$$$$$    .$$$$$$$$$$$$$!     $$`$$$$$$$$'$$    !$$$$$$$$$$$$$.    $$$$$$$$//
//$$$$$$$     $$$$$$$$$$$$$$$$.    $    $$    $   .$$$$$$$$$$$$$$$$     $$$$$$$//
//                                 $    $$    $								   //
//                                 $.   $$   .$								   //
//                                `$        $'								   //
//                                 `$$$$$$$$'								   //
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;

// Type-Define 
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef std::vector<char> vc;
typedef std::vector< vector<int> > vii;
typedef std::pair<int, int> pii;

// Hash-Define
#define int long long
#define MOD 1000000007
#define debugStart cerr << "\n[DEBUG START]\n"
#define debugStop cerr << "\n[DEBUG STOP]\n"
#define KHATAM cout << std::endl;
#define set_zero(x) memset(x, 0, sizeof(x));
#define ForPrint(x) std::for_each( begin(x), end(x), []( auto const& el ){ std::cout << el << " ";  } )

//Functions 
template<typename T> auto gcd ( T a, T b ) -> int  { return (b==0)?a:gcd(b,a%b); }

const int inf = 1e9 + 5;

signed
main() {

    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1; 
    //cin >> T;
    for ( int testcase = 1; testcase <= T; ++testcase ) {
        int N, K;
        std::cin >> N >> K;
        int arr[N];
        int dp[N];
        for ( int i = 0; i < N; ++i ) {
            
            std::cin >> arr[i];
        }
        for( int i = 0; i < N; ++i ) 
            dp[i] = INT32_MAX;
        dp[0] = 0;
        for ( int i = 1; i < N; ++i ) {
            int min_value = INT32_MAX;
            for ( int k = 1; k <= K; ++k ) {
                if (i-k>=0) {
                    min_value = min( min_value, dp[ i-k ] + abs( arr[i] - arr[i-k] ) );
                }
            }
            dp[i] = min_value;
        }
        std::cout << dp[N-1] ;
        KHATAM;
    }
    return 0;
}


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

int main(){
	int n,k,q;
	cin >> n >> k >> q;
	int* p = new int[n];
	int* a = new int[q];
	for(int i=0;i<q;i++) cin >> a[i];
	for(int i=0;i<q;i++){
		p[a[i]-1]++;
	}
	for(int i=0;i<n;i++){
		//cout << p[i] << endl;
		if(p[i] > q-k) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}


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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " "<< y << endl;    
    return 0;
}



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

using namespace std;
int main()
{
    int n;
    double tmp;
    vector<double> v;
    vector<double>::iterator it;
    double av;
    cin >> n;
    
    for(int i=0; i<n; i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    
    // for(int i=0; i<v.size(); i++){
    //     cout << v[i] << endl;
    // }
    
    
    it = v.begin();
    while(v.size() > 1){
        //cout << *it << "," << *(it+1) << endl;
        av = (*it + *(it+1))/2.;
        it = v.erase(it);
        *it = av;
        sort(v.begin(), v.end());
//        for(int i=0; i<v.size(); i++){
//            cout << v[i] << endl;
//        }
//        if(v.size() < 2) break;
    }
    
    cout << v[0] << endl;
    
    //v.clear();
    return 0;
}


Measured memory_bytes: 256
from sys import setrecursionlimit

setrecursionlimit(10**5)
S = input()
li = []
str = 'AKIHABARA'
def dfs(i, s):
    if i == len(str):
        li.append(s)
        return
    if str[i] == 'A':
        dfs(i+1, s)
    dfs(i+1, s+str[i])

dfs(0, '')
# print(li)
print('YES' if S in li else 'NO')



Measured memory_bytes: 8984
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n = I()
A = LI()
g = reduce(gcd, A)
print(g)

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

using namespace std;

#define INF INT_MAX

long A,B,C,N;
long l[8];

long dfs(long cur,long a,long b,long c){
    if(cur == N){
        return min({a,b,c}) > 0 ?  //延長・縮小魔法を考慮、-30は必ず３本は使用しなければならないため０＋l[n]×３分
            abs(a - A) + abs(b - B) + abs(c - C) - 30 : INF;
    }
    long ret0 = dfs(cur+1,a,b,c);
    long ret1 = dfs(cur+1,a+l[cur],b,c) + 10; //合成時のコスト＋１０を忘れずに（以下同様）
    long ret2 = dfs(cur+1,a,b+l[cur],c) + 10;
    long ret3 = dfs(cur+1,a,b,c+l[cur]) + 10;
    return min({ret0,ret1,ret2,ret3});
}

int main(){
    cin >> N >> A >> B >> C;
    for(long i=0;i<N;i++){
        cin >> l[i];
    }
    cout << dfs(0,0,0,0) << endl;
    return 0;
}

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

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

long long A, B;
long long C, D;

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

int main() {

	cin >> A >> B >> C >> D;
	A--;
	long long i, i2, i3, g;
	i = A / C;
	i2 = A / D;
	g = C * D / gcd(C, D);
	i3 = A / g;
	
	A = A - i - i2 + i3;

	i = B / C;
	i2 = B / D;
	i3 = B / g;

	B = B - i - i2 + i3;
	
	cout << B-A << endl;
	
}

Measured memory_bytes: 384
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000
#define l first
#define r second

int n;
pair<int,int> a[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) {
		scanf("%d %d", &a[i].l, &a[i].r);
		a[i].r++;
	}
	return 1;
}

void init() {
}

long solve() {
	long ans = 0;
	int k = 0;
	for (int i=0; i<n; i++) {
		int d = a[i].r - a[i].l;
		if (d > ans) {
			k = i;
			ans = d;
		}
	}
	int maxl = INT_MIN, minr = INT_MAX;
	for (int i=0; i<n; i++) {
		if (i==k) continue;
		maxl = max(maxl, a[i].l);
		minr = min(minr, a[i].r);
	}
	ans += max(0, minr - maxl);

	maxl = max(maxl, a[k].l);
	minr = min(minr, a[k].r);

	sort(a, a+n);
	int rx = INT_MAX;
	for (int i=n-1; i>0; i--) {
		rx = min(rx, a[i].r);
		long t = (long)max(0, rx-maxl) + max(0,minr-a[i-1].l);
		ans = max(ans, t);
	}
	return ans;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}






Measured memory_bytes: 896
#include <bits/stdc++.h>
#define mp make_pair
using namespace std;
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

const int N = 505;

int n,m,p[N*N];
int dis[N][N]; int a[N][N]; bool inq[N][N]; long long ans;
deque<pair<int,int> >Q;
int t[] = {1,0,-1,0,1};
int main(){
	int i,j,x,y,nx,ny;
	read(n),m = n * n;
	for (i = 1; i <= m; ++i) read(p[i]),--p[i];
	for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) a[i][j] = 1,dis[i][j] = min(min(i+1,n-i),min(j+1,n-j))-1;
	for (i = 1; i <= m; ++i){
		x = p[i] / n,y = p[i] % n;
		ans += dis[x][y];
		a[x][y] = 0;
		if (x) Q.push_back(mp(x-1,y)),inq[x-1][y] = 1;
		if (y) Q.push_back(mp(x,y-1)),inq[x][y-1] = 1;
		if (x+1<n) Q.push_back(mp(x+1,y)),inq[x+1][y] = 1; 
		if (y+1<n) Q.push_back(mp(x,y+1)),inq[x][y+1] = 1;
		Q.push_back(mp(x,y)),inq[x][y] = 1;
		while (!Q.empty()){
			x = Q.front().first,y = Q.front().second,Q.pop_front(),inq[x][y] = 0; 
		//	cerr<<x<<' '<<y<<' ' << dis[x][y]<<' '<<'\n';
			for (j = 0; j < 4; ++j){
				nx = x+t[j],ny = y+t[j+1];
				if (nx>=0&&ny>=0&&nx<n&&ny<n&&dis[nx][ny] > dis[x][y] + a[x][y]){
					dis[nx][ny] = dis[x][y] + a[x][y];
					if (!inq[nx][ny]){
						if (a[nx][ny]) Q.push_back(mp(nx,ny)); else Q.push_front(mp(nx,ny));
						inq[nx][ny] = 1; 
					}
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 7644
#include <stdio.h>
#include <iostream>
#include <stack>
#include <vector>
#include <utility>
using namespace std;
int binarySearch(int a[], int n, int key)
{
    int right = n;
    int left = 0;
    int mid;
    while (left < right)
    {
        mid = (right + left) / 2;
        if(key < a[mid])
            right = mid;
        else if(key > a[mid])
            left = mid +1;
        else 
            return 1;
    }
    return 0;
}
int main()
{
    int count = 0;
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; i++)
        cin >> S[i];
    int q;
    cin >> q;
    int T;
    for (int i = 0; i < q; i++)
    {
        cin >> T;
        if (binarySearch(S, n, T))
            count++;
    }
    cout << count << "\n";
}


Measured memory_bytes: 3476
n=int(input())
a=list(map(int,input().split()))
c=0
f=True
while f:
    f=False
    for j in range(n-1,0,-1):
        if a[j]<a[j-1]:
            a[j],a[j-1]=a[j-1],a[j]
            c+=1
            f=True
print(*a)
print(c)


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[1252][1252];
int enemy[1252];
int head[1252];

int main(){
    scanf("%d",&n);
    REP(i,n)REP(j,n-1)scanf("%d",&a[i][j]),a[i][j]--;
    int ans = 0;
    while(true){
        ans++;
        REP(i,n)if(head[i]!=n-1){
            enemy[i] = a[i][head[i]];
        }
        bool upd = false;
        REP(i,n)if(head[i]!=n-1 && enemy[enemy[i]]==i){
            head[i]++;
            upd = true;
        }
        if(!upd){
            puts("-1");
            return 0;
        }
        if(count(head,head+n,n-1)==n){
            break;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 5120
#include <cstdio>
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
#define N 200005

int n, len;
std::string a[N];
std::unordered_map<std::string, int> cnt;

struct node {
    std::string val;
    int cnt;
} A[N];

inline bool cmp(const node &a, const node &b) { return a.cnt > b.cnt || a.cnt == b.cnt && a.val < b.val; }

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) std::cin >> a[i], ++cnt[a[i]];
    for (int i = 0; i < n; ++i)
        if (cnt[a[i]]) {
            A[++len].val = a[i];
            A[len].cnt = cnt[a[i]];
            cnt[a[i]] = 0;
        }
    std::sort(A + 1, A + len + 1, cmp);
    std::cout << A[1].val << std::endl;
    for (int i = 2; i <= len; ++i) 
        if (A[i].cnt != A[1].cnt) break;
        else std::cout << A[i].val << std::endl;
    return 0;
}


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

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

    long long ans = k;
    for (int i = 0; i < n-1; i++) {
        ans *= k - 1;
    }

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

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i, n, l;
  int min = 1, num;
  int taste = 0;
  
  scanf("%d %d", &n, &l);
  
  if(l >= 0){
    min = l;
  }else if(l+n-1 >= 0){
    min = 0;
  }else{
    min = l+n-1;
  }
  
  for(i = 1; i <= n; i++){
    taste += l+i-1;
  }
  taste -= min;
  
  printf("%d", taste);
  
  return 0;
}

Measured memory_bytes: 128
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    if N % 2:
        print(0)
        return

    N //= 10
    ans = N
    while N:
        N //= 5
        ans += N

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61920
#include <stdio.h>

int main(void) {
	int A,B,C,K;
	scanf("%d%d%d%d",&A,&B,&C,&K);
	if(K<=A){
		printf("%d\n",K);
	}else if(A<K&&K<=A+B){
		printf("%d\n",A);
	}else{
		printf("%d\n",A-(K-(A+B)));
	}
	return 0;
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
int num[100010];
int maxl = -1000000000;
int main() {
	memset(num, 0, sizeof(num));
	int N;
	cin >> N;
	int a[N];
	for (int i = 0; i < N; i ++) {
		cin >> a[i];
		num[a[i]] ++;
	}
	sort(a, a + N);
	for (int i = -2; i < a[N - 1]; i ++) {
		maxl = max(num[i] + num[i + 1] + num[i + 2], maxl);
	}
	cout << maxl << endl;
}


Measured memory_bytes: 1024
use proconio::input;

fn main() {
  input! {
    n: i64,
  }
  let mut res = 0;

  for i in 1..n+1 {
    if i % 3 != 0 && i % 5 != 0 {
      res += i;
    }
  }
  println!("{}", res);
}

Measured memory_bytes: 2144
n = int(input())
lst = [int(i) for i in input().split()]

sumleft = [0]*(n+1)

for i in range(n):
    sumleft[i+1] = sumleft[i] + lst[i]

total = sumleft[-1]
ans = None

for i in range(1,n):
    x = sumleft[i]
    y = total - x
    if ans == None:
        ans = abs(x-y)
    else:
        ans = min(ans,abs(x-y))
print(ans)

Measured memory_bytes: 24812
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class217
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NM[0], M = NM[1];
            var MIN = new int[M];
            var MAX = new int[M];
            for(int  i = 0; i < M; i++)
            {
                var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
                int a = ab[0], b = ab[1];
                MIN[i] = a;
                MAX[i] = b;
            }
            Array.Sort(MAX,MIN);
            int edge = int.MinValue;
            int count = 0;
            for(int i = 0; i < M; i++)
            {
                if (edge <= MIN[i])
                {
                    count++;
                    edge = MAX[i];
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 18016
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(a*n>b){
        System.out.println(b);
      }else{
        System.out.println(a*n);
      }
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
const int N=2005;
long long f[N][N],fac[N*N],inv[N*N];
long long fsp(long long x,int y){
	long long ans=1;
	while(y){
		if(y&1)	ans=ans*x%P;
		x=x*x%P,y>>=1;
	}
	return ans;
}
long long C(int n,int m){
	return fac[n]*inv[m]%P*inv[n-m]%P;
}
int n,m,k;
int main(){
	scanf("%d%d",&n,&k),m=n*k;
	fac[0]=inv[0]=f[0][0]=1;
	for(int i=1;i<=m;i++){
		fac[i]=fac[i-1]*i%P;
		inv[i]=fsp(fac[i],P-2);
	}
	if(k==1){
		puts("1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
			f[i][j]=(f[i][j-1]*C(m-i-(j-1)*(k-1)-1,k-2)%P*(n-j+1)+f[i-1][j])%P;
	printf("%lld\n",f[n][n]);
	return 0;
}

Measured memory_bytes: 94592
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  int N;
  cin >> N;
  vector<int> cont(N);
  int all_sum = 0;
  for(int i = 0 ; i < N ; i++){
    cin >> cont.at(i);
    all_sum += cont.at(i);
  }
  
  int min_sum = all_sum;
  int a;
  int sum = 0;
  
  for(int i = 0 ; i < N ; i++){
    sum += cont.at(i);
    if( (all_sum - 2*sum ) < 0){
      
      a = (-1)*(all_sum - 2*sum );
    }
    else{
      a = (all_sum - 2*sum );
    }
    
    min_sum = min(a , min_sum);
    
  }
  
  cout << min_sum << endl;
  
}


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

import collections
import math

dicA = collections.Counter(A)

total = 0
for x in list(dicA.values()):
  if x != 1:
    total += math.factorial(x) // (math.factorial(x - 2)*2)

for i in range(N):
  print(total - dicA[A[i]] +1)
  

Measured memory_bytes: 25644
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <stdlib.h>
#include <time.h>

#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end());
#define ll long long
#define INF 2000000000

using namespace std;

int main() {
	string s;
	cin >> s;
	if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int k=0;
  	int num=0;
  	char s[100]={0};
  
	scanf("%d",&k);
  	scanf("%s",s);

  	for(int i=0;s[i]!='\0';i++){
    	num=i+1;
    }
  	
  	if(num<=k){
  		printf("%s",s);
  	}else{
  		for(int i=0;i<k;i++){
    		printf("%c",s[i]);
    	}
      	printf(".");
      printf(".");
      printf(".");
  	}
}

Measured memory_bytes: 2144
n = int(input())
l = list(map(int,input().split()))
l.append(0)
height = 1
counter = 0
while(height<=max(l)):
    for i in range(n+1):
        if height <= l[i-1] and l[i] < height:
            counter += 1
    height += 1
print(counter)

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

using vll = std::vector<long long>;
constexpr long long mod{998244353};

int main()
{
	std::string s;
	std::cin >> s;
	int blue{}, red{}, n;
	n = s.size();
	for (auto& e: s) blue += e - '0';
	red = 2 * n - blue;
	std::vector<vll> dp(2 * n + 1, vll(blue + 1));
	dp[0][0] = 1;
	int available_blue{}, available_red{};
	for (int length{1}; length <= n; length++)
	{
		available_blue += s[length - 1] - '0';
		available_red += '2' - s[length - 1];
		for (int blue_i{1}; blue_i <= available_blue; blue_i++)
			dp[length][blue_i] = dp[length - 1][blue_i - 1];
		for (int blue_i{std::max(0, length - available_red)}; blue_i <= std::min(blue, length); blue_i++)
		{
			dp[length][blue_i] += dp[length - 1][blue_i];
			dp[length][blue_i] %= mod;
		}
	}
	for (int length{n + 1}; length <= 2 * n; length++)
	{
		for (int blue_i{}; blue_i <= blue; blue_i++)
		{
			if (blue_i && blue_i <= blue)
				dp[length][blue_i] += dp[length - 1][blue_i - 1];
			if (length - blue_i <= red)
			{
				dp[length][blue_i] += dp[length - 1][blue_i];
				dp[length][blue_i] %= mod;
			}
		}
	}
	printf("%lld\n", dp[2 * n][blue]);

	return 0;
}

Measured memory_bytes: 125312
/* 
    Author : Jeff Ahn
    Sat 15 Aug 2020 04:59:39 AM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'

signed main() {
  fastio;

  string s;
  cin >> s;
  int res = 0;
  if (s[1] == 'R') {
    res = 1;
    if (s[0] == 'R') {
      res++;
    }
    if (s[2] == 'R') {
      res++;
    }
  }
  else if (s[0] == 'R' or s[2] == 'R') res = 1;
  cout << res << endl;
  
}


Measured memory_bytes: 3612
//114 B - 754 2018/11/02
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    string s;
    cin >> s;
    string num;
    int min=1000;
    for(int i=0;i<=s.size()-3;++i){
        num=s.substr(i,3);
        if(min>abs(753-stoi(num))) min=abs(753-stoi(num));
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

const ll INF = 1LL << 50;

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  vP ans;

  ll sign = 0;
  ll maxabs = 0;
  ll im = 0;
  for (ll i = 0; i < n; i++) {
    if (maxabs <= abs(a[i])) {
      maxabs = abs(a[i]);
      sign = (a[i] >= 0) ? 0 : 1;
      im = i + 1;
    }
  }  // i

  if (sign == 0) {
    ans.push_back(P(im, 1));
    ans.push_back(P(im, 1));
    for (ll i = 1; i < n; i++) {
      ans.push_back(P(1, i + 1));
    }
    for (ll i = 1; i < n; i++) {
      ans.push_back(P(i, i + 1));
    }
  } else {
    ans.push_back(P(im, n));
    ans.push_back(P(im, n));
    for (ll i = n - 1; i >= 1; i--) {
      ans.push_back(P(n, i));
    }
    for (ll i = n - 1; i >= 1; i--) {
      ans.push_back(P(i + 1, i));
    }
  }

  assert((ll)ans.size() <= 2 * n);

  cout << ans.size() << endl;
  rep(i, (ll)ans.size()) {
    ll ia = ans[i].first;
    ll ib = ans[i].second;
    cout << ia << " " << ib << endl;
    a[ib - 1] += a[ia - 1];
  }

  //rep(i, n) cout << a[i] << " " << endl;

  return 0;
}


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

int main()
{
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int time1, time2;
	time1 = h1 * 60 + m1;
	time2 = h2 * 60 + m2;
	cout << max(0, time2 - time1 - k) << endl;
	return 0;
}

Measured memory_bytes: 3608
n, x = gets.split.map &:to_i

$a, $p = [1], [1]
n.times do |i|
  $a << $a[i] * 2 + 3
  $p << $p[i] * 2 + 1
end

def f(n, x)
  if n == 0
    return x <= 0 ? 0 : 1
  elsif x <= 1 + $a[n - 1]
    return f(n-1, x-1)
  else
    return $p[n-1] + 1 + f(n-1, x-2-$a[n-1])
  end
end

puts f(n, x)


Measured memory_bytes: 1788
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * ceil_(a, b)); }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class C {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    string S;
    int K;
    cin >> S >> K;
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    rep(i, S.size()) {
      int now = S[i] - 'a';
      if (K >= 26 - now and now != 0) {
        S[i] = 'a';
        K -= (26 - now);
      }
    }
    int now         = S[S.size() - 1] - 'a';
    S[S.size() - 1] = alphabet[(K + now) % 26];
    cout << S << endl;
  }
};


signed main() {
  C solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>
#define _for(i, n) for (int i = 0; i < n; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

template <typename T>
vector<size_t> sort_indexes(const vector<T> &v) {
  vector<size_t> idx(v.size());
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&v](size_t i1, size_t i2) { return v[i1] < v[i2]; });
  return idx;
}

ll gcd(ll a,ll b) {
  ll gmax = 1;
  ll aa = (a<b)?a:b;
  ll bb = (a<b)?b:a;
  for(ll i = 1;i*i<=aa;i++) {
    if (aa%i==0) {
      if (bb%(aa/i) == 0) {
        gmax = aa/i;
        break;
      }
      if (bb%i == 0) {
        gmax = i;
      }
    }
  }
  return gmax;
}

int main() {
  ll n;
  cin >> n;
  ll a[n];
  _for(i, n) cin >> a[i];
  ll gcd_max = 1;
  ll gcd_arr[n];
  ll gcd_arr2[n];
  ll cgcd;
  gcd_arr[0] = a[0];
  gcd_arr2[n - 1] = a[n - 1];
  for (ll i = 1; i < n; i++) gcd_arr[i] = gcd(a[i], gcd_arr[i - 1]);
  for (ll i = 1; i < n; i++) gcd_arr2[n - i - 1] = gcd(a[n - i - 1], gcd_arr2[n - i]);
  _for(i, n) {
    if (i == 0)
      cgcd = gcd_arr2[1];
    else if (i == n - 1)
      cgcd = gcd_arr[n - 2];
    else
      cgcd = gcd(gcd_arr[i - 1], gcd_arr2[i + 1]);
    gcd_max = max(gcd_max, cgcd);
  }
  cout << gcd_max << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int x;
    cin >> x;
    if (x >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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


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

int dfs(vector<vector<int>> &t, vector<int> &dis, int u, int parent, int d){
	dis[u] = d;
	for(int i = 0; i < t[u].size(); i++){
		if(t[u][i] != parent){
			dfs(t, dis, t[u][i], u, d + 1);
		}
	}
}

int main(){
	int N, u, v, i;
	scanf("%d%d%d", &N, &u, &v);
	u--;
	v--;
	vector<vector<int>> t(N, vector<int>(0));
	for(i = 1; i < N; i++){
		int A, B;
		scanf("%d%d", &A, &B);
		A--;
		B--;
		t[A].push_back(B);
		t[B].push_back(A);
	}
	vector<int> disu(N), disv(N);
	dfs(t, disu, u, -1, 0);
	dfs(t, disv, v, -1, 0);
	int ans = 0;
	for(i = 0; i < N; i++){
		if(disu[i] < disv[i]){
			ans = max(ans, disv[i] - 1);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12928
#include <stdio.h>
int main(void) {
  int a[100000], b[100000];
  int i, num;
  char ch[100000][2];

  i = 0;  num = 0;
  do {
    scanf("%d %s %d", &a[i], ch[i], &b[i]);
    num++;
    i++;
  } while (ch[i - 1][0] != '?');

  for (i = 0; i < num; i++) {
    if (ch[i][0] == '+')
      printf("%d\n", a[i] + b[i]);
    else if (ch[i][0] == '-')
      printf("%d\n", a[i] - b[i]);
    else if (ch[i][0] == '*')
      printf("%d\n", a[i] * b[i]);
    else if (ch[i][0] == '/')
      printf("%d\n", a[i] / b[i]);
  }

  return 0;
}

Measured memory_bytes: 1044
/*
*   1. What was the key concept?
*   2. What mistake did I make? (if any)
*   3. Thing to remember from now on.
*/

#include <iostream>
using namespace std;

#define INF 0x3f3f3f3f;
#define INFL 0x3f3f3f3f3f3f3f3f;
#define NITRO ios_base::sync_with_stdio(false); cin.tie(false)
#define PRECISE cout << fixed << setprecision(9)

using ll = long long int;
using ld = long double;

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;

int main(){

    int n, x, t;
    cin >> n >> x >> t;

    cout << (n / x + (!!(n % x))) * t << endl;


    return 0;
}

// Check the corner cases. (n = 1).
// Check overflows. (int vs ll).
// Be consistent.

Measured memory_bytes: 3608
n=int(input())
t,a=map(int,input().split())
h=[]
tmp=input()
lst=tmp.split(' ')

for i in range(n):
    c=t-int(lst[i])*0.006
    h.append(abs(a-c))

m=0
for i in range(1,n):
    if(h[i]<h[m]):
        m=i
print(m+1)


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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> res(h, vector<int>(w));
    map<pair<int, int>, int> mp;
    int p = -1;
    forn(i, h) {
        forn(j, w) {
            char c; cin >> c;
            if(c == '#') {
                mp[{i, j}] = 1;
                if(p == -1)
                    p = i;
            }
        }
    }
    int num = 0;
    forab(i, p, h-1) {
        int c = 0;
        forn(j, w) {
            if(mp[{i, j}]) {
              ++c;
              break;
            }
        }
        if(c) {
            ++num;
            forn(j, w) {
                if(mp[{i, j}]) {
                    --c;
                  if(c != 0) ++num;
                }    
                res[i][j] = num;
            }
        } else {
            forn(j, w) {
                res[i][j] = res[i-1][j];
            }
        }
    }
    for(int i = p-1; i>=0; --i) {
        forn(j, w) {
            res[i][j] = res[i+1][j];
        }
    }
    forn(i, h) {
        forn(j, w)
            cout << res[i][j] << " ";
        cout << "\n";
    }
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
#include <ctype.h>
#include <math.h>
using namespace std;
int AV(int i){
    if(i<0)i*=-1;
    return i;
}

int main(){
    int N,Sum=0;
    cin>>N;
    int A[N+2];
    A[0]=0,A[N+1]=0;
    for(int i=1;i<=N;i++){
        cin>>A[i];
        Sum+=AV(A[i]-A[i-1]);
    }
   	Sum+=AV(A[N]);
    for(int i=1;i<=N;i++){
      	int gap1=AV(A[i]-A[i-1]);
      	int gap2=AV(A[i+1]-A[i]);
      	int gap3=AV(A[i+1]-A[i-1]);
        cout<<Sum-gap1-gap2+gap3<<endl;
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    vector<int> hoge= {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<hoge.at(k-1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define coord_comp(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define v_index(v, x) (lower_bound(all(v),x)-(v).begin())
typedef pair<int,int> pp;
typedef long long ll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ cin>>x; }
template<typename T1,typename T2>
void read(pair<T1,T2>& p){ read(p.first); read(p.second); }
template<typename T,typename... Args>
void read(T&a,Args&...b){ read(a); read(b...); }

int main(){
	int a,b; read(a,b);
	if(a<=0 && 0<=b){
		puts("Zero");
	} else if(0<a) puts("Positive");
	else {
		int nc=b-a+1;
		if(nc&1) puts("Negative");
		else puts("Positive");
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list()
for _ in range(N):
    S.append(input())
M = int(input())
T = list()
for _ in range(M):
    T.append(input())

all_words = set(S+T) # unique strings only
scores = [S.count(w) - T.count(w) for w in all_words]
print(max(0,max(scores)))

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

int main() {
  string s; cin >> s;
  int n = s.size(), cnt = 0;
  for (int i = 0; i < n/2; i++)
    if (s[i] != s[n-i-1]) cnt++;
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=1e6+10;

int main() {
    string s;
    cin>>s;
    if (s[2]==s[3]&&s[4]==s[5]) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();int k=0;
String s=sc.next();int d=0;
for(int c=0;c<n;c++){
if(s.charAt(c)=='I')++k;
if(s.charAt(c)=='D')--k;
if(d<=k)d=k;}
System.out.println(d);
}}

Measured memory_bytes: 21588