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

string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

template <class T, class Op, class Inv> struct weighted_dsu {
  const Op op;
  const T e;
  const Inv inv;
  vector<int> p, sz;
  vector<T> d;
  weighted_dsu(int n, Op _op, T _e, Inv _inv) :
    op(_op), e(_e), inv(_inv), p(n, -1), sz(n, 1), d(n, e) {}
  pair<int, T> root(int v) const {
    T a = e;
    while (p[v] != -1) a = op(a, d[v]), v = p[v];
    return {v, a};
  }
  void unite(int u, int v, T w) {
    T du, dv;
    tie(u, du) = root(u), tie(v, dv) = root(v);
    assert(u != v);
    if (sz[u] < sz[v]) swap(u, v), swap(du, dv), w = inv(w);
    p[v] = u;
    sz[u] += sz[v];
    d[v] = op(op(du, w), inv(dv));
  }
  T diff(int u, int v) const {
    T du, dv;
    tie(u, du) = root(u), tie(v, dv) = root(v);
    assert(u == v);
    return op(dv, inv(du));
  }
  bool same(int u, int v) const { return root(u).first == root(v).first; }
  int size(int v) const { return sz[root(v).first]; }
};
template <class T, class Op, class Inv>
auto make_weighted_dsu(int n, Op op, T e, Inv inv) {
  return weighted_dsu<T, Op, Inv>(n, op, e, inv);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int _ = n - 1; _--; ) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<long long> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  for (int v = 0; v < n; ++v) {
    int b;
    cin >> b;
    a[v] -= b;
  }
  auto wd = make_weighted_dsu(n, plus<>(), 0LL, negate<>());
  vector<long long> sum(n);
  auto dfs = [&](auto&& self, int v, int p) -> void {
    sum[v] = a[v];
    for (int u : g[v]) {
      if (u == p) {
        continue;
      }
      self(self, u, v);
      wd.unite(v, u, sum[u]);
      sum[v] += sum[u];
    }
  };
  dfs(dfs, 0, -1);
  vector<long long> x(n);
  for (int v = 1; v < n; ++v) {
    x[v] = wd.diff(0, v);
  }
  DEBUG(x);
  auto mn = *min_element(begin(x), end(x));
  for (auto&& e : x) {
    e -= mn;
  }
  auto res = accumulate(begin(x), end(x), 0LL);
  cout << res << '\n';
}



Measured memory_bytes: 18252
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
const ll mod = 1000000007;

int n,a[25];

int main(){
	cin >> n;
	repn(i,n) cin >> a[i];
	int ans = 0;
	repn(i,n-2){
		if(a[i] < a[i+1] && a[i+1] < a[i+2]) ans++;
		if(a[i] > a[i+1] && a[i+1] > a[i+2]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
int main() {
	string s;
	cin >> s;
	int n = s.size();
	int sum = 0; 
	if (s == "keyence") { cout << "YES" << endl; return 0; }
     else if (s[0] != 'k') {
		if (s[n - 7] == 'k'&&s[n - 6] == 'e'&&s[n - 5] == 'y'&&s[n - 4] == 'e'&&s[n - 3] == 'n'&&s[n - 2] == 'c'&&s[n - 1] == 'e') { cout << "YES" << endl; return 0; }
				else { cout << "NO" << endl; return 0; }
	}
     else if (s[1] != 'e'&&s[0]!='e') {
		if (s[n - 6] == 'e'&&s[n - 5] == 'y'&&s[n - 4] == 'e'&&s[n - 3] == 'n'&&s[n - 2] == 'c'&&s[n - 1] == 'e') { cout << "YES" << endl; return 0; }
		else { cout << "NO" << endl; return 0; }
	}
	else if (s[2] != 'y') {
		if (s[n - 5] == 'y'&&s[n - 4] == 'e'&&s[n - 3] == 'n'&&s[n - 2] == 'c'&&s[n - 1] == 'e') { cout << "YES" << endl; return 0; }
		else { cout << "NO" << endl; return 0; }
	}
	else if (s[3] != 'e'&&s[1]=='e'&&s[0]!='e'&&s[2]!='e') {
		if (s[n - 4] == 'e'&&s[n - 3] == 'n'&&s[n - 2] == 'c'&&s[n - 1] == 'e') { cout << "YES" << endl; return 0; }
		else { cout << "NO" << endl; return 0; }
	}
	else if (s[4] != 'n') {
		if (s[n - 3] == 'n'&&s[n - 2] == 'c'&&s[n - 1] == 'e') { cout << "YES" << endl; return 0; }
		else { cout << "NO" << endl; return 0; }
	}
	else if (s[5] != 'c') {
		if (s[n - 2] == 'c'&&s[n - 1] == 'e') { cout << "YES" << endl; return 0; }
		else { cout << "NO" << endl; return 0; }
	}
	else if (s[6] != 'e'&&s[3] == 'e'&&s[1] == 'e'&&s[0] != 'e'&&s[2] != 'e'&&s[4]!='e'&&s[5]!='e') {
		if (s[n - 1] == 'e') { cout << "YES" << endl; return 0; }
		else { cout << "NO" << endl; return 0; }
	}
	else { cout << "NO" << endl; }
}

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

using namespace std;
const int INF=1e9+5;
typedef long long ll;
const int MOD=1e9+7;
int main(){
	ll a,b,n;
	cin>>a>>b>>n;
	//ll maxi=INT_MIN;
	ll ans;
	if(b<=n)   ans=(a*(b-1))/b;
	else ans=(a*n)/b;
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;
int input(){int x;cin>>x;return x;}
vector<int> G[150];
int n;
int solve(vector<int> S){
  int k = S.size();
  bitset<150> s(0);
  for(int i=0;i<k;++i) s.flip(S[i]);
  int id = -1,cnt = 0;

  for(int i=0;i<n;++i){
    bitset<150> t(0);
    for(int j=0;j<G[i].size();++j) t.flip(G[i][j]);
    t&=s;
    if(t==s){
      id = i;
      ++cnt;
    }
  }
  if(cnt!=1) return -1;
  return id+1;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;++i){
      G[i].clear();
      int m = input();
      while(m--)
	G[i].push_back(input()-1);
    }
    vector<int> S;
    int k = input();
    for(int i=0;i<k;++i) S.push_back(input()-1);

    cout << solve(S) << endl;
  }
  return 0;
}

Measured memory_bytes: 1280
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define fo(i,a,b) for(i=a; i<b; ++i)
#define foe(i,a,b) for(i=a; i<=b; ++i)
#define rep(i,n) for(i=1;i<=n;i++)
#define all(a) a.begin(), a.end()
#define pb push_back
#define ins insert
#define mk make_pair
#define f first
#define s second
#define mod 1000000007
#define vi vector<int>
#define vll	vector<ll>
#define vvi	vector<vi>
#define pii	pair<int,int> //typedef pair<int,int> pii;
#define pll	pair<ll , ll>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
//mp.reserve(4096);
//mp.max_load_factor(0.25);

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

Measured memory_bytes: 1024
A,B,K = map(int,input().split())
if K == 0:
    print(A,B)
    exit()
if (A+B) < K:
    print(0,0)
    exit()
elif A > K:
    A -= K
else:
    A -= K
    if A != 0:
        B += A
        A -= A
print(A,B)


Measured memory_bytes: 3060
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main(){
string S;
cin>>S;
int A;
A=S[0]-'0';
rep(i,1<<3){
    int ans=A;
    rep(j,3){
        if((i>>j)&1){
            ans+=S[j+1]-'0';
        }
        else{
            ans-=S[j+1]-'0';
        }

    }
    if(ans==7){
        string s="+++++++";
        s[0]=S[0];
        
        rep(j,3){
            if((i>>j)&1){
                s[2*j+1]='+';
                s[2*j+2]=S[j+1];
            }
            else{
                s[2*j+1]='-';
                s[2*j+2]=S[j+1];
            }
        }
        s+="=7";
        cout<<s<<endl;
        return 0;
    }
}


return 0;
}

Measured memory_bytes: 3624
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

class UnionFind {
    vector<int> pir;

public:
    UnionFind(int size) : pir(size, -1) { }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (pir[y] < pir[x]) swap(x, y);
            pir[x] += pir[y];
            pir[y] = x;
        }
        return x != y;
    }

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

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

    int size(int x) {
        return -pir[root(x)];
    }
};

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

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

    VI k(n);
    VVI l(n,VI());
    REP(i,n){
        cin >> k[i];
        REP(j,k[i]){
            int t;
            cin >> t;
            l[i].push_back(t);
        }
    }

    UnionFind uf(m);
    REP(i,n){
        FOR(j,1,k[i]){
            uf.unite(l[i][0],l[i][j]);
        }
    }

    FOR(i,1,n){
        if(!uf.same(l[0][0],l[i][0])){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
#include <cmath>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<< endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N, M);
  vector<bool> m(N + 1, true);
  rep(i, 0, M) {
    VAR(int, ai);
    m[ai] = false;
  }
  vector<ll> dp(N + 1);
  dp[0] = 1;
  dp[1] = 1;
  rep(i, 2, N + 1) {
    rep(j, i - 2, i) {
      if (m[j]) {
        dp[i] = (dp[i] + dp[j]) % MOD;
      }
    }
  }
  print(dp[N]);
}


Measured memory_bytes: 1024
//Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void sublime(){ 
	#ifndef ONLINE_JUDGE 
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
      }
	ll mod=1e9+7;
int main()
{   
     //sublime();
	  ll n,i;
	   cin>>n;
	   ll arr[n];
	   ll sum=0;
	   for(i=0; i<n; i++)
	    {
	    	cin>>arr[i];
	    	sum+=arr[i];
	    	sum%=mod;
	    }
	    ll psum[n];
	    memset(psum,0,sizeof(psum));
	    
	    for(i=0; i<n; i++)
	    {
           sum-=arr[i];
           sum=(sum+mod)%mod;
           psum[i]=sum;
	    } 
	    
	    ll ans=0;
	    for(i=0; i<n-1; i++)
	    {
	    	ans+=(arr[i]*psum[i])%mod;
	    	ans%=mod;
	    }
	    cout<<ans;
	    
	   
	return 0;
}


Measured memory_bytes: 6712
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
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; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    /*
    vector<ll> X(N);
    string s,t;
    in >> s >> t;
    vector<string> s,t;
    s.resize(N);
    ll N;
    in >> N;
    */

    ll T,A,V,B,W;
    in >> A>>V;
    in >> B>>W;
    in >> T;

    if(V<=W){
        out<<"NO"<<endl;
    }else if((V-W)*T>=abs(B-A)){
        out<<"YES"<<endl;
    }else{
        out<<"NO"<<endl;
    }
    
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int D;
	cin >> D;
	cout << "Christmas";
	for (int i = D; i < 25; i++) {
		cout << " Eve";
	}
	cout << endl;
}

Measured memory_bytes: 256
n = input()
s = raw_input()
ans = 0
for i in range(1,n):
    a = s[0:i]
    b = s[i:n]
    arr = []
    for l in a:
        for m in b:
            if l == m and l not in arr:
                arr.append(l)
    if len(arr) > ans:
        ans = len(arr)
print ans


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

int main(){
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		int items[n];
		int currentMax = -1;
		for(int i = 0; i < n; i++){
			cin >> items[i];
			if(items[i] < m && i != 0){
				for(int j = 0; j < i; j++){
					if(currentMax < items[i] + items[j] && m >= items[i] + items[j]){
						currentMax = items[i] + items[j];
					}
				}
			}
		}
		if(currentMax != -1){
			cout << currentMax << endl;
		}else{
			cout << "NONE" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3028
(defun abc109c ()
  (let* ((n (read))
	 (x (read))
	 (xs (loop for i below n collect (read))))
    (format t "~a~%"
	    (reduce #'gcd (mapcar (lambda (a) (abs (- a x))) xs)
		    :initial-value 0))))

(abc109c)

Measured memory_bytes: 59748
/**
 * https://atcoder.jp/contests/abc169/tasks/abc169_b
 * N 個の整数 A1,...,AN が与えられます。
 * A1×...×AN を求めてください。
 * ただし、結果が 10^18 を超える場合は、代わりに -1 を出力してください。
 */
export function Main(input: string) {
  // 問題文解体エリア
  const inputs = input.split("\n");
  const nums = inputs[1].split(" ").map(s => BigInt(new Number(s).valueOf()));

  // 問題解決エリア
  const answer = fuck(nums);

  //出力エリア
  console.log(answer.toString());
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
// 提出する時にコメントアウト解除せよ
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

export function fuck(nums: Array<BigInt>): BigInt {
  // numberで計算するとバグる
  // 1000000000000000001であるべきだが、1000000000000000000になる
  // 例としてrubyだと正しく計算
  // console.log(Number.MAX_SAFE_INTEGER);
  // console.log(101 * 9901 * 999999000001);

  // 最初に0が含まれるかチェックする。そうすれば10^18を超えてるかどうかの検証をfor文内でできるため、タイムアウトなくなる？
  const containsZero: boolean = nums.find(n => n == BigInt(0)) != null;
  if (containsZero) return BigInt(0);

  let result = BigInt(1);
  for (let i = 0; i < nums.length; i++) {
    result = BigInt(nums[i]) * result;
    if (result > Math.pow(10, 18)) return BigInt(-1);
  }
  

  return result;
}


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

int n;
vector<char> v;
void dfs(int i, char mx)
{
	char j = 'a';
	while(j <= 'z')
	{
		if (j > mx + 1 || i == 0 && j >= 'b') return;
		v[i] = j;
		if (i == n - 1)
		{
			rep(i, n) cout << v[i];
			cout << endl;
		}
		else
		{
			if (mx < v[i])
				dfs(i + 1, v[i]);
			else
				dfs(i + 1, mx);
		}
		j++;
	}
}

signed main(void)
{
	cin >> n;
	v = vector<char>(n);
	dfs(0, 'a');
	return 0;
}


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

int main(){
	long L,R; cin >> L >> R;
	long ans = 2147483647;

	for(long i = L; i <= R; i++){
		for(long j = i + 1; j <= R; j++){
			if(j % 2019 == 0){
				cout << 0;
				return 0;
			}

			if(i * j % 2019 < ans){
				ans = i * j % 2019;
			}
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
r_list=[]

for i in range(n):
  r=list(map(str,input().split()))
  r[1]=int(r[1])
  r.append(i+1)
  r_list.append(r)

r_list.sort(key=lambda x:(x[0],-x[1]))

for j in range(n):
  print(r_list[j][2])


Measured memory_bytes: 3060
r,D,x2000 = map(int, input().split())
def algae(x2000):
    #for i in range(10):
        ans = r * x2000 - D
        #new_ans = algae(r, D, ans)
        
        return ans
      
next_value = algae(x2000)
for i in range(10):
    print(next_value)
    next_value = algae(next_value)

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

bool isprime[102400];

int main() {
  for(int i = 0; i < 102400; ++i) isprime[i] = true;
  isprime[0] = isprime[1] = false;
  for(int i = 2; i < 320; ++i) {
    if( not isprime[i] ) continue;
    for(int j = i * i; j < 102400; j+=i) {
      isprime[j] = false;
    }
  }

  int n;
  scanf("%d", &n);
  printf("%d:", n);
  for(int i = 2; i * i <= n; ++i) {
    if( not isprime[i] ) continue;
    while( n % i == 0 ) {
      printf(" %d", i);
      n /= i;
    }
  }
  if( n != 1 ) {
    printf(" %d", n);
  }

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

Measured memory_bytes: 3312
#include <iostream>
#include <bitset>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, R, A[1 << 19]; vector<int> G;
bool used[1 << 19];

bitset<150005>E;

void solve() {
	E.set(0);
	for (int i = 0; i < G.size(); i++) {
		E |= (E << G[i]);
	}
	if (E[R] == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

int main() {
	scanf("%d%d", &N, &R); R = min(R, N - R);
	for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
	for (int i = 1; i <= N; i++) {
		if (used[i] == true) continue;

		int cx = i, cnt = 0;
		while (used[cx] == false) {
			used[cx] = true;
			cx = A[cx];
			cnt++;
		}
		G.push_back(cnt);
	}
	solve();
	return 0;
}


Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";

int main(){
  ll n; cin >> n;
  map<ll,ll> m;
  ll ans=0;
  rep(i,n){
    ll num=i+1;
    ll a; cin >> a;
    ans+=m[num-a];
    m[num+a]++;
  }
  cout << ans;
  
  return 0;
}




Measured memory_bytes: 26380
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

#define INF (long long)(10e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    int A, B, C, D, E, F, w , s, rws = -1,rs = -1;
    double con, Max = -10;
    cin >> A >> B >> C >> D >> E >> F;
    for(int a = 0; a * A * 100 <= F; a++) {    
        for(int b = 0; (a * A + b * B)*100 <= F; b++) {
            w = (a * A + b * B) * 100;
            for(int c = 0; w + c * C <= F; c ++) {
                for(int d = 0; w + c * C + d * D <= F; d ++) {
                    s = (c * C + d * D);
//     cout << w << " " << s ;
                    if((w/100) * E >= s && w + s > 0 && w + s <= F) {
                        con = (double)(s * 100) /(double) (w + s);
                        if(con > Max) {
                            Max = con;
                            rws = w + s;
                            rs = s;
//     cout << " " << con << " " << rws << " " << rs ;
                        }
                    }
//                    cout << endl;
                }
            }
        }
    }
    cout << rws << " " << rs << endl;             
}



Measured memory_bytes: 256
n, m, tax = gets.strip.split.map(&:to_i)
abc = readlines.map {|line| 
  tmp = line.strip.split.map(&:to_i)
  [tmp[0], tmp[1], -1*(tmp.last-tax)]
}
N=n

graph=Array.new(n+1) {[]}
reverse_graph=Array.new(n+1) {[]}
abc.each do |a, b, tax|
  graph[a] << [b, tax]
  reverse_graph[b] << [a, tax]
end

# sから到達可能、gに到達可能の点を洗い出す
# 洗い出した点のみを使うように再構成
# ベルマンフォード法で最短距離をゲット、
# 合計値をゲットして完了

def reachable(graph, s)
  visited = [s]
  queue = [s]
  until queue.empty?
    current = queue.shift
    graph[current].each do |to, _|
      next if visited.include?(to)
      visited.push(to)
      queue.push(to)
    end
  end

  visited
end

INF = 10**13
@dist = Array.new(n+1, INF)

def berman_ford(edges, s, g)
  @dist[s]=0
  N.times do |i|
    updated = false
    edges.each do |from, to, cost|
      if @dist[from] != INF && @dist[to] > @dist[from] + cost
        @dist[to] = @dist[from]+cost
        updated = true
      end
    end
    return true unless updated
  end

  return false
end

reachable_from_s = reachable(graph, 1)
reachable_to_g = reachable(reverse_graph, n)
retrenched_nodes = reachable_from_s & reachable_to_g

retrenched_edges = abc.select{|from, to, _|
  retrenched_nodes.include?(from) && retrenched_nodes.include?(to)
}

result = -1

if berman_ford(retrenched_edges, 1, n)
  result = [-1*@dist[n], 0].max
end

#p reachable_from_s
#p reachable_to_g
#p retrenched_nodes
#p retrenched_edges
#p @dist
p result



Measured memory_bytes: 3068
import math
L = [int(input()) for i in range(5)]
S = 0
answer = []
for i in range(5):
    S += math.ceil(L[i]/10) * 10
for i in range(5):
    answer.append(S - math.ceil(L[i]/10) * 10 + L[i])
print(min(answer))

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  
  vector<vector<int>>grid(3,vector<int>(3,0));
  
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> grid[i][j];
    }
  }
  
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;
  
  if(grid[0][0] - grid[0][1] == grid[1][0] - grid[1][1] &&
     grid[0][0] - grid[0][1] == grid[2][0] - grid[2][1])
    a = 1;
  if(grid[0][1] - grid[0][2] == grid[1][1] - grid[1][2] &&
     grid[0][1] - grid[0][2] == grid[2][1] - grid[2][2])
    b = 1;
  if(grid[0][0] - grid[1][0] == grid[0][1] - grid[1][1] &&
     grid[0][0] - grid[1][0] == grid[0][2] - grid[1][2])
    c = 1;
  if(grid[1][0] - grid[2][0] == grid[1][1] - grid[2][1] &&
     grid[1][0] - grid[2][0] == grid[1][2] - grid[2][2])
    d = 1;
  
  if(a * b * c * d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    set<int> s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<"\n";
    return(0);
}

Measured memory_bytes: 3624
//課題4-C 16D8102014J Kazuto Iguchi 5/14
//C
#include<stdio.h> 
#include<string.h>
#define N 256
 
char a[1<<21],b[N]; 
int main(int argc,char *argv[]){
  char ch;
  int f; 
  int v,s,t;
  
  b['T'] = 1;
  b['G'] = 2;
  b['C'] = 3;
  b['A'] = 4;
  
  scanf("%d", &v);
  
  getchar();

  while(v--){
    s=0;
    t=1;
    
    f=(ch=getchar())=='i';
    
    while((ch=getchar())!=' ');
    
    while((ch=b[getchar()])!=0){
      
      s+=ch*t; 
      t*=4;
    }
    
    if(f)a[s]=1;
    else puts(a[s]?"yes":"no");
  }
  
  return 0;
}



Measured memory_bytes: 3036
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r,d;
	long long i;
	cin>>r>>d>>i;
	for(int j=1;j<=10;j++)
	{
		i=i*r-d;
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

//約数の総和O(√n)
ll div_sum(ll n) {
  ll s = 0;
  ll k;
  for ( k = 1; k * k <= n; k++ ) { 
    if(k * k == n) s += k;
    else if ( n % k == 0 ) { s += k + n / k; } 
  }
  return s;
}

//素因数分解
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
ll beki(ll a, ll n){
    if(n == 0){
        return 1;
    }
    ll ans = beki(a, n / 2) % mod;
    ans = ans * ans % mod;
    if(n % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

int main() {
  ll m, n; cin >> m >> n;
  cout << beki(m, n) << endl;
}


Measured memory_bytes: 3124
def p(a):
    for i in a[:-1]:
        print(i,end=' ')
    print(a[-1])


def selection_sort(a):
    cnt = 0
    for i in range(len(a)-1):
        fl = 0
        min = i
        for j in range(i+1,len(a)):
            if a[j]<a[min]:
                fl=1
                min = j
        cnt+=fl
        tmp = a[min]
        a[min] = a[i]
        a[i] = tmp
    p(a)
    print(cnt)


n = int(input())
l = list(map(int,input().split()))
selection_sort(l)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n,a;
vector<int>x;
ll dp[60][60][2600]={};
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,a;
  cin >> n >> a;
  vector<int>x(n);
  rep(i,n) cin >> x[i];
  dp[0][0][0]=1;
  rep(i,55){
    rep(j,55){
      rep(k,2550){
        dp[i+1][j][k]+=dp[i][j][k];
        dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
      }
    }
  }

  ll cnt=0;
  for(int j=1;j<=n;j++){
    cnt+=dp[n][j][j*a];
  }
  cout << cnt << endl;
}


Measured memory_bytes: 68736
x = gets.to_i
if x <= 599
    puts 8
elsif x <= 799
    puts 7
elsif x <= 999
    puts 6
elsif x <= 1199
    puts 5
elsif x <= 1399
    puts 4
elsif x <= 1599
    puts 3
elsif x <= 1799
    puts 2
elsif x <= 1999
    puts 1
end


Measured memory_bytes: 14316
#include<stdio.h>
int main()
{
  int d,r,a,b;
  double f;
  scanf("%d %d",&a,&b);
  d=a/b;
  r=a%b;
  f=(double)a/(double)b;
  printf("%d %d %f\n",d,r,f);
  return 0;
}



Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

const ll INF = 1e15;
//始点sとした最短距離を求める O((V+E)logV)
vector<ll> dijkstra(vector<vector<P>>& g, ll s) {
  ll n = SZ(g);
  vector<ll> d(n, INF);
  priority_queue<P, vector<P>, greater<P>> pq;
  vector<bool> fixed(n, false);
  d[s] = 0;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    P f = pq.top();
    pq.pop();
    ll cv = f.second;
    fixed[cv] = true;
    if (d[cv] < f.first) continue;
    FOREACH(p, g[cv]) {
      ll nv = p.first;
      ll wgt = p.second;
      if (fixed[nv]) continue;
      if (d[nv] <= d[cv] + wgt) continue;
      d[nv] = d[cv] + wgt;
      pq.push(make_pair(d[nv], nv));
    }
  }
  return d;
}

ll h, w;
ll toId(ll i, ll j) { return w * i + j; }

int main() {
  cin >> h >> w;
  ll sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  sx--, sy--, gx--, gy--;

  vector<string> s(h);
  REP(i, h) { cin >> s[i]; }

  vector<vector<P>> to(h * w);

  REP(i, h) REP(j, w) {
    if (s[i][j] == '#') {
      continue;
    }
    FOR(k, -2, 3) FOR(l, -2, 3) {
      ll x = i + k, y = j + l;
      if (x < 0 || x >= h || y < 0 || y >= w) {
        continue;
      }
      if (s[x][y] == '#') {
        continue;
      }
      ll d = abs(k) + abs(l);
      ll cId = toId(i, j), nId = toId(x, y);
      if (d == 0) {
        continue;
      }
      if (d == 1) {
        to[cId].push_back({nId, 0});
        continue;
      }
      to[cId].push_back({nId, 1});
    }
  }
  vector<ll> dist = dijkstra(to, toId(sx, sy));
  // REP(i, h * w) { DUMP(dist[i]); }
  ll id = toId(gx, gy);
  ll ans = dist[id];
  if (ans == INF) {
    ans = -1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 168512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

"""
・共通で1点失う
・1人に1点追加
"""

N,K,Q = map(int,input().split())
A = (int(x) for x in sys.stdin.read().split())

score = [K-Q] * (N+1) 
for x in A:
    score[x] += 1

answer = '\n'.join('No' if x <= 0 else 'Yes' for x in score[1:])
print(answer)

Measured memory_bytes: 12632
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
typedef pair<int,int> P;
#define MAX_N 514
int N;
P X[MAX_N];
int ans[MAX_N*MAX_N];
int cou[MAX_N];
bool f[MAX_N];
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&X[i].fi);X[i].sc=i+1;ans[X[i].fi-1]=i+1;
		cou[i]=N;
	}
	sort(X,X+N);
	for(int i=0;i<N*N;i++){
		if(ans[i]!=0){
			cou[ans[i]-1]--;f[ans[i]-1]=true;
			if(cou[ans[i]-1]!=N-ans[i]){
				printf("No\n");
				return 0;
			}
		}
		else{
			bool F=true;
			for(int j=0;j<N;j++){
				if(cou[X[j].sc-1]>=N-X[j].sc+2){
					ans[i]=X[j].sc;
					cou[X[j].sc-1]--;
					F=false;
					break;
				}
			}
			if(F){
				for(int j=0;j<N;j++){
					if(cou[j]>0&&f[j]){
						ans[i]=j+1;cou[j]--;F=false;
						break;
						
					}
				}
			}
			if(F){
				printf("No\n");
				return 0;
			}
		}
		//printf("%d %d\n",i,ans[i]);
	}
	printf("Yes\n");
	printf("%d",ans[0]);
	for(int i=1;i<N*N;i++){
		printf(" %d",ans[i]);
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int data[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << data[n-1] << endl;

    return 0;
}


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


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

Measured memory_bytes: 3724
#include<stdio.h>
int main(){
  int a[2][1000]={0};
  char s[1001];
  int i=0,j=0,k=0,t,c;
  while(fgets(s,1000,stdin)!=NULL){
    if(s[0]==10){
      j++;
      k=0;
    }
    else{
      for(i=0;s[i]!=',';i++);
      s[i]='\0';
      a[j][k]=atoi(s);
      k++;
    }
  }
  for(j=0;j<2;j++){
    for(i=0;a[j][i]!=0;i++){
      for(k=1;a[j][k+i]!=0;k++){
	if(a[j][k-1]>a[j][k]){
	  t=a[j][k-1];
	  a[j][k-1]=a[j][k];
	  a[j][k]=t;
	}
      }
    }
  }
  i=0;
  j=0;
  while(a[0][i]*a[1][j]!=0){
    if     (a[0][i]>a[1][j])j++;
    else if(a[0][i]<a[1][j])i++;
    else  {
      printf("%d ",a[0][i]);
      c=2;
      for(;a[0][i]==a[0][i+1];i++)c++;
      for(;a[1][j]==a[1][j+1];j++)c++;
      printf("%d\n",c);
      i++;
      j++;
    }
  }
  return 0;
}

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

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

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	bool ok = true;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#') {
				int cnt = 0;
				for (int k = 0; k < 4; k++) {
					int tx = i + dx[k], ty = j + dy[k];
					if (0 <= tx && tx < H && 0 <= ty && ty < W && s[tx][ty] == '#') {
						cnt++;
					}
				}
				if (cnt == 0) {
					ok = false;
				}
			}
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 3;
const int M = 9;
const int dx[] = {1, 0, -1,  0};
const int dy[] = {0, 1,  0, -1};
const char dir[] = {'r', 'u', 'l', 'd'};

typedef struct puzzle_def {
  int f[M];
  int space;
  string path;

  bool operator < (const puzzle_def &p) const {
    for (int i=0; i<M; i++) 
      if (f[i] < p.f[i])
        return true;
      else if (f[i] > p.f[i])
        return false;
    return false;
  }

/*
  bool operator < (const puzzle_def &l, const puzzle_def &r) {
    for (int i=0; i<M; i++) 
      if (l.f[i] < r.f[i])
        return true;
      else if (l.f[i] > r.f[i])
        return false;
    return false; 
  }
*/

} pzl;

bool is_target(pzl p) {
  for (int i=0; i<M; i++)
    if (p.f[i] != (i+1)) return false;
  return true;
}

string bfs(pzl s) {
  queue<pzl> q;
  map<pzl, bool> past;
  s.path = "";
  q.push(s);
  past[s] = true;

  while (q.size()) {
    pzl u = q.front(); q.pop(); 
    if (is_target(u)) return u.path;
    int x = u.space / N, y = u.space % N;
    for (int i=0; i<4; i++) {
      int nx = x + dx[i]; 
      int ny = y + dy[i]; 
      if (nx<0 || nx>=N || ny<0 || ny>=N) continue;
      pzl v = u;
      swap(v.f[v.space], v.f[nx * N + ny]);
      v.space = nx * N + ny;
      if (!past[v]) {
        past[v] = true;
        v.path += dir[i];
        q.push(v);
      }
    }
  }
  return "failed.";
}

int main() {
  pzl ini;
  for (int i=0; i<M; i++) {
    scanf("%d ", &(ini.f[i])); 
    if (!ini.f[i]) {
      ini.f[i] = M;
      ini.space = i;
    }
  }

  string res = bfs(ini);
  cout << res.size() << endl;

  return 0;
}

Measured memory_bytes: 28660
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = 0
for i in range(N):
  for j in range(i + 1, N):
    for k in range(j + 1, N):
      if a[i] != a[j] and (a[j] != a[k]) and (a[k] != a[i]):
        if a[i] + a[j] > a[k] and (a[j] + a[k] > a[i]) and (a[k] + a[i] > a[j]): res += 1
print(res)

Measured memory_bytes: 68208
<?php 
  list($n) = explode(" ", trim(fgets(STDIN)));

  $a = explode(" ", trim(fgets(STDIN)));
  
  $r = $n-1;
  $l = 0;
  $x = 0;
  while($l <= $r){
    if($x < 0){
      $x += $a[$l];
      $l++;
    }else{
      $x -= $a[$r];
      $r--;
    }
  }
  
  echo abs($x);

Measured memory_bytes: 4732
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		long S = long.Parse(Console.ReadLine());
		long ans = 0;
		long mod = 1000000007;
		for(var i=1;i<=S;i++){
			long S1 = S - i * 3;
			if(S1+1+i-2>=0){
              	long a1 = Ncr(S1+1+i-2,i-1,mod);
              	if(S1<=400){Console.Error.WriteLine((S1+1)+" "+(i-1)+" "+a1);}
				ans = (ans + Ncr(S1+1+i-2,i-1,mod)) % mod;
				ans %= mod;
			}
		}
		Console.WriteLine(ans);
	}
	public static long Mpow(long x,long n,long m)
	{
		long ans = 1;
		while(n > 0){
			if(n % 2 == 1){
				ans = ans * x % m;
				n -= 1;
			}
			x = x * x % m;
			n /= 2;
		}
		return ans;
	}
	public static long Ncr(long n,long r,long m)
	{
		long ans = 1;
      	for(var i=n-r+1;i<=n;i++){
			ans = ans * i % m;
		}
		for(var i=2;i<=r;i++){
			ans = ans * Mpow(i,m-2,m) % m;
		}
		return ans;
	}
}

Measured memory_bytes: 17780
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T,D,L;
    cin >> T >> D >> L;
    while(T != 0){
        vector<int> X(T);
        for(int i=0; i<T; i++){
            cin >> X[i];
        }
        int ok = 0;
        int ans = 0;
        for(int i=0; i<T; i++){
            if(ok) ans++;
            if(X[i] >= L) ok = D+1;
            if(ok) ok--;
        }
        cout << ans << enld;
        cin >> T >> D >> L;
    }


    return 0;
}


Measured memory_bytes: 3560
#include <iostream>

using namespace std;
const int N=1e5+500;
long long int a[N]= {0};
long long int dp1[N]={0};
long long int dp2[N]={0};
long long gcd(long long int a,long long int b)
{
    if(b==0)
    {
        return a;
    }
    else
    {
        return gcd(b,a%b);
    }
}
int main()
{
    long long int n;
    cin>>n;
    int y=0;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    a[0]=a[1];
    a[n+1]=a[n];
    for(int i=1;i<=n;i++)
    {
        dp1[i]=gcd(dp1[i-1],a[i]);
    }
    for(int i=n;i>=0;i--)
    {
        dp2[i]=gcd(dp2[i+1],a[i]);
    }
    long long int max1=0;
    for(int i=1;i<=n;i++)
    {
        long long int y=gcd(dp1[i-1],dp2[i+1]);
        max1=max(max1,y);
    }
    cout<<max1<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int dp[5005][5005];

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

	int N;
	string S;
	cin >> N >> S;

	for (int i = N - 1;i >= 0;i--) {
		for (int j = N - 1;j >= 0;j--) {
			if (S[i] == S[j]) dp[i][j] = dp[i + 1][j + 1] + 1;
		}
	}
	int res = 0;
	for (int i = 0;i < N - 1;i++) {
		for (int j = i + 1;j < N;j++) {
			res = max(min(dp[i][j], j - i), res);
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 98048
#include <stdio.h>

#define N 10000
#define Q 500

int main () {
  int i, j, n, q, c=0;
  int s[N], t[Q];

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

  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%d", &t[i]);
    for(j=0;j<n;j++){
      if(t[i]==s[j]){
        c++;
        break;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        M = new int[n][n];
        d = new int[n];
        p = new int[n];
        color = new int[n];

        for(int i = 0 ; i < n ; i ++){
            int u = sc.nextInt();
            int k = sc.nextInt();
            for(int m = 0; m < n ; m ++){
                M[u][m] = INFTY;
            }
            for(int j = 0 ; j < k ; j ++){
                int v = sc.nextInt();
                int w = sc.nextInt();
                M[u][v] = w;
            }

            d[i] = INFTY;
            p[i] = -1;
        }

        dijkstra(0);

        for(int i = 0 ; i < n ; i ++){
            System.out.print(i + " " + d[i]);
            System.out.println();
        }
    }


    static int[][] M;
    static int n;
    static int[] d;
    static int[] p;
    static int[] color;
    static final int INFTY = 1 << 21;
    static final int WHITE = 0;
    static final int GRAY = 1;
    static final int BLACK = 2;


    static void dijkstra(int s){
        d[s] = 0;
        color[s] = GRAY;

        int minv,u;
        while (true){
            u = -1;
            minv = INFTY;
            for(int i = 0 ; i < n; i ++){
                if(color[i] != BLACK && minv > d[i]){
                    minv = d[i];
                    u = i;
                }
            }

            if(minv == INFTY){
                break;
            }

            color[u] = BLACK;

            for(int v = 0 ; v < n; v ++){
                if(color[v] != BLACK && M[u][v] != INFTY){
                    if(d[u] + M[u][v] < d[v]){
                        d[v] = d[u] + M[u][v];
                        color[v] = GRAY;
                        p[v] = u;
                    }
                }
            }
        }
    }

}



Measured memory_bytes: 39536
n = int(input())
A = list(map(int,input().split()))
num = [0 for _ in range(10**6)]
for a in A:
    num[a] += 1
    num[a+1] += 1
    num[a-1] += 1
mx = max(num)
tg = num.index(mx)
print(num[tg])

Measured memory_bytes: 116676
use proconio::input;
use std::collections::BTreeMap;

fn lower_bound(map: &BTreeMap<usize, usize>, target: usize) -> usize {
    *map.range(target..).next().unwrap().1
}

fn main() {
    input! {
        n: usize,
        q: usize,
        query: [(usize, usize); q],
    }

    let mut h_map = BTreeMap::new();
    let mut w_map = BTreeMap::new();

    h_map.insert(n-1, n);
    w_map.insert(n-1, n);

    let mut ans = 0;

    for &(c, x) in query.iter() {
        if c == 1 {
            let t = lower_bound(&h_map, x);
            if t <= 1 {
                continue;
            }
            ans += t-2;
            if let Some(&y) = w_map.get(&(t-1)) {
                *w_map.entry(t-1).or_default() = y.min(x);
            }
            else {
                *w_map.entry(t-1).or_default() = x;
            }
        }
        else {
            let t = lower_bound(&w_map, x);
            if t <= 1 {
                continue;
            }
            ans += t-2;
            if let Some(&y) = h_map.get(&(t-1)) {
                *h_map.entry(t-1).or_default() = y.min(x);
            }
            else {
                *h_map.entry(t-1).or_default() = x;
            }
        }
        // dbg!(c, x, ans);
        // dbg!(h_map.clone());
        // dbg!(w_map.clone());

    }

    println!("{}", (n-2)*(n-2) - ans);
}


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

int main(){
    int n,res,s=0,t=0;
    cin >> n;
    int a[110];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n,greater<int>());
    for(int i=0;i<n;i++){
        if(i%2==0)s+=a[i];
        else t+=a[i];
    }
    res=s-t;
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min({a+b, b+c, c+a}) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
using sl = signed long;
using sll = signed long long;
using ll = long long;

// -exec call dup2(open("input.txt", 0), 0)
int main()
{
	int a, b;
	cin >> a >> b;
	cout << max({a + b, a - b, a * b});
	return 0;
}

Measured memory_bytes: 256
import collections
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
plus = []
minus = []
for i in range(n):
    diff = a[i] - b[i]
    if diff >= 0:
        plus.append(diff)
    else:
        minus.append((-1) * diff)
plus.sort(reverse=True)
plus = collections.deque(plus)
if len(minus) == 0:
    print(0)
    exit()
if sum(plus) < sum(minus):
    print(-1)
    exit()
ans = len(minus)
total = sum(minus)
while total > 0:
    total -= plus.popleft()
    ans += 1
print(ans)

Measured memory_bytes: 18732