akhauriyash/Code-Regression huggingface dataset:
n,q = map(int,input().split())
s = list(input())
a = [0]*n
c = 0
for i in range(1,n):
    if s[i-1]=="A" and s[i]=="C":
        c+=1
    a[i]=c
for i in range(q):
    l,r = map(int,input().split())
    print(a[r-1]-a[l-1])

Measured memory_bytes: 6772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int b[n]={0};
    b[0]=0;
    b[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
    }
   cout<<b[n-1];
    return 0;
}

Measured memory_bytes: 1024
<?php
// C
fscanf(STDIN, '%d %d', $n, $k);
$x = array_map('intval', explode(' ', trim(fgets(STDIN))));
if ($x[0] > 0) {
    echo $x[$k - 1];
    exit;
}
if ($x[$n - 1] < 0) {
    echo -$x[$n - $k];
    exit;
}
$l = $r = [0];
for ($i = 0; $i < $n; $i++) {
    if ($x[$i] < 0) {
        $l[] = -$x[$i];
    } elseif ($x[$i] > 0) {
        $r[] = $x[$i];
    } else {
        $k--;
    }
}
$ans = 10 ** 10;
sort($l);
for ($i = 0; $i <= $k; $i++) {
    if (!isset($l[$i]) || !isset($r[$k - $i])) continue;
    $d = [$l[$i], $r[$k - $i]];
    sort($d);
    $ans = min($ans, $d[0] * 2 + $d[1]);
}
echo $ans;

Measured memory_bytes: 20980
n, k = [int(elem) for elem in input().split()]
ps = [int(elem) for elem in input().split()]

sum_max = 0
for i in range(k - 1, n):
    if i == k - 1:
        sum_now = sum(ps[:i + 1])
    else:
        sum_now = sum_now + ps[i] - ps[i - k]
    sum_max = max(sum_max, sum_now)
    
print(float(sum_max + k) / 2)

Measured memory_bytes: 24676
#include<cstdlib>
#include<iostream>
#include<string>
using namespace std;

struct Node{
  int num;
  Node *right,*left;
};

Node *insert(Node *p,int x){
  if(p==NULL){
    Node *q=(Node *)malloc(sizeof(Node));
    q->num=x;
    q->right=q->left=NULL;
    return q;
  }else{
    if(x<p->num)p->left=insert(p->left,x);
    else p->right=insert(p->right,x);
    //   cout<<p->num<<endl;
    return p;
  }
}

bool find(Node *p,int x){
  if(p==NULL)return false;
  else if(x==p->num) return true;
  else if(x<p->num) return find(p->left,x);
  else  return find(p->right,x);
}

void inorder(Node *T){
  if(T==NULL) return;
  inorder(T->left);
  cout<<" "<<T->num;
  inorder(T->right);
}

void preorder(Node *T){
  if(T==NULL) return ;
  cout<<" "<<T->num;
  preorder(T->left);
  preorder(T->right);
}

int main(){
  int m,k;
  string s;
  struct Node *T;
  T=NULL;
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>s;
    if(s=="insert"){
      cin>>k;
      T=insert(T,k);
    }else if(s=="find"){
      cin>>k;
      if(find(T,k)==false) cout<<"no"<<endl;
      else cout<<"yes"<<endl;
    }else if(s=="print"){
      inorder(T);
      cout<<endl;
      preorder(T);
      cout<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 13712
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <cctype>

typedef long long int ll;
using namespace std;

int main() {
    string a, b, c, d;
    cin >> a >> b >> c;
    d = a.substr(0, 1) + b.substr(0, 1) + c.substr(0, 1);
    transform(d.begin(), d.end(), d.begin(), ::toupper);

    cout << d << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <string>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
using ll = long long;



int main() {
	double pi = 3.14159265358979323846;
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	double h1 = (h*60+m) % 720 * 0.5;
	double m1 = 6 * m;
	double d = abs(m1 - h1);
	long double s = sqrt(a*a+b*b-2*a*b*cos(2 * pi/ 360 * d));
	cout << setprecision(15) << s << endl;

	return 0;
}

Measured memory_bytes: 4224
package main

import (
	"fmt"
	//"math"
	//"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := scanNums(n)
	b := scanNums(n)
	c := scanNums(n)
	sum:= 0
	prenum := -1 
	for i:=0;i<n;i++{
		sum += b[a[i]-1]
		if a[i] == prenum + 1{
			sum += c[a[i]-2]
		}
		prenum = a[i]
	}
	fmt.Print(sum)
}

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}


Measured memory_bytes: 512
local bit=require"bit"
local ffi=require"ffi"
local function int(x)return ffi.new("int64_t",x)end
local function printn(x)print(tonumber(x))end
local function for64(a,b,c)c=c or 1 local x=a return c<0 and function()local ret=x x=x+c return ret>=b and ret or nil end or function() local ret=x x=x+c return ret<=b and ret or nil end end
local MOD=int(1000000007)
local function add(a,b)return (a+b)%MOD end
local function sub(a,b)a=(a-b)%MOD return a<0 and a+MOD or a end
local function mul(a,b)return a*b%MOD end
local function pow(a,b)
	local ret=int(1)
	while(b>0)do
		if(b%2==1)then ret=mul(ret,a)end
		a=mul(a,a)
		b=b/2
	end
	return ret
end
local function inv(x)
	local a=x
	local b,u,v=int(MOD),int(1),int(0)
	repeat
		local t=a/b
		a,b=b,a-t*b
		u,v=v,u-t*v
	until(b==0)
	u=u%MOD
	return u<0 and u+MOD or u
end
local function div(a,b)return mul(a,inv(b))end
local function C(n,k)
	if(n<k)then return 0 end
	local ret=int(1)
	for i in for64(n,n-k+1,-1) do
		ret=mul(ret,i)
	end
	for i in for64(2,k) do
		ret=div(ret,i)
	end
	return ret
end

 
n=int(io.read"*n")
a=int(io.read"*n")
b=int(io.read"*n")
printn(sub(sub(sub(pow(2,n),C(n,a)),C(n,b)),1))

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    string t = 'R' + s + 'L';
    int ans = 0;
    repf(i,1,n+1){
        if (t[i]==t[i+(t[i]=='R')-(t[i]=='L')]){
            ans++;}}
    cout << min(n - 1, ans + 2 * k) << ENDL;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

void WF(vector<vector<LL>> &L,int N){  // Lは隣接行列、Nは頂点数
    rep(k,N)rep(i,N)rep(j,N)L[i][j] = min(L[i][j],L[i][k]+L[k][j]);
    return;
}

int main(){
    int H,W;cin >> H >> W;
    vector<vector<LL>> c(10,vector<LL>(10,0));
    rep(i,10)rep(j,10)cin >> c[i][j];
    vector<vector<LL>> A(H,vector<LL>(W,0));
    rep(i,H)rep(j,W)cin >> A[i][j];

    WF(c,10);    
    LL ans = 0;
    rep(i,H)rep(j,W){
        if(A[i][j] == -1)continue;
        int tmp = A[i][j];
        ans += c[tmp][1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
using namespace std;
 
int main(){
    int a, b;
    char op;
    while(true){
        scanf("%d %c %d",&a, &op, &b);

        if(op=='?'){
            break;
        }
        switch(op){
        case '+':
            cout << a+b << endl;
            break;
        case '-':
            cout << a-b << endl;
            break;
        case '*':
            cout << a*b << endl;
            break;
        case '/':
            cout << a/b << endl;
            break;
        }
    }
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define ll          long long
#define int 		long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
	//write here
	int a;
	cin>>a;
	cout<<a+(a*a)+(a*a*a)<<endl;
	return;
}

int32_t main(){
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	//insert code
//	int t;
//	cin>>t;
//	while(t--)
		solve();
	return 0;
}

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

int d[500][500],de[500][500];
#define REP(i,n) for(int i=0;i<n;i++)
typedef pair<int,int> P;
int dy[4]={-1,1,0,0},dx[4]={0,0,-1,1},ans;

signed main(){
  int n;cin>>n;
  REP(i,n)REP(j,n)d[i][j]=min({i,j,n-i-1,n-j-1});
  deque<P> que;
  REP(_,n*n){
    int a;cin>>a;a--;
    ans+=d[a/n][a%n];
    de[a/n][a%n]++;
    que.push_back(P(a/n,a%n));
    while(que.size()){
      P p=*que.begin();que.pop_front();
      int y=p.first,x=p.second;
      REP(i,4){
        int Y=y+dy[i],X=x+dx[i];
        if(Y<0||Y>=n||X<0||X>=n)continue;
        if(d[Y][X]<=d[y][x]+!de[y][x])continue;
        if(de[y][x]){
          d[Y][X]=d[y][x];
          que.push_front(P(Y,X));
        }
        else{
          d[Y][X]=d[y][x]+1;
          que.push_back(P(Y,X));
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6484
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=1;i<=100;i++){
        if(a*i%b==c){
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		HashSet<Integer>[] sets = new HashSet[m];
		for (int i = 0; i < m; i++) {
		    sets[i] = new HashSet<Integer>();
		    int x = sc.nextInt();
		    for (int j = 00; j < x; j++) {
		        sets[i].add(sc.nextInt() - 1);
		    }
		}
		boolean[] arr = new boolean[m];
		for (int i = 0; i < m; i++) {
		    arr[i] = sc.nextInt() == 1;
		}
		int count = 0;
		for (int i = 0; i < Math.pow(2, n); i++) {
		    boolean[] state = getState(n, i);
		    boolean flag = true;
		    for (int j = 0; j < m && flag; j++) {
		        boolean now = false;
		        for (int x : sets[j]) {
		            now ^= state[x];
		        }
		        flag = (now == arr[j]);
		    }
		    if (flag) {
		        count++;
		    }
		}
		System.out.println(count);
   }
   
   static boolean[] getState(int n, int value) {
       boolean[] ret = new boolean[n];
       for (int i = 0; i < n; i++) {
           ret[i] = (value % 2 == 1);
           value /= 2;
       }
       return ret;
   }
}


Measured memory_bytes: 21972
#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 ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=2005,mod=1e9+7;
int add(int x,int y)
{
  x+=y;
  if(x>=mod) x-=mod;
  if(x<0) x+=mod;
  return x;
}
int mult(int x,int y)
{
  ll tmp=(ll)x*y;
  if(tmp>=mod) tmp%=mod;
  return tmp;
}
int ncr(int x,int y)
{
  ll tmp=x;
  tmp*=(x-1);
  tmp>>=1;
  tmp%=mod;
  return tmp;
}
int a[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int ans=0;
  ll n,k;
  cin>>n>>k;
  rep(i,1,n+1) cin>>a[i];
  rep(i,1,n+1)
    {
      int cnt=0,cnt2=0;
      rep(j,i+1,n+1) cnt+=(a[i]>a[j]);
      rep(j,1,n+1) cnt2+=(a[i]>a[j]);
      ans=add(ans,mult(cnt,k));
      ans=add(ans,mult(cnt2,ncr(k,2)));
    }
  cout<<ans<<endl;
  return 0 ;
}


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

int gcd(int A, int B) {
    if (B % A == 0) {
        return A;
    } else {
        return gcd(B % A, B);
    }
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
	for(int i=1 ; i <= n ; ++i)
	{
		if(n%i == 0) {
          ret.push_back(i);
		}
	}
	return ret;
}


int main(int argc, char const *argv[])
{
    int A, B, K;
    std::cin >> A >> B >> K;
    int value_max = gcd(std::min(A, B), std::max(A, B));
    std::vector<int> elements = enum_div(value_max);
    int ans = elements[elements.size() - K];
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<cmath>
#include <string>
#include<map> 
#include<deque>  
#include<vector>
#include<bitset>
#include<string>  
#include<cstring> 
#include<stack>  
#include<set>
#include<functional>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<long long,long long> pll;
ull a[123];
int n;
int main()
{
	scanf("%d",&n);
	a[0]=2;a[1]=1;a[2]=3;
	for(int i=3;i<=n;i++)a[i]=a[i-1]+a[i-2];
	printf("%lld\n",a[n]);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
typedef long long ll;

int main()
{
	int N, i, count = 0, flg = 0;
	scanf("%d", &N);
	int A[N + 1];
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		if (A[i] % 2 != 0) flg = 1;
	}
	while (flg == 0) {
		for (i = 0; i < N; i++) {
			if (A[i] % 2 != 0) {
				flg = 1;
				break;
			}
			A[i] = A[i] / 2;
		}
		if (flg == 1) break;
		count++;
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
using ll = long long;
using ld = long double;
// const int MAXMEM = 200 * 1000 * 1024;
// char _memory[MAXMEM];
// size_t _ptr = 0;
// void* operator new(size_t _x) { _ptr += _x; return _memory + _ptr - _x; }
// void operator delete (void*) noexcept {}
const string FILENAME = "input";




int n;
int a[18];
int b[18];
int dp[1 << 18][18];
int score[18];


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  	//read(FILENAME);     
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    int res = 1e9;
    for (int i = 1; i < (1 << n); i++) {
        vector<int> st;
        int cur = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                score[j] = cur;
                st.pb(j);
            } else {
                cur++;
            }
        }
        for (auto x: st) {
            dp[i][x] = 1e9;
            if (sz(st) == 1) {
                dp[i][x] = abs(x - (sz(st) - 1));
            }
            for (auto y: st) {
                if (x != y) {
                    int cost = score[x] + dp[i ^ (1 << x)][y];
                    int d = (abs(x - (sz(st) - 1)) & 1 ? b[x]: a[x]);
                    int d1 = (abs(y - (sz(st) - 2)) & 1 ? b[y]: a[y]);
                    if (d >= d1) {
                        chkmin(dp[i][x], cost);
                    }
                }   
            }
            if (sz(st) == n) {
                chkmin(res, dp[i][x]);
            }
        }
    }
    if (res > 100000) {
        cout << -1 << '\n';
        return 0;
    }
    cout << res << '\n';
    return 0;
}            	


Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll mod=1e9+7;
vector<vector<int>> v;
vector<vector<ll>> dp;
int siz,n;
ll solve(int i,int x)
{
  if(i==n)
  return (x==0?1:0);
  if(dp[i][x]!=-1)
  return dp[i][x];
  ll ans=0;
  for(int j=0;j<n;j++)
  {
    if(v[i][j]==0||(((1<<j)&x)==0))
    continue;
    ans=(ans+solve(i+1,(x^(1<<j))))%mod;
  }
  return dp[i][x]=ans;
}
int main()
{
  cin>>n;
  v.resize(n,vector<int>(n));
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
      cin>>v[i][j];
    }
  }
  siz=(1<<n)-1;
  dp.resize(n,vector<ll>((1<<n),-1));
  cout<<solve(0,siz)<<endl;
  return 0;
}


Measured memory_bytes: 363840
#include<bits/stdc++.h>
using namespace std;
char a[1000];
int main(){
	int sum=0;
	gets(a);
	for(int i=0;i<strlen(a);i++){
		if(a[i]=='C') sum=1;
		if(a[i]=='F'&&sum==1) sum=2;
	}
	if(sum==2) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
int a=read(),b=read(),h=read();
write((a+b)*h>>1);
}

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

double pi=M_PI;

int main(){
  double A,B; cin>>A>>B;
  int H,M; cin>>H>>M;
  double Bx=B*sin(2*pi*M/60);
  double By=B*cos(2*pi*M/60);
  double Ax=A*sin(pi*H/6+pi/6*M/60);
  double Ay=A*cos(pi*H/6+pi/6*M/60);
  cout<<setprecision(15);
  cout<<sqrt((Bx-Ax)*(Bx-Ax)+(By-Ay)*(By-Ay));
  cout<<endl;
  return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};
int a[2000];
ll dp[22][1200];

int main(){
	int n,K;cin>>n>>K;
	rep(i,K)scanf("%d",&a[i]);
	dp[0][0]=1;
	Fact fac(n);
	rep(i,K)rep(j,n+1){
		if(dp[i][j]==0)continue;
		for(int k=0;k<=a[i]&&j+k<=n;k++){
			(dp[i+1][j+k]+=dp[i][j]*fac.nCr(n-j,k)%MOD*fac.nCr(n-k,a[i]-k))%=MOD;
		}
	}
	cout<<dp[K][n]<<endl;
}

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

int main() {
    string n;
    cin >> n;
    
    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
main::IO()
main = do
  nc<-getLine
  let n = read nc ::Int
  dat<-(get_n n)
  print (solver 1 dat)



solver :: Int -> [Int] -> Int
solver x [] = 0
solver x (b:rest)= if b<x then solver x rest
                          else if b==x then solver (x+1) rest
                                       else if (mod b x==0) then ((div b x)-1)+(solver (max 2 x) rest)
                                                            else (div b x)+(solver (max 2 x) rest)

get_n::Int -> IO [Int]
get_n 0 = return []
get_n n = do
          c<-getLine
          let m = read c ::Int
          rest<- (get_n (n-1))
          return (m:rest)

Measured memory_bytes: 64892
#include<bits/stdc++.h>
using namespace std;
int main(){
 int d;
  cin>>d;
  if(d==22) cout<<"Christmas Eve Eve Eve";
  else if(d==23) cout<<"Christmas Eve Eve";
  else if(d==24) cout<<"Christmas Eve";
  else if(d==25) cout<<"Christmas";
  return 0;
}

Measured memory_bytes: 256
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, = read_line(int)
k, = read_line(int)
xs = [int(x) for x in input().split()]

cost = 0
for x in xs:
    cost += min(x, k - x) * 2
print(cost)


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

ll fun(int n)
{
	return 1LL * n * (n + 1) / 2;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size() + 1;
	vector<pair<char, int> > vec;
	for (int i = 0; i < n - 1; i++) {
		int j = i;
		while (i < n - 2 && s[i] == s[i + 1])
			i++;
		vec.push_back({s[i], i - j + 1});
	}
	ll sum = 0;
	int sz = vec.size();
	for (int i = 0; i < sz; i++) {
		if (i + 1 < sz && vec[i].first == '<') {
			int peak1 = max(vec[i].second, vec[i + 1].second);
			int peak2 = min(vec[i].second, vec[i + 1].second);
			sum += fun(peak1) + fun(peak2 - 1);
			i++;
		}
	}
	if (vec[0].first == '>')
		sum += fun(vec[0].second);
	if (vec[sz - 1].first == '<')
		sum += fun(vec[sz - 1].second);
	cout << sum;
	return 0;
}

Measured memory_bytes: 3352
#include<stdio.h>
int main()
{
    int x,i=0,n=0,a[10000];
    while(1){
        scanf("%d",&a[i]);
        if(a[i]==0){
            break;
        }
        i++;
        n++;
    }
    for(i=0;i<n;i++){
        printf("Case %d: %d\n",i+1,a[i]);
    }
    return 0;
}



Measured memory_bytes: 1984
#include<bits/stdc++.h>
using namespace std;
#define inet long long
main(){
  string s,s2;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]!='x')s2+=s[i];
  }
  int f=0;
  for(int i=0;i<s2.size();i++){
    if(s2[i]!=s2[s2.size()-1-i])f=1;
  }
  if(f)cout<<-1<<endl;
  else{
    int ans=0,cnt[1000000]={},c=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='x')cnt[c]++;
      else c++;
    }
    for(int i=0;i<=c;i++){
      ans+=abs(cnt[i]-cnt[c-i]);
    }
    cout<<ans/2<<endl;
  }
  return 0;
}


Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;


int64_t pow_rem(int64_t x, int64_t m, int64_t rem)
{
	if (m == 0) {
		return 1;
	}
	if (m == 1) {
		return x;
	}

	if (m & 1) {
		int64_t val = pow_rem(x, m / 2, rem);
		val = val * val;
		val %= rem;
		val *= x;
		val %= rem;
		return val;
	}
	else {
		int64_t val = pow_rem(x, m / 2, rem);
		val = val * val;
		val %= rem;
		return val;
	}
}

int64_t pow_remdiv(int64_t val, int64_t rem)
{
	return pow_rem(val, rem - 2, rem);
}

int64_t divide_rem(int64_t divident, int64_t dividor, int64_t rem)
{
	int64_t ret = pow_remdiv(dividor, rem);
	ret *= divident;
	ret %= rem;

	return ret;
}

int64_t nCr(int64_t n, int64_t r, int64_t rem) {
	if (n == 0) return 0;
	if (r > n) return 0;

	if (n - r < r) r = n - r;

	int64_t ret = 1;
	for (int64_t i = 0; i < r; i++) {
		ret *= (n - i);
		ret %= rem;
		ret = divide_rem(ret, i + 1, rem);
	}

	return ret;
}

int64_t kRem = 1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t x, y; cin >> x >> y;

	if ((x + y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}
	int64_t r = (x + y) / 3;
	x -= r;
	y -= r;
	if (x > y) swap(x, y);
	if (x < 0) {
		cout << 0 << endl;
		return 0;
	}

	cout << nCr(x + y, x, kRem);
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    string s; cin>>s;
    int cnt=0;
    for(char c:s){
        if(c=='R') cnt++;
    }
    if(cnt>n-cnt) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		BigDecimal ans = new BigDecimal("0");

		int i;
		String x,u;
		BigDecimal temp;
		for(i = 0; i < n; i++) {
			x = scan.next();
			u = scan.next();
			temp = new BigDecimal(x);
			if(u.equals("BTC")) {
				temp = temp.multiply(new BigDecimal("380000.0"));
			}
			ans = ans.add(temp);
		}
		System.out.println(ans.toString());
	}
}


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

int main(){
    int n, q;
    cin >> n >> q;
    vector<vector<int>> node(n);
    for (int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        node[a].push_back(b);
        node[b].push_back(a);
    }
    vector<int> ans(n, 0);
    for (int i = 0; i < q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    vector<bool> used(n, false);
    queue<int> que;
    que.push(0);
    while (que.size()){
        int x = que.front(); que.pop();
        used[x] = true;
        for (int i = 0; i < node[x].size(); i++){
            if (used[node[x][i]]) continue;
            ans[node[x][i]] += ans[x];
            que.push(node[x][i]);
        }
    }
    for (int i = 0; i < n; i++){
        cout << ans[i];
        if (i != n - 1) cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 15604
n,m = map(int,input().split())
x = [list(map(int,input().split())) for l in range(n)]
x = sorted(x)
count = m
p = 0
for i in x:
  if count >= i[1]:
    count -= i[1]
    p += i[0] * i[1]
  elif count ==0:
    break
  else:
    p += i[0] * count
    count = 0

print(p)
  

Measured memory_bytes: 28304
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  std::string S = std::to_string(N);
  auto X = boost::accumulate(S, 0, [](int sum, char c){
    return sum + (c - '0');
  });
  auto res = N % X == 0;
  auto ans = res ? "Yes" : "No";
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
sum = 0
score = []

n.times do |i|
    score[i] = gets.chomp.to_i
end

sum = score.inject(:+)
score.sort!

0.upto(score.length - 1) do |j|
    if score[j] % 10 == 0
        next
    elsif (sum % 10 == 0) && (sum != 0) && (score[j] % 10 != 0)
        sum -= score[j]
    else 
        break
    end
end

if sum % 10 == 0 ; sum = 0
end

puts sum

Measured memory_bytes: 1788
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Score Attack
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = 2000;

typedef long long ll;
const ll LINF = 1LL << 60;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,int> pli;

/* global variables */

int as[MAX_M], bs[MAX_M], cs[MAX_M];
ll dists[MAX_N];
bool upds[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &as[i], &bs[i], &cs[i]);
    as[i]--, bs[i]--;
  }

  fill(dists, dists + n, -LINF);
  dists[0] = 0;

  for (int i = 0; i < n - 1; i++)
    for (int j = 0; j < m; j++) {
      int &aj = as[j], &bj = bs[j], &cj = cs[j];
      ll d = dists[aj] + cj;
      if (dists[bj] < d) dists[bj] = d;
    }

  ll gd = dists[n - 1];
  //printf("%lld\n", gd);

  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int &aj = as[j], &bj = bs[j], &cj = cs[j];
      ll d = dists[aj] + cj;
      if (dists[bj] < d) {
	dists[bj] = d;
	upds[bj] = true;
      }
    }

  if (upds[n - 1]) puts("inf");
  else printf("%lld\n", gd);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(){
  int n,i,j,k,flag,count = 0,A[N];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }

  flag = 1;
  j = 1;

  while(flag){
    flag = 0;
    for(i = n-1;i >= j;i--){
      if(A[i] < A[i-1]){
        flag = 1;
        k = A[i];
        A[i] = A[i-1];
        A[i-1] = k;
        count++;
      }
      /*for(k = 0;k < n;k++){
        printf("%d ",A[k]);
      }printf("\n");*/
    }
    j++;
  }
  for(i = 0;i < n;i++){
    printf("%d",A[i]);
    if(i == n-1) break;
    printf(" ");
  } printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
string s;
int main()
{
	cin>>s;
	int sum=0;
	for(int i=0;i<s.size();i++)sum=sum+s[i]-'0',sum%=9;
	if(sum==0)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3712
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

lint MOD;

lint powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

int main(void){
    lint N;
    cin >> N;
    string X;
    cin >> X;
    lint p=0;
    rep(i,N) if(X[i]=='1') p++;
    lint res=0;
    lint resp=0,resm=0;
    bool p1,p0;
    MOD=p;
    if(p==0) p0=true,p1=true;
    if(p==1) p1=true;
    rep(i,N) if(X[i]=='1'){
        if(MOD>0) res=(res+powmod(2,N-1-i))%MOD;
        MOD++;
        resp=(resp+powmod(2,N-1-i))%MOD;
        MOD-=2;
        if(MOD>0) resm=(resm+powmod(2,N-1-i))%MOD;
        MOD++;
    }
    rep(i,N){
        lint cnt=p;
        if(X[i]=='0') cnt++;
        else cnt--;
        if(cnt==0){
            cout << 0 << endl;
            continue;
        }
        if(X[i]=='0'){
            lint base=resp;
            lint ans=1;
            MOD++;
            base=(base+powmod(2,N-1-i))%MOD;
            while(base!=0){
                int div=Flagcount(base);
                base%=div;
                ans++;
            }
            cout << ans << endl;
            MOD--;
        }
        if(X[i]=='1'){
            lint base=resm;
            lint ans=1;
            MOD--;
            base=(base-powmod(2,N-1-i)+MOD)%MOD;
            while(base!=0){
                int div=Flagcount(base);
                base%=div;
                ans++;
            }
            cout << ans << endl;
            MOD++;
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    cout<<std::setprecision(10);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;

    VV to(n);
    VV ot(n);
    rep(i,m){
        ll s,t;
        cin>>s>>t;
        s--,t--;
        to[s].pb(t);
    }

    vector<double> dp(n,0);
    per(i,n-1){
        ll cntedge = to[i].size();
        for(auto j :to[i]){
            dp[i] += (dp[j]+1)/cntedge;
        }
    }

    double ans = dp[0];
    rep(s,n){
        int t=s;
        double x=0;
        if(to[s].size()==1)continue;
        Each(y,to[s]){
            if(dp[y]>x){
                t = y;
                x = dp[y];
            }
        }
        vector<double> e(n,0);

        per(i,n-1){
            ll cntedge = to[i].size();
            for(auto j :to[i]){
                if(i==s&&j==t)cntedge--;
            }
            for(auto j :to[i]){
                if(i==s&&j==t)continue;
                e[i] += (e[j]+1)/cntedge;
            }
        }
        ans = min(e[0],ans);
    }

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


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

using namespace std;

int main()
{
    string S;
    cin>>S;
    int A[4];
    for (int i=0; i<4; i++) {
        A[i]=int(S[i]-'0');
    }
    for(int i=0;i<8;i++)
    {
        int sum = A[0]+(((i)&1)*10-5)/5*A[1]+(((i>>1)&1)*10-5)/5*A[2]+(((i>>2)&1)*10-5)/5*A[3];
        if(sum==7)
        {
            cout<<A[0];
            for(int j=0;j<=2;j++)
            {
            if(((i>>j)&1) == 1)
            {
                cout<<'+';
            }
            else
            {
                cout<<'-';
            }
            cout<<A[j+1];
            }
            cout<<"=7"<<endl;
            return 0;
        }
    }
    cout<<"bubu";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {

		int[] a = new int[4];
		int[] b = new int[4];

		for (int i=0; i<4; i++) {
			a[i] = in.nextInt();
		}
		for (int i=0; i<4; i++) {
			b[i] = in.nextInt();
		}

		int[] cnt = new int[10];
		int cnt1 = 0, cnt2 = 0;
		for (int i=0; i<4; i++) {
			if (a[i] == b[i]) {
				cnt1++;
			} else {
				cnt[a[i]]++;
				cnt[b[i]]++;
			}
		}

		for (int i=0; i<10; i++) {
			if (cnt[i] > 1) {
				cnt2++;
			}
		}

		out.println(cnt1 + " " + cnt2);
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while (in.hasNext()) solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 26428
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String c = sc.next();
		String abc = "abcdefghijklmnopqrstuvwxyz";
		int index = abc.indexOf(c);
		System.out.println(abc.charAt(index+1));
		}
	}




Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)

// #define NMAX 1000000000
int A,B,C,D;

bool solve(){
	// bool ans = true;

	int m[2][2];
	m[0][0] = A; // 先手　体力
	m[0][1] = B; // 先手　攻撃
	m[1][0] = C; // 後手　体力
	m[1][1] = D; // 後手　攻撃
	int at = 0;
	while(true){
		int df = (at+1)%2;
		m[df][0] -= m[at][1];
		if(m[df][0] <= 0){
			if(df%2){
				return true;
			}
			return false;
		}
		at = df;
	}

	return false;
}

int main(){
	cin>>A;
	cin>>B;
	cin>>C;
	cin>>D;
	cout<< (solve()?"Yes":"No") <<endl;
	// cout<<cout<<setprecision(10)<< solve() <<endl;
	// printf("%f\n",solve());
	// solve();
}


Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(10 ** 9)

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    G[x].append(y)


def topological_sort(g):
    topological_list = []
    visited = set()

    def dfs(n):
        for e in g[n]:
            if e not in visited:
                dfs(e)
        topological_list.append(n)
        visited.add(n)

    for i in range(len(g)):
        if i not in visited:
            dfs(i)

    return topological_list[::-1]


topological_order = topological_sort(G)
dp = [0] * N
for t in topological_order:
    for to in G[t]:
        dp[to] = max(dp[to], dp[t] + 1)

print(max(dp))


Measured memory_bytes: 67288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define DBG(v) cerr << #v << " = " << (v) << endl;

const int MxN = (int) 1e5 + 9;
vector<pair<int, int>> adj[MxN + 9];
int color[MxN + 9];

void dfs(const int u, const int parent = -1) {
	for (auto e : adj[u])
		if (e.first != parent) {
			color[e.first] = color[u] ^ e.second;
			dfs(e.first, u);
		}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		adj[u].push_back( { v, w & 1 });
		adj[v].push_back( { u, w & 1 });
	}
	dfs(1, -1);
	for (int i = 1; i <= n; ++i)
		cout << color[i] << '\n';
	return 0;
}


Measured memory_bytes: 8448
#include<stdio.h>
#define MAX 100
int number[MAX] = {0};
void bubbleSort(int *, int);

int main(){
    int n, i;

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

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

}

void bubbleSort(int *a, int n){
    int flag = 1;
    int t;    
    int i, j;
    int temp = 0;
    i = 0;
    while(flag){
        flag = 0;
        for(j = n - 1; j > i; j--) {
            if(*(a + j - 1) > *(a + j)){
                t = *(a + j);
                *(a + j) = *(a + j - 1);
                *(a + j - 1) = t;
                flag = 1;
                temp++;
            }
        }
        i++;
    }
    for(i = 0; i < n - 1; i++){
        printf("%d ", *(a + i));
    }
    printf("%d\n", *(a + n - 1));
    printf("%d\n", temp);
}


Measured memory_bytes: 2100
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
l1 = 0

for i in range(n):
    l1 += a[i] 
    if l1> s//2:break
r1 = s - l1
l2 = l1 -a[i]
r2 = s - l2
ans = min(abs(r1-l1),abs(r2-l2))
print(ans)

Measured memory_bytes: 87760
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int k;
  vector<lli> a(5);
  rep(i,0,5)cin>>a.at(i);
  cin>>k;
  rep(i,0,4){
    rep(j,i+1,5){
      if(a.at(j)-a.at(i)>k){
        ou(":(");
        return 0;
      }
    }
  }
  ou("Yay!");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<(a); i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pow2(x) (1ll<<(x))
 
using namespace std;
 
const int Mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int n;
	string s,t;
	cin >> n >> s >> t;
	string str;
	loop(n){
		str+=s[i];
		str+=t[i];
	}
	cout << str << "\n";
	return 0;
}


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

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


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

bool calculate(string numbers, int goal, string &result) {
  if (numbers.size() == 1) {
    if (stoi(numbers) == goal) {
      result = numbers;
      return true;
    }
    return false;
  }

  int length = numbers.size();
  string sub = numbers.substr(0, length - 1);
  char c = numbers.at(length - 1);
  int target = stoi(""s + numbers.at(length - 1));

  if (calculate(sub, goal - target, result)) {
    result += "+"s + numbers.at(length - 1);
    return true;
  }
  if (calculate(sub, goal + target, result)) {
    result += "-"s + numbers.at(length - 1);
    return true;
  }

  return false;
}

int main() {

  string numbers;
  cin >> numbers;

  string result = "";

  if (calculate(numbers, 7, result)) {
    cout << result + "=7" << endl;
  } else {
    cout << "ERROR" << endl;
    cout << numbers << endl;
    cout << result << endl;
  }
}


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

int a[205];

int read()
{
	int sum = 0, flag = 1;
	char c = getchar();
	for (; c < '0' || c > '9' ; c = getchar() )
	 if ( ! (c ^ '-' ) ) flag = -1;
	for (; c >= '0' && c <= '9' ; c = getchar() )
	 sum = (sum << 3) + (sum << 1) + (c ^ 48);
	return sum * flag;
}

int n = read() << 1;

int main()
{
	for (int i = 1; i <= n ; i ++)
	 a[i] = read();
	sort(a + 1, a + n + 1);
	int ans = 0;
    for (int i = 1; i <= n ; i += 2)
     ans += min(a[i], a[i + 1]);
    printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256