akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  n%=k;
  print(min(n,abs(n-k)));
  return 0;
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N)  cin >> A.at(i);

  ll ans=0;
  map<ll,int> mp;
  mp[0]=1;
  ll sum=0;
  rep(i,N){
    sum+=A.at(i);
    ans+=mp[sum];
    mp[sum]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 17144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59



int main(){
    ll i,j,k;
    ll n,d;
    cin>>n>>d;
    ll x[n][d];
    for(i=0;i<n;i++){
      for(j=0;j<d;j++)  cin>>x[i][j];
    }
    ll ans=0; 
    for(i=0;i<n;i++){
      for(j=i+1;j<n;j++){
        ll dis=0;
        for(k=0;k<d;k++){
          dis+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        }
        ll dd=0;
        while(dd*dd<dis) dd++;
        if(dd*dd==dis) ans++;
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
def gcd(S, T):
  if (S % T == 0):
    return T
  else:
    S = S % T
    return gcd(T, S)

def lcm(S, T):
  return S * T // gcd(S,T)

N = int(input())
S = int(input())

for i in range(N-1):
    T = int(input())
    S = lcm(max(S, T), min(S, T));

print(S)

Measured memory_bytes: 38384
# frozen_string_literal: true

n, m = gets.split(' ').map!(&:to_i)

arr = []
m.times do
  arr.concat(gets.split(' ').map!(&:to_i))
end

count = Hash.new(0)

arr.each do |e|
  count[e] += 1
end

n.times do |i|
  puts count[i + 1]
end


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

int n,c;
int x[100100],v[100100];

int solve(){
	int prefix[n],suffix[n];
	for(int i=0;i<n;i++){
		if(i==0) prefix[0]=(v[0]-x[0]);
		else prefix[i]=(prefix[i-1]+v[i]-(x[i]-x[i-1]));
	}
	int maxi[n+1];
	maxi[n]=0;

	suffix[n-1]=(v[n-1]-2*(c-x[n-1]));
	maxi[n-1]=max((int)0,suffix[n-1]);
	for(int i=n-2;i>=0;i--){
		suffix[i]=(suffix[i+1]+v[i])-2*((c-x[i])-(c-x[i+1]));
		maxi[i]=max(maxi[i+1],suffix[i]);
	}

	int ans = 0;
	for(int i=0;i<n;i++){
		int t = prefix[i]+maxi[i+1];
		ans = max(ans,t);
	}
	return ans;
}

signed main(){
	cin>>n>>c;
	for(int i=0;i<n;i++){
		cin>>x[i]>>v[i];
	}
	int t1 = solve();
	for(int i=0;i<n;i++){
		x[i]=c-x[i];
	}
	reverse(x,x+n);
	reverse(v,v+n);
	int t2 = solve();
	cout<<max(t1,t2)<<endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL<<60;

int main()
{
  int H,W; cin>>H>>W;
  string board[H];
  rep(i,H) cin>>board[i];

  string ans = "Yes";
  rep(i, H) {
    rep(j, W) {
      if (board[i][j] == '#') {
        bool can = false;
        // 上下チェック
        for (int dy = -1; dy < 2; dy++) {
          int ny = i + dy;
          if (ny >= 0 && ny < H) {
            if (i != ny && board[ny][j] == '#') can = true;
          }
        }
        // 左右チェック
        for (int dx = -1; dx < 2; dx++) {
          int nx = j + dx;
          if (nx >= 0 && nx < W) {
            if (j != nx && board[i][nx] == '#') can = true;
          }
        }
        if (can == false) {
          ans = "No";
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
<?php

$input = fgets(STDIN);

if (!preg_match('/([\d]+)\s([+\-])\s?([\d]+)?/u', $input, $match)) {
    echo '入力値エラー';
    return;
}

$a = (int) $match[1];
$b = (int) $match[3];

$op = $match[2];

if ($op === '+') {
    echo $a + $b;
} elseif ($op === '-') {
    echo $a - $b;
}

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

int main(){
    int n;
    cin >> n;
    map <string, int> mp;
    rep(i, n){
        string s;
        cin >> s;

        mp[s]++;
    }
    int max_num = 0;
    for(auto x : mp){
        max_num = max(max_num, x.second);
    }

    set<string> ans;
    for(const auto& x:mp){
        if (x.second == max_num){
            ans.insert(x.first);
        }
    }
    for (auto x : ans){
        cout << x <<endl;
    }
    return 0;
}

Measured memory_bytes: 34560
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;


int main(){
    int N, max = 0;
    map<string, int> poll;

    cin >> N;
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        if(poll.find(s) == poll.end()){
            poll[s] = 1;
        }
        else{
            poll[s]++;
        }
        if(poll[s] > max)max = poll[s];
    }
    for(map<string, int>::iterator it = poll.begin(); it != poll.end(); it++){
        pair<string, int> item = *it;
        if(item.second == max){
            cout << item.first << endl;
        } 
    }

    return 0;
}

Measured memory_bytes: 25624
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

bool ok[200];

void solve(){
    int n;
    cin >> n;
    int h[200];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    
    int cnt = 0;
    
    while(true){
        int l = -1, r = -1;
        for(int i = 0; i < n; i++){
            if(ok[i] == 0 && l == -1){
                l = i;
                r = i;
            }
            else if(ok[i] == 0 && l != -1){
                r = i;
            }
            else if(l != -1 && r != -1) break;
        }
        //cout << l << ' ' << r << endl;
        if(l == -1 && r == -1) break;
        int minpos = -1;
        int mn = 2e9;
        for(int i = l; i <= r; i++){
            if(mn > h[i]){
                minpos = i;
                mn = h[i];
            }
        }
        for(int i = l; i <= r; i++){
            h[i] -= mn;
            if(h[i] == 0) ok[i] = true;
        }
        cnt += mn;
    }
    cout << cnt;
}


int main(){
    int q = 1;
    //cin >> q;
    while(q--) solve();
}
// vse dolzhny vyiti v internet po hhtp


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    int a[n];
    rep(i,n)cin >> a[i];
    vector<int> cnt(100006);
    rep(i,n)cnt[a[i]]++;
    int q;cin >> q;
    int ret = 0;
    rep(i,100006){
        ret += i*cnt[i];
    }
    //trace(ret);
    while(q--){
        int b,c;cin >> b >> c;
        int past = cnt[b];
        ret -= b*cnt[b];
        //cout << ret << endl;
        cnt[b] = 0;
        cnt[c] += past;
        ret += past*c;
        cout << ret << endl;


    }

    return 0;
}

Measured memory_bytes: 4832
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

#define rep(X, Y) for( int (X) = 0; (X) < (Y); ++(X) )
#define rept(X, Y, Z) for( int (X) = (Y); (X) < (Z); ++(X) )
#define MOD 10000

int N, K, tmp[2];
int memo[101][4][4];
int def[101];

int func(int d, int op, int tp){
	if( memo[d][op][tp] != -1 ) return memo[d][op][tp];

	int sum = 0;

	if( d == N ) return 1;

	rept( i, 1, 4 ){
		if( def[d] != 0 && def[d] != i || op == tp && i == op ) continue;

		sum += func( d + 1, i, op ) % MOD;
	}

	return memo[d][op][tp] = sum % MOD;
}

int main(){
	memset( memo, -1, sizeof(memo) );

	scanf( "%d%d", &N, &K );

	rep( i, K ){
		scanf("%d%d", tmp, tmp + 1);

		def[tmp[0] - 1] = tmp[1];
	}

	std::cout << func(0, 0, 0) % MOD << std::endl;

	return 0;
}

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

int main() {
	int n;cin>>n;
	int t[n],v[n];
	int time=0;
	for(int i=0;i<n;i++){
		cin>>t[i];
		time+=t[i];
	}
	for(int i=0;i<n;i++)cin>>v[i];
	double speed[2*time+1];

	int k=1;
	for(int i=0;i<n;i++){
		if(i){
			if(v[i]<v[i-1])speed[k-1]=v[i];
		}
		for(int j=0;j<2*t[i];j++){
			speed[k]=v[i];
			k++;
		}
	}
	speed[0]=0;speed[2*time]=0;
	for(int i=1;i<2*time+1;i++){
		if(speed[i-1]+0.5<speed[i]){
			speed[i]=speed[i-1]+0.5;
		}
	}

	for(int i=2*time-1;i>0;i--){
		if(speed[i+1]+0.5<speed[i]){
			speed[i]=speed[i+1]+0.5;
		}
	}
	double ans=0;
	for(int i=1;i<2*time+1;i++){
		ans+=(speed[i-1]+speed[i])/4;
	}
	cout<<setprecision(15)<<ans<<endl;

		return 0;
}


Measured memory_bytes: 512
li = []
for i in range(5):
  li.append(int(input()))
k = int(input())
fl = True
for i in range(5):
  for j in range(i+1,5):
    if abs(li[i]-li[j]) > k:
      fl = False
if fl == True:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int,int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
#define st first
#define nd second
using namespace std;
const int mod=1e9+7;
const int MAX=105;
ll dp[MAX][2];
int main()
{
    BOOST;
    string maximum;
    cin>>maximum;
    int dzielnik;
    cin>>dzielnik;
    dp[0][0]=1;
    int len=maximum.size();
    for (int where=0;where<len;where++)
    {
        ll new_dp[MAX][2];
        for (int i=0;i<MAX-1;i++)
        {
            for (int j=0;j<2;j++)
            {
                new_dp[i][j]=0;
            }
        }

        for (int sum=0;sum<dzielnik;sum++)
        {
            for (int i=0;i<2;i++)
            {
                for (int digit=0;digit<10;digit++)
                {
                    if (digit>maximum[where]-'0' && !i)
                    {
                        break;
                    }

                    new_dp[(sum+digit)%dzielnik][i || (digit<maximum[where]-'0')]=
                    (new_dp[(sum+digit)%dzielnik][i || (digit<maximum[where]-'0')]+
                    dp[sum][i])%mod;
                }
            }
        }

        for (int i=0;i<MAX-1;i++)
        {
            for (int j=0;j<2;j++)
            {
                dp[i][j]=new_dp[i][j];
            }
        }
    }
    cout<<(dp[0][0]+dp[0][1]-1+mod)%mod;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int N,r=0,g=0,b=0,i,j;
  long res=0;
  char S[5000];
  scanf("%d%s",&N,S);
  for(i=0;i<N;i++){
    if(S[i]=='R') r++;
    if(S[i]=='G') g++;
    if(S[i]=='B') b++;
  }
  res=r*g;
  res*=b;
  for(i=0;i<N-2;i++){
    for(j=i+1;j<N-1;j++){
      int k=2*j-i;
      if(S[i]!=S[j]&&S[i]!=S[k]&&S[j]!=S[k]&&k<N){
        res--;
      }
    }
  }
  printf("%ld",res);
  return 0;
}

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


int main() {
  int k;
  cin >> k;
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  cout << v.at(k-1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define iso ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define clr(x,n) memset((x), n, sizeof(x))
#define mod 1000000007
#define MAX 1000005
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_tree;*/
ll arr[205];
int main()
{
    iso;
    int n, i, j, k, a, b, c;
    cin>>n;
    int ans = 0;
    for(i = 0; i < n; i++)
        cin>>arr[i];
    for(i = 0; i < n; i++)
    {
        for(j = i+1; j < n; j++)
        {
            for(k = j+1; k < n; k++)
            {
                a = arr[i];
                b = arr[j];
                c = arr[k];
                if((a < b+c) && (b < a+c) && (c < a+b) && (a!=b) && (a!=c) && (b!=c))
                    ans++;
            }
        }
    }
    cout<<ans;




    return 0;
}



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

int main() {
  ll h;
  cin >> h;
  ll count = 1;
  ll bin = 1;
  
  rep(i, 1000000000000000000){
    h /= 2;
    bin *= 2;
    if(h == 0)
      break;
    else
      count += bin;
  }
  cout << count << endl;
}

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

int main()
{
     long long n,m,a[200005],b[200005],i,j,k,dp[2002][2002]={0},mod=1e9+7;
     cin>>n>>m;
     for(i=1;i<=n;i++)   cin>>a[i];
     for(i=1;i<=m;i++)   cin>>b[i];
     
     for(i=1;i<=n;i++){
         for(j=1;j<=m;j++){
            
                dp[i][j]=(mod+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod;
            if(a[i]==b[j])
                dp[i][j]+=(1+dp[i-1][j-1])%mod;
            //cout<<dp[i][j]<<' ';
        }
    }
    cout<<(dp[n][m]+1)%mod;
}   


Measured memory_bytes: 34688
def main():
  n, w = [int(e) for e in input().split()]
  maxv = 10 ** 3 * n + 1
  t = [-1 for i in range(maxv)]
  t[0] = w
  for _ in range(n):
    nw, nv = [int(e) for e in input().split()]
    for i in range(maxv - 1, -1, -1):
      if t[i] == -1:
        continue
      if t[i + nv] < t[i] - nw:
        t[i + nv] = t[i] - nw
  for i in range(maxv - 1, 0, -1):
    if t[i] == -1:
      continue
    print(i)
    break
main()

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

int main() {
    constexpr int inf = 100000000;
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        std::cin >> a >> b;
        g[a - 1].push_back(b - 1);
    }

    int min = inf;
    std::vector<int> path;
    for (int s = 0; s < n; s++) {
        std::vector<int> dist(n, inf), prev(n, -1);
        std::priority_queue<P, std::vector<P>, std::greater<>> q;
        q.emplace(0, s);
        while (!q.empty()) {
            auto p = q.top();
            q.pop();
            if (dist[p.second] < p.first) continue;
            for (auto to : g[p.second]) {
                auto nc = p.first + 1;
                if (dist[to] <= nc) continue;
                dist[to] = nc;
                prev[to] = p.second;
                q.emplace(nc, to);
            }
        }

        if (dist[s] < min) {
            min = dist[s];
            path.clear();
            path.push_back(s);
            while (true) {
                int v = prev[path.back()];
                if (v == s) break;
                path.push_back(v);
            }
        }
    }

    if (min == inf) {
        std::cout << -1 << std::endl;
    } else {
        std::cout << min << std::endl;
        for (auto v : path) std::cout << v + 1 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        while(true){
            int n=scan.nextInt();
            if(n==0) break;
            int[] score=new int[n];
            int maxflag=0;
            int minflag=0;
            int max=0,min=0;
            for(int i=0;i<n;i++){
                score[i]=scan.nextInt();
                if(i==0){
                    max=score[0];
                    min=score[0];
                }
                else{
                    if(max < score[i]) max=score[i];
                    if(min>score[i]) min=score[i];
                }
            }
            int ave=0;
            for(int i=0;i<n;i++){
                if(score[i]==max&&maxflag==0) maxflag++;
                else if(score[i]==min&&minflag==0) minflag++;
                else{
                    ave+=score[i];
                }
            }
            ave/=(n-2);
            System.out.println(ave);

        }
    }
}


Measured memory_bytes: 28976
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
ll dp[110000][3];
ll h[110000][3];
//-----------------------------------------
int main(void){
    ll N;cin>>N;
    REP(i,N){
        cin>>h[i][0]>>h[i][1]>>h[i][2];
    }
    REP(i,N){
        REP(j,3){
            dp[i+1][j]=max(dp[i+1][j],dp[i][(j+1)%3]+h[i][j]);
            dp[i+1][j]=max(dp[i+1][j],dp[i][(j+2)%3]+h[i][j]);
        }
    }
    ll ans=0;
    REP(i,3){
        ans=max(ans,dp[N][i]);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 8284
#include <stdio.h>

int main(void)
{
	int n, h[100001], t[100001] = {0}, max;

	scanf("%d", &n);
	int i, j, count;
	for (i = 0; i < n; i++)
		scanf("%d", &h[i]);

	max = 0;
	for (i = n - 1; i > 0; i--)
	{
		if (h[i] <= h[i - 1])
		{
			t[i - 1] = t[i] + 1;
			if (max < t[i - 1])
				max = t[i - 1];
		}
	}
	printf("%d\n", max);
	return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

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

   if ((a + b + 1) < c)
   {
      cout << b + (c - (c - a - b - 1)) << '\n';
   }
   else
   {
      cout << b + c << '\n';
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n;
    cin>>n;
    ll a=2,b=1,c;
    n--;
    while (n)
    {
        c=a+b;
        a=b;
        b=c;
        n--;
    }
    cout<<b<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<string>
#include<cstring>
#include<ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
			tree_order_statistics_node_update>
	new_data_set;
//   <<implemented_sorted_vector>>  new_data_set p;
//   <<insert_like_set>>           insert(key):log(n)
//<<accessing_iterator_by_index>> find_by_order(idx):log(n)
//	    <<accessing_by_value>>   order_of_key(key):log(n)
// << replace less<int> by greater<int> for descending order>>
// find(key), erase(find(key)) works the same!
typedef long long ll;
typedef long l;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ERR(x) cout<<"#x:"<<x<<endl
#define ERR2(x,y) cout<<"#x:"<<x<<" "<<"#y:"<<y<<endl;
#define ERR3(x,y,z) cout<<"#x:"<<x<<" "<<"#y:"<<y<<" "<<"#z:"<<z<<endl;
#define show(v) for(auto e: v) cout<<e<<" ";
#define showArr(A,n) for(int i=0;i<n;i++) cout<<A[i]<<" ";
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define umpit unordered_map<ll,ll>::iterator
#define mpit map<ll,ll>::iterator
#define setit set<ll>::iterator
#define all(v) v.begin(),v.end()

const int N = (int)1e5 + 5;
vector<ll>s;
vector<ll>cache(N,MOD);

ll res(ll top)
{
	if(top == 0)
	{
		return 0;
	}
	else if(top == 1)
	{
		if(cache[top] != MOD)
		{
			return cache[top];
		}
		ll ans = (abs(s[top] - s[top-1]));
		//ERR2(top, ans);
		return cache[top] = ans;
	}
	else
	{
		if(cache[top] != MOD)
		{
			return cache[top];
		}
		ll ans = min((abs(s[top]-s[top-1]) + res(top-1)), 
						(abs(s[top] - s[top-2]) + res(top - 2))
						);
		//ERR2(top, ans);
		return cache[top] = ans;
	}
}

int main()
{
	ll n;
	cin>>n;
	s.resize(n);
	FOR(i,0,n) cin>>s[i];
	cout<<res(n-1);	
	return 0;
}


Measured memory_bytes: 7140
#include <stdio.h>
#include <math.h>

void kock(int,double,double,double,double);

int main()
{
  int n;
  double p1_x,p1_y,p2_x,p2_y;

  scanf("%d",&n);

  p1_x = 0.0;
  p1_y = 0.0;
  p2_x = 100.0;
  p2_y = 0.0;
  
  printf("%f %f\n",p1_x,p1_y);
  kock(n,p1_x,p1_y,p2_x,p2_y);
  printf("%f %f\n",p2_x,p2_y);

  return 0;
}

void kock(int n,double p1_x,double p1_y,double p2_x,double p2_y)
{
  double s_x,s_y,u_x,u_y,t_x,t_y;

  if(n == 0) return;

  s_x = (2*p1_x + p2_x)/3;
  s_y = (2*p1_y + p2_y)/3;
  t_x = (p1_x + 2*p2_x)/3;
  t_y = (p1_y + 2*p2_y)/3;
  u_x = (t_x - s_x)*cos(M_PI/3)-(t_y-s_y)*sin(M_PI/3)+s_x;
  u_y = (t_x - s_x)*sin(M_PI/3)+(t_y-s_y)*cos(M_PI/3)+s_y;

 
  kock(n-1,p1_x,p1_y,s_x,s_y);
  printf("%f %f\n",s_x,s_y);
  
  kock(n-1,s_x,s_y,u_x,u_y);
  printf("%f %f\n",u_x,u_y);
  
  kock(n-1,u_x,u_y,t_x,t_y);
  printf("%f %f\n",t_x,t_y);
 
  kock(n-1,t_x,t_y,p2_x,p2_y);
  
 
}

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


int main(){
	int N;cin >> N;
	LL K; cin >> K;
	int Q;cin >> Q;
	vector<LL> p(N, K - Q);

	rep(i,Q){
		int tmp;
		cin >> tmp;
		++p[tmp-1];
	}
	rep(i,N){
		if(p[i]>0){
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
}














Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>k;

    ll L = 0;
    ll R = 0;

    for(int i=0;i<k;i++){
        L+=(ll)i;
        R+=(ll)(n-i);
    }

    ll res = 0;

    for(int i=k;i<=n+1;i++){

        res+=(R-L+1);
        res%=MOD;

        L+=(ll)i;
        R+=(ll)(n-i);
    }

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(void) {
  string s, t; cin>>s;
  t = s;
  int n = s.size();
  reverse(t.begin(), t.end());
  if(s==t && s.substr(0, (n-1)/2) == s.substr((n+1)/2, (n-1)/2)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readString() -> String {
    return readLine()!
}

func readLines(times: Int) -> [String] {
    var array = [String]()
    for _ in 0..<times {
        array.append(readLine()!)
    }
    return array
}

func readSeparatedStrings() -> [String] {
    return readLine()!.split(separator: " ").map {String($0)}
}

func readStringToStrings() -> [String] {
    return readLine()!.map{String($0)}
}

func readSeparatedInts() -> [Int] {
    return readLine()!.split(separator: " ").map {Int($0)!}
}
func readSeparatedDouble() -> [Double] {
    return readLine()!.split(separator: " ").map {Double($0)!}
}

// 二進数に変換
func convertIntToRadix2(n: Int, radix: Int = 2) -> String {
    return String(n, radix: radix)
}

//配列を逆順にする reverced ソートする　sorted
//最初数文字取得 prefix

let x = readInt()

if x == 0 {
    print(1)
} else {
    print(0)
}


Measured memory_bytes: 13060
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

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

///////////////////////////////////////////////////////////

int digit, M;
void solve() {
  cin >> digit >> M;
  vector<int> number(100, -1);
  for(int i = 0; i < M; i++){
    int a;
    int b;
    cin >> a >> b;
    a--;
    if(number.at(a) == -1 || number.at(a) == b){
      number.at(a) = b;
    } else{
      cout << -1 <<endl;
      return;
    }
  }
  if(digit == 1){
    if(number.at(0) == -1){
      cout << 0 <<endl;
      return;
    } else{
      cout << number.at(0) <<endl;
      return;
    }
  }
  if(number.at(0) == 0){
    cout << -1 <<endl;
    return;
  } else if(number.at(0) == -1){
    number.at(0) = 1;
  }
  for(int i = 1; i < digit; i++){
    if(number.at(i) == -1){
    number.at(i) = 0;
    }
  }
  for(int i = 0; i < digit; i++){
    cout << number.at(i);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    vector<array<int, 10>> a(n + 1);
    for (int i = 0; i < n; i++) {
        s[i] -= '0';
        for (int h = 0; h < 10; h++) {
            a[i + 1][h] = a[i][h] + (s[i] == h);
        }
    }

    int p[1000] = {};
    int r = 0;
    for (int i = 0; i < n; i++) {
        int k0 = s[i] * 100;
        for (int h1 = 0; h1 < 10; h1++) {
            if (a[n][h1] - a[i + 1][h1] == 0) continue;
            int k1 = k0 + h1 * 10;
            for (int h2 = 0; h2 < 10; h2++) {
                if (a[i][h2] == 0) continue;
                int k2 = k1 + h2;
                if (p[k2] == 0) {
                    p[k2] = 1;
                    r++;
                }
            }
        }
    }

    cout << r << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

template< class T >
struct CumulativeSum {
    vector< T > data;

    CumulativeSum(int sz) : data(sz, 0) {};

    void add(int k, T x) {
        data[k] += x;
    }

    void build() {
        for(int i = 1; i < data.size(); i++) {
            data[i] += data[i - 1];
        }
    }

    T query(int k){
        if(k < 0) return (0);
        return (data[min(k, (int) data.size() - 1)]);
    }

    T query(int l,int r){// 区間[l,r]
        return query(r) - query(l - 1);
    }
};

ll n;


int main(){
    cin >> n;
    CumulativeSum<ll> sum(n);
    rep(i,n){
        ll a;
        cin >> a;
        sum.add(i,a);
    }
    sum.build();
    ll ans = INF;
    ll s = 0;
    ll h = 0;
    rep(i,n){
        ll q = sum.query(i);
        if(i % 2){
            if(q + h <= 0){
                s += abs(q + h - 1);
                h += abs(q + h - 1);
            }
        }
        else{
            if(q + h >= 0){
                s += abs(q + h + 1);
                h -= abs(q + h + 1);
            }
        }
    }
    ans = min(ans,s);
    // cout << ans << endl;
    s = 0;
    h = 0;
    rep(i,n){
        ll q = sum.query(i);
        if(i % 2){
            if(q + h >= 0){
                s += abs(q + h + 1);
                h -= abs(q + h + 1);
            }
        }
        else{
            if(q + h <= 0){
                s += abs(q + h - 1);
                h += abs(q + h - 1);
            }
        }
    }
    ans = min(ans,s);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,t,a[100005];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	cout<<n/500*1000+n%500/5*5;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;

int a,b,c,d,e,k;

void solve(){
	cin >> a >> b >> c >> d >> e >> k;
	if(e-a>k)cout << ":(";
	else if(d-a>k)cout << ":(";
	else if(c-a>k)cout << ":(";
	else if(b-a>k)cout << ":(";
	else cout << "Yay!";
	cout << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    x = int(stdin.readline().rstrip())
    sho, amari = divmod(x,11)
    if amari == 0:
        print(sho * 2)
    elif amari <= 6:
        print(sho*2 + 1)
    else:
        print(sho*2 +2)



if __name__ == '__main__':
    solve()


Measured memory_bytes: 9156
N, L = map(int, input().split())
original_taste = int(N*(L-1) + N*(N+1)*0.5)
difference = float("inf")

for i in range(N):
    if abs(L+i) < difference:
        difference = abs(L+i)
        apple_chosen = i

print(original_taste - (L+apple_chosen))

Measured memory_bytes: 3060
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(Int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(Int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);

void solve(std::vector<long long> x){
  rep(i,5) if(!x[i]) cout << i+1 << endl;
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  std::vector<long long> x(5);
  for(int i = 0 ; i < 5 ; i++){
    scanf("%lld",&x[i]);
  }
  solve(std::move(x));
  return 0;
}


Measured memory_bytes: 3692
#include <iostream>
#include <stdio.h>
#include <string>
#include <tuple>

#define MAX_N 100

using namespace std;

tuple<int, string, int> P[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string s;
    int p;
    cin >> s >> p;
    P[i] = {i + 1, s, p};
  }

  auto comp = [](const tuple<int, string, int> &p1, const tuple<int, string, int> &p2) {
    if (get<1>(p1) == get<1>(p2)) {
      return get<2>(p1) > get<2>(p2);
    } else {
      return get<1>(p1) < get<1>(p2);
    }
  };

  sort(P, P + N, comp);
  for (int i = 0; i < N; ++i) {
    printf("%d\n", get<0>(P[i]));
  }
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int a, b, c;
    vector<int> data(3);
    REP(i, 3) cin >> data[i];
    sort(data.begin(), data.end());

    int total = data[2] - data[0];
    print(total);

}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

// ll modexp(ll x, ll y, ll p)
// {
// ll res = 1;
// x = x % p;
// while (y > 0)
// {
// if (y & 1)
// res = (res * x) % p;
// y = y >> 1;
// x = (x * x) % p;
// }
// return res;
// }

// ll mulmod(ll a, ll b)
// {
// return ((a % mod) * (b % mod)) % mod;
// }

// ll sub_mod(ll a, ll b, ll m){
//    if (a >= b)
//        return a - b;
//    else
//        return m - b + a;
// }

// ll add_mod(ll a, ll b){
//    if (0 == b)
//        return a;

//    b = mod - b;
//    if (a >= b)
//        return a - b;
//    else
//        return mod - b + a;
// }

// ll gcd(ll a, ll b)
// {
// if (a == 0)
// return b;
// else
// return gcd(b % a, a);
// }

// ll modInv(ll a)
// {
//     ll g = gcd(a, mod);
//     if (g != 1)
//         return -1;
//     else
//         return modexp(a, mod-2, mod);
// }


int main()
{
fastio;
//#ifndef ONLINE_JUDGE  
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
//#endif
ll n = 0, k = 0;
cin >> n >> k;
ll i = 0;
ll c = 0;
while (i <= (n-k-1))
{
i += (k-1);
++c;
}
if (i != n)
++c;
cout << c;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;
int cnt_2(int n){
	int cnt =0;
	while(n%2==0){
		n/=2;
		cnt++;
	}
	return cnt;
}
int main(){
	int n; cin>>n;
	int a[n+1];
	for(int i=0;i<n;i++) {
		cin>>a[i];
		a[i] = cnt_2(a[i]);
	}
	int cnt = a[0];
	for(int i=1;i<n;i++) cnt = min(cnt,a[i]);
	printf("%d\n",cnt);
	return 0;
}

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

int main(){
  int n;
  int a[100], b[100];
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b+n);
  int diff = 0;
  for(int i = 0 ; i < n ; i++){
    if(a[i] != b[i]) diff++;
  }
  if(diff <= 2) cout << "YES\n";
  else cout << "NO\n";
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func nextInt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func main() {
	n := nextInt()
	k := nextInt()

	var one int
	for i := range make([]struct{}, n) {
		if nextInt() == 1 {
			one = i
		}
	}
	pos := one
	cnt := 0
	bonus := 0

	for pos > 0 {
		pos -= k - 1
		cnt++
		if pos < 0 {
			bonus += -pos
		}
	}
	pos = one
	for pos < n-1 {
		pos += k - 1
		cnt++
		if pos >= n {
			bonus += pos - (n - 1)
		}
	}
	fmt.Println(cnt - bonus/(k-1))
}


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

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

    int ans = 0;
    for (int i = 1; i * i < N; ++i) {
        ans += ((N - 1) / i - i) * 2 + 1;
    }

    cout << ans << endl;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n, m;
  cin >> n >> m;
  ll a[n], b[n];
  REP(i, n) cin >> a[i] >> b[i];
  // list[i]
  // := i日目までに始めるとM日目までに報酬が得られるバイトの集合
  vector<ll> list[m];
  REP(i, n) {
    int d = m - a[i];  // 何日目までにバイトを始めればよいか
    if (d < 0) continue;
    list[d].push_back(b[i]);
  }
  ll ans = 0;
  priority_queue<ll> que;
  RREP(i, m) {  // i = m - 1, ..., 0
    REP(j, list[i].size()) que.push(list[i][j]);
    if (que.empty()) continue;
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

using ll = long long;

ll n, m, k;
vector <vector <ll>> vec;
vector <vector <ll>> dp;
vector <ll> height;

const ll INF = 1e9;

int main() {
	cin >> n;
	string s;
	cin >> s;
	if (n >= 3200) cout << s;
	else cout << "red";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int count = 0;
  	string s, t;
  	cin >> s;
  	cin >> t;
  	
  	for(int i=0; i<3; i++){
  		if(s[i] == t[i]){
        	count++;
        }
    }    
  	cout << count << endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Between Two Integers
            var line = ReadLine();
            int a = line[0];
            int b = line[1];
            int c = line[2];

            if (c >= a && c <= b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int calc(int N)
{
    int res=0;
    for(int i=2;i*i<=N;i++){
        if(N%i==0){
            res++;
            while(N%i==0) N/=i;
        }
    }
    if(N>1) res++;
    return res;
}

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

    int a,b; cin>>a>>b;
    int N=__gcd(a,b);
    cout<<calc(N)+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;
int v = 10005,e = 100005;

struct edge{

    int from,to,cost;
    
    edge(int cost,int from,int to):cost(cost),from(from),to(to){}

    bool operator< (const edge &right){ return cost < right.cost;}
    bool operator> (const edge &right){ return cost > right.cost;}
    bool operator<= (const edge &right){ return cost <= right.cost;}
    bool operator>= (const edge &right){ return cost >= right.cost;}
};

vector<edge> EG;

struct Unionfind{
    vector<int> parents;
    int m;
    Unionfind(int n):parents(n,-1){
        m = n;
    }

    int find(int x){
        if(parents.at(x) < 0){
            return x;
        }else{
            parents.at(x) = find(parents.at(x));
            return parents.at(x);
        }
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x==y) return;
        if(parents.at(x) > parents.at(x))swap(x,y);
        parents.at(x) += parents.at(y);
        parents.at(y) = x;
    }  

   int size(int x){
       return -parents.at(find(x));
   }

   bool same(int x,int y){
       return find(x) ==find(y);
   }

   vector<int> members(int x){
       int root = find(x);
       vector<int> A;
       for(int i=0;i<m;i++){
           if(find(i) ==root ){
               A.push_back(i);
           }
       }
      return A;
  }
};

int kruskal(){
    int res = 0;
    Unionfind uf(v);
    sort(EG.begin(),EG.end());
    for(edge ed:EG){
        if(uf.same(ed.from,ed.to)) continue;
        uf.unite(ed.from,ed.to);
        res += ed.cost;
    }
    return res;
}


int main(){
    cin >> v >> e;
    rep(i,e){
        int s,t,w;
        cin >> s >> t >> w;
        edge ed(w,s,t);
        EG.push_back(ed);
    }

    int cost = kruskal();
    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 4536
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
using Int = long long;
int main() {
    int N; cin >> N;
    vector<int> A(N); for (auto &a : A) cin >> a;
    sort(rbegin(A), rend(A));
    Int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        ans += A[(i + 1) / 2];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3992