akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
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 k;
bool field[8][8];

void clear(){
    rep(i,8)rep(j,8){
        field[i][j] = false;
    }
}

bool check(){
    bool ret = true;
    rep(i,8)rep(j,8){
        if(field[i][j]){
            rep(l,8){
                if(l != j && field[i][l]) ret = false;
                if(l != i && field[l][j]) ret = false;
            }
            for(int l = -7; l <= 7; l++){
                if(l == 0) continue;
                if(0 <= i+l && i+l <= 7 && 0 <= j+l && j+l <= 7){
                    if(field[i+l][j+l]) ret = false;
                }
            }
            for(int l = -7; l <= 7; l++){
                if(l == 0) continue;
                if(0 <= i+l && i+l <= 7 && 0 <= j-l && j-l <= 7){
                    if(field[i+l][j-l]) ret = false;
                }
            }
        }
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> k;
    vector<int> v(8), r(k), c(k);
    rep(i,k) cin >> r[i] >> c[i];
    rep(i,8) v[i] = i;
    do{
        clear();
        bool ok = true;
        rep(i,k){
            if(v[r[i]] != c[i]) ok = false;
        }
        if(!ok) continue;
        rep(i,8) field[i][v[i]] = true;
        if(check()){
            rep(i,8){
                rep(j,8){
                    if(field[i][j]) cout << "Q";
                    else cout << ".";
                }
                cout << endl;
            }
            return 0;
        }
    }while(next_permutation(v.begin(), v.end()));
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#define _USE_MATH_DEFINES
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
#include <cstdlib>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}



int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    
    int a,b;

    cin>>a>>b;

    cout<<(a*b)<<"\n";

    return 0;
}


Measured memory_bytes: 3172
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1
 
struct Node { int p,l,r; };
 
Node T[MAX];
int n,D[MAX];
 
void print(int u){
 
  int i,c;
 
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";
 
  if(T[u].p == NIL ) cout << "root, ";
  else if( T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";
 
  cout << "[";
   
  for( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if (i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}
 
int rec(int u,int p){
  D[u] = p;
  if ( T[u].r != NIL) rec(T[u].r,p);
  if ( T[u].l != NIL) rec(T[u].l, p+1);
}
 
int main(){
  int i,j,d,v,c,l,r;
  cin >> n;
  for (i = 0; i < n; i++)T[i].p = T[i].l = T[i].r = NIL;
 
  for(i = 0; i < n; i++){
    cin >> v >> d;
    for( j = 0; j < d; j++){
      cin >> c;
      if( j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for (i = 0; i < n; i++){
    if(T[i].p == NIL) r = i;
  }
 
  rec(r,0);
   
  for(i = 0; i < n; i++)print(i);
 
  return 0;
 
}


Measured memory_bytes: 7736
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int a[100000];

int main()
{
	int n;
	ll ans=0;
	ll h[2];
	
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	
	h[0]=0;
	h[1]=0;
	sort(a,a+n);
	reverse(a,a+n);
	int i=0;
	int j=0;
	while(i<n-1)
	{
		if(a[i]==a[i+1])
		{
			h[j]=a[i];
			j++;
			i++;
		}
		if(j==2)
			break;
		i++;
	}
	ans=h[0]*h[1];
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

#ifdef ZERO_IQ
ios_base::sync_with_stdio ( false ), cin.tie ( 0 ), cout.tie ( 0 );
#endif

int main() {
   ll n;
   cin>>n;
   vector<ll>v(n),vv(n),fake;
    for (int i = 0; i < n; ++i) {
        cin>>v[i];
    }
    for (int j = 0; j < n; ++j) {
        cin>>vv[j];
    }
    fake=v;
    sort(fake.begin(),fake.end());
    ll ans1=0;
    ll ans2=0;
    ll c=1;
    do{
        if(v==fake){
            ans1=c;
        }
        if(vv==fake){
            ans2=c;
        }
        c++;
    }while(next_permutation(fake.begin(),fake.end()));
    cout<<abs(ans1-ans2);

    return 0;
}

Measured memory_bytes: 256
from fractions import gcd
n = int(input())
a = list(map(int, (input().split())))

if n == 2:
    print(max(a[0], a[1]))
    exit()

noskip = gcd(a[0], a[1])
skipped = max(gcd(a[0], a[2]), gcd(a[1], a[2]))

for i in range(2, n):
    skipped = max(gcd(skipped, a[i]), noskip)
    noskip = gcd(noskip, a[i])

print(max(noskip, skipped))


Measured memory_bytes: 16056
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  int h,w; cin >> h >> w;
  string s[h]; rep(i,h) cin >> s[i];
  int ml[h+2][w+2] = {};
  int mr[h+2][w+2] = {};
  int mu[h+2][w+2] = {};
  int md[h+2][w+2] = {};
  rep(i,h) {
    rep(j,w){
      if(s[i][j] == '.' ) ml[i+1][j+1] = ml[i+1][j] + 1;
      else ml[i+1][j+1]=0;
    }
  }
  rep(i,h) {
    rep(j,w){
      if(s[i][w-1-j] == '.' ) mr[i+1][w-j] = mr[i+1][w+1-j] + 1;
      else mr[i+1][w-j]=0;
    }
  }
  rep(i,h) {
    rep(j,w){
      if(s[i][j] == '.' ) mu[i+1][j+1] = mu[i][j+1] + 1;
      else mu[i+1][j+1]=0;
    }
  }
  rep(i,h) {
    rep(j,w){
      if(s[h-1-i][j] == '.' ) md[h-i][j+1] = md[h+1-i][j+1] + 1;
      else md[h-i][j+1]=0;
    }
  }
  int ans = 0;
  rep(i,h) rep(j,w) {
    if(s[i][j] == '.') ans = max(ans, ml[i+1][j] + mr[i+1][j+2] + mu[i][j+1] + md[i+2][j+1] + 1);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 67072
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)

using namespace std;

llint h, w;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w;
	if(h == 1 || w == 1){
		cout << 1 << endl;
		return 0;
	}
	llint ans = h/2*w;
	h %= 2;
	if(h) ans += (w+1)/2;
	cout << ans <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  string s;cin >> s;
  bool isfirst = true;
  if(s[0] == s[s.length()-1]) isfirst=!isfirst;
  if((s.length()&1)==0) isfirst=!isfirst;
  if(isfirst) cout << "First" << endl;
  else cout << "Second" << endl;
  return 0;
}


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

int main()
{
	int A, B;
	cin >> A >> B;

	if (A >= 13) {
		cout << B << endl;
	}
	else if (6 <= A and A <= 12) {
		cout << B / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
wv=[tuple(map(int,input().split())) for _ in range(n)]
x=10**5
dp=[[float("inf")]*(x+1) for _ in range(n+1)]
for i in range(1,n+1):
    w,v=wv[i-1]
    dp[i][v]=min(dp[i-1][v],w)
    for j in range(x+1):
        if dp[i-1][j]==float("inf"):
            continue
        if j+v<=x:
            dp[i][j+v]=min(dp[i][j+v],dp[i-1][j]+w)
        dp[i][j]=min(dp[i-1][j],dp[i][j])

ans=0
for i in range(x+1):
    if dp[n][i]<=m:
        ans=i

print(ans)


Measured memory_bytes: 307728
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
// find(pointer1,pointer2,val) => find the first value == val in the range pointer1 to pointer 2, return the address
// distance(pointer1, pointer2) => return the integer that represent how many entries between the 2 pointers

int cnt = 0;
vector<int> pre, in, post;

void rec(int lo, int hi) {
	if (lo >= hi) return;
	int root = pre[cnt++];
	int	inpos = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(lo, inpos);
	rec(inpos + 1, hi);
	post.push_back(root);
}

int main() {
	int len;
	cin >> len;
	int id;
	for (int i = 0; i < len; i++) {
		cin >> id;
		pre.push_back(id);
	}
	for (int i = 0; i < len; i++) {
		cin >> id;
		in.push_back(id);
	}
	rec(0, len);
	for (int i = 0; i < len; i++) {
		if (i) cout << " ";
		cout << post[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3180
#  =========     /\       /|    |====/|
#      |        /  \       |    |   / |
#      |       /____\      |    |  /  |
#      |      /      \     |    | /   |
#  ========= /        \  =====  |/====|  
#  code

def main():
    n = int(input())
    print((n ** 3) / 27)
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int x = 0;
    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
        {
            x++;
        }
    }
    printf("%d\n", x);
}


Measured memory_bytes: 2740
#include <stdio.h>

int main(void){
	int i,ii,iii,n,x,hantei;
	while(1){
		scanf("%d %d",&n,&x);
		if(n==0&&x==0)break;
		hantei=0;
		for(i=1;i<=n-2;i++){
			for(ii=i+1;ii<=n-1;ii++){
				for(iii=ii+1;iii<=n;iii++){
					if(i+ii+iii==x)hantei++;
				}
			}
		}
		printf("%d\n",hantei);
	}
	return 0;
}

Measured memory_bytes: 600
# 英小文字からなる文字列 S 
# S の長さが K 以下であれば、S をそのまま出力
# S の長さが K を上回っているならば、
# 先頭 K 文字だけを切り出し、末尾に ... を付加して出力

K = int(input())
S = input()

if len(S) <= K:
    print(S)
else:
    print(S[0:K]+'...')

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#ifdef Debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif


int man(int xa,int ya,int xb,int yb){
	return abs(xa-xb) + abs(ya-yb);
}

int main(){
	int n;
	int d[4];
	while(cin>>n){
		rep(i,4){cin>>d[i];d[i]--;}

		int mini=999999999,miniNum=999999999;
		for(int w=1;w<=n;w++){
			int x[4],y[4];
			rep(i,4){
				x[i]=d[i]%w;
				y[i]=( d[i]-d[i]%w )/w;
			}
			int num=man(x[0],y[0],x[1],y[1]) + man(x[2],y[2],x[3],y[3]);
			if(mini>num){
				mini=num;
				miniNum=w;
			}
		}
		cout<<mini<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define FAST   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl        '\n'
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{
   int n; cin>>n;
   string s;
   int pref=0,suf=0,mid=0,ans=0;
   rep(i,0,n)
   {
     cin>>s;
     int sz=s.size();
     rep(j,0,sz-1)
     {
       ans+=((s[j]=='A')&&(s[j+1]=='B'));
     }
     if(s[0]=='B' && s[sz-1]=='A') {mid++; continue;}
     if(s[0]=='B') pref++;
     if(s[sz-1]=='A') suf++;
   }
   if(mid)
   {
     ans+=mid-1;
     if(pref) ans++,pref--;
     if(suf) ans++,suf--;
   }
   ans+=max(0,min(pref,suf));
   cout<<ans;
} 
int main()
{   
   FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
/* ~ Programmer >> Tushar Mahajan */
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
#define ll long long int
#define ld long double
#define MOD 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL); 

int main() {
	ios;
	ll n;
	cin>>n;
	if(n>=400 && n<=599)
	{
	    cout<<8<<endl;
	}
	else if(n>=600 && n<=799)cout<<7<<endl;
	else if(n>=800 && n<=999)cout<<6<<endl;
	else if(n>=1000 && n<=1199)cout<<5<<endl;
	else if(n>=1200 && n<=1399)cout<<4<<endl;
	else if(n>=1400 && n<=1599)cout<<3<<endl;
	else if(n>=1600 && n<=1799)cout<<2<<endl;
	else if(n>=1800 && n<=1999)cout<<1<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll dp[ohara][10];
ll cost;

//-------------------------↓↓↓↓↓↓------------------------

ll func(ll tar,ll flags){
    ll res;
    if(flags==0||flags==4){
        res=tar;
    }
    else if(flags==1||flags==3){
        if(tar==0)res=2;
        else if(tar%2==1)res=1;
        else res=0;
    }
    else {
        if(tar==0)res=1;
        else if(tar%2==1)res=0;
        else res=1;
    }
    return res;
}

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

    cin>>n;
    rep(i,n)cin>>a[i];
    rrep(i,1,ohara-1){
        rep(j,9){
            dp[i][j]=LINF;
        }
    }
    rrep(i,1,n+1){
        rep(j,5){
            cost=LINF;
            rep(k,j+1){
                cost=min(cost,dp[i-1][k]);
            }
            dp[i][j]=cost+func(a[i-1],j);
        }
    }
    ans=LINF;
    rep(i,5){
        ans=min(ans,dp[n][i]);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 80128
#include<iostream>
using namespace std;
int main(){
	int n,ans,temp;
	while(cin>>n,n){
		ans=0;
		temp=1;
		for(int i=0;i<13;i++){
			temp*=5;
			ans+=n/temp;
		}
		cout<<ans<<endl;
	}
	return 0;
}	

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a)cin >> i ;
	sort(all(a)) ;
	reverse(all(a)) ;
	ll sum = a.at(0) ;
	ll cnt = n-2 ;
	for(int i=1;i<n;i++){
		sum += min(cnt,2LL)*a.at(i) ;
		cnt -= min(cnt,2LL) ;
	}
	cout << sum << endl ;
}

Measured memory_bytes: 4840
#include <stdio.h>
#include <math.h>

int main(void)
{
	double a, b, c, d;
	
	scanf("%lf%lf%lf%lf",&a,&b,&c,&d);

	printf("%lf\n", sqrt((a - c)*(a - c) + (b - d)*(b - d)));

	return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long N; cin >> N;
    constexpr int A = 26;
    long long num = 1, M = A;
    while (N > M) {
        N -= M;
        num++, M *= A;
    }
    N--;
    vector<int> V;
    while (num--) {
        V.emplace_back(N % A);
        N /= A;
    }
    reverse(V.begin(), V.end());
    string Ans;
    for (auto &x: V) {
        Ans += ('a' + x);
    }
    cout << Ans << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
	int a,b,c;
	int j=0;
	
	scanf("%d %d",&a,&b);
	
	c=a+b;
	
	if(a%3==0)
	{
		j++;
	}
	else if(b%3==0)
	{
		j++;
	}
	else if(c%3==0)
	{
		j++;
	}
	
	if(j==0)
	{
		printf("Impossible\n");
	}
	else
	{
		printf("Possible\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
// !=D
#include <bits/stdc++.h>

using namespace std;

vector<long long> p;
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string n;
	cin>> n;
	int r = 0;
	for(int i = 0; i < n.size(); i++)
	{
		r += n[i]-'0';
		r %=9;
	}
	if(r == 0)
		cout<< "Yes" << endl;
	else
		cout<< "No" << endl;
	
	return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int A, B;
int m[110][110];
string S = ".#";

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

    std::cin >> A >> B;

    bool flag = A >= B;
    if(A < B){swap(A, B);}

    for(int i=0;i<100;++i){
        m[0][i] = 1;
    }
    
    int diff = A - B, r = 1;
    while(diff > 0){
        int n = min(diff, 50);

        for(int i=0;i<n;++i){
            m[r][i*2] = 1;
        }

        for(int i=0;i<100;++i){
            m[r+1][i] = 1;
        }

        diff -= n;
        r += 2;
    }

    --B;

    int d = 1;
    while(B > 0){
        m[r][d] = 1;

        int n = min(d, B);
        for(int i=1;i<=n;++i){
            m[r+i][d-i] = 1;
        }

        B -= n;
        d += 2;
    }

    std::cout << 100 << " " << 100 << std::endl;
    for(int i=0;i<100;++i){
        for(int j=0;j<100;++j){
            std::cout << S[flag ? m[i][j] : !m[i][j]];
        }
        std::cout << std::endl;
    }
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n, k;
	cin >> n >> k;
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		double x = (double)1 / n;
		int y = i;
		while (y < k) {
			y *= 2;
			x *= 0.5;
		}
		ans += x;
	}
	cout << ans;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
	int X;
	cin >> X;
	if(X%5==0 || X%7 == 0){
	cout << "YES" << endl;
	}
	else if(X%3 == 0 && X%6!=0 && X%9 != 0){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string s;
    cin >> s;
    int n = sz(s);
    ll ans = 0;
    ll a = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A') {
            a++;
        } else if (s[i] == 'B' && s[i + 1] == 'C') {
            ans += a;
            i++;
        } else {
            a = 0;
        }
    }
    cout << ans << endl;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;




int main() {
	
	int n;
	cin >> n;
	
	VI a(n);
	REP(i, n)cin >> a[i];

	sort(ALL(a));
	if (a[0] >= 0) {
		int ans = 0;
		FOR(i, 1, n)ans += a[i];
		ans -= a[0];
		cout << ans << endl;
		REP(i, n - 2) {
			cout << a[0] << ' ' << a[i + 1] << endl;
			a[0] -= a[i + 1];
		}
		cout << a[n - 1] << ' ' << a[0] << endl;

		return 0;
	}
	if (a[n - 1] <= 0) {
		int ans = 0;
		REP(i, n - 1) {
			ans -= a[i];
		}
		ans += a[n - 1];
		cout << ans << endl;
		REP(i, n - 1) {
			cout << a[n - 1] << ' ' << a[i] << endl;
			a[n - 1] -= a[i];
		}
		return 0;
	}

	int ans = 0;
	REP(i, n)ans += abs(a[i]);
	cout << ans << endl;

	int k = upper_bound(ALL(a), 0) - a.begin();

	FOR(i, k + 1, n) {
		cout << a[k - 1] << ' ' << a[i] << endl;
		a[k - 1] -= a[i];
	}

	REP(i, k) {
		cout << a[k] << ' ' << a[i] << endl;
		a[k] -= a[i];
	}





}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
signed main(){
  int n;
  cin>>n;
  int x[n],y[n];
  for(int i=0;i<n;i++) cin>>x[i]>>y[i];
  int mi=min(*min_element(x,x+n),*min_element(y,y+n));
  int ma=max(*max_element(x,x+n),*max_element(y,y+n));
  int ans=1LL<<62LL;
  int r=mi,b=ma;
  for(int i=0;i<n;i++){
    if(x[i]>y[i]) swap(x[i],y[i]);
    r=max(r,x[i]);
    b=min(b,y[i]);
  }
  ans=min(ans,(r-mi)*(ma-b));
  //cout<<ans<<endl;
  vector<P> v;
  for(int i=0;i<n;i++){
    v.push_back(P(x[i],i));
  }
  sort(v.begin(),v.end());
  int ri=v[0].first,ra=v[n-1].first;
  int tmp=ra;
  for(int i=0;i<n-1;i++){
    //cout<<ra<<" "<<ri<<endl;
    ans=min(ans,(ma-mi)*abs(ra-ri));
    ra=max(ra,y[v[i].second]);
    ri=min(y[v[i].second],v[i+1].first);
    tmp=min(tmp,y[v[i].second]);
    if(tmp<=v[i+1].first){
      ri=tmp;
      break;
    }
    if(y[v[i].second]<=v[i+1].first) break;
    if(ri>=ra) break;
  }
  ans=min(ans,(ma-mi)*(ra-ri));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int>vec(n);
  for(int i = 0;i<n;i++) cin >> vec[i];
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int count = 0;
  for(int i = 0;i<k;i++){
    count+=vec[i];
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import sys
from io import StringIO
import unittest
import os
import collections

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行1項目
    #   1行2項目 x, y = map(int, input().split())
    #   1行N項目 x = list(map(int, input().split()))
    #   N行1項目 x = [int(input()) for i in range(n)]
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    #   1行1項目 x = input()
    #   1行1項目(1文字ずつリストに入れる場合) x = list(input())
    n = int(input())
    s_s = [input() for i in range(n)]

    a_counter = collections.Counter(s_s)

    for i in ["AC", "WA", "TLE", "RE"]:
        print(i + " x " + str(a_counter.get(i, 0)))


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """6
AC
TLE
AC
AC
WA
TLE"""
        output = """AC x 3
WA x 1
TLE x 2
RE x 0"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """10
AC
AC
AC
AC
AC
AC
AC
AC
AC
AC"""
        output = """AC x 10
WA x 0
TLE x 0
RE x 0"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 83052
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(void){


    int n, q;
    cin >> n >> q;

    string str;
    cin >> str;

    int length = str.length(), count = 0;

    vector<int> dp(length), l(q), r(q);

    int tmp;
    for(int i = 0;i < q;i++){
        cin >> l[i] >> r[i];
    }

    for(int i = 0;i < length-1;i++){
        if(str[i] == 'A' && str[i+1] == 'C'){
            count++;
        }
        dp[i] = count;
    }

    dp[length-1] = count;

    

    for(int i = 0;i < q;i++){
        int start = (l[i]-2 < 0 ? 0 : dp[l[i]-2]);
        int end = dp[r[i]-2];
        cout << end - start << endl;
    }

    /*
    cout << length << endl;

    for(int i = 0;i < length;i++){
        cout << dp[i] << " ";
    }
    cout << endl;
    */


    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int A, B, C, D; cin >> A >> B >> C >> D;
  cout << max(A*B, C*D) << endl;
  return 0;
}

Measured memory_bytes: 384
#include<cstdio>
int main(){
	int n,m,k;scanf("%d%d%d",&n,&m,&k);
	bool s=0;
	for(int x=0,y;x<=n&&!s;x++)
		if(2*x==n)x*m==k?s=1:1;
		else(y=k+m*(x-n))%(2*x-n)==0&&(y/=2*x-n)>=0&&y<=m?s=1:1;
	puts(s?"Yes":"No");
}

Measured memory_bytes: 128
// D - Fennec VS. Snuke
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void distance(int p, int d, vvi &tree, vi &visited){
	if(visited[p] > 0) return;
	visited[p] = d;
	for(auto c: tree[p]) distance(c, d+1, tree, visited);
}

string solve(int N, vi &A, vi &B){
	vvi tree(N+1, vi());
	rp(i, 0, N-1){
		tree[A[i]].push_back(B[i]);
		tree[B[i]].push_back(A[i]);
	}
	vi f(N+1), s(N+1);
	distance(1, 1, tree, f);
	distance(N, 1, tree, s);
	int c = 0;
	rp(i, 2, N) c += f[i]<=s[i]? 1: -1;
	return c>0? "Fennec": "Snuke";
}

int main(){
	int N; cin>>N;
	vi A(N-1), B(N-1);
	rp(i, 0, N-1) cin>>A[i]>>B[i];
	cout<< solve(N, A, B) <<endl;
}

Measured memory_bytes: 11904
N, M = map(int, input().split())
AB = [0] * N
for i in range(N):
    AB[i] = list(map(int, input().split()))

AB = sorted(AB, key = lambda x: x[0])
ans = 0

for i in range(N):
    if M > AB[i][1]:
        M -= AB[i][1]
        ans += AB[i][0] * AB[i][1]
    else:
        ans += AB[i][0] * M
        M = 0
    if M == 0:
        break

print(ans)

Measured memory_bytes: 29172
#include <stdio.h>
int main() {
	int N;
	scanf("%d", &N);
	int button[N], i;
	for (i = 1; i <= N; i++) {
		int tmp;
		scanf("%d", &tmp);
		button[i] = tmp;
	}
	int now = 1, c = 0;
	for (;;) {
		if (now == 2) {
			printf("%d\n", c);
			break;
		}
		if (c >= N) {
			printf("-1\n");
			break;
		}
		c++;
		now = button[now];
	}
	return 0;
}

Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] A = new int[N + 1];
		for (int i = 1; i <= N; i++)
			A[i] = sc.nextInt();

		int[] L = new int[N + 1];
		for (int i = 1; i <= N; i++)
			L[i] = gcd(L[i - 1], A[i]);

		int[] R = new int[N + 2];
		for (int i = N; i >= 1; i--)
			R[i] = gcd(R[i + 1], A[i]);
		int max = 0;
		for (int i = 1; i <= N; i++)
			max = Math.max(max, gcd(L[i - 1], R[i + 1]));
		System.out.println(max);

	}

	public static int gcd(int a, int b) {
		int c = 0;
		if (a < b)
			return gcd(b, a);

		if (b == 0)
			return a;

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

	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 25512
#include<stdio.h>
#include<string.h>
#define max 2000001
void extmax(int *,int,int);
void BUILDMaxHeap(int *,int);
void insert(int *,int,int);
int main(void){
    int S[max];
    int cnt=0;
    int key;
    char cmd[10];
     
    while(1){
        scanf("%s",cmd);
        if(cmd[0]=='i'){
            scanf("%d",&key);
            insert(S,key,++cnt);
        }
	    else if(cmd[0]=='e' && cmd[1]=='x'){
            printf("%d\n",S[1]);
            S[1]=S[cnt--];
            extmax(S,1,cnt);
        }
        else break;
    }
    return 0;
}

void extmax(int *S,int i,int h){
    int l=i*2;
    int r=l+1,temp;
    int lar=i;
     
    if(l<=h && S[l]>S[i])lar=l;
    if(r<=h && S[r]>S[lar])lar=r;
     
    if(lar!=i){
        temp=S[i];
        S[i]=S[lar];
        S[lar]=temp;
        extmax(S,lar,h);
    }
}
 
void BUILDMaxHeap(int *S,int h){
    int i;
	for(i=h/2;i>0;i--) {
		extmax(S,i,h);
	}
}
 
void insert(int *S,int key,int cnt){
    S[cnt]=key;
    int chd=cnt,temp;
    int par=chd/2;
    while(par>0){
        if(S[par]<S[chd]){
            temp=S[chd];
            S[chd]=S[par];
            S[par]=temp;
        }
        chd=par;
        par=chd/2;
    }
}


Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
int main(){
  double x,h;
  while(1){
    scanf("%lf %lf",&x,&h);
    if(x==0 && h==0) break;
    double soku = sqrt(((double)x*0.5) * ((double)x*0.5)+ (double)h*(double)h);
    printf("%f\n",(double)x*(double)x + (double)4 * (soku * (double)x * 0.5));
  }
}

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

int main (void){
	int n,k = -1;
	cin >> n;
	n *= 2;
	for(int i = 1; i < n; ++i){
		if(n % i == 0 && abs(i - n / i) == 1){
			k = n / i;
			break;
		}
	}
	if(k != -1){
		cout << "Yes" << endl;
		cout << k << endl;
	}else{
		cout << "No" << endl;
		return 0;
	}
	for(int i = 0; i < k; ++i){
		cout << k-1 << " ";
		int tmp = 1;
		for(int j = 0; j < i; ++j){
			cout << tmp + i - j - 1 << " ";
			tmp += (k-1) - j;
		}
		for(int j = tmp; j <= (k-1) - i + tmp - 1; ++j){
			cout << j << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g;
vector<edge>edges;
//vector<Pll>v;
map<Pll, Pll>ma;
set<LL>st;
double h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000];
string str, ss;
bool f[200][200];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		ans += double(1.0) / a[i];
	}
	printf("%.15f\n", 1.0 / ans);
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
amount = 0
money = 0
ab = [list(map(int, input().split())) for _ in range(n)]
sorted_ab = sorted(ab)
for i in range(n):
  if amount > m:
    break
  amount += sorted_ab[i][1]
  money += sorted_ab[i][0] * sorted_ab[i][1]
  if amount > m:
    money -= (sorted_ab[i][0] * (amount - m))
  
print(money)

Measured memory_bytes: 28648
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int i,n,c,k,a[100005],t,c1;
	long long ans=1;
	scanf("%d%d%d",&n,&c,&k);
	for(i=0;i<n;i++)
	 scanf("%d",&a[i]);
	sort(a,a+n);
	c1=1;t=0;
	for(i=1;i<n;i++)
	{
		if(a[i]<=a[t]+k && c1<c)
		{
			c1++;
		}
		else
		{
			ans++;
			t=i;
			c1=1;
		}
	}
	printf("%lld\n",ans);
  return 0;
}

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

typedef long long ll;
ll a[100005];
ll inf[100005];
ll inff=1e18+7;

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<=n;i++){
		cin>>a[i];
	}
	if(n==0){
		if(a[0]==1){
			cout<<"1"<<endl;
		}
		else {
			cout<<"-1"<<endl;
		}
		return 0;
	}
	inf[0]=1;
	for(int i=1;i<=n;i++){
		inf[i]=max(0ll,min(inff,(inf[i-1]-a[i-1])*2));
	}
	ll sum=0;
	ll temp=0;
	for(int i=n;i>=0;i--){
		if((temp+1)/2+a[i]>inf[i]){
			cout<<"-1"<<endl;
			return 0;
		}
		temp=min(inf[i],temp+a[i]);
		sum+=temp;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 5196
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N,A,B,C;
  cin >> N >> A >> B >> C;
  vector<int> s(N);
  string si;
  for(int i=0;i<N;i++){
    cin >> si;
    if(si=="AB") s[i]=0;
    else if(si=="BC") s[i]=1;
    else s[i]=2;
  }

  vector<string> abc={"A","B","C"};
  vector<int> cur(3);
  cur={A,B,C};
  vector<int> ans(N);
  int l,m;
  for(int i=0;i<N;i++){
    l=s[i]; m=(l+1)%3;
    if(cur[l]<cur[m]){
      ans[i]=l;
      cur[l]++; cur[m]--;
    }else if(cur[l]==1 && cur[m]==1 && i<N-1){
      if(m!=s[i+1] && m!=(s[i+1]+1)%3){
        ans[i]=l;
        cur[l]++; cur[m]--;
      }else{
        ans[i]=m;
        cur[m]++; cur[l]--;
      }
    }else{
      cur[m]++; cur[l]--;
      ans[i]=m;
    }
    if(cur[0]<0 || cur[1]<0 || cur[2]<0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for(int i=0;i<N;i++){
    cout << abc[ans[i]] << endl;
  }

  return 0;
}


Measured memory_bytes: 4052
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 2005;
const int mod = 1e9+7;
int C[maxd][maxd],pre[maxd];
void init()
{
    C[0][0] = C[1][0] = C[1][1] = 1;
    for(int i=2;i<maxd;i++)
    {
        C[i][0] = 1;
        for(int j=1;j<=i;j++)
            C[i][j] = (1ll * C[i-1][j]  + C[i-1][j-1]) %mod;
    }
    pre[0] = 1;
    for(int i=1;i<maxd;i++)
        pre[i] = (1ll*pre[i-1] * i) %mod;
}
int pow(int x,int y)
{
    int ans = 1;
    while(y)
    {   
        if(y&1) ans = 1ll * ans * x %mod;
        x = 1ll * x * x %mod;
        y/=2;
    }
    return ans;
}
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
    int n,m;init();
    scanf("%d %d",&n,&m);
    n = n - m;
    for(int i=1;i<=m;i++)
    {
        //printf("%lld\n",1ll * C[m-1][i-1]);
        printf("%lld\n",1ll * C[m-1][i-1] * C[n-i+1+i][i] %mod);
    }
    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,H,W;
  cin>>N>>H>>W;
  int ans=0;
  REP(i,N){
    int A,B;
    cin>>A>>B;
    if(A>=H and B>=W)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 5e5 + 7;
const int INF = 1e9 + 239;

int d[N];
vector<pair<int, int>> g[N];

set<int> sn[N];
map<pair<int, int>, int> ind;

int dij(int st, int en) {
	fill(d, d + N, INF);
	deque<int> q;
	d[st] = 0;
	q.push_back(st);
	while (!q.empty()) {
		int v = q.front();
		q.pop_front();
		for (auto t : g[v]) {
			if (d[t.first] > d[v] + t.second) {
				d[t.first] = d[v] + t.second;
				if (!t.second) q.push_front(t.first);
				else q.push_back(t.first);
			}
		}
	}
	return d[en];
}

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

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		ind[{i, -1}] = i;
	}
	vector<tuple<int, int, int>> ed;
	while (m--) {
		int u, v, c;
		cin >> u >> v >> c;
		u--;
		v--;
		c--;
		sn[u].insert(c);
		sn[v].insert(c);
		ed.push_back({u, v, c});
	}
	int pnt = n;
	for (int i = 0; i < n; i++) {
		for (auto x : sn[i]) {
			ind[{i, x}] = pnt;
			pnt++;
		}
	}
	for (int i = 0; i < n; i++) {
		for (auto x : sn[i]) {
			g[ind[{i, -1}]].push_back({ind[{i, x}], 1});
			g[ind[{i, x}]].push_back({ind[{i, -1}], 1});
		}
	}
	for (auto t : ed) {
		int u, v, c;
		tie(u, v, c) = t;
		g[ind[{u, c}]].push_back({ind[{v, c}], 0});
		g[ind[{v, c}]].push_back({ind[{u, c}], 0});
	}
	int ans = dij(ind[{0, -1}], ind[{n - 1, -1}]);
	if (ans == INF) {
		cout << -1 << endl;
	} else {
		cout << ans / 2 << endl;
	}
}	



Measured memory_bytes: 88624
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();

    if n % 2 == 0 {
        let m = (n-2) * n / 2;
        println!("{}", m);

        for i in 2..n {
            println!("{} {}", 1, i);
            println!("{} {}", n, i);
        }

        for i in 2..n {
            for j in i+1..n {
                if i + j != n + 1 {
                    println!("{} {}", i, j);
                }
            }
        }
    } else {
        let m = (n-1) * (n-1) / 2;
        println!("{}", m);

        for i in 1..n {
            println!("{} {}", n, i);
        }

        for i in 1..n {
            for j in i+1..n {
                if i + j != n {
                    println!("{} {}", i, j);
                }
            }
        }
    }

}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
using namespace std;
bool f[100005];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	while (m--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		f[a]^=1;
		f[b]^=1;
	}
	printf(count(f,f+n+1,1)? "NO":"YES");
}

Measured memory_bytes: 384
import math
a,b,c,d = map(int,input().split())
e = math.floor(c*d / math.gcd(c,d))

def div(z):
    p = (z//c) + (z//d) - (z//e)
    return p

x = a-1 - div(a-1)
y = b - div(b)
print(y-x)

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

int main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	-- a, -- b, -- c, -- d;
	string s; cin >> s;
	vector <bool> has(n);
	for (int i = 0; i < n; ++ i)
		has[i] = (s[i] == '#');
	auto check = [&](int x, int y) -> bool {
		for (; x < y; ++ x)
			if (s[x] == '#' && s[x + 1] == '#') return false;
		return true;
	};
	if (!check(a, c) || !check(b, d))
		return cout << "No\n", 0;
	if (c < d) return cout << "Yes\n", 0;
	for (int i = b; i <= d; ++ i)
		if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.')
			return cout << "Yes\n", 0;
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 644
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a = int(readline())
    print(a + a ** 2 + a ** 3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61736
#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;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans
#define ordered_set tree<pair<int,int> , null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
    Speed;
    ll n,i;
    cin>>n;
    ll ans = 0;
    ans = (n * (n - 1))/2;
    cout<<ans;


    return 0;
}


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

using namespace std;

const int N = 2000 + 5;

int n;
int lim;
vector<int> g[N];

int dist[N][N];

void dfs(int v, int fa, int anc) {
  for (auto u : g[v]) {
    if (u != fa) {
      dist[anc][u] = dist[anc][v] + 1;
      dfs(u, v, anc);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> lim;
  for (int i = 0; i < n - 1; ++i) {
    int v;
    int u;
    cin >> v >> u;
    --v;
    --u;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 0; i < n; ++i) {
    dfs(i, -1, i);
  }
  if (lim & 1) {
    int ans = n;
    for (int i = 0; i < n; ++i) {
      for (auto j : g[i]) {
        int cnt = 0;
        for (int k = 0; k < n; ++k) {
          if (min(dist[i][k], dist[j][k]) > (lim - 1) / 2) {
            ++cnt;
          }
        }
        ans = min(ans, cnt);
      }
    }
    cout << ans << endl;
  } else {
    int ans = n;
    for (int i = 0; i < n; ++i) {
      int cnt = 0;
      for (int j = 0; j < n; ++j) {
        if (dist[i][j] > lim / 2) {
          ++cnt;
        }
      }
      ans = min(ans, cnt);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 16256