akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

int a, b, c, d;
string s, instr;

int main() {
  cin >> instr;
  int a = instr[0] - '0';
  int b = instr[1] - '0';
  int c = instr[2] - '0';
  int d = instr[3] - '0';
  for (int op1 = -1; op1 <= 1; op1=op1+2) {
    for (int op2 = -1; op2 <= 1; op2=op2+2) {
      for (int op3 = -1; op3 <= 1; op3=op3+2) {
        if (a + op1 * b + op2 * c + op3 * d == 7) {
          s.push_back(a+'0');
          s.push_back(op1 == 1 ? '+' : '-');
          s.push_back(b+'0');
          s.push_back(op2 == 1 ? '+' : '-');
          s.push_back(c+'0');
          s.push_back(op3 == 1 ? '+' : '-');
          s.push_back(d+'0');
          s = s + "=7";
          goto loopend;
        }
      }
    }
  }
  loopend:
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#define ll long long int
#define mod 1000000007

using namespace std;

int n;
ll a[200009],s[200009];

int main()
{
    ///freopen("INA.txt","r",stdin);
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>> n;
    ll sum=0,ans=0;
    for(int i=1;i<=n;i++){
        cin>> a[i];
        sum+=a[i];
    }

    for(int i=1;i<n;i++){
        sum -= a[i];
        s[i] = sum;
    }
    for(int i=1;i<n;i++){
        ans += ((s[i]%mod)*a[i])%mod;
    }
    cout<< ans%mod << endl;

    return 0;
}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if(s == "AAA" || s == "BBB") cout << "No" << endl;
  else cout << "Yes" << endl;
}


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

#define endl '\n'
#define all(x) (x).begin(),(x).end()

namespace atcoder {
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T e){
		v.push_back(e);
		return v;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	void inline init(){
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}

using namespace atcoder;

int main(){
	init();

	int k;cin>>k;
	ll ans=0;
	for(int i=1;i<=k;i++)
	for(int j=1;j<=k;j++)
	for(int z=1;z<=k;z++)
	ans+=gcd(gcd(i,j),z);
	cout <<ans<<endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll odd(ll a){
    return (a+1)/2 % 2;
}
ll solve(ll a){
    if(a % 2 == 1) return odd(a);
    else return odd(a+1)^(a+1);
}
int main() {
    ll a,b;
    cin >> a >> b;
    cout << (solve(b)^solve(a-1)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    vector<ll> dp(1LL<<n,0);
    vector<vector<ll>> a(n,vector<ll>(n));
    for(auto &i:a){
        for(auto &t:i){cin>>t;}
    }
    for(ll i=0;i<1LL<<n;i++){
        for(ll t=0;t<n;t++){
            if((i>>t&1)==0){continue;}
            for(ll h=t+1;h<n;h++){
                if((i>>h&1)==0){continue;}
                dp[i]+=a[t][h];
            }
        }
    }
    for(ll i=1;i<1LL<<n;i++){
        for(ll k=i;k>0;k=(k-1)&i){
            dp[i]=max(dp[i],dp[k]+dp[i^k]);
        }
    }
    cout<<dp.back()<<endl;
    
    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
int main(){
	char s[100001];
	int k, i, len, need;
	scanf("%s %d", s, &k);
	len=strlen(s);

	for(i=0; i<len; i++){
		need=97+26-s[i];
		if(s[i]=='a' || k<need) continue;
		else{
			s[i]='a';
			k=k-need;
		}
	}
	if(k>0){
		s[i-1]=s[i-1]+(k%26);
	} 
	printf("%s", s);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <utility>

using namespace std;


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

  vector<pair<int, bool>> box_info(n, pair<int, bool> {1, false});
  box_info[0] = {1, true};

  for (int i = 0; i < m; i++) {
    int from, to;
    cin >> from >> to;
    from--, to--;
    
    box_info[to].first++;
    box_info[to].second |= box_info[from].second;

    if (box_info[from].first == 1) {
      box_info[from] = {0, false};
    } else {
      box_info[from].first--; 
    }
  }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    ans += box_info[i].second;
  }

  cout << ans << endl;
  return 0;
}

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

using namespace std; 

using ll = long long;

const int N = 1000005, INF = 1000000005;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ans = 0;
    for(int i = 1; i <= 5; i++){
        int v;  cin >> v;
        if(v == 0)
            ans = i;
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 3172
import sys
n=int(input())
g=[[] for _ in range(n)]
for i in range(n-1):
  a,b=map(int,sys.stdin.readline().split())
  g[a-1].append([b-1,i])
  g[b-1].append([a-1,i])
print(max(len(v) for v in g))
from collections import deque
l=[0]*(n-1)
q=deque([0])
b=[1]+[0]*(n-1)
while q:
  v=q.pop()
  c=-1
  k=1
  for u,e in g[v]:
    if b[u]: c=l[e]
  for u,e in g[v]:
    if b[u]: continue
    if k==c: k+=1
    l[e]=k
    k+=1
    q.appendleft(u)
    b[u]=1
for c in l: print(c)

Measured memory_bytes: 46360
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
typedef long long ll; 


int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int res = 0;
    for(int i = 0; i <= a; ++ i) {
        for(int j = 0; j <= b; ++ j) {
            for(int k = 0; k <= c; ++ k) {
                int ans = i*500+j*100+k*50;
                if(ans == x) res ++;
            }
        }
    }
    cout << res << endl;
    return 0;
}


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

vector<long long> a;
vector<vector<long long>> memo;
vector<vector<long long>> memoeven;


int main() {
  long long mod = 998244353;
  long long N, ans=0, sum=0; cin >> N;
  long long ttl=3;
  a = vector<long long>(N);
  for (int i=0; i<N; i++) {cin >> a[i]; sum+=a[i];}
  memo = vector<vector<long long>>(N+1, vector<long long>(sum+1, 0));
  memo[0][0]=1;
  memoeven = vector<vector<long long>>(N+1, vector<long long>(sum+1, 0));
  memoeven[0][0]=1;
  
  for (int i=0; i<N-1; i++) ttl = (ttl*3)%mod;
  
  for (int i=0; i<=N; i++) {
    for (int j=0; j<=sum; j++) {
      if (i==0&&j==0) continue;
      else if (i==0) memo[i][j]=0;
      else if (j-a[i-1]<0) memo[i][j]=(memo[i-1][j]*2)%mod;
      else memo[i][j] = (memo[i-1][j]*2+memo[i-1][j-a[i-1]])%mod;
    }
  }
  for (int j=(sum-1)/2+1; j<=sum; j++) ans +=memo[N][j]; 
  if (sum%2==0) {
    for (int i=0; i<=N; i++) {
      for (int j=0; j<=sum; j++) {
        if (i==0&&j==0) continue;
        else if (i==0) memoeven[i][j]=0;
        else if (j-a[i-1]<0) memoeven[i][j]=memoeven[i-1][j]%mod;
        else memoeven[i][j] = (memoeven[i-1][j]+memoeven[i-1][j-a[i-1]])%mod;
      }
    }
    ans -= memoeven[N][sum/2];
  }
cout << ((ttl - ans*3)%mod+mod)%mod << "\n"; 
}

Measured memory_bytes: 423744
import std.stdio, std.string, std.conv;
import std.algorithm;

void main() {
	auto input = getStdin!(string[]);
	string needle = input[0].toLower;
	string[] haystack = input[1..$-1].join(" ").replace(".", "").replace(",", "").toLower.split(" ");

	auto count = haystack.count(needle);
	count.writeln;
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

Measured memory_bytes: 2516
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

class UnionFind {
    struct UFNode {
        int par;
        int rank;
        LL cnt;
    };
public:
    vector<UFNode> nodes;
    UnionFind(int n): nodes(n) {
        for (int i = 0; i < n; i++) {
            nodes[i].par = i;
            nodes[i].rank = 0;
            nodes[i].cnt = 1;
        }
    };
    int root(int x) {
        return nodes[x].par == x ? x : root(nodes[x].par);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (nodes[x].rank < nodes[y].rank) {
            nodes[x].par = y;
            nodes[y].cnt += nodes[x].cnt;
        } else {
            nodes[y].par = x;
            nodes[x].cnt += nodes[y].cnt;
            if (nodes[x].rank == nodes[y].rank) nodes[x].rank++;
        }
    }
    //~UnionFind() {cout << nodes.size() << endl;}
};

void solve() {
    LL n,m;
    cin >> n >> m;
    VI a(m), b(m);
    REP(i,0,m) cin >> a[i] >> b[i];
    LL sum = n * (n-1) / 2;
    VLL ans(m);
    UnionFind uf(n);
    RREP(i,0,m) {
        --a[i];--b[i];
        if (uf.same(a[i],b[i])) ans[i] = ans[i+1];
        else {
            LL add = uf.nodes[uf.root(a[i])].cnt * uf.nodes[uf.root(b[i])].cnt;
            ans[i] = (i == m - 1 ? 0LL : ans[i+1]) + add;
            uf.unite(a[i], b[i]);
        }
    }
    REP(i,1,m) cout << sum - ans[i] << endl;
    cout << sum << endl;
}

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

Measured memory_bytes: 4480
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using pii = std::pair<int, int>;
using namespace std;

int main() {
  ll X, Y;
  cin >> X >> Y;
  set<ll> A;
  A.emplace(X);
  ll ns = X;
  for (ll i = X; i <= Y; i += ns) {
    if (i % ns == 0 && A.count(i) == 0) {
      A.emplace(i);
      ns = i;
    } 
  }
  cout << A.size() << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

template<class T>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation for query
     * @param updater operation for update
     */
    SegmentTree(size_t N, T e, function<T(T, T)> operation, function<T(T, T)> updater)
            : e(e), operation(std::move(operation)), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, e);
    }

    /**
     * iの値をxに更新
     * @param i index ( 0-indexed )
     * @param x  value
     */
    void update(int i, T x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス
     * @param i index ( 0-indexed )
     */
    T operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<T> data;
    T e;
    function<T(T, T)> operation;
    function<T(T, T)> updater;

    T query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        T c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        T c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};

void Main() {
    int N;
    cin >> N;
    vector<ll> H(N), A(N);
    rep(i, N) cin >> H[i];
    rep(i, N) cin >> A[i];

    vector<ll> dp(N + 1, 0);
    SegmentTree<ll> segmentTree(N + 1, 0, [](ll a, ll b) { return max(a, b); }, [](ll a, ll b) { return max(a, b); });

    rep(i, N) {
        ll h = H[i];
        ll a = A[i];
        ll x = segmentTree.query(0, h);
        dp[h] = x + a;
        segmentTree.update(h, dp[h]);
    }
    cout << segmentTree.query(0, N + 1) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<6-a-b;
    return 0;
}

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

int main(){
  int i,j,n,A[N],minj,st,co=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<n;i++){
    minj = i;
    
    for(j=i;j<n;j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    if(A[i]!=A[minj]) co += 1;
    st = A[minj];
    A[minj] = A[i];
    A[i] = st;
  }
  for(i=0;i<n;i++){
    if(i != n-1) printf("%d ",A[i]);
    else printf("%d\n",A[i]);
  }
  printf("%d\n",co);
  return 0;
}



Measured memory_bytes: 2104
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[100010][110][2];

int main(){
  string s; cin >> s;
  int n=s.size();
  int D; cin >> D;
  dp[0][0][0]=1;
  rep(i,n){
    rep(j,D){
      rep(k,2){
        int ni=i+1;
        //ここに置くミス
        rep(d,10){
          int nk=k;//これを↑
          if(k==0){
            if(d>int(s[i]-'0')) continue;
            if(d<int(s[i]-'0')) nk=1;
          }
          int nj=(j+d%D)%D;
          dp[ni][nj][nk]+=dp[i][j][k];
          dp[ni][nj][nk]%=mod;
        }
      }
    }
  }
  ll ans=(dp[n][0][0]+dp[n][0][1])%mod;
  ans--;
  if(ans<0) ans+=mod;
  cout << ans << endl;
}

Measured memory_bytes: 18816
#include <iostream>
using namespace std;
int main(){
	int a,b,x;
	while(1){
		cin >> a >> b;
		if (a == 0 && b == 0)break;
		if (a > b)
		{
			x = a;
			a = b;
			b = x;
		}
		cout << a << " " << b << endl;
	}
}


Measured memory_bytes: 3048
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    ll l, q;
    cin >> l >> q;
    vl a(q), b(q);
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        if (a[i] > b[i])
            swap(a[i], b[i]);
    }
    vvl dbl(n, vl(20));
    for (int i = 0; i < n; ++i) {
        dbl[i][0] = upper_bound(x.begin(), x.end(), x[i] + l) - x.begin() - 1;
    }
    for (int j = 1; j < 20; ++j) {
        for (int i = 0; i < n; ++i) {
            dbl[i][j] = dbl[dbl[i][j - 1]][j - 1];
        }
    }
    for (int i = 0; i < q; ++i) {
        auto check = [&](ll mid) {
            int s = a[i];
            int k = 0;
            while (mid) {
                if (mid & 1)
                    s = dbl[s][k];
                k++;
                mid >>= 1;
            }
            return b[i] <= s;
        };
        ll ok = n;
        ll ng = 0;
        while (abs(ok - ng) != 1) {
            ll mid = (ng + ok) / 2;
            if (check(mid))
                ok = mid;
            else
                ng = mid;
        }
        cout << ok << "\n";
    }
    return 0;
}

Measured memory_bytes: 22656
D,N=map(int,input().split())
if D==0:
    if N==100:
        print(101)
    else:
        print(N)
if D==1:
    if N==100:
        print(10100)
    else:
        print(100*N)
if D==2:
    if N==100:
        print(1010000)
    else:
        print(10000*N)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,ans;
int main()
{
	cin>>n;
	for(int i=1;i<n;++i)
	{
		int k=n/i;
		if(n%i==0) --k;
		ans+=k;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3628
n = int(input())
s = str(input())
m = 0
w = []
for j in s:
    w.append(j)
w = list(set(w))
for i in range(1,n):
    t = 0
    for h in w:
        if 1 <= s[:i].count(h) and 1 <= s[i:].count(h):
            t += 1
    if m < t:
        m = t
print(m)

Measured memory_bytes: 9168
#include<iostream>
#include<string>
#include<vector>

int main(){
    int n;
    std::string s;
    
    std::cin >> n >> s;

    for(int i = 0; i < s.size(); i++){
        s.at(i) += n;
        if(s .at(i) > 90){
            s.at(i) = s.at(i) - 26;
        }
    }
   
    std::cout << s << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
lis = [] #市i県ｐ誕生y
ID = [0 for _ in range(m)]
cnt = [0 for _ in range(n)]

for i in range(m):
    p,y = map(int,input().split())
    lis.append([i,p,y])
lis = sorted(lis,key = lambda x:x[2])
for i in range(m):
    cnt[lis[i][1]-1] += 1 #県pで何番目に誕生したか
    up = "0" * (6 - len(str(lis[i][1]))) + str(lis[i][1])
    under = "0" * (6 - len(str(cnt[lis[i][1]-1]))) + str(cnt[lis[i][1]-1])
    ID[lis[i][0]] = up + under
for i in range(m):
    print(ID[i])

Measured memory_bytes: 32184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,k;cin>>n>>k;
    set<int> a;
    for (int i = 0; i < k; i++) {
        int b;cin>>b;
        for (int j = 0; j < b; j++) {
            int f;cin>>f;
            a.insert(f);
        }
    }
    cout<<n-a.size()<<endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979323846

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; }




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}

template<typename T>
ll com(T n, T m, T mod){
  ll a = 1, b = 1, ans;
  if(n == m || m == 0){
    ans = 1;
  }else{
    for(ll i = 0;i < m; i++){
      a *= n-i;
      a %= mod;
      b *= i+1;
      b %= mod;
    }
    ans = (a * powmod(b, mod-2, mod)) % mod;
  }
  
  return ans;
}



 
int main() {
  ll N;

  cin >> N;

  vector<ll> A(N);

  rep(i, 0, N){
    ll Ai;
    cin >> Ai;

    if(Ai == 0){
      cout << 0 << endl;
      return 0;
    }
    A[i] = Ai;
    
  }
  ll ans = 1;
  rep(i, 0, N){
    ll check = (ll)1e18 / ans;
    if(check < A[i]){
      cout << -1 << endl;
      return 0;
    }
    ans *= A[i];
  }

  cout << ans << endl;

}



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

inline void hash(){}

const int N=101009,p=998244353,inv2=p+1>>1;
char A[N],B[N],C[N],D[N];
int fac[N<<2],inv[N<<2];
int n,m,ans;

inline int qpow(int A,int B){
	int res(1);while(B){
		if(B&1)res=(ll)res*A%p;
		A=(ll)A*A%p,B>>=1;
	}return res;
}

inline int Com(int nn,int mm){return (ll)fac[nn]*inv[mm]%p*inv[nn-mm]%p;}
void prework(int A){
	fac[0]=inv[0]=1;
	for(int i=1;i<=A;++i)fac[i]=(ll)fac[i-1]*i%p;
	inv[A]=qpow(fac[A],p-2);
	for(int i=A-1;i;--i)inv[i]=(ll)inv[i+1]*(i+1)%p;
}

void work(){
	int left=0,right=0,l=0,r=0,pre=1,val;
	for(int i=1;i<=n;++i)left+=A[i]-'0',right+=B[i]-'0';
	for(int i=m;i;--i)r+=C[i]-'0'+D[i]-'0';
	for(int i=1;i<=m;i++){
		l+=C[i]-'0'+D[i]-'0';
		r-=C[i]-'0'+D[i]-'0';
		if(C[i]=='0' and D[i]=='0')continue;
		if(C[i]=='1' and D[i]=='1')pre=2ll*pre%p;
		if(right)val=Com(right+r-1,r);
		else val=(!r);ans=(ans+(ll)pre*val)%p;
		if(left)val=Com(left+l-1,l);
		else val=(!l);pre=(pre+val)%p;
	}
}

int main(){
	scanf("%d%d",&n,&m);
	prework(n+m+n+m);
	scanf("%s%s",A+1,B+1);
	scanf("%s%s",C+1,D+1);
	bool died=true;
	for(int i=1;i<=n;++i)
		if(A[i]=='1' or B[i]=='1' or C[i]=='1' or D[i]=='1')
			{died=false;break;}
	if(died){puts("1");return 0;}
	work();swap(n,m);swap(A,C);
	swap(B,D);swap(C,D);work();
	printf("%d\n",ans);return 0;
}

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

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

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[])
{
    int a,b;
    cin >> a >> b;
    if (a >= 13)
        cout << b << endl;
    else if (a >= 6)
        cout << b/2 << endl;
    else
        cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
N,X,Y = map(int,input().split())
ans = [0 for i in range(N-1)]
for i in range(1,N):
    for j in range(i+1,N+1):
        mina = min(j-i, abs(X-i)+1+abs(Y-j), abs(Y-i)+1+abs(X-j))
        ans[mina-1] += 1
for i in ans:
    print(i)

Measured memory_bytes: 3444
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
int n,m;
int mod = 1e9+7;
int a[100001];
int dp[100001];
int add(int a,int b)
{
    return ((a%mod)+(b%mod))%mod;
}
int mul(int a,int b)
{
    return ((a%mod)*(b%mod))%mod;
}
int solve(int idx)
{
    if(idx == n)
        return 1;
    if(idx > n)
        return 0;
    if(a[idx] == 1)
        return 0;
    if(dp[idx]!=-1)
        return dp[idx];
    int ans = 0;
    ans = solve(idx+1);
    ans = add(ans,solve(idx+2));
    dp[idx] = ans;
    return ans;
}
signed main() 
{
    fast;
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int x;
        cin>>x;
        a[x] = 1;
    }
    cout<<solve(0);
    return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr first
#define sc second
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=3e5+10;
int y[100009];
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int r,l;
    for (int i=0;i<x;i++)
    {
        cin>>r>>l;
        for (int j=r;j<=l;j++)
            y[j]=1;
    }
    int c=0;
    for (int i=1;i<=100000;i++){
        if (y[i])
            c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 640
N=int(input())
E=[tuple(sorted(map(int,input().split()))) for i in range(N-1)]

DICT={x:ind for ind,x in enumerate(E)}

EDGE=[[] for i in range(N+1)]
for x,y in E:
    EDGE[x].append(y)
    EDGE[y].append(x)


M=int(input())
Q=[tuple(map(int,input().split())) for i in range(M)]

def dfs(x,y):
    USE=[-1]*(N+1)
    USE[x]=0

    NOW=[x]

    while NOW:
        n=NOW.pop()

        for to in EDGE[n]:
            if USE[to]==-1:
                USE[to]=n
                NOW.append(to)

    ANS=[y]
    while y!=x:
        y=USE[y]
        ANS.append(y)

    RET=[]

    for i in range(1,len(ANS)):
        RET.append(DICT[tuple(sorted([ANS[i-1],ANS[i]]))])

    return set(RET)

Q2=[dfs(x,y) for x,y in Q]

DP=[0]*(1<<M)
DP[0]=1

for i in range(N-1):
    B=0
    for k in range(M):
        if i in Q2[k]:
            B+=1<<k
        
    for j in range((1<<M)-1,-1,-1):
        DP[j|B]+=DP[j]

print(DP[-1])
        
    


Measured memory_bytes: 48876
use std::io::*;
use std::cmp;
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn search(dist:&Vec<Vec<usize>>,rs:&Vec<usize>,n:usize,rest:&mut HashSet<usize>,d:usize,min:&mut usize) {
    if rest.is_empty() {
        *min = cmp::min(*min,d);
    }else{
        for &v in rest.clone().iter() {
            let d_t = d + dist[rs[n]-1][rs[v]-1];
            if d_t >= *min {
                continue;
            }
            rest.remove(&v);
            search(dist,rs,v,rest,d_t,min);
            rest.insert(v);
        }
    }
}

fn main() {
    let v = read_vec::<usize>();
    let (n,m,r) = (v[0],v[1],v[2]);
    let rs = read_vec::<usize>();
    let mut path = vec![vec![1<<30;n];n];
    for _i in 0..m {
        let v = read_vec::<usize>();
        path[v[0]-1][v[1]-1] = v[2];
        path[v[1]-1][v[0]-1] = v[2];
    }
    for i in 0..n {
        for j in 0..n {
            for k in 0..n {
                path[j][k] = cmp::min(path[j][k],path[j][i]+path[i][k]);
            }
        }
    }
    let mut min: usize = 1<<30;
    let all: HashSet<usize> = (0..r).collect();
    for i in 0..r-1 {
        let mut rest = all.clone();
        rest.remove(&i);
        search(&path,&rs,i,&mut rest,0,&mut min);
    }
    println!("{}",min);
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

double a,b,x,ans;

int main(void){
	cin>>a>>b>>x;
	if(a*a*b/2<x){
		cout<<fixed<<setprecision(15)<<atan2((a*b-x/a)*2/a/a,1.0)/M_PI*180<<endl;
	}else{
		cout<<fixed<<setprecision(15)<<90-atan2(2*x/(a*b*b),1.0)/M_PI*180<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;

ll fac[300001],ifac[300001];

ll mpow(ll x,ll n){
    ll res = 1;
    while(n != 0){
        if(n&1) res = res*x % mod;
        x = x*x % mod;
        n = n >> 1; 
    }
    return res;
}
ll comb(ll a,ll b){
    if(a==0 && b==0) return 1;
    if(a<b || a<0) return 0;
    ll tmp = ifac[a-b]*ifac[b] % mod;
    return tmp*fac[a] % mod;
}

int main(){
    ll n,a,b,k,ans=0;
    cin >> n >> a >> b >> k;

    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0;i < 300000;i ++){
        fac[i+1] = fac[i]*(i+1) % mod;
        ifac[i+1] = ifac[i]*mpow(i+1,mod-2) % mod;
    }

    for(int x = 0;x <= n;x ++){
        ll y;
        if((k-a*x)%b==0) y = (k-a*x)/b;
        else continue;
        if(x<0||y<0) continue;
        ans += comb(n,x)*comb(n,y);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

const int N = 50;
typedef long long ll;
typedef std::pair <std::string, std::string> pss;

char s[N];
std::map <pss, ll> Hash[N];

int main(){
    int n;
    scanf("%d%s", &n, s + 1);
    Hash[0][{"", ""}] = 1;
    for (int i = 1; i <= n << 1; ++ i){
        for (auto &u : Hash[i - 1]){
            auto &s1 = u.first.first;
            auto &s2 = u.first.second;
            if (s1.size() < n && (s1.size() + s2.size() < n || s2[n - s1.size() - 1] == s[i])){
                Hash[i][{s1 + s[i], s2}] += u.second;
            }
            if (s2.size() < n && (s1.size() + s2.size() < n || s1[n - s2.size() - 1] == s[i])){
                Hash[i][{s1, s2 + s[i]}] += u.second;
            }
        }
    }
    ll ans = 0;
    for (auto u : Hash[n << 1]){
        ans += u.second;
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main(){
  int n,k; cin>>n>>k;
  vector<int> num(n);
  for(int i=0;i<n;i++){
    cin>>num[i];
  }int ans=1000000000;
  for(int i=0;i<=n-k;i++){
    int x=num[i];
    int y=num[i+k-1];
    ans=min(ans,min(abs(x),abs(y))+y-x);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1 = 1e9;
const long long I2 = 1e18;

template<typename T, typename T1>T maxn(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T minn(T &a, T1 b) {if (b < a)a = b; return a;}
bool isPrime(int n)
{
    if (n <= 1) return false;
    if (n <= 3) return true;

    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}


int main() {
//#ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
//#endif
    ll n, i, j, k;
    cin >> n >> k;
    ll a[n];
    lop(i, n)
    cin >> a[i];
    ll ans[n];
    ans[0] = 0;
    for (i = 1; i < n; i++) {
        ans[i] = I1;
        for (j = i - 1; j >= 0 && i - j <= k; j--) {
            ll val = ans[j] + abs(a[i] - a[j]);
            ans[i] = min(ans[i], val);
        }

    }
    cout << ans[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 5192
// Segment tree
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type segmentTree struct {
	data   []int
	offset int
}

func newSegmentTree(n int) segmentTree {
	var result segmentTree
	t := 1
	for t < n {
		t *= 2
	}
	result.offset = t - 1
	result.data = make([]int, 2*t-1)
	return result
}

func (st segmentTree) updateAll(a []int) {
	for i, v := range a {
		st.data[st.offset+i] = 1 << uint(v)
	}
	for i := st.offset - 1; i > -1; i-- {
		st.data[i] = st.data[i*2+1] | st.data[i*2+2]
	}
}

func (st segmentTree) update(index, value int) {
	i := st.offset + index
	st.data[i] = 1 << uint(value)
	for i >= 1 {
		i = (i - 1) / 2
		st.data[i] = st.data[i*2+1] | st.data[i*2+2]
	}
}

func (st segmentTree) query(start, stop int) int {
	result := 0
	l := start + st.offset
	r := stop + st.offset
	for l < r {
		if l&1 == 0 {
			result = result | st.data[l]
		}
		if r&1 == 0 {
			result = result | st.data[r-1]
		}
		l = l / 2
		r = (r - 1) / 2
	}
	return result
}

func toInt(s string) int {
	result, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return result
}

func bitCount(a int) int {
	result := 0
	for a != 0 {
		if a&1 == 1 {
			result++
		}
		a >>= 1
	}
	return result
}

func main() {
	defer flush()

	N := readInt()
	S := readString()

	t := make([]int, len(S))
	for i, v := range []byte(S) {
		t[i] = int(v - 'a')
	}

	st := newSegmentTree(N)
	st.updateAll(t)

	Q := readInt()
	for i := 0; i < Q; i++ {
		t := readString()
		if t == "1" {
			i := toInt(readString()) - 1
			c := int([]byte(readString())[0] - 'a')
			st.update(i, c)
		} else if t == "2" {
			l := toInt(readString())
			r := toInt(readString())
			println(bitCount(st.query(l-1, r)))
		}
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func readInts(n int) []int {
	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = readInt()
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdoutWriter, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


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

int main(){
	long long int n,a,b,c,d;
	cin>>n>>c>>d;
	if(c==0){
		cout<<c<<endl;
		return 0;
	}
	a=c+d;
	b=n/a;
	d=b*c;
	n=n-(b*a);
	if(n>c){
		n=d+c;
		cout<<n<<endl;
		return 0;
	}
	n=n+d;
	
	
	
		cout<<n<<endl;
	}



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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=1024;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

map<i64,i32> M;
i64 Value[512];

inline void pre(){
    f(i,-200,I,200){
        Value[i+200]=i*i*i;
        Value[i+200]*=i*i;
        M[Value[i+200]]=i;
    }
}

int main(){
    pre();
    i64 X=read();
    f(i,-200,I,200)
        if(M.find(X+Value[i+200])!=M.end()){
            print(M[X+Value[i+200]]);
            print(' ');
            print(i);
            break;
        }
    output();
    return 0;
}

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

using namespace std;

const int N = 100005;
int dp[N][3], a[N][3], n;

int cal(int i, int col) {
	if (i == n) {
		return 0;
	}
	int &ret = dp[i][col];
	if (ret > -2e9) {
		return ret;
	}
	for (int j = 1; j <= 3; j++) {
		if (col == j) continue;
		ret = max(ret, cal(i+1, j) + a[i][j]);
	}
	return ret;
}

int main() {
	scanf("%d", &n);
	dp[0][0] = -2e9;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			scanf("%d", &a[i][j]);
			dp[i][j] = -2e9;
		}
	}
	printf("%d", cal(0, 0));
	return 0;
}

/*
3
10 40 70
20 50 80
30 60 90
*/
/*
1
100 10 1
*/
/*
7
6 7 8
8 8 3
2 5 2
7 8 6
4 6 8
2 3 4
7 5 1
*/


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define ten(n) ((int)1e##n)
#define fst first
#define snd second
using ll=long long;
using pii=pair<int,int>;using pll=pair<ll,ll>;using pil=pair<int,ll>;using pli=pair<ll,int>;
using vs=vector<string>;using vvs=vector<vs>;using vvvs=vector<vvs>;
using vb=vector<bool>;using vvb=vector<vb>;using vvvb=vector<vvb>;
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 vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<class T> bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
ll ri(){ll l;cin>>l;return l;} string rs(){string s;cin>>s;return s;}
template<class T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<'('<<p.fst<<", "<<p.snd<<')';}
ostream&operator<<(ostream&o,const vb&t){forr(e,t)o<<"#."[e];return o;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&t){o<<"{";forr(e,t)o<<e<<",";o<<"}"<<endl;return o;}
#ifdef LOCAL
vs s_p_l_i_t(const string&s,char c){vs v;stringstream ss(s);string x;while(getline(ss,x,c))v.emplace_back(x);return move(v);}
void e_r_r(vs::iterator it){cerr<<endl;}
template<class T,class... Args>void e_r_r(vs::iterator it,T a,Args... args){cerr<<it->substr((*it)[0]==' ',it->length())<<" = "<<a<<", ";e_r_r(++it,args...);}
#define out(args...){vs a_r_g_s=s_p_l_i_t(#args,',');e_r_r(a_r_g_s.begin(),args);}
#else
#define out(args...)
#endif

void panic() {
  cout << "inf" << endl;
  exit(0);
}

ll solve() {
  int n = ri();
  int m = ri();

  vvpii E(n);
  rep(i, m) {
    int u = ri() - 1;
    int v = ri() - 1;
    ll w = -ri();
    E[u].emplace_back(v, w);
  }

  const ll inf = 1e18;
  vl D(n, inf);
  D[0] = 0;

  rep(i, n) {
    rep(u, n) {
      forr(vw, E[u]) {
        amin(D[vw.fst], D[u] + vw.snd);
      }
    }
  }

  /*
  rep(u, n) {
    forr(vw, E[u]) {
      if (D[vw.fst] > D[u] + vw.snd) {
        // 負閉路検出
      }
    }
  }
  */

  ll dd = D[n-1];

  rep(i, n) {
    rep(u, n) {
      forr(vw, E[u]) {
        amin(D[vw.fst], D[u] + vw.snd);
      }
    }
  }

  ll dd2 = D[n-1];
  if (dd != dd2) panic();

  return -D[n-1];
}

void Main() {
  cout << solve() << endl;
}

int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 384
fn main() {
    let s = read_line();
    let xyz_vec = read_num_vec(s, 3);
    let x = xyz_vec.get(0).unwrap();
    let y = xyz_vec.get(1).unwrap();
    let z = xyz_vec.get(2).unwrap();

    println!("{} {} {}", z, x, y);
}

// 1 2 3    2 1 3    3 1 2
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn read_num_vec(s: String, length: usize) -> Vec<i64> {
    let mut ws = s.split_whitespace();
    let mut result = vec![];
    for _ in 0..length {
        result.push(ws.next().unwrap().parse().unwrap());
    }
    result
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;


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

  int r,g; cin>>r>>g;
  cout << 2 * g - r << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	a := n % k
	a = min(a, abs(a-k))
	fmt.Println(a)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  vector<int> sugar;
  for (int i = 0; i <= 3000 ; i++) {
    for (int j = 0; j <= 3000; j++) {
      int sums = i * c + j * d;
      if (sums <= f) {
        sugar.push_back(sums);
      }
    }
  }

  vector<int> water;
  for (int i = 0; i <= 30; i++) {
    for (int j = 0; j <= 30; j++) {
      int sumw = i * a * 100 + j * b * 100;
      if (sumw <= f) {
        water.push_back(sumw);
      }
    }
  }

  double limit = (double)e / (100 + e);
  double n = -1;
  int ans1 = 0, ans2 = 0;
  for (int s : sugar) {
    for (int w : water) {
      int sw = s + w;
      if (sw == 0) continue;
      double x = (double)s / sw;
      if (sw <= f && x <= limit && x > n) {
        n = x;
        ans1 = sw;
        ans2 = s;
      }
    }
  }
  cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 1400