akhauriyash/Code-Regression huggingface dataset:
S = [input() for i in range(3)]

D = {"a": 0, "b": 1, "c": 2}
ANS = ["A", "B", "C"]

st = [0] * 3
turn = 0
while st[turn] != len(S[turn]):
    st[turn], turn = st[turn]+1, D[S[turn][st[turn]]]

print(ANS[turn])

Measured memory_bytes: 38256
import math
A, B, H, M = map(float, input().split())
a = (H * 60 + M) / 2
b = M * 6
c = abs(a-b)
c = c if c <= 180 else 360 - c
cc = (A**2 + B**2 - 2*A*B * math.cos(math.radians(c))) ** 0.5
print(cc)

Measured memory_bytes: 9508
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

using std::string;
using std::vector;
using std::map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  string s{}, t{}; cin >> s >> t;

  size_t begin{}, last{};
  ull ans{};
  {
    auto it = s.find(t[0], begin);
    if(it == s.npos)
    {
      cout << -1 << CRLF;
      return;
    }
    last = (it + 1) % s.size();
    ans += it + 1;
  }
  string str{s + s};
  for(size_t index = 1; index < t.size(); ++index)
  {
    auto it = str.find(t[index], last);
    if(it == str.npos)
    {
      cout << -1 << CRLF;
      return;
    }
    ans += it - last + 1;
    last = (it + 1) % s.size();
  }

  cout << ans << CRLF;

  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 720
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

type coin struct{ v, w int }

func parseProblem() int {
	n, m := scanInt(sc), scanInt(sc)
	coins := make([]coin, m)
	for i := 0; i < m; i++ {
		coins[i] = coin{
			v: scanInt(sc),
			w: 1,
		}
	}
	dp := make([]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = math.MaxInt32
	}
	dp[0] = 0
	for i := 1; i <= m; i++ {
		for v := 0; v <= n; v++ {
			it := coins[i-1]
			cv := v - it.v
			if cv >= 0 {
				cw := dp[cv] + it.w
				if dp[v] > cw {
					dp[v] = cw
				}
			}
		}
	}
	return dp[n]
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 1528
import java.util.*;

class Main{

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

		int K = sc.nextInt();

		if(K%2 == 0)
		System.out.println((K/2)*(K/2));
		else
		System.out.println(((K/2) + 1) *(K/2));

	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	vector<int> dp(n+2,1000000000);
	dp.at(0)=0;
	rep(i,n-1){
		dp.at(i+1)=min(dp.at(i+1),dp.at(i)+abs(a.at(i)-a.at(i+1)));
		if(i+2<n) dp.at(i+2)=min(dp.at(i+2),dp.at(i)+abs(a.at(i)-a.at(i+2)));
	}
	cout << dp.at(n-1) << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}

static const long long MOD_NUM = 1000000007LL;

static void A_task();

int main()
{
	A_task();
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int A, B;
	get2int(A, B);

	int ans = 1;
	if (A + B == 3) {
		ans = 3;
	}
	else if (A + B == 4) {
		ans = 2;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;

namespace Heaps
{
    class Priority_Queue
    {
        class PriorityQueue
        {
            List<int> buf;

            public PriorityQueue()
            {
                buf = new List<int>();
            }

            public void Push(int elem)
            {
                var n = buf.Count;
                buf.Add(elem);

                while (n != 0)
                {
                    var i = (n - 1) / 2;
                    if (buf[n] > buf[i])
                    {
                        var tmp = buf[n];
                        buf[n] = buf[i];
                        buf[i] = tmp;
                    }
                    n = i;
                }
            }

            public int Pop()
            {
                var top = buf[0];
                var n = buf.Count - 1;
                buf[0] = buf[n];
                buf.RemoveAt(buf.Count - 1);

                for (int i = 0, j; (j = 2 * i + 1) < n;)
                {
                    if ((j != n - 1) && (buf[j] < buf[j + 1]))
                        j++;
                    if (buf[i] < buf[j])
                    {
                        var tmp = buf[j];
                        buf[j] = buf[i];
                        buf[i] = tmp;
                    }
                    i = j;
                }
                return top;
            }

        }

        static void Main(string[] args)
        {
            var pq = new PriorityQueue();

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string line;
            while ((line = Console.ReadLine()) != "end")
                switch (line[0])
                {
                    case 'i':
                        pq.Push(int.Parse(line.Substring(7)));
                        break;
                    case 'e':
                        Console.WriteLine(pq.Pop());
                        break;
                }
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 19888
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    string s; cin >> s;
    string a;
    a += s[0]; a += s[1];
    string b;
    b += s[2]; b += s[3];
    //cout << a << " " << stoi(b) << endl;
    if (s == "0000") cout << "NA" << endl;
    else if (a == "00") {
        if (stoi(b) <= 12) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
    else if (b == "00") {
        if (stoi(a) <= 12) cout << "MMYY" << endl;
        else cout << "NA" << endl;
    }
    else if (stoi(a) > 12 && stoi(b) > 12) cout << "NA" << endl;
    else if (stoi(a) > 12) cout << "YYMM" << endl;
    else if (stoi(b) > 12) cout << "MMYY" << endl;
    else cout << "AMBIGUOUS" << endl;
}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner in=new Scanner(System.in);
        while(in.hasNext()){
        
        int n,i,j,k,l,a,b;
        //a=(n/4)+2;
        

    n=in.nextInt();
    int s=0;
    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
                for(k=0;k<10;k++){
                    for(l=0;l<10;l++){
                        if(i+j+k+l==n)s++;
                }
            }
        }
    }
    //cout<<s<<endl;
    System.out.println(s);
    }
    }
}

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

fn power(mut x: i64, mut a: i64, mod_: i64) -> i64 {
    let mut res: i64 = 1;
    while a > 0 {
        if a % 2 == 1 {
            res = res * x % mod_;
        }
        x = x * x % mod_;
        a /= 2;
    }
    res
}

fn ncr(n: usize, r: usize, fact: &Vec<i64>, invf: &Vec<i64>, mod_: i64) -> i64 {
    (fact[n] * invf[r] % mod_) * invf[n - r] % mod_
}

fn main() {
    let mod_ = 10_i64.pow(9) + 7;
    let n: usize = read();
    let m: i64 = read();
    let mut po = m;
    let mut num = 2;
    let mut ans = 1;
    let size = n + 50;
    let mut fact: Vec<i64> = vec![1; size];
    let mut invf: Vec<i64> = vec![1; size];
    for i in 2..size {
        fact[i] = i as i64 * fact[i - 1] % mod_;
        invf[i] = power(fact[i], mod_ - 2, mod_);
    }
    while po > 1 {
        if po % num == 0 {
            let mut cnt: usize = 0;
            while po % num == 0 {
                po /= num;
                cnt += 1;
            }
            ans *= ncr(cnt + n - 1, cnt, &fact, &invf, mod_);
            ans %= mod_;
        }
        num += 1;
    }
    println!("{}", ans);
}

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


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

int main() {
  int N;                 
  cin >> N;             //良い整数候補生

  int count, n3, n2, n1, n0;

  n3 = N / 1000;
  n2 = (N - n3 * 1000) / 100;
  n1 = (N - n3 * 1000 - n2 * 100) / 10;
  n0 = N % 10;

 if(n2 != n1)                                   //10の位と100の位が等しくなければ3連続同値は不可能
    cout << "No" << endl;
 else{
    if(n1 == n0 || n2 == n3)      //1の位または1000の位が隣り合う位に等しければおk
      cout << "Yes" << endl;
    else
      cout << "No"  << endl;
 }
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let mut s = std::collections::HashSet::new();
    let n: usize = sc.cin();
    for _ in 0..n {
        let a: i64 = sc.cin();
        if s.contains(&a) {
            s.remove(&a);
        } else {
            s.insert(a);
        }
    }
    put!(s.len());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 8444
import java.util.*;
 
public class Main {
    public static void main(String[] args){
      
      Scanner scan = new Scanner(System.in);
   	  int n = scan.nextInt();
      scan.nextLine();

      ArrayList<Integer> listP = new ArrayList<Integer>();
      ArrayList<Integer> listQ = new ArrayList<Integer>();
      int op=0;
      int oq=0;
      int i = 1;
      while(i<=n){
        listP.add(i);
        listQ.add(i);
        i++;
      }
      
      
      i=1;
      
      while(i<n){
        int p = scan.nextInt();
        int od = listP.indexOf(p) + 1;
        listP.remove(od-1);
        op += (od-1)*fact(n-i);
        i++;
      }
      op++;
      scan.nextLine();
      i=1;
      
      while(i<n){
        int q = scan.nextInt();
        int od = listQ.indexOf(q) + 1;
        listQ.remove(od-1);
        oq += (od-1)*fact(n-i);
        i++;
      }
      oq++;
      
      System.out.println(Math.abs(op-oq));
      
      return;
 
    }
  
  public static int fact(int k){
    if(k<=1){
      return 1;
    } else {
      return k*fact(k-1);
    }
  }
}


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

signed main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	int dp[n+1][n+1];
	int arr[n+1];int prefix[n+1];
	arr[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		dp[i][i]=0;
		dp[i-1][i]=arr[i-1]+arr[i];
	}
	partial_sum(arr,arr+1+n,prefix);
	for(int i=n;i>=1;i--)
	{
		for(int j=i+2;j<=n;j++)
		{
			dp[i][j]=LLONG_MAX;
			for(int k=i;k<j;k++)
			{
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+prefix[j]-prefix[i-1]);
			}
		}
	}
	cout<<dp[1][n]<<endl;
return 0;
}

Measured memory_bytes: 1536
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64 i:i64));
    (n - i + 1).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "4 2" => "3",
    test2: "1 1" => "1",
    test3: "15 11" => "5",
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define SZ(x) ((int)(x).size())
typedef long long ll;

typedef long double ld;
using namespace std;


int main() {
    ll r;
    cin>>r;
    ll S;
    S=3*r*r;

    cout<<S<<endl;
}
 

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App  {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val k = sc.nextInt
  val x = sc.nextInt
  val y = sc.nextInt

  val res =
    if(n <= k) x * n
    else x * k + (n - k) * y

  println(res)

}


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

bool possible(int a) {
    return (a > 1) && ((a % 3) == 0);
}
int main(void) {
    int A,B;
    cin >> A >> B;

    if(possible(A) || possible(B) || possible(A+B) ) {
        cout << "Possible\n";
    } else {
        cout << "Impossible\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
long long ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b);
		if(a&&b)--b,++ans;
		a=b&1;
		ans=ans+(b>>1);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;
vector<int> S[MAX],dis(MAX);
int N;

void BFS(int u){
    
    for(int i=0;i<N;i++){
        dis[i]=INF;
    }
    
    queue<int> Q;
    
    dis[u]=0;
    Q.push(u);
    
    while(!Q.empty()){
        int a=Q.front();
        Q.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(dis[b]!=INF) continue;
            dis[b]=dis[a]+1;
            Q.push(b);
        }
    }
}

int main(){
    
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
    }
    
    BFS(0);
    int maxi=0,s=0;
    
    for(int i=0;i<N;i++){
        if(dis[i]>maxi){
            maxi=dis[i];
            s=i;
        }
    }
    
    BFS(s);
    
    maxi=0;
    
    for(int i=0;i<N;i++){
        if(dis[i]>maxi){
            maxi=dis[i];
        }
    }
    
    if(maxi%3==1) cout<<"Second"<<endl;
    else cout<<"First"<<endl;
}




Measured memory_bytes: 13556
#include <stdio.h>
#define MAX_A 10000
#define MAX_B 500

int main(){

  int n_1,n_2,i,j,sum=0,key,flag;
  int a[MAX_A],b[MAX_B];


  scanf("%d",&n_1);
  for( i=0 ; i<n_1 ; i++ ){
    scanf("%d",&a[i]);
  }

  scanf("%d",&n_2);
  for( i=0 ; i<n_2 ; i++ ){
    scanf("%d",&b[i]);
  }

  for( j=0 ; j<n_2 ; j++ ){
    key = b[j];
    for( i=0 ; i<n_1 ; i++ ){
      if( a[i] == key ) flag = 1;
      else continue;
    }
    if( flag == 1 ){
      sum++;
      flag = 0;
    }
    else continue;
  }
  printf("%d\n",sum);
  return 0;
}

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

import static java.lang.Math.*;

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void execute(CustomReader in) throws IOException {
        int[] nk = in.readLineAsIntArray();
        final int N = nk[0];
        final int K = nk[1];
        int[] A = in.readLineAsIntArray();

        int left = 0;
        int right = 0;
        int i = 0;
        while (i < N && A[i] != 1) {
            left++;
            i++;
        }
        right = N - left - 1;

        int ans = 0;
        ans += left / (K - 1);
        ans += right / (K - 1);

        int m = (left % (K - 1) + right % (K - 1));
        if (m > 0 && m <= (K - 1)) {
            ans += 1;
        }
        if (m > (K - 1)) {
            ans += 2;
        }
        System.out.println(ans);
    }


    static class CustomReader extends BufferedReader {
        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }

        public int readLineAsInt() throws IOException {
            return Integer.parseInt(readLine());
        }

        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }

        public char[][] readAsCharMatrix(int rows) throws IOException {
            char[][] matrix = new char[rows][];
            for (int i = 0; i < rows; i++) {
                matrix[i] = this.readLine().toCharArray();
            }
            return matrix;
        }

    }

}

Measured memory_bytes: 38232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int memo[100005];
int N, K;
vector<int> a;
bool check_win(int k) {
    auto &MEMO = memo[k];
    if (MEMO != -1) return MEMO;
    if (k == 0) return MEMO = false;
    
    bool win = false;
    REP(i, N) {
        if (k - a[i] < 0) continue;
        win |= !check_win(k - a[i]);
    }
    return MEMO = win;
}
signed main() {
    REP(i, 100005) memo[i] = -1;
    cin >> N >> K;
    a.resize(N);
    cin >> a;
    cout << (check_win(K) ? "First" : "Second") << endl;
    return (0^_^0);
}



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

int main()
{
    string A, B, C;
    cin >> A >> B >> C;

    if(A.at(A.size()-1)==B.at(0)&&B.at(B.size()-1)==C.at(0)){
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=1,c=0,ans=0,y = 1e18;
  long double n,m,k;
  cin>>n >> m;
  k = n*m;
  x = k;
  c(x);
 
 
}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //int T;cin >> T;while (T--)
  solve();
  return 0;
}


Measured memory_bytes: 3712
S = input()
N = len(S)
now = S[0]

a = 0
b = 0
for i in range(1,N):
    if S[i] == now:
        a += 1
        now = str((int(now)+1)%2)
    else:
        now = S[i]

for i in reversed(range(N)):
    if S[i] == now:
        b += 1
        now = str((int(now)+1)%2)
    else:
        now = S[i]
print(min(a,b))



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

int main(){
  int X;
  cin >> X;
  for(int i=X;;i++){
    bool flag=true;
    for(int j=2;j<=sqrt(X);j++){
      if(i%j==0){
        flag=false;
        break;
      }
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


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

using namespace std;

int main(){
    int N, M, K;
    vector<long> A = {0};
    vector<long> B = {0};
    cin >> N >> M >> K;
    for (int i = 0; i < N; i++)
    {
        long a;
        cin >> a;
        a += A.at(i);
        A.push_back(a);
    }
    for (int i = 0; i < M; i++)
    {
        long b;
        cin >> b;
        b += B.at(i);
        B.push_back(b);
    }

    int maxij = 0;
    int oldj = 0;
    for (int i = 0; i <= N; i++)
    {
        for (int j = oldj; j <= M; j++)
        {
            if(B.at(M-j)<=K-A.at(i)){
                maxij = max(maxij, i + M - j);
                oldj = j;
                break;
            }
        }
    }
    cout << maxij << endl;
}


Measured memory_bytes: 8008
#include <stdio.h>
 
int main(){
  char* c[3];
  scanf("%s", &c);
  //printf("%s", c);
  
  if(strcmp(c,"MON")==0){
    printf("6");
  }else if(strcmp(c,"TUE")==0){
    printf("5");
  }else if(strcmp(c,"WED")==0){
    printf("4");
  }else if(strcmp(c,"THU")==0){
    printf("3");
  }else if(strcmp(c,"FRI")==0){
    printf("2");
  }else if(strcmp(c,"SAT")==0){
    printf("1");
  }else if(strcmp(c,"SUN")==0){
    printf("7");
  }
  return 0;
}

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

int main() {
    int X, N; cin >> X >> N;
    vector<int> p(N);
    vector<int> bucket(201, 0);
    for (int i = 0; i < N; i++) {
        cin >> p.at(i);
        bucket.at(p.at(i))++;
    }
    
    int ans = 200;
    for (int i = 1; i <= 200; i++) {
        if (bucket.at(i) > 0) {
            continue;
        }
        if (abs(ans-X) > abs(X-i)) ans = i;
    }
    if (N == 0) cout << X << endl;
    else if (abs(ans-X) >= X) cout << 0 << endl;
    else cout << ans << endl;
}

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

using namespace std;
using LL = long long;
const LL LINF = 1e18;
const LL MOD = 998244353;

class UnionFind {
public:
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool connect(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

int main(){
    int N,M;
       cin >> N >> M;
       vector<int> zisuu(N);
       vector<pair<int,int>> E;
       int cnt1 = 0;
       int cnt2 = 0;
       for(int a = 0;a < M;a++){
           int b,c;cin >> b >> c;
           b--,c--;
           E.push_back({b,c});
           zisuu.at(b)++;
           zisuu.at(c)++;
       }
       bool r = true;
       for(int a = 0;a < N;a++){
           if(zisuu.at(a)%2 == 1)r = false;
           if(zisuu.at(a) >= 6)cnt1++;
           if(zisuu.at(a) == 4)cnt2++;
       }
       if(r){
           if(cnt1 || cnt2 >= 3){
               cout<<"Yes"<<endl;
           }else if(cnt2 == 2){
               vector<int> flag;
               for(int a = 0;a < N;a++){
                   if(zisuu.at(a) == 4){
                       flag.push_back(a);
                   }
               }
               for(auto x : flag){
                   UnionFind Uni(N);
                   for(int a = 0;a < E.size();a++){
                   		if(x != E.at(a).first && x != E.at(a).second){
                       		Uni.connect(E.at(a).first,E.at(a).second);
                   		}
               		}
               	
               	if(Uni.size(0) == N-1){
                   	cout<<"No"<<endl;
                    return 0;
               	}
           }
               cout<<"Yes"<<endl;
           }else{
               cout<<"No"<<endl;
           }
       }else{
           cout<<"No"<<endl;
       }
}


Measured memory_bytes: 1784
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;
 
 
 
 
int main(){
    ll a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
    
    
    
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

  template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int a,b,x;
vector<int> leaps(3000,0);

void FilterLeap(){
  rep(i,3000){
    if((i+1) % 400 == 0 ||( (i+1) % 4 == 0 && (i+1)%100 != 0)){
      leaps[i+1] = 1;
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FilterLeap();
  string s  = "";
  while(cin >> a >> b){
    if(a + b == 0) break;
    if(s.size() != 0) s+= "\n";
    x = 0;
    for(int i = a; i <=b ;++i){
      if(leaps[i] == 1){
        s += std::to_string(i)+"\n";
      }
      else{
        ++x;
      }
    }
    if(x == b-a+1){
      s += "NA\n";
    }
  }
  cout << s;
  return 0;
}

Measured memory_bytes: 3316
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			int q = cin.Int();

			var to = new List<int>[n];
			for (int i = 0; i < n; i++) {
				to[i] = new List<int>();
			}

			for (int i = 0; i < n - 1; i++) {
				int a = cin.Int() - 1;
				int b = cin.Int() - 1;
				to[a].Add(b);
				to[b].Add(a);
			}

			var count = new int[n];
			for (int i = 0; i < q; i++) {
				int p = cin.Int() - 1;
				int x = cin.Int();
				count[p] += x;
			}

			var val = new int[n];
			for (int i = 0; i < n; i++) {
				val[i] = -1;
			}

			val[0] = count[0];
			var qu = new Queue<int>();
			qu.Enqueue(0);
			while (qu.Count > 0) {
				int cur = qu.Dequeue();
				foreach (int next in to[cur]) {
					if (val[next] == -1) {
						val[next] = val[cur] + count[next];
						qu.Enqueue(next);
					}
				}
			}

			string ans = string.Join(" ", val);
			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 57096
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
int main() {
    long long N, X;
    cin>>N>>X;
    vector<long long> ve(N);
    rep(i, 0, N) { cin >> ve[i]; }
    ve.push_back(X);
    sort(ve.begin(), ve.end());
    int gcd = ve[1] - ve[0];
    rep(i, 0, N) {
        long long sa = ve[i + 1] - ve[i];
        gcd = GCD(gcd, sa);
    }
    cout << gcd << endl;
}

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

int main() {
	int c = 0;
	char b;
	int size;
	string str;
	cin >> str;
	size = str.size();
	b = str[0];
	for (int i = 1; i < size;i++) {
		if (b != str[i]){
			c++;
			b = str[i];
		}
	}
	cout << c;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "YES" << '\n'; exit(0); }
inline void no() { cout << "NO" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  string s;
  cin >> s;
  int c = 0;
  rep(i, s.size()) if (s[i] == 'x') c++;
  if (c >= 8) no(); yes();
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
import itertools
import math
INF = 10**9
MOD = 10**9+7

A, B = map(int, input().split())
s1 = set()
for i in range(2, int(math.sqrt(A))+1):
    if A % i == 0:
        s1.add(i)
        while A % i == 0:
            A //= i
if A > 1:
    s1.add(A)
s2 = set()
for i in range(2, int(math.sqrt(B))+1):
    if B % i == 0:
        s2.add(i)
        while B % i == 0:
            B //= i
if B > 1:
    s2.add(B)
print(len(s1&s2)+1)


Measured memory_bytes: 3440
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A + B + C > 21) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    ll ans=1;
    ll x,y;
    cin >> x >> y;

    while(2*x<=y){
        ans++;
        x*=2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define test(t) ll t;cin>>t;while(t--)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Vi vector
#define pr pair
#define mpr make_pair
#define fi first
#define se second
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

set <ld> s[100005];
ld d[100005];

vector<char> prime (100000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
	{
		if (prime[i])
		{
			s[i].insert(i);			
			for (ld j=2*i; j<=n; j+=i)
			{
				prime[j] = false;
				s[j].insert(i);
			}
		}
	}
}
#define forn(i,e) for(int i = 0; i < e; i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)

#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
ld gcd(ld a, ld b) { if(b == 0) return a; return gcd(b, a % b); }
ld fastpowMOD(ld a, ld p,ld MOD){ if(p==0) return 1; ld z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
ld fastpow(ld a, ld p){ if(p==0) return 1; ld z = fastpow(a,p/2); z = (z*z); if(p%2) z = (z*a); return z; }
ld a,b;

ld search1(ld a[], ld f,ld n)
{
	ld left=1;
	ld right=n+1;
	while(right-left>1)
	{
		ld mid = left + (right-left)/2;
		if(a[mid]<f)
		{
			left=mid;
		}
		else right=mid;
	}
	return a[left];
}
ld MOD = 1e9+7;

int main(){
	ld n,i,j,k;
	cin >> n;
	string s;
	cin >> s;
	vector<vector<ld> > dp(n+1,vector<ld>(n+1,0));
	dp[1][1]=1;
	REP(i,2,n)
	{
		vector<ld> pref(i,0);
		REP(j,1,i-1)
		{
			pref[j]=(pref[j-1]+dp[i-1][j])%MOD;
		}
		REP(j,1,i)
		{
			if(s[i-2]=='<')
			{
				dp[i][j]+=pref[j-1]%MOD;
			}
			else dp[i][j]+=(pref[i-1]-pref[j-1]+MOD)%MOD;
		}
	}
	ld sum=0;
	REP(i,1,n)
	{
		sum+=dp[n][i]%MOD;
	}
	cout << sum%MOD << endl;
	return 0;
}

Measured memory_bytes: 75904
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String line;
		
		//????§??????°
		int num;
		
		//?????§???
		int max;
		
		//?¨??????¨?????°
		int maxValue = -2000000000;
		int minValue;
		
		
		num=Integer.parseInt(bf.readLine());
		int tmp[]=new int[num];
		
		for(int i=0;i<num;i++){
			tmp[i]=Integer.parseInt(bf.readLine());
		}
		
		minValue=tmp[0];
		for(int i=1;i<num;i++){
			maxValue= maxValue > tmp[i]-minValue ? maxValue:tmp[i]-minValue;
			minValue = tmp[i] > minValue ? minValue:tmp[i];
		}
		
		System.out.println(maxValue);
	}

}

Measured memory_bytes: 43152
#ABC087-B
a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
    if i <= x//500 + 1:
        for j in range(b+1):
            if j <= x//100 + 1:
                for k in range(c+1):
                    if 500*i + 100*j + 50*k == x:
                        cnt += 1
print(cnt)

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

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
ll gc(ll a, ll b){
    if(b == 0) return a;
    return gc(b, a % b);
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    ll g = 0;
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;
        g = gc(g, x);
    }
    cout << g;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

mod = 10**9+7               # mod素数
N = 10**6                   # 出力の制限
g1 = [1]*(N+1)              # 元テーブル
g2 = [1]*(N+1)              # 逆元テーブル
for i in range(2, N + 1 ): # 準備
    g1[i] = ( g1[i-1] * i ) % mod
g2[N] = pow(g1[-1], mod-2, mod)
for i in range(N, 0, -1):
    g2[i-1] = ( g2[i] * i ) % mod

def nCr(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

def nPr(n, r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

def main():
    N, M = map(int, input().split())
    ret = 0
    for k in range(N+1):
        tmp = nCr(N, k) * nPr(M, k) * (nPr(M-k, N-k)**2) % mod
        if k%2==0:
            ret += tmp
        else:
            ret -= tmp
        ret %= mod
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 87868