akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int H,W,h,w;
    private void solve() {
        H = nextInt();
        W = nextInt();
        h = nextInt();
        w = nextInt();

        out.println((H - h) * (W - w));
    }

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

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(void){
    int N;
    cin >> N;
    int cnt = 0;
    for(int i = 1; i <= N; i++){
        int p;
        cin >> p;
        if(p != i) cnt++;
    }
    if(cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
                           
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

template<typename T> istream 
&operator>>(istream &a, vector<T> &v) { 
for (auto& x : v) a >> x; return a; }

void stndrtn() {
#ifdef accepted
    freopen(".in", "r", stdin);
#endif        
}

const int N = 2e5+10;

const bool flag = 0;

void maincode() {
    int n;
    cin >> n;
    int pv = -1;
    vector<int> a;
    for (int x; n--;) {
        cin >> x;
        if (x != pv)
            a.pb(x);
        pv = x;            
    }
    auto add = [&](ll& s, int x) {
        s += x;
        if (s >= MOD)
            s -= MOD;
    };
    ll dp = 1;
    vector<ll> cnt(N);
    for (int i = 0; i < sz(a); ++i) {
        add(cnt[a[i]], dp);
        dp = cnt[a[i]];    
    }
    cout << dp;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) 
        cin >> ts;
    while (ts--)
        maincode(); 
    return 0;
}



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

import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
preo = LIST()
ino = LIST()
posto = []

def rec(l):
    if len(l) == 0:
        return
    # preorderから次の値を取り出す
    x = preo.pop(0)
    for i in range(len(l)):
        if l[i] == x:
            # preorderの値と一致したら、そこから左右に分割
            rec(l[:i])
            rec(l[i+1:])
    posto.append(x)
    return

rec(ino)
print(*posto)



Measured memory_bytes: 5608
a=gets.to_i
s=gets.to_i
d=gets.to_i
f=gets.to_i
g=gets.to_i
h=gets.to_i
j=gets.to_i
k=gets.to_i
l=gets.to_i
p=gets.to_i
print("#{a+s+d+f+g+h+j+k+l+p}\n")

Measured memory_bytes: 8684
n, m = map(int, input().split())
if abs(n-m)>1:
    print(0)
else:
    ans=1
    index=n
    while index > 0:
        ans *= index
        ans= ans%((10**9) +7)
        index-=1
    index2=m
    while index2 > 0:
        ans *= index2
        ans= ans%((10**9) +7)
        index2-=1
    if abs(n-m)==1:
        print(ans)
    else:
        print(ans*2 % ((10**9) + 7))

Measured memory_bytes: 3064
#!python3

LI = lambda: list(map(int, input().split()))

# input
N = int(input())
C = LI()

MOD = 10 ** 9 + 7


def main():
    ans = 0
    C.sort()
    for i in range(N):
        x = C[i] * (N - i + 1) % MOD
        ans = (ans + x) % MOD
    ans = ans * pow(4, N - 1, MOD) % MOD
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  int n; cin >> n;
  vector<ll>L(87);
  L[0] =2; L[1]=1;
  for(int i=2;i<87;i++){
    L[i] = L[i-1] +L[i-2];
  }
  printf("%lld",L[n]);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vii vector<int>
#define Itadakimasu ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define dash   continue;
#define br break;
#define sz size()
#define Tadaima return 0;
#define pb push_back
#define fr first
#define sc second
#define N 100010
#define T ll t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()


using namespace std;

ll dp[N];

int main()
{
    Itadakimasu

    ll n,a[N];
    int k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    int mn;
    for(int i=1;i<n;i++)
    {
        mn=i;
        dp[i]=INT_MAX;
        for(int j=1;j<=mn;j++)
        {
            mn=min(k,mn);
            dp[i]=min(dp[i-j]+abs(a[i-j]-a[i]),dp[i]);
        }
    }
    cout<<dp[n-1]<<endl;




    Tadaima
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define mp make_pair
//#define ivorysi
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int N,M;
int g[705][705];
struct node {
    int to,next;
}E[1000005];
int sumE,head[705],tot,col[705],que[705],qr;
pii conn[705];
bool f[2][705];
void add(int u,int v) {
    E[++sumE].next = head[u];
    E[sumE].to = v;
    head[u] = sumE;
}
bool dfs(int u) {
    if(col[u] == -1) col[u] = 0;
    que[++qr] = u;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(col[v] == col[u]) return false;
	else if(col[v] == -1) {
	    col[v] = col[u] ^ 1;
	    if(!dfs(v)) return false;
	}
    }
    return true;
}
void Solve() {
    read(N);read(M);
    int u,v;
    for(int i = 1 ; i <= M ; ++i) {
	read(u);read(v);
	g[u][v] = g[v][u] = 1;
    }
    for(int i = 1 ; i <= N ; ++i) {
	for(int j = i + 1 ; j <= N ; ++j) {
	    if(!g[i][j]) {add(i,j);add(j,i);}
	}
    }
    memset(col,-1,sizeof(col));
    for(int i = 1 ; i <= N ; ++i) {
	if(col[i] == -1) {
	    qr = 0;
	    if(!dfs(i)) {puts("-1");return;}
	    int cnt[2] = {0,0};
	    for(int j = 1 ; j <= qr ; ++j) cnt[col[que[j]]]++;
	    conn[++tot] = mp(cnt[0],cnt[1]);
	}
    }
    int cur = 0;
    f[0][0] = 1;
    for(int i = 1 ; i <= tot ; ++i) {
	memset(f[cur ^ 1],0,sizeof(f[cur ^ 1]));
	for(int j = N ; j >= 0 ; --j) {
	    if(j >= conn[i].fi) f[cur ^ 1][j] |= f[cur][j - conn[i].fi];
	    if(j >= conn[i].se) f[cur ^ 1][j] |= f[cur][j - conn[i].se];
	}
	cur ^= 1;
    }
    int ans = N * N;
    for(int i = 0 ; i <= N ; ++i) {
	if(f[cur][i]) {
	    ans = min(i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2,ans);
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 4736
N, K = map(int, input().split())

if K == 0:
    print(N**2)
    exit()

ans = 0
for i in range(K+1, N+1):
    if N % i < K:
        temp = 0
    else:
        temp = N % i - K + 1

    ans += N // i * (i - K) + temp

print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  char c[5]={'a','i','u','o','e'};
  set<char>se;
  rep(i,5)se.insert(c[i]);
  char dd;
  cin>>dd;
  if(se.count(dd))cout<<"vowel"<<endl;
  else cout<<"consonant"<<endl;
  

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(void)
{
  int a,b,x;
 
  cin>>a>>b>>x;
 
  for(int i=0;i<b;i++)
  {
    if(a==x)
    {
      cout<<"YES"<<endl;
      break;
    }
    else if(a<x)
    {
      a++;
    }
    else if(a>x)
    {
      cout<<"NO"<<endl;
      break;
    }
  }
  if(a<x)
  {
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    string x;
    ll sum=100000000000;
    cin>>n>>x;
    int e=0,w=0,ee=0,ww=0;
    for(int i=0;i<n;i++)
    {
        if(x[i]=='W')
            w++;
        else
            e++;
    }
      for(int i=0;i<n;i++)
      {

            ll k=e+ww;
              sum=min(sum,k);
        if(x[i]=='W')
          {w--;ww++;}
else
          {e--;
              ee++;
          }
      }ll k=ww;
      sum=min(sum,k);
      cout<<sum;
return 0;
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[n];
    for( int i = 0; i < n; ++i ) cin >> a[i];
    sort( a, a + n );
    cout << a[n - 1] - a[0] << endl;
    return 0;
}



Measured memory_bytes: 256
def selectionSort(A, N):
    cnt = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        cnt = cnt + int(i != minj)
        A[i], A[minj] = A[minj], A[i]
    return cnt


N = int(input())
A = [int(i) for i in input().split()]
cnt = selectionSort(A, N)

for i in range(N):
    if i != 0:
        print(" ", end="")
    print(A[i], end="")

print()
print(cnt)


Measured memory_bytes: 5628
#include <stdio.h>

int main(void)
{
    int i, n;
    int array[100];

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%d", &(array[i]));
    }

    for(i = (n - 1); i > 0; i--){
        printf("%d ", array[i]);
    }
    printf("%d\n", array[i]);

    return 0;
}


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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    bool prime[100001];
    rep(i, 100001) prime[i] = true;
    prime[0] = false; prime[1] = false;
    rep(i, 100001){
        if(prime[i]){
            for(int j = i*2; j < 100001 ; j+=i) prime[j] = false;
        }
    }
    int ruiseki[100001] = {0}; //ruiseki[i]は1からiまでの2017に似た数
    for(int i = 3; i <= 99999; i+=2){
        if(prime[i] && prime[(i+1)/2]){
            ruiseki[i] = ruiseki[i-1] + 1;
        }
        else{
            ruiseki[i] = ruiseki[i-1];
        }
        ruiseki[i+1] = ruiseki[i];
    }

    int Q;
    cin >> Q;
    rep(i, Q){
        int l, r;
        cin >> l >> r;
        cout << ruiseki[r]-ruiseki[l-1] << endl;
    }
    return 0;
}

void solve(){}

Measured memory_bytes: 1152
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import heapq

n = int(input())
a_list = list(map(int, input().split()))

heap = []
# heapに突っ込む
for v in a_list:
    heapq.heappush(heap, v)

sorted_a = [heapq.heappop(heap) for i in range(len(heap))]

max_len = len(sorted_a)
for i in range(max_len):
    if i == max_len-1:
        break
    if sorted_a[i] == sorted_a[i+1]:
        print("NO")
        exit()

print("YES")



Measured memory_bytes: 108884
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int n,k;
	while(cin>>n>>k,n||k){
		vi s(k);
		vvi b(n,vi(k));
		REP(i,k){
			cin>>s[i];
		}
		REP(i,n){
			REP(j,k){
				cin>>b[i][j];
				s[j]-=b[i][j];
			}
		}
		REP(i,k){
			if(s[i]<0){
				cout<<"No"<<endl;
				goto end;
			}
		}
		cout<<"Yes"<<endl;
end:;
	}
}

Measured memory_bytes: 1252
import java.util.Scanner;

public class Main{
	static int H;
	static int[]A;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		H = scan.nextInt();
		A = new int[H + 1];
		for(int i = 1; i <= H; i++) {
			A[i] = scan.nextInt();
		}
		scan.close();

		for(int i = H / 2; i >= 1; i--) {
			maxHeapify(i);
		}
		for(int i = 1; i <= H; i++) {
			System.out.print(" " + A[i]);
		}
		System.out.println();
	}
	static void maxHeapify(int i) {
		int l, r, largest;
		l = 2 * i;
		r = 2 * i + 1;

		// 左の子、自分、右の子で値が最大のノードを選ぶ
		if(l <= H && A[l] > A[i]) largest = l;
		else largest = i;
		if(r <= H && A[r] > A[largest]) largest = r;

		if(largest != i) {
			swap(A, i, largest);
			maxHeapify(largest);
		}
	}
	static void swap(int[]A, int i, int j) {
		int t = A[i];
		A[i] = A[j];
		A[j] = t;
	}
}


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

using ll = long long;
const ll INF = 1LL << 60;
const ll MAX_A = 300005;

ll op(ll a, ll b) { return max(a, b); }
ll e() { return 0; }

int main() {
    int N, K;  cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    segtree<ll, op, e> dp(MAX_A);
    for (int i = 0; i < N; ++i) {
        // DUMPS(max(A[i] - K, 0LL), min(A[i] + K + 1, MAX_A));
        ll mx = dp.prod(max(A[i] - K, 0LL), min(A[i] + K + 1, MAX_A));
        dp.set(A[i], mx + 1);
    }
    ll ans = dp.all_prod();
    cout << ans << endl;
}


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

int main() {
	string s;
	int n;
	cin >> n;
	cin >> s;
	int cont = 0;
	for(int i = 0; i < n; i++){
		while(i < n && s[i] == s[i + 1]) {
			i++;
		}
		cont++;
	}
	cout << cont << endl;
	return 0;
}

Measured memory_bytes: 512
import sys
from string import ascii_lowercase as a2z

input = sys.stdin.readline


def main():
    A = input().rstrip()

    count = {al: 0 for al in a2z}
    ans = 1
    for i, a in enumerate(A):
        ans += (i - count[a])
        count[a] += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10084
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  vector<int> b=a;
  sort(b.begin(),b.end());
  for(int i=0;i<n;i++){
    if(a[i]>b[n/2-1]){cout<<b[n/2-1]<<endl;}
    else{cout<<b[n/2]<<endl;}
  }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head

int main(){

  ll k = in();
  ll a = in();
  ll b = in();

  if(k <= a || b - a <= 2){
    cout << k + 1 << endl;
    return 0;
  }

  ll ans = a + (b - a) * ((k + 1 - a) / 2) + (k + 1 - a) % 2;

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


Measured memory_bytes: 256
h, w = map(int, input().split())
sL = [input() for i in range(h)]

ans = []
for row in sL:
    ans.append(list(row))

dxy = [(-1,-1),(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1)]
for y in range(h):
    for x in range(w):
        if sL[y][x] == "#":
            continue
        count = 0
        for dx,dy in dxy:
            if x+dx < 0 or x+dx > w-1 or y+dy < 0 or y+dy > h-1: 
                continue
            if sL[y+dy][x+dx] == "#": 
                count += 1
        ans[y][x] = count
 
for row in ans:
    print(''.join(list(map(str,row))))

Measured memory_bytes: 3064
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    K=I()
    T=S*2
    before = ""
    RLE = []
    for t in T:
        if before != t:
            RLE.append(1)
            before = t
        else:
            RLE[-1]+=1
    cnt=0
    for x in RLE:
        cnt+=x//2
    if len(RLE)==1:
        print(cnt*K//2)
        exit()
    RLE = []
    before = ""
    for t in S:
        if before != t:
            RLE.append(1)
            before = t
        else:
            RLE[-1]+=1

    cnt2 = 0    
    for x in RLE:
        cnt2+=x//2

    cnt3 = cnt - cnt2*2

    ans=cnt2*K + cnt3*(K-1)
    print(ans)
    

if __name__ == '__main__':
    main()

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define all(x) (x).begin(), (x).end()
#define fap(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const int inf = 0x3f3f3f3f;
const ll INF = 2e18;

int main() {
	FastIO;

	int n;
	cin >> n;

	vector<int> a(n), pos(n);
	for(int i=0; i<n; ++i) {
		cin >> a[i];
		--a[i];
		pos[a[i]] = i;
	}

	int res = n - 1, pre = 1;
	for(int i=n-2; i>=0; --i) {
		int len = 1;
		if(pos[i] < pos[i+1]) len += pre;
		res = min(res, n - len);
		pre = len;
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 2428
from collections import deque

# import sys

# input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 7)


def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Ch -= 1
    Cw -= 1
    Dh, Dw = map(int, input().split())
    Dh -= 1
    Dw -= 1
    S = []
    S.append(["#"] * (4 + W))
    S.append(["#"] * (4 + W))
    for i in range(H):
        S.append(["#", "#"] + list(input()) + ["#", "#"])
    S.append(["#"] * (4 + W))
    S.append(["#"] * (4 + W))
    dist = [[10 ** 18] * (4 + W) for _ in range(H + 4)]
    # print(S, warp)

    def bfs(i, j):
        q = deque()
        q.append((i, j))
        dist[i][j] = 0
        while q:
            a, b = q.popleft()
            for x in range(-2, 3):
                for y in range(-2, 3):
                    if S[a + x][b + y] == ".":
                        warp = abs(x) + abs(y) != 1
                        d = dist[a][b] + int(warp)
                        if d < dist[a + x][b + y]:
                            dist[a + x][b + y] = d
                            if warp:
                                q.append((a + x, b + y))
                            else:
                                q.appendleft((a + x, b + y))
                            # print(q)

    bfs(Ch + 2, Cw + 2)
    if dist[Dh + 2][Dw + 2] == 10 ** 18:
        print(-1)
    else:
        print(dist[Dh + 2][Dw + 2])


if __name__ == "__main__":
    main()


Measured memory_bytes: 135848
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=7e5+50;
char a[maxn];
int main()
//lmao
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,s1;
    cin>>(a+300005);
    int start=3e5+5;
    int len=strlen(a+300005);
    int endx=start+len-1;
    int flag=0;//0表示正 1表示逆
    int q;
    cin>>q;
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
           if(flag==0) flag=1;
           else flag=0;
        }
        else
        {
            int f;
            cin>>f;
            char d;
            cin>>d;
            if(f==1)
            {
                if(flag==0) //正序
                {
                    start--;
                    a[start]=d;
                }
                else
                {
                    endx++;
                    a[endx]=d;
                }
            }
            else
            {
                if(flag==0)
                {
                    endx++;
                    a[endx]=d;
                }
                else
                {
                    start--;
                    a[start]=d;
                }
            }
        }
 
    }
    if(flag==0)
    {
        for(int i=start;i<=endx;i++)
        {
            cout<<a[i];
        }
        cout<<'\n';
    }
    else
    {
        for(int i=endx;i>=start;i--)
            cout<<a[i];
        cout<<'\n';
    }
 
 
 
 
 
 
 
 
}
 

Measured memory_bytes: 896
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
import numpy as np

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    A = il()

    ret = 1
    N -= K
    while not N <= 0:
        N -= K - 1
        ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 36400
#include <cstdio>
#include <cstdint>

int main() {
  intmax_t s, t, p, q, M, y;
  scanf("%jd %jd %jd %jd %jd %jd", &s, &t, &p, &q, &M, &y);

  printf("%jd\n", s^t^y);
}



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

struct Restaurant {
  int no;
  string city;
  int point;
  bool operator<(const Restaurant& another) const {
    if (city != another.city)
      return city < another.city;
    if (point != another.point)
      return point > another.point;
    return no < another.no;
  }
};

int main() {
  int n;
  cin >> n;
  vector<Restaurant> vec(n);
  for (int i = 0; i < n; i++){
    cin >> vec[i].city >> vec[i].point;
    vec[i].no = i+1;
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++) cout << vec[i].no << endl;;
  return 0;
}


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

int main(void){
  int N, M, X, Y, x, y;
  int Xmax = -100, Ymin = 100;
  cin >> N >> M >> X >> Y;
  for(int i=0;i<N;i++){
    cin >> x;
    Xmax = max(x,Xmax);
  }
  for(int i=0;i<M;i++){
    cin >> y;
    Ymin = min(y,Ymin);
  }
  if(min(Ymin,Y) - max(Xmax,X) >= 1){
    cout << "No War" << endl;
  }
  else{
    cout << "War" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a,b;
main(){
cin>>a>>b;
if(a>=13){
    cout<<b;
    return 0;
}
if(a>=6 && a<=12){
cout<<b/2;
return 0;
}
cout<<0;
return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		Set<String> set = new HashSet<>();

		for (int i = 0; i < n; i++) {
			set.add(br.readLine());
		}

		System.out.println(set.size());
	}
}


Measured memory_bytes: 66312
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/
signed main(){
  int n,m;
  cin>>n>>m;
  int v=0;
  vi a(n);
  rep(i,n)cin>>a[i];
  rep(i,n) v+=a[i];
  sort(all(a));
  if(a[n-m]*4*m>=v) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define int long long
#define P pair<int,int>
#define S stack<int>
#define Q queue<int>
#define V vector<int>
using namespace std;

signed main(){
	int n,m,x=1;
	string s,t;
	cin>>n>>m>>s>>t;
	for(int i=1;i<=min(n,m);i++){
		if(n%i==0&&m%i==0) x=i;
	}
	for(int i=0;i*(n/x)<n;i++){
		if(s[i*(n/x)]!=t[i*(m/x)]){
			cout<<"-1"<<endl;
			return 0;
		}
	}
	cout<<n*m/x<<endl;
	return 0;
}


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

int main() {
    string s; cin >> s;
    long long cnt = 0, ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'B') cnt++;
        else ans += cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    string S;
    cin >> S;
    int N = S.size();

    bool flg = true;

    for(int i=0;i<N;i++){
        if(i%2 == 1){
            if(S[i] != 'L' & S[i] != 'U' & S[i] != 'D'){
                flg = false;
                break;
            }
        }else{
            if(S[i] != 'R' & S[i] != 'U' & S[i] != 'D'){
                flg = false;
                break;
            }
        }
    }

    if(flg){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

	int A;
	int B;

	scanf("%d %d",&A,&B);

	if (A+B==15) {
		printf("+");
	} else if(A*B==15) {
		printf("*");
	} else {
		printf("x");
	};
	
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ch char
#define st string
using namespace std;
ll a,b,c,d,e,f,g,h;
st s;
vector<ll>vc;
void Urvatullo_Atoev()
{
    cin>>a;
    while(a/=2)
    {
       b++;
       b*=2;
    }
    cout<<b+1;
}
int main()
{
    Urvatullo_Atoev();
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

pi a[100005];

int32_t main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> a[i].F, a[i].S = i;
	sort(a+1, a+n+1);
	for(int i=1;i<=n;i++) cout << a[i].S << " ";
		cout << endl;
	
}





Measured memory_bytes: 1664
N,K=map(int,input().split())
A=list(map(int,input().split()))
lity=[[0,0] for i in range(N)]
if N<K:
  hata=True
  i=0
  a=0
  j=0
  while hata:
    if lity[i][0]==1:
      a=j-lity[i][1]
      break
    lity[i][0]+=1
    lity[i][1]=j
    i=A[i]-1
    j+=1
    
  K-=j
  p=K%a
  while p>=1:
    i=A[i]-1
    p-=1
  print(i+1)
else:
  i=0
  for j in range(K):
    i=A[i]-1
  print(i+1)

Measured memory_bytes: 39156
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]


def recur(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return 10 ** 18
        return abs(a - A) + abs(b - B) + abs(c - C)
    return min([
        recur(i + 1, a, b, c),
        recur(i + 1, a + l[i], b, c) + (10 if a > 0 else 0),
        recur(i + 1, a, b + l[i], c) + (10 if b > 0 else 0),
        recur(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)
    ])


print(recur(0, 0, 0, 0))


Measured memory_bytes: 3064
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << x2 - (y2 - y1) << " " << y2 + (x2 - x1) << " " << x1 - (y2 - y1) << " " << y1 + (x2 - x1) << '\n';
    
    
    
	return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    a = LI()
    s = sum(a)
    k = 0
    for i in a:
        if 4*m*i < s:
            continue
        k += 1
    if k >= m:
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next() + "," + (Integer.MAX_VALUE - sc.nextInt()) + "," + (i + 1);
		}
		
		Arrays.sort(s);
		
		for (String string : s) {
			String ans = string.split(",")[2];
			System.out.println(ans);
		}
	}
}

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

//#define int long long
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n;
double xs, ys, xt, yt, x[1234], y[1234], r[1234], d[1234], cost;
vector<pair<int,double>> g[1234];

void dijkstra(int s) {
	priority_queue<pair<double,int>, vector<pair<double,int>>, greater<pair<double,int>>> que;
	fill(d, d+n, 1e20);
	d[s] = 0.0;
	que.push(make_pair(0.0,s));
	
	while(!que.empty()) {
		pair<double,int> p = que.top(); que.pop();
		int v = p.second;
		double dis = p.first;
		if (d[v]<dis) continue;
		for (int i = 0; i < g[v].size(); ++i) {
			int to = g[v][i].first;
			double cost = g[v][i].second;
			if (d[to] > d[v] + cost) {
				d[to] = d[v] + cost;
				que.push(make_pair(d[to], to));
			}
		}
	}
}

signed main() {
	cin >> xs >> ys >> xt >> yt >> n;
	repst(i,1,n) cin >> x[i] >> y[i] >> r[i];
	x[0] = xs, y[0] = ys, x[n+1] = xt, y[n+1] = yt;
	n += 2;
	rep(i,n) {
		rep(j,n) {
			if (i==j) continue;
			cost = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j])) - (r[i]+r[j]);
			chmax(cost, 0.0);
			g[i].pb({j, cost}), g[j].pb({i, cost});
		}
	}
	dijkstra(0);
	printf("%.10lf\n",d[n-1]);
}

Measured memory_bytes: 38964
# coding: utf-8
#Problem Name: GCD and LCM
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

while True:
    try:
        a,b = map(int,raw_input().split(' '))
        s,t = a,b
        while True:
            r = s % t
            if not r:
                LCM = t
                break
            else:
                s,t = t,r
        
        print LCM, a*b/LCM
    except:
        break

Measured memory_bytes: 4212
/*
 * Owner   : Tatsuhiro Hashimoto
 * Created : 2020-05-02 (Thu)
 */

#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define FSP(n) cout << fixed << setprecision(n);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
static inline ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b);}
static inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define prepare cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

signed main() {
    prepare
    string S;
    cin >> S;
    if (S[1] == 'R') cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

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

int main() {
  //initialize
  int N;
  cin >> N;
  int d[N];
  for(int i = 0;i < N; ++i) cin >> d[i];
  sort(d, d+N); 
  
  int ans = 1;
  int s = d[0];
  for(int i = 0;i < N; i++) {
    if(d[i] != s) {
      s = d[i];
      ans ++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
A_1, B_0, C_minus1, K = map(int, input().split(' '))

max_total = 0

if(K <= A_1):
  max_total = K
elif(K > A_1 and K <= (A_1 + B_0)):
  max_total = A_1
else:
  left = K - (A_1 + B_0)
  if(left <= C_minus1):
    max_total = A_1 - left
  else:
    max_total = A_1 - C_minus1
  
print(max_total)


Measured memory_bytes: 9184
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;

int main(){
  int S,W;
  cin >> S >> W;
  if(S<=W) cout << "unsafe" << endl;
  else cout << "safe" << endl;
  
  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

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

	    String s=gs();
	    
        while(true) {
        	if(s.length()==0)break;
        	if(s.endsWith("dream")) {
        		s=s.substring(0, s.length()-5);
        	} else if(s.endsWith("dreamer")) {
        		s=s.substring(0, s.length()-7);
        	} else if(s.endsWith("erase")) {
        		s=s.substring(0, s.length()-5);
        	} else if(s.endsWith("eraser")) {
        		s=s.substring(0, s.length()-6);
        	} else {
        		System.out.print("NO");
        		return;
        	}
        }
	    System.out.println("YES");
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 56260
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
int n;
vector<int> son[1111];
int x[1111];
int z[1111];
int dp1[5555],dp2[5555];
void upd(int&x,int y){
	if(x==-1 || x>y)x=y;
}
int main(){
	scanf("%d",&n);
	for(int i=2; i<=n; i++){
		int y;
		scanf("%d",&y);
		son[y].push_back(i);
	}
	for(int i=1; i<=n; i++){
		scanf("%d",&x[i]);
	}
	for(int i=n; i>=1; i--){
		memset(dp1,-1,sizeof(dp1));
		dp1[0] = 0;
		for(vector<int>::iterator it = son[i].begin(); it!=son[i].end(); it++){
			int black = x[*it], white = z[*it];
			memset(dp2,-1,sizeof(dp2));
			for(int j=0; j<=x[i]; j++)if(dp1[j] != -1){
				if(j + black <= x[i])
					upd(dp2[j+black], dp1[j] + white);
				if(j + white <= x[i])
					upd(dp2[j+white], dp1[j] + black);
			}
			memcpy(dp1,dp2,sizeof(dp2));
		}
		int res = -1;
		for(int j=x[i]; j>=0; j--)if(dp1[j] != -1){
			upd(res, dp1[j]);
		}
		if(res == -1){
			puts("IMPOSSIBLE");
			return 0;
		}
		z[i] = res;
	}
	puts("POSSIBLE");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    for (int i = s.length()-1; 0 < i; i--){
        if (i%2 == 0){
            vector<string> r(i);
            for (int j = 0; j < i; j++){
                r[j] = s[j];
            }
            bool flag = true;
            for (int k = 0;k < i/2;k++){
                if (r[k] != r[k+(i/2)]){flag = false;}
            }
            if (flag == true){
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long l,r;
int main()
{
	cin>>l>>r;
	long long r2=(int)(r/2019)*2019;
	if(r-l+1>=2019)
	{
		cout<<0;
		return 0;
	}
	if(r2>=l&&r2<=r)
	{
		cout<<0;
		return 0;
	}
	long long ans=1e18;
	for(int i=0;i<=r-l;i++)
	for(int j=i+1;j<=r-l;j++)
	{
		r2=(long long)(l+i);
		r2%=2019;
		long long r1=(long long)(l+j);
		r1%=2019;
		r2*=r1;
		r2%=2019;
		ans=min(ans,r2);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#l=list(map(int, input().split()))
#n,k=map(int, input().split())
#l=list(map(int, input().split()))
n = int(input())
l=list(map(int, input().split()))

ans = [0] * n

cnt = 1
for i in l:
    ans[i -1] = cnt
    cnt+=1

print(' '.join(map(str, ans)))


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

#define NMAX 50000

int comp(const void *c1, const void *c2)
{
    int tmp1, tmp2;
    tmp1 = *(int *)c1;
    tmp2 = *(int *)c2;
    if(tmp1 < tmp2 )  return -1;
    if(tmp1 == tmp2)  return  0;
    if(tmp1 > tmp2 )  return  1;
}

int  n_primes = 0;
int  primes[NMAX];
char primes_b[NMAX+1];
char tosearch[NMAX+1];

void erst(void)
{
    int n, x, i;
    // init tosearch
    tosearch[1] = 0;
    for(n=2;n<=NMAX;n++) tosearch[n] = 1;
    // loop
    while(1){
        for(x=1;!tosearch[x];x++); //find x (head of tosearch)
        // move x from tosearch to primes
        tosearch[x] = 0;
        primes[n_primes++] = x;
        // can be divided by x
        for(n=2;n<=NMAX;n++) if(n%x==0) tosearch[n]=0;
        // if step limit, merge primes and tosearch
        if(x*x>=NMAX){
            for(n=2;n<=NMAX;n++) 
                if(tosearch[n])
                    primes[n_primes++] = n; 
            qsort(primes, n_primes, sizeof(int), comp);
            break;
        }
    }
    //primes to primes_b
    for(n=1;n<=NMAX;n++) primes_b[n] = 0;
    for(i=0;i<n_primes;i++) primes_b[primes[i]] = 1;
}

int solve(int d)
{
    int i, retval;
    //odd
    if(d%2==1){
        if(primes_b[d-2]) return 1;
        else return 0;
    }
    //even
    retval = 0;
    for(i=0;primes[i]<=d-primes[i];i++)
        if(primes_b[d-primes[i]])
            retval++;
    return retval;
}


int n_d = 0;
int l_d[10000];

int main(void)
{
    int d, i;

    // get primes
    erst();

    //read
    d = 1;
    while(d){
        scanf("%d\n", &d);
        if(d) l_d[n_d++] = d;
    }

    //exec and print
    for(i=0;i<n_d;i++)
        printf("%d\n", solve(l_d[i]));

    return 0;
}

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

int main(){
  int n, Ecount=0, Wcount=0, ans = 99999999;
  string S;
  cin >> n >> S;
  for(int i=0;i<n;i++){
    if(S[i]=='E'){
      Ecount++;
    }
  }
  for(int i=0;i<n;i++){
    if(S[i]=='E'){
      Ecount--;
      ans = min(ans, Ecount+Wcount);
    }else{
      ans = min(ans, Ecount+Wcount);
      Wcount++;
    }
  }
  cout << ans << endl;
  return 0;

}



Measured memory_bytes: 900
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int e = sc.nextInt();
			if(e==0) break;
			int min = Integer.MAX_VALUE;
			for(int z=0;z*z*z<=e;z++){
				for(int y=0;y*y+z*z*z<=e;y++){
					int x = e-(y*y+z*z*z);
					min = Math.min(min,x+y+z);
				}
			}
			System.out.println(min);
		}
	}	
}

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

int main() {
  string n;
  cin >> n;
  if ((n.substr(0, 1) == n.substr(1, 1) && n.substr(0, 1) == n.substr(2, 1)) ||
      (n.substr(1, 1) == n.substr(2, 1) && n.substr(1, 1) == n.substr(3, 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
#define all(v) ((v).begin()),((v).end())
#define clr(v,val) memset(v,val,sizeof v)
void file(){
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);  
#endif
}
void fast(){
	std::ios_base::sync_with_stdio(0); cin.tie(NULL);
}
const int N = 1000000 + 20;
int n;
vector<ll>v(N);
ll can(ll md){
	for (int j = 0; j < n; j++){
		md -= (md % v[j]);
	}
	return md;
}
/***You***Can***Do***It***/
int main()
{
	
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	ll l = 0, r = 1e18;
	while (l < r){
		ll md = l+ (r - l) / 2;
		if (can(md)==0){
			l = md + 1;
		}
		else {
			r = md;
		}
	}
	if (can(l)!=2){
		cout << -1 << endl;
		return 0;
	}
	ll mn = l,mx;
	r = 1e18;
	while (l < r){
		ll md = l + (r - l + 1) / 2;
		if (can(md) == 2){
			l = md;
		}
		else {
			r = md-1;
		}
	}
	cout << mn << " " << l << endl;
}

Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  switch (N % 10) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    cout << "hon" << endl;
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    cout << "pon" << endl;
    break;
  case 3:
    cout << "bon" << endl;
    break;
  }
  return 0;
}

Measured memory_bytes: 3088