akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2 2");
            //6
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5 15");
            //1
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();

        int K = wkArr[0];
        int S = wkArr[1];

        int Answer = 0;
        for (int X = 0; X <= K; X++) {
            for (int Y = 0; Y <= K; Y++) {
                int Z = S - X - Y;
                if (Z < 0) break;
                if (Z > K) continue;
                Answer++;
            }
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 3032
import math
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()
S = input()

cnt = 0
for i in range(N):
    if i+2 >= N: break
    if S[i]+S[i+1]+S[i+2] == 'ABC':
        cnt +=1
print(cnt)

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

int main() {
  long long int N, A, B;
  cin >> N >> A >> B;
  vector<long long int> X(N);
  for (long long int i = 0; i < N; i++) cin >> X.at(i);
  long long int ans = 0;
  for (long long int i = 0; i < N - 1; i++) ans += min(A * (X.at(i + 1) - X.at(i)), B);
  cout << ans << endl;
}

Measured memory_bytes: 4032
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#include<map>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
int main(){
    int N;
    cin >> N;
    LL sum = 0;
    LL lsum = 0;
    LL rsum = 0;
    priority_queue<LL> lque;
    priority_queue<LL, vector<LL>, greater<LL> > rque;
    REP(i, N){
        LL d;
        cin >> d;
        if(d == 1){
            cin >> d;
            rque.push(d);
            rsum += d;
            if(rque.size() > lque.size()){
                lque.push(rque.top());
                lsum -= rque.top();
                rsum -= rque.top();
                rque.pop();
            }
            while(rque.top() < lque.top()){
                LL a = rque.top();
                rque.pop();
                LL b = lque.top();
                lque.pop();
                rsum -= a;
                lsum += b;
                rsum += b;
                lsum -= a;
                rque.push(b);
                lque.push(a);
            }
            cin >> d;
            sum += d;
        }else{
            cout <<lque.top() <<" "<< sum + rsum + lsum + lque.top() * (long long)lque.size() - lque.top() * (long long)rque.size() << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3828
import java.util.*
import java.util.ArrayDeque

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    var h = sc.nextInt()
    val a = sc.nextInt()

    var r = 0
    while (h > 0) {
        h -= a
        r++
    }
   print(r)
}


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

    	
    	
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000003

ll power(ll x,ll b)
{
    ll res=1;
    if(b==0)
    return 1;
    while(b>0)
    {
      if(b%2!=0)
      res=(res*x);
      b=b/2;
      x=(x*x);
      
    }
    return res;
}
 
 
       


  



      
   
    	
using namespace std;

 
vector<ll> primes;
void SieveOfEratosthenes(int n) 
{ 
    
    vector<ll>prime(200001,0);
  
    for (int p=2; p*p<=n;p++) 
    { 
       
        if (prime[p] == 0) 
        { 
           
            for (int i=p*p; i<=n; i += p) 
                prime[i] = 1; 
        } 
    } 
    
  
    // Print all prime numbers 
    for (int p=1; p<=n; p++) 
       if (prime[p]==0) 
        {
            primes.pb(p);
        }
} 












int main()
{
   ll n,i,j,k;
   cin>>n>>k;
   ll w[n+1],v[n+1],mx;
   
   for(i=0;i<n;i++)
   {
       cin>>w[i+1]>>v[i+1];
       if(i==0)
       mx=v[i+1];
       else
       mx=max(v[i+1],mx);
   }
   ll mxval=mx*n;
  ll dp[n+1][mxval+1];
   for(i=0;i<=n;i++)
   {
       for(j=0;j<=mxval;j++)
       {
           if(j==0||i==0)
           {
               if(j==0)
               dp[i][j]=0;
               if(i==0&&j!=0)
               dp[i][j]=inf;
           }
           
           else if(v[i]<=j)
           {
               dp[i][j]=min(w[i]+dp[i-1][j-v[i]],dp[i-1][j]);
           }
           else
           {
               dp[i][j]=dp[i-1][j];
           }
           
       }
   }
   ll maax=0;
   for(i=0;i<=mxval;i++)
   {
     if(k>=dp[n][i])
     {
         maax=max(maax,i);
     }
   }
   cout<<maax;
   

   







}



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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> vec(N);
  for (int i; i < M; i++) {
    int a,b;
    cin >> a >> b;
    vec[a-1] += 1;
    vec[b-1] += 1;
  }
  for (int i; i < N; i++) {
    cout << vec[i] << endl;
  }
}

Measured memory_bytes: 3524
#include<stdio.h>

int main(void){
    int i,j;
    int a,b,c;
    int n;
    int flag;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        b = 0;
        c = 0;
        flag = 1;
        for(j=0;j<10;j++){
            scanf("%d",&a);
            if(b < a && c < a){
                if(b < c)c = a;
                else b = a;
            }else if(b < a){
                b = a;
            }else if(c < a){
                c = a;
            }else{
                flag = 0;
            }
        }

        if(flag)printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    
    vector<vector<int>> dp(n + 1, vector<int>(m + 1));
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(s[i - 1] == t[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else 
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    
    string answer;
    int i = n, j = m;
    while(i && j)
    {
        if(dp[i][j] == dp[i - 1][j]) i--;
        else if(dp[i][j] == dp[i][j - 1]) j--;
        else
        {
            answer.push_back(s[i - 1]);
            i--, j--;
        }
    }

    // auto it = answer.begin(); it += 2;
    reverse(answer.begin(), answer.end());
    cout << answer;
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int *x = (int *)calloc(m, sizeof(int));
  int *d = (int *)calloc(m-1, sizeof(int));

  for(int i=0;i<m;i++){
    scanf("%d", x+i);
  }
  sort(x, x+m);
  for(int i=0;i<m-1;i++){
    d[i] = x[i+1] - x[i];
  }
  sort(d, d+m-1);
  //for(int i=0;i<m-1;i++)cout << d[i] << endl;

  long long ans = 0;
  for(int j=0;j<m-1-(n-1);j++)ans += d[j];

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main()
{
    int N;
    vector<int> Hi;

    cin >> N;

    Hi.resize(N);

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

    int count = 1;
    for(int i=1; i<N; i++){

        bool enable = true;
        
        for(int j=0; j<i; j++){
            
            if(Hi.at(i)<Hi.at(j)){
                enable = false;
                break;
            }
        }

        if(enable){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
 
  ll x = c - a -b;

  if (x < 0) {
    cout << "No" << endl;
    return 0;
  }

  if (4*a*b < x*x) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  
  set<int> values;
  rep(i, n) values.insert(d[i]);
  
  cout << values.size() << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h, w, K = LI()
c = [list(input()) for _ in range(h)]
count = 0
for i in range(h):
    for j in range(w):
        if c[i][j] == '#':
            count += 1
ans = 0
for i in range(1 << h):
    f = defaultdict(lambda : 0)
    cnt = count
    for k in range(h):
        if i >> k & 1:
            for l in range(w):
                if c[k][l] == "#" and f[(k, l)] == 0:
                    f[(k, l)] = 1
                    cnt -= 1
    for j in range(1 << w):
        cnt2 = cnt
        f2 = defaultdict(lambda : 0)
        for k, l in f.items():
            if l == 1:
                f2[k] = 1
        for k in range(w):
            if j >> k & 1:
                for l in range(h):
                    if c[l][k] == "#" and f2[(l, k)] == 0:
                        f2[(l, k)] = 1
                        cnt2 -= 1
        if cnt2 == K:
            ans += 1
print(ans)

Measured memory_bytes: 69580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll N, T;
    cin >> N >> T;
    ll res = 1e5;
    REP(i, N) {
        ll c, t;
        cin >> c >> t;
        if (t <= T) {
            chmin(res, c);
        }
    }
    if (res==1e5) cout << "TLE\n";
    else cout << res << "\n";
}


Measured memory_bytes: 256
// Red and Black
// 問題URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1130&lang=jp
// 中央*右
// 
// 所用時間: 1h
// BFSで解きました、キューの使い方について理解が深まりました。

#include <iostream>
#include <iostream>
#include <string>
#include <queue>

using namespace std;

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int W, H,stX, stY, curX, curY, buffX, buffY;
string buff, FD[25];
queue<int> Qx, Qy;

bool isRed(int x, int y){ //(x,y)が赤か?
    return FD[y][x] == '#';
}

bool inField(int x, int y){ //(x,y)がフィールド内か?
    return 0 <= x && x <= (W-1) && 0 <= y && y <= (H-1);
}

void solve(){
    int cnt = 0;
    bool Checked[25][25]={};
    Qx.push(stX);
    Qy.push(stY);
    cnt++;
    Checked[stY][stX] = true;

    while(!Qx.empty()){ //キューが空になるまで
        curX = Qx.front(); curY = Qy.front();
        Qx.pop(); Qy.pop();
        // printf("(curX, curY) = (%d, %d)\n", curX, curY);

        for(int i = 0; i < 4; i++){//現在地の周囲4マスについて
            buffX = curX + dx[i]; buffY = curY + dy[i];
            if(inField(buffX, buffY) && !isRed(buffX, buffY) && !Checked[buffY][buffX]){ //未調査で移動可能であれば
                Qx.push(buffX); Qy.push(buffY);
                Checked[buffY][buffX] = true;
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

int main(){
    while(cin >> W >> H && W){
        for(int i = 0; i < H; i++){
            cin >> buff;
            FD[i] = buff;
            for(int j = 0; j < buff.size(); j++){
                    if(buff[j]=='@'){ //スタート地点を見つけたら記録する
                        stX = j;
                        stY = i;
                        // printf("(stX, stY) = (%d, %d)\n", stX, stY);
                    }
                }
            }
    solve();
    }
}



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




int main() {
	int N; cin >> N;
	vector<int> A(N), B(N), C(N - 1);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N - 1) cin >> C[i];
	uint64_t ans = 0;
	rep(i, N) {
		ans += B[A[i] - 1];
		if (i != 0 && A[i - 1] + 1 == A[i]) ans += C[A[i - 1] - 1];
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

struct SegTree{
    int N;
    vi dat;
    void init(int _N){
        N=1;
        while(N<_N)N*=2;
        dat=vi(N*2-1,INT_MAX);
    }
    void update(int k,int val){
        k+=N-1;
        dat[k]=val;
        while(k){
            k=(k-1)/2;
            dat[k]=min(dat[k*2+1],dat[k*2+2]);
        }
    }
    int getMin(int a,int b,int k=0,int l=0,int r=-1){
        if(r==-1)r=N;
        if(r<=a||b<=l)return INT_MAX;
        if(a<=l&&b>=r)return dat[k];
        int v1=getMin(a,b,k*2+1,l,(l+r)/2);
        int v2=getMin(a,b,k*2+2,(l+r)/2,r);
        return min(v1,v2);
    }
};

int main(){
    int N,Q;
    scanf("%d%d",&N,&Q);
    SegTree seg;
    seg.init(N);
    while(Q--){
        int type;
        scanf("%d",&type);
        if(type){
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%d\n",seg.getMin(l,r+1));
        }
        else{
            int idx,val;
            scanf("%d%d",&idx,&val);
            seg.update(idx,val);
        }
    }
    return 0;
}

Measured memory_bytes: 3112
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

vector<string> bbb;

int main(void){
    ll n,m;
    cin >> n >> m;
    vll h(n);
    vll good(n);

    REP(i,n){
        cin >> h[i];
        good[i] = true;
    }
    REP(i,m){
        ll a,b;
        cin >> a >> b;
        if(h[a-1] > h[b-1]){
            good[b-1] = false;
        }else if(h[a-1] < h[b-1]){
            good[a-1] = false;
        }else{
            good[a-1] = false;
            good[b-1] = false;
        }
    }
    ll ans = 0;
    REP(i,n){
        if(good[i]){
            ans++;
        }    
    }
    cout << ans << endl;
}

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

typedef long double ld;

int main() {
  int A, B, H, M;
  scanf("%d %d %d %d", &A, &B, &H, &M);
  ld a = A;
  ld b = B;
  ld r1 = 2 * M_PI * (ld(H) / 12.0 + ld(M) / 60.0 / 12.0);
  ld r2 = 2 * M_PI * ld(M) / 60.0;
  ld diff = std::abs(r1 - r2);
  printf("%.18Lf\n", std::sqrt(a*a + b*b - 2 * a * b * std::cos(diff)));
}


Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
typedef unordered_set<int> ss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<pl,ll> tl;
const int MN = 100100;
ss g[MN];
bitset<MN> vs,fk;
vi res;
tl v[MN];
pl wh[MN];
ll dist,deg[MN],w[MN],x[MN],z[MN];
set<pl> oof;
void dfs(int s) {
	stack<int> st;
	st.push(s);
	vs.set(s);
	res.push_back(s);
	while(!st.empty()) {
		int u = st.top();st.pop();
		for(auto& v: g[u]) {
			if(vs[v]) continue;
			st.push(v);
			vs.set(v);
			res.push_back(v);
		}
	}
}
int str[MN];
int main() {
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);a--;b--;
	for(int i=0;i<n;i++) {
		int t,s;
		scanf("%d %d",&t,&s);
		v[i] = {{t,s},i};
		wh[i] = {t-s,t+s};
		oof.insert({t-s,t+s});
	}
	memset(deg,0,sizeof(deg));
	dist = abs(v[b].first.first-v[a].first.first) + abs(v[b].first.second-v[a].first.second);
	for(int i=0;i<n;i++) {
		int t = v[i].first.first,s = v[i].first.second;
		v[i] = {{t-s,t+s},i};
	}
	for(int rev=0;rev<2;rev++) {
		memset(str,0,sizeof(str));
		sort(v,v+n);
		for(int i=0;i<n;i++) {
			pl& p = v[i].first;
			w[i] = p.first;
			x[i] = p.second;
			z[i] = v[i].second;
		}
		for(int i=0;i<n;i++) {
			int wl = lower_bound(w,w+n,w[i]-dist)-w;
			int wr = upper_bound(w,w+n,w[i]-dist)-w;
			int lf = lower_bound(x+wl,x+wr,x[i]-dist)-x;
			int rt = upper_bound(x+wl,x+wr,x[i]+dist)-x-1;

			int kl = lower_bound(w,w+n,w[i]+dist)-w;
			int kr = upper_bound(w,w+n,w[i]+dist)-w;
			int df = lower_bound(x+kl,x+kr,x[i]-dist)-x;
			int dt = upper_bound(x+kl,x+kr,x[i]+dist)-x-1;
			deg[z[i]] += dt-df+1;
			if(lf>rt) {
				continue;}
			str[lf]++;str[rt]--;
			g[z[i]].insert(z[lf]);
			g[z[lf]].insert(z[i]);
			deg[z[i]] += rt-lf+1;
		}
		int rc = 0;
		for(int i=0;i<n;i++) {
			rc += str[i];
			if(rc > 0) {
				g[z[i]].insert(z[i+1]);
				g[z[i+1]].insert(z[i]);
			}
			swap(v[i].first.first,v[i].first.second);
		}
	}
	dfs(a);
	ll tot = 0;
	//sort(res.begin(),res.end());
	for(int i=0;i<res.size();i++) {
		int id = res[i];
		ll tp = tot;
		tot += deg[id];
		if(oof.find({wh[id].first+dist,wh[id].second+dist}) != oof.end()) {tot--;}
		if(oof.find({wh[id].first-dist,wh[id].second+dist}) != oof.end()) {tot--;}
		if(oof.find({wh[id].first+dist,wh[id].second-dist}) != oof.end()) {tot--;}
		if(oof.find({wh[id].first-dist,wh[id].second-dist}) != oof.end()) {tot--;}
	}
	//printf("%lld\n",tot);
	printf("%lld\n",tot/2);
}

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

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

typedef struct task{
	int x;
	int y;
};


int main() {
	int h,w;
	int s[25][25] = {};
	int i,j;
	int c[25][25];

	int max = 0;

	char in[25];

	int n = 0;

	int t_x[100000];
	int t_y[100000];
	int t_i;

	int x,y;
	int now;

	int c_x,c_y,c_c;


	scanf("%d %d",&h,&w);
	for(i=0;i<h;i++){
		scanf("%s",in);
		for(j=0;j<w;j++){
			if(in[j] == '.'){
				s[i+1][j+1] = 1;
			}else{
				s[i+1][j+1] = 0;
			}
		}
	}

	for(y=1;y<h+1;y++){
		for(x=1;x<w+1;x++){

			for(i=0;i<h+2;i++){
				for(j=0;j<w+2;j++){
					// 
					if(s[i][j] == 1){
						c[i][j] = -1;
					}else{
						c[i][j] = 0;
					}
				}
			}
			t_y[0] = y;
			t_x[0] = x;
			t_i = 1;
			if(	c[y][x] == 0){
				continue;
			}


			c[y][x] = 1;

			now = 0;


			while(t_i != now){
				c_x = t_x[now];
				c_y = t_y[now];
				c_c = c[c_y][c_x];

				// m0
				if(c[c_y  ][c_x-1] == -1){
						c[c_y  ][c_x-1] = c_c + 1;
						t_y[t_i] = c_y  ;	t_x[t_i] = c_x-1;		t_i++;
				}else if(c[c_y  ][c_x-1] != 0){
					if( c[c_y  ][c_x-1] - 1 > c_c ){
						c[c_y  ][c_x-1] = c_c + 1;
						t_y[t_i] = c_y  ;	t_x[t_i] = c_x-1;		t_i++;
					}
				}else{
					// No Operation
				}

				// p0
				if(c[c_y  ][c_x+1] == -1){
						c[c_y  ][c_x+1] = c_c + 1;
						t_y[t_i] = c_y  ;	t_x[t_i] = c_x+1;		t_i++;
				}else if(c[c_y  ][c_x+1] != 0){
					if( c[c_y  ][c_x+1] - 1 > c_c ){
						c[c_y  ][c_x+1] = c_c + 1;
						t_y[t_i] = c_y  ;	t_x[t_i] = c_x+1;		t_i++;
					}
				}else{
					// No Operation
				}

				// m0
				if(c[c_y-1][c_x  ] == -1){
						c[c_y-1][c_x  ] = c_c + 1;
						t_y[t_i] = c_y-1;	t_x[t_i] = c_x;		t_i++;
				}else if(c[c_y-1][c_x  ] != 0){
					if( c[c_y-1][c_x  ] - 1 > c_c ){
						c[c_y-1][c_x  ] = c_c + 1;
						t_y[t_i] = c_y-1;	t_x[t_i] = c_x;		t_i++;
					}
				}else{
					// No Operation
				}

				// m0
				if(c[c_y+1][c_x  ] == -1){
						c[c_y+1][c_x  ] = c_c + 1;
						t_y[t_i] = c_y+1;	t_x[t_i] = c_x;		t_i++;
				}else if(c[c_y+1][c_x  ] != 0){
					if( c[c_y+1][c_x  ] - 1 > c_c ){
						c[c_y+1][c_x  ] = c_c + 1;
						t_y[t_i] = c_y+1;	t_x[t_i] = c_x;		t_i++;
					}
				}else{
					// No Operation
				}


//			printf("====%d,%d(%d)=====\n",y,x,now);
				for(i=1;i<h+1;i++){
				for(j=1;j<w+1;j++){
					if(max < c[i][j]){
						max = c[i][j];
					}

//					printf("%d ",c[i][j]);

				}
//				printf("\n");
			}

				now++;

			}




		}
	}

	printf("%d\n",max-1);


    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


ll dp[1111][15111];

int main(void) {
  ll H, N;
  cin >> H >> N;
  ll i, j;
  ll a[1111], b[1111];
  ll max=0;
  
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i];
    chmax(max, a[i]);
  }
  
  
  for(i=0; i<N; i++) {
    for(j=0; j<H+max; j++) {
      dp[i][j]=INF;
    }
  }
  dp[0][0]=0;
  
  for(i=0; i<N; i++) {
    for(j=0; j<H+max; j++) {
      chmin(dp[i+1][j], dp[i][j]);
      chmin(dp[i][j+a[i]], dp[i][j]+b[i]);
    }
  }
  
  ll ans=INF;
  for(j=H; j<H+max; j++) {
    chmin(ans, dp[N-1][j]);
  }
  
  pt(ans);
}



Measured memory_bytes: 118528
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a;
  a = N % 1000;
  if(a == 0) {
    cout << 0 <<endl;
  }
  else{
  a = 1000 - a;
  cout << a << endl;
  }
}
  


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

int main() {
  int K,X; cin >> K >> X;
  rep(i,2*K-1) cout << X - (K-1) + i << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT long long int
using namespace std;
INT n, m, y, x[100010], xx[100010];
vector<INT> V[100010];
int main(){
    scanf("%lld%lld", &n, &m);
    for(int i = 0, a ; i < m ; i++ )
    {
        scanf("%lld%lld", &a, &y);
        V[a].push_back(y);
        x[i] = a, xx[i] = y;
    }
    for(int i = 1 ; i <= n ; i++ )
        sort(V[i].begin(), V[i].end());
    for(int i = 0 ; i < m ; i++ )
    {
        printf("%06lld%06d\n", x[i],
        (lower_bound(V[x[i]].begin(), V[x[i]].end(), xx[i])-V[x[i]].begin())+1);
    }
    return 0;
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", _dmp_(#__VA_ARGS__, __VA_ARGS__)
void _dmp_(const char*) { cerr << endl; }
template <class T, class... U>
void _dmp_(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; _dmp_(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, multiset<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct _Init_ { _Init_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } _init_;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
#define YesNo(c) ((c) ? "Yes" : "No")
////////////////////////////////

int32_t main() {
    int m,k; cin >> m >> k;
    if (m == 0) {
        if (k == 0) quit("0 0");
        else quit("-1");
    } else if (m == 1) {
        if (k == 0) quit("0 0 1 1");
        else quit("-1");
    }

    const int n = 1LL<<m;
    if (k >= n) quit("-1");
    rep (i,n) if (i != k) cout << i << " ";
    cout << k << " ";
    repR (i,n) if (i != k) cout << i << " ";
    cout << k << "\n";
}


Measured memory_bytes: 1792
/*input
6 5 2 
1 2 2 
1 3 4 
1 4 3   
1 5 1 
1 6 5

5 4 10 
1 2 3 
2 3 4 
3 4 3 
4 5 5

5 5 2
2 3 1
3 1 2
2 4 3
1 2 4
2 5 5
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N 100005
#define bit(x,y) ((x>>y)&1LL)
#define show(x) cout << (#x) << ": " << x << endl;
#define ii pair<int,int>
ostream& operator << (ostream &os, vector<int>&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << sp;
	return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
	cout << x.fi << sp << x.se << sp;
	return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << endl;
	return os;
}
int n, m, C;
int dis[N];
vector<vector<ii> > a(N);
bool visited[N];
priority_queue<pair<int, int> , vector<pair<int, int> >, greater<pair<int, int> > > pq;
int totalSum = 0;
int curSum = 0;
int ans = 1e18;
void dijkstra() {
	pq.push(mp(0, 1));
	while (!pq.empty()) {
		int u = pq.top().se; int d = pq.top().fi; pq.pop(); visited[u] = true;
		if (d != dis[u]) continue;
		for (int i = 0; i < a[u].size(); i++) {
			int v = a[u][i].fi; int nd = a[u][i].se;
			if (dis[v] > dis[u] + nd) {
				dis[v] = dis[u] + nd;
				pq.push(mp(dis[v], v));
			}
			if (visited[v]) {
				curSum += nd;
			}
		}
		ans = min(ans, totalSum - curSum + d * C);
	}
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m >> C;
	for (int i = 1; i <= m; i++) {
		int x, y, z; cin >> x >> y >> z;
		totalSum += z;
		a[x].push_back(mp(y, z));
		a[y].push_back(mp(x, z));
	}
	memset(dis, 127, sizeof(dis));
	dis[1] = 0; visited[1] = true;
	dijkstra();
}

Measured memory_bytes: 17396
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int n, x, ans;
int in[31], in2[31];
bool dp[1000001];
void solve(int a, int sum){
	for (int i = a; i <= n; i++){
		if (sum + in[i] > x&&!in2[i]){
			in[i] /= 1000;
			in2[i] = 1;
		}
		if (sum + in[i] <= x){
			if (dp[sum + in[i]])
				continue;
			if (sum + in[i] % 2){
				dp[sum + in[i]] = 1;
			}
			solve(i, sum + in[i]);
		}
	}
}
int main(){
	while (cin >> n >> x&&n&&x){
		ans = 0;
		fill(dp, dp + 1000001, 0);
		for (int i = 1; i <= n; i++){
			cin >> in[i];
			in[i] *= 1000;
			in2[i] = 0;
		}
		solve(1, 0);
		for (int i = x; i > 0; i--){
			if (dp[i]){
				for (int j = 5; j <= x; j++){
					if (j == i)
						ans = j;
					if (i % j == 0)
						break;
				}
				if (ans)
					break;
			}
		}
		if (ans)
			cout << ans << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 2196
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    h,w=parseMap(split(readline()))
    c=[parseMap(split(readline())) for i in 0:9]
    a=[parseMap(split(readline())) for i in 1:h]
    for i in 1:10
        for j in 1:10
            for k in 1:10
                # j->k，j->i->kのうち小さい方に変更
                c[j][k]=min(c[j][k],c[j][i]+c[i][k])
            end
        end
    end
    ans=0
    for i in 1:h
        for j in a[i]
            if j!=-1
                # 1-indexedなので+1してやる必要がある
                ans+=c[j+1][2]
            end
        end
    end
    println(ans)
end
main()

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

int main(void){
    long long h, k = 0,sum = 0;
    cin >> h;

    while(h){
        h /= 2;
        sum += pow(2, k);
        k++;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
ps = gets.split.map(&:to_i)

max = sum = ps[0...k].inject(:+)

(k...n).each do |i|
  sum = sum - ps[i - k] + ps[i]
  max = sum if max < sum
end

puts (max + k) / 2.0

Measured memory_bytes: 14980
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   cin >> N;
   N%=10;
   if(N==3) cout << "bon" <<endl;
   else if(N==0||N==1||N==6||N==8) cout << "pon" << endl;
   else cout << "hon" << endl;
   return 0;
}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		
		int suviver = fs.nextInt();
		
		for(int i = 1; i < n ; i++) {
			int nextHitPoint = fs.nextInt();
			suviver = suviveHitPoint(suviver, nextHitPoint);
		}
		
		System.out.println(suviver);
	}

	int suviveHitPoint(int x, int y) {
		while(x != 0 && y != 0) {
			if(x < y) {
				y = y % x;
			}else {
				x = x % y;
			}
		}
		
		if(x == 0) {
			return y;
		}else {
			return x;
		}
		
		
	}
	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 37332
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

int main() {
    int N;
    cin>>N;
    
    ll cnt=0,v=0;
    while(v<N){
        v+= ++cnt;
    }
    cout1(cnt);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  ll mini, maxi, ans;
  if(n % 2 == 0) {
    mini = (a[n / 2 - 1] + a[n / 2]);
    maxi = (b[n / 2 - 1] + b[n / 2]);
    ans = (maxi - mini);
    ans++;
  } else {
    mini = a[(n + 1) / 2 - 1];
    maxi = b[(n + 1) / 2 - 1];
    maxi += 1;
    ans = maxi - mini;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6428
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define veci(a, n) vector<int> a(n)
#define vecs(a, n) vector<string> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)

bool sqrt_check(long long n){

}

int main(){
    int a, b;
    cin >> a >> b;
    int n;
    if((1 <= b) && (b <= 9)) n = a * 10 + b;
    else if((10 <= b) && (b <= 99)) n = a * 100 + b;
    else n = a * 1000 + b;

    n += 0.000000000001;
    if(n == int(pow(int(sqrt(n)), 2))) cout << "Yes" << endl;
    else cout << "No" << endl;
    /*cout << "n:" << n << endl;
    cout << "sqrt(n):" << sqrt(n) << endl;
    cout << "int(sqrt(n)):" << int(sqrt(n)) << endl;
    cout << "int(pow(int(sqrt(n)), 2)):" << int(pow(int(sqrt(n)), 2)) << endl;*/
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

signed main() {
    ll n;
    cin >> n;
    vector<ll> ret;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    cout<<n/ret[ret.size()-1]+ret[ret.size()-1]-2<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

int N, C, X;
int D[30][30]; // D[i][j] : 色iからjに代える時のコスト
int t[3][30];  // t[i][j] : i番目の列の中でj色のマスの数

void input() {
	cin >> N >> C;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) cin >> D[i][j];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			int c;
			cin >> c;
			t[(i + j) % 3][c - 1]++;
		}
	}
}

void solve() {
	int ans = INF;
	int c[3]; // c[i] : i番目の列をc[i]色にする
	for (c[0] = 0; c[0] < C; c[0]++) {
		for (c[1] = 0; c[1] < C; c[1]++) {
			for (c[2] = 0; c[2] < C; c[2]++) {
				if (c[0] != c[1] && c[1] != c[2] && c[2] != c[0]) {
					
					int temp = 0;
					for (int i = 0; i < 3; i++) {
						for (int j = 0; j < C; j++) {
							temp += t[i][j] * D[j][c[i]];
						}
					}

					ans = min(ans, temp);

				}
			}
		}
	}

	cout << ans << endl;
}

int main() {
	input();
	solve();


	return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
a = sorted(list(map(int,input().split())))
b = sorted(list(map(int,input().split())))
c = sorted(list(map(int,input().split())))
#print(a,b,c)
cnt = 0
for i in range(n):
    d = bisect.bisect_left(a,b[i])
    e = bisect.bisect_right(c,b[i])
    cnt += d*(n-e)
print(cnt)

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

int main() {
    //
    int num;
    int sum = 0;

    cin >> num;

    vector<int> vec(num);
    for (int i = 0; i < num; i++) cin >> vec.at(i);

    for (int i = 0; i < num-1; i++) {
        for (int j = i + 1; j < num; j++) {
            sum += vec.at(i) * vec.at(j);
        }
    }

    cout << sum;
    //
}


Measured memory_bytes: 3604
import sys,math
range = xrange
input = raw_input

a,b,c = [int(x) for x in input().split()]

def test(a,b,c):
    if c - a - b <= 0:
        return False
    return 4 * a*b < (c - a - b)**2 
    
# 2 * sqrt(a*b) < c - a - b
print 'Yes' if test(a,b,c) else 'No'


Measured memory_bytes: 28012
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    ll a,b,c,d;
    scanf("%d%lld%lld%lld%lld", &n, &a, &b, &c, &d);

    int i;
    for(i=0; i<=n-1; i++) {
        int j=n-1-i;

        ll min=i*c-j*d;
        ll max=i*d-j*c;
        if(min<=b-a && b-a<=max) {
            printf("YES\n"); return 0;
        }
    }
    printf("NO\n");

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	static int[] b;
	static int n;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        b = new int[n - 1];
        for(int i = 0; i < n - 1; i++) {
        	b[i] = scan.nextInt();
        }
        int ans = 0;
        for(int i = b.length - 1 ; i >= 1 ; i--) {
        	ans += Math.min(b[i], b[i - 1]);
        }
        ans += b[0];
        ans += b[b.length - 1];

        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N;
  cin>>N;
  bool flag=true;
  vector<ll>H(N);
  for(ll i=0;i<N;i++){
    cin>>H[i];
  }

    if(N==1){
      flag=false;
      cout<<"Yes"<<endl;
    }
  else{
  
for(ll i=N-2;i>=0;i--) {
    if(H[i]>H[i+1]){
H[i]-=1;
    }
  }
 
  for(ll i=N-2;i>=0;i--){
    if(H[i]>H[i+1]){
      cout<<"No"<<endl;
      flag=false;
      
      break;
    }
  }
    
    if(flag){
      cout<<"Yes"<<endl;
    }
  }
  }


Measured memory_bytes: 1024
from collections import *
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = Counter(prime_factorize(int(input())))
count=0
for s in a.values():
    for m in range(40):
        if (m+1)*(m+2)/2>s:
            count+=m
            break
print(count)

Measured memory_bytes: 65852
r, c = gets.split.map(&:to_i)
mat = []
(1..r).each do |_x|
  mat << gets.split.map(&:to_i)
end

mat.each do |row|
  row << row.inject(:+)
end
mat[r] = []
(0..c).each do |col|
  sum = 0
  (0..r - 1).each do |row|
    sum += mat[row][col]
  end
  mat[r] << sum
end

mat.each do |row|
  puts row.join(' ')
end

Measured memory_bytes: 9008
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextStr() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRuneAt(s string, i int) rune {
	rs := []rune(s)
	return rs[i]
}

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	c := nextInt()

	if a == b && b == c {
		fmt.Print("Yes")
		return
	}
	fmt.Print("No")
}


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

int main() {

  int N , A , S , B;
  cin >> N ;
  S = 30 ;
 
  for( int i = 0 ; i < N ; i++){
    cin >> A ;

    for ( int j = 0 ; ;  j++){
    if(A%2==0){
      A /= 2 ;
    }else{
      B = j;
      break ;
    }
    }
    
    if ( B < S)
    S = B ;
    
  }
    cout << S << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

	string str;	cin>>str;

	char x =str[str.size()-1];

	if(x=='3'){

		cout<<"bon"<<endl;

	}

else if(x=='0'||x=='6'||x=='1'||x=='8'){

		cout<<"pon"<<endl;

	}

	else cout<<"hon"<<endl;

}

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

long long weights[101];
long long values[101];
const long long vMax = 100*1000+1;
long long dp[101][vMax];
long long const INF = 1LL << 60;
int main()
{
    int n;
    long long W;
    cin >> n >> W;
    for(int i=0;i<n;i++){
        cin >> weights[i] >> values[i];
    }
    for(int i=0;i<=n;i++){
        for(long long v=0;v<vMax;v++){
            dp[i][v] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i=0;i<n;i++){
        for(long long v=0;v<vMax;v++){
            if(v >= values[i]){
                dp[i+1][v] = min(dp[i][v],dp[i][v - values[i]] + weights[i]);
            }
            else{
                dp[i+1][v] = dp[i][v];
            }
        }
    }
    long long ret = 0;
    for(long long v=0;v<vMax;v++){
        if(dp[n][v] <= W){
            ret = v;
        }
    }
    cout << ret;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1000000;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){ 
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l = max(a, c);
    int r = min(d, b);
    if(l < r)
        cout << r - l << '\n';
    else
        cout << 0 << '\n';
    return 0;
}   

Measured memory_bytes: 256