akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #define int int64_t

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)

template <typename String>
String lcs(String const& a, String const& b) {
    const int n = a.size(), m = b.size();
    static int X[3030][3030], Y[3030][3030];  // 16MB x 2
    rep(i, n + 1) X[i][0] = 0;
    rep(i, m + 1) Y[0][i] = 0;
    rep(i, n) rep(j, m) {
        if (a[i] == b[j]) {
            X[i + 1][j + 1] = X[i][j] + 1;
            Y[i + 1][j + 1] = 0;
        } else if (X[i + 1][j] < X[i][j + 1]) {
            X[i + 1][j + 1] = X[i][j + 1];
            Y[i + 1][j + 1] = +1;
        } else {
            X[i + 1][j + 1] = X[i + 1][j];
            Y[i + 1][j + 1] = -1;
        }
    }
    String c;
    for (int i = n, j = m; i > 0 && j > 0;) {
        if (Y[i][j] > 0)
            --i;
        else if (Y[i][j] < 0)
            --j;
        else {
            c.push_back(a[i - 1]);
            --i;
            --j;
        }
    }
    reverse(c.begin(), c.end());
    return c;
}
signed main() {
    
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    std::string x,y;
    std::cin>>x>>y;
    std::cout<<lcs(x,y)<<std::endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 71936
<?php
fscanf(STDIN, '%d %d %d', $n, $m, $k);

$tree = new UnionFind($n);
$ans = array_fill(0, $n, -1);

for ($i  = 0; $i < $m; $i++) {
    fscanf(STDIN, '%d %d', $a, $b);
    $a--;
    $b--; // 0 ~ $n-1に合わせる
    $ans[$a]--;
    $ans[$b]--;
    $tree->unite($a, $b);
}

for ($i  = 0; $i < $k; $i++) {
    fscanf(STDIN, '%d %d', $c, $d);
    $c--;
    $d--;
    if ($tree->isSame($c, $d)) {
        $ans[$c]--;
        $ans[$d]--;
    }
}

for ($i = 0; $i < $n; $i++) {
    $ans[$i] += $tree->size($i);
}

echo implode(' ', $ans) . PHP_EOL;

// Union-Find：同じグループに属するかどうかを判定する
class UnionFind
{
    private $par; // par[$i]:$iの親 自分が根の場合は自身のindexとなる
    private $size;

    function __construct($n)
    {
        for ($i = 0; $i < $n; $i++) {
            $this->par[$i] = $i; // 最初は全てが根
            $this->size[$i] = 1;
        }
    }

    function root($x)
    { // 根を返す
        if ($this->par[$x] === $x) return $x; // 根の場合
        return $this->par[$x] = $this->root($this->par[$x]); // 全ての枝の親を根にしながら再帰処理
    }

    function unite($x, $y)
    { // $xと$yの木を併合
        $ix = $this->root($x);
        $iy = $this->root($y);
        if ($ix === $iy) return;
        if ($this->size[$ix] < $this->size[$iy]) list($ix, $iy) = [$iy, $ix];
        $this->size[$ix] += $this->size[$iy];
        $this->par[$iy] = $ix; // $yの根を$xの根に付ける
    }

    function isSame($x, $y)
    { // $xと$yの根が同じか
        return $this->root($x) === $this->root($y);
    }

    function size($x)
    {
        return $this->size[$this->root($x)];
    }
}

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

#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define v(t) vector<t>
#define vv(t) vector<vector<t>>
#define vn(t,n,val) vector<t>(n,val)
#define vvn(t,r,c,val) vector<vector<t>>(r, vector<t>(c,val))
#define vvv(t) vector<vector<vector<t>>>
#define vvvn(t,l,b,h,val) vector<vector<vector<t>>>(l,vector<vector<t>>(b,vector<t>(h)))

int main() {
	sp;

	////////////////To Remove//////////////
	// freopen("../../input.txt", "r", stdin);
	// freopen("../../output.txt", "w", stdout);
	///////////////////////////////////////

	long long n,k;
	cin>>n>>k;
	cout<<min(n%k, k-(n%k));

  	return 0;
}

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

using namespace std;

static const int N = 1000;

int lcs(string str1, string str2)
{
	int c[N + 1][N + 1];
	int m = str1.size();
	int n = str2.size();
	int maxl = 0;
	str1 = ' ' + str1;
	str2 = ' ' + str2;

	for (int i = 0; i <= m; i++) c[i][0] = 0;
	for (int i = 1; i <= n; i++) c[0][i] = 0;

	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (str1[i] == str2[j])
			{
				c[i][j] = c[i - 1][j - 1] + 1;
			}
			else 
			{
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}
	return maxl;
}

int main()
{
	string str1, str2;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << endl;
	}
	return 0;
}


Measured memory_bytes: 7076
<?php
fscanf(STDIN, "%d",$cnt);
fscanf(STDIN, "%s",$str);
$r_c=0;
$b_c=0;

for($i=0;$i<strlen($str);$i++){
	$m=substr($str,$i,1);
	if($m=="R"){
		$r_c++;
	}else{
		$b_c++;
	}
}
if($r_c>$b_c){
	echo "Yes";
}else{
	echo "No";
}
?>

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

int main()
{
    int n,m;
    int w[1500],h[1500];
    cin >> n >> m;
    for(int i = 0;i<n;i++)
        scanf("%d", &w[i]);
    for(int i = 0;i<m;i++)
        scanf("%d", &h[i]);
    while(n)
    {
        vector<int> x(1501*1001);
        vector<int> y(1501*1001);
        for(int i =0;i<n;i++)
        {	
        	int a = 0;
            for(int j = i;j<n;j++)
            {
                a+=w[j];
                x[a]++;
            }
        }
        for(int i =0;i<m;i++)
        {
        	int b = 0;
            for(int j = i;j<m;j++)
            {
                b+=h[j];
                y[b]++;
            }
        }

        int ave=0;
        for(int i =0;i<1500*1000;i++){
        	//if(y[i]!=0)cout << i << " " << y[i] << " / ";
            ave+=x[i]*y[i];
        }
        cout <<ave<<endl;



        cin >>n>>m;
    for(int i = 0;i<n;i++)
        scanf("%d", &w[i]);
    for(int i = 0;i<m;i++)
        scanf("%d", &h[i]);
    }
    return 0;
}



Measured memory_bytes: 14776
def solve():
	length, lowCase1BaseIdx = [int(x) for x in input().split()]
	originalStr = (input())
	strList = list(originalStr)
	lowerCase = strList[lowCase1BaseIdx - 1].lower()
	strList[lowCase1BaseIdx - 1] = lowerCase
	print(''.join(strList))
solve()

Measured memory_bytes: 38256
N=int(input())
H=list(map(int,input().split()))

dp=[10**9]*N
dp[0]=0
for i in range(N-2):
    dp[i+1]=min(abs(H[i]-H[i+1])+dp[i],dp[i+1])
    dp[i+2]=abs(H[i]-H[i+2])+dp[i]

dp[N-1]=min(abs(H[N-1]-H[N-2])+dp[N-2],dp[N-1])

print(dp[N-1])

Measured memory_bytes: 20472
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#import fractions
#import itertools
#import math
#lis=list(input().split())
#lis=list(map(float,input().split()))
#S=input()

n=int(input())
lis=list(map(int,input().split()))
ans=0
for i in range(n-2):
    if lis[i]<lis[i+1] and lis[i+1]<lis[i+2]:
        ans+=1
    elif lis[i]>lis[i+1] and lis[i+1]>lis[i+2]:
        ans+=1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int N = 1e5 + 7, inf = 1e9;

int n, ans = 0;
string s;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> s;
	int pv = 0;
	n = (int)s.length();
	for(int i = 0; i < n; i++){
		int cur = s[i] - 'a' + 1;
		if(pv == cur){
			if(i == n - 1) break;
			pv = 0;
			i++;
		}
		else{
			pv = cur;
		}
		ans++;
	}
	cout << ans;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#include<cstdio>
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

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[200001];
	rep1(i, N) A[getint()] = i;

	int dai[200002], shou[200002];
	rep1(i, N) {
		dai[i + 1] = i;
		shou[i - 1] = i;
	}

	ll kotae = 0;
	for (int i = N; i > 0; i--) {
		int a = A[i];
		int l = shou[a - 1];
		int r = dai[a + 1];
		kotae += (ll)(a - l + 1) * (r - a + 1) * i;
		dai[l] = r;
		shou[r] = l; cesp(l); cesp(r); ce(kotae);
	}

	printf("%lld", kotae);

	Would you please return 0;
}

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

#define endl '\n'
#define mod 1e7 

using ll = long long;
using namespace std;

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

    int n;
    cin >> n;
    int t[n][3];
    for(int i=0;i<n;i++) {
        cin >> t[i][0] >> t[i][1] >> t[i][2];
    }
    
    /**
     * Create 2d DP. 
     * Calculate all three possiblities
     * Print the max between them
     * Time: O(N)
     * 
    */

    int dp[n][3];
    dp[0][0] = t[0][0];
    dp[0][1] = t[0][1];
    dp[0][2] = t[0][2];     
    for(int i=1;i < n;++i) {
        dp[i][0] = max( (dp[i-1][1] + t[i][0]), (dp[i-1][2] + t[i][0]) );
        dp[i][1] = max( (dp[i-1][0] + t[i][1]), ( dp[i-1][2] + t[i][1]) );
        dp[i][2] = max( (dp[i-1][1] + t[i][2]), (dp[i-1][0] + t[i][2]) );
    }

    int ans = max( max(dp[n-1][0], dp[n-1][1]), dp[n-1][2] );
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 5992
require 'prime'

class Array
  def make_power
    (0..self[1]).map { |x| self[0] ** x }
  end
end

n, m = gets.split.map(&:to_i)
ps = Prime.prime_division(m)
if ps.empty?
  p 1
  exit
elsif ps.size == 1
  ds = ps.map(&:make_power)[0].reverse
else
  ds = ps.map(&:make_power).inject(&:product).map(&:flatten).map { |x| x.inject(:*) }.sort.reverse
end
p ds.bsearch { |x| x <= m / n }

Measured memory_bytes: 2428
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int a, b, c; cin >> a >> b >> c;
    int d = a - b;
    cout << max(c - d, 0) << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
import sys

a, b = map(int, sys.stdin.readline().split())
if a > b:
    a, b = b, a

def main():
    d  = b - a
    if d <= 1:
        return 'Yay!'
    elif 16 - a * 2 >= d * 2:
        return 'yay!'
    else:
        return ':('

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
#include<iostream>
#define m 1000000
using namespace std;

bool ba[m + 1] = { true };
void cp() {
	int co = 0;
	for (int i = 0; i < m + 1; i++) {
		ba[i] = { true };
	}
	for (int i = 2; i*i <= m; i++) {
		if (ba[i]) {
			for (int j = i*i; j <= m; j += i) {
				ba[j] = { false };
			}
		}
	}

	return;
}

int main() {
	int n;
	cp();
	while (cin >> n, n) {
		int c = 0;
		for (int i = 2;i <= n / 2;i++) {
			int j = n - i;
			if (ba[i] == true && ba[j] == true)c++;
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 4064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    ArrayList<String> input = new ArrayList<String>();
    for(int i = 0; i < N; i++) {
      input.add(sc.next());
    }
    Collections.sort(input);
    String ans = "";
    for(int i = 0; i < input.size(); i++) {
      ans += input.get(i);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 24784
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

void solve() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) cout << "Yes"; else cout << "No";
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
 
  return 0;
}

Measured memory_bytes: 384
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

count = 0

(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      count += 1 if 500 * i + 100 * j + 50 * k == x
    end 
  end 
end 

puts count

   




Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void) {
    int H, W;
    cin >> H >> W;
    vector< vector<int> > grid(H+2, vector<int>(W+2));
    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            int A;
            cin >> A;
            grid[i][j] += A;
        }
    }
    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            int B;
            cin >> B;
            grid[i][j] -= B;
        }
    }

    vector< vector< bitset<20'000> > > dp(H+2, vector< bitset<20'000> >(W+2));
    dp[1][1].set(10'000 + grid[1][1]);
    dp[1][1].set(10'000 - grid[1][1]);
    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            for(int k=100; k<=19'900; k++) {
                if(dp[i][j][k]) {
                    dp[i+1][j].set(k + grid[i+1][j]);
                    dp[i+1][j].set(k - grid[i+1][j]);
                    dp[i][j+1].set(k + grid[i][j+1]);
                    dp[i][j+1].set(k - grid[i][j+1]);
                }
            }
        }
    }

    int ans = numeric_limits<int>::max();
    for(int k=100; k<=19'900; k++) {
        if(dp[H][W][k]) {
            ans = min(ans, abs(10'000 - k));
        }
    }

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


Measured memory_bytes: 17152
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  set<string> se;
  int n;cin>>n;
  string s;
  rep(i,0,n){
    cin>>s;
    se.insert(s);
  }
  cout<<se.size()<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

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

#define Need_For_Speed ios_base::sync_with_stdio;cin.tie(NULL);cout.tie(NULL);

using namespace std;

int n, a, b;

int main () {
	Need_For_Speed;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << "Alice";
	}
	else {
		cout << "Borys";
	}
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc167/tasks/abc167_c

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define cerr cout
#define int long long
#define all(x) (x).begin(), (x).end()

const int maxn = 20;

int C[maxn], U[maxn];
int A[maxn][maxn];

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

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

    for(int i = 0; i < N; i++) {
        cin >> C[i];
        for(int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }

    int ans = INT_MAX;
    for(int mask = 0; mask <= (1<<12)-1; mask++) {
        for(int i = 0; i < maxn; i++) U[i] = 0;

        int cost = 0;
        for(int i = 0; i < N; i++) {
            if(mask & (1<<i)) {
                cost += C[i];
                for(int j = 0; j < M; j++) {
                    U[j] += A[i][j];
                }
            }
        }

        
        // bitset<12> x(mask);
        // cout << x << endl;
        // watch(cost)
        // cerr << endl;

        bool ok = true;
        for(int i = 0; i < M; i++) {
            if(U[i] < X) {
                ok = false;
            }
        }

        if(ok) {
            ans = min(ans, cost);
        }
    }

    if(ans == INT_MAX) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


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

int main()
{
	long long int n,k;
		cin>>n>>k;
	vector<pair<long long int,long long int>> v;
	long long int count=0;
	for(long long int i=0;i<n;i++)
	{
		long long int l,p;
			cin>>l>>p;
		v.push_back(make_pair(p,l));
		count+=p;
	}
	sort(v.begin(),v.end());
	long long int arr[n+1][count+1];
	long long int q=0;
	for(long long int i=0;i<=n;i++)
	{
		for(long long int j=0;j<=count;j++)
		{
			if(j==0 || i==0)
			{
				arr[i][j]=1e18;
			}
			else if(v[i-1].first>j)
			{
				arr[i][j]=arr[i-1][j];
			}
			else if(v[i-1].first==j) 
			{
				arr[i][j]=min(v[i-1].second,arr[i-1][j]);
			}
			else
			{
				long long int x=v[i-1].second+arr[i-1][j-v[i-1].first];
				arr[i][j]=min(x,arr[i-1][j]);
			}
			if(arr[i][j]<=k)
			{
				q=max(q,j);
			}
			
		}
	}
	
	cout<<q;
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define put(i) cout << fixed << i << endl
using namespace std;
using ll = long long;

// DPの気がするけどどうですかね
/*違いましたねpdf見て解答、解けないの辛いですねぇ*/

int main() {
    ll n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<ll> l(q), r(q);
    rep(i, q) cin >> l[i] >> r[i];

    vector<ll> t(n+1);

    for(long long j = 0; j < n-1; j++){
        if(s[j] == 'A' and s[j+1] == 'C'){
            s[j] = 'a';
        }
    }

    ll cnt = 0;
    for(long long i = 0; i < n; i++){
        if(s[i] == 'a') cnt++;
        t[i+1] = cnt;
    }

    for(long long i = 0; i < q; i++){
        put(t[r[i]-1] - t[l[i]-1]);
    }
}


Measured memory_bytes: 5868
import java.util.Scanner;
class Main{
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    
    int h = stdIn.nextInt();
    int a = stdIn.nextInt();
   
    if (h % a == 0) {
      System.out.println(h / a);
    } else {
      System.out.println(h / a + 1);
    }
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    int a,b;
    char s;
    cin>>a>>s>>b;
    if(s=='+'){
        cout<<a+b<<endl;
    }else{
        cout<<a-b<<endl;
    }
    
}


Measured memory_bytes: 3636
from fractions import gcd
from functools import reduce

K = int(input())
tmp = [[0 for _ in range(K+1)] for _ in range(K+1)]
ans = 0
for a in (range(1, K+1)):
    for b in range(a, K+1):
        if tmp[a][b] != 0:
            gcd1 = tmp[a][b]
        else:
            gcd1 = gcd(a, b)
            tmp[a][b] = gcd1
        for c in range(b, K+1):
            n = 0
            if a == b == c:
                n = 1
            elif a == b or b == c or c == a:
                n = 3
            else:
                n = 6
            gcd2 = 0
            if tmp[gcd1][c] != 0:
                gcd2 = tmp[gcd1][c]
            else:
                gcd2 = gcd(gcd1, c)
                tmp[gcd1][c] = gcd2
            ans += n * gcd2
print(ans)


Measured memory_bytes: 10968
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {



    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n =sc.nextLong();
        Map<Long,Integer> map= new HashMap<>();
        long count =0;
        for(int i=0;i<n;i++)
        {
            long saveme=sc.nextInt();
            if(map.get(i-saveme)!=null)
            {
                count=count+map.get(i-saveme);
            }

            map.putIfAbsent(saveme+i,0);
            map.put(saveme+i,map.get(saveme+i)+1);
            //map.put(saveme-i,saveme-i);

        }

        System.out.println(count);
    }
}

Measured memory_bytes: 72600
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
ll ceil(ll a,ll b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c,d,i;
    cin>>a>>b>>c>>d;
    if(b<a)
        swap(a,b);
    ll ans=b-a+1;
    ll x=ceil(a,c), y=b/c;
    //cout<<x<<y<<endl;
    ans-=(y-x+1);
    x=ceil(a,d);
    y=b/d;
    //cout<<x<<y<<endl;
    ans-=(y-x+1);
    ll e=c*d/(__gcd(c,d));
    x=ceil(a,e);
    y=b/e;
    ans+=(y-x+1);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int n; cin>>n; int an=0;
  for(int i=1;i<=n;i+=2) {
    int sm=1, nw=i;
    for(int j=2,t=1;j<=n+1;j++) {
      if (nw%j==0) {
        nw /= j; j--; t++;
      } else {
        sm *= t; t=1;
      }
    }
    if (sm==8) an++;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;

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

	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b) << "\n";
	return 0;
}


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

int main(){
  long long n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  long long ans = 0;
  long long tmp = a[0];
  for(int i = 1; i < n; i++){
    if(a[i] < tmp){
      ans += tmp - a[i];
    }else{
      tmp = a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4788
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

H, W = ints()
A = [ints() for _ in range(H)]
B = [ints() for _ in range(H)]
D = [[abs(A[h][w]-B[h][w]) for w in range(W)] for h in range(H)]

memo = {}
memo = {}


N=80*60
memo[(0, 0)] = 1 << (D[0][0]+N)

for h in range(H):
  for w in range(W):
    if h==0 and w==0:
      continue 

    d = D[h][w]
    f = 0
    if h>0:
      s = memo[(h-1, w)]
      f |= s<<d 
      f |= s>>d
    if w>0:
      s = memo[(h, w-1)]
      f |= s<<d
      f |= s>>d

    memo[(h, w)] = f

def min_keta(n):
  b = bin(n>>N)
  for i in range(len(b)):
    if b[-i-1]=='1':
      return i

print(min_keta(memo[(H-1, W-1)]))


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int K;
  cin >> K;
  
  int A = a;
  int B = b;
  int C = c;
  
  for (int i = 0; i < K; i++) {
    A *= 2;
    B *= 2;
    C *= 2;
  }
  
  A += b + c;
  B += c + a;
  C += a + b;
  
  int ans = A;
  if (ans < B) ans = B;
  if (ans < C) ans = C;
  
  cout << ans << endl;
  
}

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

using namespace std;

char field[101][101];

int main() {
    int n, m;
    cin >> n >> m;
    int d;
    cin >> d;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> field[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (field[i][j] == '#') {
                continue;
            }
            int nx = i, ny = j;
            int now1 = 0;
            while (field[nx][ny] == '.') {
                ++nx;
                ++now1;
            }
            if (now1 >= d) ++ans;
            nx = i, ny = j;
            int now2 = 0;
            while (field[nx][ny] == '.') {
                ++ny;
                ++now2;
            }
            if (now2 >= d) ++ans;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define var auto
#define MOD 1000000007


typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;


const int N = 1e5;
string arr[4] = {"dream", "dreamer", "erase" ,"eraser"};
string s;
int n;

int main()
{
    START
    //freopen("test cases\\out.txt", "r", stdin) ;
    cin>>s;
    n = s.size();
    reverse(all(s));
    for(int i =0; i<n; i++){
        if(i+4<n && s.substr(i, 5)=="maerd") i+=4;
        else if(i+6<n && s.substr(i, 7)=="remaerd") i+=6;
        else if(i+4<n && s.substr(i, 5)=="esare") i+=4;
        else if(i+5<n && s.substr(i, 6)=="resare") i+=5;
        else return cout<<"NO", 0;
    }
    cout<<"YES";
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	cin >> S;
	int N = S.size();
	VI A(N+1);
	REP(i, N) A[i+1] = S[i] - '0';

	if (!A[1] || A[N]) {
		cout << -1 << endl;
		return 0;
	}
	eFOR(i, 1, N) {
		if (A[i] ^ A[N - i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	vector<pii> ans;
	ans.push_back(pii(1, 2));
	int tmp = 2;
	FOR(i, 2, N) {
		if (A[i]) {
			ans.push_back(pii(tmp, i + 1));
			tmp = i + 1;
		}
		else {
			ans.push_back(pii(tmp, i + 1));
		}
	}
	for (auto out : ans) {
		cout << out.first << " " << out.second << endl;
	}
	return 0;
}



Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n;
    cin >>n;
	string s;
    cin >>s;
	int k; 
    cin >>k;
	for(int j=0;j<s.size();j++){
		if(s[k-1]!=s[j])s[j]='*';
	}
	cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;
lint p=1e9+7;

lint pow_mod(lint a,lint b,lint p){
  if(b==0)return 1;
  if(b%2==0){
    lint d=pow_mod(a,b/2,p);
    return (d*d)%p;
  }else{
    return (a*pow_mod(a,b-1,p))%p;
  }
}

//x / a mod p=x * inv_mod(a,p) 
lint inv_mod(lint a,lint p){
  return pow_mod(a,p-2,p);//(a^(p-2))mod p
}


int main(){
  int X,Y;
  cin>>X>>Y;
  if((2*Y-X)%3!=0 or (2*X-Y)%3!=0 or (2*Y-X)<0 or (2*X-Y)<0 ){
    cout<<0<<endl;
    return 0;
  }
  lint nx= (2*Y-X)/3;
  lint ny= (2*X-Y)/3;
  lint ans=1;
  lint dev=1;
  REP(i,(nx+ny)){
    ans*=i+1;
    ans%=p;
  }
  REP(i,nx){
    dev*=i+1;
    dev%=p;
  }
  REP(i,ny){
    dev*=i+1;
    dev%=p;
  }
  ans*=inv_mod(dev,p);
  ans%=p;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;
int INF = 1001001001;
int main(){
	int r, d, x;
	cin >> r >> d >> x;
	vector<int> ans(10);
	rep(i,10){
		x = r * x -d;
		ans[i] = x;
	}
	rep(i,10) cout << ans[i] << endl;
	return 0;
}


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 reader = new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = reader.readLine().split(" ");
        if(Integer.parseInt(inputs[0]) * Integer.parseInt(inputs[1]) % 2 == 0)
            System.out.print("Even");
        else
            System.out.print("Odd");
    }
}

Measured memory_bytes: 21204
#include <algorithm>
#include <cmath>
#include <iostream>

#include <string>
using namespace std;

unsigned long long gcd(long long a, long long b) {

  long long mo = a % b;
  if (mo == 0) {
    return b;
  }
  return gcd(b, mo);
}
int main(void) {
  int n;
  cin >> n;
  unsigned long long arr[n], lc[n] = {1};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  lc[0]=arr[0];
  for (int i = 1; i < n; i++) {
    lc[i] = (lc[i - 1] / gcd(arr[i], lc[i - 1]))*arr[i];
  }
  cout << lc[n - 1];
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//次数1の頂点と辺を除く
//木の直径を求める
//頑張る

#include<bits/stdc++.h>
using namespace std;
const int INF = 100100100;
int used[1000];
int deg[1000];

int dfs(int i, vector<vector<pair<int, int> > > &adj){

    int res = 0;
    int n = (int)adj.size();

    for(int j = 0; j < adj[i].size(); j++){
        if(deg[adj[i][j].second] != 1 && used[adj[i][j].second] == false){
            used[adj[i][j].second] = true;
            res = max(res, dfs(adj[i][j].second, adj) + adj[i][j].first);
            used[adj[i][j].second] = false;
        }
    }

    return res;
}

int main(){

    while(1){
        int n; cin >> n;
        if(!n) break;
        vector<vector<pair<int, int> > > adj(n);
        memset(deg, 0, sizeof(deg));
        vector<int> p(n - 1);
        vector<int> d(n - 1);
        for(int i = 0; i < n - 1; i++) cin >> p[i];
        for(int i = 0; i < n - 1; i++) cin >> d[i];


        for(int i = 0; i < n - 1; i++){
            adj[i + 1].push_back({d[i], p[i] - 1});
            adj[p[i] - 1].push_back({d[i], i + 1});
            
            deg[i + 1]++;
            deg[p[i] - 1]++;
        }

        int ans = 0;

        //deg = 1の頂点をとりのぞく
        for(int i = 0; i < n; i++){

            if(deg[i] == 1){

                for(int j = 0; j < adj[i].size(); j++){
                
                    ans += adj[i][j].first;
                    
                }
            }
        
        }

        //取り除いた後の橋の重みの三倍を足していく
        for(int i = 0; i < n; i++){

            for(int j = 0; j < adj[i].size(); j++){

                if(i >= adj[i][j].second) continue;

                if(deg[i] == 1 || deg[adj[i][j].second] == 1) continue;

                ans += 3 * adj[i][j].first;
            }

        }

        //木の直径を求める
        int dis = 0;
        for(int i = 0; i < n; i++){
            if(deg[i] == 1) continue;
            memset(used, false, sizeof(used));
            used[i] = true;
            dis = max(dis, dfs(i, adj));
        }

        ans -= dis;
        cout << ans << endl;
    
    }
    
    return 0;
}


Measured memory_bytes: 3208
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < M; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (a == 1) {
                set.add(b);
            }
            if (b == N) {
                map.put(a, b);
            }
        }
        for (int key : set) {
            if (map.containsKey(key)) {
                System.out.println("POSSIBLE");
                return;
            }
        }
        System.out.println("IMPOSSIBLE");
    }

}

Measured memory_bytes: 75120
import java.util.Arrays;
import java.util.Scanner;
     
    public class Main {
      public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int []a = new int[N];
        
        int A = 0;
        int B = 0;
        for(int i=0; i<N; i++) {
        	 a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        for(int i=0; i<N; i++) {
        	if(i%2 != 0) {
        		A += a[i];
        	}else {
        		B += a[i];
        	}
        }
        System.out.println(Math.abs(A-B));
      }
    }

Measured memory_bytes: 35568
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main()
{
    
    ll n;
    cin >> n;
    ll ans;
    cin >>ans;
    rep(i,n-1){
        ll a;
        cin >> a;
        ans=gcd(ans,a);
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;

namespace atcoder_past_problem
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new Input(Console.In));
        }

        public void Solve(Input input)
        {
            if (Solve2(input))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        public bool Solve2(Input input)
        {
            var n = input.ReadInt;
            var plan = new List<int[]>();
            for (var i = 0; i < n; i++)
            {
                plan.Add(input.ReadIntArray);
            }

            var axis = new int[] { 0, 0 };
            var time = 0;

            foreach (var p in plan)
            {
                var limit = p[0] - time;
                time = p[0];

                for (var i = 1; i <= limit; i++)
                {
                    if (p[1] > axis[0]) axis[0]++;
                    else if (p[1] < axis[0]) axis[0]--;
                    else if (p[2] > axis[1]) axis[1]++;
                    else if (p[2] < axis[1]) axis[1]--;
                    else axis[0]++;
                }
                if (p[1] != axis[0] || p[2] != axis[1]) return false;
            }
            return true;
        }
    }

    public class Input
    {
        private TextReader Stream { get; }
        private char Separator { get; }
        private Queue<string> InputStream { get; }

        public Input(TextReader stream, char separator = ' ')
        {
            Stream = stream;
            Separator = separator;
            InputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (InputStream.Count != 0) return InputStream.Dequeue();
                string[] tmp = Stream.ReadLine().Split(Separator);
                for (int i = 0; i < tmp.Length; ++i)
                    InputStream.Enqueue(tmp[i]);
                return InputStream.Dequeue();
            }
        }

        public string ReadLine => Stream.ReadLine();
        public int ReadInt => int.Parse(Read);
        public long ReadLong => long.Parse(Read);
        public double ReadDouble => double.Parse(Read);
        public int[] ReadIntArray => Stream.ReadLine().Split(Separator).Select(i => int.Parse(i)).ToArray();
        public long[] ReadLongArray => Stream.ReadLine().Split(Separator).Select(l => long.Parse(l)).ToArray();
    }
}


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


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

struct edge {int to; ll cost; };

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


Measured memory_bytes: 3600
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	
		int x,y,a,b,c,d,p;
		cin>>a>>b>>c>>d>>p;
		x=a*p;
		if(c<p)
			y=b+(p-c)*d;
		else
			y=b;
		if(x>y)
			cout<<y<<endl;
		else
			cout<<x<<endl;
	return 0;
}
		
			

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

signed main () {
    int n, k;
    cin >> n >> k;
    int64_t ans = 0;
    for (int b = k + 1; b <= n; ++b) {
        ans += int64_t(n / b) * int64_t(b - k);
        if (n % b >= k)
            ans += (n % b) - k + 1 - int(k == 0);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <cassert>

using namespace std;

class UnionFind {
  public:
    UnionFind(int maxValue) {
      parents.resize(maxValue + 1);
      for(int i = 0; i < parents.size(); i++) parents[i] = i; 
    }
    void Unite(int x, int y) {
      int xroot = GetRoot(x);
      int yroot = GetRoot(y);
      if(xroot == yroot) return;
      parents[xroot] = parents[yroot];
    }
    bool HasSameParent(int x, int y) {
      return GetRoot(x) == GetRoot(y);
    }
  private:
    vector<int> parents;
    int GetRoot(int v){
      assert(0 <= v && v < parents.size());
      if(parents[v] == v) return v;
      return (parents[v] = GetRoot(parents[v]));
    }
};

int main(int argc, char *argv[]) {
  int64_t N, M;
  cin >> N >> M;
  vector<int> nums;
  nums.reserve(N);
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    nums.push_back(tmp);
  }
  UnionFind uf(N);
  for(int i = 0; i < M; i++){
    int x, y;
    cin >> x >> y;
    uf.Unite(x, y);
  }
  int count = 0;
  for(int i = 1; i <= N; i++){
    if(uf.HasSameParent(i, nums[i - 1])) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int search(int sx, int sy, int dx, int dy, vector<vector<char> > &f, int w, int h)
{
vector<bool> visit;
queue<pair<pair<int, int>, int> > q;
visit.resize(w * h, false);
q.push(make_pair(make_pair(sx, sy), 0));
while(!q.empty()) {
int x = q.front().first.first;
int y = q.front().first.second;
int cost = q.front().second;
q.pop();
if(visit[x * w + y])
continue;
visit[x * w + y] = true;
if(f[x][y] == 'X')
continue;
if(x == dx && y == dy)
return cost;
int ix[4] = {-1, 0, 0, 1};
int iy[4] = {0, -1, 1, 0};
for(int i = 0; i < 4; ++i) {
int nx = ix[i] + x;
int ny = iy[i] + y;
if(nx < 0 || ny < 0 || nx >= h || ny >= w)
continue;
q.push(make_pair(make_pair(nx, ny), cost + 1));
}
}
return -1;
}

int main() {
int h, w, n;
vector<vector<char> > f;
vector<pair<int, int> > pos;
scanf("%d%d%d", &h, &w, &n);
f.resize(h);
pos.resize(n + 1);
for(int i = 0; i < h; ++i) {
char temp[1024];
scanf("%s", temp);
f[i].resize(w);
for(int j = 0; j < w; ++j) {
f[i][j] = temp[j];
if(f[i][j] == 'S')
pos[0] = make_pair(i, j);
if('0' <= f[i][j] && f[i][j] <= '9')
pos[f[i][j] - '0'] = make_pair(i, j);
}
}
int ans = 0;
for(int i = 1; i <= n; ++i) {
int sx = pos[i - 1].first;
int sy = pos[i - 1].second;
int dx = pos[i].first;
int dy = pos[i].second;
ans += search(sx, sy, dx, dy, f, w, h);
}
printf("%d\n", ans);
return 0;
}

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

struct dish{
	int value;
	int id;
	
	bool operator<(const dish& another) const {
		if(value != another.value) return value > another.value;
		return id < another.id;
	}
};

int main(){
	
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	vector<dish> dishes(n);
	
	rep(i,n){
		cin >> a[i] >> b[i];
		dishes[i] = dish{a[i]+b[i],i};
	}
	
	sort(dishes.begin(), dishes.end());
	
	ll res = 0;
	int i = 0;
	while(i < n){
		res += a[dishes[i].id];
		if(++i != n) res -= b[dishes[i].id];
		i++;
	}
	
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int n, a[1010], q, b, e, k;
signed main() {
	cin >> n; for (int i = 0; i < n; i++)cin >> a[i];
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> k >> b >> e;
		int ans = a[b];
		for (int j = b + 1; j < e; j++)if (!k)ans = min(ans, a[j]); else ans = max(ans, a[j]);
		cout << ans << endl;
	}
}


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

int main(){
  int n;
  cin >> n;
  cout << 0 << endl;
  string s;
  cin >> s;
  if(s == "Vacant") return 0;
  bool f0 = true;
  if(s == "Male") f0 = false;
  int l=0, r=n;
  while(1){
    int mid = (l+r)/2;
    cout << mid << endl;
    cin >> s;
    if(s == "Vacant") return 0;
    bool fmid = true;
    if(s == "Male") fmid = false;
    if(f0 == fmid && mid%2 == 0){
      l = mid;
    }
    else if(f0 != fmid && mid%2 == 1){
      l = mid;
    }else{
      r = mid;
    }
  }
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n)  RFOR(i,0,n)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
#define P pair<int,int>
#define PPi pair<P,int>
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};

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

	int N,K,L,p,q;
	cin>>N>>K>>L;
	UnionFind road(N),train(N);
	REP(i,K){
		cin>>p>>q;
		road.unite(p-1,q-1);
	}
	REP(i,L){
		cin>>p>>q;
		train.unite(p-1,q-1);
	}

	map<P,int> mp;
	REP(i,N) mp[P(road.find(i),train.find(i))]++;

	REP(i,N) 
		printf("%d%c",mp[P(road.find(i),train.find(i))],i!=N-1 ?' ' :'\n');
	return 0;
}




Measured memory_bytes: 15104
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 200010
using namespace std;
int n;
long long a[szxb];
int main()
{
	memset(a,0,sizeof(a));
	scanf("%d",&n);
	int t;
	long long total=0;
	for(register int i=1;i<=n;i++)
	{
		scanf("%d",&t);
		total+=t,a[i]=(a[i-1]+t);
	}
	long long minn=1e17;
	for(register int i=2;i<=n;i++)
	{
		minn=(min(minn,abs(total-(a[i-1]*2))));
	}
	printf("%lld",minn);
	putchar(10);
	return 0;
}

Measured memory_bytes: 1792
N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    A_old = A
    A = [0] * (N)
    for idx_A, a in enumerate(A_old):
        A[max(0, idx_A-a)] += 1
        if idx_A+a+1 < N:
            A[idx_A+a+1] -= 1
    for idx_A in range(1, N):
        A[idx_A] += A[idx_A-1]
    if A_old == A:
        break
print(" ".join(map(str, A)))


Measured memory_bytes: 151380