akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int n;
vector<string> ans;
string res;
vint bit;


void dfs(int x, int d) {
    if (x == n) {
        ans.PB(res);
        return;
    }
    if (bit[x] == 1) {
        res[x] = 'a'+d;
        return dfs(x+1, d+1);
    }
    rep(i, d) {
        res[x] = 'a'+i;
        dfs(x+1, d);
    }
}

void mainmain(){
    cin >> n;

    bit = vint(n);
    rep(i, 1, 1<<n) {
        res = string(n, 'a');
        rep(j, n) {
            if ((i & (1 << j))) {
                bit[j] = 1;
            }
            else {
                bit[j] = 0;
            }
        }

        dfs(0, 0);
    }

    sort(ALL(ans));
    unique(ALL(ans));

    rep(i, ans.size()) {
        cout << ans[i] << endl;
    }
}


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

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

int main() {
  int n,k;
  cin >> n >> k;
  int ans=0;
  for(int i=0;i<n;i++) {
    int x;
    cin >> x;
    int ma= min(x,k-x);
    ans = ans+ma*2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def up(num):
    if num%10 ==0:
        return num
    else:
        return (num//10+1)*10 

arr = []
mod = []

for i in range(5):
    arr.append(int(input()))
    m = 10 if arr[i]%10==0 else  arr[i]%10
    mod.append(m)

index = mod.index(min(mod))
last = arr.pop(index)
sum = sum(map(up,arr))+last
print(sum)

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

using namespace std;

#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ull unsigned long long int

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO;

	int n, m;
	cin >> n >> m;
	
	cout << (m-n)*(m-n+1) / 2 - m;
}


Measured memory_bytes: 3620
public class Main {
	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		var a = sc.nextInt();
		for(int i=0;i<=10;i++) {
			if(a<=i*1000) {
				System.out.println(i*1000-a);
				break;
			}
		}
	}
}


Measured memory_bytes: 35684
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    long long N;cin>>N;
    bool is=N%2==0?false:true;
    // vector<long long> ans;
    deque<long long> ans;
    REP(i,N){
        long long s;cin>>s;
        if(is){
            // ans.insert(ans.begin(),s);
            ans.push_front(s);
            is=false;
        } else {
            // ans.push_back(s);
            ans.push_back(s);
            is=true;
        }
    }
    for_each(ans.begin(),ans.end(),[](long long x){
        cout<<x<<" ";
    });
    cout<<endl;
}

Measured memory_bytes: 3840
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

#define fastio                              ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
#define read                                freopen("input.txt", "r", stdin);
#define write                               freopen("output.txt", "w", stdout);
#define nl                                  '\n'
#define mem(ara,n)                          memset(ara,n,sizeof ara)
#define debug(x)                            cerr << #x << " = " << x << nl

#define ll                                  long long
#define ull                                 unsigned long long
#define vi                                  vector<int>
#define pb                                  push_back
#define vpii                                vector<pair<int, int>>
#define vpll                                vector<pair<ll, ll>>
#define mp                                  make_pair
#define ff                                  first
#define ss                                  second
#define all(v)                              v.begin(), v.end()
#define rsort(v)                            sort(v.rbegin(), v.rend())

using namespace std;

const double pi = 2*acos(0.0);

int main(){
    //fastio;
    ll r;
    cin >> r;
    cout << fixed << setprecision(10) << 2*pi*r << nl;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N;
	cin >> N;
	vector<int> X(N);
	vector<int> Y(N);
	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		X[i] = tmp;
		Y[i] = tmp;
	}
	sort(all(Y));
	int M1 = Y[N/2-1];
	int M2 = Y[N/2];
	for (int i = 0; i < N; i++)
	{
		if (X[i] <= M1)
			cout << M2 << endl;
		else
			cout << M1 << endl;
	}
}


Measured memory_bytes: 3712
#include <stdio.h>

int main(void)
{
  int n, m;
  char i, j, ch, buf, conv[100][2];

  for(;;) {
    scanf("%d", &n);
    if (!n) break;
    for (i = 0; i < n; i++)
      scanf(" %c %c", &conv[i][0], &conv[i][1]);
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf(" %c", &ch);
      for (j = 0; j < n; j++)
        if (ch == conv[j][0]) {
          ch = conv[j][1];
          break;
        }
      printf("%c", ch);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <stdio.h>
int main(void)
{
  int n,k,diff;
  scanf("%d%d",&n,&k);
  if(n%k==0)
  {
    diff=0;
  }
  else
  {
    diff=1;
  }
  printf("%d\n",diff);
  return 0;
}


Measured memory_bytes: 128
import sys

if __name__ == "__main__":
    para_list = list(map(int, input().split()))
    n = para_list[0]
    m = para_list[1]
    c = para_list[2]

    B = list(map(int, input().split()))
    A = [[0]*m]*n
    for i in range(n):
        A[i] = list(map(int, input().split()))
    
    ans = 0
    for i in range(n):
        sum = 0
        for j in range(m):
            sum += A[i][j]*B[j]
        if sum+c > 0:
            ans += 1
    
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int gcd(int one, int two) {
	while (one != 0 && two != 0) {
		if (one > two) {
			one = one % two;

		}
		else {
			two = two % one;
		}

	}

	return std::max(one, two);

}
int main()
{

	int a = 0, b = 0, c=100, d = 0, e = 0, maxy = 0, max = 0, ans = 0, count = 0, size = 0, n = 0,m=0,x=0,y=0;
	int sa[10000] = {}, xwant[101] = {}, ywant[101] = {};
	int yoko = 0, tate = 0;
	std::string output,output2,output3,output4;
	char changer;
	char changer2;
	bool okada = false;

	cin >> b;
	for (int i = 0; i < 3; i++) {
		if (i == 0){a = b / 100; }
		if (i == 1) { a = b / 10 - b / 100 * 10;}
		if (i == 2) { a = b % 10; }
	
		if (a== 1) {
			e+=c*9;
		}
		else {
			e += c * 1;
		}
		c/=10 ;
		
	}

	std::cout << e << endl;
	}







Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

char s[110][110];

int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  int h, w;
  while (scanf("%d%d", &h, &w) == 2) {
    for (int i = 0; i < h; i++) {
      scanf("%s", s[i]);
    }

    vector<vector<int>> dp(h, vector<int>(w, 1e9));
    dp[h - 1][w - 1] = 0;

    for (int i = h - 1; i >= 0; i--) {
      for (int j = w - 1; j >= 0; j--) {
        if (i != h - 1) {
          dp[i][j] = min(dp[i][j], dp[i+1][j] + (s[i][j] != s[i+1][j]));
        }
        if (j != w - 1) {
          dp[i][j] = min(dp[i][j], dp[i][j+1] + (s[i][j] != s[i][j+1]));
        }
      }
    }

    int ans = dp[0][0];
    if (s[0][0] == '#') ans++;
    if (s[h - 1][w - 1] == '#') ans++;
    assert(ans % 2 == 0);
    ans /= 2;
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double Adeg = h * 30.0 + m * 6.0 / 12.0;
    double Bdeg = m * 6.0;
    
    double deg = abs(Adeg - Bdeg);
    if (deg > 180.0) deg = abs(deg - 360.0);
    
    if (deg == 0) cout << std::fixed << std::setprecision(20) << abs(a - b) << endl;
    else if (deg == 180) cout << std::fixed << std::setprecision(20) << a + b << endl;
    else{

        double rad = deg * PI / 180.0;

        double ans = sqrt(a * a + b * b - 2 * a * b * cos(rad));

        cout << std::fixed << std::setprecision(20) << ans << endl;
    }

    return 0;
    
}

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int K,N;
    cin >> K >> N;

    if(K%2==0){
        vector<int> ans;
        ans.push_back(K/2);
        rep(i,0,N-1) ans.push_back(K);
        rep(i,0,N){
            cout << ans[i];
            if(i==N-1) cout << endl;
            else cout << " ";
        }
        return;
    }

    vector<int> ans(N,(K+1)/2);
    rep(i,0,N/2){
        if(ans.back()==1){
            ans.pop_back();
            continue;
        }
        --ans.back();
        while(ans.size()<N) ans.push_back(K);
    }

    rep(i,0,ans.size()){
        cout << ans[i];
        if(i==N-1) cout << endl;
        else cout << " ";
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 3568
N = int(input())
r = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
for i in range(N):
    s = input().strip()
    if s in r: 
        r[s] += 1
print("AC x", r['AC'])
print("WA x", r['WA'])
print("TLE x", r['TLE'])
print("RE x", r['RE'])


Measured memory_bytes: 9196
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define dom 998244353
#define all(c) begin(c),end(c)
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
#define long long long
#define List vector
#define var auto
#define Count size()
#define Length size()
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

template <typename T>
struct SegTree {
	typedef function<T(T, T)> F;
	int n;
	F f;
	T exnum;
	vector<T> dat;

	SegTree(int n_, F f, T ex,
		vector<T> v = vector<T>()) {
		this->f = f;
		this->exnum = ex;
		init(n_);
		if (n_ == (int)v.size()) build(n_, v);
	}
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		dat.clear();
		dat.resize(2 * n - 1, exnum);
	}
	void build(int n_, vector<T> v) {
		for (int i = 0; i < n_; i++) dat[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--)
			dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	// 最下層に値の代入 0-indexed
	void update(int k, T x) {
		k += n - 1;
		dat[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	T query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return exnum;
		if (a <= l && r <= b) return dat[k];
		T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return f(vl, vr);
	}
	// return node[s, t] 閉区間クエリ 0-indexed
	T query(int a, int b) {
		b++;
		return query(a, b, 0, 0, n);
	}

	//デバッグ用
	T look(int k) {
		return dat[k + n - 1];
	}
	vector<T> items()
	{
		vector<T> ret(n);
		for (int i = 0; i < n; i++)
		{
			ret[i] = look(i);
		}
		return ret;
	}
};
//呼び出し方
//SegTree<int> rmq(n,
//	[](int a, int b) {return min(a, b); },
//	INT_MAX);
//SegTree<int> rsq(N,
//	[](int a, int b) {return a + b; },
//	0);


void solve()
{
	int N, Q;
	cin >> N >> Q;
	SegTree<int> rsq(N,
		[](int a, int b) {return a + b; },
		0);
	rep(i, Q)
	{
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0)
		{
			x--;
			int now = rsq.look(x);
			rsq.update(x, now + y);

		}
		else
		{
			x--; y--;
			cout << rsq.query(x, y) << endl;
		}
	}
}

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



Measured memory_bytes: 3828
N = int(input())
L = list(map(int,input().split()))

def count(L):
    if len(L) == 1:
        return L[0]
    if L == []:
        return 0
    if 0 in L:
        i = L.index(0)
        return count(L[:i]) + count(L[i+1:])
    else:
        m = min(L)
        L = list(map(lambda x:x-m,L))
        return m + count(L) 
print(count(L))


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		int N=1<<n;
		vi f(n),in(m);
		rep(i,n)cin>>f[i];
		rep(i,m)cin>>in[i];

		sort(all(in));
		vi dp(N,inf);
		dp[0]=0;
		rep(i,m){
			vi ndp(N,inf);
			rep(j,N){
				rep(l,n)if((j&1<<l)==0)dp[j|1<<l]=min(dp[j|1<<l],dp[j]);
				int sum=0;
				rep(k,n)if(j&1<<k)sum+=f[k];
				ndp[j]=dp[j]+abs(sum-in[i]);
			}
			dp=ndp;
		}
		int out=inf;
		rep(i,N)out=min(dp[i],out);
		cout<<out<<endl;
	}
}

Measured memory_bytes: 3240
import java.util.*

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val number: Int = scn.nextLine().toInt()

    val sameNumber: List<Int> = (1..9).toList().map { it -> (it.toString() + it.toString() + it.toString()).toInt() }.filter { it >= number }.toList()
    println(sameNumber[0])

}

Measured memory_bytes: 31272
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
    int n,k;
    cin>>n>>k;
    vector<int>h(n);
    for(int i=0;i<n;i++){
        cin>>h.at(i);
    }
    vector<int>dp(n,INF);
    dp[0]=0;
    for(int i=1;i<n;i++){
        for(int j=0;j<=k && i-j>=0;j++){
            chmin(dp[i],dp[i-j]+abs(h.at(i)-h.at(i-j)));
        }
    }
    cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
ll N, A, B;
vector<ll> H;
bool ok(ll x){
    ll cnt = 0;
    for(long long i=0; i<N; i++){
        lint y = H[i]-(x*B);
        if(y>0) cnt += (y+(A-B)-1)/(A-B);
    }
    return cnt <= x;
}
signed main(){
    cin>>N>>A>>B;
    ll d = A-B;
    H.resize(N);
    for(long long i=0; i<N; i++){
        cin >> H[i];
    }
    sort(RALL(H));
    ll ub = (H[0]+B-1)/B + 1;
    ll lb = 0; 
    ll res = 0;
    while(ub-lb>1){
        ll mid = (ub+lb)/2;
        if(ok(mid)) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
    return 0;
}

Measured memory_bytes: 1024
x, k, d = map(int, input().split())

# if x == 0:
#     if k % 2 == 0:
#         print(0)
#     else:
#         print(d)
if x >= 0:
    if x >= k * d:
        print(x - k * d)
    else:
        q, mod = divmod(x, d)
        k -= q
        if k % 2 == 0:
            print(mod)
        else:
            print(abs(mod - d))
elif x < 0:
    if abs(x) >= k * d:
        print(abs(x + k * d))
    else:
        q, mod = divmod(abs(x), d)
        k -= q
        if k % 2 == 0:
            print(mod)
        else:
            print(abs(mod - d))


Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x[6];
    for(int i=1;i<6;i++)cin >> x[i];
    for(int i=1;i<6;i++){
        if(x[i]==0){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3608
#include <complex>
#include <iostream>
#include <vector>

using namespace std;

int ans;

complex<double> MaxCoverCircle(vector<complex<double>> &p, double radius) {
  const int n = p.size();
  const double eps = 1e-6;
  int num_points = 1;
  complex<double> center_max(p[0]);

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      auto diff = p[i] - p[j];
      double dist = abs(diff);

      if (dist - 2*radius > eps) continue;

      auto mid = p[j] + (diff/2.0);
      auto mid_unit_normal = (diff*complex<double>(0, 1))/dist;
      auto mid_to_center = sqrt(radius - dist*dist/4.0)*mid_unit_normal;

      for (int k = 0; k < 2; ++k) {
        mid_to_center *= -1;
        auto center = mid + mid_to_center;

        int cnt = 0;
        for (int l = 0; l < n; ++l) {
          auto q = p[l] - center;
          if (q.real()*q.real() + q.imag()*q.imag() - radius*radius < eps) cnt++;
        }

        if (cnt > num_points) {
          num_points = cnt;
          center_max = center;
        }
      }
    }
  }
  ans = num_points;
  return center_max;
}

int main() {
  int n;
  while (cin >> n, n) {
    vector<complex<double>> p;
    p.reserve(n);
    for (int i = 0; i < n; ++i) {
      double x, y;
      cin >> x >> y;
      p.emplace_back(x, y);
    }
    MaxCoverCircle(p, 1);
    cout << ans << endl;
  }
}



Measured memory_bytes: 3212
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<ll> v(N);
    ll a;
    int cnt = 0;
    ll ans = 0;
    ll min_num = 1000000;
    for (int i = 0 ;i < N; i++) {
        scanf("%lld", &a);
        if (a < 0) {
            cnt++;
            a *= -1;
        }
        min_num = min(a, min_num);
        ans += a;
    }
    if (cnt % 2 == 1) {
        ans -= min_num * 2;
    }
    cout << ans << '\n';

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i<n;i++)
int main(){
int N,q=0;
cin >> N;
int l[N], r[N];
rep(i,N){cin >> l[i] >> r[i];
q += r[i]-l[i]+1;
}
cout << q << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class EAntennasOnTree {
public:
    vector<vector<int>> G;
    vector<int> in;

    int dfs(int v, int p) {
        int res = 0;
        int has = 0;
        for (auto to : G[v]) {
            if (to == p) continue;
            int tmp = dfs(to, v);
            if (tmp > 0) {
                has++;
            }
            res += tmp;
        }
        int req = p != -1 ? (int) G[v].size() - 2 : (int) G[v].size() - 1;
        return res + max(0LL, req - has);
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        G.resize(N);
        in.resize(N);
        REP(i, N - 1) {
            int x, y;
            cin >> x >> y;
            G[x].push_back(y);
            G[y].push_back(x);
            in[x]++, in[y]++;
        }

        bool ok = true;
        int root = -1;
        REP (i, N) {
            if (in[i] > 2) {
                ok = false;
                root = i;
            }
        }
        if (ok) {
            cout << 1 << endl;
            return;
        }

        int ans = dfs(root, -1);
        cout << ans << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    EAntennasOnTree solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 9600
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int ll
#define loop(__x, __start, __end) for(Int __x = __start; __x < __end; __x++)
#define loopdown(__x, __start, __end) for(Int __x = __start; __x > __end; __x--)
#define rep(__n) for(Int __x = 0; __x < __n; __x++)
#define span(__a,__x,__y) __a.begin()+__x,__a.begin()+__y
#define span_all(__a) __a.begin(),__a.end()
#define len(__x) (__x.size())
#define last(__x) (__x[__x.size()-1])

using namespace std;

struct Point {
  Int x, y;
  Point(Int x, Int y): x(x), y(y) {}
  Point(): x(0), y(0) {}

  Point operator + (Point v) { return Point(x + v.x, y + v.y); }
  Point operator - (Point v) { return Point(x - v.x, y - v.y); }
  bool operator == (const Point &v) const {
    return x == v.x && y == v.y;
  }
  bool operator< (const Point &p1) const {
    return x < p1.x && y < p1.y;
  }
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Point & v) {
  Int x, y;
  in >> x; in >> y; v.x = x; v.y = y;
  return in;
}

// Geometry

#define EPS 0.0000000001

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

Int N;
string A, B;
void solve(string& a, string& b);

void input() {
  cin >> N;
  rep(N) {
    cin >> A >> B;
    solve(A, B);
  }
}

vector<vector<Int> > dp(1001, vector<Int>(1001, -1));

Int solveRec(Int x = 0, Int y = 0) {
  if (x == A.size() || y == B.size()) return 0; // どちらかが終了したらもう共通はありえない
  Int &cache = dp.at(x).at(y);
  if (~cache) return cache;
  Int count = max(
    solveRec(x, y+1),
    solveRec(x+1, y)
  );
  if (A.at(x) == B.at(y)) {
    count = max(count, 1 + solveRec(x+1, y+1));
  }
  cache = count;
  return count;
}

void initDP(Int x_, Int y_) {
  loop(x,0,x_) {
    loop(y,0,y_) {
      dp.at(x).at(y) = -1;
    }
  }
}

void solve(string& a, string& b) {
  initDP(a.size(), b.size());
  cout<< solveRec() << endl;
}

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



Measured memory_bytes: 10656
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        int Y = scan.nextInt();
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        List<Long> p = new ArrayList<>();
        List<Long> q = new ArrayList<>();
        List<Long> r = new ArrayList<>();
        PriorityQueue<Integer> q1 = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < A; i++) {
            q1.add(scan.nextInt());
        }
        PriorityQueue<Integer> q2 = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < B; i++) {
            q2.add(scan.nextInt());
        }
        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());
        for (int i = 0; i < X; i++) {
            queue.add(q1.poll());
        }
        for (int i = 0; i < Y; i++) {
            queue.add(q2.poll());
        }
        for (int i = 0; i < C; i++) {
            queue.add(scan.nextInt());
        }
        long ans = 0;
        for (int i = 0; i < X + Y; i++) {
            ans += queue.poll();
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 98860
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  ll ans = 0;
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == 0) {
      ans += sum / 2;
      sum = 0;
    } else {
      sum += a[i];
    }
  }
  ans += sum / 2;

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl


signed main(void){
    int N,X,now=0;
    int Ans=0;
    int L[114]={};
    cin >> N >> X;
    REP(i,N){
        cin >> L[i];
    }
    REP(i,N+1){
        if(now<=X)Ans++;
        now+=L[i];
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 256
while 0<n=gets.to_i
r=[0]*(n/2)
a=(1..n-1).map{|i|i**2%n}.uniq.sort
a.each{|i|a.each{|j|i>j||break;d=i<j ?j-i :i-j;r[d>n/2?n-d-1:d-1]+=1}}
puts r.map{|i|i*2}
end

Measured memory_bytes: 6500
def main():
    h,n,*t=map(int,open(0).read().split())
    d=[0]+[10**18]*h
    for a,b in zip(*[iter(t)]*2):
        for j in range(h+1):
            k=j-a
            if k<0:k=0
            c=d[k]+b
            if c<d[j]:d[j]=c
    print(d[h])
main()

Measured memory_bytes: 3572
h,w,k=map(int,input().split())
c=list()
for i in range(h):
  d=list(input())
  c.append(d)


num_h = 2**h-1
num_w = 2**w-1
result = 0
for i in range(num_h):
  for j in range(num_w):
    tmp = 0
    for row in range(h):
      for col in range(w):
        if (i >> row) & 1 == 1:
          continue
        if (j >> col) & 1 == 1:
          continue
        if c[row][col] == '#':
          tmp += 1
    if tmp == k:
      result += 1

print(int(result))

Measured memory_bytes: 9188
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll kk;
    cin>>kk;
    ll ans=0;
    for(ll i=1;i<=kk;i++){
        for(ll j=1;j<=kk;j++){
            for(ll k=1;k<=kk;k++){
                ans+=__gcd(__gcd(i,j),k);
            }
        }
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 3648
#include "bits/stdc++.h"

using namespace std;

using u32 = uint32_t;
using u64 = uint64_t;
using i64 = int64_t;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= a; i--)
#define RF0(i,b) RFO(i,0,b)
#define F first
#define S second
#define ADD(a,b) (((u64)a + b)%MOD)
#define MUL(a,b) (((u64)a * b)%MOD)

constexpr int MOD = 998244353;

i64 strictSqrt(i64 n) {
  i64 r = std::sqrt(n);
  i64 d = abs(n - r * r);
  i64 d2;

  while (d2 = abs(n - (r + 1) * (r + 1)) < d) {
    r++;
    d = d2;
  }
  while (d2 = abs(n - (r - 1) * (r - 1)) < d) {
    r--;
    d = d2;
  }
  return r;
}

template < typename T >
constexpr T sqrt(T s)
{
  T x = s / 2.0;
  T prev = 0.0;

  while (x != prev)
  {
    prev = x;
    x = (x + s / x) / 2.0;
  }
  return x;
}

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

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

  // a + 2sqrt(ab) + b < c

  bool judge = (long double)a + b + 2 * sqrt<long double>((i64)a * b) < c;

  cout << (judge ? "Yes" : "No");
}


Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
        x: String,
    }

    let bp = x.match_indices('1').count() as u64;

    let p = if bp == 1 { vec![2, 1] } else { vec![bp + 1, bp - 1] };

    let xr: Vec<char> = x.chars().rev().collect();

    let mut xv = if xr[0] == '1' { vec![1; 2] } else { vec![0; 2] };

    let mut pows = vec![vec![1, 1]; n];

    for i in 1..n {
        for j in 0..=1 {
            pows[i][j] = (pows[i - 1][j] * 2) % p[j];
            if xr[i] == '1' {
                xv[j] += pows[i][j];
                xv[j] %= p[j];
            }
        }
    }

    for i in (0..n).rev() {
        if bp == 1 && xr[i] == '1' {
            println!("0");
        } else {
            let xi = if xr[i] == '0' {
                (xv[0] + pows[i][0]) % p[0]
            } else {
                let p = if xv[1] >= pows[i][1] { 0 } else { p[1] };
                xv[1] + p - pows[i][1]
            };
            println!("{}", 1 + pop_pop_count(xi));
        }
    }
}

fn pop_pop_count(mut v: u64) -> u64 {
    if v == 1 {
        1
    } else {
        let mut r = 0;
        while v > 0 {
            v %= v.count_ones() as u64;
            r += 1;
        }
        r
    }
}


Measured memory_bytes: 14096
n, m, k = [int(i) for i in input().split()]
mod = 998244353
kkai = [1]
for i in range(1, n + 10):
    kkai.append(kkai[-1] * i % mod)


def kai(x, p=mod):
    return kkai[x]


def comb(a, b, p=mod):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a, p)
    c *= pow(kai(b, p), p - 2, p)
    c *= pow(kai(a - b, p), p - 2, p)
    return c % p


ans = m * pow(m-1, n-1, mod)
for i in range(1, k+1):
    j = comb(n - 1, i) * m * pow(m - 1, n - i - 1, mod)
    ans += j
    ans %= mod
print(ans % mod)


Measured memory_bytes: 81012
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double ldb;

int main(void)
{
	ldb pi2 = 6.28318530717958623200;
	int r;
	scanf("%d",&r);
	printf("%.20lf",(double)(pi2*r));
	return 0;
}

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

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

    std::vector<std::string> S(N);
    for (auto& s : S) {
        std::cin >> s;
    }

    int M;
    std::cin >> M;

    std::vector<std::string> T(M);
    for (auto& t : T) {
        std::cin >> t;
    }

    int max_money = 0;
    for (auto& s : S) {
        int money = std::count(S.begin(), S.end(), s) - std::count(T.begin(), T.end(), s);
        max_money = std::max(money, max_money);
    }
    std::cout << max_money << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    vector<double> sum(n);
    rep(i,n){
        cin>>sum[i];
    }
    sort(sum.begin(),sum.end());
    double ans=(sum[0]+sum[1])/2.0;

    for(int j=2;j<n;j++){
        ans+=sum[j];
        ans/=2.0;

    }
    cout<<ans<<endl;





    return 0;
}


Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val N = nextInt()
    val P = listOfInt(-1).toIntArray()
    var ans = 0
    fun swap(n: Int) {
        val w = P[n]
        P[n] = P[n + 1]
        P[n + 1] = w
    }
    for (n in 0 until N - 1) {
        if (P[n] == n) {
            ans += 1
            swap(n)
        }
    }
    if (P[N - 1] == N - 1) ans += 1
    println(ans)
}
//49998
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(D: Int = 0) = listOfString().map { Integer.parseInt(it) + D }
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }


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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

signed main() {
    string S;
    cin >> S;

    int cnt = 0;
    REP(i, S.size()) {
        if (S[i] == 'x') cnt++;
    }

    string ans = cnt <= 7 ? "YES" : "NO";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val arr: Array<String> = Array(2) {
        readLine()!!
    }
    val line1 = arr[0]!!.split(" ")
    val line2 = arr[1]!!.split(" ")
    

    val monsterLife: Int = line1[0]!!.toInt()
    val wazaNum = line1[1]
    
    var total: Int = 0
    for (item in line2) {
        total = total + item!!.toInt()
    }
    
    print(when {
        monsterLife > total -> "No"
        else -> "Yes"
    })
}

Measured memory_bytes: 49704
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int x = sc.nextInt();
    int ans = 0;
    ArrayList<Integer> list = new ArrayList<Integer>();

    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }

    list.sort(null);

    for (int i = 0; i < n; i++) {
      int a = list.get(i);
      if (x >= a) {
        ans++;
        x -= a;
      } else {
        System.out.println(ans);
        return;
      }
    }

    if (x == 0) {
      System.out.println(n);
    } else {
      System.out.println(n - 1);
    }

  }
}

Measured memory_bytes: 35884
#include <bits/stdc++.h>
#define fi first
#define se second
#define lson (k<<1)
#define rson (k<<1|1)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl
#define rep(i,s,t) for(int i=(s),_t=(t);i<_t;++i)
#define per(i,s,t) for(int i=(t)-1,_s=(s);i>=_s;--i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=(int)1e9+7;
template<class T>void rd(T &x)
{
	x=0;
	static char c;
	while(c=getchar(),c<48);
	do x=x*10+(c^48);
		while(c=getchar(),c>47);
}
void ptn(ll x)
{
	static char stk[65];
	int tp=0;
	for(;x;x/=10)stk[tp++]=x%10^48;
	per(i,0,tp)putchar(stk[i]);
	putchar('\n');
}
template<class T>inline void Max(T &a,T b)
{
	if(b>a)a=b;
}
template<class T>inline void Min(T &a,T b)
{
	if(b<a)a=b;
}
// EOT


const int N=(int)1e5+5;

int par[N];
pii dat[N];

int get_root(int u)
{
	return par[u]==u?u:par[u]=get_root(par[u]);
}

pii val_x[N],val_y[N];

int main()
{
	int n;
	cin>>n;
	static pii disc_x[N],disc_y[N];
	int tot_x=0,tot_y=0;
	rep(i,0,n)
	{
		rd(dat[i].fi),rd(dat[i].se);
		disc_x[tot_x++]=pii(dat[i].fi,i);
		disc_y[tot_y++]=pii(dat[i].se,i);
	}
	sort(disc_x,disc_x+tot_x);
	sort(disc_y,disc_y+tot_y);
	ll ans=0;
	static int refer_x[N],refer_y[N];
	rep(i,0,n)
	{
		refer_x[i]=disc_x[i].se;
		refer_y[i]=disc_y[i].se;
	}
	rep(i,0,tot_x-1)val_x[i]=pii(dat[refer_x[i+1]].fi-dat[refer_x[i]].fi,i);
	rep(i,0,tot_y-1)val_y[i]=pii(dat[refer_y[i+1]].se-dat[refer_y[i]].se,i);
	sort(val_x,val_x+tot_x-1);
	sort(val_y,val_y+tot_y-1);
	rep(i,0,n)par[i]=i;
	int i=0,j=0;
	for(;i<tot_x-1&&j<tot_y-1;)
	{
		if(val_x[i]<val_y[j])
		{
			if(get_root(refer_x[val_x[i].se])!=get_root(refer_x[val_x[i].se+1]))
			{
				ans+=val_x[i].fi;
				par[get_root(refer_x[val_x[i].se])]=get_root(refer_x[val_x[i].se+1]);
			}
			++i;
		}
		else
		{
			if(get_root(refer_y[val_y[j].se])!=get_root(refer_y[val_y[j].se+1]))
			{
				ans+=val_y[j].fi;
				par[get_root(refer_y[val_y[j].se])]=get_root(refer_y[val_y[j].se+1]);
			}
			++j;
		}
	}
	while(i<tot_x-1)
	{
		if(get_root(refer_x[val_x[i].se])!=get_root(refer_x[val_x[i].se+1]))
		{
			ans+=val_x[i].fi;
			par[get_root(refer_x[val_x[i].se])]=get_root(refer_x[val_x[i].se+1]);
		}
		++i;
	}
	while(j<tot_y-1)
	{
		if(get_root(refer_y[val_y[j].se])!=get_root(refer_y[val_y[j].se+1]))
		{
			ans+=val_y[j].fi;
			par[get_root(refer_y[val_y[j].se])]=get_root(refer_y[val_y[j].se+1]);
		}
		++j;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6144
import itertools

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

R = []
G = []
B = []

RGBs = list(itertools.permutations(['R', 'G', 'B'], 3))
for i, s in enumerate(S):
  if s == 'R': R.append(i)
  if s == 'G': G.append(i)
  if s == 'B': B.append(i)
out = len(R) * len(G) * len(B)
for i in range(1, N):
  for j in range(N-i*2):
    if (S[j], S[j+i], S[j+i*2]) in RGBs:
      out -= 1
print(out)

Measured memory_bytes: 9324
#include<bits/stdc++.h>
using namespace std;
const int DN=1e5+5;
long long n,w,dp[105][DN],f,val,ma;
int main()
{
    cin>>n>>w;
    for(int i=1;i<=n;i++)
    {
        cin>>f>>val;
        for(int j=0;j<=w;j++)
            dp[i][j]=dp[i-1][j];
        for(int j=0;j<=w-f;j++)
            dp[i][j+f]=max(dp[i][j+f],dp[i-1][j]+val);
    }
    for(int j=0;j<=w;j++)
        ma=max(ma,dp[n][j]);
    cout<<ma;
}


Measured memory_bytes: 79488
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    bool ok = true;
    rep(i, n) {
        ll a;
        cin >> a;
        if(a%2 == 0) {
            if(a%3 != 0 && a%5 != 0) {
                ok = false;
            }
        }
    }

    if(ok) {
        out("APPROVED");
    }
    else {
        out("DENIED");
    }

    re0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll a(n),b(n),c(n);
  rep(i,n) cin>>a[i]>>b[i]>>c[i];
  vvll dp(3,vll(n));
  dp[0][0]=a[0];
  dp[1][0]=b[0];
  dp[2][0]=c[0];
  for(int i=1;i<n;i++){
    dp[0][i]=max(dp[1][i-1]+a[i],dp[2][i-1]+a[i]);
    dp[1][i]=max(dp[0][i-1]+b[i],dp[2][i-1]+b[i]);
    dp[2][i]=max(dp[0][i-1]+c[i],dp[1][i-1]+c[i]);
  }
  COUT(max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1])));
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <queue>
#define INF 1e+18
#define int long long
using namespace std;

signed main(){
	int n,p;
	while(cin >> n >> p,n){
		int wan = p,cnt[50] = {},pos = 0;
		while(1){
			if(wan == 0){
				int win = 0,m;
				for(int i = 0;i < n;i++){
					if(cnt[i]){
						win++;
						m = i;
					}
				}
				if(win == 1){
					cout << m << endl;
					break;
				}
				wan += cnt[pos];
				cnt[pos] = 0;
			}else{
				wan--;
				cnt[pos]++;
			}
			pos = (pos + 1) % n;
		}
	}
	return 0;
}

Measured memory_bytes: 2988
/*
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
*/
#include <bits/stdc++.h>

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

int main()
{
    int n,m;
    ll a,b,ans = 0;
    cin >> n >> m;
    a = (n*(n-1))/2;
    b = (m*(m-1))/2;
    cout << a+b << endl;
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int32_t main(){
    
    int n,d;
    cin >> n >> d;
    int p = 0;
    int k = d*d;
    while(n--){
        int x,y;
        cin >> x >> y;
        int o = x*x+y*y;
        if(o <= k)
           p++;
    }
    cout << p << endl;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define int long long
using namespace std;
int h(int x){
    int ans=0;
    while(x%2==0){
        ans++;
        x/=2;
    }
    return ans;
}
signed main(){
    int n; cin>>n;
    vector<int> a(n); vector<int> half(n);
    for(int i=0; i<n; i++){cin>>a.at(i); half.at(i)=h(a.at(i));}
    sort(half.begin(),half.end());
    cout<<half.at(0)<<endl;
}

Measured memory_bytes: 256