akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(void){
	int N, M, P;
	int sum, ans;
	int X[1001];

	while(true){
		cin >> N >> M >> P;
		if(!N && !M && !P)	break;

		sum = 0;
		for(int i = 0; i < N; i++){
			cin >> X[i];
			sum += X[i];
		}

		P = 100 - P;

		if(X[M-1] == 0)	ans = 0;
		else ans = sum * P / X[M-1];

		cout << ans << endl;
	}
  return 0;
}

Measured memory_bytes: 1160
def get_int
  gets.chop.to_i
end

def get_ints
  gets.chop.split.map(&:to_i)
end

def get_double
  gets.chop.to_f
end

def get_str
  gets.chop
end

def get_strs
  gets.chop.split
end

def main
  c = get_str
  alp = ('a'..'z').to_a
  index = alp.index(c) + 1
  puts alp[index]
end

if __FILE__ == $0
  main
end

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

using namespace std;

int main()
{
    long long cnt=0;
    int n,k,arr[200005];
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    if(k>=n)cout<<0<<endl;
    else {
        for(int i=0;i<n-k;i++)cnt+=arr[i];
        cout<<cnt<<endl;
    }

    return 0;
}


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

#define USED 1
#define MADA 0

long long N, T;
long long A[3005];
long long B[3005];
// dp[time][最後注文使用した?]
long long dp[6005][2];

int main(){
	cin >> N >> T;
	for(long long i = 0; i < N; i++){
		cin >> A[i] >> B[i];
	}

	for(long long i = 0; i < 3005; i++){
		dp[i][MADA] = -1;
		dp[i][USED] = -1;
	}

	long long ans = 0;
	dp[0][MADA] = 0;
	for(long long i = 0; i < N; i++){
		long long time = A[i];
		long long happy = B[i];
		for(long long j = T; j >= 0; j--){
			if(dp[j][USED] >= 0){
				//USED -> USED
				dp[j+time][USED] = max(dp[j+time][USED], dp[j][USED] + happy);
				if(j +time < T){
					ans = max(ans, dp[j+time][USED] );
				}
			}
			if(dp[j][MADA] >= 0){
				//MADA -> MADA
				dp[j+ time][MADA] = max(dp[j+ time][MADA], dp[j][MADA] + happy);
				if(j+time < T){
					ans = max(ans, dp[j+ time][MADA]);
				}
				//MADA -> USED
				dp[j][USED] = max(dp[j][USED], dp[j][MADA] + happy);
				if(j < T){
					ans = max(ans, dp[j][USED]);
				}
			}
		}

	}
	//for(long long j = 0; j <= T; j++){
	//	cout << "dp[" << j << "][USED] = " << dp[j][USED] << endl;
	//	cout << "dp[" << j << "][MADA] = " << dp[j][MADA] << endl;
	//}
	cout << ans << endl;
}


Measured memory_bytes: 384
N = int(input())

s = []
for i in range(N):
    s.append(''.join(sorted(input())))

s = sorted(s)

tmp_count = 1
count = 0
for i in range(0, len(s)-1):
    if s[i] == s[i+1]:
        tmp_count += 1
    else:
        count += tmp_count * (tmp_count - 1) // 2
        tmp_count = 1
count += tmp_count * (tmp_count - 1) // 2
print(count)

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

int combination(int n,int r) {
    if(n==1||n==0)return 0;
  if ( r * 2 > n ) r = n - r;
  int dividend = 1;
  int divisor  = 1;
  for (int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }

  return dividend / divisor;
}

int main()
{
    int n;
    int m;
    cin>>n>>m;
    int a=combination(n,2)+combination(m,2);
    cout<<combination(n,2)+combination(m,2)<<endl;
    return 0 ;
}

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
w += 1
s = $<.map(&:bytes)
a = Array.new(h+2) { Array.new(w+2,0) }
hh=Array.new(w+2) { Array.new }

h.times do |i|
	l = 0
	w.times.select { |j| s[i][j] != 46 }.each do |r|
		hh[r] << i
		l.upto(r-1) { |j| a[i][j] = r-l }
		l = r + 1 
	end
end
w.times { |k| hh[k] << h }


hh.each_with_index do |x,i|
	u = 0
	x.each do |d| 
		u.upto(d-1) { |j| a[j][i] += d-u }
		u = d + 1 
	end
end

p a.map(&:max).push(1).max-1


Measured memory_bytes: 123644
def main():
	# n,m = map(int,input().split())
	# n,k = map(int,input().split())
	n = int(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	
	print(int(n**3))


 
if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=0; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

int main()
{
  int n, m, x, y ;
  cin >> n >> m >> x >> y ;
  vector<int> vecx(n+1) ;
  vector<int> vecy(m+1) ;
  vecx.at(n) = x ;
  vecy.at(m) = y ;
  
  REP(i,n){
    cin >> vecx.at(i) ;
  }
  REP(i,m){
    cin >> vecy.at(i) ;
  }
  
  sort(ALL(vecx)) ;
  sort(ALL(vecy)) ;
  
  if(vecx.at(n)<vecy.at(0)){
    cout <<"No War"<<endl ;
  }
  else{
    cout <<"War"<<endl ;
  }

  return 0 ;
}




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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
vector<int> A;

int main()
{
	scanf("%d",&N);
	A.assign(N,0);

	FOR(i,0,N){
		scanf("%d",&A [i]);
		A [i]--;
	}

	int ans = 0;
	{
		int i = 0;
		while(i < N){
			if(A [i] != i){
				i++;
				continue;
			}
			if(i + 1 < N && A [i + 1] == i + 1){
				i += 2;
			}
			else{
				i++;
			}
			ans++;
		}
	}

	printf("%d\n",ans);

	return 0;
}


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

int max(int n, int a[])
{
	int max = 0;
	rep(i, n)
		if (max < a[i])
			max = a[i];
	return max;
}

int		main(void)
{
	int k;
	int n;
	cin >> k >> n;
	int a[k];
	rep(i, n)
		cin >> a[i];
	int ans[k];
	rep(i, n - 1)
		ans[i] = a[i + 1] - a[i];
	ans[n - 1] = a[0];
	ans[n - 1] += k - a[n - 1];
	cout << k - max(n, ans);
	return (0);
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

lli dp[2020][2020];

signed main(){

	lli n,m;
	cin>>n>>m;
	vector<lli> s(n),t(m);
	REP(i,0,n)cin>>s[i];
	REP(i,0,m)cin>>t[i];

	/*sの後ろから見ていく*/
	/*sの最初の文字が出てくるのはいつか*/

	REP(i,0,n+2)dp[i][0]=1;
	REP(j,0,m+2)dp[0][j]=1;

	for(lli i=1;i<=n+1;i++){
		for(lli j=1;j<=m+1;j++){
			dp[i][j] += dp[i-1][j] + dp[i][j-1] + (MOD - dp[i-1][j-1]);
			dp[i][j] %= MOD;
			if(i-1<n && j-1<m && s[i-1] == t[j-1]){
				dp[i+1][j+1]+=dp[i][j];
				dp[i+1][j+1]%=MOD;
			}
		}
	}
	cout<<dp[n+1][m+1]<<endl;
	return 0;
}


Measured memory_bytes: 31872
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=a[0]
point=1
k=1
while point<n-1:
    ans+=2*a[k]
    k+=1
    point+=2
if point>n-1:
    ans-=a[k-1]

print(ans)

Measured memory_bytes: 31676
n = int(input())
S = list(map(int, input().split()))
c = 0


def merge(left, mid, right):
    global c
    L = S[left:mid] + [float('inf')]
    R = S[mid:right] + [float('inf')]
    i, j = 0, 0
    for k in range(left, right):
        if L[i] <= R[j]:
            S[k] = L[i]
            i += 1
        else:
            S[k] = R[j]
            j += 1
    c += right - left


def merge_sort(left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)


merge_sort(0, n)

print(*S)
print(c)



Measured memory_bytes: 61648
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=200050;
int n;
int a[maxn],b[maxn],s[maxn];
inline int erfen(int x){
	int l=1,r=n+1;
	while(l<r){
		int m=(l+r)>>1;
		if(s[m]>=x)r=m;
		else l=m+1;
	}
	return l;
}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(register int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	int ans=0;
	for(register int i=1;i<=29;i++){
		int tmp=(1<<i)-1;
		for(register int j=1;j<=n;j++)s[j]=b[j]&tmp;
		sort(s+1,s+n+1);
		int cnt=0;
		for(register int j=1;j<=n;j++){
			cnt+=n-erfen((1<<(i-1))-(a[j]&tmp))+1;
		}
		for(register int j=1;j<=n;j++){
			cnt-=erfen((1<<i)+(1<<(i-1))-(a[j]&tmp))-erfen((1<<i)-(a[j]&tmp));
		}
		if(cnt&1){
			ans+=(1<<(i-1));
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
using namespace std;
const int MAX = 10;
int w, h;
int vx[] = { 0, 1, 0, -1, 0, };
int vy[] = { 0, 0, 1, 0, -1, };
int field[25][25];

int dfs(int x, int y,int count,int dir){

    if (count == MAX + 1 || (x == 0 || x == w + 1 || y == 0 || y == h + 1)) return MAX + 1;

    if (field[x][y] == 3) return count;

    if (field[x][y] == 0) return dfs(x + vx[dir], y + vy[dir], count, dir);

    int ret = MAX + 1;

    field[x][y] = 0;

    for (int i = 1; i <= 4; i++){

        int nextx = x - vx[dir] + vx[i];
        int nexty = y - vy[dir] + vy[i];

        if (field[nextx][nexty] == 1) continue;

        ret = min(ret, dfs(nextx, nexty, count + 1, i));
    }

    field[x][y] = 1;

    return ret;
}

int main(void){

    while (true){

        cin >> w >> h;

        if (w == 0 && h == 0) break;

        int sx, sy;

        for (int i = 1; i <= h; i++){
            for (int j = 1; j <= w; j++){
                cin >> field[j][i];
                if (field[j][i] == 2){
                    sx = j; sy = i;
                }
            }
        }

        int s = dfs(sx, sy, 0, 0);

        if (s == MAX + 1){
            cout << -1 << endl;
        }
        else{
            cout << s << endl;
        }

    }

}

Measured memory_bytes: 3068
a = gets.chomp.split("").map(&:to_i)
ans = ["-","+"]
for i in 1..8
  combi = []
  3.times do |j|
    combi[j] = i%2
    i /= 2
  end
  temp = a[0]+a[1]*(-1+2*combi[0])+a[2]*(-1+2*combi[1])+a[3]*(-1+2*combi[2])
  if temp == 7
    print a[0],ans[combi[0]],a[1],ans[combi[1]],a[2],ans[combi[2]],a[3],"=7\n"
    exit
  end
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define INF 1e9
#define MAX_V 100
using namespace std;
typedef vector<int> V;
const V zero(51,0);
struct edge{
  int to,rev;
  V cap;
  edge();
  edge(int to,V cap,int rev):to(to),cap(cap),rev(rev){};
};

bool compare (const V &a,const V &b){
  for(int i=a.size()-1;i>=0;i--)if(a[i]!=b[i])return a[i]<b[i];
  return 0;
}
V min(V a,V b){return compare(a,b)? a:b;}

vector<edge> G[MAX_V]; //??°???????????£??\?????????
bool used[MAX_V];      //DFS??§?????§??????????????????????????°
//from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from,int to,V cap){
  G[from].push_back(edge(to,cap,G[to].size()));
  G[to].push_back(edge(from,zero,G[from].size()-1));  
}

void add(V &a,V b){for(int i=0;i<(int)a.size();i++)a[i]+=b[i];}
void sub(V &a,V b){for(int i=0;i<(int)a.size();i++)a[i]-=b[i];}

//?¢?????????????DFS??§??¢???
V dfs(int v,int t,V f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap != zero){
      V d = dfs(e.to ,t , min(f,e.cap));
      if(d != zero){
	sub(e.cap,d);
	add(G[e.to][e.rev].cap,d);
	return d;
      }
    }
  }
  return zero;
}

//s??????t???????????§???????±???????
V max_flow(int s,int t){
  V flow=zero;
  for(;;){
    memset(used,0,sizeof(used));
    V f = dfs(s, t, V(51,1e4));
    if(f == zero)return flow;
    add(flow,f);
  }
}


int StoI(string &a,int &i){
  int res=0;
  while(isdigit(a[i])) res=res*10+a[i++]-'0';
  return res;
}

string ItoS(int a){
  string res;
  while(a) res=char(a%10+'0')+res,a/=10;
  if(res.empty()) res="0";
  return res;
}

V StoV(string s){
  V res(51);
  if(s=="0") return zero;
  for(int i=0;i<s.size();i++){
    int a = max(1,StoI(s,i));
    int L = 0;
    if(s[i]=='x')i+=1+(s[i+1]=='^'),L=max(1,StoI(s,i));
    res[L] = a;
  }
  return res;
}

string VtoS(V a){
  string res;
  for(int i=a.size()-1;i>=0;i--){
    if(a[i]==0)continue;
    if(!res.empty()) res+='+';
    if(a[i]>1||i==0) res+=ItoS(a[i]);
    if(i)res+='x';
    if(i>1) res+='^'+ItoS(i);
  }
  if(res.empty()) res="0";
  return res;
}

int main(){
  while(1){
  int n,m;
  cin>>n>>m;
  if(!n&&!m) return 0;
  for(int i=0;i<MAX_V;i++) G[i].clear();
  for(int i=0,a,b;i<m;i++){
    string c;
    cin>>a>>b>>c;
    V vc = StoV(c);
    add_edge(a-1,b-1,vc);
    add_edge(b-1,a-1,vc);
  }

  V ans = max_flow(0,n-1);
  cout<<VtoS(ans)<<endl;
  }
  return 0;
}

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

void agc021(string n) {
  ll ans = 9 * (n.size() - 1) + (n[0] - '1');
  ll tmp = 0;
  for (int i = 0; i < n.size(); i++) {
    tmp += n[i] - '0';
  }

  ans = max(ans, tmp);

  cout << ans << '\n';
  return;
}

int main() {
  string n;
  cin >> n;
  agc021(n);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<queue>

using namespace std;


//極秘調査

int main() {
	int N, X, Y, Z;
	bool A[100], B[100], C[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		A[i] = false;
		B[i] = false;
		C[i] = false;
	}
	
	cin >> X;
	for (int i = 0; i < X; i++) {
		int tmp;
		cin >> tmp;
		A[tmp-1] = true;
	}

	cin >> Y;
	for (int i = 0; i < Y; i++) {
		int tmp;
		cin >> tmp;
		B[tmp-1] = true;
	}

	cin >> Z;
	for (int i = 0; i < Z; i++) {
		int tmp;
		cin >> tmp;
		C[tmp-1] = true;
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == false && B[i] == false && C[i] == true)
			ans++;
		if (B[i] == true && C[i] == true)
			ans++;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3112
solve n a b
  | a > b = 0
  | (n == 1) && (a == b) = 1
  | (n == 1) && (a /= b) = 0
  | otherwise = (n-2) * (b-a) + 1

main = do
  [n,a,b] <- map read . words <$> getLine :: IO [Int]
  print $ solve n a b 


Measured memory_bytes: 508
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using PLL = pair<LL,LL>;
using VPI = vector<PII>;
using VPL = vector<PLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define RREP(i,m,n) for(int i=(m);i>=(n);i--)

int main(){
  int s,w;
  cin >> s >> w;
  
  if(w >= s){
    cout << "unsafe" << endl;
  }
  else{
    cout << "safe" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3656
// Problem : C - Candies
// Contest : AtCoder Regular Contest 090
// URL : https://atcoder.jp/contests/arc090/tasks/arc090_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define size(x) (int)x.size()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n = 2, m, a[3][N], dp[3][N];

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j] = max(i > 1 ? dp[i - 1][j] : 0, j > 1 ? dp[i][j - 1] : 0);
			dp[i][j] += a[i][j];
		}
	}
	cout << dp[n][m];
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	int n,m; cin>>n>>m;
	VL x(n),y(m); rep(i,n)cin>>x[i]; rep(i,m)cin>>y[i];
	ll xsum=0LL,ysum=0LL;
	rep(i,n){
		xsum+=(2*i-n+1)*x[i]%MOD;
		xsum%=MOD;
	}
	rep(i,m){
		ysum+=(2*i-m+1)*y[i]%MOD;
		ysum%=MOD;
	}
	ll ans=(xsum*ysum)%MOD;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll calc(ll x, ll y)
{
	if(x <= y) return y - x;
	return INF;
}
int main()
{
	ll x, y;
	cin >> x >> y;
	cout << min(min(calc(x, y), calc(-x, y) + 1), min(calc(x, -y) + 1, calc(-x, -y) + 2));
	return 0;
}
	 

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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 int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


int main()
{
	int x, y;
	cin >> x >> y;
	bool ans = false;
	rep(i, 101) {
		rep(j, 101) {
			if (i + j == x && 2 * i + 4 * j == y) {
				ans = true;
				break;
			}
		}
	}
	if (ans) cout << "Yes" << endl;
	else  cout << "No" << endl;
}


Measured memory_bytes: 3608
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val (n, a, b) = br.readLine().split(" ").map { it.toInt() }.toIntArray()
  val ans = Math.min(n * a, b)
  println(ans)
}

Measured memory_bytes: 35764
import heapq


graph = {}
inf = 1

n, m, s = map(int, input().split())

for i in range(m):
    src, nxt, dst = map(int, input().split())
    if src not in graph:
        graph[src] = {}
    graph[src][nxt] = dst
    inf += dst

cost = [inf] * n
cost[s] = 0

heap = []
heapq.heappush(heap, (0, s))

while len(heap) > 0:
    pair = heapq.heappop(heap)
    c, v = pair[0], pair[1]

    if cost[v] < c:
        continue
    if v not in graph:
        continue

    for nxt, dst in graph[v].items():
        if cost[nxt] > cost[v] + dst:
            cost[nxt] = cost[v] + dst
            heapq.heappush(heap, (cost[nxt], nxt))

for c in cost:
    print(c) if c < inf else print('INF')



Measured memory_bytes: 83036
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i;
  int cnt = 0;
  bool a=true;
  if(s[0]!='A') a=false;
  for(i=2;i<=s.size()-2;i++) if(s[i]=='C') cnt++;
  if(cnt!=1) a=false;
  for(i=0;i<s.size();i++){
    if(s[i]=='A' || s[i]=='C') continue;
    else if(s[i]<'a' || s[i]>'z') a=false;
  }
  cout << (a? "AC":"WA") << "\n";
  return 0;
}

Measured memory_bytes: 256
a, b, n = map(int, input().split())
import math
c = math.floor(a*n/b)
d = math.floor(n/b)
e = a*d
f = math.floor(a*(b-1)/b)
g = math.floor((b-1)/b)
h = a*g
if n < b:
  print(c - e)
else:
  print(f - h)

Measured memory_bytes: 9188
#!/usr/bin/env python3

def solve(n,s,t):
  for i in range(n+1):
    if s[i:] == t[:n-i]:
      return len(s[:i]) + n
  return 2*n


def main():
  N = int(input())
  s = input()
  t = input()
  print(solve(N,s,t))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9000
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;

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


P f(int x){
    int a = x%10;
    int b = 0;
    while(x){
        b = x;
        x /= 10;
    }
    return P(a,b);
}

int main(){
    int n;
    cin >> n;
    map<P,int> freq;
    for(int i=1;i<=n;i++){
        P p = f(i);
        freq[p]++;
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        P p = f(i);
        P q(p.second,p.first);
        ans += freq[q];
    }
    cout << ans << endl;
}

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

int main()
{
  int N, A, B;
  int mul;
  
  cin >> N >> A >> B;
  
  mul = N * A;
  
  if (mul >= B)
  {
    cout << B << endl;
  }
  else
  {
    cout << mul << endl;
  }
}


Measured memory_bytes: 3516
from collections import deque
from typing import List


if __name__ == "__main__":
    stack_num, query_num = map(lambda x: int(x), input().split())
    stacks: List[deque] = [deque() for _ in range(stack_num)]

    for _ in range(query_num):
        op, *value = map(lambda x: int(x), input().split())
        if (0 == op):
            stacks[value[0]].appendleft(value[1])
        elif (1 == op):
            stack = stacks[value[0]]
            if (0 != len(stack)):
                print(stack[len(stack) - 1])
        elif (2 == op):
            stack = stacks[value[0]]
            if (0 != len(stack)):
                stack.pop()
        else:
            pass



Measured memory_bytes: 15744
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long h,n,x,sum;
long long div(long long x){
	if(x==1) return x;
	return div(x/2)*2+1;
}
 
int main(){
	cin>>h;
	cout<<div(h);
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto S = readln.chomp;

    int r;
    foreach (i; 0..1000) {
        auto a = i/100;
        auto b = (i/10)%10;
        auto c = i%10;
        int d;
        foreach (j; 0..N) {
            if (d == 0 && S[j] - '0' == a) {
                ++d;
            } else if (d == 1 && S[j] - '0' == b) {
                ++d;
            } else if (d == 2 && S[j] - '0' == c) {
                ++r;
                break;
            }
        }
    }
    writeln(r);
}

Measured memory_bytes: 380
n, k = map(int, input().split())
XY = []
xs = []
ys = []
for i in range(n):
    x, y = map(int, input().split())
    XY.append((x, y))
    xs.append(x)
    ys.append(y)

xs.sort()
ys.sort()
ans = float('inf')
for a in range(n-1):
    for b in range(a+1, n):
        for c in range(n-1):
            for d in range(c+1, n):
                xl = xs[a]
                xr = xs[b]
                yl = ys[c]
                yu = ys[d]
                cnt = 0
                for x, y in XY:
                    if xl <= x <= xr and yl <= y <= yu:
                        cnt += 1
                if cnt >= k:
                    ans = min(ans, (xr-xl)*(yu-yl))
print(ans)


Measured memory_bytes: 48732
def devide(target, step):
    if (target % 2 == 0):
        step += 1
        step = devide(target / 2, step)

    return step


def resolve():
    N = int(input())
    targets = list(map(int, input().split()))
    min_step = 10000
    for i in range(N):
        step = devide(targets[i], 0)
        if(step < min_step):
            min_step = step
    print(min_step)
    
resolve()

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

int main() {
    int a, b, count = 0;
    cin >> a >> b;
    
    // for (int i = a; i <= b; i++)
    // {
    //     cout <<" i = " << i << endl;
    //     cout << i / 10000 << " " << i % 10 << " " << (i / 1000)%10<< " " << (i / 10)%10 << endl;
    // }

    for (int i = a; i <= b; i++)
    {
        if (i / 10000 == i % 10 && (i / 1000) % 10 == (i / 10) % 10) {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int m1=fabs(a-b);
	int m2=fabs(a-c);
	int m3=fabs(b-c);
	int max=0;
	if(max<m1){
		max=m1;
	}
	if(max<m2) max=m2;
	if(max<m3) max=m3;
	printf("%d",max);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int cnt = 1;
    for(int i=0;i<n;i++){
        if(a[i] == cnt){
            cnt++;
        }
    }
    cnt--;
    if(cnt > 0){
        cout << n - cnt << endl;
    }
    else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
double g[100][100],dp[100][100];
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),n||m){
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                scanf("%lf",&g[i][j]);
        
        fill_n(dp[0],100,1.0);
        fill_n(dp[1],9900,0.0);
        for(int i=1;i<m;i++)
            for(int j=0;j<n;j++)
                for(int k=0;k<n;k++)
                    dp[i][j]=max(dp[i][j],dp[i-1][k]*g[k][j]);

        printf("%.2f\n",*max_element(dp[m-1],dp[m-1]+n));
    }
    return 0;
}

Measured memory_bytes: 1248
n = int(input())
result = ""
for i in range(1,n+1):
    if i % 3 == 0 or i % 10 == 3:
        result += " " + str(i)
        continue
    x = i
    while(x):
        if x % 10 == 3:
            result += " " + str(i)
            break
        x //= 10

print(result)

Measured memory_bytes: 7684
def main() :
    S = input()
    N = len(S)

    for i in range(N) :
        if (S[i] != S[-i-1]) :
            print("No")
            return
    
    a = (N-1) // 2
    S1 = S[0:a]
    for i in range(len(S1)) :
        if (S1[i] != S1[-i-1]) :
            print("No")
            return
    
    a = (N+3) // 2
    S2 = S[a-1:]
    for i in range(len(S2)) :
        if (S2[i] != S2[-i-1]) :
            print("No")
            return
    
    print("Yes")
    
            
    


main()

Measured memory_bytes: 3064
import math
N = int(input())
A = sorted(list(map(int,input().split())))

def yakusuu(a):
    P = [a]
    for k in range(2,math.floor(math.sqrt(a))+1):
        if a % k == 0:
            P.append(k)
            P.append(a//k)
    return P

P = set(yakusuu(A[-1])+yakusuu(A[-2]))
ans = 1
for e in P:
    f = 0
    for a in A:
        if a%e != 0:
            f += 1
        if f == 2:
            break
    if f <= 1:
        ans = max(ans,e)
print(ans)


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

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        a[x]++;
    }
    vector<int> b(n + 1, 0);
    for (int i = 0; i <= n; ++i) {
        b[a[i]]++;
    }
    int last = n;
    int s = n;
    for (int k = 1; k <= n; ++k) {
        while (last > s / k) {
            s -= b[last];
            b[last - 1] += b[last];
            last--;
        }
        cout << last << '\n';
    }
    return 0;
}


Measured memory_bytes: 3200
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

const MODULO: usize = 1_000_000_007;

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut r: usize = 0;
    let mut g: usize = 0;
    let mut b: usize = 0;
    let mut ans = 1;
    for _ in 0..n {
        let a: usize = scan(tokens);
        if a == r {
            if a == g {
                if a == b {
                    ans = ans * 3 % MODULO;
                } else {
                    ans = ans * 2 % MODULO;
                }
            }
            r += 1;
        } else if a == g {
            if a == b {
                ans = ans * 2 % MODULO;
            }
            g += 1;
        } else if a == b {
            b += 1;
        } else {
            println!("0");
            return;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        System.out.println(sb.append(s.substring(0, 1)).append(s.length() - 2).append(s.substring(s.length() - 1, s.length())));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
string s;
int main(){
	cin>>n>>s;
	if(n >= 3200) cout << s << endl;
	else cout << "red" << endl;
}

Measured memory_bytes: 256
# 桁DP

n = gets.chomp.split("").map(&:to_i)
k = gets.to_i
length = n.length
# dp[上から i 桁まで][smaller][0 でない数字を使った回数]の出現回数
dp = (length + 1).times.map { 2.times.map { Array.new([length + 1, k + 1].max, 0) } }
# 初期化
# dp[0 桁目まで][桁は不自由][0 でない数字 を 0 回使った]の出現回数は 1 
dp[0][0][0] = 1

# 桁数分ループする（i は遷移元の桁）
length.times do |i|
  # smaller == 1 の場合、以下の桁は自由
  2.times do |smaller|
    # 1 を使った回数ごとに確認する
    length.times do |count|
      # smaller が既に 1 の場合は 10 回ループ、0 の場合は(その桁の数字 + 1）回ループ
      limit = smaller == 1 ? 9 : n[i]
      (limit + 1).times do |d|
        # smaller == 0 且つ d == limit（上限）の時のみ、0 のまま遷移する
        next_smaller = smaller == 0 && d == limit ? 0 : 1
        # d == 0 でない場合は回数を足す
        addition = d == 0 ? 0 : 1
        # 次の桁に遷移する
        dp[i + 1][next_smaller][count + addition] += dp[i][smaller][count]
      end
    end
  end
end

ans = 0
# 桁が自由、不自由ともに、(0 以外を k 回使った出現回数)を ans に足す
2.times do |i|
  ans += dp[length][i][k]
end
puts ans


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.length();
    stack<ll> s;
    REP(i, N) {
        if (s.size() > 0 && s.top() != S[i])
            s.pop();
        else
            s.push(S[i]);
    }

    cout << N - s.size() << endl;

    return 0;
}

Measured memory_bytes: 1232
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import permutations as perm
n = int(readline())
p = tuple(map(int, readline().split()))
q = tuple(map(int, readline().split()))
lst = list(perm(list(range(1, n+1)),n))
lst.sort()
pn=qn=0
for i,j in enumerate(lst, 1):
  if p == j:
    pn = i
  if q == j:
    qn = i
  if pn*qn!=0:
    break
print(abs(pn-qn))

Measured memory_bytes: 8052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.lang.Math;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int D = fs.nextInt(); int T = fs.nextInt(); int S = fs.nextInt();

        double x = 1.0*D/S;
        if (x<=T) {
            System.out.println("Yes");


        } else {
            System.out.println("No");
        }

    }


    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
    }

}


Measured memory_bytes: 32640
import numpy
h, w = map(int, input().split())
ls = [list(input()) for _ in range(h)]
ls = numpy.array(ls)
ls = ls[numpy.any(ls == "#", axis=1), :]
ls = ls[:, numpy.any(ls == "#", axis=0)]
for i in list(ls):
    print("".join(i))


Measured memory_bytes: 13580
x,k,d = map(int,input().split())
if abs(x)//abs(d) >= k:
    print(abs(x)-abs(d)*k)
    exit()

step = abs(x)//abs(d)
y = abs(x)-abs(d)*step
k = k-step

if k%2 == 0:
    print(y)
else:
    print(abs(y-d))

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000007



int main(){
	ios::sync_with_stdio(false);
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int cnt=0;
	while(b<=a){
		b*=2;
		cnt++;
	}
	while(c<=b){
		c*=2;
		cnt++;
	}
	if(cnt>k)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0; 
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

vector<vector<ll>> v(2222);
int mp[2222][2222];
int ans[2222];

void seica(int start){
	vector<ll> d(2222);
	REP(i, 2222)d[i] = INF;
	d[start] = 0;

	priority_queue<P, vector<P>, greater<P>> pq;
	pq.push(MP(0, start));

	while(!pq.empty()){
		auto now = pq.top();pq.pop();
		int node = now.SE;
		int dist = now.FI;
		if(d[node] < dist)continue;
		REP(i, v[node].size()){
			int aite = v[node][i];
			if(d[aite] > dist + 1){
				d[aite] = dist + 1;
				pq.push(MP(d[aite], aite));
			}
		}
	}

	REP(i, 2222)mp[start][i] = d[i];
}

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

	ll n, x, y;cin >> n >> x >> y;
	x--;y--;
	REP(i, n - 1){
		v[i].PB(i+1);
		v[i+1].PB(i);
	}

	v[x].PB(y);
	v[y].PB(x);

	REP(i, n)seica(i);

	REP(i, 2222)REP(j, 2222)if(mp[i][j] != INF)ans[mp[i][j]]++;
	for(int i = 1;i < n;i++)cout << ans[i] / 2 << endl;

	return 0;
}


Measured memory_bytes: 18816
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int A, B, C;
int ans_table[100];
int num = 0;

int main(void) {

	scanf("%d%d%d", &A, &B, &C);
	ans_table[A]++;
	ans_table[B]++;
	ans_table[C]++;

	int i = 0;
	do {
		if (ans_table[i] == 3) {
			break;
		} else {
			if (ans_table[i] == 2) {
				ans_table[i + 1] += 2;
				num++;
			} else {
				if (ans_table[i] == 1) {
					ans_table[i + 2] += 1;
					num++;
				}
			}
		}
	} while (++i);

	printf("%d\n", num);

	return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define ll long long
#define cases ll t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)


int main()
{
    fast;
    ll i,j,n,m,k,ans;
    cin>>n;
    m=n%500;
    n/=500;
    ans=n*1000;
    ans+=(m/5)*5;
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ll mod=1e9+7;
const ld PI = 2 * acos(0.0);
ll m(ll a){ return (a+mod)%mod;}
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
	if(b==0)
		return 1;
	ll d=power(a,b/2,m);
	d=(d*d)%m;
	if(b&1)
		d=(d*a)%m;
	return d;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int n;cin>>n;
	int ans=0;
	map<string,int>mapp;		
	for(int i=0;i<n;i++)	
	{
		string s;cin>>s;
		if(mapp.count(s)==0)
		{
			mapp[s]=1;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

const long long int MOD = 1000000007;

long long int mpow(long long int x, int n)
{
    if(n == 0)
        return 1;

    long long int k = 1;
    while(n > 1)
    {
        if(n % 2 == 1)
        {
            k *= x;
            k %= MOD;
        }
        x *= x;
        x %= MOD;
        n /= 2;

    }
    return (k * x) % MOD;
}

int n, a[101010];

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

    cout << mpow(2, n / 2) << endl;
    
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
using namespace std;

int main()
{
    ll n,t;
    cin>>n>>t;
    vector<ll>adj[n+1];

    ll x,y;
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    ll cnt[n+1] = {0};
    for(ll i=0;i<t;i++)
    {
        cin>>x>>y;
        cnt[x] += y;
    }

    vector<bool>vis(n+1,false);
    queue<pair<ll,ll>>q;
    q.push(mp(1,cnt[1]));

    while(!q.empty())
    {
        ll v = q.front().first;
        ll val = q.front().second;
        q.pop();

        vis[v] = true;
        cnt[v] = val;

        for(auto it:adj[v])
        {
            if(!vis[it])
                q.push(mp(it,val+cnt[it]));
        }
    }

    for(ll i=1;i<=n;i++) cout<<cnt[i]<<" ";

    return 0;
}


Measured memory_bytes: 19568
import java.util.Scanner;

public class Main{
	 public static void main(String[] args) {
		 float result=0;
	        Scanner scan = new Scanner(System.in);
	        float array[]=new float[scan.nextInt()];
	        for(int i=0;i<array.length;i++){
	        	array[i]=scan.nextInt();
	        	result=result+(1/array[i]);
	        }
	      System.out.print(1/result);
	    }
	}

Measured memory_bytes: 22868
#include<stdio.h>
int a[8][8], row[8], col[8], d1[17], d2[17];

int f(int i, int j, int s){
    int i1 = i + (j==7), j1 = (j + 1) % 8;
    if(s == 0)
        return 1;
    if(i > 7)
        return 0;
    if(a[i][j] == 1){
        if(f(i1, j1, s-1))
            return 1;
        return 0;
    }
    if(row[i] == 0 && col[j] == 0 && d1[i + j] == 0 && d2[j - i + 7] == 0){
        a[i][j] = 1;
        row[i] = col[j] = d1[i + j] = d2[j - i + 7] = 1;
        if(f(i1, j1, s-1))
            return 1;
        row[i] = col[j] = d1[i + j] = d2[j - i + 7] = 0;
        a[i][j] = 0;
    }
    if(f(i1, j1, s))
        return 1;
    return 0;
}

int main(){
    int k, i, j, x, y;
    scanf("%d", &k);
    for(i = 1; i <= k; i++){
        scanf("%d %d", &x, &y);
        a[x][y] = 1;
        row[x] = col[y] = d1[x+y] = d2[y - x + 7] = 1;
    }
    f(0, 0, 8);
    for(i = 0; i < 8; i++){
        for(j = 0; j < 8; j++){
            if(a[i][j])
                printf("Q");
            else
                printf(".");
        }
        printf("\n");
    }





}

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

min_cost = 1 << 50
for mask in range(1<<N):
    if bin(mask).count('1') < K:
        continue

    cost = 0
    prev_height = 0
    for i in range(N):
        # not chose this building
        if mask & (1<<i) == 0:
            prev_height = max(prev_height, A[i])
            continue

        # chose this building viewable
        if A[i] <= prev_height:
            cost += prev_height - A[i] + 1
            prev_height += 1
        else:
            prev_height = A[i]
    min_cost = min(min_cost, cost)

print(min_cost)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, dish;
vector< int > cnt( 5, 0 );
int hit[ 310 ][ 310 ][ 310 ];
long double dp[ 310 ][ 310 ][ 310 ];

long double solve( int a, int b, int c )
{
	if( a < 0 || b < 0 || c < 0 || ( a == 0 && b == 0 && c == 0 ) )
	{
		return 0;
	}
	if( hit[ a ][ b ][ c ] != 0 )
	{
		return dp[ a ][ b ][ c ];
	}
	hit[ a ][ b ][ c ] = 1;
	dp[ a ][ b ][ c ] = ( n * 1.0 ) / ( a + b + c ) + a * solve( a - 1, b, c ) / ( a + b + c )
													+ b * solve( a + 1, b - 1, c ) / ( a + b + c )
													+ c * solve( a, b + 1, c - 1 ) / ( a + b + c );
	return dp[ a ][ b ][ c ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	memset( hit, 0, sizeof( hit ) );
	cin >> n;
	for( int i = 1; i <= n; ++i )
	{
		cin >> dish;
		++cnt[ dish ];		
	}
	cout << fixed << setprecision( 25 ) << solve( cnt[ 1 ], cnt[ 2 ], cnt[ 3 ] ) << "\n";
	return 0;
}

Measured memory_bytes: 567808
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 

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

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1110111110111
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair <long long int , pll>              //pair of ll and pair ll 
#define    sp(x)                    setprecision(x)


int32_t main()
{
    speed upp
    int n;
    cin>>n;
    int a[n+5],b[n+5],c[n+5];
    f(i,0,n-1)
        cin>>a[i];
    f(i,0,n-1)
        cin>>b[i];
    f(i,0,n-1)
            c[i]=i+1;
    int h=0,p=1;
    f(i,0,n-1)
    {
        h=(h+(a[i])*p)%mod;
        p=(p*229)%mod;
    }
    int h1=h,h2=0;
    h=0;
    p=1;
    f(i,0,n-1)
    {
        h=(h+(b[i])*p)%mod;
         p=(p*229)%mod;
    }
    
    h2=h;
    
    vector<int>v;
    do { 
        h=0;
        p=1;
        f(i,0,n-1)
        {
            // cout<<c[i]<<"  ";
            h=(h+(c[i])*p)%mod;
             p=(p*229)%mod;
        }
        // cout<<h<<endl;
        v.pb(h);
    } while (next_permutation(c,c + n)); 
    int id1,id2;
    
    f(i,0,v.size()-1)
    {
        if(v[i]==h1)
            id1=i;
        if(v[i]==h2)
            id2=i;
    }
    // cout<<id1<<"   "<<id2<<endl;
    if(id1>id2)
        cout<<id1-id2;
    else
        cout<<id2-id1;
}

Measured memory_bytes: 892
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
n = np.array([i for i in range(A.size)][::-1])
A = A+n
ave = np.median(A)
round = lambda x:int(x*2+1)//2
ave = round(ave)
A = A-ave
A = np.abs(A)
print(A.sum())

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

#define RIGHT '>'
#define LEFT '<'
#define TOP '^'
#define UNDER 'v'
#define LOOP 'l'
#define END '.'
#define MAX 101

int main(){
    char mp[MAX][MAX];
    int n,m;
    
    while(true){
        cin >> n >> m;
        if(!n&&!m) break;
        
        for(int i = 0 ; i < n ; i++)
            for(int j = 0 ; j < m ; j++)
                cin >> mp[i][j];
        
        int x = 0,y = 0;
        while(true){
            if(mp[x][y]==END){
                cout << y << ' ' << x << endl;
                break;
            }
            if(mp[x][y]==LOOP){
                cout << "LOOP" << endl;
                break;
            }
            
            if(mp[x][y]==RIGHT){
                mp[x][y] = LOOP;
                y++;
            }
            else if(mp[x][y]==LEFT){
                mp[x][y] = LOOP;
                y--;
            }
            else if(mp[x][y]==TOP){
                mp[x][y] = LOOP;
                x--;
            }
            else{
                mp[x][y] = LOOP;
                x++;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 1168