akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N; cin >> N;
    vector<int> A(N), B(N), C(N-1);
    for (auto &a : A) cin >> a, a--;
    for (auto &b : B) cin >> b;
    for (auto &c : C) cin >> c;
    Int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += B[A[i]];
        if (i > 0 && A[i-1]+1 == A[i]) ans += C[A[i-1]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
require 'matrix'
x1, y1, x2, y2 = gets.split.map(&:to_i)

v1 = Vector[x1, y1]
v2 = Vector[x2, y2]

v21 = v2 - v1

v32 = Vector[-v21[1], v21[0]]

v3 = v2 + v32
v4 = v3 - v21

puts [v3[0], v3[1], v4[0], v4[1]].join(' ')


Measured memory_bytes: 2684
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
n = int(input())
for _ in range(n):
    (b, f, r, v) = [int(i) for i in input().split()]
    data[b - 1][f - 1][r - 1] += v

for b in range(4):
    for f in range(3):
        for r in range(10):
            print('', data[b][f][r], end='')
        print()
    if b != 3:
        print('#' * 20)

Measured memory_bytes: 7740
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
const long long MOD = 1000000007;
const int MAX = 5000001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];
 
long long power(long long m, long long n){
    long long res = 1;
    while(n > 0){
        if(n & 1) {
            res = (res * m) % MOD;
        }
        m = (m * m) % MOD;
        n >>= 1;
    }
    return res;
}

long long inverse(long long a){
    return power(a, MOD - 2);
}
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long fact_M[500001];
int main(){
  int N;
  int M;
  cin >> N >> M;
  comb_init();
  fact_M[0] = 1;
  for(int i = 1; i <= max(M, N); i++){
    fact_M[i] = (fact_M[i - 1] * i) % MOD;
  }

  long long ans = 0;
  for(int i = 0; i <= N; i++){
    long long tmp = ((fact_M[M - i] * comb(N, i)) % MOD * inverse(fact_M[M - N])) % MOD;
    if(i % 2 == 0){
      ans = (ans + tmp) % MOD;
    } else {
      ans = (ans - tmp + MOD) % MOD;
    }
  }
  cout << ((ans * fact_M[M]) % MOD * inverse(fact_M[M - N])) % MOD << endl;

  



  return 0;
}


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


int main() {
    int N;
    std::cin >> N;
    std::vector<int> sum_weights(N);

    for (int i = 0; i < N; i++) {
        int w;
        std::cin >> w;
        if (i == 0) {
            sum_weights[i] = w;
        } else {
            sum_weights[i] = sum_weights[i - 1] + w;
        }
    }

    int min_diff = sum_weights[N - 1];
    for (int i = 0; i < N - 1; i++) {
        int diff = std::abs((sum_weights[N - 1] - sum_weights[i]) - sum_weights[i]);
        min_diff = std::min(min_diff, diff);
    }
    std::cout << min_diff << std::endl;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int v[n];
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    //int maxx=v[0];
    for(int i=n-1;i>1;i--){
        //maxx=max(maxx,v[i]);
        if(v[i-1]-v[i]==1){
            v[i-1]--;
        }
        else if(v[i-1]-v[i]>1){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


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

using namespace std;

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

// 46786 - 106

void oneCase() {
   int a, b, c;
   cin>> a >> b >> c;
   if (a == b) {
       cout << c;
   } else if (c == a) {
       cout << b;
   } else {
       cout << a;
   }
   cout << "\n";

}


int main() {
    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
char weather[3][7] = {"Sunny", "Cloudy", "Rainy"};
int main(void){
    char s[10];
    int i;
    scanf("%s", s);
    for(i=0; i<2; i++){
        if(!strcmp(s, weather[i])){
            printf("%s\n", weather[i+1]);
        }
    }
    if(!strcmp(s, weather[2])){
        printf("%s\n", weather[0]);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	map<int, bool> m;
	for(int i = 0; i < N; i++)
	{
		m[i] = false;
	}

	for(int i = 0; i < K; i++)
	{
		int d;
		cin >> d;
		for(int j = 0; j < d; j++)
		{
			int a;
			cin >> a;
			m[a-1] = true;
		}
	}

	int count = 0;
	for(int i = 0; i < N; i++)
	{
		if(!m.at(i))
		{
			count++;
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 3184
n=int(input())
d=[]
for i in range(n):
  s=list(input())
  s.sort()
  s="".join(s)
  d.append(s)
d.sort()
x=[]
k=1

for i in range(n-1):
  if d[i]==d[i+1]:
    k+=1
  else:
    x.append(k)
    k=1
x.append(k)

ans=[]
for i in range(len(x)):
  if x[i]>1:
    ans.append((x[i]*(x[i]-1))/2)
  else:
    ans.append(0)
    
    
print(int(sum(ans)))

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

int main(){
    int N;
    string ans;
    cin >> N;
    for(int i=1; i<=9; i++){
        if(N%i == 0 && N <= 81){
            if(N/i <= 9){
                ans = "Yes";
                break;
            }
        }
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int MAX_N = 100100;
template<typename Type> struct UnionFind
{
    vector<Type> p, r;
    UnionFind(int sz)
    {
        p.resize(sz);
        r.resize(sz, -1);
        for(int i = 0; i < sz; i++) p[i] = i;
    }
    Type Find(Type x)
    {
        if (x == p[x]) return x;
        return p[x] = Find(p[x]);
    }
    bool isSame(Type a, Type b) { return Find(a) == Find(b); }
    void unite(Type a, Type b)
    {
        a = Find(a), b = Find(b);
        if(a == b) return;
        if(r[a] < r[b]) p[a] = b;
        else { p[b] = a; if(r[a] == r[b]) r[a]++; }
    }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    UnionFind<int> UF(n + 1);
    for(int i = 0; i < m; i++)
    {
        int s, t; cin >> s >> t;
        if(UF.isSame(s, t)) continue;
        UF.unite(s, t);
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++)
    {
        int s, t; cin >> s >> t;
        cout << (UF.isSame(s, t) ? "yes" : "no") << "\n";
    }
    return 0;
}



Measured memory_bytes: 3592
N,=map(int, input().split()) 
A=[0]*4
for i in range(N):
  S=input() 
  if "AC"==S:
    A[0]+=1
  if "WA"==S:
    A[1]+=1
  if "TLE"==S:
    A[2]+=1
  if "RE"==S:
    A[3]+=1
print("AC x "+str(A[0]))
print("WA x "+str(A[1]))
print("TLE x "+str(A[2]))
print("RE x "+str(A[3]))
 

Measured memory_bytes: 9208
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int m,n,sum=0;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d%d",&m,&n);

	for(int i=1;i<=n;i++) sum+=read<int>();

	if(m<=sum) puts("Yes");else puts("No");

	return 0;

}

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

int main(){
  int k, n;
  cin >> k >> n;
  int m = INT_MAX;
  vector<int> arr(n*2);
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    arr[i] = x;
    arr[i+n] = x + k;
  }

  for(int i = 0; i < n; i++){
    m = min(m, max(arr[i+n-1], arr[i]) - min(arr[i+n-1], arr[i]));
  }

  cout << m << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main(){
  char s[100002];
  scanf("%s",s);
  int n,black=0,white=0,i;
  n=strlen(s);
  for(i=0;i<n;i++){
    if(i%2==0){
      if(s[i]=='0')
        white++;
      else
        black++;
    }
    else{
      if(s[i]=='0')
        black++;
      else
        white++;
    }
  }
  printf("%d\n",white>=black?black:white);
  return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)

# RR...RLL...L　の形に分割したい
# 境界は"LR"となっているはず

# "LR"の"L"のindexを記録
boundary = []
for i in range(N - 1):
    if S[i] == "L" and S[i + 1] == "R":
        boundary.append(i)

# boundary は R..RL..Lの左端 として扱いたいので、N-1も追加
boundary.append(N - 1)

ans = [0] * N

l = 0
for r in boundary:
    mid = 0
    # [indexが偶数の個数, indexが奇数の個数]
    cnt = [0, 0]
    for x in range(l, r + 1):
        cnt[x % 2] += 1
        # R...RL...Lの"RL"の位置を探す
        # "RL"の"R"のindexをmidに代入
        if x < r and S[x] == "R" and S[x + 1] == "L":
            mid = x

    # 十分な操作をすると、indexの偶奇で[mid]か[mid+1]のどちらかに集まる
    # midが偶数の場合
    if mid % 2 == 0:
        ans[mid] = cnt[0]
        ans[mid + 1] = cnt[1]
    # midが奇数の場合
    elif mid % 2 == 1:
        ans[mid] = cnt[1]
        ans[mid + 1] = cnt[0]

    # 次の区間の左端 = 今の区間の右端 + 1
    l = r + 1

print(*ans)


Measured memory_bytes: 79400
#include <stdio.h>
#include <stdlib.h>

int main() {
  int i, N, W[100], T, S1, S2, delta;
  char buf[500];
 
  scanf ("%d", &N);
  
  for (i=0;i<N;i++) {
      scanf ("%d", &W[i]);
  }
  
  delta = 100;
  for (T=1;T<N;T++) {
    S1 = 0;
    S2 = 0;
    for (i=0;i<T;i++) S1+=W[i];
    for (i=T;i<N;i++) S2+=W[i];
    if (abs(S1-S2)<delta) delta = abs(S1-S2);
  }
  
  printf ("%d", delta);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
int main()
{
    int N;
    std::cin >> N;
    std::vector<ll> A(N);
    for (int i = 0; i < N; i++) { std::cin >> A[i]; }
    ll ans = 0;
    for (ll i = 0, max = 0; i < N; i++) {
        if (A[i] > max + 1) { ans += (A[i] - 1) / (max + 1); }
        if (A[i] == (max + 1) or max == 0) { max++; }
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1024
def main():
    A, B = map(int, input().split())
    cnt = 0
    for i in range(A, B+1):
        s = str(i)
        t = list(s)
        t.reverse()
        if s == ''.join(t):
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    vi P,Q;
    int p,q;
    rep(i,N){
        int a; cin >> a;
        P.eb(a);
    }
    rep(i,N){
        int a; cin >> a;
        Q.eb(a);
    }
    vi A;
    rep(i,N){
        A.eb(i+1);
    }
    int cnt=0;
    do{
        if(A==P) p=cnt;
        if(A==Q) q=cnt;
        cnt++;
    }while(next_permutation(all(A)));
    cout << abs(p-q) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define rep1(i,N) for(int i=1;i<=(int)N;i++)
#define pb push_back
#define all(c) c.begin(),c.end()
#define show(x) cout<<#x<<" "<<x<<endl
using namespace std;
bool d[500010];
int lim;
int N;
bool is1;
int popcnt;
bool canput(){
	int x;
	cin>>x;
	if(is1) return 0;
	if(x>N){
		popcnt++;
		return 1;
	}
	if(lim>x) return 0;
	if(lim==x){
		if(popcnt>lim) return 0;
		is1=1;
		return 1;
	}
	while(d[x]){
		d[x]=0;
		popcnt--;
		x--;
	}
	d[x]=1;
	popcnt++;
	while(d[lim+1]) lim++;
	return 1;
}
int main(){
	cin>>N;
	rep(i,N){
		if(canput()) puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 3512
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.println(a / b);
        System.out.println(a % b);
        double f = (double) a / (double) b;
        System.out.printf("%.8f\n", f);

    }
}



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

int main() {
    int n, h;
    cin >> n >> h;
    int a[n], b[n];
    int mx = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        mx = max(mx, a[i]);
    }
    sort(b, b+n);
    reverse(b, b+n);
    int i;
    for (i = 0; i < n && b[i] > mx && h > 0; i++) {
        h -= b[i];
    }
    h = max(0, h);
    cout << i + (h+mx-1) / mx;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <map>

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

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

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

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

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

namespace std
{
    template <>
    class hash<std::pair<int, int>>
    {
    public:
        size_t operator()(const std::pair<int, int> &x) const
        {
            return hash<int>()(x.first) ^ hash<int>()(x.second);
        }
    };
} // namespace std

int main()
{
    int n, k, l;
    std::cin >> n >> k >> l;

    UnionFind u1(n), u2(n);
    for (int i = 0; i < k; ++i)
    {
        int a, b;
        std::cin >> a >> b;
        --a;
        --b;

        u1.unite(a, b);
    }
    for (int i = 0; i < l; ++i)
    {
        int a, b;
        std::cin >> a >> b;
        --a;
        --b;

        u2.unite(a, b);
    }

    // unordered_mapは今回のケースではとても遅い
    std::unordered_map<int64_t, int> counter;
    for (int i = 0; i < n; ++i)
    {
        const int index1 = u1.root(i), index2 = u2.root(i);
        const auto p = static_cast<int64_t>(index1) * n + index2;
        ++counter[p];
    }

    for (int i = 0; i < n; ++i)
    {
        const int index1 = u1.root(i), index2 = u2.root(i);
        const auto p = static_cast<int64_t>(index1) * n + index2;

        std::cout << counter[p];
        if (i == n - 1)
        {
            std::cout << std::endl;
        }
        else
        {
            std::cout << ' ';
        }
    }

    return 0;
}


Measured memory_bytes: 9928
#include <iostream>
#include <functional>
#include <limits>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class T, class F>
    void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};

int main()
{
    input in;
    auto min = std::numeric_limits<int>::max();
    in.online<int>(in.read<std::size_t>(), [&](auto x) { min = std::min(min, __builtin_ctz(x)); });

    std::cout << min;
    return 0;
}


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

const double EPS = 1e-9;
using Point = pair<double, double>;

vector<Point> getCenter(Point a, Point b) {
  double xm = (a.first + b.first) / 2;
  double ym = (a.second + b.second) / 2;
  double dx = b.first - a.first;
  double dy = b.second - a.second;
  double l = hypot(dx, dy) / 2;
  double t = sqrt((1 - l*l) / (dx*dx + dy*dy));
  vector<Point> res;
  res.emplace_back(xm - (-dy)*t, ym - dx*t);
  res.emplace_back(xm + (-dy)*t, ym + dx*t);
  return res;
}

int N;
double X[310], Y[310];
Point p[310];

bool contain(Point a, Point b) {
  return hypot(a.first-b.first, a.second-b.second) - EPS < 1;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> N, N) {
    for (int i = 0; i < N; i++) {
      cin >> X[i] >> Y[i];
      p[i] = Point(X[i], Y[i]);
    }
    int ans = 1;
    for (int i = 0; i < N; i++) {
      for (int j = i+1; j < N; j++) {
        auto c = getCenter(p[i], p[j]);
        for (int ci = 0; ci < c.size(); ci++) {
          int sum = 0;
          for (int k = 0; k < N; k++) {
            if (contain(c[ci], p[k])) sum++;
          }
          ans = max(ans, sum);
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3364
N = int(input())
A = []
for i in range(N):
    W = input()
    A.append(W)
for i in A:
    if A.count(i) != 1:
        print('No')
        exit()
for i in range(N - 1):
    if A[i][-1] != A[i + 1][0]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 8948
#include<iostream>

using namespace std;
int main(){
	
    int a,b,i;
    while( cin >> a ) {
        b = 0;
        i = 0;
        
        while( i < 600 / a) 
		b += a * i * a * i++ * a;
		
        cout << b << "\n";
    }
}


Measured memory_bytes: 2972
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
ll UB;
double dfs(int idx, ll n, ll sigma, int e){
  //printf("dfs %d %lld %d\n", idx, n, last);
  double res = 1.0 * sigma / n;
  if(idx == 16) return res;
  ll n_sigma = sigma;
  for(int i = 0; i < e; i++){
    if(n * primes[idx] > UB) break;
    n *= primes[idx];
    n_sigma = n_sigma * primes[idx] + sigma;
    res = max(res, dfs(idx + 1, n, n_sigma, i + 1));
  }
  return res;
}
int main(){
  while(cin >> UB && UB) printf("%.16lf\n", dfs(0, 1, 1, 100));
  return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <cmath>

int n, ans;
int A[2000] = {};

bool solve(int i, int m) 
{
  if(m == 0) { //引いて0になったら可能
    return true;
  }
  if(i >= n) { //最後まで回って作れなかったら不可能
    return false;
  }
  bool res = solve(i + 1, m) || solve(i + 1, m - A[i]); 
               //引かないで次の要素を見るか、引いて次の要素を見るか
  return res;
}

int main() 
{
  std::cin >> n;
  for(int i = 0; i < n; i++) {
    std::cin >> A[i];
  }

  int q;
  std::cin >> q;
  int m[q];
  for(int i = 0; i < q; i++) {
    std::cin >> m[i];
  }

  for(int i = 0; i < q; i++) {
    if(solve(0, m[i])) {
      std::cout << "yes";
    }
    else {
      std::cout << "no";
    }
    std::cout << "\n";
  }

  return 0;
}



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

int main(){
	ll n,t;
	cin>>n>>t;
	ll mi=1e15,ma=0;
	map<ll,ll>mp;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		mp[x-mi]++;
		ma=max(ma,x-mi);
		mi=min(mi,x);
	}
	cout<<mp[ma];
	return 0;
}

Measured memory_bytes: 9824
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second	
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1=1e9;
const long long I2=1e18;
const int32_t M1=1e9+7;
const int32_t M2=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}
int n;
ld dp[301][301][301];
ld f(int p, int q,int r)
{
    if(p==0 && q==0 && r==0) return 0;
    ld x,val1=0,val2=0,val3=0;
    if(p>0)
    {
    x=(ld)(p)/(p+q+r);
    if(dp[p-1][q][r]==0) dp[p-1][q][r]=f(p-1,q,r);
    val1= (p==0?0:x*dp[p-1][q][r]);
    }
    if(q>0)
    {
    x=(ld)(q)/(p+q+r);
    if(dp[p+1][q-1][r]==0) dp[p+1][q-1][r]=f(p+1,q-1,r);
    val2= (q==0?0:x*dp[p+1][q-1][r]);
    }
    if(r>0)
    {
    x=(ld)(r)/(p+q+r);
     if(dp[p][q+1][r-1]==0) dp[p][q+1][r-1]=f(p,q+1,r-1);
    val3= (r==0?0:x*dp[p][q+1][r-1]);
    }
   // cout<<val1<<" "<<val2<<" "<<val3<<endl;
    ld ans=(ld)(n)/(p+q+r)+val1+val2+val3;
   // if(p==1) cout<<ans<<endl;
    return ans;
}
void solve()
{
  //code begins from here//
    cin>>n;
    int a[4]={0};
    lop (i,n)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    cout<<fixed<<setprecision(10)<<f(a[1],a[2],a[3])<<endl;
}

signed main()
{
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef MODULO
        initialize();
    #endif
    #ifdef SIEVE
        sieve();
    #endif
    int testcase=1;
   // cin>>testcase;
    while(testcase--) solve();
    return 0;
}


Measured memory_bytes: 212852
mozi=[input()]
ans=[]
i=0


while mozi[i] != '-':
    num=0
    
    for w in range(int(input())):
        num=num + int(input())
        
    for w in range(num):
        mozi[i] = mozi[i][1:] + mozi[i][0:1]
        
    mozi.append(input())
    i=i+1

i=0
while mozi[i] != '-':
    print(mozi[i])
    i=i+1


Measured memory_bytes: 5600
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int D = Cin<int>();
        int G = Cin<int>();
        int[] p = new int[D];
        int[] c = new int[D];
        for (int i = 0; i < D; i++) { p[i] = Cin<int>(); c[i] = Cin<int>(); }

        //bit全探索
        int M = (int)Math.Pow(2, D);
        int min = INF;
        for (int i = 0; i < M; i++)
        {
            int box = 0;
            int cou = 0;
            //2進数のbit立ちで計算
            for (int j = 0; j < D; j++)
            {
                if ((1 & i >> j) == 1)
                {
                    //1の立つ場所を解く
                    box += 100 * (j + 1) * p[j] + c[j];
                    cou += p[j];
                }
            }
            if (box >= G) min = Math.Min(min, cou);
            else {
                //足りない
                for (int j = D-1; j != -1 ; j--) {
                    if ((1 & ~i >> j) == 1)
                    {
                        int count = 0;
                        //出来るだけ解く
                        while (true) {
                            box += 100 * (j + 1);
                            count++;
                            if (box >= G || count == p[j]) break;
                        }
                        cou += count;
                    }
                    if (box >= G) break;
                }
            }
            if (box >= G) min = Math.Min(min,cou);
        }
        Console.WriteLine(min);
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    public static T Cin<T>()
    {
        if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        if (typeof(T) == typeof(int)) return (T)(object)int.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(long)) return (T)(object)long.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(string)) return (T)(object)(queue.Dequeue());
        else if (typeof(T) == typeof(double)) return (T)(object)double.Parse(queue.Dequeue());
        else return (T)(object)(-1);
    }
    public static T Line<T>()
    {
        if (typeof(T) == typeof(int[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        else if (typeof(T) == typeof(long[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        else if (typeof(T) == typeof(string[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').ToArray();
        }
        else if (typeof(T) == typeof(double[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
        else return (T)(object)(-1);
    }
}

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

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;

	double x = (a + b) / 2.0;
	cout << ceil(x) << endl;
}


Measured memory_bytes: 256
/**
 * Created by karayuu on 2018/12/08
 */
fun main(args: Array<String>) {
    val d = readLine()!!.toInt()
    when (d) {
        25 -> println("Christmas")
        24 -> println("Christmas Eve")
        23 -> println("Christmas Eve Eve")
        22 -> println("Christmas Eve Eve Eve")
    }
}

Measured memory_bytes: 29784
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

bool match(int n)
{
  std::set<int> num;
  while (n > 0)
  {
    num.insert(n % 10);
    n /= 10;
  }

  if (num.size() == 3)
    return true;
  else
    return false;
}

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

  int sum = 0;
  std::queue<long long> q;
  q.push(3);
  q.push(5);
  q.push(7);
  while (!q.empty())
  {
    long long n = q.front();
    q.pop();
    if (n > N)
      continue;
    if (match(n))
    {
      sum++;
    }
    q.push(n * 10 + 3);
    q.push(n * 10 + 5);
    q.push(n * 10 + 7);
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 768
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	LL n, m, d;
	cin >> n >> m >> d;
	double t = d == 0 ? 1 : 2;
	double ans = t * (n - d) / (n * n) * (m - 1);
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll sum = 0;
  rep(i,n) sum += a[i];
  set<ll> candidates;
  for (int i = 1; i*i <= sum; i++) {
    if (sum%i == 0) {
      candidates.insert(i);
      candidates.insert(sum/i);
    }
  }
  ll ans = 1;
  for (ll x : candidates) {
    ll need;
    { // calc need
      vector<ll> r(n);
      rep(i,n) r[i] = a[i]%x;
      sort(r.begin(), r.end());
      ll tot = 0;
      rep(i,n) tot += r[i];
      int l = n-tot/x;
      need = 0;
      rep(i,l) need += r[i];
    }
    if (need <= k) ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main() {
    string str;
    cin >> str;
    
    int a = str.size();
    char b = str.at(a - 1);
    
    char c = 's';
    if (b == c) {
        cout << str << "es" << endl;
    }
     else {
        cout << str << "s" << endl;
    }
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    int n;
    int temp;
    string result="No";
    cin >> n;
    for(int i=9;i>0;i--){
        if((n%i)==0){
            temp = n/i;
            if(temp<10){
                result = "Yes";
                break;
            }
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
template <typename qwq> inline void read(qwq &x)
{
	x = 0;
	rg int f = 1;
	rg char c = getchar();
	while (c < '0' || c > '9')
	{
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9')
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	x *= f;
}
template <typename qaq> inline void print(qaq x)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x > 9) print(x / 10);
	putchar(x % 10 + '0');
}
int n, ans;
int main()
{
	read(n);
	if (n >= 1 && n <= 9) ans = n;
	else if (n >= 10 && n <= 99) ans = 9;
	else if (n >= 100 && n <= 999) ans = 9 + n - 99;
	else if (n >= 1000 && n <= 9999) ans = 9 + 900;
	else if (n >= 10000 && n <= 99999) ans = 9 + 900 + n - 9999;
	else if (n >= 100000 && n <= 999999) ans = 9 + 900 + 90000;
	print(ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MX=2e5+9;
int n;
ll ans;
int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%d",&n);
    for( int i=1 ; i<=n ; i++ ){
        int num=n/i;
        int st=i,ed=num*i;
        ans+=(1ll*(st+ed)*num/2);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3824
#include <stdio.h>

int main() {
    int x=0,i=0,data[10000];
    while(1){
        i++;
        scanf("%d",&data[i]);
        x=x+1;
        if(data[i]==0)break;
        
        }
    for(x=1;x<i;x++){
        printf("Case %d: %d\n",x,data[x]);
    }
    return 0;
}

Measured memory_bytes: 1748
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int x = s.indexOf("A");
        int y = s.lastIndexOf("Z");
        System.out.println(y - x  + 1);
	}

}

Measured memory_bytes: 26564
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int m, d;
    cin >> m >> d;
    int ans = 0;
    rep1(i, m+1){
        rep1(j, d+1){
            int d1 = j%10;
            int d10 = j/10;
            if(d1 > 1 && d10 >1 && d1*d10 == i) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.ArrayDeque

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = br.readLine()!!.toCharArray()
    var tmp = 0L
    for (c in n) {
        tmp += c - '0'
    }
    val ans = if (tmp % 9 == 0L) "Yes" else "No"
    out.println(ans)

}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int main(){
  string s;
  cin >> s;
  //010101010... のパターン
  int ans = 0;
  for(int i=0;i<s.size();i++){
    if(i%2 == 0 && s[i] != '0'){
      ans++;
      // cout << i << " " << s[i] << endl;
    }
    if(i%2 == 1 && s[i] != '1'){
      ans++;
      // cout << i << " " << s[i] << endl;
    }
  }

  //101010101のパターン
  int tmp = 0;
  for(int i=0;i<s.size();i++){
    if(i%2 == 0 && s[i] != '1'){
      tmp++;
      // cout << i << " " << s[i] << endl;
    }
    if(i%2 == 1 && s[i] != '0'){
      tmp++;
      // cout << i << " " << s[i] << endl;
    }
  }
  cout << min(ans ,tmp )<< endl;
  return 0;
}

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

int n, m, q;

int result = 0;

void dfs(vector<int> x, vector<int> a, vector<int> b, vector<int> c, vector<int> d);



int main()
{
    cin >> n>>m>>q;
    vector<int> a(q);
    vector<int> b(q);
    vector<int> c(q);
    vector<int> d(q);
    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vector<int>(1, 1),a,b,c,d);
    cout << result << endl;
}

void dfs(vector<int> x, vector<int> a,vector<int> b,vector<int> c,vector<int> d)
{
    if (x.size() == n + 1)
    {
        int sum = 0;
        for (int i = 0; i < q; i++)
        {
            if (x[b[i]] - x[a[i]] == c[i])
                sum += d[i];
        }
        result = max(result, sum);
        return;
    }


    x.push_back(x.back());
    while (x.back() <= m)
    {
        dfs(x,a,b,c,d);
        x.back()++;
    }
}

Measured memory_bytes: 3548
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<malloc.h>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, Q;
int s[10100];

signed main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }
    int ans = 0;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int a;
        cin >> a;
        bool flag = false;
        for(int j = 0; j < N; j++){
            flag |= (a == s[j]);
        }
        if(flag)ans++;
    }
    cout << ans << endl;

    return 0;
}

/*

*/


Measured memory_bytes: 3148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 数値の読み込み
x,y = [int(i) for i in input().split()]

res = 0


if abs(y) > abs(x):
    # |x| < |y|
    if x < 0:
        res = res + 1
    if y < 0:
        res = res + 1
    res = res + (abs(y)-abs(x))
else :
    # x > y
    if x > 0:
        res = res + 1
    if y > 0:
        res = res + 1
    res = res + (abs(x)-abs(y))


print(res)

Measured memory_bytes: 3064
#coding: UTF-8

# A = int(input('A = '))
# B = int(input('B = '))
# C = int(input('C = '))
# D = int(input('D = '))
A = int(input())
B = int(input())
C = int(input())
D = int(input())

#デバック用
# print ('A',A)
# print ('B',B)
# print ('C',C)
# print ('D',D)

r = min(A,B) + min(C,D)
print(r)


Measured memory_bytes: 3064
//    _____ _     _                _           _     _ _     _     
//    \_   \ |_  (_)___  __      _| |__   __ _| |_  (_) |_  (_)___ 
//     / /\/ __| | / __| \ \ /\ / / '_ \ / _` | __| | | __| | / __|
//  /\/ /_ | |_  | \__ \  \ V  V /| | | | (_| | |_  | | |_  | \__ \
//  \____/  \__| |_|___/   \_/\_/ |_| |_|\__,_|\__| |_|\__| |_|___/
//                                                                 
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll div_floor(ll a, ll b) {
	// use when ret <= a/b, (a and b can be -ve)
	return a / b - (((a ^ b) < 0) and a % b);
}
ll div_ceil(ll a, ll b) { 
	// use when ret >= a/b, (a and b can be -ve)
	return a / b + (((a ^ b) >= 0) and a % b);
}
const int sz=200000+9;
ll cs[sz];
int n,k;
int p[sz];
double ans;
double val[sz];



int main(){
	cin>>n>>k;
	cs[0]=0;
	for(int i=1;i<=1005;i++) cs[i]=cs[i-1]+i;
	for(int i=0;i<n;i++){
		 cin>>p[i];
		 val[i]=cs[p[i]]/double(p[i]);
	}
	double tmp=0;
	for(int i=0;i+k-1<n;i++){
		if(!i){
			for(int j=0;j<k;j++) tmp+=val[j];
		}else{
			tmp-=val[i-1];
			tmp+=val[i+k-1];
		}
		ans=max(ans,tmp);
	}
	printf("%0.7lf",ans);
	return 0;
}


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

const int sosu = 1000000007; 

int main(){
    int N;
    cin >> N;
    long long a = 1;
    for (int i = 1; i <=N;i++){
        a *= i;
        a = a % sosu;
    }
    cout << a;

    return 0;
}

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

int main(){
  string s;
  cin >> s;
  string ans = "Yes";
  if((s[0]==s[1])&&(s[1]==s[2])){
    ans = "No";
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int n;
    cin >> n;
    int temp = n;
    int count = 0;
    while (temp != 0) {
        count++;
        temp /= 10;
    }
    if (count == 1) {
        cout << n << endl;
    } else {
        int out = 0;
        int out2 = 0;
        out = 9 * (count - 1);
        out += n / ((int)pow(10, count - 1)) - 1;
        while (n != 0) {
            int ntemp = n / 10;
            out2 += n - ntemp * 10;
            n /= 10;
        }
        cout << max(out, out2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();

            if ((c > a && c < b) || (c < a && c > b))
                System.out.println("Yes");
            else
                System.out.println("No");


        }
    }
}

Measured memory_bytes: 21844
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = [0] * 45
for i in c:
    e = bin(i)[2:]
    for j in range(len(e)):
        d[j] += int(e[-j-1])
ans = 0
s = 0
for i in range(44, -1, -1):
    if 2 ** i + s <= b and a > d[i] * 2:
        s += 2 ** i
for i in c:
    ans += i ^ s
print(ans)


Measured memory_bytes: 14588
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
const int mod=1e9+7;
void grid_way(vector<vector<pair<char,int> > > &a,int n,int m){
	int i=0;
	while(i<n&&a[i][0].first!='#')
	a[i++][0].second=1;
	while(i<n)
	a[i++][0].second=0;
	i=1;
	while(i<m&&a[0][i].first!='#')
	a[0][i++].second=1;
	while(i<m)
	a[0][i++].second=0;
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			a[i][j].second=0;
			if(a[i][j].first=='.')
			a[i][j].second=(a[i-1][j].second%mod+a[i][j-1].second%mod)%mod;
		}
	}
	cout<<a[n-1][m-1].second%mod<<endl;
}
int main(){
	int n,m;vector<vector<pair<char,int> > > a;cin>>n>>m;
	for(int i=0;i<n;i++){
		vector<pair<char,int> > temp;
		char c;
		for(int j=0;j<m;j++){
			cin>>c;temp.push_back(make_pair(c,0));
		}
		a.push_back(temp);
	}
	grid_way(a,n,m);
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
#define dbg3(x) cerr<<#x<<"\n"
using namespace std;
#define reg register
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<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
const int MN=1e5+5;
int N,M,p[MN];
int fa[MN];
int getf(int x){return x==fa[x]?x:fa[x]=getf(fa[x]);}
int main()
{
	N=read(),M=read();
	reg int i,x,y;
	for(i=1;i<=N;++i) p[read()]=i,fa[i]=i;
	for(i=1;i<=M;++i)
	{
		x=read(),y=read();
		if(getf(x)^getf(y)) fa[getf(x)]=fa[getf(y)];
	}
	int ans=0;
	for(i=1;i<=N;++i) ans+=(getf(i)==getf(p[i]));
	return 0*printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    
    int cnt = 0;
    REP(i, S.size()) {
        if (S[i - 1] != S[i]) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int X, A, B;
	cin >> X >> A >> B;

	if (A >= B)
	{
		cout << "delicious";
	}
	else if(B - A >= X + 1)
	{
		cout << "dangerous";
	}
	else
	{
		cout << "safe";
	}

	return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<vector<bool>> v(4,vector<bool>(13,false));
    char Mark;
    int Number;
    // 0:S, 1:H, 2:C, 3:D
    for(int i=0; i<N; ++i){
        cin >> Mark >> Number;
        if( Mark=='S' )
            v[0][Number-1]=true;
        if( Mark=='H' )
            v[1][Number-1]=true;
        if( Mark=='C' )
            v[2][Number-1]=true;
        if( Mark=='D' )
            v[3][Number-1]=true;
    }

    for(int i=0; i<4; ++i){
        for(int j=0; j<13; ++j){
            if(v[i][j] == false){
                if( i==0 ){
                    cout << "S " << j+1 <<'\n';
                }
                if( i==1 ){
                    cout << "H " << j+1 <<'\n';
                }
                if( i==2 ){
                    cout << "C " << j+1 <<'\n';
                }
                if( i==3 ){
                    cout << "D " << j+1 <<'\n';
                }
            }
        }
    }

    return 0;
}



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

using namespace std;
using ll = long long;

int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<pair<ll, ll>> vb(m);
  for (int i = 0; i < m; i++) {
    cin >> vb[i].second >> vb[i].first;
  }
  sort(v.begin(), v.end());
  sort(vb.begin(), vb.end(), greater<>());
  int i = 0;
  int k = 0;
  bool f = true;
  while (true) {
    for (int j = 0; j < vb[k].second; j++) {
      if (v[i] >= vb[k].first) {
        f = false;
        break;
      }
      v[i] = vb[k].first;
      i++;
    }
    k++;
    if (not f) {
      break;
    }
  }
  ll ans = 0;
  for (auto x : v) {
    ans += x;
  }
  cout << ans << endl;
  return 0;
}


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

num = {}
for i in A:##O(N)
    if i not in num:
        num[i] = 1
    else:
        num[i] += 1


values = list(num.values())
keys = list(num.keys())
S = 0
for i in range(len(keys)):##O(N*2)
    if values[i] >= 2:
        S += values[i]*(values[i]-1)//2

for i in range(N):
    if num[A[i]] >= 3:
        print(S-num[A[i]]*(num[A[i]]-1)//2+(num[A[i]]-1)*(num[A[i]]-2)//2)
    elif num[A[i]] == 2:
        print(S-1)
    else:
        print(S)

Measured memory_bytes: 25736