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

int battle(int x, int y) {
    if (x == y)
        return x;
    if (x < y)
        return y - x;
    return x - y;
}

int main() {
    int n;
    cin >> n;
    n = 1 << n;
    queue<int> que;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        que.push(a);
    }

    while (que.size() > 1) {
        int x = que.front(); que.pop();
        int y = que.front(); que.pop();
        que.push(battle(x, y));
    }
    cout << que.front() << endl;
}


Measured memory_bytes: 1280
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#MOD = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    ans=0
    for i in range(1,n):
        ans+=(n-1)//i
    print(ans)
if __name__=='__main__':
    do()

Measured memory_bytes: 9188
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>

using namespace std;

typedef long long li;
typedef pair<int, int> pii;

#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

double eps = 1e-5;
const int INF = 1e9 + 7;
const li LINF = 9e18 + 7;


int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	
	int n;
	cin >> n;
	n++;

	vector<int> t(n), x(n), y(n);
	t[0] = x[0] = y[0] = 0;
	for (int i = 1; i < n; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}

	for (int i = 1; i < n; i++) {
		int d = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		int dt = t[i] - t[i - 1];

		if (d <= dt && (dt - d) % 2 == 0) {
			continue;
		}

		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int X = sc.nextInt();
        int t = sc.nextInt();
        if(X - t >= 0){
            System.out.println(X - t);
        }else if(X - t < 0){
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 21844
n,m,Q=map(int,input().split())
mat=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
  l,r=map(int,input().split())
  mat[l][r]+=1

for i in range(n+1):
  for j in range(n+1):
    mat[i][j]+=mat[i-1][j]
    mat[i][j]+=mat[i][j-1]
    mat[i][j]-=mat[i-1][j-1]

for i in range(Q):
  p,q=map(int,input().split())
  s=mat[q][q]-mat[q][p-1]-mat[p-1][q]+mat[p-1][p-1]
  print(s)


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

ll N,C;
vector<PLL> v; // {x,v}

ll f1(void) {
    vector<ll> A(N); // a[i]: i番目までの(取得カロリー - 移動カロリー)の中で最大値
    A[0] = v[0].second - v[0].first;
    rep(i,1,N){
        A[i] = A[i-1] + v[i].second - (v[i].first - v[i-1].first);
    }
    rep(i,1,N){
        A[i] = max(A[i], A[i-1]);
    }

    ll ans = A[N-1];

    ll B = v[N-1].second - (C-v[N-1].first) * 2;

    if (N-2>=0)
        ans = max(ans, B + A[N-2]);

    for (ll b = N-2; b >= 0; b--){
        B = B + v[b].second - (v[b+1].first - v[b].first) * 2;
        if (b > 0){
            ans = max(ans, B+A[b-1]);
        } else {
            ans = max(ans, B);
        }
    }

    return ans;
}

ll f2(void) {
    vector<ll> B(N); // B[i]: N-1~i番目までの(取得カロリー - 移動カロリー)の中で最大値
    B[N-1] = v[N-1].second - (C - v[N-1].first);
    for (ll i = N-2; i>=0; i--) {
        B[i] = B[i+1] + v[i].second - (v[i+1].first - v[i].first);
    }
    for (ll i = N-2; i>=0; i--) {
        B[i] = max(B[i], B[i+1]);
    }

    ll ans = B[0];

    ll A = v[0].second - v[0].first * 2;

    if (1<N)
        ans = max(ans, A + B[1]);

    for (ll a = 1; a < N; a++){
        A = A + v[a].second - (v[a].first - v[a-1].first) * 2;
        if (a < N-1) {
            ans = max(ans, A+B[a+1]);
        } else {
            ans = max(ans, A);
        }
    }

    return ans;
}

signed main() {
    cin>>N>>C;
    v.resize(N);
    rep(i,0,N){
        cin>>v[i].first>>v[i].second;
    }
    sort(begin(v),end(v));
    // cout<<"f1="<<f1()<<endl;
    // cout<<"f2="<<f2()<<endl;
    cout<<max(max((ll)0,f1()),f2())<<endl;
    return 0;
}


Measured memory_bytes: 2688
A = int(input())
B = int(input())
if A==1 and B == 2:
    print(3)
elif A==1 and B==3:
    print(2)
elif A == 2 and B == 1:
    print(3)
elif A == 2 and B == 3:
    print(1)
elif A == 3 and B == 1:
    print(2)
elif A == 3 and B == 2:
    print(1)

Measured memory_bytes: 3060
import sys

k = int(sys.stdin.readline())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[k-1])


Measured memory_bytes: 38384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
A = np.array(read().split(), np.int8)

counter = np.bincount(A,minlength=4)
S = A.sum()

B = (counter[2]+counter[3])
C = counter[3]

dp = np.zeros((B+1,C+1),np.float64)

p2 = np.tile(np.arange(B+1)[:,None],(1,C+1))
p3 = np.tile(np.arange(C+1)[None,:],(B+1,1))

bc = np.arange(B+1)[:,None]*2+np.arange(C+1)[None,:]*3

for n in range(1,S+1):
    prev = dp
    one = n-bc
    p1 = np.maximum(0,one)
    dp = p1*prev + N
    dp[1:] += p2[1:]*prev[:-1]
    dp[:-1,1:] += p3[:-1,1:]*prev[1:,:-1]
    dp /= (p1+p2+p3)

answer = dp[B-C,C]
print(answer)

Measured memory_bytes: 20864
program test
implicit none
  integer,allocatable::a(:),b(:)
  integer :: N,i,ans,K,Q
  read*,N,K,Q
  allocate(a(Q))
  allocate(b(N))
  read(*,*)(a(i),i=1,Q)
  b=K-Q
  do i=1,Q
  	b(a(i))=b(a(i))+1
  end do
  do i=1,N
  	if(b(i)>0)then
    	print*,'Yes'
    else 
    	print*,'No'
    end if
  end do
end program test

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t K,temp=7,l=1,s=10; cin>>K;
  temp%=K;
  vector<bool> A(K,false);
  while(true){
    if(A.at(temp)){
      l=-1;
      break;
    }
    if(temp%K==0) break;
    A.at(temp) =true;
    temp+=s*7;
    temp%=K;
    s*=10;
    s%=K;
    l++;
  }
  cout<<l;
}


Measured memory_bytes: 3708
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    for (int i = 0; i < b; ++i) {
        cout << string(a, '1') + string(w - a, '0') << endl;
    }
    for (int i = b; i < h; ++i) {
        cout << string(a, '0') + string(w - a, '1') << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
N = gets.to_i
a_list = gets.split.map(&:to_i)
table = Hash.new { 0 }
a_list.each do |a|
  b = [a / 400, 8].min
  table[b] += 1
end
min = begin
  c = (0..7).count { |k| table.key?(k) }
  if c > 0
    c
  else
    table.key?(8) ? 1 : 0
  end
end
max = table[8] + (0..7).count { |k| table.key?(k) }
puts "#{min} #{max}"


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

#define DEBUG(x) cerr << #x << ": " << x << endl;

int main() {
    string s;
    cin >> s;
    cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
use std::collections::{HashMap,HashSet};
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (s,) = input!(String);
    let (t,) = input!(String);

    let mut m = HashMap::new();

    let mut t = t.chars();

    for c in s.chars() {
        let aft = t.next().unwrap();
        if let Some(val) = m.get(&c) {
            if val == &aft {
                continue;
            } else {
                println!("No");
                std::process::exit(0);
            }
        }

        m.insert(c, aft);
    }

    let set = m.values().collect::<HashSet<_>>();

    if set.len() == m.len() {
        println!("Yes");
    } else {
        println!("No");
    }

}

fn main() {
    solve();
}



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

int main(){
    int n, d[50];
    cin >> n;
    for(int i=0;i<n;++i) cin >> d[i];

    int64_t ans = 0;
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

int main()
{
  vector<int> dp(1000+1, 0);
  for (int i = 1; i < 1000; ++i) {
    int sum = i;
    for (int j = i+1; j < 1000; ++j) {
      sum += j;
      if (sum > 1000)
	break;
      ++dp[sum];
    }
  }

  int N;
  while (cin >> N) {
    if (N == 0)
      break;
    cout << dp[N] << endl;
  }
  return 0;
}

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

int main() {
  char c;
  cin >> c;
  if (c == 'a' | c == 'i' | c == 'u' | c == 'e' | c == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
string s;
int main(){
	cin>>n>>s;
	for (int i=0;i<n;i++)
		if (s[i]=='(')
			a++;
		else if (a>0)
			a--;
		else
			b++;
	for (int i=0;i<b;i++) s='('+s;
	for (int i=0;i<a;i++) s+=')';
	cout<<s<<endl;
	return 0;
}

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

int main(){
    long long A, B, N;
    cin >> N >> A >> B;
    long long totalBall = A + B;
    if( totalBall == 0){
        cout << 0 << endl;
        return 0;
    }
    long long amariBlueBall = N % totalBall;
    long long circleNum = (long long)((N - amariBlueBall) / totalBall);
    amariBlueBall = min(A, amariBlueBall);
    cout << circleNum * A + amariBlueBall << endl;
    return 0;
}

Measured memory_bytes: 256
// explanation
// https://scrapbox.io/esaka-sandbox/Educational_DP_Contest_%2F_DP_%E3%81%BE%E3%81%A8%E3%82%81%E3%82%B3%E3%83%B3%E3%83%86%E3%82%B9%E3%83%88_-_O_-_Matching

package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

// Mod -
const Mod = int(1e9) + 7 // mod

func main() {
	var N int
	fmt.Scanf("%d", &N)

	a := make([][]int, N)
	for i := 0; i < N; i++ {
		a[i] = make([]int, N)
		for j := 0; j < N; j++ {
			//a[i][j] = ReadInt()
			fmt.Scanf("%d", &a[i][j])
		}
	}
	dp := make([]int, 1<<N)
	dp[0] = 1
	for s := 0; s < (1 << N); s++ {
		i := bits.OnesCount(uint(s))
		for j := 0; j < N; j++ {
			if s>>j&1 == 0 && a[i][j] == 1 {
				nextS := s | 1<<j
				dp[nextS] += dp[s]
				dp[nextS] %= Mod
			}
		}
	}
	fmt.Println(dp[1<<N-1])
}

var reader = bufio.NewReader(os.Stdin)

// Scan -
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}

// ReadInt -
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 18860
#include<bits/stdc++.h>
using namespace std;
int n;
int f[50];
int fib(int k){
	 if (f[k]!=-1)
	    return f[k];
     if (k==0 || k==1) return 1;
	 f[k]=fib(k-1)+fib(k-2);
	 return f[k];	 
}
int main(){
	cin>>n;
	memset(f,-1,sizeof(f));
	cout<<fib(n)<<endl;
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string a, b, c; cin >> a >> b >> c;

	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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


int main(){
	long long a,b,c;
	cin >> a >> b >> c;
	
	if(a%2||b%2||c%2){
		cout << 0 << endl;
		return 0;
	}
	else if(a==b&&b==c){
		cout << -1 << endl;
		return 0;
	}
	
	
	long long x,y,z,cnt = 1;
	while(1){
		x=b/2+c/2;
		y=a/2+c/2;
		z=a/2+b/2;
		if(x%2||y%2||z%2) break;
		a=x,b=y,z=c;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	int saishou = 1e9;
	rep(i, 26) {
		int saidai = 0;
		char c = 'a' + i;
		int mae = -1;
		rep(j, S.size()) {
			if (S[j] == 'a' + i) {
				saidai = max(saidai, j - mae - 1);
				mae = j;
			}
		}
		saidai = max(saidai, (int)S.size() - mae - 1);
		saishou = min(saishou, saidai);
	}

	co(saishou);

	Would you please return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    s = input().rstrip()
    print(s.count("ABC"))
    return


#main
if __name__ == '__main__':
    solve()


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

int z;
long long dp[3005][3005];
long long arr[3005];

long long rekur(int a,int s)
{
	if(s-a==1)return max(arr[a],arr[s]);
	if(s-a==0)return arr[a];
	if(dp[a][s]!=-1)return dp[a][s];
	
	dp[a][s]=0;
	
	dp[a][s]=max(arr[a]+min(rekur(a+2,s),rekur(a+1,s-1)), arr[s]+min(rekur(a+1,s-1),rekur(a,s-2)));
	return dp[a][s];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	memset(dp,-1,sizeof(dp));
	cin>>z;
	long long total=0;
	for(int q=1;q<=z;q++)
	{
		cin>>arr[q];
		total+=arr[q];
	}
	
	long long asd=rekur(1,z);
	long long dsa=total-asd;
	asd=asd-dsa;
	cout<<asd<<endl;
}

Measured memory_bytes: 70912
#include <iostream>
#include <stdio.h>
using namespace std;

int search(int A[], int n, int key) {
    int i = 0;
    A[n] = key;
    while (A[i] != key) i++;
    return i != n;
}

int main()
{
    int i, n, A[10000 + 1], q, key, sum{0};

    cin >> n;
    for (i = 0; i < n; i++) scanf("%d", &A[i]);

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &key);
        if (search(A, n, key)) sum++;
    }
    printf("%d\n",sum);
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

const int MAXN = 100005;

int path[2*MAXN], depth[2*MAXN], idx[MAXN];     // idx : the index of node in dfs path

int par[MAXN];
vi adjList[MAXN];

class SparseTable{
private:
    int n, h;
    vvi t;

    int combine(int l, int r){
        if (l == -1 || r == -1) return max(l,r);

        return depth[l] < depth[r] ? l : r;
    }
public:
    SparseTable(int size){
        n = size; h = ( n == 1 ? 1 : ceil(log2(n)));
        t.assign(h, vi());

        t[0].assign(n,0);
        for (int i=0; i<n; i++) t[0][i] = i;
        for (int i=1; i<h; i++){
            t[i].assign(n,0);
            for (int j=0; j+(1<<i)<=n; j++){
                t[i][j] = combine(t[i-1][j],t[i-1][j+(1<<(i-1))]);
            }
        }
    }
    int query(int l, int r){                            // query in range v[l,r]
        int p = 31 - __builtin_clz(r-l+1);
        return combine(t[p][l],t[p][r-(1<<p)+1]);
    }
};

int cnt = 0;

// build dfs path, depth
void dfs(int curr, int d){
    idx[curr] = cnt;
    path[cnt] = curr;
    depth[cnt++] = d;
    for (int i=0; i<adjList[curr].size(); i++){
        dfs(adjList[curr][i],d+1);

        path[cnt] = curr;
        depth[cnt++] = d;
    }
}
int N, M, Q, v;

int main(){

    memset(par,-1,sizeof(par));

    scanf("%d",&N);
    for (int u=0; u<N; u++){
        scanf("%d",&M);

        for (int i=0; i<M; i++){
            scanf("%d",&v);

            par[v] = u;
            adjList[u].push_back(v);
        }
    }

    int root;
    for (int i=0; i<N; i++) if (par[i] == -1) root = i;
    
    dfs(root,0);

    SparseTable st(cnt);

    scanf("%d",&Q);
    for (int i=0; i<Q; i++){
        int u, v, l, r;
        scanf("%d%d",&u,&v);

        l = idx[u];
        r = idx[v];
        if (l > r) swap(l,r);

        int id = st.query(l,r);
        printf("%d\n",path[id]);
    }

    return 0;
}

Measured memory_bytes: 27564
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<Int,Int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

Int dp[100][3][1010];
vector<vector<pint> > river;
Int k[200];

Int myabs(Int a){
	if(a<0)return -a;
	else return a;
}

int main() {
	Int n,m;
	while(cin>>n>>m,n){
		memset(dp,-1,sizeof(dp));
		river.clear();
		Int i,j;
		vector<pint> buf;
		for(i=0;i<n;i++){
			river.push_back(buf);
			k[i]=in();
			Int x,d;
			for(j=0;j<k[i];j++){
				cin>>x>>d;
				river[i].push_back(mp(x,d));
			}
		}
		Int from,to,cost;
		for(i=0;i<k[0];i++){
			dp[0][0][river[0][i].first]=0;
		}
		for(i=0;i<k[1];i++){
			dp[1][1][river[1][i].first]=0;
		}
		for(i=0;i<k[0];i++){
			for(j=0;j<k[1];j++){
				from=river[0][i].first;
				to=river[1][j].first;
				cost=(river[0][i].second+river[1][j].second)*myabs(from-to);
				if(dp[0][1][to]==-1||dp[0][1][to]>cost){
					dp[0][1][to]=cost;
				}
			}
		}
		for(i=0;i<=n-3;i++){
			Int t,s;
			for(t=0;t<k[i];t++){
				for(s=0;s<k[i+2];s++){
					for(j=0;j<m;j++){
						from=river[i][t].first;
						to=river[i+2][s].first;
						cost=(river[i][t].second+river[i+2][s].second)*myabs(from-to);
						if(dp[j][0][from]==-1)continue;
						if(dp[j+1][2][to]==-1||dp[j+1][2][to]>dp[j][0][from]+cost){
							dp[j+1][2][river[i+2][s].first]=dp[j][0][river[i][t].first]+cost;
						}
					}
				}
			}
			for(t=0;t<k[i+1];t++){
				for(s=0;s<k[i+2];s++){
					for(j=0;j<=m;j++){
						from=river[i+1][t].first;
						to=river[i+2][s].first;
						cost=(river[i+1][t].second+river[i+2][s].second)*myabs(from-to);
						if(dp[j][1][from]==-1)continue;
						if(dp[j][2][to]==-1||dp[j][2][to]>dp[j][1][from]+cost){
							dp[j][2][river[i+2][s].first]=dp[j][1][river[i+1][t].first]+cost;
						}
					}
				}
			}
			for(t=0;t<1010;t++){
				for(j=0;j<=m;j++){
					dp[j][0][t]=dp[j][1][t];
					dp[j][1][t]=dp[j][2][t];
					dp[j][2][t]=-1;
				}
			}
		}
		Int res=100100100;
		res*=100100100;
		for(i=0;i<1010;i++){
			for(j=0;j<=m;j++){
				if(dp[j][1][i]!=-1)chmin(res,dp[j][1][i]);
			}
		}
		for(i=0;i<1010;i++){
			for(j=0;j<=m-1;j++){
				if(dp[j][0][i]!=-1)chmin(res,dp[j][0][i]);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3376
a,b,c,d=map(int, input().split())
mod=998244353
if a==c and b==d:
  print(1)
  exit()
else:
  dp=[[0]*(d+1) for _ in range(c+1)]
  for i in range(a,c+1):
    for j in range(b,d+1):
      if i==a and j==b:
        dp[i][j]=1
      else:
        dp[i][j]=dp[i][j-1]*i+dp[i-1][j]*j-dp[i-1][j-1]*(i-1)*(j-1)
        dp[i][j]%=mod
print(dp[c][d])

Measured memory_bytes: 136860
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int H, W; 
  cin >> H >> W;

  vector<string> s(H);
  REP(i, H) cin >> s[i];

  vector<bool> ok(W, true);
  REP(j, W){
    bool flag = true;
    REP(i, H){
      if(s[i][j] == '#') flag = false;
    }
    if(flag) ok[j] = false;
  }


  REP(i, H){
    bool flag = false;
    REP(j, W){
      if(s[i][j] == '#') flag = true;
    }
    if(flag){
      REP(j, W){
        if(ok[j]) cout << s[i][j];
      }
      cout << "\n";
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int set;
  int i;
  int a;
  int b;
  int c;
  scanf("%d", &set);
  for (i = 0; i < set; i++){
      scanf("%d%d%d", &a, &b, &c);
     if ((a * a == b * b + c * c)||(b * b == a * a + c * c)||(c * c == b * b + a * a)){
	   printf("YES\n");
         }
	 else{
	   printf("NO\n");
		 }
  }
  return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef unsigned long long ll;

int main(){
	int n,m,t,sum=0;
	cin>>m>>n;
	For(i,0,n){
		cin>>t;
		sum+=t;
	}
	if (sum>=m)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main() {
  int N,j, *A,flag = 1,dummy,count = 0;

  scanf("%d",&N);
  A = (int *)malloc(N * sizeof(int));
  for(j = 0;j < N;j++) {
    scanf("%d",&A[j]);
  }
  while(flag) {
    flag = 0;
    for(j = N - 1;j != 0;j--){
      if(A[j] < A[j - 1]){
	dummy = A[j];
	A[j] = A[j - 1];
	A[j - 1] = dummy;
	flag = 1;
	count++;
      }
    }
  }
  for(j = 0;j < N;j++){
    printf("%d",A[j]);
    if(j != N - 1) printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}


Measured memory_bytes: 2144
import java.util.Scanner;

public class Main {

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

		String A = sc.next();
		String B = sc.next();
		String ans = "";

		if (A.length() < B.length()) {
			ans = "LESS";
		} else if (A.length() > B.length()) {
			ans = "GREATER";
		} else {
			for (int i = 0; i < A.length(); i++) {
				if (A.charAt(i) > B.charAt(i)) {
					ans = "GREATER";
					break;
				} else if (A.charAt(i) < B.charAt(i)) {
					ans = "LESS";
					break;
				} else {
					ans = "EQUAL";
					break;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22740
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		long result = 0;
		long cnt = 0;
		for(int i = 0; i < s.length(); i++){
		    if(s.charAt(i) == 'g'){
		        if(cnt > 0){
		            result++;
		            cnt--;
		        }else{
		            cnt++;
		        }
		    }else{
		        if(cnt > 0){
		            cnt--;
		        }else{
		            result--;
		            cnt++;
		        }
		    }
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 24532
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

using namespace std;

#define li long long int
#define ld long double
const int MX1 = 1e5 + 5;
const int MX2 = 1e6 + 5;
const li inf = 4e18;
const li mod = 1e9 + 7;

li power(li a, li b) { li res = 1; while (b) { if (b % 2) res = (res * a) % mod;
a = (a * a) % mod; b /= 2; } return res; }

li mmi(li a) { return power(a, mod - 2); }

li cntbit(li n) { li cnt = 0; while (n) { n &= (n - 1); cnt++; } return cnt; }

int n, m;

void solve() {
    cin >> n >> m;
    int ans = 1;
    for (int i = 1; i * 1ll * i <= m; i++) {
        if (m % i == 0) {
            int j = m / i;
            if (i >= n) ans = max(ans, j);
            if (j >= n) ans = max(ans, i);
        }
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
	int a[55][2];
	int b[55][2];
	int n,m,i,j,k,x,y;
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> a[i][0] >> a[i][1];
	}
	for(i=0;i<m;i++){
		cin >> b[i][0] >> b[i][1];
	}
	for(i=0;i<n;i++){
		k=abs(a[i][0]-b[0][0])+abs(a[i][1]-b[0][1]);
		x=k;
		y=0;
		for(j=1;j<m;j++){
			k=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]);
			if(k<x){
				x=k;
				y=j;
			}
		}
		cout << y+1 << endl;
	}
	cout << endl;
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int m = Integer.parseInt(lines[1]);
        int[] rowSum = new int[m];
        for (int i = 0; i < n; i++) {
            lines = br.readLine().split(" ");
            int columnSum=0;
            for (int j = 0; j < m; j++) {
                 int e= Integer.parseInt(lines[j]);
                 columnSum+=e;
                 rowSum[j]+=e;
                 System.out.print(e+" ");
            }
            System.out.println(columnSum);
        }
        int totalSum=0;
        for(int i=0;i<m;i++){
            totalSum+=rowSum[i];
            System.out.print(rowSum[i]+" ");
        }
        System.out.println(totalSum);

    }
}

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

vector<int> route = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};

int main() {
    int n, s, t;
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> s >> t;
        int m = route.size();
        int l = -1, r = -1;
        for (int j=1; j<=m; ++j) {
            for (int k=0; k+j-1<m; ++k) {
                if (route[k] == s && route[k+j-1] == t) {
                    l = k;
                    r = k+j-1;
                    break;
                }
            }
            if (0 <= l) {
                break;
            }
        }
        for (int i=l; i<=r; ++i) {
            cout << (i == l ? "" : " ") << route[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007 //1000000000000000003
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

const int MAX = 100010;
ll fac[MAX];
void facinit() { // a! mod
  fac[0]=fac[1] = 1;
  reps(i, 2, MAX){
    fac[i] = fac[i - 1] * i % MOD;
  }
}


void Main(){

  int N,M;
  cin>>N>>M;

  if(abs(N-M)>1){
    cout<< 0<<"\n";
    return;
  }
  ll ans=1;

  facinit();

  ans=fac[N]*fac[M]*((N==M)+1)%MOD;

  cout<< ans<<"\n";


}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll calc(ll x){
	if(x <= 0) return 0;
	ll res = 0;
	rep(i,40){
		ll hoge = (1LL << (i+1));
		ll foo = x / hoge;
		ll bar = x % hoge;
		ll cnt = foo * hoge / 2;
		cnt += max(bar - hoge / 2 + 1, 0LL);
		if(cnt%2 == 1) res |= (1LL << i);
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	ll ans;
	if(a == 0) ans = calc(b);
	else ans = calc(b) ^ calc(a-1);
	cout << ans << endl;
	return 0;
}


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

using namespace std;
long long mod,n,dp[2000005],kq,T[2000005],bd,kt,x;
int main()
{
   
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    mod=1000000007;
    dp[1]=dp[0]=1;T[0]=1;T[1]=2;
    for (long long i=2;i<=2*n;++i)
    {
        bd=i-n-1;
        kt=min(n-2,i-3);

        dp[i]=dp[i-1];
        T[i]=(T[i-1]+dp[i])%mod;
        if (kt<0) continue;
        x=T[kt];
        if (bd>0) x=(x-T[bd-1]+mod)%mod;
        dp[i]=(dp[i]+x)%mod;
        T[i]=(T[i]+x)%mod;
    }
    kq=(dp[2*n]+dp[n-1]*(n-1)%mod)%mod;
    for (int i=0;i<=n-2;++i) kq=(kq+dp[i]*(n-1)%mod*(n-1)%mod)%mod;
    cout<<kq;
    return 0;
}


Measured memory_bytes: 31488
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n;
  scanf("%d", &n);
  vector<ii> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i].first);
    b[i].second = i;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  bool found = false;
  for (int i = 0; i < n; ++i) {
    if (a[i].first > b[i].first) {
      found = true;
      break;
    }
  }
  if (found) {
    puts("No");
    return 0;
  }
  found = false;
  for (int i = 1; i < n; ++i) {
    if (a[i].first <= b[i - 1].first) {
      found = true;
      break;
    }
  }
  if (found) {
    puts("Yes");
    return 0;
  }
  vector<int> p(n);
  for (int i = 0; i < n; ++i) {
    p[a[i].second] = b[i].second;
  }
  int cnt = 1;
  for (int i = p[0]; i != 0; i = p[i]) ++cnt;
  // trace(cnt);
  puts(cnt == n ? "No" : "Yes");
  return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>

int n, A[50];

int solve(int i, int m){
  if (m == 0) return 1;
  if (i >= n) return 0;
  int res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}

int main(){
  int q, M, i;

  scanf("%d", &n);
  for (i=0; i<n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for (i=0; i<q; i++){
    scanf("%d", &M);
    if (solve(0, M)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 2108
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 105*3;

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    int a,b;
    while (cin >> a >> b) {
        string ans = "No";
        FOR(c,1,4) if (a*b*c & 1)
            ans = "Yes";
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
    char a,b;
    cin >> a >> b;
    if(a>b){
        cout << ">" << endl;
    }
    else if(a<b){
        cout << "<" << endl;
    }
    else if (a==b){
        cout << "=" << endl;
    }
}

Measured memory_bytes: 256
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = set(map(int, input().split()))
    NP = [i for i in range(0, 102) if i not in P]
    mx = 102
    for p in NP:
        if abs(x-p) < abs(x-mx):
            mx = p
    print(mx)

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

typedef long  long ll;
#define FF first
#define SS second
#define INF 2000000000


int main(){
    ll n, k;
    cin >> n >> k;

    vector<int> health;

    for(int i = 0; i < n; ++i){
        ll mons;
        cin >> mons;
        health.push_back(mons);

    }

    sort(health.begin(), health.end());

    ll ans = 0;

    for(int i = 0; i < n-k; ++i){
        ans+=health[i];
    }
    cout << ans;

}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

int main() {
    // input
    string s;
    cin >> s;
    // solve
    reverse(ALL(s));
    int n = s.size();
    vector<string> t = {"dream", "dreamer", "erase", "eraser"};
    // output
    rep(i, 4) {
        reverse(ALL(t[i]));
    }
    bool flag = true;
    int i = 0;
    while (i < n and flag) {
        if (s[i] == 'm') {
            rep(j, 5) {
                if (i+j >= n or s[i+j] != t[0][j]) {
                    flag = false;
                    break;
                }
            }
            i += 5;
        } else if (s[i] == 'e') {
            rep(j, 5) {
                if (i+j >= n or s[i+j] != t[2][j]) {
                    flag = false;
                    break;
                }
            }
            i += 5;
        } else if (s[i] == 'r') {
            if (i+2 >= n or s[i+1] != 'e') {
                flag = false;
                break;
            } else {
                if (s[i+2] == 's') {
                    rep(j, 6) {
                        if (i+j >= n or s[i+j] != t[3][j]) {
                            flag = false;
                            break;
                        }
                    }
                    i += 6;
                } else if (s[i+2] == 'm') {
                    rep(j, 7) {
                        if (i+j >= n or s[i+j] != t[1][j]) {
                            flag = false;
                            break;
                        }
                    }
                    i += 7;
                } else {
                    flag = false;
                    break;
                }
            }
        } else {
            flag = false;
            break;
        }
    }
    if (flag) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  vector<vector<int> > G(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int d[n];
  memset(d,-1,sizeof(d));
  queue<int> q;
  d[0]=0;
  q.push(0);
  while(!q.empty()){
    int v=q.front();q.pop();
    for(int u:G[v]){
      if(d[u]<0){
	d[u]=d[v]+1;	
	q.push(u);
      }
    }
  }
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<endl;;
  return 0;
}

Measured memory_bytes: 3116
N,K=map(int, input().split())
p = list(map(int, input().split()))

p = [(n+1)/2 for n in p]
import numpy as np
s = np.cumsum(p)

e=s[K-1]
max_e=e
for i in range(1,N-K):
  e=s[i+K]-s[i]
  max_e = max(max_e, e)
    
print(max_e)

Measured memory_bytes: 24548
//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}
	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rds(char *s, int &x) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (x = 0; c >= 33 && c <= 126; s[++x] = c, c = gc());
		s[x+1] = '\0';
	}
	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	inline void prints(string s) {
		int x = s.length();
		while (t < x) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rds;
using io::print;
using io::prints;

const int N = 1e6 + 7;
int n, a[N], c[N];
char s[N];

int main() {
	rd(n), rds(s, n), --n;
	for (int i = 1; i <= n; i++) a[i] = abs(s[i] - s[i+1]);
	bool ok = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] == 1) ok = 1;
	if (!ok) for (int i = 1; i <= n; i++) a[i] >>= 1;
	for (int i = 1; i <= n; i++) {
		int x = i;
		while (!(x & 1)) ++c[i], x >>= 1;
		c[i] += c[i-1];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans ^= c[n-1] - c[i-1] - c[n-i] ? 0 : (a[i] & 1);
	if (!ok) ans <<= 1;
	print(ans);
	return 0;
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  lol a, b;
  cin >> a >> b;
  if(a == 1 || b == 1){
    cout << 1 << '\n';
  } else{
    a *= b;
  cout << UPDight(a, 2) << '\n';
  }return 0;
}


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

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define mod (ll)(1e9 + 7)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000              //1e9
#define LLINF 2000000000000000000LL //2e18

const int nmax = 8;
bool graph[nmax][nmax] = {false};

int solve(int v, int N, bool visited[nmax])
{
    bool isAll = true;
    REP(i, N)
    {
        if (visited[i] == false)
            isAll = false;
    }
    if (isAll)
        return 1;
    int ret = 0;
    REP(i, N)
    {
        if (graph[v][i] == true && visited[i] == false)
        {
            visited[i] = true;
            ret += solve(i, N, visited);
            visited[i] = false;
        }
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    REP(i, M)
    {
        int s, e;
        cin >> s >> e;
        graph[s - 1][e - 1] = graph[e - 1][s - 1] = true;
    }
    bool visited[nmax] = {false};
    visited[0] = true;
    cout << solve(0, N, visited) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
typedef long long int ll;
using namespace std;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;

  ll a_num, b_num;
  b_num = b/x + 1;

  if(a > 1) a_num = (a-1)/x + 1;
  else if(a == 1) a_num = 1;
  else a_num = 0;

  cout << b_num - a_num << endl;

}


Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1e9+7;


int main(){

int H,N;
cin>>H>>N;
int A[N+1],B[N+1];

rep3(i,N){
    cin>>A[i]>>B[i];
}
ll dp[H][N+1];
rep(i,H)rep(j,N+1)dp[i][j]=1LL<<50;
rep(i,N+1){
    dp[0][i]=0;
}
ll ans=1LL<<50;
rep(i,H){
    rep3(j,N){
        dp[i][j]=min(dp[i][j],dp[i][j-1]);
        if(i+A[j]<H){
            dp[i+A[j]][j]=min(dp[i+A[j]][j],dp[i][j]+B[j]);
        }
        
        if(i+A[j]>=H){
            ans=min(ans,dp[i][j]+B[j]);
        }
        

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

Measured memory_bytes: 81784
s=list(input())
a=int(s[0])
b=int(s[1])
c=int(s[2])
d=int(s[3])
number=[a,b,c,d]

plmi=["+","-"]

def plus(a,b,i):
    if i==0:
        return a+b
    else:
        return a-b
    
ans=[]
def plusminus(a,b,c,d,i,j,k):
    global ans
    res1=plus(a,b,i)
    res2=plus(res1,c,j)
    res3=plus(res2,d,k)
    if res3==7:
        ans.append([i,j,k])
    
    
    
    
    
    


for i in range(2):
    for j in range(2):
        for k in range(2):
            plusminus(a,b,c,d,i,j,k)

kotae=ans[0]
hugou1=plmi[kotae[0]]
hugou2=plmi[kotae[1]]
hugou3=plmi[kotae[2]]
a=str(a)
b=str(b)
c=str(c)
d=str(d)

print(a+hugou1+b+hugou2+c+hugou3+d+"=7")
            

Measured memory_bytes: 3064
n=int(input())
s=input()
dict={}
dict["R"]=[]
dict["G"]=[]
dict["B"]=[]
for i in range(n):
  if s[i]=="R":
    dict["R"].append(i)
  elif s[i]=="G":
    dict["G"].append(i)
  elif s[i]=="B":
    dict["B"].append(i)
  else:
    raise Exception
res=len(dict["R"])*len(dict["G"])*len(dict["B"])
for r in dict["R"]:
  for g in dict["G"]:
      if (r+g)%2==0:
        if s[(r+g)//2]=="B":
          res-=1
      try:
        if s[2*r-g]=="B" and 2*r-g>=0:
          	res-=1
      except:pass
      try:
        if s[2*g-r]=="B" and 2*g-r>=0:
          res-=1
      except:pass      
      
print(res)

Measured memory_bytes: 70056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll int n,a[100001],q,sum=0;
cin>>n;
map<ll int,ll int>m1;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    m1[a[i]]++;
    sum+=a[i];
}
cin>>q;
while(q--)
{
    int a,b;
    cin>>a>>b;
    sum=sum-m1[a]*a;
    sum=sum+m1[a]*b;
    m1[b]=m1[b]+m1[a];
    m1[a]=0;
    cout<<sum<<endl;
}

}


Measured memory_bytes: 10328