akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
v = [[] for _ in range(N)]
for i in range(M) :
    s, t = map(int, input().split())
    v[s-1].append(t-1)

# 削除しないでdp
dp = [0] * N
for i in range(N - 1, -1, -1) :
    if len(v[i]) == 0 :
        continue
    
    for j in v[i] :
        dp[i] += dp[j]
    dp[i] = 1 + dp[i] / len(v[i])
    
ret = dp[0]
# 削除してdp
for i in range(N - 1) :
    if len(v[i]) <= 1 :
        continue
        
    dp[i] = 0
    M = -1
    for j in v[i] :
        dp[i] += dp[j]
        M = max(M, dp[j])
    dp[i] = 1 + (dp[i] - M) / (len(v[i]) - 1)
    
    for j in range(i - 1, -1, -1) :
        if len(v[j]) == 0 :
            continue
            
        dp[j] = 0
        for k in v[j] :
            dp[j] += dp[k]
        dp[j] = 1 + dp[j] / len(v[j])
    
    ret = min(ret, dp[0])

print(ret)

Measured memory_bytes: 56700
#include<bits/stdc++.h>
using namespace std;
int main(){
    string su;
    int i, sum;
    while(1){
        i = 0;
        sum = 0;
        cin >> su;
        if(su[0] == '0'){
            return 0;
        }
        while(su[i] != '\0'){
            sum += su[i]-'0';
            i++;
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3200
s=input()
flag1 = False
flag2 = False
flag3 = False

if s[0] == "A":
    flag1 = True
    
cnt = 0
idx = -1
for i in range(2, len(s)-1):
    if s[i]=="C":
        cnt += 1
        idx = i
if cnt == 1:
    flag2 = True
    
if flag2:
    flag3 = True
    for i in range(len(s)):
        if i != 0 and i != idx and s[i].lower()!=s[i]:
            flag3 = False

if flag1 and flag2 and flag3:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int T = X + Y + Z;
		long mod = (long) 1e9 + 7;
		
		long[] dp = new long[1<<T];
		dp[0] = 1;
		for(int i=0;i<N;i++){
			long[] ndp = new long[1<<T];
			for(int j=0;j<(1<<T);j++){
				if(dp[j] == 0) continue;
				for(int k=1;k<=10;k++){
					// 0|12345|1234567|12345
					int nxt = 0;
					if(k <= X) nxt |= (1 << k);
					for(int x=1;x<X;x++){
						if(((j >> x) & 1) == 0) continue;
						if(x + k <= X){
							nxt |= (1 << (x + k));
						}
					}
					if(((j >> X) & 1) == 1){
						if(k <= Y){
							nxt |= (1 << (X + k));
						}
					}
					for(int y=1;y<Y;y++){
						if(((j >> (X + y)) & 1) == 0) continue;
						if(y + k <= Y){
							nxt |= (1 << (X + y + k));
						}
					}
					if(((j >> (X + Y)) & 1) == 1){
						if(k <= Z){
							nxt |= (1 << (X + Y + k));
						}
					}
					for(int z=1;z<Z;z++){
						if(((j >> (X + Y + z)) & 1) == 0) continue;
						if(z + k <= Z){
							nxt |= (1 << (X + Y + z + k));
						}
					}
					
					if(nxt < (1<<T)){
						ndp[nxt] += dp[j];
						if(ndp[nxt] >= mod) ndp[nxt] -= mod;
					}
				}
			}
			dp = ndp;
		}
		
		long notcontain = 0;
		foreach(var n in dp){
			notcontain += n;
			if(notcontain >= mod) notcontain -= mod;
		}
		
		long tot = 1;
		for(int i=0;i<N;i++){
			tot *= 10;
			tot %= mod;
		}
		
		long ans = (tot - notcontain + mod) % mod;
		Console.WriteLine(ans);
		
		
	}
	int N, X, Y ,Z;
	public Sol(){
		var d = ria();
		N = d[0]; X = d[1]; Y = d[2]; Z = d[3];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

#define mod 1000000007 
#define check exit(0)
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace __gnu_pbds;
using namespace std;

int main()
{
    jaldi
    ll l;
    cin>>l;
    double one,two,three;
    one=two=three=l/3.0;
    long double ans=one*two*three;
    cout<<fixed<<setprecision(8)<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;

int main(void) {

    vector<int> A(3,0);
    cin>>A[0]>>A[1]>>A[2];

    sort(A.begin(), A.end());
    int cnt=0;
    while(A[0]!=A[2]){
        if(A[1]<A[2]){
            A[1]++;
            A[0]++;
        }else{
            A[0] += 2;
        }
        cnt++;
        sort(A.begin(), A.end());
    }

    cout<<cnt<<endl;

    return 0;
}

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

char solve(string& expr, int ans) {
    for (int i = 0; i < int(expr.size()); i += 2) expr[i] -= '0';
    return "ILMU"[
        ([&] {
            int ans_ = expr[0];
            for (int i = 1; i < int(expr.size()); i += 2) {
                ans_ = expr[i] == '+' ? ans_ + expr[i + 1]: ans_ * expr[i + 1];
            }
            return ans == ans_;
        }() << 0) |
        ([&] {
            stack<int> s; s.push(expr[0]);
            for (int i = 1; i < int(expr.size()); i += 2) {
                if (expr[i] == '+') s.push(expr[i + 1]);
                else {
                    int e = s.top() * expr[i + 1];
                    s.pop(); s.push(e);
                }
            }
            int ans_ = 0;
            for (; !s.empty(); s.pop()) ans_ += s.top();
            return ans == ans_;
        }() << 1)];
}

int main() {
    string expr; int ans;
    cin >> expr >> ans;
    cout << solve(expr, ans) << endl;
}

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

int GCD(long long a,long long b)
{
    int c;
    while(b)
    {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}


int main()
{   long long a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld",a*b/GCD(a,b));

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 21;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll w,h,x,y;
    cin >> w >> h >> x >> y;
    printf("%0.10f\n",(double)w*h/2.0);
    if (2*x == w && 2*y == h) printf("1\n");
    else printf("0\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int H, W;
  std::cin >> H >> W;
  std::vector<string> ans;
  std::vector<int> cols(W, 1);
  range(i, H){
    string s;
    std::cin >> s;
    int flag = 1;
    range(j, W){
      if(s[j]=='#'){
        cols[j] = 0;
        flag = 0;
      }
    }
    if(flag == 0) {
      ans.push_back(s);
    }
  }
  range(i, ans.size()){
    range(j, W){
      if(cols[j] == 0) std::cout << ans[i][j];
    }
    std::cout <<'\n';
  }
  return 0;
}


Measured memory_bytes: 380
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
ll n,m,i,j,k,l,t,arr[sz],brr[sz],crr[sz],drr[sz];
int main()
{
    ll mx=100000000000009;
    scanf("%lld",&n);
    if(n==0)
    {
        scanf("%lld",&m);
        printf("%lld\n",m==1?1ll:-1ll);
        return 0;
    }
    for(i=0;i<=n;i++){
        scanf("%lld",&arr[i]);
      if(arr[i]>m*2)
        l=1;
      else
      {
          if(i==0)
            m=1;
          else
          m=min(m*2,mx);
          brr[i]=m;
          m-=arr[i];
      }
    }
    if(l==1)
    {
        printf("-1\n");
        return 0;
    }
    m=0;
    for(i=n;i>=0;i--)
    {
        m+=arr[i];
        m=min(m,brr[i]);
        t+=m;
    }
    printf("%lld\n",t);
}


Measured memory_bytes: 5372
#include<bits/stdc++.h>
using namespace std;
double dis(int x1,int x2,int y1,int y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
int n;
  cin>>n;
  int x[n],y[n];double sum=0;double avg;
  for(int i=0;i<n;i++)
    cin>>x[i]>>y[i];
  for(int i=0;i<n;i++)
    for(int j=i;j<n;j++)
    {
    sum=sum+dis(x[i],x[j],y[i],y[j]);
    }
avg=(sum*2)/(n);cout<<fixed<<setprecision(10)<<avg;}

Measured memory_bytes: 256
n, m, = map(int, input().split())
a = list(map(int, input().split()))
list.sort(a, reverse=True)

ret = "Yes"
a_sum = sum(a)
a_min = a_sum / (4 * m)
for i in range(m):
    if a[i] < a_min:
        ret = "No"
        break

print("{}".format(ret))

Measured memory_bytes: 3060
#include <iostream>
#include <unordered_set>

using namespace std;

int main()	{
  long long n;
  cin >> n;
  unordered_set<int> buttons;
  long long b[n + 1] = {1};
  long long dest = 1;
  long long curr_button = 1;
  long long nmoves = 0;
  for (long long i = 1; i <= n; i++)	{
    cin >> b[i];
  }
  buttons.insert(1);
  while(1)	{
    if (dest == 2)	{
      break;
    }
    dest = b[dest];
    if (buttons.find(dest) != buttons.end())	{
      cout << -1 << endl;
      break;
    }
    else	{
      buttons.insert(dest);
      nmoves++;
    }
  }
  if (dest == 2)
    cout << nmoves << endl;
  return 0;
}

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

int main() {
  int N,x;
  cin>>x>>N;
  vector<vector<int>> p(N+1,vector<int>(N+1,1000));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>p.at(i+1).at(j+1);
    }
  }
  int A=250000000;
  vector<int>a(N);
  vector<int>b(N);
  vector<int>c(N);
  for(int i=0;i<x;i++){
    for(int j=0;j<x;j++){
      int z;
      cin>>z;
      if((i+j)%3==0){
        for(int k=0;k<N;k++){
          a.at(k)+=p.at(z).at(k+1);
        }
      }
      else if((i+j)%3==1){
        for(int k=0;k<N;k++){
          b.at(k)+=p.at(z).at(k+1);
        }
      }
      else if((i+j)%3==2){
        for(int k=0;k<N;k++){
          c.at(k)+=p.at(z).at(k+1);
        }
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int k=i+1;k<N;k++){
      for(int j=k+1;j<N;j++){
        A=min(A,a.at(i)+b.at(k)+c.at(j));
        A=min(A,a.at(i)+b.at(j)+c.at(k));
        A=min(A,a.at(j)+b.at(i)+c.at(k));
        A=min(A,a.at(j)+b.at(k)+c.at(i));
        A=min(A,a.at(k)+b.at(i)+c.at(j));
        A=min(A,a.at(k)+b.at(j)+c.at(i));
      }
    }
  }
  
  cout<<A<<endl;
}

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

#define rep(i, n) for (ll i=0;i<(n); i++)

using namespace std;
//using ll=long long;
typedef long long ll;
typedef pair<ll, ll> pi;



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

  ll c[10][10];

  rep(i,10){
    rep(j,10) cin>>c[i][j];
  }

  ll a[h][w];
  
  rep(i,h){
    rep(j,w) cin>>a[i][j];
  }

  rep(k,10){
    rep(i,10){
      rep(j,10){
	c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
	}
    }
  }


  ll ans = 0;
  rep(i,h){
    rep(j,w){
      if(a[i][j]>=0) ans += c[a[i][j]][1]; 
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 512
x, n = map(int, input().split())
a = list(map(int, input().split()))

abs_min = int(1e5)
ans = -1
for i in range(0, 102):
    if i in a:
        continue
    if abs(x - i) < abs_min:
        abs_min = abs(x - i)
        ans = i
print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n,k,a[105],dp[100005];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> k;
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=k;i++){
        for(int j=1;j<=n;j++){
            if(i>=a[j] && dp[i-a[j]]==0) dp[i]=1;
        }
    }
    if(dp[k]) cout << "First";
    else cout << "Second";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
#define endl '\n'
#define F first
#define S second
const int MAX_N=1e3+3;
const int MAX_W=1e4+4;

int n;
struct Block
{
	int w, s, v;
	bool operator < (const Block &r) const
	{
		return w+s<r.w+r.s;
	}
} b[MAX_N];
ll dp[2*MAX_W];
ll ans;

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d%d%d",&b[i].w,&b[i].s,&b[i].v);
	sort(b,b+n);
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	for(int i=0;i<n;i++) for(int j=b[i].s;j>=0;j--)
		if(~dp[j]) dp[j+b[i].w]=max(dp[j+b[i].w],dp[j]+b[i].v);
	for(int i=0;i<2*MAX_W;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 384
#include <cstdio>
int main(){
	int x, y, z;
	while(1){
		scanf("%d%d", &x, &y);
		if(x == 0 && y == 0) return 0;
		while(x--){
			z = y;
			while(z--){
				putchar('#');
			}
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 2576
N,C=gets.split.map(&:to_i)

task=Array.new(C){Array.new}
N.times do
    s,t,c=gets.split.map(&:to_i)
    task[c-1] << [s,t]
end

task2=Array.new(10**5+10,0)
task.each do |channel|
    next if channel.size==0
    channel.sort!
    lasts,lastt=channel.shift
    channel.each do |s,t|
        if lastt==s
            lastt=t
        else
            task2[lasts-1]+=1
            task2[lastt]-=1
            lasts,lastt=s,t
        end
    end
    task2[lasts-1]+=1
    task2[lastt]-=1
end

temp=0
p task2.map{|t| temp+=t}.max


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;


ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}



int main() {


	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	ll e = (c*d) / gcd(c, d);


	ll ans = b - a + 1;

	ll f = (b / c) - (a / c);
	if (a%c == 0)f++;
	//if (b%c == 0)f--;
	ll g = (b / d) - (a / d);
	if (a%d == 0)g++;
	//if (b%d == 0)g++;
	ll h = (b / e) - (a / e);
	if (a%e == 0)h++;
	//if (b%e == 0)e--;

	//cout << ans << ' ' << f << ' ' << g << ' ' << h << endl;

	cout << ans - f - g + h << endl;




}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll gcd(ll a, ll b){
    ll r,temp;
    if (a < b){
        temp = a;
        a = b;
        b = temp;
    }
    while ( (r = a % b) != 0){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    ll N,M;
    cin >> N >> M;
    string S,T;
    cin >> S >> T;
    ll x = gcd(N, M);
    ll Nx = N / x;
    ll Mx = M / x;
    ll N_now = 0;
    ll M_now = 0;
    bool possible = true;
    for (ll i = 1; i <= x; i++){
        if (S[N_now] != T[M_now]) possible = false;
        N_now += Nx;
        M_now += Mx;
    }
    if (!possible) cout << -1 << endl;
    else cout << N * M / x << endl;
}


Measured memory_bytes: 3764
def main():
    import sys
    input = sys.stdin.readline

    N, W = map(int, input().split())
    WV = [list(map(int, input().split())) for i in range(N)]

    V = 10**3*N
    inf = float("inf")
    dp = [[inf] * (V+1) for _ in range(N+1)]

    dp[0][0] = 0
    # i種類目までの荷物を見る
    for i in range(N):
        # その荷物を価値がjになるように持つ
        for j in range(V + 1):
            w, v = WV[i]

            if v <= j:
                # 荷物iを選ぶ場合
                dp[i+1][j] = min(dp[i+1][j], dp[i][j-v] + w)
            # 荷物iを選ばない場合
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])

    # print(dp)
    max_ind = 0
    for j in range(V+1):
        if dp[-1][j] <= W:
            max_ind = j
    print(max_ind)


if __name__ == "__main__":
    main()


Measured memory_bytes: 313080
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <math.h>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;


#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()


const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    int n; cin>>n;
	cout << pow(n,3);
	return 0;
}



Measured memory_bytes: 256
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        // input -> index
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 1; i <= N; i++) {
            map.put(sc.nextInt(), i);
        }
        List<Map.Entry<Integer, Integer>> entries =
        map.entrySet().stream().sorted(java.util.Map.Entry.comparingByKey()).collect(Collectors.toList());

        for (Map.Entry<Integer, Integer> entry : entries) {
            System.out.print(entry.getValue() + " ");
        }
    }

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

Measured memory_bytes: 74088
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
bool cmp(pair<int,int> a, pair<int,int> b) {
    return a.first+a.second > b.first+b.second;
}
int main () {
    int n;
    scanf("%d", &n);
    vector<pair<int,int>> v;
    for(int i = 0 ; i < n ; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        v.push_back(make_pair(x, y));
    }
    sort(v.begin(), v.end(), cmp);
    long long ans = 0;
    for(int i = 0 ; i < n ; i++) {
        if(i%2==0) ans += v[i].first;
        else ans -= v[i].second;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1400
import numpy as np

N = int(input())
s = input()
w = np.array(list(map(lambda x: 1 if x == 'W' else 0, s)))
e = np.array(list(map(lambda x: 1 if x == 'E' else 0, s)))
w = np.cumsum(w)
# w = np.add.accumulate(w)
# e = e[::-1]
e = np.cumsum(e[::-1])[::-1]
# e = np.add.accumulate(e)
# e = e[::-1]
ans = []
for i in range(N):
    num = 0
    if 0 < i: num += w[i - 1]
    if i < N - 1: num += e[i + 1]
    ans.append(num)
print(min(ans))

Measured memory_bytes: 33232
def divisors(n):
	divs = {1:0,n:0}
	i = 2
	while i*i<=n:
		if n%i==0:
			divs[i] = 0
			divs[n/i] = 0
		i += 1
	return divs

N = raw_input()
N = int(N)

print(len([i for i in range(3,N+1,2) if len(divisors(i))==8]))




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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

double seica(double a){
	double sum = (a + 1.) * a / 2;
	return sum / a;
}

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

	ll n, k;cin >> n >> k;
	vector<double> v(n);
	REP(i, n)cin >> v[i];

	double ans = 0;
	double now = 0;
	REP(i, n){
		now += seica(v[i]);
		if(i >= k)now -= seica(v[i-k]);
		ans = max(ans, now);
	}

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


Measured memory_bytes: 1792
#include<iostream>
#include<cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 500;
const int inf = (1<<20);
int cap[N][N];
int flow[N][N];
bool vis[N];

int fordFulkerson(const int n,const int t,int now,int fl){
  if (now == t)return fl;
  if (vis[now])return 0;
  vis[now]=true;
  int tmp=0;
  rep(i,n){
    int &next=i;
    if (cap[now][i] - flow[now][i] > 0){
      tmp=fordFulkerson(n,t,next,min(fl,cap[now][i]-flow[now][i]));
      if (tmp != 0){
	flow[now][next]+=tmp;
	flow[next][now]=-flow[now][next];
	return tmp;
      }
    }
  }
  return 0;
}

int maxFlow(int n,int s,int t){
  int tmp=0,ret=0;
  rep(i,n)vis[i]=false;
  while((tmp = fordFulkerson(n,t,s,inf)) != 0){
    ret+=tmp;
    rep(i,n)vis[i]=false;
  }
  return ret;
}

bool dfs(int n,int now,int t){
  if (now == t)return true;
  if (vis[now])return false;
  vis[now]=true;
  rep(i,n){
    int &next=i;
    if (flow[now][next] < 0){
      if (dfs(n,next,t)){
	flow[now][next]=flow[next][now]=0;
	return true;
      }
    }
  }
  return false;
}

int dfs2(int n,int now,int t){
  if (now == t)return 1;
  if (vis[now])return 0;
  vis[now]=true;
  rep(i,n){
    int &next=i;
    if (cap[now][next]-flow[now][next] > 0){
      if (dfs2(n,next,t)){
	flow[now][next]+=1;
	flow[next][now]=-flow[now][next];
	return 1;
      }
    }
  }
  return 0;
}


main(){
  int n,e,q;
  while(cin>>n>>e>>q){
    const int s = 0,t=n-1;
    rep(i,n)rep(j,n)cap[i][j]=0,flow[i][j]=0;
    rep(i,e){
      int f,t;
      cin>>f>>t;
      f--;t--;
      cap[f][t]=1;
      cap[t][f]=1;
    }
    int prev=maxFlow(n,s,t);
    rep(i,q){
      int a,from,to,tmp;
      cin>>a>>from>>to;
      from--;to--;
      if (a == 1){//add
	cap[from][to]=cap[to][from]=1;
	tmp = maxFlow(n,s,t);
#ifdef DEBUG1
	cout <<"add:";
#endif
	cout << prev+tmp << endl;
	prev=prev+tmp;
      }else if (flow[from][to] == 0){
#ifdef DEBUG1
	cout <<"noflow:";
#endif
	cap[from][to]=cap[to][from]=0;
	cout << prev << endl;
      }else {//delete
#ifdef DEBUG1
	cout <<"del:";
#endif
	if (flow[from][to] < 0)swap(from,to);
	cap[from][to]=cap[to][from]=0;
	flow[from][to]=flow[to][from]=0;

	rep(j,n)vis[j]=false;
	int fordFulkerson(const int n,const int t,int now,int fl);
	//tmp=dfs2(n,from,to);
	tmp=fordFulkerson(n,to,from,1);
	if (tmp != 0){
	  cout << prev << endl;
	  prev=prev;//keep
	}else {
	  rep(j,n)vis[j]=false;
	  dfs(n,from,s);
	  rep(j,n)vis[j]=false;
	  dfs(n,t,to);
	  cout << prev-1 << endl;
	  prev=prev-1;
	}
      }
    }
#ifdef DEBUG
    cout << "end " << endl;
#endif
  }
}

Measured memory_bytes: 2832
using System;
using System.Linq;

namespace ConsoleApp1111
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var a = n.Distinct().Count();

            if(a == 2)
            {
                Console.WriteLine("Yes");
            }else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int x,y,s,sum,max;

	while(cin >> x >> y >> s){
		if((x==0)&&(y==0)&&(s==0)){return 0;}

		max = 0;

		for(int i=1; i<s-1; i++){
			for(int j=s-1; j >= i ; j--){

				sum =  (int)( (i*(100+x)) / 100) + (int)( (j*(100+x)) / 100);

				if(sum == s){
					sum =  (int)( (i*(100+y)) / 100) + (int)( (j*(100+y)) / 100);
					if(sum > max){ max = sum;}
				}
				if(sum < s){ break;}
				}
		}
		cout << max << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;

int gcd(int a,int b){
    int t;
    while(b>0){
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

int main(){
    ll a,b,c,d,e,k,l,m,n,o=1,o1=9,o2=10,p,q,x,y,z,max1=0,ans=0,n1;
    string s,t,u;
    cin>>n;
    
    while(n>=o2){
        if(o%2==1){
            ans+=o1;
        }
        o++;
        o1*=10;
        o2*=10;
    }
    if(o%2==0)cout<<ans<<endl;
    else{
           cout<<ans+n-o2/10+1<<endl;
    }
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k;
	cin>>n>>k;
	ll arr[n+2];
	for(ll i=0;i<n;i++)
		cin>>arr[i];
	vector<bool> dp(k+1);
	dp[0]=false;
	for(ll i=1;i<=k;i++)
	{
		for(ll j=0;j<n;j++)
		{
			if(i-arr[j]>=0)
			{
				dp[i]=dp[i] || !dp[i-arr[j]];
			}
		}
	}
	cout<<(dp[k] ? "First\n" : "Second\n");
}

Measured memory_bytes: 3576
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n, t, a;
  cin >> n >> t >> a;
  double res = inf;
  int index = -1;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    double T = (double)t - (double)x * 0.006;
    if(res > abs(T - a)){
      res = abs(T - a);
      index = i + 1;
    }
  }
  cout << index << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<iomanip>
#include<math.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main() {
    long long S = 0,W=0;
    char szBuf[10000] = { 0 };
    cin >> S;
    cin >> W;
    if (S > W)
        cout << "safe" << endl;
    else cout << "unsafe" << endl;
    return 0;
}

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

int main() {
	int bingo[3][3];
	for(int i=0;i<3;++i){
		for(int j=0;j<3;++j){
			cin>>bingo[i][j];
		}
	}
	int N;
	cin>>N;
	int tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		for(int j=0;j<3;++j){
			for(int k=0;k<3;++k){
				if(bingo[j][k]==tmp)bingo[j][k]=-1;
			}
		}
	}
	bool ans = false;
	for(int i=0;i<3;++i){
		bool tmp1 = true;
		for(int j=0;j<3;++j){
			if(bingo[i][j]!=-1)tmp1 = false;
		}
		ans = tmp1;
		if(ans)break;
		tmp1 = true;
		for(int j=0;j<3;++j){
			if(bingo[j][i]!=-1)tmp1 = false;
		}
		ans = tmp1;
		if(ans)break;
	}
	if(bingo[0][0]==bingo[1][1] & bingo[0][0]==bingo[2][2])ans = true;
	if(bingo[2][0]==bingo[1][1] & bingo[2][0]==bingo[0][2])ans=true;
	if(ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;

    ll n; cin >> n;
    vector<int> a(n+1,0);
    rep(i,1,n+1) cin >> a[i];

    vector<int> ans(n+1,0);
    ll m = 0;

    for(ll i=n;i>=1;i--){
        ll k = i;  ll flag = 0;
        while(k<=n){
            flag += ans[k];
            k += i;
        }
        flag = flag%2;
        if(flag != a[i]){
            ans[i] = 1;
            m++;
        }
    }

    cout << m << endl;
    rep(i,1,n+1){
        if(ans[i] > 0) cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<stack>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
#define in 1000000007
int main()
{
   char s[15];
   char next[5]="YAKI";
   cin>>s;
   if(strlen(s)<4) cout<<"No"<<endl;
   else{
   int i;
   for(i=0;i<4;i++)
      if(s[i]!=next[i]) break;
      if(i>=4) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
   }
    return 0;
}


Measured memory_bytes: 256
D, G = map(int, input().split())
p = [0] * D
c = [0] * D
for i in range(D):
    p[i], c[i] = map(int, input().split())
ans = float('inf')
for bit in range(1 << D):
    score = 0
    cnt = 0
    l = [0] * D
    for j in range(D):
        if (bit >> j) & 1 == 1:
            score += p[j] * 100 * (j + 1) + c[j]
            cnt += p[j]
            l[j] = 1
    if score < G:
        idx = -1
        for k, v in enumerate(l):
            if v == 0:
                idx = k
        if idx != -1:
            p_copy = p.copy()
            while score < G and p_copy[idx] > 0:
                score += (idx + 1) * 100
                cnt += 1
                p_copy[idx] -= 1
    if score < G:
        continue
    ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 3192
N = int(input())

mul = []
for i in range (1,round(N**(1/2) + 1)):
    if N%i == 0:
        mul.append(i)
        mul.append(N//i)
#print(mul)

min = mul[0] + mul[1]
for i in range (0,len(mul),2):
    if mul[i] + mul[i+1] <= min:
        min = mul[i] + mul[i+1]

print(min-2)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];
    int x = 0, y = 0;
    rep(i, n) {
        if (v[i] > c[i]) {
            x += v[i];
            y += c[i];
        }
    }
    cout << x - y << endl;
    return 0;
}

Measured memory_bytes: 256
s=list(input())
l=len(s)
ans=0

if len(set(s))==1:
    for i in range(1,l+1):
        ans+=i
    print(ans)
    exit()

for i in range(l-1):
    if s[i]=="<" and s[i+1]==">":
        left=1
        right=1
        for j in range(i):
            if s[i-j-1]=="<":
                left+=1
            else:
                break
        for j in range(l-i-2):
            if s[i+j+2]==">":
                right+=1
            else:
                break
        p=max(left,right)
        q=min(left,right)
        for j in range(p):
            ans+=(j+1)
        for j in range(q-1):
            ans+=(j+1)
if s[0]==">":
    ans+=1
    for i in range(1,l):
        if s[i]==">":
            ans+=(i+1)
        else:
            break
if s[-1]=="<":
    ans+=1
    for i in range(2,l+1):
        if s[-i]=="<":
            ans+=i
        else:
            break
print(ans)

Measured memory_bytes: 98068
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    string s;
     cin>>s;
     bool flag = true;
     int l=s.size();
     for(int i=0;i<l;i++ )
     {
         if((s[i]=='R'&& (i+1)%2==0)  || (s[i]=='L' && (i+1)%2!=0) )
         {
             flag=false;
             break;
         }
     }

    if(flag)
    cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
import java.util.*;

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

        int minDiff = 10000;
        for (int i = 0; i <= s.length() - 3; i++) {
            int diff = Math.abs(Integer.parseInt(s.substring(i, i + 3)) - 753);
            if (diff < minDiff) {
                minDiff = diff;
            }
        }
        System.out.println(minDiff);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <iostream>

using namespace std;



int main()
{
    int a,b;
    while(scanf("%X%X",&a,&b)+1)
    {
        if(a>b) printf(">\n",a,b);
        else if(a<b) printf("<\n",a,b);
        else printf("=\n",a,b);
    }
    return 0;
}


Measured memory_bytes: 256
n,m,*l = map(int, open(0).read().split())
l=iter(l)
l=list(zip(l,l,l))
l1=l[:n]
l2=l[-m:]

V=set([float('inf'),-float('inf')])
H=set([float('inf'),-float('inf')])

for a,b,c in l1:
    V.add(c)
    H.add(a)
    H.add(b)
for c,a,b in l2:
    H.add(c)
    V.add(a)
    V.add(b)

V=sorted(list(V))
H=sorted(list(H))
Vdic={}
Hdic={}
for i,v in enumerate(V):
    Vdic[v]=i
for i,h in enumerate(H):
    Hdic[h]=i

checkv=[[0]*3001 for i in range(3001)]
checkh=[[0]*3001 for i in range(3001)]
check=[[0]*3001 for i in range(3001)]

for a,b,c in l1:
    c=Vdic[c]
    for i in range(Hdic[a],Hdic[b]):
        checkh[c][i]=1
for c,a,b in l2:
    c=Hdic[c]
    for i in range(Vdic[a],Vdic[b]):
        checkv[i][c]=1

from bisect import bisect_left
pv=bisect_left(V,0)-1
ph=bisect_left(H,0)-1

ans=0

stack=[(pv,ph)]
check[pv][ph]=1

while stack:
    v,h=stack.pop()
    ans+=(V[v+1]-V[v])*(H[h+1]-H[h])
    if h!=0 and checkv[v][h]==0 and check[v][h-1]==0:
        stack.append((v,h-1))
        check[v][h-1]=1
    if h!=len(H)-2 and checkv[v][h+1]==0 and check[v][h+1]==0:
        stack.append((v,h+1))
        check[v][h+1]=1
    if v!=0 and checkh[v][h]==0 and check[v-1][h]==0:
        stack.append((v-1,h))
        check[v-1][h]=1
    if v!=len(V)-2 and checkh[v+1][h]==0 and check[v+1][h]==0:
        stack.append((v+1,h))
        check[v+1][h]=1

print("INF" if ans==float('inf') else ans)

Measured memory_bytes: 538452
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String[] s2 = s.split("");
        int n = s.length();
        int[] answer = new int[n];
        
        int r = 0;
        for(int i = 0; i < n; i++){
            if(s2[i].equals("R")){
                r++;
            }else if(r != 0){
                if(r == 1){
                    answer[i - 1]++;
                }else if(r % 2 == 0){
                    answer[i - 1] = r / 2;
                    answer[i] = r / 2;
                }else{
                    answer[i - 1] = r / 2 + 1;
                    answer[i] = r / 2;
                }
                r = 0;
            }
        }
        
        int l = 0;
        for(int i = n-1; i >= 0; i--){
            if(s2[i].equals("L")){
                l++;
            }else if(l != 0){
                if(l == 1){
                    answer[i + 1]++;
                }else if(l % 2 == 0){
                    answer[i + 1] += l / 2;
                    answer[i] += l / 2;
                }else{
                    answer[i + 1] += l / 2 + 1;
                    answer[i] += l / 2;
                }
                l = 0;
            }
        }
        
        for(int i = 0; i < n-1; i++){
            System.out.print(answer[i] + " ");
        }
        System.out.println(answer[n-1]);
    }
}

Measured memory_bytes: 43696
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int N;
    int L[200];
    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> L[2*j] >> L[2*j + 1];
    }

    sort(L, L + 2*N);

    int ans = 0 ;
    for (int j = 0; j < N; ++j) {
        ans += L[2*j];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

a,b,c,k = map(int,readline().split())
n = a+b+c
if k <= a:
    print(k)
elif k <= a+b:
    print(a)
else:
    print(a-c+(n-k))

Measured memory_bytes: 61688
#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll x; cin >> x;
    ll ans = ((x+10)/11) * 2;
    if(x<=6) ans = 1;
    else if(x<=11) ans = 2;
    else if(x%11<=6&&x%11!=0) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N+1);
    int in;
    for (int i=0; i<N+1; i++) {
        cin >> in;
        A[i] = in;
    }
    long long int ans = 0;
    for (int i=0; i<N; i++) {
        cin >> in;
        if (in >= A[i]) {
            ans += A[i];
            in -= A[i];
            if (in >= A[i+1]) {
                ans += A[i+1];
                A[i+1] = 0;
            } else {
                ans += in;
                A[i+1] -= in;
            }
        } else {
            ans += in;
        }
    }
    
   cout << ans; 
}


Measured memory_bytes: 640
s=gets.chomp
arr=["dream","dreamer","erase","eraser"]
check="YES"
while true
  arr.each do |word|
    wsize=word.size
    if word==s[-wsize..-1]
      s=s[0..-wsize-1]
      check="YES"
      break
    else
      check="NO"
    end
  end
  break if s==""||check=="NO"
end
puts check


Measured memory_bytes: 39464
#include <iostream>
#include <string>
 
using namespace std;
int main() {
  int n;
  cin >> n;
  int n4 = n / 1000;
  int n3 = (n % 1000) / 100;
  int n2 = (n % 100 ) / 10;
  int n1 = n % 10;
  if (n4 == n3 && n3 == n2 || n3 == n2 && n2 == n1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
v = list(map(int, input().split()))
v1 = Counter(v[::2]).most_common(2)+[(0,0)]
v2 = Counter(v[::-2]).most_common(2)+[(0,0)]
if v1[0][0] == v2[0][0]:
    print(N -max(v1[0][1]+v2[1][1],
                 v1[1][1]+v2[0][1]))
else:
    print(N-v1[0][1]-v2[0][1])

Measured memory_bytes: 15588
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;
bool s[100005], t[100005];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  int mi = INF, ma = 0;
  REP(i,N){
    cin >> a[i];
    mi = min(mi, a[i]);
    ma = max(ma, a[i] - mi);
  }
  int mi_i = 0;
  REP(i,N){
    if(ma == a[i] - a[mi_i]){
      s[mi_i] = true;
      t[i] = true;
    }
    if(a[mi_i] > a[i]){
      mi_i = i;
    }
  }
  cout << min(accumulate(s, s + N, 0), accumulate(t, t + N, 0)) << endl;
  return 0;
}


Measured memory_bytes: 896
#include<vector>
#include<iostream>
#define A 0
#define P 1
#define O 2
#define NONE -1

using namespace std;

void visit_dist(vector< vector<int> > &prop, int h, int w){
  int max_h = prop.size(), max_w = prop[0].size();
  int trg = prop[h][w];

  if(trg != NONE) {
    prop[h][w] = NONE;
    
    if(h > 0 && prop[h-1][w] == trg) visit_dist(prop, h-1, w);
    if(h < max_h - 1 && prop[h+1][w] == trg) visit_dist(prop, h+1, w);
    if(w > 0 && prop[h][w-1] == trg) visit_dist(prop, h, w-1);
    if(w < max_w -1 && prop[h][w+1] == trg) visit_dist(prop, h, w+1);   
  }

  return;
}

int count_dist(vector< vector<int> > &prop){
  int count = 0;
  int max_h = prop.size(), max_w = prop[0].size();
  
  for(int i = 0; i < max_h; i++){
    for(int j = 0; j < max_w; j++){
      if(prop[i][j] != NONE){
	visit_dist(prop, i, j);
	count++;
      }
    }
  }

  return count;
}

int main(){
  int h, w;
  while(cin >> h && cin >> w){
    if(h == 0 && w == 0) break;
    
    vector< vector<int> > prop;
    prop.resize(h);
    for(int i = 0; i < h; i++) prop[i].resize(w);    
    
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	char tmp;
	cin >> tmp;
	if(tmp == '@') prop[i][j] = A;
	else if(tmp == '#') prop[i][j] = P;
	else if(tmp == '*') prop[i][j] = O;
      }
    }

    cout << count_dist(prop) << endl;
  }

  return 0;
}

Measured memory_bytes: 4176
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;
struct P {
	int x, y;
	P(){}
	P(int x_, int y_):x(x_),y(y_){}
};

/** Problem1218 : Push!! **/
int W, H;
const int MAX = 8;
int field[MAX][MAX];
typedef pair<P, P> PP;
string ch = ".#OG&";

bool canMove(P s, P g, P c)
{
	queue<P> Q;
	bool vis[W][H]; fill(vis[0], vis[0]+W*H, false);
	vis[s.x][s.y]=true;
	Q.push(s);
	
	while (Q.size()) {
		P p = Q.front(); Q.pop();
		
		rep(i, 4) {
			int nx = p.x + dx[i], ny = p.y + dy[i];
			
			if_range(nx, ny, W, H) {
				if (field[nx][ny] != 1 && !vis[nx][ny] && (nx != c.x || ny != c.y)) {
					Q.push(P(nx, ny));
					vis[nx][ny] = true;
				}
			}
		}
	}
	return vis[g.x][g.y];
}
 
int main()
{
	while (cin>>W>>H, W||H) {
		P s, m, g;
		memset(field, 0, sizeof(field));

		rep(y, H) {
			rep(x, W) {
				cin>>field[x][y];
				
				if (field[x][y] == 4) {
					m = P(x, y);
				} else if (field[x][y] == 2) {
					s = P(x, y);
				} else if (field[x][y] == 3) {
					g = P(x, y);
				}
			}
		}
		
		queue<PP> Q;
		int vis[W][H][W][H]; fill(vis[0][0][0], vis[0][0][0]+W*H*W*H, INF);
		vis[s.x][s.y][m.x][m.y]=0;
		Q.push(PP(s, m));
		
		while (Q.size()) {
			PP p = Q.front(); Q.pop();
			
			if (p.first.x == g.x && p.first.y == g.y)
				break;
			
			rep(i, 4) {
				int nx = p.first.x + dx[i], ny = p.first.y + dy[i];
				int nmx = p.first.x - dx[i], nmy = p.first.y - dy[i];
				
				if_range(nx, ny, W, H) {
					if_range(nmx, nmy, W, H) {
						if (field[nx][ny] != 1 && vis[nx][ny][nmx][nmy] == INF && canMove(P(p.second.x, p.second.y), P(nmx, nmy), p.first)) {
							Q.push(PP(P(nx, ny), P(nmx, nmy)));
							vis[nx][ny][nmx][nmy] = vis[p.first.x][p.first.y][p.second.x][p.second.y]+1;
						}
					}
				}
			}
		}
		
		int ans = INF;
		rep(i, H) {
			rep(j, W) {
				ans = min(ans, vis[g.x][g.y][j][i]);
			}
		}
		cout << (ans!=INF?ans:-1) << endl;
	}
}

Measured memory_bytes: 1212
///Bismillahir Rahanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    int n;
    cin>>n;
    int sum=0;
    f(i,1,n)
    {
        f(j,1,n)
        {
            int p=__gcd(i,j);
            f(k,1,n)
            {
                int g=__gcd(p,k);
                sum+=g;
            }
        }
    }
    cout<<sum<<endl;


















    return 0;

}













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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
	IOS;
    cout.precision(30);
    string s; cin >> s; bool res=false;
    for (int i=0;i<s.length()-1;i++)
    {
        if (s[i]==s[i+1]) res=true;
    }
    if (res) cout << "Bad"; else cout << "Good";
    return 0;
}


Measured memory_bytes: 256