akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int n,m,d;
  cin >> n >> m >> d;
  if(d == 0) {
    cout << setprecision(20) <<  (double)(m-1)/ (double)n << endl;
  } else {
    cout << setprecision(20) << (double)((double)(m-1) * (double)2 * (double)(n-d)) / (double)(n) / (double)(n) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//Indomie, Mie dari Indonesia
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
int nodes,edge,degree[100005]={};
int main()
{
	scanf("%d%d",&nodes,&edge);
	for(int i=1;i<=edge;i++)
	{
		int u,v;
		cin>>u>>v;
		degree[u]++;
		degree[v]++;
	}
	for(int i=1;i<=nodes;i++)
	{
		if(degree[i]&1)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF INT_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    vector<int> a(5);
    REP(i,0,5) cin >> a[i];
    
    int k=10;
    REP(i,0,5) if(a[i]%10!=0) chmin(k,a[i]%10);
    REP(i,0,5) a[i]=RUP(a[i],10)*10;
    
    int ans=0;
    REP(i,0,5) ans += a[i];
    cout << ans+k-10 << ENT;
    return 0;
}


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


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    int n,m;
    cin >> n >> m;

    if(n == m){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

double dp[3000][3000];

int main() {
  int n;
  cin >> n;
  double p[n + 1];
  REP1(i, n) cin >> p[i];
  dp[1][1] = p[1], dp[1][0] = 1.0 - p[1];
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0) {
        dp[i][j] += dp[i - 1][j] * (1.0 - p[i]);
      } else if (j == i) {
        dp[i][j] += dp[i - 1][j - 1] * p[i];
      } else {
        dp[i][j] += dp[i - 1][j - 1] * p[i];
        dp[i][j] += dp[i - 1][j] * (1.0 - p[i]);
      }
    }
  }
  double ans = 1.0;
  for (int i = 0; i <= n / 2; ++i) {
    ans -= dp[n][i];
  }
  printf("%.12f\n", ans);
  return 0;
}

Measured memory_bytes: 68864
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;

#ifdef LOCAL 
#include "/home/gokul/Codes/lib/prettyprint.hpp"
#else
#define debug(...) 2
#endif

template <int MOD=1000000007>
struct Modular {
  int value;
  static const int MOD_value = MOD;

  Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
  Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}

  Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
  Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
  Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}

  friend Modular mexp(Modular a, long long e) {
    Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
    return res;
  }
  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }

  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
  friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
  friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};

Modular<M> p[200005], ans = 0;
vector<vector<int>> adj;
vector<int> sub;

void dfs(int x, int par) {
  sub[x] = 1;
  for (auto to : adj[x]) {
    if (to == par) continue;
    dfs(to, x);
    sub[x] += sub[to];
    ans += p[sub[to]] * p[(int)adj.size() - sub[to]];
  }
}

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  Modular<M> mul(1, 2);
  p[0] = 1;
  for (int i = 1; i < 2e5+5; ++i)
    p[i] = p[i-1] * mul;
  for (int i = 0; i < 2e5 + 5; ++i)
    p[i] = 1 - p[i];

  adj.resize(n);
  sub.resize(n);
  for (int i = 0; i < n-1; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;

    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  dfs(0, 0);
  mul *= n;
  debug(mul);
  ans -= mul;
  ans += p[n-1];
  ans += 1 - p[n];

  cout << ans << '\n';
}



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

int main()
{
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if((e-a)<=k)
    {

        cout<<"Yay!"<<endl;

    }
    else
    {
        cout<<":("<<endl;
    }


}

















Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
typedef long long LL;
const int maxN = 1e5 + 7;
const LL ONE = 1;
int N;
int P[maxN];     // P数组为1~N的一组排列 
int pos[maxN];     // pos[i]为i在P数组中的位置 
int leftFirstMaxPos[maxN];     // leftFirstMaxPos[i]为i位置的数左边第一个比i大的数的位置,没有则为0
int rightFirstMaxPos[maxN]; // rightFirstMaxPos[i]为i位置的数右边第一个比i大的数的位置,没有则为N+1 
LL ans = 0; 

int main(){
    //freopen("MyOutput.txt","w",stdout);
    //freopen("input.txt","r",stdin);
    //INIT();
    scanf("%d", &N);
//    For(i, 1, N) {
	for(int i=1;i<=N;i++){
        scanf("%d", &P[i]);
        pos[P[i]] = i; 
        // 后面是从1开始枚举,而1是最小的,所以1的左右最近大正好是相邻的两个数 
        leftFirstMaxPos[i] = i - 1;
        rightFirstMaxPos[i] = i + 1;
    }
    
    // 计算每个数i为第二大的时候对答案的贡献 
	for(int i=1;i<=N;i++){
        int Lpos1 = leftFirstMaxPos[pos[i]];     // i左边第一个比他大的数的位置 
        int Lpos2 = leftFirstMaxPos[Lpos1];        // i左边第二个比他大的数的位置 
        int Rpos1 = rightFirstMaxPos[pos[i]];    // i右边第一个比他大的数的位置 
        int Rpos2 = rightFirstMaxPos[Rpos1];        // i右边第二个比他大的数的位置 
        
        if(Lpos1 != 0) ans +=  ONE*i * (Lpos1 - Lpos2) * (Rpos1 - pos[i]);
        if(Rpos1 != N + 1) ans +=  ONE*i * (pos[i] - Lpos1) * (Rpos2 - Rpos1);
        
        // 更新 
        /*
            例如这个片段:
                  1 2 3 4 5 6 7 
                P 6 3 1 2 5 4 7
                此时以i = 1为例
                本来leftFirstMaxPos[4] = 3, rightFirstMaxPos[2] = 3的
                计算完i = 1的贡献之后, leftFirstMaxPos[4] = 2, rightFirstMaxPos[2] = 4
                这一步更新相当于把1给砍掉了,剩下的数中2又是最小的数,于是2的左右最近大又正好是相邻的两个数 
                没错,非常像链表删除一个值的操作 
                leftFirstMaxPos就相当于静态链表的前驱数组
                rightFirstMaxPos就相当于静态链表的后继数组 
        */ 
        leftFirstMaxPos[Rpos1] = Lpos1;
        rightFirstMaxPos[Lpos1] = Rpos1;
    }
    
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
from itertools import combinations

n = int(input())

f = []

for _ in range(n):
    line = list(map(lambda n:int(n),input().split(" ")))
    f.append(line)

p = []
for _ in range(n):
    line = list(map(lambda n:int(n),input().split(" ")))
    p.append(line)

def overlap(ary1,ary2):
    ret = 0
    for i in range(len(ary1)):
        if ary1[i]==ary2[i] and ary1[i]==1:
            ret += 1
    return ret

def calcProf(jary):
    # 各時間帯で店を開くかどうかの情報を元に、利益を計算する
    ret = 0
    for i in range(n):
        lap = overlap(jary, f[i])
        ret += p[i][lap]
    return ret

def conv(ary):
    ret = [0 for _ in range(10)]
    for i in ary:
        ret[i] = 1
    return ret

prof = -1000000000
for e in range(1,11):
    for elem in combinations(range(10), e):
        cp = calcProf(conv(elem))
        if cp>prof:
            prof = cp

print(prof)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
    long long int a,b,c,d,n,m,array[100000+10],ans=0,sum1=0,sum2=0,sum3=0,sum=0,cnt=0,cnt1=0,cnt2=0,cnt3=0,flag,flag1,flag2;
    int i,j;
    string s[1000],p[1000];
    char ch;
    cin>>n>>m;
    for(i=0; i<n; i++)
    {
        s[i]=m+'0';
    }
    for(i=0; i<m; i++)
    {
        p[i]=n+'0';
    }
    if( lexicographical_compare(s, s+n, p, p+m))
    {
        flag=1;
    }
    else
    {
        flag=0;

    }
    if(flag==1)
    {
        for(i=0; i<n; i++)
            cout<<s[i];
    }
    else
    {
        for(i=0; i<m; i++)
            cout<<p[i];
    }


}


Measured memory_bytes: 256
N=int(input())
s=[input() for i in range(N)]
M=int(input())
t=[input() for i in range(M)]
l=[]

tmp=s.copy()
tmp=set(tmp)
tmp=list(tmp)

for i in tmp:
    S=s.count(i)
    T=t.count(i)
    l.append(S-T)
print(max(0,max(l)))
    


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

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

	for (uint i = 0; i < 30; ++i) {
		int cost0 = i * 4;
		for (uint j = 0; j < 20; ++j) {
			int cost1 = cost0 + j * 7;
			if (cost1 == argN) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ans=0;
		int a[]=new int[n*2];
		for(int i=0;i<n*2;i++) {
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		for(int i=0;i<n*2;i+=2) ans+=a[i];
System.out.println(ans);
	}
}

Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(10000000)


while True:
    W, H = map(int, input().split())
    if W == 0 and H == 0:
        break
    G = [list(map(int, input().split())) for i in range(H)]
    dh = (0, -1, -1, -1, 0, 1, 1, 1)
    dw = (-1, -1, 0, 1, 1, 1, 0, -1)

    def dfs(h, w):
        for i in range(8):
            nh = h + dh[i]
            nw = w + dw[i]
            if nh < 0 or nh >= H or nw < 0 or nw >= W:
                continue
            if not G[nh][nw]:
                continue
            G[nh][nw] = 0
            dfs(nh, nw)
    
    cnt = 0
    for i in range(H):
        for j in range(W):
            if G[i][j]:
                dfs(i, j)
                cnt += 1
    print(cnt)


Measured memory_bytes: 7940
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int A;
int main(){
  int Lj4PdHRW;
  for(Lj4PdHRW=(0);Lj4PdHRW<(3);Lj4PdHRW++){
    A += rd_int();
  }
  if(A>=22){
    wt_L("bust");
    wt_L('\n');
  }
  else{
    wt_L("win");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191208-1 [beta]

// --- original code ---
// int A;
// {
//   rep(3) A += rd_int();
//   wt(if[A>=22, "bust", "win"]);
// }


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

int main(void){
  int i,n,m;
  scanf("%d%d",&n,&m);
  for(i=1;i<4;i++)
    if(n*m*i%2==1){
      printf("Yes\n");
      return 0;
    }
  printf("No\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
    int a, b, x;
    cin >> x >> a >> b;
    int adist = abs(x-a);
    int bdist = abs(x-b);
    cout << (adist < bdist ? "A" : "B") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
int main(){
    int a, b;
 
    cin >> a >> b;
    
    if(a == 1 && b != 1){
        cout << "Alice" << endl;
        return 0;
    }else if(a != 1 && b == 1){
        cout << "Bob" << endl;
        return 0;
    }
 
    if(a - b > 0){
        cout << "Alice" << endl;
    }else if(a - b < 0){
        cout << "Bob" << endl;
    }else{
        cout << "Draw" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>	
#include<vector>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int n, m; cin >> n >> m;
	for (int i = m / n + 1; i >= 1; i--) {
		if (m % i == 0) {
			if (m / i >= n) {
				cout << i << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans1 = min(a,b);
  int ans2 = min(c,d);
  cout << (ans1 + ans2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int l=1;
  int r=n;
  for(int i=0;i<m;i++){
    int li,ri;
    cin>>li>>ri;
    l=max(l,li);
    r=min(r,ri);
  }
  cout<<max(r-l+1,0)<<endl;
}

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

#define fi first
#define se second
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 2e5 + 5;

int a[MAXN],opt[MAXN],n;
LL suf[MAXN],sm[MAXN];

int main(){
    scanf("%d%d",&n,a+1);opt[1] = 1;
    FOR(i,2,n){
        char str[3];scanf("%s",str);
        opt[i] = str[0]=='-'?-1:1;
        scanf("%d",a+i);
    }
    FOR(i,1,n) sm[i] = sm[i-1]+a[i];
    int lst = n;
    ROF(i,n,1){
        suf[i] = sm[lst]-sm[i];
        if(opt[i+1] == -1) lst = i;
    }
//    FOR(i,1,n) DEBUG(suf[i]);
    LL ans = a[1],pre = 0;
    FOR(i,2,n) ans += a[i]*opt[i];
    FOR(i,1,n-1){
        pre += opt[i]*a[i];
        if(opt[i+1] == 1) continue;
        else ans = std::max(ans,pre+sm[n]-sm[i]-2*suf[i]);
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=n;
  rep(i,n-1){
    if(s[i]!=s[i+1])ans=min(ans,max(i+1,n-(i+1)));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define mod1 998244353 
#define inf 1000000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

set<ll> adj[100005],agla[100005];
set<pll> s;

int main()
{
    fastio;
    #ifdef APNA_IO
        start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);    
    #endif
 
    ll n,m;cin>>n>>m;
    if(m%2) return cout<<-1,0;

    for(ll i=0;i<m;i++)
    {
        ll x,y;cin>>x>>y;
        adj[x].insert(y);
        adj[y].insert(x);
    }

    for(ll i=1;i<=n;i++)
        s.insert({adj[i].size(),i});

    while(s.size())
    {
        pll p=*(s.begin());
        s.erase(s.begin());

        if(agla[p.ss].size()%2!=0)
        {
            ll x=*(adj[p.ss].begin());
            adj[p.ss].erase(adj[p.ss].begin());
            agla[p.ss].insert(x);
            s.erase(s.find({adj[x].size(),x}));
            adj[x].erase(adj[x].find(p.ss));
            s.insert({adj[x].size(),x});            
        }

        for(auto i:adj[p.ss])
        {
            s.erase(s.find({adj[i].size(),i}));
            agla[i].insert(p.ss);
            adj[i].erase(adj[i].find(p.ss));
            s.insert({adj[i].size(),i});
        }
        adj[p.ss].clear();
    }

    for(ll i=1;i<=n;i++)
        for(auto j:agla[i])
            cout<<i<<" "<<j<<endl;
    

    #ifdef APNA_IO
        end_routine();
    #endif
}


Measured memory_bytes: 26368
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	deque<char> dq;string S;
	cin >> S;char c;bool r = 0;
	rep(i,S.size()) dq.push_back(S[i]);
	int q, p, f;cin >> q;
	rep(i, q) {
		cin >> p;
		if (p == 1) r ^= 1;
		else {
			cin >> f >> c;f--;
			if (f ^ r) dq.push_back(c);
			else dq.push_front(c);
		}
	}
	if(r)reverse(dq.begin(), dq.end());
	rep(i, dq.size()) cout << dq[i];
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String t = sc.next();
		String s = sc.next();
		char[] c = new char[1000];
		Arrays.fill(c, '0');
		int count = 0;
		String s2 = "";
		for(int i = 0 ; i < s.length() ; i++) {
			if(c[s.charAt(i)] == '0') {
				count++;
				c[s.charAt(i)] = t.charAt(i);
				if(!s2.contains(t.charAt(i) + "")) {
				s2 += t.charAt(i);
				}
				else {
					System.out.println("No");
					return;
				}
			}
			else if(c[s.charAt(i)] != t.charAt(i)){
				System.out.println("No");
				return;
			}
		}

		sc.close();
		System.out.println("Yes");

	}
}



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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}

bool next(vector<ll>& now, const ll M)
{
	now.back() += 1;
	ll size = now.size();
	ll i = size - 1;
	for (; now[i] > M && i >= 0; --i)
	{
		if (i == 0)
		{
			return false;
		}
		else
		{
			++now[i - 1];
			now[i] = now[i - 1];
		}
	}
	++i;
	for (; i < size; ++i)
	{
		now[i] = now[i - 1];
	}
	return true;
}

int main(int, char**)
{
	long long N;
	scanf("%lld",&N);
	long long M;
	scanf("%lld",&M);
	long long Q;
	scanf("%lld",&Q);
	std::vector<long long> a(Q);
	std::vector<long long> b(Q);
	std::vector<long long> c(Q);
	std::vector<long long> d(Q);
	for(int i = 0 ; i < Q ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
		scanf("%lld",&c[i]);
		scanf("%lld",&d[i]);
	}

	vector<ll> A(N, 1);
	ll m = 0;
	do
	{
		ll sum = 0;
		for (ll i = 0; i < Q; ++i)
		{
			if (A[b[i] - 1] - A[a[i] - 1] == c[i])	sum += d[i];
		}
		m = max(m, sum);

		/*
		for (ll i = 0; i < N; ++i)
		{
			cerr << A[i] << ", ";
		}
		cerr << endl;
		*/
	} while (next(A, M));
	cout << m << endl;

	return 0;
}


Measured memory_bytes: 3704
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

n,m = map(int, input().split())
a = list(map(int, input().split()))
lcm_a = a[0]
for i in a[1:]:
  lcm_a = lcm_a * i // fractions.gcd(lcm_a,i)
  if lcm_a > m * 2:
    print(0)
    exit()
if all([(lcm_a // i) % 2 for i in a]):
  ans = (m - lcm_a // 2) // lcm_a + 1
  print(ans)
else:
  print(0)

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

int main(){
  int n;
  int total;
  
  cin >> n;
  int b[n];
  
  rep(i,n-1){cin >> b[i];}
  
  total = b[0] + b[n-2];
  //cout << total << endl;
  for(int i = 1; i < n-1; i++){
    total += min(b[i],b[i-1]);
  }
  cout << total;
}

Measured memory_bytes: 256
from itertools import *
from bisect import *
from math import *
from collections import *
from heapq import *
from random import *
from decimal import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n,k=MI()
    aa=LI()
    bek=[False]*(1<<n)
    for bit in range(1<<n):
        if bek[bit]==False:
            s=sum(a for i,a in enumerate(aa) if bit>>i&1)
            if s==k:bek[bit]=True
            else:continue
        for j in range(n):
            bek[bit|1<<j]=True
    mx=0
    for bit in range(1<<n):
        if bek[bit]:continue
        popcnt=bin(bit).count("1")
        if popcnt>mx:mx=popcnt
    print(n-mx)

main()



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

ll a[2*(int)1e5], sum, ans = 10000000000LL, allsum;

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        allsum += a[i];
    }
    for (int i = 0; i < n; i++) {
        sum += a[i];
        if (i+1 < n) ans = min(ans, abs(allsum-2*sum));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{ int n;
cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];

    int dp[n+1]={0};
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    { dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));

    }


    cout<<dp[n-1]<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

int n;
int a[100010]; 

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int sum = abs(a[0]) + abs(a[n-1]);
    for(int i=1;i<n;i++) sum += abs(a[i] - a[i-1]);
    cout << (sum + abs(a[1]) - (abs(a[0])+abs(a[1]-a[0]))) << endl;
    for(int i=1;i<n-1;i++){
        cout << (sum + abs(a[i+1]-a[i-1]) - (abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))) << endl;
    }
    cout << (sum + abs(a[n-2]) - (abs(a[n-1]-a[n-2])+abs(a[n-1]))) << endl;
}

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

template <typename T> class SegmentTree{
	public :
		int n;
		SegmentTree(int size,T o): out_of_range(o){
			for(n=1;n<size;n<<=1);
			data=vector<T>(2*n,out_of_range);
			lazy=vector<bool>(2*n,false);
		}

		void update(int a,int b,T x,int k,int l,int r){
			if(r<=a || b<=l) return;
			if(a<=l&&r<=b){data[k]+=x,lazy[k]=true;return;}
			if(lazy[k]) lazy_evaluate(k);
			update(a,b,x,k*2+1,l,(l+r)/2);
			update(a,b,x,k*2+2,(l+r)/2,r);
			data[k]=data[k*2+1]+data[k*2+2];
		}

		T query(int a,int b,int k,int l,int r){
			if(r<=a||b<=l) return out_of_range;
			if(a<=l&&r<=b)return data[k];
			if(lazy[k]) return (r-l)*data[k];
			T vl = query(a,b,k*2+1,l,(l+r)/2);
			T vr = query(a,b,k*2+2,(l+r)/2,r);
			return vl+vr;
		}
	private:
		vector<T> data;
		vector<bool> lazy;
		const T out_of_range;

		inline void lazy_evaluate(int k){
			data[k*2+1]+=data[k];lazy[k*2+1]=true;
			data[k*2+2]+=data[k];lazy[k*2+2]=true;
			lazy[k]=false;
		}
};

int main(void){
	int N,Q;
	cin >>  N >> Q;
	SegmentTree<int> rsq(N,0);

	for(int i=0;i<Q;i++){
		int type;
		cin >> type;
		if(type){
			int s,t;
			cin >> s >> t;
			s--,t--;
			cout << rsq.query(s,t+1,0,0,rsq.n) << endl;
		}else{
			int a,x;
			cin >> a >> x;
			a--;
			rsq.update(a,a+1,x,0,0,rsq.n);
		}
	}
	return 0;
}

Measured memory_bytes: 2256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

	int n;//カードの数
	int taro_points = 0;
	int hanako_points = 0;
	bool get_points = false;
	string taro_card, hanako_card;
	
	cin >> n;

	rep(i, n){
		cin >> taro_card >> hanako_card;

		if (taro_card == hanako_card){//文字列が等しいとき
			//それぞれ1点加算
			taro_points++;
			hanako_points++;

			continue;//以下の処理を飛ばす
		}
		
		rep(j, min(taro_card.size(), hanako_card.size())){//少ない方の文字数回ループ
			if (taro_card[j] > hanako_card[j]){//太郎カードの文字の方が大きいとき
				taro_points += 3;
				get_points = true;
				break;
			}
			else if (taro_card[j] < hanako_card[j]){
				hanako_points += 3;
				get_points = true;
				break;
			}
		}

		//文字列の短い方を+3
		if (get_points == false){
			if (taro_card.size() > hanako_card.size()){
				taro_points += 3;
			}
			else{
				hanako_points += 3;
			}
		}

		get_points = false;//初期化
	}

	cout << taro_points << " " << hanako_points << '\n';

	return 0;
}


Measured memory_bytes: 3228
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    ll X;
    cin >> X;
    ll ans = (X/500)*1000;
    X -= (X/500)*500;
    ans += (X/5)*5;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  ll N; cin >> N;
  map <ll, int> mp;
  
  if(N == 1){
    cout << 0 << endl;
    return 0;
  }
  
  ll cnt = 0;
  vector<ll> A(N);
  for(int i = 0; i < N; ++i){
    cin >> A.at(i);
    mp[A.at(i)]++;
  }
  
  sort(A.begin(), A.end());
  
  for(int i = N-1; i > 0; --i){
    if(mp[A.at(i)]==0) continue;
    ll x = 1;
    while(x <= A.at(i)) x*=2;
    ll d = x - A.at(i);
    
    if(d!=A.at(i) && mp[d]>0){
      cnt++;
      mp[A.at(i)]--;
      mp[d]--;
    }
    else if(d==A.at(i) && mp[d]>1){
      cnt++;
      mp[d] -= 2;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 26752
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000007
#define all(x) x.begin(), x.end()
using namespace std;

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

    int tc = 1;
    //cin >>  tc;
    while(tc--){
        int n, k;
        cin >> n >> k;
        int a[n];
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        sort(a, a + n);
        int sum = 0;
        for(int i = 0; i < k; i++){
            sum += a[i];
        }
        cout << sum;
    }
}



Measured memory_bytes: 3660
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var b = new int[n];
        for (int i = 0; i < n - 1; i++) b[a[i] - 1]++;
        Console.WriteLine(string.Join("\n", b));
    }
}


Measured memory_bytes: 39448
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#define MAX 10002
using namespace std;
int p[MAX];
int root(int x){
    if(p[x]==x)return x;
    return p[x] = root(p[x]);
}

int main(){
  int n,q,x,y,i;
  bool com;
  cin>>n>>q;
  for(i=1;i<n+1;i++)p[i]=i;
  for (i=0;i<q;i++){
    cin>>com>>x>>y;
    if(com)cout<<(root(x) == root(y))<<endl;
    else p[root(x)] = root(y);
  }
  return 0;
}



Measured memory_bytes: 3176
S = input()

if len(S) < 26:
    for i in range(26):
        if chr(i+97) not in S:
            ans = S + chr(i+97)
            break
elif S == "zyxwvutsrqponmlkjihgfedcba":
    ans = -1
else:
    ans = ""
    L = [S[-1]]
    for i in range(24, -1, -1):
        for l in L:
            if S[i] < l:
                for j in range(i):
                    ans += S[j]
                ans += l
                break
        if ans:
            break
        L.append(S[i])
        L.sort()
print(ans)

Measured memory_bytes: 9024
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll a, b, c; cin >> a >> b >> c;
	if (a - b >= c) {
		cout << 0 << endl;
	}
	else {
		cout << c - (a - b) << endl;
	}
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int dp[2010][2];
int n;
int a[2010];

int dfs(int pos, int x, int y, int turn) {
  if (dp[pos][turn] != -1) return dp[pos][turn];
  if (pos == n) return abs(x-y);
  if (turn == 0) {
    int res = 0;
    FOR(i, pos, n) {
      res = max(res, dfs(i+1, a[i], y, 1));
    }
    dp[pos][turn] = res;
    return dp[pos][turn];
  } else {
    int res = INF;
    FOR(i, pos, n) {
      res = min(res, dfs(i+1, x, a[i], 0));
    }
    dp[pos][turn] = res;
    return dp[pos][turn];
  }
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  REP(i, 2010) REP(j, 2) dp[i][j] = -1;
  int z, w; cin >> n >> z >> w;
  REP(i, n) cin >> a[i];
  cout << dfs(0, z, w, 0) << '\n';
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<algorithm>
using namespace std;
int n,m;
double x;
long long s,s1;
priority_queue<double> p;
int main()
{
	int i;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>x;
		p.push(x);
	}
	for(i=0;i<m;i++)
	{
		x=p.top();
		p.pop();
		x/=2;
		p.push(x);
	}
	s=0;
	for(i=0;i<n;i++)
	{
		s1=(long long)p.top();
		s+=s1;
		p.pop();
	}
	printf("%Ild\n",s);
	return 0;
}

Measured memory_bytes: 1400
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}
const int N = 1e5 + 6;
int cnt[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  cin >> v;
  sort(all(v));
  v.resize(k);
  cout << accumulate(all(v), 0) << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll INF = 1001001001001001001;
const double pi = acos(-1);

int main()
{
    string s;
    cin >> s;
    ll n = s.size();
    ll mod = 1000000007;
    vector<vector<ll>> dp(n, vector<ll>(2, 0));
    // dp[i][0]は、i番目の文字までで和がl未満確定。
    // dp[i][1]は、i番目の文字まで和がlと一致。

    dp[0][0] = 1;
    dp[0][1] = 2;
    for (ll i = 1; i < n; i++)
    {
        if (s[i] == '0')
        {
            dp[i][0] = dp[i - 1][0] * 3;
            dp[i][1] = dp[i - 1][1];
        }
        else
        {
            // s[i] == 1
            dp[i][0] = dp[i - 1][0] * 3 + dp[i - 1][1];
            dp[i][1] = dp[i - 1][1] * 2;
        }
        dp[i][0] %= mod;
        dp[i][1] %= mod;
    }
    cout << (dp[n - 1][0] + dp[n - 1][1]) % mod << endl;

    return 0;
}


Measured memory_bytes: 5888
def add(a,b): 
    return a + b
def sub(a,b): 
    return a - b
def mul(a,b): 
    return a * b
def div(a,b): 
    return a/ float(b)

A=input().split()
i=0
for j in range(len(A)):
    if A[i]=="+":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=add(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="-":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=sub(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="*":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=mul(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="/":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=div(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    i=i+1
print(r)



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

using namespace std;

int main() {

    string s;
    int n;
    cin >> n >> s;

    int ans = 0;

    for(int i = 0; i < n; i++){
        for(int j = i + 1;j < n && s[j] == s[i];i++,j++);
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
n = int(input())
if n <= 111:
    print(111)
elif n <= 222:
    print(222)
elif n <= 333:
    print(333)
elif n <= 444:
    print(444)
elif n <= 555:
    print(555)
elif n <= 666:
    print(666)
elif n <= 777:
    print(777)
elif n <= 888:
    print(888)
elif n <= 999:
    print(999)

Measured memory_bytes: 9140
N, X, Y = map(int,input().split())
s = Y - X - 1
t = (X+Y)/2
ans = [0] * (N)
for i in range(1,N+1):
    for j in range(i+1,N+1):
        if i >= Y:
            ans[j-i] += 1
        if i <= X:
            if j <= X:
                ans[j-i] += 1
            elif X < j and j <= Y:
                if j <= t:
                    ans[j-i] += 1
                else:
                    ans[X - i + 1 + Y - j] += 1
            elif j > Y:
                ans[X - i + 1 + j - Y] += 1
        if X < i and i < Y:
            if j < Y:
                if 2*(j-i) <= Y-X+1:
                    ans[j-i] += 1
                else:
                    ans[Y-X+1-j+i] += 1
            elif j >= Y:
                if Y - i <= i - X + 1:
                    ans[j-i] += 1
                else:
                    ans[i - X + 1 + j - Y] += 1

for i in range(N-1):
    print(ans[i+1])

Measured memory_bytes: 3444
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

#define MOD 1000000007

int main(void){
    int i, n;
    scanf("%d", &n);

    unsigned long long ans = 1;
    for (i = 1; i <= n;i++){
        ans = ans * i % MOD;
    }
    printf("%llu\n", ans);

    return 0;
}


Measured memory_bytes: 128
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8,i8[:],i8[:])", cache=True)
def binary_search(K, A, F):
    ng = -1
    ok = 10 ** 18
    while ok - ng > 1:
        mid = (ok + ng) // 2
        need_k = 0
        for a, f in zip(A, F):
            need_k += max(0, a - mid // f)
        if need_k <= K:
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
    F = np.array(input().split(), dtype=np.int64)

    A = np.sort(A)
    F = np.sort(F)[::-1]

    ans = binary_search(K, A, F)
    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
    ll n,l,p,a[100000];
    cin >> n >> l;
    string pos="Impossible";
    for(int i = 0;i < n;i ++){
        cin >> a[i];
        if(i&&a[i]+a[i-1]>=l){
            pos = "Possible";
            p = i;
            break;
        }
    }
    cout << pos << endl;
    if(pos=="Possible"){
        for(int i = 1;i < p;i ++){
            cout << i << endl;
        }
        for (int i = n-1;i >= p;i --){
            cout << i << endl;
        }
    }
    return 0;
}

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if ((n - i) / i <= i) break;
		if ((n - i) % i == 0) ans += (n - i) / i;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define HAIRETU(N,A) for(int i=0;i<N;i++) cin >>A[i]
using namespace std;

int main(){
    int N, X, A,sum=0, domin = 100000;
    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        cin >> A;
        sum += A;
        domin = min(domin, A);
    }
    
    cout << N + (X - sum) / domin << endl;
    return 0;
}


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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
/*----------------------------------------------------------------------*/

ll _sieve_size;
bitset<1000010> bs;
vll primes;

map<ll,int> primeFactors(ll N) {
	map<ll,int> factors;
	ll PF_idx = 0, PF = primes[PF_idx];
	while (PF * PF <= N) {
		
		int cnt = 0;
		while (N % PF == 0) { N /= PF; cnt++; }
			
		if(cnt) {
			factors[PF] = cnt;
		}
		PF = primes[++PF_idx];
		
	}
	if (N != 1) factors[N] = 1;

	return factors;
}

void sieve(ll upperbound) {
	
	_sieve_size = upperbound + 1;
	
	bs.set();
	bs[0] = bs[1] = 0;
	
	for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
		
		for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
		primes.push_back((int)i);
		
	} 
}

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll a, b; cin>>a>>b;
    sieve(1e6+1);
    map<ll,int> pa,pb;
    pa = primeFactors(a); pb = primeFactors(b);
    ll res = 1;

    for(auto itr : pa) {
    	if(pb.find(itr.ff) != pb.end()) {
    		res++;
    	}
    }
    cout<<res;

    return 0;
}

Measured memory_bytes: 1528