akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll k, a, b; cin >> k >> a >> b;
  ll d = b-a;
  ll ans = 1;
  if (d <= 2) ans += k;
  else {
    rep(i,k) {
      if (i <= k - 2 && ans >= a && d > 2) {
        ans += d;
        i++;
      } else {
        ans++;
      }
      //cout << i << ":" << ans << endl;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int ans = A * B;
  string a;
  if (ans % 2 == 0) {
    a = "No";
  } else {
    a = "Yes";
  }
  cout << a << endl;
}

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

S = input()
K = int(input())

count = 0
slist = list(S)
while(len(slist) > 0):
    a = slist.pop(0)
    count += 1
    if a != '1':
        print(a)
        sys.exit(0)
    if count == K:
        print(1)
        sys.exit(0)
print(1)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

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

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll x[200010], y[200010];
ll ans = -INF;

int main() {
  std::cin >> N;

  rep( i, N )
    std::cin >> x[i] >> y[i];

  rep( s1, 2 ) rep( s2, 2 ) {
    ll sg1 = s1 ? -1 : 1;
    ll sg2 = s2 ? -1 : 1;

    ll ma = -INF, mi = INF;

    rep( i, N ) {
      ll v = x[i]*sg1+y[i]*sg2;

      chmax( ma, v );
      chmin( mi, v );
    }

    chmax( ans, ma-mi );
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6760
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

	using i8 = std::int_fast8_t;
	using i32 = std::int_fast32_t;
	using i64 = std::int_fast64_t;
	using u8 = std::uint_fast8_t;
	using u32 = std::uint_fast32_t;
	using u64 = std::uint_fast64_t;
	using isize = std::ptrdiff_t;
	using usize = std::size_t;

	class rep {
		const usize f, l;

	public:
		class itr {
			friend rep;
			usize i;
			constexpr itr(const usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { ++i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr rep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(f); }
		constexpr itr end() const noexcept { return itr(l); }
	};
	class revrep {
		const usize f, l;

	public:
		class itr {
			friend revrep;
			usize i;
			constexpr itr(usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { --i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
		constexpr itr begin() const noexcept { return itr(l); }
		constexpr itr end() const noexcept { return itr(f); }
	};
	template <class T> using vec_alias = std::vector<T>;
	template <class T> auto md_vec(const usize n, const T &value) {
		return std::vector<T>(n, value);
	}
	template <class... Args> auto md_vec(const usize n, Args... args) {
		return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
	}
	template <class T> constexpr T difference(const T &a, const T &b) {
		return a < b ? b - a : a - b;
	}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include<cassert>

namespace n91 {
	bool solve() {
		usize n;
		std::cin >> n;
		auto g = md_vec(n, 0, static_cast<usize>(0));
		for (const auto i : rep(1, n)) {
			usize a, b;
			std::cin >> a >> b;
			--a;
			--b;
			g[a].emplace_back(b);
			g[b].emplace_back(a);
		}
		std::vector<usize> dist(n, 0);
		const auto dfs = [&](const auto &dfs, const usize v, const usize p)->void {
			for (const auto e : g[v]) {
				if (e != p) {
					dist[e] = dist[v] + 1;
					dfs(dfs, e, v);
				}
			}
		};
		dfs(dfs, 0, n);
		const auto itr = std::max_element(dist.begin(), dist.end());
		*itr = 0;
		dfs(dfs, itr - dist.begin(), n);
		const usize diam = *std::max_element(dist.cbegin(), dist.cend());
		return diam % 3 == 2 || diam % 3 == 0;
	}

	void main_() { std::cout << (solve() ? "First" : "Second") << std::endl; }

} // namespace n91

int main() {
	n91::main_();
	return 0;
}


Measured memory_bytes: 19968
import sys
# read = sys.stdin.read
readline = sys.stdin.readline
# readlines = sys.stdin.readlines
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n = readline().rstrip()
    digits = [int(d) for d in n]
    print('Yes' if int(n) % sum(digits) == 0 else 'No')

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
S = input()
N = len(S)
dp = [[0 for _ in range(13)] for _ in range(N+1)]
dp[0][0] = 1
mod = 10 ** 9 + 7
for i in range(N):
    for j in range(13):
        if S[i] == '?':
            for d in range(10):
                dp[i+1][(j*10+d)%13] += dp[i][j]%mod
        else:
            d = int(S[i])
            dp[i+1][(j*10+d)%13] += dp[i][j]%mod
print(dp[N][5]%mod)                

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[105];
ll dp[105][100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, W;
    cin >> N >> W;
    REP(i, N) {
        cin >> A[i].first >> A[i].second;
    }

    REP(i, N) {
        REP(j, W + 1) {
            dp[i + 1][j] = std::max(dp[i][j], dp[i + 1][j]);
            if (j + A[i].first <= W)
                dp[i + 1][j + A[i].first] = std::max(dp[i + 1][j + A[i].first], dp[i][j] + A[i].second);
        }
    }

    ll ans = 0;
    REP(i, W + 1) {
        ans = std::max(ans, dp[N][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 79360
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
//import org.apache.commons.lang3.StringUtils;
 
 
/**
 *
 * @author aj
 */
public class Main {
    
    public static void main(String[] args){
        try {
            //Scanner sc = new Scanner(System.in);
            BufferedInputStream bf = new BufferedInputStream(System.in);
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(bf, StandardCharsets.UTF_8));
            OutputStream out = new BufferedOutputStream ( System.out );
            
            int n = Integer.parseInt(in.readLine());
            String[] sh = in.readLine().split(" ");
            int[] h = new int[n];
            for(int i=0;i<n;i++) h[i] = Integer.parseInt(sh[i]);
            int sum = h[0];
            for(int i=1;i<n;i++){
                if (h[i]>h[i-1]) sum += (h[i] - h[i-1]);
            }
            out.write((sum+"\n").getBytes());
            out.flush();
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}

Measured memory_bytes: 23124
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    int mx=-100000;
    int p=a+b;
    if(p>mx) mx=p;
    p=a-b;
    if(p>mx) mx=p;
    p=(a*b);
    if(p>mx) mx=p;
    printf("%d\n",mx);
  
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define INFTY (1 << 30)

class Edge {
public:
    int t, w;
    Edge(){}
    Edge(int t, int w): t(t), w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
    for ( int i = 0; i < n; i++ ) d[i] = INFTY;
    queue<int> Q;
    Q.push(s);
    d[s] = 0;
    int u;
    while ( !Q.empty() ) {
        u = Q.front(); Q.pop();
        for ( int i = 0; i < G[u].size(); i++ ) {
            Edge e = G[u][i];
            if ( d[e.t] == INFTY ) {
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }
    }
}

void solve() {
    bfs(0);
    int maxv = 0;
    int tgt = 0;
    for ( int i = 0; i < n; i++ ) {
        if ( d[i] == INFTY ) continue;
        if ( maxv < d[i] ) {
            maxv = d[i];
            tgt = i;
        }
    }
    
    bfs(tgt);
    maxv = 0;
    for ( int i = 0; i < n; i++ ) {
        if ( d[i] == INFTY ) continue;
        maxv = max(maxv, d[i]);
    }
    
    cout << maxv << endl;
}

int main() {
    int s, t, w;
    cin >> n;
    
    for ( int i = 0; i < n - 1; i++ ) {
        cin >> s >> t >> w;
        
        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));
    }
    solve();
}


Measured memory_bytes: 9868
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int w = input.nextInt();
        int h = input.nextInt();
        while(input.hasNext()){
            if(w != 0 && h != 0)
                draw(h, w);
            w = input.nextInt();
            h = input.nextInt();
        }
    }
    
    public static void draw(int w, int h){
        for(int i = 0; i < w; i++ )
            System.out.print("#");
        System.out.println();
        for(int j = 0; j < h-2; j++ ){
            System.out.print("#");
            for(int k = 0; k < w-2; k ++ )
                System.out.print(".");
            System.out.println("#");
        }
        for(int l = 0; l < w; l++ )
            System.out.print("#");
        System.out.println();
        System.out.println();
    }
}


Measured memory_bytes: 36904
// C - Lower
// https://atcoder.jp/contests/abc139/tasks/abc139_c
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	var hi = []int{}
	for i := 0; i < n; i++ {
		hi = append(hi, nextInt(sc))
	}

	res, straight_count := 0, 0
	for i := 1; i < n; i++ {
		if hi[i-1] >= hi[i] {
			straight_count++
			res = int(math.Max(float64(res), float64(straight_count)))
		} else {
			straight_count = 0
		}
	}

	fmt.Println(res)
}

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


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

int main()
{
    int k;
    cin >> k;
    vector<ll> a(k);
    for (int i = 0; i < k; i++)
        cin >> a[i];
    ll min_n = 2, max_n = 2;
    for (int i = k - 1; i >= 0; i--)
    {
        ll min_num = ((min_n + a[i] - 1) / a[i]) * a[i];
        ll max_num = (max_n / a[i]) * a[i] + a[i] - 1;
        if (min_num > max_n || max_num < min_n)
        {
            cout << -1 << endl;
            return 0;
        }
        min_n = min_num;
        max_n = max_num;
    }
    cout << min_n << " " << max_n << endl;
}


Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: u8,
        m: u8,
    }
    println!("{}", if n == m {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdlib>
using namespace std;
int main()
{
	int n; 
	bool fl = false;
	cin >>n;
	if((n%100)%10==7) fl=true;
	if((n%100)/10==7) fl=true;
	if(n/100==7) fl=true;
	if(fl)cout<<"Yes"<<endl;
	else cout<<"No"<<endl ;
	return 0;
} 

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;
//ダイクストラプログラム例
//http://www.ss.cs.meiji.ac.jp/CCP024.html
//ワーシャルフロイドプログラム例
//http://pakapa104.hatenablog.com/entry/2016/02/05/225241

int main(){
	int n, m, MAX = 99999999;
	gets(n) gets(m)
	int a[m], b[m], c[m];
	for (int i = 0; i < m; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
		a[i] -= 1;
		b[i] -= 1; //indexのずれ
	}
	int dist[n][n]; //最短経路格納

	rep(i,n){ //iからjまでの最短経路、塗りつぶし
		rep(j, n){
			dist[i][j] = MAX;
		}
		dist[i][i] = 0;
	}
	rep(i,m){ //辺の距離を与えらた数で初期化
		dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
		dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
	}
	rep(k, n){ //ワーシャルフロイド
		rep(i, n){
			rep(j, n){
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
			}
		}
	}
	int result = 0;
	//2点間を結ぶ辺よりも小さいコストで移動できる→
	//その辺は最短経路には使われない
	rep(i, m){
		if (dist[a[i]][b[i]] < c[i]){ 
			result += 1;
		}
	}
	puts(result)
}


Measured memory_bytes: 256
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())
# 空白区切りの数列をリストに代入
t = [int(i) for i in input().split()] 

t.sort()

for i in range(1,n):
    if t[i]==t[i-1]:
        print("NO")
        exit()
print("YES")


Measured memory_bytes: 34144
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int L, N, R, res;
int main(){
  int Lj4PdHRW;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    rd(L);
    rd(R);
    res += R-L+1;
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20170908-1 [beta]

// --- original code ---
// int N, L, R, res;
// {
//   rd(N);
//   rep(N){
//     rd(L,R);
//     res += R-L+1;
//   }
//   wt(res);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
signed main(){
    int N;
    string S;
    cin >> N >> S;
    int l = 0;int r = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == ')') {
            if(r > 0) {
                r--;
            }
            else {
                l++;
            }
        }
        else {
            r++;
        }
    }
    for(int i = 0; i < l; i++) {
        cout << '(';
    }
    cout << S;
    for(int i = 0; i < r; i++) {
        cout << ')';
    }
    cout << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int d, p, s;
    cin >> d >> p >> s;
    int c = p * s;
    if (d <= c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n; cin>>n;
	string s,t,ans=""; cin>>s>>t;
	for(auto i=0;i<n;++i){
		ans+=s[i];
		ans+=t[i];
	}
	cout<<ans<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[100],n;
  long long p[21],q[21];
  cin>>n;
  for(i=0;i<n;i++)
    cin>>a[i];
  memset(p,0,sizeof(p));
  p[a[0]]=1;
  for(i=1;i<n-1;i++){
    memset(q,0,sizeof(q));
    for(j=0;j<21;j++){
      if(p[j]){
	if(0<=j+a[i]&&j+a[i]<=20)
	  q[j+a[i]]+=p[j];
	if(0<=j-a[i]&&j-a[i]<=20)
	  q[j-a[i]]+=p[j];
      }
    }
    memcpy(p,q,sizeof(p));
  }
  cout<<p[a[i]]<<endl;
  return 0;
}

Measured memory_bytes: 0
S = list(input())

target = '0'
cnt = 0
for i in range(len(S)):
  if i == 0:
    target = S[i]
    continue
  if target == S[i]:
    cnt += 1
    if S[i] == '0':
      target = '1'
    else:
      target = '0'
  else:
    target = S[i]
print(cnt)

Measured memory_bytes: 3956
//https://atcoder.jp/contests/dp/tasks/dp_n
//N - Slimes
//区間dp,O(N^3)
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
  std::ifstream in("./test/sample-1.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll N; cin>>N;
  vector<ll> an(N);
  for(auto&& a:an){
    cin>>a;
  }
  vector<ll> sums(N+1);
  FOR(i,0,N){
    sums[i+1]=sums[i]+an.at(i);
  }
  auto sum=[&](ll l, ll r){
    return sums[r]-sums[l];
  };
  dump(sum(0,N));
#if 1
  //forで回す
  constexpr ll INF=2LL<<60;
  vector<vector<ll>> dp(N,vector<ll>(N+1,INF));
  //初期値
  FOR(i,0,N){
    dp[i][i+1]=0;
  }
  FOR(len,2,N+1){
    for(ll l=0;l+len<=N;++l){
      ll r = l+len;
      for(ll k=l+1;k<r;++k){
        dump(l,k,r);
        chmin(dp[l][r],dp[l][k]+dp[k][r]+sum(l,r));
      }
    }    
  }
  dump(dp);
  cout<<dp[0][N]<<endl;
#else
  //メモ化再帰
  //開区間
  vector<vector<ll>> dp(N,vector<ll>(N+1,INT64_MAX));
  function<ll(ll,ll)> dfs=[&](ll l, ll r)->ll{
    if(l+1>=r)return 0;
    if(dp.at(l).at(r)!=INT64_MAX) return dp[l][r];
    ll ret=INT64_MAX;
    FOR(k,l+1,r){
      chmin(ret,dfs(l,k)+dfs(k,r)+sum(l,r));
    }
    dp.at(l).at(r)=ret;
    return ret;
  };
  auto ans=dfs(0,N);
  cout<<ans<<endl;
#endif
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
ll a,b,n,c,d,e;
cin>>n>>a>>b>>c>>d>>e;
 printf("%lld\n",(n-1)/min({a,b,c,d,e})+5);
}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

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

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

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

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
struct Edge{
  int to;
  double cost;
};

struct NODE{
  int pos;
  double cost;
};
bool operator < (const NODE &a,const NODE &b){
  return a.cost > b.cost;
}
vector<Edge> g[100000],rg[100000];

int N;
int s,t;
const ll INF = 1e15;
vector<double> dijkstra(vector<Edge> g[100000], int s){
  priority_queue<NODE> Q;
  Q.push({s,0});
  vector<double> res(N,INF);
  while(Q.size()){
    NODE q= Q.top();Q.pop();
    if(res[q.pos] == INF){
      res[q.pos] = q.cost;
    }
    else{
      continue;
    }
    for(auto n : g[q.pos]){
      Q.push({n.to,q.cost+n.cost});
    }
  }
  return res;
}
struct Bill{
  ll id,x,y;
};
vector<Bill> B(1000);
vector<int> r;
vector<double> dis;
vector<bool> f;

void rdfs(int rs){
  if(f[rs]) return ;
  r.push_back(rs);
  f[rs] = true;
  if(rs == s) return ;
  for(auto e:g[rs]){
    if(dis[rs] == dis[e.to] + e.cost){
      rdfs(e.to);
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n && n){
    N = n;
    rep(i,1000){
      g[i].clear();
    }
    map<int,int> b;
    rep(i,n){
      cin >> B[i].id >> B[i].x >> B[i].y;
      b[B[i].id] = i;
    }
    rep(i,n){
      rep(j,n){
        if(i != j){
          double dis = (B[i].x - B[j].x) * (B[i].x - B[j].x) +  (B[i].y - B[j].y) * (B[i].y - B[j].y);
          dis = sqrt(dis);
          if(dis  <= 50.0){
            g[i].push_back({j,dis});
//             g[j].push_back({i,dis});
          }
        }
      }
    }
    cin >> m;
    rep(i,m){
      cin >> s >> t;
      s = b[s];
      t = b[t];
      dis = dijkstra(g,s);
      r.clear();
      f = vector<bool>(n,false);
      rdfs(t);
      if(dis[t] == INF){
        cout << "NA" << endl;
      }
      else{
        reverse(all(r));
        rep(i,r.size()){
          if(i) cout << ' ';
          cout << B[r[i]].id;
        }
        cout << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 7864
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int N, D1, D2;
void dfs(int x, int y, vi &col, set<pii> &dir, int a=0) {
    if (x < 0 || x >= 2 * N || y < 0 || y >= 2 * N)return;
    if (col[x * 2 * N + y] != -1)return;
    col[x * 2 * N + y] = a;
    each(d, dir) {
        dfs(x + d.first, y + d.second, col, dir, 1 - a);
    }
}

void solve() {
    cin >> N >> D1 >> D2;

    map<int, int> S;
    for (int i = 0; i < 2 * N; ++i) {
        S[i*i] = i;
    }
    auto f = [&](int D) {
        set<pii> dir;
        for (int i = 0; i < 2 * N; ++i) {
            int jj = D - i*i;
            if (S.count(jj)) {
                int j = S[jj];
                for (int a : {-1, 1})for (int b : {-1, 1}) {
                    dir.insert({ a*i, b*j });
                }
            }
        }
        vi col(2 * N * 2 * N, -1);
        rep(x, 2 * N)rep(y, 2 * N) {
            if (col[x * 2 * N + y] == -1) {
                dfs(x, y, col, dir);
            }
        }
        return col;
    };

    auto C1 = f(D1);
    auto C2 = f(D2);

    int cnt[2][2] = {};
    rep(i, 2 * N * 2 * N) {
        cnt[C1[i]][C2[i]]++;
    }

    rep(i, 2)rep(j, 2) {
        if (cnt[i][j] >= N * N) {
            int z = 0;
            rep(x, 2 * N)rep(y, 2 * N) {
                int k = x * 2 * N + y;
                if (C1[k] == i && C2[k] == j) {
                    z++;
                    cout << x << ' ' << y << endl;
                    if (z == N * N) {
                        return;
                    }
                }
            }
        }
    }
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 31872
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define max(x,y) (x)>(y)?(x):(y)
#define min(x,y) (x)>(y)?(y):(x)
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1<<28;
const int maxn=110;
const int maxm=110;
const int maxk=100010;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,w;
int val[4][maxn];
ll sum[4][maxn];
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&n,&w))
    {
        int k[4]={1,1,1,1};
        sum[0][0]=sum[1][0]=sum[2][0]=sum[3][0]=0;
        ll w0=0;
        for(int i=1;i<=n;i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            if(i==1) w0=a;
            val[a-w0][k[a-w0]++]=b;
        }
        sort(val[0]+1,val[0]+k[0]+1,cmp);
        sort(val[1]+1,val[1]+k[1]+1,cmp);
        sort(val[2]+1,val[2]+k[2]+1,cmp);
        sort(val[3]+1,val[3]+k[3]+1,cmp);
        for(int i=0;i<4;i++)
            for(int j=1;j<k[i];j++)
                sum[i][j]=sum[i][j-1]+val[i][j];
        ll ans=0;
        for(int i=0;i<k[0];i++)
            for(int j=0;j<k[1];j++)
            for(int o=0;o<k[2];o++)
            for(int l=0;l<k[3];l++)
            if(w0*i+(w0+1)*j+(w0+2)*o+(w0+3)*l<=w)
            ans=max(ans,sum[0][i]+sum[1][j]+sum[2][o]+sum[3][l]);
        printf("%lld\n",ans);
    }
    return 0;
}


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

int main(void){
    // Your code here!
    string S; cin >> S;
    int max_count = 0;
    int count = 0;
    for(int i=0; i<=S.size(); i++)
    {
        if(S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T')
        {
            count++;
            if(max_count < count) max_count = count;
        }
        else count = 0;
    }
    cout << max_count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>
 
using namespace std;
#define mod 1000000007
#define ll long long 
 
 
 
 
int arr[100009];
int dp[100009];
int n,k;
int solve(int idx ,int k){
      if(idx==n-1){
return 0;}
if(dp[idx]!=-1){
return dp[idx];
}
int ans=INT_MAX;
  for(int i=1;i<=k;i++){
if(idx+i>=n){
break;}
ans=min(ans,solve(idx+i,k)+abs(arr[idx+i]-arr[idx]));
}
return dp[idx]=ans;
}

int main() {
 
	memset(dp, -1, sizeof(dp));
	cin>>n>>k;
 
	for(int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
	}
 
	cout<<solve(0,k)<<endl;
 
	return 0;
}



Measured memory_bytes: 10688
/* Simplicity and Goodness */
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{   
    int a;
    cin >> a;
    cout << a + a * a + a * a * a;
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int fnc(int x){
  if(x%100 != 0 || x == 0) return 0;
  return fnc(x/100) +1;
}

int main(){
  int D,N;
  cin >> D >> N;
  
//  cout << N * pow(100, D) << endl;
  int i = 1;
  int count = 0;
  while(1){
    if(fnc(i) == D){
      count++;
      if (count == N){
        cout << i << endl;
        return 0;
      }
    }
    i++;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

const double PI = 3.1415926535897932384626433832795;

int main() {
  double r, g;
  cin >> r >> g;
  double ans = 2 * g - r;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    cout << (n - 2) / (k - 1) + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <queue>
#include <cmath>
#define read(X) scanf("%d",&X);
#define readLL(X) cin>>X;
#define readN(N,a) for(int i=0;i<N;i++)scanf("%lld",&a[i]);
#define LL long long
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define pii pair<int,int>
using namespace std;
int N, T, K, D;

long long isi[300005];
priority_queue<long long> pq;
long long maks[300005];
long long mins[300005];
int main(){
	read(N);
	readN(N*3, isi);

	int M = N*3;
	long long tot = 0;
	long long best = 0;
	for (int i=0;i<M;i++){
		pq.push(-isi[i]);
		tot += isi[i];
		if (pq.size() < N) continue;
		if (pq.size() > N) {
			tot += pq.top(); 
			pq.pop();
		}
		best = max(best, tot);
		maks[i] = best;
	}

	tot = 0;
	best = 300000000000000LL;
	while (pq.size()) pq.pop();
	for (int i=M-1;i>=0;i--){
		pq.push( isi[i] );
		tot += isi[i];
		if (pq.size() < N) {mins[i] = best; continue;}
		if (pq.size() > N) {
			tot -= pq.top(); 
			pq.pop();
		}
		best = min(best, tot);
		mins[i] = best;
	}
	long long res = -300000000000000LL;
	for (int i=N-1;i<N*2;i++){
		//cout<<i<<" "<<maks[i]<<" "<<mins[i+1]<<endl;
		res = max(res, maks[i] - mins[i+1] );
	}
	cout<<res<<endl;
}

Measured memory_bytes: 8180
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;
void solve(){
    string s;
    cin >> s;
    stack<char> st;
    int cnt = 0;
    for(int i = 0; i < s.size(); i++){
        if(st.empty()) st.push(s[i]);
        else{
            if(st.top() != s[i]){
                st.pop();
                cnt += 2;
            }
            else st.push(s[i]);
        }
    }
    cout << cnt;
}


int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}
// vse dolzhny vyiti v internet po hhtp


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

int a, b;

int main(){
  cin >> a >> b;
  int cnt = 1, num = a;
  while(num < b){
    num += a - 1;
    cnt++;
  }
  if(b == 1) cnt = 0;
  cout << cnt << endl;
}


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

using namespace std;

int main()
{
    
    vector<string> s = {"Sunny", "Cloudy", "Rainy"};

    string n;
    cin >> n;

    for (int i = 0; i < 3; ++i)
    {
        if (s[i] == n)
        {
            cout << s[(1 + i) % 3] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
N, T = [int(x) for x in input().split()]
lst = []
for i in range(N):
    c, t = [int(x) for x in input().split()]
    if (t <= T): lst.append(c)
if (len(lst)):
    lst.sort()
    print(lst[0])
else:
    print('TLE')



Measured memory_bytes: 38256
// 4_abc126_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

vector<vector<pair<int, int>>> g;
vector<int> color;

void dfs(int nd){
    rep(i, g[nd].size()){
        int next = g[nd][i].first;
        int w = g[nd][i].second;
        if(color[next] != -1) continue;

        if(w % 2 == 0) color[next] = color[nd];
        else color[next] = 1 - color[nd];

        dfs(next);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    g.resize(n + 1);
    color.resize(n + 1);
    rep1(i, n){
        color[i] = -1;
    }
    rep(i, n - 1){
        int u, v, w;
        cin >> u >> v >> w;
        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }

    color[1] = 0;
    dfs(1);

    rep1(i, n){
        cout << color[i] << endl;
    }


    return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const int dx[4] = {+1, 0, -1, 0};
const int dy[4] = {0, -1, 0, +1};
const ll INF = 1e10;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    ll cnt = 0, minabs = INF, sum = 0;
    for(ll i=0;i<n;i++){
        if(a[i] < 0) cnt++;
        minabs = min(minabs, abs(a[i]));
        sum += abs(a[i]);
    }
    if(cnt % 2 == 0) cout << sum << endl;
    else cout << sum - 2*minabs << endl;
}


Measured memory_bytes: 1024
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n][m];
    string ss;
    for(ll i=0;i<n;i++){
        cin>>ss;
        for(ll j=0;j<m;j++){
            a[i][j]=ss[j]-'0';
        }
    }
    ll sum[n+1][m+1];
    memset(sum,0,sizeof(sum));
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            sum[i][j]=(a[i-1][j-1])+sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
        }
    }
    /*
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            cout<<sum[i][j]<<" ";
        }
        cout<<"\n";
    }
    */
    vi<ll>cuts;
    ll cs,nn=(1<<(n-1));
    ll ans=n+m;
    ll tAns,pre,tempSum;
    bool cut=false,dontConsider=false;
    //debugg(nn);
    for(ll mask=0;mask<nn;mask++){
        cuts.clear();
        cuts.pb(0);
        for(ll i=0;i<(n-1);i++){
            if(mask&(1LL<<i)){
                cuts.pb(i+1);
            }
        }
        cuts.pb(n);
        cs=cuts.size();
        tAns=cs-2;
        pre=0;
        for(ll j=1;j<=m;j++){
            cut=false;
            for(ll i=1;i<cs;i++){
                tempSum=sum[cuts[i]][j]-sum[cuts[i]][pre]-sum[cuts[i-1]][j]+sum[cuts[i-1]][pre];
                if((tempSum)>k){
                    cut=true;
                }
            }
            if(cut){
                pre=j-1;
                ++tAns;
            }
        }
        dontConsider=false;
        for(ll i=1;i<cs;i++){
            tempSum=sum[cuts[i]][m]-sum[cuts[i]][pre]-sum[cuts[i-1]][m]+sum[cuts[i-1]][pre];
            if(tempSum>k){
                dontConsider=true;
            }
        }
        if(dontConsider){
            continue;
        }
        //cout<<tAns<<"\n";
        ans=min(ans,tAns);
    }
    cout<<ans<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

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

using namespace std;

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

#define REP(i,n) for(int(i)=0;(i)<(int)(n);(i)++)

int f[1100];
int n,k;

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < k; i++) {
		int u; scanf("%d", &u);
		f[u]=1;
	}

	for (int i = n; ; i++) {
		int ti = i;
		bool ok = true;
		while (ti) {
			int d = ti%10;
			if (f[d]) ok = false;
			ti /= 10;
		}
		if (ok) {
			printf("%d\n", i);
			return 0;
		}
	}
}

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

using namespace std;

int main()
{
	long long n;
	cin >> n;
	
	long long tmp = n;
	int sum = 0;
	while(tmp != 0)
	{
		sum += tmp % 10;
		tmp /= 10;
	}
	
	if(n % sum == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
#include <stdio.h>
using namespace std;
 
int main()
{
    std::string s;
    cin >> s;
    
    int ans = 0;
    if(s == "RRR") cout << 3 << endl;
    else if(s == "RRS") cout << 2 << endl;
    else if(s == "SRR") cout << 2 << endl;
    else if(s == "SSR") cout << 1 << endl;
    else if(s == "SRS") cout << 1 << endl;
    else if(s == "RSS") cout << 1 << endl;
    else if(s == "RSR") cout << 1 << endl;
    else cout << 0 << endl;
      
 
    
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

long long n, m;
long long cnt[100005] = {0};
vector<pair<long long, pair<long long, long long>>> v;
string ans[100005];

void solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    long long p, y;
    cin >> p >> y;
    v.push_back(make_pair(y, make_pair(p, i)));
  }
  sort(v.begin(), v.end());
  solve();
  for(int i = 0; i < m; ++i) cout << ans[i] << endl;
  return 0;
}

void solve() {
  for(int i = 0; i < m; ++i) {
    pair<long long, pair<long long, long long>> now;
    long long num = 0, x = 0;
    string ns;
    now = v[i];
    ++cnt[now.se.fi];
    num += cnt[now.se.fi];
    num += now.se.fi * 1000000LL;
    while(num > 0 && x < 12) {
      ns += num % 10 + '0';
      num /= 10;
      ++x;
    }
    while(ns.size() < 12) ns += '0';
    reverse(ns.begin(), ns.end());
    ans[now.se.se] = ns;
  }
}

Measured memory_bytes: 10736
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n);
  for(auto&& e:a)std::cin>>e;

  std::vector<std::vector<ll>> dp(n+1,std::vector<ll>(n+1,0));

  using P=std::pair<ll,ll>;
  std::vector<P> tmp(n);
  rep(i,0,n)tmp[i]={a[i],i+1};

  std::sort(all(tmp),std::greater<P>());

  rep(i,0,n){
    rep(j,0,i+2){
      ll left=j,right=i+1-j;
      if(left>0)chmax(dp[left][right],dp[left-1][right]+tmp[i].first*(tmp[i].second-left));
      if(right>0)chmax(dp[left][right],dp[left][right-1]+tmp[i].first*(n+1-right-tmp[i].second));
    }
  }

  rep(i,0,n)debug(tmp[i]);

  ll ans=0;
  rep(i,0,n+1)chmax(ans,dp[i][n-i]);
  
  std::cout<<ans<<"\n";

  return 0;
}

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

int main() {
    string S, T;
    cin >> S >> T;
    int max_cnt = 0;
    for (int i=0; i<S.length()-T.length()+1; i++) {
        int cnt = 0;
        for (int j=0; j<T.length(); j++) {
            if (S[i+j] == T[j]) {
                cnt ++;
            }
        }
        if (max_cnt < cnt) {
            max_cnt = cnt;
        }
    }
    cout << T.length() - max_cnt << endl;
}

Measured memory_bytes: 3636
<?php
    $in = explode(" ", trim(fgets(STDIN)));
    if($in[0] + $in[1] > $in[2] + $in[3]){
        echo "Left";
    }elseif($in[0] + $in[1] < $in[2] + $in[3]){
        echo "Right";
    }else{
        echo "Balanced";
    }
?>

Measured memory_bytes: 4728