akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<utility>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
long long sc[3][40];
int c[40][40];
int g[550][550];
int main()
{
	int N,M;
	cin>>N>>M;
	for(int i=0;i<M;i++)
		for(int j=0;j<M;j++)
			cin>>c[i][j];
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
		{
			cin>>g[i][j];
			for(int k=0;k<M;k++)
				sc[(i+j)%3][k]+=c[g[i][j]-1][k];
		}
	long long ans=9223372036854775807;
	for(int i=0;i<M;i++)
		for(int j=0;j<M;j++)
			for(int k=0;k<M;k++)
				if(i!=j&&j!=k&&k!=i)
				{
					long long sum=sc[0][i]+sc[1][j]+sc[2][k];
					ans=min(ans,sum);
				}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  cout << (1000 - n % 1000) % 1000 << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void prt(T x){cout << x << endl;}
template<class T>void prtvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

vector<vector<int>> G;
int dp[100100];

int rec(int v){
    if(dp[v]!=-1) return dp[v];
    
    int ans=0;
    for(auto nv: G[v]){
        chmax(ans, rec(nv)+1);
    }
    return dp[v]=ans;
}

int main()
{
    int n, m; cin>>n>>m;
    G.resize(n);
    {
        int x, y;
        rep(i, m){
            cin >> x >> y;
            x--; y--;
            G[x].push_back(y);
        }
    }

    rep(i, n) dp[i]=-1;

    int ans=0;
    rep(i, n) chmax(ans, rec(i));
    prt(ans);
    return 0;
}

Measured memory_bytes: 8192
PROGRAM ABC178A
      IMPLICIT NONE
      INTEGER,PARAMETER :: prec = 16
      integer :: x
      
      read*,x
      if( x==1 )then
        print*,'0'
      else
        print*,'1'
      end if
      
      
      
      stop
      !debugg
      
      
      
      END PROGRAM

Measured memory_bytes: 2796
N, M = map(int, input().split())

check_1 = []
check_N = []
for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        check_1.append(b)
    if b == N:
        check_N.append(a)
        
if len(list(set(check_1) & set(check_N))) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 21836
S = input()
a = S[0]
b = S[1]
c = S[2]
d = S[3]
l = []
l.append(a)
l.append(b)
l.append(c)
l.append(d)
k = list(set(l))
if len(k) == 2:
  if l.count(a) == 2:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N, M, p, y;
    cin >> N >> M;
    map<int, vector<pair<int,int>>> X;
    for ( int i = 0; i < M; i++ ) {
        cin >> p >> y;
        X[p].push_back(make_pair(y,i));
    }
    vector<pair<int, int>> id(M);
    for ( auto k : X ) {
        sort(k.second.begin(), k.second.end());
        for ( int j = 0; j < k.second.size(); j++ ) {
            int i = k.second[j].second;
            id[i] = make_pair(k.first, j+1);            
        }
    }

    for ( int i = 0; i < M; i++ ) {
        cout << setfill('0') << std::right << setw(6) << id[i].first;
        cout << setfill('0') << std::right << setw(6) << id[i].second;
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 13184
import bisect as bi

N = int(input())
c = [int(input()) for i in range(N)]
inf = 10000000000
lis = [inf for i in range(N)]

for i in range(N):
	lis[bi.bisect_left(lis, c[i])] = c[i]
	
print(bi.bisect_left(lis, inf))

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

using namespace std;
int main() {
  int x, t;
  cin >> x >> t;
  for (size_t i = 0; i < t; i++) {
    if (x > 0)
      x--;
    else
      break;
  }
  cout << x << endl;

  return 0;
}

Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll mod=1000*1000*1000+7;
const ll inf=1e18;

const ll is_query = -(1LL << 62);
struct Line {
	ll m, b;
	mutable function<const Line *()> succ;
	bool operator<(const Line &rhs) const {
		if (rhs.b != is_query) return m < rhs.m;
		const Line *s = succ();
		if (!s) return 0;
		ll x = rhs.m;
		return b - s->b < (s->m - m) * x;//ld?
	}
};
struct HullDynamic : public multiset<Line> {
	bool bad(iterator y) {
		auto z = next(y);
		if (y == begin()) {
			if (z == end()) return 0;
			return y->m == z->m && y->b <= z->b;
		}
		auto x = prev(y);
		if (z == end()) return y->m == x->m && y->b <= x->b;
		return (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m);//ld?
	}
	void insert_line(ll m, ll b) {
		auto y = insert({m, b});
		y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
		if (bad(y)) {
			erase(y);
			return;
		}
		while (next(y) != end() && bad(next(y))) erase(next(y));
		while (y != begin() && bad(prev(y))) erase(prev(y));
	}
	ll eval(ll x) {
		auto l = *lower_bound((Line) {x, is_query});
		return l.m * x + l.b;
	}
};


int n;
ll c;

ll tab[nax];

ll dp[nax];

int main()
{
	HullDynamic oto;
	//~ oto.insert_line(1, 0);
	//~ oto.insert_line(2, 0);
	//~ debug() << imie(oto.eval(7));
	scanf("%d%lld", &n, &c);
	for (int i=1; i<=n; i++)
	{
		scanf("%lld", &tab[i]);
	}
	//~ return 0;
	for (int i=1; i<=n; i++)
	{
		if (i>1)
			dp[i]=-oto.eval(tab[i])+tab[i]*tab[i]+c;
		oto.insert_line(2*tab[i], -(dp[i]+tab[i]*tab[i]));
	}
	
	printf("%lld\n", dp[n]);
	return 0;
}


Measured memory_bytes: 24704
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    seika s;
    cin >> s;
    cout << ((s[0] != s[1] || s[1] != s[2]) ? "Yes" : "No") << endl;
}

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


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

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    x--;
    y--;
    vector<int> ans(n);

    for(int i=0;i<n;i++){
        vector<int> d(n,1e9);
        queue<int> q;
        auto push=[&](int v,int r){
            if(d[v]!=1e9) return;
            d[v]=r;
            q.push(v);
        };
        push(i,0);
        while(!q.empty()){
            int v=q.front();
            q.pop();
            if(v-1>=0) push(v-1,d[v]+1);
            if(v+1<n) push(v+1,d[v]+1);
            if(v==x) push(y,d[v]+1);
            if(v==y) push(x,d[v]+1);
        }
        for(int t : d) ans[t]++;
    }
    for(int i=1;i<n;i++) cout<<ans[i]/2<<endl;
}

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

inline ll gcd(ll a, ll b) {
  for (; a; swap(b %= a, a));
  return b;
}

signed main() {
    string s;
    cin >> s;
    int cnt = count_if(be(s), [](char& c) { return c == '1'; });
    auto ans = 2 * min(cnt, (int)s.size() - cnt);
    cout << ans << nl;
}


Measured memory_bytes: 512
#include<iostream>
#include<sstream>
#include<iomanip>
#include<stdlib.h>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<algorithm>
#include<complex>
using namespace std;
#define loop(i,l,r) for(int (i)=(int)(l);(i)<(int)(r);(i)++)
#define rloop(i,l,r) for(int (i)=(int)(l);(i)>(int)(r);(i)--)
#define rep(i,n) loop(i,0,n)
#define rrep(i,n) rloop(i,n-1,-1)
#define INF 0x3f3f3f3f
#define mod 1000000007LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef complex<double> C;

vector<string> split(stringstream& ss){
	string str;
	vector<string> res;
	while(ss>>str)res.push_back(str);
	return res;
}

int main(){
		int n,m;
		while(1){
				cin>>n>>m;
				if(n==0&&m==0)break;
				int d,res=0;
				vector<int>v(n+m+1);
				v[0]=0;
				loop(i,1,n+m+1)cin>>d,v[i]=d;
				sort(v.begin(),v.end());
				loop(i,1,n+m+1)res=max(res,(v[i]-v[i-1]));
				cout<<res<<endl;
		}
}

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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }

  int count = 1;
  for(int i = 1; i < N; i++){
    bool ok = true;
    for(int j = 0; j < i; j++){
      if(H[i] < H[j]){
        ok = false;
      }
    }
    if(ok){
      count++;
    }
  }
  cout << count << endl;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cout << #x << " = " << (x) << "\n";

const int maxn = 1e5 + 5;
int n, m, q;
vi adj[maxn];
int ans[maxn];
int f[maxn][11][11];

void solve() {
	cin >> n >> m;
	FOR(i, 0, m) {
		int u, v; cin >> u >> v; u--, v--;
		adj[u].pb(v), adj[v].pb(u);
	}
	vector<pair<pi, int> > que;
	int q; cin >> q;
	FOR(i, 0, q) {
		int v, d, c; cin >> v >> d >> c; v--;
		que.pb(mp(mp(v, d), c));
	}
	FORd(i, q, 0) {
		int v = que[i].fi.fi;
		int d = que[i].fi.se;
		int c = que[i].se;
		if (f[v][0][d]) continue;
		queue<int> que;
		que.push(v), que.push(0);
		f[v][0][d] = 1;
		while (sz(que)) {
			int v = que.front(); que.pop();
			int e = que.front(); que.pop();
			if (!ans[v]) {
				ans[v] = c;
			}
			if (e == d) continue;
			FOR(i, 0, sz(adj[v])) {
				int u = adj[v][i];
				if (!f[u][e + 1][d]) {
					que.push(u), que.push(e + 1);
					f[u][e + 1][d] = 1;
				}
			}
		}
	}
	FOR(i, 0, n) cout << ans[i] << "\n";
}

int main() {
	ios_base::sync_with_stdio(0); //cin.tie(0);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 56176
#include <stdio.h>
#define INF 10000000 

int k[101]; 
int list[101][101]; 

int dist[101]; 

int n;

void walk(int id,int step){
	dist[id-1]=step;
	for(int i=0;i<k[id];i++){
		if(dist[list[id][i]-1]>step+1) walk(list[id][i],step+1);
	}
}

int main(void){
	int w;
	int num;

	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&num);
		scanf("%d",k+num);
		for(int j=0;j<k[num];j++) scanf("%d",&list[num][j]);
	}
	for(int i=0;i<n;i++) dist[i]=INF;
	walk(1,0);
	for(int i=1;i<=n;i++){
		if(dist[i-1]!=INF) printf("%d %d\n",i,dist[i-1]);
		else printf("%d -1\n",i);
	}
	return 0;
}

Measured memory_bytes: 1064
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define int long long
#define rep(i, a, b) for (ll i = (a); i <= (b); ++i)
#define per(i, a, b) for (ll i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (ll i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((ll)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <ll, ll> pii ;
typedef vector <ll> vi ;
typedef vector <pii> vii ;
typedef queue <ll> qi ;
typedef queue <pii> qii ;
typedef set <ll> si ;
typedef map <ll, ll> mii ;
typedef map <string, ll> msi ;
const ll maxn = 2e6 + 100 ;
const ll inf = 0x3f3f3f3f ;
const ll iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 998244353 ;
const double eps = 1e-7 ;
template <class T = ll> T chmin(T &a, T b) { return a = min(a, b);}
template <class T = ll> T chmax(T &a, T b) { return a = max(a, b);}
template <class T = ll> T read()
{
	T f = 1, a = 0;
	char ch = getchar() ;
	while (!isdigit(ch)) { if (ch == '-') f = -1 ; ch = getchar() ; }
	while (isdigit(ch)) { a =  (a << 3) + (a << 1) + ch - '0' ; ch = getchar() ; }
	return a * f ;
}

ll n, m, ans = linf;

ll a[maxn];

bool check(ll lim)
{
	// printf("check : %lld\n", lim);
	ll ret = 0;
	rep(i, 1, lim) chmax(ret, a[i] + a[2 * lim - i + 1]);
	rep(i, 1, n - lim)
	{
		if(a[2 * n - i + 1] + a[2 * n - 2 * (n - lim) + i] < m) return 0;
		chmax(ret, a[2 * n - i + 1] + a[2 * n - 2 * (n - lim) + i] - m);
	}
	chmin(ans, ret);
	// printf("ans : %lld\n", ans);
	return 1;
}

signed main()
{
	n = read(), m = read();
	rep(i, 1, 2 * n) a[i] = read();
	sort(a + 1, a + 2 * n + 1);
	ll l = 0, r = n;
	while(l <= r)
	{
		ll mid = (l + r) >> 1;
		if(check(mid)) r = mid - 1;
		else l = mid + 1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 5284
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  const int M = 1<<15;
  int dp[M + 1][5] = {};
  dp[0][0] = 1;
  for(int i = 1; i * i <= M; i++){
    int s = i * i;
    for(int j = s; j <= M; j++){
      for(int k = 0; k <= 3; k++){
        dp[j][k+1] += dp[j-s][k];
      }
    }
  }
  int n;
  while(scanf("%d",&n) != EOF && n){
    int ans = 0;
    REP(i,5)ans += dp[n][i];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
int x[100000];
signed main() {
	int n, k, ans = 0;
	cin >> n >> k;
	for (int i = 1; i <= k; i++) {
		int z = i;
		for (int j = 2; j*j <= i; j++) {
			if (i%j == 0) {
				z -= x[j];
				if (j*j != i)z -= x[i / j];
			}
		}
		if (i >= 2)z--;
		x[i] = z;
		ans += mypow(k / i, n, mod)*z;
		ans %= mod;
	}
	cout << (ans + mod) % mod << endl;
}


Measured memory_bytes: 4376
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii;
import std.typecons, std.functional;
import std.algorithm, std.container;

void main()
{
    auto N = scanElem;
    auto M = scanElem;
    auto Q = scanElem;

    long[501][501] table;
    foreach(i; 0..M)
    {
        long[] train = scanArray;
        long l = train[0];
        long r = train[1];
        table[r][l] += 1;
    }
    foreach(x; 1..501)
    {
        foreach(y; 1..501)
        {
            table[x][y] += table[x-1][y];
            table[x][y] += table[x][y-1];
            table[x][y] -= table[x-1][y-1];
        }
    }
    foreach(i; 0..Q)
    {
        long[] query = scanArray;
        long p = query[0];
        long q = query[1];
        writeln(table[q][q] - table[p-1][q] - table[q][p-1] + table[p-1][p-1]);
    }
}

void scanValues(TList...)(ref TList list)
{
    auto lit = readln.splitter;
    foreach (ref e; list)
    {
        e = lit.fornt.to!(typeof(e));
        lit.popFront;
    }
}

T[] scanArray(T = long)()
{
    return readln.split.to!(long[]);
}

void scanStructs(T)(ref T[] t, size_t n)
{
    t.length = n;
    foreach (ref e; t)
    {
        auto line = readln.split;
        foreach (i, ref v; e.tupleof)
        {
            v = line[i].to!(typeof(v));
        }
    }
}

T scanElem(T = long)()
{
    string res;
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        res ~= cast(char) c;
        c = getchar;
    }
    return res.strip.to!T;
}

template fold(fun...) if (fun.length >= 1)
{
    auto fold(R, S...)(R r, S seed)
    {
        static if (S.length < 2)
        {
            return reduce!fun(seed, r);
        }
        else
        {
            import std.typecons : tuple;

            return reduce!fun(tuple(seed), r);
        }
    }
}

struct Factor
{
    long n;
    long c;
}

Factor[] factors(long n)
{
    Factor[] res;
    for (long i = 2; i ^^ 2 <= n; i++)
    {
        if (n % i != 0)
            continue;

        int c;
        while (n % i == 0)
        {
            n = n / i;
            c++;
        }
        res ~= Factor(i, c);
    }
    if (n != 1)
        res ~= Factor(n, 1);

    return res;
}

bool isPrime(long n)
{
    if (n <= 1)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;
    for (long i = 3; i ^^ 2 <= n; i += 2)
        if (n % i == 0)
            return false;
    return true;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

//const ll MOD = ll(1e12)+5721;
const int MOD = 1e9 + 7;
ll add(ll a, ll b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}

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

ll dp[500011];
ll powr[500011];
ll ipowr[500011];
const int C = 2017;

ll modpow(ll a, ll b)
{
	ll r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}

ll hsh(int l, int r)
{
	if(l>r) return 0;
	if(l==0) return dp[r];
	return mult(ipowr[l],add(dp[r],MOD-dp[l-1]));
}

int pref[500011];
int suf[500011];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	powr[0]=1; ipowr[0]=1;
	ll iC = modpow(C,MOD-2);
	for(int i=1;i<=500000;i++)
	{
		powr[i]=mult(powr[i-1],C);
		ipowr[i]=mult(ipowr[i-1],iC);
	}
	for(int i=0;i<s.length();i++)
	{
		dp[i] = mult((s[i]-'a'+1),powr[i]);
		if(i>0) dp[i]=add(dp[i-1],dp[i]);
	}
	int n=s.length();
	bool eq=1;
	for(int i=0;i<n;i++)
	{
		if(s[i]!=s[0]) eq=0;
	}
	if(eq)
	{
		cout<<n<<'\n'<<1<<'\n';
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		ll H = hsh(0,i-1);
		for(int j=2*i-1;j<n;j+=i)
		{
			ll H2 = hsh(j-i+1,j);
			if(H==H2)
			{
				pref[j]=1;
			}
			else break;
		}
	}
	for(int i=1;i<=n;i++)
	{
		ll H = hsh(n-i,n-1);
		for(int j=n-2*i;j>=0;j-=i)
		{
			ll H2 = hsh(j,j+i-1);
			if(H==H2)
			{
				suf[j]=1;
			}
			else break;
		}
	}
	if(!pref[n-1])
	{
		cout<<1<<'\n'<<1<<'\n';
		return 0;
	}
	int cnt=0;
	for(int i=0;i+1<n;i++)
	{
		if(pref[i]||suf[i+1]) continue;
		cnt++;
	}
	cout<<2<<'\n';	
	cout<<cnt<<'\n';
}


Measured memory_bytes: 16540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) a.begin(), a.end()
#define print(x) cout << x << "\n";

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

    vector<int> a(n + 2);
    a[0] = 0;
    a[n + 1] = 0;
    int sum = 0;

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

    for (int i = 1; i < n + 2; i++) {
        sum += abs(a[i - 1] - a[i]);
    }
        for (int i = 1; i < n + 1; i++)
        {
            int ans = sum;
            ans += -(abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) + abs(a[i - 1] - a[i + 1]);
            print(ans);
        }
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h, w, a, b;
    scanf("%d %d %d %d", &h, &w, &a, &b);
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            if((i <= b) == (j <= a)) printf("0");
            else printf("1");
        }
        printf("\n");
    }
    return 0;
}

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

#define MAX 100001
#define min(a, b) ((a) < (b) ? (a) : (b))

struct work {
	char wname[32];
	int time;
};

typedef struct work elemType;

elemType Q[MAX];
int head, tail;

void init_queue()
{
	head = tail = 0;
}

int is_full()
{
	return ((tail + 1) % MAX) == head;
}

int is_empty()
{
	return head == tail;
}

void enqueue(elemType v)
{
	if (is_full())
		exit(1);
	
	Q[tail] = v;
	tail = ((tail + 1) % MAX);
}

elemType dequeue()
{
	elemType v;
	
	if (is_empty())
		exit(1);
		
	v = Q[head];
	head = ((head + 1) % MAX);
	
	return v;
}

int main(int argc, char *argv[])
{
	int n, q, i;
	int total_time = 0;
	elemType e;
	
	init_queue();
	
	scanf("%d %d", &n, &q);
	for (i = 0; i < n; i++) {
		scanf("%s %d", Q[i].wname, &Q[i].time);
		tail++;
	}
		
	while (!is_empty()) {
		e = dequeue();
		total_time += min(q, e.time); 
		e.time -= min(q, e.time);
		if (0 == e.time) {
			printf("%s %d\n", e.wname, total_time);
		} else {
			enqueue(e);
		}
		
	}

	return 0;
}


Measured memory_bytes: 5228
#include<bits/stdc++.h>
using namespace std;
#define debug 1

int main() {
	string tile;
	getline(cin,tile);
	int n=tile.length();
	char now='0';
	int ans1=0,ans2=0;
	
	for(int i=0;i<n;i++) {
		if(tile[i]==now) ans1++;
		else ans2++;
		if(now=='0') now='1';
		else now='0';
	}
	
	cout<<min(ans1,ans2)<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	SINT32 N = 0;

	cin >> N;

	for (SINT32 i = N; i >= 0; i--) {
		SINT32 buf = 0;
		buf = sqrt(i);
		if (buf*buf == i) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 256
import itertools
op = ["+", "-"]
s = input()
for i in itertools.product(op, repeat=3):
    sm = int(s[0])
    st = s[0]
    for j, v in enumerate(i):
        if v == "+":
            sm += int(s[j+1])
            st += v
            st += s[j+1]
        else:
            sm -= int(s[j+1])
            st += v
            st += s[j+1]
    if sm == 7:
        print(st + "=7")
        exit()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  vector<int> vec(3);
  for(int i=0;i<3;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(), vec.end());
  cout <<(vec.at(2))*10+vec.at(1)+vec.at(0);  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if(x / k >= d){
        cout << x - k * d << endl;
    }else{
        ll n = x / d;
        x -= d * n;
        k -= n;
        if(k % 2 == 0){
            cout << x << endl;
        }else{
            cout << abs(x - d) << endl;
        }
    }
    
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <ext/numeric>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scs(a) scanf("%s", a)
#define pri(x) printf("%d\n", x)
#define prie(x) printf("%d ", x)
#define pris() printf("\n")
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false)
#define db(x) cerr << #x << " == " << x << endl
#define power(a,x) __gnu_cxx::power(a, x)
#define eps 1e-5
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld pi = acos(-1);
const int MOD = 1e9 + 7;

int main()
{
    BUFF;
    string n;
    cin>>n;
    bool valid=true;
    ll ret=0;

    for(int i=0;i<n.size();i++)
    {
        valid=valid&&(n[i]=='9');
        ret+=n[i]-'0';
    }
    ll aux=0;
    for(int i=0;i<n.size();i++)
    {
        if(n[i]>'0')
        {
            ll curr=0;
            curr+=n[i]-'0'-1;
            curr+=(n.size()-(i+1))*9;
            ret=max(ret,aux+curr);
        }
        aux+=n[i]-'0';
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  string t = "";
  rep(i,n){
    if(i == 0) t.push_back(s[i]);
    if(i > 0) if(s[i] != s[i-1]) t.push_back(s[i]);
  }
  cout << t.size()-1 << endl;
}

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

using namespace std;

int doit(vector<int> a, vector<int> b){
    int ans = 0;
    for(int i = 0; i < a.size(); i++)
        ans += (a[i] - b[i]) * (a[i] - b[i]);
    return ans;
}

int main(){
    int n,d; cin >> n >> d;
    vector<int> memo(20000,0);
    for(int i = 1; i * i < 20000; i++ )
        memo[i*i] = 1;
    vector<vector<int>> points(n,vector<int>(d));
    for( auto &point : points)
        for( auto &x : point) 
            cin >> x;
    int cnt = 0;
    for(int i = 0; i < n; i++)
        for(int j = i + 1; j < n; j++)
            cnt += memo[doit(points[i], points[j])];
    cout << cnt << "\n";
    return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a<b){
    cout << "a < b" << endl;
  }
  if(a>b){
    cout << "a > b" << endl;
  }
  if(a==b){
    cout << "a == b" << endl;
  }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

long long gcd(long long a, long long b) {
	return b ? gcd(b, a % b) : a;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}

signed main() {
	int n;
	cin >> n;
	int a[n], Cmp, ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += a[i] - 1;
	}
	cout << ans << '\n';
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#define N 100500
using namespace std;

int arr[N];

int fun(int x)
{
    int sum=0;
    while(x!=0)
    {
        sum+=x%10;
        x/=10;
    }
    return sum;
}


int main()
{
    int n;
    cin>>n;
    int p=0;
    for(int i=1;i<n;i+=10)
    {
        arr[p++] = fun(i)+fun(n-i);
    }
    for(int i=10;i<n;i+=10)
    {
        arr[p++] = fun(i)+fun(n-i);
    }
    int min = N;
    for(int i=0;i<p;i++)
    {
        if(min>arr[i]) min = arr[i];
    }
    cout<<min;

}


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

int main(){
   int n;
   cin >> n;
   string s;
   cin >> s;
   int ans = 0;

   for(int i = 0; i < n - 2; ++i){
       string a = s.substr(i,3);
        if(a == "ABC")ans++;
   }

   cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <utility> //pairを使う
using namespace std;

typedef unsigned long long ll;

const ll inf = 1000000000000;
const ll mod = 100000;

int main(){
	int dp[10][10], t = 0;
	int h, w;
	cin >> h >> w;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			int s;
			cin >> s;
			dp[i][j] = s;
		}
	}
	for(int k = 0; k < 10; k++){
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			int s;
			cin >> s;
			if(s != -1){
				t += dp[s][1];
			}
		}
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;

int x,y,z;

int main() {
    ios::sync_with_stdio(false);
    cin>>y>>z>>x;
    printf("%d %d %d\n",x,y,z);

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int INF=123456789;

int n,m;
int R;
int z[1001];
int ld[200][200],sd[200][200];
vector<int> island[200];
int island_id[200];
ll dp[1001][200];

void init()
{
    fill(ld[0],ld[200],INF);
    fill(sd[0],sd[200],INF);
    rep(i,200) island[i].clear();
    fill(island_id,island_id+200,-1);
    fill(dp[0],dp[1001],10000LL*INF);
}

void Warshall_Floyd()
{
    rep(i,n)
    {
        ld[i][i]=0;
        sd[i][i]=0;
    }
    rep(k,n)rep(i,n)rep(j,n)
    {
        ld[i][j]=min(ld[i][j],ld[i][k]+ld[k][j]);
        sd[i][j]=min(sd[i][j],sd[i][k]+sd[k][j]);
    }
}

void divide()
{
    int island_idx=0;
    rep(i,n)
    {
        if(island_id[i]!=-1) continue;

        island_id[i]=island_idx;
        rep(j,n) if(ld[i][j]<INF) island_id[j]=island_idx;

        ++island_idx;
    }
    rep(i,n) island[island_id[i]].pb(i);
}

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

        // input
        rep(i,m)
        {
            int x,y,t;
            char sl;
            scanf(" %d %d %d %c",&x,&y,&t,&sl);
            --x;
            --y;
            if(sl=='L') ld[x][y]=ld[y][x]=min(ld[x][y],t);
            else sd[x][y]=sd[y][x]=min(sd[x][y],t);
        }
        scanf(" %d",&R);
        rep(i,R)
        {
            scanf(" %d",&z[i]);
            --z[i];
        }

        Warshall_Floyd();

        // determine the island i-th town belongs
        divide();

        // calc ans
        dp[0][z[0]]=0;
        for(int i=1; i<R; ++i)
        {
            int p_id=island_id[z[i-1]], c_id=island_id[z[i]];
            if(p_id==c_id)
            {
                rep(j,island[p_id].size())
                {
                    int boat=island[p_id][j];
                    dp[i][boat] = min(dp[i][boat], dp[i-1][boat]+ld[z[i-1]][z[i]]);
                }
            }
            rep(j,island[p_id].size())rep(k,island[c_id].size())
            {
                int now_b=island[p_id][j], nx_b=island[c_id][k];
                dp[i][nx_b] = min(dp[i][nx_b], dp[i-1][now_b]+ld[z[i-1]][now_b]+sd[now_b][nx_b]+ld[nx_b][z[i]]);
            }
        }

        ll ans=10000LL*INF;
        rep(i,n) ans=min(ans,dp[R-1][i]);
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 5072
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    S=input()
    T=input()
    min_change = INF
    for i in range(len(S)-len(T)+1):
        tmp = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                tmp += 1
        min_change = min(min_change,tmp)
    print(min_change)




    
main()

Measured memory_bytes: 68416
#include <stdio.h>

int max;
int s;

int solve(int n, int m, int l)
{
	if (m == max){
		if (n == 0){
			return (1);
		}
		
		return (0);
	}
	if (l == 10){
		return (0);
	}
	return (solve(n - l, m + 1, l + 1) + solve(n, m, l + 1));
}

int main(void)
{
	while (1){
	scanf("%d%d", &max, &s);
	if (max == 0 && s == 0){
		return (0);
	}
	printf("%d\n", solve(s, 0, 0));
	}
	return (0);
}

Measured memory_bytes: 1028
import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long a = sc.nextInt();
    	long b = sc.nextInt();
    	long c = sc.nextInt();
    	long d = sc.nextInt();
    	System.out.println(Math.max(Math.max(a * c, a * d), Math.max(b * c, b * d)));
	}
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
 
#define limit (int) (1005)
#define mod (int) 1000000007

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

string st[4] = {"AC","WA","TLE","RE"};
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    
    int n;
    cin >> n;
    string s;

    int c[4] = {};

    for (int i = 0; i < n; ++i)
    {
        cin >> s;

        for (int j = 0; j < 4; ++j)
        {
            if (s == st[j])
            {
                c[j]++;
                break;
            }
        }
    }

    for (int i = 0; i < 4; ++i)
    {
        cout << st[i] << " x " << c[i] << "\n";
    }


    return 0;
}
















Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

using namespace std;
int MOD = 1000000007;
int a[110]={1,682498929,491101308,76479948,723816384,67347853,27368307,
625544428,199888908,888050723,927880474,281863274,661224977,623534362,
970055531,261384175,195888993,66404266,547665832,109838563,933245637,
724691727,368925948,268838846,136026497,112390913,135498044,217544623,
419363534,500780548,668123525,128487469,30977140,522049725,309058615,
386027524,189239124,148528617,940567523,917084264,429277690,996164327,
358655417,568392357,780072518,462639908,275105629,909210595,99199382,
703397904,733333339,97830135,608823837,256141983,141827977,696628828,
637939935,811575797,848924691,131772368,724464507,272814771,326159309,
456152084,903466878,92255682,769795511,373745190,606241871,825871994,
957939114,435887178,852304035,663307737,375297772,217598709,624148346,
671734977,624500515,748510389,203191898,423951674,629786193,672850561,
814362881,823845496,116667533,256473217,627655552,245795606,586445753,
172114298,193781724,778983779,83868974,315103615,965785236,492741665,
377329025,847549272,698611116};
ll getfn(int n){
        ll now=n/10000000;
        ll ans=a[now];
        for(ll i=now*10000000+1;i<=n;i++)
                ans=ans*i % MOD;
        return ans;
}
ll powermod(int x,int y){
  ll z = 1;
  while( y != 0 ){
    if( y % 2 == 1 ){
      z = ((ll)z * x) % MOD;
    }
    x = ((ll)x*x) % MOD;
    y /= 2;
  }
  return z;
}
int main(){
  int n , a, b;
  cin >> n >> a >> b;
  /*
  vector<ll> f(n+10);
  f[0] = 1;
  int big = a > b ? a : b;
  for(int i = 1 ; i <= big ; i++ ){
    f[i] = ((ll)f[i-1]*i) % MOD;
  }
  */
  ll ret = powermod(2,n) - 1;

  ll fn = getfn(n);
  ll fa = getfn(a);
  ll fb = getfn(b);
  ll fna = getfn(n-a);
  ll fnb = getfn(n-b);

  ret %= MOD;
  ll ma = (ll)fn* powermod(fa,MOD-2) ;
  ma %= MOD;
  ma = ma * powermod(fna,MOD-2);//C(n,a);
  ma %= MOD;
  
  ll mb = (ll)fn* powermod(fb,MOD-2) ;
  mb %= MOD;
  mb = mb * powermod(fnb,MOD-2);//C(n,a);
  mb %= MOD;


  ret = ret - ma;
  if( ret < 0 ) ret += MOD;

  ret = ret - mb;
  if( ret < 0 ) ret += MOD;
   
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod;
int Arr[100005];
void seive(){
		Arr[0]=Arr[1]=1;
		for(int i=2;i<100005;++i){
			if(Arr[i]==0)
			for(int j=2*i;j<100005;j+=i)
			Arr[j]=1;
		}
}


bool isprime(int a){
	if(a<2)
	return false;
	if(a==2)
	return true;
	if(a%2==0)
	return false;
	for(int i=3;i*i<=a;i+=2)
	if(a%i==0)
	return false;
	return true;
}




// -----------------------------------------------------------------------


// -----------------------------------------------------------------------



void q1(){
	int k,x;
	cin>>k>>x;
	int pp=500*k;
	if(pp>=x)
	cout<<"Yes";
	else
	cout<<"No";	
}
// -----------------------------------------------------------------------


void q2(){
	int a,b;
	cin>>a>>b;
	string s;cin>>s;
	if(s[a]!='-'){
		cout<<"No\n";
		return ;
	}
	for(int i=0;i<=a+b;++i){
		if(i==a)
		continue;
		if(!(s[i]>='0' && s[i]<='9')){
			cout<<"No\n";
			return ;
		}
	}
	cout<<"Yes\n";
}

// -----------------------------------------------------------------------

void q3(){
	int n;
	cin>>n;
	int c[n-1],s[n-1],f[n-1];
	for(int i=0;i<n-1;++i)
	cin>>c[i]>>s[i]>>f[i];
	int res[n];
	res[n-1]=0;
	for(int i=n-2;i>=0;--i){
		int t=s[i]+c[i];
		for(int j=i+1;j<n-1;++j){
			if(t<=s[j]){
				t=s[j];
				t+=c[j];
			}else{
				int next = (t+f[j]-1)/f[j];
				next*=f[j];
				t=next+c[j];
			}
		}
		res[i]=t;
	}
	for(int i=0;i<n;++i)
	cout<<res[i]<<endl;
}


// -----------------------------------------------------------------------

void q4(){
	seive();
	//cout<<Arr[23]<<endl;
	int ans[100005];
	ans[0]=0;ans[1]=0;ans[2]=0;
	for(int i=3;i<=100005;i+=2)
	{
		int num=i+1;
		num/=2;
		if(Arr[i]==0 && Arr[num]==0)
		ans[i]=1;
		else
		ans[i]=0;
	}
	//cout<<ans[3]<<endl;
	
	for(int i=1;i<100005;++i)
	ans[i]+=ans[i-1];
	//cout<<ans[7]<<endl;

	int q;cin>>q;
	while(q--){
		int l,r;
		cin>>l>>r;
		cout<<ans[r+1]-ans[l]<<endl;
		/*int cp=0;
		for(int i=l;i<=r;++i){
			int num=i+1;
			num/=2;
			if(i%2==1)
			if(isprime(i) && isprime(num))
			cp++;
		}
		cout<<cp<<endl;*/
	}
}

// -----------------------------------------------------------------------


int32_t main()
{
	mod=1e+7;
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	q1();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long N = 0;
    cin >> N;

    int result = INT_MAX;
    for (long long A = 1; A<= sqrt(N); ++A) {
        int digit = 1;
        //NをAで割り切れない = AがNの約数じゃない
        if(N % A != 0){
            continue;
        }
        long long B = N/A;
        long long big = max(A,B);
        while (big/10 !=0){
            big = big / 10;
            digit++;
        }
        result = min(result,digit);
    }
    cout << result;

    return 0;
}

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

int main() {
  int n, l;
  vector<string> s;

  cin >> n >> l;
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    s.push_back(t);
  }

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

  for (int i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;

  return 0;
}


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

	S = s+s; //??¬?????????????????????

		if( S.find(p) == -1 ){
			cout << "No\n";
		}else{
			cout << "Yes\n";
		}

	return 0;
}

Measured memory_bytes: 1188