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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

ll f[100005], g[100005];

multiset<pair<ll, int>> rem, unused;
map<int, vector<ll>> entries;
map<int, bool> hold;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	
	int n, k; read(n, k);
	rep(i, 0, n) {
		int t, d; read(t, d);
		unused.insert({d, t});
		entries[t].push_back(d);
	}

	ll val = 0;
	rep(i, 0, k) {
		val += unused.rbegin()->first;
		if (!hold[unused.rbegin()->second]) {
			hold[unused.rbegin()->second] = true;
		} else {
			rem.insert(*unused.rbegin());
		}
		unused.erase(prev(unused.end()));
	}

	rep(i, 0, n + 1)
		f[i] = -0x3f3f3f3f3f3f3f3fll;

	f[hold.size()] = val;

	for (auto t : hold)
		for (auto e : entries[t.first])
			unused.erase({e, t.first});

	for (int i = hold.size() + 1; !unused.empty() && i <= k; i++) {
		val -= rem.begin()->first;
		rem.erase(rem.begin());
		int t = unused.rbegin()->second;
		val += unused.rbegin()->first;
		hold[t] = true;
		for (auto e : entries[t])
			unused.erase({e, t});
		f[i] = val;
	}

	ll ans = -0x3f3f3f3f3f3f3f3fll;

	for (ll i = 0; i <= n; i++)
		chmax(ans, f[i] + i * i);
	write(ans);
}


Measured memory_bytes: 21504
#include<stdio.h>
using namespace std;

int main(){
    while(true){
        int H,W;
        scanf("%d %d",&H,&W);
        if(H ==0&&W==0)break;
        for(int i=0;i<H;i++){
            if(i==0||i==H-1){
                for(int j=0;j<W;j++){
                    printf("#");
                }
                printf("\n");
            }else{
                printf("#");
                for(int j=1;j<W-1;j++){
                    printf(".");
                }printf("#\n");
            }
        }printf("\n");
    }
}


Measured memory_bytes: 2700
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define maxn 200003
#define ll long long
using namespace std;
int a[maxn],cnt[maxn],cur[maxn];
ll sum = 0;
void incr(int pos){
	if(pos <1) return;
	if(cur[pos]){
		cur[pos]++;		
		return;
	}	
	cur[pos]++;
	sum++;
	return;	
}
void decr(int pos){	
	if(pos < 1) return	;
		cur[pos]--;
		if(cur[pos]==0){
			sum--;	
		}
		return;		
}
main(){
	int x,y;
	int N,M;
	cin >> N>>M;
	For(i,1,N){
		scanf("%d",a+i);
		cnt[a[i]] ++;
	}	
	For(i,1,N){
		For(j,max(i-cnt[i]+1,1),i){
			cur[j]++;
		}
	}
	For(i,1,N){
		if(cur[i]>0) sum++;
	}	
//	cout << sum;
	For(i,1,M){
		scanf("%d%d",&x,&y);
		decr(a[x]-cnt[a[x]]+1);
		cnt[a[x]]--;
		incr(y-cnt[y]);
		cnt[y]++;
		a[x]=y;		
		printf("%d\n",N-sum);
	}
}


Measured memory_bytes: 3712
#include<iostream>
#include<string>

using namespace std;

int main() {
string s;
cin >> s;
bool flg = false;
for (char c : s) {
if (c == 'C') {
flg = true;
}
if (flg && c == 'F') {cout << "Yes" << endl; return 0;}
}
cout << "No" << endl;
return 0;
}

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

using namespace std;

using ll = long long;

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

    string s;

    cin >> s;
    if (4 <= s.size() && s.substr(0, 4) == "YAKI")
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
fn main() {
    let _: i64 = read();
    let m: i64 = read();
    let py: Vec<(i64, i64, i64)> = (0..m).map(|i| (i, read(), read())).collect();
    let mut kens: Vec<Vec<(i64, i64, i64)>> = vec![Vec::new(); 100_001];
    for (i, p, y) in py {
        kens[p as usize].push((i, p, y));
    }
    let mut result = vec![];
    for ken in kens.iter_mut() {
        ken.sort_by_key(|k| k.2);
        for (j, &(i, p, _)) in ken.iter().enumerate() {
            result.push((i, format!("{:06}{:06}", p, j + 1)));
        }
    }
    result.sort_by_key(|k| k.0);
    for (_, s) in result {
        println!("{}", s);
    }
}

fn read<T: std::str::FromStr>() -> T {
    use std::io::prelude::*;

    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 25064
#include<stdio.h>
#include<string.h>
char s[110];
int main(){
	scanf("%s",s);
	int len=strlen(s);
	printf("%c%d%c\n",s[0],len-2,s[len-1]);
	return 0;
}



/*A
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",(a-1)*(b-1));
	return 0;
} 

*/

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];

Int N,M,K;
Int B,C,H,W;
Int X,Y,Z;
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}
using D=long double;

Int perform(Int x){
    return (x*(x+1))/2LL;
}

int main()
{
        cin>>N>>K;
        A.resize(N);
        
        for(auto &x:A) cin>>x;
        
        vector<Int> dp(N,1e9);
        
        dp[0]=0; dp[1]=abs(A[1]-A[0]);
        for(int i=2;i<N;++i){
            for(int j=1;j<K+1;++j){
                if(i-j>=0){
                    dp[i]=min(dp[i],dp[i-j]+abs(A[i]-A[i-j]));
                }
            }
        }
        cout<<dp[N-1]<<"\n";
}


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

using ll = long long;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    {
        auto b = a;
        sort(begin(b), end(b));
        b.erase(unique(begin(b), end(b)), end(b));
        if(a == b) {
            cout << 1 << endl;
            return 0;
        }
    }

    auto check = [&] (int k) {
        map<int, int> m;
        for(int i = 1; i < n; ++i) {
            if(a[i - 1] < a[i]) continue;
            if(m.empty()) {
                m[a[i] - 1] += 1;
            } else {
                while(!m.empty() && m.rbegin()->first > a[i] - 1) {
                    m.erase(m.rbegin()->first);
                }
                m[a[i] - 1] += 1;
                int t = a[i] - 1;
                while(t >= 0 && m[t] >= k) {
                    m[t] -= k;
                    m[--t] += 1;
                }
                if(t < 0) return false;
            }
        }
        return true;
    };
    int lb = 1, ub = n + 1;
    while(ub - lb > 1) {
        const auto mid = (ub + lb) >> 1;
        (check(mid) ? ub : lb) = mid;
    }

    cout << ub << endl;
}


Measured memory_bytes: 1920
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    long long h, w;
    cin >> h >> w;
    if (h < w) swap(h, w);
    if (w == 1) {
        cout << 1 << endl;
        return 0;
    }
    long long a = h * w;
    long long ans = (a + 1) / 2;
    cout <<ans << endl;
}

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

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

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

using namespace std;

int main() {
	string s;
	cin >> s;
	string t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			t += '0';
		}
		else if (s[i] == '1') {
			t += '1';
		}
		else {
			t = t.substr(0, t.size() - 1);
		}
	}
	cout <<t<<endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector <double> v(n);
  rep(i, n) cin >> v.at(i);
  sort(v.begin(), v.end());
  double ans = (v.at(0)+v.at(1))/2;
  rep(i, n-2) ans = (ans+v.at(i+2))/2;
  cout << fixed << setprecision(8);
  cout << ans << endl;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	map<string,int>m;
	for(int i=1;i<=n;i++)
	{
	    string s=to_string(i);
	    char f=s[0];
	    char sec=s.back();
	    s.clear();
	    s+=f;
	    s+=sec;
	    m[s]++;
	}
	long long ans=0;
	for(pair<string,int>p:m)
	{
	    string s=p.first;
	    int x=p.second;
	    swap(s[0],s[1]);
	    ans+=(long long)x*m[s];
	}
	cout<<ans<<endl;
	return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for( i = 0; i < n; i++ ){
    scanf("%s", com);
    if(com[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    }
    else if( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");

    }
  }

  return 0;
}



Measured memory_bytes: 25180
#include <iostream>

using namespace std;

int main()
{
    int a,b,c ;
   
    cin>>a>>b>>c;
    if (a>100|| b>100 ||c>100) {
        cout<<"error";
        return 0 ;
    }
    if (a<-100|| b<-100 || c<-100) {
        cout<<"error";
        return 0 ;
    }
    if(a==b) cout<<c;
    if(a==c) cout<<b;
    if(b==c) cout<<a;

    return 0;
}



Measured memory_bytes: 256
N = int(input())
adj = [[0 for j in range(N)] for i in range(N)]
for _ in range(N):
    u, k, *v = input().split()
    for i in v:
        adj[int(u)-1][int(i)-1] = 1

for a in adj:
    print(" ".join(map(str, a)))


Measured memory_bytes: 5680
using DataStructures
function main()
    n,q=myreads(Int)
    a=myreads(Int)
    f=FenwickTree(a)
    for i=1:q
        q1,q2,q3=myreads(Int)
        if q1==0
            inc!(f,q2+1,q3)
        elseif q2<1
            println(prefixsum(f,q3))
        else
            println(prefixsum(f,q3)-prefixsum(f,q2))
        end
    end
end

# ----------input function----------
sread()=chomp(readline())
sreads(sp=" ")=split(readline(),sp)
myread(ty)=parse(ty,sread())
myreads(ty)=parse.(ty,sreads())
main()

Measured memory_bytes: 247224
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,K; cin>>N>>K;
    if(2*K-1<=N)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

vector<int> g[100005];
int n;

vector<int> res;
void dfs(int v, int p = -1, int cnt = 0) {
	res[v] = cnt;
	for (int c : g[v]) {
		if (c == p) continue;
		dfs(c, v, cnt + 1);
	}
}

vector<int> distcalc(int a) {
	res = vector<int>(n);
	dfs(a);
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, h, w;
	cin >> n >> h >> w;
	int ans = 0;
	while (n--) {
		int a, b;
		cin >> a >> b;
		if (a >= h && b >= w) ans++;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n, sum = 0, minr = 101;
  cin >> n;

  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sum += s[i];
    if (s[i] % 10 != 0 && s[i] < minr) minr = s[i];
  }

  if (minr == 101)
    cout << 0 << endl;
  else if (minr < 101 && sum % 10 == 0)
    cout << sum - minr << endl;
  else if (minr < 101 && sum % 10 != 0)
    cout << sum << endl;
}

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

static const int MOD = 1000000007;

typedef vector<vector<long long>> mat;
mat mul(mat &a, mat &b) {
        mat c(a.size(), vector<long long> (b[0].size()));
        for (int i = 0; i < a.size(); i ++) {
                for (int k = 0; k < b.size(); k ++) {
                        for (int j = 0; j < b[0].size(); j ++) {
                                c[i][j] = (((c[i][j] + a[i][k] * b[k][j]) % MOD) + MOD) % MOD;
                        }
                }
        }
        return c;
}
mat pow(mat a, long long k) { //a^k
        mat b(a.size(), vector<long long> (a.size()));
        for (int i = 0; i < a.size(); i ++) {
                b[i][i] = 1;
        }
        while (k > 0) {
                if (k & 1) b = mul(b, a);
                a = mul(a, a);
                k >>= 1;
        }
        return b;
}

void solve2(long long a, long long b, long long c, long long k) {
        mat res(2, vector<long long> (2));
        res[0][0] = a; res[0][1] = -b;
        res[1][0] = 0; res[1][1] = c;
        mat ans = pow(res, k - 1);
        cout << (ans[0][0] + ans[0][1]) % MOD << endl;
        return;
}

void solve() {
        int h, w;
        long long k;
        cin >> h >> w >> k;
        vector<string> s(h);
        for (int y = 0; y < h; y ++) cin >> s[y];
        long long a = 0;
        for (int y = 0; y < h; y ++) for (int x = 0; x < w; x ++) a += s[y][x] == '#';
        int hcnt = 0, wcnt = 0;
        for (int x = 0; x < w; x ++) hcnt += (s[0][x] == '#' && s[h - 1][x] == '#');
        for (int y = 0; y < h; y ++) wcnt += (s[y][0] == '#' && s[y][w - 1] == '#');
        if (hcnt && wcnt) {
                cout << 1 << endl;
                return;
        } else if (!hcnt && !wcnt) {
                solve2(a, 0, 0, k);
        } else if (wcnt) {
                long long c = wcnt;
                long long b = 0;
                for (int y = 0; y < h; y ++) for (int x = 0; x < w - 1; x ++) b += (s[y][x] == '#' && s[y][x + 1] == '#');
                solve2(a, b, c, k);
        } else {
                long long c = hcnt;
                long long b = 0;
                for (int x = 0; x < w; x ++) for (int y = 0; y < h - 1; y ++) b += (s[y][x] == '#' && s[y + 1][x] == '#');
                solve2(a, b, c, k);
        }
        return;
}

int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        //int T;
        //freopen("a.in", "r", stdin);
        //cin >> T;
        //while (T --) solve();
        solve();
        return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

void go(const vector<vector<int> >& g, int cur, vector<ll>& d)
{
    d[cur] = 0;

    for(int to: g[cur]) {
        if(d[to] == -1)
            go(g, to, d);

        d[cur] = max(d[cur], d[to] + 1);
    }
}

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

    vector<vector<int> > g(n);

    for(int i = 0, a, b; i < m; ++i) {
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
    }

    vector<ll> d(n, -1);

    for(int i = 0; i < n; ++i) {
        if(d[i] != -1)
            continue;

        go(g, i, d);
    }

    cout << *max_element(d.begin(), d.end()) << endl;

    return 0;
}


Measured memory_bytes: 9216
n = int(input())

def F(n):
    count = 0
    for i in range(1, n+1):
        if n % i == 0 :
            count += 1
    return count

ans = 0 

for i in range(1, n+1, 2):
    if F(i) == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <iterator>
#include <cctype>
#include <cstdio>
#include <cstring>
#define rep(counter, limit) for (int counter = 0; counter < limit; counter++)
typedef long long ll; using namespace std;const int INF=1001001001;
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
int main() {

  int n;
  cin>>n;
  vector<int> ans(n,0);
  rep(i,n-1){
    int input;
    cin>>input;
    ans[input-1]++;
  }
  rep(i,n){
    cout<<ans[i]<<endl;
  }



}


Measured memory_bytes: 4112
queue=[]
b=[]

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

for w in range(list_s[0]):
    list_1=[int(i) for i in input().split()]
    queue.append(list_1)

for i in range(list_s[1]):
    b.append(int(input()))

for n in range(list_s[0]):
    ans=0
    for q in range(list_s[1]):
        ans=ans+(queue[n][q]*b[q])
        
    print(ans)


Measured memory_bytes: 5976
#include<stdio.h>
int main(){
int i,j,n,s,t,u,g[100][100];
scanf("%d",&n);
for(i=0;i<n;i++){
  for(j=0;j<n;j++){
  g[i][j]=0;
}
}
for(i=0;i<n;i++){
  scanf("%d%d",&s,&t);
  for(j=0;j<t;j++){
    scanf("%d",&u);
    g[s-1][u-1]=1;
  }
}
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=0)printf(" ");
    printf("%d",g[i][j]);
  }
  printf("\n");
}
return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int n,a[100001],x,ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x>n) ans++;
        else a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]==0) 
            continue;
        if(a[i]<i) 
            ans+=a[i];
        else if(a[i]>i) 
            ans+=a[i]-i;
    }
    cout<<ans;
    return 0;
}

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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while(a >= b)
        b += b, k--;
    while(b >= c)
        c += c, k--;
    cout << (k < 0 ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 3548
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
I suck at CP T_T
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;

int t=1,n,m,k;
vi_t a,b;

int main(){
	//scanf("%d",&t);
	while(t--){
		cin>>n;
		a.resize(n);
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		b.resize(n);
		for(int i=0;i<n;i++){
			scanf("%d",&b[i]);
		}
		ll ans=0;
		for(int i=0;i<n;i++){
			if(a[i]-b[i]>0){
				ans+=a[i]-b[i];
			}
		}
		cout<<ans<<endl;
	}
}

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

ll GCD(ll a, ll b){
  if(a < b){ swap (a,b);}  
  if(a % b==0){return b;}
  else{return GCD( a % b,b);}
}

int main() {
  ll a,b; cin>>a>>b;
  ll g= GCD(a,b);
  ll c=1;
  for(ll i=2; i<=pow(g,0.5); i++){
    if(g % i==0){
      while(true){
        if(g % i !=0){ c++; break;}
        g/=i;
      }
    }
  }
  if(g!=1){c++;}
  cout<<c;
}    

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  for(int i=0;i<=1000;i++){
    if((i*8)/100==a&&i/10==b){
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int n, count;
int *S;

inline void merge(int left, int mid, int right) {
//    printf("[merge] left = %d, mid = %d, right = %d\n",
//                    left,      mid,      right);
    int n1 = mid - left, n2 = right - mid;
    int *L = new int[n1 + 1], *R = new int[n2 + 1];
    memcpy(L, S + left, sizeof(int) * n1);
    memcpy(R, S + mid, sizeof(int) * n2);
    L[n1] = R[n2] = 1e9+1;      // sentinel 

    for (int i = 0, j = 0, k = left; k < right; ++k) {
        ++count;
        if (L[i] <= R[j]) {
            S[k] = L[i++];
        }
        else {
            S[k] = R[j++];
        }
    }
    delete[] L;
    delete[] R;
}

inline void merge_sort(int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
//        printf("[merge_sort] left = %d, mid = %d, right = %d\n",
//                             left,      mid,      right);
        merge_sort(left, mid);
        merge_sort(mid, right);
        merge(left, mid, right);
    }
}

int main(void) {

    scanf("%d", &n);

    S = new int[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", S + i);
    }

    merge_sort(0, n);

    printf("%d", S[0]);
    for (int i = 1; i < n; ++i) {
        printf(" %d", S[i]);
    }
    printf("\n%d\n", count);

    delete[] S;

    return 0;
}

Measured memory_bytes: 5080
def has_month_potential(num):
    return num >= 1 and num <= 12

S = input()

formar = int(S[:2])
latter = int(S[2:])

if has_month_potential(formar) and not has_month_potential(latter):
    print('MMYY')
elif not has_month_potential(formar) and has_month_potential(latter):
    print('YYMM')
elif has_month_potential(formar) and has_month_potential(latter):
    print('AMBIGUOUS')
elif not has_month_potential(formar) and not has_month_potential(latter):
    print('NA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sci3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define scs(s) scanf("%s",s)
#ifndef GET_MACRO

#define GET_MACRO(__1,__2,__3,NAME,...) NAME

#endif // GET_MACRO

#define sci(...) GET_MACRO(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__)
#define ll long long
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define LSB(i) ((i)&(-i))
#define read freopen("input.txt","r",stdin)

int bl[1000001];
ll mod=998244353ll;
ll prf_s[200000];
template <class T>T n_inverse_mod_m(T n,T m){
    T rn_1,rn,sn_1,sn,tn_1,tn,tr,ts,tt,q;
    rn_1=n;sn_1=1;tn_1=0;
    rn=m;sn=0;tn=1;
    while(1){
        tr=rn_1%rn;
        q=(rn_1-tr)/rn;
        ts=sn_1-(q*sn);
        tt=tn_1-(q*tn);
        if(tr==0){
            return (sn+m)%m;
        }
        sn_1=sn;sn=ts;
        tn_1=tn;tn=tt;
        rn_1=rn;rn=tr;
    }
}
ll *phi;
void build(ll n){
    phi=new ll[n+1];
    ll *tmp=new ll[n+1];
    memset(tmp,0,sizeof(ll)*(n+1));
    memset(phi,0,sizeof(ll)*(n+1));
    phi[1]=1;
    ll i,j,k,inv,pj;
    for(i=2;i<=n;i++){
        if(tmp[i]==0){
            for(j=i+i;j<=n;j+=i){
                tmp[j]=i;
            }
            inv=n_inverse_mod_m(i,mod);
            phi[i]=(1-i+mod)%mod;
            phi[i]=(phi[i]*inv)%mod;
            j=i*i;
            pj=i;
            while(j<=n){
                phi[j]=(phi[pj]*inv)%mod;
                pj=j;
                j*=i;
            }
        }
    }
    for(i=2;i<=n;i++){
        if(phi[i]==0){
            j=1;
            k=i;
            while((k%tmp[i])==0){
                k/=tmp[i];
                j*=tmp[i];
            }
            phi[i]=(phi[j]*phi[k])%mod;
        }
    }
    delete[] tmp;
    return;
}

ll find_sum(int* num,int sz){//pairwise multiple sum
    prf_s[0]=(ll)num[0];
    int i;
    for(i=1;i<sz;i++){
        prf_s[i]=(prf_s[i-1]+(ll)num[i])%mod;
    }
    ll ans=0;
    for(i=1;i<sz;i++){
        ans=(ans+(prf_s[i-1]*(ll)num[i]))%mod;
    }
    return ans;
}
int main(){
    build(1000000ll);
    int n,ai,i,j,k,l;
    int num[200000];
    sci(n);
    for(i=0;i<n;i++){
        sci(ai);
        num[i]=ai;
        bl[ai]++;
    }
    sort(num,num+n);
    ll ans=0;
    ll t1,t2,t3;
    ans=find_sum(num,n);
    for(i=2;i<1000001;i++){
        l=0;
        for(j=i;j<1000001;j+=i){
            for(k=0;k<bl[j];k++){
                num[l]=j;
                l++;
            }
        }
        t1=find_sum(num,l);
        t1=(t1*phi[i])%mod;
        ans=(ans+t1)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, d;
    vector<vector<int> > x;

    cin >> n >> d;

    x.resize(n);

    for(int i = 0; i < n; ++i)
    {
        x[i] = vector<int>(d);
        for(int j = 0; j < d; ++j)
        {
            cin >> x[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        for(int j = i + 1; j < n; ++j)
        {
            int dist2 = 0;
            for(int k = 0; k < d; ++k)
            {
                dist2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }

            // 40^2 * 10 = 16000
            bool isZ = false;
            for(int k = 0; k <= dist2; ++k)
            {
                if(k * k == dist2) {
                    isZ = true;
                }
            }

            ans += isZ ? 1 : 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl; 


int main(){
    int W,a,b;
    cin >> W >> a >>b;
    int ans=int(1e7);
    if(b>a) ans = max(0, b - (a + W));
    else ans = max(0, a - (b + W));
    print(ans);

}

Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  HashSet<String> hs = new HashSet<String>();
  boolean ok = true;
  String a = sc.next();
  String b = "";
  hs.add(a);
  for(int i = 0;i < n-1;i++){
    b = sc.next();
    if(hs.contains(b)){
      ok = false;
      break;
    }
    char[] ac = a.toCharArray();
    char[] bc = b.toCharArray();
    if(ac[ac.length - 1] != bc[0]){
      ok = false;
      break;
    }
    hs.add(b);
    a = b;
  }
  System.out.println(ok? "Yes":"No");
}}

Measured memory_bytes: 21844
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string S; cin >> S;
  int cnt = 0;
  int vmax = 0;
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G') {
      ++cnt;
    } else {
      cnt = 0;
    }
    vmax = max(vmax, cnt);
  }
  cout << vmax << endl;
}


Measured memory_bytes: 3616
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
long long A[200005] = {};
long long B[500][500] = {};
long long C[205][205] = {};
long long D[200005] = {};
long long E[200005] = {};
bool f, ff;
string S[2];
set <long long>sll;
pl bufpl;
vector <long long>vl[3];
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


bool fs[2005][2005] = {};

int main() {


	cin >> a;

	
	if (a==25) {
		cout << "Christmas" << endl;
	}
	else if(a==24){
		cout << "Christmas Eve" << endl;
	}
	else if (a == 23) {
		cout << "Christmas Eve Eve" << endl;
	}
	else if (a == 22) {
		cout << "Christmas Eve Eve Eve"  << endl;
	}


	return 0;

}


Measured memory_bytes: 2304
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc  = new Scanner(System.in);

    public static void main(String[] args){
        int N = nextInt();

        double[] v = new double[N];
        for(int i=0; i<N; i++){
            v[i] = nextInt();
        }

        Arrays.sort(v);

        for(int i=0; i<N-1; i++){
            v[i+1] = (v[i]+v[i+1])/2.0;
        }

        println(v[N-1]);
    }

    //各桁の和
    public static int sumDigits(long n) {
        int sum = 0;
        while (n != 0) {
            sum += n % 10;
            n /= 10;
        }
        return sum;//合計を返す
    }

    //最大公約数gcd
    static long gcd (long a, long b) {
        long temp;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return b;
    }
    //最小公倍数lcm
    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (c/b);
    }
    static int nextInt(){
        return Integer.parseInt(next());
    }
    static Long nextLong(){
        return Long.parseLong(next());
    }
    static String next(){
        return sc.next();
    }
    static void println(Object o){
        PrintWriter out = new PrintWriter(System.out);
        out.println(o);
        out.flush();
    }
   static void print(Object o){
       PrintWriter out = new PrintWriter(System.out);
       out.print(o);
       out.flush();
    }
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        int c;
        while ((c = System.in.read()) != -1)
            System.out.print(convert((char)c));
    }
    private static char convert(char c) {
        if (Character.isLowerCase(c))
            return Character.toUpperCase(c);
        if (Character.isUpperCase(c))
            return Character.toLowerCase(c);
        return c;
    }
}



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

int main()
{
    int n, m;
    string ans;
    cin >> n >> m;
    rep(i, n) ans += '0';
    rep(i, m)
    {
        int s, c;
        cin >> s >> c;
        if (n > 1 && s - 1 == 0 && c == 0)
        {
            cout << "-1" << endl;
            return 0;
        }

        if (ans[s - 1] == '0')
        {
            ans[s - 1] = '0' + c;
        }
        else if (ans[s - 1] != '0' + c)
        {
            cout << "-1" << endl;
            return 0;
        }
    }
    if (n > 1 && ans[0] == '0')
        ans[0] = '1';

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
n = int(input())
level = [[0]*n for _ in range(n)]
nums = [i for i in range(n)]


cnt = n
l = 0
while cnt >= 1:
    l += 1
    cnt = cnt//2
    gr = [[],[]]
    for i in range(n):
        if nums[i]%2 == 0:
            gr[0].append(i)
        else:
            gr[1].append(i)
        nums[i] = nums[i] >> 1
    for numl in gr[0]:
        for numr in gr[1]:
            if level[numl][numr] == 0:
                level[numl][numr] = l
                level[numr][numl] = l
    #print(l,gr,nums,level)
                    
for i in range(n):
    tmpstr = ""
    for j in range(i+1,n):
        tmpstr += str(level[i][j]) + " "
    print(tmpstr)



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

//const int MOD=998244353;




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	
	string s;
	cin>>s;
	
	for(char c:s){
	    cout<<(c=='?'?'D':c);
	}
	

    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main()
{
   int h,w,ans=0;
   cin >>h>>w;
   vector<vector<char>> a(h,vector<char>(w));
   REP(i,h){
   REP(j,w){
       cin >> a.at(i).at(j);
       if(a.at(i).at(j)=='#')ans++;
   }
   }
   if(ans==h+w-1)
   {
       cout << "Possible";
   }else{
       cout << "Impossible";
   }
}

Measured memory_bytes: 256
#include <stdio.h>
#define N_MAX 50

/* 正方行列の積を求める */
void multiply(int (*d)[N_MAX], int (*s1)[N_MAX], int (*s2)[N_MAX], int size, int mod) {
	int b1[N_MAX][N_MAX], b2[N_MAX][N_MAX];
	int i, j, k;
	/* バッファにコピーする */
	for (i = 0; i < size; i++) {
		for (j = 0; j < size; j++) {
			b1[i][j] = s1[i][j];
			b2[i][j] = s2[i][j];
		}
	}
	/* 計算する */
	for (i = 0; i < size; i++) {
		for (j = 0; j < size; j++) {
			d[i][j] = 0;
			for (k = 0; k < size; k++) d[i][j] += b1[i][k] * b2[k][j];
			d[i][j] %= mod;
		}
	}
}

/* 正方行列の累乗を求める */
int memo[30][N_MAX][N_MAX]; /* 2^i 乗した行列を格納するメモ */
void power(int (*d)[N_MAX], int (*s)[N_MAX], int size, int x, int mod) {
	int i, j;
	/* 初期化 */
	for (i = 0; i < size; i++) {
		for (j = 0; j < size; j++) {
			memo[0][i][j] = s[i][j];
			d[i][j] = (i == j) ? 1 : 0;
		}
	}
	/* x を2の累乗の和に分解して計算する */
	for (i = 0; (1 << i) <= x; i++) {
		/* 2^i 乗した行列を計算する */
		if (i >= 1) multiply(memo[i], memo[i-1], memo[i-1], size, mod);
		/* 求めるべき累乗を計算する */
		if ((1 << i) & x) multiply(d, d, memo[i], size, mod);
	}
}

int main(void) {
	int N, M, A, B, C, T, S[N_MAX];
	int matrix[N_MAX][N_MAX];
	int i, j;

	/* データセット毎の処理 */
	while (scanf("%d%d%d%d%d%d", &N, &M, &A, &B, &C, &T) == 6 && N > 0) {
		/* S(*, 0) を入力 */
		for (i = 0; i < N; i++) scanf("%d", S + i);

		/* 初期化 */
		for (i = 0; i < N; i++) {
			for (j = 0; j < N; j++) {
				if (i - j == 1) matrix[i][j] = A;
				else if (i - j == 0) matrix[i][j] = B;
				else if (i - j == -1) matrix[i][j] = C;
				else matrix[i][j] = 0;
			}
		}

		/* 行列の累乗 */
		power(matrix, matrix, N, T, M);

		/* S(*, T) を求めて出力する */
		for (i = 0; i < N; i++) {
			int s = 0;
			for (j = 0; j < N; j++) s += matrix[i][j] * S[j];
			s %= M;
			/* 出力 */
			if (i != 0) printf(" ");
			printf("%d", s);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 920
#include <stdio.h>
struct student{
    char id[20];
    int k;
    int m;
}p[1010];
int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    if(a >= 1 && a <= 9 && b >= 1 && b <= 9)
        printf("%d", a * b);
    else
        printf("-1");
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	ll N;
	cin >> N;
	vector<int> A(N);
	map<ll, ll> L, R;
	rep(i, 0ll, N) {
		cin >> A[i];
		L[i - A[i]]++;
		R[A[i] + i]++;
	}
	ll ans = 0;
	for (auto m : L) {
		ans += m.second * R[m.first];
	}
	printf("%lld\n", ans);
	return 0;
}


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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    ll a;
    ll r = 0;
    ll g = 0;
    ll b = 0;
    ll ans = 1;
    REP(i, n) {
        cin >> a;
        ll x = 0;
        bool z = false;
        if (r == a) {
            x++;
            if (!z) {
                z = true;
                r++;
            }
        }
        if (g == a) {
            x++;
            if (!z) {
                z = true;
                g++;
            }
        }
        if (b == a) {
            x++;
            if (!z) {
                z = true;
                b++;
            }
        }
        ans *= x;
        ans %= MOD;
    }
    cout << ans << EOL;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

typedef pair<long, long> P;

int N;
P work[300000];
bool ans=true;
long now=0;

int main() {
  cin >> N;

  //締め切り順でそーと
  for (int i=0;i<N;i++){
    cin >> work[i].second;
    cin >> work[i].first;
  }
  sort(work,work+N);

  for (int i=0;i<N;i++) {
    if (now+work[i].second <= work[i].first) {
      now += work[i].second;
    } else {
      ans = false;
      break;
    }
  }


  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;
using VI = vector<int>;
using VPI = vector<pair<int, int>>;

#define FOR(a,n) for(int i=a;i<n;i++)
#define rFOR(a,n) for(int i=n-1;i>=a;i--)
#define IN(n,a) for(int i=0;i<n;i++) cin>>a[i]
#define pIN(n,t) for(int i=0;i<n;i++){int a,b; cin>>a>>b; t.emplace_back(a,b);}
#define SORT(a) sort(a.begin(), a.end())
#define ALL(a) a.begin(), a.end()

int main()
{
	int n,a;
	cin >> n;
	a = n - (n / 2);
	double ans = (double)a / (double)n;
	cout << ans << endl;
}

Measured memory_bytes: 256
from collections import Counter

R = lambda: map(int, input().split())
R()
d = Counter(R())
s = sum(d.elements())
q, = R()
for _ in range(q):
  b, c = R()
  s += (c - b) * d[b]
  print(s)
  d[c]+=d[b]
  del d[b]


Measured memory_bytes: 22180
class Factorization:	
	def __init__(self):
		# privateなインスタンス変数を作成
		self.__factors = dict()
		self.__n = 0
	
	
	def get_factors(self, n):
		# [summary] 素因数分解した結果を、辞書([素因数, 指数]...)で返す
		self.__factors.clear()
		self.__n = n
		
		if n < 2:
			# 2より小さい数の場合、素因数分解できない
			return { n:1 }
		else:
			self.__factorization()
			
			return self.__factors
	
	
	def get_divisors(self, n):
		# [summary] 約数をリスト化して返す
		self.__factors.clear()
		self.__n = n
		
		
	def count_divisors(self, n):
		# [summary] 約数の個数を返す
		self.__factors.clear()
		self.__n = n
		
		if n < 2:
			return 1
		else:
			self.__factorization()
			count = 1
			
			for v in self.__factors.values():
				count *= v + 1
			
			return count
	

	def	__factorization(self):
		# [summary]素因数分解した結果を、インスタンス変数に格納
		
		# 2,3,5で、割れなくなるまで割り続ける
		# (末尾に2,3,5のつく数は素数でないことが明白なので
		# 後続の処理で素数のリストに入れないように、先に処理する)
		self.__divide_with(2)
		self.__divide_with(3)
		self.__divide_with(5)
			
		# 平方根以下の素数で総当たりで試し割りする
		# (実際は、素数らしき数)
		import math
		sqrt_ = math.floor(math.sqrt(self.__n))
			
		primes = [7, 11, 13, 17, 19, 23, 29, 31]
		i = 0
		is_break = False
			
		while self.__n > 1:
			for p in primes:
				if p + i <= sqrt_:
					self.__divide_with(p + i)
				else:
					# 試し割りする数が平方根を超えたら、ループを抜ける
					is_break = True
						
					# 1が素因数に追加されることを防止
					if self.__n > 1:
						self.__factors.setdefault(self.__n, 1)
				
			if is_break:
				break
			else:
				i += 30
	
	
	def __divide_with(self, d):
		count = 0
		
		while self.__n % d == 0:
			self.__n //= d
			count += 1
		
		if count > 0:
			self.__factors.setdefault(d, count)


# C - Factors of Factorial
n = int(input())

if n == 1:
	print(1)
else:
	lib = Factorization()
	factors = dict()

	for i in range(2, n + 1):
		for k, v in lib.get_factors(i).items():
			factors.setdefault(k, 0)
			factors[k] += v
	
	ans = 1
	
	for v in factors.values():
		ans = ans * (v + 1) % (10 ** 9 + 7)

	print(ans)

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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    int A[N], B[N];
    int a = 0;
    int b = 0;

    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            A[i] = 1;
            B[i] = 0;
        }
        else{
            A[i] = 0;
            B[i] = 1;
        }
    }

    for(int i = 0; i < N; i++){
        int s = S[i] - '0';
        a += (s - A[i]) * (s - A[i]);
        b += (s - B[i]) * (s - B[i]);
    }

    cout << min(a, b) << endl;

}

Measured memory_bytes: 1280
#include<iostream>
typedef long long ll;
ll c[55][55]={0};
int main()
{
	int n,p,x,a=0,b=0;
	scanf("%d%d",&n,&p);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x&1) a++;
		else b++;
	}
	c[0][0]=1;
	for(int i=1;i<=n;i++)
	for(int j=0;j<=i;j++)
	if(j==0||j==i) c[i][j]=1;
	else c[i][j]=c[i-1][j-1]+c[i-1][j];
	ll ans=0,s=1;
	if(b)
	for(int i=1;i<=b;i++) s*=2;
	if(p)
	{
		for(int i=1;i<=a;i+=2)
		ans+=s*c[a][i];
	}
	else
	{
		for(int i=0;i<=a;i+=2)
		ans+=s*c[a][i];
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  double ans = 0;
  for (int i=0; i<N; i++){
    int A;
    cin >> A;
    ans += 1.0 / A;
  }
  
  cout << 1 / ans << endl; 
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#define int long long
using namespace std;
signed main(){
    int a,b;
    cin>>a>>b;
    if(a<6)cout<<0<<endl;
    else if(a>12)cout<<b<<endl;
    else cout<<b/2<<endl;
    return 0;
}


















Measured memory_bytes: 256
S[2<<17];char*p=S;b[5<<17];I,q;main(t){for(scanf("%*d%s%*d ",S);*p;)b[++I]=1<<*p++-97;for(;q=~getchar();)if(scanf(q&1?t=0,"%d%d ":"%d %c ",&I,&q),!t){for(int i=I;i<=q;)t|=b[i++];printf("%d\n",__builtin_popcount(t));}else b[I]=1<<q-97;}

Measured memory_bytes: 2688
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[101][101];

int main() {
  ll h,w;
  cin>>h>>w;
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    rep(j,0,a){
      v.pb(i+1);
    }
  }
  ll y = 0;
  ll x = 0;
  ll index = 0;
  rep(i,0,h*w){
    d[y][x] = v[i];
    index++;
    if((i/w)%2==0){
      if(x==w-1){
        y++;
      }
      else{
        x++;
      }
    }
    else{
      if(x==0){
        y++;
      }
      else{
        x--;
      }
    }
  }
  rep(y,0,h){
    rep(x,0,w){
      cout << d[y][x];
      if(x!=w-1)cout << " ";
    }
    cout << endl;
  }
  return 0;
}







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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b)
{
  if (a < b)
  {
    return gcd(b, a);
  }
  while (b != 0)
  {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}


int main() {
  int N;
  cin >> N;
  vector<int> E(N);
  loop(0, N, i) {
    cin >> E[i];
  }

  sort(E.begin(), E.end());
  int ans = 0;
  for (int i=N-1; i>=0; i--) {
    for (int j=i-1; j>=0; j--) {
      auto iter = lower_bound(E.begin(), E.end(), E[i]+E[j]);
      ll ng = distance(iter, E.end());
      ans += (N - 1- i) - ng;
    }
  }
  print(ans);
}

Measured memory_bytes: 3596