akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n); REP(i, n) cin >> a[i];

    ll nk = n*k;
    map<ll, vll> idxes;
    REP(i, n) idxes[a[i]].push_back(i);

    vll w(n);
    for (auto kv: idxes) {
        ll sz = kv.second.size();
        kv.second.push_back(kv.second[0] + n);
        REP(i, sz) w[kv.second[i]] = kv.second[i+1] - kv.second[i] + 1;  // 次までの距離
    }

    const ll L = 60;
    vvll nx{w};
    REP(_, 60) {
        vll x = nx.back();
        vll y(n);
        REP(i, n) y[i] = min(HIGHINF, x[i]+x[(i+x[i])%n]);
        nx.push_back(y);
    }
    ll cur = 0;
    for (ll i=L; i>=0; i--) {
        if (cur + nx[i][cur%n] <= nk) cur += nx[i][cur%n];
    }
    if (cur == nk) return 0;
    
    vll ans;
    set<ll> has;
    rep(i, cur%n, n) {
        if (has.count(a[i])) {
            while(1) {
                ll v = ans.back();
                ans.pop_back();
                has.erase(v);
                if (v==a[i]) break;
            }
        } else {
            ans.push_back(a[i]);
            has.insert(a[i]);
        }
    }
    REP(i, ans.size()) cout << ans[i] << (i==ans.size()-1?'\n':' ');
    return 0;
}


Measured memory_bytes: 132836
N = str(input())
a = 0
b = 0
i = 0
ans='Yes'
while i<len(N):
    a = a+int(N[i])*10**(len(N)-i-1)
    b = b+int(N[i])
    i+=1
if a%b!=0:
    ans='No'
print(ans)

Measured memory_bytes: 3060
N = str(input())
lenN = len(N)

fN =N[0:(lenN - 1)//2]
lN =N[(lenN + 3)//2-1:]
print(("No","Yes")[(0,1)[fN == fN[-1::-1]]*(0,1)[lN == lN[-1::-1]]*(0,1)[lN == fN]])



Measured memory_bytes: 9000
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int A,B,K;
	cin>>A>>B>>K;
	for(int i=A;i<=B;i++)
		if(abs(i-A)+1<=K||abs(B-i)+1<=K)
			cout<<i<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD          1000000007
#define PI           3.14159265358979
#define OUT(x)       cerr << #x << " = " << x << endl; 
#define rep(i, n)    for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)   for (auto i : v)
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()
#define pb(x)        push_back(x)
#define mp(x, y)     make_pair((x), (y))
#define fi           first
#define se           second
#define setp(x)      setprecision(x)
#define mset(m, v)   memset(m, v, sizeof(m))
//#define int          long long
//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
static const int INF =        0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long             ll;
typedef vector<int>           vi;
typedef vector<double>        vd;
typedef vector<long long>     vll;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef pair<int, int>        pii;
typedef pair<long, long>      pll;
typedef vector<pii>           vpii;
typedef vector<pll>           vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

int n;
vi g[101010];
bool matched[101010];

void dfs(int v, int prev) {
        rep(i, g[v].size()) if (g[v][i] != prev) dfs(g[v][i], v);
        if (prev != -1 && !matched[v] && !matched[prev]) matched[v] = matched[prev] = 1;
        return;
}

int main() { 
        cin >> n;
        rep(i, n - 1) {
                int a, b;
                cin >> a >> b;
                a --;
                b --;
                g[a].pb(b);
                g[b].pb(a);
        }
        dfs(0, -1);
        bool f = false;
        rep(i, n) if (!matched[i]) f = true;
        puts(f ? "First" : "Second");
        return 0;
}



Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(n); i++)
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(){
    ll n; cin>>n;
    vector<vector<ll>> a(2, vector<ll>(n));
    rep(i,n) cin>>a[0][i];
    rep(i,n) cin>>a[1][i];
    ll res=0;
    for(ll i=0; i<n; i++){
        ll tmp=0;
        for(ll j=0; j<=i; j++){
            tmp+=a[0][j];
        }
        for(ll j=i; j<n; j++){
            tmp+=a[1][j];
        }
        chmax(res, tmp);
    }
    cout<<res<<endl;
    return 0;
}

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

using namespace std;

int main() {
  string in = "";
  cin >> in;
  if (in == "abc" || in == "acb" || in == "bac" || in == "bca" || in == "cab" || in == "cba") cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop, heapify


def main():
    n, m = map(int, input().split())
    al = list(map(int, input().split()))
    for i in range(len(al)):
        al[i] = -al[i]

    heapify(al)

    for _ in range(m):
        val = heappop(al)
        val *= -1
        val //= 2
        val *= -1

        heappush(al, val)

    print(-sum(al))


if __name__ == '__main__':
    main()


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

using namespace std;

long long f(long long n, long long x);

int main(){
    long long int a, b, x;

    cin >> a >> b >> x;

    cout << f(b, x) - f(a - 1, x) << endl;

    return 0;
}

long long f(long long n, long long x){
    if(n < 0) return 0;

    return n / x + 1;
}


Measured memory_bytes: 256
from itertools import accumulate, product

# 入力
N, W = map(int, input().split())
w, v = (
    zip(*(map(int, input().split()) for _ in range(N))) if N else
    ((), ())
)

# 各重さの物のリスト（価値について降順）
u = [
    [0] + list(
        accumulate(
            sorted(
                (
                    y for x, y in zip(w, v)
                    if x == i
                ),
                reverse=True
            )
        )
    )
    for i in range(w[0], w[0] + 4)
]

# 重さが w_1, w_1 + 1, w_1 + 2 の物をa, b, c 個選んだとき、
# 重さが w_1 + 3 の物の選び方は一意に定まることを用いて最適値を求める
ans = max(
    sum(u[i][k] for i, k in enumerate(t)) +
    u[3][
        min(
            len(u[3]) - 1,
            (W - sum(k * (w[0] + i) for i, k in enumerate(t))) // (w[0] + 3)
        )
    ]
    for t in product(*map(range, map(len, u[:3])))
    if sum(k * (w[0] + i) for i, k in enumerate(t)) <= W
)

# 出力
print(ans)


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int d = sc.nextInt();
        int[] arr = new int[h*w+1];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                int index = sc.nextInt();
                arr[index] = w*i+j;
            }
        }
        int[][] cum = new int[d][(h*w)/d+1];
        for(int i = 1; i <= h*w; i++){
            int ci = i%d;
            int cj = i/d;
            if(cj != 0){
                int prev = i-d;
                cum[ci][cj] += cum[ci][cj-1] + Math.abs(arr[i]/w - arr[prev]/w) + Math.abs(arr[i]%w - arr[prev]%w);
            }
        }
        int q = sc.nextInt();
        for(int i = 0; i < q; i++){
            int s = sc.nextInt();
            int g = sc.nextInt();
            int ci = s%d; 
            System.out.println(cum[ci][g/d]-cum[ci][s/d]);
        }
    }
    
    public static void printArr(int[][] arr, int h, int w){
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
        return;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 72316
n, m = map(int, input().split())
ps = [int(p)-1 for p in input().split()]
xys = [tuple(int(x)-1 for x in input().split()) for _ in range(m)]

union = {node:(node, 0) for node in range(n)}

def root(node):
    if union[node][0] == node:
        return union[node]
    union[node] = root(union[node][0])
    return union[node]

def unite(*roots):
    r1, r2 = sorted(roots, key=lambda x:x[1])
    rank = max(r1[1]+1, r2[1])
    r = (r2[0], rank)
    union[r1[0]] = union[r2[0]] = r

for x, y in xys:
    unite(root(x), root(y))

print(sum(root(i) == root(p) for i, p in enumerate(ps)))

Measured memory_bytes: 39520
n = int(input())
a = [(int(a), num) for a, num in zip(input().split(" "), list(range(1,n + 1)))]
a.sort()
m = len(a)
for i in range(m):
    print(a[i][1],end="")
    if(i + 1 < m):
        print(" ",end="")
print()

Measured memory_bytes: 24248
#include <stdio.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
typedef long long lint;
const int mod=1000000007;
int k,n=-1,cnt=13;
char c[15];
lint fact[2000010],inv[2000010];
int main(){
	while(1){
		*c=getchar_unlocked();
		if(*c=='\n')break;
		k*=10;
		k+=*c-'0';
	}
	while(getchar_unlocked()!=-1)n++;
	fact[0]=1;
	for(int i=1;i<=n+k;i++)fact[i]=fact[i-1]*i%mod;
	inv[n+k]=1;
	lint now=fact[n+k];
	int b=mod-2;
	while(b){
		if(b&1){
			inv[n+k]*=now;
			inv[n+k]%=mod;
		}
		b>>=1;
		now*=now;
		now%=mod;
	}
	for(int i=n+k-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	lint ans=1;now=1;
	for(int i=1;i<=k;i++){
		now*=25;
		now%=mod;
		ans+=fact[n+k]*inv[n+k-i]%mod*inv[i]%mod*now;
		ans%=mod;
	}
	*(c+14)='\n';
	while(ans){
		*(c+cnt)=ans%10+'0';
		ans/=10;
		cnt--;
	}
	fwrite(c+cnt+1,1,14-cnt,stdout);
	return 0;
}


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

using namespace std;

#define debug(x,y) cout<<(#x)<<" " <<(#y)<<" is " << (x) <<" "<< (y) << endl
#define watch(x) cout<<(#x)<<" is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i,a,b) for(i=a;i<b;i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(),(x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

lld dp[2001][2001];

lld solve(lld n, lld l) {
	if (n < 0 || n == 1 || n == 2 || l < 0) return 0;
	if ((l == 0 && n != 0) || (n == 0 && l != 0)) return dp[n][l] = 0;
	if (n == 0 && l == 0) {
		return dp[n][l] = 1;
	}
	lld c = 0;
	if (dp[n][l] != -1) return dp[n][l];
	c += solve(n - 1, l);
	c %= MOD;
	c += solve(n - 3, l - 1);
	c %= MOD;
	return dp[n][l] = c;

}

int main() {
	fast;
	cin.tie(0);
	lld n;
	cin >> n;
	if (n == 1 || n == 2) cout << "0" << endl;
	else {
		memset(dp, -1, sizeof(dp));
		lld cnt = 0;
		for (lld i = 1; i <= (n / 3) + 1; i++) {
			cnt += solve(n, i);
			cnt %= MOD;
		}
		cout << cnt << endl;
	}
}








Measured memory_bytes: 35004
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    if (n % 2 != 0) {cout << "No" << endl; return 0;}
    if (s.substr(0,n/2) == s.substr(n/2,n/2)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>

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

vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};

int main() {
	int h, w;
	cin >> h >> w;

	vector<string> a(h);
	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}

	int inf = 1e9;
	vector<vector<int>> board(h, vector<int>(w, inf));
	queue<PII> que;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				board[i][j] = 0;
				que.push(make_pair(i, j));
			}
		}
	}

	int ans = 0;
	while (!que.empty()) {
		auto p = que.front();
		que.pop();
		int y = p.first;
		int x = p.second;


		for (int i = 0; i < 4; i++) {
			int ny = y + dy[i];
			int nx = x + dx[i];

			if (ny < 0 || h <= ny || nx < 0 || w <= nx) {
				continue;
			}

			if (board[ny][nx] == inf) {
				board[ny][nx] = board[y][x] + 1;
				ans = max(ans, board[ny][nx]);
				que.push(make_pair(ny, nx));
			}
		}
	}

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


Measured memory_bytes: 13456
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <sstream>
#include <time.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define lson l,m,rt*2
#define rson m+1,r,rt*2+1
#define mt(A,B) memset(A,B,sizeof(A))
using namespace std;
typedef long long LL;
//const double PI = acos(-1);
const int N=1e5+10;
const LL mod=1e9+7;
const int inf = 0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3fLL;
char s[N];
int main()
{
#ifdef Local
    freopen("data","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h=0,ans;
    scanf("%s",s);
    h=strlen(s);
    if(s[0]==s[h-1])
    {
        ans=h-2-1;
    }
    else ans=h-2;
    if(ans%2)puts("First");
    else puts("Second");
#ifdef Local
    cerr << "time: " << (LL) clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#endif
}


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

int top, S[1000];

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a, b;
  top = 0;
  char s[100];

  while(scanf("%s", s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }else{
      push(atoi(s));
    }
  }

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


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

int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i=0;i<N;i++) cin >> d[i];
    int S = 0;
    for (int i=0;i<N;i++) for (int j=i+1;j<N;j++) S += d[i]*d[j];
    cout << S << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

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

    ll res = INF;
    rep(i, SZ(s) - 2) { chmin(res, abs(stoi(s.substr(i, 3)) - 753LL)); }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B___ROT_N
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            char[] S = Console.ReadLine().ToCharArray();
            char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();

            if (N == 0)
            {
                Console.WriteLine(S);
                return;
            }

            var j = 0;
            foreach (var item in S)
            {
                var idx = Array.IndexOf(alpha, item);
                for (int i = 1; i <= N; i++)
                {
                    idx++;
                    if (idx >= 26)
                    {
                        idx = 0;
                    }
                }
                S[j] = alpha[idx];
                j++;
            }
            Console.WriteLine(S);
        }
    }
}


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

typedef long long ll;
const ll INF = 1e18;

std::vector<ll> a;
std::vector<ll> cum;
std::vector<std::vector<ll>> dp;

ll dps(int l, int r){
	if(dp[l][r] != INF) return dp[l][r];
	if(r-l == 1) return dp[l][r] = 0;

	for(int i=1; i<r-l; i++){
		dp[l][r] = std::min(dp[l][r], dps(l, l+i) + dps(l+i, r));
	}
	return dp[l][r] = dp[l][r] + cum[r] - cum[l];
}

int main(){
	int n;
	std::cin >> n;
	a = std::vector<ll>(n+1);
	cum = std::vector<ll>(n+1);
	for(int i=0; i<n; i++){
		std::cin >> a[i];
		cum[i+1] = a[i] + cum[i];
	}

	dp = std::vector<std::vector<ll>>(n+1, std::vector<ll>(n+1, INF));
	// d[i][j] : [i, j)にあるj-i体のスライムを一体にする最小のコスト
	std::cout << dps(0, n) << std::endl;
	return 0;
}

Measured memory_bytes: 1536
function main( input ) {
    const reverse = (s) => {
        return s.split('').reverse().join('');
    }

    const WORDS = ['dream', 'dreamer', 'erase', 'eraser'].map(reverse);
    const S = reverse(input.split('\n')[0]);

    let index = 0;
    while(true) {
        let w = WORDS.find( (w) => S.startsWith(w, index) );
        if(!w) break;
        index += w.length;
    }

    if( S.length === index ) {
        console.log('YES');
    } else {
        console.log('NO');
    }
}

main( require('fs').readFileSync('/dev/stdin', 'utf8') )

Measured memory_bytes: 36284
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>

int main()
{
    int n{}, x{}, y{};
    std::cin >> n >> x >> y;

    std::vector<int> result(n);

    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            auto d1 = j - i;
            auto d2 = std::abs(x - i) + std::abs(y - j) + 1;
            result[std::min(d1, d2)]++;
            //std::cout << i << "," << j << "," << std::min(d1, d2) << std::endl;
        }
    }
    for (int i = 1; i < n; i++) {
        std::cout << result[i] << std::endl;
    }

    return 0;
}


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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

void solve(){
    int n, k;
    cin >> n >> k;
    vi h(n);
    for(auto &it: h) cin >> it;

    vi dp(n, 1e9+5);
    dp[0] = 0;
    for(int i = 1; i < n; ++i){
        for(int j = max(i-k, 0); j < i; ++j){
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }
    cout << dp[n-1] << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


Measured memory_bytes: 4752
import fractions as math
from functools import reduce
 
 
N = int(input())
A=list(map(int, input().split()))
 
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
 
num = lcm_list(A)
 
ans = 0
 
for i in range(N):
    ans += (num // A[i])
 
print(ans%(10**9+7))

Measured memory_bytes: 6112
#include<cstdio>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,ans,u[100];vector<int> ad[100];
void dfs(int c,int m){
	if(ans<m)ans=m; int s=ad[c].size(),t;
	rep(i,s){
		t=ad[c][i];
		if(!u[t])u[t]=1,dfs(t,m+1),u[t]=0;
	}
}
int main(){
	while(scanf("%d",&n),n){
		ans=1;rep(i,100)u[i]=0,ad[i].clear();
		rep(i,n){
			int a,b; scanf("%d%d",&a,&b); a--,b--;
			ad[a].push_back(b),ad[b].push_back(a);
		}
		rep(i,100)if(!ad[i].empty()){
			u[i]=1;dfs(i,1);u[i]=0;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 820
n, q = map(int, input().split())

ct = [0] * (n + 1)
e = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    e[a].append(b)
    e[b].append(a)

qs = [0] * (n + 1)
for _ in range(q):
    p, q = map(int, input().split())
    qs[p] += q

target = [1]
visited = [0] * (n + 1)
while len(target):
    t = target.pop()
    visited[t] = 1
    ct[t] += qs[t]
    for nt in e[t]:
        if visited[nt] == 0:
            target.append(nt)
            ct[nt] += ct[t]

print(*ct[1:])


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

int n;
int cnt;

void solve(int indx, int s){

  if(s > n) return;
  if(s == n){
    cnt++; 
    return;
  }

  return solve(indx+1,s+indx);

}

int main(){

  while(cin >> n, n){

    cnt = 0;
    for(int i=1;i<n;i++) solve(i,0);
    cout << cnt << endl;

  }
    
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn =1e5+13;

int a[maxn];
int b[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	for(int i=1;i<=n-2;i++)
	{
		int cnt =0;
		for(int j=0;j<3;j++)
		{
			if(a[i+j]==b[i+j])
			{
				cnt++;
			}
		}
		if(cnt == 3)
		{
			return printf("Yes"),0;
		}
	}
	printf("No");
 } 

Measured memory_bytes: 3868
def gcd(a,b):
    if a<b:
        a,b=b,a
    if b==0:
        return a
    else:
        return gcd(b,a%b)
n=int(input())
A=list(map(int,input().split()))
F=[0]*n
B=[0]*n
F[0]=A[0]
B[-1]=A[-1]
for i in range(1, n):
    F[i]=gcd(F[i-1],A[i])
    B[-i]=gcd(B[-(i-1)],A[-i])
ans=[0]*n
ans[0]=B[1]
ans[-1]=F[-2]
for i in range(1,n-1):
    ans[i]=gcd(F[i-1],B[i+1])
print(max(ans))

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

#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9 + 10;

int h, w, k;
vector<vector<char>> c(h, vector<char>(w));
int ans;

void dfs_col(vector<int> rows, vector<int> cols) {
  vector<vector<bool>> reverse(h, vector<bool>(w, false));
  for (int r : rows) {
    for (int i = 0; i < w; i++) {
      reverse.at(r).at(i) = true;
    }
  }
  for (int c : cols) {
    for (int i = 0; i < h; i++) {
      reverse.at(i).at(c) = true;
    }
  }
  int cnt_b = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!reverse[i][j] && c[i][j] == '#') {
        cnt_b++;
      }
    }
  }
  if (cnt_b == k) {
    ans++;
  }

  if (rows.size() == h) {
    return;
  }
  if (rows.empty()) {
    rows.push_back(0);
  } else {
    rows.push_back(rows.back() + 1);
  }
  while (rows.back() != h) {
    dfs_col(rows, cols);
    rows.back()++;
  }
}

void dfs_row(vector<int> rows, vector<int> cols) {
  dfs_col(rows, cols);
  if (cols.size() == w) {
    return;
  }
  if (cols.empty()) {
    cols.push_back(0);
  } else {
    cols.push_back(cols.back() + 1);
  }
  while (cols.back() != w) {
    dfs_row(rows, cols);
    cols.back()++;
  }
}
int main() {
  cin >> h >> w >> k;
  c = vector<vector<char>>(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    string line;
    cin >> line;
    for (int j = 0; j < w; j++) {
      c[i][j] = line[j];
    }
  }
  dfs_row({}, {});
  cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;

    int ans = 0;

    for(int i=1; i<=n; i++){
      if((int)floor((log10(i)+1))%2 != 0){
        ans++;
      }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define endl "\n"
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         ll n,k;
         cin>>n>>k;
         ll ans = 0;
         ll pr[k+5];
         for(int i=0;i<k+5;i++)
          pr[i]=0;
         ll have = 0;
         for(ll i=k;i>=1;i--)
         {
              ll p1 = k/i;
              ll p2 = power(p1,n);
              for(ll j=2*i;j<=k;j+=i)
              {
                 p2 = (p2-pr[j]+mod)%mod;
                 p2%=mod;
              }
              pr[i] = p2;
              ans+=(p2*(i))%mod;
              ans%=mod;
         }
         ans%=mod;
         cout<<ans<<endl;

      }
      






}



























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

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let xy = readn::<usize>(" ");
    let x = xy[0];
    let y = xy[1];
    let mut now = x;
    let mut ans = 1;
    loop {
        if now * 2 > y {
            break;
        } else {
            now *= 2;
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

pair<string, pair<int, int>> p[110];
int n;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second.first;
    p[i].second.first = 100 - p[i].second.first;
    p[i].second.second = i+1;
  }
  
  sort(p, p+n);
  
  for (int i = 0; i < n; i++) {
    cout << p[i].second.second << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// 中央の数から始めると最適解は得られない？
#include<iostream>
#include<algorithm>
using namespace std;

int main() {
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;
  int M,m;
  M = max({a1,a2,a3});
  m = min({a1,a2,a3});
  cout << M-m << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    N, A = map(int, input().split())
    x = [0]
    x.extend(list(map(int, input().split())))

    dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
    for i in range(N + 1):
        dp[i][0][0] = 1

    for i in range(1, N + 1):
        for j in range(1, i + 1):
            for k in range(1, N * A + 1):
                if k < x[i]:
                    dp[i][j][k] = dp[i - 1][j][k]
                else:
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]]

    ans = 0
    for j in range(1, N + 1):
        ans += dp[N][j][A * j]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 94684
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	int n;
	cin >> n;

	vector<int>P(n);
	vector<int>Q(n);

	REP(i, n) cin >> P[i];
	REP(i, n) cin >> Q[i];

	vector<int>S(n);
	S = P;

	SORT(S);

	int i = 1;
	int a, b;
	do {
		if (S == P) {
			a = i;
		}if (S == Q) {
			b = i;
		}
		i++;
	} while (next_permutation(S.begin(), S.end()));

	cout << abs(a - b) << endl;
	
	return 0;

}

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

int main()
{
    int a[100005],b[100005],c[100005],n;
    long long ans = 0,nowa = 0,nowc = 0;

    scanf("%d", &n);

    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < n; i++) scanf("%d", &b[i]);
    for (int i = 0; i < n; i++) scanf("%d", &c[i]);

    sort (a, a + n);
    sort (b, b + n);
    sort (c, c + n);

    for (int i = 0; i < n; i++)
    {
        while ((a[nowa] < b[i]) && (nowa < n)) nowa++;
        while ((c[nowc] <= b[i]) && (nowc < n)) nowc++;

        ans = ans + nowa * (n - nowc);
    }

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

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
vector<int> d;
vector<int> f;
vector<bool> used;
vector< vector<int> > v;
int n;
int cnt = 0;


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

  cin >> n;
  d = f = vector<int>(n, -1);
  used = vector<bool>(n, false);
  v = vector< vector<int> >(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      a--;
      v[u][a] = 1;
    }
  }

  queue<int> que;
  que.push(0);
  d[0] = cnt;
  used[0] = true;
  while(!que.empty()){
    cnt++;
    int q = que.front(); que.pop();
    for(int i = 0; i < n; i++){
      if(v[q][i] && !used[i]){
        used[i] = true;
        que.push(i);
        d[i] = d[q]+1;
      }
    }
  }

  for(int i = 0; i < n; i++){
    cout << i+1 << " " << d[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1304
#include <stdio.h>

int main(){
    int a,b,c,save;
    scanf("%d %d %d", &a,&b,&c);
    if(a > b){
        save = a;
        a = b;
        b = save;
    }
    if(b > c){
        save = b;
        b = c;
        c = save;
    }
    if(a > b){
        save = a;
        a = b;
        b = save;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

int main(void) {
  long N;
  cin >> N;
  long result = 0;
  long beginWithB = 0;
  long endWithA = 0;
  long beginWithBAndEndWithA = 0;
  rep (i, N) {
    string tmp;
    cin >> tmp;
    if (tmp[0] == 'B' and tmp[tmp.size() - 1] == 'A') beginWithBAndEndWithA++;
    else if (tmp[0] == 'B') beginWithB++;
    else if (tmp[tmp.size() - 1] == 'A') endWithA++;
    rep (j, tmp.size() - 1) if (tmp[j] == 'A' and tmp[j+1] == 'B') result++;
  }
  if (beginWithBAndEndWithA) {
    result += beginWithBAndEndWithA - 1;
    beginWithBAndEndWithA = 1;
  }
  if (beginWithBAndEndWithA and beginWithB and endWithA) {
    result += 2;
    beginWithBAndEndWithA = 0;
    beginWithB --;
    endWithA --;
  }
  long tmp = min(beginWithB, endWithA);
  if (beginWithB != endWithA and beginWithBAndEndWithA) tmp++;
  result += tmp;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int cnt[N];

void solve(){
    int n;
    cin >> n;
    for (int i = 1, p; i < n; i++){
        cin >> p;
        cnt[p]++;
    }
    for (int i = 1; i <= n; i++){
        cout << cnt[i] << endl;
    }
}

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 4432
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll arr[100005];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		if (arr[i] < 0) {
			++cnt;
			arr[i] = -arr[i];
		}
	}
	cnt %= 2;
	sort(arr, arr + n);
	if (cnt)
		arr[0] = -arr[0];
	ll ans = 0;
	for (int i = 0; i < n; ++i)
		ans += arr[i];
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1024
x,a[32],r,F="%d%d\n";S(k,b,m){k-x?S(k+1,b,m),++m<r&&S(k+1,b|a[k],m):(r=b-~(~0<<x)|m>r?r:m);}main(i,j,y){for(;scanf(F,&x,&y)*x;S(0,0,0),printf(F+2,r)){for(r=i=x;i--;)a[i]=1<<i;for(;y--;a[i]|=1<<j,a[j]|=1<<i)scanf(F,&i,&j);}}

Measured memory_bytes: 408
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ld a, b, h, m;

ld solve() {
    ld x0 = b*cos(2*pi*m/60);
    ld y0 = b*sin(2*pi*m/60);
    ld x1 = a*cos(2*pi*(h*60+m)/(12*60));
    ld y1 = a*sin(2*pi*(h*60+m)/(12*60));
    return sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
}

void input() {
    cin >> a >> b >> h >> m;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
 
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
 
const ll inf=1e10;
const ll maxs =1e5+5;
const ll mod = 1e9+7;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define line cout<<endl;
#define fr(i,b) for(ll i=1;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
ll n,m,ans;
vll Graph[maxs];
bool visited[maxs];
std::queue<ll> topo;
ll dp[maxs];
 
void addEdge()
{
    ll s,d;cin>>s>>d;
    Graph[s].pb(d);
}
 
void dfs(ll s)
{
    visited[s]=true;
    for(auto i:Graph[s])
        if(!visited[i])
            dfs(i);
    topo.push(s);
}
 
 
void solve()
{
    memset(visited,false,sizeof visited);
    for(ll i=1;i<=n;i++)
        if(!visited[i])
            dfs(i);
    
    memset(dp,0,sizeof dp);
    while(!topo.empty())
    {
        ll s = topo.front();
        topo.pop();
        
        for(auto child : Graph[s])
        {
            dp[s] = max(dp[s],1+dp[child]);
        }
        
         
    }      
    ans = -1;
    for(ll i=1;i<=n;i++)
        ans = max(ans,dp[i]); // no. of nodes in path;
    cout<<ans;    
}
 
int main()
{
    fastio();
     ll t=1;
     // cin>>t;
     while(t--){
        cin>>n>>m;
        while(m--)
            addEdge();
        solve();        
     }
    return 0;
}
 

Measured memory_bytes: 9472
s=input().rstrip()
x=list(s)
R=0;
P=0;
ans = 0;
for i in range(0,len(x)):
    if i==0:
        R+=1;
        if x[i]=='p':
            ans-=1;
    else:
        if x[i]=='g':
            if (P+1) <= R:
                P+=1;
                ans+=1;
            else:
                R+=1;
        else:
            if (P+1) <= R:
                P+=1;
#                ans+=1;
            else:
                R+=1;
                ans-=1;
print(ans)

Measured memory_bytes: 3956
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let v: Vec<usize> = (0..n).map(|_| read()).collect();
    let m: usize = 10*10*10*10*10*10*10*10*10 + 7;

    let mut answer = 0;
    let mut sum = 0;
    for i in 0..n {
        sum += v[i];
        sum %= m;
    }
    for i in 0..(n-1) {
        if sum <= v[i] {
            sum += m;
        }
        sum -= v[i];
        answer += sum * v[i] % m;
        answer %= m;
    }
    println!("{}", answer);
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for( auto &i : v ){
		cin >> i;
	}
	sort(v.begin(), v.end());
	int total = accumulate(v.begin(), v.end(), 0);
	if( total % 10 != 0 ){
		cout << total << endl;
		return 0;
	}
	for( int i = 0; i < n; ++i ){
		if( (total - v[i])%10 != 0 ){
			cout << total - v[i] << endl;
			return 0;
		}
	}
	cout << "0" << endl;
	return 0;
}

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

#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 0
#endif
using namespace std;

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << ": " << arg1 << 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...);
}

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = (int) 5e5 + 2;
int ar[NN];
int n, m;



integer main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int k;
    cin >> k;
    if (k == 1) {
        cout << 1 << endl;
        return 0;
    }
    int cnt = 1;
    int n = 7;
    while (n < k){
        n = n * 10 + 7;
        cnt++;
    }
    unordered_set<int> S;
    S.insert(n);
    while (1){
        int r = n / k;
        n = n - r * k;
        if (n == 0){
            cout << cnt << endl;
            return 0;
        }
        while (n < k){
            n = n * 10 + 7;
            cnt++;
        }
        if (S.count(n)){
            cout << -1 << endl;
            return 0;
        }
        S.insert(n);
    }


}


Measured memory_bytes: 39464
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
  public static int digitNumber(int a, int b){ 
    int sum = a + b;
    String sumString = Integer.toString(sum);
    int digit = sumString.length();
    return digit;
  }
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = new String();
    while ((line = br.readLine()) != null) {
      // 入力をもらう
      String[] inputArray = line.split(" ");
      int answer = digitNumber(Integer.parseInt(inputArray[0]),Integer.parseInt(inputArray[1]));
      System.out.println(answer);
    }   
  }
}

Measured memory_bytes: 17000
#include <stdio.h>

int main(void)
{
	int in[100], out[100];
	int i, j, f;
	
	i = 0;
	j = 0;
	
	
	while (scanf("%d", &in[i]) != EOF){
		if (in[i] == 0){
			out[j] = in[i - 1];
			i--;
			j++;
		}
		else {
			i++;
		}
	}
	
	for (f = 0; f < j; f++){
		printf("%d\n", out[f]);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include<stdio.h>

int main(void){
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if((W >= (x + r) && 0 <= (x - r)) && (H >= (y + r) && 0 <= (y - r))){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 2676
#include<cstdio>

using namespace std;

typedef long long ll;

ll x, y;

int main() {
	scanf("%lld %lld", &x, &y);
	if (x == y) {
		printf("-1\n");
		return 0;
	}
	for (int i = 1; i < y; i++) {
		if ((x * i) % y) {
			printf("%lld\n", x * i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

void push(int);
int pop(void);

int top,S[1000];
int main(){
  int x,y;
  char a[100];

  while(scanf("%s",a)!=EOF){
    if(a[0]=='+'){
      x=pop();
      y=pop();
      push(y+x);
    }
    else if(a[0]=='-'){
      x=pop();
      y=pop();
      push(y-x);
    }
    else if(a[0]=='*'){
      x=pop();
      y=pop();
      push(y*x);
    }
    else push(atoi(a));


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

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;
  return S[top+1];
}



Measured memory_bytes: 2732
using System;

namespace B___ss
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            while (true)
            {
                 S = S.Substring(0, S.Length - 1);
                if (S.Substring(0, S.Length / 2) == S.Substring(S.Length / 2, S.Length - S.Length / 2))
                    break;
            }

            Console.WriteLine(S.Length);
        }
    }
}


Measured memory_bytes: 11092
n,m=map(int, input().split())  
sc=[]
for i in range(m):
    s,c=map(int, input().split()) 
    sc.append((s,c))

ans=-1
flg=True

for i in range(1000):
    flg=True
    if len(str(i))!=n:
        continue
    stri=str(i)
    for j in range(m):
        if stri[sc[j][0]-1]!=str(sc[j][1]):
            flg=False
            break
        else:
            continue
    if flg:
        ans=i
        break

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#define pi 3.14159265358979

int main(){
	double teku[10000]={0.0},sita=pi/2,set_sita[10000]={0.0},x=0.0,y=0.0;
	int i=0;
	
	while(scanf("%lf,%lf",&teku[i],&set_sita[i])!=EOF){
		if(teku[i]==0 && set_sita[i]==0)break;
		
		set_sita[i]=set_sita[i]/180.0 * pi;
		
		x+=teku[i]*cos(sita);
		y+=teku[i]*sin(sita);
		sita-=set_sita[i];
		i++;
	}
	if(x>0)x=floor(x);
	else x=ceil(x);
	
	if(y>0)y=floor(y);
	else y=ceil(y);
	
		printf("%.0f\n%.0f\n",floor(x),floor(y));
	return 0;
}

Measured memory_bytes: 1248