akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import qualified Data.Map as M
import Control.Monad.State
-- import Test.HUnit

main :: IO ()
-- main = runTestTT (TestList tests) >> return ()
main = do
  [w,q] <- getl $ wrds toInt
  unless (w == 0 && q == 0) $ do
    xs <- replicateM q $ getl $ map toInt . tail . words
    solve w xs
    main

solve :: Int -> [[Int]] -> IO ()
solve w xs = do
  runStateT (mapM cat xs) ([(0,w)], M.empty)
  putStrLn "END"

cat :: [Int] -> StateT ([(Int,Int)], M.Map Int (Int,Int)) IO ()
cat [i, w] = do
  (sps, mp) <- get
  case findSp w sps of
   Just ((s,w),rs) -> do
     liftIO $ print s
     put (rs, M.insert i (s,w) mp)
   Nothing -> do
     liftIO $ putStrLn "impossible"
     put (sps,mp)

cat [i] = do
  (sps, mp) <- get
  put (addSp (mp M.! i) sps, M.delete i mp)

addSp :: (Int,Int) -> [(Int,Int)] -> [(Int,Int)]
addSp (s,w) [] = [(s,w)]
addSp (s,w) ((ss,ww):sps)
  | s + w < ss = (s,w) : (ss,ww) : sps 
  | s + w == ss = (s,w + ww) : sps
  | ss + ww == s = addSp (ss, ww + w) sps
  | otherwise = (ss,ww) : addSp (s,w) sps

findSp :: Int -> [(Int,Int)] -> Maybe ((Int,Int), [(Int,Int)])
findSp w sps = case g sps of
                Just s -> Just ((s,w), f s sps)
                Nothing -> Nothing
  where
    f s ((ss,ww):rs)
      | s /= ss = (ss,ww) : f s rs
      | s == ss && w == ww = rs
      | otherwise = (ss+w, ww-w) : rs
    g [] = Nothing
    g ((ss,ww):rs)
      | w > ww = g rs
      | otherwise = Just ss
                    
toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

-- tests :: [Test]
-- tests = [
--   "addSp1" ~: addSp (0,3) [] ~?= [(0,3)],
--   "addSp2" ~: addSp (0,3) [(5,1),(10,4)] ~?= [(0,3),(5,1),(10,4)],
--   "addSp3" ~: addSp (2,3) [(0,1),(10,4)] ~?= [(0,1),(2,3),(10,4)],
--   "addSp4" ~: addSp (10,2) [(0,3),(5,2)] ~?= [(0,3),(5,2),(10,2)],
--   "addSp5" ~: addSp (3,2) [(0,3),(10,2)] ~?= [(0,5),(10,2)],
--   "addSp6" ~: addSp (6,2) [(0,2),(4,1),(8,2),(15,4)] ~?= [(0,2),(4,1),(6,4),(15,4)],
--   "addSp7" ~: addSp (5,2) [(0,2),(4,1),(7,2),(15,4)] ~?= [(0,2),(4,5),(15,4)],
--   "findSp1" ~: findSp 5 [(0,2),(3,4),(10,3)] ~?= Nothing,
--   "findSp2" ~: findSp 5 [(0,2),(3,5),(10,7)] ~?= Just ((3,5),[(0,2),(10,7)]),
--   "findSp3" ~: findSp 7 [(0,2),(3,5),(10,20)] ~?= Just ((10,7),[(0,2),(3,5),(17,13)])
--   ]

Measured memory_bytes: 4180
#include <stdio.h>

int main(void)
{
	double temp,Max=0.14,Min=999999;
	while(scanf("%lf",&temp)!=EOF){
		if(temp>Max){
			Max=temp;
		}
		if(Min>temp){
			Min=temp;
		}
	}
	
	printf("%f\n",Max-Min);
	
	return 0;
}

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

int main() {
 string s; cin>>s;
  int longe=s.size();
  int i=0;
  while(i<=longe-1){
    cout<<s[i];
    i+=2;}
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}
signed main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll now;
    REP(i, 3) {
        if (b * modpow(2, i, mod) > a) {
            k -= i;
            now = b * modpow(2, i, mod);
            break;
        }
    }
    if (c * modpow(2, k, mod) > now) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b;cin>>a>>b;
    if(a<b){
        cout<<"a < b"<<endl;
    }
    else if(a==b){
        cout<<"a == b"<<endl;
    }
    else{
        cout<<"a > b"<<endl;
    }
    return 0;
}




Measured memory_bytes: 2992
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct DataSet{
    int x, y;
    int ax, ay;
    string str;
};

int search(int xSize, int ySize, int x, int y, string& s){
    //cout << '[' << x << ',' << y << ']' << endl;
    int ret = 0;
    int nowPos = x + y * xSize;
    s[nowPos] = '#';
    ++ret;
    
    if(s[nowPos - 1] == '.' && x != 0){
        ret += search(xSize, ySize, x-1, y, s);
    }
    if(s[nowPos + 1] == '.' && x + 1 != xSize){
        ret += search(xSize, ySize, x+1, y, s);
    }
    if(s[nowPos - xSize] == '.' && y != 0){
        ret += search(xSize, ySize,x, y-1, s);
    }
    if(s[nowPos + xSize] == '.' && y + 1 != ySize){
        ret += search(xSize, ySize, x, y+1, s);
    }
    return ret;
}

int main()
{
    vector<DataSet> dataSets;
    char word;
    
    while(cin){
        DataSet dataSet;
        cin >> dataSet.x >> dataSet.y;
        for(int i = 0; i < dataSet.y * dataSet.x; i++){
            cin >> word;
            if(word == '@'){
                dataSet.ax = i % dataSet.x;
                dataSet.ay = i / dataSet.x;
            }
            //cout << line << endl;
            dataSet.str += word;
        }
        dataSets.push_back(dataSet);
    }
    dataSets.pop_back();
    
    //cout << dataSets.back().x << ' ' << dataSets.back().y << endl;
    //cout << dataSets.back().ax << ' ' << dataSets.back().ay << endl;
    //cout << dataSets.back().str;
    
    for(auto dataSet : dataSets){
        if(dataSet.x == 0) continue;
        cout << search(dataSet.x, dataSet.y, dataSet.ax, dataSet.ay, dataSet.str) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int[] H, W;
        int i, j, k, count;

        H = new int[100000];
        W = new int[100000];

        i=0;
        while(true){
            if(i == 100000){break;}

            H[i] = sc.nextInt();
            W[i] = sc.nextInt();

            if(H[i] == 0 && W[i] == 0){break;}
            i++;
        }
        count = i;

        for(k=0;k<count;k++){
            for(i=0;i<H[k];i++){
                for(j=0;j<W[k];j++){
                    if(i%2==0){
                        if(j%2==0){
                            System.out.print("#");
                        }else{
                            System.out.print(".");
                        }
                    }else{
                        if(j%2==0){
                            System.out.print(".");
                        }else{
                            System.out.print("#");
                        }
                    }

                }
                System.out.println();
            }
            System.out.println();
        }
    }
}



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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;

  rep(i, 0, n) {
    int a, b, c, d, ov = 5, er = 2;
    cin >> a >> b >> c >> d;

    cout << min((a * c + b * d), ((a * max(c, ov) + b * max(d, er)) * 4 / 5))
         << '\n';
  }

  return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100000];
	cin>>n;
	long long ans=1e18;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<2;i++){
		int sum=0;
		long long ans_=0;
		for(int j=0;j<n;j++){
			sum+=a[j];
			if(sum>=0&&j%2==i){
				ans_+=sum+1;
				sum=-1;
			}else if(sum<=0&&j%2!=i){
				ans_+=1-sum;
				sum=1;
			}
		}
		ans=min(ans,ans_);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 1e10
#define endl '\n'
#define mp make_pair
#define INF INT_MAX
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)			//counts no of ones in binary representation
#define w(t) 	int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

int main(){
	fast;
	ll x,n;
	cin>>x>>n;
	ll a[n];
	bool vis[110]={0};
	forn(i,n){
		cin>>a[i];
		vis[a[i]]=1;
	}
	ll ans=-1,d;
	int i;
	for( i=x;i>=1;i--){
		if(!vis[i]){
			ans=i;
			break;
		}
		
	}
	if(i==0)	ans=0;
	d=abs(x-ans);
	for(int i=x+1;i<110;i++){
		if(!vis[i]){
			if(abs(x-i)<d){
				ans=i;
				break;
			}
		}
	}
	
	cout<<ans;
}

Measured memory_bytes: 3652
def cnct(lint,lim):
    global count
    lintlst=list(str(lint))
    if lint>lim:
        return True
    if lintlst.count("3") and lintlst.count("5") and lintlst.count("7"):
        count+=1
    cnct(lint*10+3,lim)
    cnct(lint*10+5,lim)
    cnct(lint*10+7,lim)
list753=[3,5,7]
count=0
b=int(input())
for a in list753:
    cnct(a,b)
print(count)

Measured memory_bytes: 3064
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        String B = sc.next().replace(".","");

        BigDecimal a = new BigDecimal(A);
        BigDecimal b = new BigDecimal(B);

        BigDecimal ans = a.multiply(b).divide(new BigDecimal(100));


        System.out.println(ans.longValue());
    }
}

Measured memory_bytes: 36136
# E - NEQ

N, M = map(int, input().split())
MOD = 10 ** 9 + 7

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]

for i in range(2, M+1):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)

fixed = (fac[N] * fac[M] * pow(finv[M-N], 2, MOD)) % MOD

def f(k):
    return (fac[M-k] * finv[k] * finv[N-k]) % MOD

ans = 0
for i in range(N+1):
    ans = (ans + fixed * f(i) * pow(-1, i)) % MOD

print(ans)

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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}



int main()
{

set<char>st={'A','C','G','T'};


string s;cin>>s;
ll ans=0;
int n=s.size();

for(int l=0;l<n;l++)
{
  ll cnt=0;
  for(int r=l;r<n;r++)
  {
       if(st.find(s[r])==st.end())break;
       else cnt++;     
  }
  ans=max(ans,cnt);
}

cout<<ans<<"\n";



return 0;

}


Measured memory_bytes: 256
K = input().split(" ")
N = int(K[0])
A = int(K[1])
B = int(K[2])
if A == 0:
    print(0)
else:
    M = N%(A+B)
    L = N//(A+B)
    if M <= A:
        K = L*A+M
    else:
        K = L*A+A
    print(K)
        

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}

/*
<url:https://arc071.contest.atcoder.jp/tasks/arc071_c>
問題文============================================================
 A, B からなる文字列に対して、次の操作を考えます。
 
 文字列中の 1 文字を選ぶ。それが A なら BB で、 B なら AA で置き換える。
 AAA か BBB であるような部分文字列を選び、消す。
 例えば、ABA という文字列で 1 番目の操作を 1 文字目に対して行うと、 BBBA となります。
 また、BBBAAAA に対して 2 番目の操作を 4 文字目から 6 文字目に対して行うと、 BBBA となります。
 
 これらの操作を何回でも好きな順で行うことができます。
 
 文字列 S,T と q 個のクエリ ai,bi,ci,di が与えられます。
 各クエリに対して、
 S の部分文字列 SaiSai+1…Sbi を
 T の部分文字列 TciTci+1…Tdi にすることができるか判定してください。
 
 1≤|S|,|T|≤10^5
 S,T は文字A,Bからなる。
 1≤q≤10^5
 1≤ai≤bi≤|S|
 1≤ci≤di≤|T|

=================================================================

解説=============================================================

================================================================
*/
void solve(){
    string S,T; cin >> S >> T;
    int Q; cin >> Q;
    vector<int> cusumS(S.length()+1,0),cusumT(T.length()+1,0);
    for(int i = 0; i < S.length();i++){
        if(S[i] == 'A') cusumS[i+1] = cusumS[i] + 2;
        else cusumS[i+1] = cusumS[i] + 1;
    }
    for(int i = 0; i < T.length();i++){
        if(T[i] == 'A') cusumT[i+1] = cusumT[i] + 2;
        else cusumT[i+1] = cusumT[i] + 1;
    }
    while(Q--){
        int a,b,c,d; cin >> a >> b >> c >> d;
        if(abs((cusumS[b]-cusumS[a-1])-(cusumT[d]-cusumT[c-1]))%3 == 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    solve();
	return 0;
}


Measured memory_bytes: 1744
N = int(input())
A = list(map(int, input().split()))
check = 1
ans = 0

for i in range(N):
    if(A[i] != check):
        ans += 1
    if(A[i] == check):
        check += 1

if (ans == N):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 24744
L, R = [int(x) for x in input().split()]

if R - L >= 2018:
    ans = 0
else:
    ans = 2018
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            ans = min(ans, i * j % 2019)
            if ans == 0: break
        else:
            continue
        break

print(ans)


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

static const int MOD = 1e9 + 7;
signed main () {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n, *v;
    cin >> n;

    v = new int[n+1];
    v[0] = 0;

    int i;
    for (i = 1; i <= n; ++i) {
        cin >> v[i];
        (v[i] += v[i-1]) % MOD;
    }

    int ans = 0;
    for (i = 1; i < n; ++i)
        (ans += (v[i] - v[i-1]) * ((v[n] - v[i] + MOD) % MOD) % MOD) % MOD;
    
    cout << ans % MOD;
    return 0;
}

Measured memory_bytes: 5200
n = int(input())
a = list(map(int, input().split()))
fumi_sum = 0
for i in range(1,n):
    if a[i] < a[i-1]:
        fumi_sum += a[i-1] - a[i]
        a[i] += a[i-1] - a[i]
print(fumi_sum)

Measured memory_bytes: 32332
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <iomanip>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    double ans = 0.0;
    for(int b = 1; b <= N; ++b){
        double p = 1.0 / N;
        int c = b;
        while(c < K){
            c *= 2;
            p *= 0.5;
        }
        ans += p;
    }
    cout << setprecision(16) << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

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

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

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

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

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

int main() {
  //ll ans=LLONG_MAXs;
  ll ans=0;
  ll N,K;

  cin>>N>>K;

  ll tmp;
  ll A[N];
  FOR(i,0,N-1){
    cin>>A[i];
    if(A[i]==1)tmp=i;
  }

  //ans=tmp/(K-1);

  //if(tmp%(K-1)!=0)ans++;

  //ans=ans+(N-1-tmp)/(K-1);

  //if((N-1-tmp)%(K-1)!=0)ans++;

  ans=(N-1)/(K-1);

  if((N-1)%(K-1)!=0)ans++;


cout<<ans<<endl;
return 0;

}
 


Measured memory_bytes: 1024
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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 all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t;
  cin>>s>>t;
  int dp[s.size()+1][t.size()+1];
  rep(i,s.size()+1){
    rep(j,t.size()+1){
      dp[i][j]=0;
    }
  }
  string res;
  int n=s.size();
  int m=t.size();
  FOR(i,1,n+1){
    FOR(j,1,m+1){
      if (  s[i-1] == t[j-1] ){
        dp[i][j] = dp[i-1][j-1] + 1;
      }else{
        dp[i][j] = max( dp[i][j-1] , dp[i-1][j] );
      }
    }
  }
  int x=n,y=m;
  int ndp = dp[x][y];
  while( x > 0 & y > 0 ){
   if ( ndp-1 == dp[x-1][y-1] && s[x-1]==t[y-1] ){
      x-=1; 
      y-=1; 
      ndp-=1;
      res = s[x] + res;
   }
   else if(ndp == dp[x-1][y]){
     x-=1;
   }
   else{
     y-=1;
    }
  }
  cout<<res<<endl;
}
  


Measured memory_bytes: 35584
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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


    ll ans=0;
    ll anss =0;
    ll count=0;
    ll i,j,h;
    ll Q,N,M,K,P,A,B;
    
    ll a, b,c,d;
    long double x;

    vector<ll> aa;
    vector<ll> bb;
    vector<ll> cc;
    vector<ll> dd, tt;
    string S;

    ll flag=0;
    ll temp=0;

    long double X;

    cin  >> N>>M>>Q;
    
    for(i=0;i<Q;i++){
cin>>a>>b>>c>>d;
aa.push_back(a);
bb.push_back(b);
cc.push_back(c);
dd.push_back(d);
    }

    for(i=0;i<N;i++){
        tt.push_back(1);
    }
    while(1){
        temp=0;
        rep(i, Q){
            if((tt[bb[i]-1]-tt[aa[i]-1])==cc[i]){
                temp+=dd[i];
            }
        }
        
        ans=max(ans,temp);
        //rep(i,N)cout<<tt[i];
        //cout<<endl;
        //cout<<temp<<endl;
        if(accumulate(tt.begin(), tt.end(), 0)==M*N){
            break;
        }
        ll curai=0;
        while(1){
            if(tt[N-curai-1]==M){
                curai++;
            }else{
                tt[N-curai-1]++;
                for(i=0;i<curai;i++){
                    tt[N-i-1]=tt[N-curai-1];
                }
                break;
            }
        }
    }

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

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <set>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
#define maxn 200005
int n,k,p[maxn],par[maxn],f[maxn];
//f[i]: max sorted len that ends at p[i]
set <int> s;
typedef set <int> :: iterator Ite;
int fin(int u){
  if(par[u] == u) return u;
  return par[u] = fin(par[u]);
}
void uni(int u,int v){
  u = fin(u), v = fin(v);
  if(u == v) return;
  par[u] = v;
}
int main(){
  n = getint(), k = getint();
  for(int i = k;i <= n;i++) par[i] = i;
  int pre = 0;
  for(int i = 1;i <= n;i++){
    p[i] = getint();
    if(p[i] > p[i - 1]) f[i] = f[i - 1] + 1;
    else f[i] = 1;
    if(f[i] == k){
      if(pre) uni(pre,i);
      pre = i;
    }
  }
  for(int i = 2;i <= k;i++) s.insert(p[i]);
  for(int i = 1;i <= n - k;i++){
    Ite it = s.end(); it--;
    if(p[i] < *s.begin() && *it < p[i + k]) uni(i + k - 1,i + k);
    s.erase(p[i + 1]);
    s.insert(p[i + k]);
  }
  int ans = 0;
  for(int i = k;i <= n;i++) ans += (par[i] == i);
  putint(ans,'\n');
  bufo.flush();
  return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, k; cin >> n >> k;
	vi dp(n + 1);
	dp[0] = 1;
	
	for(int i = 1; i < k; i++){
		for(int j = 0, sum = dp[0]; j + i < n; j++)
			dp[j] = (sum += dp[j + 1]) %= mod;
		dp[n - i] = 0;
	}
	ll ans = accumulate(all(dp), 0ll);
	rep(i, n - k - 1) ans = ans * 2 % mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve(int a[],int num)
{
    int mini=0,tmp=0;
    for(int i=0;i<num;i++)
    {
        mini = i;
        for(int j=i;j<num;j++)
            if(a[j]<a[mini]) {
                mini = j;
            }

            if(i!=mini) {
                swap(a[i], a[mini]);
                tmp++;
            }

    }
    for(int i=0;i<num;i++)
        if(i==num-1)     cout<<a[i]<<endl;
        else  cout<<a[i]<<" ";
    cout<<tmp<<endl;
}
int main()
{
    int num;
    cin>>num;
    int a[num];
    for(int i=0;i<num;i++)
        cin>>a[i];
    solve(a,num);
    return 0;
}


Measured memory_bytes: 3100
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n, k = i_map()
    h = [i_input() for i in range(n)]
    h.sort()
    print(min(h[i+k-1] - h[i] for i in range(n-k+1)))


if __name__=="__main__":
    main()


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

int main() {
    int A, B;
    cin >> A;
    cin >> B;

    if (max(A+B, A-B) >= (A * B)) {
        cout << max(A+B, A-B) << endl;
    }
    else {
        cout << (A*B) << endl;
    }
}

Measured memory_bytes: 256
N,D = map(int,input().split())

a=0
b=0
d=D**2
list1=[]
for j in range(N):
    lista = list(map(int,input().split()))
    a = lista[0]**2
    b = lista[1]**2
    c = a+b
    if (d >= c):
        list1.append(1)

print(len(list1))


Measured memory_bytes: 10444
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string S;
    cin>>S;
    ll di[300000];
    di[1]=1;
    ll sur[300000];
    sur[0]=0;
    ll ex[2019];
    MEMSET(ex, 0);
    ex[0]++;
    rep1(i, S.size()){
        ll th=S.size()-i;
        ll thisnum=S[th]-'0';
        sur[i]=(di[i]*thisnum%2019+sur[i-1])%2019;
        ex[sur[i]]++;
        di[i+1]=(di[i]*10)%2019;
        //cout<<sur[i]<<sp<<thisnum<<endl;
    }
    ll counter=0;
    rep(i, 2019){
        counter+=((ex[i])*(ex[i]-1))/2;
    }
    cout<<counter<<endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
string s;

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  cin>>s;
  rep(r,101)rep(l,101){
    string tmp;
    rep(i,l)tmp+="(";
    tmp+=s;
    rep(i,r)tmp+=")";
    stack<char> st;
    bool ok=true;
    rep(i,tmp.size()){
      if(tmp[i]=='(')st.push(s[i]);
      else if(st.size()>0)st.pop();
      else ok=false;
    }
    if(st.size()==0&&ok){
      cout<<tmp<<endl;
      return 0;
    }
  }
	return 0;
}


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 109, M = 2e5 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    int a, b, c, k; cin >> a >> b >> c >> k;

    int ans = min(a, k);

    k -= min(a, k);

    k -= min(b, k);

    ans -= min(c, k);

    cout << ans;

}


Measured memory_bytes: 3584
// ※※※ 解答不能 ※※※
// LHiC氏
// https://atcoder.jp/contests/agc041/submissions/9177111
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
using LL = long long;
const int N = 210000;
int n, v, p;
LL m, a[N];

int main(){
    scanf("%d %d %d %d", &n, &m, &v, &p);
    rep(i, n) scanf("%lld", &a[i]);
    sort(a, a + n);
    reverse(a, a + n);
    int ans = p;
    LL sum = 0;
    repx(i, p, n){
        sum += a[i - 1];
        int cnt = i - p + 1;
        LL cs = sum - a[i] * cnt;
        int av = v - (p - 1) - (n - i);
        av = max(av, 0);
        av = cnt - av;
        if(m >= a[p - 1] - a[i] && av * m >= cs) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n,A[MAX],s;
int B[MAX],T[VMAX+1];

int solve(){
    int ans = 0;

    bool V[MAX];
    for(int i = 0;i<n;i++){
        B[i] = A[i];
        V[i] = false;
    }
    sort(B,B+n);
    for(int i = 0;i<n;i++)
        T[B[i]] = i;
    for(int i = 0;i<n;i++){
        if(V[i])
            continue;
        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        do{
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m,v);
            S += v;
            cur = T[v];
        }while(!V[cur]);
        ans += min(S + (an - 2)*m, m+S+(an+1)*s);
    }
    return ans;
}

int main(){
    cin>>n;
    s = VMAX;
    for(int i = 0;i<n;i++){
        cin>>A[i];
        s = min(s,A[i]);
    }
    int ans = solve();
    cout<<ans<<endl;
}

Measured memory_bytes: 3168
import bisect

n=int(input())
l=list(map(int,input().split()))

l.sort()
ans=0

for i in range(n-2):
  for j in range(i+1,n-1):
    a=l[i]+l[j]
    b=l[j]-l[i]
    
    x=bisect.bisect_right(l,b)
    y=bisect.bisect_left(l,a)-1
    X=max(j+1,x)
    if y-X+1>0:
      ans+=y-X+1
      
print(ans)

Measured memory_bytes: 74792
#include	<stdio.h>
int	main(void)
{
	int n[100]={};	//?????????????????????100????????????0????????????????????????
	int a,i;		//a?????\???????????°???????????°???i???????????????????????????

	scanf("%d",&a);		//??\???????????°???????????°????±?????????????
	for(i=0; i<a; i++){
		scanf("%d ",&n[i]);
	}

	for(i=a-1; i>=0; i--){		//??\??????????????°?????????????????¨???????????????????????????????????????
		printf("%d",n[i]);
		if(i) printf(" ");		//????´??????¨??????????????\?????????
	}puts("");					//???????????????????????§???????????\????????????

	return	0;
}
	

Measured memory_bytes: 616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {


			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}

			var N = inputArray[0];
			var bukaArray = retreiveLongArray();
			var jousiDic = new Dictionary<long, long>();

			foreach (var jousi in bukaArray) {

				if (jousiDic.ContainsKey(jousi)) {
					jousiDic[jousi]++;
				}
				else {
					jousiDic.Add(jousi, 1);
				}

			}

			//答えの出力
			for (int i = 1; i <= N; i++) {
				if (jousiDic.ContainsKey(i)) {
					Console.WriteLine(jousiDic[i]);
				}
				else {
					Console.WriteLine(0);
				}

			}


		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 56860
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


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

  int ans = 0;
  if (x == 1) { cout << 1 << endl; return 0; }
  for (int b = 2; b <= 31; b++) { // b^2 <= 1000
    for(int p = 2; p <= 9; p++) { // 2^p <= 1000
      int b_p = pow(b, p);
      if (b_p > 1000) {
        break;
      }
      if (b_p > x) {
        break;
      }
      dump(b_p);
      ans = max(ans, b_p);
      dump(ans);
    }
  }

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


Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
    long long int n,m,ans=0;
    scanf("%lld%lld", &n,&m);

    if(2*n<=m)
    {
        ans+=n;
        m-=2*n;
    }
    else
    {
        ans+=(m-m%2)/2;
        m=m%2;
    }
    
    if(m>=4)
    {
        ans+=(m-m%4)/4;
    }
    printf("%lld", ans);

    return 0;

}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int d,t,s; cin>>d>>t>>s;
    if(t*s >= d) out("Yes"); else out("No");
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define MODNUM 1000000007

using ll = long long;
using namespace std;

int main(){
    string S;
    cin >> S;

    string ans;

    //R個の全探索(2^R通り)
    for (int bit = 0; bit < (1 << 3); bit++) {
        int tmp = (S[0] - '0');
        for (int i = 0; i < 3; i++) {
            //i番目のビットが立っていた時の処理
            if (bit & (1<<i)) {
                tmp += (S[i+1] - '0');
            } else {
                tmp -= (S[i+1] - '0');
            }
        }
        
        if(tmp == 7) {
            rep(i,3) {
                ans += S[i];
                if (bit & (1<<i)) ans += '+';
                else ans += '-';
            }
            ans += S[3];
            ans += "=7";
            break;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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


int main() {
    string a, b; cin >> a >> b;
    int c = stoi(a+b);
    for (int i=1; i<100*100; ++i) {
        if (i*i == c) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
DBG = !true
DBG2 = !true
nl = "\n"

n = gets.to_i
a = gets.split.map{|x| x.to_i}
puts "after split" if DBG2

h = Hash.new(0)
for i in 0...a.size
  x = a[i]
  #if h.keys.include?(x)
    h[x] += 1
  #else
  #  h[x] = 1
  #end
end
puts "after create h" if DBG2

b = []
for k in h.keys
  b << k
end
b.sort!

puts "bsz: #{b.size}" if DBG
print b if DBG
puts "" if DBG

puts "before loop" if DBG2

sum = 0
(b.size - 1).downto(0) { |i|
  c = b[i]
  key   = c
  #card  = c[1]
  card  = h[key]

  # find msb
  msb = 2**32
  while (msb & key) == 0
    msb /= 2
  end

  bud = 2*msb - key
  print "i: #{i} ky:#{key} cd:#{card} msb:#{msb} bud:#{bud}#{nl}" if DBG

  bcard = h[bud]
  next if bcard == 0  # !h.keys.include?(bud)
  if bud != key
    npairs = [card, bcard].min
    sum += npairs
    h[bud] -= npairs
  else
    npairs = card/2
    sum += npairs
  end
}

print sum


Measured memory_bytes: 36596
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;

struct Point {
  int id, x, y, key;
  Point(int id = 0, int x = 0, int y = 0):id(id),x(x),y(y){};
  bool is_edge(int r, int c) const {
    return (x == 0 || x == r || y == 0 || y == c);
  };
  void calc_key(int r, int c) {
    if (y == 0) key = x;
    else if (x == r) key = r + y;
    else if (y == c) key = r + c + (r - x);
    else key = r + c + r + (c - y);
  };
};

struct Pred {
  bool operator()(const Point& pt1, const Point& pt2) const {
    return pt1.key < pt2.key;
  };
};

int main(int argc, char *argv[])
{
  int r, c, n;
  cin >> r >> c >> n;

  vector<Point> pts;
  pts.reserve(n);
  for (int i = 0; i < n; ++i) {
    Point pt1(i), pt2(i);
    cin >> pt1.x >> pt1.y >> pt2.x >> pt2.y;
    if (pt1.is_edge(r,c) && pt2.is_edge(r,c)) {
      pt1.calc_key(r, c); pt2.calc_key(r, c);
      pts.push_back(pt1);
      pts.push_back(pt2);
    }
  }
  if (pts.size() <= 2) {
    cout << "YES" << endl;
    return 0;
  }

  sort(pts.begin(), pts.end(), Pred());

  stack<int> st;
  set<int> flag;
  for (int i = 0; i < pts.size(); ++i) {
    int id = pts[i].id;
    if (flag.find(id) == flag.end()) {
      st.push(id);
      flag.insert(id);
    } else {
      if (st.top() != id) {
        cout << "NO" << endl;
        return 0;
      }
      st.pop();
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 8036
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  1000000007;
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
     signed main(){
     
    int n,k;
    cin>>n>>k;
    int z,ans[k+1]={},ans2=0;
    for(int i=k;i>=1;i--){
         if(k/i!=k/(i+1))z=modpow(k/i,n,MOD);
         ans[i]=z;
         for(int j=2;j*i<=k;j++)ans[i]=(ans[i]+MOD-ans[j*i])%MOD;
         ans2=(ans2+i*ans[i]%MOD)%MOD;
    }

    
     cout<<ans2<<endl;
      }

        


Measured memory_bytes: 4376
#include <bits/stdc++.h>  
#include <iostream>
#include <string>
typedef long long int ll;

using namespace std;

int main() {
  int n;cin>>n;
  int ans=-n;
  for(int i=0;i<n;i++){
    int k;cin>>k;ans+=k;}
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>
using namespace std;

pair<int, int> pii[10005];
int N, answer;
bool isPrime(int n) {
    if (n == 1) return 0;
    if (n == 2) return 1;
    for (int i = 2; i <= sqrt(n); i ++)
        if (n % i == 0) return false;
    return true;
}
int main() {
    while (scanf("%d", &N) != EOF) {
        answer = 0;
        for (int i = 1; i <= N; i ++) {
            pii[i].first = i;
            pii[i].second = N - i + 1;
        }
        for (int i = 1; i <= N; i ++) {
            if (isPrime(pii[i].first) && isPrime(pii[i].second))
                answer ++;
        }
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 1284
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int Q = in.nextInt();
			long[] an = new long[Q];
			long[] bn = new long[Q];
			for (int i = 0; i < Q; i++) {
				an[i] = in.nextLong();
				bn[i] = in.nextLong();
			}

			for (int i = 0; i < Q; i++) {
				long a = Math.min(an[i], bn[i]);
				long b = Math.max(an[i], bn[i]);

				if (a == b || a + 1 == b) {
					out.println(2 * a - 2);
				} else {
					long c = sqrt(a, b);
					if (c * (c + 1) >= a * b) {
						out.println(2 * c - 2);
					} else {
						out.println(2 * c - 1);
					}
				}
			}

		}
		static long sqrt(long a, long b) {
			long c = (long)Math.sqrt(a * b);
			while (c * c >= a * b) {
				c--;
			}
			return c;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21460