akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
using P = pair<int, int>;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 998244353;
    const double ba_=3.14159265358979323846*2;
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    printf("%.12f\n",sqrt(a*a+b*b-2*a*b*cos(ba_*abs(h/12.0+m/720.0-m/60.0))));
}


Measured memory_bytes: 4148
n=int(input())
x=[None for i in range(n)]
y=[None for i in range(n)]
for i in range(n):
  x[i],y[i]=map(int,input().split())
ave=0
for i in range(n-1):
  for j in range(i+1,n):
    ave+=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
ave/=n/2
print(ave)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

bool simulate(vector<int>& w, int k, int P){
  if(P < w[w.size() - 1]) return false;
  int cnt = 1, sum = 0;
  for(int i = 0; i < w.size(); i++){
    if(sum + w[i] <= P){
      sum += w[i];
    }else{
      sum = w[i];
      cnt++;
    }
  }
  return cnt <= k;
}

int main(){
  int n, k, w_max = -1;
  cin >> n >> k;
  vector<int> w(n);
  for(int i = 0; i < n; i++){
    cin >> w[i];
    w_max = max(w_max, w[i]);
  }
  int l = w_max, r = 1000000005;
  while(r - l > 0){
    int P = (l + r) / 2;
    if(simulate(w, k, P)){
      r = P;
    }else{
      l = P + 1;
    }
  }
  cout << r << endl;
  return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll s;
    cin >> s;
    const ll MOD = 1e9 + 7;
    ll ans = 0;
    for(j = 1;j <= s;++j){
        if(3*j > s) break;
        ll ss = s - 3*j;

        int max_number = j - 1 + ss;
        int MOD = 1e9+7;
        
        vector<ll> fac(max_number+1,1);
        vector<ll> inv(max_number+1,1);
        vector<ll> finv(max_number+1,1);
        vector<ll> nCk(max_number+1,1);
        for(i = 2;i <= max_number;++i){
            inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
        }
        for(i = 1;i <= max_number;++i){
            fac.at(i) = fac.at(i-1)*i%MOD;
            finv.at(i) = finv.at(i-1)*inv.at(i)%MOD;
        }
        for(i = 1;i <= max_number;++i){
            nCk.at(i) = fac.at(max_number)*finv.at(i)%MOD*finv.at(max_number-i)%MOD;
        }
        ans += nCk.at(ss);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3668
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;

int main()
{
	int c[5][5];
	int vis = 0,a1,a2,a3,b1,b2,b3;
	for(int i = 1;i <= 3;i++)
		for(int j = 1;j <= 3;j++)
			scanf("%d",&c[i][j]);
	for(int i = 0;i <= MaxN;i++)
	{
		a1 = i;
		b1 = c[1][1]-a1;
		b2 = c[1][2]-a1;
		b3 = c[1][3]-a1;
		a2 = c[2][1]-b1;
		a3 = c[3][1]-b1;
		if(c[2][2]==b2+a2&&c[3][3] == b3+a3&&c[2][3]==a2+b3&&c[3][2]==a3+b2)
		{
			vis = 1;
			break;
		}
	}
	if(vis==1) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
D, N = map(int, input().split())
ans = 0
df = 0

if D == 0:
    df = 1
elif D == 1:
    df = 100**1
else:
    df = 100**2

if N < 100:
    ans = df * N
else:
    ans = df * (N+1)

print(ans)

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, x, d[200000];

LL f(int m) {
	LL sum = 0;
	inc(i, n) {
		int k = i / m;
		if(k == 0) { sum += 2 * d[i] + x; }
		sum += (2 * k + 3) * d[i] + x;
	}
	
	return sum;
}

int main() {
	cin >> n >> x;
	inc(i, n) { cin >> d[i]; }
	
	reverse(d, d + n);
	
	int l = 1, h = n;
	while(h - l >= 3) {
		int m1 = l + (h - l) / 3 * 1;
		int m2 = l + (h - l) / 3 * 2;
		if(f(m1) <= f(m2)) { h = m2; } else { l = m1; }
	}
	LL ans = f(l);
	incII(i, l, h) { setmin(ans, f(i)); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

#define MAX_H 500000

void maxHeapify(int*,int,int);
void buildMaxHeap(int*,int);
void swap(int*,int*);

int main(){
  int H,i,a[MAX_H];
  scanf("%d",&H);
  for (i = 0 ; i < H ; i++) {
    scanf("%d",&a[i]);
  }
  buildMaxHeap(a,H);
  for(i = 0 ; i < H ; i++){
    printf(" %d",a[i]);
  }
  printf("\n");
  return 0;
}

void maxHeapify(int *A,int i,int H){
  int l = i*2+1, r = i*2+2;
  int largest;
  if(l <= H && A[l] > A[i]){
    largest = l;
  }else{ largest = i; }

  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    swap(&A[i],&A[largest]);
    maxHeapify(A,largest,H);
  }
}

void buildMaxHeap(int *A,int H){
  int i;
  for(i = H/2 ; i >= 0 ; i--){
    maxHeapify(A,i,H);
  }
}

void swap(int *a,int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back


const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 1e5 + 20;
const int maxm = (int) 1e6 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

int n, m, a, b;

int mat[1003][1003];

void work()
{
    cin >>n >>m >>a >>b;

    string s(m, '1'), t(m, '1');

    for(int i = 0; i < m; i++)
    {
        if(i < a) s[i] ^= 1;
        else t[i] ^= 1;
    }

    for(int i = 0; i < b; i++) cout <<s <<endl;
    for(int i = b; i < n; i++) cout <<t <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    scanf("%d", &tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint n, X; cin >> n >> X;
  V<lint> b(n), l(n), u(n); for (int i = 0; i < n; ++i) cin >> b[i] >> l[i] >> u[i];
  V<> ord(n);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), [&](int i, int j) { return l[i] * b[i] + u[i] * (X - b[i]) > l[j] * b[j] + u[j] * (X - b[j]); });
  V<lint> c{0};
  for (int i : ord) c.push_back(c.back() + l[i] * b[i] + u[i] * (X - b[i]));
  lint o = 0;
  for (int i : ord) o -= l[i] * b[i];
  auto chk = [&](lint T) -> bool {
    lint q = T / X, r = T - q * X;
    lint mx = -1e18;
    for (int j = 0; j < n; ++j) {
      int i = ord[j];
      lint curr = o + l[i] * min(r, b[i]) + u[i] * max(r - b[i], 0LL);
      if (j < q) curr += c[j] + c[q + 1] - c[j + 1];
      else curr += c[q];
      mx = max(mx, curr);
    }
    return mx >= 0;
  };
  lint ng = -1, ok = n * X;
  while (ok - ng > 1) {
    lint mid = ng + ok >> 1;
    (chk(mid) ? ok : ng) = mid;
  }
  cout << ok << '\n';
}

Measured memory_bytes: 4216
#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

const int N = 1e5 + 5;

int n;
int a[N], b[N];

int get1()
{
	for(int i = 1; i <= n; i++)
	{
		if(i % 2)
			b[i] = 1;
		else
			b[i] = 100;
	}
	vector<int> vals, have;
	for(int i = 1; i <= n; i++)
	{
		int val = 0;
		if(i - 1 >= 1 && b[i] > b[i - 1])
			val++;
		else if(i - 1 >= 1)
			val--;
		if(i + 1 <= n && b[i] < b[i + 1])
			val--;
		else if(i + 1 <= n)
			val++;
		vals.push_back(val);
		have.push_back(a[i]);
	}
	sort(vals.rbegin(), vals.rend());
	sort(have.rbegin(), have.rend());
	//1 100 1 100
	int ans = 0;
	for(int i = 0; i < n; i++)
		ans += have[i] * vals[i];
	return ans;
}

int get2()
{
	for(int i = 1; i <= n; i++)
	{
		if(i % 2)
			b[i] = 100;
		else
			b[i] = 1;
	}
	vector<int> vals, have;
	for(int i = 1; i <= n; i++)
	{
		int val = 0;
		if(i - 1 >= 1 && b[i] > b[i - 1])
			val++;
		else if(i - 1 >= 1)
			val--;
		if(i + 1 <= n && b[i] < b[i + 1])
			val--;
		else if(i + 1 <= n)
			val++;
		vals.push_back(val);
		have.push_back(a[i]);
	}
	sort(vals.rbegin(), vals.rend());
	sort(have.rbegin(), have.rend());
	//1 100 1 100
	int ans = 0;
	for(int i = 0; i < n; i++)
		ans += have[i] * vals[i];
	return ans;
}


int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	int ans = max(get1(), get2());
	cout << ans;
	return 0;
}

Measured memory_bytes: 7800
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);

    int r=sc.nextInt();
    int g=sc.nextInt();
    int b=sc.nextInt();
    int k=r*100+g*10+b;
    if(k%4==0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
    sc.close();
  }
}



Measured memory_bytes: 25300
#include <iostream>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <ctype.h>

const int INF =100000000;

using namespace std;

int ans = 0;

int main(){

  for(int i = 0;i < 10;i++){
    int a ;
    cin >> a ;
    ans += a;
  }

  cout << ans << endl;
}


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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        sum += A[i];
    }
    ll prev = sum;
    for (int i = 1; i < N; i += 2) {
        prev -= 2 * A[i];
    }
    cout << prev;
    for (int i = 0; i < N-1; ++i) {
        prev = 2 * A[i] - prev;
        cout << ' ' << prev;
    }
    cout << endl;

}


Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll>A(N);
    rep(i,N){
        cin>>A[i];
    }

    ll ans = 0;
    ll now = A[0];
    rep2(i,N-1){
        if(A[i]<now){
            ans+=now-A[i];
        }else{
            now=A[i];
        }
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4788
#include<iostream>
#include<stdio.h>
using namespace std;
int main(void) {
	int a;
	int i;
	scanf("%d", &i);
	a = i / 100;
	if (i % 100 <= a * 5) {
		printf("1");
	}
	else {
		printf("0");
	}
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) (int)(a.size())
#define x first
#define y second
using namespace std;
const int MAXV = 405;
const int MAXT = 10005;
vector<pair<int, int> > g[MAXV];
int id[MAXT] , dst[MAXT] , Tmax , n , m , f[MAXV];
void inputG()
{
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int u, v, d; cin >> u >> v >> d;
		u--; v--;
		g[u].push_back({v, d});
		g[v].push_back({u, d});
	}
	for(int i = 0; i < n; i++) cin >> f[i];
}
void inputQueries()
{
	cin >> Tmax;
	memset(id , -1 , sizeof id);
	for(int i = 0; i < Tmax; i++) {
		int Nnew; cin >> Nnew;
		for(int j = 0; j < Nnew; j++) {
			cin >> id[i] >> dst[i];
		}
	}
}
vector<pair<int , int> > spanTree[MAXV];
int p[MAXV];
int find(int u)
{
	return p[u] = p[u] == u ? u : find(p[u]);
}
void unite(int u , int v , int c)
{
	int U = find(u) , V = find(v);
	if(U != V)
	{
		p[V] = U;
		spanTree[u].pb({v , c});
		spanTree[v].pb({u , c});
	}
}

void buildSpan()
{
	for(int u = 0; u < n; u++)p[u] = u;
	vector<pair<int , pair<int , int> > > edges;
	for(int u = 0; u < n; u++)
		for(auto v : g[u])
			if(u < v.x)
				edges.pb({v.y , {u , v.x}});
	sort(edges.begin() , edges.end());
	for(auto e : edges)
		unite(e.y.x , e.y.y , e.x);
}
vector<pair<int , int> > pathToRoot;
int cnt = 0;
vector<int> route;
void dfs(int u , int p = -1)
{
	cnt++;
	if(cnt % 100 == 0)
	{
		for(int idx = sz(pathToRoot) - 1; idx > 0; idx--)
		{
			int v = pathToRoot[idx - 1].x;
			for(int i = 0; i < pathToRoot[idx].y; i++)
				route.pb(v);
		}
		for(int idx = 0; idx < sz(pathToRoot) - 1; idx++)
		{
			int v = pathToRoot[idx + 1].x;
			for(int i = 0; i < pathToRoot[idx + 1].y; i++)
				route.pb(v);
		}
	}
	for(auto v : spanTree[u])
		if(v.x != p)
		{
			for(int i = 0; i < v.y; i++)
				route.pb(v.x);
			dfs(v.x , u);
			for(int i = 0; i < v.y; i++)
				route.pb(u);
		}
			
}
void findRoute()
{
	dfs(0);
}
void inputInfo()
{
	int nNew; cin >> nNew;
	for(int i = 0; i < nNew; i++)
	{
		int mem , kek;	cin >> mem >> kek;
	}
	int nPut; cin >> nPut;for(int i = 0; i < nPut; i++){int mem; cin >> mem;}
}
void inputRes()
{
	string verdict;cin >> verdict;
	if(verdict == "NG")	exit(0);
	int nAchieve;cin >> nAchieve;
	for(int i = 0; i < nAchieve; i++){int mem; cin >> mem;}
}
int main() {
	inputG();
	//inputQueries();
	
	buildSpan();
	findRoute();
	int cntStop = 0;
	cin >> Tmax;
	
	for(int i = 0; i < Tmax; i++)
	{
		inputInfo();
		if(i < cntStop)
			cout << -1 << endl;
		else
			cout << route[(i - cntStop) % sz(route)] + 1 << endl;
		inputRes();
	}
	return 0;
}


Measured memory_bytes: 1364
#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)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a,b;

int main(){
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << '\n';
}

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

int main(){
  int N, r, l, S;
  cin >> N;
  S=0;
  
  for(int i=0;i<N;i++){
    cin >> r >> l;
    S+=l-r+1;
  }
  
  cout << S << endl;
}

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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    ll a, b;
    cin >> a >> b;
    ll n = 10 * b;
    for(ll i = n; i<=n+9; i++) {
        ll curr = (2*i)/25;

        if(curr == a) {
            cout << i;
            return;
        }
    }
    cout << -1 ;
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

vector<pair<char, int>> rle(string s)
{
    vector<pair<char, int>> res;
    char c; int l;
    for (int i = 0; i < (int)s.length(); i++) {
        if (i == 0) {
            c = s[i]; l = 1;
        } else if (s[i] == c) {
            l++;
        } else {
            res.push_back({c, l});
            c = s[i]; l = 1;
        }
    }
    res.push_back({c, l});
    return res;
}

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

    string s; cin >> s;
    ll k; cin >> k;
    
    auto rs = rle(s);

    ll ans = 0;
    if (rs.size() == 1) {
        ans = (rs.front().second * k) / 2;
    } else {
        for (auto &r: rs) ans += r.second / 2;
        ans *= k;
        if (rs.front().first == rs.back().first && (rs.front().second & 1) && (rs.back().second & 1)) {
            ans += k - 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)

int main(void){
    ll K,N;
    ll dist=0;
    ll tmp_kankaku=0;
    ll max_kankaku=0;
    ll skip_posi=0;

    //標準入力
    cin >> K >> N;

    vector<int> house_posi(N);
    int house_kankaku[N];

    REP(i,N)
    {
        cin >> house_posi.at(i);
    }

    REP(i,N)
    {
        if(i==0)
        {
            //最初
            tmp_kankaku = house_posi.at(i) + ( K - house_posi.at(N-1) );
        }
        else
        {
            tmp_kankaku = house_posi.at(i) - house_posi.at(i-1);
        }
        
        if(tmp_kankaku > max_kankaku)
        {
            skip_posi = i;
            max_kankaku = tmp_kankaku;
        }
    }

    //cout << "skip_posi:" << skip_posi << endl;

    //家の位置は昇順ソート済
    //end-startを計算
    //ll temp = *(house_posi.end()-1) - *house_posi.begin();
    //cout << temp << endl;

    //end-startがK/2以下なら、最小経路になる
    // if( temp <= (K/2) )
    // {
    //     cout << temp << endl;
    //     return 0;
    // }

    //MAX-MINがK/2を超える場合、家の間隔が最も遠いところを通過しないように動く
    //最も遠いところskip_posi-1～skip_posiの間

    if(skip_posi == 0)
    {
        //最初と最後が一番長い場合
        //最初の家～最後の家のルート
        dist = ( *(house_posi.end()-1) - *(house_posi.begin()) );
    }
    else
    {
        //そのほかのルート
        //スキップ前までは通常経路
        dist += house_posi.at( skip_posi-1 );
        //スキップ後の部分
        dist += ( K - house_posi.at( skip_posi ) );
    }

    cout << dist << endl;
    return 0;
}

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


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(30)<<fixed;
	
	int n,d;
	cin>>n>>d;
	int x,y;
	int c=0;
	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		x*=x;
		y*=y;
		//cout<<x<<" "<<y<<endl;
		double d1=sqrt(x+y);
		//cout<<d1<<endl;
		if(d1<=d)
			c++;
	}
	cout<<c<<endl;
	return 0;
}





Measured memory_bytes: 3696
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

using ll = long long;
using VI = vector<int>;
using PI = pair<int, int>;
using VII = vector<PI>;

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
    int N, M;
    cin >> N >> M;
    int snum = 1 << N;
    const int INF = 1e9;
    VI dp(5000, INF);
    dp[0] = 0;
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        int C = 0;
        int c;
        rep(j, b) {
            cin >> c;
            C += 1 << (c - 1);
        }
        rep(j, snum) {
            int s = C | j;
            chmin(dp[s], dp[j]+a);
        }
    }
    cout << ((dp[snum-1] < INF) ? dp[snum-1] : -1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
	a = max(a,b);
}

void solve(){	
	int k, n;
	cin >> k >> n;
	vpi v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i].F;
		v[i].S = k - v[i].F;
	}
	/*
	for(int i = 0; i < n; i++){
		cout << v[i].F << " " << v[i].S << endl;
	}*/
	int l = n-1;
	int r = 1;
	ll ans = 0;
	while(l >= r){
		int left = (l == n-1) ? (v[l].S + v[0].F) : (v[l].S - v[l+1].S);
		int right = (v[r].F - v[r-1].F);
		if(left < right){
			ans += left;
			/*
			cout << "L -> " <<  v[l].S << endl;
			cout << "L -> " <<  v[l].S << endl;
			cout << endl;
			*/
			l--;
		}else{		
			ans += right;
			/*
			cout << "R -> " << v[r].F << endl;
			cout << "L -> " <<  v[l].S << endl;
			cout << endl;
			*/
			r++;
		}
	}
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    //int t; cin >> t;
    //while(t--) solve();
    //
    solve();
    return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var _sw = bufio.NewScanner(os.Stdin)

// issii
// issiiissii
// is_i_is_i_
func main() {
	var s []byte
	var k int
	fmt.Scan(&s)
	fmt.Scan(&k)

	var last byte
	var cnt int
	cnts := []int{}
	for _, c := range s {
		if c == last {
			cnt++
		} else {
			if last != 0 {
				cnts = append(cnts, cnt+1)
			}
			cnt = 0
		}
		last = c
	}
	cnts = append(cnts, cnt+1)

	if len(cnts) == 1 {
		ans := (cnts[0] * k) / 2
		fmt.Println(ans)
		return
	}

	mid := 0
	for i := 1; i < len(cnts)-1; i++ {
		mid += cnts[i] / 2
	}
	start := cnts[0] / 2
	end := cnts[len(cnts)-1] / 2

	sep := 0
	if s[0] == s[len(s)-1] {
		sep = (cnts[0] + cnts[len(cnts)-1]) / 2
	} else {
		sep = cnts[0]/2 + cnts[len(cnts)-1]/2
	}
	// fmt.Println(start, end, mid, sep)
	ans := start + end + mid*k + sep*(k-1)
	fmt.Println(ans)
}

func init() {
	_sw.Split(bufio.ScanWords)
}

func NextInt() int {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	i, e := strconv.Atoi(_sw.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func NextInts(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = NextInt()
	}
	return a
}

func NextString() string {
	if _sw.Scan() == false {
		panic(_sw.Err())
	}
	return _sw.Text()
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x > y {
		return y
	}
	return x
}

func Bounded(lower, n, upper int) int {
	return Min(upper, Max(lower, n))
}

func SortInts(xs []int) {
	sort.Sort(sort.IntSlice(xs))
}

func ReverseSortInts(xs []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(xs)))
}


Measured memory_bytes: 640
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
using namespace std;
typedef long long ll;
typedef long double ld;
int A,B,Q;
vector<ll> As,Bs,Qs;
ll INF=(ll)1000*1000*1000*1000;
int main() {
  vector<char> buf(1<<24);
  vector<char> obuf(1<<24);
  fread(&buf[0],1,buf.size(),stdin);
  //vector<char>().swap(buf);
  istringstream stream(&buf[0]);
  stringstream ostream;

  cout << fixed << setprecision(15);
  stream >> A >> B >> Q;
  As.resize(A);Bs.resize(B);Qs.resize(Q);
  REP(i,A)
    stream >> As[i];
  REP(i,B)
    stream >> Bs[i];
  REP(i,Q) {
    ll x;
    stream >> x;
    auto ita=lower_bound(ALL(As),x);
    auto itb=lower_bound(ALL(Bs),x);
    // only go left
    ll ans=INF;
    vector<ll> alis,blis;
    if (ita!=As.end()) {
      alis.pb(*ita);
    }
    if (itb!=Bs.end()) {
      blis.pb(*itb);
    }
    if (ita!=As.begin()) {
      ita--;
      alis.pb(*ita);
    }
    if (itb!=Bs.begin()) {
      itb--;
      blis.pb(*itb);
    }
    for(ll a:alis)
      for(ll b:blis) {
        ans = min(ans,abs(a-x)+abs(b-a));
        ans = min(ans,abs(b-x)+abs(b-a));
      }
    ostream << ans << endl;
  }
  string o=ostream.str();
  fwrite(o.c_str(),1,o.size(),stdout);


  return 0;
}


Measured memory_bytes: 42740
#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll t;cin>>t;while(t--)
ll sizes[100001];
ll arr[100001];

bool ok=true;
ll A[100001];
pll B[100001];

ll root(ll i){
    while(i!=arr[i]) i=arr[i];
    return(i);
}
void Union(ll i,ll j){
    ll root_i=root(i),root_j=root(j);
    if(root_i==root_j) return;
    if(sizes[root_i]>sizes[root_j]) swap(root_i,root_j);
    sizes[root_j]+=sizes[root_i];
    arr[root_i]=arr[root_j];
    return;
}
bool prime[10000];
vector<ll> v;
void era(){
    memset(prime,true,sizeof prime);
    for(ll p=2;p*p<=10000;p++){
        if(prime[p]){

            for(ll q=p*p;q<=10000;q+=p){
                prime[q]=false;
            }
        }
    }

    return;
}

int main(){
    IO

    ll N,Q;
    string S;
    cin>>N>>Q>>S;
    S=' '+S;
    ll dp[N+1];
    memset(dp,0,sizeof dp);
    for(ll i=1;i<=N;i++){
        dp[i]=dp[i-1];
        if(S[i]=='C' && S[i-1]=='A') dp[i]++;
    }
    ll l,r;
    while(Q--){

        cin>>l>>r;
        cout<<dp[r]-dp[l]<<"\n";
    }


    return(0);
}


Measured memory_bytes: 1772
#include <stdio.h>

int main(){
	
	int a;
	int powerOne, powerTwo, powerThree, total;
	
	scanf("%d", &a);
	
	powerOne = a;
	powerTwo = a * a;
	powerThree = a * a * a;
	total = powerOne + powerTwo + powerThree;
	
	printf("%d", total);
	
	return 0;
	
}

Measured memory_bytes: 1708
#include<iostream>
#include<string>
#include <algorithm>

using namespace std;

int main()
{
	string s,cmd,p;
	int q;
	int a,b;
	
	cin>>s;
	cin>>q;
	for( int i=0; i<q; i++ ) {
		cin>>cmd;
		if( cmd == "print" ) {
			cin>>a>>b;
			cout<<s.substr(a, b-a+1)<<endl;
		} else if( cmd == "reverse" ) {
			cin>>a>>b;
			reverse( s.begin()+a, s.begin()+b+1 );
		} else if( cmd == "replace" ) {
			cin>>a>>b>>p;
			s.replace( a, b-a+1, p );
		}
	}
	return 0;
}


Measured memory_bytes: 3200
#include<stdio.h>
#include<string.h>

struct Node{
  int key;
  struct Node *next,*prev;
};

struct Node *nil;

struct Node* listSearch(int key){
  struct Node *cur = nil->next;
  while(cur != nil&&cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  struct Node *cur = nil->next;
  int isf = 0;
  while(1){
    if(cur==nil)break;
    if(isf++>0)printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}

void deleteNode(struct Node *t){
  if(t==nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  struct Node *x = (struct Node *)malloc(sizeof(struct Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key,n,i;
  int size = 0;
  char com[20];
  int np = 0,nd = 0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0] == 'i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0] == 'd'){
      if(strlen(com)>6){
	if(com[6]=='F')deleteFirst();
	else if(com[6]=='L')deleteLast();
      }else{
	deleteKey(key);nd++;
      }size--;
    }
  }
  
  printList();
  
  return 0;
}

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

using namespace std;

bool base[50][50] = {};

void dfs( int const y, int const x, int const w, int const h )
{
  if ( x >= 0 && y >= 0 && x < w && y < h && base[y][x] ) {
      base[y][x] = false;
      dfs( y + 1, x, w, h );
      dfs( y - 1, x, w, h );
      dfs( y, x + 1, w, h );
      dfs( y, x - 1, w, h );
      dfs( y + 1, x + 1, w, h );
      dfs( y - 1, x - 1, w, h );
      dfs( y - 1, x + 1, w, h );
      dfs( y + 1, x - 1, w, h );
  }
}


int main()
{
  for(;;) {
    
    int w, h;
    cin >> w >> h;

    if ( w == 0 && h == 0 )
      break;

    for( int i=0; i<50; ++i )
      for( int j=0; j<50; ++j )
	base[i][j] = false;

    for( int i=0; i<h; ++i )
      for( int j=0; j<w; ++j )
	cin >> base[i][j];

    int count = 0;
    for( int i=0; i<h; ++i ) {
      for( int j=0; j<w; ++j ) {
	if ( base[i][j] ) {
	  dfs( i, j, w, h );
	  ++count;
	}
      }
    }
    
    cout << count << endl;
  }
}

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

int find(int x, vector<int> &P){
  if(P[x]==x) return x;
  int ret = find(P[x],P);
  P[x] = ret;
  return ret;
}

void unite(int x, int y, vector<int> &P){
  x = find(P[x],P);
  y = find(P[y],P);
  if(x!=y) P[y] = x;
  return;
}

int main() {
  int N,K,L;
  cin >> N >> K >> L;
  vector<int> P1(N+1),P2(N+1);
  for(int i=1;i<=N;i++){
    P1[i] = i;
    P2[i] = i;
  }
  
  for(int i=0;i<K;i++){
    int p,q;
    cin >> p >> q;
    unite(p,q,P1);
  }
  for(int i=0;i<L;i++){
    int r,s;
    cin >> r >> s;
    unite(r,s,P2);
  }
  
  map<pair<int,int>,int> M;
  for(int i=1;i<=N;i++) M[make_pair(find(i,P1),find(i,P2))]++;
  
  for(int i=1;i<=N;i++){
    cout << M[make_pair(P1[i],P2[i])];
    if(i==N) cout << endl;
    else cout << " ";
  }
  return 0;
}


Measured memory_bytes: 13568
#include <stdio.h>
#include <stdlib.h>
typedef struct {
  int num;
  char cha;
} Card;
  
int main(){

  int N,i,j,minj,flag = 0;
  Card *C[2],dummy;

  scanf("%d",&N);
  C[0] = (Card *)malloc(N * sizeof(Card));
  C[1] = (Card *)malloc(N * sizeof(Card));
  for(j = 0;j < N;j++) {
    scanf(" %c %d",&C[0][j].cha,&C[0][j].num);
  }

  for(i = 0;i < N;i++){
    C[1][i].cha = C[0][i].cha;
    C[1][i].num = C[0][i].num;
  }
  for(i = 0;i < N;i++){ //bubble sort
    for(j = N - 1;j != i;j--){
      if(C[1][j].num < C[1][j - 1].num){
	dummy.cha = C[1][j].cha;
	dummy.num = C[1][j].num;
	C[1][j].cha = C[1][j - 1].cha;
	C[1][j].num = C[1][j - 1].num;
	C[1][j - 1].cha = dummy.cha;
	C[1][j - 1].num = dummy.num;
      }
    }
  }
  
  for(i = 0;i < N;i++){  //selection sort
    minj = i;
    for(j = i;j < N;j++){
      if(C[0][j].num < C[0][minj].num){
	minj = j;
      }
    }
    dummy.cha = C[0][i].cha;
    dummy.num = C[0][i].num;
    C[0][i].cha = C[0][minj].cha;
    C[0][i].num = C[0][minj].num;
    C[0][minj].cha = dummy.cha;
    C[0][minj].num = dummy.num;
  }

  for(j = 0;j < N;j++){
    printf("%c%d",C[1][j].cha,C[1][j].num);
    if(j != N - 1) printf(" ");
  }
  printf("\n");
  printf("Stable\n");
  
  for(j = 0;j < N;j++){
    printf("%c%d",C[0][j].cha,C[0][j].num);
    if(j != N - 1) printf(" ");
  }
  printf("\n");
  for(i = 0;i < N;i++){
    if(C[1][i].num != C[0][i].num || C[0][i].cha != C[1][i].cha) flag = 1;
  }
  if(flag == 1) printf("Not stable\n");
  else printf("Stable\n");
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
// until dimension reduction.

using namespace std;
typedef long long LL;

string s; 
int main() {
  cin >> s;
  int l = 0, r = s.size() - 1, cnt = 0;
  while (l < r) {
    if (s[l] != s[r]) cnt++;
    l++; r--;
  }

  cout << cnt  << endl; 
  return 0;
}


Measured memory_bytes: 256
W,B=map(int,input().split())
U,D=['#']*1000,['.']*1000
for i in range(W-1):U[i*2]='.'
for i in range(B-1):D[i*2]='#'
print(80,50)
for x in range(20):print(''.join(U[x*50:-~x*50])+'\n'+'#'*50)
for x in range(20):print('.'*50+'\n'+''.join(D[x*50:-~x*50]))

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

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

	int n, *ans;
	cin >> n;
	ans = new int[n]();

	for (int i = 1; i <= 100; i++)
		for(int j = 1; j <= 100; j++)
			for (int k = 1; k <= 100; k++) {
				int t = (i + j + k) * (i + j + k) - i * j - j * k - i * k;
				if (t <= n)
					ans[t - 1]++;
			}

	for (int i = 0; i < n; i++)
		cout << ans[i] << '\n';


	return 0;
}

Measured memory_bytes: 3644
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.IArray             as IA
import qualified Data.Array.IO                 as AI
import qualified Data.Array.MArray             as MA
import qualified Data.Array.ST                 as STA
import qualified Data.Array.Unboxed            as AU
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Graph                    as G
import           Data.Int
import qualified Data.IntMap                   as IM
import qualified Data.IntSet                   as IS
import           Data.List
import qualified Data.Map.Strict               as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence                 as SQ
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Tree                     as T
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putList :: Show a => [a] -> IO ()
putList [n     ] = put n
putList (n : ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n     ] = putStr n
putStrList (n : ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b | b         = putStrLn "YES"
             | otherwise = putStrLn "NO"

yesNo b | b         = putStrLn "Yes"
        | otherwise = putStrLn "No"

main = do
  [a,b,c]<-readString
  putStrLn $ "A"++ [head b] ++"C"

Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int fld[4000][4000];
int down[4000][4000],up[4000][4000];

struct data{
    int idx,len,f;
    data(int a=0,int b=0,int c=0):idx(a),len(b),f(c){}
    bool operator<(const data &d)const{
        if(len!=d.len)return len<d.len;
        if(f!=d.f)return f<d.f;
        return idx<d.idx;
    }
};

int H,W,L,P;
int N;
ll bit[10000];
void init(int n){
    N=n;
    fill_n(bit,N+1,0ll);
}

void add(int k,int x){
    for(k++;k<=N;k+=k&-k)bit[k]+=x;
}

ll sum(int k){
    ll ret=0;
    for(k++;k;k-=k&-k)ret+=bit[k];
    return ret;
}

void prevLatteing(){
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            up[i][j]=1001001001;
            down[i][j]=1001001001;
        }
    }

    int prev=0;
    for(int i=0;i<H;i++){
        prev=0;
        for(int j=W-1;j>=0;j--){
            if(fld[i][j]==1)prev=0;
            else prev++;
            down[i][j]=min(down[i][j],prev);
        }
    }

    for(int j=0;j<W;j++){
        prev=0;
        for(int i=H-1;i>=0;i--){
            if(fld[i][j]==1)prev=0;
            else prev++;
            down[i][j]=min(down[i][j],prev);
        }
    }

    for(int i=0;i<H;i++){
        prev=0;
        for(int j=0;j<W;j++){
            if(fld[i][j]==1)prev=0;
            else prev++;
            up[i][j]=min(up[i][j],prev);
        }
    }

    for(int j=0;j<W;j++){
        prev=0;
        for(int i=0;i<H;i++){
            if(fld[i][j]==1)prev=0;
            else prev++;
            up[i][j]=min(up[i][j],prev);
        }
    }
}
vector<data>vec;
ll Latteing(int sy,int sx){

    int Size=0;
    for(int i=0;sy<H&&sx<W;i++,Size++){
        vec[i*2]=data(i,down[sy][sx],1);
        vec[i*2+1]=data(i,up[sy][sx],0);
        sy++;sx++;
    }

    sort(vec.begin(),vec.begin()+Size*2);
    reverse(vec.begin(),vec.begin()+Size*2);
    ll ret=0;
    init(Size*2+10);
    for(int i=0;i<Size*2;i++){
        data &d=vec[i];
        if(d.f==0){
            add(d.idx,1);
        }
        else{
            if(d.len<L)continue;
            ret+=sum(d.idx+d.len-1)-sum(d.idx+L-2);
        }
    }

    init(Size*2+10);
    for(int i=0;i<Size*2;i++){
        data &d=vec[i];
        if(d.f==1){
            add(d.idx,1);
        }
        else{
            if(d.len<L)continue;
            ret+=sum(d.idx-L+1)-sum(d.idx-d.len);
        }
    }
    return ret;
}

int main(){
    scanf("%d%d%d%d",&H,&W,&L,&P);
    for(int i=0;i<P;i++){
        int y,x;scanf("%d%d",&y,&x);y--;x--;
        fld[y][x]=1;
    }

    prevLatteing();
    vec.resize(2*(H+W)+1919);
    ll ans=0;

    for(int i=0;i<H;i++){
        ans+=Latteing(i,0);
    }
    for(int j=1;j<W;j++){
        ans+=Latteing(0,j);
    }

    printf("%lld\n",ans);


    return 0;
}

Measured memory_bytes: 188260
<?php
fscanf(STDIN, "%d %d",$a,$b);
$sum=0;

if($a==$b){
	$sum += $a;
	$a=$a-1;
}else{
	if($a>$b){
		$sum += $a;
		$a=$a-1;
	}else{
		$sum += $b;
		$b=$b-1;
	}
}

if($a==$b){
	$sum += $a;
	$a=$a-1;
}else{
	if($a>$b){
		$sum += $a;
		$a=$a-1;
	}else{
		$sum += $b;
		$b=$b-1;
	}
}

echo $sum;
?>

Measured memory_bytes: 3828
//IOI 2021

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 2 * 100 + 17;

int n, col[MAXN], ans;
char adj[MAXN][MAXN];

void dfs(int v, int c) {
	col[v] = c;
	for (int i = 1; i <= n; i++) {
		if (adj[v][i] != '1')
			continue;
		if (!col[i])
			dfs(i, 3 - c);
		else if (col[i] != col[v])
			continue;
		else {
			cout << -1 << endl;
			exit(0);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			cin >> adj[i][j];
	dfs(1, 1);
	for (int i = 1; i <= n; i++) {
		queue<int> q;
		int lev[MAXN] = {}, mx = 1;
		q.push(i);
		lev[i] = 1;
		while (!q.empty()) {
			int u = q.front();
			q.pop();
			for (int j = 1; j <= n; j++)
				if (adj[u][j] == '1' && !lev[j]) {
					lev[j] = lev[u] + 1;
					mx = max(mx, lev[j]);
					q.push(j);
				}
		}
		ans = max(mx, ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
import Data.List

main = do
  l <- getLine
  let [i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12] = sort $ map read $ words l :: [Int]
      j1 = i1 == i2 && i1 == i3 && i1 == i4
      j2 = i5 == i6 && i5 == i7 && i5 == i8
      j3 = i9 == i10&& i9 == i11&& i9 == i12
      re = if j1 && j2 && j3
           then "yes"
           else "no"
  putStrLn re

Measured memory_bytes: 3696
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (n % k == 0) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }
    }
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;
	vector<lli> a(n);
	REP(i,0,n){
		cin>>a[i];
		if(a[i]%2){
			cout<<"first"<<endl;
			return 0;
		}
	}
	cout<<"second"<<endl;

	return 0;
}

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

typedef long long ll;

const long double PI = (acos(-1));


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

  ll x;
  cin >> x;

  cout << 1000 * (x / 500) + 5 * ((x % 500) / 5) << endl;

  return 0;
}


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

using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vii = vector<vi>;
using pii = pair<int, int>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int MOD = 1e9 + 7;


int main(){
  int n; scanf("%d", &n);
  int data[n];
  REP(i, n) scanf("%d", &data[i]);
  sort(data, data+n);
  int i, ans = 0;
  for(i = 0; i < n - 1;i++){
    if(data[i] == data[i + 1]) i++;
    else ans++;
  }
  ans += (i == (n - 1));
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int a[200005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) cin >> a[i];

  vector<int> sum(n, 0);

  ll ans = 0;
  REP(i, n) {
    if(i - a[i] >= 0) ans += sum[i - a[i]];
    if(i + a[i] < n) sum[i + a[i]]++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
struct card{
  public:
    char suit;
    char value;
};
void bubble_sort(vector<card> &v, int size){
  int i;
  bool is_replace = true;
  while( is_replace){
    is_replace = false;
    for( i=size-1; i>=1; i--){
      if( atoi(&v[i].value) < atoi(&v[i-1].value) ){
        card swp = v[i]; v[i] = v[i-1]; v[i-1] = swp;
        is_replace = true;
      }
    }
  }
}
void selection_sort(vector<card> &v, int size){
  int i,j,min_n;
  for( i=0; i<size; i++){
    min_n = i;
    for( j=i; j<size; j++){
      if( atoi(&v[j].value) < atoi(&v[min_n].value) ){
        min_n = j;
      }
    }
    card swp = v[i]; v[i] = v[min_n]; v[min_n] = swp;
  }
}
string is_stable(vector<card> v1, vector<card> v2, int size){
  for( int i=0; i<size; i++){
    if( v1[i].suit != v2[i].suit) return "Not stable";
  }
  return "Stable";
}


int main(){
  int n; cin>>n;
  vector<card> c1(n), c2(n);
  for( int i=0; i<n; i++){
    cin >> c1[i].suit >> c1[i].value;
    c2[i] = c1[i];
  }
  bubble_sort(c1, n);
  selection_sort(c2, n);
  for( int i=0; i<n; i++){
    cout << c1[i].suit << c1[i].value;
    if( i != n-1) cout << ' ';
  }
  cout << endl << "Stable" << endl;
  for( int i=0; i<n; i++){
    cout << c2[i].suit << c2[i].value;
    if( i != n-1) cout << ' ';
  }
  cout << endl << is_stable(c1,c2,n) << endl;
  return 0;
}


Measured memory_bytes: 3196