akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
li = list(map(int,input().split()))

import collections
#l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
##c = collections.Counter(l)
#print(c)
# Counter({'a': 4, 'c': 2, 'b': 1})

c = collections.Counter(li)
#ll = list(c.items())
#print(ll)
#k = list(c.keys())
v = list(c.values())
#print(k,v)
v.sort()
#print(v) [1, 2, 2]

lenv = len(v)
#print(lenv)
if lenv <= k:
    print(0)
else:
    count = 0
    all_sum = 0
    for vv in v:
        count += 1
        all_sum += vv
        if lenv - count <= k:
            print(all_sum)
            break

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

int main(){
    int n;
    cin >> n;
    unsigned long long ans = 1, mod = 1000000007;
    for(int i = 1; i <= n; i++){
        ans = (ans * i) % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL)

int main(){
  FastIO;
  int a;
  cin >> a;
  int ans = a + (a * a) + (a * a * a);
  cout << ans << "\n";
  return 0;
}

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

int main()
{
  int n, x, ans;
  x = ans = 0;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == 'I')
    {
      x++;
    }
    else if (s[i] == 'D')
    {
      x--;
    }
    ans = max(ans, x);
  }
  cout << ans << endl;
}


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

int main(){
	int n;
	cin >> n;
    vector<int> l(n);
    for(int i=0; i<n; i++) cin >> l[i];
    
    sort(l.begin(),l.end());
    int ans=0;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            int tmp=lower_bound(l.begin()+j+1,l.end(),l[i]+l[j])-l.begin(); 
            ans += tmp-j-1;
        }
    }

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		for (int i = 0;i < a;i++) {
			printf("%d", b);
		}
	}
	else {
		for (int i = 0;i < b;i++) {
			printf("%d", a);
		}
	}

	return 0;
}

//AAAAAAAAAAAAAAAAA
//int main() {
//	int n, m;
//	cin >> n >> m;
//
//	if (n == m) {
//		cout << "Yes" << endl;
//	}
//	else {
//		cout << "No" << endl;
//	}
//	
//	return 0;
//}

Measured memory_bytes: 3552
import math
a,b,c = map(float,input().split())
H = b * math.sin(math.radians(c))
S = (a*(b*math.sin(math.radians(c))))/2
L = a + b + ((a**2) + (b**2) -(((2*a)*b)*math.cos(math.radians(c))))**0.5 
print(float(S))
print(float(L))
print(float(H))



Measured memory_bytes: 5696
#include <iostream>
#include <vector>
#include <cstring>
#include <cctype>
#include <string>
using namespace std;

int main(){
	string st;
	getline(cin, st);
	for (auto pst = st.begin(); pst != st.end(); ++pst){
		if (islower(*pst)){
			cout << static_cast<char>(toupper(*pst));
		}
		else if(isupper(*pst)){
			cout << static_cast<char>(tolower(*pst));
		}
		else{
			cout << *pst;
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1180
open System

let n, m =
    let l = Console.ReadLine().Split(' ') |> Array.map int
    l.[0], l.[1]

let ans =
    let acProb =
        [1 .. m]
        |> List.fold (fun acc _ -> acc * 0.5) 1.
    let tleProb =
        1. - acProb

    let n = n |> float
    let m = m |> float
    let submitCost =
        100. * (n - m) + 1900. * m

    let expectation k prob = submitCost * k * prob

    [   let mutable k = 1.
        let mutable prob = acProb
        yield (expectation k prob)

        while (expectation k prob) > 0.01 do
            k <- k + 1.
            prob <- tleProb * prob
            yield (expectation k prob)]
    |> List.sum
    |> Math.Ceiling
    |> int

ans |> Console.WriteLine


Measured memory_bytes: 13524
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vvi = vector<vector<int>> ;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI 3.141592653
#define rep(i, n) for(ll i = 0; i < n; i++)



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

  vvi v(n, vi(m+1));
  rep(i, n){
    rep(j, m+1){
      cin >> v[i][j];
    }
  }

  int ans = 100000000;
  for(int bit = 0; bit < (1<<n); bit++){
    vi res(m+1, 0);
    rep(i, n){
      if(bit & (1<<i)){
        rep(j, m+1){res[j] += v[i][j];}
      }
    }
    bool f = true;
    rep(i, m+1){
      if(i > 0){
        if(res[i] < x){f = false; break;}
      }
    }

    if(f){if(res[0] < ans){ans = res[0];}}
  }

  if(ans == 100000000){cout << -1 << endl; }
  else{cout << ans << endl;}
}

Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scanner = new Scanner(System.in);

		//入力表示
		String S = scanner.next();
		int count =0;
		
		char a[]=S.toCharArray();
		
		for(int i = 0; i < S.length(); i++){
			if(a[i] != a[S.length() - 1 - i]) {
				count++;
			}
		}
		System.out.println(count/2);

		scanner.close();
	}
}


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

#define read(a) cin >> a
#define out(a)  cout << a
#define ull unsigned long long
#define ll long long
#define FOR(i, l, r) for (ll i = l; i <= r; i++)
#define FOD(i, l, r) for (ll i = l; i >= r; i--)
#define fast ios_base::sync_with_stdio(false);

int main()
{
    ll d;
    ll n, a, b, dem = 0;
    cin >> n >> d;
    while(n--)
    {
        ll t = 0, t1 = 0;
        double t2;
        cin >> a >> b;
        t = pow(a, 2);
        t1 = pow(b, 2);
        t2 = sqrt(t + t1);
        if (t2 <= d) dem++;
    }
    cout << dem;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int n;

void dfs(string s = "", char mx = 'a') {
  if (s.size() == n) { COUT(s); return; }

  int p = mx-'a';
  REP(i,p+1) {
    string ns = s + (char)('a' + i);
    char nmx = (char)('a' + p+(i==p));
    dfs(ns, nmx);
  }
}

int main() {
  IOS;
  cin >> n;
  dfs();
  return 0;
}

Measured memory_bytes: 3664
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    if(n%2==0)cout << n/2 ENDL;
    else cout << (n/2)+1 ENDL;
    
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(auto & a  :v) cin>>a;
    sort(v.begin(),v.end());
    int mid = n/2;
    if(v[mid-1] != v[mid])cout << v[mid] - v[mid-1] << endl;
    else cout << 0 << endl;
    return 0;
}



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

int n, a[100], ta = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ta += a[i];
	}
	if (ta % 2 == 0) {
		cout << ta / 2 << endl;
	}
	else {
		sort(a, a + n);
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 == 1) {
				ta -= a[i];
				cout << ta / 2 << endl;
				break;
			}
		}
	}
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int N, Q; string S;
    cin >> N >> S >> Q;
    
    vector<set<int>> vsi(26);
    for (int i = 0; i < S.size(); ++i) {
        int pos = S[i] - 'a';
        vsi[pos].insert(i);
    }
    
    for (int i = 0; i < Q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            int idx; char ch; cin >> idx >> ch;
            idx--;
            char prev = S[idx];
            vsi[prev - 'a'].erase(idx);
            S[idx] = ch;
            vsi[ch - 'a'].insert(idx);
        } else {
            int l, r; cin >> l >> r; int ans = 0;
            l--; r--;
            for (int c = 0; c < 26; ++c) {
                auto it = vsi[c].lower_bound(l);
                if (it != vsi[c].end() && *it <= r) ans++;
            }
            cout << ans << "\n";
        }
    }
}


Measured memory_bytes: 24220
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


X, Y = list(map(int, input().split()))

if (X + Y) % 3 == 0:
    if X <= 2*Y and 2*X >= Y:
        n = (X+Y) // 3
        r = n // 2 - abs(X-Y) // 2
        print(cmb(n, r, p))

    else:
        print(0)
else:
    print(0)


Measured memory_bytes: 122068
#include <iostream>
using namespace std;
int main()
{

	int num[30], n;

	for (int i = 0; i < 30; i++) num[i] = 0;

	for (int i = 0; i < 28; i++){
		cin >> n;
		num[n - 1] = 1;
	}
	for (int i = 0; i < 30; i++){
		if (num[i] == 0)
			cout << i + 1 << endl;
	}

}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    int A, B;
    cin >> A >> B;
    cout << (A + B) % 24 << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 998244353;

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 main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    ll n, s;
    cin >> n >> s;
    ll a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    VI v(3030, 0);
    v[0] = 0;
    for (i = n - 1; i >= 0; i--) {
        v[0]++;
        for (j = 3029; j >= a[i]; j--) {
            v[j] += v[j - a[i]];
            v[j] %= mod;
        }
        ans += v[s];
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3704
import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();

        long[] A = new long[N];
        long[] B = new long[M];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i = 0; i < M; i++) {
            B[i] =  sc.nextInt();
        }


        long sum=0;
        int bidx = -1;
        int count=0;
        for (int i = 0; i < M ; i++) {
            if(sum+B[i] <=K){
                sum += B[i];
                bidx =i;
                count++;
            }else{
                break;
            }
        }


        int ans = count;//A zero books

        for (int i = 0; i < N; i++) {
            long bookA = A[i];
            sum += bookA;
            count++;
            while(sum>K && bidx>=0){//remvoe books in B
                sum -= B[bidx];
                count--;
                bidx--;
            }
            if(sum>K){
                break;
            }
            ans = Math.max(ans,count);
        }

        System.out.println(ans);
    }
}

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

const int N = 505;
const int C = 35;
const int INF = (int) 2e9 + 9;

int n, c;
int d[C][C], dp[3][C];

void minimize(int &a, int b) {
	if (a > b) a = b;
}

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	cin >> n >> c;
	for (int i = 1; i <= c; i++)
		for (int j = 1; j <= c; j++) cin >> d[i][j];
	int ans = INF;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) {
			int color; cin >> color;
			dp[(i + j) % 3][color]++;
		}
	for (int i = 1; i <= c; i++)
		for (int j = 1; j <= c; j++) {
			if (i == j) continue;
			for (int k = 1; k <= c; k++) {
				if (k == i || k == j) continue;
				int temp = 0;
				for (int z = 1; z <= c; z++) temp += dp[0][z] * d[z][i];
				for (int z = 1; z <= c; z++) temp += dp[1][z] * d[z][j];
				for (int z = 1; z <= c; z++) temp += dp[2][z] * d[z][k];
				minimize(ans, temp);
			}
		}
	cout << ans;
	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 REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64

int main(){
    int n;
    cin >>n;
    set<int> st;
    llong ma1=0,ma2=0;
    llong tmp;
    REP(i,n){
        scanf("%ld",&tmp);
        if(st.erase(tmp) == 0) st.insert(tmp);
        else{
            if(ma1 < tmp ){
                ma2=ma1;
                ma1=tmp;
            }
            else if(ma2 < tmp) ma2=tmp;
        }
    }
    llong ans;
    ans=ma1*ma2;
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
viii edj;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z,k,l;
    cin>>l;
    for(int i=0;i<21;i++){
        if((l>>i)&&1){
            x = (1ll<<i);
            n = i+1;
        }
    }
    for(int i=0;i<n-1;i++){
        edj.pb(mc(i+1,i+2,0));
        edj.pb(mc(i+1,i+2,1ll<<i));
    }

    l-=x;

    for(int i=21;i>=0;i--){
        if((l>>i)&&1){
            edj.pb(mc(i+1,n,x));
            x+=(1ll<<i);
            l-=(1ll<<i);
        }
    }

    cout<<n<<" "<<edj.size()<<endl;
    for(auto it:edj){
        cout<<it.F.F<<" "<<it.F.S<<" "<<it.S<<endl;
    }
    
    



    return 0;
}

Measured memory_bytes: 3640
n = int(input())
a = list(map(int , input().strip().split()))
total = 0

if len(a) % 2 != 0:
  a.append(0)
  
a.sort()

for i in range(int(len(a) / 2)):
  total += a[2 * i] - a[2 * i + 1]

print(total * (-1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
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);
  int a, b;
  cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;
  return 0;
}

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

#define N 8
#define ON 1
#define OFF 0
#define TRUE 1
#define FALSE -1

int Search(int);
void Print();
int X[N],Y[N],Z[N][N],L[2*N-1],R[2*N-1];

int main(){
  int i,j,k,m,c;
  for(i=0;i<N;i++){
    X[i]=OFF;
    Y[i]=OFF;
  }
  for(i=0;i<2*N-1;i++){
    L[i]=OFF;
    R[i]=OFF;
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      Z[i][j]=FALSE;
    }
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&m,&c);
    Z[m][c]=TRUE;
  }
  Search(0);
  return 0;
}

int Search(int p){
  int q;
  if(p==N){
    Print();
    return 0;
  }
  for(q=0;q<N;q++){
    if(Y[q]==ON || L[p+q]==ON || R[p-q+N-1]==ON){
      continue;
    }
    X[p]=q;
    Y[q]=ON;
    L[p+q]=ON;
    R[p-q+N-1]=ON;
    Search(p+1);
    X[p]=OFF;
    Y[q]=OFF;
    L[p+q]=OFF;
    R[p-q+N-1]=OFF;
  }
  return 0;
}

void Print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(Z[i][j]==TRUE){
        if(X[i]!=j){
          return;
        }
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i]==j){
        printf("Q");
      }
      else{
        printf(".");
      }
    }
    printf("\n");
  }
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
int main(){
    int n;
    scanf("%d",&n);
    string s[55];
    int t[55];
    for(int i = 0;i<n;i++){
        cin>>s[i]>>t[i];
    }
    string tar;
    cin>>tar;
    int ans=0;
    int add=0;
    for(int i =0;i<n;i++){
        if(add)ans+=t[i];//,printf("%d ",t[i]);
        if(s[i]==tar)add=1;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int D, G;

string conv(int _num) {
	string s = "0000000000";
	REP(i, D) {
		if (_num % 2 == 1) {
			s[i] = '1';
		}
		_num /= 2;
	}
	return s;
}

int main() {
	cin >> D >> G;
	int p[10], c[10];
	REP(i, D) {
		cin >> p[i] >> c[i];
	}

	int sum[10];
	REP(i, D) {
		sum[i] = (i + 1) * 100 * p[i] + c[i];
	}

	int ans = mod;
	REP(num, pow(2, D)) {
		string bits = conv(num);

		int total = 0, prob_num = 0;
		int zero_max_ix = -1;

		REP(ix, D) {
			// 全部解く
			if (bits[ix] == '1') {
				total += sum[ix];
				prob_num += p[ix];
			}
			// 全部解かない
			if (bits[ix] == '0') zero_max_ix = ix;
		}
		// 中途半端に解く
		if (total < G && zero_max_ix != -1) {
			int rest = G - total;
			int prob_num_ix;
			if (rest % ((zero_max_ix + 1) * 100) == 0) {
				prob_num_ix = rest / ((zero_max_ix + 1) * 100);
			}
			else {
				prob_num_ix = rest / ((zero_max_ix + 1) * 100) + 1;
			}

			if (prob_num_ix < p[zero_max_ix]) {
				total += prob_num_ix * 100*(zero_max_ix+1);
				prob_num += prob_num_ix;
			}
		}
		if (total >= G) {
			ans = min(ans, prob_num);
		}
	}
  	if (ans>1000) ans = -1;
	cout << ans;
	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
    int n;
    int ans = 0;
    std::cin >> n;

    for (int i = 0; i < 50000; i++) {
        if (static_cast<int>(static_cast<double>(i) * 1.08) == n) {
            ans = i;
        }
    }

    if (ans != 0) {
        std::cout << ans << std::endl;
    } else {
        std::cout << ":(" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,sum;

 cin>>N;
 
 for(int i=1; i<=9; i++)for(int j=1; j<=9; j++){
   sum=i*j;

   if(N== sum){
     cout<<"Yes"<<endl;
     return 0;
   }
 }
 cout<<"No"<< endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long x, y; cin >> x >> y;
	long res = INT_MAX;
    
	if (x <= y) res = min(res, y - x);
	x *= -1;
	if (x <= y) res = min(res, y - x + 1);
	y *= -1;
	if (x <= y) res = min(res, y - x + 2);
	x *= -1;
	if (x <= y) res = min(res, y - x + 1);

	cout << res << endl;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> copy(n);
  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
    copy[i] = p[i];
  }
  sort(copy.begin(), copy.end());
  int ng = 0;
  for (int i = 0; i < n; i++)
  {
    if (ng > 2)
    {
      cout << "NO" << endl;
      return 0;
    }

    if (p[i] != copy[i])
    {
      ng++;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 3632
program ordinary_number
    implicit none
    integer(4):: n, i, count=0
    integer(4),allocatable:: p(:)

    read*, n
    allocate(p(n))
    read*, p(:)

    do i=1, n-2
        if (is_ordinary(p(i:i+2))) count=count+1
    end do

    print*, count

contains
logical function is_ordinary(ar)
    integer(4):: ar(3)

    if (ar(2) < max(ar(1),ar(3)) .and. ar(2) > min(ar(1),ar(3))) then
        is_ordinary = .true.
    else
        is_ordinary = .false.
    end if
end function
end program ordinary_number

Measured memory_bytes: 384
n = int(input())
pl = list(map(int, input().split()))

num_l = []
for i in range(n-2):
    if pl[i] < pl[i+1] < pl[i+2] or pl[i] > pl[i+1] > pl[i+2]:
        num_l.append(pl[i+1])

print(len(set(num_l)))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t;
    cin>>n>>x>>t;
    if(n%x==0)
    {
        cout<<(n/x)*t;
    }
    else
    {
        cout<<(n/x)*t+t;
    }
    
    
    
    return 0;
}

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

int main() {
    double pi = M_PI;
    double a, b, C;
    scanf("%lf %lf %lf",&a, &b, &C);
    double S, L, h;
    S = a*b*sin(C*pi/180)/2;
    L = a+b + sqrt(a*a+b*b-2*a*b*cos(C*pi/180));
    h = b * sin(C*pi/180);
	printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);
    return 0;
}




Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int r,d,x;
  cin>>r>>d>>x;
  rep(i,10){
    x=r*x-d;
    cout<<x<<endl;
  }
}

Measured memory_bytes: 256
n = int(input())
from itertools import permutations
itr = permutations([i for i in range(1, n + 1)])
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

for i, tpl in enumerate(itr):
    if tpl == p:
        idx1 = i
    if tpl == q:
        idx2 = i
print(abs(idx1 - idx2))

Measured memory_bytes: 8996
#include<stdio.h>
#define MAX 100000
#define MERNUM 1000000000

struct card
{
    char name;
    int num;
};

struct card L[MAX / 2 + 2],R[MAX / 2 + 2];

void merge(struct card ms[],int l,int m,int r){

    int n1,n2,i,j,k;
    n1 = m - l;
    n2 = r - m;
    for(i = 0;i < n1;i++){
        L[i] = ms[l + i];
    }
    for(i = 0;i < n2;i++){
        R[i] = ms[m + i];
    }
    L[n1].num = R[n2].num = MERNUM;
    i = j = 0;
    for(k = l;k < r;k++){
        if(L[i].num <= R[j].num){
            ms[k] = L[i++];
        } else {
            ms[k] = R[j++];
        }
    }
}

void mergesort(struct card ms[],int l,int r){
    int m;
    if (l + 1 < r){
        m = (l + r) / 2;
        mergesort(ms,l,m);
        mergesort(ms,m,r);
        merge(ms,l,m,r);
    }

}

int partition(struct card qs[],int l,int r){

    int n,p;
    struct card t,x;
    
    x = qs[r];
    p = l - 1;

    for(n = l;n < r;n++){
        if (qs[n].num <= x.num){
            p++;
            t = qs[p];
            qs[p] = qs[n];
            qs[n] = t;
        }
    }

    t = qs[p + 1];
    qs[p + 1] = qs[r];
    qs[r] = t;

    return p + 1;

}

void quickSort(struct card qs[],int l,int r){
    int q;
    if (l < r){
        q = partition(qs,l,r);
        quickSort(qs,l,q-1);
        quickSort(qs,q+1,r);
    }
}

int main(void){

    char name[10];
    int num,size;
    struct card ms[MAX],qs[MAX];
    int stable = 1;

    scanf("%d",&size);

    for(int i  = 0;i < size; i++){
        scanf("%s%d",name,&num);
        ms[i].name = qs[i].name = name[0];
        ms[i].num = qs[i].num = num;
    }

    quickSort(qs,0,size-1);
    mergesort(ms,0,size);

    for (int i = 0;i < size;i++){
        if (ms[i].name != qs[i].name){
            stable = 0;
        }
    }

    if (stable == 1){
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }
    for (int i = 0;i < size;i++){
        printf("%c %d\n",qs[i].name,qs[i].num);
    }
    return 0;
}


Measured memory_bytes: 4120
package main

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

// Scan Standard Input
var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	num_s := strings.Split(nextLine(), " ")

	x1, _ := strconv.ParseFloat(num_s[0], 64)
	y1, _ := strconv.ParseFloat(num_s[1], 64)
	x2, _ := strconv.ParseFloat(num_s[2], 64)
	y2, _ := strconv.ParseFloat(num_s[3], 64)

	r := math.Sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
	fmt.Printf("%.8f\n", r)
}



Measured memory_bytes: 1136
#include<iostream>
#include<string>
#include<algorithm>
#include<sstream>
#include <functional>
using namespace std;


int main(){
int n;
	while(cin>>n&&n){
		int id[1002],a[1002]={0},b[1002]={0},c[1002]={0},p,q,r,C;
		bool flag=true;
		for(int i=0;i<n;i++)cin>>id[i]>>a[i]>>b[i]>>c[i];
		cin>>p>>q>>r>>C;
		for(int i=0;i<n;i++){
			if(a[i]<=p&&b[i]<=q&&c[i]<=r&&a[i]*4+b[i]*9+c[i]*4<=C){
			cout<<id[i]<<endl;
				flag=false;
			}
		}
		if(flag)cout<<"NA"<<endl;
	}
	
}

Measured memory_bytes: 1176
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

N, M = map(int, input().split())
def int_(num):
    return int(num) - 1
ablist = [list(map(int_, input().split())) for _ in range(M)]
ans = 0
for ng in range(M):
    uf = UnionFind(N)
    for i in range(M):
        if i != ng:
            uf.union(*ablist[i])
    if uf.group_count() != 1:
        ans += 1
print(ans)

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

#define NIL -1

class Node
{
  public:
  int p = NIL, l, r;
};


void preorder(vector<Node>& nodes, vector<int>& out, int cur)
{
    if (cur == NIL) return;
    out.push_back(cur);
    preorder(nodes, out, nodes.at(cur).l);
    preorder(nodes, out, nodes.at(cur).r);
}

void inorder(vector<Node>& nodes, vector<int>& out, int cur)
{
    if (cur == NIL) return;
    inorder(nodes, out, nodes.at(cur).l);
    out.push_back(cur);
    inorder(nodes, out, nodes.at(cur).r);
}

void postorder(vector<Node>& nodes, vector<int>& out, int cur)
{
    if (cur == NIL) return;
    postorder(nodes, out, nodes.at(cur).l);
    postorder(nodes, out, nodes.at(cur).r);
    out.push_back(cur);
}

void itr_print(vector<int>& out)
{
    for (auto itr = out.begin(); itr != out.end(); ++itr) {
        cout << " ";
        cout << *itr;
    }
    cout << endl;
}

int main()
{
  int n, r;
  cin >> n;
  vector<Node> nodes(n);
  vector<int> out;
  for (int i = 0; i < n; i++) {
    int id, l, r;
    cin >> id >> l >> r;
    nodes.at(id).l = l;
    if (l != (NIL)) {
      nodes.at(l).p = id;
    }
    nodes.at(id).r = r;
    if (r != (NIL)) {
      nodes.at(r).p = id;
    }
  }
  while(n--) {
    r = nodes.at(n).p == NIL ? n : r;
  }
  cout << "Preorder" << endl;
  preorder(nodes, out, r);
  itr_print(out);
  out.clear();
  cout << "Inorder" << endl;
  inorder(nodes, out, r);
  itr_print(out);
  out.clear();
  cout << "Postorder" << endl;
  postorder(nodes, out, r);
  itr_print(out);
  out.clear();
  return 0;
}

Measured memory_bytes: 3140
S=input()
if 1<=int(S[:2])<=12 and (13<=int(S[2:]) or int(S[2:])==0):
    print("MMYY")
elif 1<=int(S[2:])<=12 and (13<=int(S[:2]) or int(S[:2])==0):
    print("YYMM")
elif 1<=int(S[2:])<=12 and 1<=int(S[:2])<=12:
    print("AMBIGUOUS")
elif (13<=int(S[2:]) or int(S[2:])==0) and (13<=int(S[:2]) or int(S[:])==0):
    print("NA")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		long X = 0, x = 0, min = Long.MAX_VALUE;
		for(int i = 0 ; i < N ; i++) {
			a[i] = sc.nextInt();
			X += a[i];
		}
		for(int i = 0 ; i < N ; i++) {
			x += a[i];
			if(i != N - 1) {
				min = Math.min(min, Math.abs(X - 2 * x));
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 64332
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

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

struct node {
	double x, y, r;
};

double cost[1002][1002];
double d[1002];
bool used[1002] = {};

double dif(node a, node b) {
	double sq = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
	return max(0.0, sq - a.r - b.r);
}

signed main() {
	IOS();
	vector<node> p;
	double sx, sy, tx, ty;
	int n;
	cin >> sx >> sy >> tx >> ty >> n;
	p.push_back((node){sx, sy, 0.0});
	p.push_back((node){tx, ty, 0.0});
	vector<double> x, y, r;
	for (int i = 0; i < n; i++) {
		double a, b, c;
		cin >> a >> b >> c;
		p.push_back((node){a, b, c});
	}
	n += 2;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cost[i][j] = dif(p[i], p[j]);
		}
	}
	Fill(d, 1e12);
	d[0] = 0;
	while (1) {
		int v = -1;
		for (int i = 0; i < n; i++) {
			if (!used[i] && (v == -1 || d[i] < d[v])) v = i;
		}
		if (v == -1) break;
		used[v] = true;
		for (int i = 0; i < n; i++) {
			d[i] = min(d[i], d[v] + cost[i][v]);
		}
	}
	dumpf(d[1], 10);
	return 0;
}

Measured memory_bytes: 8320
def solve():
    N = int(input())
    A = list(map(int,input().split()))

    N = len(A)
    money = 1000
    for i in range(0,N):
        if i+1 >= N:
            break
        money2 = money // A[i] * A[i+1] +  money % A[i]
        money = max(money,money2)
    
    print(money)
        
if __name__ == '__main__':
    solve()

Measured memory_bytes: 61912
#include<bits/stdc++.h>
 
#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
 
using namespace std;
const int N=1e5+1, mod=998244353;

ll power(ll a,ll n){
	if(n==0) return 1;
	ll x=power(a,n/2);
	x=(x*x)%mod;
	if(n&1) return (x*a)%mod;
	return x;
}

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

	int n,mx=-1,foo=0;
	cin>>n;
	vector<int> lvl(n);
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(i==0&&x!=0)foo=1;
		lvl[x]++;
		mx=max(mx,x);
	}
	
	if(lvl[0]!=1||foo){
		cout<<0;
		return 0;
	}

	ll res=1;
	for(int i=0;i<mx;i++){
		res*=power(lvl[i],lvl[i+1]);
		res%=mod;
	}
	cout<<res;
    yogeshk972();
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
const int N=1e6+10;
string s;
int ans=0;


int main(){
  cin>>s;
  int l=s.length();

    for(int i=0;i<l/2;i++){
        if(s[i]!=s[l-i-1]){
            ans++;
        }
    }
  cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,max;
	scanf("%d%d",&n,&m);
	int a=n+m;
	int b=n-m;
	int c=n*m;
	max=a;
	if(b>max)
	    max=b;
	if(c>max)
	    max=c;
	printf("%d",max);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int h,n,temp,sum = 0;
    scanf("%d%d",&h,&n);
    for(int i = 0; i<n; i++){
        scanf("%d",&temp);
        sum += temp;
    }
    if(h<=sum)
        printf("Yes");
    else
        printf("No");
    return 0;
}

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

int main()
{
    int low, high, num, c;

    cin >> low >> high >> num;

    c = 0;
    for(int i = low; i <= high; i++)
    {
        if( (num % i) == 0)
        {
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3116
N, K = map(int, input().split())
MOD = 10**9 + 7

p = q = 1
for i in range(N):
    p = p * (N+K-1-i) % MOD
    q = q * (i+1) % MOD

print(p * pow(q, MOD-2, MOD) % MOD)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define vi vector<int> 
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define fi first
#define se second
using namespace std;
void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max({a*c,a*d,b*c,b*d});
}
int32_t main()
{
	//freopen("shell.in", "r", stdin);
	//freopen("shell.out", "w", stdout);
	int t=1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}
// Problem : B - Product Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



Measured memory_bytes: 3632
n = int(input())
p = list(map(int,input().split()))
count = 0

for i in range(1,n-1):
    if p[i-1] <= p[i] <= p[i+1] or p[i-1] >= p[i] >= p[i+1]:
        count += 1
    else:
        pass

print(count)



Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


int main(int argc, char *argv[]) {

	int N; cin >> N;

	int A,B; cin >> A >> B;
	string S; cin >> S;

	int domain = 0;
	int	foreign = 0; 
	for (int i = 0; i < N; i++) {
		switch (S[i]){
			case 'a':
				if (domain + foreign < A + B) {
					cout << "Yes"<< endl;
					domain++;
					break;
				}
			case 'b':
				if (domain + foreign < A + B and foreign < B) {
					cout << "Yes"<< endl;
					foreign++;
					break;
				}
			default:
				cout << "No" << endl;
				break;
		}
	}
	return 0;
}


Measured memory_bytes: 3744
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int r = in.ni();
        if(r>=2800) out.println("AGC");
        else if(r>=1200) out.println("ARC");
        else out.println("ABC");
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21076
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        int w = int.Parse(Console.ReadLine());
        int n = s.Length;
        for (int i = 0; i < n; i++)
        {
            if (i % w == 0)
            {
                Console.Write(s[i]);
            }
        }
        Console.Write('\n');
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, W; cin >> N >> W;
    vector<long long> dp(N*1000 + 1, INT_MAX);
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        int w, v;
        cin >> w >> v;
        for (int j = N*1000; j >= v; j--) {
            dp[j] = min(dp[j-v] + w, dp[j]);
        }
        //for (int k = 0; k <= N; k++)
    }

    for (int i = N*1000; i >= 0; i--) {
        if (dp[i] <= W) {
            cout << i;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    ll a,b,c;
    ll ans = 0;
    cin >> a >> b >> c;
    if (b < c){
        ans += 2 * b;
        c -= b;
        ans += min(a,c);
        if (c > a){
            ans++;
        }
    } else {
        ans += b + c;
    }
    cout << ans << endl;
        

    return 0;
}


Measured memory_bytes: 256
import math


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    T1, T2 = read_values()
    A1, A2 = read_values()
    B1, B2 = read_values()

    if A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2:
        print("infinity")
        return

    D1 = (A1 - B1) * T1
    D2 = (A2 - B2) * T2

    if D1 * D2 > 0:
        print(0)
        return

    D1 = abs(D1)
    D2 = abs(D2)

    if D1 > D2:
        print(0)
        return

    i = D1 // (D2 - D1)
    if D1 == i * (D2 - D1):
        print(i * 2)
    else:
        print(1 + 2 * i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

from itertools import permutations

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

N = int(input())
data = []
for i in range(N):
    data.append(list(map(int, input().split())))

cases = list(permutations(list(range(N)), N))

ans = 0
for case in cases:
    dist = 0
    for i in range(1, N):
        a, b = case[i-1], case[i]
        dist += ((data[a][0] - data[b][0])**2 + (data[a][1] - data[b][1])**2)**.5
    ans += dist

print(ans/len(cases))




Measured memory_bytes: 45552
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1050
#define mod 1000000007
int head[N],cnt,s[N*2][3],fa[N],v[N*2],as,n,m,s1,s2,is[N*2];
long long su;
struct edge{int t,next,v;}ed[N*2];
void adde(int f,int t,int v){ed[++cnt]=(edge){t,head[f],v};head[f]=cnt;ed[++cnt]=(edge){f,head[t],v};head[t]=cnt;}
int finds(int x){return fa[x]==x?x:fa[x]=finds(fa[x]);}
bool cmp(int i,int j){return s[i][2]<s[j][2];}
void dfs(int u,int fa,int t,int v){if(u==t){as=v;return;}for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs(ed[i].t,u,t,max(ed[i].v,v));}
int main()
{
	scanf("%d%d%lld",&n,&m,&su);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++)scanf("%d%d%d",&s[i][0],&s[i][1],&s[i][2]),v[i]=i;
	sort(v+1,v+m+1,cmp);
	for(int i=1;i<=m;i++)if(finds(s[v[i]][0])!=finds(s[v[i]][1]))is[v[i]]=1,fa[finds(s[v[i]][0])]=finds(s[v[i]][1]),su-=s[v[i]][2],adde(s[v[i]][0],s[v[i]][1],s[v[i]][2]);
	if(su<0)printf("0");
	else
	{
		for(int i=1;i<=m;i++)if(!is[i])
		{
			as=0;dfs(s[i][0],0,s[i][1],0);
			int tp=s[i][2]-as;
			if(tp==su)s1++;
			if(tp>su)s2++;
		}
		if(su==0)
		{
			int as=0,st1=1,st2=1;
			for(int i=1;i<=m;i++)st1=st1*2%mod;
			for(int i=1;i<=m-n+2-s1;i++)st2=st2*2%mod;
			as=(st1-st2+mod)%mod;
			printf("%d\n",as);
		}
		else
		{
			int as=0,st1=1,st2=1;
			for(int i=1;i<=s1;i++)st1=st1*2%mod;
			for(int i=1;i<=s2;i++)st2=st2*2%mod;
			as=2ll*(st1-1)*st2%mod;
			printf("%d\n",as);
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#define CODE_MAX 10000
#define L_MAX 33

int p, p2;
short code[CODE_MAX];

/* letter -> code */

#define BIT_MAX 8

char list1[8][2][L_MAX]={
     {"',?DW.CFHLOSTIK", "-ABGJMNQRUVXYZE P"},
     {"-ABGJMNQRUVXYZ ',?DWLOST", "EP.CFHIK"},
     {"E.CFH-ABGJMNQRUVXYZ',?DW", "PIK LOST"},
     {"KLO.FHR',?W", "ISTC-ABGJMNQUVXYZD"},
     {"S-AXYZL.H'?", "TBGJMNQUVOF,W"},
     {"BGJMW-XYZH'", "NQUV,A.?"},
     {"UVJM-Z", "NQBGXY"},
     {"NBXUJZ", "QGYVM-"}
};

void l2c(char ch)
{
     int i, j, k;
     
     for(i=0; i<BIT_MAX; i++)
	  for(j=0; j<2; j++)
	       for(k=0; list1[i][j][k]!='\0'; k++)
		    if(list1[i][j][k]==ch)
			 code[p++]=j;
}

/* code -> letter */

#define BIT_MAX2 5

char list2[L_MAX]="ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

char c2l()
{
     int t = 0, i;
     
     for(i=0; i<BIT_MAX2; i++)
	  t = (t<<1) + code[p2++];
     
     return list2[t];
}

/* main */

main()
{
     int i; char ch=getchar();

     while(1){
	  
	  if(ch==EOF) return 0;

	  p = p2 = 0;
	  for(i=0; i<CODE_MAX; i++) code[i]=0;

	  while(ch!='\n'){
	       l2c(ch);
	       ch=getchar();
	  }
	  
	  ch=getchar(); /* pop '\n' */
	  
	  while(p2<p) putchar(c2l());
	  puts("");
     }
}

Measured memory_bytes: 0