akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
A = [*map(int, input().split())]
ng, ok = 0, 10**9 # (ng,ok] = (l,r]
while ok - ng > 1:
    m = (ng + ok) // 2
    c = 0
    for a in A: c += (a - 1) // m
    if c <= k: ok = m
    else: ng = m
print(ok)


Measured memory_bytes: 30840
def main():
    n = int(input())
    As = list(map(int, input().split()))
    cnts = [0]*(10**5+2)
    for a in As:
        cnts[a] += 1
        cnts[a+1] += 1
        cnts[a+2] += 1
    ans = max(cnts)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20828
n = int(input())
dp = [[0 for i in range(3)]for j in range(n+1)]

for i in range(n):
    action = list(map(int,input().split()))
    for j in range(3):
        dp[i+1][j] = max(dp[i][j-1]+action[j],dp[i][j-2]+action[j])
print(max(dp[n]))

Measured memory_bytes: 60124
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    bool ans = true;
    rep(i, s.size()) {
        if (s[i] != t[i]) {
            ans = false;
            break;
        }
    }
    cout << (ans?"Yes":"No") << "\n";
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main (int argc, char const *argv[])
{
    int64_t A, B;
    int64_t ans = 0;

    scanf("%"PRId64"%"PRId64, &A, &B);

    if (A >= 13) {
        printf("%"PRId64"\n", B);
    } else if (A >= 6) {
        printf("%"PRId64"\n", B / 2);
    } else {
        puts("0");
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//b
int main(){
  
  int N, K;
  cin >> N >> K;
  bool a[100] = {};
  rep(i, K){
    int d; cin >> d;
    rep(j, d){
      int A; cin >> A;
      a[A-1] = true;
    }
  }
  int ans = 0;
  rep(i, N) if(a[i] == false) ans++;
  cout << ans << endl;
  
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  int counter = 0;
  
  for(int i=a;i<=b;i++){
    string str = to_string(i);
    if(str[4]==str[0] && str[3]==str[1]){
      counter++;
    }
  }
  cout << counter << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb  push_back
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define endl "\n"
#define inf 1000000007
#define FOR(i, a, b) for(int i=a; i<b; i++)
int dp[5005][5005] = {0};
string s, t, res="";
void solve(){
	cin>>s>>t;
	//reverse(all(s));
	//reverse(all(t));
	dp[0][0] = 0;
	FOR(i, 0, sz(s)+1){
		FOR(j, 0, sz(t)+1){
			if(i==0 || j==0) dp[i][j] = 0;
			else if(s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	int i = sz(s), j = sz(t);
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			res+=s[i-1];
			i--, j--;
		}
		else if(dp[i-1][j]>dp[i][j-1]){
			i--;
		}
		else j--;
	}
	reverse(all(res));
	cout<<" "<<res;
}
signed main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
 
}

Measured memory_bytes: 118400
#include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n,M[N][N];
int d[N];

void bfs(int);

int main() {

  int u,k,v;

  cin >> n;
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) M[i][j] = 0;
  }

  for(int i=0;i<n;i++) {
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;

}

void bfs(int s) {
  
  queue<int> q;
  q.push(s);

  for(int i=0;i<n;i++) d[i] = INFTY;

  d[s] = 0;
  int u;

  while(!q.empty()) {
    u = q.front(); q.pop();
    for(int v=0;v<n;v++) {
      if(M[u][v] == 0) continue;
      if(d[v] != INFTY) continue;
      d[v] = d[u]+1;
      q.push(v);
    }
  }
  for(int i=0;i<n;i++) {
    cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
  }
}

      
			   



Measured memory_bytes: 3136
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0

for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      total = 500*i + 100*j + 50*k
      if total == X:
        ans += 1

print(ans)

Measured memory_bytes: 39664
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type.Int

const val P = 1000000007L

// Find (x, y, r) such that r = gcd(a,b) and ax + by = r.
fun extendedGCD(a: Long, b: Long): Triple<Long, Long, Long> {
  var x0 = 1L
  var y0 = 0L
  var z0 = a
  var x1 = 0L
  var y1 = 1L
  var z1 = b
  while (true) {
    if (z1 == 0L) return Triple(x0, y0, z0)
    val q = z0 / z1
    val x2 = x0 - q * x1
    val y2 = y0 - q * y1
    val z2 = z0 - q * z1
    x0 = x1
    x1 = x2
    y0 = y1
    y1 = y2
    z0 = z1
    z1 = z2
  }
}

fun inverseMod(a: Long, m: Long): Long {
  val (x, y, r) = extendedGCD(a, m)
  if (r != 1L) return 0  // No inverse.

  return (x + m) % m
}

fun timesMod(x: Long, y: Long): Long {
  return x * y % P
}

fun plusMod(x: Long, y: Long): Long {
  return (x + y) % P
}

fun minusMod(x: Long, y: Long): Long {
  return (x - y + P) % P
}

class FiniteField(xRaw: Long) {
  val x = if (xRaw >= 0) xRaw % P else (P - ((-xRaw) % P)) % P
  constructor(xi: Int): this(xi.toLong())
  operator fun plus(o: FiniteField) = FiniteField((x + o.x) % P)
  operator fun plus(o: Int) = this + FiniteField(o)
  operator fun minus(o: FiniteField) = FiniteField((x + P - o.x) % P)
  operator fun minus(o: Int) = this - FiniteField(o)
  operator fun times(o: FiniteField) = FiniteField((x * o.x) % P)
  operator fun times(o: Int) = this * FiniteField(o)
  operator fun div(o: FiniteField) = this * inverseMod(o.x, P).toInt()
  operator fun div(o: Int) = this * FiniteField(o)
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val factorialTable = LongArray(n)
  factorialTable[0] = 1
  for (k in 1..(n - 1)) {
    factorialTable[k] = (factorialTable[k - 1] * k) % P
  }
  val inverseFactorialTable = factorialTable.map { inverseMod(it, P) }.toLongArray()

  val fTable = LongArray(n, { k ->
    if (2 * k < n) 0
    else timesMod(
        timesMod(factorialTable[k], factorialTable[k - 1]), inverseFactorialTable[2 * k - n])
  })

  var ans = 0L
  for (k in 1..(n - 1)) {
    val count = minusMod(fTable[k], fTable[k - 1])
    ans = plusMod(ans, timesMod(count, k.toLong()))
  }
  println(ans)
}

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

/* define const */

/* finish defineing const */

int main()
{
  int k,s;
  cin >> k >> s;

  long cnt = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      if (s-x-y >= 0 && s-x-y <= k) ++cnt;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	int n;
	cin>>n;
	
	long long maxx = 0;
	long long ans=0;
	long long x;
	for (int i=1; i<=n; i++) {
		cin>>x;
		if (x>=maxx) {
			maxx=x;
		} else {
			ans+=(maxx-x);
		}
	}
	
	cout<<ans<<"\n";
	
	return 0;
}


Measured memory_bytes: 3568
#include<iostream>
 #include<vector>
 #include<algorithm>
#include<string.h>
 using namespace std;
 typedef long long ll;
 int dp[100009][13];
 long long int mod = 1000000007;
 char s[100009];
		 
 int main()
 {
	 for (int i = 0; i < 100009; i++)
	 {
		 s[i] = '0';
	 }
	 cin >> s;
	 int length = strlen(s);
	 for (int i = 0; i < 100009; i++)
	 {
		 for (int j = 0; j < 13; j++)
		 {
			 dp[i][j] = 0;
		 }
	 }
	 dp[0][0] = 1;
	 for (int i = 0; i < length; i++)
	 {
		 for (int j = 0; j < 13; j++)
		 {
			 if (s[i] == '?')
			 {
				 for (int k = 0; k < 10; k++)
				 {
					 dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
					 dp[i + 1][(j * 10 + k) % 13] = dp[i + 1][(j * 10 + k) % 13] % mod;
				 }
			 }
			 else
			 {
				 int c = s[i] - '0';
				 dp[i + 1][((j * 10) + c) % 13] += dp[i][j];
			 }
		 }
	 }
	 cout << dp[length][5] << endl;
	 return 0;
 }


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

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = 9;
        int i;
        char[] s = new char[n];
        for (i=0;i<n;i++) {
            s[i] = (char)('0' + scan.nextInt());
        }

        String ans = "123456780";
        int[] d = {-3, 3, -1, 1};

        HashMap<String, Integer> hm = new HashMap<String, Integer>();

        Queue<String> q = new ArrayDeque<String>();
        q.add(toString(s));
        hm.put(toString(s), 0);/*sがキーで０が値*/

        while (!q.isEmpty()) {
            String u = q.remove();/*先頭を取得して削除*/
            if (u.equals(ans)) {
                System.out.println(hm.get(u));
                break;
            }

            StringBuffer str = new StringBuffer(u);
            int zero = str.indexOf("0");/*０が出現する位置のインデックス*/
            for (i=0;i<d.length;i++) {
                if (zero+d[i]>=0 && zero+d[i]<n && !(d[i]==-1 && (zero+d[i])%3==2) && !(d[i]==1 && (zero+d[i])%3==0)) {
                    str.setCharAt(zero, str.charAt(zero + d[i]));/*数字の入れ替え*/
                    str.setCharAt(zero + d[i], '0');
                    if (!hm.containsKey(str.toString())) {/*キーが存在するか*/
                        q.add(str.toString());
                        hm.put(str.toString(), hm.get(u) + 1);
                    }
                    str.setCharAt(zero + d[i], str.charAt(zero));
                    str.setCharAt(zero, '0');
                }
            }
        }
    }

    static String toString(char[] s) {
        String ret = "";
        int i;
        for (i=0;i<s.length;i++) {
            ret += s[i];
        }

        return ret;
    }
}



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

int main(){
	// sengen
	string s;
	// nyuryoku
	cin >> s;
	// keisan
	if(s =="SAT"){
		cout << 1;
	}else if(s == "FRI"){
		cout << 2;
	}else if(s == "THU"){
		cout << 3;
	}else if(s == "WED"){
		cout << 4;
	}else if(s == "TUE"){
		cout << 5;
	}else if(s == "MON"){
		cout << 6;
	}else{
		cout << 7;
	}
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()

using pii=pair<int,int>;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvc=vector<vector<char>>;
using ti3=tuple<int,int,int>;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }


ll solve(int n,int m,int l,int k,int a,int h){
  vector<bool> coldlist(n,false);
  rep(i,l) {
    int li;
    cin >> li;
    coldlist[li]=true;
  }
  //coldlist[h]=true;
  //coldlist[a]=true;

  vector<pii> adj[n];
  rep(i,k){
    int a,b,c;
    cin >> a>>b>>c;
    adj[a].push_back(pii(b,c));
    adj[b].push_back(pii(a,c));
  }

  priority_queue<ti3,vector<ti3>,greater<ti3>> pq;
  pq.push(make_tuple(a,m,0));

  ll dp[101][101]; //dp[i][j]=i番目の街にj分残して到達できる最短時間
  rep(i,101)rep(j,101) dp[i][j]=1e9L;
  dp[a][m]=0;

  while(pq.size()!=0){
    int to,cost,limit;
    tie(to,limit,cost) = pq.top();pq.pop();
    if(dp[to][limit]<cost) continue;

    for(auto e :adj[to]){
      int ct,cc;
      tie(ct,cc)=e;
      if(coldlist[to]){
        //現在地点が回復ポイント
        //m分になるまでt分休む
        rep(t,m+1) if(limit+t<=m){
          auto nl=limit+t-cc;
          if(nl<0) continue;

          auto nc=cc+t+cost;
          if(nc<dp[ct][nl]){
            dp[ct][nl]=nc;
            pq.push(make_tuple(ct,nl,nc));
          }
        }
      }else{
        //回復ポイントでない
        auto nl=limit-cc;
        if(nl<0) continue;
        auto nc=cost+cc;
        if(nc<dp[ct][nl]){
          dp[ct][nl]=nc;
          pq.push(make_tuple(ct,nl,nc));
        }
      }
    }
  }
  ll mm=1e9L;
  rep(i,m) mm=min(mm,dp[h][i]);
  return mm;
}

int main(){
  int N,M,L,K,A,H;
  while(cin >> N >> M >> L>>K>>A>>H,(N|M|L|K|A|H)){
    auto res=solve(N,M,L,K,A,H);
    if(res==1e9L) cout << "Help!" << endl;
    else cout << res << endl;
  }
}



Measured memory_bytes: 4156
n, a, b = (int(i) for i in input().split())

l = []
for i in range(n+1):
    s = str(i)
    sum_ = 0
    for x in s:
        sum_ += int(x)
    
    if a <= sum_ and sum_ <= b:
        l.append(i)

print(sum(l))

Measured memory_bytes: 3296
import array


N,K,Q = list(map(int, input().split()))

A = array.array('i', [0]*N)

for _ in range(Q):
    i = int(input())
    A[i-1] += 1

for i in range(N):
    point = K - Q + A[i]
    if point > 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 50508
INF = 10 ** 10

$memo = {}

def to_key(l)
  l.sort.join('_')
end

def calc_cost(a, b, c, l)
  used = {}
  cost = 0
  [c, b, a].each do |v|
    min_cost = INF
    used_index = nil
    l.each_with_index do |s, i|
      if (s - v).abs < min_cost && !used[i]
        min_cost = (s - v).abs
        used_index = i
      end
    end
    cost += min_cost
    used[used_index] = true
  end
  cost
end

def synthetic_kadomatsu(n, a, b, c, l)
  key = to_key(l)
  return $memo[key] if $memo[key]
  cost = (n - l.size) * 10 + calc_cost(a, b, c, l)
  return cost if l.size == 3 || cost == 0

  0.upto(l.size - 1) do |i|
    l1 = l.dup
    l1.delete_at(i)
    0.upto(l1.size - 1) do |j|
      l2 =  l1.dup
      l2[j] += l[i]
      cost = [cost, synthetic_kadomatsu(n, a, b, c, l2)].min
    end
  end
  $memo[key] = cost
end

n, a, b, c = gets.split.map(&:to_i)
l = []
n.times { l << gets.to_i }

puts synthetic_kadomatsu(n, a, b, c, l)


Measured memory_bytes: 2556
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,a[100005],b[100005],ans=0;
    cin>>n;
    for(int i=0;i<=n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]>=b[i]){
            a[i]-=b[i];
            ans+=b[i];
        }
        else if(a[i]+a[i+1]>=b[i]){
            b[i]-=a[i];
            ans+=a[i];
            a[i]=0;
            a[i+1]-=b[i];
            ans+=b[i];
        }
        else{
            ans+=a[i]+a[i+1];
            a[i]=0;
            a[i+1]=0;
        }
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 5208
/// Zhupengfei 2018
/// Hereby declare: this program is in public domain.

/// Solution for problem: SoundHound C

#include <bits/stdc++.h>

#ifdef LOCAL
#pragma GCC poison printf // To avoid fastio problems
#pragma GCC poison scanf
#endif

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	double n,m,d;
	cin>>n>>m>>d;
	if(d!=0)
		cout<<fixed<<setprecision(20)<<2*(n-d)*(m-1)/(n*n)<<endl;
	else
		cout<<fixed<<setprecision(20)<<(n-d)*(m-1)/(n*n)<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<vector>
#include<utility>
#define INF 0x3f3f3f3f3f3f3f3f
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'

using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
int a[maxn];
int main() {
	ll ans = 0;
	int n;cin >> n;
	for (int i = 1;i <= n;++i) {
		if (i % 3 == 0 || i % 5 == 0)continue;
		else a[i] = i;
	}
	for (int i = 1;i <= n;++i) {
		if (a[i])ans += a[i];
	}
	printf("%lld", ans);
}

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

void init() {
//#if __GLIBCXX__ == 20160609
#ifdef KEK
    freopen("a.in", "r", stdin);
    ///freopen("a.out", "w", stdout);
#else
    ///freopen(TASKNAME".in", "r", stdin);
    ///freopen(TASKNAME".out", "w", stdout);
#endif
}
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const double EPS = 1e-9;
const int INF = (int)1e9 + 41;
const int N = (int)1e6 + 34;


void solve() {
    int n;
    cin >> n;
    int a = 111;
    while (a < n)
        a += 111;
    cout << a << "\n";
}

int main() {
    init();
    solve();

    return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
num1=0
num=[]
for i in range(1,n+1):
    if p[i-1]==i:
        num1+=1
    else:
        if num1!=0:
            num.append(num1)
            num1=0
if num1!=0:
    num.append(num1)
ans=0
for i in range(len(num)):
    ans+=-(num[i]//-2)
print(ans)


Measured memory_bytes: 20580
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main( )
{
	double x1, y1, x2, y2;

	cin>>x1>>y1>>x2>>y2;

	double distance = 0;
	distance = sqrt( pow( ( x1-x2 ), 2 ) + pow( ( y1-y2 ), 2 ) );
	cout<<setprecision(10)<<distance<<endl;
	
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

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


	ans = n * (n-1) / 2 + m * (m -1) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
 
 struct Node{
  int pa;
  int left;
  int right;
};
struct Node T[100001];
int cnt=0;
 int main(void) {
   
  int i,j,n,m,newnode,child,left,right;
   
  scanf("%d",&n);
 
  for(i=0;i<n;i++)
    T[i].pa = T[i].left = T[i].right = NIL;
 
  for(i=0;i<n;i++) {
    scanf("%d%d",&newnode,&m);
    for(j=0;j<m;j++) {
      scanf("%d",&child);
      T[child].pa = newnode;
      if(j != 0) {
    T[left].right = child;
      }
      else {
    T[newnode].left = child;
      }
      left = child;
    }
  }
  for(i=0;i<n;i++) {
    cnt = 0;
    printf("node %d: parent = %d, depth = %d, ",i,T[i].pa,depth(i));
      if(T[i].pa == NIL) {
    printf("root, [");
      }
      else if (T[i].left == NIL) {
    printf("leaf, [");
      } 
      else  {
    printf("internal node, [");
      }   
    cnt=0;
    degree(T[i].left);
    printf("]\n");
  }
  return 0;
}
int depth(int nodeid) {
  if(T[nodeid].pa == NIL) {
    return cnt;
  }
  else {
 cnt++;
 return depth(T[nodeid].pa);
  }
}
 
void degree(int nodeid) {
  if(nodeid != NIL) {
    if(cnt != 0){
      printf(", ");
    }
    printf("%d",nodeid);
    cnt++;
    degree(T[nodeid].right);
  }
} 

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
 
typedef long long ll;

int N;
int x;
ll a[2017];
ll m[2017];

int main2() {
  cin >> N >> x;
  REP(i, N) cin >> a[i];
  REP(i, N) m[i] = a[i];
  ll ans = 1LL << 60;
  for (int k = 0; k < N; k++) {
    ll cur = 0;
    cur += (ll)x * k;
    REP(i, N) cur += m[i];
    chmin(ans, cur);
    REP(i, N) {
      int j = i - (k+1);
      if (j < 0) j += N;
      if (m[i] > a[j]) m[i] = a[j];
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<queue>
using namespace std;
vector<int>G[240]; int dist[240];
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b; string S;
		cin >> a >> S >> b; a--; b--;
		if (S == "wait") { G[a].push_back(b + 120); }
		if (S == "lock") { G[b + 120].push_back(a); }
	}
	int C = 0;
	for (int i = 0; i < 240; i++) {
		queue<int>Q;
		for (int j = 0; j < 240; j++)dist[j] = 0;
		Q.push(i); int cnt = 0;
		while (!Q.empty()) {
			cnt++; int a1 = Q.front(); Q.pop();
			if (cnt >= 100000) { C = 1; break; }
			for (int j = 0; j < G[a1].size(); j++) {
				if (dist[G[a1][j]]>dist[a1] - 1) {
					dist[G[a1][j]] = dist[a1] - 1;
					Q.push(G[a1][j]);
				}
			}
		}
	}
	cout << C << endl;
	return 0;
}

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

int main() {
	int n;
  	cin >>n;
  	string s;
  	cin >>s;
  long int cr=0,cg=0,cb=0,ans=0,count=0;
  
  rep(i,n){
   if(s[i]=='R'){cr++;}
   if(s[i]=='B'){cb++;}
	if(s[i]=='G'){cg++;}
  }
 
  for(long int d;d<=n/2;d++){
  	for(long int i=0;i+2*d<n;i++){
    long int j=i+d,k=i+2*d;
    if(s[i]!=s[j]&&s[k]!=s[j]&&s[i]!=s[k])
    	{count++;}
    }
  } 
  cout<<cb*cr*cg-count<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  string s, t, u;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  cin >> u;
  if (s == u)
    cout << a - 1 << " " << b << endl;
  else
    cout << a << " " << b - 1 << endl;
}

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

int n,m;
int t[128];
map<vector<int>,int> mp;

int rec(vector<int> v){
  if(v.size()<=1)return 0;
  if(mp.count(v)>0)return mp[v];

  int res=1e9;
  for(int i=0;i<n;i++){
    vector<int> A,B;
    for(int j=0;j<(int)v.size();j++){
      int id=v[j];
      if(t[id]>>i&1)A.push_back(id);
      else B.push_back(id);
    }
    if(A.empty()||B.empty())continue;
    res=min(res,max(rec(A),rec(B))+1);
  }

  return mp[v]=res;
}

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    mp.clear();
    for(int i=0;i<m;i++){
      t[i]=0;
      string str;
      cin>>str;
      for(int j=0;j<n;j++){
	t[i]*=2;
	t[i]+=(str[j]-'0');
      }
    }
    vector<int> v;
    for(int i=0;i<m;i++)v.push_back(i);
    cout<<rec(v)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3380
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    int ans[100001]; ans[0] = 0;
    int i, j;
    
    int min;
    for(i = 1; i <100001; i++){
        min = ans[i-1];
        for(j = 6; j <=i; j*=6){
            if(ans[i-j] < min) min = ans[i-j];
        }
        for(j = 9; j <=i; j*=9){
            if(ans[i-j] < min) min = ans[i-j];
        }
        ans[i] = min + 1;
    }
    
    cout << ans[n] << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int n,i=0,j=0,temp,count=0;
  scanf("%d",&n);
  int A[n];

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<n;i++){
    for(j=n-1;(j-i)>0;j--){
      if(A[j]<A[j-1]){
	temp=A[j-1];
	A[j-1]=A[j];
	A[j]=temp;
	count++;
      }
    }
  }
    for(i=0;i<(n-1);i++){
      printf("%d ",A[i]);
    }
    printf("%d\n%d\n",A[n-1],count);
    
    return 0;

}



Measured memory_bytes: 2068
n = gets.chop

counts = {} 

for i in 0..3
  if counts[n[i]].nil?
    counts[n[i]] = 1
    next
  end
  counts[n[i]]+=1
end

for i in 0..3
  if counts[n[i]] != 2
    puts "No"
    exit
  end
end

puts "Yes"



Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

using namespace std;

static const uint64_t kRem = 1000000007;

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

	vector<int> ss(n);
	for (auto& s : ss) cin >> s;
	sort(ss.begin(), ss.end());

	vector<vector<uint64_t>> dp(n + 1, vector<uint64_t>(x + 1));
	dp[n][x] = 1;

	for (int i =  0; i < n; i++) {
		int p = n - i - 1;
		for (int c_x = 0; c_x <= x; c_x++) {
			uint64_t c = dp[p + 1][c_x];
			if (c != 0) {
				int c_x_v = c_x % ss[p];
				dp[p][c_x]   += c * p;
				dp[p][c_x_v] += c;
				dp[p][c_x]   %= kRem;
				dp[p][c_x_v] %= kRem;
			}
		}
	}

	uint64_t val = 0;
	for (int c_x = 0; c_x <= x; c_x++) {
		val += dp[0][c_x] * c_x;
		val %= kRem;
	}

	cout << val << endl;

	return 0;
}

Measured memory_bytes: 158592
// author: tarang 
#include<bits/stdc++.h>
#define ll long long
#define endl  '\n'
#define fastio  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD=1000000007;
#define PI acos(-1)
using namespace std;
int vis[1000000+7];
int gcd(int x, int y)
{                     
        return (x==0)? y : gcd(y % x, x);
}
int main(){
    ll d , s , t;
    cin >> d >> s >> t;
    if( s*t >= d) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
ll ncd(ll n,ll d){
    ll x = 1,y=1;
    for(int i=0;i<d;i++){
        x = x*(n-i)%mod;
        y = y*(i+1)%mod;
    }
    return x*modpow(y,mod-2,mod)%mod;
}
int main() {    
    srand(time(NULL));
    for(int j=0;j<14;j++){
    for(int i=0;i<26;i++){
        cout<<i+1<<endl;
    }
    }
    for(int i=0;i<1;i++){

          cout<<rand()%26+1<<endl;  
    }
}
    



Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int ans=1;
    rep(i,n){
        char c;
        cin>>c;
        int ret=(c=='T');
        ans=(!ans)|ret;
    }
    cout<<(ans?'T' : 'F')<<endl;
    
    return 0;
}


Measured memory_bytes: 3100
#pragma warning (disable:4996)
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<cstdlib>
#include<functional>
#define ll long long
using namespace std;
int gcd(int a, int b)//最大公约数
{
	if (b == 0)
		return a;
	return gcd(b, a%b);
}

int main()
{
	int a,b;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		ll d=gcd(a,b);
		printf("%lld %lld\n",d,a/d*b);
	}
	return 0;
}


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

vector<int> sieve(int n) {
	vector<int> res(1, 2);
	vector<bool> prime(n, true);
	for(int i = 3; i < n; i += 2) {
		if(prime[i]) {
			res.push_back(i);
			for(int j = i * 3; j < n; j += i * 2)
				prime[j] = false;
		}
	}

	return res;
}

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

	const int MAX = 1299709;
	vector<int> primes = sieve(MAX + 1);
	for(int k; cin >> k, k;) {
		int idx = lower_bound(primes.begin(), primes.end(), k) - primes.begin();
		if(primes[idx] == k)
			cout << 0 << endl;
		else
			cout << primes[idx] - primes[idx - 1] << endl;
	}

	return EXIT_SUCCESS;
}

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

int main() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e - a > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  vector<int> p;
  for (int i = 11; p.size() < N; i += 5) {
    int flag = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) flag = 0;
    }
    if (flag) p.emplace_back(i);
  }
  for (int i = 0; i < N; i++) {
    cout << p[i] << " \n"[i + 1 == N];
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int S = 0;

	scanf("%d", &S);

	int hour = S / 3600;
	int min =( S % 3600) / 60;
	int sec = S % 60;

	printf("%d:%d:%d\n", hour, min, sec);
	return 0;
}



Measured memory_bytes: 2040
import math
AB = list(map(int, input().split()))

N2min = AB[1] * 10
N2max = AB[1] * 10 + 9

N1min = int(AB[0] * 12.5)
N1max = int((AB[0] + 0.9) * 12.5)
if (N2min <= N1max) and (N1min <= N2max):
    if (N1min < N2min):
        print(N2min)
    else:
        i = 0
        while (int((N1min - i) * 0.08) == AB[0]):
            i += 1
        print(N1min - i + 1)
else:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>

int main(void)
{
    int64_t N;
    std::cin >> N;

    std::vector<double> V(N);

    for (auto& v : V) {
        std::cin >> v;
    }

    std::sort(V.begin(), V.end());

    for (int64_t i = 1; i < V.size(); ++i) {
        V.at(i) = (V.at(i-1) + V.at(i)) / 2;
    }

    std::cout << V.back() << std::endl;

    return 0;
}


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

int main()
{
    long n;
    cin >> n;
    long ans = numeric_limits<long>::max();
    for (long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            long j = n / i;
            ans = min(ans, i + j - 2);            
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int x;
  cin >> x;
  if(x>=30){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int N; cin >> N;
    vi H(N); REP(i, N) cin >> H[i];
    int cnt = 0;
    int maxh = 0;
    REP(i, N){
        if (maxh <= H[i]){
            cnt++;
            maxh = H[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ld long double
using namespace std;
const ld eps = 1e-9;
int main(){
    long long n,k;
    cin >> n >> k;
    vector<ld> a(n);
    for(auto &i: a)cin >> i;
    ld hi = *max_element(a.begin(),a.end());
    ld lo = 0;
    ld ans = hi;
    for(int steps = 0; steps < 100; steps++){
        ld mid = (lo + hi) / 2.0;
        long long req = 0;
        for(auto i: a)req += (long long)(i-eps)/mid;
        if(req <= k)ans = mid,hi = mid;
        else lo = mid;
    }
    cout << (int)ceil(ans);
    return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
#define rep(i,n1) for(int i=0;i<n1;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
#define PI 3.141592653589793
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const ll inf=1000000007;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vector<Pii> v[100001];
int dp[100000][3]={};
ll dp2[300000][60]={};
int main() {
	int n;
	string s;
	cin>>n>>s;
	int r=0;
	rep(i,n-2){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')r++;
	}
	printf("%d",r);
	return 0;
}


Measured memory_bytes: 3072
/*
author:brownsands
       IIITA
       19-04-2019*/
    
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
int A[1000001],B[1000001],n,i,s;

signed main(){
              ios_base::sync_with_stdio(false);
              cin.tie(NULL);
              cout.tie(NULL);
    cin>>n;
    for(i=0;i<n;i++)
    cin>>A[i];
    for(i=0;i<n;i++){
    cin>>B[i];
    if(A[i]>=B[i])
    s+=A[i]-B[i];}
    cout<<s;
           
                     return 0;
}
       


Measured memory_bytes: 2304
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;
ll dp[100100];

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N);
    vector<ll> v(N);
    rep(i,N) cin >> w[i] >> v[i];
    
    rep(i,N) {
        for (int j = W; j>=w[i]; j--) {
                dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
            }
    }

    cout << dp[W] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i] << " "
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
bool isPerfectSquare(long double x) {   
    long double sr = sqrt(x); 
    return ((sr - floor(sr)) == 0); 
} 
bool isPrime(int x){
    for(int i = 2; i * i <= x; ++i){
        if(x % i == 0) return 0;
    }
    return 1;
}
int fun(int n){
    if(n & 1) return 3 * n + 1;
    else return n/2;
}
int32_t main(){
    SPEED;
    int a, b;
    cin >> a >> b;
    if(a > 0 && b > 0){
        cout << "Positive";
        return 0;
    }
    if(a < 0 && b < 0){
        int num = abs(a) - abs(b) + 1;
        if(num & 1) cout << "Negative";
        else cout << "Positive";
        return 0;
    }
    if(a == 0 || b == 0 || a > 0 && b < 0 || b > 0 && a < 0){
        cout << "Zero" ;
        return 0;
    }
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");


int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n;
    cin>>n;
    cout<<3*n*n;
}

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

int main() {
	long long N;
	cin >> N; 
	for (long long n = (long long)sqrt(N);n >= 1;--n) {
		if (0 == N%n) {
			cout <<  n + N/n- 2<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
3
7 12 8

7  12 8
17 12 16

めっちゃ簡単？
4通り*50かな
ああ、2^50ということか
それはTLEだから、重複箇所はまとめるとかDPとか、
0000000
0000001
0000010
0000011
関係してるのってその前後2か所だけ
ああ
A A
B B

ああ、すべての、か、
隣だけではない、として？
0 7 12 8 
0 17 12 16 

7 12 8 =1
7 12 16 = 4
17 12 8 = 4
17 12 16 = 4
24までなら1以上の可能性
25以降は絶対どこかの時間がかぶるから0とか
2^24とか？
とりあえず12以下に集めてみて
3があったら0確定
2なら振り分け
1なら選択
かな
毎回setにいれる？
どうやって全探索しよう
1のやつだけ2通りにわけたい
setに0と24いれといて、隣との差をとる
11いれて13いれて
再帰的に？
2^11*24で余裕
でも頭悪いスマートにできない
ああ、1じゃなかったらとばす、でいいのかな
交互にとるだけは思いつかん

1  2  3
23 22 21
00000
00001
00010
00011
*/
int main(){
  ll N; cin>>N;
  set<ll> S1,S2;
  vector<ll> D(13,0),K(0,0);
  if(N>24){
    cout<<0<<endl;
    return 0;
  }
  rep(i,N){
    ll a; cin>>a;
    D[a]++;
  }
  //NGパターン
  if(D[0]>0 || D[12]>1){
    cout<<0<<endl;
    return 0;
  }
  for(ll i=1; i<12; i++){
    if(D[i]>2){
      cout<<0<<endl;
      return 0;
    }
  }
  //初期いれ
  S1.insert(0);
  S1.insert(24);
  if(D[12]==1) S1.insert(12);
  for(ll i=1; i<12; i++){
    if(D[i]==1) K.emplace_back(i);
    if(D[i]==2){
      S1.insert(i);
      S1.insert(24-i);
    }
  }
  ll ksz=K.size(), n=(1LL<<ksz), ans=0;
  for(ll i=0; i<n; i++){
    S2=S1;//初期化
    for(ll j=0; j<ksz; j++){
      if((i&(1<<j))==0) S2.insert(K[j]);
      else S2.insert(24-K[j]);
    }
    ll tmp=100, pre=-100;
    for(auto v: S2){
      tmp=min(tmp,v-pre);
      pre=v;
//cout<<v<<" ";
    }    
    ans=max(ans,tmp);
//printf("i:%d, ans:%d\n",i,ans);
  }
  if(ans==24) ans=0;
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
N=int(input())
line=input()
line=line.rstrip().split(" ")

list1=[]
for i in range(N):
    list1.append(int(line[i]))

count=0
i=0
for i in range(N):
    
    j=0
    for j in range(50):
        if list1[i]%2==0:
            count=count+1
            list1[i]=int(list1[i]/2)
        else:
            break
        
print(count)

Measured memory_bytes: 4148
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
long long int mod = 1e9 + 7;
long long int  n,m;
long long int a[200005];
bool cmp(int x, int y)
{
	return abs(x) < abs(y);
}
int main()
{
	int pn=0 ,nn = 0;
	//pn正数，nn负数；
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] >= 0)
			pn++;
		else
			nn++;
	}
	int l=1, r=n;//左右逼近
	long long ans = 1;
	if (!pn && m % 2 == 1)//结果必定为负数
	{
		sort(a + 1, a + 1 + n, cmp);
		for (int i = 1; i <= m; i++) 
			ans = a[i] * ans % mod;
	}
	else
	{
		sort(a + 1, a + 1 + n, greater< int >());
		while (m)
		{
			if (m % 2 == 1)//为奇数就乘大的正数
			{
				ans = ans * a[l] % mod;
				l++, m--;
			}
			else
			{
				if (a[l] * a[l + 1] >= a[r] * a[r - 1])
					//两正数乘起来比负数大
				{
					ans = ans * a[l] % mod * a[l + 1] % mod;
					l += 2,m -= 2;
				}
				else
				{
					ans = ans * a[r - 1] % mod * a[r] % mod;
					r -= 2,m -= 2;
				}
			}

		}
	}
	//防止出现负数，故再加mod再取余数
	cout << (ans % mod + mod) % mod << endl;
}


Measured memory_bytes: 5056
#include <bits/stdc++.h>
#define MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;
const int maxn = 1e5 + 4;
const ll inf = 1e18;

ll a[maxn];

int main (){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	ll tot = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		tot += a[i];
	}
	ll sum = 1ll * n * (n + 1) / 2;
	if (tot % sum != 0)
		return cout << "NO" << endl, 0;
	tot /= sum;
	ll cnt = 0;
	for (int i = 0; i < n; i++) {
		ll k = a[(i + 1) % n] - tot;
		if (a[i] < k)
			return cout << "NO" << endl, 0;
		ll p = a[i] - k;
		if (p % n != 0)
			return cout << "NO" << endl, 0;
		cnt += p / n;
	}
	if (cnt == tot)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;int n,k,st=0,ed;
    cin>>n>>k>>s;
    if(k>30||(1<<(k-1))>=n){
        cout<<string(n,*min_element(s.begin(),s.end()))<<"\n";
        return 0;
    }
    string S=s;
    reverse(S.begin(),S.end());
    string T=s+S;
    for(int i=1;i<n;i++)
        if(T.substr(i,n)<T.substr(st,n))
            st=i;
    for(ed=st;ed-st+1<n&&T[st]==T[ed];ed++);
    for(int i=1;i<=((ed-st)<<(k-1))&&n;i++)cout<<T[st],n--;
    while(n--)cout<<T[ed++];
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<(b); i++)
using namespace std;
const int MAX_N = 7 + 100;
///----------------------------------------------
int l[MAX_N];
int main() {
    ///freopen ( "xx.in"  , "r" , stdin  );
    int n; cin>>n; n<<=1;
    rep(i,0,n) scanf("%d",&l[i]);
    sort(l,l+n);
    int ans=0;
    for (int i=0; i<n; i+=2) ans+=l[i];
    cout << ans;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string L="ABCDEFGHIJKLMNOPQRSTUVWXYZ",A=" ',-.?"+L,C=L+" .,-'?",
	B[]={"101","000000","000011","10010001","010001","000001","100101","10011010",
	"0101","0001","110","01001","10011011","010000","0111","10011000",
	"0110","00100","10011001","10011110","00101","111","10011111","1000",
	"00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
int bin2dec(string s){
	int x=0,i=0;
	for(;i<s.size();i++)x=x*2+s[i]-'0';
	return x;
}
int main(){
	string s,s1;
	int i;
	while(getline(cin,s)){
		s1="";
		for(i=0;i<s.size();i++)s1+=B[A.find(s[i])];
		i=s1.size()%5;
		if(i!=0)s1+=string(5-i,'0');
		s="";
		for(i=0;i<s1.size();i+=5)s+=C[bin2dec(s1.substr(i,5))];
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
using namespace std;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n,k;cin>>n>>k;
    
    map<char,int> score;
    string hand = "spr";
    rep(i,3)cin>>score[hand[i]];
    
    string t;cin>>t;
    vector<string> line(k);
    
    rep(i,n)line[i%k].push_back(t[i]);
    
    int ans = 0;
    
    rep(i,k){
        int len = 1;
        for(int j=1; j<line[i].size(); j++){
            if(line[i][j]==line[i][j-1])
                len++;
            else{
                ans += ((len+1)/2) * score[line[i][j-1]];
                len = 1;
            }
        }
        ans += ((len+1)/2) * score[line[i].back()];
        
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6116
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll  long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define main() int main()
#define ff1(i,n) for(int i=1;i<=n;++i)
#define ff0(i,n) for(int i=0;i<n;++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout<<x<<'\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d",a)
#define pab(a,b) printf("%d%d",a,b)
#define pii pair<int,int>
using namespace std;

#define maxn 200005
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll powmod(ll a,ll b){
    ll ans = 1, pow = a%mod;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans%mod;
}
ull a[maxn];
const ll maxx=1e18;
bool flow(ull a, ull b) {
    if (maxx/a<b) {
        return true;
    }

    return false;
}
main() {
    int n;
    cin>>n;
    int f=1;
    for (int i=0;i<n;i++) {
        cin>>a[i];
        if (a[i]==0) f=0;
    }
    if(f==0){
    	cout<<0<<endl;
    	return 0;
	}
    ll ans=1;
    for (int i=0;i<n;i++) {
        if (flow(ans,a[i])) {
            cout<<"-1"<<endl;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;


}
 

Measured memory_bytes: 4428
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int a, b, k;
    int count = 0;
    cin >> a >> b >> k;

    for (int i = a; i >= 1; i--)
    {
        if (a % i == 0 && b % i == 0)
        {
            count++;
        }
        if (count == k)
        {
            cout << i;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256