akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX/5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

signed main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int a = 1; a <= 1000000; a++) {
		ans += (N - 1) / a - (1 / a + bool(1 % a)) + 1;
	}
	cout << ans << endl;
}

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

int main(){
	/*input*/
	string s, t;	cin >> s >> t;
	/*calculation*/
	bool flag = false;
	for(int i = 0; i < s.size(); i++){
		char tmp = s.at(s.size() - 1); 
		s.pop_back();
		s.insert(s.begin(), tmp);
		if(s == t){
			flag = true;
			break;
		}
	}
	/*output*/
	if(flag){
		cout << "Yes" << endl;  
	}else{
		cout << "No" << endl;
	}
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int n;
int a[N];

int main() {

	FAST;

	int a, b, t;
	cin >> a >> b >> t;
	cout << b * (t / a) << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	long K;
	long[] bin;
	public void solve() {
		N = nextInt();
		K = nextLong();
		bin = new long[100000+1];
		for(int i = 0;i < N;i++){
			int a = nextInt()-1;
			int b = nextInt();

			bin[a]+=b;
		}

		long sum = 0;
		for(int i = 0;i < 100000+1;i++){
			if(bin[i]+sum < K){
				sum += bin[i];
				continue;
			}
			out.println(i+1);
			return;
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 43328
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int K, int A, int B)
        {
            if (K <= A) { return K + 1; }
            if (A >= B - 1) { return K + 1; }
            K -= A - 1;
            int N = K / 2;
            int M = K % 2;
            return Math.BigMul(B - A, N) + A + M;
        }   

        static void Main(string[] args)
        {
            var V = ReadInts();
            Console.WriteLine(Solve(V[0], V[1], V[2]));
        }
    }
}


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

int main() {
    string N;
    cin >> N;
    long long sum=0;
    for (long long i=0; i<N.size(); i++) {
        sum+=(N.at(i)-'0');
        sum%=9;
    }
    if (sum%9==0) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3748
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int N=100005;
int a[N];
int main()
{
    int n;
    cin>>n;
    int t1=0,t2=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%4==0)
            t1++;
        else if(a[i]%2==0)
            t2++;
    }
    int flag=0;
    int m;
    if(t2%2==0) m=t2;
    else m=t2-1;
    if((n-m)/2<=t1)flag=1;
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 640
def frog_hops(arr):
    n = len(arr)
    d = [0] * n
    d[1] = abs(arr[1] - arr[0])
    for i in range(2, n):
        first = d[i-1] + abs(arr[i] - arr[i-1])
        second = d[i-2] + abs(arr[i] - arr[i-2])
        d[i] = min(first, second)

    print(d[-1])
    

n = int(input())
arr = list(map(int, input().split()))

frog_hops(arr)


Measured memory_bytes: 13928
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L << 59;

long even(long n) {
    return n == 0 ? 2 : n % 2;
}

long odd(long n) {
    return 1 - n % 2;
}

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.chomp.to!long).array;

    auto dp = new long[][](N+1, 5);
    foreach (i; 0..N+1) dp[i][] = INF;

    dp[0][0] = 0;
    //foreach (i; 0..N) {
    //    dp[i+1][0] = dp[i][0] + A[i];
    //}

    foreach (i; 0..N) {
        long m = dp[i][0];
        dp[i+1][0] = min(dp[i+1][0], m + A[i]);

        m = min(m, dp[i][1]);
        dp[i+1][1] = min(dp[i+1][1], m + even(A[i]));

        m = min(m, dp[i][2]);
        dp[i+1][2] = min(dp[i+1][2], m + odd(A[i]));

        m = min(m, dp[i][3]);
        dp[i+1][3] = min(dp[i+1][3], m + even(A[i]));

        m = min(m, dp[i][4]);
        dp[i+1][4] = min(dp[i+1][4], m + A[i]);
    }

    dp[N].reduce!min.writeln;
}


Measured memory_bytes: 23036
#include <iostream>
#include <math.h>
 
using namespace std;
 
int main(void)
{
    long N, a, Nd[2], i;
 
    cin >> N;
 
    a = sqrt(N);
 
    for(i=a; i>=1; i--){
        if(N % i == 0){
            Nd[0] = N / i;
            Nd[1] = i;
            break;
        }
    }
 
    cout << Nd[0]+Nd[1]-2 << endl;
 
    return 0;
}

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

#define llint long long int

using namespace std;

int main(){
    int X, Y;

    cin >> X >> Y;

    if(Y % 2 == 0 && 2 * X <= Y && Y <= 4 * X){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

struct UnionFind {
    vector<int> p;
    UnionFind(int n) {
        p = vector<int>(n, -1);
    }
    int parent(int a) {
        if (p[a] <= -1) return a;
        return p[a] = parent(p[a]);
    }

    bool unite(int a, int b) {
        a = parent(a);
        b = parent(b);
        if (same(a, b)) return false;
        if (size(a) < size(b)) swap(a, b);
        p[a] += p[b];
        p[b] = a;
        return true;
    }

    int size(int a) {
        return -p[parent(a)];
    }
    int same(int a, int b) {
        return parent(a) == parent(b);
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uni(n);
    vector<int> cnt(n, 0);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        uni.unite(a, b);
        ++cnt[a];
        ++cnt[b];
    }
    vector<int> block(n, 0);
    rep(i, k) {
        int c, d;
        cin >> c >> d;
        --c, --d;
        if (uni.same(c, d)) {
            ++block[c];
            ++block[d];
        }
    }
    //rep(i, n) {
    //    cout << uni.size(i) << " " << cnt[i] << " " << block[i] << endl;
    //}
    rep(i, n) {
        if (i >= 1) cout << " ";
        cout << uni.size(i) - 1 - cnt[i] - block[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4580
n, m = gets.split(' ').map(&:to_i)
k = m - n
xs = gets
if k <= 0
  puts 0
else
  puts xs.split(' ').map(&:to_i).sort.each_cons(2).map{|x| x[1] - x[0] }.sort.first(k).inject(&:+)
end


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

int main() {
  vector<vector<int>>p(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>p.at(i).at(j);
    }
  }
  int a=0;
  if(p.at(0).at(0)-p.at(0).at(1)!=p.at(1).at(0)-p.at(1).at(1)||p.at(0).at(0)-p.at(0).at(1)!=p.at(2).at(0)-p.at(2).at(1)){
    a++;
  }
  if(p.at(0).at(2)-p.at(0).at(1)!=p.at(1).at(2)-p.at(1).at(1)||p.at(0).at(2)-p.at(0).at(1)!=p.at(2).at(2)-p.at(2).at(1)){
    a++;
  }
  if(p.at(0).at(0)-p.at(1).at(0)!=p.at(0).at(1)-p.at(1).at(1)||p.at(0).at(0)-p.at(1).at(0)!=p.at(0).at(2)-p.at(1).at(2)){
    a++;
  }
  if(p.at(2).at(0)-p.at(1).at(0)!=p.at(2).at(1)-p.at(1).at(1)||p.at(2).at(0)-p.at(1).at(0)!=p.at(2).at(2)-p.at(1).at(2)){
    a++;
  }
  if(a==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  
}

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

int main(){
    while(1){
        int H,W;
        cin >> H >> W;
        if(H==0) break;
        
        for (int i=0;i<H;i++){
            for (int j=0;j<W;j++){
                if (i==0 || j==0 || i==H-1 || j==W-1){
                    cout << "#";
                }else {
                    cout << ".";
                }
            }
            cout <<endl;
        }
        cout <<endl;
    }
    return 0;
}


Measured memory_bytes: 2988
#include <bits/stdc++.h>
using namespace std;
int a;
int b;
int n;
int main()
{
    cin >> a >> b >> n;
    int m = a+b;
    if (m >= n)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    } 
    return 0;
}

Measured memory_bytes: 256
#AIsing2020 b

import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
A =[0]+list(map(int,input().split()))
count = 0
for i in range(1,N+1,2):
    if A[i]%2 ==1:
        count +=1
print(count)


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

const int Maxn = 1e5 + 54;
int n, m;
struct Node{int a, b;}s[Maxn];

bool cmp(Node x, Node y) {
	return x.b == y.b ? x.a > y.a : x.b < y.b; 
}

int main() {
	cin >> n>> m;
	for (int i = 1; i <= m;++i)
		cin>>s[i].a>>s[i].b;
	sort(s+1,s+m+1,cmp);
	int now = s[1].b;
	long long res = 1;
	for (int i = 2; i <= m; ++i) {
		if (s[i].a < now) continue;
		now = s[i].b;
		res++;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main()
{
	std::string s, p;
	std::getline( cin, s );
	std::getline( cin, p );

	 std::string::size_type i, j;

	for( i = 0; i < s.size(); ++i ){
		for( j = 0; j < p.size(); ++j){
			if( s[(i + j) % s.size()] != p[j] )
				break;

			if( j == p.size() - 1){
				cout << "Yes\n";
				return 0;
			}
		}
	}

	cout << "No\n";
		
	return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int N,h[100000],minH[100000];
	cin>>N;
	for(int i=0;i<N;i++)cin>>h[i];
	minH[0]=0;
	minH[1]=abs(h[1]-h[0]);
	for(int i=2;i<N;i++)minH[i]=min(minH[i-1]+abs(h[i]-h[i-1]),minH[i-2]+abs(h[i]-h[i-2]));
	cout<<minH[N-1];
	return 0;
}

Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2020;
int n , a[N] , vis[N];
vi g[N];

vi merge(vi a,vi b) {
  vi r(sz(a)+sz(b),0);
  for(int i=0,j=0,x=0;i<sz(a)||j<sz(b);)
    r[x++]=(j==sz(b)||(i!=sz(a)&&a[i]>b[j]))?a[i++]:b[j++];
  return r;
}

vi dfs(int c) {
  vis[c]=true;
  sort(all(g[c]),[&](int x,int y){return a[x]<a[y];});
  vi res;
  for(auto t : g[c]) if(!vis[t]) {
    res = merge(res , dfs(t));
  }
  res.insert(res.begin(),a[c]);
  return res;
}

int main(){
  cin >> n;
  rep(i,1,n+1) cin >> a[i];
  rep(i,1,n+1) g[0].pb(i);
  rep(i,1,n+1) rep(j,i+1,n+1) if(__gcd(a[i],a[j])!=1)
    g[i].pb(j),g[j].pb(i);
  vi v = dfs(0);
  rep(i,1,n+1) cout << v[i] << " \n"[i==n];
  return 0;
}


Measured memory_bytes: 19712
#include<iostream>
#include<algorithm>
using namespace std;
main(){
	int n1;
	cin>>n1;
	for(int l=0;l<n1;++l){
		int a[8],max=0,min=0,n;
		cin>>n;
		for(int i=0;i<8;++i){
			a[i]=n%10;
			n/=10;
		}
		sort(a,a+8);
		for(int i=7;i>=0;--i){
			max*=10;
			max+=a[i];
		}
		for(int i=0;i<8;++i){
			min*=10;
			min+=a[i];
		}
		cout<<max-min<<endl;
	}
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        vector<int> a(n); cin >> a;
        auto b = a;
        sort(all(b), greater<int>());
        for (int i = 0; i < n; i++) {
                if (a[i] == b[0]) cout << b[1];
                else cout << b[0];
                cout << '\n';
        }
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 4788
#include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
//-----------------------------------------------------------------------------------
 
    int N, D;

    cin >> N >> D;

    cout << ceil(N / ( 2.0 * D + 1.0)) << "\n";

}

Measured memory_bytes: 256
//AOJ::ALDS1_1_D「Maximum Profit」

#include <bits/stdc++.h>
//一括include
using namespace std;
vector<int> ivec; //int型動的配列
static const int Max = 200000;

int main()
{
    int R[Max], n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> R[i];
    }

    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    cout << maxv << endl;
    return 0;
}



Measured memory_bytes: 3892
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF INT_MAX

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

// ????????¨???????????????????¨???????????§???????
struct Edge {
    int from, to, cost;
    Edge(int s, int d) : to(s), cost(d) {}
    Edge(int f, int s, int d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};

// 1??????????????????????????????????????±????????????????????????????????? vector
// Edges????????????????????????????????????????????°??????????????????
typedef vector<Edge> Edges;

// ???????????±??????????????? vector
// Graph??????????????????????????°?????????????????§??? V ??§?????????
typedef vector<Edges> Graph;

pair<int, Edges> prim(Graph &G) {
    int V = G.size(), ans = 0;
    Edges ans_e;
    vector<bool> used(V, false);
    priority_queue< Edge, vector<Edge>, greater<Edge> > q;
    q.push(Edge(0, 0));
    while(!q.empty()) {
        Edge temp = q.top(); q.pop();
        if(used[temp.to]) continue;
        used[temp.to] = true;
        ans += temp.cost; ans_e.pb(temp);
        rep(i,0,G[temp.to].size()) q.push(G[temp.to][i]);
    }
    return pair<int, Edges>(ans, ans_e);
}

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int V, E;
    cin >> V >> E;
    Graph G(V);
    int s, t, d;
    rep(i,0,E) {
        cin >> s >> t >> d;
        G[s].push_back(Edge(t,d));
        G[t].push_back(Edge(s,d)); // ????????°??????????????§
    }

    pair<int, Edges> ans = prim(G);
    cout << ans.fr << endl;
    return 0;
}

Measured memory_bytes: 10092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;cin>>S;
  while(true){
    S.erase(S.size()-2);
    if(S.substr(0,S.size()/2)==S.substr(S.size()/2,S.size()/2)) break;
  }
  cout<<S.size()<<endl;
}

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

int main(){
    string s;
    vector<int> v(26,0);
    while(getline(cin,s)){
    for(int i=0; i<s.size(); i++){
        if((s[i]-'a')>=0 && (s[i]-'a')<=25)
            v[s[i]-'a']++;
        else if((s[i]-'A')>=0 && (s[i]-'A')<=25)
            v[s[i]-'A']++;
    }
    if(s[0]=='\n') break;
}
for(int i=0; i<26; i++){
        printf("%c : %d\n",i+'a',v[i]);
    }
    return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}


int main(){
  int N;cin>>N;
  int K;cin>>K;
  VI D(K);
  REP(i,K){
    cin>>D[i];
  }
  VI data(10);
  REP(i,10){
    data[i]=0;
  }
  REP(i,K){
    data[D[i]]=1;
  }
  int r;
  for(int i=N;i<=N*10;i++){
    int j=i;
    while(j!=0)
    {
      r=j%10;
      if(data[r]==1)break;
      j/=10;
    }
    if(j==0){
      cout<<i;
      return 0;
    }
  }

}

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

int main() {
  long a, b, k;
  cin >> a >> b >> k;
  if (a+b <= k){
    cout << 0 << " " << 0 << endl;
    return 0;
  }
  if (a > k){
    cout << a-k << " " << b << endl;
    return 0;
  }
  if (a <= k){
    cout << 0 << " " << b-k+a << endl;
    return 0;
  }
}


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

int main() {
  int N;
  cin >> N;
  bool canMake = false;
  for(int i = 1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      int temp = i*j;
      if(N == temp){
        canMake = true;
        break;
      }
    }
  }
  if(canMake) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll int
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e9;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
 
int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll h,w,n;cin>>h>>w>>n;
  vector<ll> a(n),b(n);
  for(i=0;i<n;i++){cin>>a[i]>>b[i];a[i]--;b[i]--;}
  set<pair<ll,ll>>c;
  for(i=0;i<n;i++){
    c.insert({a[i],b[i]});
  }
  map<pair<ll,ll>,ll> x;
  for(i=0;i<n;i++){
    for(j=-1;j<=1;j++){
      for(o=-1;o<=1;o++){
        if(a[i]+j<1||a[i]+j>=h-1||b[i]+o<1||b[i]+o>=w-1)continue;
        buf=0;
        for(ll p=-1;p<=1;p++){
          for(ll q=-1;q<=1;q++){
            buf+=c.find({a[i]+j+p,b[i]+o+q})!=c.end();
          }
        }
        //cout<<a[i]+j spa b[i]+o spa buf<<endl;
        x.insert({{a[i]+j,b[i]+o},buf});
      }
    }
  }
  vector<ll>m(10);
  for(auto y:x){
    m[y.second]++;
  }
  long long aa=h-2,bb=w-2;
  cout<<aa*bb-x.size()<<endl;
  for(i=1;i<=9;i++)cout<<m[i]<<endl;
 
  return 0;
}

Measured memory_bytes: 61952
#include <stdio.h>

int main(){
    int n,x;
    int l[100+2],d[100+2];
    int i,cnt = 0;

    scanf("%d %d",&n,&x);
    for(i=1;i<=n;i++){
        scanf("%d",&l[i]);
    }

    for(i=1;i<=n+1;i++){
        if(i==1){
            d[i] = 0;
            if(d[i]<=x){
                cnt++;
            }
        } else {
            d[i] = l[i-1] + d[i-1];
            if(d[i]<=x){
                cnt++;
            }
        }
    }

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

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	long long N;
	cin >> N;

	long long v0 = 1;
	long long v1 = 1;
	long long v2 = 1;
	long long b = 1000000007;

	for (long long i = 1; i <= N; i++) {
		v0 *= 10;
		v1 *= 9;
		v2 *= 8;
		v0 = v0 % b;
		v1 = v1 % b;
		v2 = v2 % b;
	}

	long long ans = v0 - 2 * v1 + v2;

	while (ans < 0) {
		ans += b;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int a,b,amax,bmin;
bool f=true;
for(int i=0;i<m;i++){
  cin>>a>>b;
  if(f){
    amax=a;
    bmin=b;
    f=false;
  }
  amax=max(amax,a);
  bmin=min(bmin,b);
}
if(amax>bmin){cout<<"0"<<endl;}
else
cout<<bmin-amax+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

std::string solve(){
    long n, m;
    scanf("%ld%ld", &n, &m);
    std::string ans(n, 'a');
    for(int i = 0; i < m; i++){
        //printf("pass\n");
        long s;
        long c;
        scanf("%ld%ld", &s, &c);
        s--;
        if(ans[s] == 'a' || ans[s] == c + '0'){
            ans[s] = c + '0';
        }else{
            return "-1";
        }
    }
    if(ans[0] == '0' && n != 1){
        return "-1";
    }
    for(int i = 0; i < n; i++){
        if(ans[i] == 'a'){
            if(i == 0 && i != n-1){
                ans[i] = '1';
            }else{
                ans[i] = '0';
            }
        }
    }
    return ans;
}

int main(){
    std::cout << solve() << std::endl;
}


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

using int64 = long long;

bool Possible(const int64 add, const int64 base, const vector<int64>& life, const int64 n) {
  int64 m = 0;
  for (int64 l : life) {
    l -= base * n;
    if (l > 0) {
      int64 k = l / add + (l % add > 0);
      m += k;
      if (m > n)
        return false;
    }
  }
  return true;
}

int main() {
  int64 n, a, b;
  cin >> n >> a >> b;
  vector<int64> h(n);
  for (int64 i = 0; i < n; ++i) {
    cin >> h[i];
  }

  int64 low = 0, up = 1000000000;
  // It's possible in (low, up].
  while (low + 1 < up) {
    int64 m = (low + up) / 2;
    if (Possible(a - b, b, h, m)) {
      up = m;
    } else {
      low = m;
    }
  }
  cout << up << "\n";

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int n;
int a[200043];
long long s[200043];

int main(int argc, char const *argv[]) {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ++s[a[i]];
  }

  long long tot = 0;
  for (int i = 1; i <= n; ++i) {
    tot += s[i] * (s[i] - 1) / 2;
  }

  for (int i = 1; i <= n; ++i) {
    cout << tot - s[a[i]] * (s[a[i]] - 1) / 2 + (s[a[i]] - 1) * (s[a[i]] - 2) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>

using namespace std;

const int Z = 1e9+7;

using vi = vector<int>;

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

    int n, m;
    cin >> n >> m;

    vi inv(m + 1), fac(m + 1), ifac(m + 1);
    for (int i = 0; i <= m; i++) {
        inv.at(i) = i <= 1 ? i : 1ll * (Z - Z / i) * inv.at(Z % i) % Z;
        fac.at(i) = i == 0 ? 1 : 1ll * fac.at(i - 1) * i % Z;
        ifac.at(i) = i == 0 ? 1 : 1ll * ifac.at(i - 1) * inv.at(i) % Z;
    }

    int ans = 0;
    for (int i = 0, p = 1; i <= n; i++, p *= -1) {
        ans = ((ans + 1ll * p * ifac.at(i) * ifac.at(n - i) % Z * fac.at(m - i)) % Z + Z) % Z;
    }

    ans = 1ll * ans * fac.at(m) % Z * fac.at(n) % Z * ifac.at(m - n) % Z * ifac.at(m - n) % Z;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8980
from math import gcd
from functools import reduce
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))

g=reduce(gcd,a)
if g!=1:
  print("not coprime")
  exit()

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret
#d=defaultdict(int)
s=set()
for q in a:
  p=primeFactor(q)
  for j in p:
    if j in s:
      print("setwise coprime")
      exit()
    s.add(j)
print("pairwise coprime")

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

int main() {
  string n;
  cin >> n;
  for (int i=0; i<3; i++) {
    if (n.at(i)=='1') {
      n.at(i)='9';
    }
    else {
      n.at(i)='1';
    }
  }
  cout << n << endl;

}


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

/*pdf見て解答
コンビネーションかと思ったけど違った
フィボナッチと同じ形式で求めれるのに気づけなかった
DPにしては簡単な部類だった*/

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

    vector<ll> oks(n+1,true);
    for(long long i = 0; i < m; i++){
        ll a; cin >> a;
        oks[a] = false;
    }

    vector<ll> dp(n+1);
    dp[0] = 1;
    for(ll now = 0; now < n; ++now){
        for(ll next = now + 1; next <= min(n, now+2); ++next){
            if(oks[next]){
                dp[next] += dp[now];
                dp[next] %= ll(1e9+7);
            }
            //cout << "now:" << now << " dp[now]:" << dp[now] << " next:" << next << " dp[next]:" << dp[next] << endl;
        }
    }

    cout << dp[n] << endl;
}

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

typedef long long ll;
typedef long double ld;

const int N = 51;
const ld EPS = 1e-9;

ll items[N];
ll pascal[N][N];

void gen() {
	pascal[0][0] = 1;
	pascal[1][0] = pascal[1][1] = 1;
	for (int i = 2; i < N; i++) {
		pascal[i][0] = pascal[i][i] = 1;
		for (int j = 1; j < i; j++) {
			pascal[i][j] = pascal[i-1][j-1]+pascal[i-1][j];
		}
	}
}

int main () {
	cout.precision(9);
	cout << fixed;
	memset(pascal, 0, sizeof pascal);
	gen();
	int n, A, B; cin >> n >> A >> B; 
	for (int i = 0; i < n; i++)
		cin >> items[i];
	sort(items, items+n);
	reverse(items, items+n);
	ld best = 0;
	for (int i = 0; i < A; i++) 
		best += (ld)items[i];
	best /= (ld)A;

	int num_of_last = 0;
	int req_num = 0;
	for (int i = 0; i < n; i++) {
		if (items[i] == items[A-1]) {
			num_of_last++;
			if (i < A) req_num++;
		}
	}

	ll ans = 0;
	if (req_num == A) {
		// everything is the same number
		for (int i = A; i <= min(B, num_of_last); i++)
			ans += pascal[num_of_last][i];
	} else {
		// only part
		ans += pascal[num_of_last][req_num];
	}

	cout << best << endl << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;

static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int total_students;
  int total_queries;
  while(~scanf("%d %d",&total_students,&total_queries)){
    vector<int> student_scores;
    vector<int> sorted_student_scores;
    for(int student_i = 0; student_i < total_students; student_i++){
      int score;
      scanf("%d",&score);
      student_scores.push_back(score);
      sorted_student_scores.push_back(score);;
    }

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

    set<int> leaders;
    for(int query_i = 0; query_i < total_queries; query_i++){
      string operation;
      int num;
      cin >> operation >> num;
      if(operation == "ADD"){
        leaders.insert(num - 1);
      }
      else if(operation == "REMOVE"){
        leaders.erase(lower_bound(leaders.begin(),leaders.end(),num - 1));
      }
      else if(operation == "CHECK"){
        vector<int> leader_scores;

        for(set<int>::iterator leader_it = leaders.begin(); leader_it != leaders.end(); leader_it++){
          leader_scores.push_back(student_scores[*leader_it]);

        }
        sort(leader_scores.begin(),leader_scores.end());
        
        int rhs = INF;
        int lhs = 0;

        for(int round = 0; round < 50; round++){
          int mid = lhs + (rhs - lhs) / 2;
          int prev = 0;
          int fail_sum = 0;
          for(int leader_i = 0; leader_i < leader_scores.size(); leader_i++){
            int score = leader_scores[leader_i];
            int current= lower_bound(sorted_student_scores.begin(),
                                 sorted_student_scores.end(),
                                 score - mid)
              - sorted_student_scores.begin();
            int fail = max(0,current - prev);
            fail_sum += fail;
            prev = upper_bound(sorted_student_scores.begin(),
                               sorted_student_scores.end(),score)
              - sorted_student_scores.begin();
          }
          fail_sum += max(total_students - prev,0);

          if(fail_sum > num){
            lhs = mid;
          }
          else{
            rhs = mid;
          }
        }

        if(rhs < INF){
          printf("%d\n",rhs);
        }
        else{
          printf("NA\n");
        }
      }
    }
  }
}

Measured memory_bytes: 9756
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<limits>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define INF 1e18
using ll = long long;
using namespace std;

int main(){
  int a,b;  cin >> a >> b;
  if(10 <= a or 10 <= b){
    cout << -1;
  }else{
    cout << a*b;
  }
}


Measured memory_bytes: 256
#include<iostream>
 using namespace std;
 
 bool check(int n){
     if(n<2) return false;
     if(n==2) return true;
     if(n%2==0) return false;
     
     int i;
     for(i=3; i*i<=n; i+=2){
         if(n%i==0){
             return false;
         }
     }
     return true;
    }

int n[10000];

 int main(){
     int sw=0;
     int a;
     cin >> a;
 
     for(int i=0; i<a; i++){
         cin >> n[i];
     }
 
     for(int i=0; i<a; i++){
         if(check(n[i]))
             sw++;
     }
     cout << sw << endl;
 
     return 0;
    }

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
  cin>>n;
	vector<int> a(n,0);
  for(int i=0;i<n;i++)
    cin>>a[i];
  int max_yet = a[0];
  int count=1;
  for(int i=1;i<n;i++)
  {
    	max_yet=min(max_yet,a[i]);
    	if(max_yet>=a[i])
          count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef unsigned long long ll;
using namespace std;
int main()
{
    int n ;
    cin >> n ;
    string s , x;
    cin >> s >> x;
    n*=2;
    int max = 0 ;
    for(int i = 0 ; i < s.size() ; i++)
    {
        bool good = 1;
        for(int j = i , k = 0 ; j < s.size() ; j++ , k++)
        {
            if(s[j] != x[k]) good = 0;
        }
        if(good)
        {
            n-= (s.size()-i);
            break;
        }
    }
    cout << n << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <math.h> 

using namespace std;


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

	int n, m, i, j, k, a, b;
	cin >> n >> m;

	if (m % 2 == 1) {
		cout << "-1\n";
		return 0;
	}

	vector<vector<pair<int, int>>> adj(n + 1);
	vector<pair<int, int>> edge(m);
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		adj[a].push_back({ b, i });
		adj[b].push_back({ a, i });
		edge[i] = { a, b };
	}

	// construct MST from node 1
	vector<int> parent(n + 1, -1), depth(n + 1);
	parent[1] = 0;
	depth[1] = 0;
	queue<int> q;
	q.push(1);

	while (!q.empty()) {
		int id = q.front();
		q.pop();

		for (auto p : adj[id]) {
			if (parent[p.first] == -1) {
				parent[p.first] = id;
				depth[p.first] = depth[id] + 1;
				q.push(p.first);
			}
		}
	}

	// randomly assign all edges not on the MST
	vector<int> ct(n + 1, 0);		// count of outgoing edges

	vector<pair<int, int>> ans;
	for (i = 0; i < m; i++) {
		if ((parent[edge[i].first] != edge[i].second) && (parent[edge[i].second] != edge[i].first)) {
			ct[edge[i].first]++;
			ans.push_back(edge[i]);
		}
	}

	// sort nodes by depth
	vector<pair<int, int>> plist;
	for (i = 1; i <= n; i++) plist.push_back({ depth[i], i });
	sort(plist.rbegin(), plist.rend());
	
	// arrange direction of each node
	for (i = 0; i < n - 1; i++) {
		int id = plist[i].second;
		if (ct[id] % 2 == 0) {
			ans.push_back({ parent[id], id });
			ct[parent[id]]++;
		}
		else ans.push_back({ id, parent[id] });		
	}

	for (auto p : ans) cout << p.first << " " << p.second << "\n";

	return 0;
}



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

int const MAX = 100005;
vector<int> g[MAX];
int color[MAX];
int main() {
	long long n, m;
	cin >> n >> m;
	for (int i = 0; i<m; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for (int i = 1; i <= n; i++) {
		color[i] = 0;
	}
	queue<int> q;
	q.push(1);
	color[1] = 1;
	bool flag = 1;//二部グラフかどうか
	while (!q.empty()) {
		int now = q.front();
		q.pop();
		for (int i = 0; i<g[now].size(); i++) {
			int next = g[now][i];
			if (color[next] == 0) {
				color[next] = -color[now];
				q.push(next);
			}
			else if (color[next] == color[now]) {
				flag = 0;
				break;
			}
		}
	}
	if (flag) {
		long long blue;
		long long red;
		blue = red = 0;
		for (int i = 1; i <= n; i++) {
			if (color[i] == 1) {
				blue++;
			}
			else { red++; }
		}
		cout << blue * red - m << endl;
	}
	else {
		cout << n * (n - 1) / 2 - m << endl;
	}
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

const int N = 3005;
int r, c, k;
ll arr[N][N];
ll dp[N][N][4];

ll f(int row, int col, int t){
    if(row > r || col > c) return -10;
    if(row == r && col == c){
        if(t == 3) return 0*1LL;
        return arr[row][col];
    }
    ll &ret = dp[row][col][t];
    if(ret != -1) return ret;
    ret = 0;
    ret = max(f(row+1, col, 0), f(row, col+1, t));
    if(arr[row][col] && t < 3) ret = max(ret, max(f(row, col+1,t+1), f(row+1,col,0)) + arr[row][col]);
    return ret;
}

int main()
{
    int i = 0, j = 0, cs = 0, in;
    mem(dp,-1);
    cin>>r>>c>>k;
    for(i = 0; i < k; i++){
        ll a, b, v; cin>>a>>b>>v;
        arr[a][b] = v;
    }
    cout << f(1, 1, 0) << endl;
    return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	vector<pii> ab(n);
	rep(i, n) cin >>ab[i].second >>ab[i].first;
	//sort(all(ab), [](auto l, auto r){
//		return l.first != r.first? l.first > r.first: l.first < r.first;
	//});
	
	map<int, VI> mp;
	rep(i, n) mp[ab[i].second].push_back(ab[i].first);
	for(auto& z: mp) sort(z.second.rbegin(), z.second.rend());
	
	//for(auto x :ab) printf("%d:%d, ",x.first, x.second); puts("");
	
	VI zan;
	priority_queue<int> pq;
	ll ans =0;
	
	repr(j, m, 0){
		int tm = m - j;
		for(auto k: mp[tm]) pq.push(k);
		if(sz(pq)){
			ans += pq.top(); pq.pop();
		}
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 11648
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;
long long int D,G;
vector<long long int> p,c,a;
long long int ans=100000000;
    
int main(){
    cin >> D >> G;
    p.push_back(0);
    c.push_back(0);
    a.push_back(0);
    for(int i=0;i<D;i++){
       long long  int x,y;
        cin >> x >> y;
        p.push_back(x);
        c.push_back(y);
    }
    for(int i=1;i<=D;i++){
        a.push_back(100*i*p[i]+c[i]);
    }
    
    for(int i=0;i<1023;i++){
        for(int j=0;j<D;j++){
            if((i>>j)%2 == 1)continue;
            
            //a[j+1]
            
            long long int sum=0;
            long long int sum2=0;
            for(int k=0;k<D;k++){
                if((i>>k)%2==1){
                    sum+=a[k+1];
                    sum2+=p[k+1];
                    
                }
            }
            
            if(sum>=G)continue;
            if(sum+a[j+1]<G)continue;
            
            if(sum+(j+1)*100*(p[j+1]-1)<G){
           
                ans = min(ans,sum2+p[j+1]);
            }else{
                ans = min(ans,sum2+(G-sum-1)/((j+1)*100)+1);
            }
        }
    }
    cout << ans;
    return 0;
}


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int const MAX = 1e6 + 41;
int const MOD = 1e9 + 7;

int f[MAX];
int invf[MAX];

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	if (a < 0) a += MOD;
	return a;
}

int mult(int a, int b) {
	return (ll) a * b % MOD;
}

int getc(int n, int k) {
	if (k > n) return 0;
	return mult(f[n], mult(invf[n - k], invf[k]));
}

int bp(int x, int d) {
	int res = 1;
	while (d) {
		if (d & 1) res = mult(res, x);
		x = mult(x, x);
		d >>= 1;
	}
	return res;
}

void init() {
	f[0] = 1;
	fi(1, MAX - 1) {
		f[i] = mult(f[i - 1], i);
	}
	fi(0, MAX - 1) {
		invf[i] = bp(f[i], MOD - 2);
	}
}

int n, ans, all;

void solve() {
	if (n == 2) {
		printf("1\n");
		return;
	}
	fi(1, n - 1) {
		int w = getc(i - 1, n - 1 - i);
		if (!w) continue;
		w = mult(w, f[i]);
		w = mult(w, f[n - 1 - i]);
		w = add(w, -all);
		ans = add(ans, mult(i, w));
		all = add(all, w);				
	}
	printf("%d\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	init();  
	scanf("%d", &n);
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define int long long
using namespace std;

int n,h[150005],dp[150005],k;


signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i =1;i<=n;i++) cin >> h[i];
    dp[1]=0;
    for(int i=2;i<=n;i++) dp[i]=1e18;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
        dp[i+j]=min(dp[i]+abs(h[i]-h[i+j]),dp[i+j]);}
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792