akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

bool prime[1000001];
int mas[1004][1004];
pair< int, int > dp[1004][1004];
int v[1004][1004], now;
int px[1000001], py[1000001];
const int vy[] = {0, -1, 0, 1}, vx[] = {1, 0, -1, 0};
pair< int, int > result[114514];

pair< int, int > rec(int x, int y)
{
  if(mas[y][x] == 0) return (make_pair(0, 0));
  if(v[x][y] == now) return (dp[x][y]);
  pair< int, int > ret(0, 0);
  for(int nx = x - 1; nx <= x + 1; nx++) {
    ret = max(ret, rec(nx, y + 1));
  }
  if(!prime[mas[y][x]]) {
    if(ret.second == 0) ret.second = mas[y][x];
    ret.first++;
  }
  v[x][y] = now;
  return(dp[x][y] = ret);
}
int main()
{
  prime[1] = 1;
  for(int i = 2; i * i < 1000001; i++) {
    if(prime[i] == 0) {
      for(int j = i + i; j < 1000001; j += i) prime[j] = 1;
    }
  }
  vector< tuple< int, int, int > > query;
  for(int i = 0; ; i++) {
    int n, m;
    scanf("%d %d", &n, &m);
    if(n == 0) break;
    query.emplace_back(n, m, i);
  }
  sort(begin(query), end(query));

  int shake = 1, x = 501, y = 501, a = 3;
  for(auto& k : query) {
    int n, m, idx;
    tie(n, m, idx) = k;
    now = idx;
    for(int i = shake; i <= n; i++) {
      mas[y][x] = i;
      px[i] = x, py[i] = y;
      if(mas[y + vy[(a + 1) % 4]][x + vx[(a + 1) % 4]] == 0) a = (a + 1) % 4;
      y += vy[a], x += vx[a];
    }
    shake = n + 1;
    result[idx] = rec(px[m], py[m]);
  }
  for(int i = 0; i < query.size(); i++) {
    printf("%d %d\n", get< 0 >(result[i]), get< 1 >(result[i]));
  }
}

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

int main() {

	int h1, h2, k1, k2, a, b, c, d, n, m;

	cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;

	n = a * h1 + b * h2 + c * (h1 / 10) + d * (h2 / 20);
	m = a * k1 + b * k2 + c * (k1 / 10) + d * (k2 / 20);
	if(n > m) 
		cout << "hiroshi" << endl;
	else if (n < m)
		cout << "kenjiro" << endl;
	else
		cout << "even" << endl;

	return 0;
}


Measured memory_bytes: 3124
PROGRAM ATCODER

implicit none
integer(16) :: n,i,ans
integer(16),allocatable :: a(:)

read*, n
allocate(a(n))
read*, a(1:n)

call hs(n,a)

do i = n-1, 0, -2
  if ( i == 0 ) then
    if ( a(1) /= 0 ) then
      print'(i0)', 0
      stop
    end if
    exit
  end if
  if ( 2*i /= a(i)+a(i+1) ) then
    print'(i0)', 0
    stop
  end if
end do

ans = 1
do i = 1, n/2
  ans = mod(ans*2,10**9+7)
end do

print'(i0)', ans 

contains
!!!!!! サブルーチンは↓
subroutine hs(n,array)
  implicit none
  integer(16),intent(in)::n
  integer(16),intent(inout)::array(1:n)
  
  integer(16)::i,k,j,l,m
  integer(16)::t
  
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return
 
  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(l)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
 
  return
end subroutine hs
!!!!!!

END PROGRAM ATCODER

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    int N; cin >> N;
    map<ll, ll> mp;

    repr(i, 2, N+1){
        int T = i;
        for(ll j=2; j*j<=T; ++j){
            if(T%j == 0){
                while(T%j == 0){
                    ++mp[j];
                    T /= j;
                }
            }
        }
        if(T != 1) ++mp[T];
    }

    ll ans = 1;
    for(auto itr=mp.begin(); itr!=mp.end(); ++itr){
        ans *= (itr->second+1);
        chmod(ans);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m; cin >> n >> m;
	vi done(n), wa(n);
	rep(i, m){
		int k; string s; cin >> k >> s; k--;
		if(done[k]) continue;
		if(s == "WA") wa[k]++;
		else done[k] = 1;
	}
	int ans = 0;
	rep(i, n) if(done[i]) ans += wa[i];
	cout << accumulate(all(done), 0) << " " << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
// order_of_key and *find_by_order
int32_t main()
{
    fast;
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double w1 = 0.5;
    double pi = 3.14159265358;
    double w2 = 6;
    int t = h * 60 + m;
    double ana = w1 * t ;
    double anb = w2 * t ;
    while (ana > 360) {
        ana -= 360;
    }
    while (anb > 360) {
        anb -= 360;
    }
    double diff = abs(ana - anb);
    double ans = a * a + b * b - 2 * a * b * cos(pi * diff / 180);
    cout << setprecision(15) << sqrt(ans);




}

Measured memory_bytes: 4240
import java.util.Scanner;

public class Main {
    static long[][] dp;
    static long calculate(int i, int j, int[] a, long[] s){
        if(i >= j)
            return 0;
        if(dp[i][j] != 0)
            return dp[i][j];
        long min = Long.MAX_VALUE;
        for(int k = i+1; k <= j; k++){
            min = Math.min(min,calculate(i,k-1,a,s)+calculate(k,j,a,s)+s[j]-((i-1<0)?0:s[i-1]));
        }
        dp[i][j] = min;
        return min;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        dp = new long[n][n];
        int[] a = new int[n];
        long[] s = new long[n];
        long total = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            total += a[i];
            s[i] = total;
        }
        System.out.println(calculate(0,n-1,a,s));
    }
}


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

int n, k;
vector<int> b[10];
vector<int> v[10];

int dp[16][2020];

int dfs(int i = 0, int cnt = 0)
{
  if (i == 10) return 0;

  int &ret = dp[i][cnt];

  if (ret != -1) return ret;

  ret = dfs(i + 1, cnt);
  for (int j = 0; j < v[i].size(); j++){
    if (cnt + j + 1 > k) break;
    ret = max(ret, dfs(i + 1, cnt + j + 1) + v[i][j]);
  }

  return ret;
}

int main()
{
  memset(dp, -1, sizeof(dp));

  cin >> n >> k;
  for (int i = 0; i < n; i++){
    int c, d;
    cin >> c >> d;
    d--;
    b[d].emplace_back(c);
  }

  for (int i = 0; i < 10; i++){
    sort(b[i].begin(), b[i].end(), greater<int>());
  }

  for (int i = 0; i < 10; i++){
    for (int j = 1; j < b[i].size(); j++){
      b[i][j] += b[i][j - 1];
    }
  }

  for (int i = 0; i < 10; i++){
    for (int j = 0; j < b[i].size(); j++){
      v[i].push_back(b[i][j] + (j * j + j));
    }
  }

  for (int i = 0; i < 10; i++){
    for (auto j : v[i]) {
    }
  }

  cout << dfs() << endl;
}

Measured memory_bytes: 3280
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        if(R < 1200){
            System.out.println("ABC");
        }else if(R < 2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N;
    cin>>N;
    cout<<N*(N-1)/2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  int r, g, b, n;
  while (cin >> r >> g >> b >> n) {
    int result = 0;
    REP(i,n+1) REP(j,n+1) {
      ll rem = n - (r * i) - (g * j);
      if (rem < 0) continue;
      if (rem % b == 0) result++;
    }
    cout << result << endl;
  } 
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
	int H, W;
	cin >> H >> W;
	vector<string> C(H);
	for (int i = 0; i < H; ++i){
		cin >> C[i];
	}
	for (int i = 0; i < H; ++i){
		cout << C[i] << endl;
		cout << C[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var a = parseInt(input[0], 10);
  var b = parseInt(input[1], 10);
  var c = parseInt(input[2], 10);
  var d = parseInt(input[3], 10);

  var out = 0;

  if ( a < b ) {
    out += a;
  } else {
    out += b;
  }
  if ( c < d ) {
    out += c;
  } else {
    out += d;
  }

  console.log(out)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21192
#include <iostream>

using namespace std;

int gcd(int x, int y) {
    if (x < y) { int t = x; x = y; y = t; }
    if (y == 0) return x;
    else return gcd(y, x%y);
}

int main()
{
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
 
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
inline ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }


struct Edge{ll nxt; ll weight; };
struct El{ll idx; ll acc;};
ll indegree[100001];
vector<Edge> adj[100001];
int color[100001];
bool visited[100001];

void bfs(int st)
{
    queue<El> quu; quu.push(El{st, 0}); visited[st] = true;
    while(!quu.empty())
    {
        auto cur = quu.front(); quu.pop();
        if(cur.acc % 2 == 0)
        {
            color[cur.idx] = 0;
        }
        else
        {
            color[cur.idx] = 1;
        }
        
        for(int i = 0; i < adj[cur.idx].size(); i++)
        {
            auto next = adj[cur.idx][i];
            if(visited[next.nxt]) continue;
            visited[next.nxt] = true;
            quu.push(El{next.nxt, cur.acc + next.weight});
        }
    }
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n;
    
    for(int i = 0; i < n - 1; i++)
    {
        ll u, v, w; cin >> u >> v >> w;
        adj[u].push_back(Edge{v, w});
        adj[v].push_back(Edge{u, w});
        indegree[u] += 1;
        indegree[v] += 1;
    }
    
    int st = 1;
    for(int i = 1; i <= n; i++)
    {
        if(indegree[i] == 1)
        {
            st = i;
            break;
        }
    }
    
    bfs(st);
    
    for(int i = 1; i <= n; i++)
        cout << color[i] << endl;
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>

using namespace std;

long long int l[100];

long long int luka(long long int n){
        if(l[n]!=0)return l[n];
        else return l[n] = luka(n-1) + luka(n-2);
}

int main(){
        long long int N,ans;
        cin >> N;
        l[0]=2,l[1]=1;
        ans = luka(N);
        cout << ans << endl;
 return 0;
}

Measured memory_bytes: 256
S=input()
N=len(S)
K=int(input())
s="".join((S,S))
cnt1=0
cnt2=0
buf=0
piv=""
if len(set(S))!=1:
    for i in range(N):
        if S[i]==piv:
            buf=buf+1
        else:
            piv=S[i]
            cnt1=cnt1+(buf+1)//2
            buf=0
    cnt1=cnt1+(buf+1)//2
    buf=0
    piv=""
    for i in range(2*N):
        if s[i]==piv:
            buf=buf+1
        else:
            piv=s[i]
            cnt2=cnt2+(buf+1)//2
            buf=0
    #print(buf)
    cnt2 = cnt2 + (buf + 1) // 2
    x = cnt2 - cnt1
    print(cnt1 + (K - 1) * x)
else:
    print((len(S)*K)//2)


Measured memory_bytes: 38432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)998244353;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

struct mint {
    long long x;
    mint(long long x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& oj);
};

ostream& operator<<(ostream& os, const mint& oj){
    os << oj.x;
    return os;
}

mint factorial(int n){
    mint res = 1;
for(int i=1;i<=n;++i){
        res *= i;
    }
    return res;
}

mint nCr(int n,int r){
    mint numerator = 1;
    if(r > n - r) r = n - r;
    for(int i=n;i>n-r;--i){
        numerator *= i;
    }
    mint denominator = 1;
    for(int i=1;i<=r;++i){
        denominator *= i;
    }
    return numerator/denominator;
}

int main(){
    int n,m,k;cin >> n >> m >> k;
    mint ans = 0;
    mint pp = 1;
    vector<mint> mpow(n);
    rep(i,n){
        mpow[i] = pp;
        pp *= m-1;
    }
    vector<mint> ncr(k+10);
    ncr[k] = nCr(n-1, k);
    for(int x=k-1;x>=0;--x){
        ncr[x] = ncr[x+1] * (x+1) / (n-1-x);
    }
    //for(auto& t : ncr) cout << t << " ";
    //cout << endl;
    for(int i=0;i<=k;++i){
        // TLE mint tmp = nCr(n-1, i);
        mint tmp = ncr[i];
        tmp *= m;
        // TLE tmp *= mint(m-1).pow(n-1-i);
        tmp *= mpow[n-1-i];
        ans += tmp;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 6208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    string dic[4] = {"dream", "dreamer", "erase", "eraser"};
    string s; cin>>s;
    string tmp = "";
    for(ll i=s.size()-1; i>=0; i--){
        tmp = s[i] + tmp;
        for(string d : dic){
            if(tmp == d)
                tmp = "";
        }
    }
    if(tmp == "")
        OUT("YES");
    else
        OUT("NO");
}

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

#define loop(n, i) for(int i=0;i<n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;

ll s(ll v) {
    if (v < 10) return v;
    return (v % 10) + s(v / 10);
}

double sv(ll v) {
    return 1.0 * v / s(v);
}

ll next(ll crr) {
    // 9 rightmost 0-8 digit or plus 1
    ll base = 1;
    while (base <= crr) {
        int d = (crr / base) % 10;
        if (d < 9) {
            ll n = crr + (9 - d) * base;
            if (sv(crr) <= sv(n)) return crr;
            else return next(n);
        }
        base *= 10;
    }
    return crr;
}

int main() {
    ll l = 1;
    int k; cin >> k;
    loop (k, i) {
        cout << l << endl;
        l = next(l + 1);
    }
    return 0;
}

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

int main(void) {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}


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

namespace AtTest.ABC_133
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nab = ReadInts();
            int n = nab[0];
            int a = nab[1];
            int b = nab[2];
            WriteLine(Min(n * a, b));
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=1e6+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int n,m;
bool vis[55];
std::vector<int> g[55];
void dfs(int u){
	vis[u]=1;
	for(auto v : g[u]){
		if(!vis[v])dfs(v);
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();

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

	std::vector<pair<int,int>> a(m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&a[i].first,&a[i].second);
	}
	int ans = 0;
	for(int i=0;i<m;i++){
		int cnt = 0;
		for(int j=1;j<=n;j++)g[j].clear();
		memset(vis,0,sizeof(vis));
		for(int j=0;j<m;j++){
			if(j==i)continue;
			g[a[j].first].pb(a[j].second);
			g[a[j].second].pb(a[j].first);
		}
		for(int j=1;j<=n;j++){
			if(!vis[j])cnt++;dfs(j);
		}
		if(cnt>1)ans++;
	}

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

}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
def factorial(n):
    if (n==0) or (n==1):
        return 1
    ret = 1
    for i in range(2, n+1):
        ret *= i
    return ret
def combination(n, k):
    return factorial(n)//factorial(k)//factorial(n-k)
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, W = LI()
wv = LIR(N)

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

for i in range(N):
    w, v = wv[i]
    for j in range(W+1):
        if (j < w):
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w] + v)

print(dp[N][W])

Measured memory_bytes: 120300
import numpy as np

n = int(input())
s = input()
s_W = [0]
s_E = []

for i in range(n):
    if s[i] == "W":
        s_W.append(1)
        s_E.append(0)
    else:
        s_W.append(0)
        s_E.append(1)

W_l = np.cumsum(np.array(s_W))
E_l = np.cumsum(np.array(s_E))

ans = []
for j in range(n):
    num = W_l[j]-W_l[0]+E_l[-1]-E_l[j]
    ans.append(num)
print(min(ans))

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);

    int ma=2000000;
    int n;
    cin >> n;
    vector<bool> pri(ma, false);
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }

    sort(All(a));

    REP(i,n){
        if(i!=0&&a[i-1]==a[i])pri[a[i]]=true;
        if(!pri[a[i]]){
            for(int j=a[i]*2;j<ma;j+=a[i]){
                pri[j]=true;
            }
        }
    }

    int sum=0;
    REP(i,n){
        if(!pri[a[i]])sum++;
    }

    cout << sum << endl;

}


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

int main(void){
  	int a, b, h, m;
  	double ans, th;
  	const double PI = acos(-1);
	cin >> a >> b >> h >> m;
  	th = (30*h + 0.5*m - 6*m) * PI/180 ;
  	ans = sqrt(a*a + b*b - 2*a*b*cos(th));
  	printf("%.10f", ans);
	return 0;
}

Measured memory_bytes: 4136
import java.io.*;
import java.util.*;
/*
><BY MOHAMMAD OMAR><GOOGLE, HERE I COME!><
*/
public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int a = sc.nextInt(); int b = sc.nextInt();
        pw.println(a * b);

        pw.close();
    }

    
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public double nextDouble(String x) {

            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }


    }
}


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

int main() {

  typedef std::multiset<int> MySet;
  MySet heightSet;

  for(int i = 0; i < 10; ++i)
  {
    int val;
    cin >> val;
    // set ???????´?????????\????????¨??????????????????????????????
    heightSet.insert(val);
  }

  // ??§??????????????¢???????????????????????? reverse_iterator ?????????
  MySet::reverse_iterator rit = heightSet.rbegin();
  for(int i = 0; i < 3; ++i)
  {
    cout << *rit << endl;
    ++rit;
  }
  return 0;
}

Measured memory_bytes: 3080
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

vector<PII> g[100010];
int d[100010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
	int n, m;
	cin >> n >> m;
	vector<vector<double>> dp(n+1, vector<double>(m+1, 0.0));
	
	VI data(n);
	REP(i, n) {
		cin >> data[i];
	}
	
	double sum = 0.0;
	REP(i, n) {
		sum += data[i];
		dp[i+1][1] = sum / (double)(i+1);
	}
		
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= min(i, m-1); j++) {
			sum = 0.0;
			for (int k = i; k < n; k++) {
				sum += data[k];
				dp[k+1][j+1] = max(dp[k+1][j+1], dp[i][j] + sum / (double)(k + 1 - i));
			}
		}
	}
	
	cout << fixed << setprecision(9) << dp[n][m] << endl;
	
  return 0;
}



Measured memory_bytes: 7428
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
ans = [a[-1], 0]
m = float('inf')
for i in range(n-1):
    tmp = abs(ans[0]/2-a[i])
    if tmp < m:
        m = tmp
        ans[1] = a[i]

print(*ans)


Measured memory_bytes: 62704
kazu=int(input())
sintyo=list(map(int, input().split())) 
ans=0
takasa=sintyo[0]
for x in range(kazu-1):
    takasa2=sintyo[x+1]
    if(takasa>takasa2):
        sabun=takasa-takasa2
        ans+=sabun
    if(takasa<takasa2):
        takasa=sintyo[x+1]
print(ans)

Measured memory_bytes: 32204
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        in.close();

        int max = 0;
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            char a = str.charAt(i);
            if (a == 'A' || a == 'C'|| a == 'G' || a == 'T') {
                count++;
            } else {
                if (max < count) max = count;
                count = 0;
            }
        }
        if (max < count) max = count;

        System.out.println(max);
    }
}

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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    int P, Q, R;
    cin >> P >> Q >> R;

    int ans = min({P+Q, Q+R, R+P});
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;

namespace cards
{
    public static class main
    {
        public static void Main()
        {
            int n     = int.Parse(Console.ReadLine());
            int count = int.Parse(Console.ReadLine());
            Dictionary<int, int> cards = new Dictionary<int, int>();
            int[] arr = new int[2*n+1];
            for (int y=1 ; y<=(2*n) ; y++)
            {
                cards.Add(y,y);
            }  
             

            for (int i = 0; i < count; i++)
            {
                int input = int.Parse(Console.ReadLine());

                if (input == 0)
                {
                    int z = 1;
                    for (int x = 1; x <= 2*n; x++)
                    {
                        arr[x] = cards[x];
                    }
                    for (int x = 1; x < 2*n; x+=2)
                    {
                        cards[x]   = arr[z];
                        cards[x+1] = arr[n + z];
                        z = z + 1;
                    }
                }
                else
                {
                    int z  = 1;
                    int z1 = 1;
                    for (int x = 1; x <= 2 * n; x++)
                    {
                        arr[x] = cards[x];
                    }
                    for (int x = 1; x <= 2 * n - input; x++)
                    {
                        cards[x] = arr[input+ z1];
                        z1 = z1 + 1;
                    }
                    for (int x = 2*n-input+1; x <= 2*n; x++)
                    {                        
                        cards[x] = arr[z];
                        z = z + 1;
                    }

                }
            }
            for (int x = 1; x <= 2 * n; x++)
            {
                Console.WriteLine(cards[x]);
            }
        }
    }
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int a;
        cin >> a;
        if (i % 2 == 1 && a % 2 == 1) {
            ++cnt;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3648
from collections import defaultdict

N, P = map(int, input().split())
S = input()

if P in (2, 5):
    count = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            count += i + 1
    print(count)
else:
    d = defaultdict(int)
    r = 0
    for i in range(N):
        r += int(S[N - 1 - i]) * pow(10, i % (P - 1), P)
        r %= P
        d[r] += 1

    count = d[0]
    for num in d.values():
        count += num * (num - 1) // 2
    print(count)

Measured memory_bytes: 43084
<?php

$is_honban = 1;

if ($is_honban) {
  //----------------------------------------------------------------------------------
  // Input for honban
  //----------------------------------------------------------------------------------
  $sc = new Scanner();
  $n = $sc->nextInt();
  $d = array();
  for ($i = 0; $i < $n; $i++) {
    $d[] = $sc->nextInt();
  }



} else {
  //----------------------------------------------------------------------------------
  // Input for test
  //----------------------------------------------------------------------------------
  error_reporting(E_ERROR | E_WARNING | E_PARSE);

  $n = 7;
  $d = array(50,30,50,100,50,80,30);



}
//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------

$ans = 0;

$dd = array_unique($d);
$ans = count($dd);



//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
out::println($ans);



//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

?>


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

long long longabs(long long x) {
    if (x < 0)
        x *= -1;
    return x;
}

int main()
{
    long long pos;
    long long n, d;

    cin >> pos >> n >> d;
    pos = longabs(pos);

    if (pos / d >= n) {
        cout << pos - n * d << endl;
        return 0;
    }
    
    else {
     //10 8 2 のとき 0 3 2 と同じである  10 8 3  == 1 5 3
        n -= pos / d;
        pos -= (pos/d)*d;
    } 
 
   
       
    if (n % 2 == 0)
        cout << pos << endl;

    else
        cout << d - pos << endl;
            
        

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int ans = 1;
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int k = (int)1e18;
	for(int i=0;i<n;i++){
		if(a[i]==0){
			ans = 0;
			break;
		}
		if(ans>(k/a[i])){
			ans = -1;
			break;
		}
		ans = ans*a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 4428
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<set>
#include<sstream>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
ul gcd(ul a,ul b){
	if(b==0) return a;
	return gcd(b,a%b);
}
ul gcd(ul a,ul b,ul c){
	return gcd(gcd(a,b),c);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ul n;
	cin>>n;
	ul tot = 0;
	for(ul j=1;j<=n;j++){
		for(ul k = 1;k<=n;k++){
			for(ul m =1;m<=n;m++){
				tot += gcd(j,k,m);
			}
		}
	}
	cout<<tot;
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;
 
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

int main(){
    string S;
    cin >> S;
    ll k;
    cin >> k;

    ll cnt=0;

    for(ll i = 0; i < k; ++i){
        if(S[i]!='1'){
            cout << S[i] << endl;
            return 0;
        }
    }

    cout << "1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	string a,b,c;
	cin >> a >> b >> c;
	bool ret;
	if (a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) ret = true;
	else ret = false;
	if(ret) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll power(ll x, ll y, ll p)
{ll res = 1;x = x % p;while (y > 0){if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
ll modInverse(ll n, ll p)
{return power(n, p-2, p);}
ll nCr(ll n, ll r, ll p)
{if (r==0) return 1;ll fac[n+1];fac[0] = 1;for(ll i=1 ; i<=n; i++)fac[i] = fac[i-1]*i%p;return (fac[n]*modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll i, j, k, n, m, t, p, temp, flag, x, y, z, count, a, b, c, d;
	string sta, stb;
	cin >> sta >> stb;
	temp=0;
	ll ans=0;
	for(i=0; i<sta.size()-stb.size()+1; i++)
	{
		temp=0;
		for(j=0; j<stb.size(); j++)
		{
			if(stb[j]==sta[i+j])
				temp++;
		}
		ans=max(ans, temp);
	}
	cout << stb.size()-ans << endl;
	return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <vector>

using namespace std;

int main(void){
    int n,q;
    scanf("%d %d",&n,&q);
    char s[100000];
    scanf("%s",s);
    int res[100000] = {0};
    int box = 0;
    for(int i=1;i<n;i++){
        if(s[i-1] == 'A'&&s[i] == 'C'){
            box++;
        }
        res[i] = box;
    }
    int count[q],st,en;
    for(int i=0;i<q;i++){
        scanf("%d %d",&st,&en);
        count[i] = res[en-1] - res[st-1];
    }
    for(int i=0;i<q;i++){
        printf("%d\n",count[i]);
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ll = long long;
using ii = pair<ll, ll>;

int32_t main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<ll> vs(n);
	ll ans = 0;
	for(auto &x:vs){ 
		cin >> x;
	}
	ll hi = vs[0];
	for(auto &x:vs){
		if(x<hi) ans += hi-x;
		else hi = x;
	}
	cout << ans << endl;
}


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

int sum(int n) {
  if (n == 0) {
    return 0;
  }

  // sum関数の中でsum関数を呼び出している
  int s = sum(n - 1);
  return s + n;
}

//現在の文字sと今まで使った文字の最大値を引数にする
//n-1文字の文字列の次の文字はa~今まで使った文字の最大値+1
int n;
void dfs(string s,char mx){
  if(s.size() == n){
    cout << s << endl;
    return ;
  }
  
  for(char c = 'a';c <= mx + 1;c++){
    string t = s;
    t.push_back(c);
    dfs(t,max(mx,c));
  }
}

int main() {
  cin >> n;
  dfs("",'a'-1);
}

Measured memory_bytes: 1536
s = input()
c = [0 for _ in range(26)]

for i in range(len(s)):
    c[ord(s[i])-97] = 1

if len(s) == 26:
    ind = len(s)-1

    for _ in range(len(s)):
        r = -1
        for i in range(ord(s[ind])-97+1, ord('z')-97+1):
            if c[i] == 0:
                r = i
                break

        if r != -1:
            print(s[:ind] + chr(r+97))
            exit()

        c[ord(s[ind])-97] = 0
        ind -= 1

    print(-1)

else:
    print(s + chr(c.index(0)+97))

Measured memory_bytes: 9108
from string import lowercase as alpha

morph = { ch : chr(ord(ch) + 1) for ch in alpha }
morph['z'] = 'a'
s = raw_input().strip()
a = list(s)
k = int(raw_input())

z_next = ord('z') + 1
for i, ch in enumerate(a):
    if ch == 'a':
        continue
    z_dist = z_next - ord(ch) 
    if z_dist <= k:
        k -= z_dist
        a[i] = 'a'
k %= 26
a[-1] = chr(ord(a[-1]) + k)

print(''.join(a))

Measured memory_bytes: 15344
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, Q;

vvi G;
vi P;
vi ans;

void dfs(int v, int pp) {
    ans[v] = pp + P[v];
    for (auto nv : G[v]) {
        dfs(nv, ans[v]);
    }
}

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

    G = vvi(N, vi(0));

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

    P = vi(N, 0);
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        P[p - 1] += x;
    }

    ans = vi(N);
    dfs(0, 0);

    for (int i = 0; i < N; i++) {
        cout << ans[i] << ' ';
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 21120