akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace at_coder
{
#if TEST
    [TestClass]
#endif
    public class Test_157_c
{

        static int INIT_VAL = -1;
        
#if TEST
        public static void Test_Main()
#else
        public static void Main()
#endif
        {
            var ar = ReadIntArray();

            int N = ar[0];
            int M = ar[1];
            int[] data = new int[N];

            for(int i=0;i<N;i++)
            {
                data[i] = INIT_VAL;
            }

            int ngCount = 0;

            for(int i=0;i<M;i++)
            {
                ar = ReadIntArray();
                int ix = ar[0];
                int val = ar[1];

                if (check2(data, ix, val) == false)
                {
                    ngCount++;
                }
                if (check3(data, ix, val) == false)
                {
                    ngCount++;
                }

                if (ngCount == 0)
                {
                    data[ix - 1] = val;
                }
            }

            if (ngCount == 0)
            {
                // 先頭桁が ０ の場合は １ にする
                if (N > 1 && data[0] == INIT_VAL)
                {
                    data[0] = 1;
                }

                // 結果表示
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < data.Length; i++)
                {
                    if (data[i] == INIT_VAL)
                    {
                        data[i] = 0;
                    }
                    sb.Append(data[i].ToString());
                }
                Console.WriteLine(sb.ToString());
            }
            else
            {
                Console.WriteLine("-1");
            }
            
        }

        private static bool check3(int[] data, int ix, int val)
        {
            // すでに同じ桁に同じ数字が設定されていないことのチェック
            if (data[ix - 1] != INIT_VAL)
            {
                if (data[ix - 1] != val)
                {
                    return false;
                }
            }

            return true;
        }
        private static bool check2(int[] data, int ix, int val)
        {
            // 先頭桁が０でないことのチェック
            if (data.Length > 1 && ix == 1 && val == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }


        private static int[] ReadIntArray()
        {
            string[] ss = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int[] ar = new int[ss.Length];
            for (int i = 0; i < ss.Length; i++)
            {
                ar[i] = int.Parse(ss[i]);
            }
            return ar;
        }

#if TEST
#else
    }
}
#endif


Measured memory_bytes: 13140
use std::fmt::Write;
use std::io::Write as IoWrite;

fn main() {
    let n: usize = read();
    let mut vec: Vec<u32> = (0..n).map(|_| { read() }).collect();
    let (cnt, base) = shell_sort(n, &mut vec);
    let mut stdout = std::io::stdout();
    write!(stdout, "{}\n", base.len());
    write!(stdout, "{}\n", join(' ', &base));
    write!(stdout, "{}\n", cnt);
    write!(stdout, "{}\n", join('\n', &vec));
}

fn shell_sort(n: usize, vec: &mut Vec<u32>) -> (u32, Vec<usize>) {
    let group = group(n);
    let cnt = group.iter().fold(0, |cnt, step| { cnt + insertion_sort(n, vec, *step) });
    (cnt, group)
}

fn insertion_sort(n: usize, vec: &mut Vec<u32>, step: usize) -> u32 {
    let mut cnt = 0;
    for i in step..n {
        let mut j = i;
        while j >= step {
            if vec[j - step] > vec[j] {
                let tmp       = vec[j];
                vec[j]        = vec[j - step];
                vec[j - step] = tmp;
                j -= step;
                cnt += 1;
            } else {
                break;
            }
        }
    }
    cnt
}


fn group(n: usize) -> Vec<usize> {
    let mut group: Vec<usize> = vec![1];
    let mut step: usize = 1;
    loop {
        step = step * 3 + 1;
        if step < n {
            group.push(step);
        } else {
            break;
        }
    }
    group.into_iter().rev().collect()
}

fn join<T: std::fmt::Display>(delimiter: char, arr: &[T]) -> String {
    let mut text = String::new();
    for (i, e) in arr.iter().enumerate() {
        if i > 0 {
            text.push(delimiter);
        }
        write!(text, "{}", e).unwrap();
    }
    text
}

fn read<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<T>().ok().unwrap()
}


Measured memory_bytes: 19868
n = gets.chomp.to_i
x = gets.chomp.split(' ').map(&:to_i)

l_i = n / 2 - 1
h_i = n / 2
l,h = [x.sort[l_i], x.sort[h_i]]

x.each do |num|
  if (num <= l)
    puts h
  elsif (h <= num)
    puts l
  end
end

Measured memory_bytes: 25572
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(x);
    string ans = (x == 3 || x == 5 || x == 7)
                 ?"YES"
                 :"NO";
    co(ans);
    return 0;
}

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

B=[]
for i in range(N):
    B.append([A[i],1])

for i in range(M):
    b,c=map(int,input().split())
    B.append([c,b])
B.sort(reverse=True)
#print(B)

ans=0
cnt=0
for i in range(len(B)):
    if cnt+B[i][1]<=N:
        ans+=(B[i][0]*B[i][1])
        cnt+=B[i][1]
    elif cnt+B[i][1]>N:
        ans+=(B[i][0]*(N-cnt))
        print(ans)
        exit()

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

int main(){
    
    int n,a,b,sum;
    int count = 0;
    char* str = new char[8];

    scanf("%d", &n);
    scanf("%d", &a);
    scanf("%d", &b);

    for(int i = 1; i <= n; i++){
        sum = 0;
        //str = to_string(i);
        sprintf(str, "%d", i);
        for(int j = 0;j < strlen(str);j++){
            sum+= (int)(str[j] - '0');
        }
        if(a <= sum && sum <= b){
            count+=i;
        }

    }

    printf("%d", count);
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return int64(a)
}

func scanFloat() float64 {
	sc.Scan()
	a, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		fmt.Println(err)
	}
	return a
}

func scanTextSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = scanText()
	}
	return a
}

func scanSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanFloatSlice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = scanFloat()
	}
	return a
}

func scanInt64Slice(n int64) []int64 {
	a := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = scanInt64()
	}
	return a
}

// var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	input := scanSlice(2)
	n := input[0]
	m := input[1]

	memo := make(map[int][]int)

	for i := 1; i <= n; i++ {
		memo[i] = make([]int, 2)
	}

	for i := 0; i < m; i++ {
		tmp := scanTextSlice(2)
		p, _ := strconv.Atoi(tmp[0])
		s := tmp[1]

		mm := memo[p]
		memoAC := mm[0]
		// memoPenalty := mm[1]

		if memoAC > 0 {
			continue
		} else if memoAC <= 0 && s == "WA" {
			memo[p][1] = memo[p][1] + 1
		} else if memoAC <= 0 && s == "AC" {
			memo[p][0] = 1
		}
	}

	ansAC := 0
	ansWA := 0
	for _, val := range memo {
		ac := val[0]
		penalty := val[1]
		if ac > 0 {
			ansAC++
			ansWA += penalty

		}
	}

	fmt.Println(ansAC, ansWA)

}

func binarySearch(arr []int, number int) int {

	l := -1
	r := len(arr)
	index := 0
	for {
		mid := l + (r-l)/2
		tmp := arr[mid]

		if r-l <= 1 || tmp == number {
			index = mid
			break
		} else if tmp < number {
			l = mid
		} else {
			r = mid
		}
	}
	return index
}

func factorial(n int) int64 {
	sum := int64(1)
	for i := 2; i <= n; i++ {
		sum *= int64(i)
	}
	return sum
}

func deleteNumOfArray(arr []int, position int) []int {
	left := arr[:position]
	r := arr[position+1:]
	appendArr := append(left, r...)
	return appendArr
}


Measured memory_bytes: 13332
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define po pop_back
#define fi first
#define se second
#define mxn 200001
#define ll long long int
#define ldb long double
#define endl "\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

using namespace std;

typedef pair<ll,ll> pp;
typedef vector<ll> vi;

void solve(ll test){


    ll n;
    cin >> n;
    map<ll,ll> mp;
    ll sum = 0;
    for(ll i=0  ; i<n ; i++){
        ll x;
        cin >> x;
        sum += x;
        mp[x]++;
    }


    ll q;
    cin >> q;
    while(q--){
        ll x,y;
        cin >> x >> y;
        sum = sum + (y-x)*mp[x];
        mp[y] += mp[x];
        mp[x] = 0;
        cout << sum<< endl;
    }

}

int main(){

    fast;
    int t=1;
    // cin >> t;
    for(int i=1 ; i<=t ; i++){
        solve(i);
        // cout << endl;
    }
    return 0;
}


Measured memory_bytes: 9424
from itertools import permutations

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)

ans = 0
for p in permutations(range(1, N)):
    v = 0
    flag = True
    for nv in p:
        if nv not in G[v]:
            flag = False
            break
        v = nv
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main(){

    int count[26];
    int h, w;

    cin >> h >> w;

    for(int i = 0; i < 26; i++)
    {
        count[i] = 0;
    }
    
    for(int i = 0; i < h; i++)
    {
        string line;
        cin >> line;

        for(int j = 0; j < w; j++)
        {
            count[line[j] -'a']++;
        }
    }
    
    int four, two, one;
    four = 0;
    two = 0;
    one = 0;

    for(int i = 0; i < 26; i++){

        four += count[i] / 4;

        if(count[i] % 4 == 2){
            two++;
        }
        else if(count[i] % 4 == 1){
            one++;
        }
        else if(count[i] % 4 == 3){
            two++;
            one++;
        }
    }

    if(h % 2 == 0 && w % 2 == 0){
        if(four > 0 && two == 0 && one == 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if(h % 2 == 1 && w % 2 == 0){
        int alpha = two + 2 * (four - (h - 1) * w / 4);
        if(four >= (h - 1) * w / 4 && alpha == w / 2 && one == 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if(h % 2 == 0 && w % 2 == 1){
        int alpha = two + 2 * (four - h * (w - 1) / 4);
        if(four >= h * (w - 1) / 4 && alpha == h / 2 && one == 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{

        int alpha = two + 2 * (four - (w - 1) * (h - 1) / 4);
        if(four >= (w - 1) * (h - 1) / 4 && alpha == ((w - 1) + (h - 1)) / 2 && one == 1){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<unordered_map>

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

const ll MAX = 1e6;

long long fac[MAX], finv[MAX], inv[MAX];
 
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//binary_libraryを貼る

ll H(ll a, ll b){
  return COM( a + b - 1, b - 1);}

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

 unordered_map<ll,ll> power;  power.clear();
    ll c = sqrt((double) M); ll k = M;
    for(ll j = 2; j <= c ; j++){ //Mの素因数分解
      while( k % j == 0){ k /= j; power[j]++;}}
    if( k != 1){ power[k]++;}
    
    ll ans = 1;
     for( auto p : power){
       if(p.second != 0){
        ans *= H(p.second,N); ans %= MOD;}
      } //map全探索を行う
    
    cout << ans << endl; return 0;}
      
  

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
int flag[1000005],a[10005],sum;
int main()
{
	int n;
	scanf("%d",&n);
	memset(flag,true,sizeof(flag));
	flag[1]=false;
	sum=0;
	for(int i=2;i<=55555;i++)
		if(flag[i])
		{
			a[++sum]=i;
			for(int j=2;j<=55555/i;j++)
				flag[i*j]=false;
		}
	int cnt=0;
	for(int i=1;i<=sum;i++)
		if(a[i]%5==2)
		{
			cout<<a[i]<<" ";
			cnt++;
			if(cnt==n)break;
		}
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e9;

int main(){
    int N,K; cin>>N>>K;
    int ans=0;
    for(int i=0;i<N;i++){
        int x; cin>>x;
        if(x>=K) ans++;
    }
    cout<<ans<<endl;

}



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

public class Main {

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

        int[] p = new int[3];

        for (int i = 0; i < 3; i++) {
            p[i] = sc.nextInt();
        }

        Arrays.sort(p);

        int sum = 0;

        sum += p[0];
        sum += p[1];

        System.out.println(sum);

        sc.close();
        ;
    }
}

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

int N, M;
int l[100005], r[100005];

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> l[i] >> r[i];
    }

    int ans = 0;
    sort(l, l+M); sort(r, r+M);
    if (l[M-1] <= r[0]) ans = r[0]-l[M-1]+1;

    cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int S = int.Parse(Console.ReadLine());
		int a = S / 3600;
		int b = (S / 60) % 60;
		int c = S % 60;
		Console.WriteLine(a+":"+b+":"+c);
	}
}


Measured memory_bytes: 9224
n=int(input())
ans=''
check='abcdefghijklmnopqrstuvwxyz' #c(a)-1=0,c(b)-1=1,…,c(z)-1=25を対応づける文字列
while n!=0:
 n-=1
 ans+=check[n%26] #(n-1)%26がc(Sk)-1を表すので、上記の文字列を用いてc(Sk)-1からSkを求める
 n//=26
print(ans[::-1])

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007

int main(){
  string s;
  cin>>s;
  vector<vector<int>> index(26);
  for(int i=0;i<26;i++){
    index.at(i).push_back(-1);
  }
  int n=s.size();
  for(int i=0;i<n;i++){
    int x=s.at(i)-'a';
    index.at(x).push_back(i);
  }
  for(int i=0;i<26;i++){
    index.at(i).push_back(n);
  }

  int ans=1000000;
  for(int i=0;i<26;i++){
    int sub=0;
    for(int j=1;j<index.at(i).size();j++){
      sub=max(sub,index.at(i).at(j)-index.at(i).at(j-1)-1);
    }
    ans=min(sub,ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
// Problem : B - Go to Jail
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/******Old_school_@163******/
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma") 
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back 
#define mp                make_pair
#define F                 first
#define S                 second
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()) 
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
#define bye               fflush(stdout)

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){ 
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){ 
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
      lld t=1; cin>>t;  
      bool fg=false;  lld ct=0;
      while(t--){
          lld x;lld y; cin>>x>>y;
          if(x==y)  ct++;
          else  ct=0;
          if(ct>=3)  fg=true;
      }
      if(fg)  cout<<"Yes";
      else  cout<<"No";
}



Measured memory_bytes: 3636
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

def solve():
    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [0] * (numPow2+1)
        return data, numPow2
    def setInit(As):
        for iB, A in enumerate(As, 1):
            data[iB] = A
        for iB in range(1, numPow2):
            i = iB + (iB & -iB)
            data[iB] -= data[i]
    def addValue(iA, A):
        iB = iA + 1
        while iB > 0:
            data[iB] += A
            iB -= iB & -iB
    def getValue(iA):
        iB = iA + 1
        ans = 0
        while iB <= numPow2:
            ans += data[iB]
            iB += iB & -iB
        return ans


    N, D, A = map(int, input().split())
    XHs = [tuple(map(int, input().split())) for _ in range(N)]

    XHs.sort()
    Xs, Hs = [], []
    for X, H in XHs:
        Xs.append(X)
        Hs.append(H)

    data, numPow2 = makeBIT(N)
    setInit(Hs)

    ans = 0
    for i in range(N):
        rest = getValue(i)
        if rest <= 0: continue
        pos = Xs[i] + D
        iR = bisect_right(Xs, pos + D) - 1
        num = -(-rest // A)
        ans += num
        damage = num*A
        addValue(iR, -damage)

    print(ans)


solve()


Measured memory_bytes: 49352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 int N = sc.nextInt();
		 boolean flg = false;
		 for(int i = 1; i < 10; i++) {
			 for(int j = 1; j < 10; j++) {
				 if(N == i*j) {
					 flg = true;
					 break;
				 }
			 }
		 }
		 if(flg) {
			 System.out.println("Yes");
		 }else {
			 System.out.println("No");
		 }
	}

}


Measured memory_bytes: 35840
import sys

sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()
p = LIST()

fail = 0

for i, pi in enumerate(p):
    if pi != i + 1:
        fail += 1

if fail in [0, 2]:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll z = *x;
  *x = *y;
  *y = z;
}
void print(vector<ll> vec){
  ll length = (ll)vec.size();
  rep(i,length){
    if(i != 0){cout << " ";}
    cout << vec[i];
  }
  cout << endl;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> vec(n);
  vector<ll> ans(n);
  rep(i,n){
    cin >> vec[i];
  }
  rep(i,n){
    ans[vec[i]-1] = i + 1;
  }
  rep(i,n){
    cout << ans[i] << " ";
  }
}

Measured memory_bytes: 2432
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int a,b,x;
  cin >> a >> b >> x;

  if (a > x) {
    cout << "NO" << endl;
    return 0;
  }

  int buf = x - a;
  if (b >= buf) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int
#define Vec vector
template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int N,Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	
	Vec<int> ac(N);
	for(int i=1;i<N;i++) if(S[i-1] == 'A' && S[i] == 'C') ac[i] = 1;
	Vec<int> sum(N+1);
	for(int i=0;i<N;i++) sum[i + 1] = sum[i] + ac[i];
	for(int i=0;i<Q;i++){
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << sum[r + 1] - sum[l + 1] << endl;
		
	}
	
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  int ans=0;
  while(true) {
    bool exit = false;
  	for(int i=0; i<n; i++) {
      if(a[i] % 2 != 0) exit = true;  
    }
    if(exit) break;
    for(int i=0; i<n; i++) {
      a[i] /= 2;
    }
  ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
    int n; cin >> n;
    int ar[n];
    int count = 0;
    for(int  i = 0; i < n; ++i){
        cin >> ar[i];
    }
    for(int  i = 1; i < n-1; ++i){
        if(ar[i]>ar[i+1] && ar[i]>ar[i-1] || ar[i]<ar[i+1] && ar[i]<ar[i-1]){
            continue;
        }else count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long v = sc.nextLong();
    long b = sc.nextLong();
    long w = sc.nextLong();
    long t = sc.nextLong();
    long i = Math.abs(b-a);
    long j = (v-w) * t;
    if (i <= j){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 35576
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long Int;
#define REP(i,n) for(int i=0;i<(int)n;++i)

long long table[] = {
1ll
,2ll
,4ll
,6ll
,12ll
,24ll
,36ll
,48ll
,60ll
,120ll
,180ll
,240ll
,360ll
,720ll
,840ll
,1260ll
,1680ll
,2520ll
,5040ll
,10080ll
,15120ll
,25200ll
,27720ll
,55440ll
,110880ll
,166320ll
,277200ll
,332640ll
,554400ll
,665280ll
,720720ll
,1441440ll
,2162160ll
,3603600ll
,4324320ll
,7207200ll
,8648640ll
,10810800ll
,21621600ll
,36756720ll
,61261200ll
,73513440ll
,122522400ll
,147026880ll
,183783600ll
,367567200ll
,698377680ll
,735134400ll
,1102701600ll
,1163962800ll
,1396755360ll
,2327925600ll
,2793510720ll
,3491888400ll
,6983776800ll
,13967553600ll
,20951330400ll
,27935107200ll
,41902660800ll
,48886437600ll
,80313433200ll
,160626866400ll
,321253732800ll
,481880599200ll
,642507465600ll
,963761198400ll
,1124388064800ll
,1927522396800ll
,2248776129600ll
,3373164194400ll
,4497552259200ll
,4658179125600ll
,6746328388800ll
,9316358251200ll
,13974537376800ll
,18632716502400ll
,27949074753600ll
,32607253879200ll
,55898149507200ll
,65214507758400ll
,97821761637600ll
,130429015516800ll
,144403552893600ll
,195643523275200ll
,288807105787200ll
,433210658680800ll
,577614211574400ll
,866421317361600ll
,1010824870255200ll
,1732842634723200ll
,2021649740510400ll
,3032474610765600ll
,4043299481020800ll
};


long long divisor(long long n){
	long long i = 1 , sum = 0;
	for(; i*i < n ; i++) if(n%i == 0) sum += i + n/i;
	if(i*i == n) sum += i;
	return sum;
}

int main(){
	long long n;
	while(cin >> n && n){
		double mx = 0;
		for(int i = 0 ; i < sizeof(table) / sizeof(table[0]) ; i++){
			if(table[i] <= n)mx = max(mx,1.0*divisor(table[i]) / table[i]);
		}
		printf("%.6lf\n",mx);
	}
}

Measured memory_bytes: 908
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "PP.hpp"
#define deb(x...) cerr << "[" << #x << "] = " << x << "\n";
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b, c;
	cin >> a >> b >> c;
	for1(i, 3){
		if((a * b * i ) % 2){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}



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

class Program
{
    static void Main()
    {
        String[] arr = Console.ReadLine().Split();
        long A, B, K;
        A = long.Parse(arr[0]);
        B = long.Parse(arr[1]);
        K = long.Parse(arr[2]);
        Console.WriteLine((A - Math.Min(A, K)).ToString()
            + " "
            + (B - Math.Min(B, K - Math.Min(A, K))).ToString());
        return;
    }
}

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

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

  char n = s[6];
  if(s[5] == '0') {
  if(n == '1' || n == '2' || n == '3' || n == '4') cout << "Heisei";
  else cout << "TBD";
}else {
   cout << "TBD";
 }
}


Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let hp = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun h p -> h, p)) in
    Array.sort (fun (h1, p1) (h2, p2) -> compare (h1 + p1, h1) (h2 + p2, h2)) hp;

    let rec loop i dp =
        if i = n then dp else (
            let h, p = hp.(i) in
            let dp2 = Array.copy dp in
            for j = 1 to n do
                if dp.(j - 1) <= h then dp2.(j) <- min dp.(j) (dp.(j - 1) + p)
            done;
            loop (i + 1) dp2
        )
    in
    let init = Array.make (n + 1) max_int in
    init.(0) <- 0;
    let dp = loop 0 init in

    let rec loop i =
        if i = n + 1 || dp.(i) = max_int then i - 1 else loop (i + 1)
    in
    loop 0 |> Printf.printf "%d\n"
)

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    string S;
    cin >> S;
    if(S == "Sunny") { printf("Cloudy\n"); }
    else if(S == "Cloudy") { printf("Rainy\n"); }
    else { printf("Sunny\n"); }


    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(A <= B && B <= C && C <= D) { Console.WriteLine(0); return; }
		if(A <= C && C <= B && B <= D) { Console.WriteLine(B - C); return; }
		if(A <= C && C <= D && D <= B) { Console.WriteLine(D - C); return; }
		if(C <= A && A <= B && B <= D) { Console.WriteLine(B - A); return; }
		if(C <= A && A <= D && D <= B) { Console.WriteLine(D - A); return; }
		if(C <= D && D <= A && A <= B) { Console.WriteLine(0); return; }
		
	}
	int A,B,C,D;
	public Sol(){
		var d = ria();
		A = d[0]; B = d[1]; C = d[2]; D = d[3];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int H,W; cin>>H>>W;
  map<char,char> M;
  rep(i,0,H){
    string S; cin>>S;
    rep(j,0,W) M[S[j]]++;
  }
  int sum1=0,sum2=0;
  for(auto p:M){
    int X=p.second;
    if(X%4==0) continue;
    else if(X%2==0) sum1++;
    else{
      sum2++;
      X--;
      //if(X%4==2) sum1++;
    }
  }
  int max1=0,max2=0;
  if(H%2==1) max1+=W/2;
  if(W%2==1) max1+=H/2;
  if(H%2==1&&W%2==1) max2++;
  string ans="No";
  if(max2>=sum2&&max1>=sum1) ans="Yes";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
from collections import Counter

N = int(input())
V = list(map(int,input().split()))

even = Counter(V[1::2]).most_common() + [(0, 0)]
odd = Counter(V[::2]).most_common() + [(0, 0)]

if even[0][0] != odd[0][0]:
  print(N-even[0][1]-odd[0][1])
else:
  print(min(N-even[0][1]-odd[1][1], N-even[1][1]-odd[0][1]))


Measured memory_bytes: 20572
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
int main(){
//	ios::sync_with_stdio(false);
//	ifstream cin("data.txt");
//	freopen("data.txt", "r", stdin);
	int a, b;
	cin >> a >> b;
	cout << a + b/2 << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	fsc := NewFastScanner()
	var result string
	result = ""
	for i := 0; i < 3; i++ {
		T := fsc.Next()
		result += string(T[0])
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define P push
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    FAST();
    ll int n,m,res;
    cin>>n>>m;
    VEC(n);
    for(int i=m;i<n;i++)
    {
        if(v[i-m]>=v[i])cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }


}



Measured memory_bytes: 5328
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <time.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>

#include <chrono>

#define INF 1e9
#define LL_INF 1e18

#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD 1000000007
#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

typedef long long int ll;

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

#define nmax 200010

int n;
int h[nmax], dp[nmax];

int main()
{
    scanf("%d", &n);

    for (int i = 1; i <= n; i++) scanf("%d", &h[i]);

    for (int i = 0; i <= n; i++) dp[i] = INF;

    dp[1] = 0;

    for (int i = 2; i <= n; i++) {

        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        
        if (i > 2) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    printf("%d", dp[n]);

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B,C,D;

    cin >> A >> B >> C >> D;

    for(int i=1; ;i++){
        if(C-B*i<=0){
            cout << "Yes" << endl;
            break;
        }else if(A-D*i<=0){
            cout << "No" << endl;
            break;
        }
    }

}

Measured memory_bytes: 3564
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

int main() {
	ll a, b; cin >> a >> b;
	cout << 100 << " " << 100 << endl;

	a--; b--;
	rep(i, 0, 100) {
		if (i < 50) {
			rep(j, 0, 100) {
				if (i & 1 && j & 1) {
					if (b-- > 0)cout << '#';
					else cout << '.';
				}
				else cout << '.';
			}
		}
		else {
			rep(j, 0, 100) {
				if (i & 1 && j & 1) {
					if (a-- > 0)cout << '.';
					else cout << '#';
				}
				else cout << '#';
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 int abs2(int A){
     int a;
     if(A>=0){a=A;}else{a=-A;}
     return a;
}
int min(int n,int x[]){
    int y,i=0,j=0;
    y=x[0];
    while(i<n){
        if(x[i]<y){
            y=x[i];
            j=i;
        }
        i++;
    }
    return j+1;
}
 
int main(void){
    int N,T,A,h,d;
    scanf("%d%d%d",&N,&T,&A);
    int H[N];
    for(int i=0;i<N;i++){
        scanf("%d",&H[i]);
    }
    for(int i=0;i<N;i++){
        d=H[i]*6;
        H[i]=abs2(1000*A-1000*T+d);
    }
    printf("%d\n",min(N,H));
	return 0;
}

Measured memory_bytes: 128
using System;

namespace AOJ {
    class ALDS1_1_B {
        static void Main(string[] args) {
            int a, b;
            string[] input = Console.ReadLine().Split();
            a = int.Parse(input[0]);
            b = int.Parse(input[1]);
            Console.WriteLine(Gcd(a, b));
        }

        static int Gcd(int a, int b) {
            int r = 0;
            if (a < b) {
                int tmp = a;
                a = b;
                b = tmp;
            }
            while (b > 0) {
                r = a % b;
                a = b;
                b = r;
            }
            return a;
        }
    }
}



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

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

#define endl '\n'
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define int long long
#define pb push_back
#define f(i,l,r) for(ll i=l;i<=r;i++)
#define rf(i,r,l) for(ll i=r;i>=l;i--)
#define Max 5000001
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define d0(a) cout<<a<<' ';
#define d1(a) cout<<a<<endl;
#define d2(a,b) cout<<a<<' '<<b<<endl;
#define d3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define d4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
#define d5(a,b,c,d,e) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<endl;
#define d6(a,b,c,d,e,f) cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<e<<' '<<f<<endl;

const ll N=1e5+5,mod=1e9+7,bit=61;






signed main()
{
    fast;

    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll h1,m1,h2,m2,k;
        cin>>h1>>m1>>h2>>m2>>k;
        ll t1=h1*60+m1;
        ll t2=h2*60+m2;
        ll du=t2-t1;
        cout<<max(0ll,du-k)<<endl;
    }
    return 0;
}


















Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

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

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string x,y;
    cin >> x >> y;

    int m,n;
    m = x.length();
    n = y.length();

    vector< vector<int> > mat(m+1, vector<int>(n+1,0));

    for (int sum = 2; sum <= m+n; sum++) {
      for (int j = 1; j < sum; j++) {
        int k = sum - j;
        if (k <= 0 || k > n || j > m) continue;

        int plus = x[j-1] == y[k-1] ? 1 : 0;
        mat[j][k] = max(max(mat[j-1][k], mat[j][k-1]), mat[j-1][k-1] + plus);
      }
    }

    cout << mat[m][n] << eol;
  }
  
  return 0;
}

Measured memory_bytes: 6888
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;
}


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

const int mod = 1'000'000'007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

bool fi[1001][1001];
mint  dp[2][1001];

int main() {
  int h, w;
  cin >> h >> w;
  string s;
  rep(i, h) {
    cin >> s;
    rep(j, w) if (s.compare(j, 1, ".") == 0)
      fi[i][j] = false; else fi[i][j] = true;
  }
  rep(i, h) fi[i][w] = true;
  rep(i, w-1) fi[h][i] = true; fi[h][w-1] = false;
//  rep(i, h+1) {rep(j, w+1) cout << fi[i][j]; cout << endl;}
  rep(i, w+1) dp[0][i] = 1;
  
  int odd = (h-1) % 2;
  int j, k;
  for (int i=h-1; i >= 0; i--) {
    j = (i + 1 + odd) % 2; k = (i + odd) % 2;
    for (int l=w-1; l >= 0; l--) {
      mint d = 0;
      if (fi[i][l] == true) dp[j][l] = d;
      else {
        if (fi[i+1][l] == false) d += dp[k][l];
        if (fi[i][l+1] == false) d += dp[j][l+1];
        dp[j][l] = d;
      }
    }
//    rep(m, w) cout << dp[j][m]; cout << endl;
  }
  cout << dp[(odd+1)%2][0].x << endl;
}


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

#define int long long int

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

    int a, b, k;
    cin >> a >> b >> k;
    int cur = min(a, k);
    k -= cur;
    cout << a - cur << " " << max(b - k, 0LL) << "\n";

    return 0;
}


Measured memory_bytes: 768
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mk make_pair
#define fast                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define rep(i, a, b) for (ll i = a; i < b; i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x) (int)x.size()
#define mem(a, val) memset(a, val, sizeof(a))
#define deci(x) cout << fixed << setprecision(x);
#define bitcount(x) __builtin_popcountll(x)

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

const long long int mod = 1e9 + 7;
const long double EPS = 1e-12;
const int N = 1e5 + 20;

void solve() {
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> v(n);
  rep(i, 0, n) cin >> v[i];
  sort(rall(v));
  ans = v[0];
  int i = 1;
  while ((n - i - 1) > (i + 1)) {
    ans += v[i];
    i++;
  }
  int rem = (n - i - 1);
  for (int j = 0; j < rem; j++) {
    ans += min(v[j % (i + 1)], v[(j + 1) % (i + 1)]);
  }
  cout << ans;
}
int main() {
  fast;
  ll t;
  t = 1;

  // cin>>t;

  while (t--) {
    solve();
  }

  return 0;
}


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

using namespace std;

const int N = 1e5+20;

int vis[N];
int sg[N];
int a[N];
int n,k;

int mex(int x)
{
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
		if(x-a[i]>=0)	vis[sg[x-a[i]]]=1;
	}
	for(int i=0;i<=N;i++)
	if(vis[i]==0) return i;	
}


int main()
{
	
	cin>>n>>k;
	for(int i=1;i<=n;i++)	cin>>a[i];
	for(int i=0;i<=N;i++)	sg[i]=mex(i);
	if(sg[k]) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
		
	
}

Measured memory_bytes: 1152
N,M=map(int,input().split())
H=list(map(int,input().split()))
cnt=[1 for _ in range(N)]
for _ in range(M):
    A,B=map(int,input().split())
    A-=1
    B-=1
    if H[A]>H[B]:
        cnt[B]=0
    elif H[A]<H[B]:
        cnt[A]=0
    else:
        cnt[A]=0
        cnt[B]=0
print(cnt.count(1))


Measured memory_bytes: 19884
n = int(input())
li = [int(input()) for _ in range(n)]

i = 0
button = 0
while i <= n:
  i += 1
  button = li[button]-1
  
  if button == 1:
    break
  
  


if button == 1:
  print(i)
else:
  print(-1)


Measured memory_bytes: 7084
def dist(X1, X2):
    return sum((x1 - x2)**2 for x1, x2 in zip(X1, X2))

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

sq = set(i**2 for i in range(10**5))

ans = 0
for i in range(N):
    for j in range(i):
        if dist(X[i], X[j]) in sq:
            ans += 1

print(ans)

Measured memory_bytes: 51696