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

int main() {
    ll N, K; cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A.at(i);
        A[i]--;
    }
    ll cur = 0;
    ll step = 0;
    vector<ll> V;
    set<ll> S;
    do {
        if (S.count(cur) > 0) break;
        S.insert(cur);
        V.push_back(cur);
        step++;
        cur = A[cur];
    } while (cur != 0);
    if (K < V.size()) {
        cout << V[K] + 1 << endl;
        return 0;
    }
    if (cur != 0) {
        ll first = distance(begin(V), find(begin(V), end(V), cur));
        K -= first;
        step = V.size() - first;
        ll m = K % step;
        cout << V[first + m] + 1 << endl;
        return 0;
    }
    ll m = K % step;
    cout << V[m] + 1 << endl;
}


Measured memory_bytes: 15564
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int ind_one;
  rep(i, N) {
    cin >> A[i];
    if (A[i] == 1) ind_one = i;
  }
  int ans;

  if (K == N)
    ans = 1;
  else {
    ans = (N - 1 + K - 2) / (K - 1);
  }
  cout << ans << endl;
}

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

using namespace std;

const int MaxN = 1e5 + 15;
const int INF = 1e9;
const long double eps = 1e-9;
const int MOD = 1e9 + 7;

int n, m;
int S, T;
vector <pair<int, int > > e[MaxN];
vector <int> v[MaxN], vr[MaxN];

long long d[MaxN];

long long dps[MaxN];
long long dpt[MaxN];

bool used[MaxN];

set<pair<long long, int> > s;

void dj()
{
    for(int i = 1; i <= n; ++i)
        d[i] = 1e18;

    s.insert(make_pair(0, S));
    d[S] = 0;

    while(!s.empty())
    {
        int x = s.begin() -> second;
        s.erase(s.begin());
        for(auto to : e[x])
        {
            if(d[to.first] > d[x] + to.second)
            {
                s.erase(make_pair(d[to.first], to.first));
                d[to.first] = d[x] + to.second;
                s.insert(make_pair(d[to.first], to.first));
            }
        }
    }

    for(int i = 1; i <= n; ++i)
        for(int j = 0; j < e[i].size(); ++j)
        {
            if(d[i] + e[i][j].second == d[e[i][j].first])
            {
                v[i].push_back(e[i][j].first);
                vr[e[i][j].first].push_back(i);
            }
        }
}

int dfs1(int x)
{
    if(used[x])
        return dps[x];

    used[x] = 1;

    if(x == S)
    {
        dps[x] = 1;
        return dps[x];
    }

    for(int to : vr[x])
        dps[x] = (dps[x]  + dfs1(to)) % MOD;

    return dps[x];
}

int dfs2(int x)
{
    if(used[x])
        return dpt[x];

    used[x] = 1;

    if(x == T)
    {
        dpt[x] = 1;
        return dpt[x];
    }

    for(int to : v[x])
        dpt[x] = (dpt[x]  + dfs2(to)) % MOD;

    return dpt[x];
}

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

//    freopen("input.txt", "r", stdin);

    cout.precision(9);

    cin >> n >> m;
    cin >> S >> T;
    for(int i = 1; i <= m; ++i)
    {
        int x, y, z;
        cin >> x >> y >> z;
        e[x].push_back(make_pair(y, z));
        e[y].push_back(make_pair(x, z));
    }

    dj();

    int ans = dfs1(T);

    ans = (ans * 1ll * ans) % MOD;

    memset(used, 0, sizeof(used));

    dfs2(S);

    for(int i = 1; i <= n; ++i)
    {
        if(d[i] == d[T] - d[i])
        {
            long long x = (dps[i] * 1ll * dpt[i]) % MOD;
            x = (x * 1ll * x) % MOD;
            ans = (ans - x + MOD) % MOD;
        }
        for(int j = 0; j < e[i].size(); ++j)
        {
            if(e[i][j].second + d[i] == d[e[i][j].first])
            {
                int y = e[i][j].first;
                int x = i;
                long long P = d[T] - d[y];

                if(abs(P - d[x]) < e[i][j].second)
                {
                    long long k = (dps[x] * 1ll * dpt[y]) % MOD;
                    k = (k * 1ll * k) % MOD;
                    ans = (ans - k + MOD) % MOD;
                }
            }
        }
    }

    cout << ans << '\n';

    return 0;
}


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

int main(){
  string s;
  int k;
  cin >> k >> s;
  if(s.size() <= k)
    cout << s << endl;
  else{
    for(int i = 0;i < k;i++)
      cout << s[i];
    cout << "...\n";
  }
  return 0;
}
  

Measured memory_bytes: 3628
<?php
fscanf(STDIN,"%d %d",$N,$K);

$input = array();

for($i=1;$i<=$K;++$i){
    $a=intval(trim(fgets(STDIN)));
    $have=explode(' ',trim(fgets(STDIN)));
    $input=array_merge($input, $have);
}

$man = array();
for($i=1;$i<=$N;++$i){
    array_push($man, $i);
}

$result = array_diff($man, $input);
echo count($result);
?>


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

int main()
{
    long long H, ans = 0;
    cin >> H;

    long long upper = pow(2, 40), lower = 0;

    while (upper - lower > upper / 2)
    {
        if (H >= upper / 2)
        {
            lower = upper / 2;
        }

        else
        {
            upper /= 2;
        }
    }

    if (H == upper)
    {
        while (upper > 0)
        {
            ans += upper;
            upper /= 2;
        }
    }

    else
    {
        while (lower > 0)
        {
            ans += lower;
            lower /= 2;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
X, K, D = map(int, input().split())
X = abs(X)
m_steps = X // D
if m_steps >= K:
    print(X - D * K)
else:
    pos = X - D * m_steps
    K -= m_steps
    if K % 2:
        print(D - pos)
    else:
        print(pos)


Measured memory_bytes: 9160
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int D;
vector<int> c(26);
vector<vector<int>> s;

int main() {
  cin >> D;

  rep(i, 26) { cin >> c[i]; }

  s.resize(D, vector<int>(26));
  rep(i, D) rep(j, 26) { cin >> s[i][j]; }

  const int width = 500;

  vector<vector<int16_t>> last;
  vector<int> parent;
  vector<char> kind;

  using P = pair<int64_t, int>;
  priority_queue<P, vector<P>, greater<P>> q;

  last.push_back(vector<int16_t>(26, -1));
  parent.push_back(-1);
  kind.push_back(-1);
  q.push(P(0, 0));

  mt19937 rng(111);
  uniform_int_distribution<int> dist(0, 100 - 1);

  rep(i, D) {
    priority_queue<P, vector<P>, greater<P>> nxt;
    queue<P> mutant;

    while (!q.empty()) {
      int64_t z;
      int idx;
      tie(z, idx) = q.top();
      q.pop();

      int64_t penalty = 0;
      rep(j, 26) { penalty += c[j] * (i - last[idx][j]); }

      rep(j, 26) {
        int nidx = last.size();
        int64_t w = z + s[i][j] - penalty + c[j] * (i - last[idx][j]);
        nxt.push(P(w, nidx));
        if (nxt.size() > width) {
          if (dist(rng) == 0) {
            mutant.push(nxt.top());
          }
          nxt.pop();
        }

        last.push_back(last[idx]);
        last[nidx][j] = i;
        parent.push_back(idx);
        kind.push_back(j);
      }
    }

    q = move(nxt);
    while (!mutant.empty()) {
      q.push(mutant.front());
      mutant.pop();
    }
  }

  while (q.size() > 1) {
    q.pop();
  }

  int64_t score;
  int idx;
  tie(score, idx) = q.top();
  vector<int> sln;
  while (idx != 0) {
    sln.push_back(kind[idx]);
    idx = parent[idx];
  }
  rrep(i, D) { cout << sln[i] + 1 << "\n"; }
  cerr << score << "\n";

  return 0;
}

Measured memory_bytes: 578036
def main():
    N, W = map(int, input().split())

    w1 = [0, 0]
    w2 = [0, 0]
    w3 = [0, 0]
    w4 = [0, 0]
    v1 = []
    v2 = []
    v3 = []
    v4 = []

    i = 0
    while i < N:
        w, v = map(int, input().split())
        if i == 0 or w == w1[0]:
            w1[0] = w
            w1[1] += 1
            v1.append(v)
        elif w == w1[0] + 1:
            w2[0] = w
            w2[1] += 1
            v2.append(v)
        elif w == w1[0] + 2:
            w3[0] = w
            w3[1] += 1
            v3.append(v)
        elif w == w1[0] + 3:
            w4[0] = w
            w4[1] += 1
            v4.append(v)
        i += 1

    v1.sort(reverse=True)
    v2.sort(reverse=True)
    v3.sort(reverse=True)
    v4.sort(reverse=True)

    ans = []
    for i in range(w1[1] + 1):
        for j in range(w2[1] + 1):
            for k in range(w3[1] + 1):
                for l in range(w4[1] + 1):
                    w = w1[0] * i + w2[0] * j + w3[0] * k + w4[0] * l
                    if w <= W:
                        v = sum(v1[:i] + v2[:j] + v3[:k] + v4[:l])
                        ans.append(v)

    print(max(ans))

main()


Measured memory_bytes: 9804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 100010;
int a[N];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n, q;
	cin >> n >> q;
	string s;

	cin >> s;
	for(int i = 2; i <= n; i++){
		if(s[i-2] == 'A' && s[i-1] == 'C') a[i] = 1;
		a[i] += a[i-1];
	}
	int l, r;
	while(q--){
		cin >> l >> r;
		int ans = a[r] - a[l];
		cout << ans << "\n";
	}
}	

Measured memory_bytes: 1488
R,G,B,N = [int(i) for i in input().split()]
num = 0
box = sorted([R,G,B], key=lambda x:-x)
nums = [N//b for b in box]
for i in range(nums[0]+1):
    if (nums[0]-i)*box[0] + nums[1]*box[1] + nums[2]*box[2] < N:
        break
    for j in range(nums[1]+1):
        resj = (nums[0]-i)*box[0] + (nums[1]-j)*box[1]
        if resj + nums[2]*box[2] < N:
            break
        if resj > N:
            continue
        if (N-resj)%box[2]!=0:
            continue
        num += 1
print(num)

Measured memory_bytes: 40812
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 1005;
const ld eps = 1e-9;

ll a, b, c;

int main() {
    //freopen("test.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> a >> b >> c;
    int res = 0;
    while (1) {
        if(a & 1) break;
        if(b & 1) break;
        if(c & 1) break;
        ll A = (b + c) / 2;
        ll B = (c + a) / 2;
        ll C = (a + b) / 2;
        a = A, b = B, c = C;
        res ++;
        if(res > 100000) return cout << "-1\n", 0;
    }
    cout << res << endl;
}





Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main(int argc, const char *argv[]) {
  int A, B;
  int C = 0;
  cin >> A >> B;

  if(A > B){
    cout << A + A - 1 << endl;
  }else if(A < B){
    cout << B + B - 1 << endl;
  }else{
    cout << A + B << endl;
  }

  return 0;
}


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

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


#define REP(i, n) for(int i = 0; i < n; i++) //普通のループ
#define REPTO(i, n) for(int i = 0; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--) //逆ループ
#define FOR(i, m, n) for(int i = m; i < n; i++) //最初の数値を指定

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int counter = 0;
    int a=0;
    int c=0;
    while(A>0 && C>0){
        if(counter%2!=0){
            A = A - D;
      
            a += 1;
        }
        else{
            C = C - B;
   
            c += 1; 
        }
        counter += 1;
    }
    if(A>0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int dist(const string& a, const string& b) {
  int d = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i])
      ++d;
  }
  return d;
}

int main() {
  string s;
  cin >> s;
  const int n = s.size();

  string t1;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      t1 += '0';
    } else {
      t1 += '1';
    }
  }
  string t2;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      t2 += '1';
    } else {
      t2 += '0';
    }
  }

  int ans = min(dist(s, t1), dist(s, t2));
  cout << ans << endl;

  return 0;
}


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

int main() {
  long N, M;
  cin >> N >> M;
  long ans;
  if (N == 1) {
    if (M == 1) {
      // N=1, M=1
      ans = 1;
    } else if (M == 2) {
      // N=1, M=2
      ans = 0;
    } else {
      // N=1, M>=3
      ans = M-2;
    }
  } else if (N == 2) {
    // N=2
    ans = 0;
  } else {
    if (M==1) {
      // N>=3, M=1
      ans = N-2;
    } else if (M==2) {
      // N>=3, M=2
      ans = 0;
    } else {
      // N=>3, M=>3
      ans = (N-2)*(M-2);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // This will work only for g++ compiler. 
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forab(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define pb push_back
#define fi first
#define se second
#define __builtin_popcount(x) ones(x)
#define __builtin_popcountl(x) onesl(x)
#define __builtin_popcountll(x) onesll(x)// to be used with algorithms that processes a container Eg: find(all(c
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
// int ans=0;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    int t;
    cin>>t;
    int arr[t];
    int i=0;
    while(i<t){
      cin>>arr[i];
      i++;
    }
    if(t==1){cout<<0<<endl; return 0;}
    if(t==2){
      cout<<abs(arr[0]-arr[1])<<endl;
      return 0;
    }
    vector<int> cost(t,0);
    cost[0]=0;
    cost[1]=abs(arr[0]-arr[1]);
    for(i=2;i<t;i++){
      cost[i]=min(cost[i-1]+abs(arr[i]-arr[i-1]),cost[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<cost[t-1]<<endl;
    return 0;
}


Measured memory_bytes: 3928
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((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())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){
    ll X,Y; cin >> X >> Y;
    ll ans = 0;
    while(X <= Y){
        ans++;
        X <<= 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define vin(v,n) rep(i,n)cin>>v[i];
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define sz size()
#define fi first
#define se second0
#define pb push_back
#define prqueue priority_queue<ll,vector<ll>,greater<ll>>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
int main() {
	ll a, b; cin >> a >> b; cout << (a + b) / 2 << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h> 
using namespace std;
#define endl "\n"
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef long long ll;
#define MOD 1000000007;
 
int main() 
{ 
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int h,w,k;
    cin >> h >> w >> k;
    int black = 0;
    char board[6][6];
   
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> board[i][j];
        if(board[i][j]=='#'){
          black++;
        }
      }
    }
    
    if(black < k){
      cout << 0 << endl;
      return 0;
    }

    int ans = 0;
    for(int i = 0; i < 1<<(h+w); i++){
        int n = i;
      char d[6][6];
      for(int b = 0; b < h;b++){
        for(int j = 0; j < w; j++){
          d[b][j] = board[b][j];
        }
      }
      int x = 0;
      int dblacks = black;
      while(n>0){
        int last_bit = n&1;
        if(last_bit==1 && x < h){
          for(int j = 0; j < w; j++){
            if(d[x][j]=='#'){
              d[x][j] = '.';
              dblacks--;
            }
          }
        }
        if(last_bit==1&& x >=h){
          for(int j = 0; j < h; j++){
            if(d[j][x-h]=='#'){
              d[j][x-h] = '.';
              dblacks--;
            }
          }
        }

        x++;
        n = n>>1;
      }
      if(dblacks==k){
        ans++;
      }


    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
#if loc||local
#define _GLIBCXX_DEBUG
#endif

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;
  sort(begin(a),end(a));

  ll ans = 0;
  rep(i,n)for(int j=i+1;j<n;++j)for(int k=j+1;k<n;++k){
    if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k]){
      dump(i+1,j+1,k+1,a[i],a[j],a[k]);
      ans++;
    }
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 3632
import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

long[2] dfs(int depth, long h, long w)
{
  if (depth == 2) {
    return [h * w, h * w];
  }
  long[2] ans = [long.min / 4, long.max / 4];
  // split row
  for (int i = -1; i <= 1; ++i) {
    long mh = h / 2 + i;
    if (mh <= 0) {
      continue;
    }
    long rh = h - mh;
    if (rh <= 0) {
      continue;
    }
    auto res = dfs(depth + 1, rh, w);
    long low = min(mh * w, res[0]);
    long high = max(mh * w, res[1]);
    if (ans.back - ans.front > high - low) {
      ans[0] = low;
      ans[1] = high;
    }
  }
  for (int i = -1; i <= 1; ++i) {
    long mh = h / 3 + i;
    if (mh <= 0) {
      continue;
    }
    long rh = h - mh;
    if (rh <= 0) {
      continue;
    }
    auto res = dfs(depth + 1, rh, w);
    long low = min(mh * w, res[0]);
    long high = max(mh * w, res[1]);
    if (ans.back - ans.front > high - low) {
      ans[0] = low;
      ans[1] = high;
    }
  }
  // split col
  for (int i = -1; i <= 1; ++i) {
    long mw = w / 2 + i;
    if (mw <= 0) {
      continue;
    }
    long rw = w - mw;
    if (rw <= 0) {
      continue;
    }
    auto res = dfs(depth + 1, h, rw);
    long low = min(h * mw, res[0]);
    long high = max(h * mw, res[1]);
    if (ans.back - ans.front > high - low) {
      ans[0] = low;
      ans[1] = high;
    }
  }
  for (int i = -1; i <= 1; ++i) {
    long mw = w / 3 + i;
    if (mw <= 0) {
      continue;
    }
    long rw = w - mw;
    if (rw <= 0) {
      continue;
    }
    auto res = dfs(depth + 1, h, rw);
    long low = min(h * mw, res[0]);
    long high = max(h * mw, res[1]);
    if (ans.back - ans.front > high - low) {
      ans[0] = low;
      ans[1] = high;
    }
  }
  return ans;
}

void main() {
  auto hw = readln.chomp.split.map!(to!int);
  auto res = dfs(0, hw.front, hw.back);
  stderr.writeln = res;
  writeln = res.back - res.front;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NQ = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NQ[0];
            var Q = NQ[1];
            var ablist = Enumerable.Range(0, N - 1).Select(_ => Console.ReadLine().Split(' ').Select(int.Parse).ToArray()).ToArray();
            var pxlist = Enumerable.Range(0, Q).Select(_ => Console.ReadLine().Split(' ').Select(int.Parse).ToArray());

            var parents = new int[N];
            foreach (var ab in ablist)
            {
                var a = ab[0];
                var b = ab[1];

                parents[b - 1] = a - 1;
            }

            var counters = new int[N];
            foreach (var px in pxlist)
            {
                var p = px[0];
                var x = px[1];

                counters[p - 1] += x;
            }

            for (var i = 1; i < counters.Length; i++)
            {
                counters[i] += counters[parents[i]];
            }

            Console.WriteLine(string.Join(" ", counters));
        }
    }
}


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

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

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

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

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

const ll maxn_bellmanford=2505;
vector<vll> G(maxn_bellmanford);
bool reachableFrom1[maxn_bellmanford];
void dfs(ll v){
  if(reachableFrom1[v]) return;
  reachableFrom1[v]=true;
  for(auto nv: G[v]){
    dfs(nv);
  }
}

vector<vll> rG(maxn_bellmanford);
bool reachableToN[maxn_bellmanford];
void rdfs(ll v){
  if(reachableToN[v]) return;
  reachableToN[v]=true;
  for(auto nv: rG[v]){
    rdfs(nv);
  }
}

ll n,m;
vector<tuple<ll,ll,ll>> es;
ll dist[maxn_bellmanford];
bool ok[maxn_bellmanford];

bool bellmanford(ll s){
  fill(dist,dist+n,INF);
  dist[s]=0;
  bool update=true;
  ll cnt=0;
  while(update){
    update=false;
    for(auto e: es){
      ll a,b,c;
      tie(a,b,c)=e;
      if(!ok[a]||!ok[b]) continue;
      if(chmin(dist[b],dist[a]+c)) update=true;
    }
    if(cnt>=n){
      return true; // has negative loop
    }
    cnt++;
  }
  return false;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m;
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--; c=-c;
    es.emplace_back(a,b,c);
    G[a].push_back(b);
    rG[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  rep(i,n) ok[i]=reachableFrom1[i] && reachableToN[i];
  if(bellmanford(0)){
    cout<<"inf"<<endl;
  }else{
    cout<<-dist[n-1]<<endl;
  }
}

Measured memory_bytes: 896
import copy
import itertools

k=int(input())
pos = [['.' for _ in range(8)] for _ in range(8)]
rows = [i for i in range(8)]
cols = [i for i in range(8)]

for _ in range(k):
    r,c = map(int, input().split())
    pos[r][c] = 'Q'
    rows.remove(r)
    cols.remove(c)

for c in itertools.permutations(cols):
# for c in [(6,0,7,5,1,4)]:
    temp_pos = copy.deepcopy(pos)
    
    for r_i, c_i in zip(rows, c):
        temp_pos[r_i][c_i] = 'Q'
        
    flg = True
    
    for r_i in range(8):
        for c_i in range(8):
            
            if temp_pos[r_i][c_i]=='Q':
                
                next_r,next_c = r_i,c_i
                while 0<=next_r+1<=7 and 0<=next_c+1<=7:
                    next_r+=1
                    next_c+=1
                    if temp_pos[next_r][next_c]=='Q':
                        flg = False
                        break
                    
                next_r,next_c = r_i,c_i
                while 0<=next_r-1<=7 and 0<=next_c+1<=7:
                    next_r-=1
                    next_c+=1
                    if temp_pos[next_r][next_c]=='Q':
                        flg = False
                        break
                
                next_r,next_c = r_i,c_i
                while 0<=next_r-1<=7 and 0<=next_c-1<=7:
                    next_r-=1
                    next_c-=1
                    if temp_pos[next_r][next_c]=='Q':
                        flg = False
                        break
                
                next_r,next_c = r_i,c_i
                while 0<=next_r+1<=7 and 0<=next_c-1<=7:
                    next_r+=1
                    next_c-=1
                    if temp_pos[next_r][next_c]=='Q':
                        flg = False
                        break
                        
            if not flg:
                break
        if not flg:
            break
    if flg:
        break

if flg:
    for rows in temp_pos:
        print(*rows, sep='')


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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n, k, r, s, p;
	string t;
	cin >> n >> k >> r >> s >> p >> t;
	LL ans = 0;
	for(int i = 0; i < n; ++i){
		char &c = t[i];
		if(i >= k && t[i - k] == c){
			c = '!';
		}
		else{
			ans += (c == 'r' ? p : c == 's' ? r : s);
		}
	}
	cout << ans << '\n';
}



}
int main() try{
	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 512
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<int,int> a, const pair<int,int> b) {
    return a.second < b.second;
}

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
    int N,D;

    cin >>N>>D;
    float list[11][11];

    for(int i = 0;i<N;i++){
      for(int j = 0;j < D;j++){
        cin >>list[i][j];
        }
    }

    int ans = 0;

    for(int i = 0;i<N;i++){
      for(int j = i+1;j < N;j++){
        float length = 0;
        for(int k = 0; k< D;k++){
          length += (list[j][k] - list[i][k])*(list[j][k] - list[i][k]);
        }



        if(sqrt(length) - (int)(sqrt(length)) == 0)ans++;
      }
    }

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

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;

*/

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;
#define N 100

int n ,M[N][N];
int d[N];

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for(int i=0; i<n; i++) {
        d[i] = -1;
    }
    d[s] = 0;
    int u;
    while(!q.empty()) {
        u = q.front();
        q.pop();
        for(int v=0; v<n; v++) {
            if(M[u][v]==0) {
                continue;
            }
            if(d[v]!=-1) {
                continue;
            }
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for(int i=0; i<n; i++) {
        cout << i+1 << " " << d[i] << endl;
    }
}

int main() {
    int u, k, v;

    cin >> n;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            M[i][j] = 0;
        }
    }

    for(int i=0; i<n; i++) {
        cin >> u >> k;
        u--;
        for(int j=0; j<k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);

    return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

string eq(int a, int b) {
    if (a == b) {
        return "==";
    }
    if (a > b) {
        return ">";
    }
    return "<";

}

int main() {
    int a, b;
    cin >> a >> b;

    printf("a %s b\n", eq(a, b).c_str());
}


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cstring>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 200005;
//////////////////////////////

Int n, m, l, r, a;
vector<P> interval[N];

struct Seg {
	vector<Int> sum;
	vector<Int> mx;
	Seg() {
		sum.resize(1 << 19, 0);
		mx.resize(1 << 19, 0);
	}

	void add_val(Int l, Int r, Int val, Int bottom = 0, Int top = 1 << 18, Int pos = 1)
	{
		if (l <= bottom && top <= r) {
			sum[pos] += val;
			return;
		}
		if (r <= bottom || top <= l) {
			return;
		}
		Int mid = (bottom + top) / 2;
		add_val(l, r, val, bottom, mid, pos * 2);
		add_val(l, r, val, mid, top, pos * 2 + 1);
		mx[pos] = max(mx[pos * 2] + sum[pos * 2], mx[pos * 2 + 1] + sum[pos * 2 + 1]);
	}

	Int max_val(int l, int r, int bottom = 0, int top = 1 << 18, int pos = 1)
	{
		if (l <= bottom && top <= r) {
			return sum[pos] + mx[pos];
		}
		if (r <= bottom || top <= l) {
			return -LINF;
		}
		Int mid = (bottom + top) / 2;
		return max(max_val(l, r, bottom, mid, pos * 2), max_val(l, r, mid, top, pos * 2 + 1)) + sum[pos];
	}
};


int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> a;
		interval[r].push_back(P(l, a));
	}

	Seg seg;

	for (Int i = 1; i <= n; i++) {
		Int mx = seg.max_val(0, i);
		seg.add_val(i, i + 1, mx);
		for (auto p : interval[i]) {
			Int l = p.first;
			Int a = p.second;
			seg.add_val(l, i + 1, a);
		}
	}

	cout << seg.max_val(0, n + 1) << endl;

	return 0;
}


Measured memory_bytes: 19328
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin >> n >> k;
  int h[n],c[n],i,j;
  
  for(i=0;i<n;i++)
    cin >> h[i];
  
    c[0]=0;
  
  for(i=1;i<n;i++)
  { 
    c[i]=INT_MAX;
    for(j=i-1;j>=i-k&&j>=0;j--)
    c[i]=min(abs(h[i]-h[j])+c[j],c[i]);
  }
  cout<<c[n-1];
}

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

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    int A, B;
    cin >> A >> B;
    int plug = 1;
    int cnt = 0;
    while (plug < B)
    {
        plug += A - 1;
        // cout << plug << endl;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, M, S = 0; cin >> N >> M;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i], S += A[i];

    int cnt = 0;
    for(int i=0; i<N; i++) {
        // v < S * 1 / 4M
        // v * 4M < S
        if(A[i] * 4 * M >= S) cnt++;
    }

    cout << (cnt >= M ? "Yes" : "No") << endl;
    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  if (sum % (n * (n + 1) / 2) != 0) {
    cout << "NO\n";
    return 0;
  }
  
  ll count = sum / (n * (n + 1) / 2), count2 = 0;
  for (int i = 0; i < n; i++) {
    ll dif = a.at(i) - a.at((i - 1 + n) % n);
    dif -= count;
    dif *= -1;
    if (dif < 0 || dif % n != 0) {
      cout << "NO\n";
      return 0;
    }
    count2 += dif / n;
  }
  
  if (count == count2) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 1024
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/27 14:21:08 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

// TOP
void	Main()
{
	ll	a, b;
	cin >> a >> b;

	if (abs(a - b) > 1)
	{
		cout << 0 << endl;
		return ;
	}
	ll	va, vb;
	va = 1;
	vb = 1;
	for (ll i = a; i > 1; i--)
	{
		va *= i;
		va %= MOD;
	}
	for (ll i = b; i > 1; i--)
	{
		vb *= i;
		vb %= MOD;
	}
	ll	ans = va * vb % MOD;
	if (a == b)
	{
		ans *= 2;
		ans %= MOD;
	}
	cout << ans << endl;
}
// END

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
 
int alpha[26]={};
 
bool solve(){
    int H,W;
    cin>>H>>W;
    vector<string> a(H);
    rep(y,H) cin>>a[y];
    rep(y,H)rep(x,W) {
        alpha[a[y][x]-'a']++;
    }
    
    int minus4=1,minus2=0;
    
    if(H%2==0){
        minus4 *= H/2;
        if(W%2==1) minus2 += H/2;
    }else{
        minus4 *= (H-1)/2;
        if(W%2==1) minus2 += (H-1)/2;
    }
 
    if(W%2==0){
        minus4 *= W/2;
        if(H%2==1) minus2 += W/2;
    }else{
        minus4 *= (W-1)/2;
        if(H%2==1) minus2 += (W-1)/2;
    }
 
    int set4=0,set2=0;
    rep(c,26){
        set4 += alpha[c]/4;
        set2 += (alpha[c]%4)>=2;
    }
 
    set4-=minus4;
    if(set4<0)return false;
    set2 += set4*2;
    set2 -= minus2;
    return set2>=0;
}
 
int main(void){
    cout<<(solve() ? "Yes" : "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.next().toInt()
    val a = sc.next().toInt()
    println(problem130a(x, a))
}

fun problem130a(x: Int, a: Int): Int {
    return if (x < a) 0 else 10
}

Measured memory_bytes: 29484
def func():
    return

# n = int(input())
# s = input()
a, b = map(int, input().split())
# a = list(map(int, input().split()))
# a = input().split()

ans = ""
if a <= b:
    for i in range(b):
        ans += str(a)
else:
    for j in range(a):
        ans += str(b)

print(ans)



Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N;cin>>N;
  map<int,int> mp;
  int SUM = 0;
  for (int i = 0; i < N; i++)
  {
    int X;cin>>X;
    mp[X]++;
    SUM += X;
  }
  int Q;cin>>Q;
  for (int i = 0; i < Q; i++)
  {
    int X,Y;
    cin>>X>>Y;
    int C = mp[X];
    mp[X] = 0;
    mp[Y] += C;
    SUM -= C*X;
    SUM += C*Y;

  cout<<SUM<<endl;
  }

  
  
  
  

  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

using namespace std;

#define MAX_V 15
#define INF 1e9

int V,E;
int d[MAX_V][MAX_V];
int dp[1<<MAX_V][MAX_V];

int rec(int S,int v){
  if(dp[S][v] >= 0){
    return dp[S][v];
  }
  if(S == (1<<V)-1 && v == 0){
    return dp[S][v] = 0;
  }
  int res = INF;
  for(int u = 0 ; u < V ; u++){
    if(!(S >> u & 1)){
      res = min(res,rec(S|1<<u,u) + d[v][u]);
    }
  }
  return dp[S][v] = res;
}

void init(){
  memset(dp,-1,sizeof(dp));
  fill(d[0],d[0]+MAX_V*MAX_V,INF);
}

int main(){
  init();
  cin >> V >> E;
  for(int i = 0 ; i < E ; i++){
    int a,b,c;
    cin >> a >> b >> c;
    d[a][b] = c;
  }
  int res = rec(0,0);
  cout << (res == INF ? -1 : res) << endl;
  return 0;
}

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

using namespace std;

int main(){

	long long k,a,b;
	cin >> k >> a >> b;
	if(b<=a+1 or k<=a){
		cout << k+1;
		return 0;
	}
	k-=a+1;
	if(k%2==0){
		cout << b+(k/2)*(b-a);
	}else{
		cout << b+((k-1)/2)*(b-a)+1;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int b[105];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n-1;i++) cin>>b[i];
    int ans = b[1]+b[n-1];
    for(int i=2;i<=n-1;i++)
    {
        ans += min(b[i-1],b[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256