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

#define rep(i,n)  for(int i=0;i<n;++i)
#define per(i,n)  for(int i=n-1;i>=0;--i)
#define sc1(a)  scanf("%d",&a)
#define sc2(a,b)  scanf("%d %d",&a,&b)
#define sc3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define sl1(a)  scanf("%lld",&a)
#define sl2(a,b)  scanf("%lld %lld",&a,&b)
#define sl3(a,b,c)  scanf("%lld %lld %lld",&a,&b,&c)
#define PI 3.1415926535897932

//typedef long long ll;


int lcm(int a,int b) { return a*b/__gcd(a,b); }
//ll lcm(ll a,ll b) { return a*b/__gcd(a,b); }

/**
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/


int main(){
    int n;
    bool card[4][13];
    rep (i,4) rep (j,13) card[i][j]=0;
    sc1(n);

    rep(i,n) {
        char c[10];
        int x;
        scanf("%s %d",c,&x);
        if (*c=='S') card[0][x-1]=1;
        if (*c=='H') card[1][x-1]=1;
        if (*c=='C') card[2][x-1]=1;
        if (*c=='D') card[3][x-1]=1;
    }
    rep (i,4) rep(j,13) {
        if (card[i][j]==0) {
            if (i==0) printf("S %d\n",j+1);
            if (i==1) printf("H %d\n",j+1);
            if (i==2) printf("C %d\n",j+1);
            if (i==3) printf("D %d\n",j+1);

        }
    }
    return 0;
}



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

//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)
//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();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B, C;

    cin >> A >>B >> C;

    bool flag = false;


    for (int i = 1; i <= B; i++){
        if( (A * i) % B == C ){
            flag = true;
        }
    }

    if(flag){ cout << "YES" << endl;}
    else{ cout << "NO" << endl;}

    return 0;
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second

const ll mod = 1e9+7;

ll Pow(ll a, ll b)
{
	ll x = 1;
	for (; b > 0; b >>= 1)
	{
		if (b & 1) x = a * x % mod;
		a = a * a % mod;
	}
	return x;
}

ll comb(ll n, ll k)
{
	ll x = 1;
	for (ll i = n-k+1; i <= n; ++i)
		x = x * i % mod;
	ll y = 1;
	for (ll i = 1; i <= k; ++i)
		y = y * i % mod;
	return x * Pow(y, mod-2) % mod;
}

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll n, a, b;
	cin >> n >> a >> b;
	cout << ((Pow(2, n) - 1 - comb(n, a) - comb(n, b)) % mod + mod) % mod << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define ALL(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cout << __FILE__ << ":" << __LINE__ << endl;

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

int gcd(int a, int b) {
    if (a < b) a, b = b, a;
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

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

    map< pair<int, int>, int > M;
    reps(1, i, N+1) {
        string s = to_string(i);
        int a = (int)s[0];
        int b = (int)s[s.size()-1];
        auto p = make_pair(a, b);
        M[p]++;
    }

    int ans = 0;
    reps(1, i, N+1) {
        string s = to_string(i);
        int a = (int)s[0];
        int b = (int)s[s.size()-1];
        auto p = make_pair(b, a);
        ans += M[p];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <iostream> 
#include <queue>
#include <memory.h>
#include <math.h>
#include <vector>
#include <string>
#include <assert.h>
#include <algorithm>
using namespace std;

const int mod = 998244353;
#define N 200002
#define ll long long

int mul(int x, int y) {
	return (ll)x*y%mod;
}

int add(int x, int y) {
	int ret = (x + y);
	if (ret < 0) {
		ret += mod;
	}
	if (ret >= mod) {
		ret -= mod;
	}
	return ret;
}
int res[N];
void solve() {
	int n;
	string s;
	cin >> n >> s;
	int g = n; while (g % 2 == 0)g /= 2;
	int v = n / g;
	int pos = 0;
	int ar[N];
	for (int i = 1; i <= g; ++i) {
		if (g%i == 0) {
			ar[pos++] = i;
		}
	}
	int cc = 0;
	for (int i = 0; i < n; ++i) {
		cc = mul(cc, 2);
		cc = add(cc, s[i] - '0');
	}
	cc = add(cc, 1);
	int ret = 0;
	for (int i = 0; i < pos; ++i) {
		int size = n/ar[i];
		int bucket = ar[i];
		int tmp = 0;
		string tt[2];
		for (int j = 0; j < size; ++j) {
			tmp = mul(tmp, 2);
			tmp = add(tmp, s[j] - '0');
			tt[0] += s[j];
			if (s[j] == '0') {
				tt[1] += '1';
			}
			else {
				tt[1] += '0';
			}
		}
		string k;
		for (int x = 0; x < bucket; ++x) {
			k += tt[ (x &1)];
		}
		if (s >= k) {
			tmp = add(tmp, 1);
		}
		res[bucket] = tmp;
	}
	for (int i = g; i >= 1; --i) {
		if (g%i == 0 && res[i] > 0) {
			for (int j = i + i + i; j <= g; j += i) {
				if (g%j==0) {
					res[i] = add(res[i], -res[j]);
				}
			}
			int u = (n * 2) / i;
			ret = add(ret, mul(u, res[i]));
		}
	}
	printf("%d\n", ret);
}
int main() {
	//freopen("input.txt", "r", stdin);
	solve();
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;

const int MAXN = 1000*1000 + 7;
const int SS = 1<<20;
const long long INF = 1000*1000*1000 + 7;

long long nast[MAXN], cost[MAXN];
bool odw[MAXN];
long long n, m, q, k;

vector<int> akt;
vector<long long> pref;

void DFS(int v)
{
	odw[v] = true;
	akt.pb(v);
	if( odw[nast[v]] == false )
		DFS(nast[v]);
}

long long maks()
{
	long long m0 = akt.size();
	long long sum = 0;
	for(int i = 0; i < m0; i++)
		akt.pb(akt[i]), sum += cost[akt[i]];
	int m = akt.size();
	long long res = -(INF*INF);
	for(long long d = 1; d <= min(m0, k); d++)
	{
		long long akt_sum = 0, res_akt = 0;
		int i = 0;
		for(; i < d; i++)
			akt_sum += cost[akt[i]];
		res_akt = akt_sum;
		for(; i < m; i++)
		{
			akt_sum += cost[akt[i]];
			akt_sum -= cost[akt[i - d]];
			res_akt = max(akt_sum, res_akt);
		}

		res = max({res_akt + sum*((k - d)/m0), res_akt, res});
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int T;
	//cin >> T;
	T = 1;
	while(T--)
	{
		cin >> n >> k;
		for(int i=1; i<=n; i++)
			cin >> nast[i];
		for(int i=1; i<=n; i++)
			cin >> cost[i];

		long long res = -(INF*INF);
		for(int i=1; i<=n; i++)
		{
			if(odw[i])
				continue;
			akt.clear();
			pref.clear();
			DFS(i);
			res = max(maks(), res);
		}
		cout << res << '\n';
	}
	return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;

	vector<int> A(N);
	rep(i, 0, N)cin >> A[i];
	sort(all(A), greater<int>());

	int ans = 0;
	int cnt = 0;
	rep(i, 0, N)
	{
		if (i == 0)
		{
			ans += A[i];
			cnt = 1;
		}
		else
		{
			rep(j, 0, 2)
			{
				if (cnt < N - 1)
				{
					ans += A[i];
					cnt++;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size(), num = 0;
  vector<int> ans(n+1,0);
  for(int i=0; i<n; ++i){
    if(s[i] == '<') ans[i] = 0;
    while(s[i] == '<'){
      ++i;
      ans[i] = ans[i-1] +1;
    }
  }
  for(int i=n-1; i>=0; --i){
    if(s[i] == '>') ans[i+1] = 0;
    while(s[i] == '>'){
      ans[i] = max(ans[i], ans[i+1] +1);
      --i;
    }
  }
  ll tot = 0;
  for(int i=0; i<n+1; ++i) tot += ans[i];
  cout << tot << endl;
}

Measured memory_bytes: 5728
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>
#define L(_i,_N) for(int _i=0;_i<_N;_i++)
#define C(_Dis) cout<<_Dis<<endl;

using namespace std;

typedef long long int lli;

int main() {
	int n,Count=0;
	while (cin >> n) {
		vector<bool> ch(n+1);
 		for (int i = 2; i <= n; i++) ch[i] = true;
		for (int i = 2; i <= n; i++) {
			if (ch[i]) Count++;
			for (int j = i * 2; j <= n; j += i) ch[j] = false;
		}
		C(Count);
		Count = 0;
	}
	return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // マージソートとクイックソートの結果を比べる
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



Measured memory_bytes: 4052
#include <stdio.h>
int main(){
  int r,d,x,a,s,i;
  scanf("%d %d %d",&r,&d,&x);
  s=x;
  for(i=0;i<10;i++){
    a=r*s-d;
    s=a;
    printf("%d\n",a);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Set;

const int RLEN=1<<18|1;
inline char nc() {
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
    char ch=nc(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
    return i*f;
}

const int N=3e5+50;
int n,a[N][3],inv0,inv1,flip0,flip1;
int p0[N],p1[N];
inline void calc(int &inv,int *p,int nn) {
    Set S;
    static int pos[N];
    for(int i=1;i<=nn;i++) pos[p[i]]=i;
    for(int i=1;i<=nn;i++) S.insert(i);
    for(int i=1;i<=nn;i++) {
        inv+=S.order_of_key(pos[i]+1)-1;
        inv%=2; S.erase(pos[i]);
    } return;
}
int main() {
    n=rd(); 
    for(int j=0;j<3;j++) for(int i=1;i<=n;i++) a[i][j]=rd()-1;
    for(int i=1;i<=n;i+=2) {
      //  cerr<<i<<'\n';
        if(a[i][0]/6!=a[i][1]/6 || a[i][0]/6!=a[i][2]/6) {puts("No"); return 0;}
        else if(a[i][1]%6!=1) {puts("No"); return 0;}
        else if(a[i][0]%6+a[i][2]%6!=2) {puts("No"); return 0;}
        if(a[i][0]%6) ++flip1;
        p1[(i+1)/2]=a[i][0]/6+1;
    }
    for(int i=2;i<=n;i+=2) {
        if(a[i][0]/6!=a[i][1]/6 || a[i][0]/6!=a[i][2]/6) {puts("No"); return 0;}
        else if(a[i][1]%6!=4) {puts("No"); return 0;}
        if(a[i][0]%6==5) ++flip0;
        p0[i/2]=a[i][0]/6+1;
    }
    calc(inv0,p0,n/2); calc(inv1,p1,(n+1)/2);
    if((inv0^flip1)&1) {puts("No"); return 0;}
    if((inv1^flip0)&1) {puts("No"); return 0;}
    puts("Yes"); return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <queue>
#define to first
#define cost second
const int inf=1e9+7;
using namespace std;
int main(){

  int n,tmp,r=0,flag[100]={},v=0;
  cin>>n;
  vector <pair<int,int> > gl[n];
  priority_queue <pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > >q;
  //for(int i=1;i<n;i++) mincost[i]=inf;                                                                                                                                                       

  for(int i=0;i<n;i++) for(int j=0;j<n&&cin>>tmp;j++) if(tmp!=-1) gl[i].push_back(make_pair(j,tmp));
  int now=0;
  for(int j=0;j<n-1;j++){
    for(int i=0;i<gl[now].size();i++) if(!flag[gl[now][i].to]) q.push(make_pair(gl[now][i].cost,gl[now][i].to));
    flag[now]=1;
    // cout<<now<<" "<<q.top().first<<endl;                                                                                                                                                    
    for(;flag[q.top().second]||q.empty();) q.pop();
    if(q.empty()) break;
    r+=q.top().first;
    now=q.top().second;
    q.pop();
  }
  cout<<r<<endl;
  return 0;

}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
const long long INF = 1LL << 60;
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; }

int main(){
    int X, Y;
    cin >> X >> Y;
    bool ans = false;
    rep(turu, X+1){
        int kame = X - turu;
        if(turu*2+kame*4==Y) ans = true;
    }
    cout << ((ans) ? "Yes" :"No") << endl;
    return 0;    
}

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

int convert[10][10];

int main() {
    int H,W;
    cin >> H >> W;

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

    // わーしゃる
    for (int k=0; k<10; k++) {
        for (int i=0; i<10; i++) {
            for (int j=0; j<10; j++) {
                convert[i][j] = min(convert[i][j], convert[i][k] + convert[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            int a; cin >> a;
            if (a != -1) {
                ans += convert[a][1];
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int f(int i){
	int out;
	if(i>30)out=160;
	else if(i>20)out=140;
	else if(i>10)out=125;
	return out;	
}
int main(){
	int n;
	while(cin>>n,n+1){
		int sum=1150;
		int out=4280;
		loop(i,11,n+1)sum+=f(i);
		cout<<out-sum<<endl;
	}
}

Measured memory_bytes: 1160
#include <stdio.h>

int main(void) {
	int n,b,f,r,v;
	int inf[4][3][10];
	int i,j,k;
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				inf[i][j][k]=0;
			}
		}
	}
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		inf[b-1][f-1][r-1]+=v;
	}
	for(i=0;i<4;i++){
		for(j=0;j<3;j++){
			for(k=0;k<10;k++){
				printf(" %d",inf[i][j][k]);
			}
			printf("\n");
		}
		if(i!=3) printf("####################\n");
	}
	
	return 0;
}



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

const long long MOD = 67280421310721LL;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

inline long long mul(long long a, long long b, long long m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    long long res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}

inline long long inv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a/b;
        a = mod(a - mul(t, b, m), m); swap(a, b);
        u = mod(u - mul(t, v, m), m); swap(u, v);
    }
    return mod(u, m);
}

int main() {
  long long res = 0;
  int N; cin >> N;
  for (int i = 0; i < N; ++i) {
	long long o, y; cin >> o >> y;
	if (o == 1) res = mod(res + y, MOD);
	else if (o == 2) res = mod(res - y, MOD);
	else if (o == 3) res = mul(res, y, MOD);
	else res = mul(res, inv(y, MOD), MOD);
  }
  if (res <= 1LL<<31) cout << res << endl;
  else cout << res - MOD << endl;
}



Measured memory_bytes: 3096
import math
N = int(input())

tax_rate=1.08
x = N/tax_rate
f = math.floor(x)
c = math.ceil(x)

if math.floor(f*tax_rate)==N:
	print(f)
elif math.floor(c*tax_rate)==N:
	print(c)
else:
	print(":(")

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int m;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> m;
		ans += min(m, abs(m - k)) * 2;
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
 int N;
 cin >> N;
 vector<int> H(N);
 for(int i = 0;i < N;i++)cin >> H.at(i);
 reverse(H.begin(), H.end());
 bool r = true;
 for(int i = 1;i < N;i++){
   if(H.at(i) == H.at(i - 1) + 1){
     H.at(i) -= 1;}
   else if(H.at(i) - H.at(i - 1) >= 2){
     r = false;
     break;}
 }
  if(r == true){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
     
}


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

int main() {
    long long N;
    cin >> N;
    long long ans =  1 + N - 2;
    long long X = pow(N,0.5);
    for (int i = 2;i < X + 1;i++){
        if (N % i == 0){
            if (ans > i + (N / i) - 2) ans = i + (N / i) - 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  var query = false
  var s = ""
  var a = new ArrayBuffer[(Int,Int)]
  while( { s = readLine.trim;s } != "0,0" ) {
    val n = s.split(",").map(_.toInt)
    a += ((n(1),n(0)))
  }
  val g = a.groupBy(n=>n._1).mapValues(_.map(_._2)).toSeq.sortWith(_._1 > _._1)
  try {
    while(true) {
      val n = readInt
      println(g.indexWhere(i => i._2.exists( i => i==n ))+1)
    }
  } catch { case e:Exception => Nil }
}

Measured memory_bytes: 44164
import numpy as np
N,M,X=map(int,input().split())
  
C=[[0 for i in range(M)] for j in range(N)]
for i in range(N):
    #C=[[0 for i in range(M)] for j in range(2**N)]
    C[i] = list(map(int, input().split()))
    #print(array)
    #np.insert(C[i],0,array)
D=np.array(C)
E=[0]*2**N

for i in range(2**N):
  c=format(i,'012b')
  for j in range(N):
    d=int(c[12-N+j])
    E[i]+=D[j]*int(d)
#print(E)

#for i in range(2**M):
if min(E[-1][1:M+1])<X:
  print(-1);exit()
    
Max=E[-1][0]+1
Min=Max
for i in range(2**N):
  if min(E[i][1:M+1])>=X:
    if Min>E[i][0]:Min=E[i][0]
    continue
  else:E[i][0]=Max
#print(E)
print(Min)
exit()

Measured memory_bytes: 27972
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    long long a[6],A,i,s=0,j;
    for(i=0; i<6; i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+6);
    if(a[0]%a[1]!=0)
        A=a[0]/a[1]+1;
    else
        A=a[0]/a[1];
    s=A+4;
    printf("%lld",s);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fst first
#define snd second
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define for_tests(t, tt) int t; scanf("%d", &t); for(int tt = 1; tt <= t; tt++)
#ifndef ONLINE_JUDGE
#define debug(args...) fprintf(stderr,args)
#else
#define debug(args...)
#endif //ONLINE_JUDGE
template<typename T> inline T abs(T t) { return t < 0? -t : t; }
const ll modn = 1000000007;
inline ll mod(ll x) { return x % modn; }

const int MAXN = 212345;

int n, m, k;
char s[MAXN];

int main (){
	scanf(" %s", s);
	n = strlen(s);
	ll res = 0;
	for(ll a=0;a<(1<<(n-1));a++){
		int pos[20];
		memset(pos, 0, sizeof(pos));
		for(ll i=0;i<n;i++){
			if(a&(1ll<<i)){
				pos[i] = 1;
			}
		}
		ll cur = 0;
		for(int i=0;i<n;i++){
			cur *= 10ll;
			cur += s[i]- '0';
			if(pos[i]){
				res += cur;
				cur = 0;
			}
		}
		res += cur;
	}
	printf("%lld\n", res);
}


Measured memory_bytes: 256
//#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
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 int INF = 2e9;
const ll LINF = (1LL<<60);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,x,m;
  cin >> n >> x >> m;
  vector<ll> tmp(m);
  REP(i,m) tmp[i] = i*i % m;

  ll sum = 0;
  vector<bool> seen(m, false);
  vector<ll> path;
  REP(i,n){
    if(seen[x]){
      int ind = 0;
      while(path[ind]!=x) ind++;
      int cyc = SIZE(path) - ind;
      ll cyc_sum = 0;
      FOR(j,ind,SIZE(path)) cyc_sum += path[j];
      sum += cyc_sum * ll((n-i)/cyc);
      REP(j,(n-i)%cyc) sum += path[j+ind];
      break;
    }

    sum += x;
    seen[x] = true;
    path.push_back(x);
    x = x*x % m;
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4612
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N, M; cin >> N >> M;
  priority_queue<unsigned long, vector<unsigned long>, greater<unsigned long>> que;

  for (int i = 0; i < N; i++) {
    unsigned long A; cin >> A;
    que.push(A);
  }

  vector<pair<unsigned long, unsigned long>> v; // <val, cnt>
  for (int i = 0; i < M; i++) {
    unsigned long B, C; cin >> B >> C;
    v.push_back(make_pair(C, B));
  }
  sort(v.begin(), v.end());

  int idx = v.size()-1;
  unsigned long ans = 0;
  while (!que.empty()) {
    int org = que.top(); que.pop();
    int val = org;
    if (idx >= 0) {
      if (org < v[idx].first && v[idx].second > 0) {
	val = v[idx].first;
	v[idx].second--;
	if (v[idx].second == 0) {
	  idx--;
	}
      } else {
	idx--;
      }
    }
    ans += val;
  }
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
int n, m, dp[100000];
vector<int> adj[100000];
int calc(int u) {
	if(dp[u] != -1) return dp[u];
	int res = 0;
	for(auto v : adj[u]) res = max(res, calc(v) + 1);
	return dp[u] = res;
}
int main() {
	R(n, m);
	for(int i = 0; i < m; i++) {
		int u, v;
		R(u, v); u--; v--;
		adj[u].push_back(v);
	}
	memset(dp, -1, sizeof(dp));
	int ans = 0;
	for(int i = 0; i < n; i++) ans = max(ans, calc(i));
	W(ans);
	return 0;
}

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

int main(){
    int N, M;
    vector<Int> X(1010), Y(1010), Z(1010);
    cin >> N >> M;
    rep(i,N) cin >> X[i] >> Y[i] >> Z[i];

    Int ans = 0; 
    rep(bits, 8){
        bool x = bits&1, y = (bits>>1)&1, z = (bits>>2)&1;

        vector<Int> cakes; 
        rep(i, N){
            Int now = 0;
            if(x) now += X[i]; else now -= X[i];
            if(y) now += Y[i]; else now -= Y[i];
            if(z) now += Z[i]; else now -= Z[i];
            
            cakes.push_back(now);
        }
        sort(cakes.begin(), cakes.end(), greater<Int>());

        Int sum = 0;
        rep(i, M) sum += cakes[i];

        ans = max(ans, sum);
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
using System;

namespace ITP1_3_C
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                String[] inputs = Console.ReadLine().Split(' ');
                int x = Convert.ToInt32(inputs[0]);
                int y = Convert.ToInt32(inputs[1]);

                if (x == 0 && y == 0) break;

                if (x < y)      Console.WriteLine(x + " " + y);
                else            Console.WriteLine(y + " " + x);
            }
        }
    }
}

Measured memory_bytes: 5872
n = int(input())
x = list(map(int, input().split()))

x = sorted(x)

mi = 0
for i in range(len(x)):
    mi += (x[i] - x[0])**2

for j in range(x[0], x[-1]+1):
    temp = 0
    for i in range(len(x)):
        temp += (x[i] - j)**2

    mi = min(temp, mi)

print(mi)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {


	public static boolean hantei(int N, int t, int T, int x, int X, int y, int Y) {
		boolean plan = false;
		int rt = t - T;
		int dist = x + y - X - Y;
		if(rt >= dist && ((rt-dist)%2 == 0)) {
			plan = true;
		}
		return plan;
	}


	public static void main(String[] args) {
		int N,t,x,y;
		int T = 0;
		int X = 0;
		int Y = 0;
		boolean plan;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		for(int i = 0; i < N; i++) {
			t = sc.nextInt();
			x = sc.nextInt();
			y = sc.nextInt();
			plan = hantei(N, t, T, x, X, y, Y);
			if(!plan){
				System.out.println("No");
				System.exit(0);
			}
			T = t;
			X = x;
			Y = y;
		}
		System.out.println("Yes");
		sc.close();
	}
}


Measured memory_bytes: 87340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
   int n,temp;
  cin >> n; 
   vint w(n);
   rep(i,n) cin >> w[i] ;
   int min = 1000000000;
   auto itr = w.begin();
   for(int i = 0; i < n-1 ; i++) {
       temp = abs(accumulate(w.begin(),itr+i+1,0) - accumulate(itr+i+1,w.end(),0));
       if(temp < min) min = temp;
   }
   cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


ll mp[Max];


void primefact(ll n)
{

    ll cnt=0;

    while(n%2==0)
    {
        n/=2;
        cnt++;
    }

    mp[2]=max(mp[2],cnt);

    cnt=0;


    for(ll i=3; i<=sqrt(n); i+=2)
    {
        cnt=0;

            while(n%i==0)
            {
                n/=i;

                cnt++;
            }

            mp[i]=max(mp[i],cnt);

    }

    if(n>2)
        mp[n]=max(mp[n],1ll);
}
ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}
int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0,dasdasdads;

      bool flag=false;

      string str;


        cin>>n;

        ll ara[n+2];

        input(ara,n);

        sum=accumulate(ara,ara+n,0);


        cout<<sum-n<<endl;













}


Measured memory_bytes: 3676
N = int(input())
D = [[0]]*N
for i in range(N):
  D[i] = list((int(x) for x in input().split()))
for i in range(N-2):
  if D[i][0]==D[i][1] and D[i+1][0]==D[i+1][1] and D[i+2][0]==D[i+2][1]:
    print('Yes')
    break
else:
  print('No')

Measured memory_bytes: 9156
import itertools
from collections import Counter

N, C = map(int, input().split())

mat_D = [list(map(int, input().split())) for _ in range(C)]
mat_c = [list(map(int, input().split())) for _ in range(N)]

zero = []
one = []
two = []

for i, row in enumerate(mat_c):
    for j, col in enumerate(row):
        if (i+j+2) % 3 == 0:
            zero.append(col)
        elif (i+j+2) % 3 == 1:
            one.append(col)
        else:
            two.append(col)

zero_dict = dict(Counter(zero))
one_dict = dict(Counter(one))
two_dict = dict(Counter(two))
a = [zero_dict, one_dict, two_dict]


def make_color_patterns():
    color_pats = list(itertools.permutations(list(range(1, C + 1)), 3))
    return color_pats


def calc_D(i, col):
    aa = a[i]
    D = 0
    for k, v in aa.items():
        D += mat_D[k-1][col-1] * v
    return D


# print(mat_D, mat_c)

color_pats = make_color_patterns()

ans = float("inf")
for color_pat in color_pats:
    # print(color_pat)
    D0 = calc_D(0, color_pat[0])
    D0 = calc_D(0, color_pat[0])
    D1 = calc_D(1, color_pat[1])
    D2 = calc_D(2, color_pat[2])
    D = D0 + D1 + D2
    # print(D)
    ans = min(D, ans)

print(ans)


Measured memory_bytes: 60508
#include <iostream>
using namespace std;
long long ans[100];

int main(){
    ans[0] = 2;
    ans[1] = 1;
    for(int i = 2 ; i <= 86 ; i++)  ans[i] = ans[i-1] + ans[i-2];
    int n;
    cin>>n;
    cout<<ans[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut it = s.split_whitespace();
	let s: Vec<_> = it.next().unwrap().chars().collect();
	let t: Vec<_> = it.next().unwrap().chars().collect();
	let mut dp = vec![vec![0u16; t.len() + 1]; s.len() + 1];
	for i in 0..s.len() {
		for j in 0..t.len() {
			if s[i] == t[j] {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			} else {
				dp[i + 1][j + 1] = std::cmp::max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}
	let mut ans = vec![];
	let mut i = s.len();
	let mut j = t.len();
	while i > 0 && j > 0 {
		if dp[i][j] == dp[i - 1][j] {
			i -= 1;
		} else if dp[i][j] == dp[i][j - 1] {
			j -= 1;
		} else {
			ans.push(s[i - 1]);
			i -= 1;
			j -= 1;
		}
	}
	println!("{}", ans.into_iter().rev().collect::<String>());
}


Measured memory_bytes: 19836
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	string s;
	cin >> s;
	map<char,int> m;
	rep(i,s.size()){
		m[s[i]]++;
	}
	rep(i,26){
		if(m['a'+i]&1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
from fractions import Fraction
import math
N = int(input())
ans = Fraction(4,N)
point = [1,math.floor(N/4)]
for h in range(max(point),3501):
    h_pro = Fraction(1,h)
    check = ans - h_pro
    target = [math.floor(4*h-N/N*h),h]
    for n in range(h,3501):
        check = ans - h_pro
        n_pro = Fraction(1,n)
        check -= n_pro
        if type(check) == "int":
            if check ==1:
                print(h, end=" ")
                print(n, end=" ")
                print(1)
                exit()
        elif check.numerator == 1:
            print(h, end=" ")
            print(n, end=" ")
            print(check.denominator)
            exit()

Measured memory_bytes: 81248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ins insert
#define Pq priority_queue
#define u_set unordered_set
#define MOD 1e9+7
#define MAXN 100001
#define set_val(arr,v) memset(arr, v, sizeof(arr))
#define FOR(i,from,to) for(int i=from; i<to; i++)
#define FOL(i,from,to) for(int i=from; i>=to; i--)
#define B() begin()
#define E() end()
#define F first
#define S second
//  int  __builtin_popcount(unsigned int)

int main() {
	ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
	int h,w,n;
	cin >> h >> w >> n;
	h = max(h,w);
	cout << n/h + (n%h ? 1 : 0) << endl;
	return 0; 
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
bool vis[100005];
int co[100005];
string s;
int main(){
    int a,b;
    cin>>a>>b;
    int t;
    int cnt1=0;
    int cnt2=0;
    for(int i=1;i<=b;i++){
        cin>>t>>s;
        if(s[0]=='W'&&!vis[t])co[t]++;
        if(s[0]=='A'&&!vis[t]){
            cnt1++;
            vis[t]=1;
        }
    }
    for(int i=1;i<=100005;i++)
        if(vis[i])
            cnt2+=co[i];
    cout<<cnt1<<" "<<cnt2<<endl;
    return 0;
}

Measured memory_bytes: 768
a,b = map(int,input().split())
c = 0
if a == 3:
    c += 1
elif a == 2:
    c += 2
elif a == 1:
    c += 3

if b == 3:
    c += 1
elif b == 2:
    c += 2
elif b == 1:
    c += 3

if a == b == 1:
    c += 4

print(c*100000)

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

typedef long long int ll;

int main(){


    int n;
    cin >> n;
    //vector<int> a(n);
    int tmp;
    int count = 0;
    int count2 = 0;
    for(int i = 0;i < n;i++){
        cin >> tmp;
        if(tmp%4 == 0){
            count++;
        }else if(tmp % 2 == 0){
            count2++;
        }
    }
    if(count + count2/2 >= n/2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    size_t n, p[20];

    scanf("%zu\n", &n);
    for (size_t i = 0; i < n; i++) {
        scanf("%zu", &(p[i]));
        if (i < n - 1) {
            scanf(" ");
        }
    }

    size_t cnt = 0;
    for (size_t i = 0; i < n - 2; i++) {
        if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i + 2] < p[i + 1] && p[i + 1] < p[i])) {
            cnt++;
        }
    }

    printf("%zu", cnt);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
using ld = long double;

template <typename T>
class UnionFind {
 private:
  vector<T> parent;
  vector<T> group_size;

 public:
  UnionFind(T size_) : parent(size_), group_size(size_, 1) {
    iota(parent.begin(), parent.end(), 0);
  }

  T root(T x) { return parent[x] == x ? x : parent[x] = root(parent[x]); }

  void merge(T x, T y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (group_size[x] < group_size[y]) swap(x, y);
    group_size[x] += group_size[y];
    parent[y] = x;
  }

  bool same(T x, T y) { return root(x) == root(y); }
  T size(T x) { return group_size[root(x)]; }
};

void solve(int N, int M, int K, vector<int> A, vector<int> B, vector<int> C,
           vector<int> D) {
  // friends
  vector<set<int>> friends(N);
  UnionFind<int> u(N);
  for (int i = 0; i != M; ++i) {
    auto a = A[i] - 1;
    auto b = B[i] - 1;
    friends[a].insert(b);
    friends[b].insert(a);
    u.merge(a, b);
  }

  vector<set<int>> blocks(N);
  for (int i = 0; i != K; ++i) {
    auto c = C[i] - 1;
    auto d = D[i] - 1;
    blocks[c].insert(d);
    blocks[d].insert(c);
  }

  for (int i = 0; i != N; ++i) {
    auto ans = u.size(i) - 1;
    for (auto x : friends[i]) {
      if (u.same(i, x)) --ans;
    }
    for (auto x : blocks[i]) {
      if (u.same(i, x)) --ans;
    }
    cout << (i ? " " : "") << ans;
  }
  cout << endl;
}

int main() {
  int N;
  cin >> N;
  int M;
  cin >> M;
  int K;
  cin >> K;
  vector<int> A(M);
  vector<int> B(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
    cin >> B[i];
  }
  vector<int> C(K);
  vector<int> D(K);
  for (int i = 0; i < K; i++) {
    cin >> C[i];
    cin >> D[i];
  }
  solve(N, M, K, move(A), move(B), move(C), move(D));
  return 0;
}


Measured memory_bytes: 31360
def main(n: int, a: int, b: int):
    if a > b:
        print(0)
        return

    if n == 1:
        if a == b:
            print(1)
        else:
            print(0)
        return

    if n == 2:
        if a > b:
            print(0)
        else:
            print(1)
        return

    print((n - 2) * (b - a) + 1)


if __name__ == "__main__":
    n, a, b = map(int, input().split())

    main(n, a, b)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

map<int, int> mp;

int dfs(int d, multiset<int> &st){
    if(d == 13){
        int mn = 100000000;
        vector<int> vec;

        for(auto it = st.begin(); it != st.end(); it++){
            vec.push_back(*it);
        }

        /*for(int i = 0; i < vec.size(); i++){
            cout << vec[i] << " ";
        }
        cout << endl;
        */
        int sz = vec.size();
        for(int i = 0; i < sz; i++){
            for(int j = i + 1; j < sz; j++){
                mn = min(mn, min(vec[j] - vec[i], 24 - (vec[j] - vec[i])));
            }
        }

        return mn;
    }

    int ret = 0;

    if(mp[d] >= 3){
        ret = 0;
    }
    else if(mp[d] == 2){
        st.insert(d);
        st.insert(24 - d);
        ret = dfs(d + 1, st);
        auto it = st.find(d);
        st.erase(it);
        it = st.find(24 - d);
        st.erase(it);
    }
    else if(mp[d] == 1){
        st.insert(d);
        int c1 = dfs(d + 1, st);
        st.erase(d);
        st.insert(24 - d);
        int c2 = dfs(d + 1, st);
        st.erase(24 - d);
        ret = max(c1, c2);
    }
    else if(mp[d] == 0){
        ret = dfs(d + 1, st);
    }

    return ret;
}

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

    mp[0]++;
    for(int i = 0; i < N; i++) mp[d[i]]++;

    multiset<int> st;

    cout << dfs(0, st) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
	
	char S [30]; char T [30]; char N [30];
		int a, b;
			scanf("%s %s", &S, &T);
			scanf("%d %d", &a, &b);
			scanf("%s", &N);
	
	if (strcmp(S, N)==0) {
			printf("%d %d", a-1,b);
	}
	else if (strcmp(T,N)==0) {
			printf("%d %d", a,b-1);
	}

	return 0;
}

Measured memory_bytes: 1704
import java.io.*;
import java.util.*;
import java.util.Collections;
 
class Main{
    public static void main(String[] a) throws Exception{
    	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    	Integer[] mountains=new Integer[10];
    	for(int i=0;i<10;i++){
    		mountains[i]=Integer.valueOf(br.readLine());
    	}
    	Arrays.sort(mountains, Collections.reverseOrder());
		for(int i=0;i<3;i++){
			System.out.println(mountains[i]);
		}    	
    }
}

Measured memory_bytes: 24320
a,b,k = map(int,input().split())
import fractions
n = fractions.gcd(a,b)
divisor = []
for i in range(int(n/2)+1):
  if n % (i+1) == 0:
    divisor.append(i+1)
divisor.append(n)
print(divisor[-k])




Measured memory_bytes: 5048
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()

int main()
{
  int n;
  cin>>n;
  vi a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  sort(all(a));
  cout << a.at(n - 1) - a.at(0) << endl;

  return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        long answer = (n + 1) / 2 - 1;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

const ll INF = 1LL<<60;

int main() {
  int n, w;
  cin >> n >> w;
  vector<int> weight(n), value(n);
  rep(i,n) cin >> weight[i] >> value[i];
  vector<vector<ll>> dp(110, vector<ll>(100100, INF));
  dp[0][0] = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 100100; j++) {
      if(j - value[i] >= 0) {
        dp[i+1][j] = min(dp[i+1][j], dp[i][j - value[i]] + weight[i]);
      }
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }
  ll ans = 0;
  rep(i,100100) {
    if(dp[n][i] <= w) ans = i; 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 90340