akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a=[[] for i in range(n)]
for i in range(n-1):
    b=[int(j)-1 for j in input().split()]
    a[b[0]].append(b[1])
    a[b[1]].append(b[0])
def dfs(v):
    d=[-1 for i in range(n)]
    q=[]
    d[v]=0
    q.append(v)
    while len(q):
        v=q.pop()
        for i in a[v]:
            if d[i]==-1:
                d[i]=d[v]+1
                q.append(i)
    return d
c1=dfs(0)
c2=dfs(n-1)
c=0
for i in range(n):
    if c1[i]>c2[i]:
        c+=1
if c>=n/2:
    print("Snuke")
else:
    print("Fennec")

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

int main(void)
{
  int len,i,a,z,ans;
  char str[200001];
  scanf("%s",str);
  len = strlen(str);
  for(i=0;i<len;i++)
    {
      if(str[i] == 'A')
	{
	  a = i;
	  break;
	}
    }
  for(i=len;i>a;i--)
    {
      if(str[i] == 'Z')
	{
	  z = i;
	  break;
	}
    }
  ans = z-a+1;
  printf("%d\n",ans);
  return 0;
}


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

int main()
{
    long long n,arr[5];
    cin>>n;
    long long min=1000000000000000;
    for(int i=0;i<5;i++)
    {
        cin>>arr[i];
        if(arr[i]<=min)
        min=arr[i];
    }
    if(n<=min)
    {
        cout<<5;
        return 0;
    }
    n-=min;

long long x=ceil((1.0)*n/min)+5;
    cout<<x;
    
   
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#ifdef __debug_leywart
#include<debug/to_string.h>
#else
#define db1(x) ;
#define db2(x,begin,end) ;
#define db3(x) ;
#define db4(x,begin,end) ;
#define dbmat1(x,begin_v,end_v,begin_h,end_h) ;
#define dbmat2(x,begin_v,end_v,begin_h,end_h) ;
#define dbin1(x) ;
#define dbin2(x,begin,end) ;
#define dbtree(x,size) ;
#endif
using namespace std;
#define F first
#define S second
#define int long long

///My functions

//Constants
const int mxn = 3*1e5+5, inf = 1e9+7, mod = 1e9+7;
const long long infLL = 1e18+5;
const double EPS = 1e-9 , PI = acos(-1);

//Structs

//Variables
int n,m,Q,k,a,b,c,sum,ans,MAXans,MINans,sc,pos,acc[mxn],racc[mxn],ar[mxn];
vector<int>v,g[mxn];
bitset<mxn>flag;
bool sol ;
string s;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n ; 
    
    sc = sol = 1 ;
    for( int i = 0 ; i <= n ; i++ ) { 

        cin >> ar[i] ; 
        if( ar[i] > sc ) sol = false ; 

        sc -= ar[i] ;

        acc[i] = sc ; 

        if( i < n ){

            sc = min( infLL , sc * 2 ) ; 

        }


    }

    db2( acc , 0 , n ) 

    if( !sol ) cout << -1 ;
    else{

        sc = 0 ; 
        for( int i = n ; i >= 0 ; i-- ){

            sc += ar[i] ; 
            ans += sc ; 

            sc = min( sc , acc[ i - 1 ] ) ;

        }

        cout << ans ; 

    } 






    return 0;
}
























Measured memory_bytes: 12276
#include <stdio.h>


int main()
{
	int A, B, t = 16, a = 0, b = 0;
    scanf("%d %d", &A, &B);
    while(t > 0){
        if(a < A && t % 2 == 0)
            a++;
        else if(b < B && t % 2 != 0)
            b++;
        t--;
    }
    if(a == A && b == B)
        printf("Yay!\n");
    else
        printf(":(\n");
}



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

using namespace std;

int main(){
    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];

    if(N==1){
        cout << abs(A[0] - W) << endl;
        return 0;
    }

    cout << max( abs(A[N-1]-W), abs(A[N-1] - A[N-2]) ) << endl;

    return 0;
}

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

#define int long long
#define x first
#define y second
#define PII pair<int,int>
#define LL long long
#define pb push_back
#define pqp priority_queue<PII,vector<PII>,greater<PII>>
#define pqi priority_queue<int,vector<int>,greater<int>>
#define PSS pair<string,string>
#define in insert
#define line inline
#define sort(s) sort(s.begin(),s.end());
#define V vector<int>
#define VV vector<V>
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using namespace std;

int dx[]=  {0,-1,0,1,0,0},dy[]= {-1,0,1,0,0,0},dz[] = {0,0,0,0,-1,1};
const int N = 1e5+7;
int sum[N];
int n , m, p;

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = (x<<1) + (x<<3) + (ch^48);
        ch = getchar();
    }
    return x * f;
}

inline void solve()
{
    string s; cin >> s;
    
    for(int i = 0; i < s.size() ;i ++)
    {
        if(s[i] == '?' || s[i] == 'D') cout << 'D';
        else cout << 'P';
    }
    cout << endl;
    
}
signed main()
{
    IOS
    //int _; cin >> _; while(_ --)
    solve();

    return 0;
}


Measured memory_bytes: 3792
#import numpy as np
#import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    A = first_input[0]
    B = first_input[1]
    C = first_input[2]
    K = first_input[3]

    nokori_K = K

    if A>=nokori_K:
        print(nokori_K)
        return
    else:
        if B>=(nokori_K-A):
            print(A)
            return
        else:
            print(A-(nokori_K-A-B))
            return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61716
#MLE注意！ not は使わず !=

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    import math
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = math.pi
    print(2*n*a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65352
#include <stdio.h>

int main(void)
{
    int N,X,T=0;
    int time,count=0;

    scanf("%d %d %d",&N,&X,&T);

    if(N%X==0){
        count=(N/X);
    } else {
        count=(N/X)+1;
    }
    
    time=count*T;
    printf("%d",time);

    return 0;
}


Measured memory_bytes: 1692
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 100000;
const int MOD = 1000000007;
const int NIL = -1;
const double pi = 3.141592653589;
/* global variables */
struct Node {
    int parent,  // parent
        left,    // left child
        right;   // right sibling
};
struct Node T[MAX];

/* function */
void preorder(int u);
void inorder(int u);
void postorder(int u);

/* main */
int main(){

    int n, v, l, r;
    cin >> n;
    for (int i = 0; i < n; i++) {
        T[i].parent = T[i].left = T[i].right = NIL;
    }

    for (int i = 0; i < n; i++) {
        cin >> v >> l >> r;
        if (l != NIL) {
            T[v].left = l;
            T[l].parent = v;
        }
        if (r != NIL) {
            T[v].right = r;
            T[r].parent = v;
        }
    }

    int root;
    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) 
            root = i;
    }

    cout << "Preorder" << '\n'; preorder(root); cout << '\n';
    cout << "Inorder" << '\n'; inorder(root); cout << '\n';
    cout << "Postorder" << '\n'; postorder(root); cout << '\n';

    return 0;
}

void preorder(int u) {
    if (u == NIL) return;
    int l = T[u].left, r = T[u].right;
    cout << ' ' << u;
    preorder(l);
    preorder(r);
}

void inorder(int u){
    if (u == NIL) return;
    int l = T[u].left, r = T[u].right;
    inorder(l);
    cout << ' ' << u;
    inorder(r);
}

void postorder(int u) {
    if (u == NIL) return;
    int l = T[u].left, r = T[u].right;
    postorder(l);
    postorder(r);
    cout << ' ' << u;
}



Measured memory_bytes: 3104
def dfs(v, N, graph, visited):
    visited[v] = True
    for v2 in range(N):
        if graph[v][v2] == False:
            continue
        if visited[v2] == True:
            continue
        dfs(v2, N, graph, visited)

N, M = map(int, input().split())
a, b = [], []
graph = [[False] * N for _ in range(N)]
for i in range(M):
    _a, _b = map(int, input().split())
    a.append(_a - 1), b.append(_b - 1)
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = True

ans = 0

for i in range(M):
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = False
    visited = [False] * N
    dfs(0, N, graph, visited)
    bridge = False
    for j in range(N):
        if visited[j] == False:
            bridge = True
    if bridge:
        ans += 1
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = True

print(ans)


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

struct UnionFind{
  int num;
  vector<int> rs,ps;
  UnionFind(){}
  UnionFind(int n):num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}
  int find(int x){
    return (x==ps[x]?x:ps[x]=find(ps[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(rs[x]<rs[y]) swap(x,y);
    rs[x]+=rs[y];
    ps[y]=x;
    num--;
  }
  int size(int x){
    return rs[find(x)];
  }
  int count() const{
    return num;
  }
};

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> mem(n);
  UnionFind fr(n);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    fr.unite(a, b);
    mem[a]++;
    mem[b]++;
  }
  for(int i=0; i<k; i++){
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    if (fr.same(c, d)){
      mem[c]++;
      mem[d]++;
    }
  }
  for (int i=0; i<n; i++){
    cout << fr.size(i) - mem[i] - 1 << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  string s;
  cin >> s;

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



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

def sum(num):
    if num < 2:
        return 0
    s = 0
    for i in range(num):
        s += i
    return s

x = [0] * (n+1)

for i in range(n):
    x[a[i]] += 1

ans = 0

for i in range(n+1):
    ans += sum(x[i])

for i in range(n):
    ans2 = ans - (x[a[i]]-1)
    print(ans2)



Measured memory_bytes: 24748
def inpl(): return [int(i) for i in input().split()]
class UnionFind():
    def __init__(self, num):
        self.par = [-1 for _ in range(num)]
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)
    
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
            if self.par[rx] > self.par[ry]:
                self.par[rx] = ry
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
        return

N, K, L = inpl()
ufk = UnionFind(N)
for i in range(K):
    p, q = inpl()
    ufk.union(p-1, q-1)

ufr = UnionFind(N)
for i in range(L):
    r, s = inpl()
    ufr.union(r-1, s-1)

from collections import defaultdict
ans = defaultdict(lambda: 0)
for i in range(N):
    ans[ufk.find(i),ufr.find(i)] +=1
Ans = [0 for _ in range(N)]
for i in range(N):
    Ans[i] = ans[ufk.find(i),ufr.find(i)]
print(*Ans)

Measured memory_bytes: 41880
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
using namespace std;

int main() {
	int N;
	cin >> N;
	deque<long int> B;
	int  w;
	cin >> w;
	B.push_front(w);


	if (N % 2 == 0) {
		for (int i = 1; i < N; i++) {
			cin >> w;
			if (i % 2 == 0) {
				
				B.push_back(w);
			}
			else {
				
				B.push_front(w);
			}
		}
	}
	else {
		for (int i = 1; i < N; i++) {
			cin >> w;
			if (i % 2 != 0) {
			
				B.push_back(w);
			}
			else {
				
				B.push_front(w);
			}
		}
	}

	for (int i = 0; i < N;i++) {
		cout << B[i]<<' ';
	}
	return 0;
}


Measured memory_bytes: 3840
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

char conv(int n) {
	if (n < 0) {
		return '?';
	}
	else if (n < 10) {
		return '0' + n;
	}
	else {
		return 'A' + n - 10;
	}
}

int main() {
	int N, M, Q;
	while (cin >> N >> M >> Q, N) {
		vvi table(N, vi(M, 1));

		string S, B;
		vector<bool> isOn(N, false);
		REP(i, Q) {
			cin >> S >> B;
			REP(j, N) {
				if (S[j] == '1') {
					isOn[j] = !isOn[j];
				}
				REP(k, M) {
					if (isOn[j] && (B[k] == '0')) {
						table[j][k] = 0;
					}
					else if (!isOn[j] && (B[k] == '1')) {
						table[j][k] = 0;
					}
				}
			}
		}

		vi ans(M);
		REP(i, M) {
			int num = -1;
			REP(j, N) {
				if (table[j][i] == 1) {
					if (num == -1) {
						num = j;
					}
					else {
						num = -1;
						break;
					}
				}
			}
			ans[i] = num;
		}

		REP(i, M) {
			cout << conv(ans[i]);
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1352
d, n = map(int, input().split())

if d == 0 and n == 100:
    print(101)
elif d == 1 and n == 100:
    print(100**d * (n + 1))
elif d == 2 and n == 100:
    print(100**d * 101)
else:
    print(100**d * n)

Measured memory_bytes: 38256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		var s = Console.ReadLine();
		for (int i = 0; i < s.Length; i += 2)
		{
			Console.Write(s[i]);
		}
		Console.WriteLine();
	}
}

Measured memory_bytes: 13244
#B
n = int(input())
l = list(map(int,input().split()))

cnt = 0

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[k]<l[i]+l[j] and l[i]<l[j]+l[k] and l[j]<l[i]+l[k]:
                if l[i] != l[j] and l[i] != l[k] and l[j] != l[k]:
                    cnt += 1
print(cnt)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int n, m, x; cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  for(int i=0; i<n; i++) {
    cin >> c[i];
    for(int j=0; j<m; j++) cin >> a[i][j];
  }

  int ans = 1e9;
  for (int i=0; i<(1 << n); i++) {
    int tmp = 0;
    vector<int> xx(m, 0);
    for(int j=0; j<n; j++) {
      if ((i & (1 << j)) == (1 << j)) {
        tmp += c[j];
        for(int k=0; k<m; k++) {
          xx[k] += a[j][k];
        }
      }
    }
    bool f = true;
    for(int j=0; j<m; j++) {
      if (xx[j] >= x) continue;
      else f = false;
    }
    if (f) ans = min(tmp, ans);
  }
  cout << (ans == 1e9 ? -1 : ans) << endl;

  return 0;
}

// EOF

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define POW(n) ((n)*(n))
#define ALL(a) (a).begin(),(a).end()
#define cerr if(false) cerr
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

void solve(string S_A, string S_B, string S_C){
	string str[3] = {S_A,S_B,S_C};
	int c[3] = {};
	int index = 0;
	
	while(true){
		if(c[index] == str[index].length())break;
		index = str[index][c[index]++] - 'a';
	}
	
	cout << (char)('A'+index) << endl;
	return;
}



int main(){	
	ios::sync_with_stdio(false);
	string S_A;
	string S_B;
	string S_C;
	cin >> S_A;
	cin >> S_B;
	cin >> S_C;
	solve(S_A, S_B, S_C);
	return 0;
}


Measured memory_bytes: 256
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);
	  int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
	  List<Integer> l=new ArrayList<>();
	  for(int i=1;i<=Math.min(a, b);i++) {
		  if(a%i==0&&b%i==0)l.add(i);
	  }
	  System.out.println(l.get(l.size()-k));
  }
	public static List<Long> divisorEnum(long n) {
		List<Long> l=new ArrayList<>();
		for(long i=1;i<=Math.sqrt(n);i++) {
			if(n%i==0) {
				l.add(i);
				if(i!=Math.sqrt(n))l.add(n/i);
			}
		}
		l.sort(null);
		return l;
	}
}


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

int main(){
	int n, k, i, ans;
  	int sum = 1;
  	cin >> n >> k;
  
  	for(i=0; i<n; i++){
    	if(sum*2 > sum+k){
        	sum += k;
          	ans = sum;
        }else{
        	sum *= 2;
          	ans = sum;
        }
    }
  	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
	int w, h, n, x, y, a;
	scanf("%d%d%d", &w, &h, &n);
	int x1 = 0, x2 = w, y1 = 0, y2 = h;
	for (int i = 0; i < n; i++){
		scanf("%d%d%d", &x, &y, &a);
		switch (a){
		case 1 : if (x > x1) x1 = x; break;
		case 2 : if (x < x2) x2 = x; break;
		case 3 : if (y > y1) y1 = y; break;
		case 4 : if (y < y2) y2 = y; break;
		}
	}
	x = x2-x1;
	y = y2-y1;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	printf("%d\n", x*y);
	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,X;
    cin>>N>>X;
    vi m(N);
    int counter=0;
    rep(i,N) {
        cin>>m.at(i);
        counter+=m.at(i);
    }
    X-=counter;
    sort(all(m));
    int answer=N+X/m.at(0);
    printf("%d",answer);
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
if N[0]==N[1]==N[2] or N[3]==N[1]==N[2]:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 5272
#import math
#import numpy as np
N = int(input())
ans = 0
dp=[[0]*10 for _ in range(10)]

for a in range(1, N+1):
    a_t = int(str(a)[0])
    a_b = int(str(a)[-1])
    dp[a_t][a_b]+=1

for b in range(1,N+1):
    b_t = int(str(b)[0])
    b_b = int(str(b)[-1])
    ans+=dp[b_b][b_t]

print(int(ans))

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<stack>

typedef long long ll;

using namespace std;

int a[110];

int main(){
	ios::sync_with_stdio(false);
	int n;	cin>>n;
	for(int i = 0 ; i<n ; i++){
		cin>>a[i];
	}
	
	int ans = 0;
	for(int i = 0 ; i<n-1 ; i++){
		for(int j = 0 ; j<n-i ; j++){
			if(a[j-1]>a[j]){
				swap(a[j-1] , a[j]);
				ans++;
			}
		}
	}
	
	for(int i = 0 ; i<n ; i++){
		printf("%d%c",a[i],i==n-1?'\n':' ');
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace std;
    using namespace __gnu_pbds; 
    #define lli long long int
    #define fr(i,a,b) for(lli i=a;i<b;i++)
    #define bfr(i,a,b) for(lli i=a;i>=b;i--)
    #define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
    #define tc int t;cin>>t;while(t--)
    #define mod 1000000007LL
    #define mod2 998244353LL
    #define all(vec) vec.begin(),vec.end()  
    #define ld long double
    #define pb push_back

    #define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 


       int main()
    {
                           
             

              
              fio   
             
              lli n,m;
              cin>>n>>m;

              lli a[n+1],b[n+1]={0};
              fr(i,1,n+1)cin>>a[i];


              
              while(m--)

              {
                lli x,y;
                cin>>x>>y;
                
                 b[x]=max(b[x],a[y]);
                 b[y]=max(b[y],a[x]);


              }
              lli sum=0;
              fr(i,1,n+1)if(a[i]>b[i])sum++;
              cout<<sum;

return 0;}

Measured memory_bytes: 5176
N = int(input())
A = [int(i) for i in input().split()]
K = 0
for i in range(N-1):
  if A[i] > A[i+1]:
    S = A[i] - A[i+1]
    # リストの前の最大値を取得して比較しないといけない。
    A[i+1] += S
    K += S
  else:
    pass
print(K)

Measured memory_bytes: 32068
#include<stdio.h>
int main()
{
	int i,n,k,p,r;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&k,&p);
		r=k%p;
		if(r==0){
			r=p;
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 2724
#include <bits/stdc++.h>
using namespace std;
void init(){
cin.tie(0);
cin.sync_with_stdio(0);}

int main(){
init();

int r; cin>>r;
double pi=3.141592654;
double res=2*pi*r;
cout<<fixed<<setprecision(2)<<res;
}

Measured memory_bytes: 3804
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int T = scanner.nextInt();
		double s = 0;
		int num = 0;
		
		s = (T + 0.5) / A;
		int si = (int)s;
		num = si * B;
		
		System.out.println(num);
	}
}


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

void rec(vector<vector<int> > &G, int left, int right) {
    if (right - left <= 1) return;
    int mid = (left + right) / 2;
    for (int i = mid + 1; i < right; ++i) G[mid].push_back(i);
    rec(G, left, mid);
    rec(G, mid, right);
}

vector<vector<int> > make_graph(int N) {
    vector<vector<int> > G(N);
    rec(G, 0, N);
    return G;
}

int main() {
    int N, K; cin >> N >> K;
    auto G = make_graph(N);
    int M = 0;
    for (int i = 0; i < N; ++i) M += G[i].size();
    cout << M << endl;
    for (int i = 0; i < N; ++i) for (auto e : G[i]) cout << i+1 << " " << e+1 << endl;
    
    for (int _ = 0; _ < K; ++_) {
        int left = 0, right = N;
        string res;
        while (true) {
            int mid = (left + right) / 2;
            cout << mid + 1 << endl;
            cin >> res;
            if (res == "Yes") break;
            else if (res == "Near") left = mid;
            else right = mid;
        }
    }
}



Measured memory_bytes: 3300
#!ruby -pl
r=(?A..?Z).to_a
$_=($_.gsub!(/./,Hash[(" ',-.?".chars+r).zip"dggigggieedfigeiefiifdieffiigiii".bytes.map{|i|i-97}.zip("836$D4X-849<.C:+97,18:2;9:/05%&#".bytes.map{|c|c<51?c+109:c-51}).map{|a|"%0*b"%a}])+?0*((100-$_.size)%5)).gsub(/.{5}/,Hash[(0..31).map{|i|"%05b"%[i]}.zip r+" .,-'?".chars])

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

int main(){

  int n, m, a, b, d[1010], t[1010]={}, cnt=0;

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

  for(int i=0;i<n;i++){			 
    if(a<=d[i]){
      t[i]=1;
      cnt++;
    }else break;
  }

  for(int i=n;i>=0;i--){
    if(i==n&&n-cnt>=m) break;
    if(t[i]){
      if(d[i]<=b){
	t[i]=0;
	cnt--;
      }else break;
    }
  }

  cout<<cnt<<endl;
  
  return 0;
}

Measured memory_bytes: 3104
#!/usr/bin/perl
#abc84_d.pl
#Mon Jan  8 20:13:06 2018
#

use warnings;
use strict;

my $q = <STDIN>;
chomp $q;

my $loopnum = $q;

my @l;
my @r;

while ($loopnum > 0){
	my $stdin = <STDIN>;
	chomp $stdin;
	my @temp = split(" ",$stdin);
	push (@l, $temp[0]);
	push (@r, $temp[1]);
	$loopnum--;
}

my %primehash;
$primehash{1} = 0;
my $num = 2;
while ($num <= 100000){
	unless(exists($primehash{$num})){
		$primehash{$num} = 1;
		my $temp = $num * 2;
		while ($temp <= 100000){
			$primehash{$temp} = 0;
			$temp = $temp+$num;
		}
	}
	$num++;
}

my @accum;
$accum[0] = 0;
$accum[1] = 0;
$num = 2;
while ($num <= 100000){
	if($primehash{$num} == 1 && $primehash{int(($num+1)/2)} == 1){
		$accum[$num] = $accum[$num-1] + 1;
	}else{
		$accum[$num] = $accum[$num-1];
	}
	$num++;
}


while ($loopnum <= $#l){
	print $accum[$r[$loopnum]] - $accum[$l[$loopnum] - 1], "\n";
	$loopnum++;
}

Measured memory_bytes: 36352
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    cin >> x;
    ll ans = 0;
    ans = 1000 * (x / 500) + 5 * ((x - 500 * (x / 500)) / 5);
    cout << ans << endl;

    return 0;
}



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

int main(){

  int cnt=0;

  vector<int> vec(3);

  for (int i=0; i<3; i++){
    cin >> vec.at(i);
  }

  sort(vec.begin(),vec.end());

  if (vec.at(0)==5 && vec.at(1)==5 && vec.at(2)==7){
    cnt++;
  }

  if (cnt==1){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    // https://atcoder.jp/contests/abc171/tasks/abc171_a

    class A_171_alphabet
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string a = Console.ReadLine();

            if (Regex.IsMatch(a, @"[A-Z]"))
            {
                Console.WriteLine("A");
            }
            else if (Regex.IsMatch(a, @"[a-z]"))
            {
                Console.WriteLine("a");
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 26752
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

#define LOCAL  1
#define UPLOAD 2

using namespace std;

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int K,X;
    cin >> K >> X;

    for(int i=X-K+1;i<K+X;i++){
        cout << i << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll m,d;
	cin>>m>>d;
	ll ans=0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			ll now1,now2;
			now1=(j%10);
			now2=j/10;
			if(now1<=1||now2<=1){
				continue;
			}
			if(now1*now2==i){
			ans++;	
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
ll inv[5000];
ll beki(ll a, ll b) {
    a %= mod;
    if(b == 0) return 1;
    ll ret = beki(a, b / 2);
    ret = ret * ret % mod;
    if(b & 1) ret = ret * a % mod;
    return ret;
}

ll combination(ll a, ll b) {
    ll ret = 1;
    for(ll i = 1; i <= b; i++) {
        ret *= (a + 1 - i) % mod;
        ret %= mod;
        ret *= inv[i];
        ret %= mod;
    }
    return ret;
}

ll N, D, X;

void solve() {
    ll ans = 0;
    for(ll ng = 0; ng <= D; ng++) {
        ll rest = N - X * ng;
        if(rest < 0) break;
        ll tmp = combination(D, ng);
        tmp *= combination(rest + D - 1, rest);
        tmp %= mod;
        if(ng & 1) ans -= tmp;
        else ans += tmp;
        //cerr << ng << " " << tmp << endl;
    }
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 1; i <= 4000; i++) {
        inv[i] = beki(i, mod - 2);
    }
    while(cin >> N >> D >> X) {
        if(N == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 3124
def examC():
    N = I()
    A = LI()
    d = defaultdict(int)
    for i in A:
        d[i] +=1;d[i-1] +=1; d[i+1] +=1
    ans = max(d.values())
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 20240
#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include <iostream>
#define ll long long
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7;
const double ep = 0.0000000001;
const double pi = 3.14159265359;
ll fact[N], inv[N];
ll fp(ll x, ll y)
{
	if (!y)
		return 1;
	ll res = fp(x, y / 2);
	res = (res*res) % inf;
	if (y & 1)
		return (res*x) % inf;
	return res;
}
void calc()
{
	fact[0] = inv[0] = 1;
	for (int i = 1; i < N; i++)
	{
		fact[i] = (fact[i - 1] * i) % inf;
		inv[i] = fp(fact[i], inf - 2)%inf;
	}
}
ll ncr(ll n, ll r)
{
	return (((fact[n] * inv[n - r]) % inf)*inv[r])%inf;
}
 
	ll n,arr[1000005],sum1=0,k,sum2=0;
int main() {
	calc();
	cin >> n>>k;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	sort(arr, arr + n,greater<ll>());
	for (int i = 0; i < n; ++i) {
	if (n - (i + 1) < k - 1)
			break;
	    ll  p = ((arr[i] % inf) * ((ncr(n - (i + 1), k - 1)) % inf)) % inf;
		sum1=(sum1%inf) +p;
 
	}
	sort(arr, arr + n);
	for (int i = 0; i < n; ++i) {
		if (n -(i+1) < k - 1)
			break;
		sum2 =(sum2%inf) +((arr[i]%inf) * ((ncr(n -(i+1), k - 1))%inf))%inf;
	}

	cout << (sum1 -sum2 + 10ll * inf)%inf;
	return 0;
 
}
 

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

        int[] h = new int[n];
        for(int i = 0; i < n; i++){
            h[i] = sc.nextInt();
        }

        int max = 1;

        for(int i = 0; i < n; i++){
            if(h[i] > max){
                max = h[i];
            } else if(max - h[i] > 1){
                System.out.println("No");
                return;
            }
        }


        System.out.println("Yes");
    }
}

Measured memory_bytes: 50964
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;

int main() {
  int x, y; cin >> x >> y;
  bool exist = false;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      if (i+j == x && 2*i+4*j == y) exist = true;
    }
  }
  if (exist) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n,m,sum = 0,count = 0;
        double d;
        String ans = "No";
        ArrayList<Integer> a = new ArrayList<Integer>();
        n = sc.nextInt();
        m = sc.nextInt();
        
        for(int i = 0; i < n; i++){
            a.add(sc.nextInt());
            sum += a.get(i);
        }
        
        for(int i = 0; i < n; i++){
            if(a.get(i) >= ((double)sum / (double)(4 * m))){
                count++;
            }
        }
        
        if(count >= m){
            ans = "Yes";
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    LL n;cin>>n;

    VVL dp(n+1);
    REP(i,n){
        dp[i].resize(n+1);
    }
    FOR(i,3,n+1){
        dp[0][i]=1;
    }
    

    FOR(i,1,n){
        VL c(n+1);
        FOR(j,1,n+1){
            c[j] = c[j-1] + dp[i-1][j];
        }
        FOR(j,3,n+1){
            dp[i][j] += c[j-3];
            dp[i][j] %= MOD;
        }

        /*
        REP(j,n+1){
            cerr<<dp[i][j]<<" ";
        }
        cerr<<endl;
        */
    }

    LL result = 0;
    REP(i,n){
        result += dp[i][n];
        result %= MOD;
    }

    cout<<result<<endl;
    
	return;
}

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

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

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    bool ok = false;
    cin >> n;
    
    for (int i = 1; i < 10; i++)
        for (int j = 1; j < 10; j++)
            if (i * j == n)
                ok = true;
            
    if (ok)
        cout << "Yes";
    else
        cout << "No";


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    string s;
    cin >> s;

    int n = s.length();
    vint abc(3, 0);
    int a = 0, b = 0, c = 0;
    rep(i, n) {
        if (s[i] == 'a') abc[0]++;
        if (s[i] == 'b') abc[1]++;
        if (s[i] == 'c') abc[2]++;
    }

    sort(all(abc));
    
    yn(abc[2] - abc[0] <= 1);
    return 0;
}

Measured memory_bytes: 512
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ll long long
#define ld long double
#define ii pair<int,int>
#define heap priority_queue
#define all(k) k.begin(),k.end()
#define rall(k) k.rbegin(),k.rend()
#define len(v) ((int)v.size())
#define fa(a,c) for(auto &a:c)
#define endl '\n'


const int P = 2e7+5;
vector<bool> prime(P+1,1);
vector<ll> primes;

void sieve (){
	prime[0]=prime[1]=0;
	for (ll p=2; p*p<=P;p++) if(prime[p]){
		for(ll i=p*p; i<=P; i+=p)
			prime[i]=0; 
	}
	primes.pb(2);
	for(int i=3;i<=P;i+=2)
		if(prime[i])
			primes.push_back(i);
}

bool isprime(ll n){
	if(n<prime.size()) return prime[n];
	for(ll &p:primes){
		if(p*p>n) break;
		if(n%p==0) return 0;
	}
	return 1;
}





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

  int x;
  cin>>x;

  while(!isprime(x)){
    x++;
  }

  cout<<x<<endl;


}


Measured memory_bytes: 21096
import math
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    h.append(int(input()))
def sten(t):
    dh=[]
    for i in range(n):
        if h[i]-t*b>0:
            dh.append(h[i]-t*b)
    aan=0
    for i in range(len(dh)):
        aan+=math.ceil(dh[i]/(a-b))
    if aan<=t:
        return True
    else:
        return False

left = 0
right = int(1e9)
while left < right:
    center = (left + right) // 2
    if sten(center):
        right = center
    else:
        left = center + 1
print(left)

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Edge {
	int to; ll len;
};

ll dist[100005];
vector<Edge> G[100005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; cin >> n;
	rep(i, 1, n) {
		int a, b, c; cin >> a >> b >> c;
		G[a].push_back(Edge { b, c });
		G[b].push_back(Edge { a, c });
	}

	int q; cin >> q;
	int k; cin >> k;

	auto dfs = [&](auto&& dfs, int n, int p = -1) -> void {
		if (p == -1) {
			dist[n] = 0;
		}

		for (const Edge& e : G[n]) if (e.to != p) {
			dist[e.to] = dist[n] + e.len;
			dfs(dfs, e.to, n);
		}
	};
	dfs(dfs, k);

	rep(i, 0, q) {
		int a, b; cin >> a >> b;
		cout << dist[a] + dist[b] << endl;
	}
}



Measured memory_bytes: 13056
q = int(input())
l = []
r = []
for i in range(q):
    x, y = map(int, input().split())
    l += [x]
    r += [y]


def is_2017(x):
    if x % 2 == 0:
        return False
    return is_p[x] and is_p[(x + 1) // 2]

def is_prime(x):
    if x == 1:
        return False
    i = 2
    while i * i <= x:
        if x % i == 0:
            return False
        i += 1
    return True


is_p = [False] * 100000
n_2017 = [0] * 100000

for i in range(1, 100000):
    is_p[i] = is_prime(i)

for i in range(1, 100000):
    if is_2017(i):
        n_2017[i] = n_2017[i - 1] + 1
    else:
        n_2017[i] = n_2017[i - 1]

for i in range(q):
    print(n_2017[r[i]] - n_2017[l[i] - 1])

Measured memory_bytes: 66264
import collections
import math
import numpy as np
#H, W, K = map(int, input().split(' '))
# S = input()
# if S[2] == S[3]:
#     if S[4] == S[5]:
#         print('Yes')
#         exit()
# else:
#     print('No')

S = int(input())
gohyaku, amari = divmod(S, 500)
go, amari = divmod(amari, 5)

print(1000*gohyaku+go*5)


Measured memory_bytes: 21372
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

long long dp[110][110];
const long long INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b){
	if (a > b){
		a = b;
		return true;
	} else {
		return false;
	}
}
	
int main()
{
	int h, w;
	cin >> h >> w;
	char c[h][w];
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++) {
			cin >> c[i][j];
			dp[i][j] = INF;
		}
	}
	dp[0][0] = (c[0][0] == '#');

	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (i > 0){
				chmin(dp[i][j], dp[i-1][j]+(c[i][j] == '#' and c[i-1][j] == '.'));
			}
			if (j > 0){
				chmin(dp[i][j], dp[i][j-1]+(c[i][j] == '#' and c[i][j-1] == '.'));
			}
		}
	}

	cout << dp[h-1][w-1] << endl;
}



Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;

int c[10][10];
int a1, a2, a3, b1, b2, b3;
bool check()
{
	if (a2 + b2 == c[2][2] && a2 + b3 == c[2][3] && a3 + b2 == c[3][2] && a3 + b3 == c[3][3])
		return 1;
	return 0;
}

int main()
{
	int sum = 0;
	for(int i=1;i<=3;i++)
		for (int j = 1;j <= 3;j++)
		{
			scanf("%d", &c[i][j]);
			sum += c[i][j];
		}
	if (sum % 3)
	{
		puts("No");
		return 0;
	}
	
	a1 = c[1][1];
	a2 = c[2][1];
	a3 = c[3][1];
	b2 = c[1][2] - a1;
	b3 = c[1][3] - a1;
	if (check())
		puts("Yes");
	else
		puts("No");
}

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

using namespace std;

const int MOD = 1e9+7;

long long fact[(int)1e6+10];

long long bin_pow(long long base, int e){
    long long sol = 1;
    while(e){
        if(e & 1) sol = sol * base % MOD;
        base = base * base % MOD;
        e >>= 1;
    }
    return sol;
}

long long inv_mod(long long x){
    return bin_pow(x, MOD-2);
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int X, Y;
    cin >> X >> Y;

    fact[0] = fact[1] = 1;
    for(int i=2;i<1000010;++i)
        fact[i] = fact[i-1] * i % MOD;

    int n, m;
    if((X + Y) % 3 == 0){
        n = (X+Y)/3;
        if(n <= X and X <= 2*n){
            m = X-n;

            cout << fact[n] * inv_mod(fact[n-m] * fact[m] % MOD) % MOD << '\n';
        }
        else cout << "0\n";
    }else cout << "0\n";

    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

template<int MOD> struct Fp {  
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;

mint mypow(ll a, ll b){
	if(b == 0)return 1;
	if(b % 2 == 0){
		mint t = mypow(a , b/2);
		return t * t;
	}
	mint ret = mypow(a , b - 1) * a;
	return ret;
}

signed main(){
	//cout << fixed << setprecision(10);
	ll n,k; cin >> n >> k;
    ll ans = 0;
    while(n){
        ans++;
        n /= k;
    }
    cout << ans << endl;
	
}

Measured memory_bytes: 3596