akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pi acos(-1.0)

#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld\n",a)

#define stll(a) stoll(a,nullptr,10)
#define all(a) a.begin(),a.end()
#define PII pair<ll,ll>
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define EL printf("\n")
#define ff first
#define ss second
#define rev(a) reverse(all(a))


#define mem(ar,val) memset(ar,val,sizeof(ar))
#define ssort(ar) sort(ar.begin(),ar.end())
#define csort(ar,comp) sort(ar.begin(),ar.end(),comp)

#define bug1(a) cout<<"test "<<a<<endl;
#define bug2(a,b) cout<<"test "<<a<<" "<<b<<endl;
#define bug3(a,b,c) cout<<"test "<<a<<" "<<b<<" "<<c<<endl;
#define bug4(a,b,c,d) cout<<"test "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

#define fout freopen("output.txt","w",stdout)
#define fin  freopen("input.txt","r",stdin)

/// unordered_map<int,int>mp;
/// mp.reserve(1024);
/// mp.max_load_factor(0.25);

/// pbds
/// *find_by_order(k) - return k th largest element.. 0 based
/// order_of_key(k) - number of items strictly smaller than k

/*
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
*/

typedef long long ll;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

int main()
{
    string s,t;
    cin>>s>>t;
    ll n = s.length();
    ll cnt =0;
    for(int i=0;i<n;i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }
    cout<<cnt<<endl;
}














Measured memory_bytes: 3852
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int n,dp[2003][2003],a[6003],ans,tg,MX[2003],cur;
int A[100004],B[100004],C[100004],t;
inline void add(int x,int y,int z){A[t]=x,B[t]=y,C[t++]=z;}
int main(){
	cin>>n;
	for(int i=1;i<=3*n;i++)scanf("%d",&a[i]);
	memset(dp,-1,sizeof(dp));
	memset(MX,-1,sizeof(MX));
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=MX[a[1]]=MX[a[2]]=cur=0;
	for(int i=3;i<3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){tg++;continue;}
		t=0;
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i+1]>a[i+2])swap(a[i+1],a[i+2]);
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		for(int j=1;j<=n;j++){
			if(a[i]==a[i+1])if(dp[j][a[i]]>=0)add(j,a[i+2],dp[j][a[i]]+1);
			if(a[i+1]==a[i+2])if(dp[j][a[i+1]]>=0)add(j,a[i],dp[j][a[i+1]]+1);
		}
		if(dp[a[i]][a[i]]>=0)add(a[i+1],a[i+2],dp[a[i]][a[i]]+1);
		if(dp[a[i+1]][a[i+1]]>=0)add(a[i],a[i+2],dp[a[i+1]][a[i+1]]+1);
		if(dp[a[i+2]][a[i+2]]>=0)add(a[i],a[i+1],dp[a[i+2]][a[i+2]]+1);
		add(a[i],a[i+1],cur),add(a[i+1],a[i+2],cur),add(a[i],a[i+2],cur);
		for(int k=1;k<=n;k++)if(MX[k]>=0)add(a[i],k,MX[k]),add(a[i+1],k,MX[k]),add(a[i+2],k,MX[k]);
		for(int j=0;j<t;j++)if(dp[A[j]][B[j]]<C[j])
			dp[A[j]][B[j]]=dp[B[j]][A[j]]=C[j],MX[A[j]]=max(MX[A[j]],C[j]),MX[B[j]]=max(MX[B[j]],C[j]),cur=max(cur,C[j]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)if(dp[i][j]>=0)ans=max(ans,dp[i][j]);
		if(dp[i][i]>=0)if(i==a[3*n])ans=max(ans,dp[i][i]+1);
	}
	printf("%d",ans+tg);
}


Measured memory_bytes: 19632
import java.util.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		int G = sc.nextInt();
		int B = sc.nextInt();
		int N = sc.nextInt();
		long count = 0;
		for (int i = 0; i <= N/R; i++) {
			for (int j = 0; j <= (N-i*R)/G; j++) {
				int result = N-i*R-j*G;
				if (result%B == 0) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<long> x(n);
  vector<long> y(n);
  int i;
  for(i=0;i<n;i++){
    cin >> x[i];
    y[i] = x[i];
  }
  sort(y.begin(),y.end());
  long l = y[(n/2)-1];
  long r = y[(n/2)];
  for(i = 0;i<n;i++){
    if(x[i] <= l){
      cout << r << endl;
    }else{
      cout << l << endl;
    }
  }
}

Measured memory_bytes: 5376
#include<stdio.h>
int main(void){
	int h,w;
	int i,j;
	while(1){
		scanf("%d%d",&h,&w);
		if(h==0 && w==0)break;
		else
			for(i=0;i<h;i++){
				for(j=0;j<w;j++)printf("#");
				printf("\n");
			}
			printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
n = int(input())
H = list(map(int, input().split()))
H.append(0)

total = 0
counter = 0
while H.count(0) != len(H) and counter < 1:
  left = 0
  right = 0
  for i in range(len(H)):
    if H[i] != 0:
      left = i
      break
  for i in range(i+1, len(H)):
    if H[i] == 0:
      right = i
      break
  #print(left, right)
  min_val = min(H[left:right])
  total += min_val
  H[left:right] = map(lambda x: x - min_val, H[left:right])
#  print(H)
#  counter = 1
print(total)

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n;
	cin >> n;
	string a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	REP(i, n){
		if(a[i] == b[i] && b[i] == c[i]) continue;
		else if(a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) ans++;
		else ans+=2;
	}
	cout << ans << endl;
} 

Measured memory_bytes: 256
n = int(input())
a = []
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
sum = 0
for i in range(n+1):
    sum += abs(a[i]-a[i+1])
for i in range(1, n+1):
    print(sum - abs(a[i-1]-a[i]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]))


Measured memory_bytes: 64364
//
// Created by Yoshiki Shino on 2018/07/29.
//

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int Sn = 0;
    int N_temp = N;

    while(N_temp > 0) {
        Sn += N_temp % 10;
        N_temp /= 10;
    }

//    cout << "Sn:" << Sn << ", N:" << N <<endl;

    if (N % Sn == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }
int main() {
  char prev = ' ';
  int N, ans = 0; std::string S; std::cin >> N >> S;
  for(int i = 0; i < N; ++i) {
    if(S[i] != prev) { ++ans; prev = S[i]; }
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 512
S = input()
N = len(S)

ans = "Yes"

if not S == S[::-1]:
  ans = "No"

T = S[0:(N-1)//2]
if not T == T[::-1]:
  ans = "No"

U = S[(N+3)//2-1:N]
if not U == U[::-1]:
  ans = "No"

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
  int H,W,a,b,c,d,e;
  for(;;){ 
    scanf("%d%d",&H,&W);
      
    
    if(H==0&&W==0) break;
 
    for(a=0;W-1>=a;a++){
      printf("#");
     
    
      for(c=3;H>=c;c++){    
	if(a==W-1) printf("\n#");
	if(a==W-1) for(d=0;W-3>=d;d++){ printf(".");}
	if(a==W-1) printf("#");
      }

    }
  
      
    printf("\n");
    for(e=0;W-1>=e;e++){ printf("#");}
    printf("\n\n");
 
 }

  return 0;
}

Measured memory_bytes: 600
// Problem: D - Alter Altar
// Contest: AtCoder - AtCoder Beginner Contest 174
// URL: https://atcoder.jp/contests/abc174/tasks/abc174_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Muallif: Azimjon Mehmonali o'g'li

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define F first
#define S second
#define pb push_back
#define endl "\n"

#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(ALL(a))
#define rSORT(a) sort(rALL(a))
#define REV(a) reverse(ALL(a))
#define sqr(x) ((x) * (x))

//===========================================================

int recur_depth = 0;
#ifdef DEBUG
#define xtp(x)                                                           \
	{                                                                    \
		++recur_depth;                                                   \
		auto x_ = x;                                                     \
		--recur_depth;                                                   \
		cerr << string(recur_depth, '\t') << __func__ << ":" << __LINE__ \
			 << "\t" << #x << " = " << x_ << endl;                       \
	}
#else
#define xtp(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<(
	Ostream& os, const Cont& v) {
	os << "[";
	for (auto& x : v) {
		os << x << ", ";
	}
	return os << "]";
}
template <typename Ostream, typename... Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p) {
	return os << "{" << p.first << ", " << p.second << "}";
}

//===========================================================

#define TEZ                  \
	ios::sync_with_stdio(0); \
	cin.tie(0);

const long double PI = 3.1415926535897932384626433832795;
const ll mod = 1000000007LL;
const int INF = 1000000000;
const ll LINF = 1000000000000000000LL;

int main() {
	TEZ;

	int n;
	cin >> n;

	string s;
	cin >> s;

	vll b;
	b.pb(0);

	for (char c : s) {
		b.pb(b.back() + (bool)(c == 'R'));
	}
	xtp(b);
	ll jv = LINF;
	for (int i = 0; i <= n; i++) {
		ll g = i - b[i];
		ll h = b.back() - b[i];
		jv = min(jv, max(g, h));
	}

	cout << jv << endl;

	return 0;
}


Measured memory_bytes: 5516
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(int i=a;i<b;i++)
#define bfr(i,a,b) for(int i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007 
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back

#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 

/*
bool comp(pair<lli,lli> &a,pair<lli,lli> &b)
{
    if()
}*/




int main()
{
                       
         

                    
          fio
          

         lli n,x,y;
         cin>>n>>x>>y;
         vector<lli> adj[n];
         fr(i,0,n-1)
         {adj[i].push_back(i+1);
         adj[i+1].pb(i);}
         adj[x-1].pb(y-1);
         adj[y-1].pb(x-1);


         map<lli,lli> m; 


         fr(i,0,n)
         {
            queue<pair<lli,lli>> q;
            q.push({i,0});
            bool vis[n];
            memset(vis,false,n);

            while(!q.empty())
            {
                 lli k=q.front().first,dis=q.front().second;
                 q.pop();
                
                 if(vis[k])continue;
                //  cout<<k<<" "<<dis<<'\n';
                 vis[k]=true;
                 m[dis]++;
                 fr(j,0,adj[k].size()){if(!vis[adj[k][j]])q.push({adj[k][j],dis+1});}
            }
           // cout<<"---->\n";
         }

         vector<lli> ans(n);
         for(auto p:m)ans[p.first]=p.second/2;
            fr(i,1,n)cout<<ans[i]<<'\n';

          
          
          

         










          





                     
return 0;}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++){
    s.at(i)+=n;
    if(s.at(i)>90){
      s.at(i)-=26;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
    char s[101];
    char ss[201];
    char p[101];

    scanf("%s", s);
    scanf("%s", p);

    strcpy(ss, s);
    strcat(ss, s);

    if (strstr(ss, p) != NULL)
        puts("Yes");
    else
        puts("No");

    return 0;
}



Measured memory_bytes: 2100
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def z_algorithm(s):
    """
    各iについてs[0..n)とs[i..n)のLCP(Longest Common Prefix)の長さを求める
    s: str or (list of int )
    """
    n = len(s)
    if n==0:
        return []
    z = [None]*n
    z[0] = 0
    j = 0
    for i in range(1,n):
        k = 0 if j + z[j] <= i else min(j+z[j]-i, z[i-j])
        z[i] = k
        while i+k<n and s[k]==s[i+k]:
            k += 1
        z[i] = k
        if j+z[j] < i+z[i]:
            j = i
    z[0] = n
    return z
n = int(input())
s = input()
ans = 0
for i in range(n):
    z = z_algorithm(s[i:])
    val = -1
    for j in range(len(z)):
        val = max(val, min(z[j], j))
    ans = max(ans, val)
#     print(z)
print(ans)

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

class Combination:                                      # 計算量は O(n_max + log(mod))
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):                     # 階乗(= n_max !)の逆元を生成
            f = f * i % mod                             # 動的計画法による階乗の高速計算
            fac.append(f)                               # fac は階乗のリスト
        f = pow(f, mod-2, mod)                          # 階乗から階乗の逆元を計算。フェルマーの小定理より、　a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime
                                                        # python の pow 関数は自動的に mod の下での高速累乗を行ってくれる
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):                   # 上記の階乗の逆元から階乗の逆元のリストを生成（＝ facinv ）
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    def __call__(self, n, r):  # self.C と同じ
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def H(self, n, r):                                  # (箱区別:〇　ボール区別:×　空箱:〇)　重複組み合わせ nHm
        if (n == 0 and r > 0) or r < 0: return 0
        return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod


n, k = map(int, input().split())
MOD = 10**9 + 7
C = Combination(n)

k = min(k,n-1)
res = 0
for l in range(k+1):
    res += C(n,l)*C.H(n-l,l)
print(res%MOD)


Measured memory_bytes: 103768
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    while(true)
    {
        cin>>a>>b;
        if(a==0&b==0) 
        break;
        if(a>b) cout<<b<<" "<<a<<endl;
        else cout<<a<<" "<<b<<endl;
    }
}


Measured memory_bytes: 2984
n = gets.to_i
b = Array.new(n)
f = Array.new(n)
r = Array.new(n)
v = Array.new(n)
n.times do |i|
	b[i],f[i],r[i],v[i] = gets.chomp.split(" ")
end
data = Array.new(4).map{Array.new(3)}
4.times do |i|
	3.times do |j|
		data[i][j] = [0,0,0,0,0,0,0,0,0,0]
	end
end
n.times do |i|
	data[b[i].to_i - 1][f[i].to_i - 1][r[i].to_i - 1] += v[i].to_i
end
4.times do |i|
	3.times do |j|
		data[i][j] = data[i][j].join(" ")
		print " "
		puts data[i][j]
	end
	puts "####################" if i != 3
end

Measured memory_bytes: 8796
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...

    int x,y;
    
    while(1)
    {
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0)break;
        else
        {
            if(x>y)printf("%d %d\n",y ,x);
            else printf("%d %d\n",x ,y);
        }
        
    }
    
    return 0;
}


Measured memory_bytes: 1916
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <bitset>
#include <vector>
using namespace std;
 
const int N = 1e5;
int l[N], r[N], s[N];

int main() {
    int n;
    scanf("%d", &n);
    bool ok = false;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &l[i], &r[i]);
        if (l[i] == r[i]) {
            s[i] = 1;
        }
        if (i < 2) {
            continue;
        }
        if (s[i] + s[i - 1] + s[i - 2] == 3) {
            ok = true;
        }
    }
    if (ok) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 3764
#include <cstdio>
#include <vector>
using namespace std;

const int inf = (((1 << 30) - 1) << 1) + 1;

struct segtree1 {

	int *dat;
	
	void init(int *raw, int s)
	{
		dat = raw;
	
		for(int i = 0; i < s * 2; ++i)
			dat[i] = inf;
	}
	
	void set(int x, int v, int s)
	{
		int pos = s + x;
		
		dat[pos] = v;
		pos = pos / 2;
		
		while(pos > 0) {
		
			dat[pos] = min(dat[pos * 2 + 0], dat[pos * 2 + 1]);
			pos = pos / 2;
		}
	}
	
	void setmin(int x, int v, int s)
	{
		int pos = s + x;
		if(dat[pos] > v)
			set(x, v, s);
	}
	
	int getmin(int a, int b, int l, int r, int idx)
	{
		if(b <= l || r <= a) return inf;
		
		if(a <= l && r <= b) {
		
			return dat[idx];
		
		} else {
		
			int m = (l + r) / 2;
			int ret = inf;
			
			ret = min(ret, getmin(a, b, l, m, idx * 2 + 0));
			ret = min(ret, getmin(a, b, m, r, idx * 2 + 1));
		
			return ret;
		}
	}
	
	int getmin(int a, int b, int s)
	{
		return getmin(a, b, 0, s, 1);
	}
};

struct segtree2 {
	
	vector<segtree1> dat;
	vector<int> raw;
	int w, h;
	
	void init(int width, int height)
	{
		w = 1;
		while(w < width) w *= 2;
		
		h = 1;
		while(h < height) h *= 2;
		
		dat.resize(h * 2);
		raw.resize((h * 2) * (w * 2));
		for(int i = 0; i < h * 2; ++i)
			dat[i].init(&raw[i * (w * 2)], w);
	}
	
	void set(int x, int y, int v)
	{
		int pos = h + y;
		
		dat[pos].set(x, v, w);
		pos = pos / 2;
		
		while(pos > 0) {
		
			dat[pos].setmin(x, v, w);
			pos = pos / 2;
		}
	}
	
	int getmin(int ax, int ay, int bx, int by, int l, int r, int idx)
	{
		if(by <= l || r <= ay) return inf;
		
		if(ay <= l && r <= by) {
		
			//printf("[debug] getmin(%d, %d, %d, %d, %d, %d, %d) = %d\n", ax, ay, bx, by, l, r, idx, dat[idx].getmin(ax, bx));
			return dat[idx].getmin(ax, bx, w);
		
		} else {
		
			int m = (l + r) / 2;
			int ret = inf;
			
			ret = min(ret, getmin(ax, ay, bx, by, l, m, idx * 2 + 0));
			ret = min(ret, getmin(ax, ay, bx, by, m, r, idx * 2 + 1));
		
			//printf("[debug] getmin(%d, %d, %d, %d, %d, %d, %d) = %d\n", ax, ay, bx, by, l, r, idx, ret);
			return ret;
		}
	}
	
	int getmin(int ax, int ay, int bx, int by)
	{
		return getmin(ax, ay, bx, by, 0, h, 1);
	}
};


int main()
{
	while(true) {
	
		int r, c, q;
		segtree2 st;
		
		scanf("%d%d%d", &r, &c, &q);
		
		if(r == 0 && c == 0 && q == 0)
			break;
			
		st.init(r, c);
		
		for(int x = 0; x < r; ++x) {
			for(int y = 0; y < c; ++y) {
			
				int v;
				
				scanf("%d", &v);
				
				st.set(x, y, v);
			}
		}
		
		for(int i = 0; i < q; ++i) {
		
			int r1, c1, r2, c2;
			
			scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
			
			int ans = st.getmin(r1, c1, r2 + 1, c2 + 1);
			
			printf("%d\n", ans);
		}
	}
	
	return 0;
}

Measured memory_bytes: 35624
#%%
a, b = map(int, input().split())

def xor(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0

print(xor(a-1) ^ xor(b))


Measured memory_bytes: 2940
#include<stdio.h>

int main(){
 	int H, A;
 	scanf("%d %d", &H, &A );
 	if(H%A>0){
 		printf("%d", H/A + 1);
	 }
 	else{
 		printf("%d", H/A);
	 }
	 return 0;
 }

Measured memory_bytes: 3192
n = int(input())
A = list(map(int,input().split()))
x = 0
for i in range(n):
    if i%2==0:
        x+=A[i]
    else:
        x-=A[i]
B = [x//2]
for i in range(n-1):
    B.append(A[i]-B[-1])
ans = [2*b for b in B]
print(" ".join(map(str,ans)))

Measured memory_bytes: 85476
#include<stdio.h>

int main(){
  int h,n; scanf("%d%d",&h,&n);
  for(int i=0; i<n; i++){
    int t; scanf("%d",&t); h-=t;
  }
  if(h<=0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
n = int(input())
a = input().split()
w = int(a[n - 1])
amax = w
amin = w
asum = w
n -= 1
while n - 1 >= 0:
    w = int(a[n - 1])
    if w > amax:
        amax = w
    if w < amin:
        amin = w
    asum += w
    n -= 1

print(str(amin) + ' ' + str(amax) + ' ' + str(asum))

Measured memory_bytes: 8488
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


K, N = MI()
A = LMI()

m = 0
for i in range(N - 1):
    m = max(m, A[i + 1] - A[i])
m = max(m, K - A[-1] + A[0])
print(K - m)

Measured memory_bytes: 72396
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	list := make([]int, a)
	for i := 0; i < a; i++ {
		fmt.Scan(&list[i])
	}

	sort.Ints(list)

	count := 0
	for i := 0; i < a; i++ {
		if b < list[i] {
			count = i
			break
		}
		b -= list[i]
		if b <= 0 {
			count = i + 1
			break
		}
		count = i
	}

	fmt.Println(count)

}


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

void f(long long H,long long W){
	long long g = __gcd(H,W);
	H /= g;
	W /= g;
	if( W % 2 == 0 || H % 2 == 0 ){
		cout << 1 << " " << 1 << endl;
	}else{
		long long b = (H+1)/2 + (W-1)/2*H;
		long long a = b-1;
		long long g = __gcd(a,b);
		b /= g;
		a /= g;
		if( a == 0 ) cout << 1 << " " << 0 << endl;
		else cout << b << " " << a << endl;	
	}
}


int main(){
	int H,W;
	int T;
	cin >> T;
	while(T--){
		cin >> H >> W;
		f(H,W);
	}
	
}

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

int main() {
    // input
    int N, K;
    cin >> N >> K;

    // solve
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        sum += min(abs(x - 0), abs(x - K));
    }

    // output
    cout << sum * 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

ios_base::sync_with_stdio(false), cin.tie(NULL);
int s;
cin>>s;
long long int sum=0;
int max_till_now=0;
for(int i=0;i<s;i++)
{
int j;
cin>>j;
if(j>max_till_now)
max_till_now=j;
else
sum+=(max_till_now-j);
}
cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 3640
#include<stdio.h>

int main(void){
  long long i,j;
  int n,prime[50001];

  prime[0]=1;
  prime[1]=1;

  for(i=2;i<50001;i++)
    prime[i]=0;

  for(i=2;i<50001;i++){
    if(prime[i]==0){
      for(j=i*i;j<50001;j+=i)
	prime[j]=1;
    }
  }

  while(1){
    int count=0;
    scanf("%d",&n);
    if(n==0)break;    

    for(i=0;i<n/2+1;i++)
      if(prime[i]==0 && prime[n-i]==0)count++;
    
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C {
    class questionC {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            int x = 0;
            int y = 0;
            int t = 0;
            bool ok = true;
            for(int i = 0; i < N; i++) {
                int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                int tNext = input[0];
                int xNext = input[1];
                int yNext = input[2];
                int xdiff = Math.Abs(xNext - x);
                int ydiff = Math.Abs(yNext - y);
                int diff = xdiff + ydiff;
                int tDiff = tNext - t;
                if(tDiff < diff || tDiff % 2 != diff % 2) {
                    ok = false;
                }
                t = tNext;
                x = xNext;
                y = yNext;
            }
            // Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            // Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
            if (ok) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 17360
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    char c;
    cin >> c;
    cout << (char)(c+1) << endl;

}

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

int main() {
    double x1, y1, x2, y2;
    cin>>x1>>y1>>x2>>y2;
    double ret = sqrt(pow((x2-x1), 2.0)  + pow((y2-y1), 2.0 ));
    printf("%.6f\n", ret);
    return 0;
}

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

int main()
{
	int n = 0;
	long a[50] = { 1, 1 };

	cin >> n;

	if (n > 1) {
		for (int i = 2; i <= n; i++)
			a[i] = a[i - 1] + a[i - 2];
	}

	cout << a[n] << endl;

	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, pair<int, int> > pp;

int main() {
    int n, w, h;
    while (cin >> n >> w >> h, n|w|h) {
        vector<pp> ps;
        ps.push_back(make_pair(w*h, make_pair(w, h)));
        for (int i = 0; i < n; i++) {
            int j, s;
            cin >> j >> s;
            j--;
            int cw = ps[j].second.first;
            int ch = ps[j].second.second;
            ps.erase(ps.begin() + j);
            s %= (cw + ch) * 2;
            vector<pp> nps(2);
            if (s > 2 * cw + ch) {
                int nh = s - (2 * cw + ch);
                nps[0] = make_pair(cw * nh, make_pair(cw, nh));
                nps[1] = make_pair(cw * (ch - nh), make_pair(cw, ch - nh));
            } else if (s > cw + ch) {
                int nw = s - (cw + ch);
                nps[0] = make_pair(nw * ch, make_pair(nw, ch));
                nps[1] = make_pair((cw - nw) * ch, make_pair(cw - nw, ch));
            } else if (s > cw) {
                int nh = s - cw;
                nps[0] = make_pair(cw * nh, make_pair(cw, nh));
                nps[1] = make_pair(cw * (ch - nh), make_pair(cw, ch - nh));
            } else {
                int nw = s;
                nps[0] = make_pair(nw * ch, make_pair(nw, ch));
                nps[1] = make_pair((cw - nw) * ch, make_pair(cw - nw, ch));
            }
            sort(nps.begin(), nps.end());
            ps.insert(ps.end(), nps.begin(), nps.end());
        }
        sort(ps.begin(), ps.end());
        for (int i = 0, size = ps.size(); i < size; i++) {
            if (i > 0) {
                cout << " ";
            }
            cout << ps[i].first;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1200
s = input()

## 正答
print(s.rfind('Z') - s.find('A') + 1)

## 下記は正答だが処理時間が長すぎたケース
# betweenLength = []
# for i in range(len(s)):
#     if s[i] == 'A':
#         for j in range(len(s)):
#             if i < j and s[j] == 'Z':
#                 betweenLength.append(len(s[0:j]) + 1 - len(s[0:i]))

# print(max(betweenLength))


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

int main(){
  int N;
  cin >> N;
  cout << (N == 1 ? 0 : 1) << endl;
}

Measured memory_bytes: 3620
package main

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

var sc *bufio.Scanner

func init() {
	sc = bufio.NewScanner(os.Stdin)
	buffsize := 1000000
	buff := make([]byte, buffsize)
	sc.Buffer(buff, buffsize)
	sc.Split(bufio.ScanWords)
}

func loadint() (result int) {
	sc.Scan()
	result, _ = strconv.Atoi(sc.Text())
	return
}

func loadints(n int) []int {
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = loadint()
	}
	return xs
}

type Pair struct {
	k int
	v int
}

type PairList []Pair

func (a PairList) Len() int {
	return len(a)
}

func (a PairList) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func (a PairList) Less(i, j int) bool {
	return a[j].v < a[i].v
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func count(vs []int) PairList {
	counter := make(map[int]int)
	for _, v := range vs {
		counter[v]++
	}
	pairs := PairList{Pair{0, 0}}
	for k, v := range counter {
		pairs = append(pairs, Pair{k, v})
	}
	sort.Sort(pairs)
	return pairs
}

func main() {
	n := loadint()

	odd_v := make([]int, n/2)
	even_v := make([]int, n/2)
	for i := 0; i < n/2; i++ {
		odd_v[i] = loadint()
		even_v[i] = loadint()
	}

	odd_counter := count(odd_v)
	even_counter := count(even_v)

	result := n
	if odd_counter[0].k == even_counter[0].k {
		result = n - max(odd_counter[0].v+even_counter[1].v, odd_counter[1].v+even_counter[0].v)
	} else {
		result = n - odd_counter[0].v - even_counter[0].v
	}
	fmt.Println(result)
}


Measured memory_bytes: 9344
N = int(input())
C = input()

r = 0
w = 0

for i in range(N):
    if C[i] == 'R':
         r += 1
    else:
         w += 1

s = 0

for i in range(r):
    if C[i] == 'W':
        s += 1

print(s)

Measured memory_bytes: 9464
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * https://abc057.contest.atcoder.jp/tasks/abc057_d
 */
public class Main {


	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		long[] v = new long[N];
		for(int i=0; i<N; i++) v[i] = sc.nextLong();
		sc.close();
		
	 	Arrays.sort(v);
		long[] dp = new long[N];
		dp[0] = v[N-1];
		for(int i=1; i<N; i++){ 
			dp[i] = dp[i-1]+v[N-1-i];
		}
		Map<Long, Integer> countDp = new HashMap<Long, Integer>();
		Map<Long, Integer> startDp = new HashMap<Long, Integer>();
		for(int i=0; i<N; i++){ 
			if(countDp.containsKey(v[i])){
				countDp.put(v[i], countDp.get(v[i])+1);
			}else{
				countDp.put(v[i], 1);
				startDp.put(v[i], i);
			}
		}
		
		long max = 0;
		int num = 1;
		long ans = 0;
		for(int n=A; n<=B; n++){
			long value = dp[n-1];
			if(value*num<max*n) continue;
			long min = v[N-1-n+1];
			long count = getCombination(countDp.get(min), countDp.get(min)+startDp.get(min)-(N-1-n+1));
			if(max*n==value*num){
				ans = ans + count;
			}else{
				num = n;
				max = value;
				ans = count;
			}
		}
 
		System.out.println((double)max/num);
		System.out.println(ans);
		

	}
	
	static long getCombination(int n, int r){
		if (r == 1) {
	        return n;
	    }
	    long sum = 1;
	    for (int i = 1; i <= r; i++) {
	    	sum = sum * (n - i + 1) / i;
	    }
	    return sum;
	}
	
}

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

using namespace std;


int main() {
  
      int h,w;
      cin>>h>>w;
      int i,j,k,cnt=0;
      char mat[h+1][w+1];
      
      for(i=0;i<h;++i)
         {
             for(j=0;j<w;++j)
               {
                   cin>>mat[i][j];
               }
         }
         
       for(i=0;i<h;++i)
         {  
             cnt=0;
             for(k=0;k<w;++k)
               {
                   if(mat[i][k]=='#')
                      cnt++;
                      
               }
               
              if(cnt==0)
                {
                    for(k=0;k<w;++k)
                       mat[i][k]='*';
                }
                
             
         }
         
         for(j=0;j<w;++j)
          {
              cnt=0;
               for(k=0;k<h;++k)
               {
                   if(mat[k][j]=='#')
                      cnt++;
                      
               }
               
              if(cnt==0)
                {
                    for(k=0;k<h;++k)
                       mat[k][j]='*';
                }
              
          }
          
          int flag;
          for(i=0;i<h;++i)
            { 
                 flag=0;
                for(j=0;j<w;++j)
                  {
                      if(mat[i][j]!='*')
                        { cout<<mat[i][j];
                          flag=1;
                        }
                  }
               if(flag==1)   
                  cout<<endl;
                  
                  
            }
    
    	return 0;
} 

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

typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int inf = 1000000001;

piii pos[N]; int x[N], y[N];

vector<int> g[N]; int nc;
void adde(int u, int v) {
    //cout << u << "->" << v << endl;
    g[u].push_back(v);
}


int id1[1<<16], id2[1<<16];
void build(int p, int lb, int rb) {
    id1[p] = ++nc; g[nc].clear();
    id2[p] = ++nc; g[nc].clear();
    if (lb + 1 == rb) {
        adde(id1[p], pos[lb].second.second);
        adde(pos[lb].second.first, id2[p]);
    }
    else {
        int mid = (lb + rb) >> 1;
        build(p << 1, lb, mid);
        build(p << 1 | 1, mid, rb);
        adde(id1[p], id1[p << 1]);
        adde(id1[p], id1[p << 1 | 1]);
        adde(id2[p << 1], id2[p]);
        adde(id2[p << 1 | 1], id2[p]);
    }
}

int opp(int x) { return x & 1 ? x + 1 : x - 1; }

void adde(int l, int r, int x, int p, int lb, int rb) {
    if (l >= r) return;
    if (l <= lb && rb <= r) {
        adde(x, id1[p]);
        adde(id2[p], opp(x));
    }
    else {
        int mid = (lb + rb) >> 1;
        if (l < mid) adde(l, r, x, p << 1, lb, mid);
        if (r > mid) adde(l, r, x, p << 1 | 1, mid, rb);
    }
}

int dfn[M], low[M], bel[M], dfc, scc;
bool inst[M]; int scs[M], *sct = scs;
void scc_clr(int n) { scc = 0; fill(dfn + 1, dfn + n + 1, 0); }
int dfs_scc(int u) {
    *sct++ = u; inst[u] = 1;
    dfn[u] = low[u] = ++dfc;
    for (int v : g[u]) {
        if (!dfn[v]) low[u] = min(low[u], dfs_scc(v));
        else if (inst[v]) low[u] = min(low[u], dfn[v]);
    }
    if (dfn[u] == low[u])
        for (++scc; *sct != u; --sct)
            bel[sct[-1]] = scc, inst[sct[-1]] = 0;
    return low[u];
}

bool check(int d, int n) {
    int m = 2 * n;
    nc = m;
    for (int i = 1; i <= m; ++i)
        g[i].clear();
    build(1, 1, m + 1);
    //cout << string(79, '-') << endl;
    for (int i = 1; i <= m; ++i) {
        int lx = pos[i].first - d, rx = pos[i].first + d;
        int l = upper_bound(pos + 1, pos + m + 1, piii(lx, pii(inf,inf))) - pos;
        int r = lower_bound(pos + 1, pos + m + 1, piii(rx, pii(0,0))) - pos;
        int x = pos[i].second.first;
        adde(l, i, x, 1, 1, m + 1);
        adde(i + 1, r, x, 1, 1, m + 1);
    }
    //cout << string(79, '=') << endl;
    scc_clr(nc);
    for (int i = 1; i <= nc; ++i)
        if (!dfn[i]) dfs_scc(i);

    for (int i = 1; i <= m; ++i) {
        if (i & 1) {
            if (bel[i] == bel[i + 1])
                return false;
        }
    }
    return true;
}

int main(void){
    ios::sync_with_stdio(0); cin.tie(0);
//#ifndef ONLINE_JUDGE
//    ifstream cin("1.in");
//#endif // ONLINE_JUDGE

    int n; cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i] >> y[i];
        pos[i * 2 - 1] = { x[i], pii(i * 2 - 1, i * 2) };
        pos[i * 2] = { y[i], pii(i * 2, i * 2 - 1) };
    }

    sort(pos + 1, pos + 2 * n + 1);

    int l = 1, r = inf;
    while (l <= r) {
        int mid = (l + r) >> 1;
        if (!check(mid, n)) r = mid - 1;
        else l = mid + 1;
    }

    cout << r << endl;

	return 0;
}


Measured memory_bytes: 43520
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ld = long double;

const int N = 200001;
ll a[N], b[N], g[N], used[N], lp[N];

int main() {
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, k;
    cin >> n >> k;
    rep(i, N)
        lp[i] = used[i] = b[i] = g[i] = -1;
    rep(i, n) {
        cin >> a[i];
        if (b[a[i]] > -1)
            g[b[a[i]]] = i - b[a[i]];
        b[a[i]] = i;
    }
    rep(i, n) {
        if (b[a[i]] > -1 && g[b[a[i]]] == -1)
            g[b[a[i]]] = n + i - b[a[i]];
        b[a[i]] = i;
    }
    ll pos = 0;
    while (used[pos % n] == -1) {
        used[pos % n] = pos;
        pos += g[pos % n] + 1;
    }
    ll f = used[pos % n], d = pos - f, s = 0, m = n * k;
    if (f < m)
        s = f + (m - f - 1) / d * d;
    while (s + g[s % n] < m)
        s += g[s % n] + 1;
    vector<ll> st;
    for (; s < m; s++) {
        ll x = a[s % n];
        if (lp[x] == -1) {
            lp[x] = st.size();
            st.push_back(x);
        }
        else
            while (lp[x] > -1) {
                lp[st.back()] = -1;
                st.pop_back();
            }
    }
    for (ll i : st)
        cout << i << ' ';
}



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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int n;
    cin >> n;

    long long int p = n % 10;
    if ( p == 2 || p == 4 || p == 5 || p == 7 || p == 9 ) {
        cout << "hon" << endl;
    } else if ( p == 3 ) {
        cout << "bon" << endl;
    } else {
        cout << "pon" << endl;
    }

    return 0;

}


Measured memory_bytes: 3640
N = int(input())
X = list(map(int, input().split()))

X.sort()

ans = 0

for i in range(X[-1] - X[0] + 1):
    tmp = 0
    for j in X:
        tmp += (j - (X[0] + i))**2
    
    if i == 0:
        ans = tmp
    else:
        if ans > tmp:
            ans = tmp

print(ans)

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

int main() {
	int a,b,c,x,ans=0;
	cin >> a >> b >> c >> x;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(500*i+100*j+50*k == x) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n;
    cin >> n;
    for(int i = 0;i < n.size();i++) {
        if(n[i] == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        k = k < n ? k : n;
        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);

        for (int i = 2; i < n; i++) {
            dp[i] = dp[i - 1] + Math.abs(h[i] - h[i - 1]);
            for (int j = 2; j <= k && 0 <= i - j; j++) {
                dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(h[i] - h[i - j]));
                if (k == j) {
                    break;
                }
            }
        }

        out.println(dp[n - 1]);

        out.flush();

    }
    
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 34236
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int main(){
  int N,K,X;
  int sum=0;
  scanf("%d %d",&N,&K);
  for(int i=0;i<N;i++){
    scanf("%d",&X);
    sum+=2*min(X,abs(X-K));
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
#pragma region
// Author: Wenxing Mei
//   Date: 2018-09-01 20:24
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define per(i, r, l) for (int i = (int)(r); i >= (int)(l); --i)
#define repv(ele, vec) for (auto &ele : vec)
#define zero(mem) memset(mem, 0, sizeof(mem))
#define sd(_) scanf("%d", &_)
#define sdd(_, __) scanf("%d%d", &_, &__)
#define sddd(_, __, ___) scanf("%d%d%d", &_, &__, &___)
#define sdddd(_, __, ___, ____) scanf("%d%d%d%d", &_, &__, &___, &____)
#define sf(_) scanf("%lf", &_)
#define sff(_, __) scanf("%lf%lf", &_, &__)
#define sfff(_, __, ___) scanf("%lf%lf%lf", &_, &__, &___)
#define sffff(_, __, ___, ____) scanf("%lf%lf%lf%lf", &_, &__, &___, &____)
#define sl(_) scanf("%lld", &_)
#define sll(_, __) scanf("%lld%lld", &_, &__)
#define slll(_, __, ___) scanf("%lld%lld%lld", &_, &__, &___)
#define sllll(_, __, ___, ____) scanf("%lld%lld%lld%lld", &_, &__, &___, &____)
#define sc(_) scanf("%c", &_)
#define ss(_) scanf("%s", _)
#define sz(x) (int)(x).size()
#define boost                                                                                                          \
  ios_base::sync_with_stdio(0);                                                                                        \
  cin.tie(0);
#define mid(a, b) (((a) + (b)) >> 1)
#define lfg(x) x << 1
#define rht(x) x << 1 | 1
#define inf 0x3f3f3f3f
#define all(container) container.begin(), container.end()
//#define MOD 19260817
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#pragma endregion

// Read the question correctly
// What are the exact constraints?
// Look out for SPECIAL CASES (n=1? n=1000000000?) and overflow (ull vs int?)

int main() {
  int k;
  sd(k);
  cout << k / 2 * (k - k / 2) << endl;
  return 0;
}


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

int main(){
  int a,b; cin >> a >> b;
  if( a > b ){ swap(a,b);}
  
  for(int i = 0; i < b; i++){ cout << a;}
  cout << endl;
  
  return 0;
} 

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

int main() {
	int n;
	int west=0, east = 0;
	string s;
	bool flag;
	cin >> n >> s;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'E')++east;
	}
	int minv = east;
	for (int i = 0; i < n; ++i) {
		flag = false;
		if (s[i] == 'E')--east;
		else flag = true;
		minv = min(minv, (west + east));
		if (flag)++west;
	}
	cout << minv << endl;
	return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n, m;
    cin >> n >> m;
    priority_queue<Pl, vector<Pl>, greater<Pl>> que;
    for(int i = 0; i < n; ++i){
        ll a;
        int b;
        cin >> a >> b;
        que.push(P(a, b));
    }
    ll res = 0;
    while(m > 0){
        P p = que.top();
        que.pop();
        ll cost = p.first;
        int cnt = p.second;
        if(cnt < m){
            res += cost * cnt;
            m -= cnt;
        }
        else{
            res += cost * m;
            break;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define si set<int>
#define sll set<ll>
#define ins insert
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define mod 1000000007
using namespace std;
/*lli power(lli a,lli n)
{lli ans=0;
   while(n>0)
   {
      if(n%2)
       {
         ans=ans*a;
         n--; 
       }
      else
        {
         a=a*a;
         n=n/2; 
        }
  }
return ans;
 }*/
/*ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}*/ 
/*int is_prime[1000001];
void sieve(){
    int maxN=1000000;
    for(int i=1;i<=maxN;i++)
    is_prime[i]=1;
    is_prime[0]=is_prime[1]=0;
    for(int i=2;i*i<=maxN;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=maxN;j+=i)
            is_prime[j]=0;
        }
    }
}*/
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
        int n,W;
        cin>>n>>W;
        int w[n],v[n];
        for(int i=0;i<n;i++)
        {
        	cin>>w[i]>>v[i];
        }
        long long dp[n+1][W+1];
        for(int i=0;i<=n;i++)
        {
        	for(int j=0;j<=W;j++)
        	{
        		if(i==0|| j==0)
        		dp[i][j]=0;
        		else
        		{
        			dp[i][j]=dp[i-1][j];
        			if(w[i-1]<=j)
        			dp[i][j]=max(dp[i][j],v[i-1]+dp[i-1][j-w[i-1]]);
        		}
        	}
        }
        cout<<dp[n][W];
return 0;
}

Measured memory_bytes: 79232
N, A, B = map(int, input().split())

SUM=0
for i in range(N+1):
    list_N = list(str(i))
    sum_N = sum(list(map(int, list(list_N))))
    
    if sum_N >= A:
        if sum_N <= B:
            SUM += i

print(SUM)

Measured memory_bytes: 3060