akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// http://www.prefield.com/algorithm/dp/lis_fast.html
const ll inf = 999999999999;
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
ll lis_fast(vector<ll>& a) {
  const ll n = a.size();
  vector<ll> A(n, inf);
  vector<ll> id(n, -1);
  for (ll i = 0; i < n; ++i) {
      if(a[i] != inf){
        id[i] = index_of(A, a[i]);
        A[ id[i] ] = a[i];
      }
  }
  dump(id);
  ll m = *max_element(id.begin(), id.end());
  if(m == -1) return 0;
  vector<ll> b(m+1);
  ll cnt = 0;
  for (ll i = n-1; i >= 0; --i)
    if (id[i] == m) {
        b[m--] = a[i];
        a[i] = inf;
        cnt++;
    }
    dump(cnt);
  return cnt;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    vll b(n);
    rep(i, n){
        cin >> a[i];
        b[i] = INF-a[i];
    }
    ll ans = 0;
    /*
    while(lis_fast(a) > 0){
        dump(a);
        ans++;
    }
    */
    multiset<ll> ms;
    rep(i, n){
        ms.insert(b[i]);
        auto it = ms.upper_bound(b[i]);
        if(it != ms.end()){
            ms.erase(it);
        }
    }
    cout << SZ(ms) << endl;
    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int c[]={0,1,2,1,3,1,3,1,1,3,1,3,1};
  if(c[a]==c[b])
    cout<<"Yes";
  else
    cout<<"No";
  
  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define L long long
#define pb push_back
using namespace std;
int n,u[110],v[110],x[110],y[110],w[110],f[110],p=1e9;
vector<int> a[110];
L q;
inline void orz()
{
    int i,j=0;
    L k=1;
    for(i=1;i<=n;i++)
      j=max(j,x[i]);
    for(i=1;i<j;i++)
      k*=w[i];
    if(j<p || j==p && k<q)
      p=j,q=k;
}
inline void dfs(int i,int j,int x[])
{
    for(auto k:a[i])
      if(k!=j)
        {
         x[k]=x[i]+1;
         dfs(k,i,x);
        }
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d",&n);
	if(n==2)
	  {
	   printf("1 2\n");
	   return 0;
      }
	for(i=1;i<n;i++)
	  {
       scanf("%d%d",&j,&k);
       a[j].pb(k);
       a[k].pb(j);
       f[j]++;
       f[k]++;
       u[i]=j;
       v[i]=k;
      }
    for(i=1;i<=n;i++)
      {
       for(j=1;j<=n;j++)
         w[j]=0;
       x[i]=1;
       dfs(i,0,x);
       for(j=1;j<=n;j++)
         w[x[j]]=max(w[x[j]],f[j]-(x[j]>1));
       orz();
      }
    for(i=1;i<n;i++)
      {
       for(j=1;j<=n;j++)
         w[j]=0;
       x[u[i]]=1;
       dfs(u[i],0,x);
       y[v[i]]=1;
       dfs(v[i],0,y);
       for(j=1;j<=n;j++)
         {
          x[j]=min(x[j],y[j]);
          w[x[j]]=max(w[x[j]],f[j]-1);
         }
       w[1]*=2;
       orz();
      }
    printf("%d %lld\n",p,q);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.nextLine();
      	String before = "";
      	String now = "";
      	int count = 0;
      	for(int i=0;i<s.length();i++){
        	now = now + s.substring(i,i+1);
          	if(before.equals(now)){
            	continue;
            }
          	before = now;
          	now = "";
          	count++;
        }
      	System.out.println(count);
    }
}

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

bool pnj(int a){
  if(a==1){
    return false;
  }else if(a==2){
    return true;
  }else{
    for(int i=2;i<a;i++){
      if(a%i==0){
        return false;
      }
    }
    return true;
  }
}

int main(){
  int Q;
  cin >> Q;
  vector<int> l(Q),r(Q);
  map<int,int> m;
  int n=0;
  vector<int64_t> ans(Q,0);
  m[0]=0;
  for(int i=1;i<=1e5;i++){
    if(pnj(i)&&(pnj((i+1)/2))){
      n++;
    }
    m[i]=n;
  }
  for(int i=0;i<Q;i++){
    cin >> l.at(i) >> r.at(i);
    ans.at(i)=m.at(r.at(i))-m.at(l.at(i)-1);
    cout << ans.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 6912
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#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 mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
const int inf=1e9;
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  vector<vector<int> >in(a,vector<int>(a));
  rep(i,a)rep(j,a)in[i][j]=inf;
  int c,d,e,f;
  //cout<<"!"<<endl;
  rep(i,b+1){
    char x;
    cin>>c>>x>>d>>x>>e>>x>>f;
    c--;d--;
    if(i==b)break;
    in[c][d]=e;
    in[d][c]=f;
  }
  rep(k,a)rep(i,a)rep(j,a){
    in[i][j]=min(in[i][j],in[i][k]+in[k][j]);
  }
  cout<<e-f-(in[c][d]+in[d][c])<<endl;
}

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

int main(){
    long long w,h;
    cin >> w >> h;
    int x,y;
    cin >> x >> y;
    int t=0;
    if(x*2==w&&y*2==h){
        t=1;
    }
    printf("%.12lf %d\n",(w*h)/2.0,t);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b) cout<<c<<endl;
  else if(b==c) cout<<a<<endl;
  else cout<<b<<endl;
}

Measured memory_bytes: 256
n = int(input())
def make_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans=10**11
for num in make_div(n):
    f = max(len(str(num)), len(str(n//num)))
    if ans > f:
        ans=f
print(ans)

Measured memory_bytes: 39280
#include <bits/stdc++.h>
 
#define ll long long
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl '\n' 
 
using namespace std;

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

    vector < int > v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;

    int k ; cin >> k ; 
    cout << v[k - 1] << endl ; return 0;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  
  int n = 10 * b + c;
  
  if(n % 4 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>

using namespace std;

#define PI 3.141592653589793
#define FOR(i,a,b) for(int i=int(a);i<int(b);++i)
#define RFOR(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)

int main() {
    int n;
    double s[1001];
    while(cin >> n) {
        if (n==0) break;
        double a,m,sum;
        sum = a = 0.0;
        REP(i,n) {
            cin >> s[i];
            sum += s[i];
        }
        m = sum/(double)n;
        REP(i,n) {
            a += pow(s[i]-m, 2);
            //cout << s[i] << m << a << endl;
        }
        //cout << a << endl;
        a=sqrt(a/(double)n);
        printf("%.5f\n", a);
    }
    return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <vector>
 
using namespace std;
int cnt = 0;
 
void insertionSort(vector<int>& A, int g)
{
    for (int i = g; i < A.size(); ++i)
    {
        if (A[i - g] > A[i])
        {
            int v = A[i];
            int j = i - g;
            while (j >= 0 && A[j] > v)
            {
                A[j + g] = A[j];
                j -= g;
                ++cnt;
            }
            A[j + g] = v;
        }
    }
}
 
void solve()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> A[i];
    }
    cnt = 0;
    vector<int> G;
    int h = 1;
    while (N >= h)
    {
        G.push_back(h);
        h = 3 * h + 1;
    }
    for (int i = G.size() - 1; i >= 0; --i)
    {
        insertionSort(A, G[i]);
    }
    cout << G.size() << endl;
    for (int i = G.size() - 1; i > 0; --i)
    {
        cout << G[i] << " ";
    }
    cout << G[0] << endl;
    cout << cnt << endl;
    for (int i = 0; i < A.size(); ++i)
    {
        cout << A[i] << endl;
    }
}
 
int main()
{
    solve();
    return(0);
}


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

using namespace std;

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define INF 0x3f3f3f3f
#define f1(n) for(int i=0 ; i<n ; i++)
#define f2(m) for(int j=0 ; j<m ; j++)
#define ll long long
typedef pair<int, int> iPair;
const double epsilon = 1e-7;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> v(n);
  f1(n) cin >> v[i];
  vector<int> answer(n);
  answer[0] = 0;
  for (int i=1; i<n; ++i) {
    answer[i] = v[i-1] ^ answer[i-1];
  }
  int r = 0;
  for (int i=n-1; i>=0; --i) {
    answer[i] ^= r;
    r ^= v[i];
  }
  for (auto x: answer)
    cout << x << " ";
  return 0;
}

Measured memory_bytes: 4744
//#pragma comment (linker,"/STACK:256000000")
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define next(a) ( ((a)+1)%SIZE )
#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000
#define SIZE 100000

#define INF 1000000000
#define LLINF 10000000000000000

typedef long long ll;

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

int cnt = 0;


void insertion_sort(int *a, int n,int g)
{
	int i, j;
	int k;

	for (i = g; i < n; i++)
	{
		k = i;

		while (a[k] < a[k - g] && k>=g)
		{
			swap(&a[k], &a[k - g]);
			k-=g;
			cnt++;
		}
	}
}

/*
void insertion_sort(int *A, int n, int g) {
	int i, j, v;
	for (i = g; i < n; i++) {
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
}*/


void shell_sort(int *a, int n)
{
	long long int h=1;
	int m = 1;
	int G[100];
	int i, j;

	while ((h*3+1) < n)
	{
		h = h * 3 + 1;
		m++;
	}

	for (i = 0; i < m; i++)
	{
		G[i] = h;
		h /= 3;
	}

	printf("%d\n", m);

	for (i = 0; i < m; i++)
	{
		if (i == m - 1)
			printf("%d\n", G[i]);
		else
			printf("%d ", G[i]);
	}

	for (i = 0; i < m; i++)
		insertion_sort(a, n, G[i]);

	printf("%d\n", cnt);
}
/*

int GCD(int x, int y)
{
	if (x < y)
		swap(&x, &y);

	int z;

	while (y > 0)
	{
		z = x;
		x = y;
		y = z % y;
	}
	return x;
}

int prime(int x)
{
	int i, j;

	for (i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
			return -1;
	}

	return 1;
}

void bubble_sort(int* p, int n)
{
	int i, j;

	for (i = 0; i < n; i++)
	{
		for (j=n-1; j > i ; j--)
		{
			if (p[j] < p[j - 1])
			{
				swap(&p[j], &p[j - 1]);
				cnt++;
			}
		}
	}
}
*/

/*
void selection_sort(int* p, int n)
{
	int i, j, min;

	for (i = 0; i < n; i++)
	{
		min = i;
		for (j = i+1; j < n; j++)
		{
			if (p[j] < p[min])
				min = j;
		}
		if (min != i)
		{
			swap(&p[min], &p[i]);
			cnt++;
		}
	}
}*/


int binary_search(int* a, int n,int key)
{
	int low, middle, high;

	low = 0, high = n - 1;

	while (low <= high)
	{
		middle = (low + high) / 2;

		if (key < a[middle])
			high = middle - 1;
		else if (key > a[middle])
			low = middle + 1;
		else
			return 1;
	}
	return 0;
}

void reverse(int a[], int b, int e)
{
	int i;

	for (i = 0; i <= (e-b-1) / 2; i++)
	{
		swap(&a[b+i], &a[e - 1 - i]);
	}
}

int main()
{
	int n;
	int a[200000];
	int m;
	int b[200000];

	scanf("%d", &n);

	int i;

	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);

	scanf("%d", &m);

	for (i = 0; i < m; i++)
		scanf("%d", &b[i]);

	int count = 0;

	for (i = 0; i < m; i++)
	{
		if (binary_search(a, n, b[i]))
			count++;
	}

	if (count == m)
		printf("1\n");
	else
		printf("0\n");

	return 0;
}


Measured memory_bytes: 3184
#include<stdio.h>
int main(void)
{
    long int n;
    scanf("%ld",&n);
    long int a[n];
    long int i,b;
    for(i=0;i<n;i++)
    a[i] = 0;
    for(i=0;i<n-1;i++)
    {
        scanf("%ld",&b);
        a[b-1]++;
    }
    for(i=0;i<n;i++)
    {
        printf("%ld\n",a[i]);
    }

    return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
 
int N,M,T;
bool ok[20000];
 
signed main(){
    cin>>N>>M>>T;
    fill_n(ok,T,true);
    rep(i,N){
        int t;cin>>t;
        reps(j,t-M,t+M)ok[j]=false;
    }
 
    cout<<accumulate(ok,ok+T,0ll)<<endl;
    return 0;
}

Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextInt();
		long b = scan.nextInt();
		int k = scan.nextInt();
		long taka = a;
		long ao = b;

		for (int i = 1; i <= k; i++) {
			if (i % 2 == 1) {
				if (taka % 2 == 1) {
					taka = taka - 1;
				}
				long A = taka/2;
				taka -= A;
				ao += A;
			} else {
				if (ao % 2 == 1) {
					ao = ao - 1;
				}
				long B = ao/2;
				ao -= B;
				taka += B;
			}
		}

		System.out.println(taka + " " + ao);
	}
}


Measured memory_bytes: 21716
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (1100000099)
#define INFLL (1100000000000000099ll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

int N;

int main() {
	scanf("%d", &N);
	for(int i = 1, sum = 1;; i++, sum += i) if(N <= sum) { printf("%d\n", i); return 0; }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int countChar(string s, char c, int left, int right) {
    int max_cnt = 0, cnt = 0;
    for (int i = left; i <= right; i++) {
        if (s[i] == c) {
            cnt++;
        } else {
            cnt = 0;
        }
        max_cnt = max(max_cnt, cnt);
    }
    return max_cnt;
}

int main() {
    int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
    string S; cin >> S;

    bool ok = true;
    A--; B--; C--; D--;
    if (C < D) {
        if (countChar(S, '#', A, C) >= 2 || countChar(S, '#', B, D) >= 2) ok = false;
    } else if (D < C) {
        if (countChar(S, '#', A, C) >= 2 || countChar(S, '#', B, D) >= 2) ok = false;
        if (ok) {
            if (countChar(S, '.', B - 1, D + 1) < 3) ok = false;
        }
    } else {
        ok = false;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 900
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <numeric>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, k, a, b, c, d, e, H, W,X;
long long A[200000] = {};
long long B[365][365] = {};
bool f;
bool ff;
string S, SS;
set <long long>sll;
pl buf;
vector <long long>vl;

struct ST
{
	long long total;
	long long aki;
	long long itta;
};

vector <ST> vst;
ST st;

int main() {

	cin >> N>>k;

	cout << N-k+1<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		boolean ans = false;

		int tsuru = X;
		int kame = 0;
		for(;tsuru >=0;tsuru--) {
			kame=X-tsuru;
			if(tsuru*2 + kame*4 ==Y) {
			ans = true;
			}
		}



		if(ans) {
		System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}



}


Measured memory_bytes: 35732
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <map>
#include <algorithm>  
#include <cmath>
#include <iomanip>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*ll t;
    cin>>t;
    ll x=0;
    while(t--)
    {
        ++x;
        ll n;
        cin>>n;
        ll sum=0;
        ll** arr=new ll*[n];
        for(ll i=0;i<n;++i)
        {
            arr[i]=new ll[n];
            for(ll j=0;j<n;++j)
            {
                cin>>arr[i][j];
                if(i==j)
                {
                    sum+=arr[i][j];
                }
            }
        }
        ll r=0;
        ll c=0;
        for(ll i=0;i<n;++i)
        {
            set<ll> s;
            for(ll j=0;j<n;++j)
            {
                s.insert(arr[i][j]);
            }
            if(s.size()!=n)
            {
                ++r;
            }
        }
        for(ll i=0;i<n;++i)
        {
            set<ll> s;
            for(ll j=0;j<n;++j)
            {
                s.insert(arr[j][i]);
            }
            if(s.size()!=n)
            {
                ++c;
            }
        }

    }*/
    ll n,k;
    cin>>n>>k;
    if(n==k)
    {
        cout<<0<<endl;
    }
    else if(n<k)
    {
        cout<<min(k-n,n)<<endl;
    }
    else
    {
        n=n%k;
        cout<<min(k-n,n)<<endl;
    }
}
// cout<<"Case #"<<x<<": "<<sum<<" "<<r<<" "<<c<<endl;




















Measured memory_bytes: 256
/*GRATITUDE*/
//Arise Awake and Stop Not Till the Goal is reached. You are the greatest of all. Hare Krishna
//Break through all barriers..
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define ff              first
#define ss              second
#define uint            unsigned long long
#define int             long long
#define double           long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define vpii            vector<pii>
#define umpii           unordered_map<int,int>
#define ustii           unordered_set<int>   
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             10000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define endl            "\n"
#define all(x)             x.begin(), x.end()
#define all_r(x)           x.rbegin(), x.rend()
#define sortall(x)         sort(all(x))
#define sortall_r(x)       sort(all_r(x))  
#define tr(it, a)          for(auto it = a.begin(); it != a.end(); it++)
#define PI                 acos(-1)
#define w(t)              int t; cin>>t; while(t--)
#define for_f(a,b,c)      for(int i=a;i<=b;i=i+c)
#define for_r(a,b,c)      for(int i=a;i>=b;i=i-c) 
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define trace1(x) cout << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
void ash_god()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    freopen("o.txt", "w", stdout);
#endif
}
/*************************************************************************************************/
//Write your functions here..............................


/***************************************************************************************************/
void solve() {
/*Write your code here*/
    int n,k; cin>>n>>k;
    mk(a,n,int);
    for_f(0,n-1,1) cin>>a[i];
    sort(a,a+n);
    int res=0;
    for_f(0,k-1,1) res+=a[i];
    cout<<res;
}
int32_t main()
{
ash_god();
bool tc=0;
if(tc)  {
    w(t) solve();
}
else solve();

return 0;
} 



Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
    public static int[] A = new int[50];
    public static int n;

    public static boolean solve(int i, int m) {
        if(m == 0) return true;
        if(i >= n) return false;
        boolean res = solve(i + 1, m) || solve(i + 1, m - A[i]);
        return res;
    }
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        int[] m = new int[q];
        for(int j = 0; j < q; j++) {
            m[j] = sc.nextInt();
        }
        for(int t : m) {
            if(solve(0, t)) System.out.println("yes");
            else System.out.println("no");
        }
    }
}



Measured memory_bytes: 26700
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int a= sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
	System.out.println((a+b)*h/2);
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<int> check9;
  vector<int> check6;
  int i = 9;
  int j = 6;
  while(i<100000){
    check9.push_back(i);
    i *= 9;
  }
  while(j<100000){
    check6.push_back(j);
    j *= 6;
  }
  vector<int> dp(100001,100000);
  for (int i=0; i<100001; i++){
    if (i<6) dp[i] = i;
    else{
      int k = check9.size() - 1;
      while (k > -1){
        if (check9[k] > i) k--;
        else{
          dp[i] = min(dp[i],dp[i-check9[k]]+1);
          k--;
        }
      }
      int l = check6.size() - 1;
      while (l > -1){
        if (check6[l] > i) l--;
        else{
          dp[i] = min(dp[i],dp[i-check6[l]]+1);
          l--;
        }
      }
    }
  }
  cout << dp[N] << endl;
}


Measured memory_bytes: 640
//List of Top 3 Hills
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

//		 int n = Integer.parseInt(in.readLine());
		
		
		int top=0;
		int second=0;
		int third=0;
		
		int n;
		for(int i=0;i<10;i++){
			
			n = Integer.parseInt(in.readLine());
			
			if(n>third){
				third=n;
			
				if(n>second){
					third=second;
					second=n;
					
					if(n>top){
						second=top;
						top=n;
					}
				}
			}

			
		}
		
		
		System.out.println(top);
		System.out.println(second);
		System.out.println(third);
		
	}
}

Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin>>n;
	int no_odd = 0;
	for(int i = 1; i <=n ;i++){
		if(i % 2 != 0){
			no_odd++;
		}
	}
	cout<<fixed<<setprecision(10)<<1.0 * no_odd / n<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		Integer[] dice = {1,3,4,2,5,6};//{上(0)、東(1)、西(2)、南(3)、北(4)、下(5)}

		while(true){
			int diceCount = stdIn.nextInt();
			if(diceCount == 0)break;
			int diceSum = 1;
			for(int i=0;i<diceCount;i++){
				String diceMethod = stdIn.next();
				if("North".equals(diceMethod)){
					int northCopy = dice[4];
					dice[4] = dice[0];
					dice[0] = dice[3];
					dice[3] = dice[5];
					dice[5] = northCopy;
				}else if("East".equals(diceMethod)){
					int eastCopy = dice[1];
					dice[1] = dice[0];
					dice[0] = dice[2];
					dice[2] = dice[5];
					dice[5] = eastCopy;
				}else if("West".equals(diceMethod)){
					int westCopy = dice[2];
					dice[2] = dice[0];
					dice[0] = dice[1];
					dice[1] = dice[5];
					dice[5] = westCopy;
				}else if("South".equals(diceMethod)){
					int southCopy = dice[3];
					dice[3] = dice[0];
					dice[0] = dice[4];
					dice[4] = dice[5];
					dice[5] = southCopy;
				}else if("Right".equals(diceMethod)){
					int rightCopy =dice[1];
					dice[1] = dice[4];
					dice[4] = dice[2];
					dice[2] = dice[3];
					dice[3] = rightCopy;
				}else if("Left".equals(diceMethod)){
					int leftCopy = dice[2];
					dice[2] = dice[4];
					dice[4] = dice[1];
					dice[1] = dice[3];
					dice[3] = leftCopy;
				}
				diceSum += dice[0];
			}
			System.out.println(diceSum);
			dice[0] = 1;dice[1] = 3;dice[2] = 4;
			dice[3] = 2;dice[4] = 5;dice[5] = 6;
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>

int main(void){
  int a[100],n,flag,j,i,x=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  flag=1;
  while(flag){
    flag=0;
    for(j=n-1;j>=1;j--){
      if(a[j]<a[j-1]){
	i=a[j];a[j]=a[j-1];a[j-1]=i;
	flag=1;
	x++;
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i<n-1)
      printf(" ");
    else
      printf("\n");
  }
  printf("%d\n",x);
  
  return(0);
}



Measured memory_bytes: 2720
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	set<int> st;
	int a,b,c;
	cin>>a>>b>>c;
	st.insert(a);
	st.insert(b);
	st.insert(c);
	cout<<st.size()<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n+2);
  h[0] = 0;
  h[n+1] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
  }

  bool up = false;
  int ans = 0;
  int bottom = 0;
  for (int i = 1; i <= n + 1; i++) {
    if (h[i-1] < h[i] && !up) {
      up = true;
      bottom = h[i - 1];
    }
    else if (h[i-1] > h[i] && up) {
      up = false;
      ans += h[i - 1] - bottom;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db long double
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define W while
#define fn(i,x) for(int i=0;i<x;i++)
#define fs(i,s,x) for(int i=s;i<x;i++)
#define fr(i,x) for(int i=x;i>=0;i--)
#define fit(it,s) for(auto it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 1000000007
#define MAX 1005
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    
    ll r,d,x;
    cin >> r >> d >> x;
    fn(i,10){
      x = r*x - d;
      cout << x << "\n";

    }

    return 0;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32

MOD = 1000000007  # type: int

def solve(N: int, A: "List[int]"):
    ans = [0] * 60
    
    
    for i in range(60):
        # x0 = len([j for j in range(N) if not (A[j]>>i)&1])
        # x1 = len([j for j in range(N) if (A[j]>>i)&1])
        x0 = 0
        x1 = 0
        for j in range(N):
            if (A[j]>>i)&1:
                x1 += 1
            else:
                x0 += 1

        ans[i] = x0*x1

    x = 0
    for i in range(len(ans)):
        # print(i, 2**i)
        x += pow(2, i) * ans[i] % MOD

    print(x%MOD)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 120444
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll K, A, B;

void solve() {
	cin >> K >> A >> B;
	if(K <= A - 1) cout << K + 1 << "\n";
	else {
		K -= (A - 1);
		if(B - A <= 1) cout << A + K << "\n";
		else {
			if(K % 2 == 1) {
				cout << (K / 2) * (B - A) + A + 1 << "\n";
			}
			else cout << (K / 2) * (B - A) + A << "\n";
		}
	}
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()
	var N int
	var S, T string
	fmt.Fscanf(bufin, "%d\n", &N)
	fmt.Fscanf(bufin, "%s\n", &S)
	fmt.Fscanf(bufin, "%s\n", &T)
	if S == T {
		fmt.Fprintf(bufout, "%d\n", N)
		return
	}
	ans := 0
	for i := 0; i < N; i++ {
		OK := true
		for j := 0; j < i; j++ {
			if S[N-i+j] != T[j] {
				OK = false
				break
			}
		}
		if OK {
			ans = 2*N - i
		}
	}
	fmt.Fprintf(bufout, "%d\n", ans)

}


Measured memory_bytes: 640
N = int(input())
a_s = list(map(int,input().split()))
b_s = [0] * N
answers = []
for i,a in enumerate(list(reversed(a_s))):
    k = len(a_s)-i-1
    if sum(b_s[k::(k+1)])%2 != a_s[k]:
        b_s[k] = 1
        answers.append(str(k+1))
print(len(answers))
print(" ".join(list(reversed(answers))))

Measured memory_bytes: 17596
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  auto it = S.begin();
  auto rit = S.rbegin();
  i64 answer = 0;
  for (; it != S.end() && rit != S.rend(); ++it, ++rit) {
    if (*it != *rit) ++answer;
  }
  answer /= 2;
  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np

N, M, C = [int(_) for _ in input().split()]
B = np.array([int(_) for _ in input().split()])
cnt = 0

for i in range(N):
    A = np.array([int(_) for _ in input().split()])
    if np.dot(A, B) + C > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 12420
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

	int N, res;
	cin >> N;
	bool flag = false;
	FOR(i, 1, 9) {
		if(N <= 111*i) {
			flag = true;
			res = 111*i;
			break;
		}
	}
	if(!flag) res = 999;
	cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int H[] = new int[N];
    for(int i = 0; i < N; i++) {
      H[i] = sc.nextInt();
    }
    int max = 0;
    int cnt = 0;
    for(int i  = 0; i < N-1; i++) {
      if(H[i+1] <= H[i]) {
        cnt++;
      }else {
        cnt = 0;
      }
      if(max < cnt) {
        max = cnt;
      }
    }
    System.out.println(max);
	}
}

Measured memory_bytes: 50884
# -*- coding: utf-8 -*-
_ = input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))

diff = [i - j for i, j in zip(a, b)]

if sum(diff) < 0:
    print(-1)
    exit()

short = [i for i in diff if i < 0]
change = len(short)
shortage = sum(short)

over = [i for i in diff if i > 0]
for i in sorted(over, reverse=True):
    if shortage < 0:
        change += 1
        shortage += i
    else:
        break
print(change)


Measured memory_bytes: 19468
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
  ///#ifndef ONLINE_JUDGE
      // for getting input from input.txt
      //freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      //freopen("output.txt", "w", stdout);
  //#endif
fast();
//ll  t;cin>>t;while(t--)
{
  ll n,d,x,c=0;
  cin>>n>>d>>x;
  c+=n;
  ll a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
     int x=a[i],j=2;
     while(x+1<=d)
     {
        x=a[i]*j;
        j++;
        c++;
     }
    // cout<<c<<endl;
  }
  cout<<c+x<<endl;

}
return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

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

vector<vector<int>> grid(11, vector<int> (10001));
int R, C;

int solve() {
  int ret = 0;
  rep(state, 0, 1 << R) {
    // 初期化
    vector<vector<int>> tmp_grid(R, vector<int> (C));
    rep(i, 0, R) {
      rep(j, 0, C) {
        tmp_grid[i][j] = grid[i][j];
      }
    }

    rep(r, 0, R) {
      if ((state & (1 << r)) == (1 << r)) { // r行目をひっくり返す
        rep(c, 0, C) {
          if (tmp_grid[r][c] == 0) {
            tmp_grid[r][c] = 1;
          } else {
            tmp_grid[r][c] = 0;
          }
        }
      }
    }

    int tmp = 0;
    rep(c, 0, C) {
      int tmp0 = 0;
      rep(r, 0, R) {
        if (tmp_grid[r][c] == 0) {
          tmp0++;
        }
      }

      tmp += max(tmp0, R - tmp0);
    }

    ret = max(ret, tmp);
  }

  return ret;
};

int main() {
  while (cin >> R >> C, R+C) {
    rep(i, 0, R) {
      rep(j, 0, C) {
        cin >> grid[i][j];
      }
    }

    cout << solve() << endl;
  }

  return 0;
};



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

using ll = long long;
#define rep(n, i) for(ll i = 0; i < n; ++i)
const ll INF = 1LL << 60;

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

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

void solve(void){
  ll n; cin >> n;
  vector<ll> h(n, 0);
  rep(n, i) cin >> h[i];

  vector<ll> dp(n+10, INF);
  dp[0] = 0;

  rep(n, i) {
    chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
  }

  cout << dp[n-1] << endl;
}

int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
    #include <ext/pb_ds/tree_policy.hpp> 
    #include <functional> // for less 
    using namespace __gnu_pbds; 
    using namespace std;
    //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;    
    #define ll            long long
    #define pb            push_back
    #define ppb           pop_back
    #define si            set <ll>
    #define endl          '\n'
    #define fr            first
    #define sc            second
    #define mii           map<ll ,ll >
    #define msi           map<string,ll >
    #define mis           map<ll , string>
    #define rep(i,a,b)    for(ll  i=a;i<b;i++)
    #define all(v)        v.begin(),v.end()
    #define sort(v)       sort(all(v))
    #define pii           pair<ll ,ll >
    #define vi            vector<ll >
    #define vii           vector<pair<ll , ll >>
    #define vs            vector<string>
    #define sz(x)         (ll)x.size()
    #define M             1000000007
    #define bs            binary_search
    #define rev(a)        reverse(all(a));
    #define sp(n)         setprecision(n)
    #define spl           " "
    #define arr(a,n)      rep(i,0,n) cin>>a[i]
    #define mod           998244353
    #define print_vector(a)  for(auto t:a) cout<<t<<" ";cout<<endl;
    #define print_arr(a,n)   rep(i,0,n) cout<<a[i]<<" "; cout<<endl;        
    #define show(a,n)     for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    #define N             100000000
    #define debug(x)      cout << #x << " is " << x << endl;
    #define time          cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    #define INF           1ll<<31
    #define M_PI 3.14159265358979323846
    using namespace std;
    ll min(ll a,ll b)
    {
        return a>b?b:a;
    }
    ll max(ll a,ll b)
    {
        return a>b?a:b;
    }
    const ll maxn=2e5+500;
    void solve()
    {
        ll h;
        cin>>h;
        ll t=log2(h)+1;
        ll k=pow(2,t)-1;
        cout<<k<<endl;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t=1;
        //cin>>t;
        while(t--) solve();
    }


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int a_max = Integer.MIN_VALUE;
        int b_min = Integer.MAX_VALUE;
        for (int i = 0; i < a; i++) {
            a_max = Math.max(a_max,Integer.parseInt(sc.next()));
        }
        for (int i = 0; i < b; i++) {
            b_min = Math.min(b_min,Integer.parseInt(sc.next()));
        }
        int z = a_max + 1;
        if (z > A && z <= B) {
            if (z <= b_min) {
                System.out.println("No War");
                return;
            }
        }
        System.out.println("War");
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int gcd(int a, int b)
{
	int r;
	r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}


int main(int argc, char *argv[])
{
	int i;
	int max;
	int count = 0;
	int a, b, k;
	

	cin >> a >> b >> k;
	max = gcd(a, b);
	
	for (i = max;; i--) {
		if (a % i == 0 && b % i == 0) 
			count++;
		if (count == k)
			break;
	}

	cout << i << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int n, k[105], l[105], ans;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) { 
		cin >> k[i]; 
		++l[k[i]];
	}
	for (int i = 100; i >= 0; --i) {
		ans += l[i];
		if (ans >= i) {
			cout << i << endl;
			return 0;
		}
	}
	
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>

using namespace std;

int main(){
    int y, m ,d;
    std::string ans;
    scanf("%d/%d/%d", &y, &m, &d);
    if(m <= 4) ans = "Heisei";
    else ans = "TBD";

    cout << ans << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<long long> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

    long long ans = 0;
    for (int i = N - 1; i >= 0; i--) {
        A[i] += ans;
        long long r = A[i] % B[i];
        if (r == 0) continue;
        ans += B[i] - r;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4816
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int n,i;
	int x,y;
	int sum=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>x>>y;
		sum+=(y-x+1);
	}
	cout<<sum<<endl;
	return 0; 
} 

Measured memory_bytes: 256
a,b,k=map(int,input().split())
for i in range(k):
    if i%2==0:
        if a%2==1:
        	a-=1
        a=a//2
        b+=a
    else:
        if b%2==1:
        	b-=1
        b=b//2
        a+=b
print(str(a)+" "+str(b))

Measured memory_bytes: 2940