akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            
            var x = cin.nextInt();
            var y = cin.nextInt();

            for (int tu = 0; tu <= x; tu++)
            {
                var ka = x - tu;
                var ans = tu * 2 + ka * 4;
                if (ans == y)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            Console.WriteLine("No");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 27472
#include <cstdio>
using namespace std;
long long n,x;
long long sol(long long x,long long n){
    if(n%x==0) return n*2-x;
    return n/x*x*2+sol(n%x,x);
}int main(){while(~scanf("%lld%lld",&n,&x))printf("%lld\n",sol(x,n-x)+n);}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld
#define pb push_back
#define INF 1000000007
#define llINF 1e17
#define EPS 1e-9
#define pi acos(-1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}


const int MAX_n = 50;
int n,p,a[MAX_n];
int odd, even;
int ans;
int odd_n,even_n;

ll C[55][55];


int comb(int n, int r) {
    if(n < 0 || r < 0 || n < r) return 0;
    if(!r) return 1;
    return comb(n - 1, r - 1) + comb(n - 1, r);
}

signed main(){

    cin >> n >> p;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        if(a[i]%2 == 0)
            even++;
        else {
            odd++;
        }
    }

    for (int i = 0; i <= 50; i++) {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    }

    if(p == 0){
        for(int i = 0;i <= odd/2;i++){
            odd_n += C[odd][i*2];
        }
        even_n = 1LL << even;
        cout<< odd_n*even_n<<endl;
    }else{
        for(int i = 0;i <= odd/2;i++){
            odd_n += C[odd][i*2+1];
        }
        even_n = 1LL << even;
        cout<< odd_n*even_n<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  sort(all(a));
  int alice=0,bob=0;
  rep(i,n)
    if(i%2==n%2)bob+=a[i];
    else alice+=a[i];
  cout<<alice-bob<<endl;
}


Measured memory_bytes: 256
s = input().strip()

t = 'AKIHABARA'
si = 0
result = True

if len(s) > len(t):
    print('NO')
    exit()

for ti in range(len(t)):
    if si >= len(s):
        if t[ti:] == 'A' * (len(t) - ti):
            result = True
        else:
            result = False
        break
    elif s[si] == t[ti]:
        si += 1
    elif t[ti] == 'A':
        continue
    else:
        result = False
        break

if result:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3064
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
b = RI()

a = []
for i in range(n):
    if i==0:
        a.append(b[i])
    elif i>0 and i<(n-1):
        a.append(min(b[i-1],b[i]))
    elif i==(n-1):
        a.append(b[i-1])
    else:
        print("E")
ans = sum(a)
print(ans)

Measured memory_bytes: 77252
import itertools

N, D = map(int, input().split(' '))
a = [[int(i) for i in input().split(' ')] for _ in range(N)]

count = 0
for i in itertools.combinations(a,2):
    num = 0
    for j in range(len(i[0])):
        num += (i[0][j] - i[1][j])**2

    if num**0.5 == int(num**0.5):
        count += 1

print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N - 1));
    rep(i, 0, N) rep(j, 0, N - 1) {
        cin >> A[i][j];
        --A[i][j];
    }
    vector<vector<int>> pos(N, vector<int>(N, -1));
    rep(i, 0, N) rep(j, 0, N - 1) {
        pos[i][A[i][j]] = j;
    }
    vector<vector<int>> U(N, vector<int>(N - 1, -1));
    int num = 0;
    rep(i, 0, N) rep(j, 0, N - 1) {
        if (U[i][j] >= 0) {
            continue;
        }
        U[i][j] = U[A[i][j]][pos[A[i][j]][i]] = num++;
    }
    vector<vector<int>> graph(num);
    vector<int> cnt(num, 0);
    rep(i, 0, N) rep(j, 0, N - 2) {
        graph[U[i][j]].push_back(U[i][j + 1]);
        ++cnt[U[i][j + 1]];
    }
    queue<int> que;
    rep(i, 0, num) {
        if (!cnt[i]) {
            que.push(i);
        }
    }
    int ans = 0;
    while (!que.empty()) {
        ++ans;
        queue<int> buf;
        while (!que.empty()) {
            int node = que.front();
            que.pop();
            for (auto& next_node : graph[node]) {
                --cnt[next_node];
                if (!cnt[next_node]) {
                    buf.push(next_node);
                }
            }
        }
        while (!buf.empty()) {
            que.push(buf.front());
            buf.pop();
        }
    }
    rep(i, 0, num) {
        if (cnt[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 43392
#include <iostream>
#include <set>
#include <string>

int main(void) {
  std::string buf;
  std::set<std::string> S;
  int N;
  std::cin >> N;
  for (int c = 0; c < N; ++c) {
    std::cin >> buf;
    S.insert(buf);
  }
  std::cout << S.size();
  return 0;
}

Measured memory_bytes: 19216
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;


constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
	template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
	template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
	template<typename T> void chadd(T& a, T b) { a = a + b; }

	void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
	template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

	void CCout(long long x, const char* end = "\n") { std::cerr << x << end; }
	template <typename T> void CCout(const T& x, const char* end = "\n") { std::cerr << x << end; }
	template <typename T> void CCout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cerr << x[i] << (i == sz - 1 ? end : sep); } }

	// 標準入出力
	struct inp {
		std::size_t sz;
		inp(std::size_t _sz = 1) : sz(_sz) {}
		template <typename T> operator T () const { T a; std::cin >> a; return a; }
		template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
		template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
	};

	inp inp1; // input one
}

int main() {

	int k, n;
	cin >> k >> n;
	vector<int> a = inp(n);

	// 開始地点を全探索
	int ans = k;
	rep(i, n - 1) {
		chmin(ans, k - (a[i + 1] - a[i]));
	}
	int lenght = a[0] + k - a[n - 1];
	chmin(ans, k - lenght);

	Cout(ans);

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e15;
ll mod = 1e9+7;
ll n;
vector<ll> dp;
vector<vector<ll> > a;
ll solve(ll s){
    if( dp[s] != -inf ) return dp[s];
    ll res = 0;
    for(ll i=0;i<n;i++)for(ll j=i+1;j<n;j++)if( ( (s>>i)&1) && ( (s>>j)&1) )res += a[i][j];
    for(ll t = (s-1)&s; t > 0 ; t = ( (t-1)&s )){
	res = max(res, solve(t) + solve(s^t) );
    }
    return dp[s] = res;
}

int main(){
    cin>>n;
    dp = vector<ll>( (1<<n) , -inf );
    a = vector<vector<ll> > ( n ,vector<ll> (n,0) );
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>a[i][j];
    cout<<solve( (1<<n)-1 ) <<endl;
    return 0;
}


Measured memory_bytes: 896
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();

        int[,] cnt = new int[10, 10];

        for (int i = 1; i <= n; i++)
        {
            var str = i.ToString();
            cnt[str[0] - '0', str[str.Length - 1] - '0']++;
        }

        long ans = 0;
        for (int i = 1; i <= n; i++)
        {
            var str = i.ToString();
            ans += cnt[str[str.Length - 1] - '0', str[0] - '0'];
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 15304
#include <bits/stdc++.h>
#define INF 1e9
#define MAX_V 10000
using namespace std;

//????????¨????§???????(???????????????????????????)
struct edge{int to, cap, rev;};

vector<edge> G[MAX_V]; //??°???????????£??\?????????
bool used[MAX_V];      //DFS??§?????§??????????????????????????°

//from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});  
}


//?¢?????????????DFS??§??¢???
int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to ,t , min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

//s??????t???????????§???????±???????
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}


int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int u,v,c;
    cin>>u>>v>>c;
    add_edge(u,v,c);
  }
  cout<<max_flow(0,n-1)<<endl;

}

Measured memory_bytes: 3468
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	ll ans = 0;
	repn(i, 1, n + 1) if(!(i % 3 == 0 || i % 5 == 0)) ans += i;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
ll NcR(int n, int r) 
{ 
    ll p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            ll m=__gcd(p, k); 
            p /= m; 
            k /= m; 
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x)
{
    return (ll)(log(x)/log(base));
}
vec adj[51];
ll edges[51],parent[51],depth[51];;
map<pii,ll> s;
void dfs(ll u, ll p)
{
	parent[u]=p;
	rep(i,0,adj[u].size())
	{
		ll v=adj[u][i];
		if(v!=p)
		{
			depth[v]=depth[u]+1;
			dfs(v,u);
		}
	}
}
pii minmax(ll x,ll y)
{
	if(x>=y)
	return {y,x};
	return {x,y};
}
ll count(ll x)
{
	ll y=0;
	repi(i,0,50)
	{
		if((1ll<<i) & x)
		y++;
	}
	return y;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,l,m,k,ans,n,c,x,y,u,v;
    	cin>>n;
    	rep(i,1,n)
    	{
    		cin>>x>>y;
    		adj[x].pb(y);
    		adj[y].pb(x);
    		s[minmax(x,y)]=i-1;
		}
		repi(i,0,50)
		{
			depth[i]=0; 
			parent[i]=0;
			edges[i]=0;
		}
		dfs(1,0);
		cin>>m;
		rep(i,0,m)
		{
			cin>>u>>v;
			while(u!=v)
			{
				if(depth[v]>depth[u])
				{
					swap(u,v);
				}
				edges[i]=(edges[i] | (1ll<<s[minmax(u,parent[u])]) );
				u=parent[u];
			}
		}
		ans=0;
		rep(mask,0,1<<m)
		{
			k=0;
			rep(j,0,m)
			{
				if((1ll<<j) & mask)
				{
					k=(k | (edges[j]));
				}
			}
			c=count(k);
			if(count(mask)%2)
			ans-=1ll<<(n-c-1);
			else
			ans+=1ll<<(n-c-1);
		}
		cout<<ans;
    } 
	return 0;
}

Measured memory_bytes: 256
#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++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
/*
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
*/

int main() {
	int N, M; cin >> N >> M;	
	vector<bool> f(N, true);
	rep(i, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		f.at(a) = !f.at(a);
		f.at(b) = !f.at(b);
	}
	bool g = true;
	rep(i, N) {
		g = g && f.at(i);
	}
	YN(g);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    int n; cin >> n;
    int cnt = 0;
    bool ans = false;
    for (int i = 0; i < n; ++i) {
        int d1, d2; cin >> d1 >> d2;
        if (d1 == d2) cnt++;
        else cnt = 0;
        if (cnt >= 3) ans = true;
    }
    y_n(ans);
}

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

A = []
A_sum = 0

for i in range(N-1):
  if i != 0:
    if B[i-1] > B[i]:
      A[i] = B[i]
    A.append(B[i])
  else:
    A.append(B[i])
    A.append(B[i])
    
for i in range(N):
  A_sum += A[i]
  
print(A_sum)

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n, a, b, c, d;
string s;

bool check_reach(int start, int end) {
  for (int i = start; i <= end - 1; ++i) {
    if (s[i] == '#' && s[i + 1] == '#') {
      return false;
    }
  }

  return true;
}

bool check_triple() {
  bool ret = false;
  for (int i = b; i <= d; ++i) {
    if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') ret = true;
  }

  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);

  cin >> s;

  s = '#' + s + '#';

  if (!check_reach(a, c) || !check_reach(b, d)) {
    printf("No\n");
    return 0;
  }

  if (c < d) {
    printf("Yes\n");
    return 0;
  }

  if (check_triple()) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }

  return 0;
}


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

struct Interval {
  int start, slutt;
};
bool operator<(Interval a, Interval b) {
  return a.start < b.start;
}

Interval input[1000000];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int h,a,n,ans;
  cin >> h>>a;

  cout<<(h+a-1)/a;	  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	if(n&1 || a[n/2]==a[n/2+1]){
		printf("0\n");
	}
	else{
		int cnt=a[n/2+1]-a[n/2];
		printf("%d\n",cnt);
	}
	return 0;
}


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

int main() {
	string s;
	getline(cin,s);
	long long int a , b ;
	char ch;
	stringstream ss(s);
	while(ss >> a >> ch >> b){
		if(ch == '-')printf("%lld\n",a - b);
		else 
		printf("%lld\n",a + b);
	}
	return 0;
}

Measured memory_bytes: 256
(function(input) {
    var toMin = function(str) {
        var x = str.split(':');
        return parseInt(x[0]) * 60 + parseInt(x[1]);
    };
    var lines = input.split('\n');
    var line = lines.shift().split(' ');
    var n = line[0];
    var t = line[1];
    var last = 86400;
    var output = [];
    for (var i = 0; i < n; ++i) {
        var line = lines[i].split(' ');
        var diff = toMin(line[0]) - last;
        if (diff >= t) {
            output.push(line[1] + ' ' + diff);
        }
        last = toMin(line[2]);
    }
    console.log(output.length);
    for (var i = 0; i < output.length; ++i) {
        console.log(output[i]);
    }
})(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 15600
import java.util.Scanner;

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

    	/*Scanner = テキスト入力を扱うためのクラス
		 *キーボードからの入力を受けつける場合は
		 *System.inを使って下記のように記述
		 */


		/*while(true)で無限ループをセット
		 *int a = scan.nextInt(); 数値を入力
		 *String op = scan.next(); 算術演算子（今回は+,-,*,/の4種類）を入力してもらうことで計算を行ってる。
		 */
		while(true){
		int a		= scan.nextInt();
		String op	= scan.next();
		int b		= scan.nextInt();

		if (op.equals("?"))break;

		int result = 0;
		if(op.equals("+")){result = a+b;}
		if(op.equals("-")){result = a-b;}
		if(op.equals("*")){result = a*b;}
		if(op.equals("/")){result = a/b;}


		//最後は表示させる。
		System.out.println(result);
		}
    }
}

Measured memory_bytes: 18020
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	var N, t, cnt int
	fmt.Scan(&N)
	str := strconv.Itoa(N)

	for i := 0; i < len(str); i++ {
		t, _ = strconv.Atoi((string(str[i])))
		cnt += t
	}
	if N%cnt == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) > abs(a[j]) }


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> conn(n);
	for(int i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		--a; --b;
		conn[a].push_back(b);
		conn[b].push_back(a);
	}
	vector<bool> flags(n);
	for(const int v : conn[0]){ flags[v] = true; }
	bool answer = false;
	for(const int u : conn[n - 1]){
		if(flags[u]){ answer = true; }
	}
	cout << (answer ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}



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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(w>=v)
    {
        cout<<"NO";
        return 0;
    }
    if(abs(a-b)<=abs(v-w)*t)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
    return 0;
}


Measured memory_bytes: 3628
N = int(input())
H = list(map(int, input().split()))
H[0] -= 1
ans = True
for i in range(1, N):
    if H[i-1]<H[i]:
        H[i]-= 1
    elif H[i-1] == H[i]:
        pass
    else:
        ans=False
        break
if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 63856
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
T largestrectangle(vector<T> &v){
  int n=v.size();
  T res=0;
  using P = pair<int, T>;
  stack<P> sp;
  sp.emplace(-1,T(-1));
  for(int i=0;i<n;i++){
    int j=i;
    while(sp.top().second>v[i]){
      j=sp.top().first;
      res=max(res,(i-j+1)*(sp.top().second+1));
      sp.pop();
    }
    if(sp.top().second<v[i]) sp.emplace(j,v[i]);
  }
  while(!sp.empty()){
    res=max(res,(n-sp.top().first+1)*(sp.top().second+1));
    sp.pop();
  }
  return res;
}

//INSERT ABOVE HERE
signed main(){
  int h,w;
  cin>>h>>w;
  vector<string> st(h);
  for(int i=0;i<h;i++) cin>>st[i];

  int ans=max(h,w);
  vector<int> vv(w-1,0);
  for(int i=0;i+1<h;i++){
    for(int j=0;j+1<w;j++){
      int cnt=0;
      for(int a=0;a<2;a++)
        for(int b=0;b<2;b++)
          cnt+=st[i+a][j+b]-'0';
      if(cnt&1) vv[j]=0;
      else vv[j]++;
    }
    chmax(ans,largestrectangle(vv));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6400
s = list(input().split())
keep =[]
for i in range(len(s)):
  if s[i] == "+":
    keep.append(keep[-1]+keep[-2])
    del keep[-3:-1]
  elif s[i] == "-":
    keep.append(keep[-2]-keep[-1])
    del keep[-3:-1]
  elif s[i] == "*":
    keep.append(keep[-2]*keep[-1])
    del keep[-3:-1]
  elif s[i] == "/":
    keep.append(keep[-2]/keep[-1])
    del keep[-3:-1]
  else:
    keep.append(int(s[i]))
print(keep[-1])


Measured memory_bytes: 5600
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>

using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<int>;


bool solve()
{
	int T, D, L;
	cin >> T >> D >> L;

	if (T == 0)return false;

	vec Wet(T, 0);

	for (int i = 0; i < T; ++i)
	{
		int x; cin >> x;

		if (x < L) { continue; }

		Wet[i] += 1;
		if (i + D < T)
		{
			Wet[i + D] -= 1;
		}
	}

	int ans = Wet[0] != 0;

	for (int i = 1; i < T-1; ++i)
	{
		Wet[i] += Wet[i - 1];
		ans += Wet[i] != 0;
	}
	
	cout << ans << endl;

	return true;
}


int main()
{
	while(solve());

	return 0;
}


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

int main(int argc, char** argv){
    int n, t;
    std::cin >> n >> t;
    int cost[n];
    int time[n];
    for(int i=0; i<n; ++i){
        std::scanf("%d %d", &cost[i], &time[i]);
    }

    int min_cost = 10000;
    for(int i=0; i<n; ++i){
        if(t>=time[i]){
            if(min_cost>cost[i]){
                min_cost = cost[i];
            }
        }
    }
    if(min_cost >= 10000){
        std::cout << "TLE" << std::endl;
    }else{
        std::cout << min_cost << std::endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

const int N = 100100;
int main() {
	int n;
	int a[N];
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a[i] = x-1;
	}
	int p = 0, c = 0;
	while (1) {
		if (a[p] == -1) {
			cout << -1 << endl;
			return 0;
		}
		if (a[p] == 1) {
			cout << c+1 << endl;
			return 0;
		}
		int pp = a[p];
		a[p] = -1;
		p = pp;
		c++;
	}
	return 0;
}

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

#define fi first
#define se second
#define amen exit(0)

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef long double ld;

const ll D = 100007;
const ll Inf = 1000000007;

int main()
{
    ll x, y;
    cin >> x >> y;
    if (x <= 8 && y <= 8)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;
    amen;
}


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

int main() {
  int64_t t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) {
    cout << "infinity" << endl;
  } else if ((t1 * a1 > t1 * b1) == (t1 * a1 + t2 * a2 > t1 * b1 + t2 * b2)) {
    cout << 0 << endl;
  } else {
    cout << 1 + 2 * (abs(t1 * a1 - t1 * b1) / abs((t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2)))
      - (abs(t1 * a1 - t1 * b1) % abs((t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2)) == 0);
  }
}


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

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

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

char s[105];
bool vis[10];
int main(){
    int n, k, a;
    scanf("%d%d", &n, &k);
    for(int i=1;i<=k;i++) scanf("%d", &a), vis[a] = 1;
    for(int i=n;;i++){
        int x = i;
        bool ok = 1;
        while(x > 0){
            if(vis[x%10]){
                ok = 0;
                break;
            }
            x/=10;
        }
        if(ok){
            printf("%d\n", i);
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	string a, b, c; cin >> a >> b>>c;
	//string s; cin >> s;
	char aa = a[0]+ 'A' - 'a', bb = b[0] + 'A' - 'a', cc = c[0] + 'A' - 'a';
	cout <<aa<<bb<<cc;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
typedef std::vector<long long > vi ;
#define F first
#define S second
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(),a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define endl '\n'
#define show(a) for(auto el:a)cout<<el<<" "
const ll INF=LLONG_MAX/2;
const ll N=2e5+1;
#define yesno(f) yes(f);no(f);
#define yes(f) if(f)cout<<"YES\n";
#define no(f) if(!f)cout<<"NO\n";
using  namespace std;
int main()
{
    fast;
   ll t=1;
   //std::cin >> t;
   while(t--)
   {
       ll d,w,h=0;
       std::cin >> h>>w>>d;
       ll a[h+1][w+1];
       map<ll,pair<ll,ll>>mp;
       fr(i,1,h+1)
       {
           fr(j,1,w+1)
           {
               std::cin >> a[i][j];
               mp[a[i][j]]={i,j};
           }
       }
       ll mark[h*w+1]={0};
       fr(i,1,h*w+1)
       {
           if(mark[i]==0)
           {
               ll j;
               for(j=i+d;j<=h*w;j+=d)
               {
                   mark[j]=mark[j-d]+llabs(mp[j].F-mp[j-d].F)+llabs(mp[j].S-mp[j-d].S);
               }
           }
       }
       ll q;
       std::cin >> q;
       while(q--)
       {
           ll l,r;
           std::cin >> l>>r;
           cout<<mark[r]-mark[l]<<"\n";
       }
   }
}

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

#define SZ(x) ((int(x.size())))

typedef long long ll;

using namespace std;

const int maxn = 200*1000+10;
int n;
stack <pair <int, int> > s;
ll sum, t[maxn], x, ans;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	s.push ({-1, -1});
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		while (x < s.top().first)
		{
			sum -= t[s.top().second] * s.top().first;
			s.pop();
		}
		t[i] = i - s.top().second;
		sum += t[i] * x;
		ans += sum;
		s.push ({x, i});
	}
	cout << ans;
	return 0;
}

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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define sint int32_t
#define int long long int
#define all(v) v.begin() , v.end()
#define vii vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{
    string s , t;
    cin>>s;
    cin>>t;
    int n = s.size();
    int m = t.size();
    //int cnt = 1e9;
    int ans = m;

    for(int i = 0; i<n; i++)
    {
        int cnt = 0;
        int k = i;
        if(i+m > n) break;
        for(int j=0; j<m; j++ , k++)
        {
            if(t[j] != s[k]) cnt++;
        }
        ans = min(ans , cnt);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int n;
double p[3000];
double dp[3000][3000];
bool vis[3000][3000];

double f(int k, int h)
{
    if (k == n) return h > n / 2;
    if (vis[k][h]) return dp[k][h];
    vis[k][h] = true;
    return dp[k][h] = (1 - p[k]) * f(k + 1, h) + p[k] * f(k + 1, h + 1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> p[i];

    cout << setprecision(15) << fixed << f(0, 0);
}


Measured memory_bytes: 79488
# import math
# import statistics
a=input()
#b,c=int(input()),int(input())
c=[]
for i in a:
    c.append(i)
#e1,e2 = map(int,input().split())
#f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

if len(c)==2:
    print(a)
elif len(c)==3:
    c.reverse()
    print("".join(c))

Measured memory_bytes: 8868
#include <iostream>
#include <cmath>
#include <set>
#include <cstdio>
#include <string>
#include <cstring>

using namespace std;


int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int t=a;
	int sum=0;
	while(t<=c+0.5)
	{
		sum+=b;
		t+=a;
	}
	printf("%d\n",sum);
	return 0;
} 

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

#define pr std::pair<int, int>
#define fi first
#define se second
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define lep(i, l, r) for(int i = l; i < r; ++i)
#define irep(i, r, l) for(int i = r; i >= l; --i)
#define ilep(i, r, l) for(int i = r; i > l; --i)
#define Rep(i, r) rep(i, 1, r)
#define Lep(i, r) lep(i, 1, r)
#define IRep(i, r) irep(i, r, 1)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dputs(s) debug(s"\n")
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define FERR(s) freopen(s, "w", stderr)
typedef long long ll;
typedef long double ld;

namespace modular {
	const int MOD = 1000000007;
	inline int add(int x, int y) { return (x += y) >= MOD ? x - MOD : x; }
	inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : x; }
	inline int mul(int x, int y) { return 1LL * x * y % MOD; }
	inline int qpow(int x, int y) {
		int ans = 1;
		for (; y; y >>= 1, x = mul(x, x)) if (y & 1) ans = mul(ans, x);
		return ans;
	}
};

namespace Base {
	template<typename Tp>
	Tp input() {
		Tp x = 0, y = 1;
		char c = getchar();
		while (c < '0' || '9' < c) { if (c == '-') y = -1; c = getchar(); }
		while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
		return x * y;
	}
	template<typename Tp>
	void read(Tp& x) { x = input<Tp>(); }
	template<typename Tp> void chmax(Tp& x, Tp y) { x < y ? x = y : 0; }
	template<typename Tp> void chmin(Tp& x, Tp y) { x > y ? x = y : 0; }
};
using namespace Base;
/*----------------------------------------------------------------------*/

#define MAX_N 200007

ll N, S[MAX_N], top;
ll x[MAX_N], a[MAX_N];

inline ll dis(int x, int y) { return std::abs(x - y); }

void work(int l, int r) {
	if (S[0] < x[l]) {
		rep(i, l, r) S[++top] = x[i];
		// dputs("dsa");
		return;
	} else if (S[0] > x[r]) {
		irep(i, r, l) S[++top] = x[i];
		// dputs("asd");
		return;
	}
	if (a[l] < a[r]) {
		a[r] += a[l];
		work(l + 1, r);
		S[++top] = x[l];
	} else {
		a[l] += a[r];
		work(l, r - 1);
		S[++top] = x[r];
	}
}

int main () {
	read(N), read(S[0]);
	Rep(i, N) {
		read(x[i]), read(a[i]);
	}
	work(1, N);
	ll ans = 0;
	Rep(i, top) ans += dis(S[i - 1], S[i]);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
#include "atcoder/all"

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;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll Q;
    cin >> Q;
    REP(_, Q) {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << atcoder::floor_sum(n, m, a, b) << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int>d(n);
  for(int i=0; i<n; i++)cin >> d[i];
  int ret=0;
  for(int i=0; i<n-1; i++)for(int j=i+1; j<n; j++){
    ret+=d[i]*d[j];
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#define LEN 100005

using namespace std;

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P tmp = Q[head];
    head = (head + 1) % LEN;
    return tmp;
}

int main(int argc, const char * argv[]) {
    // insert code here...
    
    /////////
    //write//
    /////////
    
    int elaps = 0, c;
    int q;
    P u;
    cin >> n >> q;
    
    for(int i=0; i<n; i++){
        cin >> Q[i].name >> Q[i].t;
    }
    head = 0;
    tail = n;
    
    while( head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0)enqueue(u);
        else cout << u.name << " " << elaps << endl;
    }
    
    return 0;
}



Measured memory_bytes: 13236
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a,b,c,d;
    string s,t;

    //cin >> a >> b>> c >> d;
    cin >> s;// >> t;
    if (s[0] == s[2]) cout << "Yes" << endl;
    else cout << "No";


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
 int y,m;
 scanf("%2d%2d",&y,&m);
 int flag=0,flag1=0;
 if(y>=1&&y<=12&&m>=1&&m<=12)
 printf("AMBIGUOUS\n"); 
else  if(y>=0&&y<=99&&m>=1&&m<=12)
 {
 	 printf("YYMM\n");
 }
 else if(y>=1&&y<=12&&m>=0&&m<=99)
 printf("MMYY\n");
 
 else
 printf("NA\n");
 
 //cout<<y<<" "<<m;
}




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

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 100005;
int n, u, v;

vector<int> adj[N];
int distu[N], distv[N];

void dfs1(int x, int p = -1, int prof = 0){
	for(int i : adj[x]) if(i != p){
		dfs1(i, x, prof+1);
	}
	if(adj[x].size() == 1){
		distu[x] = prof;
	}
}

void dfs2(int x, int p = -1, int prof = 0){
	for(int i : adj[x]) if(i != p){
		dfs2(i, x, prof+1);
	}
	if(adj[x].size() == 1){
		distv[x] = prof;
	}
}

int main() {
	scanf("%d", &n);
	scanf("%d %d", &u, &v);
	for(int i = 1; i < n; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs1(u);
	dfs2(v);
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(distv[i] > distu[i]){
			ans = max(ans, distv[i] - 1);
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 12928