akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 ;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll vis[100001]={0};
void dfs(ll node,vector<vector<ll>>&g)
{
  vis[node]=1;
  for(auto x:g[node])
  {
    if(!vis[x]) dfs(x,g);
  }
  return ;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //   #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    //compute();
    //Sieve();
    
   ll tests=1;
 // cin>>tests;
  ll t=1;
    while(tests--)
    {
      ll n,m,i;
      cin>>n>>m;
      vector<ll>a(m);
      for(i=0;i<m;i++) cin>>a[i];
      ll tot=0;
      for(auto x:a) tot+=x;
      if(n-tot<0) cout<<-1;
      else cout<<n-tot;


        t++;
    }
    return 0;
   }

Measured memory_bytes: 14152
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const ull md=1000000007;

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

int main(){
    ull m,n;
    scanf("%llu %llu",&m,&n);
    printf("%lld\n",mod_pow(m,n,md));
    return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
using namespace std;

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

    bool pass = true;

    for (int i = 0; i < N; ++i) {
        int num;
        cin >> num;

        if (num%2 == 0) {
            if (num%3 != 0 && num%5 != 0) {
                pass = false;
                break;
            }
        }
    }

    cout << (pass ? "APPROVED" : "DENIED") << endl;

    return 0;
}

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

int main(void){
  int N,M,a,b;
  cin >> N >> M;
  vector<int> vi(N);
  for(int i=0;i<M;i++){
    cin >> a >> b;
    vi[a-1]++;
    vi[b-1]++;
  }
  for(int i=0;i<N;i++){
    cout << vi[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String line2 = sc.nextLine();
		int totall = Integer.parseInt(line);
		String[] num = line2.split(" ");

		StringBuilder gyaku = new StringBuilder();

		for (int i = totall-1; i >= 0; i--) {
			gyaku.append(num[i]);
			if (i != 0) {
				gyaku.append(" ");

			}
		}

		String reverse = gyaku.toString();
		System.out.println(reverse);

	}

}



Measured memory_bytes: 26136
n_ch = {}
[*"a".."z"].each do |ch|
  n_ch[ch] = 0
end

while gets
  $_.split("").map(&:downcase).each do |ch|
    if n_ch.has_key?(ch)
      n_ch[ch] += 1
    end
  end
end

[*"a".."z"].each do |ch|
  puts "#{ch} : #{n_ch[ch]}"
end



Measured memory_bytes: 6872
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0;i < N;i++) {
        cin >> A.at(i);
    }
    if(A.at(0) != 0) {
        cout << -1 << endl;
    }
    else {
        for(int i = 0;i < N - 1;i++) {
            if(A.at(i + 1) >= A.at(i) + 2) {
                cout << -1 << endl;
                return 0;
            }
        }
        reverse(A.begin(),A.end());
        int ret = 0;
        int cnt = A.at(0);
        int cnt2 = 1;
        for(int i = 1;i < N;i++) {
            if(A.at(i) != cnt - cnt2) {
                ret += cnt;
                cnt = A.at(i);
                cnt2 = 1;
            }
            else {
                cnt2++;
            }
        }
        ret += cnt;
        cout << ret << endl;
    }
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
  long long int n,max = 0,ans = 0;
  cin >> n;
  
  vector<long long int> p(n);
  for(int i = 0; i < n; i++)
  {
    cin >> p[i];
  }
  
  for(int i = 0; i < n; i++)
  {
    if(p[max] < p[i])
    {
      max = i;
    }
  }
  
  p[max] /= 2;
  
  for(int i = 0; i < n; i++)
  {
    ans += p[i];
  }
  
  cout << ans;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>inline void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);	
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************
const int maxn=1e6+5;
int n,m;
int v,x[maxn],rj[maxn][25],lj[maxn][25];
int lx[maxn],rx[maxn];
int mn[maxn];
int main(){
	read(n);read(v);
	rep(i,1,n)read(x[i]);
	while((1<<m)<=v)m++;m++;
	rep2(i,0,m){
		lj[0][i]=1;
		rep(j,1,n)lj[j][i]=(x[j]-x[j-1]<=(v>>i))?lj[j-1][i]:j;
		rj[n+1][i]=n;
		per(j,n,1)rj[j][i]=(x[j+1]-x[j]<=(v>>i))?rj[j+1][i]:j;
	}
	rep2(i,0,1<<m)rx[i]=n+1;
	rep2(i,0,1<<m)rep2(j,0,m)if(!(i&(1<<j))){
		lx[i|(1<<j)]=max(lx[i|(1<<j)],rj[lx[i]+1][j]);
		rx[i|(1<<j)]=min(rx[i|(1<<j)],lj[rx[i]-1][j]);
	}
	rep(i,0,n)mn[i]=n+2;
	rep2(i,0,1<<m)if(!(i&1))mn[lx[i]]=min(mn[lx[i]],rx[((1<<m)-1)^i^1]);
	per(i,n-1,0)mn[i]=min(mn[i],mn[i+1]);
	rep(i,1,n){
		if(mn[lj[i][0]-1]<=rj[i][0]+1)puts("Possible");
		else puts("Impossible");
	}
	return 0;
}

Measured memory_bytes: 56448
import sys; from collections import deque; readline = sys.stdin.readline;

S = readline().rstrip()

L,R, U, D = 'L', 'R', 'U', 'D'

if all(a == R or a == U or a == D for a in S[0::2]) and all(a==L or a==U or a==D for a in S[1::2]):
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int BIT_MAX = 100010;

template <class T> class BIT{
	T x[BIT_MAX + 1];
	
public:
	
	BIT(){
		fill(x,x+BIT_MAX+1,0);
	}
	
	void add(int a , T b){
		++a;
		for(; a <= BIT_MAX ; a += a & -a) x[a] += b;
	}
	
	T get(int a){
		++a;
		T b = 0;
		for(; a > 0 ; a -= a & -a) b += x[a];
		return b;
	}
};

int n,m;
int a[100010];
BIT<LL> bit;

int main(){
	scanf("%d%d%d" , &n , &m , a);
	--a[0];
	LL ans = 0;
	repp(i,1,n){
		scanf("%d" , a+i);
		--a[i];
		ans += (a[i]-a[i-1]+m)%m;
		if((a[i-1]+1)%m==a[i]) continue;
		int x = (a[i-1]+2)%m;
		int y = a[i];
		bit.add(x,1);
		if(x>y){
			bit.add(0,m-x+1);
			bit.add(1,x-m);
		}
		bit.add(y+1,-((y-x+m)%m)-2);
		bit.add(y+2,((y-x+m)%m)+1);
		//printf("%d %d %d\n" , i , x , y);
	}
	LL mx = 0;
	LL z = 0;
	repp(i,0,m){
		z += bit.get(i);
		//printf("  %d\n" , z);
		mx = max(mx,z);
	}
	printf("%lld\n" , ans-mx);
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
        int n;
        cin >> n;
        int a[1000001] = {0};
        int ai;
        for(int i = 0; i < n - 1; i++){
                cin >> ai;
                a[ai]++;
        }
        for(int i = 1; i <= n; i++){
                cout << a[i] << endl;
        }
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char const *argv[]) {
	ll N, A, B; cin >> N >> A >> B;
	ll ans = 2*(A - B) + N * (B - A) + 1;
	cout << (ans > 0 ? ans : 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,i;
	double a[100],b[100],sum=0,res;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf",&a[i]);
		b[i]=1/a[i];
		sum+=b[i];
	}
	res=1/sum;
	printf("%f\n",res);
}

Measured memory_bytes: 128
package main

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

func main() {
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        b, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        c, _ := strconv.Atoi(scanner.Text())
        scanner.Scan()
        d, _ := strconv.Atoi(scanner.Text())

        train := a
        if b < train {
                train = b
        }
        bus := c
        if d < bus {
                bus = d
        }
        fmt.Println(train + bus)
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int H,W,D;cin>>H>>W>>D;
	int a;
	pair<int,int> A[H*W];int score[H*W];
	rep(i,0,H)rep(j,0,W){ cin>>a; A[a-1]={i,j}; }
	rep(i,0,H*W){
		if(i<D) score[i]=0;
		else score[i]=score[i-D]+abs(A[i].first-A[i-D].first)+abs(A[i].second-A[i-D].second);
	}
	int Q;cin>>Q;
	int l,r;
	rep(i,0,Q){
		cin>>l>>r;
		cout<<score[r-1]-score[l-1]<<endl;
	}
}

Measured memory_bytes: 2176
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

int main()
{
    ll m,d;
    cin >> m >> d;
    ll ans=0;
    for(ll i=1;i<=m;i++){
        for(ll j=10;j<=d;j++){
            ll x=j/10;
            ll y=j%10;
            if(x*y==i && x>=2 && y>=2) ans++;
            
        }
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
<?php
// Your code here!
$sum = 0;
$stdin = trim(fgets(STDIN));  
for ($a=1;$a<=$stdin;$a++){
    for ($b=1;$b<=$stdin;$b++){
        $ab = gmp_gcd($a,$b);
        for ($c=1;$c<=$stdin;$c++){
            $sum+=gmp_gcd($ab, $c);  
};
};
};
echo $sum;

Measured memory_bytes: 16352
from math import sin, cos, sqrt, radians
a, b, C = map(int, input().split())
C = radians(C)
S = .5 * a * b * sin(C)
h = b * sin(C)
c = sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(C))
L = a + b + c
print(S)
print(L)
print(h)

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

int main(){
  int n;cin>>n;
  int k;cin>>k;
  string s;cin>>s;
  if(s[k-1]=='A')s[k-1]='a';
  if(s[k-1]=='B')s[k-1]='b';
  if(s[k-1]=='C')s[k-1]='c';
  cout<<s<<endl;
  return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
struct State { string nm; int rx, ry, sx, sy; };
int n, W, H; map<string, vector<State>>M;
int main() {
	while (true) {
		cin >> n; if (n == 0)break; cin >> W >> H; M.clear();
		string R;
		for (int i = 0; i < n; i++) {
			string Y; int p; cin >> Y >> p; if (i == 0)R = Y;
			for (int j = 0; j < p; j++) {
				State ST; cin >> ST.rx >> ST.ry >> ST.sx >> ST.sy >> ST.nm;
				M[Y].push_back(ST);
			}
		}
		int q; cin >> q; vector<string>D; D.push_back(R); int e = 0;
		for (int i = 0; i < q; i++) {
			string W; cin >> W;
			if (W == "show") { cout << D[e] << endl; }
			if (W == "forward") { e = min(e + 1, (int)D.size() - 1); }
			if (W == "back") { e = max(0, e - 1); }
			if (W == "click") {
				int r1, r2; cin >> r1 >> r2;
				for (int j = 0; j < M[D[e]].size(); j++) {
					State Q = M[D[e]][j];
					if (Q.rx <= r1 && r1 <= Q.sx && Q.ry <= r2 && r2 <= Q.sy) {
						while (D.size() > e + 1)D.pop_back();
						D.push_back(Q.nm); e++; break;
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
vector<int> P;
int N, K;

int main() {
    cin >> N >> K;
    P.resize(N);
    rep(i,N) {
        cin >> P.at(i);
    }
    sort(P.begin(), P.end());
    ll sum = 0;
    rep(i, K) sum += P[i];

    cout << sum << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	vi a(n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(all(a));

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			int k = lower_bound(all(a), a[i]+a[j]) - a.begin();
			ans += k - j - 1;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>


using namespace std;
typedef long long ll;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}







int main() {
  int N;
  cin>>N;
  int A=N%10;
  N/=10;
  int B=N%10;
  N/=10;
  int C=N%10;
  N/=10;
  int D=N%10;
  if(A+B+C+D==7){
    printf("%d+%d+%d+%d=7\n",D,C,B,A);
  }else
  if(D+C-B+A==7){
    printf("%d+%d-%d+%d=7\n",D,C,B,A);
  }else
  if(D+C+B-A==7){
    printf("%d+%d+%d-%d=7\n",D,C,B,A);
  }else
  if(D-C+B+A==7){
    printf("%d-%d+%d+%d=7\n",D,C,B,A);
  }
  else
  if(D-C-B+A==7){
    printf("%d-%d-%d+%d=7\n",D,C,B,A);
  }else
  if(D-C+B-A==7){
    printf("%d-%d+%d-%d=7\n",D,C,B,A);
  }else
  if(D+C-B-A==7){
    printf("%d+%d-%d-%d=7\n",D,C,B,A);
  }else
  if(D-C-B-A==7){
    printf("%d+%d+%d+%d=7\n",D,C,B,A);
  } 


  

    


  

  
  
  
  
}


  
  

  



Measured memory_bytes: 256
K = int(input())
A = list(map(int, input().split()))


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N = (N//a)*a

    if N > 2:
        r = m
    else:
        l = m
upper = l


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N = (N//a)*a

    if N < 2:
        l = m
    else:
        r = m
lower = r

if lower > upper:
    print(-1)
else:
    print(lower, upper)


Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5,M=31;
int n,a[N],b[N],c[N],d[N];
int pw[M],x[M];
void init()
{
	pw[0]=x[0]=1;
	for(int i=1;i<M;i++)
		pw[i]=pw[i-1]*2,x[i]=x[i-1]*2+1;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	int res=0;
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	for(int i=1;i<=n;i++)	cin>>b[i];
	
	for(int k=0;k<29;k++)
	{
		for(int i=1;i<=n;i++)	
			c[i]=a[i]&x[k],d[i]=b[i]&x[k];
		sort(c+1,c+1+n);
		sort(d+1,d+1+n);
		int le=n,rg=n,num=0;
		int st=n,ed=n;
		for(int i=1;i<=n;i++)
		{
			// 2^i<=x<2^(i+1)
			while(le>=1&&c[i]+d[le]>=pw[k])
				le--;
			while(rg>=1&&c[i]+d[rg]>=pw[k+1])
				rg--;
			if(rg>le)
				num+=rg-le;
			// 2^i+2^(i+1) < =x < 2^(i+2)
			while(st>=1&&c[i]+d[st]>=pw[k]+pw[k+1])
				st--;
			while(ed>=1&&c[i]+d[ed]>=pw[k+2])
				ed--;
			if(ed>st)
				num+=ed-st;
		}
		if(num%2)
			res+=pw[k];
	}
	cout<<res<<'\n';
	return 0;
}

Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <queue>
#include <unordered_map> 
#include <iomanip>
#include <random>
#include <future>
#include <thread>
#include <utility>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
#define PN 1000000007
typedef long long LL;
#define int long long


//booooooooooooost
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int), 多倍長小数(mp::cpp_dec_float_100)



LL inv_mod(LL a, LL m)
{
	LL b, x, u, q, tmp;

	b = m; x = 1; u = 0;
	while (b > 0) {
		q = a / b;
		tmp = u; u = x - q * u; x = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}

	return (x < 0) ? m + x : x;
}



signed main() {

	int N, W;
	vector<int> w, v;
	cin >> N >> W;
	for (int i = 0; i < N; ++i) {
		int _w, _v;
		cin >> _w >> _v;
		w.push_back(_w); v.push_back(_v);
	}

	vector<pair<int, int>> wv[4];
	for (int i = 0; i < N; ++i) {
		wv[w[i] - w[0]].push_back(pair<int, int>(w[i], v[i]));
	}
	for (int i = 0; i < 4; ++i) {
		sort(wv[i].begin(), wv[i].end(), [](pair<int, int>x, pair<int, int>y){ return x.second > y.second; });
		wv[i].insert(wv[i].begin(), pair<int, int>(0, 0));
		for (int j = 1; j < wv[i].size(); ++j) {
			wv[i][j].first += wv[i][j - 1].first;
			wv[i][j].second += wv[i][j - 1].second;
		}

	}

	int ans = -1;
	for (int i = 0; i < wv[0].size(); ++i) {
		if (W < wv[0][i].first) break;
		for (int j = 0; j < wv[1].size(); ++j) {
			if (W < wv[0][i].first + wv[1][j].first) break;
			for (int k = 0; k < wv[2].size(); ++k) {
				if (W < wv[0][i].first + wv[1][j].first + wv[2][k].first) break;
				for (int l = 0; l < wv[3].size(); ++l) {
					if (W < wv[0][i].first + wv[1][j].first + wv[2][k].first + wv[3][l].first) break;
					ans = max(ans, wv[0][i].second + wv[1][j].second + wv[2][k].second + wv[3][l].second);
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
main()
{
    int n=5,ans;
    int a[6];
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            ans=i;

        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3596
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	r := nextInt()
	if n >= 10 {
		fmt.Println(r)
		return
	}
	fmt.Println(r + 100*(10-n))
}


Measured memory_bytes: 640
/*
          , -- 、
        /;;;;;;', 　　　
        i二二二i
      , ' 　    ヽ ???
     i　ﾉﾉﾉﾉﾉﾍ .', 　　
     〉ﾘi' ﾟ ヮﾟﾉﾚく　 WAyon..........
  ○⊂}〈lﾄ--ｲl〉{つ● 　　
      ,ｒ/ー i-ヽヽ 　　　
     ｀｀i_ﾗi_ﾗ
*/

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int INF=(int)1e12;
const int mod=(int)1e9+7;
#define all(a) (a).begin(),(a).end()
typedef vector<vector<int>> graph;

#define pb push_back

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}



signed main () {
    int n;cin >>n;
    set<string> a;
    rep(i,n){
        string s;cin >>s;
        a.insert(s);
    }
    cout <<a.size()<<endl;
}

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

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

     for(int i = a;i<=b;i++){
       if(c%i==0){
         count++;
       }
     }

     System.out.println(count);

  }
}



Measured memory_bytes: 26356
#include "bits/stdc++.h"
using namespace std;

#define ll long long
ll n,m,x,y,iter=0,ans=0;
vector<ll> a;
vector<pair<int,int>> cb;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>m;
	for(ll i=0;i<n;i++){
		cin>>x;
		a.push_back(x);
		ans+=a[i];
	}
	for(ll i=0;i<m;i++){
		cin>>x>>y;
		cb.push_back(make_pair(y,x));
	}
	sort(a.begin(),a.end()); sort(cb.begin(),cb.end(),greater<pair<int,int>>());
	for(ll i=0;i<n;i++){
		if(a[i] < cb[iter].first){
			ans+=cb[iter].first-a[i];
			cb[iter].second--;
		}
		else
			break;
		if(cb[iter].second==0)
			iter++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2548
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{

    
    string a, b;
    cin >> a >> b;
    cout << b << a << endl;



    return 0;

}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	vector<char>dp;
	int res=0;
	for(char j:s){
		if(dp.empty() || dp.back()==j){
			dp.push_back(j);
		}else{
			res+=2;
			dp.pop_back();
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 640
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

/*
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
*/

int N;
bool rl[100];
bool check[2] = {};
int b = INF, x = INF;
int a, w;

int main() {
	cin >> N;
	REP(i, N) {
		cin >> rl[i];
		check[rl[i]] = true;
	}
	REP(i, N) {
		if (rl[i] == 0)
		{
			cin >> a;
			b = min(b, a);
		}
		else {
			cin >> w;
			x = min(x, w);
		}
	}
	if (!check[0] || !check[1]) {
		cout << 0 << endl;
		return 0;
	}
	
	cout << b + x << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  string s; cin >>s;
  int n = s.size();
  vector<vector<ll>> dp(n+1, vector<ll>(13, 0));
  // dp[i][j] := 先頭からi桁を考えて、13で割った余りがjものの個数
  dp[0][0] = 1;
  rep(i, n){
    // s[i] == '?'なら10個考える
    if (s[i] == '?'){
      rep(j, 13){
        rep(d, 10){
          int nj = (10*j+d)%13;
          dp[i+1][nj] += dp[i][j];
          dp[i+1][nj] %= MOD;
        }
      }
    }else{
      int d = s[i] - '0';
      rep(j, 13){
        int nj = (10*j+d)%13;
        dp[i+1][nj] += dp[i][j];
        dp[i+1][nj] %= MOD;
      }
    }
  }
  ll res = dp[n][5];
  cout <<res <<endl;
}


Measured memory_bytes: 13696
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}
#[allow(unused_imports)]
use input::*;

fn main() {
    let r:usize;
    input!(r);
    p(3*r*r);
}


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

int main()
{
	char lat[26];
	for (int i = 0; i < 26; i++) {
		lat[i] = 'a' + i;
	}
	int n;
	cin >> n;
	string s;
	cin >> s;
	int m = 0;
	for (int i = 1; i < n; i++) {
		int l = 0;
		for (int j = 0; j < 26; j++) {
			bool f, g;
			f = g = false;
			for (int k = 0; k < i; k++) {
				if (s[k] == lat[j]) {
					f = true;
				}
			}
			for (int k = i; k < n; k++) {
				if (s[k] == lat[j]) {
					g = true;
				}
			}
			if (f && g) {
				l++;
			}
		}
		m = max(m, l);
	}
	cout << m << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			ArrayList<Integer> hs = new ArrayList<>();
			ArrayList<Integer> ws = new ArrayList<>();
			ArrayList<Integer> ds = new ArrayList<>();
			for (int i = 1; i <= 150; i++) {
				for (int j = 2; j <= 150; j++) {
					if (i < j) {
						hs.add(i);
						ws.add(j);
						ds.add(i * i + j * j);
					}
				}
			}
			while (true) {
				String s[] = br.readLine().split(" ");
				int h = Integer.parseInt(s[0]);
				int w = Integer.parseInt(s[1]);
				if (h == 0 && w == 0)
					break;
				int d = w * w + h * h;
				int minh = 1000;
				int mind = 100000;
				int minid = 0;
				ArrayList<Integer> okds = new ArrayList<>();
				for (int i = 0; i < ds.size(); i++) {
					if (d <= ds.get(i) && h != hs.get(i)) {
						if (mind == ds.get(i)) {
							okds.add(i);
						} else if (mind > ds.get(i)) {
							if (ds.get(i) == d) {
								if (h < hs.get(i)) {
									okds.clear();
									okds.add(i);
									mind = ds.get(i);
								}
							} else {
								okds.clear();
								okds.add(i);
								mind = ds.get(i);
							}
						}
					}
				}
				for (int i = 0; i < okds.size(); i++) {
					if (mind == d) {
						if (h < hs.get(okds.get(i))) {
							minh = Math.min(minh, hs.get(okds.get(i)));
							if (minh == hs.get(okds.get(i))) {
								minid = okds.get(i);
							}
						}
					} else {
						minh = Math.min(minh, hs.get(okds.get(i)));
						if (minh == hs.get(okds.get(i))) {
							minid = okds.get(i);
						}
					}
				}
				System.out.println(hs.get(minid) + " " + ws.get(minid));
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 30896
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 10000000000000
for i in range(2 ** n):
    res = 0
    cnt = 0
    m = 0
    for j in range(n):
        if (i >> j) & 1:
            cnt += 1
            res += max(m - a[j] + 1, 0)
            m = max(m + 1, a[j])
        else:
            m = max(m, a[j])
    if cnt == k:
        ans = min(ans, res)
print(ans)


Measured memory_bytes: 3064
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = list(map(int,ipt().split()))
    a.sort(reverse=True)
    d = defaultdict(int)
    ans = 0
    for i in a:
        if d[i]:
            ans += 1
            d[i] -= 1
        else:
            nl = len(format(i,"b"))
            d[(i^(2**(nl)-1))+1] += 1

    print(ans)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 56220
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
using ll = long long;
//#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
char alph[]={"abcdefghijklmnopqrstuvwxyz"};
signed main(){
    string s; cin>>s;
    int n=(int)s.length();
    int k; cin>>k;
    map<char,int>mp;
    rep(i,26)mp[alph[i]]=26-i;
    string ans;
    rep(i,n){
        if(mp[s[i]]<=k){
            ans.push_back('a');
            if(s[i]!='a')k-=mp[s[i]];
        }
        else
            ans.push_back(s[i]);
            
    }
    k%=26;
    ans[n-1]=alph[(abs(mp[ans[n-1]]-26)+k)%26];
    cout<<ans<<endl;
    return 0;
}


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

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

    int ac_count = 0;
    int wa_count = 0;
    int tle_count = 0;
    int re_count = 0;
    for (int i = 0; i < n; ++i){
        string s;
        cin >> s;
        if (s=="AC"){
            ac_count+=1;
        }else if(s=="WA"){
            wa_count+=1;
        }else if(s=="TLE"){
            tle_count+=1;
        }else if(s=="RE"){
            re_count+=1;
        }
    }
    cout << "AC x " << ac_count << endl;
    cout << "WA x " << wa_count << endl;
    cout << "TLE x " << tle_count << endl;
    cout << "RE x " << re_count << endl;
}


Measured memory_bytes: 3628
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    string S;
    cin >> N >> S;

    map<char, vector<set<char>>> targets;
    targets['R'].push_back({'G', 'B'});
    targets['R'].push_back({'G'});
    targets['R'].push_back({'B'});
    targets['R'].push_back({});
    targets['G'].push_back({'R', 'B'});
    targets['G'].push_back({'R'});
    targets['G'].push_back({'B'});
    targets['G'].push_back({});
    targets['B'].push_back({'R', 'G'});
    targets['B'].push_back({'R'});
    targets['B'].push_back({'G'});
    targets['B'].push_back({});

    constexpr ll MOD = 998244353;

    ll ans = 1;
    for (ll i = 1; i <= N; i++) {
        (ans *= i) %= MOD;
    }
    map<set<char>, ll> mp;
    mp[{}] = 1;
    for (const char& c : S) {
        for (set<char> target : targets[c]) {
            if (mp[target] > 0) {
                (ans *= mp[target]) %= MOD;
                mp[target]--;
                target.insert(c);
                mp[target]++;
                break;
            }
        }
        mp[{}] = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 900
#include<cstdio>
const int MaxN=110;
int N;
struct edge{int to;edge*next;}E[MaxN*2],*ne=E,*fir[MaxN];
void link(int a,int b){*ne=(edge){b,fir[a]};fir[a]=ne++;}
int dep[MaxN],md[MaxN];
void dfs(int i,int fa){
	int d=0;
	for(edge*e=fir[i];e;e=e->next)if(e->to!=fa){
		dep[e->to]=dep[i]+1;
		dfs(e->to,i);
		d++;
	}
	if(d>md[dep[i]])md[dep[i]]=d;
}
int main(){
	scanf("%d",&N);
	for(int i=1,a,b;i<N;i++)scanf("%d%d",&a,&b),link(a,b),link(b,a);
	int ans1=1<<30;
	long long ans2=0;
	for(int i=1;i<=N;i++){
		dep[i]=0;
		for(int j=0;j<=N;j++)md[j]=0;
		dfs(i,0);
		int maxd=0;
		long long mul=1;
		for(int j=1;j<=N;j++)if(dep[j]>maxd)maxd=dep[j];
		for(int j=0;j<maxd;j++)mul*=md[j];
		if(maxd<ans1||maxd==ans1&&mul<ans2)ans1=maxd,ans2=mul;
	}
	for(int i=1;i<=N;i++)for(edge*e=fir[i];e;e=e->next)if(e->to>i){
		dep[i]=dep[e->to]=0;
		for(int j=0;j<=N;j++)md[j]=0;
		dfs(i,e->to);
		dfs(e->to,i);
		int maxd=0;
		long long mul=2;
		for(int j=1;j<=N;j++)if(dep[j]>maxd)maxd=dep[j];
		for(int j=0;j<maxd;j++)mul*=md[j];
		if(maxd<ans1||maxd==ans1&&mul<ans2)ans1=maxd,ans2=mul;
	}
	printf("%d %lld\n",ans1+1,ans2);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
void sor(vel &v) { sort(v.begin(), v.end()); }
signed main() {
	int p = 998244353;
	int n;
	cin >> n;
	vel a(n);
	int x = -1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	vel qun(n);
	vel qko(n, 0);
	int si = 0;
	qun[0] = a[0];
	qko[0] = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] != qun[si]) si++;
		qun[si] = a[i];
		qko[si]++;
	}
	if (qun[0] == qun[si] and si != 0) {
		qko[0] += qko[si]; si--;
	}
	vel un(si + 1);
	vel ko(si + 1);
	vel po(n, -1);
	for (int i = 0; i <= si; i++) {
		un[i] = qun[i];
		ko[i] = qko[i];
		po[un[i]] = i;
	}
	vel mu = un;
	sor(mu);
	int db = 0;
	for (int i = 0; i < si; i++) {
		if (mu[i] == mu[i + 1]) db = 1;
	}
	int mak1 = mu[si];
	if (db == 1) cout << 0 << endl;
	else {
		int ans = 1;
		vel ah(si + 1, 0);
		int ex = 0;
		if (po[0] == -1) {
			cout << 0 << endl;
			return 0;
		}
		int mes = ko[po[0]];
		for (int i = 0; i < n; i++) {
			int po1 = po[i];
			if (po1 == -1) {
				ans *= ex;
				ans = ans % p;
				ex--;
			}
			else {
				int ko1 = ko[po1];
				if (ko1 > mes) {
					ans = 0;
				}
				int xx = ah[(po1 + 1) % (si + 1)] + ah[(po1 + si) % (si + 1)];
				if (xx == 0) {
					if (ko1 == n) {
						ex = n - 1;
						ans *= n;
						ans = ans % p;
					}
					if (ko1 != mes) {
						ans = 0;
					}
				}
				if (xx == 1) {
					ex += ko1 - 1;
				}
				if (xx == 2) {
					if (i != mak1) {
						ex += ko1 + mes-2;
					}
					else {
						ex = n - i - 1;
					}
					ans *= (mes - ko1 + 1);
					ans = ans % p;
				}
				ah[po1] = 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 18944
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
ll mod=1000000007;

ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}

int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    int ar[n],br[n],p[n];
    forn(i,n)cin>>ar[i];
    forn(i,n)cin>>br[i];
    ll fac=1;
    int co=0;
    p[0]=1;p[1]=2;
    for(int i=2;i<n+1;i++){fac=fac*i;p[i]=i+1;}
    vector<int> vec[fac];
    do {
        //display(a, n);
        for(int i=0;i<n;i++)vec[co].pb(p[i]);
        co++;
    } while (next_permutation(p, p + n));
    sort(vec,vec+fac);
    int in1,in2;
    forn(i,fac){
        int fl1=0,fl2=0;
        forn(j,n){
            if(vec[i][j]==ar[j])fl1++;
            if(vec[i][j]==br[j])fl2++;
        }
        if(fl1==n)in1=i;
        if(fl2==n)in2=i;
    }
    cout<<abs(in1-in2);

	return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int dp[N],a[N],n;

int main()
{
	cin >> n;
	
	for(int i = 1 ; i <= n ; i++)  cin >> a[i] ;
	dp[0] = 0;
	dp[1] = 0;
	
	for(int i = 2 ; i <= n ; i++){
		dp[i] = dp[i-1] + abs(a[i]- a[i-1]) ;
		if(i>2){
			dp[i] = min(dp[i], dp[i-2]+abs(a[i]-a[i-2]));
		}
		
	}
	cout<<dp[n]<<endl;
	
	return 0;
}

Measured memory_bytes: 4348
#include <iostream>

using namespace std; 

int main()
{
    int y, m, d;
    char m1, m2;
    cin >> y >> m1>> m >> m2 >> d;
    if(m <= 4)
        cout << "Heisei" << endl;
    else
    {
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

h,w = inpm()
maze = inplL(h)

ans = 0
for sh in range(h):
    for sw in range(w):
        if maze[sh][sw] == '#':
            continue

        q = queue.Queue()
        q.put((sh,sw,0))

        field = [[-1]*w for i in range(h)]
        tmp = 0
        while not q.empty():
            yy,xx,kk = q.get()
            if field[yy][xx] >= 0: continue

            field[yy][xx] = kk
            if tmp < kk:
                gh,gw = (yy,xx)
                tmp = kk
            if yy != h-1 and maze[yy+1][xx] == '.':
                q.put((yy+1,xx,kk+1))
            if xx != w-1 and  maze[yy][xx+1] == '.':
                q.put((yy,xx+1,kk+1))
            if yy != 0 and  maze[yy-1][xx] == '.':
                q.put((yy-1,xx,kk+1))
            if xx != 0 and  maze[yy][xx-1] == '.':
                q.put((yy,xx-1,kk+1))
        ans = max(ans,field[gh][gw])

print(ans)

Measured memory_bytes: 86536
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, a, b;
    cin >> w >> a >> b;
    int ans = abs(a-b)-w;
    if(ans<=0) {
        ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, x = map(int, input().split())

A = list(map(int, input().split()))

count = 0

while(len(A)) != 1:
    x -= min(A)
    if x < 0:
        break
    A.remove(min(A))
    count += 1
    if len(A) == 1:
        if x - min(A) == 0:
            count += 1

print(count)

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

int main() {
    const double pi = 3.141592653589;
    double r;
    scanf("%lf", &r);
    double area = pi * r * r;
    double cir = 2 * pi * r;
    printf("%lf %lf", area, cir);
}


Measured memory_bytes: 3228
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);
  int n = stdIn.nextInt();
 int k = stdIn.nextInt();
int ans = 1;

for(int i = 0; i < n; i++){
  if(ans*2- ans > k){
       ans += k;
}else{
  ans *=2;
}
}
  System.out.println(ans);
  
}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[100005];
ll cum[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c;
    while(cin>>a>>b>>c)
    {
        ll x=a-b;
        if(x>=c) cout<<0<<endl;
        else cout<<c-x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/* 

	CODE TEMPLATE APRATIM

*/

#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define veci vector<ll>
#define it map<string, vv>::iterator
#define MOD 1000000007
#define N (ll)3e+5
#define test int T;cin>>T;while(T--)
#define nl "\n"
#define FULL(iii) iii.begin(),iii.end()
#define setbit(_) __builtin_popcount(_)
#define INF 9223372036854775807 
#define TOUPR(str) transform(str.begin(), str.end(),str.begin(), ::toupper)
#define TOLWR(str) transform(str.begin(), str.end(),str.begin(), ::tolower)
#define pb push_back
#define len(s) s.length()
#define pb push_back
#define eb emplace_back
#define S second
#define F first
#define len(s) s.length()
#define coutp cout<<setprecision(15)
#define pow(a,b) (ll)(pow(a,b)+0.5)
#define bin(x) stoull(x,0,2)
#define lld long double 
int main()
{
	ll i,d=7,n,f=1,x;
	cin>>n;
	x=n;
	for(i=1;i<=n;i++)
	{
		if(d%x==0)
		{cout<<i,f=0;break;}
		d=(d*10%x)+7;
	}
	if(f)
	cout<<-1<<nl;
}





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

using namespace std;

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

    bool can = true;
    for (int i = 0; i < n; i++) 
    {
        int x;  cin >> x;
        if (x % 2 == 0)
            can &= (x%3 == 0 || x%5 == 0);
    }

    cout << (can ? "APPROVED\n" : "DENIED\n");
    return 0;
}

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

signed  main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin>>k;
    string ans="";
    for(int i=1;i<=k;i++){
        ans+="ACL";
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using ll =long long ;
using namespace std;
int main(){
    int n,k;
    bool hantei=0;
    cin >> n >> k;
    n=n-k;
    if(n<1){
        hantei=1;
    }
    int count=1;
    while(n>0){
        n=n-k+1;
        count++;
    }
    if(hantei){
        cout << 1 <<endl;
    }else{
        cout << count << endl;
    }
}

Measured memory_bytes: 256
//#include <climits>
#include <vector>
#include <algorithm> //std::reverse()
#include <iostream>
#include <stack>
using namespace std;


int main() {
    string input;
    cin >> input;
    int A = input.size();

    int sum = 0;
    stack<int> s1;
    stack<pair<int, int> > s2;

    for (int i = 0; i < input.size(); ++i)
    {
        string c = input.substr(i,1);

        if(c == "\\") {
            s1.push(i);
            continue;
        }

        if(c == "/") {
            if(s1.empty()) {
                continue;
            }

            
            int left = s1.top(); s1.pop();

            int a = i - left; //区間の面積
            sum += a;        //合計面積

            //水たまりを結合
            while(!s2.empty() && left < s2.top().first) {
                a += s2.top().second;
                s2.pop();
            }

            //水たまりの面積を記録
            s2.push(make_pair(left, a));
        }

    }


    //出力
    vector<int> ans;
    while(!s2.empty()) {
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(), ans.end());

    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); ++i)
    {
        cout << " " << ans[i];
    }
    cout << endl;



    return 0;
}


Measured memory_bytes: 3320