akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
a=[]
for _ in range(n):a.append(tuple(list(map(int,input().split()))[::-1]))
a.sort(reverse=1)
x,y=[],[]
s=set()
for i in range(k):
  d,t= a[i]
  if t in s:
    x.append(d)
  else:
    y.append(d)
    s.add(t)
xx,yy,v=sum(x),sum(y),len(y)
ans=xx+yy+v**2
for i in range(k,n):
    if len(x)==0:break
    d,t=a[i]
    if t in s:continue
    s.add(t)
    xx-=x.pop()
    yy+=d
    v+=1
    ans=max(ans,xx+yy+v**2)
print(ans)

Measured memory_bytes: 19764
// finish date: 2018/07/07
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector <vector<int>> vvi;
typedef vector <vector<vector < int>>>
vvvi;
typedef vector <ll> vl;
typedef vector <vector<ll>> vvl;
typedef vector<double> vd;
typedef vector <vector<double>> vvd;
typedef vector <vector<vector < double>>>
vvvd;
typedef vector<bool> vb;
typedef vector <vector<bool>> vvb;
typedef vector <string> vs;
typedef vector<char> vc;
typedef vector <vector<char>> vvc;
typedef pair<int, int> pii;
const int bigmod = 1000000007;
const int INF = 1050000000;


int main() {
    int a,b;
    cin>>a>>b;
    if(a+b==15){
        cout<<"+"<<endl;
    }else if(a*b==15){
        cout<<"*"<<endl;
    }else{
        cout<<"x"<<endl;
    }


    return 0;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 10000000099
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N+2), B(N+2), C(N+2);
  rep(i, N){
    cin >> A.at(i);
  }
  A.at(N) = 0;
  A.at(N+1) = INF;
  rep(i, N){
    cin >> B.at(i);
  }
  B.at(N) = 0;
  B.at(N+1) = INF;
  rep(i, N){
    cin >> C.at(i);
  }
  C.at(N) = 0;
  C.at(N+1) = INF;
  sort(all(A));
  sort(all(B));
  sort(all(C));
  ll ans = 0;
  rep2(i, 1, N+1){
    ll l = 0;
    ll r = N+1;
    // A.at(l) < B.at(i) <= A.at(r)
    while(r-l>1){
      ll c = (l+r)/2;
      if(A.at(c) < B.at(i)){
        l = c;
      }
      else{
        r = c;
      }
    }
    ll l2 = 0;
    ll r2 = N+1;
    // C.at(l2) <= B.at(i) < C.at(r2)
    while(r2-l2 > 1){
      ll c2 = (l2 + r2) / 2;
      if(C.at(c2) <= B.at(i)){
        l2 = c2;
      }
      else{
        r2 = c2;
      }
    }
    ans += l * (N-r2+1);
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main() {
    int x,y;
    cin>>x>>y;
    for(int i = 0;i < x+1;++i) {
        if(2*i+4*(x-i)==y){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3588
import sys
input = sys.stdin.readline
H, W, M = map(int, input().split())
bombs = []
rows = [[]for _ in range(H)]
cols = [[]for _ in range(W)]
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    bombs.append((h, w))
    rows[h].append(w)
    cols[w].append(h)

max_row = 0
row_idx = set()
for i, row in enumerate(rows):
    if max_row < len(row):
        max_row = len(row)
        row_idx = {i}
        continue
    elif max_row == len(row):
        row_idx.add(i)

max_col = 0
col_idx = set()
for i, col in enumerate(cols):
    if max_col < len(col):
        max_col = len(col)
        col_idx = {i}
        continue
    elif max_col == len(col):
        col_idx.add(i)

ans = max_row+max_col
points = len(row_idx)*len(col_idx)
if M < points:
    print(ans)
else:
    for i, j in bombs:
        if i in row_idx and j in col_idx:
            points -= 1
    if points == 0:
        print(ans-1)
    else:
        print(ans)


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

money = 1000
stock = 0

for i in range(N):
    if i == N - 1:
        money += stock * A[i]
        break
    if A[i] < A[i + 1]:
        stock += money // A[i]
        money %= A[i]
    elif A[i] > A[i + 1]:
        money += A[i] * stock
        stock = 0

print(money)


Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define int long long


using namespace std ;

const int N = 3005 ;
int dp[N][N] ;

signed main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;

    string s ,t ;
    cin >> s >> t ;
    int n = s.size() ;
    int m = t.size() ;
    string res = "" ;

    for(int i = 1 ; i <= n ; ++i)
    {
        for(int j = 1 ; j <= m ; ++j)
        {
            if(s[i-1] == t[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1] ;

            }
            else
            {
                dp[i][j] = max(dp[i][j-1] , dp[i-1][j]) ;
            }

        }
    }

    int i = n , j = m ;
    while(i > 0 && j > 0 )
    {
        if(s[i-1] == t[j-1])
        {
            res += s[i-1] ;
            i-- ;
            j-- ;
        }
        else if(dp[i-1][j] > dp[i][j-1])
        {
            i-- ;
        }
        else{
            j-- ;
        }
    }
    reverse(res.begin() , res.end()) ;
    cout << res << endl ;



}


Measured memory_bytes: 74008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        String str = obj.next();
        System.out.println((str.compareTo("ABC")==0)?"ARC":"ABC");
    }
}


Measured memory_bytes: 32608
s = int(input())
a = [s]
for i in range(1000000):
    if a[i]%2 == 0:
        an = int(a[i]/2)
    else:
        an = 3*a[i] + 1
    if an in a:
        print(i+2)
        break
    else:
        a.append(an)

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    string s;
    cin >> s;
    ll ans = 0;
    ll n = s.size();
    string last = "$";
    string cur = "";
    ll ans_ = 0;
    for(ll i = 0; i < n; i++) {
        cur += s[i];
        if(last != cur) {
            ++ans_;
            last = cur;
            cur = "";
        }
    }
    chmax(ans, ans_);
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

long long n, d, a;
long long ans = 0LL;
pair<long long, long long> monster[200200];
long long less_atk[200200];
long long now_atk = 0LL;

int main(){
	scanf("%lld%lld%lld", &n, &d, &a);
	rep(i, n) scanf("%lld%lld", &monster[i].first, &monster[i].second);
	sort(monster, monster+n);
	rep(i, n){
		now_atk -= less_atk[i];
		monster[i].second -= now_atk;
		if(monster[i].second <= 0) continue;
		long long more_bomb = (monster[i].second / a) + (bool)(monster[i].second % a);
		ans += more_bomb;
		now_atk += (1LL * a * more_bomb);
		int lb = i, ub = n;
		while(lb+1 < ub){
			int mid = lb + ub >> 1;
			if(monster[mid].first - d > monster[i].first + d) ub = mid;
			else lb = mid;
		}
		less_atk[ub] += (1LL * a * more_bomb);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N;
    cin >> N;
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ll a;
        cin >> a;
        for(;a % 2 == 0; a /= 2)ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(ll, a, b, c, k);
  cout << (k % 2 == 0 ? a - b : b - a) << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 14 21:11:42 2020

@author: Kanaru Sato
"""

h,w = list(map(int, input().split()))

if h == 1 or w == 1:
    ans = 1
else:
    if (h*w)%2 == 0:
        ans = (h*w)//2
    else:
        ans = (h*w+1)//2

print(int(ans))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	map<P,ll> fox;
	REP(i,n) {
		ll x,y,w;
		cin>>x>>y>>w;
		fox[P(x,y)]+=w;
	}
	ll ans=0;
	for(auto el: fox) {
		ll x,y; tie(x,y)=el.first;
		ll w=el.second;
		{
			ll buf=w;
			if(fox.count(P(x+1,y))) buf+=fox[P(x+1,y)];
			if(fox.count(P(x+1,y+1))) buf+=fox[P(x+1,y+1)];
			if(fox.count(P(x,y+1))) buf+=fox[P(x,y+1)];
			ans=max(ans,buf);
		}
		{
			ll buf=w;
			if(fox.count(P(x-1,y))) buf+=fox[P(x-1,y)];
			if(fox.count(P(x-1,y-1))) buf+=fox[P(x-1,y-1)];
			if(fox.count(P(x,y-1))) buf+=fox[P(x,y-1)];
			ans=max(ans,buf);
		}
		{
			ll buf=w;
			if(fox.count(P(x-1,y))) buf+=fox[P(x-1,y)];
			if(fox.count(P(x-1,y+1))) buf+=fox[P(x-1,y+1)];
			if(fox.count(P(x,y+1))) buf+=fox[P(x,y+1)];
			ans=max(ans,buf);
		}
		{
			ll buf=w;
			if(fox.count(P(x+1,y))) buf+=fox[P(x+1,y)];
			if(fox.count(P(x+1,y-1))) buf+=fox[P(x+1,y-1)];
			if(fox.count(P(x,y-1))) buf+=fox[P(x,y-1)];
			ans=max(ans,buf);
		}
	}
	cout<<ans<<" / 1"<<endl;
}




Measured memory_bytes: 9408
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

struct Edge {
  int to;
  i64 cost;

  Edge(int _to, i64 _cost) : to(_to), cost(_cost) {}
};

map<i64, int> PrimeFactor(i64 n) {
  map<i64, int> ret;
  for(i64 i = 2; i * i <= n; ++i) {
    if(n % i == 0 && !ret.count(i)) ret[i] = 0;
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

  i64 n, p;
  cin >> n >> p;

  auto mp = PrimeFactor(p);
  i64 ans = 1;
  for(auto &it : mp) {
    int i = it.second / n;
    while(i--) {
      ans *= it.first;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <assert.h>
//#include <bits/stdc++.h>

#define ll long long

using namespace std;


int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    
    int endA = 0;
    int staB = 0;
    int BA = 0;
    
    int ret = 0;
    
    for(int i = 0 ; i < n ; ++i){
        string x;
        cin >> x;
        int sz = (int)x.size();
        for(int j = 0; j + 1 < sz; ++j){
            if(x[j] == 'A' && x[j + 1] == 'B')
                ++ret;
        }
        if(x[0] == 'B' && x[sz - 1] == 'A')
            ++BA;
        else
        if(x[0] == 'B')
            staB++;
        else
        if(x[sz - 1] == 'A')
            endA++;
    }
    if(BA){
        ret += (BA - 1);
        if(endA){
            ++ret;
            endA--;
        }
        if(staB){
            ++ret;
            --staB;
        }
        ret += min(staB, endA);
    } else {
        ret += min(staB, endA);
    }
    cout << ret;
}


Measured memory_bytes: 256
let ans n s =
  let rec f i x m =
    if i = n then m
    else if s.[i] = 'I' then f (i+1) (x+1) (max m (x+1))
    else f (i+1) (x-1) m
  in f 0 0 0

let () = Scanf.scanf "%d\n%s" (fun n s -> print_int (ans n s))


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

void Main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	sort(A.begin(), A.end(), [](const int x, const int y) { return abs(x) > abs(y);});
	ll res = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] >= 0) {
			res += (ll)A[i];
			continue;
		}
		if (i + 1 != N) {
			A[i] = -A[i];
			res += (ll)A[i];
			A[i + 1] = -A[i + 1];
			continue;
		}
		res += (ll)A[i];
	}
	cout << res << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      //int w,h,tmp;
      string s,t;
      cin >> s;
      int ans = 0;
      t = "CODEFESTIVAL2016";
      for(int i=0; i<s.size(); i++)
        if(s.at(i)==t.at(i)) ans++;
     
      cout << 16-ans << endl;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    int ans = a+b;
    if(ans >= 24) ans-=24;
    cout << ans << endl;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -Wall #-}

readInt :: String -> Int
readInt = read

solve :: [Int] -> Int
solve a = maximum b
    where
        b    = zipWith (-) (tail a) mins
        mins = scanl1 min a

main :: IO ()
main = do
    _ <- fmap readInt getLine
    a <- fmap (map readInt . words) getContents
    let ans = solve a
    print ans



Measured memory_bytes: 149692
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll evaluate(int contest, int date, vector<ll>& last, vector<ll>& c, vll& s) {
    ll point_today = 0;
    point_today += s[date][contest];
    for (ll j = 1; j <= 26; j++) {
        if(j==date){
            continue;
        }
        point_today -= c[contest] * (date - last[contest]);
    }
    return point_today;
}

int main(){
  ll d;
  cin >> d;//全日数
  vl c(27);
  for(ll i=1;i<=26;i++){//c_i==c[i]
    cin >> c[i];
  }
  vll s(d + 1, vl(27)); //s_d,i==s[d][i]
  for (ll i = 1; i <= d; i++){
    for (ll j = 1; j <= 26;j++){
      cin >> s[i][j];
    }
  }
  vl t;
  vl last(27, 0);//last(d,i)==last[i]
  //ll satisfy = 0;
  for (ll date = 1; date <= d;date++){
    priority_queue<pair<ll, int>> q;
    for (ll contest = 1; contest <= 26;contest++){
      q.push(mp(evaluate(contest, date, last,c,s), contest));
    }
    t.pb(q.top().S);
    //satisfy += q.top().F;
    last[q.top().S] = date;
  }
  rep(i,d){
    print(t[i]);
  }
}

Measured memory_bytes: 3740
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long sum=0;
		int i=0;
		long count =0;
		long beforeCount =0;
		while (i<S.length()) {
			count =0;
			if (S.charAt(i)=='<') {
				while(i<S.length()&&S.charAt(i)=='<') {
					i++;
					count++;
				}
				sum +=count*(count+1)/2;
				beforeCount = count;
			} else if (S.charAt(i)=='>') {
				while(i<S.length()&&S.charAt(i)=='>') {
					i++;
					count++;
				}
				if (beforeCount<count) {
					sum +=count*(count+1)/2-beforeCount;
				} else {
					sum +=count*(count-1)/2;
				}
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 29336
N, M, Q = map(int, input().split())  #数字
Q = [list(map(int, input().split())) for i in range(Q)]  #数字複数列、複数行

import itertools
A = []
for i in itertools.combinations_with_replacement(range(M),N):
    score = 0
    for j in range(len(Q)):
        if i[Q[j][1]-1] - i[Q[j][0]-1] == Q[j][2]:
            score += Q[j][3]
        A.append(score)

print(max(A))

Measured memory_bytes: 73924
n = int(input())
tlm = [tuple(map(int, input().split())) for _ in range(n)]
# time/limit

tlm.sort(key=lambda x: x[1])

flg = True
cur = 0
for t, lm in tlm:
    cur += t
    if cur > lm:
        flg = False
        break

print('Yes' if flg else 'No')


Measured memory_bytes: 31884
import math
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    X = int(input())
    a = math.gcd(X, 360)
    a = X * 360 // a
    print(a // X)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int flag=0;
  for(int i=0;i<s.size()-1;i++)
    if(s.at(i)=='A' && s.at(i+1)=='C')flag++;
  if(flag==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
fn main() {
    let s = read::<String>();
    for c in s.chars() {
        if c == '7' {
            println!("Yes");
            return;
        }
    }

    println!("No");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 2156
#include <iostream>

#include <vector>

#include <algorithm>
#include <functional>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

using std::greater;
using std::sort;

static long long
solve(int N, int K, vector<int> &H)
{
  if (N <= K)
  {
    return 0;
  }
  sort(H.begin(), H.end(), greater<int>());
  long long ret = 0;
  for (int n = K; n < N; n++)
  {
    ret += H[n];
  }
  return ret;
}

int
main()
{
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (int n = 0; n < N; n++)
  {
    cin >> H[n];
  }
  cout << solve(N, K, H) << endl;  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
#define print(a) cout << a << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,bottom,fin,l,tot=0;cin>>n;
  string s;
  vector<P> pos,neg;
  rep(i,n) {
    cin>>s;
    bottom=0,fin=0,l=s.length();
    rep(j,l) {
      if(s[j]=='(') fin++;
      else fin--;
      bottom=min(bottom,fin);
    }
    if(fin>=0) pos.emplace_back(P(bottom,fin));
    //else neg.emplace_back(P(bottom,fin));
    else neg.emplace_back(P(bottom-fin,-fin));
    tot+=fin;
  }
  sort(RALL(pos));sort(RALL(neg));
  bool isok=true;
  ll start=0;
  for(P p:pos) {
    if(start+p.first<0) {isok=false;break;}
    start+=p.second; 
  }
  start=0;
  for(P p:neg) {
    if(start+p.first<0) {isok=false;break;}
    start+=p.second;
  }
  if(isok&&tot==0) puts("Yes");else puts("No");
  return 0;
}

Measured memory_bytes: 19048
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	char name[21];
	int length;
};

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int main(){

	int N,cost[14][14],limit,count,tmp,ans,next_state,num_town;
	int** dp = new int*[14];
	for(int i = 0; i < 14; i++){
		dp[i] = new int[16384];
	}

	Info first_info[14],info[14];
	bool FLG,part_sentence[14];

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i < N; i++){
			scanf("%s",first_info[i].name);
			for(first_info[i].length = 0; first_info[i].name[first_info[i].length] != '\0';first_info[i].length++);
		}

		for(int i = 0; i < 14;i++)part_sentence[i] = false;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i != k && first_info[i].length <= first_info[k].length){
					for(int left = 0; first_info[k].length-left >= first_info[i].length;left++){
						FLG = true;

						for(int a = 0; a < first_info[i].length; a++){
							if(first_info[i].name[a] != first_info[k].name[left+a]){
								FLG = false;
								break;
							}
						}

						if(FLG){
							part_sentence[i] = true;
							break;
						}
					}

				}
			}
		}

		num_town = 0;

		for(int i = 0; i < N; i++){
			if(part_sentence[i] == false){
				strcpy(info[num_town].name,first_info[i].name);
				info[num_town].length = first_info[i].length;
				num_town++;
			}
		}

		N = num_town;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i == k)continue;

				count = 0;

				for(int left = 0; left < info[i].length;left++){
					FLG = true;
					for(int a = left; a < info[i].length && (a-left) < info[k].length;a++){
						if(info[i].name[a] != info[k].name[a-left]){
							FLG = false;
							break;
						}
					}
					if(FLG){
						count = info[i].length-left;
						break;
					}
				}

				cost[i][k] = count;
			}
		}

		limit = pow(2,N);

		for(int i = 0; i < N;i++){
			for(int k = 0; k < limit; k++){
				dp[i][k] = BIG_NUM;
			}
		}

		for(int i = 0; i < N; i++){
			tmp = pow(2,i);
			dp[i][tmp] = info[i].length;
		}

		for(int state = 0; state <= limit-2; state++){
			for(int k = 0; k < N; k++){
				if(dp[k][state] == BIG_NUM)continue;
				for(int a = 0; a < N; a++){
					if(state & (1 << a)){
						//Do nothing
					}else{
						next_state = state + pow(2,a);
						dp[a][next_state] = min(dp[a][next_state],dp[k][state] + info[a].length - cost[k][a]);
					}
				}
			}
		}

		ans = BIG_NUM;
		for(int i = 0; i < N; i++){
			ans = min(ans,dp[i][limit-1]);
		}

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

	return 0;
}

Measured memory_bytes: 3688
import java.io.IOException;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			r = scanner.nextInt();
			if (r == 0)
				break;
			map = new int[2][250001];
			for (int[] ma : map)
				Arrays.fill(ma, 1 << 30);
			map[0][0] = map[1][0] = 0;
			for (int i = 0; i < 2; i++) {
				w = scanner.nextInt();
				h = scanner.nextInt();
				sx = scanner.nextInt() - 1;
				sy = scanner.nextInt() - 1;
				int[][] m = new int[h][w];
				for (int j = 0; j < h; j++)
					for (int k = 0; k < w; k++)
						m[j][k] = scanner.nextInt();
				slove(m, i);
			}
			int res = 1 << 30;
			for (int i = 0; i <= r; i++) {
				res = Math.min(res, map[0][i] + map[1][r - i]);
			}
			System.out.println(res);
		}
	}

	private void slove(int[][] m, int i) {
		boolean[][] b = new boolean[h][w];
		int id = 1;
		int l = -1;
		b[sy][sx] = true;
		int a = h * w - 1;
		PriorityQueue<Point> pq = new PriorityQueue<Point>();
		pq.offer(new Point(m[sy][sx], sy, sx));
		while (!pq.isEmpty()) {
			Point point = pq.poll();
			l = Math.max(l, point.k);
			map[i][id++] = l;
			if(a==0){
				continue;
			}
			for (int[] mo : move) {
				int ny = point.y + mo[0];
				int nx = point.x + mo[1];
				if (!isOK(ny, nx))
					continue;
				if (b[ny][nx])
					continue;
				b[ny][nx] = true;
				a--;
				pq.offer(new Point(m[ny][nx], ny, nx));
			}
		}
	}

	private boolean isOK(int ny, int nx) {
		if (0 <= ny && ny < h && 0 <= nx && nx < w)
			return true;
		return false;
	}
	int r, w, h, sx, sy;
	int[][] map;
	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

	class Point implements Comparable<Point> {
		int k, y, x;

		@Override
		public String toString() {
			return "Point [k=" + k + ", y=" + y + ", x=" + x + "]";
		}

		public Point(int k, int y, int x) {
			super();
			this.k = k;
			this.y = y;
			this.x = x;
		}

		@Override
		public int compareTo(Point o) {
			return this.k - o.k;
		}

	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    ll n,k,q; cin >> n >> k >> q;
    vector<int> a(n);
    rep(i,n) a[i] = k - q;
    rep(i,q){
        int A; cin >> A;
        a[A-1]++;
    }
    rep(i,n){
        if(a[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

int main(){
  int H,W;
  cin >> H >> W;
  string S[H];
  int cnt=0;
  for (int i=0;i<H;i++){
    cin >> S[i];
    for (int j=0;j<W;j++){
      if (S[i][j]=='#') cnt++;
    }
  }
  if (cnt!=H+W-1){
    cout << "Impossible" << endl;
    return 0;
  }
  int x=0;
  int y=0;
  while (S[y][x]=='#'){
    if(x!=W-1){
      if (S[y][x+1]=='#') x++;
      else y++;
    }
    else y++;
    if (y==H){
      cout << "Possible" << endl;
      return 0;
    }
  }
    if (x==H-1 and y==W-1){
      cout << "Possible" << endl;
      return 0;
    }
    else{
      cout << "Impossible" << endl;
      return 0;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include <math.h>
#include <stdlib.h>

#define N 10001

#define MAX 100000
#define SENTINEL 200000000

struct Node{
  char suit;
  int value;
};

struct Node L[MAX /2+2],R[MAX /2+2];

void merge(struct Node A[],int n,int left, int mid,int right){
  
  int i,j,k;
  
  int n1 = mid-left;
  
  int n2 = right-mid;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1].value =R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
    }
  }
}
void mergeSort(struct Node A[],int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Node A[],int n,int p,int r){
  int i,j;
  struct Node t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].value<=x.value){
      i++;
      t=A[i];A[i]=A[j];A[j]=t;
    }
  }
  t= A[i+1];A[i+1]=A[r];A[r]=t;
  return i+1;
}

void quickSort(struct Node A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(){
  int n,i,v;
  struct Node A[MAX], B[MAX];
  char c[10];
  int st=1;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s%d",c,&v);
    A[i].suit=B[i].suit=c[0];
    A[i].value=B[i].value=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].suit!=B[i].suit)st=0;
  }

  if(st==1){
    printf("Stable");
  printf("\n");}
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].suit,B[i].value);
  }
  return 0;
}



Measured memory_bytes: 4144
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
//#define int long long
#define ll long long
#define all(x) x.begin(),x.end()
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18

int h[100005];
int dp[100005];
int solve(int n, int i){
    if(i==n)
        return 0;
    int a=INT_MIN,b=INT_MIN;
    if(i+1<=n)
     a = solve(n,i+1);
     if(i+2<=n)
     b = solve(n,i+2);
    return min(a + abs(h[i]-h[i-1]),b+abs(h[i-1]-h[i+1]));

}

signed main(){
IOS;
int n;
cin>>n;
for(int i=1;i<=n;i++)
    cin>>h[i];

    dp[n]=0;
    for(int i=n-1;i>=1;i--){
        dp[i]=dp[i+1] + abs(h[i]-h[i+1]);
        if(i+2 <= n){
            dp[i]=min(dp[i],dp[i+2]+abs(h[i]-h[i+2]));
        }
    }
    cout << dp[1] <<endl;

 //cout << solve(n,1);
return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long n;
char c[200005];
int w[200005];
int main(){
	cin>>n;
	int sum=0;
	memset(w,0x3f3f3f3f,sizeof(w));
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(c[i]=='W')w[++sum]=i;
	}
	int ans=0;
	int point=1;
	for(int i=n;i>=1;i--){
		if(c[i]=='R'&&i>w[point]){
			swap(c[i],c[w[point]]);
			point++;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

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

int main(){

    int N;
    cin >> N;

    
    int H[N];
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    if(N==1){
        cout << "Yes" <<endl;
        return 0;
    }
    int D[N];
    int m=H[0]-1;
    for(int i=0;i<N;i++){
        if(m>H[i]){
            cout << "No" <<endl;
            return 0;
        }
        m=max(H[i]-1,m);
    }

    cout << "Yes" <<endl;

    return 0;
}

Measured memory_bytes: 640
//Name: Baumkuchen
//Level: 3
//Category: 最小値の最大化,累積和,二分探索
//Note: 

/**
 * 一切れの大きさの下限について二分探索する。
 *
 * 下限をひとつ決め、更に切断する切れ込みをひとつ決めると、この切れ込みを端にもつ2つの切れ端について、
 * もう一方の端をどこにするかは累積和上の二分探索で求められる。
 * もう一方の端をどちらも下限ギリギリになるように取ったとき、これらが交差しておらず、かつ3つ目の切れ端も下限を超えていれば、その下限は達成できる。
 *
 * 円周上の累積和をうまく扱うため、数列を3回繰り返したものの上で考えるとよい。
 * オーダーは O(N (log N)^2)。
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool solve(bool first) {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<long long> as(1+3*N);
    as[0] = 0; // sentinel
    for(int i = 1; i <= N; ++i) {
        cin >> as[i];
        as[N+i] = as[N*2+i] = as[i];
    }
    for(int i = 1; i < 1+3*N; ++i) {
        as[i] += as[i-1];
    }

    long long sum = as[N];
    long long left = 0, right = sum / 3 + 10;
    while(left+1 < right) {
        const long long c = (left + right) / 2;
        // Separate between m-1 and m
        bool ok = false;
        for(int m = N+1; m <= 2*N; ++m) {
            const auto it = begin(as) + m;
            auto lit = lower_bound(it-N, it, as[m-1] - c);
            auto rit = lower_bound(it, it+N, as[m-1] + c);
            if(as[m-1] - *lit < c) {
                --lit;
            }
            if(rit == it+N) goto next;
            if(rit - lit >= N) goto next;
            if(sum - (*rit - *lit) < c) goto next;
            ok = true;
            break;
next:
            ;
        }
        if(ok) {
            left = c;
        } else {
            right = c;
        }
    }
    cout << left << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

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

int main(){
  string s,t;
  cin >> s;
  cin >> t;
  bool ok = true;
  for(int i=0; i<s.size(); i++)
    if(s[i] != t[i])
      ok = false;
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3604
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors
def examA():
    M, D = LI()
    c = D//10
    ans = 0
    for i in range(2,M+1):
        d = make_divisors(i)
#        print(d)
        for j in range(len(d)//2):
            cur0 = d[j*2+1]; cur10 = d[j*2]
            if cur10==1:
                continue
            if cur0<=9:
                if cur10<c:
                    ans +=1
#                    print(cur10,cur0)
                elif cur10==c and cur0+cur10*10<=D:
                    ans +=1
#                    print(cur10,cur0)
        for j in range(len(d) // 2):
            cur0 = d[j * 2];cur10 = d[j * 2+1]
            if cur0 == 1:
                continue
            if cur10 <= 9:
                if cur10 < c:
                    ans += 1
                elif cur10 == c and cur0 + cur10 * 10 <= D:
                    ans += 1
        if len(d)%2==1:
            cur0 = d[-1]; cur10 = d[-1]
            if cur10==1:
                continue
            if cur0<=9:
                if cur10<c:
                    ans +=1
#                    print(cur10,cur0)
                elif cur10==c and cur0+cur10*10<=D:
                    ans +=1
#                    print(cur10,cur0)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()


Measured memory_bytes: 38384
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
    long long key,i,h;
    key=getKey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0) return 1;
        else if(strlen(H[h])==0) return 0;
    }return 0;
}

int insert(char str[]){
    long long key,i,h;
    key=getKey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0) return 1;
        else if(strlen(H[h])==0){
            strcpy(H[h],str);
            return 0;
        }
    }return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	    scanf("%s %s", com, str);
	
	    if ( com[0] == 'i' ){
	        insert(str);
	    } 
        else {
	        if (find(str)){
		        printf("yes\n");
	        } 
            else {
		        printf("no\n");
	        }
	    }
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 100100100;

int main(){
  ll n;
  cin >> n;
  if(n%2 != 0){
    cout << 0 << endl;
    return 0;
  }
  ll count = 0;
  while(n>=10){
    count += n/10;
    n /= 5;
  }
  cout << count << endl;
  return 0;
} 

Measured memory_bytes: 256
N, K, Q = gets.split.map &:to_i
A = (1..Q).map{gets.to_i}
# p [N, K, Q], A

if K > Q
	N.times{puts "Yes"}
	exit
end

points = Array.new(N, 0)

A.each{|x| # O(Q)
	points[x-1] += 1
}
points.each{|x|
	if K + x - Q > 0
		puts "Yes"
	else
		puts "No"
	end
}

Measured memory_bytes: 4148
require "set"
n, m = gets.split.map(&:to_i)

hash = {}
(1..n).each {|i| hash[i] = [] }
m.times do
  a, b = gets.split.map(&:to_i)
  hash[a] << b
  hash[b] << a
end

set = Set.new
count = 0
hash.keys.each do |num|
  next if set.include?(num)

  arr = hash[num]
  count += 1
  queue = [] + arr
  while !queue[0].nil?
    nn = queue.shift
    set << nn
    hash[nn]&.each do |mm|
      queue << mm if !set.include?(mm)
    end
  end
end
puts count - 1


Measured memory_bytes: 35036
n, m = map(int, input().split())
dp = [float("inf") for i in range(1 << n)]
dp[0] = 0
for i in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    bit = 0
    for j in range(b):
        bit |= 1 << (c[j] - 1)
    for j in range(1 << n):
        dp[j | bit] = min(dp[j | bit], dp[j] + a)
if dp[-1] == float("inf"):
    print("-1")
else:
    print(dp[-1])

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<vector<int>> Graph; //隣接行列でグラフを表現

int main()
{
    ll N, M;
    cin >> N >> M;

    Graph G(N);
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    vector<int> dist(N, -1);
    vector<int> prev_room(N, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty())
    {
        int vertex = que.front();
        que.pop();

        for (int next_vertex : G[vertex])
        {
            if (dist[next_vertex] != -1) continue;

            dist[next_vertex] = dist[vertex] + 1;
            prev_room[next_vertex] = vertex;
            que.push(next_vertex);
        }
    }
    cout << "Yes" << endl;

    for (int i = 1; i < N; ++i) cout << prev_room[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 10632
# 左子右兄弟表現(一番左の子と、自分の右隣の兄弟へのリンクを持つ)
class TreeNode
	attr_accessor :parent, :left_child, :right_sibling, :depth

	def type
		return "root" unless @parent
		return "leaf" unless @left_child
		"internal node"
	end

	# stack overflow
	# def self.set_depth(nodes, id, depth)
	# 	nodes[id].depth = depth
	# 	if nodes[id].right_sibling
	# 		set_depth(nodes, nodes[id].right_sibling, depth)
	# 	end
	# 	if nodes[id].left_child
	# 		set_depth(nodes, nodes[id].left_child, depth + 1)
	# 	end
	# end

	def self.depth(nodes, id)
		depth = 0
		while nodes[id].parent
			id = nodes[id].parent
			depth += 1
		end
		depth
	end

	def self.description(nodes, id)
		node = nodes[id]
		children_id_list = []

		child_id = node.left_child
		while child_id
			children_id_list << child_id
			child_id = nodes[child_id].right_sibling
		end

		desc  = "node #{id}: "
		desc += "parent = #{node.parent ? node.parent : -1}, "
		desc += "depth = #{TreeNode.depth(nodes, id)}, "
		desc += "#{node.type}, "
		desc += "[#{children_id_list.join(", ")}]"
	end
end

# 木全体を配列で管理する, indexがidと紐づく
n = STDIN.gets.to_i
nodes = []
n.times { nodes << TreeNode.new }

n.times.each do |i|
	id, degree, *children = STDIN.gets.split.map(&:to_i)

	prev = nil
	children[0...degree].each_index do |j|
		child = children[j]

		if j == 0
			nodes[id].left_child = child
		else
			nodes[prev].right_sibling = child
		end

		prev = child
		nodes[child].parent = id
	end
end

nodes.each_index { |id| puts TreeNode.description(nodes, id) }

Measured memory_bytes: 25084
import java.util.Scanner;

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

    public Main() {
        Scanner sc = new Scanner(System.in);
        int aStart = Integer.parseInt(sc.next());
        int aEnd = Integer.parseInt(sc.next());
        int bStart = Integer.parseInt(sc.next());
        int bEnd = Integer.parseInt(sc.next());
        int start = Math.max(aStart, bStart);
        int end = Math.min(aEnd, bEnd);
        int intersection = Math.max(0, end - start);
        System.out.println(intersection);
    }
}


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

int main(void){
    int n, x[100010], cnt=1;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> x[i];
    }
    sort(x, x+n);
    for(int i=1;i<n;++i){
        if(x[i]!=x[i-1]) ++cnt;
    }
    cout << cnt << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 2);
  for (int i = 1; i <= N; i++) cin >> A[i];
  int all_money = 0;
  for (int i = 0; i <= N; i++) all_money += abs(A[i] - A[i + 1]);
  for (int i = 1; i <= N; i++)
    cout << all_money - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) +
    abs(A[i - 1] - A[i + 1]) << endl;
}

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

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

  int N; cin >> N;
  vector<ll> X(N), L(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> L[i];
  }
  vector<pair<int, int>> P(N);
  for (int i = 0; i < N; i++) {
    P[i] = make_pair(X[i] + L[i] - 1, X[i] - L[i]);
  }
  sort(P.begin(), P.end());

  ll ans = 0, p = -1e15;
  for (int i = 0; i < N; i++) {
    if (p < P[i].second) {
      ans++;
      p = P[i].first;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <queue>
using namespace std;
priority_queue<long long> pq;
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		long long p;
		cin>>p;
		pq.push(p);
	}
	for(int i=1;i<=m;i++){
		long long T=pq.top()/2;
		pq.pop();
		pq.push(T);
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		long long T=pq.top();
		ans+=T;
		pq.pop();
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 1400
#define ll long long int
#include <bits/stdc++.h>

using namespace std;


int main()
 {
//code
         ll i,j,k;string s,t;
         cin>>s>>t;
         ll m=s.length(),n=t.length();
         ll dp[m+1][n+1];
         for(i=0;i<m+1;i++)
         {
         	for(j=0;j<n+1;j++)
         	{
         		if(i==0||j==0)
         		dp[i][j]=0;
         		else if(s[i-1]==t[j-1])
                 dp[i][j]=dp[i-1][j-1]+1;
				 else
				  dp[i][j]=max(dp[i-1][j],dp[i][j-1]);         		
			}
		 }
		 
		 ll l=dp[m][n];
		 
		 char st[l+1];
		 i=m;j=n;
		 st[l] = '\0';
		 while(i>0&&j>0)
		 {
		 	if(s[i-1]==t[j-1])
		 	{
		 	 st[l-1]=s[i-1];i--;j--;l--;   	
			}
			else if(dp[i-1][j]>dp[i][j-1])
			{
				i--;
			}
			else
			{
				j--;
			}
		 }
		 cout<<st;
		 
}




Measured memory_bytes: 70656
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,L[1000]={0},sum=0,MAX=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>L[i];
        MAX=max(L[i],MAX);
        sum=sum+L[i];
    }
    if(MAX<(sum-MAX)) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
graph = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = map(int, readline().split())
    graph[a].append(b)
    graph[b].append(a)


def dfs(s):
    from collections import deque
    check = [0] * (n + 1)
    stack = deque([s])
    check[s] = 0
    while stack:
        now = stack.pop()
        for next in graph[now]:
            if check[next] != 0 and next != n:
                continue
            if next == n and check[now] == 1:
                print('POSSIBLE')
                exit()
            check[next] += check[now] + 1
            stack.appendleft(next)


dfs(1)
print('IMPOSSIBLE')


Measured memory_bytes: 40420
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] i = sc.nextLine().split(" ");
		int w = Integer.parseInt(i[0]);
		int h = Integer.parseInt(i[1]);
		int x = Integer.parseInt(i[2]);
		int y = Integer.parseInt(i[3]);
		int r = Integer.parseInt(i[4]);

		if (x - r < 0 || x + r > w || y - r < 0 || y + r > h) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 26232
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	var n, X, x int
	fmt.Scan(&n)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
		X += a[i]
	}
	ans := 10000000000
	for i := 0; i < n; i++ {
		x += a[i]
		if i+1 < n { // 少なくともお互い1枚はとる必要がある。
			ans = min(ans, abs(X-2*x))
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3584
fun main(args: Array<String>) = p5()

fun p5() {
    val (a, b, c, x, y) = readLine()!!.split(' ').map { it.toLong() }

    var answer = Int.MAX_VALUE.toLong()

    for (abPizza in 0..2000000) {
        answer = Math.min(answer, c * abPizza + a * Math.max(x - abPizza / 2, 0) + b * Math.max(y - abPizza / 2, 0))
    }

    println(answer)
}


Measured memory_bytes: 38424
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
long long n,a[100005],b[100005],p,pre;
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for (int i=n-1;i>=0;i--){
		long long v=(a[i]+pre)%b[i];
		if (v==0) v=b[i];
		pre+=b[i]-v;
	}
	cout<<pre;
	return 0;
} 

Measured memory_bytes: 1792
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::HashSet;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    mut s: [i64; 5],
    }

    for (i, &v) in s.iter().enumerate() {
        if v == 0 {
          println!("{}", i + 1);
          return;
        }
    }
}


Measured memory_bytes: 2080