akhauriyash/Code-Regression huggingface dataset:
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)              cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)              cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)          cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    std::vector<string> t={"dream","dreamer","erase","eraser"};
    string s;
    cin >> s;
    for(ll i=0; i<4; i++){
        reverse(all(t[i]));
    }
    reverse(all(s));
    string z="";
    for(ll i=0; i<s.size(); i++){
        z+=s[i];
        for(ll j=0; j<4; j++){
            if(z==t[j]) z="";
        }
    }
    if(z=="") cout << "YES";
    else cout << "NO";
    return 0;
}
/* The judge is never wrong! Your code is buggy 
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

map<int, map<int, int>> mem;

int C(int n, int k) {
  if (k == 1) return n;
  if (k == n) return 1;
  if (mem[n][k]) return mem[n][k];
  return mem[n][k] = C(n - 1, k - 1) + C(n - 1, k);
}

void solve() {
  int n, l, r;
  cin >> n >> l >> r;
  vector<double> a(n);
  for (auto &i : a) cin >> i;
  sort(all(a), greater<int>());
  double sum = 0;
  for (int i = 0; i < l; i++) {
    sum += a[i];
  }
  cout << fixed << setprecision(10);
  cout << sum / l << '\n';
  int al = 0, il = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == a[l - 1]) {
      al++;
      if (i < l) il++;
    }
  }
  int ans = 0;
  if (il == l) {
    for (int i = l; i <= min(al, r); i++) {
      ans += C(al, i);
    }
  } else {
    ans = C(al, il);
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3808
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vint;
#define mp make_pair
#define fst first
#define scn second
const int inf=1e9;
int color[10010];
int findparent(int i){
    return (i==color[i]?i:color[i]=findparent(color[i]));
}
void merge(int i,int j){
    i=findparent(color[i]);
    j=findparent(color[j]);
    color[j]=i;
}
int main(){
    int v,e;    cin>>v>>e;
    priority_queue<pair<int,pii > > pq;
    for(int i=0;i<e;i++){
        int s,t,w;  cin>>s>>t>>w;
        pq.push(mp(-w,mp(s,t)));
    }
    for(int i=0;i<v;i++)    color[i]=i;
    int ret=0;
    while(!pq.empty()){
        auto it=pq.top();   pq.pop();
        int w=-it.fst;
        int s=it.scn.fst,t=it.scn.scn;
        if(findparent(s)==findparent(t))    continue;
        ret+=w;
        merge(s,t);
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 4492
import java.io.*;
import java.util.Scanner;

public class Main{
               public static void main(String args[]) throws IOException{
                     int a = 0;
                     int b = 0;
                     int c = 0;
                   
                     Scanner in = new Scanner(System.in);
                     
                     String buf1 = in.next();
                     String buf2 = in.next();
                     String buf3 = in.next();
                     
                     a = Integer.parseInt(buf1);
                     b = Integer.parseInt(buf2);
                     c = Integer.parseInt(buf3);
               
                     if(a < b && b < c){
                          System.out.println(a +" "+ b +" "+ c);
                     }else if(a < c && c < b){
                          System.out.println(a +" "+ c +" "+ b);
                     }else if(b < a && a < c){
                          System.out.println(b +" "+ a +" "+ c);
                     }else if(b < c && c < a){
                          System.out.println(b +" "+ c +" "+ a);
                     }else if(c < a && a < b){
                          System.out.println(c +" "+ a +" "+ b);
                     }else if(c < b && b < a){
                          System.out.println(c +" "+ b +" "+ a);
                     }else if(a == b && b < c){
                          System.out.println(a +" "+ b +" "+ c);
                     }else if(a == b && b > c){
                          System.out.println(c +" "+ a +" "+ b);
                     }else if(a == c && b > c){
                          System.out.println(a +" "+ c +" "+ b);
                     }else if(a == c && b < c){
                          System.out.println(b +" "+ a +" "+ c);
                     }else if(b == c && a > c){
                          System.out.println(b +" "+ c +" "+ a);
                     }else if(b == c && a < c){
                          System.out.println(a +" "+ b +" "+ c);
                     }else{
                          System.out.println(a +" "+ b +" "+ c);
                     }
                     
            }
 }

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

int const INF = 1<<29;

struct frame
{
  int fx, fy;
  int tx, ty;
  int id;
   
  frame(int fx, int fy, int tx, int ty, int id)
    : fx(fx), fy(fy), tx(tx), ty(ty), id(id) {}
};
 
inline bool cmpx(frame const& a, frame const& b) {
  if(a.fx!=b.fx) return a.fx < b.fx;
  if(a.ty!=b.ty) return a.ty < b.ty;
  return a.tx < b.tx;
}

int anscnt, ans[110];

void rec(vector<frame> curr) {

  if(curr.empty()) { return; }
  sort(curr.begin(), curr.end(), cmpx);
  
  frame tar = curr[0]; ans[tar.id] = anscnt ++;
  curr.erase(curr.begin());
  
  bool hit = 0;
  int rx = tar.tx;
  rep(i, curr.size()) {
    if(curr[i].ty == tar.ty) {
      rx = curr[i].tx;
    }
    else if(curr[i].fy >= tar.ty) { }
    else if(rx < curr[i].tx && curr[i].ty > tar.ty) {
      hit = 1;
      break;
    }
  }
  
  if(!hit) {
    rx = INF;
  }
  
  //  cerr << "tar.id: " << tar.id << ", " << tar.tx << " "<< rx << endl;
  
  vector<int> check(curr.size());
  rep(i, curr.size()) {
    if(curr[i].fx<rx && curr[i].ty <= tar.ty) {
      check[i] = 1;
    }
  }

  vector<frame> L, T;
  rep(i, curr.size()) {
    if(check[i]) {
      L.push_back(curr[i]);
    }
    else {
      T.push_back(curr[i]);
    }
  }
  
  //  cerr << "Lsize: " << L.size() << ", Tsize: " << T.size() << endl;
  
  rec(L), rec(T);
  
}
 
int main() {
  bool blank = 0;
  int N;
  while(cin >> N && N) {
    if(blank) { cout << endl; }
    blank = 1;
    anscnt = 1;
    vector<frame> v;
    rep(i, N) {
      int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
      v.push_back(frame(x1, y1, x2, y2, i+1));
    }
    rec(v);
    REP(i, 1, N+1) cout << ans[i] << endl;
  }
   
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  ll N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  REP(i, N) cin >> x[i] >> y[i] >> h[i];
  ll H;
  int id;
  REP(i, N) {
    if (h[i] != 0) {
      id = i;
      continue;
    }
  }
  REP(Cx, 101) REP(Cy, 101) {
    H = h[id] + abs(x[id] - Cx) + abs(y[id] - Cy);
    if (H <= 0) continue;
    bool t = true;
    REP(i, N) {
      int tmp = H - abs(x[i] - Cx) - abs(y[i] - Cy);
      tmp = max(0, tmp);
      if (tmp != h[i]) {
        t = false;
      }
    }
    if (t) {
      cout << Cx << " " << Cy << " " << H << endl;
    }
  }
}

Measured memory_bytes: 3612
n = int(input())
l=[]
for i in range(n):
    l.append(int(input()))
#print(l)
a = l.index(max(l))
b = max(l)
l.pop(a)
c = max(l)
for i in range(n):
    if i != a:
        print(b)
    else:
        print(c)

Measured memory_bytes: 12512
#include <bits/stdc++.h>
#define R cin>>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long unsigned int ll;
int main(){
    int n, d, x;
    R n;
    cin>>d>>x;
    int a, ans=n;
    rep(i, n){
        R a;
        int temp = d - a;
        while(temp > 0){
            ans += 1;
            temp -= a;
        }
        //ans += d/a;
    }
    ans += x;
    printf("%d", ans);

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    rep(i, N+1){
        rep(j, N+1){
            int rem = N-R*i-G*j;
            if(rem >= 0 && rem%B == 0) ans++;
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const ll INF = 100100;
const int MAX = 1000;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}

struct Edge {
    int to;  // 辺の行き先
    ll cap; // 辺の容量 
    int rev; // G[e.to][e,rev]は逆辺の構造体にアクセスする
};

vector<Edge> G[MAX];
bool used[MAX];

void add_edge(int from, int to, ll cap) { // from-to間の流量をcapで設定、お互いにアクセス可能にする
    Edge e1, e2;
    e1.to = to; e1.cap = cap; e1.rev = (int)(G[to].size()); 
    e2.to = from; e2.cap = cap; e2.rev = (int)(G[from].size()); // 有向グラフにする時はe2.cap=0にする
    G[from].push_back(e1);
    G[to].push_back(e2);
}

ll dfs(int s, int t, ll f) { // sからtへ行くルートの最大流量、これ以上ルートがないとき0
    if (s == t) return f;

    used[s] = true;
    REP (i, G[s].size()) {
        Edge& e = G[s][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }

    return 0;
}

ll ford_fulkerson(int s, int t) { // sからtへの最大流量を返す
    ll flow = 0;
    while (1) {
        Fill(used, false);
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}

int H, W;
string A[MAX];

inline int x_of(int x) { return x; }
inline int y_of(int y) { return y + W; }

ll solve() {
    int s = H+W+1, t = H+W+2;

    int x = -1, y = -1;
    REP (h, H) REP (w, W) {
        if (A[h][w] == 'S') {
            add_edge(s, x_of(w), INF);
            add_edge(s, y_of(h), INF);
        } else if (A[h][w] == 'T') {
            add_edge(x_of(w), t, INF);
            add_edge(y_of(h), t, INF);
        } else if  (A[h][w] != '.') {
            add_edge(x_of(w), y_of(h), 1);
        }
    }

    ll ans = ford_fulkerson(s, t);
    if (ans >= INF) return -1;
    return ans;
}

int main() {
    cin >> H >> W;
    REP (i, H) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        ll N;
        is >> N;
        if(!is) return;
        vector<int> ans(N);
        for (int i = 0; i < N; ++i) {
            int a;
            is >> a;
            ans[a-1] = i+1;
        } // end i
        os << ans;

    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_C.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)

int main()
{
    long t = 1;
    //cin >> t;

    while (t--) {
        long n;
        cin >> n;

        double ans = pow(double(n) / 3, 3);
        printf("%.10f\n", ans);
    }
}


Measured memory_bytes: 4140
main();

sub main {
    my $n = <STDIN>;
    chomp $n;
    my $max = 0;
    my %words;
    for (my $i = 0; $i < $n; $i++) {
        my $word = <STDIN>;
        chomp $word;
        $words{$word}++;
        $max++ if $words{$word} > $max;
    }
    foreach my $word (sort keys %words) {
        print "$word\n" if $words{$word} == $max;
    }
}

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

word = [input() for i in range(N)]

yes = 0

for i in range(N-1):
  if (word.count(word[i]) > 1 or word.count(word[-1]) > 1):
    break
  if word[i][-1] == word[i+1][0]:
    yes += 1
    continue
  else:
    break

if yes == N-1:    
  print('Yes')
else:
  print('No')
    

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

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;

int arr[13][NMAX], cost[13],done[13];
int n,m,p,q,k,a,b,c,ans,x;
string s,str;
char ch;
vector<int> v;

void solve()
{
    cin>>n>>m>>x;

    int ans = 1e18;

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

    for(int i=0;i<(1LL<<n);i++){
        for(int i=0;i<m;i++){
            done[i] = 0;
        }
        int sum = 0;
        for(int j=0;j<=12;j++){

            if( ((1LL<<j) & (i)) != 0){
                sum += cost[j];

                for(int k=0;k<m;k++){
                    done[k] += arr[j][k];
                }
            }
        }
        bool np = 0;
        for(int i=0;i<m;i++){
            if(done[i] < x){
                np = 1;
                break;
            }
        }

        if(!np){
            ans = min(sum,ans);
        }
    }
    if(ans == 1e18){
        cout<<"-1";
    }else{
        cout<<ans;
    }
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

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

// prototype declaration
int digit_calc(int);
int judge(int, int);

int main(void) {
    int N, digits;
    cin >> N;
    digits = digit_calc(N);  // 桁数の計算
    int sum_digits = 0;

    {
        int N_in_block = N, j = digits;
        // cout << "N_in: " << N_in_block << digits << endl;

        for (int i = 0; i < digits; i++) {
            int maxdigit = std::pow(10, j-1);
            if (i == digits - 1) {
                sum_digits += N_in_block;
                break;
            }
            sum_digits += N_in_block / maxdigit;
            // 最大桁の数を引く 234 なら 234 - 200
            N_in_block -= (N_in_block / maxdigit) * maxdigit;
            j--;
        }
    }
    judge(N, sum_digits);

    return 0;
}

int digit_calc(int N) {
    // 桁数の計算 10で割れるだけ割っていく
    int digit = 0;
    while (N != 0) {
        N /= 10;
        digit++;
    }
    return digit;
}

int judge(int N, int sum_digits) {
    if (N % sum_digits == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_11_C
 */
#include <iostream>
#include <vector>
#include <map>

using namespace std;

class Die
{
    enum fname {
        top, front, right, left, back, bottom,
    };

    vector<int> faces;
    map<fname, int> f2i;

    void
    turn_e() {
        int tmp = f2i[top];
        f2i[top] = f2i[left];
        f2i[left] = f2i[bottom];
        f2i[bottom] = f2i[right];
        f2i[right] = tmp;
    }

    void
    turn_n() {
        int tmp = f2i[top];
        f2i[top] = f2i[front];
        f2i[front] = f2i[bottom];
        f2i[bottom] = f2i[back];
        f2i[back] = tmp;
    }

    void
    turn_s() {
        int tmp = f2i[top];
        f2i[top] = f2i[back];
        f2i[back] = f2i[bottom];
        f2i[bottom] = f2i[front];
        f2i[front] = tmp;
    }

    void
    turn_w() {
        int tmp = f2i[top];
        f2i[top] = f2i[right];
        f2i[right] = f2i[bottom];
        f2i[bottom] = f2i[left];
        f2i[left] = tmp;
    }

public:
    Die()
    {
        faces.reserve(6);

        f2i.emplace(top, 0);
        f2i.emplace(front, 1);
        f2i.emplace(right, 2);
        f2i.emplace(left, 3);
        f2i.emplace(back, 4);
        f2i.emplace(bottom, 5);
    }

    ~Die()
    {
        faces.clear();
        f2i.clear();
    }

    void
    read_faces(istream &is) {
        for (int i = 0; i < 6; i++) {
            is >> faces[i]; is.ignore();
        }
    }

    bool
    operator==(Die &x) {
        const string aface = "NENEN";
        for (auto it = aface.cbegin(); it != aface.cend() && faces[f2i[top]] != x.Front(); it++) {
            turn(*it);
        }
        if (faces[f2i[top]] != x.Front()) { return false; }

        turn_s();
        const string roll = "EEE";
        for (auto it = roll.cbegin(); it != roll.cend() && faces[f2i[top]] != x.Top(); it++) {
            turn(*it);
        }
        if (faces[f2i[top]   ] != x.Top()   ) { return false; }
        if (faces[f2i[right] ] != x.Right() ) { return false; }
        if (faces[f2i[left]  ] != x.Left()  ) { return false; }
        if (faces[f2i[back]  ] != x.Back()  ) { return false; }
        if (faces[f2i[bottom]] != x.Bottom()) { return false; }
        return true;
    }

    void
    turn(const char c) {
        switch (c) {
          case 'N':
            turn_n();
            break;
          case 'E':
            turn_e();
            break;
          case 'S':
            turn_s();
            break;
          case 'W':
            turn_w();
            break;
        }
    }

    int Top()    { return faces[f2i[top]   ]; }
    int Front()  { return faces[f2i[front] ]; }
    int Right()  { return faces[f2i[right] ]; }
    int Left()   { return faces[f2i[left]  ]; }
    int Back()   { return faces[f2i[back]  ]; }
    int Bottom() { return faces[f2i[bottom]]; }
};

int
main()
{
    ios::sync_with_stdio(false);

    Die d1, d2;
    d1.read_faces(cin);
    d2.read_faces(cin);

    cout << (d1 == d2 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3176
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d",&a,&b);
    if(a<b){
        c=a;a=b;b=c;
    }
    while(1){
        c=a%b;
        if(c==0)break;
        a=b;
        b=c;
    }
    printf("%d\n",b);
    return 0;
}

Measured memory_bytes: 1024
'use strict';
(function(stdin) {
  var lines  = stdin.toString().split('\n');
  var result = (function(data) {

    return data.filter(function(v) {
        return parseInt(v,10);
      })
     .map(function(v) {
        return v.split('')
          .map(Number)
          .reduce(function(a,b) {
            return a + b;
        });
     }).join('\n');
  
  }(lines
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 8656
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main()
 {  
    FIO
    int n,q; cin>>n>>q;
    string str; cin>>str;
    int arr[str.size()+1]={0};
    int l,r;
    REP(i,1,str.size()) if(str[i] == 'C' and str[i-1] == 'A') arr[i+1] = 1;
    REP(i,2,str.size() + 1) arr[i] += arr[i-1];
    while(q--) {
        cin>>l>>r;
        cout<<arr[r] - arr[l]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 4112
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  ld L;
  cin >> L;
  ld a = L / 3.0;
  cout << a * a * a << endl;
  return 0;
}

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

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    vector<pii> Ai(N);
    REP(i, N) Ai[i] = pii(A[i], i);
    sort(rall(Ai));

    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1));
    REP(k, N) {
        int Ap, p;
        tie(Ap, p) = Ai[k];
        REP(i, k + 1) {
            int j = k - i;
            amax(dp[i + 1][j], dp[i][j] + (ll)Ap * (p - i));
            amax(dp[i][j + 1], dp[i][j] + (ll)Ap * (N - 1 - j - p));
        }
    }

    ll result = 0;
    REP(i, N + 1) {
        int j = N - i;
        amax(result, dp[i][j]);
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 34528
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,LL>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL vector<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
LL v[3];
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    cin>>v[0]>>v[1]>>v[2];
    sort(v,v+3);
    k=0;
    if(v[0]%2==v[2]%2)
    {
        if(v[0]%2==v[1]%2)
        {
            k=(v[2]-v[0])/2;
            k+=(v[2]-v[1])/2;
        }
        else
        {
            v[0]++;
            v[2]++;
            k++;
            k+=(v[2]-v[0])/2;
            k+=(v[2]-v[1])/2;
        }
    }
    else if(v[1]%2==v[2]%2)
    {
        if(v[0]%2==v[1]%2)
        {
            k+=(v[2]-v[0])/2;
            k+=(v[2]-v[1])/2;
        }
        else
        {
            v[1]++;
            v[2]++;
            k++;
            k+=(v[2]-v[0])/2;
            k+=(v[2]-v[1])/2;
        }
    }
     else if(v[1]%2==v[0]%2)
    {
        if(v[0]%2==v[2]%2)
        {
            k=(v[2]-v[0])/2;
            k+=(v[2]-v[1])/2;
        }
        else
        {
            v[1]++;
            v[0]++;
            k++;
            k+=(v[2]-v[0])/2;
            k+=(v[2]-v[1])/2;
        }
    }
    cout<<k<<endl;

    return 0;
}


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

int main(){
	int N,M;
  	cin >> N >> M;
	int K;
  	int T[M];
  	for(int j = 0; j < M;j++)T[j]=0;
    int A;
  
  	for(int i = 0; i<N;i++){
		cin >> K;
		for(int j = 0; j < K ;j++){
        	cin >> A;
              
          	
            for(int k = 0; k < M ; k++){
              //cout << A <<" "<<j+1 <<endl; 
	          	if(A==k+1){
    				//cout << j << endl;
        	    	T[k]=T[k]+1;

            	}
            }
        }
    }
  		
  	int ans = 0;
	for(int j = 0; j < M;j++){
			//cout << T[j] << " " ;
          	if(T[j]==N){
            	ans++;
            }
    }
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll dp[105][100005];
ll val(ll W,ll n,ll wt[],ll v[]){
        if(n==0||W==0)return 0;
        if(dp[n][W]!=-1)return dp[n][W];
        if(wt[n-1]>W)return dp[n][W]=val(W,n-1,wt,v);
        return dp[n][W]=max(v[n-1]+val(W-wt[n-1],n-1,wt,v),val(W,n-1,wt,v));
}
int main()
{
    ll n,W;
    cin>>n>>W;
    memset(dp,-1,sizeof(dp));
    ll wt[n],v[n];
    for(int i=0;i<n;i++)cin>>wt[i]>>v[i];
    cout<<val(W,n,wt,v)<<endl;
}


Measured memory_bytes: 82304
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,K=MI()
    A=LI_()
    dist = [inf]*N

    now = 0
    start = 0
    for i in range(N+2):
        if(dist[now] != inf):
            cycle = i - dist[now]
            if(K>=dist[now]):
                K-=dist[now] ##出発点をnowにする
                start = now
                K%=cycle
            break
        dist[now] = i
        now = A[now]
    for i in range(K):
        start = A[start]
    print(start+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 99912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    ll ans = 0;
    if (n == 1) {
        if (m == 1) ans = 1;
        else if (m == 2) ans = 0;
        else ans = m - 2;
    } else if (n == 2) ans = 0;

    if (m == 1) {
        if (n == 1) ans = 1;
        else if (n == 2) ans = 0;
        else ans = n - 2;
    } else if (m == 2) ans = 0;

    if (n >= 3 && m >= 3) ans = (n - 2) * (m - 2);

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


Measured memory_bytes: 256
N = gets.chomp.to_i
a = Array.new(N)
b = Array.new(N)
for i in 0...N do
    str = gets.split
    a[i],b[i] = str[0].to_i, str[1].to_i
end
d = 0
e = 0
for i in 0...N-1 do
    for j in i+1...N do
        aa = (a[i]-a[j])**2
        bb = (b[i]-b[j])**2
        d += Math.sqrt(aa+bb)
        e += 1
    end
end
d /= e*1.0
answer = d*(N-1)
puts answer

Measured memory_bytes: 1788
def abc167d_teleporter():
    n, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    cnts = [0] * (n + 1)
    i = 1
    nxt = 1
    while True:
        if cnts[a[nxt]] == 0:
            cnts[a[nxt]] = i
        else:
            val = (k - i) // (i - cnts[a[nxt]])
            k -= val * (i - cnts[a[nxt]])
        if i == k:
            break
        i += 1
        nxt = a[nxt]
    print(a[nxt])



abc167d_teleporter()

Measured memory_bytes: 32368
#include<bits/stdc++.h>
#define MAXN 2000010 
#define MAXM 2000010 
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;

int read()
{
	int res=0; char ch=getchar();
	while(ch<'0' || ch>'9') ch=getchar();
	while(ch>='0' && ch<='9')
	{
		res=res*10+ch-'0'; ch=getchar();
	}
	return res;
}

struct Edge
{
	int from,to,next,dist;
	Edge(){}
	Edge(int u,int v,int n,int d):from(u),to(v),next(n),dist(d){}
};

struct Node
{
	int d,u;
	bool operator < (const Node &rhs) const
	{
		return d>rhs.d;
	}
};

int n,m,num;
Edge edges[MAXM];
int head[MAXN],tot,vis[MAXN],dis[MAXN];
map<int,int> mp[MAXN];

void AddEdge(int u,int v,int dist)
{
	edges[tot]=Edge(u,v,head[u],dist);
	head[u]=tot++;
	edges[tot]=Edge(v,u,head[v],dist);
	head[v]=tot++;
}

void init()
{
	tot=0; num=n;
	memset(head,-1,sizeof(head));
}

void dijkstra(int s)
{
	memset(dis,0x3f,sizeof(dis));
	memset(vis,0,sizeof(vis));
	priority_queue<Node> q;
	dis[s]=0;
	q.push((Node){0,s});
	while(!q.empty())
	{
		Node x=q.top(); q.pop();
		int u=x.u;
		if(vis[u]) continue;
		vis[u]=1;
		for(int i=head[u];~i;i=edges[i].next)
		{
			Edge &e=edges[i];
			if(dis[e.to]>dis[u]+e.dist)
			{
				dis[e.to]=dis[u]+e.dist;
				q.push((Node){dis[e.to],e.to});
			}
		}
	}
}

int id(int a,int b)
{
	if(mp[a][b]) return mp[a][b];
	return mp[a][b]=++num;
}

int main()
{	
	n=read(),m=read();
	init();
	for(int i=0;i!=m;++i)
	{
		int u,v,com;
		u=read(),v=read(),com=read();
		AddEdge(u,id(u,com),1);
		AddEdge(v,id(v,com),1);
		AddEdge(id(u,com),id(v,com),0);
	}
	dijkstra(1);
	int ans;
	if(dis[n]==INF) ans=-1;
	else ans=dis[n]/2;
	printf("%d\n",ans);
}

Measured memory_bytes: 157560
#include<bits/stdc++.h>
#define maxn 2000006
#define mod 1000000007
using namespace std;

int x[6],y[6];
int fac[maxn]={1,1},inv[maxn]={1,1},invf[maxn]={1,1};
int C(int n,int m){ if(n<0||m<0||n-m<0) return 0;return fac[n] * 1ll * invf[m] % mod * invf[n-m]%mod; }
int P(int n,int m){ return C(n+m,n); }
int Py(int a,int b){ return (1ll * P(x[5]+1-a,y[5]+1-b) - P(x[4]-a,y[5]+1-b) - P(x[5]+1-a,y[4]-b) + P(x[4]-a,y[4]-b)) % mod; }
int Pz(int a,int b){ return (1ll * P(a-x[0]+1,b-y[0]+1) - P(a-x[1],b-y[0]+1) - P(a-x[0]+1,b-y[1]) + P(a-x[1],b-y[1])) % mod; }


int main(){
	for(int i=0;i<6;i++) scanf("%d",&x[i]);
	for(int i=0;i<6;i++) scanf("%d",&y[i]);
	for(int i=2;i<maxn;i++) fac[i] = 1ll * fac[i-1] * i % mod,
		inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod,
		invf[i] = 1ll * invf[i-1] * inv[i] % mod;
	int ans = 0;
	for(int i=x[2];i<=x[3];i++) ans = (ans + 1ll * Py(i,y[3]+1) * Pz(i,y[3]) % mod * (i+y[3]+1)) % mod;
	for(int i=x[2];i<=x[3];i++) ans = (ans - 1ll * Py(i,y[2]) * Pz(i,y[2]-1) % mod * (i+y[2])) % mod;
	for(int i=y[2];i<=y[3];i++) ans = (ans + 1ll * Py(x[3]+1,i) * Pz(x[3],i) % mod * (i+x[3]+1)) % mod;
	for(int i=y[2];i<=y[3];i++) ans = (ans - 1ll * Py(x[2],i) * Pz(x[2]-1,i) % mod * (i+x[2])) % mod;
	printf("%d\n",(ans+mod)%mod);
}

Measured memory_bytes: 23808
#include<iostream>
#include<string.h>
 
using namespace std;
 
bool p[50001];
int  cnt;
int  n;
 
void prime()
{
 
  for(int i = 2; i*i <= 50000; i++){
    if(!p[i]){
      for(int j = i*i; j <= 50000; j+=i){
        p[j] = true;
      }
    }
  }
  p[0] = p[1] = true;
}
 
int main(void)
{
 
  prime();
 
  while(cin >> n && n){
    cnt = 0;
    for(int i = 2; i <= n/2; i++){
      if(!p[i] && !p[n-i]){
        cnt++;
      }
    }
    cout << cnt << endl;
  }
 
  return 0;
}

Measured memory_bytes: 916
n=int(input())
l=[int(i) for i in input().split()]
c=[0]*8 
ind=0 
for i in l:
    if 1<=i<=399:
        c[0]+=1 
    if 400<=i<=799:
        c[1]+=1 
    if 800<=i<=1199:
        c[2]+=1 
    if 1200<=i<=1599:
        c[3]+=1 
    if 1600<=i<=1999:
        c[4]+=1 
    if 2000<=i<=2399:
        c[5]+=1 
    if 2400<=i<=2799:
        c[6]+=1 
    if 2800<=i<=3199:
        c[7]+=1 
    if i>=3200:
        ind+=1 
s=sum(i>0 for i in c)
#+=ind 
print(max(s,1),s+ind)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int x, y, z, k; cin >> x >> y >> z >> k;
    vector<long long> as(x), bs(y), cs(z);
    for(int i=0; i<x; ++i){
        cin >> as[i];
    }
    for(int i=0; i<y; ++i){
        cin >> bs[i];
    }
    for(int i=0; i<z; ++i){
        cin >> cs[i];
    }
    priority_queue<long long> anses_ab;
    for(int ai=0; ai<x; ++ai){
        for(int bi=0; bi<y; ++bi){
            anses_ab.push(as[ai]+bs[bi]);
        }
    }
    priority_queue<long long> anses_abc;
    for(int i=0; i<min(k, x*y); ++i){
        long long t=anses_ab.top(); anses_ab.pop();
        for(int ci=0; ci<z; ++ci){
            anses_abc.push(t+cs[ci]);
        }
    }

    for(int i=0; i<k; ++i){
        cout << anses_abc.top() << endl;
        anses_abc.pop();
    }
    return 0;
}


Measured memory_bytes: 42728
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int
main(void){  
  ios_base::sync_with_stdio(false);

  int q;
  cin >> q;
  REP(i, q){
    ll a, b;
    cin >> a >> b;
    ll c = pow(a*b, 0.5);
    
    if(a == b && a == c) cout << 2*a-2 << endl; 
    else if((a*b-1)/c == c) cout << 2*c-2 << endl; 
    else if(c*c == a*b) cout << 2*c-3 << endl; 
    else cout << 2*c-1 << endl;    
  }  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 1000040
   
const int  m = 1000033;
//const int  m2= 1000003;
//7069 - 60
char stack[MAX][15];
int h1(long long);
int h2(long long);
int insert(long long,int);
long long sti(char *);
   
int main(){
  int val,i,j,n,dic=0,dicc=MAX,index2=0,vall;
  char op[15],s[15];
  int exist=-1,index=0;
   
  while(scanf("%d",&n) != EOF){
    dic=0,dicc=MAX;
    for(i=0;i<=MAX;i++)strcpy(&stack[i][0],"not");
    for(i=0;i<n;i++){
      exist=-1;
      scanf("%s %s",op,s);
      if(op[0] == 'i'){
    index=0;
    while(1){
      val = insert(sti(&s[0]),index);
      if(strcmp(&stack[val][0],"not") == 0){
        strcpy(&stack[val][0],&s[0]);
        break;
      }
      else index++;
      if(index == MAX)break;
    }
      }
      else if(op[0] =='f'){
    index2=0;
    while(1){
      vall=insert(sti(s),index2);
      if(strcmp(stack[vall],s) == 0){
        exist=1;
        break;
      }
      else if(strcmp(&stack[vall][0],"not") == 0){
        break;
      }
      index2++;
      if(index2 == MAX)break;
    }
    if(exist == 1)printf("yes\n");
    else printf("no\n");
      }
    }
  }
  return 0;
}
   
   
int h1(long long k){
  return k%m;
}
   
int h2(long long k){
  return 1+k%(m-1);
}
   
int insert(long long k,int i){
  return (h1(k) + i*h2(k))%m;
}
   
long long sti(char *s){
  long long i=0,sum=0;
  while(s[i] != '\0'){
    sum*=10;
    sum+=s[i]-'A'+1;
    i++;
  }
  return sum;
}


Measured memory_bytes: 16436
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	char input[a+b+2];
	scanf("%s",input);
	int len = strlen(input);
	int flag = 1,count = 0;
	for(int i = 0;i<len;i++)
	{
		if(input[a] != '-')
		{
			flag = 0;
			break;
		}
		if(input[i] >= '0' && input[i] <= '9')
		{
			count++;
		}
	}
	if(count == a +b) 
	{
		flag = 1;
	}
	else if(count != a+b)
	{
		flag = 0;
	} 
	(flag == 0) ? printf("No\n") : printf("Yes\n");
	return 0;
}


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

// nCr mod p(n<p)をキビキビ計算する
// 構築:O(n), クエリ:O(1)
struct combination_mod {
    using lint = long long int;
    int sz;
    lint mod;
    vector<lint> fac;
    vector<lint> finv;
    combination_mod(int _sz, lint _mod) : sz(_sz), mod(_mod) {
        fac.assign(sz + 1, 1);
        finv.assign(sz + 1, 1);
        vector<lint> inv(sz + 1, 1);
        for (int i = 2; i <= sz; 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;
        }
    }
    lint query(int n, int r) {
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
};

lint n, m, k;

int main() {
    cin >> n >> m >> k;
    lint mod = 1e9 + 7;
    combination_mod comb(m * n, mod);
    lint c = comb.query(m * n - 2, k - 2);
    lint ans = 0;
    for (lint i = 0; i < n; i++) {
        for (lint j = 0; j < m; j++) {
            lint M = (j * (j + 1) + (m - j) * (m - j - 1)) / 2;
            M %= mod;
            lint cand = 0;
            cand += M * n % mod;
            cand += i * (i + 1) / 2 % mod * m % mod;
            cand += (n - i) * (n - i - 1) / 2 % mod * m % mod;
            cand %= mod;
            cand *= c;
            cand %= mod;
            ans = (ans + cand) % mod;
        }
    }
    ans = (((lint)1e+9 + 8) / 2 * ans) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 4992
# import numpy as np
from collections import deque

# 関数化しただけで、実行速度が半分になった部分あり。。。
def solve(): #H, W, CH, CW, DH, DW, S):
	H,W=map(int,input().split())
	CH,CW=map(int,input().split())
	DH,DW=map(int,input().split())
	S=[input() for _ in range(H)]

	# 後の条件分岐を簡略化するためワープしても迷路外に出ないように壁で囲む
	S = ['##{}##'.format(row) for row in S]
	S.insert(0, '##{}##'.format('#' * W))
	S.insert(0, '##{}##'.format('#' * W))
	S.append('##{}##'.format('#' * W))
	S.append('##{}##'.format('#' * W))


	MAX_COST = 10 ** 9
	Cost=[ [ MAX_COST for _ in range(W+4)] for _ in range(H+4)]
	# Cost = np.full((H,W),MAX_COST)

	# print(S)

	ans = -1

	cost0 = deque()

	cost0.append((CH+1,CW+1,0))
	Cost[CH+1][CW+1] = 0;

	# used = set()
	walk=[(1,0),(0,1),(-1,0),(0,-1)]
	warp = [ (i,j) for i in range(-2,3) for j in range(-2,3) if (i, j) not in [(0, 0)] + walk ]
	# print(warp)

	cost1 = deque()

	while cost0:
		h,w,c=cost0.popleft()
		cost1.append((h,w,c))

		for i,j in walk:
			dh = h+i
			dw = w+j
			if S[dh][dw] == '.' and c < Cost[dh][dw]:
				Cost[dh][dw] = c
				# print("updl ", i,j,dh,dw,c)
				cost0.appendleft((dh,dw,Cost[dh][dw]))

		if len(cost0) == 0:

			while cost1:
				h,w,c=cost1.popleft()
				# print(h,w,c)
				for i,j in warp:
					dh = h+i
					dw = w+j
					# print(i,j)
					if S[dh][dw] == '.' and c + 1 < Cost[dh][dw]:
						Cost[dh][dw] = c + 1
						cost0.append((dh,dw,Cost[dh][dw]))


	if Cost[DH+1][DW+1] == MAX_COST:
		print(-1)
	else:
		print(Cost[DH+1][DW+1])


if __name__ == "__main__":

	# S=[input() for _ in range(H)]

	solve() #H, W, CH, CW, DH, DW, S)


Measured memory_bytes: 109736
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long x; 
	cin >> x; 
	int i = 1;
	long long yokin = 100;
	while( true ){
		yokin = (long long) (yokin * 1.01);
		if ( yokin >= x ) break;
		i++;
	}
	cout << i << endl;
}

Measured memory_bytes: 3636
// Best practice
 
#include<bits/stdc++.h>
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
 
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}
 
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 
 
// Code from Here -------------------------------------------------------------------------------

signed main() {
	tezz
 
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif

	int n;
	cin >> n;
	vi a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	int dp[n];
	ini(dp, 0);
	for(int i=1; i<n; i++){
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), i>1 ? dp[i-2]+abs(a[i]-a[i-2]) : INT_MAX);
	}
	cout << dp[n-1] << endl;
 
	return 0;
}  

Measured memory_bytes: 4704