akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main() {
	int n;
	int m;
	int x[100000] = {};
	int p;
	char s[3];
//	int p[100000];
//	char s[100000][3];
	int i;

	int w,a;
	
	w = 0;
	a = 0;


	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d %s",&p,s);
		if(x[p] >= 0){
			if(s[0] == 'A'){
				w += x[p];
				x[p] = x[p] * -1 - 1;
				a++;
			}else{
				x[p]++;
			}
		}
	}

	printf("%d %d\n",a,w);



    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
#define debug(x) cerr << #x << " = " << x << "\n";
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int a[3] = {}, k;
    cin >> a[0] >> a[1] >> a[2] >> k;
    sort(a, a + 3);
    a[2] <<= k;
    cout << a[0] + a[1] + a[2];
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a<c && c<b){
        cout << "Yes" << endl;
    }
    else if(b<c && c<a){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

#define llint long long int

using namespace std;

int main(){
    int X;

    cin >> X;

    int ans = (X / 500) * 1000;

    X -= (X / 500) * 500;
    ans += (X / 5) * 5;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int H, N;
  scanf("%d %d",&H,&N);
  int arr[N];
  int i, count=0;
  for(i=0;i<N;i++){
    scanf("%d",&arr[i]);
    count+=arr[i];
  }
  if(count>=H){
    printf("Yes");
  }
  else{printf("No");
  }
  

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int num(int x,int a);
int main()
{
	int x;
	int a,b;
	
	cin>>x>>a>>b;
	
	if(num(x,a)<num(x,b)){
		
		cout<<"A"<<endl;
		
	}else{
		cout<<"B"<<endl;
	}
	
	return 0;
}
int num(int x,int a){
	
	int z=a-x;
	
	if(z<0){
		z=-z;
	}
	
	return z;
	
}



Measured memory_bytes: 256
n,m = map(int,input().split())
A = list(map(int,input().split()))
pop = sum(A) / (m*4)
i = 0
p = A[i]
k = 0
for a in A :
    if a >= pop :
        k += 1
if k >= m :
    print('Yes')
else :
    print('No')   

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
//#define endl '/n'
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

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

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

string myrev(string s){
	string t=s;
	reverse(t.begin(),t.end());
	return t;
}


int main(){
	init();
	ll N;cin>>N;
	set<ll>set;
	for(int i=0;i<N;i++){
		ll a;cin>>a;
		if(set.find(a)==set.end()){
			set.insert(a);
		}else set.erase(a);
	}
	cout<<set.size()<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using ii = pair<i64, i64>;
using vii = vector<ii>;

int main() {
    i64 n, W;
    cin >> n >> W;

    vi vs(n), ws(n);
    for (int i = 0; i < n; i++) {
        cin >> vs[i] >> ws[i];
    }

    vii as, bs;
    for (int i = 0; i < (1 << n / 2); i++) {
        i64 value = 0, weight = 0;
        for (int j = 0; j < n / 2; j++) {
            if ((i >> j) & 1) {
                value += vs[j];
                weight += ws[j];
            }
        }
        as.push_back(ii(value, weight));
    }
    for (int i = 0; i < (1 << (1 + n) / 2); i++) {
        i64 value = 0, weight = 0;
        for (int j = 0; j < (1 + n) / 2; j++) {
            if ((i >> j) & 1) {
                value += vs[n / 2 + j];
                weight += ws[n / 2 + j];
            }
        }
        bs.push_back(ii(value, weight));
    }

    auto comp = [](ii p, ii q) {
        return (p.second == q.second && p.first > q.first) || p.second < q.second;
    };
    sort(as.begin(), as.end(), comp);

    vii cs = {as.front()};
    for (int i = 1; i < as.size(); i++) {
        if (as[i].first > cs.back().first) {
            cs.push_back(as[i]);
        }
    }

    i64 ans = 0;
    for (ii b: bs) {
        i64 value = b.first, weight = b.second;
        i64 rem = W - weight;

        auto it = lower_bound(cs.begin(), cs.end(), ii(-1, rem), comp);
        if (it == cs.begin()) continue;
        i64 V = (*(it - 1)).first + value;
        ans = max(ans, V);
    }
    cout << ans << endl;
}



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

int main()
{
	int n,l;
	vector<string>v;
	string s,ans="";
	scanf("%d %d",&n,&l);
	while(n--)
	{
		cin>>s;
		v.push_back(s);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		ans=ans+v[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;



int main(){
  int a[5];
  rep(i,5)cin >> a[i];
  int k;
  cin >>k;
  if(a[4]-a[0]<=k){cout << "Yay!" << endl;}else{cout << ":(" << endl;}
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








ll gcd(ll a, ll b){
    return b? gcd(b, a % b) : a;
}



int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll t1 = b / c, t2 = b / d;
    ll t3 = (a - 1) / c, t4 = (a - 1) / d;
    ll t = gcd(c, d);
    ll t5 = b / (c * d / t), t6 = (a - 1) / (c * d / t);
    cout << (b - a + 1) - (t1 - t3) - (t2 - t4) + (t5 - t6) << endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;

    LL sum = 0;
    vector<LL> v(N);
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
        sum += v[i];
        sum %= MOD;
    }

    LL res = 0;
    for(int i = 0; i < N; ++i) {
        sum -= v[i];
        sum += MOD;
        sum %= MOD;
        res += sum * v[i];
        res %= MOD;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4776
# -*- coding:utf-8 -*-
# /usr/bin/python3

from collections import Counter

def main():
  n = int(input())
  strings = Counter([''.join(sorted(input().strip())) for _ in range(n)])
  print(int(sum([v * (v-1) / 2 for _, v in strings.items()])))

if __name__=='__main__':
  main()


Measured memory_bytes: 19756
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

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

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int H, W, D;
    cin >> H >> W >> D;

    map<int, P> num2pos;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int a;
            cin >> a;
            a--;
            num2pos[a] = make_pair(i, j);
        }
    }

    vector<int> S(H * W, 0);
    for (int i = 0; i + D < H * W; i++) {
        P from = num2pos[i];
        P to = num2pos[i + D];
        S[i + D] = S[i] + abs(from.first - to.first) + abs(from.second - to.second);
    }

    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
        int L, R;
        cin >> L >> R;
        L--; R--;
        cout << S[R] - S[L] << endl;
    }
}

Measured memory_bytes: 7424
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

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

void solve(){
  int n, x; cin >> n >> x;
  vector<int> v(n);
  vector<int> z(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
    z[i] = abs(x - v[i]);
  }
  int y = z[0];
  for(int i = 1; i < n; i++){
    y = gcd(z[i], y);
  }
  cout << y << endl;
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 1
/*------------------------------------------------------------*/

int main(){
	int n;
	in(n);
//	4/(1*2*4-2*3)
	for(ll i=1;i<=3500;i++)
		for(ll j=i;j<=3500;j++)
			if(i*j*4-n*(i+j)>0&&n*i*j%(i*j*4-n*(i+j))==0){
				ll k=n*i*j/(i*j*4-n*(i+j));
				if(i*j*k*4!=n*(i*j+i*k+j*k))continue;
				outl3(i,j,k);
				return 0;
			}
}
//w*4=N(nw+hw+hn)


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => long.Parse(value)).ToList();
			var a = firstLine[0];
			var b = firstLine[1];
			var x = firstLine[2];

			long total;

			if(a == b)
			{
				if(a % x == 0)
				{
					total = 1;
				}
				else
				{
					total = 0;
				}
			}
			else if (a == 0)
			{
				total = b / x + 1;
			}
			else
			{
				a--;
				total = b / x - a / x;
			}

			Console.WriteLine(total);
		}
	}
}


Measured memory_bytes: 13268
N = int(input())
A = list(map(int,input().split()))
A_even = A[0::2]
A_odd = A[1::2]
tmp = sum(A_even) - sum(A_odd)
x = [tmp]
for i in range(N-1):
    tmp = 2*(A[i]-x[i]//2)
    x.append(tmp)
x_str = " ".join(map(str,x))
print(x_str)

Measured memory_bytes: 19992
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<string>S(H);
  string ans ="Yes";
  for(int i=0;i<H;i++){
    cin>>S.at(i);
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        int f=0;
        if(j<W-1&&S.at(i).at(j)=='#'&&S.at(i).at(j+1)=='#'){
          f=1;
        }
        if(j>0&&S.at(i).at(j)=='#'&&S.at(i).at(j-1)=='#'){
          f=1;
        }
        if(i<H-1&&S.at(i).at(j)=='#'&&S.at(i+1).at(j)=='#'){
          f=1;
        }
        if(i>0&&S.at(i).at(j)=='#'&&S.at(i-1).at(j)=='#'){
          f=1;
        }
        if(S.at(i).at(j)=='.'){
          f=1;
        }
        if(f==0){
        ans = "No";
        cout<<ans<<endl;
        return 0;
        }
      }
    }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;


const int mod=1000000007;
//const int mod=998244353;




int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t,n,m,k,q,x,a,b,c,y,l,r;
    cin >> n;
    ll dp[1<<n];
    memset(dp,0,sizeof(dp));
    ll v[n][n];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
           cin >> v[i][j];
        }
    }
    for(int i=0; i< 1<<n ; i++){
        for(int j=0; j<n; j++){
            if(!(i&(1<<j)))continue;
            for(int k=j+1; k<n; k++){
                if(i&(1<<k))
                    dp[i]+=v[j][k];
            }
        }
    }
    for(int i=1; i<(1<<n); ++i){
        for(int j=i; j>0; j=(j-1)&i){
            dp[i]=max(dp[i],dp[j]+dp[i^j]);
        }
    }
    cout << dp[(1<<n)-1]  << el;
    return 0;
}


Measured memory_bytes: 768
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

def dist_from_X(X:int):
    """ BFSで距離を求める """
    dist = [-1] * N
    que = deque([X])
    dist[X] = 0
    while que:
        v = que.popleft()
        for w in edge[v]:
            if dist[w] < 0:
                dist[w] = dist[v] + 1
                que.append(w)
    return dist

Fennec = dist_from_X(0)
Snuke = dist_from_X(N - 1)

# 距離同じ -> Fennec
cntF, cntS = 0,0
for f,s in zip(Fennec, Snuke):
    if f <= s:
        cntF += 1
    else:
        cntS += 1

# cntが同じ -> Snuke
if cntF > cntS:
    print("Fennec")
else:
    print("Snuke")

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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

using pii=pair<int,int>;

int v[100010];
int h[100010];

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

    priority_queue<pii> q;

    rep(i, N) {
        cin >> h[i];
        q.push(pii(h[i], i));
    }

    while (q.size()) {
        pii p = q.top(); q.pop();

        int idx = p.second;

        if (idx - 1 >= 0 && h[idx] > h[idx - 1]) {
            v[idx - 1] = max(v[idx - 1], L - h[idx] + v[idx]);
        }
        if (idx + 1 < N && h[idx] > h[idx + 1]) {
            v[idx + 1] = max(v[idx + 1], L - h[idx] + v[idx]);
        }
    }

    int ans = 0;

    rep(i, N) {
        ans = max(ans, v[i] + L - h[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4548
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
 
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll ans = 0;
    ll n; cin >> n;
    vector<string> s;
    for (int i = 0; i < n; i++) {
        string temp;
        cin >> temp;
        s.push_back (temp);
    }

    sort(ALL(s));

    ans++;
    for (int i = 0; i < n; i++) {
        if (i == 0) continue;
        if (s[i].compare(s[i-1]) != 0) ans++;
    }

    cout << ans << endl;

} 

Measured memory_bytes: 11624
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		
		int n =sc.nextInt();
		int a[]=new int[n];
		boolean ans=false;
		for (int i=0;i<n;i++) {
			a[i]=sc.nextInt();
			if(a[i]%2==1) {
				ans=true;
			}
		}
		System.out.println(ans?"first":"second");
	}
		
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





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

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}

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

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

    int n;
    cin >> n;

    vector<int> cnt(20, 0);
    int colorful = 0;
    rep(i, n){
        int rate;
        cin >> rate;
        cnt[rate / 400] = 1;
        if(rate / 400 >= 8) colorful ++;
    }

    int sum = accumulate(cnt.begin(), cnt.begin() + 8, 0);
    if(sum == 0){
        cout << (int)(colorful > 0) << " " << colorful << endl;
    }else{
        cout << sum  << " " << sum + colorful << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<cstdlib> 
#include<fstream> 
using namespace std;
int main(){
	int n,k,x[105];
	int ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>x[i]; 
	for(int i=1;i<=n;i++){
		ans+=min(x[i]-0,k-x[i])*2;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

namespace {

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    const int MAX_N = 51;

    int N, M, A, B, C;
    bool G[MAX_N][MAX_N];
    void input() {
        cin >> N >> M >> A >> B >> C;
        memset(G, 0, sizeof(G));
        for (int i = 0; i < M; i++) {
            int u, v;
            cin >> u >> v;
            u--; v--;
            G[u][v] = true;
        }
    }

    const int INF = 1<<28;

    vector<bool> find(int v, int n) {
        vector<bool> xs(N, false);
        xs[v] = true;
        for (int i = 0; i < n; i++) {
            vector<bool> ys(N, false);
            for (int j = 0; j < N; j++) {
                if (not xs[j]) continue;
                for (int k = 0; k < N; k++) {
                    if (G[j][k]) ys[k] = true;
                }
            }
            xs = ys;
        }
        return xs;
    }

    void solve() {
        vector<int> f(N, INF);
        f[N - 1] = 0;
        for (int n = 1; ; n++) {
            vector<int> prev = f;
            for (int i = 0; i < N; i++) {
                vector<bool> a = find(i, A);
                vector<bool> b = find(i, B);
                vector<bool> c = find(i, C);
                bool p = false, q = false, r = false;
                for (int j = 0; j < N; j++) {
                    if (a[j] && prev[j] < n) p = true;
                    if (b[j] && prev[j] < n) q = true;
                    if (c[j] && prev[j] < n) r = true;
                }
                if (p && q && r) {
                    f[i] = min(f[i], n);
                }
            }
            if (prev == f) break;
        }
        if (f[0] == INF) cout << "IMPOSSIBLE" << endl;
        else cout << f[0] << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

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

ll ceil(ll a, ll b) {
    if (b < 0) {
        a *= -1;
        b *= -1;
    }
    if (a >= 0) {
        return (a + b - 1) / b;
    } else {
        return a / b;
    }
}

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> H(N);
    for (ll& h : H) {
        cin >> h;
    }

    ll low = 0, high = 1e10;
    while (high - low > 1) {
        ll x = (high + low) / 2;

        ll cnt = 0;
        for (ll& h : H) {
            if (h - x * B <= 0)
                continue;
            cnt += ceil((h - x * B), A - B);
        }

        if (cnt <= x) {
            high = x;
        } else {
            low = x;
        }
    }
    cout << high << endl;
}


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

int main() {
  int N,K,X=0;
  cin >> N >> K;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    if(a>=K){
      X++;
    }
  }
  cout << X << endl;
}


Measured memory_bytes: 3608
n = int(input())
arr = list(map(int,input().split()))

before = ud = None
cutCnt = 0
i = 0
while i < n:
  if before is None:
    before = arr[i]
    continue
  else:
    if ud is None:
      if before > arr[i]:
        ud = 1
        before = arr[i]
      elif before < arr[i]:
        ud = 2
        before = arr[i]
    elif ud == 1 and before < arr[i]:
      cutCnt+=1
      ud = None
      before = None
      i-=1
    elif ud == 2 and before > arr[i]:
      cutCnt+=1
      ud = None
      before = None
      i-=1
    else:
      before =arr[i]
    i+=1
    
print(cutCnt+1)    

Measured memory_bytes: 62704
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<ll,ll> Pair;

ll N,M,Q;
ll sum = 0,ans = 0;
vector<ll> a(50);
vector<ll> b(50);
vector<ll> c(50);
vector<ll> d(50);
vector<ll> A(11,1);

void rec(ll NN){
    if(N == NN){
        sum = 0;
        for(ll i = 0;i < Q;++i){
            if(A[b[i]-1]-A[a[i]-1] == c[i]){
                sum = sum + d[i];
            }
        }
        if(ans < sum) ans = sum;
    }
    else{
        for(ll i = 1;i <= M;++i){

            A[NN] = i;

            if(A[NN-1] <= A[NN])    rec(NN+1);
            
        }
    }
}

void dfs(vector<ll> A){

    if(N == A.size()){
        sum = 0;
        for(ll i = 0;i < Q;++i){
            if(A[b[i]-1]-A[a[i]-1] == c[i]){
                sum = sum + d[i];
            }
        }
        if(ans < sum) ans = sum;
    }
    else{
        A.push_back(A.back());
        while(A.back() <= M){
            dfs(A);
            A.back()++;
        }

    }

}

int main(){
cin >> N >> M >> Q;
for(ll i = 0;i < Q;++i)    cin >> a[i] >> b[i] >> c[i] >> d[i];
rec(1); 
//dfs(vector<ll>(1,1));
cout << ans << endl;
return 0;
}   


Measured memory_bytes: 3572
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <map>
#define MOD 1000000007
using namespace std;
typedef long long ll;
 
int main(){
 
  ll x;
  cin >> x;
  
  if(x % 11 == 0)		cout << (x/11)*2	 << endl;
  else if(x % 11 <= 6)	cout << (x/11)*2 + 1 << endl;
  else					cout << (x/11)*2 + 2 << endl;
  
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static void line(int32_t n, vector<int32_t> &v) {
  auto &&it = v.cbegin();
  for (int32_t i = 0; i < n; ++i) {
    cout << (i == 0 ? "" : " ");
    if (!v.empty() && it != v.cend() && i + 1 == *it) {
      cout << 1;
      ++it;
    } else {
      cout << 0;
    }
  }
  cout << endl;
}
int main() {
  int32_t n;
  cin >> n;
  for (int32_t i = 0; i < n; ++i) {
    int32_t skip, k;
    cin >> skip >> k;
    vector<int32_t> v(k);
    for (int32_t j = 0; j < k; ++j) {
      cin >> v[j];
    }
    sort(v.begin(), v.end());
    line(n, v);
  }
}



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

string s[100];
int dy[4]={-1,0,0,1};
int dx[4]={0,-1,1,0};

signed main()
{
    int H,W; cin>>H>>W;
    REP(i,H) cin>>s[i];

    REP(i,H) REP(j,W){
        if(s[i][j]=='#'){
            bool ok=false;
            REP(k,4){
                int y=i+dy[k];
                int x=j+dx[k];
                if(0<=y and y<H and 0<=x and x<W and s[y][x]=='#') ok=true;
            }
            if(!ok){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;

}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] array = { sc.nextInt(), sc.nextInt(), sc.nextInt() };
		Arrays.sort(array);
		int K = sc.nextInt();
		System.out.println((int)(array[2] * Math.pow(2, K)) + array[1] + array[0]);
	}
}

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

using namespace std;

using ll = long long;

int main(){
   ll n; cin >> n;
   ll tmp = n, ans = 0;
   while(n > 0){
    ans += n % 10;
    n /= 10;
   }
   if(tmp % ans == 0){
    cout << "Yes";
   }else cout << "No";
   return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=2100;
struct node {
	int h,l;
}st[maxn];
int n,m;
int Ans;
int h[maxn],a[maxn][maxn],val[maxn][maxn];
char s[maxn];

inline void file() {
	freopen("speech.in","r",stdin);
	freopen("speech.out","w",stdout);
}

inline void solve() {
	Set(h,0);
	For (i,1,n) {
		int top=0;
		For (j,1,m) {
			if (val[i][j]==0) h[j]=0;
			else ++h[j];
			if (top && st[top].h>h[j]) {
				while (top && st[top].h>h[j]) {
					chkmax(Ans,(st[top].h+1)*(1+j-st[top].l)); --top;
				}
				st[++top].h=h[j];
			}
			else {
				st[++top].h=h[j]; st[top].l=j;
				if (top>=2 && st[top].h==st[top-1].h) st[top].l=st[top-1].l;
			}
		}
		while (top) {
			chkmax(Ans,(st[top].h+1)*(m+2-st[top].l)); --top;
		}
	}
}

int main() {
//	file();
	scanf("%d%d",&n,&m);
	For (i,1,n) {
		scanf("%s",s+1);
		For (j,1,m) {
			if (s[j]=='.') a[i][j]=0;
			else a[i][j]=1;
		}
	}
	For (i,1,n-1) For (j,1,m-1)
		if ((a[i][j]^a[i][j+1]^a[i+1][j]^a[i+1][j+1])==0) val[i][j]=1;
	Ans=max(n,m); --n; --m;
/*	For (i,1,n) {
		For (j,1,m) cout << val[i][j] << " " ;
		cout << endl;
	}*/
	solve();
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 33920
/*
作成日:2020-03-15
*/

#include <stdio.h>

int main()
{
    int a, b, c;

    scanf( "%d %d %d", &a, &b, &c );

    if( a == 5 && b == 5 && c ==7) 
        printf( "YES\n" );
    else if( a == 5 && b == 7 && c == 5 )
        printf( "YES\n" );
    else if( a == 7 && b == 5 && c == 5 )
        printf( "YES\n" );
    else printf( "NO\n");

    return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] f = new int[n];
		int sz = 0;
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			if (sz == 0) {
				f[sz] = a[0];
				++sz;
			} else {

				int ok = -1;
				int ng = sz;
				while (ng - ok > 1) {
					int middle = (ok + ng) / 2;
					if (f[middle] < a[i]) {
						ok = middle;
					} else {
						ng = middle;
					}
				}

				f[ok + 1] = a[i];
				if (ok + 1 == sz)
					++sz;
			}
		}
		
		System.out.println(sz);

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 71112
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int A[15],n,m,q,a[55],b[55],c[55],d[55],ans;
int main(){
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++)
	    cin>>a[i]>>b[i]>>c[i]>>d[i];
	for(int i=1;i<=n;i++) A[i]=1;
	while(!A[0])
	{
		int res=0;
		for(int i=1;i<=q;i++)
		    if(A[b[i]]-A[a[i]]==c[i]) res+=d[i];
		ans=max(ans,res);
		for(int i=n;i>=0;i--)
		{
			if(A[i]<m)
			{
				A[i]++;
				for(int j=i+1;j<=n;j++) A[j]=A[i];
				break;
			}
		}
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3592
package main

import "fmt"

func main() {
	var N, T int
	fmt.Scan(&N, &T)

	ts := make([]int, N)
	for i := range ts {
		fmt.Scan(&ts[i])
	}

	var sum int
	for i := 0; i < N-1; i++ {
		sum += f(ts[i], ts[i+1], T)
	}
	fmt.Println(sum + T)
}

func f(t1, t2, T int) int {
	// diff := abs(t1, t2)
	diff := t2 - t1
	if diff >= T {
		return T
	}
	return diff
}

Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int>::reverse_iterator rit; for(rit=s.rbegin();rit!=s.rend();rit++)
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+8;
using namespace std;

int t,n,m,cnt=0,ans=1,i=0,j=0;
char s[N]={0},q[N]={0},h[N]={0};
char a;
int main(){
    scanf("%s",s);
    scanf("%d",&m);
    while(m--){
        scanf("%d",&n);
        ans+=n;
        if(ans>=2) ans-=2;
        if(n==1) continue;
        if(ans==1){
            scanf("%d %c",&t,&a);
            if(t==1) q[i++]=a;
            else h[j++]=a;
        }else{
            scanf("%d %c",&t,&a);
            if(t==1) h[j++]=a;
            else q[i++]=a;
        }
    }
    if(ans==0){
        for(int ii=j-1;ii>=0;ii--) printf("%c",h[ii]);
        for(int ii=strlen(s)-1;ii>=0;ii--) printf("%c",s[ii]);
        printf("%s\n",q);
    }else{
        for(int ii=i-1;ii>=0;ii--) printf("%c",q[ii]);
        for(int ii=0;ii<strlen(s);ii++) printf("%c",s[ii]);
        printf("%s\n",h);
    }
    
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
using namespace std;

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

ll dp[201][201][201];

ll gcd3(ll a,ll b,ll c){
    if(dp[a][b][c] != -1) return dp[a][b][c];
    dp[a][b][c] = gcd(gcd(a,b),c);
    return dp[a][b][c];
}

int main(void){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if(n < 3){
        cout<<0<<endl;
        return 0;
    }
    vector<ll> ra(n,0);
    vector<ll> ba(n,0);
    vector<ll> ga(n,0);
    for(ll i=n-2;i>=0;--i){
        ra[i] = ra[i+1];
        ba[i] = ba[i+1];
        ga[i] = ga[i+1];
        if(s[i+1] == 'R') ra[i] += 1;
        if(s[i+1] == 'B') ba[i] += 1;
        if(s[i+1] == 'G') ga[i] += 1;
    }
    ll ans = 0;
    for(ll i=0;i<n-2;i++){
        for(ll j = i+1;j<n-1;j++){
            if(s[i] == s[j]) continue;
            if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')){
                ans += ga[j];
                if(j+j-i < n && s[j+j-i] == 'G') ans--;
            }
            else if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')){
                ans += ba[j];
                if(j+j-i < n && s[j+j-i] == 'B') ans--;
            }
            else if((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')){
                ans += ra[j];
                if(j+j-i < n && s[j+j-i] == 'R') ans--;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#define PIE 3.14159265358979
#define MAX_N 16
#define rep(i,n) for(int i = 0;i < (n);i++)
#define show(x) cout<<(#x)<<":"<<x<<" ";
#define showl(x) cout<<(#x)<<":"<<x<<endl;

using namespace std;
typedef long long ll;

const ll inf = 5e14;

struct segtree{
    int sz;
    vector<ll> node,lazy;
    ll def;

    segtree(int n, ll val){
        sz = 1;
        while(sz<n)sz *= 2;
        node.resize(2*sz-1,val);
        lazy.resize(2*sz-1,0);
        def = -inf;
    }
    
    void debug(){
        cout<<"[node]"<<endl;
        for(int i = 0;i < sz;i++){
            cout<<"["<<i<<"]:"<<getmax(i,i+1)<<" ";
        }
        cout<<endl;
    }
    
    void eval(int k){
        node[k]+=lazy[k];
        if(k<sz-1){
            lazy[2*k+1]+=lazy[k];
            lazy[2*k+2]+=lazy[k];}
        lazy[k]=0;
    }
    
    ll getmax(int x,int y,int l = 0,int r = -1,int k = 0){//[x,y)の最小値を求める

        if(r<0)r=sz;
        eval(k);
        if(r<=x||y<=l)
            return def;
        if(x<=l&&r<=y)
            return node[k];
        else{
            int mid = (l+r)/2;
            return max(getmax(x,y,l,mid,k*2+1),getmax(x,y,mid,r,k*2+2));
        }
    }
    
    void add(int x,int y,ll val,int l=0,int r = -1,int k = 0){
        if(r<0)r=sz;
        eval(k);
        if(r<=x||y<=l){return;}
        if(x<=l&&r<=y){
            lazy[k]+=val;
            eval(k);
        }else{
            int mid = (l+r)/2;
            add(x,y,val,l,mid,k*2+1);
            add(x,y,val,mid,r,k*2+2);
            node[k]=max(node[k*2+1],node[k*2+2]);
        }
    }
};

int main(){
    int N,M;
    vector<int> L,R,a;
    vector<pair<int,int> > add,del;//place,index;
    cin>>N>>M;
    segtree seg(N+1,0);
    L.resize(M),R.resize(M),a.resize(M),add.resize(M),del.resize(M);
    rep(i,M){
        cin>>L[i]>>R[i]>>a[i];
        R[i]++;
        add[i].first = L[i];
        del[i].first = R[i];
        add[i].second = del[i].second = i;
    }
    sort(add.begin(),add.end());
    sort(del.begin(),del.end());
    auto itadd= add.begin(),itdel = del.begin();
    ll ans = 0;
    for(int i = 1;i <= N;i++){
        while(itadd!=add.end()&&itadd->first<=i){
            if(itadd==add.end())break;
            if(itadd->first==i){
                seg.add(0,i,a[itadd->second]);
            }
            itadd++;
        }
        
        while(itdel!=del.end()&&itdel->first<=i){
            if(itdel==del.end())break;
            if(itdel->first==i){
                seg.add(0,L[itdel->second],-a[itdel->second]);
            }
            itdel++;
        }
        
        ll val = seg.getmax(0,i);
        ans = max(ans,val);
        seg.add(i,i+1,val);
    }
    cout<<ans<<endl;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
ll mo=1000000007;
ll combi(ll N_, ll C_) {
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:combi(P_+Q_-1,Q_);}
int N,A,B,C;

void solve() {
	int i,j,k,l,r,x,y;;
	
	combi(0,0);
	
	cin>>N>>A>>B>>C;
	ll ret=0;
	for(int p=0;p<=min(A,C);p++) for(int q=0;p+3*q<=C;q++) {
		int s1=A-p;
		int s2=B/2;
		int s3=C-(p+3*q);
		ll tot=fact[p+q+s1+s2]*factr[s1]%mo*factr[p]%mo*factr[q]%mo*factr[s2]%mo;
		tot*=hcomb(s2,s3);
		ret+=tot%mo;
	}
	if(B%2) ret=0;
	cout<<ret%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 9600
/** author: __nishad__ **/
//#pragma GCC optimize(2)
//#pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;


typedef long long ll ;
typedef vector<ll> vll ;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define precision(k) cout<<setprecision(k)<<fixed;
#define loop(i,a,b) for(ll i=(a);i<(b);++i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323
#define endl "\n"

int main()
{
    IOS;

    int n, k, ans=0;
    cin>>n>>k;
    int arr[n];

    loop(i, 0, n){
        cin>>arr[i];

        if(abs(k*2 - arr[i]*2) >= arr[i]*2)
            ans = ans + arr[i]*2;
        else
            ans = ans + abs(k*2 - arr[i]*2);
    }

    cout<<ans;


}





























Measured memory_bytes: 3576
#include<iostream>
#include<stack>
#include<utility>
#include<vector>
#include<algorithm>
#include<utility>
 
using namespace std;
 
vector<int> children[1234567];
int parents[1234567];
int M[1234567];
vector<int> l[1234567];
long long c[1234567];
int sl[1234567];
 
pair<int,long long> dfs(int v){
  vector<int> l;
  long long c=0;
  for(auto e:children[v]){
    auto r=dfs(e);
    c+=r.second;
    l.push_back(r.first);
  }
  sort(begin(l),end(l));
  int sl=M[v];
  for(int i=0;i<l.size();i++){
    c+=l[l.size()-1-i]*1LL*i;
    sl+=l[i];
  }
  return make_pair(sl,c);
}
 
int main(){
  int N;
  cin>>N;
  vector<int> roots;
  for(int i=0;i<N;i++){
    int L;
    cin>>M[i]>>L;
    parents[i]=L;
    if(L==-1){
      roots.push_back(i);
    }else{
      children[L].push_back(i);
    }
  }
  vector<int> to;
  for(auto e:roots){
    stack<pair<int,int> > stk;
    stk.push(make_pair(e,0));
    while(!stk.empty()){
      auto c=stk.top();
      stk.pop();
      if(children[c.first].size()==c.second){
	to.push_back(c.first);
      }else{
	stk.push(make_pair(c.first,c.second+1));
	stk.push(make_pair(children[c.first][c.second],0));
      }
    }
  }
  for(auto e:to){
    sort(begin(l[e]),end(l[e]));
    sl[e]=M[e];
    for(int i=0;i<l[e].size();i++){
      c[e]+=l[e][l[e].size()-1-i]*1LL*i;
      sl[e]+=l[e][i];
    }
    if(parents[e]!=-1){
      l[parents[e]].push_back(sl[e]);
      c[parents[e]]+=c[e];
    }
  }
  long long ans=0;
  for(auto e:roots){
    ans+=c[e];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 149496
S = gets.chomp

divides = ['dream', 'dreamer', 'erase', 'eraser']
bfs = [0]
ans = false

while !bfs.empty?
  t = bfs.shift
  if t == S.size
    ans = true
    break
  end
  divides.each do |d|
    if S.slice(t, d.size) == d
      bfs << t + d.size
    end
  end
end

puts ans ? 'YES' : 'NO'

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

int L,beki[21] = {0};
vector<pair<pair<int,int>,int>> v;

int main(){
	cin >> L;
	int r = 0;
	beki[0] = 1;
	for(int i=1;i<=20;i++){
		beki[i] = beki[i-1]*2;
		if(beki[i]*2>L){
			r = i;
			break;
		}
	}
	int N = r+1;
	for(int i=1;i<N;i++){
		v.push_back({{i,i+1},0});
		v.push_back({{i,i+1},beki[i-1]});
	}
	int t = N-1;
	while(L>0 && t>0){
		if(L-beki[t-1]>=beki[r]){
			v.push_back({{t,N},L-beki[t-1]});
			L -= beki[t-1];
		}
		t--;
	}
	cout << N << " " << v.size() << endl;
	for(int i=0;i<v.size();i++){
		cout << v[i].first.first << " " << v[i].first.second << " " << v[i].second << endl;
	}
}

Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define lll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
#define Lets_be_precise cout<<fixed<<setprecision(10)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
	cin>>v[i];
}
//#define cerr if(false)cerr//uncomment to remove cerr from program...
void solveforthiscase(const int & test)
{//deb(test);
string s;
cin>>s;
n=s.size();
ll ans=0;
ll counta=0;
for(int i=0;i<n;i++)
{
    deb(counta);
    deb(ans);
    if(s[i]=='A')
    {
        counta++;
    }
    else if(s[i]=='B')
    {
        if(i==n-1)
        break;
        if(i==0)
        continue;
        if(s[i-1]=='A' && s[i+1]=='C')
        {
        ans+=counta;
        s[i+1]='A';
        i++;
        continue;
        }
        counta=0;
    }
    else if(s[i]=='C')
    counta=0;
}
cout<<ans;
return ;
}

int main()
{
	ios_base::sync_with_stdio(false);
	Lets_be_precise;
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 720
from collections import deque

N = int(input())
edge_idx = {}
edge_color = {i: None for i in range(N-1)}
E = {v: [] for v in range(1, N+1)}
for i in range(N-1):
    a, b = map(int, input().split())
    edge_idx[(a, b)] = i
    E[a].append(b)
    E[b].append(a)
degs = {v: 0 for v in range(1, N+1)}
for v in range(1, N + 1):
    degs[v] = len(E[v])
K = max(degs.values())
print(K)
q = deque([(-1, 1)])
visited = {i: False for i in range(1, N+1)}
while q:
    p, v = q.popleft()
    visited[v] = True
    if p == -1:
        used = -1
    else:
        used = edge_color[edge_idx[(p, v)]] if p < v else edge_color[edge_idx[(v, p)]]
    c = 1
    for u in E[v]:
        if visited[u]: continue
        q.append((v, u))
        if c == used: c += 1
        if u < v:
            edge_color[edge_idx[(u, v)]] = c
        else:
            edge_color[edge_idx[(v, u)]] = c
        c += 1
for i in range(N-1):
    print(edge_color[i])

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

typedef long long ll;
#pragma GCC optimize ("Ofast")
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define pb push_back
#define fs first
#define sc second
#define MOD 1000000007
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

int main()
{
    ll r;
    cin >> r;
    ll o = 3*(r*r);
    cout << o << endl;
}


Measured memory_bytes: 256