akhauriyash/Code-Regression huggingface dataset:
s = gets.chomp
S = s.split('')

if S[0] == 'k' && S[S.size-6] == 'e' && S[S.size-5] == 'y' && S[S.size-4] == 'e' && S[S.size-3] == 'n' && S[S.size-2] == 'n' && S[S.size-1] == 'e'
puts 'YES'
elsif   S[0] == 'k' && S[1] == 'e' && S[S.size-5] == 'y' && S[S.size-4] == 'e' && S[S.size-3] == 'n' && S[S.size-2] == 'c' && S[S.size-1] == 'e'
puts 'YES'
elsif  S[0] == 'k' && S[1] == 'e' && S[2] == 'y' && S[S.size-4] == 'e' && S[S.size-3] == 'n' && S[S.size-2] == 'c' && S[S.size-1] == 'e'
puts 'YES'
elsif S[0] == 'k' && S[1] == 'e' && S[2] == 'y' && S[3] == 'e' && S[S.size-3] == 'n' && S[S.size-2] == 'c' && S[S.size-1] == 'e'
puts 'YES'
elsif S[0] == 'k' && S[1] == 'e' && S[2] == 'y' && S[3] == 'e' && S[4] == 'n' && S[S.size-2] == 'c' && S[S.size-1] == 'e'
puts 'YES'
elsif S[0] == 'k' && S[1] == 'e' && S[2] == 'y' && S[3] == 'e' && S[4] == 'n' && S[5] == 'c' && S[S.size-1] == 'e'
puts 'YES'
elsif S[0] == 'k' && S[1] == 'e' && S[2] == 'y' && S[3] == 'e' && S[4] == 'n' && S[5] == 'c' && S[6] == 'e'
    puts 'YES'
elsif S[S.size-7] == 'k' && S[S.size-6] == 'e' && S[S.size-5] == 'y' && S[S.size-4] == 'e' && S[S.size-3] == 'n' && S[S.size-2] == 'c' && S[S.size-1] == 'e'
    puts 'YES'
else
    puts 'NO'
end

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

int main(){
    int n; cin >> n;
    int ans = 1;
    for(int i=0;i<100000;i++){
        if(i*i <= n){
            ans = i*i;
        }else{
            break;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
    int n,i,p;
    set<int> s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>p;
        s.insert(p);
    }
    cout<<s.size()<<'\n';
    return(0);
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main() {
    int m , d , d1 = 1 , m1 = 1,n = 0;
    cin >> m >> d;
    while(true){
        if(m1 > m)
            break;
        if(m1 == m)
            if(d1 > d)
                break;
        d1++;
        m1++;
        n++;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = 10 ** 9 + 7
a = 1
b = 1
c = 1
for i in range(n):
    a = (a * 10) % p
    b = (b * 9) % p
    c = (c * 8) % p
y = a - 2 * b + c
if y < 0:
    while y < 0:
        y += p
elif y > p:
    while y > p:
        y -= p
print(y)

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

int main(){
    int N, M;
    cin >> N >> M;
    map<int, int> mp;
    for(int i=0; i<N+M; i++){
        int a;
        cin >> a;
        mp[a]++;
    }
    vector<int> And, Or;
    for(auto& p : mp){
        if(p.second == 2) And.push_back(p.first);
        Or.push_back(p.first);
    }
    cout << And.size() << " " << Or.size() << endl;
    for(int a : And) cout << a << endl;
    for(int a : Or) cout << a << endl;
}



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

int main() {
	int a, b;
	cin >> a >> b;

	if (a >= b) {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
		cout << endl;
	}
	else {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	char a[10];
	int i,j;
	scanf("%s",&a);
	if(a[2]==a[3]&&a[4]==a[5])
	printf("Yes");
	else
	printf("No");
return 0;
}

Measured memory_bytes: 256
use std::io::{stdin, Read};
use std::str::FromStr;
#[allow(unused_imports)]
use std::{cmp, mem, process};
#[allow(unused_imports)]
use std::collections::{HashSet, BTreeMap, BTreeSet};
fn calc(x: &Vec<usize>) -> usize {
    let mut y = x.clone();
    while y.len() > 1 {
        let mut nxt = vec![];
        for i in 0..y.len() - 2 {
            let mut temp = vec![y[i], y[i + 1], y[i + 2]];
            temp.sort();
            nxt.push(temp[1]);
        }
        y = nxt;
    }
    y[0]
}

fn solve(n: usize, x: usize) {
    // 3 ならば 1,7 はでない
    // 4 ならば 1,2 6,7 はでない
    // 5 ならば 1,2,3 7,8,9 はでない
    if n == 2 {
        if x == 2 {
            println!("Yes");
            println!("1 2 3");
        } else {
            println!("No");
        }
        return;
    }
    if 1 != x && 2 * n - 1 != x {
        // ok
        //println!("{} {} ", n, x);
        let mut ans = vec![0; 2 * n - 1];
        let mut memo = vec![false; 2 * n + 10];
        if x != 2 {
            ans[n - 1] = x;
            ans[n - 2] = x - 1;
            ans[n] = x + 1;
            ans[n + 1] = x - 2;
            for i in x - 2..x + 2 {
                memo[i] = true;
            }
        } else {
            ans[n - 1] = x;
            ans[n - 2] = x + 1;
            ans[n] = x - 1;
            ans[n + 1] = x + 2;
            for i in x - 1..x + 3 {
                memo[i] = true;
            }

        }
        let mut cnt = 1;
        for i in 0..2 * n - 1 {
            if ans[i] != 0 {
                continue;
            } else {
                while memo[cnt] {
                    cnt += 1;
                }
                ans[i] = cnt;
                memo[cnt] = true;
            }
        }
        // if calc(&ans) != x {
        //     assert!(false);
        // }
        println!("Yes");
        for i in &ans {
            println!("{}", *i);
        }
    } else {
        println!("No");
    }
}


fn main() {
    // for i in 2..20 {
    //     for j in 1..2 * i {
    //         solve(i, j);
    //     }
    // }
    let n = read::<usize>();
    let x = read::<usize>();
    solve(n, x);

}
#[allow(dead_code)]
fn read_vec<T: FromStr>(n: usize) -> Vec<T> {
    let mut v = vec![];
    for _ in 0..n {
        let a = read::<T>();
        v.push(a);
    }
    v
}
#[allow(dead_code)]
fn read_str() -> Vec<char> {
    let s: String = read();
    s.chars().collect::<Vec<char>>()
}
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(
        |_| panic!("Faild to parse {}", s),
    )
}


Measured memory_bytes: 7676
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int a[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	long long k;
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	set<int> seen;
	int now = 0;
	while(k) {
		if(seen.find(now) != seen.end()) break;
		k--;
		seen.insert(now);
		now = a[now];
	}
	if(k == 0) {
		cout << now + 1;
		exit(0);
	}
	int len = 0;
	int x = now;
	do {
		len++;
		x = a[x];
	}while(x != now);
	k %= len;
	while(k) {
		now=a[now];
		k--;
	}
	cout << now + 1;
	return 0;
}


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

int main(){
  int h,n;
  cin >> h>>n;
  
  int asum=0,a;
  for(int i=0; i<n; i++){
    cin >> a;
    asum += a;
  }
  
  if(asum>=h)cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;

char str[200005];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    int n=strlen(str);
    int cnt[26]={0};
    int i;
    ll ans=0;
    for(i=0; i<n; i++) {
        int tmp=str[i]-'a';
        ans+=(i-cnt[tmp]);
        cnt[tmp]++;
    }
    printf("%lld\n", ans+1);

    return 0;
}


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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
    ll n;
    cin >> n;
    ll a[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[n] << endl;
}

int main(){
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
} 

Measured memory_bytes: 256
NM = input().split()
A = input().split()
N = int(NM[0])
M = int(NM[1])
for j in range(N):
    A[j] = int(A[j])
A.sort(reverse=True)
for i in range(M):
    if int(A[i]) < sum(A)/4/M:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
# Template 1.0
import sys, re
from decimal import *
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor, trunc, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a,b,c = MAP()

if(a==c and a!=b) or (a==b and a!=c) or (b==c and b!=a):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 76368
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> vec(N);
    for(int i = 0; i< N; ++i){
        cin>>vec.at(i);
    }
    sort( vec.begin(), vec.end() );
    cout<< vec.at(N-1) - vec.at(0)<<endl;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new java.util.Scanner(System.in);

	public static void main(String[] args) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();

		int num[] = { a, b, c, d, e };
		Arrays.sort(num);

		for (int i = 4; i > 0; i--) {
			System.out.print(num[i] + " ");
		}
		System.out.println(num[0]);

	}

}

Measured memory_bytes: 26164
from queue import Queue


def bfs(s):
    q = Queue()
    q.put(((0,0), 0))
    found = set()
    while q.qsize() > 0:
        x, nsteps = q.get()
        if x in found:
            continue
        found.add(x)
        for d in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            y = (x[0]+d[0], x[1]+d[1])
            if y[0] < 0 or y[0] >= H or y[1] < 0 or y[1] >= W:
                continue
            if s[y[0]][y[1]] == '#':
                continue
            if y == (H-1, W-1):
                return nsteps+1
            if y in found:
                continue
            q.put((y, nsteps+1))
    return -1




H, W = list(map(int, input().split(' ')))
s = []
nwhites = 0
for i in range(H):
    s.append([c for c in input()])

for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            nwhites += 1

nsteps = bfs(s)

if nsteps == -1:
    print(-1)
else:
    print(nwhites - nsteps - 1)

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

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

class DisjointSets {
  vi rank, p;

public:
  DisjointSets() {}
  DisjointSets(int s) {
    rank.resize(s, 0);
    p.resize(s, 0);

    rep(i, s) makeSet(i);
  }

  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }
  
  bool is_same(int x, int y) {
    return findSet(x) == findSet(y);
  }

  int findSet(int x) {
    if (x != p[x]) p[x] = findSet(p[x]);
    return p[x];
  }

  void unite(int x, int y) {
    link(findSet(x), findSet(y));
  }

  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    } else {
      p[x] = y;
      if (rank[x] == rank[y]) rank[y]++;
    }
  }
};

struct Edge {
  int s, t, w;
  Edge() {}
  Edge(int s, int t, int w): s(s), t(t), w(w) {}
  bool operator < (const Edge &e) const {
    return w < e.w;
  }
};

int v, e;
vvpii g;
vector<Edge> edges;

int kruskal() {
  int total = 0;
  sort(edges.begin(), edges.end());

  auto ds = DisjointSets(v + 1);
  rep(i, v) ds.makeSet(i);
  
  int s, t, w;
  rep(i, e) {
    auto ed = edges[i];
    s = ed.s; t = ed.t; w = ed.w;
    if (!ds.is_same(s, t)) {
      total += w;
      ds.unite(s, t);
      // k.push_back(e);
    }
  }

  return total;
}

int main() {
  cin >> v >> e;
  g.resize(v);

  int s, t, w;
  rep(i, e) {
    cin >> s >> t >> w;
    edges.push_back(Edge(s, t, w));
  }

  cout << kruskal() << endl;
}



Measured memory_bytes: 4756
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

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

int main()
{
        //input->compute->output//
        int N;
        cin >> N;

        if (N < 1200)
        {
                cout << "ABC" << endl;
        }
        else if (N < 2800)
        {
                cout << "ARC" << endl;
        }
        else
        {
                cout << "AGC" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if (a == b && b == c) {
        Yes;
    }else{
        No;
    }
    return 0;
}


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

int vis[200];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);// don't forget &
    for (int i = 1; i <= k; i++) {
        int m;
        scanf("%d", &m);// don't forget &
        for (int j = 1; j <= m; j++) {
            int x;
            scanf("%d", &x);// don't forget &
            vis[x] = 1;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (vis[i] == 0) {
            ans++;
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 3844
s = input()
K = int(input())
L = len(s)
cand = []

if L > 5:
    c = []
    order = sorted(list(s))
    for i in range(L):
        if order[i] in c:
            pass
        else:
            c.append(order[i])
            if len(c) == 5:
                break
else:
    c = list(s)

for i in range(L):
    if s[i] in c:
        for j in range(i+1,min(i+K+1,L+1)):
            cand.append(s[i:j])
cand.sort()

i = 0
if len(cand) == 1:
    print(cand[0])
    exit()

i = 0
while True:
    K -= 1
    if K == 0:
        print(cand[i])
        break
    i += 1
    while(cand[i] == cand[i-1]):
        cand.pop(i)


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

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

int main() {
	int N;
	scanf("%d",&N);
	int L[N];
	for (int i = 0; i < N; i++) {
		scanf("%d",&L[i]);
	}
	qsort(L, N, sizeof(int), compare_int);
	int sum=0;
	for (int i = 0; i < N-1; i++) {
		sum += L[i];
	}
	if (sum > L[N-1]) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Threading;

class Gacha
{
    static void Main(string[] args)
    {
        var times = Console.ReadLine();

        HashSet<string> set = new HashSet<string>();


        for(var i = 0; i < int.Parse(times); i++)
        {
            var gacha = Console.ReadLine();

            if(i == 0)
            {
                set.Add(gacha);
            }
            else
            {
                if(!set.Contains(gacha))
                {
                    set.Add(gacha);
                  
                }
            }
        }
        Console.WriteLine(set.Count);
    }
}

Measured memory_bytes: 42924
#include <bits/stdc++.h>
#define _LIBCPP_DEBUG 0
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> A(n);
    A = {2, 1};
    for(int i = 2; i <= n; i++) {
        A.push_back(A[i - 1] + A[i - 2]);
        //cout << A[i] << endl;
    }
    cout << A[n] << endl;

    return 0;
}

Measured memory_bytes: 256
#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(){
  char tmp[3];
  cin >> tmp[0] >> tmp[1] >> tmp[2];
  string ret="No";
  if(tmp[0]!=tmp[1]) ret="Yes";
  if(tmp[1]!=tmp[2]) ret="Yes";
  if(tmp[2]!=tmp[0]) ret="Yes";  
  cout << ret << endl;
  return 0;
}


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

using namespace std;
map<char,int> m1;
map<char,int> m2;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        m2.clear();
        for(auto x:s){
            m2[x]++;
        }
        if(i==1){
            for(auto x:m2){
                m1[x.first] = x.second;
            }
            continue;
        }
        for(auto x:m2){
            m1[x.first] = min(m1[x.first],m2[x.first]);
        }
        for(auto x:m1){
            m1[x.first] = min(m1[x.first],m2[x.first]);
        }
    }
    for(auto x:m1){
        for(int i=1;i<=x.second;i++){
            cout<<x.first;
        }
    }
}

Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 2005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
pair<ll,ll>  p[N+1];
ll dp[N][N];
ll solve1(ll id,ll first,ll last)
{
     if(id==0)    return 0;
     ll crt = p[id].ss;
     ll dif1 = abs(crt-first);
     ll dif2 = abs(crt-last);
     ll ans=dp[id][first];
     if(ans!=-1)   return ans;
     ans = max((solve1(id-1,first,last-1)+p[id].ff*dif2),(solve1(id-1,first+1,last)+p[id].ff*dif1));
     return dp[id][first] = ans;
}
void solve()
{
     ll n;
     cin >> n;
     for(ll i=1;i<=n;i++)
     {
          cin >> p[i].ff;
          p[i].ss = i;
     }
     sort(p+1,p+n+1);
     set<ll> s;
     memset(dp,-1,sizeof(dp));
     ll ans = solve1(n,1,n);
     cout<<ans;
}

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


Measured memory_bytes: 35248
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){

	int n;
	vector<int> a;
	cin>>n;
	for(int i=0;i<n;++i){
		int m;
		cin>>m;
		a.push_back(m);
	}
	
	for(int i=n-1;i>=0;--i){
		cout<<a[i];
		if(i!=0)
			cout<<" ";
	}
	cout<<endl;
	return 0;
}

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

namespace ConsoleApp14
{
    class Class16
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int count = 0;
            
            for(int i = 1; i <= Math.Min(s.Length, t.Length); i++)
            {
                if (s.Substring(s.Length-i, i) == t.Substring(0, i))
                    count = i;
            }
            Console.WriteLine(s.Length + t.Length - count);
            
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(true){
  	c -= b;
  	if(c <= 0){
  		cout << "Yes" << endl;
  		return 0;
  	}

  	a -= d;
  	if(a <= 0){
  		cout << "No" << endl;
  		return 0;
  	}
  }
  return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		
		int[] a = new int[5];
		
		a[0] = s.nextInt();
		a[1] = s.nextInt();
		a[2] = s.nextInt();
		a[3] = s.nextInt();
		a[4] = s.nextInt();
		
		int k = s.nextInt();
		
		for(int i=0 ; i < 4 ; i++) {
			for(int j = i+1 ; j < 5; j++) {
				if(a[j] - a[i] > k) {
					System.out.println(":(");
					return;
				}
			}
		}
		
		
		System.out.println("Yay!");
		s.close();
		
	}

}

Measured memory_bytes: 21844
import java.util.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner stdIn = new Scanner(System.in);
		int[] height = new int[10];
		int[] max = new int[3];
		
		for (int i = 0; i < 10; i++){
			height[i] = stdIn.nextInt();
			if (i == 0){
				max[0] = height[i];
			}
			else {
				for (int j = 0; j < 3; j++){
					if (max[j] < height[i]){
						for (int k = 2; k > j; k--){
							max[k] = max[k - 1];
						}
						max[j] = height[i];
						break;
					}
				}
			}
		}
		for (int i = 0; i < 3; i++){
			System.out.println(max[i]);
		}
	}
}

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


int main() {
    int h,w;
    cin >> h >> w;
    int ans = h*w;
    int h2,w2;
    cin >> h2 >> w2;
    ans -= (h2*w + w2*h - h2*w2);
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class AOJ
{
	public static void Main()
	{
        var prime = new List<int>{ 2 };
        for (int i = 3; i <= 10000; i = i + 2)
        {
        	bool is_prime = true;
        	foreach(var p in prime)
        	{
        		if(i % p == 0)
        		{
        			is_prime = false;
        			break;
        		}
        	}
            if (is_prime) { prime.Add(i); }
        }

        int count = int.Parse(Console.ReadLine().Trim());
        int ans = 0;
        for (int i = 0; i < count; i++)
        {
            int test = int.Parse(Console.ReadLine().Trim());
            bool is_prime = true;
            foreach(var p in prime)
            {
            	if(test == p){ break; }
            	if(test % p == 0)
            	{
            		is_prime = false;
            		break;
            	}
            }
            if(is_prime){ ans++; }
        }
        Console.WriteLine(ans);
	}
}

Measured memory_bytes: 5824
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func NextStr() string {
	scanner.Scan()
	return scanner.Text()
}

func NextInt() int {
	i, _ := strconv.Atoi(NextStr())
	return i
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

func SqrtInt(x int) float64 {
	float_x := float64(x)
	return math.Sqrt(float_x)
}

func Sieve(n int) []int {
	var isPrime [2000000 + 5 + 1]bool
	D := make([]int, 2000000+5+1)
	for i := 0; i < len(D); i++ {
		D[i] = i
	}

	for i := 0; i <= n; i++ {
		isPrime[i] = true
	}

	isPrime[0] = false
	isPrime[1] = false

	for i := 2; i <= n; i++ {
		if isPrime[i] {

			for j := 2 * i; j <= n; j += i {
				isPrime[j] = false
				D[j] = i
			}
		}
	}
	return D
}

func Contains(n int, A []int) bool {
	for _, e := range A {
		if n == e {
			return true
		}
	}
	return false
}

const MaxA = 1000001

func main() {
	scanner.Split(bufio.ScanWords)
	D := Sieve(MaxA)

	n := NextInt()
	res := NextInt()

	var used [MaxA]bool
	for i := 0; i < MaxA; i++ {
		used[i] = false
	}

	isPC := true

	m := res
	for m > 1 {
		prime := D[m]
		used[prime] = true
		for D[m] == prime {
			m /= prime
		}
	}

	for i := 0; i < n-1; i++ {
		Ai := NextInt()
		res = Gcd(res, Ai)
		m := Ai
		for m > 1 {
			prime := D[m]
			if used[prime] {
				isPC = false
			}
			used[prime] = true
			for D[m] == prime {
				m /= prime
			}

		}
	}

	var ans string
	if res != 1 {
		ans = "not coprime"
	} else if isPC {
		ans = "pairwise coprime"
	} else {
		ans = "setwise coprime"
	}

	fmt.Println(ans)
}


Measured memory_bytes: 29024
#include <cstdio>
#include <queue>
using namespace std;
#define MP make_pair
int len[100002];
int main(){
    int N,L;
    scanf("%d%d",&N,&L);
    for(int i=1;i<=N;i++){
        scanf("%d",&len[i]);
    }
    len[0]=len[N+1]=0;
    priority_queue<pair<int,int> > pq;
    for(int i=1;i<=N;i++){
        if(len[i]>len[i-1]&&len[i]>len[i+1]) pq.push(MP(len[i],i));
    }
    int now=0;
    while(!pq.empty()){
        int nat=pq.top().second,nlen=pq.top().first;
        pq.pop();
        now+=L-(nlen+now);
        len[nat]=0;
        int bef=nat-1,aft=nat+1;
        if(len[bef]>0 && len[bef]>len[bef-1] && len[bef]>len[bef+1]){
            pq.push(MP(len[bef]-now,bef));
        }
        if(len[aft]>0 && len[aft]>len[aft-1] && len[aft]>len[aft+1]){
            pq.push(MP(len[aft]-now,aft));
        }
    }
    printf("%d\n",now);
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
   int n;
   cin>>n;
   int a,b;
   int count=0;
   bool status = false;
   while(n--)
   {
      cin>>a>>b;
      if(a==b)
      {
          count++;
      }
      else
      {
          count=0;
      }
      if(count==3)
      {
          cout<<"Yes"<<endl;
          status = true;
         break; 
      }
   }
   if(status==false)
   {
       cout<<"No\n";
   }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T> ostream& operator<<(ostream &os, const vector<T> &v){os << "{";ITR(i,v){if(i!=v.begin())os << ","; os << *i;}os << "}"; return os;}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

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

  int n,h,w; cin >> n >> h >> w;
  int ans = (n-h+1) * (n-w+1);
  cout << ans << endl;
  
  return 0;
}


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


int main() {

	int n;
	cin >> n;
	int arr[n];
	for (int i=0; i<n; i++) {
		cin >> arr[i];
	}
	
	bool x = true;
	int f = arr[0];
	
	for (int i=1; i<n; i++) {
		if (arr[i] < f) {
			x = false;
			cout << "No" << endl;
			exit(0);
		}
		if (arr[i] == f) {
			continue;
		}
		f = arr[i] - 1;
	}
	
	cout << "Yes" << endl;
	
}


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

vector<vector<vector<ll>>> memo(1005, vector<vector<ll>>(4, vector<ll>(2, -1)));
string s;
ll dp(int i, int k, bool p){
	if(i >= s.size() && k == 0)
		return 1;
	if(i >= s.size())
		return 0;
	if(k == 0)
		return 1;
	if(memo[i][k][p] != -1)
		return memo[i][k][p];
	memo[i][k][p] = 0;
	memo[i][k][p] += dp(i+1, k, p && s[i] == '0');
	if(p){
		for(int j= 1; j +'0'< s[i]; j++)
			memo[i][k][p] += dp(i+1, k-1, 0);
		if(s[i] != '0')
		memo[i][k][p] += dp(i+1, k-1, 1);
	}else{
		for(int j = 1; j < 10; j++)
			memo[i][k][p] += dp(i+1, k-1, 0);
	}
	
	return memo[i][k][p];
}

signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	cin>>s;
	int k;
	cin>>k;
	cout<<dp(0, k, 1);
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
typedef long long ll;

#define MOD 1000000007

int main(){
    
    vector<int> a(3);
    REP(i,3)cin>>a[i];
    sort(a.begin(),a.end());
    
    if(a[0]==5&&a[1]==5&&a[2]==7)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

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

using namespace std;

deque<long long int> dq;

int main(){
 
    int a,b,c;

    long long int k = 0, p;
    cin>>a>>b;
    c = a;
    while (a--)
    {
        cin>> p ;
        dq.push_back(p);
    }
    sort(dq.begin(),dq.end());
    
        if(b<=c){
            while(b--){
        dq.pop_back();
        }
        }
        else{
            cout<<k<<"\n";
            return 0;
        }
        
    
    if(!dq.empty()){
        for (int i = 0; i < (int) dq.size(); i++)
    {
        k+=dq[i];
    }
    }
    

    cout<<k<<"\n";

    return 0;
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

ll dp[200][2][5];
int main(){
	string s;int K;cin>>s>>K;
	dp[0][0][0]=1;
	rep(i,s.size())rep(j,2)rep(k,K+1){
		int lim=(j?9:s[i]-'0');
		for(int t=0;t<=lim;t++){
			dp[i+1][j||t<lim][k+(t>0)]+=dp[i][j][k];
		}
	}
	ll ans=0;
	rep(i,2){
		ans+=dp[s.size()][i][K];
	}
	cout<<ans<<endl;
}

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

int main() {
	map<char, string> cs;
	string tmp;
	cin >> tmp;
	for (auto t:tmp) cs['a'] += t;
	cin >> tmp;
	for (auto t:tmp) cs['b'] += t;
	cin >> tmp;
	for (auto t:tmp) cs['c'] += t;
	char now = 'a';
	while (true) {
		if (cs[now].size() != 0) {
			char next = cs[now][0];
			cs[now].erase(cs[now].begin());
			now = next;
		} else {
			cout << char(now - 0x20) << endl;
			return 0;
		}
	}
}

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair
#define X				first.first
#define Y				first.second

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

char island[51][51];
int W, H;
int black, white, cnt = 0;
bool b, w;

void dfs( int x, int y ) {
	REP( i, 4 ) {
		int nx = x + dx[i];
		int ny = y + dy[i];

		if( nx >= 0 && nx < W && ny >= 0 && ny < H ) {
			if( island[nx][ny] == 'B' ) b = true;
			if( island[nx][ny] == 'W' ) w = true;

			if( island[nx][ny] == '.' ) {
				island[nx][ny] = '-';
				cnt++;
				dfs( nx, ny );
			}
		}
	}

}


signed main() {
	while( cin >> W >> H, W, H ) {
		REP( i, H ) {
			REP( j, W ) {
				cin >> island[j][i];
			}
		}

		black = 0; white = 0;
		REP( i, H ) {
			REP( j, W ) {
				if( island[j][i] == '.' ) {
					b = false; w = false;
					cnt = 0;
					island[j][i] = '-';

					dfs( j, i );

					if( b & !w ) black += cnt + 1;
					if( !b & w ) white += cnt + 1;
				}
			}
		}
/*
		REP( i, H ) {
			REP( j, W ) {
				cout << island[j][i] << " ";
			}
			cout << endl;
		}
*/
		cout << black << " " << white << endl;
		
	}
}


Measured memory_bytes: 3088
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n, x, y; cin >> n >> x >> y;
  const ll MAX = 2*1000;
  ll ans[MAX + 1] = {};

  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ll tmp;
      if (j <= x || i >= y) tmp = j-i;
      else if (x < i && j < y) {
        tmp = min(j-i, i-x+1+y-j);
      } else if (i <= x && j >= y) tmp = j-i-(y-x)+1;
      else if (i <= x && j > x && j < y) {
        ll v1 = x - i;
        ll v2 = min(j-x, y-j+1);
        tmp = v1+v2;
      } else {
        ll v1 = min(y-i, i-x+1);
        ll v2 = j - y;
        tmp = v1+v2;
      }
      // debug3(i, j, tmp);
      ans[tmp]++;
    }
  }

  for (int i = 1; i < n; i++) outl(ans[i]);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

#define N 100000

int a[N];
int b[N];

int main()
{
	int n, h;
	int ans = 0;

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

	sort( a, a + n );
	int ma = a[n - 1];
	vector<int> v;
	for( int i = 0; i < n; i++ ) {
		if( b[i] > ma ) {
			v.push_back(b[i]);
		}
	}
	sort( v.begin(), v.end(), greater<int>() );
	int sz = v.size();
	for( int i = 0; i < sz; i++ ) {
		h -= v[i];
		ans++;
		if( h <= 0 ) {
			break;
		}
	}
	if( h > 0 ) {
		int r = h / ma;
		if( ( h % ma ) > 0 ) {
			r++;
		}
		ans += r;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Mod(long a, int b)
        {
            return (a % b + b) % b;
        }
        static long Solve(int N, int M, int[] A)
        {
            var dic = new Dictionary<long, int>();
            {
                long sum = 0;
                foreach (int a in A)
                {
                    sum = (sum + a) % M;
                    if (!dic.ContainsKey(sum)) { dic[sum] = 0; }
                    ++dic[sum];
                }
            }
            long ans = 0;
            {
                long sum = 0;
                foreach (int a in A)
                {
                    ans += dic.ContainsKey(sum) ? dic[sum] : 0;
                    sum = (sum + a) % M;
                    --dic[sum];
                }
            }
            return ans;
        }
        static void Main(string[] args)
        {
            int[] V = ReadInts();
            int N = V[0];
            int M = V[1];
            int[] A = ReadInts();
            Console.WriteLine(Solve(N, M, A));
        }
    }
}


Measured memory_bytes: 20704
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main() {
	SPEED;
	int n;
	int h[20];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int counts = 1;
	for (int i = 1; i < n; i++) {
		bool flag = false;
		
		for (int j =0; j < i; j++) {
			if (h[i] >= h[j]) {
				flag = true;
			}
			else {
				flag = false;
				break;
			}
		}
		if (flag) {
			counts++;
		}
	}
	cout << counts;
	ed;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()

count = 0 
for i in range(1000):
        key = str(i)
        if len(key) == 1:
                key = '00' + key 
        elif len(key) == 2:
                key = '0' + key 
        position_first = s.find(key[0]) 
        if position_first != -1 and position_first < n - 2:
                position_first += 1
                position_second = s[position_first:].find(key[1])
                if position_second != -1 and position_second + position_first < n - 1:
                        position_second += 1
                        position_third = s[position_first + position_second:].find(key[2])
                        if position_third != -1: 
                                count += 1
print(count)

Measured memory_bytes: 38384
s = list(map(int,input().split()))
n=s[0]
m=s[1]
h = list(map(int, input().split()))
p={}
for i in range(n+1):
    p[i]=0
for i in range(m):
    s = list(map(int, input().split()))
    if p[s[0]]==0:
        p[s[0]]=1
    if p[s[1]]==0:
        p[s[1]]=1
    if h[s[0]-1]>h[s[1]-1] and p[s[0]]!=3:
        p[s[0]]=2
    else:
        p[s[0]] = 3
    if h[s[0]-1] < h[s[1]-1] and p[s[1]] != 3:
        p[s[1]] = 2
    else:
        p[s[1]] = 3
ans=-1
for i in p:
    if p[i]==0 or p[i]==2:
        ans+=1
print(ans)


Measured memory_bytes: 24572
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long n,m,i,j,f[5005][5005],sum;
int main(){
	scanf("%lld%lld",&n,&m);
	f[0][m]=1;
	for(i=1;i<=n;i++)
		for(sum=0,j=m;j>=1;j--){
			f[i][j]=(sum*j+f[i-1][j]*(j+1))%mo;
			sum=(sum*2+f[i-1][j])%mo;
		}
	for(i=1,sum=0;i<=m;i++)
		sum=(sum+f[n][i])%mo;
	printf("%lld\n",sum);
    return 0;
}

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

struct T {
    int v, e;
    T(){}
    T(int v, int e): v(v), e(e){}
};
vector<T> g[100010];
int K, res[100010];

void dfs(int v, int p, int c)
{
    if (K<c) K=c;
    int k=0;
    for(auto& x: g[v]) if (x.v!=p) {
        if (++k==c) ++k;
        res[x.e]=k;
        dfs(x.v, v, k);
    }
}

int main()
{
    int n; cin>>n;
    for(int i=0; i<n-1; ++i) {
        int a, b; cin>>a>>b;
        --a, --b;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }
    dfs(0, -1, 0);
    cout<<K<<endl;
    for(int i=0; i<n-1; ++i) cout<<res[i]<<'\n';
}


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

#define MOD 1000000007
#define MAX_P 200005
Int fact[MAX_P],inv[MAX_P],finv[MAX_P];;
Int extgcd(Int a,Int b,Int& x,Int& y){
  Int d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}
Int mod_inverse(Int a,Int mod){
  Int x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
}

Int mod_pow(Int x,Int n,Int mod){
  Int res=1;
  while(n){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}

Int mod_inverse2(Int a,Int mod){
  return mod_pow(a,mod-2,mod);
}

void init(Int mod){
  fact[0]=1;
  for(Int i=1;i<MAX_P;i++)
    fact[i]=(fact[i-1]*i)%mod;

  inv[1]=1;
  for(Int i=2;i<MAX_P;i++)
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
  
  finv[0]=1;
  for(Int i=1;i<MAX_P;i++)
    finv[i]=finv[i-1]*inv[i]%mod;
}

Int mod_fact(Int n,Int mod,Int& e){
  e=0;
  if(n==0) return 1;
  Int res=mod_fact(n/mod,mod,e);
  e+=n/mod;
  if(n/mod%2!=0)return res*(mod-fact[n%mod]) %mod;
  return res*fact[n%mod]%mod;
}

Int mod_comb(Int n,Int k,Int mod){
  if(n==k||k==0) return 1;
  Int e1,e2,e3;
  Int a1=mod_fact(n,mod,e1),a2=mod_fact(k,mod,e2),a3=mod_fact(n-k,mod,e3);
  if(e1>e2+e3) return 0;
  return a1*mod_inverse(a2*a3%mod,mod)%mod;
}

Int mod_comb2(Int n,Int k,Int mod){
  Int res=1;
  for(Int i=0;i<k;i++){
    res*=(n-i)%mod;
    res%=mod;
    res*=mod_inverse(i+1,mod);
    res%=mod;
  }
  return res;
}

//only for prime mod
Int mod_comb3(Int n,Int k,Int mod){
  if(k<0||k>n) return 0;
  return fact[n]*finv[k]%mod*finv[n-k]%mod;
}

Int montmort(Int n,Int mod){
  Int res=0,inv=1;
  for(Int k=2;k<=n;k++){
    (inv*=mod_inverse(k,mod))%=mod;
    if(k%2) (res+=mod-inv)%=mod;
    else (res+=inv)%=mod;
  }
  for(Int i=1;i<=n;i++)
    (res*=i)%=mod;
  return res;
}

// calculate P(t) from given points in [0,N]
Int LagrangePolynomial(vector<Int> &y,Int t,const Int mod){
  init(mod);
  Int n=y.size()-1;
  Int num=1;
  for(Int i=0;i<=n;i++)
    num=num*((t-i)%mod)%mod;
  Int res=0;
  for(Int i=0;i<=n;i++){
    Int tmp=(y[i]*num%mod)*mod_inverse((t-i)%mod,mod)%mod;
    tmp=tmp*finv[i]%mod;
    tmp=tmp*finv[n-i]%mod;
    if((n-i)&1) tmp=mod-tmp;
    res=(res+tmp)%mod;
  }
  return res;
}

//INSERT ABOVE HERE
signed main(){
  Int n,k;
  cin>>n>>k;
  cout<<mod_pow(k,n,MOD)<<endl;
  return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <climits>
 
using namespace std;
 
bool can = false;
int max_pos = -1;
string s, t;

bool check(int start_pos) {
	if (s.size() - start_pos < t.size())
		return false;

	for (int i = start_pos; i < start_pos + t.size(); ++i) {
		if (s[i] == t[i - start_pos] || s[i] == '?') 
			continue;
		else
			return false;
	}

	return true;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
 
	cin >> s >> t;

	for (int i = 0; i < (int) s.size(); ++i) {
		if (check(i)) {
			max_pos = i;
			can = true;
		}
	}

	if (!can) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	for (int i = max_pos; i < max_pos + (int) t.size(); ++i) {
		s[i] = t[i - max_pos];
	}

	for (int i = 0; i < (int) s.size(); ++i) {
		if (s[i] == '?')
			s[i] = 'a';
	}

	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
int32_t main()
{
	fast;
	int n, k;
	cin>>n>>k;
	vector<char> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	int c=0;
	char ch=v[0];
	int c1=0;
	int s=0;
	for(int i=0;i<n;i++)
	{
		if(v[i]==ch)
		{
			c++;
		}
		else
		{
			c1++;
			// s+=c;
			ch=v[i];
			c=1;
		}
	}
	// s+=c;
	c1++;
	n-=c1;
	while(k>0 && c1>1)
	{
		if(c1==2)
		{
			n+=1;
		}
		else
		{
			n+=2;
		}
		k--;
		c1-=2;
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 384