akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
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; }
//#define int long long

void solve() {
	int a, b, c; cin >> a >> b >> c;
    if(a + b + c >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n , number[101] , i , j ;
	cin >> n ;
	for ( i = 1 ; i<= n ; i ++ ){
		cin >> number[i] ;
	}
	for ( i = n ; i > 1 ; i --){
		cout << number[i] <<" ";
	}
	cout << number[1] << endl ;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(void)
{
    u_int n;
    cin >> n;

    int a[n];
    for (u_int i = 0; i < n; i++)
        cin >> a[i];

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

Measured memory_bytes: 1140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int n;
	scanf("%d", &n);
	int *d = malloc(sizeof(int) * n);
	int sum = 0;
	int res = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", d + i);
		sum += d[i];
	}
	for(int i = 0; i < n; i++)
		res += (sum - d[i]) * d[i];
	printf("%d\n", res / 2);
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x;

		if (a > b) {
			x = a;
			a = b;
			b = x;
		}
		if (a > c) {
			x = a;
			a = c;
			c = x;
		}
		if (b > c) {
			x = b;
			b = c;
			c = x;
		}
		System.out.println(a + " " + b + " " + c);
	}
}

Measured memory_bytes: 26204
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [n;q] = reads int
    let abs = List.init (n - 1) (fun _ -> reads int |> fun [a;b] -> (a, b))
    let pxs = List.init q (fun _ -> reads int |> fun [p;x] -> (p, x))

    let sumpx =
        let a = Array.create (n + 1) 0
        for (p, x) in pxs do
            a.[p] <- a.[p] + x
        a

    let grp =
        let g : int [] = Array.init (n + 1) (fun _ -> -1)
        for (a, b) in abs do
            g.[b] <- a
        g

    let ans = Array.create (n + 1) (-1)
    ans.[1] <- sumpx.[1]
    let rec loop i =
        let p = grp.[i]
        ans.[i] <- ans.[p] + sumpx.[i]

    for i = 2 to n do loop i

    printf "%i" ans.[1]
    for i = 2 to n do
        printf " %i" ans.[i]

    0

Measured memory_bytes: 46848
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=1e5+11,INF=~0u>>2;
int A,B,C,D,E,F,ans1,ans2,a1,a2,t1,t2;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int main(){
//	freopen("ex.in","r",stdin);
	A=read();B=read();C=read();D=read();E=read();F=read();
	rep(a,31) rep(b,31) rep(c,101) rep(d,101){
		if(a*100*A+b*100*B+c*C+d*D>F) continue;
		if((a*A+b*B)*E<c*C+d*D) continue;
//		double tmp=(double)(c*C+d*D)/(double)(a*100*A+b*100*B+c*C+d*D);
		t1=(c*C+d*D);
		t2=(a*100*A+b*100*B+c*C+d*D);
		if((a1==0&&a2==0)||t1*a2>t2*a1){
			a1=t1;a2=t2;
			ans1=a*100*A+b*100*B+c*C+d*D;
			ans2=c*C+d*D;
		}
	}
	printf("%d %d",ans1,ans2);
}

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

using namespace std;

int main() {
    long long int N, K;
    cin >> N >> K;
    
    vector<long long int> vec(1e5+1, 0);
    for(int n=0; n<N; n++) {
        int a;
        long long int b;
        cin >> a >> b;
        vec[a] += b;
    }
    
    for(int i=0; i<1e5; i++) {
        vec[i+1] += vec[i];
    }

    cout << lower_bound(vec.begin(), vec.end(), K)-vec.begin() << endl;

    return 0;
    
}

Measured memory_bytes: 1024
_,*s=open(0)
t='.'
b=t*101
r=range(101)
i=0
for s in s:
 a=[i];i+=1
 for x,y,z,c in zip(b,t+s,s,r):a+=min(c+(t>z<x),a[-1]+(t>z<y)),
 b,r=s,a[1:]
print(a[-2])

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

#define sc second
#define fr first

#define ll long long
#define pi pair<int,int>
#define ppi pair<pi,pi>
#define mp make_pair
using namespace std;

int N , M;
int Dp[111][111][2];
int G[111][111];
int solve(int i,int j,int pre)
{
    if(i == N && j == M)
    {
        return (!pre && G[i][j]);
    }
    int &ret = Dp[i][j][pre];
    if(ret + 1)return ret;
    ret =1e9;
    if(pre)
    {
        if(i + 1 <= N)
            ret = min(ret , solve(i + 1,j , G[i][j]));
        if(j + 1 <= M)
            ret = min(ret , solve( i ,j + 1 , G[i][j]));
    }
    else
    {
        if(i + 1 <= N)
            ret = min(ret , solve(i + 1,j , G[i][j]) + (G[i][j] != pre));
        if(j + 1 <= M)
            ret = min(ret , solve( i ,j + 1 , G[i][j]) + (G[i][j] != pre));
    }
    return ret;
}

int main(){

    ios::sync_with_stdio(0);
    cin .tie(0),cout.tie(0);

    cin >> N >> M;
    for(int i = 1;i <= N;i++)
        for(int j = 1;j <= M;j++)
    {
        char C;  cin >> C;
        G[i][j] = (C == '#');
    }
    memset(Dp,-1,sizeof Dp);
    cout << solve(1,1,0) << '\n';



    return 0;
}


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

int main(){
    ll x,y,z,k;
    cin >> x >> y >> z >> k;
    ll a[x];
    for(ll i=0;i<x;i++) cin >> a[i];
    sort(a, a+x, greater<ll>());
    ll b[y];
    for(ll i=0;i<y;i++) cin >> b[i];
    sort(b, b+y, greater<ll>());
    ll c[z];
    for(ll i=0;i<z;i++) cin >> c[i];
    sort(c, c+z, greater<ll>());
    priority_queue<ll> pq1;
    for(ll i=0;i<x;i++){
        for(ll j=0;j<y;j++){
            pq1.push(a[i]+b[j]);
        }
    }
    priority_queue<ll> pq2;
    ll count=0;
    while(!pq1.empty()){
        count++;
        pq2.push(pq1.top());
        pq1.pop();
        if(count==k) break;
    }
    priority_queue<ll> pq3;
    while(!pq2.empty()){
        ll v=pq2.top();
        pq2.pop();
        for(ll i=0;i<z;i++){
            pq3.push(v+c[i]);
        }
    }
    for(ll i=0;i<k;i++){
        cout << pq3.top() << endl;;
        pq3.pop();
    }
}


Measured memory_bytes: 44168
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}   // 


int main() {
	int N; cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; i++)cin >> S[i];

	sort(ALL(S));
	map<string, int> p;
	for (int i = 0; i < N; i++) {
		p[S[i]]++;
	}

	int m = 0;
	for (int i = 0; i < N; i++) {
		if (m <= p[S[i]])m = p[S[i]];
	}

	map<int,string> t;
	for (int i = 0; i < N; i++) {
		if (p[S[i]] == m) {
			t[i] = S[i];
		}
		else t[i] = "A";
	}

	map<string, int> u;
	for (int i = 0; i < N; i++) {
		if (t[i] != "A" && u[t[i]] ==0) {
			cout << t[i] << endl;
			u[t[i]]++;
		}
	}
}


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

#define dictsize int(pow(5.0, 12.0))
int dict[dictsize];

map<char, int> dict_to_key = {
    {'A', 1},
    {'C', 2},
    {'G', 3},
    {'T', 4},
};

int name_to_key(string &str) {
  auto res = 0;
  for(auto &item : str) {
    res = res * 4 + dict_to_key[item];
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  string operate;
  string name;
  rep (i, N) {
    cin >> operate >> name;
    if (operate == "insert"){
      dict [name_to_key(name)] = 1;
    } else {
      if (dict [name_to_key(name)])
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 8608
N = int(input())
P = list(map(int, input().split()))

INF = 10 ** 7
minP = [INF] * (N + 1)

for i in range(N):
    minP[i + 1] = min(minP[i], P[i])

cnt = 0
for i in range(N):
    if P[i] <= minP[i]:
        cnt += 1

print(cnt)


Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    vector<ll> v;
    for(ll i = 1; i <= sqrt(n) + 1LL; i++) {
        if(n % i == 0LL) {
            v.push_back(i);
            if(i * i != n) {
                v.push_back(n / i);
            }
        }
    }
    for(int i = 0; i < v.size(); i++) {
        ll k = v[i];
        ll m = (n / k) - 1LL;
        if(k < m && m > 0LL) {
            ans += m;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int N, M, Q;
vector<int> a(60), b(60), c(60), d(60);

ll dfs(vector<int> A){
    if(A.size() == N){
        ll ans = 0;
        rep(i, Q){
            if(A.at(b.at(i) - 1) - A.at(a.at(i) - 1) == c.at(i)){
                ans += d.at(i);                
            }
        }
        return ans;
    }

    int i;
    ll ans = 0;

    if(A.size() == 0) i = 1;
    else i = A.back();

    while(i <= M){
        A.push_back(i);
        ans = max(ans, dfs(A));
        A.pop_back();
        i++;
    }
    return ans;
}

int main(){
    cin >> N >> M >> Q;
    rep(i, Q) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    vector<int> A;
    cout << dfs(A) << endl;
}


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

const int N_MAX = 12;
const int M_MAX = 12;

int A[N_MAX+1][M_MAX+1];
int C[N_MAX+1];

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    for(int i = 0; i < n; i++){
        cin >> C[i];
        for(int j = 0; j < m; j++){
            cin >> A[i][j];
        }
    }
    bool ans = false;
    int cost = 2000000;
    for(int S = 0; S < 1 << n; S++){
        int newcost = 0;
        int D[M_MAX];
        int newans = true;
        for(int i = 0; i < m; i++)D[i] = 0;
        for(int i = 0; i < n; i++){
            if (!(S & 1 << i))continue;
            newcost += C[i];
            for(int j = 0; j < m; j++) D[j] += A[i][j];
        }
        for(int j = 0; j < m; j++){
            if (D[j] < x){
                newans = false;
                break;
            }
        }
        if (newans){
            ans = true;
            cost = min(cost, newcost);
        }
    }
    if (ans) cout << cost << endl;
    else cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  string s;
  cin >> s;

  int ap = -1, zp = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' && ap == -1) ap = i;
    if (s[i] == 'Z') zp = i;
  }

  printf("%d\n", zp - ap + 1);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define INF 2000'000'000

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	//freopen("in", "r", stdin);
	int k;
	cin >> k;
	int ans = 1, cur = 7 % k;
	while(cur && ans <= 1000'002){
		ans++, cur = (cur*10 + 7) % k;
	}
	if(ans >= 1000'002)
		cout << "-1\n";
	else
		cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	class DisjointSet {

		int[] parent;
		int[] rank;
		int[] weight;
		
		public DisjointSet(int size) {
			parent = new int[size];
			rank = new int[size];
			weight = new int[size];
			for (int i = 0; i < size; i++) makeSet(i);
		}

		private void makeSet(int x) {
			parent[x] = x;
			rank[x] = 0;
			weight[x] = 0;
		}

		public void relate(int x, int y, int z) {
			link(findSet(x), findSet(y), z - weight[x] + weight[y]);
		}

		private void link(int x, int y, int cost) {
			if (rank[x] > rank[y]) {
				parent[y] = x;
				weight[y] -= cost;
			} else {
				parent[x] = y;
				weight[x] += cost;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}

		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		private int findSet(int x) {
			if (parent[x] != x) {
				int tmp = findSet(parent[x]);
				weight[x] += weight[parent[x]];
				parent[x] = tmp;
			}
			return parent[x];
		}

		public int sum(int x) {
			int sum = 0;
			int cur = x;
			while (cur != parent[cur]) {
				sum += weight[cur];
				cur = parent[cur];
			}
			return sum;
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				int z = Integer.parseInt(st.nextToken());
				ds.relate(x, y, z);
			} else {
				if (!ds.same(x, y)) {
					System.out.println("?");
				} else {
					System.out.println(ds.sum(x) - ds.sum(y));
				}
			}
		}
		reader.close();
	}
}



Measured memory_bytes: 79084
sum=0

n=int(input())
s=input().split()
t=[]
for i in range(n):
  t.append(int(s[i]))
#print(t)
for i in range(n):
  for j in range(n):
    if i==j:
        sum+=0
    else:
        sum+=t[i]*t[j]
print(int(sum/2))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> N;
    vector<ll> a(N);
    cin >> a;
    ll sum = 0;
    REP(i, N) {
        sum ^= a[i];
    }
    REP(i, N) {
        a[i] &= (~sum);
    }
    int i = 0;
    int red = 0;
    int mx = 60;
    RREP(digit, mx + 1) {
        FOR(j, i + 1, N) {
            if (a[j] & (1LL << digit)) {
                swap(a[i], a[j]);
                break;
            }
        }
        if (~a[i] & (1LL << digit)) {
            continue;
        }
        FOR(j, i + 1, N) {
            if (a[j] & (1LL << digit)) {
                a[j] ^= a[i];
            }
        }
        if (~red & (1LL << digit)) {
            red ^= a[i];
        }
        i++;
    }
    cout << red + (sum ^ red) << endl;
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+5;
const ll mod=1e9+7;
int a[30];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    int cnt=0;
    for(int i=2;i<n;i++)
    {
        if(a[i]>a[i-1] && a[i] < a[i+1] || a[i]<a[i-1]&&a[i]>a[i+1])
            cnt++;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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 ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vvll a(n, vll(n));
    REP(i, n) REP(j, n) cin >> a[i][j];
    bool is_add = true;
    ll ans = 0;
    REP(i, n) rep(j, i+1, n) {
        is_add = true;
        REP(k, n) {
            if (k==i || k==j) continue;
            if (a[i][j] > a[i][k]+a[k][j]) {
                cout << -1 << '\n'; return 0;
            } else if (a[i][j] == a[i][k]+a[k][j]) {
                is_add = false;
            }
        }
        if (is_add) ans += a[i][j];
    }
    cout << ans << '\n';
    return 0;
}


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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

LL r, d, x[11];

int main() {
	read(r), read(d), read(x[0]);
	for (int i = 1; i <= 10; ++i) {
		x[i] = r * x[i - 1] - d;
		write(x[i]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // This will work only for g++ compiler. 
#include <ext/pb_ds/assoc_container.hpp> // Used to include policy based data structure 
using namespace __gnu_pbds;  // Only for g++ compiler
using namespace std;

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define max(a, b)  (a > b) ?a :b  // max of 2 elements 
#define min(a, b)  (a < b) ?a :b  // min of 2 elements

//short hand for usual tokens
#define pb              push_back
#define fi              first
#define se              second
#define mp              make_pair
#define mii             map<int,int>
#define pqb             priority_queue<int>   // Max Heap
#define pqs             priority_queue<int,vi,greater<int> >   // Min Heap
#define setbits(x)      __builtin_popcountll(x)   // returns the number of set bits in the binary representation of x
#define zrobits(x)      __builtin_ctzll(x)   // returns the number of zeroes before the first set bit in the binary representation of x       
#define mod             1000000007   // 1e9 + 7   
#define inf             1e18   // pow(10, 18)  
#define mk(arr,n,type)  type *arr=new type[n];   // generates a dynamic array
#define w(x)            int x; cin>>x; while(x--)   // for taking test cases 
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());   // used with shuffle

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;   // Used to implement policy-based data structure

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    
    int n;
    cin>>n;
    int ans = ceil(1.0*n/1000);
    ans = ans*1000 - n;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define P pair<int,int>
using namespace std;
const int maxn = 410;
char maze[maxn][maxn];
bool visited[maxn][maxn];
int h, w;

void input() {
    cin>>h>>w;
    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++) {
            cin>>maze[i][j];
        }
    }
}

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

bool check(int i, int j, int d) {
    int ni = i + dx[d];
    int nj = j + dy[d];
    if(ni >= 0 && ni < h && nj >= 0 && nj < w)
        if(!visited[ni][nj] && maze[i][j] != maze[ni][nj]) return true;
    return false;
}

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

    ll result = 0LL;
    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++) {
            if(visited[i][j] || maze[i][j] == '.') continue;
            ll B = 0, W = 0;
            queue<P>q;
            q.push(mp(i, j));
            visited[i][j] = true;

            while(!q.empty()) {
                P curr = q.front();
                q.pop();
                if(maze[curr.first][curr.second] == '#') B++;
                else W++;

                for(int d=0;d<4;d++) {
                    if(check(curr.first, curr.second, d)) {
                        int ni = curr.first + dx[d];
                        int nj = curr.second + dy[d];
                        visited[ni][nj] = true;
                        q.push(mp(ni, nj));
                    }
                }
            }
            result += 1LL * B * W;
        }
    }
    cout<<result<<"\n";
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    double a, b, c, d, e, f;
    while (cin >> a >> b >> c >> d >> e >> f)
    {
        double det = a * e - b * d;

        double x = (1 / det) * (e * c - b * f), y = (1 / det) * (-d * c + a * f);
        if (x == 0)
            x = 0;
        if (y == 0)
            y = 0;
        printf("%.3f %.3f\n", x, y);
    }

    return 0;
}


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

int main() {
	int n;cin>>n;
	vector<int> a(n),v;
	int r=0;
	int ans=1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i==0){
			v.push_back(a[i]);
			continue;
		}
		if(a[i]-v.back()==0)continue;
		if(a[i]>v.back()){
			if(r==0){
				r=1;
				v.push_back(a[i]);
			}else if(r==1){
				v.push_back(a[i]);
			}else{
				v.clear();
				v.push_back(a[i]);
				ans++;
				r=0;
			}
		}else{
			if(r==0){
				r=-1;
				v.push_back(a[i]);
			}else if(r==-1){
				v.push_back(a[i]);
			}else{
				v.clear();
				v.push_back(a[i]);
				ans++;
				r=0;
			}
		}
//		cout<<i<<' '<<ans<<' '<<r<<' '<<a[i]<<endl;
//		for(auto j:v){
//			cout<<j<<' ';
//		}
//		cout<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    for(int i = 1;; i++){
        int cnt = 0;
        for(int j = 1; j*j <= i; j++){
            if(i%j) continue;
            cnt+=2;
            if(j*j == i)    cnt--;
        }
        if(cnt == n){
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3128
#include <iostream>
using namespace std;
int main (void){
    int H , W ;
    while (1){
        cin >> H >> W;
        if (H == 0 && W ==0){
            break;
        }
        for(int j = 0; j < W; j++){
            cout << '#';
        }
        cout << endl;
        for(int i = 1; i < H-1 ; i++){
            cout << '#';
            for(int j = 1; j< W-1; j++){
                cout << '.';
            }
            cout << '#' << endl;
        }
        for(int j = 0 ; j < W ; j++){
            cout << '#';
        }
        cout << endl << endl;
    }
    
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9 + 5;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vi ww[MAXN];
vector<pair<pii, int> > pp;

ll f[MAXN], f_inv[MAXN];

vi vals;

ll pow_mod(ll v, ll st) {
	ll ans = 1ll;
	for(; st; st >>= 1) {
		if (st & 1) {
			ans = (ans * v) % MOD;
		}
		v = (v * v) % MOD;
	}
	return ans;
}

void solve(){
	int n, x, y;
	scanf("%d%d%d", &n, &x, &y);
	REP(i, 0, n){
		int c, w;
		scanf("%d%d", &c, &w);
		ww[c].pb(w);
	}
	REPN(i, 1, n) {
		if (SZ(ww[i]) == 1) {
			pp.pb(mp(mp(ww[i][0], INF), i));
		} else if (SZ(ww[i]) > 1) {
			SORT(ww[i]);
			pp.pb(mp(mp(ww[i][0], ww[i][1]), i));
		}
	}
	SORT(pp);
	REP(i, 1, SZ(pp)){
		if (pp[i]._1._1 + pp[0]._1._1 > y) {
			//printf("# %d %d %d %d\n", pp[i]._1._1, pp[i]._2, i, SZ(pp));
			int last = SZ(pp);
			REP(j, i, last) {
				pp.pop_back();
			}
			break;
		}
	}
	if (SZ(pp) <= 1) {
		printf("1\n");
		return;
	}
	int cnt_tot = 0;
	REP(i, 0, SZ(pp)) {
		int nxt_ind = (i ? pp[0]._2 : pp[1]._2), ind = pp[i]._2;
		int cnt = 1;
		REP(j, 1, SZ(ww[ind])) {
			if (ww[ind][j] + ww[ind][0] <= x || ww[ind][j] + ww[nxt_ind][0] <= y) {
				cnt++;
			} else {
				break;
			}
		}
		
		//printf("%d %d\n", ind, cnt);
		
		cnt_tot += cnt;
		vals.pb(cnt);
	}
	
	f[0] = 1;
	REPN(i, 1, n) {
		f[i] = (f[i - 1] * i) % MOD;
	}
	f_inv[n] = pow_mod(f[n], MOD - 2);
	for(int i = n - 1; i >= 0; i--) {
		f_inv[i] = (f_inv[i + 1] * (i + 1)) % MOD;
	}
	
	ll ans = f[cnt_tot];
	REP(i, 0, SZ(vals)) {
		ans = (ans * f_inv[vals[i]]) % MOD;
	}
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 16240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14

int main(){
    string t; cin >> t;
    string s="";
    REP(i,t.size()){
        if (t[i]=='D') s+='D';
        else if (t[i]=='P') s+='P';
        else s+='D';
    }
    cout << s << endl;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
	#define ll long long int
	// #define mod 1000000007
	#define rep(i,a,n) for (int i=a;i<n;i++)
	//rep(i,0,p) {
	using namespace std;

	void solve() {
		ll n,k;
		ll nn=0,kk=0;
		cin >> n >> k;
		if(k>=n){
			if(k==n){
				cout <<"0\n";
				return;
			}
			ll minus=k-n;
			cout <<min(minus,n)<<"\n";
			return;
		}
		ll mod=n%k;
		cout <<min(abs(mod-k),min(mod,k))<<"\n";
		return;
	}

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

		// int t;
		// cin >> t;
		// while(t--)
			solve();

	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n,q;
  cin>>n>>q;
  vll tree(n+1,vl(0));
  rep(i,n-1){
      ll a,b;
      cin>>a>>b;
      tree[a].pb(b);
      tree[b].pb(a);
  }
  vl points(n+1,0);
  rep(i,q){
      ll p,x;
      cin>>p>>x;
      points[p]+=x;
  }
  vector<bool> z(n+1,false);
  queue<ll> Q;
  Q.push(1);
  while(!Q.empty()){
      ll num=Q.front();
      Q.pop();
      z[num]=true;
      rep(i,sz(tree[num])){
          if(!z[tree[num][i]]){
              points[tree[num][i]]+=points[num];
              Q.push(tree[num][i]);
          }
      }
  }
  for(ll i=1;i<=n;i++){
      cout<<points[i]<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 18828
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    ll mn = A * (N-1) + B;
    ll mx = A + B * (N - 1);
    ll ans = 0;
    ans = max(ans, mx - mn + 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
    	Scanner scanner = new Scanner(System.in);
        int n = (int) scanner.nextInt();
        int ans = 0;
      	for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++){
        for (int k = 1; k <= n; k++){
          int c = gcd(i, j);		
          ans+= gcd(k, c);
        }
        }
        }
      System.out.println(ans);
      
    }
  	
  	static int gcd(int a, int b){
    	while(a != b){
        	if (a >= b){
            	a-=b;
            }else{
            	b-=a;
            }
        }
      return a;
    }
}

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

using namespace std; 

int p[60000]; 

int main(){
	int n; 
	scanf("%d",&n); 
	for (int i=2;i<=55555;i++) if(!p[i]) 
		for(int j=i;j<=55555/i;j++) p[i*j]=1; 
	for(int i=2;i<=55555;i++)
		if(!p[i] && i%10==1 && n){
			printf("%d ",i); 
			if(--n==0) break; 
		} 
	return 0; 
}

Measured memory_bytes: 512
//Pranet Verma
#include <bits/stdc++.h>
using namespace std;
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int a[3];
	for (int i = 0; i < 3; ++i) {
		cin >> a[i];
	}
	cout << *max_element(a, a + 3) - *min_element(a, a + 3);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////

int N;
int ref;
int main(){
    scanf("%d",&N);
    for(ref=111;ref<N;ref+=111);
    printf("%d\n",ref);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a%b);
}
ll LCM(ll a, ll b){
    return a/GCD(a, b) *b;
}
//--MAIN-----------------------------------
void Main() {
    ll A,B; cin>>A>>B;
    cout<< LCM(A,B) <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

using namespace std;

int main() {
  int N, X;

  cin >> N >> X;

  int sum = 0;
  int min_m = 1000;
  int m;
  for (int i = 0; i < N; ++i) {
    cin >> m;
    sum += m;
    min_m = min(min_m, m);
  }
  const auto ans = N + (X - sum) / min_m;
  cout << ans << endl;

  return 0;
}


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

public class Main {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	long w = sc.nextLong();
    	int maxSumVal = 10;
    	long[] wei = new long[n + 10];
    	int[] val = new int[n + 10];
    	for(int i = 0 ; i < n ; i++) {
    		wei[i] = sc.nextLong();
    		val[i] = sc.nextInt();
    		maxSumVal += val[i];
    	}

    	long[][] dp = new long[n + 10][maxSumVal];
    	for(int i = 0 ; i < n + 10 ; i++) {
    		Arrays.fill(dp[i], Long.MAX_VALUE / 2);
    	}
    	dp[0][0] = 0;  //初期条件！！！！！
    	for(int i = 0 ; i < n ; i++) {
    		for(int sumVal = 0 ; sumVal < maxSumVal ; sumVal++) {
    			if(sumVal - val[i] >= 0) {
    				dp[i + 1][sumVal] = Math.min(dp[i + 1][sumVal], dp[i][sumVal - val[i]]  + wei[i]);
    			}
    			else {
    				dp[i + 1][sumVal] = Math.min(dp[i + 1][sumVal] , dp[i][0] + wei[i]);
    			}
    			dp[i + 1][sumVal] = Math.min(dp[i + 1][sumVal], dp[i][sumVal]);
    		}
    	}
    	sc.close();
    	long ans = Integer.MIN_VALUE;
    	for(int i = 0 ; i < maxSumVal ; i++) {
    		if(dp[n][i] > w)
    			break;
    		ans = i;
    	}
    	System.out.println(ans);
    }

}


Measured memory_bytes: 141668
h = gets.chomp.to_i


count = 0

if h == 1
  puts 1
  exit
end


while 1
  h = (h/2)
  count += 1

  break if h == 1

end

ans = [1]

1.upto(count) do |c|
  ans << ans[c-1] + 2**c
end

p ans.last

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

#define ll long long 

ll mod=998244353LL;
ll d[100001];
int n;
int zerocnt;


ll sqpow(ll a,ll n){
    if(n==0)return 1;
    if(n==1)return a;
    ll sq=sqpow(a,n/2);
    if(n%2==0)return sq*sq%mod;
    return a*sq%mod*sq%mod;
}


void solve(){
    zerocnt=0;
    //vector<ll> renzoku;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>d[i];
        if(d[i]==0){
            zerocnt++;
        }
    }
    if(d[0]!=0){
        cout<<0<<endl;
        return;
    }
    bool bflag=false;
    sort(d,d+n);
    //renzoku.push_back();
    ll cnt=1LL;
    for(int i=1; i<n; i++){
        if(d[i-1]!=d[i] && d[i-1]+1!=d[i]){
            bflag=true;
            break;
        }
    }
    if(bflag || zerocnt>1 || zerocnt==0){
        cout<<0<<endl;
        return;
    }
    if(zerocnt==1 && n==1){
        cout<<1<<endl;
    }

    ll temp=1LL;
    ll ans=1LL;
    for(int i=2; i<n; i++){
        //cout<<d[i]<<endl;
        if(d[i]!=d[i-1]){
            ans*=sqpow(cnt, temp);
            //cout<<cnt<<" "<<temp<<endl;
            ans%=mod;
            cnt=temp;
            temp=1;
        }
        else{
            temp++;
        }
    }
    ans*=sqpow(cnt,temp);
    cout<<ans%mod<<endl;

}

signed main(){
    //while(1)
    solve();
}

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

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

    int ans=0;
    for(int i=1;i<n-1;i++) {
        if((a[i-1]>a[i]&&a[i]>a[i+1])||(a[i+1]>a[i]&&a[i]>a[i-1])) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll ncr(ll n,ll r)
{
	if(n==1 || r==0)
	return 1;
	if(r>n/2)
	r=n-r;
	ll ans=1;
	for(ll i=1;i<=r;i++)
	{
		ans=((ans * n )/i);
		n--;
	}
	return ans;
}
int main()
{
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	ll ans=1e18;
	for(ll i=1;i<=100;i++)
	{
		ll sum=0;
		for(ll j=0;j<n;j++)
		{
			ll k=(a[j]-i)*(a[j]-i);
			sum=sum+k;
		}
		ans=min(sum,ans);
	}
	cout<<ans;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;

    i64 base = 1;
    for (; n > (i64) pow(26, base); base++) n -= (i64) pow(26, base);

    n--;
    string ans;
    for (i64 i = 0; n > 0; i++) {
        ans = (char) ('a' + (n % 26)) + ans;
        n /= 26;
    }
    cout << string(base - ans.size(), 'a') + ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

using namespace std;

int p[3] = {300000, 200000, 100000};

int main() {
	int x, y;
	cin >> x >> y;
	int ans;
	if(x <= 3){
		if(y <= 3){
			ans = p[x - 1] + p[y - 1];
			if(x == 1 && y == 1) ans += 400000;
		}
		else ans = p[x - 1];
	} 
	else{
		if(y <= 3) ans = p[y - 1];
		else ans = 0;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)

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

  cout<<(1900*m+100*(n-m))*pow(2,m)<<endl;

    return 0;
  }


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;

int n;
vector<vector<ll>> memo(3030, vector<ll>(3030, 0));
vector<ll> a(3030, 0);
vector<vector<bool>>  flg(3030, vector<bool>(3030, false));

ll rec(int l, int r){
    if(flg[l][r]) return memo[l][r];
    flg[l][r] = true;

    if(l==r) return memo[l][r] = a[l];
    return memo[l][r] = max(a[l]-rec(l+1, r), a[r]-rec(l, r-1));
}


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

    // 条件はどちらも「（自分の点数）ー（相手の点数）」最大化しようとする
    // 前から取るのがいいのか、後ろから取るのがいいのかは、残った数を使ってゲームの結果が分かれば判断できる
    // dp[i][j] := 区間[i,j]が残ってる時の、「次の手番の人の得点ーそうじゃない人の特点」

    cin >> n;
    for(int i=1; i<=n; ++i) cin >> a[i];

    cout << rec(1, n) << endl;

    
    return 0;
}

Measured memory_bytes: 73728
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef double R;
typedef complex<R> P;

const R EPS = 1e-10;
const R PI = acos((R)(-1));

R radNorP(R x) {
    return fmod(fmod(x, 2*PI)+2*PI, 2*PI);
}

const int MN = 330;

P p[MN];
typedef pair<R, int> Pi;

bool solve() {
    int n;
    cin >> n;
    if (!n) return false;

    for (int i = 0; i < n; i++) {
        R x, y;
        cin >> x >> y;
        p[i] = P(x, y);
    }

    int res = 1;
    for (int i = 0; i < n; i++) {
        vector<Pi> v;
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (2.0 < abs(p[j]-p[i])) continue;
            R th = acos(abs(p[j]-p[i])/2.0);
            R l = radNorP(arg(p[j]-p[i])-th-EPS);
            R r = radNorP(arg(p[j]-p[i])+th+EPS);
            if (r < l) {
                v.push_back(Pi(l-EPS, 1));
                v.push_back(Pi(2*PI+EPS, -1));
                v.push_back(Pi(0-EPS, 1));
                v.push_back(Pi(r+EPS, -1));
            } else {
                v.push_back(Pi(l-EPS, 1));
                v.push_back(Pi(r+EPS, -1));
            }

        }

        sort(v.begin(), v.end());
        int sm = 1;
        for (Pi p: v) {            
            sm += p.second;
            res = max(res, sm);
        }
    }
    cout << res << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}

Measured memory_bytes: 1404