akhauriyash/Code-Regression huggingface dataset:
import math
import sys

sys.setrecursionlimit(200005)

n, q = map(int, input().split(" "))
abL = [list(map(int, input().split(" "))) for _ in range(n - 1)]
pxL = [list(map(int, input().split(" "))) for _ in range(q)]

to = [[] for _ in range(200005)]
ans = [0 for _ in range(n + 1)]


def dfs(v, p=-1):
    for u in to[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)


for a, b in abL:
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

for p, x in pxL:
    p -= 1
    ans[p] += x

dfs(0)

for a in ans[:n]:
    print(a)

Measured memory_bytes: 351128
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <climits>

using namespace std;
using ll=long long;

void solve(){
  int num;
  cin >> num;
  std::map<int, int> map;
  vector<bool> ar(100001);
  for(int i=0;i<num;i++){
    int x;
    cin >> x;
    ar[x]=true;
  }
  int ct=0;
  for(int i=0;i<100001;i++)
    ct+=ar[i];
  cout <<ct-!(ct%2) << endl;
}

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


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        for(int i = 1;;i++){
            n = n-k;
            if(n <= 0){
                System.out.print(i);
                break;
            }
            n++;
        }
    }
}

Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<queue>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP1(u) for(int i=hd[u],v,c;v=e[i].v,c=e[i].c,i;i=e[i].n)
#define REP2(u) for(int&i=cr[u],v,c;v=e[i].v,c=e[i].c,i;i=e[i].n)
using namespace std;
const int N=200200,INF=1000010000;
int n,x,y,ans,S,T,fl=1;
int a[N],b[N],ca[N],cb[N],hd[N],cr[N],dep[N];
queue<int>q;
struct edge{int n,v,c;}e[N];
void add_(int u,int v,int c){e[++fl]=(edge){hd[u],v,c};hd[u]=fl;}
void adde(int u,int v,int c){add_(u,v,c);add_(v,u,0);}
bool bfs(){
	FOR(i,S,T) dep[i]=-1,cr[i]=hd[i];
	q.push(S);dep[S]=0;
	while(q.size()){
		int u=q.front();q.pop();
		REP1(u)if(c && dep[v]<0)
			dep[v]=dep[u]+1,q.push(v);
	}
	return ~dep[T];
}
int dfs(int u,int E){
	if(u==T) return E;
	int F=0;
	REP2(u)if(c && dep[v]==dep[u]+1){
		int t=dfs(v,min(c,E));
		F+=t;e[i^1].c+=t;
		E-=t;e[i^0].c-=t;
		if(!E) break;
	}
	return F;
}
int main(){
	//freopen("perm.in","r",stdin);
	//freopen("perm.out","w",stdout);
	scanf("%d",&n);S=T=1;
	FOR(i,1,n) scanf("%d",&a[i]),a[i]++;
	FOR(i,1,n) scanf("%d",&b[i]),b[i]++;
	FOR(i,1,n)if(!ca[i])for(x=a[i],++T;ca[x]=T,x!=i;x=a[x]);
	FOR(i,1,n)if(!cb[i])for(x=b[i],++T;cb[x]=T,x!=i;x=b[x]);
	++T;
	FOR(i,1,n){
		x=ca[i];y=cb[i];
		if(a[i]==b[i]){
			if(i==a[i]) ans++;
			else adde(x,y,1),e[fl].c=1;
		}
		else{
			if(i!=a[i] && i!=b[i]) adde(y,x,1);
			if(i==a[i]) adde(y,T,1);
			if(i==b[i]) adde(S,x,1);
		}
	}
	//FOR(u,1,T){cout<<u<<':';REP(u) cout<<v<<'-'<<c<<' ';cout<<'\n';}
	while(bfs()) ans+=dfs(S,INF);
	cout<<n-ans<<'\n';
	//FOR(i,1,n) cout<<(~dep[ca[i]]?a[i]:i)<<' ';cout<<'\n';
	//FOR(i,1,n) cout<<(~dep[cb[i]]?i:b[i])<<' ';cout<<'\n';
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n,k,m,x;
  cin>>n>>m;
  map<int,int> mp;
  rep(i,0,n){
    cin>>k;
    rep(j,0,k){
      cin>>x;
      mp[x]++;
    }
  }
  int ans=0;
  for(auto i:mp){
    if(i.s==n) ans++;
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define data_type int
#define endl "\n"

int  main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    data_type x1=-2,y1=-2,n;
    bool check=0;
    string str;
    cin>>str;
    n=str.size();
    for(int i=0; i<n-1; i++)
        {
            if(str[i]==str[i+1])
                {
                    x1=i,y1=i+1;
                    check=1;
                    break;
                }

        }

    if(!check)
        {
            for(int i=1; i<n-1; i++)
                {
                    if(str[i-1]==str[i+1])
                        {
                            x1=i-1,y1=i+1;
                            check=1;
                            break;
                        }

                }
        }


    cout<<x1+1<<" "<<y1+1<<endl;

    return 0;
}


Measured memory_bytes: 512
import bisect


def main():
    INF = 10 ** 10
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A.reverse()
    B = [INF for _ in range(N)]
    for a in A:
        index = bisect.bisect_right(B, a)
        B[index] = a
    ans = 0
    for b in B:
        if b == INF:
            break
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 13824
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    set<char> a;
    for(char i = 'a'; i <= 'z'; ++i){
        a.insert(i);
    }
    string s;
    cin >> s;
    if(s.size() < 26){
        repi(i, s){
            a.erase(*i);
        }
        char m = 'z';
        repi(i, a){
            m = min(m, *i);
        }
        cout << s << m << endl;
        return 0;
    }
    if(s == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }
    for(int i = s.size() - 1; i > 0; --i){
        a.clear();
        for(int j = i + 1; j < s.size(); ++j){
            a.insert(s[j]);
        }
        char m = 'a' - 1;
        repi(j, a){
            m = max(*j, m);
        }
        if(m <= s[i]){
            continue;
        }
        m = 'z' + 1;
        repi(j, a){
            if(s[i] < *j)
                m = min(*j, m);
        }
        rep(j, i){
            cout << s[j];
        }
        cout << m << endl;
        return 0;
    }
    cout << (char)(s[0] + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        String name = "";
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        if(r < 1200){
            name = "ABC";
        }else if(r < 2800){
            name = "ARC";
        }else{
            name = "AGC";
        }
        System.out.println(name);
    }
}

Measured memory_bytes: 21844
#include <stdio.h> 
 
 
 int main(){ 
     int count[26]={0}; 
     char ch; 
     int i, num; 
 
 
     while(scanf("%c", &ch)!=EOF){ 
         if(islower(ch)){ 
             num=ch-'a'; 
         }else if(isupper(ch)){ 
             num=ch-'A'; 
         }else{ 
             continue; 
         } 
         count[num]++; 
     } 
     for(i=0;i<26;i++){ 
         printf("%c : %d\n", 'a'+i, count[i]); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2036
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <map>
#include <numeric>
#include <set>
using namespace std;

#define ll long long
#define ld long double
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// vector 要素の総和算出
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// vector 最大値( return ite )
#define _max_element(v) max_element(v.begin(),v.end())
// vector 最大値が格納されている要素値
#define _max_element_number(v) distance(v.begin(),max_element(v.begin(),v.end()))

//set<uint32_t> member;	// 重複するデータを保持する事はできない member.insert(2) member.insert(2) ⇒ member.count(2)は1
//multiset<uint32_t> v;	// 重複するデータも保持する事はできる   member.insert(2) member.insert(2) ⇒ member.count(2)は2

// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値 ex) 3.30303 ⇒ 4
#define _ceil(x) ceil(x)
// 指定された要素以上の値が現れる最初の位置のイテレータを取得する
#define _lower_bound(v,min) lower_bound(v.begin(), v.end(), min)
// 指定された要素より大きい値が現れる最初の位置のイテレータを取得する
#define _upper_bound(v,min) upper_bound(v.begin(), v.end(), min)

// 順列 n個の数が与えられる
// 0,1,2,...,n-1
// 全ての並べ方を1行ごとに出力する
// ex 0 1 2 / 0 2 1 / 1 0 2 / 1 2 0 / 2 0 1 / 2 1 0
#define _next_permutation(v) do {   \
	for (auto num : v) {            \
		printf("%d ", num);         \
	}                               \
	printf("\n");                   \
} while (next_permutation(v.begin(), v.end()))

// 絶対値
static int32_t _abs(const int32_t x) { return  (x > 0 ? x : -x); }
// 最大公約数
static int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	return b ? gcd(b, a % b) : a;
}
// 最小公倍数
static int lcm(int a, int b) { return a * b / gcd(a, b); }
// 多次元 std::vector 生成
template<class T>
vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
// ex) auto dp = make_vec<uint64_t>(SIZE + 1, 2, 2);


// ABC 164 C
// https://atcoder.jp/contests/abc164/tasks/abc164_c
int main()
{
	uint32_t n;
	cin >> n;

	map<string, int32_t> mp;

	string s;
	for (uint32_t i = 0; i < n; i++) {
		cin >> s;
		mp[s]++;
	}

	printf("%d\n", mp.size());
	return 0;
}


Measured memory_bytes: 19260
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	vvi w(m,vi(m));
	rep(i,m)rep(j,m)cin>>w[i][j];
	vvi in(n,vi(n));
	rep(i,n)rep(j,n)cin>>in[i][j];
	int out=0;
	int mi=inf;
	vvi dp(m,vi(3));
	rep(i,m)rep(x,n)rep(y,n)dp[i][(x+y)%3]+=w[in[x][y]-1][i];
	rep(r1,m)rep(r2,m)rep(r3,m)if(r1!=r2&&r2!=r3&&r3!=r1){
		int sum=dp[r1][0]+dp[r2][1]+dp[r3][2];
		mi=min(mi,sum);
	}
	out=mi;
	cout<<out<<endl;
}















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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}

const double EPS = 1e-8;
using P =  complex<double>;
namespace std {
  bool isnan(const P&p){
    return isnan(p.real()) or isnan(p.imag());
  }
}
struct C {
  P p; double r;
  C(const P &p_, double r_) : p(p_), r(r_) { }
};

// 交わらない場合はnanを返す
pair<P, P> crosspointCC(const C& c1, const C& c2){
  double d = abs(c1.p - c2.p);
  double rc = (d*d + c1.r*c1.r - c2.r*c2.r) / (2*d);
  double rs = sqrt(c1.r*c1.r - rc*rc);
  P diff = (c2.p - c1.p) / d;
  return make_pair(c1.p + diff * P(rc, rs), c1.p + diff * P(rc, -rs));
}

signed main(){
  int n;
  while(cin >> n, n){
    vector<P> ps(n);
    rep(i,n){
      double x, y; cin >> x >> y;
      ps[i].real(x);
      ps[i].imag(y);
    }
    vector<P> can;
    rep(i,n) FOR(j,i+1,n){
      C c1(ps[i],1), c2(ps[j],1);
      auto tmp = crosspointCC(c1, c2);
      if(not isnan(tmp.first))
	can.push_back(tmp.first);
      if((not isnan(tmp.second)) and abs(tmp.first - tmp.second) > EPS)
	can.push_back(tmp.second);
    }

    int ans = 1;
    rep(i,can.size()){
      int tmp = 0;
      rep(j,n)
	if(abs(can[i] - ps[j]) - EPS < 1) tmp++;
      chmax(ans, tmp);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3792
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long a, b;
  cin >> a >> b;
  cout << (a + b + 1) / 2 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int m1,d1;
    int m2,d2;
    
    scanf("%d %d",&m1,&d1);
    scanf("%d %d",&m2,&d2);
    
    if(m1 == m2) printf("0\n");
    else printf("1\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int n, ans = 1;
  cin>>n;
  cin>>s;
  for(int i = 1;i < n;i++) {
  	if(s[i] != s[i - 1]) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  int sum=0;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      sum+=A[i]*A[j];
      //cout<<A[i]<<" "<<A[j]<<endl;
    }
  }
  cout<<sum<<endl;
 return 0; 
}

Measured memory_bytes: 256
def input_int():
    return(int(input()))

def input_int_list():
    return(list(map(int,input().split())))

def input_int_map():
    return(map(int,input().split()))

def run():
    num_count = input_int()
    nums = []
    for _ in range(num_count):
        nums.append(input_int())

    num_count = 1

    current_num = 1
    while True:
        current_num = nums[current_num - 1]

        if num_count >= len(nums):
            print(-1)
            return

        if current_num == 2:
            print(num_count)
            return
        num_count += 1

run()


Measured memory_bytes: 80692
#include <iostream>
#include <vector>
#include <string>

void solve() {
    int n, m, d;
    std::cin >> n >> m >> d;

    std::vector<std::string> ss(n);
    for (auto& s : ss) std::cin >> s;

    int ans = 0;
    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < m; ++y) {
            bool judge;
            judge = true;
            for (int dx = 0; dx < d; ++dx) {
                int nx = x + dx;
                if (n <= nx || ss[nx][y] == '#') judge = false;
            }
            if (judge) ++ans;

            judge = true;
            for (int dy = 0; dy < d; ++dy) {
                int ny = y + dy;
                if (m <= ny || ss[x][ny] == '#') judge = false;
            }
            if (judge) ++ans;
        }
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}



Measured memory_bytes: 3220
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;

// #define DIV ((long) (1e9 + 7))
#define DIV 1000000007

#define COUT cout <<
#define SPACE_COUT << " " 
#define COLON_COUT << ": "
#define COMMA_COUT << ", "
#define ENDL << endl;

long power(long n, long m) {
    ll result = 1;
    while(m) {
        if (m & 1)
            result = result * n % DIV;
        n = n * n % DIV;
        m >>= 1;
    }
    return result % DIV;
}

vector<long> inversed_facts;
vector<long> facts;

long inversed_factorial(int k) {
    return inversed_facts[k];
}

long factorial(int k) {
    return facts[k];
}

void init_inversed_factorial(int n) {
    inversed_facts.resize(n+1);
    long N_factorial = facts[n];
    long cur_inversed = power(facts[n], DIV - 2);
    for (int i = n; i >= 0; --i) {
        int d = i == 0 ? 1 : i;        
        inversed_facts[i] = cur_inversed;
        cur_inversed = cur_inversed * d % DIV;
    }
}

void init_factorial(int n) {
    facts.resize(n+1);
    facts[0] = 1;

    ll result = 1;
    for (int i = 1; i <= n; ++i) {
        result = result * i % DIV;
        facts[i] = result;
    }
}

void init_facts_table(int n) {
    init_factorial(n);
    init_inversed_factorial(n);
}

ll comb(int n, int m) {
    return factorial(n) * inversed_factorial(m) % DIV
            * inversed_factorial(n-m) % DIV;
}

int
main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, w, a, b;
    cin >> h >> w >> a >> b;    
    h--;
    w--;    
    int hh = h - a, ww = w - b;
    init_facts_table(w+h);

    ll total = 0;
    int n = min(hh, ww);
    for (int i = 0; i <= n; ++i) {
        ll c = comb(hh - i +  b + i, b + i) * comb(a + i + ww - i, a + i);
        total += c;
        total %= DIV;
    }

    cout << total << endl;
    return 0;
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int Lmax = -INF;
    int Rmin = INF;
    rep(i, M) {
        int L, R; cin >> L >> R;
        Lmax = max(Lmax, L);
        Rmin = min(Rmin, R);
    }
    cout << max(0, Rmin - Lmax + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
using namespace std;
int main() {
	int x, a, b, c;
	int sum = 0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					sum ++;
				}
			}
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
n, m, c = [int(_) for _ in input().split(' ')]
b = [int(_) for _ in input().split(' ')]
a = [[int(_) for _ in input().split(' ')] for __ in range(n)]
print(len([i for i in range(n) if sum([a[i][j] * b[j] for j in range(m)]) + c > 0]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	ll n; cin >> n;
	vector<ll> a(n);
	for( auto &k : a ) cin >> k;
	ll ans = 0;
	for( int i = 0; i < 60; ++i ){
		ll nll = 0, eins = 0;
		for( int k = 0; k < n; ++k ){
			if( a[k] & (1ll<<i) ) ++eins;
			else ++nll;
		}
		ans += (1ll<<i)%mod * ((nll*eins)%mod) ;
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
str = input()
cnt = 0
for i in range(len(str)):
  if i == (len(str) - 1 - i):
    break;
  if str[i] != str[len(str)-1-i]:
    cnt += 1
    
  if i + 1 == (len(str) - 1 - i):
    break;

print(cnt)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main()
{
    int M;
    int a,b,c;
    
    cin >> M;
    
    while(cin >> a >> b >> c){
        if(a*a == b*b + c*c)
            cout << "YES" <<endl;
        else if(a*a + b*b == c*c)
            cout << "YES" <<endl;
        else if(a*a + c*c ==b*b)
            cout << "YES" <<endl;
        else
            cout << "NO" << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 1156
n = int(input())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
clist = list(map(int,input().split()))
score = blist[alist[0]-1]
for i in range(1,n):
    if alist[i] - alist[i-1] == 1:
        score += blist[alist[i]-1] + clist[alist[i] - 1 -1]
    else:
        score += blist[alist[i]-1]

print(score)


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>a>>b>>c;
      Cout(max({a,b,c})-min({a,b,c}));
     

       
return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

typedef struct{double l,a,b;} lab;

void run(){
    string s;
    cin>>s;
    int ans=0;
    int d=0;
    rep(i,s.length()){
        if(s[i]=='R')d++;
        else d--;
        if(d==4)ans++,d=0;
        else if(d==-4)d=0;
    }
    cout<<ans<<endl;
}


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

int main(){
	int n, s;
	int r[20000];
	
	while( cin >> n >> s , n || s ){
		for(int i=0 ; i < n ; i++ ){
			cin >> r[i];
		}
		
		int cnt=0;
		for(int i=0 ; i < n ; i++ ){
			if( r[i] > s ){
				cnt += n - i - 1;
			}else{
				for(int j=i+1 ; j < n ; j++ ){
					if( r[i] + r[j] > s ){
						cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}
}

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

#define INF_LL (int64)1e18
#define INF (int64)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

template<typename T,T MOD,T B>
struct RollingHash{
  using ll = long long;
  vector<T> hash,po;
  RollingHash(){}
  RollingHash(vector<T> vs){init(vs);}
  RollingHash(string &s){
    vector<T> vs;
    for(char c:s) vs.emplace_back(c);
    init(vs);
  }
  void init(vector<T> vs){
    int n=vs.size();
    hash.assign(n+1,0);
    po.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=((ll)hash[i]*B+vs[i])%MOD;
      po[i+1]=(ll)po[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(int l,int r){
    T res=(ll)hash[r]+MOD-(ll)hash[l]*po[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};

int main(void) {
  int64 N;
  cin >> N;
  if (N % 2 == 0) {
    int64 N2 = N;
    int64 cnt5 = 0, cnt2 = 0;
    N /= 2;
    while (N) {
      cnt5 += N / 5;
      N /= 5;
    }
    cout << cnt5 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;

signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll l=0,r=1e15;
    while(r-l>1){
        ll mid=(l+r)/2;
        int cnt=0;
        rep(i,n){
            ll x=(a[i]+mid-1)/mid;
            cnt+=(x-1);
        }
        if(cnt<=k) r=mid;
        else l=mid;
    }
    cout<<r<<endl;
    return 0;
}



Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int n;
    int a,b,c;
    cin >> n;
    cin >> a >> b;
    cin >> c;
    vector<int> pizza(n);
    REP(i,n){
	cin >> pizza[i];
    }
    sort(RALL(pizza));
    int ans = c/a;
    int count = 1;
    REP(i,n){
	ans = max(ans, (c+pizza[i])/(a+count*b));
	c += pizza[i];
	count++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1204
def bubblesort(A, N):
	flag = 1
	count = 0
	while flag:
		flag = 0
		for j in range(N-1,0,-1):
			if A[j] < A[j-1]:
				A[j], A[j-1] = A[j-1], A[j]
				flag = 1
				count += 1
	print(*A)
	print(count)


if __name__ == "__main__":
	n = int(input())
	a = list(map(int, input().split()))
	bubblesort(a, n)


Measured memory_bytes: 5604
class ExhaustiveSeach
  def initialize
    @n = gets.to_i
    @a = gets.split.map(&:to_i)
  end

  def solve(i, m)
    return true if m == 0
    return false if i >= @n
    res = solve(i+1, m) || solve(i+1, m-@a[i])
    return res
  end
end

e = ExhaustiveSeach.new
q = gets.to_i
m = gets.split.map(&:to_i)

m.each do |mm|
  puts e.solve(0, mm) ? 'yes' : 'no'
end

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A.at(i);

    int maxin = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            int ans = abs(A.at(i) - A.at(j));
            maxin = max(ans, maxin);
        }
    }
    cout << maxin << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
  double a,b,c,h,m,theta;
  scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
  theta=fabs(11*m/2-30*h);
  theta*=M_PI/180;
  c=cos(theta);
  c=a*a+b*b-2*a*b*c;
  c=pow(c,0.5);
  printf("%.12lf\n",c);
  return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

int main() {
  string s,t; cin>>s>>t;
  int cnt=0;
  rep(i,s.size()) {
    if(s[i]!=t[i]) cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 3876
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

vector<vector<pair<Int,Int>>> graph;
vector<Int> color;

void dfs(Int v, Int col, Int dis) {
	color[v] = col;

	for (auto next_v:graph[v]) {
		if (color[next_v.first] != -1)continue;
		else {
			if (next_v.second % 2) {
				dfs(next_v.first, 1 - col, next_v.second);
			}
			else {
				dfs(next_v.first, col, next_v.second);
			}
		}
	}

}

int main() {

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

	Int N;
	cin >> N;

	graph.resize(N,vector<pair<Int,Int>>());
	Int a, b, c;
	for (Int i = 0; i < N-1; i++) {
		cin >> a >> b >> c;
		graph[a - 1].push_back(make_pair(b - 1,c));
		graph[b - 1].push_back(make_pair(a - 1,c));
	}

	color.resize(N,-1);//-1未読、0白、1黒
	dfs(0, 0, 0);

    for (Int i = 0; i < N; i++) {
		printf("%lld\n", color[i]);
    }
}

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

using ll = long long;

int main(int argc, char *argv[])
{
    int n;
    cin >> n;

    ll total = 0;
    map<string, int> counts;
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;

        sort(s.begin(), s.end());
        total += counts[s];
        counts[s] += 1;
    }

    cout << total << endl;
}


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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int a, b;
  int ans;
  
  cin >> a >> b;
  
  ans = a-b*2;
  if(ans<0) ans = 0;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    // 入力
    string S;
    cin >> S;
    
    //0と１の数を数える
    int Count0 = 0;
    int Count1 = 0;
    for (int i = 0; i < S.size(); i++){
        if (S[i] == '0') Count0 += 1;
        if (S[i] == '1') Count1 += 1;
    }
    
    cout << 2 * min(Count0, Count1) << endl;
    
    
    
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>
#include<map>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
typedef pair<ll,ll> LL_LLP;
#define INF 1000000007
#define MAX_H 20000

#define ARRAY_MAX 100005

int main(){

    int n,maxi = -1;
    cin >> n;
    vector<int> a(ARRAY_MAX);

    REP(i,n){
        cin >> a[i];
        maxi = max(maxi,a[i]);
    }
    vector<int> count(maxi,0);

    REP(i,n){
        count[a[i]-1]++;
    }

    int k = 0;
    REP(i,maxi){
        if(count[i] > 0){
            k++;
        }
    }

    if(k % 2 == 0){
        cout << k-1 << endl;
    }else{
        cout << k << endl;
    }



    return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

A = sorted([A[i] - (i + 1) for i in range(len(A))])

mid = len(A) // 2
if len(A) % 2 == 1:
    b = A[mid]
else: 
    b = (A[mid] + A[mid-1]) // 2

ans = sum([abs(i - b) for i in A])
print(ans)

Measured memory_bytes: 25200
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

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 = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL a, b, c;
    cin >> a >> b >> c;
    if( a ) a = ( a - 1 ) / c + 1;
    b = b / c + 1;
    cout << b - a << endl;

    return 0;

}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll sum[200005];

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

    ll N; cin >> N;
    ll A[200005];

    for (int i = 2;i <= N;i++){
        cin >> A[i];
        sum[A[i]]++;
    }

    for (int i = 1;i <= N;i++){
        cout << sum[i] << endl;
    }

    return 0;

}

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

using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--) {
        int N, D;
        cin >> N >> D;
        vector<int> cookies = {D};
        for (int i = 0; i < N - 1; i++) {
            int v = -1, vx = -1, kk = -1;
            for (int j = 0; j <= i; j++) {
                int k = 127 - cookies[j];
                int xk = cookies[j] ^ k;                
                if (vx < k + xk - cookies[j]) {
                    vx = k + xk - cookies[j];
                    v = j;
                    kk = k;
                }
            }
            //cout << kk << " " << (kk ^ cookies[v]) << endl;
            cookies.push_back(kk);
            cookies.push_back(kk ^ cookies[v]);
            cookies.erase(cookies.begin() + v);
        }
        int res = 0;
        for (int i = 0; i < N; i++) {
            res += cookies[i];
        }
        cout << res << endl;
    }
    return 0;
}


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

bool is_same_num(int* a){
	if(a[0]==a[1] && a[0]==a[2] ) return true;
	return false;
}

bool is_sequence(int* a){
	if(a[0]+2==a[2] && a[0]+1==a[1]) return true;
	return false;
}

bool is_win(int* a){
	if(is_same_num(a)||is_sequence(a)) return true;
	return false;
}

int main(){
	int t;
	int c[9];
	cin >> t;
	for(int i=0;i<t;++i){
		for(int j=0;j<9;++j){
			cin >> c[j];
		}
		char ch;
		for(int j=0;j<9;++j){
			cin >> ch;
			if(ch=='G') c[j]+=10;
			else if(ch=='B') c[j]+=20;
		}
		sort(c,c+9);
		bool b=false;
		do {
			if( is_win(c) && is_win(c+3) && is_win(c+6) ) b=true;
		} while (next_permutation(c , c+9));
		cout << (b ? 1 : 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n;
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		int x=read();
		if(!(x&1)){
			if((x%3)&&(x%5)){
				printf("DENIED\n");
				return 0;
			}
		}
	}
	printf("APPROVED\n");
	return 0;
}


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 = 1e18;
const ll MOD = 1e9 + 7;

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




























int main(){
    ll n;
    cin >> n;
    ll x = 0;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
        x ^= a[i];
    }
    REP(i, n){
        cout << (x ^ a[i]) << " \n"[i == n - 1];
    }
}


Measured memory_bytes: 4684
#include <iostream>  
#include <string.h> 
using namespace std;
int main() {
    string x, y;
    cin >> x >> y;
    for (int i = 0, j = 2; i < 3; i++, j--) {
        if (x[i] != y[j]) {
            cout << "NO";
            return 0;
        }

    }cout << "YES";

    
    return 0;
}



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

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

  int used = 0;

  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    used += r - l + 1;
  }

  cout << used << endl;
}

Measured memory_bytes: 3572
object Main extends App {
  import java.util.Scanner
  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val a = sc.nextInt()
  val b = sc.nextInt()
  val c = sc.nextInt()
  val s = (1 to n).map { _ =>
    sc.next("(AB|AC|BC)")
  }.toList

  def traverse(a: Int,
               b: Int,
               c: Int,
               s: List[String],
               trace: List[Char]): Option[List[Char]] = {
    s match {
      case Nil => Some(trace.reverse)
      case "AB" :: t =>
        val a1 = a + 1
        val b1 = b - 1
        val r1 = if (a1 >= 0 && b1 >= 0 && c >= 0) {
          traverse(a1, b1, c, t, 'A' :: trace)
        } else None
        if (r1.nonEmpty) {
          r1
        } else {
          val a2 = a - 1
          val b2 = b + 1
          if (a2 >= 0 && b2 >= 0 && c >= 0) {
            traverse(a2, b2, c, t, 'B' :: trace)
          } else None
        }
      case "AC" :: t =>
        val a1 = a + 1
        val c1 = c - 1
        val r1 = if (a1 >= 0 && b >= 0 && c1 >= 0) {
          traverse(a1, b, c1, t, 'A' :: trace)
        } else None
        if (r1.nonEmpty) {
          r1
        } else {
          val a2 = a - 1
          val c2 = c + 1
          if (a2 >= 0 && b >= 0 && c2 >= 0) {
            traverse(a2, b, c2, t, 'C' :: trace)
          } else None
        }
      case "BC" :: t =>
        val b1 = b + 1
        val c1 = c - 1
        val r1 = if (a >= 0 && b1 >= 0 && c1 >= 0) {
          traverse(a, b1, c1, t, 'B' :: trace)
        } else None
        if (r1.nonEmpty) {
          r1
        } else {
          val b2 = b - 1
          val c2 = c + 1
          if (a >= 0 && b2 >= 0 && c2 >= 0) {
            traverse(a, b2, c2, t, 'C' :: trace)
          } else None
        }
    }
  }
  traverse(a, b, c, s, Nil) match {
    case Some(value) =>
      println("Yes")
      value.foreach(println)
    case None =>
      println("No")
  }

}


Measured memory_bytes: 115572
#include <bits/stdc++.h>
#define REP(i, n) for (long i = 0; i < n; ++i)
#define FOR(i, b, n) for (long i = b; i < n; ++i)

using namespace std;

void solve(string S) {

  vector<long> ans(S.length(), 0);

  long l(0), m(0), r(S.length());

  REP(i, S.length() - 1) {
    if (S.substr(i, 2) == "RL")
      m = i;

    if (S.substr(i, 2) == "LR") {
      r = i;
      ans[m] = (m - l) / 2 + 1 + (r - m) / 2;
      ans[m + 1] = (m - l + 1) / 2 + (r - m + 1) / 2;
      l = i + 1;
    }
  }
  r = S.length() - 1;
  ans[m] = (m - l) / 2 + 1 + (r - m) / 2;
  ans[m + 1] = (m - l + 1) / 2 + (r - m + 1) / 2;
  
  REP(i, S.length())
    cout << (i ? " " : "") << ans[i];
  cout << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  string S;
  cin >> S;

  solve(S);

  return 0;
}


Measured memory_bytes: 4216
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  long long N;
  cin >> N;
  long long ans = (N*(N - 1))/2;

  cout << ans << endl;
}


Measured memory_bytes: 3592
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
h = []
m.times do
  h << gets.split.map(&:to_i)
end
i = 0
h.sort{|u, v| v[1] <=> u[1]}.each do |x, y|
  break if a[i] >= y
  x.times do
    a[i] = y
    i += 1
    break if i >= n
    break if a[i] >= y
  end
  break if i >= n
end
puts a.inject(:+)

Measured memory_bytes: 19728
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

bool experiment = false;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  if (experiment) {
    for (int sl=1; sl<=256; sl*=2) {
      int cnt = 0;
      for (int i=0; i<=sl; ++i) {
        for (int a=0; a<=i; ++a) {
          int b = i-a;
          if (a+b==(a^b)) {
            //cout << a << " " << b << endl;
            cnt++;
          }
        }
      }
      cout << static_cast< bitset<10
      > >(sl) << ":" << cnt/2 << endl;
    }
    return 0;
  }
  string l;
  cin >> l;
  ul mod = 1000000007;
  vector< ul > v(l.size());
  ul d=1;
  v[0] = 1;
  for (int i=1; i<v.size(); ++i) {
    v[i] = v[i-1]+d;
    d*=3;
    v[i]%=mod; d%=mod;
  }
  ul ans = 0;
  d = 1;
  for (int i=0; i<v.size(); ++i) {
    if (l[i]=='1') {
      ans += v[v.size()-i-1]*d;
      d*=2;
      ans%=mod;
      d%=mod;
    }
  }
  cout << (ans*2+1)%mod << endl;
  return 0;
}


Measured memory_bytes: 1232
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int cnt[600][600];
int main(){
   int a,b;
   cin>>a>>b;
   cout<<(a-1)*(b-1)<<endl;
   return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int daishou[200002];

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


	int N = getint();
	int A[200001];
	rep1(i, N) A[getint()] = i;

	ll kotae = 0;
	for (int i = N; i > 0; i--) {
		int a = A[i];
		int l = daishou[a - 1];
		int r = daishou[a + 1];
		if (l && r) {
			daishou[l] = r;
			daishou[r] = l;
		}
		else if (l) {
			daishou[l] = a;
			daishou[a] = l;
		}
		else if (r) {
			daishou[r] = a;
			daishou[a] = r;
		}
		else {
			daishou[a] = a;
		}
		if (!l) l = a;
		if (!r) r = a;
		kotae += (ll)(a - l + 1) * (r - a + 1) * i;
	}

	printf("%lld", kotae);

	Would you please return 0;
}

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

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  cout <<  accumulate(v.begin(), v.begin() + k, 0);
}            


Measured memory_bytes: 3660
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)
b = gets.strip.split.map(&:to_i)
c = gets.strip.split.map(&:to_i)


result=0
pre=nil
a.each do|i|
  result += b[i-1]
  result+=c[i-2] if pre==i-1
  pre=i
end

p result


Measured memory_bytes: 1788
S = input()

def Check1(S):
    for i in range(len(S) // 2):
        if S[i] != S[len(S) - 1 - i]:
            return False
    return True

def Check2(S):
    S2 = ""
    for i in range(0, (len(S) - 1) // 2):
        S2 = S2 + S[i]
    return Check1(S2)

def Check3(S):
    S3 = ""
    for i in range((len(S) + 3) // 2 - 1, len(S)):
        S3 = S3 + S[i]
    return Check1(S3)

if Check1(S) and Check2(S) and Check3(S):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064