akhauriyash/Code-Regression huggingface dataset:
from collections import deque

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

ans=[0]*(n+1)
ans[1]=1
check=[0]*(n+1)
check[1]=1
q = deque([1])

while q:
    now = q.popleft()
    for room in connection[now]:
        if check[room] == 0:
            ans[room]=now
            check[room]=1
            q.append(room)

if 0 in check[1:]:
    print('No')
    exit()
print('Yes')
for i in range(2,n+1):
    print(ans[i])


Measured memory_bytes: 35520
def sum_of_digits(n):
  s = 0
  while n > 0:
    s += n % 10
    n = int(n / 10)
  return s

n, a, b = map(int, input().split())
res = 0

for i in range(1, n + 1):
  if a <= sum_of_digits(i) <= b:
    res += i
    
print(res)


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

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		boolean f=true;
		for(int i=0;i<s.length();i++) {
			if(i%2==0) {
				if(s.charAt(i)=='L')
					f=false;
			}else {
				if(s.charAt(i)=='R')
					f=false;
			}
		}
		if(f)
			System.out.println("Yes");
		else
			System.out.println("No");

	}

}

Measured memory_bytes: 21716
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    E=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v,w=map(int,input().split())
        u-=1; v-=1; w%=2
        E[u].append((v,w))
        E[v].append((u,w))

    d=[0]*n
    def dfs(v,p):
        for nv,w in E[v]:
            if(nv==p): continue
            d[nv]=d[v]^w
            dfs(nv,v)
    dfs(0,-1)
    print(*d,sep='\n')
resolve()

Measured memory_bytes: 85764
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (ll)((v).size())
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 


#define M 100010




int main(){
    IOS;
    tihs;
    
   	ll n,m;cin>>n>>m;

   	vll g[n+1];
   	ll a[n];
   	rep(i,0,n)cin>>a[i];
   	rep(i,0,m){
   		ll u,v;cin>>u>>v;
   		u--,v--;
   		g[u].pb(v),g[v].pb(u);
   	}
   	ll ans=0;
   	rep(i,0,n){
   		bool ok=1;
   		ll now=a[i];
   		for(auto j:g[i])if(a[j]>=a[i])ok=0;
   		if(ok)ans++;
   	}
   	cout<<ans;


    return 0;
}

Measured memory_bytes: 10252
N = int(input())
height = list(map(int, input().split()))
max = 0
count = 0
tmp = 0
while count < len(height) - 1:
    corrent = height[count]
    if height[count + 1] <= corrent:
        tmp += 1
    else:
        tmp = 0
    if max < tmp:
        max = tmp
    count += 1
print(max)

Measured memory_bytes: 15020
#! /usr/bin/env perl
use strict;
use warnings;

my $input = <>;
chomp $input;

my ($a,$b,$k) = split / /,$input;

if($a>=$k){
    my $takahashi = $a - $k;
    print("$takahashi $b");
}
else{
    my $count = $k - $a;
    my $aoki = $b - $count;

    if($aoki > 0){
        print("0 $aoki");
    }
    else{
        print("0 0");
    }
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin>>n;
  cout<<(n+n*n+n*n*n)<<"\n";
  return 0;
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    long X = Long.parseLong(in.readLine());
    long deposit = 100;
    for (long i = 1; ; i++){
      deposit = (long)(deposit * 1.01);
      if(deposit >= X ){
        System.out.println(i);
        break;
      }
    }
  }
}

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

int main () {
    int a[8]; //6+null 1indexed
    int i;
    char str[100];
    int v;
    for (i = 1;i <= 6;i ++) {
        scanf ("%d ",&a[i]); //サイコロ
    }
    scanf ("%s",&str);
    //str毎にサイコロ動かそ
    for (i = 0;i < strlen(str);i ++) {
        v = a[1]; //forの中に入れる
        switch (str[i]) {
            case 'S':
                a[1] = a[5];
                a[5] = a[6];
                a[6] = a[2];
                a[2] = v; //順番大事よー
                break; //breakしんとそのまんま下
            case 'E':
                a[1] = a[4];
                a[4] = a[6];
                a[6] = a[3];
                a[3] = v;
                break;
            case 'W':
                a[1] = a[3];
                a[3] = a[6];
                a[6] = a[4];
                a[4] = v;
                break;
            case 'N':
                a[1] = a[2];
                a[2] = a[6];
                a[6] = a[5];
                a[5] = v;
                break;
        }
        /*for (int j = 1;j <= 6;j ++) {
            printf ("%d ",a[j]);
        }    
        putchar ('\n');*/
    }
    printf ("%d\n",a[1]);
    return 0;
}


Measured memory_bytes: 2124
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split("");
	inputWord = input[0];
	// keyence
	const targetList = ['k', 'e', 'y', 'e','n', 'c', 'e']
	var pattern = 'keyence';	

	if(inputWord.indexOf(pattern) === 0) {
		console.log('YES');
		return;
	}
	if((inputWord.lastIndexOf(pattern)+pattern.length===inputWord.length)&&(pattern.length<=inputWord.length)){
		console.log('YES');
		return;	
	}
	//文字列から10進数に変換するときはparseIntを使います
	var checkIndex = 0
	var changeCount = 0;
	var lastChangeIndex = 0;
	var ngFlg = false;
	for (var i = 0; i < tmp.length; i++) {
		if (tmp[i] == targetList[checkIndex]) {
			checkIndex++;
			continue;
		}
		check = pattern.slice(checkIndex);
		if((inputWord.lastIndexOf(check)+check.length===inputWord.length)&&(check.length<=inputWord.length)){
		console.log('YES');
		break;
		} else {
			console.log('NO')
			break;
		}

	}

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

    ll n;cin>>n;
    vector<ll> a(n);
    ll mn=200000;
    rep(i,n){
        cin>>a[i];
        mn=min(mn,a[i]);
    }

    if(mn!=1){
        cout<<"-1"<<endl;
        return 0;
    }

    int cnt=0;
    int num=1;
    for(int i=0; i<n; i++){
        if(a[i]==num){
            num++;
        }else{
            cnt++;
        }
    }

    cout<<cnt<<endl;
    
}

Measured memory_bytes: 4788
//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
void solve(){
   ll n,m;cin>>n>>m;
  if(n<m){
    fr(i,0,m)
      cout<<n;
  }else {
    fr(i,0,n)
      cout<<m;
  }
}

int main(){
    ll t=1;
//cin>>t;
    while(t--){
     solve();
     cout<<endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

ll modexp(ll a, ll n) {
    ll ans = 1;
    for(int i = 0; i < n; i++) {
        ans *= a;
        ans %= MOD;
    }
    return ans;
};

int main() {
    ll N;
    cin >> N;
    cout << (modexp(10, N) - modexp(9, N) - modexp(9, N) + modexp(8, N) + 3*MOD)%MOD << endl;

    return 0;
}

Measured memory_bytes: 3632
//Name: Seven Puzzle
//Level: 2
//Category: 探索
//Note:

/**
 * 状態を整数にエンコードして、同じ状態を2回踏まないようにしながら探索する。
 * テストケースの数が多いので、ゴールから逆に探索していき、「ある盤面に到達するまでの最小手数」を全ての盤面に対して求めておくとよい。
 *
 * オーダーは O(N!)。
 * ただしNはマスの数で、N=8。
 */

#include <iostream>
#include <array>
#include <vector>
#include <unordered_map>

using namespace std;

array<array<int,4>,2> field;

int encode() {
    int res = 0;
    for(int r = 0; r < 2; ++r) {
        for(int c = 0; c < 4; ++c) {
            res *= 8;
            res += field[r][c];
        }
    }
    return res;
}

pair<int,int> decode(int v) {
    pair<int,int> zero;
    for(int r = 1; r >= 0; --r) {
        for(int c = 3; c >= 0; --c) {
            field[r][c] = v % 8;
            v /= 8;
            if(field[r][c] == 0) {
                zero = make_pair(r, c);
            }
        }
    }
    return zero;
}

const int DR[] = {0, -1, 0, 1};
const int DC[] = {1, 0, -1, 0};
unordered_map<int,int> memo;
void init() {
    for(int r = 0; r < 2; ++r) {
        for(int c = 0; c < 4; ++c) {
            field[r][c] = r*4 + c;
        }
    }

    vector<int> q[2];
    q[0].push_back(encode());
    memo[q[0].back()] = 0;
    int turn = 1;
    while(q[0].size() > 0) {
        q[1].clear();
        for(int cur : q[0]) {
            auto z = decode(cur);
            for(int d = 0; d < 4; ++d) {
                const int nr = z.first + DR[d];
                const int nc = z.second + DC[d];
                if(nr < 0 || nr >= 2 || nc < 0 || nc >= 4) continue;
                swap(field[z.first][z.second], field[nr][nc]);
                const int ns = encode();
                if(!memo.count(ns)) {
                    memo[ns] = turn;
                    q[1].push_back(ns);
                }
                swap(field[z.first][z.second], field[nr][nc]);
            }
        }
        turn++;
        q[0].swap(q[1]);
    }
}

bool solve() {
    for(int r = 0; r < 2; ++r) {
        for(int c = 0; c < 4; ++c) {
            if(!(cin >> field[r][c])) return false;
        }
    }

    cout << memo[encode()] << endl;
    return true;
}

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

    init();
    while(solve()) ;
    return 0;
}

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

int main()
{
	int m;
	for (cin >> m; m > 0; m--) {
		int money, year, n, t, max = 0;
		double ri;
		bool fukuri;
		cin >> money >> year;
		for (cin >> n; n > 0; n--) {
			cin >> fukuri >> ri >> t;
			int get = 0, last = money;
			for (int i = 0; i < year; i++) {
				get += static_cast<int>(last*ri);
				if (fukuri) {
					last += get;
					get = 0;
				}
				last -= t;
			}
			last += get;
			if (max < last) {
				max = last;
			}
		}
		cout << max << endl;
	}

	return 0;
}

Measured memory_bytes: 1232
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	string s;
	cin >> s;

	ll x;
	cin >> x;

	int ans = 1;
	for (int i = 0; i < s.length(); i++)
	{
		if (s.at(i) != '1')
		{
			ans = s.at(i) - '0';
			break;
		}
		if (i == x - 1)
		{
			break;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
using ll = long long;
int main(){
  int a,b,sum=0;
  cin >> a >> b;
  int c=a+b,d=a-b,e=a*b;
  cout << max(c,max(d,e)) <<endl;
  return 0;
}


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

#define MAX 100

int T[MAX];
int P[MAX];
int X[MAX];

int main() {
	int N, M;

	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> T[i];
	}
	cin >> M;
	for( int i = 0; i < M; i++ ) {
		cin >> P[i] >> X[i];
	}

	for( int i = 0; i < M; i++ ) {
		int p = P[i];
		int ans = 0;
		for( int j = 0; j < N; j++ ) {
			if( j + 1 == p ) {
				ans += X[i];
			}
			else {
				ans += T[j];
			}
		}

		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 256
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr << #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }
#define p   998244353

void solve()
{ 

 string s;
  cin>>s;
  int f=0,g=0;

  rep(i,0,3)
  	  {
  	  	if(s[i]=='A')
  	  		f=1;
  	  	if(s[i]=='B')
  	  		g=1;
  	  }
  	  if(f and g)
  	  	  cout<<"Yes";
  	  	else
  	  		cout<<"No";











   
 }

  

signed main()
{fast
	int t;
	//cin>>t;
	t=1;
	while(t--)
		{solve();}
	
}












Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

tot_len = sum(A)
cum = 0
for i in range(N-1):
    cum += A[i]
    if cum >= tot_len/2:
        break
first = sum(A[:i+1])
last = sum(A[i+1:])
diff = abs(first - last)
if i>=1:
    first2 = sum(A[:i])
    last2 = sum(A[i:])
    diff2 = abs(first2 - last2)
    print(min(diff,diff2))
else:
    print(abs(first - last))

Measured memory_bytes: 26220
#define N 100001 
long p[N],r[N],n,m,i,b[N],a[N][2],c,d;int f(int x){if(p[x]==x)return x;return p[x]=f(p[x]);}int u(int x,int y){x=f(x);y=f(y);p[x]=y;r[y]+=r[x];r[x]=r[y];}int main(){scanf("%ld%ld",&n,&m);for(i=0;i<m;i++)scanf("%d%d",a[i],&a[i][1]);b[m]=n*(n-1)/2;for(i=0;i<N;i++){p[i]=i;r[i]=1;};for(i=m-1;i>0;i--){c=a[i][0],d=a[i][1];if(f(c)==f(d))b[i]=b[i+1];else{b[i]=b[i+1]-r[f(c)]*r[f(d)];u(c,d);}}for(i=1;i<=m;i++)printf("%ld\n",b[i]);}

Measured memory_bytes: 5120
# -*- coding: utf-8 -*-


class FactMod():
    '''
    modの値が素数の時のfactと組み合わせを求める
    フェルマーの小定理を用いているため、modが素数以外の時は使えない
    '''

    def __init__(self, n, mod):
        '''
        コンストラクタ
        f:nまでの i!の値を　配列に入れる
        inv: (i!)^-1　の値を配列に入れる
        '''
        self.mod = mod
        self.f = [1]*(n+1)
        for i in range(1, n+1):
            self.f[i] = self.f[i-1]*i % mod

        self.inv = [pow(self.f[-1], mod-2, mod)]
        for i in range(1, n+1)[::-1]:
            self.inv.append(self.inv[-1]*i % mod)
        self.inv.reverse()

    def fact(self, n):
        '''
        n!の値を返す
        '''
        return self.f[n]

    def comb(self, n, r):
        '''
        nCrの値を返す
        '''
        ret = self.f[n] * self.inv[n-r]*self.inv[r]
        ret %= self.mod
        return ret

    def perm(self, n, r):
        """
        nPrの値を返す
        """
        ret = self.f[n] * self.inv[n-r]
        ret %= self.mod
        return ret

MOD=998244353
N,M,K = map(int,input().split())

F=FactMod(N+1,MOD)
ans=0
for kk in range(K+1):
    not_kk=N-kk
    if not_kk==0:
        r=M*pow(M-1,N-1,MOD)
        ans+=M*pow(M-1,N-1,MOD)
        ans%=MOD
    else:
        r=M*pow(M-1,not_kk-1,MOD)
        ans+=M*pow(M-1,not_kk-1,MOD)*F.comb(N-1,kk)
        ans%=MOD
print(ans)


Measured memory_bytes: 91816
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	return x*f;
}
const int N=2e5+7;
const ll INF=1e12;
ll n,m,A[N],F[N];
inline bool check(ll p)
{
	ll now=m;
	for(int i=1;i<=n;i++)
	{
		// af<=p , a<=p/f
		if(p/F[i]>=A[i]) continue;
		ll t=A[i]-p/F[i];
		if(t>now) return 0;
		now-=t;
	}
	return 1;
}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++) A[i]=read();
	for(int i=1;i<=n;i++) F[i]=read();
	sort(A+1,A+n+1); sort(F+1,F+n+1);
	reverse(F+1,F+n+1);
	ll L=0,R=INF,ans=0;
	// cout<<check(1)<<endl;
	while(L<=R)
	{
		ll mid=L+R>>1;
		if(check(mid)) R=mid-1,ans=mid;
		else L=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3456
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

#define x first
#define d second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;
using pii = pair<int, int>;

typedef long long llint;

const int MAXN = 100010;
const int MAXD = 12;

int n, m, Q, v[MAXN], d[MAXN], c[MAXN];
int bio[MAXN][MAXD], sol[MAXN];
queue<pii> q;
vector<int> e[MAXN];

void bfs(int x, int dist, int col) {
  if (bio[x][dist]) return;
  q.push({x, dist});

  while (!q.empty()) {
    auto p = q.front();
    q.pop();

    if (sol[p.x] == -1)
      sol[p.x] = col;

    if (p.d > 0) {
      for (int y : e[p.x])
	if (!bio[y][p.d - 1]) {
	  q.push({y, p.d - 1});
	  bio[y][p.d - 1] = 1;
	}
    }
  }
}

int main(void) {
  memset(sol, -1, sizeof(sol));
  scanf("%d %d",&n,&m);
  REP(i, m) {
    int a, b;
    scanf("%d %d",&a,&b);
    --a;
    --b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  scanf("%d",&Q);
  REP(i, Q) {
    scanf("%d %d %d",&v[i],&d[i],&c[i]);
    --v[i];
  }
  for (int i = Q - 1; i >= 0; --i)
    bfs(v[i], d[i], c[i]);
  REP(i, n) sol[i] = max(sol[i], 0);
  REP(i, n) printf("%d\n",sol[i]);
  
  return 0;
}


Measured memory_bytes: 13224
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int ans = 700;
        
        for (int i = 0; i < 3; i++) {
            if (line.charAt(i) == 'o') ans += 100;
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
from sys import stdin
input = stdin.readline
from decimal import Decimal as D
 
from bisect import bisect_left as bl
def LIS(L):
    best = []
    for i in L:
        pos = bl(best, i)
        if len(best) <= pos: best.append(i)
        else: best[pos] = i
    return len(best)

xflip = 1
yflip = 1
x1, y1, x2, y2 = map(int,input().split())
if x1 > x2:
    xflip = -1
    x1, x2 = x2, x1
if y1 > y2:
    yflip = -1
    y1, y2 = y2, y1
points = []
n = int(input())
for i in range(n):
    x, y = map(int,input().split())
    if x1 <= x <= x2 and y1 <= y <= y2:
        points.append((x*xflip,y*yflip))
points = [y for x,y in sorted(points)]
 
foun = LIS(points)
dist = D(100)*(x2-x1+y2-y1)
dx = D('-4.2920367320510338076867835')*foun
if foun == min(x2-x1+1, y2-y1+1): dx+= D('15.7079632679489661923132165')
print(dist+dx)

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


int main(){
	string s,s2,s3;
	int a,b;
	cin >> s >> s2 >> a >> b >> s3;
	if(s==s3) a--;
	if(s2==s3) b--;
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> l(n, 0), s(n+1, 0);
    int ans = 1;
    for(int i = 0; i< n; i++){
        cin >> l[i];
        s[i+1] = s[i] + l[i];
        if(s[i+1] <= x) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ n, m ] <- readInts
	as <- readInts
	let
		s = sum as
		-- 1 / 4m * s <= a
		-- s <= 4ma
		k = length $ filter ( \a -> s <= 4 * m * a ) as
	putStrLn $ which "Yes" "No" $ m <= k

Measured memory_bytes: 508
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int,int> P;

int main(){
	int n;
	priority_queue<P,vector<P>,greater<P> > que;

	while(cin>>n,n){
		int sum=0;
		
		for(int i=0;i<n;i++){
			int tres,bdg;
			cin>>tres>>bdg;
			que.push(P(bdg,tres));
		}
		
		bool flag=false;
		while(que.size()){
			P p=que.top();que.pop();
			sum+=p.second;
			if(sum>p.first){
				cout<<"No"<<endl;
				flag=true;
				break;
			}
		}

		if(!flag) cout<<"Yes"<<endl;
		while(que.size()) que.pop();
	}

	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))

const ll N =110;
const ll K = 1e5+5;
const ll mod = 1e9+7;
ll a[N],dp[K],sum[K],n,k;

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

	clr(sum);clr(dp);
	cin>>n>>k;forn(i,n)cin>>a[i];
	dp[0]=1;forn(i,k+1){sum[i]=dp[i];if(i!=0)sum[i]+=sum[i-1];}

	forn(j,n)
	{
		forn(i,k+1)
		{
			ll l=i-a[j]-1;
			dp[i]=sum[i];if(l>=0)dp[i]-=sum[l];
			dp[i]%=mod;dp[i]+=mod;dp[i]%=mod;
		}
		forn(i,k+1){sum[i]=dp[i];if(i!=0)sum[i]+=sum[i-1];sum[i]%=mod;sum[i]+=mod;sum[i]%=mod;}
	}
	cout<<dp[k]<<endl;
}


Measured memory_bytes: 1792
N, K = map(int, input().split())
R, S_, P = map(int, input().split())
T = input()
S = [[] for _ in range(K)]


def f(x):
    if x == "r":
        return P
    if x == "s":
        return R
    if x == "p":
        return S_


for i in range(K):
    S[i].append(T[i])
for i in range(N - K):
    S[i % K].append(T[i + K])
c = 0

for i in range(len(S)):
    t = ""
    for j in range(len(S[i])):
        if t != S[i][j]:
            c += f(S[i][j])
        else:
            S[i][j] = ""
        t = S[i][j]
print(c)


Measured memory_bytes: 13436
n=int(input())
ans=[[0]*n for _ in range(n)]
for i in range(n):
  for j in range(n):
    tmp=i^j
    if tmp==0:
      ans[i][j]=1
    else:
      tmp=format(tmp,'b')[::-1]
      ans[i][j]=tmp.index('1')+1
for i in range(n-1):
  print(*ans[i][i+1:])

Measured memory_bytes: 11384
#include <iostream>
#include <cstdio>
using namespace std;
bool itcan(int x){
    if(x%3 == 0)
        return true;
    else
        return false;
}
int main()
{
    int a,b;
    scanf("%d%d", &a, &b);
    int c[3];
    c[0] = a;
    c[1] = b;
    c[2] = a+b;
    int isposs = false;
    for(int i=0; i<3; i++){
     if(itcan(c[i])){
        isposs = true;
        break;
     }
    }
    if(isposs)
        printf("Possible\n");
    else
        printf("Impossible\n");
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int main()
{
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    auto an = static_cast<int>(ceil(static_cast<double>(n) / a));
    auto cn = static_cast<int>(ceil(static_cast<double>(n) / c));
    cout << min(an * b, cn * d) << endl;
}


Measured memory_bytes: 3104
#include <stdio.h>
 
int main(void){
    // Your code here!
    int A,B,C;
    
    scanf("%d%d%d",&A,&B,&C);
    
    for(int i = 1; i <= B; i++){
        if((i*A) % B == C){
            printf("YES\n");
            return 0;
        }
    }
    
    printf("NO\n");
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

int H, W, K;
int field[3001][3001];
int dp[3001][3001][4];
int fix[3001][3001];


signed main()
{
	cin >> H >> W >> K;
	REP(i, K)
	{
		int y, x, v;
		cin >> y >> x >> v;
		field[x - 1][y - 1] = v;
	}

	multiset<int, greater<int>> s;
	for (int x = 0; x < W; x++)
	{
		s.insert(field[x][0]);

		auto it = s.begin();
		int sum = 0;
		for (int i = 0; i < 3; i++)
		{
			sum += *it;
			++it;
			if (it == s.end()) break;
		}
		fix[x][0] = sum;
	}

	for (int y = 1; y < H; y++)
	{
		dp[0][y][1] = fix[0][y - 1] + field[0][y];

		for (int x = 1; x < W; x++)
		{
			dp[x][y][1] = max(dp[x - 1][y][1], fix[x][y - 1] + field[x][y]);
			dp[x][y][2] = max(dp[x - 1][y][2], dp[x - 1][y][1] + field[x][y]);
			dp[x][y][3] = max(dp[x - 1][y][3], dp[x - 1][y][2] + field[x][y]);
		}

		for (int x = 0; x < W; x++)
		{
			int m = 0;
			for (int i = 1; i <= 3; i++)
			{
				m = max(m, dp[x][y][i]);
			}
			fix[x][y] = m;
		}
	}

	cout << fix[W - 1][H - 1] << endl;
}



Measured memory_bytes: 425172
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 1e5+10;

using namespace std;

main()
{
    fast;
    int n,m,p,x,i;
    cin>>n;
    int t[n+1],tot=0;
    for (i=1;i<=n;i++)
    {
        cin>>t[i];
        tot+=t[i];
    }
    cin>>m;
    for (i=0;i<m;i++)
    {
        cin>>p>>x;
        cout<<tot-t[p]+x<<endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String n = sc.next();
		char[] c = n.toCharArray();
		int a = Integer.valueOf(n);
		int sum = 0;
		
		for (int i = 0; i < c.length; i++) {
			sum += c[i] - '0';  
		}
		
		if (a % sum == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<pair<int,int>> vp(n, {-1, -1});
  int cnt = 0;
  int day = 0;
  while(cnt<k && day<n) {
    if (s[day] == 'o') {
      vp[cnt].first = day;
      day += c + 1;
      cnt++;
    } else {
      day++;
    }
  }
  cnt = k - 1;
  day = n - 1;
  while(cnt>=0 && day>=0) {
    if (s[day] == 'o') {
      vp[cnt].second = day;
      day -= c + 1;
      cnt--;
    } else {
      day--;
    }
  }
  for(auto &i : vp) if (i.first == i.second && i.first != -1) cout << i.first + 1 << endl;
  return 0;
}

Measured memory_bytes: 3332
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define TEST 0 //??\??????????????????(1:??????????????\??? 0:?¨??????\???)
#if TEST
FILE *in = freopen("./Q/A", "r", stdin);
FILE *out = freopen("./A/A", "w", stdout);
#endif

int card[2][50];

int calIndex(int i, int p, int c){
    if(i < c){
        return p+i-1;
    } else if(i < p+c-1){
        return i-c;
    } else {
        return i;
    }
}

void setCard(int n, int turn, int p, int c){
    for(int i = 0; i < n; i++){
        card[turn][i] = card[(turn+1)&1][calIndex(i,p,c)];
    }
}

int main(int argc, const char * argv[]) {
    while(1){
        int n, r; cin >> n >> r;
        if(!n && !r) break;
        
        for(int i = 0; i < n; i++){
            card[1][i] = n-i;
        }
        
        for(int i = 0; i < r; i++){
            int turn = i & 1;
            
            int p, c; cin >> p >> c;
            setCard(n, turn, p, c);
            
        }
        cout << card[(r+1)&1][0] << endl;
        
    }
    
    
#if TEST
    fclose(in);
    fclose(out);
#endif
}

Measured memory_bytes: 1160
#!/usr/bin/env python3

def main():
    N = int(input())

    def fanc(N):
        return N * (N + 1) // 2
    ans = 0
    for i in range(1, N + 1):
        ans += i * fanc(N // i)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8952
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:String,
    }
    println!("{}",
        if a=="111" {"3" }
        else if a=="110"{"2"}
        else if a=="101"{"2"}
        else if a=="011"{"2"}
        else if a=="100"{"1"}
        else if a=="010"{"1"}
        else if a=="001"{"1"}
        else {"0"}
    )
}

Measured memory_bytes: 2128
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);

int main(){

  string S, T; cin >> S >> T;
  cout << T + S << endl;

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

//#include"atcoder/all"


#ifdef _MSC_VER
#include <intrin.h>

#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << endl
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;


void solve() {
	int N, M, K; cin >> N >> M >> K;
	REP(i, N + 1) {
		REP(j, M + 1) {
			int res = i * j + (N - i)*(M - j);
			if (res == K) {
				print("Yes"); return;
			}
		}
	}
	print("No");
}



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

	//int q;
	//cin >> q;
	//while (q--)
	solve();

}


Measured memory_bytes: 3648
# ABC 65 B

def resolve():
    N = int(input())

    a = [0] * (N+1)
    for i in range(N):
        a[i+1] = int(input())

    b = 1
    ans = 0
    while (True):
        tmp = a[b]
        a[b] = 0
        b = tmp
        ans += 1

        if b == 2:
            print(ans)
            return
        elif b == 0:
            print(-1)
            return

    print(-1)
    return

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 6980
#include <stdio.h>

int n;
int a;
int max;
int _[100005];

int main()
{
	int *cnt = _ + 1;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);

		cnt[a - 1]++;
		cnt[a]++;
		cnt[a + 1]++;
	}

	for (int i = -1; i <= 100001; i++) {
		if (cnt[i] > max) {
			max = cnt[i];
		}
	}

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

	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){

	int FirstNum, SecondNum, Sum;
	while(scanf("%d %d", &FirstNum, &SecondNum) == 2){
		Sum = FirstNum + SecondNum;
		if (Sum < 10){ printf("1\n"); goto label;}
		if (Sum < 100){ printf("2\n"); goto label;}
		if (Sum < 1000){ printf("3\n"); goto label; }
		if (Sum < 10000){ printf("4\n"); goto label; }
		if (Sum < 100000){ printf("5\n"); goto label; }
		if (Sum < 1000000){ printf("6\n"); goto label; }
		if (Sum < 10000000){ printf("7\n"); goto label; }
		label: ;
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
typedef pair<int,int> Pp;

signed main(){
    int N;
    cin >> N;
    int M=8*N+1;
    M=sqrt(M);
    if(M*M!=8*N+1){
        cout << "No" << endl;return 0;
    }
    M=(M-1)/2;
    cout << "Yes" << endl << M+1 << endl;
    int e=0;
    bool D[500][100000]={};
    REP(i,M){
        REP(j,M-i){
            D[i][e+j]=1;
            D[i+j+1][e+j]=1;
        }
    	e+=M-i;
    }
    /*REP(i,M){
        REP(j,N){
            cout << D[i][j] << " ";
        }cout << endl;
    }cout << endl;*/
  	
    REP(i,M+1){
        cout << M <<" ";
        REP(j,N){
            if(D[i][j]==1){
                cout << j+1 << " ";
            }
        }cout << endl;
    }
    
    return 0;
}   


Measured memory_bytes: 50176
import java.util.*;

public class Main {
    public static void main(String[] args) {
        char[][] c = new char[3][3];
        Scanner sc = new Scanner(System.in);
        c[0] = sc.next().toCharArray();
        c[1] = sc.next().toCharArray();
        c[2] = sc.next().toCharArray();
        
        for(int i=0;i<3;i++) {
            System.out.print(c[i][i]);
        }
        System.out.println();
        sc.close();
    }
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bn begin()
#define en end()
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007
#define pi 3.141592653589
#define INF 1000000000000
using namespace std;

int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie 
    int n ;
    cin >> n ;
    int ans = n ;
    ans += n*n ;
    ans += n*n*n ;
    cout << ans << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <utility>
using namespace std;

int main(){
  string s;
  cin >> s;
  string s2 = s;
  s += "0000000000000";
  string d = "dream";
  string dr = "dreamer";
  string e = "erase";
  string er = "eraser";
  string t;
  while(true){
    if(s[t.size()] == 'd'){
      if(s[t.size()+5] == 'd'){t += d;}
      else if(s[t.size()+7] != 'a' && s[t.size()+5] == 'e'){t += dr;}
      else{t += d;}
      }
    
    else if(s[t.size()] == 'e'){
      if(s[t.size()+5] == 'r'){t += er;}
      else{ t += e; }
    }
    
    else{break;}
    //cout << t << endl;
  }
  bool f = false;
  if(t.size() != s2.size()){f = true;}
  else{
  for(int i = 0; i < t.size(); i++){
    if(t[i] != s2[i]){f = true; break;}
  }
  }
  if(f){ cout << "NO" << endl;}
  else{ cout << "YES" << endl;}
  
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

struct uftree {
    int n, *par, *rank, *size;
    uftree(int N) : n(N) {
        par = new int[(size_t)N];
        rank = new int[(size_t)N];
        size = new int[(size_t)N];
        for (int i = 0; i < N; i++) {
            par[i]  = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            int r         = root(par[x]);
            size[x]       = size[par[x]];
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y])
            par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
        size[x] += size[y];
        size[y] = size[x];
    }
    int get_size(int x) {
        root(x);
        return size[x];
    }
    bool same(int x, int y) { return root(x) == root(y); }

    // 集合の数をカウントする関数
    // 1..nのつもりでやってる場合も0をカウントしちゃうので注意
    int count_sets() {
        int cnt = 0;
        bool used[n];
        fill(used, used+n, false);
        for (int i=0; i<n; i++) {
            if (used[root(i)]) continue;
            cnt++;
            used[root(i)] = true;
        }
        return cnt;
    }
};

using P = pair<int, int>;
#define fi first
#define se second

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    uftree uft(n);
    vector<P> friends;
    for (int i=0, a, b; i<m; i++) {
        cin >> a >> b;
        uft.unite(--a, --b);
        friends.push_back({a, b});
    }
    int candi[n];
    for (int i=0; i<n; i++) candi[i] = uft.get_size(i) - 1;
    for (auto &f:friends) candi[f.fi]--, candi[f.se]--;
    for (int i=0, c, d; i<k; i++) {
        cin >> c >> d;
        if (uft.same(--c, --d)) {
            candi[c]--;
            candi[d]--;
        }
    }
    for (int i=0; i<n; i++) {
        cout << candi[i] << (i < n-1 ? ' ' : '\n');
    }
    return 0;
}

Measured memory_bytes: 3316
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		long N = input.nextLong();
		boolean found=false;
		for (long h = 1;h<=3500;h++) {
			for (long w = 1; w <= 3500; w++) {
				long Num = N*h*w;
				long Den = 4*h*w-N*w-N*h; //n=Nhw/(4hw-Nw-Nh) -> Analysis in programming handbook
				if (Den>0&&Num%Den==0) {
					long ans = Num/Den;
					System.out.println(h+" "+ans+" "+w);
					found=true;
					break;
				}
			}
			if (found) break;
		}
	}	
}

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

using namespace std;

int main(void){
  int a,b;
  int sum;
  

  while(cin >> a >> b){
    int digit = 0;
    sum = a + b;
    while(sum > 0){
	digit++;
	sum /= 10;
    }
    cout << digit << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

int main(void)
{
    int a;
    string s;
    cin >> a >> s;

    if(a >= 3200){
        cout << s << endl;
    }
    else{
        cout << "red" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S;
	cin >> S;
	int Q;
	cin >> Q;
	vector<int> res;
	for (int t = 0; t < Q; t++) {
		int K;
		cin >> K;
		int ans = 0;
		int r = 0;
		int m = 0;
		int c = 0;
		int tmp = 0;
		for (int i = 0; i < N; i++) {
			while (r < i + K && r < N) {
				if (S[r] == 'M') {
					m++;
				}
				else if (S[r] == 'C') {
					c++;
					tmp += m;
				}
				r++;
			}


			if (S[i] == 'D') {
				ans += tmp;
			}

			if (S[i] == 'M') {
				m--;
				tmp -= c;
			}
			else if (S[i] == 'C') {
				c--;
			}
		}
		res.push_back(ans);
	}
	for (int i = 0; i < Q; i++) {
		cout << res[i] << endl;
	}
}

Measured memory_bytes: 1948
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int d[333][333];
void warshall_floyd(int n) {
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}
int d2[333][333];
void warshall_floyd2(int n) {
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d2[i][j]=min(d2[i][j],d2[i][k]+d2[k][j]);
            }
        }
    }
}


int n,m,l;
int q,s[111111],t[111111];

int ans;
signed main(){
	
    map<P,int> kep;

    cin>>n>>m>>l;
    rep(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        kep[{a-1,b-1}]=c;
        kep[{b-1,a-1}]=c;
    }

    rep(i,n){
        rep(j,n){
            if(kep[{i,j}])d[i][j]=kep[{i,j}];
            else d[i][j]=LINF;
        }
        d[i][i]=0;
    }
    warshall_floyd(n);

    rep(i,n){
        rep(j,n){
            if(d[i][j]<=l)d2[i][j]=1;
            else d2[i][j]=LINF;
        }
        d2[i][i]=0;
    }
    warshall_floyd2(n);
    
    cin>>q;
    rep(i,q)cin>>s[i]>>t[i];
    rep(i,q){
        if(d2[s[i]-1][t[i]-1]<LINF)cout<<d2[s[i]-1][t[i]-1]-1<<endl;
        else cout<<-1<<endl;
    }

}

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

using namespace std;

#define llint long long int
#define REP(i,s,l) for(llint i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main() {

    char enki,out;
    cin >> enki ;
    
    if(enki == 'A') {out = 'T';}
    else if(enki == 'T') {out = 'A';} 
    else if(enki == 'G') {out = 'C'; }
    else if(enki == 'C') {out = 'G';}

    cout << out << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <set>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

double memo[16][1 << 16];
bool   dp[16][1 << 16];
double prob[16][16];

int m, n;

double solve(int, int);

inline double solve2(int pos, int flag){
  if(dp[pos][flag]) return memo[pos][flag];
  return solve(pos, flag);
}

double solve(int pos, int flag){
  double ret = 0.0;
  dp[pos][flag] = true;
  REP(i,m) if(flag & (1 << i)){
    double p   = 1.0;
    double tmp = 0.0;
    for(int j = pos; j < n; j++){
      double pp = p * prob[i][j];
      tmp += (p - pp) * solve2(j, flag ^ (1 << i));
      p = pp;
    }
    tmp += p;
    ret = max(ret, tmp);
  }

  return memo[pos][flag] = ret;
}

int main(){
  scanf("%d%d", &m, &n);
  REP(i,m) REP(j,n)
    scanf("%lf", &prob[i][j]);
  printf("%.11f\n", solve(0, (1 << m) - 1));
  return 0;
}

Measured memory_bytes: 9984