akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
//#define INFINITY HUGE_VALF                                                    
//#define HUGE_VALF __builtin_huge_valf()                                       
//#define INFTY 2000000000
#define N 500000
int count,L[N/2+2],R[N/2+2];
//float inf = INFINITY;                                                         
void merge(int * ,int ,int ,int );
void mergeSort(int * ,int ,int );

int main(){
  int n,A[N],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i != n-1)printf(" ");
  }
  printf("\n%d\n",count);

  return 0;
}
void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  for(i=0;i<n1;i++){
    L[i] = A[left + i];
  }
  for(i=0;i<n2;i++){
    R[i] = A[mid + i];
  }
  L[n1] = R[n2] =  2000000000 ;
  //inf;                                                                        
  i = j = 0;
  for(k=left;k<right;k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else {
      A[k] = R[j];
      j++;
    }
  }
}
void mergeSort(int A[],int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A,left,mid);  
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 5644
from collections import defaultdict
def collatz(a):
    if a % 2 == 0:
        return a//2
    return 3*a+1

s = int( input())
d = defaultdict( int)
d[s] = 1
for i in range(2, 1000000):
    s = collatz(s)
    if d[s] == 0:
        d[s] = 1
    else:
        ans = i
        break
print( ans)


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
int INF = numeric_limits<int>::max() / 2;
using ll = long long;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    vector<bool> dp1(3050,false), dp2(3050,false);
    dp1[0] = true;
	dp2[0] = true;
	for(int i = a; i <= f; i++) dp1[i] = dp1[i] || dp1[i - a];
	for(int i = b; i <= f; i++) dp1[i] = dp1[i] || dp1[i - b];
	for(int i = c; i <= f; i++) dp2[i] = dp2[i] || dp2[i - c];
	for(int i = d; i <= f; i++) dp2[i] = dp2[i] || dp2[i - d];
	
	ll a1 = 1;
    ll a2 = 0;
	for(int i = 1; i * 100 <= f; i++){
		for(int j = 0; i * 100 + j <= f; j++){
			if(j > i*e) continue;
			if(!dp1[i] || !dp2[j]) continue;
			ll v1 = i * 100 + j;
            ll v2 = j;
			if(a2*v1 <= a1*v2){
				a1 = v1;
				a2 = v2;
			}
		}
	}
    cout << a1 << " " << a2 << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m : usize,
    }

    let mut sw: Vec<Vec<usize>> = vec![];
    for _ in 0..m {
        input! {
            k : usize,
            tmp : [usize;k],
        }
        sw.push(tmp);
    }
    input! {
        p : [usize;m],
    }

    let mut ans = 0;

    for i in 0..(1 << n) {
        let mut cnt = 0;
        for j in 0..m {
            let mut sw_cnt = 0;
            for e in &sw[j] {
                let tmp = e - 1;
                if (i >> tmp) & 1 == 1 {
                    sw_cnt += 1;
                }
            }
            if sw_cnt % 2 == p[j] {
                cnt += 1;
            }
        }

        if cnt == m {
            ans += 1;
        }
    }

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


Measured memory_bytes: 2164
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    char c; cin >> c;
    for (char d = 'a'; d <= 'z'; d++) {
        if (d==c) {
            cout << 'a' << ln;
            return 0;
        }
    }
    cout << 'A' << ln;
}

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

int main()
{
    int n, r, t,c1,c2;

    scanf("%d %d", &n, &r);

    c1=((n>=1)&&(n<=100));
    c2=((r>=0)&&(r<=4111));

    if(c1 && c2){
        if(n>=10){
            printf("%d",r);
        }else{
            t=r+(100*(10-n));
            printf("%d",t);

        }
    }

    return 0;
}


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	string s ;
	cin >> s ;
	int q ;
	cin >> q ;
	string s1 = "" ;//前
	int rev = 0 ;
	rep(i,q){
		int t ;
		cin >> t ;
		if(t==1){
			swap(s1,s);
		} else {
			int f ;
			cin >> f ;
			char c ;
			cin >> c ;
			if( f == 1){
				s1.push_back(c);
			} else {
				s.push_back(c);
			}
		}
	}
	rSORT(s1);
	cout << s1 << s << endl;
}



Measured memory_bytes: 960
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=200023};

char s[N];

int main(){
	scanf("%s\n",s+1);
	int n = strlen(s+1);
	rep(i,1,n) if( s[i]=='?' ) s[i] = 'D';
	puts(s+1);
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef vector<int> VI;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;

int main() {

	int a, b, c;
	cin >> a >> b >> c;
	if (c < a)cout << 0 << endl;
	else {
		cout << (c / a) * b << endl;
	}

	return 0;
}


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

using namespace std;

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

const double EPS = 0.0000000001;
const long long int INF = 1000000000;

const int MAX_N = 200000, MAX_K = 100000, MAX_L = 100000;

int N;
int K, L;
vector<int> edge1[MAX_N], edge2[MAX_N];

int lab1[MAX_N];
int lab2[MAX_N];

map<int, int> tmp;
vector<int> vs;

void dfs1(int v, int label)
{
	lab1[v] = label;
	for (int u : edge1[v]) {
		if (lab1[u] == -1) {
			dfs1(u, label);
		}
	}
	return;
}

void dfs2(int v)
{
	lab2[v] = 0;
	auto ite = tmp.find(lab1[v]);
	if (ite != tmp.end()) {
		ite->second = ite->second + 1;
	} else {
		tmp.insert(make_pair(lab1[v], 1));
	}
	vs.push_back(v);

	for (int u : edge2[v]) {
		if (lab2[u] == -1) {
			dfs2(u);
		}
	}
	return;
}

void solve()
{
	memset(lab1, -1, sizeof(lab1));
	memset(lab2, -1, sizeof(lab2));

	int l = 0;
	for (int i = 0; i < N; ++i) {
		if (lab1[i] == -1) {
			dfs1(i, l++);
		}
	}

	for (int i = 0; i < N; ++i) {
		if (lab2[i] == -1) {
			tmp.clear();
			vs.clear();
			dfs2(i);

			for (int v : vs) {
				lab2[v] = tmp[lab1[v]];
			}
		}
		printf("%d%c", lab2[i], i == N - 1 ? '\n' : ' ');
	}
}

int main()
{
	scanf("%d", &N);
	scanf("%d%d", &K, &L);
	for (int i = 0; i < K; ++i) {
		int p, q;
		scanf("%d%d", &p, &q);
		edge1[p-1].push_back(q-1);
		edge1[q-1].push_back(p-1);
	}
	for (int i = 0; i < L; ++i) {
		int p, q;
		scanf("%d%d", &p, &q);
		edge2[p-1].push_back(q-1);
		edge2[q-1].push_back(p-1);
	}
	solve();

	return 0;
}



Measured memory_bytes: 19960
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <bitset>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>
#include <cinttypes>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}
template<class T> T read_val() { throw 1; }
template<> int read_val() { int tmp; scanf("%" PRId32, &tmp); return tmp; }
template<> long long read_val() { long long tmp; scanf("%" PRId64, &tmp); return tmp; }
auto read_int = read_val<int>; auto read_long = read_val<long long>;
template<class T> void scanf_vec(vector<T>& vec) { for (int i = 0; i < vec.size(); i++) vec[i] = read_val<T>(); }

#define MOD 1000000007
#define inf 2000000000
#define FWT_SIZE 2000000
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define sort_all(x) sort(all(x))
#define make_unique(x) (x).erase(unique(all(x)), (x).end())



int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n = read_int(), k = read_int();
//	cin >> n >> k;
	vector<int> p(n);
	scanf_vec(p);
	//cin >> p;
	stack<int> min_p;
	int nearest = n, ans = 0, been_none=0;

	stack<pii> max_a, max_b;

	for (int j = p.size() - 1; j >= 0; j--)
	{
		while (min_p.size() > 0 && p[min_p.top()] >= p[j])
			min_p.pop();

		bool changes = false;
		if (min_p.size() > 0 && p[j] > p[min_p.top()])
		{
			changes = min_p.top() < j + k;
			nearest = min(nearest, min_p.top());
		}
		int curr_max = 0;
		if (max_a.size() > 0) curr_max = max(curr_max, max_a.top().second);
		if (max_b.size() > 0) curr_max = max(curr_max, max_b.top().second);
		if (j + k < n && p[j + k] < curr_max)
			changes = true;

		min_p.push(j);

		if (j + k - 1 < n && nearest < j + k && (j + k == n || changes))
		{
			ans++;
		}

		if (j + k - 1 < n && nearest >= (j + k))
			been_none = 1;

		if (max_a.size() > 0) max_a.push({ p[j], max(p[j],max_a.top().second) });
		else max_a.push({ p[j], p[j] });
		if (max_b.size() == 0)
		{
			int max_v = 0;
			while (max_a.size() > 0)
			{
				max_v = max(max_v, max_a.top().first);
				max_b.push({ max_a.top().first, max_v });
				max_a.pop();
			}
		}
		while (max_a.size() + max_b.size() > (k - 1))
			max_b.pop();

	}
	printf("%d", ans + been_none);
//	cout << ans+been_none;

	return 0;
}

Measured memory_bytes: 2688
# include <iostream>
# include <cstring>
# include <unordered_map>
using namespace std;
# define ll long long

unordered_map<ll, ll> cnt;

int main(){
  cnt[0] = 1;
  int n;
  cin >> n;

  ll ans = 0, cur = 0;
  for(int i=0; i<n; i++){
    ll num; cin >> num;
    cur += num;
    ans += cnt[cur];
    cnt[cur]++;
  }

  cout << ans << endl;
  return 0;
}

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

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

    map<int,int> a;
    a[s]=1;

    int cnt=1;
    while(1){
        cnt++;
        if(s%2==0)
            s=s/2;
        else
            s=3*s+1;

        if(a.count(s))
            break;
        else
            a[s]=1;
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if((a-b<=d && b-c<=d && a-b>=-d && b-c>=-d) || (a-c<=d && a-c>=-d))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vi a(3);
    rep(i,3) cin>>a[i];
    sort(all(a));
    int ans=300;
    do{
        chmin(ans,abs(a[1]-a[0])+abs(a[2]-a[1]));
    }while(next_permutation(all(a)));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/* ***********************************************
Author        :yang12138
Created Time  :2017年06月03日 星期六 20时30分36秒
File Name     :B.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=1e5+10;
const int INF=1e9+10;

int h[N];
int n,a,b;

bool check(int m){
	ll cur=(ll)m*b;
	for(int i=1;i<=n;i++){
		ll t=h[i]-cur;
		if(t>0) m-=(t+a-b-1)/(a-b);

		if(m<0) return 0;
	}
	return 1;
}

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

	for(int i=1;i<=n;i++){
		scanf("%d",h+i);
	}

	int l=1,r=INF;
	while(l<r){
		int m=(l+r)>>1;
		if(check(m)) r=m;
		else l=m+1;
	}
	printf("%d\n",l);
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
   	solve(); 
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(void){
	int a1,a2,a3;
  	cin >> a1 >> a2 >> a3;
  	int max,min;
  	max = a1;
  	min = a1;
  	if(a2 > max) max = a2;
    else min = a2;
  	if(a3 > max) max = a3;
  	if(a3 < min) min = a3;
  	cout << max - min << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)

def main():
    N = int(input())
    node_attr_list = [[int(item) for item in input().split()] for _ in range(N)]

    tree = [[0, -1, 0, False, False] for _ in range(N)] # [node, parent, depth, [*child_node], foot print]
    for node_attr in node_attr_list:
        tree[node_attr[0]][0] = node_attr[0]

        if node_attr[1] != 0:
            tree[node_attr[0]][3] = node_attr[2:]
        else:
            tree[node_attr[0]][3] = False

    def dfs(node, depth, parent, children):
        # print(node, depth, parent, children)
        tree[node][4] = True
        tree[node][1] = parent
        tree[node][2] = depth
        if children:
            for item in children:
                dfs(item, depth+1, node, tree[item][3])
        else:
            return

    def all(iterable):
        for element in iterable:
            if not element[4]:
                return False
        return True

    # print(node_attr_list)

    for i in range(N):
        # print('dfs',i)
        # print(tree)
        for j in range(N):
            tree[j][4] = False
        dfs(i, 0, -1, tree[i][3])
        # print(tree)
        # print(all(tree))
        if all(tree):
            break



    for node in tree:
        print('node {}:'.format(node[0]), end=' ')
        print('parent =', node[1], end=', ')
        print('depth =', node[2], end=', ')
        if node[1] == -1:
            print('root', end=', ')
        elif not node[3]:
            print('leaf', end=', ')
        else:
            print('internal node', end=', ')

        if node[3]:
            print(node[3])
        else:
            print([])

if __name__ == "__main__":
    main()



Measured memory_bytes: 36780
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

template<class T>
T gcd(T a,T b){
	return b ? gcd(b,a % b) : a;
}

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

signed main(){
	int a,b;
	cin >> a >> b;
	cout << lcm(a,b) << endl;
}


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


int main() {
	char x, y;
	cin >> x >> y;
	int X = x;
	int Y = y;
	if (X < Y) {
		cout << '<' << endl;
	}
	else if(X > Y){
		cout << '>' << endl;
	}
	else {
		cout << '=' << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,i,x,sum,l1,l2;
  i = sum = 0;
  cin >> N >> K;
  
  for(i=0;i<N;i++){
    cin >> x;
	l1 = 2*x;
    l2 = 2*(x-K);
    if(l2 < 0) l2 = -l2;
    if(l1 < l2) sum += l1;
    else sum += l2;
  }
  cout << sum << endl;
}



Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s;
LL dpa[100010],dpc[100010],dpq[100010],pw[100010],q,ans=0;

int main()
{
	pw[0]=1;
	repn(i,100005) pw[i]=pw[i-1]*3%MOD;
	cin>>s;
	repn(i,s.size())
	{
		if(s[i-1]=='?') q++;
		dpa[i]=dpa[i-1];
		dpc[i]=dpc[i-1];
		dpq[i]=dpq[i-1];
		if(s[i-1]=='A') dpa[i]++;
		if(s[i-1]=='C') dpc[i]++;
		if(s[i-1]=='?') dpq[i]++;
	}
	rep(i,s.size())
	{
		LL fa=dpa[i]-dpa[0],fq=dpq[i]-dpq[0],bc=dpc[s.size()]-dpc[i+1],bq=dpq[s.size()]-dpq[i+1];
		if(s[i]=='B')
		ans=(ans+fa*bc*pw[q]%MOD+fa*bq*(q==0 ? 0:pw[q-1])%MOD+fq*bc*(q==0 ? 0:pw[q-1])%MOD
		+fq*bq*(q-2<0 ? 0:pw[q-2])%MOD)%MOD;
		if(s[i]=='?')
		ans=(ans+fa*bc*(q==0 ? 0:pw[q-1])%MOD+fa*bq*(q-2<0 ? 0:pw[q-2])%MOD+fq*bc*(q-2<0 ? 0:pw[q-2])%MOD
		+fq*bq*(q-3<0 ? 0:pw[q-3])%MOD)%MOD;
	}
	cout<<ans<<endl;
	rt0;
}

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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) { // 深さ優先全探索

    // 終わり方
  if (A.size() == n + 1) {
    int now = 0;
    rep(i,q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }

    // 最初のステップが次のステップに進む条件
  A.push_back(A.back()); //backは一番最後の要素 一番最後の要素をAに追加する
  while (A.back() <= m) { //一番最後の要素がm以下なら
    dfs(A); //再帰関数
    A.back()++; //一番最後の要素にインクリメント
  }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
import sys
n,k = map(int,input().split())


if k > (n-1)*(n-2)/2:
    print(-1)
    sys.exit()

num = (n-1)*(n-2)/2 - k
print(int(n-1+num))
ansl = []
for i in range(1,n):
    print(str(1)+" "+str(i+1))

for i in range(1,n):
    for j in range(i+1, n):
        if num > 0:
            print(str(i+1)+" "+str(j+1))
            num -= 1



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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans = LLONG_MIN;

    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);

    if (a <= 0 && b >= 0) {
        ans = max(ans, 0LL);
    }

    if (c <= 0 && d >= 0) {
        ans = max(ans, 0LL);
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3620
A,B,K=map(int,input().split())

m=[]
if A>=B:
    for i in range(1,A+1):
        if A%i==0 and B%i==0:
            m.append(i)
    m.reverse()
    print(m[K-1])

else:
    for i in range(1,B+1):
        if A%i==0 and B%i==0:
            m.append(i)
    m.reverse()
    print(m[K-1])

Measured memory_bytes: 3060
# Me
def check(s):
    words = [
            'dream',
            'dreamer',
            'erase',
            'eraser',
            ]

    while len(s) != 0:
        flag = False
        for w in words:
            if s[-len(w):] == w:
                s = s[:-len(w)]
                flag = True
                break
        if not flag:
            return 'NO'
    return 'YES'


print(check(input()))

Measured memory_bytes: 3316
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから
#define in(a) cin>>a
#define out(a) cout<<a<<endl

long long int kaijo(long long int n){
    if(n == 0) return 1;
    return n * kaijo(n-1);
}


vector<bool> is_prime;
void Eratosthenes(long long int n){
    is_prime.resize(n+1,true);
    is_prime[0]=false;
    is_prime[1]=false;
    for(long long int i = 2; i <= n; i++){
        if(is_prime[i]){
            for(long long int j = i*i; j <= n; j++){
                is_prime[j] = false;
            }
        }
    }
}

//素数列挙
vector<long long int> Prime;
void Prime_Enumeration(long long int n){
    Eratosthenes(n);
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            Prime.push_back(i);
        }
    }
}

long long int gcd(long long int a, long long int b){
    if(a<b){
        swap(a,b);
    }
    long long int r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return r;
}

long long int lcm(long long int a, long long int b){
    long long int g = gcd(a,b);
    long long int l = (a * b) / g;

    return l;
}

//aが負の時でも余りを非負にしたいとき
long long  mod(long long a, long long m){
    return (a % m + m) % m;
}

//拡張ユークリッド ap + bq = gcd(a,b)
long long extGCD(long long a, long long b, long long &p, long long &q){
    if(b == 0){ p = 1; q = 0; return a;}
    long long d = extGCD(b, a % b, q, p);
    q -= a /b * p;
    
    return d;
}

//中国剰余定理
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2){
    long long p, q;
    long long d = extGCD(m1, m2, p, q);

    if((b2-b1) % d != 0) return make_pair(0, -1); //解なし

    long long m = m1 * (m2 / d);
    long long tmp = (b2 - b1) / d * p % (m2 / d);
    long long r =mod(b1 + m1 * tmp, m);

    return make_pair(r, m);
}

//mod.mでのa^{-1}
long long modinv(long long a, long long m){
    long long b = m, u = 1, v = 0;
    while(b){
        long long t = a /b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0)u += m;
    return u;

}
const long long MOD = 1000000007;

//key以上のうち最小の要素のindex
int binary_search(long long int *a, long long int n, long long int key){
    long long int right = n, left = -1;
    long long int md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}


int main(){
    long long int n,a[5],m;
    cin>>n;
    rep(i,5) cin>>a[i];

    m=a[0];
    rep(i,5) m=min(m,a[i]);

    long long int ans = 4;
    ans += n/m;
    if(n%m!=0) ans++;
    

    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define li long long
li n,a[200010],b[200010],s;
int main(){
	int i,j = 1987654321;
	scanf("%lld",&n);
	for(i = 1;i <= n;++i) scanf("%lld%lld",a + i,b + i),s += a[i];
	for(i = 1;i <= n;++i){
		if(a[i] > b[i]) j = min(1ll * j,b[i]);
	}
	if(j == 1987654321){
		putchar('0');
		return 0;
	}
	//cout<<j<<endl;
	//if(j == n) s -= a[j];
	//else s -= b[j] + b[j] + 1;
	s -= j;
	cout<<s;
	return 0;
}

Measured memory_bytes: 512
K = int(input())

ans = -1

r = 7 % K
SUM = r
if SUM % K == 0:
    ans = 1
else:
    for i in range(1, K):
        r = (r * 10) % K
        SUM += r
        if SUM % K == 0:
            ans = i + 1
            break
    
print(ans)

Measured memory_bytes: 9076
# include <iostream>
# include <cstdio>

using namespace std;

int main(void)
{
    long long x;
    scanf("%lld",&x);
    long long ans = x/500*1000;
    x%=500;
    ans+= x/5*5;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,k; cin >> n >> k;
  vector<ll> v(n);
  rep(i,n) cin >> v[i];
  int r = min(n,k);

  ll ans = 0;
  rep(i, r+1) {
    rep(j, r+1) {
      if (i+j > r) continue;
      int t = max(0, k-(i+j));
      priority_queue<ll> pq;
      ll sum = 0;
      rep(a,i) {
        ll nv = v[a];
        sum += nv;
        if (nv < 0) pq.push(-nv);
      }
      for (int a=0; a<j;a++) {
        ll nv = v[n-1-a];
        sum += nv;
        if (nv < 0) pq.push(-nv);
      }
      rep(a,t) {
        if (pq.empty()) break;
        ll nv = pq.top(); pq.pop(); 
        sum += nv;
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

list = [a,b,c,d,e]
for i in range(0,len(list)-1):
    for j in range(i+1,len(list)):
        if list[j] - list[i] > k:
            print(':(')
            exit()
print('Yay!')       


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, k;
	cin>>n>>k;
	int a, po;
	fore(i, 0, n)
	{
		cin>>a;
		if(a == 1) po = i;
	}
	int neo = (n - po - 1 -(po % (k-1) > 0? (k-1) - po % (k-1): 0));
	neo = max(neo, 0);
	cout<<po / (k-1) + !!(po % (k-1)) + neo / (k-1) + !!(neo%(k-1))<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    int diff = 'A' - 'a';

    cout << (char)(s1.at(0) + diff) << (char)(s2.at(0) + diff) << (char)(s3.at(0) + diff) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int solve(int a,int b,int c,int v){
  if(a%2||b%2||c%2) return v;
  if(a==b&&b==c) return -1;
  int x,y,z;
  x=(b+c)/2;
  y=(c+a)/2;
  z=(a+b)/2;
  v++;
  return solve(x,y,z,v);
}

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int v=0;
  cout<<solve(a,b,c,v)<<endl;
  
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    string S;
    int result = 0;
    cin >> S ;
    for (int i = 0; i < 3; i++) {
        if (S[i] == 'o') {
            result++;
        }
    }
	cout << 700+100*result << endl;
	return 0;
}

Measured memory_bytes: 256
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define endl "\n"
#define X first
#define Y second
#define pii pair<int,int>
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)

const int maxn=2e6+50;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));}
ll r1 ;
ll r2 ;
ll c1 ;
ll c2 ;
ll fact[maxn] ;
ll inv[maxn] ;
ll ans;
ll combi(ll a,ll b){
    if(a<b)
        return 0;
    ll cp=fact[a];
    cp=(cp*inv[b])%mod;
    cp=(cp*inv[a-b])%mod;
    return cp;
}
int main(){
	migmig;
	cin >> r1 >> c1 >> r2 >> c2 ;
	fact[0] = fact[1] = 1;
    inv[1] = 1;
    inv[0] = 1;
	for(int i = 1 ; i < maxn ; i++){
		fact[i] = (fact[i-1] * i) % mod ;
		inv[i] = poww(fact[i] , mod-2 , mod) % mod ;
	}
	//cout<<combi(3,2);
	//cout 
	for(int i = r1 ; i <= r2 ; i++){
		ll x = combi(i + 1 + c2 , c2) % mod;
		ll y = combi(i + 1 + c1 - 1 , c1 - 1 ) % mod;
		ans = (ans + x - y + mod) % mod;
	}
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 31488
import sys

input=sys.stdin.readline

N,W=map(int,input().rstrip().split())
w=[0]*(N+1)
v=[0]*(N+1)
for i in range(1,N+1,1):
    w[i],v[i]=map(int,input().rstrip().split())

sum=0
dp=[[0 for _ in range(W+1)] for i in range(N+1)]

for i in range(1,N+1,1):
    for sum in range(1,W+1,1):
        if(sum-w[i]>=0):
            dp[i][sum]=max(dp[i][sum],dp[i-1][sum-w[i]]+v[i])
        dp[i][sum]=max(dp[i][sum],dp[i-1][sum])
print(max(dp[N][:]))

Measured memory_bytes: 171656
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		ArrayList<Arm> a = new ArrayList<Arm>();

		for (int i = 0; i < n; i++) {
			String str[] = br.readLine().split(" ");
			int left = Integer.parseInt(str[0]) - Integer.parseInt(str[1]);
			int right = Integer.parseInt(str[0]) + Integer.parseInt(str[1]);
			a.add(new Arm(left, right));
		}

		Collections.sort(a);
		long cur = Long.MIN_VALUE;
		int ans = 0;

		for (int i = 0; i < a.size(); i++) {
			if (cur > a.get(i).left) {
				continue;
			}
			ans++;
			cur = a.get(i).right;
		}

		System.out.println(ans);
	}
}

class Arm implements Comparable<Arm> {
	int left;
	int right;

	public Arm(int left, int right) {
		this.left = left;
		this.right = right;
	}

	@Override
	public int compareTo(Arm a) {
		return this.right - a.right;
	}
}


Measured memory_bytes: 47104
#include <stdio.h>
#include <string>
#include <iostream>

std::string replace_with_str (std::string str, std::string str_from, std::string str_to) {
    std::string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != std::string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(void) {
    std::string s;
		std::cin >> s;
    std::string s2 = replace_with_str(s, ",", " ");

    std::cout << s2 << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int check = 0, ans = 0;
		for(; N > 0; N--) {
			int hi = sc.nextInt();
			if(hi >= check) {
				check = hi;
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)


int32_t main(){
   string s, t;
  cin >> s >> t;
  int n = s.length();
  int count = 0;
  for(int i = 0; i<n; i++){
  	if(s[i]!=t[i]) count++;
  }
  cout << count << "\n";
    return 0;
}


Measured memory_bytes: 3928
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll x, y;
    cin>>x>>y;

    ll ans = 0;
    while(x <= y){
        x *= 2;
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	if(n==1)cout<<"Hello World"s;
	else{
		int a,b; cin>>a>>b;
		cout<<a+b;
	}
	cout<<"\n"s;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val input: List<List<Int>> =
            System.`in`.bufferedReader()
                    .readLines()
                    .map { it.split(" ").map { it.toInt() } }
                    .drop(1)
    val n = input.size
//    val d = input[0].size

    val maxCase = 40 * 40 * 10
    val set = mutableSetOf<Int>()
    var c = 0
    var v = 0
    while (v <= maxCase) {
        set.add(v)
        c++
        v = c * c
    }

    var count = 0
    for (i in 0 until n) {
        for (j in i+1 until n) {
            val di = ccc(input[i], input[j])
            if (set.contains(di)) {
                count++
            }
        }
    }
    print(count)
}

fun ccc(al: List<Int>, bl: List<Int>): Int {
    var sum = 0
    for (i in 0 until al.size) {
        val a = al[i]
        val b = bl[i]
        sum += (a - b) * (a - b)
    }
    return sum
}


Measured memory_bytes: 35876
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std;


int sumdigit(int x){
   int sum = 0;
    while(x != 0){
        sum += x % 10;
        x /= 10;
    }
    return sum;
}
int main(){
   int N;
   cin >> N;
   long long temp1 = 2ll;
   long long temp2 = 1ll;
   long long temp3;
   long long temp4;
   if(N == 0){
       cout << temp1 << endl;

   }
   else if (N==1){
       cout << temp2 << endl;
   }
   else{
   for(int i= 0; i < N - 1; i++){
       temp3 = temp1 + temp2;
       temp4 = temp2;
       temp1 = temp4;
       temp2 = temp3;

   }
cout << temp3 << endl;
   }
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    static Scanner sc = new Scanner();

    internal static void Main(string[] args) {
        var H = sc.nextInt();
        var W = sc.nextInt();
        var lst = new List<char[]>();
        for (int i = 0; i < H; i++) {
            var a = ReadLine().ToCharArray();
            if (!a.Any(c => c != '.')) { continue; }

            lst.Add(a);
        }

        for (int i = 0; i < W; i++) {
            var b = true;
            for (int j = 0; j < lst.Count; j++) {
                if (lst[j][i] != '.') {
                    b = false;
                }
            }
            if (b) {
                for (int j = 0; j < lst.Count; j++) {
                    lst[j][i] = 'a';
                }
            }
        }

        foreach (var s in lst) {
            WriteLine(string.Join("", s).Replace("a", ""));

        }
    }
}




class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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

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

  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int total=0;
  int ans=0;

  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        total = i*500+j*100+k*50;
        if(total==x){
          ans++;
          //cout<<i<<','<<j<<','<<k<<','<<total<<endl;
        }
      }
    }
  }

  cout<<ans<<endl;

}


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

using namespace std;

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

  long T = abs(B - A);

  if (T % 2 == 0) {
    long K = T /2;
    cout << max(A,B) - K << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;

static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int curMax = 0;
        int res = 0;
        foreach (var item in h)
        {
            if (curMax <= item) res++;
            curMax = Max(item, curMax);
        }
        Console.WriteLine(res);
    }
}



Measured memory_bytes: 13268
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
int const MAXN=200100;
#define ll long long int
ll n, q, cnt[MAXN];
vector<int> tree[MAXN];
void calc(int nodo=1, ll add=0, int p = -1){
	cnt[nodo]+=add;
	for(auto x:tree[nodo]){
      if(x == p)continue;
      calc(x,cnt[nodo],nodo);
    }
		
}
int main(){
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		int a, b;
		cin>>a>>b;
		tree[a].push_back(b);
     	tree[b].push_back(a);
	}
	while(q--){
		int node, a;
		cin>>node>>a;
		cnt[node]+=a;
	}
	calc();
	for(int i=1;i<=n;i++)
		cout<<cnt[i]<<" ";
}

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

const ll MOD=1e9+7;
const double EPS=1e-9;
const double PI=acos(-1.0);
//const long double PI=acos(-1.0L);

struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}

    Point operator +(const Point &b) const {return Point(x+b.x,y+b.y);}
    Point operator -(const Point &b) const {return Point(x-b.x,y-b.y);}
    Point operator *(const double b) const {return Point(x*b,y*b);}
    Point operator /(const double b) const {return Point(x/b,y/b);}
};

struct Line{
    Point a,b;
    Line(){}
    Line(Point a,Point b):a(a),b(b){}
};

int sgn(double a) {return (a>EPS)-(a<-EPS);}
int sgn(double a,double b) {return sgn(a-b);}

double dot(const Point &a,const Point &b) {return (a.x*b.x+a.y*b.y);}
double cross(const Point &a,const Point &b) {return (a.x*b.y-a.y*b.x);}
double norm(const Point &p) {return dot(p,p);}
double abs(const Point &p) {return sqrt(norm(p));}

Point projection(const Point &p,const Line &l){
    double r=dot(p-l.a,l.b-l.a)/norm(l.b-l.a);
    return l.a+(l.b-l.a)*r;
}

Point reflection(const Point &p,const Line &l){
    return p+(projection(p,l)-p)*2;
}

//1:Counter_Clockwise -1:Clockwise
//2:a-b-c -2:c-a-b 0:a-c-b
int ccw(const Point &p,const Point &q){
    int s=sgn(cross(p,q));
    if(s!=0) return s;
    if(dot(p,q)<0) return -2;
    if(norm(p)<norm(q)) return 2;
    return 0;
}
int ccw(const Point &a,const Point &b,const Point &c){return ccw(b-a,c-a);}

bool isParallel(const Line &l,const Line &r){
    if(sgn(cross(l.b-l.a,r.b-r.a))==0) return true;
    return false;
}
bool isOrthogonal(const Line &l,const Line &r){
    if(sgn(dot(l.b-l.a,r.b-r.a))==0) return true;
    return false;
}

bool isIntersected(const Line &l,const Line &r){
    if(ccw(l.b-l.a,r.a-l.a)*ccw(l.b-l.a,r.b-l.a)>0) return false;
    if(ccw(r.b-r.a,l.a-r.a)*ccw(r.b-r.a,l.b-r.a)>0) return false;
    return true;
}

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

    for(int q=0;q<Q;q++){
        Point P1,P2;
        cin>>P1.x>>P1.y>>P2.x>>P2.y;
        Point P3,P4;
        cin>>P3.x>>P3.y>>P4.x>>P4.y;

        Line L1(P1,P2);
        Line L2(P3,P4);
        if(isIntersected(L1,L2)) cout<<"1"<<endl;
        else cout<<"0"<<endl;
    }

    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<long long int> VI;
typedef vector<vector<long long int> > VVI;
typedef vector<string> VS;
typedef pair<long long int, long long int> PII;

int main(void) {
    long long int n;
    long long int m;
    cin >> n >> m;
    long long int max;
    if (n >= m) {
        max = n; 
    } else {
        max = m;
    }
    int base = 1e09 + 7;
    VI table(max + 1);
    table[1] = 1;
    for (long long int i= 2; i <= max; i++) {
        table[i] = table[i - 1] * i; 
        if (table[i] >= base) {
            table[i] = table[i] % base;
        }
    }
    if (m - n >= 2 || m - n <= -2) {
        cout << 0 << endl;
        return 0;
    } else if (m != n) {
        cout << ((table[m] % base) * (table[n] % base)) % base << endl;
    } else {
        cout << ((((table[m] % base) * (table[n] % base)) % base) * 2) % base << endl;
    }
    return 0;
}



Measured memory_bytes: 1024
S = input()
T = input()

s_dict = {}
t_dict = {}

s_arr = []
t_arr = []

s_len = 0
t_len = 0
for s in S:
    if s in s_dict:
        s_arr.append(s_dict[s])
    else:
        s_arr.append(s_len)
        s_dict[s] = s_len
        s_len += 1
for t in T:
    if t in t_dict:
        t_arr.append(t_dict[t])
    else:
        t_arr.append(t_len)
        t_dict[t] = t_len
        t_len += 1

if s_arr == t_arr:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 6832