akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    ll n,ans=0;cin>>n;
    vector<ll> a(n+1),b(n);
    rep(i,n+1)cin>>a.at(i);
    rep(i,n)cin>>b.at(i);


    for(int i=n-1;-1 < i;i--)
    {
        ans+=min(b.at(i),a.at(i+1));
        b.at(i)=max(0ll,b.at(i)-a.at(i+1));

        ans+=min(b.at(i),a.at(i));
        a.at(i)=max(a.at(i)-b.at(i),0ll);
    }

    cout<<ans<<endl;


}


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

const int N = 300010;
const int INF = 1e9;

int w, h, n;
pair<int, int> ps[N];

int ans;

struct Node {
    Node* l = nullptr;
    Node* r = nullptr;
    int ad = 0;
    int mx = 0;
};

Node* build(int sz) {
    Node* v = new Node();
    if (sz > 1) {
        v->l = build(sz / 2);
        v->r = build(sz - sz / 2);
    }
    return v;
}

void add(Node* v, int sz, int a, int b, int d) {
    if (b <= 0 || sz <= a) {
        return;
    }

    if (a <= 0 && sz <= b) {
        v->ad += d;
        v->mx += d;
        return;
    }

    add(v->l, sz / 2, a, b, d);
    add(v->r, sz - sz / 2, a - sz / 2, b - sz / 2, d);
    v->mx = max(v->l->mx, v->r->mx) + v->ad;
}

void trans() {
    for (int i = 0; i < n; i++) {
        swap(ps[i].first, ps[i].second);
    }
    swap(w, h);
}

void solve() {
    sort(ps, ps + n);

    vector<int> l = {0}, r = {0};

    Node* tr = build(n);

    for (int i = 0; i < n; i++) {
        ans = max(ans, tr->mx + ps[i].first);

        int y = ps[i].second;
        if (y <= h / 2) {
            add(tr, n, l.back(), i, -ps[i].second);
            while (l.size() > 1 && y > ps[l.back()].second) {
                add(tr, n, l.end()[-2], l.end()[-1], ps[l.back()].second - y);
                l.pop_back();
            }
            l.push_back(i);
        } else {
            add(tr, n, r.back(), i, ps[i].second - h);
            while (r.size() > 1 && y < ps[r.back()].second) {
                add(tr, n, r.end()[-2], r.end()[-1], y - ps[r.back()].second);
                r.pop_back();
            }
            r.push_back(i);
        }

        add(tr, n, i, i + 1, h - ps[i].first);
    }
}

int main() {
    scanf("%d %d %d", &w, &h, &n);
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        ps[i] = make_pair(x, y);
    }
    ps[n] = make_pair(0, 0);
    ps[n + 1] = make_pair(w, h);
    n += 2;

    solve();
    trans();
    solve();

    ans *= 2;
    printf("%d\n", ans);
}

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

using namespace std;

int n, m, k;
char mat[10][10];

bool row[10], col[10];

bool check_board() {
	int black = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			bool painted_red = row[i] or col[j];
			if(!painted_red) {
				black += mat[i][j] == '#';
			}
		}
	}
	return black == k;
}

int brute_col(int c) {
	bool finished_painting_cols = c == m;
	if(finished_painting_cols) {
		if(check_board()) {
			return 1;
		}
		return 0;
	}
	int ans = 0;
	{ // try to paint the col c
		col[c] = true;
		ans += brute_col(c + 1);
	}
	{ // try to not paint the col c
		col[c] = false;
		ans += brute_col(c + 1);
	}
	return ans;
}

int brute_row(int r) {
	bool finished_painting_rows = r == n;
	if(finished_painting_rows) return brute_col(0);
	int ans = 0;
	{ // try to paint the row r
		row[r] = true;
		ans += brute_row(r + 1);
	}
	{ // try to not paint the row r
		row[r] = false;
		ans += brute_row(r + 1);
	}
	return ans;
}

int main() {
	scanf("%d %d %d", &n, &m, &k);

	for(int i = 0; i < n; i++) {
		scanf("%s", mat[i]);
	}

	printf("%d\n", brute_row(0));
}


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

int main(){
  string S,T;
  cin >> S >> T;
  int ans=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{	int a,b;
	cin >> a;
	cin >>b;

	if(a<b){
	cout<<"a < b"<<endl;
	}
	if(a>b){
	cout<<"a > b"<<endl;
	}
	if(a==b){
	cout<<"a == b"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;

int S[200000];

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

    rep(i, N) cin >> S[i];

    int ma = 0;

    for (int i = 1; i <= N; ++i) {
        if (N % i == 0) {
            for (int j = i; j < N; j += i) {
                for (int k = 0; k < i; ++k) {
                    if (S[k] != S[j + k]) goto nxt;
                }
            }

            chmax(ma, N / i);
            break;
nxt:;
        }
    }

    cout << ma << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int a, b, maxa = 0, point;
  for(int i = 0; i < n; i++){
   cin >> a >> b; 
   if(a > maxa){
     maxa = a;
     point = b;
   }
  }
  
  cout << maxa + point << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
ll change(ll N){
    string S;
    while(N>0){
        S+=N%8+'0';
        N/=8;
    }
    rep(i,0,N){
        if(S[i]>='4') S[i]++;
    }
    return stoll(S);
}
signed main(){
    COMinit();
    ll N,A,B; cin>>N>>A>>B;
    ll P=0,Q=1;
    rep(i,N,2*N){
        ll X=modpow(A,N)*modpow(B,i-N)%MOD*i%MOD,Y=modpow(A+B,i);
        X*=COM(i-1,N-1);
        X%=MOD;
        P=P*Y%MOD+Q*X%MOD;
        P%=MOD;
        Q=Q*Y%MOD;
        X=modpow(A,i-N)*modpow(B,N)%MOD*i%MOD;
        X*=COM(i-1,N-1);
        X%=MOD;
        P=P*Y%MOD+Q*X%MOD;
        P%=MOD;
        Q=Q*Y%MOD;
    }
    ll X=100,Y=A+B;
    P=P*X%MOD;
    Q=Q*Y%MOD;
    ll ans=modpow(Q,MOD-2)*P%MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 234624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  string s1,s2;
  cin >> s1 >> s2 ;
  reverse(s2.begin(),s2.end());
  if(s1 == s2) cout << "YES" <<endl;
  else cout << "NO" << endl;
}
  

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

int main(void){
   int n,m;
   cin >> n >> m;
   vector<int> l(n);
   for(int i = 0;i < m;i++){
         int a,b;
         cin >> a >> b;
         a--;b--;
         l[a]++;
         l[b]++;
   }
   for(auto i:l){
         cout << i << endl;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

std::vector<std::pair<char,int>> run_length_encoding(const std::string& s){
    std::vector<std::pair<char,int>> v;
    char c=s[0]; int cnt=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]==c){
            cnt++;
        }else{
            v.push_back(std::make_pair(c,cnt));
            c = s[i]; cnt = 1;
        }
    }
    v.push_back(std::make_pair(c,cnt)); return v;
}

int main(){
    fast_io();

    std::string s; std::cin >> s;
    std::vector<std::pair<char,int>> v = run_length_encoding(s);
    v.push_back(std::make_pair('R',1));

    std::vector<int> r(s.size()*2,0);
    int r_position = v[0].second - 1;
    for(int i=0; i<v.size(); i+=2){
        r[r_position]   = (v[i].second - v[i].second/2) + v[i+1].second/2;
        r[r_position+1] = v[i].second/2 + (v[i+1].second - v[i+1].second/2);

        r_position += v[i+1].second + v[i+2].second;
    }

    for(int i=0; i<s.size(); i++){
        std::cout << r[i] << " ";
    }
    std::cout << "\n";
    return 0;
}


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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A.at(i);
  }
  vector<int> C(N + 1);
  for (int i = 0; i < M; i++) {
    C.at(A.at(i)) = 1;
  }
  int CS0 = 0;
  int CSN = 0;
  for (int i = 0; i < X; i++) {
    CS0 += C.at(i);
  }
  for (int i = X + 1; i <= N; i++) {
    CSN += C.at(i);
  }
  cout << min(CS0, CSN) << endl;
}


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

#define lint long long
#define P pair<int, int>


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

    lint A[L];
    
    for(int i = 0; i < L; ++i){
        cin >> A[i];
    }
    
    lint dp[L + 1][5];
    dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0; dp[0][3] = 0; dp[0][4] = 0;
    
    for(int i = 1; i < L + 1; ++i){
        dp[i][0] = dp[i - 1][0] + A[i - 1];
        if(A[i - 1] > 1){
            dp[i][1] = dp[i - 1][1] + A[i - 1] % 2;
            dp[i][3] = dp[i - 1][3] + A[i - 1]% 2;
        } else {
            dp[i][1] = dp[i - 1][1] + (2 - A[i - 1]);
            dp[i][3] = dp[i - 1][3] + (2 - A[i - 1]);
        }
        dp[i][2] = dp[i - 1][2] + (1 - A[i - 1] % 2);
        dp[i][4] = dp[i - 1][4] + A[i - 1];
        
        dp[i][1] = min(dp[i][0], dp[i][1]);
        dp[i][2] = min(dp[i][1], dp[i][2]);
        dp[i][3] = min(dp[i][2], dp[i][3]);
        dp[i][4] = min(dp[i][3], dp[i][4]);
        
    }
    
    cout << dp[L][4] << endl;
}

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

using namespace std;
typedef long long ll;
int n, k, sum=0;
string s;
bool S[100000];

int main(){
  cin >> n >> k;
  cin >> s;
  for(int i=0; i<n; i++){
    if(i!=n-1 && s[i]==s[i+1]){
      sum++;
    }
    if(s[i]=='L'){
      S[i]=false;
    } else {
      S[i]=true;
    }
  }


    bool fir=S[0];
    bool sec=false;
    for (int i=1; i<n; i++){
      if(k==0)break;
      if(!sec && fir==!S[i]){
        sec=true;
      } else if(sec && fir==S[i]){
        sum+=2;
        k--;
        sec=false;
      }
    }
    if(k>0 && S[n-1]!=fir){
      sum++;
    }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;
ll gcd(ll x, ll y){
  if(y==0)return x;
  else return gcd(y,x%y);
}
int main() {
  int n;
  cin >> n;
  cout << pow(n,3) << endl;
}

Measured memory_bytes: 256
N = int(input())
T,A = list(map(int,input().split()))
H = list(map(int,input().split()))

sa = 100000000000

for j in range(N):
    tmp = T - H[j] *0.006
    if sa > abs(tmp - A):
        sa = abs(tmp - A)
        ans = j + 1

print(ans)


Measured memory_bytes: 3060
#include <iostream> //cin,cout
#include <fstream> //input.txtの入力
#include <vector> //vector
using namespace std;

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;

  int betsu,wake;

  betsu = A*X+B*Y;
  
  if(X>Y){
    wake = min( Y*C*2 + (X-Y)*A, X*C*2 );
  }
  else if(Y>X){
    wake = min( X*C*2 + (Y-X)*B, Y*C*2 );
  }
  else{
    wake = Y*C*2;
  }

  //cout<<betsu<<' '<<wake<<endl;

  cout<<min(betsu,wake)<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>


#define int long long
using namespace std;

typedef pair<int, int> P;

int N, M, A[100010], B[10010];
int ans,drink;

vector<P> v;

signed main()
{
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		v.push_back(P(A[i], B[i]));
	}

	sort(v.begin(), v.end(), [](const P& x, const P& y) {return x.first < y.first; });

	for (int i = 0; i < N; i++) {
		if (v[i].second + drink <= M) {
			ans += v[i].second * v[i].first;
			drink += v[i].second;
		}
		else {
			ans += (M - drink)*v[i].first;
			break;
		}
		//cout << ans << endl;
	}


	cout << ans << endl;

	//system("pause");

	return 0;
}


Measured memory_bytes: 3060
//Tonight's the night and it is going to happen again and again.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
int answer_arr[500005];//taken for outputting right answer for each query.
int block=1000;int ans;int a[500005];int m[500005];
struct test
{
	int l,r,idx;
};
bool comp(test i1,test i2)
{
	if(i1.l/block!=i2.l/block)
	{
		return i1.l/block<i2.l/block;
	}
	return (i1.l/block )% 2?i1.r< i2.r:i1.r>i2.r;
}
void add(int position)
{
  m[a[position]]++;
  if(m[a[position]]==1){ans++;}
}
void remove(int position)
{
  if(m[a[position]]>0)
  	{
  		m[a[position]]--;
  		if(m[a[position]]==0){ans--;}
  	}
  
}
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
  int n,q;cin>>n>>q;
  for(int i=0;i<n;i++)
  {
  	cin>>a[i];
  }  
  int t1;t1=q;vector<test>v;test w;
  for(int i=0;i<q;i++)
   {
   	cin>>w.l>>w.r;w.l--;w.r--;w.idx=i;
   	v.push_back(w);
   }
   sort(v.begin(),v.end(),comp);
   int curl=0,curr=-1; 
   for(int i=0;i<t1;i++)
   {
     int L=v[i].l;int R=v[i].r;int p=v[i].idx;
     while(curl>L){curl--;add(curl);}
     while(curr<R){curr++;add(curr);}
     while(curl<L){remove(curl);curl++;}
     while(curr>R){remove(curr);curr--;}//\|
     answer_arr[p]=ans;
    }
    for(int i=0;i<q;i++)
    {
    	cout<<answer_arr[i]<<"\n";
    }
}


Measured memory_bytes: 15636
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	LL a, b; cin >> a >> b;
	LL g = __gcd(a, b);
	const int MAX = 1e6 + 10;
	int ans = 1;
	for (int i = 2; i < MAX && g > 1; i++) {
		if (g % i == 0) {
			ans++;
			while (g % i == 0) g /= i;
		}
	}
	if (g > 1) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

# import re
# import math
# import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
# import copy
# import heapq
# import decimal
# import statistics
# import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 10
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, n = ns()
    d = [na() for _ in range(n)]

    mat = [INF for _ in range(h + 1)]

    mat[0] = 0
    for i in range(h):
        if mat[i] == INF:
            continue
        for a, b in d:
            if i + a < h + 1:
                mat[i + a] = min(mat[i + a], mat[i] + b)
            else:
                mat[h] = min(mat[h], mat[i] + b)

    print(mat[h])


if __name__ == '__main__':
    main()


Measured memory_bytes: 41708
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    string s;
    cin >> s;

    int ans = 1000;

    for (int i = 0; i < s.length()-2; i++) {
        ans = min(ans, abs(stoi(s.substr(i, 3))-753));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
N = input()
nums = []
for i in range(N):
     nums.append(input())
profit = nums[1] - nums[0]
min = nums[0]
for a in range(1, N):
     if nums[a] - min > profit:
          profit = nums[a] - min

     if nums[a] < min:
               min = nums[a]
print profit

Measured memory_bytes: 18956
#include <stdio.h>
#include <string.h>
int row_used[8] = { 0 }, col_used[8] = { 0 }, row[8];
int conflict(r1, c1, r2, c2)
{
    int r = r2 - r1, c = c2 - c1;
    if (r1 == r2)
        return 1;
    if (c1 == c2)
        return 1;
    r = r > 0 ? r : -r;
    c = c > 0 ? c : -c;
    if (r == c)
        return 1;
    return 0;
}
void queen(int level)
{
    int i, j, invalid;
    if (level == 8)
    {
        for (i = 0; i < 8; ++i)
        {
            for (j = 0; j < 8; ++j)
            {
                if (row[i] != j)
                    printf(".");
                else
                    printf("Q");
            }
            printf("\n");
        }
        return;
    }
    if (row[level] != -1)
        queen(level + 1);
    else
    {
        for (i = 0; i < 8; ++i)
        {
            if (col_used[i])
                continue;
            invalid = 0;
            for (j = 0; !invalid && j < 8; ++j)
            {
                if (row[j] < 0)
                    continue;
                if (conflict(level, i, j, row[j]))
                    invalid = 1;
            }
            if (!invalid)
            {
                row[level] = i;
                col_used[i] = 1;
                queen(level + 1);
                row[level] = -1;
                col_used[i] = 0;
            }
        }
    }
}
int main()
{
    int n, r, c;
    scanf("%d", &n);
    memset(row, -1, sizeof(row));
    while (n--)
    {
        scanf("%d %d", &r, &c);
        row[r] = c;
        row_used[r] = 1;
        col_used[c] = 1;
    }
    queen(0);
}



Measured memory_bytes: 2140
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())

power = 1
for i in range(1, n+1):
    power *= i
    if i % 10 == 0:
        power %= (10 ** 9 + 7)

ret = power % (10 ** 9 + 7)
# 出力
print(ret)


Measured memory_bytes: 2940
#include <stdio.h>
#define SIZE 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 1000000

int G[SIZE][SIZE];
int n;

int prim(int v){
  
  int sum=0,mincost,i,j;
  int color[SIZE],cost[SIZE];

  for(i=0; i<n; i++){
    cost[i] = INF;
    color[i] = WHITE;
  }

  cost[0]=0;
  color[0]=GRAY;

  while(1){
    int ver=-1;
    mincost = INF;

    for(i=0; i<n; i++){
      if(color[i] == GRAY && cost[i] < mincost){
        mincost = cost[i];
        ver = i;
      }
    }

    if(ver == -1) break;

    color[ver] = BLACK;
    
    for(i=0; i<n; i++){
      if(color[i] != BLACK && G[ver][i] < INF){
        color[i] = GRAY;
        if(cost[i] > G[ver][i]) cost[i] = G[ver][i];
      }
    }
    
  }


  for(i=0; i<n; i++){
    sum += cost[i];
  }

  return sum;
  
}

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

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      int cost;
      scanf("%d",&cost);
      if(cost == -1) G[i][j] = INF;
      else G[i][j] = cost;
    } 
  }

  ans = prim(0);

  printf("%d\n",ans);

  return 0;
}
  




Measured memory_bytes: 2112
#include <stdio.h>
int main(void){
    int n,k;
    char buf[128];
    scanf("%d",&n);
    scanf("%d",&k);
    scanf("%s",buf);
    if(k == 1){
        printf("%d",n);
        return 0;
    }
    if(n-k == 0 ){
        printf("%d",1);
        return 0;
    }else if((n-k)%(k-1) == 0){
        printf("%d",((n-k)/(k-1))+1);
    }else{
        printf("%d",((n-k)/(k-1))+2);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++ i) {
        cin >> a[i];
    }
    int64 ans = 0;
    if (x == 0) {
        ans = accumulate(a.begin(), a.end(), 0LL);
    }
    else {
        for (int i = 0; i + 1 < n; ++ i) {
            int rem = a[i] + a[i + 1] - x;
            if (rem > 0) {
                ans += rem;
                a[i + 1] -= min(a[i + 1], rem);
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


int main() {
	int a, b; cin >> a >> b;
	cout << (a < b ? 0 : 10) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
using namespace std;
int main(){
  string s;
  while(cin >> s) {
    for(int i=0;i<s.size();i++) if(s[i]==',') s[i]=' ';
    stringstream ss(s);
    int id;double w,h;
    ss >> id >> w >> h;
    double bmi=w/(h*h);
    if(bmi>=25.0) cout << id << endl;
  }
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define int long long

int N, Q;
int S[202020], T[202020], X[202020], D[202020];

template <typename T, typename E>
struct LazySegmentTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  using P = function<E(E, int)>;
  int n;
  F f;
  G g;
  H h;
  P p;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> laz;

  LazySegmentTree() {}

  LazySegmentTree(int n_, F f, G g, H h, T d1, E d0,
                  vector<T> v = vector<T>(), P p = [](E a, int b) { return a; }) : f(f), g(g), h(h), d1(d1), d0(d0), p(p) {
    init(n_);
    if (n_ == (int)v.size()) build(n_, v);
  }

  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat.clear();
    dat.resize(2 * n - 1, d1);
    laz.clear();
    laz.resize(2 * n - 1, d0);
  }

  void build(int n_, vector<T> v) {
    for (int i = 0; i < n_; i++) dat[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
  }

  inline void eval(int len, int k) {
    if (laz[k] == d0) return;
    if (k * 2 + 1 < n * 2 - 1) {
      laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]);
      laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]);
    }
    dat[k] = g(dat[k], p(laz[k], len));
    laz[k] = d0;
  }

  T update(int a, int b, E x, int k, int l, int r) {
    eval(r - l, k);
    if (r <= a || b <= l) return dat[k];
    if (a <= l && r <= b) {
      laz[k] = h(laz[k], x);
      return g(dat[k], p(laz[k], r - l));
    }
    return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2),
                      update(a, b, x, k * 2 + 2, (l + r) / 2, r));
  }

  T update(int a, int b, E x) {
    return update(a, b, x, 0, 0, n);
  }

  T query(int a, int b, int k, int l, int r) {
    eval(r - l, k);
    if (r <= a || b <= l) return d1;
    if (a <= l && r <= b) return dat[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 f(vl, vr);
  }

  T query(int a, int b) {
    return query(a, b, 0, 0, n);
  }
};

signed main() {
  cin >> N >> Q;
  vector<int> c;
  for (int i = 0; i < N; i++) {
    cin >> S[i] >> T[i] >> X[i];
    c.push_back(S[i] - X[i]);
    c.push_back(T[i] - X[i]);
  }

  for (int i = 0; i < Q; i++) {
    cin >> D[i];
    c.push_back(D[i]);
  }

  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());

  map<int, int> mp;
  for (int i = 0; i < c.size(); i++) {
    mp[c[i]] = i;
  }

  LazySegmentTree<int, int> seg(c.size(),
                                [&](int a, int b) { return min(a, b); },
                                [&](int a, int b) { return min(a, b); },
                                [&](int a, int b) { return min(a, b); },
                                1e18, 1e18);

  for (int i = 0; i < N; i++) {
    int l = mp[S[i] - X[i]];
    int r = mp[T[i] - X[i]];
    seg.update(l, r, X[i]);
  }

  for (int i = 0; i < Q; i++) {
    int x = mp[D[i]];
    int res = seg.query(x, x + 1);

    if (res >= 1e17) {
      cout << -1 << endl;
    } else {
      cout << res << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 84072
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
A1 *= T1
A2 *= T2
B1 *= T1
B2 *= T2
if A1 > B1:
    A1, B1 = B1, A1
    A2, B2 = B2, A2
C = B1 - A1
D = A2 - B2

if C == D:
    print("infinity")
elif C > D:
    print(0)
else:
    q, r = divmod(C, (D - C))
    if r == 0:
        print(2 * q)
    else:
        print(2 * q + 1)

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

int main(){
string a;
cin >> a;
vector<char> b;
int count = 0;
for (char i : a){
if (find(b.begin(),b.end(),i) == b.end()){
count++;
b.push_back(i);
}
}
(count == 2) ? cout << "Yes\n": cout << "No\n";
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int dp[40010];

int main(){
	int n;
	scanf("%d",&n);
	dp[0]=1;
	while(n--){
		int t;
		scanf("%d",&t);
		for(int i=40000;i>=t;i--)dp[i]|=dp[i-t];
	}
	scanf("%d",&n);
	while(n--){
		int t;
		scanf("%d",&t);
		puts(dp[t]?"yes":"no");
	}
}


Measured memory_bytes: 2056
#include<stdio.h>


 int gcd ( int a, int b ){
int c;
while ( a != 0 ) {
 		c = a; a = b%a;  b = c;
}
return b;
 }
int main(){
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d\n",gcd(x,y));
}

Measured memory_bytes: 1824
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include <vector>
#include <unordered_map>

using namespace std;

vector<int> arr;
int n;

void maxHeapify(int i) {
	int l = 2 * i;
	int r = 2 * i + 1;
	int large_idx = i;
	
	if (l <= n && arr[l] > arr[large_idx])
		large_idx = l;
	if (r <= n && arr[r] > arr[large_idx])
		large_idx = r;
	
	if (i != large_idx) {
		swap(arr[i], arr[large_idx]);
		maxHeapify(large_idx);
	}
}


int main()
{
	cin >> n;
	arr.resize(n + 1);
	for (int i = 1; i <= n; ++i)
		cin >> arr[i];
	for (int i = n / 2; i >= 1; --i)
		maxHeapify(i);
	for (int i = 1; i <= n; ++i)
		cout << " " << arr[i];
	cout << endl;

	return 0;
}


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

struct sushi{
  ll score;ll type;
  bool operator<(const sushi& rhs) const
  {
      return score < rhs.score;
  }
};

struct comparator
{
  bool operator()(const sushi &lhs, const sushi &rhs){
    return lhs.score > rhs.score;
  }
};

bool used_t[100005];
ll scores[100005];
int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  ll n,k;
  cin>>n>>k;
  priority_queue<sushi> pq;
  priority_queue<sushi, vector<sushi>, comparator > pq2;
  for(ll i=0;i<n;i++){
    ll t,d;cin>>t>>d;
    pq.push({d,t});
  }
  ll sum = 0;
  ll cnt=0;
  for(ll i=0;i<k;i++){
    auto v = pq.top();pq.pop();
    if(!used_t[v.type]){
      used_t[v.type] = 1;
      cnt++;
    }else{
      pq2.push(v);
    }
    sum += v.score;
  }
  scores[cnt]=sum;

  while(!pq.empty()&&!pq2.empty()){
    // cout<<sum<<endl;
    auto v = pq.top();pq.pop();
    if(used_t[v.type])continue;
    auto v2 = pq2.top();pq2.pop();
    used_t[v.type]=true;
    sum -= v2.score;
    sum += v.score;
    cnt++;
    scores[cnt] = sum;
  }
  ll res=0;
  for(ll i=0;i<=n;i++){
    if(!scores[i])continue;
    // cout<<i<<':'<<scores[i]<<endl;
    res=max(res, scores[i] + i*i);
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 3568
import itertools

h, w, k = map(int, input().split())
S = [input() for s in range(h)]
ans = 0
for rows in itertools.product([0, 1], repeat=h):
    for cols in itertools.product([0, 1], repeat=w):
        tmp = 0
        for idx_row, i in enumerate(rows):
            if i == 1:
                continue
            for idx_col, j in enumerate(cols):
                if j == 1:
                    continue
                if S[idx_row][idx_col] == '#':
                    tmp += 1
        if tmp == k:
            ans += 1
print(ans)


Measured memory_bytes: 9188
use proconio::{input, marker::Usize1};

fn chmax(a: &mut Option<i32>, b: i32) {
    *a = Some(if let Some(v) = *a {
        v.max(b)
    } else {
        b
    });
}

fn rotate(x: &mut usize, y: &mut usize, z: &mut usize) {
    let w = *x;
    *x = *y;
    *y = *z;
    *z = w;
}

fn get_v(m: i32, l: Option<i32>) -> i32 {
    if let Some(l) = l {
        m.max(l + 1)
    } else {
        m
    }
}

struct DP {
    l12: Vec<Vec<Option<i32>>>,
    max: Vec<Option<i32>>,
    n: usize,
}

impl DP {
    fn new(n: usize) -> DP {
        DP {
            l12: vec![vec![None; n]; n],
            max: vec![None; n + 1],
            n: n,
        }
    }
    fn set(&mut self, l1: usize, l2: usize, v: i32) {
        if l2 != self.n {
            chmax(&mut self.l12[l1][l2], v);
            chmax(&mut self.l12[l2][l1], v);
            chmax(&mut self.max[l2], v);
        }
        chmax(&mut self.max[l1], v);
        chmax(&mut self.max[self.n], v);
    }
}

fn main() {
    input! {
        n: usize,
        a: [Usize1; n * 3],
    }

    let mut dp = DP::new(n);
    dp.set(a[0], a[1], 0);
    let mut c = 0; // counter, number of cuts 3 to 5 from the left.
    for i in 1..n {
        let (mut x, mut y, mut z) = (a[i * 3 - 1], a[i * 3], a[i * 3 + 1]);
        if x == y && x == z {
            c += 1;
        } else {
            let m = dp.max[dp.n].unwrap();
            let mut q = vec![];
            for _ in 0..3 {
                for l in 0..n {
                    if let Some(m) = dp.max[l] {
                        let v = if y == z { get_v(m, dp.l12[l][y]) } else { m };
                        q.push((l, x, v));
                    }
                }
                let v = if y == z { get_v(m, dp.max[y]) } else { m };
                q.push((x, n, v));

                let v = get_v(m, dp.l12[z][z]);
                q.push((x, y, v));

                rotate(&mut x, &mut y, &mut z);
            }

            for (x, y, v) in q {
                dp.set(x, y, v);
            }
        }
    }

    let l = a[3 * n - 1];
    let v = get_v(dp.max[dp.n].unwrap(), dp.l12[l][l]);
    println!("{}", v + c);
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(x) __builtin_ctz(x)

template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}

using namespace std;
const int vmax=10010;
const int inf=1<<30;
struct edge{int to,cap,cost,rev;};
vector<edge> graph[vmax];

int h[vmax],dist[vmax];
int pv[vmax],pe[vmax];
typedef tuple<int,int> state;


void add_edge(int from,int to,int cap,int cost){
	graph[from].push_back({to,cap,cost,(int)graph[to].size()});
	graph[to].push_back({from,0,-cost,(int)graph[from].size()-1});
}

int min_cost_flow(int s,int t,int f,int n){
	int res=0;
	fill(h,h+n,0);
	while(f>0){
		priority_queue <state,vector<state>,greater<state> > q;
		fill(dist,dist+n,inf);
		dist[s]=0;
		q.push(state(0,s));
		while(!q.empty()){
			int cost,v;
			tie(cost,v)=q.top();q.pop();
			if(dist[v] < cost) continue;
			rep(i,graph[v].size()){
				edge &e=graph[v][i];
				if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
					dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
					pv[e.to]=v,pe[e.to]=i;
					q.push(state(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==inf) return -1;
		rep(v,n) h[v]+=dist[v];

		int d=f;
		for(int v=t;v!=s;v=pv[v]) d=min(d,graph[pv[v]][pe[v]].cap);
		f-=d;res+=d*h[t];
		for(int v=t;v!=s;v=pv[v]){
			edge &e=graph[pv[v]][pe[v]];
			e.cap-=d;
			graph[v][e.rev].cap+=d;
		}
	}
	return res;
}

int a[1010],b[1010];
vector<int> num;

int main(void){
	int n;
	cin >> n;
	rep(i,n) cin >> a[i] >> b[i];
	rep(i,n) num.push_back(a[i]),num.push_back(b[i]);
	uniq(num);

	int s=0,t=n+1+num.size()+1;
	rep(i,n){
		add_edge(s,i+1,1,0); 
		add_edge(i+1,n+1+num.size(),1,0); 
		add_edge(i+1,n+1+getidx(num,a[i]),1,-b[i]); 
		add_edge(i+1,n+1+getidx(num,b[i]),1,-a[i]); 
	}
	rep(i,num.size()) add_edge(n+1+i,t,1,0);
	add_edge(n+1+num.size(),t,inf,0);
	int m=t+1;
	cout << -min_cost_flow(s,t,n,m) << endl;
	return 0;
}

Measured memory_bytes: 3764
#include <stdio.h>
#include <iostream>
#define Re register int

int N,A,maxx,Sum;

template <typename T> inline void read(T &var)
{
	T x=0; int w=0; char ch=0;
	while (!isdigit(ch)) w|=ch=='-',ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	var=w?-x:x;
}
inline int max(int a,int b) {return a>b?a:b;}
int main(int argc, char const *argv[])
{
	//freopen("1.in","r",stdin);
	read(N); for (Re i=1; i<=N; ++i)
		read(A),maxx=max(maxx,A),Sum+=A;
	Sum-=maxx; printf("%s\n",Sum>maxx?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  rep(i,n){
    if(s[i]!=s[n-1-i]){
      cout << "No" << endl; return 0;
    }
  }
  rep(i,n/2){
    if(s[i]!=s[n/2-1-i]){
      cout << "No" << endl; return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 1e5 + 5;

ll k,f[N];

void init(){
	for(int i=1;i<=9;i++){
		f[i]=i;
	}
	ll cnt=9;
	ll sta=1,end=9;
	while(cnt<N){
		int x,y;
		for(ll i=sta;i<=end&&cnt<N;i++){
			if(i==sta) x=cnt+1;
			int u=f[i]%10;
			int v=u-1;
			int w=u+1;
			if(v>=0)  f[++cnt]=f[i]*10+v;
			f[++cnt]=f[i]*10+u;
			if(w<=9)  f[++cnt]=f[i]*10+w;
			if(i==end) y=cnt;
		}
		// cout<<"sta="<<sta<<"  end="<<end<<'\n';
		sta=x,end=y;
	}
	// for(int i=1;i<=k;i++){
		// cout<<"f["<<i<<"]="<<f[i]<<'\n';
	// }
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	cin>>k;
	cout<<f[k]<<'\n';
	return 0;
}

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

using namespace std;

#define ll long long int

int main()
{
  ll a,b;
  cin>>a>>b;
  if(a == b)
  {
    cout<<0<<endl;
    return 0;
  }
  ll k = (a+b)/2;
  if(abs(a-k) == abs(b-k))
  {
    cout<<k<<endl;
    return 0;
  }
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}

          

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define M_PI 3.14159265358979323846 
int main(){
	double a;
	cin >>a;
	printf("%f %f\n",M_PI*a*a,2*M_PI*a);
	return 0;
}

Measured memory_bytes: 1232
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
    int n;
    while(~scanf("%d",&n)){
        int sum=0;
        int k;
        scanf("%d",&k);
        while(n--){
            int x,t;
            scanf("%d",&x);
            t=min(x,k-x);
            sum+=t*2;
        }
        printf("%d\n",sum);
    }
return 0;}


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

using namespace std;

int main(){
  int n,t=0;
  cin>>n;
  vector<int> v(n),c(n);
  for(int i=0;i<n;i++) cin>>v[i];
  for(int i=0;i<n;i++) cin>>c[i];
  for(int i=0;i<n;i++){
    if(v[i]>c[i]) t+=v[i]-c[i];
  }
  cout<<t<<endl;
}


Measured memory_bytes: 256
N = int(input())
mod = int(1e9+7)
A = sorted(list(map(int, input().split())))


N_mod = N%2
if N == 1:
    if A[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()
    
if N_mod == 1 and A[0] == 0:
    A = A[1:]
    num = 2
else:
    num = 1
ans = 1
for i in range(0, N-N_mod, 2):
    if A[i] == A[i+1] and A[i] == num:
        ans = int(ans * 2)
        ans = int(ans % mod)
        num += 2
    else:
        ans = 0
        break
print(ans)


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

int main(){

    int n,k;

    cin >> n >> k;

    int d;

    int a[n];

    int boo[n]={0};

    for (size_t i = 0; i < k; i++)
    {
        cin >> d; 
        for (size_t j = 0;j  < d; j++)
        {
            int tmp;
            cin >>tmp ;
            tmp--;
            boo[tmp]++;
        }
    }
    cout << count(boo,boo+n,0) << endl;

    return 0;
}

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

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, x[101], y[101];
  while(cin >> N, N) {
    for(int i = 0; i < N; i++) cin >> x[i] >> y[i];
    x[N] = x[0], y[N] = y[0];

    int a = -INF, b = INF, c = -INF, d = INF;
    for(int i = 0; i < 4; i++) {
      int u, t;
      cin >> u >> t;
      a = max(a, u), b = min(b, u);
      c = max(c, t), d = min(d, t);
    }
    long long ret1 = 0, ret2 = 0;
    for(int i = 0; i < N; i++) {
      if(y[i] == y[i + 1]) {
        ret2 += 1LL * y[i] * (x[i] - x[i + 1]);
        ret1 += 1LL * max(d, min(c, y[i])) * (max(b, min(a, x[i])) - max(b, min(a, x[i + 1])));
      }
    }
    cout << ret2 - ret1 << endl;
  }
}

Measured memory_bytes: 3080
#include <iostream>
#include<math.h>
#include <algorithm>
#include<string>
using namespace std;

int main() {
        int N;
        char S[110];

        cin >> N ;

        for(int i=0; i<N; i++) cin >> S[i];

        for(int i=0; i<N; i++) {
                if(S[i]=='Y') {
                cout << "Four" << endl;
                return 0;
                }
        }

        cout << "Three" << endl;
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
const int N = 1e4+5;
bool vis[N];
ll a[N];
bool sortinrev(const pair<ll,ll> &a,
               const pair<ll,ll> &b)
{
     return (a.f>b.f);
}
void solve()
{   ll n,m,k,y,x,res=0,l,r,cnt0=0,z,sum1=0,cnt1=0,h,res1,ans=0,sum=0;
    cin>>n;
    vector<ll> v[n+1];
    ll c[n];
    rep(i,0,n-1)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    rep(i,0,n)
    cin>>c[i];
    sort(c,c+n,greater<ll>());
    queue<ll> q;
    l=0;
    q.push(1);
    while(!q.empty()) // It doesn't matter in which order we assign the costs just the depth is important
    {
        x=q.front();
        q.pop();
        if(!vis[x])
        {
            vis[x]=true;
            a[x]=c[l];
            l++;
        }
        for(ll u:v[x])
            if(!vis[u]) q.push(u);
    }
    rep(i,1,n)
    ans+=c[i];
    cout<<ans<<"\n";
    rep(i,1,n+1)
    cout<<a[i]<<" ";

}
int main()
{   speed_up
    ll t;
   //cin>>t;
    t=1;
    while(t--)
        solve();

}


Measured memory_bytes: 1152
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

//14:27
fn main(){
    let n: usize = read_as_vec()[0];
    let mut ans: u64 = 0;
    let mut counter: Vec<u64> = vec![0;5];


    for _ in 0..n{
        let head:char = read_as_string().chars().nth(0).unwrap();
        if head == 'M'{
            counter[0] += 1;
        }else if head == 'A'{
            counter[1] += 1;
        }else if head == 'R'{
            counter[2] += 1;
        }else if head == 'C'{
            counter[3] += 1;
        }else if head == 'H'{
            counter[4] += 1;
        }
    }

    for i in 0..3{
        for j in i+1..4{
            for k in j+1..5{
                ans += counter[i]*counter[j]* counter[k];
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std ;
int n , m ;
struct E{
	int st , ed ;
}p[1000005];
inline bool Cmpr(E a , E b){return a.ed < b.ed ;}
inline bool Cmpl(E a , E b){return a.st < b.st ;}
int Ans ;
int r[1000005] ;
int vis[1000005] ;
int main(){
//	freopen("data.in","r",stdin);
//	freopen("me.out","w",stdout) ;
	cin >> n >> m ;
	for(int i = 1 ; i <= m ; i ++ )
		cin >> p[i].st >> p[i].ed ;
	if(m == 0 ){
		cout << 0 << endl ;
		return 0 ;
	}
	if(m == 1){
		cout << 1 << endl ;
		return 0 ;
	}
	sort(p + 1 , p + m + 1 , Cmpr) ;
	for(int i = 1 ; i <= m ; i ++ ) r[i] = p[i].ed , ++ vis[r[i]];
	int upp = 1 ;
	sort(p + 1 , p + m + 1 , Cmpl) ;
	for(int i = 1 ; i <= m ; i++){
		if(p[i].st >= r[upp]){
			++Ans ;
			while((r[upp] <= p[i].st || vis[r[upp]] == 0 ) && upp < m) upp++ ;
		}
		vis[p[i].ed] -- ; 
	}
	cout << Ans + 1  << endl ;
	return 0 ;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;

vector<int> a(200001, 0);

int main(){
    fastio;
    int n, x;
    cin >> n;
    for(int i = 0; i < n - 1; ++i){
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; ++i){
        cout << a[i] << "\n";
    }
    return 0;
}


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

namespace contest14
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var read_line_origin = Console.ReadLine();
                if (read_line_origin == null)
                {
                    break;
                } 
                
                int input = int.Parse(read_line_origin);

                // y = x^2 の x=600
                //600の約数チェック
                if (600 % input != 0) return;
                if (input == 0) return;

                //横がd で　縦が(600 - d)^2 の面積
                int s = 0;//面積

                int loop = (600 / input);

                for (int i = 0; i < loop; i++)
                {
                    s += input * (i * input) * (i * input);
                }

                Console.WriteLine(s.ToString());
            }
        }
    }
}

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

int main() {
	int a, b;
	while (cin >> a >> b) {
		int n = a + b;
		int c = 1;
		while (n) {
			int x = n / 10;
			n /= 10;
			if (x) {
				c++;
			}
		}

		cout << c << endl;
	}
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  ll H, i, j, tmp, sum = 0, result = 0;
  cin >> H;
  while (H > 1) {
    H /= 2;
    sum++;
  }
  REP(i, sum+1) {
    tmp = 1;
    REP(j, i) {
      tmp *= 2;
    }
    result += tmp;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)

int main() {

    int n;
    cin >> n;
    int w[n];
    int sum = 0;
    rep(i, 0, n) {
        cin >> w[i];
        sum += w[i];
    }
    int  ans = MOD;
    int now = 0;
    rep(i, 0, n-1) {
        now += w[i];
        ans = min(ans, abs(now - (sum - now)));
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
'use strict'

function main(s) {  
  
  const input = s.replace(/\n/g, '').split('');
  let words = [];

  // 文字配列の重複を検出
  input.forEach((x, i, self) => {
    
    // 初出時はオブジェクト追加
    if(self.indexOf(x) === i) {
      words.push({word : x, counter: 1});

    // 2回目以降はカウントするのみ
    } else {
      words.forEach(y => {
        if(x === y.word) {
          y.counter += 1;
        }
      })
    }
  });

  // 全ての文字が偶数回出ているかどうか
  const result = words.every(x => (x.counter % 2) === 0) ? 'Yes' : 'No';
  
  console.log(result);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500