akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

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



void dfs(int h, int m, int g, int k);

int H, W, c[10][10], A[200][200], ans[10] = { 1111, 1111, 1111, 1111,1111,1111,1111,1111,1111,1111 };

int main()
{
	int i, j, sum = 0;

	cin >> H >> W;
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			cin >> c[i][j];
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}

	for (i = 0; i < 10; i++) {
		dfs(i, 0, c[i][1], i);
	}

	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (A[i][j] != -1 && A[i][j] != 1) {
				sum += ans[A[i][j]];
			}
		}
	}

	cout << sum << endl;
}


void dfs(int h, int m, int g, int k) {
	int i;

	for (i = 0; i < 10; i++) {
		if (m + c[h][i] < g && i != h && i != 1) {
			dfs(i, m + c[h][i], g, k);
		}
	}

	ans[k] = min(ans[k], m + c[h][1]);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int n,m;
int d[100][100],d2[100][100];
vector<int> a,b,c;
int warshall(){
  int cnt=0;
  rep(k,0,n)rep(i,0,n)rep(j,0,n){
    chmin(d[i][j], d[i][k]+d[k][j]);
  }
  rep(i,0,m){
    if(d[a[i]][b[i]]<c[i]) cnt++;
  }
  return cnt;
}
int main(){
  cin >> n >> m;
  a.resize(m);  b.resize(m);  c.resize(m);
  rep(i,0,n)rep(j,0,n){
    d[i][j]=inf;
    d2[i][j]=inf;
    if(i==j) d[i][j]=d2[i][j]=0;
  }
  rep(i,0,m){
    int x,y,z;  cin >> x>>y>>z;
    --x;  --y;
    d[x][y] = d[y][x] = z;
    d2[x][y] = d2[y][x] = z;
    a[i]=x; b[i]=y; c[i]=z;
  }
  cout << warshall() << endl;
  return 0;
}


Measured memory_bytes: 384
unittest
{
	assert( [ "7 5 1" ].parse.expand.solve == "YES" );
	assert( [ "2 2 1" ].parse.expand.solve == "NO" );
	assert( [ "1 100 97" ].parse.expand.solve == "YES" );
	assert( [ "40 98 58" ].parse.expand.solve == "YES" );
	assert( [ "77 42 36" ].parse.expand.solve == "NO" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	auto rs = [ a % b ];
	while( true )
	{
		auto r = ( rs[ $ - 1 ] + a ) % b;
		if( r == c ) return "YES";
		if( 0 < rs.count( r ) ) return "NO";
		rs ~= r;
	}
	assert( false );
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
 #include <bits/stdc++.h>
 
 using namespace std;
 
 //----------------------- Print Function ----------------------//
 
 inline void print() {
     cout << endl;
 }
 template <typename First, typename... Rest>
 void print(const First &first, const Rest &... rest) {
     cout << first << ' ';
     print(rest...);
 }
 
 template <typename T>
 void print(const vector<T> &v) {
     for (auto e : v) cout << e << ' ';
     cout << endl;
 }
 
 //------------------------- Libraries -------------------------//
 
 //--------------------------- Solve ---------------------------//
 
 void solve() {
    int N; cin >> N;
    int F[N][10], P[N][11];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> F[i][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> P[i][j];
        }
    }

    int ans;
    for (int bit = 1; bit < 1<<10; bit++) {
        vector<int> cnt(N);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < 10; j++) {
                if ((bit & 1<<j) && F[i][j]) cnt[i]++;
            }
        }

        int tmp = 0;
        for (int i = 0; i < N; i++) {
            tmp += P[i][cnt[i]];
        }
        if (bit == 1) ans = tmp;
        else ans = max(ans, tmp);
    }

    cout << ans << '\n';
 }
 
 int main() {
     cin.tie(nullptr);
     ios_base::sync_with_stdio(false);
 
     solve();
 
     return 0;
 }

Measured memory_bytes: 3656
#include <stdio.h>

int selectionSort(int arr[], int n) {
    int i, j, tmp, count = 0, min;
    for (i = 0; i < n - 1; i++) {
        min = i;
        for (j = i; j < n; j++) {
            if (arr[j] < arr[min]) {
                min = j;
            }
        }
        tmp = arr[i];
        arr[i] = arr[min];
        arr[min] = tmp;
        if (i != min) {
            count++;
        }
    }
    return count;
}

int main() {
    int arr[100], n, i, count;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    count = selectionSort(arr, n);
    for (i = 0; i < n; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", arr[i]);
    }
    printf("\n");
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 2752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q,a,b;
    cin >> q;
    if(q==1){
        cout << "Hello World" << endl;
        return 0;
    }
    else if(q==2){
        cin >> a >> b;
        cout << a+b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import collections
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
n = int(input())
c = collections.Counter(prime_factorize(n))
#print(c)
# Counter({2: 3, 3: 1, 5: 1, 7: 1})
ans = 0
for x in c.values():
    for i in range(1,100):
        
        if(x-i >= 0):
            ans += 1
            x -= i
print(ans)
    

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

int main(){

    int a, b, k;
    cin >> a >> b >> k;

    vector<int> out;

    for(int i = a;i < a+k; ++i){
        out.push_back(i);
        if(i == b)break;
    }
    for(int i = b;i > b-k; --i){
        out.push_back(i);
        if(i == a)break;
    }
    sort(out.begin(), out.end());

    for(int i = 0;i < out.size(); ++i){

        if(out[i] != out[i+1]){
            cout << out[i] << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {

	//A
	int h, w, a, b;
	cin >> h;
	cin >> w;
	cin >> a;
	cin >> b;

	int i, j, k;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if ((i < b) && (j < a)) {
				cout << 1;
			}
			else if ((i >= b) && (j >= a)) {
				cout << 1;
			}
			else {
				cout << 0;
			}
		}
		cout << '\n';
	}

	return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

const int MAX_N = 1e5 + 1;

int main()
{
    ios::sync_with_stdio(false);

    ll N, K;
    cin >> N >> K;

    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    ll ans = 0;
    rep(i, N) {
        if (!(~K & A[i])) ans += B[i];
    }

    for (int b=30; b>=0; b--) {
        ll tmp = 0;
        rep(i, N) {
            if (!(K>>b&1) || A[i]>>b&1) continue;
            bool ok = true;
            for (int j=30; j>b; j--) {
                if (A[i]>>j & ~K>>j) {
                    ok = false;
                    break;
                }
            }
            if (ok) tmp += B[i];
        }
        ans = max(ans, tmp);
#ifdef DEBUG
        DUMP(b);
        DUMP(tmp);
#endif
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
def q4():
    _ = input()
    A = [int(i) for i in input().split(" ")]
    Q = int(input())
    bc_list = []
    for i in range(Q):
        bc_list.append([int(i) for i in input().split(" ")])

    da = {}
    sa = 0
    for a in A:
        sa += a
        if a in da:
            da[a] += 1
        else:
            da[a] = 1

    last_sum = sa
    sum_a = []

    for bc in bc_list:
        b = bc[0]
        c = bc[1]
        if b not in da:
            sum_a.append(last_sum)
            continue

        diff = c - b
        count = da[b]
        last_sum = last_sum + diff * count
        sum_a.append(last_sum)

        if c not in da:
            da[c] = da[b]
        else:
            da[c] += da[b]
        del da[b]

    for s in sum_a:
        print(s)


q4()


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

bool field[22][22];

struct point {
    int x, y;
};

int main() {
    int N;
    while (cin >> N, N != 0) {
        memset(field, 0, sizeof(field));
        int x, y;
        for (int i = 0; i < N; i++) {
            cin >> x >> y;
            field[y][x] = true;
        }
        int M; cin >> M;
        point cur; cur.x = 10; cur.y = 10;
        int count = 0;
        if (field[cur.y][cur.x]) {
            count++;
            field[cur.y][cur.x] = false;
        }
        for (int i = 0; i < M; i++) {
            char dir;
            int distance;
            cin >> dir >> distance;
            for (int j = 0; j < distance; j++) {
                switch (dir) {
                    case 'N':
                        cur.y++;
                        break;
                    case 'W':
                        cur.x--;
                        break;
                    case 'S':
                        cur.y--;
                        break;
                    case 'E':
                        cur.x++;
                        break;
                }
//                cout << cur.x << ' ' << cur.y << endl;
                if (field[cur.y][cur.x]) {
                    field[cur.y][cur.x] = false;
                    count++;
                }
            }
        }
        bool flag = true;
        for (int i = 0; i <= 20; i++) {
            for (int j = 0; j <= 20; j++) {
//                cout << field[i][j] << ' ';
                if (field[i][j]) {
                    flag = false;
                    break;
                }
            }
//            cout << endl;
        }
        if (flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

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

int main()
{
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;

    vector<int> x(5);
    x[0] = A, x[1] = B, x[2] = C, x[3] = D, x[4] = E;

    vector<int> y(5);
    for(int i = 0; i < 5; i++)
    {
        for(int j = 1; j < 14; j++)
        {
            if(j * 10 >= x[i])
            {
                y[i] = j * 10;
                break;
            }
        }
    }

    vector<pair<int, int>> z(5);
    for(int i = 0; i < 5; i++)
    {
        z[i] = make_pair(y[i] - x[i], i);
    }

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

    int ans = 0;
    for(int i = 0; i < 4; i++)
    {
        ans += y[z[i].second];
    }

    ans += x[z[4].second];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int S[100000],T[50000];
  int i,n,q,count=0;
  int mid=0,right=0,left=0;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&T[i]);
  }
  for(i = 0 ; i < q ; i++){
    
    right = n;
    left = 0;
    
    while(right > left){
      
      mid = (right+left)/2;
      
      
      if(S[mid] == T[i]){
	count++;
	break;
      }
      else if(S[mid] < T[i]){
	left = mid+1;
      }
      else {
	right = mid;
      }
    }
  } 
  printf("%d\n",count);
  return 0;
}

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

using namespace std;

int main() {
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 != m2)
    cout << 1 << endl;
  else
    cout << 0 << endl;

  return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,m,hh,mm,k; cin>>h>>m>>hh>>mm>>k;
  ll span=(hh-h)*60+mm-m;
  ll ans=span-k;
  cout<<ans<<endl;
}

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

int main()
{
  ll n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> V(n);
  for (int i = 0; i < n; i++)
  {
    cin >> V.at(i).first >> V.at(i).second;
  }

  sort(V.begin(), V.end());
  ll sum = 0;
  for (int i = 0; i < n; i++)
  {
    sum += V.at(i).second;
    if (sum >= k)
    {
      cout << V.at(i).first << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 4824
/**
 *    author:  Sanchit Sinha
 *    created: 26.09.2020 21:40:24       
**/
#include "bits/stdc++.h"
using namespace std; 

#define ll long long 
ll powermod(ll x,ll ex,ll md){ll ans=1ll;while(ex>0){if(ex&1ll) ans=(ans*x)%md; ex>>=1ll;x=(x*x)%md;}return ans;}
inline ll gcd(ll a,ll b) {if(b==0)return a;a%=b;return gcd(b,a);}
inline ll max(ll a,ll b) {return((a>b)?a:b);}
inline ll min(ll a,ll b) {return((a>b)?b:a);}

int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        ll n;
        cin>>n;
        for(ll i=0;i<n;i++) cout<<"ACL";
        return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h> // {{{
// clang-format off
#pragma GCC optimize "O3,omit-frame-pointer,inline"
#pragma GCC target "tune=native"
#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define USE1(T) template<typename T>inline
#define USE2(T, U) template<typename T,typename U>inline
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

template<typename T>using duo=std::pair<T,T>;
template<typename T>using vec=std::vector<T>;
using ll=long long;
using pii=duo<int>;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE1(T=int)vec<T>in(int n){vec<T>v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE1(T=int)vec<T>in(int n,T a){vec<T>v;v.reserve(n);rep(i,n)v.pb(in<T>()+a);return v;}
USE1(T)vec<std::pair<T,int>>enume(const vec<T>&x,int s=0){int N=x.size();vec<std::pair<T,int>>v;v.reserve(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup; //}}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() { //
  int N = in();
  auto s = in<string>();
  auto t = in<string>();

  rep(i, N) {
    if (s.substr(i) == t.substr(0, N - i)) {
      pr(N + i);
      return 0;
    }
  }
  pr(2 * N);

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {
	int p, q, r;
	scanf("%d%d%d",&p,&q,&r);
	if (p < q) {
		if (q < r) {
			printf("%d\n", p + q);
		}
		else {
			printf("%d\n", p + r);
		}
	}
	else {
		if (p < r) {
			printf("%d\n", p + q);
		}
		else {
			printf("%d\n", q + r);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>


#define MAX 10000


using namespace std;
typedef pair<int, int> pi;

vector< pi > hdrs[MAX];
priority_queue< pi, vector<pi>, greater<pi> > distances;
bool is_tree[MAX];
int d[MAX];
int n;

void dijkstra()
{
    for (int i = 0; i < n; i++) {
        is_tree[i] = false;
        d[i] = INT_MAX;
    }

    distances.push(make_pair(0, 0));
    d[0] = 0;
    while (!distances.empty()) {
        // min_distance, vertex_id
        pi now = distances.top();
        distances.pop();

        if (d[now.second] < now.first)
            continue;
        is_tree[now.second] = true;

        for (vector<pi>::iterator it = hdrs[now.second].begin(); it != hdrs[now.second].end(); it++) {
            // *(it).second is same as it->second
            if (!is_tree[(*it).second] && now.first + (*it).first < d[(*it).second]) {
                d[(*it).second] = now.first + (*it).first;
                distances.push(make_pair(d[(*it).second], (*it).second));
            }
        }
    }
}


int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            // cost, vertex_id
            hdrs[u].push_back(make_pair(c, v));
        }
    }

    dijkstra();

    for (int i = 0; i < n - 1; i++) {
        cout << i << " " << d[i] << endl;
    }
    cout << n - 1<< " " << d[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 7936
#include<stdio.h>

int main(void){
    int a,b,k,i,cnt;
    cnt = 0;

    scanf("%d %d %d",&a,&b,&k);

    for(i=100; i>=1; i--){
       if ( (a % i == 0) && (b % i == 0) )
       cnt++;
       if(cnt == k)
       break;
    }

    printf("%d\n",i);

    return 0;
}

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

int n, m;

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

	vector <pair <int, int> > a(m, {0, 0});
	for(int i = 0; i < m; i++) {
		scanf("%d%d", &a[i].first, &a[i].second);
		a[i].first--;
	}

	for(int i = 0; i < 1000; i++) {
		int l = 0;

		vector <int> v;
		for(int j = i; j > 0; j /= 10) {
			l++;
			v.push_back(j % 10);
		}

		if(i == 0) {
			l++;
			v.push_back(0);
		}

		if(l != n)
			continue;

		reverse(v.begin(), v.end());

		int bad = 0;
		for(int k = 0; k < m; k++) {
			if(a[k].first >= (int) v.size()) {
				bad = 1;
				break;
			}
			
			if(v[a[k].first] != a[k].second) {
				bad = 1;
				break;
			}
		}

		if(!bad) {
			printf("%d\n", i);
			return 0;
		}
	}

	printf("-1\n");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

string s;
map<char, int> m;

int main()
{
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		m[s[i]]++;

	for (int i = 0; i < s.size(); i++) {
		if (m[s[i]] >= 2) {
			m[s[i]]--;
			int a = 1;
			int str_size = 1;
			for (int j = i+1; j < s.size(); j++) {
				str_size++;
				if (s[i] == s[j]) {
					m[s[j]]--;
					a++;
				}
				if (str_size-a > a)break;
				else if (a > str_size-a) {
					cout << i+1 << " " << j+1 << endl;
					return 0;
				}
			}
		}
	}
	cout << "-1 -1" << endl;
 	return 0;
}

Measured memory_bytes: 512
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int n;
  readf (" %d", &n);
  auto x = new int[n];
  auto y = new int[n];
  foreach (t; 0 .. n) {
    readf (" %d %d", &x[t], &y[t]);
  }
  int res = n;
  void test (int dx, int dy) {
    int r;
    foreach (i; 0 .. n) {
      bool find = false;
      foreach (j; 0 .. n) {
        if (x[j] == x[i] - dx && y[j] == y[i] - dy) {
          find = true;
          break;
        }
      }
      if (!find) ++r;
    }
    res = min (res, r);
  }
  foreach (j; 0 .. n) {
    foreach (i; 0 .. n) if (i != j) {
      test (x[j] - x[i], y[j] - y[i]);
    }
  }
  writeln (res);
}


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

#define MAXN (200010)

int n, k, l;
std::vector<int> mat1[MAXN];
std::vector<int> mat2[MAXN];
bool vis1[MAXN], vis2[MAXN];
int cnt1, cnt2;
int bel1[MAXN], bel2[MAXN];
std::map<std::pair<int, int>, int> map;

void dfs1(int u){
	vis1[u] = true;
	bel1[u] = cnt1;
	for(auto v : mat1[u]){
		if(vis1[v]) continue;
		dfs1(v);
	}
}

void dfs2(int u){
	vis2[u] = true;
	bel2[u] = cnt2;
	for(auto v : mat2[u]){
		if(vis2[v]) continue;
		dfs2(v);
	}
}

int main(){
	scanf("%d%d%d", &n, &k, &l);
	for(int i = 1; i <= k; ++ i){
		int u, v;
		scanf("%d%d", &u, &v);
		mat1[u].push_back(v);
		mat1[v].push_back(u);
	}
	for(int i = 1; i <= l; ++ i){
		int u, v;
		scanf("%d%d", &u, &v);
		mat2[u].push_back(v);
		mat2[v].push_back(u);
	}
	for(int i = 1; i <= n; ++ i){
		if(!vis1[i]){
			++ cnt1;
			dfs1(i);
		}
		if(!vis2[i]){
			++ cnt2;
			dfs2(i);
		}
	}
	for(int i = 1; i <= n; ++ i){
		++ map[{bel1[i], bel2[i]}];
	}
	for(int i = 1; i <= n; ++ i){
		printf("%d", map[{bel1[i], bel2[i]}]);
		printf(i == n ? "\n" : " ");
	}
	return 0;
}

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

using namespace std; 
  int main()
  {
   int n;
   cin>>n;
   long long int a[n];
   unsigned long long int dp2[n+1]={0};
   int i,j,k;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
       dp2[i+1]=dp2[i]+a[i];
   }
  unsigned long long int dp[n][n],m;
   for(i=0;i<n;i++)
   {
       dp[i][i]=0;
   }
   for(i=1;i<n;i++)
   {
       for(j=0;j<n-1;j++)
       {
           if(j+i<n)
           {
               m=1e18;
           for(k=i+j-1;k>=j;k--)
           {
               m=min(dp[j][k]+dp[k+1][i+j]+dp2[i+j+1]-dp2[j],m);
           }
           dp[j][j+i]=m;
           dp[j+i][j]=m;
           
           }
       }
   }
  cout<<dp[0][n-1]<<endl;
  /*for(i=0;i<n;i++)
  {
      for(j=0;j<n;j++)
      {
          cout<<dp[i][j]<<" ";
      }
      cout<<endl;
  }*/
  
      return 0;
  }

Measured memory_bytes: 1536
n,x = map(int,input().split())
cnt = 0
while n > 0 and x > 0:
    if x >= 2**(n+1)-1:
        cnt += 2**n
        x -= (2**(n+1)-1)
    else:
        x -= 1
    n -= 1
if x >= 1:
    cnt += 1
print(cnt)

Measured memory_bytes: 38384
/*************************************************************************
    > File Name: A.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-06-03 19:59:40
 ************************************************************************/

#include<bits/stdc++.h>
#pragma GCC optimize(3)
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int sum(int x)
{
    int s=0;
    while(x)
    {
        s+=x%10;
        x/=10;
    }
    return s;
}
int main()
{
    int n;
    scanf("%d",&n);
    int ans=INF;
    for(int i=1;i<=n/2;i++)
        ans=min(ans,sum(i)+sum(n-i));
    printf("%d\n",ans);
    return 0;
}



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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int N, M; cin >> N >> M;
	atcoder::dsu uf(N);
	REP(i, M){
		int a, b; cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}
	cout << uf.groups().size() - 1 << ln;
}

Measured memory_bytes: 8864
const main = input => {
  const [a, b] = input.trim().split(" ").map(e => Number.parseInt(e))
  return a * b % 2 == 0 ? "Even" : "Odd"
}; // Implement this function

console.log(main(require('fs').readFileSync('/dev/stdin', 'utf8'))); // Common part

Measured memory_bytes: 29504
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n;cin>>n;
	ll x,l;
	vector<P> a(n);
	for(int i = 0; i < n; i++) {
		cin >>x>>l;
		a[i] = mp(x + l,x - l);
	}
	sort(ALL(a));
	l = a[0].fs;
	ll ans = 0;
	for(int i = 1; i < n; i++) {
		if (a[i].sc >= l){
			l = a[i].fs;
		}
		else{
			ans++;
		}
	}

	cout << n - ans << endl;



	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100005;

int n,m,cnt,last[N],dep[N],len,sx,sy,a[N],odd,even,s[N],k[N];
bool vis[N];
struct edge{int to,next;}e[N*2];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;
}

void dfs1(int x,int fa)
{
	vis[x]=1;
	if (dep[x]&1) even++;
	else odd++;
	for (int i=last[x];i;i=e[i].next)
	{
		if (e[i].to==fa) continue;
		if (vis[e[i].to]&&dep[e[i].to]<dep[x]) len=dep[x]-dep[e[i].to]+1,sx=x,sy=e[i].to;
		else if (!vis[e[i].to]) dep[e[i].to]=dep[x]+1,dfs1(e[i].to,x);
	}
}

void dfs2(int x)
{
	vis[x]=1;
	for (int i=last[x];i;i=e[i].next)
		if (!vis[e[i].to]) dfs2(e[i].to),s[x]+=s[e[i].to],k[x]+=k[e[i].to];
}

int main()
{
	n=read();m=read();
	for (int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		addedge(x,y);
	}
	dfs1(1,0);
	if (odd!=even&&!(len&1)||(abs(odd-even)&1)&&(len&1)) {puts("-1");return 0;}
	for (int i=1;i<=n;i++) s[i]=(dep[i]&1)?1:-1;
	int ans=0;
	if (len&1) s[sx]+=(odd-even)/2,s[sy]+=(odd-even)/2,ans+=abs(odd-even)/2;
	else k[sx]=1,k[sy]=-1;
	memset(vis,0,sizeof(vis));
	dfs2(1);
	int tot=1;
	for (int i=1;i<=n;i++)
		if (!k[i]) ans+=abs(s[i]);
		else if (k[i]==1) a[++tot]=-s[i];
		else a[++tot]=s[i];
	sort(a+1,a+tot+1);
	int mid=a[(tot+1)/2];
	ans+=abs(mid);
	for (int i=1;i<=n;i++) if (k[i]) ans+=abs(k[i]*mid+s[i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 8576
loop do
  n = gets.to_i
  break if n == 0
  arr = n.times.map { gets.to_i }

  i = n - 2
  count = 0
  loop do
    0.upto(i) do |i|
      if arr[i] > arr[i+1]
        arr[i], arr[i+1] = arr[i+1], arr[i]
        count += 1
      end
    end
    i -= 1
    break if i < 0
  end
  puts count
end

Measured memory_bytes: 6100
#include <stdio.h>
#include <stdlib.h>

int main(void){
    long long x,ans=1e9;
    scanf("%lld",&x);
    while(x>=100){
        ans=ans<llabs(753-x%1000)?ans:llabs(753-x%1000);
        x/=10;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
ab.sort(key = lambda x : x[1])

ans = 0
last = -1
for a, b in ab:
    if a < last:
        continue
    else:
        ans += 1
        last = b

print(ans)

Measured memory_bytes: 29084
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    auto bs = new int[][](K+2, K+2);
    auto ws = new int[][](K+2, K+2);
    foreach (_; 0..N) {
        auto xyc = readln.split;
        auto x = xyc[0].to!int;
        auto y = xyc[1].to!int;
        auto c = xyc[2];
        if ((c == "B" && (x/K + y/K)%2 == 0) || (c == "W" && (x/K + y/K)%2 == 1)) {
            bs[y%K+1][x%K+1] += 1;
        } else {
            ws[y%K+1][x%K+1] += 1;
        }
    }

    foreach (i; 1..K+1) foreach (j; 1..K+1) {
        bs[i][j] += bs[i-1][j];
        ws[i][j] += ws[i-1][j];
        bs[i][j] += bs[i][j-1];
        ws[i][j] += ws[i][j-1];
        bs[i][j] -= bs[i-1][j-1];
        ws[i][j] -= ws[i-1][j-1];
    }

    long r;
    foreach (i; 1..K+1) foreach (j; 1..K+1) {
        r = max(r, bs[K][K] - bs[i][K] - bs[K][j] + bs[i][j]*2 + ws[K][j] + ws[i][K] - ws[i][j]*2);
        r = max(r, ws[K][K] - ws[i][K] - ws[K][j] + ws[i][j]*2 + bs[K][j] + bs[i][K] - bs[i][j]*2);
    }
    writeln(r);
}

Measured memory_bytes: 11776
s = input()
for i, c in enumerate(s):
    if i % 2 == 0 and (c != 'R' and c != 'U' and c != 'D'):
        print('No')
        break
    elif i % 2 == 1 and (c != 'L' and c != 'U' and c != 'D'):
        print('No')
        break
else:
    print('Yes')


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
//#define int long long

signed main(){
    int n, h;
    cin >> n >> h;
    
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];
    
    sort(rALL(a));
    int attack = a[0];
    
    int thrown = 0; sort(rALL(b));
    for(int katana: b){
        if(katana < attack || h <= 0) break;
        h -= katana;
        thrown++;
    }
    
    cout << thrown + ceiv(max(0,h), attack) << endl;
}

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

const int MX = 100005;
vector<P> g[MX];
int x[MX];
bool used[MX];
vector<int> ans;


int dfs(int v)
{
    used[v] = true;
    int res = x[v];
    for (P e:g[v]) {
        if (used[e.first]) {
            continue;
        }
        int r = dfs(e.first);
        if (r) {
            ans.push_back(e.second);
        }
        res = res ^ r;
    }
    return res;
}


int main(){
    int N, M;
    cin >> N >> M;
    vector<P> a(N);
    for (int i=0; i<N; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());
    
    x[0] = a[0].second;
    for (int i=1; i<N; i++) {
        x[i] = a[i-1].second ^ a[i].second;
    }
    x[N] = a[N-1].second;
    
    
    for (int i=0; i<M; i++) {
        int l, r;
        cin >> l >> r;
        int lj = lower_bound(a.begin(), a.end(), P(l, 0)) - a.begin();
        int rj = upper_bound(a.begin(), a.end(), P(r, 1)) - a.begin();
        g[lj].emplace_back(rj, i+1);
        g[rj].emplace_back(lj, i+1);
    }
    
    
    for (int i=0; i<N+1; i++) {
        used[i] = false;
    }
    
    for (int i=0; i<N+1; i++) {
        if (used[i]) {
            continue;
        }
        int v = dfs(i);
        if (v>0) {
            cout << "-1" << endl;
            return 0;
        }
    }
    
    int ans_size = ans.size();
    sort(ans.begin(), ans.end());
    cout << ans_size << endl;
    rep(i, ans_size) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 15228
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
//#define bint int1024_t
#define ld long double
#define vect vector<ll>
#define unmap unordered_map
#define pb push_back
#define pi 3.1415926536
#define mod int(1e9+7)
#define mp make_pair
//ios_base::sync_with_stdio(false);cin.tie(NULL);
#define testcases ll t; cin>>t; while(t--)

using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

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

    // int k=0;
    // testcases
    // {
        

    //     cout<<"Case #"<<++k<<": "<<ans<<"\n";
    // }

    double r;
    cin>>r;
    cout<<setprecision(10)<<fixed<<2*pi*r;

    return 0;
}

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

	int main() {
		int N, M, a, b, i;
		cin >> N >> M;
		vector<int> r(N);

		for (i = 0; i < M; i++) {
			cin >> a >> b;
			r.at(a - 1)++;
			r.at(b - 1)++;
		}

		for (i = 0; i < N; i++) {
			cout << r.at(i) << endl;
		}
	}

  



Measured memory_bytes: 256
A, B = map(int, input().split())
S = input()
num = '1234567890'
for i in S[:A]:
    if i in num:
        continue
    else:
        print('No')
        exit()
if S[A] != '-':
    print('No')
    exit()
for i in S[A+1:]:
    if i in num:
        continue
    else:
        print('No')
        exit()
print('Yes')


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

int main (){
  int N,m;
  vector<int> arrey = {};
  cin >> N >> m;
  arrey.push_back(m);
  for (int i = 0;i < N ;i++){
    int now = -1;
    cin >> now;
    if(now == -1)break;
    for (int l = 0; l < arrey.size();l++){
      if(arrey.at(l) == now) break;
      if(l == arrey.size() - 1) {
        arrey.push_back(now);
        break;
      }
    }
  }
  cout << arrey.size()<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define ff first
#define ss second
#define mp make_pair

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define MOD 998244353LL
#define N 100005

int a[N];
int dp[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//    int a = rng();

    int n;
    cin>>n;
    cin>>a[1]>>a[2];
    dp[1] = 0;
    dp[2] = abs(a[2] - a[1]);
    for(int i = 3; i <= n; i++){
        cin>>a[i];
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout<<dp[n];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll a, b;
    cin >> a >> b;
    ll ans = a <= b ? a : a - 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

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

py = []
city = {i+1: [] for i in range(n)}
for i in range(m):
    p, y = list(map(int, input().split()))
    city[p].append(y)
    py.append([p, y])


for i in city.values():
    i.sort()
# print(city)

ans = {i+1: {} for i in range(n)}
for key, value in city.items():
    for i in range(len(value)):
        ans[key][value[i]] = i+1

for p, y in py:
    # print(p, ans[p][y])
    print("{:06}{:06}".format(p, ans[p][y]))


Measured memory_bytes: 78400
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>

using namespace std;

const long long INF = 1LL << 60;

template<typename T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}

template<typename T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}

long long weight[110];
long long value[110];
long long dp[110][1000000] = { 0 };

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

	for (int i = 0;i < n;i++)cin >> weight[i] >> value[i];

	for (int i = 0;i < n;i++) {
		for (int sum_w = 1;sum_w <=w;sum_w++) {
			if (sum_w - weight[i] >= 0) {
				chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);

			}

			chmax(dp[i + 1][sum_w], dp[i][sum_w]);
		}
	}

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



Measured memory_bytes: 289024
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int main(){
    int k,x;
    cin>>k>>x;
    for (int i = -k+1; i < k; i++)
    {
        cout<<x+i<<" ";
    }
    cout<<endl;
    


    return 0;
}

Measured memory_bytes: 256
// Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    int n = input<int>();
    std::map<int, int> cnt;

    for (int i = 0; i != n; ++i)
        cnt[input<int>()] += 1;

    for (int m = input<int>(); m != 0; --m) {
        int v = input<int>();
        cnt[v] -= 1;
        if (cnt[v] == -1) {
            cout << "NO\n";
            return 0;
        }
    }

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


Measured memory_bytes: 9728
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
    int n,k; cin >> n >> k;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    vector<int> dp(n);
    dp[0] = 0; 
    for(int i=1; i<n; i++){

        dp[i] = 1e9;
        for(int j=1; j<=k; j++){
            if(i-j < 0) break;
            dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;    
}

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

typedef long long ll;
typedef long double ld;


#define CLOCK			 cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
#define debug(a)         cerr<<#a<<": "<<a<<endl;
#define pb               push_back
#define all(x)           (x).begin(),(x).end()
#define rall(x)          (x).rbegin(),(x).rend()
#define ps               " "
#define nln              "\n"
#define ff               first
#define ss               second
#define vi               vector<int>
#define vll              vector<ll>
#define vstr             vector<string>
#define vc               vector<char>
#define PII              pair<int,int>
#define PLL              pair<ll,ll>
#define PI               acos(-1)
#define sq(x)            x*x
#define forr(i,a,b)      for(int i=(int)a;i<(int)b;i++)
#define forn(i,a,b)      for(int i=(int)a;i>(int)b;i--)
#define mod              1000000007
#define inf              9223372036854775807

///knight moves:
///int dx[]= {-2,-1,1,2,2,1,-1,-2};
///int dy[]= {1,2,2,1,-1,-2,-2,-1};

void fileio()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

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

bool is_prime(ll n)
{
	if(n<2) return false;
	if(n==2) return true;
	
	if(n%2==0) return false;
	
	for(int i=3;i<sqrt(n+1)+1;i+=2)
	{
		if(n%i==0) return false;
	}
	return true;
}


int solve()
{
	ll a,b;
	cin>>a>>b;
	ll ans=__gcd(a,b);

	vll v;
	
	forr(i,1,sqrt(ans+1)+1)
	{
		if(ans%i==0)
		{
			v.pb((ll)i);
			if(i*i!=ans) v.pb(ans/i);
		}
	}
	
	sort(all(v));
	
	/*forr(i,0,v.size()) cout<<v[i]<<ps;
	cout<<nln; */
	
	int tot=1;
	
	forr(i,0,v.size())
	{
		if(is_prime(v[i])) tot++;
	}
	
	cout<<tot;

	
	
	return 0;
}
	

int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);cout.tie(0);
    
    ///fileio();
    
    solve();
    CLOCK;     		
           
  	return 0;
}


Measured memory_bytes: 384