akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

void solve(int a, int b);

int main()
{
  int a, b;

  scanf("%d %d", &a, &b);
  solve(a, b);

  return 0;
}

void solve(int a, int b)
{
  printf("%d\n", (int)ceil((a + b) / 2.0));
}

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

int main(){
  int N;
  cin>>N;
  int A[N];
  int B[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
    B[i]=A[i];
  }
  sort(A,A+N);
  reverse(A,A+N);
  for(int i=0;i<N;i++){
    if(B[i]==A[0]){
      cout<<A[1]<<endl;
    }else{
      cout<<A[0]<<endl;
    }
  }
}


Measured memory_bytes: 5184
#include <algorithm>
#include <bitset>
#include <deque>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <iostream>
using namespace std;
#define forall(i,a,b)               for(int i=a;i<=b;i++)
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
typedef long long lli;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef map<char,int> mci;
typedef map<int,int> mii;
typedef priority_queue<int>	pqi;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef set<int> si;
typedef set<char> sc;
const long MOD = 1000000007;
int main()
{
	int n,m;
	cin>>n>>m;
	map<int,vector<int>>final;
	forall(i,0,m-1)
	{
		int x,y;
		cin>>x>>y;
		final[x].push_back(y);
	}
	vector<int>aa=final[1];
	bool isis=0;
	forall(i,0,aa.size()-1)
	{
		vector<int>bb=final[aa[i]];
		 std::vector<int>::iterator it;
  		 it = find (bb.begin(), bb.end(), n);

		if(it!=bb.end()){
		isis=1;
		break;}
	}
	if(isis==1)
	{
		cout<<"POSSIBLE"<<endl;
	}
	else
	{
		cout<<"IMPOSSIBLE"<<endl;
	}
}


Measured memory_bytes: 19832
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const objvs =(a)=>{const b=[];for(const v in a){b.push(a[v])}return b};const deduplicate=(a):any[]=>{return Array.from(new Set(a))};
const main=()=>{
  let [a,b]=tss(2),s='';
  for(let i=0;i<a.length;i++){
    s+=b[i]?a[i]+b[i]:a[i]
  }
  to(s)
}
main()


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  VEC<int> csA(N, 0);
  csA[0] = S[0] == 'A' ? 1 : 0;
  REP(i, 1, N) {
    csA[i] = csA[i - 1];
    if (S[i] == 'A') csA[i]++;
  }
  VEC<int> csAC(N, 0);
  // REP(i, 1, N) {
  //   csAC[i] = csAC[i - 1];
  //   if (S[i] == 'C') csAC[i] += csA[i - 1];
  // }
  REP(i, 1, N) {
    csAC[i] = csAC[i - 1];
    if (S[i - 1] == 'A' && S[i] == 'C') csAC[i]++;
  }
  DUMP(csA);
  DUMP(csAC);
  REP(i, 0, Q) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    int ans = 0;
    if (S[l] == 'C' && S[l - 1] == 'A') --ans;
    ans += csAC[r] - (l - 1 >= 0 ? csAC[l - 1] : 0);
    cout << ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

ll dp[1000001][4];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll mod = 1e9+7;

    dp[0][0]=1;
    for(int i=1; i<=n; i++)
       {
           dp[i][0] =  (8*dp[i-1][0]) % mod;
           dp[i][1] =  (dp[i-1][0] + dp[i-1][1]*9) %mod;
           dp[i][2] =  (dp[i-1][0] + dp[i-1][2]*9) %mod;
           dp[i][3] =  (dp[i-1][1] + dp[i-1][2] + dp[i-1][3]*10) %mod;
       }

    cout<<dp[n][3];
}


Measured memory_bytes: 34784
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
int main(){
  string s;
  cin >> s;
  s += 'T';
  int x, y;
  cin >> x >> y;
  vector< vector<int> > L(2);
  vector<int> S(2,0);
  int d = 0, t = 0;
  for(int i = 0; i < s.length(); ++i){
    if(s[i] == 'T'){
      L[d].push_back(t);
      S[d] += t;
      t = 0;
      d = 1 - d;
    }else{
      ++t;
    }
  }
  if(S[0] < x || S[1] < y){
    cout << "No" << endl;
    return 0;
  }
  x = abs(x-S[0]);
  y = abs(y-S[1]);
  if(x%2 || y%2){
    cout << "No" << endl;
    return 0;
  }
  x /= 2;
  y /= 2;
  bitset<8001> dp_x = 1, dp_y = 1;
  for(int i = 1; i < L[0].size(); ++i) dp_x |= (dp_x<<(L[0][i]));
  for(int i = 0; i < L[1].size(); ++i) dp_y |= (dp_y<<(L[1][i]));
  if(dp_x[x] && dp_y[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j;
  ll n; cin>>n;
  //ll a,b,c,d,e,f; cin>>a>>b;
  //ll a,b,c,d,e,f; cin>>a>>b>>c;
  //ll a,b,c,d,e,f; cin>>a>>b>>c>>d;
  //string s; cin >> s;
  ll result = 0;
  ll buf = 0;
  bool judge = true;
  //cout<<48-n<<endl;
  vector<ll> hash(250001);
  for(i=2;i<250001;i++){
    for(j=2,judge=true;j*j<=i;j++){
      if(i%j==0){
        judge=false;
        break;
      }
    }
    if(judge)hash[i] = 1;
    //cout<<i spa hash[i]<<endl;
  }
  vector<ll> b(250001);
  for(i=1;i*2-1<=250000;i++){
    if(hash[i]==1&&hash[i*2-1]==1)b[i*2-1]=1;
  }
  for(i=1;i*2-1<=250000;i++){
    //if(b[i]==1){cout<<i<<endl;}
    b[i]+=b[i-1];
  }
  vector<ll> l(n),r(n);
  for(i=0;i<n;i++){
    cin>>l[i]>>r[i];
  }
  for(i=0;i<n;i++){
    cout<<b[r[i]]-b[l[i]-1]<<endl;
  }
  

  return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
typedef complex<ftype> point;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

const int MAXN = 2e5+3;
const int MOD = 1e9+7;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a,b;
    cin >> a >> b;
    if (b == 1) FAIL0;
    if (b <= a) {cout << 1 << endl; return 0;}

    b -= a;
    int ans = b/(a-1) + 1;
    if (b%(a-1)) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _   int v, int tl, int tr, int l, int r
#define tm  (tl + tr >> 1)
#define sol v+v, tl, tm, l, r
#define sag v+v+1, tm+1, tr, l, r
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 1e5 + 5;    

char s[55];
signed main(){  
    int n;
    scanf("%d %s", &n, s+1);
    int ans = 3;
    int p = 1;
	for(int i=1; i<=n; i++){
        if(s[i] == s[i+1]){
            if(p == 1) ans = ans * 2 % mod;
            else ans = ans * 3LL % mod;
            i++;
            p = 2;
        }
        else{
            if(p == 1 && i > 1) ans = ans * 2 % mod;	
            p = 1;
        }
    }
    
    cout << ans;
    return 0;
}

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

int main() {
  ll n;
  cin >> n;

  vector<ll> l(n);
  for (ll i = 0; i < n; i++) {
    cin >>l[i];
  }

  sort(l.begin(), l.end());

  ll ans = 0;
  for (ll i = 0; i < n - 2; i++) {
    for (ll j = i + 1; j < n - 1; j++) {
      ll k = upper_bound(l.begin(), l.end(), l[i] + l[j] - 1) - l.begin() - 1;
      ans += k - j;
    }
  }

  cout << ans << endl;
}


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

#define M 100005
#define MOD 100000000
#define PI 3.14159265358979323846
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;
typedef pair<lli,lli> PLL;

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

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


	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;

	int first = h1*60 + m1;
	int second = h2*60 + m2;

	int ans = abs(first-second)-k;
	cout<<ans<<"\n";

}


Measured memory_bytes: 3652
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	vector<pair<int,int> >v;
	int n,s,r;
	for(;scanf("%d,%d",&n,&s),n;)v.push_back(make_pair(-s,n));
	sort(v.begin(),v.end());
	map<int,int>m;
	r=1,m[v[0].second]=r,s=v[0].first;
	for(n=1;n<v.size();m[v[n].second]=r,n++)if(s<v[n].first)s=v[n].first,r++;
	for(;~scanf("%d",&n);)printf("%d\n",m[n]);
}

Measured memory_bytes: 0
<?php

fscanf(STDIN,"%d %d",$n,$d);
$count=0;
for($i=1;$i<=$n;$i++){
    fscanf(STDIN,"%d %d",$x,$y);
    if($d>=sqrt($x*$x+$y*$y)){
        $count+=1;
    }
}
echo $count;

Measured memory_bytes: 16128
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;

char a[10];
int main()
{
	scanf("%s",a);
	bool flag = false;
	if(a[0] == a[1] && a[1] == a[2]) flag = 1;
	if(a[1] == a[2] && a[2] == a[3]) flag = 1;
	if(flag)	puts("Yes\n");
	else	puts("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int w,h,x,y,r;
	int a[4];
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

	a[0] = x + r;
	a[1] = y + r;
	a[2] = x - r;
	a[3] = y - r;

	if(a[0] - w > 0){
		printf("No\n");
	}else if(a[1] - h > 0){
		printf("No\n");
	}else if(a[2] < 0){
		printf("No\n");
	}else if(a[3] < 0){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
long long a[200001];
int main()
{
	int n;
	cin>>n;
	cin>>a[1];
	long long ans=0;
	for(int i=2;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]<a[i-1])
		{
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5172
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++) 
 
 
int dp[32][32][32][32][3];
int hyou[32][32];
int Sh[32][32];
int sumH(int x1, int y1, int x2, int y2) {
	if (x1 == 0 and y1 == 0) {
		return Sh[y2][x2];
	}
	if (x1 == 0) {
		return (Sh[y2][x2] - Sh[y1 - 1][x2]);
	}
	if (y1 == 0) {
		return Sh[y2][x2] - Sh[y2][x1 - 1];
	}
	return Sh[y2][x2] - Sh[y2][x1 - 1] - Sh[y1 - 1][x2] + Sh[y1 - 1][x1 - 1];
}
 
int main() {
	int H, W, S, k;
	while (cin >> H >> W >> k, H) {
		S = 0;
		rep(i, H) {
			rep(j, W) {
				int a;
				cin >> a;
				hyou[i][j] = a;
				S += a;
			}
		}
		rep(i, H) {
			rep(j, W) {
				if (i == 0 and j == 0) Sh[i][j] = hyou[i][j];
				else if (i == 0) Sh[i][j] = hyou[i][j] + Sh[i][j - 1];
				else if (j == 0) Sh[i][j] = hyou[i][j] + Sh[i - 1][j];
				else Sh[i][j] = Sh[i][j - 1] + Sh[i - 1][j] - Sh[i - 1][j - 1] + hyou[i][j];
			}
		}
		int m = S - k;
		rep(w, W) {
			rep(h, H) {
				rep(x, W) {
					if (x + w >= W) break;
					rep(y, H) {
						if (y + h >= H) break;
						int s = sumH(x, y, x + w, y + h);
						if (s >= S - k) {
							dp[y][x][y + h][x + w][0] = s;
							dp[y][x][y + h][x + w][1] = 1;
							dp[y][x][y + h][x + w][2] = k - (S - s);
						}
						else {
							dp[y][x][y + h][x + w][0] = s;
							dp[y][x][y + h][x + w][1] = 0;
							dp[y][x][y + h][x + w][2] = k - (S - s);
						}
						for (int w2 = x; w2 < x + w ; w2++) {
							if (dp[y][x][y + h][w2][1] + dp[y][w2 + 1][y + h][x + w][1] > dp[y][x][y + h][x + w][1]) {
								dp[y][x][y + h][x + w][1] = dp[y][x][y + h][w2][1] + dp[y][w2 + 1][y + h][x + w][1];
								dp[y][x][y + h][x + w][2] = min(dp[y][x][y + h][w2][2], dp[y][w2 + 1][y + h][x + w][2]);
							}
							else if (dp[y][x][y + h][w2][1] + dp[y][w2 + 1][y + h][x + w][1] == dp[y][x][y + h][x + w][1]) {
								dp[y][x][y + h][x + w][2] = max(dp[y][x][y + h][x + w][2], min(dp[y][x][y + h][w2][2], dp[y][w2 + 1][y + h][x + w][2]));
							}
						}
						for (int h2 = y; h2 < h + y; h2++) {
							if (dp[y][x][h2][x + w][1] + dp[h2 + 1][x][y + h][x + w][1] > dp[y][x][y + h][x + w][1]) {
								dp[y][x][y + h][x + w][1] = dp[y][x][h2][x + w][1] + dp[h2 + 1][x][y + h][x + w][1];
								dp[y][x][y + h][x + w][2] = min(dp[y][x][h2][x + w][2], dp[h2 + 1][x][y + h][x + w][2]);
							}
							else if (dp[y][x][h2][x + w][1] + dp[h2 + 1][x][y + h][x + w][1] == dp[y][x][y + h][x + w][1]) {
								dp[y][x][y + h][x + w][2] = max(dp[y][x][y + h][x + w][2], min(dp[y][x][h2][x + w][2], dp[h2 + 1][x][y + h][x + w][2]));
							}
						}
					}
				}
			}
		}
		cout << dp[0][0][H - 1][W - 1][1] << " " << dp[0][0][H - 1][W - 1][2] << endl;
	}
}


Measured memory_bytes: 13464
#include<iostream>
using namespace std;
const int MOD=1000000007;
int main(){
  long long n,k;
  cin>>n>>k;
  long long res=0;
  for(long long i=k;i<=n+1;++i){
    long long first=i*(i-1)/2;
    long long final=(n*2-i+1)*i/2;
    long long add=final-first+1;
    res=(res+add)%MOD;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll arr[3005];
ll dp[3005][3005][3];
ll solve(ll i,ll j,ll turn)
{
	if(i>j)
	return 0;
	else if(i==j&&turn==2)
	return 0;
	else if(i==j&&turn==1)
	return arr[i];
	else if(dp[i][j][turn]!=-1)
	return dp[i][j][turn];
	else
	{
		if(turn==1)
		return dp[i][j][1]=max(arr[i]+solve(i+1,j,2),arr[j]+solve(i,j-1,2));
		else
		return dp[i][j][turn]=min(solve(i+1,j,1),solve(i,j-1,1));
	}
}
int main()
{
		ll n;
		cin>>n;
		ll sum=0;
		for(ll i=0;i<n;i++)
		{
		cin>>arr[i];
		sum+=arr[i];
		}
		memset(dp,-1,sizeof(dp));
		ll x=solve(0,n-1,1);
		cout<<x-(sum-x)<<endl;
		return 0;
	}
		

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

#define MOD 1000000007

int A[2002];

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N, K;
    cin >> N >> K;

    for(int i=1; i<=N; i++)
        cin >> A[i];
    
    long long ans = 0;

    for(int i=1; i<=N; i++)
        for(int j=1; j<i; j++)
            if(A[j] > A[i])
                ans++;
    
    ans = ans * K % MOD;

    for(int i=1; i<=N; i++)
    {
        int curr = 0;

        for(int j=1; j<=N; j++)
            if(A[j] > A[i])
                curr++;
        
        ans += 1LL * K * (K-1) / 2 % MOD * curr % MOD;
    }

    cout << ans % MOD << "\n";
    return 0;
}


Measured memory_bytes: 256
import itertools as it
import sys

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

a=[]

for i in range(M):
    x,y=map(int,input().split())
    a.append([x,y])
    a.append([y,x])

ans=0
for e in it.permutations(range(N)):
    if e[0]!=0:
        break
        
    count=1
    for j in range(N-1):
        if [e[j]+1,e[j+1]+1] in a:
            count*=1
        else:
            count*=0
            break
            
    ans+=count

print(ans)

Measured memory_bytes: 9220
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
  int n,i,j,k;
  char s[100001],a[100001];
  int x[100003];
  scanf("%d%s",&n,s);
  for(i=0;i<4;i++){
    x[0]=i%2;x[1]=i/2;
    for(j=1;j<=n+1;j++){
      x[j+1]=x[j]?(s[j%n]=='o'?x[j-1]:x[j-1]^1):(s[j%n]=='o'?x[j-1]^1:x[j-1]);
    }
    if(x[0]==x[n]&&x[1]==x[n+1]){for(k=0;k<n;k++)a[k]='W'-('W'-'S')*x[k];a[n]='\0';printf("%s",a);return 0;}
  }
  printf("-1");
}


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1000000007

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

int n;
string s;
vector<bool> sheep(100002), judge(100002);

bool solve(int x, int y) {
	FOR(k, 2, n) sheep[k] = (sheep[k - 1] ^ (s[k - 1] == 'o')) ? sheep[k - 2] : 1 - sheep[k - 2];
	if ((sheep[n-2] ^ (sheep[0]) ^ (sheep[n-1]) ^ (s[n-1] == 'x'))) return false;
    if ((sheep[n-1] ^ sheep[1]) ^ (sheep[0] ^ (s[0] == 'x'))) return false;
    return true;
}

int main() {
	cin >> n >> s;
	rep(i, n) judge[i] = s[i] == 'o';
	s[n] = s[0];
	rep(i, 2) rep(j, 2) {
		sheep[0] = i;
		sheep[1] = j;
		if(solve(i, j)) {
			rep(k, n) printf("%c", (sheep[k]) ? 'W' : 'S');
			printf("\n");
			return 0;
		}
	}
	printf("-1\n");
	return 0;
} 

Measured memory_bytes: 640
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n = parseInt(readline())
    ans = 0.0
    for i = 1:n
        x, u = split(readline())
        if u == "JPY"
            ans += parseFloat(x)
        else
            ans += parseFloat(x) * 380000.0
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 169764
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 100100100
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

#define mod 998244353
 
int main(){
    int n; cin >> n;
    vector<int> a(n+2);
    for(int i=1; i<n+1; i++){
        cin >> a[i];
    }
    ll sum = 0;
    rep(i,n+1){
        sum += abs(a[i]-a[i+1]);
    }
    
    for(int i=1; i<n+1; i++){
        if(((a[i-1] <= a[i])&&(a[i] <= a[i+1]))||((a[i-1] >= a[i])&&(a[i] >= a[i+1]))){
            cout << sum << endl;
            continue;
        }
        ll ans = sum - min(abs(a[i] - a[i-1]), abs(a[i] - a[i+1]))*2;
        cout << ans << endl;
    }
    

}


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

int main(){
    int N,A,B,ans=0,sum=0,K;
    cin >> N >> A >> B;
    for(int i=1;i<N+1;i++){
        K=i;
        while(K>0){
            sum+=K%10;
            K/=10;
        }
        if(A<=sum&&sum<=B){
            ans+=i;
        }
        sum=0;
    }
    cout << ans << endl;
}

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

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

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

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

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	cin>>n>>m;
	vint v(n);
	vint cnt(n,1);
	v[0] = 1;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--,b--;
		// if(cnt[a]>=2){
		// 	v[b] |= v[a];
		// }
		// else{
		// 	v[b] = v[a];
		// 	v[a] = 0;
		// }
		if(v[a]) v[b]=1;
		cnt[b]++;
		cnt[a]--;
		if(cnt[a]==0) v[a]=0;
	}
	int ans = 0;
	rep(i,n) ans += v[i];
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	

	public static void main(String[] args) throws FileNotFoundException {
	
	
 /*File file =new File("input.txt");
 Scanner scan=new Scanner(new FileInputStream(file));
 PrintWriter out=new PrintWriter("output.txt");
 */
FastReader scan=new FastReader();

String  m=scan.next();
if(m.charAt(m.length()-1)=='s'){
	System.out.print(m+"es");
}
else
System.out.print(m+""+"s");
	
	}
}




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

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll ans = 0;
    if (K<=A) {
        ans = K;
    }
    else if (A<K and K<=A+B) {
        ans = A;
    }
    else {
        ans = A - (K-(A+B));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> gcdr(n);
    vector<int> gcdl(n);
    rep(i, n) {
        if (i == 0) gcdl[0] = a[i];
        else gcdl[i] = gcd(gcdl[i-1], a[i]);
    }
    for (int i = n - 1; i >= 0; --i) {
        if (i == n - 1) gcdr[n - 1] = a[i];
        else gcdr[i] = gcd(gcdr[i+1], a[i]);
    }
    int ans = 0;
    rep(i, n) {
        if (i == 0) {
            ans = max(ans, gcdr[i + 1]);
        }
        else if (i == n - 1) {
            ans = max(ans, gcdl[i - 1]);
        }
        else {
            ans = max(ans, gcd(gcdl[i-1], gcdr[i+1]));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

    static int line;
    static int[][] abc;
    static int[][] maxabc;

    static void maxHappiness(){
        maxabc[0][0] = abc[0][0];
        maxabc[0][1] = abc[0][1];
        maxabc[0][2] = abc[0][2];
        for(int i=1;i<line;i++){
            maxValue(i);
        }
    }
    static void maxValue(int l){

        int a = abc[l][0] + maxabc[l-1][1];
        int b = abc[l][0] + maxabc[l-1][2];
        if(a>b){
            maxabc[l][0] = a;
        }
        else{
            maxabc[l][0] = b;
        }

        int c = abc[l][1] + maxabc[l-1][0];
        int d = abc[l][1] + maxabc[l-1][2];
        if(c>d){
            maxabc[l][1] = c;
        }
        else{
            maxabc[l][1] = d;
        }

        int e = abc[l][2] + maxabc[l-1][0];
        int f = abc[l][2] + maxabc[l-1][1];
        if(e>f){
            maxabc[l][2] = e;
        }
        else{
            maxabc[l][2] = f;
        }
    }
    static int ans(){
        int[] a = new int[3];
        a[0] = maxabc[line-1][0];
        a[1] = maxabc[line-1][1];
        a[2]= maxabc[line-1][2];

        int out = 0;

        for(int i=0;i<3;i++){
            if(a[i]>out){
                out = a[i];
            }
        }
        return out;
    }

    public static void main(String[] args) throws IOException {

        BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));

        String ln = inp.readLine();

        line = Integer.parseInt(ln);
        abc = new int[line][3];
        maxabc = new int[line][3];

        for(int l=0;l<line;l++){
            String[] ABC = inp.readLine().split(" ");
            for (int i=0;i<3;i++){
                abc[l][i] = Integer.parseInt(ABC[i]);
            }
        }
        maxHappiness();
//        for (int i=0;i<line;i++){
//            System.out.println(maxabc[i][0]+" "+maxabc[i][1]+" "+maxabc[i][2]);
//        }
        System.out.println(ans());

    }
}


Measured memory_bytes: 53460
import sys
import queue
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
d = queue.Queue()
d.put([0, 0, 0])
vals = set()

while not d.empty():
    now = d.get()
    a[now[0]][now[1]] = '.'
    if now[2] in vals:
        print('Impossible')
        sys.exit()
    else:
        vals.add(now[2])
        
    if now[0] == h-1 and now[1] == w-1:
        a1 = [['.']*w for _ in range(h)]
        if a == a1:
            print('Possible')
        else:
            print('Impossible')
        sys.exit()
    else:
        if now[0]+1 < h:
            if a[now[0]+1][now[1]] == '#':
                d.put([now[0]+1, now[1], now[2]+1])
        if now[1]+1 < w:
            if a[now[0]][now[1]+1] == '#':
                d.put([now[0], now[1]+1, now[2]+1])        
print('Impossible')


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

int a[100005];

int main()
{
    int n;

    cin >> n;

    int c = 0;

    for(int i = 1 ; i<=n ; i++)
    {
        cin >> a[i];
    }
    
    int ans = 0;

    for(int i = 1 ; i<=n ; i++)
    {
        if(a[i]==i)
        {
            if(i+1<=n && a[i+1]==i+1)
            {
                ans++;
                i++;
            }
            else
                ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 200005
typedef long long int ll;
ll fact[N],inv[N],finv[N];
ll pro(ll a,ll b)
{
    return (a*b)%M;
}
void buildfact()
{
    int i,q,r;
    fill(fact,fact+N,1);
    fill(inv,inv+N,1);
    fill(finv,finv+N,1);
    for(i=2;i<N;i++)
    {
        fact[i]=pro(fact[i-1],i);
        q=M/i,r=M%i;
        inv[i]=M-pro(q,inv[r]);
        finv[i]=pro(finv[i-1],inv[i]);
    }
    return ;
}
ll ncr(int a,int b)
{
    if(a<b)
        return 0;
    return pro(fact[a],pro(finv[b],finv[a-b]));
}
int main()
{
    int n,m,k;
    in3(n,m,k);
    buildfact();
    ll ans=pro(ncr(m+1,3),pro(n,n))+pro(ncr(n+1,3),pro(m,m));
    ans=pro(ans,ncr(n*m-2,k-2));
    outl(ans);
}


Measured memory_bytes: 4992
#include<iostream>

using namespace std;
int main() {
	string s, t;
	int i;
	cin >> s >> t;
	for (i = 0;i < s.size();i++) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			goto g;
		}
	}
	if (t.size() == s.size() + 1)cout << "Yes" << endl;
	else cout << "No" << endl;
	g:
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <unordered_set>
using namespace std;

int N;
unordered_set<string> tango;
int main()
{
    int N;
    cin >> N;

    char tail = ' ';
    bool clear = true;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        if (tail != ' ')
            if (tail != s[0] || tango.count(s) != 0)
            {
                clear = false;
            }
        tail = s[s.size() - 1];
        tango.insert(s);
    }
    if (clear)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
use proconio::input;
use std:: char::*;

fn main() {
  input! {
    mut n: u64
  }

  let mut ans: Vec<char> = Vec::new();

  loop {
    n -= 1;
    let c = (n%26) as u32;
    n += 1;
    ans.push(from_u32(c + ('a' as u32)).unwrap());
    n -= c as u64;
    n /= 26;
    if n==0 {break;}
  }

  ans.reverse();

  for x in ans {
    print!("{}", x);
  }
  println!();

  //println!("Hello, AtCoder!");
}


Measured memory_bytes: 2144
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[100001];
        for (int i = 0; i < n; i++) {
            int tmp = sc.nextInt();
            a[tmp]++;
        }
        int ans = 0;
        for (int i = 0; i < a.length - 2; i++) {
            int tmp = a[i] + a[i + 1] + a[i+ 2];
            if(tmp > ans) ans = tmp;
        }
        System.out.println(ans);
    }
}


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

int main() {
  ll n,r;
  cin >> n >> r;
  cout << r + max((ll)0,100*(10-n)) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 100007;
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;
    for (long long i = -1000; i <= 1000; i++) {
        for (long long j = -1000; j <= 1000; j++) {
            if (i*i*i*i*i - j*j*j*j*j == n) {
                cout << i << " " << j;
                return;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

Measured memory_bytes: 3612
n = int(input())
review = []
for i in range(n):
    s, p = input().split()
    review.append([s, int(p), i + 1])
rev_sorted1 = sorted(review, key = lambda x: x[1] , reverse = True)
rev_sorted2 = sorted(rev_sorted1, key = lambda x: x[0], reverse = False)
for i in rev_sorted2:
    print(i[2])
    

Measured memory_bytes: 3060
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <istream>
#include <algorithm>

int main()
{
    int c[3][3];
    std::cin >> c[0][0] >> c[0][1] >> c[0][2];
    std::cin >> c[1][0] >> c[1][1] >> c[1][2];
    std::cin >> c[2][0] >> c[2][1] >> c[2][2];

    bool flag = true;
    for (int i = 0; i < 2; i++) {
        int d1 = c[i][0] - c[i+1][0];
        int d2 = c[i][1] - c[i + 1][1];
        int d3 = c[i][2] - c[i + 1][2];
        flag &= d1 == d2 && d2 == d3;
        d1 = c[0][i] - c[0][i + 1];
        d2 = c[1][i] - c[1][i + 1];
        d3 = c[2][i] - c[2][i + 1];
        flag &= d1 == d2 && d2 == d3;
    }

    std::cout <<( flag ? "Yes" : "No" )<< std::endl;

    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a * 500 + b * 100 + c * 50 == X:
                ans += 1

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define fi first
#define se second
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return M_PI;
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	int name;
	double w,t;
	char n;
	while(cin>>name>>n>>w>>n>>t){
		double bmi;
		bmi=w/(t*t);
		if(bmi>=25) cout<<name<<endl;
	}
}

Measured memory_bytes: 1232
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Collections; namespace Equeue { class Equeue { static Node[] Nodes; static void Main(string[] args) { var N = long.Parse(Console.ReadLine());  var dic = new Dictionary<string,long>(); for(int i = 0; i < N ;i++){ var S = Console.ReadLine(); if(dic.ContainsKey(S)){ dic[S]++; }else{ dic.Add(S,1); } } long max =dic.Max(kvp => kvp.Value); 

 //var ans = dic.Where(kvp => kvp.Value == max).Select(kvp => kvp.Key).ToArray(); //var ans = new List<String>(); Array.Sort(ans);

 
 foreach(var d　in　dic.Where(x => x.Value == max).OrderBy(z => z.Key, StringComparer.OrdinalIgnoreCase)){
     Console.WriteLine(d.Key);
 }
 
 
 } static bool WFS(long st){ var q = new Queue<Node>(); var tmp = Nodes[st]; tmp.loc = 100; q.Enqueue(tmp); while(q.Count > 0){ tmp = q.Dequeue(); foreach(KeyValuePair<long,long> item in tmp.adj) { var child = Nodes[item.Key]; 
 
 //Console.WriteLine(item.Key+" "+child.loc+" "+item.Value);
  if(child.loc != -1 && (child.loc != (item.Value+tmp.loc))){ return false; }else if(child.loc == -1){ child.loc = item.Value+tmp.loc; q.Enqueue(Nodes[item.Key]); //Console.WriteLine(item.Key+" "+child.loc+" "+item.Value);
   } } } return true; } } public class Node{ public long loc = -1; public Dictionary<long,long> adj = new Dictionary<long,long>(); } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) { } public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) { } public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } } 


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

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


int main()
{
  int N; cin >> N;
  double ans = 0;

  REP(i, N) {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY") ans += x;
    else ans += x * 380000.0;
  }
  cout << fixed << setprecision(20) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right

maxA = 10**5

N, M = map(int, input().split())
As = list(map(int, input().split()))

As.sort()

def isOK(v):
    num = 0
    for A in As:
        i = bisect_left(As, v-A)
        num += N-i
    return num >= M

ng, ok = 2*maxA+1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

accRevAs = [As[-1]]
for A in reversed(As[:-1]):
    accRevAs.append(accRevAs[-1]+A)
accRevAs.reverse()

v = ok
ans = 0
numGt = 0
#numEq = 0
for A in As:
#    iL = bisect_left(As, v-A)
    iR = bisect_right(As, v-A)
    if iR < N:
        ans += accRevAs[iR] + A*(N-iR)
    numGt += N-iR
#    numEq += iR-iL

ans += v * (M-numGt)
print(ans)


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

int main(void) {
	int n, dig = 0;
	cin >> n;
	int num = n;
	while (num) {
		dig += num % 10;
		num = num / 10;
	}
	cout << (n%dig == 0 ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int f(int n)
{int sum=0;
	for(int i=1;i<=n;i++)
	if(n%i==0)
	if(i%2==1)
	sum++;
	return sum;
	
}
int main()
{
	int n;
	scanf("%d",&n);
	int sum=0;
	for(int i=1;i<=n;i++)
	if(f(i)==8)sum++;
	printf("%d",sum);
	
	
	
}

Measured memory_bytes: 128
#include<iostream>
main(){for(int q,b,c,d,r,A,N;std::cin>>q>>b>>c>>d>>r,q;A?printf("%d %d\n",A,N):printf("NA\n"))for(A=0;r;r--){N=(b-r*c)/d;if(b>=r*c&&N+r>=q){A=r;break;}}return 0;}

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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll t,i,x,j,y,z,k=0,n;

cin>>n;
ll p2=n/2;
if(n&1)	return cout<<0,0;
n=n/2;
j=0;
i=5;

while(n/i>0){
	j+=n/i;
	i*=5;
}
k=0;
i=2;
while(n/i>0){
	k+=n/i;
	i*=2;
}
t=0;
i=10;
while(n/i>0){
	t+=n/i;
	i*=10;
}

z=(k<j)?t:j+n;

ce(j)
}
/*

124999999999999995
1 2 3 4 5 6 7 8
1 3 5 7 9
2 4 6 8 10 12 14 16 18 20 ... 100 

1 2 3 4 5 6 7 8 9 10 ...... 50


*/

Measured memory_bytes: 256
n = int(input())
s = input()
 
def ROTN(tmp, n):
    tmp = ord(tmp) + n
    if tmp > 0x5a:
        tmp -= 26
    return chr(tmp)
 
 
ans = []
for i in range(len(s)):
    tmp = s[i]
    ans.append(ROTN(tmp, n))
 
for i in range(len(ans)):
    print(ans[i], end="")

Measured memory_bytes: 9152
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  long long A[100000];
  long long answer=1;
  for(int i=0;i<N;i++){
    cin>>A[i];
    if(A[i]==0) answer=0;
  }
  if(answer==0) cout<<answer<<endl;
  else{
  for(int i=0;i<N;i++){
    if(A[i]<=1000000000000000000/answer){
      answer=answer*A[i];
    }
    else{
      answer=-1;
      break;
    }
  }
  cout<<answer<<endl;
  }
  
  return 0;
}

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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

char Map[2000][2000];
u32 L[2000][2000], R[2000][2000], U[2000][2000], D[2000][2000];

int main() {
  cout << setprecision(18);
  u32 H, W;
  cin >> H >> W;
  for (u32 i = 0; i < H; ++i) {
    for (u32 j = 0; j < W; ++j) {
      cin >> Map[i][j];
    }
  }
  for (u32 i = 0; i < H; ++i) {
    for (u32 j = 0; j < W; ++j) {
      if (Map[i][j] == '#') {
        L[i][j] = 0;
        U[i][j] = 0;
      } else {
        L[i][j] = (j == 0) ? 1 : L[i][j - 1] + 1;
        U[i][j] = (i == 0) ? 1 : U[i - 1][j] + 1;
      }
      if (Map[i][W - (j + 1)] == '#')
        R[i][W - (j + 1)] = 0;
      else
        R[i][W - (j + 1)] = (j == 0) ? 1 : R[i][W - j] + 1;
      if (Map[H - (i + 1)][j] == '#')
        D[H - (i + 1)][j] = 0;
      else
        D[H - (i + 1)][j] = (i == 0) ? 1 : D[H - i][j] + 1;
    }
  }
  u32 res = 0;
  for (u32 i = 0; i < H; ++i) {
    for (u32 j = 0; j < W; ++j) {
      u32 tmp;
      if (Map[i][j] == '#') continue;
      tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
      if (tmp > res) res = tmp;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 66688
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <functional>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    string t;
    bool ok = true;
    for (int i = 0; i < n; i++) {
        if (s[i] != 'A') {
            t.push_back(s[i]);
        }
    }
    string need = "KIHBR";
    ok &= (t == need);
    if (!ok) {
        cout << "NO\n";
        return 0;
    }
    vector<int> where(need.size());
    for (int i = 0, j = 0; i < n && j < need.size(); i++) {
        if (s[i] == need[j]) {
            where[j] = i;
            j++;
        }
    }
    ok &= (where[0] <= 1);
    ok &= (where[1] == where[0] + 1);
    ok &= (where[2] == where[1] + 1);
    ok &= (where[3] - where[2] <= 2);
    ok &= (where[4] - where[3] <= 2);
    ok &= (n - 1 - where[4] <= 1);
    cout << (ok ? "YES\n" : "NO\n");
}

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

int main()
{
	int i, N, a[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int ans = N;
	for (i = 1; i <= N; i++) {
		if (a[i] == N - ans + 1) ans--;
	}
	if (ans == N) ans = -1;
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 896