akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define chk(a) rep(i, a.size()) cout << a[i] << " "
#define SORT(c) sort((c).begin(),(c).end())
#define ll long long
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)


using namespace std;
typedef pair<int, int> pii;
#define WARU 1000000007;

int main(void) {

	string str;
	cin >> str;
	long long k;
	cin >> k;

	long long n = str.length();
	ll nokori = k;
	rep(i, n) {
		if (str[i] == 'a') {
			continue;
		}
		int tmp = 'z' - str[i];
		if (nokori > tmp) {
			str[i] = 'a';
			nokori -= (tmp + 1);
		}
	}
	if (nokori > 0) {
		str[n - 1] = 'a' + (str[n - 1] - 'a' + (nokori % 26)) % 26;
	}
	cout << str << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){

	long int i,n,max=-1000000,min=1000000,total=0,a[10000];

	scanf("%ld",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a[i]);
		if(max<a[i])max=a[i];
		if(min>a[i])min=a[i];
		total+=a[i];
	}

	printf("%ld %ld %ld\n",min,max,total);

	return 0;

}

Measured memory_bytes: 676
N=int(input())
inf=10**5
dp=[inf]*(N+1)
dp[0]=0

sixes=[6**(i) for i in range(1,7)]
nines=[9**(i) for i in range(1,6)]

for i in range(1,N+1):
  dp[i]=dp[i-1]+1
  
  for s in sixes:
    if i-s>=0:
      dp[i]=min(dp[i],dp[i-s]+1)
    else:
      break
      
  for n in nines:
    if i-n>=0:
      dp[i]=min(dp[i],dp[i-n]+1)
    else:
      break

print(dp[N])


Measured memory_bytes: 3828
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl "\n";
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,bool> pllb;
typedef pair<pair<ll,ll>,ll> plll;
 
const ll N = 1e5+10;
const ll INF = 1e9;
const ll N2 = 1010;
const int MOD = 1e9+7;

int n,k;
int arr[N];

int memo[N];

int dp(int idx)
{
    int &ret = memo[idx];
    if(~ret)
        return ret;
    ret = 0;
    if(idx<n-1)
        ret = abs(arr[idx+1]-arr[idx])+dp(idx+1);
    for(int i = 2; i<=k; i++)
    {
        if(idx+i<n)
            ret = min(ret,abs(arr[idx+i]-arr[idx])+dp(idx+i));
        else
            break;
        
    }
    return ret;
}



int main()
{
	fastio
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("out.txt","w",stdout);
	#endif

    memset(memo,-1,sizeof memo);
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    cout << dp(0);
}

Measured memory_bytes: 5760
A,B,C,D,E,F=map(int,input().split())
A*=100
B*=100
ans=(A,0)
Max=0
for a in range(1+F//A):
    F_a=F-a*A
    water_a=a*A
    for b in range(1+F_a//B):
        F_b=F_a-b*B
        water_b=water_a+b*B
        for c in range(1+F_b//C):
            suger_c=c*C
            if suger_c>E*water_b/100:break
            F_c=F_b-c*C
            d=min(F_c//D,(E*water_b//100-suger_c)//D)
            suger_d=suger_c+d*D
            if water_b+suger_d==0:continue
            if suger_d/(water_b+suger_d)>Max:
                Max=suger_d/(water_b+suger_d)
                ans=(water_b+suger_d,suger_d)
print(str(int(ans[0]))+' '+str(int(ans[1])))

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

using namespace std;

int main() {
    int n, m;

    cin >> n >> m;

    vector<int> h(n);

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

    vector<int> a(m), b(m);

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

    set<int> ng;

    for(int i = 0; i < m; ++i) {
        if(h.at(a.at(i) - 1) < h.at(b.at(i) - 1)) {
            ng.insert(a.at(i));
        } else if(h.at(a.at(i) - 1) > h.at(b.at(i) - 1)) {
            ng.insert(b.at(i));
        } else {
            ng.insert(a.at(i));
            ng.insert(b.at(i));
        }
    }

    printf("%d\n", n - ng.size());

    return 0;
}

Measured memory_bytes: 7220
class Card():
    def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
    def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
    
    def __eq__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.mark == other.mark and self.number == other.number
        
    def __repr__(self):
        return '{}{}'.format(self.mark, self.number)


def BubbleSort(target):
    ls = target.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
    print(' '.join(map(str, ls)))
    return sorted(ls)


def SelectSort(target):
    ls = target.copy()
    for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
    print(' '.join(map(str, ls)))
    return sorted(ls)

def judge(original, sorted_list):
    if original == sorted_list:
        print('Stable')
    else:
        print('Not stable')


_ = int(input())
l2 =  [Card(i) for i in input().split()]
l2_sort = sorted(l2)

bubble = BubbleSort(l2)
judge(l2_sort, bubble)

select = SelectSort(l2)
judge(l2_sort, select)



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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
	vector<int> v;
    int i, input;

    cin >> i;

    for (int j = 0; j < i; j++)
    {
        cin >> input;
        v.push_back(input);
    }

    int p, count = -1;

    for (int num : v)
    {
        p = 2;
        int tmp = 0;
        while (num % p == 0)
        {
            p *= 2;
            tmp++;
        }
        if (count == 0)
        {
            break;
        }
        if (count < 0 || tmp < count)
        {
            count = tmp;
        }
    }

    cout << count << endl;
    return 0;
}




Measured memory_bytes: 3624
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, X);
    IN(ll, N);
    AIN(ll, p, N);
    vector<bool> ok(201, true);
    FOR(a, p)
    {
        ok[a] = false;
    }
    ll ans = 0;
    REP1(i, 101)
    {
        if (abs(X - i) < abs(X - ans) and ok[i])
        {
            ans = i;
        }
    }
    OUT(ans);
}

Measured memory_bytes: 3632
//




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


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define pf push_front
#define ppf pop_front()
#define ff first
#define ss second
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=j; i--)
#define pll pair<ll,ll>
#define plb pair<ll,bool>
#define psl pair<string,ll>
#define psb pair<string,bool>
#define srt(v) sort((v).begin(),(v).end())
#define ub(v,val) upper_bound((v).begin(),(v).end(),(val))-(v).begin()
#define lb(v,val) lower_bound((v).begin(),(v).end(),(val))-(v).begin()


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;
const ll mod = (ll) 1e9  +  7;




void cazz() {
    ll t=1,i=0,j,n;
    //cin>>t;
    while(t--) {
        cin>>n;
        ll a,b;
        ll cnt=0;
        bool f=0;
        fr(i,0,n) {
            cin>>a>>b;
            if(a==b) cnt+=1;
            else cnt=0;
            if(cnt>=3) f=1;
        }
        if(f) cout<<"Yes\n";
        else cout<<"No\n";
    }
}




int main() {
    spdio;
	cazz();
	return 0;
}


Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] a = new int[n][m];
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				a[i][j] = sc.nextInt();
				--a[i][j];
			}
		}

		boolean[] invalid = new boolean[m];
		int ans = Integer.MAX_VALUE;
		for (int t = 0; t < m; ++t) {
			int[] cnt = new int[m];
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m; ++j) {
					if (invalid[a[i][j]])
						continue;
					++cnt[a[i][j]];
					break;
				}
			}
			int max = 0;
			for (int i = 0; i < m; ++i) {
				max = Math.max(max, cnt[i]);
			}
			ans = Math.min(ans, max);
			for (int i = 0; i < m; ++i) {
				if (cnt[i] == max) {
					invalid[i] = true;
					break;
				}
			}
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 49792
def receuve_input():
    input_string = str(input())
    return input_string

def judge_steppable(input_string):
    even_strings = [s for i,s in enumerate(input_string) if i % 2 == 1]
    odd_strings = [s for i,s in enumerate(input_string) if i % 2 == 0]

    if 'R' not in even_strings and 'L' not in odd_strings:
         print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    input_string = receuve_input()
    judge_steppable(input_string)

Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
double r, r1, r2;
double r3 = 3.141592653589;
scanf("%lf", &r);
r1 = r * r * r3;
r2 = 2 * r * r3;
printf("%lf %lf", r1, r2);

return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<double,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
struct edge{ll to;double cost;};
int V;
vector<edge> G[200001];
double d[200001],INF=1e18;
int dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost) d[e.to]=d[v]+e.cost,que.push(P(d[e.to],e.to));
        }
    }
}
double dis(double a,double b,double c,double d){
    return sqrt(abs(a-c)*abs(a-c)+abs(b-d)*abs(b-d));
}
int main(){
    int xs,ys,xt,yt,n,X[1001],Y[1001],r[1001];
    cin>>xs>>ys>>xt>>yt>>n;
    rep(i,n) cin>>X[i]>>Y[i]>>r[i];
    rep(i,n)rep(j,n)if(i!=j) G[i+1].push_back({j+1,max(double(0),dis(X[i],Y[i],X[j],Y[j])-r[j]-r[i])}),G[j+1].push_back({i+1,max(double(0),dis(X[i],Y[i],X[j],Y[j])-r[j]-r[i])});
    rep(i,n) G[0].push_back({i+1,max(double(0),dis(xs,ys,X[i],Y[i])-r[i])});
    rep(i,n) G[i+1].push_back({n+1,max(double(0),dis(xt,yt,X[i],Y[i])-r[i])});
    G[0].push_back({n+1,dis(xs,ys,xt,yt)});
    V=n+2;
    dijkstra(0);
    cout<<setprecision(10)<<d[n+1]<<"\n";
}

Measured memory_bytes: 42676
#include <iostream>
#include <cmath>
const int MAX = 1000001;
using namespace std;

bool p[MAX];

void f(){
    for(int i=0 ; i<MAX ; i++){
        p[i] = (i<=1)? false : true ;
    }
    for(int i=2 ; i <= sqrt(MAX)+1 ; i++){
        if( p[i] ){
            for(int j=i*2 ; j<MAX ; j+=i){
                p[j] = false;
            }
        }
    }
}

int main(){
    int n, ans;

    f();
    while( cin >> n , n ){
		ans = 0;
        for(int i=n+1 ; i <= 2*n ; i++ ){
            if( p[i] ){
				ans++;
			}
        }
		cout << ans << endl;
    }
}

Measured memory_bytes: 0
a = [int(_) for _ in input().split()]
if len(a) == 2:
    if (a[0] == 1 and 1 <= a[1] <= 31) or (a[0] == 2 and a[1] ==1):
        print(1)
    elif (a[0] == 2 and 2 <= a[1] <= 28) or (a[0] == 3 and 1 <= a[1] <= 2):
        print(2)
    elif (a[0] == 3 and 3 <= a[1] <= 31) or (a[0] == 4 and 1 <= a[1] <= 3):
        print(3)
    elif (a[0] == 4 and 4 <= a[1] <= 30) or (a[0] == 5 and 1 <= a[1] <= 4):
        print(4)
    elif (a[0] == 5 and 5 <= a[1] <= 31) or (a[0] == 6 and 1 <= a[1] <= 5):
        print(5)
    elif (a[0] == 6 and 6 <= a[1] <= 30) or (a[0] == 7 and 1 <= a[1] <= 6):
        print(6)
    elif (a[0] == 7 and 7 <= a[1] <= 31) or (a[0] == 8 and 1 <= a[1] <= 7):
        print(7)
    elif (a[0] == 8 and 8 <= a[1] <= 31) or (a[0] == 9 and 1 <= a[1] <= 8):
        print(8)
    elif (a[0] == 9 and 9 <= a[1] <= 30) or (a[0] == 10 and 1 <= a[1] <= 9):
        print(9)
    elif (a[0] == 10 and 10 <= a[1] <= 31) or (a[0] == 11 and 1 <= a[1] <= 10):
        print(10)
    elif (a[0] == 11 and 11 <= a[1] <= 30) or (a[0] == 12 and 1 <= a[1] <= 11):
        print(11)
    elif (a[0] == 12 and 12 <= a[1] <= 31):
        print(12)
    else:
        print('hoge!')
else:
    print('hoge!')

Measured memory_bytes: 3192
# AtCoder Beginner Contest 147
# C - HonestOrUnkind2
# https://atcoder.jp/contests/abc147/tasks/abc147_c
import sys
input = sys.stdin.readline
N = int(input())
X = []
for _ in [0]*N:
    A = int(input())
    x = [tuple(map(int, input().split())) for _ in [0]*A]
    X.append(x)

ans = 0
for bit in range(1 << N):
    cnt = 0
    for i in range(N):
        if bit >> i & 1:
            cnt += 1
            for x, y in X[i]:
                if y == 1 and bit >> (x-1) & 1 == 0:
                    break
                if y == 0 and bit >> (x-1) & 1 == 1:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, cnt)

print(ans)


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

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

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

    sort(p.begin(), p.end());

    int sum = 0;
    for (int j = 0; j < K; j++)
    {
        sum += p.at(j);
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string>s(h);
    rep(i,h){
        cin>>s[i];
    }
    rep(i,h){
        rep(j,w){
            int cnt=0;
            if(s[i][j]=='.'){
                for(int x=i-1; x<=i+1; ++x){
                    for(int y=j-1; y<=j+1; ++y){
                        if(x<0||x>=h||y<0||y>=w)continue;
                        if(s[x][y]=='#')cnt++;
                    }
                }
                s[i][j]=cnt+'0';
            }
        }
    }
    rep(i,h){
        cout<<s[i]<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
vector<int>adj [T];
			/*brownsands IIITA*/

void solve()
{	int n,ans=0,ans1=0;

    cin >> n;
    if(n%2!=0)
    {
        cout<<"0";
        return ;
    }
    int x=2;
    while((n/x)!=0)
    {
        ans+=n/x;
       x*=2;
    }
      x=5;
    while((n/x)!=0)
    {
        ans1+=(n/x)/2;
       x*=5;
    }
    cout << ans1; 
   

  
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




Measured memory_bytes: 23680
A = list(map(str, input().split()))

l = []
for n in A:
    ans = 0
    if n.isnumeric():
        l.append(int(n))
    elif n == '+':
        ans = l[-2] + l[-1]
        l[-2] = ans
        l.pop()
    elif n == '-':
        ans = l[-2] - l[-1]
        l[-2] = ans
        l.pop()
    elif n == '*':
        ans = l[-2] * l[-1]
        l[-2] = ans
        l.pop()
        
print(l[0])


Measured memory_bytes: 5600
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] x = new int[n];

		int m = sc.nextInt();
		int q = sc.nextInt();

		int[] a = new int[q];
		int[] b = new int[q];
		int[] c = new int[q];
		int[] d = new int[q];

		for ( int i=0; i<q; i++ ) {
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}

		int g = 0;

		while ( x[0]<m ) {
			nextArray(x, n, m);
			int g1 = 0;
			for ( int i=0; i<q; i++ ) {
				if ( x[b[i]]-x[a[i]]==c[i] ) g1+=d[i];
			}
			g = Math.max(g, g1);
		}
		System.out.println(g);
	}

	private static void nextArray( int[] ary, int sz, int mx) {
		if ( ary[0]==0 ) {
			for ( int i=0; i<sz; i++ ) {
				ary[i]++;
			}
		} else if ( ary[sz-1]<mx ) {
			ary[sz-1]++;
		} else {
			int f = sz-1;
			while ( ary[f]==mx ) {
				f--;
			}
			ary[f]++;
			for ( int i=f+1; i<sz; i++ ) {
				ary[i] = ary[f];
			}
		}
	}
}

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

int main (){
  int S;
  cin >> S;
  cout << S % 2 + (S - S % 2) / 10 % 2 +
    ((S - S % 2) / 10 - (S - S % 2) / 10 % 2) / 10 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
double pie=3.14159265358979;
long long mod=998244353;
//
int main(){
	int ha,ma,hb,mb,k;
	cin>>ha>>ma>>hb>>mb>>k;
	int hoge=hb*60+mb-(ha*60+ma);
	cout<<hoge-k<<endl;
	return 0;
}

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

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define sq(x)           ((x)*(x))
#define pi              acos(-1.0)
#define NUM             1000005

typedef long long ll;


int main()
{
    FastRead

    ll n,a,b;
    
    cin>>n>>a>>b;
    
    if((n==1 and a!=b) || a>b)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << (b-a)*(n-2)+1 << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <sstream>

int main () {
  int x;
  while(1){
    int d,w;
    x=0;
    std::cin>>d>>w;
    if(d==0 and w==0){
      break;
    }
    int y[d][w];
    for(int i=0;i<d;i++){
      for(int j=0;j<w;j++){
	std::cin>>y[i][j];
      }
    }

    for(int i=0;i<d-2;i++){
      for(int j=i+2;j<d;j++){
	for(int k=0;k<w-2;k++){
	  for(int l=k+2;l<w;l++){
	    int min=10,in=0,z=0;
	    for(int m=i;m<j+1;m++){
	      for(int n=k;n<l+1;n++){
		if(m==i or m==j or n==k or n==l){
		  if(y[m][n]<min){
		    min=y[m][n];
		  }
		}
	      }
	    }
	    int max=0;
	    for(int m=i+1;m<j;m++){
	      for(int n=k+1;n<l;n++){
		if(y[m][n]>max){
		  max=y[m][n];
		}
		in+=y[m][n];
		z++;
	      }
	    }
	    int tmp;
	    if(max<min and (tmp=(min*z-in))>x){
	      x=tmp;
	    }
	  }
	}
      }
    }
    std::cout<<x<<"\n";
  }
  return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b;std::cin >> a >> b;
  char A = a + '0', B = b +'0';
  string s = "", t = "";
  re(i, b) s+=A;
  re(i, a) t+=B;
  std::cout << min(s, t) << '\n';
  return 0;
}


Measured memory_bytes: 888
main = do
  [n, m] <- fmap read . words <$> getLine
  lrs <- fmap ((\[l, r] -> Just (read l, read r)) . words) . lines <$> getContents :: IO [Maybe (Int, Int)]
  print  .g $ foldr f (Just (1, n)) lrs

g (Just (l, r)) = abs (l - r) + 1
g Nothing = 0

f Nothing _ = Nothing
f _ Nothing = Nothing
f (Just (l, r)) (Just (l', r'))
  | l' <= r && l <= l' && r <= r' = Just (l', r)
  | l <= r' && l' <= l && r' <= r = Just (l, r')
  | l <= l' && r' <= r = Just (l', r')
  | l' <= l && r <= r' = Just (l, r)
  | otherwise = Nothing


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

using namespace std;

#define ll long long
#define mod 1000000007

void solve(){

    int n; cin >> n;

    cout << (1000 - (n % 1000))%1000;
    
    
    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

    //cout << "Case #" << t << ": ";
    //cout << "\n";

    //inr(10);
	return 0;
}

int inr(int a){
    return ++a;
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

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

const ll inf = 1LL<<60;

map<ll, ll> prime_factor(ll n)
{
  map<ll, ll> res;
  for (ll i=2; i*i<=n; i++) {
    while (n%i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main()
{
  ll n; cin>>n;
  map<ll, ll> mp = prime_factor(n);
  ll ans = 0;
  for (auto v:mp) {
    ll t = v.second;
    ll i = 1;
    while (t >= i) {
      ans++;
      t -= i;
      i++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int p[210001];
int v[200001];
int co[200001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
		p[i]--;
		v[p[i]]=i;
	}
	int ans=0;
	for(int i=0;i<n-1;i++){
		if(v[i]>v[i+1]){
			ans=n-i-1;
			break;
		}
	}
	for(int i=n-2;i>=0;i--){
		co[i]=co[i+1];
		if(v[i]>v[i+1]){
			co[i]=n-i-1;
		}
	}
	for(int i=n-2;i>=0;i--){
		if(v[i]>v[i+1]){
			ans=min(i+1,ans);
			break;
		}
		if(i==0)ans=0;
	}
	int pi=0;
	for(int i=0;i<n-1;i++){
		if(v[i]>v[i+1]){
			pi=i+1;
		}
		ans=min(ans,pi+co[i]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

class Edge{
public:
    int from, to;
    long long cost;
    Edge(): from(0), to(0), cost(0){};
    Edge(int u, int v, long long w): from(u), to(v), cost(w){};
    ~Edge(){};
};

void Warshall_Floyd(std::vector<Edge> &edge, int V,
    std::vector<std::vector<long long> > &d)
{
    int E = edge.size();
    const long long infty = 1e+16;

    // initialize
    for(int i=0; i<V; i++){
        for(int j=0; j<V; j++) d[i][j] = infty;
    }
    for(int i=0; i<E; i++){
        d[edge[i].from][edge[i].to] = edge[i].cost;
    }
    for(int i=0; i<V; i++) d[i][i] = 0;

    // dp
    for(int k=0; k<V; k++){
        for(int i=0; i<V; i++){
            for(int j=0; j<V; j++) d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
        }
    }
}

int main()
{
    int H, W;
    cin >> H >> W;
    Vvec<char> S(H, vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++) cin >> S[i][j];
    }

    vector<Edge> edge;
    for(int i=0; i<H; i++){
        for(int j=0; j<W-1; j++){
            if(S[i][j]=='.' && S[i][j+1]=='.'){
                edge.emplace_back(i*W+j, i*W+j+1, 1);
                edge.emplace_back(i*W+j+1, i*W+j, 1);
            }
        }
    }
    for(int i=0; i<H-1; i++){
        for(int j=0; j<W; j++){
            if(S[i][j]=='.' && S[i+1][j]=='.'){
                edge.emplace_back(i*W+j, (i+1)*W+j, 1);
                edge.emplace_back((i+1)*W+j, i*W+j, 1);
            }
        }
    }

    Vvec<ll> dist(H*W, vector<ll>(H*W));
    Warshall_Floyd(edge, H*W, dist);

    ll ans = 0;
    for(int i=0; i<H*W; i++){
        for(int j=0; j<H*W; j++){
            if(dist[i][j] < 1e9) ans = max(ans, dist[i][j]);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
const double EPS = 1e-8;

double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

vector<P> convex_cut(vector<P> G, L l){
  vector<P> res;
  for(int i=0;i<G.size();i++){
    P A = G[i];
    P B = G[(i+1)%G.size()];
    if(ccw(l.first, l.second, A) != -1) res.push_back(A);
    if(ccw(l.first, l.second, A) * ccw(l.first, l.second, B) < 0)
      res.push_back(crossPoint(L(A,B), l));
  }
  return res;
}

bool check(vector<P> G,double d){
  vector<P> pol=G;
  int n=G.size();
  for(int i=0;i<n;i++){
    P c=(G[(i+1)%n]-G[i]);
    P a=P(abs(c),d)*(c/abs(c))+G[i];
    pol=convex_cut(pol,L(a,a+c));
    if(pol.size()<3)return 0;
  }
  return  1;
}

int main(){
  int n;
  while(cin>>n,n){
    vector<P> pol(n);
    for(int i=0,x,y;i<n;i++)cin>>x>>y,pol[i]=P(x,y);
    
    double L=0,M,R=1e4;
    while(L<R){
      M=(L+R)/2;
      if(!check(pol,M)) R=M-EPS;
      else L=M+EPS;
    }
    printf("%lf\n",L);
  }
  return 0;
}

Measured memory_bytes: 3272
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a,b,h;
    cin>>a>>b>>h;
    cout<<(a+b)*h/2<<endl;
}   



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int g[6][2] = {
  1, 2,
  -1, 3,
  1, -1,
  4, 5,
  5, 2,
  2, 1
};

int main() {
  string s;
  while(cin >> s, s!="#") {
    int a = 0;
    FOR(it, s) {
      int k = *it - '0';
      if (g[a][k] == -1) {
        break;
      }
      a = g[a][k];
    }
    cout << (a == 5 ? "Yes" : "No")  << endl;
  }
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N, M;
  scanf("%lld %lld", &N, &M);

  vector<ll> list[100005];

  for (ll i = 0; i < N; i++) {
    ll a, b;
    scanf("%lld %lld", &a, &b);

    list[a].emplace_back(b);
  }

  priority_queue<ll, vector<ll>, less<ll>> q;

  ll ans = 0;
  for (ll i = 1; i <= M; i++) {
    for (ll j = 0; j < list[i].size(); j++) {
      q.push(list[i][j]);
    }
    if (q.size() > 0) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	ll n, m, a = 0, b = 0;
	cin >> n >> m;
	REP(i, n) {
		ll aa;
		cin >> aa;
		a += aa;
	}
	REP(i, m) {
		ll aa;
		cin >> aa;
		b += aa;
	}
	cout << a * b << endl;
}





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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

ll digit_sum(ll n) {
    ll res = 0;
    while (n != 0) {
        res += n % 10;
        n /= 10;
    }
    return res;
}

bool NG_jugde(ll n, ll m) {
    return (ld) n / (ld) digit_sum(n) > (ld) m / (ld) digit_sum(m);
}

int main() {
    ll k;
    cin >> k;

    set<ll> st;
    ll base = 1;

    rep(i, 15) {

        REP(i, 1, 1000) {
            st.insert(i * base - 1);
        }

        base *= 10;
    }

    vector<ll> ans;
    auto itr = st.begin();

    rep(i, st.size()) {
        if (*itr == 0) {
            itr++;
            continue;
        }
        bool ok = true;
        auto itr2 = itr;
        itr2++;

        REP(j, i + 1, st.size()) {
            if (NG_jugde(*itr, *itr2)) {
                ok = false;
                break;
            }
            itr2++;
        }
        if (ok) ans.push_back(*itr);
        itr++;
    }

    rep(i, k) cout << ans[i] << endl;

    return 0;
}



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

int main(){
	double r, S, L,PI = 3.14159265358979;

	cin >> r;

	S = PI * r * r;
	L = 2 * PI * r;

	printf("%lf %lf\n", S, L);

	return 0;

}


Measured memory_bytes: 3276
import itertools

n = int(input())

l = list(map(int, input().split()))

combi = list(itertools.combinations(l, 3))
cnt = 0

for i in range(len(combi)):
  if combi[i][0] != combi[i][1] != combi[i][2] != combi[i][0] and max(combi[i])*2 < sum(combi[i]):
    cnt +=1

print(cnt)

Measured memory_bytes: 20520
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=3005;

int n,A[MAXN];
vector<int> adj[MAXN];
bool st[MAXN];

void dfs(int u,int fa=0)
{
	st[u]=false;
	A[u]--;
	for(int i=0;i<(int)adj[u].size();i++)
	{
		int v=adj[u][i];
		if(v==fa||A[v]>A[u])
			continue;
		dfs(v,u);
		if(st[v]==false)
		{
			st[u]=true;
			break;
		}
	}
	A[u]++;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&A[i]);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
	{
		dfs(i);
		if(st[i])
			printf("%d ",i);
	}
	puts("");
	
	return 0;
}


Measured memory_bytes: 384
S = list(str(input()))
pre = -1
now = -1
count = 0

for i in range(1,len(S)):
    pre = int(S[i-1])
    now = int(S[i])
    if pre == now and now == 1:
        S[i] = 0
        count += 1
    elif pre == now and now == 0:
        S[i] = 1
        count += 1
                        

print(count)

Measured memory_bytes: 3956
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        _n: usize,
        s: Chars,
    }
    let mut x = 0;
    let mut max = 0;
    for c in s {
        if c == 'I' {
            x += 1;
            if max < x {
                max = x;
            }
        } else {
            x -= 1;
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 2180
#include<iostream>//暴力？
using namespace std;

int main()
{
	long long N, h, n, w;
	long long up, down;
	while (cin >> N)
	{
		w = 0;
		for (h = 1; h <= 3500; h++)
		{
			for (n = 1; n <= 3500; n++)
			{
				up = 4 * h*n - N*h - N*n;
				down = N*h*n;
				if (up > 0 && down%up == 0 && down / up <= 3500)
				{
					w = down / up;
					cout << h << " " << n << " " << w << endl;
				}
				if (w != 0)
				{
					break;
				}
			}
			if (w != 0)
			{
				break;
			}
		}
	}
	return 0;
}

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

#define      ll     long long int

const int N = 100005;

int main()
{
    int n, i, j, k, x, d, t, lt = 0, y, x0, y0, fl = 1;
    cin >> n;
    x0 = 0;
    y0 = 0;
    lt = 0;
    while (n--) {
        cin >> t >> x >> y;
        d = abs(x - x0) + abs(y - y0);
        if ( !(d <= (t - lt) && d % 2 == (t - lt) % 2) ) {
            fl = 0;
        }
        lt = t;
        x0 = x;
        y0 = y;
    }
    if (fl) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 0;
    for (int i = 1; i <= N; i++) {
      ans += i;
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int t = sc.nextInt();
		int[] time = new int[n];
		long sum = 0, tmp;
		time[0] = sc.nextInt();
		for (int i = 1; i < n; i++) {
			time[i] = sc.nextInt();
			if (time[i] - time[i - 1] >= t) {
				sum += t;
			}else {
				sum += time[i] - time[i-1];
			}
		}
		sum = sum + t;
		System.out.println(sum);
	}
}


Measured memory_bytes: 83928
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;
int ADD(int a, int b) { return (a + b) % MOD; }
int SUB(int a, int b) { return (a - b + MOD) % MOD; }

int main() {
    int N, K; cin >> N >> K;
    vector<int> a(N + 1);
    for (int i = 1; i <= N; i++) cin >> a[i];

    vector<vector<int>> dp(N + 1, vector<int>(K + 1, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        vector<int> acc(K + 2, 0);
        for (int j = 0; j <= K; j++) acc[j + 1] = ADD(acc[j], dp[i - 1][j]);
        for (int j = 0; j <= K; j++) {
            dp[i][j] = SUB(acc[j + 1], acc[max(0, j - a[i])]);
        }
    }
    cout << dp[N][K] << endl;
    return 0;
}

Measured memory_bytes: 40192
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  string s;
  cin>>s;
  int n=s.size();
  
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout<<-1<<endl;
    return 0;
  }
  
  map<int,int> mp;
  REP(i,n){
    mp[s[i]-'a']++;
  }
  bool flag=false;
  char target;
  REP(i,26){
    if(mp[i]==0){
      flag = true;
      target = (char)(i+'a');
      break;
    }
  }
  map<int,int> mp2;
  if(flag){
    s += target;
    cout<<s<<endl;
    return 0;
  }
  int index;
  for(int i=n-1;i>=1;i--){
    if(s[i-1]<s[i]){
      index = i-1;
      target = s[i-1];
      break;
    }
  }
  
  char next=target;
  for(int i=index+1;i<n;i++){
    if(s[i]>target){
      next = s[i];
    }
  }
  
  string ans="";
  REP(i,index){
    ans += s[i];
  }
  ans += next;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#define FOR(i,j,n) for(int i=(j);i<=((int)n);++i)
#define N 1000005
#define MOD 1000000007

typedef long long int ll;
using namespace std;
vector <int>g[N];
void init()
{
	for(int i = 0; i < N; i++) {
		g[i].clear();
	}
}
int dp[N]={0};
void dfs(int x,int p)
{
    for (int i=0;i<g[x].size();i++)
    {
        if (g[x][i]==p)
        continue;
        dp[g[x][i]]+=dp[x];
        dfs(g[x][i],x);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin>>n>>q;
    FOR(i,1,n-1)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    FOR(i,1,q)
    {
        int v,x;
        cin>>v>>x;
        dp[v]+=x;
    }
    dfs(1,0);
    FOR(i,1,n)
    cout<<dp[i]<<" ";
    
  



}




Measured memory_bytes: 47232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

int c[2][11], n, k;
void init(int f){
	int s = 0, cnt = 0, nn = n;
	if(f == 1)nn = 7;
	rep(i,nn-2){
		if(c[f][s])break;
		c[f][s]++;cnt++;
		if(f == 0)s = (s+3*3*7)%11;
		if(f == 1)s = (s+3*3)%11;
	}
	int m = (nn-2)%cnt;
	rep(i,11)c[f][i] *= (nn-2)/cnt;
	
	s = 0;
	rep(i,m){
		c[f][s]++;
		if(f == 0)s = (s+3*3*7)%11;
		if(f == 1)s = (s+3*3)%11;
	}
	return;
}

signed main(){
	scanf("%lld%lld", &n, &k);
	rep(i,2)init(i);
	int ans = 0;
	rep(i,11)rep(j,11){
		int tmp = c[0][i]*c[1][j];
		if((i+j+4)%11 == k)ans += tmp;
	}
	printf("%lld\n", ans);
	return 0;
}




Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
m = int(input())
px = [list(map(int, input().split())) for i in range(m)]
sum_t = sum(t)
for i in px:
  key, value = i[0]-1, i[1] 
  ans = sum_t - (t[key]-value)
  print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

const int INF = 0x3f3f3f3f;


int main() {
	IOS;
#ifdef xiaofan
	freopen("in.txt","r",stdin);
#endif

	int n;
	ll sum=0;
	int f=0;
	cin>>n;
	while(n--){
		ll x;
		cin>>x;
		if(x%2==0){
			if(x%3!=0&&x%5!=0)f=1;
		}
	}
	if(!f){
		cout<<"APPROVED"<<endl;
	}else{
		cout<<"DENIED"<<endl;
	}



	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[3010][3010][4];

int main(){
	int R, C, K; scanf("%d %d %d", &R, &C, &K);
	vector<vector<ll> > field(R + 1, vector<ll> (C + 1, 0));
	for(int i = 0; i < K; i++){
		int a, b; ll c; scanf("%d %d %lld", &a, &b, &c);
		field[a][b] = c;
	}
	if(field[1][1]) dp[1][1][1] = field[1][1];
	for(int i = 1; i <= R; i++){
		for(int j = 1; j <= C; j++){
			for(int k = 0; k <= 3; k++){
				if(i != R){
					dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
					if(field[i + 1][j]) dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][k] + field[i + 1][j]);
				}
				if(j != C){
					if(field[i][j + 1] == 0 || k == 3) dp[i][j + 1][k] = max(dp[i][j][k], dp[i][j + 1][k]);
					else{
						dp[i][j + 1][k + 1] = max(dp[i][j][k] + field[i][j + 1], dp[i][j + 1][k + 1]); 
						dp[i][j + 1][k] = max(dp[i][j][k], dp[i][j + 1][k]);
					}
				}
			}
		}
	}
	ll ans = 0;
	for(int i = 0; i <= 3; i++) ans = max(ans, dp[R][C][i]);
	printf("%lld\n", ans);
}

Measured memory_bytes: 355940
def resolve():
    from functools import cmp_to_key
    # aをbの上に配置するとき、W≤sa と W+wa≤sbを満たす必要: W≤min(sa,sb−wa)
    # bをaの上に配置するとき、同様に: W≤min(sb,sa−wb)
    def cmp(a, b):
        va = min(a[1], b[1] - a[0])
        vb = min(b[1], a[1] - b[0])
        if (va == vb): return 0
        return -1 if (va > vb) else 1

    N = int(input())
    # Block[w][s][v]
    Block = [list(map(int, input().split())) for _ in range(N)]
    Block.sort(key=cmp_to_key(cmp))

    max_W = 2*(10**4+1)
    dp = [[0]*(max_W+5) for _ in range(N+1)]
    # dp[i][tot] := i番目までを使って、重さの総和がtotである場合の価値の総和の最大値
    for i in range(N):
        w, s, v = Block[i]
        for tot in range(max_W):
            dp[i+1][tot] = max(dp[i+1][tot], dp[i][tot])
            if tot <= s:
                dp[i + 1][tot+w] = max(dp[i + 1][tot+w], dp[i][tot] + v)

    print(max(dp[N]))


if __name__ == "__main__":
    resolve()

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

using namespace std;

#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define dump(x) cerr << "~ " << #x << " = " << x << endl

int cnt[12];
string s;

int main() {

	fast_cin;
	
	int n;
	cin >> n;

	for(int i = 1; i <= n; i++) {
		
		cin >> s;

		if(s == "AC") {
			cnt[1]++;
		}

		else if(s == "WA") {
			cnt[2]++;
		}

		else if(s == "TLE") {
			cnt[3]++;
		}

		else if(s == "RE") {
			cnt[4]++;
		}
	}
	
	cout << "AC" << " x " << cnt[1] << endl;
	cout << "WA" << " x " << cnt[2] << endl;
	cout << "TLE" << " x " << cnt[3] << endl;
	cout << "RE" << " x " << cnt[4] << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3660
import sys
import itertools

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


n = ni()
s = input()
ct = 0
p = s[0]
for i in range(1, n):
    if p != s[i]:
        ct += 1
        p = s[i]
print(ct+1)




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

int main() {
	int N;
    cin >> N;
    int Alice = 0;
    int Bob = 0;
    vector<int> Card(N);
    for(int i = 0; i < N; i++){
    	cin >> Card.at(i);
    }
    sort(Card.begin(), Card.end());
    reverse(Card.begin(), Card.end());
    for(int i = 0; i < N; i++){
    	if(i % 2 == 0){
        	Alice += Card.at(i);
        }else{
        	Bob += Card.at(i);
        }
    }
    cout << Alice - Bob << endl;
}


Measured memory_bytes: 3612