akhauriyash/Code-Regression huggingface dataset:
n = gets.to_s.to_i
s = gets.to_s.split.map{|t| t.to_i }
t = gets.to_s.split.map{|t| t.to_i }

cnt = a = b = 0
(1..n).to_a.permutation do |per|
  
  cnt += 1
  a = cnt if per == s
  b = cnt if per == t
end

puts (a-b).abs

Measured memory_bytes: 14800
#include <cstdio>

using namespace std;

int main(){
  int N;
  int a[3001];
  int sum = 0;

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

  printf("%d\n", sum - N);
     
  return 0;
}


Measured memory_bytes: 128
n,m,k=map(int,input().split())

mod=998244353

MAX_N=n+5
fac = [1,1] + [0]*MAX_N
finv = [1,1] + [0]*MAX_N
inv = [0,1] + [0]*MAX_N
for i in range(2,MAX_N):
  fac[i] = fac[i-1] * i % mod
  inv[i] = mod - inv[mod % i] * (mod // i) % mod
  finv[i] = finv[i-1] * inv[i] % mod

def nCk(n,k):
  if n<k:
    return 0
  if n<0 or k<0:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod

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

print(ans)

Measured memory_bytes: 34220
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a%2&&b%2?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int n;

	cin >> n;

	vector <int> p(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> p[i];
	}

	int cnt = 0;
	for (int i = 1; i < n-1; ++i)
	{
		if ( !(p[i] > p[i - 1] ^ p[i] < p[i + 1]))
		{
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <unordered_set>

using namespace std;

const long double PI = 3.14159265358979323846;

int main()
{
	long double r;
	cin >> r;
	cout << 2 * r * PI;
	return 0;
}

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

#define ll long long
#define ull unsigned long long

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    ll R;
    cin >> R;
    cout << 2 * R * M_PI << endl;
    return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <cmath>

int max_(int* a, int N){
    int ans = 0;
    for(int i=0; i<N; ++i){
        ans = std::max(ans, a[i]);
    }
    for(int i=0; i<N; ++i){
        if(ans == a[i]){
            a[i] = 0;
            break;
        }
    }
    return ans;
}

int main(){
    int N;
    std::cin >> N;
    int a[N];
    for(int i=0; i<N; ++i){
        std::cin >> a[i];
    }
    int A = 0;
    int B = 0;
    for(int i=0; i<N; ++i){
        A += max_(a, N);
        B += max_(a, N);
    }
    std::cout << A - B << std::endl;
}

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

int main()
{
    long a;
    cin >> a;
    switch(a){
    case 22:
        printf("Christmas Eve Eve Eve");
    break;
    case 23:
        printf("Christmas Eve Eve");
    break;
    case 24:
    printf("Christmas Eve");
    break;
    case 25:
    printf("Christmas");
    break;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    int n; cin>>n;
    int a[n],b[n],c[n];
    for(int i=0; i<n; i++){cin>>a[i]; a[i]--;}
    for(int i=0; i<n; i++)cin>>b[i];
    for(int i=0; i<n-1; i++)cin>>c[i];

    ll ans=0;
    int pre=a[0],cur;
    ans = b[pre];
    for(int i=1; i<n; i++){
        cur = a[i];
        ans += b[cur];
        if(cur==pre+1)ans += c[pre];

        pre=cur;
    }
    cout<<ans<<"\n";
}

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

const int N = (int) 1e5;
int h[N];

int main() {
	ios::sync_with_stdio(false);
	int n, a, b; cin >> n >> a >> b;
	for (int i = 0; i < n; ++i) cin >> h[i];
	int low = 0, high = (int) 1e9;
	while (low < high) {
		int mid = (low + high) / 2;
		long long need = 0;
		for (int i = 0; i < n; ++i) if (h[i] > 1LL * b * mid) {
			need += (h[i] - b * mid + (a - b - 1)) / (a - b);
		}
		if (need <= mid) high = mid;
		else low = mid + 1;
	}
	cout << low << '\n';
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

template< unsigned mod >
struct RollingHash {
  vector< unsigned > hashed, power;

  inline unsigned mul(unsigned a, unsigned b) const {
    unsigned long long x = (unsigned long long) a * b;
    unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
    return m;
  }

  RollingHash(const string &s, unsigned base = 10007) {
    int sz = (int) s.size();
    hashed.assign(sz + 1, 0);
    power.assign(sz + 1, 0);
    power[0] = 1;
    for(int i = 0; i < sz; i++) {
      power[i + 1] = mul(power[i], base);
      hashed[i + 1] = mul(hashed[i], base) + s[i];
      if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
    }
  }

  unsigned get(int l, int r) const {
    unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
    if(ret >= mod) ret -= mod;
    return ret;
  }

  unsigned connect(unsigned h1, int h2, int h2len) const {
    unsigned ret = mul(h1, power[h2len]) + h2;
    if(ret >= mod) ret -= mod;
    return ret;
  }

  int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = -1, high = len + 1;
    while(high - low > 1) {
      int mid = (low + high) / 2;
      if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
      else high = mid;
    }
    return (low);
  }
};

using RH = RollingHash< 1000000007 >;


int main() {
  
  string s; cin >> s;
  int n = s.size();
  string ans = "";
  int val = inf;


  RH rh(s);
  for (int A = 1; A <= n; A++) {
    int rest = n - 3 * A;
    if (rest <= 0) continue;
    if (rest % 2 != 0) continue;
    int B = rest / 2;

    if (rh.get(0, A) == rh.get(A + B, A + B + A) 
        and rh.get(0, A) == rh.get(2 * A + 2 * B, 2 * A + 2 * B + A) 
        and rh.get(A, A + B) == rh.get(2 * A + B, 2 * A + B + B)) {

      string a = s.substr(0, A);
      string b = s.substr(A, B);
      if (A + B < val) {
        ans = "Love " + a + b + "!";
        val = A + B;
      }
    }
  }


  if (ans == "") {
    cout << "mitomerarenaiWA" << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 13828
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
	int s; cin >> s;
	int a = s / 100;/*うえふたつ*/
	int b = s - 100*a;
	if (1 <= a && a <= 12) {
		if (1 <= b && b <= 12) {
			cout << "AMBIGUOUS";
		}
		else if (12 < b) {
			cout << "MMYY";
		}
		else if (b == 0) {
			cout << "MMYY";
		}
	}
	else if (12 < a) {
		if (1 <= b && b <=12) {
			cout << "YYMM";
		}
		else if (b == 0||13<=b) {
			cout << "NA";
		}
	}
	else if (a == 0) {
		if (1 <= b && b <= 12) {
			cout << "YYMM";
		}
		else if (b == 0||12<b) {
			cout << "NA";
		}
	}
	else if(a<0||b<0) {
		cout << "NA";
	}

	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string convert(int x, int y){
    string a = to_string(x), b = to_string(y);
    while (a.size() < 6){
        a = "0" + a;
    }
    while (b.size() < 6){
        b = "0" + b;
    }
    return a + b;
}
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> P(M), Y(M);
    vector<tuple<int, int, int>> data(M);
    for (int i = 0; i < M; i++){
        cin >> P.at(i) >> Y.at(i);
        data.at(i) = make_tuple(P.at(i), Y.at(i), i);
    }
    sort(data.begin(), data.end());
    vector<int> p(M), y(M), n(M);
    for (int i = 0; i < M; i++){
        tie(p.at(i), y.at(i), n.at(i)) = data.at(i);
    }
    vector<pair<int, string>> pa(M);
    vector<string> ans(M);
    int ken = P.at(0);
    int count = 0;
    for (int i = 0; i < M; i++){
        if (p.at(i) == ken){
            count ++;
            ans.at(i) = convert(ken, count);
        }
        else{
            count = 1;
            ken = p.at(i);
            ans.at(i) = convert(ken, count);
        }
        pa.at(i) = make_pair(n.at(i), ans.at(i));
    }
    sort(pa.begin(), pa.end());
    
    for (int i = 0; i < M; i++){
        cout << pa.at(i).second << endl;
    }
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<int> P(N);
    rep(i, N) cin >> P[i];

    vector<double> V(N);
    rep(i, N) {
        double n = P[i];
        V[i] = n * (n + 1) / (2 * n);
    }

    
    int r = 0;
    double total = 0, ans = 0;
    rep(l, N) {
        while (r < N && r - l < K) {
            total += V[r];
            r++;
        }

        if (r - l == K) ans = max(ans, total);
        total -= V[l];
    }

    printf("%.15f\n", ans);
}

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

void printArray(int* array, int length) {
	for (int i = 0; i < length; i++) {
		cout << array[i];
		if (i != length - 1)  cout << " ";
		else cout << endl;
	}
}

int selectionSort(int* array, int length) {
	int sw = 0;
	for (int i = 0; i < length; i++) {
		int minj = i;
		for (int j = i; j < length; j++) {
			if (array[j] < array[minj]) {
				minj = j;
			}
		}
		if(array[i] > array[minj]){
		    int temp = array[i];
		    array[i] = array[minj];
		    array[minj] = temp;
		    sw++;
		}
	}
	return sw;
}

int main()
{
	int loop;
	int swap = 0;
	int array[101] = {};

	cin >> loop;
	for (int i = 0; i < loop; i++) cin >> array[i];

	swap = selectionSort(array, loop);
	printArray(array, loop);
	cout << swap << endl;

	return 0;
}



Measured memory_bytes: 3112
X,K,D=map(int,input().split())
X=abs(X)
a=X%D
b=a-D
c=X//D
if a>abs(b):
    if c>K:
        print(X-D*K)
    elif c%2==K%2:
        print(a)
    else:
        print(abs(b))
else:
    if c+1>K:
        print(abs(X-D*K))
    elif c%2!=K%2:
        print(abs(b))
    else:
        print(a)

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
    }

    REP(i, N - K) {
        if (A[i] < A[i + K])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

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

ans = 0
         
for i in range(0,N):
      left = A[i] - B[i]
      ans += min(A[i],B[i])
         
      if left < 0:
          right = A[i+1] - abs(left)
          if right < 0: right = 0
          ans += A[i+1] - right
          A[i+1] = right

print(ans)


Measured memory_bytes: 19116
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>
#define lli long long int
#define ll long long
#define mod 1000000007
#define pii pair<int,int>
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
	int S, N;
	cin >> S >> N;
	if(S==1){
		if(N==1){
			cout << 1000000;
			return 0;
		}
		if(N==2){
			cout << 500000;
			return 0;
		}
		if(N==3){
			cout << 400000;
			return 0;
		}	
		cout << 300000;
			return 0;
	}
	if(S==2){
		if(N==1){
			cout << 500000;
			return 0;
		}
		if(N==2){
			cout << 400000;
			return 0;
		}
		if(N==3){
			cout << 300000;
			return 0;
		}	
		cout << 200000;
			return 0;
	}
	if(S==3){
		if(N==1){
			cout << 400000;
			return 0;
		}
		if(N==2){
			cout << 300000;
			return 0;
		}
		if(N==3){
			cout << 200000;
			return 0;
		}	
		cout << 100000;
			return 0;
	}
	if(N==1){
			cout << 300000;
			return 0;
		}
	if(N==2){
			cout << 200000;
			return 0;
		}
	if(N==3){
			cout << 100000;
			return 0;
		}	
		cout << 0;
			return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int w, h, xs, ys, xg, yg, n;
    int c, d, x, y;

    int[][] block;
    boolean[][] route;
    boolean[][] visit;
    int[] dirX = {1, 0, -1, 0};
    int[] dirY = {0, 1, 0, -1};
    Stack<int[]> st;

    void run(){
	while(sc.hasNext()){
	    w = sc.nextInt()+1;
	    h = sc.nextInt()+1;
	    if(w==1 && h==1) break;
	    put();
	    makeRoute();
	    //show();

	    visit = new boolean[h][w];
	    if(!route[ys][xs] || !route[yg][xg]){
		System.out.println("NG");
		continue;
	    }
	    else System.out.println(search() ? "OK":"NG");
	}
    }

    boolean search(){
	st = new Stack<int[]>();
	getGO(xs, ys);

	while(!st.empty()){
	    int[] p = st.pop();
	    visit[p[1]][p[0]] = true;
	    if(p[0]==xg && p[1]==yg) return true;
	    getGO(p[0], p[1]);
	}
	return false;
    }

    void getGO(int x, int y){ 
	for(int i=0; i<dirX.length; i++){
	    int a = x+dirX[i];
	    int b = y+dirY[i];
	    if(a>0 && a<w && b>0 && b<h && route[b][a] && !visit[b][a]){
		int[] p = { a, b };
		st.push(p);
	    }
	}
    }

    void show(){
	for(int i=1; i<w; i++){
	    for(int k=1; k<h; k++)
		System.out.print(route[i][k] ? "□":"■");
	    System.out.println();
	}
	System.out.println("----------------");
    }

    void put(){
	xs = sc.nextInt();
	ys = sc.nextInt();
	xg = sc.nextInt();
	yg = sc.nextInt();
	n = sc.nextInt();

	block = new int[h][w];
	route = new boolean[h][w];

	for(int i=0; i<n; i++){
	    c = sc.nextInt();
	    d = sc.nextInt();
	    x = sc.nextInt();
	    y = sc.nextInt();
	    if(d==0)
		for(int a=x; a<x+4; a++)
		    for(int b=y; b<y+2; b++)
			block[b][a] = c;    
	    else
		for(int a=x; a<x+2; a++)
		    for(int b=y; b<y+4; b++)
			block[b][a] = c;
	}
    }

    void makeRoute(){
	int tcolor = block[ys][xs];
	for(int i=0; i<w; i++)
	    for(int k=0; k<h; k++)
		if(block[k][i]==tcolor) route[k][i] = true;
    }
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	int ret = 0;
	vector<int> a;
	for(int i=0;i<n;i++){
		int x;
		cin >>x;
		a.emplace_back(x);
	}
	for(int i=0;i<n;i++){
		int x;
		cin >> x;
		ret+=x;
	}
	vector<int> c;
	for(int i=0;i<n-1;i++){
		int x;
		cin >> x;
		c.emplace_back(x);
	}
	for(int i=0;i<n-1;i++){
		if(a[i] +1 == a[i+1]){
			ret += c[a[i] - 1];
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]
area = W * H
X = [0] * W
Y = [0] * H
for x, y, a in xya:
    if a == 1:
        for i in range(x):
            X[i] = 1
    elif a == 2:
        for i in range(x, W):
            X[i] = 1
    elif a == 3:
        for i in range(y):
            Y[i] = 1
    elif a == 4:
        for i in range(y, H):
            Y[i] = 1
print(X.count(0) * Y.count(0))


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

int main(){

  long long N,A,B;
  
 cin >> N >> A >> B;
  
  long long a = N/(A + B);
  long long b = N%(A + B);
  
  if(b > A) b = A;
  
  cout << A * a + b <<endl;
}
  
 


Measured memory_bytes: 256
A,B= [int(s) for s in input().split()]
#print(A,B)

if B ==1:
  k=0
else:
  k=1

t = B-A

if t > 0:
  q, mod = divmod(t, A-1)
#  print("q="+str(q),mod)
  k=k+q
  if mod != 0:
    k = k+1

  

print(k)

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

bool I[1009];

int main() {
	for (int i = 2; i <= 1000; i++) {
		int x = i*i;
		while (x <= 1000) {
			I[x] = true;
			x *= i;
		}
	}
	I[1] = true;
	int s = 0, n; cin >> n;
	for (int i = 1; i <= n; i++) { if (I[i] == true) s = i; }
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
from heapq import*


x, y, a, b, c = map(int, input().split())

P = sorted(map(int, input().split()), reverse = True)[:x]
Q = sorted(map(int, input().split()), reverse = True)[:y]
R = sorted(map(int, input().split()))

heapify(P); heapify(Q)
while R:
    p, q, r = heappop(P), heappop(Q), R.pop()
    if p < q:
        heappush(Q, q)
        if p < r:
            heappush(P, r)
        else:
            heappush(P, p)
            break
    else:
        heappush(P, p)
        if q < r:
            heappush(Q, r)
        else:
            heappush(Q, q)
            break

print(sum(P) + sum(Q))


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rp(i,n){
        cin >> a[i];
    }
    sort(a);
    int ans=INT_MAX;
    rep(i,a[0],a[n-1]){
        int cost=0;
        rp(j,n){
            cost += (a[j]-i)*(a[j]-i);
        }
        ans=min(ans,cost);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
nums = map(int, input().split(' '))

res = 'APPROVED'

for n in nums:
    if n % 2 == 0:
        if n % 3 == 0 or n % 5 == 0:
            pass
        else:
            res = 'DENIED'
            break

print(res)

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

int main() {
  int y, m, d;
 char s1, s2;
  cin >> y >> s1 >> m >> s2 >> d;
  if(m <= 4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  
  
}

Measured memory_bytes: 256
N=input()
X=int(N)
L=len(str(N))
b=X
ch=[0 for i in range(L)]


for i in range (1,L+1):
  ch[-i]=b%10
  b=b//10



A=[[0 for i in range (L)] for j in range (L)]

for i in range (L-1):
  for j in range (L-i):
    A[i][j]=2**(L-i-2)

for i in range(L):
  A[i][L-i-1]=2**(L-i-1)

com=[]

for i in range(L):
  an=0
  for j in range (L):
    an+=A[j][i]*10**(j)
  com.append(an)

ans=0
for i in range(L):
  ans+=com[i]*ch[i]

print(ans)




Measured memory_bytes: 3064
using System;

namespace ITP1_8_B {
    class Program {
        static void Main(string[] args) {
            while(true) {
                string s = Console.ReadLine();
                if(s == "0") {
                    break;
                }
                char[] c = s.ToCharArray();
                string[] str = new string[s.Length];
                int[] n = new int[s.Length];
                for(int i = 0; i < s.Length; i++) {
                    str[i] = c[i].ToString();
                    n[i] = int.Parse(str[i]);
                }
                int num = 0;
                for(int i = 0; i < n.Length; i++) {
                    num += n[i];
                }
                Console.WriteLine(num);               
            }
        }
    }
}

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

int main() {
    int N, M, Q; cin >> N >> M >> Q;
    vector<vector<int>> city(N+1, vector<int>(N+1));
    int L, R;
    rep(i, M) {
        cin >> L >> R;
        city[R][L]++;
    }
    /*for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            if (j) cout << " ";
            cout << city[i][j];
        }
        cout << endl;
    }
    cout << endl;*/
    for (int i = 0; i < N; i++) {
        for (int j = i; j >= 0; j--) {
            city[i+1][j] += city[i][j];
        }
    }
    for (int i = 0; i <= N; i++) {
        for (int j = i; j > 0; j--) {
            city[i][j-1] += city[i][j];
        }
    }
    int p, q;
    /*for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            if (j) cout << " ";
            cout << city[i][j];
        }
        cout << endl;
    }*/
    rep(i, Q) {
        cin >> p >> q;
        cout << city[q][p] << endl;
    }
}


Measured memory_bytes: 4632
#include<cstdio>
#define buf 100000
using namespace std;

typedef struct{
	int s,m;
}Sport;
void BubbleSort(int n);
int B[buf];

int main(void){
	Sport t,b,g,r;
	int i,k,n,z,sum,A[buf];
	char str[1000];

	for( ; ; ){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&n);
		if(n==0) break; k=0; sum=0;
		for(i=0;i<n;i++){
			fgets(str,sizeof(str),stdin);
			sscanf(str,"%d %d %d %d %d %d %d %d %d",&z,&t.m,&t.s,&b.m,&b.s,&g.m,&g.s,&r.m,&r.s);
			sum=(t.m*60)+t.s+(b.m*60)+b.s+(g.m*60)+g.s+(r.m*60)+r.s;
			A[sum]=z; B[k]=sum; k++;
		}
		BubbleSort(n);
		printf("%d\n%d\n%d\n",A[B[0]],A[B[1]],A[B[n-2]]);
	}
	return 0;
}

void BubbleSort(int n){
	int i,j,tmp;
	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){	
			if(B[j] < B[j-1]){
				tmp = B[j-1];
				B[j-1] = B[j];
				B[j] = tmp;
			}
		}
	}
}

Measured memory_bytes: 2724
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  const ll X = 50 * 49;
  int n, m, s; cin >> n >> m >> s;
  chmin(s, X);
  struct Line {
    int dst; ll a, b;
    Line(int dst, ll a, ll b) : dst(dst), a(a), b(b) {}
  };
  vector<vector<Line>> graph(n);
  while (m--) {
    int u, v, a, b; cin >> u >> v >> a >> b; --u; --v;
    graph[u].emplace_back(v, a, b);
    graph[v].emplace_back(u, a, b);
  }
  vector<int> c(n), d(n); REP(i, n) cin >> c[i] >> d[i];
  vector ans(n, vector(X + 1, LINF));
  REP(j, s) ans[0][j] = 0;
  using P = pair<ll, pair<int, int>>;
  priority_queue<P, vector<P>, greater<P>> que;
  ans[0][s] = 0;
  que.emplace(0, make_pair(0, s));
  while (!que.empty()) {
    ll dist = que.top().first;
    auto [i, j] = que.top().second;
    que.pop();
    if (dist > ans[i][j]) continue;
    ll cost = dist;
    for (ll j2 = j + c[i]; ; j2 += c[i]) {
      cost += d[i];
      if (ans[i][min(j2, X)] <= cost) break;
      ans[i][min(j2, X)] = cost;
      que.emplace(cost, make_pair(i, min(j2, X)));
      if (j2 >= X) break;
    }
    for (const Line &line : graph[i]) {
      if (line.a > j) continue;
      cost = dist + line.b;
      if (cost < ans[line.dst][j - line.a]) {
        ans[line.dst][j - line.a] = cost;
        que.emplace(cost, make_pair(line.dst, j - line.a));
      }
    }
  }
  FOR(t, 1, n) cout << *min_element(ALL(ans[t])) << '\n';
  return 0;
}


Measured memory_bytes: 69044
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int x,a;
  cin>>x>>a;
  if(x<a) cout<<0<<endl;
  else cout<<10<<endl;

  return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break

        a = [LS() for _ in range(n)]
        d = collections.defaultdict(int)
        ed = collections.defaultdict(lambda: None)
        for i in range(n):
            x, y, di = a[i]
            x = int(x)
            y = int(y)
            d[(x,y)] = i + 1
            if di == 'x':
                d[(x+1,y)] = i + 1
                ed[(x,y)] = (x+1,y)
                ed[(x+1,y)] = (x,y)
            else:
                d[(x,y+1)] = i + 1
                ed[(x,y)] = (x,y+1)
                ed[(x,y+1)] = (x,y)

        ee = collections.defaultdict(set)
        dka = list(d.keys())
        for x,y in list(d.keys()):
            dt = d[(x,y)]
            for di,dj in dd:
                ni = x + di
                nj = y + dj
                if d[(ni,nj)] > 0 and d[(ni,nj)] != dt:
                    ee[(x,y)].add((ni,nj))

        v = collections.defaultdict(bool)
        f = True
        for k in dka:
            if v[k]:
                continue
            s1 = set()
            s2 = set()
            ns1 = set([k])
            ns2 = set()
            while ns1:
                na = list(ns1)
                s1 |= ns1
                ns1 = set()
                for k in na:
                    ns1 |= ee[k]
                    ns2.add(ed[k])
                ns2 -= s2

                while ns2:
                    na = list(ns2)
                    s2 |= ns2
                    ns2 = set()
                    for k in na:
                        ns2 |= ee[k]
                        ns1.add(ed[k])
                    ns2 -= s2

                ns1 -= s1

            if s1 & s2:
                f = False
            # print('k', k)
            # print('s1', s1)
            # print('s2', s2)

            if f:
                for k in s1:
                    v[k] = 1
                for k in s2:
                    v[k] = 1
            else:
                break

        if f:
            rr.append('Yes')
        else:
            rr.append('No')


    return '\n'.join(map(str,rr))


print(main())



Measured memory_bytes: 76824
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t=1;
	//cin >> t;
	while(t--){
		int n,k,z,i=0,count=0;
      	cin >> n >>k;
      	vector<int> arr;
      for(i=0;i<n;i++){
      	cin >> z;
        arr.push_back(z);
      }
      sort(arr.begin(),arr.end());
      for(i=0;i<k;i++){
      	count+= arr[i];
      }
      cout << count << endl;
	}
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15



int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(b, a * n) << endl;
	return 0;
}






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

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

    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d.at(i);
    }

    int ans = N;
    sort(d.begin(), d.end());
    for (int i = 0; i < N - 1; i++) {
        if(d.at(i) == d.at(i + 1)) {
            ans--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
P = list(map(int,input().split()))
def Base_10_to_n(X,n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n),n)+str(X%n)
  return str(X%n)
n = 2
ans = 0
for X in range(n**N):
  STR = Base_10_to_n(X,n).zfill(N)
  flag = True
  for i in range(len(L)):
    t = 0
    for j in range(1,L[i][0]+1):
      t += int(STR[L[i][j]-1])
    if t%2 != P[i]:
      flag = False
      break
  if flag:
    ans += 1
print(ans)   

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a, b;

    scanf("%d %d", &a, &b);
    if(a == 1){
        if(b == 2){
            printf("3\n");
        }
        else printf("2\n");
    }
    else if(a == 2){
        if(b == 1){
            printf("3\n");
        }
        else printf("1\n");
    }
    else if(a == 3){
        if(b == 1){
            printf("2\n");
        }
        else printf("1\n");
    }

    return 0;
}



Measured memory_bytes: 1616
//@Author- sitanshu
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair 
#define mii map<int, int>
#define umii unordered_map<int, int>
#define vi vector<int>
#define vl vector<ll>
#define clr(val) memset(val,0,sizeof(val))
const ll MAX = 1000009, MOD = 1e9 + 7;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);


void solve()
{
    string s, t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    int dp[n+1][m+1];

    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= m; j++)
        {
            if (i == 0 || j == 0)
            dp[i][j] = 0;
            else
            {
                if (s[i-1] == t[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
                else
                {
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                }
                
            }
            
        }
    }

    string res = "";
    int i = n, j = m;
    while(i!= 0 && j!= 0)
    {
        if (s[i-1] == t[j-1])
        {
            res+= s[i-1];
            i--; j--;
        }
        else
        {
            if (dp[i][j] == dp[i-1][j])
            --i;
            else
            {
                --j;
            }
            
        }
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}



int main()
{
    //OJ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t = 1;
    while(t--)
    {
        solve();
    }  
    return 0;
}

Measured memory_bytes: 38808
#include <stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if((a!=b&&a==c)||(a!=c&&a==b)||(b==c&&b!=a)){
	printf("Yes");
}
else {
	printf("No");	
}

return 0;
}

Measured memory_bytes: 1704
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    def bfs(s,g,n):
        bfs_map = [-1 for i in range(n)]
        bfs_map[s] = 0
        q = deque()
        q.append(s)
        fin = False
        while q:
            x = q.popleft()
            for y in range(n):
                if c[x][y] > 0 and bfs_map[y] < 0:
                    bfs_map[y] = bfs_map[x]+1
                    if y == g:
                        fin = True
                        break
                    q.append(y)
            if fin:
                break

        if bfs_map[g] == -1:
            return [None,0]
        path = [None for i in range(bfs_map[g]+1)]
        m = float("inf")
        path[bfs_map[g]] = g
        y = g
        for i in range(bfs_map[g])[::-1]:
            for x in range(n+1):
                if c[x][y] > 0 and bfs_map[x] == bfs_map[y]-1:
                    path[i] = x
                    if c[x][y] < m:
                        m = c[x][y]
                    y = x
                    break
        return [path,m]

    def ford_fulkerson(s,g,c,n):
        while 1:
            p,m = bfs(s,g,n)
            if not m:break
            for i in range(len(p)-1):
                c[p[i]][p[i+1]] -= m
                c[p[i+1]][p[i]] += m
        return sum(c[g])
    h,w = LI()
    a = SR(h)
    c = [[0 for i in range(h+w+2)] for j in range(h+w+2)]
    for y in range(h):
        for x in range(w):
            if a[y][x] == "S":
                c[0][y+1] = float("inf")
                c[0][h+x+1] = float("inf")
            if a[y][x] == "T":
                c[y+1][h+w+1] = float("inf")
                c[h+x+1][h+w+1] = float("inf")
            if a[y][x] == "o":
                c[y+1][h+x+1] = 1
                c[h+x+1][y+1] = 1
    ans = ford_fulkerson(0,h+w+1,c,h+w+2)
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)
#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    F()


Measured memory_bytes: 45040
class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def size(self, x):
        return -self.d[self.find(x)]

n, m, k = map(int, input().split())

deg = [0]*100005
uf = UnionFind(n)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    deg[a] += 1
    deg[b] += 1
    uf.unite(a, b)
for _ in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.same(c, d):
        deg[c] += 1
        deg[d] += 1
for i in range(n):
    print(uf.size(i) - 1 - deg[i], end="")
    if i == n-1:
        print()
    else:
        print(" ", end="")


Measured memory_bytes: 13664
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    M, D = map(int, input().split())

    ans = 0
    for month in range(1, M + 1):
        for day in range(1, D + 1):
            d1 = day % 10
            d2 = day // 10
            if d1 >= 2 and d2 >= 2 and d1 * d2 == month:
                ans += 1

    print(ans)


sol()

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

int a, b, c, n;
int num;
bool check(int x, int y){
	if(x >= y)
		return false;
	else
		return true;
}
int chg(int x, int y, int z){
	num = 0;
	while(!check(x, y)){
		y = y * 2;
		num++;
	}
	while(!check(y, z)){
		z = z * 2;
		num++;
	}
	return num;
}

int main()
{
	cin >> a >> b >> c;
	cin >> n;
	int ans = chg(a, b, c);
//	cout << ans << endl;
	if(ans > n)
		cout << "No\n";
	else
		cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 3536
#include<stdio.h>

#define N 100000

void partition(int A[], int p, int r){
  int x, i, j;
  int buf;

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

  for(j = p; j <= r-1; j++){
    if(A[j] <= x){
      i = i + 1;
      buf = A[i];
      A[i] = A[j];
      A[j] = buf;
    }
  }

  buf = A[i + 1];
  A[i + 1] = A[r];
  A[r] = buf;

  for(j = 0; j <= r; j++){
    if(j == i + 1) printf("[%d]", A[j]);
    else printf("%d", A[j]);
    if(j != r) printf(" ");
  }

  printf("\n");
}

int main(){
  int n, i;
  int p, r;
  int A[N];

  scanf("%d", &n);

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

  p = 0;
  r = n - 1;

  partition(A, p, r);

  return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int h1, m1, h2, m2, k;
	scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
	int t1 = h1 * 60 + m1;
	int t2 = h2 * 60 + m2;
	printf("%d\n", t2 - t1 - k);
}


Measured memory_bytes: 3828
program AGC041A
    implicit none
    integer(8)::N,A,B
    read*,N,A,B
    if(mod(B-A,2)==0)then
        print'(i0)',(B-A)/2
    else
        print'(i0)',min(N-B,A-1)+(B-A-1)/2+1
    end if
end program AGC041A

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int m, n;
    scanf("%d%d",&n,&m);
    int a[n];
    for(int i = 0; i < n; i++) 
        scanf("%d",&a[i]);
    int sum = 0;
    for(int i = 0; i < n; i++) 
        sum += a[i];
    int count = 0;
    for(int i = 0; i < n; i++) {
        int p = a[i] * 4 * m;
        if(p >= sum)
            count++;
    }
    if(count >= m)
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// A, B, Kを取得
		Scanner scan = new Scanner(System.in);
		String aStr = scan.next();
		String bStr = scan.next();
		String kStr = scan.next();
		scan.close();

		// a, b, kを数値に変換
		long a = Long.parseLong(aStr);
		long b = Long.parseLong(bStr);
		long k = Long.parseLong(kStr);

		long resA = 0;
		long resB = 0;

		// kが二人のクッキー合計以上の場合
		if (k >= a + b) {
			resA = 0;
			resB = 0;

			// kが二人のクッキー合計より小さい場合
		} else {

			// 高橋君がクッキーをk枚以下持っている場合
			if (a <= k) {
				resA = 0;
				resB = b - (k - a);

				// 高橋君がクッキーをk枚より多く持っている場合
			} else {
				resA = a - k;
				resB = b;
			}
		}

		// 高橋君と青木君が最終的に持っているクッキーの枚数を出力
		System.out.println(resA + " " + resB);

	}

}


Measured memory_bytes: 23764
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
//inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int64_t get(int64_t a, int64_t c, int64_t d) {
    int64_t res = a;
    res -= a / c;
    res -= a / d;
    res += a / (c * d / __gcd(c, d));
    return res;
}

int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int64_t a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << get(b, c, d) - get(a-1, c, d) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	scanf("%d %d",&a, &b);
	if ((a+b)%2 != 0)
	{
		printf("IMPOSSIBLE\n");
		return(0);
	}
	printf("%d\n",(a+b)/2);
	return(0);
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

ll a[maxn], cnt[maxn];

void solve() {
    int n;
    cin >> n;
    map<ll, ll> mp;
    for (int i = 1; i <= n; i++) cin >> a[i], mp[a[i]]++;
    ll res = 0, ans;
    for (auto &x : mp) cnt[x.fi] = x.se, res += x.se * (x.se - 1) / 2;
    for (int i = 1; i <= n; i++) {
        ans = res;
        if (cnt[a[i]] >= 2) ans = res - cnt[a[i]] * (cnt[a[i]] - 1) / 2 + (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2;
        cout << ans << endl;
    }
}

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


Measured memory_bytes: 15232
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
typedef long long ll;
using namespace std;

void solve(){
  ll h, w, b = 0; cin >> h >> w;
  char c[h][w];
  int mv[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  int dis[h][w];
  vector<vector<bool> > visited(h, vector<bool>(w, false));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> c[i][j];
      if(c[i][j] == '#') b++;
    }
  }
  queue<pair<int, int> > q;
  q.push(make_pair(0, 0));
  visited[0][0] = true;
  dis[0][0] = 1;
  while(q.size() > 0){
    int cx = q.front().first, cy = q.front().second;
    q.pop();
    for(int i = 0; i < 4; i++){
      int nx = cx + mv[i][0], ny = cy + mv[i][1];
      if(nx >= 0 && nx < h && ny >= 0 && ny < w && visited[nx][ny] == false && c[nx][ny] == '.'){
        q.push(make_pair(nx, ny));
        dis[nx][ny] = dis[cx][cy] + 1;
        visited[nx][ny] = true;
        if(nx == h - 1 && ny == w - 1){
          cout << (h * w) - dis[nx][ny] - b << endl;
          return;
        }
      }
    }
  }
  cout << -1 << endl;
  return;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

int main()
{
	int n, i;
	cin >> n >> i;

	cout << n - i + 1 << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int ans = 0;

	for(int i = 0; i<N; i++) {
	    int a = sc.nextInt();
	    while(a%2 == 0){
		a /= 2;
		ans++;
	    }
	}
	System.out.println(ans);

    }
}

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

const int N = 100005;
vector<pair<int, ll> > g[N];
ll dist[N];
 
void dfs(int v, int p){
	for(auto x : g[v]){
		if(x.first == p)continue;
		dist[x.first] = dist[v] + x.second;
		dfs(x.first, v);
	}
}
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);
 
    ll a, b, k; 
    cin >> a >> b >> k;
    if(k>=a+b){
        a=0;
        b=0;
    }else if(k>=a){
        b=b-(k-a);
        a=0;
    }else{
        a-=k;
    }
    cout << a << " " << b << "\n";
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
  cerr << "[";
  for (auto e : aux) cerr << e << ' ';
  cerr << "]";
  return cerr;
}

const int maxN = 1000011;

int n;
int a[maxN];
ll cnt[maxN];
char c;
bool anyOne = false;

void precompute() {
  for (int i = 1; i <= n; i++) {
    int x = i;
    while ((x & 1) == 0) {
      cnt[i]++;
      x >>= 1;
    }
    cnt[i] += cnt[i - 1];
  }
}

bool isEven(int n, int k) {
  return cnt[n] - cnt[k] - cnt[n - k] > 0;
}

bool isOne() {
  int sol = 0;

  for (int i = 0; i < n; i++) {
    if (!isEven(n - 1, i))
      sol ^= a[i];
  
    //cerr << i << ' ' << isEven(n - 1, i) << '\n';
  }

  return sol % 2;
}

int main()
{
  //freopen("test.in", "r", stdin);

  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    scanf("%c", &c);
    a[i] = c - '1';
    if (a[i] == 1) anyOne = true;
  }

  if (!anyOne) {
    for (int i = 0; i < n; i++) 
      a[i] >>= 1;
  }

  precompute();

  if (isOne()) {
    if (anyOne) 
      printf("1\n");
    else
      printf("2\n");
  } else {
    if (anyOne) 
      printf("0\n");
    else
      printf("0\n");
  }
  
  return 0;
}


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

const int MAX=8;
int N;

bool graph[MAX][MAX];
bool visited[MAX];

int dfs(int v){
    visited[v]=true;
    
    bool all_visited=true;
    for(int i=0; i<N; i++) if(visited[i]==false) all_visited=false;

    if(all_visited){
        visited[v]=false;
        return 1;
    }

    int ret=0;

    for(int i=0; i<N; i++){
        if(graph[v][i]==false or visited[i]==true) continue;
        ret += dfs(i);
    }

    visited[v]=false;
    return ret;
}

int main(void){
    int M;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a,b; cin >> a >> b;
        a--; b--;
        graph[a][b]=graph[b][a]=true;
    }

    cout << dfs(0) << endl;

    return 0;
}

Measured memory_bytes: 256