akhauriyash/Code-Regression huggingface dataset:
n = int(input())
dp = [0] * 100001
potential = [1]
k = 6
while(k < 100000):
    potential.append(k)
    k *= 6
k = 9
while(k < 100000):
    potential.append(k)
    k *= 9
for i in range(1,100001):
    pre = list(filter(lambda x: x<=i, potential))
    dp[i] = min(list(map(lambda x: dp[i-x], pre))) + 1
print(dp[n])


Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;


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

	int N;
	cin >> N;
	vector<int> a(N);
	REP(i, N) cin >> a[i];
	int res = 0;
	FOR(i, 1, N - 1) {
		if (a[i] == a[i - 1] && a[i] == a[i + 1]) {
			a[i] = -i;
			res++;
		}
	}
	FOR(i, 1, N) {
		if (a[i] == a[i - 1]) {
			a[i] = -i;
			res++;
		}
	}
	cout << res << "\n";
	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcoder096_C
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力を受け取る
            int[] t_input = (Console.ReadLine().Split()).Select(i => int.Parse(i)).ToArray();
            int H = t_input[0];
            int W = t_input[1];
            string t_map;
            string jdg = "Yes";
            char[,] map = new char[H + 2, W + 2];

            //"."をすべての二次元配列に入れる
            for (int i = 0; i < H + 2; i++)
            {
                for (int j = 0; j < W + 2; j++)
                {
                    map[i, j] = '.';
                }
            }

            for (int i = 1; i < H + 1; i++)
            {
                t_map = Console.ReadLine();
                for (int j = 1; j < W + 1; j++)
                {
                    map[i, j] = (char)t_map[j-1];
                }
            }

            //周りに一つも#がないものを探す
            for (int i = 1; i < H + 1; i++)
            {
                for (int j = 1; j < W + 1; j++)
                {
                    if (map[i, j] == '#')
                    {
                        if (map[i - 1, j] == '#') continue;
                        if (map[i + 1, j] == '#') continue;
                        if (map[i, j - 1] == '#') continue;
                        if (map[i, j + 1] == '#') continue;
                        jdg = "No";
                    }
                }
            }

            //出力
            Console.WriteLine(jdg);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>


int main (void)
{
	int N;
	scanf("%d",&N);
	
	int A[N];
	int i,j,v,k;
	
	for(i=0; i<N; i++)
	{
		scanf("%d",&A[i]);
	}
	
	for(i=0; i<N; i++)
	{
		v=A[i];
		j=i-1;
		
		while(j>=0 && A[j]>v)
		{
			A[j+1]=A[j];
			
			j--;
		}
		
		A[j+1]=v;
	
	
	for(k=0; k<N; k++)
	{
		printf("%d",A[k]);
		
		if(k<N-1)
		{
			printf(" ");
		}
	}
		
		printf("\n");
	}
	
	return 0;
}


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

typedef long long int ll;
ll powk(ll a, ll n){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(ll i = 0;i < h;i++){
        cin >> s[i];
    }

    queue<pair<ll,ll>> t;
    ll cht[4] = {0, 1, 0, -1};
    ll chy[4] = {-1, 0, 1, 0};
    ll ans = 0;

    for(ll i = 0;i < h;i++){
        for(ll j = 0;j < w;j++){
            if(s[i][j] == '.'){
                t.push(pair<ll,ll>(i,j));
                ll cnt = 1;
                vector<string> sc = s;
                vector<vector<ll>> si(h,vector<ll>(w));
                sc[i][j] = '#';
                while(!t.empty()){
                    pair<ll,ll> temp = t.front();
                    t.pop();
                    for(ll k = 0;k < 4;k++){
                        ll nt = temp.first + cht[k];
                        ll ny = temp.second + chy[k];
                        if(nt < 0 || ny < 0 || nt >= h || ny >= w){
                            
                        }
                        else{
                            if(sc[nt][ny] == '.'){
                                sc[nt][ny] = '#';
                                si[nt][ny] = si[temp.first][temp.second] + 1;
                                t.push(pair<ll,ll>(nt,ny));
                                ans = max(si[nt][ny], ans);
                            }
                        }
                    }
                }
            //cout <<cnt<<endl;
            ans = max(cnt, ans);
            }
        }
    }

    cout << ans;

    return 0;
}

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

using namespace std;

long long n;
long long a[200010];
long long dp[200010][10];

int main(void)
{
	scanf("%lld", &n);
	
	for(long long i = 0 ; i < n ; i++)
		scanf("%lld", &a[i]);
	
	dp[0][0] = a[0];
	dp[1][1] = a[1];
	
	if(n > 2)
	{
		dp[2][2] = a[2];
		dp[2][0] = a[0] + a[2];
	}
	
	if(n > 3)
		dp[3][1] = max(a[0] + a[3], a[1] + a[3]);
	
	for(int i = 4 ; i < n ; i++)
	{
		if(i % 2 == 0)
			dp[i][0] = dp[i - 2][0] + a[i];
		dp[i][1] = max(dp[i - 2][1] + a[i], dp[i - 3][0] + a[i]);
		dp[i][2] = max(dp[i - 2][2] + a[i], max(dp[i - 3][1] + a[i], dp[i - 4][0] + a[i]));
	}
	
	if(n % 2 == 0)
		printf("%lld", max(dp[n - 1][1], dp[n - 2][0]));
	else
		printf("%lld", max(max(dp[n - 1][2], dp[n - 2][1]), dp[n - 3][0]));
	
	return 0;
}

Measured memory_bytes: 21000
n,k=map(int,input().split())
X=list(map(int,input().split()))
cost=float('inf')
for i in range(n-k+1):
    l=X[i]
    r=X[i+k-1]
    if l<=0:
        if r<=0:
            tmp=-l
        else:
            tmp_l=-l*2+r
            tmp_r=2*r-l
            tmp=min(tmp_l,tmp_r)
    else:
        tmp=r
    cost=min(cost,tmp)
print(cost)

Measured memory_bytes: 14532
package main

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

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func readInt(sc *bufio.Scanner) (res int) {
	res, _ =strconv.Atoi(readLine(sc))
	return
}

func readInts(sc *bufio.Scanner, n int) []int {
	ns := strings.Split(readLine(sc), " ")
	res := make([]int, n)

	for i, n := range ns {
		res[i], _ = strconv.Atoi(n)
	}
	return res
}

func readInt64s(sc *bufio.Scanner, n int) []int64 {
	ns := strings.Split(readLine(sc), " ")
	res := make([]int64, n)

	for i, n := range ns {
		res[i], _ = strconv.ParseInt(n, 10, 64)
	}
	return res
}

func readMatrix(sc *bufio.Scanner, rows, cols int) [][]int {
	res := make([][]int, rows)
	for i := 0; i < rows; i ++ {
		res[i] = readInts(sc, cols)
	}
	return res
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	x := readInt(sc)

	r := 0
	if x < 0 {
		x *= -1
	}
	p := 0
	for i := 0; i < 10000000; i ++ {
		p += i
		if x <= p {
			r = i
			break
		}
	}

	fmt.Println(r)
}

Measured memory_bytes: 640
main = readAndDo

readAndDo = do
  line <- getLine
  let (a, op, b) = input line
  if op == "?" then return ()
  else do
    print $ solve op a b
    readAndDo

-- 入力
input :: String -> (Int, String, Int)
input = decode . words
  where
    decode [a,b,c] = (readInt a, b, readInt c)
    readInt = read :: String -> Int

-- 解答
solve op a b | op == "+" = a + b
             | op == "-" = a - b
             | op == "*" = a * b
             | op == "/" = a `div` b
             | otherwise = 0



Measured memory_bytes: 4088
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};


int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout); 
    string s;
    cin>>s;
    string t = s;
    reverse(all(t));
    if( s==t ){
        bool ck=1;
        ll n = s.size();
        t = "";
        for(ll i=0;i<(n-1)/2;i++){
            t += s[i];
        }
        //cout << t << endl;
        string m = t;
        reverse(all(m));
        if ( m != t ) ck=0;
        t = "";
        for(ll i=(n+3)/2-1;i<n;i++){
            t += s[i];
        }
        //cout << t << endl;
        reverse(all(m));
        if( m!= t ) ck=0;
        if( ck ){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }  
    else{
        printf("No\n");
    }
}


Measured memory_bytes: 3600
#include<iostream>
main(){for(int N,M,P,X,S,i,m=0;std::cin>>N>>M>>P,N;m?printf("%d\n",S*(100-P)/m):puts("0"))for(S=i=0;i<N;S+=X*100,i++-M+1||(m=X*100))std::cin>>X;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int n, z, w; cin >> n >> z >> w;
  vector<int> A(n);
  for (auto& a : A) { cin >> a; }
  if (n == 1) {
    cout << (std::abs(A[0]-w)) << CRLF;
  } else {
    auto ans = std::max(std::abs(A[n-1]-w), std::abs(A[n-1]-A[n-2]));
    cout << ans << CRLF;
  }
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222


ll h[MAX];


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


  cin >> n;
  rep(i, n) cin >> h[i];
  bool used = false;
  while (1) {
    used = false;
    rep(i, n) {
      if (h[i]) {
        used = true;
        h[i]--;
      }
      else if (used){
        break;
      }
    }
    if (!used) break;
    ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def popcount(n):
    return bin(n).count('1')


def main():
    N = int(input())
    X = input()

    X_int = int(X, 2)

    pcount_X = popcount(X_int)

    pcount_X_pls1 = pcount_X + 1
    pcount_X_mns1 = pcount_X - 1
    
    X_mod_pcount_X_pls1 = X_int % pcount_X_pls1
    if pcount_X_mns1 != 0:
        X_mod_pcount_X_mns1 = X_int % pcount_X_mns1

    for i,bit in enumerate(X):
        bit = int(bit)
        if bit == 0:
            n = (X_mod_pcount_X_pls1 + pow(2, N-i-1, pcount_X_pls1)) % pcount_X_pls1
        else:
            if pcount_X_mns1 == 0:
                print(0)
                continue
            n = (X_mod_pcount_X_mns1 - pow(2, N-i-1, pcount_X_mns1)) % pcount_X_mns1

        ans = 1
        while n > 0:
            ans += 1
            n %= popcount(n)
        print(ans)
        
main()

Measured memory_bytes: 82568
S = list(input())

s = ''
count = 0
while S:
    if s == S[-1]:
        if len(S) >= 2:
            S.pop()
            S.pop()
            count+=1
            try:
                s = S.pop()
                count+=1
            except:
                break
        else:
            break        
    else:
        s = S.pop()
        count+=1
        
print(count)

Measured memory_bytes: 4840
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
typedef long long ll;
ll N;
double L;
double T[3000];

double dist(double x1, double x2, double y1, double y2){
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

double dist(int i, int j){
    double ti = 2*M_PI*T[i]/L;
    double tj = 2*M_PI*T[j]/L;
    return dist(cos(ti), cos(tj), sin(ti), sin(tj));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> L;
    for(int i = 0; i < N; i++) cin >> T[i];
    double n = N-2;
    double all = (N*(N-1)*(N-2))/6;
    double weight = (N-2)/all;
    double ans_x = 0.0, ans_y = 0.0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            double d = dist(i, j);
            // cout << i << ' ' << j << ' ' << d << endl;
            double ti = 2*M_PI*T[i]/L; double tj = 2*M_PI*T[j]/L;
            double t = (ti+tj)/2;
            double x1 = cos(t); double y1 = sin(t);
            double x2 = cos(t+M_PI); double y2 = sin(t+M_PI);
            int n2 = j-i-1, n1 = N-(j-i)-1;
            ans_x += x1*(double)n1/(double)n+x2*(double)n2/(double)n;
            ans_y += y1*(double)n1/(double)n+y2*(double)n2/(double)n;
            // cout << t << ' ' << n1 << ":(" << x1 << ',' << y1 << ')' << endl;
        }
    }
    cout << ans_x*weight << ' ' << ans_y*weight << endl;
}

Measured memory_bytes: 256
N, W = gets.split.map(&:to_i)
$ws, $vs = [], []
N.times do |i|
    $ws[i], $vs[i] = gets.split.map(&:to_i)
end

$dp = Array.new(N+1){Hash.new}

def knap(n, w)
    return -Float::INFINITY if w < 0
    return 0 if n < 0
    return $dp[n][w] if $dp[n][w]

    $dp[n][w] = [knap(n - 1, w), knap(n - 1, w - $ws[n]) + $vs[n]].max
    return $dp[n][w]
end

puts knap(N - 1, W)

Measured memory_bytes: 7932
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n,c=0; cin>>n;
    ll arr[n],brr[n];
    rep(i,0,n)   cin>>arr[i], brr[i]=arr[i];
    sort(arr, arr+n);
    rep(i,0,n) if(arr[i]!=brr[i]) c++;
    if(c<=2) cout<<"YES";
    else cout<<"NO";
    

}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


Measured memory_bytes: 3804
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br=new BufferedReader(
			new InputStreamReader(System.in));
		ArrayDeque<Integer> ad=new ArrayDeque<Integer>();
		String l[];
		int n=Integer.parseInt(br.readLine());
		for(int i=0;i<n;i++){
			l=br.readLine().split(" ");
			String c=l[0];
			switch(c){
				case "insert":ad.addFirst(Integer.parseInt(l[1]));break;
				case "delete":ad.remove(Integer.parseInt(l[1]));break;
				case "deleteFirst":ad.removeFirst();break;
				case "deleteLast":ad.removeLast();break;
			}
		}
		StringBuilder sb=new StringBuilder();
		sb.append(ad.poll());
		for(int t:ad)sb.append(" ").append(t);
		sb.append("\n");
		System.out.print(sb);
	}
}

Measured memory_bytes: 187704
#include "bits/stdc++.h"
using namespace std;
void fast() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
#define endl '\n'
//#define double long double
#define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

void solve() {
    string s;
    string s2;
    bool x = true;
    cin >> s >> s2; 
    for (int i = 0; i < s.length(); i++) {
		if (s[i] != s2[i]) {
			x = false;
			
		}
	}
	if (x) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
    
}

signed main() {
    
    fast();
    int t = 1;
    //cin >> t; // comment this line if single case
    while (t--) {
        solve();
    }
    
    
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

int main()
{
	int dish;
	int min = 15;
	int sum = 0;

	for (int i = 0; i < 5; i++) {
		cin >> dish;
		if (dish % 10) {
			sum += dish + 10 - dish % 10;
		} else {
			sum += dish;
		}
		if (dish % 10 != 0 && dish % 10 < min) {
			min = dish % 10;
		}
	}
	if (min != 15) {
		sum -= (10 - min);
	}

	printf("%d", sum);

	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,d; cin>>n>>d;
	int ans=0;
	for(int i=0;i<n;++i){
		int64_t x,y; cin>>x>>y;
		ans+=(sqrt(x*x+y*y)<=d);
	}
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3640
n=int(input())
num_list=list(map(int,input().split()))

flag=1
count=0
while flag:
    flag=0
    for j in range(n-1,0,-1):
        if num_list[j]<num_list[j-1]:
            tmp=num_list[j]
            num_list[j]=num_list[j-1]
            num_list[j-1]=tmp
            count+=1
            flag=1

ans=str(num_list[0])
for i in range(1,len(num_list)):
    ans+=" "+str(num_list[i])
print(ans)
print(count)



Measured memory_bytes: 5596
#include<iostream>
#include<string>

using namespace std;

int main() {
  string s;
  cin >> s;
  string a = "dream",b = "dreamer",c = "erase",d = "eraser";
  string ans;

  for(int i = s.size()-1; i > 0;) {
    int j = 0;
    for(; j < a.size(); j++) {
      if(s[i-j] != a[a.size()-1 - j]) {
          break;
      }
    }
    if(j == a.size()) {
      i = i - j;
      continue;
    }

    j = 0;
    for(; j < b.size(); j++) {
      if(s[i-j] != b[b.size()-1 - j]) {
          break;
      }
    }
    if(j == b.size()) {
      i = i - j;
      continue;
    }

    j = 0;
    for(; j < c.size(); j++) {
      if(s[i-j] != c[c.size()-1 - j]) {
          break;
      }
    }
    if(j == c.size()) {
      i = i - j;
      continue;
    }

    j = 0;
    for(; j < d.size(); j++) {
      if(s[i-j] != d[d.size()-1 - j]) {
          break;
      }
    }
    if(j == d.size()) {
      i = i - j;
      continue;
    }

    cout << "NO" << endl;
    return 0;
  }

  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
typedef long long int ll;
static const int MAX_N = 300000;
static const int MOD = 998244353;

ll N, A, B, K;

ll memo_fact_mod[MAX_N + 1];
ll memo_fact_inverse_mod[MAX_N + 1];
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x * x % MOD, n / 2);
	if(n % 2 == 1) res = res * x % MOD;
	return res;
}
ll fact_mod(ll n){
	ll res = 1;
	for(ll i = 1; i <= n; i++){
		res *= i;
		res %= MOD;
	}
	return res;
}
ll fact_inverse_mod(ll n){
	ll res = mod_pow(fact_mod(n), MOD - 2);
	return res;
}
ll combination(ll n, ll r){
	return (((fact_mod(n) * fact_inverse_mod(r)) % MOD) * fact_inverse_mod(n - r)) % MOD;
}
ll combination_with_memo(ll n, ll r){
	if(r == 0 || r == n) return 1;
	else return (((memo_fact_mod[n] * memo_fact_inverse_mod[r]) % MOD) * memo_fact_inverse_mod[n - r]) % MOD;
}
 
int main(){
	memo_fact_mod[0] = 0; memo_fact_mod[1] = 1LL;
	for(int i = 2; i <= MAX_N; i++){
		memo_fact_mod[i] = (memo_fact_mod[i - 1] * i) % MOD;
	}
	for(int i = 0; i <= MAX_N; i++){
		memo_fact_inverse_mod[i] = mod_pow(memo_fact_mod[i], MOD - 2);
	}
	cin >> N >> A >> B >> K;
	ll ans = 0;
	for(ll i = 0; i <= N; i++){
		if(i * A > K) break;
		if((K - A * i) % B != 0) continue;
		ll j = (K - A * i) / B;
		if(j > N) continue;
		ans += (combination_with_memo(N, i) * combination_with_memo(N, j)) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <limits.h>
#include <stdio.h>
#include <string.h>

int main(void){
	char S[100], c;
	int s=0, a=0, i;
	while((c=getchar())!=10) S[s++]=c;
	for(i=s/2-1; i>=0; i--){
		if(S[i]!=S[s-i-1]) a++;
	}
	printf("%d\n", a);
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

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

    bool a = false;
    if ((s[0] == '0' && s[1] != '0' )|| (s[0] == '1' && (s[1] == '0' || s[1] == '1' || s[1] == '2'))) {
        a = true;
    }
    bool b = false;
    if ((s[2] == '0' && s[3] != '0') || (s[2] == '1' && (s[3] == '0' || s[3] == '1' || s[3] == '2'))) {
        b = true;
    }

    if (a && b) {
        cout << "AMBIGUOUS" << endl;
    } else if (a) {
        cout << "MMYY" << endl;
    } else if (b) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
}


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

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

  long long ans = 0;
  for (long long i=N; i>=0; i--) {
    long long temp = sqrt(i);
    if (i == pow(temp, 2)) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;;

  return 0;
}


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

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

  int A, B;
  cin >> A >> B;
  int x = max(A,B) - min(A,B);
  if(x % 2 == 0){
    cout << x / 2 + min(A,B)<<endl;
  } else{
    cout << "IMPOSSIBLE" <<endl;
  }
}

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

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main (){
    int n,m;
    int ans=0;
    cin >>  n >> m;
    int g[m][n];
    rep(i,m) rep(j,n) g[i][j]=0;
    rep(i,m){
        int k;
        cin >> k;
        rep(j,k){
            int s;
            cin >> s;
            g[i][s-1]=1;
        } 
    }
    int p[m];
    rep(i,m) cin >> p[i];
    rep(i,1<<n){
        vector<int>den(m,0);
        vector<int>bin(n,0);
        bool flag=true;
        rep(j,n) {
            if(i>>j&1) bin[j]=1;
        }
        rep(s,m){
            rep(t,n){
                if(bin[t]==1) den[s]+=g[s][t];
            }
        }
        rep(j,m) {
            if(p[j]!=den[j]%2) flag=false;
        }
        if(flag) ans++;
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
/*
  ID: oodt
  PROG:
  LANG:C++
*/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>

using namespace std;

const int maxx=10005;
int n,m,k;
int a[maxx];
int ans = 0,cnt = 0,pos = 0;
int l = 0,r = 0;

int main()
{
#ifdef LOCAL
//    freopen("","r",stdin);
#endif
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    int ok = 1;
    int alice = 0;
    int bob = 0;
    for(int i = n-1 ; i >= 0 ; i--)
    {
        if(ok){
            ok = 0;
            alice += a[i];
        }
        else{
            ok = 1;
            bob += a[i];
        }
    }
    printf("%d\n",alice - bob);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
  string str;
  while(cin >> str){
    vector <int> v;
    int i,j,k;
    for(i=0;i<str.size();i++){
      if(str[i]=='I') k=1;
      else if(str[i]=='V') k=5;
      else if(str[i]=='X') k=10;
      else if(str[i]=='L') k=50;
      else if(str[i]=='C') k=100;
      else if(str[i]=='D') k=500;
      else if(str[i]=='M') k=1000;
      v.push_back(k);
    }
    int o=0;
    for(i=0;i<v.size()-1;i++){
      if(v[i]<v[i+1]) o-=v[i];
      else o+=v[i];
    }
    o+=v[v.size()-1];
    cout << o << endl;
  }
}

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

int main(){
  int N, pi, count = 0;
  scanf("%d",&N);
  for(int i = 0 ; i < N ; i++){
    scanf("%d",&pi);
    if (pi != i+1)
      count++;
  }
  if(count <= 2)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}


Measured memory_bytes: 256
//Template Jollybee 2017-0720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;

const int INF=(int)2e9;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
const ll MOD=(ll)1e9+7;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front

int main(){
	int x, t;
	scanf("%d %d",&x,&t);
	if(t>x){
		printf("0\n");
	}
	else{
		printf("%d\n",x-t);
	}
	return 0;
}



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

const int _mx = 2e6;
int a[_mx+5];

struct data {
    string s;
    LLI n;
};

int main() {
    // freopen("in.txt", "r", stdin);

    queue <data> q;
    LLI t, x, y;
    string p;
    cin >> t >> x;
    for (int i = 0; i < t; i++) {
        cin >> p >> y;
        data z;
        z.s = p;
        z.n = y;
        q.push(z);
    }
    LLI k = 0;
    while (!q.empty()) {
        data w = q.front();
        q.pop();
        if (w.n > x) {
            k += x;
            w.n -= x;
            q.push(w);
        }
        else {
            k += w.n;
            cout << w.s << " " << k << endl;
        }
    }

    return 0;
}



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

using namespace std;
typedef long long ll;
int main() {
    ll a;
    cin >> a;
    for (ll i = 1; i < 100000; i++) {
        ll p = (i * (i + 1)) / 2;
        if(p >= a) {
            cout << i << endl;
            return 0;
        }
    }
    return  0;
}


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

int main()
{
  i64 n;
  cin >> n;
  vector<i64> p(n);
  for (i64 i = 0; i < n; i++)
    cin >> p[i];
  i64 ans = 0;
  for (i64 i = 0; i <= 100; i++)
  {
    i64 cnt = 0;
    for (i64 j = 0; j < n; j++)
      if (i <= p[j])
        cnt++;
    if (i <= cnt)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;

ll n;
const int N_MAX = 200005;
vector<ll> a(N_MAX), f(N_MAX);

bool check(ll x, ll k) {
  REP(i, n) {
    ll cost = a[i] * f[i];
    if (cost <= x) continue;

    k -= (cost - x + f[i] - 1) / f[i];
    if (k < 0) return false;
  }
  return true;
}

int main() {
  ll k;
  cin >> n >> k;
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> f[i];
  sort(a.begin(), a.begin() + n, greater<ll>());
  sort(f.begin(), f.begin() + n);

  if (check(0, k)) {
    cout << 0 << endl;
    return 0;
  }

  ll lb = 0, ub = 1e14;
  while (ub - lb > 1) {
    ll mid = (lb + ub) / 2;
    if (check(mid, k))
      ub = mid;
    else
      lb = mid;
  }
  cout << ub << endl;
  return 0;
}

Measured memory_bytes: 3328
x, n = gets.split.map(&:to_i)
ps = n.zero? ? [] : gets.split.map(&:to_i)

min = 1000
result = nil

((0..101).to_a - ps).each do |n|
  l = (n - x).abs
  if l < min
    min = l
    result = n
  end
end

puts result

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

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

int main(){
	int n;
	cin>>n;
	int a[n-1];
	int c[n+1];
	for(int i=0;i<n+1;i++)
		c[i]=0;
	for(int i=0;i<n-1;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	for(int i=1;i<n+1;i++){
		cout<<c[i]<<endl;
	}
}


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

bool f(){
	int n,m;
	cin>>n>>m;
	int a[n];
	int tot=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		tot+=a[i];
	}
	sort(a,a+n);
	reverse(a,a+n);
	for (int i = 0; i < n; ++i)
	{
		if(a[i]*4*m < tot){
			if(i>=m) return 1;
			return 0;
		}
	}
	return 1;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(f()){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#include <chrono>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cstring>
#include <cassert>
#include <math.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;


int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    // scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        long long n; scanf("%lld", &n);
        vector<pair<long long, int>> fac;
        for(int i = 2; 1ll * i * i <= n; i++) {
            if(n % i == 0) {
                fac.push_back({i, 0});
                while(n % i == 0) {
                    fac.back().second++;
                    n /= i;
                }
            }
        }
        if(n > 1) fac.push_back({n, 1});
        int ans = 0;
        for(int i = 0; i < fac.size(); i++) {
            int cnt = fac[i].second;
            for(int j = 1; j <= cnt; j++) {
                ans ++;
                cnt -= j;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3788
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a=m/n;
	int max=1;
	for(int i=a;i>0;i--)
	{
		if(m%i==0)
		{
			max=i;
			break;
		}
	}
	cout<<max<<endl;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define z 27
#define ull unsigned long long
using namespace std;
ull l[601][601],r[601][601];
ull p[666];
char c[666][666];
int n,ans;
ull getl(int i,int L,int R)
{
	return l[i][R]-l[i][L-1]*p[R-L+1];
}
ull getr(int i,int L,int R)
{
	return r[i][R]-r[i][L-1]*p[R-L+1];
}
int main()
{
	scanf("%d",&n);
	p[0]=1;
	for(int i=1;i<=n*2+1;i++) p[i]=p[i-1]*z;
	for(int i=1;i<=n;i++) scanf("%s",c[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			c[i+n][j]=c[i][j+n]=c[i+n][j+n]=c[i][j];
	for(int i=1;i<=n*2;i++)
		for(int j=1;j<=n*2;j++)
			l[i][j]=l[i][j-1]*z+c[i][j]-'a'+1;
	for(int j=1;j<=n*2;j++)
		for(int i=1;i<=n*2;i++)
			r[j][i]=r[j][i-1]*z+c[i][j]-'a'+1;
	/*for(int i=1;i<=n*2;i++)
	{	for(int j=1;j<=n*2;j++)
			cout<<l[i][j]<<" ";
		cout<<endl;
	}
	for(int i=1;i<=n*2;i++)
	{	for(int j=1;j<=n*2;j++)
			cout<<r[i][j]<<" ";
		cout<<endl;
	}*/
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			bool flag=false;
			for(int k=1;k<=n;k++)
			{
				ull x=getl(i+k-1,j+k-1,j+n-1);
				ull y=getr(j+k-1,i+k-1,i+n-1);
				if(x!=y)
				{
					flag=true;
					break;
				}
			}
			if(!flag) ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6272
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define sz(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int a,b; cin>>a>>b;
cout<<max({a-b,a+b,a*b})<<el;

return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//initialization
        String[] s;
        int unit = 0,
            sale = 0,
            sum  = 0,
            kind = 0,
            num  = 0,
            avg  = 0;

        //input
        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()){
        	s = sc.nextLine().split(",");
        	unit = Integer.parseInt(s[0]);
        	sale = Integer.parseInt(s[1]);

        	//calculation
        	kind++;
        	sum += unit * sale;
        	num += sale;
        }

        avg = Math.round((float) num / kind);

        //output
        System.out.println(sum);
        System.out.println(avg);
    }
}

Measured memory_bytes: 17140
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 2e5+10;
ll ba[MAXN][2],a[MAXN];
int n;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    ll ans;
    ba[n+1][0]=ba[n+1][1]=0;
    for(int i=n;i>=1;i--){
        ba[i][0]=ba[i+1][0]+a[i];
        ba[i][1]=ba[i+1][1]+a[i]-1;
    }
    ans=ba[1][0];
    ll c[2];
    c[0]=c[1]=0;
    //cout<<ans<<endl;
    for(int i=1;i<=n;i++){
        c[0]+=a[i];
        c[1]+=a[i]-1;
        ans=min(ans , abs(c[0]-ba[i+1][0]));
    }
    printf("%lld\n",ans);
    return 0;
}


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

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

	int cnt[101];
	int n,k,d,a;

	memset(cnt,0,sizeof(cnt));
	cin >> n >> k;

	for(int i=0;i<k;i++)
	{
		cin >> d;
		for(int j=0;j<d;j++)
		{
			cin >> a;
			cnt[a]++;
		}
	}

	int res = 0;

	for(int i=1;i<=n;i++)
	{
		if(cnt[i]==0)
		{
			res++;
		}
	}

	cout << res << '\n';
	
	return 0;
}


Measured memory_bytes: 3652
right = input()
q = int(input())
left = ""
flag = 1
for i in range(q) :
    t = input()
    if t == "1" :
        flag ^= 1
        continue
    t, f, c = t.split(" ")
    f = int(f)
    left += c*flag*(2-f)
    right += c*flag*(f-1)
    left += c*(1-flag)*(f-1)
    right += c*(1-flag)*(2-f)
if flag == 1 :
    print(left[::-1]+right)
else :
    print(right[::-1]+left)

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,h,x,y;
  cin>>w>>h>>x>>y;
  double ans=(double)h*(double)w/2;
  if(x*2==w&&y*2==h){
    printf("%.10f %d\n",ans,1);
  }
  else{
    printf("%.10f %d\n",ans,0);
  }
  return(0);
}


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

int main()
{
    int n, min{1000000}, max{};
    scanf("%d", &n);
    int *a = new int[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", a + i);
        min = std::min(a[i], min);
        max = std::max(a[i], max);
    }
    if (min == max)
    {
        if (min == n - 1)
            printf("Yes\n");
        else if (n >= min * 2)
            printf("Yes\n");
        else
            printf("No\n");
        return 0;
    }
    if (min < max - 1)
    {
        printf("No\n");
        return 0;
    }

    int count{};
    for (int i = 0; i < n; i++)
        if (min == a[i]) count++;
    
    if (max > count && n - count >= (max - count) * 2)
        printf("Yes\n");
    else
        printf("No\n");
    
    delete[] a;
    return 0;
}

Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int a, b, c;
	ll k;
	cin >> a >> b >> c >> k;
	ll ans;
	if (k % 2 == 0) ans = a - b;
	else ans = b - a;
	if (max(ans, -ans) > 1000000000000000000) cout << "Unfair" << endl;
	else cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
    long long x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    long long moves=(x+d-1)/d;
    if(moves>=k){
        cout<<abs(x-k*d)<<endl;
    }
    else{
        k-=moves;
        x-=moves*d;
        if(k&1){
            x+=d;
            cout<<abs(x)<<endl;
        }
        else{
            cout<<abs(x)<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3616
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <list>
#include <ctime>
#include <memory.h>
#include <bitset>
#include <climits>
#include <iostream>
#include <stdlib.h>

#define F first
#define S second
#define endl "\n"
#define pb push_back
#define mp make_pair
#define bs 1000000007
#define pi 3.141592653589793
#define y1 kjdfshnvoavaofobiopj
using namespace std;

int a, b, h, ans;

int main(){
//freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);

cin>>a>>b>>h;
if(a > b)
	swap(a, b);
ans = a*h+(0.5)*h*(b-a);
cout<<ans<<endl;

return 0;}


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

const int MAX_N = 202020;

int dp1[MAX_N], dp2[MAX_N];

int main() {
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        if (i > 0) dp1[i] = max(dp1[i], dp1[i - 1]);
        if (s[i] == 'x') continue;
        if (i - c - 1 >= 0) dp1[i] = max(dp1[i], dp1[i - c - 1] + 1);
        dp1[i] = max(dp1[i], 1);
    }
    for (int i = n - 1; i >= 0; i--) {
        if (i < n - 1) dp2[i] = max(dp2[i], dp2[i + 1]);
        if (s[i] == 'x') continue;
        if (i + c + 1 < n) dp2[i] = max(dp2[i], dp2[i + c + 1] + 1);
        dp2[i] = max(dp2[i], 1);
    }
    for (int i = 0; i < n; i++) {
        int le = 0, ri = 0;
        if (i == 0) {
            ri = dp2[i + 1];
        } else if (i == n - 1) {
            le = dp1[i - 1];
        } else {
            le = dp1[i - 1], ri = dp2[i + 1];
        }
        if (le + ri < k) {
            cout << i + 1 << endl;
        }
    }
}

Measured memory_bytes: 3332
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def gcd(a, b): #最大公約数
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

def lcm(a, b): #最小公約数
    return((a*b)//gcd(a,b))


def main():
    a,b=inpm()
    print(lcm(a,b))
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 39148
#include <vector>
#include <string>
#include <iostream>
#include <stdlib.h> // @atoi
#include <algorithm>
using namespace std;

int ConvStrToInt(std::string checkStr)
{
	return atoi(checkStr.c_str());
}
int ConvStrToInt(char c)
{
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
std::string ConvIntToStr(int checkNum)
{
	return std::to_string(checkNum);
}

int main(void)
{
	int value, total;

	cin >> value >> total;
	for (int i = 0; i <= value; ++i)
	{
		for (int j = 0; j <= value; ++j)
		{
			int k = value - i - j;
			if (k >= 0)
			{
				int price = 10000 * i + 5000 * j + 1000 * k;
				if (price == total)
				{
					cout << i << " " << j << " " << k;
					return 0;
				}
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair

using namespace std;
map<pair<ll,ll>,ll> ma;
void dfs(ll curr,vector<ll> v[], ll para)
{
    ll st = 1;
    //set<ll> st;
    //st.insert()
    for(auto it = v[curr].begin();it!=v[curr].end();it++)
    {
        if(*it == para) 
            continue;
        if(st == ma[mp(min(curr,para),max(curr,para))])
            st++;
        ma[mp(min(*it,curr),max(*it,curr))] = st;
        //cout<<"at "<<curr+1<<" with "<<*it+1<<" = "<<st<<"\n";
        st++;
        dfs(*it,v,curr);
    }
}

int main()
{
   FAST/**/
   ll n,k;
   cin>>n>>k;
   
   ll arr[n];
   for(ll i=0;i<n;i++)
        cin>>arr[i];
   ll pref[n+1];
   pref[0] = 0;
   for(ll i=1;i<=n;i++) 
        pref[i] = arr[i-1] + pref[i-1];
   ll hold[n];
   map<ll,ll> ma;
   ll cnt = 0;
   for(ll i=0;i<n;i++)
   {
       ll curr = pref[i+1];
       curr%=k;
       if(curr == i+1)
       {
           //cout<<"at "<<i+1<<"\n";
           cnt++;   
       }
       ll val = i - curr;
       hold[i] = val;
       if(i>=k)
            ma[hold[i-k]]--;
       //cout<<val<<" ";
       cnt+=ma[val];
       //cout<<ma[val]<<" "<<ma[val-k]<<"\n";
       cnt+=ma[val-k];
       ma[val]++;
   }
   //cout<<"\n";
   
   cout<<cnt;
   
   return 0;
}  
   


Measured memory_bytes: 29952
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define int LL
#define rep(n)for (LL i=1;i<=n;++i)
const int N =1e5+10;
LL n,ans,x[N],y[N],a;
map<LL,int > mp,bo;
signed main()
{
	scanf("%lld",&n);
	rep(n)
	{
		scanf("%lld",&a);x[i]=y[i]=1;
		for(int j=2;j*j*j<=a;++j)
		{
			int cnt=0;while (a%j==0) a/=j,++cnt;
			if (cnt%3==1) x[i]*=j,y[i]*=j*j;
			if (cnt%3==2) x[i]*=j*j,y[i]*=j;
		}
		x[i]*=a;
		y[i]*= (LL)sqrt(a)*(LL)sqrt(a)==a? sqrt(a) :a*a;
		++mp[x[i]];
	}
	rep(n) if (bo.count(x[i])==0)
	{
		bo[x[i]]=bo[y[i]]=1;
		if (x[i]==1) ++ans;
		else ans+=max(mp[x[i]],mp[y[i]]);
	}	
	return printf("%lld",ans),0;
}

Measured memory_bytes: 22400
#include <stdio.h>

int main(){
int N;
scanf("%d", &N);
N %= 10;
if(N == 3){
  printf("bon\n");
}else if((N == 0 || N == 1) || (N == 6 || N == 8)){
  printf("pon\n");
}else{
  printf("hon\n");
}
  return 0;
}
  

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

signed main(){
  lint ans = 0;
  lint K; cin >> K;
  for(lint i = 1; i <= K; i++){
    for(lint j = 1; j <= K; j++){
      for(lint k = 1; k <= K; k++){
        lint x = __gcd(i, j);
        x = __gcd(x, k);
        ans += x;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <math.h> 

using namespace std;



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

	int n, i, j, k, a, b;
	cin >> n;
	vector<string> s(n);
	string sa, sz, t;
	for (i = 0; i < n; i++) cin >> s[i];
	cin >> t;

	a = 0; b = 0;
	for (i = 0; i < n; i++) {
		sa = s[i]; 
		sz = s[i];

		for (j = 0; j < s[i].length(); j++) {
			if (s[i][j] == '?') {
				sa[j] = 'a';
				sz[j] = 'z';
			}
		}

		if (sz < t) a++;
		if (sa <= t) b++;
	}

	for (i = a; i < b; i++) cout << i + 1 << " ";
	cout << b + 1 << "\n";


	return 0;
}



Measured memory_bytes: 888