akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static int n;
	public static int s;
	public static int c;

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		while (true) {
			n = sc.nextInt();
			s = sc.nextInt();

			if (n == 0 && s == 0) {
				break;
			}

			c = 0;

			dfs(0, s, s);

			System.out.println(c);
		}
	}

	public static void dfs(int k, int rest, int x) {
		if (k == n) {
			c += rest == 0 ? 1 : 0;
			return;
		}
		if (rest < 0) {
			return;
		}

		for (int i = Math.min(x, 9); i >= 0; i--) {
			dfs(k + 1, rest - i, i - 1);
		}
	}
}

Measured memory_bytes: 26404
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int a, b, h; cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    
    return 0;
    
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	ci(n);
	ll sum=0;
	fok(i,1,n+1){
		if(i%3 !=0 && i%5!=0){
			sum+=i;
		}
	}
	co(sum);
}


Measured memory_bytes: 3660
#include <stdio.h>

#define N 100000

typedef struct{
  char mark; //絵柄
  int num; //数字
  int s; //安定かの確認するための変数
} Card;

void quickSort(Card *,int,int);
int partition(Card *,int,int);

int main(void){

  int i,n,p = 0,r,f = 0;
  char c;
  Card A[N];

  scanf("%d%c",&n,&c);
  r = n-1;

  for(i=0;i<n;i++){
    scanf("%c%d%c",&A[i].mark,&A[i].num,&c);
    A[i].s = i;
  }

  quickSort(A,p,r);

  for(i=0;i<r-1;i++){
    if(A[i].num == A[i + 1].num && A[i].s > A[i + 1].s){
      printf("Not stable\n");
      f = 1;
      break;
    }
  }

  if(f == 0){
    printf("Stable\n");
  }
  
  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].mark,A[i].num);
  }
  return 0;
}


void quickSort(Card *A,int p,int r){

  int q;

  if(p < r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

int partition(Card *A,int p,int r){

  int i,j,x;
  Card temp;

  x = A[r].num;
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j].num <= x){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}

Measured memory_bytes: 1776
#include<iostream>
using namespace std;
unsigned long xor_x=88172645463325252ULL;
unsigned long rng()
{
	xor_x^=xor_x<<7;
	return xor_x^=xor_x>>9;
}
int D;
int c[26],s[365][26];
int t[365],now;
int anst[365],ans;
void calc()
{
	int lst[26];
	for(int i=0;i<26;i++)lst[i]=-1;
	now=0;
	for(int i=0;i<D;i++)
	{
		now+=s[i][t[i]];
		lst[t[i]]=i;
		for(int j=0;j<26;j++)now-=c[j]*(i-lst[j]);
	}
}
int change(int d,int q)
{
	int ret=0;
	ret-=s[d][t[d]];
	ret+=s[d][q];
	{
		int r=d+1;
		while(r<D&&t[r]!=t[d])r++;
		int l=d-1;
		while(l>=0&&t[l]!=t[d])l--;
		ret-=c[t[d]]*(r-d)*(d-l);
	}
	{
		int r=d+1;
		while(r<D&&t[r]!=q)r++;
		int l=d-1;
		while(l>=0&&t[l]!=q)l--;
		ret+=c[q]*(r-d)*(d-l);
	}
	return ret;
}
main()
{
	cin>>D;
	for(int i=0;i<26;i++)cin>>c[i];
	for(int i=0;i<D;i++)for(int j=0;j<26;j++)cin>>s[i][j];
	{
		int lst[26];
		for(int i=0;i<26;i++)lst[i]=-1;
		for(int i=0;i<D;i++)
		{
			int x=-1,tc=-1;
			for(int j=0;j<26;j++)
			{
				int u=s[i][j]+c[j]*(i-lst[j])*5;
				if(tc<u)
				{
					tc=u;
					x=j;
				}
			}
			anst[i]=t[i]=x;
			lst[x]=i;
		}
	}
	calc();
	ans=now;
	for(int tm=0;tm<3300;tm++)
	{
		while(true)
		{
			int d=rng()%D,q=rng()%26;
			int ret=change(d,q);
			if(rng()%2000>tm||ret>=0)
			{
				now+=ret;
				t[d]=q;
				break;
			}
		}
		for(int k=0;k<3300;k++)
		{
			int d1=rng()%(D-1)+1,d2=rng()%d1;
			int pt1=t[d1],pt2=t[d2];
			int diff=0;
			diff+=change(d1,pt2);
			t[d1]=pt2;
			diff+=change(d2,pt1);
			t[d2]=pt1;
			if(diff>=0)
			{
				now+=diff;
			}
			else
			{
				t[d1]=pt1;
				t[d2]=pt2;
			}
		}
		if(ans<=now)
		{
			ans=now;
			for(int i=0;i<D;i++)anst[i]=t[i];
		}
		else if(rng()%2000<tm)
		{
			now=ans;
			for(int i=0;i<D;i++)t[i]=anst[i];
		}
	}
	for(int i=0;i<D;i++)cout<<anst[i]+1<<endl;
	cerr<<ans<<endl;
}


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

int main(){
  vector<int> x(5);
  int ans = 0;
  for(int i = 0; i < 5; i++){
    cin >> x.at(i);
    if(x.at(i) != 0){
      ans++;
    }else if(x.at(i) == 0){
      ans++;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define endl '\n'

#define int long long

using namespace std;
const int MAXN = (1 << 20);

int n, k;
int a[MAXN];

void read()
{
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> a[i];
}

int solve(int len)
{
	deque<pair<int, int>> Q;

	int ans = 0;
	for(int i = 0; i < 2 * n; i++)
	{
		while(!Q.empty() && Q.back().first <= i - len) Q.pop_back();
		while(!Q.empty() && a[i] < Q.front().second) Q.pop_front();
		Q.push_front({i, a[i]});
		
		if(i >= n) ans += Q.back().second;
	}

	return ans;
}

void solve()
{
	for(int i = n; i < 2 * n; i++)
		a[i] = a[i - n];

	int ans = (int)1e18 + 42;
	for(int x = 1; x <= n; x++)
		ans = min(ans, (x - 1) * k + solve(x));
	
	cout << ans << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, a, b;

int main(){
	while (cin >> n&&n){
		int	suma = 0, sumb = 0;
		REP(i, n){
			cin >> a >> b;
			if (a > b){
				suma += a + b;
			}
			else if (a < b){
				sumb += a + b;
			}
			else {
				sumb += b;
				suma += a;
			}
		}
		cout << suma << " " << sumb << endl;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#include<set>
#include<map>
#define re register
#define ll long long
using namespace std;
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9'|| ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return sum*f;
}
const double eps=1e-10,Pi=acos(-1.0);
struct node{
	double x,y;
	node operator+(node b){return (node){x+b.x,y+b.y};}
	node operator-(node b){return (node){x-b.x,y-b.y};}
	node operator*(double b){return (node){x*b,y*b};}
	double len(){return sqrt(x*x+y*y);}
};
int fh(double a){return fabs(a)<eps?0:a>eps?1:-1;}
double cross(node a,node b){return a.x*b.y-a.y*b.x;}
double dot(node a,node b){return a.x*b.x+a.y*b.y;}
node projection(node p1,node p2,node p){node v=p2-p1;return p1+v*(dot(v,p-p1)/dot(v,v));}
node reflection(node p1,node p2,node p){node P=projection(p1,p2,p);P=P*2-p;return P;}
void Counter_Clockwise(node p1,node p2,node p){
	if(cross(p2-p1,p-p1)>eps){puts("COUNTER_CLOCKWISE");return;}
	if(cross(p2-p1,p-p1)<-eps){puts("CLOCKWISE");return;}
	if(dot(p2-p1,p-p1)<-eps){puts("ONLINE_BACK");return;}
	if(dot(p2-p1,p2-p1)>=dot(p-p1,p2-p1)){puts("ON_SEGMENT");return;}
	puts("ONLINE_FRONT");
}
bool insegment(node A,node B,node p){
	if(fh(cross(B-A,p-A)))return false;
	return ((fh(p.x-A.x)>=0 && fh(B.x-p.x)>=0) || (fh(p.x-A.x)<=0 && fh(B.x-p.x)<=0)) && ((fh(p.y-A.y)>=0 && fh(B.y-p.y)>=0) || (fh(p.y-A.y)<=0 && fh(B.y-p.y)<=0));
}
int parallel(node A1,node A2,node B1,node B2){
	if(!fh(cross(B2-B1,A2-A1)))return 2;
	if(!fh(dot(B2-B1,A2-A1)))return 1;
	return 0;
}
bool intersection(node A1,node A2,node B1,node B2){
	if(!fh(cross(B2-B1,A2-A1))){
		if(insegment(A1,A2,B1) || insegment(A1,A2,B2) || insegment(B1,B2,A1) || insegment(B1,B2,A2))return true;
		return false;
	}
	return fh(cross(A1-B1,B2-B1)*cross(A2-B1,B2-B1))<=0 && (fh(cross(B1-A1,A2-A1)*cross(B2-A1,A2-A1))<=0);
}
int main(){
	node p1,p2,p3,p4;
	int Q=gi();
	while(Q--){
		p1.x=gi();p1.y=gi();p2.x=gi();p2.y=gi();
		p3.x=gi();p3.y=gi();p4.x=gi();p4.y=gi();
		printf("%d\n",parallel(p1,p2,p3,p4));
	}
	return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){

	double r,S,L,P;
	P=3.141592653589;
	cin >> r;

	S=P*r*r;
	L=2*P*r;

	printf("%lf %lf",S,L);
return 0;
}

Measured memory_bytes: 1236
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    int n, m;
    scan(n, m);

    auto uf = WeightedUnionFind!(int)(n + 1);
    bool ok = 1;

    foreach (i ; 0 .. m) {
        int l, r, d;
        scan(l, r, d);

        if (uf.same(l, r)) {
            if (uf.diff(l, r) != d) {
                ok = 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }

    writeln(ok ? "Yes" : "No");
}



struct WeightedUnionFind(T) {
    private {
        int[] _parent, _rank;
        T[] _diff;
    }

    this(int N) {
        _parent = new int[](N);
        _rank = new int[](N);
        _diff = new T[](N);

        foreach (i ; 0 .. N) {
            _parent[i] = i;
        }
    }

    int findRoot(int x) {
        if (_parent[x] != x) {
            int r = findRoot(_parent[x]);
            _diff[x] += _diff[_parent[x]];
            _parent[x] = findRoot(r);
        }

        return _parent[x];
    }

    bool same(int x, int y) {
        return findRoot(x) == findRoot(y);
    }

    T weight(int x) {
        findRoot(x);
        return _diff[x];
    }

    // x と y が異なるグループに属すならinf(十分大きい値)を返す
    T diff(int x, int y) {
        return same(x, y) ? weight(y) - weight(x) : T.max;
    }

    import std.algorithm : swap;

    // weight(y) = weight(x) + w
    bool merge(int x, int y, T w) {
        w += weight(x) - weight(y);

        int u = findRoot(x);
        int v = findRoot(y);

        // x と y　が既に同じグループであるなら距離の更新はしない
        if (u == v) return false;

        if (_rank[u] < _rank[v]) {
            swap(u, v);
            w = -w;
        }

        if (_rank[u] == _rank[v]) {
            _rank[u]++;
        }

        _parent[v] = u;
        _diff[v] = w;

        return true;
    }
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 4476
// Problem : B - Good Distance
// Contest : AtCoder - AtCoder Beginner Contest 133
// URL : https://atcoder.jp/contests/abc133/tasks/abc133_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//Totka hai dosto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
bool isp(int x)
{
	int s=sqrt(x);
	if(s*s==x)return 1;
	return 0;
}
int32_t main()
{
	int n,d;
	cin>>n>>d;
	int a[n][d];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<d;j++)
		{
			cin>>a[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int co=0;
			for(int k=0;k<d;k++)
			{
				co+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			if(isp(co))ans++;
			
			
		}
	}
	cout<<ans;
	
}

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

using namespace std;

typedef long long ll;
ll n, mx, sum, a[105];
//bool b[105][105];


//void g(ll p)
//{
//    for(ll i = p; i <= n; i += p)
//    {
//        if(bo[i] == false)bo[i] = true;
//    }
//}
//
void f(ll p)
{
    int b[105];
    if(p > n)
    {
        sum = 0;
        for(ll i = 1; i <= n; i++)
        {
            sum += a[i];
        }
        mx = max(mx, sum);
        return;
    }
    f(p + 1);
    if(a[p] < 0) {
        for(int i = p; i <= n; i += p) b[i] = a[i];
        for(int i = p; i <= n; i += p) a[i] = 0;
        f(p + 1);
        for(int i = p; i <= n; i += p) a[i] = b[i];
    }
}

int main()
{
    scanf("%lld", &n);
    for(ll i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
    }
    for(ll i = n / 2 + 1; i <= n; i++)
    {
        if(a[i] < 0) a[i] = 0;
    }
    f(1);
    printf("%lld", mx);
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);
  for (int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;   
  }
  for(int i=0;i<N;i++){
    cout << vec.at(i) << endl;
  }
}

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

int main()
{
  int N, K;
  long long total=0;
  cin >> N >> K;
  vector<int> H(N);
  for(int i=0;i<N;i++) cin >> H.at(i);
  sort(H.begin(), H.end());
  for(int i=0;i<N-K;i++) total += H.at(i);
  cout << total << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	double res = 0;
	for (int i = 1; i <= N; i++) {
		int t = i;
		double a = 1;
		while (t < K) {
			t *= 2;
			a *= 0.5;
		}
		res += a;
	}
	res /= N;
	cout << fixed << setprecision(15) << res << endl;
}


Measured memory_bytes: 3736
import itertools
N=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

m=list(itertools.permutations(p))
m.sort()

p=tuple(p)
q=tuple(q)
a=m.index(p)
b=m.index(q)

print(abs(a-b))

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

using namespace std;

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

int main(){
  int n; cin >> n;
  vector<int> a(n); vector<int> b(n); vector<int> c(n); int i; rep(i, n) cin >> a[i] >> b[i] >> c[i];
  
  vector<vector<int>> happy(n, vector<int>(3));
  happy[0][0] = a[0];
  happy[0][1] = b[0];
  happy[0][2] = c[0];
  for(int i = 1; i < n; i++){
    happy[i][0] = a[i] + max(happy[i - 1][1], happy[i - 1][2]);
    happy[i][1] = b[i] + max(happy[i - 1][2], happy[i - 1][0]);
    happy[i][2] = c[i] + max(happy[i - 1][0], happy[i - 1][1]);
  }
  
  cout << max(happy[n - 1][0], max(happy[n - 1][1], happy[n - 1][2])) << '\n';
  return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N, W;
int v[111], w[111];
int dp[111][111111];

void solve() {
   rep (i, N) {
      for (int j = 0; j <= W; j++) {
         chmax(dp[i+1][j], dp[i][j]);
         if (j + w[i] <= W) {
            chmax(dp[i+1][j+w[i]], dp[i][j] + v[i]);
         }
      }
   }

   cout << dp[N][W] << endl;
}

int main() {
   cin >> N >> W;
   rep (i, N) { cin >> v[i] >> w[i]; }

   solve();

   return 0;
}


Measured memory_bytes: 7384
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n;
int f[105][15];
int p[105][15];

int main()
{
  scanf("%d",&n);
  REP(i,n)
  {
    REP(j,10) scanf("%d",&f[i][j]);
  }
  REP(i,n)
  {
    REP(j,11) scanf("%d",&p[i][j]);
  }
  int risan = -INF;
  FOR(i,1,1<<10)
  {
    int coba = 0;
    REP(j,n)
    {
      int ada = 0;
      REP(k,10) if(i & (1 << k)) ada += f[j][k];
      coba += p[j][ada];
    }
    MAX(risan,coba);
  }
  printf("%d\n",risan);
  return 0;
}










Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main(void) {
  string s, t, first="", last="";
  long long int q, tmp1, tmp2, r_cnt=0;
  bool flag1=false;
  cin >> s >> q;
  for(int i=0; i<q;i++) {
    cin >> tmp1;
    if(tmp1==1) {
       flag1 = ! flag1;
    } else {
      cin >> tmp2 >> t;
      if(tmp2==1) {
        if(flag1) {
         last.append(t); 
        } else {
         first.insert(0, t);
        }
      } else {
        if(flag1) {
          first.insert(0, t);
        } else {
          last.append(t);
        }
      }
    }
  }
  if(flag1) {
    reverse(s.begin(), s.end());
    reverse(first.begin(), first.end());
    reverse(last.begin(), last.end());
    cout << last << s << first << endl;
  }
  else {
    cout << first << s << last << endl; 
  }
}

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

int main(){
	/*input*/
	int n;	cin >> n;
	vector<string>s(n);
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	int m;	cin >> m;
	vector<string>t(m);
	for(int i = 0; i < m; i++){
		cin >> t[i];
	}
	/*calculation*/
	vector<int>ans(1);
	for(int i = 0; i < s.size(); i++){
		ans.push_back(0);
		for(int si = 0; si < s.size(); si++){
			if(s[i] == s[si])ans[i]++; 
		}
		for(int ti = 0; ti < t.size(); ti++){
			if(s[i] == t[ti])ans[i]--;
		}
	}
	for(int i = 0; i < t.size(); i++){
		ans.push_back(0);
		for(int si = 0; si < s.size(); si++){
			if(t[i] == s[si])ans[ans.size() - 2]++; 
		}
		for(int ti = 0; ti < t.size(); ti++){
			if(t[i] == t[ti])ans[ans.size() - 2]--;
		}
	}
	/*output*/
	sort(ans.rbegin(), ans.rend());
	cout << ans[0] << endl;
	/*debug*/
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mo = 1e9 + 7;
struct mtr {
	ll a[3][3];
	mtr () {
		memset(a, 0, sizeof a);
	}
	void unitize () {
		for (int i = 0; i < 3; ++i)
			a[i][i] = 1;
	}
} ans, trn, cou;
mtr operator * (const mtr &u, const mtr &v) {
	mtr w;
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 3; ++k)
				w.a[i][j] = (w.a[i][j] + u.a[i][k] * v.a[k][j]) % mo;
	return w;		
}
mtr operator ^ (mtr a, int b) {
	mtr ret; ret.unitize();
	for ( ; b; b >>= 1, a = a * a)
		if (b & 1)
			ret = ret * a;
	return ret;
}

int n, m, las;
void prep () {
	ans.a[0][0] = 1;
	cou.a[0][0] = 1, cou.a[0][1] = 0, cou.a[0][2] = 0;
	cou.a[1][0] = 2, cou.a[1][1] = 1, cou.a[1][2] = 0;
	cou.a[2][0] = 1, cou.a[2][1] = 1, cou.a[2][2] = 1;
	trn.a[0][0] = 1, trn.a[0][1] = 0, trn.a[0][2] = 1;
	trn.a[1][0] = 2, trn.a[1][1] = 1, trn.a[1][2] = 2;
	trn.a[2][0] = 1, trn.a[2][1] = 1, trn.a[2][2] = 2;
}
int main () {
	cin >> n >> m, prep();
	for (int i = 1, x; i <= m; ++i) {
		scanf("%d", &x);
		ans = (trn ^ (x - las)) * ans;
		ans = cou * ans, las = x + 1;
	}
	ans = (trn ^ (n - las)) * ans;
	cout << ans.a[2][0] << endl;
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
k = int(input())

ans = 0

lst = [[0 for _ in range(1, k+1)] for __ in range(k+1)]
cnt = [0 for _ in range(1, k+1)]


for i in range(1, k+1):
    for j in range(1, k+1):
        lst[i-1][j-1] = [gcd(i, j)]
        cnt[gcd(i, j)-1] += 1

ans = 0

for i in range(k):
    for j in range(1, k+1):
        ans += cnt[i]*gcd((i+1),j)

print(ans)


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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; ++i) {
        int f;
        cin >> f;
        sum += f;
    }
    if (sum > n) {
        cout << -1 << endl;
    }
    else {
        cout << n - sum << endl;
    }
    return 0;
}



Measured memory_bytes: 3640
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string s = Console.ReadLine();
    int n = s.Length;
		long answer = 0;

    for(int i = 0; i < n; i++)
    {
      if(s[i] == 'p' && i % 2 == 0) answer--;
      else if(s[i] == 'g' && i % 2 == 1) answer++;
    }

		Console.WriteLine(answer);
	}
}

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

using namespace std;
typedef long long ll;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  ll ans = 1e18;
  for (int i = 0; i < 1 << n; ++i) {
    if (i >> 0 & 1) continue;
    ll ma = a[0];
    vector<ll> tmp = a;
    for (int j = 1; j < n; ++j) {
      if ((i >> j & 1) && a[j] <= ma) {
	tmp[j] += ma - a[j] + 1;
      }
      ma = max(ma, tmp[j]);
    }

    int cnt = 1;
    ll cost = 0;
    ma = a[0];
    for (int j = 1; j < n; ++j) {
      if (tmp[j] > ma) {
	cnt++;
	ma = tmp[j];
      }
      cost += tmp[j] - a[j];
    }
    if (cnt >= k) ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())
dist = {}
distance = 0
for m in range(1, n):
    dist[m] = 0
for i in range(1, n):
    for j in range(i+1, n+1):
        distance = min(j-i, abs(i-x)+abs(j-y)+1)
        dist[distance] += 1
for p in range(1, n):
    print(dist[p])

Measured memory_bytes: 3572
#include<iostream>
#include<string.h>
using namespace std;
char toLowerCase(char ch);
int main()
{
  int n,f,b,k,i;
  string s;
  cin>>n>>k;
  cin>>s;
  for(i=0;i<n;i++)
  {
   if(i==(k-1))
   {
    char a=toLowerCase(s[i]);
    cout<<a;
   }
   else
   cout<<s[i]; 
  }
  
}
char toLowerCase(char ch)
{
	int m=(int)ch;
	m=m+32;
	char c=(char)m;
	return c;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int N, L;
    cin >> N >> L;
    //cout << "taste\n";
    for (int i = 0; i < N; ++i)
    {
        //cout << L + i << " ";
    }
    //1番ゼろにちかいものを消す
    int min = 500, num;
    for (int i = 0; i < N; ++i)
    {
        int tmp = abs(L + i);
        //cout << abs(L + i) << " ";
        if (tmp < min)
        {
            min = tmp;
            num = i;
        }
    }
    int sum = 0;
    for (int i = 0; i < N; ++i)
    {
        if (i != num)
            sum += L + i;
    }
    cout << sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  int counter;
  for(int i=0;i<N;i++){
    while(a.at(i)%2==0){
      counter++;
      a.at(i)/=2;
    }
  }
  cout<<counter<<endl;
}

Measured memory_bytes: 256
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;
#define ll long long int
#define endl '\n'
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef queue<int> qii;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
double pi = 2 * acos(0.0); 

void solve(){
    string a,b;
    cin>>a>>b;
    int ctr=0;
    rep(i,0,a.size()){
        if(a[i]!=b[i]) ctr++;
    }
    cout<<ctr;
}

int main(){ 
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}


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

int main() {
  int a, b;
  int c=1;
  int i;
  cin >> a >> b;

  for(i=0; i<=20; i++){
    if(c>=b) break;
    c=c-1+a;
  }
  cout << i <<endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
p=list(map(float,input().split()))
#dp=[[[0,0]]*(n+1) for _ in range(n+1)]
#dp[0][0]=[1,1]
dp=[[0]*(n+1) for _ in range(n+1)]
dp[0][0]=1
for t in range(1,n+1):
    dp[t][0]=dp[t-1][0]*(1-p[t-1])
    for h in range(1,t+1):
        dp[t][h]=dp[t-1][h-1]*p[t-1]+dp[t-1][h]*(1-p[t-1])
        #dp[t][h][1]=dp[t-1][h-1][1]*p[t-1] + dp[t-1][h][1]*(1-p[t-1])
        #dp[t][h][0]=dp[t-1][h-1][0]*(1-p[t-1]) + dp[t-1][h][0]*p[t-1]
ans=0
for h in range(t//2+1,n+1):
    ans+=dp[n][h]
print(ans)

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

int main() {
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> c(H);
  for(int i = 0; i < H; i++) cin >> c[i];
  int cnt = 0;
  for (int bitH = 0; bitH < (1<<H); bitH++) {
    for (int bitW = 0; bitW < (1<<W); bitW++) {
      int cntblack = 0;
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if (bitH & (1 << i)) {
            if (bitW & (1 << j)) {
              if (c[i][j] == '#') cntblack++;
            }
          }
        }
      }
      if (cntblack == K) cnt++;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 3500
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    s = sorted(list(map(int, input().strip().split())), reverse=True)
    check = [False] * (2**N)
    now = []
    now.append([s[0], 1])
    check[0] = True
    ok = True
    for i in range(N):
        next_ = []
        tmp = 0
        for j in range(len(now)):
            hp, start = now[j]
            start = max(start, tmp)
            ok = False
            for k in range(start, 2**N):
                if s[k] < hp and not check[k]:
                    tmp = k+1
                    now[j][1] = k+1
                    check[k] = True
                    next_.append([s[k], k+1])
                    ok = True
                    break
            if not ok:
                break
        now += next_
        now = sorted(now, reverse=True)
        if not ok:
            break
    
    if ok:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 55964
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)
	ans := 0

	for i := 0; i < n-1; i++ {
		ans += max(0, a[i]-a[i+1])
		a[i+1] += max(0, a[i]-a[i+1])
	}
	fmt.Fprintln(wr, ans)
}


Measured memory_bytes: 5828
from itertools import accumulate
 
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
 
a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))
 
j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    ans = i + j
print(ans)

Measured memory_bytes: 135604
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var s = Console.ReadLine();
            var ret = "";
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '0') ret += "0";
                if (s[i] == '1') ret += "1";
                if (s[i] == 'B' && ret.Length > 0)
                    ret = ret.Substring(0, ret.Length - 1);
            }
            Console.WriteLine(ret);
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 2648
var mini = -1;
var iValue = 0;

function Main(input) {

	input = input.split(" ");
	var N = parseInt(input[0]);
	var L = parseInt(input[1]);
	
	var before = 0.5*N*N + (L-0.5)*N;
	var after  = 0.5*N*N + (L-0.5)*N - L + 1;
	
	for(var i = 1;i < N + 1 ;i++){
	    var value = before - after + i;
	    value = Math.abs(value);
	    
	    if(mini === -1){
	        mini = value;
	        iValue = i;
	    }
	    
	    if(mini > value){
	        mini = value;
	        iValue = i;
	    }
	}
	
	console.log(after - iValue);
	
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    ll a,b,c;
    cin >> a >> b >> c;
    if(a + b == c || b+c==a || c+a==b){
    cout << "Yes" << endl;
    }else {
    cout << "No" << endl;
    }
}




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

Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int n, k; 
    cin >> n >> k;
    vector<int> a(n);
    vector<int> s, t;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i] < 0) t.push_back(a[i]);
        else s.push_back(a[i]);
    }

    int S = s.size();
    int T = t.size();
    bool ok = false;
    if(S > 0){
        if(n==k) ok = (T%2==0);
        else ok = true;
    }
    else{
        ok = (k%2==0);
    }
    mint ans = 1;
   if(!ok){
       sort(a.begin(), a.end(),[](int x, int y) {
      return abs(x) < abs(y);
    });
       for(int i=0; i<k; i++) ans *= a[i];
   }
   else{
       sort(s.begin(), s.end());
       sort(t.rbegin(), t.rend());
       if(k%2==1){
           ans *= s.back();
           s.pop_back();
       }
       vector<ll> p;
       while(s.size() >= 2){
           ll x = s.back(); s.pop_back();
           x *= s.back(); s.pop_back();
           p.push_back(x);
       }
       while(t.size() >= 2){
           ll x = t.back(); t.pop_back();
           x *= t.back(); t.pop_back();
           p.push_back(x);
       }
       sort(p.rbegin(), p.rend());
       for(int i=0; i<k/2; i++) ans *= p[i];
   }

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

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    map<ll,ll> m;
    rep(i,n) {cin>>a[i]; m[a[i]]++;}
    sort(a.begin(),a.end());
    ll res=0;
    rep(i,n){
        if(i>0 && a[i]==a[i-1]) continue;
        if(m[a[i]]>a[i]) res+=m[a[i]]-a[i];
        else if(m[a[i]]<a[i]) res+=m[a[i]];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 7040
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 100000000000000
int main() {
	long long x, y;
	cin >> x >> y;
	long long ans = LONG_INF;
	long long now_x = x;
	long long now_y = y;
	now_x *= -1;
	if (y-now_x >= 0) {
		ans = min(y - now_x+1,ans);
	}//1 reverse
	if (y - x >= 0) {
		ans = min(ans,y - x);
	}//0 reverse
	now_y *= -1;
	if (now_y - now_x >= 0) {
		ans = min(ans, now_y - now_x + 2);
	}
	now_x *= -1;
	if (now_y - now_x >= 0) {
		ans = min(ans, now_y - now_x + 1);
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
n,k=(int(i) for i in input().strip().split(" "))
ar=[int(i) for i in input().strip().split(" ")]
from math import ceil
pos=ar.index(1)
a=n-1-pos
b=pos
a1=(a//(k-1))
a2=b//(k-1)
c=ceil((n-1-((a1+a2)*(k-1)))/(k-1))
print(a1+a2+c)




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

typedef long long int   ll;
#define int             ll
#define PI              3.1415926535897932384626433832795

#define pb              push_back
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]

#define hell            freopen("input.txt","r", stdin);freopen("output.txt", "w", stdout);freopen("error.txt", "w",stderr);
#define fastasF_boi()   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
//#define cerr            if(false)cerr

int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
int mulmod(int a,int b){return ((a%mod)*(b%mod))%mod;}
int addmod(int a,int b){return (((a%mod)+(b%mod))+mod)%mod;}

void solve(){
    int k;cin>>k;
    int num = 0,term= 1;
    map<int,int> mp;
    while(true){
        int rm = num*10 + 7;
        rm %= k;
        if(rm == 0){
            cout<<term;
            return;
        }
        num = rm;
        if(mp[rm] == 1)
            break;
        mp[rm] = 1;
        term++;
    }
    cout<<"-1";
}

signed main(){
//    hell;

    fastasF_boi();
    int t=1;
//    cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
}



Measured memory_bytes: 66136
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll n = 3;
  vector<ll>A(n);
  rep(i,n){
    cin >> A[i];
  }
  sort(A.begin(), A.end()); //小さい順
  cout << A[2] - A[0];
}

Measured memory_bytes: 3640
#include <stdio.h>

int main (void){
    int h[10000],w[10000];
    int i,j,k,l;
    i = 0;
    while(1){
        scanf("%d %d",&h[i],&w[i]);
        if(h[i]==0 & w[i]==0){
            break;
        }
        i++;
    }

    for(j=0;j<i;j++){
//
        for(l=0;l<w[j];l++){
            printf("#");
        }
        printf("\n");
        for(k=0;k<h[j]-2;k++){
            printf("#");
            for(l=0;l<w[j]-2;l++){
                printf(".");
            }
            printf("#\n");
        }
        for(l=0;l<w[j];l++){
            printf("#");
        }        
        printf("\n");
//
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2132
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

bool is_prime(const int x) {
    assert(2 <= x);
    for (int i = 2; i < x; i++) {
        if (x % i == 0) { return false; }
    }
    return true;
}

const int MAX_H = 200;
const int MAX_W = 10;

const long long MOD = 1000000007;

long long H, W, K;

long long dp[MAX_H][MAX_W];
long long res_choice[MAX_W][2];

int main(int argc, char **argv) {
    std::cin >> H >> W >> K;

    res_choice[0][0] = 1;
    res_choice[0][1] = 0;

    for (int i = 1; i <= W; i++) {
        res_choice[i][0] = res_choice[i-1][0] + res_choice[i-1][1];
        res_choice[i][1] = res_choice[i-1][0];
    }

    for (int i = 0; i <= H; i++) {
        for (int j = 0; j <= W+1; j++) {
            dp[i][j] = 0;
        }
    }
    dp[0][1] = 1;

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            dp[i][j] = (dp[i-1][j  ] * res_choice[j-1][0] * res_choice[W - j][0]) % MOD
                     + (dp[i-1][j-1] * res_choice[j-1][1] * res_choice[W - j][0]) % MOD
                     + (dp[i-1][j+1] * res_choice[j-1][0] * res_choice[W - j][1]) % MOD;
        }
    }

    std::cout << (dp[H][K] % MOD) << std::endl;

    return 0;

}

Measured memory_bytes: 256
#include<cstdio>
const int N = 1e5+5;
 
struct Edge{
    int u,v,w,next;
}e[2*N]; int size = 0;
//双向边, 要开二倍空间
int head[N];
int d[N];
int ans[N];
int vis[N];
 
void add_edge(int u,int v,int w){
    e[size].u = u, e[size].v = v, e[size].w = w;
    e[size].next = head[u];
    head[u] = size;
    size++;
}
 
void dfs(int u,int cur){
    vis[u] = 1;
    d[u] = cur;
    for(int i = head[u]; i!=-1; i = e[i].next){
        int v = e[i].v, w = e[i].w;
        if(!vis[v]){
            dfs(v,cur^w);
        }
    }
}
 
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) head[i] = -1,vis[i] = 0; 
    for(int i = 0; i < n-1; i++){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        add_edge(u,v,w);
        add_edge(v,u,w);
    }
    dfs(1,0);
    for(int i = 1; i <= n; i++){
        if(d[i]%2==0){
            printf("0\n");
        }
        else printf("1\n");
    }
    return 0;
}

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

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    ll P,Q,R,res;

    res = 400;

    cin >> P >> Q >> R;

    res = min(res, P+Q);
    res = min(res, Q+R);
    res = min(res, R+P);

    cout << res << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[5];
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            cout<<i+1;
            break;
        }
        else{
            continue;
        }
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> x(n);
    rep(i, 0, n) cin >> x[i];
    ll mx = 1e18;
    rep(i, 1, 101) {
        ll sum = 0;
        rep(j, 0, n) sum += (x[j] - i) * (x[j] - i);
        if (sum < mx) {
            mx = sum;
        }
    }
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

  
void push(int x){
  top++;
  S[top]=x;
  
}
int pop(){
  top--;
  return S[top+1];
 
}
int main(){

  int a,b;
  top=0;
  char s[100];
  
  while(scanf("%s",s) !=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if ( s[0] == '-' ){
      b=pop();
      a=pop();
      push(a-b);
    } else if ( s[0] == '*' ){
      a=pop();
      b=pop();
      push(a*b);
    }
    else {
      push(atoi(s)); 
    }
  }
  
  printf("%d\n",pop());
 
  return 0;
}




Measured memory_bytes: 2108