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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n,K;

ll dp[100100];
bool used[100100];

vector<ll> G[100100];

ll solve(ll v,ll cnt,ll dep){
    ll res;
    if(dep == 0)res = K;
    else if(dep == 1)res = K - 1;
    else res = K - 2;
    res -= cnt;
    used[v] = true;
    ll c = 0;
    rep(i,G[v].size()){
        if(!used[G[v][i]]){
            res *= solve(G[v][i],c,dep+1);
            c++;
            res %= MOD;
        }
    }
    // cout << v << " " << res << endl;
    return res % MOD;
}

int main(){
    cin >> n >> K;
    rep(i,n-1){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cout << solve(0,0,0) << endl;
}

Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pw(int a, int b) {
	if (!b) return 1;
	int r = pw(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}

const int MAXN = 3e5+7;
vector< int >G[3][MAXN];
int grundy[3][MAXN];
int fr[3][MAXN];
int mx[3];

int p10[MAXN];

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

    int n, m;
    cin >> n;

    p10[0] = 1;
    const int base = pw(10, 18);
    for (int i = 1; i <= n; i++) p10[i] = mul(base, p10[i-1]);

    for (int c = 0; c < 3; c++) {
        cin >> m;
        while (m--) {
            int u, v;
            cin >> u >> v;
            if (u > v) swap(u, v);
            G[c][u].push_back(v);
        }

        for (int i = n; i > 0; i--) {
            set< int >st;
            for (int v : G[c][i]) st.insert(grundy[c][v]);

            grundy[c][i] = 0;
            for (int x : st) {
                if (x==grundy[c][i]) grundy[c][i]++;
                else break;
            }

//            cout << c << " " << i << " => " << grundy[c][i] << endl;
            fr[c][grundy[c][i]] = sum(fr[c][grundy[c][i]], p10[i]);
            mx[c] = max(mx[c], grundy[c][i]);
        }
    }

    int ans = 0;
    for (int g0 = 0; g0 <= mx[0]; g0++) {
        for (int g1 = 0; g1 <= mx[1]; g1++) {
            int g2 = g0^g1;
            if (g2 > mx[2]) continue;

            int tmp = mul(mul(fr[0][g0], fr[1][g1]), fr[2][g2]);
            ans = sum(ans, tmp);
        }
    }

//    ans = mul(ans, pw(10, 54));

    cout << ans << endl;

    return 0;
}


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

using namespace std;

long long p[100005];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long n, k, q, a;
	cin >> n >> k >> q;
	for(long long i = 0; i < n; ++i) p[i] = k;
	for(long long i = 0; i < q; ++i){
		cin >> a;
		++p[a - 1];
	}
	for(long long i = 0; i < n; ++i){
		if(p[i] - q > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}



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

const int N = 5e5 + 50;

int n, m, id[N], p[N], c[N], co[N];
std::pair<int, int> a[N];
bool active[N], qwq[N];

inline char nc()
{
	static char buf[1000000], *p1 = buf, *p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
}

inline int read()
{
	int res = 0, neg = 1; char ch;
	do
	{
		ch = nc();
		if (ch == '-') neg = -1;
	} while (ch < 48 || ch > 57);
	do res = res * 10 + ch - 48, ch = nc(); while (ch >= 48 && ch <= 57);
	return res * neg;
}

int main()
{
	n = read(), m = n * n;
	for (int i = 1; i <= n; ++i) a[i] = std::make_pair(read(), i), c[i] = i, p[a[i].first] = i, qwq[a[i].first] = true;
	std::sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) id[i] = a[i].second;
	int t = 1;
	for (int i = 1; i <= m; ++i)
	{
		if (p[i] == 0)
		{
			while (t <= n && a[t].second == 1)
			{
				++t;
			}
			if (t == n + 1) break;
			if (i >= a[t].first) { return puts("No"), 0; }
			
			p[i] = id[t]; ++co[id[t]]; --a[t].second;
		}
		else
		{
			if (co[p[i]] != p[i] - 1) return puts("No"), 0;
			active[p[i]] = true;
		}
	}
	t = 1;
	for (int i = 1; i <= m; ++i)
	{
		if (!p[i])
		{
			while (co[id[t]] == n - 1) ++t;
			++co[id[t]]; p[i] = id[t];
			if (!active[id[t]]) return puts("No"), 0;
		}
		else if (qwq[i])
		 active[p[i]] = true;
	}
	puts("Yes");
	for (int i = 1; i <= m; ++i) printf("%d ", p[i]);
	return 0;
}

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

int main(){
    int m,d; cin >> m >> d;
    int c = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= d; j++){
            int d1 = j%10, d2 = j/10;
            if(d1 >= 2 && d2 >= 2 && i == d1*d2) c++;
        }
    }   
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = [int(i) for i in input().split()]

cumsum = [0]
for v in A:
    cumsum.append(cumsum[-1]+v)

counter = defaultdict(lambda: 0)
for v in cumsum:
    counter[v] += 1

res = 0
for _, v in counter.items():
    res += (v*(v-1))//2

print(res)

Measured memory_bytes: 41472
#include<iostream>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
long long seg[262149], n, v, a, b, c, d, INF = (1LL << 31) - 1, size_ = 1;
void update(long long p, long long q, long long r, long long s, long long t, long long u, long long v) {
	if (s <= p || q <= r) { if (v != INF)seg[u] = v; return; }
	if (p <= r && s <= q) { seg[u] = t; return; }
	long long w = v; if (w == INF)w = seg[u]; seg[u] = INF;
	update(p, q, r, (r + s) / 2, t, u * 2, w);
	update(p, q, (r + s) / 2, s, t, u * 2 + 1, w);
}
long long find(long long p, long long q, long long r, long long s, long long u) {
	if (s <= p || q <= r)return INF;
	if ((r <= p && q <= s) && (seg[u] != INF || s - r == 1)) { return seg[u]; }
	long long a1 = find(p, q, r, (r + s) / 2, u * 2);
	long long a2 = find(p, q, (r + s) / 2, s, u * 2 + 1);
	return min(a1, a2);
}
int main() {
	cin >> n >> v; while (size_ < n)size_ *= 2;
	for (int i = 1; i <= size_ * 2; i++)seg[i] = INF;
	for (int i = 1; i <= v; i++) {
		scanf("%d", &a);
		if (a == 0) { scanf("%lld%lld%lld", &b, &c, &d); c++; update(b, c, 0, size_, d, 1, INF); }
		if (a == 1) { scanf("%lld", &b); printf("%lld\n", find(b, b + 1, 0, size_, 1)); }
	}
	return 0;
}

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

const ll d = 60;
const ll N = 200005;
int to[d][N];

int main(){
    ll n,k;
    cin >> n >> k;
    
    rep(i,n){
        cin >> to[0][i];
        to[0][i]--;
    }
    for(ll i=1; i<d; i++){
        rep(j,n){
            to[i][j] = to[i-1][to[i-1][j]];
        }
    }
    int v = 0;
    for(int i=d-1; i>=0; i--){
        ll l = ll(1)<<i;
        if(k-l>=0){
            k-=l;
            v = to[i][v];
        }
        //if(k == 0) break;
    }
    cout << v+1 << endl;
}

Measured memory_bytes: 50508
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int a[3][3] = {}, n, b, sum;
   string ans = "No";
   FOR(i, 0, 3)
      FOR(j, 0, 3)
         cin >> a[i][j];
   cin >> n;
   FOR(k, 0, n)
   {
      cin >> b;
      FOR(i, 0, 3)
         FOR(j, 0, 3)
         {
            if (a[i][j] == b)
               a[i][j] = 0;
         }
   }

   FOR(i,0,3)
   {
      sum = 0;
      FOR(j,0,3)
      {
         sum += a[i][j];
      }
      if(!sum)
      {
         ans = "Yes";
         break;
      }
   }
   FOR(i,0,3)
   {
      sum = 0;
      FOR(j,0,3)
      {
         sum += a[j][i];
      }
      if(!sum)
      {
         ans = "Yes";
         break;
      }
   }
   sum = 0;
   FOR(i,0,3)
   {
      sum += a[i][i];
   }
   if(!sum)
   {
      ans = "Yes";
   }
   sum = 0;
   FOR(i,0,3)
   {
      sum += a[i][2-i];
   }
   if(!sum)
   {
      ans = "Yes";
   }

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


Measured memory_bytes: 256
#pragma GCC optimize("O2")
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <functional>
#include <numeric>
#include <algorithm>
#include <map>
using namespace std;
#define mod 1000000007

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n ;
	cin >> n ;
	vector<long long> a(n);
	long long ans = 0 ;
	map<long long , long long> m;
	for (int i = 0 ; i < n ; i++) {
		cin >> a[i] ;
		ans += m[a[i] - i];
		m[-a[i] - i]++;

	}

	cout << ans << "\n";

	return 0 ;
}


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

struct activity {
    int a,b,c;
};

int solve(activity *arr,int n) {
    int dp[n+1][3];
    dp[1][0] = arr[1].a;
    dp[1][1] = arr[1].b;
    dp[1][2] = arr[1].c;
    for(int i=2;i<=n;i++) {
        dp[i][0] = arr[i].a + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = arr[i].b + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = arr[i].c + max(dp[i-1][0],dp[i-1][1]);
    }
    return max(dp[n][0],max(dp[n][1],dp[n][2]));
}

int main() {
	int n;
	cin>>n;
	activity *arr = new activity[n+1];
	for(int i=1;i<=n;i++) {
	    cin>>arr[i].a>>arr[i].b>>arr[i].c;
	}
	cout<<solve(arr,n);
	return 0;
}


Measured memory_bytes: 5904
n = int(input())
a = [0] + [int(i) for i in input().split()] + [0]

total = 0
for i in range(len(a)-1):
    total += abs(a[i+1] - a[i])
    
for i in range(n):
    ans = total + abs(a[i+2]-a[i]) - abs(a[i+1] - a[i]) - abs(a[i+2] - a[i+1])
    print(ans)

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

int main()
{

	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a[x-1] = i + 1;
	}
	for(int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 1152
import sys
import decimal
input=sys.stdin.readline

A,B,C,D=[int(x) for x in input().split()]
count=0
while A*C>0:
    if count%2==0:
        C-=B
    else:
        A-=D
    count+=1
if count%2==0:
    print("No")
else:
    print("Yes")



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

using namespace std;

#define lint long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

int A[3][105];

int main()
{
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i) scanf("%d", &A[0][i]);
    for (int i = 1; i <= N; ++i) scanf("%d", &A[1][i]);
    for (int i = 1; i <= N; ++i) A[0][i] += A[0][i - 1];
    for (int i = N; i >= 1; --i) A[1][i] += A[1][i + 1];
    int ans = 0;
    for (int i = 1; i <= N; ++i) ans = max(ans, A[0][i] + A[1][i]);
    printf("%d\n", ans);
    return 0;
}


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

    int n;
    cin>>n;
   ll arra[n+5];
    for(int i=0; i<n; i++)
    {
        cin>>arra[i];

    }
    ll  mx=0;
    mx=max(mx,arra[0]);
    ll sum=0;
    for(int i=1; i<n; i++)
    {
        mx=max(mx,arra[i]);
        sum+= mx-arra[i];


    }
    cout<<sum<<endl;


}


Measured memory_bytes: 5156
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
// 20:45-
const int MAX_N=2e5+1;
int N;
LL A[MAX_N];
//LL cum[MAX_N+1];
void solve() {
  vector<LL> cum(N+1);
  cum[0]=0;
  REP(i,N) cum[i+1]=cum[i]+A[i];
  
  LL res=1e16;
  FOR(i,2,N-1) {
    LL lsum=cum[i],rsum=cum[N]-cum[i];
    auto it1=lower_bound(cum.begin(),cum.begin()+i,lsum/2);
    int p0=it1-cum.begin();
    int P0[2]={p0,p0-1};
    auto it2=lower_bound(cum.begin()+i,cum.end(),lsum+rsum/2);
    int p1=it2-cum.begin();
    int P1[2]={p1,p1-1};
    
    REP(k1,2) REP(k2,2) {
      int p0=P0[k1],p1=P1[k2];
      if(p0==i||p0==0) continue;
      if(p1==i||p1==N) continue;
      LL P=cum[p0],Q=cum[i]-cum[p0];
//      dump3(i,lsum,rsum);
      LL R=cum[p1]-cum[i],S=cum[N]-cum[p1];
      LL x=max({P,Q,R,S})-min({P,Q,R,S});
//      dump3(i,p0,p1);
//      dump4(P,Q,R,S);
//      dump2(i,x);
      SMIN(res,x);
    }

  }
  cout<<res<<endl;
}

void bf() {
  vector<LL> cum(N+1);
  cum[0]=0;
  REP(i,N) cum[i+1]=cum[i]+A[i];
  
  FOR(i,1,N-1) FOR(j,i+1,N) FOR(k,j+1,N) {
    LL P=cum[i],Q=cum[j]-cum[i],R=cum[k]-cum[j],S=cum[N]-cum[k];
    LL x=max({P,Q,R,S})-min({P,Q,R,S});
    if(x==36) {
      dump4(i,j,k,x);
      dump4(P,Q,R,S);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
//  bf();
  return 0;
}


Measured memory_bytes: 3328
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    rep(i, 5){
        int a;
        cin >> a;
        if(a == 0){
            cout << i + 1 << endl;
            return 0;
        } 
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9+5
int min(int x,int y){
    return (x<y)?x:y;
}
int main(){
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    int k,n;
    cin>>n>>k;
    int h[n];
    vector<int> dp(n,INF);
    for(int i=0;i<n;++i)
        cin>>h[i];
    
    dp[0]=0;
    //dp[0][1]=abs(h[1]-h[0])
    for(int i=0;i<n;++i){
        for(int j=i+1;j<=i+k;++j){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int n,a,b,c,count=0;
  scanf("%d",&n);
  int l[n];
  for(int i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
    for(int i=0;i<n-2;i++){
      for(int j=i+1;j<n-1;j++){
        for(int z=j+1;z<n;z++){
          a=l[i];
          b=l[j];
          c=l[z];
          if(a<(b+c)&&b<(a+c)&&c<(a+b)){
            count++;
          }
        }
      }
    }
  printf("%d",count);
}

Measured memory_bytes: 128
import sys
N = int(input())
s = input()
def verify(s, tmpAns):
    global N
    for i in range(N):
        if (s[i] == 'o' and tmpAns[i] == 'S') \
                or (s[i] == 'x' and tmpAns[i] == 'W'):
                    if tmpAns[(i+1)%N] != tmpAns[(i-1+N)%N]:
                        return False
        elif (s[i] == 'x' and tmpAns[i] == 'S') \
                or (s[i] == 'o' and tmpAns[i] == 'W'):
                    if tmpAns[(i+1)%N] == tmpAns[(i-1+N)%N]:
                        return False
    return True

for i in range(4):
    a = 'S' if i & 1 else 'W'
    b = 'S' if i & 2 else 'W'
    tmpAns = a + b
    for j in range(N-2):
        c = s[j+1]
        a, b = tmpAns[j], tmpAns[j+1]
        # print('a: %s, b: %s, c: %s' % (a, b, c))
        if c == 'o' and b == 'W':
            tmpAns += 'W' if a == 'S' else 'S'
        elif c == 'o' and b == 'S':
            tmpAns += 'S' if a == 'S' else 'W'
        elif c == 'x' and b == 'W':
            tmpAns += 'S' if a == 'S' else 'W'
        elif c == 'x' and b == 'S':
            tmpAns += 'W' if a == 'S' else 'S'
    # print(tmpAns)
    if verify(s, tmpAns):
        print(tmpAns)
        sys.exit(0)
print(-1)


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

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

int main() {
    int N;
    scanf("%d", &N);

    int A[N];
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    qsort(A, N, sizeof(int), &compare);

    int fir = 0, sec = 0;
    for (int i = 1; i < N; i++) {
        if (A[i] == A[i - 1]) {
            if (fir == 0)
                fir = A[i];
            else {
                sec = A[i];
                break;
            }
            i++;
        }
    }

    printf("%lld", (long long int)fir * (long long int)sec);

    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll fac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n;cin >> n;
    if(n%2==0){
        vl count(n+1,0);
        rep(i,n){
            ll a;cin >>a;
            if(a>n)continue;
            count[a]++;
        }
        rep(i,n/2){
            if(count[i*2+1]!=2){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << modpow(2,n/2,MOD) << endl;
    }
    else{
        vl count(n,0);
        rep(i,n){
            ll a;cin >>a;
            if(a>n-1)continue;
            count[a]++;
        }
        count[0]++;
        rep(i,n/2+1){
            if(count[i*2]!=2){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << modpow(2,(n-1)/2,MOD) << endl;
    }
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	vector <int> L(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> L[ii];
	}
	sort(L.begin(), L.end());

	int ans = 0;
	for (int ii = 0; ii < N-2; ++ii){
		for (int jj = ii+1; jj < N-1; ++jj){
			int sum = L[ii] + L[jj];
			int idx = lower_bound(L.begin(), L.end(), sum) - L.begin();
			ans += max(0, idx - 1 - jj);
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
int main(){
  ll n,m;
  cin>>n>>m;
  vector<bool> issafe(n,true);
  rep(i,m){
    ll a;cin>>a;
    issafe[a]=false;
  }
  vector<ll> dp(n+1,0);
  dp[0]=1;
  if(issafe[1]) dp[1]=1;
  for(ll i=2;i<=n;i++){
    if(issafe[i-1]) dp[i]+=dp[i-1];
    if(issafe[i-2]) dp[i]+=dp[i-2];
    dp[i]%=1000000007;
  }
  cout<<dp[n]<<endl;
  
  
  
}

Measured memory_bytes: 1024
from collections import Counter

n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
v1_N = Counter(v1).most_common()
v2_N = Counter(v2).most_common()
if len(v1_N) == 1 and len(v2_N) == 1 and v1_N[0][0] == v2_N[0][0]:
    print(int(n/2))
elif v1_N[0] == v2_N[0]:
    print(min(n-v1_N[0][1]-v2_N[1][1],n-v1_N[1][1]-v2_N[0][1]))
else:
    print(n-v1_N[0][1]-v2_N[0][1]) 

Measured memory_bytes: 21084
S = sorted(list(set(list(input()))))
alpha = [int(i) for i in range(0,27)]
if len(S) == 26:
    print("None")
else:
    for i in range(0, 27):
        if chr(alpha[i]+97) not in S:
            print(chr(alpha[i]+97))
            break

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    string x;
    cin >> n >> x;
    int cnt = 0;
    for (int i = 0;i < n;++i) cnt += (x[i] == '1');
    reverse(x.begin(),x.end());
    vector<int> m1(n,0),m2(n,0);
    int sum1 = 0,sum2 = 0;
    m1[0] = m2[0] = 1;
    if (cnt-1) for (int i = 1;i < n;++i) m1[i] = m1[i-1]*2%(cnt-1);
    for (int i = 1;i < n;++i) m2[i] = m2[i-1]*2%(cnt+1);
    if (cnt-1) for (int i = 0;i < n;++i) if (x[i] == '1') (sum1 += m1[i]) %= cnt-1;
    for (int i = 0;i < n;++i) if (x[i] == '1') (sum2 += m2[i]) %= cnt+1;
    for (int j = 0;j < n;++j) {
        int i = n-1-j;
        int ans = 0,mod,sum;
        if (x[i] == '0') {
            mod = cnt+1;
            sum = sum2+m2[i];
            ans++;
        } else {
            mod = cnt-1;
            sum = sum1-m1[i]+mod;
            if (mod) ans++;
        }
        if (mod) sum %= mod;
        while (sum && mod) {
            int d = 0;
            for (int j = 0;j < 20;++j) if ((sum>>j)&1) d++;
            sum %= d;
            ans++;
        }
        cout << ans << newl;
    }
}

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

int main() {
	int w, h;
	char a, b;

	while (true) {
		cin >> h >> w;
		if ( (h == 0)&&(w == 0)) break;
		b = '#';
		for (int i=0; i<h; i++) {
			a = b;
			for (int j=0; j<w; j++) {
				cout << a;
				a =  (a == '#') ? '.' : '#';
			}
			cout << "\n";
			b =  (b == '#') ? '.' : '#'; 
		}
		cout << "\n";
	}
	return 0;

}

Measured memory_bytes: 3076
def d_DigitSum(N, S):
    if S == N:
        # f(b,N)=Nを満たすbはN+1が最小
        return N + 1
    if S > N:
        return -1

    from math import sqrt, floor, ceil

    def f(b, n):
        if n < b:
            return n
        else:
            return f(b, n // b) + (n % b)

    sn = ceil(sqrt(N))
    # 2<=b<=√Nまで探索
    for b in range(2, sn + 1):
        if f(b, N) == S:
            return b
    # √N<=b<=Nまで探索
    for p in range(sn, 0, -1):
        if (N - S) % p == 0:
            b = (N - S) // p + 1
            if f(b, N) == S:
                return b
    return -1
N = int(input())
S = int(input())
print(d_DigitSum(N, S))

Measured memory_bytes: 3064
def main():
    N = int(input())
    A = [int(arg) for arg in input().split()]
    ans = 1

    for i in range(N):
        if A[i] == 0:
            print(0)
            return

    for i in range(N):
        ans *= A[i]
        if ans > 10**18:
            print(-1)
            return

    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
    string S;
    cin >> S;
    if (S[0] != 'A')
    {
        S.insert(0, "A");
    }
    if (S.size() < 5)
    {
        cout << "NO" << endl;
        return 0;
    }
    if (S[4] != 'A')
    {
        S.insert(4, "A");
    }
    if (S.size() < 6)
    {
        cout << "NO" << endl;
        return 0;
    }
    if (S[6] != 'A')
    {
        S.insert(6, "A");
    }
    if (S.size() < 8)
    {
        cout << "NO" << endl;
        return 0;
    }
    if (S[8] != 'A')
    {
        S.insert(8, "A");
    }
    if (S != "AKIHABARA")
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 3608
N =  int(input())
y8 = 0

def ifdivisor(num):
    divisors = []
    for i in range(1,N+1):
        if num % i == 0:
            divisors.append(i)
    return divisors

for i in range(1,N+1,2):

    if len(ifdivisor(i)) == 8:
        y8 = y8 + 1

print(y8)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
    int n; cin>>n;
    ll m=INF,sum=0;
    FOR(i,0,n){
        ll a,b; cin>>a>>b;
        sum+=a;
        if(a>b) m=min(m,b);
    }
    if(m==INF) co(0);
    else co(sum-m);
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>

typedef long long ll;

using namespace std;

int ans = 0;
int N = 0;
int M = 0;
bool visited[9];
vector<int> adj[9];

void dfs(int v) {
    bool f = true;
    for (int i = 1; i <= N; i++) {
        if (!visited[i]) {
            f = false;
            break;
        }
    }

    if (f) {
        ans++;
        return;
    }

    for (auto u : adj[v]) {
        if (!visited[u]) {
            visited[u] = true;
            dfs(u);
            visited[u] = false;
        }
    }

    return;
}


int main(void) {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int ai, bi; cin >> ai >> bi;
        adj[ai].push_back(bi);
        adj[bi].push_back(ai);
    }

    visited[1] = true;
    dfs(1);
    cout << ans << endl;
}


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

int main(){
  long long int N, K;
  long long int mod = 1e9+7;
  cin >> N >> K;
  long long int A[N];
  for(int i = 0; i < N; i++){
    cin >> A[i];
    //cout << A[i] << endl;
  }
  long long int A1[N], A2[N];
  for(int i = 0; i < N-1; i++){
    long long int count = 0;
    for(int j = i+1; j < N; j++){
      if(A[i] > A[j]){
        count++;
      }
    }
    A1[i] = count;
    //cout << count << endl;
  }
  A1[N-1]=0;
  
  for(int i = 0; i < N; i++){
    long long int count = 0;
    for(int j = 0; j < N; j++){
      if(A[i] > A[j] && i != j){
        count++;
        //cout << i << j << A[i] << A[j] << endl;
      }
    }
    A2[i] = count;
    //cout << count << endl;
  }
  long long int ans= 0, ans1=0, ans2=0;
  for(int i = 0 ; i < N; i++){
    ans1 += A1[i]*K;
    ans1 = ans1%mod;
  }
  for(int i = 0; i < N; i++){
    ans2 += A2[i]*(((K-1)*K/2)%mod);
    ans2 = ans2%mod;
  }
  ans = ans1+ans2;
  ans = ans%mod;
  cout << ans; //<< ' '<<ans1<<' '<<ans2<< endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=2e5+5; 
struct node{
	int x,p,type;
	node(){}
	node(int _x,int _p,int _type) : x(_x),p(_p),type(_type) {}
	inline bool operator <(const node &rhs)const{
		return x<rhs.x;
	}
}a[N<<1];
int vis[N],pre0[N],pre1[N];
ll pre[N];
int main(){
	ri n,m,i,x,flag;
	gi(n);
	for(i=1;i<=n;++i)
		gi(x),
		a[i]=node(x,i,0),
		gi(x),
		a[i+n]=node(x,i,1);
	m=n<<1;
	sort(a+1,a+1+m);
	flag=0;
	for(i=1;i<=n;++i){
		pre[i]=pre[i-1]+a[i].x;
		if(vis[a[i].p])
			flag=1;
		vis[a[i].p]=1;
		pre0[i]=pre0[i-1]+(a[i].type==0);
		pre1[i]=pre1[i-1]+(a[i].type==1);
	}
	if(flag||pre0[n]==n||pre1[n]==n)
		return printf("%lld\n",pre[n]),0;
	if(a[n].p!=a[n+1].p||pre0[n-1]+(a[n+1].type==0)==n||pre1[n-1]+(a[n+1].type==1)==n)
		return printf("%lld\n",pre[n-1]+a[n+1].x),0;
	printf("%lld\n",min(pre[n-2]+a[n].x+a[n+1].x,pre[n-1]+a[n+2].x));
	return 0;
}

Measured memory_bytes: 11904
// ?´??????°????§£

#include <iostream>
#include <cmath>
using namespace std;

bool isPrime(int x) {
  if(x == 2) return true;

  if(x < 2 || x % 2 == 0) return false;

  int i = 3;
  while(i <= sqrt(x)) {
	if(x % i == 0) return false;
	i += 2;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";

  while(n > 1) {
    for(int i = 2; ; ++i) {
      if(isPrime(n)) {
        cout << " " << n;
        n /= n;
        break;
      }
      if(isPrime(i) && n % i == 0) {
        n /= i;
        cout << " " << i;
        break;
      }
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3092
def read_values():
    return map(int, input().split())


def read_list():
    return list(map(int, input().split()))


def f():
    N = int(input())

    for a in range(int(N ** 0.5) + 1, 0, -1):
        if N % a != 0:
            continue
        b = N // a
        print(a + b - 2)
        return


if __name__ == '__main__':
    f()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    string s;
    cin >> s;
    string divide[4] = {"maerd", "remaerd", "esare", "resare"};
    reverse(s.begin(),s.end());
    bool can = true;
    for(int i = 0;i < s.size();)
    {
        bool can2 = false;
        for(int j = 0;j<4;++j)
        {
            string t = divide[j];
            if(s.substr(i,t.size()) == t)
            {
                can2 = true;
                i += t.size();
            }

        }
        
        if(!can2)
        {
            can = false;
            break;
        }
    }
    cout << (can ? "YES\n" : "NO\n");

}

Measured memory_bytes: 512
#! /usr/bin/python
# -*- coding: utf-8 -*-

N = int(raw_input())
while N != 0:
	p = []
	a = []
	for i in range(N):
		p.append(map(int, raw_input().split()))
	M = int(raw_input())
	for i in range(M):
		a.append(raw_input().split())
	cnt = 0
	used = [False]*N
	cur = [10, 10]
	for i in range(M):
		for j in range(int(a[i][1])):
			if a[i][0] == 'N':
				cur[1] += 1
			elif a[i][0] == 'E':
				cur[0] += 1
			elif a[i][0] == 'S':
				cur[1] -= 1
			elif a[i][0] == 'W':
				cur[0] -= 1
			for k in range(N):
				if cur == p[k] and used[k] == False:
					used[k] = True
					cnt += 1
	if cnt == N:
		print "Yes"
	else:
		print "No"
		
	N = int(raw_input())

Measured memory_bytes: 4272
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#define ll long long
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l)for(int i=r;i>=l;i--)
using namespace std;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	double a;
	double sum=0;
	double ant;
	cin >> n;
	rep(i, 1, n)
	{
		cin >> a;
		sum += 1.0 / a;
	}
	cout << 1.0 / sum << endl;
}

Measured memory_bytes: 256
def resolve():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort(reverse=True)
    sm =sum(A)
    A= A[0:M]

    for i in A:
        if i * 4* M < sm:
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll
typedef long long ll;

const int md = 1000000007;
const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "YES" : "NO";
}



int main(){
    char s; cin >> s;

    switch (s)
    {
        case 'A':
            cout << 'T' << endl;
            break;
        case 'T':
            cout << 'A' << endl;
            break;

        case 'G':
            cout << 'C' << endl;
            break;

        case 'C':
            cout << 'G' << endl;
            break;

        default:
            break;
    }
    

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s,t;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  string u;
  cin>>u;
  if(s == u)a--;
  else if(t==u)b--;
  cout<<a<<" "<<b<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    std::string s;
    long ans = 0;
    std::cin >> s;
    for (int i=0; i<s.size()-1; ++i) {
        if (s[i] != s[i+1]) ++ans;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

template<class T>
struct BellmanFord {
    const T INF = numeric_limits<T>::max() / 2 - 1;
    vector<vector<pair<int, T>>> edges;
    int vertex_number;
    bool iinc = false;
    vector<vector<bool>> reachable;
    
    BellmanFord(int n) : edges(n) {
        vertex_number = n;
    }
    
    void add_edge(int from, int to, T cost) {
        edges[from].emplace_back(to, cost);
    }
    
    vector<T> get_distance(int from, int to = -1) {
        vector<T> dist(vertex_number, INF);
        dist[from] = 0;
        for (int i = 0; i < vertex_number; i++) {
            for (int ii = 0, e = edges.size(); ii < e; ii++) {
                if ((to != -1) && (!is_reachable(from, ii))) continue;
                for (int iii = 0, ee = edges[ii].size(); iii < ee; iii++) {
                    if ((to != -1) && (!is_reachable(edges[ii][iii].first, to))) continue;
                    if ((dist[ii] + edges[ii][iii].second) < dist[edges[ii][iii].first]) {
                        if (i != (vertex_number - 1)) {
                            dist[edges[ii][iii].first] = dist[ii] + edges[ii][iii].second;
                        }
                        else {
                            iinc = true;
                            break;
                        }
                    }
                }
            }
        }
        return dist;
    }
    
    bool is_include_negative_circle() {
        return iinc;
    }
    
    void get_reachable_dfs(int from, int to) {
        if (reachable[from][to]) return;
        reachable[from][to] = true;
        for (pair<int, T> e : edges[to]) {
            get_reachable_dfs(from, e.first);
        }
    }
    
    void get_reachable() {
        for (int i = 0; i < reachable.size(); i++) {
            get_reachable_dfs(i, i);
        }
    }
    
    bool is_reachable(int from, int to) {
        if (reachable.size() == 0) {
            reachable.resize(vertex_number, vector<bool>(vertex_number, false));
            get_reachable();
        }
        return reachable[from][to];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, m, p;
    cin >> n >> m >> p;
    BellmanFord<ll> bf(n);
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        c = (c - p) * -1;
        bf.add_edge(a, b, c);
    }
    auto dist = bf.get_distance(0, n - 1);
    if (bf.is_include_negative_circle()) {
        cout << -1 << endl;
    }
    else {
        cout << max(0LL, dist[n - 1] * -1) << endl;
    }
    return 0;
}


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

int main()
{
string s,t,u;
int a,b;
cin>>s>>t>>a>>b>>u;
if(s==u){
    a--;
}
else if(t==u){
    b--;
}
cout<<a<<" "<<b;
    return 0;
}

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

int main() {
    long long int n, k;
    cin >> n >> k;
    while(abs(n - k) < n){
        if(n - k > k){
            n %= k;
            continue;
        }
        n = min(n, abs(n - k));
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int k;
    cin >> k;
    if (k%2==0 || k%5==0) {
        puts("-1");
        return 0;
    }
    ll s = 0;
    rep(i, k) {
        s *= 10;
        s += 7;
        s %= k;
        if (s==0) {
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
int main(){
  int i, j, n, flag, ans=1, con=1000000007;
  cin >> n;
  int a[n];
  for(i=0; i<n; i++)
    cin >> a[i];
  sort(a, a+n);
  if(n%2==1){
    for(i=0; i<n; i++){
      if(a[i]!=2*((i+1)/2)){
	cout << 0;
	return 0;
      }
    }
    for(i=0; i<(n-1)/2; i++)
      ans=2*ans%con;
    cout <<setprecision(12)<< ans;
    return 0;
  }
  else{
    for(i=0; i<n; i++){
      if(a[i]!=1+2*(i/2)){
	cout << 0;
	return 0;
      }
    }
    for(i=0; i<n/2; i++)
      ans=2*ans%con;
    cout <<setprecision(12)<< ans;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 640
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

#define N_MAX (200000)
typedef pair<QWORD, QWORD>	PAIR;
QWORD N;
QWORD qwArray[N_MAX];
PAIR maxArray[2];

void maxCmp(QWORD n)
{
	if (n > maxArray[0].first) {
		PAIR maxTmp = maxArray[0];
		maxArray[0] = make_pair(n, 1);
		maxArray[1] = maxTmp;
	} else if (n == maxArray[0].first) {
		maxArray[0].second++;
	} else {
		if (n > maxArray[1].first) {
			maxArray[1].first = n;
		}
	}

}

QWORD outputExceptMax(QWORD qwExcNum) {
	if (qwExcNum != maxArray[0].first) {
		return maxArray[0].first;
	} else {
		if (maxArray[0].second > 1) {
			return maxArray[0].first;
		} else {
			return maxArray[1].first;
		}
	}

}

void solve_main()
{
	cin >> N;
	REP (i, 0, N) {
		cin >> qwArray[i];
		maxCmp(qwArray[i]);
	}

	REP (i, 0, N) {
		cout << outputExceptMax(qwArray[i]) << endl;
	}

}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}


Measured memory_bytes: 3200
INF = 10**10


def merge(ary, left, mid, right):
    lry = ary[left:mid]
    rry = ary[mid:right]
    lry.append(INF)
    rry.append(INF)

    cnt = 0
    i = 0
    j = 0
    for k in range(left, right):
        if lry[i] <= rry[j]:
            ary[k] = lry[i]
            i += 1
        else:
            ary[k] = rry[j]
            j += 1
            cnt += len(lry) - 1 - i

    return cnt


def merge_sort(ary, left, right):
    cnt = 0
    if left + 1 < right:
        mid = (left + right) // 2
        cnt += merge_sort(ary, left, mid)
        cnt += merge_sort(ary, mid, right)
        cnt += merge(ary, left, mid, right)

    return cnt


if __name__ == '__main__':
    n = int(input())
    ary = [int(_) for _ in input().split()]
    print(merge_sort(ary, 0, n))



Measured memory_bytes: 27480
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
    int n,m,s,t;cin>>n>>m>>s>>t;
    vvi edge(n+1);
    rep(i,m){
        int a,b;cin>>a>>b;
        edge[a].pb(b);
        edge[b].pb(a);
    }

    vi depth(n+1,-1);
    depth[s]=0;
    queue<int> que; que.push(s);
    int ms=0;
    while(!que.empty()){
        int f=que.front();
        ms=depth[f];
        for(auto to:edge[f]){
            if(depth[to]==-1){
                depth[to]=depth[f]+1;
                que.push(to);
            }
        }
        que.pop();
    }
    int mt=0;
    vi depth2(n+1,-1);
    depth2[t]=0;
    que.push(t);
    while(!que.empty()){
        int f=que.front();
        mt=depth2[f];
        for(auto to:edge[f]){
            if(depth2[to]==-1){
                depth2[to]=depth2[f]+1;
                que.push(to);
            }
        }
        que.pop();
    }
    vvi ds(ms+1);
    range(i,1,n+1){if(depth[i]!=-1)ds[depth[i]].pb(i);}
    //for(auto l:ds){for(auto i:l)cout<<i<<",";cout<<endl;}
    vvi dt(mt+1);
    range(i,1,n+1){if(depth2[i]!=-1)dt[depth2[i]].pb(i);}
    //for(auto l:dt){for(auto i:l)cout<<i<<",";cout<<endl;}
    
    ll ans=0;
    for(int i=0;i<depth[t]-1;i++){
        ans+=ds[i].size()*dt[depth[t]-2-i].size();
    }

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


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

int main()
{
    int s, tmp, diff,ans=99999;
    string str,num1,num2,num3,sum;
    cin >> str;
    s = str.size();

    for (int i = 0; i < s - 2; i++)
    {
        num1 = str.at(i);
        num2 = str.at(i+1);
        num3 = str.at(i + 2);
        sum = num1 + num2 + num3;
        tmp = stoi(sum);
        diff = abs(753 - tmp);
        if(ans>diff){
            ans = diff;
        }
        //cout << diff <<" "<<ans<< endl;

    }
    cout << ans << endl;



    /*

    for (int i = 0; i < S;i++){
        cout << ans.at(i) << endl;
        cout << abs(ans.at(i) - 753) << endl;
    }
    */
}

Measured memory_bytes: 256