akhauriyash/Code-Regression huggingface dataset:
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
constexpr long double eps = 1e-9;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll x;
	scanf("%lld", &x);
	ll ans = 0, cnt = 100;
	while (cnt < x) {
		++ans;
		cnt += cnt / 100;
	}
	printf("%lld\n", ans);

	Please AC;
}


Measured memory_bytes: 3780
class UF:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int, input().split(" "))
ab = [list(map(int, input().split(" "))) for i in range(m)]

tr = UF(n)
for a,b in ab:
  tr.union(a, b)
count = [0]*(n+1)
for i in tr.par:
  count[tr.find(i)] = 1
print(sum(count)-2)

Measured memory_bytes: 92236
#include<cstdio>
#include<list>
#include<queue>
#include<functional>
using namespace std;
typedef long long weight;
weight const infty = 0x3f3f3f3f3f3f3f;
typedef pair<weight,int> edge;
class Graph{
    int numVertex;
    list<edge> *adj;
public:
    Graph(int v);
    void addEdge(int u,int v,weight w);
    void dijkstra(weight l[],int s);
};
//v頂点{0,1,...,v-1}0辺のグラフを作成
Graph::Graph(int v){
    this->numVertex=v;
    this->adj=new list<edge>[v];
}
//グラフに重さwの辺(u-v:無向グラフ)を追加
void Graph::addEdge(int u,int v,weight w){
    adj[u].push_back({w,v});
    adj[v].push_back({w,u});
}
//頂点sから点tへの最短経路l[t]を求める
//計算量O(ElogV)
void Graph::dijkstra(weight l[],int s){
    for(int i=0;i<numVertex;i++)l[i]=infty;
    l[s]=0;//l[始点]=0,l[それ以外]=無限大
    priority_queue<edge,vector<edge>,greater<edge>> pq;//firstを優先してソートするのでweightが先
    pq.push({0,s});//pq={(最短距離0,始点s)}
    while(!pq.empty()){
        int u=pq.top().second;
        pq.pop();
        for(auto i=adj[u].begin();i!=adj[u].end();i++){
            int v=(*i).second;
            weight w=(*i).first;
            if(l[v]>l[u]+w){
                l[v]=l[u]+w;
                pq.push({l[v],v});
            }
        }
    }
}
weight la[100000],lb[100000],minw[100000];
int main(){
    int n,m,s,t,u,v;
    weight a,b;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    Graph ga(n),gb(n);
    for(int i=0;i<m;i++){
        scanf("%d%d%lld%lld",&u,&v,&a,&b);
        ga.addEdge(u-1,v-1,a);
        gb.addEdge(u-1,v-1,b);
    }
    ga.dijkstra(la,s-1);
    gb.dijkstra(lb,t-1);
    minw[n-1]=la[n-1]+lb[n-1];
    for(int i=n-2;i>=0;i--)minw[i]=min(minw[i+1],la[i]+lb[i]);
    for(int i=0;i<n;i++)printf("%lld\n",(weight)1e15-minw[i]);
    return 0;
}

Measured memory_bytes: 25984
use std::io::{BufRead, Read};

pub struct Scanner<R>
where
    R: BufRead,
{
    reader: R,
}

impl<R> Scanner<R>
where
    R: BufRead,
{
    pub fn new(reader: R) -> Self {
        Scanner { reader: reader }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: ::std::str::FromStr,
        <T as ::std::str::FromStr>::Err: ::std::fmt::Debug,
    {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .unwrap()
    }
}

fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut sc = Scanner::new(stdin);

    let mut a: u64 = sc.next();
    let mut b: u64 = sc.next();
    if a > b {
        let tmp = a;
        a = b;
        b = tmp;
    }
    if (a + b) % 2 == 0 {
        println!("{}", (a + b) / 2);
    } else {
        println!("IMPOSSIBLE");
    }
}


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

from collections import deque

H,W = map(int,readline().split())
A = [line.rstrip().decode('utf-8') for line in readlines()]

class Dinic:
    def __init__(self, N, source, sink):
        self.N = N
        self.G = [[] for _ in range(N)]
        self.source = source
        self.sink = sink

    def add_edge(self, fr, to, cap):
        n1 = len(self.G[fr])
        n2 = len(self.G[to])
        self.G[fr].append([to, cap, n2])
        self.G[to].append([fr, 0, n1]) # 逆辺を cap 0 で追加
        
    def bfs(self):
        level = [0] * self.N
        G = self.G; source = self.source; sink = self.sink
        q = deque([source])
        level[source] = 1
        pop = q.popleft; append = q.append
        while q:
            v = pop()
            lv = level[v] + 1
            for to, cap, rev in G[v]:
                if not cap:
                    continue
                if level[to]:
                    continue
                level[to] = lv
                if to == sink:
                    self.level = level
                    return
                append(to)
        self.level = level
        
    def dfs(self,v,f):
        if v == self.sink:
            return f
        G = self.G
        prog = self.progress
        level = self.level
        lv = level[v]
        E = G[v]
        for i in range(prog[v],len(E)):
            to, cap, rev = E[i]
            prog[v] = i
            if not cap:
                continue
            if level[to] <= lv:
                continue
            x = f if f < cap else cap
            ff = self.dfs(to, x)
            if ff:
                E[i][1] -= ff
                G[to][rev][1] += ff
                return ff
        return 0
    
    def max_flow(self):
        INF = 10**18
        flow = 0
        while True:
            self.bfs()
            if not self.level[self.sink]:
                return flow
            self.progress = [0] * self.N
            while True:
                f = self.dfs(self.source, INF)
                if not f:
                    break
                flow += f
        return flow

source = 0
sink = H+W+1

dinic = Dinic(H+W+2, source, sink)
add = dinic.add_edge

INF = 10 ** 18
for h in range(1,H+1):
    for w,ox in enumerate(A[h-1],1):
        if ox == 'x':
            continue
        elif ox == 'o':
            add(h,H+w,1)
            add(H+w,h,1)
        elif ox == 'S':
            add(source,h,INF)
            add(h,source,INF)
            add(source,H+w,INF)
            add(H+w,source,INF)
        elif ox == 'T':
            add(sink,h,INF)
            add(h,sink,INF)
            add(sink,H+w,INF)
            add(H+w,sink,INF)

f = dinic.max_flow()
answer = f if f < INF else -1
print(answer)

Measured memory_bytes: 7540
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
int N,K;
vi A;
int datas[1145141]={0};
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
ll forodd[514514];
int main(){
	cin>>N>>K;
	if(K==1)cout<<0<<endl;
	else cout<<N-K<<endl;

}





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

#define int long long int

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

    int n, M;
    cin >> n >> M;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    int l = 0, r = 3e5;
    while (r - l > 1)
    {
        int j = n, m = (l + r) / 2, cnt = 0;
        for (int i = 0; i < n; i++)
        {
            while (j >= 1 && a[i] + a[j - 1] >= m) j--;
            cnt += n - j;
        }
        if (cnt >= M) l = m;
        else r = m;
    }

    int j = n, sum = 0, cnt = 0, sum_j = 0;
    for (int i = 0; i < n; i++)
    {
        while (j >= 1 && a[i] + a[j - 1] >= l) sum_j += a[j - 1], j--;
        cnt += n - j;
        sum += (n - j) * a[i] + sum_j;
    }
    sum -= (cnt - M) * l;
    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
w = list(map(int,input().split()))

wmin = []

w_sum = [w[0]]
for i in range(1,n):
    w_sum.append(w_sum[i-1] + w[i])

for i in range(n-1):
    wmin.append(abs(w_sum[n-1]-2*w_sum[i]))

print(min(wmin))


Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll n,k;
  ll a[1000000];
  ll sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n ; i++) {
    cin >> a[i];
  }
  sort(a,a+n);

  for (int i  = 0; i < k; i++) {
    sum += a[i];
  }
  cout << sum <<"\n";
  return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner

object Main { // -> Main
  def main(args: Array[String]) {
    val sc = new Scanner(System.in)
    val n = sc.nextInt
    val list: Array[Int] = Array.fill(n)(sc.nextInt)

    var flag = true
    var count = 0
    while (flag) {
      flag = false
      for (j <- n-1 to 1 by -1) {
        if (list(j) < list(j - 1)) {
          val tmp = list(j - 1)
          list(j - 1) = list(j)
          list(j) = tmp
          count += 1
          flag = true
        }
      }
    }
    println(list.toList.mkString(" "))
    println(count)
  }
}

Measured memory_bytes: 45276
#include<bits/stdc++.h>
using namespace std;
#define BeatMeScanf ios_base::sync_with_stdio(false)
#define ll long long
#define sz 100505

bool is_prime[sz];
vector<int>primes;
void sieve()
{
    for(ll i=2;i<=sz;i++) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=4;i<=sz;i+=2) is_prime[i]=false;
    for(ll i=3;i<=sz;i++){
        if(is_prime[i]){
            for(ll j=i*i;j<=sz;j+=i) is_prime[j]=false;
        }
    }
    for (int i=2;i<=sz;++i) if(is_prime[i]) primes.push_back(i);
}

int main(){
    BeatMeScanf;
    sieve();
    int x;
    while(cin>>x){
        for(int i=0;i<primes.size();i++){
            if(primes[i]>=x){
                cout<<primes[i]<<endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 512
n, a, b = map(int, input().split())
sumdict = dict()
for i in range(1, 37) :
    sumdict[i] = [0]
for i in range(1, n + 1) :
    sumofi = sum([int(k) for k in list(str(i))])
    sumdict[sumofi] += [i]
ans = 0
for i in range(a, b + 1) :
    ans += sum(sumdict[i])
print(ans)

Measured memory_bytes: 3424
fn mod_pow(x: i64, n: i64, mod_: i64) -> i64 {
    if n > 0 {
        mod_pow(x * x % mod_, n >> 1, mod_) * if n & 1 == 1 { x } else { 1_i64 } % mod_
    } else {
        1_i64
    }
}

struct ModCulc {
    fact: Vec<i64>,
    fact_inv: Vec<i64>,
    mod_: i64,
}

impl ModCulc {
    fn new(n: usize, mod_: i64) -> Self {
        let mut f: Vec<i64> = vec![1; n];
        let mut f_i: Vec<i64> = vec![1; n];
        for i in 1..n {
            f[i] = (f[i - 1] * i as i64) % mod_;
            f_i[i] = mod_pow(f[i], mod_ - 2, mod_);
        }
        ModCulc {
            fact: f,
            fact_inv: f_i,
            mod_: mod_,
        }
    }

    fn nCr(&self, n: usize, r: usize) -> i64 {
        ((self.fact[n] * self.fact_inv[r]) % self.mod_ * self.fact_inv[n - r]) % self.mod_
    }
}

use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: usize = read();
    let b: usize = read();
    let k: usize = read();
    let mod_ = 998244353;
    let mc = ModCulc::new(n + 1, mod_);

    let mut ans = 0;
    for i in 0..std::cmp::min(n, k / a) + 1 {
        let po = k - i * a;
        if po % b == 0 && po / b <= n {
            ans += (mc.nCr(n, i) * mc.nCr(n, po / b)) % mod_;
            ans %= mod_;
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 12540
# ARC083C - Sugar Water (ABC074C)
def main():
    # input
    a, b, c, d, e, f = list(map(int, input().rstrip().split()))
    A = a * 100
    B = b * 100

    # default values
    x, y = min(a, b) * 100, 0  # density may be 0%
    dens = y / x

    # exhaustive search
    for i in range(f // A + 1):
        for j in range(((f - A * i) // B) + 1):
            if i == 0 and j == 0:
                continue
            water = i * A + j * B
            rest = f - water
            for k in range(rest // c + 1):
                for l in range((rest - c * k) // d + 1):
                    sugar = c * k + d * l
                    total = water + sugar

                    if sugar / total > e / (e + 100):  # compare to e (the max density)
                        break
                    else:
                        if sugar / total > dens:
                            dens = sugar / total
                            x, y = total, sugar
    print(x, y)


if __name__ == "__main__":
    main()

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

// clang-format off
#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

#define rep(i, n) for (int i = 0; i < (int)(n); ++(i))
#define reps(i, n) for (int i = 1; i <= (int)(n); ++(i))
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --(i))
#define rreps(i, n) for (int i = (int)(n); i > 0; --(i))

#define range(i, l, r) for (int i = (int)l; i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = ((int)(r) - 1); i >= (int)l; --(i))

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)

using int32 = int;
using int64 = long long;

constexpr int mod     = 1e9 + 7;
constexpr int32 inf   = 1001001001;
constexpr int64 infll = 1001001001001001001ll;
constexpr int dx[]    = {0, -1, 1, 0, -1, 1, -1, 1},
              dy[]    = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

template<typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
  int N = input(), M = input();

  vector<int> cnt(M);
  range(i, 0, N) {
    int K = input();
    range(j, 0, K) {
      cnt[input() - 1]++;
    }
  }

  int ans = 0;
  range(i, 0, M) {
    if (cnt[i] == N) ans++;
  } 

  cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 100005;

ll solve(ll x){
  ll ret = 0L;
  for(int i=0;i<41;i++){
    ll zu = (x+1)/(1L<<(i+1));
    ll cnt = zu * (1L<<i);
    ll lf = (x+1)%(1L<<(i+1));
    if(lf>(1L<<i))cnt+=lf-(1L<<i);
    if(cnt&1L)ret|=(1L<<i);
  }
  return ret;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
   ll x,y;
   cin>>x>>y;
   ll ret = solve(y);
   if(x>0)ret^=solve(x-1L);
   cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int bfs(int src,vector <int> &dp, map <int,vector <int> > &mp)
{
    if(dp[src]!=-1)
    {
        return dp[src];
    }
    if(mp.find(src)==mp.end())
    {
        dp[src]=0;
        return 0;
    }
    vector <int> temp = mp[src];
    int best=0;
    for(int i=0;i<temp.size();i++)
    {
        best = max(best,bfs(temp[i],dp,mp));
    }
    dp[src] = 1+best;
    return dp[src];
}
int main()
{
    int n,m;
    cin>>n>>m;
    map <int,vector <int> > mp;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        mp[x].push_back(y);
    }
    vector <int> dp(100001,-1);
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        ans = max(ans,bfs(i,dp,mp));
    }
    cout<<ans<<endl;
}


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

int main(){
    int N;
    int cnt = 0;
    cin >> N;
    vector<int> a(N);

    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        if(a[i] != i + 1){
            ++cnt;
        }
    }
    if(cnt <= 2){
        cout <<  "YES" <<endl;
    }
    else{
        cout << "NO" <<endl;
    }
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<int>> answe(H, vector<int>(W, 0));//答え。
  
  vector<string> vec(H+2);// 一回り大きい（.でかこむ）
  for (int j = 0; j < W+2; j++){
    vec[0][j] == '.';
    vec[H+1][j] == '.';
  }

  for (int i = 1; i < H+1; i++){
    string str;
    cin >> str;
    vec[i] = '.' + str + '.';
  }
  
  for (int i = 1; i < H+1; i++){
    for (int j = 1; j < W+1; j++){
      if(vec[i][j] == '#') answe[i-1][j-1] = -1;

      else {
        if (vec[i-1][j-1] == '#') answe[i-1][j-1]++;
        if (vec[i-1][j] == '#') answe[i-1][j-1]++;
        if (vec[i-1][j+1] == '#') answe[i-1][j-1]++;
        if (vec[i][j-1] == '#') answe[i-1][j-1]++;
        if (vec[i][j+1] == '#') answe[i-1][j-1]++;
        if (vec[i+1][j-1] == '#') answe[i-1][j-1]++;
        if (vec[i+1][j] == '#') answe[i-1][j-1]++;
        if (vec[i+1][j+1] == '#') answe[i-1][j-1]++;
      }
    }
  }
  vector<vector<string>> ans(H, vector<string>(W, "#"));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (answe[i][j] != -1){
        string x = to_string(answe[i][j]);
        ans[i][j] = x;
      }
    }
  }
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
    cout << ans[i][j];
    if (j == W-1) cout << endl;
    }
  }    
}


Measured memory_bytes: 384
import math


def main():
    k = int(input())

    GCD = [[0] * 201 for i in range(201)]
    for ki1 in range(1, k + 1):
        for ki2 in range(1, k + 1):
            GCD[ki1][ki2] = math.gcd(ki1, ki2)

    ans = 0
    for ki1 in range(1, k + 1):
        for ki2 in range(1, k + 1):
            for ki3 in range(1, k + 1):
                ans += GCD[GCD[ki1][ki2]][ki3]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68324
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c;
    char d,e;
    cin >> a >> d >> b >> e >> c;
    if (b >= 5) {
        cout << "TBD" << endl;
    } else {
        cout << "Heisei" << endl;
    }
}


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

using namespace std;

int main() {
    int N=0;
    vector<int> height;
    
    cin>>N;
    for(int I=0; I<N; I++) {
        int temp=0;
        cin>>temp;
        height.push_back(temp);
    }

    vector<int> cost(N);
    cost[1] = abs(height[0] - height[1]);
    for(int I=2; I<N; I++) {
        cost[I] = min((cost[I-1] + abs(height[I-1]-height[I])) ,(cost[I-2]+abs(height[I-2]-height[I])));
    }

    cout<<cost[N-1]<<endl;


    return 0;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    ll n, m;
    cin >> n >> m;
    if(n == 1 && m == 1){
        cout << 1 << endl;
        exit(0);
    }
    if(n==1){
        cout << m - 2 << endl;
        exit(0);
    }
    if(m==1){
        cout << n - 2 << endl;
        exit(0);
    }
    ll res = n*m -2*(n+m);
    if(res == 0) cout << 0 << endl;
    else cout << res + 4 << endl;
    
}

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

Measured memory_bytes: 256
#include <stdio.h>
typedef long long LL;

int c[100001] = {0};

int read()
{
	char c;
	while((c = getchar()) < 48 || c > 57);
	int x = c - 48;
	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;
	return x;
}

int main()
{	 
	int n, T, x, y, t;
	LL s = 0;
		
	n = read();
	while(n--){
		x = read();
		c[x]++, s += x;
	}
	
	T = read();
	while(T--){
		x = read(), y = read();
		t = c[x], c[y] += t, c[x] = 0;
		s += (LL)(y - x) * (LL)t;
		printf("%lld\n", s);
	}
		
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    ll sum = 0;
    for (int i = N; i > 0; i--)
    {
        if(i %3 == 0){

        }
        else if(i % 5 == 0){

        }
        else{
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
def solve_dp(s):
    n = len(s)
    s = [int(c) for c in s]
    inf = 10**9

    dp = [[inf] * 2 for _ in range(n)]

    d0 = s[0]
    dp[0][0] = d0
    dp[0][1] = d0+1

    for i in range(1, n):
        for j in range(2):
            d = s[i] + j
            for k in range(10):
                if d + k >= 10:
                    dp[i][j] = min(dp[i][j], dp[i-1][1] + 2*k + d - 10)
                else:
                    dp[i][j] = min(dp[i][j], dp[i-1][0] + 2*k + d)

    return dp[n-1][0]

if __name__ == '__main__':
    s = input()
    s = "0"+ s
    print(solve_dp(s))

Measured memory_bytes: 154884
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, k, n, a, ans = 0, s, b;
  scanf("%lld%lld", &k, &n);
  scanf("%lld", &s), b = s;
  for(i = 1; i < n; ++i) {
    scanf("%lld", &a);
    if(ans < a - b) ans = a - b;
    b = a;
  }
  if(ans < s + k - a) ans = s + k - a;
  printf("%lld", k - ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                             \
  cerr << __LINE__ << ": " << #x << " = {";          \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) { \
    cerr << ((hoge) ? "," : "") << x[hoge];          \
  }                                                  \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[3 * N];
  for (int i = 0; i < 3 * N; i++) cin >> A[i], A[i]--;
  const int INF = INT_MAX / 10;
  int dp[N][N];
  int dp_max[N];
  int dp_maxx = 0;
  for (int i = 0; i < N; i++) fill(dp[i], dp[i] + N, -INF);
  fill(dp_max, dp_max + N, -INF);
  dp[A[0]][A[1]] = 0;
  dp[A[1]][A[0]] = 0;
  dp_max[A[0]] = 0;
  dp_max[A[1]] = 0;
  int ans = 0;
  for (int i = 1; i < N; i++) {
    int a = A[3 * i - 1], b = A[3 * i], c = A[3 * i + 1];
    if (a == b && b == c) {
      ans++;
      continue;
    }
    vector<tuple<int, int, int>> upd;
    for (int _ = 0; _ < 3; _++) {
      int tmp = a;
      a = b;
      b = c;
      c = tmp;
      if (a == b) {
        for (int k = 0; k < N; k++) {
          upd.emplace_back(c, k, dp[a][k] + 1);
        }
      }
    }
    for (int _ = 0; _ < 3; _++) {
      int tmp = a;
      a = b;
      b = c;
      c = tmp;
      for (int k = 0; k < N; k++) {
        upd.emplace_back(a, k, dp_max[k]);
      }
    }
    for (int _ = 0; _ < 3; _++) {
      int tmp = a;
      a = b;
      b = c;
      c = tmp;
      upd.emplace_back(b, c, dp_maxx);
    }
    for (int _ = 0; _ < 3; _++) {
      int tmp = a;
      a = b;
      b = c;
      c = tmp;
      upd.emplace_back(b, c, dp[a][a] + 1);
    }
    for (auto tmp : upd) {
      int x, y, val;
      tie(x, y, val) = tmp;
      dp[x][y] = dp[y][x] = max(dp[x][y], val);
      dp_max[x] = max(dp_max[x], dp[x][y]);
      dp_max[y] = max(dp_max[y], dp[x][y]);
      dp_maxx = max(dp_maxx, dp[x][y]);
    }
  }
  int mx = 0;
  for (int k = 0; k < N; k++) {
    for (int l = 0; l < N; l++) {
      int tmp = dp[k][l];
      if (k == l && l == A[3 * N - 1]) tmp++;
      mx = max(mx, tmp);
    }
  }
  ans += mx;
  cout << ans << endl;
  return 0;
}


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

int main(){
	vector<int> a(5);
	for(int i=0;i<5;i++)cin >> a[i];
	int ans=999;
	for(int i=0;i<5;i++){
		int tmp=0;
		for(int j=0;j<5;j++){
			if(i==j)tmp+=a[j];
			else {
				tmp+=a[j];
				if(a[j]%10>0)tmp+=10-(a[j]%10);
			}
		}
		ans=min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
#define mod 1000000007
signed main(){
    int n;
    cin>>n;
    int c=0;
    int t=0,k=0,l=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int j=0;j<s.size()-1;j++){
            if(s[j]=='A'&&s[j+1]=='B')c++;
        }
        if(s[0]=='B'&&s[s.size()-1]=='A')t++;
        else if(s[0]=='B')k++;
        else if(s[s.size()-1]=='A')l++;
    }
    if(t>0){
        c+=t-1;
        if(k>0){
            k--;
            c+=1;
        }
        if(l>0){
            l--;
            c+=1;
        }
    }
    if(k>0&&l>0){
        c+=min(k,l);
    }
    cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
using namespace std;

#define INF 1e18
#define int long long

template<typename T>
void printVec(vector<T> &v) {
    for(int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}

int fact(int n) {
    if(n == 1) return 1;
    return n * fact(n - 1);
}

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

    vector<vector<double> > v(n, vector<double> (n, 0));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            double dist = sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)) * 1.0;
            v[i][j] = dist;
        }
    }

    vector<int> w(n);
    for(int i = 0; i < n; i++) w[i] = i;

    double sum = 0;
    do {
        for(int i = 1; i < n; i++) {
            sum += v[w[i]][w[i - 1]];
        }
    } while(next_permutation(w.begin(), w.end()));

    cout << setprecision(10) << sum * 1.0 / fact(n) << endl;
}


Measured memory_bytes: 764
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<LL> a(n), b(n), c(n);
		REP(i,n) cin >> a[i];
		REP(i,n) cin >> b[i];
		REP(i,n) cin >> c[i];
		sort(ALL(a));
		sort(ALL(b));
		sort(ALL(c));
		LL ans = 0;
		vector<LL> memo(n);
		REP(i,n){
			memo[i] = lower_bound(ALL(a), b[i])-a.begin();
		}
		REP(i,n-1) memo[i+1] += memo[i];
		dpite(ALL(memo));
		REP(i,n){
			int k = lower_bound(ALL(b), c[i])-b.begin();
			k--;
			DEBUG(k);
			if(k >= 0) {
				ans += memo[k];
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main(){
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    long long ans;
    if(K <= A){
        ans = K;
    }
    else if(K <= A + B){
        ans = A;
    }
    else{
        ans = 2 * A + B - K;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3632
using System;
using System.Linq;

class E
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int x = h[0], y = h[1];
		Console.WriteLine(Read().OrderBy(v => -v).Take(x).Concat(Read().OrderBy(v => -v).Take(y)).Concat(Read()).OrderBy(v => -v).Take(x + y).Sum(v => (long)v));
	}
}


Measured memory_bytes: 48556
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>
using namespace std;

int main() {
	int ans = 1,a,b,k = 1;
	cin >> a >> b;
	int A = b;
	while (A != 0) {
		A /= 10;
		k*=10;
	}
	a *= k;
	a += b;

	while (1) {
		if (ans * ans == a) {
			cout << "Yes" << endl;
			return 0;
		}
		else if(ans * ans > a) {
			break;
		}
		ans++;
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
using namespace std;
int main(void){
    ll n,m;
    cin>>n>>m;
    if(n>m){
        swap(n,m);
    }
    ll ans;
    if(n==1){
        if(m==1){
            ans=1;
        }else{
            ans=n*(m-2);
        }
        cout<<ans<<endl;
    }else if(n==2){
        cout<<0<<endl;
    }else{
        ans=(n-2)*(m-2);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x, *a = map(int, input().split())
y, *b = map(int, input().split())
z, *c = map(int, input().split())

_a = set(range(1, n+1)) ^ set(a)
match1 = set(_a) & set(c)
match2 = set(b) & set(c)
print(len(match1 | match2))


Measured memory_bytes: 5616
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{ 
  priority_queue<int, vector<int>, greater<int> > QA;
  priority_queue<int, vector<int>, greater<int> > QB;
  priority_queue<int> QC;
  int X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  for (int i = 0; i < A; i++)
  {
    int Z;cin>>Z;
    QA.push(Z);
  }
    for (int i = 0; i < B; i++)
  {
    int Z;cin>>Z;
    QB.push(Z);
  }
    for (int i = 0; i < C; i++)
  {
    int Z;cin>>Z;
    QC.push(Z);
  }
  while(QA.size() != X)QA.pop();
  while(QB.size() != Y)QB.pop();
  
  while(!QA.empty())
  {
    QC.push(QA.top());
    QA.pop();
  }
  while(!QB.empty())
  {
    QC.push(QB.top());
    QB.pop();
  }
    int ANS = 0;

  for (int i = 0; i < X+Y; i++)
  {
    ANS += QC.top();
    QC.pop();
  }
  
  cout<<ANS<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 8048
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n,k;
	string s;
	cin >> n >> s >> k;
	for (int i = 0; i < n; i++) {
		if (s[i] != s[k-1]) {
			s.replace(i, 1, "*");
		}
	}
	cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll dp[22222];

signed main()
{
	ll H, N;
	cin >> H >> N;
	vector<ll> A;
	vector<ll> B;
	REP(i, N){
		ll a, b;
		cin >> a >> b;
		A.PB(a);
		B.PB(b);
	}
	dp[0]=0;
	FOR(i, 1, 22221){
		dp[i] = INF;
	}
	REP(i, 22222){
		REP(k, N){
			if(i-A[k]>=0){
				if(dp[i]>dp[i-A[k]]+B[k]){
				dp[i] = dp[i-A[k]]+B[k];
				}
			}
		}
	}
	ll ans=INF;
	FOR(i, H, 22221){
		if(ans>dp[i]){
			ans=dp[i];
		}
	}
	cout << ans << endl;
}


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

int main(){ 
    int a,b;
    cin >> a >> b;
    
    if(a<1 || a>9 || b<1 || b>9 ){
        cout << "-1" << endl;
    } else {
        cout << a*b << endl;
    }
    
    
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n, m;
    cin >> n >> m;
    int x[n];
    map<int, int> mp;
    rep(i, 0, n) {
        cin >> x[i];
        mp[x[i]]++;
    }
    vector<int> md(m, 0), cnt(m, 0);
    for (auto it : mp) {
        int idx = it.first % m;
        md[idx] += it.second;
        cnt[idx] += it.second / 2;
    }
    int ans = md[0] / 2;
    rep(i, 1, (m + 1) / 2) {
        // cout << ans << "\n";
        ans += min(md[i], md[m - i]);
        int amari = abs(md[i] - md[m - i]);
        if (md[i] > md[m - i]) {
            ans += min(cnt[i], amari / 2);
        } else {
            ans += min(cnt[m - i], amari / 2);
        }
    }
    if (m % 2 == 0) {
        ans += md[m / 2] / 2;
    }
    cout << ans << "\n";
}

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

int main() {
  string s, ss;
  cin >> s;

  rep(i, s.size()) {
    rep(j, s.size() - i) {
      ss = s;
      ss.erase(i, j);
      if (ss == "keyence") {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  if((abs(a-b)<=d&&abs(b-c)<=d)||(abs(a-c)<=d)){printf("Yes");}
  else{printf("No");}
return 0;

}

Measured memory_bytes: 128
using System;
using System.Text;
using static ConsoleReader;

class Program
{
    static void Main(string[] args)
    {
        var a = Read<int>();
        Console.WriteLine(a + a*a + a*a*a);
    }
}

public static class IntExtentions
{
    public static void Times(this int n, Action<int> action)
    {
        for (var i = 0; i < n; i++)
        {
            action(i);
        }
    }

    public static void Times(this (int n, int m) dimensions, Action<int, int> action)
    {
        var (n, m) = dimensions;
        n.Times(i => m.Times(j => action(i, j)));
    }
}

public static class ConsoleReader
{
    public static T Read<T>()
        where T : IConvertible
    {
        var inputBuffer = new StringBuilder();
        int currChar;

        while ((currChar = Console.Read()) != -1)
        {
            if (!char.IsWhiteSpace((char)currChar))
            {
                inputBuffer.Append((char)currChar);
            }
            else if (inputBuffer.Length != 0)
            {
                break;
            }
        }

        return (T)Convert.ChangeType(inputBuffer.ToString(), typeof(T));
    }

    public static T[] ReadArray<T>(int count)
        where T : IConvertible
    {
        if (count < 0)
        {
            throw new ArgumentOutOfRangeException(nameof(count), $"'{nameof(count)}' must be >= 0");
        }

        var result = new T[count];

        for (var i = 0; i < count; i++)
        {
            result[i] = Read<T>();
        }

        return result;
    }
}

Measured memory_bytes: 27572
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int n,s=0,k,t,d=0;
	cin>>n>>k;
	s=k;
	vi v(n);
	REP(i,0,n-1){
		cin>>v[i];
	}
	REP(i,0,n-2){
		d=v[i+1]-v[i];
		t=std::min(d,k);
		s+=t;
		
	}
	cout<<s;
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 1792
while True:
    n,m = map(int,input().split())
    if n==0 and m==0:
        break
    maxz = 0
    a = input().split()
    l = list(map(int,a))
    b = 0
    
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if l[i]+l[j] <= m and  maxz < l[i]+l[j]:                    
                maxz = l[i]+l[j]
        
    if maxz ==  0:
        print("NONE")
    else:
        print(maxz)


Measured memory_bytes: 5628
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Kagami Mochi
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", &ds[i]);
  sort(ds, ds + n);
  int un = unique(ds, ds + n) - ds;

  printf("%d\n", un);
  return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m,x,y = li()
xs = list(li()) + [x]
ys = list(li()) + [y]

xmax = max(xs)
ymin = min(ys)

if xmax < ymin:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064