akhauriyash/Code-Regression huggingface dataset:
A, B, M = map(int, input().split())

if A > 1:
    F = [int(i) for i in input().split()]
else:
    F = [int(input())]
if B > 1:
    D = [int(i) for i in input().split()]
else:
    D = [int(input())]


i = F.index(min(F))
j = D.index(min(D))
price = F[i] + D[j]

for i in range(M):
    xi, yi, ci = map(int, input().split())
    price_iter = F[int(xi)-1] + D[int(yi)-1] - ci
    if price > price_iter:
        i = xi
        j = yi
        price = price_iter

print(price)

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  
  vector<int> vec_x(N);
  vector<int> vec_y(N);
  vector<int> vec_a(N);
  
  for (int i=0; i<N; i++){
    cin >> vec_x.at(i) >> vec_y.at(i) >> vec_a.at(i);
  }
  
  int x_max=W, x_min=0, y_max=H, y_min=0;
  
  for (int i=0; i<N; i++){
    if (vec_a.at(i) == 1){
      if (vec_x.at(i) > x_min){
        x_min = vec_x.at(i);
      }
    }
    else if (vec_a.at(i) == 2){
      if (vec_x.at(i) < x_max){
        x_max = vec_x.at(i);
      }
    }
    else if (vec_a.at(i) == 3){
      if (vec_y.at(i) > y_min){
        y_min = vec_y.at(i);
      }
    }
    else{
      if (vec_y.at(i) < y_max){
        y_max = vec_y.at(i);
      }
    }
  }

  if (x_max-x_min<=0 || y_max-y_min<=0){
    cout << 0 << endl;
  }
  else{
    cout << (x_max - x_min)*(y_max - y_min) << endl;
  }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ACantWaitForHoliday solver = new ACantWaitForHoliday();
        solver.solve(1, in, out);
        out.close();
    }

    static class ACantWaitForHoliday {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String w = "SUNMONTUEWEDTHUFRISAT";
            String s = in.next();
            int i = w.indexOf(s);
            i /= 3;
            out.println(7 - i);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 21204
#include <iostream>
using namespace std;
int N,K;
int a[100009];
int minp,minv;
int kaisu;
int main() {
  minv=100001;
  cin >> N >> K;
  for (int i =0;i<N;i++){
      cin >> a[i];
      if(minv>a[i]){
          minv=a[i];
          minp=i;
      }
  }
  if(minp%(K-1)==0){
      kaisu=minp/(K-1);
  }else{
      kaisu=minp/(K-1)+1;
  }
  if((N-minp-1)%(K-1)==0){
      kaisu+=(N-minp-1)/(K-1);
  }else{
      kaisu+=((N-minp-1)/(K-1)+1);
  }
  if(minp%(K-1)!=0){
      if((N-minp-1)%(K-1)!=0){
          if(minp%(K-1)+(N-minp-1)%(K-1)<=K){
    kaisu-=1;
          }
      }            
  }
  cout << kaisu << endl;
}

Measured memory_bytes: 640
n = int(input())
li = list(map(int,input().split()))

cnt = 0
for i in range(n-2):
    s1 = li[i]
    s2 = li[i+1]
    s3 = li[i+2]
    if s1 < s2 and s3 > s2:
        cnt += 1
    elif s1 > s2 and s3 < s2:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int gcd(int a,int b){
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}
int main(){
    int n,k;
    cin >> n >> k;
    cout << n-k+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String args[]){
	Scanner scan = new Scanner(System.in);
	int n=scan.nextInt();
	int h,m;
	h=n/3600;
	n%=3600;
	m=n/60;
	n%=60;
	System.out.println(h+":"+m+":"+n);
    }
}

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

ll MOD = pow(10, 9)+7;

int main(){
    string s;
    cin >> s;
    int slen = s.size();
    vector<vector<ll>> dp(slen+1, vector<ll>(13+1));

    dp.at(0).at(0)=1;
    for(int i=0;i<slen;i++){
        int c;
        if(s.at(i)=='?') c=-1;
        else c=s.at(i)-'0';

        for(int j=0;j<10;j++){
            if(c!=-1 and c!=j) continue;
            for(int k=0;k<13;k++){
                dp.at(i+1).at((k*10+j)%13) += dp.at(i).at(k);
            }
        }
        for(int j=0;j<13;j++) dp.at(i+1).at(j)%=MOD;
    }
    cout << dp.at(slen).at(5) <<endl;
    return 0;
}

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

class Cube{
public:
    int f[6];

    Cube(){}

    void roll_z(){ roll(1, 2, 4, 3);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_x(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
        int t = f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
};

int getRight(Cube c1, int f1, int f2){
    for(int i=0; i<6;i++){
        for(int j=0; j<4; j++){
            if(c1.f[0] == f1 && c1.f[1] == f2) return c1.f[2];
            c1.roll_z();
        }
        if(i % 2 == 0) c1.roll_y();
        else c1.roll_x();
    }
    return -1;
}

int main(){
    Cube c;
    int f1, f2;

    for(int i=0; i<6; i++) cin >> c.f[i];
    int q; cin >> q;

    for(int i=0; i<q; i++){
        cin >> f1 >> f2;
        cout << getRight(c, f1, f2) << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <chrono>
#include <unordered_map>



using namespace std;

typedef long long int ll;
typedef int h_int;

#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, a, n) for(int i = ( a ); i < ( n ); ++i )
#define FORR(i, a, n) for(int i = ( n ); i >= ( a ); --i)

#define DOUT(x) cout << #x << " = " << ( x ) << "\n";
#define COUT(x) cout << ( x ) << "\n";


vector < vector<int> > v;
vector<int> l;
int n;
int f(int i, int m)
{
	if (i == n) return 0;
	if (m <= 0) return 0;
	if (v[i][m] != -1) return v[i][m];
	v[i][m] = max(f(i + 1, m), f(i + 1, m - 1) + l[i]);
	return v[i][m];
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k;
	cin >> n >> k;
	l.resize(n);
	v.resize(n);
	REP(i, n) v[i].resize(k + 1, -1);
	REP(i, n)
	{
		cin >> l[i];
	}
	COUT(f(0, k));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  int ans = (H - h) * (W - w);
  cout << ans << endl;
}


Measured memory_bytes: 3580
r_input = gets.chomp.reverse

flag = true

while flag
  before_slice_length = r_input.length

  if r_input.index("eraser".reverse) == 0
    r_input.slice!(0, 6)
  elsif r_input.index("dreamer".reverse) == 0
    r_input.slice!(0, 7)
  elsif r_input.index("erase".reverse) == 0
    r_input.slice!(0, 5)
  elsif r_input.index("dream".reverse) == 0
    r_input.slice!(0, 5)
  end

  if before_slice_length == r_input.length
    flag = false
  end
end

if r_input.length == 0
  puts("YES")
else
  puts("NO")
end

Measured memory_bytes: 69956
#import numpy as np
Input = str(input())
Input = Input.split(" ")
S = []
L = len(Input)
# S= np.zeros([100])
for i in range(100):
    S.append(0)

Look = 0
for i in range(L):
    if Input[i] == "+":
        S[Look - 2] = S[Look - 2] + S[Look - 1]
        Look -= 1
        
    elif Input[i] == "-":
        S[Look - 2] = S[Look - 2] - S[Look - 1]
        Look -= 1
    elif Input[i] == "*":
        S[Look - 2] = S[Look - 2] * S[Look - 1]
        Look -= 1
    else:
        S[Look] = int(Input[i])
        Look += 1
        
    Look%=100
print(int(S[Look-1]))




Measured memory_bytes: 5600
# coding: utf-8
	
def main():
	# ２つの整数を入力
	N, Y = map(int, input().split(' '))

	# すべての枚数を列挙する。
	for i in range(Y // 10000 + 1):
		y = Y - i * 10000
		for j in range(y // 5000 + 1):
			k = (y - j * 5000) // 1000
			if i + j + k == N:
				print('%d %d %d' % (i, j, k))
				exit(0)
	print('-1 -1 -1')


if __name__ == '__main__':
	main()


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int i,n;
	int a[100];

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=n-1;i>0;i--){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[0]);
	return 0;
}

Measured memory_bytes: 596
from collections import Counter


N,K=map(int,input().split())
A=list(map(int,input().split()))
count=0
S=set(A)
c=Counter(A)
L=c.most_common(len(S))

x=len(S)-1
for _ in range(len(S)-K):
    count=count+int(L[x][1])
    x=x-1

print(count)

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

#define ll long long

using namespace std;
const int MX = 200'000 + 5; // check bounds!

int a[1002];
int main() {
    int n, k;
    cin >> n >> k;
    while (k--) {
        int d;
        cin >> d;
        while (d--) {
        int tmp;
        cin >> tmp;
        a[tmp] = 1;
        }
    }
    int sol = 0;
    for (int i = 1; i <= n; ++i)
        if (a[i] == 0)
            sol++;
    cout << sol;
    

    return 0;
}


Measured memory_bytes: 3636
a,b=map(int, input().split())

cnt = [0]*b
r = 0
for i in range(a):
    li = list(map(int, input().split()))
    #print(li)
    for j in range(1,len(li)):
        cnt[li[j]-1] +=1
        #print(cnt)
        
for k in range(b):
    if(cnt[k] == a):
        r += 1
print(r)





Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{  
  int n500, n100, n50, total;
  cin >> n500;
  cin >> n100;
  cin >> n50;
  cin >> total;
  
  int cnt = 0;
  for (int i500=0; i500<=n500; ++i500)
  {
    for (int i100=0; i100<=n100; ++i100)
    {
      for (int i50=0; i50<=n50; ++i50)
      {
        const int res = (500 * i500) + (100 * i100) + (50 * i50);
        if (res == total) ++cnt;
      }
    }
  }
  
  cout << cnt << endl;
}


Measured memory_bytes: 256
from itertools import product

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

S = []

for i in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])

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

sw = []


def judge(sw):
    for m in range(M):
        count = 0
        for k in S[m]:
            if sw[k-1] == 1:
                count += 1
        if count % 2 != P[m]:
            return False
    return True


ans = 0

for p in product(range(2), repeat=N):
    # print(p)
    if judge(p):
        ans += 1


# def dfs(n):
#    if len(sw) == n:
#        if judge(a):
#            ans += 1
#
#    sw.append(True)
#    dfs(n-1)
#    del sw[-1]
#    sw.append(False)
#    dfs(n-1)
#    del sw[-1]


print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
long long int CD(long long int a,long long int b){
	long long int tmp,r;
	long long int x;
	x=a*b;
	if(a<b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while(r!=0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return x/b;
}
int main()
{
	long long int A,B,C,D,cd,N,cn,dn,cdn;
	scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
	N=B-A+1;
	if(A%C==0){cn = A;}else{cn = A+C-A%C;}
	if(A%D==0){dn = A;}else{dn = A+D-A%D;}
	if(cn>B){cn=0;}else{cn = (B-cn)/C+1;}
	if(dn>B){dn=0;}else{dn = (B-dn)/D+1;}
	cd = CD(C,D);
	if(A%cd==0){cdn = A;}else{cdn = A+cd-A%cd;}
	if(cdn>B){cdn=0;}else{cdn = (B-cdn)/cd+1;}
	printf("%lld\n",N-cn-dn+cdn);
	return 0;
}


Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut ss = vec![];
    for i in 0..n {
        ss.push(read::<String>());
    }

    let mut count_dict = HashMap::new();
    for i in 0..n {
        let mut counts = vec![0; 26];
        for ch in ss[i].chars() {
            let idx = ch.to_digit(36).unwrap() as usize - 10;
            counts[idx] += 1;
        }
        *count_dict.entry(counts).or_insert(0) += 1;
    }
    // debug!(count_dict);
    let mut ans = 0i64;
    for &v in count_dict.values() {
        ans += v * (v - 1) / 2;
    }
    println!("{}", ans);
}

fn print_array<T: std::string::ToString>(array: &Vec<T>) {
    println!(
        "{}",
        array
            .iter()
            .map(|ref x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 26744
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; }
ll f[41][1<<18];
ll wf[41];
int main() {
	ll xt,yt,zt;
	ll n; scanf("%lld %lld %lld %lld",&n,&xt,&yt,&zt);
	ll xlim=xt,ylim=yt,zlim=zt;
	ll logs=xlim+ylim+zlim+1;
	ll slim=1<<logs;
	f[0][1]=1;
	wf[0]=2;
	wf[1]=2;
	wf[2]=2;
	wf[3]=1;
	for (ll p=0;p<n;p++) {
		for (ll s=0;s<slim;s++) {
			if (f[p][s]==0) continue;
			for (ll d=1;d<=10;d++) {
			//{
			//	ll d=wf[p];
				ll ns=(1<<(xlim+ylim+zlim))&s;
				if (d<=xlim) ns|=1<<d;
				for (ll x=0;x<xlim;x++) {
					if (s&(1<<x)) if (x+d<=xlim) ns|=1<<(x+d);
				}
				for (ll y=0;y<ylim;y++) {
					if (s&(1<<(y+xlim))) if (y+d<=ylim) ns|=1<<(y+d+xlim);
				}
				for (ll z=0;z<zlim;z++) {
					if (s&(1<<(z+xlim+ylim))) if (z+d<=zlim) ns|=1<<(z+d+xlim+ylim);
				}
				//cout<<p<<": "<<bitset<8>(s)<<" to " << bitset<8>(ns) << " : " << f[p][s] << endl;
				f[p+1][ns]+=f[p][s];
				f[p+1][ns]%=MOD;
			}
		}
	}
	ll ans=0;
	for (ll s=0;s<slim;s++) {
		if ((1<<(xlim+ylim+zlim))&s) {
			ans+=f[n][s];
			ans%=MOD;
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 60032
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]
sall = lambda: sys.stdin.readlines()

def main():
    x1, y1, x2, y2 = na()
    x3 = x2 - (y2-y1)
    y3 = y2 + (x2-x1)
    x4 = x1 - (y2-y1)
    y4 = y1 + (x2-x1)

    print(x3, y3, x4, y4)

main()


Measured memory_bytes: 3064
until (str = gets) == nil
  zero_flg = false
  str.chomp!
  ary = str.split(/[\+=]/)
  ary.each do |item|
    if item.size > 1 and item[0] == "X"
      zero_flg = true
      break
    end
  end
  str.gsub!("=", "==")
  unless zero_flg
    if eval str.gsub("X", "0")
      puts "0"
      next
    end
  end
  ("1".."9").each do |n|
    if eval str.gsub("X", n)
      puts n
      break
    elsif n == "9"
      puts "NA"
    end
  end
end

Measured memory_bytes: 8932
#include<bits/stdc++.h>
using namespace std;
char s[200200];
int n;
long long ans;
 
int main()
{
 
     cin>>s;
	n = strlen(s);
	int dem = 0;
	char kitu = 'B';
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == 'A') {
			if (kitu == 'B')
				ans += dem;
			else {
				dem = 0;
				kitu = 'B';
			}
		} else if (s[i] == 'B') {
			if (kitu == 'C') {
				kitu = 'B';
				dem++;
			} else {
				kitu = 'B';
				dem = 0;
			}
		} else {
			if (kitu == 'B') {
				kitu = 'C';
			} else {
				kitu = 'C';
				dem = 0;
			}
		}
	}
	cout<<ans;
 
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	int counter = 0;
	int i;
	for (i = 0; i <= s.size(); ++i) {
		if (s[i] == '1') ++counter;
	}
	cout << counter << endl;
}

Measured memory_bytes: 256
#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 <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
bool isp(ll m) {
    bool res = true;
    if (m == 1)return false;
    else {
        for (int i = 1; i * i <= m; i++) {
            if (m % i == 0) {
                res = false;
                break;
            }
        }
    }
    return res;
}
int main() {
    ll N;
    cin >> N;
  ll ans = 1;
  ll n = 0;
  bool res = false;
  vector<ll> num(N);
  for(ll i = 0;i<N;i++){
    cin >> num[i];
	if(num[i] == 0)res = true;
  }
  bool bo = false;
  if(res == false){
  for(int i = 0;i<N;i++){
    if(num[i] > 1000000000000000000 / ans){
      bo = true;
      break;
      
    }
       ans *= num[i];
  }
  }
  if(res)cout << "0" << endl;
  else if(bo)cout << "-1" << endl;
  else cout << ans << endl;
}

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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	t=lcm(c,d);
	n=b;
	ans+=(b-(b/c+b/d-b/t));
	b=a-1;
	ans-=(b-(b/c+b/d-b/t));
	ret(ans)
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int num=0;
int liner_search(int x,int S[],int N){
	int n=0;
	while(n<N && S[n]!=x){
		n++;
	}
	if(n<N){
		++num;
		return n;
	}
	else
		return -1;
}
int main(){
	
	int num1;
	cin>>num1;
	int a[num1];
	for(int i=0;i<num1;i++)
		cin>>a[i];
	int num2;
	cin>>num2;
	int b[num2];
	for(int i=0;i<num2;i++)
		cin>>b[i];
	int x[num2];
	for(int i=0;i<num2;i++){
		x[i]=liner_search(b[i],a,num1-1);
	}
	cout<<num<<endl;
	
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <string>
using namespace std;
 
 
void maxHeapify(vector<int>& A, int i, int H) {
    int l=2*i;
    int r=2*i+1;
    int largest=i;
 
    if(l<=H && A[i]<A[l]) {
        largest = l;
    }
 
    if(r<=H && A[largest]<A[r]) {
        largest = r;
    }
 
    if(largest!=i) {
        swap(A[i],A[largest]);
        maxHeapify(A,largest,H);
    }
 
    return;
}
 
int main() {
    int n;
    int H=0;
    int i;
    vector<int> A;
    string cmd;
 
    A.push_back(-1);
 
    cin >> cmd;
    while(cmd!="end") {
        if(cmd=="insert") {
            ++H;
            cin >> n;
            A.push_back(n);
            i=H;
            while(i/2!=0) {
                if(A[i]>A[i/2]) {
                    swap(A[i],A[i/2]);
                }
                i=i/2;
            }
        } else if(cmd=="extract") {
            cout << A[1] << endl;
            A[1]=A[H];
            --H;
            A.pop_back();
            maxHeapify(A,1,H);
        }
        cin >> cmd;
    }
    return 0;
}


Measured memory_bytes: 7108
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int a,b,t;cin>>a>>b>>t;
    int ans=0;
    ans=b*(t/a);
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> v;
    v.push_back(s[0]);
    for(int i = 1; i < N; i++){
        if(s[i] != s[i-1])  v.push_back(s[i]);
    }
    cout << v.size() << endl;
}

Measured memory_bytes: 1020
/**
  @date Time-stamp: <2019-05-19 12:14:02 tagashira>
  @file b.cpp
  @title B - Can you solve this?
  @brief https://atcoder.jp/contests/abc121/tasks/abc121_b
**/

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream> // std::ostringstream
#include <string>
#include <vector>

using namespace std;

bool can_you_solve_this(vector<int> Aj, vector<int> B, int C) {
  int sum = 0;
  for (uint i = 0; i < Aj.size(); i++) {
    sum += Aj[i] * B[i];
  }
  sum += C;
  return (sum > 0);
}

int main(int argc, char* argv[]) {
  uint i, j;
  uint N, M;
  int C;
  cin >> N >> M >> C;

  vector<int> B(M, 0);
  int tmpB;
  for (i = 0; i < M; i++) {
    cin >> tmpB;
    B.push_back(tmpB);
  }

  vector<vector<int>> A(N, vector<int>(M, 0));
  int tmpA;
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++) {
      cin >> tmpA;
      A[i].push_back(tmpA);
    }
  }

  uint ans = 0;
  for (i = 0; i < N; i++) {
    if (can_you_solve_this(A[i], B, C)) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

string S, T, U;
int A, B;

int main()
{
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if (U == S)
    {
        cout << A - 1 << " " << B << endl;
        return 0;
    }
    else
    {
        cout << A << " " << B - 1 << endl;
    }
}


Measured memory_bytes: 256
ACGT = ['A', 'C', 'G', 'T']
def ok(S):
    for c in S:
        if c not in ACGT:
            return False
    return True
def main():
    S = input()
    res = ''
    for i in range(len(S)):
        for j in range(1, len(S)+1):
            ps = S[i:j]
            if ok(ps) and len(ps) > len(res):
                res = ps

    print(len(res))
    

main()

Measured memory_bytes: 3060
D = int(input())
c = [None] + list(map(int, input().split()))
s = [None] + [[None] + list(map(int, input().split())) for _ in range(D)]
t = [None] + [int(input()) for _ in range(D)]

S = 0
last = [0] * 27
score = 0
for d in range(1, D + 1):
    S += s[d][t[d]]
    last[t[d]] = d
    for i in range(1, 27):
        S -= c[i] * (d - last[i])
    score += max(10 ** 6 + S, 0)
    print(S)


Measured memory_bytes: 9276
#include <iostream>
#include <map>
#include <bitset>
#include <cmath>
#include <climits>
#include<algorithm>
#include <vector>
#include <unordered_map>
#define loop for(int i=0;i<n;i++)
#define pb push_back
using namespace std;
typedef   long long int ll;
int main()
{
ll a;
ll b;
cin>>a>>b;
ll ans=INT_MIN;
for(int i=0;i<a*25;i++)
{
	if(floor(i*0.08)==a and floor(i*0.1)==b)
	{ans=i;
break;}
 }
 if(ans!=INT_MIN)
 cout<<ans<<endl;
 else
 cout<<"-1";
}



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

using namespace std;
using vi = vector<int>;
using ll = long long;

int const NMAX = 200 + 11;
ll const  INF  = 1e15;

int n, m, g[NMAX][NMAX];
ll  dist[NMAX][NMAX];

void floyd_warshall(void)
{
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i == j)
                dist[i][j] = 0;
            else if (g[i][j])
                dist[i][j] = g[i][j];
            else
                dist[i][j] = INF;
        }
    }

    for (int k = 1; k <= n; k++)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main(void)
{
    int rn, u, v, c;
    vi  r;

    cin >> n >> m >> rn;
    r.resize(rn);

    for (auto &ri : r)
        cin >> ri;

    while (m--)
    {
        cin >> u >> v >> c;
        g[u][v] = g[v][u] = (g[u][v] == 0 ? c : min(g[u][v], c));
    }

    sort(r.begin(), r.end());
    floyd_warshall();
    ll ans = INF, cur;
    do
    {
        cur = 0;
        for (int i = 1; i < rn; ++i)
            cur += dist[r[i - 1]][r[i]];
        ans = min(ans, cur);
    } while (next_permutation(r.begin(), r.end()));

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4100
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////
double M_PIi = 3.141592653589793;

int main() {

	int A, B, H, M;

	cin >> A >> B >> H >> M;

	double h_angle = double(H * 60 + M) / double(12*60);
	double m_angle = double(M) / double(60.f);

	double s_angle = h_angle - m_angle;

	double ans = A * A + B * B - double(2)*A*B*cos(M_PIi * double(2) * s_angle);

	printf("%.9f", sqrt(ans));

	return 0;
}


Measured memory_bytes: 4204
#include <atcoder/dsu.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<int> t(Q), u(Q), v(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> t[i] >> u[i] >> v[i];
  }

  dsu d(N);
  for (int i = 0; i < Q; ++i) {
    if (t[i] == 0) {
      d.merge(u[i], v[i]);
    } else {
      cout << d.same(u[i], v[i]) << endl;
    }
  }
}


Measured memory_bytes: 5744
#include <stdio.h>

int main(void);

int main(void) {
  int time, h, m, s;
  scanf("%d", &time);
  h = time / 3600;
  m = (time - h * 3600) / 60;
  s = time - h * 3600 - m * 60;
  printf("%d:%d:%d\n",h,m,s);
  return(0);
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;




int main(){
    string s;
    cin>>s;
    if(s=="SUN"){
        cout<<7<<endl;
        return 0;
    }else if(s=="MON"){
        cout<<6<<endl;
        return 0;
    }else if(s=="TUE"){
        cout<<5<<endl;
        return 0;       
    }else if(s=="WED"){
        cout<<4<<endl;
        return 0;        
    }else if(s=="THU"){
        cout<<3<<endl;
        return 0;
    }else if(s=="FRI"){
        cout<<2<<endl;
        return 0;       
    }else if(s=="SAT"){
        cout<<1<<endl;
        return 0;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}




bitset<100010> done;

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int k;
    cin >> k;
    deque<pair<int, int>> d;
    d.emplace_back(1, 1);

    int ans;
    while(!d.empty()){
        int sum, x;
        tie(sum, x) = d.front(); d.pop_front();
        if(done[x]) continue;
        done.set(x);
        if(x == 0) {
            ans = sum;
            break;
        }
        d.emplace_front(sum, x*10%k);
        d.emplace_back(sum+1, (x+1)%k);
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1152
n = int(input())
aas = list(map(int, input().split()))
money = 1000
stocks = 0
for i in range(n):
    if i < n-1:
        if aas[i+1] == aas[i]:
            continue
        if aas[i+1] > aas[i]:
            tmp = money // aas[i]
            money -= tmp * aas[i]
            stocks += tmp
        else:
            if stocks >= 1:
                money += aas[i] * stocks
                stocks = 0
    else:
        if stocks >= 1:
            money += aas[i] * stocks
            stocks = 0
print(money)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int,int> pii;
const int mod = (int) 1000000007;
const int inf = (int) 2e18;
const int maxn = 1e6 + 10;
int spf[maxn + 1], vis[maxn + 1];

void precompute()
{
	for (int i = 2; i <= maxn; i++)
	{
		if (!spf[i])
		{
			spf[i] = i;
			for (int j = i + i; j <= maxn; j += i)
			{
				if(!spf[j])
					spf[j] = i;
			}
		}
	}
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
    // code
    precompute();
    int n, x;
    cin >> n;
    vector<int> arr(n);
    for(int i=0; i<n; i++) cin >> arr[i];
    string res = "pairwise coprime";
    bool ok = true;
    for(int i=0; i<n; i++){
      x = arr[i];
      while(x != 1)
      {
        int cur = spf[x];
        int cnt = 0;
        while(spf[x] == cur)
        {
          x /= spf[x];
          ++ cnt;
        }
        if(!vis[cur] || cur == 1){
          vis[cur] = 1;
        } else {
          res = "setwise coprime";
          ok = false;
          break;
        }
      }
      if(!ok) break;
    }
    int r = -1;
    if(res == "setwise coprime"){
        r = arr[0];
        for(int i=1; i<n; i++){
            r = __gcd(r, arr[i]);
        }
        if(r == 1) r = -1;
    }
    if(r != -1) res = "not coprime";
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 19564
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
    static int[] ReadInts => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
    static long[] ReadLongs => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    #endregion

    static void Main()
    {
        int[] DTS = ReadInts;

        WriteLine(DTS[0]>DTS[1]*DTS[2]?"No":"Yes");
    }
}



Measured memory_bytes: 28280
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, b, h, m;
    long double rad, ans;
    cin >> a >> b >> h >> m;
    rad = abs(h*30.0 + (m/60.0)*30.0 - m*6.0);
    //cout << rad << endl;
    rad = (3.14159265358979323846264338327950/180.0)*rad;
    ans = sqrt((long double)(a*a + b*b) - (long double)(2.0*a*b*cos(rad)));
    cout << fixed << setprecision(20) << ans << endl;
}

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

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

int N, K;
int ps[1001];

int main(){
	cin>>N>>K;
	for(int i=0; i<N; i++){
		cin>>ps[i];
	}
	sort(ps, ps + N);

	int res = 0;
	for(int i=0; i<K; i++){
		res += ps[i];
	}

	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3628
# Kadane
module Kadane
  def self.max_subarray(a)
    max_so_far =  max_ending_here = -1.0 / 0
    a.each do |i|
      max_ending_here = [i, max_ending_here + i].max
      max_so_far = [max_so_far, max_ending_here].max
    end
    max_so_far
  end
end

answers = []

while n = gets.to_i
  break if n == 0
  a = []
  n.times { a << gets.to_i }
  answers << Kadane.max_subarray(a)
end

answers.each { |answer| puts answer }

Measured memory_bytes: 6112
#include <cstdio>

int main()
{
    int N,A,B;
    scanf("%d %d %d", &N, &A, &B);
    if (N * A < B)
    {
        printf("%d", N * A);
    }
    
    else
    {
        printf("%d", B);
    }
    
}


Measured memory_bytes: 1684
// Author: Tyler Wang

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(12);
  std::cerr.precision(12);
  std::mt19937 rng((std::uint_fast32_t)std::chrono::high_resolution_clock::now()
                       .time_since_epoch()
                       .count());
  string s, t;
  cin >> s >> t;
  int n = (int)s.size(), m = (int)t.size();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      dp[i + 1][j + 1] =
          max({dp[i][j + 1], dp[i + 1][j], dp[i][j] + (s[i] == t[j])});
    }
  }
  string ans;
  for (int i = n - 1, j = m - 1; i >= 0;) {
    if (dp[i][j + 1] == dp[i + 1][j + 1]) {
      --i;
    } else if (dp[i + 1][j] == dp[i + 1][j + 1]) {
      --j;
    } else {
      assert(s[i] == t[j]);
      ans += s[i];
      --i, --j;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<map>
#define PI 3.141592653589793238
#define INF -1
#define ll long long
using namespace std;

int main()
{
	int n;
	string strtmp;
	map<string,int> map;
	
	
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> strtmp;
		map[strtmp]++;
	}

	int max = 0;
	for (auto it = map.begin(); it != map.end(); it++) {
		if (it->second > max) {
			max = it->second;
		}
	}

	for (auto it = map.begin(); it != map.end(); it++) {
		if (it->second == max) {
			cout << it->first << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 25216
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
#define rl rd<LL>
typedef long long LL;
using namespace std;
const int mod = 1e9 + 7;

inline int pls(int x, int y) { return (x + y) % mod; }
inline int mns(int x, int y) { return pls(x, mod - y); }
inline int mul(int x, int y) { return 1LL * x * y % mod; }
inline void Add(int &x, int y) { x = pls(x, y); }
inline void Mul(int &x, int y) { x = mul(x, y); }
inline void Minus(int &x, int y) { x = mns(x, y); }

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

LL n;
int B;
int f[67][3];

int main() {

	n = rl();
	for (B = 0; (1LL << B) <= n; ++ B); -- B;
	f[B+1][0] = 1;
	per (i, B, 0) {
		LL m = n >> i, p = n >> (i + 1);
		if (f[i+1][0]) {
			// 1 + 1 out
			if ((p << 1 | 1) <= m) Add(f[i][min(2LL, m - (p << 1 | 1))], f[i+1][0]); // 0 + 1 ok
			if ((p << 1) <= m) Add(f[i][min(2LL, m - (p << 1))], f[i+1][0]); // 0 + 0 ok
		}
		if (f[i+1][1]) {
			--p;
			if (((p+1) << 1) <= m) Add(f[i][min(2LL, m - ((p+1) << 1))], f[i+1][1]); // 1 + 1 out
			if ((p << 1 | 1) <= m) Add(f[i][min(2LL, m - (p << 1 | 1))], f[i+1][1]); // 0 + 1 ok
			if ((p << 1) <= m) Add(f[i][min(2LL, m - (p << 1))], f[i+1][1]); // 0 + 0 ok
		}
		if (f[i+1][2]) {
			Add(f[i][2], mul(f[i+1][2], 3));
		}
	}

	int res = 0;
	For (j, 0, 3) Add(res, f[0][j]);
	printf("%d\n", res);
	
	return 0;
}

Measured memory_bytes: 128
N,M = map(int,input().split())
H=list(map(int,input().split()))
ABmap=[[] for i in range(N)]
count=0
for i in range(M):
    A,B=map(lambda x:x-1,map(int,input().split()))
    ABmap[A].append(H[B])
    ABmap[B].append(H[A])
        
for i in range(N):
    if len(ABmap[i])==0:
        count+=1
    elif max(ABmap[i])<H[i]:
        count+=1
   # print(ABmap[i])
print(count)
        
    

Measured memory_bytes: 22936
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int N[5], k;
  for (int i = 0; i < 5; ++i) {
      cin >> N[i];
  }
  cin >> k;

  int num = 0;
  for (int i = 0; i < 5; ++i) {
    for (int j = i+1; j < 5; ++j) {
      if(abs(N[i] - N[j]) > k) num++;
    }
  }

  if(num == 0){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin>>N;
  long long Ans=0;
  for(int i=1;i<=N;i++)
  {
    int Num=N/i;
    Ans+=1ll*Num*(Num+1)*i/2;
  }
  cout<<Ans<<endl;
  return 0;
}

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

const int maxN = 5005, mod = 1e9 + 7;

struct Node
{
	int to, next;
}edge[maxN * 2 + 1];

int n;
int tot, head[maxN + 1];
int f[maxN + 1][maxN + 1], g[maxN + 1];
int size[maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int SUB(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }

inline void add(int x, int y)
{
	tot ++;
	edge[tot].to = y;
	edge[tot].next = head[x];
	head[x] = tot;
}

inline void dfs(int u, int pa)
{
	size[u] = f[u][1] = 1;
	for(int i = head[u]; i; i = edge[i].next)
	{
		int v = edge[i].to;
		if(v == pa) continue;
		dfs(v, u);
		for(int j = size[u]; j >= 1; j--)
		{
			int res = f[u][j]; f[u][j] = 0;
			for(int k = 1; k <= size[v]; k++)
			{
				f[u][j + k] = ADD(f[u][j + k], 1ll * res * f[v][k] % mod);
				f[u][j] = SUB(f[u][j], 1ll * res * f[v][k] % mod * g[k] % mod);
			}
		}
		size[u] += size[v];
	}
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d %d", &x, &y);
		add(x, y); add(y, x);
	}

	g[0] = 1;
	for(int i = 2; i <= n; i += 2) g[i] = 1ll * g[i - 2] * (i - 1) % mod;

	dfs(1, 0);

	int ans = 0;
	for(int i = 1; i <= n; i++) ans = ADD(ans, 1ll * f[1][i] * g[i] % mod);

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


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

#define int long long
#define endl '\n'

const int N = 1e5 + 5;

vector<array<int, 2>> adj[N];
vector<int> dis(N);

void dfs(int x, int p) {
    for (auto i: adj[x]) {
        if (i[0] == p)  continue;
        dis[i[0]] = dis[x] + i[1];
        dfs(i[0], x);
    }
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n; cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int x, y, z; cin >> x >> y >> z;
        adj[x].emplace_back(array<int, 2> {y, z});
        adj[y].emplace_back(array<int, 2> {x, z});
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++)
        cout << dis[i] % 2 << endl;
}

Measured memory_bytes: 10240
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{	
	long long int n,m,i,j,num=0;
	int jude=0;
	
	while (scanf("%lld%lld",&n,&m)!=EOF)
	{
		if (n>=2&&m>=2)
		{
			num=(n-2)*(m-2);
		}
		
		else if (1==n&&1==m)
		{
			num=1;
		}
		
		else if (1==n&&m>=2) 
		{
			num=m-2;
		}
		
		else 
		{
			num=n-2;
		}
		
		printf("%lld",num);
	}
	
	return 0;
 } 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main() {
    IN(ll, n);
    VIN(ll, a, n);
    ll neg = 0;
    ll sum = 0;
    ll minab = INF;
    REP(i, n){
        if (a[i]<0) {
            neg++;
        }
        sum += abs(a[i]);
        minab = min(minab, abs(a[i]));
    }
    if (neg%2==0) {
        COUT(sum);
    }else {
        COUT(sum-2*minab);
    }
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if ((A == B && B != C) || (B == C && C != A) || (C == A && A != B))  cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

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

  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  int ans = 0, i = 0;
  while (i < n) {
    int r = i+1;
    while (r < n && h[r] <= h[r-1]) {
      r++;
    }
    ans = max(ans, r-i-1);
    i = r;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640