akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n;cin>>n;
    set<string> s;
    for (ll i = 0; i < n; i++)
    {
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << endl;
}


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

namespace ALDS1_10_B {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int[] p = new int[n + 1];
            int[][] dp = new int[n][];
            for (int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                p[i] = int.Parse(input[0]);
                p[i + 1] = int.Parse(input[1]);
                dp[i] = Enumerable.Repeat(int.MaxValue, n).ToArray();
                dp[i][i] = 0;
            }

            for (int w = 1; w < n; w++) {
                for (int i = 0, j = i + w; j < n; i++, j++) {
                    for (int k = i; k < j; k++) {
                        int temp = dp[i][k] + dp[k + 1][j] + p[i] * p[k + 1] * p[j + 1];
                        dp[i][j] = Math.Min(dp[i][j], temp);
                    }
                }
            }
            Console.WriteLine(dp[0][n - 1]);
        }
    }
}

Measured memory_bytes: 9700
// ABC 112 D

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

int main() {
  ll n, m;
  cin >> n >> m;

  vector<ll> divisors;
  for (int i = 1; i*i <= m; ++i) {
    if (m % i == 0) {
      divisors.push_back(i);
      if (i != m / i) {
        divisors.push_back(m / i);
      }
    }
  }
  sort(divisors.begin(), divisors.end(), greater<int>());

  ll ans = 1;

  for (auto it = divisors.begin(); it != divisors.end(); it++) {
    if (n * *it > m) {
      continue;
    }
    if ((m % (n* *it)) % *it == 0) {
      ans = *it;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
A=[[i*(i+1)//2,i] for i in range(1,4473)]

point=[]
for i in range(len(A)-1):
    if A[i][0]<=n<=A[i+1][0]:
        point=A[i+1]
        break

num=point[0]-n
for i in range(1,point[1]+1):
    if i==num:continue
    else:print(i)

Measured memory_bytes: 43504
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//示例：#define ll long long
//unsigned long long ;
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	string s, x;
	int ans=0;
	cin >> s >> x;
	for(int i=0; i<s.size(); i++)
		if(s[i]!=x[i])
			ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3864
from collections import deque

def main():
    n = int(input())
    a = list(map(int, input().split()))
    r = deque()
    for ia in range(n):
        if ia % 2 == 1:
            r.appendleft(a[ia])
        else:
            r.append(a[ia])

    if n % 2 == 1:
        r.reverse()
    for i in range(n):
        print(r[i], end = ' ')



if __name__ == '__main__':
    main()


Measured memory_bytes: 25660
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll a,b,c,d,h[500],ans,t;
  t=0;
  cin >> a >> b >> c >> d;
  rep(i,400)h[i]=0;
  ans=0;
  FOR(i,a,b+1)h[i]++;
  FOR(i,c,d+1)h[i]++;
  rep(i,300)if(h[i]==2)ans++;
  printf("%lld",max(t,ans-1));
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    char s, t;
    scanf("%c", &s);
    //cin >> s;
    switch(s){
        case 'A':
            t = 'T'; break;
        case 'T':
            t = 'A'; break;
        case 'C':
            t = 'G'; break;
        case 'G':
            t = 'C'; break;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
#define LL long long
const int MaxN = 1e5 + 7;
LL a[MaxN], b[MaxN];
LL x[MaxN], v[MaxN];

int main()
{
    LL n, c;
    scanf("%lld%lld", &n, &c);
    for(int i = 1; i <= n; i++)
        scanf("%lld%lld", &x[i], &v[i]);
    for(LL i = 1; i <= n; i++)
        a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]); 
    x[n + 1] = c;
    for(LL i = n; i >= 1; i--)
        b[i] = b[i + 1] + v[i] - (x[i+1] - x[i]); 
    for(LL i = 2; i <= n; i++)
        a[i] = max(a[i-1], a[i]);
    for(LL i = n-1; i >= 1; i--)
        b[i] = max(b[i], b[i + 1]);
    LL ans = max(0LL,max(a[n],b[1]));
    for(LL i = 1; i <= n-2; i++) 
        ans = max(ans, a[i] - x[i] + b[i + 1]);
    for(LL i = 2; i <= n; i++)     
        ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);
    printf("%lld\n", ans);
}


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

using namespace std;

vector<vector<int>> e;
vector<int> v;

void dfs(int x, int r = -1, int s = 0) {
  v[x] += s;
  for (auto& a: e[x]) {
    if (a == r) continue;
    dfs(a, x, v[x]);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  v.resize(n, 0);
  e.resize(n);
  
  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    v[a] += b;
  }
  dfs(0);
  for (auto& a: v) {
    cout << a << endl;
  }
}
    

Measured memory_bytes: 23424
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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

    int a,b; cin>>a>>b;
    if(a<=5)cout<<0<<endl;
    else if(a<=12)cout<<b/2<<endl;
    else cout<<b<<endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := scanInt(sc)

	ns := make([]int, 0, n)
	for i := 0; i < n; i++ {
		ns = append(ns, scanInt(sc))
	}

	fmt.Println(find(ns))
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func find(ns []int) int {
	m := map[int]int{}
	for _, n := range ns {
		m[n-1] += 1
		m[n] += 1
		m[n+1] += 1
	}

	max := 0
	for _, cnt := range m {
		if max < cnt {
			max = cnt
		}
	}
	return max
}

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

int main() {
    int K, N;
    cin >> K >> N;
    int A[N];
    rep(i,N){
        cin >> A[i];
    }

    int B[N];
    rep(i,N-1){
        B[i] = A[i+1] - A[i];
    }
    B[N-1] = K - A[N-1] + A[0];

    int X = B[0];

    rep(i,N){
        if(X < B[i]){
            X = B[i];
        }

        else{
        }
    }

    cout << K-X << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
signed main()
{
  vector <int> b;
  int a;
  for(int i=0;i<3;i++){
    cin>>a;
    b.push_back(a);
  }
  sort(b.begin(),b.end());
  for(int i=0;i<3;i++){
    cout<<b[i];
    if(i<2){
      cout<<" ";
    }
  }
  cout<<"\n";
  return(0);
}



Measured memory_bytes: 3160
s = raw_input()
f = 0
for i in range(len(s)):
    if f == 0 and s[i] == 'C':
        f = 1
    if f== 1 and s[i] == 'F':
        f = 2
if f==2 :
    print "Yes"
else:
    print "No"


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

int main(){
    int a,b;
    string str;
    vector<vector<int> >vec;
    vector<int>v;
    for(int i=0;i<2006;i++)
        vec.push_back(v);
    while(getline(cin,str)){
        if(str.empty())break;
        a=0,b=0;
        int i;
        for(i=0;i<str.length();i++){
            if(str[i]==',')break;
            a=a*10+(str[i]-'0');
        }
        for(i=i+1;i<str.length();i++)
            b=b*10+(str[i]-'0');
        vec[a].push_back(b);
    }
    while(cin>>str){
        a=0,b=0;
        int i;
        for(i=0;i<str.length();i++){
            if(str[i]==',')break;
            a=a*10+(str[i]-'0');
        }
        for(i=i+1;i<str.length();i++)
            b=b*10+(str[i]-'0');
        vec[1001+a].push_back(b);
    }
    for(int i=0;i<1001;i++){
        if(vec[i].size()&&vec[i+1001].size()){
            cout<<i<<" "<<vec[i].size()+vec[i+1001].size()<<endl;
        }
    }
}

Measured memory_bytes: 1308
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n;
  cin >> n;
  LL goal = 0;
  vector<LL> a(n);
  for(LL &x:a) cin >> x;
  for(LL x:a) goal ^= x;
  for(LL &x:a) x ^= x-1;
  vector<LL> stones(32);
  for(LL x:a) {
    int tmp = 2;
    REP(i,31) {
      if(x<tmp) {
        ++stones[i];
        break;
      }
      tmp += tmp;
    }
  }
  int answer = 0;
  for(int i=30;i>=0;--i) {
    if(goal >> i) {
      if(stones[i]) {
        goal ^= (1 << (i+1)) -1;
        ++answer;
      }
      else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 1024
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

var hopes [2][2001][2001]int

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	h := getNextInt(scanner)

	blades := make(Blades, n)
	mblade := Blade{}
	mblade.a = 0
	mblade.b = 0
	mblade.i = 0
	for i := 0; i < n; i++ {
		blades[i].a = getNextInt(scanner)
		blades[i].b = getNextInt(scanner)
		blades[i].i = i
		if mblade.a < blades[i].a {
			mblade.a = blades[i].a
			mblade.b = blades[i].b
			mblade.i = i
		}
	}
	sort.Sort(blades)
	sums := make([]int, n)
	si := 0
	for i := 0; i < n; i++ {
		if mblade.i == blades[i].i {
			continue
		}
		if mblade.a > blades[i].b {
			continue
		}
		sums[si+1] += sums[si] + blades[i].b
		si++
	}

	ans := 1 << 30
	sums = sums[0 : si+1]
	th := throw(h-mblade.b, sums)
	if th > si {
		th = si
	}
	a := attack(h-mblade.b-sums[th], mblade) + th
	if ans > a {
		ans = a + 1
	}
	th = throw(h, sums)
	if th > si {
		th = si
	}
	a = attack(h-sums[th], mblade) + th
	if ans > a {
		ans = a
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}

type Blade struct {
	i, a, b int
}

type Blades []Blade

func (a Blades) Len() int           { return len(a) }
func (a Blades) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Blades) Less(i, j int) bool { return a[i].b > a[j].b }

func throw(h int, sums []int) int {
	if h <= 0 {
		return 0
	}
	l := 0
	r := len(sums)
	for l < r {
		m := (l + r) >> 1
		if sums[m] < h {
			l = m + 1
			continue
		}
		r = m
	}
	return l
}

func attack(h int, mblade Blade) int {
	if h <= 0 {
		return 0
	}

	return (h-1)/mblade.a + 1
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, A, B;
	string S;
	cin >> N >> A >> B >> S;
	int x = 0, y = 0;
	for (int i = 0; i < N; ++ i) {
		if (S[i] == 'a') {
			if (x < A+B) {
				cout << "Yes" << endl;
				++ x;
			} else {
				cout << "No" << endl;
			}
		} else if (S[i] == 'b') {
			if (x < A+B && y < B) {
				cout << "Yes" << endl;
				++ x; ++ y;
			} else {
				cout << "No" << endl;
			}
		} else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

	static long mod = 1_000_000_007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), K = in.nextInt();
		int a[] = new int[N + 1];
		for ( int i = 1; i <= N; i++ ) {
			a[i] = in.nextInt();
		}
		in.close();

		long dp[][] = new long[N + 1][K + 1];
		for ( int n = 0; n <= N; n++ ) {
			dp[n][0] = 1;
		}

		for ( int n = 1; n <= N; n++ ) {
			for ( int k = 1; k <= K; k++ ) {
				dp[n][k] = (dp[n][k - 1] + dp[n - 1][k]);
				if ( a[n] < k ) {
					dp[n][k] -= dp[n - 1][k - a[n] - 1];
				}
				dp[n][k] %= mod;
			}
		}
		System.out.println((dp[N][K] + mod) % mod);
	}
}


Measured memory_bytes: 129236
import Control.Monad
import Control.Applicative
import Data.List 
readDigits = map read <$> words <$> getLine :: IO [Int]
main =
    loop
    where
    loop = do
        ns@[x,y] <- readDigits
        unless (x == 0 && y == 0) $ do
            putStrLn . unwords . map show $ sort ns
            loop

Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 998244353
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
ll fac[200009];
ll power(ll x,ll y)
{
    ll res=1;
  
    while(y>0)
    {
        if(y&1)
            res=res*x;
        res%=mod;
        y=y>>1;
        x=x*x;
        x%=mod;
    } 
    return res; 
}
ll inv(ll x)
{
	return power(x,mod-2);
}
ll ncr(ll n,ll r)
{
	ll res=fac[n];
	res*=inv(fac[n-r]);
	res%=mod;
	res*=inv(fac[r]);
	res%=mod;
	return res;
}
void solve()
{
	ll n,m,k;
	cin>>n>>m>>k;
	fac[0]=1;
	for(ll i=1;i<=200000;i++)
	{
		fac[i]=fac[i-1]*i;
		fac[i]%=mod;
	}
	ll ans=power(m-1,n-1);
	ans*=m;
	ans%=mod;
	for(ll i=1;i<=k;i++)
	{
		ll x=power(m-1,n-i-1);
		x*=m;
		x%=mod;
		x*=ncr(n-1,i);
		x%=mod;
		ans+=x;
		ans%=mod;
		ans+=mod;
		ans%=mod;
	}
	cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,l,m,n,o,p,q,r,s,t,x,a[500],tt=0;
    cin>>n>>m;
    s=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    k=0;
    for(i=0;i<n;i++)
    {
        if(a[i]*4*m<s)
        {

        }
        else 
        k++;
    }
    if(k>=m)
    cout<<"Yes\n";
    else 
    cout<<"No\n";
    return 0;
}
    

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<math.h>
using namespace std;

int  main()
{
    int n;
    int a[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    bool f[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            f[i][j] = false;
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (b[i] == a[j][k]) {
                    f[j][k] = true;
                }
            }
        }
    }
    bool ans = false;
    for (int i = 0; i < 3; i++) {
        if (f[i][0] == true && f[i][1] == true && f[i][2] == true) {
            ans = true;
        }
        if (f[0][i] == true && f[1][i] == true && f[2][i] == true) {
            ans = true;
        }
    }
    if (f[0][0] == true && f[1][1] == true && f[2][2] == true) {
        ans = true;
    }
    if (f[0][2] == true && f[1][1] == true && f[2][0] == true) {
        ans = true;
    }
    if (ans == true) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;

const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 5e3 + 10;
const ll INF = 1e18;
const ll LOG = 20;

ll Place[N][N], a[N], n, A, B;/*Place[i][j] = where is the maximum number in first i element and max <= j*/
ll dp[N][N];/*dp[i][j] = int the first i element answer for the numbers who ai <= j*/
ll inv[N][N];


int main(){
	IOS;
	cin >> n >> A >> B;
	for (int i = 1; i<= n; i++){
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++){
		for (int j = i + 1; j <= n; j++){
			inv[i][j] = inv[i][j - 1];
			if (a[i] > a[j]) inv[i][j] ++;
		}
	}
	
	
	
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			Place[i][j] = Place[i - 1][j];
			if (a[i] <= j){
				if (a[i] > a[Place[i - 1][j]]){
					Place[i][j] = i;
				}
				 
			}
			//cout << i << ' ' << j << ' ' << Place[i][j] << '\n';				
		}
	}
	
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			if (Place[i][j] == 0) continue;
			dp[i][j] = min(dp[i][a[Place[i][j]] - 1] + A, dp[Place[i][j] - 1][j] + inv[Place[i][j]][i] * B);
		}
	}
	cout << dp[n][n];
	
	
	
	
	
	return 0;
}






/*
     ,---,           ___                 ,--,
    '  .' \        ,--.'|_             ,--.'|                             ,--,
   /  ;    '.      |  | :,'            |  | :                           ,--.'|    ,---.        ,---,
  :  :       \     :  : ' :            :  : '                 .--.--.   |  |,    '   ,'\   ,-+-. /  |
  :  |   /\   \  .;__,'  /    ,--.--.  |  ' |     ,--.--.    /  /    '  `--'_   /   /   | ,--.'|'   |
  |  :  ' ;.   : |  |   |    /       \ '  | |    /       \  |  :  /`./  ,' ,'| .   ; ,. :|   |  ,"' |
  |  |  ;/  \   \:__,'| :   .--.  .-. ||  | :   .--.  .-. | |  :  ;_    '  | | '   | |: :|   | /  | |
  '  :  | \  \ ,'  '  : |__  \__\/: . .'  : |__  \__\/: . .  \  \    `. |  | : '   | .; :|   | |  | |
  |  |  '  '--'    |  | '.'| ," .--.; ||  | '.'| ," .--.; |   `----.   \'  : |_|   :    ||   | |  |/
  |  :  :          ;  :    ;/  /  ,.  |;  :    ;/  /  ,.  |  /  /`--'  /|  | '.'\   \  / |   | |--'
  |  | ,'          |  ,   /;  :   .'   \  ,   /;  :   .'   \'--'.     / ;  :    ;`----'  |   |/
  `--''             ---`-' |  ,     .-./---`-' |  ,     .-./  `--'---'  |  ,   /         '---'
                            `--`---'            `--`---'                 ---`-'
*/




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

int main(){
	int A, B, i = 0, x = 0;
	cin >> A >> B;
	
	for (;A <= B;A++) {
		bool a = A / 10000 == A % 10;
		bool b = A / 1000 % 10 == (A % 100 - A % 10) / 10;
		if(a && b) {
			i++;
		}
	}
	cout << i << endl;
 }

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a_b_vec: [(i64, i64); m],
    };
    let mut uf = UnionFind::new(n);
    let a_b_vec: Vec<(i64, i64)> = a_b_vec.iter().map(|(a, b)| (a - 1, b - 1)).collect();
    for (a, b) in a_b_vec.iter() {
        uf.unite(*a, *b);
    }
    let loss = uf.loss;
    println!("{}", n - m - 1 + loss);
}

struct UnionFind {
    parent: Vec<i64>,
    loss: usize,
}

impl UnionFind {
    fn new(size: usize) -> Self {
        let parent = vec![-1; size];
        let loss = 0;
        Self { parent, loss }
    }

    fn find(&mut self, x: i64) -> i64 {
        let n = x as usize;
        if self.parent[n as usize] < 0 {
            x
        } else {
            let par = self.parent[x as usize];
            self.parent[n] = self.find(par);
            self.parent[n]
        }
    }

    fn unite(&mut self, x: i64, y: i64) {
        let mut x_par = self.find(x);
        let mut y_par = self.find(y);
        if x_par == y_par {
            self.loss += 1;
            return;
        }
        if self.parent[x_par as usize] > self.parent[y_par as usize] {
            std::mem::swap(&mut x_par, &mut y_par);
        }
        self.parent[x_par as usize] += self.parent[y_par as usize];
        self.parent[y_par as usize] = x_par;
    }
}


Measured memory_bytes: 7056
#include <stdio.h>
#define MAX 1000000

int A[MAX];
int partition(int,int);

int main(){
    int x,n;

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

    x = partition(0,n-1);

    for(int i = 0;i < n;i++){
        if(i == x)printf("[");
        printf("%d",A[i]);
        if(i == x)printf("]");
        if(i < n - 1)printf(" ");
    }
    printf("\n");

    return 0;
}

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

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

    for(int j = p;j < r;j++){
        if(A[j] <= x){
            i = i + 1;
            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: 2244
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <map>
using namespace std;



int main()
{
   int x, y;
   cin >> x >> y;

   int b = y - 2 * x;
   int a = x - b / 2;

   if (a >= 0 && b >= 0 && b % 2 == 0)
   {
      cout << "Yes";
   }
   else
   {
      cout << "No";
   }

   return 0;
}

Measured memory_bytes: 3560
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())
    X = list(map(int, input().split()))

    dist = [0] * (n - 1)
    for i in range(n - 1):
        dist[i] = X[i + 1] - X[i]

    res = 0
    for d in dist:
        if d * a <= b:
            res += d * a
        else:
            res += b

    print(res)


if __name__ == '__main__':
    resolve()


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

int main()
{ 
  string s;
  
  cin>>s;
  
  int couter=0;
  if(s[0]=='1')++couter;
  if(s[1]=='1')++couter;
  if(s[2]=='1')++couter;
  
  cout<<couter<<endl;
}
	


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main(void){
    
    //変数：入力文字を「 inputstr 」、確認文字「 checkStr 」と置く
    string inputstr, checkStr;
    //変数:確認文字が当てはまる個数「 ans 」と置く
    int ans = 0;
    
    //入力：確認文字「 checkStr 」と入力文字を「 inputstr 」を入力する
    cin >> checkStr >> inputstr;;
    //繰返し（大文字に変換）
    for(int i = 0; i < checkStr.length(); i++){
        checkStr[i] = toupper(checkStr[i]);
    }
    
    //繰返し（END_OF_TEXTが有るか無いか）：
    while(inputstr != "END_OF_TEXT"){
        
        //繰返し（大文字に変換）
        for(int i = 0; i < checkStr.length(); i++){
        inputstr[i] = toupper(inputstr[i]);
        }
        
        //条件：確認文字が当てはまるか確認している
        if( inputstr == checkStr) ans++;
        
        //入力：入力文字を「 inputstr 」を再入力する
        cin >> inputstr;
    }
    
    cout << ans << endl;
    
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<62;
constexpr double eps = (1e-9);


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

  int h, w, a, b;
  cin >> h >> w >> a >> b;

  rep(i, b) {
    rep(j, a) cout << 0;
    rep(j, w-a) cout << 1;
    cout << endl;
  }
  rep(i, h-b) {
    rep(j, a) cout << 1;
    rep(j, w-a) cout << 0;
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3648
line = input().split(' ')
C5 = 0
C7 = 0
for i in line:
  if i == '5':
    C5 += 1
  if i == '7':
    C7 += 1
if C5 == 2 and C7 == 1:
  print('YES')
else:
  print('NO')

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

using namespace std;

typedef long long ll;
 
ll n,w,dp[100100],a,b;

int main() {
	
	scanf("%lld %lld", &n, &w);
	
	memset(dp,-1,sizeof(dp));
	dp[0] = 0;
	for(int i = 0; i < n; i++) {
		
		scanf("%lld %lld", &a, &b);
		
		for(int j = 100000;j >= b;j--) {
			if(dp[j - b] != -1) {
				if(dp[j] == -1) dp[j] = dp[j - b] + a;
				else dp[j] = min(dp[j],dp[j - b] + a);
				//printf("%d %d %d\n",i,j,dp[j]);
			}
		}
	}
	for(int i = 100000; i >= 0; i--) {
		//printf("%lld %d\n",dp[i],i);
		if(dp[i] <= w&&dp[i] != -1) {
			printf("%d",i);
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>

using namespace std;

const int mod = 1'000'000'007;

inline void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

inline int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

const int N = 5'009;

vector<int> g[N];
int sz[N];
int w[N];
int f[N][N][2];
int nf[N][2];

void dfs(int x, int pa) {
  f[x][1][0] = 1;
  sz[x] = 1;
  for (int y : g[x]) {
    if (y == pa) {
      continue;
    }
    dfs(y, x);
    for (int i = 0; i <= sz[x] + sz[y]; ++i) {
      for (int j = 0; j <= 1; ++j) {
        nf[i][j] = 0;
      }
    }
    for (int i = 0; i <= sz[x]; ++i) {
      for (int si = 0; si <= 1; ++si) {
        for (int j = 0; j <= sz[y]; ++j) {
          for (int sj = 0; sj <= 1; ++sj) {
            add(nf[i + j][si ^ sj], mul(f[x][i][si], f[y][j][sj]));
            add(nf[i][si ^ sj ^ 1], mul(f[x][i][si], mul(f[y][j][sj], w[j])));
          }
        }
      }
    }
    for (int i = 0; i <= sz[x] + sz[y]; ++i) {
      for (int j = 0; j <= 1; ++j) {
        f[x][i][j] = nf[i][j];
      }
    }
    sz[x] += sz[y];
  }
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    --x;
    --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  memset(w, 0, sizeof w);
  for (int i = 2; i <= n; i += 2) {
    w[i] = 1;
    for (int j = 0; i - 2 * j - 1 > 0; ++j) {
      w[i] = mul(w[i], i - 2 * j - 1);
    }
  }
  memset(f, 0, sizeof f);
  dfs(0, -1);
  int ans = w[n];
  for (int i = 1; i < n; ++i) {
    add(ans, mul(f[0][i][0], w[i]));
    add(ans, mod - mul(f[0][i][1], w[i]));
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 197248
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    left = 1
    right = N
    for i in range(M):
        if left < L[i]:
            left = L[i]
        if right > R[i]:
            right = R[i]
    if right < left:
        print(0)
        return
    print(right - left + 1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 10868
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int a; cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] =='?')
      s[i] = 'D';
  }
  cout << s << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

constexpr int INF = 2000000000;
constexpr ll LLINF = 9000000000000000000;

int compute(int x, int y, int R, int C) {
	if (y == 0) return x;
	if (x == R) return R + y;
	if (y == C) return R + C + (R - x);
	return R + C + R + (C - y);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int R, C, N;
	cin >> R >> C >> N;
	
	vii lines;
	while (N--) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		if (x1 != 0 && x1 != R && y1 != 0 && y1 != C) continue;
		if (x2 != 0 && x2 != R && y2 != 0 && y2 != C) continue;
		
		int i1 = compute(x1, y1, R, C), i2 = compute(x2, y2, R, C);
		if (i1 > i2) swap(i1, i2);
		lines.push_back({ll(i1), ll(i2)});
	}
	
	sort(lines.begin(), lines.end());
	
	stack<ll> end;
	bool pos = true;
	for (ii line : lines) {
		ll s = line.first, e = line.second;
		while (!end.empty() && end.top() < s) end.pop();
		if (!end.empty() && end.top() < e)
			pos = false;
		end.push(e);
	}
	
	cout << (pos ? "YES" : "NO") << endl;
	
	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int isp[1000000];
bool p(int n){
    if(isp[n]!=-1) return isp[n];
    int &res=isp[n];
    res=true;
    for(int i=7; i<=n; i+=7){
        if(i+1<n && n%(i+1)==0){
            res=false; break;
        }
        if(n%(i-1)==0){
            res=false; break;
        }
    }
    return res;
}

int main(){
    rep(i,1000000) isp[i]=-1;
    int n;
    while(cin>>n && n!=1){
        vector<int> ans;

        for(int i=7;;i+=7){
            for(int j:{-1,1}){
                int x=i+j;
                if(x>n) goto end;
                if(n%x==0 && p(x)){
                    ans.push_back(x);
                }
            }
        }
    end:;
        cout << n << ":";
        for(int i=0; i<ans.size(); i++){
            cout << " " << ans[i];
        }
        cout << endl;
    }
}

Measured memory_bytes: 5116
n = int(input())
a = {}
for i in range(n):
    a[i] = int(input())
cnt = 1
ans = 0
while True:
    if a[cnt-1] == 2:
        ans += 1
        print(ans)
        break
    cnt = a[cnt-1]
    ans += 1
    if ans > n:
        print('-1')
        break

Measured memory_bytes: 17892
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

struct Dice{
private:
	static const int _roll[4][6], _turn[2][6];
public:
	vector<int> value;
	// 1-6 : top, near, right, left, far, bottom 

	Dice(){
		value.resize(6);
		for (int i = 0; i < 6; ++i) value[i] = i;
	}

	void roll(int dir){ // N, E, W, S
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_roll[dir][i]];
		}
		value = nxt;
	}

	void turn(int dir){ // L, R
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_turn[dir][i]];
		}
		value = nxt;
	}

	int &operator[](int i){
		return value[i];
	}
};

const int Dice::_roll[4][6] = {
	{ 1, 5, 2, 3, 0, 4 }, // North
	{ 3, 1, 0, 5, 4, 2 }, // East
	{ 2, 1, 5, 0, 4, 3 }, // West
	{ 4, 0, 2, 3, 5, 1 }, // South
};

const int Dice::_turn[2][6] = {
	{ 0, 3, 1, 4, 2, 5 }, // Left
	{ 0, 2, 4, 1, 3, 5 }, // Right
};


int main(){	
	map<char, int> m;
	for (int i = 0; i < 6; ++i) m["NEWSLR"[i]] = i;

	int n;
	while (cin >> n, n){
		Dice d;
		int ans = 1;
		while (n--){
			string s;
			cin >> s;
			int x = m[s[0]];
			x < 4 ? d.roll(x) : d.turn(x - 4);
			ans += d[0]+1;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n[N], m[N];
int main()
{
	int i, j, num = 0, find[N];
	n[1] = 1;
	for (i = 2; i <= 100000; i++)
	{
		for (j = 2 * i; j <= 100000; j += i)
			n[j] = 1;
	}
	n[2] = 0;
	for (i = 1; i <= 100000; i++)
	{
		if (n[i] == 0 && n[(i + 1) / 2] == 0)
			m[i] = m[i - 1] + 1;
		else
			m[i] = m[i - 1];
	}
	int a, b, c;
	cin >> a;
	for (i = 1; i <= a; i++)
	{
		cin >> b >> c;
		find[i] = m[c] - m[b-1];
	}
	for (i = 1; i <= a; i++)
		cout << find[i] << endl;
	return 0;
}




Measured memory_bytes: 1792
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
main(){
	int n,i,start,M;
	double x,y,dX,dY,dx,dy,dot,n1,n2,co,m;
	for(;scanf("%d",&n),n;){
		vector<pair<pair<double,double>,int> >v;
		for(i=0;i<n;i++)scanf("%lf,%lf",&x,&y),v.push_back(make_pair(make_pair(x,y),i));
		pair<pair<double,double>,int>p=*min_element(v.begin(),v.end());
		dX=0,dY=-1;
		start=p.second;
		vector<int>V;
		for(M=-1;M!=start;){
			m=-1,n1=hypot(dX,dY);
			for(i=0;i<n;i++){
				if(i==p.second)continue;
				dx=v[i].first.first-p.first.first,dy=v[i].first.second-p.first.second;
				dot=dX*dx+dY*dy;
				n2=hypot(dx,dy),co=dot/n1/n2;
				if(m<co)m=co,M=i;
			}
			V.push_back(M);
			dX=v[M].first.first-p.first.first,dY=v[M].first.second-p.first.second;
			p=v[M];
		}
		printf("%d\n",n-V.size());
	}
}

Measured memory_bytes: 1112
#include<iostream>
#include<string.h>
using namespace std;
typedef long long ll;
int main(){
	int i,sum=0,t=0;
	string a;
	cin>>a;
	for(i=0;a[i]!='\0';i++){
		if(a[i]=='R'){
			if(a[i]==a[i+1]) t++;
			else{
				sum=max(sum,t+1);
				t=0;
			}
		}
	}
	cout<<sum;
}

Measured memory_bytes: 3196
#include <iostream>
using namespace std;
int main (void){
    int n;
    int ans;
    cin >> n;
    ans = 1;
    while(1){
        ans = ans*2;
        if(ans > n){
            ans = ans/2;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define N 10005

int n, m;
int fa[N];
int ans(0);

int find(int u)
{
	return fa[u] == u ? u : fa[u] = find(fa[u]);
}

struct edge
{
	int x, y, w;
	edge(void) {};
	edge(int a, int b, int c) :
		x(a), y(b), w(c) {};
	friend bool operator < (const edge &a, const edge &b)
	{
		return a.w > b.w;
	}
};

priority_queue<edge> pq;

signed main(void)
{
	cin >> n >> m;
	for (int x, y, w; m--; )
	{
		cin >> x >> y >> w;
		pq.push(edge(x, y, w));
	}
	for (int i = 0; i < n; ++i)
		fa[i] = i;
	while (!pq.empty())
	{
		edge t = pq.top(); pq.pop();
		if (find(t.x) != find(t.y))ans += t.w,
			fa[find(t.x)] = find(t.y);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define MP(a,b) make_pair(a,b)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    multiset<int> D;
    cin >> N;
    REP(i, N){
        int x;
        cin >> x;
        D.insert(x);
    }
    cin >> M;
    REP(i, M){
        int x;
        cin >> x;
        auto itr = D.find(x);
        if(itr == D.end()){
            puts("NO");
            return 0;
        }else{
            D.erase(itr);
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;


int main(void)
{
	int N, M; cin >> N >> M;
	vector<string> A(N), B(M);
	rep(i, 0, N)cin >> A[i];
	rep(i, 0, M)cin >> B[i];

	bool judge = false; 
	rep(i, 0, N - M + 1) {
		rep(j, 0, N - M + 1) {
			bool flag = true;
			rep(k, 0, M) {
				if (A[i + k].substr(j, M) != B[k]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				judge = true;
				break;
			}
		}
	}

	if (judge)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("in","r",stdin);
  freopen("out","w",stdout);
  #endif
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){cin>>a[i];a[i]-=i+1;}
    int ans=0;
  sort(a.begin(),a.end());
  int md;
  if(n&1){md=2*a[n/2];}
  else md=a[n/2]+a[n/2 -1];

  //cout<<md<<"\n";
  for(auto i:a)
  {
    //cout<<i<<" ";
    ans+=abs(i*2 - md);
  }
  cout<<ans/2;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
//#define INF (1LL<<31)-1
//#define MOD 998244353
#define MOD 1000000007

int main(){
    ll t,x=100;
    scanf("%lld",&t);
    ll ans=1;
    while(1){
        x+=x/100;
        if(x>=t)break;
        ans++;
    }
    printf("%lld",ans);
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
long long dp[103][4][2], mod = 1e9 + 7;
int k, n;
string s;
long long solve(int pos, int occ, bool flag){
    if(occ > k){
        return 0;
    }
    if(dp[pos][occ][flag] != -1){
        return dp[pos][occ][flag];
    }
    if(pos == n){
        if(occ == k){
            dp[pos][occ][flag] = 1;
        }
        else{
            dp[pos][occ][flag] = 0;
        }
        return dp[pos][occ][flag];
    }
    dp[pos][occ][flag] = 0;
    int lim;
    if(flag == 0){
        lim = s[pos] - '0';
    }
    else{
        lim = 9;
    }
    for(int i = 0; i <= lim; i++){
        int nocc = occ + (i != 0);
        int nflag = (flag == 1 || i < lim);
        dp[pos][occ][flag] = (dp[pos][occ][flag] + solve(pos + 1, nocc, nflag)) % mod;
    }
    return dp[pos][occ][flag];
}
int main(){
    cin >> s >> k;
    n = s.size();
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 0, 0);
    return 0;
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
from collections import deque

h, w, k = map(int, input().split())
A = [input().rstrip() for _ in range(h)]
for i, a in enumerate(A):
  if "S" in a:
    sy = i
    sx = a.index("S")
    break

que = deque()
D = ((-1, 0), (0, -1), (1, 0), (0, 1))
        
def bfs(y, x):
  seen = [0]*h
  seen[y] |= 1 << x
  F = deque()
  F.append((y, x, 0))
  while F:
    ny, nx, cnt = F.popleft()
    que.append((ny, nx, k))
    if cnt == k:
      continue
    for dy, dx in D:
      yy, xx = ny+dy, nx+dx
      if 0 <= yy < h and 0 <= xx < w:
        if A[yy][xx] == "#":
          continue
        if seen[yy] >> xx & 1:
          continue
        seen[yy] |= 1 << xx
        F.append((yy, xx, cnt+1))

bfs(sy, sx)

seen = [0]*h
while que:
  y, x, cnt = que.popleft()
  if y == 0 or y == h-1 or x == 0 or x == w-1:
    ans = -(-cnt // k)
    break
  for dy, dx in D:
    ny, nx = y+dy, x+dx
    if 0 <= ny < h and 0 <= nx < w:
      if seen[ny] >> nx & 1:
        continue
      seen[ny] |= 1 << nx
      que.append((ny, nx, cnt+1))

print(ans)

Measured memory_bytes: 83076
def main():
    N = int(input())
    A = list(map(int, input().split()))
    maxA = max(A)
    # エラトステネスの篩
    sieve = [0] * (maxA + 1)
    sieve[0] = sieve[1] = -1
    for i in range(maxA+1):
        if sieve[i] != 0:
            continue
        for j in range(i, maxA+1, i):
            if sieve[j] == 0:
                sieve[j] = i

    # 素因数分解
    primelist = []
    lenprimelist = 0
    for i in range(N):
        tmpset = set()
        j = A[i]
        for _ in range(N):
            tmp = sieve[j]
            if tmp <= 0:
                break
            tmpset.add(tmp)
            j = j//tmp
        lenprimelist += len(tmpset)
        primelist.append(tmpset)
    
    # 素因数の和集合を取ったときに, 元の素因数の配列の長さから小さくなっている 
    #   => ある i, j で共通する素因数を持つAi, Ajが存在する
    #   => pairwise coprime ではない
    # 全ての素因数の配列に対して共通部分を取ったときに, 空集合となる
    #   => A全体での公約数は 1 
    #   => setwise coprime である

    primeset = set()
    primeintersection = set(range(2, maxA+1))
    for s in primelist:
        primeset.update(s)
        primeintersection.intersection_update(s)
    if len(primeset) == lenprimelist:
        print('pairwise coprime')
        return
    if len(primeintersection) == 0:
        print('setwise coprime')
        return
    print('not coprime')
    return

if __name__ == "__main__":
    main()



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


#define ll long long int
#define ld long double
#define mod 1000000007
#define big 1e18+10
#define small -big
#define pb push_back
#define endl "\n"


template <typename T>

void prarr(T a)
{
     cerr << "[ ";
     
     for(auto i : a){
         cerr << i << " ";
     }
     
     cerr << "]" << endl;
}


#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){
    
	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}





void solve() {
        
      ll K;
      cin >> K;
      
      
      if(K % 2 == 0 || K % 5 == 0) {
            cout << -1 << endl;
            return;
      }
      
      ll c = 0;
      ll ans = 0;
      
      while(true) {
            c = (c * 10) % K;
            c = (c + 7) % K;
            ans++;
            if(c == 0) {
                cout << ans << endl;
                return;
            }
      }
      
     
        
}


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

    int t = 1;
    //cin >> t;

    for(int i = 1; i <= t; i++) {  
   
         solve();
    }


    return 0;
        
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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

struct guide{
    string city;
    int point;
    
    guide(string s, int p){
        city = s;
        point = p;
    }
    bool operator<(const guide &another) const
    {
        return city==another.city ? point<another.point : city>another.city;
    };
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<guide> v,v1;

    REP(i,n){
        string s;
        int p;
        cin>>s>>p;
        v.push_back(guide{s,p});
        v1.push_back(guide{s,p});
    }
    VRSORT(v);

    for(auto x:v){
        int i=1;
        for(auto y:v1){
            if(x.city==y.city&&x.point==y.point){
                cout<<i<<endl;
                break;
            }
            i++;
        }
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m,s,t1,t2;
	while(cin>>n>>m>>s>>t1>>t2,n){
		s--;t1--;t2--;
		vvi G(n,vi(n,inf));
		rep(i,n)G[i][i]=0;
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			a--;b--;
			G[a][b]=c;
		}
		rep(k,n)rep(i,n)rep(j,n)
			G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
		int out=inf;
		rep(i,n)out=min(out,G[s][i]+G[i][t1]+G[i][t2]);
		cout<<out<<endl;
	}
}
 
 

Measured memory_bytes: 1260