akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
import sys
sys.setrecursionlimit(200000)

def dfs(source, used, all_weight, connect):
    max_weight = all_weight
    max_source = source
    used[source] = 1
    for target, weight in connect[source]:
        if not used[target]:
            now_weight = all_weight + weight
            this_source, this_weight = dfs(target, used, now_weight, connect)
            if max_weight < this_weight:
                max_weight = this_weight
                max_source = this_source
    return [max_source, max_weight]

vertice = int(input())
connect = defaultdict(list)
for _ in range(vertice - 1):
    v1, v2, weight = (int(n) for n in input().split(" "))
    connect[v1].append([v2, weight])
    connect[v2].append([v1, weight])
answer = 0
start_v = 0
for i in range(2):
    used = [0 for n in range(vertice)]
    start_v, answer = dfs(start_v, used, 0, connect)
print(answer)

Measured memory_bytes: 148124
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

using namespace std;

int main(){
  int N;
  cin >> N;
  int out = 1;
  rep(i,3){
    out *= N;
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

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

  int a, b;
  cin >> a >> b;
  int sum = a + b;
  int ans = sum >= 24 ? sum - 24 : sum;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;



int main() {
    string s,t;
    cin>>s>>t;
    int n=s.length();
    for(int i=0;i<n;i++){
        if(s[i]!=t[i]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
	return 0;
}


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

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

#define all(a)  (a).begin(),(a).end()

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

int main(){
    int n;
    cin >> n;
    int a, b, c;
    cin >> a >> b >> c;

    vi calory (n,0);
    rep(i, n) cin >> calory[i];

    sort(all(calory), greater<int>());

    int cal = c;
    int ans = 0;
    rep(i, n){
        cal += calory[i];
        ans = max(ans, cal/(a+(i+1)*b));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1216
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    REP(i, A) cin >> p[i];
    REP(i, B) cin >> q[i];
    REP(i, C) cin >> r[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());

    vector<ll> vec(X+Y);
    for (int i = 0; i < X; ++i)
    {
        vec[i] = p[i];
    }
    for (int i = X; i < X + Y; ++i)
    {
        vec[i] = q[i - X];
    }
    sort(vec.begin(), vec.end());
    int idxr = 0;
    for (auto it = vec.begin(); it != vec.end(); ++it)
    {
        if (*it >= r[idxr]) break;
        *it = r[idxr];
        ++idxr;
        if (idxr >= r.size()) break;
    }
    
    ll ans = 0;
    for (const ll& v : vec)
    {
        ans += v;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6876
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int cnt = 0;
      for(int i=0;i<s.length()/2;i++){
        if(s.charAt(i)!=s.charAt(s.length()-1-i))cnt++;
      }
      System.out.println(cnt);
      
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int 
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	} 
	for(ll i=k;i<n;i++)
	{
		if(a[i-k]>=a[i])
		{
				cout<<"No\n";
		}
		else
		{
			cout<<"Yes\n";
		}
	}
	return 0;
}

Measured memory_bytes: 5188
#include<stdio.h>
int main () {
    char b;
    scanf("%c", &b);
    switch(b){
        case 'A':
            puts("T");
            return 0;
        case 'C':
            puts("G");
            return 0;
        case 'T':
            puts("A");
            return 0;
        case 'G':
            puts("C");
            return 0;
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

int main(){

	int a[3];
	int i,j;

	std::cin >> j;

	for(i=0;i<j;i++){
		std::cin >> a[0] >> a[1] >> a[2];
		std::sort(a,a+3);
		if(a[2]*a[2]==a[0]*a[0]+a[1]*a[1]){
			std::cout << "YES" << std::endl;
		}
		else{
			std::cout << "NO" << std::endl;
		}
	}
}

Measured memory_bytes: 1168
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <map>
#include <iterator>
#include <queue>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for (int i=(a-1);i>=(b);--i)
#define rrep(i,n) rrepd(i,n,0)
#define PI 3.14159265
typedef long long ll;
typedef pair<int, int> P;


int main(int argc, const char * argv[]) {
  long n;
  cin >> n;
  long ans = LONG_MAX;
  long max_multiply = sqrt(n);
  rep(i,max_multiply){
    if (n % (i+1) == 0){
      ans = min((i+1) + n/(i+1), ans);
    }
  }
  cout << ans-2 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
//ll mod=1000000007;
//ll mod=67280421310721;
ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
//			re%=mod;
		}
		a=(a*a);
//		a%=mod;
		b>>=1;
	}
	return re;
}
bool vis[20];
bool re;
bool gra[20][20];
int d;
void dfs(int i )
{
	if(i==d)
	{
		re=1;
		return;
	}
	vis[i]=1;
	FOR(j,0,20)
	{
		if(gra[i][j] && vis[j]==0)
		dfs(j);
		if(re)
		return;
	}
	return;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		n/=200;
		cout<<10-n;
	}
	return 0;
}

Measured memory_bytes: 3648
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func toUpper(b byte) byte {
	return byte(b - 32)
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c := next(), next(), next()
	fmt.Printf("%c%c%c\n", toUpper(a[0]), toUpper(b[0]), toUpper(c[0]))
}


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

int main() {
	char s[100001];
	int flag;
	int len;
	int loop;
	int ans = 0;
	scanf("%s", s);
	len = strlen(s);

	if (s[0] == 'B')flag = 0;
	if (s[0] == 'W')flag = 1;
	for (loop = 0; loop < len; loop++) {
		if (s[loop] == 'B'&&flag == 1) {
			ans++; flag = 0;

		}
		else if (s[loop] == 'W'&&flag == 0) {
			ans++; flag = 1;

		}

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

}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s; cin >> s;
    s[3] = '8';
    cout << s << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll dp[2007][2007];

int main(){
  ll N,M,A[2007],B[2007];
  cin >> N >> M;
  rep(i,N){
    cin >> A[i];
    dp[i+1][0]=1;
  }
  rep(i,M){
    cin >> B[i];
    dp[0][i+1]=1;
  }
  dp[0][0]=1;
  Rep(i,1,N+1){
    Rep(j,1,M+1){
      if(A[i-1]==B[j-1]){
        dp[i][j]=dp[i-1][j]+dp[i][j-1];
        dp[i][j]+=MOD;
        dp[i][j]%=MOD;
      }
      else{
        dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
        dp[i][j]+=MOD;
        dp[i][j]%=MOD;
      }
    }
  }
  cout << dp[N][M]%MOD << endl;
}


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


int main() {
  int N;
  cin >> N;
  string a;
  int b;  
  vector<tuple<string, int, int>> ans;

  for (int i = 0; i <  N; i++){
    cin >> a >> b;
    ans.push_back(make_tuple(a, -b, i+1));;
  }
  
  sort(ans.begin(), ans.end());//ミスってる

  int c;

  for (int i=0; i <N; i++){
    tie(ignore, ignore, c) = ans.at(i);
    cout << c << endl;
  }    
}

Measured memory_bytes: 256
import java.util.*;

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

    int len = str.length();
    int[] array = new int[len-2];

    for(int i=0; i<len-2; i++){
      array[i] = Math.abs(753 - Integer.parseInt(str.substring(i, i+3)));
    }

    Arrays.sort(array);
    System.out.println(array[0]);
  }
}

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

using namespace std;
using ll = long long;

int main() {

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

	int belonged_group[12] = { 0,2,0,1,0,1,0,0,1,0,1,0 };

	int x, y; cin >> x >> y;

	if (belonged_group[x - 1] == belonged_group[y - 1])cout << "Yes";
	else cout << "No";

	return 0;

}

Measured memory_bytes: 256
while 1:
	n,p = map(int,raw_input().split())
	if n == 0: break
	have = [0]*n
	cup = p
	i = 0
	while 1:
		if cup > 0:
			have[i] += 1
			cup -= 1
			if have[i] == p:
				break
		else:
			cup += have[i]
			have[i] = 0
		i = (i+1)%n
	print i

Measured memory_bytes: 4204
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits.h>
#include <cmath>
#include <map>
using namespace std;
using P=pair<int,int>;
using ll=long long;
int main(){
    string t;
    cin>>t;
    int m=t.size();
    bool s=false,n=false,w=false,e=false;
    for(int i=0;i<m;i++){
        switch (t[i]){
            case 'S':
                s=true;
                break;
            case 'N':
                n=true;
                break;
            case 'W':
                w=true;
                break;
            case 'E':
                e=true;
                break;
        }
    }
    if(s!=n||w!=e)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

c = []
for _ in range(3):
    c.append(list(li()))
    
correct = True
a1 = 0
a2 = c[1][0] - c[0][0]
a3 = c[2][0] - c[0][0]
b1 = c[0][0]
b2 = c[0][1]
b3 = c[0][2]

a = [a1,a2,a3]
b = [b1,b2,b3]

for i in range(3):
    for j in range(3):
        if a[i] + b[j] != c[i][j]:
            correct = False
            
print("Yes") if correct else print("No")

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

int main() {
  int N;
  cin >> N;
  vector<int>A(N, 0);
  for (int i=0; i<N; i++){
    cin >> A.at(i);
  }
   int k=1;
  for (int i=0; i<N; i++){
   
    k=A.at(k-1);
    if(k==2){
      cout << i+1 << endl;
      break;
    }
  }
  
  if (k!=2){
    cout << -1 << endl;
  }
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
queue <int > Q;
const int N=300005,E=800005;
int dist[N];
int n,m,id;
#define pb push_back
vector <int > v[N];
struct edge{
	int u,v,w;
}e[E];
inline bool cmp(edge a,edge b){
	return a.w<b.w;
}
int fa[N],val[N],to[N];
inline int getfa(int x){
	return fa[x]==x?x:fa[x]=getfa(fa[x]);
}
int main (){
	scanf ("%d%d",&n,&m);id=n;
	for (int i=1;i<=m;i++)
		scanf ("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
	for (int i=1;i<=n;i++) fa[i]=i;
	sort(e+1,e+m+1,cmp);
	for (int i=1;i<=m;){
		int j=i;
		while (e[j].w==e[i].w) ++j;--j;
		for (int t=i;t<=j;t++)	
			if (getfa(e[t].u)!=getfa(e[t].v))
				fa[getfa(e[t].u)]=getfa(e[t].v);
		int cnt=0;
		for (int t=i;t<=j;t++)
			val[++cnt]=getfa(e[t].u),val[++cnt]=getfa(e[t].v);
		sort(val+1,val+cnt+1);to[val[1]]=++id;
		for (int t=2;t<=cnt;t++)
			if (val[t]!=val[t-1]) to[val[t]]=++id;
		for (int t=i;t<=j;t++){
			int p=e[t].u;v[p].pb(to[fa[p]]),v[to[fa[p]]].pb(p);
			p=e[t].v;v[p].pb(to[fa[p]]),v[to[fa[p]]].pb(p);
		}
		for (int t=i;t<=j;t++)
			fa[e[t].u]=e[t].u,fa[e[t].v]=e[t].v;
		i=j+1;
	}
	Q.push(1),dist[1]=1;
	while (!Q.empty()){
		int x=Q.front(),s=v[x].size();Q.pop();
		for (int t=0;t<s;t++)
			if (!dist[v[x][t]])
				Q.push(v[x][t]),dist[v[x][t]]=dist[x]+1;
	}
	if (!dist[n]) puts("-1");
	else printf ("%d",(dist[n]-1)/2);
	return 0;
}

Measured memory_bytes: 23936
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long>v;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v.push_back(a);
  }

  sort(v.begin(), v.end());
  long long h = 0, w = 0;
  
  for(int i = 0; i < n - 1; ++i) {
    if(v[i] == v[i + 1]) {
      w = h;
      h = v[i];
      ++i;
    }
  }

  cout << w * h << endl;
  return 0;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll n;
	ll dp[101][4][4][4];
	ll ans = 0;

	cin >> n;

	REP(len, 101) {
		REP(i, 4) {
			REP(j, 4) {
				REP(k, 4) {
					dp[len][i][j][k] = 0;
				}
			}
		}
	}

	dp[0][3][3][3] = 1;

	FOR(len, 0, n) {
		REP(i, 4) {
			REP(j, 4) {
				REP(k, 4) {
					if (i == 2 && j == 1 && k == 0)	continue;

					REP(now, 4) {
						if (now == 1 && i == 2 && j == 0) continue;
						if (now == 2 && i == 1 && j == 0) continue;
						if (now == 2 && i == 0 && j == 1) continue;
						if (now == 2 && i == 1 && k == 0) continue;
						if (now == 2 && j == 1 && k == 0) continue;

						dp[len + 1][now][i][j] += dp[len][i][j][k];
						dp[len + 1][now][i][j] %= MOD;
					}
				}
			}
		}
	}

	REP(i, 4) {
		REP(j, 4) {
			REP(k, 4) {
				ans += dp[n][i][j][k];
				ans %= MOD;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
		
      	String s = sc.next();
      	String t = sc.next();

      int hit = 0;
      for(int i = 0; i < s.length(); i++){
         	char c1 = s.charAt(i); 
      		  char c2 = t.charAt(i); 
          	if(c1 == c2){
  				hit++;            
            }
        }
      
      	System.out.println(hit);
    }
}


Measured memory_bytes: 23636
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

uint64_t l, r;
int main(void) {
    uint64_t i, j, nmin = UINT64_MAX;
    cin >> l >> r;
    for (i = l; i <= r; i++) {
        if (i%2019 == 0) {
            cout << "0" << endl;
            return 0;
        }
    }
    for (i = l; i < r; i++) {
        for (j = i+1; j <= r; j++) {
            nmin = min(nmin, (i*j)%2019);
        }
    }
    cout << nmin << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            while (true) {
                int n = sc.nextInt();
                if (n == 0) {
                    break;
                }
                int[] data = new int[n];
                int max = 0;
                int min = 10000;
                for (int i = 0; i < n; i++) {
                    data[i] = sc.nextInt();
                    if (data[i] < min) {
                        min = data[i];
                    }
                    if (data[i] > max) {
                        max = data[i];
                    }
                }
                int ave = 0, sum = 0;
                for (int i = 0; i < n; i++) {
                    sum += data[i];
                }
                sum = sum - max - min;
                ave = sum / (n - 2);
                System.out.println(ave);

            }
        }
    }
}


Measured memory_bytes: 28896
import java.util.Scanner;


public class Main {
    Main(){

        int table[] = new int[3];
        Scanner sc = new Scanner(System.in);

        table[0] = sc.nextInt();
        table[1] = sc.nextInt();
        table[2] = sc.nextInt();

        java.util.Arrays.sort(table);
        System.out.println(table[0] + " " + table[1] + " " + table[2]);
    }

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



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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		Restaurant[] arr = new Restaurant[n];
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			int p = sc.nextInt();
			arr[i] = new Restaurant(i + 1, s, p);
		}
		
		Arrays.sort(arr, (r1, r2) -> {
			int dif = r1.city.compareTo(r2.city);
			if (dif == 0) dif = r2.point - r1.point;
			return dif;
		});
		
		for (Restaurant r : arr)
			System.out.println(r.no);

		sc.close();
	}
	
}

class Restaurant {
	int no;
	String city;
	int point;
	
	public Restaurant(int no, String s, int p) {
		this.no = no;
		this.city = s;
		this.point = p;
	}
}




Measured memory_bytes: 32368
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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; }

typedef long long ll;
typedef pair<ll, ll> p;

ll n;
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  ll res = 0;
  for (ll k = 2; k*k <= n+1; ++k) {
    ll tmp = n;
    int count = 0;
    while(true){
      // cout << tmp << endl;
      if(tmp <= 0 || count >= 10) break;
      else if(tmp == 1){
        res++;
        break;
      }
      if(tmp % k == 0) tmp = tmp / k;
      else {
        tmp = tmp % k;
        count++;
      }
    }
  }

  vector<int64_t> ya = divisor(n-1);
  res += int(ya.size()) / 2;
  res++;

  cout << res << endl;
}


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

int a[100010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	int ans = 0;
	int now = 0;
	while(ans < n) {
		ans++;
		int next = a[now] - 1;
		if(next == 1) {
			printf("%d\n", ans);
			return 0;
		}
		now = next;
	}
	printf("-1\n");
}


Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	cin >> N;
	vector<vector<int>>edge(N*N + 1);
	for (int i = 0; i < 2 * N*N - 2 * N; i++) {
		cin >> L >> R;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	vector<int>used(N*N + 1);
	vector<vector<int>>ans(N, vector<int>(N));
	for (int i = 1; i <= N*N; i++) {
		if (edge[i].size() == 2) {
			ans[0][0] = i;
			used[i] = 1;
			break;
		}
	}
	for (int i = 0; i + 1 < N; i++) {
		int nx = -1;
		for (auto j : edge[ans[0][i]]) {
			if (used[j])continue;
			if (nx == -1)nx = j;
			if (edge[nx].size() > edge[j].size())nx = j;
		}
		ans[0][i + 1] = nx;
		used[nx] = 1;
	}
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < N; j++) {
			for (auto k : edge[ans[i][j]]) {
				if (used[k])continue;
				used[k] = 1;
				ans[i + 1][j] = k;
				break;
			}
		}
	}
	for (auto i : ans) {
		for (int j = 0; j < N; j++) {
			if (j)cout << " ";
			cout << i[j];
		}
		cout << endl;
	}
}


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

int main(){
  int n,k; cin>>n>>k;
  k--;
  string s; cin>>s;
  if(s.at(k)=='A')s.at(k)='a';
  if(s.at(k)=='B')s.at(k)='b';
  if(s.at(k)=='C')s.at(k)='c';
  cout<<s;
}



Measured memory_bytes: 256
#include <cstdio>

int n;
int d[1001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&d[i]);
	}
	int i=0;
	while(1){
		int digit=0;
		if(i==0)digit=1;
		int j=i;
		while(j>0){
			j/=10;
			digit++;
		}
		bool flag=false;
		for(int k=n-1;k>=digit-1;k--){
			j=i;
			for(int l=0;l<digit;l++){
				if(d[k-l]==j%10){
					j/=10;
				}else break;
				if(l==digit-1)flag=true;
			}
			if(flag)break;
		}
		if(!flag)break;
		i++;
	}
	printf("%d\n",i);
	return 0;
}

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

int main() {
  ll N, A, B;
  cin >> N >> A >> B;

  vector<ll> H(N);

  rep0(i, N) cin >> H[i];
  sort(H.begin(), H.end());
  ll l = 0, r = 1e9, m;

  while (l + 1 < r) {
    m = (l + r) / 2;
    ll cnt = 0;
    rep0(i, N) {
      ll t = H[i];
      t -= B * m;
      if (t > 0) {
        cnt += (t + (A - B) - 1) / (A - B);
      }
      if (cnt > m) break;
    }
    // cout << m << SP << cnt << BR;
    if (cnt > m) l = m;
    else r = m;
  }

  cout << r << BR;
  return 0;
}

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

 using namespace std;
 int main()
 {
     char b;
     cin>>b;
     if(b=='A')
     {
         cout<<"T"<<endl;
     }
     else if(b=='T')
     {
         cout<<"A"<<endl;
     }
     else if(b=='G')
     {
         cout<<"C"<<endl;
     }
     else
     {
         cout<<"G"<<endl;
     }
     return 0;
 }



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

bool kaibun(ll t){
    vl digit(5);
    ll now = 0;
    while(t > 0){
        digit[now] = t % 10;
        t /= 10;
        now++;
    }
    rep(i,3){
        if(digit[i]!=digit[4-i]) return false;
    }
    return true;
}

int main(){
    ll a,b; cin >> a >> b;
    ll ans = 0;
    REP(i,a,b+1){
        if(kaibun(i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func main() {
	io := NewIo()
	defer io.Flush()

	S := io.Next()

	t1 := 0
	for i, s := range S {
		if i%2 == 0 {
			if s == '0' {
				t1++
			}
		} else {
			if s == '1' {
				t1++
			}
		}
	}

	t2 := 0
	for i, s := range S {
		if i%2 == 0 {
			if s == '1' {
				t2++
			}
		} else {
			if s == '0' {
				t2++
			}
		}
	}

	if t1 < t2 {
		io.PrintLn(t1)
	} else {
		io.PrintLn(t2)
	}

}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, const char * argv[]) {
    int r = 0;
    cin >> r;

    cout << 3*r*r << endl;

    return 0;
}

/**
 cheat sheet

 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
 sort(v.begin(), v.end());
 => 0 1 2 3 4 5 6 7 8 9

 vector<int> v{ 1, 5, 8, 9, 6, 7, 3, 4, 2, 0 };
 sort(v.begin(), v.end(), greater<int>());
 => 9 8 7 6 5 4 3 2 1 0

 struct A { int x, y; };
 bool comp(A i1, A i2) { return (i1.y < i2.y); }
 vector<A> v { { 6, 8 }, { 1, 9 }, { 2, 4 }, { 4, 7 } };
 sort(v.begin(), v.end(), comp);
 => [1, 9] [2, 4] [4, 7] [6, 8]

 */


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

int main(){
	ios::sync_with_stdio(0);
	string s, t;
	cin >> s >> t;
	t.pop_back();
	if(s==t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


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

int main(){
    using ll = long long;
    constexpr int MAX_A=100001;
    int N;
    ll M;
    std::cin>>N>>M;
    std::vector<ll> A(N);
    for(int i=0;i<N;++i) std::cin>>A[i];
    std::vector<ll> cnt(MAX_A);
    for(int i=0;i<N;++i) cnt[A[i]]++;
    std::vector<ll> S(MAX_A+1);
    for(int i=0;i<MAX_A;++i) S[i+1]=S[i]+cnt[i];
    int l=0,r=2*MAX_A+1;
    while(l+1<r){
        int X=(l+r)>>1;
        ll res=0;
        for(int i=std::max(X-MAX_A,0);i<MAX_A;++i){
            res+=cnt[i]*(S[MAX_A]-S[std::max(X-i,0)]);
        }
        if(res>=M) l=X;
        else r=X;
    }
    std::vector<ll> SS(MAX_A+1);
    for(ll i=0;i<MAX_A;++i) SS[i+1]=SS[i]+i*cnt[i];
    ll ans=0,res=0;
    for(ll i=std::max(l-MAX_A,0);i<MAX_A;++i){
        ans+=cnt[i]*((S[MAX_A]-S[std::max(l-i,0LL)])*i+SS[MAX_A]-SS[std::max(l-i,0LL)]);
        res+=cnt[i]*(S[MAX_A]-S[std::max(l-i,0LL)]);
    }
    ans-=(res-M)*l;
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;

  long long ans = 0;
  int min = 0;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (i != 0) {
      if (min > a) {
        int step = min - a;
        ans += step;
        min = step + a;    
      } else {
        min = a;
      }
    } else {
      min = a; 
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include<algorithm>
#include <string>
using namespace std;
int main() {
	int n;
	int a[200];
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	sort(a, a + n, greater<int>());
	int alice = 0, bob = 0;
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0) {
			alice = alice + a[i];
		}
		else {
			bob = bob + a[i];
		}
	
	}

	cout << alice - bob << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int[][] initial = {{0, 1, 2, 3}, {4, 5, 6, 7}};
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		map.put(encode(initial), 0);
		ArrayDeque<int[][]> que = new ArrayDeque<int[][]>();
		que.add(initial);
		int[] dy = {0, -1, 0, 1};
		int[] dx = {-1, 0, 1, 0};
		
		while (!que.isEmpty()) {
			int[][] arr = que.remove();
			int y0 = 0, x0 = 0;
			for (int y = 0; y < 2; y++) {
				for (int x = 0; x < 4; x++) {
					if (arr[y][x] == 0) {
						y0 = y;
						x0 = x;
					}
				}
			}
			for (int i = 0; i < 4; i++) {
				int _y = y0 + dy[i], _x = x0 + dx[i];
				if (_y < 0 || _y >= 2 || _x < 0 || _x >= 4) {
					continue;
				}
				int[][] _arr = new int[2][4];
				for (int y = 0; y < 2; y++) {
					for (int x = 0; x < 4; x++) {
						_arr[y][x] = arr[y][x];
					}
				}
				_arr[y0][x0] = arr[_y][_x];
				_arr[_y][_x] = arr[y0][x0];
				if (!map.containsKey(encode(_arr))) {
					map.put(encode(_arr), map.get(encode(arr)) + 1);
					que.add(_arr);
				}
			}
		}
		
		Scanner in = new Scanner(System.in);
		while (in.hasNextInt()) {
			int[][] arr = new int[2][4];
			for (int y = 0; y < 2; y++) {
				for (int x = 0; x < 4; x++) {
					arr[y][x] = in.nextInt();
				}
			}
			System.out.println(map.get(encode(arr)));
		}
	}
	
	static int encode(int[][] arr) {
		int code = 0;
		for (int y = 0; y < 2; y++) {
			for (int x = 0; x < 4; x++) {
				code *= 8;
				code += arr[y][x];
			}
		}
		return code;
	}
}

Measured memory_bytes: 41236
N,M = map(int,input().split())
inf = 10 ** 6

d = [[inf]*N for i in range(N)]
prev = [[N]*N for i in range(N)]
vlist = [[0]*N for i in range(N)]

for i in range(M):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    vlist[a][b] = 1
    vlist[b][a] = 1
    d[a][b] = c
    d[b][a] = c
    prev[a][b] = a
    prev[b][a] = b

#####
#print("d",d)
#print("vlist",vlist)
#print("prev",prev)
#####

for k in range(N):
    for i in range(N):
        for j in range(N):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
                prev[i][j] = prev[k][j]

for i in range(N):
    for j in range(N):
        if prev[i][j] == i:
            vlist[i][j] = 0

#####
#print("d",d)
#print("vlist",vlist)
#print("prev",prev)
#####

count = 0
for i in range(N-1):
    for j in range(i,N):
        if vlist[i][j] == 1 and vlist[j][i] == 1:
            count += 1

print(count)

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

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

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


int main()
{
    vector<pair<int,int>>v;
    int n,a;
    cin>>n;
    for(int i=1 ; i<=n ; i++)
    {
       cin>>a;
       v.push_back({a,i});
    }
    sort(v.begin(),v.end());
    for(int i=0 ; i<n ; i++)
    {
        cout<<v[i].second<<" ";
    }
    
    return 0;
}

Measured memory_bytes: 1780
from bisect import bisect_left, bisect_right

N = int(input())
L = list(map(int, input().split()))

L.sort()
len_L = len(L)

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        ans += bisect_left(L, L[i] + L[j]) - j - 1
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
// using graph = vector<vector<edge>>;
using graph = vector<vector<int>>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

int n;
int l[100];

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

    cin >> n;
    REP(i, n) cin >> l[i];

    sort(l, l+n);
    int cnt = 0;
    REP(i, n-2) {
        FOR(j, i+1, n-1) {
            if (l[j] == l[i]) continue;
            int k = j+1;
            while(l[j] == l[k]) k++;
            while(k < n && l[k] < l[i]+l[j]) {
                cnt++;
                k++;
            }
        }
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	string m = "maerd";
	string rd = "remaerd";
	string e = "esare";
	string re = "resare";
	string s;
	cin>>s;
	reverse(all(s));
	bool ok = true;
	int p = 0;
	while(s.size() > p){
		if(s.substr(p, 5) == m){
			p += 5;
		}else if(s.substr(p,7) == rd){
			p += 7;
		}else if(s.substr(p,6) == re){
			p += 6;
		}else if(s.substr(p,5) == e){
			p += 5;
		}else{
			ok = false; break;
		}
	}
	cout<<((ok)?"YES":"NO")<<endl;
	return 0;
}

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

int main(){

   int n;
   cin >> n;
   vector<int> p(n) , q(n);
   for(int &x : p)   cin >> x;
   for(int &x : q)   cin >> x;
   vector<int> a(n);
   for(int i = 0; i < n; i++) a[i] = i + 1;
   vector<vector<int>> f;
   int cnt = 0;

   int aa = 0 , bb = 0;
   do{
      ++cnt;
      if(a == p){ aa = cnt;}
      if(a == q){ bb = cnt;}
   }while(next_permutation(a.begin() , a.end()));

   //cout << cnt << endl;
   cout << abs(aa - bb) << endl;

   return 0;
}

Measured memory_bytes: 256
def iin(): return int(input())
def nl(): return list(map(int, input().split()))

n = iin()
a = [iin() for _ in range(n)]

ans = 0
t = 0
for x in a:
    if x == 0:
        ans += t // 2
        t = 0
    else:
        t += x
ans += t // 2
print(ans)

Measured memory_bytes: 7072
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
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(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,l;
	cin >>n >> l;
	int sum = n*(2*l+n-1)/2;
	cerr<<sum<<endl;
	if(l<=0){
		if(l+n-1>=0){
			cout << sum << endl;
		}else{
			cout << sum - (n+l-1) << endl;
		}
	}else{
		cout << sum - l << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b,c,ans;
int main() {
    scanf("%d %d %d",&a,&b,&c);
    if (a==b&&b==c) {
        cout<<1<<endl;
        return 0;
    }
    if (a!=b) ans++;
    if (b!=c) ans++;
    if (a!=c) ans++;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>

#define MOD 1000000007


using namespace std;


double zahyou[8][2];

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;



}






int main()
{
	long long int x, y;

	cin >> x >> y;

	if ((x + y) % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}

	long long int m, n;

	m = 2 * x - y;
	n = 2 * y - x;

	if (m < 0 || n < 0 || m % 3 != 0 || n % 3 != 0) {
		cout << 0 << endl;
		return 0;
	}

	m /= 3;
	n /= 3;

	long long int ans = 1;

	for (int i = 0; i < n; i++) {
		ans = (ans * (n + m - i)) % MOD;
	}

	for (int i = 1; i <= n; i++) {

		//ansをiでわる。
		ans = (ans * modpow(i, MOD - 2)) % MOD;
	}

	cout << ans << endl;






	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    bool ok=0;
    int act,acx,acy,i,t,x,y;
    int xram,yram,timp;
    int n;
    cin>>n;
    act=0;
    acx=0;
    acy=0;
    for(i=1;i<=n;i++)
    {
        cin>>t>>x>>y;
        timp=t-act;
        if((acx-x)<(x-acx))
            xram=x-acx;
        else
            xram=acx-x;

            if((acy-y)<(y-acy))
            yram=y-acy;
        else
            yram=acy-y;

        if(timp<(xram+yram) || timp%2!=(xram+yram)%2)
        {
            ok=1;
        }



            act=t;
            acx=x;
            acy=y;
    }
    if(ok==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.awt.List;
import java.util.*;
public class Main {
	static int modNum = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		
		
//		ArrayList<Integer> list = new ArrayList<Integer>();
//		
//		for(int i=1;i<=a*2;i++){
//			int b = sc.nextInt();
//			list.add(b);
//		}

		if(a<1200){
			System.out.println("ABC");
		}else{
			System.out.println("ARC");
		}
		sc.close();
	}
}

Measured memory_bytes: 20948
#include <stdio.h>
#include <math.h>

typedef struct{
  double x;
  double y;
}Point;

void koch(int,Point,Point);

int main ( void ){

  int num;

  scanf("%d" , &num );

  Point a = {0.0, 0.0};
  Point b = {100.0, 0.0};

  printf("%.8f %.8f\n" , a.x , a.y );
  koch( num , a , b );
  printf("%.8f %.8f\n" , b.x , b.y );

  return 0;
}




void koch( int num , Point a , Point b ){
  if( num == 0 ){return ; }

  Point c,d,e;


  c.x = ( 2.0 * a.x + 1.0 * b.x ) / 3.0;
  c.y = ( 2.0 * a.y + 1.0 * b.y ) / 3.0;
  d.x = ( 1.0 * a.x + 2.0 * b.x ) / 3.0;
  d.y = ( 1.0 * a.y + 2.0 * b.y ) / 3.0;
  e.x = ( d.x - c.x ) * cos( M_PI/3 ) - (d.y - c.y ) * sin( M_PI/3 ) + c.x;
  e.y = ( d.x - c.x ) * sin( M_PI/3 ) + (d.y - c.y ) * cos( M_PI/3 ) + c.y;

  koch( num - 1 , a , c );
  printf("%.8f %.8f\n" , c.x , c.y );
  koch( num - 1 , c , e );
  printf("%.8f %.8f\n" , e.x , e.y );
  koch( num - 1 , e , d );
  printf("%.8f %.8f\n" , d.x , d.y );
  koch( num - 1 , d , b );
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline


def main():
    X = int(input())
    if X >= 2000:
        print(1)
        return
    d, m = divmod(X, 100)
    if m <= d*5:
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long
int main()
{
    int n,i;
    int ans=0,k,x;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        if(x>=k)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true) {
            int n = sc.nextInt();
            int r = sc.nextInt();
            if(n==0 && r==0) break;
            int i,j;
            int huda[] = new int[n];
            for(i=0;i<n;i++) {
                huda[i] = n-i;
            }
            for(i=0;i<r;i++) {
                int p = sc.nextInt();
                int c = sc.nextInt();
                int rep[] = new int[c];
                for(j=0;j<c;j++){
                    rep[j] = huda[j+p-1];
                }
                for(j=p-2;j>=0;j--){
                    huda[j+c] = huda[j];
                }
                for(j=0;j<c;j++) {
                    huda[j] = rep[j];
                }
            }
            System.out.println(huda[0]);
        }
    }
}



Measured memory_bytes: 37572
H, N = map(int,input().split())
magic = []
for i in range(N):
    a,b = map(int,input().split())
    magic.append((a, b))
magic.sort(reverse=True)
amax, _ = magic[0]

INF = 1<<60

def solve():
    btab = [INF] * (H+1)
    btab[0] = 0
    oneshot = min(amax, H)
    for h in range(1, oneshot+1):
        btab[h] = min([b for a, b in magic if a >= h])
    for h in range(2, H+1):
        for a, b in magic:
            c = b + btab[max(h-a, 0)]
            if c < btab[h]:
                btab[h] = c
    return btab[H]

print(solve())

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

typedef long long int LL;

int main(){
    int n;
    LL  y;
    std::cin >> n >> y;
    for(int a = 0; a <= n; ++a){
        for(int b = 0; b <= n - a; ++b){
            int c = n - a - b;
            if(10000 * a + 5000 * b + 1000 * c == y){
                std::cout << a << ' ' << b << ' ' << c << std::endl;
                return 0;
            }
        }
    }

    std::cout << "-1 -1 -1" << std::endl;
    return 0;
}


Measured memory_bytes: 256