akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <vector>
using namespace std;

int main()
{    
    const int MOD = 1000000007;

    int H,W;
    cin >> H >> W;
    int A[H][W]={};
    for (int i = 0; i < H; ++i) {
        string s;   
        cin >> s;
        for (int j = 0; j < W; ++j) {
            if (s[j]=='#'){A[i][j]=1;}
        }
    }

    
    long long dp[H][W]={};


    dp[0][0]=0;
    if (A[1][0]==0){dp[1][0]=1;}
    if (A[0][1]==0){dp[0][1]=1;}


    for (int i = 2; i < H; ++i) {
        if (A[i][0]==0){dp[i][0]=dp[i-1][0];}
    }

    for (int i = 2; i < W; ++i) {
        if (A[0][i]==0){dp[0][i]=dp[0][i-1];}
    }

    

    for (int i = 1; i < H; ++i) {
        for (int j = 1; j < W; ++j) {
            //dp[i][j]=0;
            if (A[i][j]==0){
                if (A[i-1][j]==0){dp[i][j]+=dp[i-1][j];}
                if (A[i][j-1]==0){dp[i][j]+=dp[i][j-1];}
                //dp[i][j]=dp[i][j-1]+dp[i-1][j];
            }
            if (dp[i][j]>MOD){dp[i][j]=dp[i][j]%MOD;}
        }
    }

    
    cout << dp[H-1][W-1] << endl;
    return 0;

}

Measured memory_bytes: 12032
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
	int N, Y;
	cin >> N >> Y;
	int a = -1;
	int b = -1;
	int c = -1;
	bool found = false;
	for (int i = 0; i <= N && !found; i++) {
		for (int j = 0; i + j <= N && !found; j++) {
			for (int k = 0; i + j + k <= N && !found; k++) {
				if (10000 * i + 5000 * j + 1000 * k == Y && i+j+k==N) {
					a =i;
					b = j;
					c = k;
					found = true;
					break;
				}
			}
		}
	}
	cout << a << ' ' << b << ' ' << c << endl;
	return 0;
}

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

int main()
{
  int N;

  cin >> N;

  if(N%1000 == 0){
    cout << 0 << endl;
  }
  else{
    cout << 1000-N%1000 << endl;
  }

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define LOCAL
using std::to_string;
auto to_string(std::string s) -> std::string {
  return '"' + s + '"';
}
auto to_string(char c) -> std::string {
  return "'" + std::string{c} + "'";
}
auto to_string(const char* s) -> std::string {
  return to_string((std::string) s);
}
auto to_string(bool b) -> std::string {
  return (b ? "true" : "false");
}
template <typename T, typename U>
auto to_string(std::pair<T, U> p) -> std::string {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <size_t N>
auto to_string(std::bitset<N> bs) -> std::string {
  std::string res{};
  for (size_t i = 0; i < N; i++)
    res.insert(res.begin(), bs.test(i) ? '1' : '0');
  return res;
}
template <typename T>
auto to_string(T v) -> std::string {
  bool flg = false;
  std::string res = "{";
  for (auto const&x : v) {
    if (flg) res += ", ";
    else flg = true;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  std::cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  size_t n; long long X; std::cin >> n >> X;
  std::vector<long long> b(n), l(n), u(n), full(n);
  for (size_t i = 0; i < n; i++) {
    std::cin >> b.at(i) >> l.at(i) >> u.at(i);
    full.at(i) = b.at(i) * l.at(i) + (X - b.at(i)) * u.at(i);
  }
  std::vector<size_t> ord(n);
  std::iota(ord.begin(), ord.end(), 0);
  std::sort(ord.begin(), ord.end(), [&](auto i, auto j){
    return full.at(i) > full.at(j);});
  auto cal = [&] (size_t i, long long x) {
    assert(i < n);
    assert(0 <= x && x <= X);
    auto j = ord.at(i);
    if (x <= b.at(j)) return -(b.at(j) - x) * l.at(j);
    else return (x - b.at(j)) * u.at(j);
  };
  auto diff = [&] (size_t i, long long x, long long y) {
    return cal(i, y) - cal(i, x);
  };
  auto check = [&] (long long time) {
    if (time > X * (long long)n) return true;
    size_t q = time / X; long long r = time % X;
    assert(q <= n);
    assert(0LL <= r && r < X);
    long long base = 0;
    for (size_t i = 0; i < q; i++) {
      base += cal(i, X);
    }
    for (size_t i = q; i < n; i++) {
      base += cal(i, 0);
    }
    for (size_t i = 0; i < n; i++) {
      auto score = base;
      if (i < q) {
        auto a = diff(i, X, r);
        auto b = diff(q, 0, X);
        score += a + b;
      } else {
        auto c = diff(i, 0, r);
        score += c;
      }
      if (score >= 0) return true;
    }
    return false;
  };
  long long ok = X * (long long)n, ng = -1, md;
  while (abs(ok - ng) > 1) {
    md = (ok + ng) >> 1;
    if (check(md)) ok = md;
    else ng = md;
  }
  std::cout << ok << std::endl;
  return 0;
}

Measured memory_bytes: 4224
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	A, B := nextInt(), nextInt()
	if A <= 5 {
		fmt.Println(0)
	} else if A >= 13 {
		fmt.Println(B)
	} else {
		fmt.Println(B / 2)
	}
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}

// ここから拝借
// https://shoman.hatenablog.com/entry/2020/02/25/185456
// Stackは[]intのエイリアス
type Stack []int

// Push adds an element
func (s *Stack) Push(v int) {
	*s = append(*s, v)
}

// Pop removes the top element and return it
func (s *Stack) Pop() (int, error) {
	if s.Empty() {
		return 0, fmt.Errorf("stack is empty")
	}

	v := (*s)[len(*s)-1]
	*s = (*s)[:len(*s)-1]
	return v, nil
}

// Peek returns the top value
func (s *Stack) Peek() (int, error) {
	if s.Empty() {
		return 0, fmt.Errorf("stack is empty")
	}

	return (*s)[len(*s)-1], nil
}

// Size returns the length of stack
func (s *Stack) Size() int {
	return len(*s)
}

// Empty returns true when stack is empty
func (s *Stack) Empty() bool {
	return s.Size() == 0
}

// NewStack generates stack
func NewStack() *Stack {
	s := new(Stack)
	return s
}


Measured memory_bytes: 1812
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n = int(input())
    print(ceil(n/2))
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 5712
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

int main(){
    int N,i;
    string s,t;
    cin >> N;
    cin >> s;
    cin >> t;
    for(i=0;i<N;i++){
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

void process(){
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int y = sc.nextInt();

		for(int i = 0; i <= x; i++){
			if(i * 2 + (x - i)*4 == y){
				System.out.println("Yes");
				return;
			}
		}

		System.out.println("No");
	}

}


Measured memory_bytes: 27080
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define deb(x) cerr << #x << ": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
const int INF = 2e9;
ll N,X;
struct Item{
    ll cost,pages;
};
vector<Item>Items;
bool cached[100001][101]; //100000000   = 100 MBytes
ll    memo[100001][101]; //100000000 * 4  = 400 MBytes // Limit = 512 MB

ll Knapsack(ll sum, ll idx){
    if(sum < 0)  return INF;
    if(sum == 0) return 0;
    if(idx == N) return INF;
    if(cached[sum][idx])
        return memo[sum][idx];
    //Descision 1 entrar en la mochila
    ll res1 = Knapsack(sum - Items[idx].pages, idx+1) + Items[idx].cost;
    //Descision 2 dejar fuera de la mochila
    ll res2 = Knapsack(sum, idx+1);
    ll res = min(res1,res2);
    cached[sum][idx] = true;
    memo[sum][idx] = res;
    return res;
    
}


int main(){
    ios;
    cin >> N >> X;
    Items = vector<Item>(N);
    for(ll i = 0; i < N; ++i)
        cin >> Items[i].cost >> Items[i].pages;
    for(ll i = 100000; i >= 0; --i){
        ll required_knap = Knapsack(i, 0);
       // deb(required_knap);
        if(required_knap <= X){
            cout << i << '\n';
            return 0;
        }
    }
}


Measured memory_bytes: 92388
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int a[N];
    REP(i, N){
        cin >> a[i];
        
    }

    map <int, int> m;
    REP(i, N){
        m[a[i] - 1]++;
        m[a[i]]++;
        m[a[i] + 1]++;
    }
    
    int max_val = 0, max_key = 0;
    for (auto p : m) {
        auto key = p.first;
        auto value = p.second;
        if (max_val < value){
            max_val = value;
            max_key = key;
        }
    }
    cout << m[max_key] << endl;

}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
long long  k,n;
cin >> k;
n = s.size();
for(int i = 0; i < k; i++){
  if(s[i]!= '1' ){
  cout << s[i] << endl;
  return 0;
}
}
cout << 1 << endl;
return 0;


}


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

bool isMonth(int x) {
    return 1 <= x && x <= 12;
}

int main(void) {
    int s;
    cin >> s;
    int x, y;
    x = s / 100;
    y = s % 100;

    if (isMonth(x)) {
        if (isMonth(y)) {
            puts("AMBIGUOUS");
        }
        else {
            puts("MMYY");
        }
    }
    else {
        if (isMonth(y)) {
            puts("YYMM");
        } else {
            puts("NA");
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int w,n,i,a,b,ami[31],t;
	for(i=0;i<31;i++)ami[i]=i;
	scanf("%d%d",&w,&n);
	for(i=0;i<n;i++){
	    scanf("%d,%d",&a,&b);
	    t=ami[a];
	    ami[a]=ami[b];
	    ami[b]=t;
	}
	for(i=1;i<=w;i++)printf("%d\n",ami[i]);
	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/python3

import numpy as np

n = int(input())
a = list(map(int,input().split()))

#mult = np.prod(a)

if 0 in a:
  print(0)
  exit()

if any(( x > 10**18 for x in a)):
  print(-1)
  exit()

mult=1
for i in range(n):
  mult *= a[i]
  if mult > 10**18:
    print(-1)
    exit()

print(mult)



Measured memory_bytes: 40240
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF const ll INF = 1001001001;
#define PI const ld PI = 3.14159265358979323846;


int main() {
    int X,Y,Z;
    cin>>X>>Y>>Z;
    cout<<(X-Z)/(Y+Z)<<endl;
return 0;
}

Measured memory_bytes: 256
H, W, K = map(int, input().split())
grid = 'x' * (W + 2)
for _ in range(H):
    grid += 'x' + input() + 'x'
grid += 'x' * (W + 2)

N = len(grid)
strb = [i for i in range(N) if grid[i] == '#']
G = [0] * N

for i, s in enumerate(strb, 1):
    q = [s]
    while q:
        x = q.pop()
        if G[x] != 0:
            continue
        G[x] = i
        for dx in [1, -1]:
            y = x + dx
            if grid[y] == '.' and G[y] == 0:
                q.append(y)

for i in range(N - 1, -1, -1):
    if G[i] == 0 and i + W + 2 < N:
        G[i] = G[i + W + 2]

for i in range(N):
    if G[i] == 0 and i - W - 2 < N:
        G[i] = G[i - W - 2]

j = 0
for i in range(H):
    print(' '.join(str(x) for x in G[j + W + 3:j + 2 * W + 3]))
    j += W + 2


Measured memory_bytes: 10860
n = int(input())
a = []
m1 = -1
i1 = 0
m2 = -1
i2 = 1
for i in range(n):
  t = int(input())
  a.append(t)
  if t>m2:
    i2 = i
    m2 = t
  if m2>m1:
    i1, i2 = i2, i1
    m1, m2 = m2, m1
for i in range(n):
  if i!=i1:
    print(m1)
  else:
    print(m2)

Measured memory_bytes: 12532
<?php
  $s = trim(fgets(STDIN));
  $list = [];
  for($i=0; $i<strlen($s); $i++){
    if(preg_match("/".$s[$i]."/","ACGT")){
      $list[$i] = $s[$i];
    }
  }
  if(count($list) == 0){
    echo "0\n";
    exit;
  }
  $l = array_keys($list);
  $n = 1;
  $count = 1;
  for($i=1; $i<count($l); $i++){
    if($l[$i-1] == $l[$i]-1){
      $n++;
      $count = max($count,$n);
    }else{
    $n = 1;
    }
  }
  echo $count."\n";

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

int main()
{
  string S;
  cin >> S;
  vector<int64_t> A(S.size() + 1, 0);
  for (int i = 1; i <= S.size(); i++)
  {
    if (S.at(i - 1) == '<')
    {
      A.at(i) = A.at(i - 1) + 1;
    }
    else
    {
      int64_t cnt = 0;
      for (int j = i - 1; j < S.size(); j++)
      {
        if (S.at(j) == '<')
          break;
        cnt++;
      }
      A.at(i - 1) = max(A.at(i - 1), cnt);
      int64_t tmp = cnt - 1, j = i;
      while (tmp >= 0)
      {
        A.at(j) = tmp;
        tmp--;
        j++;
      }
      i = j - 1;
    }
  }
  int64_t ans = 0;
  for (auto a : A)
    ans += a;
  cout << ans << endl;
}

Measured memory_bytes: 4740
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;
int a[100005];
int b[100005], cnt, x, n;
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) scanf("%d", &x), a[x]++;
	for(int i = 1; i <= n; i ++){
		if(a[i]) b[++cnt] = i;
		if(cnt == 3) {
			puts("No");
			return 0;
		}
	}
	if(cnt == 2){
		if(abs(b[1] - b[2]) > 1){
			puts("No");
			return 0;
		}
		n -= a[b[1]];
		b[2] -= a[b[1]];if(b[2] <= 0){
			puts("No");
			return 0;
		}
		x = b[2];
	}else x = b[1];
	if(n / x >= 2){
		printf("Yes\n");
		return 0;
	}
	
	if(n - x == 1){
		if(cnt == 1)
		printf("Yes\n");
		else puts("No");
		return 0;
	}
	printf("No\n");
		return 0;
	return 0;
} 

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

string even(int w) {//0行目(一番上から)
  string s = "";
  for(int i = 0; i < w; i++) {
    if(i % 2 == 0) s.push_back('#');
    else s.push_back('.');
  }
  return s;
}

string odd(int w) {
  string s = "";
  for(int i = 0; i < w; i++) {
    if(i % 2 == 0) s.push_back('.');
    else s.push_back('#');
  }
  return s;
}

int main() {
  int h, w;
  while(true) {
    scanf("%d %d", &h, &w);
    if(h == 0 && w == 0) break;
    string sEven = even(w);
    string sOdd = odd(w);
    for(int i = 0; i < h; i++) {
      if(i % 2 == 0) printf("%s\n", sEven.c_str());
      else printf("%s\n", sOdd.c_str());
    }
    printf("\n");
  }
}


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

vector<int> a(1000001);
int n;

bool pairwise() {
  vector<int> d(1000001);
  d[1]=1;
  int maxa = 0;
  for(int i=0;i<n;i++) {
    maxa = max(maxa, a[i]);
  }
  vector<int> pr;
  for (int i=2; i<=maxa; ++i) {
    if (d[i] == 0) {
        d[i] = i;
        pr.push_back (i);
    }
    for (int j=0; j<(int)pr.size() && pr[j]<=d[i] && i*pr[j]<=maxa; ++j)
      d[i * pr[j]] = pr[j];
  }
  unordered_set<int> div;
  for(int i=0;i<n;i++){
    int e = a[i];
    while(e!=1) {
      if(div.find(d[e])!=div.end()) {
        return false;
      }
      div.insert(d[e]);
      int f = d[e];
      while(e%f==0) e/=f;
    }
  }
  return true;
}

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

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

    bool p = pairwise();
    if(p) {
      cout << "pairwise coprime";
      return 0;
    }

    int g = a[0];
    for(int i=1;i<n;i++) g = __gcd(g,a[i]);
    if(g==1) {
      cout << "setwise coprime";
      return 0;
    }

    cout << "not coprime";

    return 0;
}

Measured memory_bytes: 14708
s = input()
v = list("+".join(s))
plus_index = [i for i, x in enumerate(v) if x == '+']
n = len(plus_index)

m = v.copy()
if not eval("".join(v)) == 7:
    for i in range(1 << n):
        m = v.copy()
        for j in range(n):
            if i & (1 << j):
                m[plus_index[j]] = "-"
        if eval("".join(m)) == 7:
            break
print("".join(m) + "=7")

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007


int dp[301][301][301];
int n,m;

vector<pair<int,int>> ru[301];


bool check(pair<int,int> p ,int a,int b,int c){
	int nc=0;
	int l,x;
	tie(l,x) = p;
	if (l <= a)nc++;
	if (l <= b)nc++;
	if (l <= c)nc++;
	return nc == x;
}
bool check(vector<pair<int, int>> &v, int a, int b, int c){
	for (auto p : v){
		if (!check(p,a,b,c))return false;
	}
	return true;
}


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

	cin>>n>>m;
	rep(i,m){
		int l,r,x;
		cin>>l>>r>>x;
		ru[r].emplace_back(l,x);
	}
	if(check(ru[1],1,0,0))dp[0][0][1] = dp[0][1][0] = dp[1][0][0] = 1;
	rep(a, n)rep(b, n)rep(c,n){
		if (dp[a][b][c]==0)continue;
		
		int idx = max({a,b,c}) + 1;
		if (check(ru[idx], idx, b, c)){
			(dp[idx][b][c] += dp[a][b][c]) %= MOD;
		}
		if (check(ru[idx], a, idx, c)){
			(dp[a][idx][c] += dp[a][b][c]) %= MOD;
		}
		if (check(ru[idx], a, b, idx)){
			(dp[a][b][idx] += dp[a][b][c]) %= MOD;
		}
	}
	int ans=0;
	rep(a, n)rep(b,n)
		(ans += dp[a][b][n])%=MOD;
	rep(a, n)rep(c, n)
		(ans += dp[a][n][c]) %= MOD;
	rep(b, n)rep(c, n)
		(ans += dp[n][b][c]) %= MOD;

	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 106752
#include<bits/stdc++.h>
using namespace std;
int fun(int n)
{
	int s=0;
	while(n!=0)
	{
		s+=n%10;
		n/=10;
	}
	return s;
}
int main()
{
	int a,b,t,n,min_v=0x7FFFFFFF;
	scanf("%d",&n);
	for(a=1;a<=n/2;a++)
	{
		b=n-a;
		t=fun(a)+fun(b);
		min_v=min(t,min_v);
	}
	printf("%d",min_v);
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 1000000007
cmb = [[1]]
for i in range(n + 1):
    cmb.append([1])
    for j in range(i):
        cmb[-1].append((cmb[-2][j] + cmb[-2][j + 1]) % mod)
    cmb[-1].append(1)
for i in range(1, k + 1):
    if i > n - k + 1:
        print(0)
    else:
        print((cmb[n - k + 1][i] * cmb[k - 1][i - 1]) % mod)

Measured memory_bytes: 83820
#include <bits/stdc++.h>
using namespace std;
  
#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define treap_pair pair<treap*, treap*>
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, ll> mll;
  
const int N = 2e5 + 2;
const int M = 1e5 + 2;
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18 + 100;

  
void data() {
    #ifdef PC
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif	
}

template <typename T>
void scerr(T nums) {
    for (auto it : nums)
        cerr << it << " | ";
    cerr << "\n";
}

ll n, c, w[N], v[N], dp[N];
int ans = -inf;

int main() {
	data();
	scanf("%lld %lld", &n, &c);
	for (int i = 1; i <= n; ++i)
		scanf("%lld %lld", &w[i], &v[i]);
	for (int i = 0; i < N; ++i)
		dp[i] = INF;
	dp[0] = 0;
	for (int i = 1; i <= n; ++i) 
		for (int j = N - 1; j >= v[i]; --j)				
			dp[j] = min(dp[j - v[i]] + w[i], dp[j]);
   	for (int i = N - 1; i >= 0; --i)
		if (dp[i] <= c)
			ans = max(ans, i);
   	printf("%d", ans);
}
  
/*
    Timus: 288481RF
    CodeForces: fractal
*/


Measured memory_bytes: 3840
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, Y, A, B, C, *PQR = map(int, read().split())
    P = PQR[:A]
    Q = PQR[A : A + B]
    R = PQR[A + B :]

    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort()

    P = P[:X]
    Q = Q[:Y]
    S = []

    while R and (P or Q):
        if not P:
            vec = Q
        elif not Q:
            vec = P
        elif P[-1] < Q[-1]:
            vec = P
        else:
            vec = Q

        if vec[-1] < R[-1]:
            S.append(R.pop())
            vec.pop()
        else:
            break

    ans = sum(P) + sum(Q) + sum(S)

    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	int h,ans=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>h;
		if (h>=k)
		{
			++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

string B[10] = {
	"",
	"',.!?",
	"abcABC",
	"defDEF",
	"ghiGHI",
	"jklJKL",
	"mnoMNO",
	"pqrsPQRS",
	"tuvTUV",
	"wxyzWXYZ"
};

string solve(string s){
	int prev_button = 0;
	int cnt = 0;
	char ch = 0;
	string ans;
	
	for(int i=0 ; i < s.size() ; i++ ){
		if( i == s.size() - 1 && s[i] != '0' ){
			 if( prev_button == (s[i] - '0') ){
				int k = B[ s[i] - '0' ].size();
				prev_button = s[i] - '0';
				cnt = (cnt + 1) % k;
				ch = B[ s[i] - '0' ][cnt];
				ans.push_back( ch );
			}else{
				prev_button = s[i] - '0';
				cnt = 0;
				ans.push_back( ch );
				ch = B[ s[i] - '0' ][0];
				ans.push_back( ch );
			}
			break;
		}
		
		if( s[i] == '0' ){
			if( prev_button == 0 ){
				cnt = 0;
				ch = 0;
				ans.push_back( ' ' );
			}else{
				prev_button = 0;
				cnt = 0;
				ans.push_back( ch );
				ch = 0;
			}
		}else{
			if( prev_button == 0 ){
				prev_button = s[i] - '0';
				cnt = 0;
				ch = B[ s[i] - '0' ][0];
			}else if( prev_button == (s[i] - '0') ){
				int k = B[ s[i] - '0' ].size();
				prev_button = s[i] - '0';
				cnt = (cnt + 1) % k;
				ch = B[ s[i] - '0' ][cnt];
			}else{
				prev_button = s[i] - '0';
				cnt = 0;
				ans.push_back( ch );
				ch = B[ s[i] - '0' ][0];
			}
		}
	}
	return ans;
}

int main(){
	string s;
	while( cin >> s ){
		cout << solve( s ) << endl;
	}
}

Measured memory_bytes: 0
from collections import deque

N, M = map(int, input().split())
rooms = [0] + [[] for _ in range(N)] 
ans = [0] * (N+1)
for _ in range(M):
    A, B = map(int, input().split())
    rooms[A].append(B)
    rooms[B].append(A)

que = deque([1])

while len(que) > 0:
    x = que.popleft()
    for r in rooms[x]:
        if ans[r] == 0:
            ans[r] = x
            que.append(r)

print('Yes')
for i in range(2, N+1):
    print(ans[i])

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

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

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

    string s;
    cin >> s;
    ll ans = 0;
    for (int i = 0; i < s.length(); ++i) {
        ans += s[i] - '0';
    }
    if (ans % 9 == 0) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
}















Measured memory_bytes: 3756
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
int n,m,t,x[100010];
long long f[100010];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	long long k;
	scanf("%d%d%d",&n,&m,&t);
	for(i=1;i<=n;i++)
	  scanf("%d",&x[i]);
	for(i=1,j=0,k=1e18;i<=n;i++)
	  {
	   for(;2*(x[i]-x[j+1])>t;j++)
	     k=min(k,f[j]-2*x[j+1]);
	   f[i]=min(k+2*x[i],f[j]+t);
      }
    cout<<f[n]+m<<"\n";
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 10000;
static const int VMAX = 100000;

int n,A[MAX],s;
int B[MAX],T[VMAX+1];

int solve(){
    int i,ans = 0;
    
    bool V[MAX];
    for(i=0;i<n;i++){
        B[i] = A[i];
        V[i] = false;
    }
    sort(B,B+n);
    for(i=0;i<n;i++) T[B[i]] = i;
    for(i=0;i<n;i++){
        if(V[i]) continue;
        int cur=i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while(1){
            V[cur] = true;
            an++;
            int v=A[cur];
            m = min(m,v);
            S+=v;
            cur = T[v];
            if(V[cur]) break;
        }
        ans += min(S+(an-2)*m,m+S+(an+1)*s);
    }
    return ans;
}

int main(){
    int i;
    cin>>n;
    s=VMAX;
    for(i=0;i<n;i++){
        cin>>A[i];
        s=min(s,A[i]);
    }
    int ans = solve();
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int N, X, Y, Z;
  cin >> N >> X;
  vector<int> a(X);
  for (int i = 0; i < X; ++i)
    cin >> a[i];
  cin >> Y;
  vector<int> b(Y);
  for (int i = 0; i < Y; ++i)
    cin >> b[i];
  cin >> Z;
  vector<int> c(Z);
  for (int i = 0; i < Z; ++i)
    cin >> c[i];

  vector<bool> aa(N + 1), bb(N + 1), cc(N + 1);
  for (int i = 0; i < X; ++i)
    aa[a[i]] = true;
  for (int i = 0; i < Y; ++i)
    bb[b[i]] = true;
  for (int i = 0; i < Z; ++i)
    cc[c[i]] = true;

  int ans = 0;
  for (int i = 1; i <= N; ++i)
    if ((!aa[i] && cc[i]) || (bb[i] && cc[i]))
      ++ans;

  cout << ans << endl;
}


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

int main()
{
	string N;
	cin >> N;
	cout << "ABC" << N << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        
  		int[] a=new int[(int)Math.pow(10,5)];
		for(int c=0;c<n;c++){
    		a[sc.nextInt()]++;
    	}
  		int max=0;
  		for(int c=0;c<(Math.pow(10,5)-2);c++){
        max=Math.max(max,a[c]+a[c+1]+a[c+2]);
        
        }
    

    	System.out.println(max);
    }
}

Measured memory_bytes: 59224
#include<bits/stdc++.h>//atcoder.089.C
using namespace std;
int main(){
	long n,m,i,j,b=0;
	cin>>n;
	long a[6]={0};
	string s[n+1];
	for(i=1;i<=n;i++){
		cin>>s[i];
		if(s[i][0]=='M')a[1]++;
		if(s[i][0]=='A')a[2]++;
		if(s[i][0]=='R')a[3]++;
		if(s[i][0]=='C')a[4]++;
		if(s[i][0]=='H')a[5]++;
	}
	for(i=1;i<=3;i++){
		if(a[i]!=0)
			for(j=i+1;j<=4;j++){
				if(a[j]!=0)
					for(m=j+1;m<=5;m++){
						if(a[m]!=0)b=b+a[i]*a[j]*a[m];
					}
			}
	}
	cout<<b;
	return 0;
}

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

int main(){
    
    char T[5];
    cin >> T;
    
    bool isYes = false;
    
    if(T[3] == T[2] && T[2] == T[1]){
        isYes = true;
    }else if(T[2] == T[1] && T[1] == T[0]){
        isYes = true;
    }
    
    //配列の中身を見るため
    // for(int i=0; i<5; ++i){
    //     cout << (int)T[i] << endl;
    //}
    
    if(isYes){
        cout << "Yes" << endl; 
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> num(101, 0);
    for (int i = 0; i < N; i++) {
        int d;
        cin >> d;
        num[d]++;
    }
    int ans = 0;
    for (int i = 1; i <= 100; i++) {
        if (num[i] >= 1) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
#define PI 3.14159265359
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
const int INF = 1<<31;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int LL;

int a,b,c,d;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(NULL);
    cout.tie(NULL);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);	

    cin >> a >> b >> c >> d;

    if(a*b>c*d){
        cout << a*b;
    }else if(a*b<c*d){
        cout << c*d;
    }else{
        cout << a*b;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<string> blue(N);
  
  for (int i = 0; i < N; i++) {
    cin >> blue.at(i); 
  }
  
  int M;
  cin >> M;
  
  vector<string> red(M);
  
  for (int i = 0; i < M; i++) {
    cin >> red.at(i); 
  }
  
  int X = 0;
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    int preCount = 0;
    
     for (int j = 0; j < N; j++) {
       
       if (blue.at(i) == blue.at(j)) {
         preCount++; 
       }
       
     }
    
     for (int k = 0; k < M; k++) { 
       
       if (blue.at(i) == red.at(k)) {
         preCount--; 
       }
       
     }
    
    if (preCount > count) {
      count = preCount; 
    }
    
  }
  
  if (count > X) {
    X = count; 
  }
  
  cout << X << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 1010
using namespace std;

int n, m;
long long x[N], y[N], p[50];

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n, m = 35;

    for (int i = 1; i <= n; ++i) {
        scanf("%lld%lld", x + i, y + i);
        if (i > 1 && ((x[i] + y[i] + x[i - 1] + y[i - 1]) & 1))
            return puts("-1"), 0;
    }

    for (int i = 0; i < m; ++i)
        p[i] = (1ll << i);
    reverse(p, p + m);
    if ((x[1] + y[1]) % 2 == 0) p[m++] = 1;

    cout << m << endl;
    for (int i = 0; i < m; ++i)
        cout << p[i] << " "; cout << endl;

    for (int k = 1; k <= n; ++k) {
        for (int i = 0; i < m; ++i)
        if (abs(x[k]) > abs(y[k]))
            x[k] += (x[k] < 0 ? (putchar('L'), 1) : (putchar('R'), -1)) * p[i];
        else y[k] += (y[k] < 0 ? (putchar('D'), 1) : (putchar('U'), -1)) * p[i];
        puts("");
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b[]=new int[a];
	int ans=999999999;
	int max=0;
	int min=999999999;
	for(int i=0;i<a;i++) {
		b[i]=scan.nextInt();
		if(b[i]<min) {
			min=b[i];
		}
		if(b[i]>max) {
			max=b[i];
		}
	}
	for(int i=min;i<=max;i++) {
		int count=0;
		for(int j=0;j!=a;j++) {
			if(b[j]==i) {
				continue;
			}
			else {
				count+=(b[j]-i)*(b[j]-i);
			}
		}
		if(ans>count) {
			ans=count;
		}
	}
	System.out.println(ans);
	scan.close();
	}
}

Measured memory_bytes: 21844
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    a_2_divisor_num = [0] * 3 #[num 0 time divided by 2, num 1 time divided by 2, num more than 2 times divided by 2]
    for a in as_:
        if a % 4 == 0:
            a_2_divisor_num[2] += 1
        elif a % 2 == 0:
            a_2_divisor_num[1] += 1
        else:
            a_2_divisor_num[0] += 1
    
    if a_2_divisor_num[1] == 0:
        if a_2_divisor_num[0] <= a_2_divisor_num[2] + 1:
            print("Yes")
        else:
            print("No")
    else:
        if a_2_divisor_num[0] <= a_2_divisor_num[2]:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 14628
abc = ABC = gets.split.map(&:to_i)

c = 0 

until abc.any?(&:odd?) do
  abc = [abc[1] / 2 + abc[2] / 2, abc[0] / 2 + abc[2] / 2, abc[0] / 2 + abc[1] / 2 ]
  c = c + 1
  if abc == ABC
    puts -1
    exit
  end
end

puts c

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

using namespace std;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  map<string, long long> m;
  for (int bit = 0; bit < (1 << N); bit++)
  {
    string r, b;
    for (int i = 0; i < N; i++)
      if (bit & (1 << i))
        r += S[i];
      else
        b += S[i];
    m[r + "-" + b]++;
  }
  long long ans = 0;
  for (int bit = 0; bit < (1 << N); bit++)
  {
    string r, b;
    for (int i = 0; i < N; i++)
      if (bit & (1 << i))
        r += S[N + i];
      else
        b += S[N + i];
    reverse(r.begin(), r.end());
    reverse(b.begin(), b.end());
    ans += m[b + "-" + r];
  }
  cout << ans << endl;

  return 0;
}


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

namespace ConsoleApplication1
{
    class Union_Find
    {
        internal int[] parents, rank;

        public Union_Find(int n)
        {
            parents = Enumerable.Range(0, n).ToArray();
            rank = new int[n];
        }

        public int Find(int x)
        {
            if (parents[x] == x) return x;
            else return parents[x] = Find(parents[x]);
        }

        public void Unite(int x, int y)
        {
            x = Find(x);
            y = Find(y);

            if (x == y) return;

            if (rank[x] < rank[y])
            {
                parents[x] = y;
            }
            else
            {
                parents[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        public bool Same(int x, int y)
        {
            return Find(x) == Find(y);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);

            Union_Find uf = new Union_Find(n);
            int s, t;

            for(int i = 0; i < m; i++)
            {
                input = Console.ReadLine().Split(' ');
                s = int.Parse(input[0]);
                t = int.Parse(input[1]);

                uf.Unite(s, t);
            }

            StringBuilder sb = new StringBuilder();
            int q = int.Parse(Console.ReadLine());

            for(int i = 0; i < q; i++)
            {
                input = Console.ReadLine().Split(' ');
                s = int.Parse(input[0]);
                t = int.Parse(input[1]);

                sb.AppendLine(uf.Same(s, t) ? "yes" : "no");
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10764
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n; cin >>n;
  if(n==1||n==2){cout <<0; return;}
  int l[n],cnt=0;
  for(auto &i:l) cin >>i;
  sort(l,l+n);
  for(int i=0; i<n-2; i++) for(int j=i+1; j<n-1; j++) for(int k=j+1; k<n; k++)
  if(l[i]+l[j]>l[k]&&l[i]!=l[j]&&l[j]!=l[k]) cnt++;
  cout <<cnt;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   solve();
return 0;}

Measured memory_bytes: 3652
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 100005
#define mod 998244353
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) printf("Case %lld:\n",i)
#define pf(a) printf("%lld ",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp,mp1;
vector<pair<ll,pair<ll,pair<ll,ll> > > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,ll>mpp;
map<ll,bool>mb;
ll n,x,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
ll ans=0;
ll dp[MAX+10];
ll arr[MAX+10];
ll calc(ll pos)
{
    if(pos>=n)return 0;
    else if(dp[pos]!=-1) return dp[pos];
    ll ret=0,ret1=10000000000000000;
    ///cout<<l<<endl;
    ll mini;
    FOR1(i,l)
    {
        mini=100000000000000000;
        if(pos+i<=n)
        {
            mini=min(mini,ret+calc(pos+i)+abs(arr[pos]-arr[pos+i]));
            ret1=min(ret1,mini);
        }
    }
    ///cout<<mini<<endl;
    ////ret=mini;
    return dp[pos]=ret1;
}
int main()
{
    cin>>n>>l;
    v.clear();
    memset(arr,0,sizeof arr);
    FOR1(i,n)
    {
        cin>>arr[i];
    }
    memset(dp,-1,sizeof dp);
    ans=calc(1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8064
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}
int n;
char s[200010],t[200010];
int f(char a,char b,int r,int x){
  int i=n-1,l=1,m=r;//printf("%c\n",s[i]);
  if(s[i]==a)l++;
  if(s[i]==b)r--;//printf("%d %d ",l,r);
  if(l>r)return 0;
  while(i--){//printf("%c %c\n",t[i],s[i]);
    if(t[i]==b)l=MAX(1,l-1);
    if(t[i]==a)r=MIN(m,r+1);
    if(s[i]==a)l++;
    if(s[i]==b)r--;//printf("%d %d\n",l,r);
    if(l>r)return 0;
  }
  if(x<l||r<x)return 0;
  return 1;
}  
int main(){
  int h,w,x,y;
  scanf("%d %d %d %d %d %s %s",&h,&w,&n,&y,&x,s,t);
  printf("%s\n",f('U','D',h,y)*f('L','R',w,x)?"YES":"NO");
}
  


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int x,ans=1;
int main(void){
    scanf("%d",&x);
    for(int i=2;i*i<=x;i++){
        int r=i;
        while(r*i<=x){
            r*=i;
            ans=max(ans,r);
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
S = input()

import sys
S = S[:-1]

while len(S) > 1:
    if len(S)&1 == 1:
        S = S[:-1]
    else:
        ok = True
        mid = len(S)//2

        for i in range(mid):
            if S[i] != S[mid + i]:
                ok = False
                break
        
        if ok:
            print(len(S))
            sys.exit()
        
        S = S[:-1]

Measured memory_bytes: 3060
// Problem : A - Kyu in AtCoder
// Contest : AtCoder - M-SOLUTIONS Programming Contest 2020
// URL : https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Delete the dynamically allocated memory

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define pr              pair<long long,long long>
#define mp(a,b)         make_pair(a,b)
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fill(a,b)       memset(a, b, sizeof(a))
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
ll power(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base);
       base=(base*base);
       exp/=2;
    }
    return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x;
	cin>>x;
	if(x>=400&&x<=599){
		cout<<8<<"\n";
	}else if(x>=600&&x<=799){
		cout<<7<<"\n";
	}else if(x>=800&&x<=999){
		cout<<6<<"\n";
	}else if(x>=1000&&x<=1199){
		cout<<5<<"\n";
	}else if(x>=1200&&x<=1399){
		cout<<4<<"\n";
	}else if(x>=1400&&x<=1599){
		cout<<3<<"\n";
	}else if(x>=1600&&x<=1799){
		cout<<2<<"\n";
	}else if(x>=1800&&x<=1999){
		cout<<1<<"\n";
	}
	return 0;
	}

Measured memory_bytes: 3632
#include<iostream>
#include<string>

using namespace std;

int main(void)
{
	int N;
	int num;
	string str1,str2;

	cin>>N;
	cin>>str1;
	cin>>str2;

	num = str1.size();
	for(int i = 0;i < N;i++) {
		bool flag = false;
		for(int j = 0;j+i < N;j++) {
			if(str1[i+j] == str2[j]) {
			flag = true;
			}
			else
			{
				flag = false;
				break;
			}
		}
		if(flag) {
			break;
		}
		num += 1;
		str2.erase(str2.end()-1,str2.end());
	}

	cout<<num<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
constexpr int DEBUG = 1;
using namespace std;

struct edge {
  int id;
  int a;
  int b;
  int color;
  edge(int id_, int a_, int b_) {
    id = id_;
    a = a_;
    b = b_;
  }
};
 
bool comp(const edge &x, const edge &y) {
  if (x.a != y.a)
	  return x.a < y.a;
  return x.b < y.b;
}

bool compID(const edge &x, const edge &y) {
  return x.id < y.id;
}

int main() {
  int n;
  cin >> n;
  vector<edge> e;
  for (int i = 0; i < n - 1; i++) {
    int ai, bi;
    cin >> ai >> bi;
    e.push_back(edge(i, ai - 1, bi - 1));
  }
  sort(e.begin(), e.end(), comp);
  
  vector<int> pvc(n, 0);
  e[0].color = 1;
  pvc[e[0].b] = 1;
  int col = 1, pcol = 0, pv = 0;
  for (int i = 1; i < e.size(); i++) {
    if (e[i].a == pv)
      col++;
    else {
      pv = e[i].a;
      pcol = pvc[e[i].a];
      col = 1;
    }
    if (col == pcol)
      col++;
    e[i].color = col;
    pvc[e[i].b] = col;
  }
  
  sort(e.begin(), e.end(), compID);
  
  int k;
  for (int i = 0; i < e.size(); i++) {
    if (e[i].color > k)
      k = e[i].color;
  }
  cout << k << endl;
  for (int i = 0; i < e.size(); i++)
    cout << e[i].color << endl;
  
  return 0;
}


Measured memory_bytes: 2420
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
 
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin -2147483647
#define llmax 9223372036854775807
using namespace std;
 
int n, a, cnt;
 
 
int main(){
  	cnt=0;
	cin >> n;
	lp(n) {
		cin >> a;
		if (a % 2 == 1)cnt++;
	}
	cout << (cnt % 2 == 0 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
import sys
sys.setrecursionlimit(4000)


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


s = ''
dp = []
def main():
    global s
    global dp
    s = input()
    t = input()

    n = len(s)
    m = len(t)

    dp = [[0 for j in range(m+1)] for i in range(n + 1)]

    for i in range(n):
        for j in range(m):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

    #  print(t)
    #  v = 0
    #  result = ''
    #  print('dp[-1]', dp[-1])
    #  for idx, i in enumerate(dp[-1]):
    #      print(idx, i)
    #      if i == v + 1:
    #          result += t[idx-1]
    #          v += 1

    #  print(result)

    #  lcs_str = ''
    #  i, j = n - 1, m - 1
    #  while i >= 0 and j >= 0:
    #      if s[i] == t[j]:
    #          lcs_str += s[i]
    #          i -= 1
    #          j -= 1
    #      elif dp[i+1][j+1] == 0:
    #          break
    #      else:
    #          if dp[i][j+1] > dp[i+1][j]:
    #              i -= 1
    #          else:
    #              j -= 1

    #  print(lcs_str[::-1])
    print_lcs(n, m)
    global ans
    print("".join(ans))

ans = []

def print_lcs(i, j):
    global s, dp, ans
    if not i or not j:
        return ''

    ret = dp[i][j]
    if ret == dp[i-1][j]:
        print_lcs(i - 1, j)
    elif ret == dp[i][j-1]:
        print_lcs(i, j-1)
    else:
        print_lcs(i - 1, j - 1)
        ans.append(s[i-1])
        #  print(s[i-1], end='', flush=True)


main()


Measured memory_bytes: 126944
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

string str;
signed main(){
	cin >> str;
	int n = str.size();int ans = n;
	
	drep(i,n-1,0){
		if(str[i] == 'Z'){
			ans -= n-i-1;
			break;
		}
	}
	rep(i,n){
		if(str[i] == 'A'){
			ans -= i;
			break;
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    string s, ans = "";
    int w;
    cin >> s >> w;
    for (int i = 0; i < s.size(); i += w) {
        ans += s[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,j,k)  for(int i=(j);i<=(k);i++)
using namespace std;
int ans;
int main()
{
	int tmp;
	scanf("%d",&tmp);
	ans=tmp;
	scanf("%d",&tmp);
	ans*=10;
	ans+=tmp;
	scanf("%d",&tmp);
	ans*=10;
	ans+=tmp;
	if(ans%4==0)	printf("YES\n");
	else	printf("NO\n");
	return 0;
}


Measured memory_bytes: 256