akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>

int main(){
	int h1, h2, m1, m2, k;
	int time,ans;
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	time = (h2 * 60 + m2) - (h1 * 60 + m1);
	ans = time - k;

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1732
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	Scanner stdin = new Scanner(System.in);

	while ( stdin.hasNextInt() ) {

	    final int V = stdin.nextInt();
	    final int d = stdin.nextInt();
	    solve( V, d );
	}	
    }

    static void solve( final int V, final int d ) {

	final int[] vs = fibs( V );
	final int[] parents = new int[V];
	final int[] rank = new int[V];
	for ( int i = 0; i < V; i++ ) {
	    parents[i] = i;
	}

	for ( int i = 0; i < V; i++ ) {
	    for ( int j = i + 1; j < V; j++ ) {
		if ( Math.abs( vs[i] - vs[j] ) < d ) {
		    unite( i, j, parents, rank );
		}
	    }
	}
	
	Set<Integer> set = new HashSet<Integer>();
	for ( int i = 0; i < V; i++ ) {
	    final int parent = find( i, parents, rank );
	    if ( !set.contains( parent ) ) {
		set.add( parent );
	    }
	}
	System.out.println( set.size() );	
    }

    static int find( final int x, final int[] parents, final int[] rank ) {
	if ( parents[x] == x ) {
	    return x;
	} else {
	    parents[x] = find( parents[x], parents, rank );
	    return parents[x];
	}
    }
    
    static void unite( int x, int y, final int[] parents, final int[] rank ) {
	final int xp = find( x, parents, rank );
	final int yp = find( y, parents, rank );
	
	if ( xp == yp ) {
	    return;
	}
	
	if ( rank[xp] < rank[yp] ) {
	    parents[xp] = yp;
	} else {
	    parents[yp] = xp;
	    if ( rank[xp] == rank[yp] ) {
		rank[xp]++;
	    }			
	}
    }

    static boolean same( final int x, final int y, final int[] parents, final int[] rank ) {
	return find( x, parents, rank ) == find( y, parents, rank );
    }

    static int[] fibs( final int V ) {

	if ( V == 1 ) {
	    final int[] ar = {2};
	    return ar;
	} else {
	    final int[] vs = new int[V];
	    vs[0] = 2;
	    vs[1] = 3;
	    for ( int i = 2; i < V; i++ ) {
		vs[i] = ( vs[i - 1] + vs[i - 2] ) % 1001;
	    }
	    return vs;
	}
    }
}

Measured memory_bytes: 22096
#include<iostream>
#include<cstdio>
#include<cstdlib>

using namespace std;
//max heap size
#define N 500001

//array
int key[N];
//heap size
int n;
//function parent
int parent(int i){
  return i/2;
}
//function left
int leftc(int i){
  return 2*i;
}
//function right
int rightc(int i){
  return 2*i+1;
}

//function maxHeapify
void maxHeapify(int i){
  int l,r,largest;
  int st;
 
  l=leftc(i);
  r=rightc(i);

  if(l<=n && key[l]>key[i]) largest=l;
  else largest=i;
  
  if(r<=n && key[r]>key[largest]) largest=r;
  
  if(largest!=i){
    st=key[i];
    key[i]=key[largest];
    key[largest]=st;
    maxHeapify(largest);    
  }

}

//function build max heap
void buildMaxHeap(void){
  for(int i=(n/2);i>=1;i--) maxHeapify(i);
}

int main(){
  int data;
  int h;
 
  //load number
  scanf("%d",&n);
  //load data and set key
  for(int i=1;i<=n;i++){
    scanf("%d",&data);
    key[i]=data;
  }
 
  //execute maxheap
  buildMaxHeap();

  //print
  for(int i=1;i<=n;i++){
    printf(" %d",key[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2828
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>

const int MOD_CONST = 2019;

using namespace std;


int main() {
	long long L, R;
	cin >> L >> R;

	bool isEnd = false;
	
	int min = 2019;
	for (int i = L; i < R; i++) {
		for (int j = i+1; j <= R; j++) {
			int m = ((i%MOD_CONST)* (j%MOD_CONST)) % MOD_CONST;
			
			if (min > m) {
				min = m;
			}


			if (min == 0) {
				isEnd = true;
				break;
			}



		}
		if (isEnd) {
			break;
		}

	
	}

	cout << min << endl;

}

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

void ioThings() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("io\\in.txt", "r", stdin);
    freopen("io\\out.txt", "w", stdout);
    freopen("io\\err.txt", "w", stderr);
#endif
}

using   ll        = long long;
#define debug(x)    cerr << #x << ": <" << (x) << ">\n"
#define dotc()      int tcs; if (cin >> tcs) for (int tc = 0; tc < tcs; tc++)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second
#define mod         1000000007

int main() {
    ioThings();

    int n; cin >> n;
    while (n--) {
        int m; cin >> m;
        if (m % 2 == 0 && m % 3 && m % 5) {
            cout << "DENIED";
            return 0;
        }
    }

    cout << "APPROVED";

    return 0;
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0103&lang=jp
//1003ð~XéöxÌâèÍ

#include<iostream>
#include<string>
using namespace std;

int main(void){
     int atotal=0,btotal=0;
     int out=0;
     int n=0;
     bool one=false,two=false,three=false;
     string move="";
     cin >> n;
     for(int i=0;i<n;i++){
	  out = 0;
	  one=false;
	  two=false;
	  three=false;
	  atotal = 0;
	  btotal = 0;
	  do{
	       cin >> move;
	       if(move == "HIT"){
		    bool home;
		    home = three;
		    three = two;
		    two = one;
		    one = true;
		    if(home == true){
			 if(i%2 == 0){
			      atotal++;
			 }else{
			      btotal++;
			 }
		    }
		    // cout << "HIT" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;;
		    // cout << " " << endl;
	       }
	       if(move == "OUT"){
		    out++;
		    // cout << "OUT" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;
		    // cout << " " << endl;
	       }
	       if(move == "HOMERUN"){
		    if(i%2 == 0){
			 int t = 1;
			 if(one == true){
			      one = false;
			      t++;
			 }
			 if(two == true){
			      two = false;
			      t++;
			 }
			 if(three == true){
			      three = false;
			      t++;
			 }
			 atotal = atotal+t;
		    }else{
			  int t = 1;
			 if(one == true){
			      one = false;
			      t++;
			 }
			 if(two == true){
			      two = false;
			      t++;
			 }
			 if(three == true){
			      three = false;
			      t++;
			 }
			 btotal = btotal + t;
		    }
		    // cout << "z[" << endl;
		    // cout << atotal << endl;
		    // cout << btotal << endl;
		    // cout << " " << endl;
	       }
	  }while(out < 3);
	  if(i%2 == 0){
	       cout << atotal << endl;
	  }else{
	       cout << btotal << endl;
	  }
     }
     return 0;
}

Measured memory_bytes: 0
<?php
list($N, $K, $S) = ints();

$array = [];
for($i = 0; $i < $N; $i++){
    if($i < $K){
        $a[] = $S;
    }else{
        if($S < 10**8){
            $a[] = $S*2;
        }else{
            $a[] = $S-1;
        }
    }
}

echo implode(" ", $a);

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 11892
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, k, ans = 0, sum[200001] = {};
const ll mod = 1e9 + 7;

int main() {
	cin >> n >> k;
	rep(i, n) {
		sum[i + 1] = sum[i] + i + 1;
		sum[i + 1] %= mod;
	}
	for (int i = k; i <= n + 1; i++) {
		ans += ((mod + sum[n] - sum[max((ll)0, n - i)]) % mod + mod - sum[i - 1] + 1) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5164
#include <iostream>
#include <cstdio>
#include <queue>
#define long long long
using namespace std;
priority_queue< int,vector<int>,greater<int> > second;
priority_queue< int,vector<int>,less<int> > first;
long a[1000000],b[1000000],q[1000000],n,kq,e,fi=0,se=0,k=0,l=0;
void readdata()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>e;
        q[i]=e;
        if (e==1)
        {
            cin>>a[i]>>b[i];
        }
    }
}

void update(int a,int b)
{
    kq+=b;
    if ((fi>0)&&(first.top()>a))
    {
        first.push(a);
        fi++;
        k+=a;
    }
    else
    {
        if ((se>0)&&(second.top()<a))
        {
            second.push(a);
            se++;
            l+=a;
        }
        else
        {
            first.push(a);
            fi++;
            k+=a;
        }
    }
    long e;
    if (fi>se+1)
    {
        e=first.top();
        second.push(e);
        fi--;
        k-=e;
        l+=e;
        se++;
        first.pop();
    }
    if (se>fi+1)
    {
        e=second.top();
        first.push(e);
        se--;
        fi++;
        k+=e;
        l-=e;
        second.pop();
    }
}

void result()
{
    int x;
    if (fi>=se) x=first.top();
    else x=second.top();
    cout<<x<<" "<<x*fi-k+l-x*se+kq<<"\n";
}

void solve()
{
    for (int i=1;i<=n;i++)
    {
        if (q[i]==1) update(a[i],b[i]);
        if (q[i]==2) result();
    }
}

int main()
{
//    freopen("a.inp","r",stdin);
//    freopen("a.out","w",stdout);
    readdata();
    solve();
    return 0;
}


Measured memory_bytes: 13180
using System;

namespace AOJ.ALDS
{
    public class BinarySearch
    {
        public static void Main()
        {
            string[] input;

            int n = int.Parse(Console.ReadLine());
            int[] s = new int[n];
            input = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++) { s[i] = int.Parse(input[i]); }

            int q = int.Parse(Console.ReadLine());
            input = Console.ReadLine().Split(' ');
            int found = 0;
            for (int i = 0; i < q; i++)
            {
                // 検索対象の数字
                int search = int.Parse(input[i]);

                // バイナリサーチ
                int left = 0;
                int right = n;
                while (left < right)
                {
                    int mid = (left + right) / 2;
                    if (s[mid] == search)
                    {
                        found++;
                        break;
                    }

                    // s[mid]がsearchより小さい→右側を検索
                    // そうでない場合は左側を検索
                    if (s[mid] < search) { left = mid + 1; }
                    else { right = mid; }
                }
            }
            Console.WriteLine(found);
        }
    }
}

Measured memory_bytes: 16580
import java.util.Scanner;

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

    int N =scanner.nextInt();
    char[] A = scanner.next().toCharArray();
    char[] B = scanner.next().toCharArray();
    char[] C = scanner.next().toCharArray();
    int res = 0;
    for (int i = 0; i < N; i++) res += numMinOp(A[i], B[i], C[i]);
    System.out.println(res);
  }

  private static int numMinOp(char a, char b, char c) {
    if (a == b && b == c) return 0;
    if (a == b || b == c || a == c) return 1;
    return 2;
  }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define F first
#define S second
#define sz(x) (int)x.size()
#define db(x) cerr << #x << ": " << x << "\n";

struct qu{
    int a,b,c,d;
};

int N, M, Q;
vector<qu> A;
int V[10];

int solve(int ind) {
    if(ind == N) {
        int sc = 0;
        for(qu & x : A) {
            if(V[x.b-1]-V[x.a-1] == x.c) sc += x.d;
        }
        return sc;
    } else {
        int mx = 0;
        for(int i=(ind==0?1:V[ind-1]); i<=M; i++) {
            V[ind] = i;
            mx = max(mx, solve(ind+1));
        }
        return mx;
    }
}

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

    cin >> N >> M >> Q;
    A.resize(Q);
    for(qu & x : A) cin >> x.a >> x.b >> x.c >> x.d;
    cout << solve(0) << '\n';
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1}; //^<v>
//const int di[] = {-1,0,1,-1,1,-1,0,1}, dj[] = {-1,-1,-1,0,0,1,1,1};



int main() {
  int n;
  scanf("%d",&n);
  vvi d(n,vi(n));
  rep(i,n)rep(j,n) {
    d[i][j] = i;
    mins(d[i][j], j);
    mins(d[i][j], n-1-i);
    mins(d[i][j], n-1-j);
  }
  vvi a(n,vi(n,1));

  int ans = 0;
  rep(ni,n*n) {
    int num;
    scanf("%d",&num);
    --num;
    int i = num/n, j = num%n;
    ans += d[i][j];
    a[i][j]--;
    queue<P> q;
    q.emplace(i,j);
    while (sz(q)) {
      i = q.front().fi;
      j = q.front().se;
      q.pop();
      int nd = d[i][j]+a[i][j];
      rep(v,4) {
        int ni = i+di[v], nj = j+dj[v];
        if (ni<0||nj<0||ni>=n||nj>=n) continue;
        if (d[ni][nj] <= nd) continue;
        d[ni][nj] = nd;
        q.emplace(ni,nj);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 5644
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]);
			b[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		long ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			long c = (a[i] + ans) % b[i];
			if (c > 0) {
				ans += b[i] - c;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 49344
program atc
  implicit none
  character :: B
  read(*,*) B
  if(B.eq.'T') then
     write(*,'(a)') 'A'
  elseif(B.eq.'A') then
     write(*,'(a)') 'T'
  elseif(B.eq.'G') then
     write(*,'(a)') 'C'
  elseif(B.eq.'C') then
     write(*,'(a)') 'G'
  endif



end program



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

int main() {
    ll k,a,b,ans=1,yen=0;
    cin>>k>>a>>b;
    if(b-a<2){
        ans=ans+k;
    }
    else{
        while(k){
            if(yen==0){
                if(ans<a)
                    while(ans<a&&k)ans++,k--;
                if(ans>=a&&k>1)ans-=a,yen++,k--;
                else if(k==1)ans++,k--;

            }
            while(yen&&k){
                ans+=b;yen--;k--;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut a: Vec<u64> = (0..n).map(|_| read()).collect();
    let b: Vec<u64> = (0..n).map(|_| read()).collect();
    let mut c: Vec<u64> = (0..n).map(|_| read()).collect();

    a.sort();
    c.sort();

    let mut count = 0;
    for b_i in b {
        count += a.lower_bound(&b_i) * (n - c.lower_bound(&(b_i + 1)));
    }

    println!("{}", count);
}

trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = low + (high - low) / 2;
            match self[mid].cmp(x) {
                std::cmp::Ordering::Less => low = mid + 1,
                _ => high = mid,
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();
        while low != high {
            let mid = low + (high - low) / 2;
            match self[mid].cmp(x) {
                std::cmp::Ordering::Greater => high = mid,
                _ => low = mid + 1,
            }
        }
        high
    }
}

#[test]
fn test_binary_search() {
    let vec = vec![1, 2, 4, 6, 7, 12, 54, 60];

    assert_eq!(vec.lower_bound(&4), 2);
    assert_eq!(vec.upper_bound(&1000), vec.len());
}

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


Measured memory_bytes: 8444
package main

import (
    "fmt"
    "math"
)

func main() {
    var N, T int
    fmt.Scan(&N, &T)

    var ansC = math.MaxInt32
    var ansT = math.MaxInt32

    for i := 0; i < N; i++ {
        var c, t int
        fmt.Scan(&c, &t)
        if t <= T && c < ansC {
            ansC = c
            ansT = t
        }
    }
    if ansT > T {
        fmt.Println("TLE")
    } else {
        fmt.Println(ansC)
    }
}


Measured memory_bytes: 512
from collections import deque
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SA = [0]
for i in range(N):
  temp = SA[-1] + A[i]
  SA.append(temp)

SB = [0]
for j in range(M):
  temp = SB[-1] + B[j]
  SB.append(temp)
ans = 0
for i in range(N+1):
  an = i
  if SA[i] > K:
    break
  else:
    nokori = K -SA[i]
    if nokori >= SB[-1]:
      bn = M
    else:
      ok = 0
      ng = M
      while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        if nokori >= SB[mid]:
          ok = mid
        else:
          ng = mid
      bn = ok
  #print(an,bn)
  ans = max(ans,an+bn)
print(ans)
        
      

Measured memory_bytes: 47712
#include <stdio.h>
int main()
{
    int i,count=0;
    char s1[4],s2[4];
    scanf("%s",s1);
    scanf("%s",s2);
    for(i=0;i<3;i++)
    {
        if(s1[i]==s2[i])count++;
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 1728
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <stack>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
//#include <unordered_set>
#define INF 2147483647
#define MAXN  1000100
#define PII pair<int, int>
#define mp(a,b) make_pair(a,b)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 35;
int f[1000];

int main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(0);
#ifdef local_debug
	ifstream inputs("input.txt");
	cin.rdbuf(inputs.rdbuf());
	freopen("input.txt", "r", stdin);
#endif
	ll n,m;
	while (cin >> n >> m) {
		cout << abs((n - 2)*(m - 2)) << endl;
	}
	return 0;
}

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

int32_t main()
{
     string s;
     cin >> s;
     int k;
     cin >> k;
     int r = 0;
     int res = 1;
     for(int i = 0; s[i]; i++){
          if(s[i]=='1'){
               r= i+1;
          }
          else{
               res = s[i] - '0';
               break;
          }
     }
     if(r>=k){
          cout << 1 << "\n";
     }
     else{
          cout << res << "\n";
     }

     return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 1e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    int n;
    cin >> n;
    vector<ll> v(n+1);
    for(int j = 1; j <= n; j++) cin >> v[j];
    vector< vector<ll> > dp(n+1, vector<ll>(n+1, INF));
    
    for(int r = 1; r <= n; r ++){
        for(int l = r; l > 0; l--){
            if(l == r){
                dp[l][r] = 0;
                continue;
            }
            ll sum = 0;
            for(int i = l; i <= r; i++) sum += v[i];
            for(int i = l; i < r; i++) dp[l][r] = min(dp[l][r], sum + dp[l][i] + dp[i+1][r]);
        }
    }
    cout << dp[1][n];
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll K;
    cin >> K;
    vec A(K);
    loop(i, K) cin >> A[i];
    vec L(K + 1), R(K + 1);
    L[K] = 2;
    R[K] = 2;
    for (ll i = K - 1; i >= 0; i--)
    {
        L[i] = ((L[i + 1] + (A[i] - 1)) / A[i]) * A[i];
        if (L[i] > R[i + 1])
        {
            putout(-1);
            return 0;
        }
        R[i] = (R[i + 1] / A[i]) * A[i] + (A[i] - 1);
    }
    cout << L[0] << " " << R[0] << endl;
    return 0;
}


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,k,pos=0;
int a[200005],visited[200005],cnt[200005];

signed main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=n;i++)  visited[a[i]]++;
	for (int i=1;i<=n;i++)
	{
		if (visited[i]>0)  cnt[++pos]=visited[i];
	}
	sort(cnt+1,cnt+pos+1);
	
	if (pos<=k)  cout<<0<<endl;
	else
	{
		int ans=0;
		for (int i=1;i<=pos-k;i++)  ans+=cnt[i];
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

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

  const double pi = acos(-1);
  double a, b, x;
  cin >> a >> b >> x;
  x /= a;
  x *= 2;
  double l = 0, r = pi / 2;
  auto check = [&](double kek) {
    kek = pi / 2 - kek;
    if (kek <= atan(a * a / x)) {
      return sqrt(x / tan(kek)) <= b;
    } else {
      auto z = a / tan(kek);
      auto y = (x - a * z) / 2 / a;
      return z + y <= b;
    }
  };
  while (l + 1e-8 < r) {
    double m = (l + r) / 2;
    if (check(m)) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << fixed << setprecision(10) << l * 180 / pi;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    int W, H, x, y, r;
   cin >> W >> H >> x >> y >> r;
   if((x >= r && x <= W-r) && (y >= r && y <= H-r))
		cout << "Yes" << endl;
	else{
		cout << "No" << endl;
	}
   
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

vector<bool> IsPrime;
vector<int> primes;

void sieve(int max) {
    IsPrime.resize(max + 1, true);
    IsPrime[0] = IsPrime[1] = false;
    for (int i = 2; i * i <= max; ++i){
        if (IsPrime[i]){
            for (int j = i * i; j <= max; j += i) IsPrime[j] = false;
        }
    }
    for(int i = 0; i <= max; ++i)if(IsPrime[i])primes.push_back(i);
}

int n, m, s, t;
vector<vector<int> > g;
vector<int> dmin[2];

int bfs(){
    for(int i=0;i<2;i++) dmin[i].resize(n,IINF);
    dmin[0][s] = 0;
    queue<P> que;
    que.push({0,s});
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int b = p.first, cur = p.second;
        for(auto nxt : g[cur]){
            if(dmin[b^1][nxt] > dmin[b][cur]+1){
                dmin[b^1][nxt] = dmin[b][cur] + 1;
                que.push({b^1, nxt});
            }
        }
    }
    
    int res = IINF;
    if(dmin[0][t]==2) res = 2;
    else if (dmin[1][t] < IINF) res = *lower_bound(primes.begin(), primes.end(), max(3,dmin[1][t]));
    return res;
}

int main() {
    sieve(1e6);
    cin >> n >> m >> s >> t;
    s--; t--;
    g.resize(n);
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ans = bfs();
    cout << (ans < IINF ? ans : -1) << endl;
    return 0;
}



Measured memory_bytes: 9548
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 100000;

#define MAX 100010

signed main() {
	int n, m; cin >> n >> m;
	int s[MAX] = {};
	rep(i, 0, n - 1) {
		cin >> s[i];
	}
	int cnt[MAX] = {};
	int cur = 0;
	rep(i, 0, m) {
		int ai; cin >> ai;
		if (ai >= 0) {
			cnt[cur]++;
			cnt[cur + ai]--;
		}
		else {
			cnt[cur]--;
			cnt[cur + ai]++;
		}
		cur += ai;
	}
	int ans = 0;
	rep(i, 1, n - 1) {
		cnt[i] += cnt[i - 1];
	}
	rep(i, 0, n - 1) {
		ans += cnt[i] * s[i];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3916
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#define mod 1000000007
using namespace std;
int main(){
    int n,p[20],ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&p[i]);
    }
    for(int i=1;i<n-1;i++){
        if(p[i]==p[i-1]||p[i]==p[i+1]||(p[i]>p[i-1]&&p[i]<p[i+1])||(p[i]<p[i-1]&&p[i]>p[i+1])){
            ans++;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
S = []
for _ in range(H):
    s = input()
    S.append(s)

# 上下左右に移動できるところは移動する
# 移動してもたどり着けない場合はワープをそれぞれのますで実行し、まだ到達していない箇所にいく
# これを繰り返す

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

wx = [-2, -1, 0, 1, 2]
wy = [-2, -1, 0, 1, 2]
dp = [[-1] * W for _ in range(H)]
dp[Ch - 1][Cw - 1] = 0


def bfs(x, y, cost, dp, d):
    while len(d) > 0:
        p = d.popleft()
        dw.append(p)
        for i in range(4):
            if p[0] + dx[i] >= 0 and p[0] + dx[i] < W and p[1] + \
                    dy[i] >= 0 and p[1] + dy[i] < H:
                if S[p[1] + dy[i]][p[0] + dx[i]
                                   ] == '.' and dp[p[1] + dy[i]][p[0] + dx[i]] == -1:
                    d.append([p[0] + dx[i], p[1] + dy[i]])
                    dw.append([p[0] + dx[i], p[1] + dy[i]])
                    dp[p[1] + dy[i]][p[0] + dx[i]] = cost

    return cost, dp


ds = deque()
ds.append([Cw - 1, Ch - 1])
c = 0
while True:
    dw = deque()
    cost, dp = bfs(Cw - 1, Ch - 1, c, dp, ds)
    check = False
    while len(dw) > 0:
        p = dw.popleft()
        for m in range(5):
            for n in range(5):
                if p[0] + wx[m] >= 0 and p[0] + wx[m] < W and p[1] + \
                        wy[n] >= 0 and p[1] + wy[n] < H:
                    if S[p[1] + wy[n]][p[0] + wx[m]
                                       ] == '.' and dp[p[1] + wy[n]][p[0] + wx[m]] == -1:
                        ds.append([p[0] + wx[m], p[1] + wy[n]])
                        dp[p[1] + wy[n]][p[0] + wx[m]] = cost + 1
                        check = True
    if check:
        c += 1
    else:
        break

print(dp[Dh - 1][Dw - 1])


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

int main(){
    int n; bool can = false;
    cin >> n;
    int a[n+1];
    for(int i = 1; i <= n; i++) cin >> a[i];
    int j = 1,k = 0;
    while(k <= n){
        if(j == 2){ can = true; break; }
        j = a[j];k++;
    }
    if(can) cout << k << endl;
    else    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())


def ok():
    x = 0
    while x * 4 <= N:
        if (N - x * 4) % 7 == 0:
            return True
        x += 1
    return False

print("Yes" if ok() else "No")


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

int main()
{
 long H,W;
 cin>>H>>W;
 if(H==1||W==1){cout<<1<<endl;}
  else if((H*W)%2==0){cout<<H*W/2<<endl;}
else{cout<<H*W/2+1<<endl;}
}


Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((int)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;



int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>str;
    if(str[str.size()-1]=='s')
       str+="es";
    else str+='s';
cout<<str<<endl;

    //code
    return 0;
}




Measured memory_bytes: 50544
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  string S;
  cin >> S;
  int N = S.size();
  string ans = "AC";
  if (S[0] != 'A') {
    ans = "WA";
  }
  int count = 0;
  for (int i = 1; i < N; i++) {
    if (isupper(S[i])) {
      if (i == 1 || i == N-1 || S[i] != 'C') {
        ans = "WA";
      }
      count++;
    }
  }
  if (count != 1) {
    ans = "WA";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/arc073/editorial.pdf
　　　https://ei1333.hateblo.jp/entry/2017/05/01/004235
　　　https://atcoder.jp/contests/abc060/submissions/3782609
・公式解
・とりあえず累積和なしでやってみる。
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

N, W = map(int, input().split())
wN = [0] * N
vN = [[] for i in range(4)]
for i in range(N):
    w, v = map(int, input().split())
    if i == 0:
        offset = w
    vN[w-offset].append(v)

# 重さ毎のリストを降順ソート
for i in range(4):
    # 空リストのままだとこの後ループを回ってくれないので、[0]を追加する
    vN[i] = [0] + sorted(vN[i], reverse=True)

ans = 0
for i in range(len(vN[0])):
    for j in range(len(vN[1])):
        for k in range(len(vN[2])):
            for l in range(len(vN[3])):
                # 重さリミットを超えるパターンは対象外
                if offset * i + (offset+1) * j + (offset+2) * k + (offset+3) * l > W:
                    continue
                ans = max(sum(vN[0][:i+1]) + sum(vN[1][:j+1]) + sum(vN[2][:k+1])+ sum(vN[3][:l+1]), ans)
print(ans)


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

ll h1, m1, h2, m2, k;
int main(int argc, char **argv)
{
	cin >> h1 >> m1 >> h2 >> m2 >>k;
	ll s = h1*60 + m1;
	ll e = h2*60 + m2;
	ll t = e - s;
	std::cout << max(0ll, t - k)<< std::endl;
}


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

signed main () {
	int n, a, b, cnt = 1, ans = 0;
	cin >> n >> a;
	for (int i = 0; i < n - 1; ++i){
		cin >> b;
		if (b == a) 
			++cnt;
		else {
			ans += cnt / 2;
			cnt = 1;
		}
		a = b;
	}
	ans += cnt / 2;
	cout << ans << '\n';
}


Measured memory_bytes: 3596
n, l = map(int, input().split())

tastes = [l+x for x in range(n)]

taste_abs_min = 300

for i in range(n):
    if abs(tastes[i]) < abs(taste_abs_min):
        taste_abs_min = tastes[i]

print(sum(tastes) - taste_abs_min)

Measured memory_bytes: 2940
S = input()
List = list(S)
ans = 1
h = 0
ii = 0

for i in range(len(List)):
  a = List[i]
  if a == "h":
    h = 1
    ii = 0
  elif h == 1 and a == "i":
    h = 0
    ii = 1
  else:
    ans = 0

if ans == 1 and ii == 1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n, k;
    cin >> n >> k;
    int x = 0;
    int ans = 0;
    char before = '.';
    for (int i = 0; i < n; i++)
    {
        char now;
        cin >> now;
        if (before == now)
        {
            ans++;
        }
        else
        {
            x++;
        }
        before = now;
    }
    for (int i = 0; i < k; i++)
    {
        if (x > 2)
        {
            x -= 2;
            ans += 2;
        }
        else if (x > 1)
        {
            x -= 1;
            ans += 1;
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

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

using namespace std;

const int maxn=1<<25;

int main()
{
	int n,m;
	cin>>n>>m;
		for(int i=m/n;i>0;i--){
			if(m%i==0){
				cout<<i;
				break;
			}
		}
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200010
using namespace std;
int n;
int fa[maxn];//并查集：维护连通块
map<int,int> pos;
int tot;//离散化QWQ 2^30，太真实了
int a[maxn], b[maxn], c[maxn], d[maxn];
int ans;
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
inline bool check()
{
    sort(c + 1, c + n + 1);
    sort(d + 1, d + n + 1);
    for (register int i = 1; i <= n; i++)
        if (c[i] != d[i])
            return 0;
    return 1;
}
int main()
{
    // freopen("duliu.in","r",stdin);
    // freopen("duliu.out","w",stdout);
    scanf("%d", &n);
    register int i;
    int tmp = 0;
    for (i = 1; i <= n; i++) scanf("%d", &a[i]), tmp ^= a[i];
    a[n + 1] = tmp;
    tmp = 0;
    for (i = 1; i <= n; i++) scanf("%d", &b[i]), tmp ^= b[i];
    b[++n] = tmp;
    memcpy(c, a, sizeof a);
    memcpy(d, b, sizeof b);
    if (!check()) {
        puts("-1");
        return 0;
    }
    for (i = 1; i <= n; i++) {
        if (a[i] != b[i] || i == n) {
            if(i < n) ans++;
            if (!pos[a[i]]) pos[a[i]] = ++tot;
            if (!pos[b[i]]) pos[b[i]] = ++tot;
        }
    }
    for (i = 1; i <= tot; i++) fa[i] = i;
    if(!ans) {//没有建任何边（a == b
        puts("0");
        return 0;
    }
    for (i = 1; i <= n; i++) if (a[i] != b[i]) fa[find(pos[a[i]])] = find(pos[b[i]]);
    for (i = 1; i <= tot; i++) if (fa[i] == i) ans++;
    printf("%d\n", ans - 1);
    return 0;
}

Measured memory_bytes: 7680
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N = int(input())
answer = 0
len_div = len(make_divisors(N))
# print(make_divisors(N))
# print(make_divisors(N))
# print(make_divisors(N))
# print(len(make_divisors(N)))
# print(make_divisors(N)[len_div // 2])

if len_div % 2 == 0:
    A_len = len(str(make_divisors(N)[len_div // 2 - 1]))
    B_len = len(str(make_divisors(N)[len_div // 2]))
    if A_len <= B_len:
        answer = B_len
    else:
        answer = A_len
else:
    answer = len(str(make_divisors(N)[len_div // 2]))
    # print(make_divisors(N)[len_div // 2])
print(answer)



Measured memory_bytes: 3064
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1188811#1

#include <iostream>
#include <string>

using namespace std;

// 何文字共通しているかの計算
int minStepSize(string s1, string s2)
{
    s1 = " " + s1;
    s2 = " " + s2;
    int rows = s1.size();
    int cols = s2.size();
    int map[rows][cols] = {};

    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            if (i == 0)
            {
                map[0][j] = j;
                continue;
            }
            else if (j == 0)
            {
                map[i][0] = i;
                continue;
            }

            if (s1[i] == s2[j])
            {
                map[i][j] = min(map[i - 1][j] + 1, min(map[i][j - 1] + 1, map[i - 1][j - 1]));
            }
            else
            {
                map[i][j] = min(map[i - 1][j] + 1, min(map[i][j - 1] + 1, map[i - 1][j - 1] + 1));
            }
        }
    }

    // for (int i = 0; i < rows; i++)
    // {
    //     for (int j = 0; j < cols; j++)
    //     {
    //         printf("map[%d][%d] = %d\n", i, j, map[i][j]);
    //     }
    // }
    // printf("map.cols() = %d\nmap.rows() = %d\n", rows, cols);
    return map[rows - 1][cols - 1];
}

int sameSizeString(string s1, string s2)
{
    int ans = 0;
    for (int i = 0; i < s1.size(); i++)
    {
        if (s1[i] == s2[i])
        {
            ans++;
        }
    }
    return ans;
}

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    int common = minStepSize(s1, s2);

    cout << common << endl;
}


Measured memory_bytes: 7156
n = gets.to_i
s = gets.chomp
e = (s[0] == 'E' ? [1] : [0])
w = (s[0] == 'W' ? [1] : [0])

1.upto(n - 1) do |i|
  if (s[i] == 'E')
    e[i] = e[i - 1] + 1
    w[i] = w[i - 1]
  else
    e[i] = e[i - 1]
    w[i] = w[i - 1] + 1
  end
end
w.unshift(0)
min = Float::INFINITY
0.upto(n - 1) do |i|
  min = (e[-1] - e[i] + w[i] - w[0]).abs if min > (e[-1] - e[i] + w[i] - w[0]).abs
end
puts min

Measured memory_bytes: 7812
a = input()

for i in range(len(a)):
  if 'A' in a[i]:
    b = i
    break

for i in range(len(a)):
  if i != 0 and 'Z' in a[-i]:
    c = i
    break
      
d = len(a) - c + 1
#print(b,c)
print(len(a[b:d]))

Measured memory_bytes: 3516
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}
#[test]
fn test_split() {
    let s = "WWWWBBBB";
    assert_eq!(
        s.split('W').filter(|s| s.len() > 0).collect::<Vec<_>>(),
        vec!["BBBB"]
    )
}

fn main() {
    let s = scan!();
    let b: Vec<_> = s.split('W').filter(|s| !s.is_empty()).collect();
    let w: Vec<_> = s.split('B').filter(|s| !s.is_empty()).collect();

    println!(
        "{}",
        min(
            if s.chars().nth(0).unwrap() == 'W' && s.chars().nth(s.len() - 1).unwrap() == 'W' {
                2 * b.len()
            } else {
                2 * b.len() - 1
            },
            if s.chars().nth(0).unwrap() == 'B' && s.chars().nth(s.len() - 1).unwrap() == 'B' {
                2 * w.len()
            } else {
                2 * w.len() - 1
            },
        )
    )
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a == 5 && b == 5 && c == 7)
    cout << "YES" << endl;
  else if(a == 5 && b == 7 && c == 5)
    cout << "YES" << endl;
  else if(a == 7 && b == 5 && c == 5)
    cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < int(B); ++I)


ll cut_two(ll h,ll w){
	if(h%2==0) return (h/2)*w;
	if(w%2==0) return (w/2)*h;
	return (max(h,w)/2)*min(h,w); 
}


int main(){
	ll H,W;
	cin >> H >> W;
	ll ans = 100000000999;
	FOR(j,0,2){
		FOR(i,0,H){
			ll s1,s2,s3;
			s1 = i * W;
			s2 = cut_two((H-i),W);
			s3 = (H-i)*W - s2;
			ans = min(ans, max({s1,s2,s3}) - min({s1,s2,s3}) );
		}
		swap(H,W);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
a,b=[int(i) for i in input().split()]
s=input()
num=[str(i) for i in range(10)]
result=False
for i in range(len(s)):
    if i==a:
        if s[i]!="-":
            result=True
    else:
        if (s[i] in num)==False:
            result=True
print("No" if result else "Yes")

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

ll solve(int n, string s) {
  int res = 0;
  for(int i=0;i<n-1;i++) {
    set<char> l;
    set<char> r;
    for(int j=0;j<=i;j++) {
      l.insert(s[j]);
    }
    for(int j=i+1;j<n;j++) {
      r.insert(s[j]);
    }
    set<char> lr;
    set_intersection(l.begin(), l.end(), r.begin(), r.end(), inserter(lr, lr.end()));
    /*
    for(auto x: lr) {
      cout << x << " ";
    }
    cout << endl;
    */
    res = max(res, (int) lr.size());
  }
  return res;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  cout << solve(n, s);
}

Measured memory_bytes: 3632
#include<stdio.h>
int main()
{
int a,b,c,d,e;//a??????????????\?????????b????§????c?????????d?????????
scanf("%d",&a);
b=a%60;
e=a/60;
c=e%60;
d=e/60;
printf("%d:%d:%d\n",d,c,b);
return 0;
}

Measured memory_bytes: 2684
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

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

    string ans = "";
    int c1[26], c2[26] = {0};
    fill_n(c1, 26, 100);

    for(int i = 0; i < n; i++){
        cin >> s;
        for(int j = 0; j < s.size(); j++){
            char cj = s[j];
            c2[cj-'a']++;
        }

        for(int j = 0; j < 26; j++){
            c1[j] = min(c1[j], c2[j]);
            c2[j] = 0;
        }
    }

    for(int j = 0; j < 26; j++){
        char c = 'a' + j;
        for(int k = 0; k < c1[j]; k++){
            ans += c;
        }
    }

    cout << (ans != "" ? ans : " ") << endl;
    return 0;
}

Measured memory_bytes: 3584