akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long N;
    std::cin >> N;
    long long M;
    std::cin >> M;
    std::vector<long long> a(M);
    std::vector<long long> b(M);
    for (int i = 0; i < M; i++) {
        std::cin >> a[i];
        std::cin >> b[i];
        a[i]--;
        b[i]--;
    }
    VV<int> e(N);
    rep(i, M) {
        e[a[i]].push_back(b[i]);
        e[b[i]].push_back(a[i]);
    }
    V<int> r(N);
    int ans = 0;
    r[0] = 1;
    auto dfs = [&](auto self, int i) -> int {
        bool f = true;
        rep(i, N) {
            if (!r[i]) f = false;
        }
        if (f) {
            return 1;
        }
        int ret = 0;
        for (auto a : e[i]) {
            if (r[a] == 1) continue;
            r[a] = 1;
            ret += self(self, a);
            r[a] = 0;
        }
        return ret;
    };

    cout << dfs(dfs, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  ll n;
  cin>>n;
  ll a[n];
  rep(i,n) cin>>a[i];
  ll ans = 0;
  ll s[n + 2];
  s[0] = 0;
  FOR(i, 1, n + 1) {
    s[i] = s[i-1] + a[i-1];
  }
  s[n + 1] = 1100100100100100100;
  sort(s, s + n + 2);
  ll cnt = 1ll;
  FOR(i, 1, n + 2) {
    if(s[i] == s[i - 1]) {
      cnt++;
    } else {
      ans += cnt * (cnt-1ll) / 2ll;
      cnt = 1ll;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define fill(a,val) memset(a,val,sizeof(a))
#define REP(i,a,b) for (auto i = a; i != b; i++)
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define pb push_back
#define SQ(a) (a)*(a)
 
const int N = 100005;
 
using namespace std;


int main()
{
    std::ios::sync_with_stdio(false);

    int T = 1;
    //cin>>T;
    // cin.ignore(); must be there when using getline(cin, s)
    while(T--)
    {
        int n;
        cin>>n;
        if(n%1000 != 0)
            cout<<(n/1000 + 1)*1000 - n<<endl;
        else
            cout<<0<<endl;
        
        

    }
    return 0;
}



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

int main(){
  int N;
  cin>>N;
  string tmp;
  int midab=0,aend=0,bstart=0,baside=0;

  for(int i=0;i<N;i++){
    cin>>tmp;
    if(tmp[0]=='B'&&tmp[tmp.size()-1]=='A') baside++;
    else{
      if(tmp[0]=='B') bstart++;
      if(tmp[tmp.size()-1]=='A') aend++;
    }
    for(int j=0;j<tmp.size()-1;j++){
      if(tmp[j]=='A'&&tmp[j+1]=='B') midab++;
    }
  }
  int merge=baside;
  if(aend==0&&bstart==0&&baside>0) merge--;
  if(aend>0&&bstart>0) merge+=(1+min(bstart-1,aend-1));
  cout<<midab+merge<<endl;
  return 0;
}

Measured memory_bytes: 256
X, N = map(int, input().split())
 
ans = 0
if N > 0:
  p = list(map(int, input().split()))
  r = [i for i in range(102) if i not in p]
  d = [abs(X-i) for i in r]
  ans = r[d.index(min(d))]
else:
  ans = X

print(ans)

Measured memory_bytes: 9184
#include <iostream>//bit DP
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
int T[100005]={0};
int H[100005]={0};
int main(){
  int n,m;cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>H[i];
  }
  int ans=0;
  for(int i=1;i<=m;i++){
    int a,b;
    cin>>a>>b;
    if(H[a]<H[b])T[a]++;
    else if(H[a]==H[b]){T[a]++;T[b]++;}
    else T[b]++;
  }
  for(int i=1;i<=n;i++){
    if(T[i]==0)ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4416
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
    int cnt = 0, n;
    char temp, old = '#';
    scanf("%d", &n);
    getchar();
    for (int i = 0; i < n; i++) {
        scanf("%c", &temp);
        if (temp != old) cnt++;
        old = temp;
    }
    printf("%d", cnt);
//return
    return 0;
}

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

typedef unsigned long long ll;

ll md = 1000000007;

int main(int, char**) 
{
	int n, m = 0;
	cin >> n;
	multiset<ll> a;

	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		auto it = a.lower_bound(x);
		if (it != a.begin()) {
			--it;
			a.erase(it);
		}
		a.insert(x);
	}

	cout << a.size() << endl;

	return 0;
}


Measured memory_bytes: 4992
#!python3

import numpy as np


# input
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


def main():
    a = np.array(sorted(A))
    b = np.array(sorted(B))
    c = np.array(sorted(C))
    
    w = [None] * N
    for i in range(N):
        w[i] = N - np.searchsorted(c, b[i], side="right")
    
    wsum = [0] * (N + 1)
    for i in range(N - 1, -1, -1):
        wsum[i] = w[i] + wsum[i + 1]
    
    ans = 0
    for i in range(N):
        ans += wsum[np.searchsorted(b, a[i], side="right")]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40720
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int n;
    cin >> n;
    cout << 2 << " ";
    n--;
    for(int i = 3; i <= 55555; i++)
    {
        bool flag = true;
        for(int j = 2; j < i; j++)
        {
            if (i%j == 0 || i%5 != 1) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << i << " ";
            n--;
        }
        if (!n) {
            cout << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
vector<int>vt;
set<int>st;
map<int,int>mp;
unordered_map<string,int> umap; 
const long long MAX = 1e5;
const long long INF = 1e9;
const double pi = acos(-1);


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n;
  int arr,c[n+1];
  memset(c,0,sizeof(c));
  while(cin>>m)
  {
    c[m]++;

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

    
   return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
#define pb push_back

using namespace std;
typedef long long LL;

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	vector<int> adjlist[N + 1];
	for (int i = 0; i < M; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		adjlist[u].pb(v);
		adjlist[v].pb(u);
	}
	queue<int> q;
	q.push(1);
	int dist[N + 1];
	memset(dist, -1, sizeof dist);
	dist[1] = 0;
	while (!q.empty()) {
		int nod = q.front();
		q.pop();
		for (auto ttg : adjlist[nod]) {
			if (dist[ttg] == -1) {
				dist[ttg] = nod;
				q.push(ttg);
			}
		}
	}
	for (int i = 2; i <= N; i++) {
		if (dist[i] == -1) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	for (int i = 2; i <= N; i++) {
		printf("%d\n", dist[i]);
	}
}

Measured memory_bytes: 10568
open Scanf
open Printf

let n = sscanf (read_line ()) "%d" (fun x -> x);;
let paths =  Hashtbl.create 10000;;
let () = 
  for i = 0 to n-2 do
    sscanf (read_line ()) "%d %d %d" (
      fun u v w -> 
        Hashtbl.add paths u (v,w);
        Hashtbl.add paths v (u,w)
    )
  done;;

(* let () = Hashtbl.iter (fun key value-> printf "paths: u=%d,v=%d w=%d\n" key (fst value) (snd value)) paths;; *)

let dfs ()=
  let tbl = Hashtbl.create n in
  let rec loop stack now_len =
    match stack with
      [] -> ()
    | (x,len) :: rest -> 
      let () = Hashtbl.add tbl x (len + now_len) in 
      let node_list = Hashtbl.find_all paths x in
      let next_list = List.filter 
          (fun tupl -> (not (Hashtbl.mem tbl (fst tupl)))) node_list in
      (* let () = List.iter (fun v -> printf "now_search: %d\n next_search: u=%d,w=%d\n" x (fst v) (snd v)) next_list in *)
      let () = loop next_list (len + now_len) in
      loop rest now_len
  in loop [(1,0)] 0;(* node 1 をrootとしてみなして、サイズ0を入れる *)
  tbl;;

let ans_tbl = dfs();;
(* let () = Hashtbl.iter (fun key value-> printf "key=%d,value=%d " key value) ans_tbl;; *)

let () = 
  for i = 1 to n do
    if (Hashtbl.find ans_tbl i) mod 2 = 0 then
      printf "%d\n" 0
    else 
      printf "%d\n" 1
  done;;


Measured memory_bytes: 28544
#include <bits/stdc++.h>
using namespace std;
int main() {
 int a;
  cin >> a;
  string b;
  cin >> b;
  int c = b.size();
  if(c<=a){
    cout << b << endl;
  }
  else{
    for(int i =0;i<a;i++){
      cout << b.at(i);
    }
    cout << "..." << endl;
  }
}


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

using namespace std;

int main() {
    long long int A, B, N;
    cin >> A >> B >> N;
    
    if(B<=N) {
        cout << A*(B-1)/B << endl;
    } else {
        cout << A*N/B << endl;
    }


    return 0;
}

Measured memory_bytes: 3552
s = input()
t = input()

s = list(s)
t = list(t)

count = 0
judgment = 0

while count <= len(s):
    count +=1
    item = s.pop()
    s.insert(0,item)
    if s == t:
        judgment += 1

if judgment == 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int n;
  cin >> n;
  int d,x;
  cin >> d >> x;
  REP(i,n) {
    int a;
    cin >> a;
    x+=1+(d-1)/a;
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  ll a,b,n;
  cin  >> a >> b >> n;
  if(n>=b){
    cout << (ll)(a*(b-1)/b)-a*(ll)((b-1)/b) << endl;
  }else{
    cout << (ll)(a*n/b) - a*(ll)(n/b) << endl;
  }
}


Measured memory_bytes: 3636
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
s=s0()
n=len(s)

L=[]
R=[]
for i in range(n):
    if s[i]=="L":
        L.append(i)
    else:
        R.append(i)

ans=[0]*n
for i in range(n):
    if s[i]=="R":
        j=L[bisect_right(L,i)]
        if (j-i)%2==1:
            ans[j-1]+=1
        else:
            ans[j]+=1
    else:
        j=R[bisect_right(R,i)-1]
        if (i-j)%2==1:
            ans[j+1]+=1
        else:
            ans[j]+=1
print(*ans)

Measured memory_bytes: 10556
#include<iostream>
#include<vector>
#include<cstdlib>
#include<string>
using namespace std;

int main(){
    //入力部
    int H,W;
    cin>>H>>W;
    vector<string>a(H);
    for(int i = 0;i < H; i++){
        cin>>a.at(i);
    }
    //上下の文字列
    vector<string>b(W+2,"#");
    for(int i = 0;i < W+2; i++){
        cout<<b.at(i);
    }
    cout<<endl;
    //n行目の処理
    for(int i = 0;i < H; i++){
        cout<<"#"<<a.at(i)<<"#"<<endl;
    }
    for(int i = 0;i < W+2; i++){
        cout<<b.at(i);
    }
    cout<<endl;
    return 0;
    }


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

using namespace std;

#define int long long

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

typedef pair<int, int> PII;

//--------

int N;

int sai(int a, int b){
    if(a<b){
        swap(a, b);
    }
    int r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

signed main(){
    cin >> N;
    int ans = 0;
    REP(i, N)
    {
        int m;
        cin >> m;
        if(i != 0)
        {
            ans = sai(m, ans);
        }
        else ans = m;
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  int n; cin>>n;
  for(int i=1;i<10;i++){
    if(n%i==0 && n/i<10){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};
bool isPrime(int x) {
  if (x < 2)
    return false;
  else if (x == 2)
    return true;
  else if (x % 2 == 0)
    return false;

  double sq = sqrt(x);
  for (int i = 3; i <= sq; i += 2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int q, pr[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> q;
    rep(i, 0, 100000) {
      if (i % 2 && isPrime(i) && isPrime((i+1)/2)) pr[i]++;
    }
    rep(i, 0, 100000) pr[i+1] += pr[i];
    rep(i, 0, q) {
      int l, r;
      cin >> l >> r;
      cout << pr[r] - pr[l-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 1024
import Queue

def solve(worm):
    dic = {
        "br" : "g",
        "bg" : "r",
        "gr" : "b"
    }
    Q = Queue.Queue()
    Q.put(worm)
    dist = {}
    dist[worm] = 0
    ans = -1
    while not Q.empty():
        cur = Q.get()
        if len(set(cur)) == 1:
            ans = dist[cur]
            break
        for i in range(len(cur)-1):
            if cur[i] != cur[i+1]:
                nxt = list(cur)
                color = dic["".join(sorted(nxt[i:i+2]))]
                nxt[i] = color
                nxt[i+1] = color
                nxt = "".join(nxt)
                if not nxt in dist:
                    dist[nxt] = dist[cur] + 1
                    Q.put(nxt)
    if ans == -1:
        print "NA"
    else:
        print ans

def main():
    while True:
        s = raw_input()
        if s == "0":
            break
        solve(s)
main()

Measured memory_bytes: 6404
#include<cstdio>
#include<algorithm>
#define N 1005

int n,k,a[N];

int ans;

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	std::sort(a+1,a+n+1);
	for(int i=1;i<=k;i++)
		ans+=a[i];
	printf("%d",ans);
}

Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
const int INF=0x3f3f3f3f;
const int N=1e6+7;
const int mod=1e9+7;
int maxn,minn;
int T,n;
string s1,s2;
int len1,len2;
int dp[4010][4010];

int main(){
	cin>>s1>>s2;
	len1=s1.size();
	len2=s2.size();
	for(int i=1;i<=len1;i++){
		for(int j=1;j<=len2;j++){
			if(s1[i-1]==s2[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string s="";
	int i=len1,j=len2;
	while(i!=0&&j!=0){
		if(s1[i-1]==s2[j-1]){
			s+=s1[i-1];
			i--,j--;
		}
		else{
			if(dp[i][j]==dp[i-1][j]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	
	

	return 0;
}





Measured memory_bytes: 47360
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
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;}
const int INF = 1e9;
const ll LINF = 1e18;
// clang-format on

void solve(long long N) {
  if (N % 2 != 0) {
    ANS(0);
    return;
  }
  ll ans = 0;
  for (ll b = 10; b <= N; b = b * 5) {
    ans += N / b;
  }
  ANS(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    string s;
    cin>>s;
    rep(i,0,s.size()){
        if(s[i]=='?'){
            if(s[i-1]=='P') s[i]='D';
            else{
                if(s[i+1]=='D')s[i]='P';
                else s[i]='D';
            }
        }
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3724
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    String s=sc.next();
		int n=s.length();
		
		//int[] a=new int[n];
		
		int[] count=new int[2019];count[0]=1;
		int x=1;
		int ans=0;
		int sum=0;
		for(int i=n-1;i>=0;i--) {
			char c=s.charAt(i);
			sum=(sum+Character.getNumericValue(c)*x);
			//System.out.println(sum);
			sum%=2019;
			if(sum<0)sum+=2019;
			//System.out.println((i+1)+" "+sum);
			count[sum]++;
			ans+=count[sum]-1;
			x=(x*10)%2019;
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 40604
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/

void build(){

}
#define N 101010
int n , a[ N ];
void init(){
  n = getint();
  for( int i = 0 ; i < n ; i ++ )
    a[ i ] = getint();
}
void solve(){
  int ans = 0;
  for( int i = 0 ; i < n ; ){
    int j = i + 1;
    bool de = false , in = false;
    ans ++;
    while( j < n ){
      if( a[ j ] > a[ j - 1 ] ){
        if( de ) break;
        in = true;
      }else if( a[ j ] < a[ j - 1 ] ){
        if( in ) break;
        de = true;
      }
      j ++;
    }
    i = j;
  }
  printf( "%d\n" , ans );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


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

int main() {
  
  ll x;
  cin>>x;
  for(ll i = -119; i <= 119; i++)  {
    bool flag = false;
    for(ll j = -119; j <= 119; j++) {
    
    	if((i*i*i*i*i) - (j*j*j*j*j) == x) {

        	cout<<i<<" "<<j<<endl; 
          	flag = true;
          	break;
        }
          
    }
    if(flag) break;
  }
  return 0;
}

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

int main() {
  char ch, tmp = 'a';
  bool ans = false;
  for (int i = 0; i < 4; i++ ) {
    cin >> ch;
    // cout << ch << tmp << endl;
    if ( tmp == ch ) {
      ans = true;
      break;
    }
    tmp = ch;
  }
  if ( ans ) cout << "Bad" << endl;
  else cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int pan(int i)
{
    int tmp=0;
    while (i)
        i/=10,tmp++;
    if (tmp%2==1) return 1;return 0;
}

int main()
{
    int n;scanf("%d",&n);
    int ans=0;
    for (int i=1;i<=n;i++)
    if (pan(i))
        ans++;
    printf("%d\n",ans);


}


Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int n;
  long long int m=0;
  cin>>n;
  rep(i,n){
    int tmp;
	cin>>tmp;
	m+=tmp;
  }
  cout<<m/n<<endl;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
string s[MAX_N];
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    map<string, ll>m;
    map<string, ll>::iterator it;
    for(ll i=0; i<n; i++)
    {
        cin >> s[i];
        m[s[i]] += i+1;
    }
    ll c=0;
    for( it = m.begin(); it!=m.end(); it++)
    {
       c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 25536
#include<stdio.h>

int partition(int);
int A[100000];

int main()
{

  int i,j,n;
  
  scanf("%d",&n);
  for(i=1; i<=n; i++)
    scanf("%d",&A[i]);

  j=partition(n);

  for(i=1; i<j; i++){
    printf("%d ",A[i]);
  }

  printf("[%d] ",A[j]);

  for(i=j+1; i<=n-1; i++){
    printf("%d ",A[i]);
  }

  printf("%d\n",A[n]);
  
  return 0;
}

int partition(int r){
  int x,i,j,temp,p=1;

  x = A[r];
  i = p-1;

  for(j=p; j<=r-1; j++){
    if(A[j] <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }

  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;

  return i+1;
}
      



Measured memory_bytes: 2116
#include<iostream>
using namespace std;
long long N,A,B;
int main(){
    cin>>N;
    int a[N],b[N];
    for(int i=0;i<N;i++)cin>>a[i];
    for(int i=0;i<N;i++)cin>>b[i];
    for(int i=0;i<N;i++){
        if(a[i]>b[i])A+=(a[i]-b[i]);
        if(a[i]<b[i])B+=(b[i]-a[i])/2;
    }
    cout<<(A<=B?"Yes":"No")<<endl;
    return 0;
}

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

int main(){
  int n; cin >> n;
  int l[n];
  int t, max=0,sum=0;
  for(int i=0;i<n;i++){
    cin >> t;
    sum+=t;
    if(t>max)
      max=t;
  }
  sum-=max;
  if(sum>max)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
d = []
h = Hash.new(0)
1.upto(k) do |i|
  d[i] = gets.to_i
  a = gets.split.map(&:to_i)
  a.each do |x|
    h[x] += 1
  end
end
puts n - h.size

Measured memory_bytes: 14300
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define ld long double
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define mod 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  if (W < V && ((ld)abs(B - A) / (V - W)) <= T) {
  	cout << "YES" << endl;
  } else {
  	cout << "NO" << endl;
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
const int INF=1e9 +5;
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);   
    // freopen("output.txt", "w", stdout);
    // #endif
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int n;cin>>n;
    int a[n],b[n],c[n];
    int dp1[n],dp2[n],dp3[n];
    cin>>a[0]>>b[0]>>c[0];
    dp1[0]=a[0],dp2[0]=b[0],dp3[0]=c[0];
    repA(i,1,n-1){
        cin>>a[i]>>b[i]>>c[i];
        dp1[i]=a[i];
        dp1[i]+=max(dp2[i-1],dp3[i-1]);
        dp2[i]=b[i];
        dp2[i]+=max(dp1[i-1],dp3[i-1]);
        dp3[i]=c[i];
        dp3[i]+=max(dp2[i-1],dp1[i-1]);
    }
    cout<<max({dp1[n-1],dp2[n-1],dp3[n-1]});
    return 0;
}

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

int main() {
  long int n;
  cin >> n;
  vector<long int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  long int j = 1;
  for(int i = 0; i < n; i++){
    if(a.at(i) == j){
      j++;
    }
  }
  if(j == 1){
    cout << -1;
    return 0;
  }
  cout << n - j + 1;
}

Measured memory_bytes: 1792
from collections import Counter

N = int(input())

counter = Counter()
for _ in range(N):
    s = input()[0]
    if s in ('MARCH'):
        counter[s] += 1
if len(counter) < 3:
    print(0)
    exit()

import itertools

ans = 0
for a, b, c in itertools.combinations(counter.keys(), 3):
    ans += counter[a] * counter[b] * counter[c]
print(ans)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  

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

  string ret = "APPROVED";
  rep(i, N)
  {
    int m;
    cin >> m;
    
    if(m % 2 == 0 && m % 3 != 0 && m % 5 != 0)
    {
      ret = "DENIED";
      break;
    }
  }

  cout << fixed << ret << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = [int(i) for i in raw_input ().split()]
X, Y = [int(i) for i in raw_input ().split()]
for i in range(M - 1):
    x, y = [int(i) for i in raw_input ().split()]
    X = max(X, x)
    Y = min(Y, y)
print max(0, Y - X + 1)


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

int sum(int x) {
    return x/100000 + (x/10000)%10 + (x/1000)%10 + (x/100)%10 + (x/10)%10 + x%10;
}


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

    int min = 45;
    for (int i = 1; i < N; i++) {
        if (sum(i)+sum(N-i) < min ) {
            min = sum(i)+sum(N-i);
        }
    }

    cout<<min<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define ll long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl '\n'



using namespace std;
ll exp(ll a,ll b,ll m)
{
if(b==0)
	{
		return 1;
	}
	ll temp =exp(a,b/2,m);
	temp=(temp*temp)%m;
	if(b&1)
	{
		return (temp*(a%m))%m;
	}
	return temp;
}
	
int main()
{
	int n;
	cin>>n;
	int array[n] = {0};
	f(i,0,n)
	{
		cin>>array[i];
	}
	bool flag = true;
	f(i,0,n)
	{
		if(array[i]%2==0)
		{
			if(array[i]%3!=0 && array[i]%5!=0)
			{
				flag = false;
				break;
			}
		}
	}
	if(flag) cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;	
	return 0;
}



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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,X,Y=MI()
    X-=1
    Y-=1
    
    ans=[0]*N
    
    for i in range(N):
        for j in range(i+1,N):
            d=min(j-i,abs(X-i)+1+abs(Y-j))

                
            ans[d-1]+=1
            
    for i in range(N-1):
        print(ans[i])
                

                
   

main()


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

int main() {
  int n;
  cin >> n;
  
  vector<string>s(n);
  for(int i=0; i<n; i++) {
    cin >> s.at(i);
    sort(s.at(i).begin(), s.at(i).end());
  }
  
  sort(s.begin(), s.end());
  
  int count = 1;
  long long answer = 0;
  
  for(int i=1; i<n; i++) {
    if(s.at(i) == s.at(i-1)) {
      answer += count;
      count++;
    }
    else
      count = 1;
  }
  
  cout << answer << endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(string S){
	int r = 100000;
	for(int i = 0; i + 3 <= S.size(); ++i) {
		int t = 0;
		for(int j = 0; j < 3; ++j) {
			t = t * 10 + (S[i + j] - '0');
		}
		r = min(r, abs(t - 753));
	}
	cout << r << endl;
}

signed main(){
	string S;
	cin >> S;
    	solve(S);
    	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type Num struct {
	Num   int
	Index int
}

type Nums []Num

func (n Nums) Len() int {
	return len(n)
}

func (n Nums) Swap(i, j int) {
	n[i], n[j] = n[j], n[i]
}

func (n Nums) Less(i, j int) bool {
	return n[i].Num < n[j].Num
}

func main() {
	var N int
	fmt.Scan(&N)
	nums := scanNums(N)
	_nums := Nums{}
	for _, num := range nums {
		_nums = append(_nums, num)
	}
	sort.Sort(nums)
	half := (N + 1) / 2
	numMap := map[int]int{}
	for i := 0; i < N; i++ {
		_half := half
		if i >= half {
			_half = half - 1
		}
		numMap[nums[i].Num] = nums[_half].Num
	}
	for _, num := range _nums {
		fmt.Println(numMap[num.Num])
	}
}

func scanNums(len int) (nums Nums) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, Num{Num: num, Index: i})
	}
	return nums
}

Measured memory_bytes: 25600
H, W, n = [int(i) for i in input().split()]
r, c = [int(i) for i in input().split()]
S = input()
T = input()

L = 0
R = 1
U = 2
D = 3
f = {'L': 0, 'R': 1, 'U': 2, 'D': 3}
rf = {'L': 1, 'R': 0, 'U': 3, 'D': 2}

need = [c, W - c + 1, r, H - r + 1]

for i in range(n):
    need[f[S[i]]] -= 1
    if need[f[S[i]]] <= 0:
        print('NO')
        exit()
    need[rf[T[i]]] = min(W if T[i] == 'L' or T[i] == 'R' else H , need[rf[T[i]]] + 1)

print('YES')

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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

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

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

   int N;
   cin>>N;
   for(;N%111!=0;N++);
   cout<<N;
   return 0; 
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 



using namespace std;
//-------------------------------------------
typedef pair<ll,ll> P;
int main(void){
    ll A,B;cin>>A>>B;
    ll n=GCD(A,B);
    ll n2=sqrt(n);
    ll cnt=1;
    FOR(i,2,n2+1){
        ll k=0;
        while(n%i==0)n/=i,k=1;
        cnt+=k;
        //if(k==1)cout<<i<<" ";
    }
    if(n>1)cnt++;
    cout<<cnt<<"\n";
    
}

Measured memory_bytes: 256
//
// Created on 2020/02/16.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    string ans;
    int a;
    int b;
    int c;
    cin>>a>>b>>c;
    if(a==b && a != c)ans ="Yes";
    else if(a == c && a != b) ans="Yes";
    else if(b == c && a != b) ans="Yes";
    else ans = "No";

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
  int n;
  cin>>n;
  ll a[n];
  ll ans=1;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]==0)
      ans=0;
  }
  if(ans==0)
  {
    cout<<0;
    return 0;
  }
  ll x=1e18;
  for(int i=0;i<n;i++)
  {
    if((x/ans)<a[i])
    {
      ans=-1;
      break;
    }
    ans*=a[i];
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 4420
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    ll r, s, p; cin >> r >> s >> p;
    string t; cin >> t;
    V<char> h(n, '.');
    for (int i = 0; i < n; i++) {
        if (i < k) {
            if (t[i] == 'r') h[i] = 'p';
            else if (t[i] == 's') h[i] = 'r';
            else h[i] = 's';
        } else {
            if (t[i] == 'r') {
                if (h[i - k] == 'p') {
                    if (i + k < n) {
                        if (t[i + k] == 's') h[i] = 's';
                        else if (t[i + k] == 'p') h[i] = 'r';
                        else h[i] = 's';
                    } else h[i] = 'r';
                } else h[i] = 'p';
            } else if (t[i] == 's') {
                if (h[i - k] == 'r') {
                    if (i + k < n) {
                        if (t[i + k] == 's') h[i] = 's';
                        else if (t[i + k] == 'r') h[i] = 's';
                        else h[i] = 'p';
                    } else h[i] = 's';
                } else h[i] = 'r';
            } else { // t[i] == p
                if (h[i - k] == 's') {
                    if (i + k < n) {
                        if (t[i + k] == 's') h[i] = 'p';
                        else if (t[i + k] == 'r') h[i] = 'r';
                        else h[i] = 'p';
                    } else h[i] = 'p';
                } else h[i] = 's';
            }
        }
    }

    // for (int i = 0; i < n; i++) cout << h[i] << (i == n - 1 ? '\n' : ' ');
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (t[i] == 'r' && h[i] == 'p') ans += p;
        else if (t[i] == 's' && h[i] == 'r') ans += r;
        else if (t[i] == 'p' && h[i] == 's') ans += s;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf

int main()
{
	int a,b;
	sf("%d%d",&a,&b);
	if(a==b||-a==b||a==-b){
		pf("0\n");
	}
	if(a>b){
		swap(a,b);
	}
	for(int i=a;i<b;i++){
		if(-(a-i)==(b-i)){
		
			pf("%d\n",i);
			return 0;
		}
	}
	pf("IMPOSSIBLE\n");
	return 0;
}

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

const int Maxn = 305;
int n, m, s, t, cnt, cur[Maxn], col[Maxn * Maxn], dis[Maxn], tmp[Maxn], head[Maxn], a[Maxn][Maxn], ans1[Maxn][Maxn], ans2[Maxn][Maxn];
vector <int> Ve[Maxn][Maxn];
struct edg
{
	int nxt, to, w;
	bool del;
}edge[2 * Maxn * Maxn];
void add(int x, int y, int w)
{
	edge[++cnt] = (edg){head[x], y, w};
	head[x] = cnt;
	edge[++cnt] = (edg){head[y], x, 0, true};
	head[y] = cnt;
}
queue <int> Qu;
bool bfs(void)
{
	memset(dis, 0, sizeof(dis));
	Qu.push(s);
	while (!Qu.empty())
	{
		int u = Qu.front();
		Qu.pop();
		for (int i = head[u]; i; i = edge[i].nxt)
		{
			int to = edge[i].to;
			if (edge[i].w && to != s && !dis[to])
				dis[to] = dis[u] + 1, Qu.push(to);
		}
	}
	return (bool)dis[t];
}
int dfs(int u, int mini)
{
	if (u == t || !mini) return mini;
	int w, used = 0;
	for (int &i = cur[u]; i; i = edge[i].nxt)
	{
		if (i == 7)
			i++, i--;
		int to = edge[i].to;
		if (dis[to] == dis[u] + 1 && edge[i].w)
		{
			w = dfs(to, min(edge[i].w, mini - used));
			edge[i].w -= w, edge[((i - 1) ^ 1) + 1].w += w, used += w;
		}
	}
	return used;
}
void dinic(void)
{
	while (bfs())
	{
		memcpy(cur, head, sizeof(cur));
		dfs(s, 0x3f3f3f3f);
	}
}
int main()
{
//	freopen("agc037_d.in", "r", stdin);
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n * m; i++)
		col[i] = (i - 1) / m + 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			scanf("%d", &a[i][j]);
			add(i, n + col[a[i][j]], 1);
			Ve[i][col[a[i][j]]].push_back(a[i][j]);
		}
	s = 2 * n + 1, t = 2 * n + 2;
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
			add(s, j, 1), add(n + j, t, 1);
		dinic();
		for (int u = 1; u <= n; u++)
			for (int j = head[u]; j; j = edge[j].nxt)
			{
				int to = edge[j].to;
				if (!edge[j].w && !edge[j].del)
				{
					edge[j].del = true;
					edge[((j - 1) ^ 1) + 1].w = 0;
					ans1[u][i] = *Ve[u][to - n].rbegin();
					Ve[u][to - n].pop_back();
					break;
				}
			}
	}
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
			tmp[j] = ans1[j][i];
		sort(tmp + 1, tmp + 1 + n);
		for (int j = 1; j <= n; j++)
			ans2[j][i] = tmp[j];
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
			printf("%d ", ans1[i][j]);
		puts("");
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
			printf("%d ", ans2[i][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 5760
N, M = map(int, input().split())
H = list(map(int, input().split()))

towers = {}
for n in range(N):
    towers[n] = []

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    towers[a].append(b)
    towers[b].append(a)

result = 0
for tower_number, related_towers in towers.items():
    if len(related_towers) == 0:
        result += 1
        continue

    tower_height = H[tower_number]
    other_heights = [H[i] for i in related_towers]
    if tower_height > max(other_heights):
        result += 1

print(result)


Measured memory_bytes: 37812
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

int main(){
    char s1[100],s2[100],p[100];
    cin>>s1>>p;
    strcpy(s2, s1);
    
    strcat(s1,s2);
        if ( strstr(s1, p) == NULL ) printf("No\n");
        else printf("Yes\n");
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
#define pb push_back

#define N 210
int n, a[N];
vector<int> A;

void rot(int k) {
	if (k == 0) return;
	A.pb(k);
	for (int i = k; i < n; i ++) swap(a[i], a[i-k]);
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i ++) cin >> a[i];
	while (true) {
		bool F = false;
		for (int i = 0; i < n; i ++) {
			if (a[0] != 0 && a[n-1] > a[0]) {
				F = true;
				rot(n-1);
			}
			rot(1);
		}
		if (!F) break;
	}
	while (a[0] != 0) rot(1);
	printf ("%d\n", (int) A.size());
	for (int i = 0; i < (int) A.size(); i ++)
		cout << A[i] << endl;
	for (int i = 0; i < n; i ++) assert(a[i] == i);
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n, k;
    cin >> n >> k;
    double ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int num = i;
        double tmp = (1.0 / n);
        while (num < k)
        {
            num *= 2;
            tmp /= 2;
        }
        ans += tmp;
    }
    printf("%.15lf\n", ans);
}


Measured memory_bytes: 256
from itertools import permutations
from math import sqrt

def factorial(n):
  if n < 2:
    return 1
  return n * factorial(n - 1)


def distance(a, b):
  dx = a[0] - b[0]
  dy = a[1] - b[1]
  return sqrt(dx * dx + dy * dy)


def calc_len(points, perm):
  res = 0
  for i in range(1, len(perm)):
    a = points[perm[i]]
    b = points[perm[i - 1]]
    res += distance(a, b)
  return res


n = int(input())
points = []
for _ in range(n):
  x, y = map(int, input().split())
  points.append((x, y))

total_len = 0
for perm in permutations(list(range(n))):
  total_len += calc_len(points, perm)
print(total_len / factorial(n))


Measured memory_bytes: 3064
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

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

    int ans = 1;
    rep(i, N) {
        int number = (i + 1) * (i + 1);
        if (number > N) {
            ans = i * i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl;

#define iosbase ios_base::sync_with_stdio(false)
#define tie cin.tie();cout.tie();

#define endl '\n'

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

int vis[100100];

int n, m, k, q;
int main(){
  iosbase;
  tie;

  cin >> n >> k >> q;
  for(int i = 0; i < q; i++){
    cin >> m;
    vis[m]++;
  }

  for( int i = 1; i <= n; i++){
    if( k - q + vis[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

}


Measured memory_bytes: 1024
#include <iostream>

int main(int argc, const char * argv[]) {
    int w, h, x, y, r;
    std::cin >> w >> h >> x >> y >> r;
    if (0 <= x - r && x + r <= w
        && 0 <= y - r && y + r <= h)
    {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3096
import sys
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
N,M,L = map(int,input().split())
 
A = [list(map(int,input().split())) for i in range(N)] #N*M配列の取得
B = [list(map(int,input().split())) for i in range(M)] #M*L配列の取得
ANS = [[0]*L for i in range(N)] #N*L
 
 
for x in range(N):
    for y in range(L):
        for z in range(M):
            ANS[x][y] += B[z][y]*A[x][z]
 
for row in range(N):
    print("%d"%ANS[row][0],end = "")
    for col in range(1,L):
        print(" %d"%(ANS[row][col]),end = "")
    print()


Measured memory_bytes: 7068