akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n; cin >> n;
	string s = to_string(n);
	int k = s.size();
	bool elf = true;
	rrep(i, k)if (int(s[i] - '0') != 9) elf = false;
	int ans = 0;
	if (elf) ans = int(s[0] - '0') + 9 * (k - 1);
	else ans = int(s[0] - '0') + 9 * (k - 1) - 1;
	dunk(ans);
	return 0;
}

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

using namespace std;
typedef long long ll;
ll n,a,b,x,y;
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	for(int i=1;i<=n-1;i++)
	{
		scanf("%lld%lld",&x,&y);
		ll a1=((a-1)/x+1)*x,b1=a1/x*y;
		ll b2=((b-1)/y+1)*y,a2=b2/y*x;
		if(a1>=a&&b1>=b) a=a1,b=b1;
		else a=a2,b=b2;
	}
	printf("%lld",a+b);
	return 0;
}

Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out で入力すること

    int n;
    cin >> n;
    print((n + 1) / 2);

    return 0;
}



Measured memory_bytes: 256
"use strict";
const zip = (...arrays) => {
    const length = Math.min(...arrays.map(arr => arr.length));
    return Array.from({ length }, (value, index) => arrays.map((array => array[index])));
};

function main(input) {
    const line = input.split("\n");
    const S = line[0];
    const T = line[1];
    let ans = 0;
    let z = zip(S, T);
    for (let idx in z) if (z[idx][0] !== z[idx][1]) ans++;
    console.log(ans);
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 72012
N, M = map(int, input().split())
A = list(map(int, input().split()))

acA = [0 for _ in range(N)]
acA[0] = A[0] % M
for i in range(1, N):
    acA[i] = (acA[i-1] + A[i]) % M

cnt = 0
hist = dict()
hist[0] = 1
for e in acA:
    if e in hist:
        cnt += hist[e]
        hist[e] += 1
    else:
        hist[e] = 1
print(cnt)

Measured memory_bytes: 16172
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int n;cin >> n;
    priority_queue<LL> pa;
    priority_queue<LL,vector<LL>,greater<LL>> pb;
    LL la=0,ra=0;
    LL sum = 0;
    for(int i=0;i<n;i++){
        int x;cin >> x;
        if(x==1){
            LL l,r;cin >> l >> r;
            sum+=r;
            if(pa.empty()){
                pa.push(l);
                la+=l;
            }
            else if(pa.size()==pb.size()){
                if(pb.top()<=l){
                    LL t = pb.top();pb.pop();
                    ra+=l;
                    ra-=t;
                    la+=t;
                    pa.push(t);
                    pb.push(l);
                }
                else{
                    pa.push(l);
                    la+=l;
                }
            }
            else{
                if(pa.top()>=l){
                    LL t = pa.top();pa.pop();
                    la+=l;
                    la-=t;
                    ra+=t;
                    pa.push(l);
                    pb.push(t);
                }
                else{
                    ra+=l;
                    pb.push(l);
                }
            }
        }
        else if(x==2){
            LL s=pa.top();
            cout <<s<<" " <<sum+(LL)pa.size()*s-la+ra-(LL)pb.size()*s << endl;
        }
    }
    return 0;
}


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

const int N = 5e3 + 20;

int n, k, p[N], c[N];
bool vis[N];

void reset()
{
    for(int i = 1; i <= n; i++) vis[i] = false;
}

long long go(int node)
{
    node = p[node];
    int moves = k;

    reset();
    long long cycle_sum = 0;
    vector <long long> v;
    while(not vis[node])
    {
        vis[node] = true;
        cycle_sum += c[node];
        v.push_back(cycle_sum);
        node = p[node];
    }

    long long ans = LLONG_MIN;
    for(int i = 0; i < min(moves, (int)v.size()); i++) ans = max(ans, v[i]);
    if(moves > v.size())
    {
        long long sum = ((moves - 1) / v.size()) * cycle_sum;
        ans = max(ans, sum);
        for(int i = 0; i <= (moves - 1) % v.size(); i++) ans = max(ans, sum + v[i]);
    }
    return ans;
}

int main()
{
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%d", &p[i]);
    for(int i = 1; i <= n; i++) scanf("%d", &c[i]);

    long long ans = LLONG_MIN;
    for(int i = 1; i <= n; i++) ans = max(ans, go(i));
    printf("%lld", ans);
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n, m; cin >> n >> m;
	vector<string>a(n), b(m);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, m)cin >> b[i];
	rep(i, 0, n - m + 1) {
		rep(j, 0, n - m + 1) {
			int cnt(0);
			rep(k, 0, m) {
				rep(l, 0, m) {
					if (a[i + k][j + l] == b[k][l])cnt++;
					else goto here;
				}
			}
			here:
			if (cnt == m*m) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int w = sc.nextInt();
    int weight[] = new int[n];
    int value[] = new int[n];
    for(int i=0;i<n;i++){
      weight[i]=sc.nextInt();
      value[i]=sc.nextInt();
    }
    long dp[][]=new long[n+1][w+1];
    for(int i=0;i<=w;i++){
      dp[0][i]=0;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<=w;j++){
        if(j >= weight[i]){
          dp[i+1][j] = Math.max(dp[i][j-weight[i]] + (long)value[i], dp[i][j]);
        }else{
           dp[i+1][j] = dp[i][j];
        }
      }
    }

    System.out.print(dp[n][w]);
            System.out.print(" ");

    
    
    
  }
  

  
}

Measured memory_bytes: 126164
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;
use std::collections::HashMap;

fn main() {
    let s = input_line_str().to_charvec();
    let mut map = HashMap::new();
    for c in s {
        *map.entry(c).or_insert(0) += 1;
    }
    if map.len() == 1 {
        println!("No");
    } else {
        println!("Yes");
    }
}


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

using namespace std;
using ll = long long int;

int main() {
    int H, N;
    cin >> H >> N;
    pair<int, int> AB[N];
    int a, b;
    for (int i = 0; i < N; i++){
        cin >> a >> b;
        AB[i] = pair<int, int>(a, b);
    }
    int dp[N][H+1];
    for (int i = 0; i < N; i++){
        dp[i][0] = 0;
    }
    for(int i = 0; i <= H; i++){
        dp[0][i] = ceil((float) i / (float)AB[0].first) * AB[0].second;
    }
    for (int n = 1; n < N; n++){
        for(int h = 1; h <= H; h++){
            if (h - AB[n].first >= 0) {
                dp[n][h] = min(
                        dp[n - 1][h],
                        dp[n][h - AB[n].first] + AB[n].second
                );
            }else{
                dp[n][h] = min(
                        dp[n-1][h],
                        AB[n].second
                );
            }
        }
    }

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

Measured memory_bytes: 39296
<?php

$line = trim( fgets(STDIN) );
$temp = explode(" ", $line);
$N = $temp[0];
$Q = $temp[1];

$line = trim( fgets(STDIN) );
$sLen = strlen($line);
$s = str_split($line);

$t = array();
$d = array();

for ( $i = 0; $i < $Q; $i++ ) {
    $line = trim( fgets(STDIN) );
    $temp = explode(" ", $line);
    $t[] = $temp[0];
    $d[] = $temp[1];
}

$countLtemp = -1;
$countRtemp = -1;

for ( $i = $Q - 1; $i >= 0; $i-- ) {
    if ( $t[$i] == $s[$countLtemp+1] && $d[$i] == 'L' ) {
        $countLtemp = $countLtemp + 1;
    } else if ( $countLtemp >= 0 && $t[$i] == $s[$countLtemp] && $d[$i] == 'R' ) {
        $countLtemp = $countLtemp - 1;
    }

    if ( $t[$i] == $s[$sLen - 1 - ($countRtemp+1)] && $d[$i] == 'R' ) {
        $countRtemp = $countRtemp + 1;
    } else if ( $countRtemp >= 0 && $t[$i] == $s[$sLen - 1 - $countRtemp] && $d[$i] == 'L' ) {
        $countRtemp = $countRtemp - 1;
    }
}

echo max($N - ($countLtemp+1) - ($countRtemp+1),  0);


Measured memory_bytes: 47596
w=int(input())
l=[i+1 for i in range(w)]
n=int(input())
for _ in range(n):
    a,b=[int(i)-1 for i in input().split(",")]
    t=l[a]
    l[a]=l[b]
    l[b]=t
for i in l:
    print(i)


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

int main(){
	int n; cin>>n;
	vector<int> v(100001);
	rep(i,n){
		int l,r; cin>>l>>r;
		for(int j=l; j<=r; j++){
			v[j]++;
		}
	}
	cout<<accumulate(v.begin(),v.end(),0)<<endl;
}

Measured memory_bytes: 3756
mod = 10**9+7
s = input()[::-1]
dp = [[0 for _ in range(13)] for __ in range(len(s)+1)]
dp[0][0] = 1
ten = 1
for i in range(len(s)):
    if s[i]=="?":
        for j in range(10):
            q = (ten*j)%13
            for jj in range(13):
                dp[i+1][(jj+q)%13] = (dp[i][jj]+dp[i+1][(jj+q)%13])%mod
    else:
        q = (ten*int(s[i]))%13
        for jj in range(13):
            dp[i+1][(jj+q)%13] = (dp[i][jj]+dp[i+1][(jj+q)%13])%mod
    ten = (ten*10)%13
print(dp[-1][5])

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

int main(){
    int m, n, a[101][101], b[101], c[101];
    
    
    for (int i = 0; i < 101; i++) {
        for (int j = 0; j < 101; j++){
            a[i][j] = 0;
        }     
    }

    for (int i = 0; i < 101; i++) {
        b[i]= 0;     
    }

    for (int i = 0; i < 101; i++) {
        c[i]= 0;     
    }

    cin >> n >> m;

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

    for (int i = 1; i < m + 1; i++) {
        cin >> b[i];     
    }

    for (int i = 1; i < n + 1; i++) {
        for (int j = 1; j < m + 1; j++){
        c[i] += a[i][j] * b[j];
        }
       cout << c[i] << endl;
    }
    
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

// 辺の構造体
struct Edge{ll to, cap, rev;};
// 隣接リスト表現を格納するvector
vector<vector<Edge> > G;
// 訪問済みフラグ
vector<bool> vis;
// 頂点の数と辺の数
ll N, M;

void unite(ll from, ll to, ll cap) {
    G[from].push_back({to, cap, (ll)G[to].size()});
    G[to].push_back({from, 0, (ll)G[from].size() - 1});
}

int dfs(ll v, ll t, ll f) {
    if(v == t) return f;
    vis[v] = true;
    for(auto &e:G[v]) {
        if(!vis[e.to] && e.cap > 0) {
            ll d = dfs(e.to, t, min(f, e.cap));
            if(d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll ford_flukerson(ll s, ll t) {
    ll ret = 0;
    for(;;) {
        vis.assign(N, false);
        ll f = dfs(s, t, INF);
        if(f == 0) return ret;
        ret += f;
    }
}

void solve() {
    cin >> N >> M;
    G.resize(N);
    REP(i, M) {
        ll x,y,c;
        cin >> x >> y >> c;
        unite(x, y, c);
    }
    out(ford_flukerson(0, N-1));
}

int main() {
    fast_io;
    solve();
    return 0;
}


Measured memory_bytes: 3216
#include<iostream>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
   long long  int k;
    cin>>k;
   long long  int arr[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    long long int result[n+1];
    result[1]=0;
    result[2]=abs(arr[2]-arr[1]);
    for(int i=3;i<=n;i++)
    {
        long long int m=1000000000000000000;
        for(int j=1;j<=k;j++)
        {   if(i-j>0)
        {
            long long int mkk=(abs(arr[i-j]-arr[i])+result[i-j]);
            if(mkk<m)
            m=mkk;}
            else break;
        }
        result[i]=m;
        
    }
    cout<<result[n]<<endl;
}

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

int main(){
  int64_t H,W;
  cin>>H>>W;
  if(H==1 || W==1) cout<<1<<endl;
  else{
    int64_t ans=0;
    for(int i=0;i<H;++i){
      if(i%2==0) ans += (W+1)/2;
      else ans += W/2;
    }
    cout<<ans<<endl;
  }
}

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

#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff first
#define ss second

using namespace std;

long long n,m,a[100010],ans;
pair<long long,long long> p[100010];

void cardGame(){
    cin>>n>>m;
    for (int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for (int i=0;i<m;i++) cin>>p[i].second>>p[i].first;
    sort(p,p+m);m--;
    for (int i=0;i<n;i++)
        if (p[m].first>a[i]){
            a[i]=p[m].first;
            p[m].second--;
            if (p[m].second==0) m--;
        }
    for (int i=0;i<n;i++) ans+=a[i];
    cout<<ans<<endl;
}

int main() {
    cardGame();
}


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

int main() {

    string s;
    cin >> s;
    ll ans = 0;
    int a_seq = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            s[i + 2] = 'A';
            ans += a_seq + 1;
            i++;
        } else if (s[i] == 'A') {
            a_seq++;
        } else {
            a_seq = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h> 
int main(){
	int k; 
	char s[102];
	scanf("%d",&k);
	scanf("%s",s);
	int n = strlen(s);
	if(n<=k){
		printf("%s",s);
	}else{
		int i = 0;
		for(i;i<k;i++){
			printf("%c",s[i]);
		}
		printf("...\n");
	} 
	return 0;
}

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

// DAME: 全探索

int main() {
	int N;
	cin >> N;
	vector<int> x(N), y(N), h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> h[i];
	}

	//[0, 100]に座標があるのでMAXを定義すると楽
	int MAX = 100;

	for (int posY = 0; posY <= MAX; posY++)
	{
		for (int posX = 0; posX <= MAX; posX++)
		{
			//頂上がどれくらいの高さであってほしいか。
			//-1はまだ良く分からない時。0以上は確定してるとき
			//-2はダメだって分かった時
			int needH = -1;

			for (int i = 0; i < N; i++)
			{
				if (h[i] > 0) {
					//この頂点から見て、頂上がposY,posXの時に、
					//どれくらいの高さがあってほしいかを求める
					int tmp = h[i] + abs(posY - y[i]) + abs(posX - x[i]);
					if (needH == -1) {
						needH = tmp;
					}
					else {
						if (needH != tmp) {
							needH = -2;
							break;
						}
					}
				}
			}
			//ダメだったら別の場所を探す。
			if (needH == -2) continue;

			for (int i = 0; i < N; i++)
			{
				//高さが0の場合に矛盾してないか調べる
				if (h[i] == 0) {
					int dist = abs(posY - y[i]) + abs(posX - x[i]);
					if (needH > dist) {
						needH = -2;
						break;
					}
				}
			}

			if (needH == -2) continue;

			//見つけられたら答えをそのまま返す。
			cout << posX << " " << posY << " " << needH << endl;
			return 0;
		}
	}

}






Measured memory_bytes: 256
import sys
n = int(input())
ps = [list(map(int, input().split())) for _ in range(n)]

if n == 1:
	#x, y, h = map(int, input().split())
	print(ps[0][0], ps[0][1], ps[0][2])
else:
	for X in range(101):
		for Y in range(101):
			valid = True
			const = -1
			for p in ps:
				x, y, h = p[0], p[1], p[2]
				if h != 0:
					if const < 0:
						const = abs(X - x) + abs(Y - y) + h
					else:
						if abs(X - x) + abs(Y - y) + h != const:
							valid = False
							break
				else:
					if const >= 0:
						if const - abs(X - x) - abs(Y - y) > 0:
							valid = False
							break
			for p in ps:
				x, y, h = p[0], p[1], p[2]
				if h == 0:
					if const >= 0:
						if const - abs(X - x) - abs(Y - y) > 0:
							valid = False
							break

			if valid == True:
				print(X, Y, const)
				sys.exit()

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

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

int calc(int a, int b, int c, int d, const vector<vector<int>> &t) {
  return t[t[t[t[0][a]][b]][c]][d];
}

int main(){
  vector<vector<int>> t(10, vector<int>(10));
  REP(i,10)REP(j,10) cin>>t[i][j];
  int cnt = 0;
  REP(a,10)REP(b,10)REP(c,10)REP(d,10) {
    int e = calc(a, b, c, d, t);
    vector<int> v = {a, b, c, d, e};
    bool valid = true;
    REP(i,5) REP(j,10) {
      auto tmp = v;
      if (v[i] == j) continue;
      tmp[i] = j;
      if (t[calc(tmp[0], tmp[1], tmp[2], tmp[3], t)][tmp[4]] == 0) {
        valid = false;
      }
    }
    REP(i,4) {
      auto tmp = v;
      if (tmp[i] == tmp[i+1]) continue;
      swap(tmp[i], tmp[i+1]);
      if (t[calc(tmp[0], tmp[1], tmp[2], tmp[3], t)][tmp[4]] == 0) {
        valid = false;
      }
    }
    if (!valid) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3160
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  S = list(map(int, input().split()))
  s.append(S)

ans = 0
blank = [0]*26
for i in range(D):
  t = int(input())
  ans += s[i][t-1]
  blank = [i+1 for i in blank]
  blank[t-1] = 0
  for j in range(26):
    ans -= blank[j] * c[j]
  print(ans)

Measured memory_bytes: 9392
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 10000)
	sc.Buffer(buf, 100000+1024)

	n := readLineToInt(sc)
	vValues := explodeInt(" ", readLine(sc))
	cValues := explodeInt(" ", readLine(sc))

	outputValue := 0

	for index := 0; index < n; index++ {
		vcValue := vValues[index] - cValues[index]

		if vcValue > 0 {
			outputValue += vcValue
		}
	}

	fmt.Println(outputValue)
}

// helper

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return strings.TrimSpace(sc.Text())
}

func readLineToInt(sc *bufio.Scanner) int {
	intValue, err := strconv.Atoi(readLine(sc))
	if err != nil {
		panic(err)
	}

	return intValue
}

func explodeString(delimiter string, inputValue string) []string {
	splittedValue := strings.Split(inputValue, delimiter)

	var trimmedValues []string

	for _, value := range splittedValue {
		if value != "" {
			trimmedValues = append(trimmedValues, value)
		}
	}

	return trimmedValues
}

func explodeInt(delimiter string, inputValue string) []int {
	inputStrings := explodeString(" ", inputValue)

	var splittedInts []int

	for _, inputString := range inputStrings {
		var (
			intValue int
			err      error
		)
		intValue, err = strconv.Atoi(inputString)

		if err != nil {
			panic(err)
		}
		splittedInts = append(splittedInts, intValue)
	}

	return splittedInts
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int N; cin >> N;
    vector<int> L(2*N);
    rep(i, 2*N) cin >> L[i];
    sort(all(L));
    int ans = 0;
    rep(i, 2*N) {
      ans += L[i];
      i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())

A=list(map(int,input().split()))

B=sorted(A,reverse=True)

ans=B[0]

sheets=[B[0]]

ans=0
for i in range(1,N):

    ans += sheets[i-1]
    sheets.append(B[i])
    sheets.append(B[i])

print(ans)

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;
int cnt[10];

bool dfs(int* c, int num) {
  if (num == 4) return true;
  for (int i = 1; i < 10; i++) {
    if (c[i] >= 3) {
      c[i] -= 3;
      if (dfs(c, num + 1)) return true;
      c[i] += 3;
    }
    if (i + 2 < 10 && c[i] && c[i + 1] && c[i + 2]) {
      c[i]--, c[i + 1]--, c[i + 2]--;
      if (dfs(c, num + 1)) return true;
      c[i]++, c[i + 1]++, c[i + 2]++;
    }
  }
  return false;
}

bool check(int d) {
  int c[10];
  memcpy(c, cnt, sizeof(cnt));
  if (++c[d] > 4) return false;
  bool ok = false;
  for (int i = 1; !ok && i < 10; i++) {
    if (c[i] >= 2) {
      c[i] -= 2;
      ok |= dfs(c, 0);
      c[i] += 2;
    }
  }
  return ok;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> s) {
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < 13; i++) {
      cnt[s[i] - '0']++;
    }
    vector<int> ans;
    for (int i = 1; i < 10; i++) {
      if (check(i)) ans.emplace_back(i); 
    }
    if (ans.empty()) {
      cout << "0" << endl;
      continue;
    }
    for (int i = 0; i < (int)ans.size(); i++) {
      cout << ans[i] << " \n"[i + 1 == (int)ans.size()];
    }
  }

  return 0;
}


Measured memory_bytes: 3124
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}

fn read_ints() -> Vec<i32> {
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn main() {
    let c: Vec<Vec<i32>> = (0..3).map(|_| read_ints()).collect();

    let mut ok = true;
    for i1 in 0..3 {
        for i2 in 0..3 {
            for j1 in 0..3 {
                for j2 in 0..3 {
                    if c[i1][j1] + c[i2][j2] != c[i1][j2] + c[i2][j1] {
                        ok = false;
                    }
                }
            }
        }
    }

    println!("{}", if ok { "Yes" } else { "No" });
}

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

using namespace std;

int main()
{
    string S;
    cin >> S;

    bool f = true;
    for(int i=0; i<S.length(); ++i){
        if(i % 2 == 1){
            if((S[i] == 'L') || (S[i] == 'U') || (S[i] == 'D')) f = true;
            else {f = false; break;}
        }
        else{
            if((S[i] == 'R') || (S[i] == 'U') || (S[i] == 'D')) f = true;
            else {f = false; break;}
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	x := 0
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			x += a[i]
		} else {
			x -= a[i]
		}
	}

	ans := make([]int, n)
	ans[0] = x / 2
	for i := 0; i < n-1; i++ {
		ans[i+1] = a[i] - ans[i]
	}
	for i := 0; i < n; i++ {
		ans[i] *= 2
	}

	fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
}


Measured memory_bytes: 9856
n = gets.to_i
ps = gets.split.map(&:to_i)
qs = gets.split.map(&:to_i)

p_cnt = 0
q_cnt = 0
(1..n).to_a.permutation.each_with_index do |l, i|
  p_cnt = i+1 if ps == l
  q_cnt = i+1 if qs == l
end

puts (p_cnt-q_cnt).abs

Measured memory_bytes: 2172
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include <string.h>
using namespace std;

#define ALP 26
#define OFFSET 97
char        out[100000];

int main() {
    int     N;
    int     ans;
    
    ans = 0;
    for ( int ii = 0; ii < 5; ii++ ) {
        cin >> N;
        if ( N == 0 ) {
            ans = ii + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<stdio.h>

int main(void){
	int s,i,j,tmp,ans;
	int t[]={3600,60,1};
	for(i=0;i<3;i++){
		tmp=ans=0;
		for(j=0;j<6;j++){
			scanf("%d",&s);
			if(j<3)tmp+=s*t[j];
			else ans+=s*t[j-3];
		}
		ans-=tmp;
		int h,m;
		h=ans/3600;
		ans=ans%3600;
		m=ans/60;
		printf("%d %d %d\n",h,m,ans%60);
		
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int64_t gcd(int64_t n, int64_t m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int64_t r = n % m;
        n = m;
        m = r;
    }
    return n;
}

int main() {
    int n;
    cin >> n;

    int64_t r;
    cin >> r;
    for (int i = 1; i < n; i++) {
        int64_t t;
        cin >> t;
        int64_t u = gcd(r, t);
        r = r / u * t;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#n = gets.chomp.to_i
n, d = gets.chomp.split(" ").map(&:to_i);

def distance (a, b)
  sum =0
  a.size.times do |i|
    sum += ((a[i] - b[i])**2)
  end
  sum
end

def can_root (d)
  i=2
  while true
    return true if d == 1
    if d % (i**2) == 0
      d = d / (i**2)
      i = 2
      next
    end
    if d == i
      return false
    end
    i+=1
  end
end

xs = []
n.times do
  xs <<  gets.chomp.split(" ").map(&:to_i);
end

count =0
xs.combination(2) do |a,b|
  d = distance(a,b)
  count +=1 if can_root (d)
end

puts count

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

int main() {
  string S;
  cin >> S;
  
  int y, m, d;
      
  y = stoi(S.substr(0,4));
  m = stoi(S.substr(5,2));
  d = stoi(S.substr(8,2));
  
  string ans = "Heisei";
  if(y>=2020) ans = "TBD";
  else if (y==2019) {
    if(m>=5) ans = "TBD";
    else if(m==4 && d>30) {
      ans = "TBD";
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import collections
n=int(input())
a=[input() for i in range(n)]
c = collections.Counter(a)
l=c.most_common()
ans=[]
for i in range(len(l)):
    if l[0][1]==l[i][1]:
        ans.append(l[i][0])
ans.sort()
[print(i) for i in ans]

Measured memory_bytes: 48660
// slimes

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
using namespace std;

ll computesum(ll i,ll j,vector<ll>& arr)
{
	ll s=0;
	for(ll x=i;x<=j;x++)
	{
		s+=arr[x];
	}
	return s;
}

void printmat(vector< vector<ll> >& dp,ll r,ll c)
{
	for(ll i=1;i<=r;i++)
	{
		for(ll j=1;j<=c;j++)
		{
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
}

ll givemin(ll i,ll j,vector<ll>& arr,vector< vector<ll> >& dp)
{
	ll result=-1;
	ll sum1,sum2,mindp;
	for(ll k=i;k<j;k++)
	{
		sum1=computesum(i,k,arr);
		sum2=computesum(k+1,j,arr);
		mindp=sum1+sum2+dp[i][k]+dp[k+1][j];
		if(result==-1)
		{
			result=mindp;
			continue;
		}
		result=min(result,mindp);
	}
	return result;
}

int main()
{
	ll n;
	cin>>n;
	vector<ll> arr(n+1);
	vector< vector<ll> > dp(n+1);
	for(ll i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	for(ll i=0;i<=n;i++)
	{
		dp[i].resize(n+1,0);
	}
	
	//dp table

	ll s=1;
	while(s<n)
	{
		ll j;
		for(ll i=1;i<=n-s;i++)
		{
			j=i+s;
			dp[i][j]=givemin(i,j,arr,dp);
		}
		s++;
	}
	
	cout<<dp[1][n]<<endl;
//	printmat(dp,n,n);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> cake(h);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            if(c == '#'){
                cake[i].push_back(j + 1);
            }
        }
    }
    int cnt = 1;
    vector<vector<int>> ans(h, vector<int>(w, 0));
    vector<bool> emp(h, true);
    for(int i = 0; i < h; i++){
        int p = 0;
        for(auto&& j : cake[i]){
            for(int k = p; k < j; k++){
                ans[i][k] = cnt;
            }
            cnt++;
            p = j;
            emp[i] = false;
        }
        if(cake.size() && p <= w - 1){
            for(int k = p; k < w; k++){
                ans[i][k] = ans[i][k - 1];
            }
        }
    }
    for(int i = 1; i < h; i++){
        if(emp[i]){
            ans[i] = ans[i - 1];
        }
    }
    for(int i = h - 2; i >= 0; i--){
        if(emp[i]){
            ans[i] = ans[i + 1];
        }
    }
    for(auto&& i : ans){
        cout << static_cast<int>(i[0]);
        for(int j = 1; j < w; j++){
            cout << " " << static_cast<int>(i[j]);
        }
        cout << "\n";
    }
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    for (; n>0;) {
        int num = n%10;
        n = n/10;
        if (num == 7) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

S = input().rstrip()

def F(S,target):
    cnt = 0
    while S.count(target) != len(S):
        cnt += 1
        S = ''.join(y if x != target else x for x,y in zip(S[:-1],S[1:]))
    return cnt

answer = min(F(S,t) for t in set(S))
print(answer)

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

int main()
{
    vector<long long> a(4);
    for (long long &x : a) cin >> x;
    long long ans = -1e18;
    for (int i = 0; i < 2; i++){
        for (int j = 2; j < 4; j++){
            long long temp = a[i] * a[j];
            ans = temp > ans ? temp : ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,m,x,y,a;
  int i;
  vector <int> v,w;
  
  cin>>n>>m>>x>>y;
  for(i=0;i<n;i++){
    cin>>a;
    v.push_back(a);
  }
  for(i=0;i<m;i++){
    cin>>a;
    w.push_back(a);
  }
  a=0;
  sort(v.begin(),v.end(),greater <int>());
  sort(w.begin(),w.end());
  
  for(i=y;i>x;i--){
    
    if(x<i&&i<=y&&v[0]<i&&i<=w[0])
      a++;
  }
  
    cout<<(a==0?"War":"No War")<<endl;
    return 0;

}

Measured memory_bytes: 256
n,k = map(int,input().split())
s = input()
tmp = s[0]
cnt = 1
ss = []
if s[0] == '0':
    ss.append(0)

for i in range(1,n):
    if s[i] == tmp:
        cnt += 1
    else:
        tmp = s[i]
        ss.append(cnt)
        cnt = 1
ss.append(cnt)
if s[-1] == '0':
    ss.append(0)
ll = len(ss)

l = 0
r = k*2
tt = sum(ss[l:r+1])
ans = tt
while True:
    l += 2
    r += 2
    if r > ll:
        break
    tt += ss[r] + ss[r-1]
    tt -= ss[l-1] + ss[l-2]
    ans = max(ans, tt)
print(ans)

Measured memory_bytes: 4480
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    cout << (n-1) * (m-1) << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

    /**
     * https://atcoder.jp/contests/dp/tasks/dp_e
     * 
     * In this question, W <= 10>9 which is aa huge number to have as dp dimension
     * instead of maximizing value subject to max weight we minimize weight
     * subject to value.
     */
    private static int sum(int[] v){
        int sum = 0;
        for(int i = 0; i < v.length; i++){
            sum += v[i];
        }
        return sum;
    }

    // space optimized version, value is the dimension  
    private static long solverOneDimension(int[] w, int[] v, int n, int max){
        
        int sumValues = sum(v);
        long[] dp = new long[sumValues + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        // iterate on items
        for(int i = 1; i <= n ;i++){

            int value = v[i - 1];
            int weight = w[i - 1];

            for(int value_already = sumValues - value; value_already >= 0; --value_already) {
                    dp[value_already + value] = Math.min(dp[value_already + value], dp[value_already] + weight);
            }
        }

        long answer = 0;
        
        for(int i = 0; i <= sumValues; i++) {
            if(dp[i] <= max) {
                answer = Math.max(answer, (long) i);
            }
        }
        return answer;
    }


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); // number of items
        int max = in.nextInt(); // max weight
        int[] w = new int[n];
        int[] v = new int[n];
        
        for(int i = 0; i < n; i++){
            w[i] = in.nextInt();
            v[i] = in.nextInt();
        }
        System.out.println(solverOneDimension(w, v, n, max));
        
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int X,Fi,Th,H;
  cin >> X;
  Th= X / 500;
  Fi = (X % 500) / 5;
  H=(Th*1000)+(5*Fi);
 if(X>=0&&X<=1000000000){
  cout << H;
 }
  return 0;
}

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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30
#define MOD 1000000007 // 1e9+7

int N;
int W;

vi vec[4];
int cnt[4];

int main()
{
	cin >> N >> W;
	int w0, v;
	cin >> w0 >> v;
	vec[0].push_back(v);
	cnt[0]++;

	rep(i,N-1){
		int w;
		cin >> w >> v;
		vec[w-w0].push_back(v);
		cnt[w-w0]++;
	}
	rep(i,4){
		std::sort(vec[i].begin(), vec[i].end(), std::greater<int>());
	}


	int m = 0;
	for( int i=0; i<=N; i++ ){
		int wi = i*w0;
		if( wi > W || i > cnt[0] ) break;
		for( int j=0; j<=N; j++ ){
			int wj = wi + j*(w0+1);
			if( wj > W || j > cnt[1] ) break;
			for( int k=0; k<=N; k++ ){
				int wk = wj + k*(w0+2);
				int l = min((W-wk) / (w0+3), cnt[3]);
				if( W-wk < 0 || k > cnt[2] ) break;
				int val = 0;
				rep(x,i) val += vec[0][x];
				rep(x,j) val += vec[1][x];
				rep(x,k) val += vec[2][x];
				rep(x,l) val += vec[3][x];
				if( val > m ) m = val;
			}
		}
	}
	
	cout << m << endl;

	return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main():
    S = input()
    s = S[:len(S)//2]
    if all(a==b for a,b in zip(S, reversed(S))) and all(a==b for a,b in zip(s, reversed(s))):
        print(Yes)
    else:
        print(No)


main()







Measured memory_bytes: 5808
PROGRAM ATCODER

implicit none
integer :: n,t,i,dp,ans=0,maxb
integer,allocatable :: a(:),b(:)

read(*,*) n,t
allocate(a(n),b(n))
read(*,*) (a(i), i=1,n)

b = 0
dp = 10**9
do i = 2,n
  call chmin(dp,a(i-1))
  b(i) = a(i) - dp
end do

maxb = maxval(b)
do i = 1,n
  if(b(i) == maxb)then
    ans = ans + 1
  end if
end do

write(*,'(i0)') ans

contains
!!!!!! サブルーチンは↓
subroutine chmin(dp,x)
implicit none
integer :: dp, x

if (dp > x) then
  dp = x
  return
end if

end subroutine
!!!!!!

END PROGRAM ATCODER

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, N;
	cin >> H >> N;
	vector<int> A(N);
	vector<int> B(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}
	int INF = (int)1 << 60;
	vector<int> dp(H + 1, INF);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = A[i]; j <= H; j++) {
			dp[j] = min(dp[j], dp[j - A[i]] + B[i]);
		}
	}
	res = INF;
	for (int i = 0; i < N; i++) {
		for (int j = max((int)0, H - A[i]); j <= H; j++) {
			res = min(res, dp[j] + B[i]);
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    char n[3];
    cin >> n;

    rep(i, 3){
        if(n[i] == '1'){
            cout << 9;
        }else if(n[i] == '9'){
            cout << 1;
        }else{
            cout << n[i];
        }
    }
    cout << endl;

    return 0;
}

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

string S;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> S;
    sort(S.begin(), S.end());
    if (S[0]==S[1] && S[1]!=S[2] && S[2]==S[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256