akhauriyash/Code-Regression huggingface dataset:
import sys
import math

n, k = map(int, sys.stdin.readline().split())

W = []
for _ in range(n):
    w = int(sys.stdin.readline())
    W.append(w)

r = sum(W)
l = max(W)
pre_p = 0


while l < r:

    current = 0
    num_tracks = 1

    p = (l + r) // 2  # 値を設定

    # 積み込めるか確認
    for w in W:
        if current + w > p:
            num_tracks += 1  # 次のトラックを持ってくる
            current = w
        else:
            current += w
    
    if num_tracks > k:  # 現在の p ではトラックが足りない場合
        l = p + 1  # 最少値を上げる
    else:
        r = p  # 最大値を下げる


print(l)


Measured memory_bytes: 9612
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
/**#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	double a, b;
	std::cin >> a >> b;
	if (a == b) {
		std::cout << "AB" << std::endl;
	}
	else if (a < b) {
		std::cout << 'B' << std::endl;
	}
	else {
		std::cout << 'A' << std::endl;
	}
 	return 0;
}
int main() {
	int a, b;
	std::cin >> a >> b;
	std::vector<int>A(b, a);
	for (int i = 0;i < b;i++) {
		for (int j = 0;j < a;j++) {
			std::cin >> A[i, j];
		}
	}
	for (int i = b;i > 0;i--) {
		for (int j = a;j > 0;j--) {
			std::cout << A[i, j] << std::endl;
		}
	}
 	return 0;
}*/
int main() {
	int a;
std::cin >> a;
for (int i = 1;i > 0;i *= 2) {
	if (a < i) {
		std::cout << i / 2 << std::endl;
		break;
	}
}
return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      // cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int a, b;
  cin >> a >> b;
  if (a <= b)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int d;
  cin >> d;
  string s[26];
  s[22] = "Christmas Eve Eve Eve";
  s[23] = "Christmas Eve Eve";
  s[24] = "Christmas Eve";
  s[25] = "Christmas";
  cout << s[d] << endl;
}

Measured memory_bytes: 3496
while 1:
    N = int(input())
    if N == 0:
        break
    y = int(input())
    v = 0; k = None
    for i in range(N):
        b, r, t = map(int, input().split())
        if t == 1:
            w = 1 + y * r /100
        else:
            w = (1 + r / 100) ** y
        if v < w:
            v = w
            k = b
    print(k)


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

const int N=600005;

int a[N],L[25][N],R[25][N],f[N],g[N],S[N];

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	int n,m,k,cnt=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		if(i!=1&&a[i]-a[i-1]>m) ++cnt;
	}
	k=log2(m)+2;
//	cout<<k<<endl;
	if(cnt>k)
	{
		for(int i=1;i<=n;i++) cout<<"Impossible"<<endl;
		return 0;
	}
	int s=m;
	for(int i=0;i<k;i++)
	{
		L[i][1]=1;
		R[i][n]=n;
		for(int j=2;j<=n;j++)
		{
			if(a[j]-a[j-1]>s) L[i][j]=j;
			else L[i][j]=L[i][j-1];
		}
		for(int j=n-1;j>=1;j--)
		{
			if(a[j+1]-a[j]>s) R[i][j]=j;
			else R[i][j]=R[i][j+1];
		}
		s/=2;
	}
	/*for(int i=0;i<k;i++)
	{
		for(int j=1;j<=n;j++) cout<<L[i][j]<<" ";
		cout<<endl;
		for(int j=1;j<=n;j++) cout<<R[i][j]<<" ";
		cout<<endl;
	}
	cout<<endl;*/
	for(int i=0;i<(1<<k);i++)
	{
		f[i]=0;
		g[i]=n+1;
	}
	for(int i=0;i<(1<<(k-1));i++)
	{
		for(int j=1;j<k;j++)
		{
			if(!(i&(1<<(j-1))))
			{
				if(f[i]==n) f[i|(1<<(j-1))]=n;
				else f[i|(1<<(j-1))]=max(f[i|(1<<(j-1))],R[j][f[i]+1]);
				if(g[i]==1) g[i|(1<<(j-1))]=1;
				else g[i|(1<<(j-1))]=min(g[i|(1<<(j-1))],L[j][g[i]-1]);
			}
		}
	}
/*	for(int i=0;i<(1<<(k-1));i++) cout<<f[i]<<" ";
	cout<<endl;
	for(int i=0;i<(1<<(k-1));i++) cout<<g[i]<<" ";
	cout<<endl;*/
	for(int i=0;i<=n;i++) S[i]=0x7f7f7f7f;
	for(int i=0;i<(1<<(k-1));i++) 
	{
	//	cout<<i<<" "<<(1<<(k-1))<<" "<<((1<<(k-1))^i)<<endl;
		S[f[i]]=min(S[f[i]],g[((1<<(k-1))-1)^i]);
	}
//	for(int i=0;i<=n;i++) cout<<S[i]<<" ";
//	cout<<endl;
	for(int i=n-1;i>=0;i--) S[i]=min(S[i],S[i+1]);
//	for(int i=0;i<=n;i++) cout<<S[i]<<" ";
//	cout<<endl;
	for(int i=1;i<=n;i++)
	{
		if(S[L[0][i]-1]<=R[0][i]+1) cout<<"Possible"<<endl;
		else cout<<"Impossible"<<endl;
	}
	return 0;
}


Measured memory_bytes: 99584
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)

using namespace std;

int n, m;

bool check1(vector<int> a, vector<int> b) {
	int i;
	vector<bool> exist(n + 1, false);
	rep(i, m) {
		if (a[i] <= 0 || a[i] > n) return false;
		if (b[i] <= 0 || b[i] > n) return false;
		if (exist[a[i]]) return false;
		exist[a[i]] = true;
		if (exist[b[i]]) return false;
		exist[b[i]] = true;
	}
	return true;
}

bool check2(vector<int> a, vector<int> b) {
	int i;
	
	vector<bool> used(n + 1, false);
	rep(i, m) {
		int x = abs(a[i] - b[i]);
		x = min(n - x, x);
		if (n % 2 == 0 && x == n / 2) return false;
		if (used[x]) { cout << "a, b = " << a[i] << ", " << b[i] << ", x = " << x << endl; return false; }
		used[x] = true;
	}
	return true;
}

void debug2(vector<int> a, vector<int> b) {
	int i;
	rep(i, m) {
		int x = abs(a[i] - b[i]);
		x = min(n - x, x);
		cout << "a, b = " << a[i] << ", " << b[i] << ", x = " << x << endl;
	}
}

bool naive_checker(vector<int> a, vector<int> b) {
	if (check1(a, b) == false) return false;
	if ((int)a.size() != m || (int)b.size() != m) { return false; }
	
	typedef pair<int, int> P;
	set<P> appear;
	
	int i, j;
	for (i = 0; i < n; i++) {
		cerr << endl;
		for (j = 0; j < m; j++) {
			int A = a[j] - i; if (A <= 0) A += n;
			int B = b[j] - i; if (B <= 0) B += n;
			cerr << A << ", " << B << endl;
			if (appear.find(P(A, B)) != appear.end() || appear.find(P(B, A)) != appear.end()) return false;
			appear.insert(P(A, B));
			appear.insert(P(B, A));
		}
	}
	return true;
}

vector<int> a;
vector<int> b;
void solve() {
	if (n % 2 == 1) {
		for (int i = 0; i < m; i++) {
			a.push_back(i + 1);
			b.push_back(n - i);
		}
	}
	else {
		int x = 1;
		int y = n;
		for (int i = 0; i < min(m, (n + 1) / 4); i++) {
			a.push_back(x);
			b.push_back(y % n);
			x++;
			y--;
		}
		x++;  
		for (int i = 0; i < m - (n + 1) / 4; i++) {
			a.push_back(x);
			b.push_back(y);
			x++;
			y--;
		}
		for (int i = 0; i < m; i++) {
			a[i] = a[i] % n;
			b[i] = b[i] % n;
			if (a[i] == 0) a[i] = n;
			if (b[i] == 0) b[i] = n;
		}
	}
}

void print() {
	int i;
	rep(i, m) cout << a[i] << " " << b[i] << endl;
}

signed main() {
	cin >> n >> m;
	if (m < 1 || m * 2 + 1 > n) assert(0);
	
	solve();
	
	print();
	
	return 0;
}


Measured memory_bytes: 3940
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int dp[200010];
vector<int> g[200010];

int solve(int pos){
  int &r = dp[pos];
  if(r >= 0) return r;
  r = 0;
  for(auto x : g[pos]) r = max(r, 1+solve(x));
  return r;
}

int main(){FIN;
  memset(dp,-1,sizeof(dp));
  int ans = 0,x,y,n,m;
  cin >> n >> m;
  fore(i,0,m) cin >> x >> y, g[x-1].pb(y-1);
  fore(i,0,n) ans = max(ans,solve(i));
  cout << ans << "\n";
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int n, q, k,MM[1000001];
ll mmm[1000000];
string s;
ll ans;

int main() {
	cin >> n >> s >> q;
	for (int i = 0; i != n; ++i) {
		MM[i + 1] = MM[i];
		if (s[i] == 'M')
			++MM[i + 1];
	}
	for (int i = 0; i != q; ++i) {
		cin >> k;
		ll D = 0;
		ll M = 0;
		int l = 0;
		int r;
		ans = 0;
		for (r = 0; r < k; ++r) {
			if (s[r] == 'D')++D;
			if (s[r] == 'M') {
				M += D;
			}
			if (s[r] == 'C') {
				ans += M;
			}
		}
		int t = 0;
		for (; r < n; ++r) {
			if (s[l] == 'D') {
				--D;
				++t;
				M -= MM[r] - MM[l + 1];
			}
			++l;
			if (s[r] == 'D')++D;
			if (s[r] == 'M') {
				M += D;
				mmm[r] = D;
			}
			if (s[r] == 'C') {
				ans += M;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 13060
#include"bits/stdc++.h"
using namespace std;
int main(){
	vector<int> x{1,2,4,8,16,32,64};
	int k,n;
	cin>>n;
	for(;k!=x.size();++k){
		if(x[k]>n)
			break;
	}
	cout<<x[k-1];
}

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル

	ll X;
	cin >> X;

	int ans = 0;
	ll now = 100;
	while(now < X){
		ans++;
		now *= 1.01;
	}

	cout << ans << endl;

}

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

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define f0r(a, b) for (long long a = 0; a < (b); ++a)
#define f1r(a, b, c) for (long long a = (b); a < (c); ++a)
#define f0rd(a, b) for (long long a = (b); a >= 0; --a)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); --a)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define fix(prec) {cout << setprecision(prec) << fixed;}
#define mp make_pair
#define f first
#define s second
#define presum(p, a, n) {p[0] = a[0]; for (int i = 1; i < (n); i++) p[i] = a[i] + p[i-1];}
#define all(v) v.begin(), v.end()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ain(a, lb, rb) for (int ele = lb; ele <= rb; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define aout(a, lb, rb) {for (int ele = (lb); ele <= (rb); ele++) { if (ele > (lb)) cout << " "; cout << a[ele]; } cout << '\n';}
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
 
mt19937 rng(steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
 
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;



ll n, m, k, q, l, r, x, y, z;
ll a[1000005];
ll b[1000005];
ll c[1000005];
string s, t;
ll ans = 0;



void solve(int tc) {
  cin >> n;
  f1r(i, 1, n + 1) if (i % 3 && i % 5) ans += i;
  cout << ans << '\n';
}

int main() {
  send help

  // usaco("file");

  int tc;
  tc = 1;
  // cin >> tc;
  for (int t = 0; t < tc; t++) solve(t);
} 

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;
int a[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k, n;
	cin >> k >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
	    cin >> a[i];
	}
	int mx = 0;
	for (int i = 0; i < n - 1; i++) {
	    mx = max(mx, abs(a[i] - a[i + 1]));
	}
	mx = max(mx, k - a[n - 1] + a[0]);
	cout << k - mx << "\n";
 	return 0;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans;
    for(int i = 0;i <= 2*max(x,y);i++){
        if(i % 2 != 0)continue;
        ll p = c*i + a*(max(0,x-i/2)) + b*(max(0,y-i/2));
        //cout << p << endl;
        ans = min(ans,p);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3604
x,k,d=map(int,input().split())
x=abs(x)
dk=d*k
if dk <= x:
  print(x-dk)
  exit()

dv,md=divmod(x,d)  
k-=dv
if k%2==0:
  print(md)
else:
  print(abs(md-d))

Measured memory_bytes: 9176
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	string S;
	cin >> S;
 
	// 解法
	if (S.size()==2) cout << S << endl;
	else cout << S[2]<<S[1]<<S[0] << endl;
}


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

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////
int a[100005];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      memset(a,0,sizeof(a));
      int n,m;
      cin>>n>>m;
      int wa=0,ac=0;
      vector<pair<int,string>> v;
      int x;string s;
      REP(i,m)
      {
          cin>>x>>s;
          if(s=="AC")a[x]=1;
          v.push_back({x,s});
      }
      for(auto i:v)
      {
          if(a[i.first]==-1 || !a[i.first])
          continue;
          if(a[i.first])
          {
            if(i.second=="AC")
            {
                ac++;
                a[i.first]=-1;
            }
            else
            {
                wa++;
            }      
          }
      }
      cout<<ac<<" "<<wa;
  }
  return 0;
}

Measured memory_bytes: 6896
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>

using namespace std;

#define N 1001
#define M 20
#define mod 998244353
vector<int> adj[N];

int vis[N],par[N];

int depth[N];
int anc[N][M];

int outSize = 100000;

vector<int> ret;

void dfs(int node) {
  vis[node] = 1;
  for(int i=0;i<adj[node].size();++i) {
    int ch = adj[node][i];
    if(vis[ch] ) {
      if(depth[node]<=depth[ch]) continue;
      int diff = depth[node] - depth[ch];
      int tmp = node;
      for(int j= 0;j<M;++j) {
        if(diff&(1<<j)) {
          tmp = anc[tmp][j];
        }
      }
      if(tmp!=ch || outSize <=diff) {
        continue;
      }
      tmp = node;
      ret.clear();
      outSize = diff;
      while(true) {
        ret.push_back(tmp);
        if(tmp==ch) break;
        tmp = par[tmp];
      }

    } else {
      depth[ch] = depth[node] + 1;
      anc[ch][0] = node;
      for(int j=1;j<M;++j) {
        anc[ch][j] = anc[anc[ch][j-1]][j-1];
      }
      par[ch] = node;
      dfs(ch);
    }
  }
}
void solve() {
  int n,m;scanf("%d %d",&n,&m);
  for(int i=0;i<m;++i) {
    int a,b;scanf("%d %d",&a,&b);
    adj[a].push_back(b);
  }

  for(int st=1;st<=n;++st) {
    memset(vis,0,sizeof(vis));
    depth[st] = 0;
    for(int j=0;j<M;++j) anc[st][j] = 0;
    dfs(st);
  }
  if(outSize==100000) {
    printf("-1\n");
  } else {
    printf("%d\n",ret.size());
    for(int i=0;i<ret.size();++i) {
      printf("%d\n", ret[i]);
    }
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

ll mypow(ll n, ll m) {
    ll res = 1;
    n %= DIV;
    while (m) {
        if (m % 2) {
            res *= n;
            res %= DIV;
        }
        m /= 2;
        n *= n;
        n %= DIV;
    }
    return res;
}


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

    vector<int> cnt(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    /*
    for (int i = 0; i < N; i++) {
        
        cout << "cnt[i]=" << cnt[i] << endl;
    }
    */
    bool flag = true;
    if (N % 2 == 0) {
        for (int i = 0; i <= N - 1; i++) {
            if (i % 2 == 0) {
                if (cnt[i] > 0) {
                    flag = false;
                    break;
                }
            }
                
            else {
                if (cnt[i] != 2) {
                    flag = 0;
                    break;
                }
            }
        }
    }

    else {
        for (int i = 0; i <= N - 1; i++) {
            //cout << "i=" << i << endl;
            if (i % 2 == 1) {
                if (cnt[i] > 0) {
                    flag = false;
                    break;
                }
            }

            else {
             
                if ((i != 0 && cnt[i] != 2)|| (i == 0 && cnt[0] != 1)) {
                    //cout << cnt[i] << endl;
                    flag = 0;
                    break;
                }
            }
        }
    }
    if (flag)
        cout << mypow(2, N / 2) << endl;
    else
        cout << 0 << endl;

}

Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>

using namespace std;

typedef unsigned short us;
struct edge{
	int t;
	us c;
	edge(int t,us c):t(t),c(c){}
};

int n;
us INF=50000;
vector<edge> G[21];
map<int,map<int,us> > dp;
bool used[21];
us res=0;

void dfs(int v,int bit,us c){
	if(dp[bit][v]!=0 && dp[bit][v]<c)return;
	dp[bit][v]=c;
	if(bit==(1<<n)-1)res=min(c,res);
	else{
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			if(used[e.t])continue;
			int nbit=bit | (1<<e.t);
			dfs(e.t,nbit,e.c+c);
		}
	}
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(used,false,sizeof(used));
		res=INF;
		dp.clear();
		for(int i=0;i<n;i++)G[i].clear();
		for(int i=0;i<n-1;i++){
			int a,b;
			us c;
			scanf("%d%d%hd",&a,&b,&c);
			a--,b--;
			G[a].push_back(edge(b,c));
			G[b].push_back(edge(a,c));
		}
		/*
		for(int i=0;i<(1<<n);i++){
			for(int j=0;j<n;j++)dp[i][j]=INF;
		}
		*/
		int st=1;
		for(int i=1;i<n;i++){
			if(G[i].size()==1){
				st|=1<<i;
				used[i]=true;
			}
		}
		dfs(0,st,0);
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1124
#
# Yet I'm feeling like
# 	There is no better place than right by your side
# 		I had a little taste
# 			And I'll only spoil the party anyway
# 				'Cause all the girls are looking fine
# 					But you're the only one on my mind


import sys
import re
# inf = float("inf")
#sys.setrecursionlimit(1000000)

# abc='abcdefghijklmnopqrstuvwxyz'
# abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
# mod,MOD=1000000007,998244353
# vow=['a','e','i','o','u']
# dx,dy=[-1,1,0,0],[0,0,1,-1]

# from cmath import sqrt
# from collections import deque, Counter, OrderedDict,defaultdict
from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd,log10,atan,tan
# from bisect import bisect_left,bisect_right
# import numpy as np

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
Arr=get_array()
heapify(Arr)
while len(Arr)>1:
    x=heappop(Arr)
    y=heappop(Arr)
    z=(x+y)/2
    heappush(Arr,z)
print(Arr[-1])



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    vector<int> vec(N + 2);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i + 1);
    }
    vector<int> Sum1(N + 2);
    for(int i = 0;i < N;i++) {
        Sum1.at(i + 1) = Sum1.at(i) + abs(vec.at(i + 1) - vec.at(i));
    }
    vector<int> Sum2(N + 2);
    for(int i = N + 1;i >= 1;i--) {
        Sum2.at(i - 1) = Sum2.at(i) + abs(vec.at(i) - vec.at(i - 1));
    }
    for(int i = 1;i <= N;i++) {
        cout << Sum1.at(i - 1) + Sum2.at(i + 1) + abs(vec.at(i + 1) - vec.at(i - 1)) << endl; 
    }
}

Measured memory_bytes: 2432
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from collections import Counter

def main():
    n = II()
    vv = MII()
    ee = Counter(vv[0::2])
    oo = Counter(vv[1::2])
    minv = 10**5
    ee1 = ee.most_common()[0]
    oo1 = oo.most_common()[0]
    if ee1[0] != oo1[0]:
        minv = min(minv, n - (ee1[1] + oo1[1]))
    else:
        ee2 = ee.most_common()[1] if len(ee) > 1 else (0, 0)
        oo2 = oo.most_common()[1] if len(oo) > 1 else (0, 0)
        minv = min(minv, n - (ee1[1] + oo2[1]))
        minv = min(minv, n - (ee2[1] + oo1[1]))
    print(minv)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
typedef pair<ld,ld> point;

const int N = 16;

ld dist[N][N];
point pt[N];
ld mst[(1<<N)];
ld dp[(1<<N)];
ld tot[N];
ld d(point x, point y)
{
	return sqrt((x.fi-y.fi)*(x.fi-y.fi) + (x.se-y.se)*(x.se-y.se));
}

struct DSU
{
	int S;
	
	struct node
	{
		int p; ll sum;
	};
	vector<node> dsu;
	
	DSU(int n)
	{
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}
	
	void reset(int n)
	{
		dsu.clear();
		S = n;
		for(int i = 0; i < n; i++)
		{
			node tmp;
			tmp.p = i; tmp.sum = 0;
			dsu.pb(tmp);
		}
	}
	
	int rt(int u)
	{
		if(dsu[u].p == u) return u;
		dsu[u].p = rt(dsu[u].p);
		return dsu[u].p;
	}
	
	void merge(int u, int v)
	{
		u = rt(u); v = rt(v);
		if(u == v) return ;
		if(rand()&1) swap(u, v);
		dsu[v].p = u;
		dsu[u].sum += dsu[v].sum;
	}
	
	bool sameset(int u, int v)
	{
		if(rt(u) == rt(v)) return true;
		return false;
	}
	
	ll getstat(int u)
	{
		return dsu[rt(u)].sum;
	}
};

int n; 

void calcmst(int mask)
{
	DSU dsu(15);
	vector<pair<ld,ii> > vec;
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			if(i==j) continue;
			if((mask&(1<<i))&&(mask&(1<<j)))
			{
				vec.pb(mp(dist[i][j],mp(i,j)));
			}
		}
	}
	sort(vec.begin(),vec.end());
	int cnt = __builtin_popcount(mask) - 1;
	ld ans = 0;
	for(int i = 0; i < vec.size(); i++)
	{
		//cerr<<"VEC : "<<vec[i].fi<<' '<<vec[i].se.fi<<' '<<vec[i].se.se<<'\n';
		if(dsu.sameset(vec[i].se.fi,vec[i].se.se))
		{
			continue;
		}
		cnt--;
		dsu.merge(vec[i].se.fi,vec[i].se.se);
		ans+=vec[i].fi;
	}
	assert(cnt==0);
	mst[mask] = ans;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin>>pt[i].fi>>pt[i].se>>tot[i];
		dp[(1<<i)] = tot[i];
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			dist[i][j] = d(pt[i],pt[j]);
			//cerr<<i<<' '<<j<<' '<<dist[i][j]<<'\n';
		}
	}
	for(int i = 1; i < (1<<n); i++) calcmst(i);
	mst[0] = 0;
	for(int i = 1; i < (1<<n); i++)
	{
		dp[i] = -mst[i];
		for(int j = 0; j < n; j++)
		{
			if(i&(1<<j)) dp[i]+=tot[j];
		}
		dp[i]/=ld(__builtin_popcount(i));
		//cerr<<i<<' '<<dp[i]<<' '<<mst[i]<<'\n';
		for(int j = i; j > 0; j = ((j-1)&i))
		{
			if(j == i) continue;
			dp[i] = max(dp[i], min(dp[j], dp[(i^j)]));
		}
	}
	cout<<fixed<<setprecision(12)<<dp[(1<<n) - 1]<<'\n';
}


Measured memory_bytes: 1408
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            //h/aであまりが生じないならそのまま、それ以外は1回足す
            
                if(a == b && a != c)
                    Console.WriteLine("Yes");
                else if(a == c && a != b)
                    Console.WriteLine("Yes");
                else if(b == c && b != a)
                    Console.WriteLine("Yes");
                else
                    Console.WriteLine("No");
            
            
        }
    }

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

using namespace std;

const int MAX_N = 100000;
int n;
int l[MAX_N+1], r[MAX_N+1];

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++) cin >> l[i] >> r[i];
  l[n] = r[n] = 0;

  sort(l, l+n+1, greater<int>());
  sort(r, r+n+1);

  uint64_t d = 0;
  for (int i = 0; i < n && l[i] > r[i]; i++)
    d += (l[i] - r[i]) * 2;

  cout << d << endl;

  return 0;
}


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

vector<int> bfs(vector<vector<int>> A,int r){
    int N = A.size();
    
    queue<int> Q;
    vector<bool> seen(N,false);
    vector<int> count(N,INF);
    vector<int> before(N-1,0);
    count[r] = 0;
    seen[r] = true;
    Q.push(r);
    while(Q.size()!=0){
        int now = Q.front();
        //cout << "#" << now+1 << " ";
        for(auto& e:A[now]){
            if(!seen[e]){
                before[e-1]=now+1;
                Q.push(e);
                seen[e] = true;
            }
            count[e] = min(count[now]+1,count[e]);
        }
        Q.pop();
    }
    return before;
}

int main()
{
    int V,E,a,b;
    cin >> V >> E;
    vector<vector<int>> A(V);
    bool possible = true;
    REP(i,E){
        cin >> a >> b;
        A[a-1].push_back(b-1);
        A[b-1].push_back(a-1);
    }
    REP(i,V){
        if(A[i].size()!=0){
            sort(A[i].begin(),A[i].end());
        }
    }
    vector<int> X = bfs(A,0);
    REP(i,V-1){
        if(X[i]==0)possible=false;
    }
    if(possible){
        cout << "Yes" << endl;
        REP(i,V-1)cout << X[i] << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 16408
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
//const long long MOD = 998244353;
long long MOD;
using namespace std;


int main(int argc, char* argv[])
{
    int n,m;
    scanf("%d%d", &n, &m);

    vector<vector<int> > g(n);
    int i;
    for(i=0; i<m; i++) {
        int a,b;
        scanf("%d%d", &a, &b); a--; b--;
        g[a].push_back(b);
    }

    double ans=INF;
    int p;
    for(p=0; p<n-1; p++) {
        vector<double> dp(n);
        for(i=n-1; i>=0; i--) {
            if(i==n-1) {
                dp[i]=0;
            }
            else {
                int siz=g[i].size();
                int k;
                double sum=0;
                double max=-1;
                for(k=0; k<siz; k++) {
                    sum+=dp[g[i][k]];
                    max=MAX(max,dp[g[i][k]]);
                }
                if(i==p) {
                    if(siz==1) {
                        dp[i]=sum/siz+1;
                    }
                    else {
                        dp[i]=(sum-max)/(siz-1)+1;
                    }
                }
                else {
                    dp[i]=sum/siz+1;
                }
            }
        }
        //printf("%.10lf\n", dp[0]);
        ans = MIN(ans, dp[0]);
    }
    printf("%.10lf\n", ans);
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>

#define inf  1000000007
#define ll long long
#define PA pair<int,int>
#define PPAP pair<int,pa>
#define  MP make_pair
#define  PB push_back

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int>a;
	for(int i=0;i<n;i++){
		int p;
		cin >> p;
		a.PB(p);
	}
	int ans=0;
	int x = 0;
	while(x<n+1){
		if(x+1==a[x]){
			ans++;
			x += 2;
		}else{
			x++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
#define fin(ans) cout << (ans) << endl
const int INF = 1<<30;
const ll MOD = 1000000007;

int main() {
  string s;
  int a=0;
  cin >> s;
  //cin >> s >> t >> u;
  if(s[0]=='7') a++;
  if(s[1]=='7') a++;
  if(s[2]=='7') a++;
  if(a>0) cout << "Yes" << endl;
  else cout<< "No" << endl; 
  
}

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

const ll INF = 1LL << 60;

// i: 何桁目
// j: N 未満か
// k: 0出ない数字が表れた回数
ll dp[110][2][100];

string S;
ll K;
int main() {
    cin >> S >> K;
    int N = S.size();

    dp[0][0][0] = 1;

    for (int i = 0; i < N; i++) {
        int D = S[i] - '0';
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k <= K; k++) {
                int target = 9;
                if (j == 0) target = D;
                for (int d = 0; d <= target; d++) {
                    int cnt = 0;
                    if (d != 0) cnt++;
                    dp[i + 1][j || (d < D)][k + cnt] += dp[i][j][k];
                }
            }
        }
    }

    ll ans = 0;
    ans += dp[N][0][K];
    ans += dp[N][1][K];
    cout << ans << endl;
}

Measured memory_bytes: 3760
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim S As String = NextString()
        Dim cnt As Integer

        For i As Integer = S.Length \ 2 - 1 To 1 Step -1
            If Mid(S, 1, i) = Mid(S, 1 + i, i) Then
                cnt = i * 2
                Exit For
            End If
        Next

        WriteLine(cnt)
    End Sub

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
import java.util.*;import java.io.*;import java.math.*;
public class Main{
  //↓見なくていいよ！ここから------------------------------------------
  static class InputIterator{
    ArrayList<String> inputLine = new ArrayList<String>(1024);
    int index = 0; int max;
    InputIterator(){
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      while(true){
        String read;
        try{
          read = br.readLine();
        }catch(IOException e){
          read = null;
        }
        if(read != null){
          inputLine.add(read);
        }else{
          break;
        }
      }
      max = inputLine.size();
    }
    boolean hasNext(){return (index < max);}
    String next(){
      if(hasNext()){
        String returnStr = inputLine.get(index);
        index++;
        return returnStr;
      }else{
        throw new IndexOutOfBoundsException("これ以上入力はないよ");
      }
    }
  }
  
  static InputIterator ii = new InputIterator();//リアクティブでは使えないので諦めてScanner使うこと
  static PrintWriter out = new PrintWriter(System.out);
  static void flush(){out.flush();}
  static void myout(Object t){out.println(t);}
  static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
  static String next(){return ii.next();}
  static int nextInt(){return Integer.parseInt(next());}
  static long nextLong(){return Long.parseLong(next());}
  static ArrayList<String> nextStrArray(){return myHanSpSplit(next());}
  static ArrayList<String> myHanSpSplit(String str){return new ArrayList<String>(Arrays.asList(str.split(" ")));}
  static ArrayList<String> nextCharArray(){return mySingleSplit(next());}
  static ArrayList<String> mySingleSplit(String str){return new ArrayList<String>(Arrays.asList(str.split("")));}
  static ArrayList<Integer> nextIntArray(){
    ArrayList<Integer> ret = new ArrayList<Integer>();
    ArrayList<String> input = nextStrArray();
    for(int i = 0; i < input.size(); i++){
      ret.add(Integer.parseInt(input.get(i)));
    }
    return ret;
  }
  static ArrayList<Long> nextLongArray(){
    ArrayList<Long> ret = new ArrayList<Long>();
    ArrayList<String> input = nextStrArray();
    for(int i = 0; i < input.size(); i++){
      ret.add(Long.parseLong(input.get(i)));
    }
    return ret;
  }
  static String kaigyoToStr(String[] list){return String.join("\n",list);}
  static String kaigyoToStr(ArrayList<String> list){return String.join("\n",list);}
  static String hanSpToStr(String[] list){return String.join(" ",list);}
  static String hanSpToStr(ArrayList<String> list){return String.join(" ",list);}
  public static void main(String[] args){
    Runtime rt = Runtime.getRuntime();
    long mae = System.currentTimeMillis();
    solve();
    flush();
    long ato = System.currentTimeMillis();
    myerr("time : " + (ato - mae) + "ms");
    myerr("memory : " + ((rt.totalMemory() - rt.freeMemory()) / 1024) + "KB");
  }
  //↑見なくていいよ！ここまで------------------------------------------
  static void solve(){//ここがメイン関数代わり
	long N = nextLong();
	myout(N * (N - 1) / 2);
  }
  //Method addition frame start

  //Method addition frame end
}


Measured memory_bytes: 36884
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <limits>

using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;


int main(){
   ull a, b, c;
   cin >> a >> b >> c;
   // cout << (c*c+a*a+b*b-2*a*c-2*b*c+2*a*b) << endl;
   // cout << (c-a-b)*(c-a-b) << endl;
   ll d = (c-a-b);
   if(d > 0 && (d*d > 4*a*b)){
      cout << "Yes" << endl;
   }
   else{
      cout << "No" << endl;
   }
}

// 1_000_000_000 1_000_000_000 1_000_000_000

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

int main(){
  int k,x;
  cin >> k >> x;
  int start, end;
  start = x-k+1;
  end = x+k-1;
  
  if(start < -1000000){
    start = -1000000;
  }
  if(end > 1000000){
    end = 1000000;
  }
  for(int i=start; i<end+1; i++){
    cout << i << " ";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
string t;
int s[4][4005],a[4005];
int n,i,j,k;
ll ans;
int main()
{
	cin>>n>>t;
	for(int i=1;i<=n;i++)
	{
		if(t[i-1]=='R') a[i]=0;
		if(t[i-1]=='G') a[i]=1;
		if(t[i-1]=='B') a[i]=2;
    }
    for(int i=1;i<=n;i++)
    {
    	for(int j=0;j<3;j++) s[j][i]=s[j][i-1];
    	s[a[i]][i]=s[a[i]][i-1]+1;
	}
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++)
	{
		if(a[i]==a[j]) continue;
		ans+= s[3-a[i]-a[j]][n]-s[3-a[i]-a[j]][j];
		if(2*j-i<=n&&a[2*j-i]==3-a[i]-a[j]) ans--;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 3696
#include<stdio.h>

int main(void){
	int a[3],i,j;

	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	for(i=0;i<2;i++){
		for(j=i;j<3;j++){
			if(a[i]<a[j]){
				a[i]^=a[j]^=a[i]^=a[j];
			}
		}
	}

	i=a[1]-a[2];
	j=0;
	if(i%2==1){
		j++;	
		a[0]++;
		a[2]++;
	}
	j+=i/2+a[0]-a[1];
	printf("%d\n",j);
	return 0;
}


Measured memory_bytes: 128
from collections import Counter

N = int(input())
graph =[[] for _ in range(N + 1)]
visited = [None] * (N + 1)

for _ in range(N - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

v = 1
adv_v = N
update = True
labels = [0, 1]
vs = [v, adv_v]
prev_vs = [-1, -1]
visited[1] = 0
visited[N] = 1
while update:
    update = False
    next_cand = []

    for label, v, prev_v in zip(labels, vs, prev_vs):
        for next_v in graph[v]:
            if next_v == prev_v:
                continue
            if (visited[next_v] is None):
                update = True
                next_cand.append((next_v, label, v))

    vs = []
    labels = []
    prev_vs = []
    for next_v, label, prev_v in next_cand:
        if visited[next_v] is None:
            visited[next_v] = label
            vs.append(next_v)
            prev_vs.append(prev_v)
            labels.append(label)


c = Counter(visited)
if c[0] > c[1]:
    print("Fennec")
else:
    print("Snuke")


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

void solve() {

}

int main() {
  ll n,k;
  cin >> n >> k;
  cout << min(n,min(n % k,k-(n%k))) << endl;

  
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int N = Integer.parseInt(W);
		Data[] data = new Data[N];
		int ans = 1;
		for(int i=0;i<N;i++){
			W = in.readLine();

			String[] Ws = W.split(" ");
			int[] robo = new int[2];

			robo[0] = Integer.parseInt(Ws[0]);
			robo[1] = Integer.parseInt(Ws[1]);
			Data d = new Data(robo[0],robo[1]);
			data[i]=d;
		}

		//重複度と重複しているロボの記録
		Arrays.sort(data, new Comparator<Data>() {
            public int compare(Data d1, Data d2) {
                return d1.ed - d2.ed;
            }
        });

		int last = 0;
		for(int i=1;i<N;i++){
			if(data[last].ed <=data[i].st){
				last=i;
				ans++;
			}
		}
		System.out.println(ans);



	}

	public static class Data implements Comparable<Data>{
		public int X =0;
		public int L =0;
		public int C =0;

		public int st;
		public int ed;

		public int dist ;
		public ArrayList<Data> robo = new ArrayList<Data> ();

		public Data(int X,int L){
			this.X=X;
			this.L=L;
			C=0;
			st = Math.max(0, X-L);
			ed = Math.min(1000000000, X+L);
			dist = ed-st;
		}

		@Override
		public int compareTo(Data o) {

			return o.C - this.C;
		}

	}

}


Measured memory_bytes: 51620
#include<stdio.h>


int main()
{
	int n, x, counts;
	
	while(scanf("%d %d", &n, &x))
	{
		counts = 0;
		if(n == 0 && x == 0)break;
		for(int i = 1; i < n-1;i++)
		{
			for(int j = i + 1; j < n; j++)
			{
				for(int k = j + 1; k < n+1; k++)
				{
					if(i + j + k == x)
					{
						counts++;
					}
				}
			}
		}
		printf("%d\n", counts);
	}
	

}


Measured memory_bytes: 2720
// AOJ 1172
#include<iostream>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

const int NMAX = 123500;
bool p[2 * NMAX];
int accp[2 * NMAX];

void sieve() {
  p[0] = p[1] = true;
  REP(i, NMAX) {
    if (p[i]) continue;
    int j = 2 * i;
    while (j < 2 * NMAX) {
      p[j] = true;
      j += i;
    }
  }
}

void accumulate() {
  for (int i = 2; i < 2 * NMAX; i++) {
    accp[i] = accp[i - 1] + (p[i] ? 0 : 1);
  }
}

int main() {
  sieve();
  accumulate();
  int n;
  while (cin >> n and n) {
    cout << accp[2 * n] - accp[n] << endl;
  }
}

Measured memory_bytes: 2364
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
S = input()
Q = INT()
q = deque(S)
flg = 1
for _ in range(Q):
	Que = input().split()
	if Que[0] == "1":
		flg *= -1
	else:
		_, F, C = Que
		if any(int(F)*flg == x for x in [2, -1]):
			q.append(C)
		else:
			q.appendleft(C)
if flg == 1:
	print(*q, sep = "")
else:
	print(*list(q)[::-1], sep = "")

Measured memory_bytes: 14160
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string str;
  cin>>str;
  int l=str.length();
  int c=0;
  if(l==6)
  {
    for(int i=0;i<6;i++)
    {
      if(str[i]>=97 && str[i]<=122)
      {
        c++;
      }
      if(c==6)
      {
        if(str[2]==str[3] && str[4]==str[5])
        {
          cout<<"Yes"<<"\n";
        }
        else
          cout<<"No"<<"\n";
      }
    }
  }
  return 0;
}
      
        


Measured memory_bytes: 256