akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#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 mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
ll g,r;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>r>>g;
  cout<<r+(g-r)*2<<endl;
}

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


Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

vector<int> profit;


static large solve(const int* const a, const int n, const large r) {
    if (n <= 1) return r;

    auto firstbuyday = -1;
    for (auto i = 0; i + 1 < n; ++i) {
        if (a[i] < a[i + 1]) {
            firstbuyday = i;
            break;
        }
    }
    if (firstbuyday < 0) return r;

    auto firstsellday = firstbuyday + 1;
    for (auto i = firstbuyday + 1; i + 1 < n; ++i) {
        if (a[i] >= a[i + 1]) {
            firstsellday = i;
            break;
        }
    }
    auto stocks = r / a[firstbuyday];
    auto prof = stocks * (a[firstsellday] - a[firstbuyday]);
    auto x = solve(a + firstsellday + 1, n - firstsellday - 1, r + prof);
    return x;
}

int main()
{
    int n;
    cin >> n;
    auto a = vector<int>(n);
    for (auto& a_i : a)
        cin >> a_i;

    profit = vector<int>(n+5, -1);
    
    auto highest = 0LL;
    for (auto i = 0; i < n; ++i) {
        auto x = solve(a.data() + i, n - i, 1000);
        highest = max(x, highest);
    }

    cout << highest << endl;
    return 0;
}


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


int main(){
	ll n,k;
	cin >> n >> k;
	vector<ll> price;
	for(int i=0; i<n; i++){
		ll temp;
		cin >> temp;
		price.push_back(temp);
	}

	sort(price.begin(),price.end());

	ll ans=0;

	for(int l=0; l<k; l++){
		ans += price[l];
	}

	cout << ans;

	return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

signed main()
{   
    gearup;
    ll res = 0;
    int n; cin >> n;
    rep(i,n){
        int q; cin >> q;
        if(res+1 == q)res++;
    }
    if(res == 0)cout << -1 << endl;
    else cout << n-res << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] s_in;
		
		int N = Integer.parseInt(line);
		
		line = sc.nextLine();
		s_in = line.split(" ");
		int T = Integer.parseInt(s_in[0]);
		int A = Integer.parseInt(s_in[1]);
		
		int[] h = new int[N];
		line = sc.nextLine();
		s_in = line.split(" ");
		for(int i=0;i<N;i++) {
			h[i] = Integer.parseInt(s_in[i]);
		}
		
		double[] tempe = new double[N];
		for(int i=0;i<N;i++) {
			tempe[i] = (double)T - h[i]*0.006;
		}
		
		int nearest_h = -1;
		double nearest_dist = 100000;
		for(int i=0;i<N;i++) {
			if(Math.abs(nearest_dist - A) > Math.abs(tempe[i] - A)) {
				nearest_dist = tempe[i];
				nearest_h    = i;
			}
		}
		System.out.println(nearest_h+1);
	}
}


Measured memory_bytes: 22996
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	ar := make([]int, n+1)
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		ar[v]++
	}
	sort.Ints(ar)
	sum := 0
	for i := n; i >= 0; i-- {
		if ar[i] > 0 {
			k--
		}
		if k < 0 {
			sum += ar[i]
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 7172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

long int gcd(long int n, long int m){
  if(n == 0 || m == 0)
    return n + m;
  else if(n < m)
    return gcd(m,n);
  return gcd(m,n % m);
}

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n,m;
   cin>>n>>m;
    
   long int ans = n % m;
   ans = min(ans, m - ans);

   cout<<ans;  
   return 0;
}

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

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

ll dp[3002][3002];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  string s, t;
  cin >> s;
  cin >> t;
  // dump(s, t);
  int i, j;
  string ans = "";
  s += "#";
  t += "$";
  for (i = 0; i < s.size(); i++) {
    for (j = 0; j < t.size(); j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
      }
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
    }
  }
  // dumpv(dp, s.size() + 1, t.size() + 1);
  i = s.size() - 1;
  j = t.size() - 1;
  // while (i + j) {
  while (0 < i && 0 < j) {
    if (0 < i && dp[i][j] == dp[i - 1][j]) {
      i--;
    } else if (0 < j && dp[i][j] == dp[i][j - 1]) {
      j--;
    } else {
      i--;
      j--;
      ans += s[i];
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	string s;
	cin >> s;
	int n = s.size();
	ll cntA = 0;
	ll ans = 0;
	int i;
	for (i = 0; i < n - 2; i++) {
		char c = s[i];
		string t = s.substr(i+1, 2);
		if (c == 'A') {
			if (t == "BC") {
			ans += cntA + 1;
			s[i+2] = 'A';
			i++;
			} else if (t[0] == 'A') {
				cntA++;
			}
		} else cntA = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n,y;
  cin >> n >> y;
  
  for(int i = n;i >= 0;i--){
    for(int j = 0; i+j <= n;j++){
      if(y == 10000 * i + 5000 * j + 1000 * (n-i-j)){
        printf("%d %d %d",i,j,n-i-j);
        return 0;
      }
    }
  }
  
  puts("-1 -1 -1");
  
  return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    int r; cin>>r;
    precision(6);
    cout << (2*PI*r) << endl;
    return 0;
}


Measured memory_bytes: 3716
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int N, x;
vector<int> a;
ll times = 0;

void eat_candy(int i);

int main()
{
    cin >> N >> x;
    a.resize(N + 1);
    a[0] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        eat_candy(i);
    }

    cout << times << endl;

    return 0;
}

void eat_candy(int i)
{
    if (a[i - 1] + a[i] > x) {
        times += a[i - 1] + a[i] - x;
        a[i] = x - a[i - 1];
    }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  cin >> s;
  ul w = 0;
  ul ans = 0;
  for (ul i=0; i<s.size(); ++i) {
    if (s[i]=='W') w++;
  }
  for (ul i=0; i<s.size(); ++i) {
    if (s[i]=='B') ans += w;
    else w--;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int m, nmin, nmax;
  cin >> m >> nmin >> nmax;

  while(m && nmin && nmax){

    vector<int> p(m);
    for(int i = 0; i < m; i++) cin >> p[i];

    sort(p.begin(), p.end());

    int gap = 0, cnt = 0;
    for(int i = m - nmin; i >= m - nmax; i--){

      if(gap <= p[i] - p[i-1]){
        gap = p[i] - p[i-1];
        //cout << gap << endl;                                                  
        cnt = m - i;
      }

    }

    cout << cnt << endl;
    cin >> m >> nmin >> nmax;

  }

  return 0;

}



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;

	set<long long> nums;

	while (1) {
		n %= k;

		if (nums.count(n) > 0) {
			break;
		}
		nums.insert(n);

		n = abs(n - k);
	}

	cout << *nums.begin() << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
mod = 10 ** 9 + 7

dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for i in range(N + 1)]

def judge(i, j, k):
    if i == 0 and j == 2 and k == 1:
        return False
    elif i == 0 and j == 1 and k == 2:
        return False
    elif i == 2 and j == 0 and k == 1:
        return False
    else:
        return True

for i in range(4):
    for j in range(4):
        for k in range(4):
            dp[3][i][j][k] = judge(i, j, k)

def judge(j, k, l, m):
    if k == 0 and l == 2 and m == 1:
        return False
    elif k == 0 and l == 1 and m == 2:
        return False
    elif k == 2 and l == 0 and m == 1:
        return False
    elif j == 0 and l == 2 and m == 1:
        return False
    elif j == 0 and k == 2 and m == 1:
        return False
    else:
        return True

for i in range(4, N + 1):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for m in range(4):
                    dp[i][k][l][m] += dp[i - 1][j][k][l] * judge(j, k, l, m)
                    dp[i][k][l][m] %= mod
ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[N][i][j][k]
            ans %= mod
print(ans % mod)

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

    int main() {
      int N; cin >> N;  // 団体数
      int S;            // 合計人数

      rep(i,N){
        int L; cin >> L; // 席番－開始
        int R; cin >> R; // 席番－終了
        
        S += R - L + 1;  // 利用席数を加算
      }
      cout << S << endl;
    }

Measured memory_bytes: 256
using System;

public class Test{
    public static void Main(){
        string[] line1 = System.Console.ReadLine().Split(' ');
        string[] line2 = System.Console.ReadLine().Split(' ');
      	int day = int.Parse(line1[0]);
      	int workNum = int.Parse(line1[1]);
      	int workDay = 0;
      	for(int i = 0; i < workNum; i++){
          workDay += int.Parse(line2[i]);
        }
      	int free = day - workDay;
      	if(free >= 0){
	      System.Console.WriteLine(free);
        } else{
          System.Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 28280
#include <stdio.h>
int main(void)
{
  int x,y,z,ans=0;
  scanf("%d%d%d",&x,&y,&z);
  ans=x/(y+z);
  if(x%(y+z)<z)
  {
    ans--;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }
    else if(s=="Cloudy"){
        cout << "Rainy" << endl;
    }
    else{
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
S = input()
T = input()
sl = len(S)
tl = len(T)
ans = "z" * 100
for i in range(sl-tl+1):
    if S[i] == T[0] or S[i] == '?':
        bf = True
        for j in range(tl):
            if S[i+j] != T[j] and S[i+j] != '?':
                bf = False
                break
        if bf:
            new = S[:i] + T + S[i+tl:]
            new = new.replace("?", "a")
            ans = min(ans, new)
if ans == "z" * 100:
    print("UNRESTORABLE")
else:
    print(ans)

Measured memory_bytes: 9004
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    ll N,K;
    cin >> N >> K;
    ll a = N%K;
    cout << min(a, abs(K-a)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int rate(int n) {
    if (n < 3200) {
        return n / 400;
    }
    return -1;
}

int main() {
    int n, a;
    cin >> n;
    map<int,int> m;
    REP(i,n) {
        cin >> a;
        m[rate(a)]++;
    }
    
    int ans = 0;
    int any = m[-1];
    REP(i,8) {
        if (m[i]) ans++;
    }
    cout << max(1,ans) << " " << ans + any << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
 
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
 
    int D = scanner.nextInt();
    int N = scanner.nextInt();
 
    if ( N == 100) {
      N++;
    }
    if ( D == 0 ) {
        System.out.println(N);
    } else if ( D == 1) {
      System.out.println(100*N);
    } else {
      System.out.println(10000*N);
    }
  }
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int n;
	std::cin >> n;
	if (n < 1000) {
		std::cout << "ABC" << '\n';
	}
	else {
		std::cout << "ABD" << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    char s[100005];
    scanf("%s", s);
    int i;
    int l[100005], r[100005];
    for (i = 0; i < q; i++)
        scanf("%d %d", &l[i], &r[i]);
    int p[100005];
    p[0] = p[1] = 0;
    for (i = 1; i < n; i++)
        if (s[i] == 'C' && s[i - 1] == 'A')
            p[i + 1] = p[i] + 1;
        else
            p[i + 1] = p[i];
    for (i = 0; i < q; i++)
    {
        if (s[l[i] - 2] == 'A' && s[l[i] - 1] == 'C')
            printf("%d\n", p[r[i]] - p[l[i]]);
        else
            printf("%d\n", p[r[i]] - p[l[i] - 1]);
    }
    return 0;
}

Measured memory_bytes: 2048
n = int(input())
a = list(map(int, input().split()))
box = [0] * n
ans = []

for i in range(n-1, -1, -1):
    ms = sum(box[i::i+1])
    if ms % 2 != a[i]:
        box[i] = 1
        ans.append(i+1)

print(len(ans))
print(*ans)


Measured memory_bytes: 14008
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  string S;
  cin>>S;
  ll Rarr[N+1], Garr[N+1], Barr[N+1];
  for(int i=0;i<=N;++i) {
    Rarr[i] = 0;
    Garr[i] = 0;
    Barr[i] = 0;
  }
  for(int i=0;i<S.size();++i) {
    if(S[i]=='R') Rarr[i+1]++;
    if(S[i]=='G') Garr[i+1]++;
    if(S[i]=='B') Barr[i+1]++;
  }
  for(int i=1;i<=N;++i) {
    Rarr[i] += Rarr[i-1];
    Garr[i] += Garr[i-1];
    Barr[i] += Barr[i-1];
  }
  ll ans = 0;
  for(int i=0;i<N;++i) {
    for(int j=i+1;j<N;++j) {
      if(S[i]==S[j]) continue;
      if((S[i]=='R' && S[j]=='G') || (S[i]=='G' && S[j]=='R')) {
        ans += Barr[N]-Barr[j+1];
        if(2*j-i<N && S[2*j-i]=='B') ans--;
      }
      if((S[i]=='R' && S[j]=='B') || (S[i]=='B' && S[j]=='R')) {
        ans += Garr[N]-Garr[j+1];
        if(2*j-i<N && S[2*j-i]=='G') ans--;
      }
      if((S[i]=='B' && S[j]=='G') || (S[i]=='G' && S[j]=='B')) {
        ans += Rarr[N]-Rarr[j+1];
        if(2*j-i<N && S[2*j-i]=='R') ans--;
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


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

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){

    ll a, b, x;
    cin >> a >> b >> x;

    if(a % x == 0) cout << b/x - a/x + 1 << endl;
    else cout << b/x - a/x << endl;

}

Measured memory_bytes: 256
N = int(input())
if(N == 1):
  print("Yes")
  exit()

h = list(map(int, input().split()))

result = "Yes"
for i in range(N - 1, 0, -1):
  if(h[i - 1] <= h[i]):
    pass
  elif(h[i - 1] - 1 == h[i]):
    h[i - 1] -= 1
  else:
    result = "No"
    break
    
print(result)

Measured memory_bytes: 14224
#include <vector>
#include <functional>
#include <algorithm>
#include <iostream>
#include <climits>
using namespace std;

// 抽象 SegmentTree (0-indexed・一点更新・区間取得)
template <typename MonoidType>
struct SegmentTree {
    using Function = function< MonoidType(MonoidType, MonoidType) >;

    // node, identity element
    int n;
    vector<MonoidType> node;
    MonoidType E0;

    // update / combine function
    Function upd_f, cmb_f;

    void build(int m, vector<MonoidType> v = vector<MonoidType>()) {
        if(v != vector<MonoidType>()) m = v.size();
        n = 1; while(n < m) n *= 2;

        node = vector<MonoidType>(2*n-1, E0);
        if(v != vector<MonoidType>()) {
            for(int i=0; i<m; i++) {
                node[n-1+i] = v[i];
            }
            for(int i=n-2; i>=0; i--) {
                node[i] = cmb_f(node[2*i+1], node[2*i+2]);
            }
        }
    }

    // initialize
    SegmentTree() {}
    SegmentTree(int n_, MonoidType E0_,
                Function upd_f_, Function cmb_f_,
                vector<MonoidType> v = vector<MonoidType>()) :
        E0(E0_), upd_f(upd_f_), cmb_f(cmb_f_) {
        build(n_, v);
    }

    // update k-th element (applied value: x)
    void update(int k, MonoidType x) {
        k += n - 1;
        node[k] = upd_f(node[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            node[k] = cmb_f(node[2*k+1], node[2*k+2]);
        }
    }

    // range query for [a, b)
    MonoidType query(int a, int b) {
        MonoidType vl = E0, vr = E0;
        for(int l=a+n, r=b+n; l<r; l>>=1, r>>=1) {
            if(l & 1) vl = cmb_f(vl, node[(l++)-1]);
            if(r & 1) vr = cmb_f(node[(--r)-1], vr);
        }
        return cmb_f(vl, vr);
    }
};

// Range Minimum Query
// query 1: update
// query 2: range minimum
void DSL_2_A() {
    int N, Q; cin >> N >> Q;
    SegmentTree<int> seg(N, INT_MAX,
                         [](int a, int b) { return b; },
                         [](int a, int b) { return min(a, b); });

    int indexed = 0;
    for(int i=0; i<Q; i++) {
        int query_type; cin >> query_type;
        int x, y; cin >> x >> y;
        if(query_type == 0) {
            x -= indexed;
            seg.update(x, y);
        }
        if(query_type == 1) {
            x -= indexed, y -= indexed;
            y++;
            cout << seg.query(x, y) << endl;
        }
    }
}

void DSL_2_B() {
    int N, Q; cin >> N >> Q;
    SegmentTree<int> seg(N, 0,
                         [](int a, int b) { return a + b; },
                         [](int a, int b) { return a + b; });

    int indexed = 1;
    for(int i=0; i<Q; i++) {
        int query_type; cin >> query_type;
        int x, y; cin >> x >> y;
        if(query_type == 0) {
            x -= indexed;
            seg.update(x, y);
        }
        if(query_type == 1) {
            x -= indexed, y -= indexed;
            y++;
            cout << seg.query(x, y) << endl;
        }
    }
}

int main() {
    // DSL_2_A();
    DSL_2_B();
    return 0;
}



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

using namespace std;

#define f first
#define s second
#define pub push_back
#define pob pop_back

typedef vector<int> vi;
typedef vector<vi> graf;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> wgraf;

typedef vector<double> vd;
typedef pair<double,double> dd;
typedef vector<dd> vdd;

typedef uint64_t ui64;

int main(){

	int a, b;

	cin >> a >> b;

	int c = 1;
	int k = 0;

	while(c < b){

		c --;
		c += a;
		k++;

	}	

	cout << k << endl;


	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto S = to!string(tokens[0]);

	ulong best = 999;
	foreach (i; 0..S.length-2)
	{
		auto num = abs(to!long(S[i..i+3]) - 753);
		if (num < best)
			best = num;
	}

	writeln(best);
	stdout.flush();
/*}catch (Throwable e)
	{
		writeln(e.toString());
	}
readln();*/
}

Measured memory_bytes: 256
a,b = map(int,input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

t = factorization(gcd(a,b))
if t[0][0]==1:
    print(1)
    exit()
print(len(t)+1)
    
    

Measured memory_bytes: 9308
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();

		int[] scannerArray = new int[N];

		for (int index = 0; index < N; index++) {
			scannerArray[index] = scanner.nextInt();
		}

		Arrays.sort(scannerArray);

		double ans = scannerArray[0];

		for(int index =1; index < N; index++) {
			ans = (ans + scannerArray[index]) / 2;
		}
		log(ans);
	}

	private static void log(double str) {
		System.out.println(str);
	}

}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  ll a,b,c;
  ll k;
  std::cin >> a >> b >> c >> k;

  ll ab = a-b;
  std::cout << (k%2 == 0 ? ab : -ab) << '\n';
  return 0;
}


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

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var input2 = input.Distinct();

            Console.WriteLine(input2.Count());

        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define int long long 
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pre(i,a,b) for(int i=(b);i>=(a);i--)
#define ios ios::sync_with_stdio(false),cin.tie(0);
#define pb push_back
#define ps push
#define fi first
#define se second
#define ps push
#define Inf 0x3f3f3f3f3f3f3f3f
#define eps 1e-5
typedef long long ll;
const int N=2e5+5;
const int mod=998244353;
using namespace std;
int a[N];
int ans[N];
int vis[N];
int cnt=1;
int tmp;
int xx;
void dfs(int x){ 
     if(vis[a[x]]==0){
     ans[cnt]=a[x];
     cnt++;
     vis[a[x]]=cnt-1;
     dfs(a[x]);
    }
    else{
       tmp=cnt-vis[a[x]];
       xx=vis[a[x]];

     }

}
signed main(){
    ios;
    int n,k;
    cin>>n>>k;
    rep(i,1,n){
       cin>>a[i];
    }
    //vis[1]=1;
    
    dfs(1);
    // rep(i,1,5){
    //     cout<<ans[i]<<endl;
    // }
    if(k<=xx){

        cout<<ans[k]<<endl;
    }
    else{
        k-=(xx-1);
       // cout<<k<<endl;
        if(k%tmp!=0)
        cout<<ans[xx-1+(k)%tmp]<<endl;
        else{
            cout<<ans[xx-1+tmp]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8316
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	s = '$' + s + '$';
	int ret = 0;
	for (int i = 0; i < s.length() - 1; i++) {
		if (s[i] != s[i + 1]) {
			ret++;
		}
	}
	cout << ret - 1 << endl;
	return 0;
}


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

using namespace std;

const int INF = 1e9 + 7;

int n;
long long i;

int main(){
	scanf("%d", &n);
	
	for(i = 1; i <= 100000; i++){
		long long now = i * (i + 1) / 2;
		if(now >= n)
		return 0 * printf("%d\n", i);
	}
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 510;
vector<vector<int> > ans(N_MAX,vector<int>(N_MAX,-1));
void disassembly(int cur, int N,const vector<int> &w){
  if(N<=1) return;
  rep(i,N)rep(j,i) if((i-j)&1) ans[w[i]][w[j]] = ans[w[j]][w[i]] = cur;
  vector<int> w1;
  vector<int> w2;
  rep(i,N){
    if(i&1)w1.push_back(w[i]);
    else w2.push_back(w[i]);
  }
  disassembly(cur+1,w1.size(),w1);
  disassembly(cur+1,w2.size(),w2);
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> w(N);
  rep(i,N) w[i] = i;

  disassembly(1,N,w);
  rep(i,N){
    repp(j,i+1,N)cout << ans[i][j] SPF;
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 1536
#include <iostream>

using namespace std;

typedef long long ll;

ll n, x;
ll layer[55];

ll find(ll level, ll pos)
{
	if (level == 0) 
		return 1;
	if (pos == 1) 
		return 0;
	ll mid = layer[level] / 2;
	if (pos > 1 && pos < mid + 1) 
		return find(level - 1, pos - 1);
	if (pos == mid + 1) 
		return find(level - 1, layer[level - 1]) + 1;
	if (pos > mid + 1 && pos < layer[level]) 
		return find(level - 1, layer[level - 1]) + 
				find(level - 1, pos - 2 - layer[level - 1]) + 1;
	if (pos == layer[level]) 
		return find(level - 1, layer[level - 1]) * 2 + 1;
}

int main()
{
	cin >> n >> x;
	layer[0] = 1;
	for (int i = 1; i <= 50; i++)
	{
		layer[i] = layer[i - 1] * 2 + 3;
	}
	cout << find(n, x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <ratio>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

#define REP(i, n) for(int i = 0; i < n; ++i)

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

const ull MOD = 1000'000'007;

int main(){
    ll N = read<ll>();
    ll K = read<ll>();
    v<ll> A(N+ 1);
    REP(i, N) cin >> A[i + 1];

    v<ll> S(N + 1);
    partial_sum(A.begin(), A.end(), S.begin());
    REP(i, N + 1){ S[i] = ((S[i] - i) % K + K) % K; }

    ll ans = 0;
    map<ll, ll> cnt;
    cnt[0]++;
    for(ll l = 1-K, r = 1; r <= N; ++l, ++r){
        if(l >= 0) cnt[S[l]]--;
        //cout << S[r] << ", " << cnt[S[r]] << ", " << l <<  endl;
        ans += cnt[S[r]]++;
    }
    write(ans);
}



Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    int A,B,C,D,E,F;
    cin >> A >> B >> C >> D >> E >> F;
    vector<int>waters;
    rep(a,31) rep(b,31) {
        int sum = 100*A*a+100*B*b;
        if(sum<=F) waters.push_back(sum);
    }
    vector<int>sugars;
    rep(c,3001) rep(d,3001) {
        int sum = C*c+D*d;
        if(sum<=F) sugars.push_back(sum);
    }
    double noudo = -1;
    int ans1,ans2;
    for(auto water : waters) {
        for(auto sugar : sugars) {
            if(water + sugar > F) continue;
            int lim = (E*water)/100;
            
            if(sugar > lim) continue;
            if(water == 0) continue;
            double tmp = ((double)(sugar*100))/(double)(water+sugar);
            if(tmp > noudo) {
                noudo = tmp;
                ans1 = water + sugar;
                ans2 = sugar;
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;

}

Measured memory_bytes: 4192
#include <bits/stdc++.h>
#define rep(i,n) for(long long i = 0; i < (long long)(n); ++i)

using namespace std;
using ll = long long;

int main() {
	ll n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		ans += i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def get_min_total_dist(K, X):
    return sum([2 * min(x, abs(x - K)) for x in X])

def main():
    N = int(input())
    K = int(input())
    X = list(map(int, input().split()))
    print(get_min_total_dist(K, X))

if __name__ == "__main__":
    try:
        assert get_min_total_dist(10, [2]) == 4
        assert get_min_total_dist(9, [3, 6]) == 12
        assert get_min_total_dist(20, [11, 12, 9, 17, 12]) == 74
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()


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

long long int min(long long int a,long long int b){
	if(a>b)return b;
	else return a;
}
int main(){
	const long vol=200001;
	long l;
	long long int a[vol];
	long long dp[5][vol];
	cin>>l;
	dp[0][0]=dp[1][0]=dp[2][0]=dp[3][0]=dp[4][0]=0;
	for(long i=0;i<l;i++){
		cin>>a[i];
		dp[0][i+1]=dp[0][i]+a[i];
		dp[1][i+1]=min(dp[1][i],dp[0][i])+(a[i]==0?2:a[i]%2);
		dp[2][i+1]=min(min(dp[0][i],dp[1][i]),dp[2][i])+(a[i]+1)%2;
		dp[3][i+1]=min(min(min(dp[0][i],dp[1][i]),dp[2][i]),dp[3][i])+(a[i]==0?2:a[i]%2);
		dp[4][i+1]=min(min(min(min(dp[0][i],dp[1][i]),dp[2][i]),dp[3][i]),dp[4][i])+a[i];
	}
	cout<<min(min(min(min(dp[0][l],dp[1][l]),dp[2][l]),dp[3][l]),dp[4][l])<<endl;
	return 0;
}

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

int main() {
   
   int X, N;
   
   std::cin >> X >> N;
   
   int P[N];
   
   for (int i = 0; i < N; i++) {
      std::cin >> P[i];
   }
   
 
   std::vector<int> Ans_Array;
   
   for (int i = 0; i <= 101; i++) {
      int flag = 0;
      for (int j = 0; j < N; j++) {
         if (P[j] == i) {
            flag = 1;
         }
      }
      if (flag == 0) {
         Ans_Array.push_back(i);
      }
   }
   
   int ans,leng;
   
   leng = 10000;
   
   for (int i = 0; i < (int)Ans_Array.size(); i++) {
      if (std::abs(Ans_Array[i] - X) < leng) {
         ans = Ans_Array[i];
         leng = std::abs(Ans_Array[i] - X);
      }
   }
   
   std::cout << ans << std::endl;
   
   
   return 0;
   
}


Measured memory_bytes: 3152
x, k, d = [int(x) for x in input().split()]
ab = abs(x)
if ab-k*d>=0:
    print(ab-k*d)
else:
    t = ab//d
    k -= t
    ab -= d*t
    k %= 2
    if k==1:
        ab -= d
    print(abs(ab))

Measured memory_bytes: 9064
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main(){
char c;
cin >> c;
if(c == 'H'){
cin >> c;
cout << c << endl;
}
else{
cin >> c;
if(c == 'H'){
cout << 'D' << endl;
}
else{
cout << 'H' << endl;
}
}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			
			if(op.equals("?"))
				break;
			
			if(op.equals("+"))
				System.out.println(a+b);
			if(op.equals("-"))
				System.out.println(a-b);
			if(op.equals("*"))
				System.out.println(a*b);
			if(op.equals("/"))
				System.out.println(a/b);
				
			}
			
	}
}

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

using namespace std;

int main(void)
{
    int lake_length;
    int houses_count;
    vector<int> house_positions;

    cin >> lake_length >> houses_count;

    for(int i = 0; i < houses_count; i++){
        int h;
        cin >> h;
        house_positions.push_back(h);
    }

    int longest_way = 0;
    for(int i = 0; i < houses_count - 1; i++){
        int way = house_positions[i + 1] - house_positions[i];
        if(longest_way < way){
            longest_way = way;
        }
    }

    int last_way = lake_length - house_positions[houses_count - 1] + house_positions[0];

    if(longest_way < last_way){
        longest_way = last_way;
    }

    cout << lake_length - longest_way << endl;

    return 0;
}

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

def main():
    N,M = map(int, input().split())
    votes = [int(s) for s in input().split()]
    votes_sum = sum(votes)
    border_line = votes_sum / (4*M)

    result = 'Yes'
    votes.sort(reverse=True)
    for i in range(M):
        if votes[i] < border_line:
            result = 'No'
            break

    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
$N = $key->A[0];
$A = $key->X[0];
$ret = chkcolor($A);
printf("%d %d\n",$ret[0],$ret[1]);

function chkcolor($l) {
  $ary = array();
  $any=0;
  foreach($l as $score) {
    if ($score <= 399) {
      $ary[0]=1;
      continue;
    }
    if ($score <= 799) {
      $ary[1]=1;
      continue;
    }
    if ($score <= 1199) {
      $ary[2]=1;
      continue;
    }
    if ($score <= 1599) {
      $ary[3]=1;
      continue;
    }
    if ($score <= 1999) {
      $ary[4]=1;
      continue;
    }
    if ($score <= 2399) {
      $ary[5]=1;
      continue;
    }
    if ($score <= 2799) {
      $ary[6]=1;
      continue;
    }
    if ($score <= 3199) {
      $ary[7]=1;
      continue;
    }
    if ($score >= 3200) {
      $any+=1;
    }
  }
  $tot=0;
  $tot2=0;
  foreach($ary as $a) {
    $tot += 1;
  }
  if ($any>0 && $tot==0) {
    $ret[]=1;
    $ret[]=$any;
    return $ret;
  }
  $ret[]=$tot;
  $ret[]=$tot+$any;
  return $ret;
}


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

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

  vector<ll> a(N);
  for(ll i = 0; i < N; i++)
    cin >> a[i];

  ll sum = 0;
  for(ll i = 0; i < N; i++)
    sum += a[i];

  ll ans = abs(sum - 2 * a[0]);

  ll sub_sum = 0;
  for(ll i = 0; i < N; i++) {
    sub_sum += a[i];

    if(i == N - 1)
      continue;

    ans = min(ans, abs(sum - 2 * sub_sum));
  }

  cout << ans << endl;

}


Measured memory_bytes: 1792
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
#include <ctime>
#include <functional>
#include <cassert>
using namespace std;
const double pi=3.141592653589793238;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(),a.end(),greater<int>());
    int alice=0,bob=0;
    for(int i=0; i<n; i++){
        if(i%2==0) alice+=a[i];
        else bob+=a[i];
    }
    cout << alice-bob << endl;
}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
const int N=100009;
int ara[N];
int main()
{
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        ara[x]++;
    }
    int p=1;
    if(ara[0]!=1 && ara[0]!=0)
        p=0;

    for(int i=1;i<N;i++)
        if(ara[i]!=2 &&  ara[i]!=0)
            p=0;
    if(p==0)
        cout<<p<<endl;
    else
    {
        long long int ans=1,t=1000000007;
        for(int i=1;i<=(n/2);i++)
        {
            ans=(ans*2)%t;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    double n,k;
    cin>>n>>k;
    cout<<ceil((n-1)/(k-1));
  }  
  return 0;
}

Measured memory_bytes: 256