akhauriyash/Code-Regression huggingface dataset:
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
    int a[3];

    rep(i, 3) cin >> a[i];

    int ans = 0;
    while (1) {
        sort(a, a+3);

        if ( a[0] == a[1] && a[0] == a[2] ) break;
        
        if ( a[2] >= a[0]+2 ) a[0] += 2;
        else {
            a[0] += 1;
            a[1] += 1;
        }
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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 = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, l;
    cin >> n >> l;
    int x = 0;
    int sa = INF;
    rep(i, n) x += l + i;
    int ans = -1;
    rep(i, n) {
        int a = 0;
        rep(j, n) {
            if (i == j) continue;
            a += l + j;
        }
        if (chmin(sa, abs(a - x))) {
            ans = a;
        }
    }
    cout << ans << endl;
}

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


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

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

  int a, b;
  cin >> a >> b;
  string s = "", t = "";
  for (int i = 0; i < b; i++) s += to_string(a);
  for (int i = 0; i < a; i++) t += to_string(b);
  string ans = min(s, t);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N,X,Y;
  cin >> N >> X >> Y;
  --X;--Y;
  
  vector<int> ans(N,0);

  int cur=0;
  for(int i=0;i<N-1;i++){
    for(int j=i;j<N;j++){
      cur=min(j-i,abs(i-X)+abs(j-Y)+1);
      ans[cur]++;
    }
  }

  for(int i=1;i<N;i++) cout << ans[i] << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

vector<long long int> solve(long long int H, long long int W, long long int N, vector<pair<long long int, long long int> > square){
  vector<long long int> ans(10);
  for(long long int i = 0; i < 10; i++){
    ans[i] = 0;
  }

  sort(square.begin(), square.end());
  vector<pair<long long int, long long int> > list;

  for(long long int i = 0; i < N; i++){
    for(long long int j = 0; j < 3; j++){
      for(long long int k = 0; k < 3; k++){
        if(square[i].first - j > 0 && square[i].second - k > 0 &&
           square[i].first - j + 2 <= H && square[i].second - k + 2 <= W){
          list.push_back(make_pair(square[i].first - j, square[i].second - k));
        }
      }
    }
  }
  sort(list.begin(), list.end());

  pair<long long int, long long int> tmp(-1, -1);
  long long int cont = 0;
  for(long long int i = 0; i < (long long int)list.size(); i++){
    if(list[i].first != tmp.first || list[i].second != tmp.second){
      ans[cont]++;
      cont = 0;
      tmp.first = list[i].first;
      tmp.second = list[i].second;
    }
    cont++;
  }
  ans[cont]++;

  ans[0] = (H - 2) * (W - 2);
  for(long long int i = 1; i < 10; i++){
    ans[0] -= ans[i];
  }

  return ans;
}

int main(){

  long long int H, W, N;
  cin >> H >> W >> N;

  vector<pair<long long int, long long int> > square(N);
  for(long long int i = 0; i < N; i++){
    long long int a, b;
    cin >> a >> b;
    square[i] = make_pair(a, b);
  }

  vector<long long int> result(10);
  result = solve(H, W, N, square);

  for(long long int i = 0; i < 10; i++){
    cout << result[i] << endl;
  }
  
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int start,end;
    for(int i=0; i < s.size(); i++){
        if (s.at(i) == 'A'){
            start = i;
            break;
        }
    }
    for(int i=s.size(); i > 0; i--){
        if (s.at(i - 1) == 'Z'){
            end = i;
            break;
        }
    }  
    cout << end - start  << endl;
}

Measured memory_bytes: 640
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = [0]*n
for i in range(n):
    a[i] = int(input())
aa = sorted(a)
# print(aa)
for i in range(n):
    if a[i] != aa[-1]:
        print(aa[-1])
    else:
        print(aa[-2])


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

int main(){
    using namespace std;
    unsigned long N, K;
    cin >> N >> K;
    vector<unsigned long> p(N);
    for(auto&& i : p){
        cin >> i;
        --i;
    }
    const auto& perm_mul = [](vector<unsigned long>& x, const vector<unsigned long>& p) -> void {
        vector<unsigned long> k(x), r(p);
        transform(k.begin(), k.end(), x.begin(), [&r](auto i){return r[i];});
    };
    vector<unsigned long> r(p.size());
    iota(r.begin(), r.end(), 0UL);
    while(K){
        if(K & 1)perm_mul(r, p);
        perm_mul(p, p);
        K >>= 1;
    }
    cout << r[0] + 1 << endl;
    return 0;
}

Measured memory_bytes: 9532
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n, l, r = 0;
    cin >> n >> l;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=1;i<n;i++){
        if(a[i]+a[i-1] >= l) {
            r = i;
            break;
        }
    }
    if(r >= 1){
        puts("Possible");
        for(int i=1;i<r;i++) cout << i << endl;
        for(int i=n-1;i>=r;i--) cout << i << endl;
    }else{
        puts("Impossible");
    }
}


Measured memory_bytes: 1152
#include <bits/stdc++.h> 
using namespace std;
int main() {
  string pal;
  cin>>pal;
  bool secondcheck=true;
  bool thirdcheck=true;
  bool firstcheck=true;
  int len=pal.length();
  for(int i=0;i<len;++i){
    if(pal[i]!=pal[len-i-1]){
      firstcheck=false;
    }
  }
  string secondstring=pal.substr(0,len/2);
  for(int i=0;i<secondstring.length();++i){
    if(secondstring[i]!=secondstring[secondstring.length()-i-1]){
      secondcheck=false;
    }
  }
  string thirdstring=pal.substr((len+3)/2-1,len-(len+3)/2+1);
  for(int i=0;i<thirdstring.length();++i){
   
    if(thirdstring[i]!=thirdstring[thirdstring.length()-i-1]){
      thirdcheck=false;
    }
  }
  if(thirdcheck==true &&firstcheck==true&&secondcheck==true){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  long long in(n, k);
  long long result = 0;
  if(k == 0) {
    result = n * n;
  } else {
    n++;
    FOR(b, k, n) {
      result += (n / b) * (b - k);
      long long tmp = n % b - k;
      if(tmp > 0) {
        result += tmp;
      }
    }
  }
  out(result);
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Println(isPossible(a, b))
}

func isPossible(a, b int) string {
	if a%3 == 0 || b%3 == 0 || (a+b)%3 == 0 {
		return "Possible"
	}
	return "Impossible"
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int n, h, w, a, b, ans = 0;
    cin >> n >> h >> w;
    for(int i = 0; i < n; i++){
        scanf("%d%d", &a, &b);
        if(a >= h && b >= w) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 18
sys.setrecursionlimit(10 ** 5)


def main():
    n, m, p = map(int, readline().split())
    edge = [[] for _ in range(n)]

    for _ in range(m):
        a, b, c = map(int, readline().split())
        edge[a - 1].append([b - 1, -c + p])

    dist = [INF] * n
    dist[0] = 0

    for _ in range(n - 1):
        for u in range(n):
            for v, w in edge[u]:
                if dist[u] != INF:
                    dist[v] = min(dist[v], dist[u] + w)

    for _ in range(n):
        for u in range(n):
            for v, w in edge[u]:
                if dist[u] != INF and dist[v] > dist[u] + w:
                    dist[v] = -INF

    if dist[n - 1] == -INF:
        print(-1)
    else:
        print(max(-dist[n - 1], 0))


if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin>>n;
  string s[n];
  for (int i=0; i<n; i++) cin>>s[i];

  map<int, int> x[26], y[26];
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      int k = s[i][j] - 'a';
      ++x[k][j];
      ++y[k][i];
    }
  }
  set<int> offsets;
  bool first = true;
  for (int i=0; i<26; i++) {
    if (x[i].size() == 0) {
      continue;
    }
    set<int> tmp;
    for (int offset=0; offset<n; ++offset) {
      bool ok = true;
      for (auto e: x[i]) {
        int k = e.first;
        int v = e.second;
        if (y[i][(k + offset) % n] != v) {
          ok = false;
          break;
        }
      }
      if (ok) {
        tmp.insert(offset);
      }
    }
    if (first) {
      offsets = tmp;
      first = false;
    } else {
      set<int> intersect;
      set_intersection(offsets.begin(), offsets.end(), tmp.begin(), tmp.end(), inserter(intersect, intersect.begin()));
      offsets = intersect;
    }
  }
  cout<<n*offsets.size()<<endl;
}

Measured memory_bytes: 1152
import math

A, B = [int(i) for i in input().strip().split()]

# X * 0.08 = A + a (0 <= a < 1)
# X * 0.10 = B + b (0 <= b < 1)

# X = A / 0.08 + a / 0.08
# 12.5*A <= X < 12.5*A + 12.5
#  thus
# 12.5*A <= X < 12.5*(A+1)
# 10  *B <= X < 10  *(B+1)
#   and A <= B

if 12.5*(A+1) <= 10*B:
  print(-1)
elif 10*(B+1) <= 12.5*A:
  print(-1)
else:
  X_min = max(12.5*A, 10*B)
  X_max = min(12.5*(A+1), 10*(B+1))
  if X_min <= X_max:
    if math.ceil(X_min) <= math.floor(X_max):
      print(math.ceil(X_min))
    else:
      print(-1)
  else:
    print(-1)


Measured memory_bytes: 3064
list=[]

for i in range(5):
    x=int(input())
    list.append(x)
k=int(input())
ok_swit=1

for a in range(5):
    for b in range(4-a):
        c=a+b+1
        if abs(list[a]-list[c])>k:
            ok_swit=0

if ok_swit==1:
    print("Yay!")
else:
    print(":(")

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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 998244353;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint pow(const modint x, ll r) {
        return x^r;
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) {
            int size = factorial.size();
            factorial.resize(n+1);
            for (int i = size; i <= n; i++) {
                factorial[i] = fact(i-1) * modint(i);
            }
        }
        return factorial[n];
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial = {1};
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    int n;
    cin >> n;
    modint sum = 0;
    for (int i = n/2+1; i <= n; i++) {
        sum += C(n,i) * modint::pow(2,n-i) * modint(2);
    }
    cout << modint::pow(3,n) - sum << endl;
    return 0;
}


Measured memory_bytes: 117376
N, K = map(int, input().split())
*A, = map(int, input().split())

def f(t):
    if t!=0:
        c = 0
        for i in A:
            c += i//t if i!=t else 0
        return c<=K
    else:
        return all(i<=t for i in A)

left, right = -1, 10**10
while right-left>1:
    m = (right+left)//2
    if f(m):
        right = m
    else:
        left = m

print(right)


Measured memory_bytes: 30708
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var X, N int
	fmt.Scanf("%d", &X)
	fmt.Scanf("%d", &N)

	P := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &P[i])
	}
	sort.Ints(P)

	var a int = -1
	if len(P) > 0 {
		for p := 0; p < 102; p++ {
			if math.Abs(float64(X) - float64(p)) < math.Abs(float64(X) - float64(a)) && !Contain(P, p) {
				a = p
			}
		}
	} else {
		a = X
	}
	fmt.Println(a)
}

func Contain(s []int, e int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}



Measured memory_bytes: 1832
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

vector<vector<int>> idx(202020);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    REP(i,N){
        int num;
        cin >> num;
        idx[num].push_back(i);
    }

    int cur = 0;
    int cnt = 0;
    while(cur < N){
        auto itr = lower_bound(idx[cnt+1].begin(), idx[cnt+1].end(), cur);
        if(itr == idx[cnt+1].end()){
            if(cnt == 0){
                cout << -1 << endl;
                return 0;
            }
            break;
        }
        cnt++;
        cur = *itr;
    }

    cout << N - cnt << endl;
}

Measured memory_bytes: 11264
#include <unordered_map>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include<map>
#include<iostream>
using namespace std;

const int maxn = 100000;
int arr[maxn];
int main()
{
	//freopen("in.txt", "r", stdin);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> arr[i];
	int res = 2000000000;
	for (int i = 0; i + k <= n; ++i) {
		int l = arr[i];
		int r = arr[i + k - 1];
		if (r <= 0) {
			res = min(res, abs(l));
			continue;
		}
		if (l >= 0) {
			res = min(res, r);
			continue;
		}
		int c = r - l + min(abs(l), r);
		res = min(res, c);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int, int> pii;
inline void chmax(int &a, const int &b) {a = max(a, b);}
inline void chmin(int &a, const int &b) {a = min(a, b);}
const int INF = 1 << 28;
string s;
int N;
pii dp[210][210], INIT;

pii solve(int l, int r) {
    pii &res = dp[l][r];
    if(dp[l][r] != INIT) return res;
    // 数字
    if(r - l == 1) {
        int val = s[l] - '0';
        return res = make_pair(val, val);
    }
    // 括弧をとっぱらって再帰的に
    // このとき、括弧含め幅が 3 以下 (つまり実質 2 以下) だと
    // 数式になりえないので飛ばす
    if(s[l] == '(' && r-l > 3) {
        pii tmp = solve(l+1, r);
        res.first = max(res.first, tmp.first);
        res.second = min(res.second, tmp.second);
    }
    if(s[r-1] == ')' && r-l > 3) {
        pii tmp = solve(l, r-1);
        res.first = max(res.first, tmp.first);
        res.second = min(res.second, tmp.second);
    }
    for(int k=l; k<r; k++) {
        if(s[k] != '+' && s[k] != '-') continue;
        pii v1 = solve(l, k), v2 = solve(k+1, r);
        if(s[k] == '+') {
            res.first = max(res.first, v1.first + v2.first);
            res.second = min(res.second, v1.second + v2.second);
        }
        else {
            res.first = max(res.first, v1.first - v2.second);
            res.second = min(res.second, v1.second - v2.first);
        }
    }
    return res;
}

int main() {
    cin >> s;
    N = s.length();
    INIT = make_pair(-INF, INF);
    for(int i=0; i<N; i++) {
        fill(dp[i], dp[i] + N + 1, INIT);
    }

    cout << solve(0, N).first << endl;
    /*
    for(int i=0; i<N; i++) {
        for(int j=i+1; j<=N; j++) {
            if(dp_max[i][j] == -INF) continue;
            printf("%s\n", s.c_str());
            for(int k=0; k<N; k++) {
                if(i <= k && k < j) printf("=");
                else printf(" ");
            }
            printf(" -> %d\n", dp_max[i][j]);
        }
    }
    */
    return 0;
}


Measured memory_bytes: 3524
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local xs, ys, xt, yt = io.read("*n", "*n", "*n", "*n")
local n = io.read("*n")
local x, y, r = {}, {}, {}
x[1], y[1], r[1] = xs, ys, 0
for i = 1, n do
  x[i + 1], y[i + 1], r[i + 1] = io.read("*n", "*n", "*n")
end
x[n + 2], y[n + 2], r[n + 2] = xt, yt, 0
local n2 = n + 2
local len = {}
len[1] = 0
for i = 2, n2 do
  len[i] = 10000000000
end
local costs = {}
for i = 1, n2 * n2 do
  costs[i] = 10000000000
end

local function getcost(idx1, idx2)
  return mma(0, msq((x[idx1] - x[idx2]) * (x[idx1] - x[idx2]) + (y[idx1] - y[idx2]) * (y[idx1] - y[idx2])) - r[idx1] - r[idx2])
end

for i = 1, n + 1 do
  for j = i + 1, n + 2 do
    local c = getcost(i, j)
    costs[(i - 1) * n2 + j] = c
    costs[(j - 1) * n2 + i] = c
  end
end

local taskstate = {}
for i = 1, n2 do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0
local tasklim = n2

local function addtask(idx)
  taskstate[idx] = true
  tasknum = tasknum + 1
  local taskidx = tasknum % tasklim
  if taskidx == 0 then taskidx = tasklim end
  tasks[taskidx] = idx
end
addtask(1)

while done < tasknum do
  done = done + 1
  local taskidx = done % tasklim
  if taskidx == 0 then taskidx = tasklim end
  local src = tasks[taskidx]
  taskstate[src] = false
  local at = {}
  for dst = 1, n2 do
    local c = costs[(src - 1) * n2 + dst]
    if len[src] + c < len[dst] then
      len[dst] = len[src] + c
      if dst ~= n2 then
        if not taskstate[dst] then
          table.insert(at, dst)
        end
      end
    end
  end
  table.sort(at, function(x, y) return len[x] < len[y] end)
  for i = 1, #at do addtask(at[i]) end
end
print(string.format("%.9f", len[n2]))


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	int ans=0,cnt=0;
	for(int i=0;i<n;++i) {
		if(i>0&&a[i]!=a[i-1]) {
			ans+=(cnt/2);
			cnt=1;
		}
		else ++cnt;
	}
	ans+=cnt/2;
	cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 400000;





int main() {
	
	ll N, T;
	cin >> N >> T;
	
	ll A[4000], B[4000];
	repn(i, N) cin >> A[i] >> B[i];

	ll dp[4000][4000] = {};

	repn(i,N) {
		rep(t, T + 1) {
			if (t < A[i]) { dp[i][t] = dp[i - 1][t]; }
			else { dp[i][t] = max(dp[i - 1][t], dp[i-1][t - A[i]] + B[i]); }

		}

	}

	ll ans[4000][4000] = {};

	repn(i, N) {
		rep(t, T + 1) {
			if (t < A[i]) { ans[i][t] = max(ans[i - 1][t], dp[i - 1][t] + B[i]); }
			else {
				ans[i][t] =max( max(ans[i - 1][t], ans[i - 1][t - A[i]] + B[i]),dp[i - 1][t] + B[i]);
			}
		}
	}

	cout << ans[N][T - 1];

	system("PAUSE");

}

Measured memory_bytes: 250488
#include<bits/stdc++.h>
using namespace std;
int dig(int a){
    int ret=0;
    while(a){
        a/=10;
        ret++;
    }
    return ret;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,n;
    cin>>a>>b;
    n=b;
    for(int i=0;i<dig(b);i++){
        a*=10;
    }
    n+=a;
    for(int i=1;i*i<=n;i++){
        if(i*i==n){cout<<"Yes";return 0;}
    }
    cout<<"No";return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"reflect"
	"sort"
)

func f(i int) int {
	r := 0
	for i > 0 {
		r += i % 10
		i /= 10
	}
	return r
}

func main() {
	defer writer.Flush() // Use printf, scanf

	// CODE
	var N int
	ans := 10000000000
	scanf("%d\n", &N)
	for i := 1; i <= N/2; i++ {
		j := N - i
		if j < 1 {
			continue
		}
		ans = minInt(f(i)+f(j), ans)
	}
	printf("%d\n", ans)
}

// I/O {{{
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

// }}}
// Math {{{
func maxInt(x int, y int) int {
	if x > y {
		return x
	}
	return y
}

func minInt(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

// }}}
// {{{ dummy
func dummy() {
	fmt.Printf("Hello, World\n")
	fmt.Printf("%v", reflect.TypeOf(0))

	arr := []int{10, 9, 8, 7, 1}
	sort.Ints(arr)
	fmt.Println(arr)
}

// }}}
// PriorityQueue {{{
// Usage:
// type Person struct {
// 	name string
// 	age  int
// }
//
// func (p1 Person) Less(p2 interface{}) bool {
// 	return p1.age < p2.(Person).age
// }
//
// func main() {
// 	sc.Split(bufio.ScanWords)
// 	defer out.Flush() // Use printf
//
// 	// CODE
// 	q := NewPriorityQueue()
// 	q.Push(Person{name: "B", age: 11})
// 	q.Push(Person{name: "A", age: 10})
// 	q.Push(Person{name: "C", age: 12})
//
// 	for q.Len() > 0 {
// 		p := q.Pop().(Person)
// 		printf("%s %d\n", p.name, p.age)
// 	}
// }
func NewPriorityQueue() *PriorityQueue {
	q := &PriorityQueue{s: new(sorter)}
	heap.Init(q.s)
	return q
}

func (q *PriorityQueue) Pop() Comparable {
	return heap.Pop(q.s).(Comparable)
}

func (q *PriorityQueue) Top() Comparable {
	if len(*q.s) > 0 {
		return (*q.s)[0].(Comparable)
	}
	return nil
}

func (q *PriorityQueue) Fix(x Comparable, i int) {
	(*q.s)[i] = x
	heap.Fix(q.s, i)
}

func (q *PriorityQueue) Remove(i int) Comparable {
	return heap.Remove(q.s, i).(Comparable)
}

func (q *PriorityQueue) Len() int {
	return q.s.Len()
}

type Comparable interface {
	Less(other interface{}) bool
}

type sorter []Comparable

func (s *sorter) Push(x interface{}) {
	*s = append(*s, x.(Comparable))
}

func (s *sorter) Pop() interface{} {
	n := len(*s)
	if n > 0 {
		x := (*s)[n-1]
		*s = (*s)[0 : n-1]
		return x
	}
	return nil
}

func (s *sorter) Len() int {
	return len(*s)
}

func (s *sorter) Less(i, j int) bool {
	return (*s)[i].Less((*s)[j])
}

func (s *sorter) Swap(i, j int) {
	(*s)[i], (*s)[j] = (*s)[j], (*s)[i]
}

// Define priority queue struct
type PriorityQueue struct {
	s *sorter
}

func (q *PriorityQueue) Push(x Comparable) {
	heap.Push(q.s, x)
}

// }}}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer cout<<endl<<"answer : ";
#define maxn 100005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0;string s;bool flag=false;
        cin>>n; lld a[n]; for(i=0;i<n;i++) {cin>>a[i];cnt+=a[i];}
        map<lld,lld> mps;
        for(i=0;i<n;i++)
            if(mps.find(a[i])==mps.end())
                mps[a[i]]=1;
            else
                mps[a[i]]++;
        cin>>q;
        while(q--)
        {
            cin>>x>>y;
            if(mps.find(x)!=mps.end())
            {
                cnt-=mps[x]*x;
                cnt+=mps[x]*y;
                if(mps.find(y)==mps.end())
                    mps[y]=mps[x];
                else
                    mps[y]+=mps[x];
                mps[x]=0;
            }
            cout<<cnt<<endl;
        }


    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 9536
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def bfs(K):
    number = list(range(10))
    q = deque(list(range(1, 10)))

    cnt = 0
    while cnt < K:
        i = q.popleft()
        cnt += 1
        if cnt == K:
            return i

        last = int(str(i)[-1])
        for n in number:
            if abs(last - n) <= 1:
                next = str(i) + str(n)
                next = int(next)
                q.append(next)


def main():
    K = int(input())
    ans = bfs(K)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16800
#include <math.h>
#include <algorithm>  //sort,二分探索,など
#include <array>
#include <bitset>         //固定長bit集合
#include <cmath>          //pow,logなど
#include <complex>        //複素数
#include <deque>          //両端アクセスのキュー
#include <functional>     //sortのgreater
#include <iomanip>        //setprecision(浮動小数点の出力の誤差)
#include <iostream>       //入出力
#include <map>            //map(辞書)s
#include <numeric>        //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>          //キュー
#include <set>            //集合
#include <stack>          //スタック
#include <string>         //文字列
#include <unordered_map>  //イテレータあるけど順序保持しないmap
#include <unordered_set>  //イテレータあるけど順序保持しないset
#include <utility>        //pair
#include <vector>         //可変長配列

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())  // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define MAX(a, b)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int count = 0;
  for (int i = A; i <= B; ++i) {
    if (i % K == 0) count++;
  }
  if (count != 0) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3600
#include <iostream>
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
using namespace std;


int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,m,n,k;
     ll t;
     cin>>n>>k;
     n=n%k;
     cout<<min(n,k-n);
}


Measured memory_bytes: 256
// ITP1_7_A Grading
import java.io.*;

public class Main {

   public static void main(String[] args) {
      int m = 0, f = 0, r = 0;
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         while (true){
            String[] strAry = br.readLine().split(" ");
            m = Integer.parseInt(strAry[0]);
            f = Integer.parseInt(strAry[1]);
            r = Integer.parseInt(strAry[2]);

            if (m == -1 && f == -1 && r == -1)  break;

            System.out.printf("%s\n", judge(m, f, r));
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }

   private static String judge(int m, int f, int r) {
      if ((m == -1 || f == -1) || m + f < 30)
         return "F";
      else if (m + f < 50) {
         if (r >= 50)
            return "C";
         else
            return "D";
      }
      else if (m + f < 65)
         return "C";
      else if (m + f < 80)
         return "B";
      else
         return "A";
   }
}

Measured memory_bytes: 17040
#!/usr/bin/python
# -*- coding: utf-8 -*-

import numpy as np

def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(list(input()))
    return np.array(x)

A,B,C = map(int,input().split())
K = int(input())

for i in range(0,K):
    if A >= B:
        B = 2*B
    else:
        if B >= C:
            C = 2*C
    if C > B and B > A:
        print('Yes')
        exit()

print('No')




Measured memory_bytes: 27180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef pair<int,int> P;
map<int,int> mp;
int N,M,a[10001],b[10000];
int seginc(int l,int r){
	int x=upper_bound(a,a+M+1,l)-a-1;
	if(r<=a[x+1]) return x;
	return -1;
}
int query(int l,int r,int k,int L,int j){
	if(j+L==N && mp.count(k)) return mp[k];
	int in=seginc(l,r);
	int ret=0;
	if(in>=0){
		if(j==b[in]) ret=(r-l)-1;
		else if(b[in]>N-L) ret=(r-l)-( 1<<(b[in]-(N-L)-1) );
		else ret=r-l;
	}else{
		int x=query(l,(l+r)/2,k*2,L-1,j)+query((l+r)/2,r,k*2+1,L-1,N-L+1);
		int y=query(l,(l+r)/2,k*2,L-1,N-L+1)+query((l+r)/2,r,k*2+1,L-1,j);
		ret=min(x,y);
	}
	if(j+L==N) mp[k]=ret;
	return ret;
}
int main(){
	cin>>N>>M;
	rep(i,M+1) cin>>a[i];
	rep(i,M) cin>>b[i];
	cout<<query(0,1<<N,1,N,0)<<endl;
}

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

using namespace std;

template <typename M>
struct SegTree {
    using Op = function<M(const M&, const M&)>;
    M ID; // monoid identity
    Op op; // associative operation
    int N; // 2^lg space, for non-commutative
    vector<M> a;
    
    SegTree(int n, M leaf_default, M _ID, Op _op) : ID(_ID), op(_op) {
        init_space(n);
        fill(a.begin() + N, a.begin() + N + n, leaf_default);
        build();
    }
    SegTree(const vector<M> leaves, M _ID, Op _op) : ID(_ID), op(_op) {
        int n = leaves.size();
        init_space(n);
        copy(leaves.begin(), leaves.end(), a.begin() + N);
        build();
    }
    void init_space(int n) {
        N = 1; while (N < n) N<<=1;
        a.assign(N<<1, ID);
    }
    inline void pull(int i) { a[i] = op(a[i<<1], a[i<<1|1]); }
    void build() { for (int i = N-1; i >= 1; i--) pull(i); }

    void assign(int p, M val) {
        assert(0 <= p && p < N);
        for (a[p += N] = val; p >>= 1;) pull(p);
    }
    void better(int p, M val) {
        assert(0 <= p && p < N);
        p += N;
        for (a[p] = op(a[p], val); p >>= 1;) pull(p);
    }
    M query(int l, int r) const {
        assert(0 <= l && r <= N);
        M resl(ID), resr(ID);
        for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
            if (l & 1) resl = op(resl, a[l++]);
            if (r & 1) resr = op(a[--r], resr);
        }
        return op(resl, resr);
    }
    M query_point(int p) const { 
        assert(0 <= p && p < N);
        return a[p + N];
    }
    M query_all() const { return a[1]; }
};
using ll=long long;
void solve() {
    int n,q,A,B;
    cin >> n >> q >> A >> B;
    vector<int> a(q+1);
    a[0] = A;
    for (int i = 1; i <= q; i++) {
        cin >> a[i];
    }

    SegTree<ll> s (n+3, 1e18, 1e18,
            [](ll u, ll v){ return min(u,v); }
            );
    auto t = s;

    s.assign(B, -B);
    t.assign(B, +B);
    ll sum = 0;
    for (int i = 1; i <= q; i++) {
        int z = a[i];
        ll val = min(z + s.query(1, z), t.query(z, n+1) - z);
        ll d = abs(z - a[i-1]);
        sum += d;
        z = a[i-1];
        s.better(z, val-z - d);
        t.better(z, val+z - d);
    }
    ll res = 1e18;
    for (int i = 1; i <= n; i++) {
        ll val = i + s.query_point(i);
        res = min(res, val);
    }
    cout << res + sum;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <functional>
#define fs first
#define se second

#ifdef imeimi
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

const int mod = 998244353;

void add(int &x, int y) {
    x = (x + y) % mod;
}

int mul(int x, int y) {
    return (llong)x * y % mod;
}

int pw(int x, int p) {
    int r = 1;
    while (p) {
        if (p & 1) r = mul(r, x);
        x = mul(x, x);
        p >>= 1;
    }
    return r;
}

const int mx = 1e6;
int n;
int A[200001];
int cnt[mx + 1];
int sum1[mx + 1];
int sum2[mx + 1];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
        ++cnt[A[i]];
    }
    for (int i = 1; i <= mx; ++i) {
        sum1[i] = mul(i, cnt[i]);
        sum2[i] = mul((llong)i * i % mod, cnt[i] * (cnt[i] - 1ll) / 2 % mod);
    }
    for (int i = 1; i <= mx; ++i) {
        for (int j = i + i; j <= mx; j += i) {
            add(sum2[i], sum2[j]);
            add(sum2[i], mul(sum1[i], sum1[j]));
            add(sum1[i], sum1[j]);
        }
        //debug("%d : %d %d\n", i, sum1[i], sum2[i]);
    }
    int ans = 0;
    for (int i = mx; i > 0; --i) {
        for (int j = i + i; j <= mx; j += i) {
            add(sum2[i], mod - sum2[j]);
        }
        add(ans, mul(sum2[i], pw(i, mod - 2)));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 12800
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 200005
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct st{
	int x,y;
}a[MN];
int x[MN],y[MN],d[MN];
int cnt=0,tot=0,pos,xa,ya,xb,yb,n;
double res;
inline bool cmp(st a,st b){return a.x<b.x;}
const double pi=acos(-1);
int main()
{
	xa=in();ya=in();xb=in();yb=in();n=in();
	if (xa>xb||(xa==xb&&ya>yb)) swap(xa,xb),swap(ya,yb);
	for (int i=1;i<=n;++i) x[i]=in(),y[i]=in();
	for (int i=1;i<=n;++i){
		if (x[i]>=min(xa,xb)&&x[i]<=max(xa,xb)&&y[i]>=min(ya,yb)&&y[i]<=max(ya,yb))
		a[++cnt].x=x[i],a[cnt].y=y[i];
	}sort(a+1,a+cnt+1,cmp);
	if (ya<yb){
		for (int i=1;i<=cnt;++i){
			if (a[i].y>=d[tot]) d[++tot]=a[i].y;
			else pos=lower_bound(d+1,d+tot+1,a[i].y)-d,d[pos]=a[i].y;
		}res=100.0*(abs(xa-xb)+abs(ya-yb))-20.0*tot+5.0*pi*tot;
		if (tot==min(abs(xa-xb),abs(ya-yb))+1) res=res+5.0*pi;
	}else {
		for (int i=cnt;i;--i){
			if (a[i].y>=d[tot]) d[++tot]=a[i].y;
			else pos=lower_bound(d+1,d+tot+1,a[i].y)-d,d[pos]=a[i].y;
		}res=100.0*(abs(xa-xb)+abs(ya-yb))-20.0*tot+5.0*pi*tot;
		if (tot==min(abs(xa-xb),abs(ya-yb))+1) res=res+5.0*pi;
	}printf("%.15lf",res);return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define ii pair<int,int>

ll number_of_divisors(ll n)
{
    ll ans = 1;

	for (ll i=2; i*i <= n; i++){
		if (n%i != 0) continue;
		ll cnt = 0;
		while (n%i == 0){
			n /= i;
			cnt++;
		}
		ans *= (cnt+1);
	}
	if (n > 1){
		ans *= 2;
	}
	return ans;
}
ll aa[1000004]; ll bb[200004];
int main()
{
    io;
    ll a,b,c,d,m,n,i,j,k,l,t,x,y,z;
    ll ans=0;
    ll maxi=INT_MIN; ll mini=INT_MAX,sum=0,mul=1;

        vector<ll>vec;
        string st,ch;
        maxi=INT_MIN, mini=INT_MAX;
        sum=0,mul=1;
        cin>>n;
        x=n;
        for(i=0;i<=1000000;i++) aa[i]=0;
        while(n--)
        {
            if(aa[n]==0)
            {
            a=number_of_divisors(n);
            aa[n]=a;
            }
            sum+=aa[n];
            if(n==1) break;
        }
        cout<<sum<<endl;

    return 0;
}






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

using namespace std;

inline int read()
{
	int x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=1e5+9;
const int D=19;

int n,m,q,c,col[N];
int to[N<<1],nxt[N<<1],beg[N],tot;
bool vis[N][D];

struct query
{
	int v,d,c;
}qu[N];

inline void add(int u,int v)
{
	to[++tot]=v;
	nxt[tot]=beg[u];
	beg[u]=tot;
}

inline void dfs(int u,int frm,int dis,int c)
{
	if(dis<0)return;
	vis[u][dis]=1;if(!col[u])col[u]=c;
	for(int i=beg[u];i;i=nxt[i])
		if(!vis[to[i]][dis-1] && to[i]!=frm)
			dfs(to[i],u,dis-1,c);
}

int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	n=read();m=read();
	for(int i=1,u,v;i<=m;i++)
	{
		u=read();v=read();
		add(u,v);add(v,u);
	}
	q=read();
	for(int i=1;i<=q;i++)
		qu[i].v=read(),qu[i].d=read(),qu[i].c=read();
	for(int i=q;i>=1;i--)
		if(!vis[qu[i].v][qu[i].d])
			dfs(qu[i].v,0,qu[i].d,qu[i].c);
	for(int i=1;i<=n;i++)
		printf("%d\n",col[i]);
	return 0;
}


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

typedef long long  LL;
struct edge{int s,t,d,n;}e[200010];
int n,m,h[100010],col[100010],s0,s1,s2,error,tot;
LL ans;

void dfs(int x)
{
	col[x]?(col[x]==1?s1++:s2++):s0++;
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n,tot++)
		if (col[y]==-1)  col[y]=(col[x]+e[i].d)%3,dfs(y);
		else  if (col[y]!=(col[x]+e[i].d)%3)  error=1;
}

void work()
{
	scanf("%d %d",&n,&m);
	for (int i=1,x,y; i<=m; i++)
		{
			scanf("%d %d",&x,&y);
			e[++tot]=(edge){x,y,1,h[x]},h[x]=tot;
			e[++tot]=(edge){y,x,2,h[y]},h[y]=tot;
		}
	memset(col,-1,sizeof(col));
	for (int i=1; i<=n; i++)
		if (col[i]==-1)
			{
				s0=s1=s2=error=tot=0,col[i]=0,dfs(i);
				if (error)  ans+=1LL*(s0+s1+s2)*(s0+s1+s2);
				else  if ((!s1)||(!s2))  ans+=tot/2;
				else  ans+=1LL*s0*s1+1LL*s0*s2+1LL*s1*s2;
			}
	printf("%lld",ans);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 7296
import java.util.Scanner;
public class Main {

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

		int a = stdIn.nextInt();

		int b = stdIn.nextInt();

		int h = stdIn.nextInt();

		int m = stdIn.nextInt();


		double thour = 30 * h + 30 * m / 60.0;

		double mhour = 6 * m;


		double kakudo = (Math.abs(thour - mhour))<180 ?Math.abs(thour - mhour):360-(Math.abs(thour - mhour));
		
	
		double tmp = b * b + a * a - (2 * a * b * Math.cos(Math.toRadians(kakudo))); 

		
		System.out.println(Math.sqrt(tmp));
		
	}

}


Measured memory_bytes: 36028
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
vector<pair<pair<int,int>, pair<int,int>>> ans;
int main(){
    cout << fixed << setprecision(10);
    int h,w;
    cin >> h >> w;
    vector<vector<int>> v(h,vector<int>(w));
    rep(i,h) rep(j,w) cin >> v[i][j];
    int i = 0, j = 0;
    int itr = 0;
    while(itr < h*w){
        if(v[i][j] & 1){
            int ni = i, nj = j;
            if(ni % 2 == 0){
                if(nj < w-1) nj++;
                else ni++;
            }else{
                if(nj > 0) nj--;
                else ni++; 
            }
            if( ni < h && nj < w){
                ans.push_back(make_pair(make_pair(i+1,j+1),make_pair(ni+1,nj+1)));
                v[ni][nj] ++;
            }
            i = ni, j = nj;
            itr++;
        }else{
            int ni = i, nj = j;
            if(ni % 2 == 0){
                if(nj < w-1) nj++;
                else ni++;
            }else{
                if(nj > 0) nj--;
                else ni++;  
            }
            i = ni, j = nj;
            itr++;           
        }
    }
    cout << ans.size() << endl;
    for(auto u : ans){
        cout << u.first.first << " " << u.first.second << " " << u.second.first << " " << u.second.second << endl;
    }
    return 0;
}

Measured memory_bytes: 6344
#include<bits/stdc++.h>
/*
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 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> p;
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;
std::cin >> n;
std::vector<int> out;
int last = 1;
int sum = 0;
int it = 0;
while(n >= (last << 1) - 1){
    last = last << 1;
    it++;
}
sum = last - 1;
int dis = n - sum;

std::vector<int> flag;
int check = 1;
int poi = 0;
int ar = 0;
while(dis >= check){
    if((dis & check) == check){
        flag.pb(poi);
        ar++;
    }
    poi++;
    check = check << 1;
}
int ito = 1;
int itf = 0;

while(it >= ito){
    if((itf < ar) && (flag[itf] == ito - 1)){
        out.pb(it + ar - itf);
        itf++;
    }
    out.pb(ito);
    ito++;
}
int l = out.size();
for(int i = 0; i < l; i++){
    out.pb(i + 1);
}
std::cout << out.size() << std::endl;
for(int i = 0; i < out.size() - 1; i++){
    std::cout << out[i] << " ";
}
std::cout << out[out.size() - 1] << std::endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int s;

int func(int n){
    if(n%2==0){
        return n/2;
    }else{
        return 3*n+1;
    }
}

int main()
{
    int n,m,ans=0;
    int x[100005]={},s[100005]={};
    cin>>n>>m;
    rep(i,m)cin>>x[i];
    if(m==1){
        cout<<0<<endl;
        return 0;
    }
    sort(x,x+m);
    rep(i,m-1)s[i] = abs(x[i] - x[i+1]);
    sort(s,s+m);
    rep(i,m-n+1){
        ans+=s[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024