akhauriyash/Code-Regression huggingface dataset:
import collections
class KMP():
    def __init__(self, pattern):
        self.pattern = pattern
        self.n = len(pattern)
        self.create_k_table()
    
    def create_k_table(self):
        ktable = [-1]*(self.n+1)
        j = -1
        for i in range(self.n):
            while j >= 0 and self.pattern[i] != self.pattern[j]:
                j = ktable[j]
            j += 1
            if i+1 < self.n and self.pattern[i+1] == self.pattern[j]:
                ktable[i+1] = ktable[j]
            else:
                ktable[i+1] = j
        self.ktable = ktable

    def match(self,s):
        n = len(s)
        j = 0
        ret = [0]*n
        for i in range(n):
            while j >= 0 and (j == self.n or s[i] != self.pattern[j]):
                j = self.ktable[j]
            j += 1
            if j == self.n:
                ret[(i-self.n+1)%n] = 1 
        return ret

def main():
    s = input()
    t = input()
    n = len(s)
    m = len(t)
    while len(s) < m + n:
        s += s
    a = KMP(t)
    b = a.match(s)
    edges = [[] for i in range(n)]
    indegree = [0] * n
    for i in range(n):
        k = (i+m)%n
        if b[i]:
            edges[i].append(k)
            indegree[k] += 1
    
    def topSort():
        q = collections.deque([i for i in range(n) if indegree[i] == 0])
        while q:
            cur = q.popleft()
            res.append(cur)
            for nei in edges[cur]:
                indegree[nei] -= 1
                if indegree[nei] == 0:
                    q.append(nei)
        return len(res) == n
    
    res = []
    dp = [0] * n
    flag = topSort()
    if flag:
        for k in range(n):
            i = res[k]
            for j in edges[i]:
                dp[j] = max(dp[j], dp[i] + 1)
        ans = max(dp)
    else:
        ans = -1
    return ans
     

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 142828
#include <bits/stdc++.h>
using namespace std;
int main(){

  //input
  int H,W,K;
  cin >> H >> W >> K;
  char A[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> A[i][j];
    }
  }
  
  
  //setup
  int lpnum = 1<<(H+W);
  int Total = 0;
  for(int i=0;i<lpnum;i++){
    int count=0;
    for(int j=0;j<H*W;j++){
      if(A[j/W][j%W]=='#'){
        if((i>>(W+(j/W)))&1&(i>>(j%W))){
          count++;
        }
      }
    }
    //cout << bknum << endl;
    if(count==K){
      Total++;
    }
  }
  
  //output
  cout << Total << endl;

}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    int n;
    cin >> n;
    int p[n];
    rep(i,n) cin >> p[i];

    int ans = 0;

    for (int i = 1; i < n - 1; i++) {
        if (p[i - 1] < p[i] && p[i] < p[i + 1] || p[i - 1] > p[i] && p[i] > p[i + 1]) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define imod(a , n) (a % n + n ) % n ;
#define int long long
const double eps = 1e-9 , PI = acos(-1) ;
const int N = 1e3 + 3 , oo = 1e9 , M = 30;
vector<int>vis(1e6 + 6 );

int32_t main(){
    int n  , ans = 0;
    cin >> n ;
    vector<int>v(n);
    map<int , int > m ;
    for(auto &it : v){
        cin >> it ;
        m[it]++;}
    sort(v.begin() , v.end());

    for(auto a : v){

        if(!vis[a]){
             //   debug(a);
           if(m[a] == 1) ans ++ ;
            for(int x = a ; x <= 1e6+6 ; x += a)vis[x]++;
        }
    }
    cout << ans ;

    return 0;
}


Measured memory_bytes: 24988
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

    double a, b, c;
    std::cin >> a >> b >> c;
    c *= M_PI/180;
    std::cout << std::fixed << std::setprecision(6) << a*b*std::sin(c)/2 << "\n";
    std::cout << std::fixed << std::setprecision(6) << a+b+std::sqrt(a*a+b*b-2*a*b*std::cos(c)) << "\n";
    std::cout << std::fixed << std::setprecision(6) << b*std::sin(c) << "\n";
    return 0;
}

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

typedef long long ll;

int main()
{
    int N, M, tmp, ans = 0;
    cin >> N >> M;
    vector <int> k(M), p, s[M];
    for (int i = 0; i < M; i++) {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++) {
            cin >> tmp;
            s[i].push_back(tmp);
        }
    }
    for (int i = 0; i < M; i++) {
        cin >> tmp;
        p.push_back(tmp);
    }


    for (int bit = 0; bit < (1<<N); bit++) {
        bool x = true;
        for (int i = 0; i < M; i++) {
            int cnt = 0;
            for (int j = 0; j < k[i]; j++) {
                if (bit & 1<<(s[i][j]-1)) cnt++;
            }
            //cout << cnt << endl;
            if (cnt%2 != p[i]) x = false;
        }
        if (x) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    n: usize,
    xl: [(i32, i32);n]
  };

  // let mut xl = xl;
  // xl.sort_by_cached_key(|t| t.0 + t.1); // -> 32ms
  // xl.sort_by_key(|t| t.0 + t.1);        // -> 36ms
  // xl.sort_unstable_by_key(|t| t.0 + t.1);  // -> 28ms ただし最長ケースが異なる。
  // let mut idx = std::i64::MIN;
  // let mut ans = 0;
  // for (x, l) in xl {
  //   if idx <= x - l {
  //     idx = x+l;
  //     ans += 1;
  //   }
  // }
  let mut xl = xl.iter().map(|t| (t.0+t.1, t.0-t.1)).collect::<Vec<(i32, i32)>>();
  xl.sort_unstable_by_key(|t| t.0);
  let mut idx = std::i32::MIN;
  let mut ans = 0;
  for (end, start) in xl {
    if idx <= start {
      idx = end;
      ans += 1;
    }
  }
  echo!(ans);
}


Measured memory_bytes: 5440
import sys
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
import collections
c = collections.Counter(A)
li = list(c.values())
li.sort()
li.reverse()
ans = 0
for i in range(K,len(li)) :
    ans += li[i]
print(ans)

Measured memory_bytes: 34036
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

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

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


public class MathLib
{
    /// <summary>
    /// 最大公約数を求める
    /// </summary>
    public static long Gcd(long a, long b)
    {
        return (a < b) ? Gcd(b, a)
             : (b > 0) ? Gcd(b, a % b)
                       : a;
    }

    /// <summary>
    /// 最小公倍数を求める
    /// </summary>
    public static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }
}

class Program
{
    static int N;
    static int[] A;

    public static void Main(string[] args)
    {
        MainModule(Console.In);
    }

    public static void MainModule(TextReader In)
    {
        {
            var lin = In.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
            N = lin[0];
        }
        A = In.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();

        int prev = A[0];
        for (int i = 1; i < N; i++)
        {
            prev = (int)MathLib.Gcd(prev, A[i]);
        }

        Console.WriteLine(prev);
    }
}


Measured memory_bytes: 21728
#include<bits/stdc++.h>
#define maxn 1000005
using namespace std;
int n,ans;
char s[maxn],t[maxn];
queue<int>q;
int main()
{
	scanf("%d%s%s",&n,s,t);
	for(int i=0;i<n;i++) if(s[i]!=t[i]) {ans=-1;break;}
	if(ans!=-1) return puts("0"),0;
	for(int up=n-1,down=n-1;down>=0;down--){
		if(t[down]==t[down-1]) continue;
		while(up>down||(up>=0&&s[up]!=t[down])) up--;
		if(up<0) {ans=-1;break;}
		while(!q.empty()&&q.front()-q.size()>=down) q.pop();
		if(up!=down) q.push(up);
		ans=max(ans,(int)q.size()+1);
	}
	printf("%d\n",ans);
}

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

P f(int x) {
    int a = x % 10;
    int b = 0;
    while (x) {
        b = x;
        x /= 10;
    }
    return P(a, b);
}

int main()
{
    int n;
    cin >> n;
    map<P, int> freq;
    for (int i = 1; i <= n; i++) {
        P p = f(i);
        freq[p]++;
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        P p = f(i);
        P q(p.second, p.first);
        ans += freq[q];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;


int main(void){

	int h,w;
	string ws;
	while(cin>> h >>w){
		if(h==0 && w==0|| cin.eof()) break;
		vector< vector<int> > ba(h+1,vector<int>(w+1));
		rep(i,h){ 
			cin >> ws;
			rep(j,w){
				if(ws[j] != '*'){
					if(i<1) ba[i][j]=1;
					else ba[i][j] = ba[i-1][j]+1;
				}else{ ba[i][j] = 0; }
			}
		}
		//for(auto x: ba){ for(auto z: x) printf("%d ",z);puts("");}
		int res = 0;
		rep(i,h) rep(j,w){
			int mnh = ba[i][j];
			rep2(k, j+1, w){
				if(ba[i][k]==0) break;
				mnh = min(mnh, ba[i][k]);
				res = max(res, mnh * (k-j+1));
			}
		}
		cout << res << endl;
	}

	return 0;
	
}

Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[100000],n,m,s,i;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for(i=n;i>=n-m+1;i--)
        s+=a[i];
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun n ->
    let i = int_of_float (sqrt (float n)) in

    let digits a = string_of_int a |> String.length in
    let rec loop k =
        if n mod k = 0 then digits (n /k) else loop (k - 1)
    in
    loop i |> Printf.printf "%d\n"
)

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

int main() {
    long test=1;
    // cin>>test;
    while(test--)
    {
	long i,j,n,a,b,c,d,ans,A,B;
	string s1,s2,s3;
	cin>>a>>b>>c>>d;
	char cha='t';
	while(a>0 && c>0)
	{
	    if(cha=='t')
	    {
	        cha='a';
	        c-=b;
	    }
	    else
	    {
	        cha='t';
	        a-=d;
	    }
	}
	if(a<=0)cout<<"No";
	else cout<<"Yes";
	
	
    }
	return 0;
}

Measured memory_bytes: 3556
#include "iostream"
#include "vector"
#include "algorithm"

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  while (b != 0)
  {
    ll i = a % b;
    a = b;
    b = i;
  }
  return a;
}

int main()
{
  int n;
  cin >> n;
  ll t[110];
  ll ans = 1LL;
  for (int i = 0; i < n; i++)
  {
    cin >> t[i];
    ans = (ans / gcd(ans, t[i])) * t[i];
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

//--------------------------



int main() {

  int n, m;
  int x[101], a[101];
  int flag[2019];

  rep(i, 2019) flag[i] = 0;

  cin >> n;
  rep(i, n) {
    cin >> x[i];
    --x[i];
    flag[x[i]] = 1;
  }

  cin >> m;
  rep(i, m) {
    cin >> a[i];
    --a[i];
    if(x[a[i]]+1<=2018&&flag[x[a[i]]+1]==0) {
      flag[x[a[i]]] = 0;
      flag[x[a[i]]+1] = 1;
      ++x[a[i]];
    }
  }

  rep(i, 2019) {
    if(flag[i]==1) cout << i+1 << endl;
  }

  return 0;
}



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

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

  int n, k;
  string s;
  cin >> n >> k >> s;

  int init = 0;
  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) == s.at(i + 1)) {
      init++;
    }
  }

  cout << min(init + 2 * k, n - 1) << endl;

  return 0;
}

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

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

    if(s == "RRR") cout << 3 << endl;
    else if(s == "SSS") cout << 0 << endl;
    else if(s == "SRR" || s == "RRS") cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3592
from collections import defaultdict
def build_dp (s) :
    temp = [0,0,0] 
    for c in s :
        if c == "R" :
            temp[0] += 1
        elif c == "G" :
            temp[1] += 1
        else :
            temp[2] += 1
    return temp

def choose3 (n) :
    return (n*(n-1)*(n-2))//6

def choose2 (n) :
    return (n*(n-1))//2

def d(n, s) :
    dp = build_dp(s)
    all_pos = choose3(n)
    for i in range(3) :
        all_pos -= choose3(dp[i])
        for j in range(3) :
            if i == j :
                continue
            all_pos -= choose2(dp[i])*dp[j]

    for i in range(n) :
        for j in range(1,n) :
            if i-j < 0 or i+j >= n :
                break 
            if s[i-j] != s[i] and s[i+j] != s[i] and s[i-j] != s[i+j] :
                all_pos -= 1
    
    return all_pos

if __name__ == "__main__" :
    n = int(input())
    s = input()
    print(d(n, s))


Measured memory_bytes: 9484
#include<cstdio>

using namespace std;

int ord(int n, int p){
	int t = 0;
	while(n % p == 0){
		n /= p;
		t++;
	}
	return t;
}

int main(){
	int n; scanf("%d", &n);
	int res = 0;
	for(int i = 0; i < n; i++){
		int a; scanf("%d", &a);
		res += ord(a, 2);
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val h = sc.nextInt()
    val w = sc.nextInt()
    val n = sc.nextInt()

    val b = if (w > h) w else h

    println((n + b - 1) / b)


}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 29352
//AOJ0278

#include <iostream>
using namespace std;

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

  for(int i=0; i<N; i++){
    int x, y, b, p;
    cin >> x >> y >> b >> p;

    int f1 = x*b + y*p;

    if(b<5){
      b = 5;
    }
    if(p<2){
      p = 2;
    }
    int f2 = (x*b + y*p)*4/5;

    if(f1<f2){
      cout << f1 << endl;
    }
    else{
      cout << f2 << endl;
    }
  }

  return 0;
}

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

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

    for (int i = 1; i < 10; i++) {
        if (n % i == 0) {
            if (n / i < 10) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n, max = 0, min = 10e9, a;
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) {
    scanf("%d", &a);
    if(min > a) min = a;
    if(max < a) max = a;
  }
  printf("%d", max - min);
  return 0;
}

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
using namespace std;
typedef long long ll;
typedef string str;
int main(){
    str n;
    cin >> n;
    if(n[0]=='7' || n[1]=='7' || n[2]=='7') cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

string a, b;
int num;

int main() {
	cin >> a >> b;
	a += b;

	num = sqrt(atoi(a.c_str()));

	if (atoi(a.c_str()) == num*num) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

using namespace std;

int main() {
    string s;
    int x, y;
    cin >> s >> x >> y;

    int n = s.size();

    vector<int> t(1, 0);
    for (int i = 0; i < n; i++) {
        if (s[i] == 'F') {
            t[t.size() - 1]++;
        } else {
            t.push_back(0);
        }
    }

    vector<vector<bool>> dp(2, vector<bool>(2 * n + 1, false));
    dp[0][t[0] + n] = true;
    dp[1][n] = true;

    for (int i = 1; i < static_cast<int>(t.size()); i++) {
        vector<bool> next(2 * n + 1, false);
        for (int j = 0; j < 2 * n + 1; j++) {
            if (dp[i % 2][j]) {
                next[j - t[i]] = true;
                next[j + t[i]] = true;
            }
        }

        dp[i % 2] = next;
    }

    cout << (dp[0][x + n] && dp[1][y + n] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
vector<int> g[100005];
map<pii,int>id;
vector<int> ans;
void dfs(int s, int p, int c){
    if(p != -1)ans[id[pii(s,p)]] = c;
    int sz = (int)g[s].size();
    int now = 1;
    rep(i,sz){
        int x = g[s][i];
        if(x == p)continue;
        if(now == c)now++;
        dfs(x, s, now++);
    }
    
}
int main(){
    int n;
    cin >> n;
    rep(i,n-1){
        int a, b;
        cin >>a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
        id[pii(a,b)] = id[pii(b,a)] = i;
    }
    ans.resize(n - 1);
    dfs(0, -1, 1000000);
    cout << *max_element(ans.begin(), ans.end()) << endl;
    rep(i,n-1){
        cout << ans[i] << "\n";
    }
}


Measured memory_bytes: 19328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	ll d = 50;
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<vector<ll>> dp(d + 1, vector<ll>(2, -1));
	dp[0][1] = 0;

	for (int i = 1; i <= d; i++) {
		ll mask = 1LL << d - i;
		ll num = 0;
		for (int j = 0; j < n; j++) if (a[j] & mask) num++;
		ll count1 = mask * num;
		ll count0 = mask * (n - num);

		if (dp[i - 1][0] != -1) {
			dp[i][0] = dp[i - 1][0] + max(count0, count1);
		}
		
		if (dp[i - 1][1] != -1) {
			if (k & mask) dp[i][0] = max(dp[i][0], dp[i - 1][1] + count1);
		}
		
		if (dp[i - 1][1] != -1) {
			if (k & mask) dp[i][1] = dp[i - 1][1] + count0;
			else dp[i][1] = dp[i - 1][1] + count1;
		}
	}
	cout << max(dp[d][0], dp[d][1]) << endl;
}

Measured memory_bytes: 1024
n = int(input())
a = [int(num) for num in input().split()]

a.insert(0,99999)
a.append(-99999)

money = 1000
stocks = 0

prev_state = "decrease"
next_state = "none"

for i in range(1,len(a)-1):
    # bottom -> buy
    if a[i-1] > a[i]:
        prev_state = "decrease"
    elif a[i-1] < a[i]:
        prev_state = "increase"

    if a[i] > a[i+1]:
        next_state = "decrease"
    elif a[i] < a[i+1]:
        next_state = "increase"
    
    if prev_state == "decrease" and next_state == "increase":
        stocks += money // a[i]
        money %= a[i]
    elif prev_state == "increase" and next_state == "decrease":
        money += a[i]*stocks
        stocks = 0

print(money)

Measured memory_bytes: 8996
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n,i;
  cin>>n;int a[n+1],dp[n+1];
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
  dp[0]=0;dp[1]=abs(a[1]-a[0]);
  for(i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  }
  cout<<dp[n-1];
  return 0;
}
    

Measured memory_bytes: 1024
n = int(input())
t = tuple(map(int,input().split()))
m = int(input())
x = [list(map(int,input().split())) for _ in range(m)]

i = 0
for x[i] in x:
    l = list(t)
    j = x[i][0] - 1 #インデックス
    k = x[i][1]     #置換元
    i += i
    l[j] = k
    print(sum(l))

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

int main() {
    int n;
    cin >> n;
    string s, p, q;

    for (int i = 0; i < n; i++) {
        cin >> s;
        p += s;
    }
    for (int i = 0; i<n; i++){
        cin >>s;
        q += s;
    }

    vector<int> v(n);
   
    for (int i = 0; i <n; i++) {
        v[i] = i+1;
    }

    int cnt = 0;
    int pc, qc;
    do {
        string r;
        for (int i = 0; i < n; i++) {
            r += '0' + v[i];
        }

        if(p==r){
            pc =cnt;
        }
        if(q==r){
            qc = cnt;
        }
        cnt++;

    } while (next_permutation(v.begin(), v.end()));

    cout << abs(pc - qc) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >>m;
  vector<int> N(n);
  for(int i =0;i<2*m;i++){
    int k;
    cin >>k;
    N.at(k-1)++;
  }
  for(int i = 0;i<n;i++){
    cout << N.at(i);
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,i,n,ap,bp;
	
	for(;;){
		a=b=0;
		scanf("%d",&n);
		if(n==0) break;
		for(;n!=0;n--){
			scanf("%d%d",&ap,&bp);
			if(ap>bp) a+=ap+bp;
			else if(ap<bp) b+=ap+bp;
			else{
				a+=ap;b+=bp;
			}
		}
		printf("%d %d\n",a,b);
	}
}

Measured memory_bytes: 0
//ABC045#b
#include <iostream>
using namespace std;

int main(){
	string sa,sb,sc;
	cin >> sa;
	cin >> sb;
	cin >> sc;

	int na,nb,nc;
	na = sa.size();
	nb = sb.size();
	nc = sc.size();

	int ai,bi,ci;
	ai = 0;
	bi = 0;
	ci = 0;

	string tmp = "a";
	int tag = 1;
	while(tag == 1){
		if(tmp == "a"){
			if(ai < na){
				tmp = sa[ai];
				ai += 1;
			}else{
				cout << 'A' << endl;
				tag = 0;
			}
		}else if(tmp == "b"){
			if(bi < nb){
				tmp = sb[bi];
				bi += 1;
			}else{
				cout << 'B' << endl;
				tag = 0;
			}
		}else if(tmp == "c"){
			if(ci < nc){
				tmp = sc[ci];
				ci += 1;
			}else{
				cout << 'C' << endl;
				tag = 0;
			}
		}
	}
	return 0;
}
//2016/10/5

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int H, W;
    scanf("%d %d", &H, &W);
    
    // 2. 2倍縦長の画像を出力.
    rep(i, H){
        char c[111];
        scanf("%s", c);
        string s(c);
        printf("%s\n%s\n", s.c_str(), s.c_str());
    }
    return 0;
    
}

Measured memory_bytes: 256
import bisect


def main():
    N, D, A = list(map(int, input().split()))
    monsters = [list(map(int, input().split())) for _ in range(N)]
    monsters.sort()
    X = [m[0] for m in monsters]
    # 端から貪欲に攻撃していく
    ans = 0
    damages = [0] * (N + 1)
    for n, monster in enumerate(monsters):
        x, h = monster
        h = max(0, h - damages[n])
        to_n = bisect.bisect_right(X, x + 2 * D)
        cnt = (h + A - 1) // A  # ceil(h / A)
        ans += cnt
        damages[n] += A * cnt
        damages[to_n] -= A * cnt
        damages[n + 1] += damages[n]
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 55452
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 1e15;
const double eps = 1e-6;
const ll MOD = 1000000007;

int main() {
	ll N;
	cin >> N;
	ll ans = 0;
	for (int i = 0;i < N;i++) {
		ll A, K;
		cin >> A >> K;
		while (A % K != 0 && A >= K) {
			ll step = A / K + 1;
			ll mult = (max(0LL, (A - 1)) % K) / step + 1;
			A -= step * mult;
		}
		ll now;
		if (A < K)
			now = 0;
		else
			now = A / K;
		ans ^= now;
		//cout << endl << now << endl;
	}
	if (ans == 0)
		cout << "Aoki" << endl;
	else
		cout << "Takahashi" << endl;

	return 0;
}


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

def partition(A, p, r):
    x = A[r - 1]
    i = p -1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    return i

q = partition(A, 0, n)
A[q] = "[" + str(A[q]) + "]"
print(*A)


Measured memory_bytes: 16384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
using namespace std;
 
 
int main(){
    int p,q,r; cin >> p >> q >> r;
    cout << min(q+r,min(p+q,p+r)) << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 200005;
inline int readint()
{
	int res = 0, f = 1;
	char c = 0;
	while(!isdigit(c))
	{
		c = getchar();
		if(c=='-')
			f = -1;
	}
	while(isdigit(c))
		res = res*10+c-'0', c = getchar();
	return res*f;
}
int n,k,a[MAXN];
int len[MAXN],mina[MAXN],maxa[MAXN],q[MAXN],front,rear;

int main()
{
	n = readint(), k = readint();
	for(int i = 1; i<=n; i++)
	    a[i] = readint();
	len[1] = 1;
	for(int i = 2; i<=n; i++)
		len[i] = a[i]>a[i-1]?len[i-1]+1:1;
	front = rear = 0;
	for(int i = 1; i<=n; i++)
	{
		while(front<rear&&a[q[rear-1]]<a[i])
			rear--;
		while(front<rear&&q[front]<=i-k)
			front++;
		q[rear++] = i;
		if(i>=k)
			maxa[i-k+1] = a[q[front]];
	}
	front = rear = 0;
	for(int i = 1; i<=n; i++)
	{
		while(front<rear&&a[q[rear-1]]>a[i])
			rear--;
		while(front<rear&&q[front]<=i-k)
		    front++;
		q[rear++] = i;
		if(i>=k)
			mina[i-k+1] = a[q[front]];
	}
	int ans = 1;
	bool flag = len[k]==k;
	for(int i = 1; i<n-k+1; i++)
	{
		int dt = 0;
		if(a[i]!=mina[i]||a[i+k]!=maxa[i+1])
			dt = 1;
		if(len[i+k]>=k&&flag)
			dt = 0;
		flag |= len[i+k]>=k;
		ans += dt; 
	}
	cout << ans << endl;
	return 0;
}


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

namespace ABC065C
{
    class Program
    {
        const long Mod = 1000000007;

        static void Main(string[] args)
        {
            long N, M;
            string[] vals = Console.ReadLine().Split(' ');
            N = long.Parse(vals[0]);
            M = long.Parse(vals[1]);
            
            if((N+M) %2 == 0)
            {
                if(N == M)
                {
                    long ans = fact(N) * fact(M) * 2 % Mod;
                    Console.WriteLine(ans);
                }
                else
                {
                    Console.WriteLine(0);
                }
            }
            else
            {
                if(Math.Abs(N-M) == 1)
                {
                    long ans = fact(N) * fact(M) % Mod;
                    Console.WriteLine(ans);
                }
                else
                {
                    Console.WriteLine(0);
                }
            }

        }

        static long fact(long n)
        {
            long ret = 1;

            for(; n > 1; n--)
            {
                ret = ret * n % Mod;
            }

            return ret;
        }

    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;



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

	ll n,k;
	string s;
	cin >> n >> k >> s;

	s = s+'2';
	vector<ll> v,x;// 0normal 1mi
	ll count = 1;
	FOR(i,1,s.size()){
		if(s[i]!=s[i-1]){
			v.push_back(count);
			count = 1;
			if(s[i-1]=='1')x.push_back(0);
			else x.push_back(1);
		}else{
			count++;
		}
	}

	vector<ll> ans(x.size()),xsum(x.size());
	ans[0] = v[0];
	xsum[0] = x[0];
 	FOR(i,1,x.size()){
 		ans[i] = ans[i-1]+v[i];
 		xsum[i] = xsum[i-1]+x[i];
	}
	ll res = 0;
	FOR(i,0,x.size()){
		if(xsum[i]<=k)res = max(res,ans[i]);
		else{
			res = max(res,ans[i]-ans[i-k*2-(x[i]==0)]);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3804
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let x: usize = read();
    // BPPPB
    //
    let mut size = 5;
    let mut pcnt = 3;
    let mut map: Vec<(usize, usize)> = vec![(0, 0)];
    for i in 0..n {
        map.push((size, pcnt));
        size = size * 2 + 3;
        pcnt = pcnt * 2 + 1;
    }
    let ans = dfs(n, x, &map);
    println!("{}", ans);
}

fn dfs(n: usize, x: usize, map: &Vec<(usize, usize)>) -> usize {
    if n == 1 {
        return match x {
            5 | 4 => 3,
            3 => 2,
            2 => 1,
            _ => 0,
        };
    }
    if x >= map[n].0 - 1 {
        return map[n].1;
    }

    if x > map[n - 1].0 + 2 {
        return map[n - 1].1 + 1 + dfs(n - 1, x - map[n - 1].0 - 2, &map);
    }

    if x == map[n - 1].0 + 2 {
        return map[n - 1].1 + 1;
    }

    if x > 1 {
        return dfs(n - 1, x - 1, &map);
    }
    return 0;
}


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

int main(){
    int N, D;
    cin >> N >> D;
    int ans1 = N / (2 * D + 1);
    int ans2 = N % (2 * D + 1);
    if (ans2 > 0){
        ans1 += 1;
    }
    cout << ans1 << endl;
}


Measured memory_bytes: 256
A,B,K = list(map(int,input().split()))
if K >= A:
    if B - (K - A) >= 0:
        print(str(0)+' '+str(B-(K-A)))
    else:
        print(str(0)+' '+str(0))
else:
    print(str(A - K) + ' ' + str(B))

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <map>
#include <unordered_set>
#include <tuple>
#include <queue>
#include <set>
#include <cstring>
#include <functional>
#include <random>
#include <chrono>

#define ar array
#define all(arr) (arr).begin(), (arr).end()
#define range(i, n) for (int i=0; i < n; ++i)
#define rall(arr) (arr).rbegin(), (arr).rend()

typedef long long ll;
typedef long double ld;

using namespace std;

const ll INF = 1e18;
const int INFi = 2e9;
const int maxN = 1e6 + 5;
const int md = 998244353;
const int md2 = 1e9 + 7;

double getTime() { return clock() / (double) CLOCKS_PER_SEC; };

void solve() {
    ll n; int x, m; cin >> n >> x >> m;
    vector<int> ans(m+5);
    map<int, int> mp;
    mp[x] = 1;
    int cycle = 0;
    int start = -1;
    ans[1] = x;
    for(int i = 2; i <= m + 5; ++i) {
        x = (1ll * x * x) % m;
        if (mp[x] != 0) {
            start = mp[x];
            cycle = i - mp[x];
            break;
        }
        ans[i] = x;
        mp[x] = i;
    }
    ll cyclesum = 0;
    for(int i = start; i < start + cycle; ++i) cyclesum += ans[i];
    vector<ll> pref(m+5);
    range(i, m) pref[i+1] = pref[i] + ans[i+1];
    if (n < start) {
        cout << pref[n] << "\n";
        return;
    }
    ll k = (n - start + 1) / cycle;
    ll answ = k * cyclesum;
    ll e = (n -  start + 1) % cycle;
    answ += pref[start + e - 1];
    cout << answ << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //cout << setprecision(15) << fixed;
    int tests = 1;
    //cin >> tests;
    range(_, tests) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 6560
n, sum = [int(s) for s in input().split()]

for x in range(n + 1):
    for y in range(n - x + 1):
        if x * 10000 + y * 5000 + (n-x-y) * 1000 == sum:
            print(x, y, n-x-y)
            exit()

print(-1, -1, -1)

Measured memory_bytes: 40684
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,col[205],vis[205];
vl adj[205];
void dfs(ll i)
{
    vis[i]=1;
    for(auto j:adj[i])
    {
        if(!vis[j])
        {
            col[j]=1-col[i];
            dfs(j);
        }
        else if(col[i]==col[j])
        {
            cout<<-1;
            exit(0);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    rep(i,0,n)
    {
        string s;
        cin>>s;
        rep(j,0,n)
        {
            if(s[j]=='1')
                adj[i].pb(j);
        }
    }
    memset(col,-1,sizeof(col));
    col[0]=0;
    dfs(0);
    ll f=0;
    rep(i,0,n)
    {
        ll ans=0;
        memset(vis,0,sizeof(vis));
        set<ll>s;
        s.insert(i);
        while(sz(s))
        {
            for(auto j:s)
                vis[j]=1;
            ans++;
            set<ll>g;
            for(auto j:s)
            {
                for(auto k:adj[j])
                {
                    if(!vis[k])
                        g.insert(k);
                }
            }
            s=g;
        }
        f=max(f,ans);
    }
    cout<<f;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    string s;cin >> s;
    string ret;
    rep(i,3){
        if(s[i] == '1')ret += '9';
        else if(s[i] == '9')ret += '1';
        else ret += s[i];
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
string S;
int main(){
  cin >> S;
  if(S[0]!='A'){
    cout << "WA" << endl;
    return 0;
  }
  S[0]='a';
  /*string l=S;
  l.resize(S.size()-2);
  string r=l.substr(2);
  if(r.find("C") == string::npos){
  cout << "WA" << endl;
  return 0;
}*/
int cnt=0;
for(int i=2;i<S.size()-1;i++){
  if(S[i] == 'C'){
    S[i]='c';
    cnt++;
  }
}
if(cnt!=1){
  cout << "WA" << endl;
  return 0;
}
for(int i=0;i<S.size();i++){
  if(isupper(S[i])!=0){
    cout << "WA" << endl;
    return 0;
  }
}
cout << "AC" << endl;
return 0;
}


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

const int mod=998244353;
#define ll long long
#define ld long double
#define pb push_back
#define Dracarys ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()

ll po(ll x,ll y,ll md=mod){
	ll res=1;
	x%=md;
	
	while(y){
		if (y&1){
			res=(res*x)%md;
		}
		y>>=1;
		x=(x*x)%md;
	}
	return res;
}

void solve(){
		ll h1,m1,h2,m2,s;
		cin>>h1>>m1>>h2>>m2>>s;
		
		ll tot=(h2*60+m2-(h1*60+m1));
		cout<<(tot-s)<<"\n";	
}

int main(){
	
	Dracarys

	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



Measured memory_bytes: 3648
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int ans = 0;
		for(int i = 1; i < k; i++){
			for(int j = i+1; j <= k; j++){
				if(i%2!=j%2){
					ans++;
				}
			}
		}
		System.out.print(ans);
	}
}


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

namespace ITP1_8_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine();
            var word = Console.ReadLine();

            //target = target + target.Substring(0, word.Length - 1);
            //var find = target.Contains(word);
            //Console.WriteLine(find ? "Yes" : "No");

            var index = 0;
            for (var h = 0; h < target.Length; ++h)
            {
                index = 0;
                for (var i = 0; i < word.Length; ++i)
                {
                    var charIndex = (h + i) % target.Length;
                    if (target[charIndex] != word[index])
                    {
                        break;
                    }
                    ++index;
                }

                if (index == word.Length)
                {
                    break;
                }
            }

            Console.WriteLine((index == word.Length) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 5268
def ispalindrome(str): return 1 if str == str[::-1] else 0


def solve():
    S = input()
    N = len(S)
    if ispalindrome(S):
        left = S[:int(((N-1)/2))]
        if ispalindrome(left):
            right = S[int(((N+3)/2)-1):]
            if ispalindrome(right):
                print("Yes")
                exit()

    print("No")


# Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
import qualified Data.ByteString.Char8 as C
import Data.Maybe
import qualified Data.Vector as V
import Data.Vector.Unboxed
import Prelude hiding (drop, replicate, reverse, splitAt, toList, unfoldr, (++))

main = C.interact $ put . sol . get

get = unfoldr (C.readInt . C.dropWhile (<'0'))

put :: V.Vector (Vector Int) -> C.ByteString
put = C.unlines . V.toList . V.map (C.unwords . fmap (C.pack . show) . toList)

sol v = u
  where
  h = v!0
  w = v!1
  u = V.imap (\i a -> if odd i then reverse a else a)
    . V.unfoldrN h (Just . splitAt w)
    . ifoldl' (\u i a -> u ++ replicate a (i+1)) empty
    $ drop 3 v

Measured memory_bytes: 7116
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int INF = INT_MAX / 2;

// {damage, mp}
vector<pair<int, int>> magics;

vector<vector<int>> dp;

int main(void) {
    int H, N;
    cin >> H >> N;

    magics.resize(N + 1);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        magics[i + 1] = {a, b};
    }

    dp.resize(N + 1, vector<int>(H + 1, INF));
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        auto magic = magics[i + 1];
        for (int j = 0; j <= H; j++) {
            chmin(dp[i + 1][j], dp[i][j]);
            if (j <= magic.first) {
                chmin(dp[i + 1][j], dp[i][0] + magic.second);
            } else {
                chmin(dp[i + 1][j], dp[i][j - magic.first] + magic.second);
                chmin(dp[i + 1][j], dp[i + 1][j - magic.first] + magic.second);
            }
        }
    }

    cout << dp[N][H] << endl;

    // for (int i = 0; i <= N; i++) {
    //     for (int j = 0; j <= H; j++) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}


Measured memory_bytes: 39424
D = [[1,0],[0,-1],[-1,0],[0,1]]

def dfs(x, y)
  if $fld[y][x] == "B"
    $flag_b = true 
    return
  end
  if $fld[y][x] == "W"
    $flag_w = true
    return
  end
  $vst[y][x] = true
  D.each do |dx, dy|
    nx, ny = x + dx, y + dy
    if nx >= 0 && nx < $w && ny >= 0 && ny < $h && $vst[ny][nx].nil?
      dfs(nx, ny)
    end
  end
end

loop do
  $w, $h = gets.split.map(&:to_i)
  break if $w == 0
  $fld = $h.times.map{ gets.chomp.split("") }
  cw = cb = 0
  for i in (0...$w)
    for j in (0...$h)
      $vst = $h.times.map{ [nil]*$w }
      $flag_b = $flag_w = false
      dfs(i, j) unless $fld[j][i] == "B" || $fld[j][i] == "W" 
      cb += 1 if $flag_b && !$flag_w
      cw += 1 if !$flag_b && $flag_w
    end
  end
  puts "#{cb} #{cw}"
end

Measured memory_bytes: 17432
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
int a[100010];
int main(){
  cin>>N;
  rep(i,N) cin>>a[i];
  int x=0;
  rep(i,N){
    x=x^a[i];
  }
  if(x==0) prin("Yes");
  else prin("No");
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(void){
    int N;cin>>N;
    vector<ll>V(N);
    vector<ll>V1(N);
    vector<ll>V2(N);
    for(int i=0;i<N;i++)cin>>V[i];
    ll D=V[0];
    for(int i=0;i<N;i++){
        D=gcd(D,V[i]);
        V1[i]=D;
    }
    D=V[N-1];
    for(int i=N-1;i>=0;i--){
        D=gcd(D,V[i]);
        V2[i]=D;
    }
    ll ans=V2[1];
    if(N>2){
        for(int i=0;i<N-2;i++){
            if(gcd(V1[i],V2[i+2])>ans)ans=gcd(V1[i],V2[i+2]);
        }
    }
    if(V1[N-2]>ans)ans=V1[N-2];
    cout<<ans<<endl;
    
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();
		int k=sc.nextInt();

		int c[][] = new int[2*k][2*k];
		for(int i=0; i<n; i++) {
			int x=sc.nextInt();
			int y=sc.nextInt();
			if(sc.next().charAt(0)!='B') {
				x+=k;
			}
			x %= 2*k;
			y %= 2*k;
			c[x][y]++;
		}

		int s[][] = new int[2*k+1][2*k+1];
		s[0][0]=0;
		for(int i=0; i<2*k; i++) {
			for(int j=0; j<2*k; j++) {
				s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + c[i][j];
			}
		}

		long max = 0;
		for(int i=0; i<k; i++) {
			for(int j=0; j<k; j++) {
				int tmp1 = s[i][j];
				int tmp2 = s[2*k][j] - s[i+k][j];
				int tmp3 = s[i][2*k] - s[i][j+k];
				int tmp4 = s[i+k][j+k] - s[i][j+k] - s[i+k][j] + s[i][j];
				int tmp5 = s[2*k][2*k] - s[2*k][j+k] - s[i+k][2*k] + s[i+k][j+k];
				int tmp = tmp1+tmp2+tmp3+tmp4+tmp5;
				max = Math.max(max, tmp);
				max = Math.max(max, n-tmp);
			}
		}
		System.out.println(max);
		sc.close();
	}
}


Measured memory_bytes: 84612