akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

bool chk(vector<ll> &a, vector<ll> &x, int i){
	int n = a.size();
	x.at(0) = i*2;
	for(int j=1; j<n; j++){
		x.at(j) = a.at(j-1)*2-x.at(j-1);
	}
	return x.at(0)+x.at(n-1)>=a.at(n-1)*2;
}

int main(){
	
	int n; cin>>n;
	vector<ll> a(n),x(n);
	for(auto &i:a) cin>>i;
	int ok = a.at(0);
	chk(a,x,ok);
	ok-=(x.at(0)+x.at(n-1)-a.at(n-1)*2)/4;
	chk(a,x,ok);
	for(auto it = x.begin(); it!= x.end(); it++){
		cout << *it <<(it!=x.end()-1?' ':'\n');
	}
	cout << flush;
	
}

Measured memory_bytes: 2944
#from functools import reduce


def resolve():
    _ = int(input())
    xv = list(map(float, input().split()))
    yv = list(map(float, input().split()))

    # for p in range(1, 4):
    #     print(reduce(lambda x, y: x + abs(y[0] - y[1]) ** p, zip(xv, yv), 0) ** (1 / p))

    # p = 1, 2, 3
    for p in range(1, 4):
        k = sum([abs(x - y) ** p for x, y in zip(xv, yv)]) ** (1 / p)
        print("{0:.6f}".format(k))
    # p = ∞
    print("{0:.6f}".format(max([abs(x - y) for x, y in zip(xv, yv)])))


resolve()



Measured memory_bytes: 5676
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int x[(1<<18)+10],a[(1<<18)+10];
multiset<int> s;
int main()
{
	int n;cin>>n;
	rep(i,(1<<n)) cin>>a[i];
	sort(a,a+(1<<n));reverse(a,a+(1<<n));
	REP(i,1,(1<<n)) s.insert(a[i]);
	s.insert(-1);s.insert(1001001001);
	x[0]=a[0];
	rep(i,n){
		sort(x,x+(1<<i));
		rep(j,(1<<i)){
			multiset<int>::iterator it=s.lower_bound(x[j]);
			it--;
			if((*it)<0){
				cout<<"No"<<endl;return 0;
			}
			x[j+(1<<i)]=(*it);s.erase(it);
		}
	}
	cout<<"Yes"<<endl;
}


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

int main() {
  string S;
  cin >> S;
  int cnt = S.size();
  while (cnt >= 5) {
    if (S.at(cnt-5)=='d'&&S.at(cnt-4)=='r'&&S.at(cnt-3)=='e'&&S.at(cnt-2)=='a'&&S.at(cnt-1)=='m') {
      cnt -= 5;
    }
    else if (S.at(cnt-5)=='e'&&S.at(cnt-4)=='r'&&S.at(cnt-3)=='a'&&S.at(cnt-2)=='s'&&S.at(cnt-1)=='e') {
      cnt -= 5;
    }
    else if (cnt>=7&&S.at(cnt-7)=='d'&&S.at(cnt-6)=='r'&&S.at(cnt-5)=='e'&&S.at(cnt-4)=='a'&&S.at(cnt-3)=='m'&&S.at(cnt-2)=='e'&&S.at(cnt-1)=='r') {
      cnt -= 7;
    }
    else if (cnt>=6&&S.at(cnt-6)=='e'&&S.at(cnt-5)=='r'&&S.at(cnt-4)=='a'&&S.at(cnt-3)=='s'&&S.at(cnt-2)=='e'&&S.at(cnt-1)=='r') {
      cnt -= 6;
    }
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << (cnt == 0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
(let ((a (read-line))
      (ans 0))
  (loop :for k :from 0 :upto (- (length a) 3) :do
    (if (> (abs (- 753 ans))  (abs (- 753 (parse-integer (subseq a k (+ k 3))))))
        (setf ans (parse-integer (subseq a k (+ k 3))))
        nil))
  (princ (abs (- 753 ans))))


Measured memory_bytes: 12004
#include <iostream>

using namespace std;

int partition(int a[],int p,int r){
  int x=a[r];
  int i=p-1;
  for(int j=p;j<=r-1;j++){
    if(a[j]<=x){
      i++;
      int t=a[i];
      a[i]=a[j];
      a[j]=t;
    }
  }
  int t=a[i+1];
  a[++i]=a[r];
  a[r]=t;
  return i;
}

int main(){
  int n; cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int idx=partition(a,0,n-1);
  for(int i=0;i<n;i++){
    if(i==idx){
      if(i) cout << " " << '[' << a[i] << ']';
      else cout << a[i];
    }else{
      if(i) cout << " " << a[i];
      else cout << a[i];
    }
  }
  cout << endl;
}

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

int main(){
    int K, A, B;
    cin >> K >> A >> B;
    int sum = 0;
    while(sum < A){
        sum += K;
    }
    if(sum <= B) cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll N, Q;
  cin >> N;

  unordered_map<ll, ll> A;
  for(int i=0; i<N; i++){
    ll temp;
    cin >> temp;
    if (A.find(temp) == A.end()) A[temp] = 1;
    else ++A[temp];
  }

  ll sum = 0;
  for(auto &e : A) sum += e.first * e.second;

  cin >> Q;
  vector<ll> B(Q), C(Q);
  for(int i=0; i<Q; i++) cin >> B[i] >> C[i];


  for(int i=0; i<Q; i++){
    if (A.find(B[i]) == A.end())
    {
      cout << sum << endl;
      continue;
    }
    ll num = A[B[i]];
    ll sub = C[i] - B[i];
    sum += sub * num;
    cout << sum << endl;

    A.erase(B[i]);
    if(A.find(C[i]) == A.end()) A[C[i]] = num;
    else A[C[i]] += num;
  }

  return 0;
}

Measured memory_bytes: 7792
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut l_vec: [i64; n],
    };
    l_vec.sort();
    if n < 3 {
        println!("0");
        return;
    }
    let mut ans = 0;
    for l1i in 0..(n - 2) {
        let l1 = l_vec[l1i];
        for l2i in (l1i + 1)..(n - 1) {
            let l2 = l_vec[l2i];
            if l2 == l1 {
                continue;
            }
            for l3i in (l2i + 1)..n {
                let l3 = l_vec[l3i];
                if l1 == l3 || l2 == l3 {
                    continue;
                }
                if l3 - l2 < l1 {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}


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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> A(n);
    for(int i=0; i<n; ++i) cin>>A[i];
    deque<int> Q;
    for(int i=0; i<k; ++i) Q.push_back(A[i]);

    for(int i=k; i<n; ++i){
        int f = Q.front();
        Q.pop_front();
        Q.push_back(A[i]);
        if(A[i]>f) cout<<"Yes\n";
        else cout<<"No\n";
    }
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int x[111],y[111],r[111],c[111];
bool used[111];
char mem[1<<24];

bool judge(int i,int j){
	bool ok=true;
	rep(k,i){
		if(used[k])continue;
		if(pow(x[i]-x[k],2)+pow(y[i]-y[k],2)<pow(r[i]+r[k],2))ok=false;
	}
	rep(k,j){
		if(used[k])continue;
		if(pow(x[k]-x[j],2)+pow(y[k]-y[j],2)<pow(r[k]+r[j],2))ok=false;
	}
	return ok;
}

int dfs(int v){
	if(mem[v]!=-1)return mem[v];
	int res=0;
	rep(i,n)repl(j,i+1,n){
		if(!used[i]&&!used[j]&&c[i]==c[j]&&judge(i,j)){
			used[i]=used[j]=true;
			maxch(res,dfs(v|(1<<i)|(1<<j))+2);
			used[i]=used[j]=false;
		}
	}
	return mem[v]=res;
}

int main(){
	//cin.sync_with_stdio(false);
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		rep(i,n)scanf("%d%d%d%d",x+i,y+i,r+i,c+i);
		memset(used,0,sizeof(used));
		memset(mem,-1,sizeof(mem));
		cout<<dfs(0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 19512
#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;

	if (a + b >= 10) {
		cout << "error" << endl;
	} else {
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  if(N % 2 == 1){
    cout << "No" << endl;
  }
  else{
    vector<char> S1(N/2);
    rep(i, N/2){
      S1.at(i) = S.at(i);
    }
    rep(i, N/2){
      if(S.at(N/2 +i) != S1.at(i)){
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 10
int N,D,Ans;
int X[MAXN+5][MAXN+5];

bool Check(int *A,int *B){
	int All=0;
	for(int i=1;i<=D;i++)
		All+=(A[i]-B[i])*(A[i]-B[i]);
	return int(sqrt(All))*int(sqrt(All))==All;
}

int main(){
	scanf("%d%d",&N,&D);
	for(int i=1;i<=N;i++)
		for(int j=1;j<=D;j++)
			scanf("%d",&X[i][j]);
	for(int i=1;i<=N;i++)
		for(int j=i+1;j<=N;j++)
			Ans+=Check(X[i],X[j]);
	printf("%d",Ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;






int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b; cin >> a >> b;
    if(a+b>=24) cout << a+b-24 << endl;
    else cout << a + b << endl;
}



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

int calc(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int N, a;
    cin >> N;
    a = calc(N);
    if(N % a == 0){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 1e5 + 2;
ll i,n,k,ans,a,b;
vi adj[N];
void dfs(ll v,ll par)
{
    ll ch = k - 1;
    if(par != -1) ch -= 1;
    ch = max(0LL, ch);
    
    for(auto it: adj[v]) if(it != par){
        ans = (ans * ch) % mod;
        dfs(it,v);
        ch -= 1;
        ch = max(0LL, ch);
    }
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>k;
    rep(i,1,n){
        cin>>a>>b;
        adj[a].pb(b); adj[b].pb(a);
    }
    ans = k;
    dfs(1,-1);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 12800
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e5+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    int n;
    cin>>n;
    ll arr[n];
    ll freq[mxN]={};
    ll sum=0;
    loop(n,i,0)
        cin>>arr[i],freq[arr[i]]++,sum+=arr[i];
    int q;cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        sum-=b*freq[b];
        sum+=c*freq[b];
        freq[c]+=freq[b];
        freq[b]=0;
        cout<<sum<<Endl;
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int H, W;
  cin >> H >> W;
  int h, w;
  cin >> h >> w;
  cout << (H - h) * (W - w) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vector<vector<pll>> ed(n+1,vector<pll>(0));
  rep(i,m){
    ll l,r,d;
    cin>>l>>r>>d;
    ed[r].pb(pll(l,-d));
    ed[l].pb(pll(r,d));
  }
  queue<ll> que;
  vll dist(n+1,INF);
  for(int i=1;i<=n;i++){
    if(dist[i]==INF){
      dist[i]=0;
      que.pu(i);
      while(sz(que)){
        ll from=que.front();
        que.pop();
        for(pll p:ed[from]){
          if(dist[p.F]==INF){
            dist[p.F]=dist[from]+p.S;
            que.pu(p.F);
          }
          else if(dist[p.F]!=dist[from]+p.S){
            COUT("No");
            return 0;
          }
        }
      }
    }
  }
  COUT("Yes");
}


Measured memory_bytes: 14080
import java.util.Scanner;

class Main{
	static int[][] pond;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		pond=new int[14][14];
		String tmp="";
		while(sc.hasNext()) {
			for(int i=0; i<=13; i++) {
				for(int j=0; j<=13; j++) {
					pond[i][j]=0;
				}
			}
			for(int i=1; i<=12; i++) {
				tmp=sc.next();
				for(int j=1; j<=12; j++) {
					pond[i][j]=Integer.parseInt(tmp.charAt(j-1)+"");
				}
			}

			int kosu=0;		//池の個数

			for(int i=0; i<=13; i++) {
				for(int j=0; j<=13; j++) {
					if(pond[i][j]==1) {
						kosu++;
						DFS_ike(i,j);
					}
				}
			}
			System.out.println(kosu);
		}
	}

	public static void DFS_ike(int x,int y) {
		pond[x][y]=0;		//池を消す
		for(int dx=-1; dx<=1; dx++) {
			for(int dy=-1; dy<=1; dy++) {
				int nx=x+dx;
				int ny=y+dy;
				if(0<=nx && nx<13 && 0<=ny && ny<13 && pond[nx][ny]==1) {
					if(Math.abs(dx)+Math.abs(dy)==1) {
						DFS_ike(nx,ny);
					}
				}
			}
		}
	}
}





Measured memory_bytes: 26528
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
//#include "icc.h"
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,i,x,j;
multiset<int>s,st;
multiset<int>::iterator it,it1;
vector<int>vc;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=(1<<n);i++)
	{
		cin>>x;
		st.in(x);
	}
	//it=st.end();
	//it--;
	s.in(*(--st.end()));
	st.er(--st.end());
	for(i=0;i<n;i++)
	{
		vc.clear();
		for(it=s.begin();it!=s.end();it++)
		{
			it1=st.upper_bound((*it)-1);
			if(it1!=st.begin())it1--;
			else rc("No");
			if((*it1)>=(*it))rc("No");
			vc.pb(*it1);
			st.er(it1);
		}
		for(j=0;j<vc.size();j++)s.in(vc[j]);
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 13180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
template<class T> inline bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
int main(){
    ll n,k,d;cin>>n>>k>>d;
    n=abs(n);
    ll need1=n/d;
    if(k<need1){
        cout<<n-k*d<<endl;
    }else{
        ll xp=n-need1*d;
        ll xm=abs(n-(need1+1)*d);
        if(need1%2==k%2){
            cout<<xp<<endl;
        }else cout<<xm<<endl;
    }
    return 0;

}

Measured memory_bytes: 3644
N,A=gets.split.map(&:to_i)
r=N
(1..32).each{|i|
	v=(0..1<<60).bsearch{|e|i.times.reduce(1){|s,j|(e+j)/i*s}>=N}
	r=[r,A*(i-1)+v].min
}
p r

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int N, A[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];

    int num[3] = {0};
    int64_t ans = 1;
    for(int i=0; i<N; i++){
        int a = A[i];
        int c = 0;
        for(int k=0; k<3; k++) if(num[k] == a) c++;
        mul(ans, c);
        for(int k=0; k<3; k++) if(num[k] == a){
            num[k]++;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, e, n) for (int i = e; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const ll inf=1000000000007;

int main() {
  int n,m;
  cin >> n >> m;
  vector<P> a(n);
  rep(i,0,n){
    int cost, book;
    cin >> cost >> book;
    a[i].first=cost;
    a[i].second=book;
  }
  sort(a.begin(),a.end());
  ll ans=0;
  rep(i,0,n){
    if(a[i].second<m){
      ans+=(ll)a[i].first*a[i].second;
      m-=a[i].second;
    }
    else{
      ans+= (ll)a[i].first*m;
      cout << ans << endl;
      return 0;
    }
//    cout << ans << ' ' << m << endl;
  }
  return 0;
}

Measured memory_bytes: 4032
N,W = map(int,input().split())
V=10**5
dp = [[0]+[10**13]*V for _ in range(N+1)]
for i in range(N):
  w,v = map(int,input().split())
  for j in range(V+1):
    dp[i+1][j] = min(dp[i+1][j],dp[i][j])
    if dp[i][j]+w<=W:
      dp[i+1][j+v] = min(dp[i][j]+w,dp[i+1][j+v])
for i in range(V,-1,-1):
  if dp[N][i]<10**13:
    print(i)
    break


Measured memory_bytes: 137720
N, K = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

step = 0
next_to = 1
step_log = Array.new(N+1, -1)

while step_log[next_to] == -1 do
  step_log[next_to] = step
  next_to = A[next_to - 1]
  step += 1
end

starting_point_of_loop = step_log[next_to]

position_of_loop = (K - starting_point_of_loop) % (step - starting_point_of_loop)

if K < starting_point_of_loop
  p step_log.index(K)
else
  p step_log.index(starting_point_of_loop + position_of_loop)
end

Measured memory_bytes: 30124
def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        j = N-1
        while j != 0:
            if A[j] < A[j-1]:
                out = A[j-1]
                A[j-1] = A[j]
                A[j] = out
                flag = 1
                count += 1
            j -= 1
    print(' '.join(map(str, A)))
    print(str(count))
            
if __name__ == '__main__':
    N = int(input()) #1行目のNを取得する
    M = list(map(int,input().split()))
    bubbleSort(M, N)


Measured memory_bytes: 5600
n, p = map(int, input().split())

# 素因数分解
def factors_counts(n):
    facs = dict()
    while n%2 == 0:
        facs.setdefault(2, 0)
        facs[2] += 1
        n //=2

    for f in range(3, int(n**0.5)+ 1, 2):
        while n%f == 0:
            facs.setdefault(f, 0)
            facs[f] += 1
            n //= f
    if n != 1:
        facs.setdefault(n, 0)
        facs[n] += 1
    return facs

facs = factors_counts(p)

ans = 1
for f, c in facs.items():
    nn = c//n
    if nn > 0:
        ans *= (f**nn)
print(ans)


Measured memory_bytes: 63224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, A[200005];
set<pair<ll, ll>> st;
int main(){
	scanf("%lld", &N);
	for(int i = 1; i <= N; i++){
		scanf("%lld", A + i);
	}
	for(int i = 1; i <= N; i++){
		st.insert({A[i], i});
	}
	ll s = 0, ans = 0, bidx = -1;
	for(int i = 1; i <= N; i++){
		auto it = st.begin();
		ll v = it->first;
		ll idx = it->second;
		st.erase(it);
		if(bidx < idx){
			s++;
			bidx = idx;
		}
		else{
			s = 1;
			bidx = idx;
		}
		ans = max(ans, s);
	}
	printf("%lld\n", N - ans);
	return 0;
}

Measured memory_bytes: 14336
#include <stdio.h>

int main(void){
  int a, h, m, s, r;

  scanf("%d", &a);

  h=a/(60*60);
  r=a%(60*60);
  m=r/60;
  r=r%60;
  s=r;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}



Measured memory_bytes: 2064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
}

int main()
{
	int num, size;
	int *values;
	scanf("%d", &num);
	size = num * 10;
	values = (int *)malloc(size * sizeof(int));
	//memset(cnt, 0, num * sizeof(int));

	// 読み込み
	int i = 0;
	//char buff[100];
	//fgets(buff, sizeof(buff), stdin);
	//if (sscanf(buff, "%d", &num[i]) != 1)
	for (i = 0;; ++i)
	{
		if (size <= i)
		{
			void* w = malloc(size * 2 * sizeof(int));
			memcpy(w, values, size);
			free(values);
			values = (int*)w;
			size *= 2;
		}
		scanf("%d", &values[i]);
		char chr;
		chr = getchar();
		if(chr == '\n' || chr == EOF)
			break;
	}
	// 降順
	qsort(values, i+1, sizeof(int), compare);

	// 串
	int sum = 0;
	for (i = 0; i < num; ++i)
	{
		sum += values[i*2 + 1];
	}
	// 出力
	printf("%d\n", sum);
	free(values);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;

#define debug(x) cerr << #x << ": " << x << "\n";
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

int main(){
  ll n, ok=1e+18, ans=1;
  cin >> n;

  vector<ll> A(n);
  rep(i,n){
    cin >> A[i];
    if(A[i] == 0){
      cout << 0 << endl;
      return 0;
    }
    ok /= A[i];
  }
  if(ok == 0){
    cout << -1 << endl;
    return 0;
  }
  rep(i,n){
    ans *= A[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using ll = long long;
using P = pair<long long, long long>;
using MATRIX = vector< vector<ll> >;
template <class T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <class T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}

const long long MAX = 510000;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  long long N, K;
  cin >> N >> K;
  long long a[100000];
  rep(i, N) {
    cin >> a[i];
  }
  sort(a, a + N);
  long long ans = 0;
  rep(i, N-K+1) {
    ans += (a[N-1-i] * COM(N-1-i, K-1)) % MOD;
    ans %= MOD;
  }
  rep(i, N-K+1) {
    ans -= (a[i] * COM(N-1-i, K-1)) % MOD;
    if(ans < 0) ans += MOD;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

  ll n,p;
  cin>>n>>p;
  string s;
  cin>>s;
  myMap[0]=1;  // for case of remainder 0
  if(p==2||p==5)
  {
      ll ans=0;
      for(int i=0;i<s.size();i++)
      {
          ll d=s[i]-'0';
          if(d%p==0)
          {
              ans+=i+1;
          }
      }
      cout<<ans<<endl;
      return 0;
  }
 ll num=0;
 for(int i=0;i<s.size();i++)
 {
     ll d=s[i]-'0';
     num=num+(d*modPow(10,s.size()-1-i,p))%p;
     num%=p;
     myMap[num]++;
 }
 ll ans=0;
 for(int i=0;i<p;i++)
 {
     ll d=myMap[i];
     ans+=(d*(d-1))/2;
 }
 cout<<ans<<endl;
return 0;
}




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


def solve(m, bounds):
    le, ri = bounds[0]
    for i in range(1, m):
        new_le, new_ri = bounds[i]
        le = max(le, new_le)
        ri = min(ri, new_ri)
        if le > ri:
            return 0
    return ri - le + 1


def main():
    n, m = (int(z) for z in input().split())
    bounds = [tuple(int(x) for x in input().split()) for _ in range(m)]
    res = solve(m, bounds)
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 16556
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<cmath>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int re = a - b;
	int ans =max( c - a + b,0);
	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    s.append(a+b)
    ans -= b

s.sort(reverse=True)
for i in range(n):
    if i%2 == 0:
        ans += s[i]

print(ans)


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

int main() {
  int A, B, M, x, y, c;
  cin >> A >> B >> M;
  vector<int> a(A), b(B);
  int tmpa = 100000, tmpb = 100000, tmp;
  int64_t tmp2, tmp3;
  for(int i=0; i<A; i++){
    cin >> tmp;
    a.at(i) = tmp;
    if(tmp < tmpa) tmpa = tmp;
  }
  for(int i=0; i<B; i++){
    cin >> tmp;
    b.at(i) = tmp;
    if(tmp < tmpb) tmpb = tmp;
  }
  tmp2 = tmpa + tmpb;
  for(int i=0; i<M; i++){
    cin >> x >> y >> c;
    tmp3 = a.at(x-1) + b.at(y-1) - c;
    if(tmp3 < tmp2) tmp2 = tmp3;
  }
  cout << tmp2 << endl;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-6;

	int n;
	P[] ps;
	
	void run() {
		for(;;){
			n=sc.nextInt();
			if(n==0){
				break;
			}
			ps=new P[n];
			for(int i=0;i<n;i++){
				double x=sc.nextDouble();
				double y=sc.nextDouble();
				ps[i]=new P(x,y);
			}
			solve();
		}
	}

	void solve() {
		int ans=1;
		for(int j=0;j<n;j++){
			for(int i=j+1;i<n;i++){
				P p1=ps[i];
				P p2=ps[j];
				P d=p1.sub(p2);
				if(d.abs()>2+EPS){
					continue;
				}
				double v=d.abs();
				d=d.div(v);
				double t=sqrt(1-(v/2)*(v/2));
				P m=p1.add(p2).div(2);
				P c1=m.add(d.rot90().mul(t));
				P c2=m.add(d.rot90().mul(-t));
				ans=max(ans,count(c1));
				ans=max(ans,count(c2));
//				debug(c1.x,c1.y);
//				debug(c2.x,c2.y);
//				debug(count(c1),count(c2));
			}
		}
//		debug(ans);
		println(ans+"");
	}
	
	int count(P p){
		int res=0;
		for(int i=0;i<n;i++){
			if(p.sub(ps[i]).abs()<1+EPS){
				res++;
			}
		}
		return res;
	}
	
	class P{
		double x, y;
		
		P(double x,double y){
			this.x=x;
			this.y=y;
		}
		
		P add(P p){return new P(x+p.x,y+p.y);}
		P sub(P p){return new P(x-p.x,y-p.y);}
		P mul(double m){return new P(x*m,y*m);}
		P div(double d){return new P(x/d,y/d);}
		
		double abs(){ return sqrt(abs2()); }
		double abs2(){ return x*x+y*y; }
		P rot90(){ return new P(-y,x); }
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s) {
		System.out.print(s);
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] items = RIntAr();
            int antidote = items[0] + items[1];
            int canEatPoisonC = antidote+1 > items[2] ? items[2] : antidote + 1;
            Console.WriteLine(canEatPoisonC + items[1]);
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


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


def main():
    n, q = map(int, input().split())
    s = input()
    x = [0] * n
    if s[0:2] == 'AC':
        x[0] = 1
    for i in range(n - 1):
        if s[i+1:i+3] == 'AC':
            x[i+1] = x[i] + 1
        else:
            x[i+1] = x[i]

    for _ in range(q):
        li, ri = map(int, input().split())
        li -= 1
        ri -= 1
        lsum = 0 if li == 0 else x[li-1]
        rsum = x[ri-1]
        print(rsum - lsum)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7676
#include<stdio.h>
int main(){
  int c[20];
  int dp[50001];
  int min;
  int i, j;
  int n, m;
  scanf("%d %d", &n, &m);
  for( i = 0 ; i < m ; i++ ){
    scanf("%d", &c[i]);
  }
  for( i = 0 ; i < n + 1 ; i++ ){
    dp[i] = i ;
  }
  for( i = 1 ; i < m ; i++ ){
    for( j = c[i] ; j < n + 1 ; j++ ){
      min = dp[j - c[i]]+1;
      if( min < dp[j] ){
	dp[j] = min;
      }
    }
  }
  printf("%d\n",dp[n]);
  return 0;
}

Measured memory_bytes: 792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int x;

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> x;
	cout << ( x >= 30 ? "Yes" : "No" ) << "\n";	
	return 0;
}	

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
#include <tuple>
#include <initializer_list>
#include <algorithm>

template <typename T>
void scanf_univ(T& x)=delete;

template<> void scanf_univ(int& x){ std::scanf("%d", &x); }

template <typename Tuple, size_t... I>
void input_tuple_impl(Tuple& t, std::index_sequence<I...>){
  using swallow = std::initializer_list<int>;
  static_cast<void>(swallow{(static_cast<void>(scanf_univ(std::get<I>(t))), 0)...});
}

template <typename Tuple>
void input_tuple(Tuple& t){
  input_tuple_impl(t, std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>{});
}


int fill_update_skip(std::vector<int>& fill_map, const int pos){
  if(fill_map[pos] == -1) return pos;
  return fill_map[pos] =  fill_update_skip(fill_map, fill_map[pos]);
}

template <typename T>
auto fill_repeat(std::vector<T>& target, std::vector<int>& fill_map, const T& val, const int begin, const int end){
  for(int i = begin; i < end; ){
    if(fill_map[i] == -1){
      fill_map[i] = end;
      target[i] = val;
      i++;
    }else{
      i = fill_update_skip(fill_map, i);
    }
  }
}

int main(){
        int N,Q;
        std::cin >> N >> Q;
        using stop_type = std::tuple<int, int, int>;
        std::vector<stop_type> stop_arr(N);
  for(auto&& stop: stop_arr){
    input_tuple(stop);
        }
        std::vector<int> Q_arr(Q);
        for(int i = 0; i < Q; i++){
                std::cin >> Q_arr[i];
        }

        std::sort(stop_arr.begin(), stop_arr.end(), [](const stop_type& l, const stop_type& r){return std::get<2>(l) < std::get<2>(r);});

        std::vector<int> ans_arr(Q, -1);
  std::vector<int> fill_map(Q+1, -1);

        for(auto&& it: stop_arr){
                auto s = std::get<0>(it);
                auto t = std::get<1>(it);
                auto x = std::get<2>(it);
                auto q_start = std::distance(Q_arr.begin(), std::lower_bound(Q_arr.begin(), Q_arr.end(), s-x));
                auto q_stop = std::distance(Q_arr.begin(), std::lower_bound(Q_arr.begin(), Q_arr.end(), t-x));
    fill_repeat(ans_arr, fill_map, x, q_start, q_stop);
        }

        for(auto&& a: ans_arr){
                std::cout << a << "\n";
        }
        std::cout << std::endl;

        return 0;
}


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

ll modpower(ll a, ll r, ll mod){ //a^r
    ll x = 1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a, ll mod){
    return modpower(a, mod-2, mod);
}

vector<ll> fact;
vector<ll> invfact;

void set_fact(int n, ll mod){
    fact.resize(n+1, 1);
    invfact.resize(n+1, 1);
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i-1] * i % mod;
    }
    invfact[n] = modinv(fact[n], mod);
    for (int i = n-1; i >= 2; i--) {
        invfact[i] = invfact[i+1] * (i+1) % mod;
    }
    return;
}

ll comb(int n, int k, ll mod) {
    if (k > n || k < 0) return 0;
    if (k == n || k == 0) return 1;
    return fact[n] * invfact[n-k] % mod * invfact[k] % mod;
}

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    ll ans = 0;
    ll mod = 998244353;
    set_fact(N+10, mod);
    
    for (ll i = 0; i <= K; i++) {
        ll cand = M;
        cand *= comb(N-1, i, mod);
        cand %= mod;
        if (i < N-1) {
            cand *= modpower(M-1, N-1-i, mod);
            cand %= mod;
        }
        ans += cand;
    }
    cout << ans%mod << endl;
    return 0;
}

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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int w, h;
    scan(w, h);

    auto p = iota(w).map!(i => readln.chomp.to!long).array;
    auto q = iota(h).map!(i => readln.chomp.to!long).array;

    p.sort();
    q.sort();

    long r = h + 1;
    long c = w + 1;
    long ans;

    foreach (i ; 0 .. w + h) {
        if (p.empty) {
            ans += q.sum();
            break;
        }
        if (q.empty) {
            ans += p.sum();
            break;
        }
        if (p.front < q.front) {
            ans += p.front * r;
            p.popFront();
            c--;
        }
        else {
            ans += q.front * c;
            q.popFront();
            r--;
        }
        debug {
            writeln("ans: ", ans);
        }
    }

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

int fact(int n){
    int res=0;
    if (n==0) {
        return 1;
    }
    if (n>=3) {
        res+=fact(n-3);
    }
    if (n>=2) {
        res+=fact(n-2);
    }
    if (n>=1) {
        res+=fact(n-1);
    }
    return res;
}

int main(){
    int i;
    while (cin>>i,i) {
        int a=0;
        a+=fact(i);
        int day=a/10;
        cout<<day/365+1<<endl;
    }
}

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main(void)
{
	char str[20];
	int len,i;
	scanf("%s",str);
	len=strlen(str);
	for(i=len-1;i>=0;i--){
		printf("%c",str[i]);
	}
	printf("\n");
	return 0;
}
		
	

Measured memory_bytes: 932
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,a,b,x,y,flag;
	cin>>n;
	x=0,y=n;
	while(y)
	{
		x+=y%10;
		y/=10;
	}
	flag=n%x;
	if(flag==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll H,W;
    string S;
    cin >> H>>W;
    char a[H][W];
    REP(i,H){
        REP(j,W){
            cin >> a[i][j];
        }
    }

    map<char, int> M;
    REP(i, H)
    {
        REP(j, W)
        {
            M[a[i][j]]++;
        }
    }

    ll n1=0, n2=0, n3=0;

    for (int i = 0; i <= ('z' - 'a'); i++)
    {
        char tmp=(char)('a' + i);
        //cout << tmp << endl;
        ll tmp1 = M[tmp] % 4;
        //cout << tmp1 << endl;
        if (tmp1 == 1)
        {
            n1++;
        }
        else if(tmp1==2){
            n2++;
        }
        else if(tmp1==3){
            n3++;
        }
    }

    //cout << n2 << endl;

    if(H%2==0&&W%2==0){
        if(n1==0&&n2==0&&n3==0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if (H % 2 == 0 && W % 2 == 1){
        ll tmp2 = H / 2;
        if (n1 == 0 && n3 == 0&&n2<=tmp2)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else if (W % 2 == 0 && H % 2 == 1)
    {
        ll tmp2 = W / 2;
        if (n1 == 0 && n3 == 0 && n2 <= tmp2)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else{
        ll tmp3 = ((H - 1) + (W - 1))/2;
        if(n1+n3>=2){
            cout << "No" << endl;
        }
        else if(n1+n3==0){
            cout << "No" << endl;
        }
        else if(n1==1&&n3==0){
            if(n2<=tmp3){
                cout << "Yes" << endl;
            }
            else{
                cout << "No" << endl;
            }
        }
        else{
            if (n2 <= tmp3-1)
            {
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
        }
    }
}


Measured memory_bytes: 3672