akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    VI sum(n + 1, 0);
    
    for (int i = 0; i < n; i++) {
        long a;
        cin >> a;
        sum[i + 1] = sum[i] + a;
    }
    
    long ans = 1e18;
    VI ps(2), qs(2), rs(2), ss(2);
    for (int i = 2; i < n - 1; i++) {
        long pqsum = sum[i];
        long rssum = sum[n] - pqsum;
        
        int midind = lower_bound(sum.begin(), sum.end(), pqsum / 2) - sum.begin() - 1;
        long p, q, r, s;
        p = sum[midind];
        q = pqsum - p;
        ps[0] = p;
        qs[0] = q;
        p = sum[midind + 1];
        q = pqsum - p;
        ps[1] = p;
        qs[1] = q;
        
        midind = lower_bound(sum.begin(), sum.end(), pqsum + rssum / 2) - sum.begin() - 1;
        r = sum[midind] - pqsum;
        s = rssum - r;
        rs[0] = r;
        ss[0] = s;
        r = sum[midind + 1] - pqsum;
        s = rssum - r;
        rs[1] = r;
        ss[1] = s;
        
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                if (ps[i] * qs[i] * rs[j] * ss[j] != 0) {
                    ans = min(ans, max({ps[i], qs[i], rs[j], ss[j]}) - min({ps[i], qs[i], rs[j], ss[j]}));
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
N = int(input())

A0 = map(int, input().split())
B = []
A = []
count=0
for i in A0:
    A.append(i)
for i in A:
    while(i%2==0 and i>0):
        count+=1
        i = i/2
    B.append(count)
    count=0
print(min(B))

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
	int N;
	scanf("%d", &N);
	int firstDigit = N / 100, secondDigit = (N / 10) % 10, thirdDigit = N % 10;
	if (firstDigit == 7 || secondDigit == 7 || thirdDigit == 7) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;	
}

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

using namespace std;

using int64 = long long;

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

  vector< int > sz[1000000];
  int used = 0;

  while(N > 0) {
    int need = used;

    for(int i = used - 1; i >= 0; i--) {
      sz[need].push_back(N);
      sz[i].push_back(N);
      --N;
    }
    ++used;
  }

  if(N == 0) {
    cout << "Yes\n";
    cout << used << endl;
    for(int i = 0; i < used; i++) {
      cout << sz[i].size() << " ";
      for(int j : sz[i]) cout << j << " ";
      cout << endl;
    }
  } else {
    cout << "No\n";
  }
}



Measured memory_bytes: 25728
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int n = s.size();
	int result = 0;
	REP(i, n) { result += s[i] == t[i] ? 0 : 1; }
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
const int N=350;
char g[N][N];
bool isempty[N];
int ans[N][N];
int first_color[N];
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int h,w,k;
	cin>>h>>w>>k;
	int cnt=1;
	for(int i=1; i<=h; i++) {
		for(int j=1; j<=w; j++) {
			cin>>g[i][j];
			if(g[i][j]=='#') {
				if(!first_color[i]) {
					first_color[i]=cnt;
				}
				ans[i][j]=cnt++;
			}
		}
	}
	for(int i=1; i<=h; i++) {
		int last=-1;
		for(int j=1; j<=w; j++) {
			if(g[i][j]!='.'&&ans[i][j]) {
				last=ans[i][j];
			}
			if(g[i][j]=='.'&&!ans[i][j]) {
				if(last==-1) {
					if(!first_color[i]) {
						// copy_last_line
					}
					else{
						last=first_color[i];
						ans[i][j]=last;
					}
				}
				else{
					ans[i][j]=last;
				}
			}
		}
	}
	for(int i=1; i<=h; i++) {
		isempty[i]=true;
		for(int j=1; j<=w; j++) {
			isempty[i]&=(g[i][j]=='.');
		}
	//	cout<<i<<" "<<isempty[i]<<endl;
	}

	for(int i=1; i<=h; i++) {
		if(!isempty[i]) {
			for(int j=i-1; j>=1; j--) {
				if(isempty[j]) {
					for(int k=1; k<=w; k++) {
						ans[j][k]=ans[i][k];
					}
					isempty[j]=false;
				}
				else{
					break;
				}

			}
			for(int j=i+1; j<=h; j++) {
				if(isempty[j]) {
					for(int k=1; k<=w; k++) {
						ans[j][k]=ans[i][k];
					}
					isempty[j]=false;
				}
				else{
					break;
				}
			}

		}
	}
	for(int i=1; i<=h; i++) {
		for(int j=1; j<=w; j++) {
			cout<<ans[i][j]<<" ";
		}
		cout<<endl;
	}


	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>

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

using namespace std;

int main() {
    
    long a,b,c,k;
    
    cin >> a >> b >> c >> k;
    
    /*
    int ans=1;
    
    FOR(i, 0, k){
        long ta = a;
        long tb = b;
        a = b+c;
        b = ta+c;
        c = ta+tb;
        if(abs(a-b) > pow(10, 19)){
            ans = 0;
            break;
        }
    }
     */
    if(k%2==0){
        cout << a-b << endl;
    }else{
        cout << b-a << endl;
    }
    
    
    
    return 0;
}


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

using ll = long long;

const ll MXLL = 1e18;

int n, k;
vector<ll> dp;
vector<ll> arr;

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

   cin >> n >> k;
   dp = arr = vector<ll>(n+1, MXLL);
   for(size_t i=1;i<=n;i++)
      cin >> arr[i];

   dp[1]=0;
   for(size_t i=1;i<=n;i++)
      for(size_t j=1;j<=k && i+j<=n; j++)
         dp[i+j] = min(dp[i+j], dp[i] + abs(arr[i] - arr[i+j]));

   cout << dp[n];
   return 0;
}


Measured memory_bytes: 1792
#ifdef ONLINE_JUDGE
  #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#endif

#include "bits/stdc++.h"
using namespace std;
#define int long long

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))

signed main() {
  #ifndef ONLINE_JUDGE
    ifstream cin("in");
  #endif
  ios_base::sync_with_stdio(0); cin.tie(0); // harris leung ioi gold calling it 18.09

  int n, w; cin >> n >> w;
  int a[n], b[n]; // w, v
  for (int i = 0; i < n; i ++) cin >> a[i] >> b[i];
  int f[100010]; for (int i = 0; i <= 100000; i ++) f[i] = 1000000000000000;
  f[0] = 0;
  for (int i = 0; i < n; i ++) {
    for (int j = 100000; j >= b[i]; j --) {
      f[j] = min(f[j], f[j - b[i]] + a[i]);
    }
  }
  for (int i = 100000; i >= 0; i --) {
    if (f[i] <= w) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 4376
#include<cstdio>
#include<iostream>


using namespace std;

int main(void){
  
  int a,b,c;
  
  cin>>a>>b>>c;
  
  if(a>=b&&a>=c)
    cout<<a*10+c+b<<endl;
  else if(b>=a,b>=c)
    cout<<b*10+a+c;
  else
    cout<<c*10+a+b;
  
  return 0;

}

Measured memory_bytes: 256
x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

a_b = []
for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= k:
            a_b.append(a[i] + b[j])
        else:
            break
a_b.sort(reverse=True)
ans = []
a_b = a_b[:k]
c = c[:k]
for i in range(min(k, len(a_b))):
    for j in range(min(k, z)):
        ans.append(a_b[i] + c[j])

ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

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

using namespace std;


typedef long long ll;

const int M = 998244353;

int main(){

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

    int n ; 
    cin >> n ;

    vector<pair<ll,ll>> A (n);

    for(int i = 0 ; i < n ; ++i){
        cin >> A[i].first >> A[i].second; 
    }

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

    vector<ll> dp (n + 1 ,  0) ; 

    dp[n] = 1 ;

    stack<pair<ll,ll>> st ; 

    st.push({n , 1e18}) ; 

    for( int i = n - 1 ; i >= 0 ;--i){

        while(!st.empty() &&  (st.top().second < A[i].first + A[i].second)){
            st.pop(); 
        }

        dp[i] = dp[i+1]; 
        dp[i] = (dp[i] +  dp[st.top().first]) % M ; 
        st.push({i , A[i].first}); 
    }

    cout << dp[0]<<"\n";
    
  
    return 0;
}



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

using str = string;
using ss = stringstream;

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

    int n;cin>>n;

    ss ms;
    ms<<"ABC"<<n;

    cout<<ms.str()<<"\n";

    return 0;
}


Measured memory_bytes: 3664
S = input()
# S = "aabaa"
s_list = list(S)
lenS = len(S)
# print(s_list)
result = []
connected = False

count = 0
i = 0
while(i < lenS):
    if connected:
        # result.append(s_list[i])
        connected = False
        i += 1
        continue

    if i == lenS - 1:
        # result.append(s_list[i])
        break

    if s_list[i] == s_list[i+1]:
        # result.append(s_list[i] + s_list[i + 1])
        connected = True
        i += 2
        count += 1
    else:
        # result.append(s_list[i])
        i += 1
# print(result)
print(lenS-count)


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    int a, b, h;
    cin >> a >> b >> h;
    int ans = 0;
    // 処理
    ans = (a + b) * h / 2;
    // 出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef pair<int,int> pii;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ub upper_bound
#define lb lower_bound
#define present(c,x) (c.find(x) != c.end())
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define INF 1000000007 
#define MOD 998244353
#define INF64 1e18

void solve(){
	int n;
	cin>>n;
	vector<ld> p(n+1);
	rep(i,1,n+1)
		cin>>p[i];

	vector<vector<ld>> dp(n+1,vector<ld> (n+1,0));
	dp[0][0]=1;

	rep(i,1,n+1){
		rep(j,0,n+1){
			dp[i][j]=dp[i-1][j]*(1-p[i]);
			if(j!=0)
				dp[i][j]+=dp[i-1][j-1]*p[i];
		}
	}

	ld ans=0;
	for(int i=(n/2)+1;i<=n;i++){
		ans+=dp[n][i];
	}

	cout<<fixed<<setprecision(12)<<ans;
}	
 
int32_t main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
 
	int T;
	// cin>>T;
	T=1;
	while(T--){
		solve();
	}
}

Measured memory_bytes: 144228
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    double sum=0;
    for(int i=1;i<=n;++i) {
        double ret=1.0/n;
        int now=i;
        while(now<k) {
            now*=2;
            ret/=2;
        }
        sum+=ret;
    }
    cout << fixed << setprecision(10) << sum << endl;
}


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

int sub(int x,int y) {
  if ( x > y ) {
    return x-y;
  }
  else {
    return y-x;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> data(n);
  for ( int i = 0 ; i < n ; i++ ) {
    cin >> data.at(i);
  }
  
  vector<int> ans(n,0);
  ans.at(1) = sub(data.at(0),data.at(1)); 
  
  for ( int i = 0 ; i < n ; i++ ) {
    if ( i > 1 ) {
      int dp1 = ans.at(i-2) + sub(data.at(i),data.at(i-2));
      int dp2 = ans.at(i-1) + sub(data.at(i),data.at(i-1));
      ans.at(i) = min(dp1,dp2);
    } 
  }
  
  cout << ans.at(n-1) << endl;
}

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

int main()
{
    int h,n,i,s=0;
    cin>>h>>n;
    int a[n];
    for(i = 0; i < n; i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    if(s>=h)
        cout<<"Yes\n";
    else
        cout<<"No\n";

}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n+1);
  for(int i=0; i<m; i++){
    int b1, b2;
    cin >> b1 >> b2;
    a[b1].push_back(b2);
    a[b2].push_back(b1);
  }
  vector<int> b(n+1);
  queue<int> c;
  set<int> d;
  c.push(1);
  d.insert(1);
  while(!c.empty()){
    int tmp = c.front();
    c.pop();
    for(int i=0; i<a[tmp].size(); i++){
      int tmp2=a[tmp][i];
      if(!d.count(tmp2)){
	d.insert(tmp2);
	c.push(tmp2);
	b[tmp2]=tmp;
      }
    }
  }
  cout << "Yes" << endl;
  for(int i=2; i<n+1; i++)
    cout << b[i] << endl;
  return 0;
}

Measured memory_bytes: 18096
mod = 10 ** 9 + 7

N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

H = [0] * N
for i in range(N):
    if i == 0 or T[i - 1] < T[i]:
        H[i] = T[i]

for i in range(N - 1, -1, -1):
    if i == N - 1 or A[i] > A[i + 1]:
        H[i] = A[i]
    
ans = 1
for i in range(N):
    if H[i] == 0:
        H[i] = min(T[i], A[i])
        ans *= min(T[i], A[i])
        ans %= mod

flag = True
M = 0
for i in range(N):
    M = max(M, H[i])
    flag &= (M == T[i])
M = 0
for i in range(N - 1, -1, -1):
    M = max(M, H[i])
    flag &= (M == A[i])

if flag is True:
    print(ans)
else:
    print(0)

Measured memory_bytes: 19012
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int cumsum[100002];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    int a;
    int b;
    cin >> a >> b;
    cumsum[a] ++;
    if(b < N + 1){
      cumsum[b + 1] --;
    }
  }

  for(int i = 1; i <= N + 1; i++){
    cumsum[i] += cumsum[i - 1];
  }

  int ans = 0;
  for(int i = 0; i <= N + 1; i++){
    if(cumsum[i] + 1 >= i){
      ans = i - 1;
    }
  }
  cout << ans << endl;
  return 0;
}



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

int main() {
	int n, t;
	cin >> n >> t;
	int ans = 10000000;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if(b<=t)
			ans = min(ans, a);
	}
	if (ans > 5000) {
		cout << "TLE" << endl;
			return 0;
	}
	else
		cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  ll N;
  cin >> N;
  vector<vector<P>> to(N);
  rep(i, N - 1) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    to[a].pb({b, c});
    to[b].pb({a, c});
  }

  vll dist(N, -1);

  queue<P> q;
  q.push({0, 0});

  while (!q.empty()) {
    P t = q.front();
    q.pop();

    if (dist[t.first] != -1) continue;
    dist[t.first] = t.second;

    rep(i, to[t.first].size()) {
      q.push({to[t.first][i].first, t.second + to[t.first][i].second});
    }
  }

  rep(i, N) {
    if (dist[i] % 2 == 0) {
      COUT(0);
    } else {
      COUT(1);
    }
  }
  return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N;
    cin >> N;
    vector<int>a(N);
    int ans = 100100101001LL;
    int res = 0;
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        res+=a[i];
    } 
    for(int i = 0; i < N-1; i++) {
        cnt+=a[i];
        ans = min(ans,abs(res-2*cnt));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <set>
using namespace std;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define fill(x, y)     memset(x, y, sizeof(y))
#define all(x)         (x).begin(), (x).end()
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;

const int INF = 1e9 + 5;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vi h(N+1);
  h[0] = INF;
  for (int i = 1; i <= N; i++) {
    cin >> h[i];
  }
  vi dp(N+1, INF);
  dp[0] = 0;
  dp[1] = 0;
  for (int i = 2; i <= N; i++) {
    for (int j = 1; j <= min(i-1,K); j++) {
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  cout << dp[N] << "\n";
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)


int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    string s = "No";
    if (A == B) {
        s = "No";
    } else if (A < B) {
        s = (A < C && C < B) ? "Yes" : "No";
    } else {
        s = (B < C && C < A) ? "Yes" : "No";
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>
#include <map>

int main() {
  size_t n;
  scanf("%zu", &n);

  char buf[64];
  scanf("%s", buf);
  std::string s = buf;

  int res = 0;
  for (size_t i = 2; i < n; ++i) {
    if (s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C') ++res;
  }
  printf("%d\n", res);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		String str = std.nextLine();
		int q = Integer.parseInt(std.nextLine());

		for(int i=0; i<q; i++){
			String query = std.next();
			int a = Integer.parseInt(std.next());
			int b = Integer.parseInt(std.next());

			if(query.equals("print")){
				System.out.println(str.substring(a, b+1));

			}else if(query.equals("reverse")){
				StringBuffer sb = new StringBuffer(str.substring(a, b+1));
				String rev = sb.reverse().toString();
				str = str.substring(0, a) + rev + str.substring(b+1, str.length());

			}else if(query.equals("replace")){
				String rep = std.next();
				str = str.substring(0, a) + rep + str.substring(b+1, str.length());
			}
		}
	}
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int m;
  while (cin >> m) {
    int n = m * 3;
    int a[n];
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    sort(a, a + n);
    deque<int> q;
    for (int i = 0; i < n; ++i) {
      q.push_back(a[i]);
    }
    lli sum = 0;
    while (q.size()) {
      q.pop_back();
      sum += q.back();
      q.pop_back();
      q.pop_front();
    }
    cout << sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 2688
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
ansa=0
ansb=0
ansc=0
ansd=0
anse=0

if str(a)[-1]=="0":
  ansa=0
else:
  ansa=str(a)[-1]
  ansa=10-int(ansa)
  
if str(b)[-1]=="0":
  ansb=0
else:
  ansb=str(b)[-1]
  ansb=10-int(ansb)
  
if str(c)[-1]=="0":
  ansc=0
else:
  ansc=str(c)[-1]
  ansc=10-int(ansc)
  
if str(d)[-1]=="0":
  ansd=0
else:
  ansd=str(d)[-1]
  ansd=10-int(ansd)
  
if str(e)[-1]=="0":
  anse=0
else:
  anse=str(e)[-1]
  anse=10-int(anse)
  
sum1=ansa,ansb,ansc,ansd,anse
ans1=sum(sum1)-max(sum1)

ans2=a+b+c+d+e
print(int(ans1)+int(ans2))

Measured memory_bytes: 3064
#include <iostream>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <math.h>
#include <map>
#include <algorithm>
#include <deque>
#include <stack>
#include<set>
//#include <bits/stdc++.h>
#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

const int N=5e5+100;
using namespace std;

int a[N];
int dp[N];
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    dp[1]=0;
    dp[2]=abs(a[1]-a[2]);
    for(int i=3;i<=n;i++){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
//    for(int i=1;i<=n;i++) cout<<dp[i]<<" ";
//    cout<<endl;
    printf("%d\n",dp[n]);
    return 0;
}


Measured memory_bytes: 1024
/*
    Stay motivated and keep working hard
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n;
int dp[100007];
int h[100007];
int recur(int n){
    if(n == 1){
        return 0;
    }
    if(dp[n] != -1){
        return dp[n];
    }
    int ans1 = INT_MAX, ans2 = INT_MAX;
    if(n == 2){
        ans1 = abs(h[2] - h[1]);
    }
    else if(n == 3){
        ans1 = abs(h[3] - h[1]);
        ans2 = abs(h[3] - h[2]) + recur(2);
    }
    else{
        ans1 = abs(h[n] - h[n-2]) + recur(n-2);
        ans2 = abs(h[n] - h[n-1]) + recur(n-1);
    }
    return dp[n] = min(ans1, ans2);
}
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin >> n;
    memset(dp, -1, sizeof(dp));
    for(int i=1;i<=n;i++){
        cin >> h[i];
    }
    recur(n);
    cout << dp[n] << "\n";


    return 0;
}


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

int     main() {
        string s;
        long K;
        cin >>s >>K;
        int i=0;
        for (int i=0; i<s.size(); i++) {
                if (0==K)
                        break;
                int c=s.at(i)-'a';
                if (c==0)
                        continue;
                if (K>=26-c) {
                        s.at(i)='a';
                        K -= 26-c;
                }
        }
        if (K>0) {
                int c=s.back()-'a';
                c +=K;
                c %=26;
                s.back()=c+'a';
        }
        cout <<s <<endl;
        return 0;
};

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<vector>
#include<math.h>
using namespace std;
class SimultaneousEquation{ 
    public:
        void solve(int a,int b,int c,int d,int e,int f){ 
            double x,y;
            x=double(c*e-b*f)/(a*e-b*d);
            y=double(c*d-a*f)/(b*d-a*e);
	    if(x==0)x=0;
	    if(y==0)y=0;
            printf("%.3lf %.3lf\n",x,y);
            }
};
int main(){ 
    int a,b,c,d,e,f;
    SimultaneousEquation inst;
    while(cin>>a>>b>>c>>d>>e>>f){
        inst.solve(a,b,c,d,e,f);
    }
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
typedef vector<int> vi;

int main(){
    FOR(i, 1, 10) FOR(j, 1, 10) cout << i << "x" << j << "=" << i*j << endl;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int x,k;
    cin>>x>>k;
    pair<int,int>p[k];
    for (int i=0;i<k;i++){
        cin>>p[i].second>>p[i].first;
    }
    sort(p,p+k);
    int ans=0,kl=p[0].first;
    for (int i=0;i<k;i++){
        if (kl<=p[i].second){
            ans++;
            kl=p[i].first;
        }
    }
    cout<<ans+1<<endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;

namespace AizuOnlineJudge {
    class Program {
        static void Main() =>
            Console.WriteLine(
                Enumerable.Range(1, Console.ReadLine().Split().Length)
                    .Select(_ => Console.ReadLine().Split().Aggregate(0, (p, c) => p + int.Parse(c)))
                    .Aggregate(1L, (p, c) => p * c)
            );
    }
}



Measured memory_bytes: 35712
#include<iostream>

using namespace std;

int main(){
    long long h,n,a,x=0;
    cin >> h >>n;
    for(int i=0;i<n;i++){
        cin >> a;
        x += a;
    }
    if(h>x){
        cout << "No" <<endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int h, w, n;
int a[10000], c[100][100];

int main() {
    scanf("%d %d", &h, &w);
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    int ind = 0;
    while (a[ind] == 0) ind++;
    for (int i = 0, cnt = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i % 2 == 0) c[i][j] = ind + 1;
            else c[i][w - 1 - j] = ind + 1;
            if (++cnt == a[ind]) {
                do {
                    ind++;
                } while (a[ind] == 0);
                cnt = 0;
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w - 1; j++) printf("%d ", c[i][j]);
        printf("%d\n", c[i][w - 1]);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX =510000;
vector<vector<P>>G(100001);//行先と辺番号を記す
int N;
vector<int>res(100001); 

//v 頂点　ｐ親　ｐｃおやとの辺の色、色のメモ
void dfs(int v,int p,int pc,vector<int>&res){
	int color=1;
	if(color==pc)color++;
	for(auto e:G[v]){
    	if(e.first==p)continue;
      	res[e.second]=color;
      	dfs(e.first,v,color,res);
      	color++;//次の頂点の色をかえる
      	if(pc==color)color++;//ダブりがないよう数字を定める。
    }
  
}


int main(){
	cin >>N;
  	rep(i,N-1){
    	int a,b;
    	cin >>a>>b;
    	G[a].push_back(P(b,i));
    	G[b].push_back(P(a,i));
    }
  	int maxcolor=0;
  	rep(i,N){maxcolor=max(maxcolor,(int)G[i].size());}
  	dfs(1,-1,-1,res);
  	cout<<maxcolor<<endl;
  	for(int i=0;i<N-1;i++){cout<<res[i]<<endl;}
  
  
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

const int mod = inf;
int s[3000], t[3000], q[3000][3000], p[3000][3000];
signed main(){
  int n, m;cin >> n >> m;
  rrep(i,n)cin >> s[i];
  rrep(i,m)cin >> t[i];
  rep(i,m+1)q[0][i] = 1;
  rep(i,n+1)q[i][0] = 1;
  rrep(i,n)rrep(j,m){
    if(s[i] == t[j]){
      p[i][j] = q[i-1][j-1];
    }
    q[i][j] = mod + q[i][j-1] + q[i-1][j] - q[i-1][j-1] + p[i][j];
    q[i][j] %= mod;
  }
  cout << q[n][m] << endl;
  return 0;
}






Measured memory_bytes: 96128
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;
  N++;
  vector<vector<ll>> edge(N, vector<ll>());
  vector<ll> map(N, 0);
  vector<vector<ll>> es;

  for (auto i = 0; i < M; i++) {
    ll a, b;
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
    es.push_back({a, b});
  }

  ll res = 0;
  for (auto i = 0; i < M; i++) {
    for (auto j = 0; j < N; j++) map[j] = 0;
    vector<ll> queue;
    ll a = es[i][0];
    ll b = es[i][1];
    queue.push_back(a);
    map[a] = 1;
    while (!queue.empty()) {
      ll x = queue.back();
      queue.pop_back();
      for (auto j = 0; j < edge[x].size(); j++) {
        ll y = edge[x][j];
        if ((x == a && y == b) || (x == b && y == a)) continue;
        if (map[y] == 0) queue.push_back(y);
        map[y] = 1;
      }
    }
    queue.push_back(b);
    map[b] = -1;
    while (!queue.empty()) {
      ll x = queue.back();
      queue.pop_back();
      for (auto j = 0; j < edge[x].size(); j++) {
        ll y = edge[x][j];
        if ((x == a && y == b) || (x == b && y == a)) continue;
        if (map[y] != -1) queue.push_back(y);
        map[y] = -1;
      }
    }
    bool renketu = true;
    for (auto i = 1; i < N; i++) if (map[i] != -1) renketu = false;

    if (!renketu) res++;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A>=B && A>=C){
    A=0;
  }
  else if(B>=A && B>=C){
    B=0;
  }
  else if(C>A && C>=B){
    C=0;
  }
  printf("%d",A+B+C);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int X, Y;
    cin >> X >> Y;

    int ans = 0;
    if(X == 1)
        ans += 300000;
    if(X == 2)
        ans += 200000;
    if(X == 3)
        ans += 100000;
    
    if(Y == 1)
        ans += 300000;
    if(Y == 2)
        ans += 200000;
    if(Y == 3)
        ans += 100000;
    
    if(X == 1 && Y == 1)
        ans += 400000;
    
    cout << ans << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll A,ll B) {if(!B)return A;return gcd(B,A%B);}
int main()
{
 ll a,b;
 cin>>a>>b;
 a = gcd(a,b);
 ll ans = 0;
 for(ll i=2;i*i<=a;i++){
	 if(a%i == 0){
		 ans++;
		 while(a%i == 0)a/=i;
	}
 }
  if(a > 1)ans++;
   ans++;
  cout<<ans;
}



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

int main(){
    long long x,y;
    cin >> x >> y;
    int ans =1;
    for(long long i=2;;){
        if(x*i<=y){
            ans++;
            x *= i;
        }
        else break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int w,h,n;
	cin>>w>>h>>n;
	
	vector<vector<bool>> fie(h,vector<bool>(w,false));
	
	rep(i,n){
		int x,y,a;
		cin>>x>>y>>a;
		if(a==1){
			rep(Y,h)rep(X,w){
				if(X<x)fie[Y][X]=true;
			}
		}
		if(a==2){
			rep(Y,h)rep(X,w){
				if(X>=x)fie[Y][X]=true;
			}
		}
		if(a==3){
			rep(Y,h)rep(X,w){
				if(Y<y)fie[Y][X]=true;
			}
		}
		if(a==4){
			rep(Y,h)rep(X,w){
				if(Y>=y)fie[Y][X]=true;
			}
		}
	}
	int c = 0;
	rep(i,h)rep(j,w)if(!fie[i][j])c++;
	cout<<c<<endl;
}

Measured memory_bytes: 256
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int sum = 0;
		int num = 0;
		for(int i=1; i<=n; i++){
			num = method(i);
			if(a <= num && num <= b){
				sum += i;
			}
		}
		System.out.println(sum);
	}
	
	public static int method(int n){
		int sum = 0;
		while(n > 0){
			sum += n % 10;
			n /= 10;
		}
		return sum;
	}
}


Measured memory_bytes: 35484
#include<bits/stdc++.h>
using namespace std;
int n,c[3],i,j,k;
double dp[303][303][303];
double p0()
{
 return (double)(n-i-j-k)/(double)n; 
}
double p1()
{
 return (double)i/(double)n; 
}
double p2()
{
 return (double)j/(double)n; 
}
double p3()
{
 return (double)k/(double)n; 
}
int main()
{
  c[0]=c[1]=c[2]=0;
  cin>>n;
  int x;
  for(i=0;i<n;i++)
  {
   cin>>x;
    c[x-1]++;
  }
  dp[0][0][0]=0;
  for(k=0;k<=n;k++)
  {
    for(j=0;j<=n;j++)
    {
      for(i=0;i<=n;i++)
      {
        if((i|j|k)==0)
          continue;
        dp[i][j][k]=1.0/(1.0-p0());
        double te=1;
        if(i>=1)
          te+=p1()*dp[i-1][j][k];
        if(j>=1)
          te+=p2()*dp[i+1][j-1][k];
        if(k>=1)
          te+=p3()*dp[i][j+1][k-1];  
        dp[i][j][k]*=te;
     //   cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<"\n";
      }
    }
  }
  cout<<fixed<<setprecision(11);
  cout<<dp[c[0]][c[1]][c[2]];
  return 0;
}

Measured memory_bytes: 217344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    if (k > (n - 1) * (n - 2) / 2) {
        cout << -1 << endl;
        return 0;
    }

    vector<pair<int, int>> pr;
    bool v[n][n] = {};
    rep(i, 1, n) {
        pr.push_back(make_pair(0, i));
        v[0][i] = true;
        v[i][0] = true;
    }

    int cnt = (n - 1) * (n - 2) / 2;
    rep(i, 0, n) {
        rep(j, i + 1, n) {
            if (cnt == k) break;
            if(!v[i][j]) {
                pr.push_back(make_pair(i, j));
                v[i][j] = true;
                v[j][i] = true;
                cnt--;
            }
        }
        if (cnt == k) break;
    }

    cout << pr.size() << endl;
    for (auto i : pr) {
        cout << i.first + 1 << " " << i.second + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define int long long
priority_queue<pair<int,int> >q;
int n,m,b[200100],a[200100],pre[200100],nxt[200100];
signed main(){
    int i,j,k,ans=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(i=1;i<=n;i++){
      scanf("%lld",&b[i]);
      q.push(mp(b[i],i));
    }
    for(i=1;i<=n;i++){
      nxt[i]=i+1;
      pre[i]=i-1;
    }
    pre[1]=n;
    nxt[n]=1;
    while(!q.empty()){
      int x=q.top().se;
      q.pop();
      if(b[x]==a[x])continue;
      int y=pre[x],z=nxt[x];
      if(b[x]-b[y]-b[z]<a[x]){
      	puts("-1");
      	return 0;
      }
      k=b[x]-a[x];
      ans+=k/(b[y]+b[z]);
      b[x]=(k%(b[y]+b[z]))+a[x];
      if(a[x]!=b[x])q.push(mp(b[x],x));
    }
    cout<<ans<<"\n";
	return 0;
}


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

int main() {
	int A, B;
	cin >> A >> B;
	cout << (max(A, B) > 8 ? ":(" : "Yay!");
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

入力例2が最大のとり方
これより多い取り方は互いにできない
逆は単に取らなかったことにすればおｋ
*/

Measured memory_bytes: 256
/*
 *Author - Abhas Jain
 */

#include <bits/stdc++.h>

#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
const ll N = 3001;

ll dp[N][N];
vector<ll> a(N);
int n;

ll calc(int l, int r) {
	if (dp[l][r] != INF) {
		return dp[l][r];
	}
	if ((n - r + l) % 2) {
		return dp[l][r] = max(a[l] + calc(l + 1, r), a[r] + calc(l, r - 1));
	} else {
		return dp[l][r] = min(calc(l + 1, r) - a[l], calc(l, r - 1) - a[r]);
	}
}

void solve() 
{
    cin >> n;
    for (int i = 0; i < n; ++i) {
    	cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
    	for (int j = 0; j < n; ++j) {
    		dp[i][j] = INF;
    	}
    }
    for (int i = 0; i < n; ++i) {
    	if (n % 2) dp[i][i] = a[i];
    	else dp[i][i] = -a[i];
    }
    cout << calc(0, n - 1) << endl;
}

int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

    double pai = 6.28318530717958623200;

    //cout << "Yes" << "No" << " " << endl;
    printf("%.10f\n", n * pai);
    return 0;
}

Measured memory_bytes: 3764
// Problem : E - Sum of gcd of Tuples (Hard)
// Contest : AtCoder - AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

ll pow2(ll a, ll b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	ll d = pow2(a, b / 2);
	d = d * d % MOD;
	if (b % 2) return d * a % MOD;
	return d;	
}

const int MAX = 1e5;
vi divs[MAX + 5];
ll res[MAX + 5];
void sieve() {
	FOR(i, 2, MAX) {
		divs[i].pb(1);
		for (int j = i; j <= MAX; j+= i) {
			divs[j].pb(i);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	sieve();
	ll ans = pow2(k, n);
	res[1] = 1;
	FOR(i, 2, k) {
		ll sum = 0;
		for (auto x: divs[i]) {
			sum += res[x];
		}
		ll ile = i - sum;
		res[i] = ile;
		ans = ans + (pow2(k / i, n) * ile) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}
 


Measured memory_bytes: 14348
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use proconio::{marker::*, *};
#[fastout]
fn main() {
    input! {
        n:usize,
        a:[u32;n],
    }
    if a.iter().filter(|&x| x % 2 == 1).count() % 2 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 3392
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxlen=1e4+5;
const int maxd=105;
const ll mod=1e9+7;
ll num[5][maxd][maxlen];
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//    fl();
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string ss;
	cin>>ss;
	ss="_"+ss;
	int len=(int)ss.length()-1;
	int d;
	cin>>d;
	num[1][0][0]=1;
	for(int i=1;i<=len;i++)
	{
		int present=ss[i]-'0';
		for(int r=0;r<d;r++)
			for(int cur=0;cur<=9;cur++)
			{
				int delta=(r-cur+d*10)%d;
				if(cur<present)
					num[0][r][i]=(num[0][r][i]+num[1][delta][i-1]+num[0][delta][i-1])%mod;
				else if(cur==present)
				{
					num[0][r][i]=(num[0][r][i]+num[0][delta][i-1])%mod;
					num[1][r][i]=(num[1][r][i]+num[1][delta][i-1])%mod;
				}
				else 
					num[0][r][i]=(num[0][r][i]+num[0][delta][i-1])%mod;
			}
	}
	ll ans=(num[0][0][len]+num[1][0][len]-1+mod)%mod;
	printf("%lld\n",ans);
	return 0;
}


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

int solver(int d, int w){
    if(d > 160 || w > 25)
        return 0;
    else if(d > 140 || w > 20)
        return 1600;
    else if(d > 120 || w > 15)
        return 1400;
    else if(d > 100 || w > 10)
        return 1200;
    else if(d > 80 || w > 5)
        return 1000;
    else if(d > 60 || w > 2)
        return 800;
    else
        return 600;
}

int main(){
    int n;
    while(cin >> n, n!=0){
        int sum = 0;
        for(int i=0; i<n; i++){
            int x,y,h,w;
            cin >> x >> y >> h >> w;
            sum += solver(x+y+h, w);
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
 int main() {
  int a, b, c;
  int ans = 0;
  std::cin >> a >> b >> c;
   for (int x = a; x <= b; x++) {
    if (c % x == 0) {
     ans++;
    }
   }
    std::cout << ans <<std::endl;



 return 0;


}
     


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans = 1LL << 60;
signed main()
{
    int k, n;
    cin >> k >> n;
    vector<int> dis(n);
    for (int i = 0; i < n; i++)
        cin >> dis[i];
    int nozero = 0;
    for (int i = 0; i < n; i++)
    {
        if (dis[i] != 0)
        {
            nozero = i;
            break;
        }
    }
    for (int i = 1; i < n; i++)
    {
        ans = min(ans, dis[i - 1] + (k - dis[i]));
    }
    ans = min(ans,dis[n - 1] - dis[0]);
    cout << ans << endl;
}

Measured memory_bytes: 1792